2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://floralicense.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 * @file PeriodChanger.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
24 #include <Elementary.h>
25 #include <livebox-service.h>
26 #include <Core/Util/Log.h>
27 #include "PeriodChanger.h"
29 #define UPDATE_PERIOD_MIN 60.0
33 Evas_Object* PeriodChanger::s_window = NULL;
35 PeriodChanger::PeriodChanger(
36 std::string& boxId, std::string& instanceId,
37 float currentPeriod, float requestedPeriod)
39 , m_instanceId(instanceId)
40 , m_currentPeriod(currentPeriod)
41 , m_requestedPeriod(requestedPeriod)
47 PeriodChanger::~PeriodChanger()
52 bool PeriodChanger::change()
56 if (m_requestedPeriod < 0) {
62 if (m_requestedPeriod == 0) {
64 } else if (m_requestedPeriod > 0) {
65 if (m_requestedPeriod > UPDATE_PERIOD_MIN) {
66 newPeriod = m_requestedPeriod;
68 newPeriod = UPDATE_PERIOD_MIN;
71 LogD("negative value can't be handled here");
75 // after selecting one among period list, the following should be executed
76 return requestToPlatform(newPeriod);
79 void PeriodChanger::showPeriodPopup()
83 Evas_Object* window = createWindow();
84 Evas_Object* periodList = elm_list_add(window);
88 LogD("failed to add elm_list_add");
90 elm_list_mode_set(periodList, ELM_LIST_EXPAND);
93 // TODO Language ID should be used, not static string
94 for(int i = 0 ; i < sizeof(m_hour) / sizeof(PopupListData); i++) {
95 radio = elm_radio_add(periodList);
96 elm_radio_state_value_set(radio,
97 m_currentPeriod == m_hour[i].newPeriod ? EINA_FALSE : EINA_TRUE);
98 elm_list_item_append(periodList,
102 selectPeriodCallback, &m_hour[i]);
106 Evas_Object *popup = elm_popup_add(window);
108 LogD("failed to add elm_popup_add");
111 elm_object_style_set(popup, "popup-item list");
112 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113 elm_object_part_text_set(popup, "title,text", "Update Period");
114 elm_object_content_set(popup, periodList);
115 evas_object_show(popup);
116 Evas_Object* cancelButton = elm_button_add(popup);
118 LogD("failed to add elm_button_add");
121 // TODO Language ID should be used, not static string
122 elm_object_text_set(cancelButton, "Cancel");
123 elm_object_style_set(cancelButton, "popup_button/default");
124 elm_object_part_content_set(popup, "button1", cancelButton);
125 evas_object_show(cancelButton);
126 evas_object_smart_callback_add(cancelButton, "clicked", cancelButtonCallback, this);
129 void PeriodChanger::destroyPeriodPopup(Evas_Object *obj)
132 Evas_Object* parent = elm_object_parent_widget_get(obj);
133 Evas_Object* popup = elm_popup_add(parent);
135 const char* type = elm_object_widget_type_get(parent);
136 if (type && !strcmp(type, elm_object_widget_type_get(popup))) {
137 evas_object_del(parent);
140 parent = elm_object_parent_widget_get(parent);
142 evas_object_del(popup);
146 void PeriodChanger::setPopupListData()
150 m_hour[0].periodChanger = this;
151 m_hour[0].newPeriod = 1.0 * 60.0 * 60.0;
152 m_hour[0].period = "1 hour";
154 m_hour[1].periodChanger = this;
155 m_hour[1].newPeriod = 3.0 * 60.0 * 60.0;
156 m_hour[1].period = "3 hour";
158 m_hour[2].periodChanger = this;
159 m_hour[2].newPeriod = 6.0 * 60.0 * 60.0;
160 m_hour[2].period = "6 hour";
162 m_hour[3].periodChanger = this;
163 m_hour[3].newPeriod = 12.0 * 60.0 * 60.0;
164 m_hour[3].period = "12 hour";
166 m_hour[4].periodChanger = this;
167 m_hour[4].newPeriod = 0.0;
168 m_hour[4].period = "Never";
172 bool PeriodChanger::requestToPlatform(float newPeriod)
174 int ret = livebox_service_change_period(
175 m_boxId.c_str(), m_instanceId.c_str(), newPeriod);
178 LogD("during update period, error occurs");
182 LogD("Instance's period is set to %f", newPeriod);
187 Evas_Object* PeriodChanger::createWindow()
192 evas_object_show(s_window);
193 elm_win_raise(s_window);
197 s_window = elm_win_add(NULL, "web-provider-popup", ELM_WIN_BASIC);
198 elm_win_alpha_set(s_window, EINA_TRUE);
199 elm_win_title_set(s_window, "change update period");
200 elm_win_borderless_set(s_window, EINA_TRUE);
204 ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
205 evas_object_resize(s_window, width, height);
206 elm_win_indicator_mode_set(s_window, ELM_WIN_INDICATOR_SHOW);
208 evas_object_color_set(s_window, 255, 255, 255, 0);
209 evas_object_show(s_window);
213 void PeriodChanger::destroyWindow()
220 evas_object_hide(s_window);
221 elm_win_lower(s_window);
224 void PeriodChanger::selectPeriodCallback(void *data, Evas_Object *obj, void *event_info)
227 PopupListData* popupData = static_cast<PopupListData*>(data);
229 LogD("Update period is set to %f", popupData->newPeriod);
230 popupData->periodChanger->requestToPlatform(popupData->newPeriod);
231 popupData->periodChanger->destroyPeriodPopup(obj);
234 void PeriodChanger::cancelButtonCallback(void *data, Evas_Object *obj, void *event_info)
237 PeriodChanger* This = static_cast<PeriodChanger*>(data);
238 This->destroyPeriodPopup(obj);