1 /****************************************************************************************
2  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  * Copyright (c) 2009-2010 Bart Cerneels <bart.cerneels@kde.org>                        *
4  *                                                                                      *
5  * This program is free software; you can redistribute it and/or modify it under        *
6  * the terms of the GNU General Public License as published by the Free Software        *
7  * Foundation; either version 2 of the License, or (at your option) any later           *
8  * version.                                                                             *
9  *                                                                                      *
10  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
12  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
13  *                                                                                      *
14  * You should have received a copy of the GNU General Public License along with         *
15  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
16  ****************************************************************************************/
17 
18 #ifndef OPMLOUTLINE_H
19 #define OPMLOUTLINE_H
20 
21 #include "amarok_export.h"
22 
23 #include <QMap>
24 #include <QString>
25 
26 enum OpmlNodeType
27 {
28     InvalidNode,
29     UnknownNode,
30     RssUrlNode, //leaf node that link to an RSS
31     IncludeNode, //URL to an OPML file that will be loaded as a sub-tree upon expansion
32     RegularNode //plain sub-tree which can be represented as a folder.
33 };
34 
35 class AMAROK_EXPORT OpmlOutline
36 {
37     public:
38         explicit OpmlOutline( OpmlOutline *parent = nullptr );
~OpmlOutline()39         ~OpmlOutline() {}
40 
parent()41         OpmlOutline *parent() const { return m_parent; }
setParent(OpmlOutline * parent)42         void setParent( OpmlOutline *parent ) { m_parent = parent; }
isRootItem()43         bool isRootItem() const { return m_parent == nullptr; }
44 
attributes()45         QMap<QString,QString> attributes() const { return m_attributes; }
46 
47         /** @return a modifiable reference to the attributes */
mutableAttributes()48         QMap<QString,QString> &mutableAttributes() { return m_attributes; }
addAttribute(const QString & key,const QString & value)49         void addAttribute( const QString &key, const QString &value )
50                 { m_attributes.insert( key, value ); }
51 
children()52         QList<OpmlOutline *> children() const { return m_children; }
53 
54         /** @return a modifiable reference to the children */
mutableChildren()55         QList<OpmlOutline *> &mutableChildren() { return m_children; }
setHasChildren(bool hasChildren)56         void setHasChildren( bool hasChildren ) { m_hasChildren = hasChildren; }
hasChildren()57         bool hasChildren() const { return m_hasChildren; }
addChild(OpmlOutline * outline)58         void addChild( OpmlOutline *outline ) { m_children << outline; }
addChildren(const QList<OpmlOutline * > & outlineList)59         void addChildren( const QList<OpmlOutline *> &outlineList )
60                 { m_children << outlineList; }
61 
62         OpmlNodeType opmlNodeType() const;
63 
64     private:
65         OpmlOutline *m_parent;
66         QMap<QString,QString> m_attributes;
67 
68         bool m_hasChildren;
69         QList<OpmlOutline *> m_children;
70 };
71 
72 #endif // OPMLOUTLINE_H
73