00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _PLAYLIST_MODEL_H_
00025 #define _PLAYLIST_MODEL_H_
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include "config.h"
00029 #endif
00030
00031 #include <vlc_common.h>
00032 #include <vlc_input.h>
00033 #include <vlc_playlist.h>
00034 #include "playlist_item.hpp"
00035
00036 #include "qt4.hpp"
00037
00038 #include <QModelIndex>
00039 #include <QObject>
00040 #include <QEvent>
00041 #include <QMimeData>
00042 #include <QSignalMapper>
00043 #include <QAbstractItemModel>
00044 #include <QVariant>
00045
00046 class QSignalMapper;
00047
00048 class PLItem;
00049
00050 #define DEPTH_PL -1
00051 #define DEPTH_SEL 1
00052
00053 static const int ItemUpdate_Type = QEvent::User + PLEventType + 2;
00054 static const int ItemDelete_Type = QEvent::User + PLEventType + 3;
00055 static const int ItemAppend_Type = QEvent::User + PLEventType + 4;
00056 static const int PLUpdate_Type = QEvent::User + PLEventType + 5;
00057
00058 class PLEvent : public QEvent
00059 {
00060 public:
00061 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
00062 { i_id = id; p_add = NULL; };
00063
00064 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
00065 { p_add = a; };
00066
00067 virtual ~PLEvent() {};
00068
00069 int i_id;
00070 playlist_add_t *p_add;
00071 };
00072
00073
00074 class PLModel : public QAbstractItemModel
00075 {
00076 Q_OBJECT
00077
00078 friend class PLItem;
00079
00080 public:
00081 PLModel( playlist_t *, intf_thread_t *,
00082 playlist_item_t *, int, QObject *parent = 0 );
00083 ~PLModel();
00084
00085
00086 QVariant data( const QModelIndex &index, int role ) const;
00087 Qt::ItemFlags flags( const QModelIndex &index ) const;
00088 QVariant headerData( int section, Qt::Orientation orientation,
00089 int role = Qt::DisplayRole ) const;
00090 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
00091 QModelIndex index( PLItem *, int c ) const;
00092 int itemId( const QModelIndex &index ) const;
00093 bool isCurrent( const QModelIndex &index );
00094 QModelIndex parent( const QModelIndex &index ) const;
00095 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
00096 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
00097 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
00098
00099 void rebuild(); void rebuild( playlist_item_t * );
00100 bool hasRandom(); bool hasLoop(); bool hasRepeat();
00101
00102
00103 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
00104 void doDelete( QModelIndexList selected );
00105 void search( QString search );
00106 void sort( int column, Qt::SortOrder order );
00107 void removeItem( int );
00108
00109
00110 Qt::DropActions supportedDropActions() const;
00111 QMimeData* mimeData( const QModelIndexList &indexes ) const;
00112 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
00113 int row, int column, const QModelIndex &target );
00114 QStringList mimeTypes() const;
00115
00116 int shownFlags() { return rootItem->i_showflags; }
00117
00118 private:
00119 void addCallbacks();
00120 void delCallbacks();
00121 void customEvent( QEvent * );
00122
00123 PLItem *rootItem;
00124
00125 playlist_t *p_playlist;
00126 intf_thread_t *p_intf;
00127 int i_depth;
00128
00129 static QIcon icons[ITEM_TYPE_NUMBER];
00130
00131
00132 void ProcessInputItemUpdate( int i_input_id );
00133 void ProcessItemRemoval( int i_id );
00134 void ProcessItemAppend( playlist_add_t *p_add );
00135
00136 void UpdateTreeItem( PLItem *, bool, bool force = false );
00137 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
00138 void UpdateNodeChildren( PLItem * );
00139 void UpdateNodeChildren( playlist_item_t *, PLItem * );
00140
00141
00142 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
00143 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
00144
00145
00146 int i_popup_item, i_popup_parent;
00147 QModelIndexList current_selection;
00148 QSignalMapper *ContextUpdateMapper;
00149
00150
00151 PLItem *FindById( PLItem *, int );
00152 PLItem *FindByInput( PLItem *, int );
00153 PLItem *FindInner( PLItem *, int , bool );
00154 PLItem *p_cached_item;
00155 PLItem *p_cached_item_bi;
00156 int i_cached_id;
00157 int i_cached_input_id;
00158 signals:
00159 void shouldRemove( int );
00160
00161 public slots:
00162 void activateItem( const QModelIndex &index );
00163 void activateItem( playlist_item_t *p_item );
00164 void setRandom( bool );
00165 void setLoop( bool );
00166 void setRepeat( bool );
00167
00168 private slots:
00169 void popupPlay();
00170 void popupDel();
00171 void popupInfo();
00172 void popupStream();
00173 void popupSave();
00174 #ifdef WIN32
00175 void popupExplore();
00176 #endif
00177
00178 void viewchanged( int );
00179 };
00180
00181 #endif