Saturday, May 4, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 3250  / 2 Years ago, tue, october 25, 2022, 2:12:25

I am trying to develop some program in QT with QT SDK. Yesterday I was reading about Unity Launcher API on official ubuntu website. But there is example only for Vala and python. Is possible to use Unity Launcher API(quicklists, counters, and progress bars) with C++ language and if it's possible, please post an example.


More From » application-development

 Answers
7

I'm also learning Qt and tried to find a way to use Unity API in Qt , I could only use Dbus API , but no luck with Quicklist since it needs a DbusMenu and I do not know how to implement that (still learning :) ).



This is the example I created for my self and I hope it's useful for others .
Maybe Unity devs can help to correct / fix / add new code (quicklist) to it :)



/*
Unity Launcher Dbus API exmable for Qt
foxoman [gplus.to/foxoman][[email protected]]

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();
}


download the example here
http://ubuntuone.com/1SLDPcN9OhrU6LD1wgDs3r


[#43150] Wednesday, October 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tiowift

Total Points: 119
Total Questions: 113
Total Answers: 110

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
tiowift questions
Wed, Aug 3, 22, 04:45, 2 Years ago
Mon, Nov 7, 22, 10:58, 2 Years ago
Wed, May 10, 23, 17:52, 1 Year ago
;