diff options
Diffstat (limited to 'window_main.c')
-rw-r--r-- | window_main.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/window_main.c b/window_main.c index 4038206..04209b9 100644 --- a/window_main.c +++ b/window_main.c @@ -11,6 +11,7 @@ #include "walls_model.h" #include "wallpapers.h" #include "thumbnails.h" +#include "walls_conf.h" struct wallpaper_t *cur_wall = NULL; GdkPixbuf *orig_pixbuf = NULL; @@ -18,10 +19,12 @@ gint last_width = 0, last_height = 0, last_pos = 0; +GtkWindow *window; GtkImage *image = NULL; GtkWidget *layout = NULL; GtkStatusbar *statusbar; GtkIconView *thumbview; +GtkWidget *window_hpane, *window_vpane; GThread *add_thread = NULL, *thumb_thread = NULL; @@ -261,10 +264,38 @@ void on_add_dir_action_activate(GtkAction *action, gpointer user_data) { gtk_widget_destroy(dialog); } +static void save_window() { + gint width, height; + + gtk_window_get_size(window, &width, &height); + g_key_file_set_integer(keyfile, "window", "width", width); + g_key_file_set_integer(keyfile, "window", "height", height); + g_key_file_set_integer(keyfile, "window", "hpane_pos", gtk_paned_get_position(GTK_PANED(window_hpane))); + g_key_file_set_integer(keyfile, "window", "vpane_pos", gtk_paned_get_position(GTK_PANED(window_vpane))); +} + +void on_file_quit_activate(GtkMenuItem *menuitem, gpointer user_data) { + save_window(); + + gtk_main_quit(); +} + +static void set_sizes() { + gint width, height, hpane_pos, vpane_pos; + + width = conf_get_int("window", "width", 800); + height = conf_get_int("window", "height", 600); + gtk_window_set_default_size(window, width, height); + + hpane_pos = conf_get_int("window", "hpane_pos", 190); + vpane_pos = conf_get_int("window", "vpane_pos", 160); + + gtk_paned_set_position(GTK_PANED(window_hpane), hpane_pos); + gtk_paned_set_position(GTK_PANED(window_vpane), vpane_pos); +} + int gui_main(int argc, char **argv) { - GtkWidget *window; GtkWidget *foldtree; - GtkWidget *window_hpane; GtkBuilder *builder ; GError *error = NULL; GdkColor color; @@ -276,6 +307,8 @@ int gui_main(int argc, char **argv) { if(!db_open()) return 1; + conf_open(); + gtk_init(&argc, &argv); builder = gtk_builder_new(); @@ -285,8 +318,7 @@ int gui_main(int argc, char **argv) { return 1; } - window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); - gtk_window_set_title(GTK_WINDOW(window), "walls"); + window = GTK_WINDOW(gtk_builder_get_object(builder, "window")); foldtree = GTK_WIDGET(gtk_builder_get_object(builder, "foldtree")); foldtree_init(GTK_TREE_VIEW(foldtree)); @@ -302,6 +334,7 @@ int gui_main(int argc, char **argv) { window_hpane = GTK_WIDGET(gtk_builder_get_object(builder, "window_hpane")); g_signal_connect(window_hpane, "notify::position", G_CALLBACK(on_window_hpane_resized), window_hpane); + window_vpane = GTK_WIDGET(gtk_builder_get_object(builder, "window_vpane")); statusbar = GTK_STATUSBAR(gtk_builder_get_object(builder, "statusbar")); image_context = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "Image display"); @@ -310,11 +343,14 @@ int gui_main(int argc, char **argv) { g_object_unref(G_OBJECT(builder)); - gtk_widget_show_all(window); + set_sizes(); + + gtk_widget_show_all(GTK_WIDGET(window)); gtk_main(); db_close(); + conf_close(); return 0; } |