1 /*****************************************************************************
2  * playlist_item.hpp : Item for a playlist tree
3  ****************************************************************************
4  * Copyright (C) 2006-2011 the VideoLAN team
5  * $Id: b88314b1ffca7d34547186b84581198758c13a3e $
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 VLC_QT_PLAYLIST_ITEM_HPP_
25 #define VLC_QT_PLAYLIST_ITEM_HPP_
26 
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #include "qt.hpp"
32 
33 #include <QList>
34 #include <QString>
35 
36 class AbstractPLItem
37 {
38     friend class PLItem; /* super ugly glue stuff */
39     friend class MLItem;
40     friend class VLCModel;
41     friend class PLModel;
42     friend class MLModel;
43 
44 public:
~AbstractPLItem()45     virtual ~AbstractPLItem() {}
46 
47 protected:
48     virtual int id( ) const = 0;
childCount() const49     int childCount() const { return children.count(); }
indexOf(AbstractPLItem * item) const50     int indexOf( AbstractPLItem *item ) const { return children.indexOf( item ); };
lastIndexOf(AbstractPLItem * item) const51     int lastIndexOf( AbstractPLItem *item ) const { return children.lastIndexOf( item ); };
parent()52     AbstractPLItem *parent() { return parentItem; }
53     virtual input_item_t *inputItem() = 0;
insertChild(AbstractPLItem * item,int pos=-1)54     void insertChild( AbstractPLItem *item, int pos = -1 ) { children.insert( pos, item ); }
appendChild(AbstractPLItem * item)55     void appendChild( AbstractPLItem *item ) { insertChild( item, children.count() ); } ;
56     virtual AbstractPLItem *child( int id ) const = 0;
57     void removeChild( AbstractPLItem *item );
58     void clearChildren();
59     virtual QString getURI() const = 0;
60     virtual QString getTitle() const = 0;
61     virtual bool readOnly() const = 0;
62 
63     QList<AbstractPLItem *> children;
64     AbstractPLItem *parentItem;
65 };
66 
67 class PLItem : public AbstractPLItem
68 {
69     friend class PLModel;
70 
71 public:
72     virtual ~PLItem();
hasSameParent(PLItem * other)73     bool hasSameParent( PLItem *other ) { return parent() == other->parent(); }
74     bool operator< ( AbstractPLItem& );
75 
76 private:
77     /* AbstractPLItem */
78     int id() const Q_DECL_OVERRIDE;
inputItem()79     input_item_t *inputItem() Q_DECL_OVERRIDE { return p_input; }
child(int id) const80     AbstractPLItem *child( int id ) const Q_DECL_OVERRIDE { return children.value( id ); };
81     virtual QString getURI() const Q_DECL_OVERRIDE;
82     virtual QString getTitle() const Q_DECL_OVERRIDE;
83     virtual bool readOnly() const Q_DECL_OVERRIDE;
84 
85     /* Local */
86     PLItem( playlist_item_t *, PLItem *parent );
87     int row();
88     void takeChildAt( int );
89 
90     PLItem( playlist_item_t * );
91     void init( playlist_item_t *, PLItem * );
92     int i_playlist_id;
93     int i_flags;
94     input_item_t *p_input;
95 };
96 
97 #endif
98 
99