diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 9d52af784..08f7db9c7 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -61,8 +61,6 @@ #include "keeshare/KeeShare.h" #include "touchid/TouchID.h" -#include "config-keepassx.h" - #ifdef Q_OS_LINUX #include #endif @@ -80,6 +78,9 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) , m_previewView(new EntryPreviewWidget(this)) , m_previewSplitter(new QSplitter(m_mainWidget)) , m_searchingLabel(new QLabel(this)) +#ifdef WITH_XC_KEESHARE + , m_shareLabel(new QLabel(this)) +#endif , m_csvImportWizard(new CsvImportWizard(this)) , m_editEntryWidget(new EditEntryWidget(this)) , m_editGroupWidget(new EditGroupWidget(this)) @@ -103,6 +104,9 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) auto* vbox = new QVBoxLayout(); vbox->setMargin(0); vbox->addWidget(m_searchingLabel); +#ifdef WITH_XC_KEESHARE + vbox->addWidget(m_shareLabel); +#endif vbox->addWidget(m_previewSplitter); rightHandSideWidget->setLayout(vbox); m_entryView = new EntryView(rightHandSideWidget); @@ -134,6 +138,16 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) "border-radius: 4px;"); m_searchingLabel->setVisible(false); +#ifdef WITH_XC_KEESHARE + m_shareLabel->setText(tr("Shared group...")); + m_shareLabel->setAlignment(Qt::AlignCenter); + m_shareLabel->setStyleSheet("color: rgb(0, 0, 0);" + "background-color: rgb(255, 253, 160);" + "border: 2px solid rgb(190, 190, 190);" + "border-radius: 4px;"); + m_shareLabel->setVisible(false); +#endif + m_previewView->hide(); m_previewSplitter->addWidget(m_entryView); m_previewSplitter->addWidget(m_previewView); @@ -765,9 +779,9 @@ void DatabaseWidget::switchToMainView(bool previousDialogAccepted) setCurrentWidget(m_mainWidget); - if (sender() == m_entryView) { + if (sender() == m_entryView || sender() == m_editEntryWidget) { onEntryChanged(m_entryView->currentEntry()); - } else if (sender() == m_groupView) { + } else if (sender() == m_groupView || sender() == m_editGroupWidget) { onGroupChanged(m_groupView->currentGroup()); } } @@ -1089,6 +1103,7 @@ void DatabaseWidget::search(const QString& searchtext) } m_searchingLabel->setVisible(true); + m_shareLabel->setVisible(false); emit searchModeActivated(); } @@ -1117,6 +1132,16 @@ void DatabaseWidget::onGroupChanged(Group* group) } m_previewView->setGroup(group); + +#ifdef WITH_XC_KEESHARE + auto shareLabel = KeeShare::sharingLabel(group); + if (!shareLabel.isEmpty()) { + m_shareLabel->setText(shareLabel); + m_shareLabel->setVisible(true); + } else { + m_shareLabel->setVisible(false); + } +#endif } void DatabaseWidget::onDatabaseModified() @@ -1140,6 +1165,7 @@ void DatabaseWidget::endSearch() // Show the normal entry view of the current group m_entryView->displayGroup(currentGroup()); + onGroupChanged(currentGroup()); emit listModeActivated(); } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index f8c6a26fe..9c2788995 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -29,6 +29,8 @@ #include "gui/csvImport/CsvImportWizard.h" #include "gui/entry/EntryModel.h" +#include "config-keepassx.h" + class DatabaseOpenWidget; class KeePass1OpenWidget; class DatabaseSettingsDialog; @@ -233,6 +235,9 @@ private: QPointer m_previewView; QPointer m_previewSplitter; QPointer m_searchingLabel; +#ifdef WITH_XC_KEESHARE + QPointer m_shareLabel; +#endif QPointer m_csvImportWizard; QPointer m_editEntryWidget; QPointer m_editGroupWidget; diff --git a/src/gui/SearchWidget.cpp b/src/gui/SearchWidget.cpp index c657dc1bd..6e9b66929 100644 --- a/src/gui/SearchWidget.cpp +++ b/src/gui/SearchWidget.cpp @@ -120,6 +120,7 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event) void SearchWidget::connectSignals(SignalMultiplexer& mx) { + // Connects basically only to the current DatabaseWidget, but allows to switch between instances! mx.connect(this, SIGNAL(search(QString)), SLOT(search(QString))); mx.connect(this, SIGNAL(caseSensitiveChanged(bool)), SLOT(setSearchCaseSensitive(bool))); mx.connect(this, SIGNAL(limitGroupChanged(bool)), SLOT(setSearchLimitGroup(bool))); diff --git a/src/keeshare/KeeShare.cpp b/src/keeshare/KeeShare.cpp index 751429558..08c7b4f17 100644 --- a/src/keeshare/KeeShare.cpp +++ b/src/keeshare/KeeShare.cpp @@ -93,7 +93,7 @@ void KeeShare::setOwn(const KeeShareSettings::Own& own) bool KeeShare::isShared(const Group* group) { - return group->customData()->contains(KeeShare_Reference); + return group && group->customData()->contains(KeeShare_Reference); } KeeShareSettings::Reference KeeShare::referenceOf(const Group* group) @@ -142,6 +142,40 @@ bool KeeShare::isEnabled(const Group* group) return (reference.isImporting() && active.in) || (reference.isExporting() && active.out); } +const Group* KeeShare::resolveSharedGroup(const Group* group) +{ + while (group && group != group->database()->rootGroup()) { + if (isShared(group)) { + return group; + } + group = group->parentGroup(); + } + + return nullptr; +} + +QString KeeShare::sharingLabel(const Group* group) +{ + auto* share = resolveSharedGroup(group); + if (!share) { + return {}; + } + + const auto reference = referenceOf(share); + switch (reference.type) { + case KeeShareSettings::Inactive: + return tr("Disabled share %1").arg(reference.path); + case KeeShareSettings::ImportFrom: + return tr("Import from share %1").arg(reference.path); + case KeeShareSettings::ExportTo: + return tr("Export to share %1").arg(reference.path); + case KeeShareSettings::SynchronizeWith: + return tr("Synchronize with share %1").arg(reference.path); + } + + return {}; +} + QPixmap KeeShare::indicatorBadge(const Group* group, QPixmap pixmap) { if (!isShared(group)) { diff --git a/src/keeshare/KeeShare.h b/src/keeshare/KeeShare.h index 33c887a71..86829ea1c 100644 --- a/src/keeshare/KeeShare.h +++ b/src/keeshare/KeeShare.h @@ -43,6 +43,9 @@ public: static bool isShared(const Group* group); static bool isEnabled(const Group* group); + static const Group* resolveSharedGroup(const Group* group); + static QString sharingLabel(const Group* group); + static KeeShareSettings::Own own(); static KeeShareSettings::Active active(); static KeeShareSettings::Foreign foreign();