Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/appentry.cpp
Show All 16 Lines | |||||
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 <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" | | |||
26 | 25 | | |||
27 | #include <config-X11.h> | 26 | #include <config-X11.h> | ||
28 | #include <config-appstream.h> | | |||
29 | 27 | | |||
30 | #include <QProcess> | 28 | #include <QProcess> | ||
31 | #include <QQmlPropertyMap> | 29 | #include <QQmlPropertyMap> | ||
32 | #include <QStandardPaths> | 30 | #include <QStandardPaths> | ||
33 | #include <QDesktopServices> | | |||
34 | #if HAVE_X11 | 31 | #if HAVE_X11 | ||
35 | #include <QX11Info> | 32 | #include <QX11Info> | ||
36 | #endif | 33 | #endif | ||
37 | 34 | | |||
38 | #include <KActivities/ResourceInstance> | 35 | #include <KActivities/ResourceInstance> | ||
39 | #include <KConfigGroup> | 36 | #include <KConfigGroup> | ||
40 | #include <KJob> | 37 | #include <KJob> | ||
41 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
42 | #include <KMimeTypeTrader> | 39 | #include <KMimeTypeTrader> | ||
43 | #include <KProtocolInfo> | | |||
44 | #include <KRun> | 40 | #include <KRun> | ||
45 | #include <KSycoca> | 41 | #include <KSycoca> | ||
46 | #include <KShell> | 42 | #include <KShell> | ||
47 | #include <KSharedConfig> | 43 | #include <KSharedConfig> | ||
48 | #include <KStartupInfo> | 44 | #include <KStartupInfo> | ||
49 | 45 | | |||
50 | #include <Plasma/Plasma> | 46 | #include <Plasma/Plasma> | ||
51 | 47 | | |||
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) | 48 | AppEntry::AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameFormat) | ||
59 | : AbstractEntry(owner) | 49 | : AbstractEntry(owner) | ||
60 | , m_service(service) | 50 | , m_service(service) | ||
61 | { | 51 | { | ||
62 | if (m_service) { | 52 | if (m_service) { | ||
63 | init(nameFormat); | 53 | init(nameFormat); | ||
64 | } | 54 | } | ||
65 | } | 55 | } | ||
Show All 18 Lines | |||||
84 | { | 74 | { | ||
85 | m_name = nameFromService(m_service, nameFormat); | 75 | m_name = nameFromService(m_service, nameFormat); | ||
86 | 76 | | |||
87 | if (nameFormat == GenericNameOnly) { | 77 | if (nameFormat == GenericNameOnly) { | ||
88 | m_description = nameFromService(m_service, NameOnly); | 78 | m_description = nameFromService(m_service, NameOnly); | ||
89 | } else { | 79 | } else { | ||
90 | m_description = nameFromService(m_service, GenericNameOnly); | 80 | m_description = nameFromService(m_service, GenericNameOnly); | ||
91 | } | 81 | } | ||
92 | | ||||
93 | if (!m_menuEntryEditor) { | | |||
94 | m_menuEntryEditor = new MenuEntryEditor(); | | |||
95 | } | | |||
96 | } | 82 | } | ||
97 | 83 | | |||
98 | bool AppEntry::isValid() const | 84 | bool AppEntry::isValid() const | ||
99 | { | 85 | { | ||
100 | return m_service; | 86 | return m_service; | ||
101 | } | 87 | } | ||
102 | 88 | | |||
103 | QIcon AppEntry::icon() const | 89 | QIcon AppEntry::icon() const | ||
Show All 33 Lines | 122 | { | |||
137 | return QUrl::fromLocalFile(m_service->entryPath()); | 123 | return QUrl::fromLocalFile(m_service->entryPath()); | ||
138 | } | 124 | } | ||
139 | 125 | | |||
140 | bool AppEntry::hasActions() const | 126 | bool AppEntry::hasActions() const | ||
141 | { | 127 | { | ||
142 | return true; | 128 | return true; | ||
143 | } | 129 | } | ||
144 | 130 | | |||
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 | 131 | QVariantList AppEntry::actions() const | ||
179 | { | 132 | { | ||
180 | QVariantList actionList; | 133 | QVariantList actionList; | ||
181 | 134 | | |||
182 | actionList << Kicker::jumpListActions(m_service); | 135 | actionList << Kicker::jumpListActions(m_service); | ||
183 | if (!actionList.isEmpty()) { | 136 | if (!actionList.isEmpty()) { | ||
184 | actionList << Kicker::createSeparatorActionItem(); | 137 | actionList << Kicker::createSeparatorActionItem(); | ||
185 | } | 138 | } | ||
Show All 14 Lines | |||||
200 | } | 153 | } | ||
201 | 154 | | |||
202 | // Don't allow adding launchers, editing, hiding, or uninstalling applications | 155 | // Don't allow adding launchers, editing, hiding, or uninstalling applications | ||
203 | // when system is immutable. | 156 | // when system is immutable. | ||
204 | if (systemImmutable) { | 157 | if (systemImmutable) { | ||
205 | return actionList; | 158 | return actionList; | ||
206 | } | 159 | } | ||
207 | 160 | | |||
208 | if (m_menuEntryEditor->canEdit(m_service->entryPath())) { | | |||
209 | actionList << Kicker::createSeparatorActionItem(); | | |||
210 | | ||||
211 | QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication"); | | |||
212 | editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading. | | |||
213 | actionList << editAction; | | |||
214 | } | | |||
215 | | ||||
216 | #ifdef HAVE_APPSTREAMQT | | |||
217 | if (m_service->isApplication()) { | 161 | if (m_service->isApplication()) { | ||
218 | actionList << appstreamActions(m_service); | 162 | actionList << Kicker::createSeparatorActionItem(); | ||
163 | actionList << Kicker::editApplicationAction(m_service); | ||||
164 | actionList << Kicker::appstreamActions(m_service); | ||||
219 | } | 165 | } | ||
220 | #endif | | |||
221 | 166 | | |||
222 | QQmlPropertyMap *appletConfig = qobject_cast<QQmlPropertyMap *>(appletInterface->property("configuration").value<QObject *>()); | 167 | QQmlPropertyMap *appletConfig = qobject_cast<QQmlPropertyMap *>(appletInterface->property("configuration").value<QObject *>()); | ||
223 | 168 | | |||
224 | if (appletConfig && appletConfig->contains("hiddenApplications") && qobject_cast<AppsModel *>(m_owner)) { | 169 | if (appletConfig && appletConfig->contains("hiddenApplications") && qobject_cast<AppsModel *>(m_owner)) { | ||
225 | const QStringList &hiddenApps = appletConfig->value("hiddenApplications").toStringList(); | 170 | const QStringList &hiddenApps = appletConfig->value("hiddenApplications").toStringList(); | ||
226 | 171 | | |||
227 | if (!hiddenApps.contains(m_service->menuId())) { | 172 | if (!hiddenApps.contains(m_service->menuId())) { | ||
228 | actionList << Kicker::createActionItem(i18n("Hide Application"), "hideApplication"); | 173 | actionList << Kicker::createActionItem(i18n("Hide Application"), "hideApplication"); | ||
Show All 26 Lines | 193 | #endif | |||
255 | 200 | | |||
256 | return true; | 201 | return true; | ||
257 | } | 202 | } | ||
258 | 203 | | |||
259 | QObject *appletInterface = m_owner->rootModel()->property("appletInterface").value<QObject *>(); | 204 | QObject *appletInterface = m_owner->rootModel()->property("appletInterface").value<QObject *>(); | ||
260 | 205 | | |||
261 | if (Kicker::handleAddLauncherAction(actionId, appletInterface, m_service)) { | 206 | if (Kicker::handleAddLauncherAction(actionId, appletInterface, m_service)) { | ||
262 | return true; | 207 | return true; | ||
263 | } else if (actionId == "editApplication" && m_menuEntryEditor->canEdit(m_service->entryPath())) { | 208 | } else if (Kicker::handleEditApplicationAction(actionId, m_service)) { | ||
264 | m_menuEntryEditor->edit(m_service->entryPath(), m_service->menuId()); | 209 | return true; | ||
265 | 210 | } else if (Kicker::handleAppstreamActions(actionId, argument)) { | |||
266 | return true; | 211 | return true; | ||
267 | } else if (actionId == "manageApplication") { | | |||
268 | return QDesktopServices::openUrl(QUrl(argument.toString())); | | |||
269 | } else if (actionId == "_kicker_jumpListAction") { | 212 | } else if (actionId == "_kicker_jumpListAction") { | ||
270 | return KRun::run(argument.toString(), {}, nullptr, m_service->name(), m_service->icon()); | 213 | return KRun::run(argument.toString(), {}, nullptr, m_service->name(), m_service->icon()); | ||
271 | } | 214 | } | ||
272 | 215 | | |||
273 | return Kicker::handleRecentDocumentAction(m_service, actionId, argument); | 216 | return Kicker::handleRecentDocumentAction(m_service, actionId, argument); | ||
274 | } | 217 | } | ||
275 | 218 | | |||
276 | QString AppEntry::nameFromService(const KService::Ptr service, NameFormat nameFormat) | 219 | QString AppEntry::nameFromService(const KService::Ptr service, NameFormat nameFormat) | ||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |