From 3b2a5153a79ec627113223222ed61190bcb3a7e3 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 4 Dec 2012 10:11:35 +0000 Subject: Add validation for BOSH URLs in the connection dialog. Change-Id: I967565abb867279238919f0e5eae6ebe0641d195 Resolves: #1186 diff --git a/Swift/QtUI/QtConnectionSettings.ui b/Swift/QtUI/QtConnectionSettings.ui index 7283184..6d59fb8 100644 --- a/Swift/QtUI/QtConnectionSettings.ui +++ b/Swift/QtUI/QtConnectionSettings.ui @@ -73,7 +73,7 @@ - 0 + 2 @@ -511,22 +511,6 @@ buttonBox - accepted() - QtConnectionSettings - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox rejected() QtConnectionSettings reject() diff --git a/Swift/QtUI/QtConnectionSettingsWindow.cpp b/Swift/QtUI/QtConnectionSettingsWindow.cpp index ea693cf..2da527a 100644 --- a/Swift/QtUI/QtConnectionSettingsWindow.cpp +++ b/Swift/QtUI/QtConnectionSettingsWindow.cpp @@ -17,7 +17,10 @@ #include #include #include +#include + #include +#include namespace Swift { @@ -43,6 +46,11 @@ QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& opti connect(ui.manual_proxyType, SIGNAL(currentIndexChanged(int)), SLOT(handleProxyTypeChanged(int))); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(handleAcceptRequested())); + + QtURLValidator* urlValidator = new QtURLValidator(this); + ui.bosh_uri->setValidator(urlValidator); + ui.manual_useTLS->setCurrentIndex(2); ui.manual_proxyType->setCurrentIndex(0); @@ -101,6 +109,15 @@ void QtConnectionSettingsWindow::handleProxyTypeChanged(int index) { ui.manual_manualProxyPort->setVisible(proxySettingsVisible); } +void QtConnectionSettingsWindow::handleAcceptRequested() { + if (ui.connectionMethod->currentIndex() != 2 || ui.bosh_uri->hasAcceptableInput()) { + accept(); + } + else { + QMessageBox::critical(this, tr("Configuration invalid"), tr("The provided BOSH URL is not valid.")); + } +} + ClientOptions QtConnectionSettingsWindow::getOptions() { ClientOptions options; if (ui.connectionMethod->currentIndex() > 0) { diff --git a/Swift/QtUI/QtConnectionSettingsWindow.h b/Swift/QtUI/QtConnectionSettingsWindow.h index 2aed5d1..3b017ab 100644 --- a/Swift/QtUI/QtConnectionSettingsWindow.h +++ b/Swift/QtUI/QtConnectionSettingsWindow.h @@ -23,6 +23,7 @@ namespace Swift { private slots: void handleProxyTypeChanged(int); + void handleAcceptRequested(); private: enum { diff --git a/Swift/QtUI/QtURLValidator.cpp b/Swift/QtUI/QtURLValidator.cpp new file mode 100644 index 0000000..2df59c4 --- /dev/null +++ b/Swift/QtUI/QtURLValidator.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +#include +#include + +namespace Swift { +QtURLValidator::QtURLValidator(QObject* parent) { + +} + +QValidator::State QtURLValidator::validate(QString& input, int& pos) const { + URL url = URL::fromString(Q2PSTRING(input)); + bool valid = !url.isEmpty(); + valid &= (url.getScheme() == "http" || url.getScheme() == "https"); + return valid ? Acceptable : Intermediate; +} + +} + diff --git a/Swift/QtUI/QtURLValidator.h b/Swift/QtUI/QtURLValidator.h new file mode 100644 index 0000000..fa17253 --- /dev/null +++ b/Swift/QtUI/QtURLValidator.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +namespace Swift { + class QtURLValidator : public QValidator { + Q_OBJECT + public: + QtURLValidator(QObject* parent); + virtual QValidator::State validate(QString& input, int& pos) const; + }; +} + diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index c40ba4b..64c3b15 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -161,7 +161,8 @@ sources = [ "QtChatWindowJSBridge.cpp", "QtMUCConfigurationWindow.cpp", "QtAffiliationEditor.cpp", - "QtUISettingConstants.cpp" + "QtUISettingConstants.cpp", + "QtURLValidator.cpp" ] # Determine the version -- cgit v0.10.2-6-g49f6