2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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 #include <Elementary.h>
18 #include <ui-gadget.h>
19 #include <ui-gadget-module.h>
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>
29 #define LOG_TAG "WRT-SETTING"
32 namespace WebAppCommonSetting {
34 char *ListView::getWacTitle(void */*data*/,
41 char *ListView::getWhiteListTitle(void */*data*/,
45 return strdup("White list");
48 char *ListView::getOnOffTitle(void *data,
55 onOffData = static_cast<OnOffData *>(data);
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();
71 Evas_Object *ListView::getOnOffIcon(void *data,
79 onOffData = static_cast<OnOffData *>(data);
82 chk = elm_check_add(obj);
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,
92 onOffData->m_changedCb,
98 void ListView::delOnOffData(void *data, Evas_Object */*obj*/)
100 OnOffData *onOffData;
102 onOffData = static_cast<OnOffData *>(data);
106 char *ListView::getRoamingLabel(void *data,
107 Evas_Object */*obj*/,
111 RoamingData *roamingData;
113 roamingData = static_cast<RoamingData *>(data);
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";
123 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
126 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
127 str = "Connect automatically";
143 void ListView::delRoamingData(void *data, Evas_Object */*obj*/)
145 RoamingData *roamingData;
147 roamingData = static_cast<RoamingData *>(data);
151 char *ListView::getRoamingOptLabel(void *data,
152 Evas_Object */*obj*/,
153 const char */*part*/)
156 RoamingExpandData *roamingExpandData;
158 roamingExpandData = static_cast<RoamingExpandData *>(data);
159 Assert(roamingExpandData);
161 switch (roamingExpandData->m_mode) {
162 case WrtDB::GlobalDAOReadOnly::NEVER_CONNECT:
163 str = "Never connect";
165 case WrtDB::GlobalDAOReadOnly::ALWAYS_ASK:
168 case WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY:
169 str = "Connect automatically";
182 Evas_Object *ListView::getRoamingOptRadio(void *data,
184 const char */*part*/)
187 RoamingExpandData *roamingExpandData;
190 roamingExpandData = static_cast<RoamingExpandData *>(data);
191 Assert(roamingExpandData);
192 mode = WrtDB::GlobalDAOReadOnly::GetRoamingDataUsage();
193 radio = elm_radio_add(obj);
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);
204 void ListView::delRoamingExpandData(void *data, Evas_Object */*obj*/)
206 RoamingExpandData *roamingExpandData;
208 roamingExpandData = static_cast<RoamingExpandData *>(data);
209 delete roamingExpandData;
212 char *ListView::getComplianceModeTitle(void */*data*/,
213 Evas_Object */*obj*/,
218 if (!strcmp(part, "elm.text.1"))
219 str = "Compliance mode";
220 else if (!strcmp(part, "elm.text.2"))
221 str = "Enable compliance mode";
231 Evas_Object *ListView::getComplianceModeIcon(void *data,
233 const char */*part*/)
236 ComplianceModeData *compModeData;
239 compModeData = static_cast<ComplianceModeData *>(data);
240 Assert(compModeData);
242 chk = elm_check_add(obj);
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,
252 onComplianceModeChanged,
258 void ListView::delComlianceModeData(void *data, Evas_Object */*obj*/)
260 ComplianceModeData *compModeData;
262 compModeData = static_cast<ComplianceModeData *>(data);
266 Evas_Object *ListView::getComplianceModeOptEntry(void *data,
268 const char */*part*/)
275 opt = reinterpret_cast<int>(data);
277 ef = elm_layout_add(obj);
280 elm_layout_theme_set(ef, "layout", "editfield", "title");
282 entry = elm_entry_add(ef);
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);
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();
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();
308 elm_entry_entry_set(entry, val.c_str());
309 elm_object_signal_emit(ef, "elm,state,guidetext,hide", "elm");
312 elm_object_signal_callback_add(ef,
313 "elm,eraser,clicked",
315 onComplianceModeOptErase,
316 static_cast<void *>(entry));
317 evas_object_smart_callback_add(entry,
319 onComplianceModeOptFocused,
320 static_cast<void *>(ef));
321 evas_object_smart_callback_add(entry,
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,
328 onComplianceModeOptChanged,
334 void ListView::onBackBtnClicked(void *data,
335 Evas_Object */*obj*/,
336 void */*event_info*/)
340 listView = static_cast<ListView *>(data);
342 listView->invokeUnloadCb();
345 void ListView::onOnOffItemClicked(void *data,
346 Evas_Object */*obj*/,
350 OnOffData *onOffData;
352 it = static_cast<Elm_Object_Item *>(event_info);
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);
359 void ListView::onCookieSharingPopupOk(void *data,
360 Evas_Object */*obj*/,
361 void */*event_info*/)
363 OnOffData *onOffData;
366 onOffData = static_cast<OnOffData *>(data);
367 listView = onOffData->m_listView;
368 Assert(onOffData && listView);
370 WrtDB::GlobalDAO::SetCookieSharingMode(TRUE);
372 elm_check_state_set(onOffData->m_chk, EINA_TRUE);
373 listView->hidePopup();
376 void ListView::onCookieSharingPopupCancel(void *data,
377 Evas_Object */*obj*/,
378 void */*event_info*/)
380 OnOffData *onOffData;
383 onOffData = static_cast<OnOffData *>(data);
384 listView = onOffData->m_listView;
385 Assert(onOffData && listView);
387 WrtDB::GlobalDAO::SetCookieSharingMode(FALSE);
388 elm_check_state_set(onOffData->m_chk, EINA_FALSE);
389 listView->hidePopup();
392 void ListView::onCookieSharingChanged(void *data,
393 Evas_Object */*obj*/,
394 void */*event_info*/)
396 OnOffData *onOffData;
400 onOffData = static_cast<OnOffData *>(data);
401 listView = onOffData->m_listView;
402 Assert(onOffData && onOffData->m_chk && listView);
404 state = elm_check_state_get(onOffData->m_chk);
407 if (!listView->showPopup("Do you really want to share cookies "
408 "between web applications?",
409 onCookieSharingPopupOk,
410 onCookieSharingPopupCancel,
411 static_cast<void *>(onOffData)))
414 WrtDB::GlobalDAO::SetCookieSharingMode(FALSE);
415 elm_check_state_set(onOffData->m_chk, FALSE);
419 void ListView::onUntrustedAppApprovalPopupOk(void *data,
420 Evas_Object */*obj*/,
421 void */*event_info*/)
423 OnOffData *onOffData;
426 onOffData = static_cast<OnOffData *>(data);
427 listView = onOffData->m_listView;
428 Assert(onOffData && listView);
430 WrtDB::GlobalDAO::SetSecureByDefault(true);
431 elm_check_state_set(onOffData->m_chk, EINA_TRUE);
432 listView->hidePopup();
435 void ListView::onUntrustedAppApprovalPopupCancel(void *data,
436 Evas_Object */*obj*/,
437 void */*event_info*/)
439 OnOffData *onOffData;
442 onOffData = static_cast<OnOffData *>(data);
443 listView = onOffData->m_listView;
444 Assert(onOffData && listView);
446 elm_check_state_set(onOffData->m_chk, EINA_FALSE);
447 listView->hidePopup();
450 void ListView::onUntrustedAppApprovalChanged(void *data,
451 Evas_Object */*obj*/,
452 void */*event_info*/)
454 OnOffData *onOffData;
458 onOffData = static_cast<OnOffData *>(data);
459 listView = onOffData->m_listView;
460 Assert(onOffData && onOffData->m_chk && listView);
462 state = WrtDB::GlobalDAOReadOnly::GetSecureByDefault();
464 if (!listView->showPopup("Do you really want to allow "
465 "untrusted applications?",
466 onUntrustedAppApprovalPopupOk,
467 onUntrustedAppApprovalPopupCancel,
468 static_cast<void *>(onOffData)))
471 WrtDB::GlobalDAO::SetSecureByDefault(false);
473 elm_check_state_set(onOffData->m_chk, !state);
476 void ListView::onRoamingClicked(void *data,
482 RoamingData *roamingData;
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);
493 elm_genlist_item_subitems_clear(it);
495 listView->addRoamingOpts(obj, it);
498 void ListView::onRoamingOptClicked(void *data,
502 RoamingExpandData *roamingExpandData;
505 it = static_cast<Elm_Object_Item *>(event_info);
507 elm_genlist_item_selected_set(it, EINA_FALSE);
509 roamingExpandData = static_cast<RoamingExpandData *>(data);
510 Assert(roamingExpandData);
511 WrtDB::GlobalDAO::SetRoamingDataUsage(roamingExpandData->m_mode);
512 elm_genlist_realized_items_update(obj);
515 void ListView::onWhiteListClicked(void *data,
516 Evas_Object */*obj*/,
522 it = static_cast<Elm_Object_Item *>(event_info);
524 elm_genlist_item_selected_set(it, EINA_FALSE);
526 listView = static_cast<ListView *>(data);
528 listView->loadWhiteListView();
532 void ListView::onDevModeChanged(void *data,
533 Evas_Object */*obj*/,
534 void */*event_info*/)
536 OnOffData *onOffData;
540 onOffData = static_cast<OnOffData *>(data);
541 listView = onOffData->m_listView;
542 Assert(onOffData && onOffData->m_chk && listView);
544 state = WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
545 WrtDB::GlobalDAO::SetDeveloperMode(!state);
546 elm_check_state_set(onOffData->m_chk, !state);
549 void ListView::onComplianceModeClicked(void *data,
550 Evas_Object */*obj*/,
554 ComplianceModeData *compModeData;
556 it = static_cast<Elm_Object_Item *>(event_info);
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);
563 void ListView::onComplianceModeChanged(void *data,
564 Evas_Object */*obj*/,
565 void */*event_info*/)
567 ComplianceModeData *compModeData;
571 compModeData = static_cast<ComplianceModeData *>(data);
572 listView = compModeData->m_listView;
573 Assert(compModeData && compModeData->m_chk && listView);
575 state = WrtDB::GlobalDAOReadOnly::getComplianceMode();
576 WrtDB::GlobalDAO::setComplianceMode(!state);
578 listView->addComplianceModeOpts(compModeData->m_gl, compModeData->m_it);
580 elm_genlist_item_subitems_clear(compModeData->m_it);
581 elm_check_state_set(compModeData->m_chk, !state);
584 void ListView::onComplianceModeOptErase(void *data,
585 Evas_Object */*obj*/,
586 const char */*emission*/,
587 const char */*source*/)
591 entry = static_cast<Evas_Object *>(data);
593 elm_entry_entry_set(entry, "");
596 void ListView::onComplianceModeOptFocused(void *data,
598 void */*event_info*/)
603 ef = static_cast<Evas_Object *>(data);
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");
611 void ListView::onComplianceModeOptUnfocused(void *data,
613 void */*event_info*/)
618 ef = static_cast<Evas_Object *>(data);
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");
626 void ListView::onComplianceModeOptChanged(void *data,
628 void */*event_info*/)
636 opt = reinterpret_cast<int>(data);
637 if (!elm_object_focus_get(obj))
640 ef = static_cast<Evas_Object *>(evas_object_data_get(obj, "editfield"));
643 str = elm_entry_entry_get(obj);
645 elm_object_signal_emit(ef, "elm,state,eraser,show", "elm");
648 elm_object_signal_emit(ef, "elm,state,eraser,hide", "elm");
652 case COMPLIANCE_OPT_IMEI:
653 WrtDB::GlobalDAO::setComplianceFakeImei(val);
655 case COMPLIANCE_OPT_MEID:
656 WrtDB::GlobalDAO::setComplianceFakeMeid(val);
663 void ListView::onWhiteListViewUnload(void *data)
667 listView = static_cast<ListView *>(data);
669 listView->delWhiteListView();
672 bool ListView::getCookieSharingVal(void)
674 LOGD("%s", __FUNCTION__);
675 return WrtDB::GlobalDAOReadOnly::GetCookieSharingMode();
678 bool ListView::getUntrustedAppApprovalVal(void)
680 return WrtDB::GlobalDAOReadOnly::GetSecureByDefault();
683 bool ListView::getDevModeVal(void)
685 return WrtDB::GlobalDAOReadOnly::GetDeveloperMode();
688 bool ListView::getComplianceModeVal(void)
690 return WrtDB::GlobalDAOReadOnly::getComplianceMode();
693 void ListView::addWacTitle(Evas_Object *gl)
695 static Elm_Genlist_Item_Class itc;
699 itc.item_style = "dialogue/title";
700 itc.func.text_get = getWacTitle;
701 itc.func.content_get = NULL;
702 itc.func.state_get = NULL;
704 elm_genlist_item_append(gl,
708 ELM_GENLIST_ITEM_NONE,
713 void ListView::addWhiteList(Evas_Object *gl)
715 static Elm_Genlist_Item_Class itc;
720 itc.item_style = "dialogue/1text";
721 itc.func.text_get = getWhiteListTitle;
722 itc.func.content_get = NULL;
723 itc.func.state_get = NULL;
725 elm_genlist_item_append(gl,
729 ELM_GENLIST_ITEM_NONE,
732 } catch (const std::bad_alloc &) {
736 void ListView::addOnOffItem(Evas_Object *gl,
739 GetOnOffVal getOnOffVal,
740 Evas_Smart_Cb changedCb)
742 OnOffData *onOffData;
743 static Elm_Genlist_Item_Class itc;
748 onOffData = new OnOffData(this,
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,
760 static_cast<void *>(onOffData),
762 ELM_GENLIST_ITEM_NONE,
764 static_cast<void *>(onOffData)))
766 } catch (const std::bad_alloc &) {
770 void ListView::addRoamingItem(Evas_Object *gl)
773 RoamingData *roamingData;
774 static Elm_Genlist_Item_Class itc;
778 rg = elm_radio_add(gl);
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,
791 static_cast<void *>(roamingData),
793 ELM_GENLIST_ITEM_TREE,
795 static_cast<void *>(roamingData)))
797 } catch (const std::bad_alloc &) {
802 void ListView::addRoamingOpts(Evas_Object *obj, Elm_Object_Item *it)
804 static Elm_Genlist_Item_Class itc;
805 RoamingData *roamingData;
806 RoamingExpandData *roamingExpandData;
808 WrtDB::GlobalDAOReadOnly::NetworkAccessMode mode[] = {
809 WrtDB::GlobalDAOReadOnly::NEVER_CONNECT,
810 WrtDB::GlobalDAOReadOnly::ALWAYS_ASK,
811 WrtDB::GlobalDAOReadOnly::CONNECT_AUTOMATICALLY,
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++) {
824 roamingExpandData = new RoamingExpandData(mode[i], roamingData->m_rg);
825 if (!elm_genlist_item_append(
828 static_cast<void *>(roamingExpandData),
830 ELM_GENLIST_ITEM_NONE,
832 static_cast<void *>(roamingExpandData)))
833 delete roamingExpandData;
834 } catch (const std::bad_alloc &) {
839 void ListView::addComplianceModeItem(Evas_Object *gl)
842 ComplianceModeData *compModeData;
843 static Elm_Genlist_Item_Class itc;
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,
856 static_cast<void *>(compModeData),
858 ELM_GENLIST_ITEM_NONE,
859 onComplianceModeClicked,
860 static_cast<void *>(compModeData));
864 if (WrtDB::GlobalDAOReadOnly::getComplianceMode())
865 addComplianceModeOpts(gl, it);
867 compModeData->m_it = it;
868 } catch (const std::bad_alloc &) {
872 void ListView::addComplianceModeOpts(Evas_Object *obj, Elm_Object_Item *it)
874 static Elm_Genlist_Item_Class itc;
875 Elm_Object_Item *optIt;
877 ComplianceOpt opt[] = {
884 itc.item_style = "dialogue/1icon";
885 itc.func.text_get = NULL;
886 itc.func.content_get = getComplianceModeOptEntry;
887 itc.func.state_get = NULL;
890 for (i = 0; i < sizeof(opt) / sizeof(*opt); i++) {
891 optIt = elm_genlist_item_append(obj,
893 reinterpret_cast<void *>(opt[i]),
895 ELM_GENLIST_ITEM_NONE,
899 elm_genlist_item_select_mode_set(optIt, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
904 bool ListView::loadView(void)
908 Evas_Object *conform;
912 win = static_cast<Evas_Object *>(ug_get_window());
914 elm_win_conformant_set(win, EINA_TRUE);
915 conform = elm_conformant_add(m_naviFrame);
918 elm_object_style_set(conform, "internal_layout");
920 gl = elm_genlist_add(conform);
922 evas_object_del(conform);
925 elm_object_style_set(gl, "dialogue");
926 elm_object_content_set(conform, gl);
931 "Share cookies between web apps",
933 onCookieSharingChanged);
935 //These menus are currently being discussed.
936 //so later to be merged
939 "Untrusted applications",
940 "Allow untrusted applications",
941 getUntrustedAppApprovalVal,
942 onUntrustedAppApprovalChanged);
948 "Enable developer mode",
951 addComplianceModeItem(gl);
958 bool ListView::pushToNaviFrame(void)
963 btn = elm_button_add(m_naviFrame);
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,
979 void ListView::loadWhiteListView(void)
984 m_whiteListView.Reset(new WhiteListView(m_naviFrame));
985 if (!m_whiteListView->loadView()) {
986 m_whiteListView.Reset();
989 m_whiteListView->setUnloadCb(onWhiteListViewUnload, this);
990 } catch (const std::bad_alloc &) {
994 bool ListView::showPopup(const char *desc,
996 Evas_Smart_Cb cancel_cb,
999 return m_popup.showPopup(desc, ok_cb, cancel_cb, data);
1002 void ListView::hidePopup(void)
1004 m_popup.hidePopup();
1007 ListView::ListView(Evas_Object *naviFrame) :
1008 m_naviFrame(naviFrame)
1010 m_whiteListView.Reset();
1013 ListView::~ListView(void)
1017 } /* WebAppCommonSetting */