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_
33 #include <vlc_input.h>
34 #include <vlc_playlist.h>
36 #include "playlist_item.hpp"
38 #include <QModelIndex>
42 #include <QSignalMapper>
43 #include <QAbstractItemModel>
54 ItemUpdate_Type = QEvent::User + PLEventType + 2,
55 ItemDelete_Type = QEvent::User + PLEventType + 3,
56 ItemAppend_Type = QEvent::User + PLEventType + 4,
57 PLUpdate_Type = QEvent::User + PLEventType + 5,
60 class PLEvent : public QEvent
63 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
70 PLEvent( const playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
75 virtual ~PLEvent() { };
82 class PLModel : public QAbstractItemModel
89 PLModel( playlist_t *, intf_thread_t *,
90 playlist_item_t *, int, QObject *parent = 0 );
93 /* All types of lookups / QModel stuff */
94 QVariant data( const QModelIndex &index, int role ) const;
95 Qt::ItemFlags flags( const QModelIndex &index ) const;
96 QVariant headerData( int section, Qt::Orientation orientation,
97 int role = Qt::DisplayRole ) const;
98 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
99 QModelIndex index( PLItem *, int c ) const;
100 QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
101 int itemId( const QModelIndex &index ) const;
102 bool isCurrent( const QModelIndex &index ) const;
103 QModelIndex parent( const QModelIndex &index ) const;
104 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
105 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
106 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
108 /* Get current selection */
109 QStringList selectedURIs();
111 void rebuild(); void rebuild( playlist_item_t * );
112 bool hasRandom(); bool hasLoop(); bool hasRepeat();
114 /* Actions made by the views */
115 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
116 void doDelete( QModelIndexList selected );
117 void search( const QString& search_text );
118 void sort( int column, Qt::SortOrder order );
119 void sort( int i_root_id, int column, Qt::SortOrder order );
120 void removeItem( int );
123 Qt::DropActions supportedDropActions() const;
124 QMimeData* mimeData( const QModelIndexList &indexes ) const;
125 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
126 int row, int column, const QModelIndex &target );
127 QStringList mimeTypes() const;
129 int shownFlags() { return i_showflags; }
134 void customEvent( QEvent * );
139 playlist_t *p_playlist;
140 intf_thread_t *p_intf;
144 static QIcon icons[ITEM_TYPE_NUMBER];
146 /* Update processing */
147 void ProcessItemRemoval( int i_id );
148 void ProcessItemAppend( const playlist_add_t *p_add );
151 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
152 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
153 void UpdateTreeItem( PLItem *, bool, bool force = false );
154 /* The following actions will not signal the view! */
155 void RemoveItem ( PLItem * );
156 void RemoveChildren( PLItem * );
157 void UpdateChildren( PLItem * );
158 void UpdateChildren( playlist_item_t *, PLItem * );
161 int i_popup_item, i_popup_parent, i_popup_column;
162 QModelIndexList current_selection;
163 QSignalMapper *ContextUpdateMapper;
166 PLItem *FindById( PLItem *, int );
167 PLItem *FindByInput( PLItem *, int );
168 PLItem *FindInner( PLItem *, int , bool );
169 PLItem *getItem( const QModelIndex& index ) const;
170 int metaColumn ( int column ) const;
171 PLItem *p_cached_item;
172 PLItem *p_cached_item_bi;
174 int i_cached_input_id;
176 void shouldRemove( int );
177 void currentChanged( const QModelIndex& );
178 void columnsChanged( int );
182 void activateItem( const QModelIndex &index );
183 void activateItem( playlist_item_t *p_item );
184 void setRandom( bool );
185 void setLoop( bool );
186 void setRepeat( bool );
197 void popupSortDesc();
198 void viewchanged( int );
199 void ProcessInputItemUpdate( input_item_t *);
200 void ProcessInputItemUpdate( input_thread_t* p_input );