From 1e5a01c73341186338714c73095d5caeaecab998 Mon Sep 17 00:00:00 2001
From: Jakob Leben <jakob.leben@gmail.com>
Date: Sun, 2 Aug 2009 16:57:50 +0200
Subject: [PATCH] Qt4 Playlist: Disable dropping on non-container items

New protected field bool PLItem::b_is_node to have the data at hand.
Then only check this field in PLModel::flags().
---
 .../gui/qt4/components/playlist/playlist_item.cpp  |   14 +++++++++-----
 .../gui/qt4/components/playlist/playlist_item.hpp  |    5 +++--
 .../gui/qt4/components/playlist/playlist_model.cpp |    7 ++++++-
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index 0edde6a..b0436f0 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -48,7 +48,7 @@
 */
 
 
-void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSettings *settings )
+void PLItem::init( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m, QSettings *settings )
 {
     parentItem = parent;          /* Can be NULL, but only for the rootItem */
     i_id       = _i_id;           /* Playlist item specific id */
@@ -56,6 +56,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett
     model      = m;               /* PLModel (QAbsmodel) */
     i_type     = -1;              /* Item type - Avoid segfault */
     b_current  = false;           /* Is the item the current Item or not */
+    b_is_node = _is_node;
 
     assert( model );              /* We need a model */
 
@@ -91,19 +92,21 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m, QSett
    Call the above function init
    So far the first constructor isn't used...
    */
-PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
+PLItem::PLItem( int _i_id, int _i_input_id, bool _is_node, PLItem *parent, PLModel *m )
 {
-    init( _i_id, _i_input_id, parent, m, NULL );
+    init( _i_id, _i_input_id, _is_node, parent, m, NULL );
 }
 
 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
 {
-    init( p_item->i_id, p_item->p_input->i_id, parent, m, NULL );
+    init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
+        parent, m, NULL );
 }
 
 PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
 {
-    init( p_item->i_id, p_item->p_input->i_id, NULL, m, settings );
+    init( p_item->i_id, p_item->p_input->i_id, p_item->i_children > -1,
+        NULL, m, settings );
 }
 
 PLItem::~PLItem()
@@ -174,6 +177,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
     /* Useful for the model */
     i_type = p_item->p_input->i_type;
     b_current = iscurrent;
+    b_is_node = p_item->i_children > -1;
 
     item_col_strings.clear();
 
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index 26ce13c..c9d186b 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -40,7 +40,7 @@ class PLItem
 {
     friend class PLModel;
 public:
-    PLItem( int, int, PLItem *parent , PLModel * );
+    PLItem( int, int, bool, PLItem *parent , PLModel * );
     PLItem( playlist_item_t *, PLItem *parent, PLModel * );
     PLItem( playlist_item_t *, QSettings *, PLModel * );
     ~PLItem();
@@ -72,9 +72,10 @@ protected:
     int i_id;
     int i_input_id;
     int i_showflags;
+    bool b_is_node;
 
 private:
-    void init( int, int, PLItem *, PLModel *, QSettings * );
+    void init( int, int, bool, PLItem *, PLModel *, QSettings * );
     void updateColumnHeaders();
     PLItem *parentItem;
     PLModel *model;
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 16061f3..a2c14a4 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -117,7 +117,12 @@ Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
 {
     Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
     if( index.isValid() )
-        return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
+    {
+        PLItem *item = static_cast<PLItem*>( index.internalPointer() );
+        if ( item->b_is_node )
+            defaultFlags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
+        else defaultFlags |= Qt::ItemIsDragEnabled;
+    }
     else if ( rootItem->i_id != p_playlist->p_root_onelevel->i_id
           && rootItem->i_id != p_playlist->p_root_category->i_id )
               defaultFlags |= Qt::ItemIsDropEnabled;
-- 
1.6.0.4

