Database: sqlite default to appdata kworship.db
[kworship.git] / kworship / playlist / KwPlaylistItem.h
blob3fdf4c0812ca64fe9f2b23f3d0a2e96c438576ff
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 #ifndef _KwPlaylistItem_h_
21 #define _KwPlaylistItem_h_
23 /**
24 * @file KwPlaylistItem.h
25 * @brief An item that can be added to a playlist.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssScope.h"
30 #include "KwFilterObject.h"
31 #include "Factory.h"
33 #include <KwExport.h>
35 #include <QString>
36 #include <QList>
37 #include <QDomDocument>
38 #include <QDomDocumentFragment>
40 class KwResourceManager;
41 class KwResourceLink;
42 class KwPlaylistItem;
43 class KwPlaylistNode;
45 #define KW_PLAYLIST_ITEM \
46 private: \
47 /* \
48 * Static private variables \
49 */ \
50 static bool s_registered;
52 #define KW_REGISTER_PLAYLIST_ITEM(X, KEY) \
53 bool X::s_registered = KwPlaylistItem::factory()->addType< X >(KEY);
55 /// An item that can be added to a playlist.
56 /**
57 * Inherit from this class for each playlist item type.
59 class KWMAIN_EXPORT KwPlaylistItem : public KwFilterObject, public KwCssScope
61 public:
64 * Item factory
67 /// Factory of items identified by strings and constructed from DOM.
68 typedef ::Factory<QString, KwPlaylistItem, META_TUPLE((const QDomElement&, KwResourceManager*))> Factory;
70 /// Get a factory object.
71 static Factory* factory();
74 * Constructors + destructor.
77 /// Default constructor.
78 KwPlaylistItem();
80 /// Construct from a DOM element.
81 KwPlaylistItem(const QDomElement& element, KwResourceManager* resourceManager);
83 /// Destructor.
84 virtual ~KwPlaylistItem();
87 * DOM Translation.
90 /// Create an item from a DOM element.
91 static KwPlaylistItem* createFromDom(const QDomElement& element, KwResourceManager* resourceManager);
93 /// Export this item to the DOM.
94 void exportToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const;
96 /// Get the type of the item.
97 virtual QString itemType() const = 0;
99 /// Export details of this item to the DOM.
100 virtual void exportDetailsToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const = 0;
103 * Main interface.
106 /// Get a tree node for this item.
107 virtual KwPlaylistNode* getNode(KwPlaylistNode* parent) = 0;
109 protected:
112 * Protected methods
115 /** Indicate that elements of a particular tag name have been handled.
116 * This clears the specified elements from the DOM preserve.
118 void elementsHandled(const QString& tagName);
120 /** Indicate that the first elements of a particular tag name have been handled.
121 * This clears the specified element from the DOM preserve.
123 void elementHandled(const QString& tagName);
125 /** Get a resource by name.
126 * @param name Name of resource.
127 * @param create If true the resource link is created if it doesn't exist.
129 KwResourceLink* getResource(const QString& name, bool create = true);
131 /** Set a resource associated with a name.
132 * @param name Name of resource.
133 * @param link Link to associate with @p name.
135 KwResourceLink* setResource(const QString& name, KwResourceLink* link);
137 /** Delete a resource.
138 * @param name Name of resource to delete.
140 void deleteResource(const QString& name);
142 private:
145 * Types
148 /// Resource information.
149 struct Resource
151 QString name;
152 KwResourceLink* link;
154 typedef QList<Resource> Resources;
157 * Variables
160 /// Document to store fragment in.
161 QDomDocument m_domDocument;
163 /// Fragment of DOM from save file which needs preserving.
164 QDomDocumentFragment m_domPreserve;
166 /// Resources.
167 Resources m_resources;
170 #endif // _KwPlaylistItem_h_