Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
System Settings
Commits
204b44e9
Commit
204b44e9
authored
Oct 13, 2020
by
Nicolas Fella
Browse files
Port view loading to KPluginLoader
Use the modern™ way of loading plugins.
parent
43cb36a4
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/SettingsBase.cpp
View file @
204b44e9
...
...
@@ -33,6 +33,7 @@
#include
<KMessageBox>
#include
<KConfigGroup>
#include
<KCModuleInfo>
#include
<KPluginMetaData>
#include
<KXMLGUIFactory>
#include
<KStandardAction>
#include
<KActionCollection>
...
...
@@ -126,21 +127,30 @@ void SettingsBase::initApplication()
BaseData
::
instance
()
->
setMenuItem
(
rootModule
);
BaseData
::
instance
()
->
setHomeItem
(
homeModule
);
// Load all possible views
const
KService
::
List
pluginObjects
=
KServiceTypeTrader
::
self
()
->
query
(
QStringLiteral
(
"SystemSettingsView"
)
);
for
(
KService
::
Ptr
activeService
:
pluginObjects
)
{
QString
error
;
BaseMode
*
controller
=
activeService
->
createInstance
<
BaseMode
>
(
this
,
{
m_mode
,
m_startupModule
,
m_startupModuleArgs
},
&
error
);
if
(
error
.
isEmpty
()
)
{
possibleViews
.
insert
(
activeService
->
library
(),
controller
);
controller
->
init
(
activeService
);
connect
(
controller
,
&
BaseMode
::
changeToolBarItems
,
this
,
&
SettingsBase
::
changeToolBar
);
connect
(
controller
,
&
BaseMode
::
actionsChanged
,
this
,
&
SettingsBase
::
updateViewActions
);
connect
(
searchText
,
&
KLineEdit
::
textChanged
,
controller
,
&
BaseMode
::
searchChanged
);
connect
(
controller
,
&
BaseMode
::
viewChanged
,
this
,
&
SettingsBase
::
viewChange
);
}
else
{
qCWarning
(
SYSTEMSETTINGS_APP_LOG
)
<<
QStringLiteral
(
"View load error: "
)
+
error
;
const
QVector
<
KPluginMetaData
>
plugins
=
KPluginLoader
::
findPlugins
(
QStringLiteral
(
"systemsettingsview/"
));
for
(
const
KPluginMetaData
&
plugin
:
plugins
)
{
KPluginLoader
loader
(
plugin
.
fileName
());
KPluginFactory
*
factory
=
loader
.
factory
();
if
(
!
factory
)
{
qCWarning
(
SYSTEMSETTINGS_APP_LOG
)
<<
"KPluginFactory could not load the plugin:"
<<
plugin
.
pluginId
()
<<
loader
.
errorString
();
continue
;
}
BaseMode
*
controller
=
factory
->
create
<
BaseMode
>
(
this
,
{
m_mode
,
m_startupModule
,
m_startupModuleArgs
});
if
(
!
controller
)
{
qCWarning
(
SYSTEMSETTINGS_APP_LOG
)
<<
"Error loading plugin"
;
continue
;
}
possibleViews
.
insert
(
plugin
.
pluginId
(),
controller
);
controller
->
init
(
plugin
);
connect
(
controller
,
&
BaseMode
::
changeToolBarItems
,
this
,
&
SettingsBase
::
changeToolBar
);
connect
(
controller
,
&
BaseMode
::
actionsChanged
,
this
,
&
SettingsBase
::
updateViewActions
);
connect
(
searchText
,
&
KLineEdit
::
textChanged
,
controller
,
&
BaseMode
::
searchChanged
);
connect
(
controller
,
&
BaseMode
::
viewChanged
,
this
,
&
SettingsBase
::
viewChange
);
}
searchText
->
completionObject
()
->
setIgnoreCase
(
true
);
searchText
->
completionObject
()
->
setItems
(
BaseData
::
instance
()
->
menuItem
()
->
keywords
()
);
changePlugin
();
...
...
@@ -213,8 +223,8 @@ void SettingsBase::initConfig()
// Get the list of modules
foreach
(
BaseMode
*
mode
,
possibleViews
)
{
mode
->
addConfiguration
(
configDialog
);
QRadioButton
*
radioButton
=
new
QRadioButton
(
mode
->
service
()
->
name
(),
configWidget
.
GbViewStyle
);
radioButton
->
setIcon
(
QIcon
::
fromTheme
(
mode
->
service
()
->
icon
())
);
QRadioButton
*
radioButton
=
new
QRadioButton
(
mode
->
metaData
().
name
(),
configWidget
.
GbViewStyle
);
radioButton
->
setIcon
(
QIcon
::
fromTheme
(
mode
->
metaData
().
iconName
())
);
configLayout
->
addWidget
(
radioButton
);
viewSelection
.
addButton
(
radioButton
,
possibleViews
.
values
().
indexOf
(
mode
)
);
}
...
...
core/BaseMode.cpp
View file @
204b44e9
...
...
@@ -35,7 +35,7 @@ public:
Private
()
{}
QList
<
QAction
*>
actionsList
;
K
Service
::
Ptr
service
;
K
PluginMetaData
metaData
;
MenuItem
*
rootItem
=
nullptr
;
MenuItem
*
homeItem
=
nullptr
;
QString
startupModule
;
...
...
@@ -65,12 +65,12 @@ BaseMode::~BaseMode()
delete
d
;
}
void
BaseMode
::
init
(
const
K
Service
::
Ptr
&
modeService
)
void
BaseMode
::
init
(
const
K
PluginMetaData
metaData
)
{
d
->
rootItem
=
BaseData
::
instance
()
->
menuItem
();
d
->
homeItem
=
BaseData
::
instance
()
->
homeItem
();
d
->
service
=
modeService
;
d
->
config
=
BaseData
::
instance
()
->
configGroup
(
m
odeService
->
library
()
);
d
->
metaData
=
metaData
;
d
->
config
=
BaseData
::
instance
()
->
configGroup
(
m
etaData
.
pluginId
()
);
initEvent
();
connect
(
moduleView
(),
&
ModuleView
::
moduleChanged
,
this
,
&
BaseMode
::
viewChanged
);
}
...
...
@@ -104,9 +104,9 @@ QList<QAction*>& BaseMode::actionsList() const
return
d
->
actionsList
;
}
const
K
Service
::
Ptr
&
BaseMode
::
service
()
const
const
K
PluginMetaData
&
BaseMode
::
metaData
()
const
{
return
d
->
service
;
return
d
->
metaData
;
}
void
BaseMode
::
setShowToolTips
(
bool
show
)
...
...
core/BaseMode.h
View file @
204b44e9
...
...
@@ -22,7 +22,7 @@
#include
<QObject>
#include
<K
Service
>
#include
<K
PluginMetaData
>
class
QAction
;
class
MenuItem
;
...
...
@@ -96,7 +96,7 @@ public:
*
* @param modeService Plugins service object, used for providing extra information to System Settings.
*/
void
init
(
const
K
Service
::
Ptr
&
modeService
);
void
init
(
const
K
PluginMetaData
metaData
);
/**
* Prepares the BaseMode for use.\n
...
...
@@ -167,12 +167,7 @@ public:
*/
virtual
QList
<
QAction
*>&
actionsList
()
const
;
/**
* Provides the service object, which is used to retrieve information for the configuration dialog.
*
* @returns the service object of the plugin.
*/
const
KService
::
Ptr
&
service
()
const
;
const
KPluginMetaData
&
metaData
()
const
;
/**
* tells the config view whether to make use of tooltips or not
...
...
icons/CMakeLists.txt
View file @
204b44e9
...
...
@@ -6,6 +6,8 @@ set( icon_mode_srcs
add_library
(
icon_mode MODULE
${
icon_mode_srcs
}
)
kcoreaddons_desktop_to_json
(
icon_mode settings-icon-view.desktop
)
target_link_libraries
(
icon_mode systemsettingsview
KF5::ItemViews
KF5::KCMUtils
...
...
@@ -14,6 +16,4 @@ target_link_libraries(icon_mode systemsettingsview
KF5::Service
)
install
(
TARGETS icon_mode DESTINATION
${
KDE_INSTALL_PLUGINDIR
}
)
install
(
FILES settings-icon-view.desktop DESTINATION
${
KDE_INSTALL_KSERVICES5DIR
}
)
install
(
TARGETS icon_mode DESTINATION
${
KDE_INSTALL_PLUGINDIR
}
/systemsettingsview
)
icons/IconMode.cpp
View file @
204b44e9
...
...
@@ -34,7 +34,7 @@
#include
<KFileItemDelegate>
#include
<KLocalizedString>
K_PLUGIN_
FACTORY
(
IconModeFactory
,
registerPlugin
<
IconMode
>
();
)
K_PLUGIN_
CLASS_WITH_JSON
(
IconMode
,
"settings-icon-view.json"
)
class
IconMode
::
Private
{
public:
...
...
icons/settings-icon-view.desktop
View file @
204b44e9
[Desktop Entry]
Icon=view-list-icons
Type=Service
X-KDE-ServiceTypes=SystemSettingsView
X-KDE-Library=icon_mode
X-KDE-Keywords=System Settings
...
...
sidebar/CMakeLists.txt
View file @
204b44e9
...
...
@@ -5,6 +5,8 @@ set( sidebar_mode_srcs
add_library
(
systemsettings_sidebar_mode MODULE
${
sidebar_mode_srcs
}
)
kcoreaddons_desktop_to_json
(
systemsettings_sidebar_mode settings-sidebar-view.desktop
)
target_link_libraries
(
systemsettings_sidebar_mode systemsettingsview
KF5::ItemViews
KF5::ItemModels
...
...
@@ -21,7 +23,6 @@ target_link_libraries(systemsettings_sidebar_mode systemsettingsview
Qt5::QuickWidgets
)
install
(
TARGETS systemsettings_sidebar_mode DESTINATION
${
KDE_INSTALL_PLUGINDIR
}
)
install
(
FILES settings-sidebar-view.desktop DESTINATION
${
KDE_INSTALL_KSERVICES5DIR
}
)
install
(
TARGETS systemsettings_sidebar_mode DESTINATION
${
KDE_INSTALL_PLUGINDIR
}
/systemsettingsview
)
install
(
DIRECTORY package/ DESTINATION
${
KDE_INSTALL_DATAROOTDIR
}
/kpackage/genericqml/org.kde.systemsettings.sidebar
)
sidebar/SidebarMode.cpp
View file @
204b44e9
...
...
@@ -59,7 +59,7 @@ namespace KAStats = KActivities::Stats;
using
namespace
KAStats
;
using
namespace
KAStats
::
Terms
;
K_PLUGIN_
FACTORY
(
SidebarModeFactory
,
registerPlugin
<
SidebarMode
>
();
)
K_PLUGIN_
CLASS_WITH_JSON
(
SidebarMode
,
"settings-sidebar-view.json"
)
FocusHackWidget
::
FocusHackWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
...
...
sidebar/settings-sidebar-view.desktop
View file @
204b44e9
[Desktop Entry]
Icon=view-sidetree
Type=Service
X-KDE-ServiceTypes=SystemSettingsView
X-KDE-Library=systemsettings_sidebar_mode
X-KDE-Keywords=System Settings
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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