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_
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>
50 class PLModel : public VLCModel
55 PLModel( playlist_t *, intf_thread_t *,
56 playlist_item_t *, QObject *parent = 0 );
59 /*** QModel subclassing ***/
62 virtual QVariant data( const QModelIndex &index, const int role ) const;
63 virtual QVariant headerData( int section, Qt::Orientation orientation,
64 int role = Qt::DisplayRole ) const;
65 virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
66 virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
67 virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
68 virtual QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
69 virtual QModelIndex parent( const QModelIndex &index ) const;
72 virtual Qt::DropActions supportedDropActions() const;
73 virtual QMimeData* mimeData( const QModelIndexList &indexes ) const;
74 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action,
75 int row, int column, const QModelIndex &target );
76 virtual QStringList mimeTypes() const;
81 QStringList selectedURIs();
82 QModelIndex index( PLItem *, const int c ) const;
83 QModelIndex index( const int i_id, const int c );
84 virtual QModelIndex currentIndex() const;
85 bool isParent( const QModelIndex &index, const QModelIndex ¤t) const;
86 bool isCurrent( const QModelIndex &index ) const;
87 int itemId( const QModelIndex &index ) const;
90 virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
91 virtual void doDelete( QModelIndexList selected );
92 void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
93 void sort( const int column, Qt::SortOrder order );
94 void sort( const int i_root_id, const int column, Qt::SortOrder order );
96 void rebuild( playlist_item_t * );
98 inline PLItem *getItem( QModelIndex index ) const
100 if( index.isValid() )
101 return static_cast<PLItem*>( index.internalPointer() );
102 else return rootItem;
104 virtual int getId( QModelIndex index ) const
106 return getItem( index )->id();
110 void currentChanged( const QModelIndex& );
114 virtual void activateItem( const QModelIndex &index );
115 void activateItem( playlist_item_t *p_item );
121 playlist_t *p_playlist;
123 static QIcon icons[ITEM_TYPE_NUMBER];
125 /* Shallow actions (do not affect core playlist) */
126 void updateTreeItem( PLItem * );
127 void removeItem ( PLItem * );
128 void removeItem( int );
129 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
130 void takeItem( PLItem * ); //will not delete item
131 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
132 /* ...of which the following will not update the views */
133 void updateChildren( PLItem * );
134 void updateChildren( playlist_item_t *, PLItem * );
136 /* Deep actions (affect core playlist) */
137 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
138 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
141 int i_popup_item, i_popup_parent, i_popup_column;
142 QModelIndexList current_selection;
144 QSignalMapper *sortingMapper;
147 PLItem *findById( PLItem *, int ) const;
148 PLItem *findByInput( PLItem *, int ) const;
149 PLItem *findInner(PLItem *, int , bool ) const;
150 bool canEdit() const;
152 PLItem *p_cached_item;
153 PLItem *p_cached_item_bi;
155 int i_cached_input_id;
165 void popupSort( int column );
166 void processInputItemUpdate( input_item_t *);
167 void processInputItemUpdate( input_thread_t* p_input );
168 void processItemRemoval( int i_id );
169 void processItemAppend( int item, int parent );
172 class PlMimeData : public QMimeData
179 void appendItem( input_item_t *p_item );
180 QList<input_item_t*> inputItems() const;
181 QStringList formats () const;
184 QList<input_item_t*> _inputItems;
185 QMimeData *_mimeData;