Skip to content

Commit

Permalink
Add key removal list to Browser Integration settings window
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Feb 26, 2018
1 parent bee38cf commit f1194d2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 10 deletions.
68 changes: 65 additions & 3 deletions src/browser/BrowserOptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,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_dbTabWidget(parent),
m_ui(new Ui::BrowserOptionDialog()),
m_customData(new CustomData(this)),
m_customDataModel(new QStandardItemModel(this))
{
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->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SIGNAL(removeSharedEncryptionKeys()));
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));

Expand All @@ -51,6 +60,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 @@ -84,6 +104,9 @@ void BrowserOptionDialog::loadSettings()
m_ui->chromiumSupport->setChecked(settings.chromiumSupport());
m_ui->firefoxSupport->setChecked(settings.firefoxSupport());
m_ui->vivaldiSupport->setChecked(settings.vivaldiSupport());

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

void BrowserOptionDialog::saveSettings()
Expand Down Expand Up @@ -124,3 +147,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);
}
16 changes: 15 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,9 +37,11 @@ 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();
Expand All @@ -45,9 +52,16 @@ public slots:

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
52 changes: 52 additions & 0 deletions src/browser/BrowserOptionDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,58 @@
</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
15 changes: 9 additions & 6 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class HttpPlugin: public ISettingsPage
class BrowserPlugin: public ISettingsPage
{
public:
BrowserPlugin(DatabaseTabWidget* tabWidget) {
BrowserPlugin(DatabaseTabWidget* tabWidget) :
m_dbTabWidget(tabWidget)
{
m_nativeMessagingHost = QSharedPointer<NativeMessagingHost>(new NativeMessagingHost(tabWidget));
}

Expand All @@ -135,7 +137,7 @@ class BrowserPlugin: public ISettingsPage
}

QWidget* createWidget() override {
BrowserOptionDialog* dlg = new BrowserOptionDialog();
BrowserOptionDialog* dlg = new BrowserOptionDialog(m_dbTabWidget);
QObject::connect(dlg, SIGNAL(removeSharedEncryptionKeys()), m_nativeMessagingHost.data(), SLOT(removeSharedEncryptionKeys()));
QObject::connect(dlg, SIGNAL(removeStoredPermissions()), m_nativeMessagingHost.data(), SLOT(removeStoredPermissions()));
return dlg;
Expand All @@ -156,7 +158,8 @@ class BrowserPlugin: public ISettingsPage
}
}
private:
QSharedPointer<NativeMessagingHost> m_nativeMessagingHost;
QSharedPointer<NativeMessagingHost> m_nativeMessagingHost;
DatabaseTabWidget* const m_dbTabWidget;
};
#endif

Expand All @@ -169,7 +172,7 @@ MainWindow::MainWindow()
, m_appExiting(false)
{
m_ui->setupUi(this);

#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS)
new MainWindowAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
Expand Down Expand Up @@ -891,7 +894,7 @@ void MainWindow::updateTrayIcon()
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));

m_trayIcon->setContextMenu(menu);

m_trayIcon->setIcon(filePath()->applicationIcon());
m_trayIcon->show();
}
Expand Down Expand Up @@ -1150,4 +1153,4 @@ void MainWindow::closeAllDatabases()
void MainWindow::lockAllDatabases()
{
lockDatabasesAfterInactivity();
}
}

0 comments on commit f1194d2

Please sign in to comment.