]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.hpp
d7cbf652cc9c00754f242209ffc72fccc9a65f83
[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
125     void sendArt( QString url );
126 private:
127     void addCallbacks();
128     void delCallbacks();
129     void customEvent( QEvent * );
130
131     PLItem *rootItem;
132
133     playlist_t *p_playlist;
134     int i_depth;
135
136     static QIcon icons[ITEM_TYPE_NUMBER];
137
138     /* Update processing */
139     void ProcessInputItemUpdate( int i_input_id );
140     void ProcessItemRemoval( int i_id );
141     void ProcessItemAppend( playlist_add_t *p_add );
142
143     void UpdateTreeItem( PLItem *, bool, bool force = false );
144     void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
145     void UpdateNodeChildren( PLItem * );
146     void UpdateNodeChildren( playlist_item_t *, PLItem * );
147
148     /* Actions */
149     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
150     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
151
152     /* Popup */
153     int i_popup_item, i_popup_parent;
154     QModelIndexList current_selection;
155
156     /* Lookups */
157     PLItem *FindById( PLItem *, int );
158     PLItem *FindByInput( PLItem *, int );
159     PLItem *FindInner( PLItem *, int , bool );
160     PLItem *p_cached_item;
161     PLItem *p_cached_item_bi;
162     int i_cached_id;
163     int i_cached_input_id;
164 signals:
165     void artSet( QString );
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 private slots:
173     void popupPlay();
174     void popupDel();
175     void popupInfo();
176     void popupStream();
177     void popupSave();
178 friend class PLItem;
179 };
180
181 #endif