diff -r 000000000000 -r 318e94209a11 maemo-ui/src/mmyth_uisettings.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/maemo-ui/src/mmyth_uisettings.c Fri Dec 01 17:13:06 2006 +0000 @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mmyth_uisettings.h" + +#include "gmyth_context.h" + +static GtkWidget *settings_dialog; +static GtkWidget *entry_hostname; +static GtkWidget *entry_dbname; +static GtkWidget *entry_username; +static GtkWidget *entry_passwd; +static GtkWidget *entry_port; + +static void settings_dialog_update_data (void); +static GtkWidget* add_entry_to_table (GtkWidget *table, GString *init_str, + guint pos_left, guint pos_right, guint pos_top, guint pos_bottom); +static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str, + guint pos_left, guint pos_right, guint pos_top, guint pos_bottom); + + +gboolean +mmyth_uisettings_run (GtkWindow *main_window) +{ + + GtkWidget *settings_table; + GtkWidget *label_hostname, *label_dbname; + GtkWidget *label_username, *label_passwd, *label_port; + + GMythSettings *msettings = gmyth_context_get_settings(); + + settings_dialog = gtk_dialog_new_with_buttons ("Settings", + main_window, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT, + NULL); + + gtk_widget_set_size_request (settings_dialog, 400, 244); + +/* scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow1); + gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); + + viewport1 = gtk_viewport_new (NULL, NULL); + gtk_widget_show (viewport1); + gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1); + gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE); +*/ + + // Creates the table and attach it to the settings dialog + settings_table = gtk_table_new (5, 2, FALSE); + gtk_widget_show (settings_table); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3); + gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5); + gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10); + + label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1); + label_dbname = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2); + label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3); + label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4); + label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5); + + entry_hostname = add_entry_to_table (settings_table, + gmyth_settings_get_backend_hostname (msettings), + 1, 2, 0, 1); + entry_dbname = add_entry_to_table (settings_table, + gmyth_settings_get_dbname (msettings), + 1, 2, 1, 2 ); + entry_username = add_entry_to_table (settings_table, + gmyth_settings_get_username (msettings), + 1, 2, 2, 3 ); + entry_passwd = add_entry_to_table (settings_table, + gmyth_settings_get_password (msettings), + 1, 2, 3, 4 ); + + GString *str_port = g_string_new (""); + g_string_printf (str_port, "%d", + gmyth_settings_get_backend_port (msettings)); + entry_port = add_entry_to_table (settings_table, str_port, + 1, 2, 4, 5 ); + g_string_free (str_port, TRUE); + + if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) { + settings_dialog_update_data (); + gtk_widget_destroy (settings_dialog); + return TRUE; + } + + gtk_widget_destroy (settings_dialog); + + return FALSE; + +} + +static GtkWidget* +add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right, + guint pos_top, guint pos_bottom ) +{ + GtkWidget *tmp_label = gtk_label_new (str); + + gtk_widget_show (tmp_label); + gtk_table_attach (GTK_TABLE (table), tmp_label, + pos_left, pos_right, pos_top, pos_bottom, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5); + + return tmp_label; +} + +static GtkWidget* +add_entry_to_table (GtkWidget *table, GString *init_str, guint pos_left, guint pos_right, + guint pos_top, guint pos_bottom) +{ + GtkWidget *tmp_entry = gtk_entry_new (); + gtk_widget_show (tmp_entry); + gtk_table_attach (GTK_TABLE (table), tmp_entry, + pos_left, pos_right, pos_top, pos_bottom, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + if (init_str) + gtk_entry_set_text (GTK_ENTRY (tmp_entry), (init_str->str)); + + //gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679); + + return tmp_entry; +} + +static void +settings_dialog_update_data (void) +{ + GString *tmp_entry_text; + GMythSettings *msettings = gmyth_context_get_settings(); + + if (!msettings) { + g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__); + return; + } + + tmp_entry_text = g_string_new(""); + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_hostname))); + gmyth_settings_set_backend_hostname(msettings, tmp_entry_text); + + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_dbname))); + gmyth_settings_set_dbname(msettings, tmp_entry_text); + + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_username))); + gmyth_settings_set_username(msettings, tmp_entry_text); + + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_passwd))); + gmyth_settings_set_password(msettings, tmp_entry_text); + + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_port))); + gmyth_settings_set_backend_port(msettings, atoi(tmp_entry_text->str)); + + gmyth_settings_save (msettings); + +}