From 35ea49a99287291d0a74c0a17fef2e2cdd8a347e Mon Sep 17 00:00:00 2001 From: Carlo Baratto Date: Wed, 11 Nov 2026 17:42:00 +0100 Subject: [PATCH] Ricerca e rubrica CardDAV (0.9.0) - SearchPage: find_start/find_poll, risultati con mittente, oggetto e cartella; la riga nella cartella si ricava da id_named + row_of - ContactsPage: sincronizzazione del libro CardDAV e contatti che aprono la composizione; campi del libro in Account (indirizzo, utente, password) --- qml/pages/ContactsPage.qml | 113 ++++++++++++++++++ qml/pages/MailboxesPage.qml | 8 ++ qml/pages/SearchPage.qml | 146 +++++++++++++++++++++++ qml/pages/SettingsPage.qml | 31 +++++ rpm/harbour-grumpydove.spec | 9 +- src/accountsettings.cpp | 23 ++++ src/accountsettings.h | 15 +++ src/enginebridge.cpp | 227 +++++++++++++++++++++++++++++++++++- src/enginebridge.h | 48 +++++++- src/enginecallbacks.cpp | 6 +- src/main.cpp | 4 +- 11 files changed, 623 insertions(+), 7 deletions(-) create mode 100644 qml/pages/ContactsPage.qml create mode 100644 qml/pages/SearchPage.qml diff --git a/qml/pages/ContactsPage.qml b/qml/pages/ContactsPage.qml new file mode 100644 index 0000000..89f661c --- /dev/null +++ b/qml/pages/ContactsPage.qml @@ -0,0 +1,113 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +// Rubrica CardDAV. Il motore sincronizza il libro e tiene i contatti in +// locale; qui si leggono e, con un tocco, si scrive subito a qualcuno. +Page { + id: page + + property bool sincronizzando: false + property string errore: "" + + SilicaListView { + id: lista + anchors.fill: parent + model: contatti + currentIndex: -1 + + header: PageHeader { + title: qsTr("Rubrica") + description: page.sincronizzando ? qsTr("Sincronizzazione…") + : contatti.count > 0 ? qsTr("%1 contatti").arg(contatti.count) + : qsTr("Nessun contatto") + } + + PullDownMenu { + MenuItem { + text: page.sincronizzando ? qsTr("Sincronizzazione…") + : qsTr("Sincronizza") + enabled: !page.sincronizzando + onClicked: page.sincronizza() + } + MenuItem { + text: qsTr("Account") + onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml")) + } + } + + delegate: BackgroundItem { + id: riga + width: lista.width + height: Math.max(Theme.itemSizeMedium, testo.height + Theme.paddingLarge) + + onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"), + { destinatario: model.indirizzo }) + + Column { + id: testo + x: Theme.horizontalPageMargin + width: parent.width - 2 * Theme.horizontalPageMargin + anchors.verticalCenter: parent.verticalCenter + spacing: Theme.paddingSmall / 2 + + Label { + width: parent.width + text: model.nome.length > 0 ? model.nome : model.indirizzo + font.pixelSize: Theme.fontSizeSmall + color: Theme.primaryColor + truncationMode: TruncationMode.Fade + } + Label { + width: parent.width + text: model.indirizzo + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.secondaryColor + truncationMode: TruncationMode.Fade + } + } + } + + ViewPlaceholder { + enabled: contatti.count === 0 && !page.sincronizzando + text: page.errore.length > 0 ? page.errore + : qsTr("Sincronizza la rubrica dal menù") + hintText: page.errore.length > 0 ? qsTr("Controlla l'indirizzo del libro in Account") + : qsTr("I contatti del tuo libro CardDAV") + } + + VerticalScrollDecorator { } + } + + ListModel { id: contatti } + + Connections { + target: engine + onRubricaPronta: { + page.sincronizzando = false; + page.errore = errore; + page.riempi(); + } + } + + Component.onCompleted: page.riempi() + + function riempi() { + contatti.clear(); + var elenco = engine.contatti(); + for (var i = 0; i < elenco.length; i++) { + var c = elenco[i]; + contatti.append({ nome: c.nome, indirizzo: c.indirizzo, libro: c.libro }); + } + } + + function sincronizza() { + page.errore = ""; + var motivo = engine.sincronizzaRubrica(); + if (motivo.length > 0) { + page.errore = motivo; + page.sincronizzando = false; + return; + } + page.sincronizzando = true; + } +} diff --git a/qml/pages/MailboxesPage.qml b/qml/pages/MailboxesPage.qml index bddbc58..e0c6635 100644 --- a/qml/pages/MailboxesPage.qml +++ b/qml/pages/MailboxesPage.qml @@ -75,6 +75,14 @@ Page { text: qsTr("Rileggi le cartelle") onClicked: page.carica() } + MenuItem { + text: qsTr("Cerca") + onClicked: pageStack.push(Qt.resolvedUrl("SearchPage.qml")) + } + MenuItem { + text: qsTr("Rubrica") + onClicked: pageStack.push(Qt.resolvedUrl("ContactsPage.qml")) + } MenuItem { text: qsTr("Account") onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml")) diff --git a/qml/pages/SearchPage.qml b/qml/pages/SearchPage.qml new file mode 100644 index 0000000..d14a59e --- /dev/null +++ b/qml/pages/SearchPage.qml @@ -0,0 +1,146 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +// Ricerca nei messaggi. La ricerca la fa il motore in background (indice suo); +// qui c'e' il campo, lo stato e i risultati. Il risultato nomina il file, la +// posizione nella cartella la risolve il ponte. +Page { + id: page + + property string cercato: "" + property bool cercando: false + property string errore: "" + + SilicaFlickable { + anchors.fill: parent + contentHeight: colonna.height + Theme.paddingLarge + + PageHeader { + id: intestazione + title: qsTr("Cerca") + description: page.cercando ? qsTr("Ricerca in corso…") + : risultati.count > 0 ? qsTr("%1 risultati").arg(risultati.count) + : "" + } + + Column { + id: colonna + anchors.top: intestazione.bottom + width: parent.width + spacing: Theme.paddingMedium + + SearchField { + id: campo + width: parent.width + placeholderText: qsTr("parola o indirizzo") + EnterKey.enabled: true + EnterKey.iconSource: "image://theme/icon-m-search" + EnterKey.onClicked: page.cerca(text) + onTextChanged: if (text.length === 0) { risultati.clear(); page.errore = "" } + } + + Label { + x: Theme.horizontalPageMargin + width: parent.width - 2 * Theme.horizontalPageMargin + visible: page.errore.length > 0 + text: page.errore + color: Theme.highlightColor + font.pixelSize: Theme.fontSizeExtraSmall + wrapMode: Text.Wrap + } + + Repeater { + model: risultati + + BackgroundItem { + width: colonna.width + height: Math.max(Theme.itemSizeMedium, testo.height + Theme.paddingLarge) + onClicked: page.apri(model.cartella, model.riga) + + Column { + id: testo + x: Theme.horizontalPageMargin + width: parent.width - 2 * Theme.horizontalPageMargin + anchors.verticalCenter: parent.verticalCenter + spacing: Theme.paddingSmall / 2 + + Row { + width: parent.width + Label { + width: parent.width * 0.6 + text: model.mittente + font.pixelSize: Theme.fontSizeSmall + color: Theme.secondaryColor + truncationMode: TruncationMode.Fade + } + Label { + width: parent.width * 0.4 + horizontalAlignment: Text.AlignRight + text: model.dove + font.pixelSize: Theme.fontSizeExtraSmall + color: Theme.secondaryColor + truncationMode: TruncationMode.Fade + } + } + Label { + width: parent.width + text: model.oggetto + font.pixelSize: Theme.fontSizeSmall + color: Theme.primaryColor + truncationMode: TruncationMode.Fade + } + } + } + } + + Label { + x: Theme.horizontalPageMargin + width: parent.width - 2 * Theme.horizontalPageMargin + visible: !page.cercando && risultati.count === 0 && page.errore.length === 0 + && page.cercato.length > 0 + text: qsTr("Nessun messaggio trovato") + color: Theme.secondaryColor + font.pixelSize: Theme.fontSizeExtraSmall + } + } + } + + ListModel { id: risultati } + + Connections { + target: engine + onSearchFinished: { + page.cercando = false; + page.errore = errore; + risultati.clear(); + var elenco = engine.risultatiRicerca(); + for (var i = 0; i < elenco.length; i++) { + var r = elenco[i]; + if (r.riga < 0) continue; // il messaggio non e' piu' la' + risultati.append({ cartella: r.cartella, riga: r.riga, + mittente: r.mittente, oggetto: r.oggetto, + dove: r.dove, data: r.data }); + } + } + } + + function cerca(testo) { + if (testo.trim().length === 0) return; + page.cercato = testo.trim(); + page.errore = ""; + risultati.clear(); + var motivo = engine.avviaRicerca(page.cercato); + if (motivo.length > 0) { + page.errore = motivo; + page.cercando = false; + return; + } + page.cercando = true; + } + + function apri(cartella, riga) { + if (riga < 0) return; + pageStack.push(Qt.resolvedUrl("MessagePage.qml"), + { cartella: cartella, riga: riga }); + } +} diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index a2423c2..ef21da0 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -147,6 +147,37 @@ Page { } } + SectionHeader { text: qsTr("Rubrica (CardDAV)") } + + TextField { + width: parent.width - 2 * Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + label: qsTr("Indirizzo del libro") + placeholderText: qsTr("https://…/addressbooks/user/contacts/") + inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase + text: account.bookUrl + onTextChanged: account.bookUrl = text.trim() + } + + TextField { + width: parent.width - 2 * Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + label: qsTr("Utente del libro") + placeholderText: qsTr("vuoto = utente della posta") + text: account.bookUser + onTextChanged: account.bookUser = text.trim() + } + + TextField { + width: parent.width - 2 * Theme.horizontalPageMargin + anchors.horizontalCenter: parent.horizontalCenter + label: qsTr("Password del libro") + placeholderText: qsTr("vuota = password della posta") + echoMode: TextInput.Password + text: account.bookPassword + onTextChanged: account.bookPassword = text + } + Button { anchors.horizontalCenter: parent.horizontalCenter text: qsTr("Salva") diff --git a/rpm/harbour-grumpydove.spec b/rpm/harbour-grumpydove.spec index 49f388f..64e4ebb 100644 --- a/rpm/harbour-grumpydove.spec +++ b/rpm/harbour-grumpydove.spec @@ -1,6 +1,6 @@ Name: harbour-grumpydove Summary: Eudora-style mail interface, mobile prototype -Version: 0.8.0 +Version: 0.9.0 Release: 1 Group: Qt/Qt # 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). %changelog +* Wed Nov 11 2026 Carlo Baratto - 0.9.0-1 +- Ricerca nei messaggi: pagina Cerca nel menu delle cartelle, con i risultati + (mittente, oggetto, cartella) che aprono il messaggio. Usa find_start/ + find_poll del motore; la riga si ricava dall'id del file trovato +- Rubrica CardDAV: pagina Rubrica con sincronizzazione (book_start/book_poll/ + book_list) e contatti che aprono la composizione; indirizzo, utente e + password del libro in Account * Wed Nov 11 2026 Carlo Baratto - 0.8.0-1 - Svuotare il cestino cancella anche sul server: nuova operazione in sospeso (.delete) nel motore, \\Deleted sul solo UID e expunge con UIDPLUS quando diff --git a/src/accountsettings.cpp b/src/accountsettings.cpp index fbfcdd5..11b7bfd 100644 --- a/src/accountsettings.cpp +++ b/src/accountsettings.cpp @@ -37,6 +37,9 @@ void AccountSettings::load() 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(); + m_bookUrl = s.value("account/book_url").toString(); + m_bookUser = s.value("account/book_user").toString(); + m_bookPassword = s.value("account/book_password").toString(); if (m_smtpPassword.isEmpty()) m_smtpPassword = m_password; } @@ -55,6 +58,9 @@ void AccountSettings::save() s.setValue("account/smtp_security", m_smtpSecurity); s.setValue("account/smtp_password", m_smtpPassword); s.setValue("account/keep", m_keep); + s.setValue("account/book_url", m_bookUrl); + s.setValue("account/book_user", m_bookUser); + s.setValue("account/book_password", m_bookPassword); s.sync(); // contiene la password: leggibile solo dall'utente QFile::setPermissions(path(), QFile::ReadOwner | QFile::WriteOwner); @@ -72,6 +78,23 @@ void AccountSettings::setSmtpHost(const QString &v) { if (m_smtpHost != v) { m_s 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(); } } +void AccountSettings::setBookUrl(const QString &v) { if (m_bookUrl != v) { m_bookUrl = v; emit changed(); } } +void AccountSettings::setBookUser(const QString &v) { if (m_bookUser != v) { m_bookUser = v; emit changed(); } } +void AccountSettings::setBookPassword(const QString &v) { if (m_bookPassword != v) { m_bookPassword = v; emit changed(); } } + +// "Slibroindirizzoutentepassword": il +// motore sincronizza il libro e ne tiene i contatti in locale. +QString AccountSettings::bookLine() const +{ + if (m_bookUrl.isEmpty()) return QString(); + QString nome = m_persona.isEmpty() ? QStringLiteral("Rubrica") : m_persona; + nome.replace(QRegularExpression(QStringLiteral("[^A-Za-z0-9._-]")), + QStringLiteral("-")); + const QString utente = m_bookUser.isEmpty() ? m_user : m_bookUser; + const QString parola = m_bookPassword.isEmpty() ? m_password : m_bookPassword; + return QStringLiteral("S\t%1\t%2\t%3\t\t\t\t%4\n") + .arg(nome, m_bookUrl, utente, parola); +} QString AccountSettings::imapLine() const { diff --git a/src/accountsettings.h b/src/accountsettings.h index ac8d63c..d728db6 100644 --- a/src/accountsettings.h +++ b/src/accountsettings.h @@ -23,6 +23,10 @@ class AccountSettings : public QObject 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) + // Rubrica CardDAV: indirizzo del libro, utente e password (se diversa). + Q_PROPERTY(QString bookUrl READ bookUrl WRITE setBookUrl NOTIFY changed) + Q_PROPERTY(QString bookUser READ bookUser WRITE setBookUser NOTIFY changed) + Q_PROPERTY(QString bookPassword READ bookPassword WRITE setBookPassword NOTIFY changed) public: explicit AccountSettings(QObject *parent = nullptr); @@ -38,6 +42,9 @@ public: int smtpPort() const { return m_smtpPort; } int smtpSecurity() const { return m_smtpSecurity; } int keep() const { return m_keep; } + QString bookUrl() const { return m_bookUrl; } + QString bookUser() const { return m_bookUser; } + QString bookPassword() const { return m_bookPassword; } void setPersona(const QString &v); void setMittente(const QString &v); @@ -50,6 +57,13 @@ public: void setSmtpPort(int v); void setSmtpSecurity(int v); void setKeep(int v); + void setBookUrl(const QString &v); + void setBookUser(const QString &v); + void setBookPassword(const QString &v); + // La riga che il motore legge per sincronizzare il libro: operazione S, + // nome del libro, indirizzo, utente, poi resource/nome/indirizzo vuoti e + // la password in fondo (puo' contenere qualsiasi cosa). + QString bookLine() const; // "persona, host, porta, sicurezza, messaggi da tenere, utente, password" // come lo vuole Mail_Imap.Start: campi separati da tabulazioni. @@ -68,6 +82,7 @@ private: QString m_persona, m_mittente, m_imapHost, m_user, m_password; QString m_smtpHost, m_smtpPassword; + QString m_bookUrl, m_bookUser, m_bookPassword; int m_imapPort, m_imapSecurity, m_smtpPort, m_smtpSecurity, m_keep; }; diff --git a/src/enginebridge.cpp b/src/enginebridge.cpp index 87117ba..ca944b7 100644 --- a/src/enginebridge.cpp +++ b/src/enginebridge.cpp @@ -45,6 +45,14 @@ gd_log_fn EngineBridge::s_log = nullptr; gd_empty_fn EngineBridge::s_empty = nullptr; gd_text_fn EngineBridge::s_plain = nullptr; gd_text_fn EngineBridge::s_html = nullptr; +gd_find_start_fn EngineBridge::s_find_start = nullptr; +gd_find_poll_fn EngineBridge::s_find_poll = nullptr; +gd_find_cancel_fn EngineBridge::s_find_cancel = nullptr; +gd_id_named_fn EngineBridge::s_id_named = nullptr; +gd_row_of_fn EngineBridge::s_row_of = nullptr; +gd_find_start_fn EngineBridge::s_book_start = nullptr; +gd_find_poll_fn EngineBridge::s_book_poll = nullptr; +gd_place_fn EngineBridge::s_book_list = nullptr; // Colonne del motore (enum Column di qt_shim.cpp) enum Column { Status, Priority, Attachment, Label, Who, Date, Size, Subject, Junk }; @@ -77,7 +85,15 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f gd_send_done_fn send_done, gd_queue_sent_fn queue_sent, gd_place_fn place, gd_log_fn log, gd_empty_fn empty, - gd_text_fn plain, gd_text_fn html) + gd_text_fn plain, gd_text_fn html, + gd_find_start_fn find_start, + gd_find_poll_fn find_poll, + gd_find_cancel_fn find_cancel, + gd_id_named_fn id_named, + gd_row_of_fn row_of, + gd_find_start_fn book_start, + gd_find_poll_fn book_poll, + gd_place_fn book_list) { s_folder = folder; s_open = open; @@ -107,6 +123,14 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f s_empty = empty; s_plain = plain; s_html = html; + s_find_start = find_start; + s_find_poll = find_poll; + s_find_cancel = find_cancel; + s_id_named = id_named; + s_row_of = row_of; + s_book_start = book_start; + s_book_poll = book_poll; + s_book_list = book_list; if (s_instance) { emit s_instance->ready(); } @@ -476,6 +500,207 @@ int EngineBridge::emptyTrash(int folder) return rimossi; } +// Il nome di una cartella per indice, chiesto al motore. +QString EngineBridge::nomeCartella(int folder) +{ + if (!s_folder || folder < 0) return QString(); + char buf[512]; + int depth = 0; + const int n = s_folder(folder, &depth, buf, int(sizeof buf) - 1); + if (n < 0) return QString(); + return testoMotore(buf, qMin(n, int(sizeof buf) - 1)); +} + +// La ricerca: il motore lavora in background e riporta una riga per +// risultato ("+ "), "=" se il +// risultato e' stato tagliato, "!" per un problema. La query e' un foglio di +// campi separati da tab: cartelle, campo, confronto, testo, congiunzione, +// campo, confronto, testo, ricostruisci. +QString EngineBridge::avviaRicerca(const QString &testo) +{ + if (!s_find_start || !s_find_poll) + return tr("La ricerca del motore non è disponibile"); + const QString cercato = testo.trimmed(); + if (cercato.isEmpty()) + return tr("Scrivi qualcosa da cercare"); + + QStringList posti; + if (s_folder) { + char buf[512]; + int depth = 0; + for (int i = 0; i < 500; i++) { + const int n = s_folder(i, &depth, buf, int(sizeof buf) - 1); + if (n < 0) break; + posti << QString::number(i); + } + } + if (posti.isEmpty()) + return tr("Nessuna cartella dove cercare"); + + // Campo 0 = ovunque, confronto 0 = contiene; il secondo termine e' vuoto. + QString q = posti.join(QLatin1Char(',')); + q += QStringLiteral("\t0\t0\t"); + q += cercato; + q += QStringLiteral("\t0\t0\t0\t\t0"); // join, campo2, confronto2, "", rebuild + + m_hits.clear(); + m_findErrore.clear(); + const QByteArray bytes = q.toUtf8(); + s_find_start(bytes.constData(), bytes.size()); + + if (!m_findTimer) { + m_findTimer = new QTimer(this); + m_findTimer->setInterval(150); + connect(m_findTimer, &QTimer::timeout, this, &EngineBridge::pollRicerca); + } + m_findTimer->start(); + logInvio("find: avviata la ricerca di \"" + cercato + "\""); + return QString(); +} + +void EngineBridge::pollRicerca() +{ + if (!s_find_poll) { + if (m_findTimer) m_findTimer->stop(); + return; + } + QByteArray buffer(64 * 1024, '\0'); + int ancora = 0; + const int letti = s_find_poll(buffer.data(), buffer.size(), &ancora); + const QList righe = buffer.left(letti).split('\n'); + for (int i = 0; i < righe.size(); i++) { + const QByteArray riga = righe.at(i); + if (riga.isEmpty()) continue; + if (riga.at(0) == '!') { + m_findErrore = QString::fromUtf8(riga.mid(2)).trimmed(); + continue; + } + if (riga.at(0) != '+') continue; // "=" = risultati tagliati + const QList celle = riga.split('\t'); + if (celle.size() < 6) continue; + + SearchHit h; + h.cartella = celle.at(1).toInt(); + h.base = QString::fromUtf8(celle.at(2)); + h.mittente = QString::fromUtf8(celle.at(3)); + h.data = QString::fromUtf8(celle.at(4)); + h.oggetto = QString::fromUtf8(celle.at(5)); + h.dove = nomeCartella(h.cartella); + + // La ricerca nomina il file: la riga nella cartella si ricava dall'id. + h.riga = -1; + if (s_id_named && s_row_of) { + const QByteArray nome = h.base.toUtf8(); + const int id = s_id_named(h.cartella, nome.constData(), nome.size()); + if (id >= 0) h.riga = s_row_of(h.cartella, id); + } + m_hits.append(h); + } + if (ancora) return; + + m_findTimer->stop(); + logInvio(QString("find: %1 risultati").arg(m_hits.size())); + emit searchFinished(m_hits.size(), m_findErrore); +} + +QVariantList EngineBridge::risultatiRicerca() +{ + QVariantList out; + for (int i = 0; i < m_hits.size(); i++) { + const SearchHit &h = m_hits.at(i); + QVariantMap m; + m["cartella"] = h.cartella; + m["riga"] = h.riga; + m["dove"] = h.dove; + m["mittente"] = h.mittente; + m["data"] = h.data; + m["oggetto"] = h.oggetto; + out.append(m); + } + return out; +} + +void EngineBridge::fermaRicerca() +{ + if (s_find_cancel) s_find_cancel(); + if (m_findTimer) m_findTimer->stop(); +} + +// La rubrica: il motore sincronizza il libro CardDAV e ne tiene i contatti in +// locale; qui si avvia, si segue e si leggono. La riga di configurazione la +// compone AccountSettings::bookLine. +QString EngineBridge::sincronizzaRubrica() +{ + if (!s_book_start || !s_book_poll || !s_book_list) + return tr("La rubrica del motore non è disponibile"); + const QString riga = m_settings ? m_settings->bookLine() : QString(); + if (riga.isEmpty()) + return tr("Rubrica non configurata: indirizzo del libro, utente e password"); + + m_contatti.clear(); + m_bookErrore.clear(); + const QByteArray config = riga.toUtf8(); + s_book_start(config.constData(), config.size()); + + if (!m_bookTimer) { + m_bookTimer = new QTimer(this); + m_bookTimer->setInterval(250); + connect(m_bookTimer, &QTimer::timeout, this, &EngineBridge::pollRubrica); + } + m_bookTimer->start(); + logInvio("rubrica: avviata la sincronizzazione"); + return QString(); +} + +void EngineBridge::pollRubrica() +{ + QByteArray buffer(64 * 1024, '\0'); + int ancora = 0; + const int letti = s_book_poll ? s_book_poll(buffer.data(), buffer.size(), &ancora) : 0; + const QList righe = buffer.left(letti).split('\n'); + for (int i = 0; i < righe.size(); i++) { + const QByteArray riga = righe.at(i); + if (riga.isEmpty()) continue; + if (riga.at(0) == '!') + m_bookErrore = QString::fromUtf8(riga.mid(2)).trimmed(); + } + if (ancora) return; + + m_bookTimer->stop(); + + // I contatti come li ha il motore: libro, risorsa, nome, indirizzo. + QByteArray elenco(1 << 24, '\0'); + const int n = s_book_list ? s_book_list(0, elenco.data(), elenco.size()) : 0; + const QList contatti = elenco.left(n).split('\n'); + for (int i = 0; i < contatti.size(); i++) { + const QList celle = contatti.at(i).split('\t'); + if (celle.size() < 4) continue; + Contact c; + c.libro = QString::fromUtf8(celle.at(0)); + c.risorsa = QString::fromUtf8(celle.at(1)); + c.nome = QString::fromUtf8(celle.at(2)); + c.indirizzo = QString::fromUtf8(celle.at(3)); + m_contatti.append(c); + } + + logInvio(QString("rubrica: %1 contatti").arg(m_contatti.size())); + emit rubricaPronta(m_contatti.size(), m_bookErrore); +} + +QVariantList EngineBridge::contatti() +{ + QVariantList out; + for (int i = 0; i < m_contatti.size(); i++) { + const Contact &c = m_contatti.at(i); + QVariantMap m; + m["libro"] = c.libro; + m["nome"] = c.nome; + m["indirizzo"] = c.indirizzo; + out.append(m); + } + return out; +} + // Il giro dell'invio, come nell'originale: compose scrive il messaggio in Out // con il flag di coda, claim estrae quelli da mandare, send_start parla con il // server SMTP e send_poll riporta un messaggio per volta. diff --git a/src/enginebridge.h b/src/enginebridge.h index 51770c4..5f544b7 100644 --- a/src/enginebridge.h +++ b/src/enginebridge.h @@ -46,7 +46,15 @@ public: gd_send_done_fn send_done, gd_queue_sent_fn queue_sent, gd_place_fn place, gd_log_fn log, gd_empty_fn empty, - gd_text_fn plain, gd_text_fn html); + gd_text_fn plain, gd_text_fn html, + gd_find_start_fn find_start, + gd_find_poll_fn find_poll, + gd_find_cancel_fn find_cancel, + gd_id_named_fn id_named, + gd_row_of_fn row_of, + gd_find_start_fn book_start, + gd_find_poll_fn book_poll, + gd_place_fn book_list); bool checking() const { return m_checking; } QString lastResult() const { return m_lastResult; } @@ -71,6 +79,13 @@ public: Q_INVOKABLE int folderOut(); // Svuota il cestino indicato: quanti messaggi sono spariti, -1 se non c'e'. Q_INVOKABLE int emptyTrash(int folder); + // Ricerca: si avvia, si legge mentre lavora, e i risultati restano qui. + Q_INVOKABLE QString avviaRicerca(const QString &testo); + Q_INVOKABLE QVariantList risultatiRicerca(); + Q_INVOKABLE void fermaRicerca(); + // Rubrica CardDAV: sincronizza e restituisce i contatti. + Q_INVOKABLE QString sincronizzaRubrica(); + Q_INVOKABLE QVariantList contatti(); // Una riga dalla QML nel log del motore: serve a sapere se un tocco e' // arrivato, quando il resto non lascia traccia. Q_INVOKABLE void notaLog(const QString &riga) { logInvio("ui: " + riga); } @@ -81,6 +96,8 @@ public: signals: void ready(); + void searchFinished(int quanti, const QString &errore); + void rubricaPronta(int quanti, const QString &errore); void sendFinished(int inviati, int falliti, const QString &esito); void checkingChanged(); void mailChecked(); @@ -120,6 +137,33 @@ private: static gd_empty_fn s_empty; static gd_text_fn s_plain; static gd_text_fn s_html; + static gd_find_start_fn s_find_start; + static gd_find_poll_fn s_find_poll; + static gd_find_cancel_fn s_find_cancel; + static gd_id_named_fn s_id_named; + static gd_row_of_fn s_row_of; + static gd_find_start_fn s_book_start; + static gd_find_poll_fn s_book_poll; + static gd_place_fn s_book_list; + + struct Contact { + QString libro, nome, indirizzo, risorsa; + }; + QVector m_contatti; + QString m_bookErrore; + void pollRubrica(); + + // Un risultato di ricerca, con la riga gia' risolta: la ricerca da' il + // nome del file, non la posizione nella cartella. + struct SearchHit { + int cartella; + int riga; + QString mittente, data, oggetto, dove, base; + }; + QVector m_hits; + QString m_findErrore; + void pollRicerca(); + QString nomeCartella(int folder); // Un mio passaggio scritto nel log del motore: senza, quando l'invio si // ferma prima del motore non resta traccia di niente. void logInvio(const QString &riga); @@ -127,6 +171,8 @@ private: void pollSend(); QTimer *m_sendTimer = nullptr; + QTimer *m_findTimer = nullptr; + QTimer *m_bookTimer = nullptr; int m_sendFolder = -1; int m_sendOk = 0; int m_sendKo = 0; diff --git a/src/enginecallbacks.cpp b/src/enginecallbacks.cpp index 1b87978..1529bac 100644 --- a/src/enginecallbacks.cpp +++ b/src/enginecallbacks.cpp @@ -44,7 +44,7 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell, gd_text_fn images, gd_text_fn attachments, gd_text_fn path, gd_can_hold_fn unread) { - (void)sort; (void)mark_read; (void)id_of; (void)row_of; (void)move; + (void)sort; (void)mark_read; (void)move; (void)commit; (void)priority; (void)label; (void)decrypt; (void)key_of; (void)sheet; (void)filter; (void)last_id; (void)find_start; (void)find_poll; (void)find_cancel; (void)id_named; @@ -60,7 +60,9 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell, imap_start, imap_poll, rescan, attachments, sort, absorb, sender, header, compose, claim, send_start, send_poll, send_done, queue_sent, - place, log, empty, plain, html); + place, log, empty, plain, html, + find_start, find_poll, find_cancel, id_named, + row_of, book_start, book_poll, book_list); return QCoreApplication::exec(); } diff --git a/src/main.cpp b/src/main.cpp index eb25e0c..ac01500 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,9 +24,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) app->setOrganizationName(QStringLiteral("harbour")); app->setApplicationName(QStringLiteral("grumpydove")); - app->setApplicationVersion(QStringLiteral("0.8.0")); + app->setApplicationVersion(QStringLiteral("0.9.0")); - qDebug() << "harbour-grumpydove v0.8.0 build" << __DATE__ << __TIME__; + qDebug() << "harbour-grumpydove v0.9.0 build" << __DATE__ << __TIME__; // La sandbox di Sailfish (SailJail) non lascia vedere ~/Mail, ma il motore // legge il percorso del Maildir da GRUMPYDOVE_MAIL: si punta alla cartella