/src/sip/jabber/jabber.h

http://github.com/tomahawk-player/tomahawk · C Header · 168 lines · 115 code · 33 blank · 20 comment · 0 complexity · 218e55b6caae1b77c0cee7d20b13b8b8 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
  4. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef JABBER_H
  20. #define JABBER_H
  21. #include "sip/SipPlugin.h"
  22. #include "avatarmanager.h"
  23. #ifndef ENABLE_HEADLESS
  24. #include "xmlconsole.h"
  25. #endif
  26. #include <jreen/client.h>
  27. #include <jreen/disco.h>
  28. #include <jreen/message.h>
  29. #include <jreen/messagesession.h>
  30. #include <jreen/stanza.h>
  31. #include <jreen/jreen.h>
  32. #include <jreen/error.h>
  33. #include <jreen/presence.h>
  34. #include <jreen/vcard.h>
  35. #include <jreen/abstractroster.h>
  36. #include <jreen/connection.h>
  37. #include <jreen/mucroom.h>
  38. #ifndef ENABLE_HEADLESS
  39. #include <QMessageBox>
  40. #endif
  41. #define MYNAME "SIPJREEN"
  42. #define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" )
  43. #define TOMAHAWK_CAP_NODE_NAME QLatin1String( "http://tomahawk-player.org/" )
  44. #include "../sipdllmacro.h"
  45. class Ui_JabberConfig;
  46. class SIPDLLEXPORT JabberFactory : public SipPluginFactory
  47. {
  48. Q_OBJECT
  49. Q_INTERFACES( SipPluginFactory )
  50. public:
  51. JabberFactory() {}
  52. virtual ~JabberFactory() {}
  53. virtual QString prettyName() const { return "Jabber"; }
  54. virtual QString factoryId() const { return "sipjabber"; }
  55. virtual QIcon icon() const;
  56. virtual SipPlugin* createPlugin( const QString& pluginId );
  57. };
  58. class SIPDLLEXPORT JabberPlugin : public SipPlugin
  59. {
  60. Q_OBJECT
  61. public:
  62. JabberPlugin( const QString& pluginId );
  63. virtual ~JabberPlugin();
  64. //FIXME: Make this more correct
  65. virtual bool isValid() const { return true; }
  66. virtual const QString name() const;
  67. virtual const QString friendlyName() const;
  68. virtual const QString accountName() const;
  69. virtual ConnectionState connectionState() const;
  70. #ifndef ENABLE_HEADLESS
  71. virtual QMenu* menu();
  72. virtual QIcon icon() const;
  73. virtual QWidget* configWidget();
  74. #endif
  75. virtual void saveConfig();
  76. virtual void deletePlugin();
  77. signals:
  78. void dataError( bool exists );
  79. void jidChanged( const QString& );
  80. public slots:
  81. virtual bool connectPlugin( bool startup );
  82. void disconnectPlugin();
  83. void checkSettings();
  84. void sendMsg( const QString& to, const QString& msg );
  85. void broadcastMsg( const QString &msg );
  86. void addContact( const QString &jid, const QString& msg = QString() );
  87. void showAddFriendDialog();
  88. protected:
  89. virtual QString defaultSuffix() const;
  90. Ui_JabberConfig* m_ui; // so the google wrapper can change the config dialog a bit
  91. private slots:
  92. void showXmlConsole();
  93. void onConnect();
  94. void onDisconnect(Jreen::Client::DisconnectReason reason);
  95. void onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence );
  96. void onSubscriptionReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence );
  97. void onSubscriptionRequestConfirmed( int result );
  98. void onNewMessage( const Jreen::Message& message );
  99. void onError( const Jreen::Connection::SocketError& e );
  100. void onNewIq( const Jreen::IQ &iq );
  101. void onNewAvatar( const QString &jid );
  102. void onCheckJidExists( QString jid );
  103. private:
  104. bool readXmlConsoleEnabled();
  105. QString readPassword();
  106. QString readServer();
  107. int readPort();
  108. QString errorMessage( Jreen::Client::DisconnectReason reason );
  109. void setupClientHelper();
  110. void addMenuHelper();
  111. void removeMenuHelper();
  112. bool presenceMeansOnline( Jreen::Presence::Type p );
  113. void handlePeerStatus( const Jreen::JID &jid, Jreen::Presence::Type presenceType );
  114. using SipPlugin::errorMessage;
  115. QString m_currentUsername;
  116. QString m_currentPassword;
  117. QString m_currentServer;
  118. int m_currentPort;
  119. ConnectionState m_state;
  120. QWeakPointer< QWidget > m_configWidget;
  121. QString m_currentResource;
  122. // sort out
  123. Jreen::Client *m_client;
  124. Jreen::MUCRoom *m_room;
  125. Jreen::SimpleRoster *m_roster;
  126. QHash<Jreen::JID, Jreen::Presence::Type> m_peers;
  127. #ifndef ENABLE_HEADLESS
  128. QHash<Jreen::JID, QMessageBox*> m_subscriptionConfirmBoxes;
  129. QMenu* m_menu;
  130. XmlConsole* m_xmlConsole;
  131. #endif
  132. enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
  133. AvatarManager *m_avatarManager;
  134. };
  135. #endif