mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
Finish adding filter imlpementation
This commit is contained in:
parent
132460b797
commit
40041f5c1e
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -19,11 +19,15 @@
|
||||
#ifndef ACCOUNTMODELFILTERPROXY_H
|
||||
#define ACCOUNTMODELFILTERPROXY_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "Account.h"
|
||||
#include "dllmacro.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "accounts/AccountModel.h"
|
||||
#include "accounts/Account.h"
|
||||
#include "accounts/AccountManager.h"
|
||||
#include <accounts/AccountModelFilterProxy.h>
|
||||
#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 );
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user