* $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 <QVariant>
class QSignalMapper;
-
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,
- PLUpdate_Type = QEvent::User + PLEventType + 5,
-};
-
-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 PLModel : public QAbstractItemModel
{
Q_OBJECT
friend class PLItem;
public:
+ enum {
+ IsCurrentRole = Qt::UserRole
+ };
+
PLModel( playlist_t *, intf_thread_t *,
- playlist_item_t *, int, QObject *parent = 0 );
+ playlist_item_t *, 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;
- QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
- int itemId( const QModelIndex &index ) const;
- bool isCurrent( const QModelIndex &index ) const;
- 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;
- /* Get current selection */
- QStringList selectedURIs();
+ /* 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;
- void rebuild(); void rebuild( playlist_item_t * );
- bool hasRandom(); bool hasLoop(); bool hasRepeat();
+ /**** Custom ****/
- /* Actions made by the views */
- void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
+ /* Lookups */
+ QStringList selectedURIs();
+ QModelIndex index( PLItem *, int c ) const;
+ 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( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void doDelete( QModelIndexList selected );
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 );
+ void rebuild();
+ void rebuild( playlist_item_t * );
- /* 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;
+ inline PLItem *getItem( QModelIndex index ) const
+ {
+ if( index.isValid() )
+ return static_cast<PLItem*>( index.internalPointer() );
+ else return rootItem;
+ }
- int shownFlags() { return i_showflags; }
+signals:
+ void currentChanged( const QModelIndex& );
+ void rootChanged();
-private:
- void addCallbacks();
- void delCallbacks();
- void customEvent( QEvent * );
+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];
- /* Update processing */
- 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 );
+ /* ...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( QByteArray& data, PLItem *target );
void dropMove( QByteArray& data, PLItem *target, int new_pos );
- void TakeItem( PLItem * );
- void InsertChildren( PLItem *node, QList<PLItem*>& items, int i_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, i_popup_column;
QModelIndexList current_selection;
- QSignalMapper *ContextUpdateMapper;
/* Lookups */
- PLItem *FindById( PLItem *, int );
- PLItem *FindByInput( PLItem *, int );
- PLItem *FindInner( PLItem *, int , bool );
- static inline PLItem *getItem( QModelIndex index );
- int metaColumn ( int column ) const;
+ PLItem *findById( PLItem *, int );
+ PLItem *findByInput( PLItem *, int );
+ PLItem *findInner( PLItem *, int , bool );
+ 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 );
private slots:
void popupPlay();
void popupAddNode();
void popupSortAsc();
void popupSortDesc();
- void viewchanged( int );
- void ProcessInputItemUpdate( input_item_t *);
- void ProcessInputItemUpdate( input_thread_t* p_input );
+ void processInputItemUpdate( input_item_t *);
+ void processInputItemUpdate( input_thread_t* p_input );
+ void processItemRemoval( int i_id );
+ void processItemAppend( int item, int parent );
};
#endif