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

@ -159,18 +159,18 @@ void DivePlannerWidget::settingsChanged()
}
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, maxDepth, 1, this));
ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(DivePlannerPointsModel::instance()->getSurfacePressure()), NULL,NULL));
ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(DivePlannerPointsModel::instance()->getSurfacePressure()), NULL, NULL));
ui.atmHeight->blockSignals(false);
ui.dateEdit->setDisplayFormat(prefs.date_format);
ui.startTime->setDisplayFormat(prefs.time_format);
ui.dateEdit->setDisplayFormat(QString::fromStdString(prefs.date_format));
ui.startTime->setDisplayFormat(QString::fromStdString(prefs.time_format));
}
void DivePlannerWidget::atmPressureChanged(const int pressure)
{
DivePlannerPointsModel::instance()->setSurfacePressure(pressure);
ui.atmHeight->blockSignals(true);
ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(pressure), NULL,NULL));
ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(pressure), NULL, NULL));
ui.atmHeight->blockSignals(false);
}

View file

@ -283,13 +283,13 @@ void FilterConstraintWidget::update()
{
// The user might have changed the date and/or time format. Let's update the widgets.
if (dateFrom)
dateFrom->setDisplayFormat(prefs.date_format);
dateFrom->setDisplayFormat(QString::fromStdString(prefs.date_format));
if (dateTo)
dateTo->setDisplayFormat(prefs.date_format);
dateTo->setDisplayFormat(QString::fromStdString(prefs.date_format));
if (timeFrom)
timeFrom->setDisplayFormat(prefs.time_format);
timeFrom->setDisplayFormat(QString::fromStdString(prefs.time_format));
if (timeTo)
timeTo->setDisplayFormat(prefs.time_format);
timeTo->setDisplayFormat(QString::fromStdString(prefs.time_format));
QModelIndex idx = model->index(row, 0);
setIndex(negate.get(), idx, FilterConstraintModel::NEGATE_INDEX_ROLE);

View file

@ -272,7 +272,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
void LocationInformationWidget::on_GPSbutton_clicked()
{
QFileInfo finfo(system_default_directory());
QFileInfo finfo(QString::fromStdString(system_default_directory()));
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select GPS file to open"),
finfo.absolutePath(),

View file

@ -549,8 +549,8 @@ void MainWindow::updateLastUsedDir(const QString &dir)
static QString get_current_filename()
{
return existing_filename.empty() ? QString(prefs.default_filename)
: QString::fromStdString(existing_filename);
return QString::fromStdString(existing_filename.empty() ? prefs.default_filename
: existing_filename);
}
void MainWindow::on_actionPrint_triggered()
{
@ -1100,7 +1100,7 @@ void MainWindow::loadRecentFiles()
QString file = s.value(key).toString();
// never add our cloud URL to the recent files
if (file.startsWith(prefs.cloud_base_url))
if (file.startsWith(QString::fromStdString(prefs.cloud_base_url)))
continue;
// but allow local git repos
QRegularExpression gitrepo("(.*)\\[[^]]+]");
@ -1138,7 +1138,7 @@ void MainWindow::updateRecentFilesMenu()
void MainWindow::addRecentFile(const QString &file, bool update)
{
// never add Subsurface cloud file to the recent files - it has its own menu entry
if (file.startsWith(prefs.cloud_base_url))
if (file.startsWith(QString::fromStdString(prefs.cloud_base_url)))
return;
QString localFile = QDir::toNativeSeparators(file);
int index = recentFiles.indexOf(localFile);
@ -1201,7 +1201,7 @@ int MainWindow::file_save_as()
selection_dialog.setFileMode(QFileDialog::AnyFile);
selection_dialog.setDefaultSuffix("");
if (default_filename.empty()) {
QFileInfo defaultFile(system_default_filename());
QFileInfo defaultFile(QString::fromStdString(system_default_filename()));
selection_dialog.setDirectory(qPrintable(defaultFile.absolutePath()));
}
/* if the exit/cancel button is pressed return */
@ -1231,7 +1231,6 @@ int MainWindow::file_save_as()
int MainWindow::file_save()
{
const char *current_default;
bool is_cloud = false;
if (existing_filename.empty())
@ -1241,11 +1240,11 @@ int MainWindow::file_save()
if (is_cloud && !saveToCloudOK())
return -1;
current_default = prefs.default_filename;
const std::string &current_default = prefs.default_filename;
if (existing_filename == current_default) {
/* if we are using the default filename the directory
* that we are creating the file in may not exist */
QDir current_def_dir = QFileInfo(current_default).absoluteDir();
QDir current_def_dir = QFileInfo(QString::fromStdString(current_default)).absoluteDir();
if (!current_def_dir.exists())
current_def_dir.mkpath(current_def_dir.absolutePath());
}

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();

View file

@ -85,8 +85,8 @@ TabDiveNotes::TabDiveNotes(MainTab *parent) : TabBase(parent),
void TabDiveNotes::updateDateTimeFields()
{
ui.dateEdit->setDisplayFormat(prefs.date_format);
ui.timeEdit->setDisplayFormat(prefs.time_format);
ui.dateEdit->setDisplayFormat(QString::fromStdString(prefs.date_format));
ui.timeEdit->setDisplayFormat(QString::fromStdString(prefs.time_format));
}
void TabDiveNotes::closeWarning()