2 * Copyright (C) 2012-2013 jeanfi@gmail.com
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.
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.
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
23 static GtkTreeView *w_treeview;
25 static void save_settings(GtkWindow *window, GSettings *settings)
27 int w, h, x, y, sort_col_id;
28 GtkTreeSortable *model;
29 GtkSortType sort_order;
31 model = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)));
32 gtk_tree_sortable_get_sort_column_id(model,
35 log_debug("save_settings(): sort_col_id=%d", sort_col_id);
36 log_debug("save_settings(): sort_col_order=%d", sort_order);
38 g_settings_set_int(settings, "tasks-sort-col", sort_col_id);
39 g_settings_set_int(settings, "tasks-sort-order", sort_order);
41 gtk_window_get_size(window, &w, &h);
42 gtk_window_get_position(window, &x, &y);
44 log_debug("save_settings(): x=%d, y=%d, w=%d, h=%d", x, y, w, h);
46 g_settings_set_int(settings, "window-width", w);
47 g_settings_set_int(settings, "window-height", h);
48 g_settings_set_int(settings, "window-x", x);
49 g_settings_set_int(settings, "window-y", y);
54 static gboolean delete_event_cbk(GtkWidget *w, GdkEvent *evt, gpointer data)
56 log_debug("delete_event_cbk");
58 save_settings(GTK_WINDOW(w), (GSettings *)data);
59 gtk_widget_destroy(w);
65 GtkWindow *create_window(GtkBuilder *builder, GSettings *settings)
68 int x, y, h, w, sort_col_id;
69 GtkSortType sort_order;
70 GtkTreeSortable *model;
72 window = GTK_WINDOW(gtk_builder_get_object(builder, "window"));
74 w = g_settings_get_int(settings, "window-width");
75 h = g_settings_get_int(settings, "window-height");
76 gtk_window_set_default_size(window, w, h);
78 x = g_settings_get_int(settings, "window-x");
79 y = g_settings_get_int(settings, "window-y");
80 gtk_window_move(window, x, y);
82 g_signal_connect(window, "delete_event",
83 G_CALLBACK(delete_event_cbk), settings);
85 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
87 sort_col_id = g_settings_get_int(settings, "tasks-sort-col");
88 sort_order = g_settings_get_int(settings, "tasks-sort-order");
89 model = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)));
90 gtk_tree_sortable_set_sort_column_id(model, sort_col_id, sort_order);