]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.hpp
remove unused artSet signal in playlist_model (changed to input-manager
[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
70     void updateview( void );
71     friend class PLModel;
72 private:
73     void init( int, int, PLItem *, PLModel * );
74     PLItem *parentItem;
75     PLModel *model;
76 };
77
78 static int ItemUpdate_Type = QEvent::User + 2;
79 static int ItemDelete_Type = QEvent::User + 3;
80 static int ItemAppend_Type = QEvent::User + 4;
81 static int PLUpdate_Type = QEvent::User + 5;
82
83 class PLEvent : public QEvent
84 {
85 public:
86     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
87     { i_id = id; p_add = NULL; };
88     PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
89     { p_add = a; };
90     virtual ~PLEvent() {};
91
92     int i_id;
93     playlist_add_t *p_add;
94 };
95
96 #include <QAbstractItemModel>
97 #include <QVariant>
98
99 class PLModel : public QAbstractItemModel
100 {
101     Q_OBJECT
102
103 public:
104     PLModel( playlist_t *, intf_thread_t *,
105              playlist_item_t *, int, QObject *parent = 0 );
106     ~PLModel();
107
108     /* All types of lookups / QModel stuff */
109     QVariant data( const QModelIndex &index, int role ) const;
110     Qt::ItemFlags flags( const QModelIndex &index ) const;
111     QVariant headerData( int section, Qt::Orientation orientation,
112                          int role = Qt::DisplayRole ) const;
113     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
114     QModelIndex index( PLItem *, int c ) const;
115     int itemId( const QModelIndex &index ) const;
116     bool isCurrent( const QModelIndex &index );
117     QModelIndex parent( const QModelIndex &index ) const;
118     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
119     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
120     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
121
122     bool b_need_update;
123     int i_items_to_append;
124
125     void rebuild(); void rebuild( playlist_item_t * );
126     bool hasRandom(); bool hasLoop(); bool hasRepeat();
127
128     /* Actions made by the views */
129     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
130     void doDelete( QModelIndexList selected );
131     void search( QString search );
132     void sort( int column, Qt::SortOrder order );
133     void removeItem( int );
134
135     /* DnD handling */
136     Qt::DropActions supportedDropActions() const;
137     QMimeData* mimeData( const QModelIndexList &indexes ) const;
138     bool dropMimeData( const QMimeData *data, Qt::DropAction action,
139                       int row, int column, const QModelIndex &target );
140     QStringList mimeTypes() const;
141
142     int shownFlags() {  return rootItem->i_showflags;  }
143 private:
144     void addCallbacks();
145     void delCallbacks();
146     void customEvent( QEvent * );
147
148     PLItem *rootItem;
149
150     playlist_t *p_playlist;
151     intf_thread_t *p_intf;
152     int i_depth;
153
154     static QIcon icons[ITEM_TYPE_NUMBER];
155
156     /* Update processing */
157     void ProcessInputItemUpdate( int i_input_id );
158     void ProcessItemRemoval( int i_id );
159     void ProcessItemAppend( playlist_add_t *p_add );
160
161     void UpdateTreeItem( PLItem *, bool, bool force = false );
162     void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
163     void UpdateNodeChildren( PLItem * );
164     void UpdateNodeChildren( playlist_item_t *, PLItem * );
165
166     /* Actions */
167     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
168     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
169
170     /* Popup */
171     int i_popup_item, i_popup_parent;
172     QModelIndexList current_selection;
173     QSignalMapper *ContextUpdateMapper;
174
175     /* Lookups */
176     PLItem *FindById( PLItem *, int );
177     PLItem *FindByInput( PLItem *, int );
178     PLItem *FindInner( PLItem *, int , bool );
179     PLItem *p_cached_item;
180     PLItem *p_cached_item_bi;
181     int i_cached_id;
182     int i_cached_input_id;
183 signals:
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 #ifdef WIN32
198     void popupExplore();
199 #endif
200     void viewchanged( int );
201 friend class PLItem;
202 };
203
204 #endif