2 * Copyright 2012 Samsung Electronics Co., Ltd
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
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 struct _qp_item_data {
28 static qp_item_count g_qp_item_count = {
35 qp_item_data *quickpanel_list_util_item_new(qp_item_type_e type, void *data)
37 qp_item_data *qid = NULL;
39 qid = malloc(sizeof(struct _qp_item_data));
41 ERR("fail to alloc qid");
51 qp_item_type_e quickpanel_list_util_item_get_item_type(qp_item_data *qid)
53 qp_item_type_e item_type = QP_ITEM_TYPE_NONE;
56 return QP_ITEM_TYPE_NONE;
58 item_type = qid->type;
63 void *quickpanel_list_util_item_get_data(qp_item_data *qid)
65 void *user_data = NULL;
70 user_data = qid->data;
75 void quickpanel_list_util_item_set_data(qp_item_data *qid, void *data)
83 int quickpanel_list_util_item_compare(const void *data1, const void *data2)
86 qp_item_data *qid1 = NULL;
87 qp_item_data *qid2 = NULL;
88 const Elm_Object_Item *it1 = data1;
89 const Elm_Object_Item *it2 = data2;
101 qid1 = elm_object_item_data_get(it1);
102 qid2 = elm_object_item_data_get(it2);
105 INFO("qid1 is NULL");
110 INFO("qid2 is NULL");
114 /* elm_genlist sort is not working as i expected */
115 if (qid1->type == qid2->type)
118 diff = qid1->type - qid2->type;
122 void quickpanel_list_util_item_del_by_type(Evas_Object *list,
123 const Elm_Object_Item *refer_item,
126 const Elm_Object_Item *start_item = NULL;
132 start_item = refer_item;
134 start_item = elm_genlist_first_item_get(list);
137 qp_item_data *qid = NULL;
138 const Elm_Object_Item *next = NULL;
140 next = elm_genlist_item_next_get(start_item);
141 qid = elm_object_item_data_get(start_item);
143 ERR("fail to get qid, continue loop");
148 if (qid->type > type)
150 else if (qid->type == type)
151 elm_object_item_del((Elm_Object_Item *)start_item);
159 void quickpanel_list_util_item_update_by_type(Evas_Object *list,
160 Elm_Object_Item *refer_item,
163 Elm_Object_Item *start_item = NULL;
169 start_item = refer_item;
171 start_item = elm_genlist_first_item_get(list);
174 qp_item_data *qid = NULL;
175 Elm_Object_Item *next = NULL;
177 next = elm_genlist_item_next_get(start_item);
178 qid = elm_object_item_data_get(start_item);
180 ERR("fail to get qid, continue loop");
185 if (qid->type > type)
187 else if (qid->type == type) {
188 elm_genlist_item_fields_update(start_item, "*", ELM_GENLIST_ITEM_FIELD_ALL);
197 Elm_Object_Item *quickpanel_list_util_find_item_by_type(Evas_Object *list,
199 Elm_Object_Item *refer_item,
202 Elm_Object_Item *start_item = NULL;
203 Elm_Object_Item *found = NULL;
209 start_item = refer_item;
211 start_item = elm_genlist_first_item_get(list);
214 qp_item_data *qid = NULL;
215 Elm_Object_Item *next = NULL;
216 void *user_data = NULL;
218 next = elm_genlist_item_next_get(start_item);
219 qid = elm_object_item_data_get(start_item);
221 ERR("fail to get qid, continue loop");
226 if (qid->type > type)
228 else if (qid->type == type) {
229 user_data = quickpanel_list_util_item_get_data(qid);
230 if (user_data == data) {
242 static int __item_compare(const void *data1, const void *data2)
245 const Elm_Object_Item *it1 = data1;
246 const qp_item_data *qid1 = NULL;
247 const qp_item_data *qid2 = data2;
250 INFO("data1 is NULL");
255 INFO("data2 is NULL");
259 qid1 = elm_object_item_data_get(it1);
262 INFO("qid1 is NULL");
266 diff = qid1->type - qid2->type;
272 Elm_Object_Item *quickpanel_list_util_sort_insert(Evas_Object *list,
273 const Elm_Genlist_Item_Class *itc,
274 const void *item_data,
275 Elm_Object_Item *parent,
276 Elm_Genlist_Item_Type type,
278 const void *func_data)
280 Elm_Object_Item *it = NULL;
281 Elm_Object_Item *first = NULL;
283 retif(!list, NULL, "list is NULL");
284 retif(!itc, NULL, "itc is NULL");
285 retif(!item_data, NULL, "item_data is NULL");
287 first = elm_genlist_first_item_get(list);
289 if (__item_compare(first, item_data) >= 0)
292 first = elm_genlist_item_next_get(first);
296 it = elm_genlist_item_append(list, itc, item_data, parent,
297 type, func, func_data);
299 it = elm_genlist_item_insert_before(list, itc, item_data,
300 parent, first, type, func, func_data);
303 quickpanel_list_util_add_count((qp_item_data *)item_data);
309 qp_item_count *quickpanel_list_util_get_item_count(void)
311 return &g_qp_item_count;
314 void quickpanel_list_util_add_count(qp_item_data *qid)
316 retif(qid == NULL, , "qid is NULL");
320 case QP_ITEM_TYPE_ONGOING_NOTI:
321 g_qp_item_count.ongoing++;
323 case QP_ITEM_TYPE_NOTI_GROUP:
324 g_qp_item_count.group++;
326 case QP_ITEM_TYPE_NOTI:
327 g_qp_item_count.noti++;
329 case QP_ITEM_TYPE_MINICTRL_ONGOING:
330 case QP_ITEM_TYPE_MINICTRL_TOP:
331 case QP_ITEM_TYPE_MINICTRL_MIDDLE:
332 case QP_ITEM_TYPE_MINICTRL_LOW:
333 g_qp_item_count.minicontrol++;
335 case QP_ITEM_TYPE_NONE:
336 case QP_ITEM_TYPE_SETTING:
337 case QP_ITEM_TYPE_TOGGLE:
338 case QP_ITEM_TYPE_BRIGHTNESS:
339 case QP_ITEM_TYPE_MAX:
343 DBG("(type:%d)\nnum_ongoing:%d, num_group:%d, num_noti:%d, num_minicontrol:%d"
345 , g_qp_item_count.ongoing
346 , g_qp_item_count.group
347 , g_qp_item_count.noti
348 , g_qp_item_count.minicontrol);
351 void quickpanel_list_util_del_count(qp_item_data *qid)
353 retif(qid == NULL, , "qid is NULL");
355 quickpanel_list_util_del_count_by_itemtype(qid->type);
358 void quickpanel_list_util_del_count_by_itemtype(qp_item_type_e type)
362 case QP_ITEM_TYPE_ONGOING_NOTI:
363 g_qp_item_count.ongoing = (g_qp_item_count.ongoing <= 0) ? 0 : g_qp_item_count.ongoing - 1;
365 case QP_ITEM_TYPE_NOTI_GROUP:
366 g_qp_item_count.group = (g_qp_item_count.group <= 0) ? 0 : g_qp_item_count.group - 1;
368 case QP_ITEM_TYPE_NOTI:
369 g_qp_item_count.noti = (g_qp_item_count.noti <= 0) ? 0 : g_qp_item_count.noti - 1;
371 case QP_ITEM_TYPE_MINICTRL_ONGOING:
372 case QP_ITEM_TYPE_MINICTRL_TOP:
373 case QP_ITEM_TYPE_MINICTRL_MIDDLE:
374 case QP_ITEM_TYPE_MINICTRL_LOW:
375 g_qp_item_count.minicontrol = (g_qp_item_count.minicontrol <= 0) ? 0 : g_qp_item_count.minicontrol - 1;
377 case QP_ITEM_TYPE_NONE:
378 case QP_ITEM_TYPE_SETTING:
379 case QP_ITEM_TYPE_TOGGLE:
380 case QP_ITEM_TYPE_BRIGHTNESS:
381 case QP_ITEM_TYPE_MAX:
385 DBG("(type:%d)\nnum_ongoing:%d, num_group:%d, num_noti:%d, num_minicontrol:%d"
387 , g_qp_item_count.ongoing
388 , g_qp_item_count.group
389 , g_qp_item_count.noti
390 , g_qp_item_count.minicontrol);