diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtJoinMUCWindow.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtJoinMUCWindow.h | 17 |
2 files changed, 21 insertions, 2 deletions
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,36 +1,38 @@ /* - * 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 <boost/smart_ptr/make_shared.hpp> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> namespace Swift { + QtJoinMUCWindow::QtJoinMUCWindow(UIEventStream* uiEventStream) : uiEventStream(uiEventStream) { ui.setupUi(this); #if QT_VERSION >= 0x040700 ui.room->setPlaceholderText(tr("someroom@rooms.example.com")); #endif connect(ui.room, SIGNAL(returnPressed()), this, SLOT(handleJoin())); connect(ui.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch())); connect(ui.joinButton, SIGNAL(clicked()), this, SLOT(handleJoin())); // FIXME: Temporarily set focus on the nickName field first, so that the // placeholder for the room is visible. This is just because Qt hides // 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() { if (ui.room->text().isEmpty()) { // TODO: Error return; } if (ui.nickName->text().isEmpty()) { // TODO: Error 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 @@ -1,23 +1,40 @@ /* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once +#include <QValidator> #include <string> +#include "QtSwiftUtil.h" #include <Swift/Controllers/UIInterfaces/JoinMUCWindow.h> #include <Swift/QtUI/ui_QtJoinMUCWindow.h> 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: QtJoinMUCWindow(UIEventStream* uiEventStream); virtual void setNick(const std::string& nick); virtual void setMUC(const std::string& nick); virtual void show(); |