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_
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33 #include <vlc_playlist.h>
34 #include "playlist_item.hpp"
38 #include <QModelIndex>
42 #include <QSignalMapper>
43 #include <QAbstractItemModel>
53 static const int ItemUpdate_Type = QEvent::User + PLEventType + 2;
54 static const int ItemDelete_Type = QEvent::User + PLEventType + 3;
55 static const int ItemAppend_Type = QEvent::User + PLEventType + 4;
56 static const int PLUpdate_Type = QEvent::User + PLEventType + 5;
58 class PLEvent : public QEvent
61 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
62 { i_id = id; p_add = NULL; };
64 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
67 virtual ~PLEvent() {};
70 playlist_add_t *p_add;
74 class PLModel : public QAbstractItemModel
81 PLModel( playlist_t *, intf_thread_t *,
82 playlist_item_t *, int, QObject *parent = 0 );
85 /* All types of lookups / QModel stuff */
86 QVariant data( const QModelIndex &index, int role ) const;
87 Qt::ItemFlags flags( const QModelIndex &index ) const;
88 QVariant headerData( int section, Qt::Orientation orientation,
89 int role = Qt::DisplayRole ) const;
90 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
91 QModelIndex index( PLItem *, int c ) const;
92 int itemId( const QModelIndex &index ) const;
93 bool isCurrent( const QModelIndex &index );
94 QModelIndex parent( const QModelIndex &index ) const;
95 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
96 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
97 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
99 void rebuild(); void rebuild( playlist_item_t * );
100 bool hasRandom(); bool hasLoop(); bool hasRepeat();
102 /* Actions made by the views */
103 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
104 void doDelete( QModelIndexList selected );
105 void search( QString search );
106 void sort( int column, Qt::SortOrder order );
107 void removeItem( int );
110 Qt::DropActions supportedDropActions() const;
111 QMimeData* mimeData( const QModelIndexList &indexes ) const;
112 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
113 int row, int column, const QModelIndex &target );
114 QStringList mimeTypes() const;
116 int shownFlags() { return rootItem->i_showflags; }
121 void customEvent( QEvent * );
125 playlist_t *p_playlist;
126 intf_thread_t *p_intf;
129 static QIcon icons[ITEM_TYPE_NUMBER];
131 /* Update processing */
132 void ProcessInputItemUpdate( int i_input_id );
133 void ProcessItemRemoval( int i_id );
134 void ProcessItemAppend( playlist_add_t *p_add );
136 void UpdateTreeItem( PLItem *, bool, bool force = false );
137 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
138 void UpdateNodeChildren( PLItem * );
139 void UpdateNodeChildren( playlist_item_t *, PLItem * );
142 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
143 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
146 int i_popup_item, i_popup_parent;
147 QModelIndexList current_selection;
148 QSignalMapper *ContextUpdateMapper;
151 PLItem *FindById( PLItem *, int );
152 PLItem *FindByInput( PLItem *, int );
153 PLItem *FindInner( PLItem *, int , bool );
154 PLItem *p_cached_item;
155 PLItem *p_cached_item_bi;
157 int i_cached_input_id;
159 void shouldRemove( int );
162 void activateItem( const QModelIndex &index );
163 void activateItem( playlist_item_t *p_item );
164 void setRandom( bool );
165 void setLoop( bool );
166 void setRepeat( bool );
178 void viewchanged( int );