1 /*****************************************************************************
2 * playlist_model.hpp : Model for a playlist tree
3 ****************************************************************************
4 * Copyright (C) 2006-2011 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_
32 #include <vlc_input.h>
33 #include <vlc_playlist.h>
34 #include "vlc_model.hpp"
35 #include "playlist_item.hpp"
39 #include <QSignalMapper>
41 #include <QAbstractItemModel>
43 #include <QModelIndex>
49 class PLModel : public VLCModel
54 PLModel( playlist_t *, intf_thread_t *,
55 playlist_item_t *, QObject *parent = 0 );
59 static PLModel* getPLModel( intf_thread_t *p_intf )
61 if(!p_intf->p_sys->pl_model )
63 playlist_Lock( THEPL );
64 playlist_item_t *p_root = THEPL->p_playing;
65 playlist_Unlock( THEPL );
66 p_intf->p_sys->pl_model = new PLModel( THEPL, p_intf, p_root, NULL );
69 return p_intf->p_sys->pl_model;
72 /*** QAbstractItemModel subclassing ***/
75 QVariant data( const QModelIndex &index, const int role ) const Q_DECL_OVERRIDE;
76 int rowCount( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
77 Qt::ItemFlags flags( const QModelIndex &index ) const Q_DECL_OVERRIDE;
78 QModelIndex index( const int r, const int c, const QModelIndex &parent ) const Q_DECL_OVERRIDE;
79 QModelIndex parent( const QModelIndex &index ) const Q_DECL_OVERRIDE;
82 Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
83 QMimeData* mimeData( const QModelIndexList &indexes ) const Q_DECL_OVERRIDE;
84 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
85 int row, int column, const QModelIndex &target );
86 QStringList mimeTypes() const Q_DECL_OVERRIDE;
89 void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder ) Q_DECL_OVERRIDE;
91 /*** VLCModelSubInterface subclassing ***/
92 void rebuild( playlist_item_t * p = NULL ) Q_DECL_OVERRIDE;
93 void doDelete( QModelIndexList selected ) Q_DECL_OVERRIDE;
94 void createNode( QModelIndex index, QString name ) Q_DECL_OVERRIDE;
95 void renameNode( QModelIndex index, QString name ) Q_DECL_OVERRIDE;
99 QModelIndex rootIndex() const Q_DECL_OVERRIDE;
100 void filter( const QString& search_text, const QModelIndex & root, bool b_recursive ) Q_DECL_OVERRIDE;
101 QModelIndex currentIndex() const Q_DECL_OVERRIDE;
102 QModelIndex indexByPLID( const int i_plid, const int c ) const Q_DECL_OVERRIDE;
103 QModelIndex indexByInputItemID( const int i_inputitem_id, const int c ) const Q_DECL_OVERRIDE;
104 bool isTree() const Q_DECL_OVERRIDE;
105 bool canEdit() const Q_DECL_OVERRIDE;
106 bool action( QAction *action, const QModelIndexList &indexes ) Q_DECL_OVERRIDE;
107 bool isSupportedAction( actions action, const QModelIndex & ) const Q_DECL_OVERRIDE;
110 /* VLCModel subclassing */
111 bool isParent( const QModelIndex &index, const QModelIndex ¤t) const;
112 bool isLeaf( const QModelIndex &index ) const;
113 PLItem *getItem( const QModelIndex & index ) const;
119 playlist_t *p_playlist;
121 /* Custom model private methods */
123 QModelIndex index( PLItem *, const int c ) const;
125 /* Shallow actions (do not affect core playlist) */
126 void updateTreeItem( PLItem * );
127 void removeItem ( PLItem * );
128 void recurseDelete( QList<AbstractPLItem*> children, QModelIndexList *fullList );
129 void takeItem( PLItem * ); //will not delete item
130 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
131 /* ...of which the following will not update the views */
132 void updateChildren( PLItem * );
133 void updateChildren( playlist_item_t *, PLItem * );
135 /* Deep actions (affect core playlist) */
136 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
137 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
140 void sort( QModelIndex caller, QModelIndex rootIndex, const int column, Qt::SortOrder order );
143 PLItem *findByPLId( PLItem *, int i_plitemid ) const;
144 PLItem *findByInputId( PLItem *, int i_input_itemid ) const;
145 PLItem *findInner(PLItem *, int i_id, bool b_isinputid ) const;
148 ROOTTYPE_CURRENT_PLAYING,
149 ROOTTYPE_MEDIA_LIBRARY,
152 pl_nodetype getPLRootType() const;
155 QString latestSearch;
158 void processInputItemUpdate( input_item_t *);
159 void processInputItemUpdate();
160 void processItemRemoval( int i_pl_itemid );
161 void processItemAppend( int i_pl_itemid, int i_pl_itemidparent );
162 void activateItem( playlist_item_t *p_item );
163 void activateItem( const QModelIndex &index );
166 class PlMimeData : public QMimeData
172 virtual ~PlMimeData();
173 void appendItem( input_item_t *p_item );
174 QList<input_item_t*> inputItems() const;
175 QStringList formats () const;
178 QList<input_item_t*> _inputItems;
179 QMimeData *_mimeData;