~ubuntu-branches/ubuntu/trusty/gcr/trusty-proposed

« back to all changes in this revision

Viewing changes to gcr/gcr-import-button.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-03 10:18:39 UTC
  • Revision ID: package-import@ubuntu.com-20120503101839-wuvloldm7gmdsnij
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gnome-keyring
 
3
 *
 
4
 * Copyright (C) 2011 Collabora Ltd.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as
 
8
 * published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 *
 
21
 * Author: Stef Walter <stefw@collabora.co.uk>
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include "gcr-import-button.h"
 
27
#include "gcr-internal.h"
 
28
#include "gcr-library.h"
 
29
#include "gcr-marshal.h"
 
30
#include "gcr-parser.h"
 
31
#include "gcr-pkcs11-import-interaction.h"
 
32
 
 
33
#include <glib/gi18n-lib.h>
 
34
 
 
35
enum {
 
36
        PROP_0,
 
37
        PROP_LABEL
 
38
};
 
39
 
 
40
/**
 
41
 * SECTION:gcr-import-button
 
42
 * @title: GcrImportButton
 
43
 * @short_description: Button which imports parsed certificates and keys
 
44
 *
 
45
 * A button which imports keys and certificates. Shows a spinner when the
 
46
 * button is activated. When more than one importer is available shows
 
47
 * a drop down to select which to import to.
 
48
 */
 
49
 
 
50
/**
 
51
 * GcrImportButton:
 
52
 *
 
53
 * Button which imports parsed certificates and keys.
 
54
 */
 
55
 
 
56
/**
 
57
 * GcrImportButtonClass:
 
58
 * @parent_class: The parent class
 
59
 * @importing: Emitted when the import begins.
 
60
 * @imported: Emitted when the import completes, or fails.
 
61
 *
 
62
 * Class for #GcrImportButton.
 
63
 */
 
64
 
 
65
struct _GcrImportButtonPrivate {
 
66
        GList *queued;
 
67
        GList *importers;
 
68
        gboolean ready;
 
69
        gboolean created;
 
70
        gboolean importing;
 
71
        gchar *imported;
 
72
        GtkWidget *spinner;
 
73
        GtkWidget *arrow;
 
74
        GtkWidget *label;
 
75
        GCancellable *cancellable;
 
76
        GtkMenu *menu;
 
77
};
 
78
 
 
79
enum {
 
80
        IMPORTING,
 
81
        IMPORTED,
 
82
        LAST_SIGNAL
 
83
};
 
84
 
 
85
static guint signals[LAST_SIGNAL] = { 0 };
 
86
 
 
87
static GQuark QUARK_IMPORTER = 0;
 
88
 
 
89
G_DEFINE_TYPE (GcrImportButton, gcr_import_button, GTK_TYPE_BUTTON);
 
90
 
 
91
static void
 
92
gcr_import_button_init (GcrImportButton *self)
 
93
{
 
94
        self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_IMPORT_BUTTON, GcrImportButtonPrivate);
 
95
        self->pv->cancellable = g_cancellable_new ();
 
96
        self->pv->label = gtk_label_new ("");
 
97
}
 
98
 
 
99
static void
 
100
update_import_button (GcrImportButton *self)
 
101
{
 
102
        gchar *message;
 
103
        gchar *label;
 
104
 
 
105
        /* Initializing, set a spinner */
 
106
        if (self->pv->queued && !self->pv->ready) {
 
107
                gtk_widget_show (self->pv->spinner);
 
108
                gtk_spinner_start (GTK_SPINNER (self->pv->spinner));
 
109
                gtk_widget_hide (self->pv->arrow);
 
110
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
111
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Initializing..."));
 
112
 
 
113
        /* Importing, set a spinner */
 
114
        } else if (self->pv->importing) {
 
115
                gtk_widget_show (self->pv->spinner);
 
116
                gtk_spinner_start (GTK_SPINNER (self->pv->spinner));
 
117
                gtk_widget_hide (self->pv->arrow);
 
118
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
119
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Import is in progress..."));
 
120
 
 
121
        } else if (self->pv->imported) {
 
122
                gtk_widget_hide (self->pv->spinner);
 
123
                gtk_spinner_stop (GTK_SPINNER (self->pv->spinner));
 
124
                gtk_widget_hide (self->pv->arrow);
 
125
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
126
                message = g_strdup_printf (_("Imported to: %s"), self->pv->imported);
 
127
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), message);
 
128
                g_free (message);
 
129
 
 
130
        /* Not importing, but have importers */
 
131
        } else if (self->pv->importers) {
 
132
 
 
133
                gtk_widget_hide (self->pv->spinner);
 
134
                gtk_spinner_stop (GTK_SPINNER (self->pv->spinner));
 
135
                gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
 
136
 
 
137
                /* More than one importer */
 
138
                if (self->pv->importers->next) {
 
139
                        gtk_widget_show (self->pv->arrow);
 
140
                        gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL);
 
141
 
 
142
                /* Only one importer */
 
143
                } else {
 
144
                        gtk_widget_hide (self->pv->arrow);
 
145
                        g_object_get (self->pv->importers->data, "label", &label, NULL);
 
146
                        message = g_strdup_printf (_("Import to: %s"), label);
 
147
                        gtk_widget_set_tooltip_text (GTK_WIDGET (self), message);
 
148
                        g_free (message);
 
149
                        g_free (label);
 
150
                }
 
151
 
 
152
        /* No importers, none compatible */
 
153
        } else if (self->pv->created) {
 
154
                gtk_widget_hide (self->pv->spinner);
 
155
                gtk_spinner_stop (GTK_SPINNER (self->pv->spinner));
 
156
                gtk_widget_hide (self->pv->arrow);
 
157
 
 
158
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
159
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Cannot import because there are no compatible importers"));
 
160
 
 
161
        /* No importers yet added */
 
162
        } else {
 
163
                gtk_widget_hide (self->pv->spinner);
 
164
                gtk_spinner_stop (GTK_SPINNER (self->pv->spinner));
 
165
                gtk_widget_hide (self->pv->arrow);
 
166
 
 
167
                gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
 
168
                gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("No data to import"));
 
169
        }
 
170
}
 
171
 
 
172
static void
 
173
on_library_pkcs11_ready (GObject *source,
 
174
                         GAsyncResult *result,
 
175
                         gpointer user_data)
 
176
{
 
177
        GcrImportButton *self = GCR_IMPORT_BUTTON (user_data);
 
178
        GList *queued, *l;
 
179
 
 
180
        self->pv->ready = TRUE;
 
181
 
 
182
        /* Process the parsed items that have been seen */
 
183
        queued = self->pv->queued;
 
184
        self->pv->queued = NULL;
 
185
        for (l = queued; l != NULL; l = g_list_next (l))
 
186
                gcr_import_button_add_parsed (self, l->data);
 
187
        g_assert (self->pv->queued == NULL);
 
188
        g_list_free_full (queued, gcr_parsed_unref);
 
189
}
 
190
 
 
191
static void
 
192
gcr_import_button_constructed (GObject *obj)
 
193
{
 
194
        GcrImportButton *self = GCR_IMPORT_BUTTON (obj);
 
195
        GtkWidget *grid;
 
196
 
 
197
        G_OBJECT_CLASS (gcr_import_button_parent_class)->constructed (obj);
 
198
 
 
199
        self->pv->spinner = gtk_spinner_new ();
 
200
        self->pv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
 
201
        grid = gtk_grid_new ();
 
202
 
 
203
        gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_HORIZONTAL);
 
204
        gtk_container_add (GTK_CONTAINER (grid), self->pv->spinner);
 
205
        gtk_container_add (GTK_CONTAINER (grid), self->pv->label);
 
206
        gtk_container_add (GTK_CONTAINER (grid), self->pv->arrow);
 
207
        gtk_grid_set_row_spacing (GTK_GRID (grid), 3);
 
208
        gtk_widget_set_hexpand (grid, TRUE);
 
209
        gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
 
210
 
 
211
        gtk_widget_show (self->pv->label);
 
212
        gtk_widget_show (grid);
 
213
 
 
214
        gtk_container_add (GTK_CONTAINER (self), grid);
 
215
 
 
216
        update_import_button (self);
 
217
 
 
218
        gcr_pkcs11_initialize_async (NULL, on_library_pkcs11_ready, g_object_ref (self));
 
219
}
 
220
 
 
221
static void
 
222
gcr_import_button_set_property (GObject *obj,
 
223
                                guint prop_id,
 
224
                                const GValue *value,
 
225
                                GParamSpec *pspec)
 
226
{
 
227
        GcrImportButton *self = GCR_IMPORT_BUTTON (obj);
 
228
 
 
229
        switch (prop_id) {
 
230
        case PROP_LABEL:
 
231
                gtk_label_set_label (GTK_LABEL (self->pv->label), g_value_get_string (value));
 
232
                g_object_notify (obj, "label");
 
233
                break;
 
234
        default:
 
235
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 
236
                break;
 
237
        }
 
238
}
 
239
 
 
240
static void
 
241
gcr_import_button_get_property (GObject *obj,
 
242
                                guint prop_id,
 
243
                                GValue *value,
 
244
                                GParamSpec *pspec)
 
245
{
 
246
        GcrImportButton *self = GCR_IMPORT_BUTTON (obj);
 
247
 
 
248
        switch (prop_id) {
 
249
        case PROP_LABEL:
 
250
                g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->pv->label)));
 
251
                break;
 
252
        default:
 
253
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 
254
                break;
 
255
        }
 
256
}
 
257
 
 
258
static void
 
259
gcr_import_button_dispose (GObject *obj)
 
260
{
 
261
        GcrImportButton *self = GCR_IMPORT_BUTTON (obj);
 
262
 
 
263
        gck_list_unref_free (self->pv->importers);
 
264
        self->pv->importers = NULL;
 
265
        g_cancellable_cancel (self->pv->cancellable);
 
266
        g_clear_object (&self->pv->menu);
 
267
 
 
268
        g_list_free_full (self->pv->queued, gcr_parsed_unref);
 
269
        self->pv->queued = NULL;
 
270
 
 
271
        G_OBJECT_CLASS (gcr_import_button_parent_class)->dispose (obj);
 
272
}
 
273
 
 
274
static void
 
275
gcr_import_button_finalize (GObject *obj)
 
276
{
 
277
        GcrImportButton *self = GCR_IMPORT_BUTTON (obj);
 
278
 
 
279
        g_object_unref (self->pv->cancellable);
 
280
 
 
281
        G_OBJECT_CLASS (gcr_import_button_parent_class)->finalize (obj);
 
282
}
 
283
 
 
284
static void
 
285
on_import_complete (GObject *importer,
 
286
                    GAsyncResult *result,
 
287
                    gpointer user_data)
 
288
{
 
289
        GcrImportButton *self = GCR_IMPORT_BUTTON (user_data);
 
290
        GError *error = NULL;
 
291
 
 
292
        g_return_if_fail (self->pv->imported == NULL);
 
293
 
 
294
        self->pv->importing = FALSE;
 
295
 
 
296
        gcr_importer_import_finish (GCR_IMPORTER (importer), result, &error);
 
297
        if (error == NULL) {
 
298
                g_object_get (importer, "label", &self->pv->imported, NULL);
 
299
                gck_list_unref_free (self->pv->importers);
 
300
                self->pv->importers = NULL;
 
301
        }
 
302
 
 
303
        g_signal_emit (self, signals[IMPORTED], 0, importer, error);
 
304
        g_clear_error (&error);
 
305
 
 
306
        update_import_button (self);
 
307
}
 
