diff --git a/src/libtomahawk/sip/SipModel.cpp b/src/libtomahawk/sip/SipModel.cpp index 98417aa33..8ac36cbcb 100644 --- a/src/libtomahawk/sip/SipModel.cpp +++ b/src/libtomahawk/sip/SipModel.cpp @@ -30,10 +30,12 @@ SipModel::SipModel( QObject* parent ) connect( SipHandler::instance(), SIGNAL( pluginAdded( SipPlugin* ) ), this, SLOT( pluginAdded( SipPlugin* ) ) ); connect( SipHandler::instance(), SIGNAL( pluginRemoved( SipPlugin* ) ), this, SLOT( pluginRemoved( SipPlugin* ) ) ); + // TODO disable inline factories for now + /* foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) { if( f->isCreatable() ) m_factories << f; - } + } */ } @@ -158,7 +160,7 @@ int SipModel::rowCount( const QModelIndex& parent ) const { if( !parent.isValid() ) // invalid root node - return SipHandler::instance()->allPlugins().size() + 1; + return SipHandler::instance()->allPlugins().size() /* TODO inline factories disabled + 1*/; if( parent.isValid() && !parent.parent().isValid() ) { // top level item if( parent.row() == SipHandler::instance()->allPlugins().count() ) {// last row, this is the factory return m_factories.count(); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index dc665b11f..dc5d9a538 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -84,12 +84,15 @@ SettingsDialog::SettingsDialog( QWidget *parent ) SipConfigDelegate* sipdel = new SipConfigDelegate( this ); ui->accountsView->setItemDelegate( sipdel ); ui->accountsView->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( ui->accountsView, SIGNAL( clicked( QModelIndex ) ), this, SLOT( sipItemClicked( QModelIndex ) ) ); connect( sipdel, SIGNAL( openConfig( SipPlugin* ) ), this, SLOT( openSipConfig( SipPlugin* ) ) ); connect( ui->accountsView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( sipContextMenuRequest( QPoint ) ) ); m_sipModel = new SipModel( this ); ui->accountsView->setModel( m_sipModel ); + setupSipButtons(); + ui->staticHostName->setText( s->externalHostname() ); ui->staticPort->setValue( s->externalPort() ); @@ -220,6 +223,24 @@ SettingsDialog::createIcons() connect( ui->listWidget, SIGNAL( currentItemChanged( QListWidgetItem* ,QListWidgetItem* ) ), this, SLOT( changePage( QListWidgetItem*, QListWidgetItem* ) ) ); } +void +SettingsDialog::setupSipButtons() +{ + foreach( SipPluginFactory* f, SipHandler::instance()->pluginFactories() ) { + if( !f->isCreatable() ) + 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->removeSipButton, SIGNAL( clicked( bool ) ), this, SLOT( sipPluginDeleted( bool ) ) ); +} + + void SettingsDialog::changePage( QListWidgetItem* current, QListWidgetItem* previous ) { @@ -481,6 +502,19 @@ SettingsDialog::openSipConfig( SipPlugin* p ) } } +void +SettingsDialog::factoryActionTriggered( bool ) +{ + Q_ASSERT( sender() && qobject_cast< QAction* >( sender() ) ); + + QAction* a = qobject_cast< QAction* >( sender() ); + Q_ASSERT( qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ) ); + + SipPluginFactory* f = qobject_cast< SipPluginFactory* >( a->property( "factory" ).value< QObject* >() ); + sipFactoryClicked( f ); +} + + void SettingsDialog::sipFactoryClicked( SipPluginFactory* factory ) { @@ -518,14 +552,29 @@ SettingsDialog::sipContextMenuRequest( const QPoint& p ) QList< QAction* > acts; acts << new QAction( tr( "Delete Account" ), this ); acts.first()->setProperty( "sipplugin", idx.data( SipModel::SipPluginData ) ); - connect( acts.first(), SIGNAL( triggered( bool ) ), this, SLOT( sipPluginDeleted( bool ) ) ); + connect( acts.first(), SIGNAL( triggered( bool ) ), this, SLOT( sipPluginRowDeleted( bool ) ) ); QMenu::exec( acts, ui->accountsView->mapToGlobal( p ) ); } } void -SettingsDialog::sipPluginDeleted( bool ) +SettingsDialog::sipPluginRowDeleted( bool ) { SipPlugin* p = qobject_cast< SipPlugin* >( qobject_cast< QAction* >( sender() )->property( "sipplugin" ).value< QObject* >() ); SipHandler::instance()->removeSipPlugin( p ); } + +void +SettingsDialog::sipPluginDeleted( bool ) +{ + QModelIndexList indexes = ui->accountsView->selectionModel()->selectedIndexes(); + // if it's an account, allow to delete + foreach( const QModelIndex& idx, indexes ) + { + if( idx.isValid() && !idx.data( SipModel::FactoryRole ).toBool() && !idx.data( SipModel::FactoryItemRole ).toBool() ) + { + SipPlugin* p = qobject_cast< SipPlugin* >( idx.data( SipModel::SipPluginData ).value< QObject* >() ); + SipHandler::instance()->removeSipPlugin( p ); + } + } +} diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 80dc648a2..00f1eb4e0 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -81,14 +81,17 @@ private slots: void openResolverConfig( const QString& ); void sipItemClicked ( const QModelIndex& ); void openSipConfig( SipPlugin* ); + void factoryActionTriggered ( bool ); void sipFactoryClicked( SipPluginFactory* ); void sipContextMenuRequest( const QPoint& ); void sipPluginDeleted( bool ); + void sipPluginRowDeleted( bool ); void changePage( QListWidgetItem*, QListWidgetItem* ); private: void createIcons(); + void setupSipButtons(); Ui_StackedSettingsDialog* ui; diff --git a/src/stackedsettingsdialog.ui b/src/stackedsettingsdialog.ui index de0b868cd..2bb477cca 100644 --- a/src/stackedsettingsdialog.ui +++ b/src/stackedsettingsdialog.ui @@ -100,7 +100,7 @@ - 1 + 0 @@ -112,10 +112,7 @@ Accounts - - - 2 - + @@ -124,26 +121,75 @@ - - - 0 - - - false - - - false - - - true - - - true - - - false - - + + + + + 0 + + + false + + + false + + + true + + + true + + + false + + + + + + + + + ... + + + + :/data/images/list-add.png:/data/images/list-add.png + + + QToolButton::InstantPopup + + + + + + + ... + + + + :/data/images/list-remove.png:/data/images/list-remove.png + + + QToolButton::DelayedPopup + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + @@ -157,6 +203,12 @@ + + + 50 + false + + Local Music Information