summaryrefslogtreecommitdiff
path: root/daemon/notifications/noti.c
blob: 92ee4d6022230bc161fe610281853b1f78e95cee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
/*
 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


#include <time.h>
#include <vconf.h>
#include <appcore-common.h>
#include <app_control.h>
#include <notification.h>
#include <system_settings.h>

#include "quickpanel-ui.h"
#include "quickpanel_def.h"
#include "common.h"
#include "list_util.h"
#include "noti_node.h"
#include "noti_gridbox.h"
#include "noti_box.h"
#include "noti_listbox.h"
#include "noti_list_item.h"
#include "noti_section.h"
#include "noti_view.h"
#include "noti.h"
#include "list_util.h"
#ifdef QP_SMART_ALERT_ENABLE
#include "smart_alert.h"
#endif
#ifdef QP_SERVICE_NOTI_LED_ENABLE
#include "noti_led.h"
#endif
#ifdef QP_REMINDER_ENABLE
#include "reminder.h"
#endif
#ifdef QP_EMERGENCY_MODE_ENABLE
#include "emergency_mode.h"
#endif
#include "vi_manager.h"

#define QP_NOTI_ONGOING_DBUS_PATH	"/dbus/signal"
#define QP_NOTI_ONGOING_DBUS_INTERFACE	"notification.ongoing"

static struct _info {
	noti_node   *noti_node;
	Evas_Object *ongoing_noti_section_view;
	Evas_Object *noti_section_view;
	Evas_Object *noti_box;

	E_DBus_Signal_Handler *dbus_handler_size;
	E_DBus_Signal_Handler *dbus_handler_progress;
	E_DBus_Signal_Handler *dbus_handler_content;

	struct tm last_time;

	int is_ongoing_hided;
} s_info = {
	.noti_node = NULL,
	.ongoing_noti_section_view = NULL,
	.noti_section_view = NULL,
	.noti_box = NULL,

	.dbus_handler_size = NULL,
	.dbus_handler_progress = NULL,
	.dbus_handler_content = NULL,

	.is_ongoing_hided = 0,

	.last_time.tm_mday = 0,
	.last_time.tm_mon = 0,
	.last_time.tm_year = 0,
};

static int _init(void *data);
static int _fini(void *data);
static int _suspend(void *data);
static int _resume(void *data);
static void _lang_changed(void *data);
static void _refresh(void *data);

static void _ongoing_noti_section_add(void);
static void _opened(void *data);
//static void _quickpanel_ongoing_noti_section_remove(void);

static void _noti_time_init(void *data);
static void _noti_time_fini(void *data);

QP_Module noti = {
	.name = "noti",
	.init = _init,
	.fini = _fini,
	.suspend = _suspend,
	.resume = _resume,
	.lang_changed = _lang_changed,
	.hib_enter = NULL,
	.hib_leave = NULL,
	.refresh = _refresh,
	.get_height = NULL,
	.qp_opened = _opened,
};

static notification_h _update_item_progress(const char *pkgname,
							    int priv_id,
							    double progress)
{
	char *noti_pkgname = NULL;
	int noti_priv_id = 0;

	noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);

	if (node != NULL && node->noti != NULL) {
		notification_get_pkgname(node->noti, &noti_pkgname);
		notification_get_id(node->noti, NULL, &noti_priv_id);

		if (!pkgname || !noti_pkgname) {
			return NULL;
		}

		if (!strcmp(noti_pkgname, pkgname)
		    && priv_id == noti_priv_id) {

			if (notification_set_progress(node->noti, progress) != NOTIFICATION_ERROR_NONE) {
				ERR("fail to set progress");
			}
			return node->noti;
		}
	}

	return NULL;
}

static notification_h _update_item_size(const char *pkgname,
							int priv_id,
							double size)
{
	char *noti_pkgname = NULL;
	int noti_priv_id = 0;

	noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);

	if (node != NULL && node->noti != NULL) {
		notification_get_pkgname(node->noti, &noti_pkgname);
		notification_get_id(node->noti, NULL, &noti_priv_id);

		if (!pkgname || !noti_pkgname) {
			return NULL;
		}

		if (!strcmp(noti_pkgname, pkgname)
		    && priv_id == noti_priv_id) {
			notification_set_size(node->noti, size);
			return node->noti;
		}
	}

	return NULL;
}

static notification_h _update_item_content(const char *pkgname,
							int priv_id,
							char *content)
{
	char *noti_pkgname = NULL;
	int noti_priv_id = 0;
	int ret = NOTIFICATION_ERROR_NONE;

	noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);

	if (node != NULL && node->noti != NULL) {
		notification_get_pkgname(node->noti, &noti_pkgname);
		notification_get_id(node->noti, NULL, &noti_priv_id);

		if (!pkgname || !noti_pkgname) {
			return NULL;
		}

		if (!strcmp(noti_pkgname, pkgname) && priv_id == noti_priv_id) {
			ret = notification_set_text(node->noti, NOTIFICATION_TEXT_TYPE_CONTENT, content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
			if (ret != NOTIFICATION_ERROR_NONE) {
				ERR("Failed to set text[%d]", ret);
			}

			return node->noti;
		}
	}

	return NULL;
}

static void _update_progressbar(void *data,
						notification_h update_noti)
{
	int priv_id = 0;
	struct appdata *ad = data;
	noti_node_item *node = NULL;
	retif(ad == NULL, , "data is NULL");
	retif(ad->list == NULL, , "ad->list is NULL");

	if (notification_get_id(update_noti, NULL, &priv_id) == NOTIFICATION_ERROR_NONE) {
		node = quickpanel_noti_node_get(s_info.noti_node, priv_id);
	}
	retif(node == NULL, , "fail to find node of priv_id:%d", priv_id);
	retif(node->view == NULL, , "fail to find %p", node->view);

	quickpanel_noti_listbox_update_item(ad->list, node->view);
}

static void _item_progress_update_cb(void *data,
						DBusMessage *msg)
{
	DBusError err;
	char *pkgname = 0;
	int priv_id = 0;
	double progress = 0;
	notification_h noti = NULL;

	retif(data == NULL || msg == NULL, , "Invalid parameter!");

	dbus_error_init(&err);
	dbus_message_get_args(msg, &err,
			DBUS_TYPE_STRING, &pkgname,
			DBUS_TYPE_INT32, &priv_id,
			DBUS_TYPE_DOUBLE, &progress,
			DBUS_TYPE_INVALID);

	if (dbus_error_is_set(&err)) {
		ERR("dbus err: %s", err.message);
		dbus_error_free(&err);
		return;
	}

	if (pkgname == NULL) {
		ERR("pkgname is null");
		return;
	}

	/* check item on the list */
	noti = _update_item_progress(pkgname,
						priv_id, progress);
	retif(noti == NULL, , "Can not found noti data.");

	SDBG("pkgname[%s], priv_id[%d], progress[%lf]",
				pkgname, priv_id, progress);
	_update_progressbar(data, noti);
}

