diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-10-29 12:48:12 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-10-29 12:48:12 +0100 |
commit | d749c1dc7186e87ffc4e729898ce8c6bc004c02c (patch) | |
tree | 5f53f30d79629fc10d1ea225c837136f93f74cb3 /src/shared | |
parent | 7fc6a0ecc873eb1f54ee60f22fdd010ebe0ea990 (diff) | |
download | qt-creator-d749c1dc7186e87ffc4e729898ce8c6bc004c02c.tar.gz |
S60: Provide a message box prompting to start TRK
... with cancel, similar to the Bluetooth connect box.
Reviewed-by: Robert Loehning <robert.loehning@nokia.com>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/trk/launcher.cpp | 61 | ||||
-rw-r--r-- | src/shared/trk/launcher.h | 14 |
2 files changed, 63 insertions, 12 deletions
diff --git a/src/shared/trk/launcher.cpp b/src/shared/trk/launcher.cpp index f066ab4864..a554269f0e 100644 --- a/src/shared/trk/launcher.cpp +++ b/src/shared/trk/launcher.cpp @@ -56,6 +56,7 @@ struct LauncherPrivate { TrkDevicePtr m_device; QString m_trkServerName; QByteArray m_trkReadBuffer; + Launcher::State m_state; void logMessage(const QString &msg); // Debuggee state @@ -66,14 +67,13 @@ struct LauncherPrivate { QString m_installFileName; int m_verbose; Launcher::Actions m_startupActions; - bool m_connected; bool m_closeDevice; }; LauncherPrivate::LauncherPrivate(const TrkDevicePtr &d) : m_device(d), + m_state(Launcher::Disconnected), m_verbose(0), - m_connected(false), m_closeDevice(true) { if (m_device.isNull()) @@ -97,6 +97,19 @@ Launcher::~Launcher() delete d; } +Launcher::State Launcher::state() const +{ + return d->m_state; +} + +void Launcher::setState(State s) +{ + if (s != d->m_state) { + d->m_state = s; + emit stateChanged(s); + } +} + void Launcher::addStartupActions(trk::Launcher::Actions startupActions) { d->m_startupActions = Actions(d->m_startupActions | startupActions); @@ -186,7 +199,9 @@ bool Launcher::startServer(QString *errorMessage) } else { disconnect(this, SIGNAL(finished()), d->m_device.data(), 0); } - + setState(Connecting); + // Set up the temporary 'waiting' state if we do not get immediate connection + QTimer::singleShot(200, this, SLOT(slotWaitingForTrk())); d->m_device->sendTrkInitialPing(); d->m_device->sendTrkMessage(TrkDisconnect); // Disconnect, as trk might be still connected d->m_device->sendTrkMessage(TrkSupported, TrkCallback(this, &Launcher::handleSupportMask)); @@ -197,13 +212,20 @@ bool Launcher::startServer(QString *errorMessage) return true; } +void Launcher::slotWaitingForTrk() +{ + // Set temporary state if we are still in connected state + if (state() == Connecting) + setState(WaitingForTrk); +} + void Launcher::handleConnect(const TrkResult &result) { if (result.errorCode()) { emit canNotConnect(result.errorString()); return; } - d->m_connected = true; + setState(Connected); if (d->m_startupActions & ActionCopy) copyFileToRemote(); else if (d->m_startupActions & ActionInstall) @@ -226,17 +248,27 @@ void Launcher::logMessage(const QString &msg) void Launcher::terminate() { - if (d->m_session.pid) { - QByteArray ba; - appendShort(&ba, 0x0000, TargetByteOrder); - appendInt(&ba, d->m_session.pid, TargetByteOrder); - d->m_device->sendTrkMessage(TrkDeleteItem, TrkCallback(this, &Launcher::handleRemoteProcessKilled), ba); - } else if (d->m_connected) { + switch (state()) { + case DeviceDescriptionReceived: + case Connected: + if (d->m_session.pid) { + QByteArray ba; + appendShort(&ba, 0x0000, TargetByteOrder); + appendInt(&ba, d->m_session.pid, TargetByteOrder); + d->m_device->sendTrkMessage(TrkDeleteItem, TrkCallback(this, &Launcher::handleRemoteProcessKilled), ba); + return; + } if (d->m_copyState.copyFileHandle) closeRemoteFile(true); disconnectTrk(); - } else { + break; + case Disconnected: + break; + case Connecting: + case WaitingForTrk: + setState(Disconnected); emit finished(); + break; } } @@ -364,17 +396,21 @@ QString Launcher::deviceDescription(unsigned verbose) const void Launcher::handleTrkVersion(const TrkResult &result) { if (result.errorCode() || result.data.size() < 5) { - if (d->m_startupActions == ActionPingOnly) + if (d->m_startupActions == ActionPingOnly) { + setState(Disconnected); emit finished(); + } return; } d->m_session.trkAppVersion.trkMajor = result.data.at(1); d->m_session.trkAppVersion.trkMinor = result.data.at(2); d->m_session.trkAppVersion.protocolMajor = result.data.at(3); d->m_session.trkAppVersion.protocolMinor = result.data.at(4); + setState(DeviceDescriptionReceived); // Ping mode: Log & Terminate if (d->m_startupActions == ActionPingOnly) { qWarning("%s", qPrintable(deviceDescription())); + setState(Disconnected); emit finished(); } } @@ -501,6 +537,7 @@ void Launcher::handleCreateProcess(const TrkResult &result) void Launcher::handleWaitForFinished(const TrkResult &result) { logMessage(" FINISHED: " + stringFromArray(result.data)); + setState(Disconnected); emit finished(); } diff --git a/src/shared/trk/launcher.h b/src/shared/trk/launcher.h index 2c4881de6d..538d367e74 100644 --- a/src/shared/trk/launcher.h +++ b/src/shared/trk/launcher.h @@ -61,10 +61,21 @@ public: ActionCopyInstallRun = ActionCopy | ActionInstall | ActionRun }; + enum State { Disconnected, Connecting, Connected, + WaitingForTrk, // This occurs only if the initial ping times out after + // a reasonable timeout, indicating that Trk is not + // running. Note that this will never happen with + // Bluetooth as communication immediately starts + // after connecting. + DeviceDescriptionReceived }; + explicit Launcher(trk::Launcher::Actions startupActions = trk::Launcher::ActionPingOnly, const TrkDevicePtr &trkDevice = TrkDevicePtr(), QObject *parent = 0); ~Launcher(); + + State state() const; + void addStartupActions(trk::Launcher::Actions startupActions); void setTrkServerName(const QString &name); QString trkServerName() const; @@ -98,12 +109,14 @@ signals: void finished(); void applicationOutputReceived(const QString &output); void copyProgress(int percent); + void stateChanged(int); public slots: void terminate(); private slots: void handleResult(const trk::TrkResult &data); + void slotWaitingForTrk(); private: // kill process and breakpoints @@ -130,6 +143,7 @@ private: void startInferiorIfNeeded(); void logMessage(const QString &msg); + void setState(State s); LauncherPrivate *d; }; |