1 /* Widgets/Login
2 *
3 * The GdauiLogin widget displays information required to open a connection
4 */
5
6 #include <libgda-ui/libgda-ui.h>
7
8 static GtkWidget *window = NULL;
9
10 static void
cb1_toggled_cb(G_GNUC_UNUSED GtkCheckButton * cb,GtkWidget * login)11 cb1_toggled_cb (G_GNUC_UNUSED GtkCheckButton *cb, GtkWidget *login)
12 {
13 GdauiLoginMode mode;
14 g_object_get (G_OBJECT (login), "mode", &mode, NULL);
15 mode ^= GDA_UI_LOGIN_ENABLE_CONTROL_CENTRE_MODE;
16 gdaui_login_set_mode (GDAUI_LOGIN (login), mode);
17 }
18
19 static void
cb2_toggled_cb(G_GNUC_UNUSED GtkCheckButton * cb,GtkWidget * login)20 cb2_toggled_cb (G_GNUC_UNUSED GtkCheckButton *cb, GtkWidget *login)
21 {
22 GdauiLoginMode mode;
23 g_object_get (G_OBJECT (login), "mode", &mode, NULL);
24 mode ^= GDA_UI_LOGIN_HIDE_DSN_SELECTION_MODE;
25 gdaui_login_set_mode (GDAUI_LOGIN (login), mode);
26 }
27
28 static void
cb3_toggled_cb(G_GNUC_UNUSED GtkCheckButton * cb,GtkWidget * login)29 cb3_toggled_cb (G_GNUC_UNUSED GtkCheckButton *cb, GtkWidget *login)
30 {
31 GdauiLoginMode mode;
32 g_object_get (G_OBJECT (login), "mode", &mode, NULL);
33 mode ^= GDA_UI_LOGIN_HIDE_DIRECT_CONNECTION_MODE;
34 gdaui_login_set_mode (GDAUI_LOGIN (login), mode);
35 }
36
37 static void
button_clicked_cb(G_GNUC_UNUSED GtkButton * button,GtkWidget * login)38 button_clicked_cb (G_GNUC_UNUSED GtkButton *button, GtkWidget *login)
39 {
40 const GdaDsnInfo *info;
41 info = gdaui_login_get_connection_information (GDAUI_LOGIN (login));
42
43 g_print ("\nCurrent connection's parameters:\n");
44 g_print ("DSN name: %s\n", info->name);
45 g_print ("provider: %s\n", info->provider);
46 g_print ("description: %s\n", info->description);
47 g_print ("cnc_string: %s\n", info->cnc_string);
48 g_print ("auth_string: %s\n", info->auth_string);
49 }
50
51 static void
login_changed_cb(G_GNUC_UNUSED GdauiLogin * login,gboolean is_valid,GtkLabel * label)52 login_changed_cb (G_GNUC_UNUSED GdauiLogin *login, gboolean is_valid, GtkLabel *label)
53 {
54 if (is_valid)
55 gtk_label_set_markup (label, "<span foreground='#00AA00'>Valid information</span>");
56 else
57 gtk_label_set_markup (label, "<span foreground='red'>Invalid information</span>");
58 }
59
60 GtkWidget *
do_login(GtkWidget * do_widget)61 do_login (GtkWidget *do_widget)
62 {
63 if (!window) {
64 GtkWidget *grid, *cb, *button;
65 GtkWidget *login, *frame;
66
67 window = gtk_dialog_new_with_buttons ("GdauiLogin widget",
68 GTK_WINDOW (do_widget),
69 0,
70 GTK_STOCK_CLOSE,
71 GTK_RESPONSE_NONE,
72 NULL);
73 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
74 g_signal_connect (window, "response",
75 G_CALLBACK (gtk_widget_destroy), NULL);
76 g_signal_connect (window, "destroy",
77 G_CALLBACK (gtk_widget_destroyed), &window);
78
79
80 grid = gtk_grid_new ();
81 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
82 grid, TRUE, TRUE, 0);
83 gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
84
85 /* Create the login widget */
86 frame = gtk_frame_new ("Login widget:");
87 gtk_grid_attach (GTK_GRID (grid), frame, 0, 3, 2, 1);
88
89 login = gdaui_login_new (NULL);
90 gtk_container_add (GTK_CONTAINER (frame), login);
91
92 /* Create the options */
93 cb = gtk_check_button_new_with_label ("Enable control center");
94 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), TRUE);
95 gtk_grid_attach (GTK_GRID (grid), cb, 0, 0, 1, 1);
96 g_signal_connect (cb, "toggled",
97 G_CALLBACK (cb1_toggled_cb), login);
98
99 cb = gtk_check_button_new_with_label ("Hide DSN selection");
100 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), FALSE);
101 gtk_grid_attach (GTK_GRID (grid), cb, 0, 1, 1, 1);
102 g_signal_connect (cb, "toggled",
103 G_CALLBACK (cb2_toggled_cb), login);
104
105 cb = gtk_check_button_new_with_label ("Hide direct connection");
106 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), FALSE);
107 gtk_grid_attach (GTK_GRID (grid), cb, 0, 2, 1, 1);
108 g_signal_connect (cb, "toggled",
109 G_CALLBACK (cb3_toggled_cb), login);
110
111 button = gtk_button_new_with_label ("Show connection's parameters");
112 gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);
113 g_signal_connect (button, "clicked",
114 G_CALLBACK (button_clicked_cb), login);
115
116 GtkWidget *status;
117 gboolean valid;
118 status = gtk_label_new ("...");
119 gtk_grid_attach (GTK_GRID (grid), status, 1, 2, 1, 1);
120 g_object_get (G_OBJECT (login), "valid", &valid, NULL);
121 login_changed_cb (GDAUI_LOGIN (login), valid, GTK_LABEL (status));
122 g_signal_connect (login, "changed",
123 G_CALLBACK (login_changed_cb), status);
124 }
125
126 gboolean visible;
127 g_object_get (G_OBJECT (window), "visible", &visible, NULL);
128 if (!visible)
129 gtk_widget_show_all (window);
130 else {
131 gtk_widget_destroy (window);
132 window = NULL;
133 }
134
135 return window;
136 }
137
138
139