fixed line width
[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
24 static GtkTreeView *w_treeview;
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, sort_col_id;
36         GtkTreeModel *model;
37         GtkSortType sort_order;
38
39         model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
40         gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(model),
41                                              &sort_col_id,
42                                              &sort_order);
43         log_debug("save_settings(): sort_col_id=%d", sort_col_id);
44         log_debug("save_settings(): sort_col_order=%d", sort_order);
45
46         g_settings_set_int(settings, "tasks-sort-col", sort_col_id);
47         g_settings_set_int(settings, "tasks-sort-order", sort_order);
48
49         gtk_window_get_size(window, &w, &h);
50         gtk_window_get_position(window, &x, &y);
51
52         log_debug("save_settings(): x=%d, y=%d, w=%d, h=%d", x, y, w, h);
53
54         g_settings_set_int(settings, "window-width", w);
55         g_settings_set_int(settings, "window-height", h);
56         g_settings_set_int(settings, "window-x", x);
57         g_settings_set_int(settings, "window-y", y);
58
59         g_settings_sync();
60 }
61
62 static gboolean delete_event_cbk(GtkWidget *w, GdkEvent *evt, gpointer data)
63 {
64         log_debug("delete_event_cbk");
65
66         save_settings(GTK_WINDOW(w), (GSettings *)data);
67         gtk_widget_destroy(w);
68         gtk_main_quit();
69
70         return TRUE;
71 }
72
73 GtkWindow *create_window(GtkBuilder *builder, GSettings *settings)
74 {
75         GtkWindow *window;
76         int x, y, h, w, sort_col_id;
77         GtkSortType sort_order;
78         GtkTreeModel *model;
79
80         window = GTK_WINDOW(gtk_builder_get_object(builder, "window"));
81
82         w = g_settings_get_int(settings, "window-width");
83         h = g_settings_get_int(settings, "window-height");
84         gtk_window_set_default_size(window, w, h);
85
86         x = g_settings_get_int(settings, "window-x");
87         y = g_settings_get_int(settings, "window-y");
88         gtk_window_move(window, x, y);
89
90         g_signal_connect(window, "delete_event",
91                          G_CALLBACK(delete_event_cbk), settings);
92
93         w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
94
95         sort_col_id = g_settings_get_int(settings, "tasks-sort-col");
96         sort_order = g_settings_get_int(settings, "tasks-sort-order");
97         model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
98         gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model),
99                                              sort_col_id, sort_order);
100
101         return window;
102 }
103