Changeset View
Changeset View
Standalone View
Standalone View
applets/taskmanager/plugin/backend.cpp
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 117 | if (highlight != m_highlightWindows) { | |||
---|---|---|---|---|---|
118 | m_highlightWindows = highlight; | 118 | m_highlightWindows = highlight; | ||
119 | 119 | | |||
120 | updateWindowHighlight(); | 120 | updateWindowHighlight(); | ||
121 | 121 | | |||
122 | emit highlightWindowsChanged(); | 122 | emit highlightWindowsChanged(); | ||
123 | } | 123 | } | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | QUrl tryDecodeApplicationsUrl(const QUrl &launcherUrl) | ||||
127 | { | ||||
128 | if (launcherUrl.isValid() && launcherUrl.scheme() == QStringLiteral("applications")) { | ||||
129 | const KService::Ptr service = KService::serviceByMenuId(launcherUrl.path()); | ||||
130 | | ||||
131 | if (service) { | ||||
132 | return QUrl::fromLocalFile(service->entryPath()); | ||||
133 | } | ||||
134 | } | ||||
135 | | ||||
136 | return launcherUrl; | ||||
137 | } | ||||
138 | | ||||
126 | QVariantList Backend::jumpListActions(const QUrl &launcherUrl, QObject *parent) | 139 | QVariantList Backend::jumpListActions(const QUrl &launcherUrl, QObject *parent) | ||
127 | { | 140 | { | ||
128 | QVariantList actions; | 141 | if (!parent) { | ||
142 | return QVariantList(); | ||||
143 | } | ||||
129 | 144 | | |||
130 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | 145 | QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); | ||
131 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | 146 | | ||
132 | return actions; | 147 | if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() | ||
148 | || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { | ||||
149 | return QVariantList(); | ||||
133 | } | 150 | } | ||
134 | 151 | | |||
135 | KDesktopFile desktopFile(launcherUrl.toLocalFile()); | 152 | QVariantList actions; | ||
153 | KDesktopFile desktopFile(desktopEntryUrl.toLocalFile()); | ||||
136 | 154 | | |||
137 | const QStringList &jumpListActions = desktopFile.readActions(); | 155 | const QStringList &jumpListActions = desktopFile.readActions(); | ||
138 | 156 | | |||
139 | const QLatin1String kde("KDE"); | 157 | const QLatin1String kde("KDE"); | ||
140 | 158 | | |||
141 | foreach (const QString &actionName, jumpListActions) { | 159 | foreach (const QString &actionName, jumpListActions) { | ||
142 | const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); | 160 | const KConfigGroup &actionGroup = desktopFile.actionGroup(actionName); | ||
143 | 161 | | |||
Show All 29 Lines | |||||
173 | actions << QVariant::fromValue<QAction *>(action); | 191 | actions << QVariant::fromValue<QAction *>(action); | ||
174 | } | 192 | } | ||
175 | 193 | | |||
176 | return actions; | 194 | return actions; | ||
177 | } | 195 | } | ||
178 | 196 | | |||
179 | QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent) | 197 | QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces, QObject *parent) | ||
180 | { | 198 | { | ||
181 | QVariantList actions; | 199 | if (!parent) { | ||
200 | return QVariantList(); | ||||
201 | } | ||||
182 | 202 | | |||
183 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | 203 | QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); | ||
184 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | 204 | | ||
185 | return actions; | 205 | if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() | ||
206 | || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { | ||||
207 | return QVariantList(); | ||||
186 | } | 208 | } | ||
187 | 209 | | |||
188 | KDesktopFile desktopFile(launcherUrl.toLocalFile()); | 210 | QVariantList actions; | ||
211 | KDesktopFile desktopFile(desktopEntryUrl.toLocalFile()); | ||||
189 | 212 | | |||
190 | // Since we can't have dynamic jump list actions, at least add the user's "Places" for file managers. | 213 | // Since we can't have dynamic jump list actions, at least add the user's "Places" for file managers. | ||
191 | const QStringList &categories = desktopFile.desktopGroup().readXdgListEntry(QStringLiteral("Categories")); | 214 | const QStringList &categories = desktopFile.desktopGroup().readXdgListEntry(QStringLiteral("Categories")); | ||
192 | if (!categories.contains(QLatin1String("FileManager"))) { | 215 | if (!categories.contains(QLatin1String("FileManager"))) { | ||
193 | return actions; | 216 | return actions; | ||
194 | } | 217 | } | ||
195 | 218 | | |||
196 | QScopedPointer<KFilePlacesModel> placesModel(new KFilePlacesModel()); | 219 | QScopedPointer<KFilePlacesModel> placesModel(new KFilePlacesModel()); | ||
197 | for (int i = 0; i < placesModel->rowCount(); ++i) { | 220 | for (int i = 0; i < placesModel->rowCount(); ++i) { | ||
198 | QModelIndex idx = placesModel->index(i, 0); | 221 | QModelIndex idx = placesModel->index(i, 0); | ||
199 | 222 | | |||
200 | if (placesModel->data(idx, KFilePlacesModel::HiddenRole).toBool()) { | 223 | if (placesModel->data(idx, KFilePlacesModel::HiddenRole).toBool()) { | ||
201 | continue; | 224 | continue; | ||
202 | } | 225 | } | ||
203 | 226 | | |||
204 | const QString &title = placesModel->data(idx, Qt::DisplayRole).toString(); | 227 | const QString &title = placesModel->data(idx, Qt::DisplayRole).toString(); | ||
205 | const QIcon &icon = placesModel->data(idx, Qt::DecorationRole).value<QIcon>(); | 228 | const QIcon &icon = placesModel->data(idx, Qt::DecorationRole).value<QIcon>(); | ||
206 | const QUrl &url = placesModel->data(idx, KFilePlacesModel::UrlRole).toUrl(); | 229 | const QUrl &url = placesModel->data(idx, KFilePlacesModel::UrlRole).toUrl(); | ||
207 | 230 | | |||
208 | QAction *action = new QAction(icon, title, parent); | 231 | QAction *action = new QAction(icon, title, parent); | ||
209 | 232 | | |||
210 | connect(action, &QAction::triggered, this, [this, action, url, launcherUrl] { | 233 | connect(action, &QAction::triggered, this, [this, action, url, desktopEntryUrl] { | ||
211 | KService::Ptr service = KService::serviceByDesktopPath(launcherUrl.toLocalFile()); | 234 | KService::Ptr service = KService::serviceByDesktopPath(desktopEntryUrl.toLocalFile()); | ||
212 | if (!service) { | 235 | if (!service) { | ||
213 | return; | 236 | return; | ||
214 | } | 237 | } | ||
215 | 238 | | |||
216 | KRun::runService(*service, {url}, QApplication::activeWindow()); | 239 | KRun::runService(*service, {url}, QApplication::activeWindow()); | ||
217 | }); | 240 | }); | ||
218 | 241 | | |||
219 | actions << QVariant::fromValue(action); | 242 | actions << QVariant::fromValue(action); | ||
Show All 14 Lines | 247 | if (!showAllPlaces && actions.count() > 7) { | |||
234 | actions << QVariant::fromValue(action); | 257 | actions << QVariant::fromValue(action); | ||
235 | } | 258 | } | ||
236 | 259 | | |||
237 | return actions; | 260 | return actions; | ||
238 | } | 261 | } | ||
239 | 262 | | |||
240 | QVariantList Backend::recentDocumentActions(const QUrl &launcherUrl, QObject *parent) | 263 | QVariantList Backend::recentDocumentActions(const QUrl &launcherUrl, QObject *parent) | ||
241 | { | 264 | { | ||
242 | QVariantList actions; | 265 | if (!parent) { | ||
266 | return QVariantList(); | ||||
267 | } | ||||
243 | 268 | | |||
244 | if (!parent || !launcherUrl.isValid() || !launcherUrl.isLocalFile() | 269 | QUrl desktopEntryUrl = tryDecodeApplicationsUrl(launcherUrl); | ||
245 | || !KDesktopFile::isDesktopFile(launcherUrl.toLocalFile())) { | 270 | | ||
246 | return actions; | 271 | if (!desktopEntryUrl.isValid() || !desktopEntryUrl.isLocalFile() | ||
272 | || !KDesktopFile::isDesktopFile(desktopEntryUrl.toLocalFile())) { | ||||
273 | return QVariantList(); | ||||
247 | } | 274 | } | ||
248 | 275 | | |||
249 | QString desktopName = launcherUrl.fileName(); | 276 | QVariantList actions; | ||
277 | QString desktopName = desktopEntryUrl.fileName(); | ||||
250 | QString storageId = desktopName; | 278 | QString storageId = desktopName; | ||
251 | 279 | | |||
252 | if (storageId.startsWith(QLatin1String("org.kde."))) { | 280 | if (storageId.startsWith(QLatin1String("org.kde."))) { | ||
253 | storageId = storageId.right(storageId.length() - 8); | 281 | storageId = storageId.right(storageId.length() - 8); | ||
254 | } | 282 | } | ||
255 | 283 | | |||
256 | if (storageId.endsWith(QLatin1String(".desktop"))) { | 284 | if (storageId.endsWith(QLatin1String(".desktop"))) { | ||
257 | storageId = storageId.left(storageId.length() - 8); | 285 | storageId = storageId.left(storageId.length() - 8); | ||
Show All 25 Lines | 301 | while (actionCount < 5 && resultIt != results.end()) { | |||
283 | if (!fileItem.isFile()) { | 311 | if (!fileItem.isFile()) { | ||
284 | continue; | 312 | continue; | ||
285 | } | 313 | } | ||
286 | 314 | | |||
287 | QAction *action = new QAction(parent); | 315 | QAction *action = new QAction(parent); | ||
288 | action->setText(url.fileName()); | 316 | action->setText(url.fileName()); | ||
289 | action->setIcon(QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme("unknown"))); | 317 | action->setIcon(QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme("unknown"))); | ||
290 | action->setProperty("agent", storageId); | 318 | action->setProperty("agent", storageId); | ||
291 | action->setProperty("entryPath", launcherUrl); | 319 | action->setProperty("entryPath", desktopEntryUrl); | ||
292 | action->setData(resource); | 320 | action->setData(resource); | ||
293 | connect(action, &QAction::triggered, this, &Backend::handleRecentDocumentAction); | 321 | connect(action, &QAction::triggered, this, &Backend::handleRecentDocumentAction); | ||
294 | 322 | | |||
295 | actions << QVariant::fromValue<QAction *>(action); | 323 | actions << QVariant::fromValue<QAction *>(action); | ||
296 | 324 | | |||
297 | ++resultIt; | 325 | ++resultIt; | ||
298 | ++actionCount; | 326 | ++actionCount; | ||
299 | } | 327 | } | ||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |