Push UnifiedPush come harbour-fmd (0.16.0)
Connector D-Bus org.unifiedpush.Connector.harbour-grumpydove: possiede il nome, esporta NewEndpoint/Message/Unregistered (Q_CLASSINFO sulla classe, non su un adaptor: con un adaptor l'interfaccia non viene esportata), si registra col distributore FogHorn in asincrono e salva token ed endpoint. Il risveglio si dirama per ambiente (GRUMPYDOVE_PUSH_WAKE=1) prima di creare la GUI: nessuna finestra, motore in un thread, checkMail, notifica via org.freedesktop.Notifications, uscita con tetto a 60 s. preparaPercorsiMotore() sta in un posto solo, usata da app e risveglio.
This commit is contained in:
1 parent
d7549cedd0
commit
d9aa530ffd
8 files changed
+323
-35
No files matched your search
@@ -3,7 +3,8 @@ TARGET = harbour-grumpydove
|
|||||||
|
|
||||||
CONFIG += sailfishapp
|
CONFIG += sailfishapp
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
# QtDBus per il connector UnifiedPush (org.unifiedpush.Connector2)
|
||||||
|
QT += dbus
|
||||||
# Icone dell'originale compilate nel binario: source QML "qrc:/images/..."
|
# Icone dell'originale compilate nel binario: source QML "qrc:/images/..."
|
||||||
RESOURCES += images.qrc
|
RESOURCES += images.qrc
|
||||||
|
|
||||||
@@ -22,10 +23,12 @@ SOURCES += \
|
|||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/enginebridge.cpp \
|
src/enginebridge.cpp \
|
||||||
src/enginecallbacks.cpp \
|
src/enginecallbacks.cpp \
|
||||||
|
src/pushservice.cpp \
|
||||||
src/accountsettings.cpp
|
src/accountsettings.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/enginebridge.h \
|
src/enginebridge.h \
|
||||||
|
src/pushservice.h \
|
||||||
src/accountsettings.h
|
src/accountsettings.h
|
||||||
|
|
||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ Page {
|
|||||||
|
|
||||||
// Le callback del motore arrivano quando il bridge le riceve: se la pagina
|
// Le callback del motore arrivano quando il bridge le riceve: se la pagina
|
||||||
// e' gia' aperta, si ricarica qui.
|
// e' gia' aperta, si ricarica qui.
|
||||||
|
Connections {
|
||||||
|
target: pushService
|
||||||
|
// Il push non porta dati: dice solo che c'è posta da guardare.
|
||||||
|
onPushReceived: {
|
||||||
|
page.nonLettiPrima = engine.totalUnread();
|
||||||
|
engine.checkMail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: engine
|
target: engine
|
||||||
onReady: page.carica()
|
onReady: page.carica()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ Name[it_IT]=GrumpyDove
|
|||||||
Comment=Eudora-style mail interface, mobile prototype
|
Comment=Eudora-style mail interface, mobile prototype
|
||||||
Comment[it_IT]=Interfaccia mail in stile Eudora, prototipo mobile
|
Comment[it_IT]=Interfaccia mail in stile Eudora, prototipo mobile
|
||||||
Exec=harbour-grumpydove
|
Exec=harbour-grumpydove
|
||||||
|
ExecDBus=harbour-grumpydove
|
||||||
|
X-DBusActivatable=true
|
||||||
Icon=harbour-grumpydove
|
Icon=harbour-grumpydove
|
||||||
Type=Application
|
Type=Application
|
||||||
X-Nemo-Application-Type=silica-qt5
|
X-Nemo-Application-Type=silica-qt5
|
||||||
@@ -11,6 +13,6 @@ Categories=Network;
|
|||||||
|
|
||||||
# Internet = posta; Downloads = dove vanno gli allegati salvati.
|
# Internet = posta; Downloads = dove vanno gli allegati salvati.
|
||||||
[X-Sailjail]
|
[X-Sailjail]
|
||||||
Permissions=Internet;Downloads;Documents;Pictures
|
Permissions=Internet;Downloads;Documents;Pictures;UnifiedPush
|
||||||
OrganizationName=harbour
|
OrganizationName=harbour
|
||||||
ApplicationName=grumpydove
|
ApplicationName=grumpydove
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Name: harbour-grumpydove
|
Name: harbour-grumpydove
|
||||||
Summary: Eudora-style mail interface, mobile prototype
|
Summary: Eudora-style mail interface, mobile prototype
|
||||||
Version: 0.15.0
|
Version: 0.16.0
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: Qt/Qt
|
Group: Qt/Qt
|
||||||
# Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause
|
# Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause
|
||||||
@@ -27,6 +27,13 @@ Icons come from the original project's Eudora bitmaps (BSD 3-Clause,
|
|||||||
Computer History Museum).
|
Computer History Museum).
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat Nov 14 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.16.0-1
|
||||||
|
- Push UnifiedPush come nell'app della localizzazione: l'app possiede
|
||||||
|
org.unifiedpush.Connector.harbour-grumpydove, si registra col distributore
|
||||||
|
(FogHorn) e con un push si sveglia senza finestre, controlla la posta e
|
||||||
|
pubblica la notifica. Il risveglio si dirama per ambiente
|
||||||
|
(GRUMPYDOVE_PUSH_WAKE=1), perche' SailJail confronta la riga di comando coi
|
||||||
|
suoi template
|
||||||
* Sat Nov 14 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.15.0-1
|
* Sat Nov 14 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.15.0-1
|
||||||
- Bozze: "Salva bozza" scrive nella cartella Drafts (il motore con Queue=0 non
|
- Bozze: "Salva bozza" scrive nella cartella Drafts (il motore con Queue=0 non
|
||||||
la manda) e "Riprendi la bozza" riporta nel modulo destinatari, copie,
|
la manda) e "Riprendi la bozza" riporta nel modulo destinatari, copie,
|
||||||
@@ -288,11 +295,16 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/%{name}.desktop || tr
|
|||||||
# bogofilter per aarch64 (compilato con SQLite): al motore serve nel PATH per
|
# bogofilter per aarch64 (compilato con SQLite): al motore serve nel PATH per
|
||||||
# i filtri che imparano. Senza, il motore lo dice e i filtri restano spenti.
|
# i filtri che imparano. Senza, il motore lo dice e i filtri restano spenti.
|
||||||
install -D -m 0755 packaging/bin/bogofilter %{buildroot}%{_bindir}/bogofilter
|
install -D -m 0755 packaging/bin/bogofilter %{buildroot}%{_bindir}/bogofilter
|
||||||
|
# Attivazione D-Bus del connector UnifiedPush: è così che il push sveglia
|
||||||
|
# l'app anche da chiusa.
|
||||||
|
install -D -m 0644 rpm/org.unifiedpush.Connector.%{name}.service \
|
||||||
|
%{buildroot}%{_datadir}/dbus-1/services/org.unifiedpush.Connector.%{name}.service
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
%{_bindir}/bogofilter
|
%{_bindir}/bogofilter
|
||||||
|
%{_datadir}/dbus-1/services/org.unifiedpush.Connector.%{name}.service
|
||||||
%{_datadir}/applications/%{name}.desktop
|
%{_datadir}/applications/%{name}.desktop
|
||||||
%{_datadir}/icons/hicolor/86x86/apps/%{name}.png
|
%{_datadir}/icons/hicolor/86x86/apps/%{name}.png
|
||||||
%{_datadir}/icons/hicolor/108x108/apps/%{name}.png
|
%{_datadir}/icons/hicolor/108x108/apps/%{name}.png
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[D-BUS Service]
|
||||||
|
Name=org.unifiedpush.Connector.harbour-grumpydove
|
||||||
|
# Il risveglio si dirama per ambiente, non per argomento: SailJail confronta
|
||||||
|
# la riga di comando con i template del desktop file, e un argomento in più
|
||||||
|
# farebbe fallire l'attivazione ("Command line does not match templates").
|
||||||
|
Exec=/usr/bin/env GRUMPYDOVE_PUSH_WAKE=1 /usr/bin/sailjail -p harbour-grumpydove.desktop -- /usr/bin/harbour-grumpydove
|
||||||
+22
-32
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "enginebridge.h"
|
#include "enginebridge.h"
|
||||||
#include "accountsettings.h"
|
#include "accountsettings.h"
|
||||||
|
#include "pushservice.h"
|
||||||
|
|
||||||
// gd_engine_run: il main di GrumpyDove, esportato da libgrumpydove.so. Entra
|
// gd_engine_run: il main di GrumpyDove, esportato da libgrumpydove.so. Entra
|
||||||
// nel motore, che a sua volta chiama gd_run (enginecallbacks.cpp) e da lì il
|
// nel motore, che a sua volta chiama gd_run (enginecallbacks.cpp) e da lì il
|
||||||
@@ -20,44 +21,26 @@ extern "C" int gd_engine_run(void);
|
|||||||
|
|
||||||
Q_DECL_EXPORT int main(int argc, char *argv[])
|
Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
// Il risveglio da push si dirama PRIMA di creare la GUI: una push non deve
|
||||||
|
// poter aprire una finestra. Il desktop file passa questa variabile
|
||||||
|
// perché SailJail confronta la riga di comando coi suoi template e un
|
||||||
|
// argomento in più farebbe fallire l'attivazione.
|
||||||
|
if (qgetenv("GRUMPYDOVE_PUSH_WAKE") == QByteArrayLiteral("1"))
|
||||||
|
return risveglioPush(argc, argv);
|
||||||
|
|
||||||
QGuiApplication *app = SailfishApp::application(argc, argv);
|
QGuiApplication *app = SailfishApp::application(argc, argv);
|
||||||
|
|
||||||
app->setOrganizationName(QStringLiteral("harbour"));
|
app->setOrganizationName(QStringLiteral("harbour"));
|
||||||
app->setApplicationName(QStringLiteral("grumpydove"));
|
app->setApplicationName(QStringLiteral("grumpydove"));
|
||||||
app->setApplicationVersion(QStringLiteral("0.15.0"));
|
app->setApplicationVersion(QStringLiteral("0.16.0"));
|
||||||
|
|
||||||
qDebug() << "harbour-grumpydove v0.15.0 build" << __DATE__ << __TIME__;
|
qDebug() << "harbour-grumpydove v0.16.0 build" << __DATE__ << __TIME__;
|
||||||
|
|
||||||
// La sandbox di Sailfish (SailJail) non lascia vedere ~/Mail, ma il motore
|
// Maildir, log, rubrica e liste dei filtri nella cartella dati dell'app:
|
||||||
// legge il percorso del Maildir da GRUMPYDOVE_MAIL: si punta alla cartella
|
// la sandbox non lascia vedere ~/Mail né scrivere sotto HOME, e cambiare
|
||||||
// dati dell'app, che la sandbox rende visibile e persistente. NON si tocca
|
// HOME faceva perdere il tema del telefono.
|
||||||
// HOME: e' anche il posto dove Qt cerca la configurazione, e cambiarla
|
preparaPercorsiMotore();
|
||||||
// faceva perdere il tema del telefono (colori di default).
|
qDebug() << "Maildir del motore:" << qgetenv("GRUMPYDOVE_MAIL");
|
||||||
const QString mailDir = QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::AppDataLocation)
|
|
||||||
+ QStringLiteral("/Mail");
|
|
||||||
QDir().mkpath(mailDir);
|
|
||||||
qputenv("GRUMPYDOVE_MAIL", QFile::encodeName(mailDir));
|
|
||||||
// Anche il log del motore va dove la sandbox lascia scrivere, altrimenti
|
|
||||||
// non resta traccia di niente.
|
|
||||||
const QString logDir = QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::AppDataLocation)
|
|
||||||
+ QStringLiteral("/log");
|
|
||||||
QDir().mkpath(logDir);
|
|
||||||
qputenv("GRUMPYDOVE_LOG", QFile::encodeName(logDir));
|
|
||||||
// E i contatti della rubrica: anche quelli andrebbero sotto HOME.
|
|
||||||
const QString booksDir = QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::AppDataLocation)
|
|
||||||
+ QStringLiteral("/books");
|
|
||||||
QDir().mkpath(booksDir);
|
|
||||||
qputenv("GRUMPYDOVE_BOOKS", QFile::encodeName(booksDir));
|
|
||||||
// E le liste dei filtri che imparano.
|
|
||||||
const QString filingDir = QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::AppDataLocation)
|
|
||||||
+ QStringLiteral("/filing");
|
|
||||||
QDir().mkpath(filingDir);
|
|
||||||
qputenv("GRUMPYDOVE_FILING", QFile::encodeName(filingDir));
|
|
||||||
qDebug() << "Maildir del motore:" << mailDir;
|
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
if (translator.load(QLocale(), QStringLiteral("harbour-grumpydove"),
|
if (translator.load(QLocale(), QStringLiteral("harbour-grumpydove"),
|
||||||
@@ -70,9 +53,16 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||||||
AccountSettings account;
|
AccountSettings account;
|
||||||
bridge.setSettings(&account);
|
bridge.setSettings(&account);
|
||||||
|
|
||||||
|
// UnifiedPush: l'app possiede il nome del connector e si registra col
|
||||||
|
// distributore. Se FogHorn non c'è, lo dice nel log e la posta si
|
||||||
|
// controlla come prima.
|
||||||
|
PushService push;
|
||||||
|
push.start();
|
||||||
|
|
||||||
QQuickView *view = SailfishApp::createView();
|
QQuickView *view = SailfishApp::createView();
|
||||||
view->rootContext()->setContextProperty(QStringLiteral("engine"), &bridge);
|
view->rootContext()->setContextProperty(QStringLiteral("engine"), &bridge);
|
||||||
view->rootContext()->setContextProperty(QStringLiteral("account"), &account);
|
view->rootContext()->setContextProperty(QStringLiteral("account"), &account);
|
||||||
|
view->rootContext()->setContextProperty(QStringLiteral("pushService"), &push);
|
||||||
view->rootContext()->setContextProperty(QStringLiteral("appVersion"),
|
view->rootContext()->setContextProperty(QStringLiteral("appVersion"),
|
||||||
QCoreApplication::applicationVersion());
|
QCoreApplication::applicationVersion());
|
||||||
view->setSource(SailfishApp::pathTo(QStringLiteral("qml/harbour-grumpydove.qml")));
|
view->setSource(SailfishApp::pathTo(QStringLiteral("qml/harbour-grumpydove.qml")));
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
#include "pushservice.h"
|
||||||
|
#include "enginebridge.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
#include <QDBusPendingCall>
|
||||||
|
#include <QDBusPendingCallWatcher>
|
||||||
|
#include <QDBusPendingReply>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
extern "C" int gd_engine_run(void);
|
||||||
|
|
||||||
|
static const char *kServizio = "org.unifiedpush.Connector.harbour-grumpydove";
|
||||||
|
static const char *kOggetto = "/org/unifiedpush/Connector";
|
||||||
|
static const char *kDistributore = "org.unifiedpush.Distributor.Foghorn";
|
||||||
|
static const char *kPercorsoDistributore = "/org/unifiedpush/Distributor";
|
||||||
|
static const char *kInterfacciaDistributore = "org.unifiedpush.Distributor2";
|
||||||
|
|
||||||
|
PushService::PushService(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
QSettings s;
|
||||||
|
m_token = s.value(QStringLiteral("push/token")).toString();
|
||||||
|
m_endpoint = s.value(QStringLiteral("push/endpoint")).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PushService::start()
|
||||||
|
{
|
||||||
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||||
|
if (!bus.isConnected()) {
|
||||||
|
qWarning() << "push: nessun bus di sessione";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Il processo possiede il nome (non si registra): è così che il
|
||||||
|
// distributore sa a chi consegnare.
|
||||||
|
if (!bus.registerService(QString::fromLatin1(kServizio)))
|
||||||
|
qWarning() << "push: nome già posseduto da un altro processo";
|
||||||
|
bus.registerObject(QString::fromLatin1(kOggetto), this,
|
||||||
|
QDBusConnection::ExportAllSlots);
|
||||||
|
|
||||||
|
// Il token è l'identità verso il distributore e va scritto su disco prima
|
||||||
|
// della registrazione: NewEndpoint può arrivare prima che Register
|
||||||
|
// ritorni.
|
||||||
|
if (m_token.isEmpty()) {
|
||||||
|
m_token = QUuid::createUuid().toString();
|
||||||
|
m_token.remove(QLatin1Char('{'));
|
||||||
|
m_token.remove(QLatin1Char('}'));
|
||||||
|
QSettings s;
|
||||||
|
s.setValue(QStringLiteral("push/token"), m_token);
|
||||||
|
}
|
||||||
|
registra();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PushService::registra()
|
||||||
|
{
|
||||||
|
QDBusInterface distributore(QString::fromLatin1(kDistributore),
|
||||||
|
QString::fromLatin1(kPercorsoDistributore),
|
||||||
|
QString::fromLatin1(kInterfacciaDistributore),
|
||||||
|
QDBusConnection::sessionBus());
|
||||||
|
if (!distributore.isValid()) {
|
||||||
|
qWarning() << "push: distributore non disponibile (FogHorn assente?)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap args;
|
||||||
|
args[QStringLiteral("service")] = QString::fromLatin1(kServizio);
|
||||||
|
args[QStringLiteral("token")] = m_token;
|
||||||
|
args[QStringLiteral("description")] = QStringLiteral("GrumpyDove");
|
||||||
|
|
||||||
|
// Asincrono: la risposta può arrivare dopo NewEndpoint, e bloccarsi qui
|
||||||
|
// sarebbe un abbraccio mortale.
|
||||||
|
QDBusPendingCall call = distributore.asyncCallWithArgumentList(
|
||||||
|
QStringLiteral("Register"), { args });
|
||||||
|
auto *watcher = new QDBusPendingCallWatcher(call, this);
|
||||||
|
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
||||||
|
[this](QDBusPendingCallWatcher *w) {
|
||||||
|
QDBusPendingReply<QVariantMap> r = *w;
|
||||||
|
w->deleteLater();
|
||||||
|
if (r.isError()) {
|
||||||
|
qWarning() << "push: Register:" << r.error().message();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QVariantMap m = r.value();
|
||||||
|
qDebug() << "push: registrazione"
|
||||||
|
<< m.value(QStringLiteral("success")).toString()
|
||||||
|
<< m.value(QStringLiteral("reason")).toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap PushService::NewEndpoint(const QVariantMap &args)
|
||||||
|
{
|
||||||
|
const QString nuovo = args.value(QStringLiteral("endpoint")).toString();
|
||||||
|
if (!nuovo.isEmpty() && nuovo != m_endpoint) {
|
||||||
|
m_endpoint = nuovo;
|
||||||
|
QSettings s;
|
||||||
|
s.setValue(QStringLiteral("push/endpoint"), nuovo);
|
||||||
|
qDebug() << "push: endpoint ricevuto";
|
||||||
|
emit endpointChanged(nuovo);
|
||||||
|
}
|
||||||
|
QVariantMap r;
|
||||||
|
r[QStringLiteral("success")] = true;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap PushService::Message(const QVariantMap &args)
|
||||||
|
{
|
||||||
|
// Il push non porta dati: dice solo che c'è qualcosa da guardare (il
|
||||||
|
// servizio Mozilla rifiuta un corpo non cifrato, quindi questa catena
|
||||||
|
// funziona con ntfy/FogHorn).
|
||||||
|
emit pushReceived();
|
||||||
|
QVariantMap r;
|
||||||
|
r[QStringLiteral("id")] = args.value(QStringLiteral("id"));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap PushService::Unregistered(const QVariantMap &args)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args)
|
||||||
|
m_endpoint.clear();
|
||||||
|
QSettings s;
|
||||||
|
s.remove(QStringLiteral("push/endpoint"));
|
||||||
|
emit endpointChanged(QString());
|
||||||
|
QVariantMap r;
|
||||||
|
r[QStringLiteral("success")] = true;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void notificaSistema(const QString &titolo, const QString &testo)
|
||||||
|
{
|
||||||
|
QDBusInterface n(QStringLiteral("org.freedesktop.Notifications"),
|
||||||
|
QStringLiteral("/org/freedesktop/Notifications"),
|
||||||
|
QStringLiteral("org.freedesktop.Notifications"),
|
||||||
|
QDBusConnection::sessionBus());
|
||||||
|
if (!n.isValid()) {
|
||||||
|
qWarning() << "notifica: servizio non disponibile";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
n.call(QStringLiteral("Notify"),
|
||||||
|
QStringLiteral("harbour-grumpydove"),
|
||||||
|
0u,
|
||||||
|
QStringLiteral("harbour-grumpydove"),
|
||||||
|
titolo, testo,
|
||||||
|
QStringList(),
|
||||||
|
QVariantMap(),
|
||||||
|
8000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void preparaPercorsiMotore()
|
||||||
|
{
|
||||||
|
// Come in main(): la sandbox non lascia vedere ~/Mail né scrivere sotto
|
||||||
|
// HOME, quindi Maildir, log, rubrica e liste dei filtri stanno nella
|
||||||
|
// cartella dati dell'app. HOME non si tocca, o si perde il tema.
|
||||||
|
const QString dati = QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::AppDataLocation);
|
||||||
|
struct { const char *env; const char *sotto; } cartelle[] = {
|
||||||
|
{ "GRUMPYDOVE_MAIL", "/Mail" },
|
||||||
|
{ "GRUMPYDOVE_LOG", "/log" },
|
||||||
|
{ "GRUMPYDOVE_BOOKS", "/books" },
|
||||||
|
{ "GRUMPYDOVE_FILING", "/filing" },
|
||||||
|
};
|
||||||
|
for (const auto &c : cartelle) {
|
||||||
|
const QString percorso = dati + QString::fromLatin1(c.sotto);
|
||||||
|
QDir().mkpath(percorso);
|
||||||
|
qputenv(c.env, QFile::encodeName(percorso));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int risveglioPush(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
static int uno = 1;
|
||||||
|
QCoreApplication::setOrganizationName(QStringLiteral("harbour"));
|
||||||
|
QCoreApplication::setApplicationName(QStringLiteral("grumpydove"));
|
||||||
|
QCoreApplication app(uno, argv);
|
||||||
|
Q_UNUSED(argc)
|
||||||
|
|
||||||
|
preparaPercorsiMotore();
|
||||||
|
|
||||||
|
// Il motore entra in gd_engine_run e da lì nel suo ciclo: gira in un
|
||||||
|
// thread suo, mentre qui si aspetta l'esito.
|
||||||
|
EngineBridge bridge;
|
||||||
|
EngineBridge::setInstance(&bridge);
|
||||||
|
|
||||||
|
QThread *motore = QThread::create([] { gd_engine_run(); });
|
||||||
|
motore->start();
|
||||||
|
|
||||||
|
// Tetto di sicurezza: un risveglio non deve restare appeso.
|
||||||
|
QTimer::singleShot(60000, &app, [&app]() {
|
||||||
|
qWarning() << "push: tempo scaduto";
|
||||||
|
app.exit(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Si aspetta che il motore abbia letto le cartelle, poi si controlla.
|
||||||
|
QObject::connect(&bridge, &EngineBridge::ready, &app, [&app, &bridge]() {
|
||||||
|
static bool gia = false;
|
||||||
|
if (gia) return; // ready() arriva più volte
|
||||||
|
gia = true;
|
||||||
|
QObject::connect(&bridge, &EngineBridge::mailChecked, &app, [&app]() {
|
||||||
|
notificaSistema(QStringLiteral("Posta nuova"),
|
||||||
|
QStringLiteral("Tocca per leggere i messaggi"));
|
||||||
|
app.exit(0);
|
||||||
|
});
|
||||||
|
bridge.checkMail();
|
||||||
|
});
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#ifndef PUSHSERVICE_H
|
||||||
|
#define PUSHSERVICE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
// Connector UnifiedPush, come nelle altre app di casa: l'app possiede il nome
|
||||||
|
// org.unifiedpush.Connector.<app>, si registra col distributore (FogHorn) e
|
||||||
|
// riceve i push. Non tiene nessuna connessione verso il servizio push: quella
|
||||||
|
// è del distributore, una sola per tutte le app.
|
||||||
|
//
|
||||||
|
// I metodi D-Bus si chiamano con la maiuscola (NewEndpoint, Message), quindi
|
||||||
|
// devono stare in C++: in QML le funzioni non possono iniziare in maiuscolo.
|
||||||
|
class PushService : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.unifiedpush.Connector2")
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PushService(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
void start();
|
||||||
|
QString endpoint() const { return m_endpoint; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QVariantMap NewEndpoint(const QVariantMap &args);
|
||||||
|
QVariantMap Message(const QVariantMap &args);
|
||||||
|
QVariantMap Unregistered(const QVariantMap &args);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void endpointChanged(const QString &endpoint);
|
||||||
|
void pushReceived();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void registra();
|
||||||
|
QString m_token;
|
||||||
|
QString m_endpoint;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Una notifica di sistema che funziona anche senza GUI: nel risveglio non c'è
|
||||||
|
// nessuna finestra, quindi niente QML.
|
||||||
|
void notificaSistema(const QString &titolo, const QString &testo);
|
||||||
|
|
||||||
|
// I percorsi del motore nella cartella dati dell'app (Maildir, log, rubrica,
|
||||||
|
// liste dei filtri). Sta qui perché serve sia all'app sia al risveglio.
|
||||||
|
void preparaPercorsiMotore();
|
||||||
|
|
||||||
|
// Il risveglio da push: apre il motore senza finestre, controlla la posta,
|
||||||
|
// notifica e esce. Una push non deve poter aprire l'app.
|
||||||
|
int risveglioPush(int argc, char *argv[]);
|
||||||
|
|
||||||
|
#endif // PUSHSERVICE_H
|
||||||
Reference in new issue
Block a user