diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 1fee54a43..6f70db347 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -440,14 +440,15 @@ QStringList Group::hierarchy() QStringList hierarchy; Group* group = this; Group* parent = m_parent; - hierarchy << group->name(); + hierarchy.prepend(group->name()); while (parent) { group = group->parentGroup(); parent = group->parentGroup(); - hierarchy << group->name(); + hierarchy.prepend(group->name()); } + return hierarchy; } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 141248bd4..404adb528 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -27,7 +27,6 @@ #include "core/Uuid.h" #include "gui/entry/EntryModel.h" -#include "gui/DetailsWidget.h" #include "gui/MessageWidget.h" #include "gui/csvImport/CsvImportWizard.h" diff --git a/src/gui/DetailsWidget.cpp b/src/gui/DetailsWidget.cpp index ee051e9cb..45284c840 100644 --- a/src/gui/DetailsWidget.cpp +++ b/src/gui/DetailsWidget.cpp @@ -25,10 +25,12 @@ #include "core/FilePath.h" #include "core/TimeInfo.h" #include "gui/Clipboard.h" +#include "gui/DatabaseWidget.h" DetailsWidget::DetailsWidget(QWidget* parent) : QWidget(parent) , m_ui(new Ui::DetailsWidget()) + , m_locked(false) , m_currentEntry(nullptr) , m_currentGroup(nullptr) { @@ -36,6 +38,7 @@ DetailsWidget::DetailsWidget(QWidget* parent) connect(parent, SIGNAL(pressedEntry(Entry*)), SLOT(getSelectedEntry(Entry*))); connect(parent, SIGNAL(pressedGroup(Group*)), SLOT(getSelectedGroup(Group*))); + connect(parent, SIGNAL(currentModeChanged(DatabaseWidget::Mode)), SLOT(setDatabaseMode(DatabaseWidget::Mode))); m_ui->totpButton->setIcon(filePath()->icon("actions", "chronometer")); m_ui->closeButton->setIcon(filePath()->icon("actions", "dialog-close")); @@ -60,6 +63,9 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry) m_ui->stackedWidget->setCurrentIndex(EntryPreview); + m_ui->tabWidget->setTabEnabled(AttributesTab, false); + m_ui->tabWidget->setTabEnabled(NotesTab, false); + m_ui->totpButton->hide(); m_ui->totpWidget->hide(); m_ui->totpButton->setChecked(false); @@ -81,10 +87,6 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry) m_ui->titleLabel->setText(title); m_ui->usernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username())); - if (entry_group) { - m_ui->groupLabel->setText(entry_group->name()); - } - m_ui->notesEdit->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->notes())); if (!config()->get("security/hidepassworddetails").toBool()) { m_ui->passwordLabel->setText(shortPassword(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password()))); @@ -110,10 +112,6 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry) m_ui->expirationLabel->setText(tr("Never")); } - m_ui->creationLabel->setText(entryTime.creationTime().toString(Qt::DefaultLocaleShortDate)); - m_ui->modifyLabel->setText(entryTime.lastModificationTime().toString(Qt::DefaultLocaleShortDate)); - m_ui->accessLabel->setText(entryTime.lastAccessTime().toString(Qt::DefaultLocaleShortDate)); - if (m_currentEntry->hasTotp()) { m_ui->totpButton->show(); updateTotp(); @@ -124,6 +122,28 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry) connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTotp())); m_timer->start(m_step * 10); } + + QString notes = m_currentEntry->notes(); + if (!notes.isEmpty()) { + m_ui->tabWidget->setTabEnabled(NotesTab, true); + m_ui->notesEdit->setText(m_currentEntry->resolveMultiplePlaceholders(notes)); + } + + QStringList customAttributes = m_currentEntry->attributes()->customKeys(); + if (customAttributes.size() > 0) { + m_ui->tabWidget->setTabEnabled(AttributesTab, true); + m_ui->attributesEdit->clear(); + + QString attributesText = QString(); + for (const QString& key : customAttributes) { + QString value = m_currentEntry->attributes()->value(key); + if (m_currentEntry->attributes()->isProtected(key)) { + value = "[PROTECTED]"; + } + attributesText.append(QString("%1: %2
").arg(key, value)); + } + m_ui->attributesEdit->setText(attributesText); + } } void DetailsWidget::getSelectedGroup(Group* selectedGroup) @@ -136,13 +156,18 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup) m_ui->stackedWidget->setCurrentIndex(GroupPreview); + m_ui->tabWidget->setTabEnabled(AttributesTab, false); + m_ui->tabWidget->setTabEnabled(NotesTab, false); + m_ui->totpButton->hide(); m_ui->totpWidget->hide(); m_ui->entryIcon->setPixmap(m_currentGroup->iconPixmap()); - QStringList hierarchy = m_currentGroup->hierarchy(); QString title = " / "; + + QStringList hierarchy = m_currentGroup->hierarchy(); + for (QString parent : hierarchy) { title.append(parent); title.append(" / "); @@ -177,6 +202,10 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup) void DetailsWidget::updateTotp() { + if (m_locked) { + m_timer->stop(); + return; + } QString totpCode = m_currentEntry->totp(); QString firstHalf = totpCode.left(totpCode.size()/2); QString secondHalf = totpCode.right(totpCode.size()/2); @@ -219,3 +248,23 @@ void DetailsWidget::hideDetails() { this->hide(); } + +void DetailsWidget::setDatabaseMode(DatabaseWidget::Mode mode) +{ + m_locked = false; + if (mode == DatabaseWidget::LockedMode) { + m_locked = true; + return; + } + if (mode == DatabaseWidget::ViewMode) { + if (m_ui->stackedWidget->currentIndex() == GroupPreview) { + getSelectedGroup(m_currentGroup); + } else { + getSelectedEntry(m_currentEntry); + } + } +} + +void DetailsWidget::copyToClipboard(const QString& text) { + clipboard()->setText(text); +} \ No newline at end of file diff --git a/src/gui/DetailsWidget.h b/src/gui/DetailsWidget.h index d4accf08f..44989fd1b 100644 --- a/src/gui/DetailsWidget.h +++ b/src/gui/DetailsWidget.h @@ -40,15 +40,25 @@ public: GroupPreview = 1, }; + enum TabWidgetIndex + { + GeneralTab = 0, + AttributesTab = 1, + NotesTab = 2, + }; + private slots: void getSelectedEntry(Entry* selectedEntry); void getSelectedGroup(Group* selectedGroup); void showTotp(bool visible); void updateTotp(); void hideDetails(); + void setDatabaseMode(DatabaseWidget::Mode mode); + void copyToClipboard(const QString& text); private: const QScopedPointer m_ui; + bool m_locked; Entry* m_currentEntry; Group* m_currentGroup; quint8 m_step; diff --git a/src/gui/DetailsWidget.ui b/src/gui/DetailsWidget.ui index 0f202c0f6..2bc6653c8 100644 --- a/src/gui/DetailsWidget.ui +++ b/src/gui/DetailsWidget.ui @@ -7,7 +7,7 @@ 0 0 630 - 207 + 180 @@ -19,7 +19,7 @@ 16777215 - 235 + 200 @@ -146,332 +146,326 @@ - - - - 0 - 0 - - + 0 - - - - 0 - - - 0 - - - 0 - - - 0 - + + false + + + false + + + false + + + false + + + + General + + - - - + + + + 0 + 0 + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + - - - - - - 75 - true - - - - Group - - - - - - - - 9 - 75 - true - - - - URL - - - - - - - - 75 - true - - - - Password - - - - - - - - 75 - true - - - - Username - - - - - - - - - - - - - - 0 - 0 - - - - - - - - - + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + URL + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Password + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Qt::LeftToRight + + + Username + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Expiration + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + - - - - - - - - 75 - true - - - - Modification - - - - - - - - 75 - true - - - - Access - - - - - - - - - - - - - - 75 - true - - - - Creation - - - - - - - - 75 - true - - - - Expiration - - - - - - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - + + + + + 0 + + + 0 + + + 0 + + + 0 + - - - + + + + + + + + + + + + + 75 + true + + + + Autotype + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + + + + Expiration + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + + + + Searching + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + - - - - - 75 - true - - - - Autotype - - - - - - - - - - - 75 - true - - - - Searching - - - - - - - - - - - 75 - true - - - - Expiration - - + + + + + + + 75 + true + + + + Access + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + 75 + true + + + + Creation + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + true + + + + Modification + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - - - - - - - - 75 - true - - - - Modification - - - - - - - - 75 - true - - - - Access - - - - - - - - - - - - - - 75 - true - - - - Creation - - - - - - - - - - - - - - - - - - - - - - - 75 - true - - - - Notes - + @@ -488,42 +482,77 @@ - - - - - - 0 - 1 - - - - - 0 - 50 - - - - - 16777215 - 50 - - - - Qt::ClickFocus - - - true - - - - - - - - - Qt::Horizontal - + + + + Attributes + + + + + + + 0 + 1 + + + + + 0 + 80 + + + + + 16777215 + 80 + + + + Qt::ClickFocus + + + true + + + + + + + + Notes + + + + + + + 0 + 1 + + + + + 0 + 80 + + + + + 16777215 + 80 + + + + Qt::ClickFocus + + + true + + + + +