Adds design element candidate list handle 10/176210/2
authorhyunho <hhstark.kang@samsung.com>
Mon, 16 Apr 2018 02:34:42 +0000 (11:34 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 17 Apr 2018 10:35:01 +0000 (19:35 +0900)
Change-Id: Ie493c177c8871500e142e55c823d641c9acd42f9
Signed-off-by: hyunho <hhstark.kang@samsung.com>
watchface-complication/include/watchface-editable.h
watchface-complication/watchface-editable.cc

index f012f4b..512a025 100644 (file)
@@ -76,10 +76,173 @@ typedef void (*watchface_editable_editable_update_cb)(
 typedef void (*watchface_editable_edit_ready_cb)(watchface_editable_container_h handle,
                        const char *editor_appid, void *user_data);
 
+/**
+ * @brief The candidates list handle.
+ * @since_tizen 5.0
+ */
+typedef struct complication_candidates_list_ *complication_candidates_list_h;
+
+/**
+ * @brief Creates candidates list.
+ * @details The candidates list created by this function will be shown on the
+ *          editor app's candidates list.
+ * @since_tizen 5.0
+ * @remarks Created candidates list should be destroyed after used.
+ * @param[in] handle The candidates list handle
+ * @return #COMPLICATION_ERROR_NONE on success,
+ *         otherwise an error code (see COMPLICATION_ERROR_XXX) on failure
+ * @retval #COMPLICATION_ERROR_NONE Successful
+ * @retval #COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see watchface_editable_candidates_list_add()
+ * @see watchface_editable_candidates_list_destroy()
+ * @see watchface_editable_add_design_element()
+ * @par Sample code:
+ * @code
+#include <watchface-complication.h>
+{
+       complication_candidates_list_h handle;
+       int ret = watchface_editable_candidates_list_create(&handle);
+}
+ * @endcode
+ */
+int watchface_editable_candidates_list_create(
+                       complication_candidates_list_h *handle);
+
+/**
+ * @brief Adds candidate data to the candidates list.
+ * @since_tizen 5.0
+ * @remarks Created candidate data will be freed when
+ *          watchface_editable_candidates_list_destroy() API is called.
+ * @param[in] handle The candidates list handle
+ * @param[in] candidate The candidate data
+ * @return #COMPLICATION_ERROR_NONE on success,
+ *         otherwise an error code (see COMPLICATION_ERROR_XXX) on failure
+ * @retval #COMPLICATION_ERROR_NONE Successful
+ * @retval #COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see watchface_editable_candidates_list_create()
+ * @see watchface_editable_candidates_list_destroy()
+ * @see watchface_editable_add_design_element()
+ * @par Sample code:
+ * @code
+#include <watchface-complication.h>
+_onwatchface_editable_edit_ready_cb(editable_container_h handle,
+               const char *editor_appid, void *user_data)
+{
+       complication_candidates_list_h list_handle;
+       int ret = watchface_editable_candidates_list_create(&list_handle);
+       bundle *candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "RED");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "YELLOW");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       watchface_editable_add_design_element(handle, COLOR_EDIT, cur_idx,
+               complication_candidates_list_h, geo, "Color");
+       watchface_editable_candidates_list_destroy(list_handle);
+}
+ * @endcode
+ */
+int watchface_editable_candidates_list_add(
+        complication_candidates_list_h handle, bundle *candidate);
+
+/**
+ * @brief Destroys candidates list.
+ * @since_tizen 5.0
+ * @param[in] handle The complication allowed list handle
+ * @return #COMPLICATION_ERROR_NONE on success,
+ *         otherwise an error code (see COMPLICATION_ERROR_XXX) on failure
+ * @retval #COMPLICATION_ERROR_NONE Successful
+ * @retval #COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory
+ * @see watchface_editable_candidates_list_add()
+ * @see watchface_editable_candidates_list_create()
+ * @see watchface_editable_add_design_element()
+ * @par Sample code:
+ * @code
+#include <watchface-complication.h>
+_watchface_editable_edit_ready_cb(editable_container_h handle,
+               const char *editor_appid, void *user_data)
+{
+       complication_candidates_list_h list_handle;
+       int ret = watchface_editable_candidates_list_create(&list_handle);
+       bundle *candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "RED");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "YELLOW");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       watchface_editable_add_design_element(handle, COLOR_EDIT, cur_idx,
+               complication_candidates_list_h, geo, "Color");
+       watchface_editable_candidates_list_destroy(list_handle);
+}
+ * @endcode
+ */
+int watchface_editable_candidates_list_destroy(
+                       complication_candidates_list_h handle);
+
+/**
+ * @brief Adds the design element to the editable container handle.
+ * @details The design element will be displayed on the editor app's
+ *          editables list
+ * @since_tizen 5.0
+ * @param[in] handle The editable container
+ * @param[in] editable_id Editable id
+ * @param[in] cur_data_idx The index of the currently set data
+ * @param[in] list_handle List of candidate data
+ * @param[in] geo Position of editable
+ * @param[in] editable_name Name of editable
+ * @return #WATCHFACE_COMPLICATION_ERROR_NONE if success, other value if failure
+ * @retval #WATCHFACE_COMPLICATION_ERROR_NONE Success
+ * @retval #WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see watchface_editable_edit_ready_cb()
+ * @see watchface_editable_candidates_list_add()
+ * @see watchface_editable_candidates_list_create()
+ * @see watchface_editable_request_edit()
+ * @par Sample code:
+ * @code
+#include <watchface-editable.h>
+_watchface_editable_edit_ready_cb(watchface_editable_container_h handle,
+               const char *editor_appid, void *user_data)
+{
+       GList *candidatelist = NULL;
+       watchface_editable_geo_s geo;
+       int cur_idx = 0;
+       bundle *selected_data = NULL;
+
+       complication_candidates_list_h list_handle;
+       int ret = watchface_editable_candidates_list_create(&list_handle);
+       bundle *candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "RED");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       candidate = bundle_create();
+       bundle_add_str(candidate, "TEST_COLOR", "YELLOW");
+       watchface_editable_candidates_list_add(list_handle, candidate);
+
+       watchface_editable_load_current_data(COLOR_EDIT, &selected_data);
+       if (selected_data) {
+               bundle_get_str(selected_data, "TEST_COLOR", &cur_color);
+               if (strcmp(cur_color, "YELLOW") == 0)
+                       cur_idx = 1;
+       }
+       watchface_editable_add_design_element(handle, COLOR_EDIT, cur_idx,
+       list_handle, geo, "Color");
+       watchface_editable_candidates_list_destroy(list_handle);
+
+       watchface_editable_request_edit(handle, editor_appid, _on_editable_update, user_data);
+}
+ * @endcode
+ */
 int watchface_editable_add_design_element(watchface_editable_container_h handle,
                        int editable_id, int cur_data_idx,
-                       GList *candidates_list, watchface_editable_geo_s geo,
-                       const char *editable_name);
+                       complication_candidates_list_h list_handle,
+                       watchface_editable_geo_s geo, const char *editable_name);
 int watchface_editable_get_editable_name(const watchface_editable_h handle,
                        const char **editable_name);
 int watchface_editable_set_editable_name(const watchface_editable_h handle,
index f424a2c..50a06f6 100644 (file)
@@ -39,6 +39,10 @@ using watchface_complication::DesignElement;
 using watchface_complication::SharedHandle;
 using watchface_complication::EditablesManager;
 
+struct complication_candidates_list_ {
+  GList* candidates_list;
+};
+
 class ReadyCallbackInfo {
  public:
   ReadyCallbackInfo(watchface_editable_edit_ready_cb cb, void* user_data)
@@ -131,15 +135,17 @@ class EditablesContainerStub : public EditablesContainer {
 static EditablesContainerStub *__container;
 extern "C" EXPORT_API int watchface_editable_add_design_element(
     watchface_editable_container_h handle, int edit_id, int cur_data_idx,
-    GList* candidate_list, watchface_editable_geo_s geo, const char* editable_name) {
-  if (handle == NULL || candidate_list == NULL || editable_name == NULL)
+    complication_candidates_list_h list_handle, watchface_editable_geo_s geo,
+    const char* editable_name) {
+  if (handle == NULL || list_handle == NULL || editable_name == NULL ||
+    list_handle->candidates_list == NULL)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
   EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
   bundle* data;
   int str_len = 0;
   bundle_raw* str_raw = NULL;
-  GList* iter = candidate_list;
+  GList* iter = list_handle->candidates_list;
   std::list<std::unique_ptr<Bundle>> new_list;
 
   for (; iter; iter = iter->next) {
@@ -334,3 +340,59 @@ extern "C" EXPORT_API int watchface_editable_load_current_data(
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
+
+extern "C" EXPORT_API int watchface_editable_candidates_list_create(
+    complication_candidates_list_h* handle) {
+
+  complication_candidates_list_h h = NULL;
+
+  if (handle == NULL) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  h = (complication_candidates_list_h)calloc(1,
+      sizeof(struct complication_candidates_list_));
+
+  if (h == NULL) {
+    LOGE("Out of memory");
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  }
+
+  *handle = h;
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_editable_candidates_list_add(
+    complication_candidates_list_h handle, bundle* candidate) {
+
+  if (handle == NULL || candidate == NULL) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  handle->candidates_list = g_list_append(handle->candidates_list, candidate);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+static void __free_candidate(gpointer data)
+{
+  bundle* candidate = (bundle*)data;
+  bundle_free(candidate);
+}
+
+extern "C" EXPORT_API int watchface_editable_candidates_list_destroy(
+    complication_candidates_list_h handle) {
+  if (handle == NULL) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  if (handle->candidates_list)
+    g_list_free_full(handle->candidates_list, __free_candidate);
+  free(handle);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}