2 * Copyright 2012 Samsung Electronics Co., Ltd
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
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.
17 #include <Elementary.h>
21 #include "list_util.h"
23 #define E_DATA_ITEM_LABEL_H "QP_ITEM_DATA"
25 struct _qp_item_data {
30 HAPI qp_item_data *quickpanel_list_util_item_new(qp_item_type_e type, void *data)
32 qp_item_data *qid = NULL;
34 qid = malloc(sizeof(struct _qp_item_data));
36 ERR("fail to alloc qid");
46 HAPI void quickpanel_list_util_item_set_tag(Evas_Object *item, qp_item_data *qid)
48 retif(item == NULL, , "invalid parameter");
49 retif(qid == NULL, , "invalid parameter");
51 evas_object_data_set(item, E_DATA_ITEM_LABEL_H, qid);
54 HAPI void quickpanel_list_util_item_del_tag(Evas_Object *item)
56 retif(item == NULL, , "invalid parameter");
58 qp_item_data *qid = evas_object_data_get(item, E_DATA_ITEM_LABEL_H);
61 evas_object_data_del(item, E_DATA_ITEM_LABEL_H);
66 HAPI void *quickpanel_list_util_item_get_data(qp_item_data *qid)
68 void *user_data = NULL;
73 user_data = qid->data;
78 HAPI void quickpanel_list_util_item_set_data(qp_item_data *qid, void *data)
86 HAPI int quickpanel_list_util_item_compare(const void *data1, const void *data2)
89 qp_item_data *qid1 = NULL;
90 qp_item_data *qid2 = NULL;
91 const Evas_Object *eo1 = data1;
92 const Evas_Object *eo2 = data2;
104 qid1 = evas_object_data_get(eo1, E_DATA_ITEM_LABEL_H);
105 qid2 = evas_object_data_get(eo2, E_DATA_ITEM_LABEL_H);
108 INFO("qid1 is NULL");
113 INFO("qid2 is NULL");
117 /* elm_genlist sort is not working as i expected */
118 if (qid1->type == qid2->type)
121 diff = qid1->type - qid2->type;
125 HAPI void quickpanel_list_util_item_unpack_by_type(Evas_Object *list
126 , qp_item_type_e type)
128 retif(list == NULL, , "invalid parameter");
133 Eina_List *item_list = elm_box_children_get(list);
135 EINA_LIST_FOREACH_SAFE(item_list, l, l_next, obj)
138 // call deleted callback
139 qp_item_data *qid = evas_object_data_get(obj, E_DATA_ITEM_LABEL_H);
141 if (qid->type == type) {
142 elm_box_unpack(list, obj);
149 HAPI void quickpanel_list_util_item_unpack_by_object(Evas_Object *list
152 retif(list == NULL, , "invalid parameter");
153 retif(item == NULL, , "invalid parameter");
155 elm_box_unpack(list, item);
158 static int __item_compare(const void *data1, const void *data2)
161 const Evas_Object *eo1 = data1;
162 const qp_item_data *qid1 = NULL;
163 const qp_item_data *qid2 = data2;
166 INFO("data1 is NULL");
171 INFO("data2 is NULL");
175 qid1 = evas_object_data_get(eo1, E_DATA_ITEM_LABEL_H);
178 INFO("qid1 is NULL");
182 diff = qid1->type - qid2->type;
188 HAPI void quickpanel_list_util_sort_insert(Evas_Object *list,
189 Evas_Object *new_obj)
191 retif(list == NULL, , "invalid parameter");
192 retif(new_obj == NULL, , "invalid parameter");
196 Evas_Object *obj = NULL;
197 Evas_Object *first = NULL;
198 Eina_List *item_list = elm_box_children_get(list);
199 qp_item_data *item_data = NULL;
201 item_data = evas_object_data_get(new_obj, E_DATA_ITEM_LABEL_H);
202 retif(item_data == NULL, , "invalid parameter");
204 INFO("current entry count in list:%d", eina_list_count(item_list));
205 EINA_LIST_FOREACH_SAFE(item_list, l, l_next, obj)
208 if (__item_compare(obj, item_data) >= 0)
216 elm_box_pack_start(list, new_obj);
218 elm_box_pack_after(list, new_obj, first);