2 * Copyright (c) 2016 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.
17 #include <minicontrol-viewer.h>
22 #include "minicontrollers.h"
27 } minicontroller_info_t;
29 static Eina_List *active_minicontroller;
30 int LOCKSCREEN_EVENT_MINICONTROLLERS_CHANGED, init_count;
32 static int _lockscreen_minicontroller_search(const void *data1, const void *data2);
34 static minicontroller_info_t *_minicontroller_create(const char *name, int w, int h)
36 minicontroller_info_t *ret = calloc(1, sizeof(minicontroller_info_t));
38 ret->name = eina_stringshare_add(name);
45 static void _minicontroller_destroy(minicontroller_info_t *info)
47 eina_stringshare_del(info->name);
51 static void _minicontroller_start_handle(const char *name, int w, int h)
53 /** FIXME Since minicontroller API do not allow to filter minicontrollers
54 * targeted for lockscreen we just asume that interesting minicontrollers
55 * has proper suffix in its name */
56 if (name && strstr(name, "LOCKSCREEN")) {
57 minicontroller_info_t *info = eina_list_search_unsorted(active_minicontroller, _lockscreen_minicontroller_search, name);
59 info = _minicontroller_create(name, w, h);
60 active_minicontroller = eina_list_append(active_minicontroller, info);
61 ecore_event_add(LOCKSCREEN_EVENT_MINICONTROLLERS_CHANGED, NULL, NULL, NULL);
66 static void _minicontroller_stop_handle(const char *name)
69 minicontroller_info_t *info = eina_list_search_unsorted(active_minicontroller, _lockscreen_minicontroller_search, name);
71 active_minicontroller = eina_list_remove(active_minicontroller, info);
72 _minicontroller_destroy(info);
73 ecore_event_add(LOCKSCREEN_EVENT_MINICONTROLLERS_CHANGED, NULL, NULL, NULL);
78 static void _minicontroller_geometry_from_bundle_get(bundle *event_arg, int *width, int *height)
84 int ret = bundle_get_byte(event_arg, "width", (void**)&val, &val_size);
85 if (ret == BUNDLE_ERROR_NONE) {
86 if (width) *width = *val;
88 ret = bundle_get_byte(event_arg, "height", (void**)&val, &val_size);
89 if (ret == BUNDLE_ERROR_NONE) {
90 if (height) *height = *val;
94 static void _minicontroler_event(minicontrol_event_e event, const char *minicontrol_name, bundle *event_arg, void *data)
97 if (!minicontrol_name)
100 DBG("Available minicontroller: %s", minicontrol_name);
103 case MINICONTROL_EVENT_START:
104 _minicontroller_geometry_from_bundle_get(event_arg, &w, &h);
105 _minicontroller_start_handle(minicontrol_name, w, h);
107 case MINICONTROL_EVENT_STOP:
108 _minicontroller_stop_handle(minicontrol_name);
111 DBG("Unahandled minicontroller event: %d for %s", event, minicontrol_name);
116 int lockscreen_minicontrollers_init(void)
119 LOCKSCREEN_EVENT_MINICONTROLLERS_CHANGED = ecore_event_type_new();
120 int ret = minicontrol_viewer_set_event_cb(_minicontroler_event, NULL);
121 if (ret != MINICONTROL_ERROR_NONE) {
122 ERR("minicontrol_viewer_set_event_cb failed: %s", get_error_message(ret));
130 void lockscreen_minicontrollers_shutdown(void)
132 minicontroller_info_t *info;
136 int ret = minicontrol_viewer_unset_event_cb();
137 if (ret != MINICONTROL_ERROR_NONE) {
138 ERR("minicontrol_viewer_unset_event_cb failed: %s", get_error_message(ret));
140 EINA_LIST_FREE(active_minicontroller, info) {
141 _minicontroller_destroy(info);
143 active_minicontroller = NULL;
148 static int _lockscreen_minicontroller_search(const void *data1, const void *data2)
150 const minicontroller_info_t *info = data1;
151 const char *name = data2;
152 return strcmp(name, info->name);
155 Evas_Object *lockscreen_minicontrollers_minicontroller_create(const char *name, Evas_Object *parent)
157 minicontroller_info_t *info = eina_list_search_unsorted(active_minicontroller, _lockscreen_minicontroller_search, name);
160 ERR("Invalid minicontroller name: %s", name);
164 Evas_Object *ret = minicontrol_viewer_add(parent, info->name);
165 evas_object_size_hint_min_set(ret, info->width, info->height);
166 evas_object_show(ret);
170 Eina_List *lockscreen_minicontrollers_list_get(void)
172 Eina_List *ret = NULL, *l;
173 minicontroller_info_t *info;
175 EINA_LIST_FOREACH(active_minicontroller, l, info) {
176 ret = eina_list_append(ret, info->name);
181 bool lockscreen_minicontrollers_minicontroller_stop(const char *name)
183 int ret = minicontrol_viewer_send_event(name, MINICONTROL_VIEWER_EVENT_HIDE, NULL);
184 if (ret != MINICONTROL_ERROR_NONE) {
185 ERR("minicontrol_viewer_send_event failed: %s", get_error_message(ret));