A simple custom organizer with the Tizen Native API – part 2

This is the continuation of “A simple custom organizer with the Tizen Native API - part 1” article. If you haven’t yet, please, get familiar with the first part before reading this one. The first article describes how to connect to the calendar service and create an example task. This one – how to get a to-do task and update its properties.

Getting a to-do task & its properties

Let’s assume that you want to mark a to-do task as ”completed” or edit its parameters. The first step is to select it from a genlist:

Next, you can choose one of the following options: “Set as completed” or “Edit”. Let's focus on the second option. When you click on the “Edit” button the _edit_task_cb() function is called:

edit_it = elm_toolbar_item_append(toolbar, NULL, label_edit, _edit_task_cb, view);


static void _edit_task_cb(void *user_data, Evas_Object *obj, void *event_info) {
      main_view_data *view = user_data;
      Elm_Object_Item* item = elm_genlist_selected_item_get(view->genlist);

      if (item != NULL) {
            edit_view_add(view, view->selected_item_db_index);
      } else {
            view->popup = popup_create(view, label_edit_warn);

It gets the selected “to-do task” item from the genlist using the elm_genlist_selected_item_get() function. And if:

  • NO item is selected – NULL is returned,
  • ONE item is selected – this item is returned.

If NULL is returned – a suitable popup is displayed. Otherwise, the “Edit” view is opened (figure 2).



You can select only one item in case of our genlist (single-selection is a default option). To enable multi-selection mode use the following function:

elm_genlist_multi_select_set(view->genlist, true);

If you want to get all selected items (from the above genlist) use the elm_genlist_selected_items_get() function, because the elm_genlist_selected_item_get() function returns only the first selected item.


The “Edit” view allows the user to change parameters of a selected to-do task.


To fill the suitable fields we need data from the calendar. For this purpose we need to:

  1. Connect to the calendar database
  2. Get information about the task
  3. Set the view's fields in a suitable way

What interests us the most now is the second point.

Get information about a to-do task from a calendar database

Firstly, you need to get access to the record in which you are interested:

calendar_record_h get_todo_record(int record_index) {
      calendar_error_e error_code = CALENDAR_ERROR_NONE;
      calendar_record_h record;

      error_code = calendar_db_get_record(_calendar_todo._uri, record_index, &record);

      if (error_code != CALENDAR_ERROR_NONE)
            dlog_print(DLOG_ERROR, LOG_TAG, "calendar_db_get_record: %d\n", error_code);

      return record;

The calendar_db_get_record() function requires the http://tizen.org/privilege/calendar.read privilege. The function gets a record with a given record ID from our calendar database. The first argument of this function is the view URI of a record, the second – index of our to-do task in the calendar database. How to get it?

Every item on a genlist of to-do tasks has the following structure:

typedef struct item_data
       int index;
       char *name;
       Elm_Object_Item *item;
} item_data_s;

While getting the task from the calendar database we also get its database index and we store it in the structure showed above.

calendar_record_get_int(recordOut, _calendar_todo.id, &record_id);


id->index = record_id;

So, when we click any item on the genlist, we get this value:

static void _item_selected_cb(void *user_data, Evas_Object *obj, void *event_info) {
      main_view_data *view = user_data;
      Elm_Object_Item *it = event_info;
      item_data_s *id = elm_object_item_data_get(it);
      view->selected_item_db_index = id->index;

Having an index we can get a record handle and such information about a to-do task as:

  • name
char *get_name_of_task(calendar_record_h record) {
      char *task_name;
      calendar_record_get_str_p(record, _calendar_todo.summary, &task_name);
      return task_name;
  • start date
struct tm get_start_date_of_task(calendar_record_h record) {
    struct tm task_date;
    calendar_time_s start_time = {0};

    calendar_record_get_caltime(record, _calendar_todo.start_time, &start_time);
    struct tm time_start_temp = {0};

    const time_t date = start_time.time.utime;
    time_start_temp = *localtime(&date);
    memcpy(&task_date, &time_start_temp, sizeof(struct tm));

    return task_date;
  • or status
int get_status_of_task(calendar_record_h record) {
      int status;
      calendar_record_get_int(record, _calendar_todo.todo_status, &status);
      return status;


There are five possible to-do task statuses:

typedef enum
    CALENDAR_TODO_STATUS_NONE            = 0x0100,   /**< No status */
    CALENDAR_TODO_STATUS_NEEDS_ACTION    = 0x0200,   /**< Needs action status */
    CALENDAR_TODO_STATUS_COMPLETED       = 0x0400,   /**< Completed status */
    CALENDAR_TODO_STATUS_IN_PROCESS      = 0x0800,   /**< Work in process status */
    CALENDAR_TODO_STATUS_CANCELED        = 0x1000    /**< Canceled status */
} calendar_todo_status_e;

To translate the enum value to the appropriate name of status we use the following function:

const char *get_status_name_of_task(int status) {
      int i;

      for (i = 0; i < status_info_size; i++)
            if(status == status_info[i].type)
                  return status_info[i].name;
      return NULL;

where :

static const status_data status_info[] =
          {"None", CALENDAR_TODO_STATUS_NONE},
          {"Needs action", CALENDAR_TODO_STATUS_NEEDS_ACTION},
          {"Completed", CALENDAR_TODO_STATUS_COMPLETED},
          {"In progress", CALENDAR_TODO_STATUS_IN_PROCESS},
          {"Cancelled", CALENDAR_TODO_STATUS_CANCELED}

And we have all the information we want. The user can modify some to-do task properties.


Updating to-do's properties...

… is very similar to getting them.


We can update a to-do task’s:

  • start date
void set_start_time(calendar_record_h record, struct tm task_start_date){
    calendar_error_e error_code = CALENDAR_ERROR_NONE;
    calendar_time_s start_time;

    memset(&start_time, 0x0, sizeof(start_time));

    calendar_record_get_caltime(record, _calendar_event.start_time, &start_time);

    start_time.type = CALENDAR_TIME_UTIME;
    start_time.time.utime = mktime(&task_start_date);

      // Set new start date
      error_code = calendar_record_set_caltime(record, _calendar_todo.start_time, start_time);

      if (error_code != CALENDAR_ERROR_NONE)
         dlog_print(DLOG_ERROR, LOG_TAG, "set due_time failed : %x\n", error_code);
  • status
void set_todo_status(calendar_record_h record, calendar_todo_status_e todo_status) {
      calendar_error_e error_code = CALENDAR_ERROR_NONE;

      // Set new status
      error_code = calendar_record_set_int(record, _calendar_todo.todo_status, todo_status);

      if (error_code != CALENDAR_ERROR_NONE)
         dlog_print(DLOG_ERROR, LOG_TAG, "calendar_record_set_int failed: %x\n", error_code);


After all these operations on a specified to-do record we need to release the created record handle:

calendar_record_destroy(view->todo_record, true);


This is the end of the second and last part of this article series. More information about Calendar API and its usage can be found in the Documentation:

Tizen Mobile Native App Programming > Tutorials > Social Tutorials > Calendar Tutorial
Tizen Mobile Native App Programming > Programming Guide > Social: Managing Personal Data > Calendar
Tizen Mobile Native App Programming > API Reference > Native API Reference > Social > Calendar

File attachments: 
SDK Version Since: