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