static void _item_size_update_cb(void *data, DBusMessage * msg)
{
	DBusError err;
	char *pkgname = 0;
	int priv_id = 0;
	double size = 0;
	notification_h noti = NULL;

	retif(data == NULL || msg == NULL, , "Invalid parameter!");

	dbus_error_init(&err);
	dbus_message_get_args(msg, &err,
			DBUS_TYPE_STRING, &pkgname,
			DBUS_TYPE_INT32, &priv_id,
			DBUS_TYPE_DOUBLE, &size, DBUS_TYPE_INVALID);
	if (dbus_error_is_set(&err)) {
		ERR("dbus err: %s", err.message);
		dbus_error_free(&err);
		return;
	}

	if (pkgname == NULL) {
		ERR("pkgname is null");
		return;
	}

	/* check item on the list */
	noti = _update_item_size(pkgname, priv_id, size);
	retif(noti == NULL, , "Can not found noti data.");

	SDBG("pkgname[%s], priv_id[%d], progress[%lf]",
				pkgname, priv_id, size);

	_update_progressbar(data, noti);
}

static void _item_content_update_cb(void *data,
						DBusMessage *msg)
{
	DBusError err;
	char *pkgname = NULL;
	int priv_id = 0;
	char *content = NULL;
	notification_h noti = NULL;

	retif(data == NULL || msg == NULL, , "Invalid parameter!");

	dbus_error_init(&err);
	dbus_message_get_args(msg, &err,
			DBUS_TYPE_STRING, &pkgname,
			DBUS_TYPE_INT32, &priv_id,
			DBUS_TYPE_STRING, &content, DBUS_TYPE_INVALID);

	if (pkgname == NULL) {
		ERR("pkgname  is null");
		return;
	}
	if (content == NULL) {
		ERR("content is null");
		return;
	}

	if (dbus_error_is_set(&err)) {
		ERR("dbus err: %s", err.message);
		dbus_error_free(&err);
		return;
	}

	SDBG("pkgname[%s], priv_id[%d], content[%s]",
				pkgname, priv_id, content);

	/* check item on the list */
	noti = _update_item_content(pkgname, priv_id, content);
	retif(noti == NULL, , "Can not found noti data.");

	_update_progressbar(data, noti);
}

static int _do_noti_delete(notification_h noti)
{
	char *pkgname = NULL;
	char *caller_pkgname = NULL;
	int flags = 0, priv_id = 0, flag_delete = 0;
	notification_type_e type = NOTIFICATION_TYPE_NONE;
	int ret = NOTIFICATION_ERROR_INVALID_PARAMETER;

	quickpanel_media_play_feedback();

	retif(noti == NULL, NOTIFICATION_ERROR_INVALID_PARAMETER, "Invalid parameter!");

	notification_get_pkgname(noti, &caller_pkgname);
//	notification_get_application(noti, &pkgname);
	if (pkgname == NULL) {
		pkgname = caller_pkgname;
	}

	notification_get_id(noti, NULL, &priv_id);
	notification_get_property(noti, &flags);
	notification_get_type(noti, &type);

	if (flags & NOTIFICATION_PROP_PERMANENT_DISPLAY) {
		flag_delete = 0;
	} else {
		flag_delete = 1;
	}

	if (flag_delete == 1 && type == NOTIFICATION_TYPE_NOTI) {
		ret = notification_delete_by_priv_id(caller_pkgname, NOTIFICATION_TYPE_NOTI,
				priv_id);
	}

	return ret;
}

static void _do_noti_press(notification_h noti, int pressed_area)
{
	DBG("launch app");
	int ret = APP_CONTROL_ERROR_NONE;
	char *pkgname = NULL;
	char *caller_pkgname = NULL;

	bundle *responding_service_handle = NULL;
	bundle *single_service_handle = NULL;
	bundle *multi_service_handle = NULL;
	int flags = 0, group_id = 0, priv_id = 0, count = 0, flag_launch = 0,
			flag_delete = 0;
	notification_type_e type = NOTIFICATION_TYPE_NONE;

	quickpanel_media_play_feedback();

	retif(noti == NULL, , "Invalid parameter!");

	notification_get_pkgname(noti, &caller_pkgname);
//	notification_get_application(noti, &pkgname);
	if (pkgname == NULL) {
		pkgname = caller_pkgname;
	}

	notification_get_id(noti, &group_id, &priv_id);
	notification_get_property(noti, &flags);
	notification_get_type(noti, &type);

	if (flags & NOTIFICATION_PROP_DISABLE_APP_LAUNCH) {
		flag_launch = 0;
	} else {
		flag_launch = 1;
	}

	if (flags & NOTIFICATION_PROP_DISABLE_AUTO_DELETE) {
		flag_delete = 0;
	} else {
		flag_delete = 1;
	}

	notification_get_execute_option(noti,
			NOTIFICATION_EXECUTE_TYPE_RESPONDING,
				NULL, &responding_service_handle);
	notification_get_execute_option(noti,
				NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
				NULL, &single_service_handle);
	notification_get_execute_option(noti,
				NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH,
				NULL, &multi_service_handle);

	if (pressed_area == NOTI_PRESS_BUTTON_1 && responding_service_handle != NULL) {
		DBG("");
		quickpanel_uic_close_quickpanel(true, 1);
		ret = quickpanel_uic_launch_app(NULL, responding_service_handle);
	} else if (flag_launch == 1) {
		/* Hide quickpanel */
		quickpanel_uic_close_quickpanel(true, 1);

		char *text_count = NULL;
		notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &text_count);

		if (text_count != NULL) {
			count = atoi(text_count);
		} else {
			count = 1;
		}

		if (single_service_handle != NULL && multi_service_handle == NULL) {
			DBG("");
			ret = quickpanel_uic_launch_app(NULL, single_service_handle);
		}
		if (single_service_handle == NULL && multi_service_handle != NULL) {
			DBG("");
			ret = quickpanel_uic_launch_app(NULL, multi_service_handle);
		}
		if (single_service_handle != NULL && multi_service_handle != NULL) {
			DBG("");
			if (count <= 1) {
				ret = quickpanel_uic_launch_app(NULL, single_service_handle);
			} else {
				ret = quickpanel_uic_launch_app(NULL, multi_service_handle);
			}
		}
		quickpanel_uic_launch_app_inform_result(pkgname, ret);
	}

	if (flag_delete == 1 && type == NOTIFICATION_TYPE_NOTI) {
		notification_delete_by_priv_id(caller_pkgname,
				NOTIFICATION_TYPE_NOTI,
				priv_id);
	}
}

static void _notibox_delete_cb(noti_node_item *item, Evas_Object *obj)
{
	DBG("");
	retif(obj == NULL, , "Invalid parameter!");
	retif(item == NULL, , "Invalid parameter!");

	notification_h noti = item->noti;
	retif(noti == NULL, , "Invalid parameter!");

	if (_do_noti_delete(noti) != NOTIFICATION_ERROR_NONE) {
		quickpanel_noti_box_item_dragging_cancel(obj);
	}
}

static void _notibox_button_1_cb(noti_node_item *item, Evas_Object *obj)
{
	DBG("");
	retif(item == NULL, , "Invalid parameter!");

	notification_h noti = item->noti;
	retif(noti == NULL, , "Invalid parameter!");

	_do_noti_press(noti, NOTI_PRESS_BUTTON_1);
}

static void _notibox_select_cb(noti_node_item *item, Evas_Object *obj)
{
	DBG("");
	retif(item == NULL, , "Invalid parameter!");
	notification_h noti = item->noti;
	retif(noti == NULL, , "Invalid parameter!");

	_do_noti_press(noti, NOTI_PRESS_BG);
}

static void _noti_listitem_select_cb(noti_node_item *item, Evas_Object * obj)
{
	DBG("");
	retif(item == NULL, , "Invalid parameter!");

	notification_h noti = item->noti;
	retif(noti == NULL, , "Invalid parameter!");

	_do_noti_press(noti, NOTI_PRESS_BG);
}

static inline void _ongoing_comp_n_copy(notification_h old, notification_h new)
{
	int priv_id = 0;
	int new_priv_id = 0;
	char *pkgname = NULL;
	char *new_pkgname = NULL;
	int ret = NOTIFICATION_ERROR_NONE;

	if (!old) {
		return;
	}

	if (!new) {
		return;
	}

	notification_get_id(old, NULL, &priv_id);
	notification_get_id(new, NULL, &new_priv_id);

	notification_get_pkgname(old, &pkgname);
	notification_get_pkgname(new, &new_pkgname);

	if (!pkgname || !new_pkgname) {
		return;
	}

	if (!strcmp(pkgname, new_pkgname) && priv_id == new_priv_id) {
		double percentage = 0.0;
		double size = 0.0;
		time_t insert_time = 0;
		time_t new_insert_time = 0;

		notification_get_progress(old, &percentage);
		notification_get_size(old, &size);
		if (notification_set_progress(new, percentage) != NOTIFICATION_ERROR_NONE) {
			ERR("fail to set progress");
		}
		if (notification_set_size(new, size) != NOTIFICATION_ERROR_NONE) {
			ERR("fail to set size");
		}
		notification_get_insert_time(old, &insert_time);
		notification_get_insert_time(new, &new_insert_time);

		if (insert_time == new_insert_time) {
			char *content = NULL;
			notification_get_text(old,
				NOTIFICATION_TEXT_TYPE_CONTENT,	&content);
			ret = notification_set_text(new, NOTIFICATION_TEXT_TYPE_CONTENT, content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
			if (ret != NOTIFICATION_ERROR_NONE) {
				ERR("Failed to set text[%d]", ret);
			}
		}
	}
}

static void _noti_node_clear_list_cb(gpointer key, gpointer value, gpointer user_data)
{
	Evas_Object *noti_listbox = user_data;
	noti_node_item *node = (noti_node_item *)value;

	if (noti_listbox != NULL && node != NULL) {
		if (node->noti != NULL && node->view != NULL) {
			quickpanel_noti_listbox_remove_item(noti_listbox, node->view, EINA_TRUE);
		}
	}
}

static void _noti_clear_list_all(void)
{
	struct appdata *ad = quickpanel_get_app_data();

	if (s_info.noti_node->table != NULL) {
		g_hash_table_foreach(s_info.noti_node->table, _noti_node_clear_list_cb, ad->list);
	}

	if (s_info.noti_node != NULL) {
		quickpanel_noti_node_remove_all(s_info.noti_node);
	}
}

static void _ongoing_noti_section_icon_state_set(int is_closed) {
	if (s_info.ongoing_noti_section_view != NULL) {
		if (is_closed == 1) {
			elm_object_signal_emit(s_info.ongoing_noti_section_view, "button,opened", "prog");
		} else {
			elm_object_signal_emit(s_info.ongoing_noti_section_view, "button,closed", "prog");
		}
	}
}

static void _ongoing_noti_section_deleted_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
	DBG("");
	struct appdata *ad = data;
	s_info.ongoing_noti_section_view = NULL;
	DBG("VIM ongoing noti_section deleted");

	if (quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NONE) > 0) {
		_ongoing_noti_section_add();
	}

	quickpanel_noti_listbox_remove_item(ad->list, s_info.noti_section_view, 1);
	s_info.noti_section_view = NULL;
}