308
 
 
309
static void
 
310
begin_import (GcrImportButton *self,
 
311
              GcrImporter *importer)
 
312
{
 
313
        GTlsInteraction *interaction;
 
314
        GtkWindow *window;
 
315
 
 
316
        g_return_if_fail (self->pv->importing == FALSE);
 
317
 
 
318
        g_signal_emit (self, signals[IMPORTING], 0, importer);
 
319
 
 
320
        self->pv->importing = TRUE;
 
321
        g_free (self->pv->imported);
 
322
        self->pv->imported = NULL;
 
323
 
 
324
        /* TODO: Hack. Need to figure out how to pair these up... */
 
325
        if (g_strcmp0 (G_OBJECT_TYPE_NAME (importer), "GcrPkcs11Importer") == 0) {
 
326
                window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
 
327
                interaction = _gcr_pkcs11_import_interaction_new (window);
 
328
                gcr_importer_set_interaction (importer, interaction);
 
329
                g_object_unref (interaction);
 
330
        }
 
331
 
 
332
        gcr_importer_import_async (importer,
 
333
                                   self->pv->cancellable,
 
334
                                   on_import_complete,
 
335
                                   g_object_ref (self));
 
336
}
 
337
 
 
338
static void
 
339
on_importer_menu_activated (GtkMenuItem *menu_item,
 
340
                            gpointer user_data)
 
341
{
 
342
        GcrImportButton *self = GCR_IMPORT_BUTTON (user_data);
 
343
        GcrImporter *importer;
 
344
 
 
345
        importer = g_object_get_qdata (G_OBJECT (menu_item), QUARK_IMPORTER);
 
346
        g_return_if_fail (GCR_IMPORTER (importer));
 
347
        g_return_if_fail (self->pv->importing == FALSE);
 
348
 
 
349
        begin_import (self, importer);
 
350
        update_import_button (self);
 
351
}
 
352
 
 
353
static void
 
354
update_importer_menu (GcrImportButton *self)
 
355
{
 
356
        GtkWidget *menu_item;
 
357
        GtkWidget *image;
 
358
        GList *children, *l;
 
359
        GIcon *icon;
 
360
        gchar *label;
 
361
 
 
362
        if (!self->pv->menu) {
 
363
                self->pv->menu = GTK_MENU (gtk_menu_new ());
 
364
                g_object_ref_sink (self->pv->menu);
 
365
        }
 
366
 
 
367
        children = gtk_container_get_children (GTK_CONTAINER (self->pv->menu));
 
368
        for (l = children; l != NULL; l = g_list_next (l))
 
369
                gtk_container_remove (GTK_CONTAINER (self->pv->menu), l->data);
 
370
        g_list_free (children);
 
371
 
 
372
        for (l = self->pv->importers; l != NULL; l = g_list_next (l)) {
 
373
                g_object_get (l->data, "label", &label, "icon", &icon, NULL);
 
374
                menu_item = gtk_image_menu_item_new_with_label (label);
 
375
                g_signal_connect (menu_item, "activate", G_CALLBACK (on_importer_menu_activated), self);
 
376
                g_object_set_qdata (G_OBJECT (menu_item), QUARK_IMPORTER, l->data);
 
377
                image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
 
378
                gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
 
379
                gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);
 
380
                gtk_widget_show (image);
 
381
                gtk_widget_show (menu_item);
 
382
                gtk_container_add (GTK_CONTAINER (self->pv->menu), menu_item);
 
383
                g_object_unref (icon);
 
384
                g_free (label);
 
385
        }
 
386
}
 
387
 
 
388
static void
 
389
on_menu_position (GtkMenu *menu,
 
390
                  gint *x,
 
391
                  gint *y,
 
392
                  gboolean *push_in,
 
393
                  gpointer user_data)
 
