diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-11-28 20:07:57 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-11-28 20:16:52 (GMT) |
commit | 5c2567847c73f6095206dfbd451fe2f26f4056aa (patch) | |
tree | 06a9ed263bec86531bd08b89242c78b3aeb0d8a0 | |
parent | 85dcc894ccf417ec8b057d868afb1d8006634ac4 (diff) | |
download | swift-5c2567847c73f6095206dfbd451fe2f26f4056aa.zip swift-5c2567847c73f6095206dfbd451fe2f26f4056aa.tar.bz2 |
Implemented XML console.
Resolves: #135
-rw-r--r-- | Swift/Controllers/MainController.cpp | 16 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/XMLConsoleWidget.h | 5 | ||||
-rw-r--r-- | Swift/Controllers/XMLConsoleController.cpp | 12 | ||||
-rw-r--r-- | Swift/Controllers/XMLConsoleController.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtXMLConsoleWidget.cpp | 46 | ||||
-rw-r--r-- | Swift/QtUI/QtXMLConsoleWidget.h | 22 |
6 files changed, 90 insertions, 17 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 2e640e0..8800da0 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -42,22 +42,12 @@ #include "Swiften/Queries/Requests/GetVCardRequest.h" #include "Swiften/Avatars/AvatarFileStorage.h" #include "Swiften/Avatars/AvatarManager.h" #include "Swiften/StringCodecs/SHA1.h" #include "Swiften/StringCodecs/Hexify.h" -namespace { - void printIncomingData(const Swift::String& data) { - std::cout << "<- " << data << std::endl; - } - - void printOutgoingData(const Swift::String& data) { - std::cout << "-> " << data << std::endl; - } -} - namespace Swift { static const String CLIENT_NAME = "Swift"; static const String CLIENT_VERSION = "0.3"; static const String CLIENT_NODE = "http://swift.im"; @@ -270,14 +260,16 @@ void MainController::handleLoginRequest(const String &username, const String &pa } void MainController::performLoginFromCachedCredentials() { if (!client_) { client_ = new Swift::Client(jid_, password_); presenceSender_ = new PresenceSender(client_); - //client_->onDataRead.connect(&printIncomingData); - //client_->onDataWritten.connect(&printOutgoingData); + client_->onDataRead.connect(boost::bind( + &XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); + client_->onDataWritten.connect(boost::bind( + &XMLConsoleController::handleDataWritten, xmlConsoleController_, _1)); if (!certificateFile_.isEmpty()) { client_->setCertificate(certificateFile_); } client_->onError.connect(boost::bind(&MainController::handleError, this, _1)); client_->onConnected.connect(boost::bind(&MainController::handleConnected, this)); client_->onMessageReceived.connect(boost::bind(&MainController::handleIncomingMessage, this, _1)); diff --git a/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h b/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h index e333d97..eab29a8 100644 --- a/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h +++ b/Swift/Controllers/UIInterfaces/XMLConsoleWidget.h @@ -1,11 +1,16 @@ #pragma once namespace Swift { + class String; + class XMLConsoleWidget { public: virtual ~XMLConsoleWidget(); + virtual void handleDataRead(const String& data) = 0; + virtual void handleDataWritten(const String& data) = 0; + virtual void show() = 0; virtual void activate() = 0; }; } diff --git a/Swift/Controllers/XMLConsoleController.cpp b/Swift/Controllers/XMLConsoleController.cpp index 4629573..7de5b94 100644 --- a/Swift/Controllers/XMLConsoleController.cpp +++ b/Swift/Controllers/XMLConsoleController.cpp @@ -21,7 +21,19 @@ void XMLConsoleController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { } xmlConsoleWidget->show(); xmlConsoleWidget->activate(); } } +void XMLConsoleController::handleDataRead(const String& data) { + if (xmlConsoleWidget) { + xmlConsoleWidget->handleDataRead(data); + } +} + +void XMLConsoleController::handleDataWritten(const String& data) { + if (xmlConsoleWidget) { + xmlConsoleWidget->handleDataWritten(data); + } +} + } diff --git a/Swift/Controllers/XMLConsoleController.h b/Swift/Controllers/XMLConsoleController.h index 52a8269..134bf0d 100644 --- a/Swift/Controllers/XMLConsoleController.h +++ b/Swift/Controllers/XMLConsoleController.h @@ -4,19 +4,25 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include "Swift/Controllers/UIEvents/UIEventStream.h" namespace Swift { + class String; class XMLConsoleWidgetFactory; class XMLConsoleWidget; + class XMLConsoleController { public: XMLConsoleController(UIEventStream* uiEventStream, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory); ~XMLConsoleController(); + public: + void handleDataRead(const String& data); + void handleDataWritten(const String& data); + private: void handleUIEvent(boost::shared_ptr<UIEvent> event); private: XMLConsoleWidgetFactory* xmlConsoleWidgetFactory; XMLConsoleWidget* xmlConsoleWidget; diff --git a/Swift/QtUI/QtXMLConsoleWidget.cpp b/Swift/QtUI/QtXMLConsoleWidget.cpp index 7553d06..662f070 100644 --- a/Swift/QtUI/QtXMLConsoleWidget.cpp +++ b/Swift/QtUI/QtXMLConsoleWidget.cpp @@ -1,13 +1,40 @@ #include "QtXMLConsoleWidget.h" #include <QCloseEvent> +#include <QTextEdit> +#include <QVBoxLayout> +#include <QPushButton> +#include <QScrollBar> + +#include "QtSwiftUtil.h" +#include "Swiften/Base/String.h" namespace Swift { + QtXMLConsoleWidget::QtXMLConsoleWidget() { + setWindowTitle("Console"); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setSpacing(0); + layout->setContentsMargins(0,0,0,0); + textEdit = new QTextEdit(this); + textEdit->setReadOnly(true); + layout->addWidget(textEdit); + + QWidget* bottom = new QWidget(this); + layout->addWidget(bottom); + + QHBoxLayout* buttonLayout = new QHBoxLayout(bottom); + buttonLayout->setContentsMargins(0,0,20,0); + buttonLayout->setSpacing(0); + buttonLayout->addStretch(); + QPushButton* clearButton = new QPushButton("Clear", bottom); + connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear())); + buttonLayout->addWidget(clearButton); } void QtXMLConsoleWidget::showEvent(QShowEvent* event) { emit windowOpening(); QWidget::showEvent(event); } @@ -23,7 +50,26 @@ void QtXMLConsoleWidget::activate() { void QtXMLConsoleWidget::closeEvent(QCloseEvent* event) { emit windowClosing(); event->accept(); } +void QtXMLConsoleWidget::handleDataRead(const String& data) { + textEdit->setTextColor(QColor(33,98,33)); + appendText(data); +} + +void QtXMLConsoleWidget::handleDataWritten(const String& data) { + textEdit->setTextColor(QColor(155,1,0)); + appendText(data); +} + +void QtXMLConsoleWidget::appendText(const String& data) { + QScrollBar* scrollBar = textEdit->verticalScrollBar(); + bool scrollToBottom = (!scrollBar || scrollBar->value() == scrollBar->maximum()); + textEdit->append(P2QSTRING(data)); + if (scrollToBottom) { + textEdit->ensureCursorVisible(); + } +} + } diff --git a/Swift/QtUI/QtXMLConsoleWidget.h b/Swift/QtUI/QtXMLConsoleWidget.h index 50b53f2..0d5a10d 100644 --- a/Swift/QtUI/QtXMLConsoleWidget.h +++ b/Swift/QtUI/QtXMLConsoleWidget.h @@ -1,18 +1,30 @@ #pragma once #include "Swift/Controllers/UIInterfaces/XMLConsoleWidget.h" #include "QtTabbable.h" +class QTextEdit; + namespace Swift { class QtXMLConsoleWidget : public QtTabbable, public XMLConsoleWidget { - Q_OBJECT + Q_OBJECT + public: QtXMLConsoleWidget(); + void show(); void activate(); - protected slots: - void closeEvent(QCloseEvent* event); - protected: - void showEvent(QShowEvent* event); + + virtual void handleDataRead(const String& data); + virtual void handleDataWritten(const String& data); + + private: + virtual void closeEvent(QCloseEvent* event); + virtual void showEvent(QShowEvent* event); + + void appendText(const String& data); + + private: + QTextEdit* textEdit; }; } |