diff options
author | Federico Mena Quintero <federico@src.gnome.org> | 2000-05-24 04:52:12 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2000-05-24 04:52:12 +0800 |
commit | 910e86eba685c2eddbd9ebd48b25391490d5f24b (patch) | |
tree | 4f9f9106343ce0f4615b333e18e329ce4b07a07d | |
parent | 46700211974920a7a79c82d2ad4420934d3e7266 (diff) | |
download | gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar.gz gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar.bz2 gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar.lz gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar.xz gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.tar.zst gsoc2013-evolution-910e86eba685c2eddbd9ebd48b25391490d5f24b.zip |
Commit for if my laptop dies - Federico
svn path=/trunk/; revision=3185
28 files changed, 1881 insertions, 4213 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 804605bd84..a79bb456e7 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,31 @@ +2000-05-22 Federico Mena Quintero <federico@helixcode.com> + + * gui/calendar-commands.c (calendar_get_events_in_range): Removed + function. + + * gui/mark.c (mark_month_item): Use + cal_client_get_events_in_range(). + + * gui/calendar-commands.c (show_year_view_clicked): Comment out, + since we don't have a year view. + + * gui/gnome-cal.c (setup_widgets): Removed the year view stuff. + (gnome_calendar_get_current_view_name): Likewise. + (gnome_calendar_update_view_times): Likewise. + (gnome_calendar_direction): Likewise. + (gnome_calendar_set_view): Likewise. + (gnome_calendar_update_all): Likewise. + (gnome_calendar_object_updated_cb): Likewise. + (gnome_calendar_object_removed_cb): Likewise. + (gnome_calendar_time_format_changed): Likewise. + (gnome_calendar_get_current_time_range): Likewise. + + * gui/gnome-cal.h (GnomeCalendar): Removed the year view stuff. + + * gui/Makefile.am (evolution_calendar_SOURCES): Added layout.[ch], + print.[ch]. Removed quick-view.[ch], year-view.[ch] since they + are no longer used. Removed all the old Pilot crap. + 2000-05-20 Damon Chaplin <damon@helixcode.com> * cal-util/cal-recur.[hc]: new files to implement iCalendar recurrence diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index c3971a9874..3e3e392c4f 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -2,13 +2,6 @@ SUBDIRS = dialogs help_base = $(datadir)/gnome/help/cal -#if HAVE_GNOME_PILOT -#extra_pilot_bins = \ -# calendar-conduit-control-applet \ -# calendar-pilot-sync -#endif - - CPPFLAGS = \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" @@ -43,6 +36,8 @@ bin_PROGRAMS = evolution-calendar evolution_calendar_SOURCES = \ alarm.c \ alarm.h \ + calendar-commands.c \ + calendar-commands.h \ e-day-view-main-item.c \ e-day-view-main-item.h \ e-day-view-time-item.c \ @@ -59,8 +54,11 @@ evolution_calendar_SOURCES = \ e-week-view-titles-item.h \ e-week-view.c \ e-week-view.h \ + event-editor.c \ + event-editor.h \ event-editor-utils.c \ event-editor-utils.h \ + evolution-calendar-control.c \ getdate.y \ gncal-todo.c \ gncal-todo.h \ @@ -69,27 +67,15 @@ evolution_calendar_SOURCES = \ gnome-cal.c \ gnome-cal.h \ goto.c \ + layout.c \ + layout.h \ mark.c \ mark.h \ popup-menu.c \ popup-menu.h \ - prop.c \ - quick-view.c \ - quick-view.h \ - todo-conduit.h \ - year-view.c \ - year-view.h \ - calendar-commands.c \ - calendar-commands.h \ - event-editor.c \ - event-editor.h \ - evolution-calendar-control.c - - -# eventedit.c \ -# eventedit.h \ - - + print.c \ + print.h \ + prop.c evolution_calendar_LDADD = \ $(EXTRA_GNOME_LIBS) \ @@ -108,98 +94,6 @@ gnorbadir = $(sysconfdir)/CORBA/servers gnorba_DATA = calendar-control.gnorba endif -#calendar_pilot_sync_SOURCES = \ -# GnomeCal-common.c \ -# GnomeCal-stubs.c \ -# alarm.c \ -# calendar-pilot-sync.c \ -# calendar.c \ -# calendar.h - - -#calendar_pilot_sync_LDADD = \ -# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ -# $(LINK_FLAGS) - -#if HAVE_GNOME_PILOT -##calendar_conduit -#calendar_conduitsdir=$(libdir)/gnome-pilot/conduits -# -#calendar_conduits_LTLIBRARIES = libcalendar_conduit.la -#endif - -#libcalendar_conduit_la_SOURCES = \ -# GnomeCal-common.c \ -# GnomeCal-stubs.c \ -# calendar-conduit.h \ -# calendar-conduit.c \ -# alarm.c \ -# calendar.c - -#libcalendar_conduit_la_LDFLAGS = \ -# -rpath $(libdir) - -#libcalendar_conduit_la_LIBADD = \ -# ../libversit/libversit.la \ -# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ -# $(GNOME_LIBDIR) \ -# $(GNOME_LIBS) - -#calendar_conduit_control_applet_SOURCES = \ -# calendar-conduit-control-applet.c - -#calendar_conduit_control_applet_LDADD = \ -# $(CAPPLET_LIBS) \ -# $(GNOME_LIBDIR) \ -# $(GNOME_CAPPLET_LIBS) \ -# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ -# $(GNOMEUI_LIBS) \ -# $(GNOME_PILOT_LIBS) \ -# $(INTLLIBS) - -#todo_conduit -#todo_conduitsdir=$(libdir)/gnome-pilot/conduits - -#todo_conduits_LTLIBRARIES = libtodo_conduit.la - -#libtodo_conduit_la_LDFLAGS = \ -# -rpath $(libdir) - -#libtodo_conduit_la_LIBADD = \ -# $(GNOME_LIBDIR) \ -# $(GNOME_LIBS) - -#libtodo_conduit_la_SOURCES = \ -# todo-conduit.c - -#todo-conduit.c: GnomeCal.h - -#todo_conduit_control_applet_SOURCES = \ -# todo-conduit-control-applet.c - -#todo_conduit_control_applet_LDADD = \ -# $(CAPPLET_LIBS) \ -# $(GNOME_LIBDIR) \ -# $(GNOME_CAPPLET_LIBS) \ -# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ -# $(GNOMEUI_LIBS) \ -# $(GNOME_PILOT_LIBS) \ -# $(INTLLIBS) - -#if HAVE_GNOME_PILOT -#ccenterdir = $(datadir)/control-center -#Rootdir = $(ccenterdir) -#PalmPilotdir = $(ccenterdir)/Peripherals/PalmPilot -#Conduitsdir = $(PalmPilotdir)/Conduits -# -#Conduits_DATA = \ -# calendar-conduit-control-applet.desktop -## todo-conduit-control-applet.desktop -# -#Conduits_seconddir = $(datadir)/gnome/apps/Settings/Peripherals/PalmPilot/Conduits/ -#Conduits_second_DATA = $(Conduits_DATA) -#endif - EXTRA_DIST = \ bell.xpm \ recur.xpm \ @@ -211,18 +105,8 @@ EXTRA_DIST = \ calendar-control.gnorba \ calendar-control.oafinfo -# gnome-calendar-conduit.png -# todo-conduit-control-applet.desktop -# $(idl_DATA) -# $(gnorba_DATA) -# calendar-conduit-control-applet.desktop - -#appicondir = $(datadir)/pixmaps -#appicon_DATA = gnome-calendar-conduit.png - install-data-local: $(mkinstalldirs) $(DESTDIR)$(help_base)/C -# $(mkinstalldirs) $(Conduitsdir) if ENABLE_PURIFY PLINK = $(LIBTOOL) --mode=link $(PURIFY) $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 3524c3d53b..5726f45362 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -325,9 +325,11 @@ show_month_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path static void show_year_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path) { +#if 0 GnomeCalendar *gcal = GNOME_CALENDAR (user_data); gnome_calendar_set_view (gcal, "yearview"); gtk_widget_grab_focus (gcal->year_view); +#endif } static void @@ -878,71 +880,3 @@ calendar_iterate_free_cache_entry (gpointer key, { ical_object_unref ((iCalObject*) value); } - - -static gint -calendar_object_compare_by_start (gconstpointer a, gconstpointer b) -{ - const CalendarObject *ca = a; - const CalendarObject *cb = b; - time_t diff; - - diff = ca->ev_start - cb->ev_start; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/* FIXME -- where should this (and calendar_object_compare_by_start) go? */ -/* FIXME -- for recurring events we should only load the iCalObject once. */ -/* returns a list of events in the form of CalendarObject* */ -GList* -calendar_get_events_in_range (CalClient *calc, - time_t start, time_t end) -{ - GList *l, *cois, *res = NULL; - CalObjFindStatus status; - CalObjInstance *coi; - char *uid, *obj_string; - iCalObject *ico; - CalendarObject *co; - - cois = cal_client_get_events_in_range (calc, start, end); - - for (l = cois; l; l = l->next) { - coi = l->data; - uid = coi->uid; - obj_string = cal_client_get_object (calc, uid); - - status = ical_object_find_in_string (uid, obj_string, &ico); - g_free (obj_string); - - switch (status){ - case CAL_OBJ_FIND_SUCCESS: - co = g_new (CalendarObject, 1); - co->ev_start = coi->start; - co->ev_end = coi->end; - co->ico = ico; - - res = g_list_prepend (res, co); - break; - case CAL_OBJ_FIND_SYNTAX_ERROR: - printf ("calendar_get_events_in_range: " - "syntax error uid=%s\n", uid); - break; - case CAL_OBJ_FIND_NOT_FOUND: - printf ("calendar_get_events_in_range: " - "obj not found uid=%s\n", uid); - break; - } - - g_free (uid); - g_free (coi); - } - - g_list_free (cois); - - /* Sort the list here, since it is more efficient to sort it once - rather doing lots of sorted insertions. */ - res = g_list_sort (res, calendar_object_compare_by_start); - - return res; -} diff --git a/calendar/gui/calendar-commands.h b/calendar/gui/calendar-commands.h index 50cc2b85b6..a3e5f5393c 100644 --- a/calendar/gui/calendar-commands.h +++ b/calendar/gui/calendar-commands.h @@ -106,17 +106,6 @@ void calendar_set_uri (GnomeCalendar *gcal, char *calendar_file); /* FIXME -- where should this stuff go? */ /*----------------------------------------------------------------------*/ -/* This is only used by the calendar_get_events_in_range routine to get - * a list of objects that recur on a specific date - */ -typedef struct { - time_t ev_start; - time_t ev_end; - iCalObject *ico; -} CalendarObject; - -GList *calendar_get_events_in_range (CalClient *calc, - time_t start, time_t end); void calendar_iterate (GnomeCalendar *cal, time_t start, time_t end, diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c deleted file mode 100644 index 74c8ddaab9..0000000000 --- a/calendar/gui/calendar.c +++ /dev/null @@ -1,668 +0,0 @@ -/* - * Calendar manager object - * - * This keeps track of a given calendar. Eventually this will abtract everything - * related to getting calendars/saving calendars locally or to a remote Calendar Service - * - * Copyright (C) 1998, 1999 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (quartic@gimp.org) - * - */ - -#include <gnome.h> -#include <stdio.h> -#include <config.h> -#include <unistd.h> -#include <sys/stat.h> -#include <cal-util/timeutil.h> -#include "calendar.h" -#include "alarm.h" -#include "libversit/vcc.h" - -#ifdef HAVE_TZNAME -extern char *tzname[2]; -#endif - -/* Our day range */ -time_t calendar_day_begin, calendar_day_end; - -static void calendar_init_alarms (Calendar *cal); -static void calendar_set_day (void); - -Calendar * -calendar_new (char *title,CalendarNewOptions options) -{ - Calendar *cal; - - cal = g_new0 (Calendar, 1); - - cal->title = g_strdup (title); - -#if 0 - if (options & CALENDAR_USE_ICAL) - cal->format = CAL_ICAL; - else - cal->format = CAL_VCAL; -#endif - - if ((calendar_day_begin == 0) || (calendar_day_end == 0)) - calendar_set_day (); - - cal->event_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (options & CALENDAR_INIT_ALARMS) { - calendar_init_alarms (cal); - } - - return cal; -} - -static void -try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end) -{ - alarm->trigger = start-alarm->offset; - - if (alarm->trigger < calendar_day_begin) - return; - if (alarm->trigger > calendar_day_end) - return; - alarm_add (alarm, &calendar_notify, ico); -} - -static int -add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure) -{ - if (obj->aalarm.enabled) - try_add (obj, &obj->aalarm, start, end); - if (obj->dalarm.enabled) - try_add (obj, &obj->dalarm, start, end); - if (obj->palarm.enabled) - try_add (obj,&obj->palarm, start, end); - if (obj->malarm.enabled) - try_add (obj, &obj->malarm, start, end); - - return TRUE; -} - -#define max(a,b) ((a > b) ? a : b) - -static void -ical_object_try_alarms (iCalObject *obj) -{ - int ao, po, od, mo; - int max_o; - - ao = alarm_compute_offset (&obj->aalarm); - po = alarm_compute_offset (&obj->palarm); - od = alarm_compute_offset (&obj->dalarm); - mo = alarm_compute_offset (&obj->malarm); - - max_o = max (ao, max (po, max (od, mo))); - if (max_o == -1) - return; - - ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj); -} - -void -calendar_add_object (Calendar *cal, iCalObject *obj) -{ - g_return_if_fail (cal != NULL); - g_return_if_fail (obj != NULL); - g_return_if_fail (obj->uid != NULL); - - obj->new = 0; - switch (obj->type){ - case ICAL_EVENT: - g_hash_table_insert (cal->event_hash, obj->uid, obj); - cal->events = g_list_prepend (cal->events, obj); - ical_object_try_alarms (obj); -#ifdef DEBUGGING_MAIL_ALARM - obj->malarm.trigger = 0; - calendar_notify (0, obj); -#endif - break; - - case ICAL_TODO: - cal->todo = g_list_prepend (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_prepend (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - if (!obj->uid){ - char buffer [80]; - - snprintf (buffer, sizeof (buffer), "GnomeCalendar-%ld\n", time (NULL)); - obj->uid = g_strdup (buffer); - } - - cal->modified = TRUE; - - obj->last_mod = time (NULL); -} - -void -calendar_remove_object (Calendar *cal, iCalObject *obj) -{ - switch (obj->type){ - case ICAL_EVENT: - cal->events = g_list_remove (cal->events, obj); - g_hash_table_remove (cal->event_hash, obj->uid); - break; - - case ICAL_TODO: - cal->todo = g_list_remove (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_remove (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - cal->modified = TRUE; -} - -void -calendar_destroy (Calendar *cal) -{ - g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->events); - - g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->todo); - - g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->journal); - - g_hash_table_destroy (cal->event_hash); - - if (cal->title) - g_free (cal->title); - if (cal->filename) - g_free (cal->filename); - - g_free (cal); -} - -void -calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure) -{ - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - ical_object_generate_events (object, start, end, cb, closure); - } -} - -void -calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure) -{ - calendar_iterate_on_objects (cal->events, start, end, cb, closure); -} - -GList * -calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func) -{ - GList *new_events = 0; - - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - if ((start <= object->dtstart) && (object->dtend <= end)){ - if (sort_func) - new_events = g_list_insert_sorted (new_events, object, sort_func); - else - new_events = g_list_prepend (new_events, object); - } - } - - /* Put the list in increasing order if no sort function was specified */ - - if (!sort_func) - new_events = g_list_reverse (new_events); - - return new_events; -} - -GList * -calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->todo, start, end, sort_func); -} - -GList * -calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->journal, start, end, sort_func); -} - -gint -calendar_compare_by_dtstart (gpointer a, gpointer b) -{ - iCalObject *obj1, *obj2; - time_t diff; - - obj1 = a; - obj2 = b; - - diff = obj1->dtstart - obj2->dtstart; - - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -#define str_val(obj) (char *) vObjectUStringZValue (obj) - -/* Loads our calendar contents from a vObject */ -void -calendar_load_from_vobject (Calendar *cal, VObject *vcal) -{ - VObjectIterator i; - - initPropIterator (&i, vcal); - - while (moreIteration (&i)){ - VObject *this = nextVObject (&i); - iCalObject *ical; - const char *object_name = vObjectName (this); - - if (strcmp (object_name, VCDCreatedProp) == 0){ - cal->created = time_from_isodate (str_val (this)); - continue; - } - - if (strcmp (object_name, VCLocationProp) == 0) - continue; /* FIXME: imlement */ - - if (strcmp (object_name, VCProdIdProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCVersionProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCTimeZoneProp) == 0) - continue; /* FIXME: implement */ - - ical = ical_object_create_from_vobject (this, object_name); - - if (ical) - calendar_add_object (cal, ical); - } -} - -static void -calendar_set_day (void) -{ - time_t calendar_today; - - calendar_today = time (NULL); - calendar_day_begin = time_day_begin (calendar_today); - calendar_day_end = time_day_end (calendar_today); -} - -/* Loads a calendar from a file */ -char * -calendar_load (Calendar *cal, char *fname) -{ - VObject *vcal; - struct stat s; - - if (cal->filename){ - g_warning ("Calendar load called again\n"); - return "Internal error"; - } - - cal->filename = g_strdup (fname); - - stat (fname, &s); - cal->file_time = s.st_mtime; - - calendar_set_day (); -#if 0 - switch (cal->format) { - case CAL_VCAL: -#endif - vcal = Parse_MIME_FromFileName (fname); - if (!vcal) - return "Could not load the calendar"; - calendar_load_from_vobject (cal, vcal); - cleanVObject (vcal); - cleanStrTbl (); -#if 0 - break; - /* - case CAL_ICAL: - icalendar_calendar_load (cal, fname); - break; - */ - default: - return "Unknown calendar format"; - } -#endif - - return NULL; -} - -/* - * calendar_load_from_memory: - * @cal: calendar on which we load the information - * @buffer: A buffer that contains a vCalendar file - * - * Loads the information from the vCalendar information in @buffer - * into the Calendar - */ -char * -calendar_load_from_memory (Calendar *cal, const char *buffer) -{ - VObject *vcal; - - g_return_val_if_fail (buffer != NULL, NULL); - - cal->filename = g_strdup ("memory-based-calendar"); - vcal = Parse_MIME (buffer, strlen (buffer)); - if (!vcal) - return "Could not load the calendar"; - - cal->file_time = time (NULL); - calendar_load_from_vobject (cal, vcal); - cleanVObject (vcal); - cleanStrTbl (); - - return NULL; -} - -static VObject * -vcalendar_create_from_calendar (Calendar *cal) -{ - VObject *vcal; - GList *l; - time_t now = time (NULL); - struct tm tm; - - /* WE call localtime for the side effect of setting tzname */ - tm = *localtime (&now); - - vcal = newVObject (VCCalProp); - addPropValue (vcal, VCProdIdProp, "-//GNOME//NONSGML GnomeCalendar//EN"); -#if defined(HAVE_TM_ZONE) - addPropValue (vcal, VCTimeZoneProp, tm.tm_zone); -#elif defined(HAVE_TZNAME) - addPropValue (vcal, VCTimeZoneProp, tzname[0]); -#endif - addPropValue (vcal, VCVersionProp, VERSION); - cal->temp = vcal; - - /* Events */ - - for (l = cal->events; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - /* To-do entries */ - - for (l = cal->todo; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - return vcal; -} - -void -calendar_save (Calendar *cal, char *fname) -{ - VObject *vcal; - FILE *fp; - GtkWidget *dlg; - struct stat s; - int status; - - if (fname == NULL) - fname = cal->filename; - - vcal = vcalendar_create_from_calendar (cal); - 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) { - writeVObject(fp, vcal); - fclose(fp); - if (strcmp(cal->filename, fname)) { - if (cal->filename) - g_free (cal->filename); - cal->filename = g_strdup (fname); - } - status = stat (fname, &s); - cal->file_time = s.st_mtime; - } else { - dlg = gnome_message_box_new(_("Failed to save calendar!"), - GNOME_MESSAGE_BOX_ERROR, "Ok", NULL); - gtk_widget_show(dlg); - } - - cleanVObject (vcal); - cleanStrTbl (); -} - -char * -calendar_get_as_vcal_string (Calendar *cal) -{ - VObject *vcal; - char *result; - - g_return_val_if_fail (cal != NULL, NULL); - - vcal = vcalendar_create_from_calendar (cal); - result = writeMemVObject (NULL, 0, vcal); - - cleanVObject (vcal); - cleanStrTbl (); - - return result; -} - -static gint -calendar_object_compare_by_start (gconstpointer a, gconstpointer b) -{ - const CalendarObject *ca = a; - const CalendarObject *cb = b; - time_t diff; - - diff = ca->ev_start - cb->ev_start; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -static int -assemble_event_list (iCalObject *obj, time_t start, time_t end, void *c) -{ - CalendarObject *co; - GList **l = c; - - co = g_new (CalendarObject, 1); - - co->ev_start = start; - co->ev_end = end; - co->ico = obj; - *l = g_list_insert_sorted (*l, co, calendar_object_compare_by_start); - - return 1; -} - -void -calendar_destroy_event_list (GList *l) -{ - GList *p; - - for (p = l; p; p = p->next) - g_free (p->data); - g_list_free (l); -} - -GList * -calendar_get_events_in_range (Calendar *cal, time_t start, time_t end) -{ - GList *l = 0; - - calendar_iterate (cal, start, end, assemble_event_list, &l); - return l; -} - -void -calendar_object_changed (Calendar *cal, iCalObject *obj, int flags) -{ - obj->last_mod = time (NULL); - obj->pilot_status = ICAL_PILOT_SYNC_MOD; - - if (!(flags & CHANGE_DATES)) - return; - - /* Remove any alarms on the alarm list for this object */ - while (alarm_kill (obj)) - ; - - ical_object_try_alarms (obj); -} - -static void -calendar_day_change (time_t time, CalendarAlarm *which, void *closure) -{ - GList *events; - Calendar *cal = closure; - - calendar_set_day (); - calendar_init_alarms (cal); - - for (events = cal->events; events; events = events->next){ - iCalObject *obj = events->data; - - ical_object_try_alarms (obj); - } -} - -static void -calendar_init_alarms (Calendar *cal) -{ - CalendarAlarm day_change_alarm; - - day_change_alarm.trigger = calendar_day_end; - alarm_add (&day_change_alarm, calendar_day_change, cal); -} - -static iCalObject * -calendar_object_find_in_list (Calendar *cal, GList *list, const char *uid) -{ - GList *l; - - for (l = list; l; l = l->next){ - iCalObject *obj = l->data; - - if (strcmp (obj->uid, uid) == 0) - return obj; - } - - return NULL; -} - -iCalObject * -calendar_object_find_event (Calendar *cal, const char *uid) -{ - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - return g_hash_table_lookup (cal->event_hash, uid); -} - -iCalObject * -calendar_object_find_todo (Calendar *cal, const char *uid) -{ - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - return calendar_object_find_in_list (cal, cal->todo, uid); -} - -iCalObject * -calendar_object_find (Calendar *cal, const char *uid) -{ - iCalObject *obj; - - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - obj = calendar_object_find_in_list (cal, cal->todo, uid); - - if (obj == NULL) - obj = calendar_object_find_in_list (cal, cal->events, uid); - - return obj; -} - -iCalObject * -calendar_object_find_by_pilot (Calendar *cal, int pilot_id) -{ - GList *l; - - g_return_val_if_fail (cal != NULL, NULL); - - for (l = cal->events; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_id == pilot_id) - return obj; - } - - for (l = cal->todo; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_id == pilot_id) - return obj; - } - - return NULL; -} - -/* - * calendar_string_from_object: - * - * Returns the iCalObject @object armored around a vCalendar - * object as a string. - */ -char * -calendar_string_from_object (iCalObject *object) -{ - Calendar *cal; - char *str; - - g_return_val_if_fail (object != NULL, NULL); - - cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); - calendar_add_object (cal, object); - str = calendar_get_as_vcal_string (cal); - calendar_remove_object (cal, object); - - calendar_destroy (cal); - - return str; -} diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h deleted file mode 100644 index 27223b4f67..0000000000 --- a/calendar/gui/calendar.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef CALENDAR_H -#define CALENDAR_H - -#include "cal-util/calobj.h" - -BEGIN_GNOME_DECLS - -typedef struct { - /* This calendar's title */ - char *title; - - /* backing store for this calendar object */ - char *filename; - - /* The list of events; todo's and journal entries */ - GList *events; - GList *todo; - GList *journal; - GList *timezones; /* required for iCalendar */ - - GHashTable *event_hash; - - /* Time at which the calendar was created */ - time_t created; - - /* Timestamp in the filename */ - time_t file_time; - - /* If the calendar was last modified */ - int modified; - void *temp; - - void *corba_server; -} Calendar; - -/* This is only used by the calendar_get_events_in_range routine to get - * a list of objects that recur on a specific date - */ -typedef struct { - time_t ev_start; - time_t ev_end; - iCalObject *ico; -} CalendarObject; - -typedef enum { - CALENDAR_INIT_NIL = 0, - CALENDAR_INIT_ALARMS = 1 << 0, - CALENDAR_USE_ICAL = 1 << 1 -} CalendarNewOptions; - -Calendar *calendar_new (char *title,CalendarNewOptions options); -char *calendar_get_as_vcal_string (Calendar *cal); -char *calendar_string_from_object (iCalObject *object); - -char *calendar_load (Calendar *cal, char *fname); -char *calendar_load_from_memory (Calendar *cal, const char *buffer); -void calendar_load_from_vobject (Calendar *cal, VObject *vcal); -void calendar_save (Calendar *cal, char *fname); -void calendar_add_object (Calendar *cal, iCalObject *obj); -void calendar_remove_object (Calendar *cal, iCalObject *obj); -void calendar_destroy (Calendar *cal); -GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -gint calendar_compare_by_dtstart (gpointer a, gpointer b); - -void calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure); -void calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure); - -/* Returns a list of CalendarObject structures. These represent the events in the calendar that are - * in the specified range. - */ -GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end); - -/* Destroy list returned by calendar_get_events_in_range() with this function */ -void calendar_destroy_event_list (GList *l); - -/* Informs the calendar that obj information has changed */ -void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags); - -void calendar_notify (time_t time, CalendarAlarm *which, void *data); - -iCalObject *calendar_object_find_event (Calendar *cal, const char *uid); -iCalObject *calendar_object_find_todo (Calendar *cal, const char *uid); -iCalObject *calendar_object_find (Calendar *cal, const char *uid); -iCalObject *calendar_object_find_by_pilot (Calendar *cal, int pilot_id); - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/corba-cal-factory.c b/calendar/gui/corba-cal-factory.c deleted file mode 100644 index 07a7008db0..0000000000 --- a/calendar/gui/corba-cal-factory.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * corba-cal-factory.c: Service that provides access to the calendar repositories. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ - -#include <config.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/stat.h> -#include "gnome-cal.h" -#include "calendar-commands.h" -#include <cal-util/timeutil.h> -#include "libversit/vcc.h" -#include <libgnorba/gnorba.h> -#include <bonobo.h> -#include "GnomeCal.h" -#include "corba-cal-factory.h" -#include "corba-cal.h" - -CORBA_ORB orb; -PortableServer_POA poa; -PortableServer_POAManager poa_manager; - -static POA_Bonobo_GenericFactory__epv calendar_epv; -static POA_Bonobo_GenericFactory__vepv calendar_vepv; - -/* - * Servant and Object Factory - */ -static POA_Bonobo_GenericFactory calendar_servant; -static Bonobo_GenericFactory calendar_factory; - -static CORBA_boolean -calendar_supports (PortableServer_Servant servant, - CORBA_char * obj_goad_id, - CORBA_Environment * ev) -{ - if (strcmp (obj_goad_id, "IDL:GNOME:Calendar:Repository:1.0") == 0) - return CORBA_TRUE; - else - return CORBA_FALSE; -} - -static CORBA_Object -calendar_create_object (PortableServer_Servant servant, - CORBA_char *goad_id, - const GNOME_stringlist *params, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal; - struct stat s; - char *name; - - if (params->_length == 1) - name = params->_buffer [0]; - else - name = NULL; - - if (strcmp (goad_id, "IDL:GNOME:Calendar:Repository:1.0") != 0){ - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_GenericFactory_CannotActivate, - NULL); - return CORBA_OBJECT_NIL; - } - - gcal = gnome_calendar_locate (name); - if (gcal != NULL) - return CORBA_Object_duplicate (gcal->calc->corba_server, ev); - - if (stat (name, &s) != 0){ - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_GenericFactory_CannotActivate, - NULL); - return CORBA_OBJECT_NIL; - } - - gcal = new_calendar ("", name, NULL, NULL, FALSE); - - return CORBA_Object_duplicate (gcal->calc->corba_server, ev); -} - -void -init_corba_server (void) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - poa_manager = PortableServer_POA__get_the_POAManager (poa, &ev); - if (ev._major != CORBA_NO_EXCEPTION){ - g_warning ("Can not get the POA manager"); - CORBA_exception_free (&ev); - return; - } - - PortableServer_POAManager_activate (poa_manager, &ev); - - /* First create the locator for the repositories as a factory object */ - calendar_vepv.Bonobo_GenericFactory_epv = &calendar_epv; - calendar_epv.supports = calendar_supports; - calendar_epv.create_object = calendar_create_object; - - calendar_servant.vepv = &calendar_vepv; - POA_Bonobo_GenericFactory__init ((PortableServer_Servant) &calendar_servant, &ev); - CORBA_free (PortableServer_POA_activate_object ( - poa, (PortableServer_Servant)&calendar_servant, &ev)); - - calendar_factory = PortableServer_POA_servant_to_reference ( - poa, (PortableServer_Servant) &calendar_servant, &ev); - - goad_server_register ( - CORBA_OBJECT_NIL, calendar_factory, - "IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev); - CORBA_exception_free (&ev); -} - -void -unregister_calendar_services (void) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - goad_server_unregister ( - CORBA_OBJECT_NIL, - "IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev); - CORBA_exception_free (&ev); -} diff --git a/calendar/gui/corba-cal-factory.h b/calendar/gui/corba-cal-factory.h deleted file mode 100644 index 096baef012..0000000000 --- a/calendar/gui/corba-cal-factory.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _CORBA_CAL_FACTORY_H_ -#define _CORBA_CAL_FACTORY_H_ - -/* The CORBA globals */ -CORBA_ORB orb; -PortableServer_POA poa; - -void init_corba_server (void); -void unregister_calendar_services (void); - -#endif /* _CORBA_CAL_FACTORY_H_ */ diff --git a/calendar/gui/corba-cal.c b/calendar/gui/corba-cal.c deleted file mode 100644 index 72fd3bac1f..0000000000 --- a/calendar/gui/corba-cal.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - * corba-cal.c: Service that provides access to the calendar repository - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ - -#include <config.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/stat.h> -/*#include "calendar.h" DELETE */ -#include "gnome-cal.h" -#include "alarm.h" -#include <cal-util/timeutil.h> -#include "libversit/vcc.h" -#include <libgnorba/gnome-factory.h> -#include "GnomeCal.h" -#include "corba-cal-factory.h" -#include "corba-cal.h" - -static iCalObject * -calendar_object_find_by_pilot (GnomeCalendar *cal, int pilot_id); - - -typedef struct { - POA_GNOME_Calendar_Repository servant; - GnomeCalendar *calendar; -} CalendarServant; - -/* - * Vectors - */ -static POA_GNOME_Calendar_Repository__epv calendar_repository_epv; -static POA_GNOME_Calendar_Repository__vepv calendar_repository_vepv; - -/* - * Servant and Object Factory - */ -static POA_GNOME_Calendar_Repository calendar_repository_servant; - -static inline GnomeCalendar * -gnomecal_from_servant (PortableServer_Servant servant) -{ - CalendarServant *cs = (CalendarServant *) servant; - - return cs->calendar; -} - -static CORBA_char * -cal_repo_get_object (PortableServer_Servant servant, - const CORBA_char *uid, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *obj_string; - char *buffer; - CORBA_char *ret; - - /*obj = calendar_object_find_event (gcal->cal, uid); DELETE */ - obj_string = cal_client_get_object (gcal->calc, uid); - obj = string_to_ical_object (obj_string); - free (obj_string); - - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set ( - ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, - exn); - return NULL; - } - - /* buffer = calendar_string_from_object (obj); DELETE */ - buffer = ical_object_to_string (obj); - ret = CORBA_string_dup (buffer); - free (buffer); - - return ret; -} - - - -static CORBA_char * -cal_repo_get_object_by_pilot_id (PortableServer_Servant servant, - CORBA_long pilot_id, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *buffer; - CORBA_char *ret; - - obj = calendar_object_find_by_pilot (gcal, pilot_id); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, exn); - return NULL; - } - - /* buffer = calendar_string_from_object (obj); DELETE */ - buffer = ical_object_to_string (obj); - ret = CORBA_string_dup (buffer); - free (buffer); - - return ret; - -} - -/* where should this go? FIX ME */ -static iCalObject * -calendar_object_find_by_pilot (GnomeCalendar *cal, int pilot_id) -{ - GList *l, *uids; - - g_return_val_if_fail (cal != NULL, NULL); - - uids = cal_client_get_uids (cal->calc, CALOBJ_TYPE_ANY); - for (l = uids; l; l = l->next){ - char *obj_string = cal_client_get_object (cal->calc, l->data); - iCalObject *obj = string_to_ical_object (obj_string); - g_free (obj_string); - - if (obj->pilot_id == pilot_id) - return obj; - } - - /* DELETE - for (l = cal->todo; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_id == pilot_id) - return obj; - } - */ - - return NULL; -} - -static CORBA_char * -cal_repo_get_id_from_pilot_id (PortableServer_Servant servant, - CORBA_long pilot_id, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - - obj = calendar_object_find_by_pilot (gcal, pilot_id); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, exn); - return NULL; - } - - return CORBA_string_dup (obj->uid); -} - -static void -cal_repo_delete_object (PortableServer_Servant servant, - const CORBA_char *uid, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *obj_string; - - /* obj = calendar_object_find_event (gcal->cal, uid); */ - obj_string = cal_client_get_object (gcal->calc, uid); - obj = string_to_ical_object (obj_string); - free (obj_string); - - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, - exn); - return; - } - - gnome_calendar_remove_object (gcal, obj); -} - -static void -cal_repo_update_object (PortableServer_Servant servant, - const CORBA_char *uid, - const CORBA_char *vcalendar_object, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - /* iCalObject *obj; char *obj_string; */ - iCalObject *new_object; - char *new_object_string; - - new_object = ical_object_new_from_string (vcalendar_object); - -#if 0 /* it looks like this is taken care of in cal_client_update_object? */ - /* DELETE */ - /* obj = calendar_object_find_event (gcal->cal, uid); DELETE */ - obj_string = cal_client_get_object (gcal->calc, uid); - obj = string_to_ical_object (obj_string); - free (obj_string); - - if (obj != NULL){ - /* calendar_remove_object (gcal->cal, obj); DELETE */ - cal_client_remove_object (gcal->calc, uid); - } -#endif /* 0 */ - - /* calendar_add_object (gcal->cal, new_object); DELETE */ - new_object_string = ical_object_to_string (new_object); - cal_client_update_object (gcal->calc, uid, new_object_string); - free (new_object_string); -} - -static void -cal_repo_update_pilot_id (PortableServer_Servant servant, - const CORBA_char *uid, - const CORBA_long pilot_id, - const CORBA_long pilot_status, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *obj_string; - - /* obj = calendar_object_find_event (gcal->cal, uid); DELETE */ - obj_string = cal_client_get_object (gcal->calc, uid); - obj = string_to_ical_object (obj_string); - free (obj_string); - - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set ( - ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, - exn); - return; - } - - obj->pilot_id = pilot_id; - obj->pilot_status = pilot_status; -} - - -static void list_free_string (gpointer data, gpointer user_data) -{ - free (data); -} - - -static CORBA_long -cal_repo_get_number_of_objects (PortableServer_Servant servant, - GNOME_Calendar_Repository_RecordStatus record_status, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - CORBA_long res; - iCalPilotState real_record_status; - GList *l, *uids; - - if (record_status == GNOME_Calendar_Repository_ANY) { - /* return g_list_length(gcal->cal->events); DELETE */ - GList *uids = cal_client_get_uids (gcal->calc, - CALOBJ_TYPE_EVENT); - res = g_list_length (uids); - g_list_foreach (uids, list_free_string, NULL); - g_list_free (uids); - return res; - } - - switch (record_status) { - case GNOME_Calendar_Repository_NEW: - real_record_status = ICAL_PILOT_SYNC_MOD; - break; - case GNOME_Calendar_Repository_MODIFIED: - real_record_status = ICAL_PILOT_SYNC_MOD; - break; - case GNOME_Calendar_Repository_DELETED: - real_record_status = ICAL_PILOT_SYNC_DEL; - break; - } - - res = 0; - - uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT); - for (l = uids; l; l = l->next){ - char *obj_string = cal_client_get_object (gcal->calc, l->data); - iCalObject *obj = string_to_ical_object (obj_string); - - if (obj->pilot_status == real_record_status) - res ++; - g_free (l->data); - } - g_list_free (uids); - - return res; -} - -static GNOME_Calendar_Repository_String_Sequence* -cal_repo_get_object_id_list(PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - GList *l, *uids; - GNOME_Calendar_Repository_String_Sequence *result; - int counter; - - uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT); - - result = GNOME_Calendar_Repository_String_Sequence__alloc(); - result->_length = g_list_length (uids); - result->_buffer = - CORBA_sequence_CORBA_string_allocbuf(result->_length); - - counter = 0; - for (l = uids; l; l = l->next){ - result->_buffer[counter] = CORBA_string_dup(l->data); - counter++; - g_free (l->data); - } - g_list_free (uids); - - return result; -} - -static CORBA_char * -cal_repo_get_updated_objects (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - /* FIX ME -- this might be wrong */ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - /* Calendar *dirty_cal; DELETE */ - VObject *vcalobj, *vobj; - GList *l, *uids; - CORBA_char *res; - char *str; - - /* dirty_cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); DELETE */ - vcalobj = newVObject (VCCalProp); - - uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT); - for (l = uids; l; l = l->next){ - char *obj_string = cal_client_get_object (gcal->calc, l->data); - iCalObject *obj = string_to_ical_object (obj_string); - - if (obj->pilot_status != ICAL_PILOT_SYNC_MOD) - continue; - - /* calendar_add_object (dirty_cal, obj); DELETE */ - vobj = ical_object_to_vobject (obj); - addVObjectProp (vcalobj, vobj); - g_free (l->data); - } - g_list_free (uids); - -# if 0 - /* DELETE */ - str = calendar_get_as_vcal_string (dirty_cal); - res = CORBA_string_dup (str); - free (str); /* calendar_get_as_vcal_string() uses writeMemVObject(), which uses realloc() */ - calendar_destroy (dirty_cal); -# endif /* 0 */ - - str = writeMemVObject (NULL, NULL, vcalobj); - res = CORBA_string_dup (str); - free (str); /* calendar_get_as_vcal_string() uses writeMemVObject(), - which uses realloc() */ - cleanVObject (vcalobj); - cleanStrTbl (); - - return res; -} - -static void -cal_repo_done (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - /* GnomeCalendar *gcal = gnomecal_from_servant (servant); */ - - /* calendar_save (gcal->cal, NULL); DELETE */ - /* FIX ME -- i dont know what to do here */ -} - -static void -init_calendar_repo_class (void) -{ - calendar_repository_epv.get_object = cal_repo_get_object; - calendar_repository_epv.get_object_by_pilot_id = cal_repo_get_object_by_pilot_id; - calendar_repository_epv.get_id_from_pilot_id = cal_repo_get_id_from_pilot_id; - calendar_repository_epv.delete_object = cal_repo_delete_object; - calendar_repository_epv.update_object = cal_repo_update_object; - calendar_repository_epv.get_number_of_objects = cal_repo_get_number_of_objects; - calendar_repository_epv.get_updated_objects = cal_repo_get_updated_objects; - calendar_repository_epv.update_pilot_id = cal_repo_update_pilot_id; - calendar_repository_epv.get_object_id_list = cal_repo_get_object_id_list; - calendar_repository_epv.done = cal_repo_done; - - calendar_repository_vepv.GNOME_Calendar_Repository_epv = - &calendar_repository_epv; - - calendar_repository_servant.vepv = &calendar_repository_vepv; -} - -/* - * Initializes the CORBA parts of the @calendar object - */ -void -gnome_calendar_create_corba_server (GnomeCalendar *calendar) -{ - static gboolean class_inited = FALSE; - CalendarServant *calendar_servant; - CORBA_Environment ev; - - if (!class_inited){ - init_calendar_repo_class (); - class_inited = TRUE; - } - - calendar_servant = g_new0 (CalendarServant, 1); - calendar_servant->servant.vepv = &calendar_repository_vepv; - calendar_servant->calendar = calendar; - - CORBA_exception_init (&ev); - POA_GNOME_Calendar_Repository__init ((PortableServer_Servant) calendar_servant, &ev); - CORBA_free ( - PortableServer_POA_activate_object (poa, calendar_servant, &ev)); - calendar->calc->corba_server = - PortableServer_POA_servant_to_reference (poa, calendar_servant, &ev); - - CORBA_exception_free (&ev); -} diff --git a/calendar/gui/corba-cal.h b/calendar/gui/corba-cal.h deleted file mode 100644 index 47caacba70..0000000000 --- a/calendar/gui/corba-cal.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _CORBA_CAL_H_ -#define _CORBA_CAL_H_ - -void gnome_calendar_create_corba_server (GnomeCalendar *calendar); - -#endif /* _CORBA_CAL_H_ */ diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 2f339fbebd..f189d5a124 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -27,7 +27,6 @@ #include "eventedit.h" #include "gncal-todo.h" #include "gnome-cal.h" -#include "year-view.h" #include "calendar-commands.h" @@ -227,23 +226,6 @@ setup_widgets (GnomeCalendar *gcal) gtk_widget_show (gcal->month_view); gtk_notebook_append_page (GTK_NOTEBOOK (gcal->main_notebook), gcal->month_view, gtk_label_new ("")); - - /* The Year View. */ - gcal->year_view = year_view_new (gcal, gcal->selection_start_time); -#if 0 - gtk_widget_show (gcal->year_view); -#endif - gcal->year_view_sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (gcal->year_view_sw); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (gcal->year_view_sw), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (gcal->year_view_sw), - gcal->year_view); - GTK_LAYOUT (gcal->year_view)->vadjustment->step_increment = 10.0; - gtk_adjustment_changed (GTK_LAYOUT (gcal->year_view)->vadjustment); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->main_notebook), - gcal->year_view_sw, gtk_label_new ("")); } static GtkWidget * @@ -276,8 +258,6 @@ gnome_calendar_get_current_view_name (GnomeCalendar *gcal) return "weekview"; else if (page == gcal->month_view) return "monthview"; - else if (page == gcal->year_view_sw) - return "yearview"; else return "dayview"; } @@ -314,9 +294,6 @@ gnome_calendar_update_view_times (GnomeCalendar *gcal, e_week_view_set_selected_time_range (E_WEEK_VIEW (page), gcal->selection_start_time, gcal->selection_end_time); - else if (page == gcal->year_view_sw) - year_view_set (YEAR_VIEW (gcal->year_view), - gcal->selection_start_time); else { g_warning ("My penguin is gone!"); g_assert_not_reached (); @@ -339,8 +316,6 @@ gnome_calendar_direction (GnomeCalendar *gcal, int direction) new_time = time_add_week (current_time, direction); else if (cp == gcal->month_view) new_time = time_add_month (current_time, direction); - else if (cp == gcal->year_view_sw) - new_time = time_add_year (current_time, direction); else { g_warning ("Weee! Where did the penguin go?"); g_assert_not_reached (); @@ -412,9 +387,6 @@ gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name) } else if (strcmp (page_name, "monthview") == 0) { page = gcal->month_view; main_page = 1; - } else if (strcmp (page_name, "yearview") == 0) { - page = gcal->year_view_sw; - main_page = 2; } else { g_warning ("Unknown calendar view: %s", page_name); return; @@ -819,10 +791,6 @@ gnome_calendar_update_all (GnomeCalendar *cal) e_week_view_update_all_events (E_WEEK_VIEW (cal->week_view)); e_week_view_update_all_events (E_WEEK_VIEW (cal->month_view)); -#if 0 - year_view_update (YEAR_VIEW (cal->year_view), NULL, TRUE); -#endif - gncal_todo_update (GNCAL_TODO (cal->todo), NULL, TRUE); gnome_calendar_tag_calendar (cal, cal->gtk_calendar); } @@ -897,11 +865,6 @@ gnome_calendar_object_updated_cb (GtkWidget *cal_client, e_week_view_update_event (E_WEEK_VIEW (gcal->week_view), uid); e_week_view_update_event (E_WEEK_VIEW (gcal->month_view), uid); - /* FIXME: optimize these? */ -#if 0 - year_view_update (YEAR_VIEW (gcal->year_view), NULL, TRUE); -#endif - gncal_todo_update (GNCAL_TODO (gcal->todo), NULL, TRUE); gnome_calendar_tag_calendar (gcal, gcal->gtk_calendar); } @@ -922,10 +885,6 @@ gnome_calendar_object_removed_cb (GtkWidget *cal_client, e_week_view_remove_event (E_WEEK_VIEW (gcal->week_view), uid); e_week_view_remove_event (E_WEEK_VIEW (gcal->month_view), uid); - /* FIXME: optimize these? */ -#if 0 - year_view_update (YEAR_VIEW (gcal->year_view), NULL, CHANGE_ALL); -#endif gncal_todo_update (GNCAL_TODO (gcal->todo), NULL, CHANGE_ALL); gnome_calendar_tag_calendar (gcal, gcal->gtk_calendar); } @@ -1300,8 +1259,6 @@ gnome_calendar_time_format_changed (GnomeCalendar *gcal) g_return_if_fail (gcal != NULL); g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - year_view_time_format_changed (YEAR_VIEW (gcal->year_view)); - gtk_calendar_display_options (gcal->gtk_calendar, (week_starts_on_monday ? (gcal->gtk_calendar->display_flags @@ -1365,11 +1322,6 @@ gnome_calendar_get_current_time_range (GnomeCalendar *gcal, || page == gcal->month_view) e_week_view_get_selected_time_range (E_WEEK_VIEW (page), start_time, end_time); -#if 0 - else if (page == gcal->year_view_sw) - year_view_set (YEAR_VIEW (gcal->year_view), - gcal->selection_start_time); -#endif else { g_warning ("My penguin is gone!"); g_assert_not_reached (); diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index 48bd6af679..3711e65af0 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -45,8 +45,6 @@ typedef struct { GtkWidget *work_week_view; GtkWidget *week_view; GtkWidget *month_view; - GtkWidget *year_view; - GtkWidget *year_view_sw; void *event_editor; @@ -113,8 +111,6 @@ void gnome_calendar_object_changed (GnomeCalendar *gcal, iCalObject *obj, int flags); -void calendar_notify (time_t time, CalendarAlarm *which, void *data); - GnomeCalendar *gnome_calendar_locate (const char *pathname); /* Notifies the calendar that the time format has changed and it must update all its views */ diff --git a/calendar/gui/layout.c b/calendar/gui/layout.c new file mode 100644 index 0000000000..c8dfde6bdb --- /dev/null +++ b/calendar/gui/layout.c @@ -0,0 +1,309 @@ +/* Evolution calendar - Event layout engine + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: Miguel de Icaza <miguel@helixcode.com> + * Federico Mena-Quintero <federico@helixcode.com> + * + * 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 <config.h> +#include <stdlib.h> +#include "layout.h" + + + +/* This structure is used to pass around layout information among the internal + * layout functions. + */ +struct layout_info { + GList *events; /* List of events from client */ + int num_events; /* The number of events (length of the list) */ + LayoutQueryTimeFunc func; /* Function to convert a list item to a start/end time pair */ + int num_rows; /* Size of the time partition */ + time_t *partition; /* The time partition containing start and end time values */ + int *array; /* Working array of free and allocated time slots */ + int *allocations; /* Returned array of slot allocations */ + int *slots; /* Returned array of slots used */ + int num_slots; /* Number of slots used */ +}; + + + +/* This defines the maximum number of events to overlap per row. More than that + * number of events will not be displayed. This is not ideal, so sue me. + */ +#define MAX_EVENTS_PER_ROW 32 + + +/* Compares two time_t values, used for qsort() */ +static int +compare_time_t (const void *a, const void *b) +{ + time_t ta, tb; + + ta = *((time_t *) a); + tb = *((time_t *) b); + + if (ta < tb) + return -1; + else if (ta > tb) + return 1; + else + return 0; +} + +/* Builds a partition of the time range occupied by the events in the list. It returns an array + * with the times that define the partition and the number of items in the partition. + */ +static void +build_partition (struct layout_info *li) +{ + time_t *rows, *p, *q; + GList *list; + int i, unique_vals; + + /* This is the maximum number of rows we would need */ + + li->num_rows = li->num_events * 2; + + /* Fill the rows with the times */ + + rows = g_new (time_t, li->num_rows); + + for (list = li->events, p = rows; list; list = list->next) { + (* li->func) (list, &p[0], &p[1]); + p += 2; + } + + /* Do a sort | uniq on the array */ + + qsort (rows, li->num_rows, sizeof (time_t), compare_time_t); + + p = rows; + q = rows + 1; + unique_vals = 1; + + for (i = 1; i < li->num_rows; i++, q++) + if (*q != *p) { + unique_vals++; + p++; + *p = *q; + } + + /* Return the number of unique values in the partition and the partition array itself */ + + li->num_rows = unique_vals; + li->partition = rows; +} + +/* Returns the index of the element in the partition that corresponds to the specified time */ +static int +find_index (struct layout_info *li, time_t t) +{ + int i; + + for (i = 0; ; i++) + if (li->partition[i] == t) + return i; + + g_assert_not_reached (); +} + +#define xy(li, x, y) li->array[(y * MAX_EVENTS_PER_ROW) + (x)] + +/* Checks that all the cells in the slot array at the specified slot column are free to use by an + * event that has the specified range. + */ +static int +range_is_empty (struct layout_info *li, int slot, time_t start, time_t end) +{ + int i; + + for (i = find_index (li, start); li->partition[i] < end; i++) + if (xy (li, slot, i) != -1) + return FALSE; + + return TRUE; +} + +/* Allocates a time in the slot array for the specified event's index */ +static void +range_allocate (struct layout_info *li, int slot, time_t start, time_t end, int ev_num) +{ + int i; + + for (i = find_index (li, start); li->partition[i] < end; i++) + xy (li, slot, i) = ev_num; +} + +/* Performs the initial allocation of slots for events. Each event gets one column; they will be + * expanded in a later stage. Returns the number of columns used. + */ +static void +initial_allocate (struct layout_info *li) +{ + GList *events; + int i; + int slot; + int num_slots; + time_t start, end; + + num_slots = 0; + + for (i = 0, events = li->events; events; events = events->next, i++) { + (* li->func) (events, &start, &end); + + /* Start with no allocation, no columns */ + + li->allocations[i] = -1; + li->slots[i] = 0; + + /* Find a free column for the event */ + + for (slot = 0; slot < MAX_EVENTS_PER_ROW; slot++) + if (range_is_empty (li, slot, start, end)) { + range_allocate (li, slot, start, end, i); + + li->allocations[i] = slot; + li->slots[i] = 1; + + if ((slot + 1) > num_slots) + num_slots = slot + 1; + + break; + } + } + + li->num_slots = num_slots; +} + +/* Returns the maximum number of columns that an event can expanded by in the slot array */ +static int +columns_to_expand (struct layout_info *li, int ev_num, time_t start, time_t end) +{ + int cols; + int slot; + int i_start; + int i; + + cols = 0; + + i_start = find_index (li, start); + + for (slot = li->allocations[ev_num] + 1; slot < li->num_slots; slot++) { + for (i = i_start; li->partition[i] < end; i++) + if (xy (li, slot, i) != -1) + return cols; + + cols++; + } + + return cols; +} + +/* Expands an event by the specified number of columns */ +static void +do_expansion (struct layout_info *li, int ev_num, time_t start, time_t end, int num_cols) +{ + int i, j; + int slot; + + for (i = find_index (li, start); li->partition[i] < end; i++) { + slot = li->allocations[ev_num] + 1; + + for (j = 0; j < num_cols; j++) + xy (li, slot + j, i) = ev_num; + } +} + +/* Expands the events in the slot array to occupy as many columns as possible. This is the second + * pass of the layout algorithm. + */ +static void +expand_events (struct layout_info *li) +{ + GList *events; + time_t start, end; + int i; + int cols; + + for (i = 0, events = li->events; events; events = events->next, i++) { + (* li->func) (events, &start, &end); + + cols = columns_to_expand (li, i, start, end); + + if (cols == 0) + continue; /* We can't expand this event */ + + do_expansion (li, i, start, end, cols); + + li->slots[i] += cols; + } +} + +void +layout_events (GList *events, LayoutQueryTimeFunc func, + int *num_slots, int **allocations, int **slots) +{ + struct layout_info li; + int i; + + g_return_if_fail (num_slots != NULL); + g_return_if_fail (allocations != NULL); + g_return_if_fail (slots != NULL); + + if (!events) { + *num_slots = 0; + *allocations = NULL; + *slots = NULL; + + return; + } + + li.events = events; + li.num_events = g_list_length (events); + li.func = func; + + /* Build the partition of the time range, and then build the array of slots */ + + build_partition (&li); + + li.array = g_new (int, li.num_rows * MAX_EVENTS_PER_ROW); + for (i = 0; i < (li.num_rows * MAX_EVENTS_PER_ROW); i++) + li.array[i] = -1; /* This is our 'empty' value */ + + /* Build the arrays for allocations and columns used */ + + li.allocations = g_new (int, li.num_events); + li.slots = g_new (int, li.num_events); + + /* Perform initial allocation and then expand the events to as many + * slots as they can occupy. + */ + + initial_allocate (&li); + expand_events (&li); + + /* Clean up and return values */ + + g_free (li.partition); + g_free (li.array); + + *num_slots = li.num_slots; + *allocations = li.allocations; + *slots = li.slots; +} diff --git a/calendar/gui/layout.h b/calendar/gui/layout.h new file mode 100644 index 0000000000..ed40e40a29 --- /dev/null +++ b/calendar/gui/layout.h @@ -0,0 +1,56 @@ +/* Evolution calendar - Event layout engine + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: Miguel de Icaza <miguel@helixcode.com> + * Federico Mena-Quintero <federico@helixcode.com> + * + * 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 LAYOUT_H +#define LAYOUT_H + +#include <glib.h> +#include <time.h> + + + +/* Functions of this type must translate the list item into two time_t values + * for the start and end of an event. + */ +typedef void (* LayoutQueryTimeFunc) (GList *event, time_t *start, time_t *end); + + +/* This is the main layout function for overlapping events. You pass in a list + * of (presumably) events and a function that should take a list element and + * return the start and end times for the event corresponding to that list + * element. + * + * It returns the number of slots ("columns") that you need to take into account + * when actually painting the events, the array of the first slot index that + * each event occupies, and the array of number of slots that each event + * occupies. You have to free both arrays. + * + * You will get somewhat better-looking results if the list of events is sorted + * by using the start time as the primary sort key and the end time as the + * secondary sort key -- so that "longer" events go first in the list. + */ +void layout_events (GList *events, LayoutQueryTimeFunc func, + int *num_slots, int **allocations, int **slots); + + + +#endif diff --git a/calendar/gui/main.c b/calendar/gui/main.c deleted file mode 100644 index 46f4c31e3e..0000000000 --- a/calendar/gui/main.c +++ /dev/null @@ -1,434 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Main file for the GNOME Calendar program - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * Federico Mena (federico@helixcode.com) - */ - -#include <config.h> - -#include <pwd.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <gnome.h> -#include <libgnorba/gnorba.h> -#include <bonobo.h> -#include <cal-util/timeutil.h> -#include <gui/alarm.h> -#include <gui/eventedit.h> -#include <gui/gnome-cal.h> -#include <gui/calendar-commands.h> - - -enum { - GEOMETRY_KEY = -1, - USERFILE_KEY = -2, - VIEW_KEY = -3, - HIDDEN_KEY = -4, - TODO_KEY = -5, - DEBUG_KEY = -6 -}; - -/* Lists used to startup various GnomeCalendars */ -static GList *start_calendars; -static GList *start_geometries; -static GList *start_views; - -/* For dumping part of a calendar */ -static time_t from_t, to_t; - -/* If set, show events for the specified date and quit */ -/*static int show_events;*/ - -/* If set, show todo items quit */ -/*static int show_todo;*/ - -/* If true, do not show our top level window */ -int startup_hidden = 0; - -/* File to load instead of the user default's file */ -static char *load_file; - -extern time_t get_date (); - -static void -process_dates (void) -{ - if (!from_t) - from_t = time_day_begin (time (NULL)); - - if (!to_t || to_t < from_t) - to_t = time_add_day (from_t, 1); -} - - -static int -same_day (struct tm *a, struct tm *b) -{ - return (a->tm_mday == b->tm_mday && - a->tm_mon == b->tm_mon && - a->tm_year == b->tm_year); -} - - -#if 0 -static void -dump_events (void) -{ - CalClient *calc; - gboolean r; - GList *l; - time_t now = time (NULL); - struct tm today = *localtime (&now); - - process_dates (); - init_calendar (); - - /* FIXME: this is not waiting for the calendar to be loaded */ - - /* DELETE - cal = calendar_new (full_name, CALENDAR_INIT_ALARMS); - s = calendar_load (cal, load_file ? load_file : user_calendar_file); - if (s){ - printf ("error: %s\n", s); - exit (1); - } - */ - - r = cal_client_load_calendar (calc, - load_file ? load_file : user_calendar_file); - if (r == FALSE) { - printf ("error: loading %s\n", - load_file ? load_file : user_calendar_file); - exit (1); - } - l = calendar_get_events_in_range (calc, from_t, to_t); - - for (; l; l = l->next){ - char start [80], end [80]; - CalendarObject *co = l->data; - struct tm ts, te; - char *format; - - ts = *localtime (&co->ev_start); - te = *localtime (&co->ev_end); - - if (same_day (&today, &ts)) - format = N_("%H:%M"); - else - format = N_("%A %b %d, %H:%M"); - strftime (start, sizeof (start), _(format), &ts); - - if (!same_day (&ts, &te)) - format = N_("%A %b %d, %H:%M"); - strftime (end, sizeof (start), _(format), &te); - - printf ("%s -- %s\n", start, end); - printf (" %s\n", co->ico->summary); - } - /* calendar_destroy_event_list (l); DELETE / FIXME */ - /* calendar_destroy (cal); DELETE */ - exit (0); -} -#endif /* 0 */ - - -#if 0 -static void -dump_todo (void) -{ - CalClient *calc; - gboolean r; - GList *l; - - process_dates (); - init_calendar (); - - /* FIXME: this is not waiting for the calendar to be loaded */ - - /* DELETE - cal = calendar_new (full_name, CALENDAR_INIT_ALARMS); - s = calendar_load (cal, load_file ? load_file : user_calendar_file); - if (s){ - printf ("error: %s\n", s); - exit (1); - } - */ - - r = cal_client_load_calendar (calc, - load_file ? load_file : user_calendar_file); - if (r == FALSE) { - printf ("error: loading %s\n", - load_file ? load_file : user_calendar_file); - exit (1); - } - l = calendar_get_events_in_range (calc, from_t, to_t); - - for (; l; l = l->next){ - CalendarObject *co = l->data; - iCalObject *object = co->ico; - - if (object->type != ICAL_TODO) - continue; - - printf ("[%s]: %s\n",object->organizer->addr, object->summary); - } - /* calendar_destroy (cal); DELETE */ - exit (0); -} -#endif /* 0 */ - - -static void -session_die (void) -{ - quit_cmd (NULL, NULL, NULL); -} - -/* - * Save the session callback - */ -static int -session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer client_data) -{ - char *sess_id; - char **argv = (char **) g_malloc (sizeof (char *) * ((active_calendars * 6) + 3)); - GList *l, *free_list = 0; - int i; - - sess_id = gnome_client_get_id (client); - - argv [0] = client_data; - for (i = 1, l = all_calendars; l; l = l->next){ - GnomeCalendar *gcal = GNOME_CALENDAR (l->data); - char *geometry; - - geometry = gnome_geometry_string (GTK_WIDGET (gcal)->window); - - /* FIX ME - if (strcmp (gcal->client->filename, user_calendar_file) == 0) - argv [i++] = "--userfile"; - else { - argv [i++] = "--file"; - argv [i++] = gcal->client->filename; - } - */ - - argv [i++] = "--geometry"; - argv [i++] = geometry; - argv [i++] = "--view"; - argv [i++] = gnome_calendar_get_current_view_name (gcal); - free_list = g_list_append (free_list, geometry); - } - argv [i] = NULL; - gnome_client_set_clone_command (client, i, argv); - gnome_client_set_restart_command (client, i, argv); - - for (l = free_list; l; l = l->next) - g_free (l->data); - g_list_free (free_list); - - return 1; -} - -static void -parse_an_arg (poptContext ctx, - enum poptCallbackReason reason, - const struct poptOption *opt, - char *arg, void *data) -{ - switch (opt->val){ - case 'f': - from_t = get_date (arg, NULL); - break; - - case 't': - to_t = get_date (arg, NULL); - break; - - case GEOMETRY_KEY: - start_geometries = g_list_append (start_geometries, arg); - break; - - case USERFILE_KEY: - /* This is a special key that tells the program to load - * the user's calendar file. This allows session management - * to work even if the User's home directory changes location - * (ie, on a networked setup). - */ - arg = COOKIE_USER_HOME_DIR; - /* fall through */ - break; - - case VIEW_KEY: - start_views = g_list_append (start_views, arg); - break; - - case 'F': - start_calendars = g_list_append (start_calendars, arg); - break; - - /* - case TODO_KEY: - show_todo = 1; - break; - */ - - /* - case 'e': - show_events = 1; - break; - */ - - case HIDDEN_KEY: - startup_hidden = 1; - break; - - case DEBUG_KEY: - if (!g_strcasecmp (arg, "alarms")) - debug_alarms = 1; - break; - - default: - } -} - - - - -static const struct poptOption options [] = { - { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL }, - { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"), - NULL }, - { "todo", 0, POPT_ARG_NONE, NULL, TODO_KEY, N_("Show TO-DO items and quit"), - NULL }, - { "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") }, - { "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") }, - { "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL }, - { "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") }, - { "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode (dayview, weekview, monthview, yearview)"), N_("VIEW") }, - { "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") }, - { "hidden", 0, POPT_ARG_NONE, NULL, HIDDEN_KEY, N_("If used, starts in iconic mode"), NULL }, - { "debug", 'd', POPT_ARG_STRING, NULL, DEBUG_KEY, N_("Enable debugging output of TYPE (alarms)"), N_("TYPE") }, - { NULL, '\0', 0, NULL, 0} -}; - - -int -main (int argc, char **argv) -{ - GnomeClient *client; - GtkWidget *cal_window; - GnomeCalendar *cal_frame; - - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE); - -#ifdef USING_OAF - gnome_init_with_popt_table ("calendar", VERSION, argc, argv, oaf_popt_options, - 0, NULL); - oaf_init (argc, argv); -#else - { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - gnome_CORBA_init_with_popt_table ("calendar", VERSION, &argc, argv, - options, 0, NULL, 0, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("main(): could not initialize the ORB"); - CORBA_exception_free (&ev); - exit (EXIT_FAILURE); - } - CORBA_exception_free (&ev); - } -#endif - - if (!bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) { - g_message ("main(): could not initialize Bonobo"); - exit (EXIT_FAILURE); - } - - process_dates (); - -# if 0 - if (show_events) - dump_events (); - - if (show_todo) - dump_todo (); -# endif /* 0 */ - - client = gnome_master_client (); - if (client) { - gtk_signal_connect (GTK_OBJECT (client), "save_yourself", - GTK_SIGNAL_FUNC (session_save_state), argv [0]); - gtk_signal_connect (GTK_OBJECT (client), "die", - GTK_SIGNAL_FUNC (session_die), NULL); - } - - alarm_init (); - init_calendar (); - - /* FIXME: the following is broken-ish, since geometries/views are not matched - * to calendars, but they are just picked in whatever order they came in - * from the command line. - */ - - /* Load all of the calendars specified in the command line with the - * geometry specified, if any. - */ - if (start_calendars) { - GList *p, *g, *v; - char *title; - - p = start_calendars; - g = start_geometries; - v = start_views; - - while (p) { - char *file = p->data; - char *geometry = g ? g->data : NULL; - char *page_name = v ? v->data : NULL; - - if (file == COOKIE_USER_HOME_DIR) - file = user_calendar_file; - - if (strcmp (file, user_calendar_file) == 0) - title = full_name; - else - title = file; - - cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - cal_frame = new_calendar (title, file, geometry, page_name, startup_hidden); - gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame)); - gtk_widget_show (cal_window); - - p = p->next; - if (g) - g = g->next; - if (v) - v = v->next; - } - g_list_free (p); - } else { - char *geometry = start_geometries ? start_geometries->data : NULL; - char *page_name = start_views ? start_views->data : NULL; - - cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - cal_frame = new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden); - gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame)); - gtk_widget_show (cal_window); - } - - bonobo_main (); - return 0; -} diff --git a/calendar/gui/main.h b/calendar/gui/main.h deleted file mode 100644 index 9c8ea083f5..0000000000 --- a/calendar/gui/main.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef MAIN_H -#define MAIN_H - -/* Calendar preferences */ - -extern int day_begin, day_end; -extern char *user_name; -extern int am_pm_flag; -extern int week_starts_on_monday; - - -/* This enum and the following array define the color preferences */ - -typedef enum { - COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */ - COLOR_PROP_HEADING_COLOR, /* Color for headings */ - COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */ - COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */ - COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ - COLOR_PROP_DAY_FG, /* Color for day numbers */ - COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ - COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */ - COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */ - COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */ - COLOR_PROP_LAST /* Number of color properties */ -} ColorProp; - -struct color_prop { - int r; /* Values are in [0, 65535] */ - int g; - int b; - char *label; /* Label for properties dialog */ - char *key; /* Key for gnome_config */ -}; - -extern struct color_prop color_props[]; - - -/* todo preferences */ -extern int todo_show_due_date; - -extern int todo_item_dstatus_highlight_overdue; -extern int todo_item_dstatus_highlight_due_today; -extern int todo_item_dstatus_highlight_not_due_yet; - -extern int todo_show_time_remaining; -extern int todo_show_priority; -extern char *todo_overdue_font_text; -extern gboolean todo_style_changed; -extern gint todo_current_sort_column; -extern gint todo_current_sort_type; - -/* alarm stuff */ -extern CalendarAlarm alarm_defaults[4]; -extern gboolean beep_on_display; -extern gboolean enable_aalarm_timeout; -extern guint audio_alarm_timeout; -extern const guint MAX_AALARM_TIMEOUT; -extern gboolean enable_snooze; -extern guint snooze_secs; -extern const guint MAX_SNOOZE_SECS; - -/* Creates and runs the preferences dialog box */ -void properties (GtkWidget *toplevel); - -/* Asks for all the time-related displays to be updated when the user changes the time format - * preferences. - */ -void time_format_changed (void); - -/* Asks for all the month items' colors to be reset */ -void colors_changed (void); - -/* Asks for all todo lists to reflect the accurate properties */ -void todo_properties_changed(void); - -/* Creates and runs the Go-to date dialog */ -void goto_dialog (GnomeCalendar *gcal); - -/* Returns a pointer to a statically-allocated string with a representation of the specified color. - * Values must be in [0, 65535]. - */ -char *build_color_spec (int r, int g, int b); - -/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */ -void parse_color_spec (char *spec, int *r, int *g, int *b); - -/* Calls build_color_spec() for the color in the specified property number */ -char *color_spec_from_prop (ColorProp propnum); - -GnomeCalendar *new_calendar (char *full_name, char *calendar_file, - char *geometry, char *page, gboolean hidden); - - -/*----------------------------------------------------------------------*/ -/* FIX ME -- where should this stuff go? */ -/*----------------------------------------------------------------------*/ - -/* This is only used by the calendar_get_events_in_range routine to get - * a list of objects that recur on a specific date - */ -typedef struct { - time_t ev_start; - time_t ev_end; - iCalObject *ico; -} CalendarObject; - -GList *calendar_get_events_in_range (CalClient *calc, - time_t start, time_t end); -void -calendar_iterate (GnomeCalendar *cal, - time_t start, time_t end, - calendarfn cb, void *closure); -#endif diff --git a/calendar/gui/mark.c b/calendar/gui/mark.c index 02b3af17e1..ea83845b2a 100644 --- a/calendar/gui/mark.c +++ b/calendar/gui/mark.c @@ -1,8 +1,22 @@ -/* Functions to mark calendars +/* Evolution calendar - Functions to mark calendars * * Copyright (C) 1998 Red Hat Software, Inc. * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena-Quintero <federico@helixcode.com> + * + * 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 <config.h> @@ -11,6 +25,7 @@ #include "calendar-commands.h" #include "mark.h" + /* Frees the specified data when an object is destroyed */ static void @@ -101,30 +116,35 @@ mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end) } void -mark_month_item (GnomeMonthItem *mitem, GnomeCalendar *cal) +mark_month_item (GnomeMonthItem *mitem, GnomeCalendar *gcal) { time_t month_begin, month_end; - GList *list, *l; - CalendarObject *co; + GList *events; + GList *l; g_return_if_fail (mitem != NULL); g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (cal != NULL); + g_return_if_fail (gcal != NULL); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1)); month_end = time_month_end (month_begin); - list = calendar_get_events_in_range (cal->client, month_begin, month_end); + events = cal_client_get_events_in_range (gcal->client, month_begin, month_end); + + for (l = events; l; l = l->next) { + CalObjInstance *coi; - for (l = list; l; l = l->next) { - co = l->data; + coi = l->data; /* We clip the event's start and end times to the month's limits */ - mark_event_in_month (mitem, MAX (co->ev_start, month_begin), MIN (co->ev_end, month_end)); + mark_event_in_month (mitem, + MAX (coi->start, month_begin), + MIN (coi->end, month_end)); } - /* calendar_destroy_event_list (list); DELETE / FIX ME */ + cal_obj_instance_list_free (events); } void diff --git a/calendar/gui/mark.h b/calendar/gui/mark.h index ea7315a43f..76c82c580d 100644 --- a/calendar/gui/mark.h +++ b/calendar/gui/mark.h @@ -1,8 +1,22 @@ -/* Functions to mark calendars +/* Evolution calendar - Functions to mark calendars * * Copyright (C) 1998 Red Hat Software, Inc. * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena-Quintero <federico@helixcode.com> + * + * 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 MARK_H @@ -11,6 +25,7 @@ /*#include "calendar.h"*/ #include "gnome-month-item.h" + /* These are the fonts used for the montly calendars */ @@ -55,5 +70,6 @@ void month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpoi */ char *default_color_func (ColorProp prop_num, gpointer data); + #endif diff --git a/calendar/gui/month-view.c b/calendar/gui/month-view.c deleted file mode 100644 index 6ac8c035bc..0000000000 --- a/calendar/gui/month-view.c +++ /dev/null @@ -1,800 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gnome.h> -#include <libgnomeui/gnome-canvas-text.h> -#include <cal-util/timeutil.h> -#include "eventedit.h" -#include "layout.h" -#include "month-view.h" -#include "calendar-commands.h" -#include "mark.h" -#include "quick-view.h" - - -/* Spacing between title and calendar */ -#define SPACING 4 - -/* Padding between day borders and event text */ -#define EVENT_PADDING 3 - - -static void month_view_class_init (MonthViewClass *class); -static void month_view_init (MonthView *mv); -static void month_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void month_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvasClass *parent_class; - - -GtkType -month_view_get_type (void) -{ - static GtkType month_view_type = 0; - - if (!month_view_type) { - GtkTypeInfo month_view_info = { - "MonthView", - sizeof (MonthView), - sizeof (MonthViewClass), - (GtkClassInitFunc) month_view_class_init, - (GtkObjectInitFunc) month_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - month_view_type = gtk_type_unique (gnome_canvas_get_type (), &month_view_info); - } - - return month_view_type; -} - -static void -month_view_class_init (MonthViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - widget_class->size_request = month_view_size_request; - widget_class->size_allocate = month_view_size_allocate; -} - -/* Creates the quick view when a day is clicked in the month view */ -static void -do_quick_view_popup (MonthView *mv, GdkEventButton *event, int day) -{ - time_t day_begin_time, day_end_time; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_begin_time = time_from_day (mv->year, mv->month, day); - day_end_time = time_day_end (day_begin_time); - - list = calendar_get_events_in_range (mv->calendar->client, - day_begin_time, day_end_time); - - strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_begin_time)); - qv = quick_view_new (mv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - /* calendar_destroy_event_list (list); DELETE / FIX ME*/ -} - -/* Callback used to destroy the popup menu when the month view is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Creates a new appointment in the current day */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (mv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (mv->calendar, view_name); - gnome_calendar_goto (mv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_year (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "yearview"); -} - -static GnomeUIInfo mv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _year"), NULL, jump_to_year, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Creates the popup menu for the month view if it does not yet exist, and attaches it to the month - * view object so that it can be destroyed when appropriate. - */ -static GtkWidget * -get_popup_menu (MonthView *mv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (mv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (mv_popup_menu); - gtk_object_set_data (GTK_OBJECT (mv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (mv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Pops up the menu for the month view. */ -static void -do_popup_menu (MonthView *mv, GdkEventButton *event, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (mv); - - /* Enable or disable items as appropriate */ - - gtk_widget_set_sensitive (mv_popup_menu[0].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[2].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[3].widget, day != 0); - - if (day == 0) - day = 1; - - /* Store the time for the menu item callbacks to use */ - - t = time_from_day (mv->year, mv->month, day); - - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, mv); -} - -/* Event handler for day groups. When mouse button 1 is pressed, it will pop up a quick view with - * the events in that day. When mouse button 3 is pressed, it will pop up a menu. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - int child_num; - int day; - - mv = MONTH_VIEW (data); - - child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (mv->mitem), item); - day = gnome_month_item_num2day (GNOME_MONTH_ITEM (mv->mitem), child_num); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((event->button.button == 1) && (day != 0)) { - do_quick_view_popup (mv, (GdkEventButton *) event, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (mv, (GdkEventButton *) event, day); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Returns the index of the specified arrow in the array of arrows */ -static int -get_arrow_index (MonthView *mv, GnomeCanvasItem *arrow) -{ - int i; - - for (i = 0; i < 42; i++) - if (mv->up[i] == arrow) - return i; - else if (mv->down[i] == arrow) - return i + 42; - - g_warning ("Eeeek, arrow %p not found in month view %p", arrow, mv); - return -1; -} - -/* Checks whether arrows need to be displayed at the specified day index or not */ -static void -check_arrow_visibility (MonthView *mv, int day_index) -{ - GtkArg args[3]; - double text_height; - double clip_height; - double y_offset; - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 3, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - - /* Check up arrow */ - - if (y_offset < 0.0) - gnome_canvas_item_show (mv->up[day_index]); - else - gnome_canvas_item_hide (mv->up[day_index]); - - if (y_offset > (clip_height - text_height)) - gnome_canvas_item_show (mv->down[day_index]); - else - gnome_canvas_item_hide (mv->down[day_index]); -} - -/* Finds which arrow was clicked and scrolls the corresponding text item in the month view */ -static void -do_arrow_click (MonthView *mv, GnomeCanvasItem *arrow) -{ - int arrow_index; - int day_index; - int up; - GtkArg args[4]; - double text_height, clip_height; - double y_offset; - GdkFont *font; - - arrow_index = get_arrow_index (mv, arrow); - up = (arrow_index < 42); - day_index = up ? arrow_index : (arrow_index - 42); - - /* See how much we can scroll */ - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - args[3].name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 4, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - font = GTK_VALUE_BOXED (args[3]); - - if (up) - y_offset += font->ascent + font->descent; - else - y_offset -= font->ascent + font->descent; - - if (y_offset > 0.0) - y_offset = 0.0; - else if (y_offset < (clip_height - text_height)) - y_offset = clip_height - text_height; - - /* Scroll */ - - gnome_canvas_item_set (mv->text[day_index], - "y_offset", y_offset, - NULL); - - check_arrow_visibility (mv, day_index); -} - -/* Event handler for the scroll arrows in the month view */ -static gint -arrow_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - - mv = MONTH_VIEW (data); - - switch (event->type) { - case GDK_ENTER_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG), - NULL); - return TRUE; - - case GDK_LEAVE_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - NULL); - return TRUE; - - case GDK_BUTTON_PRESS: - if (event->button.button != 1) - break; - - do_arrow_click (mv, item); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Creates a new arrow out of the specified points and connects the proper signals to it */ -static GnomeCanvasItem * -new_arrow (MonthView *mv, GnomeCanvasGroup *group, GnomeCanvasPoints *points) -{ - GnomeCanvasItem *item; - char *color_spec; - - color_spec = color_spec_from_prop (COLOR_PROP_DAY_FG); - - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", color_spec, - "outline_color", color_spec, - NULL); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) arrow_event, - mv); - - return item; -} - -static void -month_view_init (MonthView *mv) -{ - int i; - GnomeCanvasItem *day_group; - GnomeCanvasPoints *points; - - /* Title */ - - mv->title = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (mv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "fontset", HEADING_FONTSET, - "fill_color", "black", - NULL); - - /* Month item */ - - mv->mitem = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (mv))); - gnome_canvas_item_set (mv->mitem, - "x", 0.0, - "anchor", GTK_ANCHOR_NW, - "day_anchor", GTK_ANCHOR_NE, - "start_on_monday", week_starts_on_monday, - "heading_padding", 2.0, - "heading_fontset", BIG_DAY_HEADING_FONTSET, - "day_fontset", BIG_NORMAL_DAY_FONTSET, - NULL); - - /* Arrows and text items. The arrows start hidden by default; they will be shown as - * appropriate by the item adjustment code. Also, connect to the event signal of the - * day groups so that we can pop up the quick view when appropriate. - */ - - points = gnome_canvas_points_new (3); - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - i + GNOME_MONTH_ITEM_DAY_GROUP); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - mv); - - /* Up arrow */ - - points->coords[0] = 3; - points->coords[1] = 10; - points->coords[2] = 11; - points->coords[3] = 10; - points->coords[4] = 7; - points->coords[5] = 3; - - mv->up[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Down arrow */ - - points->coords[0] = 13; - points->coords[1] = 3; - points->coords[2] = 17; - points->coords[3] = 10; - points->coords[4] = 21; - points->coords[5] = 3; - - mv->down[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Text item */ - - mv->text[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (day_group), - gnome_canvas_text_get_type (), - "fontset", EVENT_FONTSET, - "anchor", GTK_ANCHOR_NW, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "clip", TRUE, - NULL); - } - gnome_canvas_points_free (points); - - mv->old_current_index = -1; -} - -GtkWidget * -month_view_new (GnomeCalendar *calendar, time_t month) -{ - MonthView *mv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - mv = gtk_type_new (month_view_get_type ()); - mv->calendar = calendar; - - month_view_colors_changed (mv); - month_view_set (mv, month); - return GTK_WIDGET (mv); -} - -static void -month_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - if (GTK_WIDGET_CLASS (parent_class)->size_request) - (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition); - - requisition->width = 200; - requisition->height = 150; -} - -/* Adjusts the text items for events in the month view to the appropriate size. It also makes the - * corresponding arrows visible or invisible, as appropriate. - */ -static void -adjust_children (MonthView *mv) -{ - int i; - GnomeCanvasItem *item; - double x1, y1, x2, y2; - GtkArg arg; - - for (i = 0; i < 42; i++) { - /* Get dimensions of the day group */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_GROUP); - gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2); - - /* Normalize and add paddings */ - - x2 -= x1 + EVENT_PADDING; - x1 = EVENT_PADDING; - y2 -= y1 + EVENT_PADDING; - y1 = EVENT_PADDING; - - /* Add height of day label to y1 */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_LABEL); - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 1, &arg); - y1 += GTK_VALUE_DOUBLE (arg); - - /* Set the position and clip size */ - - gnome_canvas_item_set (mv->text[i], - "x", x1, - "y", y1, - "clip_width", x2 - x1, - "clip_height", y2 - y1, - "x_offset", 0.0, - "y_offset", 0.0, - NULL); - - /* See what visibility state the arrows should be set to */ - - check_arrow_visibility (mv, i); - } -} - -static void -month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - MonthView *mv; - GdkFont *font; - GtkArg arg; - int y; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - mv = MONTH_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mv), 0, 0, allocation->width, allocation->height); - - /* Adjust items to new size */ - - arg.name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->title), 1, &arg); - font = GTK_VALUE_BOXED (arg); - - gnome_canvas_item_set (mv->title, - "x", (double) allocation->width / 2.0, - "y", (double) SPACING, - NULL); - - y = font->ascent + font->descent + 2 * SPACING; - gnome_canvas_item_set (mv->mitem, - "y", (double) y, - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - y - 1), - NULL); - - /* Adjust children */ - - adjust_children (mv); -} - -/* This defines the environment for the calendar iterator function that is used to populate the - * month view with events. - */ -struct iter_info { - MonthView *mv; /* The month view we are creating children for */ - int first_day_index; /* Index of the first day of the month within the month item */ - time_t month_begin, month_end; /* Beginning and end of month */ - GString **strings; /* Array of strings to populate */ -}; - -/* This is the calendar iterator function used to populate the string array with event information. - * For each event, it iterates through all the days that the event touches and appends the proper - * information to the string array in the iter_info structure. - */ -static int -add_event (iCalObject *ico, time_t start, time_t end, void *data) -{ - struct iter_info *ii; - struct tm tm; - time_t t; - time_t day_begin_time, day_end_time; - - ii = data; - - /* Get the first day of the event */ - - t = MAX (start, ii->month_begin); - day_begin_time = time_day_begin (t); - day_end_time = time_day_end (day_begin_time); - - /* Loop until the event ends or the month ends. For each day touched, append the proper - * information to the corresponding string. - */ - - do { - tm = *localtime (&day_begin_time); - g_string_sprintfa (ii->strings[ii->first_day_index + tm.tm_mday - 1], "%s\n", ico->summary); - - /* Next day */ - - day_begin_time = time_add_day (day_begin_time, 1); - day_end_time = time_day_end (day_begin_time); - } while ((end > day_begin_time) && (day_begin_time < ii->month_end)); - - return TRUE; /* this means we are not finished yet with event generation */ -} - -void -month_view_update (MonthView *mv, iCalObject *object, int flags) -{ - struct iter_info ii; - GString *strings[42]; - int i; - time_t t; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - ii.mv = mv; - - /* Create an array of empty GStrings */ - - ii.strings = strings; - - for (i = 0; i < 42; i++) - strings[i] = g_string_new (NULL); - - ii.first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), 1); - g_assert (ii.first_day_index != -1); - - /* Populate the array of strings with events */ - - t = time_from_day (mv->year, mv->month, 1); - ii.month_begin = time_month_begin (t); - ii.month_end = time_month_end (t); - - calendar_iterate (mv->calendar, - ii.month_begin, ii.month_end, add_event, &ii); - - for (i = 0; i < 42; i++) { - /* Delete the last character if it is a newline */ - - if (strings[i]->str && strings[i]->len && (strings[i]->str[strings[i]->len - 1] == '\n')) - g_string_truncate (strings[i], strings[i]->len - 1); - - gnome_canvas_item_set (mv->text[i], - "text", strings[i]->str, - NULL); - g_string_free (strings[i], TRUE); - } - - /* Adjust children for scrolling */ - - adjust_children (mv); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (MonthView *mv) -{ - time_t t; - struct tm tm; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (mv->old_current_index != -1) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "fontset", BIG_NORMAL_DAY_FONTSET, - NULL); - - mv->old_current_index = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = *localtime (&t); - - if (((tm.tm_year + 1900) == mv->year) && (tm.tm_mon == mv->month)) { - mv->old_current_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), tm.tm_mday); - g_assert (mv->old_current_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "fontset", BIG_CURRENT_DAY_FONTSET, - NULL); - } -} - -void -month_view_set (MonthView *mv, time_t month) -{ - struct tm tm; - char buf[100]; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - /* Title */ - - tm = *localtime (&month); - - mv->year = tm.tm_year + 1900; - mv->month = tm.tm_mon; - - strftime (buf, 100, _("%B %Y"), &tm); - - gnome_canvas_item_set (mv->title, - "text", buf, - NULL); - - /* Month item */ - - gnome_canvas_item_set (mv->mitem, - "year", mv->year, - "month", mv->month, - NULL); - - /* Update events */ - - month_view_update (mv, NULL, 0); - mark_current_day (mv); -} - -void -month_view_time_format_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - gnome_canvas_item_set (mv->mitem, - "start_on_monday", week_starts_on_monday, - NULL); - - month_view_set (mv, time_month_begin (time_from_day (mv->year, mv->month, 1))); -} - -void -month_view_colors_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - colorify_month_item (GNOME_MONTH_ITEM (mv->mitem), default_color_func, NULL); - mark_current_day (mv); - - /* FIXME: set children to the marked color */ -} diff --git a/calendar/gui/month-view.h b/calendar/gui/month-view.h deleted file mode 100644 index 6e49c2f931..0000000000 --- a/calendar/gui/month-view.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef MONTH_VIEW_H -#define MONTH_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_MONTH_VIEW (month_view_get_type ()) -#define MONTH_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_MONTH_VIEW, MonthView)) -#define MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_MONTH_VIEW, MonthViewClass)) -#define IS_MONTH_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_MONTH_VIEW)) -#define IS_MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_MONTH_VIEW)) - - -typedef struct _MonthView MonthView; -typedef struct _MonthViewClass MonthViewClass; - -struct _MonthView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year of the month we are displaying */ - int month; /* The month we are displaying */ - int old_current_index; /* The index of the day marked as current, or -1 if none */ - - GnomeCanvasItem *up[42]; /* Arrows to go up in the days */ - GnomeCanvasItem *down[42]; /* Arrows to go down in the days */ - GnomeCanvasItem *text[42]; /* Text items for the events */ - - GnomeCanvasItem *title; /* The title heading with the month/year */ - GnomeCanvasItem *mitem; /* The canvas month item used by this month view */ -}; - -struct _MonthViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType month_view_get_type (void); - -/* Creates a new month view widget associated to the specified calendar */ -GtkWidget *month_view_new (GnomeCalendar *calendar, time_t month); - -/* Notifies the month view that a calendar object has changed */ -void month_view_update (MonthView *mv, iCalObject *ico, int flags); - -/* Notifies the month view about a change of date */ -void month_view_set (MonthView *mv, time_t month); - -/* Notifies the month view that the time format has changed */ -void month_view_time_format_changed (MonthView *mv); - -/* Notifies the month view that the colors have changed */ -void month_view_colors_changed (MonthView *mv); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/print.c b/calendar/gui/print.c new file mode 100644 index 0000000000..3985645002 --- /dev/null +++ b/calendar/gui/print.c @@ -0,0 +1,1186 @@ +/* Evolution calendar - Print support + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: Michael Zucchi <notzed@helixcode.com> + * Federico Mena-Quintero <federico@helixcode.com> + * + * 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 <config.h> +#include <sys/stat.h> +#include <math.h> +#include <gnome.h> +#include <libgnomeprint/gnome-print.h> +#include <libgnomeprint/gnome-print-copies.h> +#include <libgnomeprint/gnome-print-master.h> +#include <libgnomeprint/gnome-print-preview.h> +#include <libgnomeprint/gnome-printer-profile.h> +#include <libgnomeprint/gnome-printer-dialog.h> +#include <cal-util/timeutil.h> +#include "calendar-commands.h" +#include "gnome-cal.h" +#include "layout.h" + + + +static void show_print_dialogue(void); + +/* copied from gnome-month-item.c this should be shared?? */ + +/* Number of days in a month, for normal and leap years */ +static const int days_in_month[2][12] = { + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the + * Gregorian reformation. + */ +static const int sept_1752[42] = { + 0, 0, 1, 2, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 +}; + +#define REFORMATION_DAY 639787 /* First day of the reformation, counted from 1 Jan 1 */ +#define MISSING_DAYS 11 /* They corrected out 11 days */ +#define THURSDAY 4 /* First day of reformation */ +#define SATURDAY 6 /* Offset value; 1 Jan 1 was a Saturday */ +#define SEPT_1752_START 2 /* Start day within month */ +#define SEPT_1752_END 20 /* End day within month */ + +/* Returns the number of leap years since year 1 up to (but not including) the specified year */ +static int +leap_years_up_to (int year) +{ + return (year / 4 /* trivial leapness */ + - ((year > 1700) ? (year / 100 - 17) : 0) /* minus centuries since 1700 */ + + ((year > 1600) ? ((year - 1600) / 400) : 0)); /* plus centuries since 1700 divisible by 400 */ +} + +/* Returns whether the specified year is a leap year */ +static int +is_leap_year (int year) +{ + if (year <= 1752) + return !(year % 4); + else + return (!(year % 4) && (year % 100)) || !(year % 400); +} + +/* Returns the 1-based day number within the year of the specified date */ +static int +day_in_year (int day, int month, int year) +{ + int is_leap, i; + + is_leap = is_leap_year (year); + + for (i = 0; i < month; i++) + day += days_in_month [is_leap][i]; + + return day; +} + +/* Returns the day of the week (zero-based, zero is Sunday) for the specified date. For the days + * that were removed on the Gregorian reformation, it returns Thursday. + */ +static int +day_in_week (int day, int month, int year) +{ + int n; + + n = (year - 1) * 365 + leap_years_up_to (year - 1) + day_in_year (day, month, year); + + if (n < REFORMATION_DAY) + return (n - 1 + SATURDAY) % 7; + + if (n >= (REFORMATION_DAY + MISSING_DAYS)) + return (n - 1 + SATURDAY - MISSING_DAYS) % 7; + + return THURSDAY; +} + +/* Fills the 42-element days array with the day numbers for the specified month. Slots outside the + * bounds of the month are filled with zeros. The starting and ending indexes of the days are + * returned in the start and end arguments. + */ +static void +build_month (int month, int year, int start_on_monday, int *days, int *start, int *end) +{ + int i; + int d_month, d_week; + + /* Note that months are zero-based, so September is month 8 */ + + if ((year == 1752) && (month == 8)) { + memcpy (days, sept_1752, 42 * sizeof (int)); + + if (start) + *start = SEPT_1752_START; + + if (end) + *end = SEPT_1752_END; + + return; + } + + for (i = 0; i < 42; i++) + days[i] = 0; + + d_month = days_in_month[is_leap_year (year)][month]; + d_week = day_in_week (1, month, year); + + if (start_on_monday) + d_week = (d_week + 6) % 7; + + for (i = 0; i < d_month; i++) + days[d_week + i] = i + 1; + + if (start) + *start = d_week; + + if (end) + *end = d_week + d_month - 1; +} + + +enum align_box { + ALIGN_LEFT=1, + ALIGN_RIGHT, + ALIGN_CENTRE, + ALIGN_BORDER= 1<<8 +}; + +/* width = width of border, -'ve is no border + fillcolour = shade of fill, -'ve is no fill */ +static void +print_border(GnomePrintContext *pc, double l, double r, double t, double b, double width, double fillcolour) +{ + int i; + gnome_print_gsave (pc); + if (fillcolour<0.0) + i=1; + else + i=0; + for (;i<2;i++) { + gnome_print_moveto(pc, l, t); + gnome_print_lineto(pc, l, b); + gnome_print_lineto(pc, r, b); + gnome_print_lineto(pc, r, t); + gnome_print_lineto(pc, l, t); + if (i==0) { + gnome_print_setrgbcolor(pc, fillcolour, fillcolour, fillcolour); + gnome_print_fill(pc); + if (width<0.0) + i=2; + } else { + gnome_print_setrgbcolor(pc, 0, 0, 0); + gnome_print_setlinewidth(pc, width); + gnome_print_stroke(pc); + } + } + gnome_print_grestore (pc); +} + +/* outputs 1 line of aligned text in a box */ +static void +print_text(GnomePrintContext *pc, GnomeFont *font, const char *text, enum align_box align, double l, double r, double t, double b) +{ + double w, x; + gnome_print_gsave (pc); + w = gnome_font_get_width_string(font, text); + switch (align&3) { + default: + case ALIGN_LEFT: + x = l; + break; + case ALIGN_RIGHT: + x = l+(r-l)-w-2; + break; + case ALIGN_CENTRE: + x = l+((r-l)-w)/2; + break; + } + gnome_print_moveto(pc, x, t-font->size); + gnome_print_setfont(pc, font); + gnome_print_setrgbcolor (pc, 0,0,0); + gnome_print_show(pc, text); + gnome_print_grestore (pc); +} + +/* gets/frees the font for you, as a bold font */ +static void +print_text_size(GnomePrintContext *pc, double size, const char *text, enum align_box align, double l, double r, double t, double b) +{ + GnomeFont *font; + + font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, size); + print_text(pc, font, text, align, l, r, t, b); + gtk_object_unref (GTK_OBJECT (font)); +} + +static void +titled_box(GnomePrintContext *pc, const char *text, GnomeFont *font, enum align_box align, double *l, double *r, double *t, double *b, double linewidth) +{ + if (align&ALIGN_BORDER) { + gnome_print_gsave(pc); + print_border(pc, *l, *r, *t, *t-font->size-font->size*0.4, linewidth, 0.9); + print_border(pc, *l, *r, *t-font->size-font->size*0.4, *b, linewidth, -1.0); + gnome_print_grestore(pc); + *l+=2; + *r-=2; + *b+=2; + } + print_text(pc, font, text, align, *l, *r, *t, *b); + *t-=font->size*1.4; +} + +enum datefmt { + DATE_MONTH = 1 << 0, + DATE_DAY = 1 << 1, + DATE_DAYNAME = 1 << 2, + DATE_YEAR = 1 << 3 +}; + +static char *days[] = { + N_("1st"), N_("2nd"), N_("3rd"), N_("4th"), N_("5th"), + N_("6th"), N_("7th"), N_("8th"), N_("9th"), N_("10th"), + N_("11th"), N_("12th"), N_("13th"), N_("14th"), N_("15th"), + N_("16th"), N_("17th"), N_("18th"), N_("19th"), N_("20th"), + N_("21st"), N_("22nd"), N_("23rd"), N_("24th"), N_("25th"), + N_("26th"), N_("27th"), N_("28th"), N_("29th"), N_("30th"), + N_("31st") +}; + +/* + format the date 'nicely' and consistently for various headers +*/ +static char * +format_date(time_t time, int flags, char *buffer, int bufflen) +{ + char fmt[64]; + struct tm tm; + + tm = *localtime(&time); + fmt[0] = 0; + if (flags & DATE_DAYNAME) { + strcat(fmt, "%A"); + } + if (flags & DATE_DAY) { + if (flags & DATE_DAYNAME) + strcat(fmt, " "); + strcat(fmt, gettext(days[tm.tm_mday-1])); + } + if (flags & DATE_MONTH) { + if (flags & (DATE_DAY|DATE_DAYNAME)) + strcat(fmt, " "); + strcat(fmt, "%B"); + if ((flags & (DATE_DAY|DATE_YEAR)) == (DATE_DAY|DATE_YEAR)) + strcat(fmt, ","); + } + if (flags & DATE_YEAR) { + if (flags & (DATE_DAY|DATE_DAYNAME|DATE_MONTH)) + strcat(fmt, " "); + strcat(fmt, "%Y"); + } + strftime(buffer, bufflen, fmt, &tm); + return buffer; +} + + +/* + print out the month small, embolden any days with events. +*/ +static void +print_month_small (GnomePrintContext *pc, GnomeCalendar *gcal, + time_t month, double left, double right, double top, double bottom, + int titleflags, time_t greystart, time_t greyend, int bordertitle) +{ + GnomeFont *font, *font_bold, *font_normal; + time_t now, next; + int x, y; + int days[42]; + int day; + char buf[100]; + struct tm tm; + double xpad, ypad, size; + char *daynames[] = { _("Su"), _("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa") }; + + xpad = (right-left)/7; + ypad = (top-bottom)/8.3; + if (xpad>ypad) + size=ypad; + else + size=xpad; + + size = (xpad+ypad)/3.0; + + tm = *localtime (&month); + + /* get month days */ + build_month(tm.tm_mon, tm.tm_year+1900, week_starts_on_monday, days, 0, 0); + + /* build day-busy bits */ + now = time_month_begin(month); + + /* get title */ + format_date(month, titleflags, buf, 100); + font = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 1, size*1.2); /* title font */ + if (bordertitle) + print_border(pc, + left, left+7*xpad, top, top-font->size*1.3, + 1.0, 0.9); + print_text(pc, font, buf, ALIGN_CENTRE, + left, left+7*xpad, top, top - font->size); + gtk_object_unref (GTK_OBJECT (font)); + + font_normal = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, size); + font_bold = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, size); + + gnome_print_setrgbcolor (pc, 0,0,0); + for (x=0;x<7;x++) { + print_text(pc, font_bold, daynames[(week_starts_on_monday?x+1:x)%7], ALIGN_CENTRE, + left+x*xpad, left+(x+1)*xpad, bottom+7*ypad, bottom+7*ypad-font_bold->size); + } + + for (y=0;y<6;y++) { + for (x=0;x<7;x++) { + day = days[y*7+x]; + if (day!=0) { + GList *events; + + sprintf(buf, "%d", day); + + /* this is a slow messy way to do this ... but easy ... */ + events = cal_client_get_events_in_range (gcal->client, + now, + time_day_end (now)); + font = events ? font_bold : font_normal; + cal_obj_instance_list_free (events); + + next = time_add_day(now, 1); + if ((now>=greystart && now<greyend) + || (greystart>=now && greystart<next)) { + print_border(pc, + left+x*xpad+xpad*0.1, + left+(x+1)*xpad+xpad*0.1, + bottom+(5-y)*ypad+font->size-ypad*0.15, + bottom+(5-y)*ypad-ypad*0.15, + -1.0, 0.75); + } + print_text(pc, font, buf, ALIGN_RIGHT, + left+x*xpad, left+(x+1)*xpad, bottom+(5-y)*ypad+font->size, bottom+(5-y)*ypad); + now = next; + } + } + } + gtk_object_unref (GTK_OBJECT (font_normal)); + gtk_object_unref (GTK_OBJECT (font_bold)); +} + + + +/* wraps text into the print context, not taking up more than its allowed space */ +static double +bound_text(GnomePrintContext *pc, GnomeFont *font, char *text, double left, double right, double top, double bottom, double indent) +{ + double maxwidth = right-left; + double width; + char *p; + char *wordstart; + int c; + char *outbuffer, *o, *outbuffendmarker; + int outbufflen; + int dump=0; + int first=1; + + g_return_val_if_fail(text!=NULL, top); + + if (top<bottom) { + /* too much to fit in appointment printout */ + return top; + } + + outbufflen = 1024; + outbuffer = g_malloc(outbufflen); + outbuffendmarker = outbuffer+outbufflen-2; + + top -= font->size; + gnome_print_setfont (pc, font); + + width=0; + p = text; + wordstart = outbuffer; + o = outbuffer; + while ((c=*p)) { + if (c=='\n') { + wordstart=o; + dump=1; + } else { + /* grow output buffer if required */ + if (o>=outbuffendmarker) { + char *newbuf; + outbufflen*=2; + newbuf = g_realloc(outbuffer, outbufflen); + o = newbuf+(o-outbuffer); + wordstart = newbuf+(o-outbuffer); + outbuffer = newbuf; + outbuffendmarker = outbuffer+outbufflen-2; + } + *o++=c; + if (c==' ') + wordstart = o; + width+=gnome_font_get_width(font, c); + if (width>maxwidth) + dump=1; + else + dump=0; + } + if (dump) { + if (wordstart==outbuffer) + wordstart=o; + c=*wordstart; + *wordstart=0; + gnome_print_moveto(pc, left, top); + gnome_print_show(pc, outbuffer); + *wordstart=c; + memcpy(outbuffer, wordstart, o-wordstart); + width = gnome_font_get_width_string_n(font, outbuffer, o-wordstart); + o=outbuffer+(o-wordstart); + wordstart = outbuffer; + top -= font->size; + if (top<bottom) { + /* too much to fit, drop the rest */ + g_free(outbuffer); + return top; + } + if (first) { + left += indent; + maxwidth -= indent; + first=0; + } + } + p++; + } + if (dump==0) { + *o=0; + gnome_print_moveto(pc, left, top); + gnome_print_show(pc, outbuffer); + top -= font->size; + } + g_free(outbuffer); + return top; +} + +/* Used with layout_events(), takes in a list element and returns the start and + * end times for the event corresponding to that element. + */ +static void +event_layout_query_func (GList *instance, time_t *start, time_t *end) +{ + CalObjInstance *coi = instance->data; + + *start = coi->start; + *end = coi->end; +} + +static void +print_day_details (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, + double left, double right, double top, double bottom) +{ + time_t start, end; + GList *l, *events; + int num_slots, *allocations, *slots; + int i; + GnomeFont *font_hour, *font_minute, *font_summary; + double yinc, y, yend, x, xend; + double width=40, slot_width; + char buf[20]; + + yinc = (top-bottom)/24; + + /* fill static detail */ + font_hour = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, yinc/2); + font_minute = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, yinc/3); + font_summary = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, yinc/3); + + gnome_print_setrgbcolor (pc, 0, 0, 0); + + /* internal lines */ + gnome_print_setlinewidth(pc, 0.0); + gnome_print_moveto(pc, left+width, bottom); + gnome_print_lineto(pc, left+width, top); + gnome_print_stroke (pc); + + for (i=0;i<24;i++) { + y = top - yinc*(i+1); + print_border(pc, left+1, left+width-1, y, y+yinc-1, -1.0, 0.9); + gnome_print_setrgbcolor (pc, 0, 0, 0); + + /* the hour label/minute */ + sprintf(buf, "%d", i); + print_text(pc, font_hour, buf, ALIGN_RIGHT, left, left+width/2, y+yinc, y); + switch(i) { + case 12: sprintf(buf, _("pm")); break; + case 0: sprintf(buf, _("am")); break; + default: sprintf(buf, "00"); break; + } + print_text(pc, font_minute, buf, ALIGN_LEFT, left+width/2, left+width/2, y+yinc, y); + + /* internal lines */ + gnome_print_moveto(pc, left+width, y); + gnome_print_lineto(pc, right, y); + gnome_print_stroke (pc); + gnome_print_moveto(pc, left+width/2, y+yinc/2); + gnome_print_lineto(pc, right, y+yinc/2); + gnome_print_stroke (pc); + + } + + start = time_day_begin(whence); + end = time_day_end(start); + + events = cal_client_get_events_in_range (gcal->client, start, end); + + layout_events (events, event_layout_query_func, &num_slots, &allocations, &slots); + + slot_width = (right-left-width)/num_slots; + + for (i = 0, l = events; l != NULL; l = l->next, i++) { + CalObjInstance *coi; + char *str_ico; + iCalObject *ico; + CalObjFindStatus status; + + coi = l->data; + str_ico = cal_client_get_object (gcal->client, coi->uid); + + if (!str_ico) { + /* The object could have disappeared from the server */ + continue; + } + + status = ical_object_find_in_string (coi->uid, str_ico, &ico); + g_free (str_ico); + + switch (status) { + case CAL_OBJ_FIND_SUCCESS: + /* Go on */ + break; + + case CAL_OBJ_FIND_SYNTAX_ERROR: + g_message ("print_day_details(): syntax error in fetched object"); + continue; + + case CAL_OBJ_FIND_NOT_FOUND: + g_message ("print_day_details(): could not find fetched object"); + continue; + } + + y = top - (top - bottom) * (coi->start - start) / (end - start) - 1; + yend = top - (top - bottom) * (coi->end - start) / (end - start) + 1; + x = left + width + slot_width * allocations[i]; + + if (num_slots > 0) + x++; + + xend = x + slots[i] * slot_width - 2; + + print_border (pc, x, xend, y, yend, 0.0, 0.9); + + bound_text (pc, font_summary, ico->summary, x, xend, y, yend, 0); + ical_object_unref (ico); + } + + cal_obj_instance_list_free (events); + g_free (allocations); + g_free (slots); + + print_border (pc, left, right, top, bottom, 1.0, -1.0); + + gtk_object_unref (GTK_OBJECT (font_hour)); + gtk_object_unref (GTK_OBJECT (font_minute)); + gtk_object_unref (GTK_OBJECT (font_summary)); +} + +#if 0 +#define TIME_FMT "%X" +#else +#define TIME_FMT "%l:%M%p" +#endif + +static void +print_day_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, + double left, double right, double top, double bottom, + double size, int totime, int titleformat) +{ + time_t start, end; + GList *l, *events; + int i; + GnomeFont *font_summary; + double y, yend, x, xend, inc, incsmall; + char buf[100]; + double margin; + struct tm tm; + + /* fill static detail */ + font_summary = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, size); + + gnome_print_setfont (pc, font_summary); + + start = time_day_begin(whence); + end = time_day_end(start); + + tm = *localtime(&start); + + format_date(start, titleformat, buf, 100); + titled_box (pc, buf, font_summary, ALIGN_RIGHT | ALIGN_BORDER, + &left, &right, &top, &bottom, 0.0); + + events = cal_client_get_events_in_range (gcal->client, start, end); + + inc = size*0.3; + incsmall = size*0.2; + + y = top-inc; + yend = bottom-incsmall; + + /* do a good rough approximation of the 'widest' time */ + tm.tm_year = 2000; + tm.tm_mon = 12; + tm.tm_mday = 22; + tm.tm_sec = 22; + tm.tm_min = 22; + tm.tm_hour = 23; + strftime(buf, 100, TIME_FMT, &tm); + margin = gnome_font_get_width_string(font_summary, buf); + + for (i=0, l = events; l != NULL; l = l->next, i++) { + CalObjInstance *coi; + char *str_ico; + iCalObject *ico; + CalObjFindStatus status; + + coi = l->data; + str_ico = cal_client_get_object (gcal->client, coi->uid); + + if (!str_ico) { + /* The object could have disappeared from the server */ + continue; + } + + status = ical_object_find_in_string (coi->uid, str_ico, &ico); + g_free (str_ico); + + switch (status) { + case CAL_OBJ_FIND_SUCCESS: + /* Go on */ + break; + + case CAL_OBJ_FIND_SYNTAX_ERROR: + g_message ("print_day_summary(): syntax error in fetched object"); + continue; + + case CAL_OBJ_FIND_NOT_FOUND: + g_message ("print_day_summary(): could not find fetched object"); + continue; + } + + x = left + incsmall; + xend = right - inc; + + if (y - font_summary->size < bottom) + break; + + tm = *localtime (&coi->start); + strftime (buf, 100, TIME_FMT, &tm); + gnome_print_moveto (pc, x + (margin + - gnome_font_get_width_string (font_summary, buf)), + y - font_summary->size); + gnome_print_show (pc, buf); + + if (totime) { + tm = *localtime (&coi->end); + strftime (buf, 100, TIME_FMT, &tm); + gnome_print_moveto (pc, + (x + margin + inc + + (margin + - gnome_font_get_width_string (font_summary, buf))), + y - font_summary->size); + gnome_print_show (pc, buf); + + y = bound_text (pc, font_summary, ico->summary, + x + margin * 2 + inc * 2, xend, + y, yend, 0); + } else { + /* we also indent back after each time is printed */ + y = bound_text (pc, font_summary, ico->summary, + x + margin + inc, xend, + y, yend, -margin + inc); + } + + y += font_summary->size - inc; + + ical_object_unref (ico); + } + + cal_obj_instance_list_free (events); + + gtk_object_unref (GTK_OBJECT (font_summary)); +} + +static void +print_week_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, + double left, double right, double top, double bottom) +{ + double y, l, r, t, b; + time_t now; + int i; + + l = left; + r = (right-left)/2+left; + t = top; + y = (top-bottom)/3; + b = top-y; + now = time_week_begin(whence); /* returns sunday, we need monday */ + now = time_add_day(now, 1); + for (i = 0; i < 7; i++) { + print_day_summary (pc, gcal, now, l, r, t, b, + 10, TRUE, DATE_DAY | DATE_DAYNAME | DATE_MONTH); + now = time_add_day (now, 1); + switch (i) { + case 5: + y /= 2.0; + b += y; + case 0: + case 1: + case 3: + case 4: + t -= y; + b -= y; + break; + case 2: + l = r; + r = right; + t = top; + b = t-y; + break; + case 6: + break; + } + } +} + +static void +print_year_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, + double left, double right, double top, double bottom, int morerows) +{ + double y, x, l, r, t, b; + time_t now; + int xx, yy, rows, cols; + + l = left; + t = top; + if (morerows) { + rows=4; + cols=3; + } else { + rows=3; + cols=4; + } + y = (top-bottom)/rows; + x = (right-left)/cols; + r = l+x; + b = top-y; + now = time_year_begin(whence); + for (yy = 0; yy < rows; yy++) { + t = top - y * yy; + b = t - y; + for (xx = 0; xx < cols; xx++) { + l = left + x * xx; + r = l + x; + print_month_small (pc, gcal, now, + l + 8, r - 8, t - 8, b + 8, DATE_MONTH, 0, 0, TRUE); + now = time_add_month (now, 1); + } + } +} + +static void +print_month_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, + double left, double right, double top, double bottom) +{ + time_t now, today; + int days[42]; + int day; + struct tm tm; + int x, y; + char buf[100]; + GnomeFont *font_days; + + now = time_month_begin(whence); + tm = *localtime (&now); + + /* get month days */ + build_month(tm.tm_mon, tm.tm_year+1900, week_starts_on_monday, days, 0, 0); + + /* a little margin */ + top -= 4; + + /* do day names ... */ + font_days = gnome_font_new_closest ("Times", GNOME_FONT_BOLD, 0, 10); + gnome_print_setfont(pc, font_days); + for (x=0;x<7;x++) { + today = time_add_day(now, days[6+x]); + format_date(today, DATE_DAYNAME, buf, 100); + print_text(pc, font_days, buf, ALIGN_CENTRE, + (right-left)*x/7+left, (right-left)*(x+1)/7+left, + top, top-font_days->size); + } + top -= font_days->size*1.5; + gtk_object_unref (GTK_OBJECT (font_days)); + + for (y=0;y<6;y++) { + for (x=0;x<7;x++) { + day = days[y*7+x]; + if (day!=0) { + print_day_summary (pc, gcal, now, + (right-left)*x/7+left, + (right-left)*(x+1)/7+left, + top - (top-bottom)*y/6, + top - (top-bottom)*(y+1)/6, 6, FALSE, + day==1?(DATE_DAY|DATE_MONTH):DATE_DAY); + now = time_add_day(now, 1); + } + } + } +} + +static void +print_todo_details (GnomePrintContext *pc, GnomeCalendar *gcal, time_t start, time_t end, + double left, double right, double top, double bottom) +{ + GList *l, *todos; + int i; + GnomeFont *font_summary; + double y, yend, x, xend; + + todos = cal_client_get_uids (gcal->client, CALOBJ_TYPE_TODO); + + font_summary = gnome_font_new_closest ("Times", GNOME_FONT_BOOK, 0, 10); + + gnome_print_setrgbcolor (pc, 0, 0, 0); + gnome_print_setlinewidth (pc, 0.0); + + titled_box (pc, _("TODO Items"), font_summary, + ALIGN_CENTRE | ALIGN_BORDER, &left, &right, &top, &bottom, 1.0); + + y = top - 3; + yend = bottom - 2; + + for (i = 0, l = todos; l != NULL; l = l->next, i++) { + char *str_ico; + iCalObject *ico; + CalObjFindStatus status; + + str_ico = cal_client_get_object (gcal->client, l->data); + + if (!str_ico) { + /* The object could have disappeared from the server */ + continue; + } + + status = ical_object_find_in_string (l->data, str_ico, &ico); + g_free (str_ico); + + switch (status) { + case CAL_OBJ_FIND_SUCCESS: + /* Go on */ + break; + + case CAL_OBJ_FIND_SYNTAX_ERROR: + g_message ("print_todo_details(): syntax error in fetched object"); + continue; + + case CAL_OBJ_FIND_NOT_FOUND: + g_message ("print_todo_details(): could not find fetched object"); + continue; + } + + x = left; + xend = right-2; + + if (y < bottom) + break; + + y = bound_text (pc, font_summary, ico->summary, x + 2, xend, y, yend, 0); + y += font_summary->size; + gnome_print_moveto (pc, x, y - 3); + gnome_print_lineto (pc, xend, y - 3); + gnome_print_stroke (pc); + y -= 3; + + ical_object_unref (ico); + } + + cal_obj_uid_list_free (todos); + + gtk_object_unref (GTK_OBJECT (font_summary)); +} + +#if 0 + +static GnomePrintContext * +print_context (int preview, char *paper) +{ + GtkWidget *toplevel, *canvas, *sw; + GnomePrinter *printer; + GnomePrintContext *pc; + + if (preview) { + gtk_widget_push_colormap (gdk_rgb_get_cmap ()); + gtk_widget_push_visual (gdk_rgb_get_visual ()); + + toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_usize (toplevel, 700, 700); + sw = gtk_scrolled_window_new (NULL, NULL); + canvas = gnome_canvas_new_aa (); + gtk_container_add (GTK_CONTAINER (toplevel), sw); + gtk_container_add (GTK_CONTAINER (sw), canvas); + + gnome_canvas_set_pixels_per_unit((GnomeCanvas *)canvas, 1); + + pc = gnome_print_preview_new ((GnomeCanvas *)canvas, paper); + + gtk_widget_show_all (toplevel); + + gtk_widget_pop_visual (); + gtk_widget_pop_colormap (); + } else { + printer = gnome_printer_dialog_new_modal (); + + if (!printer) + return NULL; + + pc = gnome_print_context_new_with_paper_size (printer, paper); + } + + return pc; +} + +#endif + + +typedef enum printview { + VIEW_DAY=0, + VIEW_WEEK, + VIEW_MONTH, + VIEW_YEAR +} printview_t; + +void +print_calendar (GnomeCalendar *gcal, time_t at, printview_t view, int todos) +{ + GnomePrintContext *pc; + const GnomePaper *paper_info; + double l, r, t, b, todo, header; + char buf[100]; + time_t when; + char *paper = "A4"; + GnomePrintMaster *gpm = gnome_print_master_new (); + + pc = gnome_print_master_get_context (gpm); + paper_info = gnome_paper_with_name (paper); + gnome_print_master_set_paper (gpm, paper_info); + +#if 0 + show_print_dialogue (); +#endif + + l = gnome_paper_lmargin (paper_info); + r = gnome_paper_pswidth (paper_info) - gnome_paper_rmargin (paper_info); + t = gnome_paper_psheight (paper_info) - gnome_paper_tmargin (paper_info); + b = gnome_paper_bmargin (paper_info); + + /* depending on the view, do a different output */ + switch (view) { + case VIEW_DAY: { + int i, days = 1; + + for (i = 0; i < days; i++) { + todo = ((r - l) / 5) * 4 + l; + header = t - 70; + print_todo_details (pc, gcal, 0, INT_MAX, todo, r, header, b); + print_day_details (pc, gcal, at, l, todo - 2.0, header, b); + + print_border (pc, l, r, t, header + 2.0, 1.0, 0.9); + + print_month_small (pc, gcal, at, r - 190, r - 104, t - 4, + header + 8, DATE_MONTH | DATE_YEAR, at, at, FALSE); + print_month_small (pc, gcal, time_add_month (at, 1), r - 90, r - 4, t - 4, + header + 8, DATE_MONTH | DATE_YEAR, 0, 0, FALSE); + + format_date (at, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); + print_text_size (pc, 24, buf, ALIGN_LEFT, l + 3, todo, t - 3, header); + + format_date (at, DATE_DAYNAME, buf, 100); + print_text_size (pc, 18, buf, ALIGN_LEFT, l + 3, todo, t - 27 - 4, header); + gnome_print_showpage (pc); + at = time_add_day (at, 1); + } + break; + } + case VIEW_WEEK: + header = t - 70; + print_week_summary (pc, gcal, at, l, r, header, b); + + /* more solid total outline */ + print_border (pc, l, r, header, b, 1.0, -1.0); + + /* header border */ + print_border (pc, l, r, t, header + 2.0, 1.0, 0.9); + + when = time_week_begin (at); + when = time_add_day (when, 1); + + print_month_small (pc, gcal, at, r - 90, r - 4, t - 4, + header + 8, DATE_MONTH | DATE_YEAR, when, time_add_week (when, 1), + FALSE); + print_month_small (pc, gcal, time_add_month (at, -1), r - 190, r - 104, t - 4, + header + 8, DATE_MONTH | DATE_YEAR, when, time_add_week (when, 1), + FALSE); + + format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); + print_text_size (pc, 24, buf, ALIGN_LEFT, l + 3, r, t - 4, header); + + when = time_add_day (when, 6); + format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); + print_text_size (pc, 24, buf, ALIGN_LEFT, l + 3, r, t - 24 - 3, header); + gnome_print_showpage (pc); + break; + + case VIEW_MONTH: + header = t - 70; + gnome_print_rotate (pc, 90); + gnome_print_translate (pc, 0, -gnome_paper_pswidth (paper_info)); + /*print_month_summary(pc, cal, at, l, r, header, b);*/ + print_month_summary (pc, gcal, at, b, t, r - 70, l); + + print_border (pc, b, t, r, r - 72.0, 1.0, 0.9); + + print_month_small (pc, gcal, time_add_month (at, 1), + t - (t - b) / 7 + 2, t - 8, r - 4, r - 68, + DATE_MONTH | DATE_YEAR, 0, 0, FALSE); + print_month_small (pc, gcal, time_add_month (at, -1), + b + 8, b + (t - b) / 7 - 2, r - 4, r - 68, + DATE_MONTH | DATE_YEAR, 0, 0, FALSE); + + /* centered title */ + format_date (at, DATE_MONTH | DATE_YEAR, buf, 100); + print_text_size (pc, 24, buf, ALIGN_CENTRE, b + 3, t, r - 3, l); + gnome_print_showpage (pc); + break; + + case VIEW_YEAR: +#if 0 + /* landscape */ + gnome_print_rotate(pc, 90); + gnome_print_translate(pc, 0, -gnome_paper_pswidth(paper_info)); + print_year_summary(pc, gcal, at, b, t, r-50, l, FALSE); + + /* centered title */ + format_date(at, DATE_YEAR, buf, 100); + print_text_size(pc, 24, buf, ALIGN_CENTRE, b+3, t, r-3, l); +#else + /* portrait */ + print_year_summary(pc, gcal, at, l, r, t-50, b, TRUE); + + /* centered title */ + format_date(at, DATE_YEAR, buf, 100); + print_text_size(pc, 24, buf, ALIGN_CENTRE, l+3, r, t-3, b); +#endif + gnome_print_showpage(pc); + break; + + default: + g_warning("cannot print unknown calendar view\n"); + break; + } + + gnome_print_master_close (gpm); + gnome_print_master_print (gpm); +} + +#if 0 + +/* + Load the printing dialogue box +*/ +static void +show_print_dialogue(void) +{ + GtkWidget *print_dialogue; + GtkWidget *printer_widget; + GtkWidget *paper_widget; + GtkWidget *print_copies; + GtkWidget *table; + + print_dialogue = + gnome_dialog_new(_("Print Calendar"), + GNOME_STOCK_BUTTON_OK, + _("Preview"), + GNOME_STOCK_BUTTON_CANCEL, + NULL); + + table = gtk_table_new(2, 2, FALSE); + gtk_container_add(GTK_CONTAINER(GNOME_DIALOG (print_dialogue)->vbox), GTK_WIDGET (table)); + gtk_widget_show(table); + + printer_widget = gnome_printer_widget_new (); + gtk_table_attach((GtkTable *)table, printer_widget, 1, 2, 0, 2, 0, 0, 4, 4); + gtk_widget_show(printer_widget); + +#if 0 + frame = gtk_frame_new("Select Paper"); + paper_widget = gnome_paper_selector_new (); + gtk_table_attach(table, frame, 0, 1, 0, 1, 0, 0, 4, 4); + gtk_container_add(frame, GTK_WIDGET (paper_widget)); + gtk_widget_show(paper_widget); + gtk_widget_show(frame); +#else + paper_widget = gnome_paper_selector_new (); + gtk_table_attach((GtkTable *)table, paper_widget, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 4, 4); + gtk_widget_show(paper_widget); +#endif + print_copies = gnome_print_copies_new (); + gtk_table_attach((GtkTable *)table, print_copies, 0, 1, 1, 2, 0, 0, 4, 4); + gtk_widget_show(print_copies); + +#if 0 + frame = gtk_frame_new("Print Range"); + gtk_table_attach_defaults(table, frame, 0, 1, 1, 2); + gtk_widget_show(frame); +#endif + + gnome_dialog_run_and_close (GNOME_DIALOG (print_dialogue)); +} + +#endif diff --git a/calendar/gui/print.h b/calendar/gui/print.h new file mode 100644 index 0000000000..64199f5964 --- /dev/null +++ b/calendar/gui/print.h @@ -0,0 +1,22 @@ +/* Evolution calendar - Print support + * + * Copyright (C) 2000 Helix Code, Inc. + * + * Authors: Michael Zucchi <notzed@helixcode.com> + * Federico Mena-Quintero <federico@helixcode.com> + * + * 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. + */ + diff --git a/calendar/gui/quick-view.c b/calendar/gui/quick-view.c deleted file mode 100644 index 5b5dd10014..0000000000 --- a/calendar/gui/quick-view.c +++ /dev/null @@ -1,284 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#include <config.h> -#include <gdk_imlib.h> -#include <gtk/gtkalignment.h> -#include <gtk/gtkframe.h> -#include <gtk/gtkhseparator.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkvbox.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-text.h> -#include <libgnomeui/gnome-uidefs.h> -#include "quick-view.h" -#include "calendar-commands.h" - - -#define QUICK_VIEW_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" - - -static void quick_view_class_init (QuickViewClass *class); -static void quick_view_init (QuickView *qv); - -static gint quick_view_button_release (GtkWidget *widget, GdkEventButton *event); -static gint quick_view_map_event (GtkWidget *widget, GdkEventAny *event); - - -static GtkWindowClass *parent_class; - - -GtkType -quick_view_get_type (void) -{ - static GtkType quick_view_type = 0; - - if (!quick_view_type) { - GtkTypeInfo quick_view_info = { - "QuickView", - sizeof (QuickView), - sizeof (QuickViewClass), - (GtkClassInitFunc) quick_view_class_init, - (GtkObjectInitFunc) quick_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - quick_view_type = gtk_type_unique (gtk_window_get_type (), &quick_view_info); - } - - return quick_view_type; -} - -static void -quick_view_class_init (QuickViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gtk_window_get_type ()); - - widget_class->button_release_event = quick_view_button_release; - widget_class->map_event = quick_view_map_event; -} - -static void -quick_view_init (QuickView *qv) -{ - GTK_WINDOW (qv)->type = GTK_WINDOW_POPUP; - gtk_window_set_position (GTK_WINDOW (qv), GTK_WIN_POS_MOUSE); -} - -static gint -quick_view_button_release (GtkWidget *widget, GdkEventButton *event) -{ - QuickView *qv; - - qv = QUICK_VIEW (widget); - - if (event->button != qv->button) - return FALSE; - - gdk_pointer_ungrab (event->time); - gtk_grab_remove (GTK_WIDGET (qv)); - gtk_widget_hide (GTK_WIDGET (qv)); - - gtk_main_quit (); /* End modality of the quick view */ - return TRUE; -} - -static gint -quick_view_map_event (GtkWidget *widget, GdkEventAny *event) -{ - GdkCursor *cursor; - - cursor = gdk_cursor_new (GDK_ARROW); - gdk_pointer_grab (widget->window, - TRUE, - GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, - GDK_CURRENT_TIME); - gdk_cursor_destroy (cursor); - - return FALSE; -} - -/* Creates the items corresponding to a single calendar object. Takes in the y position of the - * items to create and returns the y position of the next item to create. Also takes in the current - * maximum width for items and returns the new maximum width. - */ -static void -create_items_for_event (QuickView *qv, CalendarObject *co, double *y, double *max_width) -{ - GnomeCanvas *canvas; - GnomeCanvasItem *item; - char start[100], end[100]; - struct tm start_tm, end_tm; - char *str; - GtkArg args[2]; - - /* FIXME: make this nice */ - - canvas = GNOME_CANVAS (qv->canvas); - - start_tm = *localtime (&co->ev_start); - end_tm = *localtime (&co->ev_end); - - if (am_pm_flag) { - strftime (start, sizeof (start), "%I:%M%p", &start_tm); - strftime (end, sizeof (end), "%I:%M%p", &end_tm); - } else { - strftime (start, sizeof (start), "%H:%M", &start_tm); - strftime (end, sizeof (end), "%H:%M", &end_tm); - } - - str = g_strconcat (start, " - ", end, " ", co->ico->summary, NULL); - - item = gnome_canvas_item_new (gnome_canvas_root (canvas), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", *y, - "anchor", GTK_ANCHOR_NW, - "text", str, - "fontset", QUICK_VIEW_FONTSET, - NULL); - - g_free (str); - - /* Measure the text and return the proper size values */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - if (GTK_VALUE_DOUBLE (args[0]) > *max_width) - *max_width = GTK_VALUE_DOUBLE (args[0]); - - *y += GTK_VALUE_DOUBLE (args[1]); -} - -/* Creates the canvas items corresponding to the events in the list */ -static void -setup_event_list (QuickView *qv, GList *event_list) -{ - CalendarObject *co; - GnomeCanvasItem *item; - GtkArg args[2]; - double y, max_width; - - /* If there are no events, then just put a simple label */ - - if (!event_list) { - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (qv->canvas)), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", 0.0, - "anchor", GTK_ANCHOR_NW, - "text", _("No appointments for this day"), - "fontset", QUICK_VIEW_FONTSET, - NULL); - - /* Measure the text and set the proper sizes */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - y = GTK_VALUE_DOUBLE (args[1]); - max_width = GTK_VALUE_DOUBLE (args[0]); - } else { - /* Create the items for all the events in the list */ - - y = 0.0; - max_width = 0.0; - - for (; event_list; event_list = event_list->next) { - co = event_list->data; - create_items_for_event (qv, co, &y, &max_width); - } - } - - /* Set the scrolling region to fit all the items */ - - gnome_canvas_set_scroll_region (GNOME_CANVAS (qv->canvas), - 0.0, 0.0, - max_width, y); - - gtk_widget_set_usize (qv->canvas, max_width, y); -} - -GtkWidget * -quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list) -{ - QuickView *qv; - GtkWidget *vbox; - GtkWidget *w; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - qv = gtk_type_new (quick_view_get_type ()); - qv->calendar = calendar; - - /* Create base widgets for the popup window */ - - w = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_ETCHED_OUT); - gtk_container_add (GTK_CONTAINER (qv), w); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (w), vbox); - - w = gtk_label_new (title); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_set_border_width (GTK_CONTAINER (w), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0); - - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - - qv->canvas = gnome_canvas_new (); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - gtk_container_add (GTK_CONTAINER (w), qv->canvas); - - /* Set up the event list */ - - setup_event_list (qv, event_list); - - return GTK_WIDGET (qv); -} - -void -quick_view_do_popup (QuickView *qv, GdkEventButton *event) -{ - g_return_if_fail (qv != NULL); - g_return_if_fail (IS_QUICK_VIEW (qv)); - g_return_if_fail (event != NULL); - - /* Pop up the window */ - - gtk_widget_show_all (GTK_WIDGET (qv)); - gtk_grab_add (GTK_WIDGET (qv)); - - qv->button = event->button; - - gtk_main (); /* Begin modality */ - - /* The button release event handler will call gtk_main_quit() */ -} diff --git a/calendar/gui/quick-view.h b/calendar/gui/quick-view.h deleted file mode 100644 index 4cb19c63fd..0000000000 --- a/calendar/gui/quick-view.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#ifndef QUICK_VIEW_H -#define QUICK_VIEW_H - -#include <libgnome/gnome-defs.h> -#include <gtk/gtkwindow.h> -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_QUICK_VIEW (quick_view_get_type ()) -#define QUICK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_QUICK_VIEW, QuickView)) -#define QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_QUICK_VIEW, QuickViewClass)) -#define IS_QUICK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_QUICK_VIEW)) -#define IS_QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_QUICK_VIEW)) - - -typedef struct _QuickView QuickView; -typedef struct _QuickViewClass QuickViewClass; - -struct _QuickView { - GtkWindow window; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - GtkWidget *canvas; /* The canvas that displays the contents of the quick view */ - - int button; /* The button that was pressed to pop up the quick view */ -}; - -struct _QuickViewClass { - GtkWindowClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType quick_view_get_type (void); - -/* Creates a new quick view with the specified title and the specified event list. It is associated - * to the specified calendar. The event list must be a list of CalendarObject structures. - */ -GtkWidget *quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list); - -/* Pops up the quick view widget modally and loops until the uses closes it by releasing the mouse - * button. You can destroy the quick view when this function returns. - */ -void quick_view_do_popup (QuickView *qv, GdkEventButton *event); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c deleted file mode 100644 index 766ad965b6..0000000000 --- a/calendar/gui/year-view.c +++ /dev/null @@ -1,744 +0,0 @@ -/* Year view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gtk/gtkmain.h> -#include <gnome.h> -#include <cal-util/timeutil.h> -#include "eventedit.h" -#include "year-view.h" -#include "calendar-commands.h" -#include "mark.h" -#include "quick-view.h" - - -#define HEAD_SPACING 4 /* Spacing between year heading and months */ -#define TITLE_SPACING 1 /* Spacing between title and calendar */ -#define SPACING 4 /* Spacing between months */ - - -static void year_view_class_init (YearViewClass *class); -static void year_view_init (YearView *yv); -static void year_view_destroy (GtkObject *object); -static void year_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void year_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvas *parent_class; - - -GtkType -year_view_get_type (void) -{ - static GtkType year_view_type = 0; - - if (!year_view_type) { - GtkTypeInfo year_view_info = { - "YearView", - sizeof (YearView), - sizeof (YearViewClass), - (GtkClassInitFunc) year_view_class_init, - (GtkObjectInitFunc) year_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info); - } - - return year_view_type; -} - -static void -year_view_class_init (YearViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - object_class->destroy = year_view_destroy; - - widget_class->size_request = year_view_size_request; - widget_class->size_allocate = year_view_size_allocate; -} - -/* Resizes the year view's child items. This is done in the idle loop for - * performance (we avoid resizing on every size allocation). - */ -static gint -idle_handler (gpointer data) -{ - YearView *yv; - GtkArg arg; - double head_height; - double title_height; - double width, height; - double month_width; - double month_height; - double month_yofs; - double xofs, yofs; - double x, y; - int i; - - yv = data; - - /* Compute the size we can use */ - - width = MAX (GTK_WIDGET (yv)->allocation.width, yv->min_width); - height = MAX (GTK_WIDGET (yv)->allocation.height, yv->min_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, width, height); - - width--; - height--; - - /* Get the heights of the heading and the titles */ - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg); - head_height = GTK_VALUE_DOUBLE (arg) + 2 * HEAD_SPACING; - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg); - title_height = GTK_VALUE_DOUBLE (arg); - - /* Offsets */ - - xofs = (width + SPACING) / 3.0; - yofs = (height - head_height + SPACING) / 4.0; - - /* Month item vertical offset */ - - month_yofs = title_height + TITLE_SPACING; - - /* Month item dimensions */ - - month_width = (width - 2 * SPACING) / 3.0; - month_height = (yofs - SPACING) - month_yofs; - - /* Adjust the year heading */ - - gnome_canvas_item_set (yv->heading, - "x", width / 2.0, - "y", (double) HEAD_SPACING, - NULL); - - /* Adjust titles and months */ - - for (i = 0; i < 12; i++) { - x = (i % 3) * xofs; - y = head_height + (i / 3) * yofs; - - gnome_canvas_item_set (yv->titles[i], - "x", x + month_width / 2.0, - "y", y, - NULL); - - gnome_canvas_item_set (yv->mitems[i], - "x", x, - "y", y + month_yofs, - "width", month_width, - "height", month_height, - NULL); - } - - /* Done */ - - yv->need_resize = FALSE; - return FALSE; -} - -/* Marks the year view as needing a resize, which will be performed during the idle loop */ -static void -need_resize (YearView *yv) -{ - if (yv->need_resize) - return; - - yv->need_resize = TRUE; - yv->idle_id = gtk_idle_add (idle_handler, yv); -} - -/* Callback used to destroy the year view's popup menu when the year view itself is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Create a new appointment in the highlighted day from the year view's popup menu */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (yv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (yv->calendar, view_name); - gnome_calendar_goto (yv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_month (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "monthview"); -} - -/* Information for the year view's popup menu */ -static GnomeUIInfo yv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _month"), NULL, jump_to_month, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Returns the popup menu cooresponding to the specified year view. If the menu has not been - * created yet, it creates it and attaches it to the year view. - */ -static GtkWidget * -get_popup_menu (YearView *yv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (yv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (yv_popup_menu); - gtk_object_set_data (GTK_OBJECT (yv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (yv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Executes the year view's popup menu. It may disable/enable some menu items based on the - * specified flags. A pointer to a time_t value containing the specified time data is set in the - * "time_data" object data key of the menu items. - */ -static void -do_popup_menu (YearView *yv, GdkEventButton *event, int allow_new, int allow_day, int allow_week, int allow_month, - int year, int month, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (yv); - - /* Enable/disable items as appropriate */ - - gtk_widget_set_sensitive (yv_popup_menu[0].widget, allow_new); - gtk_widget_set_sensitive (yv_popup_menu[2].widget, allow_day); - gtk_widget_set_sensitive (yv_popup_menu[3].widget, allow_week); - gtk_widget_set_sensitive (yv_popup_menu[4].widget, allow_month); - - /* Set the day item relevant to the context */ - - t = time_from_day (year, month, day); - - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, yv); -} - -/* Creates the quick view when the user clicks on a day */ -static void -do_quick_view_popup (YearView *yv, GdkEventButton *event, int year, int month, int day) -{ - time_t day_start, day_end; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_start = time_from_day (year, month, day); - day_end = time_day_end (day_start); - - list = calendar_get_events_in_range (yv->calendar->client, - day_start, day_end); - - strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_start)); - qv = quick_view_new (yv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - /* calendar_destroy_event_list (list); DELETE */ -} - -/* Event handler for days in the year's month items */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - int child_num, day; - - mitem = GNOME_MONTH_ITEM (data); - child_num = gnome_month_item_child2num (mitem, item); - day = gnome_month_item_num2day (mitem, child_num); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (day == 0) - break; - - if (event->button.button == 1) { - do_quick_view_popup (yv, (GdkEventButton *) event, mitem->year, mitem->month, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (yv, (GdkEventButton *) event, TRUE, TRUE, TRUE, TRUE, - mitem->year, mitem->month, day); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Event handler for whole month items */ -static gint -month_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - - mitem = GNOME_MONTH_ITEM (item); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button != 3) - break; - - do_popup_menu (yv, (GdkEventButton *) event, FALSE, FALSE, FALSE, TRUE, - mitem->year, mitem->month, 1); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Sets up the month item with the specified index -- connects signals for handling events, etc. */ -static void -setup_month_item (YearView *yv, int n) -{ - GnomeCanvasItem *mitem; - GnomeCanvasItem *item; - int i; - - mitem = yv->mitems[n]; - - /* Connect the day signals */ - - for (i = 0; i < 42; i++) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i); - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) day_event, - mitem); - } - - /* Connect the month signals */ - - gtk_signal_connect (GTK_OBJECT (mitem), "event", - (GtkSignalFunc) month_event, - NULL); - - /* Prepare for prelighting */ - - month_item_prepare_prelight (GNOME_MONTH_ITEM (mitem), default_color_func, NULL); -} - -/* Computes the minimum size for the year view and stores it in its internal fields */ -static void -compute_min_size (YearView *yv) -{ - GtkArg args[2]; - double m_width; - double m_height; - double max_width; - double w; - int i; - - /* Compute the minimum size of the year heading */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 2, args); - - m_width = GTK_VALUE_DOUBLE (args[0]); - m_height = 2 * HEAD_SPACING + GTK_VALUE_DOUBLE (args[1]); - - /* Add height of month titles and their spacings */ - - args[0].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &args[0]); - - m_height += 4 * (GTK_VALUE_DOUBLE (args[0]) + TITLE_SPACING); - - /* Add width of month titles */ - - max_width = 0.0; - - for (i = 0; i < 12; i++) { - args[0].name = "text_width"; - gtk_object_getv (GTK_OBJECT (yv->titles[i]), 1, &args[0]); - - w = GTK_VALUE_DOUBLE (args[0]); - if (max_width < w) - max_width = w; - } - - max_width = 3 * max_width + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add width of month items */ - - args[0].name = "width"; - args[1].name = "height"; - gtk_object_getv (GTK_OBJECT (yv->mitems[0]), 2, args); - - max_width = 3 * GTK_VALUE_DOUBLE (args[0]) + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add height of month items */ - - m_height += 4 * GTK_VALUE_DOUBLE (args[1]) + 3 * SPACING; - - /* Finally, set the minimum width and height in the year view */ - - yv->min_width = (int) (m_width + 0.5); - yv->min_height = (int) (m_height + 0.5); -} - -static void -year_view_init (YearView *yv) -{ - int i; - char buf[100]; - struct tm tm; - - memset (&tm, 0, sizeof (tm)); - - /* Heading */ - - yv->heading = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "fontset", HEADING_FONTSET, - "fill_color", "black", - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) { - /* Title */ - - strftime (buf, 100, "%B", &tm); - tm.tm_mon++; - - yv->titles[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "text", buf, - "anchor", GTK_ANCHOR_N, - "fontset", TITLE_FONTSET, - "fill_color", "black", - NULL); - - /* Month item */ - - yv->mitems[i] = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (yv))); - gnome_canvas_item_set (yv->mitems[i], - "anchor", GTK_ANCHOR_NW, - "start_on_monday", week_starts_on_monday, - "heading_fontset", DAY_HEADING_FONTSET, - "day_fontset", NORMAL_DAY_FONTSET, - NULL); - setup_month_item (yv, i); - } - - /* We will need to resize the items when we paint for the first time */ - - yv->old_marked_day = -1; - yv->idle_id = -1; - need_resize (yv); -} - -static void -year_view_destroy (GtkObject *object) -{ - YearView *yv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_YEAR_VIEW (object)); - - yv = YEAR_VIEW (object); - - if (yv->need_resize) { - yv->need_resize = FALSE; - gtk_idle_remove (yv->idle_id); - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -GtkWidget * -year_view_new (GnomeCalendar *calendar, time_t year) -{ - YearView *yv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - yv = gtk_type_new (year_view_get_type ()); - yv->calendar = calendar; - - year_view_colors_changed (yv); - year_view_set (yv, year); - compute_min_size (yv); - - return GTK_WIDGET (yv); -} - -static void -year_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - yv = YEAR_VIEW (widget); - - requisition->width = yv->min_width; - requisition->height = yv->min_height; -} - -static void -year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - yv = YEAR_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - need_resize (yv); -} - -void -year_view_update (YearView *yv, iCalObject *object, int flags) -{ - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - /* If only the summary changed, we don't care */ - - if (object && ((flags & CHANGE_SUMMARY) == flags)) - return; - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (YearView *yv) -{ - time_t t; - struct tm tm; - int month_index, day_index; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (yv->old_marked_day != -1) { - month_index = yv->old_marked_day / 42; - day_index = yv->old_marked_day % 42; - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "fontset", NORMAL_DAY_FONTSET, - NULL); - - yv->old_marked_day = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = *localtime (&t); - - if ((tm.tm_year + 1900) == yv->year) { - month_index = tm.tm_mon; - day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (yv->mitems[month_index]), tm.tm_mday); - g_assert (day_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "fontset", CURRENT_DAY_FONTSET, - NULL); - - yv->old_marked_day = month_index * 42 + day_index; - } -} - -void -year_view_set (YearView *yv, time_t year) -{ - struct tm tm; - char buf[100]; - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - tm = *localtime (&year); - yv->year = tm.tm_year + 1900; - - /* Heading */ - - sprintf (buf, "%d", yv->year); - gnome_canvas_item_set (yv->heading, - "text", buf, - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "year", yv->year, - "month", i, - NULL); - - /* Unmark and re-mark all the months */ - - for (i = 0; i < 12; i++) { - unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i])); - mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), - yv->calendar); - } - - mark_current_day (yv); -} - -void -year_view_time_format_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "start_on_monday", week_starts_on_monday, - NULL); - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -void -year_view_colors_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) { - colorify_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), default_color_func, NULL); - mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), - yv->calendar); - } - - mark_current_day (yv); -} diff --git a/calendar/gui/year-view.h b/calendar/gui/year-view.h deleted file mode 100644 index 77e63366d5..0000000000 --- a/calendar/gui/year-view.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Year view display for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef YEAR_VIEW_H -#define YEAR_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_YEAR_VIEW (year_view_get_type ()) -#define YEAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_YEAR_VIEW, YearView)) -#define YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_YEAR_VIEW, YearViewClass)) -#define IS_YEAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_YEAR_VIEW)) -#define IS_YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_YEAR_VIEW)) - - -typedef struct _YearView YearView; -typedef struct _YearViewClass YearViewClass; - -struct _YearView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year we are displaying */ - - GnomeCanvasItem *heading; /* Big heading with year */ - GnomeCanvasItem *titles[12]; /* Titles for months */ - GnomeCanvasItem *mitems[12]; /* Month items */ - - int old_marked_day; /* The day that is marked as the current day */ - - int min_width; /* Minimum dimensions of year view, used for size_request*/ - int min_height; - - guint idle_id; /* ID of idle handler for resize */ - - int need_resize : 1; /* Specifies whether we need to resize the canvas items or not */ -}; - -struct _YearViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType year_view_get_type (void); - -/* Creates a new year view widget associated to the specified calendar */ -GtkWidget *year_view_new (GnomeCalendar *calendar, time_t year); - -/* Notifies the year view that a calendar object has changed */ -void year_view_update (YearView *yv, iCalObject *ico, int flags); - -/* Notifies the year view about a change of date */ -void year_view_set (YearView *yv, time_t year); - -/* Notifies the year view that the time format has changed */ -void year_view_time_format_changed (YearView *yv); - -/* Notifies the year view that colors have changed */ -void year_view_colors_changed (YearView *yv); - - -END_GNOME_DECLS - -#endif diff --git a/e-util/ChangeLog b/e-util/ChangeLog index ffad50d570..a4a005b05d 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,19 @@ +2000-05-23 Federico Mena Quintero <federico@helixcode.com> + + * e-dialog-widgets.c (get_radio_value): Implemented. Amazing that + one has to go through so much pain to get a stupid value from + GTK+. + (hook_option_menu): Implemented. Same complaint. + (get_toggle_value): Implemented. + (get_spin_button_value): Implemented. + (get_entry_value): Implemented. + (e_dialog_widget_hook_value): Function to hook a widget to the + variable it will modify. + (e_dialog_get_values): Function to feed the variables from a + dialog's widgets. + (e_dialog_xml_widget_hook_value): Function to hook a widget from + a Glade file. + 2000-05-23 Christopher James Lahey <clahey@helixcode.com> * e-util.c, e-util.h: Added e_write_file. diff --git a/e-util/e-dialog-widgets.c b/e-util/e-dialog-widgets.c index 283e6f95b6..92285232b6 100644 --- a/e-util/e-dialog-widgets.c +++ b/e-util/e-dialog-widgets.c @@ -30,9 +30,16 @@ +/* A widget, a pointer to the variable it will modify, and extra information */ typedef struct { - /* Widgets that are hooked */ - GSList *widgets; + GtkWidget *widget; + gpointer value_var; + gpointer info; +} WidgetHook; + +/* Hook information for a complete dialog */ +typedef struct { + GSList *whooks; } DialogHooks; @@ -45,8 +52,8 @@ dialog_destroy_cb (GtkObject *dialog, gpointer data) hooks = data; - g_slist_free (hooks->widgets); - hooks->widgets = NULL; + g_slist_free (hooks->whooks); + hooks->whooks = NULL; g_free (hooks); gtk_object_set_data (dialog, "dialog-hooks", NULL); @@ -156,6 +163,41 @@ hook_radio (GtkWidget *dialog, GtkRadioButton *radio, gpointer value_var, gpoint GTK_SIGNAL_FUNC (toggled_cb), dialog); } +/* Gets the value of a radio button group */ +static void +get_radio_value (GtkRadioButton *radio, gpointer value_var, gpointer info) +{ + GSList *group; + GSList *l; + int i; + int *value; + const int *value_map; + int v; + + group = gtk_radio_button_group (radio); + + for (i = 0, l = group; l; l = l->next) { + radio = GTK_RADIO_BUTTON (l->data); + + if (GTK_TOGGLE_BUTTON (radio)->active) + break; + } + + if (!l) + g_assert_not_reached (); + + value = (int *) value_var; + value_map = (const int *) info; + + v = index_to_value (value_map, i); + if (v == -1) { + g_message ("get_radio_value(): could not find index %d in value map!", i); + return; + } + + *value = v; +} + /* Callback for the "activate" signal of menu items */ static void activate_cb (GtkMenuItem *item, gpointer data) @@ -199,6 +241,46 @@ hook_option_menu (GtkWidget *dialog, GtkOptionMenu *omenu, gpointer value_var, g } } +/* Gets the value of an option menu */ +static void +get_option_menu_value (GtkOptionMenu *omenu, gpointer value_var, gpointer info) +{ + GtkMenu *menu; + GtkWidget *active; + GList *children; + GList *l; + int i; + int *value; + const int *value_map; + int v; + + menu = GTK_MENU (gtk_option_menu_get_menu (omenu)); + + active = gtk_menu_get_active (menu); + g_assert (active != NULL); + + children = GTK_MENU_SHELL (menu)->children; + + for (i = 0, l = children; l; l = l->next) { + if (GTK_WIDGET (l->data) == active) + break; + } + + if (!l) + g_assert_not_reached (); + + value = (int *) value_var; + value_map = (const int *) info; + + v = index_to_value (value_map, i); + if (v == -1) { + g_message ("get_option_menu_value(): could not find index %d in value map!", i); + return; + } + + *value = v; +} + /* Hooks a toggle button */ static void hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpointer info) @@ -217,6 +299,16 @@ hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpo GTK_SIGNAL_FUNC (toggled_cb), dialog); } +/* Gets the value of a toggle button */ +static void +get_toggle_value (GtkToggleButton *toggle, gpointer value_var, gpointer info) +{ + gboolean *value; + + value = (gboolean *) value; + *value = toggle->active ? TRUE : FALSE; +} + /* Callback for the "value_changed" signal of the adjustment of a spin button */ static void value_changed_cb (GtkAdjustment *adj, gpointer data) @@ -249,10 +341,58 @@ hook_spin_button (GtkWidget *dialog, GtkSpinButton *spin, gpointer value_var, gp GTK_SIGNAL_FUNC (value_changed_cb), dialog); } +/* Gets the value of a spin button */ +static void +get_spin_button_value (GtkSpinButton *spin, gpointer value_var, gpointer info) +{ + double *value; + GtkAdjustment *adj; + + value = (double *) value_var; + + adj = gtk_spin_button_get_adjustment (spin); + *value = adj->value; +} + +/* Callback for the "changed" signal of an entry widget */ +static void +changed_cb (GtkEntry *entry, gpointer data) +{ + GnomePropertyBox *pbox; + + pbox = GNOME_PROPERTY_BOX (data); + gnome_property_box_changed (pbox); +} + /* Hooks an entry widget */ static void hook_entry (GtkWidget *dialog, GtkEntry *entry, gpointer value_var, gpointer info) { + char **value; + + /* Set the value */ + + value = (char **) value_var; + gtk_entry_set_text (entry, *value); + + /* Hook to changed */ + + if (GNOME_IS_PROPERTY_BOX (dialog)) + gtk_signal_connect (GTK_OBJECT (entry), "changed", + GTK_SIGNAL_FUNC (changed_cb), dialog); +} + +/* Gets the value of an entry widget */ +static void +get_entry_value (GtkEntry *entry, gpointer value_var, gpointer data) +{ + char **value; + + value = (char **) value_var; + if (*value) + g_free (*value); + + *value = g_strdup (gtk_entry_get_text (entry)); } gboolean @@ -260,6 +400,7 @@ e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, gpointer value_var, gpointer info) { DialogHooks *hooks; + WidgetHook *wh; g_return_val_if_fail (dialog != NULL, FALSE); g_return_val_if_fail (widget != NULL, FALSE); @@ -285,7 +426,64 @@ e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, else return FALSE; - hooks->widgets = g_slist_prepend (hooks->widgets, widget); + wh = g_new (WidgetHook, 1); + wh->widget = widget; + wh->value_var = value_var; + wh->info = info; + + hooks->whooks = g_slist_prepend (hooks->whooks, wh); return TRUE; } + +void +e_dialog_get_values (GtkWidget *dialog) +{ + DialogHooks *hooks; + GSList *l; + + g_return_if_fail (dialog != NULL); + + hooks = get_dialog_hooks (dialog); + + for (l = hooks->whooks; l; l = l->next) { + WidgetHook *wh; + + wh = l->data; + + if (GTK_IS_RADIO_BUTTON (wh->widget)) + get_radio_value (GTK_RADIO_BUTTON (wh->widget), wh->value_var, wh->info); + else if (GTK_IS_OPTION_MENU (wh->widget)) + get_option_menu_value (GTK_OPTION_MENU (wh->widget), wh->value_var, wh->info); + else if (GTK_IS_TOGGLE_BUTTON (wh->widget)) + get_toggle_value (GTK_TOGGLE_BUTTON (wh->widget), wh->value_var, wh->info); + else if (GTK_IS_SPIN_BUTTON (wh->widget)) + get_spin_button_value (GTK_SPIN_BUTTON (wh->widget), wh->value_var, wh->info); + else if (GTK_IS_ENTRY (wh->widget)) + get_entry_value (GTK_ENTRY (wh->widget), wh->value_var, wh->info); + else + g_assert_not_reached (); + } +} + +gboolean +e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const char *widget_name, + gpointer value_var, gpointer info) +{ + GtkWidget *widget; + + g_return_val_if_fail (xml != NULL, FALSE); + g_return_val_if_fail (GLADE_IS_XML (xml), FALSE); + g_return_val_if_fail (dialog != NULL, FALSE); + g_return_val_if_fail (widget_name != NULL, FALSE); + g_return_val_if_fail (value_var != NULL, FALSE); + + widget = glade_xml_get_widget (xml, widget_name); + if (!widget) { + g_message ("e_dialog_xml_widget_hook_value(): could not find widget `%s' in " + "Glade data!", widget_name); + return FALSE; + } + + return e_dialog_widget_hook_value (dialog, widget, value_var, info); +} |