4
* Copyright (C) 2008 Stefan Walter
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.
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.
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
22
#include "seahorse-viewer.h"
23
#include <glib/gi18n-lib.h>
25
#include <seahorse-preferences.h>
27
#include <seahorse-commands.h>
28
#include <seahorse-util.h>
29
#include <seahorse-types.h>
30
#include <seahorse-operation.h>
32
#include <seahorse-source.h>
33
#include <seahorse-progress.h>
34
#include <common/seahorse-registry.h>
39
struct _SeahorseViewerPrivate {
40
GtkUIManager* _ui_manager;
41
GtkActionGroup* _object_actions;
42
GHashTable* _commands;
45
#define SEAHORSE_VIEWER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SEAHORSE_TYPE_VIEWER, SeahorseViewerPrivate))
47
SEAHORSE_VIEWER_DUMMY_PROPERTY,
48
SEAHORSE_VIEWER_SELECTED,
49
SEAHORSE_VIEWER_CURRENT_SET,
50
SEAHORSE_VIEWER_WINDOW
52
static gboolean seahorse_viewer__about_initialized;
53
static void _seahorse_viewer_on_app_preferences_gtk_action_activate (GtkAction* _sender, gpointer self);
54
static void _seahorse_viewer_on_app_about_gtk_action_activate (GtkAction* _sender, gpointer self);
55
static void _seahorse_viewer_on_help_show_gtk_action_activate (GtkAction* _sender, gpointer self);
56
static void _seahorse_viewer_on_key_properties_gtk_action_activate (GtkAction* _sender, gpointer self);
57
static void _seahorse_viewer_on_key_export_file_gtk_action_activate (GtkAction* _sender, gpointer self);
58
static void _seahorse_viewer_on_key_export_clipboard_gtk_action_activate (GtkAction* _sender, gpointer self);
59
static void _seahorse_viewer_on_key_delete_gtk_action_activate (GtkAction* _sender, gpointer self);
60
static void seahorse_viewer_include_basic_actions (SeahorseViewer* self);
61
static GList* seahorse_viewer_real_get_selected_objects (SeahorseViewer* self);
62
static void seahorse_viewer_real_set_selected_objects (SeahorseViewer* self, GList* objects);
63
static SeahorseObject* seahorse_viewer_real_get_selected_object_and_uid (SeahorseViewer* self, guint* uid);
64
static void seahorse_viewer_on_ui_add_widget (SeahorseViewer* self, GtkUIManager* ui, GtkWidget* widget);
65
static void seahorse_viewer_on_app_preferences (SeahorseViewer* self, GtkAction* action);
66
static void _seahorse_viewer_on_about_link_clicked_gtk_about_dialog_activate_link_func (GtkAboutDialog* about, const char* link_, gpointer self);
67
static void seahorse_viewer_on_app_about (SeahorseViewer* self, GtkAction* action);
68
static void seahorse_viewer_on_about_link_clicked (GtkAboutDialog* about, const char* url);
69
static void seahorse_viewer_on_help_show (SeahorseViewer* self, GtkAction* action);
70
static void seahorse_viewer_on_key_properties (SeahorseViewer* self, GtkAction* action);
71
static gint seahorse_viewer_compare_by_tag (SeahorseViewer* self, SeahorseObject* one, SeahorseObject* two);
72
static void seahorse_viewer_delete_object_batch (SeahorseViewer* self, GList* objects);
73
static void seahorse_viewer_on_key_delete (SeahorseViewer* self, GtkAction* action);
74
static void seahorse_viewer_on_copy_complete (SeahorseViewer* self, SeahorseOperation* op);
75
static void* _g_realloc_grealloc_func (void* data, gulong size);
76
static void _g_free_gdestroy_notify (void* data);
77
static void _seahorse_viewer_on_copy_complete_seahorse_done_func (SeahorseOperation* op, gpointer self);
78
static void seahorse_viewer_on_key_export_clipboard (SeahorseViewer* self, GtkAction* action);
79
static void seahorse_viewer_on_export_done (SeahorseViewer* self, SeahorseOperation* op);
80
static void _seahorse_viewer_on_export_done_seahorse_done_func (SeahorseOperation* op, gpointer self);
81
static void seahorse_viewer_on_key_export_file (SeahorseViewer* self, GtkAction* action);
82
static void seahorse_viewer_on_selection_changed (SeahorseViewer* self, SeahorseView* view);
83
static void _seahorse_viewer_on_ui_add_widget_gtk_ui_manager_add_widget (GtkUIManager* _sender, GtkWidget* widget, gpointer self);
84
static void _seahorse_viewer_on_selection_changed_seahorse_view_selection_changed (SeahorseViewer* _sender, gpointer self);
85
static GObject * seahorse_viewer_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
86
static gpointer seahorse_viewer_parent_class = NULL;
87
static SeahorseViewIface* seahorse_viewer_seahorse_view_parent_iface = NULL;
88
static void seahorse_viewer_dispose (GObject * obj);
89
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
91
static const GtkActionEntry SEAHORSE_VIEWER_UI_ENTRIES[] = {{"key-menu", NULL, N_ ("_Key")}, {"edit-menu", NULL, N_ ("_Edit")}, {"view-menu", NULL, N_ ("_View")}, {"help-menu", NULL, N_ ("_Help")}, {"app-preferences", GTK_STOCK_PREFERENCES, N_ ("Prefere_nces"), NULL, N_ ("Change preferences for this program"), ((GCallback) (NULL))}, {"app-about", "gnome-stock-about", N_ ("_About"), NULL, N_ ("About this program"), ((GCallback) (NULL))}, {"help-show", GTK_STOCK_HELP, N_ ("_Contents"), "F1", N_ ("Show Seahorse help"), ((GCallback) (NULL))}};
92
static const GtkActionEntry SEAHORSE_VIEWER_KEY_ENTRIES[] = {{"key-properties", GTK_STOCK_PROPERTIES, N_ ("P_roperties"), NULL, N_ ("Show key properties"), ((GCallback) (NULL))}, {"key-export-file", GTK_STOCK_SAVE_AS, N_ ("E_xport Public Key..."), NULL, N_ ("Export public part of key to a file"), ((GCallback) (NULL))}, {"key-export-clipboard", GTK_STOCK_COPY, N_ ("_Copy Public Key"), "<control>C", N_ ("Copy public part of selected keys to the clipboard"), ((GCallback) (NULL))}, {"key-delete", GTK_STOCK_DELETE, N_ ("_Delete Key"), NULL, N_ ("Delete selected keys"), ((GCallback) (NULL))}};
95
static void _seahorse_viewer_on_app_preferences_gtk_action_activate (GtkAction* _sender, gpointer self) {
96
seahorse_viewer_on_app_preferences (self, _sender);
100
static void _seahorse_viewer_on_app_about_gtk_action_activate (GtkAction* _sender, gpointer self) {
101
seahorse_viewer_on_app_about (self, _sender);
105
static void _seahorse_viewer_on_help_show_gtk_action_activate (GtkAction* _sender, gpointer self) {
106
seahorse_viewer_on_help_show (self, _sender);
110
static void _seahorse_viewer_on_key_properties_gtk_action_activate (GtkAction* _sender, gpointer self) {
111
seahorse_viewer_on_key_properties (self, _sender);
115
static void _seahorse_viewer_on_key_export_file_gtk_action_activate (GtkAction* _sender, gpointer self) {
116
seahorse_viewer_on_key_export_file (self, _sender);
120
static void _seahorse_viewer_on_key_export_clipboard_gtk_action_activate (GtkAction* _sender, gpointer self) {
121
seahorse_viewer_on_key_export_clipboard (self, _sender);
125
static void _seahorse_viewer_on_key_delete_gtk_action_activate (GtkAction* _sender, gpointer self) {
126
seahorse_viewer_on_key_delete (self, _sender);
130
static void seahorse_viewer_include_basic_actions (SeahorseViewer* self) {
131
GtkActionGroup* actions;
132
GtkActionGroup* _tmp0;
134
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
136
* We hook callbacks up here for now because of a compiler warning. See:
137
* http://bugzilla.gnome.org/show_bug.cgi?id=539483
139
actions = gtk_action_group_new ("main");
140
gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
141
gtk_action_group_add_actions (actions, SEAHORSE_VIEWER_UI_ENTRIES, G_N_ELEMENTS (SEAHORSE_VIEWER_UI_ENTRIES), self);
142
g_signal_connect_object (gtk_action_group_get_action (actions, "app-preferences"), "activate", ((GCallback) (_seahorse_viewer_on_app_preferences_gtk_action_activate)), self, 0);
143
g_signal_connect_object (gtk_action_group_get_action (actions, "app-about"), "activate", ((GCallback) (_seahorse_viewer_on_app_about_gtk_action_activate)), self, 0);
144
g_signal_connect_object (gtk_action_group_get_action (actions, "help-show"), "activate", ((GCallback) (_seahorse_viewer_on_help_show_gtk_action_activate)), self, 0);
145
seahorse_viewer_include_actions (self, actions);
147
self->priv->_object_actions = (_tmp0 = gtk_action_group_new ("key"), (self->priv->_object_actions == NULL ? NULL : (self->priv->_object_actions = (g_object_unref (self->priv->_object_actions), NULL))), _tmp0);
148
gtk_action_group_set_translation_domain (self->priv->_object_actions, GETTEXT_PACKAGE);
149
gtk_action_group_add_actions (self->priv->_object_actions, SEAHORSE_VIEWER_KEY_ENTRIES, G_N_ELEMENTS (SEAHORSE_VIEWER_KEY_ENTRIES), self);
150
g_signal_connect_object (gtk_action_group_get_action (self->priv->_object_actions, "key-properties"), "activate", ((GCallback) (_seahorse_viewer_on_key_properties_gtk_action_activate)), self, 0);
151
g_signal_connect_object (gtk_action_group_get_action (self->priv->_object_actions, "key-export-file"), "activate", ((GCallback) (_seahorse_viewer_on_key_export_file_gtk_action_activate)), self, 0);
152
g_signal_connect_object (gtk_action_group_get_action (self->priv->_object_actions, "key-export-clipboard"), "activate", ((GCallback) (_seahorse_viewer_on_key_export_clipboard_gtk_action_activate)), self, 0);
153
g_signal_connect_object (gtk_action_group_get_action (self->priv->_object_actions, "key-delete"), "activate", ((GCallback) (_seahorse_viewer_on_key_delete_gtk_action_activate)), self, 0);
154
/* Mark the properties toolbar button as important */
155
g_object_set (gtk_action_group_get_action (self->priv->_object_actions, "key-properties"), "is-important", TRUE, NULL);
156
seahorse_viewer_include_actions (self, self->priv->_object_actions);
157
(actions == NULL ? NULL : (actions = (g_object_unref (actions), NULL)));
161
void seahorse_viewer_ensure_updated (SeahorseViewer* self) {
162
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
163
gtk_ui_manager_ensure_update (self->priv->_ui_manager);
167
void seahorse_viewer_include_actions (SeahorseViewer* self, GtkActionGroup* actions) {
168
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
169
g_return_if_fail (GTK_IS_ACTION_GROUP (actions));
170
gtk_ui_manager_insert_action_group (self->priv->_ui_manager, actions, -1);
174
static GList* seahorse_viewer_real_get_selected_objects (SeahorseViewer* self) {
175
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), NULL);
180
GList* seahorse_viewer_get_selected_objects (SeahorseViewer* self) {
181
return SEAHORSE_VIEWER_GET_CLASS (self)->get_selected_objects (self);
185
static void seahorse_viewer_real_set_selected_objects (SeahorseViewer* self, GList* objects) {
186
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
187
g_return_if_fail (objects != NULL);
191
void seahorse_viewer_set_selected_objects (SeahorseViewer* self, GList* objects) {
192
SEAHORSE_VIEWER_GET_CLASS (self)->set_selected_objects (self, objects);
196
static SeahorseObject* seahorse_viewer_real_get_selected_object_and_uid (SeahorseViewer* self, guint* uid) {
197
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), NULL);
198
/* Must be overridden */
203
SeahorseObject* seahorse_viewer_get_selected_object_and_uid (SeahorseViewer* self, guint* uid) {
204
return SEAHORSE_VIEWER_GET_CLASS (self)->get_selected_object_and_uid (self, uid);
208
static void seahorse_viewer_on_ui_add_widget (SeahorseViewer* self, GtkUIManager* ui, GtkWidget* widget) {
212
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
213
g_return_if_fail (GTK_IS_UI_MANAGER (ui));
214
g_return_if_fail (GTK_IS_WIDGET (widget));
216
if (G_TYPE_FROM_INSTANCE (G_OBJECT (widget)) == GTK_TYPE_MENU_BAR) {
219
name = (_tmp0 = g_strdup ("menu-placeholder"), (name = (g_free (name), NULL)), _tmp0);
221
if (G_TYPE_FROM_INSTANCE (G_OBJECT (widget)) == GTK_TYPE_TOOLBAR) {
224
name = (_tmp1 = g_strdup ("toolbar-placeholder"), (name = (g_free (name), NULL)), _tmp1);
226
name = (g_free (name), NULL);
231
holder = (_tmp2 = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), name), (_tmp2 == NULL ? NULL : g_object_ref (_tmp2)));
232
if (holder != NULL) {
233
gtk_container_add ((GTK_CONTAINER (holder)), widget);
235
g_warning ("seahorse-viewer.vala:187: no place holder found for: %s", name);
237
name = (g_free (name), NULL);
238
(holder == NULL ? NULL : (holder = (g_object_unref (holder), NULL)));
242
static void seahorse_viewer_on_app_preferences (SeahorseViewer* self, GtkAction* action) {
243
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
244
g_return_if_fail (GTK_IS_ACTION (action));
245
seahorse_preferences_show (seahorse_view_get_window (SEAHORSE_VIEW (self)), NULL);
249
static void _seahorse_viewer_on_about_link_clicked_gtk_about_dialog_activate_link_func (GtkAboutDialog* about, const char* link_, gpointer self) {
250
seahorse_viewer_on_about_link_clicked (about, link_);
254
static void seahorse_viewer_on_app_about (SeahorseViewer* self, GtkAction* action) {
256
gint authors_length1;
261
gint documenters_length1;
265
gint artists_length1;
268
GtkAboutDialog* about;
269
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
270
g_return_if_fail (GTK_IS_ACTION (action));
274
authors = (_tmp2 = (_tmp1 = g_new0 (char*, 9 + 1), _tmp1[0] = g_strdup ("Jacob Perkins <jap1@users.sourceforge.net>"), _tmp1[1] = g_strdup ("Jose Carlos Garcia Sogo <jsogo@users.sourceforge.net>"), _tmp1[2] = g_strdup ("Jean Schurger <yshark@schurger.org>"), _tmp1[3] = g_strdup ("Stef Walter <stef@memberwebs.com>"), _tmp1[4] = g_strdup ("Adam Schreiber <sadam@clemson.edu>"), _tmp1[5] = g_strdup (""), _tmp1[6] = (_tmp0 = _ ("Contributions:"), (_tmp0 == NULL ? NULL : g_strdup (_tmp0))), _tmp1[7] = g_strdup ("Albrecht DreĆ <albrecht.dress@arcor.de>"), _tmp1[8] = g_strdup ("Jim Pharis <binbrain@gmail.com>"), _tmp1), authors_length1 = 9, _tmp2);
277
documenters = (_tmp4 = (_tmp3 = g_new0 (char*, 3 + 1), _tmp3[0] = g_strdup ("Jacob Perkins <jap1@users.sourceforge.net>"), _tmp3[1] = g_strdup ("Adam Schreiber <sadam@clemson.edu>"), _tmp3[2] = g_strdup ("Milo Casagrande <milo_casagrande@yahoo.it>"), _tmp3), documenters_length1 = 3, _tmp4);
280
artists = (_tmp6 = (_tmp5 = g_new0 (char*, 2 + 1), _tmp5[0] = g_strdup ("Jacob Perkins <jap1@users.sourceforge.net>"), _tmp5[1] = g_strdup ("Stef Walter <stef@memberwebs.com>"), _tmp5), artists_length1 = 2, _tmp6);
281
if (!seahorse_viewer__about_initialized) {
282
seahorse_viewer__about_initialized = TRUE;
283
gtk_about_dialog_set_url_hook (_seahorse_viewer_on_about_link_clicked_gtk_about_dialog_activate_link_func, NULL, NULL);
285
about = g_object_ref_sink (((GtkAboutDialog*) (gtk_about_dialog_new ())));
286
gtk_about_dialog_set_artists (about, artists);
287
gtk_about_dialog_set_authors (about, authors);
288
gtk_about_dialog_set_documenters (about, documenters);
289
gtk_about_dialog_set_version (about, VERSION);
290
gtk_about_dialog_set_comments (about, _ ("Encryption Key Manager"));
291
gtk_about_dialog_set_copyright (about, "Copyright \xc2\xa9 2002 - 2008 Seahorse Project");
292
gtk_about_dialog_set_translator_credits (about, _ ("translator-credits"));
293
gtk_about_dialog_set_logo_icon_name (about, "seahorse");
294
gtk_about_dialog_set_website (about, "http://www.gnome.org/projects/seahorse");
295
gtk_about_dialog_set_website_label (about, _ ("Seahorse Project Homepage"));
296
gtk_dialog_run (GTK_DIALOG (about));
297
authors = (_vala_array_free (authors, authors_length1, ((GDestroyNotify) (g_free))), NULL);
298
documenters = (_vala_array_free (documenters, documenters_length1, ((GDestroyNotify) (g_free))), NULL);
299
artists = (_vala_array_free (artists, artists_length1, ((GDestroyNotify) (g_free))), NULL);
300
(about == NULL ? NULL : (about = (g_object_unref (about), NULL)));
304
static void seahorse_viewer_on_about_link_clicked (GtkAboutDialog* about, const char* url) {
305
GError * inner_error;
306
g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
307
g_return_if_fail (url != NULL);
310
GAppLaunchContext* _tmp0;
312
g_app_info_launch_default_for_uri (url, (_tmp0 = g_app_launch_context_new ()), &inner_error);
313
if (inner_error != NULL) {
314
goto __catch0_g_error;
316
(_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL)));
325
g_warning ("seahorse-viewer.vala:243: couldn't launch url: %s: %s", url, ex->message);
326
(ex == NULL ? NULL : (ex = (g_error_free (ex), NULL)));
334
static void seahorse_viewer_on_help_show (SeahorseViewer* self, GtkAction* action) {
335
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
336
g_return_if_fail (GTK_IS_ACTION (action));
337
seahorse_widget_show_help (SEAHORSE_WIDGET (self));
341
void seahorse_viewer_show_context_menu (SeahorseViewer* self, guint button, guint time) {
344
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
346
menu = (_tmp0 = GTK_MENU (gtk_ui_manager_get_widget (self->priv->_ui_manager, "/KeyPopup")), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
347
g_return_if_fail (menu != NULL && G_TYPE_FROM_INSTANCE (G_OBJECT (menu)) == GTK_TYPE_MENU);
348
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button, time);
349
gtk_widget_show (GTK_WIDGET (menu));
350
(menu == NULL ? NULL : (menu = (g_object_unref (menu), NULL)));
354
void seahorse_viewer_show_properties (SeahorseViewer* self, SeahorseObject* obj) {
355
SeahorseCommands* _tmp0;
356
SeahorseCommands* commands;
357
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
358
g_return_if_fail (SEAHORSE_IS_OBJECT (obj));
360
commands = (_tmp0 = ((SeahorseCommands*) (g_hash_table_lookup (self->priv->_commands, GINT_TO_POINTER (seahorse_object_get_tag (obj))))), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
361
if (commands != NULL) {
362
seahorse_commands_show_properties (commands, obj);
364
(commands == NULL ? NULL : (commands = (g_object_unref (commands), NULL)));
368
static void seahorse_viewer_on_key_properties (SeahorseViewer* self, GtkAction* action) {
369
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
370
g_return_if_fail (GTK_IS_ACTION (action));
371
if (seahorse_viewer_get_selected (self) != NULL) {
372
seahorse_viewer_show_properties (self, seahorse_viewer_get_selected (self));
377
static gint seahorse_viewer_compare_by_tag (SeahorseViewer* self, SeahorseObject* one, SeahorseObject* two) {
380
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), 0);
381
g_return_val_if_fail (SEAHORSE_IS_OBJECT (one), 0);
382
g_return_val_if_fail (SEAHORSE_IS_OBJECT (two), 0);
383
kone = seahorse_object_get_tag (one);
384
ktwo = seahorse_object_get_tag (two);
395
static void seahorse_viewer_delete_object_batch (SeahorseViewer* self, GList* objects) {
396
GError * inner_error;
397
SeahorseCommands* _tmp0;
398
SeahorseCommands* commands;
399
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
400
g_return_if_fail (objects != NULL);
402
g_assert (objects != NULL);
404
commands = (_tmp0 = ((SeahorseCommands*) (g_hash_table_lookup (self->priv->_commands, GINT_TO_POINTER (seahorse_object_get_tag (((SeahorseObject*) (((SeahorseObject*) (objects->data))))))))), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
406
if (commands != NULL) {
407
seahorse_commands_delete_objects (commands, objects, &inner_error);
408
if (inner_error != NULL) {
409
goto __catch1_g_error;
420
seahorse_util_handle_error (ex, _ ("Couldn't delete."), seahorse_view_get_window (SEAHORSE_VIEW (self)), NULL);
421
(ex == NULL ? NULL : (ex = (g_error_free (ex), NULL)));
426
(commands == NULL ? NULL : (commands = (g_object_unref (commands), NULL)));
430
static void seahorse_viewer_on_key_delete (SeahorseViewer* self, GtkAction* action) {
437
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
438
g_return_if_fail (GTK_IS_ACTION (action));
441
/* Get the selected objects and sort them by ktype */
443
objects = (_tmp0 = seahorse_viewer_get_selected_objects (self), (objects == NULL ? NULL : (objects = (g_list_free (objects), NULL))), _tmp0);
444
objects = g_list_sort (objects, ((GCompareFunc) (seahorse_viewer_compare_by_tag)));
445
num = g_list_length (objects);
447
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
448
(batch == NULL ? NULL : (batch = (g_list_free (batch), NULL)));
451
/* Check for private objects */
453
GList* object_collection;
455
object_collection = objects;
456
for (object_it = object_collection; object_it != NULL; object_it = object_it->next) {
457
SeahorseObject* object;
458
object = ((SeahorseObject*) (object_it->data));
460
if (seahorse_object_get_usage (object) == SEAHORSE_USAGE_PRIVATE_KEY) {
466
prompt = (_tmp1 = g_strdup_printf (_ ("%s is a private key. Are you sure you want to proceed?"), seahorse_object_get_display_name (((SeahorseObject*) (((SeahorseObject*) (objects->data)))))), (prompt = (g_free (prompt), NULL)), _tmp1);
472
prompt = (_tmp3 = (_tmp2 = _ ("One or more of the deleted keys are private keys. Are you sure you want to proceed?"), (_tmp2 == NULL ? NULL : g_strdup (_tmp2))), (prompt = (g_free (prompt), NULL)), _tmp3);
474
if (!seahorse_util_prompt_delete (prompt)) {
475
prompt = (g_free (prompt), NULL);
476
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
477
(batch == NULL ? NULL : (batch = (g_list_free (batch), NULL)));
480
prompt = (g_free (prompt), NULL);
485
ktype = ((GQuark) (0));
487
batch = (_tmp4 = NULL, (batch == NULL ? NULL : (batch = (g_list_free (batch), NULL))), _tmp4);
489
GList* object_collection;
491
object_collection = objects;
492
for (object_it = object_collection; object_it != NULL; object_it = object_it->next) {
493
SeahorseObject* _tmp6;
494
SeahorseObject* object;
496
object = (_tmp6 = ((SeahorseObject*) (object_it->data)), (_tmp6 == NULL ? NULL : g_object_ref (_tmp6)));
498
/* Process that batch */
499
if (ktype != seahorse_object_get_tag (object) && batch != NULL) {
501
seahorse_viewer_delete_object_batch (self, batch);
503
batch = (_tmp5 = NULL, (batch == NULL ? NULL : (batch = (g_list_free (batch), NULL))), _tmp5);
505
/* Add to the batch */
506
batch = g_list_prepend (batch, object);
507
(object == NULL ? NULL : (object = (g_object_unref (object), NULL)));
511
/* Process last batch */
513
seahorse_viewer_delete_object_batch (self, batch);
515
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
516
(batch == NULL ? NULL : (batch = (g_list_free (batch), NULL)));
520
static void seahorse_viewer_on_copy_complete (SeahorseViewer* self, SeahorseOperation* op) {
523
GMemoryOutputStream* _tmp1;
524
GMemoryOutputStream* output;
530
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
531
g_return_if_fail (SEAHORSE_IS_OPERATION (op));
532
if (!seahorse_operation_is_successful (op)) {
533
seahorse_operation_display_error (op, _ ("Couldn't retrieve data from key server"), GTK_WIDGET (seahorse_view_get_window (SEAHORSE_VIEW (self))));
537
result = (_tmp0 = G_OBJECT (seahorse_operation_get_result (op)), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
538
g_return_if_fail (result != NULL && G_TYPE_FROM_INSTANCE (result) != G_TYPE_MEMORY_OUTPUT_STREAM);
540
output = (_tmp1 = G_MEMORY_OUTPUT_STREAM (result), (_tmp1 == NULL ? NULL : g_object_ref (_tmp1)));
541
text = ((const char*) (g_memory_output_stream_get_data (output)));
542
g_return_if_fail (text != NULL);
543
size = seahorse_util_memory_output_length (output);
544
g_return_if_fail (size >= 0);
545
atom = gdk_atom_intern ("CLIPBOARD", FALSE);
547
board = (_tmp2 = gtk_clipboard_get (atom), (_tmp2 == NULL ? NULL : g_object_ref (_tmp2)));
548
gtk_clipboard_set_text (board, text, ((gint) (size)));
549
seahorse_viewer_set_status (self, _ ("Copied keys"));
550
(result == NULL ? NULL : (result = (g_object_unref (result), NULL)));
551
(output == NULL ? NULL : (output = (g_object_unref (output), NULL)));
552
(board == NULL ? NULL : (board = (g_object_unref (board), NULL)));
556
static void* _g_realloc_grealloc_func (void* data, gulong size) {
557
return g_realloc (data, size);
561
static void _g_free_gdestroy_notify (void* data) {
566
static void _seahorse_viewer_on_copy_complete_seahorse_done_func (SeahorseOperation* op, gpointer self) {
567
seahorse_viewer_on_copy_complete (self, op);
571
static void seahorse_viewer_on_key_export_clipboard (SeahorseViewer* self, GtkAction* action) {
573
GOutputStream* output;
574
SeahorseOperation* op;
575
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
576
g_return_if_fail (GTK_IS_ACTION (action));
577
objects = seahorse_viewer_get_selected_objects (self);
578
if (objects == NULL) {
579
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
582
output = G_OUTPUT_STREAM (((GMemoryOutputStream*) (g_memory_output_stream_new (NULL, ((gulong) (0)), _g_realloc_grealloc_func, _g_free_gdestroy_notify))));
583
op = seahorse_source_export_objects (objects, output);
584
seahorse_progress_show (op, _ ("Retrieving keys"), TRUE);
585
seahorse_operation_watch (op, _seahorse_viewer_on_copy_complete_seahorse_done_func, self, NULL, NULL);
586
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
587
(output == NULL ? NULL : (output = (g_object_unref (output), NULL)));
588
(op == NULL ? NULL : (op = (g_object_unref (op), NULL)));
592
static void seahorse_viewer_on_export_done (SeahorseViewer* self, SeahorseOperation* op) {
593
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
594
g_return_if_fail (SEAHORSE_IS_OPERATION (op));
595
if (!seahorse_operation_is_successful (op)) {
596
seahorse_operation_display_error (op, _ ("Couldn't export keys"), GTK_WIDGET (seahorse_view_get_window (SEAHORSE_VIEW (self))));
601
static void _seahorse_viewer_on_export_done_seahorse_done_func (SeahorseOperation* op, gpointer self) {
602
seahorse_viewer_on_export_done (self, op);
606
static void seahorse_viewer_on_key_export_file (SeahorseViewer* self, GtkAction* action) {
607
GError * inner_error;
612
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
613
g_return_if_fail (GTK_IS_ACTION (action));
615
objects = seahorse_viewer_get_selected_objects (self);
616
if (objects == NULL) {
617
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
621
dialog = (_tmp0 = seahorse_util_chooser_save_new (_ ("Export public key"), seahorse_view_get_window (SEAHORSE_VIEW (self))), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
622
seahorse_util_chooser_show_key_files (dialog);
623
seahorse_util_chooser_set_filename (dialog, objects);
624
uri = seahorse_util_chooser_save_prompt (dialog);
628
GOutputStream* output;
629
SeahorseOperation* op;
630
file = g_file_new_for_uri (uri);
631
output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, &inner_error));
632
if (inner_error != NULL) {
633
goto __catch2_g_error;
635
op = seahorse_source_export_objects (objects, output);
636
seahorse_progress_show (op, _ ("Exporting keys"), TRUE);
637
seahorse_operation_watch (op, _seahorse_viewer_on_export_done_seahorse_done_func, self, NULL, NULL);
638
(file == NULL ? NULL : (file = (g_object_unref (file), NULL)));
639
(output == NULL ? NULL : (output = (g_object_unref (output), NULL)));
640
(op == NULL ? NULL : (op = (g_object_unref (op), NULL)));
651
seahorse_util_handle_error (ex, _ ("Couldn't export key to \"%s\""), (_tmp1 = seahorse_util_uri_get_last (uri)), NULL);
652
_tmp1 = (g_free (_tmp1), NULL);
653
(ex == NULL ? NULL : (ex = (g_error_free (ex), NULL)));
654
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
655
(dialog == NULL ? NULL : (dialog = (g_object_unref (dialog), NULL)));
656
uri = (g_free (uri), NULL);
663
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
664
(dialog == NULL ? NULL : (dialog = (g_object_unref (dialog), NULL)));
665
uri = (g_free (uri), NULL);
669
static void seahorse_viewer_on_selection_changed (SeahorseViewer* self, SeahorseView* view) {
670
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
671
g_return_if_fail (SEAHORSE_IS_VIEW (view));
672
gtk_action_group_set_sensitive (self->priv->_object_actions, seahorse_view_get_selected (view) != NULL);
676
void seahorse_viewer_set_status (SeahorseViewer* self, const char* text) {
680
GtkStatusbar* status;
682
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
683
g_return_if_fail (text != NULL);
685
widget = (_tmp0 = seahorse_widget_get_widget (SEAHORSE_WIDGET (self), "status"), (_tmp0 == NULL ? NULL : g_object_ref (_tmp0)));
686
g_return_if_fail (widget != NULL || G_TYPE_FROM_INSTANCE (G_OBJECT (widget)) != GTK_TYPE_STATUSBAR);
688
status = (_tmp1 = GTK_STATUSBAR (widget), (_tmp1 == NULL ? NULL : g_object_ref (_tmp1)));
689
id = gtk_statusbar_get_context_id (status, "key-manager");
690
gtk_statusbar_pop (status, id);
691
gtk_statusbar_push (status, id, text);
692
(widget == NULL ? NULL : (widget = (g_object_unref (widget), NULL)));
693
(status == NULL ? NULL : (status = (g_object_unref (status), NULL)));
697
void seahorse_viewer_set_numbered_status (SeahorseViewer* self, const char* text, gint num) {
699
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
700
g_return_if_fail (text != NULL);
701
message = g_strdup_printf (text, num);
702
seahorse_viewer_set_status (self, message);
703
message = (g_free (message), NULL);
707
SeahorseObject* seahorse_viewer_get_selected (SeahorseViewer* self) {
708
SeahorseObject* value;
709
g_object_get (G_OBJECT (self), "selected", &value, NULL);
711
g_object_unref (value);
717
static SeahorseObject* seahorse_viewer_real_get_selected (SeahorseViewer* self) {
718
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), NULL);
719
/* Must be overridden */
724
void seahorse_viewer_set_selected (SeahorseViewer* self, SeahorseObject* value) {
725
g_object_set (G_OBJECT (self), "selected", value, NULL);
729
static void seahorse_viewer_real_set_selected (SeahorseViewer* self, SeahorseObject* value) {
731
g_return_if_fail (SEAHORSE_IS_VIEWER (self));
733
objects = g_list_prepend (objects, value);
734
seahorse_viewer_set_selected_objects (self, objects);
735
(objects == NULL ? NULL : (objects = (g_list_free (objects), NULL)));
736
g_object_notify (((GObject *) (self)), "selected");
740
SeahorseSet* seahorse_viewer_get_current_set (SeahorseViewer* self) {
742
g_object_get (G_OBJECT (self), "current-set", &value, NULL);
744
g_object_unref (value);
750
static SeahorseSet* seahorse_viewer_real_get_current_set (SeahorseViewer* self) {
751
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), NULL);
752
/* Must be overridden */
757
static GtkWindow* seahorse_viewer_real_get_window (SeahorseViewer* self) {
758
g_return_val_if_fail (SEAHORSE_IS_VIEWER (self), NULL);
759
return GTK_WINDOW (seahorse_widget_get_toplevel (SEAHORSE_WIDGET (self)));
763
static void _seahorse_viewer_on_ui_add_widget_gtk_ui_manager_add_widget (GtkUIManager* _sender, GtkWidget* widget, gpointer self) {
764
seahorse_viewer_on_ui_add_widget (self, _sender, widget);
768
static void _seahorse_viewer_on_selection_changed_seahorse_view_selection_changed (SeahorseViewer* _sender, gpointer self) {
769
seahorse_viewer_on_selection_changed (self, _sender);
773
static GObject * seahorse_viewer_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
775
SeahorseViewerClass * klass;
776
GObjectClass * parent_class;
777
SeahorseViewer * self;
778
GError * inner_error;
779
klass = SEAHORSE_VIEWER_CLASS (g_type_class_peek (SEAHORSE_TYPE_VIEWER));
780
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
781
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
782
self = SEAHORSE_VIEWER (obj);
791
self->priv->_ui_manager = (_tmp0 = gtk_ui_manager_new (), (self->priv->_ui_manager == NULL ? NULL : (self->priv->_ui_manager = (g_object_unref (self->priv->_ui_manager), NULL))), _tmp0);
792
/* The widgts get added in an idle loop later */
793
g_signal_connect_object (self->priv->_ui_manager, "add-widget", ((GCallback) (_seahorse_viewer_on_ui_add_widget_gtk_ui_manager_add_widget)), self, 0);
796
path = g_strdup_printf ("%sseahorse-%s.ui", SEAHORSE_GLADEDIR, seahorse_widget_get_name (SEAHORSE_WIDGET (self)));
797
gtk_ui_manager_add_ui_from_file (self->priv->_ui_manager, path, &inner_error);
798
if (inner_error != NULL) {
799
goto __catch3_g_error;
801
path = (g_free (path), NULL);
810
g_warning ("seahorse-viewer.vala:70: couldn't load ui description for '%s': %s", seahorse_widget_get_name (SEAHORSE_WIDGET (self)), ex->message);
811
(ex == NULL ? NULL : (ex = (g_error_free (ex), NULL)));
817
win = (_tmp1 = seahorse_widget_get_toplevel (SEAHORSE_WIDGET (self)), (_tmp1 == NULL ? NULL : g_object_ref (_tmp1)));
818
if (G_TYPE_FROM_INSTANCE (G_OBJECT (win)) == GTK_TYPE_WINDOW) {
819
gtk_window_add_accel_group ((GTK_WINDOW (win)), gtk_ui_manager_get_accel_group (self->priv->_ui_manager));
821
seahorse_viewer_include_basic_actions (self);
822
g_signal_connect_object (SEAHORSE_VIEW (self), "selection-changed", ((GCallback) (_seahorse_viewer_on_selection_changed_seahorse_view_selection_changed)), self, 0);
823
/* Setup the commands */
825
self->priv->_commands = (_tmp2 = g_hash_table_new (g_direct_hash, g_direct_equal), (self->priv->_commands == NULL ? NULL : (self->priv->_commands = (g_hash_table_unref (self->priv->_commands), NULL))), _tmp2);
826
types = seahorse_registry_find_types (seahorse_registry_get (), "commands", NULL, NULL);
828
GList* typ_collection;
830
typ_collection = types;
831
for (typ_it = typ_collection; typ_it != NULL; typ_it = typ_it->next) {
833
typ = GPOINTER_TO_INT (typ_it->data);
835
SeahorseCommands* commands;
836
SeahorseCommands* _tmp3;
837
GtkActionGroup* _tmp4;
838
GtkActionGroup* actions;
841
/* Add each commands to our hash table */
842
commands = SEAHORSE_COMMANDS (g_object_new (typ, "view", self, NULL, NULL));
844
g_hash_table_insert (self->priv->_commands, GINT_TO_POINTER (seahorse_commands_get_ktype (commands)), (_tmp3 = commands, (_tmp3 == NULL ? NULL : g_object_ref (_tmp3))));
845
/* Add the UI for each commands */
847
actions = (_tmp4 = seahorse_commands_get_command_actions (commands), (_tmp4 == NULL ? NULL : g_object_ref (_tmp4)));
848
if (actions != NULL) {
849
seahorse_viewer_include_actions (self, actions);
852
uidef = (_tmp5 = seahorse_commands_get_ui_definition (commands), (_tmp5 == NULL ? NULL : g_strdup (_tmp5)));
853
if (uidef != NULL && g_utf8_strlen (uidef, -1) > 0) {
854
gtk_ui_manager_add_ui_from_string (self->priv->_ui_manager, uidef, ((glong) (-1)), &inner_error);
855
if (inner_error != NULL) {
856
g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
857
g_clear_error (&inner_error);
860
(commands == NULL ? NULL : (commands = (g_object_unref (commands), NULL)));
861
(actions == NULL ? NULL : (actions = (g_object_unref (actions), NULL)));
862
uidef = (g_free (uidef), NULL);
866
(win == NULL ? NULL : (win = (g_object_unref (win), NULL)));
867
(types == NULL ? NULL : (types = (g_list_free (types), NULL)));
873
static void seahorse_viewer_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
874
SeahorseViewer * self;
875
self = SEAHORSE_VIEWER (object);
876
switch (property_id) {
877
case SEAHORSE_VIEWER_SELECTED:
878
g_value_set_object (value, seahorse_viewer_real_get_selected (self));
880
case SEAHORSE_VIEWER_CURRENT_SET:
881
g_value_set_object (value, seahorse_viewer_real_get_current_set (self));
883
case SEAHORSE_VIEWER_WINDOW:
884
g_value_set_object (value, seahorse_viewer_real_get_window (self));
887
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
893
static void seahorse_viewer_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
894
SeahorseViewer * self;
895
self = SEAHORSE_VIEWER (object);
896
switch (property_id) {
897
case SEAHORSE_VIEWER_SELECTED:
898
seahorse_viewer_real_set_selected (self, g_value_get_object (value));
901
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
907
static void seahorse_viewer_class_init (SeahorseViewerClass * klass) {
908
seahorse_viewer_parent_class = g_type_class_peek_parent (klass);
909
g_type_class_add_private (klass, sizeof (SeahorseViewerPrivate));
910
G_OBJECT_CLASS (klass)->get_property = seahorse_viewer_get_property;
911
G_OBJECT_CLASS (klass)->set_property = seahorse_viewer_set_property;
912
G_OBJECT_CLASS (klass)->constructor = seahorse_viewer_constructor;
913
G_OBJECT_CLASS (klass)->dispose = seahorse_viewer_dispose;
914
SEAHORSE_VIEWER_CLASS (klass)->get_selected_objects = seahorse_viewer_real_get_selected_objects;
915
SEAHORSE_VIEWER_CLASS (klass)->set_selected_objects = seahorse_viewer_real_set_selected_objects;
916
SEAHORSE_VIEWER_CLASS (klass)->get_selected_object_and_uid = seahorse_viewer_real_get_selected_object_and_uid;
917
g_object_class_override_property (G_OBJECT_CLASS (klass), SEAHORSE_VIEWER_SELECTED, "selected");
918
g_object_class_override_property (G_OBJECT_CLASS (klass), SEAHORSE_VIEWER_CURRENT_SET, "current-set");
919
g_object_class_override_property (G_OBJECT_CLASS (klass), SEAHORSE_VIEWER_WINDOW, "window");
923
static void seahorse_viewer_seahorse_view_interface_init (SeahorseViewIface * iface) {
924
seahorse_viewer_seahorse_view_parent_iface = g_type_interface_peek_parent (iface);
925
iface->get_selected_objects = seahorse_viewer_get_selected_objects;
926
iface->set_selected_objects = seahorse_viewer_set_selected_objects;
930
static void seahorse_viewer_instance_init (SeahorseViewer * self) {
931
self->priv = SEAHORSE_VIEWER_GET_PRIVATE (self);
935
static void seahorse_viewer_dispose (GObject * obj) {
936
SeahorseViewer * self;
937
self = SEAHORSE_VIEWER (obj);
938
(self->priv->_ui_manager == NULL ? NULL : (self->priv->_ui_manager = (g_object_unref (self->priv->_ui_manager), NULL)));
939
(self->priv->_object_actions == NULL ? NULL : (self->priv->_object_actions = (g_object_unref (self->priv->_object_actions), NULL)));
940
(self->priv->_commands == NULL ? NULL : (self->priv->_commands = (g_hash_table_unref (self->priv->_commands), NULL)));
941
G_OBJECT_CLASS (seahorse_viewer_parent_class)->dispose (obj);
945
GType seahorse_viewer_get_type (void) {
946
static GType seahorse_viewer_type_id = 0;
947
if (G_UNLIKELY (seahorse_viewer_type_id == 0)) {
948
static const GTypeInfo g_define_type_info = { sizeof (SeahorseViewerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_viewer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseViewer), 0, (GInstanceInitFunc) seahorse_viewer_instance_init };
949
static const GInterfaceInfo seahorse_view_info = { (GInterfaceInitFunc) seahorse_viewer_seahorse_view_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
950
seahorse_viewer_type_id = g_type_register_static (SEAHORSE_TYPE_WIDGET, "SeahorseViewer", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
951
g_type_add_interface_static (seahorse_viewer_type_id, SEAHORSE_TYPE_VIEW, &seahorse_view_info);
953
return seahorse_viewer_type_id;
957
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
958
if (array != NULL && destroy_func != NULL) {
960
if (array_length >= 0)
961
for (i = 0; i < array_length; i = i + 1) {
962
if (((gpointer*) (array))[i] != NULL)
963
destroy_func (((gpointer*) (array))[i]);
966
for (i = 0; ((gpointer*) (array))[i] != NULL; i = i + 1) {
967
destroy_func (((gpointer*) (array))[i]);