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