diff --git a/src/Device.h b/src/Device.h index 4c6bd8525..5d8c05c9f 100644 --- a/src/Device.h +++ b/src/Device.h @@ -32,6 +32,7 @@ struct Device virtual bool download(CommPortPtr dev, const QDir &tmpdir, QString &tmpname, QString &filename, StatusCallback statusCallback, QString &err) = 0; + virtual void cleanup(CommPortPtr dev) { (void) dev; } static QList deviceTypes(); static Device &device(const QString &deviceType); diff --git a/src/DownloadRideDialog.cpp b/src/DownloadRideDialog.cpp index 67cb9669b..cfea6b2c4 100644 --- a/src/DownloadRideDialog.cpp +++ b/src/DownloadRideDialog.cpp @@ -195,6 +195,9 @@ DownloadRideDialog::downloadClicked() QMessageBox::information(this, tr("Success"), tr("Download complete.")); mainWindow->addRide(filename); + + device.cleanup(dev); + downloadInProgress = false; accept(); } diff --git a/src/SrmDevice.cpp b/src/SrmDevice.cpp index b05bb8460..8e43abd5f 100644 --- a/src/SrmDevice.cpp +++ b/src/SrmDevice.cpp @@ -19,6 +19,7 @@ #include "SrmDevice.h" #include "SrmRideFile.h" #include +#include #include #include #include @@ -57,6 +58,19 @@ get_tmpname(const QDir &tmpdir, QString &tmpname, QString &err) return true; } +static bool +dev2path(CommPortPtr dev, QString &path, QString &err) +{ + // Read device path out of device name. Sketchy. + QRegExp rx("^Serial: (.+)$"); + if (!rx.exactMatch(dev->name())) { + err = "SRM download not supported by device " + dev->name(); + return false; + } + path = rx.cap(1); + return true; +} + bool SrmDevice::download(CommPortPtr dev, const QDir &tmpdir, QString &tmpname, QString &filename, @@ -64,13 +78,9 @@ SrmDevice::download(CommPortPtr dev, const QDir &tmpdir, { // Totally ghetto, proof-of-concept integration with srmio. cb = statusCallback; - // Read device path out of device name. Sketchy. - QRegExp rx("^Serial: (.+)$"); - if (!rx.exactMatch(dev->name())) { - err = "SRM download not supported by device " + dev->name(); + QString path; + if (!dev2path(dev, path, err)) return false; - } - QString path = rx.cap(1); if (!get_tmpname(tmpdir, tmpname, err)) return false; srmpc_conn_t srm; @@ -108,3 +118,24 @@ SrmDevice::download(CommPortPtr dev, const QDir &tmpdir, return true; } +void +SrmDevice::cleanup(CommPortPtr dev) +{ + QString path, err; + if (!dev2path(dev, path, err)) + assert(false); + if (QMessageBox::question( + 0, "Powercontrol", + "Erase downloaded ride from device memory?", + "&Erase", "&Save Only", + QString(), 1, 1) == 0) { + srmpc_conn_t srm = srmpc_open(path.toAscii().constData(), 0, NULL); + if(srmpc_clear_chunks(srm) < 0) { + QMessageBox::warning( + 0, "Error", + "Error communicating with device."); + } + srmpc_close(srm); + } +} + diff --git a/src/SrmDevice.h b/src/SrmDevice.h index 2d4878742..c4c19f648 100644 --- a/src/SrmDevice.h +++ b/src/SrmDevice.h @@ -28,6 +28,7 @@ struct SrmDevice : public Device virtual bool download(CommPortPtr dev, const QDir &tmpdir, QString &tmpname, QString &filename, StatusCallback statusCallback, QString &err); + virtual void cleanup(CommPortPtr dev); }; #endif // _GC_SrmDevice_h