2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <Elementary.h>
22 #include <tzsh_quickpanel_service.h>
23 #include <notification.h>
24 #include <notification_internal.h>
27 #include "quickpanel-ui.h"
29 #include "list_util.h"
30 #include "noti_node.h"
32 static void _noti_node_free(noti_node_item *node);
34 HAPI void quickpanel_noti_node_create(noti_node **handle)
36 retif(handle == NULL, , "Invalid parameter!");
38 *handle = (noti_node *)malloc(sizeof(noti_node));
40 if (*handle != NULL) {
41 (*handle)->table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_noti_node_free);
42 (*handle)->n_ongoing = 0;
43 (*handle)->n_noti = 0;
49 HAPI void quickpanel_noti_node_destroy(noti_node **handle)
51 retif(handle == NULL, , "Invalid parameter!");
52 retif(*handle == NULL, , "Invalid parameter!");
54 g_hash_table_remove_all((*handle)->table);
55 g_hash_table_destroy((*handle)->table);
56 (*handle)->table = NULL;
62 HAPI noti_node_item *quickpanel_noti_node_add(noti_node *handle, notification_h noti, void *view)
65 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
66 noti_node_item *node = NULL;
68 retif(handle == NULL || noti == NULL, NULL, "Invalid parameter!");
70 if (notification_get_id(noti, NULL, &priv_id) == NOTIFICATION_ERROR_NONE) {
71 node = malloc(sizeof(noti_node_item));
73 ERR("fail to alloc item");
80 g_hash_table_insert(handle->table, GINT_TO_POINTER(priv_id), (gpointer *)node);
82 notification_get_type(noti, ¬i_type);
84 if (noti_type == NOTIFICATION_TYPE_NOTI) {
86 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
90 DBG("n_noti = [%d] n_ongoing = [%d]", handle->n_noti, handle->n_ongoing);
97 HAPI void quickpanel_noti_node_remove(noti_node *handle, int priv_id)
99 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
101 retif(handle == NULL, , "Invalid parameter!");
102 retif(handle->table == NULL, , "Invalid parameter!");
104 noti_node_item *item = quickpanel_noti_node_get(handle, priv_id);
107 if (item->noti != NULL) {
108 notification_get_type(item->noti, ¬i_type);
110 if (noti_type == NOTIFICATION_TYPE_NOTI) {
112 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
117 notification_free(item->noti);
121 if (g_hash_table_remove(handle->table, GINT_TO_POINTER(priv_id))) {
122 DBG("success to remove %d", priv_id);
127 HAPI void quickpanel_noti_node_remove_all(noti_node *handle)
129 retif(handle == NULL, , "Invalid parameter!");
130 retif(handle->table == NULL, , "Invalid parameter!");
132 g_hash_table_remove_all(handle->table);
134 handle->n_ongoing = 0;
135 DBG("all the nodes are removed");
138 HAPI noti_node_item *quickpanel_noti_node_get(noti_node *handle, int priv_id)
140 retif(handle == NULL, NULL, "Invalid parameter!");
141 retif(handle->table == NULL, NULL, "Invalid parameter!");
143 return (noti_node_item *)g_hash_table_lookup(handle->table, GINT_TO_POINTER(priv_id));
146 HAPI int quickpanel_noti_node_get_item_count(noti_node *handle, notification_type_e noti_type)
148 retif(handle == NULL, 0, "Invalid parameter!");
150 DBG("n_noti %d , n_ongoing %d ", handle->n_noti, handle->n_ongoing);
152 if (noti_type == NOTIFICATION_TYPE_NOTI) {
153 return handle->n_noti;
154 } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
155 return handle->n_ongoing;
156 } else if (noti_type == NOTIFICATION_TYPE_NONE) {
157 return handle->n_noti + handle->n_ongoing;
163 static void _noti_node_free(noti_node_item *node)
165 retif(node == NULL, , "Invalid parameter!");
167 DBG("item_node is freed:%p", node);