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>
52 class PLModel : public QAbstractItemModel
57 friend class PLSelector;
61 IsCurrentRole = Qt::UserRole,
63 IsCurrentsParentNodeRole
66 PLModel( playlist_t *, intf_thread_t *,
67 playlist_item_t *, QObject *parent = 0 );
70 /*** QModel subclassing ***/
73 QVariant data( const QModelIndex &index, const int role ) const;
74 QVariant headerData( int section, Qt::Orientation orientation,
75 int role = Qt::DisplayRole ) const;
76 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
77 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
78 Qt::ItemFlags flags( const QModelIndex &index ) const;
79 QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
80 QModelIndex parent( const QModelIndex &index ) const;
83 Qt::DropActions supportedDropActions() const;
84 QMimeData* mimeData( const QModelIndexList &indexes ) const;
85 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
86 int row, int column, const QModelIndex &target );
87 QStringList mimeTypes() const;
92 QStringList selectedURIs();
93 QModelIndex index( PLItem *, const int c ) const;
94 QModelIndex index( const int i_id, const int c );
95 QModelIndex currentIndex() const;
96 bool isParent( const QModelIndex &index, const QModelIndex ¤t) const;
97 bool isCurrent( const QModelIndex &index ) const;
98 int itemId( const QModelIndex &index ) const;
99 static int columnFromMeta( int meta_column );
100 static int columnToMeta( int column );
103 bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
104 void doDelete( QModelIndexList selected );
105 void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
106 void sort( const int column, Qt::SortOrder order );
107 void sort( const int i_root_id, const int column, Qt::SortOrder order );
109 void rebuild( playlist_item_t * );
111 inline PLItem *getItem( QModelIndex index ) const
113 if( index.isValid() )
114 return static_cast<PLItem*>( index.internalPointer() );
115 else return rootItem;
119 void currentChanged( const QModelIndex& );
123 void activateItem( const QModelIndex &index );
124 void activateItem( playlist_item_t *p_item );
130 playlist_t *p_playlist;
131 intf_thread_t *p_intf;
133 static QIcon icons[ITEM_TYPE_NUMBER];
135 /* Shallow actions (do not affect core playlist) */
136 void updateTreeItem( PLItem * );
137 void removeItem ( PLItem * );
138 void removeItem( int );
139 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
140 void takeItem( PLItem * ); //will not delete item
141 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
142 /* ...of which the following will not update the views */
143 void updateChildren( PLItem * );
144 void updateChildren( playlist_item_t *, PLItem * );
146 /* Deep actions (affect core playlist) */
147 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
148 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
151 int i_popup_item, i_popup_parent, i_popup_column;
152 QModelIndexList current_selection;
154 QSignalMapper *sortingMapper;
157 PLItem *findById( PLItem *, int ) const;
158 PLItem *findByInput( PLItem *, int ) const;
159 PLItem *findInner(PLItem *, int , bool ) const;
160 bool canEdit() const;
162 PLItem *p_cached_item;
163 PLItem *p_cached_item_bi;
165 int i_cached_input_id;
175 void popupSort( int column );
176 void processInputItemUpdate( input_item_t *);
177 void processInputItemUpdate( input_thread_t* p_input );
178 void processItemRemoval( int i_id );
179 void processItemAppend( int item, int parent );
182 class PlMimeData : public QMimeData
189 void appendItem( input_item_t *p_item );
190 QList<input_item_t*> inputItems() const;
191 QStringList formats () const;
194 QList<input_item_t*> _inputItems;
195 QMimeData *_mimeData;