File indexing completed on 2025-01-05 03:53:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-07-24
0007  * Description : MJPEG server manager
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_MJPEG_SERVER_MNGR_H
0016 #define DIGIKAM_MJPEG_SERVER_MNGR_H
0017 
0018 // Qt includes
0019 
0020 #include <QObject>
0021 #include <QMap>
0022 #include <QList>
0023 #include <QString>
0024 #include <QUrl>
0025 
0026 // Local includes
0027 
0028 #include "mjpegserver.h"
0029 #include "mjpegstreamsettings.h"
0030 
0031 namespace DigikamGenericMjpegStreamPlugin
0032 {
0033 
0034 class MjpegServerMngr : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     /**
0041      * Setup the list of items to share with the MJPEG server into a single album.
0042      */
0043     void setItemsList(const QString& aname, const QList<QUrl>& urls);
0044 
0045     /**
0046      * Return a flat list of items shared.
0047      */
0048     QList<QUrl> itemsList()                  const;
0049 
0050     /**
0051      * Setup the list of albums to share with MJPEG server.
0052      */
0053     void setCollectionMap(const MjpegServerMap&);
0054 
0055     /**
0056      * Return the current album map shared.
0057      */
0058     MjpegServerMap collectionMap()           const;
0059 
0060     /**
0061      * Setup the MJPEGstream settings.
0062      */
0063     void setSettings(const MjpegStreamSettings& set);
0064 
0065     /**
0066      * Return the MJPEG stream settings.
0067      */
0068     MjpegStreamSettings settings()           const;
0069 
0070     /**
0071      * Start the DLNA server and share the contents. Return true is all is on-line.
0072      */
0073     bool startMjpegServer();
0074 
0075     /**
0076      * Stop the DLNA server and clean-up.
0077      */
0078     void cleanUp();
0079 
0080     /**
0081      * Low level methods to save and load from xml data file.
0082      */
0083     bool save();
0084     bool load();
0085 
0086     /**
0087      * Wrapper to check if server configuration must be saved and restored between application sessions.
0088      */
0089     bool loadAtStartup();
0090     void saveAtShutdown();
0091 
0092     /**
0093      * Return true if server is running in background.
0094      */
0095     bool isRunning()                         const;
0096 
0097     /**
0098      * Return some stats about total albums and total items shared on the network.
0099      */
0100     int  albumsShared()                      const;
0101     int  itemsShared()                       const;
0102 
0103     /**
0104      * Config properties methods.
0105      */
0106     QString configGroupName()                 const;
0107     QString configStartServerOnStartupEntry() const;
0108 
0109     /**
0110      * Send a notification message if MediaServer have been started or not.
0111      */
0112     void mjpegServerNotification(bool started);
0113 
0114 public:
0115 
0116     /**
0117      * This manager is a singleton. Use this method to control the MJPEG server instance.
0118      */
0119     static MjpegServerMngr* instance();
0120 
0121 private:
0122 
0123     // Disable
0124     MjpegServerMngr();
0125     explicit MjpegServerMngr(QObject*) = delete;
0126     ~MjpegServerMngr() override;
0127 
0128 private:
0129 
0130     friend class MjpegServerMngrCreator;
0131 
0132     class Private;
0133     Private* const d;
0134 };
0135 
0136 } // namespace DigikamGenericMjpegStreamPlugin
0137 
0138 #endif // DIGIKAM_MJPEG_SERVER_MNGR_H