File indexing completed on 2025-01-05 03:52:08

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-09-24
0007  * Description : a media server to export collections through DLNA.
0008  *               Implementation inspired on Platinum File Media Server.
0009  *
0010  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "dlnaserver.h"
0017 
0018 namespace DigikamGenericMediaServerPlugin
0019 {
0020 
0021 DLNAMediaServer::DLNAMediaServer(const char*  friendly_name,
0022                                  bool         show_ip,
0023                                  const char*  uuid,
0024                                  NPT_UInt16   port,
0025                                  bool         port_rebind)
0026     : PLT_MediaServer(friendly_name,
0027                       show_ip,
0028                       uuid,
0029                       port,
0030                       port_rebind),
0031       DLNAMediaServerDelegate("/")
0032 {
0033     SetDelegate(this);
0034 }
0035 
0036 void DLNAMediaServer::addAlbumsOnServer(const MediaServerMap& map)
0037 {
0038     static_cast<DLNAMediaServerDelegate*>(GetDelegate())->addAlbumsOnServer(map);
0039 }
0040 
0041 DLNAMediaServer::~DLNAMediaServer()
0042 {
0043 }
0044 
0045 NPT_Result DLNAMediaServer::SetupIcons()
0046 {
0047     QString path;
0048 
0049     if (QApplication::applicationName() == QLatin1String("digikam"))
0050     {
0051         path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/logo-digikam.png"));
0052     }
0053     else
0054     {
0055         path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("showfoto/data/logo-showfoto.png"));
0056     }
0057 
0058     QByteArray icon;
0059     QImage     img(path);
0060     QString    uri;
0061     int        depth;
0062     int        size;
0063 
0064     if (!img.isNull())
0065     {
0066         qCDebug(DIGIKAM_MEDIASRV_LOG) << "Setup Media Server icons";
0067 
0068         size = 256;
0069         icon = iconData(img, size, uri, depth);
0070         AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
0071         size = 120;
0072         icon = iconData(img, size, uri, depth);
0073         AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
0074         size = 48;
0075         icon = iconData(img, size, uri, depth);
0076         AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
0077         size = 32;
0078         icon = iconData(img, size, uri, depth);
0079         AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
0080         size = 16;
0081         icon = iconData(img, size, uri, depth);
0082         AddIcon(PLT_DeviceIcon("image/png", size, size, depth, uri.toLatin1().data()), icon.data(), icon.size(), true);
0083 
0084         return NPT_SUCCESS;
0085     }
0086 
0087     return NPT_FAILURE;
0088 }
0089 
0090 QByteArray DLNAMediaServer::iconData(const QImage& img, int size, QString& uri, int& depth) const
0091 {
0092     QByteArray ba;
0093     QBuffer    buffer(&ba);
0094     buffer.open(QIODevice::WriteOnly);
0095     QImage icon = img.scaled(size, size);
0096     icon.save(&buffer, "PNG");
0097     buffer.close();
0098 
0099     uri         = QString::fromLatin1("/icon%1x%2.png").arg(size).arg(size);
0100     depth       = icon.depth();
0101 
0102     return ba;
0103 }
0104 
0105 } // namespace DigikamGenericMediaServerPlugin