[ACR-1635] Support ebook format
[platform/core/api/media-content.git] / src / media_info.c
index 6d8ba72..4441e69 100644 (file)
@@ -110,7 +110,7 @@ static void __media_info_thumbnail_completed_cb(int error, const char *path, voi
        return;
 }
 
-static bool __media_info_isFaceRecognition_feature_supported()
+static bool __media_info_isFaceRecognition_feature_supported(void)
 {
        bool isFaceRecognitionSupported = false;
 
@@ -343,7 +343,13 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
                _media->audio_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
                _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE);
                _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL);
+       } else if (_media->media_type == MEDIA_CONTENT_TYPE_BOOK) {
+               _media->book_meta = g_new0(book_meta_s, 1);
 
+               _media->book_meta->subject = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
+               _media->book_meta->author = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
+               _media->book_meta->date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
+               _media->book_meta->publisher = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
        }
 }
 #ifdef _USE_TVPD_MODE
@@ -406,7 +412,6 @@ int _media_info_get_media_info_from_db(const char *path, media_info_h media)
 int media_info_insert_to_db(const char *path, media_info_h *info)
 {
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
-       char repl_path[MAX_PATH_LEN] = {0, };
        int ret = MEDIA_CONTENT_ERROR_NONE;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
        int modified_time = 0;
@@ -414,52 +419,49 @@ int media_info_insert_to_db(const char *path, media_info_h *info)
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(info);
 
-       ret = _media_content_replace_path(path, repl_path);
-       content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
-
-       ret = __media_info_check_file_validity(repl_path);
+       ret = __media_info_check_file_validity(path);
        content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
 
-       ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+       ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE) {
                content_error("media_svc_get_storage_id failed : %d", ret);
                return _content_error_capi(ret);
        }
 
-       ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
+       ret = ms_user_get_storage_type(_content_get_uid(), path, &storage_type);
        if (ret != MS_MEDIA_ERR_NONE) {
                content_sec_error("ms_user_get_storage_type failed : %d", ret);
                return _content_error_capi(ret);
        }
 
        /* Get modified time for check exists */
-       ret = media_svc_get_modified_time(_content_get_db_handle(), storage_id, repl_path, &modified_time);
+       ret = media_svc_get_modified_time(_content_get_db_handle(), storage_id, path, &modified_time);
        if (ret == MS_MEDIA_ERR_NONE) {
                /* Refresh if need */
-               if (modified_time != _media_util_get_file_time(repl_path)) {
-                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
+               if (modified_time != _media_util_get_file_time(path)) {
+                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                content_error("media_svc_refresh_item failed : %d", ret);
                                return _content_error_capi(ret);
                        }
                }
        } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
-               content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", repl_path);
-               content_retvm_if(!_media_util_check_support_media_type(repl_path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
+               content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path);
+               content_retvm_if(!_media_util_check_support_media_type(path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
 
-               ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
+               ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, _content_get_uid());
                if (ret != MS_MEDIA_ERR_NONE) {
                        if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
-                               content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path);
+                               content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
                                ret = MEDIA_CONTENT_ERROR_NONE;
                        } else {
-                               content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
+                               content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
                        }
 
                        return _content_error_capi(ret);
                }
        } else {
-               content_sec_error("media_svc_get_modified_time failed : %d (%s)", ret, repl_path);
+               content_sec_error("media_svc_get_modified_time failed : %d (%s)", ret, path);
                return _content_error_capi(ret);
        }
 
@@ -467,13 +469,13 @@ int media_info_insert_to_db(const char *path, media_info_h *info)
 
 #ifdef _USE_TVPD_MODE
        if (STRING_VALID(storage_id))
-               ret = _media_info_get_media_info_from_db(repl_path, storage_id, (media_info_h)_media);
+               ret = _media_info_get_media_info_from_db(path, storage_id, (media_info_h)_media);
        else
