[svn r31] Some changes, in order to use the newly added nuvdemux features.
10 #include "mmyth_uisettings.h"
12 #include "gmyth_context.h"
14 static GtkWidget *settings_dialog;
15 static GtkWidget *entry_hostname;
16 static GtkWidget *entry_dbname;
17 static GtkWidget *entry_username;
18 static GtkWidget *entry_passwd;
19 static GtkWidget *entry_port;
21 static void settings_dialog_update_data (void);
22 static GtkWidget* add_entry_to_table (GtkWidget *table, GString *init_str,
23 guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
24 static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str,
25 guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
29 mmyth_uisettings_run (GtkWindow *main_window)
32 GtkWidget *settings_table;
33 GtkWidget *label_hostname, *label_dbname;
34 GtkWidget *label_username, *label_passwd, *label_port;
36 GMythSettings *msettings = gmyth_context_get_settings();
38 settings_dialog = gtk_dialog_new_with_buttons ("Settings",
40 GTK_DIALOG_DESTROY_WITH_PARENT,
47 gtk_widget_set_size_request (settings_dialog, 400, 244);
49 /* scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
50 gtk_widget_show (scrolledwindow1);
51 gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
52 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
54 viewport1 = gtk_viewport_new (NULL, NULL);
55 gtk_widget_show (viewport1);
56 gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1);
57 gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE);
60 // Creates the table and attach it to the settings dialog
61 settings_table = gtk_table_new (5, 2, FALSE);
62 gtk_widget_show (settings_table);
63 gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0);
64 gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3);
65 gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5);
66 gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10);
68 label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1);
69 label_dbname = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2);
70 label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3);
71 label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4);
72 label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
74 entry_hostname = add_entry_to_table (settings_table,
75 gmyth_settings_get_backend_hostname (msettings),
77 entry_dbname = add_entry_to_table (settings_table,
78 gmyth_settings_get_dbname (msettings),
80 entry_username = add_entry_to_table (settings_table,
81 gmyth_settings_get_username (msettings),
83 entry_passwd = add_entry_to_table (settings_table,
84 gmyth_settings_get_password (msettings),
87 GString *str_port = g_string_new ("");
88 g_string_printf (str_port, "%d",
89 gmyth_settings_get_backend_port (msettings));
90 entry_port = add_entry_to_table (settings_table, str_port,
92 g_string_free (str_port, TRUE);
94 if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
95 settings_dialog_update_data ();
96 gtk_widget_destroy (settings_dialog);
100 gtk_widget_destroy (settings_dialog);
107 add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right,
108 guint pos_top, guint pos_bottom )
110 GtkWidget *tmp_label = gtk_label_new (str);
112 gtk_widget_show (tmp_label);
113 gtk_table_attach (GTK_TABLE (table), tmp_label,
114 pos_left, pos_right, pos_top, pos_bottom,
115 (GtkAttachOptions) (GTK_FILL),
116 (GtkAttachOptions) (0), 0, 0);
117 gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);
123 add_entry_to_table (GtkWidget *table, GString *init_str, guint pos_left, guint pos_right,
124 guint pos_top, guint pos_bottom)
126 GtkWidget *tmp_entry = gtk_entry_new ();
127 gtk_widget_show (tmp_entry);
128 gtk_table_attach (GTK_TABLE (table), tmp_entry,
129 pos_left, pos_right, pos_top, pos_bottom,
130 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
131 (GtkAttachOptions) (0), 0, 0);
133 gtk_entry_set_text (GTK_ENTRY (tmp_entry), (init_str->str));
135 //gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
141 settings_dialog_update_data (void)
143 GString *tmp_entry_text;
144 GMythSettings *msettings = gmyth_context_get_settings();
147 g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
151 tmp_entry_text = g_string_new("");
152 g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_hostname)));
153 gmyth_settings_set_backend_hostname(msettings, tmp_entry_text);
155 g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
156 gmyth_settings_set_dbname(msettings, tmp_entry_text);
158 g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_username)));
159 gmyth_settings_set_username(msettings, tmp_entry_text);
161 g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
162 gmyth_settings_set_password(msettings, tmp_entry_text);
164 g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_port)));
165 gmyth_settings_set_backend_port(msettings, atoi(tmp_entry_text->str));
167 gmyth_settings_save (msettings);