]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt: remove random and repeat buttons from playlist
[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  *          Jakob Leben <jleben@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _PLAYLIST_MODEL_H_
26 #define _PLAYLIST_MODEL_H_
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "qt4.hpp"
33
34 #include <vlc_input.h>
35 #include <vlc_playlist.h>
36
37 #include "playlist_item.hpp"
38
39 #include <QModelIndex>
40 #include <QObject>
41 #include <QEvent>
42 #include <QMimeData>
43 #include <QSignalMapper>
44 #include <QAbstractItemModel>
45 #include <QVariant>
46
47 class QSignalMapper;
48 class PLItem;
49
50 class PLModel : public QAbstractItemModel
51 {
52     Q_OBJECT
53
54 friend class PLItem;
55
56 public:
57     PLModel( playlist_t *, intf_thread_t *,
58              playlist_item_t *, QObject *parent = 0 );
59     ~PLModel();
60
61     /*** QModel subclassing ***/
62
63     /* Data structure */
64     QVariant data( const QModelIndex &index, int role ) const;
65     QVariant headerData( int section, Qt::Orientation orientation,
66                          int role = Qt::DisplayRole ) const;
67     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
68     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
69     Qt::ItemFlags flags( const QModelIndex &index ) const;
70     QModelIndex index( int r, int c, const QModelIndex &parent ) const;
71     QModelIndex parent( const QModelIndex &index ) const;
72
73     /* Drag and Drop */
74     Qt::DropActions supportedDropActions() const;
75     QMimeData* mimeData( const QModelIndexList &indexes ) const;
76     bool dropMimeData( const QMimeData *data, Qt::DropAction action,
77                       int row, int column, const QModelIndex &target );
78     QStringList mimeTypes() const;
79
80     /**** Custom ****/
81
82     /* Lookups */
83     QStringList selectedURIs();
84     QModelIndex index( PLItem *, int c ) const;
85     QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
86     bool isCurrent( const QModelIndex &index ) const;
87     int itemId( const QModelIndex &index ) const;
88
89     /* Actions */
90     void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
91     void doDelete( QModelIndexList selected );
92     void search( const QString& search_text );
93     void sort( int column, Qt::SortOrder order );
94     void sort( int i_root_id, int column, Qt::SortOrder order );
95     void removeItem( int );
96     void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
97
98 private:
99
100     /* General */
101     PLItem *rootItem;
102     PLItem *currentItem;
103
104     playlist_t *p_playlist;
105     intf_thread_t *p_intf;
106     int i_depth;
107
108     static QIcon icons[ITEM_TYPE_NUMBER];
109
110     /* Actions */
111     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
112     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
113     void updateTreeItem( PLItem * );
114     void removeItem ( PLItem * );
115     void takeItem( PLItem * ); //will not delete item
116     void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
117     void dropAppendCopy( QByteArray& data, PLItem *target );
118     void dropMove( QByteArray& data, PLItem *target, int new_pos );
119     /* The following actions will not signal the view! */
120     void updateChildren( PLItem * );
121     void updateChildren( playlist_item_t *, PLItem * );
122
123     /* Popup */
124     int i_popup_item, i_popup_parent, i_popup_column;
125     QModelIndexList current_selection;
126
127     /* Lookups */
128     PLItem *findById( PLItem *, int );
129     PLItem *findByInput( PLItem *, int );
130     PLItem *findInner( PLItem *, int , bool );
131     static inline PLItem *getItem( QModelIndex index );
132     int columnFromMeta( int meta_column ) const;
133     int columnToMeta( int column ) const;
134     bool canEdit() const;
135     PLItem *p_cached_item;
136     PLItem *p_cached_item_bi;
137     int i_cached_id;
138     int i_cached_input_id;
139
140 signals:
141     void currentChanged( const QModelIndex& );
142
143 public slots:
144     void activateItem( const QModelIndex &index );
145     void activateItem( playlist_item_t *p_item );
146
147 private slots:
148     void popupPlay();
149     void popupDel();
150     void popupInfo();
151     void popupStream();
152     void popupSave();
153     void popupExplore();
154     void popupAddNode();
155     void popupSortAsc();
156     void popupSortDesc();
157     void processInputItemUpdate( input_item_t *);
158     void processInputItemUpdate( input_thread_t* p_input );
159     void processItemRemoval( int i_id );
160     void processItemAppend( int item, int parent );
161 };
162
163 #endif