]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.hpp
qt4: let QTreeView manage visible playlist columns selection
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
index 183aab9ad7a6ed3532648c6ad3129c7b94e7cdea..2ff33321cb079a27960a9a83f5b5d6782a5df0f4 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include "qt4.hpp"
+
 #include <vlc_input.h>
 #include <vlc_playlist.h>
+
 #include "playlist_item.hpp"
 
 #include <QModelIndex>
@@ -48,24 +50,31 @@ class PLItem;
 #define DEPTH_PL -1
 #define DEPTH_SEL 1
 
-static int ItemUpdate_Type = QEvent::User + 2;
-static int ItemDelete_Type = QEvent::User + 3;
-static int ItemAppend_Type = QEvent::User + 4;
-static int PLUpdate_Type = QEvent::User + 5;
+enum {
+    ItemUpdate_Type = QEvent::User + PLEventType + 2,
+    ItemDelete_Type = QEvent::User + PLEventType + 3,
+    ItemAppend_Type = QEvent::User + PLEventType + 4,
+};
 
 class PLEvent : public QEvent
 {
 public:
     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
-    { i_id = id; p_add = NULL; };
+    {
+        i_id = id;
+        add.i_node = -1;
+        add.i_item = -1;
+    };
 
-    PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
-    { p_add = a; };
+    PLEvent( const playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
+    {
+        add = *a;
+    };
 
-    virtual ~PLEvent() {};
+    virtual ~PLEvent() { };
 
     int i_id;
-    playlist_add_t *p_add;
+    playlist_add_t add;
 };
 
 
@@ -80,48 +89,49 @@ public:
              playlist_item_t *, int, QObject *parent = 0 );
     ~PLModel();
 
-    /* All types of lookups / QModel stuff */
+    /*** QModel subclassing ***/
+
+    /* Data structure */
     QVariant data( const QModelIndex &index, int role ) const;
-    Qt::ItemFlags flags( const QModelIndex &index ) const;
     QVariant headerData( int section, Qt::Orientation orientation,
                          int role = Qt::DisplayRole ) const;
-    QModelIndex index( int r, int c, const QModelIndex &parent ) const;
-    QModelIndex index( PLItem *, int c ) const;
-    int itemId( const QModelIndex &index ) const;
-    bool isCurrent( const QModelIndex &index );
-    QModelIndex parent( const QModelIndex &index ) const;
-    int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
+    Qt::ItemFlags flags( const QModelIndex &index ) const;
+    QModelIndex index( int r, int c, const QModelIndex &parent ) const;
+    QModelIndex parent( const QModelIndex &index ) const;
+
+    /* Drag and Drop */
+    Qt::DropActions supportedDropActions() const;
+    QMimeData* mimeData( const QModelIndexList &indexes ) const;
+    bool dropMimeData( const QMimeData *data, Qt::DropAction action,
+                      int row, int column, const QModelIndex &target );
+    QStringList mimeTypes() const;
 
-    bool b_need_update;
-    int i_items_to_append;
+    /**** Custom ****/
 
-    void rebuild(); void rebuild( playlist_item_t * );
+    /* Lookups */
+    QStringList selectedURIs();
     bool hasRandom(); bool hasLoop(); bool hasRepeat();
+    QModelIndex index( PLItem *, int c ) const;
+    QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
+    bool isCurrent( const QModelIndex &index ) const;
+    int itemId( const QModelIndex &index ) const;
 
-    /* Actions made by the views */
+    /* Actions */
     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
     void doDelete( QModelIndexList selected );
-    void search( QString search );
+    void search( const QString& search_text );
     void sort( int column, Qt::SortOrder order );
+    void sort( int i_root_id, int column, Qt::SortOrder order );
     void removeItem( int );
-
-    /* DnD handling */
-    Qt::DropActions supportedDropActions() const;
-    QMimeData* mimeData( const QModelIndexList &indexes ) const;
-    bool dropMimeData( const QMimeData *data, Qt::DropAction action,
-                      int row, int column, const QModelIndex &target );
-    QStringList mimeTypes() const;
-
-    int shownFlags() { return rootItem->i_showflags;  }
+    void rebuild(); void rebuild( playlist_item_t * );
 
 private:
-    void addCallbacks();
-    void delCallbacks();
-    void customEvent( QEvent * );
 
+    /* General */
     PLItem *rootItem;
+    PLItem *currentItem;
 
     playlist_t *p_playlist;
     intf_thread_t *p_intf;
@@ -129,35 +139,45 @@ private:
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 
-    /* Update processing */
-    void ProcessInputItemUpdate( int i_input_id );
-    void ProcessItemRemoval( int i_id );
-    void ProcessItemAppend( playlist_add_t *p_add );
-
-    void UpdateTreeItem( PLItem *, bool, bool force = false );
-    void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
-    void UpdateNodeChildren( PLItem * );
-    void UpdateNodeChildren( playlist_item_t *, PLItem * );
+    /* Callbacks related */
+    void addCallbacks();
+    void delCallbacks();
+    void customEvent( QEvent * );
+    void processItemRemoval( int i_id );
+    void processItemAppend( const playlist_add_t *p_add );
 
     /* Actions */
     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
+    void updateTreeItem( PLItem *, bool, bool force = false );
+    void takeItem( PLItem * ); //will not delete item
+    void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
+    void dropAppendCopy( QByteArray& data, PLItem *target );
+    void dropMove( QByteArray& data, PLItem *target, int new_pos );
+    /* The following actions will not signal the view! */
+    void removeItem ( PLItem * );
+    void updateChildren( PLItem * );
+    void updateChildren( playlist_item_t *, PLItem * );
 
     /* Popup */
-    int i_popup_item, i_popup_parent;
+    int i_popup_item, i_popup_parent, i_popup_column;
     QModelIndexList current_selection;
-    QSignalMapper *ContextUpdateMapper;
 
     /* Lookups */
-    PLItem *FindById( PLItem *, int );
-    PLItem *FindByInput( PLItem *, int );
-    PLItem *FindInner( PLItem *, int , bool );
+    PLItem *findById( PLItem *, int );
+    PLItem *findByInput( PLItem *, int );
+    PLItem *findInner( PLItem *, int , bool );
+    static inline PLItem *getItem( QModelIndex index );
+    int columnFromMeta( int meta_column ) const;
+    int columnToMeta( int column ) const;
     PLItem *p_cached_item;
     PLItem *p_cached_item_bi;
     int i_cached_id;
     int i_cached_input_id;
+
 signals:
     void shouldRemove( int );
+    void currentChanged( const QModelIndex& );
 
 public slots:
     void activateItem( const QModelIndex &index );
@@ -172,11 +192,12 @@ private slots:
     void popupInfo();
     void popupStream();
     void popupSave();
-#ifdef WIN32
     void popupExplore();
-#endif
-
-    void viewchanged( int );
+    void popupAddNode();
+    void popupSortAsc();
+    void popupSortDesc();
+    void processInputItemUpdate( input_item_t *);
+    void processInputItemUpdate( input_thread_t* p_input );
 };
 
 #endif