summaryrefslogtreecommitdiff
path: root/mobile/lock-setting/lockscreen-options/src/lockscreen-options-main.c
blob: 2ede565b676c809930fb5af9e591936d1e527739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.1 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */



#include <vconf.h>
#include <vconf-keys.h>
#include <ui-gadget.h>
#include <ui-gadget-module.h>
#include <ail.h>

#include "lockscreen-options.h"
#include "lockscreen-options-debug.h"
#include "lockscreen-options-main.h"
#include "lockscreen-options-util.h"

#include "starter-vconf.h"

#define LOCKSCREEN_OPTOINS_GENLIST_ITEM_CNT 5

typedef struct {
	int glStyle;
	int stringId;
	Evas_Object *check;
	void (*func) (void *data, Evas_Object * obj, void *event_info);
} lockscreen_menu_item_info;

static lockscreen_menu_item_info lockscreen_options_menu_item[] = {
	{ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON, IDS_LOCKSCREEN_OPTIONS_EVENT_NOTIFICATIONS, NULL, NULL},
	{ENUM_LOCKSCREEN_GENLIST_STYLE_HELP, IDS_LOCKSCREEN_OPTIONS_EVENT_NOTIFICATIONS_HELP, NULL, NULL},
	{ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON, IDS_LOCKSCREEN_OPTIONS_CLOCK, NULL, NULL},
	{ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON, IDS_LOCKSCREEN_OPTIONS_HELPTEXT, NULL, NULL},
	{ENUM_LOCKSCREEN_GENLIST_STYLE_HELP, IDS_LOCKSCREEN_OPTIONS_HELPTEXT_HELP, NULL, NULL}
};

static Elm_Gen_Item_Class itc_menu_1text1icon;
static Elm_Gen_Item_Class itc_menu_2text1icon;
static Elm_Gen_Item_Class itc_help_1text;

static void _lockscreen_options_main_back_cb(void *data, Evas_Object * obj,
					     void *event_info)
{
	lockscreen_options_ug_data *ug_data =
	    (lockscreen_options_ug_data *) data;

	if (ug_data == NULL)
		return;

	ug_destroy_me(ug_data->ug);
}

static char *_lockscreen_options_main_gl_label_get(void *data,
						   Evas_Object * obj,
						   const char *part)
{
	if (data == NULL || part == NULL)
		return NULL;

	lockscreen_menu_item_info *lockoption_data =
	    (lockscreen_menu_item_info *) data;

	if ((strcmp(part, "elm.text") == 0) ||
	    (strcmp(part, "elm.text.1") == 0)) {
		return
		    strdup(lockscreen_optoins_get_string
			   (lockoption_data->stringId));
	}

	return NULL;

}

static void _lockscreen_options_set_menu_status(int stringId, int value)
{
	int ret = 0;
	switch (stringId) {
	case IDS_LOCKSCREEN_OPTIONS_EVENT_NOTIFICATIONS:
		ret = vconf_set_bool(VCONFKEY_LOCKSCREEN_EVENT_NOTIFICATION_DISPLAY, value);
		break;
	case IDS_LOCKSCREEN_OPTIONS_CLOCK:
		ret = vconf_set_bool(VCONFKEY_LOCKSCREEN_CLOCK_DISPLAY, value);
		break;
	case IDS_LOCKSCREEN_OPTIONS_HELPTEXT:
		ret = vconf_set_bool(VCONFKEY_LOCKSCREEN_HELP_TEXT_DISPLAY, value);
		break;
	default:
		LOCKOPTIONS_DBG("NO VALID STRINGID %d", stringId);
		break;
	}
}

static bool _lockscreen_options_get_menu_status(int stringId)
{
	int status = 0;
	int ret = 0;

	switch (stringId) {
	case IDS_LOCKSCREEN_OPTIONS_EVENT_NOTIFICATIONS:
		ret = vconf_get_bool(VCONFKEY_LOCKSCREEN_EVENT_NOTIFICATION_DISPLAY, &status);
		break;
	case IDS_LOCKSCREEN_OPTIONS_CLOCK:
		ret = vconf_get_bool(VCONFKEY_LOCKSCREEN_CLOCK_DISPLAY, &status);
		break;
	case IDS_LOCKSCREEN_OPTIONS_HELPTEXT:
		ret = vconf_get_bool(VCONFKEY_LOCKSCREEN_HELP_TEXT_DISPLAY, &status);
		break;
	default:
		LOCKOPTIONS_DBG("NO VALID INDEX %d", stringId);
		break;
	}

	if (ret == -1) {
		LOCKOPTIONS_ERR("Failed to get vconfkey %d!", stringId);
		return 0;
	}

	LOCKOPTIONS_DBG
	    ("_lockscreen_options_get_menu_status index %d Status %d", stringId,
	     status);

	return status;
}

