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
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 <unicode/uloc.h>
18 #include <unicode/udat.h>
19 #include <unicode/udatpg.h>
20 #include <unicode/ustring.h>
21 #include <runtime_info.h>
23 #include "quickpanel-ui.h"
25 #include "noti_util.h"
27 #define QP_NOTI_DAY_DEC (24 * 60 * 60)
29 HAPI int quickpanel_noti_get_event_count_from_noti(notification_h noti) {
30 char *text_count = NULL;
32 retif(noti == NULL, 0, "Invalid parameter!");
34 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &text_count);
35 if (text_count != NULL) {
36 return atoi(text_count);
41 HAPI int quickpanel_noti_get_event_count_by_pkgname(const char *pkgname) {
43 notification_h noti = NULL;
44 notification_list_h noti_list = NULL;
46 retif(pkgname == NULL, 0, "Invalid parameter!");
48 notification_get_detail_list(pkgname, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE, -1, ¬i_list);
49 if (noti_list != NULL) {
50 noti = notification_list_get_data(noti_list);
52 count = quickpanel_noti_get_event_count_from_noti(noti);
54 notification_free_list(noti_list);
61 HAPI char *quickpanel_noti_get_time(time_t t, char *buf, int buf_len)
63 UErrorCode status = U_ZERO_ERROR;
64 UDateTimePatternGenerator *generator;
65 UDateFormat *formatter;
66 UChar skeleton[40] = { 0 };
67 UChar pattern[40] = { 0 };
68 UChar formatted[40] = { 0 };
69 int32_t patternCapacity, formattedCapacity;
70 int32_t skeletonLength, patternLength, formattedLength;
73 const char customSkeleton[] = UDAT_YEAR_NUM_MONTH_DAY;
74 char bf1[32] = { 0, };
75 bool is_24hour_enabled = FALSE;
78 time_t today, yesterday;
82 localtime_r(&today, &loc_time);
87 today = mktime(&loc_time);
89 yesterday = today - QP_NOTI_DAY_DEC;
91 localtime_r(&t, &loc_time);
93 if (t >= yesterday && t < today) {
94 ret = snprintf(buf, buf_len, _S("IDS_COM_BODY_YESTERDAY"));
95 } else if (t < yesterday) {
96 /* set UDate from time_t */
97 date = (UDate) t * 1000;
99 /* get default locale */
100 /* for thread saftey */
101 uloc_setDefault(__secure_getenv("LC_TIME"), &status);
102 locale = uloc_getDefault();
104 /* open datetime pattern generator */
105 generator = udatpg_open(locale, &status);
106 if (generator == NULL)
109 /* calculate pattern string capacity */
111 (int32_t) (sizeof(pattern) / sizeof((pattern)[0]));
113 /* ascii to unicode for input skeleton */
114 u_uastrcpy(skeleton, customSkeleton);
116 /* get skeleton length */
117 skeletonLength = strlen(customSkeleton);
119 /* get best pattern using skeleton */
121 udatpg_getBestPattern(generator, skeleton, skeletonLength,
122 pattern, patternCapacity, &status);
124 /* open datetime formatter using best pattern */
126 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1,
127 pattern, patternLength, &status);
128 if (formatter == NULL) {
129 udatpg_close(generator);
133 /* calculate formatted string capacity */
135 (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
137 /* formatting date using formatter by best pattern */
139 udat_format(formatter, date, formatted, formattedCapacity,
142 /* unicode to ascii to display */
143 u_austrcpy(bf1, formatted);
145 /* close datetime pattern generator */
146 udatpg_close(generator);
148 /* close datetime formatter */
149 udat_close(formatter);
151 ret = snprintf(buf, buf_len, "%s", bf1);
153 ret = runtime_info_get_value_bool(
154 RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
155 if (ret == RUNTIME_INFO_ERROR_NONE && is_24hour_enabled == TRUE) {
156 ret = strftime(buf, buf_len, "%H:%M", &loc_time);
158 strftime(bf1, sizeof(bf1), "%l:%M", &loc_time);
160 if (loc_time.tm_hour >= 0 && loc_time.tm_hour < 12)
161 ret = snprintf(buf, buf_len, "%s%s", bf1, "AM");
163 ret = snprintf(buf, buf_len, "%s%s", bf1, "PM");
168 return ret <= 0 ? NULL : buf;