From 3abcde9a2abade0ce576976b6dce869e8aa28601 Mon Sep 17 00:00:00 2001 From: Venkatesh Shukla Date: Fri, 11 Apr 2014 11:47:35 +0530 Subject: Add option to save userid in data files The userid of Subsurface Webservice can be included in locally saved xml files and git repository. For xml files, it is stored in userid tag. For git repo, it is stored in 00-Subsurface file present in the repo. Preference dialog and webservice dialog modified to include option for saving userid locally. In case of difference in default userid and userid in local file, some semantics are followed. These can be referred to here: http://lists.hohndel.org/pipermail/subsurface/2014-April/011422.html Fixes #473 Signed-off-by: Venkatesh Shukla Signed-off-by: Dirk Hohndel --- qt-ui/subsurfacewebservices.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'qt-ui/subsurfacewebservices.cpp') diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index d6d0debee..1b8eab129 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -312,12 +312,16 @@ void WebServices::resetState() SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f) { QSettings s; - ui.userID->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + if (!save_userid_local || !*userid) + ui.userID->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + else + ui.userID->setText(userid); hidePassword(); hideUpload(); ui.progressBar->setFormat("Enter User ID and click Download"); ui.progressBar->setRange(0, 1); ui.progressBar->setValue(-1); + ui.saveUidLocal->setChecked(save_userid_local); } void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) @@ -339,7 +343,20 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) /* store last entered uid in config */ QSettings s; - s.setValue("subsurface_webservice_uid", ui.userID->text().toUpper()); + QString qDialogUid = ui.userID->text().toUpper(); + bool qSaveUid = ui.saveUidLocal->checkState(); + set_save_userid_local(qSaveUid); + if (qSaveUid) { + QString qSettingUid = s.value("subsurface_webservice_uid").toString(); + QString qFileUid = QString::fromStdString(userid); + bool s_eq_d = (qSettingUid == qDialogUid); + bool d_eq_f = (qDialogUid == qFileUid); + if (!d_eq_f || s_eq_d) + s.setValue("subsurface_webservice_uid", qDialogUid); + set_userid(qDialogUid.toLocal8Bit().data()); + } else { + s.setValue("subsurface_webservice_uid", qDialogUid); + } s.sync(); hide(); close(); @@ -626,6 +643,7 @@ DivelogsDeWebServices::DivelogsDeWebServices(QWidget *parent, Qt::WindowFlags f) QSettings s; ui.userID->setText(s.value("divelogde_user").toString()); ui.password->setText(s.value("divelogde_pass").toString()); + ui.saveUidLocal->hide(); hideUpload(); } @@ -883,3 +901,20 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) break; } } + +#define MAX_USERID_SIZE 32 +short save_userid_local = false; +char *userid = NULL; +void set_save_userid_local(short value) +{ + QSettings s; + s.setValue("save_uid_local", value); + save_userid_local = value; +} + +void set_userid(char *rUserId) +{ + userid = (char *) malloc(MAX_USERID_SIZE); + if (userid && rUserId) + strcpy(userid, rUserId); +} -- cgit v1.2.3-70-g09d2