]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.hpp
Qt4 : build fix.
[vlc] / modules / gui / qt4 / 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 #include <vlc/vlc.h>
28 #include <vlc_input.h>
29 #include <vlc_playlist.h>
30
31 #include <QModelIndex>
32 #include <QObject>
33 #include <QEvent>
34 #include <QMimeData>
35 #include <QSignalMapper>
36
37 class PLModel;
38 class QSignalMapper;
39
40 class PLItem
41 {
42 public:
43     PLItem( int, int, PLItem *parent , PLModel *);
44     PLItem( playlist_item_t *, PLItem *parent, PLModel *);
45     ~PLItem();
46
47     int row() const;
48     void insertChild( PLItem *, int p, bool signal = true );
49
50     void appendChild( PLItem *item, bool signal = true )
51     {
52         insertChild( item, children.count(), signal );
53     };
54     void remove( PLItem *removed );
55     PLItem *child( int row ) { return children.value( row ); };
56     int childCount() const { return children.count(); };
57     QString columnString( int col ) { return strings.value( col ); };
58     PLItem *parent() { return parentItem; };
59
60     void update( playlist_item_t *, bool);
61 protected:
62     QList<PLItem*> children;
63     QList<QString> strings;
64     bool current;
65     int type;
66     int i_id;
67     int i_input_id;
68     int i_showflags;
69     void updateview( void );
70     friend class PLModel;
71 private:
72     void init( int, int, PLItem *, PLModel * );
73     PLItem *parentItem;
74     PLModel *model;
75 };
76
77 static int ItemUpdate_Type = QEvent::User + 2;
78 static int ItemDelete_Type = QEvent::User + 3;
79 static int ItemAppend_Type = QEvent::User + 4;
80 static int PLUpdate_Type = QEvent::User + 5;
81
82 class PLEvent : public QEvent
83 {
84 public:
85     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
86     { i_id = id; p_add = NULL; };
87     PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
88     { p_add = a; };
89     virtual ~PLEvent() {};
90
91     int i_id;
92     playlist_add_t *p_add;
93 };
94
95 #include <QAbstractItemModel>
96 #include <QVariant>
97
98 class PLModel : public QAbstractItemModel
99 {
100     Q_OBJECT
101
102 public:
103     PLModel( playlist_t *, intf_thread_t *,
104              playlist_item_t *, int, QObject *parent = 0);
105     ~PLModel();
106
107     /* All types of lookups / QModel stuff */
108     QVariant data( const QModelIndex &index, int role) const;
109     Qt::ItemFlags flags( const QModelIndex &index) const;
110     QVariant headerData( int section, Qt::Orientation orientation,
111                          int role = Qt::DisplayRole) const;
112     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
113     QModelIndex index( PLItem *, int c ) const;
114     int itemId( const QModelIndex &index ) const;
115     bool isCurrent( const QModelIndex &index );
116     QModelIndex parent( const QModelIndex &index) const;
117     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
118     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
119     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
120
121     bool b_need_update;
122     int i_items_to_append;
123     void rebuild(); void rebuild( playlist_item_t *);
124     bool hasRandom(); bool hasLoop(); bool hasRepeat();
125
126     /* Actions made by the views */
127     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
128     void doDelete( QModelIndexList selected );
129     void search( QString search );
130     void sort( int column, Qt::SortOrder order );
131     void removeItem( int );
132
133     /* DnD handling */
134     Qt::DropActions supportedDropActions() const;
135     QMimeData* mimeData(const QModelIndexList &indexes) const;
136     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
137                       int row, int column, const QModelIndex &target);
138     QStringList mimeTypes() const;
139
140     void sendArt( QString url );
141     void removeArt( );
142 private:
143     void addCallbacks();
144     void delCallbacks();
145     void customEvent( QEvent * );
146
147     PLItem *rootItem;
148
149     playlist_t *p_playlist;
150     intf_thread_t *p_intf;
151     int i_depth;
152
153     static QIcon icons[ITEM_TYPE_NUMBER];
154
155     /* Update processing */
156     void ProcessInputItemUpdate( int i_input_id );
157     void ProcessItemRemoval( int i_id );
158     void ProcessItemAppend( playlist_add_t *p_add );
159
160     void UpdateTreeItem( PLItem *, bool, bool force = false );
161     void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
162     void UpdateNodeChildren( PLItem * );
163     void UpdateNodeChildren( playlist_item_t *, PLItem * );
164
165     /* Actions */
166     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
167     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
168
169     /* Popup */
170     int i_popup_item, i_popup_parent;
171     QModelIndexList current_selection;
172     QSignalMapper *ContextUpdateMapper;
173
174     /* Lookups */
175     PLItem *FindById( PLItem *, int );
176     PLItem *FindByInput( PLItem *, int );
177     PLItem *FindInner( PLItem *, int , bool );
178     PLItem *p_cached_item;
179     PLItem *p_cached_item_bi;
180     int i_cached_id;
181     int i_cached_input_id;
182 signals:
183     void artSet( QString );
184     void shouldRemove( int );
185 public slots:
186     void activateItem( const QModelIndex &index );
187     void activateItem( playlist_item_t *p_item );
188     void setRandom( bool );
189     void setLoop( bool );
190     void setRepeat( bool );
191 private slots:
192     void popupPlay();
193     void popupDel();
194     void popupInfo();
195     void popupStream();
196     void popupSave();
197     void viewchanged( int );
198 friend class PLItem;
199 };
200
201 #endif