Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
What is that Qt Language?. Are you talking about QScript or are you just asking for a C or C++ example? – Javier Rivera Oct 10 '11 at 9:42
I am talking about this: qt.nokia.com/products As much as I understand Qt is just a framework for C++. – kv1dr Oct 10 '11 at 11:10
Not just, it's a full library that can be used with loads of languages, including Python. I understand that you are asking for a C++ example, if you use Qt or any other library doesn't matter. Can you edit the question to make it clear?. (BTW: Unity 2D is made with Qt), – Javier Rivera Oct 10 '11 at 11:35
Ok then...I mean an example for C++ :) – kv1dr Oct 10 '11 at 12:37

1 Answer

up vote 4 down vote accepted

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

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

share|improve this answer
I haven't any experience in C++, but why don't you just import libunity (#include <unity/unity/unity.h>) and use the API? – Javier Rivera Oct 11 '11 at 6:45
Thank you foxoman. This works like a charm :) Warning for everyone: Don't forget the first step(like I did), otherwise this will not work. :) (First step : add this line to your Qt project file .pro QT += dbus) – kv1dr Oct 11 '11 at 7:16
@JavierRivera: I tried to import libunity, but it doesn't find unity.h. There is a ton of libraries I can import(according to autocomplete function), but there is no library named unity. – kv1dr Oct 11 '11 at 7:24
1  
whoops, I forgot to install libunity-dev. But now, there is another problem with glib.h(/usr/include/unity/unity/unity.h:7: error: glib.h: No such file or directory), but I have libglib2.0-dev installed. – kv1dr Oct 11 '11 at 9:24
2  
@Javier Rivera : I tried to use libunity with the QLibrary help but it take to much effort to reach the same result with dbus api . – foxoman Oct 11 '11 at 11:11
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.