leo_sobral@1
|
1 |
#include<gtk/gtk.h>
|
leo_sobral@1
|
2 |
#include<glib.h>
|
leo_sobral@1
|
3 |
#include <sys/types.h>
|
leo_sobral@1
|
4 |
#include <sys/stat.h>
|
leo_sobral@1
|
5 |
#include <unistd.h>
|
leo_sobral@1
|
6 |
#include <string.h>
|
leo_sobral@1
|
7 |
#include <stdio.h>
|
leo_sobral@1
|
8 |
#include <stdlib.h>
|
leo_sobral@1
|
9 |
|
leo_sobral@1
|
10 |
#include "mmyth_uisettings.h"
|
leo_sobral@1
|
11 |
|
leo_sobral@1
|
12 |
#include "gmyth_context.h"
|
leo_sobral@1
|
13 |
|
leo_sobral@1
|
14 |
static GtkWidget *settings_dialog;
|
leo_sobral@1
|
15 |
static GtkWidget *entry_hostname;
|
leo_sobral@1
|
16 |
static GtkWidget *entry_dbname;
|
leo_sobral@1
|
17 |
static GtkWidget *entry_username;
|
leo_sobral@1
|
18 |
static GtkWidget *entry_passwd;
|
leo_sobral@1
|
19 |
static GtkWidget *entry_port;
|
leo_sobral@1
|
20 |
|
leo_sobral@1
|
21 |
static void settings_dialog_update_data (void);
|
leo_sobral@1
|
22 |
static GtkWidget* add_entry_to_table (GtkWidget *table, GString *init_str,
|
leo_sobral@1
|
23 |
guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
|
leo_sobral@1
|
24 |
static GtkWidget* add_label_to_table (GtkWidget *table, const gchar *str,
|
leo_sobral@1
|
25 |
guint pos_left, guint pos_right, guint pos_top, guint pos_bottom);
|
leo_sobral@1
|
26 |
|
leo_sobral@1
|
27 |
|
leo_sobral@1
|
28 |
gboolean
|
leo_sobral@1
|
29 |
mmyth_uisettings_run (GtkWindow *main_window)
|
leo_sobral@1
|
30 |
{
|
leo_sobral@1
|
31 |
|
leo_sobral@1
|
32 |
GtkWidget *settings_table;
|
leo_sobral@1
|
33 |
GtkWidget *label_hostname, *label_dbname;
|
leo_sobral@1
|
34 |
GtkWidget *label_username, *label_passwd, *label_port;
|
leo_sobral@1
|
35 |
|
leo_sobral@1
|
36 |
GMythSettings *msettings = gmyth_context_get_settings();
|
leo_sobral@1
|
37 |
|
leo_sobral@1
|
38 |
settings_dialog = gtk_dialog_new_with_buttons ("Settings",
|
leo_sobral@1
|
39 |
main_window,
|
leo_sobral@1
|
40 |
GTK_DIALOG_DESTROY_WITH_PARENT,
|
leo_sobral@1
|
41 |
GTK_STOCK_OK,
|
leo_sobral@1
|
42 |
GTK_RESPONSE_ACCEPT,
|
leo_sobral@1
|
43 |
GTK_STOCK_CANCEL,
|
leo_sobral@1
|
44 |
GTK_RESPONSE_REJECT,
|
leo_sobral@1
|
45 |
NULL);
|
leo_sobral@1
|
46 |
|
leo_sobral@1
|
47 |
gtk_widget_set_size_request (settings_dialog, 400, 244);
|
leo_sobral@1
|
48 |
|
leo_sobral@1
|
49 |
/* scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
|
leo_sobral@1
|
50 |
gtk_widget_show (scrolledwindow1);
|
leo_sobral@1
|
51 |
gtk_container_add (GTK_CONTAINER (window1), scrolledwindow1);
|
leo_sobral@1
|
52 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
|
leo_sobral@1
|
53 |
|
leo_sobral@1
|
54 |
viewport1 = gtk_viewport_new (NULL, NULL);
|
leo_sobral@1
|
55 |
gtk_widget_show (viewport1);
|
leo_sobral@1
|
56 |
gtk_container_add (GTK_CONTAINER (scrolledwindow1), viewport1);
|
leo_sobral@1
|
57 |
gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport1), GTK_SHADOW_NONE);
|
leo_sobral@1
|
58 |
*/
|
leo_sobral@1
|
59 |
|
leo_sobral@1
|
60 |
// Creates the table and attach it to the settings dialog
|
leo_sobral@1
|
61 |
settings_table = gtk_table_new (5, 2, FALSE);
|
leo_sobral@1
|
62 |
gtk_widget_show (settings_table);
|
leo_sobral@1
|
63 |
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(settings_dialog)->vbox), settings_table, FALSE, TRUE, 0);
|
leo_sobral@1
|
64 |
gtk_container_set_border_width (GTK_CONTAINER (settings_table), 3);
|
leo_sobral@1
|
65 |
gtk_table_set_row_spacings (GTK_TABLE (settings_table), 5);
|
leo_sobral@1
|
66 |
gtk_table_set_col_spacings (GTK_TABLE (settings_table), 10);
|
leo_sobral@1
|
67 |
|
leo_sobral@1
|
68 |
label_hostname = add_label_to_table (settings_table, "Host Name:", 0, 1, 0, 1);
|
leo_sobral@1
|
69 |
label_dbname = add_label_to_table (settings_table, "Database Name:", 0, 1, 1, 2);
|
leo_sobral@1
|
70 |
label_username = add_label_to_table (settings_table, "Username:", 0, 1, 2, 3);
|
leo_sobral@1
|
71 |
label_passwd = add_label_to_table (settings_table, "Password:", 0, 1, 3, 4);
|
leo_sobral@1
|
72 |
label_port = add_label_to_table (settings_table, "Server port:", 0, 1, 4, 5);
|
leo_sobral@1
|
73 |
|
leo_sobral@1
|
74 |
entry_hostname = add_entry_to_table (settings_table,
|
leo_sobral@1
|
75 |
gmyth_settings_get_backend_hostname (msettings),
|
leo_sobral@1
|
76 |
1, 2, 0, 1);
|
leo_sobral@1
|
77 |
entry_dbname = add_entry_to_table (settings_table,
|
leo_sobral@1
|
78 |
gmyth_settings_get_dbname (msettings),
|
leo_sobral@1
|
79 |
1, 2, 1, 2 );
|
leo_sobral@1
|
80 |
entry_username = add_entry_to_table (settings_table,
|
leo_sobral@1
|
81 |
gmyth_settings_get_username (msettings),
|
leo_sobral@1
|
82 |
1, 2, 2, 3 );
|
leo_sobral@1
|
83 |
entry_passwd = add_entry_to_table (settings_table,
|
leo_sobral@1
|
84 |
gmyth_settings_get_password (msettings),
|
leo_sobral@1
|
85 |
1, 2, 3, 4 );
|
leo_sobral@1
|
86 |
|
leo_sobral@1
|
87 |
GString *str_port = g_string_new ("");
|
leo_sobral@1
|
88 |
g_string_printf (str_port, "%d",
|
leo_sobral@1
|
89 |
gmyth_settings_get_backend_port (msettings));
|
leo_sobral@1
|
90 |
entry_port = add_entry_to_table (settings_table, str_port,
|
leo_sobral@1
|
91 |
1, 2, 4, 5 );
|
leo_sobral@1
|
92 |
g_string_free (str_port, TRUE);
|
leo_sobral@1
|
93 |
|
leo_sobral@1
|
94 |
if (gtk_dialog_run (GTK_DIALOG (settings_dialog)) == GTK_RESPONSE_ACCEPT) {
|
leo_sobral@1
|
95 |
settings_dialog_update_data ();
|
leo_sobral@1
|
96 |
gtk_widget_destroy (settings_dialog);
|
leo_sobral@1
|
97 |
return TRUE;
|
leo_sobral@1
|
98 |
}
|
leo_sobral@1
|
99 |
|
leo_sobral@1
|
100 |
gtk_widget_destroy (settings_dialog);
|
leo_sobral@1
|
101 |
|
leo_sobral@1
|
102 |
return FALSE;
|
leo_sobral@1
|
103 |
|
leo_sobral@1
|
104 |
}
|
leo_sobral@1
|
105 |
|
leo_sobral@1
|
106 |
static GtkWidget*
|
leo_sobral@1
|
107 |
add_label_to_table (GtkWidget *table, const gchar *str, guint pos_left, guint pos_right,
|
leo_sobral@1
|
108 |
guint pos_top, guint pos_bottom )
|
leo_sobral@1
|
109 |
{
|
leo_sobral@1
|
110 |
GtkWidget *tmp_label = gtk_label_new (str);
|
leo_sobral@1
|
111 |
|
leo_sobral@1
|
112 |
gtk_widget_show (tmp_label);
|
leo_sobral@1
|
113 |
gtk_table_attach (GTK_TABLE (table), tmp_label,
|
leo_sobral@1
|
114 |
pos_left, pos_right, pos_top, pos_bottom,
|
leo_sobral@1
|
115 |
(GtkAttachOptions) (GTK_FILL),
|
leo_sobral@1
|
116 |
(GtkAttachOptions) (0), 0, 0);
|
leo_sobral@1
|
117 |
gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);
|
leo_sobral@1
|
118 |
|
leo_sobral@1
|
119 |
return tmp_label;
|
leo_sobral@1
|
120 |
}
|
leo_sobral@1
|
121 |
|
leo_sobral@1
|
122 |
static GtkWidget*
|
leo_sobral@1
|
123 |
add_entry_to_table (GtkWidget *table, GString *init_str, guint pos_left, guint pos_right,
|
leo_sobral@1
|
124 |
guint pos_top, guint pos_bottom)
|
leo_sobral@1
|
125 |
{
|
leo_sobral@1
|
126 |
GtkWidget *tmp_entry = gtk_entry_new ();
|
leo_sobral@1
|
127 |
gtk_widget_show (tmp_entry);
|
leo_sobral@1
|
128 |
gtk_table_attach (GTK_TABLE (table), tmp_entry,
|
leo_sobral@1
|
129 |
pos_left, pos_right, pos_top, pos_bottom,
|
leo_sobral@1
|
130 |
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
leo_sobral@1
|
131 |
(GtkAttachOptions) (0), 0, 0);
|
leo_sobral@1
|
132 |
if (init_str)
|
leo_sobral@1
|
133 |
gtk_entry_set_text (GTK_ENTRY (tmp_entry), (init_str->str));
|
leo_sobral@1
|
134 |
|
leo_sobral@1
|
135 |
//gtk_entry_set_invisible_char (GTK_ENTRY (entry_port), 9679);
|
leo_sobral@1
|
136 |
|
leo_sobral@1
|
137 |
return tmp_entry;
|
leo_sobral@1
|
138 |
}
|
leo_sobral@1
|
139 |
|
leo_sobral@1
|
140 |
static void
|
leo_sobral@1
|
141 |
settings_dialog_update_data (void)
|
leo_sobral@1
|
142 |
{
|
leo_sobral@1
|
143 |
GString *tmp_entry_text;
|
leo_sobral@1
|
144 |
GMythSettings *msettings = gmyth_context_get_settings();
|
leo_sobral@1
|
145 |
|
leo_sobral@1
|
146 |
if (!msettings) {
|
leo_sobral@1
|
147 |
g_warning ("[%s] Could not get GMythSettings instance from context\n", __FUNCTION__);
|
leo_sobral@1
|
148 |
return;
|
leo_sobral@1
|
149 |
}
|
leo_sobral@1
|
150 |
|
leo_sobral@1
|
151 |
tmp_entry_text = g_string_new("");
|
leo_sobral@1
|
152 |
g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_hostname)));
|
leo_sobral@1
|
153 |
gmyth_settings_set_backend_hostname(msettings, tmp_entry_text);
|
leo_sobral@1
|
154 |
|
leo_sobral@1
|
155 |
g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_dbname)));
|
leo_sobral@1
|
156 |
gmyth_settings_set_dbname(msettings, tmp_entry_text);
|
leo_sobral@1
|
157 |
|
leo_sobral@1
|
158 |
g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_username)));
|
leo_sobral@1
|
159 |
gmyth_settings_set_username(msettings, tmp_entry_text);
|
leo_sobral@1
|
160 |
|
leo_sobral@1
|
161 |
g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_passwd)));
|
leo_sobral@1
|
162 |
gmyth_settings_set_password(msettings, tmp_entry_text);
|
leo_sobral@1
|
163 |
|
leo_sobral@1
|
164 |
g_string_printf(tmp_entry_text, "%s", gtk_entry_get_text( GTK_ENTRY(entry_port)));
|
leo_sobral@1
|
165 |
gmyth_settings_set_backend_port(msettings, atoi(tmp_entry_text->str));
|
leo_sobral@1
|
166 |
|
leo_sobral@1
|
167 |
gmyth_settings_save (msettings);
|
leo_sobral@1
|
168 |
|
leo_sobral@1
|
169 |
}
|