1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

missing bits and pieces of accounts and auto-connect

port settings dialog to new accounts
fix adding and removing of accounts
This commit is contained in:
Leo Franchi
2011-12-12 22:37:23 -05:00
parent 00adb66cf0
commit aefec1eaac
26 changed files with 456 additions and 347 deletions

View File

@@ -65,7 +65,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
QFont desc = opt.font; QFont desc = opt.font;
desc.setItalic( true ); desc.setItalic( true );
desc.setPointSize( error.pointSize() - 2 ); desc.setPointSize( desc.pointSize() - 2 );
// draw the background // draw the background
const QWidget* w = opt.widget; const QWidget* w = opt.widget;
@@ -93,7 +93,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
// from the right edge--config status and online/offline // from the right edge--config status and online/offline
QRect confRect = QRect( itemRect.width() - WRENCH_SIZE - 2 * PADDING, mid - WRENCH_SIZE / 2 + top, WRENCH_SIZE, WRENCH_SIZE ); QRect confRect = QRect( itemRect.width() - WRENCH_SIZE - 2 * PADDING, mid - WRENCH_SIZE / 2 + top, WRENCH_SIZE, WRENCH_SIZE );
if( index.data( SipModel::HasConfig ).toBool() ) { if( index.data( AccountModel::HasConfig ).toBool() ) {
QStyleOptionToolButton topt; QStyleOptionToolButton topt;
topt.rect = confRect; topt.rect = confRect;
@@ -116,10 +116,10 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
QPixmap p; QPixmap p;
QString statusText; QString statusText;
Account::ConnectionState state = static_cast< Account::ConnectionState >( index.data( AccountModel::ConnectionStateRole ).toInt() ); Account::ConnectionState state = static_cast< Account::ConnectionState >( index.data( AccountModel::ConnectionStateRole ).toInt() );
if( state == SipPlugin::Connected ) { if( state == Account::Connected ) {
p = QPixmap( RESPATH "images/sipplugin-online.png" ); p = QPixmap( RESPATH "images/sipplugin-online.png" );
statusText = tr( "Online" ); statusText = tr( "Online" );
} else if( state == SipPlugin::Connecting ) { } else if( state == Account::Connecting ) {
p = QPixmap( RESPATH "images/sipplugin-offline.png" ); p = QPixmap( RESPATH "images/sipplugin-offline.png" );
statusText = tr( "Connecting..." ); statusText = tr( "Connecting..." );
} else { } else {
@@ -128,7 +128,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
} }
p = p.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation ); p = p.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter->drawPixmap( statusX, statusY - STATUS_ICON_SIZE / 2 + top, STATUS_ICON_SIZE, STATUS_ICON_SIZE, p ); painter->drawPixmap( statusX, statusY - STATUS_ICON_SIZE / 2 + top, STATUS_ICON_SIZE, STATUS_ICON_SIZE, p );
const int width = statusFM.width( statusText ); int width = statusFM.width( statusText );
int statusTextX = statusX - PADDING - width; int statusTextX = statusX - PADDING - width;
painter->save(); painter->save();
painter->setFont( statusF ); painter->setFont( statusF );
@@ -155,7 +155,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
// text to accompany checkbox // text to accompany checkbox
const int capW = statusFM.width( capString ); const int capW = statusFM.width( capString );
const int capTextX = statusX - PADDING - capW; const int capTextX = statusX - PADDING - capW;
painter->drawText( QRect( capTextX, capY - statusFM.height() / 2 + top, capW, statusFM.height() ) ); painter->drawText( QRect( capTextX, capY - statusFM.height() / 2 + top, capW, statusFM.height() ), capString );
if ( capTextX < statusTextX ) if ( capTextX < statusTextX )
statusTextX = capTextX; statusTextX = capTextX;
@@ -167,7 +167,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
painter->setFont( name ); painter->setFont( name );
QFontMetrics namefm( name ); QFontMetrics namefm( name );
// pos will the top-left point of the text rect // pos will the top-left point of the text rect
pos = mid - ( nameHeight / 2 ) + top; pos = mid - ( namefm.height() / 2 ) + top;
// TODO bound with config icon and offline/online status // TODO bound with config icon and offline/online status
width = itemRect.width() - statusTextX; width = itemRect.width() - statusTextX;
QRect nameRect( textLeftEdge, pos, width, namefm.height() ); QRect nameRect( textLeftEdge, pos, width, namefm.height() );
@@ -208,15 +208,11 @@ AccountDelegate::checkRectForIndex( const QStyleOptionViewItem &option, const QM
QRect QRect
AccountDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const AccountDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const
{ {
if( !idx.data( SipModel::FactoryItemRole ).toBool() && !idx.data( SipModel::FactoryRole ).toBool() ) QStyleOptionViewItemV4 opt = option;
{ initStyleOption( &opt, idx );
QStyleOptionViewItemV4 opt = option; QRect itemRect = opt.rect;
initStyleOption( &opt, idx ); QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
QRect itemRect = opt.rect; return confRect;
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
return confRect;
}
return QRect();
} }
@@ -229,7 +225,7 @@ AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex
void void
AccountDelegate::askedForEdit( const QModelIndex& idx ) AccountDelegate::askedForEdit( const QModelIndex& idx )
{ {
emit openConfig( qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() ) ); emit openConfig( qobject_cast< Account* >( idx.data( AccountModel::AccountData ).value< QObject* >() ) );
} }

View File

@@ -47,7 +47,7 @@ private slots:
void askedForEdit( const QModelIndex& idx ); void askedForEdit( const QModelIndex& idx );
signals: signals:
void openConfig( Account* ); void openConfig( Tomahawk::Accounts::Account* );
}; };
} }

View File

