From af9bb2bfeaefd55a508e606ce3b937a50c17acc1 Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Wed, 26 Aug 2009 17:35:36 +0200 Subject: [PATCH] Show copy progress. --- .../qt-s60/s60devicerunconfiguration.cpp | 7 ++ .../qt-s60/s60devicerunconfiguration.h | 1 + tests/manual/trk/launcher.cpp | 73 +++++++++++++------ tests/manual/trk/launcher.h | 3 + 4 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp index 1bec3a67bee..318be09fc65 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp @@ -647,6 +647,7 @@ void S60DeviceRunControl::signsisProcessFinished() connect(m_launcher, SIGNAL(startingApplication()), this, SLOT(printStartingNotice())); connect(m_launcher, SIGNAL(applicationRunning(uint)), this, SLOT(printRunNotice(uint))); connect(m_launcher, SIGNAL(applicationOutputReceived(QString)), this, SLOT(printApplicationOutput(QString))); + connect(m_launcher, SIGNAL(copyProgress(int)), this, SLOT(printCopyProgress(int))); //TODO sisx destination and file path user definable m_launcher->setTrkServerName(m_serialPortName); @@ -670,6 +671,12 @@ void S60DeviceRunControl::signsisProcessFinished() void S60DeviceRunControl::printCopyingNotice() { emit addToOutputWindow(this, tr("Copying install file...")); + emit addToOutputWindow(this, tr("0% copied.")); +} + +void S60DeviceRunControl::printCopyProgress(int progress) +{ + emit addToOutputWindow(this, tr("%1% copied.").arg(progress)); } void S60DeviceRunControl::printInstallingNotice() diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h index a44db56ae8f..d05b7cc8d9f 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h @@ -160,6 +160,7 @@ private slots: void signsisProcessFailed(); void signsisProcessFinished(); void printCopyingNotice(); + void printCopyProgress(int progress); void printInstallingNotice(); void printStartingNotice(); void printRunNotice(uint pid); diff --git a/tests/manual/trk/launcher.cpp b/tests/manual/trk/launcher.cpp index 474b965a236..956a86fc952 100644 --- a/tests/manual/trk/launcher.cpp +++ b/tests/manual/trk/launcher.cpp @@ -43,6 +43,14 @@ namespace trk { typedef TrkWriteQueueDevice::Callback Callback; struct LauncherPrivate { + struct CopyState { + QString sourceFileName; + QString destinationFileName; + uint copyFileHandle; + QByteArray *data; + int position; + }; + LauncherPrivate(); TrkWriteQueueDevice m_device; QString m_trkServerName; @@ -52,9 +60,8 @@ struct LauncherPrivate { // Debuggee state Session m_session; // global-ish data (process id, target information) + CopyState m_copyState; QString m_fileName; - QString m_copySrcFileName; - QString m_copyDstFileName; QString m_installFileName; int m_verbose; }; @@ -88,8 +95,8 @@ void Launcher::setFileName(const QString &name) void Launcher::setCopyFileName(const QString &srcName, const QString &dstName) { - d->m_copySrcFileName = srcName; - d->m_copyDstFileName = dstName; + d->m_copyState.sourceFileName = srcName; + d->m_copyState.destinationFileName = dstName; } void Launcher::setInstallFileName(const QString &name) @@ -111,7 +118,7 @@ bool Launcher::startServer(QString *errorMessage) { if (d->m_verbose) { const QString msg = QString::fromLatin1("Port=%1 Executable=%2 Package=%3 Remote Package=%4 Install file=%5") - .arg(d->m_trkServerName, d->m_fileName, d->m_copySrcFileName, d->m_copyDstFileName, d->m_installFileName); + .arg(d->m_trkServerName, d->m_fileName, d->m_copyState.sourceFileName, d->m_copyState.destinationFileName, d->m_installFileName); logMessage(msg); } if (!d->m_device.open(d->m_trkServerName, errorMessage)) @@ -123,7 +130,7 @@ bool Launcher::startServer(QString *errorMessage) d->m_device.sendTrkMessage(TrkVersions, Callback(this, &Launcher::handleTrkVersion)); if (d->m_fileName.isEmpty()) return true; - if (!d->m_copySrcFileName.isEmpty() && !d->m_copyDstFileName.isEmpty()) + if (!d->m_copyState.sourceFileName.isEmpty() && !d->m_copyState.destinationFileName.isEmpty()) copyFileToRemote(); else installAndRun(); @@ -158,6 +165,7 @@ void Launcher::waitForTrkFinished(const TrkResult &result) void Launcher::terminate() { + //TODO handle case where application has not been started QByteArray ba; appendShort(&ba, 0x0000, TargetByteOrder); appendInt(&ba, d->m_session.pid, TargetByteOrder); @@ -296,25 +304,46 @@ void Launcher::handleFileCreation(const TrkResult &result) { // we don't do any error handling yet, which is bad const char *data = result.data.data(); - uint copyFileHandle = extractInt(data + 2); - QFile file(d->m_copySrcFileName); + d->m_copyState.copyFileHandle = extractInt(data + 2); + QFile file(d->m_copyState.sourceFileName); file.open(QIODevice::ReadOnly); - QByteArray src = file.readAll(); + d->m_copyState.data = new QByteArray(file.readAll()); + d->m_copyState.position = 0; file.close(); - const int BLOCKSIZE = 1024; - int size = src.length(); - int pos = 0; - while (pos < size) { + continueCopying(); +} + +void Launcher::handleCopy(const TrkResult &result) +{ + Q_UNUSED(result) + + continueCopying(); +} + +void Launcher::continueCopying() +{ + static const int BLOCKSIZE = 1024; + int size = d->m_copyState.data->length(); + if (size == 0) + emit copyProgress(100); + else { + int percent = qMin((d->m_copyState.position*100)/size, 100); + emit copyProgress(percent); + } + if (d->m_copyState.position < size) { QByteArray ba; - appendInt(&ba, copyFileHandle, TargetByteOrder); - appendString(&ba, src.mid(pos, BLOCKSIZE), TargetByteOrder, false); - d->m_device.sendTrkMessage(TrkWriteFile, Callback(), ba); - pos += BLOCKSIZE; + appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder); + appendString(&ba, d->m_copyState.data->mid(d->m_copyState.position, BLOCKSIZE), TargetByteOrder, false); + d->m_copyState.position += BLOCKSIZE; + d->m_device.sendTrkMessage(TrkWriteFile, Callback(this, &Launcher::handleCopy), ba); + } else { + QByteArray ba; + appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder); + appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder); + d->m_device.sendTrkMessage(TrkCloseFile, Callback(this, &Launcher::handleFileCreated), ba); + delete d->m_copyState.data; + d->m_copyState.data = 0; } - QByteArray ba; - appendInt(&ba, copyFileHandle, TargetByteOrder); - appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder); - d->m_device.sendTrkMessage(TrkCloseFile, Callback(this, &Launcher::handleFileCreated), ba); } void Launcher::handleFileCreated(const TrkResult &result) @@ -441,7 +470,7 @@ void Launcher::copyFileToRemote() emit copyingStarted(); QByteArray ba; appendByte(&ba, 0x10); - appendString(&ba, d->m_copyDstFileName.toLocal8Bit(), TargetByteOrder, false); + appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false); d->m_device.sendTrkMessage(TrkOpenFile, Callback(this, &Launcher::handleFileCreation), ba); } diff --git a/tests/manual/trk/launcher.h b/tests/manual/trk/launcher.h index cb9881b5511..7a2eccf1cb2 100644 --- a/tests/manual/trk/launcher.h +++ b/tests/manual/trk/launcher.h @@ -62,6 +62,7 @@ signals: void applicationRunning(uint pid); void finished(); void applicationOutputReceived(const QString &output); + void copyProgress(int percent); public slots: void terminate(); @@ -76,6 +77,8 @@ private: void cleanUp(); void handleFileCreation(const TrkResult &result); + void handleCopy(const TrkResult &result); + void continueCopying(); void handleFileCreated(const TrkResult &result); void handleInstallPackageFinished(const TrkResult &result); void handleCpuType(const TrkResult &result); -- GitLab