]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/ml_model.hpp
Qt: MLModel: rework menu signaling
[vlc] / modules / gui / qt4 / components / playlist / ml_model.hpp
1 /*****************************************************************************
2  * ml_model.hpp ML model
3  *****************************************************************************
4  * Copyright (C) 2008-2011 the VideoLAN Team and AUTHORS
5  * $Id$
6  *
7  * Authors: Antoine Lejeune <phytos@videolan.org>
8  *          Jean-Philippe André <jpeg@videolan.org>
9  *          Rémi Duraffort <ivoire@videolan.org>
10  *          Adrien Maglo <magsoft@videolan.org>
11  *          Srikanth Raju <srikiraju#gmail#com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 #ifndef _MEDIA_LIBRARY_MLMODEL_H
29 #define _MEDIA_LIBRARY_MLMODEL_H
30
31 #ifdef HAVE_CONFIG_H
32 # include <config.h>
33 #endif
34
35 #ifdef MEDIA_LIBRARY
36 #include <vlc_common.h>
37 #include <vlc_interface.h>
38 #include <vlc_media_library.h>
39
40 #include "components/playlist/vlc_model.hpp"
41 #include "ml_item.hpp"
42 #include "qt4.hpp"
43
44 class MLItem;
45
46 /** *************************************************************************
47  * \brief Tree model for the result list
48  ****************************************************************************/
49 class MLModel : public VLCModel
50 {
51     Q_OBJECT;
52
53 public:
54     // Basic QAbstractItemModel implementation
55     MLModel( intf_thread_t *_p_intf, QObject *parent = NULL );
56     virtual ~MLModel();
57
58     virtual int itemId( const QModelIndex & ) const;
59
60     QVariant data( const QModelIndex &idx, const int role = Qt::DisplayRole ) const;
61     bool setData( const QModelIndex &idx, const QVariant &value,
62                   int role = Qt::EditRole );
63     ml_select_e columnType( int column ) const;
64
65     QModelIndex index( int row, int column,
66                        const QModelIndex & parent = QModelIndex() ) const;
67     virtual QModelIndex currentIndex() const;
68     int rowCount( const QModelIndex & parent = QModelIndex() ) const;
69     int columnCount( const QModelIndex & parent = QModelIndex() ) const;
70
71     QModelIndex parent( const QModelIndex& ) const;
72     QVariant headerData( int, Qt::Orientation, int ) const;
73     Qt::ItemFlags flags( const QModelIndex& ) const;
74     bool isEditable( const QModelIndex& ) const;
75
76     // Drag and drop: MIME data
77     QMimeData* mimeData( const QModelIndexList & indexes ) const;
78
79     // Custom functions
80     int insertMedia( ml_media_t *p_media, int row = -1,
81                      bool bSignal = true );
82     int appendMedia( ml_media_t *p_media );
83     int insertMediaArray( vlc_array_t *p_media_array, int row = -1,
84                           bool bSignal = true );
85
86     int insertResult( const ml_result_t *p_result, int row = -1,
87                       bool bSignal = true );
88     inline int appendResult( const ml_result_t *p_result );
89     int insertResultArray( vlc_array_t *p_result_array, int row = -1,
90                            bool bSignal = true );
91
92     virtual void doDelete( QModelIndexList list );
93     void remove( QModelIndex idx );
94
95     void clear();
96     virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
97     void play( const QModelIndex &idx );
98     QStringList selectedURIs( QModelIndexList * );
99     virtual QString getURI( const QModelIndex &index ) const;
100     virtual QModelIndex rootIndex() const;
101     virtual bool isTree() const;
102     virtual bool canEdit() const;
103     virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const;
104     QModelIndex getIndexByMLID( int id ) const;
105
106 public slots:
107     void activateItem( const QModelIndex &index );
108     virtual void actionSlot( QAction *action );
109
110 protected:
111     void remove( MLItem *item );
112     inline MLItem *getItem( QModelIndex index ) const
113     {
114         if( index.isValid() )
115             return static_cast<MLItem*>( index.internalPointer() );
116         else return NULL;
117     }
118
119 private:
120     QList< MLItem* > items;
121     media_library_t* p_ml;
122
123 };
124
125 #endif
126 #endif