Imported Upstream version 0.0.5
[ptask-pkg-ubuntu.git] / src / ui_newtask_diag.c
1 /*
2  * Copyright (C) 2012-2013 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <gtk/gtk.h>
21
22 #include <log.h>
23 #include <tw.h>
24 #include <ui.h>
25
26 static const char *ui_get_priority(GtkComboBox *combo)
27 {
28         int prio;
29
30         prio = gtk_combo_box_get_active(combo);
31
32         switch (prio) {
33         case 3:
34                 return "H";
35         case 2:
36                 return "M";
37         case 1:
38                 return "L";
39         default:
40                 return "";
41         }
42 }
43
44 void ui_newtask()
45 {
46         gint result;
47         static GtkDialog *diag;
48         GtkBuilder *builder;
49         GtkEntry *entry;
50         const char *desc, *prj, *prio;
51         GtkComboBox *combo;
52
53         log_debug("ui_newtask()");
54
55         builder = gtk_builder_new();
56         gtk_builder_add_from_file
57                 (builder,
58                  PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
59                  NULL);
60         diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew"));
61         gtk_builder_connect_signals(builder, NULL);
62
63         result = gtk_dialog_run(diag);
64
65         if (result == GTK_RESPONSE_ACCEPT) {
66                 log_debug("ui_newtask(): ok");
67
68                 entry = GTK_ENTRY(gtk_builder_get_object
69                                   (builder, "diag_tasknew_description"));
70                 desc = gtk_entry_get_text(entry);
71
72                 entry = GTK_ENTRY(gtk_builder_get_object
73                                   (builder, "diag_tasknew_project"));
74                 prj = gtk_entry_get_text(entry);
75
76                 combo = GTK_COMBO_BOX(gtk_builder_get_object
77                                       (builder, "diag_tasknew_priority"));
78                 prio = ui_get_priority(combo);
79
80                 log_debug("ui_newtask(): description=%s project=%s priority=%d",
81                           desc,
82                           prj,
83                           prio);
84
85                 tw_add(desc, prj, prio);
86                 refresh();
87         } else {
88                 log_debug("ui_newtask(): cancel");
89         }
90
91         g_object_unref(G_OBJECT(builder));
92
93         gtk_widget_destroy(GTK_WIDGET(diag));
94 }