我有些困惑,因为我甚至不知道该如何入手。我找到的唯一有用的东西是KStatusBarJobTracker,但我不知道该如何使用它。我没有找到任何关于如何实现这个目标的教程或例子。
我有些困惑,因为我甚至不知道该如何入手。我找到的唯一有用的东西是KStatusBarJobTracker,但我不知道该如何使用它。我没有找到任何关于如何实现这个目标的教程或例子。
真正的问题是:这仅在您拥有标准位置之一的有效桌面文件时才起作用!您需要将文件作为DBus消息的参数传递才能使其起作用。
基于这些信息,我找出了如何使用它,并创建了一个GitHub存储库,支持跨平台任务栏进度,并在linux实现中使用了此API。
无论如何,以下是如何操作。它应该适用于KDE Plasma和Unity桌面,可能还有其他桌面(我没有尝试过):
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.
基本上就是这样。 注意: 当重新启动应用程序时,系统会记住上次的状态。因此,在启动应用程序时,您应该重置所有这些参数。
没错,事实证明你是正确的,目前没有这方面的教程。然而,这个Reviewboard请求展示了它是如何在KDevelop中实现的,你应该可以通过那个找到解决方法 :) https://git.reviewboard.kde.org/r/127050/
ps: 目前没有教程可能是一个很好的机会,让你参与进来并提供一些小型、自包含的教程... 我相信这将非常受欢迎 :)