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