Configurazione dell'account in app (0.3.0)
- src/accountsettings.*: server IMAP e SMTP, porta, sicurezza, utente, password, messaggi da tenere; QSettings nel percorso persistente della sandbox (AppConfigLocation), file leggibile solo dall'utente - bridge: checkMail passa la riga di Mail_Imap.Start al motore e ne segue Poll; a fine controllo rescan e ricarica delle cartelle - QML: SettingsPage nel menu Account, comando Scarica la posta, esito del controllo a schermo - nome della personalita sanificato: diventa la cartella sul telefono
This commit is contained in:
1 parent
b99a7ae41f
commit
48174a178d
10 files changed
+511
-10
No files matched your search
@@ -21,10 +21,12 @@ QMAKE_LFLAGS += -Wl,-rpath,/usr/share/harbour-grumpydove/lib
|
||||
SOURCES += \
|
||||
src/main.cpp \
|
||||
src/enginebridge.cpp \
|
||||
src/enginecallbacks.cpp
|
||||
src/enginecallbacks.cpp \
|
||||
src/accountsettings.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/enginebridge.h
|
||||
src/enginebridge.h \
|
||||
src/accountsettings.h
|
||||
|
||||
OTHER_FILES += \
|
||||
qml/harbour-grumpydove.qml \
|
||||
|
||||
@@ -60,15 +60,25 @@ Page {
|
||||
|
||||
header: PageHeader {
|
||||
title: qsTr("Cartelle")
|
||||
description: cartelle.count === 0 ? qsTr("In lettura...")
|
||||
description: !account.configured() ? qsTr("Account non configurato: menù qui sopra")
|
||||
: cartelle.count === 0 ? qsTr("Nessuna cartella")
|
||||
: qsTr("%1 non letti").arg(engine.totalUnread())
|
||||
}
|
||||
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
text: engine.checking ? qsTr("Controllo in corso…") : qsTr("Scarica la posta")
|
||||
enabled: !engine.checking
|
||||
onClicked: engine.checkMail()
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Rileggi le cartelle")
|
||||
onClicked: page.carica()
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Account")
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
||||
}
|
||||
MenuItem {
|
||||
text: qsTr("Nuovo messaggio")
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"))
|
||||
@@ -132,5 +142,32 @@ Page {
|
||||
}
|
||||
|
||||
VerticalScrollDecorator { }
|
||||
|
||||
// Esito del controllo della posta, dalle righe che il motore manda a
|
||||
// Poll ("! problema", "+ copiati", "* cartella creata").
|
||||
Connections {
|
||||
target: engine
|
||||
onMailChecked: {
|
||||
avviso.text = engine.lastResult;
|
||||
avvisoTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: avviso
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.Wrap
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
Timer {
|
||||
id: avvisoTimer
|
||||
interval: 4000
|
||||
onTriggered: avviso.text = ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
// Configurazione dell'account. Nel client originale queste voci stavano in
|
||||
// Tools > Personalities: qui sono i campi di un server IMAP e di uno SMTP,
|
||||
// salvati in ~/.config/harbour/grumpydove/grumpydove.conf.
|
||||
Page {
|
||||
id: page
|
||||
|
||||
SilicaFlickable {
|
||||
anchors.fill: parent
|
||||
contentHeight: colonna.height + Theme.paddingLarge
|
||||
|
||||
PageHeader {
|
||||
id: intestazione
|
||||
title: qsTr("Account")
|
||||
description: qsTr("Server di posta in arrivo e in partenza")
|
||||
}
|
||||
|
||||
Column {
|
||||
id: colonna
|
||||
anchors.top: intestazione.bottom
|
||||
width: parent.width
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Nome dell'account")
|
||||
placeholderText: qsTr("per esempio: casa")
|
||||
text: account.persona
|
||||
onTextChanged: account.persona = text
|
||||
}
|
||||
|
||||
SectionHeader { text: qsTr("Posta in arrivo (IMAP)") }
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Server")
|
||||
placeholderText: qsTr("imap.example.org")
|
||||
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
|
||||
text: account.imapHost
|
||||
onTextChanged: account.imapHost = text.trim()
|
||||
}
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Porta")
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
text: account.imapPort
|
||||
onTextChanged: {
|
||||
var n = parseInt(text);
|
||||
if (n > 0) account.imapPort = n;
|
||||
}
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Sicurezza")
|
||||
currentIndex: account.imapSecurity
|
||||
menu: ContextMenu {
|
||||
MenuItem { text: qsTr("Nessuna") }
|
||||
MenuItem { text: qsTr("STARTTLS") }
|
||||
MenuItem { text: qsTr("TLS") }
|
||||
}
|
||||
onCurrentIndexChanged: account.imapSecurity = currentIndex
|
||||
}
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Utente")
|
||||
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
||||
text: account.user
|
||||
onTextChanged: account.user = text
|
||||
}
|
||||
|
||||
PasswordField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Password")
|
||||
text: account.password
|
||||
showEchoModeToggle: true
|
||||
onTextChanged: account.password = text
|
||||
}
|
||||
|
||||
SectionHeader { text: qsTr("Posta in partenza (SMTP)") }
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Server")
|
||||
placeholderText: qsTr("smtp.example.org")
|
||||
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase
|
||||
text: account.smtpHost
|
||||
onTextChanged: account.smtpHost = text.trim()
|
||||
}
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Porta")
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
text: account.smtpPort
|
||||
onTextChanged: {
|
||||
var n = parseInt(text);
|
||||
if (n > 0) account.smtpPort = n;
|
||||
}
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Sicurezza")
|
||||
currentIndex: account.smtpSecurity
|
||||
menu: ContextMenu {
|
||||
MenuItem { text: qsTr("Nessuna") }
|
||||
MenuItem { text: qsTr("STARTTLS") }
|
||||
MenuItem { text: qsTr("TLS") }
|
||||
}
|
||||
onCurrentIndexChanged: account.smtpSecurity = currentIndex
|
||||
}
|
||||
|
||||
TextField {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
label: qsTr("Messaggi da tenere per cartella")
|
||||
description: qsTr("0 = tutti")
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
text: account.keep
|
||||
onTextChanged: {
|
||||
var n = parseInt(text);
|
||||
if (!isNaN(n)) account.keep = n;
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Salva")
|
||||
preferredWidth: Theme.buttonWidthSmall
|
||||
onClicked: page.salva()
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: account.configPath()
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator { }
|
||||
}
|
||||
|
||||
function salva() {
|
||||
account.save();
|
||||
avviso.text = qsTr("Account salvato");
|
||||
avvisoTimer.restart();
|
||||
}
|
||||
|
||||
Label {
|
||||
id: avviso
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Theme.paddingLarge
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
Timer {
|
||||
id: avvisoTimer
|
||||
interval: 1500
|
||||
onTriggered: avviso.text = ""
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
Name: harbour-grumpydove
|
||||
Summary: Eudora-style mail interface, mobile prototype
|
||||
Version: 0.2.0
|
||||
Version: 0.3.0
|
||||
Release: 1
|
||||
Group: Qt/Qt
|
||||
# Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause
|
||||
@@ -27,6 +27,12 @@ Icons come from the original project's Eudora bitmaps (BSD 3-Clause,
|
||||
Computer History Museum).
|
||||
|
||||
%changelog
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.3.0-1
|
||||
- Configurazione dell'account in app (menù > Account): server IMAP e SMTP,
|
||||
porta, sicurezza, utente, password, messaggi da tenere; salvata in
|
||||
~/.config/harbour/grumpydove/grumpydove.conf (zona persistente di SailJail)
|
||||
- "Scarica la posta" passa la configurazione al motore (formato di
|
||||
Mail_Imap.Start) e ne segue l'avanzamento; poi ricarica le cartelle
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.2.0-1
|
||||
- Il motore di GrumpyDove dentro l'app: libgrumpydove.so compilata per
|
||||
aarch64, collegata al bridge C++ (engine/), con le librerie che Sailfish
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "accountsettings.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
AccountSettings::AccountSettings(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_imapPort(993), m_imapSecurity(2),
|
||||
m_smtpPort(587), m_smtpSecurity(1), m_keep(500)
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
// Nella sandbox solo ~/.config/<org>/<app>/ persiste fra gli avvii.
|
||||
QString AccountSettings::path()
|
||||
{
|
||||
const QString dir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
QDir().mkpath(dir);
|
||||
return dir + QStringLiteral("/grumpydove.conf");
|
||||
}
|
||||
|
||||
void AccountSettings::load()
|
||||
{
|
||||
QSettings s(path(), QSettings::IniFormat);
|
||||
m_persona = s.value("account/persona").toString();
|
||||
m_imapHost = s.value("account/imap_host").toString();
|
||||
m_imapPort = s.value("account/imap_port", 993).toInt();
|
||||
m_imapSecurity = s.value("account/imap_security", 2).toInt();
|
||||
m_user = s.value("account/user").toString();
|
||||
m_password = s.value("account/password").toString();
|
||||
m_smtpHost = s.value("account/smtp_host").toString();
|
||||
m_smtpPort = s.value("account/smtp_port", 587).toInt();
|
||||
m_smtpSecurity = s.value("account/smtp_security", 1).toInt();
|
||||
m_smtpPassword = s.value("account/smtp_password").toString();
|
||||
m_keep = s.value("account/keep", 500).toInt();
|
||||
if (m_smtpPassword.isEmpty()) m_smtpPassword = m_password;
|
||||
}
|
||||
|
||||
void AccountSettings::save()
|
||||
{
|
||||
QSettings s(path(), QSettings::IniFormat);
|
||||
s.setValue("account/persona", m_persona);
|
||||
s.setValue("account/imap_host", m_imapHost);
|
||||
s.setValue("account/imap_port", m_imapPort);
|
||||
s.setValue("account/imap_security", m_imapSecurity);
|
||||
s.setValue("account/user", m_user);
|
||||
s.setValue("account/password", m_password);
|
||||
s.setValue("account/smtp_host", m_smtpHost);
|
||||
s.setValue("account/smtp_port", m_smtpPort);
|
||||
s.setValue("account/smtp_security", m_smtpSecurity);
|
||||
s.setValue("account/smtp_password", m_smtpPassword);
|
||||
s.setValue("account/keep", m_keep);
|
||||
s.sync();
|
||||
// contiene la password: leggibile solo dall'utente
|
||||
QFile::setPermissions(path(), QFile::ReadOwner | QFile::WriteOwner);
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void AccountSettings::setPersona(const QString &v) { if (m_persona != v) { m_persona = v; emit changed(); } }
|
||||
void AccountSettings::setImapHost(const QString &v) { if (m_imapHost != v) { m_imapHost = v; emit changed(); } }
|
||||
void AccountSettings::setImapPort(int v) { if (m_imapPort != v) { m_imapPort = v; emit changed(); } }
|
||||
void AccountSettings::setImapSecurity(int v) { if (m_imapSecurity != v) { m_imapSecurity = v; emit changed(); } }
|
||||
void AccountSettings::setUser(const QString &v) { if (m_user != v) { m_user = v; emit changed(); } }
|
||||
void AccountSettings::setPassword(const QString &v) { if (m_password != v) { m_password = v; emit changed(); } }
|
||||
void AccountSettings::setSmtpHost(const QString &v) { if (m_smtpHost != v) { m_smtpHost = v; emit changed(); } }
|
||||
void AccountSettings::setSmtpPort(int v) { if (m_smtpPort != v) { m_smtpPort = v; emit changed(); } }
|
||||
void AccountSettings::setSmtpSecurity(int v) { if (m_smtpSecurity != v) { m_smtpSecurity = v; emit changed(); } }
|
||||
void AccountSettings::setKeep(int v) { if (m_keep != v) { m_keep = v; emit changed(); } }
|
||||
|
||||
QString AccountSettings::imapLine() const
|
||||
{
|
||||
if (m_imapHost.isEmpty() || m_user.isEmpty()) return QString();
|
||||
// La personalità diventa il nome della cartella sul telefono
|
||||
// (<root>/<persona>/...): il motore rifiuta i nomi che non possono
|
||||
// esserlo, quindi si tengono solo lettere, cifre e pochi segni.
|
||||
QString nome = m_persona.isEmpty() ? m_user : m_persona;
|
||||
nome.replace(QRegularExpression(QStringLiteral("[^A-Za-z0-9._-]")),
|
||||
QStringLiteral("-"));
|
||||
return QString("%1\t%2\t%3\t%4\t%5\t%6\t%7")
|
||||
.arg(nome, m_imapHost, QString::number(m_imapPort),
|
||||
QString::number(m_imapSecurity), QString::number(m_keep),
|
||||
m_user, m_password);
|
||||
}
|
||||
|
||||
QString AccountSettings::smtpLine() const
|
||||
{
|
||||
if (m_smtpHost.isEmpty() || m_user.isEmpty()) return QString();
|
||||
return QString("%1\t%2\t%3\t%4\t%5")
|
||||
.arg(m_smtpHost, QString::number(m_smtpPort),
|
||||
QString::number(m_smtpSecurity), m_user, m_smtpPassword);
|
||||
}
|
||||
|
||||
bool AccountSettings::configured() const
|
||||
{
|
||||
return !m_imapHost.isEmpty() && !m_user.isEmpty();
|
||||
}
|
||||
|
||||
QString AccountSettings::configPath() const { return path(); }
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef ACCOUNTSETTINGS_H
|
||||
#define ACCOUNTSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
// Configurazione dell'account, nel posto che la sandbox SailJail rende
|
||||
// persistente: QStandardPaths::AppConfigLocation (~/.config/harbour/grumpydove).
|
||||
// Un QSettings costruito di default scriverebbe fuori e l'app dal launcher
|
||||
// ripartirebbe vuota (trappola nota su Sailfish 4.4+).
|
||||
class AccountSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString persona READ persona WRITE setPersona NOTIFY changed)
|
||||
Q_PROPERTY(QString imapHost READ imapHost WRITE setImapHost NOTIFY changed)
|
||||
Q_PROPERTY(int imapPort READ imapPort WRITE setImapPort NOTIFY changed)
|
||||
Q_PROPERTY(int imapSecurity READ imapSecurity WRITE setImapSecurity NOTIFY changed)
|
||||
Q_PROPERTY(QString user READ user WRITE setUser NOTIFY changed)
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY changed)
|
||||
Q_PROPERTY(QString smtpHost READ smtpHost WRITE setSmtpHost NOTIFY changed)
|
||||
Q_PROPERTY(int smtpPort READ smtpPort WRITE setSmtpPort NOTIFY changed)
|
||||
Q_PROPERTY(int smtpSecurity READ smtpSecurity WRITE setSmtpSecurity NOTIFY changed)
|
||||
Q_PROPERTY(int keep READ keep WRITE setKeep NOTIFY changed)
|
||||
|
||||
public:
|
||||
explicit AccountSettings(QObject *parent = nullptr);
|
||||
|
||||
QString persona() const { return m_persona; }
|
||||
QString imapHost() const { return m_imapHost; }
|
||||
int imapPort() const { return m_imapPort; }
|
||||
int imapSecurity() const { return m_imapSecurity; }
|
||||
QString user() const { return m_user; }
|
||||
QString password() const { return m_password; }
|
||||
QString smtpHost() const { return m_smtpHost; }
|
||||
int smtpPort() const { return m_smtpPort; }
|
||||
int smtpSecurity() const { return m_smtpSecurity; }
|
||||
int keep() const { return m_keep; }
|
||||
|
||||
void setPersona(const QString &v);
|
||||
void setImapHost(const QString &v);
|
||||
void setImapPort(int v);
|
||||
void setImapSecurity(int v);
|
||||
void setUser(const QString &v);
|
||||
void setPassword(const QString &v);
|
||||
void setSmtpHost(const QString &v);
|
||||
void setSmtpPort(int v);
|
||||
void setSmtpSecurity(int v);
|
||||
void setKeep(int v);
|
||||
|
||||
// "persona, host, porta, sicurezza, messaggi da tenere, utente, password"
|
||||
// come lo vuole Mail_Imap.Start: campi separati da tabulazioni.
|
||||
Q_INVOKABLE QString imapLine() const;
|
||||
Q_INVOKABLE QString smtpLine() const;
|
||||
Q_INVOKABLE bool configured() const;
|
||||
Q_INVOKABLE void save();
|
||||
Q_INVOKABLE QString configPath() const;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
static QString path();
|
||||
void load();
|
||||
|
||||
QString m_persona, m_imapHost, m_user, m_password;
|
||||
QString m_smtpHost, m_smtpPassword;
|
||||
int m_imapPort, m_imapSecurity, m_smtpPort, m_smtpSecurity, m_keep;
|
||||
};
|
||||
|
||||
#endif // ACCOUNTSETTINGS_H
|
||||
+76
-2
@@ -1,8 +1,10 @@
|
||||
#include "enginebridge.h"
|
||||
#include "accountsettings.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
EngineBridge *EngineBridge::s_instance = nullptr;
|
||||
@@ -15,11 +17,22 @@ gd_read_fn EngineBridge::s_read = nullptr;
|
||||
gd_id_of_fn EngineBridge::s_id_of = nullptr;
|
||||
gd_move_fn EngineBridge::s_move = nullptr;
|
||||
gd_commit_fn EngineBridge::s_commit = nullptr;
|
||||
gd_find_start_fn EngineBridge::s_imap_start = nullptr;
|
||||
gd_find_poll_fn EngineBridge::s_imap_poll = nullptr;
|
||||
gd_rescan_fn EngineBridge::s_rescan = nullptr;
|
||||
|
||||
// Colonne del motore (enum Column di qt_shim.cpp)
|
||||
enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk };
|
||||
|
||||
EngineBridge::EngineBridge(QObject *parent) : QObject(parent) {}
|
||||
EngineBridge::EngineBridge(QObject *parent)
|
||||
: QObject(parent), m_settings(nullptr), m_checking(false)
|
||||
{
|
||||
// Il controllo della posta gira in una task del motore: si interroga a
|
||||
// intervalli finché non ha finito.
|
||||
m_poll = new QTimer(this);
|
||||
m_poll->setInterval(250);
|
||||
connect(m_poll, &QTimer::timeout, this, &EngineBridge::pollMail);
|
||||
}
|
||||
|
||||
EngineBridge *EngineBridge::instance() { return s_instance; }
|
||||
void EngineBridge::setInstance(EngineBridge *b) { s_instance = b; }
|
||||
@@ -27,7 +40,9 @@ void EngineBridge::setInstance(EngineBridge *b) { s_instance = b; }
|
||||
void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
||||
gd_body_fn body, gd_can_hold_fn unread,
|
||||
gd_read_fn mark_read, gd_id_of_fn id_of,
|
||||
gd_move_fn move, gd_commit_fn commit)
|
||||
gd_move_fn move, gd_commit_fn commit,
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan)
|
||||
{
|
||||
s_folder = folder;
|
||||
s_open = open;
|
||||
@@ -38,11 +53,70 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
||||
s_id_of = id_of;
|
||||
s_move = move;
|
||||
s_commit = commit;
|
||||
s_imap_start = imap_start;
|
||||
s_imap_poll = imap_poll;
|
||||
s_rescan = rescan;
|
||||
if (s_instance) {
|
||||
emit s_instance->ready();
|
||||
}
|
||||
}
|
||||
|
||||
// "Scarica la posta": si passa al motore la riga dell'account (formato di
|
||||
// Mail_Imap.Start) e si segue Poll fino a che non ha finito.
|
||||
void EngineBridge::checkMail()
|
||||
{
|
||||
if (m_checking) return;
|
||||
if (!m_settings) return;
|
||||
const QString line = m_settings->imapLine();
|
||||
if (line.isEmpty()) {
|
||||
m_lastResult = tr("Configura l'account prima di scaricare la posta");
|
||||
emit mailChecked();
|
||||
return;
|
||||
}
|
||||
if (!s_imap_start || !s_imap_poll) {
|
||||
m_lastResult = tr("Il motore non e' pronto");
|
||||
emit mailChecked();
|
||||
return;
|
||||
}
|
||||
const QByteArray bytes = line.toUtf8();
|
||||
m_checking = true;
|
||||
emit checkingChanged();
|
||||
m_lastResult.clear();
|
||||
s_imap_start(bytes.constData(), bytes.size());
|
||||
m_poll->start();
|
||||
}
|
||||
|
||||
void EngineBridge::pollMail()
|
||||
{
|
||||
char buf[8192];
|
||||
int running = 1;
|
||||
const int n = s_imap_poll ? s_imap_poll(buf, int(sizeof buf) - 1, &running) : 0;
|
||||
|
||||
if (n > 0) {
|
||||
const QString text = QString::fromUtf8(buf, n);
|
||||
const QStringList lines = text.split('\n', QString::SkipEmptyParts);
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
const QString riga = lines.at(i);
|
||||
// "! testo" = problema; "+ persona cartella quanti" = copiati;
|
||||
// "* cartella" = cartella creata
|
||||
if (riga.startsWith(QLatin1String("!")))
|
||||
m_lastResult = riga.mid(2).trimmed();
|
||||
else if (riga.startsWith(QLatin1String("+")))
|
||||
m_lastResult = tr("Posta scaricata");
|
||||
}
|
||||
}
|
||||
|
||||
if (!running) {
|
||||
m_poll->stop();
|
||||
m_checking = false;
|
||||
if (m_lastResult.isEmpty()) m_lastResult = tr("Nessun messaggio nuovo");
|
||||
if (s_rescan) s_rescan(); // le cartelle possono essere nuove
|
||||
emit checkingChanged();
|
||||
emit ready(); // la QML ricarica
|
||||
emit mailChecked();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineBridge::markRead(int folder, int row, bool read)
|
||||
{
|
||||
if (!s_read) return;
|
||||
|
||||
+27
-1
@@ -6,6 +6,9 @@
|
||||
#include <QString>
|
||||
#include "qt_shim.h"
|
||||
|
||||
class AccountSettings;
|
||||
class QTimer;
|
||||
|
||||
// Ponte fra il motore di GrumpyDove e la QML.
|
||||
//
|
||||
// Il motore (libgrumpydove.so) chiama gd_run passando le sue callback: quelle
|
||||
@@ -14,17 +17,26 @@
|
||||
class EngineBridge : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool checking READ checking NOTIFY checkingChanged)
|
||||
Q_PROPERTY(QString lastResult READ lastResult NOTIFY mailChecked)
|
||||
|
||||
public:
|
||||
explicit EngineBridge(QObject *parent = nullptr);
|
||||
|
||||
static EngineBridge *instance();
|
||||
static void setInstance(EngineBridge *b);
|
||||
void setSettings(AccountSettings *s) { m_settings = s; }
|
||||
|
||||
// Chiamata da gd_run: conserva le callback e avvisa la QML.
|
||||
static void keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
||||
gd_body_fn body, gd_can_hold_fn unread,
|
||||
gd_read_fn mark_read, gd_id_of_fn id_of,
|
||||
gd_move_fn move, gd_commit_fn commit);
|
||||
gd_move_fn move, gd_commit_fn commit,
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan);
|
||||
|
||||
bool checking() const { return m_checking; }
|
||||
QString lastResult() const { return m_lastResult; }
|
||||
|
||||
Q_INVOKABLE QVariantList folders();
|
||||
Q_INVOKABLE QVariantList messages(int folder);
|
||||
@@ -33,9 +45,15 @@ public:
|
||||
Q_INVOKABLE int totalUnread();
|
||||
Q_INVOKABLE void markRead(int folder, int row, bool read);
|
||||
Q_INVOKABLE bool moveToTrash(int folder, int row);
|
||||
Q_INVOKABLE void checkMail();
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
void checkingChanged();
|
||||
void mailChecked();
|
||||
|
||||
private slots:
|
||||
void pollMail();
|
||||
|
||||
private:
|
||||
static EngineBridge *s_instance;
|
||||
@@ -48,6 +66,14 @@ private:
|
||||
static gd_id_of_fn s_id_of;
|
||||
static gd_move_fn s_move;
|
||||
static gd_commit_fn s_commit;
|
||||
static gd_find_start_fn s_imap_start;
|
||||
static gd_find_poll_fn s_imap_poll;
|
||||
static gd_rescan_fn s_rescan;
|
||||
|
||||
AccountSettings *m_settings;
|
||||
QTimer *m_poll;
|
||||
QString m_lastResult;
|
||||
bool m_checking;
|
||||
};
|
||||
|
||||
#endif // ENGINEBRIDGE_H
|
||||
@@ -58,7 +58,8 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
||||
(void)path;
|
||||
|
||||
EngineBridge::keepCallbacks(folder, open, cell, body, unread,
|
||||
mark_read, id_of, move, commit);
|
||||
mark_read, id_of, move, commit,
|
||||
imap_start, imap_poll, rescan);
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -7,6 +7,7 @@
|
||||
#include <sailfishapp.h>
|
||||
|
||||
#include "enginebridge.h"
|
||||
#include "accountsettings.h"
|
||||
|
||||
// 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
|
||||
@@ -20,9 +21,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
|
||||
app->setOrganizationName(QStringLiteral("harbour"));
|
||||
app->setApplicationName(QStringLiteral("grumpydove"));
|
||||
app->setApplicationVersion(QStringLiteral("0.2.0"));
|
||||
app->setApplicationVersion(QStringLiteral("0.3.0"));
|
||||
|
||||
qDebug() << "harbour-grumpydove v0.2.0 build" << __DATE__ << __TIME__;
|
||||
qDebug() << "harbour-grumpydove v0.3.0 build" << __DATE__ << __TIME__;
|
||||
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale(), QStringLiteral("harbour-grumpydove"),
|
||||
@@ -32,9 +33,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
|
||||
EngineBridge bridge;
|
||||
EngineBridge::setInstance(&bridge);
|
||||
AccountSettings account;
|
||||
bridge.setSettings(&account);
|
||||
|
||||
QQuickView *view = SailfishApp::createView();
|
||||
view->rootContext()->setContextProperty(QStringLiteral("engine"), &bridge);
|
||||
view->rootContext()->setContextProperty(QStringLiteral("account"), &account);
|
||||
view->rootContext()->setContextProperty(QStringLiteral("appVersion"),
|
||||
QCoreApplication::applicationVersion());
|
||||
view->setSource(SailfishApp::pathTo(QStringLiteral("qml/harbour-grumpydove.qml")));
|
||||
|
||||
Reference in new issue
Block a user