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 + 30))
77 r = asprintf(&buf, "One minute ago");
78 else if (dt < (HOUR + 100))
79 r = asprintf(&buf, "%d minutes ago", (int)dt/60);
80 else if (dt < (HOUR * 4))
81 r = asprintf(&buf, "%d hours ago", (int)dt/3600);
83 struct tm *f_time = gmtime(&date);
84 EINA_SAFETY_ON_NULL_GOTO(f_time, err_gmtime);
85 r = asprintf(&buf, "%02d:%02d", f_time->tm_hour,
87 } else if (dt < WEEK) {
89 struct tm *tm = localtime(&date);
90 strftime(tmp, sizeof(tmp), "%A", tm);
92 r = asprintf(&buf, "%s, %d days ago", tmp, days);
95 struct tm *tm = localtime(&date);
96 strftime(tmp, sizeof(tmp), "%x", tm);
97 r = asprintf(&buf, "%s", tmp);
109 Evas_Object *picture_icon_get(Evas_Object *parent, const char *picture)
111 Evas_Object *icon = elm_icon_add(parent);
113 if (!picture || *picture == '\0')
114 elm_icon_standard_set(icon, "no-picture");
117 elm_icon_file_set(icon, picture, NULL);
121 prefix = efreet_config_home_get();
122 snprintf(path, sizeof(path), "%s/%s/%s", prefix, PACKAGE_NAME,
124 elm_image_file_set(icon, path, NULL);
130 Evas_Object *layout_add(Evas_Object *parent, const char *style)
132 Evas_Object *layout = elm_layout_add(parent);
133 if (!elm_layout_theme_set(layout, "layout", "dialer", style)) {
134 CRITICAL("No theme for 'elm/layout/dialer/%s' at %s",
136 evas_object_del(layout);
142 Eina_Bool util_init(const char *theme)
144 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
145 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
146 elm_app_info_set(util_init, "ofono-efl", "themes/default.edj");
148 snprintf(def_theme, sizeof(def_theme), "%s/themes/default.edj",
149 elm_app_data_dir_get());
151 elm_theme_extension_add(NULL, def_theme);
153 elm_theme_overlay_add(NULL, def_theme);
156 if (theme[0] != '/') {
157 if (eina_str_has_suffix(theme, ".edj")) {
158 snprintf(tmp, sizeof(tmp), "%s/themes/%s",
159 elm_app_data_dir_get(), theme);
161 snprintf(tmp, sizeof(tmp), "%s/themes/%s.edj",
162 elm_app_data_dir_get(), theme);
166 elm_theme_overlay_add(NULL, theme);
172 void util_shutdown(void)