tizen 2.4 release
[apps/home/attach-panel.git] / src / list.c
1 /*
2  * Copyright (c) 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 #include <aul.h>
18 #include <Elementary.h>
19 #include <tizen.h>
20 #include <rua.h>
21 #include <rua_stat.h>
22
23 #include "attach_panel.h"
24 #include "attach_panel_internal.h"
25 #include "conf.h"
26 #include "log.h"
27
28
29
30 static struct {
31         int ordering;
32 } list_info = {
33         .ordering = 1,
34 };
35
36 static int __rua_stat_tag_iter_cb(const char *rua_stat_tag, void *data)
37 {
38         Eina_List *content_list = data;
39         Eina_List *l = NULL;
40         Eina_List *ln = NULL;
41         content_s *content_info = NULL;
42
43         retv_if(!content_list, -1);
44         retv_if(!rua_stat_tag, -1);
45
46         _D("[Rua] %d : %s", list_info.ordering, rua_stat_tag);
47         EINA_LIST_FOREACH_SAFE(content_list, l, ln, content_info) {
48                 continue_if(!content_info);
49                 continue_if(!content_info->innate_content_info);
50                 if (!strcmp(rua_stat_tag, content_info->innate_content_info->appid)) {
51                         content_info->order = list_info.ordering;
52                         list_info.ordering ++;
53                 }
54         }
55
56         return 0;
57 }
58
59
60
61 static int __sort_cb(const void *d1, const void *d2)
62 {
63         content_s *content_info1 = (content_s *) d1;
64         content_s *content_info2 = (content_s *) d2;
65
66         if (!content_info1 || !content_info1->innate_content_info) {
67                 return 1;
68         }
69         if (!content_info2 || !content_info2->innate_content_info) {
70                 return -1;
71         }
72         if (content_info1->innate_content_info->is_ug || content_info2->innate_content_info->is_ug) {
73                 return -1;
74         }
75         if (content_info1->order < content_info2->order) {
76                 return -1;
77         } else if (content_info1->order > content_info2->order) {
78                 return 1;
79         } else {
80                 return (strcmp(content_info1->innate_content_info->appid, content_info2->innate_content_info->appid));
81         }
82 }
83
84
85
86 Eina_List * _list_sort_by_rua(Eina_List *content_list)
87 {
88         int ret = 0;
89
90         retv_if(!content_list, NULL);
91
92         list_info.ordering = 1;
93         ret = rua_stat_get_stat_tags("attach-panel", __rua_stat_tag_iter_cb, content_list);
94         retv_if(0 != ret, NULL);
95
96         content_list = eina_list_sort(content_list, eina_list_count(content_list), __sort_cb);
97
98         return content_list;
99 }