On Wed, Apr 2, 2014 at 11:50 PM, Linus Torvalds < [email protected]> wrote:
> On Wed, Apr 2, 2014 at 11:04 AM, Venkatesh Shukla IIT BHU > <[email protected]> wrote: > > This is my first patch in Main Subsurface code. I am eager to receive > your > > feedbacks for any kind of improvements. > > That can't work. Nothing parses it from the xml, so it may get > "saved", but it will never get loaded and thus re-saved. > > Linus > Sir I apologize for my haste and stupidity. I have made necessary changes to the parsing mechanism. This seems to work fine. Please send feedbacks for improvements. I have attached the patch with respect to current git commit. -- *Venkatesh Shukla *
From 2d5595aa0669d618e5f396f75403ffab9e85c28b Mon Sep 17 00:00:00 2001 From: Venkatesh Shukla <[email protected]> Date: Thu, 3 Apr 2014 20:39:15 +0530 Subject: [PATCH] Ticket #473: Add option of saving User ID in xml 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. Dialogbox retains the last set option or as per present xml. 3. Suitable modifications made in parse-xml.c 4. saving option depends on presence/absence of userid in xml Todo: 1. Force save once on clicking accept ? Signed-off-by: Venkatesh Shukla <[email protected]> --- dive.h | 6 ++++++ parse-xml.c | 24 ++++++++++++++++++++++++ qt-ui/subsurfacewebservices.cpp | 29 ++++++++++++++++++++++++++++- qt-ui/subsurfacewebservices.h | 11 +++++++++++ qt-ui/webservices.ui | 9 ++++++++- save-xml.c | 8 +++++++- 6 files changed, 84 insertions(+), 3 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..17b03bb 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,13 @@ 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 +1375,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 +1538,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 }, diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 7077465..ff49525 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -318,6 +318,7 @@ SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) 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 +340,11 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button) /* store last entered uid in config */ QSettings s; - s.setValue("subsurface_webservice_uid", ui.userID->text().toUpper()); + QString qUserId = ui.userID->text().toUpper(); + bool qSaveUserId = ui.saveUserIdXml->checkState(); + s.setValue("subsurface_webservice_uid", qUserId); + set_userid(qUserId.toLocal8Bit().data()); + set_save_userid_xml(qSaveUserId); s.sync(); hide(); close(); @@ -626,6 +631,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 +889,24 @@ 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..cd41558 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,8 +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); if (autogroup) -- 1.9.0
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
