]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt: return playlist model and views to "now playing" root if current root is deleted
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
index 64ecae5e960fe6527a90e4d767e1fc904ea5bb2a..cb5e68c3e04766c9ee682acc8f9eeaa6b6c192c5 100644 (file)
@@ -54,6 +54,10 @@ class PLModel : public QAbstractItemModel
 friend class PLItem;
 
 public:
+    enum {
+      IsCurrentRole = Qt::UserRole
+    };
+
     PLModel( playlist_t *, intf_thread_t *,
              playlist_item_t *, QObject *parent = 0 );
     ~PLModel();
@@ -82,7 +86,8 @@ public:
     /* Lookups */
     QStringList selectedURIs();
     QModelIndex index( PLItem *, int c ) const;
-    QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
+    QModelIndex index( int i_id, int c );
+    QModelIndex currentIndex();
     bool isCurrent( const QModelIndex &index ) const;
     int itemId( const QModelIndex &index ) const;
 
@@ -95,13 +100,17 @@ public:
     void removeItem( int );
     void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
 
-    static inline PLItem *getItem( QModelIndex index );
+    inline PLItem *getItem( QModelIndex index ) const
+    {
+        if( index.isValid() )
+            return static_cast<PLItem*>( index.internalPointer() );
+        else return rootItem;
+    }
 
 private:
 
     /* General */
     PLItem *rootItem;
-    PLItem *currentItem;
 
     playlist_t *p_playlist;
     intf_thread_t *p_intf;
@@ -141,6 +150,7 @@ private:
 
 signals:
     void currentChanged( const QModelIndex& );
+    void rootChanged();
 
 public slots:
     void activateItem( const QModelIndex &index );