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 /mobile-widgets | |
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 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 7e11f8c2d..075e002e0 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -144,7 +144,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged); QString libdcLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/libdivecomputer.log"; - logfile_name = strdup(qPrintable(libdcLogFileName)); + logfile_name = copy_qstring(libdcLogFileName); #if defined(Q_OS_ANDROID) appLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/subsurface.log"; appLogFile.setFileName(appLogFileName); @@ -416,7 +416,7 @@ void QMLManager::saveCloudCredentials() s.sync(); if (!same_string(prefs.cloud_storage_email, qPrintable(m_cloudUserName))) { free((void *)prefs.cloud_storage_email); - prefs.cloud_storage_email = strdup(qPrintable(m_cloudUserName)); + prefs.cloud_storage_email = copy_qstring(m_cloudUserName); cloudCredentialsChanged = true; } @@ -429,7 +429,7 @@ void QMLManager::saveCloudCredentials() if (!same_string(prefs.cloud_storage_password, qPrintable(m_cloudPassword))) { 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()) { setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); @@ -577,7 +577,7 @@ void QMLManager::retrieveUserid() if (!userid.isEmpty()) { // overwrite the existing userid free((void *)prefs.userid); - prefs.userid = strdup(qPrintable(userid)); + prefs.userid = copy_qstring(userid); QSettings s; s.setValue("subsurface_webservice_uid", prefs.userid); 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.workingpressure.mbar = wp; } if (myDive->suit() != suit) { diveChanged = true; free(d->suit); - d->suit = strdup(qPrintable(suit)); + d->suit = copy_qstring(suit); } if (myDive->buddy() != buddy) { if (buddy.contains(",")){ @@ -1035,12 +1035,12 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q } diveChanged = true; free(d->buddy); - d->buddy = strdup(qPrintable(buddy)); + d->buddy = copy_qstring(buddy); } if (myDive->divemaster() != diveMaster) { diveChanged = true; free(d->divemaster); - d->divemaster = strdup(qPrintable(diveMaster)); + d->divemaster = copy_qstring(diveMaster); } if (myDive->rating() != rating) { diveChanged = true; @@ -1053,7 +1053,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q if (myDive->notes() != notes) { diveChanged = true; 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 // to update |