First of all, I apologize for my mistake of not adding the mailing list in
my reply. I realized it just now that I haven't.

On Fri, Apr 4, 2014 at 12:19 AM, Dirk Hohndel <[email protected]> wrote:

> On Thu, 2014-04-03 at 23:26 +0530, Venkatesh Shukla IIT BHU wrote:
> >         I think Lubomir's question was about the preference order...
> >         we store
> >
> >         the userid in the settings AND we store it in the XML file. If
> >         both are
> >         present, which one is given preference?
> >
> >
> >
> > In the present implementation, the event which happens later decides.
> > If a new file is loaded, the userid 'a' of the file would take
> > preference. If in this new file, the user opens the download dialog
> > box and downloads dives with another userid 'b' and saves it, b will
> > be stored in the file. Also, as before, b is stored in the subsurface
> > settings.Maybe we should introduce this as a preference for the user?
> >
> >
> > I have few questions regarding this.
> > 1. If a new xml file with different userid is loaded, should
> > subsurface settings be changed to replace the old with the new?
>
> That's an interesting question. I would say no. That's a file specific
> setting that should not override the local setting.
>
> I think the right semantic is this:
>
> - if the user enters a user id in the dialog, that user id is saved in
> the local settings
> - if the user clicks the setting to save it to XML, it's saved to both
> - if the user has a local setting that populates the dialog. If the user
> opens a file that has a per file userid, that is used instead - but it
> doesn't change the local setting


I have taken care of the above semantics in the attached patch.

Explanation :
When a new file is loaded,
1. If it contains user id, saving of userid is enabled. Also, this shows up
in the textbox in the download dialogbox. And the checkbox is ticked.
2. If it doesn't contain userid, saving userid is disabled. The textbox is
filled up with userid from subsurface settings. Checkbox is unticked.
If checkbox is unticked, userid is not stores in xml file.


Now, if there are userid of dialogbox, xml file and subsurface settings,
there are these 5 cases possible.
1. All three uid are same. Nothing needs to be done. Save it everywhere.
 2. All three uid are different. User has manually input a UID in the
dialogbox. Save it everywhere.
 3. Settings == File !=  Dialog UID : User has manually input a UID. Save
it everywhere.
 4. Settings == Dialog != File UID : User has changed the file UID to
settings one. Save it everywhere.
 5. File == Dialog != Settings UID : Xml file with different UID than saved
is loaded. Use the file UID to save in the file. But leave the settings as
they
    were.

Everywhere corresponds to xml file and subsurface settings.


> > 2. After the download of dives from subsurface webservice, if the
> > checkbox is ticked, should save-xml be called automatically?
>
> No
>
> >  Currently, the user has to save manually after download for the
> > effect of userid inclusion/exclusion to take place.
>
> A successful download should modify the file (as it adds GPS data and
> possibly dive site names). And because of that the user will be asked to
> save before she quits Subsurface
>
> > Okay Dirk, I'll study libgit2 and try to achieve what you have said.
> > It is indeed a good idea.
>
> Thanks


I am still working on this part.
I have tried to follow the CodingStyle document.

Regards
-- 

*Venkatesh Shukla *
From 6776428635895cb6ea22eee8e2bf3920e7b8febd Mon Sep 17 00:00:00 2001
From: Venkatesh Shukla <[email protected]>
Date: Fri, 4 Apr 2014 03:06:05 +0530
Subject: [PATCH] Add option of saving subsurface userid in xml Fixes #473

Changes Made:
1. Choose if User ID is to be saved during import of divelogs from
   subsurface webservice. Save function must be called once for change
   to take effect.
2. Checkbox retains the last set option or as per present xml.
3. Suitable modifications made in parse-xml.c
4. If userid is present in xml, saving option is enabled, else
   disabled. For manually enabling it, use the webservices dialogbox.
5. The userid in the xml file does not override the settings until
   manually done so via webservices dialogbox.
6. Userid, if present in the xml, is shown in the download dialogbox.
   But it doesn't override the settings of subsurface. If userid is
   absent, then the saved userid is shown in dialogbox.

Signed-off-by: Venkatesh Shukla <[email protected]>
---
 dive.h                          |  6 ++++
 parse-xml.c                     | 24 ++++++++++++++++
 qt-ui/subsurfacewebservices.cpp | 62 +++++++++++++++++++++++++++++++++++++++--
 qt-ui/subsurfacewebservices.h   | 11 ++++++++
 qt-ui/webservices.ui            |  9 +++++-
 save-xml.c                      |  9 +++++-
 6 files changed, 117 insertions(+), 4 deletions(-)

diff --git a/dive.h b/dive.h
index f62d83d..cc8b9b4 100644
--- a/dive.h
+++ b/dive.h
@@ -887,6 +887,12 @@ extern double strtod_flags(const char *str, const char **ptr, unsigned int flags
 
 #define ascii_strtod(str, ptr) strtod_flags(str, ptr, STRTOD_ASCII)
 
+extern short save_userid_xml;
+extern char* userid;
+
+extern void set_save_userid_xml(short value);
+extern void set_userid(char* rUserId);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/parse-xml.c b/parse-xml.c
index 483187a..eeca46a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -112,6 +112,7 @@ static struct {
 	} dc;
 } cur_settings;
 static bool in_settings = false;
