aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component/e-address-widget.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-03-09 07:15:20 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-03-09 07:15:20 +0800
commitafe6fc18fc95f00efdbd3ea7f5ebd6c7fd64330d (patch)
treecce5d4763c2eda00558c1d6a0b38861417befc91 /addressbook/gui/component/e-address-widget.c
parenta9c279d8a69c93d00d0c8eb5c876f42e8a99682f (diff)
downloadgsoc2013-evolution-afe6fc18fc95f00efdbd3ea7f5ebd6c7fd64330d.tar.gz
gsoc2013-evolution-afe6fc18fc95f00efdbd3ea7f5ebd6c7fd64330d.tar.zst
gsoc2013-evolution-afe6fc18fc95f00efdbd3ea7f5ebd6c7fd64330d.zip
Switched to use e_contact_quick_add_free_form. Removed debugging code,
2001-03-08 Jon Trowbridge <trow@ximian.com> * gui/component/select-names/e-select-names-popup.c (quick_add_cb): Switched to use e_contact_quick_add_free_form. Removed debugging code, hopefully without introducing any bugs in the process. * gui/component/select-names/e-select-names-text-model.c (e_select_names_text_model_insert_length): Fix bug with commas inside of name/address combos. As long as the comma is inside of quotes, it will be treated as part of the name rather than as a break between addresses. * gui/component/select-names/e-select-names-completion.c (match_nickname): Use e_card_name_to_string for nickname match strings. (match_email): Use e_card_name_to_string for email match strings. (e_select_names_completion_begin): Strip quotes out of query text, so we don't produce malformed sexps. Added William Blake quote easter egg. * contact-editor/e-contact-quick-add.c: Further attempts to fix... mostly unsuccessful. (e_contact_quick_add_free_form): Added. Takes a single string and tries to parse out (using some simple, loose rules) the name and e-mail -- then calls e_contact_quick_add. An attempt to get the computer to automatically Do The Right Thing. * backend/ebook/e-book.c: Fixed some broken indentation. Yes, I'm anal. * gui/component/GNOME_Evolution_Addressbook.oafinfo: Added oaf_server info for EAddressWidget. * gui/component/GNOME_Evolution_Addressbook.oaf.in: Added oaf_server info for EAddressWidget. * gui/component/addressbook-factory.c (main): Add call to e_address_widget_factory_init. * gui/component/e-address-widget.h: * gui/component/e-address-widget.c: Added. A little widget (and a Bonobo control, BTW) for displaying addresses, with a left-click menu. Used to display addresses in the mail viewer (as embedded GtkHTML objects, replacing the text previously used). Still quite incomplete. 2001-03-08 Jon Trowbridge <trow@ximian.com> * mail-format.c (write_field_row_begin): Added. Table row HTML broken out into its own function. (write_subject): Added. Emits the proper HTML for the subject line. (write_field_to_stream): #ifdef-ed out of existence. (write_address): Take a CamelInternetAddress and spit out an <object> tag with the appropriate <param>s. * mail-display.c (on_object_requested): Check for an "address" object. If found, call... (handle_embedded_address_object): ...this function, which creates an AddressWidget bonobo control and passes in the necessary info. I never really realized just quite how much GtkHTML kicks ass until I figured out how to make this work. svn path=/trunk/; revision=8607
Diffstat (limited to 'addressbook/gui/component/e-address-widget.c')
-rw-r--r--addressbook/gui/component/e-address-widget.c414
1 files changed, 414 insertions, 0 deletions
diff --git a/addressbook/gui/component/e-address-widget.c b/addressbook/gui/component/e-address-widget.c
new file mode 100644
index 0000000000..2af83e67aa
--- /dev/null
+++ b/addressbook/gui/component/e-address-widget.c
@@ -0,0 +1,414 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * e-address-widget.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 <bonobo/bonobo-control.h>
+#include <bonobo/bonobo-property-bag.h>
+#include <bonobo/bonobo-generic-factory.h>
+#include <addressbook/contact-editor/e-contact-quick-add.h>
+#include "e-address-widget.h"
+
+static void e_address_widget_class_init (EAddressWidgetClass *klass);
+static void e_address_widget_init (EAddressWidget *obj);
+static void e_address_widget_destroy (GtkObject *obj);
+
+static gint e_address_widget_button_press_handler (GtkWidget *w, GdkEventButton *ev);
+static void e_address_widget_popup (EAddressWidget *, GdkEventButton *ev);
+
+static GtkObjectClass *parent_class;
+
+static void
+e_address_widget_class_init (EAddressWidgetClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *) klass;
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ parent_class = GTK_OBJECT_CLASS (gtk_type_class (gtk_event_box_get_type ()));
+
+ object_class->destroy = e_address_widget_destroy;
+
+ widget_class->button_press_event = e_address_widget_button_press_handler;
+}
+
+static void
+e_address_widget_init (EAddressWidget *addr)
+{
+
+}
+
+static void
+e_address_widget_destroy (GtkObject *obj)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (obj);
+
+ g_free (addr->name);
+ g_free (addr->email);
+ if (addr->card)
+ gtk_object_unref (GTK_OBJECT (addr->card));
+}
+
+static gint
+e_address_widget_button_press_handler (GtkWidget *w, GdkEventButton *ev)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (w);
+ if (ev->button == 3 && ev->state == 0) {
+ e_address_widget_popup (addr, ev);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+GtkType
+e_address_widget_get_type (void)
+{
+ static GtkType aw_type = 0;
+
+ if (!aw_type) {
+ GtkTypeInfo aw_info = {
+ "EAddressWidget",
+ sizeof (EAddressWidget),
+ sizeof (EAddressWidgetClass),
+ (GtkClassInitFunc) e_address_widget_class_init,
+ (GtkObjectInitFunc) e_address_widget_init,
+ NULL, NULL, /* reserved... but for what sinister purpose? */
+ (GtkClassInitFunc) NULL
+ };
+
+ aw_type = gtk_type_unique (gtk_event_box_get_type (), &aw_info);
+ }
+
+ return aw_type;
+}
+
+static void
+gtk_widget_visible (GtkWidget *w, gboolean x)
+{
+ if (x)
+ gtk_widget_show (w);
+ else
+ gtk_widget_hide (w);
+}
+
+static void
+e_address_widget_refresh (EAddressWidget *addr)
+{
+ gchar *str;
+ gboolean have_name, have_email;
+
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ have_name = addr->name && *addr->name;
+ have_email = addr->email && *addr->email;
+
+ gtk_label_set_text (GTK_LABEL (addr->name_widget), have_name ? addr->name : "");
+ gtk_widget_visible (addr->name_widget, have_name);
+
+ if (have_email) {
+ str = g_strdup_printf (have_name ? "<%s>" : "%s", addr->email);
+ gtk_label_set_text (GTK_LABEL (addr->email_widget), str);
+ g_free (str);
+ } else {
+ gtk_label_set_text (GTK_LABEL (addr->email_widget), "");
+ }
+ gtk_widget_visible (addr->email_widget, have_email);
+
+ gtk_widget_visible (addr->spacer, have_name && have_email);
+
+ /* Launch a query to find the appropriate card, if necessary. */
+ addr->querying = TRUE;
+}
+
+void
+e_address_widget_set_name (EAddressWidget *addr, const gchar *name)
+{
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ g_free (addr->name);
+ addr->name = g_strdup (name);
+
+ e_address_widget_refresh (addr);
+}
+
+void
+e_address_widget_set_email (EAddressWidget *addr, const gchar *email)
+{
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ g_free (addr->email);
+ addr->email = g_strdup (email);
+
+ e_address_widget_refresh (addr);
+}
+
+
+void
+e_address_widget_set_text (EAddressWidget *addr, const gchar *text)
+{
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ e_address_widget_set_email (addr, text); /* CRAP */
+}
+
+void
+e_address_widget_construct (EAddressWidget *addr)
+{
+ GtkWidget *box;
+
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ box = gtk_hbox_new (FALSE, 2);
+
+ addr->name_widget = gtk_label_new ("");
+ addr->spacer = gtk_label_new (" ");
+ addr->email_widget = gtk_label_new ("");
+
+ gtk_box_pack_start (GTK_BOX (box), addr->name_widget, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), addr->spacer, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), addr->email_widget, FALSE, FALSE, 0);
+
+
+ gtk_container_add (GTK_CONTAINER (addr), box);
+
+ gtk_widget_show (box);
+ gtk_widget_show (addr->name_widget);
+ gtk_widget_show (addr->email_widget);
+}
+
+GtkWidget *
+e_address_widget_new (void)
+{
+ EAddressWidget *addr = gtk_type_new (e_address_widget_get_type ());
+ e_address_widget_construct (addr);
+ return GTK_WIDGET (addr);
+}
+
+/*
+ *
+ * Popup Menu
+ *
+ */
+
+#define ARBITRARY_UIINFO_LIMIT 64
+static GtkWidget *
+popup_menu_card (EAddressWidget *addr)
+{
+ ECard *card = E_CARD (addr->card);
+ g_return_val_if_fail (card != NULL, NULL);
+
+ return NULL;
+}
+
+static void
+add_contacts_cb (GtkWidget *w, gpointer user_data)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (user_data);
+
+ e_contact_quick_add (addr->name, addr->email, NULL, NULL);
+}
+
+static GtkWidget *
+popup_menu_nocard (EAddressWidget *addr)
+{
+ GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT];
+ GtkWidget *pop;
+ gint i=0, dead;
+
+ memset (uiinfo, 0, sizeof (uiinfo));
+
+ if (addr->name) {
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = addr->name;
+ ++i;
+ }
+
+ if (addr->email) {
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = addr->email;
+ ++i;
+ }
+ dead = i;
+
+ uiinfo[i].type = GNOME_APP_UI_SEPARATOR;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ITEM;
+ uiinfo[i].label = N_("Add to Contacts");
+ uiinfo[i].moreinfo = add_contacts_cb;
+ ++i;
+
+ uiinfo[i].type = GNOME_APP_UI_ENDOFINFO;
+
+
+ pop = gnome_popup_menu_new (uiinfo);
+ for (i=0; i<dead; ++i)
+ dead_item (GTK_ITEM (uiinfo[i].widget));
+ return pop;
+}
+
+static void
+e_address_widget_popup (EAddressWidget *addr, GdkEventButton *ev)
+{
+ GtkWidget *pop;
+
+ g_return_if_fail (addr && E_IS_ADDRESS_WIDGET (addr));
+
+ pop = addr->card ? popup_menu_card (addr) : popup_menu_nocard (addr);
+
+ if (pop)
+ gnome_popup_menu_do_popup (pop, NULL, NULL, ev, addr);
+}
+
+/*
+ *
+ * Bonobo Control Magic
+ *
+ */
+
+enum {
+ ADDRESS_PROPERTY_NAME,
+ ADDRESS_PROPERTY_EMAIL,
+ ADDRESS_PROPERTY_TEXT,
+ ADDRESS_PROPERTY_BACKGROUND_RGB
+};
+
+
+static void
+get_prop (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, CORBA_Environment *ev, gpointer user_data)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (user_data);
+
+ switch (arg_id) {
+
+ case ADDRESS_PROPERTY_NAME:
+ BONOBO_ARG_SET_STRING (arg, addr->name ? addr->name :"");
+ break;
+
+ case ADDRESS_PROPERTY_EMAIL:
+ BONOBO_ARG_SET_STRING (arg, addr->email ? addr->email : "");
+ break;
+
+ case ADDRESS_PROPERTY_TEXT:
+ BONOBO_ARG_SET_STRING (arg, "?");
+ break;
+ }
+}
+
+static void
+set_prop (BonoboPropertyBag *bag, const BonoboArg *arg, guint arg_id, CORBA_Environment *ev, gpointer user_data)
+{
+ EAddressWidget *addr = E_ADDRESS_WIDGET (user_data);
+
+ switch (arg_id) {
+ case ADDRESS_PROPERTY_NAME:
+ e_address_widget_set_name (addr, BONOBO_ARG_GET_STRING (arg));
+ break;
+
+ case ADDRESS_PROPERTY_EMAIL:
+ e_address_widget_set_email (addr, BONOBO_ARG_GET_STRING (arg));
+ break;
+
+ case ADDRESS_PROPERTY_TEXT:
+ e_address_widget_set_text (addr, BONOBO_ARG_GET_STRING (arg));
+ break;
+
+
+ case ADDRESS_PROPERTY_BACKGROUND_RGB:
+ {
+ gint bg = BONOBO_ARG_GET_INT (arg);
+ GdkColor color;
+
+ color.red = (bg & 0xff0000) >> 8;
+ color.green = (bg & 0x00ff00);
+ color.blue = (bg & 0x0000ff) << 8;
+
+ if (gdk_colormap_alloc_color (gtk_widget_get_colormap (GTK_WIDGET (addr)), &color, FALSE, TRUE)) {
+ GtkStyle *style = gtk_style_copy (gtk_widget_get_style (GTK_WIDGET (addr)));
+ style->bg[0] = color;
+ gtk_widget_set_style (GTK_WIDGET (addr), style);
+ }
+ }
+
+ break;
+ }
+}
+
+static BonoboControl *
+e_address_widget_factory_new_control (void)
+{
+ BonoboControl *control;
+ BonoboPropertyBag *bag;
+ GtkWidget *w;
+
+ w = e_address_widget_new ();
+ gtk_widget_show (w);
+
+ control = bonobo_control_new (w);
+
+ bag = bonobo_property_bag_new (get_prop, set_prop, w);
+ bonobo_property_bag_add (bag, "name", ADDRESS_PROPERTY_NAME,
+ BONOBO_ARG_STRING, NULL, NULL,
+ BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
+
+ bonobo_property_bag_add (bag, "email", ADDRESS_PROPERTY_EMAIL,
+ BONOBO_ARG_STRING, NULL, NULL,
+ BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
+
+ bonobo_property_bag_add (bag, "text", ADDRESS_PROPERTY_TEXT,
+ BONOBO_ARG_STRING, NULL, NULL,
+ BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
+
+ bonobo_property_bag_add (bag, "background_rgb", ADDRESS_PROPERTY_BACKGROUND_RGB,
+ BONOBO_ARG_INT, NULL, NULL,
+ BONOBO_PROPERTY_WRITEABLE);
+
+ bonobo_control_set_properties (control, bag);
+ bonobo_object_unref (BONOBO_OBJECT (bag));
+
+ return control;
+}
+
+static BonoboObject *
+e_address_widget_factory (BonoboGenericFactory *factory, gpointer user_data)
+{
+ return BONOBO_OBJECT (e_address_widget_factory_new_control ());
+}
+
+void
+e_address_widget_factory_init (void)
+{
+ static BonoboGenericFactory *factory = NULL;
+
+ if (factory != NULL)
+ return;
+
+ factory = bonobo_generic_factory_new ("OAFIID:GNOME_Evolution_Addressbook_AddressWidgetFactory",
+ e_address_widget_factory, NULL);
+
+ if (factory == NULL)
+ g_error ("I could not register an AddressWidget factory.");
+}