~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/dlnaexport/extra/hupnp/src/devicehosting/devicehost/hdevicehost_configuration.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
 
3
 *
 
4
 *  Author: Tuomo Penttinen <tp@herqq.org>
 
5
 *
 
6
 *  This file is part of Herqq UPnP (HUPnP) library.
 
7
 *
 
8
 *  Herqq UPnP is free software: you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU Lesser General Public License as published by
 
10
 *  the Free Software Foundation, either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  Herqq UPnP is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
 *  GNU Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public License
 
19
 *  along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#include "hdevicehost_configuration.h"
 
23
#include "hdevicehost_configuration_p.h"
 
24
 
 
25
#include "../../devicemodel/hdevicemodel_infoprovider.h"
 
26
#include "../../devicemodel/server/hdevicemodelcreator.h"
 
27
 
 
28
#include "../../general/hupnp_global_p.h"
 
29
#include "../../utils/hmisc_utils_p.h"
 
30
 
 
31
namespace Herqq
 
32
{
 
33
 
 
34
namespace Upnp
 
35
{
 
36
 
 
37
/*******************************************************************************
 
38
 * HDeviceConfigurationPrivate
 
39
 ******************************************************************************/
 
40
HDeviceConfigurationPrivate::HDeviceConfigurationPrivate() :
 
41
    m_pathToDeviceDescriptor(), m_cacheControlMaxAgeInSecs(1800)
 
42
{
 
43
}
 
44
 
 
45
HDeviceConfigurationPrivate::~HDeviceConfigurationPrivate()
 
46
{
 
47
}
 
48
 
 
49
/*******************************************************************************
 
50
 * HDeviceConfiguration
 
51
 ******************************************************************************/
 
52
HDeviceConfiguration::HDeviceConfiguration() :
 
53
    h_ptr(new HDeviceConfigurationPrivate())
 
54
{
 
55
}
 
56
 
 
57
HDeviceConfiguration::~HDeviceConfiguration()
 
58
{
 
59
    delete h_ptr;
 
60
}
 
61
 
 
62
HDeviceConfiguration* HDeviceConfiguration::newInstance() const
 
63
{
 
64
    return new HDeviceConfiguration();
 
65
}
 
66
 
 
67
void HDeviceConfiguration::doClone(HClonable* target) const
 
68
{
 
69
    HDeviceConfiguration* conf = dynamic_cast<HDeviceConfiguration*>(target);
 
70
 
 
71
    if (!conf)
 
72
    {
 
73
        return;
 
74
    }
 
75
 
 
76
    conf->h_ptr->m_cacheControlMaxAgeInSecs = h_ptr->m_cacheControlMaxAgeInSecs;
 
77
    conf->h_ptr->m_pathToDeviceDescriptor = h_ptr->m_pathToDeviceDescriptor;
 
78
}
 
79
 
 
80
HDeviceConfiguration* HDeviceConfiguration::clone() const
 
81
{
 
82
    return static_cast<HDeviceConfiguration*>(HClonable::clone());
 
83
}
 
84
 
 
85
QString HDeviceConfiguration::pathToDeviceDescription() const
 
86
{
 
87
    return h_ptr->m_pathToDeviceDescriptor;
 
88
}
 
89
 
 
90
void HDeviceConfiguration::setPathToDeviceDescription(
 
91
    const QString& pathToDeviceDescriptor)
 
92
{
 
93
    h_ptr->m_pathToDeviceDescriptor = pathToDeviceDescriptor;
 
94
}
 
95
 
 
96
void HDeviceConfiguration::setCacheControlMaxAge(qint32 maxAgeInSecs)
 
97
{
 
98
    static const qint32 max = 60*60*24;
 
99
 
 
100
    if (maxAgeInSecs < 5)
 
101
    {
 
102
        maxAgeInSecs = 5;
 
103
    }
 
104
    else if (maxAgeInSecs > max)
 
105
    {
 
106
        maxAgeInSecs = max;
 
107
    }
 
108
 
 
109
    h_ptr->m_cacheControlMaxAgeInSecs = maxAgeInSecs;
 
110
}
 
111
 
 
112
qint32 HDeviceConfiguration::cacheControlMaxAge() const
 
113
{
 
114
    return h_ptr->m_cacheControlMaxAgeInSecs;
 
115
}
 
116
 
 
117
bool HDeviceConfiguration::isValid() const
 
118
{
 
119
    return !h_ptr->m_pathToDeviceDescriptor.isEmpty();
 
120
}
 
121
 
 
122
/*******************************************************************************
 
123
 * HDeviceHostConfigurationPrivate
 
124
 ******************************************************************************/
 
125
HDeviceHostConfigurationPrivate::HDeviceHostConfigurationPrivate() :
 
126
    m_collection(),
 
127
    m_individualAdvertisementCount(2),
 
128
    m_subscriptionExpirationTimeout(0),
 
129
    m_networkAddresses(),
 
130
    m_deviceCreator(0),
 
131
    m_infoProvider(0)
 
132
{
 
133
    QHostAddress ha = findBindableHostAddress();
 
134
    m_networkAddresses.append(ha);
 
135
}
 
136
 
 
137
/*******************************************************************************
 
138
 * HDeviceHostConfiguration
 
139
 ******************************************************************************/
 
140
HDeviceHostConfiguration::HDeviceHostConfiguration() :
 
141
    h_ptr(new HDeviceHostConfigurationPrivate())
 
142
{
 
143
}
 
144
 
 
145
HDeviceHostConfiguration::HDeviceHostConfiguration(
 
146
    const HDeviceConfiguration& arg) :
 
147
        h_ptr(new HDeviceHostConfigurationPrivate())
 
148
{
 
149
    add(arg);
 
150
}
 
151
 
 
152
HDeviceHostConfiguration::~HDeviceHostConfiguration()
 
153
{
 
154
    qDeleteAll(h_ptr->m_collection);
 
155
    delete h_ptr;
 
156
}
 
157
 
 
158
HDeviceHostConfiguration* HDeviceHostConfiguration::newInstance() const
 
159
{
 
160
    return new HDeviceHostConfiguration();
 
161
}
 
162
 
 
163
void HDeviceHostConfiguration::doClone(HClonable* target) const
 
164
{
 
165
    HDeviceHostConfiguration* conf =
 
166
        dynamic_cast<HDeviceHostConfiguration*>(target);
 
167
 
 
168
    if (!conf)
 
169
    {
 
170
        return;
 
171
    }
 
172
 
 
173
    conf->h_ptr->m_individualAdvertisementCount =
 
174
        h_ptr->m_individualAdvertisementCount;
 
175
 
 
176
    conf->h_ptr->m_networkAddresses = h_ptr->m_networkAddresses;
 
177
 
 
178
    conf->h_ptr->m_subscriptionExpirationTimeout =
 
179
        h_ptr->m_subscriptionExpirationTimeout;
 
180
 
 
181
    QList<const HDeviceConfiguration*> confCollection;
 
182
    foreach(const HDeviceConfiguration* conf, h_ptr->m_collection)
 
183
    {
 
184
        confCollection.append(conf->clone());
 
185
    }
 
186
 
 
187
    qDeleteAll(conf->h_ptr->m_collection);
 
188
    conf->h_ptr->m_collection = confCollection;
 
189
 
 
190
    conf->h_ptr->m_deviceCreator.reset(
 
191
        h_ptr->m_deviceCreator ? h_ptr->m_deviceCreator->clone() : 0);
 
192
 
 
193
    conf->h_ptr->m_infoProvider.reset(
 
194
        h_ptr->m_infoProvider ? h_ptr->m_infoProvider->clone() : 0);
 
195
}
 
196
 
 
197
HDeviceHostConfiguration* HDeviceHostConfiguration::clone() const
 
198
{
 
199
    return static_cast<HDeviceHostConfiguration*>(HClonable::clone());
 
200
}
 
201
 
 
202
bool HDeviceHostConfiguration::add(const HDeviceConfiguration& arg)
 
203
{
 
204
    if (arg.isValid())
 
205
    {
 
206
        h_ptr->m_collection.push_back(arg.clone());
 
207
        return true;
 
208
    }
 
209
 
 
210
    return false;
 
211
}
 
212
 
 
213
void HDeviceHostConfiguration::clear()
 
214
{
 
215
    qDeleteAll(h_ptr->m_collection);
 
216
    h_ptr->m_collection.clear();
 
217
}
 
218
 
 
219
QList<const HDeviceConfiguration*> HDeviceHostConfiguration::deviceConfigurations() const
 
220
{
 
221
    return h_ptr->m_collection;
 
222
}
 
223
 
 
224
qint32 HDeviceHostConfiguration::individualAdvertisementCount() const
 
225
{
 
226
    return h_ptr->m_individualAdvertisementCount;
 
227
}
 
228
 
 
229
QList<QHostAddress> HDeviceHostConfiguration::networkAddressesToUse() const
 
230
{
 
231
    return h_ptr->m_networkAddresses;
 
232
}
 
233
 
 
234
HDeviceModelCreator* HDeviceHostConfiguration::deviceModelCreator() const
 
235
{
 
236
    return h_ptr->m_deviceCreator.data();
 
237
}
 
238
 
 
239
HDeviceModelInfoProvider* HDeviceHostConfiguration::deviceModelInfoProvider() const
 
240
{
 
241
    return h_ptr->m_infoProvider.data();
 
242
}
 
243
 
 
244
void HDeviceHostConfiguration::setDeviceModelCreator(
 
245
    const HDeviceModelCreator& deviceCreator)
 
246
{
 
247
    h_ptr->m_deviceCreator.reset(deviceCreator.clone());
 
248
}
 
249
 
 
250
void HDeviceHostConfiguration::setDeviceModelInfoProvider(
 
251
    const HDeviceModelInfoProvider& infoProvider)
 
252
{
 
253
    h_ptr->m_infoProvider.reset(infoProvider.clone());
 
254
}
 
255
 
 
256
void HDeviceHostConfiguration::setIndividualAdvertisementCount(qint32 arg)
 
257
{
 
258
    if (arg < 1)
 
259
    {
 
260
        arg = 1;
 
261
    }
 
262
 
 
263
    h_ptr->m_individualAdvertisementCount = arg;
 
264
}
 
265
 
 
266
qint32 HDeviceHostConfiguration::subscriptionExpirationTimeout() const
 
267
{
 
268
    return h_ptr->m_subscriptionExpirationTimeout;
 
269
}
 
270
 
 
271
void HDeviceHostConfiguration::setSubscriptionExpirationTimeout(qint32 arg)
 
272
{
 
273
    static const qint32 max = 60*60*24;
 
274
 
 
275
    if (arg > max)
 
276
    {
 
277
        arg = max;
 
278
    }
 
279
 
 
280
    h_ptr->m_subscriptionExpirationTimeout = arg;
 
281
}
 
282
 
 
283
bool HDeviceHostConfiguration::setNetworkAddressesToUse(
 
284
    const QList<QHostAddress>& addresses)
 
285
{
 
286
    if (!HSysInfo::instance().areLocalAddresses(addresses))
 
287
    {
 
288
        return false;
 
289
    }
 
290
 
 
291
    h_ptr->m_networkAddresses = addresses;
 
292
    return true;
 
293
}
 
294
 
 
295
bool HDeviceHostConfiguration::isEmpty() const
 
296
{
 
297
    return h_ptr->m_collection.isEmpty();
 
298
}
 
299
 
 
300
bool HDeviceHostConfiguration::isValid() const
 
301
{
 
302
    return !isEmpty() && deviceModelCreator();
 
303
}
 
304
 
 
305
}
 
306
}