File indexing completed on 2024-05-19 04:50:13
0001 /**************************************************************************************** 0002 * Copyright (c) 2011 Stefan Derkits <stefan@derkits.at> * 0003 * Copyright (c) 2011 Christian Wagner <christian.wagner86@gmx.at> * 0004 * Copyright (c) 2011 Felix Winter <ixos01@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #include "GpodderTreeItem.h" 0020 0021 #include "GpodderPodcastTreeItem.h" 0022 #include "GpodderServiceModel.h" 0023 #include "GpodderTagTreeItem.h" 0024 0025 GpodderTreeItem::GpodderTreeItem( GpodderTreeItem *parent, const QString &name ) 0026 : QObject( parent ) 0027 , m_parentItem( parent ) 0028 , m_name( name ) 0029 , m_hasChildren( false ) 0030 { 0031 } 0032 0033 GpodderTreeItem::~GpodderTreeItem() 0034 { 0035 qDeleteAll( m_childItems ); 0036 } 0037 0038 void 0039 GpodderTreeItem::appendChild( GpodderTreeItem *item ) 0040 { 0041 m_childItems.append( item ); 0042 } 0043 0044 GpodderTreeItem * 0045 GpodderTreeItem::child( int row ) 0046 { 0047 return m_childItems.value( row ); 0048 } 0049 0050 bool 0051 GpodderTreeItem::hasChildren() const 0052 { 0053 return m_hasChildren; 0054 } 0055 0056 void 0057 GpodderTreeItem::setHasChildren( bool hasChildren ) 0058 { 0059 m_hasChildren = hasChildren; 0060 } 0061 0062 int 0063 GpodderTreeItem::childCount() const 0064 { 0065 return m_childItems.count(); 0066 } 0067 0068 GpodderTreeItem * 0069 GpodderTreeItem::parent() const 0070 { 0071 return m_parentItem; 0072 } 0073 0074 QVariant 0075 GpodderTreeItem::displayData() const 0076 { 0077 return m_name; 0078 } 0079 0080 bool 0081 GpodderTreeItem::isRoot() const 0082 { 0083 return ( m_parentItem == nullptr ); 0084 } 0085 0086 void 0087 GpodderTreeItem::appendTags( mygpo::TagListPtr tags ) 0088 { 0089 for( const auto &tag : tags->list() ) 0090 { 0091 GpodderTagTreeItem *treeItem = new GpodderTagTreeItem( tag, this ); 0092 appendChild( treeItem ); 0093 } 0094 } 0095 0096 void 0097 GpodderTreeItem::appendPodcasts( mygpo::PodcastListPtr podcasts ) 0098 { 0099 for( const auto &podcast : podcasts->list() ) 0100 { 0101 appendChild( new GpodderPodcastTreeItem( podcast, this ) ); 0102 } 0103 }