~ubuntu-branches/ubuntu/utopic/network-manager-openvpn/utopic

« back to all changes in this revision

Viewing changes to auth-dialog/gnome-two-password-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-25 10:43:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225104309-v4b2scsl68protyn
Tags: 0.7.0.97-1
* New upstream release.
* debian/patches/01_dbus_policy.patch
  - Removed, merged upstream.
* debian/control
  - Drop libgnomeui-dev from Build-Depends, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
15
   Library General Public License for more details.
16
16
 
17
 
   You should have received a copy of the GNU Library General Public
18
 
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
19
 
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
   Boston, MA 02111-1307, USA.
 
17
   You should have received a copy of the GNU General Public License along
 
18
   with this program; if not, write to the Free Software Foundation, Inc.,
 
19
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
20
 
22
21
   Authors: Ramiro Estrugo <ramiro@eazel.com>
23
22
*/
24
23
 
25
24
#include <config.h>
26
 
//#include "gnome-i18nP.h"
27
25
#include "gnome-two-password-dialog.h"
28
 
#include <gtk/gtkbox.h>
29
 
#include <gtk/gtkcheckbutton.h>
30
 
#include <gtk/gtkentry.h>
31
 
#include <gtk/gtkhbox.h>
32
 
#include <gtk/gtkimage.h>
33
 
#include <gtk/gtklabel.h>
34
 
#include <gtk/gtkmain.h>
35
 
#include <gtk/gtksignal.h>
36
 
#include <gtk/gtkstock.h>
37
 
#include <gtk/gtktable.h>
38
 
#include <gtk/gtkvbox.h>
39
 
#include <gtk/gtkradiobutton.h>
40
 
#include <gtk/gtkstock.h>
41
26
 
42
27
#include <glib/gi18n.h>
43
28
#include <gtk/gtk.h>
63
48
        GtkWidget *password_entry;
64
49
        GtkWidget *password_entry_secondary;
65
50
        GtkWidget *domain_entry;
66
 
        
 
51
 
 
52
        GtkWidget *table_alignment;
67
53
        GtkWidget *table;
68
54
        
69
55
        GtkWidget *remember_session_button;
83
69
static const guint CAPTION_TABLE_USERNAME_ROW = 0;
84
70
static const guint CAPTION_TABLE_PASSWORD_ROW = 1;
85
71
 
86
 
/* Layout constants */
87
 
static const guint DIALOG_BORDER_WIDTH = 6;
88
 
static const guint CAPTION_TABLE_BORDER_WIDTH = 4;
89
 
 
90
72
/* GnomeTwoPasswordDialogClass methods */
91
73
static void gnome_two_password_dialog_class_init (GnomeTwoPasswordDialogClass *password_dialog_class);
92
74
static void gnome_two_password_dialog_init       (GnomeTwoPasswordDialog      *password_dialog);
103
85
 
104
86
static gpointer parent_class;
105
87
 
106
 
GtkType
 
88
GType
107
89
gnome_two_password_dialog_get_type (void)
108
90
{
109
91
        static GType type = 0;
218
200
}
219
201
 
220
202
static void
221
 
add_row (GtkWidget *table, int row, const char *label_text, GtkWidget *entry, int offset)
 
203
add_row (GtkWidget *table, int row, const char *label_text, GtkWidget *entry)
222
204
{
223
205
        GtkWidget *label;
224
206
 
225
207
        label = gtk_label_new_with_mnemonic (label_text);
226
 
        gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
 
208
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
227
209
 
228
 
        gtk_table_attach (GTK_TABLE (table), label,
229
 
                          0, 1,
230
 
                          row, row + 1,
231
 
                          GTK_FILL,
232
 
                          (GTK_FILL|GTK_EXPAND),
233
 
                          offset, 0);
234
 
        
235
 
        gtk_table_attach (GTK_TABLE (table), entry,
236
 
                          1, 2,
237
 
                          row, row + 1,
238
 
                          (GTK_FILL|GTK_EXPAND),
239
 
                          (GTK_FILL|GTK_EXPAND),
240
 
                          0, 0);
 
210
        gtk_table_attach_defaults (GTK_TABLE (table), label,
 
211
                                   0, 1, row, row + 1);
 
212
        gtk_table_attach_defaults (GTK_TABLE (table), entry,
 
213
                                   1, 2, row, row + 1);
241
214
 
242
215
        gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
243
216
}
256
229
        int offset;
257
230
 
258
231
        if (password_dialog->details->anon_support_on) {
259
 
                offset = 20;
 
232
                offset = 12;
260
233
        }
261
234
        else {
262
235
                offset = 0;
263
236
        }
264
237
 
 
238
        gtk_alignment_set_padding (GTK_ALIGNMENT (password_dialog->details->table_alignment),
 
239
                                   0, 0, offset, 0);
 
240
 
265
241
        table = password_dialog->details->table;
266
242
        /* This will not kill the entries, since they are ref:ed */
267
243
        gtk_container_foreach (GTK_CONTAINER (table),
269
245
        
270
246
        row = 0;
271
247
        if (password_dialog->details->show_username)
272
 
                add_row (table, row++, _("_Username:"), password_dialog->details->username_entry, offset);
 
248
                add_row (table, row++, _("_Username:"), password_dialog->details->username_entry);
273
249
        if (password_dialog->details->show_domain)
274
 
                add_row (table, row++, _("_Domain:"), password_dialog->details->domain_entry, offset);
 
250
                add_row (table, row++, _("_Domain:"), password_dialog->details->domain_entry);
275
251
        if (password_dialog->details->show_password)
276
252
                add_row (table, row++, password_dialog->details->primary_password_label,
277
 
                         password_dialog->details->password_entry, offset);
 
253
                         password_dialog->details->password_entry);
278
254
        if (password_dialog->details->show_password_secondary)
279
255
                add_row (table, row++, password_dialog->details->secondary_password_label, 
280
 
                         password_dialog->details->password_entry_secondary, offset);
 
256
                         password_dialog->details->password_entry_secondary);
281
257
 
282
258
        gtk_widget_show_all (table);
283
259
}
325
301
                           gboolean      readonly_username)
326
302
{
327
303
        GnomeTwoPasswordDialog *password_dialog;
 
304
        GtkDialog *dialog;
328
305
        GtkWidget *table;
329
306
        GtkLabel *message_label;
330
307
        GtkWidget *hbox;
331
308
        GtkWidget *vbox;
 
309
        GtkWidget *main_vbox;
332
310
        GtkWidget *dialog_icon;
333
311
        GSList *group;
334
312
 
335
313
        password_dialog = GNOME_TWO_PASSWORD_DIALOG (gtk_widget_new (gnome_two_password_dialog_get_type (), NULL));
 
314
        dialog = GTK_DIALOG (password_dialog);
336
315
 
337
316
        gtk_window_set_title (GTK_WINDOW (password_dialog), dialog_title);
338
 
        gtk_dialog_add_buttons (GTK_DIALOG (password_dialog),
 
317
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 
318
 
 
319
        gtk_dialog_add_buttons (dialog,
339
320
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
340
321
                                GTK_STOCK_OK, GTK_RESPONSE_OK,
341
322
                                NULL);
 
323
        gtk_dialog_set_default_response (GTK_DIALOG (password_dialog), GTK_RESPONSE_OK);
342
324
 
343
325
        /* Setup the dialog */
344
 
        gtk_dialog_set_has_separator (GTK_DIALOG (password_dialog), FALSE);
 
326
        gtk_dialog_set_has_separator (dialog, FALSE);
 
327
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
 
328
        gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
 
329
        gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
 
330
        gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
345
331
 
346
332
        gtk_window_set_position (GTK_WINDOW (password_dialog), GTK_WIN_POS_CENTER);
347
333
        gtk_window_set_modal (GTK_WINDOW (password_dialog), TRUE);
348
334
 
349
 
        gtk_container_set_border_width (GTK_CONTAINER (password_dialog), DIALOG_BORDER_WIDTH);
350
 
 
351
 
        gtk_dialog_set_default_response (GTK_DIALOG (password_dialog), GTK_RESPONSE_OK);
352
 
 
353
335
        g_signal_connect (password_dialog, "show",
354
336
                          G_CALLBACK (dialog_show_callback), password_dialog);
355
337
        g_signal_connect (password_dialog, "close",
370
352
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_dialog->details->connect_with_no_userpass_button), TRUE);
371
353
        }
372
354
        
373
 
        
374
 
        password_dialog->details->radio_vbox = gtk_vbox_new (FALSE, 0);
 
355
        password_dialog->details->radio_vbox = gtk_vbox_new (FALSE, 6);
375
356
        gtk_box_pack_start (GTK_BOX (password_dialog->details->radio_vbox),
376
357
                password_dialog->details->connect_with_no_userpass_button,
377
358
                FALSE, FALSE, 0);       
384
365
                          G_CALLBACK (userpass_radio_button_clicked), password_dialog); 
385
366
 
386
367
        /* The table that holds the captions */
 
368
        password_dialog->details->table_alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
 
369
 
387
370
        password_dialog->details->table = table = gtk_table_new (3, 2, FALSE);
388
371
        gtk_table_set_col_spacings (GTK_TABLE (table), 12);
389
372
        gtk_table_set_row_spacings (GTK_TABLE (table), 6);
 
373
        gtk_container_add (GTK_CONTAINER (password_dialog->details->table_alignment), table);
390
374
 
391
375
        password_dialog->details->username_entry = gtk_entry_new ();
392
376
        password_dialog->details->domain_entry = gtk_entry_new ();
394
378
        password_dialog->details->password_entry_secondary = gtk_entry_new ();
395
379
 
396
380
        /* We want to hold on to these during the table rearrangement */
 
381
#if GLIB_CHECK_VERSION (2, 10, 0)
 
382
        g_object_ref_sink (password_dialog->details->username_entry);
 
383
        g_object_ref_sink (password_dialog->details->domain_entry);
 
384
        g_object_ref_sink (password_dialog->details->password_entry);
 
385
        g_object_ref_sink (password_dialog->details->password_entry_secondary);
 
386
#else
397
387
        g_object_ref (password_dialog->details->username_entry);
398
388
        gtk_object_sink (GTK_OBJECT (password_dialog->details->username_entry));
399
389
        g_object_ref (password_dialog->details->domain_entry);
402
392
        gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry));
403
393
        g_object_ref (password_dialog->details->password_entry_secondary);
404
394
        gtk_object_sink (GTK_OBJECT (password_dialog->details->password_entry_secondary));
 
395
#endif
405
396
        
406
397
        gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry), FALSE);
407
398
        gtk_entry_set_visibility (GTK_ENTRY (password_dialog->details->password_entry_secondary), FALSE);
426
417
 
427
418
        /* Adds some eye-candy to the dialog */
428
419
        hbox = gtk_hbox_new (FALSE, 12);
 
420
        gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
429
421
        dialog_icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
430
422
        gtk_misc_set_alignment (GTK_MISC (dialog_icon), 0.5, 0.0);
431
423
        gtk_box_pack_start (GTK_BOX (hbox), dialog_icon, FALSE, FALSE, 0);
432
424
 
433
 
        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (password_dialog)->vbox), 12);
434
 
        gtk_container_set_border_width (GTK_CONTAINER(hbox), 6);
435
 
        gtk_box_set_spacing (GTK_BOX (hbox), 12);
436
 
 
437
425
        /* Fills the vbox */
438
 
        vbox = gtk_vbox_new (FALSE, 0);
 
426
        main_vbox = gtk_vbox_new (FALSE, 18);
439
427
 
440
428
        if (message) {
441
429
                message_label = GTK_LABEL (gtk_label_new (message));
442
430
                gtk_label_set_justify (message_label, GTK_JUSTIFY_LEFT);
443
431
                gtk_label_set_line_wrap (message_label, TRUE);
444
432
 
445
 
                gtk_box_pack_start (GTK_BOX (vbox),
446
 
                                    GTK_WIDGET (message_label),
447
 
                                    TRUE,       /* expand */
448
 
                                    TRUE,       /* fill */
449
 
                                    5);         /* padding */
 
433
                gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (message_label),
 
434
                                    FALSE, FALSE, 0);
450
435
        }
 
436
 
 
437
        vbox = gtk_vbox_new (FALSE, 6);
 
438
        gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
 
439
 
451
440
        gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->radio_vbox,
452
 
                            TRUE, TRUE, 5);
453
 
        gtk_box_pack_start (GTK_BOX (vbox), table, 
454
 
                            TRUE, TRUE, 5);
455
 
 
456
 
        /* Configure the table */
457
 
        gtk_container_set_border_width (GTK_CONTAINER (table),
458
 
                                        CAPTION_TABLE_BORDER_WIDTH);
459
 
 
460
 
        gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 5);
 
441
                            FALSE, FALSE, 0);
 
442
        gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->table_alignment,
 
443
                            FALSE, FALSE, 0);
 
444
 
 
445
        gtk_box_pack_start (GTK_BOX (hbox), main_vbox, FALSE, FALSE, 0);
461
446
 
462
447
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialog)->vbox),
463
448
                            hbox,
473
458
                gtk_check_button_new_with_mnemonic (_("_Save password in keyring"));
474
459
 
475
460
        gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_session_button, 
476
 
                            TRUE, TRUE, 6);
 
461
                            FALSE, FALSE, 0);
477
462
        gtk_box_pack_start (GTK_BOX (vbox), password_dialog->details->remember_forever_button, 
478
 
                            TRUE, TRUE, 0);
 
463
                            FALSE, FALSE, 0);
479
464
        
480
465
        
481
466
        gnome_two_password_dialog_set_username (password_dialog, username);