+static bool in_userid = false;
 static struct tm cur_tm;
 static int cur_cylinder_index, cur_ws_index;
 static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
@@ -858,6 +859,12 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
 	nonmatch("sample", name, buf);
 }
 
+void try_to_fill_userid(const char *name, char *buf)
+{
+	if (save_userid_xml)
+		set_userid(buf);
+}
+
 static const char *country, *city;
 
 static void divinglog_place(char *place, void *_location)
@@ -1367,8 +1374,23 @@ static void divecomputer_end(void)
 	cur_dc = NULL;
 }
 
+static void userid_start(void)
+{
+	in_userid = true;
+	set_save_userid_xml(true); //if the xml file contains userid, keep saving it
+}
+
+static void userid_stop(void)
+{
+	in_userid = false;
+}
+
 static void entry(const char *name, char *buf)
 {
+	if (in_userid) {
+		try_to_fill_userid(name, buf);
+		return;
+	}
 	if (in_settings) {
 		try_to_fill_dc_settings(name, buf);
 		try_to_match_autogroup(name, buf);
@@ -1515,6 +1537,7 @@ static struct nesting {
 	  { "weightsystem", ws_start, ws_end },
 	  { "divecomputer", divecomputer_start, divecomputer_end },
 	  { "P", sample_start, sample_end },
+	  { "userid", userid_start, userid_stop},
 
 	  /* Import type recognition */
 	  { "Divinglog", DivingLog_importer },
@@ -1603,6 +1626,7 @@ void parse_xml_buffer(const char *url, const char *buffer, int size,
 		return;
 	}
 	reset_all();
+	set_save_userid_xml(false);
 	dive_start();
 	doc = test_xslt_transforms(doc, params);
 	traverse(xmlDocGetRootElement(doc));
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 7077465..b231173 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_xml)
+		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.saveUserIdXml->setChecked(save_userid_xml);
 }
 
 void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
@@ -339,7 +343,37 @@ 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.saveUserIdXml->checkState();
+		set_save_userid_xml(qSaveUid);
+		/*
+		 * Five possible cases :
+		 * 1. All three uid are same. Nothing needs to be done.
+		 *    Save it everywhere.
+		 * 2. All three uid are different. User has manually
+		 *    input a UID in dialogbox. Save it everywhere.
+		 * 3. Settings == File !=  Dialog UID : User has manually
+		 *    input a UID. Save it everywhere.
+		 * 4. Settings == Dialog != File UID : User has changed
+		 *    displayed UID to saved one. Save it everywhere.
+		 * 5. File == Dialog != Settings UID : Xml file with
+		 *    different UID than saved is loaded. Use file UID
+		 *    to save in the file. But leave the settings as they
+		 *    were.
+		 *    Everywhere : Global variable userid -> presently open file
+		 *               : Subsurface settings
+		 */
+		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 = (qFileUid == qDialogUid);
+			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 +660,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.saveUserIdXml->hide();
 	hideUpload();
 }
 
@@ -883,3 +918,26 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
 		break;
 	}
 }
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define MAX_USERID_SIZE 32
+short save_userid_xml = false;
+char *userid = NULL;
+
+void set_save_userid_xml(short value)
+{
+	save_userid_xml = value;
+}
+
+void set_userid(char* rUserId)
+{
+	userid = (char*) malloc(MAX_USERID_SIZE * sizeof (char));
+	if (userid && rUserId)
+		strcpy(userid, rUserId);
+}
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 175c991..d6b143f 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -98,4 +98,15 @@ private:
 	bool uploadMode;
 };
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern short save_userid_xml;
+extern char* userid;
+void set_save_userid_xml(short value);
+void set_userid(char *value);
+#ifdef __cplusplus
+}
+#endif
+
 #endif // SUBSURFACEWEBSERVICES_H
diff --git a/qt-ui/webservices.ui b/qt-ui/webservices.ui
index 295c252..bf14462 100644
--- a/qt-ui/webservices.ui
+++ b/qt-ui/webservices.ui
@@ -45,7 +45,7 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="0" colspan="3">
+   <item row="5" column="0" colspan="3">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -79,6 +79,13 @@
      </property>
     </widget>
    </item>
+   <item row="4" column="0" colspan="4">
+    <widget class="QCheckBox" name="saveUserIdXml">
+     <property name="text">
+      <string>Save User ID in XML?</string>
+     </property>
+    </widget>
+   </item>
    <item row="1" column="0">
     <widget class="QLabel" name="passLabel">
      <property name="text">
diff --git a/save-xml.c b/save-xml.c
index 61a9300..2b3c336 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -11,6 +11,7 @@
 #include "device.h"
 #include "membuffer.h"
 
+
 /*
  * We're outputting utf8 in xml.
  * We need to quote the characters <, >, &.
@@ -506,7 +507,13 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
 	struct dive *dive;
 	dive_trip_t *trip;
 
-	put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
+	put_format(b, "<divelog program='subsurface' version='%d'>\n", VERSION);
+
+	if (save_userid_xml) {
+		put_format(b, "<userid>%s</userid>\n", userid);
+	}
+
+	put_format(b, "<settings>\n");
 
 	/* save the dive computer nicknames, if any */
 	call_for_each_dc(b, save_one_device);
-- 
1.9.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to