]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist_item.cpp
qt4 playlist: fix crash at "vlc --no-media-library"
[vlc] / modules / gui / qt4 / components / playlist / playlist_item.cpp
1 /*****************************************************************************
2  * playlist_item.cpp : Manage playlist item
3  ****************************************************************************
4  * Copyright © 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <assert.h>
30
31 #include "qt4.hpp"
32 #include "playlist_item.hpp"
33 #include <vlc_intf_strings.h>
34
35 #include "sorting.h"
36
37 /*************************************************************************
38  * Playlist item implementation
39  *************************************************************************/
40
41 /*
42    Playlist item is just a wrapper, an abstraction of the playlist_item
43    in order to be managed by PLModel
44
45    PLItem have a parent, and id and a input Id
46 */
47
48
49 void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
50 {
51     parentItem = parent;          /* Can be NULL, but only for the rootItem */
52     i_id       = _playlist_item->i_id;           /* Playlist item specific id */
53     p_input    = _playlist_item->p_input;
54     vlc_gc_incref( p_input );
55
56 }
57
58 /*
59    Constructors
60    Call the above function init
61    */
62 PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
63 {
64     init( p_item, parent );
65 }
66
67 PLItem::PLItem( playlist_item_t * p_item )
68 {
69     init( p_item, NULL );
70 }
71
72 PLItem::~PLItem()
73 {
74     vlc_gc_decref( p_input );
75     qDeleteAll( children );
76     children.clear();
77 }
78
79 /* So far signal is always true.
80    Using signal false would not call PLModel... Why ?
81  */
82 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
83 {
84     children.insert( i_pos, item );
85 }
86
87 /* This function is used to get one's parent's row number in the model */
88 int PLItem::row() const
89 {
90     if( parentItem )
91         return parentItem->children.indexOf( const_cast<PLItem*>(this) );
92        // We don't ever inherit PLItem, yet, but it might come :D
93     return 0;
94 }
95