Notices


Reply
Thread Tools
velox's Avatar
Posts: 291 | Thanked: 939 times | Joined on Dec 2009
#91
There are a few ways to start, but I found the easiest way (for me) was to just install the SailfishOS SDK. The files you get as an entry point when just creating a new project in there are pretty good to "poke at and see what happens". It's basically a "Hello world" as well.
__________________
slumber: sensors enabled sleep timer for SFOS (translations/input/ appreciated if you've got some spare time)
talefish: directory based audiobook player for SFOS
___
list of i486/noarch packages on openrepos (jolla tablet)
 

The Following User Says Thank You to velox For This Useful Post:
Markkyboy's Avatar
Posts: 241 | Thanked: 286 times | Joined on Oct 2012 @ Planet Thanet
#92
Forget it. Sorry I asked. I'll work it out myself.
__________________
moderator@openrepos
___________________

T.J.C.

Omelettes - You can't make one without breaking an egg.
 

The Following User Says Thank You to Markkyboy For This Useful Post:
Posts: 447 | Thanked: 1,216 times | Joined on Feb 2012 @ Germany
#93
Here is my dbus notification example, it was created for testing and understanding purpos to use it in another application.

After birth it was already nearly a small console tool so I added a small help description.
If somebody interested I uploaded it to openrepos as a package.

For dbus related code, scroll to the end please.

Code:
/*sfnotify - notification through dbus for sailfish
    Copyright (C) <2017> <Halftux>

    This file is part of sfnotify.

    gpscon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    gpscon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with gpscon. If not, see <http://www.gnu.org/licenses/>.*/

#include <QDebug>
#include <QTextStream>
#include <QStringList>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusArgument>
#include <QDBusVariant>
#include <QVariantMap>

int main(int argc, char *argv[])
{
    QString summary, body;
    QStringList arglist;
    int timeout=2000;
    bool showhelp=false;

    if (argc > 1)
    {
        for ( int i = 1; i < argc; i++ )
        {
            //qDebug() << i << argv[i] << argc;
            arglist << argv[i];
        }
        QRegExp rx("summary*");
        rx.setPatternSyntax(QRegExp::Wildcard);

        int posfind = arglist.indexOf(rx);
        if (posfind!=-1)
        {
            summary=arglist.at(posfind);
            summary=summary.mid(8,summary.length()-2);
            //qDebug() << "summary: " << summary;
        }
        else qDebug() << "no summary detected";

        rx.setPattern("body*");
        posfind = arglist.indexOf(rx);
        if (posfind!=-1)
        {
            body=arglist.at(posfind);
            body=body.mid(5,body.length()-2);
            //qDebug() << "body: " << body;
        }
        else qDebug() << "no body detected";

        rx.setPattern("timeout*");
        posfind = arglist.indexOf(rx);
        if (posfind!=-1)
        {
            timeout=arglist.at(posfind).mid(8,arglist.at(posfind).length()-2).toInt();
            //qDebug() << "timeout: " << timeout;
        }
        else qDebug() << "no timeout detected using default value 2000";

        if (arglist.contains("--help") || arglist.contains("-h")) showhelp=true;

    //qDebug() << summary << body << timeout << showhelp;
    }

    if (summary=="" && body=="")
    {
        summary="sfnotify";
        body="it makes no sense to make a notification without a text. get info with --help";
        showhelp=true;
    }

    if (showhelp)
    {
        QTextStream cout(stdout);
                    cout << endl;
                    cout << "sfnotify v0.0.1 by halftux" << endl << endl;
                    cout << "Options:" << endl;
                    cout << "--------" << endl;
                    cout << "  [--help] help output" << endl;
                    cout << "  [summary='string'] summary text" << endl;
                    cout << "  [body='string'] body text" << endl;
                    cout << "  [timeout=integer] close after x ms" << endl;
    }
    else
    {
        QStringList action_slist;
        action_slist << "default" << "";
        QVariantMap hint_vmap;
        hint_vmap["x-nemo-preview-body"] = QVariant(body);
        hint_vmap["x-nemo-preview-summary"] = QVariant(summary);
        hint_vmap["x-nemo-icon"] = QVariant("icon-m-notifications");

        QDBusConnection bus = QDBusConnection::sessionBus();
        QDBusInterface notify("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", bus);
        QVariantList args;
        args << QString("Appname");
        args << uint(0);
        args << QString("icon-m-notifications");
        args << QString("Summary");
        args << QString("Body");
        args << QStringList(action_slist);
        args << QVariantMap(hint_vmap);
        args << timeout;
        QDBusMessage call = notify.callWithArgumentList(QDBus::Block, "Notify", args);
        uint id = call.arguments().first().toUInt();
        qDebug() << "id:" << id;
    }
    return 0;
}
My first full application in a forum post.
My way to say thank you for a thread with useful information.
 

The Following 5 Users Say Thank You to Halftux For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 07:53.