1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-19 04:11:46 +02:00

disable inline factories and use +/- button for now

This commit is contained in:
Leo Franchi
2011-05-03 17:49:43 -04:00
parent 52c2fd2a5a
commit 63738b58c0
4 changed files with 135 additions and 29 deletions

View File

@@ -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();

View File

@@ -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 );
}
}
}

View File

@@ -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;

View File

@@ -100,7 +100,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="accountsPage">
<layout class="QVBoxLayout" name="verticalLayout_11">
@@ -112,10 +112,7 @@
<property name="title">
<string>Accounts</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>2</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@@ -124,26 +121,75 @@
</widget>
</item>
<item>
<widget class="QTreeView" name="accountsView">
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>false</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTreeView" name="accountsView">
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>false</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="addSipLayout">
<item>
<widget class="QToolButton" name="addSipButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/data/images/list-add.png</normaloff>:/data/images/list-add.png</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="removeSipButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/data/images/list-remove.png</normaloff>:/data/images/list-remove.png</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
@@ -157,6 +203,12 @@
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="title">
<string>Local Music Information</string>
</property>