Commit 6d48203b authored by Jakob Leben's avatar Jakob Leben

qt4 playlist: make popup Add Node and Sort operate on parent

If playlist view was full with items it was hard/impossible to
add node to root if the action operated on right-clicked item.
Sort action follows the same style for consistence and practicality.
parent 8587991a
...@@ -925,63 +925,56 @@ void PLModel::search( const QString& search_text ) ...@@ -925,63 +925,56 @@ void PLModel::search( const QString& search_text )
/*********** Popup *********/ /*********** Popup *********/
void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
{ {
int i_id; int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
if( index.isValid() ) i_id = itemId( index );
else i_id = rootItem->i_id;
i_popup_column = index.column();
PL_LOCK; PL_LOCK;
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id ); playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
if( p_item ) if( !p_item )
{ {
i_popup_item = p_item->i_id; PL_UNLOCK; return;
i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1; }
bool node = p_item->i_children > -1; i_popup_item = index.isValid() ? p_item->i_id : -1;
bool tree = false; i_popup_parent = index.isValid() ?
if( node ) ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
{ ( p_item->i_id );
/* check whether we are in tree view */ i_popup_column = index.column();
playlist_item_t *p_up = p_item; /* check whether we are in tree view */
while( p_up ) bool tree = false;
{ playlist_item_t *p_up = p_item;
if ( p_up == p_playlist->p_root_category ) tree = true; while( p_up )
p_up = p_up->p_parent; {
} if ( p_up == p_playlist->p_root_category ) tree = true;
} p_up = p_up->p_parent;
PL_UNLOCK; }
PL_UNLOCK;
current_selection = list; current_selection = list;
QMenu *menu = new QMenu; QMenu *menu = new QMenu;
if( index.isValid() ) if( i_popup_item > -1 )
{ {
menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) ); menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) ); menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
menu->addSeparator(); menu->addSeparator();
menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) ); menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) ); menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
menu->addSeparator(); menu->addSeparator();
menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) ); menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
if( node ) menu->addSeparator();
{ QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
menu->addSeparator(); qfu( psz_column_title( metaColumn( index.column() ) ) ) );
QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") + sort_menu->addAction( qtr( "Ascending" ),
qfu( psz_column_title( metaColumn( index.column() ) ) ) ); this, SLOT( popupSortAsc() ) );
sort_menu->addAction( qtr( "Ascending" ), sort_menu->addAction( qtr( "Descending" ),
this, SLOT( popupSortAsc() ) ); this, SLOT( popupSortDesc() ) );
sort_menu->addAction( qtr( "Descending" ),
this, SLOT( popupSortDesc() ) );
}
}
if( node && tree )
menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
if( index.isValid() )
{
menu->addSeparator();
menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
}
menu->popup( point );
} }
else if( tree )
PL_UNLOCK; menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
if( i_popup_item > -1 )
{
menu->addSeparator();
menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
}
menu->popup( point );
} }
...@@ -1122,7 +1115,7 @@ void PLModel::popupAddNode() ...@@ -1122,7 +1115,7 @@ void PLModel::popupAddNode()
if( !ok || name.isEmpty() ) return; if( !ok || name.isEmpty() ) return;
PL_LOCK; PL_LOCK;
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
i_popup_item ); i_popup_parent );
if( p_item ) if( p_item )
{ {
playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL ); playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
...@@ -1132,12 +1125,12 @@ void PLModel::popupAddNode() ...@@ -1132,12 +1125,12 @@ void PLModel::popupAddNode()
void PLModel::popupSortAsc() void PLModel::popupSortAsc()
{ {
sort( i_popup_item, i_popup_column, Qt::AscendingOrder ); sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
} }
void PLModel::popupSortDesc() void PLModel::popupSortDesc()
{ {
sort( i_popup_item, i_popup_column, Qt::DescendingOrder ); sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
} }
/********************************************************************** /**********************************************************************
* Playlist callbacks * Playlist callbacks
......
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