Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/plugin/smartlaunchers/smartlauncheritem.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de> * | 2 | * Copyright (C) 2016, 2019 Kai Uwe Broulik <kde@privat.broulik.de> * | ||
3 | * * | 3 | * * | ||
4 | * This program is free software; you can redistribute it and/or modify * | 4 | * This program is free software; you can redistribute it and/or modify * | ||
5 | * it under the terms of the GNU General Public License as published by * | 5 | * it under the terms of the GNU General Public License as published by * | ||
6 | * the Free Software Foundation; either version 2 of the License, or * | 6 | * the Free Software Foundation; either version 2 of the License, or * | ||
7 | * (at your option) any later version. * | 7 | * (at your option) any later version. * | ||
8 | * * | 8 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 9 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
Show All 22 Lines | 30 | if (!m_backendPtr) { | |||
33 | m_backendPtr = s_backend.toStrongRef(); | 33 | m_backendPtr = s_backend.toStrongRef(); | ||
34 | } | 34 | } | ||
35 | } | 35 | } | ||
36 | 36 | | |||
37 | QWeakPointer<Backend> Item::s_backend; | 37 | QWeakPointer<Backend> Item::s_backend; | ||
38 | 38 | | |||
39 | void Item::init() | 39 | void Item::init() | ||
40 | { | 40 | { | ||
41 | if (m_inited || m_storageId.isEmpty() || !m_backendPtr || !m_backendPtr->available()) { | 41 | if (m_inited || m_storageId.isEmpty() || !m_backendPtr) { | ||
42 | return; | 42 | return; | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | connect(m_backendPtr.data(), &Backend::reloadRequested, this, [this](const QString &uri) { | ||||
46 | if (uri.isEmpty() || m_storageId == uri) { | ||||
47 | populate(); | ||||
48 | } | ||||
49 | }); | ||||
50 | | ||||
45 | connect(m_backendPtr.data(), &Backend::launcherRemoved, this, [this](const QString &uri) { | 51 | connect(m_backendPtr.data(), &Backend::launcherRemoved, this, [this](const QString &uri) { | ||
46 | if (m_storageId == uri) { | 52 | if (uri.isEmpty() || m_storageId == uri) { | ||
47 | clear(); | 53 | clear(); | ||
48 | } | 54 | } | ||
49 | }); | 55 | }); | ||
50 | 56 | | |||
51 | connect(m_backendPtr.data(), &Backend::countChanged, this, [this](const QString &uri, int count) { | 57 | connect(m_backendPtr.data(), &Backend::countChanged, this, [this](const QString &uri, int count) { | ||
52 | if (m_storageId == uri) { | 58 | if (uri.isEmpty() || m_storageId == uri) { | ||
53 | setCount(count); | 59 | setCount(count); | ||
54 | } | 60 | } | ||
55 | }); | 61 | }); | ||
56 | 62 | | |||
57 | connect(m_backendPtr.data(), &Backend::countVisibleChanged, this, [this](const QString &uri, bool countVisible) { | 63 | connect(m_backendPtr.data(), &Backend::countVisibleChanged, this, [this](const QString &uri, bool countVisible) { | ||
58 | if (m_storageId == uri) { | 64 | if (uri.isEmpty() || m_storageId == uri) { | ||
59 | setCountVisible(countVisible); | 65 | setCountVisible(countVisible); | ||
60 | } | 66 | } | ||
61 | }); | 67 | }); | ||
62 | 68 | | |||
63 | connect(m_backendPtr.data(), &Backend::progressChanged, this, [this](const QString &uri, int progress) { | 69 | connect(m_backendPtr.data(), &Backend::progressChanged, this, [this](const QString &uri, int progress) { | ||
64 | if (m_storageId == uri) { | 70 | if (uri.isEmpty() || m_storageId == uri) { | ||
65 | setProgress(progress); | 71 | setProgress(progress); | ||
66 | } | 72 | } | ||
67 | }); | 73 | }); | ||
68 | 74 | | |||
69 | connect(m_backendPtr.data(), &Backend::progressVisibleChanged, this, [this](const QString &uri, bool progressVisible) { | 75 | connect(m_backendPtr.data(), &Backend::progressVisibleChanged, this, [this](const QString &uri, bool progressVisible) { | ||
70 | if (m_storageId == uri) { | 76 | if (uri.isEmpty() || m_storageId == uri) { | ||
71 | setProgressVisible(progressVisible); | 77 | setProgressVisible(progressVisible); | ||
72 | } | 78 | } | ||
73 | }); | 79 | }); | ||
74 | 80 | | |||
75 | connect(m_backendPtr.data(), &Backend::urgentChanged, this, [this](const QString &uri, bool urgent) { | 81 | connect(m_backendPtr.data(), &Backend::urgentChanged, this, [this](const QString &uri, bool urgent) { | ||
76 | if (m_storageId == uri) { | 82 | if (uri.isEmpty() || m_storageId == uri) { | ||
77 | setUrgent(urgent); | 83 | setUrgent(urgent); | ||
78 | } | 84 | } | ||
79 | }); | 85 | }); | ||
80 | 86 | | |||
81 | m_available = true; | 87 | m_inited = true; | ||
82 | emit availableChanged(m_available); | | |||
83 | } | 88 | } | ||
84 | 89 | | |||
85 | void Item::populate() | 90 | void Item::populate() | ||
86 | { | 91 | { | ||
87 | if (!m_backendPtr || !m_backendPtr->available() || m_storageId.isEmpty()) { | 92 | if (!m_backendPtr || m_storageId.isEmpty()) { | ||
88 | return; | 93 | return; | ||
89 | } | 94 | } | ||
90 | 95 | | |||
91 | if (!m_backendPtr->hasLauncher(m_storageId)) { | 96 | if (!m_backendPtr->hasLauncher(m_storageId)) { | ||
92 | return; | 97 | return; | ||
93 | } | 98 | } | ||
94 | 99 | | |||
95 | setCount(m_backendPtr->count(m_storageId)); | 100 | setCount(m_backendPtr->count(m_storageId)); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 151 | if (m_backendPtr) { | |||
151 | } | 156 | } | ||
152 | } | 157 | } | ||
153 | 158 | | |||
154 | init(); | 159 | init(); | ||
155 | populate(); | 160 | populate(); | ||
156 | } | 161 | } | ||
157 | } | 162 | } | ||
158 | 163 | | |||
159 | bool Item::available() const | | |||
160 | { | | |||
161 | return m_available; | | |||
162 | } | | |||
163 | 164 | | |||
164 | int Item::count() const | 165 | int Item::count() const | ||
165 | { | 166 | { | ||
166 | return m_count; | 167 | return m_count; | ||
167 | } | 168 | } | ||
168 | 169 | | |||
169 | void Item::setCount(int count) | 170 | void Item::setCount(int count) | ||
170 | { | 171 | { | ||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |