Tizen 2.0 Release
[apps/home/wrt-setting.git] / webapp-common / listview.cpp
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.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
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 <Elementary.h>
18 #include <ui-gadget.h>
19 #include <ui-gadget-module.h>
20
21 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
22 #include <dpl/wrt-dao-rw/global_dao.h>
23 #include <dpl/assert.h>
24
25 #include "listview.h"
26 #include "icons.h"
27
28
29 #define LOG_TAG "WRT-SETTING"
30 #include <dlog.h>
31
32 namespace WebAppCommonSetting {
33 const char * const COOKIE_SHARING = "IDS_ST_BODY_COOKIE_SHARING";
34 const char * const SHARE_COOKIES_BETWEEN_WEB_APPS =
35     "IDS_ST_BODY_SHARE_COOKIES_BETWEEN_WEB_APPS";
36 const char * const MOFILE_INSTALL_DIR =
37     "/usr/ug/res/locale";
38
39 char *ListView::getWacTitle(void */*data*/,
40                             Evas_Object */*obj*/,
41                             const char */*part*/)
42 {
43     return strdup("WAC");
44 }
45
46 char *ListView::getWhiteListTitle(void */*data*/,
47                                   Evas_Object */*obj*/,
48                                   const char */*part*/)
49 {
50     return strdup("White list");
51 }
52
53 char *ListView::getText(void *data,
54                         Evas_Object */*obj*/,
55                         const char *part)
56 {
57     OnOffData *onOffData;
58     const char *str;
59
60     onOffData = static_cast<OnOffData *>(data);
61     Assert(onOffData);
62
63     if (!strcmp(part, "elm.text"))
64         str = onOffData->m_title.c_str();
65     else if (!strcmp(part, "elm.text.1"))
66         str = onOffData->m_title.c_str();
67     else {
68         return NULL;
69     }
70     return strdup(str);
71 }
72
73 Evas_Object *ListView::getOnOffIcon(void *data,
74                                     Evas_Object *obj,
75                                     const char */*part*/)
76 {
77     OnOffData *onOffData;
78     Evas_Object *chk;
79     bool val;
80
81     onOffData = static_cast<OnOffData *>(data);
82     Assert(onOffData);
83
84     chk = elm_check_add(obj);
85     if (!chk)
86         return NULL;
87     evas_object_propagate_events_set(chk, EINA_TRUE);
88     elm_object_style_set(chk, "on&off");
89     val = onOffData->m_getOnOffVal();
90     elm_check_state_set(chk, static_cast<Eina_Bool>(val));
91     onOffData->m_chk = chk;
92     evas_object_smart_callback_add(chk,
93                                    "changed",
94                                    onOffData->m_changedCb,
95                                    data);
96
97     return chk;
98 }
99
100 void ListView::delOnOffData(void *data, Evas_Object */*obj*/)
101 {
102     OnOffData *onOffData;
103
104     onOffData = static_cast<OnOffData *>(data);
105     delete onOffData;
106 }
107
108 char *ListView::getRoamingLabel(void *data,
109                                 Evas_Object */*obj*/,
110                                 const char *part)
111 {
112     const char *str;
113     RoamingData *roamingData;
114
115     roamingData = static_cast<RoamingData *>(data);
116     Assert(roamingData);
117
118     if (!strcmp(part, "elm.text.1")) {
119         str = "Data roaming";
120     } else if (!strcmp(part, "elm.text.2")) {
121         switch (WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage()) {
122         case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
123             str = "Never connect";
124             break;
125         case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
126             str = "Always ask";
127             break;
128         case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
129             str = "Connect automatically";
130             break;
131         default:
132             str = NULL;
133             break;
134         }
135     } else {
136         str = NULL;
137     }
138
139     if (!str)
140         return NULL;
141
142     return strdup(str);
143 }
144
145 void ListView::delRoamingData(void *data, Evas_Object */*obj*/)
146 {
147     RoamingData *roamingData;
148
149     roamingData = static_cast<RoamingData *>(data);
150     delete roamingData;
151 }
152
153 char *ListView::getRoamingOptLabel(void *data,
154                                    Evas_Object */*obj*/,
155                                    const char */*part*/)
156 {
157     const char *str;
158     RoamingExpandData *roamingExpandData;
159
160     roamingExpandData = static_cast<RoamingExpandData *>(data);
161     Assert(roamingExpandData);
162
163     switch (roamingExpandData->m_mode) {
164     case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
165         str = "Never connect";
166         break;
167     case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
168         str = "Always ask";
169         break;
170     case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
171         str = "Connect automatically";
172         break;
173     default:
174         str = NULL;
175         break;
176     }
177
178     if (!str)
179         return NULL;
180
181     return strdup(str);
182 }
183
184 Evas_Object *ListView::getRoamingOptRadio(void *data,
185                                           Evas_Object *obj,
186                                           const char */*part*/)
187 {
188     Evas_Object *radio;
189     RoamingExpandData *roamingExpandData;
190     int mode;
191
192     roamingExpandData = static_cast<RoamingExpandData *>(data);
193     Assert(roamingExpandData);
194     mode = WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage();
195     radio = elm_radio_add(obj);
196     if (!radio)
197         return NULL;
198     elm_radio_state_value_set(radio, roamingExpandData->m_mode);
199     elm_radio_group_add(radio, roamingExpandData->m_rg);
200     if (mode == roamingExpandData->m_mode)
201         elm_radio_value_set(radio, mode);
202
203     return radio;
204 }
205
206 void ListView::delRoamingExpandData(void *data, Evas_Object */*obj*/)
207 {
208     RoamingExpandData *roamingExpandData;
209
210     roamingExpandData = static_cast<RoamingExpandData *>(data);
211     delete roamingExpandData;
212 }
213
214 char *ListView::getComplianceModeTitle(void */*data*/,
215                                        Evas_Object */*obj*/,
216                                        const char *part)
217 {
218     const char *str;
219
220     if (!strcmp(part, "elm.text.1"))
221         str = "Compliance mode";
222     else if (!strcmp(part, "elm.text.2"))
223         str = "Enable compliance mode";
224     else
225         str = NULL;
226
227     if (!str)
228         return NULL;
229
230     return strdup(str);
231 }
232
233 Evas_Object *ListView::getComplianceModeIcon(void *data,
234                                     Evas_Object *obj,
235                                     const char */*part*/)
236 {
237     Evas_Object *chk;
238     ComplianceModeData *compModeData;
239     bool val;
240
241     compModeData = static_cast<ComplianceModeData *>(data);
242     Assert(compModeData);
243
244     chk = elm_check_add(obj);
245     if (!chk)
246         return NULL;
247     evas_object_propagate_events_set(chk, EINA_FALSE);
248     elm_object_style_set(chk, "on&off");
249     val = WrtDB::GlobalDAOReadOnly::getComplianceMode();
250     elm_check_state_set(chk, static_cast<Eina_Bool>(val));
251     compModeData->m_chk = chk;
252     evas_object_smart_callback_add(chk,
253                                    "changed",
254                                    onComplianceModeChanged,
255                                    data);
256
257     return chk;
258 }
259
260 void ListView::delComlianceModeData(void *data, Evas_Object */*obj*/)
261 {
262     ComplianceModeData *compModeData;
263
264     compModeData = static_cast<ComplianceModeData *>(data);
265     delete compModeData;
266 }
267
268 Evas_Object *ListView::getComplianceModeOptEntry(void *data,
269                                                  Evas_Object *obj,
270                                                  const char */*part*/)
271 {
272     int opt;
273     Evas_Object *ef;
274     Evas_Object *entry;
275     std::string val;
276
277     opt = reinterpret_cast<int>(data);
278
279     ef = elm_layout_add(obj);
280     if (!ef)
281         return NULL;
282     elm_layout_theme_set(ef, "layout", "editfield", "title");
283
284     entry = elm_entry_add(ef);
285     if (!entry) {
286         evas_object_del(ef);
287         return NULL;
288     }
289     evas_object_data_set(entry, "editfield", static_cast<void *>(ef));
290     elm_entry_single_line_set(entry, EINA_TRUE);
291     elm_object_part_content_set(ef, "elm.swallow.content", entry);
292
293     switch (opt) {
294     case COMPLIANCE_OPT_IMEI:
295         elm_object_part_text_set(ef, "elm.text", "IMEI");
296         elm_object_part_text_set(ef, "elm.guidetext", "Put fake IMEI");
297         val = WrtDB::GlobalDAOReadOnly::getComplianceFakeImei();
298         break;
299     case COMPLIANCE_OPT_MEID:
300         elm_object_part_text_set(ef, "elm.text", "MEID");
301         elm_object_part_text_set(ef, "elm.guidetext", "Put fake MEID");
302         val = WrtDB::GlobalDAOReadOnly::getComplianceFakeMeid();
303         break;
304     default:
305         evas_object_del(ef);
306         return NULL;
307     }
308
309     if (!val.empty()) {
310         elm_entry_entry_set(entry, val.c_str());
311         elm_object_signal_emit(ef, "elm,state,guidetext,hide", "elm");
312     }
313
314     elm_object_signal_callback_add(ef,
315                                    "elm,eraser,clicked",
316                                    "elm",
317                                    onComplianceModeOptErase,
318                                    static_cast<void *>(entry));
319     evas_object_smart_callback_add(entry,
320                                    "focused",
321                                    onComplianceModeOptFocused,
322                                    static_cast<void *>(ef));
323     evas_object_smart_callback_add(entry,
324                                    "unfocused",
325                                    onComplianceModeOptUnfocused,
326                                    static_cast<void *>(ef));
327     /* FIXME: The callback is invoked unexpectedly. Why? DO report to EFL team */
328     evas_object_smart_callback_add(entry,
329                                    "changed",
330                                    onComplianceModeOptChanged,
331                                    data);
332
333     return ef;
334 }
335
336 void ListView::onBackBtnClicked(void *data,
337                                 Evas_Object */*obj*/,
338                                 void */*event_info*/)
339 {
340     ListView *listView;
341
342     listView = static_cast<ListView *>(data);
343     Assert(listView);
344     listView->invokeUnloadCb();
345 }
346
347 void ListView::onOnOffItemClicked(void *data,
348                                   Evas_Object */*obj*/,
349                                   void *event_info)
350 {
351     Elm_Object_Item *it;
352     OnOffData *onOffData;
353
354     it = static_cast<Elm_Object_Item *>(event_info);
355     Assert(it);
356     elm_genlist_item_selected_set(it, EINA_FALSE);
357     onOffData = static_cast<OnOffData *>(data);
358     evas_object_smart_callback_call(onOffData->m_chk, "changed", NULL);
359 }
360
361 void ListView::onCookieSharingPopupOk(void *data,
362                                       Evas_Object */*obj*/,
363                                       void */*event_info*/)
364 {
365     OnOffData *onOffData;
366     ListView *listView;
367
368     onOffData = static_cast<OnOffData *>(data);
369     listView = onOffData->m_listView;
370     Assert(onOffData && listView);
371
372     WrtDB::GlobalDAO::SetCookieSharingMode(TRUE);
373
374     elm_check_state_set(onOffData->m_chk, EINA_TRUE);
375     listView->hidePopup();
376 }
377
378 void ListView::onCookieSharingPopupCancel(void *data,
379                                           Evas_Object */*obj*/,
380                                           void */*event_info*/)
381 {
382     OnOffData *onOffData;
383     ListView *listView;
384
385     onOffData = static_cast<OnOffData *>(data);
386     listView = onOffData->m_listView;
387     Assert(onOffData && listView);
388
389     WrtDB::GlobalDAO::SetCookieSharingMode(FALSE);
390     elm_check_state_set(onOffData->m_chk, EINA_FALSE);
391     listView->hidePopup();
392 }
393
394 void ListView::onCookieSharingChanged(void *data,
395                                       Evas_Object */*obj*/,
396                                       void */*event_info*/)
397 {
398     OnOffData *onOffData;
399     ListView *listView;
400     bool state;
401
402     onOffData = static_cast<OnOffData *>(data);
403     listView = onOffData->m_listView;
404     Assert(onOffData && onOffData->m_chk && listView);
405
406     state = elm_check_state_get(onOffData->m_chk);
407
408     if (!state) {
409         WrtDB::GlobalDAO::SetCookieSharingMode(TRUE);
410         elm_check_state_set(onOffData->m_chk, EINA_TRUE);
411     } else {
412         WrtDB::GlobalDAO::SetCookieSharingMode(FALSE);
413         elm_check_state_set(onOffData->m_chk, FALSE);
414     }
415 }
416
417 void ListView::onUntrustedAppApprovalPopupOk(void *data,
418                                              Evas_Object */*obj*/,
419                                              void */*event_info*/)
420 {
421     OnOffData *onOffData;
422     ListView *listView;
423
424     onOffData = static_cast<OnOffData *>(data);
425     listView = onOffData->m_listView;
426     Assert(onOffData && listView);
427
428     WrtDB::GlobalDAO::SetSecureByDefault(true);
429     elm_check_state_set(onOffData->m_chk, EINA_TRUE);
430     listView->hidePopup();
431 }
432
433 void ListView::onUntrustedAppApprovalPopupCancel(void *data,
434                                                  Evas_Object */*obj*/,
435                                                  void */*event_info*/)
436 {
437     OnOffData *onOffData;
438     ListView *listView;
439
440     onOffData = static_cast<OnOffData *>(data);
441     listView = onOffData->m_listView;
442     Assert(onOffData && listView);
443
444     elm_check_state_set(onOffData->m_chk, EINA_FALSE);
445     listView->hidePopup();
446 }
447
448 void ListView::onUntrustedAppApprovalChanged(void *data,
449                                              Evas_Object */*obj*/,
450                                              void */*event_info*/)
451 {
452     OnOffData *onOffData;
453     ListView *listView;
454     bool state;
455
456     onOffData = static_cast<OnOffData *>(data);
457     listView = onOffData->m_listView;
458     Assert(onOffData && onOffData->m_chk && listView);
459
460     state = WrtDB::GlobalDAOReadOnly::GetSecureByDefault();
461     if (!state) {
462         if (!listView->showPopup("Do you really want to allow "
463                                  "untrusted applications?",
464                                  onUntrustedAppApprovalPopupOk,
465                                  onUntrustedAppApprovalPopupCancel,
466                                  static_cast<void *>(onOffData)))
467             return;
468     } else {
469         WrtDB::GlobalDAO::SetSecureByDefault(false);
470     }
471     elm_check_state_set(onOffData->m_chk, !state);
472 }
473
474 void ListView::onRoamingClicked(void *data,
475                                 Evas_Object *obj,
476                                 void *event_info)
477 {
478     Elm_Object_Item *it;
479     Eina_Bool expanded;
480     RoamingData *roamingData;
481     ListView *listView;
482
483     it = static_cast<Elm_Object_Item *>(event_info);
484     roamingData = static_cast<RoamingData *>(data);
485     listView = roamingData->m_listView;
486     Assert(it && roamingData && listView);
487     elm_genlist_item_selected_set(it, EINA_FALSE);
488     expanded = elm_genlist_item_expanded_get(it);
489     elm_genlist_item_expanded_set(it, !expanded);
490     if (expanded)
491         elm_genlist_item_subitems_clear(it);
492     else
493         listView->addRoamingOpts(obj, it);
494 }
495
496 void ListView::onRoamingOptClicked(void *data,
497                                    Evas_Object *obj,
498                                    void *event_info)
499 {
500     RoamingExpandData *roamingExpandData;
501     Elm_Object_Item *it;
502
503     it = static_cast<Elm_Object_Item *>(event_info);
504     Assert(it);
505     elm_genlist_item_selected_set(it, EINA_FALSE);
506
507     roamingExpandData = static_cast<RoamingExpandData *>(data);
508     Assert(roamingExpandData);
509     WrtDB::GlobalDAO::SetRoamingDataUsage(roamingExpandData->m_mode);
510     elm_genlist_realized_items_update(obj);
511 }
512
513 void ListView::onWhiteListClicked(void *data,
514                                   Evas_Object */*obj*/,
515                                   void *event_info)
516 {
517     Elm_Object_Item *it;
518     ListView *listView;
519
520     it = static_cast<Elm_Object_Item *>(event_info);
521     Assert(it);
522     elm_genlist_item_selected_set(it, EINA_FALSE);
523
524     listView = static_cast<ListView *>(data);
525     Assert(listView);
526     listView->loadWhiteListView();
527
528 }
529
530 void ListView::onDevModeChanged(void *data,
531                                 Evas_Object */*obj*/,
532                                 void */*event_info*/)
533 {
534     OnOffData *onOffData;
535     ListView *listView;
536     Eina_Bool state;
537
538     onOffData = static_cast<OnOffData *>(data);
539     listView = onOffData->m_listView;
540     Assert(onOffData && onOffData->m_chk && listView);
541
542     state = WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
543     WrtDB::GlobalDAO::SetDeveloperMode(!state);
544     elm_check_state_set(onOffData->m_chk, !state);
545 }
546
547 void ListView::onComplianceModeClicked(void *data,
548                                        Evas_Object */*obj*/,
549                                        void *event_info)
550 {
551     Elm_Object_Item *it;
552     ComplianceModeData *compModeData;
553
554     it = static_cast<Elm_Object_Item *>(event_info);
555     Assert(it);
556     elm_genlist_item_selected_set(it, EINA_FALSE);
557     compModeData = static_cast<ComplianceModeData *>(data);
558     evas_object_smart_callback_call(compModeData->m_chk, "changed", NULL);
559 }
560
561 void ListView::onComplianceModeChanged(void *data,
562                                        Evas_Object */*obj*/,
563                                        void */*event_info*/)
564 {
565     ComplianceModeData *compModeData;
566     ListView *listView;
567     Eina_Bool state;
568
569     compModeData = static_cast<ComplianceModeData *>(data);
570     listView = compModeData->m_listView;
571     Assert(compModeData && compModeData->m_chk && listView);
572
573     state = WrtDB::GlobalDAOReadOnly::getComplianceMode();
574     WrtDB::GlobalDAO::setComplianceMode(!state);
575     if (!state)
576         listView->addComplianceModeOpts(compModeData->m_gl, compModeData->m_it);
577     else
578         elm_genlist_item_subitems_clear(compModeData->m_it);
579     elm_check_state_set(compModeData->m_chk, !state);
580 }
581
582 void ListView::onComplianceModeOptErase(void *data,
583                                         Evas_Object */*obj*/,
584                                         const char */*emission*/,
585                                         const char */*source*/)
586 {
587     Evas_Object *entry;
588
589     entry = static_cast<Evas_Object *>(data);
590     Assert(entry);
591     elm_entry_entry_set(entry, "");
592 }
593
594 void ListView::onComplianceModeOptFocused(void *data,
595                                           Evas_Object *obj,
596                                           void */*event_info*/)
597 {
598     Evas_Object *ef;
599
600     Assert(obj);
601     ef = static_cast<Evas_Object *>(data);
602     Assert(ef);
603
604     if (!elm_entry_is_empty(obj))
605         elm_object_signal_emit(ef, "elm,state,eraser,show", "elm");
606     elm_object_signal_emit(ef, "elm,state,guidetext,hide", "elm");
607 }
608
609 void ListView::onComplianceModeOptUnfocused(void *data,
610                                             Evas_Object *obj,
611                                             void */*event_info*/)
612 {
613     Evas_Object *ef;
614
615     Assert(obj);
616     ef = static_cast<Evas_Object *>(data);
617     Assert(ef);
618
619     if (elm_entry_is_empty(obj))
620         elm_object_signal_emit(ef, "elm,state,guidetext,show", "elm");
621     elm_object_signal_emit(ef, "elm,state,eraser,hide", "elm");
622 }
623
624 void ListView::onComplianceModeOptChanged(void *data,
625                                           Evas_Object *obj,
626                                           void */*event_info*/)
627 {
628     int opt;
629     std::string val;
630     const char *str;
631     Evas_Object *ef;
632
633     Assert(obj);
634     opt = reinterpret_cast<int>(data);
635     if (!elm_object_focus_get(obj))
636         return;
637
638     ef = static_cast<Evas_Object *>(evas_object_data_get(obj, "editfield"));
639     Assert(ef);
640
641     str = elm_entry_entry_get(obj);
642     if (str) {
643         elm_object_signal_emit(ef, "elm,state,eraser,show", "elm");
644         val.assign(str);
645     } else {
646         elm_object_signal_emit(ef, "elm,state,eraser,hide", "elm");
647     }
648
649     switch (opt) {
650     case COMPLIANCE_OPT_IMEI:
651         WrtDB::GlobalDAO::setComplianceFakeImei(val);
652         break;
653     case COMPLIANCE_OPT_MEID:
654         WrtDB::GlobalDAO::setComplianceFakeMeid(val);
655         break;
656     default:
657         return;
658     }
659 }
660
661 void ListView::onWhiteListViewUnload(void *data)
662 {
663     ListView *listView;
664
665     listView = static_cast<ListView *>(data);
666     Assert(listView);
667     listView->delWhiteListView();
668 }
669
670 bool ListView::getCookieSharingVal(void)
671 {
672    LOGD("%s",  __FUNCTION__);
673    return WrtDB::GlobalDAOReadOnly::GetCookieSharingMode();
674 }
675
676 bool ListView::getUntrustedAppApprovalVal(void)
677 {
678     return WrtDB::GlobalDAOReadOnly::GetSecureByDefault();
679 }
680
681 bool ListView::getDevModeVal(void)
682 {
683     return WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
684 }
685
686 bool ListView::getComplianceModeVal(void)
687 {
688     return WrtDB::GlobalDAOReadOnly::getComplianceMode();
689 }
690
691 void ListView::addWacTitle(Evas_Object *gl)
692 {
693     static Elm_Genlist_Item_Class itc;
694
695     Assert(gl);
696
697     itc.item_style = "dialogue/title";
698     itc.func.text_get = getWacTitle;
699     itc.func.content_get = NULL;
700     itc.func.state_get = NULL;
701     itc.func.del = NULL;
702     elm_genlist_item_append(gl,
703                             &itc,
704                             NULL,
705                             NULL,
706                             ELM_GENLIST_ITEM_NONE,
707                             NULL,
708                             NULL);
709 }
710
711 void ListView::addWhiteList(Evas_Object *gl)
712 {
713     static Elm_Genlist_Item_Class itc;
714
715     Assert(gl);
716
717     try {
718         itc.item_style = "dialogue/1text";
719         itc.func.text_get = getWhiteListTitle;
720         itc.func.content_get = NULL;
721         itc.func.state_get = NULL;
722         itc.func.del = NULL;
723         elm_genlist_item_append(gl,
724                                 &itc,
725                                 NULL,
726                                 NULL,
727                                 ELM_GENLIST_ITEM_NONE,
728                                 onWhiteListClicked,
729                                 this);
730     } catch (const std::bad_alloc &) {
731     }
732 }
733
734 void ListView::addOnOffItem(Evas_Object *gl,
735                             const char *title,
736                             GetOnOffVal getOnOffVal,
737                             Evas_Smart_Cb changedCb)
738 {
739     OnOffData *onOffData;
740     static Elm_Genlist_Item_Class itc;
741
742     Assert(gl);
743
744     try {
745         onOffData = new OnOffData(this,
746                                   title,
747                                   getOnOffVal,
748                                   changedCb);
749         itc.item_style = "dialogue/1text.1icon";
750         itc.func.text_get = getText;
751         itc.func.content_get = getOnOffIcon;
752         itc.func.state_get = NULL;
753         itc.func.del = delOnOffData;
754         if (!elm_genlist_item_append(gl,
755                                      &itc,
756                                      static_cast<void *>(onOffData),
757                                      NULL,
758                                      ELM_GENLIST_ITEM_NONE,
759                                      onOnOffItemClicked,
760                                      static_cast<void *>(onOffData)))
761             delete onOffData;
762     } catch (const std::bad_alloc &) {
763     }
764 }
765 void ListView::addDesc(Evas_Object *gl,
766                        const char *title)
767 {
768     OnOffData *onOffData;
769     static Elm_Genlist_Item_Class itc;
770
771     Assert(gl);
772
773     try {
774         onOffData = new OnOffData(this,
775                                   title,
776                                   NULL,
777                                   NULL);
778         itc.item_style = "multiline/1text";
779         itc.func.text_get = getText;
780         itc.func.content_get = NULL;
781         itc.func.state_get = NULL;
782         itc.func.del = delOnOffData;
783         elm_genlist_mode_set(gl, ELM_LIST_COMPRESS);
784         if (!elm_genlist_item_append(gl,
785                                      &itc,
786                                      static_cast<void *>(onOffData),
787                                      NULL,
788                                      ELM_GENLIST_ITEM_NONE,
789                                      NULL,
790                                      static_cast<void *>(onOffData)))
791             delete onOffData;
792     } catch (const std::bad_alloc &) {
793     }
794 }
795
796 void ListView::addDepth(Evas_Object *gl)
797 {
798     static Elm_Genlist_Item_Class itc;
799     Elm_Object_Item *it;
800     Assert(gl);
801
802     try {
803         itc.item_style = "dialogue/separator/21/with_line";
804         itc.func.text_get = NULL;
805         itc.func.content_get = NULL;
806         itc.func.state_get = NULL;
807         itc.func.del = NULL;
808         it = elm_genlist_item_append(gl,
809                                 &itc,
810                                 NULL,
811                                 NULL,
812                                 ELM_GENLIST_ITEM_NONE,
813                                 NULL,
814                                 NULL);
815         elm_genlist_item_select_mode_set(it,
816         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
817     } catch (const std::bad_alloc &) {
818     }
819 }
820 void ListView::addRoamingItem(Evas_Object *gl)
821 {
822     Evas_Object *rg;
823     RoamingData *roamingData;
824     static Elm_Genlist_Item_Class itc;
825
826     Assert(gl);
827
828     rg = elm_radio_add(gl);
829     if (!rg)
830         return;
831
832     try {
833         roamingData = new RoamingData(rg, this);
834         itc.item_style = "dialogue/2text.3/expandable";
835         itc.func.text_get = getRoamingLabel;
836         itc.func.content_get = NULL;
837         itc.func.state_get = NULL;
838         itc.func.del = delRoamingData;
839         if (!elm_genlist_item_append(gl,
840                                      &itc,
841                                      static_cast<void *>(roamingData),
842                                      NULL,
843                                      ELM_GENLIST_ITEM_TREE,
844                                      onRoamingClicked,
845                                      static_cast<void *>(roamingData)))
846             delete roamingData;
847     } catch (const std::bad_alloc &) {
848         evas_object_del(rg);
849     }
850 }
851
852 void ListView::addRoamingOpts(Evas_Object *obj, Elm_Object_Item *it)
853 {
854     static Elm_Genlist_Item_Class itc;
855     RoamingData *roamingData;
856     RoamingExpandData *roamingExpandData;
857     unsigned int i;
858     WrtDB::GlobalDAOReadOnly::NetworkAccessMode mode[] = {
859         WrtDB::GlobalDAOReadOnly::NEVER_CONNECT,
860         WrtDB::GlobalDAOReadOnly::ALWAYS_ASK,
861         WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY,
862     };
863
864     Assert(obj && it);
865
866     roamingData = static_cast<RoamingData *>(elm_object_item_data_get(it));
867     itc.item_style = "dialogue/1text.1icon.2/expandable2";
868     itc.func.text_get = getRoamingOptLabel;
869     itc.func.content_get = getRoamingOptRadio;
870     itc.func.state_get = NULL;
871     itc.func.del = delRoamingExpandData;
872     for (i = 0; i < sizeof(mode) / sizeof(*mode); i++) {
873         try {
874             roamingExpandData = new RoamingExpandData(mode[i], roamingData->m_rg);
875             if (!elm_genlist_item_append(
876                         obj,
877                         &itc,
878                         static_cast<void *>(roamingExpandData),
879                         it,
880                         ELM_GENLIST_ITEM_NONE,
881                         onRoamingOptClicked,
882                         static_cast<void *>(roamingExpandData)))
883                 delete roamingExpandData;
884         } catch (const std::bad_alloc &) {
885         }
886     }
887 }
888
889 void ListView::addComplianceModeItem(Evas_Object *gl)
890 {
891     Elm_Object_Item *it;
892     ComplianceModeData *compModeData;
893     static Elm_Genlist_Item_Class itc;
894
895     Assert(gl);
896
897     try {
898         compModeData = new ComplianceModeData(this, gl);
899         itc.item_style = "dialogue/2text.1icon.6";
900         itc.func.text_get = getComplianceModeTitle;
901         itc.func.content_get = getComplianceModeIcon;
902         itc.func.state_get = NULL;
903         itc.func.del = delComlianceModeData;
904         it = elm_genlist_item_append(gl,
905                                      &itc,
906                                      static_cast<void *>(compModeData),
907                                      NULL,
908                                      ELM_GENLIST_ITEM_NONE,
909                                      onComplianceModeClicked,
910                                      static_cast<void *>(compModeData));
911         if (!it) {
912             delete compModeData;
913             return;
914         }
915
916         if (WrtDB::GlobalDAOReadOnly::getComplianceMode())
917             addComplianceModeOpts(gl, it);
918
919         compModeData->m_it = it;
920     } catch (const std::bad_alloc &) {
921     }
922 }
923
924 void ListView::addComplianceModeOpts(Evas_Object *obj, Elm_Object_Item *it)
925 {
926     static Elm_Genlist_Item_Class itc;
927     Elm_Object_Item *optIt;
928     unsigned int i;
929     ComplianceOpt opt[] = {
930         COMPLIANCE_OPT_IMEI,
931         COMPLIANCE_OPT_MEID,
932     };
933
934     Assert(obj && it);
935
936     itc.item_style = "dialogue/1icon";
937     itc.func.text_get = NULL;
938     itc.func.content_get = getComplianceModeOptEntry;
939     itc.func.state_get = NULL;
940     itc.func.del = NULL;
941
942     for (i = 0; i < sizeof(opt) / sizeof(*opt); i++) {
943         optIt = elm_genlist_item_append(obj,
944                                         &itc,
945                                         reinterpret_cast<void *>(opt[i]),
946                                         it,
947                                         ELM_GENLIST_ITEM_NONE,
948                                         NULL,
949                                         NULL);
950         if (optIt)
951             elm_genlist_item_select_mode_set(optIt, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
952     }
953
954 }
955
956 bool ListView::loadView(void)
957 {
958     Evas_Object *win;
959
960     Assert(m_naviFrame);
961     resetBase();
962     win = static_cast<Evas_Object *>(ug_get_window());
963     Assert(win);
964
965     m_gl = elm_genlist_add(m_naviFrame);
966     if (!m_gl) {
967         evas_object_del(m_naviFrame);
968         return false;
969     }
970     bindtextdomain("ug-webapp-common-efl",
971         MOFILE_INSTALL_DIR);
972     elm_object_style_set(m_gl, "dialogue");
973     addDepth(m_gl);
974     addOnOffItem(m_gl,
975                 dgettext("ug-webapp-common-efl", COOKIE_SHARING),
976                 getCookieSharingVal,
977                 onCookieSharingChanged);
978     addDesc(m_gl,
979             dgettext("ug-webapp-common-efl",
980                 SHARE_COOKIES_BETWEEN_WEB_APPS));
981     pushToNaviFrame();
982
983     return true;
984 }
985
986 bool ListView::pushToNaviFrame(void)
987 {
988     Evas_Object *btn;
989
990     Assert(m_naviFrame);
991     btn = elm_button_add(m_naviFrame);
992     if (!btn)
993         return false;
994
995     elm_object_style_set(btn, "naviframe/end_btn/default");
996     evas_object_smart_callback_add(btn, "clicked", onBackBtnClicked, this);
997     elm_naviframe_item_push(m_naviFrame,
998                             "Web applications",
999                             btn,
1000                             NULL,
1001                             m_gl,
1002                             NULL);
1003
1004     return true;
1005 }
1006
1007 void ListView::loadWhiteListView(void)
1008 {
1009     Assert(m_naviFrame);
1010
1011     try {
1012         m_whiteListView.Reset(new WhiteListView(m_naviFrame));
1013         if (!m_whiteListView->loadView()) {
1014             m_whiteListView.Reset();
1015             return;
1016         }
1017         m_whiteListView->setUnloadCb(onWhiteListViewUnload, this);
1018     } catch (const std::bad_alloc &) {
1019     }
1020 }
1021
1022 bool ListView::showPopup(const char *desc,
1023                          Evas_Smart_Cb ok_cb,
1024                          Evas_Smart_Cb cancel_cb,
1025                          void *data)
1026 {
1027     return m_popup.showPopup(desc, ok_cb, cancel_cb, data);
1028 }
1029
1030 void ListView::hidePopup(void)
1031 {
1032     m_popup.hidePopup();
1033 }
1034
1035 ListView::ListView(Evas_Object *naviFrame) :
1036     m_naviFrame(naviFrame)
1037 {
1038     m_whiteListView.Reset();
1039 }
1040
1041 ListView::~ListView(void)
1042 {
1043 }
1044
1045 } /* WebAppCommonSetting */