1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
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>
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.
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.
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/>.
25
#include "sip/SipPlugin.h"
27
#include "AvatarManager.h"
29
#ifndef ENABLE_HEADLESS
30
#include "XmlConsole.h"
33
#include "accounts/AccountDllMacro.h"
35
#include "../XmppInfoPlugin.h"
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>
51
#ifndef ENABLE_HEADLESS
52
#include <QMessageBox>
56
class ACCOUNTDLLEXPORT XmppSipPlugin : public SipPlugin
60
friend class Tomahawk::InfoSystem::XmppInfoPlugin;
63
XmppSipPlugin( Tomahawk::Accounts::Account* account );
64
virtual ~XmppSipPlugin();
66
//FIXME: Make this more correct
67
virtual bool isValid() const { return true; }
68
virtual QString inviteString() const;
70
Tomahawk::InfoSystem::InfoPluginPtr infoPlugin();
72
#ifndef ENABLE_HEADLESS
73
virtual QMenu* menu();
76
// used by XmppAccount to expose connection state and controls
77
Tomahawk::Accounts::Account::ConnectionState connectionState() const;
80
void jidChanged( const QString& );
82
// Used by XmppAccount
83
void stateChanged( Tomahawk::Accounts::Account::ConnectionState state );
84
void error( int errorId, const QString& errorStr );
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() );
94
void showAddFriendDialog();
95
void publishTune( const QUrl& url, const Tomahawk::InfoSystem::InfoStringHash& trackInfo );
98
virtual QString defaultSuffix() const;
101
void showXmlConsole();
103
void onDisconnect( Jreen::Client::DisconnectReason reason );
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 );
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 );
115
bool readXmlConsoleEnabled();
116
QString readUsername();
117
QString readPassword();
118
QString readServer();
121
QString errorMessage( Jreen::Client::DisconnectReason reason );
122
void setupClientHelper();
123
void addMenuHelper();
124
void removeMenuHelper();
126
bool presenceMeansOnline( Jreen::Presence::Type p );
127
void handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type presenceType );
129
QString m_currentUsername;
130
QString m_currentPassword;
131
QString m_currentServer;
133
QString m_currentResource;
135
QWeakPointer< Tomahawk::InfoSystem::XmppInfoPlugin > m_infoPlugin;
136
Tomahawk::Accounts::Account::ConnectionState m_state;
139
Jreen::Client* m_client;
141
Jreen::MUCRoom* m_room;
142
Jreen::SimpleRoster* m_roster;
143
QHash< Jreen::JID, Jreen::Presence::Type > m_peers;
145
#ifndef ENABLE_HEADLESS
146
QHash< Jreen::JID, QMessageBox* > m_subscriptionConfirmBoxes;
148
XmlConsole* m_xmlConsole;
151
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
152
AvatarManager* m_avatarManager;
153
Jreen::PubSub::Manager* m_pubSubManager;