| The Following User Says Thank You to velox For This Useful Post: | ||
|
|
2015-12-29
, 19:26
|
|
|
Posts: 433 |
Thanked: 726 times |
Joined on Oct 2012
@ Costa Blanca, España
|
#92
|
| The Following User Says Thank You to Markkyboy For This Useful Post: | ||
|
|
2017-03-31
, 20:15
|
|
|
Posts: 835 |
Thanked: 2,424 times |
Joined on Feb 2012
@ Germany
|
#93
|


/*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;
}

| The Following 5 Users Say Thank You to Halftux For This Useful Post: | ||
slumber: sensors enabled sleep timer for SFOS (translations/input/… appreciated if you've got some spare time)
talefish: directory based audiobook player for SFOS
nofono: ofono restart for SFOS
___
list of i486/noarch packages on openrepos (jolla tablet)