0.6.0 blocco 1: Home di consultazione e pagina Regolazioni
- Home: stato in una riga col pallino, due letture grandi toccabili, tre azioni rapide; via i due slider, i sette pulsanti e la scheda separata. - Nuova pagina Regolazioni: un blocco per grandezza, valore attuale sempre visibile, preimpostazioni per le dita fredde, conferma esplicita; il pulsante e' attivo solo se c'e' davvero qualcosa da cambiare. - Messaggi dei comandi spostati in ApiClient (api.notice) con NoticeBar ancorata in fondo: prima nascevano fuori dallo schermo. - Stato breve/esteso/livello in C++ (testabile senza SDK), 18 verifiche nuove: 79/79. - stale + lastUpdate: la Home dice 'aggiornato alle HH:MM' e spegne i numeri vecchi invece di farli passare per freschi. - 192/192 stringhe tradotte (54 nuove).
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
|
||||
@@ -12,7 +14,32 @@ ApiClient::ApiClient(Settings *settings, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(settings)
|
||||
, m_busy(false)
|
||||
, m_stale(false)
|
||||
, m_noticeIsError(false)
|
||||
, m_noticeTimer(0)
|
||||
{
|
||||
// Il messaggio dell'ultimo comando (o dell'ultimo errore) vale per ogni
|
||||
// pagina: lo stato sta qui, si spegne da solo e la UI lo mostra ancorato
|
||||
// in fondo alla schermata (NoticeBar), fuori dal contenuto che scorre.
|
||||
m_noticeTimer = new QTimer(this);
|
||||
m_noticeTimer->setSingleShot(true);
|
||||
m_noticeTimer->setInterval(7000);
|
||||
connect(m_noticeTimer, &QTimer::timeout, this, [this]() {
|
||||
if (m_notice.isEmpty())
|
||||
return;
|
||||
m_notice.clear();
|
||||
emit noticeChanged();
|
||||
});
|
||||
connect(this, &ApiClient::errorOccurred, this, [this](const QString &message) {
|
||||
setNotice(message, true);
|
||||
});
|
||||
connect(this, &ApiClient::commandFinished, this, [this](bool ok, const QString &message) {
|
||||
setNotice(message, !ok);
|
||||
});
|
||||
connect(this, &ApiClient::statsRefreshed, this, [this](bool ok, const QString &message) {
|
||||
setNotice(message, !ok);
|
||||
});
|
||||
|
||||
if (m_settings) {
|
||||
// La UI deve riflettere subito il passaggio da "non configurato" a
|
||||
// "configurato" quando si salvano indirizzo o token.
|
||||
@@ -29,6 +56,30 @@ bool ApiClient::configured() const
|
||||
&& !m_settings->token().trimmed().isEmpty();
|
||||
}
|
||||
|
||||
QString ApiClient::stateShort() const
|
||||
{
|
||||
return AiraJson::stateShort(m_summary);
|
||||
}
|
||||
|
||||
QString ApiClient::stateLong() const
|
||||
{
|
||||
return AiraJson::stateLong(m_summary);
|
||||
}
|
||||
|
||||
int ApiClient::statusLevel() const
|
||||
{
|
||||
return AiraJson::statusLevel(m_summary);
|
||||
}
|
||||
|
||||
void ApiClient::setNotice(const QString &message, bool isError)
|
||||
{
|
||||
m_notice = message;
|
||||
m_noticeIsError = isError;
|
||||
emit noticeChanged();
|
||||
if (!message.isEmpty())
|
||||
m_noticeTimer->start();
|
||||
}
|
||||
|
||||
void ApiClient::setBusy(bool value)
|
||||
{
|
||||
if (value == m_busy)
|
||||
@@ -102,6 +153,10 @@ void ApiClient::refresh()
|
||||
? tr("Server unreachable (timeout)")
|
||||
: AiraJson::errorMessage(body, status);
|
||||
qWarning() << "[api] summary non riuscito:" << status << msg;
|
||||
if (!m_stale) {
|
||||
m_stale = true;
|
||||
emit staleChanged();
|
||||
}
|
||||
emit errorOccurred(msg);
|
||||
return;
|
||||
}
|
||||
@@ -110,10 +165,22 @@ void ApiClient::refresh()
|
||||
const QVariantMap summary = AiraJson::parseSummary(body, &ok);
|
||||
if (!ok) {
|
||||
qWarning() << "[api] riassunto non interpretabile";
|
||||
if (!m_stale) {
|
||||
m_stale = true;
|
||||
emit staleChanged();
|
||||
}
|
||||
emit errorOccurred(tr("Unreadable response from the bridge"));
|
||||
return;
|
||||
}
|
||||
m_summary = summary;
|
||||
if (m_stale) {
|
||||
m_stale = false;
|
||||
emit staleChanged();
|
||||
}
|
||||
// Ora dell'ultimo aggiornamento riuscito: la Home la mostra, cosi' un
|
||||
// numero vecchio non passa per un numero fresco.
|
||||
m_lastUpdate = QLocale::system().toString(QTime::currentTime(), QLocale::ShortFormat);
|
||||
emit lastUpdateChanged();
|
||||
emit summaryChanged(summary);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user