added creation date, due, and start date in the list of tasks.
[ptask.git] / src / ui_tasktree.c
index e879b4d..8e46c25 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
+#define _XOPEN_SOURCE
+#include <time.h>
+
+#include <stdlib.h>
 #include <string.h>
 
 #include <gtk/gtk.h>
 
 #include <log.h>
+#include <ptime.h>
 #include <ui_projecttree.h>
+#include <ui_taskpanel.h>
 #include <ui_tasktree.h>
 
 static GtkTreeView *w_treeview;
@@ -32,7 +38,11 @@ enum {
        COL_DESCRIPTION,
        COL_PROJECT,
        COL_UUID,
-       COL_PRIORITY
+       COL_PRIORITY,
+       COL_URGENCY,
+       COL_CREATION_DATE,
+       COL_DUE,
+       COL_START
 };
 
 static int priority_to_int(const char *str)
@@ -74,6 +84,17 @@ static gint priority_cmp(GtkTreeModel *model,
                return 0;
 }
 
+int tasktree_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
+{
+       log_fct_enter();
+
+       ui_taskpanel_update(ui_tasktree_get_selected_task());
+
+       log_fct_exit();
+
+       return FALSE;
+}
+
 void ui_tasktree_init(GtkBuilder *builder)
 {
        GtkTreeModel *model;
@@ -118,6 +139,17 @@ void ui_tasktree_save_settings(GSettings *settings)
        g_settings_set_int(settings, "tasks-sort-order", sort_order);
 }
 
+const char *ui_tasktree_get_task_uuid()
+{
+       struct task *t;
+
+       t = ui_tasktree_get_selected_task();
+
+       if (t)
+               return t->uuid;
+       else
+               return NULL;
+}
 
 struct task *ui_tasktree_get_selected_task()
 {
@@ -159,6 +191,47 @@ struct task *ui_tasktree_get_selected_task()
        return result;
 }
 
+void ui_tasktree_set_selected_task(const char *uuid)
+{
+       GtkTreePath *path;
+       GtkTreeIter iter;
+       GtkTreeModel *model;
+       GValue value = {0,};
+       const char *c_uuid;
+
+       log_fct_enter();
+
+       if (current_tasks) {
+               model = gtk_tree_view_get_model(w_treeview);
+
+               if (!gtk_tree_model_get_iter_first(model, &iter))
+                       return ;
+
+               path = NULL;
+               while (gtk_tree_model_iter_next(model, &iter)) {
+                       gtk_tree_model_get_value(model,
+                                                &iter,
+                                                COL_UUID,
+                                                &value);
+                       c_uuid = g_value_get_string(&value);
+
+                       if (!strcmp(uuid, c_uuid)) {
+                               path = gtk_tree_model_get_path(model, &iter);
+                               break;
+                       }
+
+                       g_value_unset(&value);
+               }
+
+               if (!path)
+                       path = gtk_tree_path_new_first();
+               gtk_tree_view_set_cursor(w_treeview, path, NULL, FALSE);
+       }
+
+       log_fct_exit();
+}
+
+
 void ui_tasktree_update(struct task **tasks, const char *prj_filter)
 {
        GtkTreeModel *model;
@@ -166,7 +239,7 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter)
        struct task *task;
        GtkTreeIter iter;
        const char *prj;
-       GtkTreePath *p;
+       char *s;
 
        current_tasks = tasks;
 
@@ -189,17 +262,53 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter)
 
                        gtk_list_store_set(GTK_LIST_STORE(model),
                                           &iter,
-                                          COL_ID, (*tasks_cur)->id,
+                                          COL_ID,
+                                          (*tasks_cur)->id,
                                           COL_DESCRIPTION,
                                           (*tasks_cur)->description,
-                                          COL_PROJECT, prj,
-                                          COL_UUID, (*tasks_cur)->uuid,
-                                          COL_PRIORITY, (*tasks_cur)->priority,
+                                          COL_PROJECT,
+                                          prj,
+                                          COL_UUID,
+                                          (*tasks_cur)->uuid,
+                                          COL_PRIORITY,
+                                          (*tasks_cur)->priority,
+                                          COL_URGENCY,
+                                          (*tasks_cur)->urgency,
                                           -1);
-               }
 
-               p = gtk_tree_path_new_first();
-               gtk_tree_view_set_cursor(w_treeview, p, NULL, FALSE);
+                       if ((*tasks_cur)->start) {
+                               s = tm_to_str((*tasks_cur)->start);
+                               gtk_list_store_set
+                                       (GTK_LIST_STORE(model),
+                                        &iter,
+                                        COL_START,
+                                        s,
+                                        -1);
+                               free(s);
+                       }
+
+                       if ((*tasks_cur)->due) {
+                               s = tm_to_str((*tasks_cur)->due);
+                               gtk_list_store_set
+                                       (GTK_LIST_STORE(model),
+                                        &iter,
+                                        COL_DUE,
+                                        s,
+                                        -1);
+                               free(s);
+                       }
+
+                       if ((*tasks_cur)->entry) {
+                               s = tm_to_str((*tasks_cur)->entry);
+                               gtk_list_store_set
+                                       (GTK_LIST_STORE(model),
+                                        &iter,
+                                        COL_CREATION_DATE,
+                                        s,
+                                        -1);
+                               free(s);
+                       }
+               }
        }
 
 }