diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-07-17 12:58:55 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-07-17 12:58:55 +0800 |
commit | 6bb3bbdfff7383749d19a57cfe3162cd67aabf9b (patch) | |
tree | 45ed719c87fd8e1fd8f3e304d0bf187bfba3a7d3 /addressbook | |
parent | ca133393551eb77aeff1af61e04541b71be4a28a (diff) | |
download | gsoc2013-evolution-6bb3bbdfff7383749d19a57cfe3162cd67aabf9b.tar.gz gsoc2013-evolution-6bb3bbdfff7383749d19a57cfe3162cd67aabf9b.tar.zst gsoc2013-evolution-6bb3bbdfff7383749d19a57cfe3162cd67aabf9b.zip |
Added addSectionWithLimit to the SelectNames interface.
2001-07-16 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/Evolution-Addressbook-SelectNames.idl:
Added addSectionWithLimit to the SelectNames interface.
* gui/component/select-names/e-select-names-bonobo.c
(impl_SelectNames_add_section_with_limit): Added. Implements
addSectionWithLimit.
(e_select_names_bonobo_construct): Set up as a BonoboEventSource.
(init): Listen for "changed" signals from our manager.
(manager_changed_cb): Notify our listeners if we get a changed
signal from our manager.
* gui/component/select-names/e-select-names-manager.c
(e_select_names_manager_class_init): Added a "changed" signal".
(section_copy): Propogate the signal connection.
(section_free): Disconnect the changed handler.
(e_select_names_manager_add_section_with_limit): Connect to the
new section's model, listening for changes.
(e_select_names_manager_activate_dialog): Connect to the "working
copy" model, listening for changes.
(e_select_names_manager_add_section_with_limit): Added.
(e_select_names_manager_add_section): Changed to just be a special
case of e_select_names_manager_add_section_with_limit.
* gui/component/select-names/e-select-names-model.c
(e_select_names_model_set_limit): Added. Allows a max number of
names allowed in the model.
(e_select_names_model_get_limit): Added. Returns the limit.
(e_select_names_model_at_limit): Added. Returns TRUE if the
model is "full".
(e_select_names_model_insert): Check that we aren't at the
limit before inserting. Silently return if we are.
(e_select_names_model_append): Check that we aren't at the
limit before appending. Silently return if we are.
svn path=/trunk/; revision=11150
Diffstat (limited to 'addressbook')
9 files changed, 254 insertions, 37 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index a4cc6a6d70..e5c521ea54 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,39 @@ +2001-07-16 Jon Trowbridge <trow@ximian.com> + + * gui/component/select-names/Evolution-Addressbook-SelectNames.idl: + Added addSectionWithLimit to the SelectNames interface. + + * gui/component/select-names/e-select-names-bonobo.c + (impl_SelectNames_add_section_with_limit): Added. Implements + addSectionWithLimit. + (e_select_names_bonobo_construct): Set up as a BonoboEventSource. + (init): Listen for "changed" signals from our manager. + (manager_changed_cb): Notify our listeners if we get a changed + signal from our manager. + + * gui/component/select-names/e-select-names-manager.c + (e_select_names_manager_class_init): Added a "changed" signal". + (section_copy): Propogate the signal connection. + (section_free): Disconnect the changed handler. + (e_select_names_manager_add_section_with_limit): Connect to the + new section's model, listening for changes. + (e_select_names_manager_activate_dialog): Connect to the "working + copy" model, listening for changes. + (e_select_names_manager_add_section_with_limit): Added. + (e_select_names_manager_add_section): Changed to just be a special + case of e_select_names_manager_add_section_with_limit. + + * gui/component/select-names/e-select-names-model.c + (e_select_names_model_set_limit): Added. Allows a max number of + names allowed in the model. + (e_select_names_model_get_limit): Added. Returns the limit. + (e_select_names_model_at_limit): Added. Returns TRUE if the + model is "full". + (e_select_names_model_insert): Check that we aren't at the + limit before inserting. Silently return if we are. + (e_select_names_model_append): Check that we aren't at the + limit before appending. Silently return if we are. + 2001-07-16 Chris Toshok <toshok@ximian.com> [ Fix bug #4705 - LDAP storage gets saved with corrupted binddn] diff --git a/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl b/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl index 35586b611e..244799deb2 100644 --- a/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl +++ b/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl @@ -27,6 +27,8 @@ module Addressbook { 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); @@ -34,6 +36,7 @@ module Addressbook { void activateDialog (in string section_id); }; + }; }; }; diff --git a/addressbook/gui/component/select-names/Makefile.am b/addressbook/gui/component/select-names/Makefile.am index 8c308d937a..5c7b37794b 100644 --- a/addressbook/gui/component/select-names/Makefile.am +++ b/addressbook/gui/component/select-names/Makefile.am @@ -46,25 +46,25 @@ INCLUDES = \ 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 \ +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 diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.c b/addressbook/gui/component/select-names/e-select-names-bonobo.c index 7c1b9aa3c1..428826f7fe 100644 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.c +++ b/addressbook/gui/component/select-names/e-select-names-bonobo.c @@ -29,6 +29,7 @@ #include <bonobo/bonobo-property-bag.h> #include <bonobo/bonobo-control.h> +#include <bonobo/bonobo-event-source.h> #include <gal/util/e-util.h> #include <gal/e-text/e-entry.h> @@ -47,6 +48,7 @@ static BonoboObjectClass *parent_class = NULL; struct _ESelectNamesBonoboPrivate { ESelectNamesManager *manager; + BonoboEventSource *event_source; }; enum _EntryPropertyID { @@ -163,6 +165,24 @@ impl_SelectNames_add_section (PortableServer_Servant servant, } 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")); @@ -263,9 +283,10 @@ corba_class_init () base_epv->default_POA = NULL; epv = g_new0 (POA_GNOME_Evolution_Addressbook_SelectNames__epv, 1); - epv->addSection = impl_SelectNames_add_section; - epv->getEntryBySection = impl_SelectNames_get_entry_for_section; - epv->activateDialog = impl_SelectNames_activate_dialog; + 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 (); @@ -286,6 +307,24 @@ class_init (ESelectNamesBonoboClass *klass) } 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; @@ -293,6 +332,12 @@ init (ESelectNamesBonobo *select_names) 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; } @@ -306,6 +351,10 @@ e_select_names_bonobo_construct (ESelectNamesBonobo *select_names, 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 * diff --git a/addressbook/gui/component/select-names/e-select-names-bonobo.h b/addressbook/gui/component/select-names/e-select-names-bonobo.h index 8827f61f01..49043e1756 100644 --- a/addressbook/gui/component/select-names/e-select-names-bonobo.h +++ b/addressbook/gui/component/select-names/e-select-names-bonobo.h @@ -41,7 +41,7 @@ extern "C" { #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 ((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; diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c index d0472448c9..ead51d8dca 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -28,11 +28,20 @@ enum { 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 { @@ -105,6 +114,17 @@ e_select_names_manager_class_init (ESelectNamesManagerClass *klass) 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); } /* @@ -161,11 +181,19 @@ 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; @@ -175,6 +203,9 @@ 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) @@ -216,17 +247,56 @@ e_select_names_manager_init (ESelectNamesManager *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); } @@ -404,6 +474,10 @@ e_select_names_manager_activate_dialog (ESelectNamesManager *manager, 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); diff --git a/addressbook/gui/component/select-names/e-select-names-manager.h b/addressbook/gui/component/select-names/e-select-names-manager.h index ba7ed58d08..61779fb56a 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.h +++ b/addressbook/gui/component/select-names/e-select-names-manager.h @@ -35,26 +35,32 @@ struct _ESelectNamesManager { 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); -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); +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); +EList *e_select_names_manager_get_cards (ESelectNamesManager *manager, + const char *id); #endif /* Standard Gtk function */ -GtkType e_select_names_manager_get_type (void); +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 index 3fd5249a26..f102421f0e 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.c +++ b/addressbook/gui/component/select-names/e-select-names-model.c @@ -56,6 +56,8 @@ struct _ESelectNamesModelPrivate { GList *data; /* of EDestination */ gchar *text; gchar *addr_text; + + gint limit; }; @@ -148,6 +150,8 @@ static void e_select_names_model_init (ESelectNamesModel *model) { model->priv = g_new0 (struct _ESelectNamesModelPrivate, 1); + + model->priv->limit = -1; } static void @@ -239,6 +243,8 @@ e_select_names_model_duplicate (ESelectNamesModel *old) model->priv->data = g_list_append (model->priv->data, dup); } + model->priv->limit = old->priv->limit; + return model; } @@ -318,6 +324,33 @@ e_select_names_model_count (ESelectNamesModel *model) 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) { @@ -419,6 +452,12 @@ e_select_names_model_insert (ESelectNamesModel *model, gint index, EDestination 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)); @@ -433,6 +472,12 @@ 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)); diff --git a/addressbook/gui/component/select-names/e-select-names-model.h b/addressbook/gui/component/select-names/e-select-names-model.h index 989a829223..330f1ddd82 100644 --- a/addressbook/gui/component/select-names/e-select-names-model.h +++ b/addressbook/gui/component/select-names/e-select-names-model.h @@ -50,6 +50,10 @@ 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, |