问题
I am trying to show a progress in the taskbar of the plasma desktop using the KDE Frameworks. In short, it want to do the same thing as dolphin, when it copies files:
I'm kinda stuck, because I don't even know where to get started. The only thing I found that could be useful is KStatusBarJobTracker, but I don't know how to use it. I could not find any tutorials or examples how to do this.
回答1:
Right, so as it turns out you are right, there is not currently a tutorial for this. This reviewboard request, however, shows how it was implemented in KDevelop, and it should be possible for you to work it out through that :) https://git.reviewboard.kde.org/r/127050/
ps: that there is no tutorial now might be a nice way for you to hop in and help out, by writing a small, self contained tutorial for it... something i'm sure would be very much welcomed :)
回答2:
So, after digging around, and thanks to the help of @leinir, I was able to find out the following:
- Since Plasma 5.6 KDE supports the Unitiy DBus Launcher-API, which can be used, for example, to show progress
- I found a post on AskUbuntu that explains how to use the API with Qt
The real problem is: This only works, if you have a valid desktop file in one of the standard locations! You need to pass the file as parameter of the DBus message to make it work.
Based on this information, I figured out how to use it and created a GitHub repository, that supports cross platform taskbar progress, and uses this API for the linux implementation.
However, here is how to do it anyways. It should work for KDE Plasma and the Unity desktop, maybe more (haven't tried any others):
Create a
.desktop
file for your application. For test purpose, this can be a "dummy" file, that could look like this:[Desktop Entry] Type=Application Version=1.1 Name=MyApp Exec=<path_to>/MyApp
Copy that file to
~/.local/share/applications/
(or wherever user specific desktop files go on your system)In your code, all you need to do is execute the following code, to update the taskbar state:
auto message = QDBusMessage::createSignal(QStringLiteral("/com/example/MyApp"), QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update")); //you don't always have to specify all parameters, just the ones you want to update QVariantMap properties; properties.insert(QStringLiteral("progress-visible"), true);// enable the progress properties.insert(QStringLiteral("progress"), 0.5);// set the progress value (from 0.0 to 1.0) properties.insert(QStringLiteral("count-visible"), true);// display the "counter badge" properties.insert(QStringLiteral("count"), 42);// set the counter value message << QStringLiteral("application://myapp.desktop") //assuming you named the desktop file "myapp.desktop" << properties; QDBusConnection::sessionBus().send(message);
Compile and run your application. You don't have to start it via the desktop file, at least I did not need to. If you want to be sure your application is "connected" to that desktop file, just set a custom icon for the file. Your application should show that icon in the taskbar.
And thats basically it. Note: The system remembers the last state when restarting the application. Thus, you should reset all those parameters once when starting the application.
来源:https://stackoverflow.com/questions/43875343/kde-taskbar-progress