-               ret = _media_info_get_media_info_from_db(repl_path, DB_TABLE_MEDIA, (media_info_h)_media);
+               ret = _media_info_get_media_info_from_db(path, DB_TABLE_MEDIA, (media_info_h)_media);
 
        *info = (media_info_h)_media;
 #else
-       ret = _media_info_get_media_info_from_db(repl_path, (media_info_h)_media);
+       ret = _media_info_get_media_info_from_db(path, (media_info_h)_media);
 
        *info = (media_info_h)_media;
 #endif
@@ -482,35 +484,13 @@ int media_info_insert_to_db(const char *path, media_info_h *info)
 
 int media_info_insert_batch_to_db(const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data)
 {
-       char **repl_path_array = NULL;
-       int idx = 0;
-       int ret = MS_MEDIA_ERR_NONE;
-       char repl_path[MAX_PATH_LEN] = {0, };
-
        content_retip_if_fail(path_array);
        content_retip_if_fail(array_length > 0);
        content_retip_if_fail(completed_cb);
 
-       repl_path_array = g_malloc0(sizeof(char *) * array_length);
-
-       for (idx = 0; idx < array_length; idx++) {
-               if (STRING_VALID(path_array[idx])) {
-                       memset(repl_path, 0, sizeof(repl_path));
-                       _media_content_replace_path(path_array[idx], repl_path);
-                       repl_path_array[idx] = g_strndup(repl_path, strlen(repl_path));
-               } else {
-                       content_error("path[%d] is invalid string", idx);
-               }
-       }
-
-       ret = __media_info_insert_batch((const char **)repl_path_array, array_length, completed_cb, user_data);
-       for (idx = 0; idx < array_length; idx++)
-               g_free(repl_path_array[idx]);
-
-       g_free(repl_path_array);
-
-       return ret;
+       return __media_info_insert_batch(path_array, array_length, completed_cb, user_data);
 }
+
 #ifdef _USE_TVPD_MODE
 int media_info_get_media_info_by_path_from_db(const char* path, media_info_h* media)
 {
@@ -622,6 +602,16 @@ int media_info_destroy(media_info_h media)
                g_free(_media->audio_meta);
        }
 
+       if (_media->book_meta) {
+               g_free(_media->book_meta->media_id);
+               g_free(_media->book_meta->author);
+               g_free(_media->book_meta->date);
+               g_free(_media->book_meta->publisher);
+               g_free(_media->book_meta->subject);
+
+               g_free(_media->book_meta);
+       }
+
        g_free(_media);
 
        return MEDIA_CONTENT_ERROR_NONE;
@@ -720,6 +710,14 @@ int media_info_clone(media_info_h *dst, media_info_h src)
                _dst->audio_meta->duration = _src->audio_meta->duration;
                _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
                _dst->audio_meta->bitpersample = _src->audio_meta->bitpersample;
+       } else if (_src->media_type == MEDIA_CONTENT_TYPE_BOOK && _src->book_meta) {
+               _dst->book_meta = g_new0(book_meta_s, 1);
+
+               _dst->book_meta->media_id = g_strdup(_src->book_meta->media_id);
+               _dst->book_meta->author = g_strdup(_src->book_meta->author);
+               _dst->book_meta->date = g_strdup(_src->book_meta->date);
+               _dst->book_meta->publisher = g_strdup(_src->book_meta->publisher);
+               _dst->book_meta->subject = g_strdup(_src->book_meta->subject);
        }
 
        *dst = (media_info_h)_dst;
@@ -887,6 +885,29 @@ int media_info_get_audio(media_info_h media, audio_meta_h *audio)
        return ret;
 }
 
