Commit 26222c9b authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: MLModel: rework menu signaling

(see previous commit)
parent 240e4ec4
...@@ -509,6 +509,64 @@ QString MLModel::getURI( const QModelIndex &index ) const ...@@ -509,6 +509,64 @@ QString MLModel::getURI( const QModelIndex &index ) const
return QString(); return QString();
} }
void MLModel::actionSlot( QAction *action )
{
char *uri = NULL, *path = NULL;
QString name;
QStringList mrls;
QModelIndex index;
bool ok;
playlist_item_t *p_item;
actionsContainerType a = action->data().value<actionsContainerType>();
switch ( a.action )
{
case actionsContainerType::ACTION_PLAY:
play( a.indexes.first() );
break;
case actionsContainerType::ACTION_ADDTOPLAYLIST:
break;
case actionsContainerType::ACTION_INFO:
if( a.indexes.first().isValid() )
{
input_item_t* p_input = getItem( a.indexes.first() )->inputItem();
MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
mid->setParent( PlaylistDialog::getInstance( p_intf ),
Qt::Dialog );
mid->show();
}
break;
case actionsContainerType::ACTION_STREAM:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0], false );
break;
case actionsContainerType::ACTION_EXPLORE:
break;
case actionsContainerType::ACTION_SAVE:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0] );
break;
case actionsContainerType::ACTION_ADDNODE:
break;
case actionsContainerType::ACTION_REMOVE:
doDelete( a.indexes );
break;
case actionsContainerType::ACTION_SORT:
break;
}
}
QModelIndex MLModel::rootIndex() const QModelIndex MLModel::rootIndex() const
{ {
// FIXME // FIXME
...@@ -535,18 +593,36 @@ bool MLModel::isCurrentItem( const QModelIndex &index, playLocation where ) cons ...@@ -535,18 +593,36 @@ bool MLModel::isCurrentItem( const QModelIndex &index, playLocation where ) cons
return false; return false;
} }
bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ) bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &selectionlist )
{ {
current_selection = list; QModelIndexList callerAsList;
current_index = index; callerAsList << ( index.isValid() ? index : QModelIndex() );
#define ADD_MENU_ENTRY( icon, title, act, data ) \
action = menu.addAction( icon, title ); \
container.action = act; \
container.indexes = data; \
action->setData( QVariant::fromValue( container ) )
/* */
QMenu menu; QMenu menu;
QAction *action;
VLCModel::actionsContainerType container;
if( index.isValid() ) if( index.isValid() )
{ {
menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) ); ADD_MENU_ENTRY( QIcon( ":/menu/play" ), qtr(I_POP_PLAY),
menu.addAction( QIcon( ":/menu/stream" ), container.ACTION_PLAY, callerAsList );
qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) ); ADD_MENU_ENTRY( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM),
menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) ); container.ACTION_STREAM, selectionlist );
ADD_MENU_ENTRY( QIcon(), qtr(I_POP_SAVE),
container.ACTION_SAVE, selectionlist );
ADD_MENU_ENTRY( QIcon( ":/menu/info" ), qtr(I_POP_INFO),
container.ACTION_INFO, callerAsList );
menu.addSeparator(); menu.addSeparator();
} }
...@@ -559,8 +635,8 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode ...@@ -559,8 +635,8 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
if( index.isValid() ) if( index.isValid() )
{ {
menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ), ADD_MENU_ENTRY( QIcon( ":/buttons/playlist/playlist_remove" ), qtr(I_POP_DEL),
qtr(I_POP_DEL), this, SLOT( popupDel() ) ); container.ACTION_REMOVE, selectionlist );
menu.addSeparator(); menu.addSeparator();
} }
if( !menu.isEmpty() ) if( !menu.isEmpty() )
...@@ -570,53 +646,18 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode ...@@ -570,53 +646,18 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
else return false; else return false;
} }
void MLModel::popupPlay() QStringList MLModel::selectedURIs( QModelIndexList *current_selection )
{
play( current_index );
}
void MLModel::popupDel()
{
doDelete( current_selection );
}
void MLModel::popupInfo()
{
MLItem *item = static_cast< MLItem* >( current_index.internalPointer() );
input_item_t* p_input = ml_CreateInputItem( p_ml, item->id() );
MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
mid->setParent( PlaylistDialog::getInstance( p_intf ),
Qt::Dialog );
mid->show();
}
QStringList MLModel::selectedURIs()
{ {
QStringList list; QStringList list;
for( int i = 0; i < current_selection.count(); i++ ) for( int i = 0; i < current_selection->count(); i++ )
{ {
QModelIndex idx = current_selection.value(i); QModelIndex idx = current_selection->value(i);
MLItem *item = static_cast< MLItem* >( idx.internalPointer() ); MLItem *item = static_cast< MLItem* >( idx.internalPointer() );
list.append( QString( item->getUri().toString() ) ); list.append( QString( item->getUri().toString() ) );
} }
return list; return list;
} }
void MLModel::popupStream()
{
QStringList mrls = selectedURIs();
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0], false );
}
void MLModel::popupSave()
{
QStringList mrls = selectedURIs();
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0] );
}
QModelIndex MLModel::getIndexByMLID( int id ) const QModelIndex MLModel::getIndexByMLID( int id ) const
{ {
for( int i = 0; i < rowCount( ); i++ ) for( int i = 0; i < rowCount( ); i++ )
......
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
void clear(); void clear();
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void play( const QModelIndex &idx ); void play( const QModelIndex &idx );
QStringList selectedURIs(); QStringList selectedURIs( QModelIndexList * );
virtual QString getURI( const QModelIndex &index ) const; virtual QString getURI( const QModelIndex &index ) const;
virtual QModelIndex rootIndex() const; virtual QModelIndex rootIndex() const;
virtual bool isTree() const; virtual bool isTree() const;
...@@ -105,13 +105,7 @@ public: ...@@ -105,13 +105,7 @@ public:
public slots: public slots:
void activateItem( const QModelIndex &index ); void activateItem( const QModelIndex &index );
virtual void actionSlot( QAction *action );
protected slots:
void popupDel();
void popupPlay();
void popupInfo();
void popupStream();
void popupSave();
protected: protected:
void remove( MLItem *item ); void remove( MLItem *item );
...@@ -126,8 +120,6 @@ private: ...@@ -126,8 +120,6 @@ private:
QList< MLItem* > items; QList< MLItem* > items;
media_library_t* p_ml; media_library_t* p_ml;
QModelIndex current_index;
QModelIndexList current_selection;
}; };
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment