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 KwResourceLink.cpp
22 * @brief A link to a resource file.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwResourceLink.h"
27 #include "KwResourceManager.h"
29 #include <QDomDocument>
30 #include <QDomElement>
33 * Constructors + destructor
36 /// Default constructor.
37 KwResourceLink::KwResourceLink()
44 /// Construct from a DOM element.
45 KwResourceLink::KwResourceLink(const QDomElement
& element
, KwResourceManager
* resourceManager
)
50 QString type
= element
.attribute("type");
54 m_url
= element
.text();
58 /// Construct a URL link.
59 KwResourceLink::KwResourceLink(const KUrl
& url
)
66 /// Construct a path link.
67 KwResourceLink::KwResourceLink(Type type
, const QString
& path
)
72 Q_ASSERT(type
!= Null
&& type
!= Url
);
76 KwResourceLink::~KwResourceLink()
84 /// Export this resource link into a DOM.
85 void KwResourceLink::exportToDom(QDomDocument
& document
, QDomElement
& element
, KwResourceManager
* resourceManager
) const
87 resourceManager
->addResource(this);
92 element
.setAttribute("type", "url");
93 element
.appendChild(document
.createTextNode(m_url
.url()));
107 /// Get whether the link is null.
108 bool KwResourceLink::isNull() const
110 return (Null
== m_type
);
113 /// Get the type of resource link.
114 KwResourceLink::Type
KwResourceLink::type() const
120 KUrl
KwResourceLink::url() const
122 Q_ASSERT(m_type
== Url
);
126 /// Get the type dependent path.
127 QString
KwResourceLink::path() const
129 Q_ASSERT(m_type
!= Null
&& m_type
!= Url
);