mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Settings update: Clean up save user id local
So, prefs.save_userid_local is being set outside of a preferences set (it's set to true and false while loading the files via xml or git) and because of that I had to bypass a few method calls. When something triggers a preferences change, the application will be notified that the preferences changed, thing that I couldn't do while reading the xml or git because that should be local-only. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
048379cc2b
commit
81d5d82b7b
7 changed files with 36 additions and 35 deletions
|
@ -3353,11 +3353,6 @@ timestamp_t get_times()
|
||||||
return dive->when;
|
return dive->when;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_save_userid_local(short value)
|
|
||||||
{
|
|
||||||
prefs.save_userid_local = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_userid(char *rUserId)
|
void set_userid(char *rUserId)
|
||||||
{
|
{
|
||||||
if (prefs.userid)
|
if (prefs.userid)
|
||||||
|
|
|
@ -811,7 +811,7 @@ static void parse_settings_userid(char *line, struct membuffer *str, void *_unus
|
||||||
(void) str;
|
(void) str;
|
||||||
(void) _unused;
|
(void) _unused;
|
||||||
if (line) {
|
if (line) {
|
||||||
set_save_userid_local(true);
|
prefs.save_userid_local = true;
|
||||||
set_userid(line);
|
set_userid(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1520,7 @@ static int parse_settings_entry(git_repository *repo, const git_tree_entry *entr
|
||||||
git_blob *blob = git_tree_entry_blob(repo, entry);
|
git_blob *blob = git_tree_entry_blob(repo, entry);
|
||||||
if (!blob)
|
if (!blob)
|
||||||
return report_error("Unable to read settings file");
|
return report_error("Unable to read settings file");
|
||||||
set_save_userid_local(false);
|
prefs.save_userid_local = false;
|
||||||
for_each_line(blob, settings_parser, NULL);
|
for_each_line(blob, settings_parser, NULL);
|
||||||
git_blob_free(blob);
|
git_blob_free(blob);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1771,7 +1771,12 @@ static void divecomputer_end(void)
|
||||||
static void userid_start(void)
|
static void userid_start(void)
|
||||||
{
|
{
|
||||||
in_userid = true;
|
in_userid = true;
|
||||||
set_save_userid_local(true); //if the xml contains userid, keep saving it.
|
//if the xml contains userid, keep saving it.
|
||||||
|
// don't call the prefs method here as we don't wanna
|
||||||
|
// actually change the preferences, this is temporary and
|
||||||
|
// will be reverted when the file finishes.
|
||||||
|
|
||||||
|
prefs.save_userid_local = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void userid_stop(void)
|
static void userid_stop(void)
|
||||||
|
@ -2045,7 +2050,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size,
|
||||||
if (!doc)
|
if (!doc)
|
||||||
return report_error(translate("gettextFromC", "Failed to parse '%s'"), url);
|
return report_error(translate("gettextFromC", "Failed to parse '%s'"), url);
|
||||||
|
|
||||||
set_save_userid_local(false);
|
prefs.save_userid_local = false;
|
||||||
reset_all();
|
reset_all();
|
||||||
dive_start();
|
dive_start();
|
||||||
doc = test_xslt_transforms(doc, params);
|
doc = test_xslt_transforms(doc, params);
|
||||||
|
|
|
@ -811,6 +811,17 @@ void CloudStorageSettings::setBackgroundSync(bool value)
|
||||||
emit backgroundSyncChanged(value);
|
emit backgroundSyncChanged(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CloudStorageSettings::setSaveUserIdLocal(short int value)
|
||||||
|
{
|
||||||
|
prefs.save_userid_local = value;
|
||||||
|
emit saveUserIdLocalChanged(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
short int CloudStorageSettings::saveUserIdLocal() const
|
||||||
|
{
|
||||||
|
return prefs.save_userid_local;
|
||||||
|
}
|
||||||
|
|
||||||
void CloudStorageSettings::setBaseUrl(const QString& value)
|
void CloudStorageSettings::setBaseUrl(const QString& value)
|
||||||
{
|
{
|
||||||
free((void*)prefs.cloud_base_url);
|
free((void*)prefs.cloud_base_url);
|
||||||
|
@ -1621,17 +1632,6 @@ QObject(parent),
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsObjectWrapper::setSaveUserIdLocal(short int value)
|
|
||||||
{
|
|
||||||
Q_UNUSED(value);
|
|
||||||
//TODO: Find where this is stored on the preferences.
|
|
||||||
}
|
|
||||||
|
|
||||||
short int SettingsObjectWrapper::saveUserIdLocal() const
|
|
||||||
{
|
|
||||||
return prefs.save_userid_local;
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingsObjectWrapper* SettingsObjectWrapper::instance()
|
SettingsObjectWrapper* SettingsObjectWrapper::instance()
|
||||||
{
|
{
|
||||||
static SettingsObjectWrapper settings;
|
static SettingsObjectWrapper settings;
|
||||||
|
|
|
@ -262,6 +262,7 @@ class CloudStorageSettings : public QObject {
|
||||||
Q_PROPERTY(QString userid READ userId WRITE setUserId NOTIFY userIdChanged)
|
Q_PROPERTY(QString userid READ userId WRITE setUserId NOTIFY userIdChanged)
|
||||||
Q_PROPERTY(QString base_url READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged)
|
Q_PROPERTY(QString base_url READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged)
|
||||||
Q_PROPERTY(QString git_url READ gitUrl WRITE setGitUrl NOTIFY gitUrlChanged)
|
Q_PROPERTY(QString git_url READ gitUrl WRITE setGitUrl NOTIFY gitUrlChanged)
|
||||||
|
Q_PROPERTY(short save_userid_local READ saveUserIdLocal WRITE setSaveUserIdLocal NOTIFY saveUserIdLocalChanged)
|
||||||
Q_PROPERTY(bool git_local_only READ gitLocalOnly WRITE setGitLocalOnly NOTIFY gitLocalOnlyChanged)
|
Q_PROPERTY(bool git_local_only READ gitLocalOnly WRITE setGitLocalOnly NOTIFY gitLocalOnlyChanged)
|
||||||
Q_PROPERTY(bool save_password_local READ savePasswordLocal WRITE setSavePasswordLocal NOTIFY savePasswordLocalChanged)
|
Q_PROPERTY(bool save_password_local READ savePasswordLocal WRITE setSavePasswordLocal NOTIFY savePasswordLocalChanged)
|
||||||
Q_PROPERTY(short verification_status READ verificationStatus WRITE setVerificationStatus NOTIFY verificationStatusChanged)
|
Q_PROPERTY(short verification_status READ verificationStatus WRITE setVerificationStatus NOTIFY verificationStatusChanged)
|
||||||
|
@ -279,6 +280,7 @@ public:
|
||||||
short verificationStatus() const;
|
short verificationStatus() const;
|
||||||
bool backgroundSync() const;
|
bool backgroundSync() const;
|
||||||
bool gitLocalOnly() const;
|
bool gitLocalOnly() const;
|
||||||
|
short saveUserIdLocal() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPassword(const QString& value);
|
void setPassword(const QString& value);
|
||||||
|
@ -292,6 +294,7 @@ public slots:
|
||||||
void setVerificationStatus(short value);
|
void setVerificationStatus(short value);
|
||||||
void setBackgroundSync(bool value);
|
void setBackgroundSync(bool value);
|
||||||
void setGitLocalOnly(bool value);
|
void setGitLocalOnly(bool value);
|
||||||
|
void setSaveUserIdLocal(short value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void passwordChanged(const QString& value);
|
void passwordChanged(const QString& value);
|
||||||
|
@ -305,6 +308,8 @@ signals:
|
||||||
void verificationStatusChanged(short value);
|
void verificationStatusChanged(short value);
|
||||||
void backgroundSyncChanged(bool value);
|
void backgroundSyncChanged(bool value);
|
||||||
void gitLocalOnlyChanged(bool value);
|
void gitLocalOnlyChanged(bool value);
|
||||||
|
void saveUserIdLocalChanged(short value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString group;
|
QString group;
|
||||||
};
|
};
|
||||||
|
@ -601,7 +606,6 @@ private:
|
||||||
|
|
||||||
class SettingsObjectWrapper : public QObject {
|
class SettingsObjectWrapper : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(short save_userid_local READ saveUserIdLocal WRITE setSaveUserIdLocal NOTIFY saveUserIdLocalChanged)
|
|
||||||
|
|
||||||
Q_PROPERTY(TechnicalDetailsSettings* techical_details MEMBER techDetails CONSTANT)
|
Q_PROPERTY(TechnicalDetailsSettings* techical_details MEMBER techDetails CONSTANT)
|
||||||
Q_PROPERTY(PartialPressureGasSettings* pp_gas MEMBER pp_gas CONSTANT)
|
Q_PROPERTY(PartialPressureGasSettings* pp_gas MEMBER pp_gas CONSTANT)
|
||||||
|
@ -619,7 +623,6 @@ class SettingsObjectWrapper : public QObject {
|
||||||
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
|
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
|
||||||
public:
|
public:
|
||||||
static SettingsObjectWrapper *instance();
|
static SettingsObjectWrapper *instance();
|
||||||
short saveUserIdLocal() const;
|
|
||||||
|
|
||||||
TechnicalDetailsSettings *techDetails;
|
TechnicalDetailsSettings *techDetails;
|
||||||
PartialPressureGasSettings *pp_gas;
|
PartialPressureGasSettings *pp_gas;
|
||||||
|
@ -635,12 +638,8 @@ public:
|
||||||
AnimationsSettingsObjectWrapper *animation_settings;
|
AnimationsSettingsObjectWrapper *animation_settings;
|
||||||
LocationServiceSettingsObjectWrapper *location_settings;
|
LocationServiceSettingsObjectWrapper *location_settings;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setSaveUserIdLocal(short value);
|
|
||||||
private:
|
private:
|
||||||
SettingsObjectWrapper(QObject *parent = NULL);
|
SettingsObjectWrapper(QObject *parent = NULL);
|
||||||
signals:
|
|
||||||
void saveUserIdLocalChanged(short value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "subsurfacewebservices.h"
|
#include "subsurfacewebservices.h"
|
||||||
#include "core/prefs-macros.h"
|
#include "core/prefs-macros.h"
|
||||||
#include "core/cloudstorage.h"
|
#include "core/cloudstorage.h"
|
||||||
|
#include "core/subsurface-qt/SettingsObjectWrapper.h"
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ PreferencesNetwork::~PreferencesNetwork()
|
||||||
|
|
||||||
void PreferencesNetwork::refreshSettings()
|
void PreferencesNetwork::refreshSettings()
|
||||||
{
|
{
|
||||||
QSettings s;
|
|
||||||
|
|
||||||
ui->proxyHost->setText(prefs.proxy_host);
|
ui->proxyHost->setText(prefs.proxy_host);
|
||||||
ui->proxyPort->setValue(prefs.proxy_port);
|
ui->proxyPort->setValue(prefs.proxy_port);
|
||||||
ui->proxyAuthRequired->setChecked(prefs.proxy_auth);
|
ui->proxyAuthRequired->setChecked(prefs.proxy_auth);
|
||||||
|
@ -42,17 +40,19 @@ void PreferencesNetwork::refreshSettings()
|
||||||
ui->save_password_local->setChecked(prefs.save_password_local);
|
ui->save_password_local->setChecked(prefs.save_password_local);
|
||||||
ui->cloud_background_sync->setChecked(prefs.cloud_background_sync);
|
ui->cloud_background_sync->setChecked(prefs.cloud_background_sync);
|
||||||
ui->save_uid_local->setChecked(prefs.save_userid_local);
|
ui->save_uid_local->setChecked(prefs.save_userid_local);
|
||||||
ui->default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper());
|
ui->default_uid->setText(QString(prefs.userid).toUpper());
|
||||||
|
|
||||||
cloudPinNeeded();
|
cloudPinNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreferencesNetwork::syncSettings()
|
void PreferencesNetwork::syncSettings()
|
||||||
{
|
{
|
||||||
QSettings s;
|
auto cloud = SettingsObjectWrapper::instance()->cloud_storage;
|
||||||
s.setValue("subsurface_webservice_uid", ui->default_uid->text().toUpper());
|
auto proxy = SettingsObjectWrapper::instance()->proxy;
|
||||||
set_save_userid_local(ui->save_uid_local->checkState());
|
|
||||||
|
|
||||||
|
cloud->setUserId(ui->default_uid->text().toUpper());
|
||||||
|
cloud->setSaveUserIdLocal(ui->save_uid_local->checkState());
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
s.beginGroup("Network");
|
s.beginGroup("Network");
|
||||||
s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt());
|
s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt());
|
||||||
s.setValue("proxy_host", ui->proxyHost->text());
|
s.setValue("proxy_host", ui->proxyHost->text());
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "desktop-widgets/maintab.h"
|
#include "desktop-widgets/maintab.h"
|
||||||
#include "core/display.h"
|
#include "core/display.h"
|
||||||
#include "core/membuffer.h"
|
#include "core/membuffer.h"
|
||||||
|
#include "core/subsurface-qt/SettingsObjectWrapper.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "core/cloudstorage.h"
|
#include "core/cloudstorage.h"
|
||||||
|
|
||||||
|
@ -436,7 +437,8 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
QString qDialogUid = ui.userID->text().toUpper();
|
QString qDialogUid = ui.userID->text().toUpper();
|
||||||
bool qSaveUid = ui.saveUidLocal->checkState();
|
bool qSaveUid = ui.saveUidLocal->checkState();
|
||||||
set_save_userid_local(qSaveUid);
|
SettingsObjectWrapper::instance()->cloud_storage->setSaveUserIdLocal(qSaveUid);
|
||||||
|
|
||||||
if (qSaveUid) {
|
if (qSaveUid) {
|
||||||
QString qSettingUid = s.value("subsurface_webservice_uid").toString();
|
QString qSettingUid = s.value("subsurface_webservice_uid").toString();
|
||||||
QString qFileUid = QString(prefs.userid);
|
QString qFileUid = QString(prefs.userid);
|
||||||
|
|
Loading…
Add table
Reference in a new issue