static void _lockscreen_options_check_changed_cb(void *data, Evas_Object * obj,
						 void *event_info)
{
	if (data == NULL || obj == NULL)
		return;

	lockscreen_menu_item_info *lockoption_data =
	    (lockscreen_menu_item_info *) data;

	Eina_Bool ret;
	int value = 0;

	ret = elm_check_state_get(obj);

	LOCKOPTIONS_DBG("_lockscreen_options_check_changed_cb : %s",
			ret == EINA_TRUE ? "ON" : "OFF");

	if (ret == EINA_TRUE) {
		value = 1;
	} else {
		value = 0;
	}

	_lockscreen_options_set_menu_status(lockoption_data->stringId, value);
}

static Evas_Object *_lockscreen_options_main_gl_icon_get(void *data,
							 Evas_Object * obj,
							 const char *part)
{
	if (data == NULL || obj == NULL)
		return NULL;

	lockscreen_menu_item_info *lockoption_data =
	    (lockscreen_menu_item_info *) data;

	LOCKOPTIONS_DBG("icon get stringId : %d", lockoption_data->stringId);

	Evas_Object *check;
	int value = 0;

	check = elm_check_add(obj);
	elm_object_style_set(check, "on&off");
	evas_object_show(check);

	value = _lockscreen_options_get_menu_status(lockoption_data->stringId);
	elm_check_state_set(check, value);

	evas_object_pass_events_set(check, 1);
	evas_object_propagate_events_set(check, 0);

	evas_object_smart_callback_add(check, "changed",
				       _lockscreen_options_check_changed_cb,
				       lockoption_data);

	lockoption_data->check = check;

	return check;
}

static void _lockscreen_options_main_gl_del(void *data, Evas_Object * obj)
{
	LOCKOPTIONS_DBG("_lockscreen_options_main_gl_del");
}

static void _lockscreen_options_main_gl_sel(void *data, Evas_Object * obj,
					    void *event_info)
{
	if (data == NULL)
		return;

	lockscreen_menu_item_info *lockoption_data = NULL;

	elm_genlist_item_selected_set((Elm_Object_Item *) event_info,
				      EINA_FALSE);

	Elm_Object_Item *item = (Elm_Object_Item *) event_info;
	lockoption_data =
	    (lockscreen_menu_item_info *) elm_object_item_data_get(item);
	if (lockoption_data == NULL) {
		return;
	}

	if (lockoption_data->stringId ==
	    IDS_LOCKSCREEN_OPTIONS_EVENT_NOTIFICATIONS
	    || lockoption_data->stringId == IDS_LOCKSCREEN_OPTIONS_CLOCK
	    || lockoption_data->stringId == IDS_LOCKSCREEN_OPTIONS_HELPTEXT) {
		Eina_Bool check_state =
		    elm_check_state_get(lockoption_data->check);
		_lockscreen_options_set_menu_status(lockoption_data->stringId,
						    !check_state);
		elm_genlist_item_update(item);
	}

	if (lockoption_data->func != NULL) {
		lockoption_data->func(data, obj, event_info);
	}
}

static void _lockscreen_options_create_gl_item(Elm_Gen_Item_Class * item,
					       int glStyle)
{
	if (glStyle == ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON) {
		item->item_style = LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON;
		item->func.text_get = _lockscreen_options_main_gl_label_get;
		item->func.content_get = _lockscreen_options_main_gl_icon_get;
		item->func.state_get = NULL;
		item->func.del = _lockscreen_options_main_gl_del;
	} else if (glStyle == ENUM_LOCKSCREEN_GENLIST_STYLE_2TEXT1ICON) {
		item->item_style = LOCKSCREEN_GENLIST_STYLE_2TEXT1ICON;
		item->func.text_get = _lockscreen_options_main_gl_label_get;
		item->func.content_get = _lockscreen_options_main_gl_icon_get;
		item->func.state_get = NULL;
		item->func.del = NULL;
	} else if (glStyle == ENUM_LOCKSCREEN_GENLIST_STYLE_HELP) {
		item->item_style = LOCKSCREEN_GENLIST_STYLE_HELP;
		item->func.text_get = _lockscreen_options_main_gl_label_get;
		item->func.content_get = NULL;
		item->func.state_get = NULL;
		item->func.del = _lockscreen_options_main_gl_del;
	} else {
		LOCKOPTIONS_DBG("_lockscreen_options_create_gl_item FAIL\n");
	}
}

void lockscreen_options_main_create_view(lockscreen_options_ug_data * ug_data)
{
	LOCKOPTIONS_DBG("lockscreen_options_main_create_view begin\n");

	Evas_Object *navi_bar = ug_data->navi_bar;
	Evas_Object *back_button = NULL;
	Evas_Object *genlist = NULL;
	Elm_Object_Item *item = NULL;
	int i = 0;

	if (navi_bar == NULL) {
		LOCKOPTIONS_WARN("navi_bar is null.");
		return;
	}

	_lockscreen_options_create_gl_item(&(itc_menu_1text1icon),
					   ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON);
	_lockscreen_options_create_gl_item(&(itc_menu_2text1icon),
					   ENUM_LOCKSCREEN_GENLIST_STYLE_2TEXT1ICON);
	_lockscreen_options_create_gl_item(&(itc_help_1text),
					   ENUM_LOCKSCREEN_GENLIST_STYLE_HELP);

	genlist = elm_genlist_add(navi_bar);

	elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
	elm_object_style_set(genlist, "dialogue");

	lockscreen_options_util_create_seperator(genlist);

	for (i = 0; i < LOCKSCREEN_OPTOINS_GENLIST_ITEM_CNT; i++) {
		Elm_Gen_Item_Class *itc = NULL;
		if (lockscreen_options_menu_item[i].glStyle ==
		    ENUM_LOCKSCREEN_GENLIST_STYLE_1TEXT1ICON) {
			itc = &(itc_menu_1text1icon);
			elm_genlist_item_append(genlist,
						       itc,
						       &
						       (lockscreen_options_menu_item
							[i]), NULL,
						       ELM_GENLIST_ITEM_NONE,
						       _lockscreen_options_main_gl_sel,
						       ug_data);
		} else if(lockscreen_options_menu_item[i].glStyle ==
		    ENUM_LOCKSCREEN_GENLIST_STYLE_2TEXT1ICON) {
		    itc = &(itc_menu_2text1icon);
			elm_genlist_item_append(genlist,
						       itc,
						       &
						       (lockscreen_options_menu_item
							[i]), NULL,
						       ELM_GENLIST_ITEM_NONE,
						       _lockscreen_options_main_gl_sel,
						       ug_data);
		} else if (lockscreen_options_menu_item[i].glStyle ==
			   ENUM_LOCKSCREEN_GENLIST_STYLE_HELP) {
			itc = &(itc_help_1text);
			item = elm_genlist_item_append(genlist,
						       itc,
						       &
						       (lockscreen_options_menu_item
							[i]), NULL,
						       ELM_GENLIST_ITEM_NONE,
						       NULL, NULL);
			elm_genlist_item_select_mode_set(item,
							 ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
			if(i != (LOCKSCREEN_OPTOINS_GENLIST_ITEM_CNT - 1)){
				lockscreen_options_util_create_underline(genlist);
			}
		} else {
			LOCKOPTIONS_WARN("lockscreen option has no such type.");
			return;
		}
	}

	back_button = elm_button_add(navi_bar);
	elm_object_style_set(back_button, "naviframe/back_btn/default");
	evas_object_smart_callback_add(back_button, "clicked",
				       _lockscreen_options_main_back_cb,
				       ug_data);

	elm_naviframe_item_push(navi_bar, _("IDS_ST_BODY_LOCK_SCREEN") , back_button, NULL, genlist, NULL);
}