Qt: PLModel::removeItem( int ) is not for public usage
[vlc.git] / modules / gui / qt4 / components / playlist / playlist_model.hpp
blob19f704b1e4ab345365820c832d30877c6cf54cff
1 /*****************************************************************************
2 * playlist_model.hpp : Model for a playlist tree
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id$
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_
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include "qt4.hpp"
34 #include <vlc_input.h>
35 #include <vlc_playlist.h>
37 #include "playlist_item.hpp"
39 #include <QModelIndex>
40 #include <QObject>
41 #include <QEvent>
42 #include <QMimeData>
43 #include <QSignalMapper>
44 #include <QAbstractItemModel>
45 #include <QVariant>
47 class QSignalMapper;
48 class PLItem;
50 class PLModel : public QAbstractItemModel
52 Q_OBJECT
54 friend class PLItem;
56 public:
57 enum {
58 IsCurrentRole = Qt::UserRole
61 PLModel( playlist_t *, intf_thread_t *,
62 playlist_item_t *, QObject *parent = 0 );
63 ~PLModel();
65 /*** QModel subclassing ***/
67 /* Data structure */
68 QVariant data( const QModelIndex &index, int role ) const;
69 QVariant headerData( int section, Qt::Orientation orientation,
70 int role = Qt::DisplayRole ) const;
71 int rowCount( const QModelIndex &parent = QModelIndex() ) const;
72 int columnCount( const QModelIndex &parent = QModelIndex() ) const;
73 Qt::ItemFlags flags( const QModelIndex &index ) const;
74 QModelIndex index( int r, int c, const QModelIndex &parent ) const;
75 QModelIndex parent( const QModelIndex &index ) const;
77 /* Drag and Drop */
78 Qt::DropActions supportedDropActions() const;
79 QMimeData* mimeData( const QModelIndexList &indexes ) const;
80 bool dropMimeData( const QMimeData *data, Qt::DropAction action,
81 int row, int column, const QModelIndex &target );
82 QStringList mimeTypes() const;
84 /**** Custom ****/
86 /* Lookups */
87 QStringList selectedURIs();
88 QModelIndex index( PLItem *, int c ) const;
89 QModelIndex index( int i_id, int c );
90 QModelIndex currentIndex();
91 bool isCurrent( const QModelIndex &index ) const;
92 int itemId( const QModelIndex &index ) const;
94 /* Actions */
95 void popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
96 void doDelete( QModelIndexList selected );
97 void search( const QString& search_text );
98 void sort( int column, Qt::SortOrder order );
99 void sort( int i_root_id, int column, Qt::SortOrder order );
100 void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
102 inline PLItem *getItem( QModelIndex index ) const
104 if( index.isValid() )
105 return static_cast<PLItem*>( index.internalPointer() );
106 else return rootItem;
109 private:
111 /* General */
112 PLItem *rootItem;
114 playlist_t *p_playlist;
115 intf_thread_t *p_intf;
116 int i_depth;
118 static QIcon icons[ITEM_TYPE_NUMBER];
120 /* Actions */
121 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
122 void updateTreeItem( PLItem * );
123 void removeItem ( PLItem * );
124 void removeItem( int );
125 void takeItem( PLItem * ); //will not delete item
126 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
127 void dropAppendCopy( QByteArray& data, PLItem *target );
128 void dropMove( QByteArray& data, PLItem *target, int new_pos );
129 /* The following actions will not signal the view! */
130 void updateChildren( PLItem * );
131 void updateChildren( playlist_item_t *, PLItem * );
133 /* Popup */
134 int i_popup_item, i_popup_parent, i_popup_column;
135 QModelIndexList current_selection;
137 /* Lookups */
138 PLItem *findById( PLItem *, int );
139 PLItem *findByInput( PLItem *, int );
140 PLItem *findInner( PLItem *, int , bool );
142 int columnFromMeta( int meta_column ) const;
143 int columnToMeta( int column ) const;
144 bool canEdit() const;
145 PLItem *p_cached_item;
146 PLItem *p_cached_item_bi;
147 int i_cached_id;
148 int i_cached_input_id;
150 signals:
151 void currentChanged( const QModelIndex& );
152 void rootChanged();
154 public slots:
155 void activateItem( const QModelIndex &index );
156 void activateItem( playlist_item_t *p_item );
158 private slots:
159 void popupPlay();
160 void popupDel();
161 void popupInfo();
162 void popupStream();
163 void popupSave();
164 void popupExplore();
165 void popupAddNode();
166 void popupSortAsc();
167 void popupSortDesc();
168 void processInputItemUpdate( input_item_t *);
169 void processInputItemUpdate( input_thread_t* p_input );
170 void processItemRemoval( int i_id );
171 void processItemAppend( int item, int parent );
174 #endif