mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Separate the download thread from the widget logic
This is important to not duplicate code for the Qml view. Now the DownloadFromDiveComputer widget is mostly free from important code (that has been upgraded to the core folder), and I can start coding the QML interface. There are still a few functions on the desktop widget that will die so I can call them via the QML code later. I also touched the location of a few globals (please, let's stop using those) - because it was declared on the desktop code and being used in the core. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3c3f91dcb2
commit
dec47e11cd
11 changed files with 106 additions and 64 deletions
|
|
@ -84,11 +84,13 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
|||
isocialnetworkintegration.cpp
|
||||
gpslocation.cpp
|
||||
cloudstorage.cpp
|
||||
downloadfromdcthread.cpp
|
||||
|
||||
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
|
||||
subsurface-qt/DiveObjectHelper.cpp
|
||||
subsurface-qt/CylinderObjectHelper.cpp
|
||||
subsurface-qt/SettingsObjectWrapper.cpp
|
||||
|
||||
${SERIAL_FTDI}
|
||||
${PLATFORM_SRC}
|
||||
${BT_CORE_SRC_FILES}
|
||||
|
|
|
|||
|
|
@ -971,6 +971,8 @@ extern volume_t string_to_volume(const char *str, pressure_t workp);
|
|||
extern fraction_t string_to_fraction(const char *str);
|
||||
extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth);
|
||||
|
||||
extern struct dive_table downloadTable;
|
||||
|
||||
#include "pref.h"
|
||||
|
||||
#endif // DIVE_H
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ dive_trip_t *dive_trip_list;
|
|||
|
||||
unsigned int amount_selected;
|
||||
|
||||
// We need to stop using globals, really.
|
||||
struct dive_table downloadTable;
|
||||
|
||||
#if DEBUG_SELECTION_TRACKING
|
||||
void dump_selection(void)
|
||||
{
|
||||
|
|
|
|||
36
core/downloadfromdcthread.cpp
Normal file
36
core/downloadfromdcthread.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include "downloadfromdcthread.h"
|
||||
#include "core/libdivecomputer.h"
|
||||
|
||||
static QString str_error(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
const QString str = QString().vsprintf(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
DownloadThread::DownloadThread(QObject *parent, device_data_t *data) : QThread(parent),
|
||||
data(data)
|
||||
{
|
||||
data->download_table = nullptr;
|
||||
}
|
||||
|
||||
void DownloadThread::setDiveTable(struct dive_table* table)
|
||||
{
|
||||
data->download_table = table;
|
||||
}
|
||||
|
||||
void DownloadThread::run()
|
||||
{
|
||||
Q_ASSERT(data->download_table != nullptr);
|
||||
const char *errorText;
|
||||
import_thread_cancelled = false;
|
||||
if (!strcmp(data->vendor, "Uemis"))
|
||||
errorText = do_uemis_import(data);
|
||||
else
|
||||
errorText = do_libdivecomputer_import(data);
|
||||
if (errorText)
|
||||
error = str_error(errorText, data->devname, data->vendor, data->product);
|
||||
}
|
||||
21
core/downloadfromdcthread.h
Normal file
21
core/downloadfromdcthread.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef DOWNLOADFROMDCTHREAD_H
|
||||
#define DOWNLOADFROMDCTHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
#include "dive.h"
|
||||
#include "libdivecomputer.h"
|
||||
|
||||
class DownloadThread : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DownloadThread(QObject *parent, device_data_t *data);
|
||||
void setDiveTable(struct dive_table *table);
|
||||
void run() override;
|
||||
|
||||
QString error;
|
||||
|
||||
private:
|
||||
device_data_t *data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -76,6 +76,8 @@ static int dive_to_read = 0;
|
|||
|
||||
static int max_deleted_seen = -1;
|
||||
|
||||
extern struct dive_table downloadTable;
|
||||
|
||||
/* helper function to parse the Uemis data structures */
|
||||
static void uemis_ts(char *buffer, void *_when)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue