Removed the globals 'userid' and 'save_userid_local' variables

This is a preferences setting, it should belong to the preferences
structure.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-04-17 11:34:21 -03:00 committed by Dirk Hohndel
parent f14c14c383
commit 9598462830
9 changed files with 32 additions and 32 deletions

View file

@ -100,6 +100,8 @@ SET(SUBSURFACE_CORE_LIB_SRCS
uemis.c
uemis-downloader.c
linux.c
#gettextfrommoc should be added because we are using it on the c-code.
gettextfromc.cpp
)
#the interface, in C++
@ -152,7 +154,6 @@ SET(SUBSURFACE_PROFILE_LIB_SRCS
#the main app.
SET(SUBSURFACE_APP
main.cpp
gettextfromc.cpp
qt-gui.cpp
qthelper.cpp
)
@ -193,3 +194,7 @@ ENABLE_TESTING()
ADD_EXECUTABLE( TestUnitConversion tests/testunitconversion.cpp )
TARGET_LINK_LIBRARIES( TestUnitConversion ${QT_LIBRARIES})
ADD_TEST( NAME TestUnitConversion COMMAND TestUnitConversion)
ADD_EXECUTABLE( TestProfile tests/testprofile.cpp )
TARGET_LINK_LIBRARIES( TestProfile ${QT_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES} -lzip -ldivecomputer subsurface_corelib)
ADD_TEST( NAME TestProfile COMMAND TestProfile)

15
dive.c
View file

@ -2,6 +2,7 @@
/* maintains the internal dive list structure */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "gettext.h"
#include "dive.h"
@ -2188,3 +2189,17 @@ timestamp_t get_times()
}
return dive->when;
}
#define MAX_USERID_SIZE 32
void set_save_userid_local(short value)
{
prefs.save_userid_local = value;
}
void set_userid(char *rUserId)
{
prefs.userid = (char *) malloc(MAX_USERID_SIZE);
if (prefs.userid && rUserId)
strcpy(prefs.userid, rUserId);
}
#undef MAX_USERID_SIZE

3
dive.h
View file

@ -895,9 +895,6 @@ 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_local;
extern char* userid;
extern void set_save_userid_local(short value);
extern void set_userid(char* user_id);

View file

@ -861,7 +861,7 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
void try_to_fill_userid(const char *name, char *buf)
{
if (save_userid_local)
if (prefs.save_userid_local)
set_userid(buf);
}

2
pref.h
View file

@ -43,6 +43,8 @@ struct preferences {
short show_average_depth;
short zoomed_plot;
short hrgraph;
short save_userid_local;
char *userid;
};
enum unit_system_values {
METRIC,

View file

@ -313,16 +313,16 @@ void WebServices::resetState()
SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f)
{
QSettings s;
if (!save_userid_local || !*userid)
if (!prefs.save_userid_local || !*prefs.userid)
ui.userID->setText(s.value("subsurface_webservice_uid").toString().toUpper());
else
ui.userID->setText(userid);
ui.userID->setText(prefs.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);
ui.saveUidLocal->setChecked(prefs.save_userid_local);
}
void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
@ -349,7 +349,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton *button)
set_save_userid_local(qSaveUid);
if (qSaveUid) {
QString qSettingUid = s.value("subsurface_webservice_uid").toString();
QString qFileUid = QString::fromStdString(userid);
QString qFileUid = QString(prefs.userid);
bool s_eq_d = (qSettingUid == qDialogUid);
bool d_eq_f = (qDialogUid == qFileUid);
if (!d_eq_f || s_eq_d)
@ -904,20 +904,3 @@ 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);
}

View file

@ -101,8 +101,6 @@ private:
#ifdef __cplusplus
extern "C" {
#endif
extern short save_userid_local;
extern char *userid;
extern void set_save_userid_local(short value);
extern void set_userid(char *user_id);
#ifdef __cplusplus

View file

@ -681,8 +681,8 @@ static struct dir *mktree(struct dir *dir, const char *fmt, ...)
static void save_userid(void *_b)
{
struct membuffer *b = _b;
if (save_userid_local)
put_format(b, "userid %30s", userid);
if (prefs.save_userid_local)
put_format(b, "userid %30s", prefs.userid);
}
static void save_one_device(void *_b, const char *model, uint32_t deviceid,

View file

@ -508,8 +508,8 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
if (save_userid_local)
put_format(b, " <userid>%s</userid>\n", userid);
if (prefs.save_userid_local)
put_format(b, " <userid>%s</userid>\n", prefs.userid);
/* save the dive computer nicknames, if any */
call_for_each_dc(b, save_one_device);