summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-12-04 10:11:35 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-12-04 11:51:30 (GMT)
commit3b2a5153a79ec627113223222ed61190bcb3a7e3 (patch)
treef6636f5ef54a444cf5f8ccf0761e0545ea6811cb
parentfff7ba50011f25fc050329c5db9d0ff8fe11abfa (diff)
downloadswift-3b2a5153a79ec627113223222ed61190bcb3a7e3.zip
swift-3b2a5153a79ec627113223222ed61190bcb3a7e3.tar.bz2
Add validation for BOSH URLs in the connection dialog.
Change-Id: I967565abb867279238919f0e5eae6ebe0641d195 Resolves: #1186
-rw-r--r--Swift/QtUI/QtConnectionSettings.ui18
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.cpp17
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.h1
-rw-r--r--Swift/QtUI/QtURLValidator.cpp25
-rw-r--r--Swift/QtUI/QtURLValidator.h17
-rw-r--r--Swift/QtUI/SConscript3
6 files changed, 63 insertions, 18 deletions
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
@@ -64,25 +64,25 @@
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="page_3"/>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
@@ -502,40 +502,24 @@
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>QtConnectionSettings</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QtConnectionSettings</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
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
@@ -8,25 +8,28 @@
#include <boost/lexical_cast.hpp>
#include <QCoreApplication>
#include <QIcon>
#include <QLabel>
#include <QVBoxLayout>
#include <QtGlobal>
#include <QPushButton>
#include <QTextEdit>
#include <QFile>
#include <QTextStream>
+#include <QMessageBox>
+
#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtURLValidator.h>
namespace Swift {
QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& options) : QDialog() {
ui.setupUi(this);
connect(ui.connectionMethod, SIGNAL(currentIndexChanged(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostNameLabel, SLOT(setEnabled(bool)));
connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostName, SLOT(setEnabled(bool)));
connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPortLabel, SLOT(setEnabled(bool)));
connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPort, SLOT(setEnabled(bool)));
@@ -34,24 +37,29 @@ QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& opti
connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHostLabel, SLOT(setEnabled(bool)));
connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHost, SLOT(setEnabled(bool)));
connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPortLabel, SLOT(setEnabled(bool)));
connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPort, SLOT(setEnabled(bool)));
connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHostLabel, SLOT(setEnabled(bool)));
connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHost, SLOT(setEnabled(bool)));
connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPortLabel, SLOT(setEnabled(bool)));
connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPort, SLOT(setEnabled(bool)));
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);
ClientOptions defaults;
if (options.boshURL.isEmpty()) {
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;
@@ -92,24 +100,33 @@ QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& opti
}
}
void QtConnectionSettingsWindow::handleProxyTypeChanged(int index) {
bool proxySettingsVisible = index != NoProxy && index != SystemProxy;
ui.manual_manualProxy->setVisible(proxySettingsVisible);
ui.manual_manualProxyHostLabel->setVisible(proxySettingsVisible);
ui.manual_manualProxyHost->setVisible(proxySettingsVisible);
ui.manual_manualProxyPortLabel->setVisible(proxySettingsVisible);
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) {
/* Not automatic */
if (ui.connectionMethod->currentIndex() == 1) {
/* Manual */
options.useTLS = static_cast<ClientOptions::UseTLS>(ui.manual_useTLS->currentIndex());
options.useStreamCompression = ui.manual_allowCompression->isChecked();
options.allowPLAINWithoutTLS = ui.manual_allowPLAINWithoutTLS->isChecked();
if (ui.manual_manualHost->isChecked()) {
options.manualHostname = Q2PSTRING(ui.manual_manualHostName->text());
try {
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
@@ -14,23 +14,24 @@
namespace Swift {
class QtConnectionSettingsWindow : public QDialog {
Q_OBJECT
public:
QtConnectionSettingsWindow(const ClientOptions& options);
ClientOptions getOptions();
private slots:
void handleProxyTypeChanged(int);
+ void handleAcceptRequested();
private:
enum {
NoProxy = 0,
SystemProxy = 1,
SOCKS5Proxy = 2,
HTTPProxy = 3
};
Ui::QtConnectionSettings ui;
};
}
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 <Swift/QtUI/QtURLValidator.h>
+
+#include <Swiften/Base/URL.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+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 <QValidator>
+
+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
@@ -152,25 +152,26 @@ sources = [
"Whiteboard/GView.cpp",
"Whiteboard/TextDialog.cpp",
"Whiteboard/QtWhiteboardWindow.cpp",
"Whiteboard/ColorWidget.cpp",
"QtSubscriptionRequestWindow.cpp",
"QtRosterHeader.cpp",
"QtWebView.cpp",
"qrc_DefaultTheme.cc",
"qrc_Swift.cc",
"QtChatWindowJSBridge.cpp",
"QtMUCConfigurationWindow.cpp",
"QtAffiliationEditor.cpp",
- "QtUISettingConstants.cpp"
+ "QtUISettingConstants.cpp",
+ "QtURLValidator.cpp"
]
# Determine the version
myenv["SWIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift")
if env["PLATFORM"] == "win32" :
swift_windows_version = Version.convertToWindowsVersion(myenv["SWIFT_VERSION"])
myenv["SWIFT_VERSION_MAJOR"] = swift_windows_version[0]
myenv["SWIFT_VERSION_MINOR"] = swift_windows_version[1]
myenv["SWIFT_VERSION_PATCH"] = swift_windows_version[2]
if env["PLATFORM"] == "win32" :