PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/src/libtomahawk/playlist/albumitem.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 105 lines | 66 code | 19 blank | 20 comment | 8 complexity | 492569c3c70f2031f7439cc8566b4e25 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#include "albumitem.h"
 20
 21#include "utils/tomahawkutils.h"
 22#include "utils/logger.h"
 23
 24using namespace Tomahawk;
 25
 26
 27AlbumItem::~AlbumItem()
 28{
 29    // Don't use qDeleteAll here! The children will remove themselves
 30    // from the list when they get deleted and the qDeleteAll iterator
 31    // will fail badly!
 32    for ( int i = children.count() - 1; i >= 0; i-- )
 33        delete children.at( i );
 34
 35    if ( parent && index.isValid() )
 36    {
 37        parent->children.removeAt( index.row() );
 38    }
 39}
 40
 41
 42AlbumItem::AlbumItem( AlbumItem* parent, QAbstractItemModel* model )
 43{
 44    this->parent = parent;
 45    this->model = model;
 46    childCount = 0;
 47    toberemoved = false;
 48
 49    if ( parent )
 50    {
 51        parent->children.append( this );
 52    }
 53}
 54
 55
 56AlbumItem::AlbumItem( const Tomahawk::album_ptr& album, AlbumItem* parent, int row )
 57    : QObject( parent )
 58    , m_album( album )
 59{
 60    this->parent = parent;
 61    if ( parent )
 62    {
 63        if ( row < 0 )
 64        {
 65            parent->children.append( this );
 66            row = parent->children.count() - 1;
 67        }
 68        else
 69        {
 70            parent->children.insert( row, this );
 71        }
 72
 73        this->model = parent->model;
 74    }
 75
 76    toberemoved = false;
 77
 78    connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
 79}
 80
 81
 82AlbumItem::AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent, int row )
 83    : QObject( parent )
 84    , m_artist( artist )
 85{
 86    this->parent = parent;
 87    if ( parent )
 88    {
 89        if ( row < 0 )
 90        {
 91            parent->children.append( this );
 92            row = parent->children.count() - 1;
 93        }
 94        else
 95        {
 96            parent->children.insert( row, this );
 97        }
 98
 99        this->model = parent->model;
100    }
101
102    toberemoved = false;
103
104    connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
105}