From: Jean-Philippe Orsini Date: Wed, 27 Nov 2013 07:24:46 +0000 (+0000) Subject: new task diag allow to set description and priority X-Git-Tag: v0.0.6~76 X-Git-Url: http://git.wpitchoune.net/gitweb/?p=ptask.git;a=commitdiff_plain;h=2a51512c32c229eb2d6a8aeb9aa4a78d1f52256d new task diag allow to set description and priority --- diff --git a/NEWS b/NEWS index ca0257e..2c2817f 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ v0.0.4 * added window position and size restore. * added tasks sort column/order restore. * fixed error message displayed when a note does not exist. + * new task dialog allow to set description and priority. v0.0.3 ------ diff --git a/src/glade/ptask.glade b/src/glade/ptask.glade index e748459..c56a143 100644 --- a/src/glade/ptask.glade +++ b/src/glade/ptask.glade @@ -151,7 +151,7 @@ 4 4 prioritystore - 0 + 2 diff --git a/src/tw.c b/src/tw.c index 30f5dcb..cbf3d61 100644 --- a/src/tw.c +++ b/src/tw.c @@ -116,7 +116,7 @@ static char *tw_exec(char *opts) return task_exec(opts2); } -static struct json_object *task_exec_json(char *opts) +static struct json_object *task_exec_json(const char *opts) { struct json_object *o; char *str, *cmd; @@ -147,7 +147,9 @@ struct task **tw_get_all_tasks(const char *status) char *opts; opts = malloc(strlen("export status:") + strlen(status) + 1); - sprintf(opts, "export status:%s", status); + + strcpy(opts, "export status:"); + strcat(opts, status); jtasks = task_exec_json(opts); free(opts); @@ -211,16 +213,12 @@ static char *escape(const char *txt) while (*txt) { switch (*txt) { case '"': - *c = '\\'; c++; - *c = '"'; - break; case '$': - *c = '\\'; c++; - *c = '$'; - break; case '&': + case '<': + case '>': *c = '\\'; c++; - *c = '&'; + *c = *txt; break; default: *c = *txt; @@ -297,24 +295,44 @@ void tw_modify_priority(const char *uuid, const char *priority) free(opts); } -void tw_add(const char *newdesc) +void tw_add(const char *newdesc, const char *prj, const char *prio) { - char *str; - char *opts; - - str = escape(newdesc); - - opts = malloc(1 - + strlen(" add \"") - + strlen(str) + char *opts, *eprj; + + eprj = escape(prj); + + opts = malloc(strlen(" add") + + strlen(" priority:") + + 1 + + strlen(" project:\\\"") + + strlen(eprj) + + strlen("\\\"") + + strlen(" \"") + + strlen(newdesc) + strlen("\"") + 1); - sprintf(opts, " add \"%s\"", str); + + strcpy(opts, " add"); + + if (prio && strlen(prio) == 1) { + strcat(opts, " priority:"); + strcat(opts, prio); + } + + if (eprj && strlen(prj)) { + strcat(opts, " project:\\\""); + strcat(opts, eprj); + strcat(opts, "\\\""); + } + + strcat(opts, " \""); + strcat(opts, newdesc); + strcat(opts, " \""); tw_exec(opts); - free(str); free(opts); + free(eprj); } void tw_done(const char *uuid) diff --git a/src/tw.h b/src/tw.h index 3a26712..41a1789 100644 --- a/src/tw.h +++ b/src/tw.h @@ -35,7 +35,7 @@ void tw_modify_description(const char *uuid, const char *newdesc); void tw_modify_project(const char *uuid, const char *newproj); void tw_modify_priority(const char *uuid, const char *priority); void tw_done(const char *uuid); -void tw_add(const char *newdesc); +void tw_add(const char *newdesc, const char *prj, const char *prio); void tw_task_list_free(struct task **tasks); #endif diff --git a/src/ui_newtask_diag.c b/src/ui_newtask_diag.c index 96d0291..fdfec87 100644 --- a/src/ui_newtask_diag.c +++ b/src/ui_newtask_diag.c @@ -23,15 +23,34 @@ #include #include +static const char *ui_get_priority(GtkComboBox *combo) +{ + int prio; + + prio = gtk_combo_box_get_active(combo); + + switch (prio) { + case 3: + return "H"; + case 2: + return "M"; + case 1: + return "L"; + default: + return ""; + } +} + void ui_newtask() { gint result; static GtkDialog *diag; GtkBuilder *builder; GtkEntry *entry; - const char *ctxt; + const char *desc, *prj, *prio; + GtkComboBox *combo; - log_debug("newtask_clicked_cbk"); + log_debug("ui_newtask()"); builder = gtk_builder_new(); gtk_builder_add_from_file @@ -44,17 +63,29 @@ void ui_newtask() result = gtk_dialog_run(diag); if (result == GTK_RESPONSE_ACCEPT) { - log_debug("ok"); + log_debug("ui_newtask(): ok"); + entry = GTK_ENTRY(gtk_builder_get_object (builder, "diag_tasknew_description")); - ctxt = gtk_entry_get_text(entry); + desc = gtk_entry_get_text(entry); + + entry = GTK_ENTRY(gtk_builder_get_object + (builder, "diag_tasknew_project")); + prj = gtk_entry_get_text(entry); + + combo = GTK_COMBO_BOX(gtk_builder_get_object + (builder, "diag_tasknew_priority")); + prio = ui_get_priority(combo); - log_debug("%s", ctxt); + log_debug("ui_newtask(): description=%s project=%s priority=%d", + desc, + prj, + prio); - tw_add(ctxt); + tw_add(desc, prj, prio); refresh(); } else { - log_debug("cancel"); + log_debug("ui_newtask(): cancel"); } g_object_unref(G_OBJECT(builder));