+static struct task *get_selected_task(GtkTreeView *treeview)
+{
+ GtkTreePath *path;
+ GtkTreeViewColumn *cols;
+ gint *i;
+ struct task *task;
+
+ gtk_tree_view_get_cursor(treeview, &path, &cols);
+
+ if (path) {
+ i = gtk_tree_path_get_indices(path);
+
+ if (i)
+ printf("row selected: %d\n", *i);
+
+ task = tasks[*i];
+
+ gtk_tree_path_free(path);
+
+ return task;
+ }
+
+ return NULL;
+}
+
+static char *escape(const 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;
+ const char *ctxt;
+
+ task = get_selected_task(GTK_TREE_VIEW(w_treeview));
+
+ printf("tasksave_clicked_cbk %d\n", task->id);
+
+ 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);
+
+ txt = escape(txt);
+
+ printf("%s\n", txt);
+ }
+
+ ctxt = gtk_entry_get_text(w_description);
+ txt = escape(ctxt);
+
+ opts = malloc(1
+ + strlen(task->uuid)
+ + strlen(" modify description:\"")
+ + strlen(txt)
+ + strlen("\"")
+ + 1);
+ sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
+
+ task_exec(opts);
+
+ free(txt);
+
+ 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) {
+
+ 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;
+}
+