]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_model.hpp
Revert "Qt4: remove b_current on PLItem, and store currentIndex when it changes"
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
1 /*****************************************************************************
2  * playlist_model.hpp : Model for a playlist tree
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef _PLAYLIST_MODEL_H_
25 #define _PLAYLIST_MODEL_H_
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include "qt4.hpp"
32
33 #include <vlc_input.h>
34 #include <vlc_playlist.h>
35
36 #include "playlist_item.hpp"
37
38 #include <QModelIndex>
39 #include <QObject>
40 #include <QEvent>
41 #include <QMimeData>
42 #include <QSignalMapper>
43 #include <QAbstractItemModel>
44 #include <QVariant>
45
46 class QSignalMapper;
47
48 class PLItem;
49
50 #define DEPTH_PL -1
51 #define DEPTH_SEL 1
52
53 enum {
54     ItemUpdate_Type = QEvent::User + PLEventType + 2,
55     ItemDelete_Type = QEvent::User + PLEventType + 3,
56     ItemAppend_Type = QEvent::User + PLEventType + 4,
57     PLUpdate_Type   = QEvent::User + PLEventType + 5,
58 };
59
60 class PLEvent : public QEvent
61 {
62 public:
63     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
64     {
65         i_id = id;
66         add.i_node = -1;
67         add.i_item = -1;
68     };
69
70     PLEvent( const playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
71     {
72         add = *a;
73     };
74
75     virtual ~PLEvent() { };
76
77     int i_id;
78     playlist_add_t add;
79 };
80
81
82 class PLModel : public QAbstractItemModel
83 {
84     Q_OBJECT
85
86 friend class PLItem;
87
88 public:
89     PLModel( playlist_t *, intf_thread_t *,
90              playlist_item_t *, int, QObject *parent = 0 );
91     ~PLModel();
92
93     /* All types of lookups / QModel stuff */
94     QVariant data( const QModelIndex &index, int role ) const;
95     Qt::ItemFlags flags( const QModelIndex &index ) const;
96     QVariant headerData( int section, Qt::Orientation orientation,
97                          int role = Qt::DisplayRole ) const;
98     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
99     QModelIndex index( PLItem *, int c ) const;
100     int itemId( const QModelIndex &index ) const;
101     bool isCurrent( const QModelIndex &index );
102     QModelIndex parent( const QModelIndex &index ) const;
103     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
104     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
105     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
106
107     /* Get current selection */
108     QStringList selectedURIs();
109
110     void rebuild(); void rebuild( playlist_item_t * );
111     bool hasRandom(); bool hasLoop(); bool hasRepeat();
112
113     /* Actions made by the views */
114     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
115     void doDelete( QModelIndexList selected );
116     void search( const QString& search_text );
117     void sort( int column, Qt::SortOrder order );
118     void removeItem( int );
119
120     /* DnD handling */
121     Qt::DropActions supportedDropActions() const;
122     QMimeData* mimeData( const QModelIndexList &indexes ) const;
123     bool dropMimeData( const QMimeData *data, Qt::DropAction action,
124                       int row, int column, const QModelIndex &target );
125     QStringList mimeTypes() const;
126
127     int shownFlags() { return rootItem->i_showflags;  }
128
129 private:
130     void addCallbacks();
131     void delCallbacks();
132     void customEvent( QEvent * );
133
134     PLItem *rootItem;
135
136     playlist_t *p_playlist;
137     intf_thread_t *p_intf;
138     int i_depth;
139
140     static QIcon icons[ITEM_TYPE_NUMBER];
141
142     /* Update processing */
143     void ProcessItemRemoval( int i_id );
144     void ProcessItemAppend( const playlist_add_t *p_add );
145
146     void UpdateTreeItem( PLItem *, bool, bool force = false );
147     void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
148     void UpdateNodeChildren( PLItem * );
149     void UpdateNodeChildren( playlist_item_t *, PLItem * );
150
151     /* Actions */
152     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
153     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
154
155     /* Popup */
156     int i_popup_item, i_popup_parent;
157     QModelIndexList current_selection;
158     QSignalMapper *ContextUpdateMapper;
159
160     /* Lookups */
161     PLItem *FindById( PLItem *, int );
162     PLItem *FindByInput( PLItem *, int );
163     PLItem *FindInner( PLItem *, int , bool );
164     PLItem *p_cached_item;
165     PLItem *p_cached_item_bi;
166     int i_cached_id;
167     int i_cached_input_id;
168 signals:
169     void shouldRemove( int );
170     void currentChanged( const QModelIndex& );
171     void columnsChanged( int );
172
173
174 public slots:
175     void activateItem( const QModelIndex &index );
176     void activateItem( playlist_item_t *p_item );
177     void setRandom( bool );
178     void setLoop( bool );
179     void setRepeat( bool );
180
181 private slots:
182     void popupPlay();
183     void popupDel();
184     void popupInfo();
185     void popupStream();
186     void popupSave();
187     void popupExplore();
188     void viewchanged( int );
189     void ProcessInputItemUpdate( input_item_t *);
190     void ProcessInputItemUpdate( input_thread_t* p_input );
191 };
192
193 #endif