@@ -1,2 +1,2 @@
add_subdirectory( xmpp ) add_subdirectory( xmpp )
add_subdirectory( twitter ) #add_subdirectory( twitter )

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -57,7 +58,7 @@ TwitterSipPlugin::TwitterSipPlugin( Tomahawk::Accounts::Account* account )
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
connect( account, SIGNAL( nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ), SLOT( accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ) ); connect( account, SIGNAL( nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ), SLOT( accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ) );
if ( Database::instance()->dbid() != m_configuration[ "saveddbid" ].toString() ) if ( Database::instance()->dbid() != m_configuration[ "saveddbid" ].toString() )
{ {
m_configuration[ "cachedpeers" ] = QVariantHash(); m_configuration[ "cachedpeers" ] = QVariantHash();
@@ -113,7 +114,7 @@ TwitterSipPlugin::connectPlugin()
m_cachedPeers = m_configuration[ "cachedpeers" ].toHash(); m_cachedPeers = m_configuration[ "cachedpeers" ].toHash();
QStringList peerList = m_cachedPeers.keys(); QStringList peerList = m_cachedPeers.keys();
qStableSort( peerList.begin(), peerList.end() ); qStableSort( peerList.begin(), peerList.end() );
if ( !m_account->isAuthenticated() ) if ( !m_account->isAuthenticated() )
{ {
tDebug() << Q_FUNC_INFO << "account isn't authenticated, attempting"; tDebug() << Q_FUNC_INFO << "account isn't authenticated, attempting";
@@ -144,7 +145,7 @@ TwitterSipPlugin::disconnectPlugin()
delete m_directMessageDestroy.data(); delete m_directMessageDestroy.data();
m_cachedTwitterAuth.clear(); m_cachedTwitterAuth.clear();
m_configuration[ "cachedpeers" ] = m_cachedPeers; m_configuration[ "cachedpeers" ] = m_cachedPeers;
syncConfig(); syncConfig();
m_cachedPeers.empty(); m_cachedPeers.empty();
@@ -156,12 +157,12 @@ void
TwitterSipPlugin::accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user ) TwitterSipPlugin::accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user )
{ {
Q_UNUSED( user ); Q_UNUSED( user );
if ( !isValid() ) if ( !isValid() )
return; return;
m_cachedTwitterAuth = twitterAuth; m_cachedTwitterAuth = twitterAuth;
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_cachedTwitterAuth.data(), this ) ); m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_cachedTwitterAuth.data(), this ) );
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_cachedTwitterAuth.data(), this ) ); m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( m_cachedTwitterAuth.data(), this ) );
m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_cachedTwitterAuth.data(), this ) ); m_directMessages = QWeakPointer<QTweetDirectMessages>( new QTweetDirectMessages( m_cachedTwitterAuth.data(), this ) );
@@ -216,7 +217,7 @@ TwitterSipPlugin::registerOffers( const QStringList &peerList )
{ {
if ( !isValid() ) if ( !isValid() )
return; return;
foreach( QString screenName, peerList ) foreach( QString screenName, peerList )
{ {
QVariantHash peerData = m_cachedPeers[screenName].toHash(); QVariantHash peerData = m_cachedPeers[screenName].toHash();
@@ -227,7 +228,7 @@ TwitterSipPlugin::registerOffers( const QStringList &peerList )
m_configuration[ "cachedpeers" ] = m_cachedPeers; m_configuration[ "cachedpeers" ] = m_cachedPeers;
syncConfig(); syncConfig();
} }
if ( Servent::instance()->connectedToSession( peerData["node"].toString() ) ) if ( Servent::instance()->connectedToSession( peerData["node"].toString() ) )
{ {
peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch(); peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch();
@@ -246,13 +247,13 @@ TwitterSipPlugin::registerOffers( const QStringList &peerList )
m_cachedAvatars.remove( screenName ); m_cachedAvatars.remove( screenName );
continue; continue;
} }
if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) ) if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) )
{ {
qDebug() << "TwitterSipPlugin does not have host, port and/or pkey values for " << screenName << " (this is usually *not* a bug or problem but a normal part of the process)"; qDebug() << "TwitterSipPlugin does not have host, port and/or pkey values for " << screenName << " (this is usually *not* a bug or problem but a normal part of the process)";
continue; continue;
} }
QMetaObject::invokeMethod( this, "registerOffer", Q_ARG( QString, screenName ), Q_ARG( QVariantHash, peerData ) ); QMetaObject::invokeMethod( this, "registerOffer", Q_ARG( QString, screenName ), Q_ARG( QVariantHash, peerData ) );
} }
} }
@@ -653,7 +654,7 @@ TwitterSipPlugin::fetchAvatar( const QString& screenName )
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( !isValid() ) if ( !isValid() )
return; return;
QTweetUserShow *userShowFetch = new QTweetUserShow( m_cachedTwitterAuth.data(), this ); QTweetUserShow *userShowFetch = new QTweetUserShow( m_cachedTwitterAuth.data(), this );
connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) ); connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) );
userShowFetch->fetch( screenName ); userShowFetch->fetch( screenName );
@@ -672,11 +673,6 @@ TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
} }
void
TwitterSipPlugin::refreshProxy()
{
//handled by TwitterAccount::refreshProxy()
}
void void
TwitterSipPlugin::profilePicReply() TwitterSipPlugin::profilePicReply()

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -34,7 +35,7 @@
#include "accounts/accountdllmacro.h" #include "accounts/accountdllmacro.h"
#include "sip/SipPlugin.h" #include "sip/SipPlugin.h"
#include "accounts/account.h" #include "accounts/Account.h"
#include "accounts/twitter/tomahawkoauthtwitter.h" #include "accounts/twitter/tomahawkoauthtwitter.h"
class ACCOUNTDLLEXPORT TwitterSipPlugin : public SipPlugin class ACCOUNTDLLEXPORT TwitterSipPlugin : public SipPlugin
@@ -52,7 +53,6 @@ public:
public slots: public slots:
virtual void connectPlugin(); virtual void connectPlugin();
void disconnectPlugin(); void disconnectPlugin();
void refreshProxy();
void configurationChanged(); void configurationChanged();
void sendMsg( const QString& to, const QString& msg ) void sendMsg( const QString& to, const QString& msg )
@@ -73,7 +73,7 @@ public slots:
} }
void checkSettings(); void checkSettings();
private slots: private slots:
void accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user ); void accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user );
void checkTimerFired(); void checkTimerFired();
@@ -92,14 +92,14 @@ private slots:
void fetchAvatar( const QString &screenName ); void fetchAvatar( const QString &screenName );
void avatarUserDataSlot( const QTweetUser &user ); void avatarUserDataSlot( const QTweetUser &user );
void profilePicReply(); void profilePicReply();
private: private:
inline void syncConfig() { m_account->setCredentials( m_credentials ); m_account->setConfiguration( m_configuration ); m_account->sync(); } inline void syncConfig() { m_account->setCredentials( m_credentials ); m_account->setConfiguration( m_configuration ); m_account->sync(); }
bool refreshTwitterAuth(); bool refreshTwitterAuth();
void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text ); void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text );
QWeakPointer< TomahawkOAuthTwitter > m_cachedTwitterAuth; QWeakPointer< TomahawkOAuthTwitter > m_cachedTwitterAuth;
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline; QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
QWeakPointer< QTweetMentions > m_mentions; QWeakPointer< QTweetMentions > m_mentions;
QWeakPointer< QTweetDirectMessages > m_directMessages; QWeakPointer< QTweetDirectMessages > m_directMessages;
@@ -108,7 +108,7 @@ private:
QVariantHash m_configuration; QVariantHash m_configuration;
QVariantHash m_credentials; QVariantHash m_credentials;
QTimer m_checkTimer; QTimer m_checkTimer;
QTimer m_connectTimer; QTimer m_connectTimer;
QTimer m_dmPollTimer; QTimer m_dmPollTimer;

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -163,15 +164,6 @@ TwitterAccount::connectAuthVerifyReply( const QTweetUser &user )
} }
void
TwitterAccount::refreshProxy()
{
//FIXME: Could this cause a race condition if a client is threaded?
if ( !m_twitterAuth.isNull() )
m_twitterAuth.data()->setNetworkAccessManager( TomahawkUtils::nam() );
}
} }
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -72,8 +73,6 @@ public:
bool refreshTwitterAuth(); bool refreshTwitterAuth();
TomahawkOAuthTwitter* twitterAuth() const { return m_twitterAuth.data(); } TomahawkOAuthTwitter* twitterAuth() const { return m_twitterAuth.data(); }
void refreshProxy();
signals: signals:
void nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter >&, const QTweetUser &user ); void nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter >&, const QTweetUser &user );
void nowDeauthenticated(); void nowDeauthenticated();

View File

