mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Enable libdivecomputer log or dump from the UI
Pick filenames for these functions as they are selected. Use the windows-safe fopen function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4de739b935
commit
d42cc5a40c
6 changed files with 113 additions and 31 deletions
|
@ -9,7 +9,6 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
#include "libdivecomputer/version.h"
|
|
||||||
|
|
||||||
/* Christ. Libdivecomputer has the worst configuration system ever. */
|
/* Christ. Libdivecomputer has the worst configuration system ever. */
|
||||||
#ifdef HW_FROG_H
|
#ifdef HW_FROG_H
|
||||||
|
@ -19,6 +18,8 @@
|
||||||
#define NOT_FROG
|
#define NOT_FROG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *dumpfile_name;
|
||||||
|
char *logfile_name;
|
||||||
const char *progress_bar_text = "";
|
const char *progress_bar_text = "";
|
||||||
double progress_bar_fraction = 0.0;
|
double progress_bar_fraction = 0.0;
|
||||||
|
|
||||||
|
@ -657,7 +658,6 @@ static const char *do_device_import(device_data_t *data)
|
||||||
{
|
{
|
||||||
dc_status_t rc;
|
dc_status_t rc;
|
||||||
dc_device_t *device = data->device;
|
dc_device_t *device = data->device;
|
||||||
int dump = 0; /* TODO: Enable memory dump from the UI somehow. */
|
|
||||||
|
|
||||||
data->model = str_printf("%s %s", data->vendor, data->product);
|
data->model = str_printf("%s %s", data->vendor, data->product);
|
||||||
|
|
||||||
|
@ -672,13 +672,12 @@ static const char *do_device_import(device_data_t *data)
|
||||||
if (rc != DC_STATUS_SUCCESS)
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
return translate("gettextFromC","Error registering the cancellation handler.");
|
return translate("gettextFromC","Error registering the cancellation handler.");
|
||||||
|
|
||||||
if (dump) {
|
if (data->libdc_dump) {
|
||||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||||
|
|
||||||
rc = dc_device_dump (device, buffer);
|
rc = dc_device_dump (device, buffer);
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
if (rc == DC_STATUS_SUCCESS) {
|
||||||
/* TODO: Should the filename (and directory) be configurable? */
|
FILE* fp = subsurface_fopen(dumpfile_name, "wb");
|
||||||
FILE* fp = fopen ("subsurface.bin", "wb");
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp);
|
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
@ -722,9 +721,8 @@ const char *do_libdivecomputer_import(device_data_t *data)
|
||||||
data->device = NULL;
|
data->device = NULL;
|
||||||
data->context = NULL;
|
data->context = NULL;
|
||||||
|
|
||||||
/* TODO: Enable logging from the UI somehow. */
|
if (data->libdc_log)
|
||||||
/* TODO: Should the filename (and directory) be configurable? */
|
fp = subsurface_fopen(logfile_name, "w");
|
||||||
fp = fopen("subsurface.log", "w");
|
|
||||||
|
|
||||||
rc = dc_context_new(&data->context);
|
rc = dc_context_new(&data->context);
|
||||||
if (rc != DC_STATUS_SUCCESS)
|
if (rc != DC_STATUS_SUCCESS)
|
||||||
|
|
|
@ -24,6 +24,8 @@ typedef struct device_data_t {
|
||||||
dc_context_t *context;
|
dc_context_t *context;
|
||||||
int preexisting;
|
int preexisting;
|
||||||
bool force_download;
|
bool force_download;
|
||||||
|
bool libdc_log;
|
||||||
|
bool libdc_dump;
|
||||||
} device_data_t;
|
} device_data_t;
|
||||||
|
|
||||||
const char *do_libdivecomputer_import(device_data_t *data);
|
const char *do_libdivecomputer_import(device_data_t *data);
|
||||||
|
@ -32,6 +34,8 @@ const char *do_uemis_import(const char *mountpath, short force_download);
|
||||||
extern int import_thread_cancelled;
|
extern int import_thread_cancelled;
|
||||||
extern const char *progress_bar_text;
|
extern const char *progress_bar_text;
|
||||||
extern double progress_bar_fraction;
|
extern double progress_bar_fraction;
|
||||||
|
extern char *logfile_name;
|
||||||
|
extern char *dumpfile_name;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
struct product {
|
struct product {
|
||||||
|
@ -43,7 +44,7 @@ DownloadFromDCWidget *DownloadFromDCWidget::instance()
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
||||||
QDialog(parent, f), thread(0), timer(new QTimer(this)),
|
QDialog(parent, f), thread(0), timer(new QTimer(this)),
|
||||||
currentState(INITIAL)
|
currentState(INITIAL)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
@ -54,6 +55,12 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
||||||
fill_device_list();
|
fill_device_list();
|
||||||
fill_computer_list();
|
fill_computer_list();
|
||||||
|
|
||||||
|
ui.chooseDumpFile->setEnabled(ui.dumpToFile->isChecked());
|
||||||
|
connect(ui.chooseDumpFile, SIGNAL(clicked()), this, SLOT(pickDumpFile()));
|
||||||
|
connect(ui.dumpToFile, SIGNAL(stateChanged(int)), this, SLOT(checkDumpFile(int)));
|
||||||
|
ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
|
||||||
|
connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile()));
|
||||||
|
connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int)));
|
||||||
vendorModel = new QStringListModel(vendorList);
|
vendorModel = new QStringListModel(vendorList);
|
||||||
ui.vendor->setModel(vendorModel);
|
ui.vendor->setModel(vendorModel);
|
||||||
if (default_dive_computer_vendor) {
|
if (default_dive_computer_vendor) {
|
||||||
|
@ -248,6 +255,46 @@ bool DownloadFromDCWidget::preferDownloaded()
|
||||||
return ui.preferDownloaded->isChecked();
|
return ui.preferDownloaded->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::checkLogFile(int state)
|
||||||
|
{
|
||||||
|
ui.chooseLogFile->setEnabled(state == Qt::Checked);
|
||||||
|
data.libdc_log = (state == Qt::Checked);
|
||||||
|
if (state == Qt::Checked && logFile.isEmpty()) {
|
||||||
|
pickLogFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::pickLogFile()
|
||||||
|
{
|
||||||
|
QString filename = existing_filename ? : prefs.default_filename;
|
||||||
|
QFileInfo fi(filename);
|
||||||
|
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
|
||||||
|
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer download logfile"),
|
||||||
|
filename, tr("Log files (*.log)"));
|
||||||
|
if (!logFile.isEmpty())
|
||||||
|
logfile_name = strdup(logFile.toUtf8().data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::checkDumpFile(int state)
|
||||||
|
{
|
||||||
|
ui.chooseDumpFile->setEnabled(state == Qt::Checked);
|
||||||
|
data.libdc_dump = (state == Qt::Checked);
|
||||||
|
if (state == Qt::Checked && dumpFile.isEmpty()) {
|
||||||
|
pickDumpFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::pickDumpFile()
|
||||||
|
{
|
||||||
|
QString filename = existing_filename ? : prefs.default_filename;
|
||||||
|
QFileInfo fi(filename);
|
||||||
|
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.bin");
|
||||||
|
dumpFile = QFileDialog::getSaveFileName(this, tr("Choose file for divecomputer binary dump file"),
|
||||||
|
filename, tr("Dump files (*.bin)"));
|
||||||
|
if (!dumpFile.isEmpty())
|
||||||
|
dumpfile_name = strdup(dumpFile.toUtf8().data());
|
||||||
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::reject()
|
void DownloadFromDCWidget::reject()
|
||||||
{
|
{
|
||||||
// we don't want the download window being able to close
|
// we don't want the download window being able to close
|
||||||
|
|
|
@ -44,6 +44,10 @@ public slots:
|
||||||
void onDownloadThreadFinished();
|
void onDownloadThreadFinished();
|
||||||
void updateProgressBar();
|
void updateProgressBar();
|
||||||
void runDialog();
|
void runDialog();
|
||||||
|
void checkLogFile(int state);
|
||||||
|
void checkDumpFile(int state);
|
||||||
|
void pickDumpFile();
|
||||||
|
void pickLogFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void markChildrenAsDisabled();
|
void markChildrenAsDisabled();
|
||||||
|
@ -63,7 +67,8 @@ private:
|
||||||
QStringListModel *productModel;
|
QStringListModel *productModel;
|
||||||
void fill_computer_list();
|
void fill_computer_list();
|
||||||
void fill_device_list();
|
void fill_device_list();
|
||||||
|
QString logFile;
|
||||||
|
QString dumpFile;
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>331</width>
|
<width>331</width>
|
||||||
<height>241</height>
|
<height>314</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -19,6 +19,20 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="2" column="0" colspan="3">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Device or Mount Point</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QComboBox" name="device">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -39,20 +53,6 @@
|
||||||
<item row="1" column="1" colspan="2">
|
<item row="1" column="1" colspan="2">
|
||||||
<widget class="QComboBox" name="product"/>
|
<widget class="QComboBox" name="product"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="3">
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Device or Mount Point</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" colspan="2">
|
|
||||||
<widget class="QComboBox" name="device">
|
|
||||||
<property name="editable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QToolButton" name="search">
|
<widget class="QToolButton" name="search">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="3">
|
<item row="8" column="0" colspan="3">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
|
@ -105,17 +105,43 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0" colspan="3">
|
<item row="9" column="0" colspan="3">
|
||||||
<widget class="QProgressBar" name="progressBar">
|
<widget class="QProgressBar" name="progressBar">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="6" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="logToFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save libdivecomputer logfile</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="dumpToFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save libdivecomputer dumpfile</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="2">
|
||||||
|
<widget class="QToolButton" name="chooseLogFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="2">
|
||||||
|
<widget class="QToolButton" name="chooseDumpFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="../subsurface.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#include "qthelper.h"
|
#include "qthelper.h"
|
||||||
#include "qt-ui/mainwindow.h"
|
#include "qt-ui/mainwindow.h"
|
||||||
|
#include "qt-gui.h"
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#define tr(_arg) mainWindow()->information()->tr(_arg)
|
#define tr(_arg) mainWindow()->information()->tr(_arg)
|
||||||
|
@ -197,4 +200,3 @@ QList< int > getDivesInTrip ( dive_trip_t* trip )
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue