diff options
| author | Manuel Traut <manut@mecka.net> | 2014-02-18 23:36:45 +0100 |
|---|---|---|
| committer | Manuel Traut <manut@mecka.net> | 2014-02-18 23:36:45 +0100 |
| commit | 07761742a5a104020c975f649bd188a950a4891c (patch) | |
| tree | e3b551f1f5680d2fc48a6ad4d84dde46727ac817 | |
| parent | a9f5c60272e630c3de528dc773eb5af491a01e0a (diff) | |
middleware/xmpp: add an example
- this is a minimal qt client that can be used with a jabber/xmpp server
- have a look at the README file for the test setup
Signed-off-by: Manuel Traut <manut@mecka.net>
| -rw-r--r-- | frameworks/middleware/examples/xmpp/README | 28 | ||||
| -rw-r--r-- | frameworks/middleware/examples/xmpp/client.cpp | 24 | ||||
| -rw-r--r-- | frameworks/middleware/examples/xmpp/myclient.cpp | 32 | ||||
| -rw-r--r-- | frameworks/middleware/examples/xmpp/myclient.h | 17 | ||||
| -rw-r--r-- | frameworks/middleware/examples/xmpp/xmpp.pro | 15 |
5 files changed, 116 insertions, 0 deletions
diff --git a/frameworks/middleware/examples/xmpp/README b/frameworks/middleware/examples/xmpp/README new file mode 100644 index 0000000..ef147ce --- /dev/null +++ b/frameworks/middleware/examples/xmpp/README @@ -0,0 +1,28 @@ +a) apt-get install libqxmpp-dev psi ejabberd + +b) edit /etc/ejabberd/ejabberd.cfg to allow inband registration: + + --8<--- + %% No username can be registered via in-band registration: + %% To enable in-band registration, replace 'deny' with 'allow' + % (note that if you remove mod_register from modules list then users will not + % be able to change their password as well as register). + % This setting is default because it's more safe. + {access, register, [{allow, all}]}. + --8<--- + +c) start psi and configure it to use 'localhost' as server and create two + accounts: <yourname>:<yourpass> + qtapp:test + +d) login with <yourname> and qtapp, add both accounts to their contact list, + and try to send messages. logoff the qtapp account. + +e) build the qt client application and start it: + +qmake +make +./client + +f) the qtapp account needs now to be online in psi, write a messagte to qtapp + the message should be displayed in the commandline diff --git a/frameworks/middleware/examples/xmpp/client.cpp b/frameworks/middleware/examples/xmpp/client.cpp new file mode 100644 index 0000000..9390438 --- /dev/null +++ b/frameworks/middleware/examples/xmpp/client.cpp @@ -0,0 +1,24 @@ +/* +* Copyright (C) 2008-2010 Manjeet Dahiya +* +* Author: +* Manjeet Dahiya +* modified 2014 by Manuel Traut <manut@linutronix.de> +*/ + +#include <QtCore/QCoreApplication> + +//#include <qxmpp/QXmppLogger.h> + +#include "myclient.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + // QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); + + MyClient client; + client.connectToServer("qtapp@localhost", "test"); + + return a.exec(); +} diff --git a/frameworks/middleware/examples/xmpp/myclient.cpp b/frameworks/middleware/examples/xmpp/myclient.cpp new file mode 100644 index 0000000..fa28603 --- /dev/null +++ b/frameworks/middleware/examples/xmpp/myclient.cpp @@ -0,0 +1,32 @@ +/* +* Copyright (C) 2008-2010 Manjeet Dahiya +* +* Author: +* Manjeet Dahiya +* +* modified 2014 by Manuel Traut <manut@linutronix.de> +*/ + +#include <qxmpp/QXmppMessage.h> +#include <iostream> + +#include "myclient.h" + +MyClient::MyClient() : QXmppClient() +{ + bool check = connect(this, + SIGNAL(messageReceived(QXmppMessage)), + SLOT(message_rx(QXmppMessage))); + Q_ASSERT(check); + Q_UNUSED(check); +} + +MyClient::~MyClient() { ; } + +void MyClient::message_rx(const QXmppMessage& message) +{ + QString from = message.from(); + QString msg = message.body(); + std::cout<<from.toStdString()<<": "<<msg.toStdString()<<std::endl; + sendPacket(QXmppMessage("", from, "you mean " + msg + "??")); +} diff --git a/frameworks/middleware/examples/xmpp/myclient.h b/frameworks/middleware/examples/xmpp/myclient.h new file mode 100644 index 0000000..22d864c --- /dev/null +++ b/frameworks/middleware/examples/xmpp/myclient.h @@ -0,0 +1,17 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include <qxmpp/QXmppClient.h> + +class MyClient : public QXmppClient +{ + Q_OBJECT +public: + MyClient(); + ~MyClient(); + +public slots: + void message_rx(const QXmppMessage&); +}; + +#endif diff --git a/frameworks/middleware/examples/xmpp/xmpp.pro b/frameworks/middleware/examples/xmpp/xmpp.pro new file mode 100644 index 0000000..7f0be00 --- /dev/null +++ b/frameworks/middleware/examples/xmpp/xmpp.pro @@ -0,0 +1,15 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Feb 18 19:47:09 2014 +###################################################################### + +TEMPLATE = app +TARGET = client +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += client.cpp myclient.cpp +HEADERS += myclient.h + +QT += network +LIBS += -lqxmpp |
