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
@@ -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(); }
|
||||
Reference in new issue
Block a user