Fel*_*lix 1 qt taskbar kde progress-bar kde-plasma
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:
我有点被困,因为我什至不知道从哪里开始。我发现唯一有用的是KStatusBarJobTracker,但我不知道如何使用它。我找不到任何教程或示例如何执行此操作。
因此,在深入研究之后,并借助@leinir的帮助,我能够找到以下内容:
真正的问题是:仅在标准位置之一中有有效的桌面文件时,这才有效!您需要将文件作为DBus消息的参数传递,以使其正常工作。
根据这些信息,我弄清楚了如何使用它,并创建了一个GitHub存储库,该存储库支持跨平台任务栏进度,并将此API用于Linux实现。
但是,无论如何,这是怎么做。它应该适用于KDE Plasma和Unity桌面,也许更多(还没有尝试过):
.desktop为您的应用程序创建一个文件。出于测试目的,这可以是一个“虚拟”文件,如下所示:
[Desktop Entry]
Type=Application
Version=1.1
Name=MyApp
Exec=<path_to>/MyApp
Run Code Online (Sandbox Code Playgroud)将该文件复制到~/.local/share/applications/(或用户特定的桌面文件在系统上的任何位置)
在您的代码中,您所需要做的就是执行以下代码,以更新任务栏状态:
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);
Run Code Online (Sandbox Code Playgroud)编译并运行您的应用程序。您不必通过桌面文件启动它,至少我不需要。如果要确保您的应用程序已“连接”到该桌面文件,只需为该文件设置一个自定义图标即可。您的应用程序应在任务栏中显示该图标。
基本上就是这样。注意:重新启动应用程序时,系统会记住上一个状态。因此,启动应用程序时,应将所有这些参数重置一次。