From 0932fd7ec9d21e763371a043283384af8bc987fb Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Wed, 17 Jan 2001 10:44:33 +0000 Subject: Ximianified email addresses and copyrights. 2001-01-17 Federico Mena Quintero * */*: Ximianified email addresses and copyrights. * idl/evolution-calendar.idl (CalFactory::open): Renamed from ::load(), and added an only_if_exists argument. (CalFactory::create): Removed method. (Listener::OpenStatus): Removed the IN_USE error and replaced it with a NOT_FOUND one; renamed the enum from LoadStatus. (Listener::notifyCalOpened): Renamed from notifyCalLoaded(). * pcs/cal-backend.h (CalBackend): Removed the uri field. (CalBackendOpenStatus): Renamed from CalBackendLoadStatus and added a NOT_FOUND value. (CalBackendClass::open): Put in a slot for the open method. * pcs/cal-backend.c (cal_backend_create): Removed function. * pcs/cal-backend-file.c (cal_backend_file_open): Return the appropriate value when only_if_exists is TRUE. (create_cal): We are Ximian now, so set the PRODID property to the appropriate foo. * pcs/cal-factory.c (CalFactory_open): implemented, replacing CalFactory_load() and CalFactory_create(). (CalFactory_open): Moved the queue_load_create_job() stuff to here, since we now only need to contemplate the open case instead of load/create ones. (open_backend): Do everything here; replaces load_backend() and create_backend(). * cal-client/cal-listener.h (CalListenerClass::cal_opened): Renamed from cal_loaded. (CalListenerClass): Replaced the silly signals, which are gratuitous abstraction, by a set of function pointers in the instance structure. * cal-client/cal-listener.c (cal_listener_get_calendar): Removed unused function. (cal_listener_construct): Added the listener notification functions. (cal_listener_new): Ditto. (Listener_notifyCalOpened): Renamed to our new naming convention for servant implementations. (Listener_notifyObjUpdated): Ditto. (Listener_notifyObjRemoved): Ditto. * cal-client/cal-client.h (CalClientOpenStatus): Renamed from CalClientLoadStatus. (CalClientClass::cal_opened): Renamed from ::cal_loaded(). (CalClientLoadState): New enum; basically make LoadState public so that users of this code do not have to maintain their own states. * cal-client/cal-client.c (cal_client_create_calendar): Removed function. (cal_client_open_calendar): Moved the functionality over from load_or_create(); now we do everything here. (*): Use the CalClientLoadState enum values instead of the old LoadState values. (cal_client_get_load_state): Renamed from cal_client_is_loaded(), and return the appropriate value. (CalClientPrivate): Added an uri field. (cal_client_init): Initialize priv->uri. (cal_client_destroy): Free the priv->uri. (cal_opened_cb): Maintain the priv->uri. (cal_client_open_calendar): Fill in the priv->uri. (cal_client_get_uri): New function. * gui/calendar-model.c (calendar_model_set_new_comp_vtype): New function to configure the type of calendar components to create when doing click-to-add. This makes the model usable for something other than task lists. (calendar_model_get_new_comp_vtype): New function. * gui/e-calendar-table.c (e_calendar_table_get_model): New function. (e_calendar_table_destroy): Unref the subset_model. * gui/gnome-cal.h (GnomeCalendarOpenMode): Removed enum. * gui/gnome-cal.c (LoadState): Removed enum; we now use the CalClientLoadState from the client objects. (GnomeCalendarPrivate): Removed the loading_uri and task_pad_loading_uri fields as well as the load_state and task_pad_load_state fields, as we can now query them directly from the CalClient. (open_error): Renamed from load_error(). (create_error): Removed function. (gnome_calendar_open): Do not take in the mode parameter. (cal_opened_cb): Get rid of our beautifully-crafted state machine and replace it with simple code; all the loading smarts are in the Wombat now. (setup_widgets): Set the new component vtype of the table model to CAL_COMPONENT_TODO. * gui/Makefile.am (evolution_calendar_SOURCES): Removed gnome-month-item.[ch] from the list of sources. * gui/calendar-summary.c (CalSummary): Removed unused cal_loaded field. (create_summary_view): Do not check if the file exists; this is the job of the Wombat. (generate_html_summary): Fixed prototype. (alarm_fn): Fixed prototype. (property_dialog): Fixed prototype. Wonder if/how this ever worked. (create_summary_view): Cast the component and view as appropriate. Removed unused html variable. [Iain dude, are you compiling with -Wall?] * gui/e-itip-control.c (cal_opened_cb): Sigh, this function signature was *very* wrong. It was using CalClientGetStatus instead of CalClientOpenStatus. * gui/e-tasks.h (ETasksOpenMode): Removed enum. * gui/e-tasks.c (setup_widgets): Set the new component vtype of the table model to CAL_COMPONENT_TODO. (LoadState): Removed the state machine foo. (e_tasks_open): Removed the mode parameter. (initial_load): Removed function. (create_error): Removed function. (ETasksPrivate): Removed folder_uri field. (cal_opened_cb): Remove the state machine. * gui/component-factory.c: #include "tasks-control.h" * conduits/calendar/calendar-conduit.h (ECalConduitContext): Removed calendar_load_tried field. * conduits/calendar/calendar-conduit.c (start_calendar_server_cb): Sigh, fixed function prototype. * conduits/todo/todo-conduit.h (EToDoConduitContext): Removed calendar_load_tried field. * conduits/todo/todo-conduit.c (start_calendar_server_cb): Fixed function prototype. svn path=/trunk/; revision=7571 --- calendar/pcs/cal-backend-file.c | 147 +++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 63 deletions(-) (limited to 'calendar/pcs/cal-backend-file.c') diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index 10d0a35746..623031fa69 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -1,8 +1,9 @@ /* Evolution calendar - iCalendar file backend * * Copyright (C) 2000 Helix Code, Inc. + * Copyright (C) 2000 Ximian, Inc. * - * Author: Federico Mena-Quintero + * Author: Federico Mena-Quintero * * 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 @@ -65,8 +66,8 @@ static void cal_backend_file_destroy (GtkObject *object); static GnomeVFSURI *cal_backend_file_get_uri (CalBackend *backend); static void cal_backend_file_add_cal (CalBackend *backend, Cal *cal); -static CalBackendLoadStatus cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri); -static void cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri); +static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, + gboolean only_if_exists); static int cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type); static char *cal_backend_file_get_object (CalBackend *backend, const char *uid); @@ -138,8 +139,7 @@ cal_backend_file_class_init (CalBackendFileClass *class) backend_class->get_uri = cal_backend_file_get_uri; backend_class->add_cal = cal_backend_file_add_cal; - backend_class->load = cal_backend_file_load; - backend_class->create = cal_backend_file_create; + backend_class->open = cal_backend_file_open; backend_class->get_n_objects = cal_backend_file_get_n_objects; backend_class->get_object = cal_backend_file_get_object; backend_class->get_type_by_uid = cal_backend_file_get_type_by_uid; @@ -587,7 +587,7 @@ scan_vcalendar (CalBackendFile *cbfile) /* Callback used from icalparser_parse() */ static char * -get_line (char *s, size_t size, void *data) +get_line_fn (char *s, size_t size, void *data) { FILE *file; @@ -595,91 +595,71 @@ get_line (char *s, size_t size, void *data) return fgets (s, size, file); } -/* Load handler for the file backend */ -static CalBackendLoadStatus -cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri) +/* Parses an open iCalendar file and returns a toplevel component with the contents */ +static icalcomponent * +parse_file (FILE *file) { - CalBackendFile *cbfile; - CalBackendFilePrivate *priv; - char *str_uri; - FILE *file; icalparser *parser; icalcomponent *icalcomp; - cbfile = CAL_BACKEND_FILE (backend); - priv = cbfile->priv; - - g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_LOAD_ERROR); - g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR); + parser = icalparser_new (); + icalparser_set_gen_data (parser, file); - if (!gnome_vfs_uri_is_local (uri)) - return CAL_BACKEND_LOAD_ERROR; + icalcomp = icalparser_parse (parser, get_line_fn); + icalparser_free (parser); - str_uri = gnome_vfs_uri_to_string (uri, - (GNOME_VFS_URI_HIDE_USER_NAME - | GNOME_VFS_URI_HIDE_PASSWORD - | GNOME_VFS_URI_HIDE_HOST_NAME - | GNOME_VFS_URI_HIDE_HOST_PORT - | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD)); + return icalcomp; +} - /* Load! */ - file = fopen (str_uri, "r"); - g_free (str_uri); +/* Parses an open iCalendar file and loads it into the backend */ +static CalBackendOpenStatus +open_cal (CalBackendFile *cbfile, GnomeVFSURI *uri, FILE *file) +{ + CalBackendFilePrivate *priv; + icalcomponent *icalcomp; - if (!file) - return CAL_BACKEND_LOAD_ERROR; + priv = cbfile->priv; - parser = icalparser_new (); - icalparser_set_gen_data (parser, file); + icalcomp = parse_file (file); - icalcomp = icalparser_parse (parser, get_line); - icalparser_free (parser); + if (fclose (file) != 0) { + if (icalcomp) + icalcomponent_free (icalcomp); - if (fclose (file) != 0) - return CAL_BACKEND_LOAD_ERROR; + return CAL_BACKEND_OPEN_ERROR; + } if (!icalcomp) - return CAL_BACKEND_LOAD_ERROR; - - /* FIXME: should we try to demangle XROOT components and individual - * components as well? + return CAL_BACKEND_OPEN_ERROR; + + /* FIXME: should we try to demangle XROOT components and + * individual components as well? */ if (icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT) - return CAL_BACKEND_LOAD_ERROR; + return CAL_BACKEND_OPEN_ERROR; priv->icalcomp = icalcomp; priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); scan_vcalendar (cbfile); - /* Clean up */ - if (priv->uri) - gnome_vfs_uri_unref (priv->uri); - gnome_vfs_uri_ref (uri); priv->uri = uri; - return CAL_BACKEND_LOAD_SUCCESS; + return CAL_BACKEND_OPEN_SUCCESS; } -/* Create handler for the file backend */ -static void -cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri) +static CalBackendOpenStatus +create_cal (CalBackendFile *cbfile, GnomeVFSURI *uri) { - CalBackendFile *cbfile; CalBackendFilePrivate *priv; icalproperty *prop; - cbfile = CAL_BACKEND_FILE (backend); priv = cbfile->priv; - g_return_if_fail (priv->icalcomp == NULL); - g_return_if_fail (uri != NULL); - /* Create the new calendar information */ - g_assert (priv->icalcomp == NULL); priv->icalcomp = icalcomponent_new (ICAL_VCALENDAR_COMPONENT); /* RFC 2445, section 4.7.1 */ @@ -687,26 +667,67 @@ cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri) icalcomponent_add_property (priv->icalcomp, prop); /* RFC 2445, section 4.7.3 */ - prop = icalproperty_new_prodid ("-//Helix Code//NONSGML Evolution Calendar//EN"); + prop = icalproperty_new_prodid ("-//Ximian//NONSGML Evolution Calendar//EN"); icalcomponent_add_property (priv->icalcomp, prop); - /* RFC 2445, section 4.7.4 */ + /* RFC 2445, section 4.7.4. This is the iCalendar spec version, *NOT* + * the product version! Do not change this! + */ prop = icalproperty_new_version ("2.0"); icalcomponent_add_property (priv->icalcomp, prop); /* Create our internal data */ - g_assert (priv->comp_uid_hash == NULL); priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); - /* Clean up */ - if (priv->uri) - gnome_vfs_uri_unref (priv->uri); - gnome_vfs_uri_ref (uri); priv->uri = uri; mark_dirty (cbfile); + + return CAL_BACKEND_OPEN_SUCCESS; +} + +/* Open handler for the file backend */ +static CalBackendOpenStatus +cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists) +{ + CalBackendFile *cbfile; + CalBackendFilePrivate *priv; + char *str_uri; + FILE *file; + + cbfile = CAL_BACKEND_FILE (backend); + priv = cbfile->priv; + + g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_OPEN_ERROR); + g_return_val_if_fail (uri != NULL, CAL_BACKEND_OPEN_ERROR); + + g_assert (priv->uri == NULL); + g_assert (priv->comp_uid_hash == NULL); + + if (!gnome_vfs_uri_is_local (uri)) + return CAL_BACKEND_OPEN_ERROR; + + str_uri = gnome_vfs_uri_to_string (uri, + (GNOME_VFS_URI_HIDE_USER_NAME + | GNOME_VFS_URI_HIDE_PASSWORD + | GNOME_VFS_URI_HIDE_HOST_NAME + | GNOME_VFS_URI_HIDE_HOST_PORT + | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD)); + + /* Load! */ + file = fopen (str_uri, "r"); + g_free (str_uri); + + if (file) + return open_cal (cbfile, uri, file); + else { + if (only_if_exists) + return CAL_BACKEND_OPEN_NOT_FOUND; + + return create_cal (cbfile, uri); + } } /* Get_n_objects handler for the file backend */ -- cgit