394
{
 
395
        GcrImportButton *self = GCR_IMPORT_BUTTON (user_data);
 
396
        GtkWidget *widget = GTK_WIDGET (self);
 
397
        GtkAllocation allocation;
 
398
        GtkRequisition menu_req;
 
399
        GdkRectangle monitor;
 
400
        GdkWindow *window;
 
401
        GtkWidget *toplevel;
 
402
        GdkScreen *screen;
 
403
        gint monitor_num;
 
404
        gint sx = 0;
 
405
        gint sy = 0;
 
406
 
 
407
        g_return_if_fail (x != NULL);
 
408
        g_return_if_fail (y != NULL);
 
409
        g_return_if_fail (push_in != NULL);
 
410
 
 
411
        gtk_widget_get_allocation (widget, &allocation);
 
412
 
 
413
        if (!gtk_widget_get_has_window (widget)) {
 
414
                sx += allocation.x;
 
415
                sy += allocation.y;
 
416
        }
 
417
 
 
418
        window = gtk_widget_get_window (widget);
 
419
        gdk_window_get_root_coords (window, sx, sy, &sx, &sy);
 
420
 
 
421
        gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &menu_req);
 
422
        if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
 
423
                *x = sx;
 
424
        else
 
425
                *x = sx + allocation.width - menu_req.width;
 
426
        *y = sy;
 
427
 
 
428
        screen = gtk_widget_get_screen (widget);
 
429
        monitor_num = gdk_screen_get_monitor_at_window (screen, window);
 
430
        if (monitor_num < 0)
 
431
                monitor_num = 0;
 
432
        gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
433
 
 
434
        if (*x < monitor.x)
 
435
                *x = monitor.x;
 
436
        else if (*x + menu_req.width > monitor.x + monitor.width)
 
437
                *x = monitor.x + monitor.width - menu_req.width;
 
438
 
 
439
        if (monitor.y + monitor.height - *y - allocation.height >= menu_req.height)
 
440
                *y += allocation.height;
 
441
        else if (*y - monitor.y >= menu_req.height)
 
442
                *y -= menu_req.height;
 
443
        else if (monitor.y + monitor.height - *y - allocation.height > *y - monitor.y)
 
444
                *y += allocation.height;
 
445
        else
 
446
                *y -= menu_req.height;
 
447
 
 
448
        gtk_menu_set_monitor (menu, monitor_num);
 
449
 
 
450
        toplevel = gtk_widget_get_parent (GTK_WIDGET (menu));
 
451
        if (GTK_IS_WINDOW (toplevel) && gtk_widget_get_visible (toplevel))
 
452
                gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
 
453
 
 
454
        *push_in = FALSE;
 
455
}
 
456
 
 
457
static void
 
458
gcr_import_button_clicked (GtkButton *button)
 
459
{
 
460
        GcrImportButton *self = GCR_IMPORT_BUTTON (button);
 
461
 
 
462
        g_return_if_fail (self->pv->importing == FALSE);
 
463
        g_return_if_fail (self->pv->importers != NULL);
 
464
 
 
465
        /* More than one importer, show the menu */
 
466
        if (self->pv->importers->next) {
 
467
                update_importer_menu (self);
 
468
                gtk_menu_popup (self->pv->menu, NULL, NULL, on_menu_position,
 
469
                                self, 1, gtk_get_current_event_time ());
 
470
 
 
471
        /* Only one importer, import on click */
 
472
        } else {
 
473
                begin_import (self, self->pv->importers->data);
 
474
        }
 
475
 
 
476
        update_import_button (self);
 
477
}
 
478
 
 
479
static void
 
480
gcr_import_button_class_init (GcrImportButtonClass *klass)
 
