Skip to content

Commit

Permalink
Browser connection keys and rules are stored in custom data instead o…
Browse files Browse the repository at this point in the history
…f attributes
  • Loading branch information
varjolintu committed Mar 5, 2018
1 parent 8cd4d83 commit 53165ea
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 63 deletions.
6 changes: 3 additions & 3 deletions src/browser/BrowserEntryConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "core/Entry.h"
#include "core/EntryAttributes.h"

static const char KEEPASSBROWSER_NAME[] = "KeePassXC-Browser Settings";
static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings";


BrowserEntryConfig::BrowserEntryConfig(QObject* parent) :
Expand Down Expand Up @@ -83,7 +83,7 @@ void BrowserEntryConfig::setRealm(const QString& realm)

bool BrowserEntryConfig::load(const Entry* entry)
{
QString s = entry->attributes()->value(KEEPASSBROWSER_NAME);
QString s = entry->customData()->value(KEEPASSXCBROWSER_NAME);
if (s.isEmpty()) {
return false;
}
Expand All @@ -105,5 +105,5 @@ void BrowserEntryConfig::save(Entry* entry)
QVariantMap v = qo2qv(this);
QJsonObject o = QJsonObject::fromVariantMap(v);
QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
entry->attributes()->set(KEEPASSBROWSER_NAME, json);
entry->customData()->set(KEEPASSXCBROWSER_NAME, json);
}
68 changes: 65 additions & 3 deletions src/browser/BrowserOptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@
#include "BrowserSettings.h"
#include "core/FilePath.h"

#include <QMessageBox>
#include <QFileDialog>
#include "gui/MessageBox.h"

BrowserOptionDialog::BrowserOptionDialog(QWidget* parent) :
BrowserOptionDialog::BrowserOptionDialog(DatabaseTabWidget* parent) :
QWidget(parent),
m_ui(new Ui::BrowserOptionDialog())
m_ui(new Ui::BrowserOptionDialog()),
m_customData(new CustomData(this)),
m_customDataModel(new QStandardItemModel(this)),
m_dbTabWidget(parent)
{
m_ui->setupUi(this);
m_ui->removeCustomDataButton->setEnabled(false);
m_ui->customDataTable->setModel(m_customDataModel);
connect(m_ui->customDataTable->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
SLOT(toggleRemoveButton(QItemSelection)));
connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedKey()));
connect(m_ui->convertToCustomData, SIGNAL(clicked()), this, SIGNAL(convertAttributesToCustomData()));
connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys()));
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));

Expand All @@ -54,6 +63,17 @@ BrowserOptionDialog::~BrowserOptionDialog()
{
}

CustomData* BrowserOptionDialog::customData() const
{
// Returns the current database customData from metadata. Otherwise return an empty customData member.
if (DatabaseWidget* dbWidget = m_dbTabWidget->currentDatabaseWidget()) {
if (Database* db = dbWidget->database()) {
return db->metadata()->customData();
}
}
return m_customData;
}

void BrowserOptionDialog::loadSettings()
{
BrowserSettings settings;
Expand Down Expand Up @@ -88,6 +108,9 @@ void BrowserOptionDialog::loadSettings()
m_ui->firefoxSupport->setChecked(settings.firefoxSupport());
m_ui->vivaldiSupport->setChecked(settings.vivaldiSupport());

// Update the stored key list every time settings are loaded
updateModel();

#if defined(KEEPASSXC_DIST_APPIMAGE)
m_ui->supportBrowserProxy->setChecked(true);
m_ui->supportBrowserProxy->setEnabled(false);
Expand Down Expand Up @@ -139,3 +162,42 @@ void BrowserOptionDialog::showProxyLocationFileDialog()
fileTypeFilter);
m_ui->customProxyLocation->setText(proxyLocation);
}

void BrowserOptionDialog::removeSelectedKey()
{
if (QMessageBox::Yes != MessageBox::question(this,
tr("Delete the selected key?"),
tr("Do you really want to delete the selected key?\n"
"This may cause the affected plugins to malfunction."),
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel)) {
return;
}

const QItemSelectionModel* itemSelectionModel = m_ui->customDataTable->selectionModel();
if (itemSelectionModel) {
for (const QModelIndex& index : itemSelectionModel->selectedRows(0)) {
const QString key = index.data().toString();
customData()->remove(key);
}
updateModel();
}
}

void BrowserOptionDialog::toggleRemoveButton(const QItemSelection& selected)
{
m_ui->removeCustomDataButton->setEnabled(!selected.isEmpty());
}

void BrowserOptionDialog::updateModel()
{
m_customDataModel->clear();
m_customDataModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")});

for (const QString& key : customData()->keys()) {
m_customDataModel->appendRow(QList<QStandardItem*>()
<< new QStandardItem(key)
<< new QStandardItem(customData()->value(key)));
}

m_ui->removeCustomDataButton->setEnabled(false);
}
17 changes: 16 additions & 1 deletion src/browser/BrowserOptionDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

#include <QWidget>
#include <QScopedPointer>
#include <QStandardItemModel>
#include <QItemSelection>
#include <QPointer>
#include "core/CustomData.h"
#include "gui/DatabaseTabWidget.h"

namespace Ui {
class BrowserOptionDialog;
Expand All @@ -32,22 +37,32 @@ class BrowserOptionDialog : public QWidget
Q_OBJECT

public:
explicit BrowserOptionDialog(QWidget* parent = nullptr);
explicit BrowserOptionDialog(DatabaseTabWidget* parent = nullptr);
~BrowserOptionDialog();

CustomData* customData() const;

public slots:
void loadSettings();
void saveSettings();

signals:
void removeSharedEncryptionKeys();
void removeStoredPermissions();
void convertAttributesToCustomData();

private slots:
void showProxyLocationFileDialog();
void removeSelectedKey();
void toggleRemoveButton(const QItemSelection& selected);

private:
void updateModel();
QScopedPointer<Ui::BrowserOptionDialog> m_ui;

QPointer<CustomData> m_customData;
QPointer<QStandardItemModel> m_customDataModel;
DatabaseTabWidget* const m_dbTabWidget;
};

#endif // BROWSEROPTIONDIALOG_H
69 changes: 69 additions & 0 deletions src/browser/BrowserOptionDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,75 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="convertToCustomData">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Move KeePassHTTP attributes to KeePassXC-Browser &amp;custom data</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Stored Keys</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="customDataTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>200</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="removeCustomDataButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down
Loading

0 comments on commit 53165ea

Please sign in to comment.