45024fe9cedd84e58d8529c22303b9d76a243fd8
[apps/core/preloaded/quickpanel.git] / daemon / notifications / animated_image.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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 #include "animated_image.h"
18
19 static int quickpanel_animated_image_init(void *data);
20 static int quickpanel_animated_image_fini(void *data);
21 static int quickpanel_animated_image_suspend(void *data);
22 static int quickpanel_animated_image_resume(void *data);
23
24 QP_Module animated_image = {
25         .name = "animated_image",
26         .init = quickpanel_animated_image_init,
27         .fini = quickpanel_animated_image_fini,
28         .suspend = quickpanel_animated_image_suspend,
29         .resume = quickpanel_animated_image_resume,
30         .lang_changed = NULL,
31         .refresh = NULL
32 };
33
34 static Eina_List *g_animated_image_list = NULL;
35
36 static void _animated_image_list_add(Evas_Object *image)
37 {
38         retif(image == NULL, ,"invalid parameter");
39
40         g_animated_image_list = eina_list_append(g_animated_image_list, image);
41 }
42
43 static void _animated_image_play(Eina_Bool on)
44 {
45         const Eina_List *l = NULL;
46         const Eina_List *ln = NULL;
47         Evas_Object *entry_obj = NULL;
48
49         retif(g_animated_image_list == NULL, ,"list is empty");
50
51         EINA_LIST_FOREACH_SAFE(g_animated_image_list, l, ln, entry_obj) {
52                 if (entry_obj == NULL) continue;
53
54                 if (on == EINA_TRUE) {
55                         if (elm_image_animated_play_get(entry_obj) == EINA_FALSE) {
56                                 elm_image_animated_play_set(entry_obj, EINA_TRUE);
57                         }
58                 } else {
59                         if (elm_image_animated_play_get(entry_obj) == EINA_TRUE) {
60                                 elm_image_animated_play_set(entry_obj, EINA_FALSE);
61                         }
62                 }
63         }
64 }
65
66 static void _animated_image_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
67 {
68         retif(obj == NULL, , "obj is NULL");
69         retif(g_animated_image_list == NULL, , "list is empty");
70
71         g_animated_image_list = eina_list_remove(g_animated_image_list, obj);
72 }
73
74 HAPI void quickpanel_animated_image_add(Evas_Object *image) {
75         retif(image == NULL, , "image is NULL");
76
77         if (elm_image_animated_available_get(image) == EINA_TRUE) {
78                 elm_image_animated_set(image, EINA_TRUE);
79                 if (quickpanel_is_suspended() == 0) {
80                         elm_image_animated_play_set(image, EINA_TRUE);
81                 } else {
82                         elm_image_animated_play_set(image, EINA_FALSE);
83                 }
84                 _animated_image_list_add(image);
85                 evas_object_event_callback_add(image, EVAS_CALLBACK_DEL, _animated_image_deleted_cb, NULL);
86         }
87 }
88
89 /*****************************************************************************
90  *
91  * Util functions
92  *
93  *****************************************************************************/
94 static int quickpanel_animated_image_init(void *data)
95 {
96         return QP_OK;
97 }
98
99 static int quickpanel_animated_image_fini(void *data)
100 {
101         return QP_OK;
102 }
103
104 static int quickpanel_animated_image_suspend(void *data)
105 {
106         struct appdata *ad = data;
107         retif(ad == NULL, QP_FAIL, "Invalid parameter!");
108
109         INFO("animated image going to be suspened");
110         _animated_image_play(EINA_FALSE);
111
112         return QP_OK;
113 }
114
115 static int quickpanel_animated_image_resume(void *data)
116 {
117         struct appdata *ad = data;
118         retif(ad == NULL, QP_FAIL, "Invalid parameter!");
119
120         INFO("animated image going to be resumed");
121         _animated_image_play(EINA_TRUE);
122
123         return QP_OK;
124 }