aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component/select-names/e-select-names-popup.c
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 /addressbook/gui/component/select-names/e-select-names-popup.c
parent10d0e730eccccf34fc53dc8c1d6145fca1f52f57 (diff)
downloadgsoc2013-evolution-e6e1655f31dca8aceb4c97c966d44bac23eb7200.tar.gz
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
Diffstat (limited to 'addressbook/gui/component/select-names/e-select-names-popup.c')
-rw-r--r--addressbook/gui/component/select-names/e-select-names-popup.c345
1 files changed, 345 insertions, 0 deletions
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");
+
+}