diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-09-10 21:13:27 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-09-10 21:13:27 (GMT) |
commit | 010cdd3a81f35a377cb93a2f5c9fcc94bac7c855 (patch) | |
tree | e8901d79abfa8be2d6fa9e058b2db28ea72fcfe7 | |
parent | dd38b017c12478ef1cc4db37c1e8219e3151742f (diff) | |
download | swift-contrib-010cdd3a81f35a377cb93a2f5c9fcc94bac7c855.zip swift-contrib-010cdd3a81f35a377cb93a2f5c9fcc94bac7c855.tar.bz2 |
Set default account settings back to the defaults.
Resolves: #1156
-rw-r--r-- | Swift/Controllers/MainController.cpp | 24 | ||||
-rw-r--r-- | Swift/QtUI/QtConnectionSettingsWindow.cpp | 17 |
2 files changed, 27 insertions, 14 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index c2a7b33..910a489 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -783,14 +783,14 @@ std::string MainController::serializeClientOptions(const ClientOptions& options) } #define CHECK_PARSE_LENGTH if (i >= segments.size()) {return result;} -#define PARSE_INT_RAW CHECK_PARSE_LENGTH intVal = 0; try {intVal = boost::lexical_cast<int>(segments[i]);} catch(const boost::bad_lexical_cast&) {};i++; +#define PARSE_INT_RAW(defaultValue) CHECK_PARSE_LENGTH intVal = defaultValue; try {intVal = boost::lexical_cast<int>(segments[i]);} catch(const boost::bad_lexical_cast&) {};i++; #define PARSE_STRING_RAW CHECK_PARSE_LENGTH stringVal = byteArrayToString(Base64::decode(segments[i]));i++; -#define PARSE_BOOL(option) PARSE_INT_RAW; result.option = (intVal == 1); -#define PARSE_INT(option) PARSE_INT_RAW; result.option = intVal; +#define PARSE_BOOL(option, defaultValue) PARSE_INT_RAW(defaultValue); result.option = (intVal == 1); +#define PARSE_INT(option, defaultValue) PARSE_INT_RAW(defaultValue); result.option = intVal; #define PARSE_STRING(option) PARSE_STRING_RAW; result.option = stringVal; #define PARSE_SAFE_STRING(option) PARSE_STRING_RAW; result.option = SafeString(createSafeByteArray(stringVal)); -#define PARSE_URL(option) {PARSE_STRING_RAW; std::string scheme = stringVal; PARSE_STRING_RAW; std::string host = stringVal; PARSE_INT_RAW; int port = intVal; PARSE_STRING_RAW; std::string path = stringVal; result.option = !scheme.empty() && !host.empty() ? URL(scheme, host, port, path) : URL();} +#define PARSE_URL(option) {PARSE_STRING_RAW; std::string scheme = stringVal; PARSE_STRING_RAW; std::string host = stringVal; PARSE_INT_RAW(0); int port = intVal; PARSE_STRING_RAW; std::string path = stringVal; result.option = !scheme.empty() && !host.empty() ? URL(scheme, host, port, path) : URL();} ClientOptions MainController::parseClientOptions(const std::string& optionString) { @@ -800,20 +800,20 @@ ClientOptions MainController::parseClientOptions(const std::string& optionString std::string stringVal; std::vector<std::string> segments = String::split(optionString, ','); - PARSE_BOOL(useStreamCompression); - PARSE_INT_RAW; + PARSE_BOOL(useStreamCompression, 1); + PARSE_INT_RAW(-1); switch (intVal) { case 1: result.useTLS = ClientOptions::NeverUseTLS;break; case 2: result.useTLS = ClientOptions::UseTLSWhenAvailable;break; case 3: result.useTLS = ClientOptions::RequireTLS;break; default:; } - PARSE_BOOL(allowPLAINWithoutTLS); - PARSE_BOOL(useStreamResumption); - PARSE_BOOL(useAcks); + PARSE_BOOL(allowPLAINWithoutTLS, 0); + PARSE_BOOL(useStreamResumption, 0); + PARSE_BOOL(useAcks, 1); PARSE_STRING(manualHostname); - PARSE_INT(manualPort); - PARSE_INT_RAW; + PARSE_INT(manualPort, -1); + PARSE_INT_RAW(-1); switch (intVal) { case 1: result.proxyType = ClientOptions::NoProxy;break; case 2: result.proxyType = ClientOptions::SystemConfiguredProxy;break; @@ -821,7 +821,7 @@ ClientOptions MainController::parseClientOptions(const std::string& optionString case 4: result.proxyType = ClientOptions::HTTPConnectProxy;break; } PARSE_STRING(manualProxyHostname); - PARSE_INT(manualProxyPort); + PARSE_INT(manualProxyPort, -1); PARSE_URL(boshURL); PARSE_URL(boshHTTPConnectProxyURL); PARSE_SAFE_STRING(boshHTTPConnectProxyAuthID); diff --git a/Swift/QtUI/QtConnectionSettingsWindow.cpp b/Swift/QtUI/QtConnectionSettingsWindow.cpp index 324eb06..b5afe50 100644 --- a/Swift/QtUI/QtConnectionSettingsWindow.cpp +++ b/Swift/QtUI/QtConnectionSettingsWindow.cpp @@ -49,8 +49,21 @@ QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& opti ClientOptions defaults; if (options.boshURL.empty()) { - bool isDefault = options.useStreamCompression == defaults.useStreamCompression && options.useTLS == defaults.useTLS && options.allowPLAINWithoutTLS == defaults.allowPLAINWithoutTLS && options.useStreamCompression == defaults.useStreamCompression && options.useAcks == defaults.useAcks && options.manualHostname == defaults.manualHostname && options.manualPort == defaults.manualPort && options.proxyType == defaults.proxyType && options.manualProxyHostname == defaults.manualProxyHostname && options.manualProxyPort == defaults.manualProxyPort; - if (!isDefault) { + int i = 0; + bool isDefault = options.useStreamCompression == defaults.useStreamCompression; + isDefault &= options.useTLS == defaults.useTLS; + isDefault &= options.allowPLAINWithoutTLS == defaults.allowPLAINWithoutTLS; + isDefault &= options.useStreamCompression == defaults.useStreamCompression; + isDefault &= options.useAcks == defaults.useAcks; + isDefault &= options.manualHostname == defaults.manualHostname; + isDefault &= options.manualPort == defaults.manualPort; + isDefault &= options.proxyType == defaults.proxyType; + isDefault &= options.manualProxyHostname == defaults.manualProxyHostname; + isDefault &= options.manualProxyPort == defaults.manualProxyPort; + if (isDefault) { + ui.connectionMethod->setCurrentIndex(0); + } + else { ui.connectionMethod->setCurrentIndex(1); ui.manual_useTLS->setCurrentIndex(options.useTLS); ui.manual_allowPLAINWithoutTLS->setChecked(options.allowPLAINWithoutTLS); |