apply FSL(Flora Software License)
[apps/core/preloaded/taskmanager.git] / src / _info.c
1  /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
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
7   *
8   *     http://www.tizenopensource.org/license
9   *
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.
15   */
16
17
18 #include <stdio.h>
19
20 #include <appcore-common.h>
21
22 #include "taskmanager.h"
23 #include "_util_log.h"
24 #include "_util_efl.h"
25
26 static void ctxpopup_clear(void *data)
27 {
28         struct appdata *ad = data;
29
30         retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
31
32         if (ad->info_timer) {
33                 ecore_timer_del(ad->info_timer);
34                 ad->info_timer = NULL;
35         }
36
37         if (ad->info_ctxpopup) {
38                 evas_object_del(ad->info_ctxpopup);
39                 ad->info_ctxpopup = NULL;
40         }
41
42 }
43
44 static void label_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
45 {
46         Evas_Object *ly = (Evas_Object *)data;
47         Evas_Coord w, h;
48         Evas_Coord pw, ph;
49
50         retm_if(ly == NULL, "Invalid argument: Evas_Object is NULL\n");
51
52         edje_object_part_geometry_get(_EDJ(ly),
53                         "padding/t", NULL, NULL, &pw, &ph);
54         evas_object_geometry_get(obj, NULL, NULL, &w, &h);
55         evas_object_size_hint_min_set(ly, (w + ph * 2), (h + ph * 2));
56 }
57
58 static void _ctxpopup_hide_cb(void *data, Evas_Object *obj, void *event_info)
59 {
60         struct appdata *ad = (struct appdata *)data;
61         ctxpopup_clear(ad);
62 }
63
64 int _util_move_ctxpopup(Evas_Object *eo, Evas_Object *target)
65 {
66         double scale;
67         Evas_Coord tx, ty, tw, th;
68         Evas_Coord cx, cy;
69
70         retvm_if(eo == NULL, -1, "Invalid argument: ctxpopup is NULL\n");
71
72         scale = elm_config_scale_get();
73
74         evas_object_geometry_get(target, &tx, &ty, &tw, &th);
75
76         cx = tx + (int)(tw * 0.5);
77         cy = ty + (int)(10.0 * scale);
78
79         evas_object_move(eo, cx, cy);
80
81         return 0;
82 }
83
84 static Eina_Bool info_hide_cb(void *data)
85 {
86         struct appdata *ad = data;
87
88         ctxpopup_clear(ad);
89
90         return ECORE_CALLBACK_CANCEL;
91 }
92
93 void create_info_ctxpopup(void *data, Evas_Object *obj, void *event_info)
94 {
95         struct appdata *ad = (struct appdata *)data;
96         Evas_Object *lb, *ly;
97         double scale = 0.0;
98         char buf[128] = {0, };
99
100         retm_if(data == NULL, "Invalid argument: appdata is NULL\n");
101
102         if (ad->info_ctxpopup) {
103                 evas_object_del(ad->info_ctxpopup);
104                 ad->info_ctxpopup = NULL;
105         }
106
107         scale = elm_config_scale_get();
108
109         ad->info_ctxpopup = _add_ctxpopup(ad->win);
110         evas_object_smart_callback_add(ad->info_ctxpopup, "dismissed",
111                                        _ctxpopup_hide_cb, ad);
112
113         ly = _add_layout(ad->info_ctxpopup, EDJ_NAME, "info");
114         evas_object_resize(ly, (int)(240.0 * scale), (int)(105.0 * scale));
115         elm_object_content_set(ad->info_ctxpopup, ly);
116
117         snprintf(buf, sizeof(buf),
118                         "<font_size=22>%s<font_size>", _("IDS_TASKMGR_INFO_MESSAGE"));
119         lb = _add_label(ly, buf);
120         evas_object_event_callback_add(lb, EVAS_CALLBACK_RESIZE,
121                                        label_resize_cb, ly);
122         elm_layout_content_set(ly, "swallow", lb);
123
124         _util_move_ctxpopup(ad->info_ctxpopup, ad->info_btn);
125
126         ad->info_timer = ecore_timer_add(3, info_hide_cb, ad);
127
128         evas_object_show(ad->info_ctxpopup);
129 }
130
131