@@ -2,6 +2,7 @@
* *
* Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de> * Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -48,13 +49,16 @@
#include <utils/tomahawkutils.h> #include <utils/tomahawkutils.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <accounts/accountmanager.h> #include <accounts/AccountManager.h>
XmppSipPlugin::XmppSipPlugin( Tomahawk::Accounts::Account *account ) using namespace Tomahawk;
using namespace Accounts;
XmppSipPlugin::XmppSipPlugin( Account *account )
: SipPlugin( account ) : SipPlugin( account )
, m_menu( 0 ) , m_menu( 0 )
, m_xmlConsole( 0 ) , m_xmlConsole( 0 )
, m_state( Disconnected ) , m_state( Account::Disconnected )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@@ -152,7 +156,7 @@ XmppSipPlugin::connectPlugin()
if ( m_client->connection() ) if ( m_client->connection() )
connect(m_client->connection(), SIGNAL(error(SocketError)), SLOT(onError(SocketError))); connect(m_client->connection(), SIGNAL(error(SocketError)), SLOT(onError(SocketError)));
m_state = Connecting; m_state = Account::Connecting;
emit stateChanged( m_state ); emit stateChanged( m_state );
return; return;
} }
@@ -162,10 +166,10 @@ XmppSipPlugin::disconnectPlugin()
{ {
if (!m_client->isConnected()) if (!m_client->isConnected())
{ {
if ( m_state != Disconnected ) // might be Connecting if ( m_state != Account::Disconnected ) // might be Connecting
{ {
m_state = Disconnected; m_state = Account::Disconnected;
emit stateChanged( m_state ); emit stateChanged( m_state );
} }
return; return;
} }
@@ -178,7 +182,7 @@ XmppSipPlugin::disconnectPlugin()
m_peers.clear(); m_peers.clear();
m_client->disconnectFromServer( true ); m_client->disconnectFromServer( true );
m_state = Disconnecting; m_state = Account::Disconnecting;
emit stateChanged( m_state ); emit stateChanged( m_state );
} }
@@ -218,7 +222,7 @@ XmppSipPlugin::onConnect()
//connect( m_room, SIGNAL( messageReceived( Jreen::Message, bool ) ), this, SLOT( onNewMessage( Jreen::Message ) ) ); //connect( m_room, SIGNAL( messageReceived( Jreen::Message, bool ) ), this, SLOT( onNewMessage( Jreen::Message ) ) );
//connect( m_room, SIGNAL( presenceReceived( Jreen::Presence, const Jreen::MUCRoom::Participant* ) ), this, SLOT( onNewPresence( Jreen::Presence ) ) ); //connect( m_room, SIGNAL( presenceReceived( Jreen::Presence, const Jreen::MUCRoom::Participant* ) ), this, SLOT( onNewPresence( Jreen::Presence ) ) );
m_state = Connected; m_state = Account::Connected;
emit stateChanged( m_state ); emit stateChanged( m_state );
addMenuHelper(); addMenuHelper();
@@ -235,7 +239,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
break; break;
case Jreen::Client::AuthorizationError: case Jreen::Client::AuthorizationError:
emit error( SipPlugin::AuthError, errorMessage( reason ) ); emit error( Account::AuthError, errorMessage( reason ) );
break; break;
case Jreen::Client::HostUnknown: case Jreen::Client::HostUnknown:
@@ -246,7 +250,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
case Jreen::Client::SystemShutdown: case Jreen::Client::SystemShutdown:
case Jreen::Client::Conflict: case Jreen::Client::Conflict:
case Jreen::Client::Unknown: case Jreen::Client::Unknown:
emit error( SipPlugin::ConnectionError, errorMessage( reason ) ); emit error( Account::ConnectionError, errorMessage( reason ) );
break; break;
default: default:
@@ -254,7 +258,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
Q_ASSERT(false); Q_ASSERT(false);
break; break;
} }
m_state = Disconnected; m_state = Account::Disconnected;
emit stateChanged( m_state ); emit stateChanged( m_state );
removeMenuHelper(); removeMenuHelper();
@@ -314,7 +318,7 @@ XmppSipPlugin::errorMessage( Jreen::Client::DisconnectReason reason )
break; break;
} }
m_state = Disconnected; m_state = Account::Disconnected;
emit stateChanged( m_state ); emit stateChanged( m_state );
return QString(); return QString();
@@ -534,7 +538,7 @@ void XmppSipPlugin::removeMenuHelper()
void XmppSipPlugin::onNewMessage(const Jreen::Message& message) void XmppSipPlugin::onNewMessage(const Jreen::Message& message)
{ {
if ( m_state != Connected ) if ( m_state != Account::Connected )
return; return;
// qDebug() << Q_FUNC_INFO << "message type" << message.subtype(); // qDebug() << Q_FUNC_INFO << "message type" << message.subtype();
@@ -576,7 +580,7 @@ void XmppSipPlugin::onNewMessage(const Jreen::Message& message)
void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ) void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence )
{ {
Q_UNUSED(item); Q_UNUSED(item);
if ( m_state != Connected ) if ( m_state != Account::Connected )
return; return;
Jreen::JID jid = presence.from(); Jreen::JID jid = presence.from();
@@ -618,7 +622,7 @@ void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, cons
void XmppSipPlugin::onSubscriptionReceived(const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence) void XmppSipPlugin::onSubscriptionReceived(const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence)
{ {
if ( m_state != Connected ) if ( m_state != Account::Connected )
return; return;
// qDebug() << Q_FUNC_INFO << "presence type:" << presence.subtype(); // qDebug() << Q_FUNC_INFO << "presence type:" << presence.subtype();
@@ -704,7 +708,7 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result )
void XmppSipPlugin::onNewIq(const Jreen::IQ& iq) void XmppSipPlugin::onNewIq(const Jreen::IQ& iq)
{ {
if ( m_state != Connected ) if ( m_state != Account::Connected )
return; return;
Jreen::IQReply *reply = qobject_cast<Jreen::IQReply*>(sender()); Jreen::IQReply *reply = qobject_cast<Jreen::IQReply*>(sender());
@@ -847,7 +851,7 @@ void XmppSipPlugin::handlePeerStatus(const Jreen::JID& jid, Jreen::Presence::Typ
void XmppSipPlugin::onNewAvatar(const QString& jid) void XmppSipPlugin::onNewAvatar(const QString& jid)
{ {
// qDebug() << Q_FUNC_INFO << jid; // qDebug() << Q_FUNC_INFO << jid;
if ( m_state != Connected ) if ( m_state != Account::Connected )
return; return;
Q_ASSERT(!m_avatarManager->avatar( jid ).isNull()); Q_ASSERT(!m_avatarManager->avatar( jid ).isNull());
@@ -911,7 +915,7 @@ XmppSipPlugin::readServer()
} }
SipPlugin::ConnectionState Account::ConnectionState
XmppSipPlugin::connectionState() const XmppSipPlugin::connectionState() const
{ {
return m_state; return m_state;

View File

@@ -2,6 +2,7 @@
* *
* Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de> * Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -55,20 +56,26 @@ public:
//FIXME: Make this more correct //FIXME: Make this more correct
virtual bool isValid() const { return true; } virtual bool isValid() const { return true; }
virtual ConnectionState connectionState() const;
virtual QMenu* menu(); virtual QMenu* menu();
// used by XmppAccount to expose connection state and controls
Tomahawk::Accounts::Account::ConnectionState connectionState() const;
signals: signals:
void jidChanged( const QString& ); void jidChanged( const QString& );
// Used by XmppAccount
void stateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void error( int errorId, const QString& errorStr );
public slots: public slots:
virtual void connectPlugin(); virtual void connectPlugin();
void disconnectPlugin(); virtual void disconnectPlugin();
void checkSettings(); virtual void checkSettings();
void configurationChanged(); virtual void configurationChanged();
void sendMsg( const QString& to, const QString& msg ); virtual void sendMsg( const QString& to, const QString& msg );
void broadcastMsg( const QString &msg ); void broadcastMsg( const QString &msg );
void addContact( const QString &jid, const QString& msg = QString() ); virtual void addContact( const QString &jid, const QString& msg = QString() );
void showAddFriendDialog(); void showAddFriendDialog();
protected: protected:
@@ -103,15 +110,13 @@ private:
bool presenceMeansOnline( Jreen::Presence::Type p ); bool presenceMeansOnline( Jreen::Presence::Type p );
void handlePeerStatus( const Jreen::JID &jid, Jreen::Presence::Type presenceType ); void handlePeerStatus( const Jreen::JID &jid, Jreen::Presence::Type presenceType );
using SipPlugin::errorMessage;
QMenu* m_menu; QMenu* m_menu;
XmlConsole* m_xmlConsole; XmlConsole* m_xmlConsole;
QString m_currentUsername; QString m_currentUsername;
QString m_currentPassword; QString m_currentPassword;
QString m_currentServer; QString m_currentServer;
int m_currentPort; int m_currentPort;
ConnectionState m_state; Tomahawk::Accounts::Account::ConnectionState m_state;
QString m_currentResource; QString m_currentResource;

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -19,6 +20,7 @@
#include "xmppaccount.h" #include "xmppaccount.h"
#include "xmppconfigwidget.h" #include "xmppconfigwidget.h"
#include "sip/SipPlugin.h" #include "sip/SipPlugin.h"
#include "ui_xmppconfigwidget.h"
#include <QtCore/QtPlugin> #include <QtCore/QtPlugin>
@@ -37,7 +39,6 @@ XmppAccountFactory::createAccount( const QString& accountId )
XmppAccount::XmppAccount( const QString &accountId ) XmppAccount::XmppAccount( const QString &accountId )
: Account( accountId ) : Account( accountId )
, m_isAuthenticated( false )
{ {
loadFromConfig( accountId ); loadFromConfig( accountId );
@@ -46,27 +47,52 @@ XmppAccount::XmppAccount( const QString &accountId )
types << SipType; types << SipType;
setTypes( types ); setTypes( types );
m_configWidget = QWeakPointer< XmppConfigWidget >( new XmppConfigWidget( this, 0 ) ); m_configWidget = QWeakPointer< QWidget >( new XmppConfigWidget( this, 0 ) );
} }
XmppAccount::~XmppAccount() XmppAccount::~XmppAccount()
{ {
delete m_configWidget.data();
delete m_xmppSipPlugin.data();
} }
void void
XmppAccount::authenticate() XmppAccount::authenticate()
{ {
return; if ( connectionState() != Account::Connected )
sipPlugin()->connectPlugin();
} }
void void
XmppAccount::deauthenticate() XmppAccount::deauthenticate()
{ {
return; if ( connectionState() != Account::Disconnected )
sipPlugin()->disconnectPlugin();
}
bool
XmppAccount::isAuthenticated() const
{
return m_xmppSipPlugin.data()->connectionState() == Account::Connected;
}
Account::ConnectionState
XmppAccount::connectionState() const
{
// Ensure we exist
const_cast<XmppAccount*>( this )->sipPlugin();
return m_xmppSipPlugin.data()->connectionState();
}
void
XmppAccount::saveConfig()
{
if ( !m_configWidget.isNull() )
static_cast< XmppConfigWidget* >( m_configWidget.data() )->saveConfig();
} }
@@ -76,6 +102,10 @@ XmppAccount::sipPlugin()
if ( m_xmppSipPlugin.isNull() ) if ( m_xmppSipPlugin.isNull() )
{ {
m_xmppSipPlugin = QWeakPointer< XmppSipPlugin >( new XmppSipPlugin( this ) ); m_xmppSipPlugin = QWeakPointer< XmppSipPlugin >( new XmppSipPlugin( this ) );
connect( m_xmppSipPlugin.data(), SIGNAL( stateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
connect( m_xmppSipPlugin.data(), SIGNAL( error( int, QString ) ), this, SIGNAL( error( int, QString ) ) );
return m_xmppSipPlugin.data(); return m_xmppSipPlugin.data();
} }
return m_xmppSipPlugin.data(); return m_xmppSipPlugin.data();

View File

@@ -2,6 +2,7 @@
* *
* Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de> * Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -61,19 +62,19 @@ public:
void authenticate(); void authenticate();
void deauthenticate(); void deauthenticate();
bool isAuthenticated() const { return m_isAuthenticated; } bool isAuthenticated() const;
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; } Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
SipPlugin* sipPlugin(); SipPlugin* sipPlugin();
QWidget* configurationWidget() { return m_configWidget.data(); } QWidget* configurationWidget() { return m_configWidget.data(); }
QWidget* aclWidget() { return 0; } QWidget* aclWidget() { return 0; }
void saveConfig();
void refreshProxy() {}; virtual Tomahawk::Accounts::Account::ConnectionState connectionState() const;
private: private:
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
bool m_isAuthenticated;
QWeakPointer< QWidget > m_configWidget; QWeakPointer< QWidget > m_configWidget;
QWeakPointer< XmppSipPlugin > m_xmppSipPlugin; QWeakPointer< XmppSipPlugin > m_xmppSipPlugin;

View File

@@ -22,7 +22,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <accounts/accountmanager.h> #include <accounts/AccountManager.h>
#include <utils/logger.h> #include <utils/logger.h>
namespace Tomahawk namespace Tomahawk
@@ -53,16 +53,31 @@ XmppConfigWidget::~XmppConfigWidget()
delete m_ui; delete m_ui;
} }
void
XmppConfigWidget::saveConfig()
{
QVariantHash credentials = m_account->credentials();
credentials[ "username" ] = m_ui->xmppUsername->text();
credentials[ "password" ] = m_ui->xmppPassword->text();
credentials[ "server" ] = m_ui->xmppServer->text();
credentials[ "port" ] = m_ui->xmppPort->text();
m_account->setAccountFriendlyName( m_ui->xmppUsername->text() );
m_account->setCredentials( credentials );
m_account->sync();
static_cast< XmppSipPlugin* >( m_account->sipPlugin() )->checkSettings();
}
void void
XmppConfigWidget::onCheckJidExists( QString jid ) XmppConfigWidget::onCheckJidExists( QString jid )
{ {
QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->getAccounts( Tomahawk::Accounts::SipType ); QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
foreach( Tomahawk::Accounts::Account* account, accounts ) foreach( Tomahawk::Accounts::Account* account, accounts )
{ {
if ( account->accountId() == m_account->accountId() ) if ( account->accountId() == m_account->accountId() )
continue; continue;
QString savedUsername = account->credentials()[ "username" ].toString(); QString savedUsername = account->credentials()[ "username" ].toString();
QStringList savedSplitUsername = account->credentials()[ "username" ].toString().split("@"); QStringList savedSplitUsername = account->credentials()[ "username" ].toString().split("@");
QString savedServer = account->configuration()[ "server" ].toString(); QString savedServer = account->configuration()[ "server" ].toString();

View File

@@ -45,12 +45,14 @@ public:
explicit XmppConfigWidget( XmppAccount* account = 0, QWidget *parent = 0 ); explicit XmppConfigWidget( XmppAccount* account = 0, QWidget *parent = 0 );
virtual ~XmppConfigWidget(); virtual ~XmppConfigWidget();
void saveConfig();
signals: signals:
void dataError( bool exists ); void dataError( bool exists );
private slots: private slots:
void onCheckJidExists( QString jid ); void onCheckJidExists( QString jid );
private: private:
Ui::XmppConfigWidget *m_ui; Ui::XmppConfigWidget *m_ui;
XmppAccount *m_account; XmppAccount *m_account;

View File

@@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org? * Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -76,12 +76,6 @@ Account::isAuthenticated() const
} }
void
Account::refreshProxy()
{
}
void void
Account::onError(int errorCode, const QString& error ) Account::onError(int errorCode, const QString& error )
{ {
@@ -97,6 +91,94 @@ Account::onConnectionStateChanged( Account::ConnectionState )
} }
void
Account::syncConfig()
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
s->setValue( "accountfriendlyname", m_accountFriendlyName );
s->setValue( "enabled", m_enabled );
s->setValue( "autoconnect", m_autoConnect );
s->setValue( "credentials", m_credentials );
s->setValue( "configuration", m_configuration );
s->setValue( "acl", m_acl );
s->setValue( "types", m_types );
s->endGroup();
s->sync();
}
void
Account::loadFromConfig( const QString& accountId )
{
m_accountId = accountId;
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
m_enabled = s->value( "enabled", false ).toBool();
m_autoConnect = s->value( "autoconnect", false ).toBool();
m_credentials = s->value( "credentials", QVariantHash() ).toHash();
m_configuration = s->value( "configuration", QVariantHash() ).toHash();
m_acl = s->value( "acl", QVariantMap() ).toMap();
m_types = s->value( "types", QStringList() ).toStringList();
s->endGroup();
}
void
Account::removeFromConfig()
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
s->remove( "accountfriendlyname" );
s->remove( "enabled" );
s->remove( "autoconnect" );
s->remove( "credentials" );
s->remove( "configuration" );
s->remove( "acl" );
s->remove( "types" );
s->endGroup();
s->remove( "accounts/" + m_accountId );
}
void
Account::setTypes( const QSet< AccountType > types )
{
QMutexLocker locker( &m_mutex );
m_types = QStringList();
foreach ( AccountType type, types )
{
switch( type )
{
case InfoType:
m_types << "InfoType";
break;
case SipType:
m_types << "SipType";
break;
}
}
syncConfig();
}
QSet< AccountType >
Account::types() const
{
QMutexLocker locker( &m_mutex );
QSet< AccountType > set;
foreach ( QString type, m_types )
{
if ( type == "InfoType" )
set << InfoType;
else if ( type == "SipType" )
set << SipType;
}
return set;
}
} }
} }

View File

@@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2011, Leo Franchi <lfranchi@kde.org? * Copyright 2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -63,23 +63,28 @@ public:
explicit Account( const QString &accountId ); explicit Account( const QString &accountId );
virtual ~Account() {} virtual ~Account() {}
virtual QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm" QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm"
virtual QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc. QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc.
virtual bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; } bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; }
virtual bool autoConnect() const { QMutexLocker locker( &m_mutex ); return m_autoConnect; } bool autoConnect() const { QMutexLocker locker( &m_mutex ); return m_autoConnect; }
virtual QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; } QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; }
virtual QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_configuration; } QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_configuration; }
/**
* Configuration widgets can have a "dataError( bool )" signal to enable/disable the OK button in their wrapper dialogs.
*/
virtual QWidget* configurationWidget() = 0; virtual QWidget* configurationWidget() = 0;
virtual void saveConfig() {} // called when the widget has been edited. save values from config widget, call sync() to write to disk account generic settings
virtual QVariantHash credentials() { QMutexLocker locker( &m_mutex ); return m_credentials; } QVariantHash credentials() { QMutexLocker locker( &m_mutex ); return m_credentials; }
virtual QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_acl; } QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_acl; }
virtual QWidget* aclWidget() = 0; virtual QWidget* aclWidget() = 0;
virtual QIcon icon() const = 0; virtual QIcon icon() const = 0;
virtual ConnectionState connectionState() = 0; virtual ConnectionState connectionState() const = 0;
virtual bool isAuthenticated() const = 0; virtual bool isAuthenticated() const = 0;
virtual QString errorMessage() const { QMutexLocker locker( &m_mutex ); return m_cachedError; } virtual QString errorMessage() const { QMutexLocker locker( &m_mutex ); return m_cachedError; }
@@ -87,51 +92,27 @@ public:
virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0; virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
virtual SipPlugin* sipPlugin() = 0; virtual SipPlugin* sipPlugin() = 0;
virtual QSet< AccountType > types() const QSet< AccountType > types() const;
{
QMutexLocker locker( &m_mutex );
QSet< AccountType > set;
foreach ( QString type, m_types )
{
if ( type == "InfoType" )
set << InfoType;
else if ( type == "SipType" )
set << SipType;
}
return set;
}
virtual void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; } void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; }
virtual void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_accountFriendlyName = friendlyName; } void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_accountFriendlyName = friendlyName; }
virtual void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; } void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; }
virtual void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; } void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; }
virtual void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; } void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
virtual void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; } void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; }
virtual void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; } void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; }
virtual void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; } void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
virtual void setTypes( const QSet< AccountType > types ) void setTypes( const QSet< AccountType > types );
{
QMutexLocker locker( &m_mutex );
m_types = QStringList();
foreach ( AccountType type, types )
{
switch( type )
{
case InfoType:
m_types << "InfoType";
break;
case SipType:
m_types << "SipType";
break;
}
}
syncConfig();
}
virtual void refreshProxy() = 0;
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); }; virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
/**
* Removes all the settings held in the config file for this account instance
*
* Re-implement if you have saved additional files or config settings outside the built-in ones
*/
virtual void removeFromConfig();
public slots: public slots:
virtual void authenticate() = 0; virtual void authenticate() = 0;
virtual void deauthenticate() = 0; virtual void deauthenticate() = 0;
@@ -141,38 +122,10 @@ signals:
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void configurationChanged(); void configurationChanged();
void authenticated( bool );
protected: protected:
virtual void loadFromConfig( const QString &accountId ) virtual void loadFromConfig( const QString &accountId );
{ virtual void syncConfig();
m_accountId = accountId;
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
m_enabled = s->value( "enabled", false ).toBool();
m_autoConnect = s->value( "autoconnect", false ).toBool();
m_credentials = s->value( "credentials", QVariantHash() ).toHash();
m_configuration = s->value( "configuration", QVariantHash() ).toHash();
m_acl = s->value( "acl", QVariantMap() ).toMap();
m_types = s->value( "types", QStringList() ).toStringList();
s->endGroup();
}
virtual void syncConfig()
{
TomahawkSettings* s = TomahawkSettings::instance();
s->beginGroup( "accounts/" + m_accountId );
s->setValue( "accountfriendlyname", m_accountFriendlyName );
s->setValue( "enabled", m_enabled );
s->setValue( "autoconnect", m_autoConnect );
s->setValue( "credentials", m_credentials );
s->setValue( "configuration", m_configuration );
s->setValue( "acl", m_acl );
s->setValue( "types", m_types );
s->endGroup();
s->sync();
}
private slots: private slots:
void onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ); void onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState );

