da5a4304092912a9b9e9bc340c9faee502640a5b
[apps/home/ug-memo-efl.git] / src / memo-assist.c
1 /*
2  * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
3  * 
4  * This file is part of the ug-memo-efl
5  * Written by Zhibin Zhou <zhibin.zhou@samsung.com>, Canjiang Lu <canjiang.lu@samsung.com>,
6  *            Feng Li <feng.li@samsung.com>
7  *
8  * PROPRIETARY/CONFIDENTIAL
9  *
10  * This software is the confidential and proprietary information of
11  * SAMSUNG ELECTRONICS ("Confidential Information").
12  * You shall not disclose such Confidential Information and shall
13  * use it only in accordance with the terms of the license agreement
14  * you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
15  * representations or warranties about the suitability
16  * of the software, either express or implied, including but not
17  * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
18  * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
19  * a result of using, modifying or distributing this software or its derivatives.
20  *
21  */
22
23 #include <stdio.h>
24 #include <unicode/ustring.h>
25 #include <unicode/utypes.h>
26 #include <unicode/udat.h>
27 #include <unicode/udatpg.h>
28 #include <iniparser.h>
29 #include <dictionary.h>
30 #include <vconf-keys.h>
31 #include <vconf.h>
32 #include <gravel.h>
33 #include <extended-elm.h>
34 #include <supplement.h>
35 #include <memo-assist.h>
36 #include <appcore-common.h>
37
38 #define ICU_TIME_BUFFER 256
39 static UDateFormat* dfmt = NULL;
40
41 /**
42  * memo_get_doodle_title
43  *
44  * @brief
45  *
46  * @return
47  *
48  * @exception    None
49  *
50  * @remark       None
51  *
52  * @see
53  *
54  */
55 char *memo_get_doodle_title()
56 {
57     memo_data_list_t *l = NULL;
58     memo_data_list_t *t = NULL;
59     char buf[MEMO_BUFFER_SIZE];
60     int i = 0;
61     int d = 0;
62     l = memo_get_all_data_list();
63     for (t = l; t != NULL; t = t->next) {
64         if (t->md.has_doodle) {
65             d = atoi(t->md.content + strlen(DOODLE_TITLE_PREFIX));
66             i = (d > i) ? d : i;
67         }
68     }
69     i++;
70     snprintf(buf, MEMO_BUFFER_SIZE, "%s%04d", DOODLE_TITLE_PREFIX, i);
71     memo_free_data_list(l);
72     return strdup(buf);
73 }
74
75 void icu_init()
76 {
77     UErrorCode status = U_ZERO_ERROR;
78     const char *locale;
79     UChar ubuf[ICU_TIME_BUFFER];
80     UChar bestPattern[ICU_TIME_BUFFER];
81     UDateTimePatternGenerator *generator;
82     enum appcore_time_format timeformat;
83     char *timezone_id = NULL;
84     UChar utimezone_id[256] = {0,};
85
86     /* reset timezone according to vconf */
87     timezone_id = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
88     u_uastrcpy(utimezone_id, timezone_id);
89     SFREE(timezone_id);
90     ucal_setDefaultTimeZone(utimezone_id , &status);
91     /* init */
92     uloc_setDefault(getenv("LC_TIME"), &status); /* ICU API to set default locale */
93     locale = uloc_getDefault();
94     /* format */
95     appcore_get_timeformat(&timeformat);
96     if (timeformat==APPCORE_TIME_FORMAT_24) {
97         /* 14 May 09 15:37 */
98         u_strFromUTF8(ubuf, MEMO_BUFFER_SIZE, NULL, "dMMMyyHHmm", -1, &status);
99     } else {
100         /* 14 May 09 03:37 PM */
101         u_strFromUTF8(ubuf, MEMO_BUFFER_SIZE, NULL, "dMMMyyhhmma", -1, &status);
102     }
103     /* get pattern */
104     generator = udatpg_open(locale, &status);
105     udatpg_getBestPattern(generator, ubuf, u_strlen(ubuf), bestPattern, ICU_TIME_BUFFER, &status);
106     udatpg_close(generator);
107     /* format */
108     if (dfmt != NULL) {
109         udat_close(dfmt);
110     }
111     dfmt = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
112 }
113
114 /**
115  * memo_time_format
116  *
117  * @brief
118  *
119  * @param   [in] buf    buffer used to store formated time
120  *
121  * @param   [in] len    length of buf
122  *
123  * @param   [in] time  actual time
124  *
125  * @return
126  *
127  * @exception    None
128  *
129  * @remark       None
130  *
131  * @see
132  *
133  */
134 void memo_time_format(char *buf, int len, time_t time)
135 {
136     UErrorCode status = U_ZERO_ERROR;
137     UChar ubuf[ICU_TIME_BUFFER];
138
139     if (dfmt == NULL) {
140         icu_init();
141     }
142     udat_format(dfmt, (UDate)time*1000, ubuf, ICU_TIME_BUFFER, NULL, &status);
143     u_strToUTF8(buf, len, NULL, ubuf, -1, &status);
144 }
145
146 time_t memo_get_binary_release_date()
147 {
148     struct tm time = {0};
149     char *date = NULL;
150     dictionary *about_dic = iniparser_load("/etc/info.ini");
151
152     RETVIF(about_dic==NULL, 0);
153     date = iniparser_getstr(about_dic, "Build:Date");
154     strptime(date, "%Y.%m.%d", &time);
155     iniparser_freedict(about_dic);
156     return timelocal(&time);
157 }
158
159 void memo_com_dummy_cb(void *data, const char *msg, void *event)
160 {
161     LOGD("msg : %s\n", msg);
162 }
163
164 void memo_navigator_pop(Evas_Object *navi)
165 {
166     Elm_Object_Item *top_it = elm_naviframe_top_item_get(navi);
167     Evas_Object *eo = elm_object_item_content_get(top_it);
168     Evas_Object *prev_eo = evas_object_data_get(eo, "previous_obj");
169     if(prev_eo == NULL) { /* exit when view stack is empty */
170         elm_exit();
171     } else {
172         Evas_Smart_Cb cb = evas_object_data_get(prev_eo, "update_cb");
173         RETIF(cb == NULL);
174         void *cb_data = evas_object_data_get(prev_eo, "update_data");
175         cb(cb_data, NULL, NULL);
176     }
177     elm_naviframe_item_pop(navi);
178 }
179
180 Elm_Object_Item *memo_naviframe_item_push(Evas_Object *obj, const char *title_label,
181     Evas_Object *prev_btn, Evas_Object *next_btn, Evas_Object *content, const char *item_style)
182 {
183     Elm_Object_Item *top_it = elm_naviframe_top_item_get(obj);
184     if (top_it != NULL) {
185         Evas_Object *eo = elm_object_item_content_get(top_it);
186         if (eo != NULL) {
187             evas_object_data_set(content, "previous_obj", eo);
188         }
189     }
190
191     return elm_naviframe_item_push(obj, title_label, prev_btn, next_btn, content, item_style);
192 }
193
194 Evas_Object *memo_controlbar_add(Evas_Object *parent)
195 {
196         Evas_Object *toolbar = elm_toolbar_add(parent);
197         elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
198         elm_toolbar_homogeneous_set(toolbar, EINA_FALSE);
199         return toolbar;
200 }