From: Jakub Siewierski Date: Tue, 11 Aug 2015 15:02:28 +0000 (+0200) Subject: [Tutorial][Media Content] Tags: Add adding/deleting tags X-Git-Tag: tizen_3.0/TD_SYNC/20161201~610^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69d6475e9ea533659c107872f7b468f0475e69a9;p=sdk%2Fonline-doc.git [Tutorial][Media Content] Tags: Add adding/deleting tags Change-Id: I5f7f73a0e5fe401215d9c171a503e5e33beddb31 Signed-off-by: Jakub Siewierski --- diff --git a/org.tizen.tutorials/html/native/content/media_content_tutorial_n.htm b/org.tizen.tutorials/html/native/content/media_content_tutorial_n.htm index 1aef36a..f6ecce1 100644 --- a/org.tizen.tutorials/html/native/content/media_content_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/content/media_content_tutorial_n.htm @@ -81,7 +81,9 @@
  • Tag
  • Storage @@ -209,8 +211,12 @@
  • Storage @@ -1691,7 +1697,7 @@ media_content_disconnect();
  • #include <media_content.h> -

    Before retrieving tag information, open a connection to the Content Service by calling the media_content_connect() function:

    +

    Before using tag-related functions, open a connection to the Content Service by calling the media_content_connect() function:

    media_content_connect();
    @@ -1699,6 +1705,50 @@ media_content_disconnect();
    media_content_disconnect();
    +

    Adding Tags

    +

    To add a tag to the database, and add a file to the tag:

    +
      +
    1. Add the tag. +

      Use media_tag_insert_to_db() to add the tag. The result is a handle to the new tag.

      +
      +media_tag_h tag = NULL;
      +const char *tag_name = "Tag name";
      +
      +media_tag_insert_to_db(tag_name, &tag);
      +
      +
    2. + +
    3. Insert a media item into the tag. +

      +To insert an item into the tag, you need to know the id of the item. +One of the ways of obtaining the id is to insert a media item into the database. +In the example below, a media file is inserted and then added to the tag.

      +
      +media_info_h image_info = NULL;
      +char *image_id = NULL;
      +
      +media_info_insert_to_db("path/to/image_file", &image_info);
      +
      +media_info_get_media_id(image_info, &image_id);
      +
      +media_tag_add_media(tag, image_id);
      +
      +
    4. + +
    5. Update the tag. +

      After you make any changes to the tag, like change its name or add items, you need to update it.

      +
      +media_tag_update_to_db(tag);
      +
      +
    6. + +
    7. Destroy the tag handle.
    8. +

      After the tag has been inserted into the database and all updates to it have been made, you can destroy the handle. Note that this is not related to deleting the tag from the database.

      +
      +media_tag_destroy(tag);
      +
      +
    +

    Getting the Tag List

    @@ -1792,7 +1842,6 @@ else             dlog_print(DLOG_DEBUG, LOG_TAG, "[%s] media_name [%d] : %s", tag_name, j, media_name);             dlog_print(DLOG_DEBUG, LOG_TAG, "[%s] media_path [%d] : %s", tag_name, j, media_path); -            free(media_id);             free(media_name);             free(media_path);             media_info_destroy(tag_media_handle); @@ -1801,12 +1850,82 @@ else       free(tag_name);       media_tag_destroy(tag_handle);       g_list_free(media_list_in_tag); +      media_list_in_tag = NULL;    }    g_list_free(tag_list); } +

    Deleting Tags

    +

    Deleting a tag requires its id. In the example below, the id is obtained by calling media_tag_foreach_tag_from_db().

    +
      +
    1. Define the callback. +

      Define the callback called for each found tag. The callback will add the handle of each tag to the tag list.

      +
      +bool gallery_tag_item_cb(media_tag_h tag, void *user_data)
      +{
      +   media_tag_h new_tag = NULL;
      +
      +   int ret = media_tag_clone(&new_tag, tag);
      +   GList **list = (GList**)user_data;
      +   *list = g_list_append(*list, new_tag);
      +
      +   return true; // Continue with the next iteration
      +}
      +
      +
    2. +
    3. Find tags. +

      Call media_tag_foreach_tag_from_db() to find tags in the database. The first parameter is a filter; if NULL, all tags are found. The second parameter is the callback, called for each found tag. The third parameter is data passed to the callback in each iteration. In this example it is a list of tag handles.

      +
      +GList *tag_list = NULL;
      +
      +media_tag_foreach_tag_from_db(NULL, gallery_tag_item_cb, &tag_list);
      +
      + +
    4. Iterate through the tag list. +

      After the list is completed, access each element:

      + +
      +media_tag_h tag_handle = NULL;
      +int tag_id;
      +char *tag_name = NULL;
      +
      +int len = g_list_length(tag_list);
      +
      +int i;
      +for (i = 0; i < len; i++)
      +{
      +   tag_handle = (media_tag_h) g_list_nth_data(tag_list, i);
      +
      +
    5. +
    6. Delete the tag. +

      Provided that you have the tag handle, get the tag id with media_tag_get_tag_id() and delete the tag with media_tag_delete_from_db().

      +
      +   ret = media_tag_get_tag_id(tag_handle, &tag_id);
      +
      +   ret = media_tag_delete_from_db(tag_id);
      +
      +
    7. + +
    8. Destroy the tag handle. +

      Now that the handle is no longer needed, it can be destroyed:

      +
      +   ret = media_tag_destroy(tag_handle);
      +}
      +
      +
    9. +
    10. Free the tag list. +

      After all elements have been accessed, free the tag handle list:

      +
      +g_list_free(tag_list);
      +tag_list = NULL;
      +
      +
    11. + +
    + +

    Initializing the Storage

    To initialize the storage for use:

    @@ -1957,7 +2076,6 @@ bool media_cb(media_info_h media, void *user_data) } -

    Finding Media Item Groups Using a Filter

    To find groups containing only items matching the given criteria: