Fix crash in Group Edit after enabling Browser Integration (#8778)

Fixes https://github.com/keepassxreboot/keepassxc/issues/8775
This commit is contained in:
Sami Vänttinen 2022-12-19 05:56:00 +02:00 committed by Jonathan White
parent 3383882b95
commit 90c63483c1
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
4 changed files with 164 additions and 178 deletions

View File

@ -3084,10 +3084,6 @@ Would you like to correct it?</source>
</context> </context>
<context> <context>
<name>EditGroupWidgetBrowser</name> <name>EditGroupWidgetBrowser</name>
<message>
<source>Edit Group</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>These settings affect to the group&apos;s behaviour with the browser extension.</source> <source>These settings affect to the group&apos;s behaviour with the browser extension.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -73,7 +73,7 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
#if defined(WITH_XC_BROWSER) #if defined(WITH_XC_BROWSER)
, m_browserSettingsChanged(false) , m_browserSettingsChanged(false)
, m_browserUi(new Ui::EditGroupWidgetBrowser()) , m_browserUi(new Ui::EditGroupWidgetBrowser())
, m_browserWidget(new QScrollArea()) , m_browserWidget(new QWidget(this))
#endif #endif
, m_group(nullptr) , m_group(nullptr)
{ {
@ -83,8 +83,7 @@ EditGroupWidget::EditGroupWidget(QWidget* parent)
addPage(tr("Icon"), icons()->icon("preferences-desktop-icons"), m_editGroupWidgetIcons); addPage(tr("Icon"), icons()->icon("preferences-desktop-icons"), m_editGroupWidgetIcons);
#if defined(WITH_XC_BROWSER) #if defined(WITH_XC_BROWSER)
if (config()->get(Config::Browser_Enabled).toBool()) { if (config()->get(Config::Browser_Enabled).toBool()) {
addPage(tr("Browser Integration"), icons()->icon("internet-web-browser"), m_browserWidget); initializeBrowserPage();
m_browserUi->setupUi(m_browserWidget);
} }
#endif #endif
#if defined(WITH_XC_KEESHARE) #if defined(WITH_XC_KEESHARE)
@ -135,28 +134,7 @@ void EditGroupWidget::setupModifiedTracking()
#if defined(WITH_XC_BROWSER) #if defined(WITH_XC_BROWSER)
if (config()->get(Config::Browser_Enabled).toBool()) { if (config()->get(Config::Browser_Enabled).toBool()) {
// Browser integration tab setupBrowserModifiedTracking();
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 #endif
} }
@ -230,6 +208,14 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
inheritOmitWww = parent->resolveCustomDataTriState(BrowserService::OPTION_OMIT_WWW); 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->browserIntegrationHideEntriesComboBox, inheritHideEntries);
addTriStateItems(m_browserUi->browserIntegrationSkipAutoSubmitComboBox, inheritSkipSubmit); addTriStateItems(m_browserUi->browserIntegrationSkipAutoSubmitComboBox, inheritSkipSubmit);
addTriStateItems(m_browserUi->browserIntegrationOnlyHttpAuthComboBox, inheritOnlyHttp); addTriStateItems(m_browserUi->browserIntegrationOnlyHttpAuthComboBox, inheritOnlyHttp);
@ -246,6 +232,8 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_NOT_HTTP_AUTH, false))); indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_NOT_HTTP_AUTH, false)));
m_browserUi->browserIntegrationOmitWwwCombobox->setCurrentIndex( m_browserUi->browserIntegrationOmitWwwCombobox->setCurrentIndex(
indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_OMIT_WWW, false))); indexFromTriState(group->resolveCustomDataTriState(BrowserService::OPTION_OMIT_WWW, false)));
} else if (hasPage(m_browserWidget)) {
setPageHidden(m_browserWidget, true);
} }
#endif #endif
@ -363,6 +351,34 @@ void EditGroupWidget::cancel()
} }
#ifdef WITH_XC_BROWSER #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() void EditGroupWidget::updateBrowserModified()
{ {
m_browserSettingsChanged = true; m_browserSettingsChanged = true;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -72,6 +72,8 @@ private slots:
void save(); void save();
void cancel(); void cancel();
#ifdef WITH_XC_BROWSER #ifdef WITH_XC_BROWSER
void initializeBrowserPage();
void setupBrowserModifiedTracking();
void updateBrowserModified(); void updateBrowserModified();
#endif #endif
@ -89,7 +91,7 @@ private:
#ifdef WITH_XC_BROWSER #ifdef WITH_XC_BROWSER
bool m_browserSettingsChanged; bool m_browserSettingsChanged;
const QScopedPointer<Ui::EditGroupWidgetBrowser> m_browserUi; const QScopedPointer<Ui::EditGroupWidgetBrowser> m_browserUi;
QPointer<QScrollArea> m_browserWidget; QWidget* const m_browserWidget;
#endif #endif
QScopedPointer<Group> m_temporaryGroup; QScopedPointer<Group> m_temporaryGroup;

View File

@ -1,34 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>EditGroupWidgetBrowser</class> <class>EditGroupWidgetBrowser</class>
<widget class="QScrollArea" name="EditGroupWidgetBrowser"> <widget class="QWidget" name="EditGroupWidgetBrowser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>539</width>
<height>523</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit Group</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="container">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -59,127 +32,126 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,1" columnstretch="0,1" rowminimumheight="0,0,0,1"> <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,1" columnstretch="0,1" rowminimumheight="0,0,0,1">
   <property name="leftMargin"> <property name="leftMargin">
   <number>0</number> <number>0</number>
   </property> </property>
   <property name="topMargin"> <property name="topMargin">
   <number>10</number> <number>10</number>
   </property> </property>
   <property name="rightMargin"> <property name="rightMargin">
   <number>0</number> <number>0</number>
   </property> </property>
   <property name="bottomMargin"> <property name="bottomMargin">
  <number>0</number> <number>0</number>
  </property> </property>
  <property name="horizontalSpacing"> <property name="horizontalSpacing">
  <number>10</number> <number>10</number>
  </property> </property>
  <property name="verticalSpacing"> <property name="verticalSpacing">
  <number>8</number> <number>8</number>
  </property> </property>
  <item row="0" column="0"> <item row="0" column="0">
  <widget class="QLabel" name="browserIntegrationHideEntriesLabel"> <widget class="QLabel" name="browserIntegrationHideEntriesLabel">
  <property name="text"> <property name="text">
  <string>Hide entries from browser extension:</string> <string>Hide entries from browser extension:</string>
  </property> </property>
  <property name="alignment"> <property name="alignment">
  <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="0" column="1"> <item row="0" column="1">
  <widget class="QComboBox" name="browserIntegrationHideEntriesComboBox"> <widget class="QComboBox" name="browserIntegrationHideEntriesComboBox">
  <property name="accessibleName"> <property name="accessibleName">
  <string>Hide entries from browser extension toggle for this and sub groups</string> <string>Hide entries from browser extension toggle for this and sub groups</string>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="1" column="0"> <item row="1" column="0">
  <widget class="QLabel" name="browserIntegrationSkipAutoSubmitLabel"> <widget class="QLabel" name="browserIntegrationSkipAutoSubmitLabel">
  <property name="text"> <property name="text">
  <string>Skip Auto-Submit for entries:</string> <string>Skip Auto-Submit for entries:</string>
  </property> </property>
  <property name="alignment"> <property name="alignment">
  <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="1" column="1"> <item row="1" column="1">
  <widget class="QComboBox" name="browserIntegrationSkipAutoSubmitComboBox"> <widget class="QComboBox" name="browserIntegrationSkipAutoSubmitComboBox">
  <property name="accessibleName"> <property name="accessibleName">
  <string>Skip Auto-Submit toggle for this and sub groups</string> <string>Skip Auto-Submit toggle for this and sub groups</string>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="2" column="0"> <item row="2" column="0">
  <widget class="QLabel" name="browserIntegrationOnlyHttpAuthLabel"> <widget class="QLabel" name="browserIntegrationOnlyHttpAuthLabel">
  <property name="text"> <property name="text">
  <string>Use entries only with HTTP Basic Auth:</string> <string>Use entries only with HTTP Basic Auth:</string>
  </property> </property>
  <property name="alignment"> <property name="alignment">
  <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="2" column="1"> <item row="2" column="1">
  <widget class="QComboBox" name="browserIntegrationOnlyHttpAuthComboBox"> <widget class="QComboBox" name="browserIntegrationOnlyHttpAuthComboBox">
  <property name="accessibleName"> <property name="accessibleName">
  <string>Only HTTP Auth toggle for this and sub groups</string> <string>Only HTTP Auth toggle for this and sub groups</string>
  </property> </property>
  </widget> </widget>
  </item> </item>
  <item row="3" column="0"> <item row="3" column="0">
   <widget class="QLabel" name="browserIntegrationNotHttpAuthLabel"> <widget class="QLabel" name="browserIntegrationNotHttpAuthLabel">
   <property name="text"> <property name="text">
   <string>Do not use entries with HTTP Basic Auth:</string> <string>Do not use entries with HTTP Basic Auth:</string>
   </property> </property>
   <property name="alignment"> <property name="alignment">
   <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
   </property> </property>
   </widget> </widget>
   </item> </item>
   <item row="3" column="1"> <item row="3" column="1">
   <widget class="QComboBox" name="browserIntegrationNotHttpAuthComboBox"> <widget class="QComboBox" name="browserIntegrationNotHttpAuthComboBox">
   <property name="accessibleName"> <property name="accessibleName">
   <string>Do not use HTTP Auth toggle for this and sub groups</string> <string>Do not use HTTP Auth toggle for this and sub groups</string>
   </property> </property>
   </widget> </widget>
   </item> </item>
<item row="4" column="0"> <item row="4" column="0">
   <widget class="QLabel" name="browserIntegrationOmitWwwLabel"> <widget class="QLabel" name="browserIntegrationOmitWwwLabel">
   <property name="text"> <property name="text">
   <string>Omit WWW subdomain from matching:</string> <string>Omit WWW subdomain from matching:</string>
   </property> </property>
   <property name="alignment"> <property name="alignment">
   <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
   </property> </property>
   </widget> </widget>
   </item> </item>
   <item row="4" column="1"> <item row="4" column="1">
   <widget class="QComboBox" name="browserIntegrationOmitWwwCombobox"> <widget class="QComboBox" name="browserIntegrationOmitWwwCombobox">
   <property name="accessibleName"> <property name="accessibleName">
   <string>Omit WWW subdomain from matching toggle for this and sub groups</string> <string>Omit WWW subdomain from matching toggle for this and sub groups</string>
   </property> </property>
   </widget> </widget>
   </item> </item>
   <item row="5" column="0"> <item row="5" column="0">
   <spacer name="verticalSpacer_1"> <spacer name="verticalSpacer_1">
   <property name="orientation"> <property name="orientation">
   <enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
   </property> </property>
   <property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
   <size> <size>
   <width>20</width> <width>20</width>
   <height>40</height> <height>40</height>
  </size> </size>
  </property> </property>
  </spacer> </spacer>
  </item> </item>
  </layout> </layout>
 </item> </item>
</layout> </layout>
</widget> </widget>
</widget>
<tabstops> <tabstops>
<tabstop>browserIntegrationHideEntriesComboBox</tabstop> <tabstop>browserIntegrationHideEntriesComboBox</tabstop>
<tabstop>browserIntegrationSkipAutoSubmitComboBox</tabstop> <tabstop>browserIntegrationSkipAutoSubmitComboBox</tabstop>