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,
65 PLModel( playlist_t *, intf_thread_t *,
66 playlist_item_t *, QObject *parent = 0 );
69 /*** QModel subclassing ***/
72 QVariant data( const QModelIndex &index, int role ) const;
73 QVariant headerData( int section, Qt::Orientation orientation,
74 int role = Qt::DisplayRole ) const;
75 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
76 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
77 Qt::ItemFlags flags( const QModelIndex &index ) const;
78 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
79 QModelIndex parent( const QModelIndex &index ) const;
82 Qt::DropActions supportedDropActions() const;
83 QMimeData* mimeData( const QModelIndexList &indexes ) const;
84 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
85 int row, int column, const QModelIndex &target );
86 QStringList mimeTypes() const;
91 QStringList selectedURIs();
92 QModelIndex index( PLItem *, int c ) const;
93 QModelIndex index( int i_id, int c );
94 QModelIndex currentIndex();
95 bool isCurrent( const QModelIndex &index ) const;
96 int itemId( const QModelIndex &index ) const;
97 static int columnFromMeta( int meta_column );
98 static int columnToMeta( int column );
101 bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
102 void doDelete( QModelIndexList selected );
103 void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
104 void sort( int column, Qt::SortOrder order );
105 void sort( int i_root_id, int column, Qt::SortOrder order );
107 void rebuild( playlist_item_t * );
109 inline PLItem *getItem( QModelIndex index ) const
111 if( index.isValid() )
112 return static_cast<PLItem*>( index.internalPointer() );
113 else return rootItem;
117 void currentChanged( const QModelIndex& );
121 void activateItem( const QModelIndex &index );
122 void activateItem( playlist_item_t *p_item );
128 playlist_t *p_playlist;
129 intf_thread_t *p_intf;
131 static QIcon icons[ITEM_TYPE_NUMBER];
133 /* Shallow actions (do not affect core playlist) */
134 void updateTreeItem( PLItem * );
135 void removeItem ( PLItem * );
136 void removeItem( int );
137 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
138 void takeItem( PLItem * ); //will not delete item
139 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
140 /* ...of which the following will not update the views */
141 void updateChildren( PLItem * );
142 void updateChildren( playlist_item_t *, PLItem * );
144 /* Deep actions (affect core playlist) */
145 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
146 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
149 int i_popup_item, i_popup_parent, i_popup_column;
150 QModelIndexList current_selection;
152 QSignalMapper *sortingMapper;
155 PLItem *findById( PLItem *, int );
156 PLItem *findByInput( PLItem *, int );
157 PLItem *findInner( PLItem *, int , bool );
158 bool canEdit() const;
160 PLItem *p_cached_item;
161 PLItem *p_cached_item_bi;
163 int i_cached_input_id;
173 void popupSort( int column );
174 void processInputItemUpdate( input_item_t *);
175 void processInputItemUpdate( input_thread_t* p_input );
176 void processItemRemoval( int i_id );
177 void processItemAppend( int item, int parent );
180 class PlMimeData : public QMimeData
187 void appendItem( input_item_t *p_item );
188 QList<input_item_t*> inputItems() const;
189 QStringList formats () const;
192 QList<input_item_t*> _inputItems;
193 QMimeData *_mimeData;