diff --git a/QmlClient/plugins/QXmpp/plugins.qmltypes b/QmlClient/plugins/QXmpp/plugins.qmltypes index 0402abce3..b8d1110d3 100644 --- a/QmlClient/plugins/QXmpp/plugins.qmltypes +++ b/QmlClient/plugins/QXmpp/plugins.qmltypes @@ -78,6 +78,17 @@ Module { prototype: "QObject" exports: ["QXmpp/QXmppClient 1.0"] exportMetaObjectRevisions: [0] + Enum { + name: "StatusType" + values: { + "Online": 0, + "Away": 1, + "XA": 2, + "DND": 3, + "Chat": 4, + "Invisible": 5 + } + } Property { name: "configuration" type: "QmlQXmppConfiguration" @@ -97,8 +108,8 @@ Module { isPointer: true } Property { name: "vcardManager"; type: "QmlQXmppVCardManager"; isReadonly: true; isPointer: true } - Property { name: "statusType"; type: "string" } - Property { name: "statusText"; type: "string" } + Property { name: "clientStatusType"; type: "StatusType"; isReadonly: true } + Property { name: "clientStatusText"; type: "string"; isReadonly: true } Method { name: "connectUsingConfiguration" } Method { name: "connectToServer" @@ -109,7 +120,11 @@ Module { Method { name: "sendMessage" Parameter { name: "bareJid"; type: "string" } - Parameter { name: "message"; type: "string" } + Parameter { name: "map"; type: "QVariantMap" } + } + Method { + name: "setClientPresence" + Parameter { name: "map"; type: "QVariantMap" } } } Component { @@ -129,6 +144,50 @@ Module { Property { name: "keepAliveInterval"; type: "int" } Property { name: "keepAliveTimeout"; type: "int" } } + Component { + name: "QmlQXmppMessage" + prototype: "QObject" + exports: ["QXmpp/QXmppMessage 1.0"] + exportMetaObjectRevisions: [0] + Enum { + name: "Type" + values: { + "Error": 0, + "Normal": 1, + "Chat": 2, + "GroupChat": 3, + "Headline": 4 + } + } + Enum { + name: "State" + values: { + "None": 0, + "Active": 1, + "Inactive": 2, + "Gone": 3, + "Composing": 4, + "Paused": 5 + } + } + Property { name: "body"; type: "string"; isReadonly: true } + Property { name: "isAttentionRequested"; type: "bool"; isReadonly: true } + Property { name: "isReceiptRequested"; type: "bool"; isReadonly: true } + Property { name: "mucInvitationJid"; type: "string"; isReadonly: true } + Property { name: "mucInvitationPassword"; type: "string"; isReadonly: true } + Property { name: "mucInvitationReason"; type: "string"; isReadonly: true } + Property { name: "receiptId"; type: "string"; isReadonly: true } + Property { name: "stamp"; type: "QDateTime"; isReadonly: true } + Property { name: "subject"; type: "string"; isReadonly: true } + Property { name: "thread"; type: "string"; isReadonly: true } + Property { name: "xhtml"; type: "string"; isReadonly: true } + Property { name: "state"; type: "QmlQXmppMessage::State"; isReadonly: true } + Property { name: "type"; type: "QmlQXmppMessage::Type"; isReadonly: true } + Property { name: "to"; type: "string"; isReadonly: true } + Property { name: "from"; type: "string"; isReadonly: true } + Property { name: "id"; type: "string"; isReadonly: true } + Property { name: "lang"; type: "string"; isReadonly: true } + } Component { name: "QmlQXmppPresence" prototype: "QObject" @@ -261,8 +320,8 @@ Module { Component { name: "QmlQXmppVCard" prototype: "QObject" - exports: ["QXmpp/QXmppVCard 1.0", "QXmpp/QXmppVCardEx 1.0"] - exportMetaObjectRevisions: [0, 0] + exports: ["QXmpp/QXmppVCard 1.0"] + exportMetaObjectRevisions: [0] Property { name: "from"; type: "string" } Property { name: "birthday"; type: "QDate" } Property { name: "description"; type: "string" } diff --git a/QmlClient/plugins/QXmpp/qxmpp-declarative.dll b/QmlClient/plugins/QXmpp/qxmpp-declarative.dll index bd8f32fd9..2138c3989 100644 Binary files a/QmlClient/plugins/QXmpp/qxmpp-declarative.dll and b/QmlClient/plugins/QXmpp/qxmpp-declarative.dll differ diff --git a/qxmpp-declarative/include/QmlQXmppClient.h b/qxmpp-declarative/include/QmlQXmppClient.h index 62fffaec6..efecc3b5d 100644 --- a/qxmpp-declarative/include/QmlQXmppClient.h +++ b/qxmpp-declarative/include/QmlQXmppClient.h @@ -39,14 +39,24 @@ class QXmppArchiveManager; class QmlQXmppClient : public QObject { Q_OBJECT + Q_ENUMS(StatusType) Q_PROPERTY(QmlQXmppConfiguration *configuration READ configuration CONSTANT) Q_PROPERTY(QmlQXmppArchiveManager* archiveManager READ archiveManager CONSTANT) Q_PROPERTY(QmlQXmppRosterManager* rosterManager READ rosterManager CONSTANT) Q_PROPERTY(QmlQXmppVCardManager* vcardManager READ vcardManager CONSTANT) - Q_PROPERTY(QString statusType READ clientStatusType WRITE setClientStatusType NOTIFY statusTypeChanged) - Q_PROPERTY(QString statusText READ clientStatusText WRITE setClientStatusText NOTIFY statusTextChanged) + Q_PROPERTY(StatusType clientStatusType READ clientStatusType NOTIFY clientStatusTypeChanged) + Q_PROPERTY(QString clientStatusText READ clientStatusText NOTIFY clientStatusTextChanged) public: + enum StatusType { + Online = QXmppPresence::Online, + Away, + XA, + DND, + Chat, + Invisible + }; + QmlQXmppClient(QObject *parent = 0); ~QmlQXmppClient(); @@ -54,9 +64,8 @@ class QmlQXmppClient : public QObject QmlQXmppArchiveManager *archiveManager(); QmlQXmppRosterManager *rosterManager(); QmlQXmppVCardManager* vcardManager(); - - QString clientStatusType(); - void setClientStatusType(const QString &value); + + StatusType clientStatusType(); QString clientStatusText(); void setClientStatusText(const QString &value); @@ -94,14 +103,14 @@ class QmlQXmppClient : public QObject void messageReceived(QmlQXmppMessage* message); - // This signal is emitted when client presence type changes. + // This signal is emitted when presence stanza received void presenceReceived(QmlQXmppPresence *presence); // This signal is emitted when client status type changes. - void statusTypeChanged(const QString &type); + void clientStatusTypeChanged(); // This signal is emitted when client status text changes. - void statusTextChanged(const QString &text); + void clientStatusTextChanged(); public slots: // connect using QXmppConfiguration params @@ -109,6 +118,7 @@ public slots: void connectToServer(const QString &jid, const QString &password); void disconnectFromServer(); void sendMessage(const QString& bareJid, QVariantMap map); + void setClientPresence(QVariantMap map); private slots: void onMessageReceived(const QXmppMessage& message); @@ -116,6 +126,8 @@ private slots: private: void connectSignals(); + QXmppPresence::AvailableStatusType intToAvailableStatusType(int value); + StatusType availableStatusTypeToStatusType(QXmppPresence::AvailableStatusType type); private: QXmppClient _client; diff --git a/qxmpp-declarative/src/QmlQXmppClient.cpp b/qxmpp-declarative/src/QmlQXmppClient.cpp index 95f3472cc..4203990f7 100644 --- a/qxmpp-declarative/src/QmlQXmppClient.cpp +++ b/qxmpp-declarative/src/QmlQXmppClient.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -96,28 +97,9 @@ QmlQXmppVCardManager *QmlQXmppClient::vcardManager() return this->_vcardManagerWrapper; } -QString QmlQXmppClient::clientStatusType() +QmlQXmppClient::StatusType QmlQXmppClient::clientStatusType() { - if (this->_client.clientPresence().type() == QXmppPresence::Available) - return QmlQXmppPresence::statusToString(this->_client.clientPresence().availableStatusType()); - - return "offline"; -} - -void QmlQXmppClient::setClientStatusType(const QString &value) -{ - if (value != this->clientStatusType()) { - QXmppPresence presence = this->_client.clientPresence(); - if (value == "offline") { - presence.setType(QXmppPresence::Unavailable); - } else { - presence.setType(QXmppPresence::Available); - presence.setAvailableStatusType(QmlQXmppPresence::stringToStatus(value)); - } - this->_client.setClientPresence(presence); - - emit this->statusTypeChanged(value); - } + return this->availableStatusTypeToStatusType(this->_client.clientPresence().availableStatusType()); } QString QmlQXmppClient::clientStatusText() @@ -125,17 +107,6 @@ QString QmlQXmppClient::clientStatusText() return this->_client.clientPresence().statusText(); } -void QmlQXmppClient::setClientStatusText(const QString &value) -{ - if (value != this->clientStatusText()) { - QXmppPresence presence = this->_client.clientPresence(); - presence.setStatusText(value); - this->_client.setClientPresence(presence); - - emit this->statusTextChanged(value); - } -} - void QmlQXmppClient::connectUsingConfiguration() { this->_client.connectToServer(this->_configuration); @@ -179,6 +150,31 @@ void QmlQXmppClient::sendMessage(const QString& bareJid, QVariantMap map) } } +void QmlQXmppClient::setClientPresence(QVariantMap map) +{ + bool anythingChanged = false; + QXmppPresence presence = this->_client.clientPresence(); + + if (map.contains(QString("type"))) { + QXmppPresence::AvailableStatusType newType = intToAvailableStatusType(map["type"].toInt()); + if (newType != presence.availableStatusType()) { + presence.setAvailableStatusType(newType); + anythingChanged = true; + } + } + + if (map.contains(QString("text"))) { + QString newStatus = map["text"].toString(); + if (newStatus != presence.statusText()) { + presence.setStatusText(newStatus); + anythingChanged = true; + } + } + + if (anythingChanged) + this->_client.setClientPresence(presence); +} + void QmlQXmppClient::onMessageReceived(const QXmppMessage& message) { QmlQXmppMessage qmlmessage(message); @@ -187,6 +183,11 @@ void QmlQXmppClient::onMessageReceived(const QXmppMessage& message) void QmlQXmppClient::onPresenceReceived(const QXmppPresence &presence) { + if (QXmppUtils::jidToBareJid(presence.from()) == this->_client.configuration().jidBare()) { + emit this->clientStatusTypeChanged(); + emit this->clientStatusTextChanged(); + } + QmlQXmppPresence presenceWrapper(presence); emit this->presenceReceived(&presenceWrapper); } @@ -198,4 +199,42 @@ void QmlQXmppClient::connectSignals() SIGNAL_CONNECT_CHECK(connect(&this->_client, SIGNAL(disconnected()), this, SIGNAL(disconnected()))); SIGNAL_CONNECT_CHECK(connect(&this->_client, SIGNAL(messageReceived(const QXmppMessage &)), this, SLOT(onMessageReceived(const QXmppMessage &)))); SIGNAL_CONNECT_CHECK(connect(&this->_client, SIGNAL(presenceReceived(const QXmppPresence &)), this, SLOT(onPresenceReceived(const QXmppPresence &)))); -} \ No newline at end of file +} + +QXmppPresence::AvailableStatusType QmlQXmppClient::intToAvailableStatusType(int value) +{ + switch (value) { + case QmlQXmppClient::Online: + return QXmppPresence::Online; + case QmlQXmppClient::Away: + return QXmppPresence::Away; + case QmlQXmppClient::XA: + return QXmppPresence::XA; + case QmlQXmppClient::DND: + return QXmppPresence::DND; + case QmlQXmppClient::Chat: + return QXmppPresence::Chat; + case QmlQXmppClient::Invisible: + return QXmppPresence::Invisible; + } + return QXmppPresence::Online; +} + +QmlQXmppClient::StatusType QmlQXmppClient::availableStatusTypeToStatusType(QXmppPresence::AvailableStatusType type) +{ + switch (type) { + case QXmppPresence::Online: + return QmlQXmppClient::Online; + case QXmppPresence::Away: + return QmlQXmppClient::Away; + case QXmppPresence::XA: + return QmlQXmppClient::XA; + case QXmppPresence::DND: + return QmlQXmppClient::DND; + case QXmppPresence::Chat: + return QmlQXmppClient::Chat; + case QXmppPresence::Invisible: + return QmlQXmppClient::Invisible; + } + return QmlQXmppClient::Online; +}