Add Browser Integration to Group Edit page

Closes #1789 and closes #3998
This commit is contained in:
varjolintu
2021-10-09 14:46:39 -04:00
committed by Jonathan White
parent c7cdce6e33
commit b6716bdfe5
11 changed files with 524 additions and 66 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,6 +18,10 @@
#include "EditGroupWidget.h"
#include "ui_EditGroupWidgetMain.h"
#if defined(WITH_XC_BROWSER)
#include "browser/BrowserService.h"
#include "ui_EditGroupWidgetBrowser.h"
#endif
#include "core/Config.h"
#include "core/Metadata.h"
@@ -65,12 +70,23 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
, m_editGroupWidgetMain(new QScrollArea())
, m_editGroupWidgetIcons(new EditWidgetIcons())
, m_editWidgetProperties(new EditWidgetProperties())
#if defined(WITH_XC_BROWSER)
, m_browserSettingsChanged(false)
, m_browserUi(new Ui::EditGroupWidgetBrowser())
, m_browserWidget(new QScrollArea())
#endif
, m_group(nullptr)
{
m_mainUi->setupUi(m_editGroupWidgetMain);
addPage(tr("Group"), icons()->icon("document-edit"), m_editGroupWidgetMain);
addPage(tr("Icon"), icons()->icon("preferences-desktop-icons"), m_editGroupWidgetIcons);
#if defined(WITH_XC_BROWSER)
if (config()->get(Config::Browser_Enabled).toBool()) {
addPage(tr("Browser Integration"), icons()->icon("internet-web-browser"), m_browserWidget);
m_browserUi->setupUi(m_browserWidget);
}
#endif
#if defined(WITH_XC_KEESHARE)
addEditPage(new EditGroupPageKeeShare(this));
#endif
@@ -116,6 +132,33 @@ void EditGroupWidget::setupModifiedTracking()
// Icon tab
connect(m_editGroupWidgetIcons, SIGNAL(widgetUpdated()), SLOT(setModified()));
#if defined(WITH_XC_BROWSER)
if (config()->get(Config::Browser_Enabled).toBool()) {
// Browser integration tab
connect(
m_browserUi->browserIntegrationHideEntriesComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setModified()));
connect(m_browserUi->browserIntegrationSkipAutoSubmitComboBox,
SIGNAL(currentIndexChanged(int)),
SLOT(setModified()));
connect(
m_browserUi->browserIntegrationOnlyHttpAuthComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setModified()));
connect(
m_browserUi->browserIntegrationNotHttpAuthComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setModified()));
connect(m_browserUi->browserIntegrationHideEntriesComboBox,
SIGNAL(currentIndexChanged(int)),
SLOT(updateBrowserModified()));
connect(m_browserUi->browserIntegrationSkipAutoSubmitComboBox,
SIGNAL(currentIndexChanged(int)),
SLOT(updateBrowserModified()));
connect(m_browserUi->browserIntegrationOnlyHttpAuthComboBox,
SIGNAL(currentIndexChanged(int)),
SLOT(updateBrowserModified()));
connect(m_browserUi->browserIntegrationNotHttpAuthComboBox,
SIGNAL(currentIndexChanged(int)),
SLOT(updateBrowserModified()));
}
#endif
}
void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<Database>& database)
@@ -170,6 +213,37 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
page.set(m_temporaryGroup.data(), m_db);
}
#ifdef WITH_XC_BROWSER
if (config()->get(Config::Browser_Enabled).toBool()) {
auto inheritHideEntries = false;
auto inheritSkipSubmit = false;
auto inheritOnlyHttp = false;
auto inheritNoHttp = false;
auto parent = group->parentGroup();
if (parent) {
inheritHideEntries = parent->resolveCustomDataTriState(BrowserService::OPTION_HIDE_ENTRY);
inheritSkipSubmit = parent->resolveCustomDataTriState(BrowserService::OPTION_SKIP_AUTO_SUBMIT);
inheritOnlyHttp = parent->resolveCustomDataTriState(BrowserService::OPTION_ONLY_HTTP_AUTH);
inheritNoHttp = parent->resolveCustomDataTriState(BrowserService::OPTION_NOT_HTTP_AUTH);
}
addTriStateItems(m_browserUi->browserIntegrationHideEntriesComboBox, inheritHideEntries);
addTriStateItems(m_browserUi->browserIntegrationSkipAutoSubmitComboBox, inheritSkipSubmit);
addTriStateItems(m_browserUi->browserIntegrationOnlyHttpAuthComboBox, inheritOnlyHttp);
addTriStateItems(m_browserUi->browserIntegrationNotHttpAuthComboBox, inheritNoHttp);
m_browserUi->browserIntegrationHideEntriesComboBox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_HIDE_ENTRY, false)));
m_browserUi->browserIntegrationSkipAutoSubmitComboBox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_SKIP_AUTO_SUBMIT, false)));
m_browserUi->browserIntegrationOnlyHttpAuthComboBox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_ONLY_HTTP_AUTH, false)));
m_browserUi->browserIntegrationNotHttpAuthComboBox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_NOT_HTTP_AUTH, false)));
}
#endif
setCurrentPage(0);
m_mainUi->editName->setFocus();
@@ -217,6 +291,27 @@ void EditGroupWidget::apply()
page.assign();
}
#ifdef WITH_XC_BROWSER
if (config()->get(Config::Browser_Enabled).toBool()) {
if (!m_browserSettingsChanged) {
return;
}
m_temporaryGroup->setCustomDataTriState(
BrowserService::OPTION_HIDE_ENTRY,
triStateFromIndex(m_browserUi->browserIntegrationHideEntriesComboBox->currentIndex()));
m_temporaryGroup->setCustomDataTriState(
BrowserService::OPTION_SKIP_AUTO_SUBMIT,
triStateFromIndex(m_browserUi->browserIntegrationSkipAutoSubmitComboBox->currentIndex()));
m_temporaryGroup->setCustomDataTriState(
BrowserService::OPTION_ONLY_HTTP_AUTH,
triStateFromIndex(m_browserUi->browserIntegrationOnlyHttpAuthComboBox->currentIndex()));
m_temporaryGroup->setCustomDataTriState(
BrowserService::OPTION_NOT_HTTP_AUTH,
triStateFromIndex(m_browserUi->browserIntegrationNotHttpAuthComboBox->currentIndex()));
}
#endif
// Icons add/remove are applied globally outside the transaction!
m_group->copyDataFrom(m_temporaryGroup.data());
@@ -243,7 +338,7 @@ void EditGroupWidget::cancel()
if (isModified()) {
auto result = MessageBox::question(this,
QString(),
tr("Entry has unsaved changes"),
tr("Group has unsaved changes"),
MessageBox::Cancel | MessageBox::Save | MessageBox::Discard,
MessageBox::Cancel);
if (result == MessageBox::Cancel) {
@@ -259,6 +354,13 @@ void EditGroupWidget::cancel()
emit editFinished(false);
}
#ifdef WITH_XC_BROWSER
void EditGroupWidget::updateBrowserModified()
{
m_browserSettingsChanged = true;
}
#endif
void EditGroupWidget::clear()
{
m_group = nullptr;