maemo-ui/src/mmyth_uisettings.c
author rosfran
Wed Mar 28 15:53:29 2007 +0100 (2007-03-28)
branchtrunk
changeset 467 bc13aaf7561d
parent 244 c88244670b08
child 754 cb885ee44618
permissions -rw-r--r--
[svn r472] Changed all the g_debug, g_warning and g_debug calls, to the gmyth_debug status/error printing function.
renatofilho@20
     1
#include<gtk/gtk.h>
renatofilho@20
     2
#include<glib.h>
renatofilho@20
     3
#include <sys/types.h>
renatofilho@20
     4
#include <sys/stat.h>
renatofilho@20
     5
#include <unistd.h>
renatofilho@20
     6
#include <string.h>
renatofilho@20
     7
#include <stdio.h>
renatofilho@20
     8
#include <stdlib.h>
renatofilho@20
     9
renatofilho@20
    10
#include "mmyth_uisettings.h"
renatofilho@20
    11
rosfran@208
    12
#include <gmyth/gmyth_backendinfo.h>
renatofilho@20
    13
renatofilho@20
    14
static GtkWidget *settings_dialog;
renatofilho@20
    15
static GtkWidget *entry_hostname;
renatofilho@20
    16
static GtkWidget *entry_dbname;
renatofilho@20
    17
static GtkWidget *entry_username;
renatofilho@20
    18
static GtkWidget *entry_passwd;
renatofilho@20
    19
static GtkWidget *entry_port;
renatofilho@20
    20
renatofilho@20
    21
static void settings_dialog_update_data (void);
rosfran@208
    22
static GtkWidget* add_entry_to_table (GtkWidget *table, const gchar *init_str,
renatofilho@20
    23
	guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
renatofilho@20
    24
static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str, 
renatofilho@20
    25
	guint pos_left, guint pos_right,  guint pos_top, guint pos_bottom);
renatofilho@20
    26
	
rosfran@208
    27
static GMythBackendInfo *backend_info = NULL;
rosfran@208
    28
renatofilho@20
    29
gboolean
renatofilho@20
    30
mmyth_uisettings_run (GtkWindow *main_window)
renatofilho@20
    31
{
renatofilho@20
    32
renatofilho@20
    33
	GtkWidget *settings_table;
renatofilho@20
    34
	GtkWidget *label_hostname, *label_dbname;
renatofilho@20
    35
	GtkWidget *label_username, *label_passwd, *label_port;
renatofilho@20
    36
morphbr@268
    37
	backend_info = gmyth_backend_info_new_full( "localhost", "mythtv", 
rosfran@208
    38
			"mythtv", "mythconverg", 6543 );
renatofilho@20
    39
	
renatofilho@20
    40
	settings_dialog = gtk_dialog_new_with_buttons ("Settings",
renatofilho@20
    41
                                         main_window,
renatofilho@20
    42
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
renatofilho@20
    43
                                         GTK_STOCK_OK,
renatofilho@20
    44
                                         GTK_RESPONSE_ACCEPT,
renatofilho@20
    45
                                         GTK_STOCK_CANCEL,
renatofilho@20
    46
                                         GTK_RESPONSE_REJECT,
renatofilho@20
    47
                                         NULL);
renatofilho@20
    48
                                         
renatofilho@20
    49
  gtk_widget_set_size_request (settings_dialog, 400, 244);
renatofilho@20
    50
renatofilho@20
    51
/*  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
renatofilho@20
    52
  gtk_widget_show (scrolledwindow1);
renatofilho@20
    53
  gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
renatofilho@20
    54
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
renatofilho@20
    55
renatofilho@20
    56
  viewport1 = gtk_viewport_new (NULL, NULL);
renatofilho@20
    57
  gtk_widget_show (viewport1);
renatofilho@20
    58
  gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1);
renatofilho@20
    59
  gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE);
renatofilho@20
    60
*/
renatofilho@20
    61
renatofilho@20
    62
	// Creates the table and attach it to the settings dialog
renatofilho@20
    63
	settings_table = gtk_table_new (5, 2, FALSE);
renatofilho@20
    64
	gtk_widget_show (settings_table);
renatofilho@20
    65
	gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0);
renatofilho@20
    66
	gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3);
renatofilho@20
    67
	gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5);
renatofilho@20
    68
	gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10);
renatofilho@20
    69
renatofilho@20
    70
	label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1);
renatofilho@20
    71
	label_dbname   = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2);
renatofilho@20
    72
	label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3);
renatofilho@20
    73
	label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4);
renatofilho@20
    74
	label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
renatofilho@20
    75
	
renatofilho@20
    76
	entry_hostname = add_entry_to_table (settings_table,
rosfran@208
    77
		gmyth_backend_info_get_hostname (backend_info),
renatofilho@20
    78
		1, 2, 0, 1);
