The source code moved from the SPIN with license changed to Flora 1.1
[apps/native/home/homescreen-efl.git] / src / app_item.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://floralicense.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 "homescreen-efl.h"
18 #include "app_item.h"
19 #include "app_mgr.h"
20
21 static struct
22 {
23         int unique_id;
24 } s_app_item_info = {
25         .unique_id = -1
26 };
27
28 HAPI app_item_t *app_item_create(const app_item_type_t type, const int unique_id,
29                                 const char *label, const char *icon, const char *exec,
30                                 const char *appid, void *data, bool is_removeable,
31                                 int col, int row, int col_span, int row_span,
32                                 const char *content_info)
33 {
34         app_item_t *item = (app_item_t *)calloc(1, sizeof(app_item_t));
35
36         if (!item) {
37                 dlog_print(DLOG_ERROR, LOG_TAG, "[ALLOC_FAILED]");
38                 return NULL;
39         }
40
41         item->type = type;
42         if (unique_id < 0) {
43                 item->unique_id = ++s_app_item_info.unique_id;
44         } else {
45                 item->unique_id = unique_id;
46                 s_app_item_info.unique_id = s_app_item_info.unique_id > unique_id ? s_app_item_info.unique_id : unique_id;
47         }
48
49         if (label)
50                 item->label = strdup(label);
51         if (icon)
52                 item->icon = strdup(icon);
53         if (exec)
54                 item->exec = strdup(exec);
55         if (appid)
56                 item->appid = strdup(appid);
57         if (content_info)
58                 item->content_info = strdup(content_info);
59
60         item->badge_count = 0;
61         item->data = data;
62         item->removable = is_removeable;
63         item->is_checked = false;
64         item->layout = NULL;
65         item->grid_item = NULL;
66
67         item->col = col;
68         item->row = row;
69         item->col_span = col_span;
70         item->row_span = row_span;
71
72
73         return item;
74 }
75
76 HAPI void app_item_free(app_item_t *item)
77 {
78         if (!item)
79                 return;
80
81         free((void *)item->label);
82         free((void *)item->icon);
83         free((void *)item->exec);
84         free((void *)item->appid);
85         free((void *)item->content_info);
86
87         free(item);
88 }
89
90 HAPI void app_item_geometry_update(app_item_t *app_item, int x, int y, int w, int h)
91 {
92         if (!app_item) {
93                 LOGE("app_item == NULL");
94                 return;
95         }
96
97         app_item->col = x;
98         app_item->row = y;
99         app_item->col_span = w;
100         app_item->row_span = h;
101 }
102
103 HAPI void app_item_update_content_info(app_item_t *app_item, const char *content_info)
104 {
105         if (!app_item) {
106                 LOGE("app_item == NULL");
107                 return;
108         }
109
110         if (app_item->content_info)
111                 free(app_item->content_info);
112
113         if (content_info) {
114                 app_item->content_info = strdup(content_info);
115         } else {
116                 app_item->content_info = NULL;
117         }
118 }
119
120