1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship 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 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship 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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwPlaylistList.cpp
22 * @brief A list of playlist items.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwPlaylistList.h"
27 #include "KwPlaylistListNode.h"
29 #include <QDomElement>
33 KW_REGISTER_PLAYLIST_ITEM(KwPlaylistList
, "list")
36 * Constructors + destructor.
39 /// Default constructor.
40 KwPlaylistList::KwPlaylistList()
46 /// Construct from a DOM element.
47 KwPlaylistList::KwPlaylistList(const QDomElement
& element
, KwResourceManager
* resourceManager
)
48 : KwPlaylistItem(element
, resourceManager
)
50 elementsHandled("playlist_items");
51 QDomElement list
= element
.firstChildElement("playlist_items");
52 while (!list
.isNull())
54 QDomNodeList children
= list
.childNodes();
55 for (int i
= 0; i
< children
.count(); ++i
)
57 QDomElement child
= children
.item(i
).toElement();
60 KwPlaylistItem
* item
= KwPlaylistItem::createFromDom(child
, resourceManager
);
67 list
= list
.nextSiblingElement("playlist_items");
72 KwPlaylistList::~KwPlaylistList()
81 void KwPlaylistList::addItem(KwPlaylistItem
* item
, int position
)
85 m_playlist
.push_back(item
);
89 m_playlist
.insert(position
, item
);
91 item
->setParentScope(this);
94 /// Get the number of children.
95 int KwPlaylistList::getItemCount() const
97 return m_playlist
.size();
100 /// Get a specific child.
101 KwPlaylistItem
* KwPlaylistList::getItem(int index
)
103 assert(index
< getItemCount());
104 Playlist::iterator it
= m_playlist
.begin();
105 while (index
&& it
!= m_playlist
.end())
110 assert(it
!= m_playlist
.end());
111 if (it
== m_playlist
.end())
120 /// Get a specific child.
121 const KwPlaylistItem
* KwPlaylistList::getItem(int index
) const
123 assert(index
< getItemCount());
124 Playlist::const_iterator it
= m_playlist
.constBegin();
125 while (index
&& it
!= m_playlist
.constEnd())
130 assert(it
!= m_playlist
.constEnd());
131 if (it
== m_playlist
.constEnd())
145 QString
KwPlaylistList::itemType() const
150 void KwPlaylistList::exportDetailsToDom(QDomDocument
& document
, QDomElement
& element
, KwResourceManager
* resourceManager
) const
152 QDomElement children
= document
.createElement("playlist_items");
153 element
.appendChild(children
);
155 foreach (const KwPlaylistItem
* item
, m_playlist
)
157 item
->exportToDom(document
, children
, resourceManager
);
165 KwPlaylistNode
* KwPlaylistList::getNode(KwPlaylistNode
* parent
)
167 return new KwPlaylistListNode(parent
, this);