2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
18 #include <AppCommon.h>
20 #include "source_mgr.h"
21 #include "menu_view.h"
23 #include "allsource_view.h"
24 #include "plugged_layout.h"
26 #define PLUGGED_GRID 0
29 #define PLUGGED_DATA "plugged_data"
31 #define TEXT_NO_SRC_TEXT_LINE1 "No plugged source"
32 #define TEXT_NO_SRC_TEXT_LINE2 "Check connection status or install any cloud service."
34 struct SPluggedLayout {
37 Elm_Object_Item *focus_it;
38 Elm_Object_Item *del_it;
42 SSigCallbackPair *sigCb;
45 memset(this, 0, sizeof(SPluggedLayout));
49 Evas_Object *CPluggedLayout::m_DrawGengrid(Evas_Object *layout)
53 grid = util_add_grid(layout, ITEM_W, ITEM_H);
57 Connect(grid, PLUGGED_GRID, TYPE_KEY_DOWN | TYPE_MOUSE_MOVE
58 | TYPE_REALIZED | TYPE_UNREALIZED | TYPE_FOCUSED);
63 bool CPluggedLayout::Create(CLayoutMgr *lmgr, void *data)
74 m = new SPluggedLayout;
78 m->base = lmgr->Base();
85 layout = util_add_layout(m->base, GRP_PLUGGED_CONTENT);
87 _ERR("Add layout failed");
93 m->grid = m_DrawGengrid(layout);
95 _ERR("Add gengrid failed");
98 evas_object_del(layout);
102 vmgr = CViewMgr::GetInstance();
103 srcmgr = CSourceMgr::GetInstance();
107 m->sigCb = (SSigCallbackPair *)data;
109 evas_object_data_set(m->base, PLUGGED_DATA, m);
111 elm_object_part_content_set(layout, PART_CONTENT_CONTENT, m->grid);
113 CBaseLayout::Create(layout);
118 void CPluggedLayout::t_OnShow(void)
122 CBaseLayout::t_OnShow();
124 elm_object_part_content_set(m->base, PART_CONTENT, Layout());
127 void CPluggedLayout::t_OnHide(void)
131 CBaseLayout::t_OnHide();
133 elm_object_part_content_unset(m->base, PART_CONTENT);
136 void CPluggedLayout::Destroy(void)
140 evas_object_del(Layout());
142 CBaseLayout::Destroy();
148 void CPluggedLayout::m_DrawNoContentArea(void)
150 elm_object_part_text_set(Layout(), PART_NO_SRC_TEXT_LINE1,
151 _(TEXT_NO_SRC_TEXT_LINE1));
152 elm_object_part_text_set(Layout(), PART_NO_SRC_TEXT_LINE2,
153 _(TEXT_NO_SRC_TEXT_LINE2));
155 elm_object_part_content_unset(Layout(), PART_CONTENT_CONTENT);
156 evas_object_hide(m->grid);
158 m->sigCb->cb(m->sigCb->cookie, E_RETURN);
161 void CPluggedLayout::m_DrawContentArea(void)
163 elm_object_part_text_set(Layout(), PART_NO_SRC_TEXT_LINE1, "");
164 elm_object_part_text_set(Layout(), PART_NO_SRC_TEXT_LINE2, "");
166 elm_object_part_content_set(Layout(), PART_CONTENT_CONTENT, m->grid);
167 evas_object_show(m->grid);
171 Eina_Bool CPluggedLayout::sm_CbTimerDelItem(void *data)
173 CPluggedLayout *root = (CPluggedLayout *)data;
177 root->m_TimerDelItem();
182 void CPluggedLayout::m_TimerDelItem(void)
184 Elm_Object_Item *prev;
185 Elm_Object_Item *next;
190 prev = elm_gengrid_item_prev_get(m->del_it);
191 next = elm_gengrid_item_next_get(m->del_it);
193 elm_object_item_data_set(m->del_it, NULL);
194 elm_object_item_del(m->del_it);
197 m_DrawNoContentArea();
198 else if (m->del_it == m->focus_it) {
204 elm_object_item_focus_set(m->focus_it, EINA_TRUE);
210 void CPluggedLayout::sm_CbGridItemFocused(void *cookie, Elm_Object_Item *it,
211 const char *emission, const char *source)
213 CPluggedLayout *root = (CPluggedLayout *)cookie;
216 root->m_OnGridItemFocused(it, emission, source);
219 void CPluggedLayout::m_OnGridItemFocused(Elm_Object_Item *it,
220 const char *emission, const char *source)
225 m->focus_it = (Elm_Object_Item *)it;
228 void CPluggedLayout::Focus(void)
232 elm_object_focus_set(m->grid, EINA_TRUE);
233 elm_object_item_focus_set(m->focus_it, EINA_TRUE);
236 void CPluggedLayout::Update(void *data, enum update_ui type)
244 CSourceInfo *si_data;
249 list = srcmgr->PluggedList();
250 count = eina_list_count(list);
252 if (type == SRC_PLUG_ADD_ONE) {
253 si_data = (CSourceInfo *)data;
254 util_add_item(m->grid, si_data);
258 } else if (type == SRC_PLUG_DEL_ONE && data) {
259 si_data = (CSourceInfo *)data;
260 m->del_it = (Elm_Object_Item*)si_data->Data();
261 si_data->SetData(NULL);
263 timer = ecore_timer_add(DEL_IT_TIME, sm_CbTimerDelItem, this);
264 elm_object_item_data_set(m->del_it, timer);
265 util_dim_item(m->del_it);
266 } else if (type == SRC_UPDATE_ALL) {
268 m_DrawNoContentArea();
273 elm_gengrid_clear(m->grid);
275 EINA_LIST_FOREACH(list, l, obj) {
276 si = (CSourceInfo *)obj;
277 util_add_item(m->grid, si);
282 void CPluggedLayout::OnKeyDown(int id, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
288 si = m->srcmgr->SourceInfoByData(m->focus_it);
292 if (!strcmp(ev->keyname, KEY_MENU)
293 || !strcmp(ev->keyname, KEY_MENU_REMOTE))
294 m->vmgr->PushView(MENU_VIEW, si);
295 else if (!strcmp(ev->keyname, KEY_BACK)
296 || !strcmp(ev->keyname, KEY_BACK_REMOTE))
297 m->sigCb->cb(m->sigCb->cookie, E_RETURN);
304 void CPluggedLayout::OnMouseMove(int id, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Move *ev)
310 it = elm_gengrid_at_xy_item_get(obj, ev->cur.canvas.x,
311 ev->cur.canvas.y, NULL, NULL);
315 if (elm_object_item_focus_get(it))
318 elm_object_item_focus_set(it, EINA_TRUE);
320 m->sigCb->cb(m->sigCb->cookie, E_HIGHLIGHT);
328 void CPluggedLayout::OnRealized(int id, Evas_Object *obj, Elm_Object_Item *item)
332 elm_object_item_signal_callback_add(item, "item_focused",
333 "edc", sm_CbGridItemFocused, this);
340 void CPluggedLayout::OnUnrealized(int id, Evas_Object *obj, Elm_Object_Item *item)
344 elm_object_item_signal_callback_del(item, "item_focused",
345 "edc", sm_CbGridItemFocused);
352 void CPluggedLayout::OnFocused(int id, Evas_Object *obj, Elm_Object_Item *item)
356 m->sigCb->cb(m->sigCb->cookie, E_HIGHLIGHT);