KDE Taskbar Progress
Asked Answered
A

2

4

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:

enter image description here

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.

Aude answered 9/5, 2017 at 16:34 Comment(0)
C
2

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 :)

Cowlick answered 9/5, 2017 at 16:58 Comment(4)
I will propably create a github repository for it.Aude
However, I think this works for Ubuntu Unity desktop only? I using the KDE Plasma DesktopAude
I've got it working now! I will post my own answer tomorrow showing the "full" solution.Aude
Brilliant call, and i would like to forward thanks from Eike Hein (who you might know as that guy that recently, after maintaining the old stack for years, rewrote the entire taskbar subsystem in plasma 5) for doing so! :)Cowlick
A
10

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):

  1. 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
    
  2. Copy that file to ~/.local/share/applications/ (or wherever user specific desktop files go on your system)

  3. 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);
    
  4. 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.

Aude answered 11/5, 2017 at 15:25 Comment(1)
Do you know of a way to make this work from a bash script? im not at all experienced with QtMeadors
C
2

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 :)

Cowlick answered 9/5, 2017 at 16:58 Comment(4)
I will propably create a github repository for it.Aude
However, I think this works for Ubuntu Unity desktop only? I using the KDE Plasma DesktopAude
I've got it working now! I will post my own answer tomorrow showing the "full" solution.Aude
Brilliant call, and i would like to forward thanks from Eike Hein (who you might know as that guy that recently, after maintaining the old stack for years, rewrote the entire taskbar subsystem in plasma 5) for doing so! :)Cowlick

© 2022 - 2024 — McMap. All rights reserved.