Пример #1
0
static MuError
run_cmd_cfind (const char* pattern, MuConfigFormat format,
	       gboolean color, GError **err)
{
	gboolean rv;
	MuContacts *contacts;
	size_t num;
	ECData ecdata;

	ecdata.format = format;
	ecdata.color  = color;

	contacts = mu_contacts_new (mu_runtime_path(MU_RUNTIME_PATH_CONTACTS));
	if (!contacts) {
		g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_CONTACTS_CANNOT_RETRIEVE,
				     "could not retrieve contacts");
		return MU_ERROR_CONTACTS_CANNOT_RETRIEVE;
	}

	print_header (format);
	rv = mu_contacts_foreach (contacts,
				  (MuContactsForeachFunc)each_contact,
				  &ecdata, pattern, &num);
	mu_contacts_destroy (contacts);

	if (num == 0) {
		g_warning ("no matching contacts found");
		return MU_ERROR_NO_MATCHES;
	}

	return rv ? MU_OK : MU_ERROR_CONTACTS;
}
Пример #2
0
/**
 * get all contacts as an s-expression
 *
 * @param self contacts object
 * @param personal_only whether to restrict the list to 'personal' email addresses
 *
 * @return the sexp
 */
static char*
contacts_to_sexp (MuContacts *contacts, gboolean personal, time_t after)
{
	SexpData sdata;

	g_return_val_if_fail (contacts, NULL);

	sdata.personal = personal;
	sdata.after    = after;

	/* make a guess for the initial size */
	sdata.gstr = g_string_sized_new (mu_contacts_count(contacts) * 128);
	sdata.gstr = g_string_append (sdata.gstr, "(:contacts (");
	mu_contacts_foreach (contacts,
			     (MuContactsForeachFunc)each_contact_sexp,
			     &sdata, NULL, NULL);
	sdata.gstr = g_string_append (sdata.gstr, "))");

	return g_string_free (sdata.gstr, FALSE);
}