messages implementation.
[profile/ivi/lemolo.git] / utils / util.c
index 39344ff..7b72681 100644 (file)
@@ -73,23 +73,21 @@ char *date_format(time_t date)
 
        if (dt < 30)
                r = asprintf(&buf, "Just now");
-       else if (dt < (MINUTE + 30))
+       else if (dt < (MINUTE * 2))
                r = asprintf(&buf, "One minute ago");
-       else if (dt < (HOUR + 100))
-               r = asprintf(&buf, "%d minutes ago", (int)dt/60);
+       else if (dt < (HOUR * 2))
+               r = asprintf(&buf, "%dmin ago", (int)dt/60);
        else if (dt < (HOUR * 4))
-               r = asprintf(&buf, "%d hours ago", (int)dt/3600);
+               r = asprintf(&buf, "%dh ago", (int)dt/3600);
        else if (dt <= DAY) {
-               struct tm *f_time = gmtime(&date);
-               EINA_SAFETY_ON_NULL_GOTO(f_time, err_gmtime);
+               struct tm *f_time = localtime(&date);
                r = asprintf(&buf,  "%02d:%02d", f_time->tm_hour,
                                f_time->tm_min);
        } else if (dt < WEEK) {
                char tmp[256];
                struct tm *tm = localtime(&date);
                strftime(tmp, sizeof(tmp), "%A", tm);
-               int days = dt / DAY;
-               r = asprintf(&buf, "%s, %d days ago", tmp, days);
+               r = asprintf(&buf, "%s", tmp);
        } else {
                char tmp[256];
                struct tm *tm = localtime(&date);
@@ -101,9 +99,35 @@ char *date_format(time_t date)
                buf = strdup("");
 
        return buf;
+}
+
+char *date_short_format(time_t date)
+{
+       time_t now = time(NULL);
+       double dt = difftime(now, date);
+       char *buf;
+       int r;
 
-err_gmtime:
-       return strdup("");
+       if (dt <= DAY) {
+               struct tm *f_time = localtime(&date);
+               r = asprintf(&buf,  "%02d:%02d", f_time->tm_hour,
+                               f_time->tm_min);
+       } else if (dt < WEEK) {
+               char tmp[256];
+               struct tm *tm = localtime(&date);
+               strftime(tmp, sizeof(tmp), "%A", tm);
+               r = asprintf(&buf, "%s", tmp);
+       } else {
+               char tmp[256];
+               struct tm *tm = localtime(&date);
+               strftime(tmp, sizeof(tmp), "%x", tm);
+               r = asprintf(&buf, "%s", tmp);
+       }
+
+       if (r < 0)
+               buf = strdup("");
+
+       return buf;
 }
 
 Evas_Object *picture_icon_get(Evas_Object *parent, const char *picture)
@@ -113,12 +137,16 @@ Evas_Object *picture_icon_get(Evas_Object *parent, const char *picture)
        if (!picture || *picture == '\0')
                elm_icon_standard_set(icon, "no-picture");
        else {
+#ifdef HAVE_TIZEN
+               elm_icon_file_set(icon, picture, NULL);
+#else
                char path[PATH_MAX];
                const char *prefix;
                prefix = efreet_config_home_get();
                snprintf(path, sizeof(path), "%s/%s/%s", prefix, PACKAGE_NAME,
                                picture);
                elm_image_file_set(icon, path, NULL);
+#endif
        }
        return icon;
 }
@@ -126,8 +154,8 @@ Evas_Object *picture_icon_get(Evas_Object *parent, const char *picture)
 Evas_Object *layout_add(Evas_Object *parent, const char *style)
 {
        Evas_Object *layout = elm_layout_add(parent);
-       if (!elm_layout_theme_set(layout, "layout", "dialer", style)) {
-               CRITICAL("No theme for 'elm/layout/dialer/%s' at %s",
+       if (!elm_layout_theme_set(layout, "layout", "ofono-efl", style)) {
+               CRITICAL("No theme for 'elm/layout/ofono-efl/%s' at %s",
                                style, def_theme);
                evas_object_del(layout);
                return NULL;