]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/vlc_model.hpp
450616927801746bbaf96fe1c3af8c6c87dfe40b
[vlc] / modules / gui / qt4 / components / playlist / vlc_model.hpp
1 /*****************************************************************************
2  * vlc_model.hpp : base for playlist and ml model
3  ****************************************************************************
4  * Copyright (C) 2010 the VideoLAN team and AUTHORS
5  * $Id$
6  *
7  * Authors: Srikanth Raju <srikiraju#gmail#com>
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 _VLC_MODEL_H_
25 #define _VLC_MODEL_H_
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include "qt4.hpp"
32 #include "sorting.h"
33
34 #include <vlc_input.h>
35
36 #include <QModelIndex>
37 #include <QPixmapCache>
38 #include <QSize>
39 #include <QAbstractItemModel>
40
41
42 class VLCModel : public QAbstractItemModel
43 {
44     Q_OBJECT
45 public:
46     enum {
47       IsCurrentRole = Qt::UserRole,
48       IsLeafNodeRole,
49       IsCurrentsParentNodeRole
50     };
51
52     VLCModel( intf_thread_t *_p_intf, QObject *parent = 0 );
53     virtual int getId( QModelIndex index ) const = 0;
54     virtual QModelIndex currentIndex() const = 0;
55     virtual bool popup( const QModelIndex & index,
56             const QPoint &point, const QModelIndexList &list ) = 0;
57     virtual void doDelete( QModelIndexList ) = 0;
58     virtual ~VLCModel();
59     static QString getMeta( const QModelIndex & index, int meta );
60     static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
61
62     static int columnToMeta( int _column )
63     {
64         int meta = 1;
65         int column = 0;
66
67         while( column != _column && meta != COLUMN_END )
68         {
69             meta <<= 1;
70             column++;
71         }
72
73         return meta;
74     }
75
76     static int columnFromMeta( int meta_col )
77     {
78         int meta = 1;
79         int column = 0;
80
81         while( meta != meta_col && meta != COLUMN_END )
82         {
83             meta <<= 1;
84             column++;
85         }
86
87         return column;
88     }
89
90 public slots:
91     virtual void activateItem( const QModelIndex &index ) = 0;
92
93 protected:
94     intf_thread_t *p_intf;
95
96 };
97
98
99 #endif