Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide "Export to GPX" from GUI #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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------"
Expand Down
7 changes: 7 additions & 0 deletions src/movescount/logstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion src/movescount/logstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "deviceinfo.h"
#include "logentry.h"
#include "logstore.h"

class LogStore : public QObject
{
Expand All @@ -54,6 +55,8 @@ class LogStore : public QObject
LogEntry *read(LogDirEntry dirEntry);
LogEntry *read(QString filename);
QList<LogDirEntry> dir(QString device = "");
static QString getStoragePath();

signals:

public slots:
Expand All @@ -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
{
Expand Down
84 changes: 84 additions & 0 deletions src/openambit/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <QListWidgetItem>
#include <QMessageBox>
#include <QDesktopServices>
#include <QProcess>
#include <QTextCodec>
#include <QDir>

#define APPKEY "HpF9f1qV5qrDJ1hY1QK1diThyPsX10Mh4JvCw9xVQSglJNLdcwr3540zFyLzIC3e"
#define MOVESCOUNT_DEFAULT_URL "https://uiservices.movescount.com/"
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/openambit/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private slots:
void logItemSelected(QListWidgetItem *current,QListWidgetItem *previous);
void showContextMenuForLogItem(const QPoint &pos);
void logItemWriteMovescount();
void logItemWriteGPX();
void updateLogList();

private:
Expand Down
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 2.8.5)

install(PROGRAMS openambit2gpx.py DESTINATION bin)