/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. #include "albumitem.h"
  19. #include "utils/tomahawkutils.h"
  20. #include "utils/logger.h"
  21. using namespace Tomahawk;
  22. AlbumItem::~AlbumItem()
  23. {
  24. // Don't use qDeleteAll here! The children will remove themselves
  25. // from the list when they get deleted and the qDeleteAll iterator
  26. // will fail badly!
  27. for ( int i = children.count() - 1; i >= 0; i-- )
  28. delete children.at( i );
  29. if ( parent && index.isValid() )
  30. {
  31. parent->children.removeAt( index.row() );
  32. }
  33. }
  34. AlbumItem::AlbumItem( AlbumItem* parent, QAbstractItemModel* model )
  35. {
  36. this->parent = parent;
  37. this->model = model;
  38. childCount = 0;
  39. toberemoved = false;
  40. if ( parent )
  41. {
  42. parent->children.append( this );
  43. }
  44. }
  45. AlbumItem::AlbumItem( const Tomahawk::album_ptr& album, AlbumItem* parent, int row )
  46. : QObject( parent )
  47. , m_album( album )
  48. {
  49. this->parent = parent;
  50. if ( parent )
  51. {
  52. if ( row < 0 )
  53. {
  54. parent->children.append( this );
  55. row = parent->children.count() - 1;
  56. }
  57. else
  58. {
  59. parent->children.insert( row, this );
  60. }
  61. this->model = parent->model;
  62. }
  63. toberemoved = false;
  64. connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
  65. }
  66. AlbumItem::AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent, int row )
  67. : QObject( parent )
  68. , m_artist( artist )
  69. {
  70. this->parent = parent;
  71. if ( parent )
  72. {
  73. if ( row < 0 )
  74. {
  75. parent->children.append( this );
  76. row = parent->children.count() - 1;
  77. }
  78. else
  79. {
  80. parent->children.insert( row, this );
  81. }
  82. this->model = parent->model;
  83. }
  84. toberemoved = false;
  85. connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
  86. }