summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp')
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp168
1 files changed, 68 insertions, 100 deletions
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
index 7d2caba..3bdc433 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
@@ -10,43 +10,42 @@
#include <QMovie>
#include <QScrollBar>
#include <QTimer>
+#include <QPushButton>
-#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/MUCSearch/MUCSearchEmptyItem.h"
#include "Swift/QtUI/QtSwiftUtil.h"
namespace Swift {
-QtMUCSearchWindow::QtMUCSearchWindow(UIEventStream* eventStream) {
+QtMUCSearchWindow::QtMUCSearchWindow() {
+ ui_.setupUi(this);
#ifndef Q_WS_MAC
setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
- eventStream_ = eventStream;
- setupUi(this);
- showEmptyRooms_->hide();
- filterLabel_->hide();
- filter_->hide();
+ setModal(true);
+ ui_.filter_->hide();
model_ = new MUCSearchModel();
delegate_ = new MUCSearchDelegate();
- results_->setModel(model_);
- results_->setItemDelegate(delegate_);
- results_->setHeaderHidden(true);
-#ifdef SWIFT_PLATFORM_MACOSX
- results_->setAlternatingRowColors(true);
-#endif
- connect(service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&)));
- connect(room_, SIGNAL(returnPressed()), this, SLOT(handleJoin()));
- connect(nickName_, SIGNAL(returnPressed()), room_, SLOT(setFocus()));
- connect(searchButton_, SIGNAL(clicked()), this, SLOT(handleSearch()));
- connect(joinButton_, SIGNAL(clicked()), this, SLOT(handleJoin()));
- connect(results_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleSelected(const QModelIndex&)));
- connect(results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
- throbber_ = new QLabel("Searching", results_);
+ ui_.results_->setModel(model_);
+ ui_.results_->setItemDelegate(delegate_);
+ ui_.results_->setHeaderHidden(true);
+ ui_.results_->setRootIsDecorated(true);
+ ui_.results_->setAnimated(true);
+ ui_.results_->setAlternatingRowColors(true);
+ connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&)));
+ connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&)));
+ // Not using a button box, because i can't seem to be able to make the ok button non-default (on mac)
+ connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+
+ throbber_ = new QLabel("Searching", ui_.results_);
throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_));
throbber_->setToolTip("Searching");
+
hasHadScrollBars_ = false;
updateThrobberPosition();
setSearchInProgress(false);
@@ -62,8 +61,8 @@ void QtMUCSearchWindow::resizeEvent(QResizeEvent* /*event*/) {
void QtMUCSearchWindow::updateThrobberPosition() {
bool isShown = throbber_->isVisible();
- int resultWidth = results_->width();
- int resultHeight = results_->height();
+ int resultWidth = ui_.results_->width();
+ int resultHeight = ui_.results_->height();
//throbberWidth = throbber_->movie()->scaledSize().width();
//throbberHeight = throbber_->movie()->scaledSize().height();
int throbberWidth = 16; /* This is nasty, but the above doesn't work! */
@@ -72,99 +71,43 @@ void QtMUCSearchWindow::updateThrobberPosition() {
* because if you listen for the expanded/collapsed signals, you seem to get them before the scrollbars are updated.
* This seems an acceptable workaround.
*/
- hasHadScrollBars_ |= results_->verticalScrollBar()->isVisible();
- int hMargin = hasHadScrollBars_ ? results_->verticalScrollBar()->width() + 2 : 2;
+ hasHadScrollBars_ |= ui_.results_->verticalScrollBar()->isVisible();
+ int hMargin = hasHadScrollBars_ ? ui_.results_->verticalScrollBar()->width() + 2 : 2;
int vMargin = 2; /* We don't get horizontal scrollbars */
throbber_->setGeometry(QRect(resultWidth - throbberWidth - hMargin, resultHeight - throbberHeight - vMargin, throbberWidth, throbberHeight)); /* include margins */
throbber_->setVisible(isShown);
}
-void QtMUCSearchWindow::addSavedServices(const std::vector<JID>& services) {
- service_->clear();
- foreach (JID jid, services) {
- service_->addItem(P2QSTRING(jid.toString()));
+void QtMUCSearchWindow::addSavedServices(const std::list<JID>& services) {
+ ui_.service_->clear();
+ foreach (const JID& jid, services) {
+ ui_.service_->addItem(P2QSTRING(jid.toString()));
}
- service_->clearEditText();
-}
-
-void QtMUCSearchWindow::handleActivated(const QModelIndex& index) {
- if (!index.isValid()) {
- return;
+ if (!services.empty()) {
+ ui_.service_->setEditText(P2QSTRING(services.begin()->toString()));
}
- MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()));
- if (roomItem) {
- handleSelected(index);
- handleJoin();
+ else {
+ ui_.service_->clearEditText();
}
}
-void QtMUCSearchWindow::handleSelected(const QModelIndex& current) {
- if (!current.isValid()) {
+void QtMUCSearchWindow::handleActivated(const QModelIndex& index) {
+ if (!index.isValid()) {
return;
- }
- MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(current.internalPointer()));
- if (roomItem) {
- room_->setText(roomItem->getNode() + "@" + roomItem->getParent()->getHost());
}
-
-}
-
-void QtMUCSearchWindow::handleSearch(const QString& text) {
- if (text.isEmpty()) {
- return;
+ if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) {
+ accept();
}
- onAddService(JID(Q2PSTRING(text)));
}
void QtMUCSearchWindow::handleSearch() {
- handleSearch(service_->currentText());
-}
-
-
-void QtMUCSearchWindow::handleJoin() {
- if (room_->text().isEmpty()) {
- handleSelected(results_->currentIndex());
- }
- if (room_->text().isEmpty()) {
- return;
- }
- boost::optional<String> maybeNick;
- if (!nickName_->text().isEmpty()) {
- lastSetNick_ = Q2PSTRING(nickName_->text());
- maybeNick = lastSetNick_;
- }
-
- JID room(Q2PSTRING(room_->text()));
- if (joinAutomatically_->isChecked()) {
- createAutoJoin(room, maybeNick);
- }
- eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(room, maybeNick)));
- hide();
+ handleSearch(ui_.service_->currentText());
}
-void QtMUCSearchWindow::createAutoJoin(const JID& room, boost::optional<String> passedNick) {
- String nick = lastSetNick_;
- if (passedNick) {
- nick = passedNick.get();
+void QtMUCSearchWindow::handleSearch(const QString& service) {
+ if (!service.isEmpty()) {
+ onSearchService(JID(Q2PSTRING(service)));
}
- 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) {
- room_->setText(P2QSTRING(nick));
}
void QtMUCSearchWindow::show() {
@@ -179,11 +122,16 @@ void QtMUCSearchWindow::clearList() {
void QtMUCSearchWindow::addService(const MUCService& service) {
updateThrobberPosition();
MUCSearchServiceItem* serviceItem = new MUCSearchServiceItem(P2QSTRING(service.getJID().toString()));
- foreach (MUCService::MUCRoom room, service.getRooms()) {
- new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem);
+ if (service.getRooms().size() > 0) {
+ foreach (MUCService::MUCRoom room, service.getRooms()) {
+ new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem);
+ }
+ }
+ else {
+ new MUCSearchEmptyItem(serviceItem);
}
model_->addService(serviceItem);
- results_->expandAll();
+ ui_.results_->expandAll();
}
void QtMUCSearchWindow::setSearchInProgress(bool searching) {
@@ -195,4 +143,24 @@ void QtMUCSearchWindow::setSearchInProgress(bool searching) {
throbber_->setVisible(searching);
}
+void QtMUCSearchWindow::accept() {
+ QModelIndexList selection = ui_.results_->selectionModel()->selectedIndexes();
+ if (selection.isEmpty()) {
+ onFinished(boost::optional<JID>());
+ }
+ else {
+ QModelIndex selectedItem = selection[0];
+ MUCSearchRoomItem* item = dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(selectedItem.internalPointer()));
+ if (item) {
+ onFinished(JID(Q2PSTRING(item->getNode()), Q2PSTRING(item->getParent()->getHost())));
+ }
+ }
+ QDialog::accept();
+}
+
+void QtMUCSearchWindow::reject() {
+ onFinished(boost::optional<JID>());
+ QDialog::reject();
+}
+
}