[evolution] evolution-addressbook-export: Make ActionContext a struct.



commit 4d1bf133ce8dd5d46a010f96031d57cb3cb8e9cb
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Feb 25 15:23:49 2013 -0500

    evolution-addressbook-export: Make ActionContext a struct.
    
    Defining this as a union makes the code needlessly verbose.

 .../evolution-addressbook-export-list-cards.c      |   18 +++++++-------
 .../evolution-addressbook-export-list-folders.c    |    4 +-
 addressbook/tools/evolution-addressbook-export.c   |   14 +++++-----
 addressbook/tools/evolution-addressbook-export.h   |   26 +++++--------------
 4 files changed, 25 insertions(+), 37 deletions(-)
---
diff --git a/addressbook/tools/evolution-addressbook-export-list-cards.c 
b/addressbook/tools/evolution-addressbook-export-list-cards.c
index 89fd758..a884e6e 100644
--- a/addressbook/tools/evolution-addressbook-export-list-cards.c
+++ b/addressbook/tools/evolution-addressbook-export-list-cards.c
@@ -612,29 +612,29 @@ action_list_cards (GSList *contacts,
        length = g_slist_length (contacts);
 
        if (length <= 0) {
-               g_warning ("Couldn't load addressbook correctly!!!! %s####", 
p_actctx->action_list_cards.addressbook_source_uid ?
-                               p_actctx->action_list_cards.addressbook_source_uid : "NULL");
+               g_warning ("Couldn't load addressbook correctly!!!! %s####", p_actctx->addressbook_source_uid 
?
+                               p_actctx->addressbook_source_uid : "NULL");
                exit (-1);
        }
 
-       if (p_actctx->action_list_cards.output_file == NULL) {
+       if (p_actctx->output_file == NULL) {
                outputfile = stdout;
        } else {
                /* fopen output file */
-               if (!(outputfile = g_fopen (p_actctx->action_list_cards.output_file, "w"))) {
+               if (!(outputfile = g_fopen (p_actctx->output_file, "w"))) {
                        g_warning (_("Can not open file"));
                        exit (-1);
                }
        }
 
-       if (p_actctx->action_list_cards.IsVCard == TRUE)
+       if (p_actctx->IsVCard == TRUE)
                format = CARD_FORMAT_VCARD;
        else
                format = CARD_FORMAT_CSV;
 
        output_n_cards_file (outputfile, contacts, length, 0, format);
 
-       if (p_actctx->action_list_cards.output_file != NULL) {
+       if (p_actctx->output_file != NULL) {
                fclose (outputfile);
        }
 }
@@ -703,7 +703,7 @@ action_list_cards_init (ESourceRegistry *registry,
 
        g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FAILED);
 
-       uid = p_actctx->action_list_cards.addressbook_source_uid;
+       uid = p_actctx->addressbook_source_uid;
 
        if (uid != NULL)
                source = e_source_registry_ref_source (registry, uid);
@@ -722,8 +722,8 @@ action_list_cards_init (ESourceRegistry *registry,
        if (error != NULL) {
                g_warning (
                        "Couldn't load addressbook %s: %s",
-                       p_actctx->action_list_cards.addressbook_source_uid ?
-                       p_actctx->action_list_cards.addressbook_source_uid :
+                       p_actctx->addressbook_source_uid ?
+                       p_actctx->addressbook_source_uid :
                        "'default'", error->message);
                g_error_free (error);
                exit (-1);
diff --git a/addressbook/tools/evolution-addressbook-export-list-folders.c 
b/addressbook/tools/evolution-addressbook-export-list-folders.c
index 29c44db..c1d2b41 100644
--- a/addressbook/tools/evolution-addressbook-export-list-folders.c
+++ b/addressbook/tools/evolution-addressbook-export-list-folders.c
@@ -41,8 +41,8 @@ action_list_folders_init (ESourceRegistry *registry,
 
        g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FAILED);
 
-       if (p_actctx->action_list_folders.output_file != NULL) {
-               if (!(outputfile = g_fopen (p_actctx->action_list_folders.output_file, "w"))) {
+       if (p_actctx->output_file != NULL) {
+               if (!(outputfile = g_fopen (p_actctx->output_file, "w"))) {
                        g_warning (_("Can not open file"));
                        exit (-1);
                }
diff --git a/addressbook/tools/evolution-addressbook-export.c 
b/addressbook/tools/evolution-addressbook-export.c
index 0b83036..428877b 100644
--- a/addressbook/tools/evolution-addressbook-export.c
+++ b/addressbook/tools/evolution-addressbook-export.c
@@ -158,22 +158,22 @@ main (gint argc,
        if (current_action == ACTION_LIST_FOLDERS) {
                actctx.action_type = current_action;
                if (opt_output_file == NULL) {
-                       actctx.action_list_folders.output_file = NULL;
+                       actctx.output_file = NULL;
                } else {
-                       actctx.action_list_folders.output_file = g_strdup (opt_output_file);
+                       actctx.output_file = g_strdup (opt_output_file);
                }
                action_list_folders_init (registry, &actctx);
 
        } else if (current_action == ACTION_LIST_CARDS) {
                actctx.action_type = current_action;
                if (opt_output_file == NULL) {
-                       actctx.action_list_cards.output_file = NULL;
+                       actctx.output_file = NULL;
                } else {
-                       actctx.action_list_cards.output_file = g_strdup (opt_output_file);
+                       actctx.output_file = g_strdup (opt_output_file);
                }
-               actctx.action_list_cards.IsCSV = IsCSV;
-               actctx.action_list_cards.IsVCard = IsVCard;
-               actctx.action_list_cards.addressbook_source_uid =
+               actctx.IsCSV = IsCSV;
+               actctx.IsVCard = IsVCard;
+               actctx.addressbook_source_uid =
                        g_strdup (opt_addressbook_source_uid);
 
                action_list_cards_init (registry, &actctx);
diff --git a/addressbook/tools/evolution-addressbook-export.h 
b/addressbook/tools/evolution-addressbook-export.h
index 090446b..ca78eb8 100644
--- a/addressbook/tools/evolution-addressbook-export.h
+++ b/addressbook/tools/evolution-addressbook-export.h
@@ -37,30 +37,18 @@ G_BEGIN_DECLS
 
 #define DEFAULT_SIZE_NUMBER 100
 
-union _ActionContext
-{
+struct _ActionContext {
 
        guint action_type;
+       gchar *output_file;
 
-       struct
-       {
-               gint action_type;
-               gchar *output_file;
-       }
-       action_list_folders;
-
-       struct
-       {
-               gint action_type;
-               gchar *output_file;
-               gint IsCSV;
-               gint IsVCard;
-               gchar *addressbook_source_uid;
-       }
-       action_list_cards;
+       /* for cards only */
+       gint IsCSV;
+       gint IsVCard;
+       gchar *addressbook_source_uid;
 };
 
-typedef union _ActionContext ActionContext;
+typedef struct _ActionContext ActionContext;
 
 /* action_list_folders */
 guint          action_list_folders_init        (ESourceRegistry *registry,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]