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