1 /***************************************************************************
2 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> *
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. *
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. *
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"
26 AlbumGroup::AlbumGroup()
32 AlbumGroup::~AlbumGroup()
39 void Playlist::AlbumGroup::addRow(int row
)
43 //Does this row fit in any of our existing groups?
45 for ( int i
= 0; i
< m_groups
.count(); i
++ ) {
47 if ( m_groups
[i
].rows
.contains( row
) ) {
51 else if ( m_groups
[i
].rows
.last() == row
- 1 ) {
52 m_groups
[i
].rows
.append( row
);
59 //no group found, create new one:
62 newGroup
.collapsed
= false;
63 newGroup
.rows
.append( row
);
64 m_groups
.append( newGroup
);
68 int Playlist::AlbumGroup::groupMode( int row
)
72 foreach( Group group
, m_groups
) {
73 if ( group
.rows
.contains( row
) ) {
75 //debug() << "row " << row << " is collapsed= " << group.collapsed;
77 if ( group
.rows
.count() < 2 )
79 else if ( group
.rows
.first() == row
) {
80 if ( !group
.collapsed
)
83 return Head_Collapsed
;
84 } else if ( group
.rows
.last() == row
) {
85 if ( !group
.collapsed
)
90 if ( !group
.collapsed
)
102 void Playlist::AlbumGroup::setCollapsed(int row
, bool collapsed
)
105 for (int i
= 0; i
< m_groups
.count(); i
++ ) {
106 if ( m_groups
[ i
].rows
.contains( row
) ) {
107 m_groups
[ i
].collapsed
= collapsed
;
108 //debug() << "row " << row << " collapsed = " << m_groups[ i ].collapsed;
113 int Playlist::AlbumGroup::elementsInGroup(int row
)
116 foreach( Group group
, m_groups
) {
117 if ( group
.rows
.contains( row
) ) {
118 return group
.rows
.count();
126 int Playlist::AlbumGroup::firstInGroup(int row
)
129 foreach( Group group
, m_groups
) {
130 if ( group
.rows
.contains( row
) ) {
131 return group
.rows
.first();
139 int Playlist::AlbumGroup::lastInGroup(int row
)
142 foreach( Group group
, m_groups
) {
143 if ( group
.rows
.contains( row
) ) {
144 return group
.rows
.last();
151 void Playlist::AlbumGroup::removeGroup(int row
)
154 for (int i
= 0; i
< m_groups
.count(); i
++ ) {
155 if ( m_groups
[ i
].rows
.contains( row
) ) {
156 m_groups
.removeAt( i
);
164 int Playlist::AlbumGroup::subgroupCount()
166 return m_groups
.count();
169 void Playlist::AlbumGroup::printGroupRows()
171 foreach( Group group
, m_groups
) {
172 debug() << "Subgroup: " << group
.rows
;
177 void Playlist::AlbumGroup::removeBetween(int first
, int last
)
180 debug() << "first: " << first
<< ", last: " << last
;
181 for ( int i
= first
; i
<= last
; i
++ ) {
182 for (int j
= 0; j
< m_groups
.count(); j
++ ) {
183 if ( m_groups
[ j
].rows
.contains( i
) ) {
184 m_groups
.removeAt( j
);
192 //when something is inserted or removed, all following indexes must be moved to match their actual new position.
193 void Playlist::AlbumGroup::offsetBetween(int first
, int last
, int offset
)
197 debug() << "first: " << first
<< ", last: " << last
;
198 for (int j
= 0; j
< m_groups
.count(); j
++ ) {
199 for ( int i
= first
; i
<= last
; i
++ ) {
200 if ( m_groups
[ j
].rows
.contains( i
) ) {
201 //offset all in this group (so we dont break any groups)
202 for ( int k
= 0; k
< m_groups
[ j
].rows
.count(); k
++ ) {
203 m_groups
[ j
].rows
.append( m_groups
[ j
].rows
.takeFirst() + offset
);