diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index c2074a4b1..5f7a4883f 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -172,6 +172,8 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, // Draw individual accounts and add account button for factories m_cachedButtonRects[ index ] = QRect(); + + bool canDelete = index.data( AccountModel::CanDeleteRole ) .toBool(); if ( rowType == Tomahawk::Accounts::AccountModel::TopLevelFactory ) { const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >(); @@ -224,6 +226,29 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, } } + else if ( canDelete ) + { + const QString btnText = tr( "Remove Account" ); + const int btnWidth = installMetrics.width( btnText ) + 2*PADDING; + QRect btnRect; + + if ( hasConfigWrench ) + btnRect = QRect( opt.rect.right() - PADDING - btnWidth, opt.rect.bottom() - installMetrics.height() - 3*PADDING, btnWidth, installMetrics.height() + 2*PADDING ); + else + btnRect = QRect( opt.rect.right() - PADDING - btnWidth, center - ( installMetrics.height() + 4 ) / 2, btnWidth, installMetrics.height() + 2*PADDING ); + + leftEdge = btnRect.left(); + m_cachedButtonRects[ index ] = btnRect; + + painter->save(); + painter->setPen( opt.palette.color( QPalette::Active, QPalette::AlternateBase ) ); + + drawRoundedButton( painter, btnRect, true ); + + painter->setFont( installFont ); + painter->drawText( btnRect, Qt::AlignCenter, btnText ); + painter->restore(); + } // Draw the title and description // title @@ -431,7 +456,7 @@ AccountDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QS else if ( m_cachedButtonRects.contains( index ) && m_cachedButtonRects[ index ].contains( me->pos() ) ) { // Install/create/etc button for this row - model->setData( index, true, AccountModel::AddAccountButtonRole ); + model->setData( index, true, AccountModel::CustomButtonRole ); } } @@ -475,7 +500,7 @@ AccountDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QS void -AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) const +AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const { QPainterPath btnPath; const int radius = 3; @@ -490,8 +515,16 @@ AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) co btnPath.lineTo( btnRect.left(), btnCenter ); QLinearGradient g; - g.setColorAt( 0, QColor(54, 127, 211) ); - g.setColorAt( 0.5, QColor(43, 104, 182) ); + if ( !red ) + { + g.setColorAt( 0, QColor(54, 127, 211) ); + g.setColorAt( 0.5, QColor(43, 104, 182) ); + } + else + { + g.setColorAt( 0, QColor(206, 63, 63) ); + g.setColorAt( 0.5, QColor(170, 52, 52) ); + } //painter->setPen( bg.darker() ); painter->fillPath( btnPath, g ); //painter->drawPath( btnPath ); @@ -505,8 +538,16 @@ AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) co btnPath.lineTo( btnRect.right(), btnCenter ); btnPath.lineTo( btnRect.left(), btnCenter ); - g.setColorAt( 0, QColor(34, 85, 159) ); - g.setColorAt( 0.5, QColor(35, 79, 147) ); + if ( !red ) + { + g.setColorAt( 0, QColor(34, 85, 159) ); + g.setColorAt( 0.5, QColor(35, 79, 147) ); + } + else + { + g.setColorAt( 0, QColor(150, 50, 50) ); + g.setColorAt( 0.5, QColor(130, 40, 40) ); + } painter->fillPath( btnPath, g ); } diff --git a/src/AccountDelegate.h b/src/AccountDelegate.h index 4cadd38c8..eab8cdf7a 100644 --- a/src/AccountDelegate.h +++ b/src/AccountDelegate.h @@ -47,7 +47,7 @@ signals: void openConfig( Tomahawk::Accounts::AccountFactory* ); private: - void drawRoundedButton( QPainter* painter, const QRect& buttonRect ) const; + void drawRoundedButton( QPainter* painter, const QRect& buttonRect, bool red = false ) const; // Returns new left edge int drawStatus( QPainter* painter, const QPointF& rightTopEdge, Account* acct, bool drawText = false ) const; void drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const; diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 8d13eba19..0cbc92ed1 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -207,6 +207,10 @@ AccountModel::data( const QModelIndex& index, int role ) const else return UniqueFactory; } + else if ( role == CanDeleteRole ) + { + return node->type == AccountModelNode::ManualResolverType; + } Account* acct = 0; if ( node->type == AccountModelNode::ManualResolverType ) @@ -349,12 +353,23 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role } // The install/create/remove/etc button was clicked. Handle it properly depending on this item - if ( role == AddAccountButtonRole ) + if ( role == CustomButtonRole ) { - Q_ASSERT( node->type == AccountModelNode::FactoryType ); - // Make a new account of this factory type - emit createAccount( node->factory ); - return true; + if ( node->type == AccountModelNode::FactoryType ) + { + // Make a new account of this factory type + emit createAccount( node->factory ); + return true; + } + else if ( node->type == AccountModelNode::ManualResolverType ) + { + Q_ASSERT( node->resolverAccount ); + AccountManager::instance()->removeAccount( node->resolverAccount ); + + return true; + } + Q_ASSERT( false ); // Should not be here, only the above two types should have this button + return false; } diff --git a/src/libtomahawk/accounts/AccountModel.h b/src/libtomahawk/accounts/AccountModel.h index a1c6a2e31..491723d22 100644 --- a/src/libtomahawk/accounts/AccountModel.h +++ b/src/libtomahawk/accounts/AccountModel.h @@ -58,9 +58,10 @@ public: AccountData = Qt::UserRole + 28, // raw plugin CanRateRole = Qt::UserRole + 32, AccountTypeRole = Qt::UserRole + 33, + CanDeleteRole = Qt::UserRole + 34, CheckboxClickedRole = Qt::UserRole + 29, // the checkbox for this row was toggled - AddAccountButtonRole = Qt::UserRole + 30, // the add account button + CustomButtonRole = Qt::UserRole + 30, // the add account or remove account button // Used by factories ChildrenOfFactoryRole = Qt::UserRole + 31 diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index f3cf4a594..899f087ea 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -20,6 +20,7 @@ #define RESOLVERACCOUNT_H #include "accounts/Account.h" +#include "dllmacro.h" namespace Tomahawk { @@ -27,7 +28,7 @@ class ExternalResolverGui; namespace Accounts { -class ResolverAccountFactory : public AccountFactory +class DLLEXPORT ResolverAccountFactory : public AccountFactory { Q_OBJECT public: @@ -51,7 +52,7 @@ public: * * Contains the resolver* that is it wrapping */ -class ResolverAccount : public Account +class DLLEXPORT ResolverAccount : public Account { Q_OBJECT public: diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 10a04fdf6..0fe591af7 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -53,6 +53,7 @@ #include "accounts/Account.h" #include "accounts/AccountManager.h" #include +#include #include "utils/logger.h" #include "AccountFactoryWrapper.h" @@ -119,7 +120,9 @@ SettingsDialog::SettingsDialog( QWidget *parent ) ui->accountsView->setModel( m_accountProxy ); + connect( ui->installFromFileBtn, SIGNAL( clicked( bool ) ), this, SLOT( installFromFile() ) ); connect( m_accountModel, SIGNAL( createAccount( Tomahawk::Accounts::AccountFactory* ) ), this, SLOT( createAccountFromFactory( Tomahawk::Accounts::AccountFactory* ) ) ); + connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), ui->accountsView, SLOT( scrollToBottom() ) ); ui->accountsFilterCombo->addItem( tr( "All" ), Accounts::NoType ); ui->accountsFilterCombo->addItem( accountTypeToString( SipType ), SipType ); @@ -606,6 +609,25 @@ SettingsDialog::handleAccountAdded( Account* account, bool added ) } +void +SettingsDialog::installFromFile() +{ + const QString resolver = QFileDialog::getOpenFileName( this, tr( "Install resolver from file" ), TomahawkSettings::instance()->scriptDefaultPath() ); + + if( !resolver.isEmpty() ) + { + Account* acct = ResolverAccountFactory::createFromPath( resolver, false ); + AccountManager::instance()->addAccount( acct ); + TomahawkSettings::instance()->addAccount( acct->accountId() ); + AccountManager::instance()->enableAccount( acct ); + + + QFileInfo resolverAbsoluteFilePath( resolver ); + TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() ); + } +} + + void SettingsDialog::requiresRestart() { diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 2c642e6e2..05bd3ba58 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -99,6 +99,8 @@ private slots: void accountConfigDelete(); void accountCreateConfigClosed( int value ); + void installFromFile(); + void updateScanOptionsView(); void changePage( QListWidgetItem*, QListWidgetItem* );