]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.hpp
Add missing actions in popup
[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 <QModelIndex>
28 #include <QObject>
29 #include <QEvent>
30
31 #include <vlc/vlc.h>
32 #include <vlc/input.h>
33 #include <vlc_playlist.h>
34
35 class PLModel;
36
37 class PLItem
38 {
39 public:
40     PLItem( int, int, PLItem *parent , PLModel *);
41     PLItem( playlist_item_t *, PLItem *parent, PLModel *);
42     ~PLItem();
43
44     int row() const;
45     void insertChild( PLItem *, int p, bool signal = true );
46
47     void appendChild( PLItem *item, bool signal = true )
48     {
49         insertChild( item, children.count(), signal );
50     };
51     void remove( PLItem *removed );
52     PLItem *child( int row ) { return children.value( row ); };
53     int childCount() const { return children.count(); };
54     QString columnString( int col ) { return strings.value( col ); };
55     PLItem *parent() { return parentItem; };
56
57     void update( playlist_item_t *, bool);
58 protected:
59     QList<PLItem*> children;
60     QList<QString> strings;
61     bool current;
62     int type;
63     int i_id;
64     int i_input_id;
65     friend class PLModel;
66 private:
67     void init( int, int, PLItem *, PLModel * );
68     PLItem *parentItem;
69     PLModel *model;
70 };
71
72 static int ItemUpdate_Type = QEvent::User + 2;
73 static int ItemDelete_Type = QEvent::User + 3;
74 static int ItemAppend_Type = QEvent::User + 4;
75
76 class PLEvent : public QEvent
77 {
78 public:
79     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
80     { i_id = id; p_add = NULL; };
81     PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
82     { p_add = a; };
83     virtual ~PLEvent() {};
84
85     int i_id;
86     playlist_add_t *p_add;
87 };
88
89 #include <QAbstractItemModel>
90 #include <QVariant>
91
92 class PLModel : public QAbstractItemModel
93 {
94     Q_OBJECT
95
96 public:
97     PLModel( playlist_t *, playlist_item_t *, int, QObject *parent = 0);
98     ~PLModel();
99
100     /* All types of lookups / QModel stuff */
101     QVariant data( const QModelIndex &index, int role) const;
102     Qt::ItemFlags flags( const QModelIndex &index) const;
103     QVariant headerData( int section, Qt::Orientation orientation,
104                          int role = Qt::DisplayRole) const;
105     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
106     QModelIndex index( PLItem *, int c ) const;
107     int itemId( const QModelIndex &index ) const;
108     bool isCurrent( const QModelIndex &index );
109     QModelIndex parent( const QModelIndex &index) const;
110     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
111     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
112     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
113
114     bool b_need_update;
115     int i_items_to_append;
116     void rebuild(); void rebuild( playlist_item_t *);
117     bool hasRandom(); bool hasLoop(); bool hasRepeat();
118
119     /* Actions made by the views */
120     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
121     void doDelete( QModelIndexList selected );
122     void search( QString search );
123     void sort( int column, Qt::SortOrder order );
124 private:
125     void addCallbacks();
126     void delCallbacks();
127     void customEvent( QEvent * );
128
129     PLItem *rootItem;
130
131     playlist_t *p_playlist;
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
154     /* Lookups */
155     PLItem *FindById( PLItem *, int );
156     PLItem *FindByInput( PLItem *, int );
157     PLItem *FindInner( PLItem *, int , bool );
158     PLItem *p_cached_item;
159     PLItem *p_cached_item_bi;
160     int i_cached_id;
161     int i_cached_input_id;
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 private slots:
169     void popupPlay();
170     void popupDel();
171     void popupInfo();
172     void popupStream();
173     void popupSave();
174 friend class PLItem;
175 };
176
177 #endif