harbour-server 0.1.0: schermata parametri server (schema status/1)
Prima release dell'app Sailfish: schermata unica con CPU, memoria, disco, container, backup, servizi, SSH, aggiornamenti e VPN, letti da un endpoint read-only /v1/status. Soglie giallo/rosso, aggiornamento ogni 60 s, copertina, impostazioni con indirizzo e token.
This commit is contained in:
commit
24e1f3b376
20 files changed
+1112
No files matched your search
@@ -0,0 +1,70 @@
|
||||
#ifndef STATUSCLIENT_H
|
||||
#define STATUSCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QVariantMap>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class Settings;
|
||||
|
||||
// Scarica lo snapshot `status/1` dal collector e lo espone al QML.
|
||||
//
|
||||
// QNetworkAccessManager non applica timeout: una richiesta senza risposta
|
||||
// lascerebbe la UI in attesa per sempre, quindi c'e' un watchdog che aborta
|
||||
// dopo kTimeoutMs e riporta un errore visibile.
|
||||
class StatusClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariantMap data READ data NOTIFY changed)
|
||||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||||
Q_PROPERTY(QString error READ error NOTIFY errorChanged)
|
||||
Q_PROPERTY(QString fetchedAt READ fetchedAt NOTIFY changed)
|
||||
Q_PROPERTY(bool configured READ configured NOTIFY changed)
|
||||
|
||||
public:
|
||||
explicit StatusClient(Settings *settings, QObject *parent = nullptr);
|
||||
|
||||
QVariantMap data() const;
|
||||
bool busy() const;
|
||||
QString error() const;
|
||||
QString fetchedAt() const;
|
||||
bool configured() const;
|
||||
|
||||
Q_INVOKABLE void refresh();
|
||||
|
||||
// Formattazione lato C++: lo JS del QML di Qt 5.6 e' ES5 e le locale
|
||||
// numeriche italiane (virgola decimale) qui sono affidabili.
|
||||
Q_INVOKABLE QString fmtBytes(qint64 bytes) const;
|
||||
Q_INVOKABLE QString fmtUptime(qint64 seconds) const;
|
||||
Q_INVOKABLE QString fmtAge(double hours) const;
|
||||
Q_INVOKABLE QString fmtNum(double value, int decimals) const;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
void busyChanged();
|
||||
void errorChanged();
|
||||
|
||||
private slots:
|
||||
void onFinished();
|
||||
void onTimeout();
|
||||
|
||||
private:
|
||||
void setBusy(bool value);
|
||||
void setError(const QString &message);
|
||||
void clearReply();
|
||||
|
||||
Settings *m_settings;
|
||||
QNetworkAccessManager m_nam;
|
||||
QPointer<QNetworkReply> m_reply;
|
||||
QTimer m_watchdog;
|
||||
QVariantMap m_data;
|
||||
QString m_error;
|
||||
QString m_fetchedAt;
|
||||
bool m_busy;
|
||||
};
|
||||
|
||||
#endif // STATUSCLIENT_H
|
||||
Reference in new issue
Block a user