From 0d0a0f6557b27f99fd95cfd221784cd397a55ff3 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sat, 5 Jan 2019 19:54:30 +0000 Subject: [PATCH 1/2] Install openambit2gpx.py --- CMakeLists.txt | 1 + build.sh | 12 ++++++++++++ tools/CMakeLists.txt | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 tools/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7804409e..62bb9fdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(BUILD_EXTRAS "Build examples and wireshark dissector" OFF) add_subdirectory(src/libambit) add_subdirectory(src/movescount) add_subdirectory(src/openambit) +add_subdirectory(tools) if (NOT ${LIBAMBIT_FOUND}) add_dependencies(movescount ambit) diff --git a/build.sh b/build.sh index 6c5b047b..b6a99ccf 100755 --- a/build.sh +++ b/build.sh @@ -19,6 +19,18 @@ do fi done +for target in tools +do + if [ "$DO_INSTALL" == "1" ]; then + cd $SOURCE_LOCATION + mkdir -p $target-build + cd $target-build + cmake "$@" ../$target + echo "------installing $target------" + sudo make install + fi +done + if [ "$BUILD_EXTRAS" == "1" ]; then cd $SOURCE_LOCATION echo "------building example------" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 00000000..ea570799 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.5) + +install(PROGRAMS openambit2gpx.py DESTINATION bin) From 3a2bf2f8f7bda07190287bbda267e990e1cf3490 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sat, 5 Jan 2019 20:12:18 +0000 Subject: [PATCH 2/2] #181: Use openambit2gpx.py to convert selected log to a GPX file. Right click on a log and simply select "Write to GPX". GPX files are put in your ~/.openambit/GPX directory. --- README.rst | 6 +-- src/movescount/logstore.cpp | 7 +++ src/movescount/logstore.h | 5 ++- src/openambit/mainwindow.cpp | 84 ++++++++++++++++++++++++++++++++++++ src/openambit/mainwindow.h | 1 + 5 files changed, 99 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 4a3a3618..137a6120 100644 --- a/README.rst +++ b/README.rst @@ -141,9 +141,9 @@ Install Procedure ----------------- If you have built from source with ``build.sh``, you can install with -``install.sh``. This only installs the ``openambit`` application and -the ``libambit`` library it needs. When you have built only selected -parts, simply install them with: +``install.sh``. This installs the ``openambit`` application and the +``libambit`` library it needs and the ``openambit2gpx.py`` script. +When you have built only selected parts, simply install them with: .. code-block:: sh diff --git a/src/movescount/logstore.cpp b/src/movescount/logstore.cpp index d7425921..fce6d704 100644 --- a/src/movescount/logstore.cpp +++ b/src/movescount/logstore.cpp @@ -122,12 +122,19 @@ static sample_swimming_style_name_t sampleSwimmingStyleNames[] = { { 0, "" } }; +QString LogStore::storagePath; + LogStore::LogStore(QObject *parent) : QObject(parent) { storagePath = QString(getenv("HOME")) + "/.openambit"; } +QString LogStore::getStoragePath() +{ + return storagePath; +} + LogEntry *LogStore::store(const DeviceInfo& deviceInfo, ambit_personal_settings_t *personalSettings, ambit_log_entry_t *logEntry) { QDateTime dateTime(QDate(logEntry->header.date_time.year, logEntry->header.date_time.month, logEntry->header.date_time.day), diff --git a/src/movescount/logstore.h b/src/movescount/logstore.h index e9a09342..e7670db5 100644 --- a/src/movescount/logstore.h +++ b/src/movescount/logstore.h @@ -32,6 +32,7 @@ #include "deviceinfo.h" #include "logentry.h" +#include "logstore.h" class LogStore : public QObject { @@ -54,6 +55,8 @@ class LogStore : public QObject LogEntry *read(LogDirEntry dirEntry); LogEntry *read(QString filename); QList dir(QString device = ""); + static QString getStoragePath(); + signals: public slots: @@ -63,7 +66,7 @@ public slots: LogEntry *storeInternal(QString serial, QDateTime dateTime, const DeviceInfo& deviceInfo, ambit_personal_settings_t *personalSettings, ambit_log_entry_t *logEntry, QString movescountId = ""); LogEntry *readInternal(QString path); - QString storagePath; + static QString storagePath; class XMLReader { diff --git a/src/openambit/mainwindow.cpp b/src/openambit/mainwindow.cpp index 8b47e20d..0dab75a6 100644 --- a/src/openambit/mainwindow.cpp +++ b/src/openambit/mainwindow.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #define APPKEY "HpF9f1qV5qrDJ1hY1QK1diThyPsX10Mh4JvCw9xVQSglJNLdcwr3540zFyLzIC3e" #define MOVESCOUNT_DEFAULT_URL "https://uiservices.movescount.com/" @@ -422,6 +425,9 @@ void MainWindow::showContextMenuForLogItem(const QPoint &pos) QAction *action = new QAction(tr("Write Movescount file"), this); connect(action, SIGNAL(triggered()), this, SLOT(logItemWriteMovescount())); contextMenu.addAction(action); + QAction *action2 = new QAction(tr("Write GPX file"), this); + connect(action2, SIGNAL(triggered()), this, SLOT(logItemWriteGPX())); + contextMenu.addAction(action2); contextMenu.exec(mapToGlobal(pos)); } @@ -490,6 +496,84 @@ void MainWindow::startSync() emit MainWindow::syncNow(ui->checkBoxResyncAll->isChecked()); } +void MainWindow::logItemWriteGPX() +{ + const QString logfile = ui->logsList->selectedItems().at(0)->data(Qt::UserRole).toString(); + const QString program = "openambit2gpx.py"; + QStringList arguments; + const QString inLogfile = LogStore::getStoragePath() + "/" + logfile; + const QString dirStr = LogStore::getStoragePath() + "/GPX"; + QString outfile = dirStr + "/" + logfile; + + // Ensure directory exists + QDir dir(dirStr); + if (!dir.exists()) { + if ( !dir.mkpath(".") ) { + QMessageBox msgBox(QMessageBox::Critical, + QCoreApplication::applicationName(), + tr("Directory '%1' not available.").arg(dir.path()), + QMessageBox::Close, + this); + msgBox.exec(); + return; + }; + } + + outfile.replace(QRegExp("\\.log"), ".gpx"); + arguments << inLogfile << outfile; + + // Could run in the background and signal when complete or similar + // but that requires more complex code. + // The process shouldn't take too long... + // So for convience simply show it being busy for the moment + QApplication::setOverrideCursor(Qt::WaitCursor); + QApplication::processEvents(); + + //int result = QProcess::execute(program, arguments); + // Using this way allows capturing stdout & stderr + QProcess *myProcess = new QProcess(this); + myProcess->start(program, arguments); + bool finished = myProcess->waitForFinished(); + + QApplication::restoreOverrideCursor(); + QApplication::processEvents(); + + if ( finished ) { + const int result = myProcess->exitCode(); + + if ( result == 2 ) { + QMessageBox msgBox(QMessageBox::Critical, + QCoreApplication::applicationName(), + tr("Ensure openambit2gpx.py is installed."), + QMessageBox::Close, + this); + msgBox.exec(); + } + else if ( result != 0 ) { + // Capture any output should something have gone wrong and display it + QByteArray baOut = myProcess->readAllStandardOutput(); + QByteArray baErr = myProcess->readAllStandardError(); + + QTextCodec *codec = QTextCodec:: codecForLocale(); + QString output = codec->toUnicode(baOut) + "\n" + codec->toUnicode(baErr); + + QMessageBox msgBox(QMessageBox::Critical, + QCoreApplication::applicationName(), + tr("GPX conversion failed :( - reason %1\n%2").arg(result).arg(output), + QMessageBox::Close, + this); + msgBox.exec(); + } + } else { + QMessageBox msgBox(QMessageBox::Critical, + QCoreApplication::applicationName(), + tr("Conversion process timed out."), + QMessageBox::Close, + this); + msgBox.exec(); + } +} + void MainWindow::movesCountSetup() { bool syncOrbit = false; diff --git a/src/openambit/mainwindow.h b/src/openambit/mainwindow.h index 0ac9aa43..d152cb3f 100644 --- a/src/openambit/mainwindow.h +++ b/src/openambit/mainwindow.h @@ -82,6 +82,7 @@ private slots: void logItemSelected(QListWidgetItem *current,QListWidgetItem *previous); void showContextMenuForLogItem(const QPoint &pos); void logItemWriteMovescount(); + void logItemWriteGPX(); void updateLogList(); private: