Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/appentry.cpp
Show All 19 Lines | |||||
20 | #include <config-workspace.h> | 20 | #include <config-workspace.h> | ||
21 | #include "appentry.h" | 21 | #include "appentry.h" | ||
22 | #include "actionlist.h" | 22 | #include "actionlist.h" | ||
23 | #include "appsmodel.h" | 23 | #include "appsmodel.h" | ||
24 | #include "containmentinterface.h" | 24 | #include "containmentinterface.h" | ||
25 | #include "menuentryeditor.h" | 25 | #include "menuentryeditor.h" | ||
26 | 26 | | |||
27 | #include <config-X11.h> | 27 | #include <config-X11.h> | ||
28 | #include <config-appstream.h> | | |||
29 | 28 | | |||
30 | #include <QProcess> | 29 | #include <QProcess> | ||
31 | #include <QQmlPropertyMap> | 30 | #include <QQmlPropertyMap> | ||
32 | #include <QStandardPaths> | 31 | #include <QStandardPaths> | ||
33 | #include <QDesktopServices> | 32 | #include <QDesktopServices> | ||
34 | #if HAVE_X11 | 33 | #if HAVE_X11 | ||
35 | #include <QX11Info> | 34 | #include <QX11Info> | ||
36 | #endif | 35 | #endif | ||
37 | 36 | | |||
38 | #include <KActivities/ResourceInstance> | 37 | #include <KActivities/ResourceInstance> | ||
39 | #include <KConfigGroup> | 38 | #include <KConfigGroup> | ||
40 | #include <KJob> | 39 | #include <KJob> | ||
41 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
42 | #include <KMimeTypeTrader> | 41 | #include <KMimeTypeTrader> | ||
43 | #include <KProtocolInfo> | | |||
44 | #include <KRun> | 42 | #include <KRun> | ||
45 | #include <KSycoca> | 43 | #include <KSycoca> | ||
46 | #include <KShell> | 44 | #include <KShell> | ||
47 | #include <KSharedConfig> | 45 | #include <KSharedConfig> | ||
48 | #include <KStartupInfo> | 46 | #include <KStartupInfo> | ||
49 | 47 | | |||
50 | #include <Plasma/Plasma> | 48 | #include <Plasma/Plasma> | ||
51 | 49 | | |||
52 | #ifdef HAVE_APPSTREAMQT | | |||
53 | #include <AppStreamQt/pool.h> | | |||
54 | #endif | | |||
55 | | ||||
56 | MenuEntryEditor *AppEntry::m_menuEntryEditor = nullptr; | | |||
57 | | ||||
58 | AppEntry::AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameFormat) | 50 | AppEntry::AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameFormat) | ||
59 | : AbstractEntry(owner) | 51 | : AbstractEntry(owner) | ||
60 | , m_service(service) | 52 | , m_service(service) | ||
61 | { | 53 | { | ||
62 | if (m_service) { | 54 | if (m_service) { | ||
63 | init(nameFormat); | 55 | init(nameFormat); | ||
64 | } | 56 | } | ||
65 | } | 57 | } | ||
Show All 18 Lines | |||||
84 | { | 76 | { | ||
85 | m_name = nameFromService(m_service, nameFormat); | 77 | m_name = nameFromService(m_service, nameFormat); | ||
86 | 78 | | |||
87 | if (nameFormat == GenericNameOnly) { | 79 | if (nameFormat == GenericNameOnly) { | ||
88 | m_description = nameFromService(m_service, NameOnly); | 80 | m_description = nameFromService(m_service, NameOnly); | ||
89 | } else { | 81 | } else { | ||
90 | m_description = nameFromService(m_service, GenericNameOnly); | 82 | m_description = nameFromService(m_service, GenericNameOnly); | ||
91 | } | 83 | } | ||
92 | | ||||
93 | if (!m_menuEntryEditor) { | | |||
94 | m_menuEntryEditor = new MenuEntryEditor(); | | |||
95 | } | | |||
96 | } | 84 | } | ||
97 | 85 | | |||
98 | bool AppEntry::isValid() const | 86 | bool AppEntry::isValid() const | ||
99 | { | 87 | { | ||
100 | return m_service; | 88 | return m_service; | ||
101 | } | 89 | } | ||
102 | 90 | | |||
103 | QIcon AppEntry::icon() const | 91 | QIcon AppEntry::icon() const | ||
Show All 33 Lines | 124 | { | |||
137 | return QUrl::fromLocalFile(m_service->entryPath()); | 125 | return QUrl::fromLocalFile(m_service->entryPath()); | ||
138 | } | 126 | } | ||
139 | 127 | | |||
140 | bool AppEntry::hasActions() const | 128 | bool AppEntry::hasActions() const | ||
141 | { | 129 | { | ||
142 | return true; | 130 | return true; | ||
143 | } | 131 | } | ||
144 | 132 | | |||
145 | #ifdef HAVE_APPSTREAMQT | | |||
146 | Q_GLOBAL_STATIC(AppStream::Pool, appstreamPool) | | |||
147 | | ||||
148 | QVariantList appstreamActions(const KService::Ptr &service) | | |||
149 | { | | |||
150 | QVariantList ret; | | |||
151 | | ||||
152 | const KService::Ptr appStreamHandler = KMimeTypeTrader::self()->preferredService(QStringLiteral("x-scheme-handler/appstream")); | | |||
153 | | ||||
154 | // Don't show action if we can't find any app to handle appstream:// URLs. | | |||
155 | if (!appStreamHandler) { | | |||
156 | if (!KProtocolInfo::isHelperProtocol(QStringLiteral("appstream")) | | |||
157 | || KProtocolInfo::exec(QStringLiteral("appstream")).isEmpty()) { | | |||
158 | return ret; | | |||
159 | } | | |||
160 | } | | |||
161 | | ||||
162 | if (!appstreamPool.exists()) { | | |||
163 | appstreamPool->load(); | | |||
164 | } | | |||
165 | | ||||
166 | const auto components = appstreamPool->componentsById(service->desktopEntryName()+QLatin1String(".desktop")); | | |||
167 | for(const auto &component: components) { | | |||
168 | const QString componentId = component.id(); | | |||
169 | | ||||
170 | QVariantMap appstreamAction = Kicker::createActionItem(i18nc("@action opens a software center with the application", "Manage '%1'...", component.name()), "manageApplication", QVariant(QStringLiteral("appstream://") + componentId)); | | |||
171 | appstreamAction[QStringLiteral("icon")] = QStringLiteral("applications-other"); | | |||
172 | ret << appstreamAction; | | |||
173 | } | | |||
174 | return ret; | | |||
175 | } | | |||
176 | #endif | | |||
177 | | ||||
178 | QVariantList AppEntry::actions() const | 133 | QVariantList AppEntry::actions() const | ||
179 | { | 134 | { | ||
180 | QVariantList actionList; | 135 | QVariantList actionList; | ||
181 | 136 | | |||
182 | actionList << Kicker::jumpListActions(m_service); | 137 | actionList << Kicker::jumpListActions(m_service); | ||
183 | if (!actionList.isEmpty()) { | 138 | if (!actionList.isEmpty()) { | ||
184 | actionList << Kicker::createSeparatorActionItem(); | 139 | actionList << Kicker::createSeparatorActionItem(); | ||
185 | } | 140 | } | ||
Show All 14 Lines | |||||
200 | } | 155 | } | ||
201 | 156 | | |||
202 | // Don't allow adding launchers, editing, hiding, or uninstalling applications | 157 | // Don't allow adding launchers, editing, hiding, or uninstalling applications | ||
203 | // when system is immutable. | 158 | // when system is immutable. | ||
204 | if (systemImmutable) { | 159 | if (systemImmutable) { | ||
205 | return actionList; | 160 | return actionList; | ||
206 | } | 161 | } | ||
207 | 162 | | |||
208 | if (m_menuEntryEditor->canEdit(m_service->entryPath())) { | 163 | if (Kicker::canEdit(m_service->entryPath())) { | ||
209 | actionList << Kicker::createSeparatorActionItem(); | 164 | actionList << Kicker::createSeparatorActionItem(); | ||
210 | 165 | | |||
211 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); | 166 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); | ||
212 | editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. | 167 | editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. | ||
213 | actionList << editAction; | 168 | actionList << editAction; | ||
214 | } | 169 | } | ||
215 | 170 | | |||
216 | #ifdef HAVE_APPSTREAMQT | | |||
217 | if (m_service->isApplication()) { | 171 | if (m_service->isApplication()) { | ||
218 | actionList << appstreamActions(m_service); | 172 | actionList << Kicker::appstreamActions(m_service); | ||
219 | } | 173 | } | ||
220 | #endif | | |||
221 | 174 | | |||
222 | QQmlPropertyMap *appletConfig = qobject_cast<QQmlPropertyMap *>(appletInterface->property("configuration").value<QObject *>()); | 175 | QQmlPropertyMap *appletConfig = qobject_cast<QQmlPropertyMap *>(appletInterface->property("configuration").value<QObject *>()); | ||
223 | 176 | | |||
224 | if (appletConfig && appletConfig->contains("hiddenApplications") && qobject_cast<AppsModel *>(m_owner)) { | 177 | if (appletConfig && appletConfig->contains("hiddenApplications") && qobject_cast<AppsModel *>(m_owner)) { | ||
225 | const QStringList &hiddenApps = appletConfig->value("hiddenApplications").toStringList(); | 178 | const QStringList &hiddenApps = appletConfig->value("hiddenApplications").toStringList(); | ||
226 | 179 | | |||
227 | if (!hiddenApps.contains(m_service->menuId())) { | 180 | if (!hiddenApps.contains(m_service->menuId())) { | ||
228 | actionList << Kicker::createActionItem(i18n("Hide Application"), "hideApplication"); | 181 | actionList << Kicker::createActionItem(i18n("Hide Application"), "hideApplication"); | ||
Show All 26 Lines | 201 | #endif | |||
255 | 208 | | |||
256 | return true; | 209 | return true; | ||
257 | } | 210 | } | ||
258 | 211 | | |||
259 | QObject *appletInterface = m_owner->rootModel()->property("appletInterface").value<QObject *>(); | 212 | QObject *appletInterface = m_owner->rootModel()->property("appletInterface").value<QObject *>(); | ||
260 | 213 | | |||
261 | if (Kicker::handleAddLauncherAction(actionId, appletInterface, m_service)) { | 214 | if (Kicker::handleAddLauncherAction(actionId, appletInterface, m_service)) { | ||
262 | return true; | 215 | return true; | ||
263 | } else if (actionId == "editApplication" && m_menuEntryEditor->canEdit(m_service->entryPath())) { | 216 | } else if (actionId == "editApplication" && Kicker::canEdit(m_service->entryPath())) { | ||
264 | m_menuEntryEditor->edit(m_service->entryPath(), m_service->menuId()); | 217 | Kicker::edit(m_service->entryPath(), m_service->menuId()); | ||
265 | 218 | | |||
266 | return true; | 219 | return true; | ||
267 | } else if (actionId == "manageApplication") { | 220 | } else if (actionId == "manageApplication") { | ||
268 | return QDesktopServices::openUrl(QUrl(argument.toString())); | 221 | return QDesktopServices::openUrl(QUrl(argument.toString())); | ||
269 | } else if (actionId == "_kicker_jumpListAction") { | 222 | } else if (actionId == "_kicker_jumpListAction") { | ||
270 | return KRun::run(argument.toString(), {}, nullptr, m_service->name(), m_service->icon()); | 223 | return KRun::run(argument.toString(), {}, nullptr, m_service->name(), m_service->icon()); | ||
271 | } | 224 | } | ||
272 | 225 | | |||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |