extracted ui code to create a new task
[ptask.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 void ui_newtask()
27 {
28         gint result;
29         static GtkDialog *diag;
30         GtkBuilder *builder;
31         GtkEntry *entry;
32         const char *ctxt;
33
34         log_debug("newtask_clicked_cbk");
35
36         builder = gtk_builder_new();
37         gtk_builder_add_from_file
38                 (builder,
39                  PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
40                  NULL);
41         diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew"));
42         gtk_builder_connect_signals(builder, NULL);
43
44         result = gtk_dialog_run(diag);
45
46         if (result == GTK_RESPONSE_ACCEPT) {
47                 log_debug("ok");
48                 entry = GTK_ENTRY(gtk_builder_get_object
49                                   (builder, "diag_tasknew_description"));
50                 ctxt = gtk_entry_get_text(entry);
51
52                 log_debug("%s", ctxt);
53
54                 tw_add(ctxt);
55                 refresh();
56         } else {
57                 log_debug("cancel");
58         }
59
60         g_object_unref(G_OBJECT(builder));
61
62         gtk_widget_destroy(GTK_WIDGET(diag));
63 }