| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and Digia. For licensing terms and |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 24 | ** |
| 25 | ** In addition, as a special exception, Digia gives you certain additional |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 28 | ** |
| 29 | ** GNU General Public License Usage |
| 30 | ** Alternatively, this file may be used under the terms of the GNU |
| 31 | ** General Public License version 3.0 as published by the Free Software |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
| 33 | ** packaging of this file. Please review the following information to |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
| 36 | ** |
| 37 | ** |
| 38 | ** $QT_END_LICENSE$ |
| 39 | ** |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | #include "qgalleryresource.h" |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE_DOCGALLERY |
| 45 | |
| 46 | /*! |
| 47 | \class QGalleryResource |
| 48 | |
| 49 | \ingroup gallery |
| 50 | |
| 51 | \inmodule QtDocGallery |
| 52 | |
| 53 | \brief The QGalleryResource class provides a resource identifier for a |
| 54 | gallery item. |
| 55 | |
| 56 | A gallery resource is URL and a set of disambiguating meta-data properties |
| 57 | used to identify a single representation of a gallery item that may be |
| 58 | accessible using multiple protocols or in multiple formats. This may be |
| 59 | useful when querying something like a media server which can serve the same |
| 60 | video in multiple resolutions, instead of listing the same video multiple |
| 61 | times it would list it only once but include a resource for each resolution. |
| 62 | */ |
| 63 | |
| 64 | /*! |
| 65 | Constructs a null resource. |
| 66 | */ |
| 67 | |
| 68 | QGalleryResource::QGalleryResource() |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | /*! |
| 73 | Constructs a resource from a \a url. |
| 74 | */ |
| 75 | |
| 76 | QGalleryResource::QGalleryResource(const QUrl &url) |
| 77 | : m_url(url) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | /*! |
| 82 | Constructs a resource from a \a url and a set of \a attributes. |
| 83 | */ |
| 84 | |
| 85 | QGalleryResource::QGalleryResource(const QUrl &url, QMap<int, QVariant> attributes) |
| 86 | : m_url(url) |
| 87 | , m_attributes(attributes) |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | /*! |
| 92 | Constructs a copy of a \a resource. |
| 93 | */ |
| 94 | |
| 95 | QGalleryResource::QGalleryResource(const QGalleryResource &resource) |
| 96 | : m_url(resource.m_url) |
| 97 | , m_attributes(resource.m_attributes) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | /*! |
| 102 | Destroys a resource. |
| 103 | */ |
| 104 | |
| 105 | QGalleryResource::~QGalleryResource() |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | /*! |
| 110 | Assigns the value of \a resource to another resource. |
| 111 | */ |
| 112 | |
| 113 | QGalleryResource &QGalleryResource::operator =(const QGalleryResource &resource) |
| 114 | { |
| 115 | m_url = resource.m_url; |
| 116 | m_attributes = resource.m_attributes; |
| 117 | |
| 118 | return *this; |
| 119 | } |
| 120 | |
| 121 | /*! |
| 122 | Compares \a resource to another resource. |
| 123 | |
| 124 | Returns true if both resources are the same, and false otherwise. |
| 125 | */ |
| 126 | |
| 127 | bool QGalleryResource::operator ==(const QGalleryResource &resource) const |
| 128 | { |
| 129 | return m_url == resource.m_url && m_attributes == resource.m_attributes; |
| 130 | } |
| 131 | |
| 132 | /*! |
| 133 | Compares \a resource to another resource. |
| 134 | |
| 135 | Returns true if the resource are not the same, and false otherwise. |
| 136 | */ |
| 137 | |
| 138 | bool QGalleryResource::operator !=(const QGalleryResource &resource) const |
| 139 | { |
| 140 | return m_url != resource.m_url || m_attributes != resource.m_attributes; |
| 141 | } |
| 142 | |
| 143 | /*! |
| 144 | Returns the URL of a resource. |
| 145 | */ |
| 146 | |
| 147 | QUrl QGalleryResource::url() const |
| 148 | { |
| 149 | return m_url; |
| 150 | } |
| 151 | |
| 152 | /*! |
| 153 | Returns the attributes of a resource. |
| 154 | */ |
| 155 | |
| 156 | QMap<int, QVariant> QGalleryResource::attributes() const |
| 157 | { |
| 158 | return m_attributes; |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | Returns the value of the resource attribute identified by \a key. |
| 163 | */ |
| 164 | |
| 165 | QVariant QGalleryResource::attribute(int key) const |
| 166 | { |
| 167 | return m_attributes.value(akey: key); |
| 168 | } |
| 169 | |
| 170 | QT_END_NAMESPACE_DOCGALLERY |
| 171 | |