[Gpa-commits] r925 - trunk/src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Dec 17 19:41:29 CET 2008
Author: werner
Date: 2008-12-17 19:41:28 +0100 (Wed, 17 Dec 2008)
New Revision: 925
Modified:
trunk/src/ChangeLog
trunk/src/cardman.c
trunk/src/gpacardreloadop.c
trunk/src/gpgmeedit.c
trunk/src/recipientdlg.c
Log:
Code cleanups.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2008-12-17 11:19:59 UTC (rev 924)
+++ trunk/src/ChangeLog 2008-12-17 18:41:28 UTC (rev 925)
@@ -1,3 +1,27 @@
+2008-12-17 Werner Koch <wk at g10code.com>
+
+ * cardman.c: Change layout of file.
+ (card_reload): Rename to card_reload_action. Change callers.
+ Factor code out to ...
+ (card_reload): New.
+ (card_genkey): Rename to card_reload_action. Change callers.
+ Factor code out to ...
+ (card_genkey): New.
+ (watcher_cb): Call card_reload direct.
+ (gpa_cardman_new): Remove.
+ (gpa_card_manager_get_instance): Create object directly.
+ (register_reload_operation): Remove and inline the code instead.
+
+ * gpgmeedit.c (EditAction): Rename to edit_action_t.
+ (EditTransit): Rename to edit_transit_t.
+ (edit_fnc): Remove superfluous use of gpg_err_code.
+ (ExpireState, TrustState, SignState, PasswdState, CardState): Make
+ them anonymous enums.
+ (gpa_gpgme_card_edit_list_parms_release): Rename to
+ card_edit_list_parms_release.
+
+ * gpacardreloadop.c: Change layout of file.
+
2008-12-16 Werner Koch <wk at g10code.com>
* cardman.c (_GpaCardManager): Add fields CARD_WIDGET and HAVE_CARD.
Modified: trunk/src/cardman.c
===================================================================
--- trunk/src/cardman.c 2008-12-17 11:19:59 UTC (rev 924)
+++ trunk/src/cardman.c 2008-12-17 18:41:28 UTC (rev 925)
@@ -76,7 +76,7 @@
int have_card; /* True, if a supported card is in the reader. */
gpa_filewatch_id_t watch; /* For watching the reader status file. */
- int in_watcher_cb; /* Sentinel for watcher_cb(). */
+ int in_card_reload; /* Sentinel for card_reload. */
};
struct _GpaCardManagerClass
@@ -98,102 +98,42 @@
typedef gboolean (*sensitivity_func_t)(gpointer);
#endif
+
/* Local prototypes */
-static void watcher_cb (void *opaque,
- const char *filename, const char *reason);
-static void update_title (GpaCardManager *cardman);
-static void update_info_visibility (GpaCardManager *cardman);
-static GObject *gpa_card_manager_constructor
- (GType type, guint n_construct_properties,
- GObjectConstructParam *construct_properties);
+
+/************************************************************
+ ******************* Implementation *********************
+ ************************************************************/
-/*
- * GtkWidget boilerplate.
- */
static void
-gpa_card_manager_finalize (GObject *object)
-{
- /* FIXME: Remove the watch object and all other resources. */
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-
-static void
-gpa_card_manager_init (GpaCardManager *cardman)
+update_title (GpaCardManager *cardman)
{
- char *fname;
+ const char *title = _("GNU Privacy Assistant - Card Manager");
- fname = g_build_filename (gnupg_homedir, "reader_0.status", NULL);
- cardman->watch = gpa_add_filewatch (fname, "c", watcher_cb, cardman);
- xfree (fname);
-}
-
-static void
-gpa_card_manager_class_init (GpaCardManagerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->constructor = gpa_card_manager_constructor;
- object_class->finalize = gpa_card_manager_finalize;
-}
-
-GType
-gpa_card_manager_get_type (void)
-{
- static GType cardman_type = 0;
-
- if (!cardman_type)
+ if (cardman->have_card)
+ gtk_window_set_title (GTK_WINDOW (cardman), title);
+ else
{
- static const GTypeInfo cardman_info =
- {
- sizeof (GpaCardManagerClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gpa_card_manager_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GpaCardManager),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gpa_card_manager_init,
- };
+ char *tmp;
- cardman_type = g_type_register_static (GTK_TYPE_WINDOW,
- "GpaCardManager",
- &cardman_info, 0);
+ tmp = g_strdup_printf ("%s (%s)", title, _("no card"));
+ gtk_window_set_title (GTK_WINDOW (cardman), tmp);
+ xfree (tmp);
}
-
- return cardman_type;
}
-
static void
-watcher_cb (void *opaque, const char *filename, const char *reason)
+update_info_visibility (GpaCardManager *cardman)
{
- GpaCardManager *cardman = opaque;
-
- if (cardman && !cardman->in_watcher_cb && strchr (reason, 'c') )
- {
- cardman->in_watcher_cb++;
- gtk_action_activate (gtk_ui_manager_get_action
- (cardman->ui_manager, "/MainMenu/Card/CardReload"));
- cardman->in_watcher_cb--;
- }
+ if (cardman->have_card)
+ gtk_widget_show_all (cardman->card_widget);
+ else
+ gtk_widget_hide_all (cardman->card_widget);
}
-static void
-register_reload_operation (GpaCardManager *cardman, GpaCardReloadOperation *op)
-{
- /* FIXME: is this correct? -mo */
- g_signal_connect (G_OBJECT (op), "completed",
- G_CALLBACK (g_object_unref), cardman);
-}
-
/* This is the callback used by the GpaCardReloadOp object. It's
called for each data item during a reload operation and updates the
according widgets. */
@@ -263,18 +203,41 @@
gtk_entry_set_text (GTK_ENTRY (cardman->entryKeyAuth), string);
}
+
+/* This function is called to trigger a card-reload. */
+static void
+card_reload (GpaCardManager *cardman)
+{
+ GpaCardReloadOperation *op;
+
+ if (!cardman->in_card_reload)
+ {
+ cardman->in_card_reload++;
+ op = gpa_card_reload_operation_new (cardman->window,
+ card_reload_cb, cardman);
+ g_signal_connect (G_OBJECT (op), "completed",
+ G_CALLBACK (g_object_unref), cardman);
+
+ /* Fixme: We should decrement the sentinel only after finishing
+ the operation, so that we don't run them over and over if the
+ user clicks too often. Note however that the primary reason
+ for this sentinel is to avoid concurrent reloads triggered by
+ the user and by the file watcher. */
+ cardman->in_card_reload--;
+ }
+}
+
+
/* This function is called when the user triggers a card-reload. */
static void
-card_reload (GtkAction *action, gpointer param)
+card_reload_action (GtkAction *action, gpointer param)
{
GpaCardManager *cardman = param;
- GpaCardReloadOperation *op;
- op = gpa_card_reload_operation_new (cardman->window,
- card_reload_cb, cardman);
- register_reload_operation (cardman, GPA_CARD_RELOAD_OPERATION (op));
+ card_reload (cardman);
}
+
#if 0
/* This function is called when the user triggers a card-reload. */
static void
@@ -288,17 +251,38 @@
}
#endif
-/* This function is called when the user triggers a key-generation. */
+/* This function is called to triggers a key-generation. */
static void
-card_genkey (GtkAction *action, gpointer param)
+card_genkey (GpaCardManager *cardman)
{
- GpaCardManager *cardman = param;
GpaGenKeyCardOperation *op;
op = gpa_gen_key_card_operation_new (cardman->window);
- register_reload_operation (cardman, GPA_GEN_KEY_OPERATION (op));
+ g_signal_connect (G_OBJECT (op), "completed",
+ G_CALLBACK (g_object_unref), cardman);
}
+
+/* This function is called when the user triggers a key-generation. */
+static void
+card_genkey_action (GtkAction *action, gpointer param)
+{
+ GpaCardManager *cardman = param;
+
+ card_genkey (cardman);
+}
+
+
+static void
+watcher_cb (void *opaque, const char *filename, const char *reason)
+{
+ GpaCardManager *cardman = opaque;
+
+ if (cardman && strchr (reason, 'c') )
+ card_reload (cardman);
+}
+
+
/* Construct the card manager menu and toolbar widgets and return
them. */
static void
@@ -317,14 +301,14 @@
/* Card menu. */
{ "CardReload", GTK_STOCK_REFRESH, NULL, NULL,
- N_("Reload card information"), G_CALLBACK (card_reload) },
+ N_("Reload card information"), G_CALLBACK (card_reload_action) },
#if 0
/* FIXME: not yet implemented. */
{ "CardEdit", GTK_STOCK_EDIT, NULL, NULL,
N_("Edit card information"), G_CALLBACK (card_edit) },
#endif
{ "CardGenkey", GTK_STOCK_NEW, "Generate new key...", NULL,
- N_("Generate new key on card"), G_CALLBACK (card_genkey) },
+ N_("Generate new key on card"), G_CALLBACK (card_genkey_action) },
};
static const char *ui_description =
@@ -408,7 +392,6 @@
gpa_toolbar_set_homogeneous (GTK_TOOLBAR (*toolbar), FALSE);
}
-
/* Callback for the destroy signal. */
static void
@@ -418,33 +401,6 @@
}
-static void
-update_title (GpaCardManager *cardman)
-{
- const char *title = _("GNU Privacy Assistant - Card Manager");
-
- if (cardman->have_card)
- gtk_window_set_title (GTK_WINDOW (cardman), title);
- else
- {
- char *tmp;
-
- tmp = g_strdup_printf ("%s (%s)", title, _("no card"));
- gtk_window_set_title (GTK_WINDOW (cardman), tmp);
- xfree (tmp);
- }
-}
-
-static void
-update_info_visibility (GpaCardManager *cardman)
-{
- if (cardman->have_card)
- gtk_widget_show_all (cardman->card_widget);
- else
- gtk_widget_hide_all (cardman->card_widget);
-}
-
-
/* This function constructs the container holding the card "form". It
updates CARDMAN with new references to the entry widgets, etc. */
static GtkWidget *
@@ -525,6 +481,32 @@
return table;
}
+
+
+
+/************************************************************
+ ****************** Object Management ********************
+ ************************************************************/
+
+static void
+gpa_card_manager_finalize (GObject *object)
+{
+ /* FIXME: Remove the watch object and all other resources. */
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gpa_card_manager_init (GpaCardManager *cardman)
+{
+ char *fname;
+
+ fname = g_build_filename (gnupg_homedir, "reader_0.status", NULL);
+ cardman->watch = gpa_add_filewatch (fname, "c", watcher_cb, cardman);
+ xfree (fname);
+}
+
/* Construct a new class object of GpaCardManager. */
static GObject*
gpa_card_manager_constructor (GType type,
@@ -607,36 +589,65 @@
return object;
}
-static GpaCardManager *
-gpa_cardman_new (void)
+
+static void
+gpa_card_manager_class_init (GpaCardManagerClass *klass)
{
- GpaCardManager *cardman;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->constructor = gpa_card_manager_constructor;
+ object_class->finalize = gpa_card_manager_finalize;
+}
- cardman = g_object_new (GPA_CARD_MANAGER_TYPE, NULL);
- gtk_action_activate (gtk_ui_manager_get_action
- (cardman->ui_manager, "/MainMenu/Card/CardReload"));
-#if 0
- /* ? */
- update_selection_sensitive_actions (cardman);
-#endif
-
- return cardman;
+GType
+gpa_card_manager_get_type (void)
+{
+ static GType this_type = 0;
+
+ if (!this_type)
+ {
+ static const GTypeInfo this_info =
+ {
+ sizeof (GpaCardManagerClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gpa_card_manager_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GpaCardManager),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) gpa_card_manager_init,
+ };
+
+ this_type = g_type_register_static (GTK_TYPE_WINDOW,
+ "GpaCardManager",
+ &this_info, 0);
+ }
+
+ return this_type;
}
-/* API */
-
+
+/************************************************************
+ ********************** Public API ************************
+ ************************************************************/
GtkWidget *
gpa_card_manager_get_instance (void)
{
if (!instance)
- instance = gpa_cardman_new ();
+ {
+ instance = g_object_new (GPA_CARD_MANAGER_TYPE, NULL);
+ card_reload (instance);
+ }
return GTK_WIDGET (instance);
}
-gboolean gpa_card_manager_is_open (void)
+
+gboolean
+gpa_card_manager_is_open (void)
{
return (instance != NULL);
}
-
-/* EOF */
Modified: trunk/src/gpacardreloadop.c
===================================================================
--- trunk/src/gpacardreloadop.c 2008-12-17 11:19:59 UTC (rev 924)
+++ trunk/src/gpacardreloadop.c 2008-12-17 18:41:28 UTC (rev 925)
@@ -26,10 +26,13 @@
#include "gpa.h"
#include "gtktools.h"
+#include "gpgmeedit.h"
+
#include "gpaoperation.h"
#include "gpacardreloadop.h"
+/* Definition of the object. */
struct _GpaCardReloadOperation
{
GpaOperation parent;
@@ -39,28 +42,16 @@
gpgme_data_t gpgme_output;
};
+/* Definition of the object's class. */
struct _GpaCardReloadOperationClass
{
GpaOperationClass parent_class;
};
+/* The parent class. */
+static GObjectClass *parent_class;
-static GObjectClass *parent_class = NULL;
-
-static void gpa_card_reload_operation_done_cb (GpaContext *context,
- gpg_error_t err,
- GpaCardReloadOperation *op);
-
-static void gpa_card_reload_operation_done_error_cb (GpaContext *context,
- gpg_error_t err,
- GpaCardReloadOperation *op);
-
-/* We do all the work in the idle loop. */
-static gboolean gpa_card_reload_operation_idle_cb (gpointer data);
-
-/* GObject boilerplate */
-
-/* Properties of our object. */
+/* Identifiers for the properties of our class. */
enum
{
PROP_0,
@@ -68,178 +59,17 @@
PROP_CARD_RELOAD_CB_OPAQUE
};
-static void
-gpa_card_reload_operation_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object);
- switch (prop_id)
- {
- case PROP_CARD_RELOAD_CB:
- g_value_set_pointer (value, op->card_reload_cb);
- break;
- case PROP_CARD_RELOAD_CB_OPAQUE:
- g_value_set_pointer (value, op->card_reload_cb_opaque);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-static void
-gpa_card_reload_operation_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object);
- gpa_card_reload_cb_t cb;
+/* Local prototypes. */
- switch (prop_id)
- {
- case PROP_CARD_RELOAD_CB:
- cb = (gpa_card_reload_cb_t) g_value_get_pointer (value);
- op->card_reload_cb = cb;
- break;
- case PROP_CARD_RELOAD_CB_OPAQUE:
- op->card_reload_cb_opaque = g_value_get_pointer (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-static void
-gpa_card_reload_operation_init (GpaCardReloadOperation *op)
-{
- gpgme_data_t gpgme_output;
- gpg_error_t err;
- /* Create a new GPGME data handle into which the GPGME output during
- the card-list operation is written. */
- gpgme_output = NULL;
- err = gpgme_data_new (&gpgme_output);
- if (err)
- gpa_gpgme_warning (err);
+
+/************************************************************
+ ******************* Implementation *********************
+ ************************************************************/
- op->card_reload_cb = NULL;
- op->card_reload_cb_opaque = NULL;
- op->gpgme_output = gpgme_output;
-}
-
-static void
-gpa_card_reload_operation_finalize (GObject *object)
-{
- /* GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object); */
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static GObject*
-gpa_card_reload_operation_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
-{
- GObject *object;
- GpaCardReloadOperation *op;
-
- /* Invoke parent's constructor */
- object = parent_class->constructor (type,
- n_construct_properties,
- construct_properties);
- op = GPA_CARD_RELOAD_OPERATION (object);
-
- /* Connect to the "done" signal */
- g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
- G_CALLBACK (gpa_card_reload_operation_done_error_cb), op);
- g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
- G_CALLBACK (gpa_card_reload_operation_done_cb), op);
-
- /* Begin working when we are back into the main loop */
- g_idle_add (gpa_card_reload_operation_idle_cb, op);
-
- return object;
-}
-
-static void
-gpa_card_reload_operation_class_init (GpaCardReloadOperationClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class->constructor = gpa_card_reload_operation_constructor;
- object_class->finalize = gpa_card_reload_operation_finalize;
- object_class->set_property = gpa_card_reload_operation_set_property;
- object_class->get_property = gpa_card_reload_operation_get_property;
-
- /* Properties */
- g_object_class_install_property (object_class,
- PROP_CARD_RELOAD_CB,
- g_param_spec_pointer
- ("card_reload_cb", "card_reload_cb",
- "card_reload_cb",
- G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class,
- PROP_CARD_RELOAD_CB_OPAQUE,
- g_param_spec_pointer
- ("card_reload_cb_opaque", "card_reload_cb_opaque",
- "card_reload_cb_opaque",
- G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
-}
-
-GType
-gpa_card_reload_operation_get_type (void)
-{
- static GType operation_type = 0;
-
- if (!operation_type)
- {
- static const GTypeInfo operation_info =
- {
- sizeof (GpaCardReloadOperationClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gpa_card_reload_operation_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GpaCardReloadOperation),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gpa_card_reload_operation_init,
- };
-
- operation_type = g_type_register_static (GPA_OPERATION_TYPE,
- "GpaCardReloadOperation",
- &operation_info, 0);
- }
-
- return operation_type;
-}
-
-/* API */
-
-GpaCardReloadOperation *
-gpa_card_reload_operation_new (GtkWidget *window, gpa_card_reload_cb_t cb, void *opaque)
-{
- GpaCardReloadOperation *op;
-
- op = g_object_new (GPA_CARD_RELOAD_OPERATION_TYPE,
- "window", window,
- "card_reload_cb", cb,
- "card_reload_cb_opaque", opaque,
- NULL);
-
- return op;
-}
-
-
-/* Internal */
-
/* Called during idle loop; triggers the actual GPGME card-list
operation. */
static gboolean
@@ -362,3 +192,184 @@
break;
}
}
+
+
+
+/************************************************************
+ ****************** Object Management ********************
+ ************************************************************/
+
+static void
+gpa_card_reload_operation_get_property
+ (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object);
+
+ switch (prop_id)
+ {
+ case PROP_CARD_RELOAD_CB:
+ g_value_set_pointer (value, op->card_reload_cb);
+ break;
+ case PROP_CARD_RELOAD_CB_OPAQUE:
+ g_value_set_pointer (value, op->card_reload_cb_opaque);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+gpa_card_reload_operation_set_property
+ (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object);
+ gpa_card_reload_cb_t cb;
+
+ switch (prop_id)
+ {
+ case PROP_CARD_RELOAD_CB:
+ cb = (gpa_card_reload_cb_t) g_value_get_pointer (value);
+ op->card_reload_cb = cb;
+ break;
+ case PROP_CARD_RELOAD_CB_OPAQUE:
+ op->card_reload_cb_opaque = g_value_get_pointer (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+gpa_card_reload_operation_finalize (GObject *object)
+{
+ /* GpaCardReloadOperation *op = GPA_CARD_RELOAD_OPERATION (object); */
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void
+gpa_card_reload_operation_init (GpaCardReloadOperation *op)
+{
+ gpgme_data_t gpgme_output;
+ gpg_error_t err;
+
+ /* Create a new GPGME data handle into which the GPGME output during
+ the card-list operation is written. */
+ gpgme_output = NULL;
+ err = gpgme_data_new (&gpgme_output);
+ if (err)
+ gpa_gpgme_warning (err);
+
+ op->card_reload_cb = NULL;
+ op->card_reload_cb_opaque = NULL;
+ op->gpgme_output = gpgme_output;
+}
+
+
+static GObject*
+gpa_card_reload_operation_constructor
+ (GType type, guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GObject *object;
+ GpaCardReloadOperation *op;
+
+ /* Invoke parent's constructor. */
+ object = parent_class->constructor (type,
+ n_construct_properties,
+ construct_properties);
+ op = GPA_CARD_RELOAD_OPERATION (object);
+
+ /* Connect to the "done" signal. */
+ g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
+ G_CALLBACK (gpa_card_reload_operation_done_error_cb), op);
+ g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
+ G_CALLBACK (gpa_card_reload_operation_done_cb), op);
+
+ /* Begin working when we are back into the main loop. */
+ g_idle_add (gpa_card_reload_operation_idle_cb, op);
+
+ return object;
+}
+
+
+static void
+gpa_card_reload_operation_class_init (GpaCardReloadOperationClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = gpa_card_reload_operation_finalize;
+ object_class->constructor = gpa_card_reload_operation_constructor;
+ object_class->set_property = gpa_card_reload_operation_set_property;
+ object_class->get_property = gpa_card_reload_operation_get_property;
+
+ /* Install properties. */
+ g_object_class_install_property
+ (object_class, PROP_CARD_RELOAD_CB,
+ g_param_spec_pointer ("card_reload_cb", "card_reload_cb",
+ "card_reload_cb",
+ G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property
+ (object_class, PROP_CARD_RELOAD_CB_OPAQUE,
+ g_param_spec_pointer ("card_reload_cb_opaque", "card_reload_cb_opaque",
+ "card_reload_cb_opaque",
+ G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+}
+
+
+GType
+gpa_card_reload_operation_get_type (void)
+{
+ static GType this_type = 0;
+
+ if (!this_type)
+ {
+ static const GTypeInfo this_info =
+ {
+ sizeof (GpaCardReloadOperationClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gpa_card_reload_operation_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GpaCardReloadOperation),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) gpa_card_reload_operation_init,
+ };
+
+ this_type = g_type_register_static (GPA_OPERATION_TYPE,
+ "GpaCardReloadOperation",
+ &this_info, 0);
+ }
+
+ return this_type;
+}
+
+
+
+/************************************************************
+ ********************** Public API ************************
+ ************************************************************/
+
+GpaCardReloadOperation *
+gpa_card_reload_operation_new (GtkWidget *window,
+ gpa_card_reload_cb_t cb, void *opaque)
+{
+ GpaCardReloadOperation *op;
+
+ op = g_object_new (GPA_CARD_RELOAD_OPERATION_TYPE,
+ "window", window,
+ "card_reload_cb", cb,
+ "card_reload_cb_opaque", opaque,
+ NULL);
+
+ return op;
+}
Modified: trunk/src/gpgmeedit.c
===================================================================
--- trunk/src/gpgmeedit.c 2008-12-17 11:19:59 UTC (rev 924)
+++ trunk/src/gpgmeedit.c 2008-12-17 18:41:28 UTC (rev 925)
@@ -1,24 +1,26 @@
/* gpgmetools.c - The GNU Privacy Assistant
- * Copyright (C) 2002, Miguel Coca.
+ * Copyright (C) 2002 Miguel Coca.
+ * Copyright (C) 2008 g10 Code GmbH.
*
* This file is part of GPA
*
- * GPA is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * GPA is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
- * GPA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GPA is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
#include "gpgmeedit.h"
#include "passwddlg.h"
@@ -44,35 +46,123 @@
/* Prototype of the action function. Returns the error if there is one */
-typedef gpg_error_t (*EditAction) (int state, void *opaque,
- char **result);
+typedef gpg_error_t (*edit_action_t) (int state, void *opaque,
+ char **result);
/* Prototype of the transit function. Returns the next state. If and error
* is found changes *err. If there is no error it should NOT touch it */
-typedef int (*EditTransit) (int current_state, gpgme_status_code_t status,
- const char *args, void *opaque, gpg_error_t *err);
+typedef int (*edit_transit_t) (int current_state, gpgme_status_code_t status,
+ const char *args, void *opaque,
+ gpg_error_t *err);
+/* States for the edit expire command. */
+enum
+ {
+ EXPIRE_START,
+ EXPIRE_COMMAND,
+ EXPIRE_DATE,
+ EXPIRE_QUIT,
+ EXPIRE_SAVE,
+ EXPIRE_ERROR
+ };
+
+
+/* States for the edit trust command. */
+enum
+ {
+ TRUST_START,
+ TRUST_COMMAND,
+ TRUST_VALUE,
+ TRUST_REALLY_ULTIMATE,
+ TRUST_QUIT,
+ TRUST_SAVE,
+ TRUST_ERROR
+ };
+
+
+/* States for the sign command. */
+enum
+ {
+ SIGN_START,
+ SIGN_COMMAND,
+ SIGN_UIDS,
+ SIGN_SET_EXPIRE,
+ SIGN_SET_CHECK_LEVEL,
+ SIGN_CONFIRM,
+ SIGN_QUIT,
+ SIGN_SAVE,
+ SIGN_ERROR
+ };
+
+/* Parameter for the sign command. */
+struct sign_parms_s
+{
+ gchar *check_level;
+ gboolean local;
+};
+
+
+/* States for the passwd command. */
+enum
+ {
+ PASSWD_START,
+ PASSWD_COMMAND,
+ PASSWD_ENTERNEW,
+ PASSWD_QUIT,
+ PASSWD_SAVE,
+ PASSWD_ERROR
+ };
+
+/* Parameter for the passwd command. */
+struct passwd_parms_s
+{
+ gpgme_passphrase_cb_t func;
+ void *opaque;
+};
+
+
+/* States for card related commands. */
+enum
+ {
+ CARD_START,
+ CARD_COMMAND,
+ CARD_ADMIN_COMMAND,
+ CARD_QUIT,
+ CARD_QUERY_LOGIN,
+ CARD_ERROR
+ };
+
+
+
+
/* Data to be passed to the edit callback. Must be filled by the caller of
* gpgme_op_edit() */
struct edit_parms_s
{
/* Current state */
int state;
+
/* Last error: The return code of gpgme_op_edit() is the return value of
* the last invocation of the callback. But returning an error from the
* callback does not abort the edit operation, so we must remember any
* error. In other words, errors from action() or transit() are sticky.
*/
gpg_error_t err;
+
/* The action function */
- EditAction action;
+ edit_action_t action;
+
/* The transit function */
- EditTransit transit;
+ edit_transit_t transit;
+
/* The output data object */
gpgme_data_t out;
+
/* Signal attachment id */
gulong signal_id;
+
/* Data to be passed to the previous functions */
void *opaque;
+
/* The passwd dialog needs to see GPGME_STATUS_NEED_PASSPHRASE_SYM.
To make thinks easier it is only passed to the FSM if this flag
has been set. */
@@ -113,19 +203,19 @@
/* Choose the next state based on the current one and the input */
parms->state = parms->transit (parms->state, status, args, parms->opaque,
&parms->err);
- if (gpg_err_code (parms->err) == GPG_ERR_NO_ERROR)
+ if (!parms->err)
{
gpg_error_t err;
+
/* Choose the action based on the state */
err = parms->action (parms->state, parms->opaque, &result);
#if DEBUG_FSM
g_debug ("edit_fnc: newstate=%d err=%s result=%s",
parms->state, gpg_strerror (err), result);
#endif
- if (gpg_err_code (err) != GPG_ERR_NO_ERROR)
- {
- parms->err = err;
- }
+ if (err)
+ parms->err = err;
+
/* Send the command, if any was provided */
if (result)
{
@@ -145,22 +235,12 @@
}
-/* Change expiry time */
-
-typedef enum
-{
- EXPIRE_START,
- EXPIRE_COMMAND,
- EXPIRE_DATE,
- EXPIRE_QUIT,
- EXPIRE_SAVE,
- EXPIRE_ERROR
-} ExpireState;
-
+
+/* Change expiry time: action. */
static gpg_error_t
edit_expire_fnc_action (int state, void *opaque, char **result)
{
- gchar *date = opaque;
+ char *date = opaque;
switch (state)
{
@@ -187,9 +267,11 @@
default:
return gpg_error (GPG_ERR_GENERAL);
}
- return gpg_error (GPG_ERR_NO_ERROR);
+ return 0;
}
+
+/* Change expiry time: transit. */
static int
edit_expire_fnc_transit (int current_state, gpgme_status_code_t status,
const char *args, void *opaque, gpg_error_t *err)
@@ -272,19 +354,8 @@
}
-/* Change the key ownertrust */
-
-typedef enum
-{
- TRUST_START,
- TRUST_COMMAND,
- TRUST_VALUE,
- TRUST_REALLY_ULTIMATE,
- TRUST_QUIT,
- TRUST_SAVE,
- TRUST_ERROR
-} TrustState;
-
+
+/* Change the key ownertrust: action. */
static gpg_error_t
edit_trust_fnc_action (int state, void *opaque, char **result)
{
@@ -322,6 +393,7 @@
return gpg_error (GPG_ERR_NO_ERROR);
}
+/* Change the key ownertrust: transit. */
static int
edit_trust_fnc_transit (int current_state, gpgme_status_code_t status,
const char *args, void *opaque, gpg_error_t *err)
@@ -416,27 +488,9 @@
}
-/* Sign a key */
-typedef enum
-{
- SIGN_START,
- SIGN_COMMAND,
- SIGN_UIDS,
- SIGN_SET_EXPIRE,
- SIGN_SET_CHECK_LEVEL,
- SIGN_CONFIRM,
- SIGN_QUIT,
- SIGN_SAVE,
- SIGN_ERROR
-} SignState;
-
-struct sign_parms_s
-{
- gchar *check_level;
- gboolean local;
-};
-
+
+/* Sign a key: action. */
static gpg_error_t
edit_sign_fnc_action (int state, void *opaque, char **result)
{
@@ -482,6 +536,8 @@
return gpg_error (GPG_ERR_NO_ERROR);
}
+
+/* Sign a key: transit. */
static int
edit_sign_fnc_transit (int current_state, gpgme_status_code_t status,
const char *args, void *opaque, gpg_error_t *err)
@@ -641,24 +697,8 @@
return next_state;
}
-/* Change passphrase */
-
-typedef enum
-{
- PASSWD_START,
- PASSWD_COMMAND,
- PASSWD_ENTERNEW,
- PASSWD_QUIT,
- PASSWD_SAVE,
- PASSWD_ERROR
-} PasswdState;
-
-struct passwd_parms_s
-{
- gpgme_passphrase_cb_t func;
- void *opaque;
-};
-
+
+/* Change passphrase: action. */
static gpg_error_t
edit_passwd_fnc_action (int state, void *opaque, char **result)
{
@@ -690,6 +730,7 @@
return gpg_error (GPG_ERR_NO_ERROR);
}
+/* Change passphrase: transit. */
static int
edit_passwd_fnc_transit (int current_state, gpgme_status_code_t status,
const char *args, void *opaque, gpg_error_t *err)
@@ -758,9 +799,9 @@
return next_state;
}
-/* Release the edit parameters needed for setting owner trust. The prototype
- * is that of a GpaContext's "done" signal handler.
- */
+
+/* Release the edit parameters needed for setting owner trust. The
+ prototype is that of a GpaContext's "done" signal handler. */
static void
gpa_gpgme_edit_trust_parms_release (GpaContext *ctx, gpg_error_t err,
struct edit_parms_s* parms)
@@ -775,8 +816,8 @@
g_free (parms);
}
-/* Generate the edit parameters needed for setting owner trust.
- */
+
+/* Generate the edit parameters needed for setting owner trust. */
static struct edit_parms_s*
gpa_gpgme_edit_trust_parms_new (GpaContext *ctx, const char *trust_string,
gpgme_data_t out)
@@ -800,9 +841,11 @@
return edit_parms;
}
+
/* Change the ownertrust of a key */
-gpg_error_t gpa_gpgme_edit_trust_start (GpaContext *ctx, gpgme_key_t key,
- gpgme_validity_t ownertrust)
+gpg_error_t
+gpa_gpgme_edit_trust_start (GpaContext *ctx, gpgme_key_t key,
+ gpgme_validity_t ownertrust)
{
const gchar *trust_strings[] = {"1", "1", "2", "3", "4", "5"};
struct edit_parms_s *parms = NULL;
@@ -819,9 +862,9 @@
return err;
}
+
/* Release the edit parameters needed for changing the expiry date. The
- * prototype is that of a GpaContext's "done" signal handler.
- */
+ prototype is that of a GpaContext's "done" signal handler. */
static void
gpa_gpgme_edit_expire_parms_release (GpaContext *ctx, gpg_error_t err,
struct edit_parms_s* parms)
@@ -836,8 +879,8 @@
g_free (parms);
}
-/* Generate the edit parameters needed for changing the expiry date.
- */
+
+/* Generate the edit parameters needed for changing the expiry date. */
static struct edit_parms_s*
gpa_gpgme_edit_expire_parms_new (GpaContext *ctx, GDate *date,
gpgme_data_t out)
@@ -873,9 +916,10 @@
return edit_parms;
}
-/* Change the expire date of a key */
-gpg_error_t gpa_gpgme_edit_expire_start (GpaContext *ctx, gpgme_key_t key,
- GDate *date)
+
+/* Change the expire date of a key. */
+gpg_error_t
+gpa_gpgme_edit_expire_start (GpaContext *ctx, gpgme_key_t key, GDate *date)
{
struct edit_parms_s *parms;
gpg_error_t err;
@@ -892,9 +936,9 @@
return err;
}
+
/* Release the edit parameters needed for signing. The prototype is that of
- * a GpaContext's "done" signal handler.
- */
+ a GpaContext's "done" signal handler. */
static void
gpa_gpgme_edit_sign_parms_release (GpaContext *ctx, gpg_error_t err,
struct edit_parms_s* parms)
@@ -908,8 +952,8 @@
g_free (parms);
}
-/* Generate the edit parameters needed for signing
- */
+
+/* Generate the edit parameters needed for signing. */
static struct edit_parms_s*
gpa_gpgme_edit_sign_parms_new (GpaContext *ctx, char *check_level,
gboolean local, gpgme_data_t out)
@@ -936,9 +980,11 @@
return edit_parms;
}
-/* Sign this key with the given private key */
-gpg_error_t gpa_gpgme_edit_sign_start (GpaContext *ctx, gpgme_key_t key,
- gpgme_key_t secret_key, gboolean local)
+
+/* Sign this key with the given private key. */
+gpg_error_t
+gpa_gpgme_edit_sign_start (GpaContext *ctx, gpgme_key_t key,
+ gpgme_key_t secret_key, gboolean local)
{
struct edit_parms_s *parms = NULL;
gpg_error_t err = gpg_error (GPG_ERR_NO_ERROR);
@@ -1070,20 +1116,12 @@
return err;
}
+
+
/*
* Card related code.
*/
-typedef enum
- {
- CARD_START,
- CARD_COMMAND,
- CARD_ADMIN_COMMAND,
- CARD_QUIT,
- CARD_QUERY_LOGIN,
- CARD_ERROR
- } CardState;
-
/* Implementation of the card-list operation. */
/* Action function for card-list. */
@@ -1115,14 +1153,19 @@
{
case CARD_START:
if (status == GPGME_STATUS_CARDCTRL)
- /* Consume GPGME_STATUS_CARDCTRL and stay in CARD_START state. */
- next_state = CARD_START;
+ {
+ /* Consume GPGME_STATUS_CARDCTRL and stay in CARD_START state. */
+ next_state = CARD_START;
+ }
else if (status == GPGME_STATUS_GET_LINE)
next_state = CARD_COMMAND;
+ else
+ goto bailout;
break;
case CARD_COMMAND:
next_state = CARD_QUIT;
break;
+ bailout:
default:
next_state = CARD_ERROR;
*err = gpg_error (GPG_ERR_GENERAL);
@@ -1132,8 +1175,8 @@
}
static void
-gpa_gpgme_card_edit_list_parms_release (GpaContext *ctx, gpg_error_t err,
- struct edit_parms_s *parms)
+card_edit_list_parms_release (GpaContext *ctx, gpg_error_t err,
+ struct edit_parms_s *parms)
{
/* FIXME: is this correct? -mo */
@@ -1157,15 +1200,17 @@
parms->transit = card_edit_list_fnc_transit;
parms->out = out;
parms->opaque = NULL;
- parms->signal_id = g_signal_connect (G_OBJECT (ctx), "done",
- G_CALLBACK (gpa_gpgme_card_edit_list_parms_release),
- parms);
+ parms->signal_id =
+ g_signal_connect (G_OBJECT (ctx), "done",
+ G_CALLBACK (card_edit_list_parms_release),
+ parms);
err = gpgme_op_card_edit_start (ctx->ctx, NULL, edit_fnc, parms, out);
return err;
}
+
#if 0 /* DISABLED */
/* Modify. */
Modified: trunk/src/recipientdlg.c
===================================================================
--- trunk/src/recipientdlg.c 2008-12-17 11:19:59 UTC (rev 924)
+++ trunk/src/recipientdlg.c 2008-12-17 18:41:28 UTC (rev 925)
@@ -84,7 +84,7 @@
#define TRUNCATE_KEYSEARCH_AT 40
-/* Na object to keep information about keys. */
+/* An object to keep information about keys. */
struct keyinfo_s
{
/* An array with associated key(s) or NULL if none found/selected. */
More information about the Gpa-commits
mailing list