maemo-ui-old/src/mmyth_uisettings.c
author melunko
Mon Oct 08 19:35:09 2007 +0100 (2007-10-08)
branchtrunk
changeset 860 bb5592a9ac48
parent 754 cb885ee44618
permissions -rw-r--r--
[svn r866] Fixed gst-gmyth Makefile to get source from gstreamer cvs
     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,
    23                                      const gchar * init_str,
    24                                      guint pos_left, guint pos_right,
    25                                      guint pos_top, guint pos_bottom);
    26 static GtkWidget *add_label_to_table(GtkWidget * table, const gchar * str,
    27                                      guint pos_left, guint pos_right,
    28                                      guint pos_top, guint pos_bottom);
    29 
    30 static GMythBackendInfo *backend_info = NULL;
    31 
    32 gboolean
    33 mmyth_uisettings_run(GtkWindow * main_window)
    34 {
    35 
    36     GtkWidget      *settings_table;
    37     GtkWidget      *label_hostname,
    38                    *label_dbname;
    39     GtkWidget      *label_username,
    40                    *label_passwd,
    41                    *label_port;
    42 
    43     backend_info = gmyth_backend_info_new_full("localhost", "mythtv",
    44                                                "mythtv", "mythconverg",
    45                                                6543);
    46 
    47     settings_dialog = gtk_dialog_new_with_buttons("Settings",
    48                                                   main_window,
    49                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
    50                                                   GTK_STOCK_OK,
    51                                                   GTK_RESPONSE_ACCEPT,
    52                                                   GTK_STOCK_CANCEL,
    53                                                   GTK_RESPONSE_REJECT,
    54                                                   NULL);
    55 
    56     gtk_widget_set_size_request(settings_dialog, 400, 244);
    57 
    58     /*
    59      * scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
    60      * gtk_widget_show (scrolledwindow1); gtk_container_add (GTK_CONTAINER 
    61      * (window1), scrolledwindow1); gtk_scrolled_window_set_policy
    62      * (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC,
    63      * GTK_POLICY_NEVER);
    64      * 
    65      * viewport1 = gtk_viewport_new (NULL, NULL); gtk_widget_show
    66      * (viewport1); gtk_container_add (GTK_CONTAINER (scrolledwindow1),
    67      * viewport1); gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), 
    68      * GTK_SHADOW_NONE); 
    69      */
    70 
    71     // Creates the table and attach it to the settings dialog
    72     settings_table = gtk_table_new(5, 2, FALSE);
    73     gtk_widget_show(settings_table);
    74     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(settings_dialog)->vbox),
    75                        settings_table, FALSE, TRUE, 0);
    76     gtk_container_set_border_width(GTK_CONTAINER(settings_table), 3);
    77     gtk_table_set_row_spacings(GTK_TABLE(settings_table), 5);
    78     gtk_table_set_col_spacings(GTK_TABLE(settings_table), 10);
    79 
    80     label_hostname =
    81         add_label_to_table(settings_table, "Host Name:", 0, 1, 0, 1);
    82     label_dbname =
    83         add_label_to_table(settings_table, "Database Name:", 0, 1, 1, 2);
    84     label_username =
    85         add_label_to_table(settings_table, "Username:", 0, 1, 2, 3);
    86     label_passwd =
    87         add_label_to_table(settings_table, "Password:", 0, 1, 3, 4);
    88     label_port =
    89         add_label_to_table(settings_table, "Server port:", 0, 1, 4, 5);
    90 
    91     entry_hostname = add_entry_to_table(settings_table,
    92                                         gmyth_backend_info_get_hostname
    93                                         (backend_info), 1, 2, 0, 1);
    94     entry_dbname =
    95         add_entry_to_table(settings_table,
    96                            gmyth_backend_info_get_db_name(backend_info), 1,
    97                            2, 1, 2);
    98     entry_username =
    99         add_entry_to_table(settings_table,
   100                            gmyth_backend_info_get_username(backend_info),
   101                            1, 2, 2, 3);
   102     entry_passwd =
   103         add_entry_to_table(settings_table,
   104                            gmyth_backend_info_get_password(backend_info),
   105                            1, 2, 3, 4);
   106 
   107     entry_port =
   108         add_entry_to_table(settings_table,
   109                            g_strdup_printf("%d",
   110                                            gmyth_backend_info_get_port
   111                                            (backend_info)), 1, 2, 4, 5);
   112 
   113     if (gtk_dialog_run(GTK_DIALOG(settings_dialog)) == GTK_RESPONSE_ACCEPT) {
   114         settings_dialog_update_data();
   115         gtk_widget_destroy(settings_dialog);
   116         return TRUE;
   117     }
   118 
   119     gtk_widget_destroy(settings_dialog);
   120 
   121     return FALSE;
   122 
   123 }
   124 
   125 static GtkWidget *
   126 add_label_to_table(GtkWidget * table, const gchar * str, guint pos_left,
   127                    guint pos_right, guint pos_top, guint pos_bottom)
   128 {
   129     GtkWidget      *tmp_label = gtk_label_new(str);
   130 
   131     gtk_widget_show(tmp_label);
   132     gtk_table_attach(GTK_TABLE(table), tmp_label,
   133                      pos_left, pos_right, pos_top, pos_bottom,
   134                      (GtkAttachOptions) (GTK_FILL),
   135                      (GtkAttachOptions) (0), 0, 0);
   136     gtk_misc_set_alignment(GTK_MISC(tmp_label), 0, 0.5);
   137 
   138     return tmp_label;
   139 }
   140 
   141 static GtkWidget *
   142 add_entry_to_table(GtkWidget * table, const gchar * init_str,
   143                    guint pos_left, guint pos_right, guint pos_top,
   144                    guint pos_bottom)
   145 {
   146     GtkWidget      *tmp_entry = gtk_entry_new();
   147     gtk_widget_show(tmp_entry);
   148     gtk_table_attach(GTK_TABLE(table), tmp_entry,
   149                      pos_left, pos_right, pos_top, pos_bottom,
   150                      (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
   151                      (GtkAttachOptions) (0), 0, 0);
   152     if (init_str)
   153         gtk_entry_set_text(GTK_ENTRY(tmp_entry), init_str);
   154 
   155     // gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
   156 
   157     return tmp_entry;
   158 }
   159 
   160 static void
   161 settings_dialog_update_data(void)
   162 {
   163     // GMythSettings *backend_info = gmyth_context_get_settings();
   164 
   165     if (!backend_info) {
   166         g_warning
   167             ("[%s] Could not get GMythSettings instance from context\n",
   168              __FUNCTION__);
   169         return;
   170     }
   171 
   172     gmyth_backend_info_set_hostname(backend_info,
   173                                     gtk_entry_get_text(GTK_ENTRY
   174                                                        (entry_hostname)));
   175 
   176     gmyth_backend_info_set_db_name(backend_info,
   177                                    gtk_entry_get_text(GTK_ENTRY
   178                                                       (entry_dbname)));
   179 
   180     gmyth_backend_info_set_username(backend_info,
   181                                     gtk_entry_get_text(GTK_ENTRY
   182                                                        (entry_username)));
   183 
   184     gmyth_backend_info_set_password(backend_info,
   185                                     gtk_entry_get_text(GTK_ENTRY
   186                                                        (entry_passwd)));
   187 
   188     gmyth_backend_info_set_port(backend_info,
   189                                 (gint)
   190                                 g_ascii_strtoull(gtk_entry_get_text
   191                                                  (GTK_ENTRY(entry_port)),
   192                                                  NULL, 10));
   193 
   194     // gmyth_backend_info_save (backend_info);
   195 
   196 }