From 4a74b1ff15ca5cbc175c8fb98839960f1af494fb Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Fri, 8 Dec 2000 00:00:15 +0000 Subject: New and improved display, Bug fixes memory leaks removed Preferences and probably more that I can't remember. svn path=/trunk/; revision=6858 --- executive-summary/component/Makefile.am | 8 + executive-summary/component/e-summary-callbacks.c | 212 +++++++++++++++++ executive-summary/component/e-summary-callbacks.h | 10 + executive-summary/component/e-summary-factory.c | 50 +--- executive-summary/component/e-summary-prefs.c | 97 ++++++++ executive-summary/component/e-summary-prefs.h | 39 ++++ executive-summary/component/e-summary-url.c | 125 +++++++++- executive-summary/component/e-summary.c | 259 ++++++++++++++------- executive-summary/component/e-summary.h | 23 +- .../component/executive-summary-config.glade | 169 ++++++++++++++ executive-summary/component/main.c | 6 +- 11 files changed, 856 insertions(+), 142 deletions(-) create mode 100644 executive-summary/component/e-summary-callbacks.c create mode 100644 executive-summary/component/e-summary-callbacks.h create mode 100644 executive-summary/component/e-summary-prefs.c create mode 100644 executive-summary/component/e-summary-prefs.h create mode 100644 executive-summary/component/executive-summary-config.glade (limited to 'executive-summary/component') diff --git a/executive-summary/component/Makefile.am b/executive-summary/component/Makefile.am index ba77a68238..7e7bb2bc8b 100644 --- a/executive-summary/component/Makefile.am +++ b/executive-summary/component/Makefile.am @@ -48,8 +48,12 @@ evolution_executive_summary_SOURCES = \ component-factory.h \ e-summary.c \ e-summary.h \ + e-summary-callbacks.c \ + e-summary-callbacks.h \ e-summary-factory.c \ e-summary-factory.h \ + e-summary-prefs.c \ + e-summary-prefs.h \ e-summary-url.c \ e-summary-url.h \ e-summary-util.c \ @@ -66,3 +70,7 @@ evolution_executive_summary_LDADD = \ $(GTKHTML_LIBS) \ $(UNICODE_LIBS) +gladedir = $(datadir)/evolution/glade +glade_DATA = executive-summary-config.glade + +EXTRA_DIST = $(glade_DATA) diff --git a/executive-summary/component/e-summary-callbacks.c b/executive-summary/component/e-summary-callbacks.c new file mode 100644 index 0000000000..03ea56805c --- /dev/null +++ b/executive-summary/component/e-summary-callbacks.c @@ -0,0 +1,212 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-summary-callbacks.c + * + * Author: + * Iain Holmes + * + * Copyright (C) 2000 Helix Code, 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +#include "e-summary.h" + +#include "Composer.h" + +#define COMPOSER_IID "OAFIID:GNOME_Evolution_Mail_Composer" +typedef struct _PropertyData { + ESummary *esummary; + GnomePropertyBox *box; + GladeXML *xml; +} PropertyData; + +void +embed_service (GtkWidget *widget, + ESummary *esummary) +{ + char *required_interfaces[2] = {"IDL:GNOME/Evolution:Summary:ComponentFactory:1.0", + NULL}; + char *obj_id; + + obj_id = bonobo_selector_select_id ("Select a service", + (const char **) required_interfaces); + if (obj_id == NULL) + return; + + e_summary_embed_service_from_id (esummary, obj_id); +} + +void +new_mail (GtkWidget *widget, + ESummary *esummary) +{ + GNOME_Evolution_Composer_RecipientList *to, *cc, *bcc; + CORBA_char *subject; + CORBA_Object composer; + CORBA_Environment ev; + + CORBA_exception_init (&ev); + composer = oaf_activate_from_id ((char *)COMPOSER_IID, 0, NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION || composer == NULL) { + CORBA_exception_free (&ev); + g_warning ("Unable to start composer component!"); + return; + } + CORBA_exception_free (&ev); + + to = GNOME_Evolution_Composer_RecipientList__alloc (); + to->_length = 0; + to->_maximum = 0; + to->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (0); + + cc = GNOME_Evolution_Composer_RecipientList__alloc (); + cc->_length = 0; + cc->_maximum = 0; + cc->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (0); + + bcc = GNOME_Evolution_Composer_RecipientList__alloc (); + bcc->_length = 0; + bcc->_maximum = 0; + bcc->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (0); + + subject = CORBA_string_dup (""); + + CORBA_exception_init (&ev); + GNOME_Evolution_Composer_setHeaders (composer, to, cc, + bcc, subject, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); + CORBA_free (to); + CORBA_free (cc); + CORBA_free (bcc); + CORBA_free (subject); + + g_warning ("Error setting headers!"); + return; + } + + CORBA_free (to); + CORBA_free (cc); + CORBA_free (bcc); + CORBA_free (subject); + + GNOME_Evolution_Composer_show (composer, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); + g_warning ("Error showing composer"); + return; + } + + CORBA_exception_free (&ev); + return; +} + +static void +destroy_prefs_cb (GtkObject *object, + PropertyData *data) +{ + gtk_object_unref (data->xml); + g_free (data); +} + +static void +html_page_changed_cb (GtkEntry *entry, + PropertyData *data) +{ + ESummaryPrefs *prefs; + + /* Change the tmp prefs so that we can restore if the user cancels */ + prefs = data->esummary->tmp_prefs; + + if (prefs->page) + g_free (prefs->page); + + prefs->page = g_strdup (gtk_entry_get_text (entry)); + + gnome_property_box_changed (data->box); +} + +static void +apply_prefs_cb (GnomePropertyBox *property_box, + int page, + ESummary *esummary) +{ + g_print ("Applying\n"); + + if (page != -1) + return; + + esummary->prefs = e_summary_prefs_copy (esummary->tmp_prefs); + + e_summary_reconfigure (esummary); +} + +void +configure_summary (GtkWidget *widget, + ESummary *esummary) +{ + static GtkWidget *prefs = NULL; + PropertyData *data; + GtkWidget *html_page; + + if (prefs != NULL) { + g_assert (GTK_WIDGET_REALIZED (prefs)); + gdk_window_show (prefs->window); + gdk_window_raise (prefs->window); + return; + } + + data = g_new (PropertyData, 1); + data->esummary = esummary; + + if (esummary->tmp_prefs != NULL) { + e_summary_prefs_free (esummary->tmp_prefs); + } + + esummary->tmp_prefs = e_summary_prefs_copy (esummary->prefs); + + data->xml = glade_xml_new (EVOLUTION_GLADEDIR + "/executive-summary-config.glade", NULL); + prefs = glade_xml_get_widget (data->xml, "summaryprefs"); + data->box = prefs; + html_page = glade_xml_get_widget (data->xml, "htmlpage"); + + if (esummary->prefs->page != NULL) + gtk_entry_set_text (GTK_ENTRY (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (html_page))), esummary->prefs->page); + + gtk_signal_connect (GTK_OBJECT (gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (html_page))), + "changed", GTK_SIGNAL_FUNC (html_page_changed_cb), + data); + + gtk_signal_connect (GTK_OBJECT (prefs), "apply", + GTK_SIGNAL_FUNC (apply_prefs_cb), esummary); + + gtk_signal_connect (GTK_OBJECT (prefs), "destroy", + GTK_SIGNAL_FUNC (destroy_prefs_cb), data); + gtk_signal_connect (GTK_OBJECT (prefs), "destroy", + GTK_SIGNAL_FUNC (gtk_widget_destroyed), &prefs); +} + diff --git a/executive-summary/component/e-summary-callbacks.h b/executive-summary/component/e-summary-callbacks.h new file mode 100644 index 0000000000..3d42adca26 --- /dev/null +++ b/executive-summary/component/e-summary-callbacks.h @@ -0,0 +1,10 @@ +#ifndef __E_SUMMARY_CALLBACKS_H__ +#define __E_SUMMARY_CALLBACKS_H__ + +void embed_service (GtkWidget *widget, + ESummary *esummary); +void new_mail (GtkWidget *widget, + ESummary *esummary); +void configure_summary (GtkWidget *widget, + ESummary *esummary); +#endif diff --git a/executive-summary/component/e-summary-factory.c b/executive-summary/component/e-summary-factory.c index 3f3a3bba89..48c35f9035 100644 --- a/executive-summary/component/e-summary-factory.c +++ b/executive-summary/component/e-summary-factory.c @@ -40,6 +40,8 @@ #include "e-summary-factory.h" #include "e-summary.h" +#include "e-summary-util.h" +#include "e-summary-callbacks.h" #include "Evolution.h" #include @@ -48,11 +50,10 @@ static GList *control_list = NULL; -void embed_service (GtkWidget *widget, - ESummary *esummary); - BonoboUIVerb verbs[] = { BONOBO_UI_UNSAFE_VERB ("AddService", embed_service), + BONOBO_UI_UNSAFE_VERB ("NewMail", new_mail), + BONOBO_UI_UNSAFE_VERB ("ESummarySettings", configure_summary), BONOBO_UI_VERB_END }; @@ -64,7 +65,11 @@ set_pixmap (BonoboUIComponent *component, char *path; GdkPixbuf *pixbuf; +#if 0 path = g_concat_dir_and_file (EVOLUTION_DATADIR "/images/evolution/buttons", icon); +#else + path = e_pixmap_file (icon); +#endif pixbuf = gdk_pixbuf_new_from_file (path); g_return_if_fail (pixbuf != NULL); @@ -78,6 +83,7 @@ static void update_pixmaps (BonoboUIComponent *component) { set_pixmap (component, "/Toolbar/AddService", "add-service.png"); + set_pixmap (component, "/Toolbar/NewMail", "compose-message.png"); } static void @@ -168,44 +174,6 @@ control_destroy_cb (BonoboControl *control, gtk_object_destroy (GTK_OBJECT (esummary)); } -/* A ********very******** - temporary function to embed something -*/ -void -embed_service (GtkWidget *widget, - ESummary *esummary) -{ - char *required_interfaces[2] = {"IDL:GNOME/Evolution:Summary:ComponentFactory:1.0", - NULL}; - char *obj_id; - - obj_id = bonobo_selector_select_id ("Select a service", - (const char **) required_interfaces); - if (obj_id == NULL) - return; - - e_summary_factory_embed_service_from_id (esummary, obj_id); -} - -ESummaryWindow * -e_summary_factory_embed_service_from_id (ESummary *esummary, - const char *obj_id) -{ - GNOME_Evolution_Summary_Component component; - ExecutiveSummaryComponentFactoryClient *client; - ESummaryWindow *window; - CORBA_Environment ev; - - client = executive_summary_component_factory_client_new (obj_id); - - component = executive_summary_component_factory_client_create_view (client); - - window = e_summary_add_service (esummary, component, obj_id); - e_summary_rebuild_page (esummary); - - return window; -} - BonoboControl * e_summary_factory_new_control (const char *uri, const GNOME_Evolution_Shell shell) diff --git a/executive-summary/component/e-summary-prefs.c b/executive-summary/component/e-summary-prefs.c new file mode 100644 index 0000000000..ffefdcd583 --- /dev/null +++ b/executive-summary/component/e-summary-prefs.c @@ -0,0 +1,97 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-summary-prefs.c: Preference handling routines. + * + * Authors: Iain Holmes + * + * Copyright (C) 2000 Helix Code, 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include "e-summary-prefs.h" +#include "e-summary.h" + +void +e_summary_prefs_free (ESummaryPrefs *prefs) +{ + g_return_if_fail (prefs != NULL); + + g_free (prefs->page); + g_free (prefs); +} + +ESummaryPrefs * +e_summary_prefs_new (void) +{ + ESummaryPrefs *prefs; + + prefs = g_new0 (ESummaryPrefs, 1); + return prefs; +} + +ESummaryPrefs * +e_summary_prefs_copy (ESummaryPrefs *prefs) +{ + ESummaryPrefs *copy; + + g_return_val_if_fail (prefs != NULL, NULL); + + copy = e_summary_prefs_new (); + copy->page = g_strdup (prefs->page); + + return copy; +} + +ESummaryPrefs * +e_summary_prefs_load (const char *path) +{ + ESummaryPrefs *prefs; + char *item; + + g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (*path != '\0', NULL); + + prefs = e_summary_prefs_new (); + + item = g_strdup_printf ("=%s/e-summary=/executive-summary/page", path); + prefs->page = gnome_config_get_string (item); + g_free (item); + + return prefs; +} + +void +e_summary_prefs_save (ESummaryPrefs *prefs, + const char *path) +{ + char *item; + + g_return_if_fail (prefs != NULL); + g_return_if_fail (path != NULL); + g_return_if_fail (*path != '\0'); + + item = g_strdup_printf ("=%s/e-summary=/executive-summary/page", path); + gnome_config_set_string (item, prefs->page); + g_free (item); + + gnome_config_sync (); + gnome_config_drop_all (); +} diff --git a/executive-summary/component/e-summary-prefs.h b/executive-summary/component/e-summary-prefs.h new file mode 100644 index 0000000000..95fc6af2c2 --- /dev/null +++ b/executive-summary/component/e-summary-prefs.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-summary-prefs.h: Preference handling routines. + * + * Authors: Iain Holmes + * + * Copyright (C) 2000 Helix Code, 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. + */ + +#ifndef __E_SUMMARY_PREFS_H__ +#define __E_SUMMARY_PREFS_H__ + +typedef struct _ESummaryPrefs ESummaryPrefs; +struct _ESummaryPrefs { + char *page; +}; + +ESummaryPrefs *e_summary_prefs_new (void); +void e_summary_prefs_free (ESummaryPrefs *prefs); +ESummaryPrefs *e_summary_prefs_copy (ESummaryPrefs *prefs); +ESummaryPrefs *e_summary_prefs_load (const char *path); +void e_summary_prefs_save (ESummaryPrefs *prefs, + const char *path); + +#endif diff --git a/executive-summary/component/e-summary-url.c b/executive-summary/component/e-summary-url.c index f7dd863a26..d53b21ec4c 100644 --- a/executive-summary/component/e-summary-url.c +++ b/executive-summary/component/e-summary-url.c @@ -73,6 +73,12 @@ static char *descriptions[] = { N_("Open %s with the default GNOME application") }; +typedef struct _PropertyDialog { + BonoboListener *listener; + Bonobo_Listener corba_listener; + Bonobo_EventSource eventsource; + GtkWidget *dialog; +} PropertyDialog; #define COMPOSER_IID "OAFIID:GNOME_Evolution_Mail_Composer" gboolean e_summary_url_mail_compose (ESummary *esummary, @@ -319,6 +325,65 @@ get_protocol (const char *url) return protocol; } +static void +property_apply (GnomePropertyBox *propertybox, + gint page_num, + Bonobo_PropertyControl control) +{ + CORBA_Environment ev; + + g_print ("page_num: %d\n", page_num); + + CORBA_exception_init (&ev); + Bonobo_PropertyControl_notifyAction (control, page_num, Bonobo_PropertyControl_APPLY, &ev); + CORBA_exception_free (&ev); +} + +static void +property_help (GnomePropertyBox *propertybox, + gint page_num, + Bonobo_PropertyControl control) +{ + CORBA_Environment ev; + + CORBA_exception_init (&ev); + Bonobo_PropertyControl_notifyAction (control, page_num, Bonobo_PropertyControl_HELP, &ev); + CORBA_exception_free (&ev); +} + +static void +property_event (BonoboListener *listener, + char *event_name, + CORBA_any *any, + CORBA_Environment *ev, + gpointer user_data) +{ + PropertyDialog *data = (PropertyDialog *) user_data; + if (strcmp (event_name, "property_box_changed") == 0) { + gnome_property_box_changed (GNOME_PROPERTY_BOX (data->dialog)); + return; + } +} + +static void +dialog_destroyed (GtkObject *object, + PropertyDialog *dialog) +{ + CORBA_Environment ev; + + CORBA_exception_init (&ev); + Bonobo_EventSource_removeListener (dialog->eventsource, + dialog->corba_listener, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Error: %s", CORBA_exception_id (&ev)); + } + + bonobo_object_unref (BONOBO_OBJECT (dialog->listener)); + bonobo_object_release_unref (dialog->eventsource, &ev); + CORBA_exception_free (&ev); + g_free (dialog); +} + void e_summary_url_click (GtkWidget *widget, const char *url, @@ -328,6 +393,11 @@ e_summary_url_click (GtkWidget *widget, char *parsed; int address; ESummaryWindow *window; + Bonobo_Control control; + GtkWidget *prefsbox, *control_widget; + CORBA_Environment ev; + PropertyDialog *data; + int num_pages, i; protocol = get_protocol (url); @@ -354,7 +424,7 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 8); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; e_summary_remove_window (esummary, window); e_summary_rebuild_page (esummary); @@ -365,9 +435,50 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 12); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; - /* Issue the configure command some how :) */ + data = g_new (PropertyDialog, 1); + /* Create the property box */ + prefsbox = gnome_property_box_new (); + data->dialog = prefsbox; + + CORBA_exception_init (&ev); + data->eventsource = Bonobo_Unknown_queryInterface (window->propertycontrol, + "IDL:Bonobo/EventSource:1.0", + &ev); + data->listener = bonobo_listener_new (property_event, data); + data->corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (data->listener)); + Bonobo_EventSource_addListener (data->eventsource, + data->corba_listener, &ev); + + gtk_signal_connect (GTK_OBJECT (prefsbox), "apply", + GTK_SIGNAL_FUNC (property_apply), + window->propertycontrol); + gtk_signal_connect (GTK_OBJECT (prefsbox), "help", + GTK_SIGNAL_FUNC (property_help), + window->propertycontrol); + gtk_signal_connect (GTK_OBJECT (prefsbox), "destroy", + GTK_SIGNAL_FUNC (dialog_destroyed), data); + + num_pages = Bonobo_PropertyControl__get_pageCount (window->propertycontrol, &ev); + for (i = 0; i < num_pages; i++) { + char *pagename; + + control = Bonobo_PropertyControl_getControl (window->propertycontrol, i, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Unable to get property control."); + CORBA_exception_free (&ev); + break; + } + control_widget = bonobo_widget_new_control_from_objref (control, + CORBA_OBJECT_NIL); + gnome_property_box_append_page (GNOME_PROPERTY_BOX (prefsbox), + control_widget, + gtk_label_new ("page")); + } + + gtk_widget_show_all (prefsbox); + break; case PROTOCOL_LEFT: @@ -375,7 +486,7 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 7); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; e_summary_window_move_left (esummary, window); e_summary_rebuild_page (esummary); @@ -385,7 +496,7 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 8); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; e_summary_window_move_right (esummary, window); e_summary_rebuild_page (esummary); @@ -395,7 +506,7 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 5); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; e_summary_window_move_up (esummary, window); e_summary_rebuild_page (esummary); @@ -405,7 +516,7 @@ e_summary_url_click (GtkWidget *widget, address = atoi (url + 7); window = (ESummaryWindow *) GINT_TO_POINTER (address); if (window->iid == NULL) - return; + break; e_summary_window_move_down (esummary, window); e_summary_rebuild_page (esummary); diff --git a/executive-summary/component/e-summary.c b/executive-summary/component/e-summary.c index e9bf104fd1..587b063e6a 100644 --- a/executive-summary/component/e-summary.c +++ b/executive-summary/component/e-summary.c @@ -32,7 +32,7 @@ #include #include #include -#include + #include #include #include @@ -42,9 +42,12 @@ #include "e-summary-util.h" #include "e-summary-url.h" +#include +#include + #define PARENT_TYPE (gtk_vbox_get_type ()) -#define STORAGE_TYPE "efs" +#define STORAGE_TYPE "fs" #define IID_FILE "oaf.id" #define DATA_FILE "data" @@ -81,20 +84,6 @@ static void e_summary_save_state (ESummary *esummary, static void e_summary_load_state (ESummary *esummary, const char *path); -/* Used to distinguish dead windows */ -static ESummaryWindow dead_window = { - CORBA_OBJECT_NIL, - CORBA_OBJECT_NIL, - CORBA_OBJECT_NIL, - CORBA_OBJECT_NIL, - CORBA_OBJECT_NIL, - CORBA_OBJECT_NIL, - NULL, - NULL, - NULL, - NULL -}; - /* GtkObject methods */ static void @@ -109,7 +98,7 @@ e_summary_destroy (GtkObject *object) if (priv == NULL) return; - prefix = g_concat_dir_and_file (evolution_dir, "config/Executive-Summary"); + prefix = g_concat_dir_and_file (evolution_dir, "config/"); e_summary_save_state (esummary, prefix); g_free (prefix); @@ -203,6 +192,8 @@ e_summary_init (ESummary *esummary) GdkColor bgcolour = {0, 0xdfff, 0xdfff, 0xffff}; ESummaryPrivate *priv; + esummary->prefs = NULL; + esummary->tmp_prefs = NULL; esummary->private = g_new0 (ESummaryPrivate, 1); priv = esummary->private; @@ -252,7 +243,7 @@ e_summary_new (const GNOME_Evolution_Shell shell) /* Restore services */ path = g_concat_dir_and_file (evolution_dir, - "config/Executive-Summary"); + "config"); e_summary_load_state (esummary, path); g_free (path); @@ -324,8 +315,8 @@ on_object_requested (GtkHTML *html, if (widget->parent == NULL) gtk_container_add (GTK_CONTAINER (eb), widget); - return TRUE; #endif + return TRUE; } /* Generates the window controls and works out @@ -386,14 +377,16 @@ make_control_html (ESummaryWindow *window, tmp = html; if (!r) { html = g_strdup_printf ("%s" - "", tmp); + "", tmp); } else { html = g_strdup_printf ("%s" "" - "", tmp, id); + "", tmp, id); } g_free (tmp); + +#if 0 tmp = html; if (!d) { html = g_strdup_printf ("%s" @@ -416,6 +409,7 @@ make_control_html (ESummaryWindow *window, } g_free (tmp); +#endif return html; } @@ -463,13 +457,14 @@ e_summary_display_window (ESummary *esummary, html = GNOME_Evolution_Summary_HTMLView_getHtml (window->html, &ev); if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); g_warning ("Cannot get HTML."); - return; - } - CORBA_exception_free (&ev); + } else { + CORBA_exception_free (&ev); - gtk_html_write (GTK_HTML (priv->html), priv->stream, - html, strlen (html)); + gtk_html_write (GTK_HTML (priv->html), priv->stream, + html, strlen (html)); + } } else { #if 0 char *body_cid; @@ -563,6 +558,23 @@ e_summary_rebuild_page (ESummary *esummary) return FALSE; } +static void +html_event (BonoboListener *listener, + char *event_name, + CORBA_any *any, + CORBA_Environment *ev, + gpointer user_data) +{ + ESummaryWindow *window = (ESummaryWindow *) user_data; + + g_print ("Event: %s\n", event_name); + if (strcmp (event_name, "html_changed") != 0) { + return; + } + + e_summary_rebuild_page (window->esummary); +} + static void prop_changed_cb (BonoboPropertyListener *listener, char *name, @@ -573,6 +585,7 @@ prop_changed_cb (BonoboPropertyListener *listener, if (window->title != NULL) g_free (window->title); window->title = g_strdup (BONOBO_ARG_GET_STRING (arg)); + e_summary_rebuild_page (window->esummary); return; } @@ -580,6 +593,7 @@ prop_changed_cb (BonoboPropertyListener *listener, if (window->icon != NULL) g_free (window->icon); window->icon = g_strdup (BONOBO_ARG_GET_STRING (arg)); + e_summary_rebuild_page (window->esummary); return; } } @@ -604,6 +618,7 @@ e_summary_add_service (ESummary *esummary, window = g_new0 (ESummaryWindow, 1); window->component = component; window->iid = g_strdup (iid); + window->esummary = esummary; /* See what interfaces our component supports */ CORBA_exception_init (&ev); @@ -631,6 +646,26 @@ e_summary_add_service (ESummary *esummary, return NULL; } + if (window->html != CORBA_OBJECT_NIL) { + Bonobo_Listener listener; + CORBA_Environment ev2; + + /* If HTML view, then set up the listeners. */ + window->event_source = Bonobo_Unknown_queryInterface (window->html, + "IDL:Bonobo/EventSource:1.0", + &ev); + window->html_listener = bonobo_listener_new (html_event, + window); + listener = bonobo_object_corba_objref (BONOBO_OBJECT (window->html_listener)); + window->html_corba_listener = listener; + + CORBA_exception_init (&ev2); + Bonobo_EventSource_addListener (window->event_source, + listener, &ev2); + /* Catch error? FIXME */ + CORBA_exception_free (&ev2); + } + unknown = Bonobo_Unknown_queryInterface (component, "IDL:Bonobo/PropertyBag:1.0", &ev); @@ -673,6 +708,28 @@ e_summary_add_service (ESummary *esummary, return window; } + +ESummaryWindow * +e_summary_embed_service_from_id (ESummary *esummary, + const char *obj_id) +{ + GNOME_Evolution_Summary_Component component; + ExecutiveSummaryComponentFactoryClient *client; + ESummaryWindow *window; + + client = executive_summary_component_factory_client_new (obj_id); + + component = executive_summary_component_factory_client_create_view (client); + + /* Don't need the client any more */ + bonobo_object_unref (BONOBO_OBJECT (client)); + + window = e_summary_add_service (esummary, component, obj_id); + e_summary_rebuild_page (esummary); + + return window; +} + void e_summary_window_free (ESummaryWindow *window) { @@ -685,37 +742,49 @@ e_summary_window_free (ESummaryWindow *window) g_free (window->title); CORBA_exception_init (&ev); - Bonobo_Unknown_unref (window->component, &ev); - CORBA_Object_release (window->component, &ev); if (window->control != CORBA_OBJECT_NIL) { - CORBA_Object_release (window->control, &ev); + bonobo_object_release_unref (window->control, &ev); + } + + if (window->event_source != CORBA_OBJECT_NIL) { + Bonobo_EventSource_removeListener (window->event_source, + window->html_corba_listener, + &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("CORBA ERROR: %s", CORBA_exception_id (&ev)); + } + bonobo_object_release_unref (window->event_source, &ev); } if (window->html != CORBA_OBJECT_NIL) { - CORBA_Object_release (window->html, &ev); + bonobo_object_release_unref (window->html, &ev); } if (window->propertybag != CORBA_OBJECT_NIL) { - CORBA_Object_release (window->propertybag, &ev); + bonobo_object_release_unref (window->propertybag, &ev); } if (window->persiststream != CORBA_OBJECT_NIL) { - CORBA_Object_release (window->persiststream, &ev); + bonobo_object_release_unref (window->persiststream, &ev); } if (window->propertycontrol != CORBA_OBJECT_NIL) { - CORBA_Object_release (window->propertycontrol, &ev); + bonobo_object_release_unref (window->propertycontrol, &ev); + } + + if (window->listener) { + bonobo_object_unref (BONOBO_OBJECT (window->listener)); + } + + if (window->html_listener) { + bonobo_object_unref (BONOBO_OBJECT (window->html_listener)); } + bonobo_object_release_unref (window->component, &ev); CORBA_exception_free (&ev); g_free (window); - - /* The contents of window are set to dead_window - so we know if we're trying to access a window - that no longer exists */ - *window = dead_window; } void @@ -840,8 +909,7 @@ e_summary_set_title (ESummary *esummary, } static void -load_html_page (ESummary *esummary, - const char *filename) +e_summary_load_page (ESummary *esummary) { ESummaryPrivate *priv; GnomeVFSHandle *handle = NULL; @@ -849,17 +917,17 @@ load_html_page (ESummary *esummary, GtkWidget *toplevel; GString *string; char *str, *comment; + char *filename; g_return_if_fail (esummary != NULL); g_return_if_fail (IS_E_SUMMARY (esummary)); - + priv = esummary->private; + filename = g_strdup (esummary->prefs->page); /* Pass NULL to reset the page to the default */ if (filename == NULL || *filename == '\0') { - g_free (priv->header); - g_free (priv->footer); - return; + filename = g_concat_dir_and_file (EVOLUTION_DATADIR, "/evolution/summary.html"); } toplevel = gtk_widget_get_toplevel (GTK_WIDGET (esummary)); @@ -868,9 +936,11 @@ load_html_page (ESummary *esummary, if (result != GNOME_VFS_OK) { e_notice (GTK_WINDOW (toplevel), GNOME_MESSAGE_BOX_WARNING, _("Cannot open the HTML file:\n%s"), filename); + g_free (filename); return; } + g_free (filename); while (1) { char buffer[4096]; GnomeVFSFileSize size; @@ -896,7 +966,7 @@ load_html_page (ESummary *esummary, comment = strstr (str, ""); if (comment == NULL) { - e_notice (GTK_WINDOW (toplevel), GNOME_MESSAGE_BOX_WARNING, + e_notice (NULL, GNOME_MESSAGE_BOX_WARNING, _("File does not have a place for the services.\n")); g_free (str); return; @@ -984,20 +1054,28 @@ load_component (ESummary *esummary, corba_subdir = Bonobo_Storage_openStorage (corba_storage, curdir, Bonobo_Storage_READ, &ev); + if (corba_subdir == CORBA_OBJECT_NIL) { + g_free (curdir); + return; + } + iid = load_component_id (corba_subdir, &ev); if (iid) { Bonobo_Stream corba_stream; - window = e_summary_factory_embed_service_from_id (esummary, iid); + window = e_summary_embed_service_from_id (esummary, iid); if (window) { if (window->persiststream) { corba_stream = Bonobo_Storage_openStream (corba_subdir, DATA_FILE, - Bonobo_Storage_READ, &ev); - if (ev._major != CORBA_NO_EXCEPTION) + Bonobo_Storage_READ | + Bonobo_Storage_CREATE, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_print ("Gah"); return; + } Bonobo_PersistStream_load (window->persiststream, corba_stream, @@ -1005,22 +1083,34 @@ load_component (ESummary *esummary, if (ev._major != CORBA_NO_EXCEPTION) g_warning ("Could not load `%s'", iid); + bonobo_object_release_unref (corba_stream, &ev); } } g_free (iid); } + bonobo_object_release_unref (corba_subdir, &ev); CORBA_exception_free (&ev); g_free (curdir); } - + +void +e_summary_reconfigure (ESummary *esummary) +{ + ESummaryPrefs *prefs; + + prefs = esummary->prefs; + + e_summary_load_page (esummary); + e_summary_rebuild_page (esummary); +} + static void e_summary_load_state (ESummary *esummary, const char *path) { char *fullpath; - char *htmlpage = NULL; BonoboStorage *storage; Bonobo_Storage corba_storage; Bonobo_Storage_DirectoryList *list; @@ -1030,7 +1120,7 @@ e_summary_load_state (ESummary *esummary, g_return_if_fail (esummary != NULL); g_return_if_fail (IS_E_SUMMARY (esummary)); - fullpath = g_strdup_printf ("%s", path); + fullpath = g_strdup_printf ("%s/Executive-Summary", path); storage = bonobo_storage_open (STORAGE_TYPE, fullpath, Bonobo_Storage_READ | Bonobo_Storage_WRITE, @@ -1040,30 +1130,22 @@ e_summary_load_state (ESummary *esummary, corba_storage = bonobo_object_corba_objref (BONOBO_OBJECT (storage)); list = Bonobo_Storage_listContents (corba_storage, "/", 0, &ev); - if (!list) { - CORBA_exception_free (&ev); - bonobo_object_unref (BONOBO_OBJECT (storage)); - return; + if (list) { + for (i = 0; i < list->_length; i++) + load_component (esummary, storage, i); + + CORBA_free (list); } - - for (i = 0; i < list->_length; i++) - load_component (esummary, storage, i); - - CORBA_free (list); + bonobo_object_unref (BONOBO_OBJECT (storage)); + CORBA_exception_free (&ev); } g_free (fullpath); - /* Load the html page */ - fullpath = g_strdup_printf ("=%s=/executive-summary/page", path); - htmlpage = gnome_config_get_string (fullpath); - g_print ("htmlpage: %s\n", htmlpage); - if (htmlpage) { - load_html_page (esummary, htmlpage); - } - g_free (fullpath); - g_free (htmlpage); + /* Load the preferences */ + esummary->prefs = e_summary_prefs_load (path); + e_summary_reconfigure (esummary); } static void @@ -1080,23 +1162,33 @@ save_component (BonoboStorage *storage, CORBA_exception_init (&ev); corba_subdir = Bonobo_Storage_openStorage (corba_storage, curdir, - Bonobo_Storage_CREATE, &ev); + Bonobo_Storage_CREATE| + Bonobo_Storage_WRITE| + Bonobo_Storage_READ, &ev); if (ev._major != CORBA_NO_EXCEPTION) { g_warning ("Cannot create '%s'", curdir); + g_free (curdir); } else { Bonobo_Stream corba_stream; + g_free (curdir); corba_stream = Bonobo_Storage_openStream - (corba_subdir, IID_FILE, Bonobo_Storage_CREATE, &ev); + (corba_subdir, IID_FILE, + Bonobo_Storage_CREATE| + Bonobo_Storage_READ| + Bonobo_Storage_WRITE, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("EEk: %s", CORBA_exception_id (&ev)); + g_warning ("EEK: %s", CORBA_exception_id (&ev)); + if (corba_subdir != CORBA_OBJECT_NIL) + bonobo_object_release_unref (corba_subdir, &ev); + CORBA_exception_free (&ev); return; } bonobo_stream_client_write_string (corba_stream, window->iid, TRUE, &ev); - Bonobo_Unknown_unref (corba_stream, &ev); - CORBA_Object_release (corba_stream, &ev); + bonobo_object_release_unref (corba_stream, &ev); corba_stream = Bonobo_Storage_openStream (corba_subdir, DATA_FILE, Bonobo_Storage_CREATE, @@ -1109,14 +1201,11 @@ save_component (BonoboStorage *storage, } } - Bonobo_Unknown_unref (corba_stream, &ev); - CORBA_Object_release (corba_stream, &ev); - - Bonobo_Unknown_unref (corba_subdir, &ev); - CORBA_Object_release (corba_subdir, &ev); + bonobo_object_release_unref (corba_stream, &ev); } - g_free (curdir); + if (corba_subdir != CORBA_OBJECT_NIL) + bonobo_object_release_unref (corba_subdir, &ev); CORBA_exception_free (&ev); } @@ -1137,10 +1226,11 @@ e_summary_save_state (ESummary *esummary, priv = esummary->private; -#if 0 - fullpath = g_strdup_printf("%s", path); + fullpath = g_strdup_printf("%s/Executive-Summary", path); g_print ("fullpath: %s\n", fullpath); - unlink (fullpath); + + /* FIXME: Use RC's rmdir function */ + remove (fullpath); storage = bonobo_storage_open (STORAGE_TYPE, fullpath, Bonobo_Storage_READ | @@ -1154,6 +1244,7 @@ e_summary_save_state (ESummary *esummary, i = 0; for (windows = priv->window_list; windows; windows = windows->next) { save_component (storage, windows->data, i); + g_print ("IID: %s\n", ((ESummaryWindow *)windows->data)->iid); i++; } @@ -1161,8 +1252,8 @@ e_summary_save_state (ESummary *esummary, CORBA_exception_free (&ev); bonobo_object_unref (BONOBO_OBJECT (storage)); + e_summary_prefs_save (esummary->prefs, path); g_free (fullpath); -#endif } void diff --git a/executive-summary/component/e-summary.h b/executive-summary/component/e-summary.h index 5eae27ea0c..90c1412f95 100644 --- a/executive-summary/component/e-summary.h +++ b/executive-summary/component/e-summary.h @@ -24,12 +24,15 @@ #ifndef _E_SUMMARY_H__ #define _E_SUMMARY_H__ -#include #include -#include #include +#include +#include #include +#include + +#include "e-summary-prefs.h" #define E_SUMMARY_TYPE (e_summary_get_type ()) #define E_SUMMARY(obj) (GTK_CHECK_CAST ((obj), E_SUMMARY_TYPE, ESummary)) @@ -51,22 +54,29 @@ struct _ESummaryWindow { Bonobo_PersistStream persiststream; Bonobo_PropertyBag propertybag; Bonobo_PropertyControl propertycontrol; + Bonobo_EventSource event_source; BonoboPropertyListener *listener; + BonoboListener *html_listener; + Bonobo_Listener html_corba_listener; char *iid; char *title; char *icon; + + ESummary *esummary; }; struct _ESummary { - GtkVBox parent; + GtkVBox parent; - ESummaryPrivate *private; + ESummaryPrefs *prefs; + ESummaryPrefs *tmp_prefs; + ESummaryPrivate *private; }; struct _ESummaryClass { - GtkVBoxClass parent_class; + GtkVBoxClass parent_class; }; GtkType e_summary_get_type (void); @@ -79,6 +89,8 @@ void e_summary_remove_window (ESummary *esummary, ESummaryWindow *e_summary_add_service (ESummary *esummary, GNOME_Evolution_Summary_Component component, const char *iid); +ESummaryWindow * e_summary_embed_service_from_id (ESummary *esummary, + const char *obj_id); void e_summary_set_shell_view_interface (ESummary *summary, GNOME_Evolution_ShellView svi); @@ -99,5 +111,6 @@ void e_summary_window_move_up (ESummary *esummary, ESummaryWindow *window); void e_summary_window_move_down (ESummary *esummary, ESummaryWindow *window); +void e_summary_reconfigure (ESummary *esummary); #endif diff --git a/executive-summary/component/executive-summary-config.glade b/executive-summary/component/executive-summary-config.glade new file mode 100644 index 0000000000..387964fa21 --- /dev/null +++ b/executive-summary/component/executive-summary-config.glade @@ -0,0 +1,169 @@ + + + + + Project1 + project1 + + src + pixmaps + C + True + True + False + True + True + True + True + interface.c + interface.h + callbacks.c + callbacks.h + support.c + support.h + + + + + GnomePropertyBox + summaryprefs + True + + + GtkNotebook + GnomePropertyBox:notebook + notebook1 + 2 + True + True + True + True + GTK_POS_TOP + False + 2 + 2 + False + + 0 + True + True + + + + GtkVBox + vbox1 + 2 + True + False + 0 + + + GtkFrame + frame1 + 2 + True + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox2 + True + False + 0 + + + GtkHBox + hbox1 + True + False + 0 + + 0 + True + True + + + + GtkLabel + label2 + True + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GnomeFileEntry + htmlpage + True + 10 + False + False + + 0 + True + True + + + + GtkEntry + GnomeEntry:entry + combo-entry1 + True + True + True + True + 0 + + + + + + + Placeholder + + + + + + Placeholder + + + + Placeholder + + + + + GtkLabel + Notebook:tab + Label + True + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + diff --git a/executive-summary/component/main.c b/executive-summary/component/main.c index 3c9cc059dd..0c36a9866e 100644 --- a/executive-summary/component/main.c +++ b/executive-summary/component/main.c @@ -23,8 +23,6 @@ #include -#include - #include #include #include @@ -55,6 +53,7 @@ main (int argc, orb = oaf_init (argc, argv); gdk_rgb_init (); + glade_gnome_init (); if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) { g_error (_("Executive summary component could not initialize Bonobo.\n" "If there was a warning message about the " @@ -70,9 +69,6 @@ main (int argc, component_factory_init (); - signal (SIGSEGV, SIG_DFL); - signal (SIGBUS, SIG_DFL); - gnome_vfs_init (); bonobo_main (); -- cgit