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>
8 * Jakob Leben <jleben@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef _PLAYLIST_MODEL_H_
26 #define _PLAYLIST_MODEL_H_
34 #include <vlc_input.h>
35 #include <vlc_playlist.h>
37 #include "playlist_item.hpp"
39 #include <QModelIndex>
43 #include <QSignalMapper>
44 #include <QAbstractItemModel>
55 ItemUpdate_Type = QEvent::User + PLEventType + 2,
56 ItemDelete_Type = QEvent::User + PLEventType + 3,
57 ItemAppend_Type = QEvent::User + PLEventType + 4,
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 *, QObject *parent = 0 );
93 /*** QModel subclassing ***/
96 QVariant data( const QModelIndex &index, int role ) const;
97 QVariant headerData( int section, Qt::Orientation orientation,
98 int role = Qt::DisplayRole ) const;
99 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
100 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
101 Qt::ItemFlags flags( const QModelIndex &index ) const;
102 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
103 QModelIndex parent( const QModelIndex &index ) const;
106 Qt::DropActions supportedDropActions() const;
107 QMimeData* mimeData( const QModelIndexList &indexes ) const;
108 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
109 int row, int column, const QModelIndex &target );
110 QStringList mimeTypes() const;
115 QStringList selectedURIs();
116 bool hasRandom(); bool hasLoop(); bool hasRepeat();
117 QModelIndex index( PLItem *, int c ) const;
118 QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
119 bool isCurrent( const QModelIndex &index ) const;
120 int itemId( const QModelIndex &index ) const;
123 void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
124 void doDelete( QModelIndexList selected );
125 void search( const QString& search_text );
126 void sort( int column, Qt::SortOrder order );
127 void sort( int i_root_id, int column, Qt::SortOrder order );
128 void removeItem( int );
129 void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
137 playlist_t *p_playlist;
138 intf_thread_t *p_intf;
141 static QIcon icons[ITEM_TYPE_NUMBER];
143 /* Callbacks related */
146 void customEvent( QEvent * );
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 * );
154 void removeItem ( PLItem * );
155 void takeItem( PLItem * ); //will not delete item
156 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
157 void dropAppendCopy( QByteArray& data, PLItem *target );
158 void dropMove( QByteArray& data, PLItem *target, int new_pos );
159 /* The following actions will not signal the view! */
160 void updateChildren( PLItem * );
161 void updateChildren( playlist_item_t *, PLItem * );
164 int i_popup_item, i_popup_parent, i_popup_column;
165 QModelIndexList current_selection;
168 PLItem *findById( PLItem *, int );
169 PLItem *findByInput( PLItem *, int );
170 PLItem *findInner( PLItem *, int , bool );
171 static inline PLItem *getItem( QModelIndex index );
172 int columnFromMeta( int meta_column ) const;
173 int columnToMeta( int column ) const;
174 PLItem *p_cached_item;
175 PLItem *p_cached_item_bi;
177 int i_cached_input_id;
180 void currentChanged( const QModelIndex& );
183 void activateItem( const QModelIndex &index );
184 void activateItem( playlist_item_t *p_item );
185 void setRandom( bool );
186 void setLoop( bool );
187 void setRepeat( bool );
198 void popupSortDesc();
199 void processInputItemUpdate( input_item_t *);
200 void processInputItemUpdate( input_thread_t* p_input );