maemo-ui-old/src/mmyth_uisettings.c
branchtrunk
changeset 860 bb5592a9ac48
parent 754 cb885ee44618
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/maemo-ui-old/src/mmyth_uisettings.c	Mon Oct 08 19:35:09 2007 +0100
     1.3 @@ -0,0 +1,196 @@
     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/gmyth_backendinfo.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,
    1.26 +                                     const gchar * init_str,
    1.27 +                                     guint pos_left, guint pos_right,
    1.28 +                                     guint pos_top, guint pos_bottom);
    1.29 +static GtkWidget *add_label_to_table(GtkWidget * table, const gchar * str,
    1.30 +                                     guint pos_left, guint pos_right,
    1.31 +                                     guint pos_top, guint pos_bottom);
    1.32 +
    1.33 +static GMythBackendInfo *backend_info = NULL;
    1.34 +
    1.35 +gboolean
    1.36 +mmyth_uisettings_run(GtkWindow * main_window)
    1.37 +{
    1.38 +
    1.39 +    GtkWidget      *settings_table;
    1.40 +    GtkWidget      *label_hostname,
    1.41 +                   *label_dbname;
    1.42 +    GtkWidget      *label_username,
    1.43 +                   *label_passwd,
    1.44 +                   *label_port;
    1.45 +
    1.46 +    backend_info = gmyth_backend_info_new_full("localhost", "mythtv",
    1.47 +                                               "mythtv", "mythconverg",
    1.48 +                                               6543);
    1.49 +
    1.50 +    settings_dialog = gtk_dialog_new_with_buttons("Settings",
    1.51 +                                                  main_window,
    1.52 +                                                  GTK_DIALOG_DESTROY_WITH_PARENT,
    1.53 +                                                  GTK_STOCK_OK,
    1.54 +                                                  GTK_RESPONSE_ACCEPT,
    1.55 +                                                  GTK_STOCK_CANCEL,
    1.56 +                                                  GTK_RESPONSE_REJECT,
    1.57 +                                                  NULL);
    1.58 +
    1.59 +    gtk_widget_set_size_request(settings_dialog, 400, 244);
    1.60 +
    1.61 +    /*
    1.62 +     * scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
    1.63 +     * gtk_widget_show (scrolledwindow1); gtk_container_add (GTK_CONTAINER 
    1.64 +     * (window1), scrolledwindow1); gtk_scrolled_window_set_policy
    1.65 +     * (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC,
    1.66 +     * GTK_POLICY_NEVER);
    1.67 +     * 
    1.68 +     * viewport1 = gtk_viewport_new (NULL, NULL); gtk_widget_show
    1.69 +     * (viewport1); gtk_container_add (GTK_CONTAINER (scrolledwindow1),
    1.70 +     * viewport1); gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), 
    1.71 +     * GTK_SHADOW_NONE); 
    1.72 +     */
    1.73 +
    1.74 +    // Creates the table and attach it to the settings dialog
    1.75 +    settings_table = gtk_table_new(5, 2, FALSE);
    1.76 +    gtk_widget_show(settings_table);
    1.77 +    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(settings_dialog)->vbox),
    1.78 +                       settings_table, FALSE, TRUE, 0);
    1.79 +    gtk_container_set_border_width(GTK_CONTAINER(settings_table), 3);
    1.80 +    gtk_table_set_row_spacings(GTK_TABLE(settings_table), 5);
    1.81 +    gtk_table_set_col_spacings(GTK_TABLE(settings_table), 10);
    1.82 +
    1.83 +    label_hostname =
    1.84 +        add_label_to_table(settings_table, "Host Name:", 0, 1, 0, 1);
    1.85 +    label_dbname =
    1.86 +        add_label_to_table(settings_table, "Database Name:", 0, 1, 1, 2);
    1.87 +    label_username =
    1.88 +        add_label_to_table(settings_table, "Username:", 0, 1, 2, 3);
    1.89 +    label_passwd =
    1.90 +        add_label_to_table(settings_table, "Password:", 0, 1, 3, 4);
    1.91 +    label_port =
    1.92 +        add_label_to_table(settings_table, "Server port:", 0, 1, 4, 5);
    1.93 +
    1.94 +    entry_hostname = add_entry_to_table(settings_table,
    1.95 +                                        gmyth_backend_info_get_hostname
    1.96 +                                        (backend_info), 1, 2, 0, 1);
    1.97 +    entry_dbname =
    1.98 +        add_entry_to_table(settings_table,
    1.99 +                           gmyth_backend_info_get_db_name(backend_info), 1,
   1.100 +                           2, 1, 2);
   1.101 +    entry_username =
   1.102 +        add_entry_to_table(settings_table,
   1.103 +                           gmyth_backend_info_get_username(backend_info),
   1.104 +                           1, 2, 2, 3);
   1.105 +    entry_passwd =
   1.106 +        add_entry_to_table(settings_table,
   1.107 +                           gmyth_backend_info_get_password(backend_info),
   1.108 +                           1, 2, 3, 4);
   1.109 +
   1.110 +    entry_port =
   1.111 +        add_entry_to_table(settings_table,
   1.112 +                           g_strdup_printf("%d",
   1.113 +                                           gmyth_backend_info_get_port
   1.114 +                                           (backend_info)), 1, 2, 4, 5);
   1.115 +
   1.116 +    if (gtk_dialog_run(GTK_DIALOG(settings_dialog)) == GTK_RESPONSE_ACCEPT) {
   1.117 +        settings_dialog_update_data();
   1.118 +        gtk_widget_destroy(settings_dialog);
   1.119 +        return TRUE;
   1.120 +    }
   1.121 +
   1.122 +    gtk_widget_destroy(settings_dialog);
   1.123 +
   1.124 +    return FALSE;
   1.125 +
   1.126 +}
   1.127 +
   1.128 +static GtkWidget *
   1.129 +add_label_to_table(GtkWidget * table, const gchar * str, guint pos_left,
   1.130 +                   guint pos_right, guint pos_top, guint pos_bottom)
   1.131 +{
   1.132 +    GtkWidget      *tmp_label = gtk_label_new(str);
   1.133 +
   1.134 +    gtk_widget_show(tmp_label);
   1.135 +    gtk_table_attach(GTK_TABLE(table), tmp_label,
   1.136 +                     pos_left, pos_right, pos_top, pos_bottom,
   1.137 +                     (GtkAttachOptions) (GTK_FILL),
   1.138 +                     (GtkAttachOptions) (0), 0, 0);
   1.139 +    gtk_misc_set_alignment(GTK_MISC(tmp_label), 0, 0.5);
   1.140 +
   1.141 +    return tmp_label;
   1.142 +}
   1.143 +
   1.144 +static GtkWidget *
   1.145 +add_entry_to_table(GtkWidget * table, const gchar * init_str,
   1.146 +                   guint pos_left, guint pos_right, guint pos_top,
   1.147 +                   guint pos_bottom)
   1.148 +{
   1.149 +    GtkWidget      *tmp_entry = gtk_entry_new();
   1.150 +    gtk_widget_show(tmp_entry);
   1.151 +    gtk_table_attach(GTK_TABLE(table), tmp_entry,
   1.152 +                     pos_left, pos_right, pos_top, pos_bottom,
   1.153 +                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
   1.154 +                     (GtkAttachOptions) (0), 0, 0);
   1.155 +    if (init_str)
   1.156 +        gtk_entry_set_text(GTK_ENTRY(tmp_entry), init_str);
   1.157 +
   1.158 +    // gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
   1.159 +
   1.160 +    return tmp_entry;
   1.161 +}
   1.162 +
   1.163 +static void
   1.164 +settings_dialog_update_data(void)
   1.165 +{
   1.166 +    // GMythSettings *backend_info = gmyth_context_get_settings();
   1.167 +
   1.168 +    if (!backend_info) {
   1.169 +        g_warning
   1.170 +            ("[%s] Could not get GMythSettings instance from context\n",
   1.171 +             __FUNCTION__);
   1.172 +        return;
   1.173 +    }
   1.174 +
   1.175 +    gmyth_backend_info_set_hostname(backend_info,
   1.176 +                                    gtk_entry_get_text(GTK_ENTRY
   1.177 +                                                       (entry_hostname)));
   1.178 +
   1.179 +    gmyth_backend_info_set_db_name(backend_info,
   1.180 +                                   gtk_entry_get_text(GTK_ENTRY
   1.181 +                                                      (entry_dbname)));
   1.182 +
   1.183 +    gmyth_backend_info_set_username(backend_info,
   1.184 +                                    gtk_entry_get_text(GTK_ENTRY
   1.185 +                                                       (entry_username)));
   1.186 +
   1.187 +    gmyth_backend_info_set_password(backend_info,
   1.188 +                                    gtk_entry_get_text(GTK_ENTRY
   1.189 +                                                       (entry_passwd)));
   1.190 +
   1.191 +    gmyth_backend_info_set_port(backend_info,
   1.192 +                                (gint)
   1.193 +                                g_ascii_strtoull(gtk_entry_get_text
   1.194 +                                                 (GTK_ENTRY(entry_port)),
   1.195 +                                                 NULL, 10));
   1.196 +
   1.197 +    // gmyth_backend_info_save (backend_info);
   1.198 +
   1.199 +}