diff --git a/src/GetNewStuffDelegate.cpp b/src/GetNewStuffDelegate.cpp index 1e1c5d381..a1a3409bd 100644 --- a/src/GetNewStuffDelegate.cpp +++ b/src/GetNewStuffDelegate.cpp @@ -111,28 +111,31 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio // Go from right edge now, stars, install button, and downloaded info // install / status button - AtticaManager::ResolverState state = static_cast< AtticaManager::ResolverState >( index.data( GetNewStuffModel::StateRole ).toInt() ); + GetNewStuffModel::ItemState state = static_cast< GetNewStuffModel::ItemState >( index.data( GetNewStuffModel::StateRole ).toInt() ); QString actionText; switch( state ) { - case AtticaManager::Uninstalled: + case GetNewStuffModel::Uninstalled: actionText = tr( "Install" ); break; - case AtticaManager::Installing: + case GetNewStuffModel::Installing: actionText = tr( "Installing" ); break; - case AtticaManager::Upgrading: + case GetNewStuffModel::Upgrading: actionText = tr( "Upgrading" ); break; - case AtticaManager::Failed: + case GetNewStuffModel::Failed: actionText = tr( "Failed" ); break; - case AtticaManager::Installed: + case GetNewStuffModel::Installed: actionText = tr( "Uninstall" ); break; - case AtticaManager::NeedsUpgrade: + case GetNewStuffModel::NeedsUpgrade: actionText = tr( "Upgrade" ); break; + case GetNewStuffModel::CanInstallMore: + actionText = tr( "Install Another" ); + break; } const int btnWidth = m_widestTextWidth + 7; diff --git a/src/GetNewStuffDialog.cpp b/src/GetNewStuffDialog.cpp index da3f0891f..b188a2f38 100644 --- a/src/GetNewStuffDialog.cpp +++ b/src/GetNewStuffDialog.cpp @@ -21,6 +21,9 @@ #include "ui_GetNewStuffDialog.h" #include "GetNewStuffDelegate.h" #include "GetNewStuffModel.h" +#include "tomahawksettings.h" + +#include GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) @@ -29,13 +32,13 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f ) { ui->setupUi( this ); - ui->listView->setModel( m_model ); - GetNewStuffDelegate* del = new GetNewStuffDelegate( ui->listView ); - connect( del, SIGNAL( update( QModelIndex ) ), ui->listView, SLOT( update( QModelIndex ) ) ); - ui->listView->setItemDelegate( del ); - ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); + ui->accountsList->setModel( m_model ); + GetNewStuffDelegate* del = new GetNewStuffDelegate( ui->accountsList ); + connect( del, SIGNAL( update( QModelIndex ) ), ui->accountsList, SLOT( update( QModelIndex ) ) ); + ui->accountsList->setItemDelegate( del ); + ui->accountsList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); - ui->listView->setMouseTracking( true ); + ui->accountsList->setMouseTracking( true ); setMinimumSize( 560, 350 ); @@ -43,8 +46,10 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f ) setMaximumSize( 560, 350 ); setSizeGripEnabled( false ); - ui->listView->setAttribute( Qt::WA_MacShowFocusRect, false ); + ui->accountsList->setAttribute( Qt::WA_MacShowFocusRect, false ); #endif + + connect( ui->installFromFileBtn, SIGNAL( clicked( bool ) ), this, SLOT( installFromFile() ) ); } @@ -52,3 +57,19 @@ GetNewStuffDialog::~GetNewStuffDialog() { delete ui; } + + +void +GetNewStuffDialog::installFromFile() +{ + QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() ); + +// m_resolversModel->addResolver( resolver, true ); + // TODO + if( !resolver.isEmpty() ) + { + + QFileInfo resolverAbsoluteFilePath = resolver; + TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() ); + } +} diff --git a/src/GetNewStuffDialog.h b/src/GetNewStuffDialog.h index a0e195a8d..3e63a66c1 100644 --- a/src/GetNewStuffDialog.h +++ b/src/GetNewStuffDialog.h @@ -33,6 +33,9 @@ public: explicit GetNewStuffDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ); ~GetNewStuffDialog(); +private slots: + void installFromFile(); + private: Ui::GetNewStuffDialog *ui; GetNewStuffModel* m_model; diff --git a/src/GetNewStuffDialog.ui b/src/GetNewStuffDialog.ui index 1686a8200..f844f82f4 100644 --- a/src/GetNewStuffDialog.ui +++ b/src/GetNewStuffDialog.ui @@ -7,7 +7,7 @@ 0 0 449 - 282 + 327 @@ -15,17 +15,41 @@ - + - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + Install from file... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/src/GetNewStuffModel.cpp b/src/GetNewStuffModel.cpp index 405ca968b..e80093cdf 100644 --- a/src/GetNewStuffModel.cpp +++ b/src/GetNewStuffModel.cpp @@ -20,32 +20,73 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" +#include "AtticaManager.h" +#include "accounts/AccountManager.h" #include #include -#include "AtticaManager.h" + +using namespace Tomahawk; +using namespace Accounts; GetNewStuffModel::GetNewStuffModel( QObject* parent ) : QAbstractListModel ( parent ) { - - if ( AtticaManager::instance()->resolversLoaded() ) - m_contentList = AtticaManager::instance()->resolvers(); - connect( AtticaManager::instance(), SIGNAL( resolversReloaded( Attica::Content::List ) ), this, SLOT( resolversReloaded( Attica::Content::List ) ) ); connect( AtticaManager::instance(), SIGNAL( resolverStateChanged( QString ) ), this, SLOT( resolverStateChanged( QString ) ) ); + loadData(); } GetNewStuffModel::~GetNewStuffModel() { } +void +GetNewStuffModel::loadData() +{ + foreach ( const QVariant& content, m_contentList ) + { + if ( !isAttica( content ) ) + { + AccountItem* item = content.value< GetNewStuffModel::AccountItem* >(); + delete item; + } + } + m_contentList.clear(); + + Attica::Content::List fromAttica = AtticaManager::instance()->resolvers(); + foreach ( const Attica::Content& content, fromAttica ) + m_contentList.append( QVariant::fromValue< Attica::Content >( content ) ); + + QList< AccountFactory* > factories = AccountManager::instance()->factories(); + QList< Account* > allAccounts = AccountManager::instance()->accounts(); + foreach ( AccountFactory* fac, factories ) + { + if ( !fac->allowUserCreation() ) + continue; + + AccountItem* item = new AccountItem; + item->factory = fac; + + foreach ( Account* acct, allAccounts ) + { + if ( AccountManager::instance()->factoryForAccount( acct ) == fac ) + item->alreadyExists = true; + else + item->alreadyExists = false; + } + + m_contentList.append( QVariant::fromValue< GetNewStuffModel::AccountItem* >( item ) ); + } +} + + void GetNewStuffModel::resolversReloaded( const Attica::Content::List& resolvers ) { beginResetModel(); - m_contentList = resolvers; + loadData(); endResetModel(); } @@ -54,7 +95,10 @@ GetNewStuffModel::resolverStateChanged( const QString& resolverId ) { for ( int i = 0; i < m_contentList.count(); i++ ) { - const Attica::Content resolver = m_contentList[ i ]; + if ( !isAttica( m_contentList.at( i ) ) ) + continue; + + const Attica::Content resolver = atticaFromItem( m_contentList.at( i ) ); if ( resolver.id() == resolverId ) { QModelIndex idx = index( i, 0, QModelIndex() ); @@ -70,33 +114,82 @@ GetNewStuffModel::data( const QModelIndex& index, int role ) const if ( !index.isValid() || !hasIndex( index.row(), index.column(), index.parent() ) ) return QVariant(); - Attica::Content resolver = m_contentList[ index.row() ]; - switch ( role ) + if ( isAttica( m_contentList.at( index.row() ) ) ) { - case Qt::DisplayRole: - return resolver.name(); - case Qt::DecorationRole: - return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) ); - case DownloadUrlRole: - // TODO - return QUrl(); - case RatingRole: - return resolver.rating() / 20; // rating is out of 100 - case DownloadCounterRole: - return resolver.downloads(); - case VersionRole: - return resolver.version(); - case DescriptionRole: - return resolver.description(); - case TypeRole: - return ResolverType; - case AuthorRole: - return resolver.author(); - case StateRole: - return (int)AtticaManager::instance()->resolverState( resolver ); - case UserHasRatedRole: - return AtticaManager::instance()->userHasRated( resolver ); + const Attica::Content resolver = atticaFromItem( m_contentList.at( index.row() ) ); + switch ( role ) + { + case Qt::DisplayRole: + return resolver.name(); + case Qt::DecorationRole: + return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) ); + case DownloadUrlRole: + // TODO + return QUrl(); + case RatingRole: + return resolver.rating() / 20; // rating is out of 100 + case DownloadCounterRole: + return resolver.downloads(); + case VersionRole: + return resolver.version(); + case DescriptionRole: + return resolver.description(); + case TypeRole: + return AtticaType; + case AuthorRole: + return resolver.author(); + case StateRole: + return (int)AtticaManager::instance()->resolverState( resolver ); + case UserHasRatedRole: + return AtticaManager::instance()->userHasRated( resolver ); + } } + else + { + // Account, not from Attica + AccountItem* item = accountFromItem( m_contentList.at( index.row() ) ); + Q_ASSERT( item ); + switch ( role ) + { + case Qt::DisplayRole: + return item->factory->prettyName(); + case Qt::DecorationRole: + return QVariant::fromValue< QPixmap >( item->factory->icon() ); + case RatingRole: + // TODO + return 3; +// return resolver.rating() / 20; // rating is out of 100 + case DownloadCounterRole: + // TODO + return 10; +// return resolver.downloads(); + case VersionRole: + return "1.0"; +// return resolver.version(); + case DescriptionRole: + return item->factory->description(); + case TypeRole: + return AccountType; + case AuthorRole: + return "Tomahawk Developers"; + case StateRole: + { + GetNewStuffModel::ItemState state = Uninstalled; + if ( item->factory->isUnique() && item->alreadyExists ) + state = Installed; + else if ( !item->factory->isUnique() && item->alreadyExists ) + state = CanInstallMore; + else if ( !item->alreadyExists ) + state = Uninstalled; + return (int)state; + } + case UserHasRatedRole: + // TODO + return true; +// return AtticaManager::instance()->userHasRated( resolver ); + } + } + return QVariant(); } @@ -114,43 +207,84 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int if ( !hasIndex( index.row(), index.column(), index.parent() ) ) return false; - - Attica::Content resolver = m_contentList[ index.row() ]; - AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver ); - if ( role == Qt::EditRole ) + if ( isAttica( m_contentList.at( index.row() ) ) ) { - switch( state ) + Attica::Content resolver = atticaFromItem( m_contentList.at( index.row() ) ); + AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver ); + if ( role == Qt::EditRole ) { - case AtticaManager::Uninstalled: - // install - AtticaManager::instance()->installResolver( resolver ); - break; - case AtticaManager::Installing: - case AtticaManager::Upgrading: - // Do nothing, busy - break; - case AtticaManager::Installed: - // Uninstall - AtticaManager::instance()->uninstallResolver( resolver ); - break; - case AtticaManager::NeedsUpgrade: - AtticaManager::instance()->upgradeResolver( resolver ); - break; - default: - //FIXME -- this handles e.g. Failed - break; - }; - } else if ( role == RatingRole ) - { - // For now only allow rating if a resolver is installed! - if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade ) - return false; - if ( AtticaManager::instance()->userHasRated( resolver ) ) - return false; - m_contentList[ index.row() ].setRating( value.toInt() * 20 ); - AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] ); + switch( state ) + { + case AtticaManager::Uninstalled: + // install + AtticaManager::instance()->installResolver( resolver ); + break; + case AtticaManager::Installing: + case AtticaManager::Upgrading: + // Do nothing, busy + break; + case AtticaManager::Installed: + // Uninstall + AtticaManager::instance()->uninstallResolver( resolver ); + break; + case AtticaManager::NeedsUpgrade: + AtticaManager::instance()->upgradeResolver( resolver ); + break; + default: + //FIXME -- this handles e.g. Failed + break; + }; + } else if ( role == RatingRole ) + { + // For now only allow rating if a resolver is installed! + if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade ) + return false; + if ( AtticaManager::instance()->userHasRated( resolver ) ) + return false; + resolver.setRating( value.toInt() * 20 ); + m_contentList[ index.row() ] = QVariant::fromValue< Attica::Content >( resolver ); + AtticaManager::instance()->uploadRating( resolver ); + } + emit dataChanged( index, index ); + } + else + { + AccountItem* item = accountFromItem( m_contentList.at( index.row() ) ); + if ( role == Qt::EditRole ) + { + // TODO + } + else if ( role == RatingRole ) + { + // TODO + } } - emit dataChanged( index, index ); return true; } + + +bool +GetNewStuffModel::isAttica( const QVariant& item ) const +{ + return qstrcmp( item.typeName(),"Attica::Content" ) == 0; +} + + +GetNewStuffModel::AccountItem* +GetNewStuffModel::accountFromItem( const QVariant& item ) const +{ + Q_ASSERT( !isAttica( item ) ); + + return item.value< GetNewStuffModel::AccountItem* >(); +} + + +Attica::Content +GetNewStuffModel::atticaFromItem( const QVariant& item ) const +{ + Q_ASSERT( isAttica( item ) ); + + return item.value< Attica::Content >(); + +} diff --git a/src/GetNewStuffModel.h b/src/GetNewStuffModel.h index 378057e1e..c2e21afba 100644 --- a/src/GetNewStuffModel.h +++ b/src/GetNewStuffModel.h @@ -19,14 +19,17 @@ #ifndef GETNEWSTUFFMODEL_H #define GETNEWSTUFFMODEL_H -#include +#include "accounts/Account.h" #include + +#include #include class GetNewStuffModel: public QAbstractListModel { Q_OBJECT + public: enum NewStuffRoles { // DisplayRole is title @@ -43,9 +46,26 @@ public: }; enum Types { - ResolverType = 0, + AtticaType = 0, + AccountType = 1 }; + enum ItemState { + Uninstalled = 0, + Installing, + Installed, + NeedsUpgrade, + Upgrading, + Failed, + CanInstallMore, // accounts that are not unique + }; + + // plz don't use me kthxbbq + typedef struct { + Tomahawk::Accounts::AccountFactory* factory; + bool alreadyExists; + } AccountItem; + explicit GetNewStuffModel( QObject* parent = 0 ); virtual ~GetNewStuffModel(); @@ -58,7 +78,14 @@ private slots: void resolverStateChanged( const QString& resolverId ); private: - Attica::Content::List m_contentList; + void loadData(); + bool isAttica( const QVariant& item ) const; + Attica::Content atticaFromItem( const QVariant& item ) const; + AccountItem* accountFromItem( const QVariant& item ) const; + + QVariantList m_contentList; }; +Q_DECLARE_METATYPE( GetNewStuffModel::AccountItem* ); + #endif // GETNEWSTUFFMODEL_H diff --git a/src/accounts/twitter/twitteraccount.h b/src/accounts/twitter/twitteraccount.h index 4746f9aae..d943b2591 100644 --- a/src/accounts/twitter/twitteraccount.h +++ b/src/accounts/twitter/twitteraccount.h @@ -46,6 +46,7 @@ public: QString prettyName() const { return "Twitter"; } QString factoryId() const { return "twitteraccount"; } + QString description() const { return tr( "Connect to your Twitter followers." ); } QPixmap icon() const { return QPixmap( ":/twitter-icon.png" ); } Account* createAccount( const QString& pluginId = QString() ); }; diff --git a/src/accounts/xmpp/googlewrapper/googlewrapper.h b/src/accounts/xmpp/googlewrapper/googlewrapper.h index fdb8fb0a0..833cf3be2 100644 --- a/src/accounts/xmpp/googlewrapper/googlewrapper.h +++ b/src/accounts/xmpp/googlewrapper/googlewrapper.h @@ -38,6 +38,7 @@ public: virtual QString prettyName() const { return "Google"; } virtual QString factoryId() const { return "googleaccount"; } + QString description() const { return tr( "Connect to GChat to find your friends" ); } virtual QPixmap icon() const; virtual Account* createAccount( const QString& pluginId ); }; diff --git a/src/accounts/xmpp/xmppaccount.h b/src/accounts/xmpp/xmppaccount.h index 905a869ff..77ba97904 100644 --- a/src/accounts/xmpp/xmppaccount.h +++ b/src/accounts/xmpp/xmppaccount.h @@ -47,6 +47,7 @@ public: virtual ~XmppAccountFactory() {} QString prettyName() const { return "XMPP (Jabber)"; } + QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); } QString factoryId() const { return "xmppaccount"; } QPixmap icon() const { return QPixmap( ":/xmpp-icon.png" ); } Account* createAccount( const QString& pluginId = QString() ); diff --git a/src/accounts/zeroconf/zeroconfaccount.h b/src/accounts/zeroconf/zeroconfaccount.h index 5f926a12a..726e5c5a2 100644 --- a/src/accounts/zeroconf/zeroconfaccount.h +++ b/src/accounts/zeroconf/zeroconfaccount.h @@ -39,6 +39,7 @@ public: virtual QString factoryId() const { return "zeroconfaccount"; } virtual QString prettyName() const { return "Local Network"; } + QString description() const { return tr( "Automatically connect to Tomahawks on the local network" ); } virtual bool isUnique() const { return true; } #ifndef ENABLE_HEADLESS virtual QPixmap icon() const; diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 7a92f30e8..9513b4839 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -165,10 +165,14 @@ public: virtual QString prettyName() const = 0; // internal name virtual QString factoryId() const = 0; + // description to be shown when user views a list of account types + virtual QString description() const = 0; // if the user can create multiple - virtual QPixmap icon() const { return QPixmap(); } virtual bool isUnique() const { return false; } + virtual QPixmap icon() const { return QPixmap(); } + virtual bool allowUserCreation() const { return true; } + virtual Account* createAccount( const QString& accountId = QString() ) = 0; }; diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index 8d77a83e0..228479de6 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -36,7 +36,9 @@ public: virtual Account* createAccount(const QString& accountId = QString()); virtual QString factoryId() const { return "resolveraccount"; } + virtual QString description() const { return QString(); } virtual QString prettyName() const { return QString(); } // Internal, not displayed + virtual bool allowUserCreation() const { return false; } }; /** diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 2000df4e0..2e26b7a43 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -61,14 +61,6 @@ using namespace Tomahawk; using namespace Accounts; -static QString -md5( const QByteArray& src ) -{ - QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); - return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); -} - - SettingsDialog::SettingsDialog( QWidget *parent ) : QDialog( parent ) , ui( new Ui_StackedSettingsDialog ) @@ -83,9 +75,6 @@ SettingsDialog::SettingsDialog( QWidget *parent ) TomahawkUtils::unmarginLayout( layout() ); ui->stackedWidget->setContentsMargins( 4, 4, 4, 0 ); - ui->addScript->setFixedWidth( 42 ); - ui->removeScript->setFixedWidth( ui->addScript->width() ); - ui->checkBoxReporter->setChecked( s->crashReporterEnabled() ); ui->checkBoxHttp->setChecked( s->httpEnabled() ); ui->checkBoxStaticPreferred->setChecked( s->preferStaticHostPort() ); @@ -123,6 +112,14 @@ SettingsDialog::SettingsDialog( QWidget *parent ) m_accountModel = new AccountModel( this ); ui->accountsView->setModel( m_accountModel ); + connect( ui->addNewServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( getMoreResolvers() ) ); + connect( ui->removeServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( accountDeleted( bool ) ) ); + + connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) ); + connect( AtticaManager::instance(), SIGNAL( resolverUninstalled( QString ) ), this, SLOT( accountUninstalled( QString ) ) ); + + connect( ui->accountsView->selectionModel(), SIGNAL( selectionChanged( QItemSelection,QItemSelection ) ), this, SLOT( accountsSelectionChanged() ) ); + if ( !Servent::instance()->isReady() ) { m_sipSpinner = new LoadingSpinner( ui->accountsView ); @@ -132,9 +129,6 @@ SettingsDialog::SettingsDialog( QWidget *parent ) ui->removeServiceBtn->setEnabled( false ); connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) ); } - - setupAccountButtons(); - ui->staticHostName->setText( s->externalHostname() ); ui->staticPort->setValue( s->externalPort() ); ui->proxyButton->setVisible( true ); @@ -178,18 +172,6 @@ SettingsDialog::SettingsDialog( QWidget *parent ) ui->pushButtonTestLastfmLogin->setVisible( false ); #endif - // SCRIPT RESOLVER - ui->removeScript->setEnabled( false ); - ui->scriptList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); - - connect( ui->getMoreResolvers, SIGNAL( clicked() ), this, SLOT( getMoreResolvers() ) ); - - connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( atticaResolverInstalled( QString ) ) ); - connect( AtticaManager::instance(), SIGNAL( resolverUninstalled( QString ) ), this, SLOT( atticaResolverUninstalled( QString ) ) ); - - connect( ui->scriptList->selectionModel(), SIGNAL( selectionChanged( QItemSelection,QItemSelection ) ), this, SLOT( scriptSelectionChanged() ) ); - connect( ui->addScript, SIGNAL( clicked( bool ) ), this, SLOT( addScriptResolver() ) ); - connect( ui->removeScript, SIGNAL( clicked( bool ) ), this, SLOT( removeScriptResolver() ) ); connect( ui->proxyButton, SIGNAL( clicked() ), SLOT( showProxySettings() ) ); connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( toggleUpnp(bool) ) ); connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) ); @@ -244,7 +226,7 @@ SettingsDialog::serventReady() { m_sipSpinner->fadeOut(); ui->addNewServiceBtn->setEnabled( true ); - ui->removeScript->setEnabled( true ); + ui->removeServiceBtn->setEnabled( true ); } @@ -310,27 +292,6 @@ SettingsDialog::createIcons() } -void -SettingsDialog::setupAccountButtons() -{ -// foreach( AccountFactory* f, AccountManager::instance()->factories() ) -// { -// if( f->isUnique() && AccountManager::instance()->hasPluginWithFactory( f->factoryId() ) ) -// { -// continue; -// } -// -// 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 ) ) ); -// } - - connect( ui->removeServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( accountDeleted( bool ) ) ); -} - - void SettingsDialog::changePage( QListWidgetItem* current, QListWidgetItem* previous ) { @@ -470,32 +431,6 @@ SettingsDialog::onLastFmFinished() #endif } -/* -void -SettingsDialog::addScriptResolver() -{ - QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() ); - if( !resolver.isEmpty() ) - { - - QFileInfo resolverAbsoluteFilePath = resolver; - TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() ); - } -} - - -void -SettingsDialog::removeScriptResolver() -{ - // only one selection - if( !ui->scriptList->selectionModel()->selectedIndexes().isEmpty() ) - { - QString resolver = ui->scriptList->selectionModel()->selectedIndexes().first().data( ResolversModel::ResolverPath ).toString(); - AtticaManager::instance()->uninstallResolver( resolver ); - m_resolversModel->removeResolver( resolver ); - } -}*/ - void SettingsDialog::getMoreResolvers() @@ -513,30 +448,30 @@ SettingsDialog::getMoreResolvers() } -// void -// SettingsDialog::atticaResolverInstalled( const QString& resolverId ) -// { +void +SettingsDialog::accountInstalled(Account* account) +{ // m_resolversModel->atticaResolverInstalled( resolverId ); -// } -// -// -// void -// SettingsDialog::atticaResolverUninstalled ( const QString& resolverId ) -// { -// m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) ); -// } +} void -SettingsDialog::scriptSelectionChanged() +SettingsDialog::accountUninstalled(const QString& acct) { - if( !ui->scriptList->selectionModel()->selectedIndexes().isEmpty() ) +// m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) ); +} + + +void +SettingsDialog::accountsSelectionChanged() +{ + if( !ui->accountsView->selectionModel()->selectedIndexes().isEmpty() ) { - ui->removeScript->setEnabled( true ); + ui->removeServiceBtn->setEnabled( true ); } else { - ui->removeScript->setEnabled( false ); + ui->addNewServiceBtn->setEnabled( false ); } } @@ -545,46 +480,7 @@ void SettingsDialog::getMoreResolversFinished( int ret ) { Q_UNUSED( ret ); -} - - -void -SettingsDialog::openResolverConfig( const QString& resolver ) -{ - Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->resolverForPath( resolver ); - Tomahawk::ExternalResolverGui* res = qobject_cast< Tomahawk::ExternalResolverGui* >( r ); - if( res && res->configUI() ) - { -#ifndef Q_WS_MAC - DelegateConfigWrapper dialog( res->configUI(), "Resolver Configuration", this ); - QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); - int ret = dialog.exec(); - if( !watcher.isNull() && ret == QDialog::Accepted ) - { - // send changed config to resolver - r->saveConfig(); - } -#else - // on osx a sheet needs to be non-modal - DelegateConfigWrapper* dialog = new DelegateConfigWrapper( res->configUI(), "Resolver Configuration", this, Qt::Sheet ); - dialog->setProperty( "resolver", QVariant::fromValue< QObject* >( res ) ); - connect( dialog, SIGNAL( finished( int ) ), this, SLOT( resolverConfigClosed( int ) ) ); - - dialog->show(); -#endif - } -} - - -void -SettingsDialog::resolverConfigClosed( int value ) -{ - if( value == QDialog::Accepted ) - { - DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() ); - Tomahawk::ExternalResolver* r = qobject_cast< Tomahawk::ExternalResolver* >( dialog->property( "resolver" ).value< QObject* >() ); - r->saveConfig(); - } + sender()->deleteLater(); } @@ -627,20 +523,7 @@ SettingsDialog::accountConfigClosed( int value ) void -SettingsDialog::factoryActionTriggered( bool ) -{ - Q_ASSERT( sender() && qobject_cast< QAction* >( sender() ) ); - - QAction* a = qobject_cast< QAction* >( sender() ); - Q_ASSERT( qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) ); - - AccountFactory* f = qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ); - accountFactoryClicked( f ); -} - - -void -SettingsDialog::accountFactoryClicked( AccountFactory* factory ) +SettingsDialog::createAccountFromFactory( AccountFactory* factory ) { //if exited with OK, create it, if not, delete it immediately! Account* account = factory->createAccount(); @@ -708,22 +591,6 @@ SettingsDialog::handleAccountAdded( Account* account, bool added ) TomahawkSettings::instance()->addAccount( account->accountId() ); AccountManager::instance()->addAccount( account ); AccountManager::instance()->hookupAndEnable( account ); - -// if ( f && f->isUnique() ) -// { -// // remove from actions list -// QAction* toremove = 0; -// foreach( QAction* a, ui->addSipButton->actions() ) -// { -// if( f == qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) ) -// { -// toremove = a; -// break; -// } -// } -// if ( toremove ) -// ui->addSipButton->removeAction( toremove ); -// } } else { @@ -741,7 +608,7 @@ SettingsDialog::accountContextMenuRequest( const QPoint& p ) if( idx.isValid() ) { QList< QAction* > acts; - acts << new QAction( tr( "Delete Account" ), this ); + acts << new QAction( tr( "Delete Service" ), this ); 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 ) ); @@ -754,18 +621,6 @@ SettingsDialog::onAccountRowDeleted( bool ) { 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 ); } @@ -780,18 +635,6 @@ SettingsDialog::accountDeleted( bool ) if( idx.isValid() ) { Account* account = qobject_cast< Account* >( idx.data( AccountModel::AccountData ).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 ); } } diff --git a/src/settingsdialog.h b/src/settingsdialog.h index b0a26a482..de2e948e1 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -45,6 +45,7 @@ namespace Tomahawk class AccountModel; class Account; class AccountFactory; +class Account; } } @@ -87,21 +88,18 @@ private slots: void testLastFmLogin(); void onLastFmFinished(); - void scriptSelectionChanged(); - void getMoreResolvers(); - void getMoreResolversFinished( int ); - - void openResolverConfig( const QString& ); - void openAccountConfig( Tomahawk::Accounts::Account* ); - void factoryActionTriggered ( bool ); - void accountFactoryClicked( Tomahawk::Accounts::AccountFactory* ); + void createAccountFromFactory( Tomahawk::Accounts::AccountFactory* ); void accountContextMenuRequest( const QPoint& ); void accountDeleted( bool ); void onAccountRowDeleted( bool ); - // dialog slots - void resolverConfigClosed( int value ); + void accountsSelectionChanged(); + void getMoreResolvers(); + void getMoreResolversFinished( int ); + + void accountInstalled( Tomahawk::Accounts::Account* account ); + void accountUninstalled( const QString& acct ); void accountConfigClosed( int value ); void accountCreateConfigClosed( int value ); @@ -115,7 +113,6 @@ private slots: private: void createIcons(); - void setupAccountButtons(); void handleAccountAdded( Tomahawk::Accounts::Account* p, bool added ); Ui_StackedSettingsDialog* ui; diff --git a/src/stackedsettingsdialog.ui b/src/stackedsettingsdialog.ui index b26f638b5..e0e1620f0 100644 --- a/src/stackedsettingsdialog.ui +++ b/src/stackedsettingsdialog.ui @@ -365,107 +365,6 @@ - - - - 0 - - - - - Script Resolvers - - - - 2 - - - - - Script resolvers search for a given track to make it playable. - - - - - - - Get more resolvers... - - - - - - - - - true - - - QAbstractItemView::SingleSelection - - - false - - - true - - - false - - - true - - - true - - - - - - - - - - - - - :/data/images/list-add.png:/data/images/list-add.png - - - - - - - - - - - :/data/images/list-remove.png:/data/images/list-remove.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - -