kv1*_*1dr 10 unity qt c++ application-development
我正在尝试使用 QT SDK 在 QT 中开发一些程序。昨天我在 ubuntu 官方网站上阅读了有关Unity Launcher API 的信息。但是只有 Vala 和 python 的例子。是否可以将 Unity Launcher API(快速列表、计数器和进度条)与 C++ 语言一起使用,如果可能,请发布示例。
我也在学习 Qt 并试图找到一种在 Qt 中使用 Unity API 的方法,我只能使用 Dbus API,但没有使用 Quicklist,因为它需要一个 DbusMenu,我不知道如何实现它(仍在学习:) )。
这是我为自己创建的示例,希望对其他人有用。也许 Unity 开发人员可以帮助纠正/修复/添加新代码(快速列表):)
/*
Unity Launcher Dbus API exmable for Qt
foxoman [gplus.to/foxoman][foxoman.u@gmail.com]
https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
First step : add this line to your Qt project file .pro
QT += dbus
*/
/* I will run this example as Qt console apps */
#include <QtCore/QCoreApplication>
/* Include Qt Dbus required */
#include <QtDBus>
// Qt Main Method
int main(int argc, char *argv[])
{
/* Qt console Main Loop [ in GUI application the Main loop is QApplication ]
Unity API need Main Loop to run */
QCoreApplication a(argc, argv);
/* Create Qt Dbus Signal to send Dbus Message to unity Dbus API
signal com.canonical.Unity.LauncherEntry.Update (in s app_uri, in a{sv} properties)
*/
QDBusMessage signal = QDBusMessage::createSignal(
"/", /* Path */
"com.canonical.Unity.LauncherEntry", /* Unity DBus Interface */
"Update"); /* Update Signal */
/* app_uri
Desktop ID ex: firefox -> need to be pined in the launcher to see the effect
*/
signal << "application://firefox.desktop";
/* properties : A map of strings to variants with the properties to set on the launcher icon */
QVariantMap setProperty;
/* A number to display on the launcher icon */
setProperty.insert("count", qint64(80));
/* show count */
setProperty.insert("count-visible", true);
/* progress bar count must be float between 0 and 1 (mean from 0.00 to 0.100)*/
setProperty.insert("progress", double(0.80));
/* show progress bar */
setProperty.insert("progress-visible", true);
/* Tells the launcher to get the users attention */
setProperty.insert("urgent",true);
/* Pack the properties Map to the signal */
signal << setProperty;
/* Send the signal */
QDBusConnection::sessionBus().send(signal);
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
在此处下载示例 http://ubuntuone.com/1SLDPcN9OhrU6LD1wgDs3r