[ACR-1643] Add to search ebooks with keywords 89/261589/7 accepted/tizen/unified/20210804.043656 submit/tizen/20210804.011518
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 22 Jul 2021 01:25:03 +0000 (10:25 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 3 Aug 2021 21:59:20 +0000 (06:59 +0900)
Change-Id: Ie097375fefd3fd21b82ca15896a958797eff7661
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
include/media_book.h
include_product/media_book.h
src/media_book.c
test/media-content_test.c

index a80a20b..6e39fde 100755 (executable)
@@ -171,6 +171,35 @@ int book_meta_get_date(book_meta_h book, char **date);
 int book_meta_get_publisher(book_meta_h book, char **publisher);
 
 /**
+ * @brief Gets a list of paths to ebooks which contain a given keyword.
+ * @details This function returns a list of ebook paths including @a keyword.\n
+ *          The search scope is title, table of contents, and body.\n
+ *          If there are no ebooks matching the criteria, @a path_list will be NULL.
+ *
+ * @since_tizen 6.5
+ *
+ * @remarks Each element of @a path_list should be released with free(), then the array itself should be released with free(). \n
+ *          %http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage. \n
+ *          %http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
+ *
+ * @param[in] keyword Keyword to search for
+ * @param[out] path_list A list of paths to books containing @a keyword
+ * @param[out] len Length of @a path_list
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE              Successful
+ * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_CONTENT_ERROR_DB_FAILED         DB Operation failed
+ * @retval #MEDIA_CONTENT_ERROR_DB_BUSY           DB Operation busy
+ *
+ * @see media_info_get_media_from_db_by_path()
+ */
+int book_meta_get_path_with_keyword(const char *keyword, char ***path_list, unsigned int *len);
+
+/**
  *@}
  */
 
index a80a20b..6e39fde 100755 (executable)
@@ -171,6 +171,35 @@ int book_meta_get_date(book_meta_h book, char **date);
 int book_meta_get_publisher(book_meta_h book, char **publisher);
 
 /**
+ * @brief Gets a list of paths to ebooks which contain a given keyword.
+ * @details This function returns a list of ebook paths including @a keyword.\n
+ *          The search scope is title, table of contents, and body.\n
+ *          If there are no ebooks matching the criteria, @a path_list will be NULL.
+ *
+ * @since_tizen 6.5
+ *
+ * @remarks Each element of @a path_list should be released with free(), then the array itself should be released with free(). \n
+ *          %http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage. \n
+ *          %http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
+ *
+ * @param[in] keyword Keyword to search for
+ * @param[out] path_list A list of paths to books containing @a keyword
+ * @param[out] len Length of @a path_list
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE              Successful
+ * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_CONTENT_ERROR_DB_FAILED         DB Operation failed
+ * @retval #MEDIA_CONTENT_ERROR_DB_BUSY           DB Operation busy
+ *
+ * @see media_info_get_media_from_db_by_path()
+ */
+int book_meta_get_path_with_keyword(const char *keyword, char ***path_list, unsigned int *len);
+
+/**
  *@}
  */
 
index 1d15204..1154736 100644 (file)
@@ -112,3 +112,35 @@ int book_meta_get_publisher(book_meta_h book, char **publisher)
 
        return MEDIA_CONTENT_ERROR_NONE;
 }
+
+int book_meta_get_path_with_keyword(const char *keyword, char ***path_list, unsigned int *len)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       GList *book_list = NULL;
+       int i = 0;
+       int result_len = 0;
+
+       content_retip_if_fail(keyword);
+       content_retip_if_fail(path_list);
+       content_retip_if_fail(len);
+
+       ret = media_svc_get_book_by_keyword(_content_get_db_handle(), keyword, &book_list);
+       content_retv_if(ret != MS_MEDIA_ERR_NONE, _content_error_capi(ret));
+
+       result_len = g_list_length(book_list);
+       if (result_len == 0) {
+               content_info("There is no corresponding eBook");
+               return MEDIA_CONTENT_ERROR_NONE;
+       }
+
+       *path_list = g_new0(char *, result_len);
+
+       for (i = 0; i < result_len; i++)
+               (*path_list)[i] = g_strdup((const gchar *)g_list_nth_data(book_list, i));
+
+       g_list_free_full(book_list, g_free);
+
+       *len = result_len;
+
+       return MEDIA_CONTENT_ERROR_NONE;
+}
index a041de2..0470978 100755 (executable)
@@ -2421,6 +2421,54 @@ END:
        return ret;
 }
 
+int test_ebook_text_finder(const char *keyword)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       char **book_path_list = NULL;
+       unsigned int book_path_len = 0;
+       unsigned int i = 0;
+       media_info_h media = NULL;
+       book_meta_h book = NULL;
+       char *s_value = NULL;
+       long long ms_time = 0;
+       struct timeval start_time;
+       struct timeval end_time;
+
+       gettimeofday(&start_time, NULL);
+
+       ret = book_meta_get_path_with_keyword(keyword, &book_path_list, &book_path_len);
+       if (ret == MEDIA_CONTENT_ERROR_NONE)
+               content_debug("book_meta_get_path_with_keyword is success");
+       else
+               content_error("book_meta_get_path_with_keyword is failed");
+
+       gettimeofday(&end_time, NULL);
+
+       for (i = 0; i < book_path_len; i++) {
+               content_debug("=========================== [%d]", i);
+               content_debug("%s", book_path_list[i]);
+               content_debug("===============================");
+               media_info_get_media_from_db_by_path(book_path_list[i], &media);
+               media_info_get_title(media, &s_value);
+               content_debug("Title  : %s", s_value);
+               g_free(s_value);
+               media_info_get_book(media, &book);
+               book_meta_get_author(book, &s_value);
+               content_debug("Author : %s", s_value);
+               g_free(s_value);
+               book_meta_get_date(book, &s_value);
+               content_debug("Date   : %s", s_value);
+               g_free(s_value);
+               book_meta_destroy(book);
+               media_info_destroy(media);
+               content_debug("===============================");
+       }
+
+       ms_time = (end_time.tv_sec * 1000LL + end_time.tv_usec / 1000) - (start_time.tv_sec * 1000LL + start_time.tv_usec/ 1000);
+
+       content_debug("Search Time [%lld]", ms_time);
+       return ret;
+}
 int test_disconnect_database(void)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -2750,7 +2798,7 @@ void _noti_cb(media_content_error_e error,
        if (error == 0)
                content_debug("noti success! : %d\n", error);
        else
-               content_debug("error occured! : %d\n", error);
+               content_debug("error occurred! : %d\n", error);
 
        content_debug("Noti from PID(%d)\n", pid);
 
@@ -2801,7 +2849,7 @@ void _noti_cb_2(media_content_error_e error,
        if (error == 0)
                content_debug("noti_2 success! : %d\n", error);
        else
-               content_debug("error occured! : %d\n", error);
+               content_debug("error occurred! : %d\n", error);
 
        content_debug("Noti_2 from PID(%d)\n", pid);
 
@@ -3357,6 +3405,12 @@ int main(int argc, char *argv[])
 #endif
 
 #if 0
+       if (argc == 2) {
+               ret = test_ebook_text_finder(argv[1]);
+               if (ret != MEDIA_CONTENT_ERROR_NONE)
+                       return ret;
+       }
+
        ret = test_start_face_detection(FALSE);
        if (ret != MEDIA_CONTENT_ERROR_NONE)
                return ret;