preferences: use std::string in struct preferences

This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-13 22:59:32 +02:00 committed by bstoeger
parent 82fc9de40b
commit ccdd92aeb7
78 changed files with 645 additions and 694 deletions

View file

@ -30,8 +30,8 @@ void PreferencesCloud::on_resetPassword_clicked()
void PreferencesCloud::refreshSettings()
{
ui->cloud_storage_email->setText(prefs.cloud_storage_email);
ui->cloud_storage_password->setText(prefs.cloud_storage_password);
ui->cloud_storage_email->setText(QString::fromStdString(prefs.cloud_storage_email));
ui->cloud_storage_password->setText(QString::fromStdString(prefs.cloud_storage_password));
ui->save_password_local->setChecked(prefs.save_password_local);
updateCloudAuthenticationState();
}
@ -57,19 +57,19 @@ void PreferencesCloud::syncSettings()
}
if (!reg.match(email).hasMatch() || (!newpassword.isEmpty() && !reg.match(newpassword).hasMatch())) {
QMessageBox::warning(this, tr("Warning"), emailpasswordformatwarning);
ui->cloud_storage_new_passwd->setText("");
ui->cloud_storage_new_passwd->setText(QString());
return;
}
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesCloud::updateCloudAuthenticationState);
connect(cloudAuth, &CloudStorageAuthenticate::passwordChangeSuccessful, this, &PreferencesCloud::passwordUpdateSuccessful);
cloudAuth->backend(email, password, "", newpassword);
ui->cloud_storage_new_passwd->setText("");
ui->cloud_storage_new_passwd->setText(QString());
}
} else if (prefs.cloud_verification_status == qPrefCloudStorage::CS_UNKNOWN ||
prefs.cloud_verification_status == qPrefCloudStorage::CS_INCORRECT_USER_PASSWD ||
email != prefs.cloud_storage_email ||
password != prefs.cloud_storage_password) {
email.toStdString() != prefs.cloud_storage_email ||
password.toStdString() != prefs.cloud_storage_password) {
// different credentials - reset verification status
int oldVerificationStatus = cloud->cloud_verification_status();
@ -104,7 +104,7 @@ void PreferencesCloud::syncSettings()
cloud->set_save_password_local(ui->save_password_local->isChecked());
cloud->set_cloud_storage_password(password);
cloud->set_cloud_verification_status(prefs.cloud_verification_status);
cloud->set_cloud_base_url(prefs.cloud_base_url);
cloud->set_cloud_base_url(QString::fromStdString(prefs.cloud_base_url));
}
void PreferencesCloud::updateCloudAuthenticationState()
@ -131,5 +131,5 @@ void PreferencesCloud::updateCloudAuthenticationState()
void PreferencesCloud::passwordUpdateSuccessful()
{
ui->cloud_storage_password->setText(prefs.cloud_storage_password);
ui->cloud_storage_password->setText(QString::fromStdString(prefs.cloud_storage_password));
}

View file

