]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt4: add size-scale into playlist model
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
1 /*****************************************************************************
2  * playlist_model.hpp : Model for a playlist tree
3  ****************************************************************************
4  * Copyright (C) 2006-2011 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 <vlc_input.h>
33 #include <vlc_playlist.h>
34 #include "vlc_model.hpp"
35 #include "playlist_item.hpp"
36
37 #include <QObject>
38 #include <QEvent>
39 #include <QSignalMapper>
40 #include <QMimeData>
41 #include <QAbstractItemModel>
42 #include <QVariant>
43 #include <QModelIndex>
44
45 class PLItem;
46 class PLSelector;
47 class PlMimeData;
48 class QSignalMapper;
49
50 class PLModel : public VLCModel
51 {
52     Q_OBJECT
53
54 public:
55     PLModel( playlist_t *, intf_thread_t *,
56              playlist_item_t *, QObject *parent = 0 );
57     virtual ~PLModel();
58
59     /*** QModel subclassing ***/
60
61     /* Data structure */
62     virtual QVariant data( const QModelIndex &index, const int role ) const;
63     virtual QVariant headerData( int section, Qt::Orientation orientation,
64                          int role = Qt::DisplayRole ) const;
65     virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
66     virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
67     virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
68     virtual QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
69     virtual QModelIndex parent( const QModelIndex &index ) const;
70
71     /* Drag and Drop */
72     virtual Qt::DropActions supportedDropActions() const;
73     virtual QMimeData* mimeData( const QModelIndexList &indexes ) const;
74     virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action,
75                       int row, int column, const QModelIndex &target );
76     virtual QStringList mimeTypes() const;
77
78     /**** Custom ****/
79
80     /* Lookups */
81     QStringList selectedURIs();
82     QModelIndex index( PLItem *, const int c ) const;
83     QModelIndex index( const int i_id, const int c );
84     virtual QModelIndex currentIndex() const;
85     bool isParent( const QModelIndex &index, const QModelIndex &current) const;
86     bool isCurrent( const QModelIndex &index ) const;
87     int itemId( const QModelIndex &index ) const;
88
89     /* Actions */
90     virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
91     virtual void doDelete( QModelIndexList selected );
92     void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
93     void sort( const int column, Qt::SortOrder order );
94     void sort( const int i_root_id, const int column, Qt::SortOrder order );
95     void rebuild( playlist_item_t * p = NULL );
96
97     inline PLItem *getItem( QModelIndex index ) const
98     {
99         if( index.isValid() )
100             return static_cast<PLItem*>( index.internalPointer() );
101         else return rootItem;
102     }
103     virtual int getId( QModelIndex index ) const
104     {
105         return getItem( index )->id();
106     }
107     inline int getZoom() const
108     {
109         return i_zoom;
110     }
111
112 signals:
113     void currentChanged( const QModelIndex& );
114     void rootChanged();
115
116 public slots:
117     virtual void activateItem( const QModelIndex &index );
118     void activateItem( playlist_item_t *p_item );
119     inline void changeZoom( const int zoom )
120     {
121         i_zoom = zoom;
122         emit layoutChanged();
123     }
124
125 private:
126     /* General */
127     PLItem *rootItem;
128
129     playlist_t *p_playlist;
130
131     static QIcon icons[ITEM_TYPE_NUMBER];
132
133     /* Shallow actions (do not affect core playlist) */
134     void updateTreeItem( PLItem * );
135     void removeItem ( PLItem * );
136     void removeItem( int );
137     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
138     void takeItem( PLItem * ); //will not delete item
139     void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
140     /* ...of which  the following will not update the views */
141     void updateChildren( PLItem * );
142     void updateChildren( playlist_item_t *, PLItem * );
143
144     /* Deep actions (affect core playlist) */
145     void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
146     void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
147
148     /* Popup */
149     int i_popup_item, i_popup_parent, i_popup_column;
150     QModelIndexList current_selection;
151     QMenu *sortingMenu;
152     QSignalMapper *sortingMapper;
153
154     /* Lookups */
155     PLItem *findById( PLItem *, int ) const;
156     PLItem *findByInput( PLItem *, int ) const;
157     PLItem *findInner(PLItem *, int , bool ) const;
158     bool canEdit() const;
159
160     PLItem *p_cached_item;
161     PLItem *p_cached_item_bi;
162     int i_cached_id;
163     int i_cached_input_id;
164
165     /* Zoom factor for font-size */
166     int i_zoom;
167
168 private slots:
169     void popupPlay();
170     void popupDel();
171     void popupInfo();
172     void popupStream();
173     void popupSave();
174     void popupExplore();
175     void popupAddNode();
176     void popupAddToPlaylist();
177     void popupSort( int column );
178     void processInputItemUpdate( input_item_t *);
179     void processInputItemUpdate( input_thread_t* p_input );
180     void processItemRemoval( int i_id );
181     void processItemAppend( int item, int parent );
182 };
183
184 class PlMimeData : public QMimeData
185 {
186     Q_OBJECT
187
188 public:
189     PlMimeData() {}
190     ~PlMimeData();
191     void appendItem( input_item_t *p_item );
192     QList<input_item_t*> inputItems() const;
193     QStringList formats () const;
194
195 private:
196     QList<input_item_t*> _inputItems;
197     QMimeData *_mimeData;
198 };
199
200 #endif