Preferences infrastructure for GeoManagement

Simple preferences infrastructure with default prefs, prefs and hooks for
the Qt Settings system and our preferences ui.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-06-22 18:44:05 -03:00 committed by Dirk Hohndel
parent ce4333e8fd
commit 21c46b8c2d
3 changed files with 51 additions and 1 deletions

10
pref.h
View file

@ -24,6 +24,15 @@ typedef struct {
char *album_id; char *album_id;
} facebook_prefs_t; } facebook_prefs_t;
typedef struct {
bool enable_geocoding;
bool parse_dive_without_gps;
bool tag_existing_dives;
char *first_item;
char *second_item;
char *third_item;
} geocoding_prefs_t;
struct preferences { struct preferences {
const char *divelist_font; const char *divelist_font;
const char *default_filename; const char *default_filename;
@ -100,6 +109,7 @@ struct preferences {
bool save_password_local; bool save_password_local;
short cloud_verification_status; short cloud_verification_status;
bool cloud_background_sync; bool cloud_background_sync;
geocoding_prefs_t geocoding;
}; };
enum unit_system_values { enum unit_system_values {
METRIC, METRIC,

View file

@ -1,6 +1,7 @@
#include "preferences.h" #include "preferences.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "models.h" #include "models.h"
#include "divelocationmodel.h"
#include <QSettings> #include <QSettings>
#include <QFileDialog> #include <QFileDialog>
@ -45,6 +46,9 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy);
ui.proxyType->setCurrentIndex(-1); ui.proxyType->setCurrentIndex(-1);
ui.first_item->setModel(GeoReferencingOptionsModel::instance());
ui.second_item->setModel(GeoReferencingOptionsModel::instance());
ui.third_item->setModel(GeoReferencingOptionsModel::instance());
// Facebook stuff: // Facebook stuff:
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) #if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
FacebookManager *fb = FacebookManager::instance(); FacebookManager *fb = FacebookManager::instance();
@ -232,6 +236,14 @@ void PreferencesDialog::setUiFromPrefs()
ui.save_password_local->setChecked(prefs.save_password_local); ui.save_password_local->setChecked(prefs.save_password_local);
cloudPinNeeded(); cloudPinNeeded();
ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); ui.cloud_background_sync->setChecked(prefs.cloud_background_sync);
// GeoManagement
ui.enable_geocoding->setChecked( prefs.geocoding.enable_geocoding );
ui.parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps);
ui.tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives);
ui.first_item->setCurrentText(prefs.geocoding.first_item);
ui.second_item->setCurrentText(prefs.geocoding.second_item);
ui.third_item->setCurrentText(prefs.geocoding.third_item);
} }
void PreferencesDialog::restorePrefs() void PreferencesDialog::restorePrefs()
@ -438,6 +450,16 @@ void PreferencesDialog::syncSettings()
// it could go into some sort of "advanced setup" or something // it could go into some sort of "advanced setup" or something
SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url);
s.endGroup(); s.endGroup();
s.beginGroup("geocoding");
s.setValue("enable_geocoding", ui.enable_geocoding->isChecked());
s.setValue("parse_dives_without_gps", ui.parse_without_gps->isChecked());
s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked());
s.setValue("first_item", ui.first_item->currentText());
s.setValue("second_item", ui.second_item->currentText());
s.setValue("third_item", ui.third_item->currentText());
s.endGroup();
loadSettings(); loadSettings();
emit settingsChanged(); emit settingsChanged();
} }
@ -575,6 +597,16 @@ void PreferencesDialog::loadSettings()
GET_TXT("cloud_base_url", cloud_base_url); GET_TXT("cloud_base_url", cloud_base_url);
prefs.cloud_git_url = strdup(qPrintable(QString(prefs.cloud_base_url) + "/git")); prefs.cloud_git_url = strdup(qPrintable(QString(prefs.cloud_base_url) + "/git"));
s.endGroup(); s.endGroup();
// GeoManagement
s.beginGroup("geocoding");
GET_BOOL("enable_geocoding", geocoding.enable_geocoding);
GET_BOOL("parse_dives_without_gps", geocoding.parse_dive_without_gps);
GET_BOOL("tag_existing_dives", geocoding.tag_existing_dives);
GET_TXT("first_item", geocoding.first_item);
GET_TXT("second_item", geocoding.second_item);
GET_TXT("third_item", geocoding.third_item);
s.endGroup();
} }
void PreferencesDialog::buttonClicked(QAbstractButton *button) void PreferencesDialog::buttonClicked(QAbstractButton *button)

View file

@ -68,7 +68,15 @@ struct preferences default_prefs = {
.access_token = NULL .access_token = NULL
}, },
.defaultsetpoint = 1100, .defaultsetpoint = 1100,
.cloud_background_sync = true .cloud_background_sync = true,
.geocoding = {
.enable_geocoding = false,
.parse_dive_without_gps = false,
.tag_existing_dives = false,
.first_item = NULL,
.second_item = NULL,
.third_item = NULL
}
}; };
int run_survey; int run_survey;