]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt4: cache currentItem index
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
index c8d5da078e42e35ea8745d597cfdabe32672c81b..033cdc691ac1e576ee82d64c273d2b3c7e40bbe2 100644 (file)
@@ -5,6 +5,7 @@
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
+ *          Jakob Leben <jleben@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <QSignalMapper>
 #include <QAbstractItemModel>
 #include <QVariant>
-
-class QSignalMapper;
+#include <QAction>
 
 class PLItem;
-
-#define DEPTH_PL -1
-#define DEPTH_SEL 1
-
-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;
-        add.i_node = -1;
-        add.i_item = -1;
-    };
-
-    PLEvent( const playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
-    {
-        add = *a;
-    };
-
-    virtual ~PLEvent() { };
-
-    int i_id;
-    playlist_add_t add;
-};
-
+class PLSelector;
+class PlMimeData;
 
 class PLModel : public QAbstractItemModel
 {
     Q_OBJECT
 
 friend class PLItem;
+friend class PLSelector;
 
 public:
+    enum {
+      IsCurrentRole = Qt::UserRole,
+      IsLeafNodeRole
+    };
+
     PLModel( playlist_t *, intf_thread_t *,
-             playlist_item_t *, int, QObject *parent = 0 );
+             playlist_item_t *, QObject *parent = 0 );
     ~PLModel();
 
     /*** QModel subclassing ***/
@@ -112,84 +89,79 @@ public:
 
     /* Lookups */
     QStringList selectedURIs();
-    bool hasRandom(); bool hasLoop(); bool hasRepeat();
-    int shownFlags() { return i_showflags;  }
     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;
+    static int columnFromMeta( int meta_column );
+    static int columnToMeta( int column );
 
     /* Actions */
-    void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
+    bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
     void doDelete( QModelIndexList selected );
-    void search( const QString& search_text );
+    void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
     void sort( int column, Qt::SortOrder order );
     void sort( int i_root_id, int column, Qt::SortOrder order );
-    void removeItem( int );
-    void rebuild(); void rebuild( playlist_item_t * );
+    void rebuild();
+    void rebuild( playlist_item_t * );
 
-private:
+    inline PLItem *getItem( QModelIndex index ) const
+    {
+        if( index.isValid() )
+            return static_cast<PLItem*>( index.internalPointer() );
+        else return rootItem;
+    }
+
+signals:
+    void currentChanged( const QModelIndex& );
+    void rootChanged();
+
+public slots:
+    void activateItem( const QModelIndex &index );
+    void activateItem( playlist_item_t *p_item );
 
+private:
     /* General */
     PLItem *rootItem;
-    PLItem *currentItem;
 
     playlist_t *p_playlist;
     intf_thread_t *p_intf;
-    int i_depth;
-    int i_showflags;
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 
-    /* Callbacks related */
-    void addCallbacks();
-    void delCallbacks();
-    void customEvent( QEvent * );
-    void processItemRemoval( int i_id );
-    void processItemAppend( const playlist_add_t *p_add );
-
-    /* Actions */
+    /* Shallow actions (do not affect core playlist) */
+    void updateTreeItem( PLItem * );
+    void removeItem ( PLItem * );
+    void removeItem( int );
     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 * );
+    /* ...of which  the following will not update the views */
     void updateChildren( PLItem * );
     void updateChildren( playlist_item_t *, PLItem * );
 
+    /* Deep actions (affect core playlist) */
+    void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
+    void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
+
     /* Popup */
     int i_popup_item, i_popup_parent, i_popup_column;
     QModelIndexList current_selection;
-    QSignalMapper *ContextUpdateMapper;
+    QMenu *sortingMenu;
+    QSignalMapper *sortingMapper;
 
     /* Lookups */
     PLItem *findById( PLItem *, int );
     PLItem *findByInput( PLItem *, int );
     PLItem *findInner( PLItem *, int , bool );
-    static inline PLItem *getItem( QModelIndex index );
-    int columnFromMeta( int meta_column, int shown_flags ) const;
-    int columnToMeta( int column, int shown_flags ) const;
+    bool canEdit() 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& );
-    void columnsChanged( int );
-
-
-public slots:
-    void activateItem( const QModelIndex &index );
-    void activateItem( playlist_item_t *p_item );
-    void setRandom( bool );
-    void setLoop( bool );
-    void setRepeat( bool );
+    QModelIndex current_index;
 
 private slots:
     void popupPlay();
@@ -199,11 +171,28 @@ private slots:
     void popupSave();
     void popupExplore();
     void popupAddNode();
-    void popupSortAsc();
-    void popupSortDesc();
-    void toggleColumnShown( int meta_column );
+    void popupSort( int column );
     void processInputItemUpdate( input_item_t *);
     void processInputItemUpdate( input_thread_t* p_input );
+    void processItemRemoval( int i_id );
+    void processItemAppend( int item, int parent );
+    void cacheCurrent( const QModelIndex & );
+};
+
+class PlMimeData : public QMimeData
+{
+    Q_OBJECT
+
+public:
+    PlMimeData();
+    ~PlMimeData();
+    void appendItem( input_item_t *p_item );
+    QList<input_item_t*> inputItems() const;
+    QStringList formats () const;
+
+private:
+    QList<input_item_t*> _inputItems;
+    QMimeData *_mimeData;
 };
 
 #endif