From 7acab8b24cd9e7e2e32211e77d2a5c2eae1c4bb0 Mon Sep 17 00:00:00 2001 From: nobody Date: Thu, 2 Aug 2001 15:43:54 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'release-0-2-91'. svn path=/tags/release-0-2-91/; revision=11578 --- addressbook/gui/component/select-names/.cvsignore | 12 - .../Evolution-Addressbook-SelectNames.idl | 42 - .../GNOME_Evolution_Addressbook_SelectNames.oaf.in | 29 - addressbook/gui/component/select-names/Makefile.am | 85 -- .../component/select-names/e-select-names-bonobo.c | 431 ------- .../component/select-names/e-select-names-bonobo.h | 71 -- .../select-names/e-select-names-completion.c | 1183 -------------------- .../select-names/e-select-names-completion.h | 68 -- .../select-names/e-select-names-factory.c | 59 - .../select-names/e-select-names-factory.h | 31 - .../select-names/e-select-names-manager.c | 512 --------- .../select-names/e-select-names-manager.h | 66 -- .../component/select-names/e-select-names-model.c | 694 ------------ .../component/select-names/e-select-names-model.h | 76 -- .../component/select-names/e-select-names-popup.c | 401 ------- .../component/select-names/e-select-names-popup.h | 36 - .../select-names/e-select-names-table-model.c | 344 ------ .../select-names/e-select-names-table-model.h | 51 - .../select-names/e-select-names-text-model.c | 723 ------------ .../select-names/e-select-names-text-model.h | 45 - .../gui/component/select-names/e-select-names.c | 801 ------------- .../gui/component/select-names/e-select-names.h | 107 -- .../gui/component/select-names/recipient.glade | 61 - .../gui/component/select-names/select-names.glade | 320 ------ 24 files changed, 6248 deletions(-) delete mode 100644 addressbook/gui/component/select-names/.cvsignore delete mode 100644 addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl delete mode 100644 addressbook/gui/component/select-names/GNOME_Evolution_Addressbook_SelectNames.oaf.in delete mode 100644 addressbook/gui/component/select-names/Makefile.am delete mode 100644 addressbook/gui/component/select-names/e-select-names-bonobo.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-bonobo.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-completion.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-completion.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-factory.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-factory.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-manager.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-manager.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-model.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-model.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-popup.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-popup.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-table-model.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-table-model.h delete mode 100644 addressbook/gui/component/select-names/e-select-names-text-model.c delete mode 100644 addressbook/gui/component/select-names/e-select-names-text-model.h delete mode 100644 addressbook/gui/component/select-names/e-select-names.c delete mode 100644 addressbook/gui/component/select-names/e-select-names.h delete mode 100644 addressbook/gui/component/select-names/recipient.glade delete mode 100644 addressbook/gui/component/select-names/select-names.glade (limited to 'addressbook/gui/component/select-names') diff --git a/addressbook/gui/component/select-names/.cvsignore b/addressbook/gui/component/select-names/.cvsignore deleted file mode 100644 index cd669499fa..0000000000 --- a/addressbook/gui/component/select-names/.cvsignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -Evolution-Addressbook-SelectNames-stubs.c -Evolution-Addressbook-SelectNames-skels.c -Evolution-Addressbook-SelectNames-common.c -Evolution-Addressbook-SelectNames.h -GNOME_Evolution_Addressbook_SelectNames.oaf diff --git a/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl b/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl deleted file mode 100644 index 244799deb2..0000000000 --- a/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * CORBA interface for the SelectNames dialog. - * - * Authors: - * Ettore Perazzoli - * - * Copyright (C) 2000 Ximian, Inc. - */ - -#include - -module GNOME { -module Evolution { -module Addressbook { - - interface SelectNames : Bonobo::Unknown { - struct Section { - string id; - string title; - }; - - typedef sequence
SectionList; - - exception DuplicateID {}; - exception SectionNotFound {}; - - void addSection (in string id, in string title) - raises (DuplicateID); - void addSectionWithLimit (in string id, in string title, in short limit) - raises (DuplicateID); - - Bonobo::Control getEntryBySection (in string section_id) - raises (SectionNotFound); - - void activateDialog (in string section_id); - }; - - -}; -}; -}; diff --git a/addressbook/gui/component/select-names/GNOME_Evolution_Addressbook_SelectNames.oaf.in b/addressbook/gui/component/select-names/GNOME_Evolution_Addressbook_SelectNames.oaf.in deleted file mode 100644 index 7f26e2aaed..0000000000 --- a/addressbook/gui/component/select-names/GNOME_Evolution_Addressbook_SelectNames.oaf.in +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/addressbook/gui/component/select-names/Makefile.am b/addressbook/gui/component/select-names/Makefile.am deleted file mode 100644 index 5c7b37794b..0000000000 --- a/addressbook/gui/component/select-names/Makefile.am +++ /dev/null @@ -1,85 +0,0 @@ -# CORBA stuff - -IDLS = \ - Evolution-Addressbook-SelectNames.idl - -IDL_GENERATED = \ - Evolution-Addressbook-SelectNames.h \ - Evolution-Addressbook-SelectNames-common.c \ - Evolution-Addressbook-SelectNames-skels.c \ - Evolution-Addressbook-SelectNames-stubs.c - -Evolution-Addressbook-SelectNames-impl.o: Evolution-Addressbook-SelectNames.h - -$(IDL_GENERATED): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) -I $(datadir)/idl `$(GNOME_CONFIG) --cflags idl` \ - $(srcdir)/Evolution-Addressbook-SelectNames.idl - -oafdir = $(datadir)/oaf - -oaf_in_files = GNOME_Evolution_Addressbook_SelectNames.oaf.in -oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) - -@XML_I18N_MERGE_OAF_RULE@ - - -INCLUDES = \ - -DG_LOG_DOMAIN=\"evolution-addressbook\" \ - $(EXTRA_GNOME_CFLAGS) \ - $(GNOME_INCLUDEDIR) \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - -I$(top_srcdir)/shell \ - -I$(top_builddir)/shell \ - -I$(top_srcdir)/widgets/e-text \ - -I$(top_srcdir)/widgets/e-table \ - -I$(top_srcdir)/addressbook/gui/minicard \ - -I$(top_srcdir)/addressbook/gui/widgets \ - -I$(top_srcdir)/addressbook/contact-editor \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_builddir)/addressbook/backend \ - $(BONOBO_HTML_GNOME_CFLAGS) \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_ICONSDIR=\""$(iconsdir)"\" \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ - -DCAMEL_PROVIDERDIR=\""$(providerdir)"\" - -lib_LTLIBRARIES = libeselectnames.la - -libeselectnames_la_SOURCES = \ - $(IDL_GENERATED) \ - e-select-names-bonobo.c \ - e-select-names-bonobo.h \ - e-select-names-completion.c \ - e-select-names-completion.h \ - e-select-names-factory.c \ - e-select-names-factory.h \ - e-select-names-manager.c \ - 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 \ - e-select-names-text-model.h \ - e-select-names.c \ - e-select-names.h - -gladedir = $(datadir)/evolution/glade -glade_DATA = select-names.glade - - - -EXTRA_DIST = \ - $(glade_DATA) \ - $(oaf_in_files) \ - $(oaf_DATA) \ - $(IDLS) - -BUILT_SOURCES = $(IDL_GENERATED) -CLEANFILES += $(BUILT_SOURCES) - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.c b/addressbook/gui/component/select-names/e-select-names-bonobo.c deleted file mode 100644 index 25adf13a65..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.c +++ /dev/null @@ -1,431 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-select-names-bonobo.c - * - * Copyright (C) 2000 Ximian, Inc. - * - * 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. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "e-select-names-bonobo.h" - -#include -#include -#include - -#include -#include - -#include "Evolution-Addressbook-SelectNames.h" - -#include "e-select-names-manager.h" -#include "e-select-names-model.h" -#include "e-select-names-text-model.h" -#include "e-select-names-completion.h" - - - -#define PARENT_TYPE bonobo_object_get_type () -static BonoboObjectClass *parent_class = NULL; - -struct _ESelectNamesBonoboPrivate { - ESelectNamesManager *manager; - BonoboEventSource *event_source; -}; - -enum _EntryPropertyID { - ENTRY_PROPERTY_ID_TEXT, - ENTRY_PROPERTY_ID_DESTINATIONS, - ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS, - ENTRY_PROPERTY_ID_ENTRY_CHANGED -}; -typedef enum _EntryPropertyID EntryPropertyID; - - -/* PropertyBag implementation for the entry widgets. */ - -static void -entry_get_property_fn (BonoboPropertyBag *bag, - BonoboArg *arg, - unsigned int arg_id, - CORBA_Environment *ev, - void *user_data) -{ - GtkWidget *w; - - w = GTK_WIDGET (user_data); - - switch (arg_id) { - case ENTRY_PROPERTY_ID_TEXT: - { - ESelectNamesModel *model; - model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (w), "select_names_model")); - g_assert (model != NULL); - - BONOBO_ARG_SET_STRING (arg, e_select_names_model_get_textification (model)); - break; - } - - case ENTRY_PROPERTY_ID_DESTINATIONS: - { - ESelectNamesModel *model; - char *text; - - model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (w), "select_names_model")); - g_assert (model != NULL); - - text = e_select_names_model_export_destinationv (model); - BONOBO_ARG_SET_STRING (arg, text); - g_free (text); - } - break; - - case ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS: - { - ESelectNamesCompletion *comp; - comp = E_SELECT_NAMES_COMPLETION (gtk_object_get_data (GTK_OBJECT (w), "completion_handler")); - g_assert (comp != NULL); - - BONOBO_ARG_SET_BOOLEAN (arg, e_select_names_completion_get_match_contact_lists (comp)); - break; - } - - case ENTRY_PROPERTY_ID_ENTRY_CHANGED: - /* This is a read-only property. */ - g_assert_not_reached (); - break; - - default: - break; - } -} - -static void -entry_set_property_fn (BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - GtkWidget *w; - - w = GTK_WIDGET (user_data); - - switch (arg_id) { - - case ENTRY_PROPERTY_ID_TEXT: - e_entry_set_text (E_ENTRY (w), BONOBO_ARG_GET_STRING (arg)); - break; - - case ENTRY_PROPERTY_ID_DESTINATIONS: - { - ESelectNamesModel *model; - model = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (w), "select_names_model")); - g_assert (model != NULL); - - e_select_names_model_import_destinationv (model, BONOBO_ARG_GET_STRING (arg)); - break; - } - - case ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS: - { - ESelectNamesCompletion *comp; - comp = E_SELECT_NAMES_COMPLETION (gtk_object_get_data (GTK_OBJECT (w), "completion_handler")); - g_assert (comp != NULL); - - e_select_names_completion_set_match_contact_lists (comp, BONOBO_ARG_GET_BOOLEAN (arg)); - break; - } - - case ENTRY_PROPERTY_ID_ENTRY_CHANGED: - gtk_object_set_data (GTK_OBJECT (w), "entry_property_id_changed", GUINT_TO_POINTER (1)); - break; - - default: - break; - } -} - - -/* CORBA interface implementation. */ - -static POA_GNOME_Evolution_Addressbook_SelectNames__vepv SelectNames_vepv; - -static POA_GNOME_Evolution_Addressbook_SelectNames * -create_servant (void) -{ - POA_GNOME_Evolution_Addressbook_SelectNames *servant; - CORBA_Environment ev; - - servant = (POA_GNOME_Evolution_Addressbook_SelectNames *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &SelectNames_vepv; - - CORBA_exception_init (&ev); - - POA_GNOME_Evolution_Addressbook_SelectNames__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - return NULL; - } - - CORBA_exception_free (&ev); - - return servant; -} - -static void -impl_SelectNames_add_section (PortableServer_Servant servant, - const CORBA_char *id, - const CORBA_char *title, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - ESelectNamesBonobo *select_names; - ESelectNamesBonoboPrivate *priv; - - bonobo_object = bonobo_object_from_servant (servant); - select_names = E_SELECT_NAMES_BONOBO (bonobo_object); - priv = select_names->priv; - - e_select_names_manager_add_section (priv->manager, id, title); -} - -static void -impl_SelectNames_add_section_with_limit (PortableServer_Servant servant, - const CORBA_char *id, - const CORBA_char *title, - CORBA_short limit, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - ESelectNamesBonobo *select_names; - ESelectNamesBonoboPrivate *priv; - - bonobo_object = bonobo_object_from_servant (servant); - select_names = E_SELECT_NAMES_BONOBO (bonobo_object); - priv = select_names->priv; - - e_select_names_manager_add_section_with_limit (priv->manager, id, title, limit); -} - -static void -entry_changed (GtkWidget *widget, BonoboControl *control) -{ - gboolean changed = GPOINTER_TO_UINT (gtk_object_get_data (GTK_OBJECT (widget), "entry_property_id_changed")); - - if (!changed) - bonobo_control_set_property (control, "entry_changed", TRUE, NULL); -} - -static Bonobo_Control -impl_SelectNames_get_entry_for_section (PortableServer_Servant servant, - const CORBA_char *section_id, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - ESelectNamesBonobo *select_names; - ESelectNamesBonoboPrivate *priv; - GtkWidget *entry_widget; - BonoboControl *control; - BonoboPropertyBag *property_bag; - - bonobo_object = bonobo_object_from_servant (servant); - select_names = E_SELECT_NAMES_BONOBO (bonobo_object); - priv = select_names->priv; - - entry_widget = e_select_names_manager_create_entry (priv->manager, section_id); - gtk_widget_show (entry_widget); - - if (entry_widget == NULL) { - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Addressbook_SelectNames_SectionNotFound, - NULL); - return CORBA_OBJECT_NIL; - } - - control = bonobo_control_new (entry_widget); - - property_bag = bonobo_property_bag_new (entry_get_property_fn, entry_set_property_fn, entry_widget); - bonobo_property_bag_add (property_bag, "text", ENTRY_PROPERTY_ID_TEXT, - BONOBO_ARG_STRING, NULL, NULL, - BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE); - bonobo_property_bag_add (property_bag, "destinations", ENTRY_PROPERTY_ID_DESTINATIONS, - BONOBO_ARG_STRING, NULL, NULL, - BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE); - bonobo_property_bag_add (property_bag, "allow_contact_lists", ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS, - BONOBO_ARG_BOOLEAN, NULL, NULL, - BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE); - bonobo_property_bag_add (property_bag, "entry_changed", ENTRY_PROPERTY_ID_ENTRY_CHANGED, - BONOBO_ARG_BOOLEAN, NULL, NULL, - BONOBO_PROPERTY_WRITEABLE); - - bonobo_control_set_properties (control, property_bag); - - gtk_signal_connect (GTK_OBJECT (entry_widget), "changed", - GTK_SIGNAL_FUNC (entry_changed), control); - - return CORBA_Object_duplicate (bonobo_object_corba_objref (BONOBO_OBJECT (control)), ev); -} - -static void -impl_SelectNames_activate_dialog (PortableServer_Servant servant, - const CORBA_char *section_id, - CORBA_Environment *ev) -{ - BonoboObject *bonobo_object; - ESelectNamesBonobo *select_names; - ESelectNamesBonoboPrivate *priv; - - bonobo_object = bonobo_object_from_servant (servant); - select_names = E_SELECT_NAMES_BONOBO (bonobo_object); - priv = select_names->priv; - - e_select_names_manager_activate_dialog (priv->manager, section_id); -} - - -/* GtkObject methods. */ - -static void -impl_destroy (GtkObject *object) -{ - ESelectNamesBonobo *select_names; - ESelectNamesBonoboPrivate *priv; - - select_names = E_SELECT_NAMES_BONOBO (object); - priv = select_names->priv; - - gtk_object_unref (GTK_OBJECT (priv->manager)); - - g_free (priv); -} - - -static void -corba_class_init () -{ - POA_GNOME_Evolution_Addressbook_SelectNames__vepv *vepv; - POA_GNOME_Evolution_Addressbook_SelectNames__epv *epv; - PortableServer_ServantBase__epv *base_epv; - - base_epv = g_new0 (PortableServer_ServantBase__epv, 1); - base_epv->_private = NULL; - base_epv->finalize = NULL; - base_epv->default_POA = NULL; - - epv = g_new0 (POA_GNOME_Evolution_Addressbook_SelectNames__epv, 1); - epv->addSection = impl_SelectNames_add_section; - epv->addSectionWithLimit = impl_SelectNames_add_section_with_limit; - epv->getEntryBySection = impl_SelectNames_get_entry_for_section; - epv->activateDialog = impl_SelectNames_activate_dialog; - - vepv = &SelectNames_vepv; - vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); - vepv->GNOME_Evolution_Addressbook_SelectNames_epv = epv; -} - -static void -class_init (ESelectNamesBonoboClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS (klass); - parent_class = gtk_type_class (bonobo_object_get_type ()); - - object_class->destroy = impl_destroy; - - corba_class_init (); -} - -static void -manager_changed_cb (ESelectNamesManager *manager, const gchar *section_id, gint changed_working_copy, gpointer closure) -{ - ESelectNamesBonobo *select_names = E_SELECT_NAMES_BONOBO (closure); - BonoboArg *arg; - - arg = bonobo_arg_new (BONOBO_ARG_STRING); - BONOBO_ARG_SET_STRING (arg, section_id); - - bonobo_event_source_notify_listeners_full (select_names->priv->event_source, - "GNOME/Evolution", - "changed", - changed_working_copy ? "working_copy" : "model", - arg, NULL); - - bonobo_arg_release (arg); -} - -static void -init (ESelectNamesBonobo *select_names) -{ - ESelectNamesBonoboPrivate *priv; - - priv = g_new (ESelectNamesBonoboPrivate, 1); - - priv->manager = e_select_names_manager_new (); - priv->event_source = NULL; - - gtk_signal_connect (GTK_OBJECT (priv->manager), - "changed", - GTK_SIGNAL_FUNC (manager_changed_cb), - select_names); - - select_names->priv = priv; -} - - -void -e_select_names_bonobo_construct (ESelectNamesBonobo *select_names, - GNOME_Evolution_Addressbook_SelectNames corba_object) -{ - g_return_if_fail (select_names != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_BONOBO (select_names)); - - bonobo_object_construct (BONOBO_OBJECT (select_names), corba_object); - - g_assert (select_names->priv->event_source == NULL); - select_names->priv->event_source = bonobo_event_source_new (); - bonobo_object_add_interface (BONOBO_OBJECT (select_names), BONOBO_OBJECT (select_names->priv->event_source)); -} - -ESelectNamesBonobo * -e_select_names_bonobo_new (void) -{ - POA_GNOME_Evolution_Addressbook_SelectNames *servant; - GNOME_Evolution_Addressbook_SelectNames corba_object; - ESelectNamesBonobo *select_names; - - servant = create_servant (); - if (servant == NULL) - return NULL; - - select_names = gtk_type_new (e_select_names_bonobo_get_type ()); - - corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (select_names), servant); - e_select_names_bonobo_construct (select_names, corba_object); - - return select_names; -} - - -E_MAKE_TYPE (e_select_names_bonobo, "ESelectNamesBonobo", ESelectNamesBonobo, class_init, init, PARENT_TYPE) diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.h b/addressbook/gui/component/select-names/e-select-names-bonobo.h deleted file mode 100644 index 49043e1756..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-select-names-bonobo.h - * - * Copyright (C) 2000 Ximian, Inc. - * - * 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. - * - * Author: Ettore Perazzoli - */ - -#ifndef __E_SELECT_NAMES_BONOBO_H__ -#define __E_SELECT_NAMES_BONOBO_H__ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "Evolution-Addressbook-SelectNames.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_SELECT_NAMES_BONOBO (e_select_names_bonobo_get_type ()) -#define E_SELECT_NAMES_BONOBO(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SELECT_NAMES_BONOBO, ESelectNamesBonobo)) -#define E_SELECT_NAMES_BONOBO_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SELECT_NAMES_BONOBO, ESelectNamesBonoboClass)) -#define E_IS_SELECT_NAMES_BONOBO(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SELECT_NAMES_BONOBO)) -#define E_IS_SELECT_NAMES_BONOBO_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SELECT_NAMES_BONOBO)) - - -typedef struct _ESelectNamesBonobo ESelectNamesBonobo; -typedef struct _ESelectNamesBonoboPrivate ESelectNamesBonoboPrivate; -typedef struct _ESelectNamesBonoboClass ESelectNamesBonoboClass; - -struct _ESelectNamesBonobo { - BonoboObject parent; - - ESelectNamesBonoboPrivate *priv; -}; - -struct _ESelectNamesBonoboClass { - BonoboObjectClass parent_class; -}; - - -GtkType e_select_names_bonobo_get_type (void); -void e_select_names_bonobo_construct (ESelectNamesBonobo *select_names, - GNOME_Evolution_Addressbook_SelectNames corba_object); -ESelectNamesBonobo *e_select_names_bonobo_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_SELECT_NAMES_BONOBO_H__ */ diff --git a/addressbook/gui/component/select-names/e-select-names-completion.c b/addressbook/gui/component/select-names/e-select-names-completion.c deleted file mode 100644 index 1d1cde2489..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-completion.c +++ /dev/null @@ -1,1183 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-select-names-completion.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge - */ - -/* - * 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 -#include "e-select-names-completion.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include - - -struct _ESelectNamesCompletionPrivate { - - ESelectNamesModel *model; - - EBook *book; - gboolean book_ready; - gboolean cancelled; - - guint book_view_tag; - EBookView *book_view; - - gchar *waiting_query; - gint waiting_pos, waiting_limit; - gchar *query_text; - - gchar *cached_query_text; - GList *cached_cards; - - gboolean match_contact_lists; - gboolean primary_only; -}; - -static void e_select_names_completion_class_init (ESelectNamesCompletionClass *); -static void e_select_names_completion_init (ESelectNamesCompletion *); -static void e_select_names_completion_destroy (GtkObject *object); - -static void e_select_names_completion_got_book_view_cb (EBook *book, EBookStatus status, EBookView *view, gpointer user_data); -static void e_select_names_completion_card_added_cb (EBookView *, const GList *cards, gpointer user_data); -static void e_select_names_completion_seq_complete_cb (EBookView *, gpointer user_data); - -static void e_select_names_completion_do_query (ESelectNamesCompletion *, const gchar *query_text, gint pos, gint limit); - -static void e_select_names_completion_begin (ECompletion *, const gchar *txt, gint pos, gint limit); -static void e_select_names_completion_end (ECompletion *); -static void e_select_names_completion_cancel (ECompletion *); - -static GtkObjectClass *parent_class; - -static FILE *out; - -/* - * - * Query builders - * - */ - -typedef gchar *(*BookQuerySExp) (ESelectNamesCompletion *); -typedef ECompletionMatch *(*BookQueryMatchTester) (ESelectNamesCompletion *, EDestination *); - -static void -our_match_destroy (ECompletionMatch *match) -{ - gtk_object_unref (GTK_OBJECT (match->user_data)); -} - -static ECompletionMatch * -make_match (EDestination *dest, const gchar *menu_form, double score) -{ - ECompletionMatch *match = g_new0 (ECompletionMatch, 1); - ECard *card = e_destination_get_card (dest); - - e_completion_match_construct (match); - - e_completion_match_set_text (match, e_destination_get_name (dest), menu_form); - match->sort_major = card ? floor (e_card_get_use_score (card)) : 0; - match->score = score; - match->sort_minor = e_destination_get_email_num (dest); - - match->user_data = dest; - gtk_object_ref (GTK_OBJECT (dest)); - - match->destroy = our_match_destroy; - - return match; -} - -static void -emailify_match (ECompletionMatch *match) -{ - EDestination *dest = E_DESTINATION (match->user_data); - ECard *card = e_destination_get_card (dest); - const gchar *email = e_destination_get_email (dest); - const gchar *menu_txt = e_completion_match_get_menu_text (match); - - if (card && card->email && e_list_length (card->email) > 1 && !e_card_evolution_list (card)) { - - if (email && strstr (menu_txt, email) == NULL) { - gchar *tmp = g_strdup_printf ("%s <%s>", menu_txt, email); - e_completion_match_set_text (match, - e_completion_match_get_match_text (match), - tmp); - g_free (tmp); - } - - match->sort_minor = e_destination_get_email_num (dest); - } -} - -/* - * Nickname query - */ - -static gchar * -sexp_nickname (ESelectNamesCompletion *comp) -{ - return g_strdup_printf ("(beginswith \"nickname\" \"%s\")", comp->priv->query_text); - -} - -static ECompletionMatch * -match_nickname (ESelectNamesCompletion *comp, EDestination *dest) -{ - ECompletionMatch *match = NULL; - gint len = strlen (comp->priv->query_text); - ECard *card = e_destination_get_card (dest); - double score; - - if (card->nickname - && !g_utf8_strncasecmp (comp->priv->query_text, card->nickname, len)) { - ECompletionMatch *match = g_new0 (ECompletionMatch, 1); - gchar *name = e_card_name_to_string (card->name); - gchar *str; - - score = len * 10; /* nickname gives 10 points per matching character */ - str = g_strdup_printf ("(%s) %s", card->nickname, name); - - match = make_match (dest, str, score); - g_free (name); - g_free (str); - } - - return match; -} - -/* - * E-Mail Query - */ - -static gchar * -sexp_email (ESelectNamesCompletion *comp) -{ - return g_strdup_printf ("(beginswith \"email\" \"%s\")", comp->priv->query_text); -} - -static ECompletionMatch * -match_email (ESelectNamesCompletion *comp, EDestination *dest) -{ - ECompletionMatch *match; - gint len = strlen (comp->priv->query_text); - ECard *card = e_destination_get_card (dest); - const gchar *email = e_destination_get_email (dest); - double score; - - if (email - && !g_utf8_strncasecmp (comp->priv->query_text, email, len) - && !e_destination_is_evolution_list (dest)) { - - gchar *name, *str; - - score = len * 2; /* 2 points for each matching character */ - - name = e_card_name_to_string (card->name); - if (name && *name) - str = g_strdup_printf ("<%s> %s", email, name); - else - str = g_strdup (email); - - match = make_match (dest, str, score); - - g_free (name); - g_free (str); - - return match; - } - - return NULL; -} - -/* - * Name Query - */ - -static gchar * -sexp_name (ESelectNamesCompletion *comp) -{ - if (comp && comp->priv->query_text && *comp->priv->query_text) { - gchar *cpy = g_strdup (comp->priv->query_text); - gchar **strv; - gchar *query; - gint i, count=0; - - strv = g_strsplit (cpy, " ", 0); - for (i=0; strv[i]; ++i) { - ++count; - g_strstrip (strv[i]); - strv[i] = g_strdup_printf ("(contains \"full_name\" \"%s\")", strv[i]); - } - - if (count == 1) { - query = strv[0]; - strv[0] = NULL; - } else { - gchar *joined = g_strjoinv (" ", strv); - query = g_strdup_printf ("(and %s)", joined); - g_free (joined); - } - - for (i=0; strv[i]; ++i) - g_free (strv[i]); - g_free (cpy); - g_free (strv); - - - return query; - } - - return NULL; -} - -enum { - MATCHED_NOTHING = 0, - MATCHED_GIVEN_NAME = 1<<0, - MATCHED_ADDITIONAL_NAME = 1<<1, - MATCHED_FAMILY_NAME = 1<<2 -}; - -/* - Match text against every substring in fragment that follows whitespace. - This allows the fragment "de Icaza" to match against txt "ica". -*/ -static gboolean -match_name_fragment (const gchar *fragment, const gchar *txt) -{ - gint len = strlen (txt); - - while (*fragment) { - if (!g_utf8_strncasecmp (fragment, txt, len)) - return TRUE; - - while (*fragment && !isspace ((gint) *fragment)) - ++fragment; - while (*fragment && isspace ((gint) *fragment)) - ++fragment; - } - - return FALSE; -} - -static ECompletionMatch * -match_name (ESelectNamesCompletion *comp, EDestination *dest) -{ - ECompletionMatch *final_match = NULL; - gchar *menu_text = NULL; - ECard *card; - gchar *cpy, **strv; - gint len, i, match_len = 0; - gint match = 0, first_match = 0; - double score = 0; - gboolean have_given, have_additional, have_family; - - card = e_destination_get_card (dest); - - if (card->name == NULL) - return NULL; - - cpy = g_strdup (comp->priv->query_text); - strv = g_strsplit (cpy, " ", 0); - - for (i=0; strv[i] && !(match & MATCHED_NOTHING); ++i) { - gint this_match = 0; - - g_strstrip (strv[i]); - len = strlen (strv[i]); - - if (card->name->given - && *card->name->given - && !(match & MATCHED_GIVEN_NAME) - && match_name_fragment (card->name->given, strv[i])) { - - this_match = MATCHED_GIVEN_NAME; - - } - else if (card->name->additional - && *card->name->additional - && !(match & MATCHED_ADDITIONAL_NAME) - && match_name_fragment (card->name->additional, strv[i])) { - - this_match = MATCHED_ADDITIONAL_NAME; - - } else if (card->name->family - && *card->name->family - && !(match & MATCHED_FAMILY_NAME) - && match_name_fragment (card->name->family, strv[i])) { - - this_match = MATCHED_FAMILY_NAME; - } - - - if (this_match != MATCHED_NOTHING) { - match_len += len; - match |= this_match; - if (first_match == 0) - first_match = this_match; - } else { - match = first_match = 0; - break; - } - - } - - score = match_len * 3; /* three points per match character */ - - if (card->nickname) { - /* We massively boost the score if the nickname exists and is the same as one of the "real" names. This keeps the - nickname from matching ahead of the real name for this card. */ - len = strlen (card->nickname); - if ((card->name->given && !g_utf8_strncasecmp (card->name->given, card->nickname, MIN (strlen (card->name->given), len))) - || (card->name->family && !g_utf8_strncasecmp (card->name->family, card->nickname, MIN (strlen (card->name->family), len))) - || (card->name->additional && !g_utf8_strncasecmp (card->name->additional, card->nickname, MIN (strlen (card->name->additional), len)))) - score *= 100; - } - - have_given = card->name->given && *card->name->given; - have_additional = card->name->additional && *card->name->additional; - have_family = card->name->family && *card->name->family; - - if (first_match != MATCHED_NOTHING && e_card_evolution_list (card)) { - - menu_text = e_card_name_to_string (card->name); - - } else if (first_match == MATCHED_GIVEN_NAME) { - - if (have_family) - menu_text = g_strdup_printf ("%s %s", card->name->given, card->name->family); - else - menu_text = g_strdup_printf (card->name->given); - - } else if (first_match == MATCHED_ADDITIONAL_NAME) { - - if (have_family) { - - menu_text = g_strdup_printf ("%s, %s%s%s", - card->name->family, - have_given ? card->name->given : "", - have_given ? " " : "", - card->name->additional); - - } else { - - menu_text = g_strdup_printf ("%s%s%s", - have_given ? card->name->given : "", - have_given ? " " : "", - card->name->additional); - - } - - } else if (first_match == MATCHED_FAMILY_NAME) { - - if (have_given) - menu_text = g_strdup_printf ("%s, %s %s", - card->name->family, - card->name->given, - have_additional ? card->name->additional : ""); - else - menu_text = g_strdup_printf (card->name->family); - } - - if (menu_text) { - final_match = make_match (dest, menu_text, score); - g_free (menu_text); - } - - return final_match; -} - -/* - * Initials Query - */ - -static gchar * -sexp_initials (ESelectNamesCompletion *comp) -{ - return NULL; -} - -static ECompletionMatch * -match_initials (ESelectNamesCompletion *comp, EDestination *dest) -{ - return NULL; -} - - -typedef struct _BookQuery BookQuery; -struct _BookQuery { - gboolean primary; - BookQuerySExp builder; - BookQueryMatchTester tester; -}; - -static BookQuery book_queries[] = { - { TRUE, sexp_nickname, match_nickname}, - { TRUE, sexp_email, match_email }, - { TRUE, sexp_name, match_name }, - { FALSE, sexp_initials, match_initials } -}; -static gint book_query_count = sizeof (book_queries) / sizeof (BookQuery); - -/* - * Build up a big compound sexp corresponding to all of our queries. - */ -static gchar * -book_query_sexp (ESelectNamesCompletion *comp) -{ - gint i, j, count = 0; - gchar **queryv, *query; - - g_return_val_if_fail (comp && E_IS_SELECT_NAMES_COMPLETION (comp), NULL); - - if (! (comp->priv->query_text && *comp->priv->query_text)) - return NULL; - - if (comp->priv->primary_only) { - for (i=0; ipriv->primary_only) { - if (book_queries[i].tester && e_destination_get_card (dest)) - this_match = book_queries[i].tester (comp, dest); - - if (this_match) { - if (best_match == NULL || this_match->score > best_match->score) { - e_completion_match_unref (best_match); - best_match = this_match; - } else { - e_completion_match_unref (this_match); - } - } - } - } - - if (best_match) - emailify_match (best_match); - - return best_match; -} - -static void -book_query_process_card_list (ESelectNamesCompletion *comp, const GList *cards) -{ - while (cards) { - ECard *card = E_CARD (cards->data); - - if (e_card_evolution_list (card)) { - - if (comp->priv->match_contact_lists) { - - EDestination *dest = e_destination_new (); - ECompletionMatch *match; - e_destination_set_card (dest, card, 0); - match = book_query_score (comp, dest); - if (match && match->score > 0) { - e_completion_found_match (E_COMPLETION (comp), match); - } else { - e_completion_match_unref (match); - } - gtk_object_unref (GTK_OBJECT (dest)); - - } - - } else if (card->email) { - gint i; - for (i=0; iemail); ++i) { - EDestination *dest = e_destination_new (); - const gchar *email; - ECompletionMatch *match; - - e_destination_set_card (dest, card, i); - email = e_destination_get_email (dest); - - if (email && *email) { - - match = book_query_score (comp, dest); - if (match && match->score > 0) { - e_completion_found_match (E_COMPLETION (comp), match); - } else { - e_completion_match_unref (match); - } - - gtk_object_unref (GTK_OBJECT (dest)); - } - } - } - - cards = g_list_next (cards); - } -} - -#if 0 -static gchar * -initials_query_match_cb (QueryInfo *qi, ECard *card, double *score) -{ - gint len; - gchar f='\0', m='\0', l='\0'; /* initials */ - gchar cf, cm, cl; - - len = strlen (qi->comp->priv->query_text); - - if (len == 2) { - - f = qi->comp->priv->query_text[0]; - m = '\0'; - l = qi->comp->priv->query_text[1]; - - } else if (len == 3) { - - f = qi->comp->priv->query_text[0]; - m = qi->comp->priv->query_text[1]; - l = qi->comp->priv->query_text[2]; - - } else { - return NULL; - } - - cf = card->name->given ? *card->name->given : '\0'; - cm = card->name->additional ? *card->name->additional : '\0'; - cl = card->name->family ? *card->name->family : '\0'; - - if (f && isupper ((gint) f)) - f = tolower ((gint) f); - if (m && isupper ((gint) m)) - m = tolower ((gint) m); - if (l && isupper ((gint) l)) - l = tolower ((gint) l); - - if (cf && isupper ((gint) cf)) - cf = tolower ((gint) cf); - if (cm && isupper ((gint) cm)) - cm = tolower ((gint) cm); - if (cl && isupper ((gint) cl)) - cl = tolower ((gint) cl); - - if ((f == '\0' || (f == cf)) && (m == '\0' || (m == cm)) && (l == '\0' || (l == cl))) { - if (score) - *score = 3; - if (m) - return g_strdup_printf ("%s %s %s", card->name->given, card->name->additional, card->name->family); - else - return g_strdup_printf ("%s %s", card->name->given, card->name->family); - } - - return NULL; -} - -static gboolean -start_initials_query (ESelectNamesCompletion *comp) -{ - gint len; - gchar *query; - - if (comp && comp->priv->query_text && *(comp->priv->query_text)) { - - len = strlen (comp->priv->query_text); - if (len < 2 || len > 3) - return FALSE; - - query = g_strdup_printf ("(contains \"x-evolution-any-field\" \"%c\")", *(comp->priv->query_text)); - query_info_start (comp, comp->priv->query_text, query, initials_query_match_cb); - g_free (query); - return TRUE; - } - - return FALSE; -} -#endif - - -/* - * - * ESelectNamesCompletion code - * - */ - - -GtkType -e_select_names_completion_get_type (void) -{ - static GtkType select_names_complete_type = 0; - - if (!select_names_complete_type) { - GtkTypeInfo select_names_complete_info = { - "ESelectNamesCompletion", - sizeof (ESelectNamesCompletion), - sizeof (ESelectNamesCompletionClass), - (GtkClassInitFunc) e_select_names_completion_class_init, - (GtkObjectInitFunc) e_select_names_completion_init, - NULL, NULL, /* reserved */ - (GtkClassInitFunc) NULL - }; - - select_names_complete_type = gtk_type_unique (e_completion_get_type (), &select_names_complete_info); - } - - return select_names_complete_type; -} - -static void -e_select_names_completion_class_init (ESelectNamesCompletionClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); - ECompletionClass *completion_class = E_COMPLETION_CLASS (klass); - - parent_class = GTK_OBJECT_CLASS (gtk_type_class (e_completion_get_type ())); - - object_class->destroy = e_select_names_completion_destroy; - - completion_class->begin_completion = e_select_names_completion_begin; - completion_class->end_completion = e_select_names_completion_end; - completion_class->cancel_completion = e_select_names_completion_cancel; - - if (getenv ("EVO_DEBUG_SELECT_NAMES_COMPLETION")) { - out = fopen ("/tmp/evo-debug-select-names-completion", "w"); - if (out) - setvbuf (out, NULL, _IONBF, 0); - } -} - -static void -e_select_names_completion_init (ESelectNamesCompletion *comp) -{ - comp->priv = g_new0 (struct _ESelectNamesCompletionPrivate, 1); - comp->priv->match_contact_lists = TRUE; -} - -static void -e_select_names_completion_destroy (GtkObject *object) -{ - ESelectNamesCompletion *comp = E_SELECT_NAMES_COMPLETION (object); - - if (comp->priv->model) - gtk_object_unref (GTK_OBJECT (comp->priv->model)); - - if (comp->priv->book) - gtk_object_unref (GTK_OBJECT (comp->priv->book)); - - if (comp->priv->book_view) - gtk_object_unref (GTK_OBJECT (comp->priv->book_view)); - - g_free (comp->priv->waiting_query); - g_free (comp->priv->query_text); - - g_free (comp->priv->cached_query_text); - g_list_foreach (comp->priv->cached_cards, (GFunc)gtk_object_unref, NULL); - g_list_free (comp->priv->cached_cards); - - g_free (comp->priv); - - if (parent_class->destroy) - parent_class->destroy (object); -} - - -/* - * - * EBook/EBookView Callbacks & Query Stuff - * - */ - -static gchar * -clean_query_text (const gchar *s) -{ - gchar *q = g_new (gchar, strlen(s)+1), *t; - - t = q; - while (*s) { - if (*s != ',' && *s != '"') { - *t = *s; - ++t; - } - ++s; - } - *t = '\0'; - - return q; -} - -static void -e_select_names_completion_clear_cache (ESelectNamesCompletion *comp) -{ - g_free (comp->priv->cached_query_text); - comp->priv->cached_query_text = NULL; - - g_list_foreach (comp->priv->cached_cards, (GFunc)gtk_object_unref, NULL); - g_list_free (comp->priv->cached_cards); - comp->priv->cached_cards = NULL; -} - -static void -e_select_names_completion_got_book_view_cb (EBook *book, EBookStatus status, EBookView *view, gpointer user_data) -{ - ESelectNamesCompletion *comp; - - if (status != E_BOOK_STATUS_SUCCESS) - return; - - comp = E_SELECT_NAMES_COMPLETION (user_data); - - comp->priv->cancelled = FALSE; - - comp->priv->book_view_tag = 0; - - comp->priv->book_view = view; - gtk_object_ref (GTK_OBJECT (view)); - - gtk_signal_connect (GTK_OBJECT (view), - "card_added", - GTK_SIGNAL_FUNC (e_select_names_completion_card_added_cb), - comp); - gtk_signal_connect (GTK_OBJECT (view), - "sequence_complete", - GTK_SIGNAL_FUNC (e_select_names_completion_seq_complete_cb), - comp); -} - -static void -e_select_names_completion_card_added_cb (EBookView *book_view, const GList *cards, gpointer user_data) -{ - ESelectNamesCompletion *comp = E_SELECT_NAMES_COMPLETION (user_data); - - if (! comp->priv->cancelled) - book_query_process_card_list (comp, cards); - - /* Save the list of matching cards. */ - while (cards) { - comp->priv->cached_cards = g_list_prepend (comp->priv->cached_cards, cards->data); - gtk_object_ref (GTK_OBJECT (cards->data)); - cards = g_list_next (cards); - } -} - -static void -e_select_names_completion_seq_complete_cb (EBookView *book_view, gpointer user_data) -{ - ESelectNamesCompletion *comp = E_SELECT_NAMES_COMPLETION (user_data); - - gtk_object_unref (GTK_OBJECT (comp->priv->book_view)); - - comp->priv->book_view = NULL; - - g_free (comp->priv->query_text); - comp->priv->query_text = NULL; - - if (out) - fprintf (out, "ending search "); - if (out && !e_completion_searching (E_COMPLETION (comp))) - fprintf (out, "while not searching!"); - if (out) - fprintf (out, "\n"); - e_completion_end_search (E_COMPLETION (comp)); /* That's all folks! */ - - /* Need to launch a new completion if another one is pending. */ - if (comp->priv->waiting_query) { - gchar *s = comp->priv->waiting_query; - comp->priv->waiting_query = NULL; - e_completion_begin_search (E_COMPLETION (comp), s, comp->priv->waiting_pos, comp->priv->waiting_limit); - g_free (s); - } -} - -static void -e_select_names_completion_stop_query (ESelectNamesCompletion *comp) -{ - g_return_if_fail (comp && E_IS_SELECT_NAMES_COMPLETION (comp)); - - if (out) - fprintf (out, "stopping query\n"); - - if (comp->priv->waiting_query) { - if (out) - fprintf (out, "stopped waiting query\n"); - g_free (comp->priv->waiting_query); - comp->priv->waiting_query = NULL; - } - - g_free (comp->priv->query_text); - comp->priv->query_text = NULL; - - if (comp->priv->book_view_tag) { - if (out) - fprintf (out, "cancelled book view creation\n"); - e_book_cancel (comp->priv->book, comp->priv->book_view_tag); - comp->priv->book_view_tag = 0; - } - - if (comp->priv->book_view) { - if (out) - fprintf (out, "unrefed book view\n"); - gtk_object_unref (GTK_OBJECT (comp->priv->book_view)); - comp->priv->book_view = NULL; - } - - /* Clear the cache, which may contain partial results. */ - e_select_names_completion_clear_cache (comp); - -} - -static void -e_select_names_completion_start_query (ESelectNamesCompletion *comp, const gchar *query_text) -{ - g_return_if_fail (comp && E_IS_SELECT_NAMES_COMPLETION (comp)); - g_return_if_fail (query_text); - - e_select_names_completion_stop_query (comp); /* Stop any prior queries. */ - - if (comp->priv->book_ready) { - gchar *sexp; - - g_free (comp->priv->query_text); - comp->priv->query_text = g_strdup (query_text); - - g_free (comp->priv->cached_query_text); - comp->priv->cached_query_text = g_strdup (query_text); - - sexp = book_query_sexp (comp); - if (sexp && *sexp) { - - if (out) - fprintf (out, "\n\n**** starting query: \"%s\"\n", comp->priv->query_text); - - comp->priv->book_view_tag = e_book_get_book_view (comp->priv->book, sexp, - e_select_names_completion_got_book_view_cb, comp); - - if (! comp->priv->book_view_tag) - g_warning ("Exception calling e_book_get_book_view"); - - } else { - g_free (comp->priv->query_text); - comp->priv->query_text = NULL; - } - g_free (sexp); - - } else { - - comp->priv->waiting_query = g_strdup (query_text); - - } -} - -static void -e_select_names_completion_do_query (ESelectNamesCompletion *comp, const gchar *query_text, gint pos, gint limit) -{ - gchar *clean; - gboolean query_is_still_running, can_reuse_cached_cards; - - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_COMPLETION (comp)); - - clean = clean_query_text (query_text); - if (! (clean && *clean)) { - g_free (clean); - e_completion_end_search (E_COMPLETION (comp)); - return; - } - - query_is_still_running = comp->priv->book_view_tag || comp->priv->book_view; - - if (out) { - fprintf (out, "do_query: %s => %s\n", query_text, clean); - if (query_is_still_running) - fprintf (out, "a query is still running!\n"); - } - if (comp->priv->cached_query_text && out) - fprintf (out, "cached: %s\n", comp->priv->cached_query_text); - - can_reuse_cached_cards = (comp->priv->cached_query_text - && (strlen (comp->priv->cached_query_text) <= strlen (clean)) - && !g_utf8_strncasecmp (comp->priv->cached_query_text, clean, strlen (comp->priv->cached_query_text))); - - - if (can_reuse_cached_cards) { - - if (out) - fprintf (out, "can reuse cached card!\n"); - - if (query_is_still_running) { - g_free (comp->priv->waiting_query); - comp->priv->waiting_query = clean; - comp->priv->waiting_pos = pos; - comp->priv->waiting_limit = limit; - if (out) - fprintf (out, "waiting for running query to complete: %s\n", comp->priv->waiting_query); - return; - } - - g_free (comp->priv->query_text); - comp->priv->query_text = clean; - if (out) - fprintf (out, "using existing query info: %s (vs %s)\n", comp->priv->query_text, comp->priv->cached_query_text); - comp->priv->cancelled = FALSE; - book_query_process_card_list (comp, comp->priv->cached_cards); - e_completion_end_search (E_COMPLETION (comp)); - return; - } - - e_select_names_completion_start_query (comp, clean); - g_free (clean); -} - - -/* - * - * Completion Search Override - a Framework for Christian-Resurrection-Holiday Edible-Chicken-Ova - * - */ - -typedef struct _SearchOverride SearchOverride; -struct _SearchOverride { - const gchar *trigger; - const gchar *text[4]; -}; -static SearchOverride override[] = { - { "why?", { "\"I must create a system, or be enslaved by another man's.\"", - " -- Wiliam Blake, \"Jerusalem\"", - NULL } }, - { NULL, { NULL } } }; - -static gboolean -search_override_check (SearchOverride *over, const gchar *text) -{ - /* The g_utf8_validate is needed because as of 2001-06-11, - * EText doesn't translate from locale->UTF8 when you paste - * into it. - */ - if (over == NULL || text == NULL || !g_utf8_validate (text, -1, NULL)) - return FALSE; - - return !g_utf8_strcasecmp (over->trigger, text); -} - - -/* - * - * Completion Callbacks - * - */ - -static void -e_select_names_completion_begin (ECompletion *comp, const gchar *text, gint pos, gint limit) -{ - ESelectNamesCompletion *selcomp = E_SELECT_NAMES_COMPLETION (comp); - const gchar *str; - gint index, j; - - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_COMPLETION (comp)); - g_return_if_fail (text != NULL); - - if (out) { - fprintf (out, "\n\n**** requesting completion\n"); - fprintf (out, "text=\"%s\" pos=%d limit=%d\n", text, pos, limit); - } - - e_select_names_model_text_pos (selcomp->priv->model, pos, &index, NULL, NULL); - str = index >= 0 ? e_select_names_model_get_string (selcomp->priv->model, index) : NULL; - - if (out) - fprintf (out, "index=%d str=\"%s\"\n", index, str); - - if (str == NULL || *str == '\0') { - if (out) - fprintf (out, "aborting empty query\n"); - e_completion_end_search (comp); - return; - } - - for (j=0; override[j].trigger; ++j) { - if (search_override_check (&(override[j]), str)) { - gint k; - - for (k=0; override[j].text[k]; ++k) { - ECompletionMatch *match = g_new (ECompletionMatch, 1); - e_completion_match_construct (match); - e_completion_match_set_text (match, text, override[j].text[k]); - match->score = 1 / (double) (k + 1); - e_completion_found_match (comp, match); - } - - e_completion_end_search (comp); - return; - } - } - - e_select_names_completion_do_query (selcomp, str, pos, limit); -} - -static void -e_select_names_completion_end (ECompletion *comp) -{ - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_COMPLETION (comp)); - - if (out) - fprintf (out, "completion ended\n"); -} - -static void -e_select_names_completion_cancel (ECompletion *comp) -{ - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_COMPLETION (comp)); - - E_SELECT_NAMES_COMPLETION (comp)->priv->cancelled = TRUE; - - if (out) - fprintf (out, "completion cancelled\n"); -} - -static void -e_select_names_completion_book_ready (EBook *book, EBookStatus status, ESelectNamesCompletion *comp) -{ - comp->priv->book_ready = TRUE; - - g_return_if_fail (book != NULL); - g_return_if_fail (E_IS_BOOK (book)); - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_COMPLETION (comp)); - - /* If waiting_query is non-NULL, someone tried to start a query before the book was ready. - Now that it is, get started. */ - if (comp->priv->waiting_query) { - e_select_names_completion_start_query (comp, comp->priv->waiting_query); - g_free (comp->priv->waiting_query); - comp->priv->waiting_query = NULL; - } - - gtk_object_unref (GTK_OBJECT (comp)); /* post-async unref */ -} - - -/* - * - * Our Pseudo-Constructor - * - */ - -ECompletion * -e_select_names_completion_new (EBook *book, ESelectNamesModel *model) -{ - ESelectNamesCompletion *comp; - - g_return_val_if_fail (book == NULL || E_IS_BOOK (book), NULL); - g_return_val_if_fail (model, NULL); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), NULL); - - comp = (ESelectNamesCompletion *) gtk_type_new (e_select_names_completion_get_type ()); - - if (book == NULL) { - - comp->priv->book = e_book_new (); - gtk_object_ref (GTK_OBJECT (comp->priv->book)); - gtk_object_sink (GTK_OBJECT (comp->priv->book)); - - comp->priv->book_ready = FALSE; - gtk_object_ref (GTK_OBJECT (comp)); /* ref ourself before our async call */ - e_book_load_local_address_book (comp->priv->book, (EBookCallback) e_select_names_completion_book_ready, comp); - - } else { - comp->priv->book = book; - gtk_object_ref (GTK_OBJECT (comp->priv->book)); - comp->priv->book_ready = TRUE; - } - - comp->priv->model = model; - gtk_object_ref (GTK_OBJECT (model)); - - return E_COMPLETION (comp); -} - -gboolean -e_select_names_completion_get_match_contact_lists (ESelectNamesCompletion *comp) -{ - g_return_val_if_fail (E_IS_SELECT_NAMES_COMPLETION (comp), FALSE); - return comp->priv->match_contact_lists; -} - - -void -e_select_names_completion_set_match_contact_lists (ESelectNamesCompletion *comp, gboolean x) -{ - g_return_if_fail (E_IS_SELECT_NAMES_COMPLETION (comp)); - comp->priv->match_contact_lists = x; -} diff --git a/addressbook/gui/component/select-names/e-select-names-completion.h b/addressbook/gui/component/select-names/e-select-names-completion.h deleted file mode 100644 index cfa496ca69..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-completion.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-select-names-completion.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge - */ - -/* - * 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_COMPLETION_H -#define E_SELECT_NAMES_COMPLETION_H - -#include -#include -#include "e-select-names-model.h" - -BEGIN_GNOME_DECLS - -#define E_SELECT_NAMES_COMPLETION_TYPE (e_select_names_completion_get_type ()) -#define E_SELECT_NAMES_COMPLETION(o) (GTK_CHECK_CAST ((o), E_SELECT_NAMES_COMPLETION_TYPE, ESelectNamesCompletion)) -#define E_SELECT_NAMES_COMPLETION_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), E_SELECT_NAMES_COMPLETION_TYPE, ESelectNamesCompletionClass)) -#define E_IS_SELECT_NAMES_COMPLETION(o) (GTK_CHECK_TYPE ((o), E_SELECT_NAMES_COMPLETION_TYPE)) -#define E_IS_SELECT_NAMES_COMPLETION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SELECT_NAMES_COMPLETION_TYPE)) - -typedef struct _ESelectNamesCompletion ESelectNamesCompletion; -typedef struct _ESelectNamesCompletionClass ESelectNamesCompletionClass; -struct _ESelectNamesCompletionPrivate; - -struct _ESelectNamesCompletion { - ECompletion parent; - - struct _ESelectNamesCompletionPrivate *priv; -}; - -struct _ESelectNamesCompletionClass { - ECompletionClass parent_class; - -}; - -GtkType e_select_names_completion_get_type (void); - -ECompletion *e_select_names_completion_new (EBook *, ESelectNamesModel *); - -gboolean e_select_names_completion_get_match_contact_lists (ESelectNamesCompletion *); -void e_select_names_completion_set_match_contact_lists (ESelectNamesCompletion *, gboolean); - -END_GNOME_DECLS - -#endif /* E_SELECT_NAMES_COMPLETION_H */ - diff --git a/addressbook/gui/component/select-names/e-select-names-factory.c b/addressbook/gui/component/select-names/e-select-names-factory.c deleted file mode 100644 index 7f65110c2a..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-factory.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-select-names-factory.c - * - * Copyright (C) 2000 Ximian, Inc. - * - * 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. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "e-select-names-bonobo.h" -#include "e-select-names-factory.h" - - -#define COMPONENT_FACTORY_ID "OAFIID:GNOME_Evolution_Addressbook_SelectNamesFactory" - -static BonoboGenericFactory *factory = NULL; - - -static BonoboObject * -factory_fn (BonoboGenericFactory *factory, - void *closure) -{ - return BONOBO_OBJECT (e_select_names_bonobo_new ()); -} - - -gboolean -e_select_names_factory_init (void) -{ - if (factory != NULL) - return TRUE; - - factory = bonobo_generic_factory_new (COMPONENT_FACTORY_ID, factory_fn, NULL); - - if (factory == NULL) - return FALSE; - - return TRUE; -} diff --git a/addressbook/gui/component/select-names/e-select-names-factory.h b/addressbook/gui/component/select-names/e-select-names-factory.h deleted file mode 100644 index dbdec8a182..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-factory.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-select-names-factory.h - * - * Copyright (C) 2000 Ximian, Inc. - * - * 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. - * - * Author: Ettore Perazzoli - */ - -#ifndef _E_SECELT_NAMES_FACTORY_H -#define _E_SECELT_NAMES_FACTORY_H - -#include - -gboolean e_select_names_factory_init (void); - -#endif diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c deleted file mode 100644 index 4481438327..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ /dev/null @@ -1,512 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - */ - -#include - -#include -#include -#include - -#include - -#include "e-select-names-manager.h" -#include "e-select-names-model.h" -#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 - -/* Object argument IDs */ -enum { - ARG_0, - ARG_CARD, -}; - -enum { - CHANGED, - LAST_SIGNAL -}; - -static guint e_select_names_manager_signals[LAST_SIGNAL] = { 0 }; - - -typedef struct { - char *id; - char *title; - ESelectNamesModel *model; - ESelectNamesManager *manager; - guint changed_handler; -} ESelectNamesManagerSection; - -typedef struct { - char *id; - EEntry *entry; -} ESelectNamesManagerEntry; - -static void e_select_names_manager_init (ESelectNamesManager *manager); -static void e_select_names_manager_class_init (ESelectNamesManagerClass *klass); - -static void e_select_names_manager_destroy (GtkObject *object); -static void e_select_names_manager_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_select_names_manager_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -/** - * e_select_names_manager_get_type: - * @void: - * - * Registers the &ESelectNamesManager class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ESelectNamesManager class. - **/ -GtkType -e_select_names_manager_get_type (void) -{ - static GtkType manager_type = 0; - - if (!manager_type) { - GtkTypeInfo manager_info = { - "ESelectNamesManager", - sizeof (ESelectNamesManager), - sizeof (ESelectNamesManagerClass), - (GtkClassInitFunc) e_select_names_manager_class_init, - (GtkObjectInitFunc) e_select_names_manager_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - manager_type = gtk_type_unique (gtk_object_get_type (), &manager_info); - } - - return manager_type; -} - -/** - * e_select_names_manager_new: - * @VCard: a string in vCard format - * - * Returns: a new #ESelectNamesManager that wraps the @VCard. - */ -ESelectNamesManager * -e_select_names_manager_new (void) -{ - ESelectNamesManager *manager = E_SELECT_NAMES_MANAGER(gtk_type_new(e_select_names_manager_get_type())); - return manager; -} - -static void -e_select_names_manager_class_init (ESelectNamesManagerClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - gtk_object_add_arg_type ("ESelectNamesManager::card", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); - - object_class->destroy = e_select_names_manager_destroy; - object_class->get_arg = e_select_names_manager_get_arg; - object_class->set_arg = e_select_names_manager_set_arg; - - e_select_names_manager_signals[CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ESelectNamesManagerClass, changed), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, - GTK_TYPE_POINTER, - GTK_TYPE_INT); - gtk_object_class_add_signals (object_class, e_select_names_manager_signals, LAST_SIGNAL); -} - -/* - * ESelectNamesManager lifecycle management and vcard loading/saving. - */ - -static void -e_select_names_manager_destroy (GtkObject *object) -{ - ESelectNamesManager *manager; - - manager = E_SELECT_NAMES_MANAGER (object); - - gtk_object_unref(GTK_OBJECT(manager->sections)); - gtk_object_unref(GTK_OBJECT(manager->entries)); -} - - -/* Set_arg handler for the manager */ -static void -e_select_names_manager_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesManager *manager; - - manager = E_SELECT_NAMES_MANAGER (object); - - switch (arg_id) { - case ARG_CARD: - break; - default: - return; - } -} - -/* Get_arg handler for the manager */ -static void -e_select_names_manager_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesManager *manager; - - manager = E_SELECT_NAMES_MANAGER (object); - - switch (arg_id) { - case ARG_CARD: - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void * -section_copy(const void *sec, void *data) -{ - const ESelectNamesManagerSection *section = sec; - ESelectNamesManagerSection *newsec; - - static void section_model_changed_cb (ESelectNamesModel *, gpointer); - - newsec = g_new(ESelectNamesManagerSection, 1); - newsec->id = g_strdup(section->id); - newsec->title = g_strdup(section->title); - newsec->model = section->model; - newsec->manager = section->manager; - newsec->changed_handler = gtk_signal_connect (GTK_OBJECT (newsec->model), - "changed", - GTK_SIGNAL_FUNC (section_model_changed_cb), - newsec); - - if (newsec->model) - gtk_object_ref(GTK_OBJECT(newsec->model)); - return newsec; -} - -static void -section_free(void *sec, void *data) -{ - ESelectNamesManagerSection *section = sec; - if (section->manager && section->changed_handler) { - gtk_signal_disconnect (GTK_OBJECT (section->model), section->changed_handler); - } - g_free(section->id); - g_free(section->title); - if (section->model) - gtk_object_unref(GTK_OBJECT(section->model)); - g_free(section); -} - -static void * -entry_copy(const void *ent, void *data) -{ - const ESelectNamesManagerEntry *entry = ent; - ESelectNamesManagerEntry *newent; - - newent = g_new(ESelectNamesManagerEntry, 1); - newent->id = g_strdup(entry->id); - newent->entry = entry->entry; - if (newent->entry) - gtk_object_ref(GTK_OBJECT(newent->entry)); - return newent; -} - -static void -entry_free(void *ent, void *data) -{ - ESelectNamesManagerEntry *entry = ent; - g_free(entry->id); - if (entry->entry) - gtk_object_unref(GTK_OBJECT(entry->entry)); - g_free(entry); -} - -/** - * e_select_names_manager_init: - */ -static void -e_select_names_manager_init (ESelectNamesManager *manager) -{ - manager->sections = e_list_new(section_copy, section_free, manager); - manager->entries = e_list_new(entry_copy, entry_free, manager); -} - -static void -section_model_changed_cb (ESelectNamesModel *model, gpointer closure) -{ - ESelectNamesManagerSection *section = closure; - gtk_signal_emit (GTK_OBJECT (section->manager), - e_select_names_manager_signals[CHANGED], - section->id, - FALSE); -} - -static void -section_model_working_copy_changed_cb (ESelectNamesModel *model, gpointer closure) -{ - ESelectNamesManagerSection *section = closure; - gtk_signal_emit (GTK_OBJECT (section->manager), - e_select_names_manager_signals[CHANGED], - section->id, - TRUE); -} - -void -e_select_names_manager_add_section (ESelectNamesManager *manager, - const char *id, - const char *title) -{ - e_select_names_manager_add_section_with_limit (manager, id, title, -1); -} - -void -e_select_names_manager_add_section_with_limit (ESelectNamesManager *manager, - const char *id, - const char *title, - gint limit) -{ - ESelectNamesManagerSection *section; - - section = g_new(ESelectNamesManagerSection, 1); - section->id = g_strdup(id); - section->title = g_strdup(title); - - section->model = e_select_names_model_new(); - e_select_names_model_set_limit (section->model, limit); - - section->manager = manager; - - section->changed_handler = gtk_signal_connect (GTK_OBJECT (section->model), - "changed", - GTK_SIGNAL_FUNC (section_model_changed_cb), - section); - - e_list_append(manager->sections, section); - section_free(section, manager); -} - -ESelectNamesModel * -e_select_names_manager_get_source (ESelectNamesManager *manager, const char *id) -{ - EIterator *iterator; - - g_return_val_if_fail (manager && E_IS_SELECT_NAMES_MANAGER (manager), NULL); - g_return_val_if_fail (id, NULL); - - iterator = e_list_get_iterator (manager->sections); - for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) { - const ESelectNamesManagerSection *section = e_iterator_get (iterator); - if (!strcmp (section->id, id)) { - return section->model; - } - } - - return NULL; -} - -static void -entry_destroyed(EEntry *entry, ESelectNamesManager *manager) -{ - if(!GTK_OBJECT_DESTROYED(manager)) { - EIterator *iterator = e_list_get_iterator(manager->entries); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ESelectNamesManagerEntry *this_entry = e_iterator_get(iterator); - if(entry == this_entry->entry) { - e_iterator_delete(iterator); - break; - } - } - } - gtk_object_unref(GTK_OBJECT(manager)); -} - -static void -completion_handler (EEntry *entry, ECompletionMatch *match) -{ - ESelectNamesModel *snm; - EDestination *dest; - gint i, pos, start_pos, len; - - if (match == NULL || match->user_data == NULL) - return; - - - snm = E_SELECT_NAMES_MODEL (gtk_object_get_data (GTK_OBJECT (entry), "select_names_model")); - dest = E_DESTINATION (match->user_data); - - /* Sometimes I really long for garbage collection. Reference - counting makes you feel 31337, but sometimes it is just a - bitch. */ - gtk_object_ref (GTK_OBJECT (dest)); - - pos = e_entry_get_position (entry); - e_select_names_model_text_pos (snm, pos, &i, NULL, NULL); - e_select_names_model_replace (snm, i, dest); - e_select_names_model_name_pos (snm, i, &start_pos, &len); - 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) -{ - ETextModel *model; - EIterator *iterator; - iterator = e_list_get_iterator(manager->sections); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ESelectNamesManagerSection *section = e_iterator_get(iterator); - if (!strcmp(section->id, id)) { - ESelectNamesManagerEntry *entry; - EEntry *eentry; - ECompletion *comp; - - 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; - - model = e_select_names_text_model_new (section->model); - e_list_append (manager->entries, entry); - g_free(entry); - - comp = e_select_names_completion_new (NULL, section->model); /* NULL == use local addressbook */ - e_entry_enable_completion_full (eentry, comp, 50, completion_handler); - - gtk_object_set_data (GTK_OBJECT (eentry), "completion_handler", comp); - - gtk_object_set(GTK_OBJECT(eentry), - "model", model, - "editable", TRUE, - "use_ellipsis", TRUE, - "allow_newlines", FALSE, - NULL); - gtk_signal_connect(GTK_OBJECT(eentry), "destroy", - GTK_SIGNAL_FUNC(entry_destroyed), manager); - gtk_object_ref(GTK_OBJECT(manager)); - return GTK_WIDGET(eentry); - } - } - return NULL; -} - -static void -e_select_names_clicked(ESelectNames *dialog, gint button, ESelectNamesManager *manager) -{ - switch(button) { - case 0: { - EList *list = manager->sections; - EIterator *iterator = e_list_get_iterator(list); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - ESelectNamesManagerSection *section = (void *) e_iterator_get(iterator); - ESelectNamesModel *source = e_select_names_get_source(dialog, section->id); - e_select_names_model_overwrite_copy (section->model, source); - gtk_object_unref (GTK_OBJECT (source)); - - } - gtk_object_unref(GTK_OBJECT(iterator)); - -#if 0 - list = manager->entries; - iterator = e_list_get_iterator(list); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - ESelectNamesManagerEntry *entry = (void *) e_iterator_get(iterator); - ESelectNamesModel *source = e_select_names_get_source(dialog, entry->id); - if (source) { - ETextModel *model = e_select_names_text_model_new(source); - if (model) { - gtk_object_set(GTK_OBJECT(entry->entry), - "model", model, - NULL); - gtk_object_unref(GTK_OBJECT(source)); - } - gtk_object_unref(GTK_OBJECT(model)); - } - } - gtk_object_unref(GTK_OBJECT(iterator)); -#endif - break; - } - } - gnome_dialog_close(GNOME_DIALOG(dialog)); -} - -void -e_select_names_manager_activate_dialog (ESelectNamesManager *manager, - const char *id) -{ - EIterator *iterator; - - if (manager->names) { - g_assert (GTK_WIDGET_REALIZED (GTK_WIDGET (manager->names))); - e_select_names_set_default(manager->names, id); - gdk_window_show (GTK_WIDGET (manager->names)->window); - gdk_window_raise (GTK_WIDGET (manager->names)->window); - } else { - manager->names = E_SELECT_NAMES (e_select_names_new ()); - - iterator = e_list_get_iterator(manager->sections); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ESelectNamesManagerSection *section = e_iterator_get(iterator); - ESelectNamesModel *newmodel = e_select_names_model_duplicate(section->model); - e_select_names_add_section(manager->names, section->id, section->title, newmodel); - gtk_signal_connect (GTK_OBJECT (newmodel), - "changed", - GTK_SIGNAL_FUNC (section_model_working_copy_changed_cb), - (gpointer)section); /* casting out const to avoid compiler warning */ - gtk_object_unref(GTK_OBJECT(newmodel)); - } - e_select_names_set_default(manager->names, id); - gtk_signal_connect(GTK_OBJECT(manager->names), "clicked", - GTK_SIGNAL_FUNC(e_select_names_clicked), manager); - gtk_signal_connect(GTK_OBJECT(manager->names), "destroy", - GTK_SIGNAL_FUNC(gtk_widget_destroyed), - &manager->names); - gtk_widget_show(GTK_WIDGET(manager->names)); - } -} - -#if 0 -/* Of type ECard */ -EList * -e_select_names_manager_get_cards (ESelectNamesManager *manager, - const char *id) -{ - EIterator *iterator; - iterator = e_list_get_iterator(manager->sections); - for (e_iterator_reset(iterator); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const ESelectNamesManagerSection *section = e_iterator_get(iterator); - if (!strcmp(section->id, id)) { - return e_select_names_model_get_cards(section->model); - } - } - return NULL; -} -#endif diff --git a/addressbook/gui/component/select-names/e-select-names-manager.h b/addressbook/gui/component/select-names/e-select-names-manager.h deleted file mode 100644 index 61779fb56a..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-manager.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - */ - -#ifndef __E_SELECT_NAMES_MANAGER_H__ -#define __E_SELECT_NAMES_MANAGER_H__ - -#include -#include -#include -#include -#include "e-select-names.h" - -#define E_TYPE_SELECT_NAMES_MANAGER (e_select_names_manager_get_type ()) -#define E_SELECT_NAMES_MANAGER(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SELECT_NAMES_MANAGER, ESelectNamesManager)) -#define E_SELECT_NAMES_MANAGER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SELECT_NAMES_MANAGER, ESelectNamesManagerClass)) -#define E_IS_SELECT_NAMES_MANAGER(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SELECT_NAMES_MANAGER)) -#define E_IS_SELECT_NAMES_MANAGER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SELECT_NAMES_MANAGER)) - -typedef struct _ESelectNamesManager ESelectNamesManager; -typedef struct _ESelectNamesManagerClass ESelectNamesManagerClass; - -struct _ESelectNamesManager { - GtkObject object; - - EList *sections; - EList *entries; - - ESelectNames *names; -}; - -struct _ESelectNamesManagerClass { - GtkObjectClass parent_class; - - void (*changed) (ESelectNamesManager *, const gchar *section_id, gint changed_working_copy); -}; - -ESelectNamesManager *e_select_names_manager_new (void); -void e_select_names_manager_add_section (ESelectNamesManager *manager, - const char *id, - const char *title); -void e_select_names_manager_add_section_with_limit (ESelectNamesManager *manager, - const char *id, - const char *title, - gint limit); -ESelectNamesModel *e_select_names_manager_get_source (ESelectNamesManager *manager, - const char *id); -GtkWidget *e_select_names_manager_create_entry (ESelectNamesManager *manager, - const char *id); -void e_select_names_manager_activate_dialog (ESelectNamesManager *manager, - const char *id); - -#if 0 -/* Of type ECard */ -EList *e_select_names_manager_get_cards (ESelectNamesManager *manager, - const char *id); -#endif - -/* Standard Gtk function */ -GtkType e_select_names_manager_get_type (void); - -#endif /* ! __E_SELECT_NAMES_MANAGER_H__ */ diff --git a/addressbook/gui/component/select-names/e-select-names-model.c b/addressbook/gui/component/select-names/e-select-names-model.c deleted file mode 100644 index dc383994d3..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-model.c +++ /dev/null @@ -1,694 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * Jon Trowbidge - * - * Copyright (C) 2000, 2001 Ximian, Inc. - */ - -#include - -#include -#include -#include -#include -#include - -#include - -#include "e-select-names-model.h" -#include "addressbook/backend/ebook/e-card-simple.h" - -#define SEPARATOR ", " -#define SEPLEN 2 - - -enum { - E_SELECT_NAMES_MODEL_CHANGED, - E_SELECT_NAMES_MODEL_RESIZED, - E_SELECT_NAMES_MODEL_LAST_SIGNAL -}; - -static guint e_select_names_model_signals[E_SELECT_NAMES_MODEL_LAST_SIGNAL] = { 0 }; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_CARD, -}; - -enum { - NAME_DATA_BLANK, - NAME_DATA_CARD, - NAME_DATA_STRING -}; - -enum { - NAME_FORMAT_GIVEN_FIRST, - NAME_FORMAT_FAMILY_FIRST -}; - -struct _ESelectNamesModelPrivate { - gchar *id; - gchar *title; - - GList *data; /* of EDestination */ - gchar *text; - gchar *addr_text; - - gint limit; -}; - - -static void e_select_names_model_init (ESelectNamesModel *model); -static void e_select_names_model_class_init (ESelectNamesModelClass *klass); - -static void e_select_names_model_destroy (GtkObject *object); -static void e_select_names_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_select_names_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -GtkType -e_select_names_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ESelectNamesModel", - sizeof (ESelectNamesModel), - sizeof (ESelectNamesModelClass), - (GtkClassInitFunc) e_select_names_model_class_init, - (GtkObjectInitFunc) e_select_names_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (gtk_object_get_type (), &model_info); - } - - return model_type; -} - -typedef void (*GtkSignal_NONE__INT_INT_INT) (GtkObject *object, gint arg1, gint arg2, gint arg3, gpointer user_data); -static void -local_gtk_marshal_NONE__INT_INT_INT (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_NONE__INT_INT_INT rfunc; - rfunc = (GtkSignal_NONE__INT_INT_INT) func; - (* rfunc) (object, - GTK_VALUE_INT(args[0]), - GTK_VALUE_INT(args[1]), - GTK_VALUE_INT(args[2]), - func_data); -} - - -static void -e_select_names_model_class_init (ESelectNamesModelClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - e_select_names_model_signals[E_SELECT_NAMES_MODEL_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ESelectNamesModelClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_select_names_model_signals[E_SELECT_NAMES_MODEL_RESIZED] = - gtk_signal_new ("resized", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ESelectNamesModelClass, resized), - local_gtk_marshal_NONE__INT_INT_INT, - GTK_TYPE_NONE, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_select_names_model_signals, E_SELECT_NAMES_MODEL_LAST_SIGNAL); - - gtk_object_add_arg_type ("ESelectNamesModel::card", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_CARD); - - klass->changed = NULL; - - object_class->destroy = e_select_names_model_destroy; - object_class->get_arg = e_select_names_model_get_arg; - object_class->set_arg = e_select_names_model_set_arg; -} - -/** - * e_select_names_model_init: - */ -static void -e_select_names_model_init (ESelectNamesModel *model) -{ - model->priv = g_new0 (struct _ESelectNamesModelPrivate, 1); - - model->priv->limit = -1; -} - -static void -e_select_names_model_destroy (GtkObject *object) -{ - ESelectNamesModel *model = E_SELECT_NAMES_MODEL (object); - - g_free (model->priv->title); - g_free (model->priv->id); - - g_list_foreach (model->priv->data, (GFunc) gtk_object_unref, NULL); - g_list_free (model->priv->data); - - g_free (model->priv->text); - g_free (model->priv->addr_text); - - g_free (model->priv); - -} - - -/* Set_arg handler for the model */ -static void -e_select_names_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesModel *model; - - model = E_SELECT_NAMES_MODEL (object); - - switch (arg_id) { - case ARG_CARD: - break; - default: - return; - } -} - -/* Get_arg handler for the model */ -static void -e_select_names_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesModel *model; - - model = E_SELECT_NAMES_MODEL (object); - - switch (arg_id) { - case ARG_CARD: - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - - -static void -e_select_names_model_changed (ESelectNamesModel *model) -{ - g_free (model->priv->text); - model->priv->text = NULL; - - g_free (model->priv->addr_text); - model->priv->addr_text = NULL; - - gtk_signal_emit (GTK_OBJECT(model), e_select_names_model_signals[E_SELECT_NAMES_MODEL_CHANGED]); -} - -/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ - -ESelectNamesModel * -e_select_names_model_new (void) -{ - ESelectNamesModel *model; - model = E_SELECT_NAMES_MODEL (gtk_type_new (e_select_names_model_get_type ())); - return model; -} - -ESelectNamesModel * -e_select_names_model_duplicate (ESelectNamesModel *old) -{ - ESelectNamesModel *model = E_SELECT_NAMES_MODEL(gtk_type_new(e_select_names_model_get_type())); - GList *iter; - - model->priv->id = g_strdup (old->priv->id); - model->priv->title = g_strdup (old->priv->title); - - for (iter = old->priv->data; iter != NULL; iter = g_list_next (iter)) { - EDestination *dup = e_destination_copy (E_DESTINATION (iter->data)); - model->priv->data = g_list_append (model->priv->data, dup); - } - - model->priv->limit = old->priv->limit; - - return model; -} - -const gchar * -e_select_names_model_get_textification (ESelectNamesModel *model) -{ - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), NULL); - - if (model->priv->text == NULL) { - - if (model->priv->data == NULL) { - - model->priv->text = g_strdup (""); - - } else { - gchar **strv = g_new0 (gchar *, g_list_length (model->priv->data)+1); - gint i = 0; - GList *iter = model->priv->data; - - while (iter) { - EDestination *dest = E_DESTINATION (iter->data); - strv[i] = (gchar *) e_destination_get_textrep (dest); - ++i; - iter = g_list_next (iter); - } - - model->priv->text = g_strjoinv (SEPARATOR, strv); - - g_free (strv); - } - } - - return model->priv->text; -} - -const gchar * -e_select_names_model_get_address_text (ESelectNamesModel *model) -{ - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), NULL); - - if (model->priv->addr_text == NULL) { - - if (model->priv->data == NULL) { - - model->priv->addr_text = g_strdup (""); - - } else { - gchar **strv = g_new0 (gchar *, g_list_length (model->priv->data)+1); - gint i = 0; - GList *iter = model->priv->data; - - while (iter) { - EDestination *dest = E_DESTINATION (iter->data); - strv[i] = (gchar *) e_destination_get_address (dest); - if (strv[i]) - ++i; - iter = g_list_next (iter); - } - - model->priv->addr_text = g_strjoinv (SEPARATOR, strv); - - g_free (strv); - } - } - - return model->priv->addr_text; -} - -gint -e_select_names_model_count (ESelectNamesModel *model) -{ - g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), 0); - - return g_list_length (model->priv->data); -} - -gint -e_select_names_model_get_limit (ESelectNamesModel *model) -{ - g_return_val_if_fail (model != NULL, 0); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), 0); - - return model->priv->limit; -} - -void -e_select_names_model_set_limit (ESelectNamesModel *model, gint limit) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - - model->priv->limit = MAX (limit, -1); -} - -gboolean -e_select_names_model_at_limit (ESelectNamesModel *model) -{ - g_return_val_if_fail (model != NULL, TRUE); - g_return_val_if_fail (E_IS_SELECT_NAMES_MODEL (model), TRUE); - - return model->priv->limit >= 0 && g_list_length (model->priv->data) >= model->priv->limit; -} - -const EDestination * -e_select_names_model_get_destination (ESelectNamesModel *model, gint index) -{ - g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL); - g_return_val_if_fail (0 <= index, NULL); - g_return_val_if_fail (index < g_list_length (model->priv->data), NULL); - - return E_DESTINATION (g_list_nth_data (model->priv->data, index)); -} - -gchar * -e_select_names_model_export_destinationv (ESelectNamesModel *model) -{ - EDestination **destv; - gchar *str; - gint i, len = 0; - GList *j; - g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL); - - len = g_list_length (model->priv->data); - destv = g_new0 (EDestination *, len+1); - - for (i=0, j = model->priv->data; j != NULL; j = g_list_next (j)) { - EDestination *dest = E_DESTINATION (j->data); - - if (dest) - destv[i++] = dest; - } - - str = e_destination_exportv (destv); - g_free (destv); - - return str; -} - -static -void send_changed (EDestination *dest, ECard *card, gpointer closure) -{ - ESelectNamesModel *model = closure; - e_select_names_model_changed (model); -} - -void -e_select_names_model_import_destinationv (ESelectNamesModel *model, - gchar *destinationv) -{ - EDestination **destv; - gint i; - - g_return_if_fail (model && E_IS_SELECT_NAMES_MODEL (model)); - - destv = e_destination_importv (destinationv); - - e_select_names_model_delete_all (model); - - if (destv == NULL) - return; - - for (i = 0; destv[i]; i++) { - e_destination_use_card (destv[i], send_changed, model); - e_select_names_model_append (model, destv[i]); - } - g_free (destv); -} - -ECard * -e_select_names_model_get_card (ESelectNamesModel *model, gint index) -{ - const EDestination *dest; - - g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL); - g_return_val_if_fail (0 <= index, NULL); - g_return_val_if_fail (index < g_list_length (model->priv->data), NULL); - - dest = e_select_names_model_get_destination (model, index); - return dest ? e_destination_get_card (dest) : NULL; - -} - -const gchar * -e_select_names_model_get_string (ESelectNamesModel *model, gint index) -{ - const EDestination *dest; - - g_return_val_if_fail (model && E_IS_SELECT_NAMES_MODEL (model), NULL); - g_return_val_if_fail (0 <= index, NULL); - g_return_val_if_fail (index < g_list_length (model->priv->data), NULL); - - dest = e_select_names_model_get_destination (model, index); - - return dest ? e_destination_get_textrep (dest) : ""; -} - -void -e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - g_return_if_fail (0 <= index && index <= g_list_length (model->priv->data)); - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - if (e_select_names_model_at_limit (model)) { - /* FIXME: This is bad. */ - gtk_object_unref (GTK_OBJECT (dest)); - return; - } - - model->priv->data = g_list_insert (model->priv->data, dest, index); - - gtk_object_ref (GTK_OBJECT (dest)); - gtk_object_sink (GTK_OBJECT (dest)); - - e_select_names_model_changed (model); -} - -void -e_select_names_model_append (ESelectNamesModel *model, EDestination *dest) -{ - g_return_if_fail (model && E_IS_SELECT_NAMES_MODEL (model)); - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - if (e_select_names_model_at_limit (model)) { - /* FIXME: This is bad. */ - gtk_object_unref (GTK_OBJECT (dest)); - return; - } - - model->priv->data = g_list_append (model->priv->data, dest); - - gtk_object_ref (GTK_OBJECT (dest)); - gtk_object_sink (GTK_OBJECT (dest)); - - e_select_names_model_changed (model); -} - -void -e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination *dest) -{ - GList *node; - const gchar *new_str, *old_str; - gint old_strlen=0, new_strlen=0; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - g_return_if_fail (model->priv->data == NULL || (0 <= index && index < g_list_length (model->priv->data))); - g_return_if_fail (dest && E_IS_DESTINATION (dest)); - - new_str = e_destination_get_textrep (dest); - new_strlen = new_str ? strlen (new_str) : 0; - - 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); - - if (node->data != dest) { - - old_str = e_destination_get_textrep (E_DESTINATION (node->data)); - old_strlen = old_str ? strlen (old_str) : 0; - - gtk_object_unref (GTK_OBJECT (node->data)); - - node->data = dest; - gtk_object_ref (GTK_OBJECT (dest)); - gtk_object_sink (GTK_OBJECT (dest)); - } - } - - e_select_names_model_changed (model); - - gtk_signal_emit (GTK_OBJECT (model), e_select_names_model_signals[E_SELECT_NAMES_MODEL_RESIZED], - index, old_strlen, new_strlen); -} - -void -e_select_names_model_delete (ESelectNamesModel *model, gint index) -{ - GList *node; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - g_return_if_fail (0 <= index && index < g_list_length (model->priv->data)); - - node = g_list_nth (model->priv->data, index); - gtk_object_unref (GTK_OBJECT (node->data)); - - model->priv->data = g_list_remove_link (model->priv->data, node); - g_list_free_1 (node); - - e_select_names_model_changed (model); -} - -void -e_select_names_model_clean (ESelectNamesModel *model) -{ - GList *iter, *next; - gboolean changed = FALSE; - - g_return_if_fail (model != NULL && E_IS_SELECT_NAMES_MODEL (model)); - - iter = model->priv->data; - - while (iter) { - EDestination *dest; - - next = g_list_next (iter); - dest = iter->data ? E_DESTINATION (iter->data) : NULL; - - if (dest == NULL || e_destination_is_empty (dest)) { - if (dest) - gtk_object_unref (GTK_OBJECT (dest)); - model->priv->data = g_list_remove_link (model->priv->data, iter); - g_list_free_1 (iter); - changed = TRUE; - } - - iter = next; - } - - if (changed) - e_select_names_model_changed (model); -} - -void -e_select_names_model_delete_all (ESelectNamesModel *model) -{ - g_return_if_fail (model != NULL && E_IS_SELECT_NAMES_MODEL (model)); - - g_list_foreach (model->priv->data, (GFunc) gtk_object_unref, NULL); - g_list_free (model->priv->data); - model->priv->data = NULL; - - e_select_names_model_changed (model); -} - -void -e_select_names_model_overwrite_copy (ESelectNamesModel *dest, ESelectNamesModel *src) -{ - gint i, len; - - g_return_if_fail (dest && E_IS_SELECT_NAMES_MODEL (dest)); - g_return_if_fail (src && E_IS_SELECT_NAMES_MODEL (src)); - - if (src == dest) - return; - - e_select_names_model_delete_all (dest); - len = e_select_names_model_count (src); - for (i = 0; i < len; ++i) { - const EDestination *d = e_select_names_model_get_destination (src, i); - if (d) - e_select_names_model_append (dest, e_destination_copy (d)); - } -} - -void -e_select_names_model_name_pos (ESelectNamesModel *model, gint index, gint *pos, gint *length) -{ - gint rp = 0, i, len = 0; - GList *iter; - const gchar *str; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - - i = 0; - iter = model->priv->data; - while (iter && i <= index) { - rp += len + (i > 0 ? SEPLEN : 0); - str = e_destination_get_textrep (E_DESTINATION (iter->data)); - len = str ? strlen (str) : 0; - ++i; - iter = g_list_next (iter); - } - - if (i <= index) { - rp = -1; - len = 0; - } - - if (pos) - *pos = rp; - if (length) - *length = len; -} - -void -e_select_names_model_text_pos (ESelectNamesModel *model, gint pos, gint *index, gint *start_pos, gint *length) -{ - GList *iter; - const gchar *str; - gint len = 0, i = 0, sp = 0, adj = 0; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_MODEL (model)); - - iter = model->priv->data; - - while (iter != NULL) { - str = e_destination_get_textrep (E_DESTINATION (iter->data)); - len = str ? strlen (str) : 0; - - if (sp <= pos && pos <= sp + len + adj) { - break; - } - - sp += len + adj + 1; - adj = 1; - ++i; - - iter = g_list_next (iter); - } - - if (i != 0) - ++sp; /* skip past "magic space" */ - - if (iter == NULL) { -#if 0 - g_print ("text_pos ended NULL\n"); -#endif - i = -1; - sp = -1; - len = 0; - } else { -#if 0 - g_print ("text_pos got index %d\n", i); -#endif - } - - if (index) - *index = i; - if (start_pos) - *start_pos = sp; - if (length) - *length = len; -} diff --git a/addressbook/gui/component/select-names/e-select-names-model.h b/addressbook/gui/component/select-names/e-select-names-model.h deleted file mode 100644 index b11e9503ec..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-model.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors: - * Chris Lahey - * Jon Trowbridge - * - * Copyright (C) 2000, 2001 Ximian, Inc. - */ - -#ifndef __E_SELECT_NAMES_MODEL_H__ -#define __E_SELECT_NAMES_MODEL_H__ - -#include -#include -#include -#include -#include -#include - -#define E_TYPE_SELECT_NAMES_MODEL (e_select_names_model_get_type ()) -#define E_SELECT_NAMES_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SELECT_NAMES_MODEL, ESelectNamesModel)) -#define E_SELECT_NAMES_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SELECT_NAMES_MODEL, ESelectNamesModelClass)) -#define E_IS_SELECT_NAMES_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SELECT_NAMES_MODEL)) -#define E_IS_SELECT_NAMES_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SELECT_NAMES_MODEL)) - -typedef struct _ESelectNamesModel ESelectNamesModel; -typedef struct _ESelectNamesModelClass ESelectNamesModelClass; -struct _ESelectNamesModelPrivate; - -struct _ESelectNamesModel { - GtkObject object; - - struct _ESelectNamesModelPrivate *priv; -}; - -struct _ESelectNamesModelClass { - GtkObjectClass parent_class; - - void (*changed) (ESelectNamesModel *model); - void (*resized) (ESelectNamesModel *model, gint index, gint old_len, gint new_len); -}; - -GtkType e_select_names_model_get_type (void); - -ESelectNamesModel *e_select_names_model_new (void); -ESelectNamesModel *e_select_names_model_duplicate (ESelectNamesModel *old); - -const gchar *e_select_names_model_get_textification (ESelectNamesModel *model); -const gchar *e_select_names_model_get_address_text (ESelectNamesModel *model); - -gint e_select_names_model_count (ESelectNamesModel *model); -gint e_select_names_model_get_limit (ESelectNamesModel *model); -void e_select_names_model_set_limit (ESelectNamesModel *model, gint limit); -gboolean e_select_names_model_at_limit (ESelectNamesModel *model); - -const EDestination *e_select_names_model_get_destination (ESelectNamesModel *model, gint index); -gchar *e_select_names_model_export_destinationv (ESelectNamesModel *model); -void e_select_names_model_import_destinationv (ESelectNamesModel *model, - gchar *destinationv); -ECard *e_select_names_model_get_card (ESelectNamesModel *model, gint index); -const gchar *e_select_names_model_get_string (ESelectNamesModel *model, gint index); - -void e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination *dest); -void e_select_names_model_append (ESelectNamesModel *model, EDestination *dest); -void e_select_names_model_replace (ESelectNamesModel *model, gint index, EDestination *dest); -void e_select_names_model_delete (ESelectNamesModel *model, gint index); -void e_select_names_model_delete_all (ESelectNamesModel *model); -void e_select_names_model_overwrite_copy (ESelectNamesModel *dest, ESelectNamesModel *src); - -void e_select_names_model_clean (ESelectNamesModel *model); - -void e_select_names_model_name_pos (ESelectNamesModel *model, gint index, gint *pos, gint *length); -void e_select_names_model_text_pos (ESelectNamesModel *model, gint pos, gint *index, gint *start_pos, gint *length); - -#endif /* ! __E_SELECT_NAMES_MODEL_H__ */ diff --git a/addressbook/gui/component/select-names/e-select-names-popup.c b/addressbook/gui/component/select-names/e-select-names-popup.c deleted file mode 100644 index c4cb57533d..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-popup.c +++ /dev/null @@ -1,401 +0,0 @@ -/* -*- 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 - */ - -/* - * 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 - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "e-addressbook-util.h" -#include "e-select-names-popup.h" - -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 (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); -} - -/* You are in a maze of twisty little callbacks, all alike... */ - -static void -make_contact_editor_cb (EBook *book, gpointer user_data) -{ - if (book) { - EDestination *dest = E_DESTINATION (user_data); - EContactEditor *ce; - ECard *card; - - card = (ECard *) e_destination_get_card (dest); - ce = e_addressbook_show_contact_editor (book, card, FALSE, TRUE); - e_contact_editor_raise (ce); - gtk_object_unref (GTK_OBJECT (dest)); - } -} - -static void -edit_contact_info_cb (GtkWidget *w, gpointer user_data) -{ - PopupInfo *info = (PopupInfo *) user_data; - if (info == NULL) - return; - - gtk_object_ref (GTK_OBJECT (info->dest)); - e_book_use_local_address_book (make_contact_editor_cb, (gpointer) info->dest); -} - -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 (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; -} - -static void -toggle_html_mail_cb (GtkWidget *w, gpointer user_data) -{ - PopupInfo *info = (PopupInfo *) user_data; - GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (w); - const EDestination *dest; - - if (info == NULL) - return; - - dest = info->dest; - - item = GTK_CHECK_MENU_ITEM (item); - e_destination_set_html_mail_pref ((EDestination *) dest, item->active); -} - -static void -add_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - uiinfo->type = GNOME_APP_UI_TOGGLEITEM; - uiinfo->label = _("Send HTML Mail?"); - uiinfo->moreinfo = toggle_html_mail_cb; -} - -static void -init_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (uiinfo->widget), - e_destination_get_html_mail_pref (info->dest)); - gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (uiinfo->widget), TRUE); - -} - -#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; - gint html_toggle; - - /* - * Build up our GnomeUIInfo array. - */ - - memset (uiinfo, 0, sizeof (uiinfo)); - memset (radioinfo, 0, sizeof (radioinfo)); - - card = e_destination_get_card (info->dest); - - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = (gchar *) e_destination_get_name (info->dest); - ++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)) { - gchar *label = (gchar *)e_iterator_get (iterator); - - if (label && *label) { - radioinfo[j].type = GNOME_APP_UI_ITEM; - radioinfo[j].label = label; - 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; - - add_html_mail (&(uiinfo[i]), info); - html_toggle = i; - ++i; - - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = N_("Edit Contact Info"); - uiinfo[i].moreinfo = edit_contact_info_cb; - ++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); - - 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); - } - } - - init_html_mail (&(uiinfo[html_toggle]), info); - - return pop; -} - -static void -quick_add_cb (GtkWidget *w, gpointer user_data) -{ - PopupInfo *info = (PopupInfo *) user_data; - e_contact_quick_add_free_form (e_destination_get_address (info->dest), NULL, NULL); -} - -static GtkWidget * -popup_menu_nocard (PopupInfo *info) -{ - GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT]; - gint i=0; - GtkWidget *pop; - const gchar *str; - gint html_toggle; - - memset (uiinfo, 0, sizeof (uiinfo)); - - str = e_destination_get_name (info->dest); - if (str == NULL) - str = _("Unnamed Contact"); - - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = (gchar *) str; - ++i; - - uiinfo[i].type = GNOME_APP_UI_SEPARATOR; - ++i; - - add_html_mail (&(uiinfo[i]), info); - html_toggle = i; - ++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); - - init_html_mail (&(uiinfo[html_toggle]), info); - - 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); - - 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); - if (e_destination_is_empty (dest)) - return; - - 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); - - gnome_popup_menu_do_popup (popup, NULL, NULL, ev, info); - - } else { - - popup_info_free (info); - - } -} diff --git a/addressbook/gui/component/select-names/e-select-names-popup.h b/addressbook/gui/component/select-names/e-select-names-popup.h deleted file mode 100644 index cc93534181..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-popup.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- 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 - */ - -/* - * 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/component/select-names/e-select-names-table-model.c b/addressbook/gui/component/select-names/e-select-names-table-model.c deleted file mode 100644 index fee84ce071..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-table-model.c +++ /dev/null @@ -1,344 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - */ - -#include -#include -#include -#include - -#include -#include - -#include "e-select-names-table-model.h" -#include "addressbook/backend/ebook/e-card-simple.h" - -/* Object argument IDs */ -enum { - ARG_0, - ARG_SOURCE, -}; - -static void e_select_names_table_model_init (ESelectNamesTableModel *model); -static void e_select_names_table_model_class_init (ESelectNamesTableModelClass *klass); - -static void e_select_names_table_model_destroy (GtkObject *object); -static void e_select_names_table_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_select_names_table_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_select_names_table_model_model_changed (ESelectNamesModel *source, - ESelectNamesTableModel *model); - - -static void -e_select_names_table_model_add_source (ESelectNamesTableModel *model, - ESelectNamesModel *source) -{ - model->source = source; - if (model->source) - gtk_object_ref(GTK_OBJECT(model->source)); - model->source_changed_id = gtk_signal_connect(GTK_OBJECT(model->source), "changed", - GTK_SIGNAL_FUNC(e_select_names_table_model_model_changed), - model); -} - -static void -e_select_names_table_model_drop_source (ESelectNamesTableModel *model) -{ - if (model->source_changed_id) - gtk_signal_disconnect(GTK_OBJECT(model->source), model->source_changed_id); - if (model->source) - gtk_object_unref(GTK_OBJECT(model->source)); - model->source = NULL; - model->source_changed_id = 0; -} - -/** - * e_select_names_table_model_get_type: - * @void: - * - * Registers the &ESelectNamesTableModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ESelectNamesTableModel class. - **/ -GtkType -e_select_names_table_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ESelectNamesTableModel", - sizeof (ESelectNamesTableModel), - sizeof (ESelectNamesTableModelClass), - (GtkClassInitFunc) e_select_names_table_model_class_init, - (GtkObjectInitFunc) e_select_names_table_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (e_table_model_get_type (), &model_info); - } - - return model_type; -} - -/** - * e_select_names_table_model_new: - * @VCard: a string in vCard format - * - * Returns: a new #ESelectNamesTableModel that wraps the @VCard. - */ -ETableModel * -e_select_names_table_model_new (ESelectNamesModel *source) -{ - ETableModel *model = E_TABLE_MODEL(gtk_type_new(e_select_names_table_model_get_type())); - gtk_object_set(GTK_OBJECT(model), - "source", source, - NULL); - return model; -} - -static void -fill_in_info (ESelectNamesTableModel *model) -{ - if (model->source) { - int count = e_select_names_model_count (model->source); - gint i; - - model->count = count; - model->data = g_new(ESelectNamesTableModelData, count); - - for (i = 0; i < count; ++i) { - const EDestination *dest = e_select_names_model_get_destination (model->source, i); - ECard *card = dest ? e_destination_get_card (dest) : NULL; - - if (card) { - ECardSimple *simple = e_card_simple_new(card); - model->data[i].name = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_NAME_OR_ORG); - if (model->data[i].name == 0) - model->data[i].name = g_strdup(""); - model->data[i].email = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_EMAIL); - if (model->data[i].email == 0) - model->data[i].email = g_strdup(""); - gtk_object_unref(GTK_OBJECT(simple)); - } else { - model->data[i].name = g_strdup (e_destination_get_name (dest)); - model->data[i].email = g_strdup (e_destination_get_email (dest)); - } - } - } else { - model->count = 0; - } -} - -static void -clear_info (ESelectNamesTableModel *model) -{ - int i; - for (i = 0; i < model->count; i++) { - g_free(model->data[i].name); - g_free(model->data[i].email); - } - g_free(model->data); - model->data = NULL; - model->count = -1; -} - -/* - * ESelectNamesTableModel lifecycle management and vcard loading/saving. - */ - -static void -e_select_names_table_model_destroy (GtkObject *object) -{ - ESelectNamesTableModel *model; - - model = E_SELECT_NAMES_TABLE_MODEL (object); - - e_select_names_table_model_drop_source (model); - clear_info(model); -} - -/* This function returns the number of columns in our ETableModel. */ -static int -e_select_names_table_model_col_count (ETableModel *etc) -{ - return 2; -} - -/* This function returns the number of rows in our ETableModel. */ -static int -e_select_names_table_model_row_count (ETableModel *etc) -{ - ESelectNamesTableModel *e_select_names_table_model = E_SELECT_NAMES_TABLE_MODEL(etc); - if (e_select_names_table_model->count == -1) { - if (e_select_names_table_model->source) { - fill_in_info(e_select_names_table_model); - } else { - return 0; - } - } - return e_select_names_table_model->count; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -e_select_names_table_model_value_at (ETableModel *etc, int col, int row) -{ - ESelectNamesTableModel *e_select_names_table_model = E_SELECT_NAMES_TABLE_MODEL(etc); - if (e_select_names_table_model->data == NULL) { - fill_in_info(e_select_names_table_model); - } - switch (col) { - case 0: - if (e_select_names_table_model->data[row].name == NULL) { - fill_in_info(e_select_names_table_model); - } - return e_select_names_table_model->data[row].name; - break; - case 1: - if (e_select_names_table_model->data[row].email == NULL) { - fill_in_info(e_select_names_table_model); - } - return e_select_names_table_model->data[row].email; - break; - } - return ""; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -e_select_names_table_model_set_value_at (ETableModel *etc, int col, int row, const void *val) -{ -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -e_select_names_table_model_is_cell_editable (ETableModel *etc, int col, int row) -{ - return FALSE; -} - -/* This function duplicates the value passed to it. */ -static void * -e_select_names_table_model_duplicate_value (ETableModel *etc, int col, const void *value) -{ - return g_strdup(value); -} - -/* This function frees the value passed to it. */ -static void -e_select_names_table_model_free_value (ETableModel *etc, int col, void *value) -{ - g_free(value); -} - -static void * -e_select_names_table_model_initialize_value (ETableModel *etc, int col) -{ - return g_strdup(""); -} - -static gboolean -e_select_names_table_model_value_is_empty (ETableModel *etc, int col, const void *value) -{ - return !(value && *(char *)value); -} - -static char * -e_select_names_table_model_value_to_string (ETableModel *etc, int col, const void *value) -{ - return g_strdup(value); -} - -static void -e_select_names_table_model_model_changed (ESelectNamesModel *source, - ESelectNamesTableModel *model) -{ - clear_info(model); - e_table_model_changed(E_TABLE_MODEL(model)); -} - -/* Set_arg handler for the model */ -static void -e_select_names_table_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesTableModel *model; - - model = E_SELECT_NAMES_TABLE_MODEL (object); - - switch (arg_id) { - case ARG_SOURCE: - e_select_names_table_model_drop_source (model); - e_select_names_table_model_add_source (model, E_SELECT_NAMES_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - default: - return; - } -} - -/* Get_arg handler for the model */ -static void -e_select_names_table_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesTableModel *model; - - model = E_SELECT_NAMES_TABLE_MODEL (object); - - switch (arg_id) { - case ARG_SOURCE: - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(model->source); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/** - * e_select_names_table_model_init: - */ -static void -e_select_names_table_model_init (ESelectNamesTableModel *model) -{ - model->source = NULL; - model->source_changed_id = 0; - - model->count = -1; - model->data = NULL; -} - -static void -e_select_names_table_model_class_init (ESelectNamesTableModelClass *klass) -{ - GtkObjectClass *object_class; - ETableModelClass *table_model_class; - - object_class = GTK_OBJECT_CLASS(klass); - table_model_class = E_TABLE_MODEL_CLASS(klass); - - gtk_object_add_arg_type ("ESelectNamesTableModel::source", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_SOURCE); - - object_class->destroy = e_select_names_table_model_destroy; - object_class->get_arg = e_select_names_table_model_get_arg; - object_class->set_arg = e_select_names_table_model_set_arg; - - table_model_class->column_count = e_select_names_table_model_col_count; - table_model_class->row_count = e_select_names_table_model_row_count; - table_model_class->value_at = e_select_names_table_model_value_at; - table_model_class->set_value_at = e_select_names_table_model_set_value_at; - table_model_class->is_cell_editable = e_select_names_table_model_is_cell_editable; - table_model_class->duplicate_value = e_select_names_table_model_duplicate_value; - table_model_class->free_value = e_select_names_table_model_free_value; - table_model_class->initialize_value = e_select_names_table_model_initialize_value; - table_model_class->value_is_empty = e_select_names_table_model_value_is_empty; - table_model_class->value_to_string = e_select_names_table_model_value_to_string; -} diff --git a/addressbook/gui/component/select-names/e-select-names-table-model.h b/addressbook/gui/component/select-names/e-select-names-table-model.h deleted file mode 100644 index f917ff17d8..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-table-model.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - */ - -#ifndef __E_SELECT_NAMES_TABLE_MODEL_H__ -#define __E_SELECT_NAMES_TABLE_MODEL_H__ - -#include -#include -#include -#include -#include "e-select-names-model.h" - -#define E_TYPE_SELECT_NAMES_TABLE_MODEL (e_select_names_table_model_get_type ()) -#define E_SELECT_NAMES_TABLE_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SELECT_NAMES_TABLE_MODEL, ESelectNamesTableModel)) -#define E_SELECT_NAMES_TABLE_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SELECT_NAMES_TABLE_MODEL, ESelectNamesTableModelClass)) -#define E_IS_SELECT_NAMES_TABLE_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SELECT_NAMES_TABLE_MODEL)) -#define E_IS_SELECT_NAMES_TABLE_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SELECT_NAMES_TABLE_MODEL)) - -typedef struct { - char *name; - char *email; -} ESelectNamesTableModelData; - -typedef struct _ESelectNamesTableModel ESelectNamesTableModel; -typedef struct _ESelectNamesTableModelClass ESelectNamesTableModelClass; - -struct _ESelectNamesTableModel { - ETableModel parent; - - ESelectNamesModel *source; - int source_changed_id; - - int count; - ESelectNamesTableModelData *data; /* This is used as an array. */ -}; - -struct _ESelectNamesTableModelClass { - ETableModelClass parent_class; -}; - -ETableModel *e_select_names_table_model_new (ESelectNamesModel *source); - -/* Standard Gtk function */ -GtkType e_select_names_table_model_get_type (void); - -#endif /* ! __E_SELECT_NAMES_TABLE_MODEL_H__ */ diff --git a/addressbook/gui/component/select-names/e-select-names-text-model.c b/addressbook/gui/component/select-names/e-select-names-text-model.c deleted file mode 100644 index 0183fdd236..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-text-model.c +++ /dev/null @@ -1,723 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * Jon Trowbridge - * - * Copyright (C) 2000, 2001 Ximian, Inc. - */ - -#include - -#include -#include -#include -#include - -#include - -#include -#include "e-select-names-text-model.h" -#include "e-addressbook-util.h" - -static FILE *out = NULL; /* stream for debugging spew */ - -#define SEPLEN 2 - -/* Object argument IDs */ -enum { - ARG_0, - ARG_SOURCE, -}; - -static void e_select_names_text_model_class_init (ESelectNamesTextModelClass *klass); -static void e_select_names_text_model_init (ESelectNamesTextModel *model); -static void e_select_names_text_model_destroy (GtkObject *object); -static void e_select_names_text_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_select_names_text_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_select_names_text_model_set_source (ESelectNamesTextModel *model, ESelectNamesModel *source); - -static const gchar *e_select_names_text_model_get_text (ETextModel *model); -static void e_select_names_text_model_set_text (ETextModel *model, const gchar *text); -static void e_select_names_text_model_insert (ETextModel *model, gint position, const gchar *text); -static void e_select_names_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length); -static void e_select_names_text_model_delete (ETextModel *model, gint position, gint length); - -static gint e_select_names_text_model_obj_count (ETextModel *model); -static const gchar *e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len); -static void e_select_names_text_model_activate_obj (ETextModel *model, gint n); - - -ETextModelClass *parent_class; -#define PARENT_TYPE e_text_model_get_type() - -/** - * e_select_names_text_model_get_type: - * @void: - * - * Registers the &ESelectNamesTextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ESelectNamesTextModel class. - **/ -GtkType -e_select_names_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ESelectNamesTextModel", - sizeof (ESelectNamesTextModel), - sizeof (ESelectNamesTextModelClass), - (GtkClassInitFunc) e_select_names_text_model_class_init, - (GtkObjectInitFunc) e_select_names_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (PARENT_TYPE, &model_info); - } - - return model_type; -} - -static void -e_select_names_text_model_class_init (ESelectNamesTextModelClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *text_model_class; - - object_class = GTK_OBJECT_CLASS(klass); - text_model_class = E_TEXT_MODEL_CLASS(klass); - - parent_class = gtk_type_class(PARENT_TYPE); - - gtk_object_add_arg_type ("ESelectNamesTextModel::source", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_SOURCE); - - object_class->destroy = e_select_names_text_model_destroy; - object_class->get_arg = e_select_names_text_model_get_arg; - object_class->set_arg = e_select_names_text_model_set_arg; - - text_model_class->get_text = e_select_names_text_model_get_text; - text_model_class->set_text = e_select_names_text_model_set_text; - text_model_class->insert = e_select_names_text_model_insert; - text_model_class->insert_length = e_select_names_text_model_insert_length; - text_model_class->delete = e_select_names_text_model_delete; - - text_model_class->obj_count = e_select_names_text_model_obj_count; - text_model_class->get_nth_obj = e_select_names_text_model_get_nth_obj; - text_model_class->object_activated = e_select_names_text_model_activate_obj; - - if (getenv ("EVO_DEBUG_SELECT_NAMES_TEXT_MODEL")) { - out = fopen ("/tmp/evo-debug-select-names-text-model", "w"); - if (out) - setvbuf (out, NULL, _IONBF, 0); - } -} - -static void -dump_model (ESelectNamesTextModel *text_model) -{ - ESelectNamesModel *model = text_model->source; - gint i; - - if (out == NULL) - return; - - fprintf (out, "\n*** Model State: count=%d\n", e_select_names_model_count (model)); - - for (i=0; i" : ""); - fprintf (out, "\n"); -} - -static void -e_select_names_text_model_init (ESelectNamesTextModel *model) -{ -} - -static void -e_select_names_text_model_destroy (GtkObject *object) -{ - ESelectNamesTextModel *model; - - model = E_SELECT_NAMES_TEXT_MODEL (object); - - e_select_names_text_model_set_source (model, NULL); - - if (GTK_OBJECT_CLASS(parent_class)->destroy) - GTK_OBJECT_CLASS(parent_class)->destroy(object); -} - -static void -e_select_names_text_model_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesTextModel *model; - - model = E_SELECT_NAMES_TEXT_MODEL (object); - - switch (arg_id) { - case ARG_SOURCE: - e_select_names_text_model_set_source(model, E_SELECT_NAMES_MODEL (GTK_VALUE_OBJECT (*arg))); - break; - default: - return; - } -} - -static void -e_select_names_text_model_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNamesTextModel *model; - - model = E_SELECT_NAMES_TEXT_MODEL (object); - - switch (arg_id) { - case ARG_SOURCE: - GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(model->source); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -resize_cb (ESelectNamesModel *source, gint index, gint old_len, gint new_len, ETextModel *model) -{ - EReposDeleteShift repos_del; - EReposInsertShift repos_ins; - gint pos; - - e_select_names_model_name_pos (source, index, &pos, NULL); - - if (new_len < old_len) { - - repos_del.model = model; - repos_del.pos = pos; - repos_del.len = old_len - new_len; - e_text_model_reposition (model, e_repos_delete_shift, &repos_del); - - } else if (old_len < new_len) { - - repos_ins.model = model; - repos_ins.pos = pos; - repos_ins.len = new_len - old_len; - e_text_model_reposition (model, e_repos_insert_shift, &repos_ins); - - } -} - - -static void -e_select_names_text_model_set_source (ESelectNamesTextModel *model, - ESelectNamesModel *source) -{ - if (source == model->source) - return; - - if (model->source) { - gtk_signal_disconnect (GTK_OBJECT (model->source), model->source_changed_id); - gtk_signal_disconnect (GTK_OBJECT (model->source), model->source_resize_id); - gtk_object_unref (GTK_OBJECT (model->source)); - } - - model->source = source; - - if (model->source) { - gtk_object_ref (GTK_OBJECT (model->source)); - model->source_changed_id = gtk_signal_connect_object (GTK_OBJECT(model->source), - "changed", - GTK_SIGNAL_FUNC (e_text_model_changed), - GTK_OBJECT (model)); - model->source_resize_id = gtk_signal_connect (GTK_OBJECT(model->source), - "resized", - GTK_SIGNAL_FUNC (resize_cb), - model); - } -} - -ETextModel * -e_select_names_text_model_new (ESelectNamesModel *source) -{ - ETextModel *model = E_TEXT_MODEL (gtk_type_new (e_select_names_text_model_get_type())); - e_select_names_text_model_set_source (E_SELECT_NAMES_TEXT_MODEL (model), source); - return model; -} - -static const gchar * -e_select_names_text_model_get_text (ETextModel *model) -{ - ESelectNamesTextModel *snm = E_SELECT_NAMES_TEXT_MODEL(model); - - return snm ? e_select_names_model_get_textification (snm->source) : ""; -} - -static void -e_select_names_text_model_set_text (ETextModel *model, const gchar *text) -{ - ESelectNamesTextModel *snm = E_SELECT_NAMES_TEXT_MODEL(model); - - e_select_names_model_delete_all (snm->source); - e_select_names_text_model_insert (model, 0, text); -} - -static void -e_select_names_text_model_insert (ETextModel *model, gint position, const gchar *text) -{ - e_select_names_text_model_insert_length (model, position, text, strlen (text)); -} - -static void -e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gchar *text, gint length) -{ - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - gint i; - - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_TEXT_MODEL (model)); - - if (out) { - gchar *tmp = g_strndup (text, length); - fprintf (out, ">> insert \"%s\" (len=%d) at %d\n", tmp, length, pos); - g_free (tmp); - } - - pos = CLAMP (pos, 0, strlen (e_select_names_model_get_textification (source))); - - /* We want to control all cursor motions ourselves, rather than taking hints - from the ESelectNamesModel. */ - gtk_signal_handler_block (GTK_OBJECT (source), E_SELECT_NAMES_TEXT_MODEL (model)->source_resize_id); - - /* We handle this one character at a time. */ - - for (i = 0; i < length && text[i]; ++i) { - gint index, start_pos, text_len; - gboolean inside_quote = FALSE; - - if (out) - fprintf (out, "processing [%c]\n", text[i]); - - e_select_names_model_text_pos (source, pos, &index, &start_pos, &text_len); - - if (out) - fprintf (out, "index=%d start_pos=%d text_len=%d\n", index, start_pos, text_len); - - if (text[i] == ',' && index >= 0) { /* Is this a quoted or an unquoted comma we are dealing with? */ - const EDestination *dest = e_select_names_model_get_destination (source, index); - if (dest) { - const gchar *str = e_destination_get_textrep (dest); - gint j; - if (out) - fprintf (out, "str=%s pos=%d\n", str, pos); - for (j=0; j 0 && (e_select_names_model_get_string (source, ins_point-1) == NULL)))) { - - e_select_names_model_insert (source, ins_point, e_destination_new ()); - - repos.model = model; - repos.pos = pos; - repos.len = SEPLEN; - e_text_model_reposition (model, e_repos_insert_shift, &repos); - pos += SEPLEN; - } - - } else { - EReposInsertShift repos; - gint offset = MAX (pos - start_pos, 0); - const gchar *str = e_select_names_model_get_string (source, index); - gchar *str1 = g_strndup (str, offset); - gchar *str2 = g_strdup (str+offset); - EDestination *d1 = e_destination_new (), *d2 = e_destination_new (); - - e_destination_set_string (d1, str1); - e_destination_set_string (d2, str2); - - e_select_names_model_replace (source, index, d1); - e_select_names_model_insert (source, index+1, d2); - - g_free (str1); - g_free (str2); - - repos.model = model; - repos.pos = pos; - repos.len = SEPLEN; - e_text_model_reposition (model, e_repos_insert_shift, &repos); - pos += SEPLEN; - } - - } else { - EReposInsertShift repos; - gint offset = MAX (pos - start_pos, 0); - const gchar *str; - gchar *new_str = NULL; - gint this_length = 1; - gboolean whitespace = isspace ((gint) text[i]); - - str = index >= 0 ? e_select_names_model_get_string (source, index) : NULL; - if (str && *str) { - if (pos <= start_pos) { - if (whitespace) { - /* swallow leading whitespace */ - this_length = 0; - } else { - /* Adjust for our "magic white space" */ - new_str = g_strdup_printf("%c%s%s", text[i], pos < start_pos ? " " : "", str); - if (pos < start_pos) - ++this_length; - } - } else { - new_str = g_strdup_printf ("%.*s%c%s", offset, str, text[i], str + offset); - } - } else { - if (whitespace) { - /* swallow leading whitespace */ - this_length = 0; - } else { - new_str = g_strdup_printf ("%c", text[i]); - } - } - - if (new_str) { - - EDestination *dest = e_destination_new (); - e_destination_set_string (dest, new_str); - - e_select_names_model_replace (source, index, dest); - - if (this_length > 0) { - repos.model = model; - repos.pos = pos; - repos.len = this_length; - e_text_model_reposition (model, e_repos_insert_shift, &repos); - - pos += this_length; - } - - g_free (new_str); - } - } - } - - dump_model (E_SELECT_NAMES_TEXT_MODEL (model)); - - gtk_signal_handler_unblock (GTK_OBJECT (source), E_SELECT_NAMES_TEXT_MODEL (model)->source_resize_id); -} - - -static void -e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) -{ - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - gint index, start_pos, text_len, offset; - - if (out) { - const gchar *str = e_select_names_model_get_textification (source); - gint i, len; - - fprintf (out, ">> delete %d at pos %d\n", length, pos); - - len = strlen (str); - for (i=0; isource_resize_id); - - /* First, we handle a few tricky cases. */ - - if (pos < start_pos) { - EReposAbsolute repos; - - repos.model = model; - repos.pos = pos; - e_text_model_reposition (model, e_repos_absolute, &repos); - - length -= start_pos - pos; - - if (length > 0) - e_select_names_text_model_delete (model, start_pos, length); - goto finished; - } - - if (pos == start_pos + text_len) { - /* We are positioned right at the end of an entry, possibly right in front of a comma. */ - - if (index+1 < e_select_names_model_count (source)) { - EReposDeleteShift repos; - EDestination *new_dest; - const gchar *str1 = e_select_names_model_get_string (source, index); - const gchar *str2 = e_select_names_model_get_string (source, index+1); - gchar *new_str; - - while (str1 && *str1 && isspace ((gint) *str1)) - ++str1; - while (str2 && *str2 && isspace ((gint) *str2)) - ++str2; - - if (str1 && str2) - new_str = g_strdup_printf ("%s %s", str1, str2); - else if (str1) - new_str = g_strdup (str1); - else if (str2) - new_str = g_strdup (str2); - else - new_str = g_strdup (""); - - if (out) - fprintf (out, "joining \"%s\" and \"%s\" to \"%s\"\n", str1, str2, new_str); - - e_select_names_model_delete (source, index+1); - - new_dest = e_destination_new (); - e_destination_set_string (new_dest, new_str); - e_select_names_model_replace (source, index, new_dest); - g_free (new_str); - - repos.model = model; - repos.pos = pos; - repos.len = SEPLEN - 1; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); - - if (length > 1) - e_select_names_text_model_delete (model, pos, length-1); - } else { - /* If we are at the end of the last entry (which we must be if we end up in this block), - we can just do nothing. So this else-block is here just to give us a place to - put this comment. */ - } - - goto finished; - } - - if (pos + length > start_pos + text_len) { - /* Uh oh... our changes straddle two objects. */ - - if (pos == start_pos) { /* Delete the whole thing */ - EReposDeleteShift repos; - - e_select_names_model_delete (source, index); - - if (out) - fprintf (out, "deleted all of %d\n", index); - - repos.model = model; - repos.pos = pos; - repos.len = text_len + SEPLEN; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); - - length -= text_len + SEPLEN; - if (length > 0) - e_select_names_text_model_delete (model, pos, length); - - } else { - /* Delete right up to the end, and then call e_select_names_text_model_delete again - to finish the job. */ - gint len1, len2; - - len1 = text_len - (pos - start_pos); - len2 = length - len1; - - if (out) - fprintf (out, "two-stage delete: %d, %d\n", len1, len2); - - - e_select_names_text_model_delete (model, pos, len1); - e_select_names_text_model_delete (model, pos, len2); - } - - goto finished; - } - - /* Our changes are confined to just one entry. */ - if (length > 0) { - const gchar *str; - gchar *new_str; - - offset = pos - start_pos; - - str = e_select_names_model_get_string (source, index); - new_str = str ? g_strdup_printf ("%.*s%s", offset, str, str + offset + length) : NULL; - - if (new_str) { - EReposDeleteShift repos; - EDestination *dest; - - dest = e_destination_new (); - e_destination_set_string (dest, new_str); - e_select_names_model_replace (source, index, dest); - - if (out) - fprintf (out, "new_str: \"%s\"\n", new_str); - - g_free (new_str); - - repos.model = model; - repos.pos = pos; - repos.len = length; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); - - } else { - EReposDeleteShift repos; - - e_select_names_model_delete (source, index); - - if (out) - fprintf (out, "deleted %d\n", index); - - - repos.model = model; - repos.pos = pos; - repos.len = SEPLEN; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); - } - } - - finished: - gtk_signal_handler_unblock (GTK_OBJECT (source), E_SELECT_NAMES_TEXT_MODEL (model)->source_resize_id); - dump_model (E_SELECT_NAMES_TEXT_MODEL (model)); -} - -static gint -e_select_names_text_model_obj_count (ETextModel *model) -{ - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - gint i, count; - - count = i = e_select_names_model_count (source); - while (i > 0) { - const EDestination *dest; - --i; - dest = e_select_names_model_get_destination (source, i); - if (e_destination_get_card (dest) == NULL) - --count; - } - - return count; -} - -static gint -nth_obj_index (ESelectNamesModel *source, gint n) -{ - gint i, N; - - i = 0; - N = e_select_names_model_count (source); - - do { - const EDestination *dest = e_select_names_model_get_destination (source, i); - if (e_destination_get_card (dest)) - --n; - ++i; - } while (n >= 0 && i < N); - - if (i <= N) - --i; - else - i = -1; - - return i; -} - -static const gchar * -e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len) -{ - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - const gchar *txt; - gint i, pos; - - i = nth_obj_index (source, n); - if (i < 0) - return NULL; - - e_select_names_model_name_pos (source, i, &pos, len); - if (pos < 0) - return NULL; - - txt = e_select_names_model_get_textification (source); - return txt + pos; -} - -static void -e_select_names_text_model_activate_obj (ETextModel *model, gint n) -{ - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - EContactEditor *contact_editor; - ECard *card; - gint i; - - i = nth_obj_index (source, n); - g_return_if_fail (i >= 0); - - card = e_select_names_model_get_card (source, i); - g_return_if_fail (card); - - /* present read-only contact editor when someone double clicks from here */ - contact_editor = e_addressbook_show_contact_editor (NULL, card, FALSE, FALSE); - e_contact_editor_raise (contact_editor); -} - - - diff --git a/addressbook/gui/component/select-names/e-select-names-text-model.h b/addressbook/gui/component/select-names/e-select-names-text-model.h deleted file mode 100644 index 7a9e0a7396..0000000000 --- a/addressbook/gui/component/select-names/e-select-names-text-model.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * Jon Trowbridge - * - * Copyright (C) 2000, 2001 Ximian, Inc. - */ - -#ifndef __E_SELECT_NAMES_TEXT_MODEL_H__ -#define __E_SELECT_NAMES_TEXT_MODEL_H__ - -#include -#include -#include -#include -#include "e-select-names-model.h" - -#define E_TYPE_SELECT_NAMES_TEXT_MODEL (e_select_names_text_model_get_type ()) -#define E_SELECT_NAMES_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SELECT_NAMES_TEXT_MODEL, ESelectNamesTextModel)) -#define E_SELECT_NAMES_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SELECT_NAMES_TEXT_MODEL, ESelectNamesTextModelClass)) -#define E_IS_SELECT_NAMES_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SELECT_NAMES_TEXT_MODEL)) -#define E_IS_SELECT_NAMES_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SELECT_NAMES_TEXT_MODEL)) - -typedef struct _ESelectNamesTextModel ESelectNamesTextModel; -typedef struct _ESelectNamesTextModelClass ESelectNamesTextModelClass; - -struct _ESelectNamesTextModel { - ETextModel parent; - - ESelectNamesModel *source; - gint source_changed_id; - gint source_resize_id; -}; - -struct _ESelectNamesTextModelClass { - ETextModelClass parent_class; -}; - -ETextModel *e_select_names_text_model_new (ESelectNamesModel *source); - -/* Standard Gtk function */ -GtkType e_select_names_text_model_get_type (void); - -#endif /* ! __E_SELECT_NAMES_TEXT_MODEL_H__ */ diff --git a/addressbook/gui/component/select-names/e-select-names.c b/addressbook/gui/component/select-names/e-select-names.c deleted file mode 100644 index 9340bbce48..0000000000 --- a/addressbook/gui/component/select-names/e-select-names.c +++ /dev/null @@ -1,801 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-select-names.c - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey - * - * 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "e-select-names.h" -#include -#include "e-select-names-table-model.h" -#include -#include - -static void e_select_names_init (ESelectNames *card); -static void e_select_names_class_init (ESelectNamesClass *klass); -static void e_select_names_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_select_names_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_select_names_destroy (GtkObject *object); - -static GnomeDialogClass *parent_class = NULL; -#define PARENT_TYPE gnome_dialog_get_type() - -/* The arguments we take */ -enum { - ARG_0, -}; - -typedef struct { - char *title; - ETableModel *model; - ESelectNamesModel *source; - ESelectNames *names; - GtkWidget *label; -} ESelectNamesChild; - -GtkType -e_select_names_get_type (void) -{ - static GtkType type = 0; - - if (!type) { - static const GtkTypeInfo info = - { - "ESelectNames", - sizeof (ESelectNames), - sizeof (ESelectNamesClass), - (GtkClassInitFunc) e_select_names_class_init, - (GtkObjectInitFunc) e_select_names_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -static void -e_select_names_class_init (ESelectNamesClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = e_select_names_set_arg; - object_class->get_arg = e_select_names_get_arg; - object_class->destroy = e_select_names_destroy; -} - -#define SPEC " \ - \ - \ - \ - \ - \ -" - -#define SPEC2 " \ - \ - \ - \ - \ - \ -" - -GtkWidget *e_addressbook_create_ebook_table(char *name, char *string1, char *string2, int num1, int num2); - -static void -set_book(EBook *book, EBookStatus status, EAddressbookModel *model) -{ - gtk_object_set(GTK_OBJECT(model), - "book", book, - NULL); - gtk_object_unref(GTK_OBJECT(book)); - gtk_object_unref(GTK_OBJECT(model)); -} - -static void -addressbook_model_set_uri(EAddressbookModel *model, char *uri) -{ - EBook *book; - book = e_book_new(); - gtk_object_ref(GTK_OBJECT(model)); - e_book_load_uri(book, uri, (EBookCallback) set_book, model); -} - -static void -real_add_address_cb (int model_row, - gpointer closure) -{ - ESelectNamesChild *child = closure; - ESelectNames *names = child->names; - ECard *card = e_addressbook_model_get_card(E_ADDRESSBOOK_MODEL(names->model), model_row); - EDestination *dest = e_destination_new (); - - e_destination_set_card (dest, card, 0); - - e_select_names_model_append (child->source, dest); - e_select_names_model_clean (child->source); - - gtk_object_unref(GTK_OBJECT(card)); -} - -static void -real_add_address(ESelectNames *names, ESelectNamesChild *child) -{ - e_table_selected_row_foreach(e_table_scrolled_get_table(names->table), - real_add_address_cb, child); -} - -static void -add_address(ETable *table, int row, int col, GdkEvent *event, ESelectNames *names) -{ - ESelectNamesChild *child; - - child = g_hash_table_lookup(names->children, names->def); - if (child) { - real_add_address(names, child); - } -} - -GtkWidget * -e_addressbook_create_ebook_table(char *name, char *string1, char *string2, int num1, int num2) -{ - ETableModel *adapter; - EAddressbookModel *model; - GtkWidget *table; - char *filename; - char *uri; - char *spec; - - model = e_addressbook_model_new (); - adapter = E_TABLE_MODEL (e_addressbook_table_adapter_new(model)); - - filename = gnome_util_prepend_user_home("evolution/local/Contacts/addressbook.db"); - uri = g_strdup_printf("file://%s", filename); - - addressbook_model_set_uri(model, uri); - - g_free(uri); - g_free(filename); - - gtk_object_set(GTK_OBJECT(model), - "editable", FALSE, - "query", "(contains \"email\" \"\")", - NULL); - - spec = g_strdup_printf(SPEC, E_CARD_SIMPLE_FIELD_NAME_OR_ORG); - table = e_table_scrolled_new (adapter, NULL, spec, NULL); - g_free(spec); - - gtk_object_set_data(GTK_OBJECT(table), "adapter", adapter); - gtk_object_set_data(GTK_OBJECT(table), "model", model); - - return table; -} - -typedef struct { - char *description; - char *display_name; - char *physical_uri; - -} ESelectNamesFolder; - -static void -e_select_names_folder_free(ESelectNamesFolder *e_folder) -{ - g_free(e_folder->description ); - g_free(e_folder->display_name); - g_free(e_folder->physical_uri); - g_free(e_folder); -} - -static void -e_select_names_option_activated(GtkWidget *widget, ESelectNames *e_select_names) -{ - ESelectNamesFolder *e_folder = gtk_object_get_data (GTK_OBJECT (widget), "EsnChoiceFolder"); - gchar *uri; - - uri = g_strdup_printf ("%s/addressbook.db", e_folder->physical_uri); - addressbook_model_set_uri(e_select_names->model, uri); - g_free (uri); -} - -typedef struct { - ESelectNames *names; - GtkWidget *menu; -} NamesAndMenu; - -static void -add_menu_item (gpointer key, - gpointer value, - gpointer user_data) -{ - GtkWidget *menu; - GtkWidget *item; - ESelectNamesFolder *e_folder; - NamesAndMenu *nnm; - ESelectNames *e_select_names; - - nnm = user_data; - e_folder = value; - menu = nnm->menu; - e_select_names = nnm->names; - - item = gtk_menu_item_new_with_label (e_folder->display_name); - gtk_menu_append (GTK_MENU (menu), item); - gtk_object_set_data (GTK_OBJECT (item), "EsnChoiceFolder", e_folder); - - gtk_signal_connect (GTK_OBJECT (item), "activate", - GTK_SIGNAL_FUNC (e_select_names_option_activated), - e_select_names); -} - -static void -update_option_menu(ESelectNames *e_select_names) -{ - GtkWidget *menu; - GtkWidget *option; - - option = glade_xml_get_widget (e_select_names->gui, - "optionmenu-folder"); - if (option) { - NamesAndMenu nnm; - menu = gtk_menu_new (); - - nnm.names = e_select_names; - nnm.menu = menu; - - g_hash_table_foreach (e_select_names->folders, - add_menu_item, - &nnm); - - gtk_widget_show_all (menu); - - gtk_option_menu_set_menu (GTK_OPTION_MENU (option), - menu); - gtk_option_menu_set_history (GTK_OPTION_MENU (option), 0); - gtk_widget_set_sensitive (option, TRUE); - } -} - -static void -new_folder (EvolutionStorageListener *storage_listener, - const char *path, - const GNOME_Evolution_Folder *folder, - ESelectNames *e_select_names) -{ - if (!strcmp(folder->type, "contacts")) { - ESelectNamesFolder *e_folder = g_new(ESelectNamesFolder, 1); - e_folder->description = g_strdup(folder->description ); - e_folder->display_name = g_strdup(folder->display_name); - e_folder->physical_uri = g_strdup(folder->physical_uri); - g_hash_table_insert(e_select_names->folders, - g_strdup(path), e_folder); - update_option_menu(e_select_names); - } -} - -static void -update_folder (EvolutionStorageListener *storage_listener, - const char *path, - const char *display_name, - ESelectNames *e_select_names) -{ - ESelectNamesFolder *e_folder = g_hash_table_lookup(e_select_names->folders, path); - if (e_folder) { - g_free(e_folder->display_name); - e_folder->display_name = g_strdup(e_folder->display_name); - update_option_menu(e_select_names); - } -} - -static void -removed_folder (EvolutionStorageListener *storage_listener, - const char *path, - ESelectNames *e_select_names) -{ - ESelectNamesFolder *e_folder; - char *orig_path; - - if (g_hash_table_lookup_extended(e_select_names->folders, path, (void **) &orig_path, (void **) &e_folder)) { - g_hash_table_remove(e_select_names->folders, path); - e_select_names_folder_free(e_folder); - g_free(orig_path); - update_option_menu(e_select_names); - } -} - -static void -update_query (GtkWidget *button, ESelectNames *e_select_names) -{ - char *category = ""; - char *search = ""; - char *query; - char *q_array[4]; - int i; - if (e_select_names->categories_entry) { - category = gtk_entry_get_text (GTK_ENTRY (e_select_names->categories_entry)); - } - if (e_select_names->search_entry) { - search = gtk_entry_get_text (GTK_ENTRY (e_select_names->search_entry)); - } - i = 0; - q_array[i++] = "(contains \"email\" \"\")"; - if (category && *category) - q_array[i++] = g_strdup_printf ("(is \"category\" \"%s\")", category); - if (search && *search) - q_array[i++] = g_strdup_printf ("(contains \"x-evolution-any-field\" \"%s\")", search); - q_array[i++] = NULL; - if (i > 2) { - char *temp = g_strjoinv (" ", q_array); - query = g_strdup_printf ("(and %s)", temp); - g_free (temp); - } else { - query = g_strdup (q_array[0]); - } - gtk_object_set (GTK_OBJECT (e_select_names->model), - "query", query, - NULL); - for (i = 1; q_array[i]; i++) { - g_free (q_array[i]); - } - g_free (query); -} - -static void -e_select_names_hookup_shell_listener (ESelectNames *e_select_names) -{ - GNOME_Evolution_Storage storage; - GNOME_Evolution_StorageListener listener; - CORBA_Environment ev; - - CORBA_exception_init(&ev); - - storage = (GNOME_Evolution_Storage) (evolution_shell_client_get_local_storage(addressbook_component_get_shell_client())); - e_select_names->listener = evolution_storage_listener_new(); - - listener = evolution_storage_listener_corba_objref(e_select_names->listener); - - /* This should really never happen, but a bug report (ximian #5193) came in w/ a backtrace suggesting that it did in - fact happen to someone, so the best we can do is try to avoid crashing in this case. */ - if (storage == CORBA_OBJECT_NIL) { - GtkWidget *oh_shit; - - oh_shit = gnome_error_dialog (_("Unable to get local storage. This should never happen.")); - gtk_widget_show (oh_shit); - return; - } - - gtk_signal_connect(GTK_OBJECT(e_select_names->listener), "new_folder", - GTK_SIGNAL_FUNC(new_folder), e_select_names); - gtk_signal_connect(GTK_OBJECT(e_select_names->listener), "update_folder", - GTK_SIGNAL_FUNC(update_folder), e_select_names); - gtk_signal_connect(GTK_OBJECT(e_select_names->listener), "removed_folder", - GTK_SIGNAL_FUNC(removed_folder), e_select_names); - - GNOME_Evolution_Storage_addListener(storage, listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_select_names_init: Exception adding listener to " - "remote GNOME_Evolution_Storage interface.\n"); - CORBA_exception_free (&ev); - return; - } - - bonobo_object_release_unref(storage, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("e_select_names_init: Exception unref'ing " - "remote GNOME_Evolution_Storage interface.\n"); - CORBA_exception_free (&ev); - return; - } - - CORBA_exception_free(&ev); -} - -GtkWidget *e_select_names_create_categories (gchar *name, - gchar *string1, gchar *string2, - gint int1, gint int2); - -GtkWidget * -e_select_names_create_categories (gchar *name, - gchar *string1, gchar *string2, - gint int1, gint int2) -{ - ECategoriesMasterList *ecml; - GtkWidget *combo; - - ecml = e_categories_master_list_wombat_new (); - combo = e_categories_master_list_combo_new (ecml); - gtk_object_unref (GTK_OBJECT (ecml)); - - return combo; -} - -static void -e_select_names_init (ESelectNames *e_select_names) -{ - GladeXML *gui; - GtkWidget *widget; - - gui = glade_xml_new (EVOLUTION_GLADEDIR "/select-names.glade", NULL); - e_select_names->gui = gui; - - e_select_names->children = g_hash_table_new(g_str_hash, g_str_equal); - e_select_names->child_count = 0; - e_select_names->def = NULL; - - widget = glade_xml_get_widget(gui, "table-top"); - if (!widget) { - return; - } - gtk_widget_ref(widget); - gtk_widget_unparent(widget); - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(e_select_names)->vbox), widget, TRUE, TRUE, 0); - gtk_widget_unref(widget); - - gnome_dialog_append_buttons(GNOME_DIALOG(e_select_names), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - - gtk_window_set_policy(GTK_WINDOW(e_select_names), FALSE, TRUE, FALSE); - - e_select_names->table = E_TABLE_SCROLLED(glade_xml_get_widget(gui, "table-source")); - e_select_names->model = gtk_object_get_data(GTK_OBJECT(e_select_names->table), "model"); - e_select_names->adapter = gtk_object_get_data(GTK_OBJECT(e_select_names->table), "adapter"); - - e_select_names->categories = glade_xml_get_widget (gui, "custom-categories"); - if (e_select_names->categories && !GTK_IS_COMBO (e_select_names->categories)) - e_select_names->categories = NULL; - if (e_select_names->categories) { - e_select_names->categories_entry = GTK_COMBO (e_select_names->categories)->entry; - } else - e_select_names->categories_entry = NULL; - e_select_names->search_entry = glade_xml_get_widget (gui, "entry-find"); - if (e_select_names->search_entry && !GTK_IS_ENTRY (e_select_names->search_entry)) - e_select_names->search_entry = NULL; - if (e_select_names->search_entry) - gtk_signal_connect(GTK_OBJECT(e_select_names->search_entry), "activate", - GTK_SIGNAL_FUNC(update_query), e_select_names); - if (e_select_names->categories_entry) - gtk_signal_connect(GTK_OBJECT(e_select_names->categories_entry), "changed", - GTK_SIGNAL_FUNC(update_query), e_select_names); - - e_select_names->folders = g_hash_table_new(g_str_hash, g_str_equal); - - e_select_names_hookup_shell_listener (e_select_names); - - gtk_signal_connect (GTK_OBJECT (e_table_scrolled_get_table (e_select_names->table)), "double_click", - GTK_SIGNAL_FUNC (add_address), e_select_names); -} - -static void e_select_names_child_free(char *key, ESelectNamesChild *child, ESelectNames *e_select_names) -{ - g_free(child->title); - gtk_object_unref(GTK_OBJECT(child->model)); - gtk_object_unref(GTK_OBJECT(child->source)); - g_free(key); -} - -static void -e_select_names_destroy (GtkObject *object) { - ESelectNames *e_select_names = E_SELECT_NAMES(object); - - gtk_signal_disconnect_by_data(GTK_OBJECT(e_select_names->listener), e_select_names); - gtk_object_unref(GTK_OBJECT(e_select_names->listener)); - - gtk_object_unref(GTK_OBJECT(e_select_names->gui)); - g_hash_table_foreach(e_select_names->children, (GHFunc) e_select_names_child_free, e_select_names); - g_hash_table_destroy(e_select_names->children); - - g_free(e_select_names->def); -} - -GtkWidget* -e_select_names_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_select_names_get_type ())); - return widget; -} - -static void -e_select_names_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ESelectNames *editor; - - editor = E_SELECT_NAMES (o); - - switch (arg_id){ - default: - return; - } -} - -static void -e_select_names_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ESelectNames *e_select_names; - - e_select_names = E_SELECT_NAMES (object); - - switch (arg_id) { - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -button_clicked(GtkWidget *button, ESelectNamesChild *child) -{ - real_add_address(child->names, child); -} - -static void -remove_address(ETable *table, int row, int col, GdkEvent *event, ESelectNamesChild *child) -{ - e_select_names_model_delete (child->source, row); -} - -struct _RightClickData { - ETable *table; - ESelectNamesChild *child; -}; -typedef struct _RightClickData RightClickData; - -static GSList *selected_rows = NULL; - -static void -etable_selection_foreach_cb (int row, void *data) -{ - /* Build a list of rows in reverse order, then remove them, - necessary because otherwise it'll start trying to delete - rows out of index in ETableModel */ - selected_rows = g_slist_prepend (selected_rows, - GINT_TO_POINTER (row)); -} - -static void -selected_rows_foreach_cb (void *row, void *data) -{ - ESelectNamesChild *child = data; - - e_select_names_model_delete (child->source, GPOINTER_TO_INT (row)); -} - -static void -remove_cb (GtkWidget *widget, void *data) -{ - RightClickData *rcdata = (RightClickData *)data; - - /* Build a list of selected rows */ - e_table_selected_row_foreach (rcdata->table, - etable_selection_foreach_cb, - rcdata->child); - - /* Now process the list we made, removing each selected row */ - g_slist_foreach (selected_rows, - (GFunc)selected_rows_foreach_cb, - rcdata->child); - - /* Free everything we've created */ - g_free (rcdata); - g_slist_free (selected_rows); - selected_rows = NULL; -} - -static void -section_right_click_cb (ETable *table, gint row, gint col, GdkEvent *event, ESelectNamesChild *child) -{ - EPopupMenu right_click_menu[] = { - { N_("Remove"), NULL, - GTK_SIGNAL_FUNC (remove_cb), NULL, 0 }, - { NULL, NULL, NULL, 0 } - }; - - RightClickData *rcdata = g_new0 (RightClickData, 1); - rcdata->table = table; - rcdata->child = child; - - e_popup_menu_run (right_click_menu, event, 0, 0, - rcdata); -} - -void -e_select_names_add_section(ESelectNames *e_select_names, char *name, char *id, ESelectNamesModel *source) -{ - ESelectNamesChild *child; - GtkWidget *button; - GtkWidget *alignment; - GtkWidget *label; - GtkTable *table; - char *label_text; - - ETableModel *model; - GtkWidget *etable; - - if (g_hash_table_lookup(e_select_names->children, id)) { - return; - } - - table = GTK_TABLE(glade_xml_get_widget (e_select_names->gui, "table-recipients")); - - child = g_new(ESelectNamesChild, 1); - - child->names = e_select_names; - child->title = g_strdup(_(name)); - - e_select_names->child_count++; - - alignment = gtk_alignment_new(0, 0, 1, 0); - - button = gtk_button_new (); - - label_text = g_strconcat (child->title, " ->", NULL); - label = gtk_label_new (label_text); - g_free (label_text); - gtk_container_add (GTK_CONTAINER (button), label); - child->label = label; - - gtk_container_add(GTK_CONTAINER(alignment), button); - gtk_widget_show_all(alignment); - gtk_signal_connect(GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(button_clicked), child); - gtk_table_attach(table, alignment, - 0, 1, - e_select_names->child_count, - e_select_names->child_count + 1, - GTK_FILL, GTK_FILL, - 0, 0); - - model = e_select_names_table_model_new(source); - etable = e_table_scrolled_new (model, NULL, SPEC2, NULL); - - gtk_signal_connect(GTK_OBJECT(e_table_scrolled_get_table(E_TABLE_SCROLLED(etable))), "right_click", - GTK_SIGNAL_FUNC(section_right_click_cb), child); - gtk_signal_connect(GTK_OBJECT(e_table_scrolled_get_table(E_TABLE_SCROLLED(etable))), "double_click", - GTK_SIGNAL_FUNC(remove_address), child); - - child->model = model; - child->source = source; - gtk_object_ref(GTK_OBJECT(child->model)); - gtk_object_ref(GTK_OBJECT(child->source)); - - gtk_widget_show(etable); - - gtk_table_attach(table, etable, - 1, 2, - e_select_names->child_count, - e_select_names->child_count + 1, - GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, - 0, 0); - - g_hash_table_insert(e_select_names->children, g_strdup(id), child); -} - -static void * -card_copy(const void *value, void *closure) -{ - gtk_object_ref(GTK_OBJECT(value)); - return (void *)value; -} - -static void -card_free(void *value, void *closure) -{ - gtk_object_unref(GTK_OBJECT(value)); -} - -EList * -e_select_names_get_section(ESelectNames *e_select_names, char *id) -{ - ESelectNamesChild *child; - int i; - int rows; - EList *list; - - child = g_hash_table_lookup(e_select_names->children, id); - if (!child) - return NULL; - rows = e_table_model_row_count(child->model); - - list = e_list_new(card_copy, card_free, NULL); - for (i = 0; i < rows; i++) { - ECard *card = e_cardlist_model_get(E_CARDLIST_MODEL(child->model), i); - e_list_append(list, card); - gtk_object_unref(GTK_OBJECT(card)); - } - return list; -} - -ESelectNamesModel * -e_select_names_get_source(ESelectNames *e_select_names, - char *id) -{ - ESelectNamesChild *child = g_hash_table_lookup(e_select_names->children, id); - if (child) { - if (child->source) - gtk_object_ref(GTK_OBJECT(child->source)); - return child->source; - } else - return NULL; -} - -void -e_select_names_set_default (ESelectNames *e_select_names, - const char *id) -{ - ESelectNamesChild *child; - - if (e_select_names->def) { - child = g_hash_table_lookup(e_select_names->children, e_select_names->def); - if (child) - gtk_widget_restore_default_style(child->label); - } - - g_free(e_select_names->def); - e_select_names->def = g_strdup(id); - - if (e_select_names->def) { - child = g_hash_table_lookup(e_select_names->children, e_select_names->def); - if (child) { - EFont *efont; - GdkFont *gdkfont; - GtkStyle *style, *oldstyle; - - oldstyle = gtk_widget_get_style(child->label); - style = gtk_style_copy(oldstyle); - - efont = e_font_from_gdk_font(style->font); - gdkfont = e_font_to_gdk_font(efont, E_FONT_BOLD); - e_font_unref(efont); - - gdk_font_ref(gdkfont); - gdk_font_unref(style->font); - style->font = gdkfont; - - gtk_widget_set_style(child->label, style); - - gtk_style_unref(oldstyle); - } - } -} diff --git a/addressbook/gui/component/select-names/e-select-names.h b/addressbook/gui/component/select-names/e-select-names.h deleted file mode 100644 index 918dbc5794..0000000000 --- a/addressbook/gui/component/select-names/e-select-names.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-select-names.h - * Copyright (C) 2000 Ximian, Inc. - * Author: Chris Lahey - * - * 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_SELECT_NAMES_H__ -#define __E_SELECT_NAMES_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "e-select-names-model.h" -#include "e-util/e-list.h" -#include "shell/evolution-storage-listener.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ESelectNames - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_SELECT_NAMES_TYPE (e_select_names_get_type ()) -#define E_SELECT_NAMES(obj) (GTK_CHECK_CAST ((obj), E_SELECT_NAMES_TYPE, ESelectNames)) -#define E_SELECT_NAMES_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_SELECT_NAMES_TYPE, ESelectNamesClass)) -#define E_IS_SELECT_NAMES(obj) (GTK_CHECK_TYPE ((obj), E_SELECT_NAMES_TYPE)) -#define E_IS_SELECT_NAMES_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_SELECT_NAMES_TYPE)) - -typedef struct _ESelectNames ESelectNames; -typedef struct _ESelectNamesClass ESelectNamesClass; - -struct _ESelectNames -{ - GnomeDialog parent; - - /* item specific fields */ - GladeXML *gui; - - GHashTable *children; /* Of type char * to ESelectNamesChild */ - int child_count; - ETableScrolled *table; - ETableModel *adapter; - EAddressbookModel *model; - GtkWidget *categories; - GtkWidget *categories_entry; - GtkWidget *search_entry; - EvolutionStorageListener *listener; - GHashTable *folders; - char *def; -}; - -struct _ESelectNamesClass -{ - GnomeDialogClass parent_class; -}; - - -GtkWidget *e_select_names_new (void); -GtkType e_select_names_get_type (void); - -void e_select_names_add_section (ESelectNames *e_select_names, - char *name, - char *id, - ESelectNamesModel *source); -ESelectNamesModel *e_select_names_get_source (ESelectNames *e_select_names, - char *id); -void e_select_names_set_default (ESelectNames *e_select_names, - const char *id); -/* Returns a ref counted list of addresses. */ -EList *e_select_names_get_section (ESelectNames *e_select_names, - char *id); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_SELECT_NAMES_H__ */ diff --git a/addressbook/gui/component/select-names/recipient.glade b/addressbook/gui/component/select-names/recipient.glade deleted file mode 100644 index b60972d094..0000000000 --- a/addressbook/gui/component/select-names/recipient.glade +++ /dev/null @@ -1,61 +0,0 @@ - - - - - Recipient - recipient - - src - pixmaps - C - True - True - True - False - False - False - True - - - - GtkWindow - window1 - False - window1 - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - True - False - - - GtkHBox - hbox-top - False - 4 - - - GtkAlignment - alignment1 - 1.08033e-07 - 0 - 1 - 0 - - 0 - False - True - - - - GtkButton - text-button - True - - - - - - - diff --git a/addressbook/gui/component/select-names/select-names.glade b/addressbook/gui/component/select-names/select-names.glade deleted file mode 100644 index e15a70b4ad..0000000000 --- a/addressbook/gui/component/select-names/select-names.glade +++ /dev/null @@ -1,320 +0,0 @@ - - - - - Select-names - select-names - - src - pixmaps - C - True - True - False - False - False - - - - GnomeDialog - dialog-top - False - Select Names - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - True - False - False - False - - - GtkVBox - GnomeDialog:vbox - dialog-vbox1 - False - 8 - - 4 - True - True - - - - GtkHButtonBox - GnomeDialog:action_area - dialog-action_area1 - GTK_BUTTONBOX_END - 8 - 85 - 27 - 7 - 0 - - 0 - False - True - GTK_PACK_END - - - - GtkButton - button1 - True - True - GNOME_STOCK_BUTTON_OK - - - - GtkButton - button3 - True - True - GNOME_STOCK_BUTTON_CANCEL - - - - - GtkTable - table-top - 7 - 2 - False - 6 - 6 - - 0 - True - True - - - - Custom - table-source - e_addressbook_create_ebook_table - 0 - 0 - Sat, 10 Jun 2000 22:02:57 GMT - - 0 - 1 - 6 - 7 - 0 - 0 - True - True - False - False - True - True - - - - - GtkTable - table-recipients - 1 - 2 - False - 4 - 4 - - 1 - 2 - 6 - 7 - 0 - 0 - True - False - False - False - True - True - - - - GtkAccelLabel - accellabel2 - - GTK_JUSTIFY_CENTER - False - 0 - 0.5 - 0 - 0 - - 1 - 2 - 0 - 1 - 0 - 0 - True - False - False - False - True - True - - - - - - GtkOptionMenu - optionmenu-folder - True - True - - 0 - - 0 - 1 - 1 - 2 - 0 - 0 - False - False - False - False - True - False - - - - - GtkLabel - label3 - - GTK_JUSTIFY_CENTER - False - 0 - 0.5 - 0 - 0 - entry-find - - 0 - 1 - 0 - 1 - 0 - 0 - False - False - False - False - True - False - - - - - GtkLabel - label2 - - GTK_JUSTIFY_CENTER - False - 0 - 0.5 - 0 - 0 - custom-categories - - 0 - 1 - 2 - 3 - 0 - 0 - False - False - False - False - True - True - - - - - GtkLabel - label1 - - GTK_JUSTIFY_CENTER - False - 0 - 0.5 - 0 - 0 - entry-find - - 0 - 1 - 4 - 5 - 0 - 0 - False - False - False - False - True - True - - - - - GtkEntry - entry-find - True - True - True - 0 - - - 0 - 1 - 5 - 6 - 0 - 0 - True - False - False - False - True - True - - - - - Custom - custom-categories - True - e_select_names_create_categories - 0 - 0 - Wed, 27 Jun 2001 01:47:01 GMT - - 0 - 1 - 3 - 4 - 0 - 0 - True - False - False - False - True - True - - - - - - - -- cgit v1.2.3