View File

@@ -49,12 +49,17 @@ AccountManager::AccountManager( QObject *parent )
: QObject( parent ) : QObject( parent )
{ {
s_instance = this; s_instance = this;
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
loadPluginFactories( findPluginFactories() ); loadPluginFactories( findPluginFactories() );
} }
AccountManager::~AccountManager() AccountManager::~AccountManager()
{ {
delete SipHandler::instance();
disconnectAll(); disconnectAll();
qDeleteAll( m_accounts ); qDeleteAll( m_accounts );
} }
@@ -116,12 +121,31 @@ AccountManager::loadPluginFactories( const QStringList& paths )
} }
bool
AccountManager::hasPluginWithFactory( const QString& factory ) const
{
foreach( Account* account, m_accounts ) {
if( factoryFromId( account->accountId() ) == factory )
return true;
}
return false;
}
QString QString
AccountManager::factoryFromId( const QString& accountId ) const AccountManager::factoryFromId( const QString& accountId ) const
{ {
return accountId.split( "_" ).first(); return accountId.split( "_" ).first();
} }
AccountFactory*
AccountManager::factoryForAccount( Account* account ) const
{
const QString factoryId = factoryFromId( account->accountId() );
return m_accountFactories.value( factoryId, 0 );
}
void void
AccountManager::loadPluginFactory( const QString& path ) AccountManager::loadPluginFactory( const QString& path )
@@ -191,7 +215,7 @@ AccountManager::loadFromConfig()
if( m_accountFactories.contains( pluginFactory ) ) if( m_accountFactories.contains( pluginFactory ) )
{ {
Account* account = loadPlugin( accountId ); Account* account = loadPlugin( accountId );
addAccountPlugin( account ); addAccount( account );
} }
} }
} }
@@ -203,13 +227,11 @@ AccountManager::initSIP()
foreach( Account* account, accounts( Tomahawk::Accounts::SipType ) ) foreach( Account* account, accounts( Tomahawk::Accounts::SipType ) )
{ {
tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId(); tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId();
SipPlugin* p = account->sipPlugin(); hookupAndEnable( account, true );
SipHandler::instance()->hookUpPlugin( p );
} }
} }
Account* Account*
AccountManager::loadPlugin( const QString& accountId ) AccountManager::loadPlugin( const QString& accountId )
{ {
@@ -223,8 +245,9 @@ AccountManager::loadPlugin( const QString& accountId )
return account; return account;
} }
void void
AccountManager::addAccountPlugin( Account* account ) AccountManager::addAccount( Account* account )
{ {
tDebug() << Q_FUNC_INFO << "adding account plugin"; tDebug() << Q_FUNC_INFO << "adding account plugin";
m_accounts.append( account ); m_accounts.append( account );
@@ -235,14 +258,53 @@ AccountManager::addAccountPlugin( Account* account )
emit added( account ); emit added( account );
} }
void
AccountManager::removeAccount( Account* account )
{
account->deauthenticate();
// emit before moving from list so accountmodel can get indexOf
emit removed( account );
m_accounts.removeAll( account );
m_enabledAccounts.removeAll( account );
m_connectedAccounts.removeAll( account );
foreach ( AccountType type, m_accountsByAccountType.keys() )
{
QList< Account* > accounts = m_accountsByAccountType.value( type );
accounts.removeAll( account );
m_accountsByAccountType[ type ] = accounts;
}
TomahawkSettings::instance()->removeAccount( account->accountId() );
account->removeFromConfig();
account->deleteLater();
}
void void
AccountManager::hookupAccount( Account* account ) const AccountManager::hookupAccount( Account* account ) const
{ {
connect( account, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) ); connect( account, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
connect( account, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( Accounts::Account::ConnectionState ) ) ); connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), SLOT( onStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
} }
void
AccountManager::hookupAndEnable( Account* account, bool startup )
{
SipPlugin* p = account->sipPlugin();
SipHandler::instance()->hookUpPlugin( p );
if ( account->enabled() && ( !startup || account->autoConnect() ) )
{
account->authenticate();
m_enabledAccounts << account;
}
}
void void
AccountManager::onError( int code, const QString& msg ) AccountManager::onError( int code, const QString& msg )

View File

@@ -44,16 +44,16 @@ public:
explicit AccountManager( QObject *parent ); explicit AccountManager( QObject *parent );
virtual ~AccountManager(); virtual ~AccountManager();
QStringList findPluginFactories();
void loadPluginFactories( const QStringList &paths );
void loadFromConfig(); void loadFromConfig();
void initSIP(); void initSIP();
void loadPluginFactory( const QString &path ); QList< AccountFactory* > factories() const { return m_accountFactories.values(); }
void addAccountPlugin( Account* account ); bool hasPluginWithFactory( const QString& factory ) const;
Account* loadPlugin( const QString &accountId ); AccountFactory* factoryForAccount( Account* account ) const;
QString factoryFromId( const QString& accountId ) const;
void addAccount( Account* account );
void hookupAndEnable( Account* account, bool startup = false ); /// Hook up signals and start the plugin
void removeAccount( Account* account );
QList< Account* > accounts() const { return m_accounts; }; QList< Account* > accounts() const { return m_accounts; };
QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; } QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
@@ -74,11 +74,17 @@ signals:
void stateChanged( Account* p, Accounts::Account::ConnectionState state ); void stateChanged( Account* p, Accounts::Account::ConnectionState state );
private slots: private slots:
void onStateChanged( Accounts::Account::ConnectionState state ); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void onError( int code, const QString& msg ); void onError( int code, const QString& msg );
void onSettingsChanged(); void onSettingsChanged();
private: private:
QStringList findPluginFactories();
void loadPluginFactories( const QStringList &paths );
void loadPluginFactory( const QString &path );
QString factoryFromId( const QString& accountId ) const;
Account* loadPlugin( const QString &accountId );
void hookupAccount( Account* ) const; void hookupAccount( Account* ) const;
QList< Account* > m_accounts; QList< Account* > m_accounts;

View File

@@ -54,14 +54,13 @@ SipHandler::SipHandler( QObject* parent )
: QObject( parent ) : QObject( parent )
{ {
s_instance = this; s_instance = this;
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
} }
SipHandler::~SipHandler() SipHandler::~SipHandler()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
s_instance = 0;
} }
@@ -111,16 +110,6 @@ SipHandler::hookUpPlugin( SipPlugin* sip )
QObject::connect( sip->account(), SIGNAL( configurationChanged() ), sip, SLOT( configurationChanged() ) ); QObject::connect( sip->account(), SIGNAL( configurationChanged() ), sip, SLOT( configurationChanged() ) );
} }
/*
void
SipHandler::refreshProxy()
{
qDebug() << Q_FUNC_INFO;
foreach( SipPlugin* sip, m_allPlugins )
sip->refreshProxy();
}*/
void void
SipHandler::onPeerOnline( const QString& jid ) SipHandler::onPeerOnline( const QString& jid )

View File

@@ -48,8 +48,6 @@ public:
void loadFromAccountManager(); void loadFromAccountManager();
bool hasPluginType( const QString& factoryId ) const;
const QPixmap avatar( const QString& name ) const; const QPixmap avatar( const QString& name ) const;
//TODO: implement a proper SipInfo class and maybe attach it to the source //TODO: implement a proper SipInfo class and maybe attach it to the source
const SipInfo sipInfo( const QString& peerId ) const; const SipInfo sipInfo( const QString& peerId ) const;
@@ -57,10 +55,6 @@ public:
void hookUpPlugin( SipPlugin* p ); void hookUpPlugin( SipPlugin* p );
public slots:
// TODO no longer called from anywhere... can we remove it?
// void refreshProxy();
private slots: private slots:
void onSipInfo( const QString& peerId, const SipInfo& info ); void onSipInfo( const QString& peerId, const SipInfo& info );
void onSoftwareVersion( const QString& peerId, const QString& versionString ); void onSoftwareVersion( const QString& peerId, const QString& versionString );

View File

@@ -82,13 +82,6 @@ SipPlugin::peersOnline() const
} }
void
SipPlugin::refreshProxy()
{
qDebug() << Q_FUNC_INFO << "Not implemented";
}
void void
SipPlugin::onPeerOnline( const QString& peerId ) SipPlugin::onPeerOnline( const QString& peerId )
{ {

View File

@@ -54,7 +54,6 @@ public:
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
virtual QMenu* menu(); virtual QMenu* menu();
#endif #endif
virtual void saveConfig() {} // called when the widget has been edited
virtual QIcon icon() const; virtual QIcon icon() const;
virtual Tomahawk::Accounts::Account* account() const; virtual Tomahawk::Accounts::Account* account() const;
// peer infos // peer infos
@@ -69,8 +68,6 @@ public slots:
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0; virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
virtual void sendMsg( const QString& to, const QString& msg ) = 0; virtual void sendMsg( const QString& to, const QString& msg ) = 0;
virtual void refreshProxy();
signals: signals:
void peerOnline( const QString& ); void peerOnline( const QString& );
void peerOffline( const QString& ); void peerOffline( const QString& );

View File

@@ -126,7 +126,7 @@ void
TomahawkSettings::doInitialSetup() TomahawkSettings::doInitialSetup()
{ {
// by default we add a local network resolver // by default we add a local network resolver
addSipPlugin( "sipzeroconf_autocreated" ); addAccount( "sipzeroconf_autocreated" );
} }

View File

@@ -114,7 +114,7 @@ public:
void addAccount( const QString& accountId ); void addAccount( const QString& accountId );
void removeAccount( const QString& accountId ); void removeAccount( const QString& accountId );
void setBookmarkPlaylist( const QString& guid ); void setBookmarkPlaylist( const QString& guid );
QString bookmarkPlaylist() const; QString bookmarkPlaylist() const;

View File

@@ -50,8 +50,9 @@
#include "database/database.h" #include "database/database.h"
#include "network/servent.h" #include "network/servent.h"
#include "playlist/dynamic/widgets/LoadingSpinner.h" #include "playlist/dynamic/widgets/LoadingSpinner.h"
#include "sip/SipHandler.h"
#include "accounts/AccountModel.h" #include "accounts/AccountModel.h"
#include "accounts/Account.h"
#include "accounts/AccountManager.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "ui_proxydialog.h" #include "ui_proxydialog.h"
@@ -115,9 +116,8 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ui->accountsView->setContextMenuPolicy( Qt::CustomContextMenu ); ui->accountsView->setContextMenuPolicy( Qt::CustomContextMenu );
ui->accountsView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); ui->accountsView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
connect( ui->accountsView, SIGNAL( clicked( QModelIndex ) ), this, SLOT( sipItemClicked( QModelIndex ) ) ); connect( sipdel, SIGNAL( openConfig( Tomahawk::Accounts::Account* ) ), this, SLOT( openAccountConfig( Tomahawk::Accounts::Account* ) ) );
connect( sipdel, SIGNAL( openConfig( SipPlugin* ) ), this, SLOT( openSipConfig( SipPlugin* ) ) ); connect( ui->accountsView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( accountContextMenuRequest( QPoint ) ) );
connect( ui->accountsView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( sipContextMenuRequest( QPoint ) ) );
m_accountModel = new AccountModel( this ); m_accountModel = new AccountModel( this );
ui->accountsView->setModel( m_accountModel ); ui->accountsView->setModel( m_accountModel );
@@ -131,7 +131,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) ); connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) );
} }
//setupSipButtons(); setupAccountButtons();
ui->staticHostName->setText( s->externalHostname() ); ui->staticHostName->setText( s->externalHostname() );
ui->staticPort->setValue( s->externalPort() ); ui->staticPort->setValue( s->externalPort() );
@@ -313,13 +313,13 @@ SettingsDialog::createIcons()
connect( ui->listWidget, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ), SLOT( changePage( QListWidgetItem*, QListWidgetItem* ) ) ); connect( ui->listWidget, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ), SLOT( changePage( QListWidgetItem*, QListWidgetItem* ) ) );
} }
/*
void void
SettingsDialog::setupSipButtons() SettingsDialog::setupAccountButtons()
{ {
foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) foreach( AccountFactory* f, AccountManager::instance()->factories() )
{ {
if( f->isUnique() && SipHandler::instance()->hasPluginType( f->factoryId() ) ) if( f->isUnique() && AccountManager::instance()->hasPluginWithFactory( f->factoryId() ) )
{ {
continue; continue;
} }
@@ -331,9 +331,9 @@ SettingsDialog::setupSipButtons()
connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) ); connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
} }
connect( ui->removeSipButton, SIGNAL( clicked( bool ) ), this, SLOT( sipPluginDeleted( bool ) ) ); connect( ui->removeSipButton, SIGNAL( clicked( bool ) ), this, SLOT( accountDeleted( bool ) ) );
} }
*/
void void
SettingsDialog::changePage( QListWidgetItem* current, QListWidgetItem* previous ) SettingsDialog::changePage( QListWidgetItem* current, QListWidgetItem* previous )
@@ -591,39 +591,26 @@ SettingsDialog::resolverConfigClosed( int value )
} }
} }
/*
void
SettingsDialog::sipItemClicked( const QModelIndex& item )
{
if( item.data( SipModel::FactoryRole ).toBool() )
if( ui->accountsView->isExpanded( item ) )
ui->accountsView->collapse( item );
else
ui->accountsView->expand( item );
else if( item.data( SipModel::FactoryItemRole ).toBool() )
sipFactoryClicked( qobject_cast<SipPluginFactory* >( item.data( SipModel::SipPluginFactoryData ).value< QObject* >() ) );
}
void void
SettingsDialog::openSipConfig( SipPlugin* p ) SettingsDialog::openAccountConfig( Account* account )
{ {
if( p->configWidget() ) if( account->configurationWidget() )
{ {
#ifndef Q_WS_MAC #ifndef Q_WS_MAC
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Configuration" ).arg( p->friendlyName() ), this ); DelegateConfigWrapper dialog( account->configurationWidget(), QString("%1 Configuration" ).arg( account->accountFriendlyName() ), this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
int ret = dialog.exec(); int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) if( !watcher.isNull() && ret == QDialog::Accepted )
{ {
// send changed config to resolver // send changed config to resolver
p->saveConfig(); account->saveConfig();
} }
#else #else
// on osx a sheet needs to be non-modal // on osx a sheet needs to be non-modal
DelegateConfigWrapper* dialog = new DelegateConfigWrapper( p->configWidget(), QString("%1 Configuration" ).arg( p->friendlyName() ), this, Qt::Sheet ); DelegateConfigWrapper* dialog = new DelegateConfigWrapper( account->configurationWidget(), QString("%1 Configuration" ).arg( account->accountFriendlyName() ), this, Qt::Sheet );
dialog->setProperty( "sipplugin", QVariant::fromValue< QObject* >( p ) ); dialog->setProperty( "accountplugin", QVariant::fromValue< QObject* >( account ) );
connect( dialog, SIGNAL( finished( int ) ), this, SLOT( sipConfigClosed( int ) ) ); connect( dialog, SIGNAL( finished( int ) ), this, SLOT( accountConfigClosed( int ) ) );
dialog->show(); dialog->show();
#endif #endif
@@ -632,13 +619,13 @@ SettingsDialog::openSipConfig( SipPlugin* p )
void void
SettingsDialog::sipConfigClosed( int value ) SettingsDialog::accountConfigClosed( int value )
{ {
if( value == QDialog::Accepted ) if( value == QDialog::Accepted )
{ {
DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() ); DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() );
SipPlugin* p = qobject_cast< SipPlugin* >( dialog->property( "sipplugin" ).value< QObject* >() ); Account* account = qobject_cast< Account* >( dialog->property( "accountplugin" ).value< QObject* >() );
p->saveConfig(); account->saveConfig();
} }
} }
@@ -649,149 +636,154 @@ SettingsDialog::factoryActionTriggered( bool )
Q_ASSERT( sender() && qobject_cast< QAction* >( sender() ) ); Q_ASSERT( sender() && qobject_cast< QAction* >( sender() ) );
QAction* a = qobject_cast< QAction* >( sender() ); QAction* a = qobject_cast< QAction* >( sender() );
Q_ASSERT( qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ) ); Q_ASSERT( qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) );
SipPluginFactory* f = qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ); AccountFactory* f = qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() );
sipFactoryClicked( f ); accountFactoryClicked( f );
} }
void void
SettingsDialog::sipFactoryClicked( SipPluginFactory* factory ) SettingsDialog::accountFactoryClicked( AccountFactory* factory )
{ {
//if exited with OK, create it, if not, delete it immediately! //if exited with OK, create it, if not, delete it immediately!
SipPlugin* p = factory->createPlugin(); Account* account = factory->createAccount();
bool added = false; bool added = false;
if( p->configWidget() ) if( account->configurationWidget() )
{ {
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
// on osx a sheet needs to be non-modal // on osx a sheet needs to be non-modal
DelegateConfigWrapper* dialog = new DelegateConfigWrapper( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this, Qt::Sheet ); DelegateConfigWrapper* dialog = new DelegateConfigWrapper( account->configurationWidget(), QString("%1 Config" ).arg( account->accountFriendlyName() ), this, Qt::Sheet );
dialog->setProperty( "sipplugin", QVariant::fromValue< QObject* >( p ) ); dialog->setProperty( "accountplugin", QVariant::fromValue< QObject* >( account ) );
connect( dialog, SIGNAL( finished( int ) ), this, SLOT( sipCreateConfigClosed( int ) ) ); connect( dialog, SIGNAL( finished( int ) ), this, SLOT( accountCreateConfigClosed( int ) ) );
connect( p, SIGNAL( datatError( bool ) ), dialog, SLOT( toggleOkButton( bool ) ) );
if( account->configurationWidget()->metaObject()->indexOfSignal( "dataError(bool)" ) > -1 )
connect( account->configurationWidget(), SIGNAL( dataError( bool ) ), dialog, SLOT( toggleOkButton( bool ) ), Qt::UniqueConnection );
dialog->show(); dialog->show();
#else #else
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this ); DelegateConfigWrapper dialog( account->configurationWidget(), QString("%1 Config" ).arg( account->accountFriendlyName() ), this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
connect( p, SIGNAL( dataError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ) );
if( account->configurationWidget()->metaObject()->indexOfSignal( "dataError(bool)" ) > -1 )
connect( account->configurationWidget(), SIGNAL( dataError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ), Qt::UniqueConnection );
int ret = dialog.exec(); int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) if( !watcher.isNull() && ret == QDialog::Accepted ) // send changed config to account
{
// send changed config to resolver
p->saveConfig();
// accepted, so add it to tomahawk
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
SipHandler::instance()->addSipPlugin( p );
added = true; added = true;
} else // canceled, delete it
else
{
// canceled, delete it
added = false; added = false;
}
handleSipPluginAdded( p, added ); handleAccountAdded( account, added );
#endif #endif
} else } else
{ {
// no config, so just add it // no config, so just add it
added = true; added = true;
TomahawkSettings::instance()->addSipPlugin( p->pluginId() ); handleAccountAdded( account, added );
SipHandler::instance()->addSipPlugin( p );
handleSipPluginAdded( p, added );
} }
} }
void void
SettingsDialog::sipCreateConfigClosed( int finished ) SettingsDialog::accountCreateConfigClosed( int finished )
{ {
DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() ); DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() );
SipPlugin* p = qobject_cast< SipPlugin* >( dialog->property( "sipplugin" ).value< QObject* >() ); Account* account = qobject_cast< Account* >( dialog->property( "accountplugin" ).value< QObject* >() );
Q_ASSERT( p ); Q_ASSERT( account );
bool added = false; bool added = ( finished == QDialog::Accepted );
if( finished == QDialog::Accepted )
{
p->saveConfig(); handleAccountAdded( account, added );
TomahawkSettings::instance()->addSipPlugin( p->pluginId() );
SipHandler::instance()->addSipPlugin( p );
added = true;
}
handleSipPluginAdded( p, added );
} }
void void
SettingsDialog::handleSipPluginAdded( SipPlugin* p, bool added ) SettingsDialog::handleAccountAdded( Account* account, bool added )
{ {
SipPluginFactory* f = SipHandler::instance()->factoryFromPlugin( p ); AccountFactory* f = AccountManager::instance()->factoryForAccount( account );
if( added && f && f->isUnique() ) if ( added )
{ {
// remove from actions list account->setEnabled( true );
QAction* toremove = 0; account->setAutoConnect( true );
foreach( QAction* a, ui->addSipButton->actions() ) account->saveConfig();
TomahawkSettings::instance()->addAccount( account->accountId() );
AccountManager::instance()->addAccount( account );
AccountManager::instance()->hookupAndEnable( account );
if( f && f->isUnique() )
{ {
if( f == qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ) ) // remove from actions list
QAction* toremove = 0;
foreach( QAction* a, ui->addSipButton->actions() )
{ {
toremove = a; if( f == qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) )
break; {
toremove = a;
break;
}
} }
if( toremove )
ui->addSipButton->removeAction( toremove );
} }
if( toremove )
ui->addSipButton->removeAction( toremove );
} }
else if( added == false ) else
{ // user pressed cancel { // user pressed cancel
delete p; delete account;
} }
} }
void void
SettingsDialog::sipContextMenuRequest( const QPoint& p ) SettingsDialog::accountContextMenuRequest( const QPoint& p )
{ {
QModelIndex idx = ui->accountsView->indexAt( p ); QModelIndex idx = ui->accountsView->indexAt( p );
// if it's an account, allow to delete // if it's an account, allow to delete
if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() ) if( idx.isValid() )
{ {
QList< QAction* > acts; QList< QAction* > acts;
acts << new QAction( tr( "Delete Account" ), this ); acts << new QAction( tr( "Delete Account" ), this );
acts.first()->setProperty( "sipplugin", idx.data( SipModel::SipPluginData ) ); acts.first()->setProperty( "accountplugin", idx.data( AccountModel::AccountData ) );
connect( acts.first(), SIGNAL( triggered( bool ) ), this, SLOT( sipPluginRowDeleted( bool ) ) ); connect( acts.first(), SIGNAL( triggered( bool ) ), this, SLOT( onAccountRowDeleted( bool ) ) );
QMenu::exec( acts, ui->accountsView->mapToGlobal( p ) ); QMenu::exec( acts, ui->accountsView->mapToGlobal( p ) );
} }
} }
void void
SettingsDialog::sipPluginRowDeleted( bool ) SettingsDialog::onAccountRowDeleted( bool )
{ {
SipPlugin* p = qobject_cast< SipPlugin* >( qobject_cast< QAction* >( sender() )->property( "sipplugin" ).value< QObject* >() ); Account* account = qobject_cast< Account* >( qobject_cast< QAction* >( sender() )->property( "accountplugin" ).value< QObject* >() );
SipHandler::instance()->removeSipPlugin( p );
if( AccountFactory* f = AccountManager::instance()->factoryForAccount( account ) )
{
if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu
{
QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
ui->addSipButton->addAction( action );
connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
}
}
AccountManager::instance()->removeAccount( account );
} }
void void
SettingsDialog::sipPluginDeleted( bool ) SettingsDialog::accountDeleted( bool )
{ {
QModelIndexList indexes = ui->accountsView->selectionModel()->selectedIndexes(); QModelIndexList indexes = ui->accountsView->selectionModel()->selectedIndexes();
// if it's an account, allow to delete // if it's an account, allow to delete
foreach( const QModelIndex& idx, indexes ) foreach( const QModelIndex& idx, indexes )
{ {
if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() ) if( idx.isValid() )
{ {
SipPlugin* p = qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() ); Account* account = qobject_cast< Account* >( idx.data( AccountModel::AccountData ).value< QObject* >() );
if( SipPluginFactory* f = SipHandler::instance()->factoryFromPlugin( p ) ) if( AccountFactory* f = AccountManager::instance()->factoryForAccount( account ) )
{ {
if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu
{ {
@@ -802,11 +794,11 @@ SettingsDialog::sipPluginDeleted( bool )
connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) ); connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
} }
} }
SipHandler::instance()->removeSipPlugin( p ); AccountManager::instance()->removeAccount( account );
} }
} }
} }
*/
ProxyDialog::ProxyDialog( QWidget *parent ) ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent ) : QDialog( parent )

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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 * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -42,7 +43,9 @@ namespace Tomahawk
namespace Accounts namespace Accounts
{ {
class AccountModel; class AccountModel;
} class Account;
class AccountFactory;
}
} }
class ProxyDialog : public QDialog class ProxyDialog : public QDialog
@@ -95,21 +98,20 @@ private slots:
#endif #endif
void openResolverConfig( const QString& ); void openResolverConfig( const QString& );
/*
void sipItemClicked ( const QModelIndex& ); void openAccountConfig( Tomahawk::Accounts::Account* );
void openSipConfig( SipPlugin* );
void factoryActionTriggered ( bool ); void factoryActionTriggered ( bool );
void sipFactoryClicked( SipPluginFactory* ); void accountFactoryClicked( Tomahawk::Accounts::AccountFactory* );
void sipContextMenuRequest( const QPoint& ); void accountContextMenuRequest( const QPoint& );
void sipPluginDeleted( bool ); void accountDeleted( bool );
void sipPluginRowDeleted( bool ); void onAccountRowDeleted( bool );
*/
// dialog slots // dialog slots
void resolverConfigClosed( int value ); void resolverConfigClosed( int value );
/*
void sipConfigClosed( int value ); void accountConfigClosed( int value );
void sipCreateConfigClosed( int value ); void accountCreateConfigClosed( int value );
*/
void updateScanOptionsView(); void updateScanOptionsView();
void changePage( QListWidgetItem*, QListWidgetItem* ); void changePage( QListWidgetItem*, QListWidgetItem* );
@@ -117,8 +119,8 @@ private slots:
private: private:
void createIcons(); void createIcons();
//void setupSipButtons(); void setupAccountButtons();
//void handleSipPluginAdded( SipPlugin* p, bool added ); void handleAccountAdded( Tomahawk::Accounts::Account* p, bool added );
Ui_StackedSettingsDialog* ui; Ui_StackedSettingsDialog* ui;

