mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
work towards integrating resolvers in accounts refactor
This commit is contained in:
@@ -76,9 +76,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
|||||||
diagnosticsdialog.cpp
|
diagnosticsdialog.cpp
|
||||||
configdelegatebase.cpp
|
configdelegatebase.cpp
|
||||||
AccountDelegate.cpp
|
AccountDelegate.cpp
|
||||||
resolverconfigdelegate.cpp
|
|
||||||
settingslistdelegate.cpp
|
settingslistdelegate.cpp
|
||||||
resolversmodel.cpp
|
|
||||||
tomahawkwindow.cpp
|
tomahawkwindow.cpp
|
||||||
LoadXSPFDialog.cpp
|
LoadXSPFDialog.cpp
|
||||||
)
|
)
|
||||||
@@ -127,10 +125,8 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
|||||||
settingsdialog.h
|
settingsdialog.h
|
||||||
diagnosticsdialog.h
|
diagnosticsdialog.h
|
||||||
configdelegatebase.h
|
configdelegatebase.h
|
||||||
resolverconfigdelegate.h
|
|
||||||
AccountDelegate.h
|
AccountDelegate.h
|
||||||
settingslistdelegate.h
|
settingslistdelegate.h
|
||||||
resolversmodel.h
|
|
||||||
delegateconfigwrapper.h
|
delegateconfigwrapper.h
|
||||||
tomahawkwindow.h
|
tomahawkwindow.h
|
||||||
LoadXSPFDialog.h
|
LoadXSPFDialog.h
|
||||||
|
@@ -40,6 +40,8 @@ class ACCOUNTDLLEXPORT XmppAccountFactory : public AccountFactory
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES( Tomahawk::Accounts::AccountFactory )
|
Q_INTERFACES( Tomahawk::Accounts::AccountFactory )
|
||||||
|
|
||||||
|
// for settings access
|
||||||
|
friend class XmppConfigWidget;
|
||||||
public:
|
public:
|
||||||
XmppAccountFactory() {}
|
XmppAccountFactory() {}
|
||||||
virtual ~XmppAccountFactory() {}
|
virtual ~XmppAccountFactory() {}
|
||||||
@@ -76,12 +78,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
QWeakPointer< QWidget > m_configWidget; // so the google wrapper can change the config dialog a bit
|
QWeakPointer< QWidget > m_configWidget; // so the google wrapper can change the config dialog a bit
|
||||||
QWeakPointer< XmppSipPlugin > m_xmppSipPlugin;
|
QWeakPointer< XmppSipPlugin > m_xmppSipPlugin;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
// for settings access
|
|
||||||
friend class XmppConfigWidget;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -308,6 +308,7 @@ set( libSources
|
|||||||
accounts/AccountManager.cpp
|
accounts/AccountManager.cpp
|
||||||
accounts/Account.cpp
|
accounts/Account.cpp
|
||||||
accounts/AccountModel.cpp
|
accounts/AccountModel.cpp
|
||||||
|
accounts/ResolverAccount.cpp
|
||||||
|
|
||||||
sip/SipPlugin.cpp
|
sip/SipPlugin.cpp
|
||||||
sip/SipHandler.cpp
|
sip/SipHandler.cpp
|
||||||
@@ -439,6 +440,7 @@ set( libHeaders
|
|||||||
accounts/Account.h
|
accounts/Account.h
|
||||||
accounts/AccountManager.h
|
accounts/AccountManager.h
|
||||||
accounts/AccountModel.h
|
accounts/AccountModel.h
|
||||||
|
accounts/ResolverAccount.h
|
||||||
|
|
||||||
EchonestCatalogSynchronizer.h
|
EchonestCatalogSynchronizer.h
|
||||||
|
|
||||||
|
@@ -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
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
#include "resolver.h"
|
#include "resolver.h"
|
||||||
|
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ public slots:
|
|||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(); // if config widget was added/removed
|
void changed(); // if config widget was added/removed, name changed, etc
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setFilePath( const QString& path ) { m_filePath = path; }
|
void setFilePath( const QString& path ) { m_filePath = path; }
|
||||||
|
@@ -113,7 +113,7 @@ public:
|
|||||||
void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
||||||
void setTypes( AccountTypes types );
|
void setTypes( AccountTypes types );
|
||||||
|
|
||||||
virtual void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all the settings held in the config file for this account instance
|
* Removes all the settings held in the config file for this account instance
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "sourcelist.h"
|
#include "sourcelist.h"
|
||||||
|
#include "ResolverAccount.h"
|
||||||
|
|
||||||
#include <QtCore/QLibrary>
|
#include <QtCore/QLibrary>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
@@ -53,6 +54,10 @@ AccountManager::AccountManager( QObject *parent )
|
|||||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
|
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
|
||||||
|
|
||||||
loadPluginFactories( findPluginFactories() );
|
loadPluginFactories( findPluginFactories() );
|
||||||
|
|
||||||
|
// We include the resolver factory manually, not in a plugin
|
||||||
|
ResolverAccountFactory* f = new ResolverAccountFactory();
|
||||||
|
m_accountFactories[ f->factoryId() ] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,13 +175,40 @@ AccountManager::loadPluginFactory( const QString& path )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AccountManager::enableAccount( Account* account )
|
||||||
|
{
|
||||||
|
if ( account->isAuthenticated() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
account->authenticate();
|
||||||
|
|
||||||
|
account->setEnabled( true );
|
||||||
|
m_enabledAccounts << account;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AccountManager::disableAccount( Account* account )
|
||||||
|
{
|
||||||
|
if ( !account->isAuthenticated() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
account->deauthenticate();
|
||||||
|
account->setEnabled( false );
|
||||||
|
m_enabledAccounts.removeAll( account );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountManager::connectAll()
|
AccountManager::connectAll()
|
||||||
{
|
{
|
||||||
foreach( Account* acc, m_accounts )
|
foreach( Account* acc, m_accounts )
|
||||||
{
|
{
|
||||||
if ( acc->types() & Accounts::SipType && acc->sipPlugin() )
|
acc->authenticate();
|
||||||
acc->sipPlugin()->connectPlugin();
|
m_enabledAccounts << acc;
|
||||||
|
// if ( acc->types() & Accounts::SipType && acc->sipPlugin() )
|
||||||
|
// acc->sipPlugin()->connectPlugin();
|
||||||
|
|
||||||
}
|
}
|
||||||
m_connected = true;
|
m_connected = true;
|
||||||
@@ -186,9 +218,10 @@ AccountManager::connectAll()
|
|||||||
void
|
void
|
||||||
AccountManager::disconnectAll()
|
AccountManager::disconnectAll()
|
||||||
{
|
{
|
||||||
foreach( Account* acc, m_connectedAccounts )
|
foreach( Account* acc, m_enabledAccounts )
|
||||||
acc->sipPlugin()->disconnectPlugin();
|
acc->deauthenticate();
|
||||||
|
|
||||||
|
m_enabledAccounts.clear();
|
||||||
SourceList::instance()->removeAllRemote();
|
SourceList::instance()->removeAllRemote();
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
}
|
}
|
||||||
@@ -224,9 +257,8 @@ void
|
|||||||
AccountManager::initSIP()
|
AccountManager::initSIP()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO;
|
tDebug() << Q_FUNC_INFO;
|
||||||
foreach( Account* account, accounts( Tomahawk::Accounts::SipType ) )
|
foreach( Account* account, accounts() )
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "adding plugin " << account->accountId();
|
|
||||||
hookupAndEnable( account, true );
|
hookupAndEnable( account, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +332,8 @@ void
|
|||||||
AccountManager::hookupAndEnable( Account* account, bool startup )
|
AccountManager::hookupAndEnable( Account* account, bool startup )
|
||||||
{
|
{
|
||||||
SipPlugin* p = account->sipPlugin();
|
SipPlugin* p = account->sipPlugin();
|
||||||
SipHandler::instance()->hookUpPlugin( p );
|
if ( p )
|
||||||
|
SipHandler::instance()->hookUpPlugin( p );
|
||||||
|
|
||||||
if ( account->enabled() && ( !startup || account->autoConnect() ) )
|
if ( account->enabled() && ( !startup || account->autoConnect() ) )
|
||||||
{
|
{
|
||||||
@@ -363,4 +396,4 @@ AccountManager::onStateChanged( Account::ConnectionState state )
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
@@ -47,6 +47,9 @@ public:
|
|||||||
void loadFromConfig();
|
void loadFromConfig();
|
||||||
void initSIP();
|
void initSIP();
|
||||||
|
|
||||||
|
void enableAccount( Account* account );
|
||||||
|
void disableAccount( Account* account );
|
||||||
|
|
||||||
QList< AccountFactory* > factories() const { return m_accountFactories.values(); }
|
QList< AccountFactory* > factories() const { return m_accountFactories.values(); }
|
||||||
bool hasPluginWithFactory( const QString& factory ) const;
|
bool hasPluginWithFactory( const QString& factory ) const;
|
||||||
AccountFactory* factoryForAccount( Account* account ) const;
|
AccountFactory* factoryForAccount( Account* account ) const;
|
||||||
|
@@ -84,10 +84,12 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
|
|||||||
Account* account = accounts[ index.row() ];
|
Account* account = accounts[ index.row() ];
|
||||||
|
|
||||||
if( state == Qt::Checked && !account->enabled() ) {
|
if( state == Qt::Checked && !account->enabled() ) {
|
||||||
account->setEnabled( true );
|
AccountManager::instance()->enableAccount( account );
|
||||||
} else if( state == Qt::Unchecked ) {
|
} else if( state == Qt::Unchecked ) {
|
||||||
account->setEnabled( false );
|
AccountManager::instance()->disableAccount( account );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
account->sync();
|
||||||
dataChanged( index, index );
|
dataChanged( index, index );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -40,7 +40,6 @@ public:
|
|||||||
enum Roles {
|
enum Roles {
|
||||||
AccountName = Qt::UserRole + 15,
|
AccountName = Qt::UserRole + 15,
|
||||||
AccountIcon = Qt::UserRole + 16,
|
AccountIcon = Qt::UserRole + 16,
|
||||||
HeadlineText = Qt::UserRole + 17,
|
|
||||||
AccountTypeRole = Qt::UserRole + 19,
|
AccountTypeRole = Qt::UserRole + 19,
|
||||||
ConnectionStateRole = Qt::UserRole + 20,
|
ConnectionStateRole = Qt::UserRole + 20,
|
||||||
HasConfig = Qt::UserRole + 21,
|
HasConfig = Qt::UserRole + 21,
|
||||||
|
@@ -64,7 +64,10 @@ Pipeline::~Pipeline()
|
|||||||
m_running = false;
|
m_running = false;
|
||||||
|
|
||||||
// stop script resolvers
|
// stop script resolvers
|
||||||
qDeleteAll( m_scriptResolvers );
|
foreach ( QWeakPointer< ExternalResolver > r, m_scriptResolvers )
|
||||||
|
if ( !r.isNull() )
|
||||||
|
r.data()->deleteLater();
|
||||||
|
|
||||||
m_scriptResolvers.clear();
|
m_scriptResolvers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +136,7 @@ Pipeline::addScriptResolver( const QString& path, bool start )
|
|||||||
if ( !res )
|
if ( !res )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_scriptResolvers << res;
|
m_scriptResolvers << QWeakPointer< ExternalResolver >( res );
|
||||||
if ( start )
|
if ( start )
|
||||||
res->start();
|
res->start();
|
||||||
|
|
||||||
@@ -147,10 +150,10 @@ Pipeline::addScriptResolver( const QString& path, bool start )
|
|||||||
void
|
void
|
||||||
Pipeline::stopScriptResolver( const QString& path )
|
Pipeline::stopScriptResolver( const QString& path )
|
||||||
{
|
{
|
||||||
foreach ( ExternalResolver* res, m_scriptResolvers )
|
foreach ( QWeakPointer< ExternalResolver > res, m_scriptResolvers )
|
||||||
{
|
{
|
||||||
if ( res->filePath() == path )
|
if ( res.data()->filePath() == path )
|
||||||
res->stop();
|
res.data()->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,18 +161,18 @@ Pipeline::stopScriptResolver( const QString& path )
|
|||||||
void
|
void
|
||||||
Pipeline::removeScriptResolver( const QString& scriptPath )
|
Pipeline::removeScriptResolver( const QString& scriptPath )
|
||||||
{
|
{
|
||||||
ExternalResolver* r = 0;
|
QWeakPointer< ExternalResolver > r;
|
||||||
foreach ( ExternalResolver* res, m_scriptResolvers )
|
foreach ( QWeakPointer< ExternalResolver > res, m_scriptResolvers )
|
||||||
{
|
{
|
||||||
if ( res->filePath() == scriptPath )
|
if ( res.data()->filePath() == scriptPath )
|
||||||
r = res;
|
r = res;
|
||||||
}
|
}
|
||||||
m_scriptResolvers.removeAll( r );
|
m_scriptResolvers.removeAll( r );
|
||||||
|
|
||||||
if ( r )
|
if ( !r.isNull() )
|
||||||
{
|
{
|
||||||
r->stop();
|
r.data()->stop();
|
||||||
r->deleteLater();
|
r.data()->deleteLater();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,10 +180,10 @@ Pipeline::removeScriptResolver( const QString& scriptPath )
|
|||||||
ExternalResolver*
|
ExternalResolver*
|
||||||
Pipeline::resolverForPath( const QString& scriptPath )
|
Pipeline::resolverForPath( const QString& scriptPath )
|
||||||
{
|
{
|
||||||
foreach ( ExternalResolver* res, m_scriptResolvers )
|
foreach ( QWeakPointer< ExternalResolver > res, m_scriptResolvers )
|
||||||
{
|
{
|
||||||
if ( res->filePath() == scriptPath )
|
if ( res.data()->filePath() == scriptPath )
|
||||||
return res;
|
return res.data();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,7 @@ public:
|
|||||||
Tomahawk::ExternalResolver* addScriptResolver( const QString& scriptPath, bool start = true );
|
Tomahawk::ExternalResolver* addScriptResolver( const QString& scriptPath, bool start = true );
|
||||||
void stopScriptResolver( const QString& scriptPath );
|
void stopScriptResolver( const QString& scriptPath );
|
||||||
void removeScriptResolver( const QString& scriptPath );
|
void removeScriptResolver( const QString& scriptPath );
|
||||||
QList< Tomahawk::ExternalResolver* > scriptResolvers() const { return m_scriptResolvers; }
|
QList< QWeakPointer< ExternalResolver > > scriptResolvers() const { return m_scriptResolvers; }
|
||||||
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
|
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
|
||||||
|
|
||||||
void addResolver( Resolver* r );
|
void addResolver( Resolver* r );
|
||||||
@@ -106,7 +106,7 @@ private:
|
|||||||
int decQIDState( const Tomahawk::query_ptr& query );
|
int decQIDState( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
QList< Resolver* > m_resolvers;
|
QList< Resolver* > m_resolvers;
|
||||||
QList< Tomahawk::ExternalResolver* > m_scriptResolvers;
|
QList< QWeakPointer<Tomahawk::ExternalResolver> > m_scriptResolvers;
|
||||||
QList< ResolverFactoryFunc > m_resolverFactories;
|
QList< ResolverFactoryFunc > m_resolverFactories;
|
||||||
QMap< QID, bool > m_qidsTimeout;
|
QMap< QID, bool > m_qidsTimeout;
|
||||||
QMap< QID, unsigned int > m_qidsState;
|
QMap< QID, unsigned int > m_qidsState;
|
||||||
|
@@ -342,6 +342,8 @@ ScriptResolver::doSetup( const QVariantMap& m )
|
|||||||
|
|
||||||
if ( !m_stopped )
|
if ( !m_stopped )
|
||||||
Tomahawk::Pipeline::instance()->addResolver( this );
|
Tomahawk::Pipeline::instance()->addResolver( this );
|
||||||
|
|
||||||
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -255,8 +255,34 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
|||||||
|
|
||||||
remove( sipPlugin );
|
remove( sipPlugin );
|
||||||
}
|
}
|
||||||
setValue( "accounts/allaccounts", accounts );
|
|
||||||
remove( "sip" );
|
remove( "sip" );
|
||||||
|
|
||||||
|
// Migrate all resolvers from old resolvers settings to new accounts system
|
||||||
|
const QStringList allResolvers = value( "script/resolvers" ).toStringList();
|
||||||
|
const QStringList enabledResolvers = value( "script/loadedresolvers" ).toStringList();
|
||||||
|
|
||||||
|
foreach ( const QString& resolver, allResolvers )
|
||||||
|
{
|
||||||
|
const QString accountKey = QString( "resolveraccount_%1" ).arg( QUuid::createUuid().toString().mid( 1, 8 ) );
|
||||||
|
accounts << accountKey;
|
||||||
|
|
||||||
|
beginGroup( "accounts/" + accountKey );
|
||||||
|
setValue( "enabled", enabledResolvers.contains( resolver ) == true );
|
||||||
|
setValue( "autoconnect", true );
|
||||||
|
setValue( "types", QStringList() << "ResolverType" );
|
||||||
|
|
||||||
|
QVariantHash configuration;
|
||||||
|
configuration[ "path" ] = resolver;
|
||||||
|
setValue( "configuration", configuration );
|
||||||
|
|
||||||
|
endGroup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
remove( "script/resolvers" );
|
||||||
|
remove( "script/loadedresolvers" );
|
||||||
|
|
||||||
|
setValue( "accounts/allaccounts", accounts );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
//template <typename T> class QSharedPointer;
|
//template <typename T> class QSharedPointer;
|
||||||
|
|
||||||
@@ -69,6 +70,9 @@ namespace Tomahawk
|
|||||||
InfoSystemMode
|
InfoSystemMode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ExternalResolver;
|
||||||
|
typedef boost::function<Tomahawk::ExternalResolver*(QString)> ResolverFactoryFunc;
|
||||||
|
|
||||||
}; // ns
|
}; // ns
|
||||||
|
|
||||||
typedef int AudioErrorCode;
|
typedef int AudioErrorCode;
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include "resolverconfigdelegate.h"
|
#include "resolverconfigdelegate.h"
|
||||||
|
|
||||||
#include "resolversmodel.h"
|
// #include "resolversmodel.h"
|
||||||
#include "ExternalResolverGui.h"
|
#include "ExternalResolverGui.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@@ -1,251 +0,0 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://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
|
|
||||||
* 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 "resolversmodel.h"
|
|
||||||
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
#include "tomahawksettings.h"
|
|
||||||
#include "tomahawkapp.h"
|
|
||||||
#include "ExternalResolverGui.h"
|
|
||||||
#include "pipeline.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "AtticaManager.h"
|
|
||||||
#include "utils/logger.h"
|
|
||||||
|
|
||||||
ResolversModel::ResolversModel( QObject* parent )
|
|
||||||
: QAbstractListModel( parent )
|
|
||||||
{
|
|
||||||
addInstalledResolvers();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ResolversModel::~ResolversModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
|
||||||
ResolversModel::data( const QModelIndex& index, int role ) const
|
|
||||||
{
|
|
||||||
if( !index.isValid() || !hasIndex( index.row(), index.column(), QModelIndex() ) )
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->scriptResolvers().at( index.row() );
|
|
||||||
Tomahawk::ExternalResolverGui* res = qobject_cast< Tomahawk::ExternalResolverGui* >( r );
|
|
||||||
Q_ASSERT(res); // this is part of the gui, so there should be no non-gui resolvers
|
|
||||||
switch( role )
|
|
||||||
{
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case ResolversModel::ResolverName:
|
|
||||||
return res->name();
|
|
||||||
case ResolversModel::ResolverPath:
|
|
||||||
return res->filePath();
|
|
||||||
case ResolversModel::HasConfig:
|
|
||||||
return res->configUI() != 0;
|
|
||||||
case ResolversModel::ErrorState:
|
|
||||||
return res->error();
|
|
||||||
case Qt::CheckStateRole:
|
|
||||||
return res->running() ? Qt::Checked : Qt::Unchecked;
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return res->filePath();
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ResolversModel::setData( const QModelIndex& index, const QVariant& value, int role )
|
|
||||||
{
|
|
||||||
if ( !hasIndex( index.row(), index.column(), QModelIndex() ) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->scriptResolvers().at( index.row() );
|
|
||||||
if ( r && r->error() == Tomahawk::ExternalResolver::FileNotFound ) // give it a shot to see if the user manually fixed paths
|
|
||||||
{
|
|
||||||
r->reload();
|
|
||||||
|
|
||||||
if( r->error() == Tomahawk::ExternalResolver::FileNotFound ) // Nope, no luck. Doesn't exist on disk, don't let user mess with it
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if ( !r && !QFile::exists( r->filePath() ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( role == Qt::CheckStateRole )
|
|
||||||
{
|
|
||||||
Qt::CheckState state = static_cast< Qt::CheckState >( value.toInt() );
|
|
||||||
|
|
||||||
if ( state == Qt::Checked && !r->running() ) {
|
|
||||||
r->start();
|
|
||||||
}
|
|
||||||
else if ( state == Qt::Unchecked )
|
|
||||||
{
|
|
||||||
r->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit dataChanged( index, index );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
ResolversModel::rowCount( const QModelIndex& parent ) const
|
|
||||||
{
|
|
||||||
Q_UNUSED( parent );
|
|
||||||
return Tomahawk::Pipeline::instance()->scriptResolvers().count();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
ResolversModel::columnCount(const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
Q_UNUSED( parent );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::ItemFlags
|
|
||||||
ResolversModel::flags( const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::addResolver( const QString& resolver, bool enable )
|
|
||||||
{
|
|
||||||
const int count = rowCount( QModelIndex() );
|
|
||||||
beginInsertRows( QModelIndex(), count, count );
|
|
||||||
Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->addScriptResolver( resolver, enable );
|
|
||||||
Tomahawk::ExternalResolverGui* res = qobject_cast< Tomahawk::ExternalResolverGui* >( r );
|
|
||||||
Q_ASSERT(res); // this is part of the gui, so there should be no non-gui resolvers
|
|
||||||
connect( res, SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
|
||||||
endInsertRows();
|
|
||||||
|
|
||||||
if ( res->configUI() )
|
|
||||||
emit openConfig( res->filePath() );
|
|
||||||
else
|
|
||||||
m_waitingForLoad << resolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::atticaResolverInstalled( const QString& resolverId )
|
|
||||||
{
|
|
||||||
#ifdef LIBATTICA_FOUND
|
|
||||||
Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->resolverForPath( AtticaManager::instance()->pathFromId( resolverId ) );
|
|
||||||
if ( !r )
|
|
||||||
return;
|
|
||||||
const int idx = Tomahawk::Pipeline::instance()->scriptResolvers().indexOf( r );
|
|
||||||
if ( idx >= 0 )
|
|
||||||
{
|
|
||||||
beginInsertRows( QModelIndex(), idx, idx );
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::removeResolver( const QString& resolver )
|
|
||||||
{
|
|
||||||
const int idx = Tomahawk::Pipeline::instance()->scriptResolvers().indexOf( Tomahawk::Pipeline::instance()->resolverForPath( resolver ) );
|
|
||||||
if ( idx < 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
beginRemoveRows( QModelIndex(), idx, idx );
|
|
||||||
Tomahawk::Pipeline::instance()->removeScriptResolver( resolver );
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::resolverChanged()
|
|
||||||
{
|
|
||||||
Tomahawk::ExternalResolver* res = qobject_cast< Tomahawk::ExternalResolver* >( sender() );
|
|
||||||
Q_ASSERT( res );
|
|
||||||
|
|
||||||
if ( Tomahawk::Pipeline::instance()->scriptResolvers().contains( res ) )
|
|
||||||
{
|
|
||||||
qDebug() << "Got resolverChanged signal, does it have a config UI yet?" << qobject_cast< Tomahawk::ExternalResolverGui* >(res)->configUI();
|
|
||||||
const QModelIndex idx = index( Tomahawk::Pipeline::instance()->scriptResolvers().indexOf( res ), 0, QModelIndex() );
|
|
||||||
emit dataChanged( idx, idx );
|
|
||||||
|
|
||||||
if ( m_waitingForLoad.contains( res->filePath() ) )
|
|
||||||
{
|
|
||||||
m_waitingForLoad.remove( res->filePath() );
|
|
||||||
emit openConfig( res->filePath() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::addInstalledResolvers()
|
|
||||||
{
|
|
||||||
QList< QDir > pluginDirs;
|
|
||||||
|
|
||||||
QDir appDir( qApp->applicationDirPath() );
|
|
||||||
QDir libDir( CMAKE_INSTALL_PREFIX "/lib" );
|
|
||||||
QDir libexecDir( CMAKE_INSTALL_FULL_LIBEXECDIR );
|
|
||||||
|
|
||||||
QDir lib64Dir( appDir );
|
|
||||||
lib64Dir.cdUp();
|
|
||||||
lib64Dir.cd( "lib64" );
|
|
||||||
|
|
||||||
pluginDirs << appDir << libDir << lib64Dir << libexecDir;
|
|
||||||
foreach ( const QDir& pluginDir, pluginDirs )
|
|
||||||
{
|
|
||||||
qDebug() << "Checking directory for resolvers:" << pluginDir;
|
|
||||||
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*_tomahawkresolver*", QDir::Files ) ){
|
|
||||||
if ( fileName.contains( "_tomahawkresolver" ) ) {
|
|
||||||
const QString path = pluginDir.absoluteFilePath( fileName );
|
|
||||||
bool found = false;
|
|
||||||
foreach ( Tomahawk::ExternalResolver* res, Tomahawk::Pipeline::instance()->scriptResolvers() )
|
|
||||||
{
|
|
||||||
if ( res->filePath() == path )
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
if ( !found ) {
|
|
||||||
Tomahawk::Pipeline::instance()->addScriptResolver( path, false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ResolversModel::saveScriptResolvers()
|
|
||||||
{
|
|
||||||
QStringList enabled, all;
|
|
||||||
foreach ( Tomahawk::ExternalResolver* res, Tomahawk::Pipeline::instance()->scriptResolvers() )
|
|
||||||
{
|
|
||||||
all << res->filePath();
|
|
||||||
if ( res->running() )
|
|
||||||
enabled << res->filePath();
|
|
||||||
}
|
|
||||||
TomahawkSettings::instance()->setAllScriptResolvers( all );
|
|
||||||
TomahawkSettings::instance()->setEnabledScriptResolvers( enabled );
|
|
||||||
}
|
|
@@ -1,64 +0,0 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://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
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef RESOLVERSMODEL_H
|
|
||||||
#define RESOLVERSMODEL_H
|
|
||||||
|
|
||||||
#include <QModelIndex>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QSet>
|
|
||||||
|
|
||||||
class ResolversModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
enum Roles {
|
|
||||||
ResolverName = Qt::UserRole + 15,
|
|
||||||
ResolverPath = Qt::UserRole + 16,
|
|
||||||
HasConfig = Qt::UserRole + 17,
|
|
||||||
ErrorState = Qt::UserRole + 18
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit ResolversModel( QObject* parent = 0 );
|
|
||||||
virtual ~ResolversModel();
|
|
||||||
|
|
||||||
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
|
|
||||||
virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
|
|
||||||
virtual int columnCount( const QModelIndex& parent ) const;
|
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
||||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
|
||||||
|
|
||||||
void addResolver( const QString& resolver, bool enable = false );
|
|
||||||
void atticaResolverInstalled ( const QString& resolverId );
|
|
||||||
void removeResolver( const QString& resolver );
|
|
||||||
|
|
||||||
void saveScriptResolvers();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void openConfig( const QString& filePath );
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void resolverChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addInstalledResolvers();
|
|
||||||
QSet<QString> m_waitingForLoad;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // RESOLVERSMODEL_H
|
|
@@ -44,8 +44,6 @@
|
|||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
#include "resolver.h"
|
#include "resolver.h"
|
||||||
#include "ExternalResolverGui.h"
|
#include "ExternalResolverGui.h"
|
||||||
#include "resolverconfigdelegate.h"
|
|
||||||
#include "resolversmodel.h"
|
|
||||||
#include "scanmanager.h"
|
#include "scanmanager.h"
|
||||||
#include "settingslistdelegate.h"
|
#include "settingslistdelegate.h"
|
||||||
#include "AccountDelegate.h"
|
#include "AccountDelegate.h"
|
||||||
@@ -77,7 +75,6 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
|||||||
, m_proxySettings( this )
|
, m_proxySettings( this )
|
||||||
, m_rejected( false )
|
, m_rejected( false )
|
||||||
, m_accountModel( 0 )
|
, m_accountModel( 0 )
|
||||||
, m_resolversModel( 0 )
|
|
||||||
, m_sipSpinner( 0 )
|
, m_sipSpinner( 0 )
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
@@ -183,13 +180,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
|||||||
|
|
||||||
// SCRIPT RESOLVER
|
// SCRIPT RESOLVER
|
||||||
ui->removeScript->setEnabled( false );
|
ui->removeScript->setEnabled( false );
|
||||||
ResolverConfigDelegate* del = new ResolverConfigDelegate( this );
|
|
||||||
connect( del, SIGNAL( openConfig( QString ) ), SLOT( openResolverConfig( QString ) ) );
|
|
||||||
ui->scriptList->setItemDelegate( del );
|
|
||||||
m_resolversModel = new ResolversModel( this );
|
|
||||||
ui->scriptList->setModel( m_resolversModel );
|
|
||||||
ui->scriptList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
ui->scriptList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||||
connect( m_resolversModel, SIGNAL( openConfig( QString ) ), SLOT( openResolverConfig( QString ) ) );
|
|
||||||
|
|
||||||
#ifdef LIBATTICA_FOUND
|
#ifdef LIBATTICA_FOUND
|
||||||
connect( ui->getMoreResolvers, SIGNAL( clicked() ), this, SLOT( getMoreResolvers() ) );
|
connect( ui->getMoreResolvers, SIGNAL( clicked() ), this, SLOT( getMoreResolvers() ) );
|
||||||
@@ -242,8 +233,6 @@ SettingsDialog::~SettingsDialog()
|
|||||||
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
|
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
|
||||||
s->setLastFmPassword( ui->lineEditLastfmPassword->text() );
|
s->setLastFmPassword( ui->lineEditLastfmPassword->text() );
|
||||||
|
|
||||||
m_resolversModel->saveScriptResolvers();
|
|
||||||
|
|
||||||
s->applyChanges();
|
s->applyChanges();
|
||||||
s->sync();
|
s->sync();
|
||||||
}
|
}
|
||||||
@@ -485,14 +474,13 @@ SettingsDialog::onLastFmFinished()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void
|
void
|
||||||
SettingsDialog::addScriptResolver()
|
SettingsDialog::addScriptResolver()
|
||||||
{
|
{
|
||||||
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() );
|
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() );
|
||||||
if( !resolver.isEmpty() )
|
if( !resolver.isEmpty() )
|
||||||
{
|
{
|
||||||
m_resolversModel->addResolver( resolver, true );
|
|
||||||
|
|
||||||
QFileInfo resolverAbsoluteFilePath = resolver;
|
QFileInfo resolverAbsoluteFilePath = resolver;
|
||||||
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
||||||
@@ -512,7 +500,7 @@ SettingsDialog::removeScriptResolver()
|
|||||||
#endif
|
#endif
|
||||||
m_resolversModel->removeResolver( resolver );
|
m_resolversModel->removeResolver( resolver );
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -532,18 +520,18 @@ SettingsDialog::getMoreResolvers()
|
|||||||
|
|
||||||
|
|
||||||
#ifdef LIBATTICA_FOUND
|
#ifdef LIBATTICA_FOUND
|
||||||
void
|
// void
|
||||||
SettingsDialog::atticaResolverInstalled( const QString& resolverId )
|
// SettingsDialog::atticaResolverInstalled( const QString& resolverId )
|
||||||
{
|
// {
|
||||||
m_resolversModel->atticaResolverInstalled( resolverId );
|
// m_resolversModel->atticaResolverInstalled( resolverId );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
void
|
// void
|
||||||
SettingsDialog::atticaResolverUninstalled ( const QString& resolverId )
|
// SettingsDialog::atticaResolverUninstalled ( const QString& resolverId )
|
||||||
{
|
// {
|
||||||
m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) );
|
// m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) );
|
||||||
}
|
// }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -87,15 +87,9 @@ private slots:
|
|||||||
void testLastFmLogin();
|
void testLastFmLogin();
|
||||||
void onLastFmFinished();
|
void onLastFmFinished();
|
||||||
|
|
||||||
void addScriptResolver();
|
|
||||||
void scriptSelectionChanged();
|
void scriptSelectionChanged();
|
||||||
void removeScriptResolver();
|
|
||||||
void getMoreResolvers();
|
void getMoreResolvers();
|
||||||
void getMoreResolversFinished( int );
|
void getMoreResolversFinished( int );
|
||||||
#ifdef LIBATTICA_FOUND
|
|
||||||
void atticaResolverInstalled( const QString& );
|
|
||||||
void atticaResolverUninstalled( const QString& );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void openResolverConfig( const QString& );
|
void openResolverConfig( const QString& );
|
||||||
|
|
||||||
@@ -129,7 +123,6 @@ private:
|
|||||||
ProxyDialog m_proxySettings;
|
ProxyDialog m_proxySettings;
|
||||||
bool m_rejected;
|
bool m_rejected;
|
||||||
Tomahawk::Accounts::AccountModel* m_accountModel;
|
Tomahawk::Accounts::AccountModel* m_accountModel;
|
||||||
ResolversModel* m_resolversModel;
|
|
||||||
LoadingSpinner* m_sipSpinner;
|
LoadingSpinner* m_sipSpinner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user