2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://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.
19 #include <minicontrol-viewer.h>
20 #include <minicontrol-monitor.h>
23 #include "quickpanel-ui.h"
24 #include "list_util.h"
25 #include "quickpanel_debug_util.h"
27 #define QP_R_MARGIN 12
28 #define MINICONTROL_WIDTH_P_MAX 692
29 #define MINICONTROL_WIDTH_L_MAX 1252
31 #define MINICONTROL_TYPE_STR_ONGOING "_ongoing]"
33 static int quickpanel_minictrl_init(void *data);
34 static int quickpanel_minictrl_fini(void *data);
35 static int quickpanel_minictrl_suspend(void *data);
36 static int quickpanel_minictrl_resume(void *data);
38 QP_Module minictrl = {
40 .init = quickpanel_minictrl_init,
41 .fini = quickpanel_minictrl_fini,
42 .suspend = quickpanel_minictrl_suspend,
43 .resume = quickpanel_minictrl_resume,
55 minicontrol_priority_e priority;
60 GHashTable *g_prov_table;
62 static void _viewer_freeze(Evas_Object *viewer)
64 int freezed_count = 0;
65 retif(viewer == NULL, , "Invalid parameter!");
67 freezed_count = elm_object_scroll_freeze_get(viewer);
69 if (freezed_count <= 0) {
70 elm_object_scroll_freeze_push(viewer);
74 static void _viewer_unfreeze(Evas_Object *viewer)
76 int i = 0, freezed_count = 0;
77 retif(viewer == NULL, , "Invalid parameter!");
79 freezed_count = elm_object_scroll_freeze_get(viewer);
81 for (i = 0 ; i < freezed_count; i++) {
82 elm_object_scroll_freeze_pop(viewer);
86 static Evas_Object *_get_minictrl_obj(Evas_Object *layout) {
87 retif(layout == NULL, NULL, "Invalid parameter!");
89 return elm_object_part_content_get(layout, "elm.icon");
92 static void _viewer_set_size(Evas_Object *layout, void *data, int width, int height)
94 Evas_Object *viewer = NULL;
95 retif(layout == NULL, , "Invalid parameter!");
96 retif(data == NULL, , "Invalid parameter!");
97 retif(width < 0, , "Invalid parameter!");
98 retif(height < 0, , "Invalid parameter!");
99 struct appdata *ad = data;
101 int resized_width = 0;
103 viewer = _get_minictrl_obj(layout);
104 retif(viewer == NULL, , "Invalid parameter!");
106 if (ad->angle == 90 || ad->angle == 270) {
107 max_width = (ad->scale * MINICONTROL_WIDTH_L_MAX) - 1;
109 max_width = (ad->scale * MINICONTROL_WIDTH_P_MAX) - 1;
111 resized_width = (width > max_width) ? max_width : width;
113 DBG("resize:%d %d", resized_width, height);
115 evas_object_size_hint_min_set(viewer, resized_width, height);
118 static void _viewer_item_free(struct _viewer_item *item)
120 struct appdata *ad = quickpanel_get_app_data();
121 retif(ad == NULL, , "Invalid parameter!");
122 retif(ad->list == NULL, , "Invalid parameter!");
123 retif(item == NULL, , "Invalid parameter!");
130 evas_object_unref(item->viewer);
132 quickpanel_list_util_item_unpack_by_object(ad->list, item->viewer);
133 quickpanel_list_util_item_del_tag(item->viewer);
134 evas_object_del(item->viewer);
140 static Evas_Object *_minictrl_create_view(struct appdata *ad, const char *name)
142 retif(ad == NULL, NULL, "Invalid parameter!");
143 retif(ad->list == NULL, NULL, "Invalid parameter!");
144 retif(name == NULL, NULL, "Invalid parameter!");
146 Evas_Object *layout = NULL;
148 layout = elm_layout_add(ad->list);
151 elm_layout_file_set(layout, DEFAULT_EDJ,
152 "quickpanel/minictrl/default");
154 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
156 evas_object_show(layout);
158 Evas_Object *viewer = minicontrol_viewer_add(layout, name);
160 ERR("fail to add viewer - %s", name);
164 evas_object_ref(viewer);
166 elm_object_part_content_set(layout, "elm.icon", viewer);
171 static int _minictrl_is_ongoing(const char *str)
173 if (str == NULL) return 0;
175 if (strstr(str, MINICONTROL_TYPE_STR_ONGOING) != NULL) {
182 qp_item_type_e _minictrl_priority_to_type(minicontrol_priority_e priority)
187 case MINICONTROL_PRIORITY_TOP:
188 type = QP_ITEM_TYPE_MINICTRL_TOP;
190 case MINICONTROL_PRIORITY_MIDDLE:
191 type = QP_ITEM_TYPE_MINICTRL_MIDDLE;
193 case MINICONTROL_PRIORITY_LOW:
195 type = QP_ITEM_TYPE_MINICTRL_LOW;
202 static void _minictrl_release_cb(void *data, Evas *e,
203 Evas_Object *obj, void *event_info) {
205 retif(!data, , "data is NULL");
209 _viewer_unfreeze(ad->scroller);
212 static void _minictrl_add(const char *name, unsigned int width,
214 minicontrol_priority_e priority,
217 qp_item_data *qid = NULL;
218 struct _viewer_item *vit = NULL;
221 Evas_Object *viewer = NULL;
223 retif(!name, , "name is NULL");
224 retif(!data, , "data is NULL");
227 retif(!ad->list, , "list is NULL");
230 struct _viewer_item *found = NULL;
231 found = g_hash_table_lookup(g_prov_table, name);
234 ERR("already have it : %s", name);
238 ERR("g_prov_table is NULL");
242 /* elm_plug receives 'server_del' event,
243 * if it repeats connect and disconnect frequently.
246 viewer = _minictrl_create_view(ad, name);
247 _viewer_set_size(viewer, ad, width, height);
249 evas_object_event_callback_add(_get_minictrl_obj(viewer), EVAS_CALLBACK_MOUSE_UP,
250 _minictrl_release_cb, ad);
252 vit = malloc(sizeof(struct _viewer_item));
254 ERR("fail to alloc vit");
255 evas_object_del(viewer);
259 if (_minictrl_is_ongoing(name) == 1) {
260 DBG("QP_ITEM_TYPE_MINICTRL_ONGOING is added");
261 type = QP_ITEM_TYPE_MINICTRL_ONGOING;
263 type = _minictrl_priority_to_type(priority);
265 qid = quickpanel_list_util_item_new(type, vit);
267 ERR("fail to alloc vit");
268 evas_object_del(viewer);
272 vit->name = strdup(name);
274 vit->height = height;
275 vit->priority = priority;
276 vit->viewer = viewer;
278 quickpanel_list_util_item_set_tag(vit->viewer, qid);
279 quickpanel_list_util_sort_insert(ad->list, vit->viewer);
281 g_hash_table_insert(g_prov_table, g_strdup(name), vit);
283 INFO("success to add %s", name);
286 static void _minictrl_remove(const char *name, void *data)
289 if (g_hash_table_remove(g_prov_table, name))
291 INFO("success to remove %s", name);
293 retif(data == NULL, , "data is NULL");
296 WARN("unknown provider name : %s", name);
300 static void _minictrl_update(const char *name, unsigned int width,
301 unsigned int height, void *data)
303 struct _viewer_item *found = NULL;
304 struct appdata *ad = NULL;
309 retif(!data, , "data is NULL");
312 found = g_hash_table_lookup(g_prov_table, name);
315 WARN("unknown provider name : %s", name);
319 found->width = width;
320 found->height = height;
323 _viewer_set_size(found->viewer, ad, width, height);
327 static void _minictrl_request(const char *name, int action, void *data)
329 struct appdata *ad = NULL;
330 retif(!name, , "name is NULL");
331 retif(!data, , "data is NULL");
334 if (action == MINICONTROL_REQ_HIDE_VIEWER) {
335 quickpanel_close_quickpanel(true);
337 if (action == MINICONTROL_REQ_FREEZE_SCROLL_VIEWER) {
338 if (ad->list != NULL) {
339 ERR("freezed by %s", name);
340 _viewer_freeze(ad->scroller);
343 if (action == MINICONTROL_REQ_UNFREEZE_SCROLL_VIEWER) {
344 if (ad->list != NULL) {
345 ERR("unfreezed by %s", name);
346 _viewer_unfreeze(ad->scroller);
351 static void _mctrl_monitor_cb(minicontrol_action_e action,
352 const char *name, unsigned int width,
354 minicontrol_priority_e priority,
357 retif(!data, , "data is NULL");
358 retif(!name, , "name is NULL");
361 case MINICONTROL_ACTION_START:
362 _minictrl_add(name, width, height, priority, data);
364 case MINICONTROL_ACTION_RESIZE:
365 _minictrl_update(name, width, height, data);
367 case MINICONTROL_ACTION_STOP:
368 _minictrl_remove(name, data);
370 case MINICONTROL_ACTION_REQUEST:
371 _minictrl_request(name, width, data);
378 static int quickpanel_minictrl_init(void *data)
380 minicontrol_error_e ret;
382 retif(!data, QP_FAIL, "Invalid parameter!");
384 g_prov_table = g_hash_table_new_full(g_str_hash, g_str_equal,
385 (GDestroyNotify)g_free,
386 (GDestroyNotify)_viewer_item_free);
388 ret = minicontrol_monitor_start(_mctrl_monitor_cb, data);
389 if (ret != MINICONTROL_ERROR_NONE) {
390 ERR("fail to minicontrol_monitor_start()- %d", ret);
397 static int quickpanel_minictrl_fini(void *data)
399 minicontrol_error_e ret;
400 ret = minicontrol_monitor_stop();
401 if (ret != MINICONTROL_ERROR_NONE)
402 ERR("fail to minicontrol_monitor_stop()- %d", ret);
405 g_hash_table_remove_all(g_prov_table);
412 static int quickpanel_minictrl_suspend(void *data)
414 struct appdata *ad = data;
415 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
417 if (ad->list != NULL) {
418 _viewer_unfreeze(ad->scroller);
424 static int quickpanel_minictrl_resume(void *data)
426 struct appdata *ad = data;
427 retif(ad == NULL, QP_FAIL, "Invalid parameter!");
429 if (ad->list != NULL) {
430 _viewer_unfreeze(ad->scroller);