renatofilho@20
    79
	entry_dbname = add_entry_to_table (settings_table,
rosfran@208
    80
		gmyth_backend_info_get_db_name (backend_info),
renatofilho@20
    81
		1, 2, 1, 2 );
renatofilho@20
    82
	entry_username = add_entry_to_table (settings_table,
rosfran@208
    83
		gmyth_backend_info_get_username (backend_info),
renatofilho@20
    84
		1, 2, 2, 3 );
renatofilho@20
    85
	entry_passwd = add_entry_to_table (settings_table,
rosfran@208
    86
		gmyth_backend_info_get_password (backend_info),
renatofilho@20
    87
		1, 2, 3, 4 );
renatofilho@20
    88
		
rosfran@208
    89
	entry_port = add_entry_to_table (settings_table, g_strdup_printf( "%d", gmyth_backend_info_get_port (backend_info) ),
renatofilho@20
    90
		1, 2, 4, 5 );
renatofilho@20
    91
		
renatofilho@20
    92
	if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
renatofilho@20
    93
		settings_dialog_update_data ();
renatofilho@20
    94
		gtk_widget_destroy (settings_dialog);
renatofilho@20
    95
		return TRUE;
renatofilho@20
    96
	}
renatofilho@20
    97
	
renatofilho@20
    98
	gtk_widget_destroy (settings_dialog);
renatofilho@20
    99
	
renatofilho@20
   100
	return FALSE;
renatofilho@20
   101
	
renatofilho@20
   102
}
renatofilho@20
   103
renatofilho@20
   104
static GtkWidget*
renatofilho@20
   105
add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right, 
renatofilho@20
   106
		guint pos_top, guint pos_bottom )
renatofilho@20
   107
{
renatofilho@20
   108
	GtkWidget *tmp_label = gtk_label_new (str);
renatofilho@20
   109
	
renatofilho@20
   110
	gtk_widget_show (tmp_label);
renatofilho@20
   111
	gtk_table_attach (GTK_TABLE (table), tmp_label, 
renatofilho@20
   112
					pos_left, pos_right, pos_top, pos_bottom,
renatofilho@20
   113
                    (GtkAttachOptions) (GTK_FILL),
renatofilho@20
   114
                    (GtkAttachOptions) (0), 0, 0);
renatofilho@20
   115
	gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);
renatofilho@20
   116
	
renatofilho@20
   117
	return tmp_label;
renatofilho@20
   118
}
renatofilho@20
   119
renatofilho@20
   120
static GtkWidget*
rosfran@208
   121
add_entry_to_table (GtkWidget *table, const gchar *init_str, guint pos_left, guint pos_right,
renatofilho@20
   122
		guint pos_top, guint pos_bottom)
renatofilho@20
   123
{
renatofilho@20
   124
	GtkWidget *tmp_entry = gtk_entry_new ();
renatofilho@20
   125
	gtk_widget_show (tmp_entry);
renatofilho@20
   126
	gtk_table_attach (GTK_TABLE (table), tmp_entry, 
renatofilho@20
   127
					pos_left, pos_right, pos_top, pos_bottom,
renatofilho@20
   128
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
renatofilho@20
   129
                    (GtkAttachOptions) (0), 0, 0);
renatofilho@20
   130
    if (init_str)
rosfran@208
   131
		gtk_entry_set_text (GTK_ENTRY (tmp_entry), init_str);
renatofilho@20
   132
		
renatofilho@20
   133
	//gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
renatofilho@20
   134
	
renatofilho@20
   135
	return tmp_entry;
renatofilho@20
   136
}
renatofilho@20
   137
renatofilho@20
   138
static void
renatofilho@20
   139
settings_dialog_update_data (void) 
renatofilho@20
   140
{
rosfran@208
   141
	//GMythSettings *backend_info = gmyth_context_get_settings();
renatofilho@20
   142
	
rosfran@208
   143
	if (!backend_info) {
renatofilho@20
   144
		g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
renatofilho@20
   145
		return;
renatofilho@20
   146
	}
renatofilho@20
   147
		
rosfran@208
   148
	gmyth_backend_info_set_hostname(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_hostname) ));
renatofilho@20
   149
	
rosfran@208
   150
	gmyth_backend_info_set_db_name(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
renatofilho@20
   151
	
rosfran@208
   152
	gmyth_backend_info_set_username(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_username)));
rosfran@208
   153
rosfran@208
   154
	gmyth_backend_info_set_password(backend_info, gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
renatofilho@20
   155
	
rosfran@208
   156
	gmyth_backend_info_set_port(backend_info, (gint)g_ascii_strtoull( gtk_entry_get_text( GTK_ENTRY(entry_port) ), 
rosfran@208
   157
				NULL, 10) );
renatofilho@20
   158
	
rosfran@208
   159
	//gmyth_backend_info_save (backend_info);
renatofilho@20
   160
	
renatofilho@20
   161
}