maemo-ui/src/mmyth_uisettings.c
author renatofilho
Thu Apr 12 22:38:44 2007 +0100 (2007-04-12)
branchtrunk
changeset 541 0bf798c3f17e
parent 244 c88244670b08
child 754 cb885ee44618
permissions -rw-r--r--
[svn r546] fixed parse
     1 #include<gtk/gtk.h>
     2 #include<glib.h>
     3 #include <sys/types.h>
     4 #include <sys/stat.h>
     5 #include <unistd.h>
     6 #include <string.h>
     7 #include <stdio.h>
     8 #include <stdlib.h>
     9 
    10 #include "mmyth_uisettings.h"
    11 
    12 #include <gmyth/gmyth_backendinfo.h>
    13 
    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;
    20 
    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);
    26 	
    27 static GMythBackendInfo *backend_info = NULL;
    28 
    29 gboolean
    30 mmyth_uisettings_run (GtkWindow *main_window)
    31 {
    32 
    33 	GtkWidget *settings_table;
    34 	GtkWidget *label_hostname, *label_dbname;
    35 	GtkWidget *label_username, *label_passwd, *label_port;
    36 
    37 	backend_info = gmyth_backend_info_new_full( "localhost", "mythtv", 
    38 			"mythtv", "mythconverg", 6543 );
    39 	
    40 	settings_dialog = gtk_dialog_new_with_buttons ("Settings",
    41                                          main_window,
    42                                          GTK_DIALOG_DESTROY_WITH_PARENT,
    43                                          GTK_STOCK_OK,
    44                                          GTK_RESPONSE_ACCEPT,
    45                                          GTK_STOCK_CANCEL,
    46                                          GTK_RESPONSE_REJECT,
    47                                          NULL);
    48                                          
    49   gtk_widget_set_size_request (settings_dialog, 400, 244);
    50 
    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);
    55 
    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);
    60 */
    61 
    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);
    69 
    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);
    75 	
    76 	entry_hostname = add_entry_to_table (settings_table,
    77 		gmyth_backend_info_get_hostname (backend_info),
    78 		1, 2, 0, 1);
    79 	entry_dbname = add_entry_to_table (settings_table,
    80 		gmyth_backend_info_get_db_name (backend_info),
    81 		1, 2, 1, 2 );
    82 	entry_username = add_entry_to_table (settings_table,
    83 		gmyth_backend_info_get_username (backend_info),
    84 		1, 2, 2, 3 );
    85 	entry_passwd = add_entry_to_table (settings_table,
    86 		gmyth_backend_info_get_password (backend_info),
    87 		1, 2, 3, 4 );
    88 		
    89 	entry_port = add_entry_to_table (settings_table, g_strdup_printf( "%d", gmyth_backend_info_get_port (backend_info) ),
    90 		1, 2, 4, 5 );
    91 		
    92 	if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
    93 		settings_dialog_update_data ();
    94 		gtk_widget_destroy (settings_dialog);
    95 		return TRUE;
    96 	}
    97 	
    98 	gtk_widget_destroy (settings_dialog);
    99 	
   100 	return FALSE;
   101 	
   102 }
   103 
   104 static GtkWidget*
   105 add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right, 
   106 		guint pos_top, guint pos_bottom )
   107 {
   108 	GtkWidget *tmp_label = gtk_label_new (str);
   109 	
   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);
   116 	
   117 	return tmp_label;
   118 }
   119 
   120 static GtkWidget*
   121 add_entry_to_table (GtkWidget *table, const gchar *init_str, guint pos_left, guint pos_right,
   122 		guint pos_top, guint pos_bottom)
   123 {
   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);
   130     if (init_str)
   131 		gtk_entry_set_text (GTK_ENTRY (tmp_entry), init_str);
   132 		
   133 	//gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
   134 	
   135 	return tmp_entry;
   136 }
   137 
   138 static void
   139 settings_dialog_update_data (void) 
   140 {
   141 	//GMythSettings *backend_info = gmyth_context_get_settings();
   142 	
   143 	if (!backend_info) {
   144 		g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
   145 		return;
   146 	}
   147 		
   148 	gmyth_backend_info_set_hostname(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_hostname) ));
   149 	
   150 	gmyth_backend_info_set_db_name(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
   151 	
   152 	gmyth_backend_info_set_username(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_username)));
   153 
   154 	gmyth_backend_info_set_password(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
   155 	
   156 	gmyth_backend_info_set_port(backend_info, (gint)g_ascii_strtoull( gtk_entry_get_text( GTK_ENTRY(entry_port) ), 
   157 				NULL, 10) );
   158 	
   159 	//gmyth_backend_info_save (backend_info);
   160 	
   161 }