Basic openoffice.org control, and listening for new presentation documents, still...
[kworship.git] / kworship / archive / KwResourceLink.cpp
bloba387e35a3ef1e534516e84fce10c078de899883d
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 /**
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()
38 : m_type(Null)
39 , m_url()
40 , m_path()
44 /// Construct from a DOM element.
45 KwResourceLink::KwResourceLink(const QDomElement& element, KwResourceManager* resourceManager)
46 : m_type(Null)
47 , m_url()
48 , m_path()
50 QString type = element.attribute("type");
51 if (type == "url")
53 m_type = Url;
54 m_url = element.text();
58 /// Construct a URL link.
59 KwResourceLink::KwResourceLink(const KUrl& url)
60 : m_type(Url)
61 , m_url(url)
62 , m_path()
66 /// Construct a path link.
67 KwResourceLink::KwResourceLink(Type type, const QString& path)
68 : m_type(type)
69 , m_url()
70 , m_path(path)
72 Q_ASSERT(type != Null && type != Url);
75 /// Destructor.
76 KwResourceLink::~KwResourceLink()
81 * DOM Translation.
84 /// Export this resource link into a DOM.
85 void KwResourceLink::exportToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const
87 resourceManager->addResource(this);
88 switch (m_type)
90 case Url:
92 element.setAttribute("type", "url");
93 element.appendChild(document.createTextNode(m_url.url()));
94 break;
96 default:
98 break;
104 * Accessors
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
116 return m_type;
119 /// Get the url.
120 KUrl KwResourceLink::url() const
122 Q_ASSERT(m_type == Url);
123 return m_url;
126 /// Get the type dependent path.
127 QString KwResourceLink::path() const
129 Q_ASSERT(m_type != Null && m_type != Url);
130 return m_path;