static void _ongoing_noti_section_add(void)
{
	int noti_count = 0;
	struct appdata *ad = quickpanel_get_app_data();
	retif(ad == NULL, , "Invalid parameter!");
	retif(ad->list == NULL, , "Invalid parameter!");

	if (s_info.noti_node) {
		noti_count = quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NONE);
	}

	DBG("[%d] ", noti_count);

	if (s_info.ongoing_noti_section_view == NULL) {
		s_info.ongoing_noti_section_view = quickpanel_noti_section_create(ad->list, QP_ITEM_TYPE_ONGOING_NOTI_GROUP);
		if (s_info.ongoing_noti_section_view != NULL) {
			quickpanel_noti_section_set_deleted_cb(s_info.ongoing_noti_section_view, _ongoing_noti_section_deleted_cb, ad);
			quickpanel_noti_section_update(s_info.ongoing_noti_section_view, noti_count);

			if (s_info.is_ongoing_hided == 1) {
				_ongoing_noti_section_icon_state_set(0);
			}
		}
	}
	else {
		DBG("noti section update %d ", noti_count);
		quickpanel_noti_section_update(s_info.ongoing_noti_section_view, noti_count);
	}
}

static void _noti_ongoing_add(Evas_Object *list, void *data, int is_prepend)
{
	Evas_Object *noti_list_item = NULL;
	notification_h noti = data;
	retif(list == NULL, , "Invalid parameter!");

	if (noti != NULL) {
		noti_list_item = quickpanel_noti_list_item_create(list, noti);

		if (noti_list_item != NULL) {
			noti_node_item *item = quickpanel_noti_node_add(s_info.noti_node, (void*)data, (void*)noti_list_item);
			if (item != NULL) {
				quickpanel_noti_list_item_node_set(noti_list_item, item);
				quickpanel_noti_list_item_set_item_selected_cb(noti_list_item, _noti_listitem_select_cb);

				if (s_info.ongoing_noti_section_view == NULL) {
					_ongoing_noti_section_add();
				}
				quickpanel_noti_listbox_add_item(list, noti_list_item, is_prepend, s_info.ongoing_noti_section_view);
			}
		} else
			ERR("fail to insert item to list : %p", data);
	}

	DBG("noti[%p] data[%p] added listbox[%p]",
			data, noti_list_item, list);
}

static void _noti_add(Evas_Object *list, void *data, int insert_pos)
{
	notification_h noti = data;
	notification_ly_type_e layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
	Evas_Object *noti_view = NULL;

	retif(list == NULL, , "Invalid parameter!");

	if (noti != NULL) {
		notification_get_layout(noti, &layout);
		noti_view = quickpanel_noti_list_item_create(list, noti);

		if (noti_view != NULL) {
			noti_node_item *item = quickpanel_noti_node_add(s_info.noti_node, (void*)data, (void*)noti_view);
			if (item != NULL) {
				quickpanel_noti_list_item_node_set(noti_view, item);
				quickpanel_noti_list_item_set_item_selected_cb(noti_view, _notibox_select_cb);
				quickpanel_noti_list_item_set_item_button_1_cb(noti_view, _notibox_button_1_cb);
				quickpanel_noti_list_item_set_item_deleted_cb(noti_view, _notibox_delete_cb);

				if (s_info.noti_section_view == NULL) {
					_ongoing_noti_section_add();
				}
				quickpanel_noti_listbox_add_item(list, noti_view, insert_pos, s_info.noti_section_view);
			}
		} else
			ERR("fail to insert item to list : %p", data);
	}

	DBG("noti[%p] view[%p] added gridbox[%p]",
			data, noti_view, list);
}

static void _update_notilist(struct appdata *ad)
{
	Evas_Object *list = NULL;
	notification_h noti = NULL;
	notification_h noti_save = NULL;
	notification_list_h list_head = NULL;
	notification_list_h list_traverse = NULL;
	int applist = NOTIFICATION_DISPLAY_APP_ALL;

	DBG("");

	retif(ad == NULL, , "Invalid parameter!");

	list = ad->list;
	retif(list == NULL, , "Failed to get noti genlist.");

	_noti_clear_list_all();

	notification_get_list(NOTIFICATION_TYPE_ONGOING, -1, &list_head);
	list_traverse = list_head;
	while (list_traverse != NULL) {
		noti = notification_list_get_data(list_traverse);
		notification_get_display_applist(noti, &applist);

		if (applist &
		    NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
			notification_clone(noti, &noti_save);
			_noti_ongoing_add(list, noti_save, LISTBOX_APPEND);
		}
		list_traverse = notification_list_get_next(list_traverse);
	}
	if (list_head != NULL) {
		notification_free_list(list_head);
		list_head = NULL;
	}

	notification_get_list(NOTIFICATION_TYPE_NOTI , -1, &list_head);
	list_traverse = list_head;
	while (list_traverse != NULL) {
		noti = notification_list_get_data(list_traverse);
		notification_get_display_applist(noti, &applist);

		if (applist &
		    NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
			notification_clone(noti, &noti_save);
			_noti_add(list, noti_save, LISTBOX_APPEND);
		}
		list_traverse = notification_list_get_next(list_traverse);
	}
	if (list_head != NULL) {
		notification_free_list(list_head);
		list_head = NULL;
	}

	if (list != NULL) {
		elm_box_recalculate(list);
	}
}