@ -54,11 +54,11 @@ void PreferencesLanguage::refreshSettings()
ui->languageSystemDefault->setChecked(prefs.locale.use_system_language);
ui->timeFormatSystemDefault->setChecked(!prefs.time_format_override);
ui->dateFormatSystemDefault->setChecked(!prefs.date_format_override);
ui->timeFormatEntry->setCurrentText(prefs.time_format);
ui->dateFormatEntry->setCurrentText(prefs.date_format);
ui->shortDateFormatEntry->setText(prefs.date_format_short);
ui->timeFormatEntry->setCurrentText(QString::fromStdString(prefs.time_format));
ui->dateFormatEntry->setCurrentText(QString::fromStdString(prefs.date_format));
ui->shortDateFormatEntry->setText(QString::fromStdString(prefs.date_format_short));
QAbstractItemModel *m = ui->languageDropdown->model();
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, QString(prefs.locale.lang_locale).replace("-", "_"));
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, QString::fromStdString(prefs.locale.lang_locale).replace("-", "_"));
if (languages.count())
ui->languageDropdown->setCurrentIndex(languages.first().row());
}
@ -69,9 +69,9 @@ void PreferencesLanguage::syncSettings()
QString currentText = ui->languageDropdown->currentText();
if (useSystemLang != ui->languageSystemDefault->isChecked() ||
(!useSystemLang && currentText != prefs.locale.language)) {
(!useSystemLang && currentText.toStdString() != prefs.locale.language)) {
// remove the googlemaps cache folder on language change
QDir googlecachedir(QString(system_default_directory()).append("/googlemaps"));
QDir googlecachedir(QString::fromStdString(system_default_directory() + "/googlemaps"));
googlecachedir.removeRecursively();
QMessageBox::warning(this, tr("Restart required"),

View file

@ -24,7 +24,7 @@ PreferencesLog::~PreferencesLog()
void PreferencesLog::on_chooseFile_clicked()
{
QFileInfo fi(system_default_filename());
QFileInfo fi(QString::fromStdString(system_default_filename()));
QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface files") + " (*.ssrf *.xml)");
if (!choosenFileName.isEmpty())
@ -34,7 +34,7 @@ void PreferencesLog::on_chooseFile_clicked()
void PreferencesLog::on_btnUseDefaultFile_toggled(bool toggle)
{
if (toggle) {
ui->defaultfilename->setText(system_default_filename());
ui->defaultfilename->setText(QString::fromStdString(system_default_filename()));
ui->defaultfilename->setEnabled(false);
} else {
ui->defaultfilename->setEnabled(true);

View file

@ -41,7 +41,7 @@ void PreferencesMedia::checkFfmpegExecutable()
void PreferencesMedia::on_ffmpegFile_clicked()
{
QFileInfo fi(system_default_filename());
QFileInfo fi(QString::fromStdString(system_default_filename()));
QString ffmpegFileName = QFileDialog::getOpenFileName(this, tr("Select ffmpeg executable"));
if (!ffmpegFileName.isEmpty()) {

View file

@ -27,11 +27,11 @@ PreferencesNetwork::~PreferencesNetwork()
void PreferencesNetwork::refreshSettings()
{
ui->proxyHost->setText(prefs.proxy_host);
ui->proxyHost->setText(QString::fromStdString(prefs.proxy_host));
ui->proxyPort->setValue(prefs.proxy_port);
ui->proxyAuthRequired->setChecked(prefs.proxy_auth);
ui->proxyUsername->setText(prefs.proxy_user);
ui->proxyPassword->setText(prefs.proxy_pass);
ui->proxyUsername->setText(QString::fromStdString(prefs.proxy_user));
ui->proxyPassword->setText(QString::fromStdString(prefs.proxy_pass));
ui->proxyType->setCurrentIndex(ui->proxyType->findData(prefs.proxy_type));
}
@ -49,9 +49,8 @@ void PreferencesNetwork::syncSettings()
void PreferencesNetwork::proxyType_changed(int idx)
{
if (idx == -1) {
if (idx < 0)
return;
}
int proxyType = ui->proxyType->itemData(idx).toInt();
bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy);

View file

@ -37,12 +37,6 @@ static bool abstractpreferenceswidget_lessthan(const AbstractPreferencesWidget *
PreferencesDialog::PreferencesDialog()
{
//FIXME: This looks wrong.
//QSettings s;
//s.beginGroup("GeneralSettings");
//s.setValue("default_directory", system_default_directory());
//s.endGroup();
setWindowIcon(QIcon(":subsurface-icon"));
setWindowTitle(tr("Preferences"));
pagesList = new QListWidget();
@ -130,7 +124,7 @@ void PreferencesDialog::cancelRequested()
void PreferencesDialog::defaultsRequested()
{
copy_prefs(&default_prefs, &prefs);
prefs = default_prefs;
refreshPages();
emit diveListNotifier.settingsChanged();
accept();