Skip to content

Commit

Permalink
Add a new temporary log file and ability to read it while waiting for…
Browse files Browse the repository at this point in the history
… USB connection. Also make sure it is timestamped.
  • Loading branch information
xsacha committed Jun 26, 2015
1 parent 312add4 commit 07b0e7f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions qml/generic/USBConnect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 6 additions & 0 deletions src/installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ class InstallNet : public QObject {
Q_PROPERTY(DeviceInfo* device MEMBER device NOTIFY deviceChanged)
Q_PROPERTY(QQmlListProperty<Apps> 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)
Q_PROPERTY(int backCurProgress READ backCurProgress NOTIFY backCurProgressChanged)

Q_PROPERTY(int backMethods READ backMethods NOTIFY backMethodsChanged)
Q_PROPERTY(QStringList backNames READ backNames NOTIFY backMethodsChanged)

Q_PROPERTY(QList<double> backSizes READ backSizes NOTIFY backMethodsChanged)
Q_PROPERTY(QQmlListProperty<Apps> backAppList READ backAppList NOTIFY backMethodsChanged)
public:
Expand All @@ -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();
Expand Down Expand Up @@ -185,6 +189,7 @@ class InstallNet : public QObject {
void appListChanged();
void backAppListChanged();
void deviceChanged();
void hasLogChanged();
private slots:
bool checkLogin();
void login();
Expand Down Expand Up @@ -225,6 +230,7 @@ private slots:
SslNetworkAccessManager* manager;
QNetworkReply *reply;
QNetworkCookieJar* cookieJar;
QTemporaryFile* logFile;
QFile* compressedFile;
QStringList _firmwareNames;
QStringList _firmwarePaths;
Expand Down
20 changes: 18 additions & 2 deletions src/installer_qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "<br>";
_newLine = newLog + "<br>";
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 {
Expand Down

0 comments on commit 07b0e7f

Please sign in to comment.