(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 15 Oct 2012 19:02:33 +0000 (19:02 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 15 Oct 2012 19:02:33 +0000 (19:02 +0000)
src/glade/gtask.glade
src/main.c

index 7d38739..fe9ca9b 100644 (file)
     <property name="default_width">640</property>
     <property name="default_height">480</property>
     <child>
-      <object class="GtkScrolledWindow" id="scrolledwindow2">
+      <object class="GtkPaned" id="paned1">
         <property name="visible">True</property>
         <property name="can_focus">True</property>
-        <property name="shadow_type">in</property>
+        <property name="orientation">vertical</property>
+        <property name="position">144</property>
+        <property name="position_set">True</property>
         <child>
-          <object class="GtkTreeView" id="treeview">
+          <object class="GtkScrolledWindow" id="scrolledwindow2">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="has_tooltip">True</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-selection"/>
-            </child>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkTreeViewColumn" id="treeviewcolumn1">
-                <property name="sizing">autosize</property>
-                <property name="min_width">10</property>
-                <property name="title" translatable="yes">Id</property>
+              <object class="GtkTreeView" id="treeview">
+                <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="GtkCellRendererText" id="cellrenderertext1"/>
-                  <attributes>
-                    <attribute name="text">0</attribute>
-                  </attributes>
+                  <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>
               </object>
             </child>
+          </object>
+          <packing>
+            <property name="resize">False</property>
+            <property name="shrink">True</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
             <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>
+              <object class="GtkBox" id="box2">
+                <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>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="shadow_type">in</property>
+                    <child>
+                      <object class="GtkTextView" id="taskdescription">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </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>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="box3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</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="GtkCellRendererText" id="cellrenderertext2"/>
-                  <attributes>
-                    <attribute name="text">1</attribute>
-                  </attributes>
+                  <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="position">2</property>
+              </packing>
             </child>
           </object>
+          <packing>
+            <property name="resize">True</property>
+            <property name="shrink">True</property>
+          </packing>
         </child>
       </object>
     </child>
index 7fade92..3f95c31 100644 (file)
 
 #include <gtk/gtk.h>
 
-
 struct task {
        int id;
        char *description;
        char *status;
+       char *uuid;
 };
 
 static struct task **tasks;
+static GtkTextView *w_description;
+static GtkTreeView *w_treeview;
 
 static char *task_exec(char *opts)
 {
@@ -45,6 +47,8 @@ static char *task_exec(char *opts)
        strcpy(cmd, "task rc.json.array=on ");
        strcat(cmd, opts);
 
+       printf("execute: %s\n", cmd);
+
        f = popen(cmd, "r");
 
        if (!f) {
@@ -120,6 +124,9 @@ 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, "uuid");
+               tasks[i]->uuid = strdup(json_object_get_string(json));
        }
 
        tasks[n] = NULL;
@@ -129,13 +136,12 @@ static struct task **get_all_tasks()
        return tasks;
 }
 
-static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
+static struct task *get_selected_task(GtkTreeView *treeview)
 {
        GtkTreePath *path;
        GtkTreeViewColumn *cols;
        gint *i;
-
-       printf("cursor_changed_cbk\n");
+       struct task *task;
 
        gtk_tree_view_get_cursor(treeview, &path, &cols);
 
@@ -144,18 +150,109 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
                
                if (i)
                        printf("row selected: %d\n", *i);
-               
 
+               task = tasks[*i];
+
+               gtk_tree_path_free(path);
+
+               return task;
        }
 
-       gtk_tree_path_free(path);
+       return NULL;
+}
+
+static char *escape(char *txt)
+{
+       char *result;
+       char *c;
+
+       result = malloc(2*strlen(txt)+1);
+       c = result;
+
+       while(*txt) {
+               switch(*txt) {
+               case '"':
+                       *c = '\\'; c++;
+                       *c = '"';
+                       break;
+               case '$':
+                       *c = '\\'; c++;
+                       *c = '$';
+                       break;
+               case '&':
+                       *c = '\\'; c++;
+                       *c = '&';
+                       break;
+               default:
+                       *c = *txt;
+               }
+               c++;
+               txt++;
+       }
+
+       *c = '\0';
+
+       return result;
+}
+
+static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
+{
+       struct task *task;
+       GtkTextBuffer *buf;
+       char *txt, *opts;
+       GtkTextIter sIter, eIter;
+
+       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);
+
+       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);
+
+       printf("%s\n", txt);
+
+       opts = malloc(1
+                     + strlen(task->uuid)
+                     + strlen(" modify description:\"")
+                     + strlen(txt)
+                     + strlen("\"")
+                     + 1);
+       sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
+
+       task_exec(opts);
+       
+       return FALSE;
+}
+
+static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
+{
+       struct task *task;
+       GtkTextBuffer *buf;
+
+       printf("cursor_changed_cbk\n");
+
+       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));
+
+       }
 
        return FALSE;
 }
+
 int main(int argc, char **argv)
 {
        GtkWidget *window;
-       GtkWidget *treeview;
+       GtkWidget *btn;
        GtkBuilder *builder;
        GtkTreeIter iter;
        int i;
@@ -171,9 +268,12 @@ int main(int argc, char **argv)
        window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
        printf("%p\n", window);
 
-       treeview = GTK_WIDGET(gtk_builder_get_object(builder, "treeview"));
+       w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
 
-       model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
+       w_description = GTK_TEXT_VIEW(gtk_builder_get_object(builder,
+                                                            "taskdescription"));
+
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
 
        tasks = get_all_tasks();
 
@@ -186,9 +286,13 @@ int main(int argc, char **argv)
                                   -1);
        }
 
-       g_signal_connect(treeview,
+       g_signal_connect(w_treeview,
                         "cursor-changed", (GCallback)cursor_changed_cbk, tasks);
 
+       btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
+       g_signal_connect(btn,
+                        "clicked", (GCallback)tasksave_clicked_cbk, tasks);
+
        g_object_unref(G_OBJECT(builder));
 
        gtk_widget_show_all(window);