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