74b13ec6f5cab25072486a69723e62c72e60c4c7
[ptask.git] / src / ui.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 <log.h>
21 #include <ui.h>
22 #include <ui_newtask_diag.h>
23 #include <ui_projecttree.h>
24 #include <ui_tasktree.h>
25
26 int newtask_clicked_cbk(GtkButton *btn, gpointer data)
27 {
28         ui_newtask();
29
30         return FALSE;
31 }
32
33 static void save_settings(GtkWindow *window, GSettings *settings)
34 {
35         int w, h, x, y;
36
37         gtk_window_get_size(window, &w, &h);
38         gtk_window_get_position(window, &x, &y);
39
40         log_debug("save_settings(): x=%d, y=%d, w=%d, h=%d", x, y, w, h);
41
42         g_settings_set_int(settings, "window-width", w);
43         g_settings_set_int(settings, "window-height", h);
44         g_settings_set_int(settings, "window-x", x);
45         g_settings_set_int(settings, "window-y", y);
46
47         ui_tasktree_save_settings(settings);
48
49         g_settings_sync();
50 }
51
52 static gboolean delete_event_cbk(GtkWidget *w, GdkEvent *evt, gpointer data)
53 {
54         log_debug("delete_event_cbk");
55
56         save_settings(GTK_WINDOW(w), (GSettings *)data);
57         gtk_widget_destroy(w);
58         gtk_main_quit();
59
60         return TRUE;
61 }
62
63 GtkWindow *create_window(GtkBuilder *builder, GSettings *settings)
64 {
65         GtkWindow *window;
66         int x, y, w, h;
67
68         window = GTK_WINDOW(gtk_builder_get_object(builder, "window"));
69
70         w = g_settings_get_int(settings, "window-width");
71         h = g_settings_get_int(settings, "window-height");
72         gtk_window_set_default_size(window, w, h);
73
74         x = g_settings_get_int(settings, "window-x");
75         y = g_settings_get_int(settings, "window-y");
76         gtk_window_move(window, x, y);
77
78         g_signal_connect(window, "delete_event",
79                          G_CALLBACK(delete_event_cbk), settings);
80
81         ui_tasktree_init(builder);
82         ui_projecttree_init(builder);
83
84         ui_tasktree_load_settings(settings);
85
86         return window;
87 }