1 /*****************************************************************************
2 * playlist_model.hpp : Model for a playlist tree
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef _PLAYLIST_MODEL_H_
25 #define _PLAYLIST_MODEL_H_
28 #include <vlc_input.h>
29 #include <vlc_playlist.h>
31 #include <QModelIndex>
35 #include <QSignalMapper>
43 PLItem( int, int, PLItem *parent , PLModel *);
44 PLItem( playlist_item_t *, PLItem *parent, PLModel *);
48 void insertChild( PLItem *, int p, bool signal = true );
50 void appendChild( PLItem *item, bool signal = true )
52 insertChild( item, children.count(), signal );
54 void remove( PLItem *removed );
55 PLItem *child( int row ) { return children.value( row ); };
56 int childCount() const { return children.count(); };
57 QString columnString( int col ) { return strings.value( col ); };
58 PLItem *parent() { return parentItem; };
60 void update( playlist_item_t *, bool);
62 QList<PLItem*> children;
63 QList<QString> strings;
69 void updateview( void );
72 void init( int, int, PLItem *, PLModel * );
77 static int ItemUpdate_Type = QEvent::User + 2;
78 static int ItemDelete_Type = QEvent::User + 3;
79 static int ItemAppend_Type = QEvent::User + 4;
80 static int PLUpdate_Type = QEvent::User + 5;
82 class PLEvent : public QEvent
85 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
86 { i_id = id; p_add = NULL; };
87 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
89 virtual ~PLEvent() {};
92 playlist_add_t *p_add;
95 #include <QAbstractItemModel>
98 class PLModel : public QAbstractItemModel
103 PLModel( playlist_t *, intf_thread_t *,
104 playlist_item_t *, int, QObject *parent = 0);
107 /* All types of lookups / QModel stuff */
108 QVariant data( const QModelIndex &index, int role) const;
109 Qt::ItemFlags flags( const QModelIndex &index) const;
110 QVariant headerData( int section, Qt::Orientation orientation,
111 int role = Qt::DisplayRole) const;
112 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
113 QModelIndex index( PLItem *, int c ) const;
114 int itemId( const QModelIndex &index ) const;
115 bool isCurrent( const QModelIndex &index );
116 QModelIndex parent( const QModelIndex &index) const;
117 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
118 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
119 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
122 int i_items_to_append;
123 void rebuild(); void rebuild( playlist_item_t *);
124 bool hasRandom(); bool hasLoop(); bool hasRepeat();
126 /* Actions made by the views */
127 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
128 void doDelete( QModelIndexList selected );
129 void search( QString search );
130 void sort( int column, Qt::SortOrder order );
131 void removeItem( int );
134 Qt::DropActions supportedDropActions() const;
135 QMimeData* mimeData(const QModelIndexList &indexes) const;
136 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
137 int row, int column, const QModelIndex &target);
138 QStringList mimeTypes() const;
140 void sendArt( QString url );
145 void customEvent( QEvent * );
149 playlist_t *p_playlist;
150 intf_thread_t *p_intf;
153 static QIcon icons[ITEM_TYPE_NUMBER];
155 /* Update processing */
156 void ProcessInputItemUpdate( int i_input_id );
157 void ProcessItemRemoval( int i_id );
158 void ProcessItemAppend( playlist_add_t *p_add );
160 void UpdateTreeItem( PLItem *, bool, bool force = false );
161 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
162 void UpdateNodeChildren( PLItem * );
163 void UpdateNodeChildren( playlist_item_t *, PLItem * );
166 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
167 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
170 int i_popup_item, i_popup_parent;
171 QModelIndexList current_selection;
172 QSignalMapper *ContextUpdateMapper;
175 PLItem *FindById( PLItem *, int );
176 PLItem *FindByInput( PLItem *, int );
177 PLItem *FindInner( PLItem *, int , bool );
178 PLItem *p_cached_item;
179 PLItem *p_cached_item_bi;
181 int i_cached_input_id;
183 void artSet( QString );
184 void shouldRemove( int );
186 void activateItem( const QModelIndex &index );
187 void activateItem( playlist_item_t *p_item );
188 void setRandom( bool );
189 void setLoop( bool );
190 void setRepeat( bool );
197 void viewchanged( int );