(no commit message)
[prss.git] / src / main.c
index 2661e4a..59f3999 100644 (file)
@@ -51,7 +51,8 @@ enum {
 
 enum {
        COL_HEADLINE_TITLE,
-       COL_HEADLINE_ID
+       COL_HEADLINE_ID,
+       COL_HEADLINE_DATE
 };
 
 static struct option long_options[] = {
@@ -276,14 +277,37 @@ static struct headline *get_selected_headline(GtkTreeIter *iter)
        return NULL;
 }
 
+static char *headline_get_formated_headline(struct headline *h)
+{
+       if (h->unread)
+               return g_strdup_printf("<b>%s</b>", h->title);
+       else
+               return strdup(h->title);
+}
+
+static char *headline_get_date(struct headline *h)
+{
+       struct tm *tmp;
+       char date[200];
+
+       tmp = localtime(&h->date);
+       
+       if (h->unread)
+               strftime(date, sizeof(date), "<b>%D</b>", tmp);
+       else
+               strftime(date, sizeof(date), "%D", tmp);
+
+       return strdup(date);
+}
+
 int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
 {
        GtkTreeIter iter;
        GtkTreeModel *headline_model;
        GtkListStore *headline_store;
        struct feed *feed;
-       struct headline **headlines;
-       char *title;
+       struct headline **headlines, *h;
+       char *title, *date;
 
        if (model_state)
                return TRUE;
@@ -303,22 +327,23 @@ int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
                        while (headlines && *headlines) {
                                gtk_list_store_append(headline_store, &iter);
 
-                               if ((*headlines)->unread)
-                                       title = g_strdup_printf
-                                               ("<b>%s</b>",
-                                                (*headlines)->title);
-                               else
-                                       title = strdup((*headlines)->title);
+                               h = *headlines;
+
+                               title = headline_get_formated_headline(h);
+                               date = headline_get_date(h);
 
                                gtk_list_store_set(headline_store,
                                                   &iter,
                                                   COL_HEADLINE_TITLE,
                                                   title,
                                                   COL_HEADLINE_ID,
-                                                  (*headlines)->id,
+                                                  h->id,
+                                                  COL_HEADLINE_DATE,
+                                                  date,
                                                   -1);
 
-                               free(title);
+                               g_free(title);
+                               free(date);
 
                                headlines++;
                        }