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-05-10 04:37:21 +00:00
|
|
|
#include <QSettings>
|
2013-05-10 16:24:06 +00:00
|
|
|
#include <QDesktopWidget>
|
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-05-10 04:37:21 +00:00
|
|
|
QVariant v;
|
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
|
|
|
|
|
2013-05-10 04:37:21 +00:00
|
|
|
QSettings settings("hohndel.org","subsurface");
|
|
|
|
settings.beginGroup("GeneralSettings");
|
|
|
|
v = settings.value(QString("default_filename"));
|
|
|
|
if (v.isValid()) {
|
|
|
|
QString name = v.toString();
|
|
|
|
prefs.default_filename = strdup(name.toUtf8());
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
|
|
|
|
2013-05-06 04:06:45 +00:00
|
|
|
#if 0
|
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-05-06 04:06:45 +00:00
|
|
|
/* these still need to be handled in QSettings */
|
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");
|
2013-05-06 04:06:45 +00:00
|
|
|
#endif
|
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;
|
2013-05-06 04:06:45 +00:00
|
|
|
#if 0
|
2012-05-02 17:03:48 +00:00
|
|
|
subsurface_close_conf();
|
2013-05-06 04:06:45 +00:00
|
|
|
#endif
|
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-05-07 03:36:37 +00:00
|
|
|
QString get_depth_string(depth_t depth, bool showunit)
|
|
|
|
{
|
|
|
|
if (prefs.units.length == units::METERS) {
|
|
|
|
double meters = depth.mm / 1000.0;
|
|
|
|
return QString("%1%2").arg(meters, 0, 'f', meters >= 20.0 ? 0 : 1 ).arg(showunit ? _("m") : "");
|
|
|
|
} else {
|
|
|
|
double feet = mm_to_feet(depth.mm);
|
|
|
|
return QString("%1%2").arg(feet, 0, 'f', 1). arg(showunit ? _("ft") : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString get_weight_string(weight_t weight, bool showunit)
|
|
|
|
{
|
|
|
|
if (prefs.units.weight == units::KG) {
|
|
|
|
double kg = weight.grams / 1000.0;
|
|
|
|
return QString("%1%2").arg(kg, 0, 'f', kg >= 20.0 ? 0 : 1 ).arg(showunit ? _("kg") : "");
|
|
|
|
} else {
|
|
|
|
double lbs = grams_to_lbs(weight.grams);
|
|
|
|
return QString("%1%2").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1 ).arg(showunit ? _("lbs") : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString get_temperature_string(temperature_t temp, bool showunit)
|
|
|
|
{
|
|
|
|
if (prefs.units.temperature == units::CELSIUS) {
|
|
|
|
double celsius = mkelvin_to_C(temp.mkelvin);
|
|
|
|
return QString("%1%2").arg(celsius, 0, 'f', 1).arg(showunit ? _("C") : "");
|
|
|
|
} else {
|
|
|
|
double fahrenheit = mkelvin_to_F(temp.mkelvin);
|
|
|
|
return QString("%1%2").arg(fahrenheit, 0, 'f', 1).arg(showunit ? _("F") : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString get_volume_string(volume_t volume, bool showunit)
|
|
|
|
{
|
|
|
|
if (prefs.units.volume == units::LITER) {
|
|
|
|
double liter = volume.mliter / 1000.0;
|
|
|
|
return QString("%1%2").arg(liter, 0, 'f', liter >= 40.0 ? 0 : 1 ).arg(showunit ? _("l") : "");
|
|
|
|
} else {
|
|
|
|
double cuft = ml_to_cuft(volume.mliter);
|
|
|
|
return QString("%1%2").arg(cuft, 0, 'f', cuft >= 20.0 ? 0 : (cuft >= 2.0 ? 1 : 2)).arg(showunit ? _("cuft") : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString get_pressure_string(pressure_t pressure, bool showunit)
|
|
|
|
{
|
|
|
|
if (prefs.units.pressure == units::BAR) {
|
|
|
|
double bar = pressure.mbar / 1000.0;
|
|
|
|
return QString("%1%2").arg(bar, 0, 'f', 1).arg(showunit ? _("bar") : "");
|
|
|
|
} else {
|
|
|
|
double psi = mbar_to_PSI(pressure.mbar);
|
|
|
|
return QString("%1%2").arg(psi, 0, 'f', 0).arg(showunit ? _("psi") : "");
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 10:57:51 +00:00
|
|
|
|
2013-05-10 16:24:06 +00:00
|
|
|
double get_screen_dpi()
|
|
|
|
{
|
|
|
|
QDesktopWidget *mydesk = application->desktop();
|
|
|
|
return mydesk->physicalDpiX();
|
|
|
|
}
|
2013-04-01 20:08:13 +00:00
|
|
|
#include "qt-gui.moc"
|