Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kontact
Commits
2a94fe45
Verified
Commit
2a94fe45
authored
Jun 30, 2021
by
Alexander Lohnau
💬
Browse files
Cleanup unused code from imports
parent
71d96dff
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/ksettingsdialog/dialog.cpp
View file @
2a94fe45
...
...
@@ -29,15 +29,8 @@
namespace
KSettings
{
Dialog
::
Dialog
(
QWidget
*
parent
)
:
Dialog
(
QStringList
{},
parent
)
{
}
Dialog
::
Dialog
(
const
QStringList
&
components
,
QWidget
*
parent
)
:
KCMultiDialog
(
*
new
DialogPrivate
(
this
),
new
KPageWidget
,
parent
)
{
Q_D
(
Dialog
);
d
->
components
=
components
;
}
Dialog
::~
Dialog
()
...
...
@@ -59,17 +52,10 @@ void Dialog::showEvent(QShowEvent *)
d
->
firstshow
=
false
;
setUpdatesEnabled
(
true
);
}
for
(
const
QString
&
compName
:
qAsConst
(
d
->
components
))
{
KSharedConfig
::
Ptr
config
=
KSharedConfig
::
openConfig
(
compName
+
QLatin1String
(
"rc"
));
config
->
sync
();
}
}
DialogPrivate
::
DialogPrivate
(
Dialog
*
parent
)
:
KCMultiDialogPrivate
(
parent
)
,
firstshow
(
true
)
,
pluginStateDirty
(
0
)
{
}
...
...
@@ -106,110 +92,22 @@ void DialogPrivate::createDialogFromServices()
{
Q_Q
(
Dialog
);
for
(
const
auto
&
pair
:
qAsC
onst
(
componentsMetaData
))
{
for
(
const
auto
&
pair
:
std
::
as_c
onst
(
componentsMetaData
))
{
const
KPluginMetaData
&
parentComponentMetaData
=
pair
.
first
;
const
QVector
<
KPluginMetaData
>
&
kcmsMetaData
=
pair
.
second
;
KPageWidgetItem
*
parentItem
=
createPageItem
(
nullptr
,
parentComponentMetaData
.
name
(),
parentComponentMetaData
.
description
(),
parentComponentMetaData
.
iconName
());
// connectItemCheckBox(item, pinfo, pinfo.isPluginEnabled());
for
(
const
KPluginMetaData
&
metaData
:
kcmsMetaData
)
{
q
->
addModule
(
metaData
,
parentItem
);
}
}
QObject
::
connect
(
q
,
QOverload
<>::
of
(
&
KCMultiDialog
::
configCommitted
),
q
,
[
this
]()
{
updateConfiguration
();
});
QObject
::
connect
(
q
,
QOverload
<
const
QByteArray
&>::
of
(
&
KCMultiDialog
::
configCommitted
),
q
,
[](
const
QByteArray
&
componentName
)
{
KSharedConfig
::
Ptr
config
=
KSharedConfig
::
openConfig
(
QString
::
fromLatin1
(
componentName
)
+
QLatin1String
(
"rc"
));
config
->
reparseConfiguration
();
});
}
void
DialogPrivate
::
updateConfiguration
()
{
Q_Q
(
Dialog
);
const
QHash
<
KPageWidgetItem
*
,
KPluginInfo
>::
Iterator
endIt
=
pluginForItem
.
end
();
QHash
<
KPageWidgetItem
*
,
KPluginInfo
>::
Iterator
it
=
pluginForItem
.
begin
();
for
(;
it
!=
endIt
;
++
it
)
{
KPageWidgetItem
*
item
=
it
.
key
();
KPluginInfo
pinfo
=
it
.
value
();
pinfo
.
setPluginEnabled
(
item
->
isChecked
());
pinfo
.
save
();
}
if
(
pluginStateDirty
>
0
)
{
Q_EMIT
q
->
pluginSelectionChanged
();
pluginStateDirty
=
0
;
}
}
void
DialogPrivate
::
_k_clientChanged
()
{
if
(
pluginStateDirty
>
0
)
{
Q_Q
(
Dialog
);
q
->
buttonBox
()
->
button
(
QDialogButtonBox
::
Apply
)
->
setEnabled
(
true
);
}
else
{
KCMultiDialogPrivate
::
_k_clientChanged
();
}
}
void
DialogPrivate
::
_k_updateEnabledState
(
bool
enabled
)
{
Q_Q
(
Dialog
);
KPageWidgetItem
*
item
=
qobject_cast
<
KPageWidgetItem
*>
(
q
->
sender
());
if
(
!
item
)
{
qCWarning
(
KONTACT_LOG
)
<<
"invalid sender"
;
return
;
}
// iterate over all child KPageWidgetItem objects and check whether they need to be enabled/disabled
const
KPageWidgetModel
*
model
=
qobject_cast
<
const
KPageWidgetModel
*>
(
q
->
pageWidget
()
->
model
());
Q_ASSERT
(
model
);
QModelIndex
index
=
model
->
index
(
item
);
if
(
!
index
.
isValid
())
{
qCWarning
(
KONTACT_LOG
)
<<
"could not find item in model"
;
return
;
}
const
KPluginInfo
&
pinfo
=
pluginForItem
.
value
(
item
);
if
(
!
pinfo
.
isValid
())
{
qCWarning
(
KONTACT_LOG
)
<<
"could not find KPluginInfo in item"
;
return
;
}
if
(
pinfo
.
isPluginEnabled
()
!=
enabled
)
{
++
pluginStateDirty
;
}
else
{
--
pluginStateDirty
;
}
if
(
pluginStateDirty
<
2
)
{
_k_clientChanged
();
}
QModelIndex
firstborn
=
model
->
index
(
0
,
0
,
index
);
if
(
firstborn
.
isValid
())
{
// change all children
index
=
firstborn
;
QStack
<
QModelIndex
>
stack
;
while
(
index
.
isValid
())
{
KPageWidgetItem
*
item
=
model
->
item
(
index
);
item
->
setEnabled
(
enabled
);
firstborn
=
model
->
index
(
0
,
0
,
index
);
if
(
firstborn
.
isValid
())
{
stack
.
push
(
index
);
index
=
firstborn
;
}
else
{
index
=
index
.
sibling
(
index
.
row
()
+
1
,
0
);
while
(
!
index
.
isValid
()
&&
!
stack
.
isEmpty
())
{
index
=
stack
.
pop
();
index
=
index
.
sibling
(
index
.
row
()
+
1
,
0
);
}
}
}
}
}
}
// namespace
#include
"moc_dialog.cpp"
src/ksettingsdialog/dialog.h
View file @
2a94fe45
...
...
@@ -11,96 +11,22 @@
#include
"./kcmultidialog.h"
#include
<KService>
template
<
class
T
>
class
QList
;
namespace
KSettings
{
class
DialogPrivate
;
/**
* @short Generic configuration dialog that works over component boundaries
*
* For more information see \ref KSettings.
*
* This class aims to standardize the use of configuration dialogs in applications.
* Especially when using KParts and/or Plugins you face problems creating consistent
* config dialogs.
*
* To show a configuration dialog you only have to call the show method and be
* done with it. A code example:
*
* You initialize @c m_cfgdlg with
* @code
* m_cfgdlg = new Dialog(this);
* @endcode
*
* If you use a KPart that was not especially designed for your app you can use
* the second constructor:
* @code
* QStringList kpartslist;
* for (all my kparts) {
* kpartslist += m_mypart->componentData().componentName();
* }
*
* m_cfgdlg = new Dialog(kpartslist, this);
* @endcode
*
* and ideally you can connect the "Configure MyApp" action to the config
* dialog show() slot:
* @code
* KStandardAction::preferences(m_cfgdlg, &QDialog::show, actionCollection());
* @endcode
*
* If you need to be informed when the config is changed by the dialog, you can
* connect to the @c KCMultiDialog::configCommitted() signal (which emits the
* component name as its argument):
* @code
* connect(m_cfgdlg, QOverload<const QByteArray &>::of(&KCMultiDialog::configCommitted), this, &Foo::slotConfigUpdated);
* @endcode
*
* @see KSettings.
*
* @author Matthias Kretz <kretz@kde.org>
*/
class
Dialog
:
public
KCMultiDialog
{
friend
class
PageNode
;
Q_DECLARE_PRIVATE
(
Dialog
)
Q_OBJECT
public:
/**
* Construct a new Preferences Dialog for the application. It uses all
* KCMs with X-KDE-ParentApp set to QCoreApplication::instance()->applicationName().
*
* @param content Select whether you want a static or configurable
* config dialog.
* @param parent The parent is only used as the parent for the
* dialog - centering the dialog over the parent
* widget.
*/
explicit
Dialog
(
QWidget
*
parent
=
nullptr
);
/**
* Construct a new Preferences Dialog with the pages for the selected
* instance names. For example if you want to have the configuration
* pages for the kviewviewer KPart you would pass a
* QStringList consisting of only the name of the part "kviewviewer".
*
* @param components A list of the names of the components that your
* config dialog should merge the config pages in.
* @param parent The parent is only used as the parent for the
* dialog - centering the dialog over the parent
* widget.
*/
explicit
Dialog
(
const
QStringList
&
components
,
QWidget
*
parent
=
nullptr
);
~
Dialog
()
override
;
/**
*
bla bla bla
*
Adds a page with parentPluginMetaData used for title & icon of the component page and pluginMetaData for it's subpages
*/
void
addPluginComponent
(
const
KPluginMetaData
&
parentPluginMetaData
,
const
QVector
<
KPluginMetaData
>
&
pluginMetaData
);
...
...
@@ -119,10 +45,6 @@ Q_SIGNALS:
* requested.
*/
void
pluginSelectionChanged
();
private:
// Q_PRIVATE_SLOT(d_func(), void _k_configureTree())
Q_PRIVATE_SLOT
(
d_func
(),
void
_k_updateEnabledState
(
bool
))
};
}
...
...
src/ksettingsdialog/dialog_p.h
View file @
2a94fe45
...
...
@@ -30,38 +30,13 @@ class DialogPrivate : public KCMultiDialogPrivate
protected:
DialogPrivate
(
Dialog
*
parent
);
QHash
<
KPageWidgetItem
*
,
KPluginInfo
>
pluginForItem
;
QStringList
registeredComponents
;
QSet
<
KPluginMetaData
>
kcmsMetaData
;
QList
<
QPair
<
KPluginMetaData
,
QVector
<
KPluginMetaData
>>>
componentsMetaData
;
QStringList
arguments
;
QStringList
components
;
bool
firstshow
:
1
;
quint32
pluginStateDirty
:
30
;
// void _k_configureTree();
void
_k_updateEnabledState
(
bool
);
void
updateConfiguration
();
void
_k_clientChanged
()
override
;
bool
firstshow
=
true
;
KPageWidgetItem
*
createPageItem
(
KPageWidgetItem
*
parentItem
,
const
QString
&
name
,
const
QString
&
comment
,
const
QString
&
iconName
);
// void connectItemCheckBox(KPageWidgetItem *item, const KPluginInfo &pinfo, bool isEnabled);
private:
/**
* @internal
* Check whether the plugin associated with this KCM is enabled.
*/
bool
isPluginForKCMEnabled
(
const
KCModuleInfo
*
moduleinfo
,
KPluginInfo
&
pinfo
)
const
;
QSet
<
KCModuleInfo
>
instanceServices
();
QSet
<
KCModuleInfo
>
parentComponentsServices
(
const
QStringList
&
);
/**
* @internal
* This method is called only once. The KCMultiDialog is not created
...
...
src/ksettingsdialog/kcmultidialog.cpp
View file @
2a94fe45
...
...
@@ -229,13 +229,6 @@ KCMultiDialog::KCMultiDialog(QWidget *parent)
d_func
()
->
init
();
}
KCMultiDialog
::
KCMultiDialog
(
KPageWidget
*
pageWidget
,
QWidget
*
parent
,
Qt
::
WindowFlags
flags
)
:
KPageDialog
(
pageWidget
,
parent
,
flags
)
,
d_ptr
(
new
KCMultiDialogPrivate
(
this
))
{
d_func
()
->
init
();
}
KCMultiDialog
::
KCMultiDialog
(
KCMultiDialogPrivate
&
dd
,
KPageWidget
*
pageWidget
,
QWidget
*
parent
,
Qt
::
WindowFlags
flags
)
:
KPageDialog
(
pageWidget
,
parent
,
flags
)
,
d_ptr
(
&
dd
)
...
...
@@ -337,8 +330,6 @@ void KCMultiDialogPrivate::apply()
for
(
const
QString
&
name
:
qAsConst
(
updatedComponents
))
{
Q_EMIT
q
->
configCommitted
(
name
.
toLatin1
());
}
Q_EMIT
q
->
configCommitted
();
}
void
KCMultiDialog
::
slotApplyClicked
()
...
...
src/ksettingsdialog/kcmultidialog.h
View file @
2a94fe45
...
...
@@ -30,16 +30,7 @@ class KCMultiDialog : public KPageDialog
Q_DECLARE_PRIVATE
(
KCMultiDialog
)
public:
/**
* Constructs a new KCMultiDialog
*
* @param parent The parent widget
**/
explicit
KCMultiDialog
(
QWidget
*
parent
=
nullptr
);
/**
* Destructor
**/
~
KCMultiDialog
()
override
;
/**
...
...
@@ -49,20 +40,7 @@ public:
*/
KPageWidgetItem
*
addModule
(
const
KPluginMetaData
&
metaData
,
KPageWidgetItem
*
parent
=
nullptr
);
/**
* Removes all modules from the dialog.
*/
void
clear
();
Q_SIGNALS:
/**
* Emitted after all KCModules have been told to save their configuration.
*
* The applyClicked and okClicked signals are emitted before the
* configuration is saved.
*/
void
configCommitted
();
/**
* Emitted after the KCModules have been told to save their configuration.
* It is emitted once for every instance the KCMs that were changed belong
...
...
@@ -84,7 +62,6 @@ protected:
/**
* This constructor can be used by subclasses to provide a custom KPageWidget.
*/
KCMultiDialog
(
KPageWidget
*
pageWidget
,
QWidget
*
parent
,
Qt
::
WindowFlags
flags
=
Qt
::
WindowFlags
());
KCMultiDialog
(
KCMultiDialogPrivate
&
dd
,
KPageWidget
*
pageWidget
,
QWidget
*
parent
,
Qt
::
WindowFlags
flags
=
Qt
::
WindowFlags
());
KCMultiDialogPrivate
*
const
d_ptr
;
...
...
@@ -169,7 +146,7 @@ public:
}
}
UnboundScrollArea
(
QWidget
*
w
)
explicit
UnboundScrollArea
(
QWidget
*
w
)
:
QScrollArea
(
w
)
{
}
...
...
src/ksettingsdialog/kcmultidialog_p.h
View file @
2a94fe45
...
...
@@ -44,7 +44,7 @@ protected:
virtual
void
_k_clientChanged
();
void
_k_dialogClosed
();
KCMultiDialog
*
q_ptr
;
KCMultiDialog
*
const
q_ptr
;
private:
void
init
();
...
...
src/mainwindow.cpp
View file @
2a94fe45
...
...
@@ -714,7 +714,7 @@ void MainWindow::slotPreferences()
static
Kontact
::
KontactConfigureDialog
*
dlg
=
nullptr
;
if
(
!
dlg
)
{
dlg
=
new
Kontact
::
KontactConfigureDialog
(
this
);
connect
(
dlg
,
QOverload
<
const
QByteArray
&>::
of
(
&
KSettings
::
Dialog
::
configCommitted
)
,
this
,
[
this
](
const
QByteArray
&
componentName
)
{
connect
(
dlg
,
&
KSettings
::
Dialog
::
configCommitted
,
this
,
[
this
](
const
QByteArray
&
componentName
)
{
if
(
componentName
==
QByteArrayLiteral
(
"kontact"
))
{
MainWindow
::
updateConfig
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment