1 | /* |
2 | * Copyright (C) 2011 Tuomo Penttinen, all rights reserved. |
3 | * |
4 | * Author: Tuomo Penttinen <tp@herqq.org> |
5 | * |
6 | * This file is part of an application named HUpnpAvSimpleTestApp |
7 | * used for demonstrating how to use the Herqq UPnP A/V (HUPnPAv) library. |
8 | * |
9 | * HUpnpAvSimpleTestApp is free software: you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation, either version 3 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * HUpnpAvSimpleTestApp is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with HUpnpAvSimpleTestApp. If not, see <http://www.gnu.org/licenses/>. |
21 | */ |
22 | |
23 | #include "controlpoint_navigatoritem.h" |
24 | |
25 | #include <HUpnpCore/HDeviceInfo> |
26 | #include <HUpnpCore/HClientService> |
27 | #include <HUpnpCore/HStateVariableInfo> |
28 | |
29 | #include <HUpnpAv/HContainer> |
30 | #include <HUpnpAv/HMediaBrowser> |
31 | #include <HUpnpAv/HConnectionInfo> |
32 | #include <HUpnpAv/HMediaRendererAdapter> |
33 | #include <HUpnpAv/HContentDirectoryAdapter> |
34 | |
35 | #include <QVariant> |
36 | |
37 | using namespace Herqq::Upnp; |
38 | using namespace Herqq::Upnp::Av; |
39 | |
40 | /******************************************************************************* |
41 | * ControlPointNavigatorItem |
42 | ******************************************************************************/ |
43 | ControlPointNavigatorItem::ControlPointNavigatorItem( |
44 | ControlPointNavigatorItem *parent) : |
45 | m_childItems(), m_parentItem(parent) |
46 | { |
47 | } |
48 | |
49 | ControlPointNavigatorItem::~ControlPointNavigatorItem() |
50 | { |
51 | qDeleteAll(m_childItems); |
52 | } |
53 | |
54 | void ControlPointNavigatorItem::appendChild(ControlPointNavigatorItem* item) |
55 | { |
56 | Q_ASSERT(item); |
57 | m_childItems.append(item); |
58 | } |
59 | |
60 | void ControlPointNavigatorItem::removeChild(qint32 index) |
61 | { |
62 | Q_ASSERT(index < m_childItems.size()); |
63 | delete m_childItems.at(index); |
64 | m_childItems.removeAt(index); |
65 | } |
66 | |
67 | ControlPointNavigatorItem* ControlPointNavigatorItem::child(int row) const |
68 | { |
69 | return m_childItems.value(row); |
70 | } |
71 | |
72 | int ControlPointNavigatorItem::childCount() const |
73 | { |
74 | return m_childItems.count(); |
75 | } |
76 | |
77 | int ControlPointNavigatorItem::columnCount() const |
78 | { |
79 | return 1; |
80 | } |
81 | |
82 | ControlPointNavigatorItem* ControlPointNavigatorItem::parent() |
83 | { |
84 | return m_parentItem; |
85 | } |
86 | |
87 | int ControlPointNavigatorItem::row() const |
88 | { |
89 | if (m_parentItem) |
90 | { |
91 | for(int i = 0; i < m_parentItem->m_childItems.size(); ++i) |
92 | { |
93 | if (m_parentItem->m_childItems.at(i) == this) |
94 | { |
95 | return i; |
96 | } |
97 | } |
98 | } |
99 | return 0; |
100 | } |
101 | |
102 | int ControlPointNavigatorItem::rowCount() const |
103 | { |
104 | qint32 rowCount = childCount(); |
105 | foreach(ControlPointNavigatorItem* child, m_childItems) |
106 | { |
107 | rowCount += child->rowCount(); |
108 | } |
109 | |
110 | return rowCount; |
111 | } |
112 | |
113 | /******************************************************************************* |
114 | * RootItem |
115 | ******************************************************************************/ |
116 | RootItem::RootItem(ControlPointNavigatorItem* parent) : |
117 | ControlPointNavigatorItem(parent) |
118 | { |
119 | } |
120 | |
121 | RootItem::~RootItem() |
122 | { |
123 | } |
124 | |
125 | QVariant RootItem::data (int /*column*/) const |
126 | { |
127 | return "Root" ; |
128 | } |
129 | |
130 | void RootItem::accept(ControlPointNavigatorItemVisitor* /*visitor*/) |
131 | { |
132 | } |
133 | |
134 | /******************************************************************************* |
135 | * ContainerItem |
136 | ******************************************************************************/ |
137 | ContainerItem::ContainerItem( |
138 | const QString& name, ControlPointNavigatorItem* parent) : |
139 | ControlPointNavigatorItem(parent), m_name(name) |
140 | { |
141 | } |
142 | |
143 | ContainerItem::~ContainerItem() |
144 | { |
145 | } |
146 | |
147 | QVariant ContainerItem::data (int /*column*/) const |
148 | { |
149 | return m_name; |
150 | } |
151 | |
152 | void ContainerItem::accept(ControlPointNavigatorItemVisitor* /*visitor*/) |
153 | { |
154 | } |
155 | |
156 | /******************************************************************************* |
157 | * RendererItem |
158 | ******************************************************************************/ |
159 | RendererItem::RendererItem( |
160 | HMediaRendererAdapter* renderer, ControlPointNavigatorItem* parent) : |
161 | ControlPointNavigatorItem(parent), m_renderer(renderer) |
162 | { |
163 | Q_ASSERT(m_renderer); |
164 | } |
165 | |
166 | RendererItem::~RendererItem() |
167 | { |
168 | } |
169 | |
170 | QVariant RendererItem::data(int /*column*/) const |
171 | { |
172 | return m_renderer->device()->info().friendlyName(); |
173 | } |
174 | |
175 | void RendererItem::accept(ControlPointNavigatorItemVisitor* visitor) |
176 | { |
177 | visitor->visit(this); |
178 | } |
179 | |
180 | /******************************************************************************* |
181 | * ConnectionItem |
182 | ******************************************************************************/ |
183 | ConnectionItem::ConnectionItem( |
184 | HConnection* connection, ControlPointNavigatorItem* parent) : |
185 | ControlPointNavigatorItem(parent), m_connection(connection) |
186 | { |
187 | Q_ASSERT(m_connection); |
188 | } |
189 | |
190 | ConnectionItem::~ConnectionItem() |
191 | { |
192 | } |
193 | |
194 | QVariant ConnectionItem::data(int /*column*/) const |
195 | { |
196 | if (!m_connection) |
197 | { |
198 | return QVariant(); |
199 | } |
200 | |
201 | return QString("Id:%1" ).arg( |
202 | QString::number(m_connection->info().connectionId())); |
203 | } |
204 | |
205 | void ConnectionItem::accept(ControlPointNavigatorItemVisitor* visitor) |
206 | { |
207 | visitor->visit(this); |
208 | } |
209 | |
210 | /******************************************************************************* |
211 | * CdsContainerItem |
212 | ******************************************************************************/ |
213 | CdsContainerItem::CdsContainerItem( |
214 | HContainer* container, |
215 | HCdsDataSource* dataSource, |
216 | ControlPointNavigatorItem* parent) : |
217 | ControlPointNavigatorItem(parent), |
218 | m_container(container), m_dataSource(dataSource) |
219 | { |
220 | Q_ASSERT(m_container); |
221 | Q_ASSERT(m_dataSource); |
222 | } |
223 | |
224 | CdsContainerItem::~CdsContainerItem() |
225 | { |
226 | } |
227 | |
228 | QVariant CdsContainerItem::data(int /*column*/) const |
229 | { |
230 | return m_container->title(); |
231 | } |
232 | |
233 | void CdsContainerItem::accept(ControlPointNavigatorItemVisitor* visitor) |
234 | { |
235 | visitor->visit(this); |
236 | } |
237 | |
238 | /******************************************************************************* |
239 | * ContentDirectoryItem |
240 | ******************************************************************************/ |
241 | ContentDirectoryItem::ContentDirectoryItem( |
242 | HMediaBrowser* browser, ControlPointNavigatorItem* parent) : |
243 | ControlPointNavigatorItem(parent), m_browser(browser) |
244 | { |
245 | Q_ASSERT(m_browser); |
246 | } |
247 | |
248 | ContentDirectoryItem::~ContentDirectoryItem() |
249 | { |
250 | delete m_browser; |
251 | } |
252 | |
253 | QVariant ContentDirectoryItem::data(int /*column*/) const |
254 | { |
255 | return m_browser->contentDirectory()->service()->parentDevice()->info().friendlyName(); |
256 | } |
257 | |
258 | void ContentDirectoryItem::accept(ControlPointNavigatorItemVisitor* visitor) |
259 | { |
260 | visitor->visit(this); |
261 | } |
262 | |