1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef METADATA_H 17 #define METADATA_H 18 19 #include <unordered_map> 20 #include <variant> 21 #include "scanner_utils.h" 22 #include "fetch_result.h" 23 #include "abs_shared_result_set.h" 24 25 namespace OHOS { 26 namespace Media { 27 class Metadata { 28 public: 29 Metadata(); 30 ~Metadata() = default; 31 using VariantData = std::variant<int32_t, std::string, int64_t, double>; 32 33 void SetFileId(const VariantData &id); 34 int32_t GetFileId() const; 35 36 void SetFilePath(const VariantData &path); 37 const std::string &GetFilePath() const; 38 39 void SetUri(const VariantData &uri); 40 const std::string &GetUri() const; 41 42 void SetRelativePath(const VariantData &relativePath); 43 const std::string &GetRelativePath() const; 44 45 void SetFileMimeType(const VariantData &mimeType); 46 const std::string &GetFileMimeType() const; 47 48 void SetFileMediaType(const VariantData &mediaType); 49 MediaType GetFileMediaType() const; 50 51 void SetFileName(const VariantData &name); 52 const std::string &GetFileName() const; 53 54 void SetFileSize(const VariantData &size); 55 int64_t GetFileSize() const; 56 57 void SetFileDateAdded(const VariantData &dateAdded); 58 int64_t GetFileDateAdded() const; 59 60 void SetFileDateModified(const VariantData &dateModified); 61 int64_t GetFileDateModified() const; 62 63 void SetFileExtension(const VariantData &fileExt); 64 const std::string &GetFileExtension() const; 65 66 void SetFileTitle(const VariantData &title); 67 const std::string &GetFileTitle() const; 68 69 void SetFileArtist(const VariantData &artist); 70 const std::string &GetFileArtist() const; 71 72 void SetAlbum(const VariantData &album); 73 const std::string &GetAlbum() const; 74 75 void SetFileHeight(const VariantData &height); 76 int32_t GetFileHeight() const; 77 78 void SetFileWidth(const VariantData &width); 79 int32_t GetFileWidth() const; 80 81 void SetOrientation(const VariantData &orientation); 82 int32_t GetOrientation() const; 83 84 void SetFileDuration(const VariantData &duration); 85 int32_t GetFileDuration() const; 86 87 int32_t GetParentId() const; 88 void SetParentId(const VariantData &id); 89 90 void SetAlbumId(const VariantData &albumId); 91 int32_t GetAlbumId() const; 92 93 void SetAlbumName(const VariantData &album); 94 const std::string &GetAlbumName() const; 95 96 void SetRecyclePath(const VariantData &recyclePath); 97 const std::string &GetRecyclePath() const; 98 99 void SetDateTaken(const VariantData &dateTaken); 100 int64_t GetDateTaken() const; 101 102 void SetLongitude(const VariantData &longitude); 103 double GetLongitude() const; 104 105 void SetLatitude(const VariantData &latitude); 106 double GetLatitude() const; 107 108 void SetTimePending(const VariantData &timePending); 109 int64_t GetTimePending() const; 110 111 void SetUserComment(const VariantData &userComment); 112 const std::string &GetUserComment() const; 113 114 void SetAllExif(const VariantData &allExif); 115 const std::string &GetAllExif() const; 116 117 #ifdef MEDIALIBRARY_COMPATIBILITY 118 void SetPhotoSubType(const VariantData &photoSubType); 119 int32_t GetPhotoSubType() const; 120 #endif 121 void SetForAdd(bool forAdd); 122 bool GetForAdd() const; 123 void SetTableName(const std::string &tableName); 124 std::string GetTableName(); 125 126 void Init(); 127 128 using MetadataFnPtr = void (Metadata::*)(const VariantData &); 129 std::unordered_map<std::string, std::pair<ResultSetDataType, MetadataFnPtr>> memberFuncMap_; 130 131 private: 132 int32_t id_; 133 std::string uri_; 134 std::string filePath_; 135 std::string relativePath_; 136 137 std::string mimeType_; 138 MediaType mediaType_; 139 std::string name_; 140 141 int64_t size_; 142 int64_t dateModified_; 143 int64_t dateAdded_; 144 145 std::string fileExt_; 146 int32_t parentId_; 147 148 // audio 149 std::string title_; 150 std::string artist_; 151 std::string album_; 152 153 // video, image 154 int32_t height_; 155 int32_t width_; 156 int32_t duration_; 157 int32_t orientation_; 158 159 // video, audio, image 160 int64_t dateTaken_; 161 162 // image 163 double longitude_; 164 double latitude_; 165 std::string userComment_; 166 std::string allExif_; 167 168 // album 169 int32_t albumId_; 170 std::string albumName_; 171 172 // recycle 173 std::string recyclePath_; 174 175 // pending 176 int64_t timePending_; 177 #ifdef MEDIALIBRARY_COMPATIBILITY 178 // photo subtype 179 int32_t photoSubType_ = 0; 180 #endif 181 bool forAdd_ = false; 182 std::string tableName_; 183 }; 184 } // namespace Media 185 } // namespace OHOS 186 187 #endif // METADATA_H 188