static void
verify_premodify_and_prepare_contact (EContact *contact)
{
	EVCardAttribute *attr;

	/* ensure there is no email address to begin with, then add one */
	g_assert (!e_vcard_get_attribute (E_VCARD (contact), EVC_EMAIL));
	attr = e_vcard_attribute_new (NULL, EVC_EMAIL);
	e_vcard_add_attribute_with_value (E_VCARD (contact), attr, EMAIL_ADD);
}
Example #2
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);
}
Example #3
0
static void
add_number_to_contact (gchar *number)
{
    EBook *book;
    EBookQuery *query;
    EBookView *view;
    GtkWidget *window, *contacts_treeview, *scroll, *groups_combo;
    GtkTreeModel *store, *group_store, *contact_filter;
    GError *err = NULL;

    window = gtk_dialog_new_with_buttons ("Add to Contact", NULL, 0,
					  "Cancel", GTK_RESPONSE_CANCEL,
					  "Add", GTK_RESPONSE_OK,
					  NULL);
    gtk_dialog_set_has_separator (GTK_DIALOG (window), FALSE);

    book = e_book_new_system_addressbook (&err);
    if (err)
      return;
    e_book_open (book, FALSE, &err);
    if (err)
     return;
    query = e_book_query_any_field_contains (NULL);
    e_book_get_book_view (book, query, NULL, 0, &view, &err);
    if (err)
      return;

    e_book_query_unref (query);
    e_book_view_start (view);


    store = hito_contact_store_new (view);

    group_store = hito_group_store_new ();
    hito_group_store_set_view (HITO_GROUP_STORE (group_store), view);
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_all_group_new ());
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (-99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_separator_group_new (99));
    hito_group_store_add_group (HITO_GROUP_STORE (group_store), hito_no_category_group_new ());

    contact_filter = hito_contact_model_filter_new (HITO_CONTACT_STORE (store));

    groups_combo = hito_group_combo_new (HITO_GROUP_STORE (group_store));
    hito_group_combo_connect_filter (HITO_GROUP_COMBO (groups_combo),
                                   HITO_CONTACT_MODEL_FILTER (contact_filter));
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), groups_combo);
    gtk_combo_box_set_active (GTK_COMBO_BOX (groups_combo), 0);



    contacts_treeview = hito_contact_view_new (HITO_CONTACT_STORE (store), HITO_CONTACT_MODEL_FILTER (contact_filter));

    scroll = moko_finger_scroll_new ();
    gtk_widget_set_size_request (scroll, -1, 300);
    gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox), scroll);

    gtk_container_add (GTK_CONTAINER (scroll), contacts_treeview);

    gtk_widget_show_all (scroll);
    gtk_widget_show_all (groups_combo);

    if (gtk_dialog_run (GTK_DIALOG (window)) == GTK_RESPONSE_OK)
    {
      GtkTreeIter iter;
      EContact *contact;
      EVCardAttribute *attr;
      GtkTreeModel *model;
      GtkTreeSelection *selection;

      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (contacts_treeview));

      if (gtk_tree_selection_get_selected (selection, &model, &iter))
      {
        gtk_tree_model_get (model, &iter, COLUMN_CONTACT, &contact, -1);
        if (contact)
        {
          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");
          e_book_async_commit_contact (book, contact, NULL, NULL);
          g_object_unref (contact);
        }
      }
    }

    gtk_widget_destroy (window);
    g_object_unref (book);
}
Example #4
0
static void
contacts_entry_changed (GtkWidget *widget, EContactChangeData *data)
{
	GList *v, *values = contacts_entries_get_values (data->widget, NULL);
	
	e_vcard_attribute_remove_values (data->attr);
	/* Note: First element of a structured field is type, so remove it */
	if (g_list_length (values) > 1) {
		GList *type = g_list_last (values);
		values = g_list_remove_link (values, type);
		g_free (type->data);
		g_list_free (type);
	}
		
	for (v = g_list_last (values); v; v = v->prev) {
		e_vcard_attribute_add_value (data->attr,
					     (const gchar *)v->data);
	}

	if (!g_ascii_strcasecmp (e_vcard_attribute_get_name (data->attr), EVC_FN))
	{
		/* add N and X-EVOLUTION-FILE-AS attributes */
		ENameWestern *name;
		gchar *file_as;
		EVCardAttribute *attr;
		EVCard *evc = E_VCARD (data->contact);

		name = e_name_western_parse ((char*)values->data);
		
		/* Add "N" attribute */
		attr = e_vcard_get_attribute (evc, EVC_N);
		if (attr)
			e_vcard_attribute_remove_values (attr);
		else
		{
			attr = e_vcard_attribute_new ("", EVC_N);
			e_vcard_add_attribute (evc, attr);
		}
#define SAFESTR(x) (x) ? x : ""
		e_vcard_attribute_add_value (attr, SAFESTR (name->last));
		e_vcard_attribute_add_value (attr, SAFESTR (name->first));
		e_vcard_attribute_add_value (attr, SAFESTR (name->middle));
		e_vcard_attribute_add_value (attr, SAFESTR (name->prefix));
		e_vcard_attribute_add_value (attr, SAFESTR (name->suffix));

		/* Add file-as attribute for evolution */
		file_as = g_strdup_printf ("%s, %s", name->last, name->first);
		attr = e_vcard_get_attribute (evc, EVC_X_FILE_AS);
		if (attr)
			e_vcard_remove_attribute (evc, attr);
		attr = e_vcard_attribute_new ("", EVC_X_FILE_AS);
		e_vcard_add_attribute_with_value (evc, attr, file_as);
		g_free (file_as);

		g_free (name);
	}

	g_list_foreach (values, (GFunc)g_free, NULL);
	g_list_free (values);
	*data->changed = TRUE;
}