~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/accounts/xmpp/sip/XmppSip.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *   Copyright 2011, Leo Franchi <lfranchi@kde.org>
 
6
 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
 
7
 *
 
8
 *   Tomahawk is free software: you can redistribute it and/or modify
 
9
 *   it under the terms of the GNU General Public License as published by
 
10
 *   the Free Software Foundation, either version 3 of the License, or
 
11
 *   (at your option) any later version.
 
12
 *
 
13
 *   Tomahawk is distributed in the hope that it will be useful,
 
14
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
 *   GNU General Public License for more details.
 
17
 *
 
18
 *   You should have received a copy of the GNU General Public License
 
19
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef XMPPSIP_H
 
23
#define XMPPSIP_H
 
24
 
 
25
#include "sip/SipPlugin.h"
 
26
 
 
27
#include "AvatarManager.h"
 
28
 
 
29
#ifndef ENABLE_HEADLESS
 
30
    #include "XmlConsole.h"
 
31
#endif
 
32
 
 
33
#include "accounts/AccountDllMacro.h"
 
34
 
 
35
#include "../XmppInfoPlugin.h"
 
36
 
 
37
#include <jreen/client.h>
 
38
#include <jreen/disco.h>
 
39
#include <jreen/message.h>
 
40
#include <jreen/messagesession.h>
 
41
#include <jreen/stanza.h>
 
42
#include <jreen/jreen.h>
 
43
#include <jreen/error.h>
 
44
#include <jreen/presence.h>
 
45
#include <jreen/vcard.h>
 
46
#include <jreen/abstractroster.h>
 
47
#include <jreen/connection.h>
 
48
#include <jreen/mucroom.h>
 
49
#include <jreen/pubsubmanager.h>
 
50
 
 
51
#ifndef ENABLE_HEADLESS
 
52
    #include <QMessageBox>
 
53
#endif
 
54
 
 
55
 
 
56
class ACCOUNTDLLEXPORT XmppSipPlugin : public SipPlugin
 
57
{
 
58
    Q_OBJECT
 
59
 
 
60
friend class Tomahawk::InfoSystem::XmppInfoPlugin;
 
61
 
 
62
public:
 
63
    XmppSipPlugin( Tomahawk::Accounts::Account* account );
 
64
    virtual ~XmppSipPlugin();
 
65
 
 
66
    //FIXME: Make this more correct
 
67
    virtual bool isValid() const { return true; }
 
68
    virtual QString inviteString() const;
 
69
 
 
70
    Tomahawk::InfoSystem::InfoPluginPtr infoPlugin();
 
71
 
 
72
#ifndef ENABLE_HEADLESS
 
73
    virtual QMenu* menu();
 
74
#endif
 
75
 
 
76
    // used by XmppAccount to expose connection state and controls
 
77
    Tomahawk::Accounts::Account::ConnectionState connectionState() const;
 
78
 
 
79
signals:
 
80
    void jidChanged( const QString& );
 
81
 
 
82
    // Used by XmppAccount
 
83
    void stateChanged( Tomahawk::Accounts::Account::ConnectionState state );
 
84
    void error( int errorId, const QString& errorStr );
 
85
 
 
86
public slots:
 
87
    virtual void connectPlugin();
 
88
    virtual void disconnectPlugin();
 
89
    virtual void checkSettings();
 
90
    virtual void configurationChanged();
 
91
    virtual void sendMsg( const QString& peerId, const SipInfo& info );
 
92
    virtual void addContact( const QString& peerId, const QString& msg = QString() );
 
93
 
 
94
    void showAddFriendDialog();
 
95
    void publishTune( const QUrl& url, const Tomahawk::InfoSystem::InfoStringHash& trackInfo );
 
96
 
 
97
protected:
 
98
    virtual QString defaultSuffix() const;
 
99
 
 
100
private slots:
 
101
    void showXmlConsole();
 
102
    void onConnect();
 
103
    void onDisconnect( Jreen::Client::DisconnectReason reason );
 
104
 
 
105
    void onPresenceReceived( const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence );
 
106
    void onSubscriptionReceived( const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence );
 
107
    void onSubscriptionRequestConfirmed( int result );
 
108
 
 
109
    void onNewMessage( const Jreen::Message& message );
 
110
    void onError( const Jreen::Connection::SocketError& e );
 
111
    void onNewIq( const Jreen::IQ& iq );
 
112
    void onNewAvatar( const QString& jid );
 
113
 
 
114
private:
 
115
    bool readXmlConsoleEnabled();
 
116
    QString readUsername();
 
117
    QString readPassword();
 
118
    QString readServer();
 
119
    int readPort();
 
120
 
 
121
    QString errorMessage( Jreen::Client::DisconnectReason reason );
 
122
    void setupClientHelper();
 
123
    void addMenuHelper();
 
124
    void removeMenuHelper();
 
125
 
 
126
    bool presenceMeansOnline( Jreen::Presence::Type p );
 
127
    void handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type presenceType );
 
128
 
 
129
    QString m_currentUsername;
 
130
    QString m_currentPassword;
 
131
    QString m_currentServer;
 
132
    int m_currentPort;
 
133
    QString m_currentResource;
 
134
 
 
135
    QWeakPointer< Tomahawk::InfoSystem::XmppInfoPlugin > m_infoPlugin;
 
136
    Tomahawk::Accounts::Account::ConnectionState m_state;
 
137
 
 
138
    // sort out
 
139
    Jreen::Client* m_client;
 
140
 
 
141
    Jreen::MUCRoom* m_room;
 
142
    Jreen::SimpleRoster* m_roster;
 
143
    QHash< Jreen::JID, Jreen::Presence::Type > m_peers;
 
144
 
 
145
#ifndef ENABLE_HEADLESS
 
146
    QHash< Jreen::JID, QMessageBox* > m_subscriptionConfirmBoxes;
 
147
    QMenu* m_menu;
 
148
    XmlConsole* m_xmlConsole;
 
149
#endif
 
150
 
 
151
    enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
 
152
    AvatarManager* m_avatarManager;
 
153
    Jreen::PubSub::Manager* m_pubSubManager;
 
154
};
 
155
 
 
156
#endif