mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Constify strings in pref.h
Make all char * pointers in pref.h const to make it clear that these strings are not mutable. This meant adding a number of (void *) casts in calls to free(). Apart from being the right thing to do, this commit makes the code more consistent, as many of the strings in pref.h were already const. While touching core/qthelper.cpp turn three instances of (void*) into (void *). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f8fcd65bc4
commit
6ae16b87d0
6 changed files with 59 additions and 58 deletions
|
@ -64,7 +64,7 @@ void CloudStorageAuthenticate::uploadFinished()
|
||||||
csSettings.setVerificationStatus(CS_NEED_TO_VERIFY);
|
csSettings.setVerificationStatus(CS_NEED_TO_VERIFY);
|
||||||
report_error(qPrintable(tr("Cloud account verification required, enter PIN in preferences")));
|
report_error(qPrintable(tr("Cloud account verification required, enter PIN in preferences")));
|
||||||
} else if (cloudAuthReply == QLatin1String("[PASSWDCHANGED]")) {
|
} else if (cloudAuthReply == QLatin1String("[PASSWDCHANGED]")) {
|
||||||
free(prefs.cloud_storage_password);
|
free((void *)prefs.cloud_storage_password);
|
||||||
prefs.cloud_storage_password = prefs.cloud_storage_newpassword;
|
prefs.cloud_storage_password = prefs.cloud_storage_newpassword;
|
||||||
prefs.cloud_storage_newpassword = NULL;
|
prefs.cloud_storage_newpassword = NULL;
|
||||||
emit passwordChangeSuccessful();
|
emit passwordChangeSuccessful();
|
||||||
|
|
|
@ -3623,11 +3623,12 @@ timestamp_t get_times()
|
||||||
|
|
||||||
void set_userid(char *rUserId)
|
void set_userid(char *rUserId)
|
||||||
{
|
{
|
||||||
|
char *userid = strdup(rUserId);
|
||||||
|
if (strlen(userid) > 30)
|
||||||
|
userid[30] = '\0';
|
||||||
if (prefs.userid)
|
if (prefs.userid)
|
||||||
free(prefs.userid);
|
free((void *)prefs.userid);
|
||||||
prefs.userid = strdup(rUserId);
|
prefs.userid = userid;
|
||||||
if (strlen(prefs.userid) > 30)
|
|
||||||
prefs.userid[30]='\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this sets a usually unused copy of the preferences with the units
|
/* this sets a usually unused copy of the preferences with the units
|
||||||
|
|
34
core/pref.h
34
core/pref.h
|
@ -22,9 +22,9 @@ typedef struct
|
||||||
} partial_pressure_graphs_t;
|
} partial_pressure_graphs_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *access_token;
|
const char *access_token;
|
||||||
char *user_id;
|
const char *user_id;
|
||||||
char *album_id;
|
const char *album_id;
|
||||||
} facebook_prefs_t;
|
} facebook_prefs_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -46,15 +46,15 @@ enum deco_mode {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool dont_check_for_updates;
|
bool dont_check_for_updates;
|
||||||
bool dont_check_exists;
|
bool dont_check_exists;
|
||||||
char *last_version_used;
|
const char *last_version_used;
|
||||||
char *next_check;
|
const char *next_check;
|
||||||
} update_manager_prefs_t;
|
} update_manager_prefs_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *vendor;
|
const char *vendor;
|
||||||
char *product;
|
const char *product;
|
||||||
char *device;
|
const char *device;
|
||||||
char *device_name;
|
const char *device_name;
|
||||||
int download_mode;
|
int download_mode;
|
||||||
} dive_computer_prefs_t;
|
} dive_computer_prefs_t;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ struct preferences {
|
||||||
short rulergraph;
|
short rulergraph;
|
||||||
short tankbar;
|
short tankbar;
|
||||||
short save_userid_local;
|
short save_userid_local;
|
||||||
char *userid;
|
const char *userid;
|
||||||
int ascrate75; // All rates in mm / sec
|
int ascrate75; // All rates in mm / sec
|
||||||
int ascrate50;
|
int ascrate50;
|
||||||
int ascratestops;
|
int ascratestops;
|
||||||
|
@ -112,11 +112,11 @@ struct preferences {
|
||||||
enum deco_mode display_deco_mode;
|
enum deco_mode display_deco_mode;
|
||||||
depth_t bestmixend;
|
depth_t bestmixend;
|
||||||
int proxy_type;
|
int proxy_type;
|
||||||
char *proxy_host;
|
const char *proxy_host;
|
||||||
int proxy_port;
|
int proxy_port;
|
||||||
short proxy_auth;
|
short proxy_auth;
|
||||||
char *proxy_user;
|
const char *proxy_user;
|
||||||
char *proxy_pass;
|
const char *proxy_pass;
|
||||||
bool doo2breaks;
|
bool doo2breaks;
|
||||||
bool drop_stone_mode;
|
bool drop_stone_mode;
|
||||||
bool last_stop; // At 6m?
|
bool last_stop; // At 6m?
|
||||||
|
@ -138,10 +138,10 @@ struct preferences {
|
||||||
bool use_default_file;
|
bool use_default_file;
|
||||||
short default_file_behavior;
|
short default_file_behavior;
|
||||||
facebook_prefs_t facebook;
|
facebook_prefs_t facebook;
|
||||||
char *cloud_storage_password;
|
const char *cloud_storage_password;
|
||||||
char *cloud_storage_newpassword;
|
const char *cloud_storage_newpassword;
|
||||||
char *cloud_storage_email;
|
const char *cloud_storage_email;
|
||||||
char *cloud_storage_email_encoded;
|
const char *cloud_storage_email_encoded;
|
||||||
bool save_password_local;
|
bool save_password_local;
|
||||||
short cloud_verification_status;
|
short cloud_verification_status;
|
||||||
bool cloud_background_sync;
|
bool cloud_background_sync;
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ int getCloudURL(QString &filename)
|
||||||
if (email.isEmpty() || same_string(prefs.cloud_storage_password, ""))
|
if (email.isEmpty() || same_string(prefs.cloud_storage_password, ""))
|
||||||
return report_error("Please configure Cloud storage email and password in the preferences");
|
return report_error("Please configure Cloud storage email and password in the preferences");
|
||||||
if (email != prefs.cloud_storage_email_encoded) {
|
if (email != prefs.cloud_storage_email_encoded) {
|
||||||
free(prefs.cloud_storage_email_encoded);
|
free((void *)prefs.cloud_storage_email_encoded);
|
||||||
prefs.cloud_storage_email_encoded = strdup(qPrintable(email));
|
prefs.cloud_storage_email_encoded = strdup(qPrintable(email));
|
||||||
}
|
}
|
||||||
filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email);
|
filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email);
|
||||||
|
|
|
@ -47,7 +47,7 @@ void DiveComputerSettings::setVendor(const QString& vendor)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("dive_computer_vendor", vendor);
|
s.setValue("dive_computer_vendor", vendor);
|
||||||
free(prefs.dive_computer.vendor);
|
free((void *)prefs.dive_computer.vendor);
|
||||||
prefs.dive_computer.vendor = copy_string(qPrintable(vendor));
|
prefs.dive_computer.vendor = copy_string(qPrintable(vendor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void DiveComputerSettings::setProduct(const QString& product)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("dive_computer_product", product);
|
s.setValue("dive_computer_product", product);
|
||||||
free(prefs.dive_computer.product);
|
free((void *)prefs.dive_computer.product);
|
||||||
prefs.dive_computer.product = copy_string(qPrintable(product));
|
prefs.dive_computer.product = copy_string(qPrintable(product));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ void DiveComputerSettings::setDevice(const QString& device)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("dive_computer_device", device);
|
s.setValue("dive_computer_device", device);
|
||||||
free(prefs.dive_computer.device);
|
free((void *)prefs.dive_computer.device);
|
||||||
prefs.dive_computer.device = copy_string(qPrintable(device));
|
prefs.dive_computer.device = copy_string(qPrintable(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void DiveComputerSettings::setDeviceName(const QString& device_name)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("dive_computer_device_name", device_name);
|
s.setValue("dive_computer_device_name", device_name);
|
||||||
free(prefs.dive_computer.device_name);
|
free((void *)prefs.dive_computer.device_name);
|
||||||
prefs.dive_computer.device_name = copy_string(qPrintable(device_name));
|
prefs.dive_computer.device_name = copy_string(qPrintable(device_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ void UpdateManagerSettings::setLastVersionUsed(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("LastVersionUsed", value);
|
s.setValue("LastVersionUsed", value);
|
||||||
free (prefs.update_manager.last_version_used);
|
free((void *)prefs.update_manager.last_version_used);
|
||||||
prefs.update_manager.last_version_used = copy_string(qPrintable(value));
|
prefs.update_manager.last_version_used = copy_string(qPrintable(value));
|
||||||
emit lastVersionUsedChanged(value);
|
emit lastVersionUsedChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ void UpdateManagerSettings::setNextCheck(const QDate& date)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("NextCheck", date);
|
s.setValue("NextCheck", date);
|
||||||
free (prefs.update_manager.next_check);
|
free((void *)prefs.update_manager.next_check);
|
||||||
prefs.update_manager.next_check = copy_string(qPrintable(date.toString("dd/MM/yyyy")));
|
prefs.update_manager.next_check = copy_string(qPrintable(date.toString("dd/MM/yyyy")));
|
||||||
emit nextCheckChanged(date);
|
emit nextCheckChanged(date);
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ void FacebookSettings::setAccessToken (const QString& value)
|
||||||
s.beginGroup(subgroup);
|
s.beginGroup(subgroup);
|
||||||
s.setValue("ConnectToken", value);
|
s.setValue("ConnectToken", value);
|
||||||
#endif
|
#endif
|
||||||
free(prefs.facebook.access_token);
|
free((void *)prefs.facebook.access_token);
|
||||||
prefs.facebook.access_token = copy_string(qPrintable(value));
|
prefs.facebook.access_token = copy_string(qPrintable(value));
|
||||||
emit accessTokenChanged(value);
|
emit accessTokenChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -763,7 +763,7 @@ void FacebookSettings::setUserId(const QString& value)
|
||||||
s.beginGroup(subgroup);
|
s.beginGroup(subgroup);
|
||||||
s.setValue("UserId", value);
|
s.setValue("UserId", value);
|
||||||
#endif
|
#endif
|
||||||
free(prefs.facebook.user_id);
|
free((void *)prefs.facebook.user_id);
|
||||||
prefs.facebook.user_id = copy_string(qPrintable(value));
|
prefs.facebook.user_id = copy_string(qPrintable(value));
|
||||||
emit userIdChanged(value);
|
emit userIdChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,7 @@ void FacebookSettings::setAlbumId(const QString& value)
|
||||||
s.beginGroup(subgroup);
|
s.beginGroup(subgroup);
|
||||||
s.setValue("AlbumId", value);
|
s.setValue("AlbumId", value);
|
||||||
#endif
|
#endif
|
||||||
free(prefs.facebook.album_id);
|
free((void *)prefs.facebook.album_id);
|
||||||
prefs.facebook.album_id = copy_string(qPrintable(value));
|
prefs.facebook.album_id = copy_string(qPrintable(value));
|
||||||
emit albumIdChanged(value);
|
emit albumIdChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -891,7 +891,7 @@ void ProxySettings::setHost(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("proxy_host", value);
|
s.setValue("proxy_host", value);
|
||||||
free(prefs.proxy_host);
|
free((void *)prefs.proxy_host);
|
||||||
prefs.proxy_host = copy_string(qPrintable(value));
|
prefs.proxy_host = copy_string(qPrintable(value));
|
||||||
emit hostChanged(value);
|
emit hostChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -925,7 +925,7 @@ void ProxySettings::setUser(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("proxy_user", value);
|
s.setValue("proxy_user", value);
|
||||||
free(prefs.proxy_user);
|
free((void *)prefs.proxy_user);
|
||||||
prefs.proxy_user = copy_string(qPrintable(value));
|
prefs.proxy_user = copy_string(qPrintable(value));
|
||||||
emit userChanged(value);
|
emit userChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -937,7 +937,7 @@ void ProxySettings::setPass(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("proxy_pass", value);
|
s.setValue("proxy_pass", value);
|
||||||
free(prefs.proxy_pass);
|
free((void *)prefs.proxy_pass);
|
||||||
prefs.proxy_pass = copy_string(qPrintable(value));
|
prefs.proxy_pass = copy_string(qPrintable(value));
|
||||||
emit passChanged(value);
|
emit passChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1010,7 @@ void CloudStorageSettings::setPassword(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("password", value);
|
s.setValue("password", value);
|
||||||
free(prefs.cloud_storage_password);
|
free((void *)prefs.cloud_storage_password);
|
||||||
prefs.cloud_storage_password = copy_string(qPrintable(value));
|
prefs.cloud_storage_password = copy_string(qPrintable(value));
|
||||||
emit passwordChanged(value);
|
emit passwordChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -1020,7 +1020,7 @@ void CloudStorageSettings::setNewPassword(const QString& value)
|
||||||
if (value == prefs.cloud_storage_newpassword)
|
if (value == prefs.cloud_storage_newpassword)
|
||||||
return;
|
return;
|
||||||
/*TODO: This looks like wrong, but 'new password' is not saved on disk, why it's on prefs? */
|
/*TODO: This looks like wrong, but 'new password' is not saved on disk, why it's on prefs? */
|
||||||
free(prefs.cloud_storage_newpassword);
|
free((void *)prefs.cloud_storage_newpassword);
|
||||||
prefs.cloud_storage_newpassword = copy_string(qPrintable(value));
|
prefs.cloud_storage_newpassword = copy_string(qPrintable(value));
|
||||||
emit newPasswordChanged(value);
|
emit newPasswordChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1032,7 @@ void CloudStorageSettings::setEmail(const QString& value)
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(group);
|
s.beginGroup(group);
|
||||||
s.setValue("email", value);
|
s.setValue("email", value);
|
||||||
free(prefs.cloud_storage_email);
|
free((void *)prefs.cloud_storage_email);
|
||||||
prefs.cloud_storage_email = copy_string(qPrintable(value));
|
prefs.cloud_storage_email = copy_string(qPrintable(value));
|
||||||
emit emailChanged(value);
|
emit emailChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -1044,7 +1044,7 @@ void CloudStorageSettings::setUserId(const QString& value)
|
||||||
//WARNING: UserId is stored outside of any group, but it belongs to Cloud Storage.
|
//WARNING: UserId is stored outside of any group, but it belongs to Cloud Storage.
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.setValue("subsurface_webservice_uid", value);
|
s.setValue("subsurface_webservice_uid", value);
|
||||||
free(prefs.userid);
|
free((void *)prefs.userid);
|
||||||
prefs.userid = copy_string(qPrintable(value));
|
prefs.userid = copy_string(qPrintable(value));
|
||||||
emit userIdChanged(value);
|
emit userIdChanged(value);
|
||||||
}
|
}
|
||||||
|
@ -1054,7 +1054,7 @@ void CloudStorageSettings::setEmailEncoded(const QString& value)
|
||||||
if (value == prefs.cloud_storage_email_encoded)
|
if (value == prefs.cloud_storage_email_encoded)
|
||||||
return;
|
return;
|
||||||
/*TODO: This looks like wrong, but 'email encoded' is not saved on disk, why it's on prefs? */
|
/*TODO: This looks like wrong, but 'email encoded' is not saved on disk, why it's on prefs? */
|
||||||
free(prefs.cloud_storage_email_encoded);
|
free((void *)prefs.cloud_storage_email_encoded);
|
||||||
prefs.cloud_storage_email_encoded = copy_string(qPrintable(value));
|
prefs.cloud_storage_email_encoded = copy_string(qPrintable(value));
|
||||||
emit emailEncodedChanged(value);
|
emit emailEncodedChanged(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ void QMLManager::saveCloudCredentials()
|
||||||
s.setValue("cloud_verification_status", credentialStatus());
|
s.setValue("cloud_verification_status", credentialStatus());
|
||||||
s.sync();
|
s.sync();
|
||||||
if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUser))) {
|
if (!same_string(prefs.cloud_storage_email, qPrintable(cloudUser))) {
|
||||||
free(prefs.cloud_storage_email);
|
free((void *)prefs.cloud_storage_email);
|
||||||
prefs.cloud_storage_email = strdup(qPrintable(cloudUser));
|
prefs.cloud_storage_email = strdup(qPrintable(cloudUser));
|
||||||
cloudCredentialsChanged = true;
|
cloudCredentialsChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ void QMLManager::saveCloudCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPwd))) {
|
if (!same_string(prefs.cloud_storage_password, qPrintable(cloudPwd))) {
|
||||||
free(prefs.cloud_storage_password);
|
free((void *)prefs.cloud_storage_password);
|
||||||
prefs.cloud_storage_password = strdup(qPrintable(cloudPwd));
|
prefs.cloud_storage_password = strdup(qPrintable(cloudPwd));
|
||||||
}
|
}
|
||||||
if (cloudUser.isEmpty() || cloudPwd.isEmpty()) {
|
if (cloudUser.isEmpty() || cloudPwd.isEmpty()) {
|
||||||
|
@ -404,7 +404,7 @@ void QMLManager::saveCloudCredentials()
|
||||||
} else if (cloudCredentialsChanged) {
|
} else if (cloudCredentialsChanged) {
|
||||||
// let's make sure there are no unsaved changes
|
// let's make sure there are no unsaved changes
|
||||||
saveChangesLocal();
|
saveChangesLocal();
|
||||||
free(prefs.userid);
|
free((void *)prefs.userid);
|
||||||
prefs.userid = NULL;
|
prefs.userid = NULL;
|
||||||
syncLoadFromCloud();
|
syncLoadFromCloud();
|
||||||
QString url;
|
QString url;
|
||||||
|
@ -550,7 +550,7 @@ void QMLManager::retrieveUserid()
|
||||||
}
|
}
|
||||||
if (!userid.isEmpty()) {
|
if (!userid.isEmpty()) {
|
||||||
// overwrite the existing userid
|
// overwrite the existing userid
|
||||||
free(prefs.userid);
|
free((void *)prefs.userid);
|
||||||
prefs.userid = strdup(qPrintable(userid));
|
prefs.userid = strdup(qPrintable(userid));
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.setValue("subsurface_webservice_uid", prefs.userid);
|
s.setValue("subsurface_webservice_uid", prefs.userid);
|
||||||
|
@ -649,9 +649,9 @@ void QMLManager::revertToNoCloudIfNeeded()
|
||||||
appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed"));
|
appendTextToLog(QStringLiteral("taking things back offline since sync with cloud failed"));
|
||||||
prefs.git_local_only = syncToCloud();
|
prefs.git_local_only = syncToCloud();
|
||||||
}
|
}
|
||||||
free(prefs.cloud_storage_email);
|
free((void *)prefs.cloud_storage_email);
|
||||||
prefs.cloud_storage_email = NULL;
|
prefs.cloud_storage_email = NULL;
|
||||||
free(prefs.cloud_storage_password);
|
free((void *)prefs.cloud_storage_password);
|
||||||
prefs.cloud_storage_password = NULL;
|
prefs.cloud_storage_password = NULL;
|
||||||
setCloudUserName("");
|
setCloudUserName("");
|
||||||
setCloudPassword("");
|
setCloudPassword("");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue