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>
50 class PLModel : public QAbstractItemModel
57 PLModel( playlist_t *, intf_thread_t *,
58 playlist_item_t *, QObject *parent = 0 );
61 /*** QModel subclassing ***/
64 QVariant data( const QModelIndex &index, int role ) const;
65 QVariant headerData( int section, Qt::Orientation orientation,
66 int role = Qt::DisplayRole ) const;
67 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
68 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
69 Qt::ItemFlags flags( const QModelIndex &index ) const;
70 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
71 QModelIndex parent( const QModelIndex &index ) const;
74 Qt::DropActions supportedDropActions() const;
75 QMimeData* mimeData( const QModelIndexList &indexes ) const;
76 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
77 int row, int column, const QModelIndex &target );
78 QStringList mimeTypes() const;
83 QStringList selectedURIs();
84 QModelIndex index( PLItem *, int c ) const;
85 QModelIndex index( int i_id, int c );
86 QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
87 bool isCurrent( const QModelIndex &index ) const;
88 int itemId( const QModelIndex &index ) const;
91 void popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
92 void doDelete( QModelIndexList selected );
93 void search( const QString& search_text );
94 void sort( int column, Qt::SortOrder order );
95 void sort( int i_root_id, int column, Qt::SortOrder order );
96 void removeItem( int );
97 void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
99 inline PLItem *getItem( QModelIndex index ) const
101 if( index.isValid() )
102 return static_cast<PLItem*>( index.internalPointer() );
103 else return rootItem;
112 playlist_t *p_playlist;
113 intf_thread_t *p_intf;
116 static QIcon icons[ITEM_TYPE_NUMBER];
119 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
120 void doDeleteItem( PLItem *item, QModelIndexList *fullList );
121 void updateTreeItem( PLItem * );
122 void removeItem ( PLItem * );
123 void takeItem( PLItem * ); //will not delete item
124 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
125 void dropAppendCopy( QByteArray& data, PLItem *target );
126 void dropMove( QByteArray& data, PLItem *target, int new_pos );
127 /* The following actions will not signal the view! */
128 void updateChildren( PLItem * );
129 void updateChildren( playlist_item_t *, PLItem * );
132 int i_popup_item, i_popup_parent, i_popup_column;
133 QModelIndexList current_selection;
136 PLItem *findById( PLItem *, int );
137 PLItem *findByInput( PLItem *, int );
138 PLItem *findInner( PLItem *, int , bool );
140 int columnFromMeta( int meta_column ) const;
141 int columnToMeta( int column ) const;
142 bool canEdit() const;
143 PLItem *p_cached_item;
144 PLItem *p_cached_item_bi;
146 int i_cached_input_id;
149 void currentChanged( const QModelIndex& );
152 void activateItem( const QModelIndex &index );
153 void activateItem( playlist_item_t *p_item );
164 void popupSortDesc();
165 void processInputItemUpdate( input_item_t *);
166 void processInputItemUpdate( input_thread_t* p_input );
167 void processItemRemoval( int i_id );
168 void processItemAppend( int item, int parent );