]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_model.hpp
qt4: cosmetics and consistence
[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     /*** QModel subclassing ***/
94
95     /* Data structure */
96     QVariant data( const QModelIndex &index, int role ) const;
97     QVariant headerData( int section, Qt::Orientation orientation,
98                          int role = Qt::DisplayRole ) const;
99     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
100     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
101     Qt::ItemFlags flags( const QModelIndex &index ) const;
102     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
103     QModelIndex parent( const QModelIndex &index ) const;
104
105     /* Drag and Drop */
106     Qt::DropActions supportedDropActions() const;
107     QMimeData* mimeData( const QModelIndexList &indexes ) const;
108     bool dropMimeData( const QMimeData *data, Qt::DropAction action,
109                       int row, int column, const QModelIndex &target );
110     QStringList mimeTypes() const;
111
112     /**** Custom ****/
113
114     /* Lookups */
115     QStringList selectedURIs();
116     bool hasRandom(); bool hasLoop(); bool hasRepeat();
117     int shownFlags() { return i_showflags;  }
118     QModelIndex index( PLItem *, int c ) const;
119     QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
120     bool isCurrent( const QModelIndex &index ) const;
121     int itemId( const QModelIndex &index ) const;
122
123     /* Actions */
124     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
125     void doDelete( QModelIndexList selected );
126     void search( const QString& search_text );
127     void sort( int column, Qt::SortOrder order );
128     void sort( int i_root_id, int column, Qt::SortOrder order );
129     void removeItem( int );
130     void rebuild(); void rebuild( playlist_item_t * );
131
132 private:
133
134     /* General */
135     PLItem *rootItem;
136     PLItem *currentItem;
137
138     playlist_t *p_playlist;
139     intf_thread_t *p_intf;
140     int i_depth;
141     int i_showflags;
142
143     static QIcon icons[ITEM_TYPE_NUMBER];
144
145     /* Callbacks related */
146     void addCallbacks();
147     void delCallbacks();
148     void customEvent( QEvent * );
149     void processItemRemoval( int i_id );
150     void processItemAppend( const playlist_add_t *p_add );
151
152     /* Actions */
153     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
154     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
155     void updateTreeItem( PLItem *, bool, bool force = false );
156     void takeItem( PLItem * ); //will not delete item
157     void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
158     void dropAppendCopy( QByteArray& data, PLItem *target );
159     void dropMove( QByteArray& data, PLItem *target, int new_pos );
160     /* The following actions will not signal the view! */
161     void removeItem ( PLItem * );
162     void updateChildren( PLItem * );
163     void updateChildren( playlist_item_t *, PLItem * );
164
165     /* Popup */
166     int i_popup_item, i_popup_parent, i_popup_column;
167     QModelIndexList current_selection;
168     QSignalMapper *ContextUpdateMapper;
169
170     /* Lookups */
171     PLItem *findById( PLItem *, int );
172     PLItem *findByInput( PLItem *, int );
173     PLItem *findInner( PLItem *, int , bool );
174     static inline PLItem *getItem( QModelIndex index );
175     int metaColumn ( int column ) const;
176     PLItem *p_cached_item;
177     PLItem *p_cached_item_bi;
178     int i_cached_id;
179     int i_cached_input_id;
180
181 signals:
182     void shouldRemove( int );
183     void currentChanged( const QModelIndex& );
184     void columnsChanged( int );
185
186
187 public slots:
188     void activateItem( const QModelIndex &index );
189     void activateItem( playlist_item_t *p_item );
190     void setRandom( bool );
191     void setLoop( bool );
192     void setRepeat( bool );
193
194 private slots:
195     void popupPlay();
196     void popupDel();
197     void popupInfo();
198     void popupStream();
199     void popupSave();
200     void popupExplore();
201     void popupAddNode();
202     void popupSortAsc();
203     void popupSortDesc();
204     void viewchanged( int );
205     void processInputItemUpdate( input_item_t *);
206     void processInputItemUpdate( input_thread_t* p_input );
207 };
208
209 #endif