Skip to content

Commit

Permalink
Add share indication label in group view
Browse files Browse the repository at this point in the history
When viewing a shared group, the sharing state is indicated by a label
similar to the search label.
  • Loading branch information
Christian Kieschnick committed Feb 26, 2019
1 parent e8ec45e commit b973d22
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
#include "keeshare/KeeShare.h"
#include "touchid/TouchID.h"

#include "config-keepassx.h"

#ifdef Q_OS_LINUX
#include <sys/vfs.h>
#endif
Expand All @@ -80,6 +78,9 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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))
Expand All @@ -103,6 +104,9 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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);
Expand Down Expand Up @@ -134,6 +138,16 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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);
Expand Down Expand Up @@ -1117,6 +1131,15 @@ void DatabaseWidget::onGroupChanged(Group* group)
}

m_previewView->setGroup(group);

#ifdef WITH_XC_KEESHARE
if (group && KeeShare::isShared(group)) {
m_shareLabel->setText(KeeShare::sharingLabel(group));
m_shareLabel->setVisible(true);
} else {
m_shareLabel->setVisible(false);
}
#endif
}

void DatabaseWidget::onDatabaseModified()
Expand Down
5 changes: 5 additions & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "gui/csvImport/CsvImportWizard.h"
#include "gui/entry/EntryModel.h"

#include "config-keepassx.h"

class DatabaseOpenWidget;
class KeePass1OpenWidget;
class DatabaseSettingsDialog;
Expand Down Expand Up @@ -233,6 +235,9 @@ private slots:
QPointer<EntryPreviewWidget> m_previewView;
QPointer<QSplitter> m_previewSplitter;
QPointer<QLabel> m_searchingLabel;
#ifdef WITH_XC_KEESHARE
QPointer<QLabel> m_shareLabel;
#endif
QPointer<CsvImportWizard> m_csvImportWizard;
QPointer<EditEntryWidget> m_editEntryWidget;
QPointer<EditGroupWidget> m_editGroupWidget;
Expand Down
1 change: 1 addition & 0 deletions src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
19 changes: 19 additions & 0 deletions src/keeshare/KeeShare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ bool KeeShare::isEnabled(const Group* group)
return (reference.isImporting() && active.in) || (reference.isExporting() && active.out);
}

QString KeeShare::sharingLabel(const Group* group)
{
if (!isShared(group)) {
return "";
}
const auto reference = referenceOf(group);
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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/keeshare/KeeShare.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class KeeShare : public QObject
static bool isShared(const Group* group);
static bool isEnabled(const Group* group);

static QString sharingLabel(const Group* group);

static KeeShareSettings::Own own();
static KeeShareSettings::Active active();
static KeeShareSettings::Foreign foreign();
Expand Down

0 comments on commit b973d22

Please sign in to comment.