The license change version 1.0 to version 1.1
[apps/home/wrt-setting.git] / webapp-detail / mainview.cpp
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 <Elementary.h>
18 #include <ui-gadget-module.h>
19
20 #include <dpl/assert.h>
21
22 #include "mainview.h"
23 #include "edc/defs.h"
24 #include "util.h"
25
26 namespace WebAppDetailSetting {
27
28 void MainView::onBackBtnClicked(void *data,
29                                 Evas_Object */*eo*/,
30                                 void */*event_info*/)
31 {
32     MainView *mainView;
33
34     mainView = static_cast<MainView *>(data);
35     Assert(mainView);
36     ug_destroy_me(mainView->getUG());
37 }
38
39 void MainView::onSegCtrlChanged(void *data,
40                                 Evas_Object */*eo*/,
41                                 void *event_info)
42 {
43     MainView *mainView;
44     Evas_Object *subCtnt;
45     Elm_Object_Item *it;
46
47     mainView = static_cast<MainView *>(data);
48     Assert(mainView);
49     it = reinterpret_cast<Elm_Object_Item *>(event_info);
50     Assert(it);
51
52     subCtnt = mainView->getSubCtnt();
53     if (!subCtnt)
54         return;
55
56     if (it == mainView->getSegCtrlDetail())
57         elm_object_signal_emit(subCtnt,
58                 SIG_SHOW_DETAIL, SRC_PROG);
59     else if (it == mainView->getSegCtrlPerm())
60         elm_object_signal_emit(subCtnt,
61                 SIG_SHOW_PERM, SRC_PROG);
62 }
63
64 Evas_Object *MainView::createToolBar(Evas_Object *parent)
65 {
66     Evas_Object *toolBar;
67     Evas_Object *segCtrl;
68     Elm_Object_Item *it;
69
70     toolBar = elm_toolbar_add(parent);
71     if (!toolBar)
72         return NULL;
73     elm_object_style_set(toolBar, "naviframe");
74     elm_toolbar_shrink_mode_set(toolBar, ELM_TOOLBAR_SHRINK_EXPAND);
75     elm_toolbar_select_mode_set(toolBar, ELM_OBJECT_SELECT_MODE_ALWAYS);
76
77     segCtrl = elm_segment_control_add(toolBar);
78     if (!segCtrl) {
79         evas_object_del(toolBar);
80         return NULL;
81     }
82
83     m_segCtrlDetail = elm_segment_control_item_add(segCtrl,
84                                                    NULL,
85                                                    D_("IDS_COM_BODY_DETAILS"));
86     /* FIXME: i18n */
87     m_segCtrlPerm = elm_segment_control_item_add(segCtrl, NULL, "Permissions");
88     elm_segment_control_item_selected_set(m_segCtrlDetail, EINA_TRUE);
89     it = elm_toolbar_item_append(toolBar, NULL, NULL, NULL, NULL);
90     elm_object_item_part_content_set(it, "object", segCtrl);
91     evas_object_smart_callback_add(segCtrl, "changed", onSegCtrlChanged, this);
92
93     return toolBar;
94 }
95
96 Evas_Object *MainView::createContent(Evas_Object *parent)
97 {
98     Evas_Object *nf;
99
100     Assert(parent);
101     nf = elm_naviframe_add(parent);
102     if (!nf)
103     return NULL;
104
105     try {
106     m_detail.Reset(new DetailView(nf, m_ug, m_appID));
107     if (!m_detail->loadView())
108         goto del_list;
109     return nf;
110
111     } catch (const std::bad_alloc &) {
112     m_detail.Reset();
113     goto del_nf;
114     }
115
116     del_list:
117     m_detail.Reset();
118     del_nf:
119     evas_object_del(nf);
120     return NULL;
121 }
122
123 Evas_Object *MainView::loadView(void)
124 {
125     Evas_Object *ly;
126     Evas_Object *eo;
127     Evas_Object *parent;
128
129     Assert(m_ug);
130     resetBase();
131
132     parent = static_cast<Evas_Object *>(ug_get_parent_layout(m_ug));
133     Assert(parent);
134
135     ly = elm_layout_add(parent);
136     if (!ly)
137         return NULL;
138     elm_layout_theme_set(ly, "layout", "application", "default");
139
140     eo = elm_bg_add(ly);
141     if (!eo)
142         goto del_ly;
143     elm_object_part_content_set(ly, "elm.swallow.bg", eo);
144
145     eo = createContent(ly);
146     if (!eo)
147         goto del_ly;
148     elm_object_part_content_set(ly, "elm.swallow.content", eo);
149
150     resetBase(ly);
151
152     return ly;
153
154 del_ly:
155     evas_object_del(ly);
156
157     return NULL;
158 }
159
160 MainView::MainView(ui_gadget_h ug, DPL::String appId) :
161     m_ug(ug),
162     m_appID(appId),
163     m_subCtnt(NULL),
164     m_segCtrlDetail(NULL),
165     m_segCtrlPerm(NULL)
166 {
167     Assert(ug);
168
169     m_detail.Reset();
170     m_perm.Reset();
171 }
172
173 MainView::~MainView(void)
174 {
175 }
176
177 } /* WebAppDetailSetting */