481
{
 
482
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
483
        GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
 
484
 
 
485
        gobject_class->constructed = gcr_import_button_constructed;
 
486
        gobject_class->dispose = gcr_import_button_dispose;
 
487
        gobject_class->finalize = gcr_import_button_finalize;
 
488
        gobject_class->get_property = gcr_import_button_get_property;
 
489
        gobject_class->set_property = gcr_import_button_set_property;
 
490
 
 
491
        button_class->clicked = gcr_import_button_clicked;
 
492
 
 
493
        g_object_class_override_property (gobject_class, PROP_LABEL, "label");
 
494
 
 
495
        /**
 
496
         * GcrImportButton::importing:
 
497
         * @self: the import button
 
498
         * @importer: the importer that will be imported to
 
499
         *
 
500
         * Signal emitted when an import begins.
 
501
         */
 
502
        signals[IMPORTING] = g_signal_new ("importing", GCR_TYPE_IMPORT_BUTTON, G_SIGNAL_RUN_LAST,
 
503
                                          G_STRUCT_OFFSET (GcrImportButtonClass, importing),
 
504
                                          NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
 
505
                                          G_TYPE_NONE, 1, G_TYPE_OBJECT);
 
506
 
 
507
        /**
 
508
         * GcrImportButton::imported:
 
509
         * @self: the import button
 
510
         * @importer: the importer that was imported to
 
511
         * @error: if import was successful %NULL, or an error
 
512
         *
 
513
         * Signal emitted when an import completes or fails.
 
514
         */
 
515
        signals[IMPORTED] = g_signal_new ("imported", GCR_TYPE_IMPORT_BUTTON, G_SIGNAL_RUN_LAST,
 
516
                                          G_STRUCT_OFFSET (GcrImportButtonClass, imported),
 
517
                                          NULL, NULL, _gcr_marshal_VOID__OBJECT_BOXED,
 
518
                                          G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_ERROR);
 
519
 
 
520
        QUARK_IMPORTER = g_quark_from_static_string ("gcr-import-button-importer");
 
521
 
 
522
        g_type_class_add_private (klass, sizeof (GcrImportButtonPrivate));
 
523
}
 
524
 
 
525
/**
 
526
 * gcr_import_button_new:
 
527
 * @label: (allow-none): label to display on the button
 
528
 *
 
529
 * Create a new #GcrImportButton.
 
530
 *
 
531
 * Returns: (transfer full): a newly created #GcrImportButton
 
532
 */
 
533
GcrImportButton *
 
534
gcr_import_button_new (const gchar *label)
 
535
{
 
536
        return g_object_new (GCR_TYPE_IMPORT_BUTTON,
 
537
                             "label", label,
 
538
                             NULL);
 
539
}
 
540
 
 
541
/**
 
542
 * gcr_import_button_add_parsed:
 
543
 * @self: an import button
 
544
 * @parsed: a parsed item
 
545
 *
 
546
 * Queue an item to import via the button
 
547
 */
 
548
void
 
549
gcr_import_button_add_parsed (GcrImportButton *self,
 
550
                              GcrParsed *parsed)
 
551
{
 
552
        GList *importers;
 
553
 
 
554
        g_return_if_fail (GCR_IS_IMPORT_BUTTON (self));
 
555
        g_return_if_fail (parsed != NULL);
 
556
 
 
557
        if (!self->pv->ready) {
 
558
                self->pv->queued = g_list_prepend (self->pv->queued, gcr_parsed_ref (parsed));
 
559
                update_import_button (self);
 
560
                return;
 
561
        }
 
562
 
 
563
        g_free (self->pv->imported);
 
564
        self->pv->imported = NULL;
 
565
 
 
566
        if (self->pv->created) {
 
567
                importers = gcr_importer_queue_and_filter_for_parsed (self->pv->importers, parsed);
 
568
        } else {
 
569
                importers = gcr_importer_create_for_parsed (parsed);
 
570
                self->pv->created = TRUE;
 
571
        }
 
572
 
 
573
        gck_list_unref_free (self->pv->importers);
 
574
        self->pv->importers = importers;
 
575
 
 
576
        update_import_button (self);
 
577
}