]> git.sesse.net Git - vlc/commitdiff
Qt4: implement PLModel::popupAddNode()
authorJakob Leben <jleben@videolan.org>
Tue, 18 Aug 2009 11:29:09 +0000 (13:29 +0200)
committerJakob Leben <jleben@videolan.org>
Tue, 18 Aug 2009 11:29:09 +0000 (13:29 +0200)
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp

index b4a75a0df893187ba2df8fbb8e264f2570792ab0..d8ba78738d7a5ca68d5dcc0540e63156e965b1cf 100644 (file)
@@ -948,7 +948,20 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
     {
         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 )
+        {
+            /* check whether we are in tree view */
+            playlist_item_t *p_up = p_item;
+            while( p_up )
+            {
+                if ( p_up == p_playlist->p_root_category ) tree = true;
+                p_up = p_up->p_parent;
+            }
+        }
         PL_UNLOCK;
+
         current_selection = list;
         QMenu *menu = new QMenu;
         menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
@@ -958,11 +971,12 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
         menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
         menu->addSeparator();
         menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
-        if( p_item->i_children > -1 )
+        if( node )
         {
             menu->addSeparator();
             menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
-            menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
+            if( tree );
+                menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
         }
         menu->addSeparator();
         menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
@@ -1096,6 +1110,23 @@ void PLModel::popupExplore()
         PL_UNLOCK;
 }
 
+#include <QInputDialog>
+void PLModel::popupAddNode()
+{
+    bool ok;
+    QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
+        QString( "Add node" ), QString( "Enter name for new node" ),
+        QLineEdit::Normal, QString(), &ok);
+    if( !ok || name.isEmpty() ) return;
+    PL_LOCK;
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+                                                    i_popup_item );
+    if( p_item )
+    {
+        playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
+    }
+    PL_UNLOCK;
+}
 /**********************************************************************
  * Playlist callbacks
  **********************************************************************/
index 359471b29139928117599d8e09bab192b2665d17..cdac23246e442640630444df8c8380de7c46587d 100644 (file)
@@ -186,6 +186,7 @@ private slots:
     void popupStream();
     void popupSave();
     void popupExplore();
+    void popupAddNode();
     void viewchanged( int );
     void ProcessInputItemUpdate( input_item_t *);
     void ProcessInputItemUpdate( input_thread_t* p_input );