Skip to content

Commit

Permalink
FdoSecrets: only enable the settings page when there is actually a se…
Browse files Browse the repository at this point in the history
…rvice instance

* Fix keepassxreboot#4311
  • Loading branch information
Aetf authored and droidmonkey committed Mar 10, 2020
1 parent 8ae718b commit 2359742
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
12 changes: 12 additions & 0 deletions src/fdosecrets/widgets/DatabaseSettingsWidgetFdoSecrets.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="MessageWidget" name="warningWidget" native="true"/>
</item>
Expand Down
41 changes: 25 additions & 16 deletions src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ SettingsWidgetFdoSecrets::SettingsWidgetFdoSecrets(FdoSecretsPlugin* plugin, QWi
dbViewHeader->setSectionResizeMode(1, QHeaderView::Stretch); // group
dbViewHeader->setSectionResizeMode(2, QHeaderView::ResizeToContents); // manage button

m_ui->tabWidget->setEnabled(m_ui->enableFdoSecretService->isChecked());
connect(m_ui->enableFdoSecretService, &QCheckBox::toggled, m_ui->tabWidget, &QTabWidget::setEnabled);
// prompt the user to save settings before the sections are enabled
connect(m_plugin, &FdoSecretsPlugin::secretServiceStarted, this, &SettingsWidgetFdoSecrets::updateServiceState);
connect(m_plugin, &FdoSecretsPlugin::secretServiceStopped, this, &SettingsWidgetFdoSecrets::updateServiceState);
connect(m_ui->enableFdoSecretService, &QCheckBox::toggled, this, &SettingsWidgetFdoSecrets::updateServiceState);
updateServiceState();

// background checking
m_checkTimer.setInterval(2000);
Expand Down Expand Up @@ -310,18 +313,6 @@ void SettingsWidgetFdoSecrets::saveSettings()
FdoSecrets::settings()->setNoConfirmDeleteItem(m_ui->noConfirmDeleteItem->isChecked());
}

void SettingsWidgetFdoSecrets::showMessage(const QString& text, MessageWidget::MessageType type)
{
// Show error messages for a longer time to make sure the user can read them
if (type == MessageWidget::Error) {
m_ui->warningMsg->setCloseButtonVisible(true);
m_ui->warningMsg->showMessage(text, type, -1);
} else {
m_ui->warningMsg->setCloseButtonVisible(false);
m_ui->warningMsg->showMessage(text, type, 2000);
}
}

void SettingsWidgetFdoSecrets::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
Expand All @@ -344,14 +335,32 @@ void SettingsWidgetFdoSecrets::checkDBusName()

auto reply = QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral(DBUS_SERVICE_SECRET));
if (!reply.isValid()) {
showMessage(tr("<b>Error:</b> Failed to connect to DBus. Please check your DBus setup."), MessageWidget::Error);
m_ui->warningMsg->showMessage(
tr("<b>Error:</b> Failed to connect to DBus. Please check your DBus setup."), MessageWidget::Error, -1);
m_ui->enableFdoSecretService->setChecked(false);
m_ui->enableFdoSecretService->setEnabled(false);
return;
}
if (reply.value()) {
showMessage(tr("<b>Warning:</b> ") + m_plugin->reportExistingService(), MessageWidget::Warning);
m_ui->warningMsg->showMessage(
tr("<b>Warning:</b> ") + m_plugin->reportExistingService(), MessageWidget::Warning, -1);
m_ui->enableFdoSecretService->setChecked(false);
m_ui->enableFdoSecretService->setEnabled(false);
return;
}
m_ui->warningMsg->hideMessage();
m_ui->enableFdoSecretService->setEnabled(true);
}

void SettingsWidgetFdoSecrets::updateServiceState()
{
m_ui->tabWidget->setEnabled(m_plugin->serviceInstance() != nullptr);
if (m_ui->enableFdoSecretService->isChecked() && !m_plugin->serviceInstance()) {
m_ui->tabWidget->setToolTip(
tr("Save current changes to activate the plugin and enable editing of this section."));
} else {
m_ui->tabWidget->setToolTip("");
}
}

#include "SettingsWidgetFdoSecrets.moc"
2 changes: 1 addition & 1 deletion src/fdosecrets/widgets/SettingsWidgetFdoSecrets.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public slots:

private slots:
void checkDBusName();
void showMessage(const QString& text, MessageWidget::MessageType type);
void updateServiceState();

protected:
void showEvent(QShowEvent* event) override;
Expand Down
12 changes: 12 additions & 0 deletions src/fdosecrets/widgets/SettingsWidgetFdoSecrets.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
<string>Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="MessageWidget" name="warningMsg" native="true"/>
</item>
Expand Down

0 comments on commit 2359742

Please sign in to comment.