qmlxmppclient.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef QMLXMPPCLIENT_H
  2. #define QMLXMPPCLIENT_H
  3. #include <QObject>
  4. #include <QtDeclarative>
  5. #include <QStringList>
  6. #include <QVariant>
  7. #include <QXmppPresence.h>
  8. //#include "MyXmppClient.h"
  9. class QMLXmppClient : public QObject
  10. {
  11. Q_OBJECT
  12. Q_DISABLE_COPY( QMLXmppClient )
  13. Q_PROPERTY( QString jidLastMsg READ getJidLastMsg NOTIFY messageReceived )
  14. Q_PROPERTY( bool isTyping READ getTyping NOTIFY typingChange )
  15. Q_PROPERTY( int Connecting READ getValueConnecting ) //const
  16. Q_PROPERTY( int Connected READ getValueConnected ) //const
  17. Q_PROPERTY( int Disconnected READ getValueDisconnected ) //const
  18. Q_PROPERTY( int stateConnect READ getStateConnect NOTIFY connectingChanged )
  19. Q_PROPERTY( QString statusText READ getStatusText NOTIFY statusTextChanged )
  20. Q_PROPERTY( StatusXmpp status READ getStatus NOTIFY statusChanged FINAL )
  21. Q_PROPERTY( QVariant subscriptionJids READ getListSubscription NOTIFY subscriptionReceived )
  22. Q_PROPERTY( QString myJid READ getMyJid() NOTIFY myJidChanged )
  23. static QMLXmppClient* instance;
  24. QString jidLastMessage;
  25. bool flTyping;
  26. int m_stateConnect;
  27. QString m_statusText;
  28. QStringList m_listSubscriptions;
  29. public:
  30. enum StatusXmpp {
  31. Online = 1,
  32. Chat = 2,
  33. Away = 3,
  34. XA = 4,
  35. DND = 5,
  36. Offline = 0
  37. };
  38. enum StateConnect {
  39. Disconnect = 0,
  40. Connected = 1,
  41. Connecting = 2
  42. };
  43. Q_ENUMS( StatusXmpp )
  44. explicit QMLXmppClient(QObject *parent = 0);
  45. static QMLXmppClient* getInstance() { return QMLXmppClient::instance; }
  46. void emitMsgRecv(const QString &jid ) { jidLastMessage = jid; emit messageReceived(); }
  47. QString getJidLastMsg() const { return jidLastMessage; }
  48. /* собеседник печатает/не печатает сообщение */
  49. bool getTyping() const { return flTyping; }
  50. void setTyping( QString &jid, const bool isTyping ) { flTyping = isTyping; emit typingChange(jid, isTyping); }
  51. /* константы определяющие соединения */
  52. int getValueConnecting() const { return QMLXmppClient::MYXMPP_CONNECTING; }
  53. int getValueConnected() const { return QMLXmppClient::MYXMPP_CONNECTED; }
  54. int getValueDisconnected() const { return QMLXmppClient::MYXMPP_DISCONNECTED; }
  55. int getStateConnect() const { return m_stateConnect; }
  56. void setStateConnect( const int st );
  57. /* статус xmpp клиента */
  58. StatusXmpp getStatus() const { return m_status; }
  59. void setStatus( QXmppPresence::Status::Type __status, const bool flNotify = true );
  60. /* текст статуса */
  61. QString getStatusText() const { return m_statusText; }
  62. void setStatusText( const QString &__statusText, const bool flNotify = false );
  63. /* */
  64. QVariant getListSubscription() { return QVariant(m_listSubscriptions); }
  65. void setListSubscription( const QStringList &listSubscriptions ) { m_listSubscriptions = listSubscriptions; emit subscriptionReceived(); }
  66. /* my jid */
  67. QString getMyJid() const { return m_myjid; }
  68. void setMyJid( const QString &myJid ) { if(myJid != m_myjid) { m_myjid =myJid; emit myJidChanged(); } }
  69. static int MYXMPP_DISCONNECTED;
  70. static int MYXMPP_CONNECTED;
  71. static int MYXMPP_CONNECTING;
  72. signals:
  73. void changeMyJid();
  74. void unreadMessages();
  75. void messageReceived();
  76. void typingChange( QString bareJid, bool isTyping );
  77. void connectingChanged();
  78. void statusChanged();
  79. void statusTextChanged();
  80. void subscriptionReceived();
  81. void myJidChanged();
  82. public slots:
  83. private:
  84. StatusXmpp m_status;
  85. QString m_myjid;
  86. };
  87. QML_DECLARE_TYPE(QMLXmppClient)
  88. #endif // QMLXMPPCLIENT_H