Skip to content

Commit b14de43

Browse files
committed
FIX(client): Use std::string instead of QString
1 parent 2af0ba0 commit b14de43

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

src/mumble/ConfigDialog.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,26 @@ void ConfigDialog::updateProfileList() {
214214
qcbProfiles->clear();
215215

216216
// Always sort the default profile before anything else
217-
qcbProfiles->addItem(Profiles::s_default_profile_name);
217+
qcbProfiles->addItem(QString::fromStdString(Profiles::s_default_profile_name));
218218

219-
QStringList profiles = Global::get().profiles.allProfiles.keys();
220-
profiles.sort();
221-
for (const QString &profile : profiles) {
219+
QList< std::string > profiles = Global::get().profiles.allProfiles.keys();
220+
std::sort(profiles.begin(), profiles.end());
221+
for (const std::string &profile : profiles) {
222222
if (profile == Profiles::s_default_profile_name) {
223223
continue;
224224
}
225-
qcbProfiles->addItem(profile);
225+
qcbProfiles->addItem(QString::fromStdString(profile));
226226
}
227227

228-
qcbProfiles->setCurrentIndex(qcbProfiles->findText(Global::get().profiles.activeProfileName));
228+
qcbProfiles->setCurrentIndex(
229+
qcbProfiles->findText(QString::fromStdString(Global::get().profiles.activeProfileName)));
229230

230-
bool isDefault = qcbProfiles->currentText() == Profiles::s_default_profile_name;
231+
bool isDefault = qcbProfiles->currentText().toStdString() == Profiles::s_default_profile_name;
231232
qpbProfileRename->setEnabled(!isDefault);
232233
qpbProfileDelete->setEnabled(!isDefault);
233234
}
234235

235-
void ConfigDialog::switchProfile(const QString &newProfile, bool saveActiveProfile) {
236+
void ConfigDialog::switchProfile(const std::string &newProfile, bool saveActiveProfile) {
236237
Profiles &profiles = Global::get().profiles;
237238

238239
if (saveActiveProfile) {
@@ -248,7 +249,7 @@ void ConfigDialog::switchProfile(const QString &newProfile, bool saveActiveProfi
248249
}
249250

250251
void ConfigDialog::on_qcbProfiles_currentIndexChanged(int) {
251-
QString selectedProfile = qcbProfiles->currentText();
252+
std::string selectedProfile = qcbProfiles->currentText().toStdString();
252253

253254
Profiles &profiles = Global::get().profiles;
254255

@@ -265,11 +266,12 @@ void ConfigDialog::on_qcbProfiles_currentIndexChanged(int) {
265266

266267
void ConfigDialog::on_qpbProfileAdd_clicked() {
267268
bool ok;
268-
QString profileName =
269+
std::string profileName =
269270
QInputDialog::getText(this, tr("Creating settings profile"), tr("Enter new settings profile name"),
270-
QLineEdit::Normal, Global::get().profiles.activeProfileName, &ok);
271+
QLineEdit::Normal, QString::fromStdString(Global::get().profiles.activeProfileName), &ok)
272+
.toStdString();
271273

272-
if (!ok || profileName.isEmpty()) {
274+
if (!ok || profileName.empty()) {
273275
return;
274276
}
275277

@@ -289,18 +291,19 @@ void ConfigDialog::on_qpbProfileAdd_clicked() {
289291
}
290292

291293
void ConfigDialog::on_qpbProfileRename_clicked() {
292-
QString oldProfileName = qcbProfiles->currentText();
294+
std::string oldProfileName = qcbProfiles->currentText().toStdString();
293295

294296
if (oldProfileName == Profiles::s_default_profile_name) {
295297
return;
296298
}
297299

298300
bool ok;
299-
QString profileName =
301+
std::string profileName =
300302
QInputDialog::getText(this, tr("Renaming settings profile"), tr("Enter new settings profile name"),
301-
QLineEdit::Normal, oldProfileName, &ok);
303+
QLineEdit::Normal, QString::fromStdString(oldProfileName), &ok)
304+
.toStdString();
302305

303-
if (!ok || profileName.isEmpty()) {
306+
if (!ok || profileName.empty()) {
304307
return;
305308
}
306309

@@ -316,7 +319,7 @@ void ConfigDialog::on_qpbProfileRename_clicked() {
316319
}
317320

318321
void ConfigDialog::on_qpbProfileDelete_clicked() {
319-
QString oldProfileName = qcbProfiles->currentText();
322+
std::string oldProfileName = qcbProfiles->currentText().toStdString();
320323

321324
if (oldProfileName == Profiles::s_default_profile_name) {
322325
return;
@@ -326,9 +329,10 @@ void ConfigDialog::on_qpbProfileDelete_clicked() {
326329
return;
327330
}
328331

329-
QMessageBox::StandardButton confirmation = QMessageBox::question(
330-
this, tr("Delete settings profile"),
331-
tr("Are you sure you want to permanently delete settings profile '%1'").arg(oldProfileName));
332+
QMessageBox::StandardButton confirmation =
333+
QMessageBox::question(this, tr("Delete settings profile"),
334+
tr("Are you sure you want to permanently delete settings profile '%1'")
335+
.arg(QString::fromStdString(oldProfileName)));
332336

333337
if (confirmation != QMessageBox::Yes) {
334338
return;

src/mumble/ConfigDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConfigDialog : public QDialog, public Ui::ConfigDialog {
2020

2121
void updateTabOrder();
2222
void updateProfileList();
23-
void switchProfile(const QString &newProfile, bool saveActiveProfile);
23+
void switchProfile(const std::string &newProfile, bool saveActiveProfile);
2424

2525
protected:
2626
static QMutex s_existingWidgetsMutex;

src/mumble/Settings.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ void Settings::save(const QString &path) const {
156156
nlohmann::json &profilesJSON = settingsJSON.at(SettingsKeys::PROFILES);
157157
nlohmann::json activeProfileJSON = *this;
158158

159-
qInfo("Saving settings profile '%s'", qUtf8Printable(profiles.activeProfileName));
159+
qInfo("Saving settings profile '%s'", qUtf8Printable(QString::fromStdString(profiles.activeProfileName)));
160160

161161
// Replace the settings loaded from disk with the current (possibly modified) settings
162-
profilesJSON.erase(profiles.activeProfileName.toStdString());
162+
profilesJSON.erase(profiles.activeProfileName);
163163
profilesJSON.push_back({ profiles.activeProfileName, activeProfileJSON });
164164

165165
QFile tmpFile(QString::fromLatin1("%1/mumble_settings.json.tmp")
@@ -225,28 +225,30 @@ void Settings::save() const {
225225
}
226226
}
227227

228-
void Settings::loadProfile(std::optional< QString > requestedProfile) {
228+
void Settings::loadProfile(std::optional< std::string > requestedProfile) {
229229
Profiles &profiles = Global::get().profiles;
230230

231-
QString profileName;
231+
std::string profileName;
232232
if (!requestedProfile) {
233233
profileName = profiles.activeProfileName;
234234
} else {
235235
profileName = requestedProfile.value();
236236
}
237237

238238
if (!profiles.allProfiles.contains(profileName)) {
239-
qWarning("Failed to load settings profile '%s'. Falling back to '%s'...", qUtf8Printable(profileName),
240-
qUtf8Printable(Profiles::s_default_profile_name));
239+
qWarning("Failed to load settings profile '%s'. Falling back to '%s'...",
240+
qUtf8Printable(QString::fromStdString(profileName)),
241+
qUtf8Printable(QString::fromStdString(Profiles::s_default_profile_name)));
241242
profileName = Profiles::s_default_profile_name;
242243

243244
if (!profiles.allProfiles.contains(profileName)) {
244-
qWarning("Failed to load fallback settings profile '%s'", qUtf8Printable(Profiles::s_default_profile_name));
245+
qWarning("Failed to load fallback settings profile '%s'",
246+
qUtf8Printable(QString::fromStdString(Profiles::s_default_profile_name)));
245247
return;
246248
}
247249
}
248250

249-
qInfo("Loading settings profile '%s'", qUtf8Printable(profileName));
251+
qInfo("Loading settings profile '%s'", qUtf8Printable(QString::fromStdString(profileName)));
250252

251253
*this = profiles.allProfiles[profileName];
252254
profiles.activeProfileName = profileName;
@@ -437,8 +439,8 @@ std::size_t qHash(const ChannelTarget &target) {
437439
return qHash(target.channelID);
438440
}
439441

440-
const QString Profiles::s_default_profile_name = QLatin1String("default");
441-
const int Profiles::s_current_settings_version = 2;
442+
const std::string Profiles::s_default_profile_name = "default";
443+
const int Profiles::s_current_settings_version = 2;
442444

443445
const QString Settings::cqsDefaultPushClickOn = QLatin1String(":/on.ogg");
444446
const QString Settings::cqsDefaultPushClickOff = QLatin1String(":/off.ogg");

src/mumble/Settings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ struct OverlaySettings {
189189
};
190190

191191
struct Profiles {
192-
static const QString s_default_profile_name;
192+
static const std::string s_default_profile_name;
193193
static const int s_current_settings_version;
194194

195-
int settings_version = s_current_settings_version;
196-
QString activeProfileName = s_default_profile_name;
197-
QMap< QString, Settings > allProfiles = {};
195+
int settings_version = s_current_settings_version;
196+
std::string activeProfileName = s_default_profile_name;
197+
QMap< std::string, Settings > allProfiles = {};
198198
};
199199

200200
struct Settings {
@@ -585,7 +585,7 @@ struct Settings {
585585
void save(const QString &path) const;
586586
void save() const;
587587

588-
void loadProfile(std::optional< QString > requestedProfile = {});
588+
void loadProfile(std::optional< std::string > requestedProfile = {});
589589
void load(const QString &path);
590590
void load();
591591

0 commit comments

Comments
 (0)