1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/maemo-ui/src/mmyth_uisettings.c Fri Oct 06 16:13:28 2006 +0100
1.3 @@ -0,0 +1,169 @@
1.4 +#include<gtk/gtk.h>
1.5 +#include<glib.h>
1.6 +#include <sys/types.h>
1.7 +#include <sys/stat.h>
1.8 +#include <unistd.h>
1.9 +#include <string.h>
1.10 +#include <stdio.h>
1.11 +#include <stdlib.h>
1.12 +
1.13 +#include "mmyth_uisettings.h"
1.14 +
1.15 +#include "gmyth_context.h"
1.16 +
1.17 +static GtkWidget *settings_dialog;
1.18 +static GtkWidget *entry_hostname;
1.19 +static GtkWidget *entry_dbname;
1.20 +static GtkWidget *entry_username;
1.21 +static GtkWidget *entry_passwd;
1.22 +static GtkWidget *entry_port;
1.23 +
1.24 +static void settings_dialog_update_data (void);
1.25 +static GtkWidget* add_entry_to_table (GtkWidget *table, GString *init_str,
1.26 + guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
1.27 +static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str,
1.28 + guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
1.29 +
1.30 +
1.31 +gboolean
1.32 +mmyth_uisettings_run (GtkWindow *main_window)
1.33 +{
1.34 +
1.35 + GtkWidget *settings_table;
1.36 + GtkWidget *label_hostname, *label_dbname;
1.37 + GtkWidget *label_username, *label_passwd, *label_port;
1.38 +
1.39 + GMythSettings *msettings = gmyth_context_get_settings();
1.40 +
1.41 + settings_dialog = gtk_dialog_new_with_buttons ("Settings",
1.42 + main_window,
1.43 + GTK_DIALOG_DESTROY_WITH_PARENT,
1.44 + GTK_STOCK_OK,
1.45 + GTK_RESPONSE_ACCEPT,
1.46 + GTK_STOCK_CANCEL,
1.47 + GTK_RESPONSE_REJECT,
1.48 + NULL);
1.49 +
1.50 + gtk_widget_set_size_request (settings_dialog, 400, 244);
1.51 +
1.52 +/* scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
1.53 + gtk_widget_show (scrolledwindow1);
1.54 + gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
1.55 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
1.56 +
1.57 + viewport1 = gtk_viewport_new (NULL, NULL);
1.58 + gtk_widget_show (viewport1);
1.59 + gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1);
1.60 + gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE);
1.61 +*/
1.62 +
1.63 + // Creates the table and attach it to the settings dialog
1.64 + settings_table = gtk_table_new (5, 2, FALSE);
1.65 + gtk_widget_show (settings_table);
1.66 + gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0);
1.67 + gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3);
1.68 + gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5);
1.69 + gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10);
1.70 +
1.71 + label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1);
1.72 + label_dbname = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2);
1.73 + label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3);
1.74 + label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4);
1.75 + label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
1.76 +
1.77 + entry_hostname = add_entry_to_table (settings_table,
1.78 + gmyth_settings_get_backend_hostname (msettings),
1.79 + 1, 2, 0, 1);
1.80 + entry_dbname = add_entry_to_table (settings_table,
1.81 + gmyth_settings_get_dbname (msettings),
1.82 + 1, 2, 1, 2 );
1.83 + entry_username = add_entry_to_table (settings_table,
1.84 + gmyth_settings_get_username (msettings),
1.85 + 1, 2, 2, 3 );
1.86 + entry_passwd = add_entry_to_table (settings_table,
1.87 + gmyth_settings_get_password (msettings),
1.88 + 1, 2, 3, 4 );
1.89 +
1.90 + GString *str_port = g_string_new ("");
1.91 + g_string_printf (str_port, "%d",
1.92 + gmyth_settings_get_backend_port (msettings));
1.93 + entry_port = add_entry_to_table (settings_table, str_port,
1.94 + 1, 2, 4, 5 );
1.95 + g_string_free (str_port, TRUE);
1.96 +
1.97 + if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
1.98 + settings_dialog_update_data ();
1.99 + gtk_widget_destroy (settings_dialog);
1.100 + return TRUE;
1.101 + }
1.102 +
1.103 + gtk_widget_destroy (settings_dialog);
1.104 +
1.105 + return FALSE;
1.106 +
1.107 +}
1.108 +
1.109 +static GtkWidget*
1.110 +add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right,
1.111 + guint pos_top, guint pos_bottom )
1.112 +{
1.113 + GtkWidget *tmp_label = gtk_label_new (str);
1.114 +
1.115 + gtk_widget_show (tmp_label);
1.116 + gtk_table_attach (GTK_TABLE (table), tmp_label,
1.117 + pos_left, pos_right, pos_top, pos_bottom,
1.118 + (GtkAttachOptions) (GTK_FILL),
1.119 + (GtkAttachOptions) (0), 0, 0);
1.120 + gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);
1.121 +
1.122 + return tmp_label;
1.123 +}
1.124 +
1.125 +static GtkWidget*
1.126 +add_entry_to_table (GtkWidget *table, GString *init_str, guint pos_left, guint pos_right,
1.127 + guint pos_top, guint pos_bottom)
1.128 +{
1.129 + GtkWidget *tmp_entry = gtk_entry_new ();
1.130 + gtk_widget_show (tmp_entry);
1.131 + gtk_table_attach (GTK_TABLE (table), tmp_entry,
1.132 + pos_left, pos_right, pos_top, pos_bottom,
1.133 + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1.134 + (GtkAttachOptions) (0), 0, 0);
1.135 + if (init_str)
1.136 + gtk_entry_set_text (GTK_ENTRY (tmp_entry), (init_str->str));
1.137 +
1.138 + //gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
1.139 +
1.140 + return tmp_entry;
1.141 +}
1.142 +
1.143 +static void
1.144 +settings_dialog_update_data (void)
1.145 +{
1.146 + GString *tmp_entry_text;
1.147 + GMythSettings *msettings = gmyth_context_get_settings();
1.148 +
1.149 + if (!msettings) {
1.150 + g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
1.151 + return;
1.152 + }
1.153 +
1.154 + tmp_entry_text = g_string_new("");
1.155 + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_hostname)));
1.156 + gmyth_settings_set_backend_hostname(msettings, tmp_entry_text);
1.157 +
1.158 + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
1.159 + gmyth_settings_set_dbname(msettings, tmp_entry_text);
1.160 +
1.161 + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_username)));
1.162 + gmyth_settings_set_username(msettings, tmp_entry_text);
1.163 +
1.164 + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
1.165 + gmyth_settings_set_password(msettings, tmp_entry_text);
1.166 +
1.167 + g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_port)));
1.168 + gmyth_settings_set_backend_port(msettings, atoi(tmp_entry_text->str));
1.169 +
1.170 + gmyth_settings_save (msettings);
1.171 +
1.172 +}