From ecd4309da49ad3186ae829b7c8b50eb78f856249 Mon Sep 17 00:00:00 2001 From: Kevin Smith <git@kismith.co.uk> Date: Mon, 31 May 2010 22:13:00 +0100 Subject: Add option to autojoin when joining a room. Resolves: #380 diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp index a8bf9ee..b1cfd65 100644 --- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp +++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp @@ -10,6 +10,7 @@ #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" +#include "Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h" #include "Swift/QtUI/MUCSearch/MUCSearchModel.h" #include "Swift/QtUI/MUCSearch/MUCSearchDelegate.h" #include "Swift/QtUI/QtSwiftUtil.h" @@ -79,14 +80,37 @@ void QtMUCSearchWindow::handleJoin() { } boost::optional<String> maybeNick; if (!nickName_->text().isEmpty()) { - maybeNick = Q2PSTRING(nickName_->text()); + lastSetNick_ = Q2PSTRING(nickName_->text()); + maybeNick = lastSetNick_; } - eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(JID(Q2PSTRING(room_->text())), maybeNick))); + + JID room(Q2PSTRING(room_->text())); + if (joinAutomatically_->isChecked()) { + createAutoJoin(room, maybeNick); + } + eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(room, maybeNick))); hide(); } +void QtMUCSearchWindow::createAutoJoin(const JID& room, boost::optional<String> passedNick) { + String nick = lastSetNick_; + if (passedNick) { + nick = passedNick.get(); + } + MUCBookmark bookmark(room, room.getNode()); + bookmark.setAutojoin(true); + if (!nick.isEmpty()) { + bookmark.setNick(nick); + } + //if (!password.isEmpty()) { + // bookmark.setPassword(password); + //} + eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark))); +} + void QtMUCSearchWindow::setNick(const String& nick) { nickName_->setText(P2QSTRING(nick)); + lastSetNick_ = nick; } void QtMUCSearchWindow::setMUC(const String& nick) { diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h index 7b556b0..c0a8e72 100644 --- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h +++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h @@ -32,8 +32,10 @@ namespace Swift { void handleSelected(const QModelIndex& current); void handleActivated(const QModelIndex& index); private: + void createAutoJoin(const JID& room, boost::optional<String> passedNick); MUCSearchModel* model_; MUCSearchDelegate* delegate_; UIEventStream* eventStream_; + String lastSetNick_; }; } diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.ui b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.ui index d3d327e..11c4df2 100644 --- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.ui +++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.ui @@ -95,7 +95,7 @@ <property name="geometry"> <rect> <x>280</x> - <y>410</y> + <y>380</y> <width>211</width> <height>18</height> </rect> @@ -131,7 +131,7 @@ <property name="geometry"> <rect> <x>280</x> - <y>430</y> + <y>400</y> <width>201</width> <height>26</height> </rect> @@ -179,6 +179,19 @@ <string>Search</string> </property> </widget> + <widget class="QCheckBox" name="joinAutomatically_"> + <property name="geometry"> + <rect> + <x>280</x> + <y>440</y> + <width>211</width> + <height>22</height> + </rect> + </property> + <property name="text"> + <string>Join automatically in future</string> + </property> + </widget> </widget> <resources/> <connections/> -- cgit v0.10.2-6-g49f6