inline static void _print_debuginfo_from_noti(notification_h noti) {
	retif(noti == NULL, , "Invalid parameter!");

	char *noti_pkgname = NULL;
	notification_type_e noti_type = NOTIFICATION_TYPE_NONE;

	notification_get_pkgname(noti, &noti_pkgname);
	notification_get_type(noti, &noti_type);

	if (noti_pkgname != NULL) {
		SERR("pkg:%s", noti_pkgname);
	}

	SERR("type:%d", noti_type);
}

static void _detailed_changed_cb(void *data, notification_type_e type, notification_op *op_list, int num_op)
{
	int i = 0;
	int op_type = 0;
	int priv_id = 0;
	struct appdata *ad = NULL;
	notification_h noti_new = NULL;
	notification_h noti_from_master = NULL;
	notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
	int noti_applist = NOTIFICATION_DISPLAY_APP_ALL;
	notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
	notification_ly_type_e old_noti_layout = NOTIFICATION_LY_NONE;

	retif(data == NULL, , "Invalid parameter!");
	ad = data;

	SERR("num_op:%d", num_op);

	for (i = 0; i < num_op; i++) {
		notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_TYPE, &op_type);
		notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &priv_id);
		notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, &noti_from_master);

		SERR("noti operation:%d privid:%d", op_type, priv_id);


		switch(op_type)	{
		case NOTIFICATION_OP_INSERT: 
			if (noti_from_master == NULL) {
				ERR("failed to get a notification from master");
				continue;
			}
			if (notification_clone(noti_from_master, &noti_new) != NOTIFICATION_ERROR_NONE) {
				ERR("failed to create a cloned notification");
				continue;
			}

			_print_debuginfo_from_noti(noti_new);
#ifdef QP_EMERGENCY_MODE_ENABLE
			if (quickpanel_emergency_mode_is_on()) {
				if (quickpanel_emergency_mode_notification_filter(noti_new, 0)) {
					notification_free(noti_new);
					return;
				}
			}
#endif
#ifdef QP_SMART_ALERT_ENABLE
			quickpanel_smart_alert_update_info(noti_new);
#endif
#ifdef QP_SERVICE_NOTI_LED_ENABLE
			quickpanel_noti_led_proc(noti_new, op_type);
#endif

			notification_get_type(noti_new, &noti_type);
			notification_get_display_applist(noti_new, &noti_applist);
			notification_get_layout(noti_new, &noti_layout);

			if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
				noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);
				if (node != NULL) {
					if (noti_type == NOTIFICATION_TYPE_NOTI) {
						DBG("cb after inserted:%d", priv_id);
					}
					notification_free(noti_new);
				} else {
					if (noti_type == NOTIFICATION_TYPE_NOTI) {
						_noti_add(ad->list, noti_new, LISTBOX_APPEND);
#ifdef QP_REMINDER_ENABLE
						quickpanel_reminder_start(NULL);
#endif
					} else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
						_noti_ongoing_add(ad->list, noti_new, LISTBOX_PREPEND);
					} else {
						notification_free(noti_new);
					}
				}
			} else {
				notification_free(noti_new);
			}
			break;

		case NOTIFICATION_OP_DELETE:
			{
				noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);

				if (node != NULL && node->noti != NULL) {
					notification_h noti = node->noti;
					notification_get_type(noti, &noti_type);

#ifdef QP_SMART_ALERT_ENABLE
					quickpanel_smart_alert_update_info(noti);
#endif
#ifdef QP_SERVICE_NOTI_LED_ENABLE
					quickpanel_noti_led_proc(noti, op_type);
#endif
					_print_debuginfo_from_noti(noti);

					if (noti_type == NOTIFICATION_TYPE_NOTI) {
						quickpanel_noti_listbox_remove_item(ad->list, node->view, 1);
					} else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
						quickpanel_noti_listbox_remove_item(ad->list, node->view, 1);
					}

					quickpanel_noti_node_remove(s_info.noti_node, priv_id);
					if (quickpanel_media_player_id_get() == priv_id) {
						quickpanel_media_player_stop();
					}
				} else {
					ERR("node = NULL or node->noti == NULL");
				}

#ifdef QP_REMINDER_ENABLE
				if (quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NOTI) <= 0) {
					quickpanel_reminder_stop(NULL);
				}
