[Release] wrt-setting_0.0.50
[apps/home/wrt-setting.git] / webapp-common / 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 <ui-gadget-module.h>
18 #include <Elementary.h>
19
20 #include <dpl/assert.h>
21
22 #include "mainview.h"
23 #include "listview.h"
24
25 namespace WebAppCommonSetting {
26
27 void MainView::onListViewUnload(void *data)
28 {
29     MainView *mainView;
30
31     mainView = static_cast<MainView *>(data);
32     Assert(mainView);
33     ug_destroy_me(mainView->getUG());
34 }
35
36 Evas_Object *MainView::createContent(Evas_Object *parent)
37 {
38     Evas_Object *nf;
39
40     Assert(parent);
41     nf = elm_naviframe_add(parent);
42     if (!nf)
43         return NULL;
44
45     try {
46         m_list.Reset(new ListView(nf));
47         if (!m_list->loadView())
48             goto del_list;
49         m_list->setUnloadCb(onListViewUnload, this);
50         return nf;
51
52     } catch (const std::bad_alloc &) {
53         goto del_nf;
54     }
55
56 del_list:
57     m_list.Reset();
58 del_nf:
59     evas_object_del(nf);
60
61     return NULL;
62 }
63
64 bool MainView::loadView(void)
65 {
66     Evas_Object *ly;
67     Evas_Object *eo;
68     Evas_Object *parent;
69
70     Assert(m_ug);
71     resetBase();
72
73     parent = static_cast<Evas_Object *>(ug_get_parent_layout(m_ug));
74     Assert(parent);
75
76     ly = elm_layout_add(parent);
77     if (!ly)
78         return false;
79     elm_layout_theme_set(ly, "layout", "application", "default");
80
81     eo = elm_bg_add(ly);
82     if (!eo)
83         goto del_ly;
84     elm_object_part_content_set(ly, "elm.swallow.bg", eo);
85
86     eo = createContent(ly);
87     if (!eo)
88         goto del_ly;
89     elm_object_part_content_set(ly, "elm.swallow.content", eo);
90
91     resetBase(ly);
92
93     return true;
94
95 del_ly:
96     evas_object_del(ly);
97
98     return false;
99 }
100
101 MainView::MainView(ui_gadget_h ug) :
102     m_ug(ug)
103 {
104     Assert(ug);
105
106     m_list.Reset();
107 }
108
109 MainView::~MainView(void)
110 {
111 }
112
113 } /* WebAppCommonSetting */