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

index fe9ca9b..9e15293 100644 (file)
@@ -3,9 +3,11 @@
   <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkListStore" id="liststore1">
     <columns>
-      <!-- column-name gint1 -->
+      <!-- column-name id -->
       <column type="gint"/>
-      <!-- column-name gchararray1 -->
+      <!-- column-name description -->
+      <column type="gchararray"/>
+      <!-- column-name project -->
       <column type="gchararray"/>
     </columns>
   </object>
     <property name="default_width">640</property>
     <property name="default_height">480</property>
     <child>
-      <object class="GtkPaned" id="paned1">
+      <object class="GtkBox" id="box1">
         <property name="visible">True</property>
-        <property name="can_focus">True</property>
+        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <property name="position">144</property>
-        <property name="position_set">True</property>
         <child>
-          <object class="GtkScrolledWindow" id="scrolledwindow2">
+          <object class="GtkBox" id="box4">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="shadow_type">in</property>
+            <property name="can_focus">False</property>
             <child>
-              <object class="GtkTreeView" id="treeview">
+              <object class="GtkButton" id="refresh">
+                <property name="label" translatable="yes">refresh</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="has_tooltip">False</property>
-                <property name="model">liststore1</property>
-                <property name="headers_clickable">False</property>
-                <property name="expander_column">treeviewcolumn1</property>
-                <property name="search_column">0</property>
-                <property name="enable_grid_lines">both</property>
-                <property name="enable_tree_lines">True</property>
-                <property name="tooltip_column">-1</property>
-                <child internal-child="selection">
-                  <object class="GtkTreeSelection" id="treeview-selection1"/>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="treeviewcolumn1">
-                    <property name="sizing">autosize</property>
-                    <property name="min_width">10</property>
-                    <property name="title" translatable="yes">Id</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="cellrenderertext1"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="treeviewcolumn2">
-                    <property name="sizing">autosize</property>
-                    <property name="fixed_width">10</property>
-                    <property name="min_width">30</property>
-                    <property name="title" translatable="yes">Description</property>
-                    <property name="expand">True</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="cellrenderertext2"/>
-                      <attributes>
-                        <attribute name="text">1</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
+                <property name="receives_default">True</property>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
             </child>
           </object>
           <packing>
-            <property name="resize">False</property>
-            <property name="shrink">True</property>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
           </packing>
         </child>
         <child>
-          <object class="GtkBox" id="box1">
+          <object class="GtkPaned" id="paned1">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
+            <property name="can_focus">True</property>
             <property name="orientation">vertical</property>
+            <property name="position">144</property>
+            <property name="position_set">True</property>
             <child>
-              <object class="GtkBox" id="box2">
+              <object class="GtkScrolledWindow" id="scrolledwindow2">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkLabel" id="label1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label" translatable="yes">Description:</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
+                <property name="can_focus">True</property>
+                <property name="margin_bottom">4</property>
+                <property name="shadow_type">in</property>
                 <child>
-                  <object class="GtkScrolledWindow" id="scrolledwindow1">
+                  <object class="GtkTreeView" id="treeview">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="shadow_type">in</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="model">liststore1</property>
+                    <property name="headers_clickable">False</property>
+                    <property name="expander_column">treeviewcolumn1</property>
+                    <property name="search_column">0</property>
+                    <property name="enable_grid_lines">both</property>
+                    <property name="enable_tree_lines">True</property>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection" id="treeview-selection"/>
+                    </child>
                     <child>
-                      <object class="GtkTextView" id="taskdescription">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                        <property name="sizing">autosize</property>
+                        <property name="min_width">10</property>
+                        <property name="title" translatable="yes">Id</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext1"/>
+                          <attributes>
+                            <attribute name="text">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn3">
+                        <property name="min_width">10</property>
+                        <property name="title" translatable="yes">Project</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext3"/>
+                          <attributes>
+                            <attribute name="text">2</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+                        <property name="sizing">autosize</property>
+                        <property name="fixed_width">10</property>
+                        <property name="min_width">30</property>
+                        <property name="title" translatable="yes">Description</property>
+                        <property name="expand">True</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                          <attributes>
+                            <attribute name="text">1</attribute>
+                          </attributes>
+                        </child>
                       </object>
                     </child>
                   </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="resize">False</property>
+                <property name="shrink">True</property>
               </packing>
             </child>
             <child>
-              <object class="GtkBox" id="box3">
+              <object class="GtkBox" id="box2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
                 <child>
-                  <object class="GtkButton" id="tasksave">
-                    <property name="label" translatable="yes">OK</property>
+                  <object class="GtkGrid" id="grid2">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="image_position">top</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>
+                    <child>
+                      <object class="GtkLabel" id="label1">
+                        <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">Description:</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label2">
+                        <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">Note:</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="GtkScrolledWindow" id="scrolledwindow1">
+                        <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="hexpand">True</property>
+                        <property name="vexpand">True</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="GtkTextView" id="tasknote">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                          </object>
+                        </child>
+                      </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>
+                    <child>
+                      <object class="GtkEntry" id="taskdescription">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">•</property>
+                        <property name="invisible_char_set">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">0</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
+                    <property name="expand">True</property>
                     <property name="fill">True</property>
