Ejemplo n.º 1
0
static gint
add_record (GnomePilotConduitSyncAbs *conduit,
	    GnomePilotRecord *remote,
	    EAddrConduitContext *ctxt)
{
	EContact *contact;
	int retval = 0;

	g_return_val_if_fail (remote != NULL, -1);

	LOG (g_message ( "add_record: adding %s to desktop\n", print_remote (remote) ));

	contact = ecard_from_remote_record (ctxt, remote, NULL);

	/* add the ecard to the server */
	if (!e_book_add_contact (ctxt->ebook, contact, NULL)) {
		WARN ("add_record: failed to add card to ebook\n");
		g_object_unref (contact);

		return -1;
	}

	e_pilot_map_insert (ctxt->map, remote->ID, e_contact_get (contact, E_CONTACT_UID), FALSE);

	g_object_unref (contact);

	return retval;
}
Ejemplo n.º 2
0
static gint
replace_record (GnomePilotConduitSyncAbs *conduit,
		EAddrLocalRecord *local,
		GnomePilotRecord *remote,
		EAddrConduitContext *ctxt)
{
	EContact *new_contact;
	EBookChange *ebc;
	char *old_id;
	int retval = 0;

	g_return_val_if_fail (remote != NULL, -1);

	LOG (g_message ("replace_record: replace %s with %s\n",
	     print_local (local), print_remote (remote)));

	old_id = e_contact_get (local->contact, E_CONTACT_UID);
	ebc = g_hash_table_lookup (ctxt->changed_hash, old_id);

	new_contact = ecard_from_remote_record (ctxt, remote, local->contact);
	g_object_unref (local->contact);
	local->contact = new_contact;

	if (ebc && ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
		if (!e_book_add_contact (ctxt->ebook, local->contact, NULL)) {
			WARN (G_STRLOC ": failed to add card\n");

			return -1;
		}

	} else {
		if (!e_book_commit_contact (ctxt->ebook, local->contact, NULL)) {
			WARN (G_STRLOC ": failed to commit card\n");

			return -1;
		}
	}

	/* Adding a record causes wombat to assign a new uid so we must tidy */
	if (ebc && ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) {
		const char *uid = e_contact_get_const (local->contact, E_CONTACT_UID);
		gboolean arch;

		arch = e_pilot_map_uid_is_archived (ctxt->map, uid);
		e_pilot_map_insert (ctxt->map, remote->ID, uid, arch);

		ebc = g_hash_table_lookup (ctxt->changed_hash, old_id);
		if (ebc) {
			g_hash_table_remove (ctxt->changed_hash, old_id);
			g_object_unref (ebc->contact);
			g_object_ref (local->contact);
			ebc->contact = local->contact;
			/* FIXME We should possibly be duplicating the uid */
			g_hash_table_insert (ctxt->changed_hash, (gpointer) uid, ebc);
		}
	}

	return retval;
}
Ejemplo n.º 3
0
static void
create_new_contact_from_number (gchar *number)
{
  GtkWidget *dialog, *name, *label;

  dialog = gtk_dialog_new_with_buttons ("Save as Contact",
             NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);

  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);

  label = gtk_label_new ("Enter a name for the contact");
  name = gtk_entry_new ();

  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG(dialog)->vbox), label);
  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG(dialog)->vbox), name);

  gtk_widget_show (label);
  gtk_widget_show (name);

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  {
    EContact *contact;
    EBook *book;
    EVCardAttribute *attr;

    /* create contact */
    contact = e_contact_new ();
    /* add name */
    e_contact_set (contact, E_CONTACT_FULL_NAME, (const gpointer)gtk_entry_get_text (GTK_ENTRY (name))); /* (const gpointer) removes a useless warning) */
    /* add number */
    attr = e_vcard_attribute_new ("", EVC_TEL);
    e_vcard_add_attribute_with_value (E_VCARD (contact), attr, number);
    hito_vcard_attribute_set_type (attr, "Other");

    /* open address book */
    /* TODO: check GErrors */
    book = e_book_new_system_addressbook (NULL);
    e_book_open (book, FALSE, NULL);

    /* add contact to address book, and close */
    e_book_add_contact (book, contact, NULL);

    g_object_unref (book);
    g_object_unref (contact);
  }
  gtk_widget_destroy (dialog);
}
Ejemplo n.º 4
0
static void
contacts_edit_ok_new_cb (GtkWidget *button, ContactsData *data)
{
	if (data->contact) {
		/* Clean contact */
		contacts_clean_contact (data->contact);
	
		/* Commit changes */
		if (contacts_contact_is_empty (data->contact)) {
			g_object_unref (data->contact);
		} else {
			GError *error = NULL;
			e_book_add_contact(data->book, data->contact, &error);
			if (error) {
				GtkWidget *dialog;
				GtkWidget *toplevel = gtk_widget_get_toplevel (button);
				dialog = gtk_message_dialog_new (
						GTK_WINDOW (toplevel),
						GTK_DIALOG_MODAL,
						GTK_MESSAGE_ERROR,
						GTK_BUTTONS_OK,
						_("Couldn't add contact")
						);

				gtk_message_dialog_format_secondary_text (
						GTK_MESSAGE_DIALOG (dialog),
						_("Cannot add contact: %s"), 
						error->message 
						);

				gtk_dialog_run (GTK_DIALOG (dialog));
				gtk_widget_destroy (dialog);		
				g_warning ("Cannot add contact: %s",
					error->message);
				g_error_free (error);
			}
		}
	}
 
        data->changed = FALSE;
	contacts_edit_pane_hide (data);
}
Ejemplo n.º 5
0
/* calls to import contacts */
static int
addrbook_libebook_import(ship_list_t *imps, int *concount, int query)
{
	int ret = -1;
	void *ptr = 0;
	contact_t *c = 0;
	GError *error = 0;
	*concount = 0;

	/* query & import */
	ship_lock(addrbook_lock);
	if (ship_list_first(imps) && (!query || ui_query_import_contacts(imps) > 0)) {

		ptr = 0;
		while ((c = ship_list_next(imps, &ptr))) {
			EContact *contact = 0;
			EContactName name;
			char *arr[2], *ln;
			arr[1] = 0;
			bzero(&name, sizeof(name));
			ret = -1;

			/* create a new contact */
			ASSERT_TRUE(contact = e_contact_new(), cerr);
			
			/* create the name struct */
			ln = strchr(c->name, ' ');
			if (ln) {
				ASSERT_TRUE(name.given = strndup(c->name, ln - c->name), cerr);
				ASSERT_TRUE(name.family = strdup(ln+1), cerr);
			} else {
				ASSERT_TRUE(name.given = strdup(c->name), cerr);
			}

			/* simple strings */
			e_contact_set(contact, E_CONTACT_FULL_NAME, c->name);
			e_contact_set(contact, E_CONTACT_GIVEN_NAME, name.given);
			if (name.family)
				e_contact_set(contact, E_CONTACT_FAMILY_NAME, name.family);
 			if (ship_ht_get_string(c->params, "category"))
				e_contact_set(contact, E_CONTACT_CATEGORIES, ship_ht_get_string(c->params, "category"));
			
			/* EContactName */
			e_contact_set(contact, E_CONTACT_NAME, &name);

			/* array of strings */
 			if (ship_ht_get_string(c->params, "email")) {
				arr[0] = ship_ht_get_string(c->params, "email");
				e_contact_set(contact, E_CONTACT_EMAIL, arr);
			}
			arr[0] = c->sip_aor;
			e_contact_set(contact, E_CONTACT_SIP, arr);

			ASSERT_TRUE(e_book_add_contact(book, contact, &error), cerr);
			ret = 0;
		cerr:
			g_object_unref(contact);
			freez(name.family);
			freez(name.given);
			
			if (ret)
				goto err;

			/* save what we've done */
			c->added = time(NULL);
			(*concount)++;
		}
	}

	ret = 0;
 err:
	if (error) {
		if (query) 
			ui_print_error("Error importing the contacts: %s.\n", error->message);
		g_error_free(error);
	} else if (ret && query) {
		ui_print_error("An error occured while importing the contacts.\n");
	}
	ship_unlock(addrbook_lock);
	return ret;
}
Ejemplo n.º 6
0
void
bbdb_sync_buddy_list (void)
{
	GList       *blist, *l;
	EBook       *book = NULL;

	/* Get the Gaim buddy list */
	blist = bbdb_get_gaim_buddy_list ();
	if (blist == NULL)
		return;

	/* Open the addressbook */
	book = bbdb_open_addressbook (GAIM_ADDRESSBOOK);
	if (book == NULL) {
		free_buddy_list (blist);
		return;
	}

	printf ("bbdb: Synchronizing buddy list to contacts...\n");
	/* Walk the buddy list */
	for (l = blist; l != NULL; l = l->next) {
		GaimBuddy *b = l->data;
		EBookQuery *query;
		GList *contacts;
		GError *error = NULL;
		EContact *c;

		if (b->alias == NULL || strlen (b->alias) == 0)
			b->alias = b->account_name;

		/* Look for an exact match full name == buddy alias */
		query = e_book_query_field_test (E_CONTACT_FULL_NAME, E_BOOK_QUERY_IS, b->alias);
		e_book_get_contacts (book, query, &contacts, NULL);
		e_book_query_unref (query);
		if (contacts != NULL) {

			/* FIXME: If there's more than one contact with this
			   name, just give up; we're not smart enough for
			   this. */
			if (contacts->next != NULL)
 				continue;

			c = E_CONTACT (contacts->data);

			if (! bbdb_merge_buddy_to_contact (book, b, c))
				continue;

			/* Write it out to the addressbook */
			if (! e_book_commit_contact (book, c, &error)) {
				g_warning ("bbdb: Could not modify contact: %s\n", error->message);
				g_error_free (error);
			}
			continue;
		}

		/* Otherwise, create a new contact. */
		c = e_contact_new ();
		e_contact_set (c, E_CONTACT_FULL_NAME, (gpointer) b->alias);
		if (! bbdb_merge_buddy_to_contact (book, b, c)) {
			g_object_unref (G_OBJECT (c));
			continue;
		}

		if (! e_book_add_contact (book, c, &error)) {
			g_warning ("bbdb: Failed to add new contact: %s\n", error->message);
			g_error_free (error);
			return;
		}
		g_object_unref (G_OBJECT (c));

	}


	/* Update the last-sync'd time */
	{
		GConfClient *gconf;
		time_t  last_sync;
		char   *last_sync_str;

		gconf = gconf_client_get_default ();

		time (&last_sync);
		last_sync_str = g_strdup_printf ("%ld", (glong) last_sync);
		gconf_client_set_string (gconf, GCONF_KEY_GAIM_LAST_SYNC, last_sync_str, NULL);
		g_free (last_sync_str);

		g_object_unref (G_OBJECT (gconf));
	}
	printf ("bbdb: Done syncing buddy list to contacts.\n");
}