Preferences: move network preferences to the new dialog

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-10-01 19:48:57 -03:00 committed by Dirk Hohndel
parent cfecd1a9ab
commit d9595ad266
8 changed files with 496 additions and 518 deletions

View file

@ -31,23 +31,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
ui.setupUi(this); ui.setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false); 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) #if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
FacebookManager *fb = FacebookManager::instance(); FacebookManager *fb = FacebookManager::instance();
facebookWebView = new QWebView(this); 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(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout);
connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect);
#endif #endif
connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int)));
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
// connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double)));
@ -101,24 +84,6 @@ void PreferencesDialog::facebookDisconnect()
#endif #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) void PreferencesDialog::showEvent(QShowEvent *event)
{ {
setUiFromPrefs(); setUiFromPrefs();
@ -128,24 +93,7 @@ void PreferencesDialog::showEvent(QShowEvent *event)
void PreferencesDialog::setUiFromPrefs() 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() void PreferencesDialog::restorePrefs()
@ -161,105 +109,6 @@ void PreferencesDialog::rememberPrefs()
void PreferencesDialog::syncSettings() 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() void PreferencesDialog::loadSettings()
@ -270,9 +119,6 @@ void PreferencesDialog::loadSettings()
loadPreferences(); loadPreferences();
QSettings s; QSettings s;
QVariant v; 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) 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() void PreferencesDialog::emitSettingsChanged()
{ {
emit settingsChanged(); 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());
}

View file

@ -29,11 +29,8 @@ slots:
void loadSettings(); void loadSettings();
void restorePrefs(); void restorePrefs();
void rememberPrefs(); void rememberPrefs();
void proxyType_changed(int idx);
void facebookLoggedIn(); void facebookLoggedIn();
void facebookDisconnect(); void facebookDisconnect();
void cloudPinNeeded();
void passwordUpdateSuccessfull();
private: private:
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
void setUiFromPrefs(); void setUiFromPrefs();

View file

@ -92,16 +92,6 @@
<property name="currentRow"> <property name="currentRow">
<number>-1</number> <number>-1</number>
</property> </property>
<item>
<property name="text">
<string>Network</string>
</property>
<property name="icon">
<iconset>
<normalon>:/network</normalon>
</iconset>
</property>
</item>
<item> <item>
<property name="text"> <property name="text">
<string>Facebook</string> <string>Facebook</string>
@ -125,303 +115,6 @@
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="network_page">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_15">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Proxy</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="2">
<widget class="QLabel" name="label_23">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="proxyType"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string>Host</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="proxyAuthRequired">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Requires authentication</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Proxy type</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="proxyPort">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>80</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="proxyUsername">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>32</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="proxyHost">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_25">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="proxyPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="cloudStorageGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>129</height>
</size>
</property>
<property name="title">
<string>Subsurface cloud storage</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_16b">
<property name="toolTip">
<string extracomment="Email address used for the Subsurface cloud storage infrastructure"/>
</property>
<property name="text">
<string>Email address</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_16c">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="cloud_storage_pin_label">
<property name="text">
<string>Verification PIN</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="cloud_storage_new_passwd_label">
<property name="text">
<string>New password</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="cloud_storage_email">
<property name="toolTip">
<string extracomment="Email address used for the Subsurface cloud storage infrastructure"/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="cloud_storage_password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="cloud_storage_pin">
<property name="toolTip">
<string extracomment="One time verification PIN for Subsurface cloud storage infrastructure"/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="cloud_storage_new_passwd">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cloud_background_sync">
<property name="text">
<string>Sync to cloud in the background?</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="save_password_local">
<property name="text">
<string>Save Password locally?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Subsurface web service</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Default user ID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="default_uid"/>
</item>
<item>
<widget class="QCheckBox" name="save_uid_local">
<property name="text">
<string>Save user ID locally?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="facebook_page"> <widget class="QWidget" name="facebook_page">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
@ -544,37 +237,5 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>proxyAuthRequired</sender>
<signal>toggled(bool)</signal>
<receiver>proxyUsername</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>409</x>
<y>123</y>
</hint>
<hint type="destinationlabel">
<x>409</x>
<y>153</y>
</hint>
</hints>
</connection>
<connection>
<sender>proxyAuthRequired</sender>
<signal>toggled(bool)</signal>
<receiver>proxyPassword</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>409</x>
<y>123</y>
</hint>
<hint type="destinationlabel">
<x>409</x>
<y>183</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View file

@ -17,6 +17,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS
preferences_defaults.cpp preferences_defaults.cpp
preferences_units.cpp preferences_units.cpp
preferences_graph.cpp preferences_graph.cpp
preferences_network.cpp
) )
source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS})

View file

@ -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 <QNetworkProxy>
#include <QSettings>
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);
}

View file

@ -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

View file

@ -0,0 +1,293 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesNetwork</class>
<widget class="QWidget" name="PreferencesNetwork">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>713</width>
<height>558</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Proxy</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="2">
<widget class="QLabel" name="label_23">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string>Host</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Proxy type</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="proxyPort">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>80</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="proxyHost">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="proxyType"/>
</item>
<item row="2" column="1" colspan="3">
<widget class="QCheckBox" name="proxyAuthRequired">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Requires authentication</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="proxyUsername">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>32</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_25">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="proxyPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="cloudStorageGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>129</height>
</size>
</property>
<property name="title">
<string>Subsurface cloud storage</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_16b">
<property name="toolTip">
<string extracomment="Email address used for the Subsurface cloud storage infrastructure"/>
</property>
<property name="text">
<string>Email address</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_16c">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="cloud_storage_pin_label">
<property name="text">
<string>Verification PIN</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="cloud_storage_new_passwd_label">
<property name="text">
<string>New password</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="cloud_storage_email">
<property name="toolTip">
<string extracomment="Email address used for the Subsurface cloud storage infrastructure"/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="cloud_storage_password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="cloud_storage_pin">
<property name="toolTip">
<string extracomment="One time verification PIN for Subsurface cloud storage infrastructure"/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="cloud_storage_new_passwd">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cloud_background_sync">
<property name="text">
<string>Sync to cloud in the background?</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="save_password_local">
<property name="text">
<string>Save Password locally?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Subsurface web service</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Default user ID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="default_uid"/>
</item>
<item>
<widget class="QCheckBox" name="save_uid_local">
<property name="text">
<string>Save user ID locally?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -6,6 +6,7 @@
#include "preferences_defaults.h" #include "preferences_defaults.h"
#include "preferences_units.h" #include "preferences_units.h"
#include "preferences_graph.h" #include "preferences_graph.h"
#include "preferences_network.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
@ -41,6 +42,7 @@ PreferencesDialogV2::PreferencesDialogV2()
addPreferencePage(new PreferencesDefaults()); addPreferencePage(new PreferencesDefaults());
addPreferencePage(new PreferencesUnits()); addPreferencePage(new PreferencesUnits());
addPreferencePage(new PreferencesGraph()); addPreferencePage(new PreferencesGraph());
addPreferencePage(new PreferencesNetwork());
refreshPages(); refreshPages();
connect(pagesList, &QListWidget::currentRowChanged, connect(pagesList, &QListWidget::currentRowChanged,