2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file im-get-policy.c
18 * @author Janusz Kozerski (j.kozerski@samsung.com)
23 #include "im-uigadget.h"
24 #include "im-common.h"
25 #include "im-get-policy.h"
27 /************************ Genlist Item Class ************************/
28 static void _gl_del(void *data, Evas_Object *obj)
30 // Cleaning formated policy string
36 static char * _item_label_get(void *data, Evas_Object *obj, const char *part)
43 // Needed because of GCC "missing initializer" error
44 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
45 static Elm_Genlist_Item_Class _itc_policy_content = {
46 .item_style = "multiline/1text",
47 .func.text_get = _item_label_get,
48 .func.content_get = NULL,
49 .func.state_get = NULL,
52 #pragma GCC diagnostic pop // Restoring GCC command line parameters
53 /********************************************************************/
55 // This function will format policy to EFL usable string ("<br>" as a new line
56 // sign). You have to free() the memory that's allocated by this function.
57 static char* _convert_policy (const char *const *const policy)
59 LOGD("Enter function: %s", __func__);
60 char *new_policy = NULL;
62 const char* const new_line_sign = "<br>";
63 size_t nls_size = strlen(new_line_sign);
67 // Counting size for policy rules
68 while (policy[i] != NULL) {
69 size += strlen(policy[i]);
72 // Size of new line signs after every policy rule except the last one.
73 size += nls_size * (i - 1);
75 // NULL sign at the end
78 new_policy = malloc(size * sizeof(char));
84 while (policy[i] != NULL) {
85 LOGD("Policy rule no. %d: %s", i, policy[i]);
86 strcpy(tmp, policy[i]);
87 tmp += strlen(policy[i]);
88 if (policy[i+1] != NULL) { //Appending new_line_sign only if it's not the last rule
89 strcpy(tmp, new_line_sign);
94 new_policy[size] = '\0';
96 LOGD("Formated Policy: %s", new_policy);
100 void im_get_policy_cb(void *data, Evas_Object *obj, void *event_info)
102 LOGD("Enter function: %s", __func__);
106 struct ug_data *ad = (struct ug_data*) data;
108 Evas_Object *genlist = NULL;
109 Elm_Object_Item *nf_it = NULL;
110 char **policy = NULL;
111 char *formated_policy = NULL;
113 // TODO: Call function from libIMA to get currently loaded policy
114 // int res = ima_get_ima_policy(&policy);
115 // Check error code: if (res) {return;}
116 // Temporary allocation - will be removed when function from libIMA will be used
117 policy = calloc(4, sizeof(char*));
118 policy[0] = strdup("MEASURE something");
119 policy[1] = strdup("MEASUER something else");
120 policy[2] = strdup("DONT_MEASURE file");
123 formated_policy = _convert_policy((const char *const *const) policy);
125 while (policy[i] != NULL) {
133 if (!formated_policy)
136 genlist = elm_genlist_add(ad->navi_bar);
140 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
141 evas_object_smart_callback_add(genlist, "selected", genlist_clicked_cb, NULL);
143 nf_it = elm_genlist_item_append(
144 genlist, // Genlist object
145 &_itc_policy_content, // Item class
146 formated_policy, // Item data
148 ELM_GENLIST_ITEM_NONE, // Item type
149 genlist_clicked_cb, // select callback
150 NULL); // callback data
151 elm_genlist_item_select_mode_set(nf_it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
153 nf_it = elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "IDS_ST_CURRENT_POLICY"), NULL, NULL, genlist, NULL);
154 elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);
156 elm_naviframe_prev_btn_auto_pushed_set(ad->navi_bar, EINA_FALSE);
157 elm_naviframe_item_pop_cb_set(nf_it, NULL, NULL);
159 ea_object_event_callback_add(ad->navi_bar, EA_CALLBACK_BACK, ea_naviframe_back_cb, NULL);
160 ea_object_event_callback_add(ad->navi_bar, EA_CALLBACK_MORE, ea_naviframe_more_cb, NULL);