Fix ug-setting-homescreen-efl build into pure Wayland profile.
[apps/core/preloaded/ug-setting-homescreen-efl.git] / homescreen-setting-main.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <vconf.h>
18 #include <ui-gadget.h>
19
20 #include "homescreen-setting-main.h"
21 #include "homescreen-setting-data.h"
22 #include "homescreen-setting-type.h"
23
24 static Elm_Genlist_Item_Class itc_seperator, itc_type;
25
26 struct ug_data *g_ug_data = NULL;
27
28 enum
29 {
30         MAIN_INDEX_GROUP = 0,
31         MAIN_INDEX_TYPE,
32 };
33
34 enum
35 {
36         MAIN_GROUP_HOMESCREEN = 0,
37 };
38
39 typedef struct _homescreen_setting_main homescreen_setting_main_t;
40 struct _homescreen_setting_main
41 {
42         int index;
43         int group;
44         char *text1;
45         char *text2;
46 };
47
48 static void _homescreen_setting_main_back_cb(void *data, Evas_Object * obj, void *event_info)
49 {
50         HOMESET_DBG("");
51         struct ug_data *ugd = (struct ug_data *) data;
52
53         if (ugd == NULL)
54                 return;
55
56         ug_destroy_me(ugd->ug);
57 }
58
59 static char *_homescreen_setting_main_gl_text_get(void *data, Evas_Object *obj, const char *part)
60 {
61         homescreen_setting_main_t *main_data = (homescreen_setting_main_t *) data;
62
63         if (main_data == NULL)
64         {
65                 HOMESET_ERR("invalid data");
66                 return NULL;
67         }
68
69         if (!strcmp(part, "elm.text.1"))
70         {
71                 if (main_data->index == MAIN_INDEX_TYPE && main_data->text1 != NULL)
72                 {
73                         return strdup(main_data->text1);
74                 }
75         }
76         else if (!strcmp(part, "elm.text.2"))
77         {
78                 if (main_data->index == MAIN_INDEX_TYPE)
79                 {
80                         if (main_data->text2)
81                         {
82                                 free(main_data->text2);
83                         }
84
85                         char *homeapp = homescreen_setting_data_get_selected_homeapp();
86                         if (homeapp)
87                         {
88                                 if (!strcmp(homeapp, HOMESCREEN_SETTING_DEFAULT_PKGNAME))
89                                 {
90                                         main_data->text2 = strdup(HOMESET_TEXT("IDS_ST_BODY_DEFAULT_HOME_SCREEN"));
91                                 }
92                                 else
93                                 {
94                                         main_data->text2 = homescreen_setting_data_get_name(homeapp);
95                                 }
96
97                                 free(homeapp);
98                         }
99                         else
100                         {
101                                 main_data->text2 = strdup(HOMESET_TEXT("IDS_ST_BODY_DEFAULT_HOME_SCREEN"));
102                         }
103
104                         return strdup(main_data->text2);
105                 }
106         }
107
108         return NULL;
109 }
110
111 static void _homescreen_setting_main_gl_del(void *data, Evas_Object *obj)
112 {
113         HOMESET_DBG("");
114         homescreen_setting_main_t *main_data = (homescreen_setting_main_t *) data;
115
116         if (main_data == NULL)
117         {
118                 HOMESET_ERR("invalid data");
119                 return;
120         }
121
122         /* Release data */
123         if (main_data->text1 != NULL)
124         {
125                 free(main_data->text1);
126         }
127
128         if (main_data->text2 != NULL)
129         {
130                 free(main_data->text2);
131         }
132
133         free(main_data);
134 }
135
136 static void _homescreen_setting_main_gl_sel(void *data, Evas_Object *obj, void *event_info)
137 {
138         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
139         if (item == NULL)
140         {
141                 HOMESET_ERR("invalid item data");
142                 return;
143         }
144
145         elm_genlist_item_selected_set(item, EINA_FALSE);
146
147         homescreen_setting_main_t *main_data = (homescreen_setting_main_t *) elm_object_item_data_get(item);
148         if (main_data == NULL)
149         {
150                 HOMESET_ERR("invalid main data");
151                 return;
152         }
153
154         struct ug_data *ugd = (struct ug_data *) data;
155         if (ugd == NULL)
156         {
157                 HOMESET_ERR("invalid ug data");
158                 return;
159         }
160
161         if (main_data->index == MAIN_INDEX_TYPE)
162         {
163                 /* change home screen type view */
164                 homescreen_setting_type_create_view(ugd);
165         }
166 }
167
168 static Evas_Object* _homescreen_setting_main_add_genlist(struct ug_data *ugd)
169 {
170         Evas_Object *genlist;
171         Elm_Object_Item *it;
172
173         genlist = elm_genlist_add(ugd->naviframe);
174         elm_object_style_set(genlist, "dialogue");
175
176         /* dialogue for seperator */
177         itc_seperator.item_style = "dialogue/separator";
178         itc_seperator.func.text_get = NULL;
179         itc_seperator.func.content_get = NULL;
180         itc_seperator.func.state_get = NULL;
181         itc_seperator.func.del = NULL;
182
183         it = elm_genlist_item_append(genlist, &itc_seperator, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
184         elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
185
186         /* dialogue for type */
187         itc_type.item_style = "dialogue/2text.3";
188         itc_type.func.text_get = _homescreen_setting_main_gl_text_get;
189         itc_type.func.content_get = NULL;
190         itc_type.func.state_get = NULL;
191         itc_type.func.del = _homescreen_setting_main_gl_del;
192
193         homescreen_setting_main_t *main_data = (homescreen_setting_main_t *) malloc(sizeof(homescreen_setting_main_t));
194         if (main_data != NULL)
195         {
196                 main_data->index = MAIN_INDEX_TYPE;
197                 main_data->group = MAIN_GROUP_HOMESCREEN;
198                 main_data->text1 = strdup(HOMESET_TEXT("IDS_ST_BODY_HOME_SCREEN_TYPE"));
199                 main_data->text2 = strdup(HOMESET_TEXT("IDS_ST_BODY_DEFAULT_HOME_SCREEN"));
200
201                 elm_genlist_item_append(genlist, &itc_type, (void *) main_data, NULL, ELM_GENLIST_ITEM_NONE, _homescreen_setting_main_gl_sel, ugd);
202         }
203
204         return genlist;
205 }
206
207 void homescreen_setting_main_create_view(void *data)
208 {
209         HOMESET_DBG("create main view");
210         struct ug_data *ugd = (struct ug_data *) data;
211         if (!ugd)
212         {
213                 HOMESET_ERR("invalid ugd");
214                 return;
215         }
216
217         g_ug_data = ugd;
218
219         /* Create genlist */
220         Evas_Object *genlist = _homescreen_setting_main_add_genlist(ugd);
221         g_ug_data->genlist_main = genlist;
222
223         /* Back button */
224         Evas_Object *button = elm_button_add(ugd->naviframe);
225         elm_object_style_set(button, "naviframe/end_btn/default");
226         evas_object_smart_callback_add(button, "clicked", _homescreen_setting_main_back_cb, ugd);
227
228         /* Push to naviframe */
229         elm_naviframe_item_push(ugd->naviframe, HOMESET_TEXT("IDS_ST_HEADER_HOME_SCREEN"), button, NULL, genlist, NULL);
230 }