diff options
author | Seth Alves <alves@src.gnome.org> | 2000-04-10 02:46:25 +0800 |
---|---|---|
committer | Seth Alves <alves@src.gnome.org> | 2000-04-10 02:46:25 +0800 |
commit | 9496367085a9e45cf4d918987aab2244e3c7ece1 (patch) | |
tree | cec62e9ba647d28172ef834c6f59150589d557d1 /calendar | |
parent | 99612fe24cfc0dcb5bc8f020fe759ccb3cfc1416 (diff) | |
download | gsoc2013-evolution-9496367085a9e45cf4d918987aab2244e3c7ece1.tar.gz gsoc2013-evolution-9496367085a9e45cf4d918987aab2244e3c7ece1.tar.zst gsoc2013-evolution-9496367085a9e45cf4d918987aab2244e3c7ece1.zip |
catch cal_loaded signal on the cal client. (gnome_calendar_load_cb):
* gui/gnome-cal.c (gnome_calendar_load): catch cal_loaded signal
on the cal client.
(gnome_calendar_load_cb): callback for cal_loaded signal. moved
gnome_calendar_update_all from gnome_calendar_load to here.
* gui/calendar-commands.c: minor cleanups
* pcs/cal-backend.c (save_to_vcal): copied code from gnome-pim
to write vcal to a file
(save): filled it with more gnome-pim code
(add_object): call save () after changing
(remove_object): same
(cal_backend_create): same
(cal_backend_remove_object): same
svn path=/trunk/; revision=2352
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 17 | ||||
-rw-r--r-- | calendar/gui/calendar-commands.c | 17 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.c | 25 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.h | 2 | ||||
-rw-r--r-- | calendar/pcs/cal-backend.c | 135 |
5 files changed, 155 insertions, 41 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index d3618c86e4..2022dd4a3a 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,20 @@ +2000-04-09 Seth Alves <alves@hungry.com> + + * gui/gnome-cal.c (gnome_calendar_load): catch cal_loaded signal + on the cal client. + (gnome_calendar_load_cb): callback for cal_loaded signal. moved + gnome_calendar_update_all from gnome_calendar_load to here. + + * gui/calendar-commands.c: minor cleanups + + * pcs/cal-backend.c (save_to_vcal): copied code from gnome-pim + to write vcal to a file + (save): filled it with more gnome-pim code + (add_object): call save () after changing + (remove_object): same + (cal_backend_create): same + (cal_backend_remove_object): same + 2000-04-08 Christopher James Lahey <clahey@helixcode.com> * gui/Makefile.am: Removed linking with libetable and libeminicard diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 9b3fa91525..12b3c92774 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -566,6 +566,7 @@ calendar_close_event (GtkWidget *widget, GdkEvent *event, GnomeCalendar *gcal) return TRUE; } + GnomeCalendar * new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, gboolean hidden) { @@ -584,16 +585,7 @@ new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, if (gnome_parse_geometry (geometry, &xpos, &ypos, &width, &height)){ if (xpos != -1) gtk_widget_set_uposition (toplevel, xpos, ypos); - /*if (width != -1) - gtk_widget_set_usize (toplevel, width, 600);*/ } - /*gtk_widget_set_usize (toplevel, width, 600); */ - - /* - setup_appbar (toplevel); - setup_menu (toplevel); - */ - if (page) gnome_calendar_set_view (GNOME_CALENDAR (toplevel), page); @@ -601,12 +593,13 @@ new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, printf ("calendar_file is '%s'\n", calendar_file?calendar_file:"NULL"); if (calendar_file && g_file_exists (calendar_file)) { printf ("loading calendar\n"); - success = gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); + success = gnome_calendar_load (GNOME_CALENDAR (toplevel), + calendar_file); } else { printf ("creating calendar\n"); - success = gnome_calendar_create (GNOME_CALENDAR (toplevel), calendar_file); - /*GNOME_CALENDAR (toplevel)->client->filename = g_strdup (calendar_file);*/ + success = gnome_calendar_create (GNOME_CALENDAR (toplevel), + calendar_file); } printf ("load or create returned %d\n", success); diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 86655f15e5..5b449c79d3 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -256,12 +256,25 @@ gnome_calendar_new (char *title) static void gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags) { - gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), object, flags); - gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags); + gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), + object, flags); + gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), + object, flags); month_view_update (MONTH_VIEW (cal->month_view), object, flags); year_view_update (YEAR_VIEW (cal->year_view), object, flags); } + +static void +gnome_calendar_load_cb (GtkWidget *cal_client, + gpointer something, + GnomeCalendar *gcal) +{ + gnome_calendar_update_all (gcal, NULL, 0); +} + + + int gnome_calendar_load (GnomeCalendar *gcal, char *file) { @@ -269,16 +282,14 @@ gnome_calendar_load (GnomeCalendar *gcal, char *file) g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), 0); g_return_val_if_fail (file != NULL, 0); - /* FIXME: connect to the cal_loaded signal fo the CalClient and get the - * asynchronous notification properly! - */ + gtk_signal_connect (GTK_OBJECT (gcal->client), "cal_loaded", + gnome_calendar_load_cb, gcal); - /* if ((r = calendar_load (gcal->cal, file)) != NULL){ DELETE */ if (cal_client_load_calendar (gcal->client, file) == FALSE){ printf ("Error loading calendar: %s\n", file); return 0; } - gnome_calendar_update_all (gcal, NULL, 0); + return 1; } diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index 636696e9a0..fec7b95bb5 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -43,7 +43,7 @@ typedef struct { guint gnome_calendar_get_type (void); GtkWidget *gnome_calendar_new (char *title); -int gnome_calendar_load (GnomeCalendar *gcal, +int gnome_calendar_load (GnomeCalendar *gcal, char *file); int gnome_calendar_create (GnomeCalendar *gcal, char *file); diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c index 2d8807d08a..893a9aab1f 100644 --- a/calendar/pcs/cal-backend.c +++ b/calendar/pcs/cal-backend.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* Evolution calendar backend * * Copyright (C) 2000 Helix Code, Inc. @@ -52,6 +53,9 @@ typedef struct { /* Whether a calendar has been loaded */ guint loaded : 1; + + /* Do we need to sync to permanent storage? */ + gboolean dirty : 1; } CalBackendPrivate; @@ -90,7 +94,8 @@ cal_backend_get_type (void) (GtkClassInitFunc) NULL }; - cal_backend_type = gtk_type_unique (GTK_TYPE_OBJECT, &cal_backend_info); + cal_backend_type = + gtk_type_unique (GTK_TYPE_OBJECT, &cal_backend_info); } return cal_backend_type; @@ -122,11 +127,82 @@ cal_backend_init (CalBackend *backend) priv->format = CAL_VCAL; } +static void save_to_vcal (CalBackend *backend, char *fname) +{ + FILE *fp; + CalBackendPrivate *priv = backend->priv; + + if (g_file_exists (fname)){ + char *backup_name = g_strconcat (fname, "~", NULL); + + if (g_file_exists (backup_name)){ + unlink (backup_name); + } + rename (fname, backup_name); + g_free (backup_name); + } + + fp = fopen(fname,"w"); + if (fp) { + GList *l; + + for (l = priv->events; l; l = l->next) { + iCalObject *ical = l->data; + VObject *vobject = ical_object_to_vobject (ical); + writeVObject(fp, vobject); + cleanVObject (vobject); + } + for (l = priv->todos; l; l = l->next) { + iCalObject *ical = l->data; + VObject *vobject = ical_object_to_vobject (ical); + writeVObject(fp, vobject); + cleanVObject (vobject); + } + for (l = priv->journals; l; l = l->next) { + iCalObject *ical = l->data; + VObject *vobject = ical_object_to_vobject (ical); + writeVObject(fp, vobject); + cleanVObject (vobject); + } + + fclose(fp); + } /*else { + report bad problem FIX ME; + }*/ + + cleanStrTbl (); +} + + /* Saves a calendar */ static void save (CalBackend *backend) { - /* FIXME */ + char *str_uri; + CalBackendPrivate *priv = backend->priv; + + str_uri = gnome_vfs_uri_to_string (priv->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)); + + if (! priv->dirty) + return; + + switch (priv->format) { + case CAL_VCAL: + save_to_vcal (backend, str_uri); + break; + case CAL_ICAL: + /*icalendar_calendar_save (backend, str_uri);*/ + /* FIX ME */ + break; + default: + /* FIX ME log */ + break; + } } /* g_hash_table_foreach() callback to destroy an iCalObject */ @@ -229,7 +305,8 @@ ensure_uid (iCalObject *ico) /* Is this good enough? */ - buf = g_strdup_printf ("Evolution-Tlacuache-%d-%ld-%u", (int) getpid(), str_time, seqno++); + buf = g_strdup_printf ("Evolution-Tlacuache-%d-%ld-%u", + (int) getpid(), str_time, seqno++); ico->uid = buf; return TRUE; @@ -259,6 +336,8 @@ add_object (CalBackend *backend, iCalObject *ico) g_hash_table_insert (priv->object_hash, ico->uid, ico); + priv->dirty = TRUE; + switch (ico->type) { case ICAL_EVENT: priv->events = g_list_prepend (priv->events, ico); @@ -288,6 +367,8 @@ add_object (CalBackend *backend, iCalObject *ico) /* FIXME: gnomecal old code */ ico->last_mod = time (NULL); #endif + + save (backend); } /* Removes an object from the backend's hash and lists. Does not perform @@ -304,6 +385,8 @@ remove_object (CalBackend *backend, iCalObject *ico) g_assert (ico->uid != NULL); g_hash_table_remove (priv->object_hash, ico->uid); + priv->dirty = TRUE; + switch (ico->type) { case ICAL_EVENT: list = &priv->events; @@ -331,6 +414,7 @@ remove_object (CalBackend *backend, iCalObject *ico) g_list_free_1 (l); ical_object_destroy (ico); + save (backend); } /* Load a calendar from a VObject */ @@ -471,8 +555,8 @@ cal_destroy_cb (GtkObject *object, gpointer data) * @backend: A calendar backend. * @cal: A calendar client interface object. * - * Adds a calendar client interface object to a calendar @backend. The calendar - * backend must already have a loaded calendar. + * Adds a calendar client interface object to a calendar @backend. + * The calendar backend must already have a loaded calendar. **/ void cal_backend_add_cal (CalBackend *backend, Cal *cal) @@ -549,11 +633,11 @@ icalendar_calendar_load (CalBackend * cal, char* fname) if (ical->type != ICAL_EVENT && ical->type != ICAL_TODO && ical->type != ICAL_JOURNAL) { - g_warning ("Skipping unsupported iCalendar component."); + g_warning ("Skipping unsupported iCalendar component."); } else add_object (cal, ical); subcomp = icalcomponent_get_next_component (comp, - ICAL_ANY_COMPONENT); + ICAL_ANY_COMPONENT); } } @@ -614,7 +698,7 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) char *str_uri; g_return_val_if_fail (backend != NULL, CAL_BACKEND_LOAD_ERROR); - g_return_val_if_fail (IS_CAL_BACKEND (backend), CAL_BACKEND_LOAD_ERROR); + g_return_val_if_fail (IS_CAL_BACKEND (backend),CAL_BACKEND_LOAD_ERROR); priv = backend->priv; g_return_val_if_fail (!priv->loaded, CAL_BACKEND_LOAD_ERROR); @@ -626,12 +710,11 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) */ 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)); - + (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)); /* look at the extension on the filename and decide if this is a ical or vcal file */ @@ -650,7 +733,7 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri) load_from_vobject (backend, vobject); cleanVObject (vobject); cleanStrTbl (); - break; + break; case CAL_ICAL: icalendar_calendar_load (backend, str_uri); break; @@ -692,12 +775,16 @@ cal_backend_create (CalBackend *backend, GnomeVFSURI *uri) g_assert (priv->object_hash == NULL); priv->object_hash = g_hash_table_new (g_str_hash, g_str_equal); + priv->dirty = TRUE; + /* Done */ gnome_vfs_uri_ref (uri); priv->uri = uri; priv->loaded = TRUE; + + save (backend); } /** @@ -886,10 +973,12 @@ cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_t end) iCalObject *ico; ico = l->data; - ical_object_generate_events (ico, start, end, build_event_list, &c); + ical_object_generate_events (ico, start, end, + build_event_list, &c); } c.event_list = g_list_sort (c.event_list, compare_instance_func); + return c.event_list; } @@ -933,14 +1022,15 @@ notify_remove (CalBackend *backend, const char *uid) * @uid: Unique identifier of the object to update. * @calobj: String representation of the new calendar object. * - * Updates an object in a calendar backend. It will replace any existing object - * that has the same UID as the specified one. The backend will in turn notify - * all of its clients about the change. + * Updates an object in a calendar backend. It will replace any existing + * object that has the same UID as the specified one. The backend will in + * turn notify all of its clients about the change. * * Return value: TRUE on success, FALSE on being passed an invalid object. **/ gboolean -cal_backend_update_object (CalBackend *backend, const char *uid, const char *calobj) +cal_backend_update_object (CalBackend *backend, const char *uid, + const char *calobj) { CalBackendPrivate *priv; iCalObject *ico, *new_ico; @@ -1008,8 +1098,11 @@ cal_backend_remove_object (CalBackend *backend, const char *uid) remove_object (backend, ico); - /* FIXME: do the notification asynchronously */ + priv->dirty = TRUE; + save (backend); + /* FIXME: do the notification asynchronously */ notify_remove (backend, uid); + return TRUE; } |