Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/systemtray.cpp
Context not available. | |||||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
---|---|---|---|---|---|
19 | 19 | | |||
20 | #include "systemtray.h" | 20 | #include "systemtray.h" | ||
21 | #include "systemtraymodel.h" | ||||
21 | #include "debug.h" | 22 | #include "debug.h" | ||
22 | 23 | | |||
23 | #include <QDebug> | 24 | #include <QDebug> | ||
Context not available. | |||||
42 | 43 | | |||
43 | #include <plasma_version.h> | 44 | #include <plasma_version.h> | ||
44 | 45 | | |||
45 | class PlasmoidModel: public QStandardItemModel | | |||
46 | { | | |||
47 | public: | | |||
48 | explicit PlasmoidModel(QObject *parent = nullptr) | | |||
49 | : QStandardItemModel(parent) | | |||
50 | { | | |||
51 | } | | |||
52 | | ||||
53 | QHash<int, QByteArray> roleNames() const override { | | |||
54 | QHash<int, QByteArray> roles = QStandardItemModel::roleNames(); | | |||
55 | roles[Qt::UserRole+1] = "plugin"; | | |||
56 | return roles; | | |||
57 | } | | |||
58 | }; | | |||
59 | | ||||
60 | SystemTray::SystemTray(QObject *parent, const QVariantList &args) | 46 | SystemTray::SystemTray(QObject *parent, const QVariantList &args) | ||
61 | : Plasma::Containment(parent, args), | 47 | : Plasma::Containment(parent, args), | ||
62 | m_availablePlasmoidsModel(nullptr) | 48 | m_availablePlasmoidsModel(nullptr), | ||
49 | m_systemTrayModel(new SystemTrayModel(this)) | ||||
63 | { | 50 | { | ||
64 | setHasConfigurationInterface(true); | 51 | setHasConfigurationInterface(true); | ||
65 | setContainmentType(Plasma::Types::CustomEmbeddedContainment); | 52 | setContainmentType(Plasma::Types::CustomEmbeddedContainment); | ||
53 | | ||||
54 | PlasmoidModel *currentPlasmoidsModel = new PlasmoidModel(m_systemTrayModel); | ||||
55 | connect(this, &SystemTray::appletAdded, currentPlasmoidsModel, &PlasmoidModel::addApplet); | ||||
56 | connect(this, &SystemTray::appletRemoved, currentPlasmoidsModel, &PlasmoidModel::removeApplet); | ||||
57 | m_systemTrayModel->addSourceModel(currentPlasmoidsModel); | ||||
58 | | ||||
59 | m_statusNotifierModel = new StatusNotifierModel(m_systemTrayModel); | ||||
60 | m_systemTrayModel->addSourceModel(m_statusNotifierModel); | ||||
66 | } | 61 | } | ||
67 | 62 | | |||
68 | SystemTray::~SystemTray() | 63 | SystemTray::~SystemTray() | ||
Context not available. | |||||
349 | return m_systrayApplets.contains(appletId); | 344 | return m_systrayApplets.contains(appletId); | ||
350 | } | 345 | } | ||
351 | 346 | | |||
347 | Plasma::Service *SystemTray::serviceForSource(const QString &source) | ||||
348 | { | ||||
349 | return m_statusNotifierModel->serviceForSource(source); | ||||
350 | } | ||||
351 | | ||||
352 | void SystemTray::restoreContents(KConfigGroup &group) | 352 | void SystemTray::restoreContents(KConfigGroup &group) | ||
353 | { | 353 | { | ||
354 | Q_UNUSED(group); | 354 | QStringList newKnownItems; | ||
355 | //NOTE: RestoreContents shouldn't do anything here because is too soon, so have an empty reimplementation | 355 | QStringList newExtraItems; | ||
356 | | ||||
357 | KConfigGroup general = group.group("General"); | ||||
358 | | ||||
359 | QStringList knownItems = general.readEntry("knownItems", QStringList()); | ||||
360 | QStringList extraItems = general.readEntry("extraItems", QStringList()); | ||||
361 | | ||||
362 | //Add every plasmoid that is both not enabled explicitly and not already known | ||||
363 | for (int i = 0; i < m_defaultPlasmoids.length(); ++i) { | ||||
364 | QString candidate = m_defaultPlasmoids[i]; | ||||
365 | if (!knownItems.contains(candidate)) { | ||||
366 | newKnownItems.append(candidate); | ||||
367 | if (!extraItems.contains(candidate)) { | ||||
368 | newExtraItems.append(candidate); | ||||
369 | } | ||||
370 | } | ||||
371 | } | ||||
372 | | ||||
373 | if (newExtraItems.length() > 0) { | ||||
374 | general.writeEntry("extraItems", extraItems + newExtraItems); | ||||
375 | } | ||||
376 | if (newKnownItems.length() > 0) { | ||||
377 | general.writeEntry("knownItems", knownItems + newKnownItems); | ||||
378 | } | ||||
379 | | ||||
380 | setAllowedPlasmoids(general.readEntry("extraItems", QStringList())); | ||||
356 | } | 381 | } | ||
357 | 382 | | |||
358 | void SystemTray::restorePlasmoids() | 383 | void SystemTray::restorePlasmoids() | ||
Context not available. | |||||
394 | } | 419 | } | ||
395 | } | 420 | } | ||
396 | 421 | | |||
397 | QStringList ownApplets; | | |||
398 | | ||||
399 | QMap<QString, KPluginMetaData> sortedApplets; | 422 | QMap<QString, KPluginMetaData> sortedApplets; | ||
400 | for (auto it = m_systrayApplets.constBegin(); it != m_systrayApplets.constEnd(); ++it) { | 423 | for (auto it = m_systrayApplets.constBegin(); it != m_systrayApplets.constEnd(); ++it) { | ||
401 | const KPluginMetaData &info = it.value(); | 424 | const KPluginMetaData &info = it.value(); | ||
Context not available. | |||||
437 | initDBusActivatables(); | 460 | initDBusActivatables(); | ||
438 | } | 461 | } | ||
439 | 462 | | |||
440 | QStringList SystemTray::defaultPlasmoids() const | 463 | QAbstractItemModel *SystemTray::systemTrayModel() | ||
441 | { | 464 | { | ||
442 | return m_defaultPlasmoids; | 465 | return m_systemTrayModel; | ||
443 | } | 466 | } | ||
444 | 467 | | |||
445 | QAbstractItemModel* SystemTray::availablePlasmoids() | 468 | QAbstractItemModel* SystemTray::availablePlasmoids() | ||
Context not available. | |||||
455 | name += i18n(" (Automatic load)"); | 478 | name += i18n(" (Automatic load)"); | ||
456 | } | 479 | } | ||
457 | QStandardItem *item = new QStandardItem(QIcon::fromTheme(info.iconName()), name); | 480 | QStandardItem *item = new QStandardItem(QIcon::fromTheme(info.iconName()), name); | ||
458 | item->setData(info.pluginId()); | 481 | item->setData(info.pluginId(), static_cast<int>(PlasmoidModel::PlasmoidModelRole::PluginRole)); | ||
459 | m_availablePlasmoidsModel->appendRow(item); | 482 | m_availablePlasmoidsModel->appendRow(item); | ||
460 | } | 483 | } | ||
461 | m_availablePlasmoidsModel->sort(0 /*column*/); | 484 | m_availablePlasmoidsModel->sort(0 /*column*/); | ||
Context not available. | |||||
503 | connect(systemCallWatcher, &QDBusPendingCallWatcher::finished, | 526 | connect(systemCallWatcher, &QDBusPendingCallWatcher::finished, | ||
504 | [=](QDBusPendingCallWatcher *callWatcher){ | 527 | [=](QDBusPendingCallWatcher *callWatcher){ | ||
505 | SystemTray::serviceNameFetchFinished(callWatcher, QDBusConnection::systemBus()); | 528 | SystemTray::serviceNameFetchFinished(callWatcher, QDBusConnection::systemBus()); | ||
506 | }); | 529 | }); | ||
507 | } | 530 | } | ||
508 | 531 | | |||
509 | void SystemTray::serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection) | 532 | void SystemTray::serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection) | ||
Context not available. |