From e49d6213ad129284a45d53c3fcdc03249e84efe2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 3 Sep 2015 14:20:19 -0300 Subject: Move qt-ui to desktop-widgets Since we have now destkop and mobile versions, 'qt-ui' was a very poor name choice for a folder that contains only destkop-enabled widgets. Also, move the graphicsview-common.h/cpp to subsurface-core because it doesn't depend on qgraphicsview, it merely implements all the colors that we use throughout Subsurface, and we will use colors on both desktop and mobile versions Same thing applies for metrics.h/cpp Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 559 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 559 insertions(+) create mode 100644 desktop-widgets/preferences.cpp (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp new file mode 100644 index 000000000..6450c41cb --- /dev/null +++ b/desktop-widgets/preferences.cpp @@ -0,0 +1,559 @@ +#include "preferences.h" +#include "mainwindow.h" +#include "models.h" +#include "divelocationmodel.h" +#include "prefs-macros.h" +#include "qthelper.h" +#include "subsurfacestartup.h" + +#include +#include +#include +#include +#include +#include + +#include "subsurfacewebservices.h" + +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) +#include "socialnetworks.h" +#include +#endif + +PreferencesDialog *PreferencesDialog::instance() +{ + static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance()); + return dialog; +} + +PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) +{ + ui.setupUi(this); + setAttribute(Qt::WA_QuitOnClose, false); + +#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT) + for (int i = 0; i < ui.listWidget->count(); i++) { + if (ui.listWidget->item(i)->text() == "Facebook") { + delete ui.listWidget->item(i); + QWidget *fbpage = ui.stackedWidget->widget(i); + ui.stackedWidget->removeWidget(fbpage); + } + } +#endif + + ui.proxyType->clear(); + ui.proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); + ui.proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); + ui.proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); + ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); + ui.proxyType->setCurrentIndex(-1); + + ui.first_item->setModel(GeoReferencingOptionsModel::instance()); + ui.second_item->setModel(GeoReferencingOptionsModel::instance()); + ui.third_item->setModel(GeoReferencingOptionsModel::instance()); + // Facebook stuff: +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + FacebookManager *fb = FacebookManager::instance(); + facebookWebView = new QWebView(this); + ui.fbWebviewContainer->layout()->addWidget(facebookWebView); + if (fb->loggedIn()) { + facebookLoggedIn(); + } else { + facebookDisconnect(); + } + connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin); + connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn); + connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout); + connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); +#endif + connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); + connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); + connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int))); + // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); + QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); + connect(close, SIGNAL(activated()), this, SLOT(close())); + QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); + connect(quit, SIGNAL(activated()), parent, SLOT(close())); + loadSettings(); + setUiFromPrefs(); + rememberPrefs(); +} + +void PreferencesDialog::facebookLoggedIn() +{ +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + ui.fbDisconnect->show(); + ui.fbWebviewContainer->hide(); + ui.fbWebviewContainer->setEnabled(false); + ui.FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below")); +#endif +} + +void PreferencesDialog::facebookDisconnect() +{ +#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) + // remove the connect/disconnect button + // and instead add the login view + ui.fbDisconnect->hide(); + ui.fbWebviewContainer->show(); + ui.fbWebviewContainer->setEnabled(true); + ui.FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline")); + if (facebookWebView) { + facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); + facebookWebView->setUrl(FacebookManager::instance()->connectUrl()); + } +#endif +} + +void PreferencesDialog::cloudPinNeeded() +{ + ui.cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); + ui.cloudDefaultFile->setEnabled(true); + } else { + ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); + if (ui.cloudDefaultFile->isChecked()) + ui.noDefaultFile->setChecked(true); + ui.cloudDefaultFile->setEnabled(false); + } + MainWindow::instance()->enableDisableCloudActions(); +} + +#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" +void PreferencesDialog::gflowChanged(int gf) +{ + ui.gflow->setStyleSheet(DANGER_GF); +} +void PreferencesDialog::gfhighChanged(int gf) +{ + ui.gfhigh->setStyleSheet(DANGER_GF); +} +#undef DANGER_GF + +void PreferencesDialog::showEvent(QShowEvent *event) +{ + setUiFromPrefs(); + rememberPrefs(); + QDialog::showEvent(event); +} + +void PreferencesDialog::setUiFromPrefs() +{ + // graphs + ui.pheThreshold->setValue(prefs.pp_graphs.phe_threshold); + ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold); + ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); + ui.maxpo2->setValue(prefs.modpO2); + ui.red_ceiling->setChecked(prefs.redceiling); + ui.units_group->setEnabled(ui.personalize->isChecked()); + + ui.gflow->setValue(prefs.gflow); + ui.gfhigh->setValue(prefs.gfhigh); + ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); + ui.show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); + ui.show_ccr_sensors->setChecked(prefs.show_ccr_sensors); + ui.defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); + ui.psro2rate->setValue(prefs.o2consumption / 1000.0); + ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); + + // units + if (prefs.unit_system == METRIC) + ui.metric->setChecked(true); + else if (prefs.unit_system == IMPERIAL) + ui.imperial->setChecked(true); + else + ui.personalize->setChecked(true); + ui.gpsTraditional->setChecked(prefs.coordinates_traditional); + ui.gpsDecimal->setChecked(!prefs.coordinates_traditional); + + ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS); + ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); + ui.meter->setChecked(prefs.units.length == units::METERS); + ui.feet->setChecked(prefs.units.length == units::FEET); + ui.bar->setChecked(prefs.units.pressure == units::BAR); + ui.psi->setChecked(prefs.units.pressure == units::PSI); + ui.liter->setChecked(prefs.units.volume == units::LITER); + ui.cuft->setChecked(prefs.units.volume == units::CUFT); + ui.kg->setChecked(prefs.units.weight == units::KG); + ui.lbs->setChecked(prefs.units.weight == units::LBS); + + ui.font->setCurrentFont(QString(prefs.divelist_font)); + ui.fontsize->setValue(prefs.font_size); + ui.defaultfilename->setText(prefs.default_filename); + ui.noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); + ui.cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); + ui.localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui.default_cylinder->clear(); + for (int i = 0; tank_info[i].name != NULL; i++) { + ui.default_cylinder->addItem(tank_info[i].name); + if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) + ui.default_cylinder->setCurrentIndex(i); + } + ui.displayinvalid->setChecked(prefs.display_invalid_dives); + ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); + ui.show_average_depth->setChecked(prefs.show_average_depth); + ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); + ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); + ui.velocitySlider->setValue(prefs.animation_speed); + + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); + filterModel->setSourceModel(LanguageModel::instance()); + filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + ui.languageView->setModel(filterModel); + filterModel->sort(0); + connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString))); + + QSettings s; + + ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); + ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + + s.beginGroup("Language"); + ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); + QAbstractItemModel *m = ui.languageView->model(); + QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); + if (languages.count()) + ui.languageView->setCurrentIndex(languages.first()); + + s.endGroup(); + + ui.proxyHost->setText(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.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); + ui.btnUseDefaultFile->setChecked(prefs.use_default_file); + + ui.cloud_storage_email->setText(prefs.cloud_storage_email); + ui.cloud_storage_password->setText(prefs.cloud_storage_password); + ui.save_password_local->setChecked(prefs.save_password_local); + cloudPinNeeded(); + ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); + ui.default_uid->setText(prefs.userid); + + // GeoManagement +#ifdef DISABLED + ui.enable_geocoding->setChecked( prefs.geocoding.enable_geocoding ); + ui.parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps); + ui.tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives); +#endif + ui.first_item->setCurrentIndex(prefs.geocoding.category[0]); + ui.second_item->setCurrentIndex(prefs.geocoding.category[1]); + ui.third_item->setCurrentIndex(prefs.geocoding.category[2]); +} + +void PreferencesDialog::restorePrefs() +{ + prefs = oldPrefs; + setUiFromPrefs(); +} + +void PreferencesDialog::rememberPrefs() +{ + oldPrefs = prefs; +} + +void PreferencesDialog::syncSettings() +{ + QSettings s; + + s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); + set_save_userid_local(ui.save_uid_local->checkState()); + + // Graph + s.beginGroup("TecDetails"); + SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui.pheThreshold->value()); + SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui.po2Threshold->value()); + SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui.pn2Threshold->value()); + SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui.maxpo2->value()); + SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui.red_ceiling->isChecked()); + SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui.gflow->value()); + SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui.gfhigh->value()); + SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui.gf_low_at_maxdepth->isChecked()); + SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui.show_ccr_setpoint->isChecked()); + SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui.show_ccr_sensors->isChecked()); + SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui.display_unused_tanks->isChecked()); + SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); + s.endGroup(); + + // Units + s.beginGroup("Units"); + QString unitSystem[] = {"metric", "imperial", "personal"}; + short unitValue = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE); + SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); + s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); + s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS); + s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR); + s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); + s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); + s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui.gpsTraditional->isChecked()); + s.endGroup(); + + // Defaults + s.beginGroup("GeneralSettings"); + s.setValue("default_filename", ui.defaultfilename->text()); + s.setValue("default_cylinder", ui.default_cylinder->currentText()); + s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked()); + if (ui.noDefaultFile->isChecked()) + s.setValue("default_file_behavior", NO_DEFAULT_FILE); + else if (ui.localDefaultFile->isChecked()) + s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); + else if (ui.cloudDefaultFile->isChecked()) + s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); + s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); + s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); + s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); + s.endGroup(); + + s.beginGroup("Display"); + SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui.font->currentFont().toString(), ui.font->currentFont()); + SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui.fontsize->value()); + s.setValue("displayinvalid", ui.displayinvalid->isChecked()); + s.endGroup(); + s.sync(); + + // Locale + QLocale loc; + s.beginGroup("Language"); + bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); + if (useSystemLang != ui.languageSystemDefault->isChecked() || + (!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) { + QMessageBox::warning(MainWindow::instance(), tr("Restart required"), + tr("To correctly load a new language you must restart Subsurface.")); + } + s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); + s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); + s.endGroup(); + + // Animation + s.beginGroup("Animations"); + s.setValue("animation_speed", ui.velocitySlider->value()); + s.endGroup(); + + s.beginGroup("Network"); + s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); + s.setValue("proxy_host", ui.proxyHost->text()); + s.setValue("proxy_port", ui.proxyPort->value()); + SB("proxy_auth", ui.proxyAuthRequired); + s.setValue("proxy_user", ui.proxyUsername->text()); + s.setValue("proxy_pass", ui.proxyPassword->text()); + s.endGroup(); + + s.beginGroup("CloudStorage"); + QString email = ui.cloud_storage_email->text(); + QString password = ui.cloud_storage_password->text(); + QString newpassword = ui.cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui.cloud_storage_new_passwd->setText(""); + free(prefs.cloud_storage_newpassword); + prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + + // different credentials - reset verification status + prefs.cloud_verification_status = CS_UNKNOWN; + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password); + } + } + } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { + QString pin = ui.cloud_storage_pin->text(); + if (!pin.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); + } + } + SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); + SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked()); + if (ui.save_password_local->isChecked()) { + SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); + } else { + s.remove("password"); + free(prefs.cloud_storage_password); + prefs.cloud_storage_password = strdup(qPrintable(password)); + } + SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); + SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked()); + + // at this point we intentionally do not have a UI for changing this + // it could go into some sort of "advanced setup" or something + SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); + s.endGroup(); + + s.beginGroup("geocoding"); +#ifdef DISABLED + s.setValue("enable_geocoding", ui.enable_geocoding->isChecked()); + s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked()); + s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked()); +#endif + s.setValue("cat0", ui.first_item->currentIndex()); + s.setValue("cat1", ui.second_item->currentIndex()); + s.setValue("cat2", ui.third_item->currentIndex()); + s.endGroup(); + + loadSettings(); + emit settingsChanged(); +} + +void PreferencesDialog::loadSettings() +{ + // This code was on the mainwindow, it should belong nowhere, but since we didn't + // correctly fixed this code yet ( too much stuff on the code calling preferences ) + // force this here. + loadPreferences(); + QSettings s; + QVariant v; + + ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); + ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + + ui.defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui.btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui.chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); +} + +void PreferencesDialog::buttonClicked(QAbstractButton *button) +{ + switch (ui.buttonBox->standardButton(button)) { + case QDialogButtonBox::Discard: + restorePrefs(); + syncSettings(); + close(); + break; + case QDialogButtonBox::Apply: + syncSettings(); + break; + case QDialogButtonBox::FirstButton: + syncSettings(); + close(); + break; + default: + break; // ignore warnings. + } +} +#undef SB + +void PreferencesDialog::on_chooseFile_clicked() +{ + QFileInfo fi(system_default_filename()); + QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); + + if (!choosenFileName.isEmpty()) + ui.defaultfilename->setText(choosenFileName); +} + +void PreferencesDialog::on_resetSettings_clicked() +{ + QSettings s; + + QMessageBox response(this); + response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + response.setDefaultButton(QMessageBox::Cancel); + response.setWindowTitle(tr("Warning")); + response.setText(tr("If you click OK, all settings of Subsurface will be reset to their default values. This will be applied immediately.")); + response.setWindowModality(Qt::WindowModal); + + int result = response.exec(); + if (result == QMessageBox::Ok) { + copy_prefs(&default_prefs, &prefs); + setUiFromPrefs(); + Q_FOREACH (QString key, s.allKeys()) { + s.remove(key); + } + syncSettings(); + close(); + } +} + +void PreferencesDialog::passwordUpdateSuccessfull() +{ + ui.cloud_storage_password->setText(prefs.cloud_storage_password); +} + +void PreferencesDialog::emitSettingsChanged() +{ + emit settingsChanged(); +} + +void PreferencesDialog::proxyType_changed(int idx) +{ + if (idx == -1) { + return; + } + + int proxyType = ui.proxyType->itemData(idx).toInt(); + bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); + ui.proxyHost->setEnabled(hpEnabled); + ui.proxyPort->setEnabled(hpEnabled); + ui.proxyAuthRequired->setEnabled(hpEnabled); + ui.proxyUsername->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); + ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); + ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); +} + +void PreferencesDialog::on_btnUseDefaultFile_toggled(bool toggle) +{ + if (toggle) { + ui.defaultfilename->setText(system_default_filename()); + ui.defaultfilename->setEnabled(false); + } else { + ui.defaultfilename->setEnabled(true); + } +} + +void PreferencesDialog::on_noDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = NO_DEFAULT_FILE; +} + +void PreferencesDialog::on_localDefaultFile_toggled(bool toggle) +{ + ui.defaultfilename->setEnabled(toggle); + ui.btnUseDefaultFile->setEnabled(toggle); + ui.chooseFile->setEnabled(toggle); + prefs.default_file_behavior = LOCAL_DEFAULT_FILE; +} + +void PreferencesDialog::on_cloudDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = CLOUD_DEFAULT_FILE; +} -- cgit v1.2.3-70-g09d2 From 1d2d046c0f80d8884d783aad57340c9b6867985a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 25 Sep 2015 16:15:37 -0300 Subject: Preferences: Port the default preferences to the new system Simple port of the default preferences to the new preferences structure. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 83 +------ desktop-widgets/preferences.h | 5 - desktop-widgets/preferences.ui | 276 +-------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + .../preferences/preferences_defaults.cpp | 115 +++++++++ desktop-widgets/preferences/preferences_defaults.h | 30 +++ .../preferences/preferences_defaults.ui | 251 +++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 402 insertions(+), 361 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_defaults.cpp create mode 100644 desktop-widgets/preferences/preferences_defaults.h create mode 100644 desktop-widgets/preferences/preferences_defaults.ui (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 6450c41cb..cb19ce759 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -118,12 +118,8 @@ void PreferencesDialog::cloudPinNeeded() ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); if (prefs.cloud_verification_status == CS_VERIFIED) { ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); - ui.cloudDefaultFile->setEnabled(true); } else { ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); - if (ui.cloudDefaultFile->isChecked()) - ui.noDefaultFile->setChecked(true); - ui.cloudDefaultFile->setEnabled(false); } MainWindow::instance()->enableDisableCloudActions(); } @@ -186,24 +182,11 @@ void PreferencesDialog::setUiFromPrefs() ui.kg->setChecked(prefs.units.weight == units::KG); ui.lbs->setChecked(prefs.units.weight == units::LBS); - ui.font->setCurrentFont(QString(prefs.divelist_font)); - ui.fontsize->setValue(prefs.font_size); - ui.defaultfilename->setText(prefs.default_filename); - ui.noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); - ui.cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); - ui.localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.default_cylinder->clear(); - for (int i = 0; tank_info[i].name != NULL; i++) { - ui.default_cylinder->addItem(tank_info[i].name); - if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) - ui.default_cylinder->setCurrentIndex(i); - } - ui.displayinvalid->setChecked(prefs.display_invalid_dives); ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); ui.show_average_depth->setChecked(prefs.show_average_depth); ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); - ui.velocitySlider->setValue(prefs.animation_speed); + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); filterModel->setSourceModel(LanguageModel::instance()); @@ -232,7 +215,7 @@ void PreferencesDialog::setUiFromPrefs() ui.proxyUsername->setText(prefs.proxy_user); ui.proxyPassword->setText(prefs.proxy_pass); ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); - ui.btnUseDefaultFile->setChecked(prefs.use_default_file); + ui.cloud_storage_email->setText(prefs.cloud_storage_email); ui.cloud_storage_password->setText(prefs.cloud_storage_password); @@ -302,27 +285,11 @@ void PreferencesDialog::syncSettings() // Defaults s.beginGroup("GeneralSettings"); - s.setValue("default_filename", ui.defaultfilename->text()); - s.setValue("default_cylinder", ui.default_cylinder->currentText()); - s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked()); - if (ui.noDefaultFile->isChecked()) - s.setValue("default_file_behavior", NO_DEFAULT_FILE); - else if (ui.localDefaultFile->isChecked()) - s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); - else if (ui.cloudDefaultFile->isChecked()) - s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); s.endGroup(); - s.beginGroup("Display"); - SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui.font->currentFont().toString(), ui.font->currentFont()); - SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui.fontsize->value()); - s.setValue("displayinvalid", ui.displayinvalid->isChecked()); - s.endGroup(); - s.sync(); - // Locale QLocale loc; s.beginGroup("Language"); @@ -336,11 +303,6 @@ void PreferencesDialog::syncSettings() s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); s.endGroup(); - // Animation - s.beginGroup("Animations"); - s.setValue("animation_speed", ui.velocitySlider->value()); - s.endGroup(); - s.beginGroup("Network"); s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); s.setValue("proxy_host", ui.proxyHost->text()); @@ -445,10 +407,6 @@ void PreferencesDialog::loadSettings() ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - ui.defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); } void PreferencesDialog::buttonClicked(QAbstractButton *button) @@ -472,15 +430,6 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) } #undef SB -void PreferencesDialog::on_chooseFile_clicked() -{ - QFileInfo fi(system_default_filename()); - QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); - - if (!choosenFileName.isEmpty()) - ui.defaultfilename->setText(choosenFileName); -} - void PreferencesDialog::on_resetSettings_clicked() { QSettings s; @@ -529,31 +478,3 @@ void PreferencesDialog::proxyType_changed(int idx) ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); } - -void PreferencesDialog::on_btnUseDefaultFile_toggled(bool toggle) -{ - if (toggle) { - ui.defaultfilename->setText(system_default_filename()); - ui.defaultfilename->setEnabled(false); - } else { - ui.defaultfilename->setEnabled(true); - } -} - -void PreferencesDialog::on_noDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = NO_DEFAULT_FILE; -} - -void PreferencesDialog::on_localDefaultFile_toggled(bool toggle) -{ - ui.defaultfilename->setEnabled(toggle); - ui.btnUseDefaultFile->setEnabled(toggle); - ui.chooseFile->setEnabled(toggle); - prefs.default_file_behavior = LOCAL_DEFAULT_FILE; -} - -void PreferencesDialog::on_cloudDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = CLOUD_DEFAULT_FILE; -} diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index 326b1f964..c05145611 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -24,7 +24,6 @@ signals: public slots: void buttonClicked(QAbstractButton *button); - void on_chooseFile_clicked(); void on_resetSettings_clicked(); void syncSettings(); void loadSettings(); @@ -33,10 +32,6 @@ slots: void gflowChanged(int gf); void gfhighChanged(int gf); void proxyType_changed(int idx); - void on_btnUseDefaultFile_toggled(bool toggle); - void on_noDefaultFile_toggled(bool toggle); - void on_localDefaultFile_toggled(bool toggle); - void on_cloudDefaultFile_toggled(bool toggle); void facebookLoggedIn(); void facebookDisconnect(); void cloudPinNeeded(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index de2d79b91..aa5dc4cb5 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -164,7 +164,7 @@ - 4 + 0 @@ -180,232 +180,6 @@ 5 - - - - Lists and tables - - - - 5 - - - - - Font - - - - - - - - - - Font size - - - - - - - - - - - - - Dives - - - - 5 - - - 5 - - - 5 - - - - - Default dive log file - - - - - - - - - No default file - - - defaultFileGroup - - - - - - - &Local default file - - - defaultFileGroup - - - - - - - Clo&ud storage default file - - - defaultFileGroup - - - - - - - - - Local dive log file - - - - - - - - - - - - Use default - - - true - - - - - - - ... - - - - - - - - - Display invalid - - - - - - - - - - - - - - - - - Default cylinder - - - - 5 - - - 5 - - - 5 - - - - - Use default cylinder - - - - - - - - - - - - - - - - - Animations - - - - 5 - - - - - Speed - - - - - - - 500 - - - Qt::Horizontal - - - - - - - 500 - - - - - - - - - - Clear all settings - - - - 5 - - - 5 - - - - - Reset all settings to their default value - - - - - - @@ -1788,38 +1562,6 @@ - - velocitySlider - valueChanged(int) - velocitySpinBox - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - - - velocitySpinBox - valueChanged(int) - velocitySlider - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - proxyAuthRequired toggled(bool) @@ -1852,22 +1594,6 @@ - - btnUseDefaultFile - toggled(bool) - chooseFile - setHidden(bool) - - - 236 - 44 - - - 236 - 44 - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 4eb2f7d23..c55d7b881 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -14,6 +14,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferencesdialog.cpp preferences_language.cpp preferences_georeference.cpp + preferences_defaults.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp new file mode 100644 index 000000000..637117105 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -0,0 +1,115 @@ +#include "preferences_defaults.h" +#include "ui_preferences_defaults.h" +#include "dive.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesDefaults::PreferencesDefaults(): AbstractPreferencesWidget(tr("Defaults"), QIcon(":defaults"), 0 ), ui(new Ui::PreferencesDefaults()) +{ + ui->setupUi(this); +} + +PreferencesDefaults::~PreferencesDefaults() +{ + delete ui; +} + +void PreferencesDefaults::on_chooseFile_clicked() +{ + QFileInfo fi(system_default_filename()); + QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); + + if (!choosenFileName.isEmpty()) + ui->defaultfilename->setText(choosenFileName); +} + + +void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle) +{ + if (toggle) { + ui->defaultfilename->setText(system_default_filename()); + ui->defaultfilename->setEnabled(false); + } else { + ui->defaultfilename->setEnabled(true); + } +} + +void PreferencesDefaults::on_noDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = NO_DEFAULT_FILE; +} + +void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle) +{ + ui->defaultfilename->setEnabled(toggle); + ui->btnUseDefaultFile->setEnabled(toggle); + ui->chooseFile->setEnabled(toggle); + prefs.default_file_behavior = LOCAL_DEFAULT_FILE; +} + +void PreferencesDefaults::on_cloudDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = CLOUD_DEFAULT_FILE; +} + +void PreferencesDefaults::refreshSettings() +{ + ui->font->setCurrentFont(QString(prefs.divelist_font)); + ui->fontsize->setValue(prefs.font_size); + ui->defaultfilename->setText(prefs.default_filename); + ui->noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); + ui->cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); + ui->localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + + ui->default_cylinder->clear(); + for (int i = 0; tank_info[i].name != NULL; i++) { + ui->default_cylinder->addItem(tank_info[i].name); + if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) + ui->default_cylinder->setCurrentIndex(i); + } + ui->displayinvalid->setChecked(prefs.display_invalid_dives); + ui->velocitySlider->setValue(prefs.animation_speed); + ui->btnUseDefaultFile->setChecked(prefs.use_default_file); + + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudDefaultFile->setEnabled(true); + } else { + if (ui->cloudDefaultFile->isChecked()) + ui->noDefaultFile->setChecked(true); + ui->cloudDefaultFile->setEnabled(false); + } + + ui->defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); +} + +void PreferencesDefaults::syncSettings() +{ + QSettings s; + s.beginGroup("GeneralSettings"); + s.setValue("default_filename", ui->defaultfilename->text()); + s.setValue("default_cylinder", ui->default_cylinder->currentText()); + s.setValue("use_default_file", ui->btnUseDefaultFile->isChecked()); + if (ui->noDefaultFile->isChecked()) + s.setValue("default_file_behavior", NO_DEFAULT_FILE); + else if (ui->localDefaultFile->isChecked()) + s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); + else if (ui->cloudDefaultFile->isChecked()) + s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); + s.endGroup(); + + s.beginGroup("Display"); + SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui->font->currentFont().toString(), ui->font->currentFont()); + SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui->fontsize->value()); + s.setValue("displayinvalid", ui->displayinvalid->isChecked()); + s.endGroup(); + s.sync(); + + // Animation + s.beginGroup("Animations"); + s.setValue("animation_speed", ui->velocitySlider->value()); + s.endGroup(); +} diff --git a/desktop-widgets/preferences/preferences_defaults.h b/desktop-widgets/preferences/preferences_defaults.h new file mode 100644 index 000000000..94de8b28a --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.h @@ -0,0 +1,30 @@ +#ifndef PREFERENCES_DEFAULTS_H +#define PREFERENCES_DEFAULTS_H + +#include "abstractpreferenceswidget.h" +#include "subsurface-core/pref.h" + +namespace Ui { + class PreferencesDefaults; +} + +class PreferencesDefaults : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesDefaults(); + virtual ~PreferencesDefaults(); + virtual void refreshSettings(); + virtual void syncSettings(); +public slots: + void on_chooseFile_clicked(); + void on_btnUseDefaultFile_toggled(bool toggled); + void on_noDefaultFile_toggled(bool toggled); + void on_localDefaultFile_toggled(bool toggled); + void on_cloudDefaultFile_toggled(bool toggled); + +private: + Ui::PreferencesDefaults *ui; +}; + + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui new file mode 100644 index 000000000..632e82763 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -0,0 +1,251 @@ + + + PreferencesDefaults + + + + 0 + 0 + 555 + 558 + + + + Form + + + + + + Lists and tables + + + + 5 + + + + + Font + + + + + + + + + + Font size + + + + + + + + + + + + + Dives + + + + 5 + + + 5 + + + 5 + + + + + Default dive log file + + + + + + + + + No default file + + + + + + + &Local default file + + + + + + + Clo&ud storage default file + + + + + + + + + Local dive log file + + + + + + + + + + + + Use default + + + true + + + + + + + ... + + + + + + + + + Display invalid + + + + + + + + + + + + + + + + + Default cylinder + + + + 5 + + + 5 + + + 5 + + + + + Use default cylinder + + + + + + + + + + + + + + + + + Animations + + + + 5 + + + + + Speed + + + + + + + 500 + + + Qt::Horizontal + + + + + + + 500 + + + + + + + + + + Clear all settings + + + + 5 + + + 5 + + + + + Reset all settings to their default value + + + + + + + + + + Qt::Vertical + + + + 0 + 195 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 3975994a9..6f66d856d 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -3,6 +3,7 @@ #include "abstractpreferenceswidget.h" #include "preferences_language.h" #include "preferences_georeference.h" +#include "preferences_defaults.h" #include #include @@ -35,6 +36,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesLanguage()); addPreferencePage(new PreferencesGeoreference()); + addPreferencePage(new PreferencesDefaults()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From c53615315e151a2790218c13898f128d561df1b9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 25 Sep 2015 16:25:05 -0300 Subject: Code cleanup Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 48 +------ desktop-widgets/preferences.ui | 268 +--------------------------------------- 2 files changed, 4 insertions(+), 312 deletions(-) (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index cb19ce759..2ce96bd77 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -48,10 +48,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); ui.proxyType->setCurrentIndex(-1); - ui.first_item->setModel(GeoReferencingOptionsModel::instance()); - ui.second_item->setModel(GeoReferencingOptionsModel::instance()); - ui.third_item->setModel(GeoReferencingOptionsModel::instance()); - // Facebook stuff: #if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) FacebookManager *fb = FacebookManager::instance(); facebookWebView = new QWebView(this); @@ -187,28 +183,11 @@ void PreferencesDialog::setUiFromPrefs() ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); - - QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); - filterModel->setSourceModel(LanguageModel::instance()); - filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - ui.languageView->setModel(filterModel); - filterModel->sort(0); - connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString))); - QSettings s; ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - s.beginGroup("Language"); - ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); - QAbstractItemModel *m = ui.languageView->model(); - QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); - if (languages.count()) - ui.languageView->setCurrentIndex(languages.first()); - - s.endGroup(); - ui.proxyHost->setText(prefs.proxy_host); ui.proxyPort->setValue(prefs.proxy_port); ui.proxyAuthRequired->setChecked(prefs.proxy_auth); @@ -222,17 +201,6 @@ void PreferencesDialog::setUiFromPrefs() ui.save_password_local->setChecked(prefs.save_password_local); cloudPinNeeded(); ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); - ui.default_uid->setText(prefs.userid); - - // GeoManagement -#ifdef DISABLED - ui.enable_geocoding->setChecked( prefs.geocoding.enable_geocoding ); - ui.parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps); - ui.tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives); -#endif - ui.first_item->setCurrentIndex(prefs.geocoding.category[0]); - ui.second_item->setCurrentIndex(prefs.geocoding.category[1]); - ui.third_item->setCurrentIndex(prefs.geocoding.category[2]); } void PreferencesDialog::restorePrefs() @@ -290,19 +258,6 @@ void PreferencesDialog::syncSettings() s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); s.endGroup(); - // Locale - QLocale loc; - s.beginGroup("Language"); - bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); - if (useSystemLang != ui.languageSystemDefault->isChecked() || - (!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) { - QMessageBox::warning(MainWindow::instance(), tr("Restart required"), - tr("To correctly load a new language you must restart Subsurface.")); - } - s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); - s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); - s.endGroup(); - s.beginGroup("Network"); s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); s.setValue("proxy_host", ui.proxyHost->text()); @@ -381,6 +336,7 @@ void PreferencesDialog::syncSettings() SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); s.endGroup(); +<<<<<<< HEAD s.beginGroup("geocoding"); #ifdef DISABLED s.setValue("enable_geocoding", ui.enable_geocoding->isChecked()); @@ -392,6 +348,8 @@ void PreferencesDialog::syncSettings() s.setValue("cat2", ui.third_item->currentIndex()); s.endGroup(); +======= +>>>>>>> Code Cleanup loadSettings(); emit settingsChanged(); } diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index aa5dc4cb5..a799d966c 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -83,16 +83,6 @@ -1 - - - Defaults - - - - :/subsurface-icon - - - Units @@ -113,16 +103,6 @@ - - - Language - - - - :/advanced - - - Network @@ -143,16 +123,6 @@ - - - Georeference - - - - :/georeference - - - @@ -164,37 +134,8 @@ - 0 + 3 - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -787,93 +728,6 @@ - - - - 0 - 0 - - - - - 5 - - - QLayout::SetNoConstraint - - - 5 - - - - - - 0 - 0 - - - - UI language - - - - - - System default - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Filter - - - - - - - - - - - - - - 0 - 0 - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - @@ -1200,94 +1054,6 @@ - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Dive Site Layout - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - / - - - - - - - - 0 - 0 - - - - - - - - / - - - - - - - - 0 - 0 - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - @@ -1370,38 +1136,6 @@ - - languageSystemDefault - toggled(bool) - languageView - setDisabled(bool) - - - 231 - 26 - - - 186 - 30 - - - - - languageSystemDefault - toggled(bool) - languageFilter - setDisabled(bool) - - - 231 - 26 - - - 185 - 20 - - - imperial toggled(bool) -- cgit v1.2.3-70-g09d2 From 57d7b59bdc62a5b01fa420bc420dbdcf1414a23a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 25 Sep 2015 17:07:04 -0300 Subject: Preferences: move units to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 39 -- desktop-widgets/preferences.ui | 489 +--------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + desktop-widgets/preferences/preferences_units.cpp | 60 +++ desktop-widgets/preferences/preferences_units.h | 21 + desktop-widgets/preferences/preferences_units.ui | 251 +++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 7 files changed, 336 insertions(+), 527 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_units.cpp create mode 100644 desktop-widgets/preferences/preferences_units.h create mode 100644 desktop-widgets/preferences/preferences_units.ui (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 2ce96bd77..672d75906 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -146,7 +146,6 @@ void PreferencesDialog::setUiFromPrefs() ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); ui.maxpo2->setValue(prefs.modpO2); ui.red_ceiling->setChecked(prefs.redceiling); - ui.units_group->setEnabled(ui.personalize->isChecked()); ui.gflow->setValue(prefs.gflow); ui.gfhigh->setValue(prefs.gfhigh); @@ -157,31 +156,8 @@ void PreferencesDialog::setUiFromPrefs() ui.psro2rate->setValue(prefs.o2consumption / 1000.0); ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); - // units - if (prefs.unit_system == METRIC) - ui.metric->setChecked(true); - else if (prefs.unit_system == IMPERIAL) - ui.imperial->setChecked(true); - else - ui.personalize->setChecked(true); - ui.gpsTraditional->setChecked(prefs.coordinates_traditional); - ui.gpsDecimal->setChecked(!prefs.coordinates_traditional); - - ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS); - ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); - ui.meter->setChecked(prefs.units.length == units::METERS); - ui.feet->setChecked(prefs.units.length == units::FEET); - ui.bar->setChecked(prefs.units.pressure == units::BAR); - ui.psi->setChecked(prefs.units.pressure == units::PSI); - ui.liter->setChecked(prefs.units.volume == units::LITER); - ui.cuft->setChecked(prefs.units.volume == units::CUFT); - ui.kg->setChecked(prefs.units.weight == units::KG); - ui.lbs->setChecked(prefs.units.weight == units::LBS); - ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); ui.show_average_depth->setChecked(prefs.show_average_depth); - ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); - ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); QSettings s; @@ -237,20 +213,6 @@ void PreferencesDialog::syncSettings() SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); s.endGroup(); - // Units - s.beginGroup("Units"); - QString unitSystem[] = {"metric", "imperial", "personal"}; - short unitValue = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE); - SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); - s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); - s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS); - s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR); - s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); - s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); - s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); - s.setValue("coordinates", ui.gpsTraditional->isChecked()); - s.endGroup(); - // Defaults s.beginGroup("GeneralSettings"); s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); @@ -391,7 +353,6 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) void PreferencesDialog::on_resetSettings_clicked() { QSettings s; - QMessageBox response(this); response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); response.setDefaultButton(QMessageBox::Cancel); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index a799d966c..12ba10d4b 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -83,16 +83,6 @@ -1 - - - Units - - - - :/units - - - Graph @@ -134,309 +124,8 @@ - 3 + 0 - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Unit system - - - - - - System - - - - - - - &Metric - - - buttonGroup_6 - - - - - - - Imperial - - - buttonGroup_6 - - - - - - - Personali&ze - - - buttonGroup_6 - - - - - - - - - - Individual settings - - - false - - - false - - - - - - Depth - - - - - - - meter - - - buttonGroup - - - - - - - feet - - - buttonGroup - - - - - - - Pressure - - - - - - - bar - - - buttonGroup_2 - - - - - - - psi - - - buttonGroup_2 - - - - - - - Volume - - - - - - - &liter - - - buttonGroup_3 - - - - - - - cu ft - - - buttonGroup_3 - - - - - - - Temperature - - - - - - - celsius - - - buttonGroup_4 - - - - - - - fahrenheit - - - buttonGroup_4 - - - - - - - Weight - - - - - - - kg - - - buttonGroup_5 - - - - - - - lbs - - - buttonGroup_5 - - - - - - - - - - - - Time units - - - - - - Ascent/descent speed denominator - - - - - - - Minutes - - - verticalSpeed - - - - - - - Seconds - - - verticalSpeed - - - - - - - - - - - - GPS coordinates - - - - - - Location Display - - - - - - - traditional (dms) - - - buttonGroup_7 - - - - - - - decimal - - - buttonGroup_7 - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -1120,182 +809,6 @@ - - personalize - toggled(bool) - units_group - setEnabled(bool) - - - 185 - 19 - - - 186 - 23 - - - - - imperial - toggled(bool) - feet - setChecked(bool) - - - 164 - 19 - - - 175 - 34 - - - - - metric - toggled(bool) - meter - setChecked(bool) - - - 142 - 19 - - - 153 - 34 - - - - - imperial - toggled(bool) - psi - setChecked(bool) - - - 164 - 19 - - - 175 - 33 - - - - - metric - toggled(bool) - bar - setChecked(bool) - - - 142 - 19 - - - 153 - 33 - - - - - imperial - toggled(bool) - cuft - setChecked(bool) - - - 164 - 19 - - - 175 - 31 - - - - - metric - toggled(bool) - liter - setChecked(bool) - - - 142 - 19 - - - 153 - 31 - - - - - imperial - toggled(bool) - fahrenheit - setChecked(bool) - - - 164 - 19 - - - 175 - 29 - - - - - metric - toggled(bool) - celsius - setChecked(bool) - - - 142 - 19 - - - 153 - 29 - - - - - imperial - toggled(bool) - lbs - setChecked(bool) - - - 164 - 19 - - - 175 - 28 - - - - - metric - toggled(bool) - kg - setChecked(bool) - - - 142 - 19 - - - 153 - 28 - - - proxyAuthRequired toggled(bool) diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index c55d7b881..8ea4bd79c 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -15,6 +15,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_language.cpp preferences_georeference.cpp preferences_defaults.cpp + preferences_units.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_units.cpp b/desktop-widgets/preferences/preferences_units.cpp new file mode 100644 index 000000000..76f2078d7 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.cpp @@ -0,0 +1,60 @@ +#include "preferences_units.h" +#include "ui_preferences_units.h" +#include "prefs-macros.h" +#include "qthelper.h" + +#include + +PreferencesUnits::PreferencesUnits(): AbstractPreferencesWidget(tr("Units"),QIcon(":units"),1), ui(new Ui::PreferencesUnits()) +{ + ui->setupUi(this); +} + +PreferencesUnits::~PreferencesUnits() +{ + +} + +void PreferencesUnits::refreshSettings() +{ + QSettings s; + s.beginGroup("Units"); + QString unitSystem[] = {"metric", "imperial", "personal"}; + short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); + SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); + s.setValue("temperature", ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); + s.setValue("length", ui->feet->isChecked() ? units::FEET : units::METERS); + s.setValue("pressure", ui->psi->isChecked() ? units::PSI : units::BAR); + s.setValue("volume", ui->cuft->isChecked() ? units::CUFT : units::LITER); + s.setValue("weight", ui->lbs->isChecked() ? units::LBS : units::KG); + s.setValue("vertical_speed_time", ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui->gpsTraditional->isChecked()); + s.endGroup(); +} + +void PreferencesUnits::syncSettings() +{ + switch(prefs.unit_system) { + case METRIC: ui->metric->setChecked(true); break; + case IMPERIAL: ui->imperial->setChecked(true); break; + default: ui->personalize->setChecked(true); break; + } + + ui->gpsTraditional->setChecked(prefs.coordinates_traditional); + ui->gpsDecimal->setChecked(!prefs.coordinates_traditional); + + ui->celsius->setChecked(prefs.units.temperature == units::CELSIUS); + ui->fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT); + ui->meter->setChecked(prefs.units.length == units::METERS); + ui->feet->setChecked(prefs.units.length == units::FEET); + ui->bar->setChecked(prefs.units.pressure == units::BAR); + ui->psi->setChecked(prefs.units.pressure == units::PSI); + ui->liter->setChecked(prefs.units.volume == units::LITER); + ui->cuft->setChecked(prefs.units.volume == units::CUFT); + ui->kg->setChecked(prefs.units.weight == units::KG); + ui->lbs->setChecked(prefs.units.weight == units::LBS); + ui->units_group->setEnabled(ui->personalize->isChecked()); + + ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); + ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); +} diff --git a/desktop-widgets/preferences/preferences_units.h b/desktop-widgets/preferences/preferences_units.h new file mode 100644 index 000000000..21a7f4404 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_UNITS_H +#define PREFERENCES_UNITS_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesUnits; +} + +class PreferencesUnits : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesUnits(); + virtual ~PreferencesUnits(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesUnits *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_units.ui b/desktop-widgets/preferences/preferences_units.ui new file mode 100644 index 000000000..bb1ffba66 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.ui @@ -0,0 +1,251 @@ + + + PreferencesUnits + + + + 0 + 0 + 400 + 374 + + + + Form + + + + + + Unit system + + + + + + System + + + + + + + &Metric + + + + + + + Imperial + + + + + + + Personali&ze + + + + + + + + + + Individual settings + + + false + + + false + + + + + + Depth + + + + + + + meter + + + + + + + feet + + + + + + + Pressure + + + + + + + bar + + + + + + + psi + + + + + + + Volume + + + + + + + &liter + + + + + + + cu ft + + + + + + + Temperature + + + + + + + celsius + + + + + + + fahrenheit + + + + + + + Weight + + + + + + + kg + + + + + + + lbs + + + + + + + + + + Time units + + + + + + Ascent/descent speed denominator + + + + + + + Minutes + + + + + + + Seconds + + + + + + + + + + GPS coordinates + + + + + + Location Display + + + + + + + traditional (dms) + + + + + + + decimal + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 6f66d856d..7d9e17d7e 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -4,6 +4,7 @@ #include "preferences_language.h" #include "preferences_georeference.h" #include "preferences_defaults.h" +#include "preferences_units.h" #include #include @@ -37,6 +38,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesLanguage()); addPreferencePage(new PreferencesGeoreference()); addPreferencePage(new PreferencesDefaults()); + addPreferencePage(new PreferencesUnits()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From cfecd1a9ab6f1ac870622427af56fa43a87bf14b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 1 Oct 2015 18:59:53 -0300 Subject: Preferences: move graph preferences to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 56 +--- desktop-widgets/preferences.h | 2 - desktop-widgets/preferences.ui | 356 +++------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + desktop-widgets/preferences/preferences_graph.cpp | 78 +++++ desktop-widgets/preferences/preferences_graph.h | 27 ++ desktop-widgets/preferences/preferences_graph.ui | 268 ++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 417 insertions(+), 373 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_graph.cpp create mode 100644 desktop-widgets/preferences/preferences_graph.h create mode 100644 desktop-widgets/preferences/preferences_graph.ui (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 672d75906..9ef93fafc 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -64,8 +64,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial #endif connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); - connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); - connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int))); + // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); connect(close, SIGNAL(activated()), this, SLOT(close())); @@ -120,17 +119,6 @@ void PreferencesDialog::cloudPinNeeded() MainWindow::instance()->enableDisableCloudActions(); } -#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" -void PreferencesDialog::gflowChanged(int gf) -{ - ui.gflow->setStyleSheet(DANGER_GF); -} -void PreferencesDialog::gfhighChanged(int gf) -{ - ui.gfhigh->setStyleSheet(DANGER_GF); -} -#undef DANGER_GF - void PreferencesDialog::showEvent(QShowEvent *event) { setUiFromPrefs(); @@ -140,25 +128,6 @@ void PreferencesDialog::showEvent(QShowEvent *event) void PreferencesDialog::setUiFromPrefs() { - // graphs - ui.pheThreshold->setValue(prefs.pp_graphs.phe_threshold); - ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold); - ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); - ui.maxpo2->setValue(prefs.modpO2); - ui.red_ceiling->setChecked(prefs.redceiling); - - ui.gflow->setValue(prefs.gflow); - ui.gfhigh->setValue(prefs.gfhigh); - ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); - ui.show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); - ui.show_ccr_sensors->setChecked(prefs.show_ccr_sensors); - ui.defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); - ui.psro2rate->setValue(prefs.o2consumption / 1000.0); - ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); - - ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); - ui.show_average_depth->setChecked(prefs.show_average_depth); - QSettings s; ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); @@ -197,29 +166,6 @@ void PreferencesDialog::syncSettings() s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); set_save_userid_local(ui.save_uid_local->checkState()); - // Graph - s.beginGroup("TecDetails"); - SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui.pheThreshold->value()); - SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui.po2Threshold->value()); - SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui.pn2Threshold->value()); - SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui.maxpo2->value()); - SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui.red_ceiling->isChecked()); - SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui.gflow->value()); - SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui.gfhigh->value()); - SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui.gf_low_at_maxdepth->isChecked()); - SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui.show_ccr_setpoint->isChecked()); - SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui.show_ccr_sensors->isChecked()); - SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui.display_unused_tanks->isChecked()); - SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); - s.endGroup(); - - // Defaults - s.beginGroup("GeneralSettings"); - s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); - s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); - s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); - s.endGroup(); - s.beginGroup("Network"); s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); s.setValue("proxy_host", ui.proxyHost->text()); diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index c05145611..4d2c33e76 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -29,8 +29,6 @@ slots: void loadSettings(); void restorePrefs(); void rememberPrefs(); - void gflowChanged(int gf); - void gfhighChanged(int gf); void proxyType_changed(int idx); void facebookLoggedIn(); void facebookDisconnect(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index 12ba10d4b..97e281433 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -6,8 +6,8 @@ 0 0 - 711 - 662 + 835 + 698 @@ -19,7 +19,16 @@ - + + 5 + + + 5 + + + 5 + + 5 @@ -83,16 +92,6 @@ -1 - - - Graph - - - - :/graph - - - Network @@ -126,309 +125,27 @@ 0 - + 0 0 - + 5 - + 5 - - - - Show - - - - - - - - true - - - Threshold when showing pO₂ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pN₂ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pHe - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Max pO₂ when showing MOD - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Draw dive computer reported ceiling red - - - - - - - - - - - Show unused cylinders in Equipment tab - - - - - - - - - - - Show average depth - - - - - - - - - - - - Misc - - - - - - GFLow - - - - - - - 1 - - - 150 - - - - - - - GFHigh - - - - - - - 1 - - - 150 - - - - - - - GFLow at max depth - - - - - - - CCR: show setpoints when viewing pO₂ - - - - - - - CCR: show individual O₂ sensor values when viewing pO₂ - - - - - - - Default CCR set-point for dive planning - - - - - - - bar - - - 2 - - - 10.000000000000000 - - - 0.100000000000000 - - - - - - - pSCR O₂ metabolism rate - - - - - - - pSCR ratio - - - - - - - ℓ/min - - - 3 - - - - - - - - - - 1: - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - + + 5 + + 5 - + 5 @@ -658,7 +375,16 @@ 5 - + + 5 + + + 5 + + + 5 + + 5 @@ -707,7 +433,16 @@ 5 - + + 5 + + + 5 + + + 5 + + 5 @@ -842,15 +577,4 @@ - - - - - - - - - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 8ea4bd79c..b3ef4e3d5 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -16,6 +16,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_georeference.cpp preferences_defaults.cpp preferences_units.cpp + preferences_graph.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp new file mode 100644 index 000000000..f671076f4 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -0,0 +1,78 @@ +#include "preferences_graph.h" +#include "ui_preferences_graph.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +#include "qt-models/models.h" + +PreferencesGraph::PreferencesGraph() : AbstractPreferencesWidget(tr("Graph"), QIcon(":graph"), 5) +{ + ui = new Ui::PreferencesGraph(); + ui->setupUi(this); +} + +PreferencesGraph::~PreferencesGraph() +{ + delete ui; +} + +void PreferencesGraph::refreshSettings() +{ + ui->pheThreshold->setValue(prefs.pp_graphs.phe_threshold); + ui->po2Threshold->setValue(prefs.pp_graphs.po2_threshold); + ui->pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); + ui->maxpo2->setValue(prefs.modpO2); + ui->red_ceiling->setChecked(prefs.redceiling); + + ui->gflow->setValue(prefs.gflow); + ui->gfhigh->setValue(prefs.gfhigh); + ui->gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); + ui->show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); + ui->show_ccr_sensors->setChecked(prefs.show_ccr_sensors); + ui->defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); + ui->psro2rate->setValue(prefs.o2consumption / 1000.0); + ui->pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); + + ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); + ui->show_average_depth->setChecked(prefs.show_average_depth); +} + +void PreferencesGraph::syncSettings() +{ + QSettings s; + + s.beginGroup("GeneralSettings"); + s.setValue("defaultsetpoint", rint(ui->defaultSetpoint->value() * 1000.0)); + s.setValue("o2consumption", rint(ui->psro2rate->value() *1000.0)); + s.setValue("pscr_ratio", rint(1000.0 / ui->pscrfactor->value())); + s.endGroup(); + + // Graph + s.beginGroup("TecDetails"); + SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui->pheThreshold->value()); + SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui->po2Threshold->value()); + SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui->pn2Threshold->value()); + SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui->maxpo2->value()); + SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui->red_ceiling->isChecked()); + SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui->gflow->value()); + SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui->gfhigh->value()); + SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui->gf_low_at_maxdepth->isChecked()); + SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui->show_ccr_setpoint->isChecked()); + SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui->show_ccr_sensors->isChecked()); + SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui->display_unused_tanks->isChecked()); + SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui->show_average_depth->isChecked()); + s.endGroup(); +} + +#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" +void PreferencesGraph::on_gflow_valueChanged(int gf) +{ + ui->gflow->setStyleSheet(DANGER_GF); +} +void PreferencesGraph::on_gfhigh_valueChanged(int gf) +{ + ui->gfhigh->setStyleSheet(DANGER_GF); +} +#undef DANGER_GF \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.h b/desktop-widgets/preferences/preferences_graph.h new file mode 100644 index 000000000..ca40c0a92 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.h @@ -0,0 +1,27 @@ +#ifndef PREFERENCES_GRAPH_H +#define PREFERENCES_GRAPH_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesGraph; +} + +class PreferencesGraph : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesGraph(); + virtual ~PreferencesGraph(); + virtual void refreshSettings(); + virtual void syncSettings(); + +private slots: + void on_gflow_valueChanged(int gf); + void on_gfhigh_valueChanged(int gf); + +private: + Ui::PreferencesGraph *ui; + +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.ui b/desktop-widgets/preferences/preferences_graph.ui new file mode 100644 index 000000000..bdbbc75d3 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.ui @@ -0,0 +1,268 @@ + + + PreferencesGraph + + + + 0 + 0 + 505 + 623 + + + + Form + + + + + + Show + + + + + + true + + + Threshold when showing pO₂ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pN₂ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pHe + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Max pO₂ when showing MOD + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Draw dive computer reported ceiling red + + + + + + + Show unused cylinders in Equipment tab + + + + + + + Show average depth + + + + + + + + + + Misc + + + + + + 1 + + + 150 + + + + + + + bar + + + 2 + + + 10.000000000000000 + + + 0.100000000000000 + + + + + + + Default CCR set-point for dive planning + + + + + + + pSCR O₂ metabolism rate + + + + + + + GFLow + + + + + + + GFHigh + + + + + + + 1 + + + 150 + + + + + + + ℓ/min + + + 3 + + + + + + + pSCR ratio + + + + + + + + + + 1: + + + + + + + CCR: show individual O₂ sensor values when viewing pO₂ + + + + + + + CCR: show setpoints when viewing pO₂ + + + + + + + GFLow at max depth + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 7d9e17d7e..db1d30113 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -5,6 +5,7 @@ #include "preferences_georeference.h" #include "preferences_defaults.h" #include "preferences_units.h" +#include "preferences_graph.h" #include #include @@ -39,6 +40,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesGeoreference()); addPreferencePage(new PreferencesDefaults()); addPreferencePage(new PreferencesUnits()); + addPreferencePage(new PreferencesGraph()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From d9595ad266021575522f73bb87dfc51517461d59 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 1 Oct 2015 19:48:57 -0300 Subject: Preferences: move network preferences to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 177 +---------- desktop-widgets/preferences.h | 3 - desktop-widgets/preferences.ui | 339 --------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + .../preferences/preferences_network.cpp | 173 +++++++++++ desktop-widgets/preferences/preferences_network.h | 26 ++ desktop-widgets/preferences/preferences_network.ui | 293 ++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 496 insertions(+), 518 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_network.cpp create mode 100644 desktop-widgets/preferences/preferences_network.h create mode 100644 desktop-widgets/preferences/preferences_network.ui (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 9ef93fafc..2ec9ee96d 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -31,23 +31,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial ui.setupUi(this); setAttribute(Qt::WA_QuitOnClose, false); -#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT) - for (int i = 0; i < ui.listWidget->count(); i++) { - if (ui.listWidget->item(i)->text() == "Facebook") { - delete ui.listWidget->item(i); - QWidget *fbpage = ui.stackedWidget->widget(i); - ui.stackedWidget->removeWidget(fbpage); - } - } -#endif - - ui.proxyType->clear(); - ui.proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); - ui.proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); - ui.proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); - ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); - ui.proxyType->setCurrentIndex(-1); - #if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) FacebookManager *fb = FacebookManager::instance(); facebookWebView = new QWebView(this); @@ -62,7 +45,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout); connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); #endif - connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); @@ -101,24 +84,6 @@ void PreferencesDialog::facebookDisconnect() #endif } -void PreferencesDialog::cloudPinNeeded() -{ - ui.cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - if (prefs.cloud_verification_status == CS_VERIFIED) { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); - } else { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); - } - MainWindow::instance()->enableDisableCloudActions(); -} - void PreferencesDialog::showEvent(QShowEvent *event) { setUiFromPrefs(); @@ -128,24 +93,7 @@ void PreferencesDialog::showEvent(QShowEvent *event) void PreferencesDialog::setUiFromPrefs() { - QSettings s; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - ui.proxyHost->setText(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.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); - - ui.cloud_storage_email->setText(prefs.cloud_storage_email); - ui.cloud_storage_password->setText(prefs.cloud_storage_password); - ui.save_password_local->setChecked(prefs.save_password_local); - cloudPinNeeded(); - ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); } void PreferencesDialog::restorePrefs() @@ -161,105 +109,6 @@ void PreferencesDialog::rememberPrefs() void PreferencesDialog::syncSettings() { - QSettings s; - - s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); - set_save_userid_local(ui.save_uid_local->checkState()); - - s.beginGroup("Network"); - s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); - s.setValue("proxy_host", ui.proxyHost->text()); - s.setValue("proxy_port", ui.proxyPort->value()); - SB("proxy_auth", ui.proxyAuthRequired); - s.setValue("proxy_user", ui.proxyUsername->text()); - s.setValue("proxy_pass", ui.proxyPassword->text()); - s.endGroup(); - - s.beginGroup("CloudStorage"); - QString email = ui.cloud_storage_email->text(); - QString password = ui.cloud_storage_password->text(); - QString newpassword = ui.cloud_storage_new_passwd->text(); - if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { - // deal with password change - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); - QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); - ui.cloud_storage_new_passwd->setText(""); - free(prefs.cloud_storage_newpassword); - prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); - } - } - } else if (prefs.cloud_verification_status == CS_UNKNOWN || - prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || - email != prefs.cloud_storage_email || - password != prefs.cloud_storage_password) { - - // different credentials - reset verification status - prefs.cloud_verification_status = CS_UNKNOWN; - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password); - } - } - } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { - QString pin = ui.cloud_storage_pin->text(); - if (!pin.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password, pin); - } - } - SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); - SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked()); - if (ui.save_password_local->isChecked()) { - SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); - } else { - s.remove("password"); - free(prefs.cloud_storage_password); - prefs.cloud_storage_password = strdup(qPrintable(password)); - } - SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); - SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked()); - - // at this point we intentionally do not have a UI for changing this - // it could go into some sort of "advanced setup" or something - SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); - s.endGroup(); - -<<<<<<< HEAD - s.beginGroup("geocoding"); -#ifdef DISABLED - s.setValue("enable_geocoding", ui.enable_geocoding->isChecked()); - s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked()); - s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked()); -#endif - s.setValue("cat0", ui.first_item->currentIndex()); - s.setValue("cat1", ui.second_item->currentIndex()); - s.setValue("cat2", ui.third_item->currentIndex()); - s.endGroup(); - -======= ->>>>>>> Code Cleanup - loadSettings(); - emit settingsChanged(); } void PreferencesDialog::loadSettings() @@ -270,9 +119,6 @@ void PreferencesDialog::loadSettings() loadPreferences(); QSettings s; QVariant v; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); } void PreferencesDialog::buttonClicked(QAbstractButton *button) @@ -318,28 +164,7 @@ void PreferencesDialog::on_resetSettings_clicked() } } -void PreferencesDialog::passwordUpdateSuccessfull() -{ - ui.cloud_storage_password->setText(prefs.cloud_storage_password); -} - void PreferencesDialog::emitSettingsChanged() { emit settingsChanged(); } - -void PreferencesDialog::proxyType_changed(int idx) -{ - if (idx == -1) { - return; - } - - int proxyType = ui.proxyType->itemData(idx).toInt(); - bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); - ui.proxyHost->setEnabled(hpEnabled); - ui.proxyPort->setEnabled(hpEnabled); - ui.proxyAuthRequired->setEnabled(hpEnabled); - ui.proxyUsername->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); -} diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index 4d2c33e76..0fda4d390 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -29,11 +29,8 @@ slots: void loadSettings(); void restorePrefs(); void rememberPrefs(); - void proxyType_changed(int idx); void facebookLoggedIn(); void facebookDisconnect(); - void cloudPinNeeded(); - void passwordUpdateSuccessfull(); private: explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); void setUiFromPrefs(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index 97e281433..8d0b18900 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -92,16 +92,6 @@ -1 - - - Network - - - - :/network - - - Facebook @@ -125,303 +115,6 @@ 0 - - - - 0 - 0 - - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Proxy - - - - - - - 0 - 0 - - - - Port - - - - - - - - - - Host - - - - - - - Qt::LeftToRight - - - Requires authentication - - - - - - - Proxy type - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Username - - - - - - - - 1 - 0 - - - - 65535 - - - 80 - - - - - - - - 0 - 0 - - - - 32 - - - - - - - - 2 - 0 - - - - 64 - - - - - - - Password - - - - - - - - 0 - 0 - - - - 32 - - - QLineEdit::Password - - - - - - - - - - - 0 - 0 - - - - - 0 - 129 - - - - Subsurface cloud storage - - - - - - - - - Email address - - - - - - - Password - - - - - - - Verification PIN - - - - - - - New password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - Sync to cloud in the background? - - - - - - - Save Password locally? - - - - - - - - - - Subsurface web service - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Default user ID - - - - - - - - - - Save user ID locally? - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -544,37 +237,5 @@ - - proxyAuthRequired - toggled(bool) - proxyUsername - setEnabled(bool) - - - 409 - 123 - - - 409 - 153 - - - - - proxyAuthRequired - toggled(bool) - proxyPassword - setEnabled(bool) - - - 409 - 123 - - - 409 - 183 - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index b3ef4e3d5..4e506ed73 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -17,6 +17,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_defaults.cpp preferences_units.cpp preferences_graph.cpp + preferences_network.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp new file mode 100644 index 000000000..000df1e7f --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -0,0 +1,173 @@ +#include "preferences_network.h" +#include "ui_preferences_network.h" +#include "preferences.h" +#include "dive.h" +#include "subsurfacewebservices.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesNetwork::PreferencesNetwork() : AbstractPreferencesWidget(tr("Network"),QIcon(":network"), 9), ui(new Ui::PreferencesNetwork()) +{ + ui->setupUi(this); + + ui->proxyType->clear(); + ui->proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); + ui->proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); + ui->proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); + ui->proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); + ui->proxyType->setCurrentIndex(-1); + + connect(ui->proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); +} + +PreferencesNetwork::~PreferencesNetwork() +{ + delete ui; +} + +void PreferencesNetwork::refreshSettings() +{ + QSettings s; + + ui->proxyHost->setText(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->proxyType->setCurrentIndex(ui->proxyType->findData(prefs.proxy_type)); + ui->cloud_storage_email->setText(prefs.cloud_storage_email); + ui->cloud_storage_password->setText(prefs.cloud_storage_password); + ui->save_password_local->setChecked(prefs.save_password_local); + ui->cloud_background_sync->setChecked(prefs.cloud_background_sync); + ui->save_uid_local->setChecked(prefs.save_userid_local); + ui->default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + + cloudPinNeeded(); +} + +void PreferencesNetwork::syncSettings() +{ + QSettings s; + s.setValue("subsurface_webservice_uid", ui->default_uid->text().toUpper()); + set_save_userid_local(ui->save_uid_local->checkState()); + + s.beginGroup("Network"); + s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt()); + s.setValue("proxy_host", ui->proxyHost->text()); + s.setValue("proxy_port", ui->proxyPort->value()); + SB("proxy_auth", ui->proxyAuthRequired); + s.setValue("proxy_user", ui->proxyUsername->text()); + s.setValue("proxy_pass", ui->proxyPassword->text()); + s.endGroup(); + + s.beginGroup("CloudStorage"); + QString email = ui->cloud_storage_email->text(); + QString password = ui->cloud_storage_password->text(); + QString newpassword = ui->cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui->cloud_storage_new_passwd->setText(""); + free(prefs.cloud_storage_newpassword); + prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + + // different credentials - reset verification status + prefs.cloud_verification_status = CS_UNKNOWN; + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password); + } + } + } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { + QString pin = ui->cloud_storage_pin->text(); + if (!pin.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); + } + } + SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); + SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui->save_password_local->isChecked()); + if (ui->save_password_local->isChecked()) { + SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); + } else { + s.remove("password"); + free(prefs.cloud_storage_password); + prefs.cloud_storage_password = strdup(qPrintable(password)); + } + SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); + SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui->cloud_background_sync->isChecked()); + + // at this point we intentionally do not have a UI for changing this + // it could go into some sort of "advanced setup" or something + SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); + s.endGroup(); +} + +void PreferencesNetwork::cloudPinNeeded() +{ + ui->cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); + } else { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); + } + //TODO: Do not call mainWindow here. Verify things on SettingsChanged. + //MainWindow::instance()->enableDisableCloudActions(); +} + +void PreferencesNetwork::proxyType_changed(int idx) +{ + if (idx == -1) { + return; + } + + int proxyType = ui->proxyType->itemData(idx).toInt(); + bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); + ui->proxyHost->setEnabled(hpEnabled); + ui->proxyPort->setEnabled(hpEnabled); + ui->proxyAuthRequired->setEnabled(hpEnabled); + ui->proxyUsername->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyPassword->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyAuthRequired->setChecked(ui->proxyAuthRequired->isChecked()); +} + +void PreferencesNetwork::passwordUpdateSuccessfull() +{ + ui->cloud_storage_password->setText(prefs.cloud_storage_password); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.h b/desktop-widgets/preferences/preferences_network.h new file mode 100644 index 000000000..8f35adeb0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.h @@ -0,0 +1,26 @@ +#ifndef PREFERENCES_NETWORK_H +#define PREFERENCES_NETWORK_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesNetwork; +} + +class PreferencesNetwork : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesNetwork(); + virtual ~PreferencesNetwork(); + virtual void refreshSettings(); + virtual void syncSettings(); + +private: + Ui::PreferencesNetwork *ui; + + void cloudPinNeeded(); + void proxyType_changed(int i); + void passwordUpdateSuccessfull(); +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.ui b/desktop-widgets/preferences/preferences_network.ui new file mode 100644 index 000000000..8bb9bf9a0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.ui @@ -0,0 +1,293 @@ + + + PreferencesNetwork + + + + 0 + 0 + 713 + 558 + + + + Form + + + + + + Proxy + + + + + + + 0 + 0 + + + + Port + + + + + + + Host + + + + + + + Proxy type + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Username + + + + + + + + 1 + 0 + + + + 65535 + + + 80 + + + + + + + + 2 + 0 + + + + 64 + + + + + + + + + + Qt::LeftToRight + + + Requires authentication + + + + + + + + 0 + 0 + + + + 32 + + + + + + + Password + + + + + + + + 0 + 0 + + + + 32 + + + QLineEdit::Password + + + + + + + + + + + 0 + 0 + + + + + 0 + 129 + + + + Subsurface cloud storage + + + + + + + + + Email address + + + + + + + Password + + + + + + + Verification PIN + + + + + + + New password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + Sync to cloud in the background? + + + + + + + Save Password locally? + + + + + + + + + + Subsurface web service + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Default user ID + + + + + + + + + + Save user ID locally? + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index db1d30113..bf751bff7 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -6,6 +6,7 @@ #include "preferences_defaults.h" #include "preferences_units.h" #include "preferences_graph.h" +#include "preferences_network.h" #include #include @@ -41,6 +42,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesDefaults()); addPreferencePage(new PreferencesUnits()); addPreferencePage(new PreferencesGraph()); + addPreferencePage(new PreferencesNetwork()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From c1b2907071432f6a313605950fa95c8eff000a55 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 9 Oct 2015 18:11:18 -0300 Subject: Fix warnings Also, disable Facebook temporarely since I'm removing the preferences widget in a few commits. Facebook will have to change to use a new way of connection that I'm still creating. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/mainwindow.ui | 1 - desktop-widgets/preferences.cpp | 3 +++ desktop-widgets/preferences/preferences_network.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'desktop-widgets/preferences.cpp') diff --git a/desktop-widgets/mainwindow.ui b/desktop-widgets/mainwindow.ui index 5e3200cfc..c62e1df7f 100644 --- a/desktop-widgets/mainwindow.ui +++ b/desktop-widgets/mainwindow.ui @@ -142,7 +142,6 @@ Share on - diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 2ec9ee96d..29e9d2458 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -142,6 +142,8 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) } #undef SB +#if 0 +// TODO: Copy this later. void PreferencesDialog::on_resetSettings_clicked() { QSettings s; @@ -163,6 +165,7 @@ void PreferencesDialog::on_resetSettings_clicked() close(); } } +#endif void PreferencesDialog::emitSettingsChanged() { diff --git a/desktop-widgets/preferences/preferences_network.h b/desktop-widgets/preferences/preferences_network.h index 8f35adeb0..3e17d51b0 100644 --- a/desktop-widgets/preferences/preferences_network.h +++ b/desktop-widgets/preferences/preferences_network.h @@ -9,17 +9,19 @@ namespace Ui { class PreferencesNetwork : public AbstractPreferencesWidget { Q_OBJECT + public: PreferencesNetwork(); virtual ~PreferencesNetwork(); virtual void refreshSettings(); virtual void syncSettings(); +public slots: + void proxyType_changed(int i); + private: Ui::PreferencesNetwork *ui; - void cloudPinNeeded(); - void proxyType_changed(int i); void passwordUpdateSuccessfull(); }; -- cgit v1.2.3-70-g09d2