diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-02-28 23:37:09 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-03-14 13:55:36 +0200 |
commit | d1572a8d9574e80955796b8667317c8dbd376081 (patch) | |
tree | ab58f9920a20b5c55bd54474f2edcfdc4eb2b904 /core | |
parent | b72cc1f31784346884c8552c22f1e4c3c6d5ed1d (diff) | |
download | subsurface-d1572a8d9574e80955796b8667317c8dbd376081.tar.gz |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/android.cpp | 3 | ||||
-rw-r--r-- | core/divesitehelpers.cpp | 4 | ||||
-rw-r--r-- | core/downloadfromdcthread.cpp | 9 | ||||
-rw-r--r-- | core/prefs-macros.h | 12 | ||||
-rw-r--r-- | core/qthelper.cpp | 51 | ||||
-rw-r--r-- | core/qthelper.h | 2 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 61 |
7 files changed, 75 insertions, 67 deletions
diff --git a/core/android.cpp b/core/android.cpp index 5234f35a9..277c4492e 100644 --- a/core/android.cpp +++ b/core/android.cpp @@ -2,6 +2,7 @@ /* implements Android specific functions */ #include "dive.h" #include "display.h" +#include "qthelper.h" #include <string.h> #include <sys/types.h> #include <dirent.h> @@ -52,7 +53,7 @@ static const char *system_default_path_append(const char *append) if (append) path += QString("/%1").arg(append); - return strdup(qPrintable(path)); + return copy_qstring(path); } const char *system_default_directory(void) diff --git a/core/divesitehelpers.cpp b/core/divesitehelpers.cpp index c1c9ed860..aed19eed8 100644 --- a/core/divesitehelpers.cpp +++ b/core/divesitehelpers.cpp @@ -95,7 +95,7 @@ void ReverseGeoLookupThread::run() ds->taxonomy.category[ri].category = j; ds->taxonomy.category[ri].origin = taxonomy_origin::GEOCODED; 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++; } } @@ -156,7 +156,7 @@ void ReverseGeoLookupThread::run() if (idx < TC_NR_CATEGORIES) { ds->taxonomy.category[idx].category = TC_OCEAN; 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) ds->taxonomy.nr++; } diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index dfbeb244d..ea803e20b 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -1,5 +1,6 @@ #include "downloadfromdcthread.h" #include "core/libdivecomputer.h" +#include "core/qthelper.h" #include "core/subsurface-qt/SettingsObjectWrapper.h" #include <QDebug> #include <QRegularExpression> @@ -281,12 +282,12 @@ int DCDeviceData::diveId() const void DCDeviceData::setVendor(const QString& vendor) { - data.vendor = strdup(qPrintable(vendor)); + data.vendor = copy_qstring(vendor); } void DCDeviceData::setProduct(const QString& product) { - data.product = strdup(qPrintable(product)); + data.product = copy_qstring(product); } 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 newDevName = back.indexOf(':') >= 0 ? back : front; qWarning() << "Found invalid bluetooth device" << devName << "corrected to" << newDevName << "."; - data.devname = strdup(qPrintable(newDevName)); + data.devname = copy_qstring(newDevName); return; } } - data.devname = strdup(qPrintable(devName)); + data.devname = copy_qstring(devName); } void DCDeviceData::setDevBluetoothName(const QString& name) diff --git a/core/prefs-macros.h b/core/prefs-macros.h index 16a92aa24..72d5c60b2 100644 --- a/core/prefs-macros.h +++ b/core/prefs-macros.h @@ -2,6 +2,8 @@ #ifndef PREFSMACROS_H #define PREFSMACROS_H +#include "core/qthelper.h" + #define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0)) #define GET_UNIT(name, field, f, t) \ @@ -60,11 +62,11 @@ else \ prefs.field = defval -#define GET_TXT(name, field) \ - v = s.value(QString(name)); \ - if (v.isValid()) \ - prefs.field = strdup(qPrintable(v.toString())); \ - else \ +#define GET_TXT(name, field) \ + v = s.value(QString(name)); \ + if (v.isValid()) \ + prefs.field = copy_qstring(v.toString()); \ + else \ prefs.field = copy_string(default_prefs.field) #define SAVE_OR_REMOVE_SPECIAL(_setting, _default, _compare, _value) \ diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 483e90b21..ca21837a4 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -99,7 +99,7 @@ extern "C" const char *printGPSCoords(int lat, int lon) } else { 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 return strdup(""); } - return strdup(qPrintable(newPath)); + return copy_qstring(newPath); } extern "C" char *get_file_name(const char *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) @@ -473,7 +473,7 @@ extern "C" const char *subsurface_user_agent() { static QString uA = getUserAgent(); - return strdup(qPrintable(uA)); + return copy_qstring(uA); } /* TOOD: Move this to SettingsObjectWrapper, and also fix this complexity. @@ -504,7 +504,7 @@ QString uiLanguage(QLocale *callerLoc) uiLang = languages[2]; else 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("date_format_override", date_format_override); GET_TXT("time_format", time_format); @@ -540,11 +540,11 @@ QString uiLanguage(QLocale *callerLoc) dateFormat.replace("'en' 'den' d:'e'", " d"); if (!prefs.date_format_override || empty_string(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)) { 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)) { @@ -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(".ss", "").replace(":ss", "").replace("ss", ""); free((void *)prefs.time_format); - prefs.time_format = strdup(qPrintable(timeFormat)); + prefs.time_format = copy_qstring(timeFormat); } 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) { QString text = get_dive_date_string(when); - return strdup(qPrintable(text)); + return copy_qstring(text); } 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)); - return strdup(qPrintable(current_date)); + return copy_qstring(current_date); } 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() { - return strdup(qPrintable(hashfile_name())); + return copy_qstring(hashfile_name()); } 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) { - return strdup(qPrintable(localFilePath(picture->filename))); + return copy_qstring(localFilePath(picture->filename)); } extern "C" bool picture_exists(struct picture *picture) @@ -1266,7 +1266,7 @@ const QString picturedir() 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 @@ -1446,7 +1446,7 @@ int getCloudURL(QString &filename) return report_error("Please configure Cloud storage email and password in the preferences"); if (email != 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); if (verbose) @@ -1458,7 +1458,7 @@ extern "C" char *cloud_url() { QString filename; getCloudURL(filename); - return strdup(qPrintable(filename)); + return copy_qstring(filename); } extern "C" bool getProxyString(char **buffer) @@ -1471,7 +1471,7 @@ extern "C" bool getProxyString(char **buffer) else proxy = QString("http://%1:%2").arg(prefs.proxy_host).arg(prefs.proxy_port); if (buffer) - *buffer = strdup(qPrintable(proxy)); + *buffer = copy_qstring(proxy); return true; } 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()) { if (parseLine.contains("//DIVE NR: ")) { 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; } } @@ -1573,7 +1573,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { if (parseLine.contains("//Hardware Version: ")) { 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; } } @@ -1586,7 +1586,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) while ((parseLine = f.readLine().trimmed()).length() > 0 && !f.atEnd()) { if (parseLine.contains("//Log interval: ")) { 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; } } @@ -1601,7 +1601,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) QString needle = "//Mode: "; if (parseLine.contains(needle)) { 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); @@ -1614,7 +1614,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) QString needle = "//Firmware Version: "; if (parseLine.contains(needle)) { 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); @@ -1623,7 +1623,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) QString needle = "//Serial number: "; if (parseLine.contains(needle)) { 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); @@ -1632,7 +1632,7 @@ int parse_seabear_header(const char *filename, char **params, int pnr) QString needle = "//GF: "; if (parseLine.contains(needle)) { 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); @@ -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); b->len += utf8_size; } + +char *copy_qstring(const QString &s) +{ + return strdup(qPrintable(s)); +} diff --git a/core/qthelper.h b/core/qthelper.h index 74d2af396..978493e1c 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -54,9 +54,9 @@ void init_proxy(); QString getUUID(); QStringList imageExtensionFilters(); char *intdup(int index); +char *copy_qstring(const QString &); __printf(1, 2) QString asprintf_loc(const char *cformat, ...); __printf(1, 0) QString vasprintf_loc(const char *cformat, va_list ap); - #endif // 3) Functions visible to C and C++ diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index dcb1f8382..cd1054b97 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -6,7 +6,6 @@ #include <QDate> #include <QNetworkProxy> -#include "core/dive.h" // TODO: remove copy_string from dive.h #include "core/helpers.h" DiveComputerSettings::DiveComputerSettings(QObject *parent): @@ -48,7 +47,7 @@ void DiveComputerSettings::setVendor(const QString& vendor) s.beginGroup(group); s.setValue("dive_computer_vendor", 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) @@ -60,7 +59,7 @@ void DiveComputerSettings::setProduct(const QString& product) s.beginGroup(group); s.setValue("dive_computer_product", 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) @@ -72,7 +71,7 @@ void DiveComputerSettings::setDevice(const QString& device) s.beginGroup(group); s.setValue("dive_computer_device", 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) @@ -84,7 +83,7 @@ void DiveComputerSettings::setDeviceName(const QString& device_name) s.beginGroup(group); s.setValue("dive_computer_device_name", 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) @@ -145,7 +144,7 @@ void UpdateManagerSettings::setLastVersionUsed(const QString& value) s.beginGroup(group); s.setValue("LastVersionUsed", value); 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); } @@ -158,7 +157,7 @@ void UpdateManagerSettings::setNextCheck(const QDate& date) s.beginGroup(group); s.setValue("NextCheck", date); 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); } @@ -765,7 +764,7 @@ void FacebookSettings::setAccessToken (const QString& value) s.setValue("ConnectToken", value); #endif free((void *)prefs.facebook.access_token); - prefs.facebook.access_token = copy_string(qPrintable(value)); + prefs.facebook.access_token = copy_qstring(value); emit accessTokenChanged(value); } @@ -780,7 +779,7 @@ void FacebookSettings::setUserId(const QString& value) s.setValue("UserId", value); #endif free((void *)prefs.facebook.user_id); - prefs.facebook.user_id = copy_string(qPrintable(value)); + prefs.facebook.user_id = copy_qstring(value); emit userIdChanged(value); } @@ -795,7 +794,7 @@ void FacebookSettings::setAlbumId(const QString& value) s.setValue("AlbumId", value); #endif free((void *)prefs.facebook.album_id); - prefs.facebook.album_id = copy_string(qPrintable(value)); + prefs.facebook.album_id = copy_qstring(value); emit albumIdChanged(value); } @@ -908,7 +907,7 @@ void ProxySettings::setHost(const QString& value) s.beginGroup(group); s.setValue("proxy_host", value); free((void *)prefs.proxy_host); - prefs.proxy_host = copy_string(qPrintable(value)); + prefs.proxy_host = copy_qstring(value); emit hostChanged(value); } @@ -942,7 +941,7 @@ void ProxySettings::setUser(const QString& value) s.beginGroup(group); s.setValue("proxy_user", value); free((void *)prefs.proxy_user); - prefs.proxy_user = copy_string(qPrintable(value)); + prefs.proxy_user = copy_qstring(value); emit userChanged(value); } @@ -954,7 +953,7 @@ void ProxySettings::setPass(const QString& value) s.beginGroup(group); s.setValue("proxy_pass", value); free((void *)prefs.proxy_pass); - prefs.proxy_pass = copy_string(qPrintable(value)); + prefs.proxy_pass = copy_qstring(value); emit passChanged(value); } @@ -1022,7 +1021,7 @@ void CloudStorageSettings::setPassword(const QString& value) s.beginGroup(group); s.setValue("password", value); free((void *)prefs.cloud_storage_password); - prefs.cloud_storage_password = copy_string(qPrintable(value)); + prefs.cloud_storage_password = copy_qstring(value); emit passwordChanged(value); } @@ -1032,7 +1031,7 @@ void CloudStorageSettings::setNewPassword(const QString& value) return; /*TODO: This looks like wrong, but 'new password' is not saved on disk, why it's on prefs? */ free((void *)prefs.cloud_storage_newpassword); - prefs.cloud_storage_newpassword = copy_string(qPrintable(value)); + prefs.cloud_storage_newpassword = copy_qstring(value); emit newPasswordChanged(value); } @@ -1044,7 +1043,7 @@ void CloudStorageSettings::setEmail(const QString& value) s.beginGroup(group); s.setValue("email", value); free((void *)prefs.cloud_storage_email); - prefs.cloud_storage_email = copy_string(qPrintable(value)); + prefs.cloud_storage_email = copy_qstring(value); emit emailChanged(value); } @@ -1056,7 +1055,7 @@ void CloudStorageSettings::setUserId(const QString& value) QSettings s; s.setValue("subsurface_webservice_uid", value); free((void *)prefs.userid); - prefs.userid = copy_string(qPrintable(value)); + prefs.userid = copy_qstring(value); emit userIdChanged(value); } @@ -1066,7 +1065,7 @@ void CloudStorageSettings::setEmailEncoded(const QString& value) return; /*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); - prefs.cloud_storage_email_encoded = copy_string(qPrintable(value)); + prefs.cloud_storage_email_encoded = copy_qstring(value); emit emailEncodedChanged(value); } @@ -1119,8 +1118,8 @@ void CloudStorageSettings::setBaseUrl(const QString& value) QSettings s; s.beginGroup(group); s.setValue("cloud_base_url", value); - prefs.cloud_base_url = copy_string(qPrintable(value)); - prefs.cloud_git_url = copy_string(qPrintable(QString(prefs.cloud_base_url) + "/git")); + prefs.cloud_base_url = copy_qstring(value); + prefs.cloud_git_url = copy_qstring(QString(prefs.cloud_base_url) + "/git"); } void CloudStorageSettings::setGitUrl(const QString& value) @@ -1796,7 +1795,7 @@ void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value) s.beginGroup(group); s.setValue("default_filename", value); free((void *)prefs.default_filename); - prefs.default_filename = copy_string(qPrintable(value)); + prefs.default_filename = copy_qstring(value); emit defaultFilenameChanged(value); } @@ -1809,7 +1808,7 @@ void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value) s.beginGroup(group); s.setValue("default_cylinder", value); free((void *)prefs.default_cylinder); - prefs.default_cylinder = copy_string(qPrintable(value)); + prefs.default_cylinder = copy_qstring(value); emit defaultCylinderChanged(value); } @@ -1916,7 +1915,7 @@ void DisplaySettingsObjectWrapper::setDivelistFont(const QString& value) if (!subsurface_ignore_font(qPrintable(newValue))) { free((void *)prefs.divelist_font); - prefs.divelist_font = strdup(qPrintable(newValue)); + prefs.divelist_font = copy_qstring(newValue); qApp->setFont(QFont(newValue)); } emit divelistFontChanged(newValue); @@ -2013,7 +2012,7 @@ void LanguageSettingsObjectWrapper::setLangLocale(const QString &value) s.beginGroup(group); s.setValue("UiLangLocale", value); free((void *)prefs.locale.lang_locale); - prefs.locale.lang_locale = copy_string(qPrintable(value)); + prefs.locale.lang_locale = copy_qstring(value); emit langLocaleChanged(value); } @@ -2025,7 +2024,7 @@ void LanguageSettingsObjectWrapper::setLanguage(const QString& value) s.beginGroup(group); s.setValue("UiLanguage", value); free((void *)prefs.locale.language); - prefs.locale.language = copy_string(qPrintable(value)); + prefs.locale.language = copy_qstring(value); emit languageChanged(value); } @@ -2037,7 +2036,7 @@ void LanguageSettingsObjectWrapper::setTimeFormat(const QString& value) s.beginGroup(group); s.setValue("time_format", value); free((void *)prefs.time_format); - prefs.time_format = copy_string(qPrintable(value)); + prefs.time_format = copy_qstring(value); emit timeFormatChanged(value); } @@ -2050,7 +2049,7 @@ void LanguageSettingsObjectWrapper::setDateFormat(const QString& value) s.beginGroup(group); s.setValue("date_format", value); free((void *)prefs.date_format); - prefs.date_format = copy_string(qPrintable(value)); + prefs.date_format = copy_qstring(value); emit dateFormatChanged(value); } @@ -2063,7 +2062,7 @@ void LanguageSettingsObjectWrapper::setDateFormatShort(const QString& value) s.beginGroup(group); s.setValue("date_format_short", value); free((void *)prefs.date_format_short); - prefs.date_format_short = copy_string(qPrintable(value)); + prefs.date_format_short = copy_qstring(value); emit dateFormatShortChanged(value); } @@ -2269,7 +2268,7 @@ void SettingsObjectWrapper::load() defaultFont = QFont(prefs.divelist_font); } else { free((void *)prefs.divelist_font); - prefs.divelist_font = strdup(qPrintable(fontName)); + prefs.divelist_font = copy_qstring(fontName); } defaultFont.setPointSizeF(prefs.font_size); qApp->setFont(defaultFont); @@ -2306,7 +2305,7 @@ void SettingsObjectWrapper::load() // 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 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(); // 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"); GET_BOOL("DontCheckForUpdates", update_manager.dont_check_for_updates); 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.beginGroup("Language"); |