Cleanup: introduce copy_qstring() function

strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-02-28 23:37:09 +01:00 committed by Lubomir I. Ivanov
parent b72cc1f317
commit d1572a8d95
19 changed files with 116 additions and 108 deletions

View file

@ -2,6 +2,7 @@
/* implements Android specific functions */ /* implements Android specific functions */
#include "dive.h" #include "dive.h"
#include "display.h" #include "display.h"
#include "qthelper.h"
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
@ -52,7 +53,7 @@ static const char *system_default_path_append(const char *append)
if (append) if (append)
path += QString("/%1").arg(append); path += QString("/%1").arg(append);
return strdup(qPrintable(path)); return copy_qstring(path);
} }
const char *system_default_directory(void) const char *system_default_directory(void)

View file

@ -95,7 +95,7 @@ void ReverseGeoLookupThread::run()
ds->taxonomy.category[ri].category = j; ds->taxonomy.category[ri].category = j;
ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCODED; ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCODED;
free((void *)ds->taxonomy.category[ri].value); free((void *)ds->taxonomy.category[ri].value);
ds->taxonomy.category[ri].value = copy_string(qPrintable(firstData[taxonomy_api_names[j]].toString())); ds->taxonomy.category[ri].value = copy_qstring(firstData[taxonomy_api_names[j]].toString());
ri++; ri++;
} }
} }
@ -156,7 +156,7 @@ void ReverseGeoLookupThread::run()
if (idx < TC_NR_CATEGORIES) { if (idx < TC_NR_CATEGORIES) {
ds->taxonomy.category[idx].category = TC_OCEAN; ds->taxonomy.category[idx].category = TC_OCEAN;
ds->taxonomy.category[idx].origin = taxonomy_origin::GEOCODED; ds->taxonomy.category[idx].origin = taxonomy_origin::GEOCODED;
ds->taxonomy.category[idx].value = copy_string(qPrintable(oceanName["name"].toString())); ds->taxonomy.category[idx].value = copy_qstring(oceanName["name"].toString());
if (idx == ds->taxonomy.nr) if (idx == ds->taxonomy.nr)
ds->taxonomy.nr++; ds->taxonomy.nr++;
} }

View file

@ -1,5 +1,6 @@
#include "downloadfromdcthread.h" #include "downloadfromdcthread.h"
#include "core/libdivecomputer.h" #include "core/libdivecomputer.h"
#include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/subsurface-qt/SettingsObjectWrapper.h"
#include <QDebug> #include <QDebug>
#include <QRegularExpression> #include <QRegularExpression>
@ -281,12 +282,12 @@ int DCDeviceData::diveId() const
void DCDeviceData::setVendor(const QString& vendor) void DCDeviceData::setVendor(const QString& vendor)
{ {
data.vendor = strdup(qPrintable(vendor)); data.vendor = copy_qstring(vendor);
} }
void DCDeviceData::setProduct(const QString& product) void DCDeviceData::setProduct(const QString& product)
{ {
data.product = strdup(qPrintable(product)); data.product = copy_qstring(product);
} }
void DCDeviceData::setDevName(const QString& devName) void DCDeviceData::setDevName(const QString& devName)
@ -303,11 +304,11 @@ void DCDeviceData::setDevName(const QString& devName)
QString back = devName.mid(idx1 + 1, idx2 - idx1 - 1); QString back = devName.mid(idx1 + 1, idx2 - idx1 - 1);
QString newDevName = back.indexOf(':') >= 0 ? back : front; QString newDevName = back.indexOf(':') >= 0 ? back : front;
qWarning() << "Found invalid bluetooth device" << devName << "corrected to" << newDevName << "."; qWarning() << "Found invalid bluetooth device" << devName << "corrected to" << newDevName << ".";
data.devname = strdup(qPrintable(newDevName)); data.devname = copy_qstring(newDevName);
return; return;
} }
} }
data.devname = strdup(qPrintable(devName)); data.devname = copy_qstring(devName);
} }
void DCDeviceData::setDevBluetoothName(const QString& name) void DCDeviceData::setDevBluetoothName(const QString& name)

View file

@ -2,6 +2,8 @@
#ifndef PREFSMACROS_H #ifndef PREFSMACROS_H
#define PREFSMACROS_H #define PREFSMACROS_H
#include "core/qthelper.h"
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0)) #define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
#define GET_UNIT(name, field, f, t) \ #define GET_UNIT(name, field, f, t) \
@ -60,11 +62,11 @@
else \ else \
prefs.field = defval prefs.field = defval
#define GET_TXT(name, field) \ #define GET_TXT(name, field) \
v = s.value(QString(name)); \ v = s.value(QString(name)); \
if (v.isValid()) \ if (v.isValid()) \
prefs.field = strdup(qPrintable(v.toString())); \ prefs.field = copy_qstring(v.toString()); \
else \ else \
prefs.field = copy_string(default_prefs.field) prefs.field = copy_string(default_prefs.field)
#define SAVE_OR_REMOVE_SPECIAL(_setting, _default, _compare, _value) \ #define SAVE_OR_REMOVE_SPECIAL(_setting, _default, _compare, _value) \

View file

@ -99,7 +99,7 @@ extern "C" const char *printGPSCoords(int lat, int lon)
} else { } else {
result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0); result.sprintf("%f %f", (double) lat / 1000000.0, (double) lon / 1000000.0);
} }
return strdup(qPrintable(result)); return copy_qstring(result);
} }
/** /**
@ -387,13 +387,13 @@ extern "C" char *move_away(const char *old_path)
#endif #endif
return strdup(""); return strdup("");
} }
return strdup(qPrintable(newPath)); return copy_qstring(newPath);
} }
extern "C" char *get_file_name(const char *fileName) extern "C" char *get_file_name(const char *fileName)
{ {
QFileInfo fileInfo(fileName); QFileInfo fileInfo(fileName);
return strdup(fileInfo.fileName().toUtf8()); return copy_qstring(fileInfo.fileName());
} }
extern "C" void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName) extern "C" void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName)
@ -473,7 +473,7 @@ extern "C" const char *subsurface_user_agent()
{ {
static QString uA = getUserAgent(); static QString uA = getUserAgent();
return strdup(qPrintable(uA)); return copy_qstring(uA);
} }
/* TOOD: Move this to SettingsObjectWrapper, and also fix this complexity. /* TOOD: Move this to SettingsObjectWrapper, and also fix this complexity.
@ -504,7 +504,7 @@ QString uiLanguage(QLocale *callerLoc)
uiLang = languages[2]; uiLang = languages[2];
else else
uiLang = languages[0]; uiLang = languages[0];
prefs.locale.lang_locale = copy_string(qPrintable(uiLang)); prefs.locale.lang_locale = copy_qstring(uiLang);
GET_BOOL("time_format_override", time_format_override); GET_BOOL("time_format_override", time_format_override);
GET_BOOL("date_format_override", date_format_override); GET_BOOL("date_format_override", date_format_override);
GET_TXT("time_format", time_format); GET_TXT("time_format", time_format);
@ -540,11 +540,11 @@ QString uiLanguage(QLocale *callerLoc)
dateFormat.replace("'en' 'den' d:'e'", " d"); dateFormat.replace("'en' 'den' d:'e'", " d");
if (!prefs.date_format_override || empty_string(prefs.date_format)) { if (!prefs.date_format_override || empty_string(prefs.date_format)) {
free((void *)prefs.date_format); free((void *)prefs.date_format);
prefs.date_format = strdup(qPrintable(dateFormat)); prefs.date_format = copy_qstring(dateFormat);
} }
if (!prefs.date_format_override || empty_string(prefs.date_format_short)) { if (!prefs.date_format_override || empty_string(prefs.date_format_short)) {
free((void *)prefs.date_format_short); free((void *)prefs.date_format_short);
prefs.date_format_short = strdup(qPrintable(shortDateFormat)); prefs.date_format_short = copy_qstring(shortDateFormat);
} }
} }
if (!prefs.time_format_override || empty_string(prefs.time_format)) { if (!prefs.time_format_override || empty_string(prefs.time_format)) {
@ -552,7 +552,7 @@ QString uiLanguage(QLocale *callerLoc)
timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", "");
timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", "");
free((void *)prefs.time_format); free((void *)prefs.time_format);
prefs.time_format = strdup(qPrintable(timeFormat)); prefs.time_format = copy_qstring(timeFormat);
} }
return uiLang; return uiLang;
} }
@ -998,7 +998,7 @@ QString get_short_dive_date_string(timestamp_t when)
const char *get_dive_date_c_string(timestamp_t when) const char *get_dive_date_c_string(timestamp_t when)
{ {
QString text = get_dive_date_string(when); QString text = get_dive_date_string(when);
return strdup(qPrintable(text)); return copy_qstring(text);
} }
extern "C" const char *get_current_date() extern "C" const char *get_current_date()
@ -1008,7 +1008,7 @@ extern "C" const char *get_current_date()
current_date = loc.toString(ts, QString(prefs.date_format_short)); current_date = loc.toString(ts, QString(prefs.date_format_short));
return strdup(qPrintable(current_date)); return copy_qstring(current_date);
} }
bool is_same_day(timestamp_t trip_when, timestamp_t dive_when) bool is_same_day(timestamp_t trip_when, timestamp_t dive_when)
@ -1098,7 +1098,7 @@ const QString hashfile_name()
extern "C" char *hashfile_name_string() extern "C" char *hashfile_name_string()
{ {
return strdup(qPrintable(hashfile_name())); return copy_qstring(hashfile_name());
} }
void read_hashes() void read_hashes()
@ -1247,7 +1247,7 @@ void learnImages(const QDir dir, int max_recursions)
extern "C" const char *local_file_path(struct picture *picture) extern "C" const char *local_file_path(struct picture *picture)
{ {
return strdup(qPrintable(localFilePath(picture->filename))); return copy_qstring(localFilePath(picture->filename));
} }
extern "C" bool picture_exists(struct picture *picture) extern "C" bool picture_exists(struct picture *picture)
@ -1266,7 +1266,7 @@ const QString picturedir()
extern "C" char *picturedir_string() extern "C" char *picturedir_string()
{ {
return strdup(qPrintable(picturedir())); return copy_qstring(picturedir());
} }
/* when we get a picture from git storage (local or remote) and can't find the picture /* when we get a picture from git storage (local or remote) and can't find the picture
@ -1446,7 +1446,7 @@ int getCloudURL(QString &filename)
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((void *)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 = copy_qstring(email);
} }
filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email); filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email);
if (verbose) if (verbose)
@ -1458,7 +1458,7 @@ extern "C" char *cloud_url()
{ {
QString filename; QString filename;
getCloudURL(filename); getCloudURL(filename);
return strdup(qPrintable(filename)); return copy_qstring(filename);
} }
extern "C" bool getProxyString(char **buffer) extern "C" bool getProxyString(char **buffer)
@ -1471,7 +1471,7 @@ extern "C" bool getProxyString(char **buffer)
else else
proxy = QString("http://%1:%2").arg(prefs.proxy_host).arg(prefs.proxy_port); proxy = QString("http://%1:%2").arg(prefs.proxy_host).arg(prefs.proxy_port);
if (buffer) if (buffer)
*buffer = strdup(qPrintable(proxy)); *buffer = copy_qstring(proxy);
return true; return true;
} }
return false; return false;
@ -1558,7 +1558,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//DIVE NR: ")) { if (parseLine.contains("//DIVE NR: ")) {
params[pnr++] = strdup("diveNro"); params[pnr++] = strdup("diveNro");
params[pnr++] = strdup(qPrintable(parseLine.replace(QString::fromLatin1("//DIVE NR: "), QString::fromLatin1("")))); params[pnr++] = copy_qstring(parseLine.replace(QString::fromLatin1("//DIVE NR: "), QString::fromLatin1("")));
break; break;
} }
} }
@ -1573,7 +1573,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//Hardware Version: ")) { if (parseLine.contains("//Hardware Version: ")) {
params[pnr++] = strdup("hw"); params[pnr++] = strdup("hw");
params[pnr++] = strdup(qPrintable(parseLine.replace(QString::fromLatin1("//Hardware Version: "), QString::fromLatin1("\"Seabear ")).trimmed().append("\""))); params[pnr++] = copy_qstring(parseLine.replace(QString::fromLatin1("//Hardware Version: "), QString::fromLatin1("\"Seabear ")).trimmed().append("\""));
break; break;
} }
} }
@ -1586,7 +1586,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) {
if (parseLine.contains("//Log interval: ")) { if (parseLine.contains("//Log interval: ")) {
params[pnr++] = strdup("delta"); params[pnr++] = strdup("delta");
params[pnr++] = strdup(qPrintable(parseLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s")))); params[pnr++] = copy_qstring(parseLine.remove(QString::fromLatin1("//Log interval: ")).trimmed().remove(QString::fromLatin1(" s")));
break; break;
} }
} }
@ -1601,7 +1601,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
QString needle = "//Mode: "; QString needle = "//Mode: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("diveMode"); params[pnr++] = strdup("diveMode");
params[pnr++] = strdup(qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""))); params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""));
} }
} }
f.seek(0); f.seek(0);
@ -1614,7 +1614,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
QString needle = "//Firmware Version: "; QString needle = "//Firmware Version: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("Firmware"); params[pnr++] = strdup("Firmware");
params[pnr++] = strdup(qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""))); params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""));
} }
} }
f.seek(0); f.seek(0);
@ -1623,7 +1623,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
QString needle = "//Serial number: "; QString needle = "//Serial number: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("Serial"); params[pnr++] = strdup("Serial");
params[pnr++] = strdup(qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""))); params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""));
} }
} }
f.seek(0); f.seek(0);
@ -1632,7 +1632,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr)
QString needle = "//GF: "; QString needle = "//GF: ";
if (parseLine.contains(needle)) { if (parseLine.contains(needle)) {
params[pnr++] = strdup("GF"); params[pnr++] = strdup("GF");
params[pnr++] = strdup(qPrintable(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""))); params[pnr++] = copy_qstring(parseLine.replace(needle, QString::fromLatin1("")).prepend("\"").append("\""));
} }
} }
f.seek(0); f.seek(0);
@ -2143,3 +2143,8 @@ extern "C" void put_vformat_loc(struct membuffer *b, const char *fmt, va_list ar
memcpy(b->buffer + b->len, data, utf8_size); memcpy(b->buffer + b->len, data, utf8_size);
b->len += utf8_size; b->len += utf8_size;
} }
char *copy_qstring(const QString &s)
{
return strdup(qPrintable(s));
}

View file

@ -54,9 +54,9 @@ void init_proxy();
QString getUUID(); QString getUUID();
QStringList imageExtensionFilters(); QStringList imageExtensionFilters();
char *intdup(int index); char *intdup(int index);
char *copy_qstring(const QString &);
__printf(1, 2) QString asprintf_loc(const char *cformat, ...); __printf(1, 2) QString asprintf_loc(const char *cformat, ...);
__printf(1, 0) QString vasprintf_loc(const char *cformat, va_list ap); __printf(1, 0) QString vasprintf_loc(const char *cformat, va_list ap);
#endif #endif
// 3) Functions visible to C and C++ // 3) Functions visible to C and C++

View file

@ -6,7 +6,6 @@
#include <QDate> #include <QDate>
#include <QNetworkProxy> #include <QNetworkProxy>
#include "core/dive.h" // TODO: remove copy_string from dive.h
#include "core/helpers.h" #include "core/helpers.h"
DiveComputerSettings::DiveComputerSettings(QObject *parent): DiveComputerSettings::DiveComputerSettings(QObject *parent):
@ -48,7 +47,7 @@ void DiveComputerSettings::setVendor(const QString& vendor)
s.beginGroup(group); s.beginGroup(group);
s.setValue("dive_computer_vendor", vendor); s.setValue("dive_computer_vendor", vendor);
free((void *)prefs.dive_computer.vendor); free((void *)prefs.dive_computer.vendor);
prefs.dive_computer.vendor = copy_string(qPrintable(vendor)); prefs.dive_computer.vendor = copy_qstring(vendor);
} }
void DiveComputerSettings::setProduct(const QString& product) void DiveComputerSettings::setProduct(const QString& product)
@ -60,7 +59,7 @@ void DiveComputerSettings::setProduct(const QString& product)
s.beginGroup(group); s.beginGroup(group);
s.setValue("dive_computer_product", product); s.setValue("dive_computer_product", product);
free((void *)prefs.dive_computer.product); free((void *)prefs.dive_computer.product);
prefs.dive_computer.product = copy_string(qPrintable(product)); prefs.dive_computer.product = copy_qstring(product);
} }
void DiveComputerSettings::setDevice(const QString& device) void DiveComputerSettings::setDevice(const QString& device)
@ -72,7 +71,7 @@ void DiveComputerSettings::setDevice(const QString& device)
s.beginGroup(group); s.beginGroup(group);
s.setValue("dive_computer_device", device); s.setValue("dive_computer_device", device);
free((void *)prefs.dive_computer.device); free((void *)prefs.dive_computer.device);
prefs.dive_computer.device = copy_string(qPrintable(device)); prefs.dive_computer.device = copy_qstring(device);
} }
void DiveComputerSettings::setDeviceName(const QString& device_name) void DiveComputerSettings::setDeviceName(const QString& device_name)
@ -84,7 +83,7 @@ void DiveComputerSettings::setDeviceName(const QString& device_name)
s.beginGroup(group); s.beginGroup(group);
s.setValue("dive_computer_device_name", device_name); s.setValue("dive_computer_device_name", device_name);
free((void *)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_qstring(device_name);
} }
void DiveComputerSettings::setDownloadMode(int mode) void DiveComputerSettings::setDownloadMode(int mode)
@ -145,7 +144,7 @@ void UpdateManagerSettings::setLastVersionUsed(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("LastVersionUsed", value); s.setValue("LastVersionUsed", value);
free((void *)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_qstring(value);
emit lastVersionUsedChanged(value); emit lastVersionUsedChanged(value);
} }
@ -158,7 +157,7 @@ void UpdateManagerSettings::setNextCheck(const QDate& date)
s.beginGroup(group); s.beginGroup(group);
s.setValue("NextCheck", date); s.setValue("NextCheck", date);
free((void *)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_qstring(date.toString("dd/MM/yyyy"));
emit nextCheckChanged(date); emit nextCheckChanged(date);
} }
@ -765,7 +764,7 @@ void FacebookSettings::setAccessToken (const QString& value)
s.setValue("ConnectToken", value); s.setValue("ConnectToken", value);
#endif #endif
free((void *)prefs.facebook.access_token); free((void *)prefs.facebook.access_token);
prefs.facebook.access_token = copy_string(qPrintable(value)); prefs.facebook.access_token = copy_qstring(value);
emit accessTokenChanged(value); emit accessTokenChanged(value);
} }
@ -780,7 +779,7 @@ void FacebookSettings::setUserId(const QString& value)
s.setValue("UserId", value); s.setValue("UserId", value);
#endif #endif
free((void *)prefs.facebook.user_id); free((void *)prefs.facebook.user_id);
prefs.facebook.user_id = copy_string(qPrintable(value)); prefs.facebook.user_id = copy_qstring(value);
emit userIdChanged(value); emit userIdChanged(value);
} }
@ -795,7 +794,7 @@ void FacebookSettings::setAlbumId(const QString& value)
s.setValue("AlbumId", value); s.setValue("AlbumId", value);
#endif #endif
free((void *)prefs.facebook.album_id); free((void *)prefs.facebook.album_id);
prefs.facebook.album_id = copy_string(qPrintable(value)); prefs.facebook.album_id = copy_qstring(value);
emit albumIdChanged(value); emit albumIdChanged(value);
} }
@ -908,7 +907,7 @@ void ProxySettings::setHost(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("proxy_host", value); s.setValue("proxy_host", value);
free((void *)prefs.proxy_host); free((void *)prefs.proxy_host);
prefs.proxy_host = copy_string(qPrintable(value)); prefs.proxy_host = copy_qstring(value);
emit hostChanged(value); emit hostChanged(value);
} }
@ -942,7 +941,7 @@ void ProxySettings::setUser(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("proxy_user", value); s.setValue("proxy_user", value);
free((void *)prefs.proxy_user); free((void *)prefs.proxy_user);
prefs.proxy_user = copy_string(qPrintable(value)); prefs.proxy_user = copy_qstring(value);
emit userChanged(value); emit userChanged(value);
} }
@ -954,7 +953,7 @@ void ProxySettings::setPass(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("proxy_pass", value); s.setValue("proxy_pass", value);
free((void *)prefs.proxy_pass); free((void *)prefs.proxy_pass);
prefs.proxy_pass = copy_string(qPrintable(value)); prefs.proxy_pass = copy_qstring(value);
emit passChanged(value); emit passChanged(value);
} }
@ -1022,7 +1021,7 @@ void CloudStorageSettings::setPassword(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("password", value); s.setValue("password", value);
free((void *)prefs.cloud_storage_password); free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = copy_string(qPrintable(value)); prefs.cloud_storage_password = copy_qstring(value);
emit passwordChanged(value); emit passwordChanged(value);
} }
@ -1032,7 +1031,7 @@ void CloudStorageSettings::setNewPassword(const QString& value)
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((void *)prefs.cloud_storage_newpassword); free((void *)prefs.cloud_storage_newpassword);
prefs.cloud_storage_newpassword = copy_string(qPrintable(value)); prefs.cloud_storage_newpassword = copy_qstring(value);
emit newPasswordChanged(value); emit newPasswordChanged(value);
} }
@ -1044,7 +1043,7 @@ void CloudStorageSettings::setEmail(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("email", value); s.setValue("email", value);
free((void *)prefs.cloud_storage_email); free((void *)prefs.cloud_storage_email);
prefs.cloud_storage_email = copy_string(qPrintable(value)); prefs.cloud_storage_email = copy_qstring(value);
emit emailChanged(value); emit emailChanged(value);
} }
@ -1056,7 +1055,7 @@ void CloudStorageSettings::setUserId(const QString& value)
QSettings s; QSettings s;
s.setValue("subsurface_webservice_uid", value); s.setValue("subsurface_webservice_uid", value);
free((void *)prefs.userid); free((void *)prefs.userid);
prefs.userid = copy_string(qPrintable(value)); prefs.userid = copy_qstring(value);
emit userIdChanged(value); emit userIdChanged(value);
} }
@ -1066,7 +1065,7 @@ void CloudStorageSettings::setEmailEncoded(const QString& value)
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((void *)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_qstring(value);
emit emailEncodedChanged(value); emit emailEncodedChanged(value);
} }
@ -1119,8 +1118,8 @@ void CloudStorageSettings::setBaseUrl(const QString& value)
QSettings s; QSettings s;
s.beginGroup(group); s.beginGroup(group);
s.setValue("cloud_base_url", value); s.setValue("cloud_base_url", value);
prefs.cloud_base_url = copy_string(qPrintable(value)); prefs.cloud_base_url = copy_qstring(value);
prefs.cloud_git_url = copy_string(qPrintable(QString(prefs.cloud_base_url) + "/git")); prefs.cloud_git_url = copy_qstring(QString(prefs.cloud_base_url) + "/git");
} }
void CloudStorageSettings::setGitUrl(const QString& value) void CloudStorageSettings::setGitUrl(const QString& value)
@ -1796,7 +1795,7 @@ void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("default_filename", value); s.setValue("default_filename", value);
free((void *)prefs.default_filename); free((void *)prefs.default_filename);
prefs.default_filename = copy_string(qPrintable(value)); prefs.default_filename = copy_qstring(value);
emit defaultFilenameChanged(value); emit defaultFilenameChanged(value);
} }
@ -1809,7 +1808,7 @@ void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("default_cylinder", value); s.setValue("default_cylinder", value);
free((void *)prefs.default_cylinder); free((void *)prefs.default_cylinder);
prefs.default_cylinder = copy_string(qPrintable(value)); prefs.default_cylinder = copy_qstring(value);
emit defaultCylinderChanged(value); emit defaultCylinderChanged(value);
} }
@ -1916,7 +1915,7 @@ void DisplaySettingsObjectWrapper::setDivelistFont(const QString& value)
if (!subsurface_ignore_font(qPrintable(newValue))) { if (!subsurface_ignore_font(qPrintable(newValue))) {
free((void *)prefs.divelist_font); free((void *)prefs.divelist_font);
prefs.divelist_font = strdup(qPrintable(newValue)); prefs.divelist_font = copy_qstring(newValue);
qApp->setFont(QFont(newValue)); qApp->setFont(QFont(newValue));
} }
emit divelistFontChanged(newValue); emit divelistFontChanged(newValue);
@ -2013,7 +2012,7 @@ void LanguageSettingsObjectWrapper::setLangLocale(const QString &value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("UiLangLocale", value); s.setValue("UiLangLocale", value);
free((void *)prefs.locale.lang_locale); free((void *)prefs.locale.lang_locale);
prefs.locale.lang_locale = copy_string(qPrintable(value)); prefs.locale.lang_locale = copy_qstring(value);
emit langLocaleChanged(value); emit langLocaleChanged(value);
} }
@ -2025,7 +2024,7 @@ void LanguageSettingsObjectWrapper::setLanguage(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("UiLanguage", value); s.setValue("UiLanguage", value);
free((void *)prefs.locale.language); free((void *)prefs.locale.language);
prefs.locale.language = copy_string(qPrintable(value)); prefs.locale.language = copy_qstring(value);
emit languageChanged(value); emit languageChanged(value);
} }
@ -2037,7 +2036,7 @@ void LanguageSettingsObjectWrapper::setTimeFormat(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("time_format", value); s.setValue("time_format", value);
free((void *)prefs.time_format); free((void *)prefs.time_format);
prefs.time_format = copy_string(qPrintable(value)); prefs.time_format = copy_qstring(value);
emit timeFormatChanged(value); emit timeFormatChanged(value);
} }
@ -2050,7 +2049,7 @@ void LanguageSettingsObjectWrapper::setDateFormat(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("date_format", value); s.setValue("date_format", value);
free((void *)prefs.date_format); free((void *)prefs.date_format);
prefs.date_format = copy_string(qPrintable(value)); prefs.date_format = copy_qstring(value);
emit dateFormatChanged(value); emit dateFormatChanged(value);
} }
@ -2063,7 +2062,7 @@ void LanguageSettingsObjectWrapper::setDateFormatShort(const QString& value)
s.beginGroup(group); s.beginGroup(group);
s.setValue("date_format_short", value); s.setValue("date_format_short", value);
free((void *)prefs.date_format_short); free((void *)prefs.date_format_short);
prefs.date_format_short = copy_string(qPrintable(value)); prefs.date_format_short = copy_qstring(value);
emit dateFormatShortChanged(value); emit dateFormatShortChanged(value);
} }
@ -2269,7 +2268,7 @@ void SettingsObjectWrapper::load()
defaultFont = QFont(prefs.divelist_font); defaultFont = QFont(prefs.divelist_font);
} else { } else {
free((void *)prefs.divelist_font); free((void *)prefs.divelist_font);
prefs.divelist_font = strdup(qPrintable(fontName)); prefs.divelist_font = copy_qstring(fontName);
} }
defaultFont.setPointSizeF(prefs.font_size); defaultFont.setPointSizeF(prefs.font_size);
qApp->setFont(defaultFont); qApp->setFont(defaultFont);
@ -2306,7 +2305,7 @@ void SettingsObjectWrapper::load()
// creating the git url here is simply a convenience when C code wants // creating the git url here is simply a convenience when C code wants
// to compare against that git URL - it's always derived from the base URL // to compare against that git URL - it's always derived from the base URL
GET_TXT("cloud_base_url", cloud_base_url); GET_TXT("cloud_base_url", cloud_base_url);
prefs.cloud_git_url = strdup(qPrintable(QString(prefs.cloud_base_url) + "/git")); prefs.cloud_git_url = copy_qstring(QString(prefs.cloud_base_url) + "/git");
s.endGroup(); s.endGroup();
// Subsurface webservice id is stored outside of the groups // Subsurface webservice id is stored outside of the groups
@ -2368,7 +2367,7 @@ void SettingsObjectWrapper::load()
prefs.update_manager.dont_check_exists = s.contains("DontCheckForUpdates"); prefs.update_manager.dont_check_exists = s.contains("DontCheckForUpdates");
GET_BOOL("DontCheckForUpdates", update_manager.dont_check_for_updates); GET_BOOL("DontCheckForUpdates", update_manager.dont_check_for_updates);
GET_TXT("LastVersionUsed", update_manager.last_version_used); GET_TXT("LastVersionUsed", update_manager.last_version_used);
prefs.update_manager.next_check = copy_string(qPrintable(s.value("NextCheck").toDate().toString("dd/MM/yyyy"))); prefs.update_manager.next_check = copy_qstring(s.value("NextCheck").toDate().toString("dd/MM/yyyy"));
s.endGroup(); s.endGroup();
s.beginGroup("Language"); s.beginGroup("Language");

View file

@ -910,9 +910,9 @@ void ConfigureDiveComputerDialog::getDeviceData()
#else #else
QString device = ui.device->currentText(); QString device = ui.device->currentText();
#endif #endif
device_data.devname = strdup(qPrintable(device)); device_data.devname = copy_qstring(device);
device_data.vendor = strdup(qPrintable(selected_vendor)); device_data.vendor = copy_qstring(selected_vendor);
device_data.product = strdup(qPrintable(selected_product)); device_data.product = copy_qstring(selected_product);
device_data.descriptor = descriptorLookup.value(selected_vendor + selected_product); device_data.descriptor = descriptorLookup.value(selected_vendor + selected_product);
device_data.deviceid = device_data.diveid = 0; device_data.deviceid = device_data.diveid = 0;
@ -1479,7 +1479,7 @@ void ConfigureDiveComputerDialog::pickLogFile()
filename, tr("Log files") + " (*.log)"); filename, tr("Log files") + " (*.log)");
if (!logFile.isEmpty()) { if (!logFile.isEmpty()) {
free(logfile_name); free(logfile_name);
logfile_name = strdup(qPrintable(logFile)); logfile_name = copy_qstring(logFile);
} }
} }

View file

@ -949,7 +949,7 @@ void DiveListView::matchImagesToDives(QStringList fileNames)
for_each_dive (j, dive) { for_each_dive (j, dive) {
if (!dive->selected) if (!dive->selected)
continue; continue;
dive_create_picture(dive, copy_string(qPrintable(fileName)), shiftDialog.amount(), shiftDialog.matchAll()); dive_create_picture(dive, copy_qstring(fileName), shiftDialog.amount(), shiftDialog.matchAll());
} }
} }

View file

@ -788,10 +788,10 @@ int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr)
params[pnr++] = intdup(ui->CSVUnits->currentIndex()); params[pnr++] = intdup(ui->CSVUnits->currentIndex());
if (hw.length()) { if (hw.length()) {
params[pnr++] = strdup("hw"); params[pnr++] = strdup("hw");
params[pnr++] = strdup(qPrintable(hw)); params[pnr++] = copy_qstring(hw);
} else if (ui->knownImports->currentText().length() > 0) { } else if (ui->knownImports->currentText().length() > 0) {
params[pnr++] = strdup("hw"); params[pnr++] = strdup("hw");
params[pnr++] = strdup(qPrintable(ui->knownImports->currentText().prepend("\"").append("\""))); params[pnr++] = copy_qstring(ui->knownImports->currentText().prepend("\"").append("\""));
} }
params[pnr++] = NULL; params[pnr++] = NULL;

View file

@ -297,7 +297,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
#endif #endif
if (data->vendor() == "Uemis") { if (data->vendor() == "Uemis") {
char *colon; char *colon;
char *devname = strdup(qPrintable(ui.device->currentText())); char *devname = copy_qstring(ui.device->currentText());
if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) { if ((colon = strstr(devname, ":\\ (UEMISSDA)")) != NULL) {
*(colon + 2) = '\0'; *(colon + 2) = '\0';
@ -362,7 +362,7 @@ void DownloadFromDCWidget::pickLogFile()
filename, tr("Log files") + " (*.log)"); filename, tr("Log files") + " (*.log)");
if (!logFile.isEmpty()) { if (!logFile.isEmpty()) {
free(logfile_name); free(logfile_name);
logfile_name = copy_string(qPrintable(logFile)); logfile_name = copy_qstring(logFile);
} }
} }
@ -388,7 +388,7 @@ void DownloadFromDCWidget::pickDumpFile()
filename, tr("Dump files") + " (*.bin)"); filename, tr("Dump files") + " (*.bin)");
if (!dumpFile.isEmpty()) { if (!dumpFile.isEmpty()) {
free(dumpfile_name); free(dumpfile_name);
dumpfile_name = copy_string(qPrintable(dumpFile)); dumpfile_name = copy_qstring(dumpFile);
} }
} }

View file

@ -158,7 +158,7 @@ void LocationInformationWidget::acceptChanges()
{ {
char *uiString; char *uiString;
struct dive_site *currentDs; struct dive_site *currentDs;
uiString = copy_string(qPrintable(ui.diveSiteName->text())); uiString = copy_qstring(ui.diveSiteName->text());
if (get_dive_site_by_uuid(displayed_dive_site.uuid) != NULL) { if (get_dive_site_by_uuid(displayed_dive_site.uuid) != NULL) {
currentDs = get_dive_site_by_uuid(displayed_dive_site.uuid); currentDs = get_dive_site_by_uuid(displayed_dive_site.uuid);
} else { } else {
@ -175,14 +175,14 @@ void LocationInformationWidget::acceptChanges()
} else { } else {
free(uiString); free(uiString);
} }
uiString = copy_string(qPrintable(ui.diveSiteDescription->text())); uiString = copy_qstring(ui.diveSiteDescription->text());
if (!same_string(uiString, currentDs->description)) { if (!same_string(uiString, currentDs->description)) {
free(currentDs->description); free(currentDs->description);
currentDs->description = uiString; currentDs->description = uiString;
} else { } else {
free(uiString); free(uiString);
} }
uiString = copy_string(qPrintable(ui.diveSiteCountry->text())); uiString = copy_qstring(ui.diveSiteCountry->text());
// if the user entered a different contriy, first update the taxonomy // if the user entered a different contriy, first update the taxonomy
// for the displayed dive site; this below will get copied into the currentDs // for the displayed dive site; this below will get copied into the currentDs
if (!same_string(uiString, taxonomy_get_country(&displayed_dive_site.taxonomy)) && if (!same_string(uiString, taxonomy_get_country(&displayed_dive_site.taxonomy)) &&
@ -193,7 +193,7 @@ void LocationInformationWidget::acceptChanges()
// now update the currentDs (which we then later copy back ontop of displayed_dive_site // now update the currentDs (which we then later copy back ontop of displayed_dive_site
copy_dive_site_taxonomy(&displayed_dive_site, currentDs); copy_dive_site_taxonomy(&displayed_dive_site, currentDs);
uiString = copy_string(qPrintable(ui.diveSiteNotes->document()->toPlainText())); uiString = copy_qstring(ui.diveSiteNotes->document()->toPlainText());
if (!same_string(uiString, currentDs->notes)) { if (!same_string(uiString, currentDs->notes)) {
free(currentDs->notes); free(currentDs->notes);
currentDs->notes = uiString; currentDs->notes = uiString;

View file

@ -935,7 +935,7 @@ void MainWindow::updateVariations(QString variations)
{ {
QString notes = QString(displayed_dive.notes); QString notes = QString(displayed_dive.notes);
free(displayed_dive.notes); free(displayed_dive.notes);
displayed_dive.notes = strdup(qPrintable(notes.replace("VARIATIONS", variations))); displayed_dive.notes = copy_qstring(notes.replace("VARIATIONS", variations));
plannerDetails()->divePlanOutput()->setHtml(displayed_dive.notes); plannerDetails()->divePlanOutput()->setHtml(displayed_dive.notes);
} }
@ -1652,7 +1652,7 @@ int MainWindow::file_save_as(void)
filename.remove(prefs.cloud_git_url); filename.remove(prefs.cloud_git_url);
filename.remove(0, filename.indexOf("[") + 1); filename.remove(0, filename.indexOf("[") + 1);
filename.replace("]", ".ssrf"); filename.replace("]", ".ssrf");
default_filename = strdup(qPrintable(filename)); default_filename = copy_qstring(filename);
} }
// create a file dialog that allows us to save to a new file // create a file dialog that allows us to save to a new file
QFileDialog selection_dialog(this, tr("Save file as"), default_filename, QFileDialog selection_dialog(this, tr("Save file as"), default_filename,

View file

@ -745,7 +745,7 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, int divenr)
if(createdNewDive) { if(createdNewDive) {
copy_dive_site(origDs, newDs); copy_dive_site(origDs, newDs);
free(newDs->name); free(newDs->name);
newDs->name = copy_string(qPrintable(ui.location->text().constData())); newDs->name = copy_qstring(ui.location->text());
newDs->uuid = pickedUuid; newDs->uuid = pickedUuid;
qDebug() << "Creating and copying dive site"; qDebug() << "Creating and copying dive site";
} else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) { } else if (newDs->latitude.udeg == 0 && newDs->longitude.udeg == 0) {
@ -1090,7 +1090,7 @@ void MainTab::on_buddy_textChanged()
text_list[i] = text_list[i].trimmed(); text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", "); QString text = text_list.join(", ");
free(displayed_dive.buddy); free(displayed_dive.buddy);
displayed_dive.buddy = strdup(qPrintable(text)); displayed_dive.buddy = copy_qstring(text);
markChangedWidget(ui.buddy); markChangedWidget(ui.buddy);
} }
@ -1107,7 +1107,7 @@ void MainTab::on_divemaster_textChanged()
text_list[i] = text_list[i].trimmed(); text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", "); QString text = text_list.join(", ");
free(displayed_dive.divemaster); free(displayed_dive.divemaster);
displayed_dive.divemaster = strdup(qPrintable(text)); displayed_dive.divemaster = copy_qstring(text);
markChangedWidget(ui.divemaster); markChangedWidget(ui.divemaster);
} }
@ -1303,7 +1303,7 @@ void MainTab::saveTaggedStrings()
} }
} }
free(mydive->buddy); free(mydive->buddy);
mydive->buddy = copy_string(qPrintable(newString)); mydive->buddy = copy_qstring(newString);
); );
addedList.clear(); addedList.clear();
removedList.clear(); removedList.clear();
@ -1325,7 +1325,7 @@ void MainTab::saveTaggedStrings()
} }
} }
free(mydive->divemaster); free(mydive->divemaster);
mydive->divemaster = copy_string(qPrintable(newString)); mydive->divemaster = copy_qstring(newString);
); );
} }
@ -1397,7 +1397,7 @@ void MainTab::on_diveTripLocation_textEdited(const QString& text)
{ {
if (currentTrip) { if (currentTrip) {
free(displayedTrip.location); free(displayedTrip.location);
displayedTrip.location = strdup(qPrintable(text)); displayedTrip.location = copy_qstring(text);
markChangedWidget(ui.diveTripLocation); markChangedWidget(ui.diveTripLocation);
} }
} }
@ -1407,7 +1407,7 @@ void MainTab::on_suit_textChanged(const QString &text)
if (editMode == IGNORE || acceptingEdit == true) if (editMode == IGNORE || acceptingEdit == true)
return; return;
free(displayed_dive.suit); free(displayed_dive.suit);
displayed_dive.suit = strdup(qPrintable(text)); displayed_dive.suit = copy_qstring(text);
markChangedWidget(ui.suit); markChangedWidget(ui.suit);
} }
@ -1419,15 +1419,15 @@ void MainTab::on_notes_textChanged()
if (same_string(displayedTrip.notes, qPrintable(ui.notes->toPlainText()))) if (same_string(displayedTrip.notes, qPrintable(ui.notes->toPlainText())))
return; return;
free(displayedTrip.notes); free(displayedTrip.notes);
displayedTrip.notes = strdup(qPrintable(ui.notes->toPlainText())); displayedTrip.notes = copy_qstring(ui.notes->toPlainText());
} else { } else {
if (same_string(displayed_dive.notes, qPrintable(ui.notes->toPlainText()))) if (same_string(displayed_dive.notes, qPrintable(ui.notes->toPlainText())))
return; return;
free(displayed_dive.notes); free(displayed_dive.notes);
if (ui.notes->toHtml().indexOf("<table") != -1) if (ui.notes->toHtml().indexOf("<table") != -1)
displayed_dive.notes = strdup(qPrintable(ui.notes->toHtml())); displayed_dive.notes = copy_qstring(ui.notes->toHtml());
else else
displayed_dive.notes = strdup(qPrintable(ui.notes->toPlainText())); displayed_dive.notes = copy_qstring(ui.notes->toPlainText());
} }
markChangedWidget(ui.notes); markChangedWidget(ui.notes);
} }

View file

@ -144,7 +144,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged); connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
QString libdcLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/libdivecomputer.log"; QString libdcLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/libdivecomputer.log";
logfile_name = strdup(qPrintable(libdcLogFileName)); logfile_name = copy_qstring(libdcLogFileName);
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
appLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/subsurface.log"; appLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/subsurface.log";
appLogFile.setFileName(appLogFileName); appLogFile.setFileName(appLogFileName);
@ -416,7 +416,7 @@ void QMLManager::saveCloudCredentials()
s.sync(); s.sync();
if (!same_string(prefs.cloud_storage_email, qPrintable(m_cloudUserName))) { if (!same_string(prefs.cloud_storage_email, qPrintable(m_cloudUserName))) {
free((void *)prefs.cloud_storage_email); free((void *)prefs.cloud_storage_email);
prefs.cloud_storage_email = strdup(qPrintable(m_cloudUserName)); prefs.cloud_storage_email = copy_qstring(m_cloudUserName);
cloudCredentialsChanged = true; cloudCredentialsChanged = true;
} }
@ -429,7 +429,7 @@ void QMLManager::saveCloudCredentials()
if (!same_string(prefs.cloud_storage_password, qPrintable(m_cloudPassword))) { if (!same_string(prefs.cloud_storage_password, qPrintable(m_cloudPassword))) {
free((void *)prefs.cloud_storage_password); free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = strdup(qPrintable(m_cloudPassword)); prefs.cloud_storage_password = copy_qstring(m_cloudPassword);
} }
if (m_cloudUserName.isEmpty() || m_cloudPassword.isEmpty()) { if (m_cloudUserName.isEmpty() || m_cloudPassword.isEmpty()) {
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
@ -577,7 +577,7 @@ void QMLManager::retrieveUserid()
if (!userid.isEmpty()) { if (!userid.isEmpty()) {
// overwrite the existing userid // overwrite the existing userid
free((void *)prefs.userid); free((void *)prefs.userid);
prefs.userid = strdup(qPrintable(userid)); prefs.userid = copy_qstring(userid);
QSettings s; QSettings s;
s.setValue("subsurface_webservice_uid", prefs.userid); s.setValue("subsurface_webservice_uid", prefs.userid);
s.sync(); s.sync();
@ -1020,14 +1020,14 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
} }
} }
d->cylinder[0].type.description = strdup(qPrintable(cylinder)); d->cylinder[0].type.description = copy_qstring(cylinder);
d->cylinder[0].type.size.mliter = size; d->cylinder[0].type.size.mliter = size;
d->cylinder[0].type.workingpressure.mbar = wp; d->cylinder[0].type.workingpressure.mbar = wp;
} }
if (myDive->suit() != suit) { if (myDive->suit() != suit) {
diveChanged = true; diveChanged = true;
free(d->suit); free(d->suit);
d->suit = strdup(qPrintable(suit)); d->suit = copy_qstring(suit);
} }
if (myDive->buddy() != buddy) { if (myDive->buddy() != buddy) {
if (buddy.contains(",")){ if (buddy.contains(",")){
@ -1035,12 +1035,12 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
} }
diveChanged = true; diveChanged = true;
free(d->buddy); free(d->buddy);
d->buddy = strdup(qPrintable(buddy)); d->buddy = copy_qstring(buddy);
} }
if (myDive->divemaster() != diveMaster) { if (myDive->divemaster() != diveMaster) {
diveChanged = true; diveChanged = true;
free(d->divemaster); free(d->divemaster);
d->divemaster = strdup(qPrintable(diveMaster)); d->divemaster = copy_qstring(diveMaster);
} }
if (myDive->rating() != rating) { if (myDive->rating() != rating) {
diveChanged = true; diveChanged = true;
@ -1053,7 +1053,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
if (myDive->notes() != notes) { if (myDive->notes() != notes) {
diveChanged = true; diveChanged = true;
free(d->notes); free(d->notes);
d->notes = strdup(qPrintable(notes)); d->notes = copy_qstring(notes);
} }
// now that we have it all figured out, let's see what we need // now that we have it all figured out, let's see what we need
// to update // to update

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "core/units.h" #include "core/units.h"
#include "qt-models/divelocationmodel.h" #include "qt-models/divelocationmodel.h"
#include "core/dive.h" #include "core/qthelper.h"
#include <QDebug> #include <QDebug>
#include <QLineEdit> #include <QLineEdit>
#include <QIcon> #include <QIcon>
@ -149,7 +149,7 @@ bool LocationInformationModel::setData(const QModelIndex &index, const QVariant
struct dive_site *ds = get_dive_site(index.row()); struct dive_site *ds = get_dive_site(index.row());
free(ds->name); free(ds->name);
ds->name = copy_string(qPrintable(value.toString())); ds->name = copy_qstring(value.toString());
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }

View file

@ -160,7 +160,7 @@ void DivePlannerPointsModel::setupCylinders()
} }
if (cylinder_none(&displayed_dive.cylinder[0])) { if (cylinder_none(&displayed_dive.cylinder[0])) {
// roughly an AL80 // roughly an AL80
displayed_dive.cylinder[0].type.description = strdup(qPrintable(tr("unknown"))); displayed_dive.cylinder[0].type.description = copy_qstring(tr("unknown"));
displayed_dive.cylinder[0].type.size.mliter = 11100; displayed_dive.cylinder[0].type.size.mliter = 11100;
displayed_dive.cylinder[0].type.workingpressure.mbar = 207000; displayed_dive.cylinder[0].type.workingpressure.mbar = 207000;
} }
@ -1123,7 +1123,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
// Deal with line breaks // Deal with line breaks
oldnotes.replace("\n", "<br>"); oldnotes.replace("\n", "<br>");
oldnotes.append(displayed_dive.notes); oldnotes.append(displayed_dive.notes);
displayed_dive.notes = strdup(qPrintable(oldnotes)); displayed_dive.notes = copy_qstring(oldnotes);
// If we save as new create a copy of the dive here // If we save as new create a copy of the dive here
if (replanCopy) { if (replanCopy) {
struct dive *copy = alloc_dive(); struct dive *copy = alloc_dive();

View file

@ -114,7 +114,7 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r
} }
} }
if (ws_info[i].name == NULL) // didn't find a match if (ws_info[i].name == NULL) // didn't find a match
ws->description = strdup(qPrintable(vString)); ws->description = copy_qstring(vString);
changed = true; changed = true;
} }
} }

View file

@ -43,7 +43,7 @@ void TestGitStorage::initTestCase()
QString gitUrl(prefs.cloud_base_url); QString gitUrl(prefs.cloud_base_url);
if (gitUrl.right(1) != "/") if (gitUrl.right(1) != "/")
gitUrl += "/"; gitUrl += "/";
prefs.cloud_git_url = strdup(qPrintable(gitUrl + "git")); prefs.cloud_git_url = copy_qstring(gitUrl + "git");
s.endGroup(); s.endGroup();
prefs.cloud_storage_email_encoded = strdup("ssrftest@hohndel.org"); prefs.cloud_storage_email_encoded = strdup("ssrftest@hohndel.org");
prefs.cloud_storage_password = strdup("geheim"); prefs.cloud_storage_password = strdup("geheim");