new frontend - FUSE
[mediadatabase.git] / gtk / preferences.c
blobeeaa2599712a6c7359fc6f8f02289c03e249669e
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: preferences.c,v 1.1 2005/02/19 21:03:03 nedko Exp $
6 * DESCRIPTION:
7 *
9 * NOTES:
12 *****************************************************************************/
14 #include <gtk/gtk.h>
16 #include "../result.h"
17 #include "../libdb/libdb.h"
18 #include "../libfrontend/db.h"
19 #include "../libfrontend/disk.h"
20 #include "../libfrontend/conf.h"
21 #include "glade.h"
23 void
24 on_preferences_window_button_cancel_activate(
25 GtkAction *action,
26 GtkWidget *window)
28 gtk_widget_destroy(window);
31 void
32 on_preferences_window_button_ok_activate(
33 GtkAction *action,
34 GtkWidget *window)
36 mediadb_result r;
37 GtkWidget * dialog;
39 r = db_set_mysql_host(
40 gtk_entry_get_text(
41 GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_host_entry"))));
43 r = db_set_mysql_user(
44 gtk_entry_get_text(
45 GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_user_entry"))));
47 r = db_set_mysql_pass(
48 gtk_entry_get_text(
49 GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_pass_entry"))));
51 r = db_set_mysql_database(
52 gtk_entry_get_text(
53 GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_mysql_db_entry"))));
55 r = db_set_sqlite_database(
56 gtk_entry_get_text(
57 GTK_ENTRY(get_glade_widget_child(window, "preferences_window_notebook_sqlite_dbfile_entry"))));
59 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(get_glade_widget_child(window, "radiobutton_mysql"))))
61 db_use_mysql();
64 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(get_glade_widget_child(window, "radiobutton_sqlite"))))
66 db_use_sqlite();
69 disk_set_mount_command(
70 gtk_entry_get_text(
71 GTK_ENTRY(get_glade_widget_child(window, "mount_cmd_entry"))));
73 disk_set_unmount_command(
74 gtk_entry_get_text(
75 GTK_ENTRY(get_glade_widget_child(window, "unmount_cmd_entry"))));
77 disk_set_path(
78 gtk_entry_get_text(
79 GTK_ENTRY(get_glade_widget_child(window, "mountdir_entry"))));
81 r = conf_write();
83 dialog = gtk_message_dialog_new(
84 GTK_WINDOW(window),
85 GTK_DIALOG_MODAL,
86 GTK_MESSAGE_INFO,
87 GTK_BUTTONS_CLOSE,
88 "Backend related settings changes will take effect when program is restarted.");
90 gtk_dialog_run(GTK_DIALOG(dialog));
91 gtk_widget_destroy(dialog);
93 gtk_widget_destroy(window);
96 void
97 on_preferences_activate(
98 GtkAction *action,
99 GtkWidget *window)
101 GtkWidget * pref;
102 unsigned int nDBType;
104 pref = construct_glade_widget("preferences_window");
106 g_signal_connect(
107 get_glade_widget_child(pref, "preferences_window_button_cancel"),
108 "activate",
109 G_CALLBACK(on_preferences_window_button_cancel_activate), pref);
111 g_signal_connect(
112 get_glade_widget_child(pref, "preferences_window_button_cancel"),
113 "released",
114 G_CALLBACK(on_preferences_window_button_cancel_activate), pref);
116 g_signal_connect(
117 get_glade_widget_child(pref, "preferences_window_button_ok"),
118 "activate",
119 G_CALLBACK(on_preferences_window_button_ok_activate), pref);
121 g_signal_connect(
122 get_glade_widget_child(pref, "preferences_window_button_ok"),
123 "released",
124 G_CALLBACK(on_preferences_window_button_ok_activate), pref);
126 nDBType = db_get_type();
127 if (nDBType == MEDIADB_DBTYPE_MYSQL)
129 gtk_toggle_button_set_active(
130 GTK_TOGGLE_BUTTON(get_glade_widget_child(pref, "radiobutton_mysql")),
131 TRUE);
133 else if (nDBType == MEDIADB_DBTYPE_SQLITE)
135 gtk_toggle_button_set_active(
136 GTK_TOGGLE_BUTTON(get_glade_widget_child(pref, "radiobutton_sqlite")),
137 TRUE);
140 gtk_entry_set_text(
141 GTK_ENTRY(get_glade_widget_child(pref, "mount_cmd_entry")),
142 disk_get_mount_command());
144 gtk_entry_set_text(
145 GTK_ENTRY(get_glade_widget_child(pref, "unmount_cmd_entry")),
146 disk_get_unmount_command());
148 gtk_entry_set_text(
149 GTK_ENTRY(get_glade_widget_child(pref, "mountdir_entry")),
150 disk_get_path());
152 gtk_entry_set_text(
153 GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_host_entry")),
154 db_get_mysql_host());
156 gtk_entry_set_text(
157 GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_user_entry")),
158 db_get_mysql_user());
160 gtk_entry_set_text(
161 GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_pass_entry")),
162 db_get_mysql_pass());
164 gtk_entry_set_text(
165 GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_mysql_db_entry")),
166 db_get_mysql_database());
168 gtk_entry_set_text(
169 GTK_ENTRY(get_glade_widget_child(pref, "preferences_window_notebook_sqlite_dbfile_entry")),
170 db_get_sqlite_database());
172 if (window != NULL)
174 gtk_window_set_transient_for(
175 GTK_WINDOW(pref),
176 GTK_WINDOW(window));
180 /*****************************************************************************
182 * Modifications log:
184 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
186 * $Log: preferences.c,v $
187 * Revision 1.1 2005/02/19 21:03:03 nedko
188 * Implement preferences window.
190 *****************************************************************************/