Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/systemtray.cpp
Show All 37 Lines | |||||
38 | #include <KActionCollection> | 38 | #include <KActionCollection> | ||
39 | #include <KAcceleratorManager> | 39 | #include <KAcceleratorManager> | ||
40 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
41 | 41 | | |||
42 | #include <plasma_version.h> | 42 | #include <plasma_version.h> | ||
43 | 43 | | |||
44 | SystemTray::SystemTray(QObject *parent, const QVariantList &args) | 44 | SystemTray::SystemTray(QObject *parent, const QVariantList &args) | ||
45 | : Plasma::Containment(parent, args), | 45 | : Plasma::Containment(parent, args), | ||
46 | m_availablePlasmoidsModel(nullptr), | | |||
47 | m_systemTrayModel(new SystemTrayModel(this)), | 46 | m_systemTrayModel(new SystemTrayModel(this)), | ||
47 | m_sortedSystemTrayModel(nullptr), | ||||
48 | m_configSystemTrayModel(nullptr) | 48 | m_configSystemTrayModel(nullptr) | ||
49 | { | 49 | { | ||
50 | setHasConfigurationInterface(true); | 50 | setHasConfigurationInterface(true); | ||
51 | setContainmentType(Plasma::Types::CustomEmbeddedContainment); | 51 | setContainmentType(Plasma::Types::CustomEmbeddedContainment); | ||
52 | 52 | | |||
53 | PlasmoidModel *currentPlasmoidsModel = new PlasmoidModel(m_systemTrayModel); | 53 | PlasmoidModel *currentPlasmoidsModel = new PlasmoidModel(m_systemTrayModel); | ||
54 | connect(this, &SystemTray::appletAdded, currentPlasmoidsModel, &PlasmoidModel::addApplet); | 54 | connect(this, &SystemTray::appletAdded, currentPlasmoidsModel, &PlasmoidModel::addApplet); | ||
55 | connect(this, &SystemTray::appletRemoved, currentPlasmoidsModel, &PlasmoidModel::removeApplet); | 55 | connect(this, &SystemTray::appletRemoved, currentPlasmoidsModel, &PlasmoidModel::removeApplet); | ||
56 | connect(this, &SystemTray::configurationChanged, currentPlasmoidsModel, &PlasmoidModel::onConfigurationChanged); | ||||
56 | 57 | | |||
57 | m_statusNotifierModel = new StatusNotifierModel(m_systemTrayModel); | 58 | m_statusNotifierModel = new StatusNotifierModel(m_systemTrayModel); | ||
59 | connect(this, &SystemTray::configurationChanged, m_statusNotifierModel, &StatusNotifierModel::onConfigurationChanged); | ||||
58 | 60 | | |||
59 | m_systemTrayModel->addSourceModel(currentPlasmoidsModel); | 61 | m_systemTrayModel->addSourceModel(currentPlasmoidsModel); | ||
60 | m_systemTrayModel->addSourceModel(m_statusNotifierModel); | 62 | m_systemTrayModel->addSourceModel(m_statusNotifierModel); | ||
61 | } | 63 | } | ||
62 | 64 | | |||
63 | SystemTray::~SystemTray() | 65 | SystemTray::~SystemTray() | ||
64 | { | 66 | { | ||
65 | } | 67 | } | ||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | 305 | { | |||
310 | if (visualParent->window() && visualParent->window()->screen()) { | 312 | if (visualParent->window() && visualParent->window()->screen()) { | ||
311 | pos = visualParent->window()->mapToGlobal(pos.toPoint()); | 313 | pos = visualParent->window()->mapToGlobal(pos.toPoint()); | ||
312 | } else { | 314 | } else { | ||
313 | return QPoint(); | 315 | return QPoint(); | ||
314 | } | 316 | } | ||
315 | return pos; | 317 | return pos; | ||
316 | } | 318 | } | ||
317 | 319 | | |||
318 | void SystemTray::reorderItemBefore(QQuickItem* before, QQuickItem* after) | 320 | bool SystemTray::isSystemTrayApplet(const QString &appletId) | ||
319 | { | 321 | { | ||
320 | if (!before || !after) { | 322 | return m_systrayApplets.contains(appletId); | ||
321 | return; | | |||
322 | } | 323 | } | ||
323 | 324 | | |||
324 | before->setVisible(false); | 325 | Plasma::Service *SystemTray::serviceForSource(const QString &source) | ||
325 | before->setParentItem(after->parentItem()); | 326 | { | ||
326 | before->stackBefore(after); | 327 | return m_statusNotifierModel->serviceForSource(source); | ||
327 | before->setVisible(true); | | |||
328 | } | 328 | } | ||
329 | 329 | | |||
330 | void SystemTray::reorderItemAfter(QQuickItem* after, QQuickItem* before) | 330 | void SystemTray::restoreContents(KConfigGroup &group) | ||
331 | { | 331 | { | ||
332 | if (!before || !after) { | 332 | QStringList newKnownItems; | ||
333 | return; | 333 | QStringList newExtraItems; | ||
334 | } | 334 | | ||
335 | KConfigGroup general = group.group("General"); | ||||
335 | 336 | | |||
336 | after->setVisible(false); | 337 | QStringList knownItems = general.readEntry("knownItems", QStringList()); | ||
337 | after->setParentItem(before->parentItem()); | 338 | QStringList extraItems = general.readEntry("extraItems", QStringList()); | ||
338 | after->stackAfter(before); | 339 | | ||
339 | after->setVisible(true); | 340 | //Add every plasmoid that is both not enabled explicitly and not already known | ||
341 | for (int i = 0; i < m_defaultPlasmoids.length(); ++i) { | ||||
342 | QString candidate = m_defaultPlasmoids[i]; | ||||
343 | if (!knownItems.contains(candidate)) { | ||||
344 | newKnownItems.append(candidate); | ||||
345 | if (!extraItems.contains(candidate)) { | ||||
346 | newExtraItems.append(candidate); | ||||
347 | } | ||||
348 | } | ||||
340 | } | 349 | } | ||
341 | 350 | | |||
342 | bool SystemTray::isSystemTrayApplet(const QString &appletId) | 351 | if (newExtraItems.length() > 0) { | ||
343 | { | 352 | general.writeEntry("extraItems", extraItems + newExtraItems); | ||
344 | return m_systrayApplets.contains(appletId); | 353 | } | ||
354 | if (newKnownItems.length() > 0) { | ||||
355 | general.writeEntry("knownItems", knownItems + newKnownItems); | ||||
345 | } | 356 | } | ||
346 | 357 | | |||
347 | void SystemTray::restoreContents(KConfigGroup &group) | 358 | setAllowedPlasmoids(general.readEntry("extraItems", QStringList())); | ||
348 | { | 359 | | ||
349 | Q_UNUSED(group); | 360 | emit configurationChanged(config()); | ||
350 | //NOTE: RestoreContents shouldn't do anything here because is too soon, so have an empty reimplementation | | |||
351 | } | 361 | } | ||
352 | 362 | | |||
353 | void SystemTray::restorePlasmoids() | 363 | void SystemTray::restorePlasmoids() | ||
354 | { | 364 | { | ||
355 | if (!isContainment()) { | 365 | if (!isContainment()) { | ||
356 | qCWarning(SYSTEM_TRAY) << "Loaded as an applet, this shouldn't have happened"; | 366 | qCWarning(SYSTEM_TRAY) << "Loaded as an applet, this shouldn't have happened"; | ||
357 | return; | 367 | return; | ||
358 | } | 368 | } | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 433 | for (const KPluginMetaData &info : qAsConst(sortedApplets)) { | |||
425 | if (m_allowedPlasmoids.contains(info.pluginId())) { | 435 | if (m_allowedPlasmoids.contains(info.pluginId())) { | ||
426 | newTask(info.pluginId()); | 436 | newTask(info.pluginId()); | ||
427 | } | 437 | } | ||
428 | } | 438 | } | ||
429 | 439 | | |||
430 | initDBusActivatables(); | 440 | initDBusActivatables(); | ||
431 | } | 441 | } | ||
432 | 442 | | |||
433 | QAbstractItemModel *SystemTray::configSystemTrayModel() | 443 | void SystemTray::configChanged() | ||
434 | { | 444 | { | ||
435 | if (!m_configSystemTrayModel) { | 445 | Containment::configChanged(); | ||
436 | m_configSystemTrayModel = new SortedSystemTrayModel(SortedSystemTrayModel::SortingType::ConfigurationPage, this); | 446 | emit configurationChanged(config()); | ||
437 | m_configSystemTrayModel->setSourceModel(m_systemTrayModel); | | |||
438 | } | | |||
439 | return m_configSystemTrayModel; | | |||
440 | } | 447 | } | ||
441 | 448 | | |||
442 | QStringList SystemTray::defaultPlasmoids() const | 449 | QAbstractItemModel *SystemTray::systemTrayModel() | ||
443 | { | 450 | { | ||
444 | return m_defaultPlasmoids; | 451 | if (!m_sortedSystemTrayModel) { | ||
452 | m_sortedSystemTrayModel = new SortedSystemTrayModel(SortedSystemTrayModel::SortingType::SystemTray, this); | ||||
453 | m_sortedSystemTrayModel->setSourceModel(m_systemTrayModel); | ||||
454 | } | ||||
455 | return m_sortedSystemTrayModel; | ||||
445 | } | 456 | } | ||
446 | 457 | | |||
447 | QAbstractItemModel* SystemTray::availablePlasmoids() | 458 | QAbstractItemModel *SystemTray::configSystemTrayModel() | ||
448 | { | 459 | { | ||
449 | if (!m_availablePlasmoidsModel) { | 460 | if (!m_configSystemTrayModel) { | ||
450 | m_availablePlasmoidsModel = new PlasmoidModel(this); | 461 | m_configSystemTrayModel = new SortedSystemTrayModel(SortedSystemTrayModel::SortingType::ConfigurationPage, this); | ||
462 | m_configSystemTrayModel->setSourceModel(m_systemTrayModel); | ||||
451 | } | 463 | } | ||
452 | return m_availablePlasmoidsModel; | 464 | return m_configSystemTrayModel; | ||
453 | } | 465 | } | ||
454 | 466 | | |||
455 | QStringList SystemTray::allowedPlasmoids() const | 467 | QStringList SystemTray::allowedPlasmoids() const | ||
456 | { | 468 | { | ||
457 | return m_allowedPlasmoids; | 469 | return m_allowedPlasmoids; | ||
458 | } | 470 | } | ||
459 | 471 | | |||
460 | void SystemTray::setAllowedPlasmoids(const QStringList &allowed) | 472 | void SystemTray::setAllowedPlasmoids(const QStringList &allowed) | ||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |