1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 10:19:41 +01:00

Account properly saves itself now and can reload a saved account

This commit is contained in:
Jeff Mitchell 2011-11-05 12:22:57 -04:00
parent 8e2721236f
commit 13cfda6e1e
12 changed files with 103 additions and 36 deletions

View File

@ -33,7 +33,7 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
${QTWEETLIB_INCLUDE_DIR}
)
qt4_wrap_cpp( tomahawkOAuthTwitterMoc ${tomahawkOAuthTwitterSources} )
qt4_wrap_cpp( tomahawkOAuthTwitterMoc ${tomahawkOAuthTwitterHeaders} )
add_library( tomahawk_oauth_twitter SHARED ${tomahawkOAuthTwitterSources} ${tomahawkOAuthTwitterMoc} )
qt4_wrap_cpp( twitterAccountMoc ${twitterAccountHeaders} )
qt4_wrap_ui( twitterAccountUI_H ${twitterAccountUI} )
@ -57,6 +57,7 @@ target_link_libraries( tomahawk_oauth_twitter
target_link_libraries( tomahawk_account_twitter
tomahawk_oauth_twitter
tomahawk_siptwitter
${TOMAHAWK_LIBRARIES}
${QTWEETLIB_LIBRARIES}
${QT_LIBRARIES}

View File

@ -45,7 +45,7 @@ TwitterAccount::TwitterAccount( const QString &accountId )
setAccountServiceName( "Twitter" );
QSet< AccountType > types;
types << InfoType;
types << InfoType << SipType;
setTypes( types );
m_configWidget = QWeakPointer< TwitterConfigWidget >( new TwitterConfigWidget( this, 0 ) );

View File

@ -62,7 +62,7 @@ public:
bool canSelfAuthenticate() { return false; }
bool authenticate() { return false; }
bool isAuthenticated() { return m_isAuthenticated; }
bool isAuthenticated() const { return m_isAuthenticated; }
Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; }
SipPlugin* sipPlugin();

View File

@ -38,6 +38,7 @@ set( libSources
EchonestCatalogSynchronizer.cpp
accounts/accountmanager.cpp
accounts/account.cpp
sip/SipPlugin.cpp
sip/SipHandler.cpp

View File

@ -0,0 +1,64 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "account.h"
namespace Tomahawk
{
namespace Accounts
{
QWidget*
Account::configurationWidget()
{
return 0;
}
QWidget*
Account::aclWidget()
{
return 0;
}
QIcon
Account::icon() const
{
return QIcon();
}
bool
Account::authenticate()
{
return false;
}
bool
Account::isAuthenticated() const
{
return false;
}
}
}

View File

@ -80,7 +80,7 @@ public:
virtual QIcon icon() const = 0;
virtual bool authenticate() = 0; //if none needed, just return true
virtual bool isAuthenticated() = 0;
virtual bool isAuthenticated() const = 0;
virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() = 0;
virtual SipPlugin* sipPlugin() = 0;
@ -190,7 +190,7 @@ public:
virtual QIcon icon() const { return QIcon(); }
virtual bool isUnique() const { return false; }
virtual Account* createAccount( const QString& pluginId = QString() ) = 0;
virtual Account* createAccount( const QString& accountId = QString() ) = 0;
};
};

View File

@ -112,9 +112,9 @@ AccountManager::loadPluginFactories( const QStringList& paths )
QString
AccountManager::factoryFromId( const QString& pluginId ) const
AccountManager::factoryFromId( const QString& accountId ) const
{
return pluginId.split( "_" ).first();
return accountId.split( "_" ).first();
}
@ -143,21 +143,22 @@ AccountManager::loadPluginFactory( const QString& path )
void
AccountManager::loadFromConfig()
{
QStringList pluginIds = TomahawkSettings::instance()->accountPlugins();
QStringList accountIds = TomahawkSettings::instance()->accounts();
//FIXME: this is just for debugging
if ( pluginIds.isEmpty() )
if ( accountIds.isEmpty() )
{
Account* account = m_accountFactories[ "twitteraccount" ]->createAccount();
addAccountPlugin( account );
TomahawkSettings::instance()->addAccount( account->accountId() );
}
foreach( const QString& pluginId, pluginIds )
foreach( const QString& accountId, accountIds )
{
QString pluginFactory = factoryFromId( pluginId );
QString pluginFactory = factoryFromId( accountId );
if( m_accountFactories.contains( pluginFactory ) )
{
Account* account = loadPlugin( pluginId );
Account* account = loadPlugin( accountId );
addAccountPlugin( account );
}
}
@ -166,13 +167,13 @@ AccountManager::loadFromConfig()
Account*
AccountManager::loadPlugin( const QString& pluginId )
AccountManager::loadPlugin( const QString& accountId )
{
QString factoryName = factoryFromId( pluginId );
QString factoryName = factoryFromId( accountId );
Q_ASSERT( m_accountFactories.contains( factoryName ) );
Account* account = m_accountFactories[ factoryName ]->createAccount( pluginId );
Account* account = m_accountFactories[ factoryName ]->createAccount( accountId );
// caller responsible for calling pluginAdded() and hookupPlugin
return account;
@ -186,7 +187,7 @@ AccountManager::addAccountPlugin( Account* account )
foreach( AccountType type, account->types() )
m_accountsByAccountType[ type ].append( account );
//TODO:
//TODO:?
//emit pluginAdded( account );
}

View File

@ -49,8 +49,8 @@ public:
void loadFromConfig();
void loadPluginFactory( const QString &path );
void addAccountPlugin( Account* account );
Account* loadPlugin( const QString &pluginId );
QString factoryFromId( const QString& pluginId ) const;
Account* loadPlugin( const QString &accountId );
QString factoryFromId( const QString& accountId ) const;
QList< Account* > getAccounts() { return m_accounts; };
QList< Account* > getAccounts( Tomahawk::Accounts::AccountType type ) { return m_accountsByAccountType[ type ]; }

View File

@ -693,34 +693,34 @@ TomahawkSettings::removeSipPlugin( const QString& pluginId )
QStringList
TomahawkSettings::accountPlugins() const
TomahawkSettings::accounts() const
{
return value( "accounts/allplugins", QStringList() ).toStringList();
return value( "accounts/allaccounts", QStringList() ).toStringList();
}
void
TomahawkSettings::setAccountPlugins( const QStringList& plugins )
TomahawkSettings::setAccounts( const QStringList& accountIds )
{
setValue( "accounts/allplugins", plugins );
setValue( "accounts/allaccounts", accountIds );
}
void
TomahawkSettings::addAccountPlugin( const QString& pluginId )
TomahawkSettings::addAccount( const QString& accountId )
{
QStringList list = accountPlugins();
list << pluginId;
setAccountPlugins( list );
QStringList list = accounts();
list << accountId;
setAccounts( list );
}
void
TomahawkSettings::removeAccountPlugin( const QString& pluginId )
TomahawkSettings::removeAccount( const QString& accountId )
{
QStringList list = accountPlugins();
list.removeAll( pluginId );
setAccountPlugins( list );
QStringList list = accounts();
list.removeAll( accountId );
setAccounts( list );
}

View File

@ -106,10 +106,10 @@ public:
void addSipPlugin( const QString& pluginId, bool enable = true );
void removeSipPlugin( const QString& pluginId );
void setAccountPlugins( const QStringList& plugins );
QStringList accountPlugins() const;
void addAccountPlugin( const QString& pluginId );
void removeAccountPlugin( const QString& pluginId );
void setAccounts( const QStringList& accountIds );
QStringList accounts() const;
void addAccount( const QString& accountId );
void removeAccount( const QString& accountId );
void setBookmarkPlaylist( const QString& guid );

View File

@ -33,7 +33,6 @@ ENDIF( WIN32 )
target_link_libraries( tomahawk_siptwitter
tomahawk_oauth_twitter
tomahawk_account_twitter
${TOMAHAWK_LIBRARIES}
${QTWEETLIB_LIBRARIES}
${QT_LIBRARIES}

View File

@ -510,6 +510,7 @@ TomahawkApp::initServent()
void
TomahawkApp::initSIP()
{
tDebug() << Q_FUNC_INFO;
foreach ( Tomahawk::Accounts::Account* account, Tomahawk::Accounts::AccountManager::instance()->getAccounts() )
{
tDebug() << Q_FUNC_INFO << "testing account with name " << account->accountServiceName();