Qt: export PLModel in the main struct
[vlc.git] / modules / gui / qt4 / components / playlist / playlist_model.hpp
blob4fc4109e3f1a7651c28724218fea0e62f4c3fd70
1 /*****************************************************************************
2 * playlist_model.hpp : Model for a playlist tree
3 ****************************************************************************
4 * Copyright (C) 2006-2011 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jakob Leben <jleben@videolan.org>
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.
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.
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 *****************************************************************************/
25 #ifndef _PLAYLIST_MODEL_H_
26 #define _PLAYLIST_MODEL_H_
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_input.h>
33 #include <vlc_playlist.h>
34 #include "vlc_model.hpp"
35 #include "playlist_item.hpp"
37 #include <QObject>
38 #include <QEvent>
39 #include <QSignalMapper>
40 #include <QMimeData>
41 #include <QAbstractItemModel>
42 #include <QVariant>
43 #include <QModelIndex>
45 class PLItem;
46 class PLSelector;
47 class PlMimeData;
48 class QSignalMapper;
50 class PLModel : public VLCModel
52 Q_OBJECT
54 public:
55 PLModel( playlist_t *, intf_thread_t *,
56 playlist_item_t *, QObject *parent = 0 );
57 virtual ~PLModel();
59 static PLModel* getPLModel( intf_thread_t *p_intf )
61 if(!p_intf->p_sys->pl_model )
63 playlist_Lock( THEPL );
64 playlist_item_t *p_root = THEPL->p_playing;
65 playlist_Unlock( THEPL );
66 p_intf->p_sys->pl_model = new PLModel( THEPL, p_intf, p_root, NULL );
69 return p_intf->p_sys->pl_model;
72 /*** QModel subclassing ***/
74 /* Data structure */
75 virtual QVariant data( const QModelIndex &index, const int role ) const;
76 virtual QVariant headerData( int section, Qt::Orientation orientation,
77 int role = Qt::DisplayRole ) const;
78 virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
79 virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
80 virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
81 virtual QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
82 virtual QModelIndex parent( const QModelIndex &index ) const;
84 /* Drag and Drop */
85 virtual Qt::DropActions supportedDropActions() const;
86 virtual QMimeData* mimeData( const QModelIndexList &indexes ) const;
87 virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action,
88 int row, int column, const QModelIndex &target );
89 virtual QStringList mimeTypes() const;
91 /**** Custom ****/
93 /* Lookups */
94 QStringList selectedURIs();
95 QModelIndex index( PLItem *, const int c ) const;
96 QModelIndex index( const int i_id, const int c );
97 virtual QModelIndex currentIndex() const;
98 bool isParent( const QModelIndex &index, const QModelIndex &current) const;
99 bool isCurrent( const QModelIndex &index ) const;
100 int itemId( const QModelIndex &index ) const;
102 /* Actions */
103 virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
104 virtual void doDelete( QModelIndexList selected );
105 void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
106 void sort( const int column, Qt::SortOrder order );
107 void sort( const int i_root_id, const int column, Qt::SortOrder order );
108 void rebuild( playlist_item_t * p = NULL );
110 inline PLItem *getItem( QModelIndex index ) const
112 if( index.isValid() )
113 return static_cast<PLItem*>( index.internalPointer() );
114 else return rootItem;
116 virtual int getId( QModelIndex index ) const
118 return getItem( index )->id();
120 inline int getZoom() const
122 return i_zoom;
125 signals:
126 void currentChanged( const QModelIndex& );
127 void rootChanged();
129 public slots:
130 virtual void activateItem( const QModelIndex &index );
131 void activateItem( playlist_item_t *p_item );
132 inline void changeZoom( const int zoom )
134 i_zoom = zoom;
135 emit layoutChanged();
138 private:
139 /* General */
140 PLItem *rootItem;
142 playlist_t *p_playlist;
144 static QIcon icons[ITEM_TYPE_NUMBER];
146 /* Shallow actions (do not affect core playlist) */
147 void updateTreeItem( PLItem * );
148 void removeItem ( PLItem * );
149 void removeItem( int );
150 void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
151 void takeItem( PLItem * ); //will not delete item
152 void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
153 /* ...of which the following will not update the views */
154 void updateChildren( PLItem * );
155 void updateChildren( playlist_item_t *, PLItem * );
157 /* Deep actions (affect core playlist) */
158 void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
159 void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
161 /* Popup */
162 int i_popup_item, i_popup_parent, i_popup_column;
163 QModelIndexList current_selection;
164 QMenu *sortingMenu;
165 QSignalMapper *sortingMapper;
167 /* Lookups */
168 PLItem *findById( PLItem *, int ) const;
169 PLItem *findByInput( PLItem *, int ) const;
170 PLItem *findInner(PLItem *, int , bool ) const;
171 bool canEdit() const;
173 PLItem *p_cached_item;
174 PLItem *p_cached_item_bi;
175 int i_cached_id;
176 int i_cached_input_id;
178 /* Zoom factor for font-size */
179 int i_zoom;
181 private slots:
182 void popupPlay();
183 void popupDel();
184 void popupInfo();
185 void popupStream();
186 void popupSave();
187 void popupExplore();
188 void popupAddNode();
189 void popupAddToPlaylist();
190 void popupSort( int column );
191 void processInputItemUpdate( input_item_t *);
192 void processInputItemUpdate( input_thread_t* p_input );
193 void processItemRemoval( int i_id );
194 void processItemAppend( int item, int parent );
197 class PlMimeData : public QMimeData
199 Q_OBJECT
201 public:
202 PlMimeData() {}
203 ~PlMimeData();
204 void appendItem( input_item_t *p_item );
205 QList<input_item_t*> inputItems() const;
206 QStringList formats () const;
208 private:
209 QList<input_item_t*> _inputItems;
210 QMimeData *_mimeData;
213 #endif