2013-05-03 11:04:51 -07:00
|
|
|
/* qt-gui.cpp */
|
|
|
|
/* Qt UI implementation */
|
2012-10-11 09:42:59 +09:00
|
|
|
#include <libintl.h>
|
|
|
|
#include <glib/gi18n.h>
|
2011-09-20 12:40:34 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2012-01-02 21:53:33 -08:00
|
|
|
#include <unistd.h>
|
2012-09-09 09:06:44 -07:00
|
|
|
#include <sys/stat.h>
|
2013-01-05 12:56:45 -08:00
|
|
|
#include <sys/time.h>
|
2013-01-05 12:16:02 -08:00
|
|
|
#include <ctype.h>
|
2011-09-20 12:40:34 -07:00
|
|
|
|
|
|
|
#include "dive.h"
|
|
|
|
#include "divelist.h"
|
|
|
|
#include "display.h"
|
2012-09-25 07:28:47 -07:00
|
|
|
#include "uemis.h"
|
2013-01-09 12:07:09 -08:00
|
|
|
#include "device.h"
|
2013-01-18 03:05:48 +02:00
|
|
|
#include "webservice.h"
|
2013-02-26 18:24:02 +01:00
|
|
|
#include "version.h"
|
2011-09-20 12:40:34 -07:00
|
|
|
#include "libdivecomputer.h"
|
2013-04-07 15:20:43 -07:00
|
|
|
#include "qt-ui/mainwindow.h"
|
2011-09-20 12:40:34 -07:00
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTranslator>
|
2013-04-07 15:20:43 -07:00
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
class Translator: public QTranslator
|
2013-04-02 19:49:17 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-05-03 11:04:51 -07:00
|
|
|
Translator(QObject *parent = 0);
|
|
|
|
~Translator() {}
|
2013-04-02 19:49:17 +03:00
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
virtual QString translate(const char *context, const char *sourceText,
|
|
|
|
const char *disambiguation = NULL) const;
|
2013-04-02 19:49:17 +03:00
|
|
|
};
|
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
Translator::Translator(QObject *parent):
|
|
|
|
QTranslator(parent)
|
2013-04-02 19:49:17 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
QString Translator::translate(const char *context, const char *sourceText,
|
|
|
|
const char *disambiguation) const
|
2013-04-02 19:49:17 +03:00
|
|
|
{
|
2013-05-03 11:04:51 -07:00
|
|
|
return gettext(sourceText);
|
2013-04-02 19:49:17 +03:00
|
|
|
}
|
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
static QApplication *application = NULL;
|
2013-04-02 19:49:17 +03:00
|
|
|
|
2013-05-03 11:04:51 -07:00
|
|
|
int error_count;
|
|
|
|
const char *existing_filename;
|
2013-04-02 19:49:17 +03:00
|
|
|
|
2013-04-18 08:59:31 +01:00
|
|
|
void init_qt_ui(int *argcp, char ***argvp)
|
|
|
|
{
|
|
|
|
application->installTranslator(new Translator(application));
|
|
|
|
MainWindow *window = new MainWindow();
|
|
|
|
window->show();
|
|
|
|
}
|
|
|
|
|
2011-11-01 17:09:15 -07:00
|
|
|
void init_ui(int *argcp, char ***argvp)
|
2011-09-20 12:40:34 -07:00
|
|
|
{
|
2013-04-22 06:45:57 -07:00
|
|
|
application = new QApplication(*argcp, *argvp);
|
2013-04-25 15:28:31 -07: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
|
|
|
|
|
2013-05-05 21:06:45 -07:00
|
|
|
#if 0
|
2011-11-23 22:56:57 -08:00
|
|
|
subsurface_open_conf();
|
2013-01-10 19:33:53 -08:00
|
|
|
|
2013-01-11 10:14:10 -08:00
|
|
|
load_preferences();
|
2012-08-21 22:04:24 -07:00
|
|
|
|
2013-05-05 21:06:45 -07:00
|
|
|
/* these still need to be handled in QSettings */
|
2013-01-10 19:33:53 -08: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");
|
2013-05-05 21:06:45 -07:00
|
|
|
#endif
|
2011-09-20 12:40:34 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_ui(void)
|
|
|
|
{
|
2013-04-01 13:57:51 +03:00
|
|
|
application->exec();
|
2011-09-20 12:40:34 -07:00
|
|
|
}
|
|
|
|
|
2012-05-02 10:03:48 -07:00
|
|
|
void exit_ui(void)
|
|
|
|
{
|
2013-04-01 13:57:51 +03:00
|
|
|
delete application;
|
2013-05-05 21:06:45 -07:00
|
|
|
#if 0
|
2012-05-02 10:03:48 -07:00
|
|
|
subsurface_close_conf();
|
2013-05-05 21:06:45 -07:00
|
|
|
#endif
|
2012-09-13 10:46:09 -07:00
|
|
|
if (existing_filename)
|
2012-09-15 20:51:06 -07:00
|
|
|
free((void *)existing_filename);
|
2012-09-22 19:07:50 +03:00
|
|
|
if (default_dive_computer_device)
|
|
|
|
free((void *)default_dive_computer_device);
|
2012-05-02 10:03:48 -07:00
|
|
|
}
|
|
|
|
|
2012-09-10 12:27:00 -07:00
|
|
|
void set_filename(const char *filename, gboolean force)
|
2011-09-20 21:50:26 -07:00
|
|
|
{
|
2012-09-10 12:27:00 -07:00
|
|
|
if (!force && existing_filename)
|
|
|
|
return;
|
2012-09-15 20:51:06 -07:00
|
|
|
free((void *)existing_filename);
|
2012-07-31 20:55:41 +03:00
|
|
|
if (filename)
|
2011-09-20 21:50:26 -07:00
|
|
|
existing_filename = strdup(filename);
|
2012-11-10 15:32:06 +01:00
|
|
|
else
|
|
|
|
existing_filename = NULL;
|
2011-09-20 21:50:26 -07:00
|
|
|
}
|
2012-12-12 20:26:29 -10:00
|
|
|
|
2012-12-26 13:47:54 -08:00
|
|
|
const char *get_dc_nickname(const char *model, uint32_t deviceid)
|
2012-12-21 21:00:06 -08:00
|
|
|
{
|
2013-01-09 11:38:35 -08:00
|
|
|
struct device_info *known = get_device_info(model, deviceid);
|
2012-12-26 13:47:54 -08:00
|
|
|
if (known) {
|
|
|
|
if (known->nickname && *known->nickname)
|
|
|
|
return known->nickname;
|
|
|
|
else
|
|
|
|
return known->model;
|
2012-12-21 21:00:06 -08:00
|
|
|
}
|
2012-12-22 21:37:13 -08:00
|
|
|
return NULL;
|
2012-12-21 21:00:06 -08:00
|
|
|
}
|
|
|
|
|
2012-12-12 20:26:29 -10:00
|
|
|
void set_dc_nickname(struct dive *dive)
|
|
|
|
{
|
2013-05-03 11:04:51 -07:00
|
|
|
/* needs Qt implementation */
|
2012-12-12 20:26:29 -10:00
|
|
|
}
|
2013-02-06 01:10:40 +02:00
|
|
|
|
2013-04-01 13:57:51 +03:00
|
|
|
|
2013-04-01 23:08:13 +03:00
|
|
|
#include "qt-gui.moc"
|