static const std::string uri_absolute_prefix = "file:///";
}
-const std::map<std::string, media_content_orientation_e> orientationMap = {
- {"NORMAL", MEDIA_CONTENT_ORIENTATION_NORMAL},
- {"FLIP_HORIZONTAL", MEDIA_CONTENT_ORIENTATION_HFLIP},
- {"ROTATE_180", MEDIA_CONTENT_ORIENTATION_ROT_180},
- {"FLIP_VERTICAL", MEDIA_CONTENT_ORIENTATION_VFLIP},
- {"TRANSPOSE", MEDIA_CONTENT_ORIENTATION_TRANSPOSE},
- {"ROTATE_90", MEDIA_CONTENT_ORIENTATION_ROT_90},
- {"TRANSVERSE", MEDIA_CONTENT_ORIENTATION_TRANSVERSE},
- {"ROTATE_270", MEDIA_CONTENT_ORIENTATION_ROT_270},
-};
-
std::string get_date(char* tmpStr) {
ScopeLogger();
if (tmpStr) {
void ContentDirToJson(media_folder_h folder, picojson::object& o) {
ScopeLogger();
int ret;
- char* tmpStr = NULL;
- media_content_storage_e storage_type;
+ char *tmpStr = NULL;
// id
ret = media_folder_get_folder_id(folder, &tmpStr);
}
}
- // storageType
- ret = media_folder_get_storage_type(folder, &storage_type);
- // TODO: The function media_folder_get_storage_type is marked as deprecated since 5.0.
- // As an alternative, it is recommended to use storage_get_type_dev function. However,
- // this function does not work with internal storages. The media_folder_get_storage_type
- // function should be kept or moved to internal header by Native API.
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- if (storage_type == MEDIA_CONTENT_STORAGE_INTERNAL) {
- o["storageType"] = picojson::value(std::string("INTERNAL"));
- } else {
- LoggerD("storageType = %d, assuming EXTERNAL as storage type", storage_type);
- o["storageType"] = picojson::value(std::string("EXTERNAL"));
- }
- }
-
// modifiedDate
struct stat stat_res;
if (stat(folder_path.c_str(), &stat_res) == 0) {
ScopeLogger();
int ret = MEDIA_CONTENT_ERROR_NONE;
- std::string description = content.get("description").to_str();
- int rating = std::stoi(content.get("rating").to_str());
bool is_fav = content.get("isFavorite").get<bool>();
if (NULL == media) {
return ret;
}
- ret = media_info_set_description(media, description.c_str());
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Updating description failed.");
- }
-
- ret = media_info_set_rating(media, rating);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Updating rating failed.");
- }
-
ret = media_info_set_favorite(media, is_fav);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Updating isFavorite failed.");
LoggerE("Updating favorite failed.");
}
- if (type == MEDIA_CONTENT_TYPE_IMAGE) {
- std::string orientation = content.get("orientation").to_str();
- auto orientationToSet = orientationMap.find(orientation);
-
- if (orientationToSet != orientationMap.end()) {
- image_meta_h img;
- if (MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) &&
- MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) &&
- MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) {
- LoggerD("orientation update was successful");
- } else {
- LoggerE("orientation update failed");
- }
- image_meta_destroy(img);
- }
- }
-
- if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) {
- picojson::value geo = content.get("geolocation");
- if (geo.evaluate_as_boolean()) {
- LoggerD("geolocation is not null");
- double latitude = atof(geo.get("latitude").to_str().c_str());
- double longitude = atof(geo.get("longitude").to_str().c_str());
- ret = media_info_set_latitude(media, latitude);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Updating geolocation is failed.");
- }
- ret = media_info_set_longitude(media, longitude);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating geolocation is failed.");
- }
- } else {
- LoggerD("geolocation is null");
- }
- }
-
return MEDIA_CONTENT_ERROR_NONE;
}
int ret = MEDIA_CONTENT_ERROR_NONE;
std::string id = content.get("id").to_str();
- std::string new_name = content.get("name").to_str();
media_info_h media = nullptr;
- char* name = nullptr;
- char* path = nullptr;
SCOPE_EXIT {
if (media) {
media_info_destroy(media);
}
- if (name) {
- free(name);
- }
- if (path) {
- free(path);
- }
};
ret = media_info_get_media_from_db(id.c_str(), &media);
LoggerE("media_info_update_to_db failed: %d", ret);
return ret;
}
- ret = media_info_get_display_name(media, &name);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("media_info_get_display_name failed: %d", ret);
- return ret;
- }
- const std::string name_str(name);
- if (name_str != new_name) {
- ret = media_info_get_file_path(media, &path);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("media_info_get_file_path failed: %d", ret);
- return ret;
- }
- std::string path_str(path);
- const size_t p = path_str.rfind(name_str);
- path_str.replace(p, name_str.length(), new_name);
- LoggerD("new media path: %s", path_str.c_str());
- ret = media_info_move_to_db(media, path_str.c_str());
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("media_info_move_to_db failed: %d", ret);
- return ret;
- }
- }
return ret;
}
char* id = NULL;
char* path = NULL;
time_t date;
- media_content_storage_e storageType;
int ret;
}
date = stat_res.st_mtime;
- ret = media_folder_get_storage_type(folder, &storageType);
- // TODO: The function media_folder_get_storage_type is marked as deprecated since 5.0.
- // As an alternative, it is recommended to use storage_get_type_dev function. However,
- // this function does not work with internal storages. The media_folder_get_storage_type
- // function should be kept or moved to internal header by Native API.
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LogAndReportError(ContentManager::convertError(ret), out,
- ("Failed: media_folder_get_storage_type"));
- return;
- }
-
(*out)["id"] = picojson::value(std::string(id));
(*out)["directoryURI"] = picojson::value(std::string(path));
(*out)["title"] = picojson::value(std::string(name));
- if (storageType == MEDIA_CONTENT_STORAGE_INTERNAL) {
- (*out)["storageType"] = picojson::value(std::string("INTERNAL"));
- } else if (storageType == MEDIA_CONTENT_STORAGE_EXTERNAL) {
- (*out)["storageType"] = picojson::value(std::string("EXTERNAL"));
- }
-
(*out)["modifiedDate"] = picojson::value(static_cast<double>(date));
}
void ContentManager::getDirectories(const std::shared_ptr<ReplyCallbackData>& user_data) {
ScopeLogger();
int ret;
- filter_h filter = NULL;
- ret = media_filter_create(&filter);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Failed: media_filter_create failed");
- return;
- }
-
- SCOPE_EXIT {
- media_filter_destroy(filter);
- };
-
- std::string condition = "(FOLDER_STORAGE_TYPE = 0 OR FOLDER_STORAGE_TYPE = 1)";
- media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT);
picojson::array pico_dirs;
- ret = media_folder_foreach_folder_from_db(filter, media_foreach_directory_cb, &pico_dirs);
+ ret = media_folder_foreach_folder_from_db(nullptr, media_foreach_directory_cb,
+ &pico_dirs);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
PlatformResult err = LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Getting the directories failed.",