~carifio/seahorse/seahorse-remove-broken-help-buttons

« back to all changes in this revision

Viewing changes to src/seahorse-gkeyring-item-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-07-22 09:20:59 UTC
  • mto: (3.2.1 sid) (1.4.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20080722092059-q336t49r9uaveij3
Tags: upstream-2.23.5
ImportĀ upstreamĀ versionĀ 2.23.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Seahorse
3
 
 *
4
 
 * Copyright (C) 2006 Stefan Walter
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
 * See the GNU General Public License for more details.
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the
17
 
 * Free Software Foundation, Inc.,
18
 
 * 59 Temple Place, Suite 330,
19
 
 * Boston, MA 02111-1307, USA.
20
 
 */
21
 
#include <config.h>
22
 
#include <gnome.h>
23
 
 
24
 
#include "seahorse-key-widget.h"
25
 
#include "seahorse-util.h"
26
 
#include "seahorse-key.h"
27
 
#include "seahorse-gkeyring-item.h"
28
 
#include "seahorse-gkeyring-source.h"
29
 
#include "seahorse-gkeyring-operation.h"
30
 
#include "seahorse-gtkstock.h"
31
 
#include "seahorse-secure-memory.h"
32
 
#include "seahorse-secure-entry.h"
33
 
 
34
 
/* -----------------------------------------------------------------------------
35
 
 * MAIN TAB 
36
 
 */
37
 
 
38
 
static void
39
 
load_password (SeahorseWidget *swidget, SeahorseGKeyringItem *git)
40
 
{
41
 
    SeahorseSecureEntry *entry;
42
 
    gchar *secret;
43
 
    
44
 
    entry = SEAHORSE_SECURE_ENTRY (g_object_get_data (G_OBJECT (swidget), 
45
 
                                             "secure-password-entry"));
46
 
    if (entry) {
47
 
        
48
 
        /* Retrieve initial password. Try to keep it safe */
49
 
        WITH_SECURE_MEM ((secret = gnome_keyring_item_info_get_secret (git->info)));
50
 
        seahorse_secure_entry_set_text (entry, secret ? secret : "");
51
 
        g_free (secret);
52
 
    
53
 
        seahorse_secure_entry_reset_changed (entry);
54
 
    }
55
 
}
56
 
 
57
 
static void
58
 
do_main (SeahorseWidget *swidget)
59
 
{
60
 
    SeahorseKey *key;
61
 
    SeahorseGKeyringItem *git;
62
 
    GtkWidget *widget;
63
 
    gchar *text;
64
 
    const gchar *label;
65
 
    gboolean network = FALSE;
66
 
 
67
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
68
 
    git = SEAHORSE_GKEYRING_ITEM (key);
69
 
 
70
 
    /* Image */
71
 
    widget = seahorse_widget_get_widget (swidget, "key-image");
72
 
    if (widget)
73
 
        gtk_image_set_from_stock (GTK_IMAGE (widget), seahorse_key_get_stock_id (key), 
74
 
                                  GTK_ICON_SIZE_DIALOG);
75
 
 
76
 
    /* Description */
77
 
    widget = seahorse_widget_get_widget (swidget, "description-field");
78
 
    if (widget) {
79
 
        text = seahorse_gkeyring_item_get_description (git);
80
 
        gtk_entry_set_text (GTK_ENTRY (widget), text ? text : "");
81
 
        g_free (text);
82
 
    }
83
 
    
84
 
    /* Window title */
85
 
    text = seahorse_key_get_display_name (key);
86
 
    widget = seahorse_widget_get_top (swidget);
87
 
    gtk_window_set_title (GTK_WINDOW (widget), text);
88
 
    g_free (text);
89
 
 
90
 
    /* Use and type */
91
 
    switch (seahorse_gkeyring_item_get_use (git)) {
92
 
    case SEAHORSE_GKEYRING_USE_NETWORK:
93
 
        label = _("Access a network share or resource");
94
 
        network = TRUE;
95
 
        break;
96
 
    case SEAHORSE_GKEYRING_USE_WEB:
97
 
        label = _("Access a website");
98
 
        network = TRUE;
99
 
        break;
100
 
    case SEAHORSE_GKEYRING_USE_PGP:
101
 
        label = _("Unlocks a PGP key");
102
 
        break;
103
 
    case SEAHORSE_GKEYRING_USE_SSH:
104
 
        label = _("Unlocks a Secure Shell key");
105
 
        break;
106
 
    case SEAHORSE_GKEYRING_USE_OTHER:
107
 
        label = _("Saved password or login");
108
 
        break;
109
 
    }
110
 
    
111
 
    widget = seahorse_widget_get_widget (swidget, "use-field");
112
 
    if (widget)
113
 
        gtk_label_set_text (GTK_LABEL (widget), label);
114
 
    
115
 
    /* The type */
116
 
    widget = seahorse_widget_get_widget (swidget, "type-field");
117
 
    if (widget)
118
 
        gtk_label_set_text (GTK_LABEL (widget), 
119
 
                network ? _("Network Credentials") : _("Password"));
120
 
    
121
 
    /* Network */
122
 
    seahorse_widget_set_visible (swidget, "server-label", network);
123
 
    seahorse_widget_set_visible (swidget, "server-field", network);
124
 
    seahorse_widget_set_visible (swidget, "login-label", network);
125
 
    seahorse_widget_set_visible (swidget, "login-field", network);
126
 
    
127
 
    if (network) {
128
 
        label = seahorse_gkeyring_item_get_attribute (git, "server");
129
 
        widget = seahorse_widget_get_widget (swidget, "server-field");
130
 
        if (widget)
131
 
            gtk_label_set_text (GTK_LABEL (widget), label);
132
 
        
133
 
        label = seahorse_gkeyring_item_get_attribute (git, "user");
134
 
        widget = seahorse_widget_get_widget (swidget, "login-field");
135
 
        if (widget)
136
 
            gtk_label_set_text (GTK_LABEL (widget), label);
137
 
    } 
138
 
    
139
 
    load_password (swidget, git);
140
 
}
141
 
 
142
 
static void
143
 
password_activate (SeahorseSecureEntry *entry, SeahorseWidget *swidget)
144
 
{
145
 
    SeahorseKey *key;
146
 
    SeahorseGKeyringItem *git;
147
 
    SeahorseOperation *op;
148
 
    GnomeKeyringItemInfo *info;
149
 
    GtkWidget *widget;
150
 
    GError *err = NULL;
151
 
    
152
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
153
 
    git = SEAHORSE_GKEYRING_ITEM (key);
154
 
 
155
 
    widget = seahorse_widget_get_widget (swidget, "password-expander");
156
 
    g_return_if_fail (widget);
157
 
    if (!gtk_expander_get_expanded (GTK_EXPANDER (widget)))
158
 
        return;
159
 
 
160
 
    entry = SEAHORSE_SECURE_ENTRY (g_object_get_data (G_OBJECT (swidget), 
161
 
                                                "secure-password-entry"));
162
 
    if (!entry || !seahorse_secure_entry_get_changed (entry))
163
 
        return;
164
 
        
165
 
    /* Setup for saving */
166
 
    WITH_SECURE_MEM (info = gnome_keyring_item_info_copy (git->info));
167
 
    WITH_SECURE_MEM (gnome_keyring_item_info_set_secret (info, 
168
 
                            seahorse_secure_entry_get_text (entry)));
169
 
 
170
 
    gtk_widget_set_sensitive (GTK_WIDGET (entry), FALSE);
171
 
    
172
 
    op = seahorse_gkeyring_operation_update_info (git, info);
173
 
    gnome_keyring_item_info_free (info);
174
 
    
175
 
    /* This is usually a quick operation */
176
 
    seahorse_operation_wait (op);
177
 
    
178
 
    if (!seahorse_operation_is_successful (op)) {
179
 
        seahorse_operation_copy_error (op, &err);
180
 
        seahorse_util_handle_error (err, _("Couldn't change password."));
181
 
        load_password (swidget, git);
182
 
    }
183
 
    
184
 
    gtk_widget_set_sensitive (GTK_WIDGET (entry), TRUE);
185
 
}
186
 
 
187
 
static gboolean
188
 
password_focus_out (SeahorseSecureEntry* entry, GdkEventFocus *event, SeahorseWidget *swidget)
189
 
{
190
 
    password_activate (entry, swidget);
191
 
    return FALSE;
192
 
}
193
 
 
194
 
static void 
195
 
show_password_toggled (GtkToggleButton *button, SeahorseWidget *swidget)
196
 
{
197
 
    GtkWidget *widget;
198
 
    
199
 
    widget = GTK_WIDGET (g_object_get_data (G_OBJECT (swidget), "secure-password-entry"));
200
 
    if (!widget)
201
 
        return;
202
 
    
203
 
    seahorse_secure_entry_set_visibility (SEAHORSE_SECURE_ENTRY (widget), 
204
 
                                          gtk_toggle_button_get_active (button));
205
 
}
206
 
 
207
 
static void
208
 
password_expander_activate (GtkExpander *expander, SeahorseWidget *swidget)
209
 
{
210
 
    SeahorseKey *key;
211
 
    SeahorseGKeyringItem *git;
212
 
    GtkWidget *widget;
213
 
    GtkWidget *box;
214
 
 
215
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
216
 
    git = SEAHORSE_GKEYRING_ITEM (key);
217
 
 
218
 
    if (!gtk_expander_get_expanded (expander))
219
 
        return;
220
 
 
221
 
    /* 
222
 
     * TODO: Once gnome-keyring-daemon has support for not reading 
223
 
     * the secret, then we'd retrieve the secret when the password 
224
 
     * expander is opened 
225
 
     */
226
 
    
227
 
    widget = GTK_WIDGET (g_object_get_data (G_OBJECT (swidget), "secure-password-entry"));
228
 
    if (!widget) {
229
 
        widget = seahorse_secure_entry_new ();
230
 
        
231
 
        box = seahorse_widget_get_widget (swidget, "password-box-area");
232
 
        g_return_if_fail (box != NULL);
233
 
        gtk_container_add (GTK_CONTAINER (box), widget);
234
 
        g_object_set_data (G_OBJECT (swidget), "secure-password-entry", widget);
235
 
        gtk_widget_show (widget);
236
 
        
237
 
        /* Retrieve initial password */
238
 
        load_password (swidget, git);
239
 
        
240
 
        /* Now watch for changes in the password */
241
 
        g_signal_connect (widget, "activate", G_CALLBACK (password_activate), swidget);
242
 
        g_signal_connect (widget, "focus-out-event", G_CALLBACK (password_focus_out), swidget);
243
 
    }
244
 
    
245
 
    /* Always have a hidden password when opening box */
246
 
    widget = seahorse_widget_get_widget (swidget, "show-password-check");
247
 
    g_return_if_fail (widget != NULL);
248
 
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
249
 
}
250
 
 
251
 
static void
252
 
description_activate (GtkWidget *entry, SeahorseWidget *swidget)
253
 
{
254
 
    SeahorseKey *key;
255
 
    SeahorseGKeyringItem *git;
256
 
    SeahorseOperation *op;
257
 
    GnomeKeyringItemInfo *info;
258
 
    const gchar *text;
259
 
    gchar *original;
260
 
    GError *err = NULL;
261
 
    
262
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
263
 
    git = SEAHORSE_GKEYRING_ITEM (key);
264
 
 
265
 
    text = gtk_entry_get_text (GTK_ENTRY (entry));
266
 
    original = seahorse_gkeyring_item_get_description (git);
267
 
    
268
 
    /* Make sure not the same */
269
 
    if (text == original || g_utf8_collate (text, original ? original : "") == 0) {
270
 
        g_free (original);
271
 
        return;
272
 
    }
273
 
 
274
 
    gtk_widget_set_sensitive (entry, FALSE);
275
 
    
276
 
    WITH_SECURE_MEM (info = gnome_keyring_item_info_copy (git->info));
277
 
    gnome_keyring_item_info_set_display_name (info, text);
278
 
    
279
 
    op = seahorse_gkeyring_operation_update_info (git, info);
280
 
    gnome_keyring_item_info_free (info);
281
 
    
282
 
    /* This is usually a quick operation */
283
 
    seahorse_operation_wait (op);
284
 
    
285
 
    if (!seahorse_operation_is_successful (op)) {
286
 
        seahorse_operation_copy_error (op, &err);
287
 
        seahorse_util_handle_error (err, _("Couldn't set description."));
288
 
        gtk_entry_set_text (GTK_ENTRY (entry), original);
289
 
    }
290
 
    
291
 
    gtk_widget_set_sensitive (entry, TRUE);
292
 
    
293
 
    g_free (original);
294
 
}
295
 
 
296
 
static gboolean
297
 
description_focus_out (GtkWidget* widget, GdkEventFocus *event, SeahorseWidget *swidget)
298
 
{
299
 
    description_activate (widget, swidget);
300
 
    return FALSE;
301
 
}
302
 
 
303
 
/* -----------------------------------------------------------------------------
304
 
 * DETAILS TAB
305
 
 */
306
 
 
307
 
static void 
308
 
do_details (SeahorseWidget *swidget)
309
 
{
310
 
    SeahorseKey *key;
311
 
    SeahorseGKeyringItem *git;
312
 
    GString *details;
313
 
    GtkWidget *widget;
314
 
    guint i;
315
 
 
316
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
317
 
    git = SEAHORSE_GKEYRING_ITEM (key);
318
 
 
319
 
    details = g_string_new (NULL);
320
 
    
321
 
    g_string_append_printf (details, "<b>identifier</b>: %u\n", git->item_id);
322
 
    
323
 
    /* Build up the display string */
324
 
    if (git->attributes) {
325
 
        for(i = 0; i < git->attributes->len; ++i) {
326
 
            GnomeKeyringAttribute *attr = &(gnome_keyring_attribute_list_index (git->attributes, i));
327
 
            g_string_append_printf (details, "<b>%s</b>: ", attr->name);
328
 
            switch (attr->type) {
329
 
            case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
330
 
                g_string_append_printf (details, "%s\n", attr->value.string);
331
 
                break;
332
 
            case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
333
 
                g_string_append_printf (details, "%u\n", attr->value.integer);
334
 
                break;
335
 
            default:
336
 
                g_string_append (details, "<i>[invalid]</i>\n");
337
 
                break;
338
 
            }
339
 
        }
340
 
    }
341
 
    
342
 
    widget = seahorse_widget_get_widget (swidget, "details-box");
343
 
    g_return_if_fail (widget != NULL);
344
 
    gtk_label_set_markup (GTK_LABEL (widget), details->str);
345
 
    
346
 
    g_string_free (details, TRUE);
347
 
}
348
 
 
349
 
/* -----------------------------------------------------------------------------
350
 
 * APPLICATIONS TAB 
351
 
 */
352
 
 
353
 
static gint
354
 
selected_application_index (SeahorseWidget *swidget)
355
 
{
356
 
    GtkTreeView *tree;
357
 
    GtkTreePath *path;
358
 
    GtkTreeModel *model;
359
 
    GtkTreeSelection *selection;
360
 
    GtkTreeIter iter;
361
 
    gint* indices;
362
 
    gint ret;
363
 
    
364
 
    tree = GTK_TREE_VIEW (seahorse_widget_get_widget (swidget, "application-list"));
365
 
    g_return_val_if_fail (GTK_IS_TREE_VIEW (tree), -1);
366
 
    
367
 
    selection = gtk_tree_view_get_selection (tree);
368
 
    if (!gtk_tree_selection_get_selected (selection, &model, &iter))
369
 
        return -1;
370
 
        
371
 
    path = gtk_tree_model_get_path (model, &iter);
372
 
    g_return_val_if_fail (path, -1);
373
 
    
374
 
    indices = gtk_tree_path_get_indices (path);
375
 
    g_return_val_if_fail (indices, -1);
376
 
    
377
 
    ret = *indices;
378
 
    gtk_tree_path_free (path);
379
 
    
380
 
    return ret;
381
 
}
382
 
 
383
 
static void
384
 
update_application_details (SeahorseWidget *swidget)
385
 
{
386
 
    SeahorseKey *key;
387
 
    SeahorseGKeyringItem *git;
388
 
    GnomeKeyringAccessControl *ac;
389
 
    GtkLabel *label;
390
 
    GtkToggleButton *toggle;
391
 
    GnomeKeyringAccessType access;
392
 
    gint index;
393
 
    gchar *path;
394
 
    
395
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
396
 
    git = SEAHORSE_GKEYRING_ITEM (key);
397
 
 
398
 
    index = selected_application_index (swidget);
399
 
    if (index < 0) {
400
 
        ac = NULL;
401
 
    } else {
402
 
        ac = (GnomeKeyringAccessControl*)g_list_nth_data (git->acl, index);
403
 
        g_return_if_fail (ac);
404
 
    }
405
 
        
406
 
    seahorse_widget_set_sensitive (swidget, "application-details", ac != NULL);
407
 
    
408
 
    label = GTK_LABEL (seahorse_widget_get_widget (swidget, "application-path"));
409
 
    g_return_if_fail (GTK_IS_LABEL (label));
410
 
    path = ac ? gnome_keyring_item_ac_get_path_name (ac) : NULL;
411
 
    gtk_label_set_text (label, path ? path : "");
412
 
    g_free (path);
413
 
 
414
 
    g_object_set_data (G_OBJECT (swidget), "updating", "updating");
415
 
    access = ac ? gnome_keyring_item_ac_get_access_type (ac) : 0;
416
 
    
417
 
    toggle = GTK_TOGGLE_BUTTON (seahorse_widget_get_widget (swidget, "application-read"));
418
 
    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle));
419
 
    gtk_toggle_button_set_active (toggle, access & GNOME_KEYRING_ACCESS_READ);    
420
 
 
421
 
    toggle = GTK_TOGGLE_BUTTON (seahorse_widget_get_widget (swidget, "application-write"));
422
 
    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle));    
423
 
    gtk_toggle_button_set_active (toggle, access & GNOME_KEYRING_ACCESS_WRITE);    
424
 
 
425
 
    toggle = GTK_TOGGLE_BUTTON (seahorse_widget_get_widget (swidget, "application-delete"));
426
 
    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle));
427
 
    gtk_toggle_button_set_active (toggle, access & GNOME_KEYRING_ACCESS_REMOVE);
428
 
    
429
 
    g_object_set_data (G_OBJECT (swidget), "updating", NULL);
430
 
}
431
 
 
432
 
static void
433
 
application_selection_changed (GtkTreeSelection *selection, SeahorseWidget *swidget)
434
 
{
435
 
    update_application_details (swidget);
436
 
}
437
 
 
438
 
static void 
439
 
merge_toggle_button_access (SeahorseWidget *swidget, const gchar *identifier, 
440
 
                            GnomeKeyringAccessType *access, GnomeKeyringAccessType type)
441
 
{
442
 
    GtkToggleButton *toggle;
443
 
    
444
 
    toggle = GTK_TOGGLE_BUTTON (seahorse_widget_get_widget (swidget, identifier));
445
 
    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle));
446
 
    if (gtk_toggle_button_get_active (toggle))
447
 
        *access |= type;
448
 
    else
449
 
        *access &= ~type;
450
 
}
451
 
 
452
 
static void
453
 
application_access_toggled (GtkCheckButton *check, SeahorseWidget *swidget)
454
 
{
455
 
    SeahorseKey *key;
456
 
    SeahorseGKeyringItem *git;
457
 
    SeahorseOperation *op;
458
 
    GnomeKeyringAccessType access;
459
 
    GnomeKeyringAccessControl *ac;
460
 
    GError *err = NULL;
461
 
    GList *acl;
462
 
    guint index;
463
 
    
464
 
    /* Just us setting up the controls, not the user */
465
 
    if (g_object_get_data (G_OBJECT (swidget), "updating"))
466
 
        return;
467
 
    
468
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
469
 
    git = SEAHORSE_GKEYRING_ITEM (key);
470
 
 
471
 
    index = selected_application_index (swidget);
472
 
    g_return_if_fail (index >= 0);
473
 
    
474
 
    acl = gnome_keyring_acl_copy (git->acl);
475
 
    ac = (GnomeKeyringAccessControl*)g_list_nth_data (acl, index);
476
 
    g_return_if_fail (ac);
477
 
    
478
 
    access = gnome_keyring_item_ac_get_access_type (ac);
479
 
    
480
 
    merge_toggle_button_access (swidget, "application-read", &access, GNOME_KEYRING_ACCESS_READ);    
481
 
    merge_toggle_button_access (swidget, "application-write", &access, GNOME_KEYRING_ACCESS_WRITE);    
482
 
    merge_toggle_button_access (swidget, "application-delete", &access, GNOME_KEYRING_ACCESS_REMOVE);    
483
 
 
484
 
    if (access != gnome_keyring_item_ac_get_access_type (ac)) {
485
 
        
486
 
        gnome_keyring_item_ac_set_access_type (ac, access);
487
 
 
488
 
        seahorse_widget_set_sensitive (swidget, "application-details", FALSE);
489
 
        
490
 
        op = seahorse_gkeyring_operation_update_acl (git, acl);
491
 
        g_return_if_fail (op);
492
 
        
493
 
        seahorse_operation_wait (op);
494
 
        if (!seahorse_operation_is_successful (op)) {
495
 
            seahorse_operation_copy_error (op, &err);
496
 
            seahorse_util_handle_error (err, _("Couldn't set application access."));
497
 
            update_application_details (swidget);
498
 
        }
499
 
                
500
 
        seahorse_widget_set_sensitive (swidget, "application-details", TRUE);        
501
 
    }
502
 
    
503
 
    gnome_keyring_acl_free (acl);
504
 
}
505
 
 
506
 