#endif
			}
			break;

		case NOTIFICATION_OP_UPDATE:
			{
				noti_node_item *node = quickpanel_noti_node_get(s_info.noti_node, priv_id);
				notification_h old_noti = NULL;

				DBG("Notification update priv_id[%d]", priv_id);

				if (noti_from_master == NULL) {
					ERR("failed to get a notification from master");
					continue;
				}

				if (notification_clone(noti_from_master, &noti_new) != NOTIFICATION_ERROR_NONE) {
					ERR("failed to create a cloned notification");
					continue;
				}
#ifdef QP_EMERGENCY_MODE_ENABLE
				if (quickpanel_emergency_mode_is_on()) {
					if (quickpanel_emergency_mode_notification_filter(noti_new, 0)) {
						DBG("notification filtered");
						notification_free(noti_new);
						return;
					}
				}
#endif
#ifdef QP_SMART_ALERT_ENABLE
				quickpanel_smart_alert_update_info(noti_new);
#endif
#ifdef QP_SERVICE_NOTI_LED_ENABLE
				quickpanel_noti_led_proc(noti_new, op_type);
#endif
				_print_debuginfo_from_noti(noti_new);
				notification_get_layout(noti_new, &noti_layout);

				if (node != NULL && node->view != NULL && node->noti != NULL) {
					notification_get_type(noti_new, &noti_type);

					notification_get_layout(node->noti, &old_noti_layout);
					if (noti_type == NOTIFICATION_TYPE_NOTI || old_noti_layout != noti_layout) {
						if (quickpanel_noti_view_is_view_handler_changed(node->view, noti_new) == 1) {
							quickpanel_noti_listbox_remove_item(ad->list, node->view, 1);
							quickpanel_noti_node_remove(s_info.noti_node, priv_id);
							_noti_add(ad->list, noti_new, GRIDBOX_PREPEND);
						} else {
							old_noti = node->noti;
							node->noti = noti_new;
							quickpanel_noti_listbox_update_item(ad->list, node->view);
						}
					} else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
						old_noti = node->noti;
						node->noti = noti_new;

						quickpanel_noti_listbox_update_item(ad->list, node->view);
					} else {
						notification_free(noti_new);
					}

					if (old_noti != NULL) {
						notification_free(old_noti);
					}
				} else {
					notification_get_display_applist(noti_new, &noti_applist);

					if (noti_applist & NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY) {
						if (noti_type == NOTIFICATION_TYPE_NOTI) {
							_noti_add(ad->list, noti_new, LISTBOX_PREPEND);
						} else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
							_noti_ongoing_add(ad->list, noti_new, LISTBOX_PREPEND);
						} else {
							notification_free(noti_new);
						}
					} else {
						notification_free(noti_new);
					}
				}
			}
			break;

		case NOTIFICATION_OP_SERVICE_READY:
			_update_notilist(ad);

#ifdef	QP_SMART_ALERT_ENABLE
			quickpanel_smart_alert_update_info(NULL);
#endif
#ifdef QP_SERVICE_NOTI_LED_ENABLE
			quickpanel_noti_led_init(ad, s_info.noti_node);
#endif
			quickpanel_vim_set_state_ready();

#ifdef QP_REMINDER_ENABLE
			if (quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NOTI) > 0) {
				quickpanel_reminder_start(NULL);
			} else {
				quickpanel_reminder_stop(NULL);
			}
#endif
			//quickpanel_chg_init();
			break;

		default:
			SERR("Unknown op type");
			break;
		}
	}

	int noti_count = quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NOTI);
	int ongoing_noti_count = quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_ONGOING);

	if (s_info.noti_section_view != NULL) {
		quickpanel_noti_section_update(s_info.noti_section_view, noti_count+ongoing_noti_count);
	}
	if (s_info.ongoing_noti_section_view != NULL) {
		quickpanel_noti_section_update(s_info.ongoing_noti_section_view, noti_count+ongoing_noti_count);
	}

	SERR("current noti count:%d, ongoing:%d", noti_count, ongoing_noti_count);
}

static void _update_sim_status_cb(keynode_t *node, void *data)
{
	struct appdata *ad = data;

	if (ad != NULL && ad->list != NULL) {
		if (notification_is_service_ready() == 1) {
			_update_notilist(ad);
		}
	}
}

static Eina_Bool _noti_callback_register_idler_cb(void *data)
{
	struct appdata *ad = data;
	retif(ad == NULL, EINA_FALSE, "Invalid parameter!");

	notification_register_detailed_changed_cb(_detailed_changed_cb, ad);

	return EINA_FALSE;
}

static int _register_event_handler(struct appdata *ad)
{
	int ret = 0;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");
	retif(ad->dbus_connection == NULL, QP_FAIL, "Invalid parameter!");

	s_info.dbus_handler_size =
		e_dbus_signal_handler_add(ad->dbus_connection, NULL,
			QP_NOTI_ONGOING_DBUS_PATH,
			QP_NOTI_ONGOING_DBUS_INTERFACE, "update_progress",
			_item_progress_update_cb,
			ad);
	if (s_info.dbus_handler_size == NULL) {
		ERR("fail to add size signal");
	}

	s_info.dbus_handler_progress =
		e_dbus_signal_handler_add(ad->dbus_connection, NULL,
			QP_NOTI_ONGOING_DBUS_PATH,
			QP_NOTI_ONGOING_DBUS_INTERFACE, "update_size",
			_item_size_update_cb,
			ad);
	if (s_info.dbus_handler_progress == NULL) {
		ERR("fail to add progress signal");
	}

	s_info.dbus_handler_content =
		e_dbus_signal_handler_add(ad->dbus_connection, NULL,
			QP_NOTI_ONGOING_DBUS_PATH,
			QP_NOTI_ONGOING_DBUS_INTERFACE, "update_content",
			_item_content_update_cb,
			ad);
	if (s_info.dbus_handler_content == NULL) {
		ERR("fail to add content signal");
	}

	/* Notify vconf key */
	ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
				       _update_sim_status_cb,
				       (void *)ad);
	if (ret != 0) {
		ERR("Failed to register SIM_SLOT change callback!");
	}

	/* Register notification changed cb */
	ecore_idler_add(_noti_callback_register_idler_cb, ad);

	return ret;
}

