Allegati: elenco, salvataggio in Download e apertura (0.4.0)
- bridge: attachments() legge nome/lunghezza/byte come la vista originale e li tiene in cache; saveAttachment() scrive in Download con QSaveFile e scarta i percorsi nel nome scelto dal mittente - MessagePage: sezione con nome e dimensione, un tocco salva e apre - permesso SailJail Downloads nel desktop file
This commit is contained in:
1 parent
639bb9880d
commit
5e1f73774f
7 files changed
+171
-8
No files matched your search
@@ -18,6 +18,7 @@ Page {
|
||||
property string quando: ""
|
||||
property string indirizzo: ""
|
||||
property string corpo: ""
|
||||
property var allegati: []
|
||||
|
||||
Component.onCompleted: leggi()
|
||||
|
||||
@@ -33,9 +34,28 @@ Page {
|
||||
page.quando = engine.cell(page.cartella, page.riga, 5);
|
||||
page.oggetto = engine.cell(page.cartella, page.riga, 7);
|
||||
page.corpo = engine.body(page.cartella, page.riga);
|
||||
page.allegati = engine.attachments(page.cartella, page.riga);
|
||||
page.totale = engine.messages(page.cartella).length;
|
||||
}
|
||||
|
||||
function salvaAllegato(indice) {
|
||||
var path = engine.saveAttachment(page.cartella, page.riga, indice);
|
||||
if (path.length > 0) {
|
||||
avviso.text = qsTr("Salvato in %1").arg(path);
|
||||
avvisoTimer.restart();
|
||||
Qt.openUrlExternally("file://" + path);
|
||||
} else {
|
||||
avviso.text = qsTr("Non e' stato possibile salvare l'allegato");
|
||||
avvisoTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
function dimensione(bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
if (bytes < 1048576) return Math.round(bytes / 1024) + " KB";
|
||||
return (bytes / 1048576).toFixed(1) + " MB";
|
||||
}
|
||||
|
||||
function vai(delta) {
|
||||
var nuovo = page.riga + delta;
|
||||
if (nuovo < 0 || nuovo >= page.totale) {
|
||||
@@ -105,6 +125,51 @@ Page {
|
||||
color: Theme.primaryColor
|
||||
bottomPadding: Theme.paddingLarge
|
||||
}
|
||||
|
||||
// Allegati: un tocco li salva in Download e li apre con l'app
|
||||
// associata. I nomi li sceglie il mittente, quindi il bridge
|
||||
// scarta ogni percorso.
|
||||
SectionHeader {
|
||||
visible: page.allegati.length > 0
|
||||
text: page.allegati.length === 1 ? qsTr("1 allegato")
|
||||
: qsTr("%1 allegati").arg(page.allegati.length)
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: page.allegati
|
||||
|
||||
delegate: BackgroundItem {
|
||||
width: contenuto.width
|
||||
height: Theme.itemSizeSmall
|
||||
onClicked: page.salvaAllegato(modelData.indice)
|
||||
|
||||
Row {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
Image {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: Theme.iconSizeExtraSmall
|
||||
height: width
|
||||
source: "qrc:/images/icona-allegato.png"
|
||||
smooth: false
|
||||
}
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: modelData.nome
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.primaryColor
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: page.dimensione(modelData.dimensione)
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PullDownMenu {
|
||||
|
||||
@@ -9,7 +9,8 @@ Type=Application
|
||||
X-Nemo-Application-Type=silica-qt5
|
||||
Categories=Network;
|
||||
|
||||
# Internet = posta; Downloads = dove vanno gli allegati salvati.
|
||||
[X-Sailjail]
|
||||
Permissions=Internet
|
||||
Permissions=Internet;Downloads
|
||||
OrganizationName=harbour
|
||||
ApplicationName=grumpydove
|
||||
@@ -1,6 +1,6 @@
|
||||
Name: harbour-grumpydove
|
||||
Summary: Eudora-style mail interface, mobile prototype
|
||||
Version: 0.3.4
|
||||
Version: 0.4.0
|
||||
Release: 1
|
||||
Group: Qt/Qt
|
||||
# Codice EUPL-1.2; le icone vengono dagli sprite di Eudora, BSD 3-Clause
|
||||
@@ -27,6 +27,10 @@ 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.4.0-1
|
||||
- Allegati: elenco nella pagina del messaggio (nome e dimensione), un tocco
|
||||
li salva in Download e li apre con l'app associata; il nome del mittente
|
||||
viene ridotto al solo nome del file
|
||||
* Wed Nov 11 2026 Carlo Baratto <carlo@carlobaratto.it> - 0.3.4-1
|
||||
- Le cartelle standard del motore si chiamano INBOX, Sent, Junk, Trash: il
|
||||
bridge mappava In/Out e sbagliava le icone di posta in arrivo e inviata
|
||||
|
||||
+86
-2
@@ -2,6 +2,11 @@
|
||||
#include "accountsettings.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QSaveFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <QVector>
|
||||
@@ -21,12 +26,14 @@ 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;
|
||||
gd_text_fn EngineBridge::s_attachments = 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), m_settings(nullptr), m_checking(false)
|
||||
: QObject(parent), m_settings(nullptr), m_checking(false),
|
||||
m_attFolder(-1), m_attRow(-1)
|
||||
{
|
||||
// Il controllo della posta gira in una task del motore: si interroga a
|
||||
// intervalli finché non ha finito.
|
||||
@@ -43,7 +50,7 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
||||
gd_read_fn mark_read, gd_id_of_fn id_of,
|
||||
gd_move_fn move, gd_commit_fn commit,
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan)
|
||||
gd_rescan_fn rescan, gd_text_fn attachments)
|
||||
{
|
||||
s_folder = folder;
|
||||
s_open = open;
|
||||
@@ -57,6 +64,7 @@ void EngineBridge::keepCallbacks(gd_folder_fn folder, gd_open_fn open, gd_cell_f
|
||||
s_imap_start = imap_start;
|
||||
s_imap_poll = imap_poll;
|
||||
s_rescan = rescan;
|
||||
s_attachments = attachments;
|
||||
if (s_instance) {
|
||||
emit s_instance->ready();
|
||||
}
|
||||
@@ -270,6 +278,82 @@ QString EngineBridge::body(int folder, int row)
|
||||
return QString::fromUtf8(buf, n);
|
||||
}
|
||||
|
||||
// Gli allegati del messaggio, come li dà il motore: per ognuno nome (UTF-8),
|
||||
// NUL, la lunghezza, NUL, i byte. Si leggono una volta sola e si tengono,
|
||||
// perché ogni chiamata li ricostruisce da capo (fino a 80 MB).
|
||||
QVariantList EngineBridge::attachments(int folder, int row)
|
||||
{
|
||||
QVariantList out;
|
||||
if (!s_attachments || !s_id_of) return out;
|
||||
const int id = s_id_of(folder, row);
|
||||
if (id < 0) return out;
|
||||
|
||||
QByteArray blob(80 << 20, Qt::Uninitialized);
|
||||
const int n = s_attachments(folder, id, blob.data(), blob.size());
|
||||
if (n <= 0) return out;
|
||||
blob.truncate(n);
|
||||
|
||||
m_attBytes.clear();
|
||||
m_attNames.clear();
|
||||
m_attFolder = folder;
|
||||
m_attRow = row;
|
||||
|
||||
int at = 0;
|
||||
while (at < blob.size()) {
|
||||
const int a = blob.indexOf('\0', at);
|
||||
if (a < 0) break;
|
||||
const int b = blob.indexOf('\0', a + 1);
|
||||
if (b < 0) break;
|
||||
bool ok = false;
|
||||
const int length = blob.mid(a + 1, b - a - 1).toInt(&ok);
|
||||
if (!ok || length < 0 || b + 1 + length > blob.size()) break;
|
||||
|
||||
const QString nome = QString::fromUtf8(blob.mid(at, a - at));
|
||||
const QByteArray bytes = blob.mid(b + 1, length);
|
||||
m_attNames.append(nome);
|
||||
m_attBytes.append(bytes);
|
||||
|
||||
QVariantMap m;
|
||||
m["nome"] = nome;
|
||||
m["dimensione"] = bytes.size();
|
||||
m["indice"] = out.size();
|
||||
out.append(m);
|
||||
at = b + 1 + length;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Salva un allegato in Download e restituisce il percorso ("" se non riesce).
|
||||
QString EngineBridge::saveAttachment(int folder, int row, int index)
|
||||
{
|
||||
if (folder != m_attFolder || row != m_attRow)
|
||||
attachments(folder, row);
|
||||
if (index < 0 || index >= m_attBytes.size()) return QString();
|
||||
|
||||
QString dir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
if (dir.isEmpty()) dir = QDir::homePath() + QStringLiteral("/Downloads");
|
||||
QDir().mkpath(dir);
|
||||
|
||||
// il nome arriva dal mittente: si tiene solo l'ultimo pezzo, senza percorsi
|
||||
QString nome = QFileInfo(m_attNames.at(index)).fileName();
|
||||
if (nome.isEmpty()) nome = QStringLiteral("allegato-%1").arg(index + 1);
|
||||
QString path = dir + "/" + nome;
|
||||
const QFileInfo fi(nome);
|
||||
for (int k = 1; QFile::exists(path) && k < 1000; k++) {
|
||||
path = fi.suffix().isEmpty()
|
||||
? QString("%1/%2 (%3)").arg(dir, nome, QString::number(k))
|
||||
: QString("%1/%2 (%3).%4").arg(dir, fi.completeBaseName(),
|
||||
QString::number(k), fi.suffix());
|
||||
}
|
||||
|
||||
QSaveFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly)) return QString();
|
||||
const QByteArray &bytes = m_attBytes.at(index);
|
||||
if (f.write(bytes) != bytes.size()) { f.cancelWriting(); return QString(); }
|
||||
if (!f.commit()) return QString();
|
||||
return path;
|
||||
}
|
||||
|
||||
int EngineBridge::totalUnread()
|
||||
{
|
||||
if (!s_folder || !s_unread) return 0;
|
||||
|
||||
+10
-1
@@ -33,7 +33,7 @@ public:
|
||||
gd_read_fn mark_read, gd_id_of_fn id_of,
|
||||
gd_move_fn move, gd_commit_fn commit,
|
||||
gd_find_start_fn imap_start, gd_find_poll_fn imap_poll,
|
||||
gd_rescan_fn rescan);
|
||||
gd_rescan_fn rescan, gd_text_fn attachments);
|
||||
|
||||
bool checking() const { return m_checking; }
|
||||
QString lastResult() const { return m_lastResult; }
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
Q_INVOKABLE void markRead(int folder, int row, bool read);
|
||||
Q_INVOKABLE bool moveToTrash(int folder, int row);
|
||||
Q_INVOKABLE void checkMail();
|
||||
Q_INVOKABLE QVariantList attachments(int folder, int row);
|
||||
Q_INVOKABLE QString saveAttachment(int folder, int row, int index);
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
@@ -69,11 +71,18 @@ private:
|
||||
static gd_find_start_fn s_imap_start;
|
||||
static gd_find_poll_fn s_imap_poll;
|
||||
static gd_rescan_fn s_rescan;
|
||||
static gd_text_fn s_attachments;
|
||||
|
||||
AccountSettings *m_settings;
|
||||
QTimer *m_poll;
|
||||
QString m_lastResult;
|
||||
bool m_checking;
|
||||
// Gli allegati dell'ultimo messaggio aperto: letti una volta sola, perché
|
||||
// il motore li ricostruisce da capo a ogni chiamata.
|
||||
QList<QByteArray> m_attBytes;
|
||||
QStringList m_attNames;
|
||||
int m_attFolder;
|
||||
int m_attRow;
|
||||
};
|
||||
|
||||
#endif // ENGINEBRIDGE_H
|
||||
@@ -59,7 +59,7 @@ int gd_run(gd_folder_fn folder, gd_open_fn open, gd_cell_fn cell,
|
||||
|
||||
EngineBridge::keepCallbacks(folder, open, cell, body, unread,
|
||||
mark_read, id_of, move, commit,
|
||||
imap_start, imap_poll, rescan);
|
||||
imap_start, imap_poll, rescan, attachments);
|
||||
return QCoreApplication::exec();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -21,9 +21,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
|
||||
app->setOrganizationName(QStringLiteral("harbour"));
|
||||
app->setApplicationName(QStringLiteral("grumpydove"));
|
||||
app->setApplicationVersion(QStringLiteral("0.3.4"));
|
||||
app->setApplicationVersion(QStringLiteral("0.4.0"));
|
||||
|
||||
qDebug() << "harbour-grumpydove v0.3.4 build" << __DATE__ << __TIME__;
|
||||
qDebug() << "harbour-grumpydove v0.4.0 build" << __DATE__ << __TIME__;
|
||||
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale(), QStringLiteral("harbour-grumpydove"),
|
||||
|
||||
Reference in new issue
Block a user