Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/systemtray.cpp
Show All 12 Lines | |||||
13 | * * | 13 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
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> | ||
24 | #include <QTimer> | 25 | #include <QTimer> | ||
25 | 26 | | |||
26 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
27 | #include <QDBusConnectionInterface> | 28 | #include <QDBusConnectionInterface> | ||
28 | #include <QDBusPendingCallWatcher> | 29 | #include <QDBusPendingCallWatcher> | ||
29 | #include <QMenu> | 30 | #include <QMenu> | ||
30 | #include <QQuickItem> | 31 | #include <QQuickItem> | ||
31 | #include <QRegExp> | 32 | #include <QRegExp> | ||
32 | #include <QScreen> | 33 | #include <QScreen> | ||
33 | #include <QStandardItemModel> | 34 | #include <QStandardItemModel> | ||
34 | #include <QQuickWindow> | 35 | #include <QQuickWindow> | ||
35 | 36 | | |||
36 | #include <Plasma/PluginLoader> | 37 | #include <Plasma/PluginLoader> | ||
37 | #include <Plasma/ServiceJob> | 38 | #include <Plasma/ServiceJob> | ||
38 | 39 | | |||
39 | #include <KActionCollection> | 40 | #include <KActionCollection> | ||
40 | #include <KAcceleratorManager> | 41 | #include <KAcceleratorManager> | ||
41 | #include <KLocalizedString> | 42 | #include <KLocalizedString> | ||
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() | ||
69 | { | 64 | { | ||
70 | } | 65 | } | ||
71 | 66 | | |||
72 | void SystemTray::init() | 67 | void SystemTray::init() | ||
73 | { | 68 | { | ||
▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Line(s) | 425 | for (const KPluginMetaData &info : qAsConst(sortedApplets)) { | |||
432 | if (m_allowedPlasmoids.contains(info.pluginId())) { | 427 | if (m_allowedPlasmoids.contains(info.pluginId())) { | ||
433 | newTask(info.pluginId()); | 428 | newTask(info.pluginId()); | ||
434 | } | 429 | } | ||
435 | } | 430 | } | ||
436 | 431 | | |||
437 | initDBusActivatables(); | 432 | initDBusActivatables(); | ||
438 | } | 433 | } | ||
439 | 434 | | |||
435 | QAbstractItemModel *SystemTray::systemTrayModel() | ||||
436 | { | ||||
437 | return m_systemTrayModel; | ||||
438 | } | ||||
439 | | ||||
440 | QStringList SystemTray::defaultPlasmoids() const | 440 | QStringList SystemTray::defaultPlasmoids() const | ||
441 | { | 441 | { | ||
442 | return m_defaultPlasmoids; | 442 | return m_defaultPlasmoids; | ||
443 | } | 443 | } | ||
444 | 444 | | |||
445 | QAbstractItemModel* SystemTray::availablePlasmoids() | 445 | QAbstractItemModel* SystemTray::availablePlasmoids() | ||
446 | { | 446 | { | ||
447 | if (!m_availablePlasmoidsModel) { | 447 | if (!m_availablePlasmoidsModel) { | ||
448 | m_availablePlasmoidsModel = new PlasmoidModel(this); | 448 | m_availablePlasmoidsModel = new PlasmoidModel(this); | ||
449 | | ||||
450 | for (const KPluginMetaData &info : qAsConst(m_systrayApplets)) { | | |||
451 | QString name = info.name(); | | |||
452 | const QString dbusactivation = info.rawData().value(QStringLiteral("X-Plasma-DBusActivationService")).toString(); | | |||
453 | | ||||
454 | if (!dbusactivation.isEmpty()) { | | |||
455 | name += i18n(" (Automatic load)"); | | |||
456 | } | | |||
457 | QStandardItem *item = new QStandardItem(QIcon::fromTheme(info.iconName()), name); | | |||
458 | item->setData(info.pluginId()); | | |||
459 | m_availablePlasmoidsModel->appendRow(item); | | |||
460 | } | | |||
461 | m_availablePlasmoidsModel->sort(0 /*column*/); | | |||
462 | } | 449 | } | ||
463 | return m_availablePlasmoidsModel; | 450 | return m_availablePlasmoidsModel; | ||
464 | } | 451 | } | ||
465 | 452 | | |||
466 | QStringList SystemTray::allowedPlasmoids() const | 453 | QStringList SystemTray::allowedPlasmoids() const | ||
467 | { | 454 | { | ||
468 | return m_allowedPlasmoids; | 455 | return m_allowedPlasmoids; | ||
469 | } | 456 | } | ||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |