From 651f10eee7bce78b95b61061b9aef6bb4ab81841 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 5 Mar 2012 18:00:34 +0000 Subject: Check validity of MUC names in join dialog Resolves: #868 diff --git a/Swift/QtUI/QtJoinMUCWindow.cpp b/Swift/QtUI/QtJoinMUCWindow.cpp index 14777bd..4884bbd 100644 --- a/Swift/QtUI/QtJoinMUCWindow.cpp +++ b/Swift/QtUI/QtJoinMUCWindow.cpp @@ -1,17 +1,18 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2012 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ + #include "QtJoinMUCWindow.h" -#include "QtSwiftUtil.h" #include #include #include namespace Swift { + QtJoinMUCWindow::QtJoinMUCWindow(UIEventStream* uiEventStream) : uiEventStream(uiEventStream) { ui.setupUi(this); #if QT_VERSION >= 0x040700 @@ -25,6 +26,7 @@ QtJoinMUCWindow::QtJoinMUCWindow(UIEventStream* uiEventStream) : uiEventStream(u // the placeholder when a widget is focused for some reason. ui.nickName->setFocus(); ui.instantRoom->setChecked(true); + ui.nickName->setValidator(new NickValidator(this)); } void QtJoinMUCWindow::handleJoin() { diff --git a/Swift/QtUI/QtJoinMUCWindow.h b/Swift/QtUI/QtJoinMUCWindow.h index 90b4f3f..c7e2d74 100644 --- a/Swift/QtUI/QtJoinMUCWindow.h +++ b/Swift/QtUI/QtJoinMUCWindow.h @@ -6,12 +6,29 @@ #pragma once +#include #include +#include "QtSwiftUtil.h" #include #include namespace Swift { class UIEventStream; + class NickValidator : public QValidator { + Q_OBJECT + public: + NickValidator(QObject* parent) : QValidator(parent) { + } + + virtual QValidator::State validate(QString& input, int& /*pos*/) const { + if (input.isEmpty()) { + return QValidator::Acceptable; + } + JID test("alice", "wonderland.lit", Q2PSTRING(input)); + + return test.isValid() ? QValidator::Acceptable : QValidator::Invalid; + } + }; class QtJoinMUCWindow : public QWidget, public JoinMUCWindow { Q_OBJECT public: -- cgit v0.10.2-6-g49f6