View File

@@ -40,7 +40,6 @@
#include "database/databasecollection.h" #include "database/databasecollection.h"
#include "database/databasecommand_collectionstats.h" #include "database/databasecommand_collectionstats.h"
#include "database/databaseresolver.h" #include "database/databaseresolver.h"
#include "sip/SipHandler.h"
#include "playlist/dynamic/GeneratorFactory.h" #include "playlist/dynamic/GeneratorFactory.h"
#include "playlist/dynamic/echonest/EchonestGenerator.h" #include "playlist/dynamic/echonest/EchonestGenerator.h"
#include "playlist/dynamic/database/DatabaseGenerator.h" #include "playlist/dynamic/database/DatabaseGenerator.h"
@@ -297,7 +296,7 @@ TomahawkApp::~TomahawkApp()
//FIXME: delete GeneratorFactory::registerFactory( "echonest", new EchonestFactory ); ? //FIXME: delete GeneratorFactory::registerFactory( "echonest", new EchonestFactory ); ?
delete SipHandler::instance(); delete Tomahawk::Accounts::AccountManager::instance();
Pipeline::instance()->stop(); Pipeline::instance()->stop();
@@ -513,7 +512,7 @@ TomahawkApp::initSIP()
#endif #endif
tDebug( LOGINFO ) << "Connecting SIP classes"; tDebug( LOGINFO ) << "Connecting SIP classes";
Accounts::AccountManager::instance()->loadFromConfig(); Accounts::AccountManager::instance()->initSIP();
} }
} }