static int _unregister_event_handler(struct appdata *ad)
{
	int ret = 0;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");
	retif(ad->dbus_connection == NULL, QP_FAIL, "Invalid parameter!");

	/* Unregister notification changed cb */
	notification_unregister_detailed_changed_cb(_detailed_changed_cb, (void *)ad);

	ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
				_update_sim_status_cb);
	if (ret != 0) {
		ERR("Failed to ignore SIM_SLOT change callback!");
	}

	/* Delete dbus signal */
	if (s_info.dbus_handler_size != NULL) {
		e_dbus_signal_handler_del(ad->dbus_connection,
				s_info.dbus_handler_size);
		s_info.dbus_handler_size = NULL;
	}
	if (s_info.dbus_handler_progress != NULL) {
		e_dbus_signal_handler_del(ad->dbus_connection,
				s_info.dbus_handler_progress);
		s_info.dbus_handler_progress = NULL;
	}
	if (s_info.dbus_handler_content != NULL) {
		e_dbus_signal_handler_del(ad->dbus_connection,
				s_info.dbus_handler_content);
		s_info.dbus_handler_content = NULL;
	}

	return QP_OK;
}

/*static void _quickpanel_noti_init(void *data)
{
	struct appdata *ad = NULL;

	retif(data == NULL, , "Invalid parameter!");
	ad = data;

	retif(ad->list == NULL, , "Invalid parameter!");

	DBG("wr");

	if (s_info.noti_box == NULL) {
		s_info.noti_box = quickpanel_noti_listbox_create(ad->list
			, quickpanel_get_app_data(), QP_ITEM_TYPE_ONGOING_NOTI);
		quickpanel_noti_listbox_set_item_deleted_cb(s_info.noti_box, _quickpanel_list_box_deleted_cb);
		quickpanel_list_util_sort_insert(ad->list, s_info.noti_box);
	}
}

static void _quickpanel_noti_fini(void *data)
{
	struct appdata *ad = NULL;

	retif(data == NULL, , "Invalid parameter!");
	ad = data;

	retif(ad->list == NULL, , "Invalid parameter!");

	DBG("dr");
}*/

static int _init(void *data)
{
	struct appdata *ad = data;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");

	quickpanel_noti_node_create(&s_info.noti_node);

	//_quickpanel_noti_init(ad);

	_register_event_handler(ad);

	// NOTI TIME
	_noti_time_init(data);

	return QP_OK;
}

static int _fini(void *data)
{
	struct appdata *ad = data;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");

#ifdef QP_SERVICE_NOTI_LED_ENABLE
	quickpanel_noti_led_fini(ad);
#endif

	/* Unregister event handler */
	_unregister_event_handler(data);

	_noti_clear_list_all();

	//_quickpanel_noti_fini(ad);

	if (s_info.noti_node != NULL) {
		quickpanel_noti_node_destroy(&s_info.noti_node);
	}

	// NOTI TIME
	_noti_time_fini(data);

	return QP_OK;
}

static int _suspend(void *data)
{
	struct appdata *ad = data;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");

	return QP_OK;
}

static void _noti_node_ongoing_update_cb(gpointer key, gpointer value, gpointer user_data)
{
	notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
	Evas_Object *noti_listbox = user_data;
	noti_node_item *node = (noti_node_item *)value;

	if (noti_listbox != NULL && node != NULL) {
		if (node->noti != NULL && node->view != NULL) {
			notification_get_type(node->noti, &noti_type);
			if (noti_type == NOTIFICATION_TYPE_ONGOING) {
				quickpanel_noti_listbox_update_item(noti_listbox, node->view);
			}
		}
	}
}

static int _resume(void *data)
{
	struct appdata *ad = data;
	retif(ad == NULL, QP_FAIL, "Invalid parameter!");

	if (ad->list != NULL && s_info.noti_node != NULL) {
		if (quickpanel_noti_node_get_item_count(s_info.noti_node, QP_ITEM_TYPE_ONGOING_NOTI) > 0) {
			if (s_info.noti_node->table != NULL) {
				g_hash_table_foreach(s_info.noti_node->table, _noti_node_ongoing_update_cb, ad->list);
			}
		}
	}

	return QP_OK;
}

static void _refresh(void *data)
{
	struct appdata *ad = NULL;

	retif(data == NULL, , "Invalid parameter!");
	ad = data;

	quickpanel_noti_listbox_rotation(ad->list, ad->angle);
}

static void _lang_changed(void *data)
{
	int noti_count = 0;
	int ongoing_noti_count = 0;
	struct appdata *ad = data;

	retif(ad == NULL, , "Invalid parameter!");

	if (notification_is_service_ready() == 1) {

		_update_notilist(ad);

		noti_count = quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NOTI);
		ongoing_noti_count = quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_ONGOING);

		if (s_info.noti_section_view != NULL) {
			quickpanel_noti_section_update(s_info.noti_section_view, noti_count+ongoing_noti_count);
		}
		if (s_info.ongoing_noti_section_view != NULL) {
			quickpanel_noti_section_update(s_info.ongoing_noti_section_view, noti_count+ongoing_noti_count);
		}
	}
}

HAPI int quickpanel_noti_get_count(void)
{
	return quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NONE);
}

HAPI int quickpanel_noti_get_type_count(notification_type_e noti_type)
{
	return quickpanel_noti_node_get_item_count(s_info.noti_node, noti_type);
}

HAPI int quickpanel_noti_get_geometry(int *limit_h, int *limit_partial_h, int *limit_partial_w)
{
	retif(limit_h == NULL, 0, "invalid parameter");
	retif(limit_partial_h == NULL, 0, "invalid parameter");
	retif(limit_partial_w == NULL, 0, "invalid parameter");
	struct appdata *ad = quickpanel_get_app_data();

	return quickpanel_noti_listbox_get_geometry(ad->list,
					limit_h, limit_partial_h, limit_partial_w);
}

