]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.hpp
Find as you type
[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 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32 #include <vlc_playlist.h>
33
34 class PLModel;
35
36 class PLItem
37 {
38 public:
39     PLItem( int, int, PLItem *parent , PLModel *);
40     PLItem( playlist_item_t *, PLItem *parent, PLModel *);
41     ~PLItem();
42
43     int row() const;
44     void insertChild( PLItem *, int p, bool signal = true );
45
46     void appendChild( PLItem *item, bool signal = true )
47     {
48         insertChild( item, children.count(), signal );
49     };
50     void remove( PLItem *removed );
51     PLItem *child( int row ) { return children.value( row ); };
52     int childCount() const { return children.count(); };
53     QString columnString( int col ) { return strings.value( col ); };
54     PLItem *parent() { return parentItem; };
55
56     void update( playlist_item_t *, bool);
57 protected:
58     QList<PLItem*> children;
59     QList<QString> strings;
60     bool current;
61     int type;
62     int i_id;
63     int i_input_id;
64     friend class PLModel;
65 private:
66     void init( int, int, PLItem *, PLModel * );
67     PLItem *parentItem;
68     PLModel *model;
69 };
70
71 static int ItemUpdate_Type = QEvent::User + 2;
72 static int ItemDelete_Type = QEvent::User + 3;
73 static int ItemAppend_Type = QEvent::User + 4;
74
75 class PLEvent : public QEvent
76 {
77 public:
78     PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
79     { i_id = id; p_add = NULL; };
80     PLEvent(  playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
81     { p_add = a; };
82     virtual ~PLEvent() {};
83
84     int i_id;
85     playlist_add_t *p_add;
86 };
87
88 #include <QAbstractItemModel>
89 #include <QVariant>
90
91 class PLModel : public QAbstractItemModel
92 {
93     Q_OBJECT
94
95 public:
96     PLModel( playlist_t *, playlist_item_t *, int, QObject *parent = 0);
97     ~PLModel();
98
99     /* All types of lookups / QModel stuff */
100     QVariant data( const QModelIndex &index, int role) const;
101     Qt::ItemFlags flags( const QModelIndex &index) const;
102     QVariant headerData( int section, Qt::Orientation orientation,
103                          int role = Qt::DisplayRole) const;
104     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
105     QModelIndex index( PLItem *, int c ) const;
106     int itemId( const QModelIndex &index ) const;
107     bool isCurrent( const QModelIndex &index );
108     QModelIndex parent( const QModelIndex &index) const;
109     int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
110     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
111     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
112
113     bool b_need_update;
114     int i_items_to_append;
115     void rebuild(); void rebuild( playlist_item_t *);
116     bool hasRandom(); bool hasLoop(); bool hasRepeat();
117
118     /* Actions made by the views */
119     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
120     void doDelete( QModelIndexList selected );
121     void search( QString search );
122     void sort( int column, Qt::SortOrder order );
123 private:
124     void addCallbacks();
125     void delCallbacks();
126     void customEvent( QEvent * );
127
128     PLItem *rootItem;
129
130     playlist_t *p_playlist;
131     int i_depth;
132
133     static QIcon icons[ITEM_TYPE_NUMBER];
134
135     /* Update processing */
136     void ProcessInputItemUpdate( int i_input_id );
137     void ProcessItemRemoval( int i_id );
138     void ProcessItemAppend( playlist_add_t *p_add );
139
140     void UpdateTreeItem( PLItem *, bool, bool force = false );
141     void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
142     void UpdateNodeChildren( PLItem * );
143     void UpdateNodeChildren( playlist_item_t *, PLItem * );
144
145     /* Actions */
146     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
147     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
148
149     /* Popup */
150     int i_popup_item, i_popup_parent;
151     QModelIndexList current_selection;
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 public slots:
162     void activateItem( const QModelIndex &index );
163     void activateItem( playlist_item_t *p_item );
164     void setRandom( bool );
165     void setLoop( bool );
166     void setRepeat( bool );
167 private slots:
168     void popupPlay();
169     void popupDel();
170 friend class PLItem;
171 };
172
173 #endif