aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/tools
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2007-04-20 02:53:33 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2007-04-20 02:53:33 +0800
commit64977cb1bcc55bf4c7c0fc38cd3d047b1e6a25c6 (patch)
tree4ebe95239bef43cb97c0e46aa8194d44e6c88be6 /addressbook/tools
parentbb05f6e6d0541bf29c8dde4e264cc7c23ba52fbb (diff)
downloadgsoc2013-evolution-64977cb1bcc55bf4c7c0fc38cd3d047b1e6a25c6.tar.gz
gsoc2013-evolution-64977cb1bcc55bf4c7c0fc38cd3d047b1e6a25c6.tar.zst
gsoc2013-evolution-64977cb1bcc55bf4c7c0fc38cd3d047b1e6a25c6.zip
Massive code cleanup (bug #429422)
svn path=/trunk/; revision=33432
Diffstat (limited to 'addressbook/tools')
-rw-r--r--addressbook/tools/evolution-addressbook-export.c113
1 files changed, 62 insertions, 51 deletions
diff --git a/addressbook/tools/evolution-addressbook-export.c b/addressbook/tools/evolution-addressbook-export.c
index ee157b74df..b99925d279 100644
--- a/addressbook/tools/evolution-addressbook-export.c
+++ b/addressbook/tools/evolution-addressbook-export.c
@@ -23,7 +23,9 @@
#include <config.h>
+#include <string.h>
#include <glib.h>
+#include <glib/gi18n.h>
#include <bonobo-activation/bonobo-activation.h>
#include <bonobo/bonobo-main.h>
#include <gnome.h>
@@ -32,62 +34,71 @@
#include "evolution-addressbook-export.h"
+/* Command-Line Options */
+static gchar *opt_output_file = NULL;
+static gboolean opt_list_folders_mode = FALSE;
+static gchar *opt_output_format = NULL;
+static gchar *opt_addressbook_folder_uri = NULL;
+static gboolean opt_async_mode = FALSE;
+static gint opt_file_size = 0;
+static gchar **opt_remaining = NULL;
+
+static GOptionEntry entries[] = {
+ { "output", '\0', G_OPTION_FLAG_FILENAME,
+ G_OPTION_ARG_STRING, &opt_output_file,
+ N_("Specify the output file instead of standard output"),
+ N_("OUTPUTFILE") },
+ { "list-addressbook-folders", 'l', 0,
+ G_OPTION_ARG_NONE, &opt_list_folders_mode,
+ N_("List local addressbook folders") },
+ { "format", '\0', 0,
+ G_OPTION_ARG_STRING, &opt_output_format,
+ N_("Show cards as vcard or csv file"),
+ N_("[vcard|csv]") },
+ { "async", 'a', 0,
+ G_OPTION_ARG_NONE, &opt_async_mode,
+ N_("Export in asynchronous mode") },
+ { "size", '\0', 0,
+ G_OPTION_ARG_INT, &opt_file_size,
+ N_("The number of cards in out output file in asynchronous mode, "
+ "default size 100."),
+ N_("NUMBER") },
+ { G_OPTION_REMAINING, '\0', 0,
+ G_OPTION_ARG_STRING_ARRAY, &opt_remaining },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
ActionContext actctx;
GnomeProgram *program;
- poptContext context;
- const gchar **argvn;
+ GOptionContext *context;
int current_action = ACTION_NOTHING;
int IsCSV = FALSE;
int IsVCard = FALSE;
- /*** popttable */
- char *output_file = NULL;
- int list_folders_mode = FALSE;
- char *output_format = NULL;
- char *addressbook_folder_uri = NULL;
- int async_mode = FALSE;
- int file_size = 0;
-
- struct poptOption options[] = {
- {"output", '\0', POPT_ARG_STRING, &output_file, 0, N_("Specify the output file instead of standard output"),
- N_("OUTPUTFILE")},
- {"list-addressbook-folders", 'l', POPT_ARG_NONE, &list_folders_mode, 0, N_("List local addressbook folders"),
- NULL},
- {"format", '\0', POPT_ARG_STRING, &output_format, 0, N_("Show cards as vcard or csv file"), N_("[vcard|csv]")},
- {"async", 'a', POPT_ARG_NONE, &async_mode, 0, N_("Export in asynchronous mode"), NULL},
- {"size", '\0', POPT_ARG_INT, &file_size, 0,
- N_("The number of cards in one output file in asynchronous mode, default size 100."), N_("NUMBER")},
- {NULL, '\0', 0, NULL, 0, NULL, NULL}
- };
- /* popttable end ** */
-
/*i18n-lize */
bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- program =
- gnome_program_init (PACKAGE, VERSION, GNOME_BONOBO_MODULE, argc, argv, GNOME_PARAM_POPT_TABLE, options,
- GNOME_PARAM_NONE);
+ context = g_option_context_new (NULL);
+ g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+ program = gnome_program_init (
+ PACKAGE, VERSION, GNOME_BONOBO_MODULE, argc, argv,
+ GNOME_PARAM_GOPTION_CONTEXT, context,
+ GNOME_PARAM_NONE);
/* Parsing Parameter */
- g_object_get (program, "popt-context", &context, NULL);
- argvn = poptGetArgs (context);
- if (!argvn) {
- addressbook_folder_uri = NULL;
- } else { /* there at lease is a one argument, and that should be addressbook folder uri */
- addressbook_folder_uri = g_strdup (*argvn);
- }
- poptFreeContext (context);
+ if (g_strv_length (opt_remaining) > 0)
+ opt_addressbook_folder_uri = g_strdup (opt_remaining[0]);
- if (list_folders_mode != FALSE) {
+ if (opt_list_folders_mode != FALSE) {
current_action = ACTION_LIST_FOLDERS;
/* check there should not be addressbook-folder-uri , and async and size , output_format */
- if (addressbook_folder_uri != NULL || async_mode != FALSE || output_format != NULL || file_size != 0) {
+ if (opt_addressbook_folder_uri != NULL || opt_async_mode != FALSE || opt_output_format != NULL || opt_file_size != 0) {
g_warning (_("Command line arguments error, please use --help option to see the usage."));
exit (-1);
}
@@ -96,11 +107,11 @@ main (int argc, char **argv)
current_action = ACTION_LIST_CARDS;
/* check the output format */
- if (output_format == NULL) {
+ if (opt_output_format == NULL) {
IsVCard = TRUE;
} else {
- IsCSV = !strcmp (output_format, "csv");
- IsVCard = !strcmp (output_format, "vcard");
+ IsCSV = !strcmp (opt_output_format, "csv");
+ IsVCard = !strcmp (opt_output_format, "vcard");
if (IsCSV == FALSE && IsVCard == FALSE) {
g_warning (_("Only support csv or vcard format."));
exit (-1);
@@ -108,17 +119,17 @@ main (int argc, char **argv)
}
/*check async and output file */
- if (async_mode == TRUE) {
+ if (opt_async_mode == TRUE) {
/* check have to output file , set default file_size */
- if (output_file == NULL) {
+ if (opt_output_file == NULL) {
g_warning (_("In async mode, output must be file."));
exit (-1);
}
- if (file_size == 0)
- file_size = DEFAULT_SIZE_NUMBER;
+ if (opt_file_size == 0)
+ opt_file_size = DEFAULT_SIZE_NUMBER;
} else {
/*check no file_size */
- if (file_size != 0) {
+ if (opt_file_size != 0) {
g_warning (_("In normal mode, there is no need for the size option."));
exit (-1);
}
@@ -128,24 +139,24 @@ main (int argc, char **argv)
/* do actions */
if (current_action == ACTION_LIST_FOLDERS) {
actctx.action_type = current_action;
- if (output_file == NULL) {
+ if (opt_output_file == NULL) {
actctx.action_list_folders.output_file = NULL;
} else {
- actctx.action_list_folders.output_file = g_strdup (output_file);
+ actctx.action_list_folders.output_file = g_strdup (opt_output_file);
}
action_list_folders_init (&actctx);
} else if (current_action == ACTION_LIST_CARDS) {
actctx.action_type = current_action;
- if (output_file == NULL) {
+ if (opt_output_file == NULL) {
actctx.action_list_cards.output_file = NULL;
} else {
- actctx.action_list_cards.output_file = g_strdup (output_file);
+ actctx.action_list_cards.output_file = g_strdup (opt_output_file);
}
actctx.action_list_cards.IsCSV = IsCSV;
actctx.action_list_cards.IsVCard = IsVCard;
- actctx.action_list_cards.addressbook_folder_uri = g_strdup (addressbook_folder_uri);
- actctx.action_list_cards.async_mode = async_mode;
- actctx.action_list_cards.file_size = file_size;
+ actctx.action_list_cards.addressbook_folder_uri = g_strdup (opt_addressbook_folder_uri);
+ actctx.action_list_cards.async_mode = opt_async_mode;
+ actctx.action_list_cards.file_size = opt_file_size;
action_list_cards_init (&actctx);