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_
27 #include <QModelIndex>
33 #include <vlc/input.h>
34 #include <vlc_playlist.h>
41 PLItem( int, int, PLItem *parent , PLModel *);
42 PLItem( playlist_item_t *, PLItem *parent, PLModel *);
46 void insertChild( PLItem *, int p, bool signal = true );
48 void appendChild( PLItem *item, bool signal = true )
50 insertChild( item, children.count(), signal );
52 void remove( PLItem *removed );
53 PLItem *child( int row ) { return children.value( row ); };
54 int childCount() const { return children.count(); };
55 QString columnString( int col ) { return strings.value( col ); };
56 PLItem *parent() { return parentItem; };
58 void update( playlist_item_t *, bool);
60 QList<PLItem*> children;
61 QList<QString> strings;
68 void init( int, int, PLItem *, PLModel * );
73 static int ItemUpdate_Type = QEvent::User + 2;
74 static int ItemDelete_Type = QEvent::User + 3;
75 static int ItemAppend_Type = QEvent::User + 4;
76 static int PLUpdate_Type = QEvent::User + 5;
78 class PLEvent : public QEvent
81 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
82 { i_id = id; p_add = NULL; };
83 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
85 virtual ~PLEvent() {};
88 playlist_add_t *p_add;
91 #include <QAbstractItemModel>
94 class PLModel : public QAbstractItemModel
99 PLModel( playlist_t *, playlist_item_t *, int, QObject *parent = 0);
102 /* All types of lookups / QModel stuff */
103 QVariant data( const QModelIndex &index, int role) const;
104 Qt::ItemFlags flags( const QModelIndex &index) const;
105 QVariant headerData( int section, Qt::Orientation orientation,
106 int role = Qt::DisplayRole) const;
107 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
108 QModelIndex index( PLItem *, int c ) const;
109 int itemId( const QModelIndex &index ) const;
110 bool isCurrent( const QModelIndex &index );
111 QModelIndex parent( const QModelIndex &index) const;
112 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
113 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
114 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
117 int i_items_to_append;
118 void rebuild(); void rebuild( playlist_item_t *);
119 bool hasRandom(); bool hasLoop(); bool hasRepeat();
121 /* Actions made by the views */
122 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
123 void doDelete( QModelIndexList selected );
124 void search( QString search );
125 void sort( int column, Qt::SortOrder order );
126 void removeItem( int );
129 Qt::DropActions supportedDropActions() const;
130 QMimeData* mimeData(const QModelIndexList &indexes) const;
131 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
132 int row, int column, const QModelIndex &target);
133 QStringList mimeTypes() const;
135 void sendArt( QString url );
140 void customEvent( QEvent * );
144 playlist_t *p_playlist;
147 static QIcon icons[ITEM_TYPE_NUMBER];
149 /* Update processing */
150 void ProcessInputItemUpdate( int i_input_id );
151 void ProcessItemRemoval( int i_id );
152 void ProcessItemAppend( playlist_add_t *p_add );
154 void UpdateTreeItem( PLItem *, bool, bool force = false );
155 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
156 void UpdateNodeChildren( PLItem * );
157 void UpdateNodeChildren( playlist_item_t *, PLItem * );
160 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
161 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
164 int i_popup_item, i_popup_parent;
165 QModelIndexList current_selection;
168 PLItem *FindById( PLItem *, int );
169 PLItem *FindByInput( PLItem *, int );
170 PLItem *FindInner( PLItem *, int , bool );
171 PLItem *p_cached_item;
172 PLItem *p_cached_item_bi;
174 int i_cached_input_id;
176 void artSet( QString );
177 void shouldRemove( int );
179 void activateItem( const QModelIndex &index );
180 void activateItem( playlist_item_t *p_item );
181 void setRandom( bool );
182 void setLoop( bool );
183 void setRepeat( bool );