[svn r356] Solved bug on read method callback.
10 #include "mmyth_uisettings.h"
12 #include <gmyth/gmyth_backendinfo.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, const gchar *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);
27 static GMythBackendInfo *backend_info = NULL;
30 mmyth_uisettings_run (GtkWindow *main_window)
33 GtkWidget *settings_table;
34 GtkWidget *label_hostname, *label_dbname;
35 GtkWidget *label_username, *label_passwd, *label_port;
37 backend_info = gmyth_backend_info_new_full( "localhost", "mythtv",
38 "mythtv", "mythconverg", 6543 );
40 settings_dialog = gtk_dialog_new_with_buttons ("Settings",
42 GTK_DIALOG_DESTROY_WITH_PARENT,
49 gtk_widget_set_size_request (settings_dialog, 400, 244);
51 /* scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
52 gtk_widget_show (scrolledwindow1);
53 gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
54 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
56 viewport1 = gtk_viewport_new (NULL, NULL);
57 gtk_widget_show (viewport1);
58 gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1);
59 gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE);
62 // Creates the table and attach it to the settings dialog
63 settings_table = gtk_table_new (5, 2, FALSE);
64 gtk_widget_show (settings_table);
65 gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0);
66 gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3);
67 gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5);
68 gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10);
70 label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1);
71 label_dbname = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2);
72 label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3);
73 label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4);
74 label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
76 entry_hostname = add_entry_to_table (settings_table,
77 gmyth_backend_info_get_hostname (backend_info),
79 entry_dbname = add_entry_to_table (settings_table,
80 gmyth_backend_info_get_db_name (backend_info),
82 entry_username = add_entry_to_table (settings_table,
83 gmyth_backend_info_get_username (backend_info),
85 entry_passwd = add_entry_to_table (settings_table,
86 gmyth_backend_info_get_password (backend_info),
89 entry_port = add_entry_to_table (settings_table, g_strdup_printf( "%d", gmyth_backend_info_get_port (backend_info) ),
92 if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
93 settings_dialog_update_data ();
94 gtk_widget_destroy (settings_dialog);
98 gtk_widget_destroy (settings_dialog);
105 add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right,
106 guint pos_top, guint pos_bottom )
108 GtkWidget *tmp_label = gtk_label_new (str);
110 gtk_widget_show (tmp_label);
111 gtk_table_attach (GTK_TABLE (table), tmp_label,
112 pos_left, pos_right, pos_top, pos_bottom,
113 (GtkAttachOptions) (GTK_FILL),
114 (GtkAttachOptions) (0), 0, 0);
115 gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);
121 add_entry_to_table (GtkWidget *table, const gchar *init_str, guint pos_left, guint pos_right,
122 guint pos_top, guint pos_bottom)
124 GtkWidget *tmp_entry = gtk_entry_new ();
125 gtk_widget_show (tmp_entry);
126 gtk_table_attach (GTK_TABLE (table), tmp_entry,
127 pos_left, pos_right, pos_top, pos_bottom,
128 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
129 (GtkAttachOptions) (0), 0, 0);
131 gtk_entry_set_text (GTK_ENTRY (tmp_entry), init_str);
133 //gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
139 settings_dialog_update_data (void)
141 //GMythSettings *backend_info = gmyth_context_get_settings();
144 g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
148 gmyth_backend_info_set_hostname(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_hostname) ));
150 gmyth_backend_info_set_db_name(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
152 gmyth_backend_info_set_username(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_username)));
154 gmyth_backend_info_set_password(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
156 gmyth_backend_info_set_port(backend_info, (gint)g_ascii_strtoull( gtk_entry_get_text( GTK_ENTRY(entry_port) ),
159 //gmyth_backend_info_save (backend_info);