Changeset View
Changeset View
Standalone View
Standalone View
app/SettingsBase.cpp
Show All 37 Lines | |||||
38 | #include <KActionCollection> | 38 | #include <KActionCollection> | ||
39 | #include <KServiceTypeTrader> | 39 | #include <KServiceTypeTrader> | ||
40 | #include <KToolBar> | 40 | #include <KToolBar> | ||
41 | #include <kwindowconfig.h> | 41 | #include <kwindowconfig.h> | ||
42 | 42 | | |||
43 | #include "BaseData.h" | 43 | #include "BaseData.h" | ||
44 | #include "ModuleView.h" | 44 | #include "ModuleView.h" | ||
45 | 45 | | |||
46 | SettingsBase::SettingsBase( QWidget * parent ) | 46 | SettingsBase::SettingsBase(BaseMode::ApplicationMode mode, QWidget * parent ) | ||
47 | : KXmlGuiWindow(parent) | 47 | : KXmlGuiWindow(parent), | ||
48 | m_mode(mode) | ||||
48 | { | 49 | { | ||
49 | // Ensure delayed loading doesn't cause a crash | 50 | // Ensure delayed loading doesn't cause a crash | ||
50 | activeView = nullptr; | 51 | activeView = nullptr; | ||
51 | aboutDialog = nullptr; | 52 | aboutDialog = nullptr; | ||
52 | configDialog = nullptr; | 53 | configDialog = nullptr; | ||
53 | lostFound = nullptr; | 54 | lostFound = nullptr; | ||
54 | // Prepare the view area | 55 | // Prepare the view area | ||
55 | stackedWidget = new QStackedWidget( this ); | 56 | stackedWidget = new QStackedWidget( this ); | ||
56 | setWindowTitle(i18n("System Settings")); | | |||
57 | setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-system"))); | | |||
58 | setCentralWidget(stackedWidget); | 57 | setCentralWidget(stackedWidget); | ||
59 | setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint ); | 58 | setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint ); | ||
60 | // Initialise search | 59 | // Initialise search | ||
61 | searchText = new KLineEdit( this ); | 60 | searchText = new KLineEdit( this ); | ||
62 | searchText->setClearButtonEnabled( true ); | 61 | searchText->setClearButtonEnabled( true ); | ||
63 | searchText->setPlaceholderText( i18nc( "Search through a list of control modules", "Search" ) ); | 62 | searchText->setPlaceholderText( i18nc( "Search through a list of control modules", "Search" ) ); | ||
64 | searchText->setCompletionMode( KCompletion::CompletionPopup ); | 63 | searchText->setCompletionMode( KCompletion::CompletionPopup ); | ||
65 | 64 | | |||
65 | if (m_mode == BaseMode::InfoCenter) { | ||||
66 | actionCollection()->removeAction(configureAction); | ||||
67 | configureAction = nullptr; | ||||
68 | setWindowTitle(i18n("Info Center")); | ||||
69 | setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo"))); | ||||
70 | } else { | ||||
71 | setWindowTitle(i18n("System Settings")); | ||||
72 | setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-system"))); | ||||
73 | } | ||||
74 | | ||||
66 | spacerWidget = new QWidget( this ); | 75 | spacerWidget = new QWidget( this ); | ||
67 | spacerWidget->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum ); | 76 | spacerWidget->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Maximum ); | ||
68 | // Initialise the window so we don't flicker | 77 | // Initialise the window so we don't flicker | ||
69 | initToolBar(); | 78 | initToolBar(); | ||
70 | // We can now launch the delayed loading safely | 79 | // We can now launch the delayed loading safely | ||
71 | QTimer::singleShot(0, this, &SettingsBase::initApplication); | 80 | QTimer::singleShot(0, this, &SettingsBase::initApplication); | ||
72 | } | 81 | } | ||
73 | 82 | | |||
Show All 10 Lines | 89 | { | |||
84 | const QSize targetSize = QSize(1024, 700); | 93 | const QSize targetSize = QSize(1024, 700); | ||
85 | return targetSize.boundedTo(screenSize); | 94 | return targetSize.boundedTo(screenSize); | ||
86 | 95 | | |||
87 | } | 96 | } | ||
88 | 97 | | |||
89 | void SettingsBase::initApplication() | 98 | void SettingsBase::initApplication() | ||
90 | { | 99 | { | ||
91 | // Prepare the menu of all modules | 100 | // Prepare the menu of all modules | ||
101 | if (m_mode == BaseMode::InfoCenter) { | ||||
102 | categories = KServiceTypeTrader::self()->query(QStringLiteral("KInfoCenterCategory")); | ||||
103 | modules = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-ParentApp] == 'kinfocenter'")); | ||||
104 | } else { | ||||
92 | categories = KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsCategory")); | 105 | categories = KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsCategory")); | ||
93 | modules = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-System-Settings-Parent-Category] != ''")); | 106 | modules = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-System-Settings-Parent-Category] != ''")); | ||
94 | modules += KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsExternalApp")); | 107 | modules += KServiceTypeTrader::self()->query(QStringLiteral("SystemSettingsExternalApp")); | ||
108 | } | ||||
109 | | ||||
95 | rootModule = new MenuItem( true, nullptr ); | 110 | rootModule = new MenuItem( true, nullptr ); | ||
96 | initMenuList(rootModule); | 111 | initMenuList(rootModule); | ||
112 | | ||||
97 | // Handle lost+found modules... | 113 | // Handle lost+found modules... | ||
98 | if (lostFound) { | 114 | if (lostFound) { | ||
99 | for (int i = 0; i < modules.size(); ++i) { | 115 | for (int i = 0; i < modules.size(); ++i) { | ||
100 | const KService::Ptr entry = modules.at(i); | 116 | const KService::Ptr entry = modules.at(i); | ||
101 | MenuItem * infoItem = new MenuItem(false, lostFound); | 117 | MenuItem * infoItem = new MenuItem(false, lostFound); | ||
102 | infoItem->setService( entry ); | 118 | infoItem->setService( entry ); | ||
103 | qCDebug(SYSTEMSETTINGS_APP_LOG) << "Added " << entry->name(); | 119 | qCDebug(SYSTEMSETTINGS_APP_LOG) << "Added " << entry->name(); | ||
104 | } | 120 | } | ||
105 | } | 121 | } | ||
106 | 122 | | |||
107 | // Prepare the Base Data | 123 | // Prepare the Base Data | ||
108 | BaseData::instance()->setMenuItem( rootModule ); | 124 | BaseData::instance()->setMenuItem( rootModule ); | ||
125 | BaseData::instance()->setHomeItem( homeModule ); | ||||
109 | // Load all possible views | 126 | // Load all possible views | ||
110 | const KService::List pluginObjects = KServiceTypeTrader::self()->query( QStringLiteral("SystemSettingsView") ); | 127 | const KService::List pluginObjects = KServiceTypeTrader::self()->query( QStringLiteral("SystemSettingsView") ); | ||
111 | const int nbPlugins = pluginObjects.count(); | 128 | const int nbPlugins = pluginObjects.count(); | ||
112 | for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) { | 129 | for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) { | ||
113 | KService::Ptr activeService = pluginObjects.at( pluginsDone ); | 130 | KService::Ptr activeService = pluginObjects.at( pluginsDone ); | ||
114 | QString error; | 131 | QString error; | ||
115 | BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error); | 132 | BaseMode * controller = activeService->createInstance<BaseMode>(this, {m_mode}, &error); | ||
116 | if( error.isEmpty() ) { | 133 | if( error.isEmpty() ) { | ||
117 | possibleViews.insert( activeService->library(), controller ); | 134 | possibleViews.insert( activeService->library(), controller ); | ||
118 | controller->init( activeService ); | 135 | controller->init( activeService ); | ||
119 | connect(controller, &BaseMode::changeToolBarItems, this, &SettingsBase::changeToolBar); | 136 | connect(controller, &BaseMode::changeToolBarItems, this, &SettingsBase::changeToolBar); | ||
120 | connect(controller, &BaseMode::actionsChanged, this, &SettingsBase::updateViewActions); | 137 | connect(controller, &BaseMode::actionsChanged, this, &SettingsBase::updateViewActions); | ||
121 | connect(searchText, &KLineEdit::textChanged, controller, &BaseMode::searchChanged); | 138 | connect(searchText, &KLineEdit::textChanged, controller, &BaseMode::searchChanged); | ||
122 | connect(controller, &BaseMode::viewChanged, this, &SettingsBase::viewChange); | 139 | connect(controller, &BaseMode::viewChanged, this, &SettingsBase::viewChange); | ||
123 | } else { | 140 | } else { | ||
Show All 9 Lines | |||||
133 | activateWindow(); | 150 | activateWindow(); | ||
134 | } | 151 | } | ||
135 | 152 | | |||
136 | void SettingsBase::initToolBar() | 153 | void SettingsBase::initToolBar() | ||
137 | { | 154 | { | ||
138 | // Fill the toolbar with default actions | 155 | // Fill the toolbar with default actions | ||
139 | // Exit is the very last action | 156 | // Exit is the very last action | ||
140 | quitAction = actionCollection()->addAction( KStandardAction::Quit, QStringLiteral("quit_action"), this, SLOT(close()) ); | 157 | quitAction = actionCollection()->addAction( KStandardAction::Quit, QStringLiteral("quit_action"), this, SLOT(close()) ); | ||
158 | | ||||
141 | // Configure goes at the end | 159 | // Configure goes at the end | ||
142 | configureAction = actionCollection()->addAction( KStandardAction::Preferences, QStringLiteral("configure"), this, SLOT(configShow()) ); | 160 | configureAction = actionCollection()->addAction( KStandardAction::Preferences, QStringLiteral("configure"), this, SLOT(configShow()) ); | ||
143 | configureAction->setText( i18n("Configure...") ); | 161 | configureAction->setText( i18n("Configure...") ); | ||
144 | // Help after it | 162 | // Help after it | ||
145 | initHelpMenu(); | 163 | initHelpMenu(); | ||
146 | configureAction->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure"))); | 164 | configureAction->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure"))); | ||
147 | 165 | | |||
166 | | ||||
148 | // Then a spacer so the search line-edit is kept separate | 167 | // Then a spacer so the search line-edit is kept separate | ||
149 | spacerAction = new QWidgetAction( this ); | 168 | spacerAction = new QWidgetAction( this ); | ||
150 | spacerAction->setDefaultWidget(spacerWidget); | 169 | spacerAction->setDefaultWidget(spacerWidget); | ||
151 | actionCollection()->addAction( QStringLiteral("spacer"), spacerAction ); | 170 | actionCollection()->addAction( QStringLiteral("spacer"), spacerAction ); | ||
152 | // Finally the search line-edit | 171 | // Finally the search line-edit | ||
153 | searchAction = new QWidgetAction( this ); | 172 | searchAction = new QWidgetAction( this ); | ||
154 | searchAction->setDefaultWidget(searchText); | 173 | searchAction->setDefaultWidget(searchText); | ||
155 | connect( searchAction, SIGNAL(triggered(bool)), searchText, SLOT(setFocus())); | 174 | connect( searchAction, SIGNAL(triggered(bool)), searchText, SLOT(setFocus())); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
202 | } | 221 | } | ||
203 | 222 | | |||
204 | 223 | | |||
205 | void SettingsBase::initMenuList(MenuItem * parent) | 224 | void SettingsBase::initMenuList(MenuItem * parent) | ||
206 | { | 225 | { | ||
207 | // look for any categories inside this level, and recurse into them | 226 | // look for any categories inside this level, and recurse into them | ||
208 | for (int i = 0; i < categories.size(); ++i) { | 227 | for (int i = 0; i < categories.size(); ++i) { | ||
209 | const KService::Ptr entry = categories.at(i); | 228 | const KService::Ptr entry = categories.at(i); | ||
210 | const QString parentCategory = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category")).toString(); | 229 | QString parentCategory; | ||
211 | const QString parentCategory2 = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category-V2")).toString(); | 230 | QString parentCategory2; | ||
231 | if (m_mode == BaseMode::InfoCenter) { | ||||
232 | parentCategory = entry->property(QStringLiteral("X-KDE-KInfoCenter-Parent-Category")).toString(); | ||||
233 | } else { | ||||
234 | parentCategory = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category")).toString(); | ||||
235 | parentCategory2 = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category-V2")).toString(); | ||||
236 | } | ||||
237 | | ||||
212 | if ( parentCategory == parent->category() || | 238 | if (parentCategory == parent->category() || | ||
213 | // V2 entries must not be empty if they want to become a proper category. | 239 | // V2 entries must not be empty if they want to become a proper category. | ||
214 | ( !parentCategory2.isEmpty() && parentCategory2 == parent->category() ) ) { | 240 | ( !parentCategory2.isEmpty() && parentCategory2 == parent->category() ) ) { | ||
215 | MenuItem * menuItem = new MenuItem(true, parent); | 241 | MenuItem * menuItem = new MenuItem(true, parent); | ||
216 | menuItem->setService( entry ); | 242 | menuItem->setService( entry ); | ||
217 | if( menuItem->category() == QLatin1String("lost-and-found") ) { | 243 | if( menuItem->category() == QLatin1String("lost-and-found") ) { | ||
218 | lostFound = menuItem; | 244 | lostFound = menuItem; | ||
219 | continue; | 245 | continue; | ||
220 | } | 246 | } | ||
221 | initMenuList( menuItem ); | 247 | initMenuList( menuItem ); | ||
222 | } | 248 | } | ||
223 | } | 249 | } | ||
224 | 250 | | |||
225 | KService::List removeList; | 251 | KService::List removeList; | ||
226 | 252 | | |||
227 | // scan for any modules at this level and add them | 253 | // scan for any modules at this level and add them | ||
228 | for (int i = 0; i < modules.size(); ++i) { | 254 | for (int i = 0; i < modules.size(); ++i) { | ||
229 | const KService::Ptr entry = modules.at(i); | 255 | const KService::Ptr entry = modules.at(i); | ||
230 | const QString category = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category")).toString(); | 256 | | ||
231 | const QString category2 = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category-V2")).toString(); | 257 | QString category; | ||
258 | QString category2; | ||||
259 | if (m_mode == BaseMode::InfoCenter) { | ||||
260 | category = entry->property(QStringLiteral("X-KDE-KInfoCenter-Category")).toString(); | ||||
261 | } else { | ||||
262 | category = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category")).toString(); | ||||
263 | category2 = entry->property(QStringLiteral("X-KDE-System-Settings-Parent-Category-V2")).toString(); | ||||
264 | } | ||||
265 | | ||||
232 | if( !parent->category().isEmpty() && (category == parent->category() || category2 == parent->category()) ) { | 266 | if( !parent->category().isEmpty() && (category == parent->category() || category2 == parent->category()) ) { | ||
233 | if (!entry->noDisplay() ) { | 267 | if (!entry->noDisplay() ) { | ||
234 | // Add the module info to the menu | 268 | // Add the module info to the menu | ||
235 | MenuItem * infoItem = new MenuItem(false, parent); | 269 | MenuItem * infoItem = new MenuItem(false, parent); | ||
236 | infoItem->setService( entry ); | 270 | infoItem->setService( entry ); | ||
271 | if (m_mode == BaseMode::InfoCenter && entry->pluginKeyword() == QStringLiteral("kcm-about-distro")) { | ||||
272 | homeModule = infoItem; | ||||
273 | } | ||||
237 | } | 274 | } | ||
238 | 275 | | |||
239 | removeList.append( modules.at(i) ); | 276 | removeList.append( modules.at(i) ); | ||
240 | } | 277 | } | ||
241 | } | 278 | } | ||
242 | 279 | | |||
243 | for (int i = 0; i < removeList.size(); ++i) { | 280 | for (int i = 0; i < removeList.size(); ++i) { | ||
244 | modules.removeOne( removeList.at(i) ); | 281 | modules.removeOne( removeList.at(i) ); | ||
245 | } | 282 | } | ||
246 | 283 | | |||
247 | parent->sortChildrenByWeight(); | 284 | parent->sortChildrenByWeight(); | ||
248 | } | 285 | } | ||
249 | 286 | | |||
250 | void SettingsBase::configUpdated() | 287 | void SettingsBase::configUpdated() | ||
251 | { | 288 | { | ||
252 | KConfigGroup dialogConfig = KSharedConfig::openConfig()->group("ConfigDialog"); | 289 | KConfigGroup dialogConfig = KSharedConfig::openConfig()->group("ConfigDialog"); | ||
253 | KWindowConfig::saveWindowSize(configDialog->windowHandle(), dialogConfig); | 290 | KWindowConfig::saveWindowSize(configDialog->windowHandle(), dialogConfig); | ||
254 | BaseConfig::setActiveView( possibleViews.keys().at(viewSelection.checkedId()) ); | 291 | BaseConfig::setActiveView( possibleViews.keys().at(viewSelection.checkedId()) ); | ||
292 | | ||||
255 | BaseConfig::setShowToolTips( configWidget.ChTooltips->isChecked() ); | 293 | BaseConfig::setShowToolTips( configWidget.ChTooltips->isChecked() ); | ||
256 | activeView->setShowToolTips( configWidget.ChTooltips->isChecked() ); | 294 | activeView->setShowToolTips( configWidget.ChTooltips->isChecked() ); | ||
257 | activeView->saveConfiguration(); | 295 | activeView->saveConfiguration(); | ||
258 | changePlugin(); | 296 | changePlugin(); | ||
259 | } | 297 | } | ||
260 | 298 | | |||
261 | void SettingsBase::configShow() | 299 | void SettingsBase::configShow() | ||
262 | { | 300 | { | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 355 | if( possibleViews.isEmpty() ) { // We should ensure we have a plugin available to choose | |||
320 | return; // Halt now! | 358 | return; // Halt now! | ||
321 | } | 359 | } | ||
322 | 360 | | |||
323 | if( activeView ) { | 361 | if( activeView ) { | ||
324 | activeView->saveState(); | 362 | activeView->saveState(); | ||
325 | activeView->leaveModuleView(); | 363 | activeView->leaveModuleView(); | ||
326 | } | 364 | } | ||
327 | 365 | | |||
328 | const QString viewToUse = BaseConfig::activeView(); | 366 | const QString viewToUse = m_mode == BaseMode::InfoCenter ? QStringLiteral("systemsettings_sidebar_mode") : BaseConfig::activeView(); | ||
329 | if( possibleViews.keys().contains(viewToUse) ) { // First the configuration entry | 367 | if( possibleViews.keys().contains(viewToUse) ) { // First the configuration entry | ||
330 | activeView = possibleViews.value(viewToUse); | 368 | activeView = possibleViews.value(viewToUse); | ||
331 | } | 369 | } | ||
332 | else { // Otherwise we activate the failsafe | 370 | else { // Otherwise we activate the failsafe | ||
333 | activeView = possibleViews.begin().value(); | 371 | activeView = possibleViews.begin().value(); | ||
334 | } | 372 | } | ||
335 | 373 | | |||
336 | if( stackedWidget->indexOf(activeView->mainWidget()) == -1 ) { | 374 | if( stackedWidget->indexOf(activeView->mainWidget()) == -1 ) { | ||
Show All 18 Lines | |||||
355 | updateViewActions(); | 393 | updateViewActions(); | ||
356 | 394 | | |||
357 | activeView->giveFocus(); | 395 | activeView->giveFocus(); | ||
358 | } | 396 | } | ||
359 | 397 | | |||
360 | void SettingsBase::viewChange(bool state) | 398 | void SettingsBase::viewChange(bool state) | ||
361 | { | 399 | { | ||
362 | KCModuleInfo * moduleInfo = activeView->moduleView()->activeModule(); | 400 | KCModuleInfo * moduleInfo = activeView->moduleView()->activeModule(); | ||
401 | if (configureAction) { | ||||
363 | configureAction->setDisabled(state); | 402 | configureAction->setDisabled(state); | ||
403 | } | ||||
364 | if( moduleInfo ) { | 404 | if( moduleInfo ) { | ||
365 | setCaption( moduleInfo->moduleName(), state ); | 405 | setCaption( moduleInfo->moduleName(), state ); | ||
366 | } else { | 406 | } else { | ||
367 | setCaption( QString(), state ); | 407 | setCaption( QString(), state ); | ||
368 | } | 408 | } | ||
369 | changeAboutMenu( activeView->moduleView()->aboutData(), aboutModuleAction, i18n("About Active Module") ); | 409 | changeAboutMenu( activeView->moduleView()->aboutData(), aboutModuleAction, i18n("About Active Module") ); | ||
370 | } | 410 | } | ||
371 | 411 | | |||
Show All 12 Lines | 419 | { | |||
384 | guiFactory()->unplugActionList( this, QStringLiteral("search") ); | 424 | guiFactory()->unplugActionList( this, QStringLiteral("search") ); | ||
385 | guiFactory()->unplugActionList( this, QStringLiteral("quit") ); | 425 | guiFactory()->unplugActionList( this, QStringLiteral("quit") ); | ||
386 | if ( BaseMode::Search & toolbar ) { | 426 | if ( BaseMode::Search & toolbar ) { | ||
387 | QList<QAction*> searchBarActions; | 427 | QList<QAction*> searchBarActions; | ||
388 | searchBarActions << spacerAction << searchAction; | 428 | searchBarActions << spacerAction << searchAction; | ||
389 | guiFactory()->plugActionList( this, QStringLiteral("search"), searchBarActions ); | 429 | guiFactory()->plugActionList( this, QStringLiteral("search"), searchBarActions ); | ||
390 | actionCollection()->setDefaultShortcut(searchAction, QKeySequence(Qt::CTRL + Qt::Key_F)); | 430 | actionCollection()->setDefaultShortcut(searchAction, QKeySequence(Qt::CTRL + Qt::Key_F)); | ||
391 | } | 431 | } | ||
392 | if ( BaseMode::Configure & toolbar ) { | 432 | if ( (BaseMode::Configure & toolbar) && configureAction) { | ||
393 | QList<QAction*> configureBarActions; | 433 | QList<QAction*> configureBarActions; | ||
394 | configureBarActions << configureAction; | 434 | configureBarActions << configureAction; | ||
395 | guiFactory()->plugActionList( this, QStringLiteral("configure"), configureBarActions ); | 435 | guiFactory()->plugActionList( this, QStringLiteral("configure"), configureBarActions ); | ||
396 | } | 436 | } | ||
397 | if ( BaseMode::Quit & toolbar ) { | 437 | if ( BaseMode::Quit & toolbar ) { | ||
398 | QList<QAction*> quitBarActions; | 438 | QList<QAction*> quitBarActions; | ||
399 | quitBarActions << quitAction; | 439 | quitBarActions << quitAction; | ||
400 | guiFactory()->plugActionList( this, QStringLiteral("quit"), quitBarActions ); | 440 | guiFactory()->plugActionList( this, QStringLiteral("quit"), quitBarActions ); | ||
Show All 28 Lines |