<p>To create the genlist:</p>
<ol><li>
-<p>The genlist is created using the <span style="font-family: Courier New,Courier,monospace">elm_genlist_add()</span> function. For the genlist to be displayed properly, genlist item classes have to be created and defined with the <span style="font-family: Courier New,Courier,monospace">elm_genlist_item_class_new()</span> function. The following code snippet demonstrates how to set the item class properties. A <span style="font-family: Courier New,Courier,monospace">text_get</span> and a <span style="font-family: Courier New,Courier,monospace">content_get</span> callback function are defined to create item text and layout creation.</p>
+<p>The genlist is created using the <span style="font-family: Courier New,Courier,monospace">elm_genlist_add()</span> function. For the genlist to be displayed properly, a genlist item class has to be created and defined with the <span style="font-family: Courier New,Courier,monospace">elm_genlist_item_class_new()</span> function. The following code snippet demonstrates how to set the item class properties. A <span style="font-family: Courier New,Courier,monospace">text_get</span> and a <span style="font-family: Courier New,Courier,monospace">content_get</span> callback function are defined to create item text and layout creation.</p>
<pre class="prettyprint">
Evas_Object *genlist;
-Elm_Genlist_Item_Class *itc_name, *itc_description;
+Elm_Genlist_Item_Class *itc;
int index;
/* Create item class */
-itc_name = elm_genlist_item_class_new();
-itc_name->item_style = "default";
-itc_name->func.text_get = gl_text_name_get_cb;
-itc_name->func.content_get = gl_content_get_cb;
-
-itc_description = elm_genlist_item_class_new();
-itc_description->item_style = "multiline";
-itc_description->func.text_get = gl_text_description_get_cb;
+itc = elm_genlist_item_class_new();
+itc->item_style = "multiline";
+itc->func.text_get = gl_text_get_cb;
+itc->func.content_get = gl_content_get_cb;
/* Genlist */
-genlist = elm_genlist_add(ad->nf);
-Evas_Object *genlist = elm_genlist_add(viewdata.win);
-
-// Error handling
-
-viewdata.item_class = elm_genlist_item_class_new();
-
-// Error handling
-
-viewdata.item_class->item_style = "full";
-viewdata.item_class->func.text_get = NULL;
-viewdata.item_class->func.content_get = __get_item_content;
-viewdata.item_class->func.state_get = NULL;
-viewdata.item_class->func.del = NULL;
+genlist = elm_genlist_add(ad->nf);
+elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
</pre></li>
<li>
-<p>The genlist is filled with rule items and its descriptions. To append items to the genlist, the <span style="font-family: Courier New,Courier,monospace">elm_genlist_item_append()</span> function is invoked for each <span style="font-family: Courier New,Courier,monospace">Eina_List</span> item.</p>
+<p>The genlist is filled with rule items. To append items to the genlist, the <span style="font-family: Courier New,Courier,monospace">elm_genlist_item_append()</span> function is invoked for each <span style="font-family: Courier New,Courier,monospace">Eina_List</span> item.</p>
<pre class="prettyprint">
// For each rule
for (index = RULE_FIRST; index < RULE_LAST; index++) {
- /* Rule name item */
- if (ruleinfo_arr[index].result == CONTEXT_TRIGGER_ERROR_NONE) {
- elm_genlist_item_append(genlist, itc_name, (void *) &ruleinfo_arr[index], NULL, ELM_GENLIST_ITEM_NONE, gl_selected_cb, NULL);
- } else {
- elm_genlist_item_append(genlist, itc_name, (void *) &ruleinfo_arr[index], NULL, ELM_GENLIST_ITEM_NONE, gl_disabled_selected_cb, ad);
- }
-
- /* Rule description item */
- Elm_Object_Item *item = elm_genlist_item_append(genlist, itc_description, (void *) &ruleinfo_arr[index], NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
- elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+ /* Rule item */
+ elm_genlist_item_append(genlist, itc, (void *)&ruleinfo_arr[index], NULL, ELM_GENLIST_ITEM_NONE, gl_selected_cb, ad);
}
</pre></li>
<li>
-<p>The application's <span style="font-family: Courier New,Courier,monospace">rule_info</span> structure containing its rule information such as name, description, and so on. It is later passed on to the previously defined callback function. The following example shows the <span style="font-family: Courier New,Courier,monospace">gl_text_name_get_cb</span>, the <span style="font-family: Courier New,Courier,monospace">gl_text_description_get_cb</span>, the <span style="font-family: Courier New,Courier,monospace">gl_content_get_cb</span> callback function. Rule information is retrieved from the parameter and used to create the item layout.</p>
+<p>The application's <span style="font-family: Courier New,Courier,monospace">rule_info</span> structure containing its rule information such as name, description, and so on. It is later passed on to the previously defined callback function. The following example shows the <span style="font-family: Courier New,Courier,monospace">gl_text_get_cb</span>, and the <span style="font-family: Courier New,Courier,monospace">gl_content_get_cb</span> callback function. Rule information is retrieved from the parameter and used to create the item layout.</p>
<pre class="prettyprint">
-static char *gl_text_name_get_cb(void *data, Evas_Object * obj, const char *part)
+static char *gl_text_get_cb(void *data, Evas_Object * obj, const char *part)
{
rule_info_s *info = (rule_info_s *) data;
if (!strcmp(part, "elm.text"))
return strdup(info->name);
-
- return NULL;
-}
-
-static char *gl_text_description_get_cb(void *data, Evas_Object * obj, const char *part)
-{
- rule_info_s *info = (rule_info_s *) data;
-
- if (!strcmp(part, "elm.text.multiline"))
+ else if (!strcmp(part, "elm.text.multiline"))
return strdup(info->description);
return NULL;
</pre></li>
</ol>
-<p>When a genlist item or a check button is clicked, corresponding rule will be enabled or disabled.</p>
+<p>When a genlist item or a check button is clicked, corresponding rule will be enabled or disabled. If the user taps an rule item which fails to be added for some reasons, an error popup will be shown to indicate the reasons.</p>
<pre class="prettyprint">
-static void gl_selected_cb(void *data EINA_UNUSED, Evas_Object * obj EINA_UNUSED, void *event_info)
+static void gl_selected_cb(void *data, Evas_Object * obj EINA_UNUSED, void *event_info)
{
Elm_Object_Item *it = (Elm_Object_Item *) event_info;
- int error = CONTEXT_TRIGGER_ERROR_NONE;
-
- rule_info_s *info = elm_object_item_data_get(it);
elm_genlist_item_selected_set(it, false);
- Evas_Object *check = elm_object_item_part_content_get(it, "elm.swallow.end");
+ rule_info_s *info = elm_object_item_data_get(it);
- if (elm_check_state_get(check)) {
- error = disable_rule(info->id);
- if (error == CONTEXT_TRIGGER_ERROR_NONE)
- elm_check_state_set(check, !info->enabled);
+ if (info->result == CONTEXT_TRIGGER_ERROR_NONE) {
+ int error = CONTEXT_TRIGGER_ERROR_NONE;
+ Evas_Object *check = elm_object_item_part_content_get(it, "elm.swallow.end");
+
+ if (elm_check_state_get(check)) {
+ error = disable_rule(info->id);
+ if (error == CONTEXT_TRIGGER_ERROR_NONE)
+ elm_check_state_set(check, !info->enabled);
+ } else {
+ error = enable_rule(info->id);
+ if (error == CONTEXT_TRIGGER_ERROR_NONE)
+ elm_check_state_set(check, !info->enabled);
+ }
} else {
- error = enable_rule(info->id);
- if (error == CONTEXT_TRIGGER_ERROR_NONE)
- elm_check_state_set(check, !info->enabled);
+ create_error_popup(data, info);
}
}
elm_check_state_set(obj, !info->enabled);
}
}
+
+static void create_error_popup(appdata_s * ad, void *data)
+{
+ rule_info_s *info = (rule_info_s *) data;
+
+ char *err_msg = NULL;
+
+ switch (info->result) {
+ case CONTEXT_TRIGGER_ERROR_PERMISSION_DENIED:
+ err_msg = ERR_MSG_PERMISSION_DENIED;
+ break;
+ case CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED:
+ err_msg = ERR_MSG_NOT_SUPPORTED;
+ break;
+ case CONTEXT_TRIGGER_ERROR_INVALID_RULE:
+ err_msg = ERR_MSG_INVALID_RULE;
+ break;
+ default:
+ err_msg = ERR_MSG_DEFAULT;
+ break;
+ }
+
+ Evas_Object *popup = elm_popup_add(ad->win);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ elm_object_part_text_set(popup, "title,text", info->name);
+
+ elm_object_text_set(popup, err_msg);
+
+ Evas_Object *btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", popup_btn_clicked_cb, popup);
+ evas_object_show(popup);
+}
</pre>
<script type="text/javascript" src="../scripts/jquery.zclip.min.js"></script>