From b5e98ec993c2648dd0f6e19eab490963625931a2 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Date: Wed, 10 Aug 2016 13:43:39 -0300
Subject: [PATCH] Settings update: Fix "Network" and "CloudStorage"

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 .../preferences/preferences_network.cpp       | 45 +++++++------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp
index 5d7f70665..2e0ebbd32 100644
--- a/desktop-widgets/preferences/preferences_network.cpp
+++ b/desktop-widgets/preferences/preferences_network.cpp
@@ -52,20 +52,18 @@ void PreferencesNetwork::syncSettings()
 	cloud->setUserId(ui->default_uid->text().toUpper());
 	cloud->setSaveUserIdLocal(ui->save_uid_local->checkState());
 
-	QSettings s;
-	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();
+	proxy->setType(ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt());
+	proxy->setHost(ui->proxyHost->text());
+	proxy->setPort(ui->proxyPort->value());
+	proxy->setAuth(ui->proxyAuthRequired->isChecked());
+	proxy->setUser(ui->proxyUsername->text());
+	proxy->setPass(ui->proxyPassword->text());
 
-	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();
+
+	//TODO: Change this to the Cloud Storage Stuff, not preferences.
 	if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) {
 		// deal with password change
 		if (!email.isEmpty() && !password.isEmpty()) {
@@ -79,8 +77,7 @@ void PreferencesNetwork::syncSettings()
 				connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull()));
 				cloudAuth->backend(email, password, "", newpassword);
 				ui->cloud_storage_new_passwd->setText("");
-				free(prefs.cloud_storage_newpassword);
-				prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword));
+				cloud->setNewPassword(newpassword);
 			}
 		}
 	} else if (prefs.cloud_verification_status == CS_UNKNOWN ||
@@ -89,7 +86,7 @@ void PreferencesNetwork::syncSettings()
 		   password != prefs.cloud_storage_password) {
 
 		// different credentials - reset verification status
-		prefs.cloud_verification_status = CS_UNKNOWN;
+		cloud->setVerificationStatus(CS_UNKNOWN);
 		if (!email.isEmpty() && !password.isEmpty()) {
 			// connect to backend server to check / create credentials
 			QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
@@ -114,22 +111,12 @@ void PreferencesNetwork::syncSettings()
 			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();
+	cloud->setEmail(email);
+	cloud->setSavePasswordLocal(ui->save_password_local->isChecked());
+	cloud->setPassword(password);
+	cloud->setVerificationStatus(prefs.cloud_verification_status);
+	cloud->setBackgroundSync(ui->cloud_background_sync->isChecked());
+	cloud->setBaseUrl(prefs.cloud_base_url);
 }
 
 void PreferencesNetwork::cloudPinNeeded()