From 5ebed0cd5dc2eb2f71e18b24148903f3c10ebf69 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 21 Mar 2010 00:19:02 +0100 Subject: Implemented a very basic configuration dialog. This code is a bit hackish, all configuration options should be collected in a single place (eg. a config struct) in order to easily keep track of all configuration options. --- SConstruct | 8 ++-- config.ui | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ config_ui.h | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ preload.c | 4 +- wallpapers.c | 6 ++- wallpapers.h | 2 + walls.ui | 15 +++++++ window_config.c | 100 ++++++++++++++++++++++++++++++++++++++++++++ window_config.h | 15 +++++++ window_main.c | 19 +++++++++ 10 files changed, 409 insertions(+), 6 deletions(-) create mode 100644 config.ui create mode 100644 config_ui.h create mode 100644 window_config.c create mode 100644 window_config.h diff --git a/SConstruct b/SConstruct index f9d3986..7300a29 100644 --- a/SConstruct +++ b/SConstruct @@ -36,10 +36,11 @@ env.ParseConfig('pkg-config --cflags --libs gthread-2.0') def build_ui(target, source, env): f = open(str(target[0]), 'w') - f.write('#ifndef _WALLS_UI_H_\n') - f.write('#define _WALLS_UI_H_\n') + uiname = str(target[0]).rsplit('.', 1)[0] + f.write('#ifndef _%s_H_\n' % uiname.upper()) + f.write('#define _%s_H_\n' % uiname.upper()) f.write('#include \n') - f.write('gchar *%s_string = \n' % str(target[0]).rsplit('.', 1)[0]) + f.write('gchar *%s_string = \n' % uiname) for line in open(str(source[0]), 'r'): f.write('"%s"\n' % line.replace('"', '\\"').strip()) f.write(';\n') @@ -50,6 +51,7 @@ ui_builder = Builder(action = build_ui) env['BUILDERS']['walls_ui'] = ui_builder env.walls_ui('walls_ui.h', 'walls.ui') env.walls_ui('tags_ui.h', 'tags.ui') +env.walls_ui('config_ui.h', 'config.ui') walls = env.Program('walls', Glob('*.c')) destdir = ARGUMENTS.get('DESTDIR', '') diff --git a/config.ui b/config.ui new file mode 100644 index 0000000..2a73642 --- /dev/null +++ b/config.ui @@ -0,0 +1,120 @@ + + + + + + 5 + normal + False + + + True + vertical + 2 + + + True + vertical + + + True + _Interpolation Mode: + True + interp_combo + + + False + 0 + + + + + True + + + False + 1 + + + + + True + Max _Preload: + True + preload_scale + + + False + 2 + + + + + True + True + adjustment1 + 0 + + + 3 + + + + + False + 1 + + + + + True + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + button2 + button1 + + + + + 32 + 1 + 8 + + diff --git a/config_ui.h b/config_ui.h new file mode 100644 index 0000000..952aa4b --- /dev/null +++ b/config_ui.h @@ -0,0 +1,126 @@ +#ifndef _CONFIG_UI_H_ +#define _CONFIG_UI_H_ +#include +gchar *config_ui_string = +"" +"" +"" +"" +"" +"5" +"normal" +"False" +"" +"" +"True" +"vertical" +"2" +"" +"" +"True" +"vertical" +"" +"" +"True" +"_Interpolation Mode:" +"True" +"interp_combo" +"" +"" +"False" +"0" +"" +"" +"" +"" +"True" +"" +"" +"False" +"1" +"" +"" +"" +"" +"True" +"Max _Preload:" +"True" +"preload_scale" +"" +"" +"False" +"2" +"" +"" +"" +"" +"True" +"True" +"adjustment1" +"0" +"" +"" +"3" +"" +"" +"" +"" +"False" +"1" +"" +"" +"" +"" +"True" +"end" +"" +"" +"gtk-cancel" +"True" +"True" +"True" +"True" +"" +"" +"False" +"False" +"0" +"" +"" +"" +"" +"gtk-ok" +"True" +"True" +"True" +"True" +"" +"" +"False" +"False" +"1" +"" +"" +"" +"" +"False" +"end" +"0" +"" +"" +"" +"" +"" +"button2" +"button1" +"" +"" +"" +"" +"32" +"1" +"8" +"" +"" +; +#endif diff --git a/preload.c b/preload.c index 3bd2e24..62664cf 100644 --- a/preload.c +++ b/preload.c @@ -4,8 +4,9 @@ #include "preload.h" #include "wallpapers.h" +#include "walls_conf.h" -guint preload_max = 6; +guint preload_max = 2; static gboolean preload_thread_exit = FALSE; static GHashTable *hashtable = NULL; @@ -33,6 +34,7 @@ static void preload_hash_table_free(gpointer data) { } void preload_init() { + preload_max = conf_get_int("walls", "max_preload", 2); preload_hashtable_mutex = g_mutex_new(); preload_thread_mutex = g_mutex_new(); diff --git a/wallpapers.c b/wallpapers.c index dbfb8a1..bc907d5 100644 --- a/wallpapers.c +++ b/wallpapers.c @@ -13,6 +13,8 @@ #include "wallpapers.h" +GdkInterpType interp_type = GDK_INTERP_NEAREST; + gboolean wallpapers_add_dir(const gchar *path, sqlite_uint64 parent, GtkStatusbar *statusbar, gboolean recursive ) { static guint context_id = 0; GDir *dir; @@ -210,7 +212,7 @@ GdkPixbuf *resize_pixbuf(GdkPixbuf *orig, gint win_width, gint win_height, gint } if(width == 0 || height == 0) return NULL; pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); - gdk_pixbuf_scale(orig, pb, 0, 0, width, height, 0, 0, scalex, scaley, GDK_INTERP_BILINEAR); + gdk_pixbuf_scale(orig, pb, 0, 0, width, height, 0, 0, scalex, scaley, interp_type); } else { width = img_width; height = img_height; @@ -235,6 +237,6 @@ GdkPixbuf *zoom_pixbuf(GdkPixbuf *orig, gdouble zoom) { height = img_height * zoom; pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); gdk_pixbuf_scale(orig, pb, 0, 0, width, height, 0, 0, - (gdouble)width / (gdouble)img_width, (gdouble)height / (gdouble)img_height, GDK_INTERP_NEAREST); + (gdouble)width / (gdouble)img_width, (gdouble)height / (gdouble)img_height, interp_type); return pb; } diff --git a/wallpapers.h b/wallpapers.h index fc575b3..38384a0 100644 --- a/wallpapers.h +++ b/wallpapers.h @@ -11,4 +11,6 @@ void wallpapers_remove_missing(struct directory_t*, GtkStatusbar*, gboolean); GdkPixbuf *resize_pixbuf(GdkPixbuf*, gint, gint, gint*, gint*, gdouble*); GdkPixbuf *zoom_pixbuf(GdkPixbuf*, gdouble); +extern GdkInterpType interp_type; + #endif diff --git a/walls.ui b/walls.ui index a355977..6f0a61a 100644 --- a/walls.ui +++ b/walls.ui @@ -36,6 +36,21 @@ True + + + gtk-preferences + True + True + True + + + + + + + True + + gtk-quit diff --git a/window_config.c b/window_config.c new file mode 100644 index 0000000..a8de897 --- /dev/null +++ b/window_config.c @@ -0,0 +1,100 @@ +#include "window_config.h" +#include "config_ui.h" +#include "walls_conf.h" +#include "preload.h" +#include "wallpapers.h" + +struct window_config_t *window_config_new(GtkWindow *parent) { + GtkBuilder *builder; + GtkDialog *dialog; + GtkComboBox *interp_combo; + GtkHScale *preload_scale; + GtkListStore *liststore; + GtkTreeIter iter; + GError *error = NULL; + GtkCellRenderer *cell; + struct window_config_t *wct; + + int interp_mode = conf_get_int("walls", "interpolation_mode", GDK_INTERP_NEAREST); + int max_preload = conf_get_int("walls", "max_preload", 2); + + builder = gtk_builder_new(); + if(!gtk_builder_add_from_string(builder, config_ui_string, -1, &error)) { + g_warning("%s", error->message); + g_error_free(error); + return NULL; + } + + interp_combo = GTK_COMBO_BOX(gtk_builder_get_object(builder, "interp_combo")); + liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); + + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, 0, "Nearest", 1, GDK_INTERP_NEAREST, -1); + + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, 0, "Tiles", 1, GDK_INTERP_TILES, -1); + + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, 0, "Bilinear", 1, GDK_INTERP_BILINEAR, -1); + + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, 0, "Hyper", 1, GDK_INTERP_HYPER, -1); + + gtk_combo_box_set_model(interp_combo, GTK_TREE_MODEL(liststore)); + g_object_unref(liststore); + + cell = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(interp_combo), cell, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(interp_combo), cell, "text", 0, NULL); + + switch(interp_mode) { + case GDK_INTERP_TILES: + gtk_combo_box_set_active(interp_combo, 1); + break; + case GDK_INTERP_BILINEAR: + gtk_combo_box_set_active(interp_combo, 2); + break; + case GDK_INTERP_HYPER: + gtk_combo_box_set_active(interp_combo, 3); + break; + default: + gtk_combo_box_set_active(interp_combo, 0); + } + + preload_scale = GTK_HSCALE(gtk_builder_get_object(builder, "preload_scale")); + gtk_range_set_value(GTK_RANGE(preload_scale), max_preload); + + dialog = GTK_DIALOG(gtk_builder_get_object(builder, "config_dialog")); + gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); + gtk_builder_connect_signals(builder, dialog); + g_object_unref(G_OBJECT(builder)); + + wct = g_malloc(sizeof(struct window_config_t)); + wct->dialog = dialog; + wct->interp_combo = interp_combo; + wct->preload_scale = GTK_RANGE(preload_scale); + + return wct; +} + +void window_config_save(struct window_config_t *wct) { + GValue value = {0}; + + int interp_mode = GDK_INTERP_NEAREST; + int max_preload = 2; + + GtkListStore *liststore = GTK_LIST_STORE(gtk_combo_box_get_model(wct->interp_combo)); + GtkTreeIter iter; + gtk_combo_box_get_active_iter(wct->interp_combo, &iter); + gtk_tree_model_get_value(GTK_TREE_MODEL(liststore), &iter, 1, &value); + interp_mode = g_value_get_int(&value); + g_value_unset(&value); + + max_preload = gtk_range_get_value(wct->preload_scale); + + g_key_file_set_integer(keyfile, "walls", "interpolation_mode", interp_mode); + interp_type = interp_mode; + + g_key_file_set_integer(keyfile, "walls", "max_preload", max_preload); + preload_max = max_preload; +} diff --git a/window_config.h b/window_config.h new file mode 100644 index 0000000..639a746 --- /dev/null +++ b/window_config.h @@ -0,0 +1,15 @@ +#ifndef _WINDOW_CONFIG_H_ +#define _WINDOW_CONFIG_H_ + +#include + +struct window_config_t { + GtkDialog *dialog; + GtkComboBox *interp_combo; + GtkRange *preload_scale; +}; + +struct window_config_t *window_config_new(); +void window_config_save(struct window_config_t *wct); + +#endif diff --git a/window_main.c b/window_main.c index ca3d8dc..3262ba9 100644 --- a/window_main.c +++ b/window_main.c @@ -10,6 +10,7 @@ #include "walls_conf.h" #include "window_tag.h" #include "preload.h" +#include "window_config.h" enum zoom_mode_t { ZOOM_BESTFIT, @@ -1057,6 +1058,22 @@ void on_file_quit_activate(GtkMenuItem *menuitem, gpointer user_data) { gtk_main_quit(); } +void on_file_preferences_activate(GtkMenuItem *menuitem, gpointer user_data) { + struct window_config_t *wct; + + wct = window_config_new(window); + if(!wct) { + return; + } + + if(gtk_dialog_run(wct->dialog) == GTK_RESPONSE_OK) { + window_config_save(wct); + } + + gtk_widget_destroy(GTK_WIDGET(wct->dialog)); + g_free(wct); +} + static void set_sizes() { gint width, height, hpane_pos, vpane_pos; @@ -1069,6 +1086,8 @@ static void set_sizes() { gtk_paned_set_position(GTK_PANED(window_hpane), hpane_pos); gtk_paned_set_position(GTK_PANED(window_vpane), vpane_pos); + + interp_type = conf_get_int("walls", "interpolation_mode", interp_type); } int gui_main(int argc, char **argv) { -- cgit v1.2.3