(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 16 Oct 2012 12:07:26 +0000 (12:07 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 16 Oct 2012 12:07:26 +0000 (12:07 +0000)
src/glade/gtask.glade
src/main.c
src/tw.c
src/tw.h

index 9e15293..2873a85 100644 (file)
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="liststore2">
+    <columns>
+      <!-- column-name gchararray1 -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">pending</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">completed</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkWindow" id="window">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">gtask</property>
@@ -31,6 +45,9 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
+                <property name="margin_left">4</property>
+                <property name="margin_right">4</property>
+                <property name="margin_top">4</property>
               </object>
               <packing>
                 <property name="expand">False</property>
               </packing>
             </child>
             <child>
-              <placeholder/>
-            </child>
-            <child>
-              <placeholder/>
+              <object class="GtkBox" id="box5">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_left">4</property>
+                <property name="margin_right">4</property>
+                <property name="margin_top">4</property>
+                <child>
+                  <object class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">4</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="label" translatable="yes">Status:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBox" id="status">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">4</property>
+                    <property name="margin_right">4</property>
+                    <property name="margin_top">4</property>
+                    <property name="model">liststore2</property>
+                    <property name="active">0</property>
+                    <child>
+                      <object class="GtkCellRendererText" id="cellrenderertext4"/>
+                      <attributes>
+                        <attribute name="text">0</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
             </child>
           </object>
           <packing>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">1</property>
+                        <property name="top_attach">2</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="top_attach">1</property>
+                        <property name="top_attach">2</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                       <object class="GtkEntry" id="taskdescription">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="margin_left">4</property>
+                        <property name="margin_right">4</property>
+                        <property name="margin_top">4</property>
+                        <property name="margin_bottom">4</property>
                         <property name="invisible_char">•</property>
                         <property name="invisible_char_set">True</property>
                       </object>
                         <property name="height">1</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="label3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_left">4</property>
+                        <property name="margin_right">4</property>
+                        <property name="margin_top">4</property>
+                        <property name="margin_bottom">4</property>
+                        <property name="label" translatable="yes">Project:</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkEntry" id="taskproject">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="margin_left">4</property>
+                        <property name="margin_right">4</property>
+                        <property name="margin_top">4</property>
+                        <property name="invisible_char">•</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">True</property>
index 49e3622..78beb8f 100644 (file)
 static struct task **tasks;
 static GtkTextView *w_note;
 static GtkEntry *w_description;
+static GtkEntry *w_project;
 static GtkTreeView *w_treeview;
 static GtkWidget *w_tasksave_btn;
+static GtkComboBox *w_status;
 
 static struct task *get_selected_task(GtkTreeView *treeview)
 {
@@ -62,6 +64,23 @@ static struct task *get_selected_task(GtkTreeView *treeview)
        return task;
 }
 
+static void clear_task_panel()
+{
+       GtkTextBuffer *buf;
+
+       gtk_widget_set_sensitive(w_tasksave_btn, 0);
+       
+       buf = gtk_text_view_get_buffer(w_note);
+       gtk_text_buffer_set_text(buf, "", 0);
+       gtk_widget_set_sensitive(GTK_WIDGET(w_note), 0);
+       
+       gtk_entry_set_text(w_description, "");
+       gtk_widget_set_sensitive(GTK_WIDGET(w_description), 0);
+       
+       gtk_entry_set_text(w_project, "");
+       gtk_widget_set_sensitive(GTK_WIDGET(w_project), 0);
+}
+
 static void refresh()
 {
        GtkTreeModel *model;
@@ -69,8 +88,23 @@ static void refresh()
        struct task *task;
        int i;
        GtkTreeIter iter;
-
-       tasks = get_all_tasks();
+       int status;
+
+       clear_task_panel();
+
+       status = gtk_combo_box_get_active(w_status);
+       printf("status: %d\n", status);
+       
+       switch (status) {
+       case 0:
+               tasks = get_all_tasks("pending");
+               break;
+       case 1:
+               tasks = get_all_tasks("completed");
+               break;
+       default:
+               tasks = get_all_tasks("pending");
+       }
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
        gtk_list_store_clear(GTK_LIST_STORE(model));
@@ -145,6 +179,14 @@ static int refresh_clicked_cbk(GtkButton *btn, gpointer data)
        return FALSE;
 }
 
+static int status_changed_cbk(GtkComboBox *w, gpointer data)
+{
+       printf("status_changed_cbk\n");
+       refresh();
+
+       return FALSE;
+}
+
 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
 {
        struct task *task;
@@ -156,17 +198,28 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
 
        if (task) {
 
-               if (task->note) {
-                       buf = gtk_text_view_get_buffer(w_note);
+               buf = gtk_text_view_get_buffer(w_note);
+               if (task->note)
                        gtk_text_buffer_set_text(buf,
                                                 task->note,
                                                 strlen(task->note));
-               }
+               else
+                       gtk_text_buffer_set_text(buf, "", 0);
+               gtk_widget_set_sensitive(GTK_WIDGET(w_note), 1);
 
                gtk_entry_set_text(w_description, task->description);
+               gtk_widget_set_sensitive(GTK_WIDGET(w_description), 1);
+
+               if (task->project)
+                       gtk_entry_set_text(w_project, task->project);
+               else
+                       gtk_entry_set_text(w_project, "");
+               gtk_widget_set_sensitive(GTK_WIDGET(w_project), 1);
+
                gtk_widget_set_sensitive(w_tasksave_btn, 1);
        } else {
-               gtk_widget_set_sensitive(w_tasksave_btn, 0);
+               printf("clear task widgets\n");
+               clear_task_panel();
        }
 
        return FALSE;
@@ -192,13 +245,17 @@ int main(int argc, char **argv)
 
        w_description = GTK_ENTRY(gtk_builder_get_object(builder,
                                                         "taskdescription"));
+       w_project = GTK_ENTRY(gtk_builder_get_object(builder, "taskproject"));
+       w_status = GTK_COMBO_BOX(gtk_builder_get_object(builder, "status"));
 
        refresh();
 
        g_signal_connect(w_treeview,
                         "cursor-changed", (GCallback)cursor_changed_cbk,
                         tasks);
-
+       g_signal_connect(w_status,
+                        "changed", (GCallback)status_changed_cbk,
+                        tasks);
        btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
        g_signal_connect(btn,
                         "clicked", (GCallback)tasksave_clicked_cbk, tasks);
index e2a7bca..7ed0ae1 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -86,13 +86,18 @@ static struct json_object *task_exec_json(char *opts)
        return NULL;
 }
 
-struct task **get_all_tasks()
+struct task **get_all_tasks(const char *status)
 {
        int i, n;
        struct json_object *jtasks, *jtask, *json;
        struct task **tasks;
+       char *opts;
 
-       jtasks = task_exec_json("export");
+       opts = malloc(strlen("export status:") + strlen(status) + 1);
+       sprintf(opts, "export status:%s", status);
+
+       jtasks = task_exec_json(opts);
+       free(opts);
 
        if (!jtasks)
                return NULL;
index 5942fa1..4bf2324 100644 (file)
--- a/src/tw.h
+++ b/src/tw.h
@@ -29,7 +29,7 @@ struct task {
        char *project;
 };
 
-struct task **get_all_tasks();
+struct task **get_all_tasks(const char *status);
 char *task_exec(char *opts);
 char *escape(const char *txt);