some more work on collabsible albums. I think I will need to optimize the playlist...
[amarok.git] / src / playlist / PlaylistAlbumGroup.cpp
blob2d1c99914d6b3e96a5749c95237ae55c579e55fa
1 /***************************************************************************
2 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #include "PlaylistAlbumGroup.h"
22 #include "debug.h"
24 namespace Playlist {
26 AlbumGroup::AlbumGroup()
28 DEBUG_BLOCK
32 AlbumGroup::~AlbumGroup()
34 DEBUG_BLOCK
39 void Playlist::AlbumGroup::addRow(int row)
41 DEBUG_BLOCK
43 //Does this row fit in any of our existing groups?
44 bool inGroup = false;
45 for ( int i = 0; i < m_groups.count(); i++ ) {
47 if ( m_groups[i].rows.last() == row - 1 ) {
48 m_groups[i].rows.append( row );
49 inGroup = true;
50 break;
54 //no group found, create new one:
55 if ( !inGroup ) {
56 Group newGroup;
57 newGroup.collapsed = false;
58 newGroup.rows.append( row );
59 m_groups.append( newGroup );
63 int Playlist::AlbumGroup::groupMode( int row )
65 DEBUG_BLOCK
67 foreach( Group group, m_groups ) {
68 if ( group.rows.contains( row ) ) {
70 debug() << "row " << row << " is collapsed= " << group.collapsed;
72 if ( group.rows.count() < 2 )
73 return None;
74 else if ( group.rows.first() == row ) {
75 if ( !group.collapsed )
76 return Head;
77 else
78 return Head_Collapsed;
79 } else if ( group.rows.last() == row ) {
80 if ( !group.collapsed )
81 return End;
82 else
83 return Collapsed;
84 } else {
85 if ( !group.collapsed )
86 return Body;
87 else
88 return Collapsed;
93 return None;
97 void Playlist::AlbumGroup::setCollapsed(int row, bool collapsed)
99 DEBUG_BLOCK
100 for (int i = 0; i < m_groups.count(); i++ ) {
101 if ( m_groups[ i ].rows.contains( row ) ) {
102 m_groups[ i ].collapsed = collapsed;
103 debug() << "row " << row << " collapsed = " << m_groups[ i ].collapsed;
108 int Playlist::AlbumGroup::elementsInGroup(int row)
110 DEBUG_BLOCK
111 foreach( Group group, m_groups ) {
112 if ( group.rows.contains( row ) ) {
113 return group.rows.count();
117 return 0;