PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 13ms RepoModel.GetById 27ms app.codeStats 0ms

/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
 20#ifndef JABBER_H
 21#define JABBER_H
 22
 23#include "sip/SipPlugin.h"
 24
 25#include "avatarmanager.h"
 26
 27#ifndef ENABLE_HEADLESS
 28    #include "xmlconsole.h"
 29#endif
 30
 31#include <jreen/client.h>
 32#include <jreen/disco.h>
 33#include <jreen/message.h>
 34#include <jreen/messagesession.h>
 35#include <jreen/stanza.h>
 36#include <jreen/jreen.h>
 37#include <jreen/error.h>
 38#include <jreen/presence.h>
 39#include <jreen/vcard.h>
 40#include <jreen/abstractroster.h>
 41#include <jreen/connection.h>
 42#include <jreen/mucroom.h>
 43
 44#ifndef ENABLE_HEADLESS
 45    #include <QMessageBox>
 46#endif
 47
 48#define MYNAME "SIPJREEN"
 49#define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" )
 50#define TOMAHAWK_CAP_NODE_NAME QLatin1String( "http://tomahawk-player.org/" )
 51
 52#include "../sipdllmacro.h"
 53
 54class Ui_JabberConfig;
 55
 56class SIPDLLEXPORT JabberFactory : public SipPluginFactory
 57{
 58    Q_OBJECT
 59    Q_INTERFACES( SipPluginFactory )
 60
 61public:
 62    JabberFactory() {}
 63    virtual ~JabberFactory() {}
 64
 65    virtual QString prettyName() const { return "Jabber"; }
 66    virtual QString factoryId() const { return "sipjabber"; }
 67    virtual QIcon icon() const;
 68    virtual SipPlugin* createPlugin( const QString& pluginId );
 69};
 70
 71class SIPDLLEXPORT JabberPlugin : public SipPlugin
 72{
 73    Q_OBJECT
 74
 75public:
 76    JabberPlugin( const QString& pluginId );
 77    virtual ~JabberPlugin();
 78
 79    //FIXME: Make this more correct
 80    virtual bool isValid() const { return true; }
 81    virtual const QString name() const;
 82    virtual const QString friendlyName() const;
 83    virtual const QString accountName() const;
 84    virtual ConnectionState connectionState() const;
 85
 86#ifndef ENABLE_HEADLESS
 87    virtual QMenu* menu();
 88    virtual QIcon icon() const;
 89    virtual QWidget* configWidget();
 90#endif
 91    virtual void saveConfig();
 92    virtual void deletePlugin();
 93
 94signals:
 95    void dataError( bool exists );
 96    void jidChanged( const QString& );
 97
 98public slots:
 99    virtual bool connectPlugin( bool startup );
100    void disconnectPlugin();
101    void checkSettings();
102    void sendMsg( const QString& to, const QString& msg );
103    void broadcastMsg( const QString &msg );
104    void addContact( const QString &jid, const QString& msg = QString() );
105    void showAddFriendDialog();
106
107protected:
108    virtual QString defaultSuffix() const;
109
110    Ui_JabberConfig* m_ui; // so the google wrapper can change the config dialog a bit
111
112private slots:
113    void showXmlConsole();
114    void onConnect();
115    void onDisconnect(Jreen::Client::DisconnectReason reason);
116
117    void onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence );
118    void onSubscriptionReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence );
119    void onSubscriptionRequestConfirmed( int result );
120
121    void onNewMessage( const Jreen::Message& message );
122    void onError( const Jreen::Connection::SocketError& e );
123    void onNewIq( const Jreen::IQ &iq );
124    void onNewAvatar( const QString &jid );
125    void onCheckJidExists( QString jid );
126
127private:
128    bool readXmlConsoleEnabled();
129    QString readPassword();
130    QString readServer();
131    int readPort();
132
133    QString errorMessage( Jreen::Client::DisconnectReason reason );
134    void setupClientHelper();
135    void addMenuHelper();
136    void removeMenuHelper();
137
138    bool presenceMeansOnline( Jreen::Presence::Type p );
139    void handlePeerStatus( const Jreen::JID &jid, Jreen::Presence::Type presenceType );
140
141    using SipPlugin::errorMessage;
142
143    QString m_currentUsername;
144    QString m_currentPassword;
145    QString m_currentServer;
146    int m_currentPort;
147    ConnectionState m_state;
148
149    QWeakPointer< QWidget > m_configWidget;
150
151    QString m_currentResource;
152
153    // sort out
154    Jreen::Client *m_client;
155
156    Jreen::MUCRoom *m_room;
157    Jreen::SimpleRoster *m_roster;
158    QHash<Jreen::JID, Jreen::Presence::Type> m_peers;
159#ifndef ENABLE_HEADLESS
160    QHash<Jreen::JID, QMessageBox*> m_subscriptionConfirmBoxes;
161    QMenu* m_menu;
162    XmlConsole* m_xmlConsole;
163#endif
164    enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
165    AvatarManager *m_avatarManager;
166};
167
168#endif