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,33 +925,32 @@ void PLModel::search( const QString& search_text ) ...@@ -925,33 +925,32 @@ 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;
i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
bool node = p_item->i_children > -1;
bool tree = false;
if( node )
{ {
PL_UNLOCK; return;
}
i_popup_item = index.isValid() ? p_item->i_id : -1;
i_popup_parent = index.isValid() ?
( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
( p_item->i_id );
i_popup_column = index.column();
/* check whether we are in tree view */ /* check whether we are in tree view */
bool tree = false;
playlist_item_t *p_up = p_item; playlist_item_t *p_up = p_item;
while( p_up ) while( p_up )
{ {
if ( p_up == p_playlist->p_root_category ) tree = true; if ( p_up == p_playlist->p_root_category ) tree = true;
p_up = p_up->p_parent; 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() ) );
...@@ -960,8 +959,6 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ...@@ -960,8 +959,6 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
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(); menu->addSeparator();
QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") + QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
qfu( psz_column_title( metaColumn( index.column() ) ) ) ); qfu( psz_column_title( metaColumn( index.column() ) ) ) );
...@@ -970,18 +967,14 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ...@@ -970,18 +967,14 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
sort_menu->addAction( qtr( "Descending" ), sort_menu->addAction( qtr( "Descending" ),
this, SLOT( popupSortDesc() ) ); this, SLOT( popupSortDesc() ) );
} }
} if( tree )
if( node && tree )
menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) ); menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
if( index.isValid() ) if( i_popup_item > -1 )
{ {
menu->addSeparator(); menu->addSeparator();
menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) ); menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
} }
menu->popup( point ); menu->popup( point );
}
else
PL_UNLOCK;
} }
...@@ -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