From b9be7f210c18828ad4a9cd09795c9dc858c9297c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 2 Mar 2011 23:26:54 +0200 Subject: [PATCH] * WIP: rudimentary implementation of the 'cfind' command, to find contacts --- src/mu-cmd.c | 37 ++++++++++++++++++++++++++++++++++++- src/mu-cmd.h | 11 +++++++++++ src/mu-config.c | 4 +++- src/mu-config.h | 1 + src/mu-contacts.h | 2 +- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/mu-cmd.c b/src/mu-cmd.c index 047f8628..adea7717 100644 --- a/src/mu-cmd.c +++ b/src/mu-cmd.c @@ -29,7 +29,8 @@ #include "mu-util.h" #include "mu-str.h" #include "mu-maildir.h" - +#include "mu-contacts.h" +#include "mu-runtime.h" /* we ignore fields for now */ static gboolean @@ -128,3 +129,37 @@ mu_cmd_mkdir (MuConfig *opts) return MU_EXITCODE_OK; } + + +static void +each_contact (const char *email, const char *name, gpointer data) +{ + g_print ("%s %s\n", email, name ? name : ""); +} + +MuExitCode +mu_cmd_cfind (MuConfig *opts) +{ + MuContacts *contacts; + + g_return_val_if_fail (opts, MU_EXITCODE_ERROR); + g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_CFIND, + MU_EXITCODE_ERROR); + + /* if (!opts->params[1]) { */ + /* g_warning ("usage: mu cfind [ptrn] "); */ + /* return MU_EXITCODE_ERROR; */ + /* } */ + + contacts = mu_contacts_new (mu_runtime_contacts_cache_file()); + if (!contacts) { + g_warning ("could not retrieve contacts"); + return MU_EXITCODE_ERROR; + } + + mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact, NULL); + mu_contacts_destroy (contacts); + + return MU_OK; +} + diff --git a/src/mu-cmd.h b/src/mu-cmd.h index 2a3a4ef7..11e0e1f0 100644 --- a/src/mu-cmd.h +++ b/src/mu-cmd.h @@ -92,6 +92,17 @@ MuExitCode mu_cmd_find (MuConfig *opts); MuExitCode mu_cmd_extract (MuConfig *opts); +/** + * execute the cfind command + * + * @param opts configuration options + * + * @return MU_EXITCODE_OK (0) if the command succeeds, + * MU_EXITCODE_ERROR otherwise + */ +MuExitCode mu_cmd_cfind (MuConfig *opts); + + G_END_DECLS #endif /*__MU_CMD_H__*/ diff --git a/src/mu-config.c b/src/mu-config.c index 96d20b8a..573ba0c6 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -244,7 +244,8 @@ parse_cmd (MuConfig *opts, int *argcp, char ***argvp) { "cleanup", MU_CONFIG_CMD_CLEANUP }, { "mkdir", MU_CONFIG_CMD_MKDIR }, { "view", MU_CONFIG_CMD_VIEW }, - { "extract", MU_CONFIG_CMD_EXTRACT } + { "extract", MU_CONFIG_CMD_EXTRACT }, + { "cfind", MU_CONFIG_CMD_CFIND }, }; opts->cmd = MU_CONFIG_CMD_NONE; @@ -394,6 +395,7 @@ mu_config_execute (MuConfig *opts) case MU_CONFIG_CMD_INDEX: return mu_cmd_index (opts); case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts); case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts); + case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts); case MU_CONFIG_CMD_UNKNOWN: g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr); show_usage (FALSE); diff --git a/src/mu-config.h b/src/mu-config.h index 0d7d17dc..5281efb8 100644 --- a/src/mu-config.h +++ b/src/mu-config.h @@ -41,6 +41,7 @@ enum _MuConfigCmd { MU_CONFIG_CMD_MKDIR, MU_CONFIG_CMD_VIEW, MU_CONFIG_CMD_EXTRACT, + MU_CONFIG_CMD_CFIND, MU_CONFIG_CMD_NONE, MU_CONFIG_CMD_UNKNOWN diff --git a/src/mu-contacts.h b/src/mu-contacts.h index 7484e867..e5a183df 100644 --- a/src/mu-contacts.h +++ b/src/mu-contacts.h @@ -63,7 +63,7 @@ gboolean mu_contacts_add (MuContacts *contacts, const char* name, const char *em void mu_contacts_destroy (MuContacts *contacts); -typedef void (*MuContactsForeachFunc) (const char *email, const char *mail, +typedef void (*MuContactsForeachFunc) (const char *email, const char *name, gpointer user_data); /**