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;
70 void updateview( void );
73 void init( int, int, PLItem *, PLModel * );
78 static int ItemUpdate_Type = QEvent::User + 2;
79 static int ItemDelete_Type = QEvent::User + 3;
80 static int ItemAppend_Type = QEvent::User + 4;
81 static int PLUpdate_Type = QEvent::User + 5;
83 class PLEvent : public QEvent
86 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
87 { i_id = id; p_add = NULL; };
88 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
90 virtual ~PLEvent() {};
93 playlist_add_t *p_add;
96 #include <QAbstractItemModel>
99 class PLModel : public QAbstractItemModel
104 PLModel( playlist_t *, intf_thread_t *,
105 playlist_item_t *, int, QObject *parent = 0);
108 /* All types of lookups / QModel stuff */
109 QVariant data( const QModelIndex &index, int role) const;
110 Qt::ItemFlags flags( const QModelIndex &index) const;
111 QVariant headerData( int section, Qt::Orientation orientation,
112 int role = Qt::DisplayRole) const;
113 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
114 QModelIndex index( PLItem *, int c ) const;
115 int itemId( const QModelIndex &index ) const;
116 bool isCurrent( const QModelIndex &index );
117 QModelIndex parent( const QModelIndex &index) const;
118 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
119 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
120 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
123 int i_items_to_append;
125 void rebuild(); void rebuild( playlist_item_t *);
126 bool hasRandom(); bool hasLoop(); bool hasRepeat();
128 /* Actions made by the views */
129 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
130 void doDelete( QModelIndexList selected );
131 void search( QString search );
132 void sort( int column, Qt::SortOrder order );
133 void removeItem( int );
136 Qt::DropActions supportedDropActions() const;
137 QMimeData* mimeData(const QModelIndexList &indexes) const;
138 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
139 int row, int column, const QModelIndex &target);
140 QStringList mimeTypes() const;
142 void sendArt( QString url );
145 int shownFlags() { return rootItem->i_showflags; }
149 void customEvent( QEvent * );
153 playlist_t *p_playlist;
154 intf_thread_t *p_intf;
157 static QIcon icons[ITEM_TYPE_NUMBER];
159 /* Update processing */
160 void ProcessInputItemUpdate( int i_input_id );
161 void ProcessItemRemoval( int i_id );
162 void ProcessItemAppend( playlist_add_t *p_add );
164 void UpdateTreeItem( PLItem *, bool, bool force = false );
165 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
166 void UpdateNodeChildren( PLItem * );
167 void UpdateNodeChildren( playlist_item_t *, PLItem * );
170 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
171 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
174 int i_popup_item, i_popup_parent;
175 QModelIndexList current_selection;
176 QSignalMapper *ContextUpdateMapper;
179 PLItem *FindById( PLItem *, int );
180 PLItem *FindByInput( PLItem *, int );
181 PLItem *FindInner( PLItem *, int , bool );
182 PLItem *p_cached_item;
183 PLItem *p_cached_item_bi;
185 int i_cached_input_id;
187 void artSet( QString );
188 void shouldRemove( int );
190 void activateItem( const QModelIndex &index );
191 void activateItem( playlist_item_t *p_item );
192 void setRandom( bool );
193 void setLoop( bool );
194 void setRepeat( bool );
204 void viewchanged( int );