1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 23:39:42 +01: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;
desc.setItalic( true );
desc.setPointSize( error.pointSize() - 2 );
desc.setPointSize( desc.pointSize() - 2 );
// draw the background
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
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;
topt.rect = confRect;
@ -116,10 +116,10 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
QPixmap p;
QString statusText;
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" );
statusText = tr( "Online" );
} else if( state == SipPlugin::Connecting ) {
} else if( state == Account::Connecting ) {
p = QPixmap( RESPATH "images/sipplugin-offline.png" );
statusText = tr( "Connecting..." );
} 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 );
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;
painter->save();
painter->setFont( statusF );
@ -155,7 +155,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
// text to accompany checkbox
const int capW = statusFM.width( capString );
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 )
statusTextX = capTextX;
@ -167,7 +167,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
painter->setFont( name );
QFontMetrics namefm( name );
// 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
width = itemRect.width() - statusTextX;
QRect nameRect( textLeftEdge, pos, width, namefm.height() );
@ -208,15 +208,11 @@ AccountDelegate::checkRectForIndex( const QStyleOptionViewItem &option, const QM
QRect
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 );
QRect itemRect = opt.rect;
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
return confRect;
}
return QRect();
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, idx );
QRect itemRect = opt.rect;
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
return confRect;
}
@ -229,7 +225,7 @@ AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex
void
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 );
signals:
void openConfig( Account* );
void openConfig( Tomahawk::Accounts::Account* );
};
}

View File

@ -1,2 +1,2 @@
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> ===
*
* 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
* 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;
connect( account, SIGNAL( nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ), SLOT( accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &, const QTweetUser & ) ) );
if ( Database::instance()->dbid() != m_configuration[ "saveddbid" ].toString() )
{
m_configuration[ "cachedpeers" ] = QVariantHash();
@ -113,7 +114,7 @@ TwitterSipPlugin::connectPlugin()
m_cachedPeers = m_configuration[ "cachedpeers" ].toHash();
QStringList peerList = m_cachedPeers.keys();
qStableSort( peerList.begin(), peerList.end() );
if ( !m_account->isAuthenticated() )
{
tDebug() << Q_FUNC_INFO << "account isn't authenticated, attempting";
@ -144,7 +145,7 @@ TwitterSipPlugin::disconnectPlugin()
delete m_directMessageDestroy.data();
m_cachedTwitterAuth.clear();
m_configuration[ "cachedpeers" ] = m_cachedPeers;
syncConfig();
m_cachedPeers.empty();
@ -156,12 +157,12 @@ void
TwitterSipPlugin::accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user )
{
Q_UNUSED( user );
if ( !isValid() )
return;
m_cachedTwitterAuth = twitterAuth;
m_friendsTimeline = QWeakPointer<QTweetFriendsTimeline>( new QTweetFriendsTimeline( m_cachedTwitterAuth.data(), this ) );
m_mentions = QWeakPointer<QTweetMentions>( new QTweetMentions( 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() )
return;
foreach( QString screenName, peerList )
{
QVariantHash peerData = m_cachedPeers[screenName].toHash();
@ -227,7 +228,7 @@ TwitterSipPlugin::registerOffers( const QStringList &peerList )
m_configuration[ "cachedpeers" ] = m_cachedPeers;
syncConfig();
}
if ( Servent::instance()->connectedToSession( peerData["node"].toString() ) )
{
peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch();
@ -246,13 +247,13 @@ TwitterSipPlugin::registerOffers( const QStringList &peerList )
m_cachedAvatars.remove( screenName );
continue;
}
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)";
continue;
}
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;
if ( !isValid() )
return;
QTweetUserShow *userShowFetch = new QTweetUserShow( m_cachedTwitterAuth.data(), this );
connect( userShowFetch, SIGNAL( parsedUserInfo( QTweetUser ) ), SLOT( avatarUserDataSlot( QTweetUser ) ) );
userShowFetch->fetch( screenName );
@ -672,11 +673,6 @@ TwitterSipPlugin::avatarUserDataSlot( const QTweetUser &user )
connect( reply, SIGNAL( finished() ), this, SLOT( profilePicReply() ) );
}
void
TwitterSipPlugin::refreshProxy()
{
//handled by TwitterAccount::refreshProxy()
}
void
TwitterSipPlugin::profilePicReply()

View File

@ -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 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
@ -34,7 +35,7 @@
#include "accounts/accountdllmacro.h"
#include "sip/SipPlugin.h"
#include "accounts/account.h"
#include "accounts/Account.h"
#include "accounts/twitter/tomahawkoauthtwitter.h"
class ACCOUNTDLLEXPORT TwitterSipPlugin : public SipPlugin
@ -52,7 +53,6 @@ public:
public slots:
virtual void connectPlugin();
void disconnectPlugin();
void refreshProxy();
void configurationChanged();
void sendMsg( const QString& to, const QString& msg )
@ -73,7 +73,7 @@ public slots:
}
void checkSettings();
private slots:
void accountAuthenticated( const QWeakPointer< TomahawkOAuthTwitter > &twitterAuth, const QTweetUser &user );
void checkTimerFired();
@ -92,14 +92,14 @@ private slots:
void fetchAvatar( const QString &screenName );
void avatarUserDataSlot( const QTweetUser &user );
void profilePicReply();
private:
inline void syncConfig() { m_account->setCredentials( m_credentials ); m_account->setConfiguration( m_configuration ); m_account->sync(); }
bool refreshTwitterAuth();
void parseGotTomahawk( const QRegExp &regex, const QString &screenName, const QString &text );
QWeakPointer< TomahawkOAuthTwitter > m_cachedTwitterAuth;
QWeakPointer< QTweetFriendsTimeline > m_friendsTimeline;
QWeakPointer< QTweetMentions > m_mentions;
QWeakPointer< QTweetDirectMessages > m_directMessages;
@ -108,7 +108,7 @@ private:
QVariantHash m_configuration;
QVariantHash m_credentials;
QTimer m_checkTimer;
QTimer m_connectTimer;
QTimer m_dmPollTimer;

View File

@ -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 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
@ -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> ===
*
* 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
* it under the terms of the GNU General Public License as published by
@ -72,8 +73,6 @@ public:
bool refreshTwitterAuth();
TomahawkOAuthTwitter* twitterAuth() const { return m_twitterAuth.data(); }
void refreshProxy();
signals:
void nowAuthenticated( const QWeakPointer< TomahawkOAuthTwitter >&, const QTweetUser &user );
void nowDeauthenticated();

View File

@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
* 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
* it under the terms of the GNU General Public License as published by
@ -48,13 +49,16 @@
#include <utils/tomahawkutils.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 )
, m_menu( 0 )
, m_xmlConsole( 0 )
, m_state( Disconnected )
, m_state( Account::Disconnected )
{
qDebug() << Q_FUNC_INFO;
@ -152,7 +156,7 @@ XmppSipPlugin::connectPlugin()
if ( m_client->connection() )
connect(m_client->connection(), SIGNAL(error(SocketError)), SLOT(onError(SocketError)));
m_state = Connecting;
m_state = Account::Connecting;
emit stateChanged( m_state );
return;
}
@ -162,10 +166,10 @@ XmppSipPlugin::disconnectPlugin()
{
if (!m_client->isConnected())
{
if ( m_state != Disconnected ) // might be Connecting
if ( m_state != Account::Disconnected ) // might be Connecting
{
m_state = Disconnected;
emit stateChanged( m_state );
m_state = Account::Disconnected;
emit stateChanged( m_state );
}
return;
}
@ -178,7 +182,7 @@ XmppSipPlugin::disconnectPlugin()
m_peers.clear();
m_client->disconnectFromServer( true );
m_state = Disconnecting;
m_state = Account::Disconnecting;
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( presenceReceived( Jreen::Presence, const Jreen::MUCRoom::Participant* ) ), this, SLOT( onNewPresence( Jreen::Presence ) ) );
m_state = Connected;
m_state = Account::Connected;
emit stateChanged( m_state );
addMenuHelper();
@ -235,7 +239,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
break;
case Jreen::Client::AuthorizationError:
emit error( SipPlugin::AuthError, errorMessage( reason ) );
emit error( Account::AuthError, errorMessage( reason ) );
break;
case Jreen::Client::HostUnknown:
@ -246,7 +250,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
case Jreen::Client::SystemShutdown:
case Jreen::Client::Conflict:
case Jreen::Client::Unknown:
emit error( SipPlugin::ConnectionError, errorMessage( reason ) );
emit error( Account::ConnectionError, errorMessage( reason ) );
break;
default:
@ -254,7 +258,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
Q_ASSERT(false);
break;
}
m_state = Disconnected;
m_state = Account::Disconnected;
emit stateChanged( m_state );
removeMenuHelper();
@ -314,7 +318,7 @@ XmppSipPlugin::errorMessage( Jreen::Client::DisconnectReason reason )
break;
}
m_state = Disconnected;
m_state = Account::Disconnected;
emit stateChanged( m_state );
return QString();
@ -534,7 +538,7 @@ void XmppSipPlugin::removeMenuHelper()
void XmppSipPlugin::onNewMessage(const Jreen::Message& message)
{
if ( m_state != Connected )
if ( m_state != Account::Connected )
return;
// 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 )
{
Q_UNUSED(item);
if ( m_state != Connected )
if ( m_state != Account::Connected )
return;
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)
{
if ( m_state != Connected )
if ( m_state != Account::Connected )
return;
// qDebug() << Q_FUNC_INFO << "presence type:" << presence.subtype();
@ -704,7 +708,7 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result )
void XmppSipPlugin::onNewIq(const Jreen::IQ& iq)
{
if ( m_state != Connected )
if ( m_state != Account::Connected )
return;
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)
{
// qDebug() << Q_FUNC_INFO << jid;
if ( m_state != Connected )
if ( m_state != Account::Connected )
return;
Q_ASSERT(!m_avatarManager->avatar( jid ).isNull());
@ -911,7 +915,7 @@ XmppSipPlugin::readServer()
}
SipPlugin::ConnectionState
Account::ConnectionState
XmppSipPlugin::connectionState() const
{
return m_state;

View File

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

View File

@ -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 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
@ -19,6 +20,7 @@
#include "xmppaccount.h"
#include "xmppconfigwidget.h"
#include "sip/SipPlugin.h"
#include "ui_xmppconfigwidget.h"
#include <QtCore/QtPlugin>
@ -37,7 +39,6 @@ XmppAccountFactory::createAccount( const QString& accountId )
XmppAccount::XmppAccount( const QString &accountId )
: Account( accountId )
, m_isAuthenticated( false )
{
loadFromConfig( accountId );
@ -46,27 +47,52 @@ XmppAccount::XmppAccount( const QString &accountId )
types << SipType;
setTypes( types );
m_configWidget = QWeakPointer< XmppConfigWidget >( new XmppConfigWidget( this, 0 ) );
m_configWidget = QWeakPointer< QWidget >( new XmppConfigWidget( this, 0 ) );
}
XmppAccount::~XmppAccount()
{
delete m_configWidget.data();
delete m_xmppSipPlugin.data();
}
void
XmppAccount::authenticate()
{
return;
if ( connectionState() != Account::Connected )
sipPlugin()->connectPlugin();
}
void
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() )
{
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();

View File

@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Dominik Schmidt <dev@dominik-schmidt.de>
* 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
* it under the terms of the GNU General Public License as published by
@ -61,19 +62,19 @@ public:
void authenticate();
void deauthenticate();
bool isAuthenticated() const { return m_isAuthenticated; }
bool isAuthenticated() const;
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
SipPlugin* sipPlugin();
QWidget* configurationWidget() { return m_configWidget.data(); }
QWidget* aclWidget() { return 0; }
void saveConfig();
void refreshProxy() {};
virtual Tomahawk::Accounts::Account::ConnectionState connectionState() const;
private:
Ui_XmppConfigWidget* m_ui; // so the google wrapper can change the config dialog a bit
bool m_isAuthenticated;
QWeakPointer< QWidget > m_configWidget;
QWeakPointer< XmppSipPlugin > m_xmppSipPlugin;

View File

@ -22,7 +22,7 @@
#include <QMessageBox>
#include <accounts/accountmanager.h>
#include <accounts/AccountManager.h>
#include <utils/logger.h>
namespace Tomahawk
@ -53,16 +53,31 @@ XmppConfigWidget::~XmppConfigWidget()
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
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 )
{
if ( account->accountId() == m_account->accountId() )
continue;
QString savedUsername = account->credentials()[ "username" ].toString();
QStringList savedSplitUsername = account->credentials()[ "username" ].toString().split("@");
QString savedServer = account->configuration()[ "server" ].toString();

View File

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

View File

@ -1,7 +1,7 @@
/* === This file is part of Tomahawk Player - <http://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
* it under the terms of the GNU General Public License as published by
@ -76,12 +76,6 @@ Account::isAuthenticated() const
}
void
Account::refreshProxy()
{
}
void
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> ===
*
* 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
* it under the terms of the GNU General Public License as published by
@ -63,23 +63,28 @@ public:
explicit Account( const QString &accountId );
virtual ~Account() {}
virtual 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.
virtual bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; }
virtual bool autoConnect() const { QMutexLocker locker( &m_mutex ); return m_autoConnect; }
virtual QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; }
QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm"
QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc.
bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; }
bool autoConnect() const { QMutexLocker locker( &m_mutex ); return m_autoConnect; }
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 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 QIcon icon() const = 0;
virtual ConnectionState connectionState() = 0;
virtual ConnectionState connectionState() const = 0;
virtual bool isAuthenticated() const = 0;
virtual QString errorMessage() const { QMutexLocker locker( &m_mutex ); return m_cachedError; }
@ -87,51 +92,27 @@ public:
virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
virtual SipPlugin* sipPlugin() = 0;
virtual 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;
}
QSet< AccountType > types() const;
virtual 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; }
virtual void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; }
virtual void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; }
virtual 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; }
virtual 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; }
virtual 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;
void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; }
void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_accountFriendlyName = friendlyName; }
void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; }
void setAutoConnect( bool autoConnect ) { QMutexLocker locker( &m_mutex ); m_autoConnect = autoConnect; }
void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; }
void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; }
void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
void setTypes( const QSet< AccountType > types );
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:
virtual void authenticate() = 0;
virtual void deauthenticate() = 0;
@ -141,38 +122,10 @@ signals:
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void configurationChanged();
void authenticated( bool );
protected:
virtual void 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();
}
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();
}
virtual void loadFromConfig( const QString &accountId );
virtual void syncConfig();
private slots:
void onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState );

View File

@ -49,12 +49,17 @@ AccountManager::AccountManager( QObject *parent )
: QObject( parent )
{
s_instance = this;
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
loadPluginFactories( findPluginFactories() );
}
AccountManager::~AccountManager()
{
delete SipHandler::instance();
disconnectAll();
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
AccountManager::factoryFromId( const QString& accountId ) const
{
return accountId.split( "_" ).first();
}
AccountFactory*
AccountManager::factoryForAccount( Account* account ) const
{
const QString factoryId = factoryFromId( account->accountId() );
return m_accountFactories.value( factoryId, 0 );
}
void
AccountManager::loadPluginFactory( const QString& path )
@ -191,7 +215,7 @@ AccountManager::loadFromConfig()
if( m_accountFactories.contains( pluginFactory ) )
{
Account* account = loadPlugin( accountId );
addAccountPlugin( account );
addAccount( account );
}
}
}
@ -203,13 +227,11 @@ AccountManager::initSIP()
foreach( Account* account, accounts( Tomahawk::Accounts::SipType ) )
{
tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId();
SipPlugin* p = account->sipPlugin();
SipHandler::instance()->hookUpPlugin( p );
hookupAndEnable( account, true );
}
}
Account*
AccountManager::loadPlugin( const QString& accountId )
{
@ -223,8 +245,9 @@ AccountManager::loadPlugin( const QString& accountId )
return account;
}
void
AccountManager::addAccountPlugin( Account* account )
AccountManager::addAccount( Account* account )
{
tDebug() << Q_FUNC_INFO << "adding account plugin";
m_accounts.append( account );
@ -235,14 +258,53 @@ AccountManager::addAccountPlugin( Account* 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
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 ) ) );
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
AccountManager::onError( int code, const QString& msg )

View File

@ -44,16 +44,16 @@ public:
explicit AccountManager( QObject *parent );
virtual ~AccountManager();
QStringList findPluginFactories();
void loadPluginFactories( const QStringList &paths );
void loadFromConfig();
void initSIP();
void loadPluginFactory( const QString &path );
void addAccountPlugin( Account* account );
Account* loadPlugin( const QString &accountId );
QString factoryFromId( const QString& accountId ) const;
QList< AccountFactory* > factories() const { return m_accountFactories.values(); }
bool hasPluginWithFactory( const QString& factory ) const;
AccountFactory* factoryForAccount( Account* account ) 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( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
@ -74,11 +74,17 @@ signals:
void stateChanged( Account* p, Accounts::Account::ConnectionState state );
private slots:
void onStateChanged( Accounts::Account::ConnectionState state );
void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void onError( int code, const QString& msg );
void onSettingsChanged();
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;
QList< Account* > m_accounts;

View File

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

View File

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

View File

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

View File

@ -126,7 +126,7 @@ void
TomahawkSettings::doInitialSetup()
{
// 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 removeAccount( const QString& accountId );
void setBookmarkPlaylist( const QString& guid );
QString bookmarkPlaylist() const;

View File

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

View File

@ -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
@ -42,7 +43,9 @@ namespace Tomahawk
namespace Accounts
{
class AccountModel;
}
class Account;
class AccountFactory;
}
}
class ProxyDialog : public QDialog
@ -95,21 +98,20 @@ private slots:
#endif
void openResolverConfig( const QString& );
/*
void sipItemClicked ( const QModelIndex& );
void openSipConfig( SipPlugin* );
void openAccountConfig( Tomahawk::Accounts::Account* );
void factoryActionTriggered ( bool );
void sipFactoryClicked( SipPluginFactory* );
void sipContextMenuRequest( const QPoint& );
void sipPluginDeleted( bool );
void sipPluginRowDeleted( bool );
*/
void accountFactoryClicked( Tomahawk::Accounts::AccountFactory* );
void accountContextMenuRequest( const QPoint& );
void accountDeleted( bool );
void onAccountRowDeleted( bool );
// dialog slots
void resolverConfigClosed( int value );
/*
void sipConfigClosed( int value );
void sipCreateConfigClosed( int value );
*/
void accountConfigClosed( int value );
void accountCreateConfigClosed( int value );
void updateScanOptionsView();
void changePage( QListWidgetItem*, QListWidgetItem* );
@ -117,8 +119,8 @@ private slots:
private:
void createIcons();
//void setupSipButtons();
//void handleSipPluginAdded( SipPlugin* p, bool added );
void setupAccountButtons();
void handleAccountAdded( Tomahawk::Accounts::Account* p, bool added );
Ui_StackedSettingsDialog* ui;

View File

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