aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-03-06 18:00:44 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-03-06 18:00:44 +0800
commite6e1655f31dca8aceb4c97c966d44bac23eb7200 (patch)
treee3334cea315a90e669d0d16144ede3ba67cf9ab4
parent10d0e730eccccf34fc53dc8c1d6145fca1f52f57 (diff)
downloadgsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.gz
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.bz2
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.lz
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.xz
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.zst
gsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.zip
Fix a reference counting bug.
2001-03-06 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names-model.c (e_select_names_model_replace): Fix a reference counting bug. * gui/component/select-names/e-select-names-manager.c (popup_cb): A callback for creating the appropriate popup by calling e_select_names_popup. (e_select_names_manager_create_entry): Connect popup_cb to the entry's popup signal * gui/component/select-names/e-select-names-popup.c: Added. Code for popup right-click menus for recipient entries. Still a bit incomplete. * backend/ebook/e-destination.c (e_destination_get_email_num): Added. * contact-editor/e-contact-quick-add.c: Added. Some code and a dialog for very quickly adding entries to the address book. Still not fully working. svn path=/trunk/; revision=8567
-rw-r--r--addressbook/ChangeLog22
-rw-r--r--addressbook/backend/ebook/e-destination.c8
-rw-r--r--addressbook/backend/ebook/e-destination.h7
-rw-r--r--addressbook/contact-editor/Makefile.am4
-rw-r--r--addressbook/contact-editor/e-contact-quick-add.c282
-rw-r--r--addressbook/contact-editor/e-contact-quick-add.h40
-rw-r--r--addressbook/gui/component/select-names/Makefile.am2
-rw-r--r--addressbook/gui/component/select-names/e-select-names-manager.c14
-rw-r--r--addressbook/gui/component/select-names/e-select-names-model.c4
-rw-r--r--addressbook/gui/component/select-names/e-select-names-popup.c345
-rw-r--r--addressbook/gui/component/select-names/e-select-names-popup.h36
-rw-r--r--addressbook/gui/contact-editor/Makefile.am4
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.c282
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.h40
14 files changed, 1084 insertions, 6 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index de2ebadee3..221e3f81e1 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,25 @@
+2001-03-06 Jon Trowbridge <trow@ximian.com>
+
+ * gui/component/select-names/e-select-names-model.c
+ (e_select_names_model_replace): Fix a reference counting bug.
+
+ * gui/component/select-names/e-select-names-manager.c (popup_cb):
+ A callback for creating the appropriate popup by calling
+ e_select_names_popup.
+ (e_select_names_manager_create_entry): Connect popup_cb to the
+ entry's popup signal
+
+ * gui/component/select-names/e-select-names-popup.c: Added. Code
+ for popup right-click menus for recipient entries. Still a bit
+ incomplete.
+
+ * backend/ebook/e-destination.c (e_destination_get_email_num):
+ Added.
+
+ * contact-editor/e-contact-quick-add.c: Added. Some code and a
+ dialog for very quickly adding entries to the address book.
+ Still not fully working.
+
2001-03-04 Christopher James Lahey <clahey@ximian.com>
* backend/ebook/e-card-simple.c: Cleaned up the formatting in this
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c
index 92aed64715..c1e0ad8a78 100644
--- a/addressbook/backend/ebook/e-destination.c
+++ b/addressbook/backend/ebook/e-destination.c
@@ -183,6 +183,14 @@ e_destination_get_card (const EDestination *dest)
return dest->priv->card;
}
+gint
+e_destination_get_email_num (const EDestination *dest)
+{
+ g_return_val_if_fail (dest && E_IS_DESTINATION (dest), -1);
+
+ return dest->priv->card_email_num;
+}
+
const gchar *
e_destination_get_string (const EDestination *dest)
{
diff --git a/addressbook/backend/ebook/e-destination.h b/addressbook/backend/ebook/e-destination.h
index 509a351f1d..2014f8e340 100644
--- a/addressbook/backend/ebook/e-destination.h
+++ b/addressbook/backend/ebook/e-destination.h
@@ -60,9 +60,10 @@ EDestination *e_destination_copy (EDestination *);
void e_destination_set_card (EDestination *, ECard *card, gint email_num);
void e_destination_set_string (EDestination *, const gchar *string);
-ECard *e_destination_get_card (const EDestination *);
-const gchar *e_destination_get_string (const EDestination *);
-gint e_destination_get_strlen (const EDestination *); /* a convenience function... */
+ECard *e_destination_get_card (const EDestination *);
+gint e_destination_get_email_num (const EDestination *);
+const gchar *e_destination_get_string (const EDestination *);
+gint e_destination_get_strlen (const EDestination *); /* a convenience function... */
const gchar *e_destination_get_email (const EDestination *);
const gchar *e_destination_get_email_verbose (const EDestination *);
diff --git a/addressbook/contact-editor/Makefile.am b/addressbook/contact-editor/Makefile.am
index d5ed7feeaa..700be0ff35 100644
--- a/addressbook/contact-editor/Makefile.am
+++ b/addressbook/contact-editor/Makefile.am
@@ -22,7 +22,9 @@ libecontacteditor_a_SOURCES = \
e-contact-editor.c \
e-contact-editor.h \
e-contact-save-as.c \
- e-contact-save-as.h
+ e-contact-save-as.h \
+ e-contact-quick-add.c \
+ e-contact-quick-add.h
noinst_PROGRAMS = \
contact-editor-test
diff --git a/addressbook/contact-editor/e-contact-quick-add.c b/addressbook/contact-editor/e-contact-quick-add.c
new file mode 100644
index 0000000000..f27fdf9553
--- /dev/null
+++ b/addressbook/contact-editor/e-contact-quick-add.c
@@ -0,0 +1,282 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-contact-quick-add.c
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#include <config.h>
+#include <gnome.h>
+#include <addressbook/backend/ebook/e-book.h>
+#include <addressbook/backend/ebook/e-card.h>
+#include "e-contact-editor.h"
+#include "e-contact-quick-add.h"
+
+static FILE *out = NULL;
+
+static void
+e_card_quick_set_name (ECard *card, const gchar *str)
+{
+ g_return_if_fail (card && E_IS_CARD (card));
+
+ if (str == NULL)
+ return;
+
+ if (out)
+ fprintf (out, "quick-set name to \"%s\"\n", str);
+
+ if (card->name)
+ e_card_name_free (card->name);
+ card->name = e_card_name_from_string (str);
+}
+
+static void
+e_card_quick_set_email (ECard *card, const gchar *str)
+{
+ g_return_if_fail (card && E_IS_CARD (card));
+
+ if (str == NULL)
+ return;
+
+ if (out)
+ fprintf (out, "quick-set email to \"%s\"\n", str);
+
+ if (card->email == NULL) {
+ card->email = e_list_new ((EListCopyFunc) g_strdup,
+ (EListFreeFunc) g_free,
+ NULL);
+ e_list_append (card->email, str);
+ } else {
+ EIterator *iter = e_list_get_iterator (card->email);
+ e_iterator_reset (iter);
+ if (e_iterator_is_valid (iter)) {
+ e_iterator_set (iter, str);
+ }
+ }
+}
+
+
+static void
+book_ready_cb (EBook *book, EBookStatus status, gpointer user_data)
+{
+ if (status == E_BOOK_STATUS_SUCCESS)
+ e_book_add_card (book, E_CARD (user_data), NULL, NULL);
+ gtk_object_unref (GTK_OBJECT (book));
+}
+
+static void
+add_card (ECard *card)
+{
+ EBook *book = e_book_new ();
+ gchar *filename, *uri;
+
+ filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db");
+ uri = g_strdup_printf ("file://%s", filename);
+
+ e_book_load_uri (book, uri, book_ready_cb, card);
+
+ g_free (filename);
+ g_free (uri);
+}
+
+static void
+add_card_cb (EContactEditor *ce, ECard *card, gpointer user_data)
+{
+ add_card (card);
+}
+
+static void
+editor_closed_cb (GtkWidget *w, gpointer user_data)
+{
+ if (user_data)
+ gtk_object_unref (user_data);
+ gtk_object_unref (GTK_OBJECT (w));
+}
+
+static void
+clicked_cb (GtkWidget *w, gint button, gpointer user_data)
+{
+ ECard *card = E_CARD (user_data);
+
+ /* Get data out of entries. */
+ if (button == 0 || button == 1) {
+ gpointer name_entry;
+ gpointer email_entry;
+ gchar *name = NULL;
+ gchar *email = NULL;
+
+ name_entry = gtk_object_get_data (GTK_OBJECT (card), "e-contact-quick-add-name-entry");
+ email_entry = gtk_object_get_data (GTK_OBJECT (card), "e-contact-quick-add-email-entry");
+
+ if (name_entry)
+ name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
+ if (email_entry)
+ email = gtk_editable_get_chars (GTK_EDITABLE (email_entry), 0, -1);
+
+ e_card_quick_set_name (card, name);
+ e_card_quick_set_email (card, email);
+
+ g_free (name);
+ g_free (email);
+ }
+
+ gtk_widget_destroy (w);
+
+ if (button == 0) { /* OK */
+
+ add_card (card);
+
+ } else if (button == 1) {
+
+ /* EDIT FULL */
+ EContactEditor *contact_editor;
+ contact_editor = e_contact_editor_new (card, TRUE);
+
+ gtk_signal_connect (GTK_OBJECT (contact_editor),
+ "add_card",
+ GTK_SIGNAL_FUNC (add_card_cb),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (contact_editor),
+ "editor_closed",
+ GTK_SIGNAL_FUNC (editor_closed_cb),
+ user_data);
+
+ e_contact_editor_raise (contact_editor);
+
+ } else {
+ /* CANCEL */
+ gtk_object_unref (user_data);
+ }
+
+}
+
+static GtkWidget *
+build_quick_add_dialog (ECard *new_card, EContactQuickAddCallback cb, gpointer user_data)
+{
+ GtkWidget *dialog;
+ GtkTable *table;
+ GtkWidget *name_entry;
+ GtkWidget *email_entry;
+ const gint xpad=1, ypad=1;
+
+ g_return_val_if_fail (new_card && E_IS_CARD (new_card), NULL);
+
+ dialog = gnome_dialog_new (_("Contact Quick-Add"),
+ GNOME_STOCK_BUTTON_OK,
+ _("Edit Full"),
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "clicked",
+ clicked_cb,
+ new_card);
+
+ name_entry = gtk_entry_new ();
+
+ if (new_card->name) {
+ gchar *str = e_card_name_to_string (new_card->name);
+ gtk_entry_set_text (GTK_ENTRY (name_entry), str);
+ g_free (str);
+ }
+
+
+ email_entry = gtk_entry_new ();
+
+ if (new_card->email && e_list_length (new_card->email)) {
+ EIterator *iterator = e_list_get_iterator (new_card->email);
+ if (iterator) {
+ e_iterator_reset (iterator);
+ if (e_iterator_is_valid (iterator)) {
+ const gchar *str = e_iterator_get (iterator);
+ gtk_entry_set_text (GTK_ENTRY (email_entry), str);
+ }
+ }
+ }
+
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-name-entry", name_entry);
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-email-entry", email_entry);
+
+
+ table = GTK_TABLE (gtk_table_new (2, 2, FALSE));
+
+ gtk_table_attach (table, gtk_label_new (_("Full Name")),
+ 0, 1, 0, 1,
+ 0, 0, xpad, ypad);
+ gtk_table_attach (table, name_entry,
+ 1, 2, 0, 1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND, xpad, ypad);
+ gtk_table_attach (table, gtk_label_new (_("E-mail")),
+ 0, 1, 1, 2,
+ 0, 0, xpad, ypad);
+ gtk_table_attach (table, email_entry,
+ 1, 2, 1, 2,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND, xpad, ypad);
+
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+ GTK_WIDGET (table),
+ TRUE, TRUE, 0);
+ gtk_widget_show_all (GTK_WIDGET (table));
+
+
+ return dialog;
+}
+
+void
+e_contact_quick_add (const gchar *name, const gchar *email,
+ EContactQuickAddCallback cb, gpointer user_data)
+{
+ ECard *new_card;
+ GtkWidget *dialog;
+
+ if (out == NULL) {
+ out = fopen ("/tmp/barnass", "w");
+ if (out)
+ setvbuf (out, NULL, _IONBF, 0);
+ }
+
+ if (out)
+ fprintf (out, "\n name: %s\nemail: %s\n", name, email);
+
+
+ /* We need to have *something* to work with. */
+ if (name == NULL && email == NULL) {
+ if (cb)
+ cb (NULL, user_data);
+ return;
+ }
+
+ new_card = e_card_new ("");
+ if (cb)
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-cb", cb);
+ if (user_data)
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-user-data", user_data);
+
+
+ e_card_quick_set_name (new_card, name);
+ e_card_quick_set_email (new_card, email);
+
+ dialog = build_quick_add_dialog (new_card, cb, user_data);
+
+ gtk_widget_show_all (dialog);
+}
diff --git a/addressbook/contact-editor/e-contact-quick-add.h b/addressbook/contact-editor/e-contact-quick-add.h
new file mode 100644
index 0000000000..630dfd2ad0
--- /dev/null
+++ b/addressbook/contact-editor/e-contact-quick-add.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-contact-quick-add.h
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#ifndef __E_CONTACT_QUICK_ADD_H__
+#define __E_CONTACT_QUICK_ADD_H__
+
+#include <gtk/gtk.h>
+#include <addressbook/backend/ebook/e-card.h>
+
+typedef void (*EContactQuickAddCallback) (ECard *new_card, gpointer user_data);
+
+void e_contact_quick_add (const gchar *name, const gchar *email,
+ EContactQuickAddCallback cb, gpointer user_data);
+
+#endif /* __E_CONTACT_QUICK_ADD_H__ */
+
diff --git a/addressbook/gui/component/select-names/Makefile.am b/addressbook/gui/component/select-names/Makefile.am
index 7e9a2e00e3..4010ca1f8e 100644
--- a/addressbook/gui/component/select-names/Makefile.am
+++ b/addressbook/gui/component/select-names/Makefile.am
@@ -59,6 +59,8 @@ libeselectnames_la_SOURCES = \
e-select-names-manager.h \
e-select-names-model.c \
e-select-names-model.h \
+ e-select-names-popup.c \
+ e-select-names-popup.h \
e-select-names-table-model.c \
e-select-names-table-model.h \
e-select-names-text-model.c \
diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c
index e1c8d80276..e1718cf3a7 100644
--- a/addressbook/gui/component/select-names/e-select-names-manager.c
+++ b/addressbook/gui/component/select-names/e-select-names-manager.c
@@ -17,6 +17,7 @@
#include "e-select-names-text-model.h"
#include "e-select-names.h"
#include "e-select-names-completion.h"
+#include "e-select-names-popup.h"
#include <gal/e-text/e-entry.h>
#include <addressbook/backend/ebook/e-destination.h>
@@ -289,6 +290,12 @@ completion_handler (EEntry *entry, const gchar *text, gpointer user_data)
e_entry_set_position (entry, start_pos+len);
}
+static void
+popup_cb (EEntry *entry, GdkEventButton *ev, gint pos, ESelectNamesModel *model)
+{
+ e_select_names_popup (model, ev, pos);
+}
+
GtkWidget *
e_select_names_manager_create_entry (ESelectNamesManager *manager, const char *id)
{
@@ -304,7 +311,12 @@ e_select_names_manager_create_entry (ESelectNamesManager *manager, const char *i
eentry = E_ENTRY (e_entry_new ());
gtk_object_set_data (GTK_OBJECT (eentry), "select_names_model", section->model);
-
+
+ gtk_signal_connect (GTK_OBJECT (eentry),
+ "popup",
+ GTK_SIGNAL_FUNC (popup_cb),
+ section->model);
+
entry = g_new (ESelectNamesManagerEntry, 1);
entry->entry = eentry;
entry->id = (char *)id;
diff --git a/addressbook/gui/component/select-names/e-select-names-model.c b/addressbook/gui/component/select-names/e-select-names-model.c
index e663768c21..939c40aa8b 100644
--- a/addressbook/gui/component/select-names/e-select-names-model.c
+++ b/addressbook/gui/component/select-names/e-select-names-model.c
@@ -386,7 +386,11 @@ e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination
new_strlen = e_destination_get_strlen (dest);
if (model->priv->data == NULL) {
+
model->priv->data = g_list_append (model->priv->data, dest);
+ gtk_object_ref (GTK_OBJECT (dest));
+ gtk_object_sink (GTK_OBJECT (dest));
+
} else {
node = g_list_nth (model->priv->data, index);
diff --git a/addressbook/gui/component/select-names/e-select-names-popup.c b/addressbook/gui/component/select-names/e-select-names-popup.c
new file mode 100644
index 0000000000..23898a3079
--- /dev/null
+++ b/addressbook/gui/component/select-names/e-select-names-popup.c
@@ -0,0 +1,345 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-select-names-popup.c
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <gnome.h>
+#include <addressbook/contact-editor/e-contact-quick-add.h>
+#include "e-select-names-popup.h"
+
+static FILE *out = NULL;
+
+typedef struct _PopupInfo PopupInfo;
+struct _PopupInfo {
+ ESelectNamesModel *model;
+ const EDestination *dest;
+ gint pos;
+ gint index;
+};
+
+static PopupInfo *
+popup_info_new (ESelectNamesModel *model, const EDestination *dest, gint pos, gint index)
+{
+ PopupInfo *info = g_new0 (PopupInfo, 1);
+ info->model = model;
+ info->dest = dest;
+ info->pos = pos;
+ info->index = index;
+
+ if (model)
+ gtk_object_ref (GTK_OBJECT (model));
+
+ if (dest)
+ gtk_object_ref (GTK_OBJECT (dest));
+
+ return info;
+}
+
+static void
+popup_info_free (PopupInfo *info)
+{
+ if (info) {
+
+ if (out)
+ fprintf (out, "popup_info_free\n");
+
+ if (info->model)
+ gtk_object_unref (GTK_OBJECT (info->model));
+
+ if (info->dest)
+ gtk_object_unref (GTK_OBJECT (info->dest));
+
+ g_free (info);
+ }
+}
+
+static void
+popup_info_cleanup (GtkWidget *w, gpointer info)
+{
+ popup_info_free ((PopupInfo *) info);
+}
+
+static void
+do_nothing (gpointer foo)
+{
+
+}
+
+static void
+change_email_num_cb (GtkWidget *w, gpointer user_data)
+{
+ PopupInfo *info = (PopupInfo *) user_data;
+ gint n;
+ EDestination *dest;
+
+ if (info == NULL)
+ return;
+
+ if (! GTK_CHECK_MENU_ITEM (w)->active)
+ return;
+
+ n = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (w), "number"));
+ if (out)
+ fprintf (out, "replacing %d\n", n);
+
+ if (n != e_destination_get_email_num (info->dest)) {
+ dest = e_destination_new ();
+ e_destination_set_card (dest, e_destination_get_card (info->dest), n);
+ e_select_names_model_replace (info->model, info->index, dest);
+
+ }
+}
+
+static void
+remove_recipient_cb (GtkWidget *w, gpointer user_data)
+{
+ PopupInfo *info = (PopupInfo *) user_data;
+ e_select_names_model_delete (info->model, info->index);
+}
+
+static void
+add_remove_recipient (GnomeUIInfo *uiinfo, PopupInfo *info)
+{
+ uiinfo->type = GNOME_APP_UI_ITEM;
+ uiinfo->label = _("Remove");
+ uiinfo->moreinfo = remove_recipient_cb;
+}
+
+static void
+remove_all_recipients_cb (GtkWidget *w, gpointer user_data)
+{
+ PopupInfo *info = (PopupInfo *) user_data;
+ e_select_names_model_delete_all (info->model);
+}
+
+static void
+add_remove_all_recipients (GnomeUIInfo *uiinfo, PopupInfo *info)
+{
+ uiinfo->type = GNOME_APP_UI_ITEM;
+ uiinfo->label = _("Remove All");
+ uiinfo->moreinfo = remove_all_recipients_cb;
+}
+
+#define ARBITRARY_UIINFO_LIMIT 64
+static GtkWidget *
+popup_menu_card (PopupInfo *info)
+{
+ GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT];
+ GnomeUIInfo radioinfo[ARBITRARY_UIINFO_LIMIT];
+ gboolean using_radio = FALSE;
+ ECard *card;
+ gint i=0;
+ GtkWidget *pop;
+ EIterator *iterator;
+ gchar *name_str;
+
+ if (out)
+ fprintf (out, "popup_menu_card\n");
+
+ /*
+ * Build up our GnomeUIInfo array.
+ */
+
+ memset (uiinfo, 0, sizeof (uiinfo));
+ memset (radioinfo, 0, sizeof (radioinfo));
+
+ card = e_destination_get_card (info->dest);
+ name_str = e_card_name_to_string (card->name);
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = name_str;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+
+ if (e_list_length (card->email) > 1) {
+ gint j = 0;
+
+ using_radio = TRUE;
+
+ iterator = e_list_get_iterator (card->email);
+ for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) {
+
+ radioinfo[j].type = GNOME_APP_UI_ITEM;
+ radioinfo[j].label = (gchar *)e_iterator_get (iterator);
+ radioinfo[j].moreinfo = change_email_num_cb;
+ ++j;
+ }
+
+ radioinfo[j].type = GNOME_APP_UI_ENDOFINFO;
+
+ uiinfo[i].type = GNOME_APP_UI_RADIOITEMS;
+ uiinfo[i].moreinfo = radioinfo;
+ ++i;
+
+ } else {
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = (gchar *) e_destination_get_email (info->dest);
+ ++i;
+ }
+
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = N_("Edit Contact Info");
+ uiinfo[i].moreinfo = do_nothing;
+ ++i;
+
+ add_remove_recipient (&(uiinfo[i]), info);
+ ++i;
+
+ add_remove_all_recipients (&(uiinfo[i]), info);
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+
+ /*
+ * Now do something with it...
+ */
+
+ pop = gnome_popup_menu_new (uiinfo);
+ g_free (name_str);
+
+ if (using_radio) {
+ gint n = e_destination_get_email_num (info->dest);
+ gint j;
+ for (j=0; radioinfo[j].type != GNOME_APP_UI_ENDOFINFO; ++j) {
+ gtk_object_set_data (GTK_OBJECT (radioinfo[j].widget), "number", GINT_TO_POINTER (j));
+ if (j == n)
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (radioinfo[n].widget), TRUE);
+ }
+ }
+
+ if (out)
+ fprintf (out, "leaving popup_menu_card\n");
+
+ return pop;
+}
+
+static void
+quick_add_cb (GtkWidget *w, gpointer user_data)
+{
+ PopupInfo *info = (PopupInfo *) user_data;
+ e_contact_quick_add (NULL, e_destination_get_string (info->dest),
+ NULL, NULL);
+}
+
+static GtkWidget *
+popup_menu_nocard (PopupInfo *info)
+{
+ GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT];
+ gint i=0;
+ GtkWidget *pop;
+ const gchar *str;
+
+ memset (uiinfo, 0, sizeof (uiinfo));
+
+ str = e_destination_get_string (info->dest);
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = (gchar *) str;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = _("Add to Contacts");
+ uiinfo[i].moreinfo = quick_add_cb;
+ ++i;
+
+ add_remove_recipient (&(uiinfo[i]), info);
+ ++i;
+
+ add_remove_all_recipients (&(uiinfo[i]), info);
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+
+ pop = gnome_popup_menu_new (uiinfo);
+
+ return pop;
+}
+
+
+void
+e_select_names_popup (ESelectNamesModel *model, GdkEventButton *ev, gint pos)
+{
+ GtkWidget *popup;
+ PopupInfo *info;
+ const EDestination *dest;
+ ECard *card;
+ gint index;
+
+ g_return_if_fail (model && E_IS_SELECT_NAMES_MODEL (model));
+ g_return_if_fail (ev);
+ g_return_if_fail (0 <= pos);
+
+ if (out == NULL) {
+ out = fopen ("/tmp/evo-debug-select-names-popup", "w");
+ if (out)
+ setvbuf (out, NULL, _IONBF, 0);
+ }
+
+ if (out)
+ fprintf (out, "\n\ne_select_names_popup\n");
+
+ e_select_names_model_text_pos (model, pos, &index, NULL, NULL);
+ if (index < 0 || index >= e_select_names_model_count (model))
+ return;
+
+ dest = e_select_names_model_get_destination (model, index);
+ card = e_destination_get_card (dest);
+
+ info = popup_info_new (model, dest, pos, index);
+
+ popup = card ? popup_menu_card (info) : popup_menu_nocard (info);
+
+ if (popup) {
+ /* Clean up our info item after we've made our selection. */
+ gtk_signal_connect (GTK_OBJECT (popup),
+ "selection-done",
+ GTK_SIGNAL_FUNC (popup_info_cleanup),
+ info);
+
+ if (out)
+ fprintf (out, "doing popup\n");
+
+ gnome_popup_menu_do_popup (popup, NULL, NULL, ev, info);
+
+ } else {
+
+ popup_info_free (info);
+
+ }
+
+ if (out)
+ fprintf (out, "leaving e_select_names_popup\n\n");
+
+}
diff --git a/addressbook/gui/component/select-names/e-select-names-popup.h b/addressbook/gui/component/select-names/e-select-names-popup.h
new file mode 100644
index 0000000000..cc93534181
--- /dev/null
+++ b/addressbook/gui/component/select-names/e-select-names-popup.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-select-names-popup.h
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#ifndef __E_SELECT_NAMES_POPUP_H__
+#define __E_SELECT_NAMES_POPUP_H__
+
+#include "e-select-names-model.h"
+
+void e_select_names_popup (ESelectNamesModel *model, GdkEventButton *ev, gint pos);
+
+#endif /* __E_SELECT_NAMES_POPUP_H__ */
+
diff --git a/addressbook/gui/contact-editor/Makefile.am b/addressbook/gui/contact-editor/Makefile.am
index d5ed7feeaa..700be0ff35 100644
--- a/addressbook/gui/contact-editor/Makefile.am
+++ b/addressbook/gui/contact-editor/Makefile.am
@@ -22,7 +22,9 @@ libecontacteditor_a_SOURCES = \
e-contact-editor.c \
e-contact-editor.h \
e-contact-save-as.c \
- e-contact-save-as.h
+ e-contact-save-as.h \
+ e-contact-quick-add.c \
+ e-contact-quick-add.h
noinst_PROGRAMS = \
contact-editor-test
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
new file mode 100644
index 0000000000..f27fdf9553
--- /dev/null
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -0,0 +1,282 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-contact-quick-add.c
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#include <config.h>
+#include <gnome.h>
+#include <addressbook/backend/ebook/e-book.h>
+#include <addressbook/backend/ebook/e-card.h>
+#include "e-contact-editor.h"
+#include "e-contact-quick-add.h"
+
+static FILE *out = NULL;
+
+static void
+e_card_quick_set_name (ECard *card, const gchar *str)
+{
+ g_return_if_fail (card && E_IS_CARD (card));
+
+ if (str == NULL)
+ return;
+
+ if (out)
+ fprintf (out, "quick-set name to \"%s\"\n", str);
+
+ if (card->name)
+ e_card_name_free (card->name);
+ card->name = e_card_name_from_string (str);
+}
+
+static void
+e_card_quick_set_email (ECard *card, const gchar *str)
+{
+ g_return_if_fail (card && E_IS_CARD (card));
+
+ if (str == NULL)
+ return;
+
+ if (out)
+ fprintf (out, "quick-set email to \"%s\"\n", str);
+
+ if (card->email == NULL) {
+ card->email = e_list_new ((EListCopyFunc) g_strdup,
+ (EListFreeFunc) g_free,
+ NULL);
+ e_list_append (card->email, str);
+ } else {
+ EIterator *iter = e_list_get_iterator (card->email);
+ e_iterator_reset (iter);
+ if (e_iterator_is_valid (iter)) {
+ e_iterator_set (iter, str);
+ }
+ }
+}
+
+
+static void
+book_ready_cb (EBook *book, EBookStatus status, gpointer user_data)
+{
+ if (status == E_BOOK_STATUS_SUCCESS)
+ e_book_add_card (book, E_CARD (user_data), NULL, NULL);
+ gtk_object_unref (GTK_OBJECT (book));
+}
+
+static void
+add_card (ECard *card)
+{
+ EBook *book = e_book_new ();
+ gchar *filename, *uri;
+
+ filename = gnome_util_prepend_user_home ("evolution/local/Contacts/addressbook.db");
+ uri = g_strdup_printf ("file://%s", filename);
+
+ e_book_load_uri (book, uri, book_ready_cb, card);
+
+ g_free (filename);
+ g_free (uri);
+}
+
+static void
+add_card_cb (EContactEditor *ce, ECard *card, gpointer user_data)
+{
+ add_card (card);
+}
+
+static void
+editor_closed_cb (GtkWidget *w, gpointer user_data)
+{
+ if (user_data)
+ gtk_object_unref (user_data);
+ gtk_object_unref (GTK_OBJECT (w));
+}
+
+static void
+clicked_cb (GtkWidget *w, gint button, gpointer user_data)
+{
+ ECard *card = E_CARD (user_data);
+
+ /* Get data out of entries. */
+ if (button == 0 || button == 1) {
+ gpointer name_entry;
+ gpointer email_entry;
+ gchar *name = NULL;
+ gchar *email = NULL;
+
+ name_entry = gtk_object_get_data (GTK_OBJECT (card), "e-contact-quick-add-name-entry");
+ email_entry = gtk_object_get_data (GTK_OBJECT (card), "e-contact-quick-add-email-entry");
+
+ if (name_entry)
+ name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
+ if (email_entry)
+ email = gtk_editable_get_chars (GTK_EDITABLE (email_entry), 0, -1);
+
+ e_card_quick_set_name (card, name);
+ e_card_quick_set_email (card, email);
+
+ g_free (name);
+ g_free (email);
+ }
+
+ gtk_widget_destroy (w);
+
+ if (button == 0) { /* OK */
+
+ add_card (card);
+
+ } else if (button == 1) {
+
+ /* EDIT FULL */
+ EContactEditor *contact_editor;
+ contact_editor = e_contact_editor_new (card, TRUE);
+
+ gtk_signal_connect (GTK_OBJECT (contact_editor),
+ "add_card",
+ GTK_SIGNAL_FUNC (add_card_cb),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (contact_editor),
+ "editor_closed",
+ GTK_SIGNAL_FUNC (editor_closed_cb),
+ user_data);
+
+ e_contact_editor_raise (contact_editor);
+
+ } else {
+ /* CANCEL */
+ gtk_object_unref (user_data);
+ }
+
+}
+
+static GtkWidget *
+build_quick_add_dialog (ECard *new_card, EContactQuickAddCallback cb, gpointer user_data)
+{
+ GtkWidget *dialog;
+ GtkTable *table;
+ GtkWidget *name_entry;
+ GtkWidget *email_entry;
+ const gint xpad=1, ypad=1;
+
+ g_return_val_if_fail (new_card && E_IS_CARD (new_card), NULL);
+
+ dialog = gnome_dialog_new (_("Contact Quick-Add"),
+ GNOME_STOCK_BUTTON_OK,
+ _("Edit Full"),
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+
+ gtk_signal_connect (GTK_OBJECT (dialog),
+ "clicked",
+ clicked_cb,
+ new_card);
+
+ name_entry = gtk_entry_new ();
+
+ if (new_card->name) {
+ gchar *str = e_card_name_to_string (new_card->name);
+ gtk_entry_set_text (GTK_ENTRY (name_entry), str);
+ g_free (str);
+ }
+
+
+ email_entry = gtk_entry_new ();
+
+ if (new_card->email && e_list_length (new_card->email)) {
+ EIterator *iterator = e_list_get_iterator (new_card->email);
+ if (iterator) {
+ e_iterator_reset (iterator);
+ if (e_iterator_is_valid (iterator)) {
+ const gchar *str = e_iterator_get (iterator);
+ gtk_entry_set_text (GTK_ENTRY (email_entry), str);
+ }
+ }
+ }
+
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-name-entry", name_entry);
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-email-entry", email_entry);
+
+
+ table = GTK_TABLE (gtk_table_new (2, 2, FALSE));
+
+ gtk_table_attach (table, gtk_label_new (_("Full Name")),
+ 0, 1, 0, 1,
+ 0, 0, xpad, ypad);
+ gtk_table_attach (table, name_entry,
+ 1, 2, 0, 1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND, xpad, ypad);
+ gtk_table_attach (table, gtk_label_new (_("E-mail")),
+ 0, 1, 1, 2,
+ 0, 0, xpad, ypad);
+ gtk_table_attach (table, email_entry,
+ 1, 2, 1, 2,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND, xpad, ypad);
+
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+ GTK_WIDGET (table),
+ TRUE, TRUE, 0);
+ gtk_widget_show_all (GTK_WIDGET (table));
+
+
+ return dialog;
+}
+
+void
+e_contact_quick_add (const gchar *name, const gchar *email,
+ EContactQuickAddCallback cb, gpointer user_data)
+{
+ ECard *new_card;
+ GtkWidget *dialog;
+
+ if (out == NULL) {
+ out = fopen ("/tmp/barnass", "w");
+ if (out)
+ setvbuf (out, NULL, _IONBF, 0);
+ }
+
+ if (out)
+ fprintf (out, "\n name: %s\nemail: %s\n", name, email);
+
+
+ /* We need to have *something* to work with. */
+ if (name == NULL && email == NULL) {
+ if (cb)
+ cb (NULL, user_data);
+ return;
+ }
+
+ new_card = e_card_new ("");
+ if (cb)
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-cb", cb);
+ if (user_data)
+ gtk_object_set_data (GTK_OBJECT (new_card), "e-contact-quick-add-user-data", user_data);
+
+
+ e_card_quick_set_name (new_card, name);
+ e_card_quick_set_email (new_card, email);
+
+ dialog = build_quick_add_dialog (new_card, cb, user_data);
+
+ gtk_widget_show_all (dialog);
+}
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.h b/addressbook/gui/contact-editor/e-contact-quick-add.h
new file mode 100644
index 0000000000..630dfd2ad0
--- /dev/null
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-contact-quick-add.h
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Developed by Jon Trowbridge <trow@ximian.com>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ */
+
+#ifndef __E_CONTACT_QUICK_ADD_H__
+#define __E_CONTACT_QUICK_ADD_H__
+
+#include <gtk/gtk.h>
+#include <addressbook/backend/ebook/e-card.h>
+
+typedef void (*EContactQuickAddCallback) (ECard *new_card, gpointer user_data);
+
+void e_contact_quick_add (const gchar *name, const gchar *email,
+ EContactQuickAddCallback cb, gpointer user_data);
+
+#endif /* __E_CONTACT_QUICK_ADD_H__ */
+