From 07b0e7ff8c19cc0c93f42441d7e22ef8819a4d2a Mon Sep 17 00:00:00 2001 From: Sacha Date: Fri, 26 Jun 2015 11:59:38 +1000 Subject: [PATCH] Add a new temporary log file and ability to read it while waiting for USB connection. Also make sure it is timestamped. --- qml/generic/USBConnect.qml | 7 +++++++ src/installer.cpp | 3 +++ src/installer.h | 6 ++++++ src/installer_qml.cpp | 20 ++++++++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/qml/generic/USBConnect.qml b/qml/generic/USBConnect.qml index 974561b..7344a60 100644 --- a/qml/generic/USBConnect.qml +++ b/qml/generic/USBConnect.qml @@ -84,8 +84,15 @@ Item { } Label { visible: i.possibleDevices + Layout.alignment: Qt.AlignHCenter text: qsTr("Talking to %1 possible device(s).").arg(i.possibleDevices) + translator.lang } + Button { + visible: i.hasLog + Layout.alignment: Qt.AlignHCenter + text: qsTr("Connection Log"); + onClicked: i.openLog(); + } } BusyIndicator { visible: !i.loginBlock diff --git a/src/installer.cpp b/src/installer.cpp index 683e135..5a5fa8b 100644 --- a/src/installer.cpp +++ b/src/installer.cpp @@ -43,6 +43,9 @@ InstallNet::InstallNet( QObject* parent) : QObject(parent), connect(&_back, SIGNAL(curSizeChanged()), this, SIGNAL(backCurProgressChanged())); connect(&_back, SIGNAL(numMethodsChanged()), this, SIGNAL(backMethodsChanged())); + logFile = new QTemporaryFile(); + logFile->open(); // This will autoclose and autoremove by default when ~InstallNet + QByteArray hashedPass = settings.value("pass", "").toByteArray(); if (hashedPass.isEmpty()) { diff --git a/src/installer.h b/src/installer.h index 964d3aa..5804d00 100644 --- a/src/installer.h +++ b/src/installer.h @@ -86,6 +86,7 @@ class InstallNet : public QObject { Q_PROPERTY(DeviceInfo* device MEMBER device NOTIFY deviceChanged) Q_PROPERTY(QQmlListProperty appList READ appList NOTIFY appListChanged) Q_PROPERTY(int appCount READ appCount NOTIFY appListChanged) + Q_PROPERTY(bool hasLog READ hasLog NOTIFY hasLogChanged) Q_PROPERTY(QString backStatus READ backStatus NOTIFY backStatusChanged) Q_PROPERTY(int backProgress READ backProgress NOTIFY backCurProgressChanged) @@ -93,6 +94,7 @@ class InstallNet : public QObject { Q_PROPERTY(int backMethods READ backMethods NOTIFY backMethodsChanged) Q_PROPERTY(QStringList backNames READ backNames NOTIFY backMethodsChanged) + Q_PROPERTY(QList backSizes READ backSizes NOTIFY backMethodsChanged) Q_PROPERTY(QQmlListProperty backAppList READ backAppList NOTIFY backMethodsChanged) public: @@ -115,6 +117,8 @@ class InstallNet : public QObject { Q_INVOKABLE void setActionProperty(QString name, QString value); Q_INVOKABLE void backupQuery(); Q_INVOKABLE void exportInstalled(); + Q_INVOKABLE void openLog(); + Q_INVOKABLE bool hasLog(); Q_INVOKABLE QString appDeltaMsg(); void requestConfigure(); void requestChallenge(); @@ -185,6 +189,7 @@ class InstallNet : public QObject { void appListChanged(); void backAppListChanged(); void deviceChanged(); + void hasLogChanged(); private slots: bool checkLogin(); void login(); @@ -225,6 +230,7 @@ private slots: SslNetworkAccessManager* manager; QNetworkReply *reply; QNetworkCookieJar* cookieJar; + QTemporaryFile* logFile; QFile* compressedFile; QStringList _firmwareNames; QStringList _firmwarePaths; diff --git a/src/installer_qml.cpp b/src/installer_qml.cpp index acf9022..e12c7b9 100644 --- a/src/installer_qml.cpp +++ b/src/installer_qml.cpp @@ -99,10 +99,26 @@ void InstallNet::setCompleted(const bool &exists) void InstallNet::setNewLine(const QString &newLine) { - _newLine = ""; // Otherwise it thinks it didn't change... + // Prefix with date + QString newLog = QTime().currentTime().toString("[hh:mm:ss] ") + newLine; + + _newLine = ""; // Reset qproperty and notify emit newLineChanged(); - _newLine = newLine + "
"; + _newLine = newLog + "
"; emit newLineChanged(); + newLog.append("\n"); + logFile->write(newLog.toLatin1()); + logFile->flush(); // Update file so it can be viewed in real-time + emit hasLogChanged(); +} + +bool InstallNet::hasLog() { + return logFile->fileName() != ""; +} + +void InstallNet::openLog() { + if (logFile->fileName() != "") + openFile(logFile->fileName()); } QString InstallNet::backStatus() const {