From 1ebd045cadb3585c846ea38c63d508e5aa6ec1e7 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 22 Mar 2010 17:40:13 +0000 Subject: Sucky UI for subscription requests diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp index 91eb2c1..def124a 100644 --- a/Swift/QtUI/EventViewer/QtEventWindow.cpp +++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp @@ -1,11 +1,14 @@ + #include "Swift/QtUI/EventViewer/QtEventWindow.h" #include #include "Swiften/Events/MessageEvent.h" +#include "Swift/QtUI/QtSubscriptionRequestWindow.h" #include "Swiften/Events/SubscriptionRequestEvent.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" + #include "Swiften/Base/Platform.h" namespace Swift { @@ -39,8 +42,8 @@ void QtEventWindow::handleItemActivated(const QModelIndex& item) { if (messageEvent) { eventStream_->send(boost::shared_ptr(new RequestChatUIEvent(messageEvent->getStanza()->getFrom()))); } else if (subscriptionEvent) { - printf("Subscription activated\n"); - //FIXME: do something + QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this); + window->show(); } else { qWarning() << "Trying to activate an unexpected event"; } diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.cpp b/Swift/QtUI/QtSubscriptionRequestWindow.cpp new file mode 100644 index 0000000..df0c8e6 --- /dev/null +++ b/Swift/QtUI/QtSubscriptionRequestWindow.cpp @@ -0,0 +1,77 @@ +#include "Swift/QtUI/QtSubscriptionRequestWindow.h" + +#include +#include +#include +#include + +#include "Swift/QtUI/QtSwiftUtil.h" + +namespace Swift { +QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(boost::shared_ptr event, QWidget* parent) : QDialog(parent), event_(event) { + QString text = P2QSTRING(event->getJID().toString()) + " would like to add you to their roster. Would you like to add them to your roster and share your status when you're online? If you choose to defer this choice, you'll be asked again when you next login."; + QVBoxLayout* layout = new QVBoxLayout(); + QLabel* label = new QLabel(text, this); + layout->addWidget(label); + + if (event_->getConcluded()) { + QLabel* doneLabel = new QLabel("You have already replied to this request"); + QPushButton* okButton = new QPushButton("OK", this); + connect(okButton, SIGNAL(clicked()), this, SLOT(handleDefer())); + layout->addWidget(doneLabel); + layout->addWidget(okButton); + } else { + QPushButton* yesButton = new QPushButton("Yes", this); + connect(yesButton, SIGNAL(clicked()), this, SLOT(handleYes())); + QPushButton* noButton = new QPushButton("No", this); + connect(noButton, SIGNAL(clicked()), this, SLOT(handleNo())); + QPushButton* deferButton = new QPushButton("Defer", this); + connect(deferButton, SIGNAL(clicked()), this, SLOT(handleDefer())); + + QHBoxLayout* buttonLayout = new QHBoxLayout(); + buttonLayout->addWidget(yesButton); + buttonLayout->addWidget(noButton); + buttonLayout->addWidget(deferButton); + + layout->addLayout(buttonLayout); + } + + setLayout(layout); +} + +void QtSubscriptionRequestWindow::handleYes() { + event_->accept(); + delete this; +} + +void QtSubscriptionRequestWindow::handleNo() { + event_->decline(); + delete this; +} + +void QtSubscriptionRequestWindow::handleDefer() { + delete this; +} + +QtSubscriptionRequestWindow::~QtSubscriptionRequestWindow() { + windows_.removeOne(this); +} + +QtSubscriptionRequestWindow* QtSubscriptionRequestWindow::getWindow(boost::shared_ptr event, QWidget* parent) { + foreach (QtSubscriptionRequestWindow* window, windows_) { + if (window->getEvent() == event) { + return window; + } + } + QtSubscriptionRequestWindow* window = new QtSubscriptionRequestWindow(event, parent); + windows_.append(window); + return window; +} + +boost::shared_ptr QtSubscriptionRequestWindow::getEvent() { + return event_; +} + +QList QtSubscriptionRequestWindow::windows_; + +} diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.h b/Swift/QtUI/QtSubscriptionRequestWindow.h new file mode 100644 index 0000000..692b45b --- /dev/null +++ b/Swift/QtUI/QtSubscriptionRequestWindow.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +#include "Swiften/Events/SubscriptionRequestEvent.h" + +namespace Swift { + class QtSubscriptionRequestWindow : public QDialog { + Q_OBJECT + public: + static QtSubscriptionRequestWindow* getWindow(boost::shared_ptr event, QWidget* parent = 0); + ~QtSubscriptionRequestWindow(); + boost::shared_ptr getEvent(); + private slots: + void handleYes(); + void handleNo(); + void handleDefer(); + private: + QtSubscriptionRequestWindow(boost::shared_ptr event, QWidget* parent = 0); + static QList windows_; + boost::shared_ptr event_; + /*QPushButton* yesButton_; + QPushButton* noButton_; + QPushButton* deferButton_;*/ + }; +} diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index f1a229a..e6a62aa 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -84,6 +84,7 @@ sources = [ "EventViewer/QtEventWindowFactory.cpp", "EventViewer/QtEventWindow.cpp", "EventViewer/QtEvent.cpp", + "QtSubscriptionRequestWindow.cpp", "QtRosterHeader.cpp", "qrc_DefaultTheme.cc", "qrc_Swift.cc", diff --git a/Swiften/Events/MessageEvent.h b/Swiften/Events/MessageEvent.h index 1f71493..43174a1 100644 --- a/Swiften/Events/MessageEvent.h +++ b/Swiften/Events/MessageEvent.h @@ -22,7 +22,7 @@ namespace Swift { void read() { assert (isReadable()); - onConclusion(); + conclude(); } private: diff --git a/Swiften/Events/StanzaEvent.h b/Swiften/Events/StanzaEvent.h index adef112..b1dc537 100644 --- a/Swiften/Events/StanzaEvent.h +++ b/Swiften/Events/StanzaEvent.h @@ -6,8 +6,13 @@ namespace Swift { class StanzaEvent { public: - StanzaEvent(){}; + StanzaEvent(){concluded_ = false;}; virtual ~StanzaEvent() {}; + void conclude() {concluded_ = true; onConclusion();}; + /** Do not call this directly from outside the class */ boost::signal onConclusion; + bool getConcluded() {return concluded_;}; + private: + bool concluded_; }; } diff --git a/Swiften/Events/SubscriptionRequestEvent.h b/Swiften/Events/SubscriptionRequestEvent.h index fe41df7..ed063d7 100644 --- a/Swiften/Events/SubscriptionRequestEvent.h +++ b/Swiften/Events/SubscriptionRequestEvent.h @@ -20,13 +20,13 @@ namespace Swift { boost::signal onDecline; void accept() { onAccept(); - onConclusion(); - } + conclude(); + }; void decline() { onDecline(); - onConclusion(); - } + conclude(); + }; private: JID jid_; -- cgit v0.10.2-6-g49f6