-                    <property name="position">0</property>
+                    <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="taskcancel">
-                    <property name="label" translatable="yes">Cancel</property>
+                  <object class="GtkBox" id="box3">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">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>
+                    <child>
+                      <object class="GtkButton" id="tasksave">
+                        <property name="label" translatable="yes">OK</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="image_position">top</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="taskcancel">
+                        <property name="label" translatable="yes">Cancel</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
-                    <property name="fill">True</property>
+                    <property name="fill">False</property>
                     <property name="position">2</property>
                   </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
+                <property name="resize">True</property>
+                <property name="shrink">True</property>
               </packing>
             </child>
           </object>
           <packing>
-            <property name="resize">True</property>
-            <property name="shrink">True</property>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
           </packing>
         </child>
       </object>
index 3f95c31..62fa99c 100644 (file)
@@ -29,10 +29,13 @@ struct task {
        char *description;
        char *status;
        char *uuid;
+       char *note;
+       char *project;
 };
 
 static struct task **tasks;
-static GtkTextView *w_description;
+static GtkTextView *w_note;
+static GtkEntry *w_description;
 static GtkTreeView *w_treeview;
 
 static char *task_exec(char *opts)
@@ -125,8 +128,17 @@ static struct task **get_all_tasks()
                json = json_object_object_get(jtask, "status");
                tasks[i]->status = strdup(json_object_get_string(json));
 
+               json = json_object_object_get(jtask, "project");
+               if (json)
+                       tasks[i]->project
+                               = strdup(json_object_get_string(json));
+               else
+                       tasks[i]->project = NULL;
+
                json = json_object_object_get(jtask, "uuid");
                tasks[i]->uuid = strdup(json_object_get_string(json));
+
+               tasks[i]->note = NULL;
        }
 
        tasks[n] = NULL;
@@ -161,7 +173,7 @@ static struct task *get_selected_task(GtkTreeView *treeview)
        return NULL;
 }
 
-static char *escape(char *txt)
+static char *escape(const char *txt)
 {
        char *result;
        char *c;
@@ -201,20 +213,26 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
        GtkTextBuffer *buf;
        char *txt, *opts;
        GtkTextIter sIter, eIter;
+       const char *ctxt;
 
        task = get_selected_task(GTK_TREE_VIEW(w_treeview));
 
        printf("tasksave_clicked_cbk %d\n", task->id);  
 
-       buf = gtk_text_view_get_buffer(w_description);
+       if (task->note) {
+               buf = gtk_text_view_get_buffer(w_note);
 
-       gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
-       gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
-       txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
+               gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
+               gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
+               txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
 
-       txt = escape(txt);
+               txt = escape(txt);
+
+               printf("%s\n", txt);
+       }
 
-       printf("%s\n", txt);
+       ctxt = gtk_entry_get_text(w_description);
+       txt = escape(ctxt);
 
        opts = malloc(1
                      + strlen(task->uuid)
@@ -223,8 +241,10 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
                      + strlen("\"")
                      + 1);
        sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
-
+       
        task_exec(opts);
+
+       free(txt);
        
        return FALSE;
 }
@@ -239,11 +259,15 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
        task = get_selected_task(treeview);
 
        if (task) {
-               buf = gtk_text_view_get_buffer(w_description);
-               gtk_text_buffer_set_text(buf,
-                                        task->description,
-                                        strlen(task->description));
 
+               if (task->note) {
+                       buf = gtk_text_view_get_buffer(w_note);
+                       gtk_text_buffer_set_text(buf,
+                                                task->note,
+                                                strlen(task->note));
+               }
+
+               gtk_entry_set_text(w_description, task->description);
        }
 
        return FALSE;
@@ -258,6 +282,7 @@ int main(int argc, char **argv)
        int i;
        GtkTreeModel *model;
        struct task **tasks_cur;
+       struct task *task;
 
        gtk_init(NULL, NULL);
        builder = gtk_builder_new();
@@ -270,15 +295,26 @@ int main(int argc, char **argv)
 
        w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
 
-       w_description = GTK_TEXT_VIEW(gtk_builder_get_object(builder,
-                                                            "taskdescription"));
+       w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
+
+       w_description = GTK_ENTRY(gtk_builder_get_object(builder,
+                                                        "taskdescription"));
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
 
        tasks = get_all_tasks();
 
        for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
+               task = (*tasks_cur);
+
                gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+               
+               if (task->project)
+                       gtk_list_store_set(GTK_LIST_STORE(model),
+                                          &iter,
+                                          2, task->project,
+                                          -1);
+
                gtk_list_store_set(GTK_LIST_STORE(model),
                                   &iter,
                                   0, (*tasks_cur)->id,