[Release] wrt-setting_0.0.50
[apps/home/wrt-setting.git] / webapp-common / popup.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.h>
19
20 #include <dpl/assert.h>
21
22 #include "popup.h"
23
24 namespace WebAppCommonSetting {
25
26 bool Popup::showPopup(const char *desc,
27                       Evas_Smart_Cb ok_cb,
28                       Evas_Smart_Cb cancel_cb,
29                       void *data)
30 {
31     Evas_Object *btn1;
32     Evas_Object *btn2;
33
34     if (m_pu)
35         evas_object_del(m_pu);
36
37     m_pu = elm_popup_add(m_win);
38     if (!m_pu)
39         return false;
40     evas_object_size_hint_weight_set(m_pu,
41                                      EVAS_HINT_EXPAND,
42                                      EVAS_HINT_EXPAND);
43     elm_object_text_set(m_pu, desc);
44
45     btn1 = elm_button_add(m_pu);
46     if (!btn1) {
47         evas_object_del(m_pu);
48         return false;
49     }
50     elm_object_text_set(btn1, "OK");
51     evas_object_smart_callback_add(btn1, "clicked", ok_cb, data);
52     elm_object_part_content_set(m_pu, "button1", btn1);
53
54     btn2 = elm_button_add(m_pu);
55     if (!btn2) {
56         evas_object_del(m_pu);
57         return false;
58     }
59     elm_object_text_set(btn2, "Cancel");
60     evas_object_smart_callback_add(btn2, "clicked", cancel_cb, data);
61     elm_object_part_content_set(m_pu, "button2", btn2);
62
63     evas_object_show(m_pu);
64
65     return true;
66 }
67
68 void Popup::hidePopup(void)
69 {
70     if (m_pu) {
71         evas_object_del(m_pu);
72         m_pu = NULL;
73     }
74 }
75
76 Popup::Popup(void) :
77     m_win(NULL),
78     m_pu(NULL)
79 {
80     m_win = static_cast<Evas_Object *>(ug_get_window());
81     Assert(m_win);
82 }
83
84 Popup::~Popup(void)
85 {
86     if (m_pu)
87         evas_object_del(m_pu);
88 }
89
90 } /* WebAppCommonSetting */