improved log
[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 static GtkComboBox *w_status;
27
28 int newtask_clicked_cbk(GtkButton *btn, gpointer data)
29 {
30         ui_newtask();
31
32         return FALSE;
33 }
34
35 static void save_settings(GtkWindow *window, GSettings *settings)
36 {
37         int w, h, x, y;
38
39         gtk_window_get_size(window, &w, &h);
40         gtk_window_get_position(window, &x, &y);
41
42         log_debug("save_settings(): x=%d, y=%d, w=%d, h=%d", x, y, w, h);
43
44         g_settings_set_int(settings, "window-width", w);
45         g_settings_set_int(settings, "window-height", h);
46         g_settings_set_int(settings, "window-x", x);
47         g_settings_set_int(settings, "window-y", y);
48
49         ui_tasktree_save_settings(settings);
50
51         g_settings_sync();
52 }
53
54 int refresh_clicked_cbk(GtkButton *btn, gpointer data)
55 {
56         log_fct_enter();
57         refresh();
58         log_fct_exit();
59         return FALSE;
60 }
61
62
63 static gboolean delete_event_cbk(GtkWidget *w, GdkEvent *evt, gpointer data)
64 {
65         log_fct_enter();
66
67         save_settings(GTK_WINDOW(w), (GSettings *)data);
68         gtk_widget_destroy(w);
69         gtk_main_quit();
70
71         log_fct_exit();
72
73         return TRUE;
74 }
75
76 static int status_changed_cbk(GtkComboBox *w, gpointer data)
77 {
78         log_debug("status_changed_cbk");
79         refresh();
80
81         return FALSE;
82 }
83
84 GtkWindow *create_window(GtkBuilder *builder, GSettings *settings)
85 {
86         GtkWindow *window;
87         int x, y, w, h;
88
89         window = GTK_WINDOW(gtk_builder_get_object(builder, "window"));
90
91         w_status = GTK_COMBO_BOX(gtk_builder_get_object(builder, "status"));
92         g_signal_connect(w_status,
93                          "changed", (GCallback)status_changed_cbk,
94                          NULL);
95
96         w = g_settings_get_int(settings, "window-width");
97         h = g_settings_get_int(settings, "window-height");
98         gtk_window_set_default_size(window, w, h);
99
100         x = g_settings_get_int(settings, "window-x");
101         y = g_settings_get_int(settings, "window-y");
102         gtk_window_move(window, x, y);
103
104         g_signal_connect(window, "delete_event",
105                          G_CALLBACK(delete_event_cbk), settings);
106
107         ui_tasktree_init(builder);
108         ui_projecttree_init(builder);
109
110         ui_tasktree_load_settings(settings);
111
112         return window;
113 }
114
115 const char *ui_get_status_filter()
116 {
117         const char *status;
118
119         log_fct_enter();
120
121         status = gtk_combo_box_get_active_id(w_status);
122         log_fct("status: %d", status);
123
124         log_fct_exit();
125
126         return status;
127 }