2013-05-03 18:04:51 +00:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2012-10-11 00:42:59 +00:00
|
|
|
#include <libintl.h>
|
|
|
|
#include <glib/gi18n.h>
|
2011-09-20 19:40:34 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2012-01-03 05:53:33 +00:00
|
|
|
#include <unistd.h>
|
2012-09-09 16:06:44 +00:00
|
|
|
#include <sys/stat.h>
|
2013-01-05 20:56:45 +00:00
|
|
|
#include <sys/time.h>
|
2013-01-05 20:16:02 +00:00
|
|
|
#include <ctype.h>
|
2011-09-20 19:40:34 +00:00
|
|
|
|
|
|
|
#include "dive.h"
|
|
|
|
#include "divelist.h"
|
|
|
|
#include "display.h"
|
2012-09-25 14:28:47 +00:00
|
|
|
#include "uemis.h"
|
2013-01-09 20:07:09 +00:00
|
|
|
#include "device.h"
|
2013-01-18 01:05:48 +00:00
|
|
|
#include "webservice.h"
|
2013-02-26 17:24:02 +00:00
|
|
|
#include "version.h"
|
2011-09-20 19:40:34 +00:00
|
|
|
#include "libdivecomputer.h"
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "qt-ui/mainwindow.h"
|
2011-09-20 19:40:34 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTranslator>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
class Translator: public QTranslator
|
2013-04-02 16:49:17 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-05-03 18:04:51 +00:00
|
|
|
Translator(QObject *parent = 0);
|
|
|
|
~Translator() {}
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
virtual QString translate(const char *context, const char *sourceText,
|
|
|
|
const char *disambiguation = NULL) const;
|
2013-04-02 16:49:17 +00:00
|
|
|
};
|
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
Translator::Translator(QObject *parent):
|
|
|
|
QTranslator(parent)
|
2013-04-02 16:49:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
QString Translator::translate(const char *context, const char *sourceText,
|
|
|
|
const char *disambiguation) const
|
2013-04-02 16:49:17 +00:00
|
|
|
{
|
2013-05-03 18:04:51 +00:00
|
|
|
return gettext(sourceText);
|
2013-04-02 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
static QApplication *application = NULL;
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2013-05-03 18:04:51 +00:00
|
|
|
int error_count;
|
|
|
|
const char *existing_filename;
|
2013-04-02 16:49:17 +00:00
|
|
|
|
2013-04-18 07:59:31 +00:00
|
|
|
void init_qt_ui(int *argcp, char ***argvp)
|
|
|
|
{
|
|
|
|
application->installTranslator(new Translator(application));
|
|
|
|
MainWindow *window = new MainWindow();
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
2011-11-02 00:09:15 +00:00
|
|
|
void init_ui(int *argcp, char ***argvp)
|
2011-09-20 19:40:34 +00:00
|
|
|
{
|
2013-04-22 13:45:57 +00:00
|
|
|
application = new QApplication(*argcp, *argvp);
|
2013-04-25 22:28:31 +00:00
|
|
|
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
// ask QString in Qt 4 to interpret all char* as UTF-8,
|
|
|
|
// like Qt 5 does.
|
|
|
|
// 106 is "UTF-8", this is faster than lookup by name
|
|
|
|
// [http://www.iana.org/assignments/character-sets/character-sets.xml]
|
|
|
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
|
|
|
|
#endif
|
|
|
|
|
2011-11-24 06:56:57 +00:00
|
|
|
subsurface_open_conf();
|
2013-01-11 03:33:53 +00:00
|
|
|
|
2013-01-11 18:14:10 +00:00
|
|
|
load_preferences();
|
2012-08-22 05:04:24 +00:00
|
|
|
|
2013-01-11 03:33:53 +00:00
|
|
|
default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor");
|
|
|
|
default_dive_computer_product = subsurface_get_conf("dive_computer_product");
|
|
|
|
default_dive_computer_device = subsurface_get_conf("dive_computer_device");
|
2011-09-20 19:40:34 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_ui(void)
|
|
|
|
{
|
2013-04-01 10:57:51 +00:00
|
|
|
application->exec();
|
2011-09-20 19:40:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:03:48 +00:00
|
|
|
void exit_ui(void)
|
|
|
|
{
|
2013-04-01 10:57:51 +00:00
|
|
|
delete application;
|
2012-05-02 17:03:48 +00:00
|
|
|
subsurface_close_conf();
|
2012-09-13 17:46:09 +00:00
|
|
|
if (existing_filename)
|
2012-09-16 03:51:06 +00:00
|
|
|
free((void *)existing_filename);
|
2012-09-22 16:07:50 +00:00
|
|
|
if (default_dive_computer_device)
|
|
|
|
free((void *)default_dive_computer_device);
|
2012-05-02 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 19:27:00 +00:00
|
|
|
void set_filename(const char *filename, gboolean force)
|
2011-09-21 04:50:26 +00:00
|
|
|
{
|
2012-09-10 19:27:00 +00:00
|
|
|
if (!force && existing_filename)
|
|
|
|
return;
|
2012-09-16 03:51:06 +00:00
|
|
|
free((void *)existing_filename);
|
2012-07-31 17:55:41 +00:00
|
|
|
if (filename)
|
2011-09-21 04:50:26 +00:00
|
|
|
existing_filename = strdup(filename);
|
2012-11-10 14:32:06 +00:00
|
|
|
else
|
|
|
|
existing_filename = NULL;
|
2011-09-21 04:50:26 +00:00
|
|
|
}
|
2012-12-13 06:26:29 +00:00
|
|
|
|
2012-12-26 21:47:54 +00:00
|
|
|
const char *get_dc_nickname(const char *model, uint32_t deviceid)
|
2012-12-22 05:00:06 +00:00
|
|
|
{
|
2013-01-09 19:38:35 +00:00
|
|
|
struct device_info *known = get_device_info(model, deviceid);
|
2012-12-26 21:47:54 +00:00
|
|
|
if (known) {
|
|
|
|
if (known->nickname && *known->nickname)
|
|
|
|
return known->nickname;
|
|
|
|
else
|
|
|
|
return known->model;
|
2012-12-22 05:00:06 +00:00
|
|
|
}
|
2012-12-23 05:37:13 +00:00
|
|
|
return NULL;
|
2012-12-22 05:00:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 06:26:29 +00:00
|
|
|
void set_dc_nickname(struct dive *dive)
|
|
|
|
{
|
2013-05-03 18:04:51 +00:00
|
|
|
/* needs Qt implementation */
|
2012-12-13 06:26:29 +00:00
|
|
|
}
|
2013-02-05 23:10:40 +00:00
|
|
|
|
2013-04-01 10:57:51 +00:00
|
|
|
|
2013-04-01 20:08:13 +00:00
|
|
|
#include "qt-gui.moc"
|