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 #ifndef DIGIKAM_DLNA_SERVER_DELEGATE_H 0017 #define DIGIKAM_DLNA_SERVER_DELEGATE_H 0018 0019 // Qt includes 0020 0021 #include <QString> 0022 #include <QUrl> 0023 #include <QList> 0024 #include <QMap> 0025 #include <QImage> 0026 #include <QByteArray> 0027 #include <QBuffer> 0028 0029 // Local includes 0030 0031 #include "digikam_debug.h" 0032 #include "previewloadthread.h" 0033 #include "dimg.h" 0034 #include "drawdecoder.h" 0035 0036 // Local includes 0037 0038 #include "dmediaserver.h" 0039 0040 // Platinum includes 0041 0042 #include "Neptune.h" 0043 #include "PltMediaServer.h" 0044 #include "PltMediaCache.h" 0045 0046 using namespace Digikam; 0047 0048 namespace DigikamGenericMediaServerPlugin 0049 { 0050 0051 /** 0052 * File Media Server Delegate for digiKam. 0053 * The DLNAMediaServerDelegate class is based on PLT_MediaServerDelegate 0054 * implementation for a file system backed Media Server. 0055 */ 0056 class DLNAMediaServerDelegate : public PLT_MediaServerDelegate 0057 { 0058 public: 0059 0060 /// Constructor and destructor 0061 explicit DLNAMediaServerDelegate(const char* url_root, 0062 bool use_cache = false); 0063 ~DLNAMediaServerDelegate() override; 0064 0065 /// Class methods 0066 static NPT_String BuildSafeResourceUri(const NPT_HttpUrl& base_uri, 0067 const char* host, 0068 const char* file_path); 0069 0070 void addAlbumsOnServer(const MediaServerMap& map); 0071 0072 protected: 0073 0074 /// PLT_MediaServerDelegate methods 0075 NPT_Result OnBrowseMetadata(PLT_ActionReference& action, 0076 const char* object_id, 0077 const char* filter, 0078 NPT_UInt32 starting_index, 0079 NPT_UInt32 requested_count, 0080 const char* sort_criteria, 0081 const PLT_HttpRequestContext& context) override; 0082 0083 NPT_Result OnBrowseDirectChildren(PLT_ActionReference& action, 0084 const char* object_id, 0085 const char* filter, 0086 NPT_UInt32 starting_index, 0087 NPT_UInt32 requested_count, 0088 const char* sort_criteria, 0089 const PLT_HttpRequestContext& context) override; 0090 0091 NPT_Result OnSearchContainer(PLT_ActionReference& action, 0092 const char* object_id, 0093 const char* search_criteria, 0094 const char* filter, 0095 NPT_UInt32 starting_index, 0096 NPT_UInt32 requested_count, 0097 const char* sort_criteria, 0098 const PLT_HttpRequestContext& context) override; 0099 0100 NPT_Result ProcessFileRequest(NPT_HttpRequest& request, 0101 const NPT_HttpRequestContext& context, 0102 NPT_HttpResponse& response) override; 0103 0104 /// Overridable methods 0105 virtual NPT_Result ExtractResourcePath(const NPT_HttpUrl& url, 0106 NPT_String& file_path); 0107 0108 virtual NPT_String BuildResourceUri(const NPT_HttpUrl& base_uri, 0109 const char* host, 0110 const char* file_path); 0111 0112 virtual NPT_Result ServeFile(const NPT_HttpRequest& request, 0113 const NPT_HttpRequestContext& context, 0114 NPT_HttpResponse& response, 0115 const NPT_String& file_path); 0116 0117 virtual NPT_Result GetFilePath(const char* object_id, 0118 NPT_String& filepath); 0119 0120 virtual bool ProcessFile(const NPT_String&, 0121 const char* filter = nullptr); 0122 0123 virtual PLT_MediaObject* BuildFromFilePath(const NPT_String& filepath, 0124 const PLT_HttpRequestContext& context, 0125 bool with_count = true, 0126 bool keep_extension_in_title = false, 0127 bool allip = false); 0128 0129 protected: 0130 0131 friend class PLT_MediaItem; 0132 0133 class Private; 0134 Private* const d; 0135 0136 private: 0137 0138 Q_DISABLE_COPY(DLNAMediaServerDelegate) 0139 }; 0140 0141 } // namespace DigikamGenericMediaServerPlugin 0142 0143 #endif // DIGIKAM_DLNA_SERVER_DELEGATE_H