mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
separate more stuff into siphandler/accountmanager
This commit is contained in:
parent
328d055ee1
commit
b6911525a4
@ -20,6 +20,7 @@
|
||||
#define ACCOUNTDELEGATE_H
|
||||
|
||||
#include "configdelegatebase.h"
|
||||
#include "accounts/AccountModel.h"
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include "sip/twittersip.h"
|
||||
#include "accounts/accountdllmacro.h"
|
||||
#include "accounts/account.h"
|
||||
#include "accounts/Account.h"
|
||||
|
||||
#define MYNAME "ACCOUNTTWITTER"
|
||||
|
||||
@ -77,7 +77,7 @@ public:
|
||||
signals:
|
||||
void nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter >&, const QTweetUser &user );
|
||||
void nowDeauthenticated();
|
||||
|
||||
|
||||
private slots:
|
||||
void configDialogAuthedSignalSlot( bool authed );
|
||||
void connectAuthVerifyReply( const QTweetUser &user );
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sip/xmppsip.h"
|
||||
#include "accounts/accountdllmacro.h"
|
||||
#include "accounts/account.h"
|
||||
#include "accounts/Account.h"
|
||||
|
||||
#define MYNAME "ACCOUNTJABBER"
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Tomahawk
|
||||
|
||||
namespace Accounts
|
||||
{
|
||||
|
||||
|
||||
class ACCOUNTDLLEXPORT XmppAccountFactory : public AccountFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -70,7 +70,7 @@ public:
|
||||
QWidget* aclWidget() { return 0; }
|
||||
|
||||
void refreshProxy() {};
|
||||
|
||||
|
||||
private:
|
||||
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
|
||||
bool m_isAuthenticated;
|
||||
|
@ -55,14 +55,6 @@ Account::icon() const
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Account::canSelfAuthenticate() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Account::authenticate()
|
||||
{
|
||||
@ -88,4 +80,23 @@ void
|
||||
Account::refreshProxy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Account::onError(int errorCode, const QString& error )
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
m_cachedError = error;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Account::onConnectionStateChanged( Account::ConnectionState )
|
||||
{
|
||||
m_cachedError.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -79,8 +79,6 @@ public:
|
||||
|
||||
virtual QIcon icon() const = 0;
|
||||
|
||||
virtual void authenticate() = 0;
|
||||
virtual void deauthenticate() = 0;
|
||||
virtual ConnectionState connectionState() = 0;
|
||||
virtual bool isAuthenticated() const = 0;
|
||||
|
||||
@ -134,6 +132,10 @@ public:
|
||||
|
||||
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
||||
|
||||
public slots:
|
||||
virtual void authenticate() = 0;
|
||||
virtual void deauthenticate() = 0;
|
||||
|
||||
signals:
|
||||
void error( int errorId, const QString& errorStr );
|
||||
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
||||
@ -174,7 +176,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState );
|
||||
void onError( int,QString );
|
||||
void onError( int, const QString& );
|
||||
|
||||
private:
|
||||
QString m_accountServiceName;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -18,11 +19,14 @@
|
||||
|
||||
#include "AccountManager.h"
|
||||
#include "config.h"
|
||||
#include "sourcelist.h"
|
||||
|
||||
#include <QtCore/QLibrary>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QPluginLoader>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QTimer>
|
||||
#include <sip/SipHandler.h>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
@ -63,7 +67,7 @@ AccountManager::findPluginFactories()
|
||||
QList< QDir > pluginDirs;
|
||||
|
||||
QDir appDir( qApp->applicationDirPath() );
|
||||
#ifdef Q_WS_MAC
|
||||
#ifdef Q_WS_MAC
|
||||
if ( appDir.dirName() == "MacOS" )
|
||||
{
|
||||
// Development convenience-hack
|
||||
@ -71,7 +75,7 @@ AccountManager::findPluginFactories()
|
||||
appDir.cdUp();
|
||||
appDir.cdUp();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
QDir libDir( CMAKE_INSTALL_PREFIX "/lib" );
|
||||
|
||||
@ -141,19 +145,46 @@ AccountManager::loadPluginFactory( const QString& path )
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
AccountManager::connectAll()
|
||||
{
|
||||
foreach( Account* acc, m_accounts )
|
||||
{
|
||||
if ( acc->types().contains( Accounts::SipType ) && acc->sipPlugin() )
|
||||
acc->sipPlugin()->connectPlugin();
|
||||
|
||||
}
|
||||
m_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::disconnectAll()
|
||||
{
|
||||
foreach( Account* acc, m_connectedAccounts )
|
||||
acc->sipPlugin()->disconnectPlugin();
|
||||
|
||||
SourceList::instance()->removeAllRemote();
|
||||
m_connected = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::toggleAccountsConnected()
|
||||
{
|
||||
if ( m_connected )
|
||||
disconnectAll();
|
||||
else
|
||||
connectAll();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::loadFromConfig()
|
||||
{
|
||||
QStringList accountIds = TomahawkSettings::instance()->accounts();
|
||||
|
||||
//FIXME: this is just for debugging
|
||||
if ( accountIds.isEmpty() )
|
||||
{
|
||||
Account* account = m_accountFactories[ "twitteraccount" ]->createAccount();
|
||||
addAccountPlugin( account );
|
||||
TomahawkSettings::instance()->addAccount( account->accountId() );
|
||||
}
|
||||
|
||||
foreach( const QString& accountId, accountIds )
|
||||
{
|
||||
QString pluginFactory = factoryFromId( accountId );
|
||||
@ -165,6 +196,18 @@ AccountManager::loadFromConfig()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AccountManager::initSIP()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
foreach( Account* account, accounts( Tomahawk::Accounts::SipType ) )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId();
|
||||
SipPlugin* p = account->sipPlugin();
|
||||
SipHandler::instance()->hookUpPlugin( p );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Account*
|
||||
@ -175,8 +218,8 @@ AccountManager::loadPlugin( const QString& accountId )
|
||||
Q_ASSERT( m_accountFactories.contains( factoryName ) );
|
||||
|
||||
Account* account = m_accountFactories[ factoryName ]->createAccount( accountId );
|
||||
hookupAccount( account );
|
||||
|
||||
// caller responsible for calling pluginAdded() and hookupPlugin
|
||||
return account;
|
||||
}
|
||||
|
||||
@ -189,7 +232,66 @@ AccountManager::addAccountPlugin( Account* account )
|
||||
foreach( AccountType type, account->types() )
|
||||
m_accountsByAccountType[ type ].append( account );
|
||||
|
||||
emit accountAdded( account );
|
||||
emit added( account );
|
||||
}
|
||||
|
||||
void
|
||||
AccountManager::hookupAccount( Account* account ) const
|
||||
{
|
||||
connect( account, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
|
||||
connect( account, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( Accounts::Account::ConnectionState ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
AccountManager::onError( int code, const QString& msg )
|
||||
{
|
||||
Account* account = qobject_cast< Account* >( sender() );
|
||||
Q_ASSERT( account );
|
||||
|
||||
|
||||
qWarning() << "Failed to connect to SIP:" << account->accountFriendlyName() << code << msg;
|
||||
|
||||
if ( code == Account::AuthError )
|
||||
{
|
||||
emit authError( account );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTimer::singleShot( 10000, account, SLOT( authenticate() ) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AccountManager::onSettingsChanged()
|
||||
{
|
||||
foreach( Account* account, m_accounts )
|
||||
{
|
||||
if ( account->types().contains( Accounts::SipType ) && account->sipPlugin() )
|
||||
account->sipPlugin()->checkSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::onStateChanged( Account::ConnectionState state )
|
||||
{
|
||||
Account* account = qobject_cast< Account* >( sender() );
|
||||
Q_ASSERT( account );
|
||||
|
||||
if ( account->connectionState() == Account::Disconnected )
|
||||
{
|
||||
m_connectedAccounts.removeAll( account );
|
||||
emit disconnected( account );
|
||||
}
|
||||
else if ( account->connectionState() == Account::Connected )
|
||||
{
|
||||
m_connectedAccounts << account;
|
||||
emit connected( account );
|
||||
}
|
||||
|
||||
emit stateChanged( account, state );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -47,6 +48,8 @@ public:
|
||||
void loadPluginFactories( const QStringList &paths );
|
||||
|
||||
void loadFromConfig();
|
||||
void initSIP();
|
||||
|
||||
void loadPluginFactory( const QString &path );
|
||||
void addAccountPlugin( Account* account );
|
||||
Account* loadPlugin( const QString &accountId );
|
||||
@ -58,12 +61,26 @@ public:
|
||||
public slots:
|
||||
void connectAll();
|
||||
void disconnectAll();
|
||||
void toggleAccountsConnected();
|
||||
|
||||
signals:
|
||||
void accountAdded( Tomahawk::Accounts::Account* );
|
||||
void accountRemoved( Tomahawk::Accounts::Account* );
|
||||
void added( Tomahawk::Accounts::Account* );
|
||||
void removed( Tomahawk::Accounts::Account* );
|
||||
|
||||
void connected( Tomahawk::Accounts::Account* );
|
||||
void disconnected( Tomahawk::Accounts::Account* );
|
||||
void authError( Tomahawk::Accounts::Account* );
|
||||
|
||||
void stateChanged( Account* p, Accounts::Account::ConnectionState state );
|
||||
|
||||
private slots:
|
||||
void onStateChanged( Accounts::Account::ConnectionState state );
|
||||
void onError( int code, const QString& msg );
|
||||
|
||||
void onSettingsChanged();
|
||||
private:
|
||||
void hookupAccount( Account* ) const;
|
||||
|
||||
QList< Account* > m_accounts;
|
||||
QList< Account* > m_enabledAccounts;
|
||||
QList< Account* > m_connectedAccounts;
|
||||
|
@ -30,8 +30,8 @@ using namespace Accounts;
|
||||
AccountModel::AccountModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
{
|
||||
connect( AccountManager::instance(), SIGNAL( accountAdded( Tomahawk::Accounts::Account* ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) );
|
||||
connect( AccountManager::instance(), SIGNAL( accountRemoved( Tomahawk::Accounts::Account* ) ), this, SLOT( accountRemoved( Tomahawk::Accounts::Account* ) ) );
|
||||
connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) );
|
||||
connect( AccountManager::instance(), SIGNAL( removed( Tomahawk::Accounts::Account* ) ), this, SLOT( accountRemoved( Tomahawk::Accounts::Account* ) ) );
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
|
||||
}
|
||||
|
||||
int
|
||||
AccountModel::rowCount( const QModelIndex& parent ) const
|
||||
AccountModel::rowCount( const QModelIndex& ) const
|
||||
{
|
||||
return AccountManager::instance()->accounts().size();
|
||||
}
|
||||
@ -113,8 +113,7 @@ AccountModel::flags( const QModelIndex& index ) const
|
||||
void
|
||||
AccountModel::accountAdded( Account* account )
|
||||
{
|
||||
Q_UNUSED( p );
|
||||
// we assume account plugins are added at the end of the list.
|
||||
// TODO HACK we assume account plugins are added at the end of the list.
|
||||
Q_ASSERT( AccountManager::instance()->accounts().last() == account );
|
||||
if ( account->types().contains( SipType ) )
|
||||
connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), this, SLOT( accountStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
|
||||
@ -128,17 +127,17 @@ AccountModel::accountAdded( Account* account )
|
||||
void
|
||||
AccountModel::accountRemoved( Account* account )
|
||||
{
|
||||
int idx = AccountManager::instance()->allPlugins().indexOf( account );
|
||||
int idx = AccountManager::instance()->accounts().indexOf( account );
|
||||
beginRemoveRows( QModelIndex(), idx, idx );
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountModel::accountStateChanged( Tomahawk::Accounts::Account::ConnectionState state )
|
||||
AccountModel::accountStateChanged( Tomahawk::Accounts::Account::ConnectionState )
|
||||
{
|
||||
Account* account = qobject_cast< Account* >( sender() );
|
||||
Q_ASSERT( a );
|
||||
Q_ASSERT( account );
|
||||
|
||||
for ( int i = 0; i < AccountManager::instance()->accounts().size(); i++ )
|
||||
{
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "dllmacro.h"
|
||||
#include "sip/SipPlugin.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QModelIndex>
|
||||
#include <QStringList>
|
||||
|
||||
|
@ -52,7 +52,6 @@ SipHandler::instance()
|
||||
|
||||
SipHandler::SipHandler( QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_connected( false )
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
@ -97,13 +96,6 @@ SipHandler::versionString( const QString& peerId ) const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::onSettingsChanged()
|
||||
{
|
||||
checkSettings();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::hookUpPlugin( SipPlugin* sip )
|
||||
{
|
||||
@ -113,164 +105,13 @@ SipHandler::hookUpPlugin( SipPlugin* sip )
|
||||
QObject::connect( sip, SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( onSipInfo( QString, SipInfo ) ) );
|
||||
QObject::connect( sip, SIGNAL( softwareVersionReceived( QString, QString ) ), SLOT( onSoftwareVersion( QString, QString ) ) );
|
||||
|
||||
QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
|
||||
QObject::connect( sip, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( SipPlugin::ConnectionState ) ) );
|
||||
|
||||
QObject::connect( sip, SIGNAL( avatarReceived( QString, QPixmap ) ), SLOT( onAvatarReceived( QString, QPixmap ) ) );
|
||||
QObject::connect( sip, SIGNAL( avatarReceived( QPixmap ) ), SLOT( onAvatarReceived( QPixmap ) ) );
|
||||
|
||||
QObject::connect( sip->account(), SIGNAL( configurationChanged() ), sip, SLOT( configurationChanged() ) );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SipHandler::pluginLoaded( const QString& pluginId ) const
|
||||
{
|
||||
foreach( SipPlugin* plugin, m_allPlugins )
|
||||
{
|
||||
if ( plugin->pluginId() == pluginId )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::checkSettings()
|
||||
{
|
||||
foreach( SipPlugin* sip, m_allPlugins )
|
||||
{
|
||||
sip->checkSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::addSipPlugin( SipPlugin* p )
|
||||
{
|
||||
m_allPlugins << p;
|
||||
|
||||
hookUpPlugin( p );
|
||||
p->connectPlugin();
|
||||
|
||||
emit pluginAdded( p );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::removeSipPlugin( SipPlugin* p )
|
||||
{
|
||||
p->disconnectPlugin();
|
||||
|
||||
emit pluginRemoved( p );
|
||||
|
||||
m_allPlugins.removeAll( p );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::loadFromAccountManager()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
QList< Tomahawk::Accounts::Account* > accountList = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
|
||||
foreach( Tomahawk::Accounts::Account* account, accountList )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId();
|
||||
SipPlugin* p = account->sipPlugin();
|
||||
addSipPlugin( p );
|
||||
}
|
||||
m_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::connectAll()
|
||||
{
|
||||
foreach( SipPlugin* sip, m_allPlugins )
|
||||
{
|
||||
sip->connectPlugin();
|
||||
}
|
||||
m_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::disconnectAll()
|
||||
{
|
||||
foreach( SipPlugin* p, m_connectedPlugins )
|
||||
p->disconnectPlugin();
|
||||
|
||||
SourceList::instance()->removeAllRemote();
|
||||
m_connected = false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::connectPlugin( const QString &pluginId )
|
||||
{
|
||||
#ifndef TOMAHAWK_HEADLESS
|
||||
if ( !TomahawkSettings::instance()->acceptedLegalWarning() )
|
||||
{
|
||||
int result = QMessageBox::question(
|
||||
//TomahawkApp::instance()->mainWindow(),
|
||||
0, tr( "Legal Warning" ),
|
||||
tr( "By pressing OK below, you agree that your use of Tomahawk will be in accordance with any applicable laws, including copyright and intellectual property laws, in effect in your country of residence, and indemnify the Tomahawk developers and project from liability should you choose to break those laws.\n\nFor more information, please see http://gettomahawk.com/legal" ),
|
||||
tr( "I Do Not Agree" ), tr( "I Agree" )
|
||||
);
|
||||
if ( result != 1 )
|
||||
return;
|
||||
else
|
||||
TomahawkSettings::instance()->setAcceptedLegalWarning( true );
|
||||
}
|
||||
#endif
|
||||
foreach( SipPlugin* sip, m_allPlugins )
|
||||
{
|
||||
if ( sip->pluginId() == pluginId )
|
||||
{
|
||||
Q_ASSERT( m_allPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
|
||||
//each sip should refreshProxy() or take care of that function in some other way during connection
|
||||
sip->connectPlugin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::disconnectPlugin( const QString &pluginName )
|
||||
{
|
||||
foreach( SipPlugin* sip, m_connectedPlugins )
|
||||
{
|
||||
if ( sip->account()->accountId() == pluginName )
|
||||
sip->disconnectPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QList< SipPlugin* >
|
||||
SipHandler::allPlugins() const
|
||||
{
|
||||
return m_allPlugins;
|
||||
}
|
||||
|
||||
|
||||
QList< SipPlugin* >
|
||||
SipHandler::connectedPlugins() const
|
||||
{
|
||||
return m_connectedPlugins;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::toggleConnect()
|
||||
{
|
||||
if( m_connected )
|
||||
disconnectAll();
|
||||
else
|
||||
connectAll();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void
|
||||
SipHandler::refreshProxy()
|
||||
{
|
||||
@ -278,7 +119,7 @@ SipHandler::refreshProxy()
|
||||
|
||||
foreach( SipPlugin* sip, m_allPlugins )
|
||||
sip->refreshProxy();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
void
|
||||
@ -381,47 +222,6 @@ SipHandler::onMessage( const QString& from, const QString& msg )
|
||||
qDebug() << Q_FUNC_INFO << from << msg;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::onError( int code, const QString& msg )
|
||||
{
|
||||
SipPlugin* sip = qobject_cast< SipPlugin* >( sender() );
|
||||
Q_ASSERT( sip );
|
||||
|
||||
qWarning() << "Failed to connect to SIP:" << sip->account()->accountFriendlyName() << code << msg;
|
||||
|
||||
if ( code == SipPlugin::AuthError )
|
||||
{
|
||||
emit authError( sip );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTimer::singleShot( 10000, sip, SLOT( connectPlugin() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::onStateChanged( SipPlugin::ConnectionState state )
|
||||
{
|
||||
SipPlugin* sip = qobject_cast< SipPlugin* >( sender() );
|
||||
Q_ASSERT( sip );
|
||||
|
||||
if ( sip->connectionState() == SipPlugin::Disconnected )
|
||||
{
|
||||
m_connectedPlugins.removeAll( sip );
|
||||
emit disconnected( sip );
|
||||
}
|
||||
else if ( sip->connectionState() == SipPlugin::Connected )
|
||||
{
|
||||
m_connectedPlugins << sip;
|
||||
emit connected( sip );
|
||||
}
|
||||
|
||||
emit stateChanged( sip, state );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipHandler::onAvatarReceived( const QString& from, const QPixmap& avatar )
|
||||
{
|
||||
|
@ -31,8 +31,12 @@
|
||||
#include <QPixmap>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Manages SIP plugins for connecting to friends. External interface to SIP plugins is
|
||||
* through AccountManager, this is an internal class.
|
||||
*/
|
||||
|
||||
class DLLEXPORT SipHandler : public QObject
|
||||
class SipHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -42,13 +46,8 @@ public:
|
||||
SipHandler( QObject* parent );
|
||||
~SipHandler();
|
||||
|
||||
QList< SipPlugin* > allPlugins() const;
|
||||
QList< SipPlugin* > connectedPlugins() const;
|
||||
void loadFromAccountManager();
|
||||
|
||||
void addSipPlugin( SipPlugin* p );
|
||||
void removeSipPlugin( SipPlugin* p );
|
||||
|
||||
bool hasPluginType( const QString& factoryId ) const;
|
||||
|
||||
const QPixmap avatar( const QString& name ) const;
|
||||
@ -56,25 +55,11 @@ public:
|
||||
const SipInfo sipInfo( const QString& peerId ) const;
|
||||
const QString versionString( const QString& peerId ) const;
|
||||
|
||||
void hookUpPlugin( SipPlugin* p );
|
||||
|
||||
public slots:
|
||||
void checkSettings();
|
||||
|
||||
void connectPlugin( const QString &pluginId = QString() );
|
||||
void disconnectPlugin( const QString &pluginId = QString() );
|
||||
|
||||
void toggleConnect();
|
||||
|
||||
void refreshProxy();
|
||||
|
||||
signals:
|
||||
void connected( SipPlugin* );
|
||||
void disconnected( SipPlugin* );
|
||||
void authError( SipPlugin* );
|
||||
|
||||
void stateChanged( SipPlugin* p, SipPlugin::ConnectionState state );
|
||||
|
||||
void pluginAdded( SipPlugin* p );
|
||||
void pluginRemoved( SipPlugin* p );
|
||||
// TODO no longer called from anywhere... can we remove it?
|
||||
// void refreshProxy();
|
||||
|
||||
private slots:
|
||||
void onSipInfo( const QString& peerId, const SipInfo& info );
|
||||
@ -82,10 +67,6 @@ private slots:
|
||||
void onMessage( const QString&, const QString& );
|
||||
void onPeerOffline( const QString& );
|
||||
void onPeerOnline( const QString& );
|
||||
void onError( int code, const QString& msg );
|
||||
void onStateChanged( SipPlugin::ConnectionState );
|
||||
|
||||
void onSettingsChanged();
|
||||
|
||||
// set data for local source
|
||||
void onAvatarReceived( const QPixmap& avatar );
|
||||
@ -96,14 +77,6 @@ private slots:
|
||||
private:
|
||||
static SipHandler *s_instance;
|
||||
|
||||
QStringList findPluginFactories();
|
||||
bool pluginLoaded( const QString& pluginId ) const;
|
||||
void hookUpPlugin( SipPlugin* p );
|
||||
|
||||
void loadPluginFactories( const QStringList& paths );
|
||||
void loadPluginFactory( const QString& path );
|
||||
QString factoryFromId( const QString& pluginId ) const;
|
||||
|
||||
//TODO: move this to source
|
||||
QHash<QString, SipInfo> m_peersSipInfos;
|
||||
QHash<QString, QPixmap> m_usernameAvatars;
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* 2011, Dominik Schmidt <dev@dominik-schmidt.de>
|
||||
* 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -67,13 +68,6 @@ SipPlugin::account() const
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
SipPlugin::errorMessage() const
|
||||
{
|
||||
return m_cachedError;
|
||||
}
|
||||
|
||||
|
||||
QIcon
|
||||
SipPlugin::icon() const
|
||||
{
|
||||
@ -95,22 +89,6 @@ SipPlugin::refreshProxy()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipPlugin::onError( int code, const QString& error )
|
||||
{
|
||||
Q_UNUSED( code );
|
||||
m_cachedError = error;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipPlugin::onStateChange( SipPlugin::ConnectionState state )
|
||||
{
|
||||
Q_UNUSED( state );
|
||||
m_cachedError.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SipPlugin::onPeerOnline( const QString& peerId )
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* 2011, Dominik Schmidt <dev@dominik-schmidt.de>
|
||||
* 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "album.h"
|
||||
#include "collection.h"
|
||||
#include "infosystem/infosystem.h"
|
||||
#include "accounts/accountmanager.h"
|
||||
#include "accounts/AccountManager.h"
|
||||
#include "database/database.h"
|
||||
#include "database/databasecollection.h"
|
||||
#include "database/databasecommand_collectionstats.h"
|
||||
@ -505,16 +505,6 @@ void
|
||||
TomahawkApp::initSIP()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
// TODO debugging hack only
|
||||
foreach ( Tomahawk::Accounts::Account* account, Tomahawk::Accounts::AccountManager::instance()->accounts() )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "testing account with name " << account->accountServiceName();
|
||||
if ( account->configurationWidget() && account->configuration().isEmpty() )
|
||||
account->configurationWidget()->show();
|
||||
if ( !account->enabled() )
|
||||
account->setEnabled( true );
|
||||
}
|
||||
|
||||
//FIXME: jabber autoconnect is really more, now that there is sip -- should be renamed and/or split out of jabber-specific settings
|
||||
if ( !arguments().contains( "--nosip" ) )
|
||||
{
|
||||
@ -523,7 +513,7 @@ TomahawkApp::initSIP()
|
||||
#endif
|
||||
|
||||
tDebug( LOGINFO ) << "Connecting SIP classes";
|
||||
SipHandler::instance()->loadFromAccountManager();
|
||||
Accounts::AccountManager::instance()->loadFromConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "artist.h"
|
||||
#include "audio/audioengine.h"
|
||||
#include "viewmanager.h"
|
||||
#include "sip/SipHandler.h"
|
||||
#include "accounts/AccountManager.h"
|
||||
#include "sourcetree/sourcetreeview.h"
|
||||
#include "network/servent.h"
|
||||
#include "utils/proxystyle.h"
|
||||
@ -73,7 +73,7 @@
|
||||
#include <actioncollection.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
using namespace Accounts;
|
||||
|
||||
TomahawkWindow::TomahawkWindow( QWidget* parent )
|
||||
: QMainWindow( parent )
|
||||
@ -106,12 +106,12 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
|
||||
ui->menu_Help->addSeparator();
|
||||
ui->menu_Help->addAction( "Crash now...", this, SLOT( crashNow() ) );
|
||||
}
|
||||
|
||||
|
||||
ui->menuApp->insertAction( ui->actionCreatePlaylist, ActionCollection::instance()->getAction( "togglePrivacy" ) );
|
||||
ui->menuApp->insertSeparator( ui->actionCreatePlaylist );
|
||||
|
||||
// set initial state
|
||||
onSipDisconnected();
|
||||
onAccountDisconnected();
|
||||
vm->setQueue( m_queueView );
|
||||
vm->showWelcomePage();
|
||||
}
|
||||
@ -306,7 +306,7 @@ TomahawkWindow::setupSignals()
|
||||
// connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) );
|
||||
connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) );
|
||||
connect( ui->actionDiagnostics, SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) );
|
||||
connect( ui->actionToggleConnect, SIGNAL( triggered() ), SipHandler::instance(), SLOT( toggleConnect() ) );
|
||||
connect( ui->actionToggleConnect, SIGNAL( triggered() ), AccountManager::instance(), SLOT( toggleAccountsConnected() ) );
|
||||
connect( ui->actionUpdateCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) );
|
||||
connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) );
|
||||
connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
|
||||
@ -328,18 +328,20 @@ TomahawkWindow::setupSignals()
|
||||
ui->menuWindow->menuAction()->setVisible( false );
|
||||
#endif
|
||||
|
||||
// <SipHandler>
|
||||
connect( SipHandler::instance(), SIGNAL( connected( SipPlugin* ) ), SLOT( onSipConnected() ) );
|
||||
connect( SipHandler::instance(), SIGNAL( disconnected( SipPlugin* ) ), SLOT( onSipDisconnected() ) );
|
||||
connect( SipHandler::instance(), SIGNAL( authError( SipPlugin* ) ), SLOT( onSipError() ) );
|
||||
// <AccountHandler>
|
||||
connect( AccountManager::instance(), SIGNAL( connected( Tomahawk::Accounts::Account* ) ), SLOT( onAccountConnected() ) );
|
||||
connect( AccountManager::instance(), SIGNAL( disconnected( Tomahawk::Accounts::Account* ) ), SLOT( onAccountDisconnected() ) );
|
||||
connect( AccountManager::instance(), SIGNAL( authError( Tomahawk::Accounts::Account* ) ), SLOT( onAccountError() ) );
|
||||
|
||||
// <SipMenu>
|
||||
connect( SipHandler::instance(), SIGNAL( pluginAdded( SipPlugin* ) ), this, SLOT( onSipPluginAdded( SipPlugin* ) ) );
|
||||
connect( SipHandler::instance(), SIGNAL( pluginRemoved( SipPlugin* ) ), this, SLOT( onSipPluginRemoved( SipPlugin* ) ) );
|
||||
foreach( SipPlugin *plugin, SipHandler::instance()->allPlugins() )
|
||||
// Menus for accounts that support them
|
||||
connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), this, SLOT( onAccountAdded( Tomahawk::Accounts::Account* ) ) );
|
||||
foreach( Account* account, AccountManager::instance()->accounts( Tomahawk::Accounts::SipType ) )
|
||||
{
|
||||
connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
|
||||
connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
|
||||
if ( !account || !account->sipPlugin() )
|
||||
continue;
|
||||
|
||||
connect( account->sipPlugin(), SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
|
||||
connect( account->sipPlugin(), SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -654,39 +656,37 @@ TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipConnected()
|
||||
TomahawkWindow::onAccountConnected()
|
||||
{
|
||||
ui->actionToggleConnect->setText( tr( "Go &offline" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipDisconnected()
|
||||
TomahawkWindow::onAccountDisconnected()
|
||||
{
|
||||
ui->actionToggleConnect->setText( tr( "Go &online" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipPluginAdded( SipPlugin* p )
|
||||
TomahawkWindow::onAccountAdded( Account* acc )
|
||||
{
|
||||
connect( p, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
|
||||
connect( p, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
|
||||
if ( !acc->types().contains( SipType ) ||
|
||||
!acc->sipPlugin() )
|
||||
return;
|
||||
|
||||
connect( acc->sipPlugin(), SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
|
||||
connect( acc->sipPlugin(), SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipPluginRemoved( SipPlugin* p )
|
||||
TomahawkWindow::onAccountError()
|
||||
{
|
||||
Q_UNUSED( p );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onSipError()
|
||||
{
|
||||
onSipDisconnected();
|
||||
// TODO fix.
|
||||
// onAccountDisconnected();
|
||||
|
||||
// TODO real error message from plugin kthxbbq
|
||||
QMessageBox::warning( this,
|
||||
tr( "Authentication Error" ),
|
||||
QString( "Error connecting to SIP: Authentication failed!" ),
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -28,9 +29,14 @@
|
||||
#include "result.h"
|
||||
#include "utils/xspfloader.h"
|
||||
|
||||
namespace Tomahawk {
|
||||
namespace Accounts {
|
||||
class Account;
|
||||
}
|
||||
}
|
||||
|
||||
class JobStatusModel;
|
||||
class QSearchField;
|
||||
class SipPlugin;
|
||||
class SourceTreeView;
|
||||
class QAction;
|
||||
|
||||
@ -80,9 +86,10 @@ public slots:
|
||||
void showOfflineSources();
|
||||
|
||||
private slots:
|
||||
void onSipConnected();
|
||||
void onSipDisconnected();
|
||||
void onSipError();
|
||||
void onAccountAdded( Tomahawk::Accounts::Account* account );
|
||||
void onAccountConnected();
|
||||
void onAccountDisconnected();
|
||||
void onAccountError();
|
||||
|
||||
void onXSPFError( XSPFLoader::XSPFErrorCode error );
|
||||
void onXSPFOk( const Tomahawk::playlist_ptr& );
|
||||
@ -97,9 +104,6 @@ private slots:
|
||||
void showAboutTomahawk();
|
||||
void checkForUpdates();
|
||||
|
||||
void onSipPluginAdded( SipPlugin* p );
|
||||
void onSipPluginRemoved( SipPlugin* p );
|
||||
|
||||
void onSearch( const QString& search );
|
||||
void onFilterEdited();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user