aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-07-18 17:43:36 +0800
committerChris Lahey <clahey@src.gnome.org>2000-07-18 17:43:36 +0800
commit32a10931a91628394db1185cb2e582ab0952dcb9 (patch)
tree70370f6d8be7cfb0a15238893e31fcd4bb130f06
parent9cad440d041093c75b601364d3038c082686c81a (diff)
downloadgsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar.gz
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar.bz2
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar.lz
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar.xz
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.tar.zst
gsoc2013-evolution-32a10931a91628394db1185cb2e582ab0952dcb9.zip
New files for using a minicard as a widget or a bonobo control.
2000-07-18 Christopher James Lahey <clahey@helixcode.com> * gui/minicard/e-minicard-control.c, gui/minicard/e-minicard-control.h, gui/minicard/e-minicard-widget.c, gui/minicard/e-minicard-widget.h: New files for using a minicard as a widget or a bonobo control. svn path=/trunk/; revision=4209
-rw-r--r--addressbook/ChangeLog8
-rw-r--r--addressbook/gui/minicard/e-minicard-control.c307
-rw-r--r--addressbook/gui/minicard/e-minicard-control.h8
-rw-r--r--addressbook/gui/minicard/e-minicard-widget.c214
-rw-r--r--addressbook/gui/minicard/e-minicard-widget.h76
-rw-r--r--addressbook/gui/widgets/e-minicard-control.c307
-rw-r--r--addressbook/gui/widgets/e-minicard-control.h8
-rw-r--r--addressbook/gui/widgets/e-minicard-widget.c214
-rw-r--r--addressbook/gui/widgets/e-minicard-widget.h76
9 files changed, 1218 insertions, 0 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 6660365388..b9ace1e755 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,11 @@
+2000-07-18 Christopher James Lahey <clahey@helixcode.com>
+
+ * gui/minicard/e-minicard-control.c,
+ gui/minicard/e-minicard-control.h,
+ gui/minicard/e-minicard-widget.c,
+ gui/minicard/e-minicard-widget.h: New files for using a minicard
+ as a widget or a bonobo control.
+
2000-07-14 Chris Toshok <toshok@helixcode.com>
* gui/component/e-ldap-storage.c (ldap_server_foreach): duh.
diff --git a/addressbook/gui/minicard/e-minicard-control.c b/addressbook/gui/minicard/e-minicard-control.c
new file mode 100644
index 0000000000..8cac2dc15e
--- /dev/null
+++ b/addressbook/gui/minicard/e-minicard-control.c
@@ -0,0 +1,307 @@
+/*
+ * e-minicard-control.c
+ *
+ * Authors:
+ * Chris Lahey <clahey@helixcode.com>
+ *
+ * Copyright 1999, 2000, Helix Code, Inc.
+ */
+
+#include <config.h>
+#include <gnome.h>
+#include <bonobo.h>
+
+#include "e-minicard-factory.h"
+
+#if 0
+enum {
+ PROP_RUNNING
+} MyArgs;
+
+#define RUNNING_KEY "Clock::Running"
+
+static void
+get_prop (BonoboPropertyBag *bag,
+ BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ GtkObject *clock = user_data;
+
+ switch (arg_id) {
+
+ case PROP_RUNNING:
+ {
+ gboolean b = GPOINTER_TO_UINT (gtk_object_get_data (clock, RUNNING_KEY));
+ BONOBO_ARG_SET_BOOLEAN (arg, b);
+ break;
+ }
+
+ default:
+ g_warning ("Unhandled arg %d", arg_id);
+ break;
+ }
+}
+
+static void
+set_prop (BonoboPropertyBag *bag,
+ const BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ GtkClock *clock = user_data;
+
+ switch (arg_id) {
+
+ case PROP_RUNNING:
+ {
+ guint i;
+
+ i = BONOBO_ARG_GET_BOOLEAN (arg);
+
+ if (i)
+ gtk_clock_start (clock);
+ else
+ gtk_clock_stop (clock);
+
+ gtk_object_set_data (GTK_OBJECT (clock), RUNNING_KEY,
+ GUINT_TO_POINTER (i));
+ break;
+ }
+
+ default:
+ g_warning ("Unhandled arg %d", arg_id);
+ break;
+ }
+}
+#endif
+
+/*
+ * Bonobo::PersistStream
+ *
+ * These two functions implement the Bonobo::PersistStream load and
+ * save methods which allow data to be loaded into and out of the
+ * BonoboObject.
+ */
+static int
+stream_read (Bonobo_Stream stream)
+{
+ Bonobo_Stream_iobuf *buffer;
+ CORBA_Environment ev;
+ char *data = NULL;
+ gint length = 0;
+
+ CORBA_exception_init (&ev);
+ do {
+#define READ_CHUNK_SIZE 65536
+ Bonobo_Stream_read (stream, READ_CHUNK_SIZE,
+ &buffer, &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+ return NULL;
+ }
+
+ if (buffer->_length <= 0)
+ break;
+
+ data = g_realloc (data,
+ length + buffer->_length);
+
+ memcpy (data + length,
+ buffer->_buffer, buffer->_length);
+
+ length += buffer->_length;
+
+ CORBA_free (buffer);
+ } while (1);
+
+ CORBA_free (buffer);
+ CORBA_exception_free (&ev);
+
+ if (data == NULL)
+ data = g_strdup("");
+
+ return data;
+} /* stream_read */
+
+/*
+ * This function implements the Bonobo::PersistStream:load method.
+ */
+static void
+pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type, void *data,
+ CORBA_Environment *ev)
+{
+ ECard *card;
+ char *vcard;
+ GtkWidget *minicard = data;
+
+ if (*type && g_strcasecmp (type, "text/plain") != 0 &&
+ g_strcasecmp (type, "text/x-vCard") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ if ((vcard = stream_read (stream, embeddable_data)) == NULL) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_FileNotFound, NULL);
+ return;
+ }
+
+ card = e_card_new(vcard);
+ g_free(vcard);
+ gtk_object_set(GTK_OBJECT(minicard),
+ "card", card,
+ NULL);
+ gtk_object_unref(GTK_OBJECT(card));
+} /* pstream_load */
+
+/*
+ * This function implements the Bonobo::PersistStream:save method.
+ */
+static void
+pstream_save (BonoboPersistStream *ps, const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type, void *data,
+ CORBA_Environment *ev)
+{
+ Bonobo_Stream_iobuf *buffer;
+ size_t pos;
+ char *vcard;
+ ECard *card;
+ EMinicardWidget *minicard = data;
+ int length;
+
+ if (*type && g_strcasecmp (type, "text/plain") != 0 &&
+ g_strcasecmp (type, "text/x-vCard") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ buffer = Bonobo_Stream_iobuf__alloc ();
+
+ gtk_object_get(GTK_OBJECT(minicard),
+ "card", &card,
+ NULL);
+ vcard = e_card_get_vcard(card);
+ length = strlen(vcard);
+ data = CORBA_sequence_CORBA_octet_allocbuf (length);
+ memcpy (data, vcard, length);
+
+ buffer->_buffer = data;
+ buffer->_length = length;
+
+ g_free(vcard);
+
+ pos = 0;
+
+ while (pos < length) {
+ CORBA_long bytes_read;
+
+ bytes_read = Bonobo_Stream_write (stream, buffer, ev);
+
+ if (ev->_major != CORBA_NO_EXCEPTION) {
+ CORBA_free (buffer);
+ CORBA_free (data);
+ return;
+ }
+
+ pos += bytes_read;
+ }
+
+ CORBA_free (buffer);
+ CORBA_free (data);
+} /* pstream_save */
+
+static CORBA_long
+pstream_get_max_size (BonoboPersistStream *ps, void *data,
+ CORBA_Environment *ev)
+{
+ GtkWidget *minicard = data;
+ ECard *card;
+ char *vcard;
+
+ gtk_object_get(GTK_OBJECT(minicard),
+ "card", &card,
+ NULL);
+ vcard = e_card_get_vcard(card);
+ length = strlen(vcard);
+ g_free(vcard);
+
+ return length;
+}
+
+static Bonobo_Persist_ContentTypeList *
+pstream_get_content_types (BonoboPersistStream *ps, void *closure,
+ CORBA_Environment *ev)
+{
+ return bonobo_persist_generate_content_types (2, "text/plain", "text/x-vCard");
+}
+
+static BonoboObject *
+e_minicard_factory (BonoboGenericFactory *Factory, void *closure)
+{
+#if 0
+ BonoboPropertyBag *pb;
+#endif
+ BonoboControl *control;
+ BonoboPersistStream *stream;
+ GtkWidget *minicard;
+
+ /* Create the control. */
+ minicard = e_minicard_widget_new ();
+ gtk_widget_show (minicard);
+
+ control = bonobo_control_new (minicard);
+
+ stream = bonobo_persist_stream_new (pstream_load, pstream_save,
+ pstream_get_max_size,
+ pstream_get_content_types,
+ minicard);
+
+#if 0
+ /* Create the properties. */
+ pb = bonobo_property_bag_new (get_prop, set_prop, clock);
+ bonobo_control_set_property_bag (control, pb);
+
+ bonobo_property_bag_add (pb, "running", PROP_RUNNING,
+ BONOBO_ARG_BOOLEAN, NULL,
+ "Whether or not the clock is running", 0);
+#endif
+
+ if (stream == NULL) {
+ bonobo_object_unref (BONOBO_OBJECT (control));
+ return NULL;
+ }
+
+ bonobo_object_add_interface (BONOBO_OBJECT (control),
+ BONOBO_OBJECT (stream));
+
+ return BONOBO_OBJECT (control);
+}
+
+void
+e_minicard_factory_init (void)
+{
+ static BonoboGenericFactory *e_minicard_factory = NULL;
+
+ if (e_minicard_factory != NULL)
+ return;
+
+#if USING_OAF
+ e_minicard_factory =
+ bonobo_generic_factory_new (
+ "OAFIID:e_minicard_factory:f9542709-fb31-4c6a-bc00-d462ba41e4b9",
+ e_minicard_factory, NULL);
+#else
+ e_minicard_factory =
+ bonobo_generic_factory_new (
+ "control-factory:e-minicard",
+ e_minicard_factory, NULL);
+#endif
+
+ if (e_minicard_factory == NULL)
+ g_error ("I could not register a EMinicard factory.");
+}
diff --git a/addressbook/gui/minicard/e-minicard-control.h b/addressbook/gui/minicard/e-minicard-control.h
new file mode 100644
index 0000000000..3b69ec9080
--- /dev/null
+++ b/addressbook/gui/minicard/e-minicard-control.h
@@ -0,0 +1,8 @@
+#ifndef __E_MINICARD_CONTROL_H__
+#define __E_MINICARD_CONTROL_H__
+
+#include <bonobo/bonobo-control.h>
+
+void e_minicard_factory_init (void);
+
+#endif /* __E_MINICARD_CONTROL_H__ */
diff --git a/addressbook/gui/minicard/e-minicard-widget.c b/addressbook/gui/minicard/e-minicard-widget.c
new file mode 100644
index 0000000000..e3b61e9540
--- /dev/null
+++ b/addressbook/gui/minicard/e-minicard-widget.c
@@ -0,0 +1,214 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-table-field-chooser.c
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library 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 library; 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 <e-table-field-chooser.h>
+#include <e-table-field-chooser-item.h>
+
+static void e_minicard_widget_init (EMinicardWidget *card);
+static void e_minicard_widget_class_init (EMinicardWidgetClass *klass);
+static void e_minicard_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
+static void e_minicard_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
+static void e_minicard_widget_destroy (GtkObject *object);
+
+static ECanvas *parent_class = NULL;
+
+/* The arguments we take */
+enum {
+ ARG_0,
+ ARG_CARD,
+};
+
+GtkType
+e_minicard_widget_get_type (void)
+{
+ static GtkType table_field_chooser_type = 0;
+
+ if (!table_field_chooser_type)
+ {
+ static const GtkTypeInfo table_field_chooser_info =
+ {
+ "EMinicardWidget",
+ sizeof (EMinicardWidget),
+ sizeof (EMinicardWidgetClass),
+ (GtkClassInitFunc) e_minicard_widget_class_init,
+ (GtkObjectInitFunc) e_minicard_widget_init,
+ /* reserved_1 */ NULL,
+ /* reserved_2 */ NULL,
+ (GtkClassInitFunc) NULL,
+ };
+
+ table_field_chooser_type = gtk_type_unique (e_canvas_get_type (), &table_field_chooser_info);
+ }
+
+ return table_field_chooser_type;
+}
+
+static void
+e_minicard_widget_class_init (EMinicardWidgetClass *klass)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = (GtkObjectClass*) klass;
+ widget_class = (GtkWidgetClass *) klass;
+
+ parent_class = gtk_type_class (gtk_vbox_get_type ());
+
+ object_class->set_arg = e_minicard_widget_set_arg;
+ object_class->get_arg = e_minicard_widget_get_arg;
+ object_class->destroy = e_minicard_widget_destroy;
+
+ widget_class->size_request = e_minicard_widget_size_request;
+ widget_class->size_allocate = e_minicard_widget_size_allocate;
+ gtk_object_add_arg_type ("EMinicardWidget::card", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_CARD);
+}
+
+static void
+e_minicard_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
+{
+ double height;
+ EMinicardWidget *emw = E_MINICARD_WIDGET(widget);
+ gnome_canvas_item_set( emw->item,
+ "width", (double) allocation->width,
+ NULL );
+ gtk_object_get(GTK_OBJECT(emw->item),
+ "height", &height,
+ NULL);
+ height = MAX(height, allocation->height);
+ gnome_canvas_set_scroll_region(GNOME_CANVAS( emw->canvas ), 0, 0, allocation->width - 1, height - 1);
+ gnome_canvas_item_set( emw->rect,
+ "x2", (double) allocation->width,
+ "y2", (double) height,
+ NULL );
+ if (GTK_WIDGET_CLASS(parent_class)->size_allocate)
+ GTK_WIDGET_CLASS(parent_class)->size_allocate(widget, allocation);
+}
+
+static void resize(GnomeCanvas *canvas, EMinicardWidget *emw)
+{
+ double height;
+ gtk_object_get(GTK_OBJECT(emw->item),
+ "height", &height,
+ NULL);
+
+ height = MAX(height, emw->last_alloc.height);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS(emw->canvas), 0, 0, emw->last_alloc.width - 1, height - 1);
+ gnome_canvas_item_set( emw->rect,
+ "x2", (double) emw->last_alloc.width,
+ "y2", (double) height,
+ NULL );
+}
+
+static void
+e_minicard_widget_init (EMinicardWidget *emw)
+{
+ emw->rect = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS( emw->canvas ) ),
+ gnome_canvas_rect_get_type(),
+ "x1", (double) 0,
+ "y1", (double) 0,
+ "x2", (double) 100,
+ "y2", (double) 100,
+ "fill_color", "white",
+ NULL );
+
+ emw->item = gnome_canvas_item_new(gnome_canvas_root(emw->canvas),
+ e_minicard_widget_item_get_type(),
+ "width", (double) 100,
+ NULL );
+
+ gtk_signal_connect( GTK_OBJECT( emw->canvas ), "reflow",
+ GTK_SIGNAL_FUNC( resize ),
+ emw);
+
+ gnome_canvas_set_scroll_region ( GNOME_CANVAS( emw->canvas ),
+ 0, 0,
+ 100, 100 );
+
+ /* Connect the signals */
+ gtk_signal_connect (GTK_OBJECT (emw->canvas), "size_allocate",
+ GTK_SIGNAL_FUNC (allocate_callback),
+ emw);
+}
+
+static void
+e_minicard_widget_destroy (GtkObject *object)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ g_free(emw->dnd_code);
+ if (emw->full_header)
+ gtk_object_unref(GTK_OBJECT(emw->full_header));
+
+ if (emw->gui)
+ gtk_object_unref(GTK_OBJECT(emw->gui));
+}
+
+GtkWidget*
+e_minicard_widget_new (void)
+{
+ GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_minicard_widget_get_type ()));
+ return widget;
+}
+
+static void
+e_minicard_widget_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ switch (arg_id){
+ case ARG_CARD:
+ if (emw->full_header)
+ gtk_object_unref(GTK_OBJECT(emw->card));
+ if (GTK_VALUE_OBJECT(*arg)) {
+ emw->card = E_CARD(GTK_VALUE_OBJECT(*arg));
+ gtk_object_ref(GTK_OBJECT(emw->card));
+ }
+ else
+ emw->card = NULL;
+ if (emw->item)
+ gtk_object_set(GTK_OBJECT(emw->item),
+ "card", emw->card,
+ NULL);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+e_minicard_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ switch (arg_id) {
+ case ARG_CARD:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(emw->card);
+ break;
+ default:
+ arg->type = GTK_TYPE_INVALID;
+ break;
+ }
+}
diff --git a/addressbook/gui/minicard/e-minicard-widget.h b/addressbook/gui/minicard/e-minicard-widget.h
new file mode 100644
index 0000000000..9656e41693
--- /dev/null
+++ b/addressbook/gui/minicard/e-minicard-widget.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* e-minicard-widget.h
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __E_MINICARD_WIDGET_H__
+#define __E_MINICARD_WIDGET_H__
+
+#include <gnome.h>
+#include <glade/glade.h>
+#include "e-table-header.h"
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+/* EMinicardWidget - A card displaying information about a contact.
+ *
+ * The following arguments are available:
+ *
+ * name type read/write description
+ * --------------------------------------------------------------------------------
+ */
+
+#define E_MINICARD_WIDGET_TYPE (e_minicard_widget_get_type ())
+#define E_MINICARD_WIDGET(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_WIDGET_TYPE, EMinicardWidget))
+#define E_MINICARD_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_WIDGET_TYPE, ETableFieldChooserClass))
+#define E_IS_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_WIDGET_TYPE))
+#define E_IS_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_WIDGET_TYPE))
+
+
+typedef struct _EMinicardWidget EMinicardWidget;
+typedef struct _ETableFieldChooserClass ETableFieldChooserClass;
+
+struct _EMinicardWidget
+{
+ ECanvas parent;
+
+ /* item specific fields */
+ GnomeCanvasItem *item;
+
+ GnomeCanvasItem *rect;
+ ECard *card;
+};
+
+struct _ETableFieldChooserClass
+{
+ ECanvasClass parent_class;
+};
+
+
+GtkWidget *e_minicard_widget_new(void);
+GtkType e_minicard_widget_get_type (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __E_MINICARD_WIDGET_H__ */
diff --git a/addressbook/gui/widgets/e-minicard-control.c b/addressbook/gui/widgets/e-minicard-control.c
new file mode 100644
index 0000000000..8cac2dc15e
--- /dev/null
+++ b/addressbook/gui/widgets/e-minicard-control.c
@@ -0,0 +1,307 @@
+/*
+ * e-minicard-control.c
+ *
+ * Authors:
+ * Chris Lahey <clahey@helixcode.com>
+ *
+ * Copyright 1999, 2000, Helix Code, Inc.
+ */
+
+#include <config.h>
+#include <gnome.h>
+#include <bonobo.h>
+
+#include "e-minicard-factory.h"
+
+#if 0
+enum {
+ PROP_RUNNING
+} MyArgs;
+
+#define RUNNING_KEY "Clock::Running"
+
+static void
+get_prop (BonoboPropertyBag *bag,
+ BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ GtkObject *clock = user_data;
+
+ switch (arg_id) {
+
+ case PROP_RUNNING:
+ {
+ gboolean b = GPOINTER_TO_UINT (gtk_object_get_data (clock, RUNNING_KEY));
+ BONOBO_ARG_SET_BOOLEAN (arg, b);
+ break;
+ }
+
+ default:
+ g_warning ("Unhandled arg %d", arg_id);
+ break;
+ }
+}
+
+static void
+set_prop (BonoboPropertyBag *bag,
+ const BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ GtkClock *clock = user_data;
+
+ switch (arg_id) {
+
+ case PROP_RUNNING:
+ {
+ guint i;
+
+ i = BONOBO_ARG_GET_BOOLEAN (arg);
+
+ if (i)
+ gtk_clock_start (clock);
+ else
+ gtk_clock_stop (clock);
+
+ gtk_object_set_data (GTK_OBJECT (clock), RUNNING_KEY,
+ GUINT_TO_POINTER (i));
+ break;
+ }
+
+ default:
+ g_warning ("Unhandled arg %d", arg_id);
+ break;
+ }
+}
+#endif
+
+/*
+ * Bonobo::PersistStream
+ *
+ * These two functions implement the Bonobo::PersistStream load and
+ * save methods which allow data to be loaded into and out of the
+ * BonoboObject.
+ */
+static int
+stream_read (Bonobo_Stream stream)
+{
+ Bonobo_Stream_iobuf *buffer;
+ CORBA_Environment ev;
+ char *data = NULL;
+ gint length = 0;
+
+ CORBA_exception_init (&ev);
+ do {
+#define READ_CHUNK_SIZE 65536
+ Bonobo_Stream_read (stream, READ_CHUNK_SIZE,
+ &buffer, &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+ return NULL;
+ }
+
+ if (buffer->_length <= 0)
+ break;
+
+ data = g_realloc (data,
+ length + buffer->_length);
+
+ memcpy (data + length,
+ buffer->_buffer, buffer->_length);
+
+ length += buffer->_length;
+
+ CORBA_free (buffer);
+ } while (1);
+
+ CORBA_free (buffer);
+ CORBA_exception_free (&ev);
+
+ if (data == NULL)
+ data = g_strdup("");
+
+ return data;
+} /* stream_read */
+
+/*
+ * This function implements the Bonobo::PersistStream:load method.
+ */
+static void
+pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type, void *data,
+ CORBA_Environment *ev)
+{
+ ECard *card;
+ char *vcard;
+ GtkWidget *minicard = data;
+
+ if (*type && g_strcasecmp (type, "text/plain") != 0 &&
+ g_strcasecmp (type, "text/x-vCard") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ if ((vcard = stream_read (stream, embeddable_data)) == NULL) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_FileNotFound, NULL);
+ return;
+ }
+
+ card = e_card_new(vcard);
+ g_free(vcard);
+ gtk_object_set(GTK_OBJECT(minicard),
+ "card", card,
+ NULL);
+ gtk_object_unref(GTK_OBJECT(card));
+} /* pstream_load */
+
+/*
+ * This function implements the Bonobo::PersistStream:save method.
+ */
+static void
+pstream_save (BonoboPersistStream *ps, const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type, void *data,
+ CORBA_Environment *ev)
+{
+ Bonobo_Stream_iobuf *buffer;
+ size_t pos;
+ char *vcard;
+ ECard *card;
+ EMinicardWidget *minicard = data;
+ int length;
+
+ if (*type && g_strcasecmp (type, "text/plain") != 0 &&
+ g_strcasecmp (type, "text/x-vCard") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ buffer = Bonobo_Stream_iobuf__alloc ();
+
+ gtk_object_get(GTK_OBJECT(minicard),
+ "card", &card,
+ NULL);
+ vcard = e_card_get_vcard(card);
+ length = strlen(vcard);
+ data = CORBA_sequence_CORBA_octet_allocbuf (length);
+ memcpy (data, vcard, length);
+
+ buffer->_buffer = data;
+ buffer->_length = length;
+
+ g_free(vcard);
+
+ pos = 0;
+
+ while (pos < length) {
+ CORBA_long bytes_read;
+
+ bytes_read = Bonobo_Stream_write (stream, buffer, ev);
+
+ if (ev->_major != CORBA_NO_EXCEPTION) {
+ CORBA_free (buffer);
+ CORBA_free (data);
+ return;
+ }
+
+ pos += bytes_read;
+ }
+
+ CORBA_free (buffer);
+ CORBA_free (data);
+} /* pstream_save */
+
+static CORBA_long
+pstream_get_max_size (BonoboPersistStream *ps, void *data,
+ CORBA_Environment *ev)
+{
+ GtkWidget *minicard = data;
+ ECard *card;
+ char *vcard;
+
+ gtk_object_get(GTK_OBJECT(minicard),
+ "card", &card,
+ NULL);
+ vcard = e_card_get_vcard(card);
+ length = strlen(vcard);
+ g_free(vcard);
+
+ return length;
+}
+
+static Bonobo_Persist_ContentTypeList *
+pstream_get_content_types (BonoboPersistStream *ps, void *closure,
+ CORBA_Environment *ev)
+{
+ return bonobo_persist_generate_content_types (2, "text/plain", "text/x-vCard");
+}
+
+static BonoboObject *
+e_minicard_factory (BonoboGenericFactory *Factory, void *closure)
+{
+#if 0
+ BonoboPropertyBag *pb;
+#endif
+ BonoboControl *control;
+ BonoboPersistStream *stream;
+ GtkWidget *minicard;
+
+ /* Create the control. */
+ minicard = e_minicard_widget_new ();
+ gtk_widget_show (minicard);
+
+ control = bonobo_control_new (minicard);
+
+ stream = bonobo_persist_stream_new (pstream_load, pstream_save,
+ pstream_get_max_size,
+ pstream_get_content_types,
+ minicard);
+
+#if 0
+ /* Create the properties. */
+ pb = bonobo_property_bag_new (get_prop, set_prop, clock);
+ bonobo_control_set_property_bag (control, pb);
+
+ bonobo_property_bag_add (pb, "running", PROP_RUNNING,
+ BONOBO_ARG_BOOLEAN, NULL,
+ "Whether or not the clock is running", 0);
+#endif
+
+ if (stream == NULL) {
+ bonobo_object_unref (BONOBO_OBJECT (control));
+ return NULL;
+ }
+
+ bonobo_object_add_interface (BONOBO_OBJECT (control),
+ BONOBO_OBJECT (stream));
+
+ return BONOBO_OBJECT (control);
+}
+
+void
+e_minicard_factory_init (void)
+{
+ static BonoboGenericFactory *e_minicard_factory = NULL;
+
+ if (e_minicard_factory != NULL)
+ return;
+
+#if USING_OAF
+ e_minicard_factory =
+ bonobo_generic_factory_new (
+ "OAFIID:e_minicard_factory:f9542709-fb31-4c6a-bc00-d462ba41e4b9",
+ e_minicard_factory, NULL);
+#else
+ e_minicard_factory =
+ bonobo_generic_factory_new (
+ "control-factory:e-minicard",
+ e_minicard_factory, NULL);
+#endif
+
+ if (e_minicard_factory == NULL)
+ g_error ("I could not register a EMinicard factory.");
+}
diff --git a/addressbook/gui/widgets/e-minicard-control.h b/addressbook/gui/widgets/e-minicard-control.h
new file mode 100644
index 0000000000..3b69ec9080
--- /dev/null
+++ b/addressbook/gui/widgets/e-minicard-control.h
@@ -0,0 +1,8 @@
+#ifndef __E_MINICARD_CONTROL_H__
+#define __E_MINICARD_CONTROL_H__
+
+#include <bonobo/bonobo-control.h>
+
+void e_minicard_factory_init (void);
+
+#endif /* __E_MINICARD_CONTROL_H__ */
diff --git a/addressbook/gui/widgets/e-minicard-widget.c b/addressbook/gui/widgets/e-minicard-widget.c
new file mode 100644
index 0000000000..e3b61e9540
--- /dev/null
+++ b/addressbook/gui/widgets/e-minicard-widget.c
@@ -0,0 +1,214 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * e-table-field-chooser.c
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library 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 library; 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 <e-table-field-chooser.h>
+#include <e-table-field-chooser-item.h>
+
+static void e_minicard_widget_init (EMinicardWidget *card);
+static void e_minicard_widget_class_init (EMinicardWidgetClass *klass);
+static void e_minicard_widget_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
+static void e_minicard_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
+static void e_minicard_widget_destroy (GtkObject *object);
+
+static ECanvas *parent_class = NULL;
+
+/* The arguments we take */
+enum {
+ ARG_0,
+ ARG_CARD,
+};
+
+GtkType
+e_minicard_widget_get_type (void)
+{
+ static GtkType table_field_chooser_type = 0;
+
+ if (!table_field_chooser_type)
+ {
+ static const GtkTypeInfo table_field_chooser_info =
+ {
+ "EMinicardWidget",
+ sizeof (EMinicardWidget),
+ sizeof (EMinicardWidgetClass),
+ (GtkClassInitFunc) e_minicard_widget_class_init,
+ (GtkObjectInitFunc) e_minicard_widget_init,
+ /* reserved_1 */ NULL,
+ /* reserved_2 */ NULL,
+ (GtkClassInitFunc) NULL,
+ };
+
+ table_field_chooser_type = gtk_type_unique (e_canvas_get_type (), &table_field_chooser_info);
+ }
+
+ return table_field_chooser_type;
+}
+
+static void
+e_minicard_widget_class_init (EMinicardWidgetClass *klass)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = (GtkObjectClass*) klass;
+ widget_class = (GtkWidgetClass *) klass;
+
+ parent_class = gtk_type_class (gtk_vbox_get_type ());
+
+ object_class->set_arg = e_minicard_widget_set_arg;
+ object_class->get_arg = e_minicard_widget_get_arg;
+ object_class->destroy = e_minicard_widget_destroy;
+
+ widget_class->size_request = e_minicard_widget_size_request;
+ widget_class->size_allocate = e_minicard_widget_size_allocate;
+ gtk_object_add_arg_type ("EMinicardWidget::card", GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE, ARG_CARD);
+}
+
+static void
+e_minicard_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
+{
+ double height;
+ EMinicardWidget *emw = E_MINICARD_WIDGET(widget);
+ gnome_canvas_item_set( emw->item,
+ "width", (double) allocation->width,
+ NULL );
+ gtk_object_get(GTK_OBJECT(emw->item),
+ "height", &height,
+ NULL);
+ height = MAX(height, allocation->height);
+ gnome_canvas_set_scroll_region(GNOME_CANVAS( emw->canvas ), 0, 0, allocation->width - 1, height - 1);
+ gnome_canvas_item_set( emw->rect,
+ "x2", (double) allocation->width,
+ "y2", (double) height,
+ NULL );
+ if (GTK_WIDGET_CLASS(parent_class)->size_allocate)
+ GTK_WIDGET_CLASS(parent_class)->size_allocate(widget, allocation);
+}
+
+static void resize(GnomeCanvas *canvas, EMinicardWidget *emw)
+{
+ double height;
+ gtk_object_get(GTK_OBJECT(emw->item),
+ "height", &height,
+ NULL);
+
+ height = MAX(height, emw->last_alloc.height);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS(emw->canvas), 0, 0, emw->last_alloc.width - 1, height - 1);
+ gnome_canvas_item_set( emw->rect,
+ "x2", (double) emw->last_alloc.width,
+ "y2", (double) height,
+ NULL );
+}
+
+static void
+e_minicard_widget_init (EMinicardWidget *emw)
+{
+ emw->rect = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS( emw->canvas ) ),
+ gnome_canvas_rect_get_type(),
+ "x1", (double) 0,
+ "y1", (double) 0,
+ "x2", (double) 100,
+ "y2", (double) 100,
+ "fill_color", "white",
+ NULL );
+
+ emw->item = gnome_canvas_item_new(gnome_canvas_root(emw->canvas),
+ e_minicard_widget_item_get_type(),
+ "width", (double) 100,
+ NULL );
+
+ gtk_signal_connect( GTK_OBJECT( emw->canvas ), "reflow",
+ GTK_SIGNAL_FUNC( resize ),
+ emw);
+
+ gnome_canvas_set_scroll_region ( GNOME_CANVAS( emw->canvas ),
+ 0, 0,
+ 100, 100 );
+
+ /* Connect the signals */
+ gtk_signal_connect (GTK_OBJECT (emw->canvas), "size_allocate",
+ GTK_SIGNAL_FUNC (allocate_callback),
+ emw);
+}
+
+static void
+e_minicard_widget_destroy (GtkObject *object)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ g_free(emw->dnd_code);
+ if (emw->full_header)
+ gtk_object_unref(GTK_OBJECT(emw->full_header));
+
+ if (emw->gui)
+ gtk_object_unref(GTK_OBJECT(emw->gui));
+}
+
+GtkWidget*
+e_minicard_widget_new (void)
+{
+ GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_minicard_widget_get_type ()));
+ return widget;
+}
+
+static void
+e_minicard_widget_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ switch (arg_id){
+ case ARG_CARD:
+ if (emw->full_header)
+ gtk_object_unref(GTK_OBJECT(emw->card));
+ if (GTK_VALUE_OBJECT(*arg)) {
+ emw->card = E_CARD(GTK_VALUE_OBJECT(*arg));
+ gtk_object_ref(GTK_OBJECT(emw->card));
+ }
+ else
+ emw->card = NULL;
+ if (emw->item)
+ gtk_object_set(GTK_OBJECT(emw->item),
+ "card", emw->card,
+ NULL);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+e_minicard_widget_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+{
+ EMinicardWidget *emw = E_MINICARD_WIDGET(object);
+
+ switch (arg_id) {
+ case ARG_CARD:
+ GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(emw->card);
+ break;
+ default:
+ arg->type = GTK_TYPE_INVALID;
+ break;
+ }
+}
diff --git a/addressbook/gui/widgets/e-minicard-widget.h b/addressbook/gui/widgets/e-minicard-widget.h
new file mode 100644
index 0000000000..9656e41693
--- /dev/null
+++ b/addressbook/gui/widgets/e-minicard-widget.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* e-minicard-widget.h
+ * Copyright (C) 2000 Helix Code, Inc.
+ * Author: Chris Lahey <clahey@helixcode.com>
+ *
+ * This library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __E_MINICARD_WIDGET_H__
+#define __E_MINICARD_WIDGET_H__
+
+#include <gnome.h>
+#include <glade/glade.h>
+#include "e-table-header.h"
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+/* EMinicardWidget - A card displaying information about a contact.
+ *
+ * The following arguments are available:
+ *
+ * name type read/write description
+ * --------------------------------------------------------------------------------
+ */
+
+#define E_MINICARD_WIDGET_TYPE (e_minicard_widget_get_type ())
+#define E_MINICARD_WIDGET(obj) (GTK_CHECK_CAST ((obj), E_MINICARD_WIDGET_TYPE, EMinicardWidget))
+#define E_MINICARD_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_MINICARD_WIDGET_TYPE, ETableFieldChooserClass))
+#define E_IS_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_TYPE ((obj), E_MINICARD_WIDGET_TYPE))
+#define E_IS_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_MINICARD_WIDGET_TYPE))
+
+
+typedef struct _EMinicardWidget EMinicardWidget;
+typedef struct _ETableFieldChooserClass ETableFieldChooserClass;
+
+struct _EMinicardWidget
+{
+ ECanvas parent;
+
+ /* item specific fields */
+ GnomeCanvasItem *item;
+
+ GnomeCanvasItem *rect;
+ ECard *card;
+};
+
+struct _ETableFieldChooserClass
+{
+ ECanvasClass parent_class;
+};
+
+
+GtkWidget *e_minicard_widget_new(void);
+GtkType e_minicard_widget_get_type (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __E_MINICARD_WIDGET_H__ */