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