8 #include <Elementary.h>
13 static char def_theme[PATH_MAX] = "";
15 /* TODO: find a configurable way to format the number.
16 * Right now it's: 1-234-567-8901 as per
17 * http://en.wikipedia.org/wiki/Local_conventions_for_writing_telephone_numbers#North_America
19 * IDEA: use ordered set of regexp -> replacement.
21 char *phone_format(const char *number)
30 slen = strlen(number);
34 if ((slen <= 4) || (slen > 12))
37 if ((slen == 12) && (number[0] != '+'))
40 for (i = 0; i < slen; i++) {
41 if ((number[i] < '0') || (number[i] > '9')) {
42 if ((number[i] == '+') && (i == 0))
48 d = eina_strbuf_new();
49 eina_strbuf_append_length(d, number, slen);
50 if ((slen > 4) && (number[slen - 5] != '+'))
51 eina_strbuf_insert_char(d, '-', slen - 4);
53 if ((slen > 7) && (number[slen - 8] != '+'))
54 eina_strbuf_insert_char(d, '-', slen - 7);
55 if ((slen > 10) && (number[slen - 11] != '+'))
56 eina_strbuf_insert_char(d, '-', slen - 10);
59 ret = eina_strbuf_string_steal(d);
64 return strdup(number);
67 char *date_format(time_t date)
69 time_t now = time(NULL);
70 double dt = difftime(now, date);
75 r = asprintf(&buf, "Just now");
76 else if (dt < (MINUTE * 2))
77 r = asprintf(&buf, "One minute ago");
78 else if (dt < (HOUR * 2))
79 r = asprintf(&buf, "%dmin ago", (int)dt/60);
80 else if (dt < (HOUR * 4))
81 r = asprintf(&buf, "%dh ago", (int)dt/3600);
83 struct tm *f_time = localtime(&date);
84 r = asprintf(&buf, "%02d:%02d", f_time->tm_hour,
86 } else if (dt < WEEK) {
88 struct tm *tm = localtime(&date);
89 strftime(tmp, sizeof(tmp), "%A", tm);
90 r = asprintf(&buf, "%s", tmp);
93 struct tm *tm = localtime(&date);
94 strftime(tmp, sizeof(tmp), "%x", tm);
95 r = asprintf(&buf, "%s", tmp);
104 char *date_short_format(time_t date)
106 time_t now = time(NULL);
107 double dt = difftime(now, date);
112 struct tm *f_time = localtime(&date);
113 r = asprintf(&buf, "%02d:%02d", f_time->tm_hour,
115 } else if (dt < WEEK) {
117 struct tm *tm = localtime(&date);
118 strftime(tmp, sizeof(tmp), "%A", tm);
119 r = asprintf(&buf, "%s", tmp);
122 struct tm *tm = localtime(&date);
123 strftime(tmp, sizeof(tmp), "%x", tm);
124 r = asprintf(&buf, "%s", tmp);
133 Evas_Object *picture_icon_get(Evas_Object *parent, const char *picture)
135 Evas_Object *icon = elm_icon_add(parent);
137 if (!picture || *picture == '\0')
138 elm_icon_standard_set(icon, "no-picture");
141 elm_icon_file_set(icon, picture, NULL);
145 prefix = efreet_config_home_get();
146 snprintf(path, sizeof(path), "%s/%s/%s", prefix, PACKAGE_NAME,
148 elm_image_file_set(icon, path, NULL);
154 Evas_Object *layout_add(Evas_Object *parent, const char *style)
156 Evas_Object *layout = elm_layout_add(parent);
157 if (!elm_layout_theme_set(layout, "layout", "ofono-efl", style)) {
158 CRITICAL("No theme for 'elm/layout/ofono-efl/%s' at %s",
160 evas_object_del(layout);
166 Eina_Bool util_init(const char *theme)
168 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
169 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
170 elm_app_info_set(util_init, "ofono-efl", "themes/default.edj");
172 snprintf(def_theme, sizeof(def_theme), "%s/themes/default.edj",
173 elm_app_data_dir_get());
175 elm_theme_extension_add(NULL, def_theme);
177 elm_theme_overlay_add(NULL, def_theme);
180 if (theme[0] != '/') {
181 if (eina_str_has_suffix(theme, ".edj")) {
182 snprintf(tmp, sizeof(tmp), "%s/themes/%s",
183 elm_app_data_dir_get(), theme);
185 snprintf(tmp, sizeof(tmp), "%s/themes/%s.edj",
186 elm_app_data_dir_get(), theme);
190 elm_theme_overlay_add(NULL, theme);
196 void util_shutdown(void)