+int media_info_get_book(media_info_h media, book_meta_h *book)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+
+       media_info_s *_media = (media_info_s*)media;
+
+       content_retip_if_fail(media);
+       content_retip_if_fail(_media->media_type == MEDIA_CONTENT_TYPE_BOOK);
+       content_retip_if_fail(book);
+
+       book_meta_s *_book = g_new0(book_meta_s, 1);
+
+       _book->media_id = g_strdup(_media->media_id);
+       _book->author = g_strdup(_media->book_meta->author);
+       _book->publisher = g_strdup(_media->book_meta->publisher);
+       _book->date = g_strdup(_media->book_meta->date);
+       _book->subject = g_strdup(_media->book_meta->subject);
+
+       *book = (book_meta_h)_book;
+
+       return ret;
+}
+
 int media_info_get_media_id(media_info_h media, char **media_id)
 {
        media_info_s *_media = (media_info_s*)media;
@@ -1303,6 +1324,43 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media)
        return ret;
 }
 
+int media_info_get_media_from_db_by_path(const char *path, media_info_h *media)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       media_info_s *_media = NULL;
+
+       content_retip_if_fail(STRING_VALID(path));
+       content_retip_if_fail(media);
+       ret = _media_util_check_file_exist(path);
+       content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_util_check_file_exist failed : %d", ret);
+
+#ifdef _USE_TVPD_MODE
+       char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, };
+
+       ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
+       if (ret != MS_MEDIA_ERR_NONE) {
+               content_error("media_svc_get_storage_id failed : %d", ret);
+               return _content_error_capi(ret);
+       }
+#endif
+
+       _media = g_new0(media_info_s, 1);
+
+#ifdef _USE_TVPD_MODE
+       ret = _media_info_get_media_info_from_db(path, STRING_VALID(storage_id) ? storage_id : DB_TABLE_MEDIA, (media_info_h)_media);
+#else
+       ret = _media_info_get_media_info_from_db(path, (media_info_h)_media);
+#endif
+       if (ret != MEDIA_CONTENT_ERROR_NONE) {
+               g_free(_media);
+               _media = NULL;
+       }
+
+       *media = (media_info_h)_media;
+
+       return ret;
+}
+
 int media_info_set_favorite(media_info_h media, bool favorite)
 {
        media_info_s *_media = (media_info_s*)media;
@@ -1365,7 +1423,7 @@ int media_info_update_to_db(media_info_h media)
 
        if (ret == MEDIA_CONTENT_ERROR_NONE) {
                /* Send notification for this update */
-               content_debug("Update is successfull. Send notification for this");
+               content_debug("Update is successful. Send notification for this");
                if (_media->file_path && _media->mime_type)
                        media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type);
                else
@@ -1380,16 +1438,18 @@ int media_info_move_to_db(media_info_h media, const char* dst_path)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char repl_path[MAX_PATH_LEN] = {0, };
        media_info_s *_info = NULL;
+#ifdef _USE_TVPD_MODE
+       char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, };
+#endif
 
        content_retip_if_fail(media);
        content_retip_if_fail(STRING_VALID(dst_path));
 
-       ret = _media_content_replace_path(dst_path, repl_path);
-       content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
-
        media_info_s *_media = (media_info_s*)media;
 
        /* If dst_path is folder, append file_name */
+       SAFE_STRLCPY(repl_path, dst_path, sizeof(repl_path));
+
        if (g_file_test(repl_path, G_FILE_TEST_IS_DIR)) {
                if (repl_path[strlen(repl_path) - 1] != '/')
                        SAFE_STRLCAT(repl_path, "/", sizeof(repl_path));
@@ -1410,7 +1470,14 @@ int media_info_move_to_db(media_info_h media, const char* dst_path)
        /* Update media_info handle */
        _info = g_new0(media_info_s, 1);
 
+#ifdef _USE_TVPD_MODE
+       ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+       content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+       ret = _media_info_get_media_info_from_db(repl_path, storage_id, (media_info_h)_info);
+#else
        ret = _media_info_get_media_info_from_db(repl_path, (media_info_h)_info);
+#endif
 
        SAFE_FREE(_media->display_name);
        _media->display_name = g_strdup(_info->display_name);