[Tizen 3.0] 2.4 source code merge
[apps/core/preloaded/quickpanel.git] / daemon / service / animated_icon.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 <Elementary.h>
19 #include <tzsh.h>
20 #include <tzsh_quickpanel_service.h>
21 #include <E_DBus.h>
22
23 #include "quickpanel-ui.h"
24 #include "common.h"
25 #include "quickpanel_def.h"
26 #include "animated_icon.h"
27
28 #define E_DATA_ANI_ICON_TYPE "ANI_ICON_TYPE"
29 #define PATH_DOWNLOAD "reserved://quickpanel/ani/downloading"
30 #define PATH_UPLOAD "reserved://quickpanel/ani/uploading"
31 #define PATH_INSTALL "reserved://quickpanel/ani/install"
32
33 static qp_animated_icon_type _animated_type_get(const char *path)
34 {
35         retif_nomsg(path == NULL, QP_ANIMATED_ICON_NONE);
36
37         if (strncasecmp(path, PATH_DOWNLOAD, MIN(strlen(PATH_DOWNLOAD), strlen(path))) == 0) {
38                 return QP_ANIMATED_ICON_DOWNLOAD;
39         } else if (strncasecmp(path, PATH_UPLOAD, MIN(strlen(PATH_UPLOAD), strlen(path))) == 0) {
40                 return QP_ANIMATED_ICON_UPLOAD;
41         } else if (strncasecmp(path, PATH_INSTALL, MIN(strlen(PATH_INSTALL), strlen(path))) == 0) {
42                 return QP_ANIMATED_ICON_INSTALL;
43         }
44
45         return QP_ANIMATED_ICON_NONE;
46 }
47
48 HAPI Evas_Object *quickpanel_animated_icon_get(Evas_Object *parent, const char *path)
49 {
50         qp_animated_icon_type type = QP_ANIMATED_ICON_NONE;
51         const char *layout_icon = NULL;
52         Evas_Object *layout = NULL;
53         retif_nomsg(parent == NULL, NULL);
54         retif_nomsg(path == NULL, NULL);
55
56         type = _animated_type_get(path);
57
58         if (type == QP_ANIMATED_ICON_DOWNLOAD) {
59                 layout_icon = "quickpanel/animated_icon_download";
60         } else if (type == QP_ANIMATED_ICON_UPLOAD) {
61                 layout_icon = "quickpanel/animated_icon_upload";
62         } else if (type == QP_ANIMATED_ICON_INSTALL) {
63                 layout_icon = "quickpanel/animated_icon_install";
64         } else {
65                 return NULL;
66         }
67
68         layout = elm_layout_add(parent);
69         if (layout != NULL) {
70                 elm_layout_file_set(layout, DEFAULT_EDJ, layout_icon);
71                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
72                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
73                 evas_object_data_set(layout, E_DATA_ANI_ICON_TYPE, (void *)type);
74                 evas_object_show(layout);
75         }
76
77         return layout;
78 }
79
80 HAPI int quickpanel_animated_icon_is_same_icon(Evas_Object *view, const char *path)
81 {
82         qp_animated_icon_type type = QP_ANIMATED_ICON_NONE;
83         qp_animated_icon_type type_old = QP_ANIMATED_ICON_NONE;
84         retif_nomsg(view == NULL, 0);
85         retif_nomsg(path == NULL, 0);
86
87         type = _animated_type_get(path);
88         type_old = (qp_animated_icon_type)evas_object_data_get(view,
89                         E_DATA_ANI_ICON_TYPE);
90
91         if (type == type_old) {
92                 return 1;
93         }
94
95         return 0;
96 }