static void 
507
 
do_application (SeahorseWidget *swidget)
508
 
{
509
 
    SeahorseKey *key;
510
 
    SeahorseGKeyringItem *git;
511
 
    GtkTreeView *tree;
512
 
    GtkListStore *store;
513
 
    GtkTreeModel *model;
514
 
    GtkTreeIter iter;
515
 
    GtkCellRenderer *renderer;
516
 
    GnomeKeyringAccessControl *ac;
517
 
    GtkTreeViewColumn *column;
518
 
    GList *acl;
519
 
    gboolean valid;
520
 
    gchar *display;
521
 
 
522
 
    key = SEAHORSE_KEY_WIDGET (swidget)->skey;
523
 
    git = SEAHORSE_GKEYRING_ITEM (key);
524
 
 
525
 
    tree = GTK_TREE_VIEW (seahorse_widget_get_widget (swidget, "application-list"));
526
 
    g_return_if_fail (tree);
527
 
    
528
 
    model = gtk_tree_view_get_model (tree);
529
 
    if (!model) {
530
 
        store = gtk_list_store_new (1, GTK_TYPE_STRING);
531
 
        model = GTK_TREE_MODEL (store);
532
 
        gtk_tree_view_set_model (tree, model);
533
 
        
534
 
        renderer = gtk_cell_renderer_text_new ();
535
 
        column = gtk_tree_view_column_new_with_attributes ("name", renderer, "text", 0, NULL);
536
 
        gtk_tree_view_append_column (tree, column);
537
 
    } else {
538
 
        store = GTK_LIST_STORE (model);
539
 
    }
540
 
    
541
 
    acl = git->acl;
542
 
    
543
 
    /* Fill in the tree store, replacing any rows already present */
544
 
    valid = gtk_tree_model_get_iter_first (model, &iter);
545
 
    for ( ; acl; acl = g_list_next (acl)) {
546
 
    
547
 
        ac = (GnomeKeyringAccessControl*)acl->data;
548
 
        g_return_if_fail (ac);
549
 
        
550
 
        if (!valid)
551
 
            gtk_list_store_append (store, &iter);
552
 
 
553
 
        display = gnome_keyring_item_ac_get_display_name (ac);
554
 
        gtk_list_store_set (store, &iter, 0, display ? display : "", -1);
555
 
        g_free (display);
556
 
        
557
 
        if (valid)
558
 
            valid = gtk_tree_model_iter_next (model, &iter);
559
 
    }
560
 
    
561
 
    /* Remove all the remaining rows */
562
 
    while (valid)
563
 
        valid = gtk_list_store_remove (store, &iter);
564
 
        
565
 
    update_application_details (swidget);
566
 
}
567
 
 
568
 
/* -----------------------------------------------------------------------------
569
 
 * GENERAL
570
 
 */
571
 
 
572
 
static void
573
 
key_changed (SeahorseKey *skey, SeahorseKeyChange change, SeahorseWidget *swidget)
574
 
{
575
 
    do_main (swidget);
576
 
    do_details (swidget);
577
 
    do_application (swidget);
578
 
}
579
 
 
580
 
static void
581
 
key_destroyed (GtkObject *object, SeahorseWidget *swidget)
582
 
{
583
 
    seahorse_widget_destroy (swidget);
584
 
}
585
 
 
586
 
static void
587
 
properties_destroyed (GtkObject *object, SeahorseWidget *swidget)
588
 
{
589
 
    g_signal_handlers_disconnect_by_func (SEAHORSE_KEY_WIDGET (swidget)->skey,
590
 
                                          key_changed, swidget);
591
 
    g_signal_handlers_disconnect_by_func (SEAHORSE_KEY_WIDGET (swidget)->skey,
592
 
                                          key_destroyed, swidget);
593
 
}
594
 
 
595
 
static void
596
 
properties_response (GtkDialog *dialog, int response, SeahorseWidget *swidget)
597
 
{
598
 
    if (response == GTK_RESPONSE_HELP) {
599
 
        seahorse_widget_show_help(swidget);
600
 
        return;
601
 
    }
602
 
   
603
 
    seahorse_widget_destroy (swidget);
604
 
}
605
 
 
606
 
