]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_item.hpp
Qt: make a destructor as virtual
[vlc] / modules / gui / qt4 / components / playlist / playlist_item.hpp
1 /*****************************************************************************
2  * playlist_item.hpp : Item 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  *
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 _PLAYLIST_ITEM_H_
25 #define _PLAYLIST_ITEM_H_
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <QList>
32
33 class AbstractPLItem
34 {
35     friend class PLItem; /* super ugly glue stuff */
36     friend class MLItem;
37     friend class PLModel;
38     friend class MLModel;
39
40 protected:
41     virtual int id() const = 0;
42     int childCount() const { return children.count(); }
43     int indexOf( AbstractPLItem *item ) const { return children.indexOf( item ); };
44     int lastIndexOf( AbstractPLItem *item ) const { return children.lastIndexOf( item ); };
45     AbstractPLItem *parent() { return parentItem; }
46     virtual input_item_t *inputItem() = 0;
47     void insertChild( AbstractPLItem *item, int pos = -1 ) { children.insert( pos, item ); }
48     void appendChild( AbstractPLItem *item ) { insertChild( item, children.count() ); } ;
49     virtual AbstractPLItem *child( int id ) const = 0;
50     void clearChildren();
51
52     QList<AbstractPLItem *> children;
53     AbstractPLItem *parentItem;
54 };
55
56 class PLItem : public AbstractPLItem
57 {
58     friend class PLModel;
59
60 public:
61     virtual ~PLItem();
62     bool hasSameParent( PLItem *other ) { return parent() == other->parent(); }
63     bool operator< ( PLItem& );
64
65 private:
66     /* AbstractPLItem */
67     int id() const { return i_id; };
68     input_item_t *inputItem() { return p_input; }
69     AbstractPLItem *child( int id ) const { return children.value( id ); };
70
71     /* Local */
72     PLItem( playlist_item_t *, PLItem *parent );
73     int row();
74     void removeChild( PLItem * );
75     void takeChildAt( int );
76
77     PLItem( playlist_item_t * );
78     void init( playlist_item_t *, PLItem * );
79     int i_id;
80     input_item_t *p_input;
81 };
82
83 #endif
84