Skip to content

Commit

Permalink
Fix crash in Group Edit after enabling Browser Integration (#8778)
Browse files Browse the repository at this point in the history
Fixes #8775
  • Loading branch information
varjolintu committed Dec 19, 2022
1 parent 2dbb29f commit ad773c5
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 178 deletions.
4 changes: 0 additions & 4 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3084,10 +3084,6 @@ Would you like to correct it?</source>
</context>
<context>
<name>EditGroupWidgetBrowser</name>
<message>
<source>Edit Group</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>These settings affect to the group&apos;s behaviour with the browser extension.</source>
<translation type="unfinished"></translation>
Expand Down
68 changes: 42 additions & 26 deletions src/gui/group/EditGroupWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2022 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
Expand Down Expand Up @@ -73,7 +73,7 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
#if defined(WITH_XC_BROWSER)
, m_browserSettingsChanged(false)
, m_browserUi(new Ui::EditGroupWidgetBrowser())
, m_browserWidget(new QScrollArea())
, m_browserWidget(new QWidget(this))
#endif
, m_group(nullptr)
{
Expand All @@ -83,8 +83,7 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
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);
initializeBrowserPage();
}
#endif
#if defined(WITH_XC_KEESHARE)
Expand Down Expand Up @@ -135,28 +134,7 @@ void EditGroupWidget::setupModifiedTracking()

#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()));
setupBrowserModifiedTracking();
}
#endif
}
Expand Down Expand Up @@ -230,6 +208,14 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
inheritOmitWww = parent->resolveCustomDataTriState(BrowserService::OPTION_OMIT_WWW);
}

// If the page has not been created at all, some of the elements are null
if (m_browserUi->browserIntegrationHideEntriesComboBox == nullptr
&& config()->get(Config::Browser_Enabled).toBool()) {
initializeBrowserPage();
setupBrowserModifiedTracking();
}

setPageHidden(m_browserWidget, false);
addTriStateItems(m_browserUi->browserIntegrationHideEntriesComboBox, inheritHideEntries);
addTriStateItems(m_browserUi->browserIntegrationSkipAutoSubmitComboBox, inheritSkipSubmit);
addTriStateItems(m_browserUi->browserIntegrationOnlyHttpAuthComboBox, inheritOnlyHttp);
Expand All @@ -246,6 +232,8 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_NOT_HTTP_AUTH, false)));
m_browserUi->browserIntegrationOmitWwwCombobox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_OMIT_WWW, false)));
} else if (hasPage(m_browserWidget)) {
setPageHidden(m_browserWidget, true);
}
#endif

Expand Down Expand Up @@ -363,6 +351,34 @@ void EditGroupWidget::cancel()
}

#ifdef WITH_XC_BROWSER
void EditGroupWidget::initializeBrowserPage()
{
addPage(tr("Browser Integration"), icons()->icon("internet-web-browser"), m_browserWidget);
m_browserUi->setupUi(m_browserWidget);
}

void EditGroupWidget::setupBrowserModifiedTracking()
{
// 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()));
}

void EditGroupWidget::updateBrowserModified()
{
m_browserSettingsChanged = true;
Expand Down
6 changes: 4 additions & 2 deletions src/gui/group/EditGroupWidget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2022 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
Expand Down Expand Up @@ -72,6 +72,8 @@ private slots:
void save();
void cancel();
#ifdef WITH_XC_BROWSER
void initializeBrowserPage();
void setupBrowserModifiedTracking();
void updateBrowserModified();
#endif

Expand All @@ -89,7 +91,7 @@ private slots:
#ifdef WITH_XC_BROWSER
bool m_browserSettingsChanged;
const QScopedPointer<Ui::EditGroupWidgetBrowser> m_browserUi;
QPointer<QScrollArea> m_browserWidget;
QWidget* const m_browserWidget;
#endif

QScopedPointer<Group> m_temporaryGroup;
Expand Down
Loading

0 comments on commit ad773c5

Please sign in to comment.