HAPI noti_node_item *quickpanel_noti_node_get_by_priv_id(int priv_id)
{
	retif(s_info.noti_node == NULL, NULL, "invalid parameter");

	return quickpanel_noti_node_get(s_info.noti_node, priv_id);
}

HAPI noti_node_item *quickpanel_noti_node_get_first_noti(void)
{
	// get box list
	Eina_List *l;
	Eina_List *l_next;
	Evas_Object *obj = NULL;
	Eina_List *item_list = NULL;
	noti_node_item *node = NULL;
	noti_node_item *node_first_noti = NULL;
	notification_type_e type = NOTIFICATION_TYPE_NONE;
	struct appdata *ad = quickpanel_get_app_data();

	item_list = elm_box_children_get(ad->list);
	retif(item_list == NULL, NULL, "invalid parameter");

	EINA_LIST_FOREACH_SAFE(item_list, l, l_next, obj) {
		if (obj != NULL) {
			node = quickpanel_noti_list_item_node_get(obj);
			if (node) {
				notification_h noti = node->noti;
				if (noti) {
					notification_get_type(noti, &type);
					if (type == NOTIFICATION_TYPE_NOTI) {
						node_first_noti = node;
						break;
					}
				}
			}
		}
	}

	if (item_list != NULL) {
		eina_list_free(item_list);
	}

	return node_first_noti;
}

HAPI void quickpanel_noti_closing_trigger_set(void)
{
	struct appdata *ad = quickpanel_get_app_data();
	quickpanel_noti_listbox_closing_trigger_set(ad->list);
}

static void _opened(void *data)
{
	if (elm_config_access_get() == EINA_TRUE) {
		elm_access_say(_NOT_LOCALIZED("Notification panel"));
	}
}

HAPI void quickpanel_noti_set_clear_all_status()
{
	struct appdata *ad = quickpanel_get_app_data();
	if ((quickpanel_noti_listbox_get_item_count(ad->list) >= 0
			|| quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_ONGOING) >= 0)
			&& quickpanel_noti_node_get_item_count(s_info.noti_node, NOTIFICATION_TYPE_NOTI) <= 0) 	{
		INFO("NOTI SECTION CLEAR ALL HIDE");
		elm_object_signal_emit(s_info.ongoing_noti_section_view ,
				"notifaction,section,clear_all,hide", "base");
	} else {
		INFO("NOTI SECTION CLEAR ALL SHOW");
		elm_object_signal_emit(s_info.ongoing_noti_section_view,
				"notifaction,section,clear_all,show", "base");
	}

}

HAPI void quickpanel_noti_on_clear_all_clicked(void *data, Evas_Object *obj, void *info)
{
	quickpanel_media_play_feedback();
	LOGI("NOTI CLEAR ALL CLICKED");

	DBG("");
	struct appdata *ad = quickpanel_get_app_data();
	retif(ad == NULL, , "Invalid parameter!");
	retif(ad->list == NULL, , "Invalid parameter!");

	quickpanel_noti_closing_trigger_set();
#ifdef HAVE_X
	notification_clear(NOTIFICATION_TYPE_NOTI);
#endif
	quickpanel_uic_close_quickpanel(EINA_FALSE, EINA_FALSE);

	/*if (s_info.noti_node->n_ongoing == 0)
	{
		_ongoing_noti_section_remove();
	}*/
}

// TIME REACTION

static void _on_time_changed(keynode_t *key, void *data)
{
	struct appdata *ad = data;

	time_t current_time = time(NULL);
	struct tm loc_time;
	localtime_r(&current_time, &loc_time);

	if (loc_time.tm_yday != s_info.last_time.tm_yday || loc_time.tm_year != s_info.last_time.tm_year) {
		_update_notilist(ad);
	}

	s_info.last_time = loc_time;
}

static Eina_Bool _notification_time_format_changed_cb(void *data)
{
	struct appdata *ad = data;

	_update_notilist(ad);

	return ECORE_CALLBACK_CANCEL;
}

static void _noti_time_init(void *data)
{
	int ret = 0;
	struct appdata *ad = data;
	retif_nomsg(ad == NULL, );

	time_t current_time = time(NULL);
	localtime_r(&current_time, &s_info.last_time);

	ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT, _on_time_changed, data);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_SETAPPL_TIMEZONE_INT, ret);
	ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, _on_time_changed, data);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_TELEPHONY_SVC_ROAM, ret);
	ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, _on_time_changed, data);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_SETAPPL_TIMEZONE_ID, ret);
}

static void _noti_time_fini(void *data)
{
	int ret = 0;
	struct appdata *ad = data;
	retif_nomsg(ad == NULL, );

	ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT, _on_time_changed);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_SETAPPL_TIMEZONE_INT, ret);
	ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, _on_time_changed);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_SETAPPL_TIMEZONE_ID, ret);
	ret = vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, _on_time_changed);
	msgif(ret != 0, "failed to set key(%s) : %d", VCONFKEY_TELEPHONY_SVC_ROAM, ret);
}

HAPI void quickpanel_noti_update_by_system_time_changed_cb(system_settings_key_e  *key, void *data)
{
	struct appdata *ad = data;

#ifdef HAVE_X
	if (key == SYSTEM_SETTINGS_KEY_TIME_CHANGED
		||key == SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY ){
		_on_time_changed(key,data);
	} else
#endif
	{ //key == SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR
		_notification_time_format_changed_cb(data);
	}
}


HAPI void quickpanel_noti_init_noti_section(void)
{
	if (s_info.ongoing_noti_section_view == NULL) {
		_ongoing_noti_section_add();
	}
}