void
607
 
seahorse_gkeyring_item_properties_new (SeahorseGKeyringItem *git, GtkWindow *parent)
608
 
{
609
 
    SeahorseKey *key = SEAHORSE_KEY (git);
610
 
    SeahorseKeySource *sksrc;
611
 
    SeahorseWidget *swidget = NULL;
612
 
    GtkWidget *widget;
613
 
 
614
 
    swidget = seahorse_key_widget_new ("gkeyring-item-properties",
615
 
                                       parent, 
616
 
                                       key);    
617
 
    
618
 
    /* This happens if the window is already open */
619
 
    if (swidget == NULL)
620
 
        return;
621
 
 
622
 
    /* This causes the key source to get any specific info about the key */
623
 
    if (seahorse_key_get_loaded (key) < SKEY_INFO_COMPLETE) {
624
 
        sksrc = seahorse_key_get_source (key);
625
 
        seahorse_key_source_load_async (sksrc, seahorse_key_get_keyid (key));
626
 
    }
627
 
 
628
 
    widget = glade_xml_get_widget (swidget->xml, swidget->name);
629
 
    g_signal_connect (widget, "response", G_CALLBACK (properties_response), swidget);
630
 
    g_signal_connect (GTK_OBJECT (widget), "destroy", G_CALLBACK (properties_destroyed), swidget);
631
 
    g_signal_connect_after (git, "changed", G_CALLBACK (key_changed), swidget);
632
 
    g_signal_connect_after (git, "destroy", G_CALLBACK (key_destroyed), swidget);
633
 
 
634
 
    /* 
635
 
     * The signals don't need to keep getting connected. Everytime a key changes the
636
 
     * do_* functions get called. Therefore, seperate functions connect the signals
637
 
     * have been created
638
 
     */
639
 
 
640
 
    do_main (swidget);
641
 
    do_details (swidget);
642
 
    do_application (swidget);
643
 
    
644
 
    widget = seahorse_widget_get_widget (swidget, "password-expander");
645
 
    g_return_if_fail (widget);
646
 
    g_signal_connect_after (widget, "activate", G_CALLBACK (password_expander_activate), swidget);
647
 
 
648
 
    glade_xml_signal_connect_data (swidget->xml, "show_password_toggled", 
649
 
                                   G_CALLBACK (show_password_toggled), swidget);
650
 
 
651
 
    widget = seahorse_widget_get_widget (swidget, "description-field");
652
 
    g_return_if_fail (widget != NULL);
653
 
    g_signal_connect (widget, "activate", G_CALLBACK (description_activate), swidget);
654
 
    g_signal_connect (widget, "focus-out-event", G_CALLBACK (description_focus_out), swidget);
655
 
 
656
 
    glade_xml_signal_connect_data (swidget->xml, "application_access_toggled", 
657
 
                                   G_CALLBACK (application_access_toggled), swidget);
658
 
 
659
 
    widget = seahorse_widget_get_widget (swidget, "application-list");
660
 
    g_return_if_fail (GTK_IS_TREE_VIEW (widget));
661
 
    
662
 
    g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)), "changed", 
663
 
                      G_CALLBACK (application_selection_changed), swidget);
664
 
}