summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rosca <[email protected]>2016-09-22 12:55:45 +0200
committerDavid Rosca <[email protected]>2016-10-08 12:46:08 +0200
commit5e175a976967f53fe683ce12e76b1144d98d24d4 (patch)
treeb5c948d2c6d0c4a1679a88d9b9d6228dfacc9925
parent95cb8b51ade0b1491e65a6022e4f4554653329b5 (diff)
Quicklaunch: Add support for jumplist actions
Differential Revision: https://phabricator.kde.org/D2833
-rw-r--r--applets/quicklaunch/package/contents/ui/IconItem.qml37
-rw-r--r--applets/quicklaunch/plugin/quicklaunch_p.cpp45
-rw-r--r--applets/quicklaunch/plugin/quicklaunch_p.h5
3 files changed, 77 insertions, 10 deletions
diff --git a/applets/quicklaunch/package/contents/ui/IconItem.qml b/applets/quicklaunch/package/contents/ui/IconItem.qml
index 198836a..fc0eb98 100644
--- a/applets/quicklaunch/package/contents/ui/IconItem.qml
+++ b/applets/quicklaunch/package/contents/ui/IconItem.qml
@@ -74,6 +74,7 @@ Item {
if (mouse.button == Qt.LeftButton) {
logic.openUrl(url)
} else if (mouse.button == Qt.RightButton) {
+ contextMenu.refreshActions();
contextMenu.open(mouse.x, mouse.y);
}
}
@@ -122,9 +123,17 @@ Item {
PlasmaComponents.ContextMenu {
id: contextMenu
+
+ property var jumpListItems : []
+
visualParent: mouseArea
PlasmaComponents.MenuItem {
+ id: jumpListSeparator
+ separator: true
+ }
+
+ PlasmaComponents.MenuItem {
text: i18n("Add Launcher...")
icon: "list-add"
onClicked: addLauncher()
@@ -153,6 +162,34 @@ Item {
PlasmaComponents.MenuItem {
action: plasmoid.action("remove")
}
+
+ function refreshActions() {
+ for (var i = 0; i < jumpListItems.length; ++i) {
+ var item = jumpListItems[i];
+ removeMenuItem(item);
+ item.destroy();
+ }
+ jumpListItems = [];
+
+ for (var i = 0; i < launcher.jumpListActions.length; ++i) {
+ var action = launcher.jumpListActions[i];
+ var item = menuItemComponent.createObject(iconItem, {
+ "text": action.name,
+ "icon": action.icon
+ });
+ item.clicked.connect(function() {
+ logic.openExec(this.exec);
+ }.bind(action));
+
+ addMenuItem(item, jumpListSeparator);
+ jumpListItems.push(item);
+ }
+ }
+ }
+
+ Component {
+ id: menuItemComponent
+ PlasmaComponents.MenuItem { }
}
}
}
diff --git a/applets/quicklaunch/plugin/quicklaunch_p.cpp b/applets/quicklaunch/plugin/quicklaunch_p.cpp
index 04561e5..6b052c7 100644
--- a/applets/quicklaunch/plugin/quicklaunch_p.cpp
+++ b/applets/quicklaunch/plugin/quicklaunch_p.cpp
@@ -44,11 +44,12 @@ QuicklaunchPrivate::QuicklaunchPrivate(QObject *parent)
{
}
-QJsonObject QuicklaunchPrivate::launcherData(const QUrl &url)
+QVariantMap QuicklaunchPrivate::launcherData(const QUrl &url)
{
QString name;
QString icon;
QString genericName;
+ QVariantList jumpListActions;
if (url.scheme() == QLatin1String("quicklaunch")) {
// Ignore internal scheme
@@ -64,6 +65,28 @@ QJsonObject QuicklaunchPrivate::launcherData(const QUrl &url)
if (name.isEmpty()) {
name = QFileInfo(url.toLocalFile()).fileName();
}
+
+ const QStringList &actions = f.readActions();
+
+ foreach (const QString &actionName, actions) {
+ const KConfigGroup &actionGroup = f.actionGroup(actionName);
+
+ if (!actionGroup.isValid() || !actionGroup.exists()) {
+ continue;
+ }
+
+ const QString &name = actionGroup.readEntry("Name");
+ const QString &exec = actionGroup.readEntry("Exec");
+ if (name.isEmpty() || exec.isEmpty()) {
+ continue;
+ }
+
+ jumpListActions << QVariantMap{
+ {QStringLiteral("name"), name},
+ {QStringLiteral("icon"), actionGroup.readEntry("Icon")},
+ {QStringLiteral("exec"), exec}
+ };
+ }
} else {
QMimeDatabase db;
name = fi.baseName();
@@ -82,11 +105,12 @@ QJsonObject QuicklaunchPrivate::launcherData(const QUrl &url)
icon = KIO::iconNameForUrl(url);
}
- QJsonObject data;
- data[QStringLiteral("applicationName")] = name;
- data[QStringLiteral("iconName")] = icon;
- data[QStringLiteral("genericName")] = genericName;
- return data;
+ return QVariantMap{
+ {QStringLiteral("applicationName"), name},
+ {QStringLiteral("iconName"), icon},
+ {QStringLiteral("genericName"), genericName},
+ {QStringLiteral("jumpListActions"), jumpListActions}
+ };
}
void QuicklaunchPrivate::openUrl(const QUrl &url)
@@ -94,6 +118,11 @@ void QuicklaunchPrivate::openUrl(const QUrl &url)
new KRun(url, Q_NULLPTR);
}
+void QuicklaunchPrivate::openExec(const QString &exec)
+{
+ KRun::run(exec, {}, Q_NULLPTR);
+}
+
void QuicklaunchPrivate::addLauncher(bool isPopup)
{
KOpenWithDialog *dialog = new KOpenWithDialog();
@@ -151,8 +180,8 @@ void QuicklaunchPrivate::editLauncher(QUrl url, int index, bool isPopup)
bool desktopFileCreated = false;
if (!url.isLocalFile() || !KDesktopFile::isDesktopFile(url.toLocalFile())) {
- QString desktopFilePath = determineNewDesktopFilePath(QStringLiteral("launcher"));
- QJsonObject data = launcherData(url);
+ const QString desktopFilePath = determineNewDesktopFilePath(QStringLiteral("launcher"));
+ const QVariantMap data = launcherData(url);
KConfig desktopFile(desktopFilePath);
KConfigGroup desktopEntry(&desktopFile, "Desktop Entry");
diff --git a/applets/quicklaunch/plugin/quicklaunch_p.h b/applets/quicklaunch/plugin/quicklaunch_p.h
index 7b447bc..e143e53 100644
--- a/applets/quicklaunch/plugin/quicklaunch_p.h
+++ b/applets/quicklaunch/plugin/quicklaunch_p.h
@@ -23,7 +23,7 @@
#include <QUrl>
#include <QObject>
-#include <QJsonObject>
+#include <QVariantMap>
class QuicklaunchPrivate : public QObject
{
@@ -32,8 +32,9 @@ class QuicklaunchPrivate : public QObject
public:
explicit QuicklaunchPrivate(QObject *parent = Q_NULLPTR);
- Q_INVOKABLE QJsonObject launcherData(const QUrl &url);
+ Q_INVOKABLE QVariantMap launcherData(const QUrl &url);
Q_INVOKABLE void openUrl(const QUrl &url);
+ Q_INVOKABLE void openExec(const QString &exec);
Q_INVOKABLE void addLauncher(bool isPopup = false);
Q_INVOKABLE void editLauncher(QUrl url, int index, bool isPopup = false);