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"
40 #include <QAbstractItemModel>
42 #include <QModelIndex>
49 class PLModel : public QAbstractItemModel
55 IsCurrentRole = Qt::UserRole,
57 IsCurrentsParentNodeRole
60 PLModel( playlist_t *, intf_thread_t *,
61 playlist_item_t *, QObject *parent = 0 );
64 /*** QModel subclassing ***/
67 virtual QVariant data( const QModelIndex &index, const int role ) const;
68 virtual QVariant headerData( int section, Qt::Orientation orientation,
69 int role = Qt::DisplayRole ) const;
70 virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
71 virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
72 virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
73 virtual QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
74 virtual QModelIndex parent( const QModelIndex &index ) const;
77 virtual Qt::DropActions supportedDropActions() const;
78 virtual QMimeData* mimeData( const QModelIndexList &indexes ) const;
79 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action,
80 int row, int column, const QModelIndex &target );
81 virtual QStringList mimeTypes() const;
86 QStringList selectedURIs();
87 QModelIndex index( PLItem *, const int c ) const;
88 QModelIndex index( const int i_id, const int c );
89 QModelIndex currentIndex() const;
90 bool isParent( const QModelIndex &index, const QModelIndex ¤t) const;
91 bool isCurrent( const QModelIndex &index ) const;
92 int itemId( const QModelIndex &index ) const;
93 static int columnFromMeta( int meta_column );
94 static int columnToMeta( int column );
96 static QString getMeta( const QModelIndex & index, int meta );
97 static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
100 bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
101 void doDelete( QModelIndexList selected );
102 void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
103 void sort( const int column, Qt::SortOrder order );
104 void sort( const int i_root_id, const int column, Qt::SortOrder order );
106 void rebuild( playlist_item_t * );
108 inline PLItem *getItem( QModelIndex index ) const
110 if( index.isValid() )
111 return static_cast<PLItem*>( index.internalPointer() );
112 else return rootItem;
116 void currentChanged( const QModelIndex& );
120 void activateItem( const QModelIndex &index );
121 void activateItem( playlist_item_t *p_item );
127 playlist_t *p_playlist;
128 intf_thread_t *p_intf;
130 static QIcon icons[ITEM_TYPE_NUMBER];
132 /* Shallow actions (do not affect core playlist) */
133 void updateTreeItem( PLItem * );
134 void removeItem ( PLItem * );
135 void removeItem( int );
136 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
137 void takeItem( PLItem * ); //will not delete item
138 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
139 /* ...of which the following will not update the views */
140 void updateChildren( PLItem * );
141 void updateChildren( playlist_item_t *, PLItem * );
143 /* Deep actions (affect core playlist) */
144 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
145 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
148 int i_popup_item, i_popup_parent, i_popup_column;
149 QModelIndexList current_selection;
151 QSignalMapper *sortingMapper;
154 PLItem *findById( PLItem *, int ) const;
155 PLItem *findByInput( PLItem *, int ) const;
156 PLItem *findInner(PLItem *, int , bool ) const;
157 bool canEdit() const;
159 PLItem *p_cached_item;
160 PLItem *p_cached_item_bi;
162 int i_cached_input_id;
172 void popupSort( int column );
173 void processInputItemUpdate( input_item_t *);
174 void processInputItemUpdate( input_thread_t* p_input );
175 void processItemRemoval( int i_id );
176 void processItemAppend( int item, int parent );
179 class PlMimeData : public QMimeData
186 void appendItem( input_item_t *p_item );
187 QList<input_item_t*> inputItems() const;
188 QStringList formats () const;
191 QList<input_item_t*> _inputItems;
192 QMimeData *_mimeData;