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 unsigned int quickpanel_minictrl_get_height(void *data);
37 QP_Module minictrl = {
39 .init = quickpanel_minictrl_init,
40 .fini = quickpanel_minictrl_fini,
47 .get_height = quickpanel_minictrl_get_height,
54 minicontrol_priority_e priority;
60 GHashTable *g_prov_table;
62 static void _viewer_set_size(Evas_Object *viewer, void *data, int width, int height)
64 retif(viewer == NULL, , "Invalid parameter!");
65 retif(data == NULL, , "Invalid parameter!");
66 retif(width < 0, , "Invalid parameter!");
67 retif(height < 0, , "Invalid parameter!");
68 struct appdata *ad = data;
70 int resized_width = 0;
72 DBG("mini w:%d h:%d", width, height);
74 if (ad->angle == 90 || ad->angle == 270) {
75 max_width = (ad->scale * MINICONTROL_WIDTH_L_MAX) - 1;
77 max_width = (ad->scale * MINICONTROL_WIDTH_P_MAX) - 1;
79 resized_width = (width > max_width) ? max_width : width;
80 evas_object_size_hint_min_set(viewer, resized_width, height);
83 static void _viewer_item_free(struct _viewer_item *item)
92 elm_object_item_del(item->it);
95 evas_object_unref(item->viewer);
96 evas_object_del(item->viewer);
103 static Evas_Object *_minictrl_load_viewer(Evas_Object *parent,
104 struct _viewer_item *item)
106 Evas_Object *viewer = NULL;
109 ERR("parent is NULL");
119 ERR("item name is NULL");
123 viewer = minicontrol_viewer_add(parent, item->name);
125 ERR("fail to create viewer for [%s]", item->name);
129 evas_object_size_hint_min_set(viewer, item->width - QP_R_MARGIN , item->height);
135 static Evas_Object *_minictrl_gl_get_content(void *data, Evas_Object * obj,
138 Evas_Object *content = NULL;
139 qp_item_data *qid = NULL;
140 struct _viewer_item *item = NULL;
142 retif(data == NULL, NULL, "Invalid parameter!");
145 item = quickpanel_list_util_item_get_data(qid);
146 retif(!item, NULL, "item is NULL");
148 if (strcmp(part, "elm.icon") == 0)
149 content = item->viewer;
155 static Eina_Bool _minictrl_gl_get_state(void *data, Evas_Object *obj,
161 static void _minictrl_gl_del(void *data, Evas_Object *obj)
164 quickpanel_list_util_del_count(data);
171 static Elm_Genlist_Item_Class *_minictrl_gl_style_get(void)
173 Elm_Genlist_Item_Class *itc = NULL;
175 itc = elm_genlist_item_class_new();
177 ERR("fail to elm_genlist_item_class_new()");
181 itc->item_style = "minicontrol/default";
182 itc->func.text_get = NULL;
183 itc->func.content_get = _minictrl_gl_get_content;
184 itc->func.state_get = _minictrl_gl_get_state;
185 itc->func.del = _minictrl_gl_del;
190 static int _minictrl_is_ongoing(const char *str)
192 if (str == NULL) return 0;
194 if (strstr(str, MINICONTROL_TYPE_STR_ONGOING) != NULL) {
201 qp_item_type_e _minictrl_priority_to_type(minicontrol_priority_e priority)
206 case MINICONTROL_PRIORITY_TOP:
207 type = QP_ITEM_TYPE_MINICTRL_TOP;
209 case MINICONTROL_PRIORITY_MIDDLE:
210 type = QP_ITEM_TYPE_MINICTRL_MIDDLE;
212 case MINICONTROL_PRIORITY_LOW:
214 type = QP_ITEM_TYPE_MINICTRL_LOW;
221 static void _minictrl_add(const char *name, unsigned int width,
223 minicontrol_priority_e priority,
226 qp_item_data *qid = NULL;
227 Elm_Genlist_Item_Class *itc = NULL;
228 struct _viewer_item *vit = NULL;
231 Evas_Object *viewer = NULL;
233 retif(!name, , "name is NULL");
234 retif(!data, , "data is NULL");
237 retif(!ad->list, , "list is NULL");
240 struct _viewer_item *found = NULL;
241 found = g_hash_table_lookup(g_prov_table, name);
244 ERR("already have it : %s", name);
248 ERR("g_prov_table is NULL");
252 /* elm_plug receives 'server_del' event,
253 * if it repeats connect and disconnect frequently.
256 viewer = minicontrol_viewer_add(ad->list, name);
258 ERR("fail to add viewer - %s", name);
261 evas_object_ref(viewer);
262 _viewer_set_size(viewer, ad, width, height);
264 itc = _minictrl_gl_style_get();
266 ERR("fail to _minictrl_gl_style_get()");
267 evas_object_del(viewer);
271 vit = malloc(sizeof(struct _viewer_item));
273 ERR("fail to alloc vit");
274 evas_object_del(viewer);
275 elm_genlist_item_class_free(itc);
280 if (_minictrl_is_ongoing(name) == 1) {
281 DBG("QP_ITEM_TYPE_MINICTRL_ONGOING is added");
282 type = QP_ITEM_TYPE_MINICTRL_ONGOING;
284 type = _minictrl_priority_to_type(priority);
286 qid = quickpanel_list_util_item_new(type, vit);
288 ERR("fail to alloc vit");
289 evas_object_del(viewer);
290 elm_genlist_item_class_free(itc);
294 vit->name = strdup(name);
296 vit->height = height;
297 vit->priority = priority;
298 vit->viewer = viewer;
300 vit->it = quickpanel_list_util_sort_insert(ad->list, itc, qid, NULL,
301 ELM_GENLIST_ITEM_NONE, NULL, NULL);
303 g_hash_table_insert(g_prov_table, g_strdup(name), vit);
305 INFO("success to add %s", name);
307 elm_genlist_item_class_free(itc);
309 quickpanel_ui_update_height(ad);
312 static void _minictrl_remove(const char *name, void *data)
315 if (g_hash_table_remove(g_prov_table, name))
317 INFO("success to remove %s", name);
319 retif(data == NULL, , "data is NULL");
320 quickpanel_ui_update_height(data);
323 WARN("unknown provider name : %s", name);
327 static void _minictrl_update(const char *name, unsigned int width,
328 unsigned int height, void *data)
330 struct _viewer_item *found = NULL;
331 struct appdata *ad = NULL;
336 retif(!data, , "data is NULL");
339 found = g_hash_table_lookup(g_prov_table, name);
342 WARN("unknown provider name : %s", name);
346 found->width = width;
347 found->height = height;
350 _viewer_set_size(found->viewer, ad, width, height);
354 elm_genlist_item_update(found->it);
355 quickpanel_ui_update_height(ad);
359 static void _minictrl_request(const char *name, int action, void *data)
362 struct appdata *ad = NULL;
363 retif(!name, , "name is NULL");
364 retif(!data, , "data is NULL");
367 if (action == MINICONTROL_REQ_HIDE_VIEWER) {
368 xwin = elm_win_xwindow_get(ad->win);
370 DBG("close by minictrl:%s", name);
371 debug_printf("close by minictrl:%s", name);
372 ecore_x_e_illume_quickpanel_state_send(ecore_x_e_illume_zone_get(xwin),ECORE_X_ILLUME_QUICKPANEL_STATE_OFF);
377 static void _mctrl_monitor_cb(minicontrol_action_e action,
378 const char *name, unsigned int width,
380 minicontrol_priority_e priority,
383 retif(!data, , "data is NULL");
384 retif(!name, , "name is NULL");
387 case MINICONTROL_ACTION_START:
388 _minictrl_add(name, width, height, priority, data);
390 case MINICONTROL_ACTION_RESIZE:
391 _minictrl_update(name, width, height, data);
393 case MINICONTROL_ACTION_STOP:
394 _minictrl_remove(name, data);
396 case MINICONTROL_ACTION_REQUEST:
397 _minictrl_request(name, width, data);
404 static int quickpanel_minictrl_init(void *data)
406 minicontrol_error_e ret;
408 retif(!data, QP_FAIL, "Invalid parameter!");
410 g_prov_table = g_hash_table_new_full(g_str_hash, g_str_equal,
411 (GDestroyNotify)g_free,
412 (GDestroyNotify)_viewer_item_free);
414 ret = minicontrol_monitor_start(_mctrl_monitor_cb, data);
415 if (ret != MINICONTROL_ERROR_NONE) {
416 ERR("fail to minicontrol_monitor_start()- %d", ret);
423 static int quickpanel_minictrl_fini(void *data)
425 minicontrol_error_e ret;
426 ret = minicontrol_monitor_stop();
427 if (ret != MINICONTROL_ERROR_NONE)
428 ERR("fail to minicontrol_monitor_stop()- %d", ret);
431 g_hash_table_remove_all(g_prov_table);
439 static void _quickpanel_minictrl_hf_sum_height(gpointer key, gpointer value, gpointer data)
441 struct _viewer_item *item = value;
443 if (item != NULL && data != NULL) {
444 *((unsigned int *)data) += item->height;
448 static unsigned int quickpanel_minictrl_get_height(void *data)
450 unsigned int height_minictrl = 0;
452 if (g_prov_table != NULL) {
453 g_hash_table_foreach(g_prov_table, _quickpanel_minictrl_hf_sum_height, &height_minictrl);
456 return height_minictrl;