From 76a0da80d73c62bca9a86835c1a7d4be9b3c437b Mon Sep 17 00:00:00 2001 From: nedko Date: Sat, 19 Feb 2005 21:03:03 +0000 Subject: [PATCH] Implement preferences window. --- gtk/GNUmakefile | 7 +- gtk/mediadatabase.glade | 756 +++++++++++++++++++++++++++++++++++++++++++++++- gtk/preferences.c | 190 ++++++++++++ 3 files changed, 948 insertions(+), 5 deletions(-) create mode 100644 gtk/preferences.c diff --git a/gtk/GNUmakefile b/gtk/GNUmakefile index 773fc92..90c7a03 100644 --- a/gtk/GNUmakefile +++ b/gtk/GNUmakefile @@ -1,6 +1,6 @@ ############################################################################## # -# $Id: GNUmakefile,v 1.10 2005/02/18 02:25:40 nedko Exp $ +# $Id: GNUmakefile,v 1.11 2005/02/19 21:03:03 nedko Exp $ # # DESCRIPTION: # Makefile for console mediadatabase frontends @@ -24,7 +24,7 @@ ifeq ($(GTK_OK),yes) CFLAGS += -g -Wall $(shell pkg-config --cflags gtk+-2.0 libglade-2.0) LINKFLAGS += -g $(shell pkg-config --libs gtk+-2.0 libglade-2.0) -SOURCES = main.c medias.c media.c helper.c search.c path.c about.c glade.c +SOURCES = main.c medias.c media.c helper.c search.c path.c about.c glade.c preferences.c OBJECTS = $(SOURCES:%.c=%.o) DEP_FILES = $(OBJECTS:.o=.d) @@ -82,6 +82,9 @@ endif # GTK_OK # !!! WARNING !!! Following lines are automatically updated by the CVS system. # # $Log: GNUmakefile,v $ +# Revision 1.11 2005/02/19 21:03:03 nedko +# Implement preferences window. +# # Revision 1.10 2005/02/18 02:25:40 nedko # We are now using libglade for menu - don't compile menu.c # diff --git a/gtk/mediadatabase.glade b/gtk/mediadatabase.glade index 6640fd4..bea78be 100644 --- a/gtk/mediadatabase.glade +++ b/gtk/mediadatabase.glade @@ -50,7 +50,7 @@ - + True gtk-find 1 @@ -64,6 +64,15 @@ + + True + gtk-preferences + True + + + + + True _Quit @@ -71,7 +80,7 @@ - + True gtk-quit 1 @@ -105,7 +114,7 @@ - + True gtk-about 1 @@ -941,4 +950,745 @@ + + True + Preferences + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + settings + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + 5 + True + 2 + 1 + False + 5 + 5 + + + + True + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + + + + True + 1 + 2 + True + 0 + 5 + + + + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + + + 1 + 2 + 0 + 1 + fill + + + + + + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + True + GTK_POS_TOP + False + False + + + + True + 2 + 1 + False + 0 + 0 + + + + 5 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + 5 + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 5 + 0 + + + + True + False + 0 + + + + True + True + Use MySQL database as backend + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Use SQLite database as backend + True + GTK_RELIEF_NORMAL + True + False + False + True + radiobutton_mysql + + + 0 + False + False + + + + + + + + + + True + <b>Backend</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + 1 + 0 + 1 + + + + + + 5 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 5 + 0 + + + + 5 + True + 3 + 2 + False + 5 + 5 + + + + True + Mount command + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Unmount command + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Mount directory + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + + + + + + + + + + + True + <b>Media filesystem access</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + 1 + 1 + 2 + fill + + + + + False + False + + + + + + True + General + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + 5 + True + 4 + 2 + False + 5 + 5 + + + + True + Host + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Username + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Password + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + Database + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + True + True + False + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 3 + 4 + + + + + + False + False + + + + + + True + MySQL + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + + 5 + True + 1 + 2 + False + 5 + 5 + + + + True + Database file + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 0 + 1 + + + + + + False + False + + + + + + True + SQLite + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + 0 + 1 + 0 + 1 + fill + + + + + + diff --git a/gtk/preferences.c b/gtk/preferences.c new file mode 100644 index 0000000..eeaa259 --- /dev/null +++ b/gtk/preferences.c @@ -0,0 +1,190 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/***************************************************************************** + * + * $Id: preferences.c,v 1.1 2005/02/19 21:03:03 nedko Exp $ + * + * DESCRIPTION: + * + * + * NOTES: + * + * + *****************************************************************************/ + +#include + +#include "../result.h" +#include "../libdb/libdb.h" +#include "../libfrontend/db.h" +#include "../libfrontend/disk.h" +#include "../libfrontend/conf.h" +#include "glade.h" + +void +on_preferences_window_button_cancel_activate( + GtkAction *action, + GtkWidget *window) +{ + gtk_widget_destroy(window); +} + +void +on_preferences_window_button_ok_activate( + GtkAction *action, + GtkWidget *window) +{ + mediadb_result r; + GtkWidget * dialog; + + r = db_set_mysql_host( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_host_entry")))); + + r = db_set_mysql_user( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_user_entry")))); + + r = db_set_mysql_pass( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_pass_entry")))); + + r = db_set_mysql_database( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_db_entry")))); + + r = db_set_sqlite_database( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_sqlite_dbfile_entry")))); + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(get_glade_widget_child(window, "radiobutton_mysql")))) + { + db_use_mysql(); + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(get_glade_widget_child(window, "radiobutton_sqlite")))) + { + db_use_sqlite(); + } + + disk_set_mount_command( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "mount_cmd_entry")))); + + disk_set_unmount_command( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "unmount_cmd_entry")))); + + disk_set_path( + gtk_entry_get_text( + GTK_ENTRY(get_glade_widget_child(window, "mountdir_entry")))); + + r = conf_write(); + + dialog = gtk_message_dialog_new( + GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_MESSAGE_INFO, + GTK_BUTTONS_CLOSE, + "Backend related settings changes will take effect when program is restarted."); + + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + gtk_widget_destroy(window); +} + +void +on_preferences_activate( + GtkAction *action, + GtkWidget *window) +{ + GtkWidget * pref; + unsigned int nDBType; + + pref = construct_glade_widget("preferences_window"); + + g_signal_connect( + get_glade_widget_child(pref, "preferences_window_button_cancel"), + "activate", + G_CALLBACK(on_preferences_window_button_cancel_activate), pref); + + g_signal_connect( + get_glade_widget_child(pref, "preferences_window_button_cancel"), + "released", + G_CALLBACK(on_preferences_window_button_cancel_activate), pref); + + g_signal_connect( + get_glade_widget_child(pref, "preferences_window_button_ok"), + "activate", + G_CALLBACK(on_preferences_window_button_ok_activate), pref); + + g_signal_connect( + get_glade_widget_child(pref, "preferences_window_button_ok"), + "released", + G_CALLBACK(on_preferences_window_button_ok_activate), pref); + + nDBType = db_get_type(); + if (nDBType == MEDIADB_DBTYPE_MYSQL) + { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(get_glade_widget_child(pref, "radiobutton_mysql")), + TRUE); + } + else if (nDBType == MEDIADB_DBTYPE_SQLITE) + { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(get_glade_widget_child(pref, "radiobutton_sqlite")), + TRUE); + } + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "mount_cmd_entry")), + disk_get_mount_command()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "unmount_cmd_entry")), + disk_get_unmount_command()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "mountdir_entry")), + disk_get_path()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_host_entry")), + db_get_mysql_host()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_user_entry")), + db_get_mysql_user()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_pass_entry")), + db_get_mysql_pass()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_db_entry")), + db_get_mysql_database()); + + gtk_entry_set_text( + GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_sqlite_dbfile_entry")), + db_get_sqlite_database()); + + if (window != NULL) + { + gtk_window_set_transient_for( + GTK_WINDOW(pref), + GTK_WINDOW(window)); + } +} + +/***************************************************************************** + * + * Modifications log: + * + * !!! WARNING !!! Following lines are automatically updated by the CVS system. + * + * $Log: preferences.c,v $ + * Revision 1.1 2005/02/19 21:03:03 nedko + * Implement preferences window. + * + *****************************************************************************/ -- 2.11.4.GIT