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>
32 #include <vlc/input.h>
33 #include <vlc_playlist.h>
40 PLItem( int, int, PLItem *parent , PLModel *);
41 PLItem( playlist_item_t *, PLItem *parent, PLModel *);
45 void insertChild( PLItem *, int p, bool signal = true );
47 void appendChild( PLItem *item, bool signal = true )
49 insertChild( item, children.count(), signal );
51 void remove( PLItem *removed );
52 PLItem *child( int row ) { return children.value( row ); };
53 int childCount() const { return children.count(); };
54 QString columnString( int col ) { return strings.value( col ); };
55 PLItem *parent() { return parentItem; };
57 void update( playlist_item_t *, bool);
59 QList<PLItem*> children;
60 QList<QString> strings;
67 void init( int, int, PLItem *, PLModel * );
72 static int ItemUpdate_Type = QEvent::User + 2;
73 static int ItemDelete_Type = QEvent::User + 3;
74 static int ItemAppend_Type = QEvent::User + 4;
76 class PLEvent : public QEvent
79 PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
80 { i_id = id; p_add = NULL; };
81 PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
83 virtual ~PLEvent() {};
86 playlist_add_t *p_add;
89 #include <QAbstractItemModel>
92 class PLModel : public QAbstractItemModel
97 PLModel( playlist_t *, playlist_item_t *, int, QObject *parent = 0);
100 /* All types of lookups / QModel stuff */
101 QVariant data( const QModelIndex &index, int role) const;
102 Qt::ItemFlags flags( const QModelIndex &index) const;
103 QVariant headerData( int section, Qt::Orientation orientation,
104 int role = Qt::DisplayRole) const;
105 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
106 QModelIndex index( PLItem *, int c ) const;
107 int itemId( const QModelIndex &index ) const;
108 bool isCurrent( const QModelIndex &index );
109 QModelIndex parent( const QModelIndex &index) const;
110 int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
111 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
112 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
115 int i_items_to_append;
116 void rebuild(); void rebuild( playlist_item_t *);
117 bool hasRandom(); bool hasLoop(); bool hasRepeat();
119 /* Actions made by the views */
120 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
121 void doDelete( QModelIndexList selected );
122 void search( QString search );
123 void sort( int column, Qt::SortOrder order );
127 void customEvent( QEvent * );
131 playlist_t *p_playlist;
134 static QIcon icons[ITEM_TYPE_NUMBER];
136 /* Update processing */
137 void ProcessInputItemUpdate( int i_input_id );
138 void ProcessItemRemoval( int i_id );
139 void ProcessItemAppend( playlist_add_t *p_add );
141 void UpdateTreeItem( PLItem *, bool, bool force = false );
142 void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
143 void UpdateNodeChildren( PLItem * );
144 void UpdateNodeChildren( playlist_item_t *, PLItem * );
147 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
148 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
151 int i_popup_item, i_popup_parent;
152 QModelIndexList current_selection;
155 PLItem *FindById( PLItem *, int );
156 PLItem *FindByInput( PLItem *, int );
157 PLItem *FindInner( PLItem *, int , bool );
158 PLItem *p_cached_item;
159 PLItem *p_cached_item_bi;
161 int i_cached_input_id;
163 void activateItem( const QModelIndex &index );
164 void activateItem( playlist_item_t *p_item );
165 void setRandom( bool );
166 void setLoop( bool );
167 void setRepeat( bool );