1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2017-09-24
* Description : a media server to export collections through DLNA.
* Implementation inspired on Platinum File Media Server.
*
* SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "dlnaserver.h"
namespace DigikamGenericMediaServerPlugin
{
DLNAMediaServer::DLNAMediaServer(const char* friendly_name,
bool show_ip,
const char* uuid,
NPT_UInt16 port,
bool port_rebind)
: PLT_MediaServer(friendly_name,
show_ip,
uuid,
port,
port_rebind),
DLNAMediaServerDelegate("/")
{
SetDelegate(this);
}
void DLNAMediaServer::addAlbumsOnServer(const MediaServerMap& map)<--- Derived function 'DLNAMediaServer::addAlbumsOnServer'
{
static_cast<DLNAMediaServerDelegate*>(GetDelegate())->addAlbumsOnServer(map);
}
DLNAMediaServer::~DLNAMediaServer()
{
}
NPT_Result DLNAMediaServer::SetupIcons()
{
QString path;
if (QApplication::applicationName() == QLatin1String("digikam"))
{
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/logo-digikam.png"));
}
else
{
path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("showfoto/data/logo-showfoto.png"));
}
QByteArray icon;
QImage img(path);
QString uri;
int depth;
int size;
if (!img.isNull())
{
qCDebug(DIGIKAM_MEDIASRV_LOG) << "Setup Media Server icons";
size = 256;
icon = iconData(img, size, uri, depth);
AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
size = 120;
icon = iconData(img, size, uri, depth);
AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
size = 48;
icon = iconData(img, size, uri, depth);
AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
size = 32;
icon = iconData(img, size, uri, depth);
AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
size = 16;
icon = iconData(img, size, uri, depth);
AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
return NPT_SUCCESS;
}
return NPT_FAILURE;
}
QByteArray DLNAMediaServer::iconData(const QImage& img, int size, QString& uri, int& depth) const
{
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
QImage icon = img.scaled(size, size);
icon.save(&buffer, "PNG");
buffer.close();
uri = QString::fromLatin1("/icon%1x%2.png").arg(size).arg(size);
depth = icon.depth();
return ba;
}
} // namespace DigikamGenericMediaServerPlugin
|