diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index b8f88affb..9af7daf0c 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -306,6 +306,7 @@ set( libSources accounts/AccountManager.cpp accounts/Account.cpp accounts/AccountModel.cpp + accounts/AccountModelFilterProxy.cpp accounts/ResolverAccount.cpp sip/SipPlugin.cpp @@ -447,6 +448,7 @@ set( libHeaders accounts/Account.h accounts/AccountManager.h accounts/AccountModel.h + accounts/AccountModelFilterProxy.h accounts/ResolverAccount.h EchonestCatalogSynchronizer.h diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 73dffaded..36a22ebef 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -31,12 +31,14 @@ accountTypeToString( AccountType type ) switch ( type ) { case SipType: - return tr( "Friend Finders" ); + return QObject::tr( "Friend Finders" ); case ResolverType: - return tr( "Music Finders" ); + return QObject::tr( "Music Finders" ); case InfoType: - return tr( "Status Updaters" ); + return QObject::tr( "Status Updaters" ); } + + return QString(); } diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 73448fd2b..addc02184 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -188,5 +188,5 @@ public: Q_DECLARE_INTERFACE( Tomahawk::Accounts::AccountFactory, "tomahawk.AccountFactory/1.0" ) Q_DECLARE_METATYPE( QList< Tomahawk::Accounts::Account* > ) - +Q_DECLARE_METATYPE( Tomahawk::Accounts::AccountTypes ) #endif diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 44a16919b..98113352d 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -115,6 +115,8 @@ AccountModel::data( const QModelIndex& index, int role ) const return QVariant::fromValue< QList< Tomahawk::Accounts::Account* > >( node->accounts ); case HasConfig: return !node->accounts.isEmpty(); + case AccountTypeRole: + return QVariant::fromValue< AccountTypes >( node->factory->types() ); default: return QVariant(); } @@ -144,6 +146,8 @@ AccountModel::data( const QModelIndex& index, int role ) const return c.downloads(); case CanRateRole: return true; + case AccountTypeRole: + return QVariant::fromValue< AccountTypes >( AccountTypes( ResolverType ) ); case VersionRole: return c.version(); case UserHasRatedRole: @@ -207,6 +211,8 @@ AccountModel::data( const QModelIndex& index, int role ) const return Uninstalled; case CanRateRole: return false; + case AccountTypeRole: + return QVariant::fromValue< AccountTypes >( node->factory->types() ); default: return QVariant(); } @@ -233,6 +239,8 @@ AccountModel::data( const QModelIndex& index, int role ) const return Installed; case ChildrenOfFactoryRole: return QVariant::fromValue< QList< Tomahawk::Accounts::Account* > >( node->accounts ); + case AccountTypeRole: + return QVariant::fromValue< AccountTypes >( acct->types() ); default: return QVariant(); } diff --git a/src/libtomahawk/accounts/AccountModel.h b/src/libtomahawk/accounts/AccountModel.h index eaa676172..a1c6a2e31 100644 --- a/src/libtomahawk/accounts/AccountModel.h +++ b/src/libtomahawk/accounts/AccountModel.h @@ -57,6 +57,7 @@ public: // used by individual accounts AccountData = Qt::UserRole + 28, // raw plugin CanRateRole = Qt::UserRole + 32, + AccountTypeRole = Qt::UserRole + 33, CheckboxClickedRole = Qt::UserRole + 29, // the checkbox for this row was toggled AddAccountButtonRole = Qt::UserRole + 30, // the add account button diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp index faf14c7cb..ff3de4063 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp @@ -20,11 +20,13 @@ #include "AccountModel.h" + using namespace Tomahawk; using namespace Accounts; AccountModelFilterProxy::AccountModelFilterProxy( QObject* parent ) : QSortFilterProxyModel(parent) + , m_filterType( NoType ) { } @@ -35,10 +37,20 @@ AccountModelFilterProxy::filterAcceptsRow( int sourceRow, const QModelIndex& sou if ( m_filterType == NoType ) return true; - const QModeIndex idx = sourceParent.child( sourceRow, 0 ); - const AccountModel::RowType rowType = static_cast< AccountModel::RowType >( idx.data( AccountModel::RowTypeRole ).toInt() ); - + const QModelIndex idx = sourceModel()->index( sourceRow, 0, sourceParent ); + const AccountTypes types = static_cast< AccountTypes >( idx.data( AccountModel::AccountTypeRole ).value< AccountTypes >() ); + return types.testFlag( m_filterType ); } + +void +AccountModelFilterProxy::setFilterType( AccountType type ) +{ + if ( type == m_filterType ) + return; + + m_filterType = type; + invalidate(); +} diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.h b/src/libtomahawk/accounts/AccountModelFilterProxy.h index 02ebb161a..f22f8f4e9 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.h +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.h @@ -19,11 +19,15 @@ #ifndef ACCOUNTMODELFILTERPROXY_H #define ACCOUNTMODELFILTERPROXY_H -#include #include "Account.h" +#include "dllmacro.h" +#include -class AccountModelFilterProxy : public QSortFilterProxyModel +namespace Tomahawk { +namespace Accounts { + +class DLLEXPORT AccountModelFilterProxy : public QSortFilterProxyModel { Q_OBJECT public: @@ -38,4 +42,7 @@ private: Tomahawk::Accounts::AccountType m_filterType; }; +} + +} #endif // ACCOUNTMODELFILTERPROXY_H diff --git a/src/main.cpp b/src/main.cpp index f326cca78..10591e684 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,15 +81,6 @@ main( int argc, char *argv[] ) AEInstallEventHandler( 'GURL', 'GURL', h, 0, false ); #endif -/* // Unity hack taken from Clementine's main.cpp -#ifdef Q_OS_LINUX - // In 11.04 Ubuntu decided that the system tray should be reserved for certain - // whitelisted applications. Tomahawk will override this setting and insert - // itself into the list of whitelisted apps. - setenv( "QT_X11_NO_NATIVE_MENUBAR", "1", true ); - UbuntuUnityHack hack; -#endif*/ - TomahawkApp a( argc, argv ); // MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index e48c060d5..10a04fdf6 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -52,6 +52,7 @@ #include "accounts/AccountModel.h" #include "accounts/Account.h" #include "accounts/AccountManager.h" +#include #include "utils/logger.h" #include "AccountFactoryWrapper.h" @@ -113,8 +114,10 @@ SettingsDialog::SettingsDialog( QWidget *parent ) connect( accountDelegate, SIGNAL( update( QModelIndex ) ), ui->accountsView, SLOT( update( QModelIndex ) ) ); m_accountModel = new AccountModel( this ); + m_accountProxy = new AccountModelFilterProxy( m_accountModel ); + m_accountProxy->setSourceModel( m_accountModel ); - ui->accountsView->setModel( m_accountModel ); + ui->accountsView->setModel( m_accountProxy ); connect( m_accountModel, SIGNAL( createAccount( Tomahawk::Accounts::AccountFactory* ) ), this, SLOT( createAccountFromFactory( Tomahawk::Accounts::AccountFactory* ) ) ); @@ -427,12 +430,20 @@ SettingsDialog::onLastFmFinished() } +void +SettingsDialog::accountsFilterChanged( int ) +{ + AccountType filter = static_cast< AccountType >( ui->accountsFilterCombo->itemData( ui->accountsFilterCombo->currentIndex() ).toInt() ); + m_accountProxy->setFilterType( filter ); +} + + void SettingsDialog::openAccountConfig( Account* account, bool showDelete ) { if( account->configurationWidget() ) { -#if 0 +#ifndef Q_OS_MAC DelegateConfigWrapper dialog( account->configurationWidget(), QString("%1 Configuration" ).arg( account->accountFriendlyName() ), this ); dialog.setShowDelete( showDelete ); QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 544b1ff70..2c642e6e2 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -46,6 +46,7 @@ namespace Tomahawk class Account; class AccountFactory; class Account; +class AccountModelFilterProxy; } } @@ -114,6 +115,7 @@ private: ProxyDialog m_proxySettings; bool m_rejected; Tomahawk::Accounts::AccountModel* m_accountModel; + Tomahawk::Accounts::AccountModelFilterProxy* m_accountProxy; LoadingSpinner* m_sipSpinner; };