Commit 204b44e9 authored by Nicolas Fella's avatar Nicolas Fella

Port view loading to KPluginLoader

Use the modern™ way of loading plugins.
parent 43cb36a4
......@@ -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) );
}
......
......@@ -35,7 +35,7 @@ public:
Private() {}
QList<QAction*> actionsList;
KService::Ptr service;
KPluginMetaData metaData;
MenuItem *rootItem = nullptr;
MenuItem *homeItem = nullptr;
QString startupModule;
......@@ -65,12 +65,12 @@ BaseMode::~BaseMode()
delete d;
}
void BaseMode::init( const KService::Ptr &modeService )
void BaseMode::init(const KPluginMetaData metaData)
{
d->rootItem = BaseData::instance()->menuItem();
d->homeItem = BaseData::instance()->homeItem();
d->service = modeService;
d->config = BaseData::instance()->configGroup( modeService->library() );
d->metaData = metaData;
d->config = BaseData::instance()->configGroup( metaData.pluginId() );
initEvent();
connect( moduleView(), &ModuleView::moduleChanged, this, &BaseMode::viewChanged );
}
......@@ -104,9 +104,9 @@ QList<QAction*>& BaseMode::actionsList() const
return d->actionsList;
}
const KService::Ptr& BaseMode::service() const
const KPluginMetaData &BaseMode::metaData() const
{
return d->service;
return d->metaData;
}
void BaseMode::setShowToolTips( bool show)
......
......@@ -22,7 +22,7 @@
#include <QObject>
#include <KService>
#include <KPluginMetaData>
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 KService::Ptr &modeService );
void init(const KPluginMetaData 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
......
......@@ -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 )
......@@ -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:
......
[Desktop Entry]
Icon=view-list-icons
Type=Service
X-KDE-ServiceTypes=SystemSettingsView
X-KDE-Library=icon_mode
X-KDE-Keywords=System Settings
......
......@@ -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)
......@@ -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)
......
[Desktop Entry]
Icon=view-sidetree
Type=Service
X-KDE-ServiceTypes=SystemSettingsView
X-KDE-Library=systemsettings_sidebar_mode
X-KDE-Keywords=System Settings
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment