diff options
Diffstat (limited to 'calendar/gui')
171 files changed, 0 insertions, 75525 deletions
diff --git a/calendar/gui/.cvsignore b/calendar/gui/.cvsignore deleted file mode 100644 index 19b64f5154..0000000000 --- a/calendar/gui/.cvsignore +++ /dev/null @@ -1,23 +0,0 @@ -Makefile.in -Makefile -.deps -_libs -.libs -.pure -evolution-calendar -evolution-calendar.pure -evolution-calendar.h -evolution-calendar-common.c -evolution-calendar-skels.c -evolution-calendar-stubs.c -*.lo -Evolution-Addressbook-SelectNames-common.c -Evolution-Addressbook-SelectNames-skels.c -Evolution-Addressbook-SelectNames-stubs.c -Evolution-Addressbook-SelectNames.h -Evolution-Composer-common.c -Evolution-Composer-skels.c -Evolution-Composer-stubs.c -Evolution-Composer.h -GNOME_Evolution_Calendar.server -GNOME_Evolution_Calendar.server.in diff --git a/calendar/gui/GNOME_Evolution_Calendar.server.in.in b/calendar/gui/GNOME_Evolution_Calendar.server.in.in deleted file mode 100644 index 801cada120..0000000000 --- a/calendar/gui/GNOME_Evolution_Calendar.server.in.in +++ /dev/null @@ -1,129 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_Factory" - type="shlib" - location="@COMPONENTDIR@/libevolution-calendar.so"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar and Tasks"/> - -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_iTip_Control" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:Bonobo/Control:1.0"/> - <item value="IDL:Bonobo/PersistStream:1.0"/> - </oaf_attribute> - - <oaf_attribute name="bonobo:supported_mime_types" type="stringv"> - <item value="text/calendar"/> - <item value="text/x-calendar"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar scheduling message viewer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_ShellComponent" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/ShellComponent:1.0"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar and Tasks component"/> - - <oaf_attribute name="evolution:shell_component_icon" type="string" - value="evolution-calendar.png"/> - <oaf_attribute name="evolution:shell_component_launch_order" type="number" - value="3"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_Control" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:BonoboControl/calendar-control:1.0"/> - <item value="IDL:Bonobo/Control:1.0"/> - <item value="IDL:Bonobo/PropertyBag:1.0"/> - </oaf_attribute> - - <oaf_attribute name="bonobo:supported_mime_types" type="stringv"> - <item value="text/calendar"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar viewer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Tasks_Control" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:BonoboControl/tasks-control:1.0"/> - <item value="IDL:Bonobo/Control:1.0"/> - <item value="IDL:Bonobo/PropertyBag:1.0"/> - </oaf_attribute> - - <oaf_attribute name="bonobo:supported_mime_types" type="stringv"> - <item value="text/calendar"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Tasks viewer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_CompEditorFactory" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Calendar/CompEditorFactory:1.0"/> - <item value="IDL:Bonobo/Unknown:1.0"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar/Task editor"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_ConfigControl" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/ConfigControl:1.0"/> - </oaf_attribute> - - <oaf_attribute name="evolution:config_item:title" type="string" - _value="Calendar and Tasks"/> - - <oaf_attribute name="evolution:config_item:description" type="string" - _value="Configure your timezone, Calendar and Task List here "/> - - <oaf_attribute name="evolution:config_item:icon_name" type="string" - value="evolution-calendar.png"/> - - <oaf_attribute name="evolution:config_item:type" type="stringv"> - <item value="calendar"/> - <item value="tasks"/> - </oaf_attribute> - - <oaf_attribute name="evolution:config_item:priority" type="string" value="-7"/> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar configuration control"/> - -</oaf_server> - -</oaf_info> diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am deleted file mode 100644 index 9c58cce4a7..0000000000 --- a/calendar/gui/Makefile.am +++ /dev/null @@ -1,226 +0,0 @@ -## CORBA stuff - -IDLS = \ - $(top_srcdir)/composer/Evolution-Composer.idl \ - $(top_srcdir)/calendar/idl/evolution-calendar.idl \ - $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl - -# Message composer IDL files - -COMPOSER_IDL_GENERATED_H = \ - Evolution-Composer.h -COMPOSER_IDL_GENERATED_C = \ - Evolution-Composer-common.c \ - Evolution-Composer-skels.c \ - Evolution-Composer-stubs.c -COMPOSER_IDL_GENERATED = $(COMPOSER_IDL_GENERATED_C) $(COMPOSER_IDL_GENERATED_H) - -$(COMPOSER_IDL_GENERATED_H): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) $(IDL_INCLUDES) \ - $(srcdir)/../../composer/Evolution-Composer.idl -$(COMPOSER_IDL_GENERATED_C): $(COMPOSER_IDL_GENERATED_H) - - -# SelectNames IDL files - -SELECT_NAMES_IDL_GENERATED_H = \ - Evolution-Addressbook-SelectNames.h -SELECT_NAMES_IDL_GENERATED_C = \ - Evolution-Addressbook-SelectNames-common.c \ - Evolution-Addressbook-SelectNames-skels.c \ - Evolution-Addressbook-SelectNames-stubs.c -SELECT_NAMES_IDL_GENERATED = $(SELECT_NAMES_IDL_GENERATED_C) $(SELECT_NAMES_IDL_GENERATED_H) - -$(SELECT_NAMES_IDL_GENERATED_H): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) $(IDL_INCLUDES) \ - $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl -$(SELECT_NAMES_IDL_GENERATED_C): $(SELECT_NAMES_IDL_GENERATED_H) - - -# Calendar IDL files - -CALENDAR_IDL_GENERATED_H = \ - evolution-calendar.h -CALENDAR_IDL_GENERATED_C = \ - evolution-calendar-common.c \ - evolution-calendar-skels.c \ - evolution-calendar-stubs.c -CALENDAR_IDL_GENERATED = $(CALENDAR_IDL_GENERATED_C) $(CALENDAR_IDL_GENERATED_H) - -$(CALENDAR_IDL_GENERATED_H): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) $(IDL_INCLUDES) \ - $(top_srcdir)/calendar/idl/evolution-calendar.idl -$(CALENDAR_IDL_GENERATED_C): $(CALENDAR_IDL_GENERATED_H) - - -IDL_GENERATED = $(COMPOSER_IDL_GENERATED) $(SELECT_NAMES_IDL_GENERATED) $(CALENDAR_IDL_GENERATED) - - -SUBDIRS = alarm-notify dialogs - -component_LTLIBRARIES = libevolution-calendar.la - -INCLUDES = \ - -DG_LOG_DOMAIN=\"calendar-gui\" \ - -I$(top_builddir)/shell \ - -I$(top_srcdir)/shell \ - -I$(top_srcdir) \ - -I$(top_srcdir)/calendar \ - -I$(top_srcdir)/calendar/cal-client \ - -I$(top_builddir)/calendar/cal-client \ - -I$(top_srcdir)/libical/src/libical \ - -I$(top_builddir)/libical/src/libical \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_builddir)/addressbook/backend \ - -I$(top_srcdir)/widgets \ - -DEVOLUTION_DATADIR=\""$(datadir)"\" \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \ - -DEVOLUTION_GALVIEWSDIR=\""$(viewsdir)"\" \ - -DEVOLUTION_UIDIR=\""$(evolutionuidir)"\" \ - -DPREFIX=\""$(prefix)"\" \ - $(EVOLUTION_CALENDAR_CFLAGS) - -glade_DATA = \ - e-itip-control.glade \ - goto-dialog.glade - -etspec_DATA = e-calendar-table.etspec e-meeting-time-sel.etspec - -libevolution_calendar_la_SOURCES = \ - $(IDL_GENERATED) \ - cal-search-bar.c \ - cal-search-bar.h \ - calendar-config.c \ - calendar-config.h \ - calendar-commands.c \ - calendar-commands.h \ - calendar-component.c \ - calendar-component.h \ - calendar-model.c \ - calendar-model.h \ - calendar-offline-handler.c \ - calendar-offline-handler.h \ - calendar-view.c \ - calendar-view.h \ - calendar-view-factory.c \ - calendar-view-factory.h \ - comp-editor-factory.c \ - comp-editor-factory.h \ - comp-util.c \ - comp-util.h \ - control-factory.c \ - control-factory.h \ - e-alarm-list.c \ - e-alarm-list.h \ - e-calendar-table.h \ - e-calendar-table.c \ - e-cell-date-edit-text.h \ - e-cell-date-edit-text.c \ - e-comp-editor-registry.c \ - e-comp-editor-registry.h \ - e-date-time-list.c \ - e-date-time-list.h \ - e-day-view-layout.c \ - e-day-view-layout.h \ - e-day-view-main-item.c \ - e-day-view-main-item.h \ - e-day-view-time-item.c \ - e-day-view-time-item.h \ - e-day-view-top-item.c \ - e-day-view-top-item.h \ - e-day-view.c \ - e-day-view.h \ - e-itip-control.h \ - e-itip-control.c \ - e-meeting-attendee.c \ - e-meeting-attendee.h \ - e-meeting-model.c \ - e-meeting-model.h \ - e-meeting-time-sel.c \ - e-meeting-time-sel.h \ - e-meeting-time-sel-item.c \ - e-meeting-time-sel-item.h \ - e-meeting-types.h \ - e-meeting-utils.c \ - e-meeting-utils.h \ - e-week-view-event-item.c \ - e-week-view-event-item.h \ - e-week-view-layout.c \ - e-week-view-layout.h \ - e-week-view-main-item.c \ - e-week-view-main-item.h \ - e-week-view-titles-item.c \ - e-week-view-titles-item.h \ - e-week-view.c \ - e-week-view.h \ - e-tasks.c \ - e-tasks.h \ - e-timezone-entry.c \ - e-timezone-entry.h \ - gnome-cal.c \ - gnome-cal.h \ - goto.c \ - goto.h \ - itip-bonobo-control.c \ - itip-bonobo-control.h \ - itip-utils.c \ - itip-utils.h \ - main.c \ - misc.c \ - misc.h \ - print.c \ - print.h \ - tag-calendar.c \ - tag-calendar.h \ - tasks-control.c \ - tasks-control.h \ - weekday-picker.c \ - weekday-picker.h - -libevolution_calendar_la_LIBADD = \ - $(DB3_LDADD) \ - $(top_builddir)/widgets/menus/libmenus.la \ - $(top_builddir)/shell/libeshell.la \ - $(top_builddir)/calendar/cal-client/libcal-client.la \ - $(top_builddir)/addressbook/backend/ebook/libebook.la \ - $(top_builddir)/calendar/gui/dialogs/libcal-dialogs.la \ - $(top_builddir)/widgets/e-timezone-dialog/libetimezonedialog.la \ - $(top_builddir)/widgets/misc/libemiscwidgets.la \ - $(EVOLUTION_CALENDAR_LIBS) - -libevolution_calendar_la_LDFLAGS = -avoid-version -module - -server_in_files = GNOME_Evolution_Calendar.server.in.in - -server_DATA = $(server_in_files:.server.in.in=.server) -$(server_in_files:.server.in.in=.server.in): $(server_in_files) - sed -e "s|\@COMPONENTDIR\@|$(componentdir)|" $< > $@ - -# GConf schemas - -schemadir = $(GCONF_SCHEMA_FILE_DIR) -schema_DATA = apps_evolution_calendar.schemas - -@INTLTOOL_SERVER_RULE@ - -EXTRA_DIST = \ - $(glade_DATA) \ - $(schema_DATA) \ - $(etspec_DATA) \ - $(server_in_files) - -BUILT_SOURCES = $(IDL_GENERATED) -CLEANFILES = $(BUILT_SOURCES) - -install-data-local: - $(mkinstalldirs) $(Conduitsdir); \ - if test -z "$(DESTDIR)"; then \ - for p in $(schema_DATA); do \ - GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(srcdir)/$$p; \ - done; \ - fi - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) diff --git a/calendar/gui/alarm-notify/.cvsignore b/calendar/gui/alarm-notify/.cvsignore deleted file mode 100644 index 5d0cf13a94..0000000000 --- a/calendar/gui/alarm-notify/.cvsignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -evolution-calendar-stubs.c -evolution-calendar-skels.c -evolution-calendar-common.c -evolution-calendar.h -evolution-alarm-notify -GNOME_Evolution_Calendar_AlarmNotify.server -GNOME_Evolution_Calendar_AlarmNotify.server.in diff --git a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in b/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in deleted file mode 100644 index 4b34fbdc7b..0000000000 --- a/calendar/gui/alarm-notify/GNOME_Evolution_Calendar_AlarmNotify.server.in.in +++ /dev/null @@ -1,24 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory" - type="exe" - location="@LIBEXECDIR@/evolution-alarm-notify"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar alarm notification service"/> - -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Calendar_AlarmNotify" - type="factory" - location="OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory"> - - <oaf_attribute name="name" type="string" - _value="Evolution Calendar alarm notification service"/> -</oaf_server> - -</oaf_info> diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am deleted file mode 100644 index a85e99a9cf..0000000000 --- a/calendar/gui/alarm-notify/Makefile.am +++ /dev/null @@ -1,72 +0,0 @@ -CORBA_GENERATED_H = \ - evolution-calendar.h -CORBA_GENERATED_C = \ - evolution-calendar-common.c \ - evolution-calendar-skels.c \ - evolution-calendar-stubs.c -CORBA_GENERATED = $(CORBA_GENERATED_C) $(CORBA_GENERATED_H) - -idls = $(top_srcdir)/calendar/idl/evolution-calendar.idl -idl_flags = $(IDL_INCLUDES) - -$(CORBA_GENERATED_H): $(idls) - $(ORBIT_IDL) $(idl_flags) $(top_srcdir)/calendar/idl/evolution-calendar.idl -$(CORBA_GENERATED_C): $(CORBA_GENERATED_H) - - -privlibexec_PROGRAMS = evolution-alarm-notify - - -INCLUDES = \ - -DG_LOG_DOMAIN=\"evolution-alarm-notify\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/calendar \ - -I$(top_builddir)/calendar \ - -I$(top_srcdir)/libical/src/libical \ - -I$(top_builddir)/libical/src/libical \ - -I$(top_srcdir)/widgets \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ - $(EVOLUTION_CALENDAR_CFLAGS) - -glade_DATA = \ - alarm-notify.glade - -evolution_alarm_notify_SOURCES = \ - $(CORBA_GENERATED) \ - alarm.c \ - alarm.h \ - alarm-notify.c \ - alarm-notify.h \ - alarm-notify-dialog.c \ - alarm-notify-dialog.h \ - alarm-queue.c \ - alarm-queue.h \ - config-data.c \ - config-data.h \ - notify-main.c \ - save.c \ - save.h - -evolution_alarm_notify_LDADD = \ - $(top_builddir)/calendar/cal-client/libcal-client.la \ - $(top_builddir)/calendar/cal-util/libcal-util.la \ - $(EVOLUTION_CALENDAR_LIBS) - -server_in_files = \ - GNOME_Evolution_Calendar_AlarmNotify.server.in.in - -server_DATA = $(server_in_files:.server.in.in=.server) -$(server_in_files:.server.in.in=.server.in): $(server_in_files) - sed -e "s|\@LIBEXECDIR\@|$(privlibexecdir)|" $< > $@ - -@INTLTOOL_SERVER_RULE@ - -EXTRA_DIST = \ - $(server_DATA) \ - $(server_in_files) \ - $(glade_DATA) - -BUILT_SOURCES = $(CORBA_GENERATED) -CLEANFILES = $(BUILT_SOURCES) diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.c b/calendar/gui/alarm-notify/alarm-notify-dialog.c deleted file mode 100644 index f128701708..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.c +++ /dev/null @@ -1,416 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <stdio.h> -#include <string.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtkwindow.h> -#include <libgnome/gnome-i18n.h> -#if 0 -# include <libgnomeui/gnome-winhints.h> -#endif -#include <libgnomeui/gnome-window-icon.h> -#include <glade/glade.h> -#include <e-util/e-time-utils.h> -#include <gal/widgets/e-unicode.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> -#include "cal-util/timeutil.h" -#include "alarm-notify-dialog.h" -#include "config-data.h" - - -GtkWidget *make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow); - -/* The useful contents of the alarm notify dialog */ -typedef struct { - GladeXML *xml; - - GtkWidget *dialog; - GtkWidget *close; - GtkWidget *snooze; - GtkWidget *edit; - GtkWidget *snooze_time; - GtkWidget *html; - - AlarmNotifyFunc func; - gpointer func_data; -} AlarmNotify; - - - -/* Callback used when the notify dialog is destroyed */ -static void -dialog_destroy_cb (GtkObject *object, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_object_unref (an->xml); - g_free (an); -} - -/* Delete_event handler for the alarm notify dialog */ -static gint -delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); - - gtk_widget_destroy (widget); - return TRUE; -} - -/* Callback for the close button */ -static void -close_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_CLOSE, -1, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -/* Callback for the snooze button */ -static void -snooze_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - int snooze_time; - - an = data; - g_assert (an->func != NULL); - - snooze_time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (an->snooze_time)); - (* an->func) (ALARM_NOTIFY_SNOOZE, snooze_time, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -/* Callback for the edit button */ -static void -edit_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmNotify *an; - - an = data; - g_assert (an->func != NULL); - - (* an->func) (ALARM_NOTIFY_EDIT, -1, an->func_data); - - gtk_widget_destroy (an->dialog); -} - -static void -url_requested_cb (GtkHTML *html, const char *url, GtkHTMLStream *stream, gpointer data) -{ - - if (!strncmp ("file:///", url, strlen ("file:///"))) { - FILE *fp; - const char *filename = url + strlen ("file://"); - char buf[4096]; - size_t len; - - fp = fopen (filename, "r"); - - if (fp == NULL) { - g_warning ("Error opening image: %s\n", url); - gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); - return; - } - - while ((len = fread (buf, 1, sizeof(buf), fp)) > 0) - gtk_html_stream_write (stream, buf, len); - - if (feof (fp)) { - fclose (fp); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); - return; - } - - fclose (fp); - } - - g_warning ("Error loading image"); - gtk_html_stream_close (stream, GTK_HTML_STREAM_ERROR); - return; -} - -GtkWidget * -make_html_display (gchar *widget_name, char *s1, char *s2, int scroll, int shadow) -{ - GtkWidget *html, *scrolled_window; - - gtk_widget_push_colormap (gdk_rgb_get_colormap ()); - - html = gtk_html_new(); - - gtk_html_set_default_content_type (GTK_HTML (html), - "charset=utf-8"); - gtk_html_load_empty (GTK_HTML (html)); - - g_signal_connect (html, "url_requested", - G_CALLBACK (url_requested_cb), - NULL); - - gtk_widget_pop_colormap(); - - scrolled_window = gtk_scrolled_window_new(NULL, NULL); - - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_SHADOW_IN); - - gtk_widget_set_size_request (scrolled_window, 300, 200); - - gtk_container_add(GTK_CONTAINER (scrolled_window), html); - - gtk_widget_show_all(scrolled_window); - - g_object_set_data (G_OBJECT (scrolled_window), "html", html); - return scrolled_window; -} - -static void -write_times (GtkHTMLStream *stream, char *start, char *end) -{ - if (start) - gtk_html_stream_printf (stream, "<b>%s</b> %s<br>", _("Starting:"), start); - if (end) - gtk_html_stream_printf (stream, "<b>%s</b> %s<br>", _("Ending:"), end); - -} - -/* Converts a time_t to a string, relative to the specified timezone */ -static char * -timet_to_str_with_zone (time_t t, icaltimezone *zone) -{ - struct icaltimetype itt; - struct tm tm; - char buf[256]; - - if (t == -1) - return g_strdup (_("invalid time")); - - itt = icaltime_from_timet_with_zone (t, FALSE, zone); - tm = icaltimetype_to_tm (&itt); - - e_time_format_date_and_time (&tm, config_data_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - return g_strdup (buf); -} - -/* Creates a heading for the alarm notification dialog */ -static void -write_html_heading (GtkHTMLStream *stream, const char *message, - CalComponentVType vtype, time_t occur_start, time_t occur_end) -{ - char *buf; - char *start, *end; - char *bg_path = "file://" EVOLUTION_IMAGESDIR "/bcg.png"; - char *image_path = "file://" EVOLUTION_IMAGESDIR "/alarm.png"; - icaltimezone *current_zone; - - /* Stringize the times */ - - current_zone = config_data_get_timezone (); - - buf = timet_to_str_with_zone (occur_start, current_zone); - start = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - g_free (buf); - - buf = timet_to_str_with_zone (occur_end, current_zone); - end = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - g_free (buf); - - /* Write the header */ - - gtk_html_stream_printf (stream, - "<HTML><BODY background=\"%s\">" - "<TABLE WIDTH=\"100%%\">" - "<TR>" - "<TD><IMG SRC=\"%s\" ALIGN=\"top\" BORDER=\"0\"></TD>" - "<TD><H1>%s</H1></TD>" - "</TR>" - "</TABLE>", - bg_path, - image_path, - _("Evolution Alarm")); - - gtk_html_stream_printf (stream, "<br><br><font size=\"+2\">%s</font><br><br>", message); - - /* Write the times */ - - switch (vtype) { - case CAL_COMPONENT_EVENT: - write_times (stream, start, end); - break; - - case CAL_COMPONENT_TODO: - write_times (stream, start, end); - break; - - default: - /* Only VEVENTs and VTODOs can have alarms */ - g_assert_not_reached (); - break; - } - - g_free (start); - g_free (end); -} - -/** - * alarm_notify_dialog: - * @trigger: Trigger time for the alarm. - * @occur_start: Start of occurrence time for the event. - * @occur_end: End of occurrence time for the event. - * @vtype: Type of the component which corresponds to the alarm. - * @message; Message to display in the dialog; usually comes from the component. - * @func: Function to be called when a dialog action is invoked. - * @func_data: Closure data for @func. - * - * Runs the alarm notification dialog. The specified @func will be used to - * notify the client about result of the actions in the dialog. - * - * Return value: a pointer to the dialog structure if successful or NULL if an error occurs. - **/ -gpointer -alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - CalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data) -{ - AlarmNotify *an; - GtkHTMLStream *stream; - icaltimezone *current_zone; - char *buf, *title; - - g_return_val_if_fail (trigger != -1, NULL); - - /* Only VEVENTs or VTODOs can have alarms */ - g_return_val_if_fail (vtype == CAL_COMPONENT_EVENT || vtype == CAL_COMPONENT_TODO, NULL); - g_return_val_if_fail (message != NULL, NULL); - g_return_val_if_fail (func != NULL, NULL); - - an = g_new0 (AlarmNotify, 1); - - an->func = func; - an->func_data = func_data; - - an->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-notify.glade", NULL, NULL); - if (!an->xml) { - g_message ("alarm_notify_dialog(): Could not load the Glade XML file!"); - g_free (an); - return NULL; - } - - an->dialog = glade_xml_get_widget (an->xml, "alarm-notify"); - an->close = glade_xml_get_widget (an->xml, "close"); - an->snooze = glade_xml_get_widget (an->xml, "snooze"); - an->edit = glade_xml_get_widget (an->xml, "edit"); - an->snooze_time = glade_xml_get_widget (an->xml, "snooze-time"); - an->html = g_object_get_data (G_OBJECT (glade_xml_get_widget (an->xml, "frame")), "html"); - - if (!(an->dialog && an->close && an->snooze && an->edit - && an->snooze_time)) { - g_message ("alarm_notify_dialog(): Could not find all widgets in Glade file!"); - g_object_unref (an->xml); - g_free (an); - return NULL; - } - - g_signal_connect (G_OBJECT (an->dialog), "destroy", - G_CALLBACK (dialog_destroy_cb), - an); - - /* Title */ - - current_zone = config_data_get_timezone (); - - buf = timet_to_str_with_zone (trigger, current_zone); - title = g_strdup_printf (_("Alarm on %s"), buf); - g_free (buf); - - gtk_window_set_title (GTK_WINDOW (an->dialog), title); - g_free (title); - - /* html heading */ - stream = gtk_html_begin (GTK_HTML (an->html)); - write_html_heading (stream, message, vtype, occur_start, occur_end); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); - - /* Connect actions */ - - g_signal_connect (an->dialog, "delete_event", - G_CALLBACK (delete_event_cb), - an); - - g_signal_connect (an->close, "clicked", - G_CALLBACK (close_clicked_cb), - an); - - g_signal_connect (an->snooze, "clicked", - G_CALLBACK (snooze_clicked_cb), - an); - - g_signal_connect (an->edit, "clicked", - G_CALLBACK (edit_clicked_cb), - an); - - /* Run! */ - - if (!GTK_WIDGET_REALIZED (an->dialog)) - gtk_widget_realize (an->dialog); - -#if 0 - gnome_win_hints_set_state (an->dialog, WIN_STATE_STICKY); - gnome_win_hints_set_layer (an->dialog, WIN_LAYER_ONTOP); - gnome_window_icon_set_from_file (GTK_WINDOW (an->dialog), EVOLUTION_IMAGESDIR "/alarm.png"); -#endif - - gtk_widget_show (an->dialog); - return an; -} - -void -alarm_notify_dialog_disable_buttons (gpointer dialog) -{ - AlarmNotify *an = dialog; - - gtk_widget_set_sensitive (an->snooze, FALSE); - gtk_widget_set_sensitive (an->edit, FALSE); -} diff --git a/calendar/gui/alarm-notify/alarm-notify-dialog.h b/calendar/gui/alarm-notify/alarm-notify-dialog.h deleted file mode 100644 index 39cadbca0b..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify-dialog.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Evolution calendar - alarm notification dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_NOTIFY_DIALOG_H -#define ALARM_NOTIFY_DIALOG_H - -#include <time.h> -#include <glib.h> -#include <cal-util/cal-component.h> - - - -typedef enum { - ALARM_NOTIFY_CLOSE, - ALARM_NOTIFY_SNOOZE, - ALARM_NOTIFY_EDIT -} AlarmNotifyResult; - -typedef void (* AlarmNotifyFunc) (AlarmNotifyResult result, int snooze_mins, gpointer data); - -gpointer alarm_notify_dialog (time_t trigger, time_t occur_start, time_t occur_end, - CalComponentVType vtype, const char *message, - AlarmNotifyFunc func, gpointer func_data); -void alarm_notify_dialog_disable_buttons (gpointer dialog); - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-notify.c b/calendar/gui/alarm-notify/alarm-notify.c deleted file mode 100644 index 20ba5547f1..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.c +++ /dev/null @@ -1,474 +0,0 @@ -/* Evolution calendar - Alarm notification service object - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <string.h> -#include <cal-client/cal-client.h> -#include "alarm-notify.h" -#include "alarm-queue.h" -#include "save.h" -#include "e-util/e-url.h" - - - -/* A loaded client */ -typedef struct { - /* The actual client */ - CalClient *client; - - /* The URI of the client in gnome-vfs's format. This *is* the key that - * is stored in the uri_client_hash hash table below. - */ - EUri *uri; - - /* Number of times clients have requested this URI to be added to the - * alarm notification system. - */ - int refcount; - - /* the ID of the retry timeout function - */ - int timeout_id; -} LoadedClient; - -/* Private part of the AlarmNotify structure */ -struct _AlarmNotifyPrivate { - /* Mapping from EUri's to LoadedClient structures */ - GHashTable *uri_client_hash; -}; - - - -static void alarm_notify_class_init (AlarmNotifyClass *klass); -static void alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass); -static void alarm_notify_finalize (GObject *object); - -static void AlarmNotify_addCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev); -static void AlarmNotify_removeCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev); - - -static BonoboObjectClass *parent_class; - - - -BONOBO_TYPE_FUNC_FULL (AlarmNotify, - GNOME_Evolution_Calendar_AlarmNotify, - BONOBO_TYPE_OBJECT, - alarm_notify); - -/* Class initialization function for the alarm notify service */ -static void -alarm_notify_class_init (AlarmNotifyClass *klass) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) klass; - - parent_class = g_type_class_peek_parent (klass); - - klass->epv.addCalendar = AlarmNotify_addCalendar; - klass->epv.removeCalendar = AlarmNotify_removeCalendar; - - object_class->finalize = alarm_notify_finalize; -} - -/* Object initialization function for the alarm notify system */ -static void -alarm_notify_init (AlarmNotify *an, AlarmNotifyClass *klass) -{ - AlarmNotifyPrivate *priv; - - priv = g_new0 (AlarmNotifyPrivate, 1); - an->priv = priv; - - priv->uri_client_hash = g_hash_table_new (g_str_hash, g_str_equal); -} - -/* Callback used from g_hash-table_forach(), used to destroy a loade client */ -static void -destroy_loaded_client_cb (gpointer key, gpointer value, gpointer data) -{ - LoadedClient *lc; - char *str_uri; - - str_uri = key; - lc = value; - - g_free (str_uri); - g_object_unref (G_OBJECT (lc->client)); - e_uri_free (lc->uri); - g_free (lc); -} - -/* Finalize handler for the alarm notify system */ -static void -alarm_notify_finalize (GObject *object) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_ALARM_NOTIFY (object)); - - an = ALARM_NOTIFY (object); - priv = an->priv; - - g_hash_table_foreach (priv->uri_client_hash, destroy_loaded_client_cb, NULL); - - g_hash_table_destroy (priv->uri_client_hash); - priv->uri_client_hash = NULL; - - g_free (priv); - an->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* CORBA servant implementation */ - -/* Looks for a canonicalized URI inside an array of URIs; returns the index - * within the array or -1 if not found. - */ -static int -find_uri_index (GPtrArray *uris, const char *str_uri) -{ - int i; - - for (i = 0; i < uris->len; i++) { - char *uri; - - uri = uris->pdata[i]; - if (strcmp (uri, str_uri) == 0) - break; - } - - if (i == uris->len) - return -1; - else - return i; -} - -/* Frees an array of URIs and the URIs within it. */ -static void -free_uris (GPtrArray *uris) -{ - int i; - - for (i = 0; i < uris->len; i++) { - char *uri; - - uri = uris->pdata[i]; - g_free (uri); - } - - g_ptr_array_free (uris, TRUE); -} - -/* Adds an URI to the list of calendars to load on startup */ -static void -add_uri_to_load (EUri *uri) -{ - char *str_uri; - GPtrArray *loaded_uris; - int i; - - /* Canonicalize the URI */ - str_uri = e_uri_to_string (uri, FALSE); - g_assert (str_uri != NULL); - - loaded_uris = get_calendars_to_load (); - if (!loaded_uris) { - g_message ("add_uri_to_load(): Could not get the list of calendars to load; " - "will not add `%s'", str_uri); - g_free (str_uri); - return; - } - - /* Look for the URI in the list of calendars to load */ - - i = find_uri_index (loaded_uris, str_uri); - - /* We only need to add the URI if we didn't find it among the list of - * calendars. - */ - if (i != -1) { - g_free (str_uri); - free_uris (loaded_uris); - return; - } - - g_ptr_array_add (loaded_uris, str_uri); - save_calendars_to_load (loaded_uris); - - free_uris (loaded_uris); -} - -/* Removes an URI from the list of calendars to load on startup */ -static void -remove_uri_to_load (EUri *uri) -{ - char *str_uri; - GPtrArray *loaded_uris; - char *loaded_uri; - int i; - - /* Canonicalize the URI */ - str_uri = e_uri_to_string (uri, FALSE); - g_assert (str_uri != NULL); - - loaded_uris = get_calendars_to_load (); - if (!loaded_uris) { - g_message ("remove_uri_to_load(): Could not get the list of calendars to load; " - "will not add `%s'", str_uri); - g_free (str_uri); - return; - } - - /* Look for the URI in the list of calendars to load */ - - i = find_uri_index (loaded_uris, str_uri); - g_free (str_uri); - - /* If we didn't find it, there is no need to remove it */ - if (i == -1) { - free_uris (loaded_uris); - return; - } - - loaded_uri = loaded_uris->pdata[i]; - g_free (loaded_uri); - - g_ptr_array_remove_index (loaded_uris, i); - save_calendars_to_load (loaded_uris); - - free_uris (loaded_uris); -} - -/* AlarmNotify::addCalendar method */ -static void -AlarmNotify_addCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev) -{ - AlarmNotify *an; - - an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); - alarm_notify_add_calendar (an, str_uri, TRUE, ev); -} - -/* AlarmNotify::removeCalendar method */ -static void -AlarmNotify_removeCalendar (PortableServer_Servant servant, - const CORBA_char *str_uri, - CORBA_Environment *ev) -{ - AlarmNotify *an; - AlarmNotifyPrivate *priv; - LoadedClient *lc; - EUri *uri; - char *orig_str; - gpointer lc_ptr, orig_str_ptr; - gboolean found; - - an = ALARM_NOTIFY (bonobo_object_from_servant (servant)); - priv = an->priv; - - uri = e_uri_new (str_uri); - if (!uri) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI, - NULL); - return; - } - - remove_uri_to_load (uri); - - found = g_hash_table_lookup_extended (priv->uri_client_hash, str_uri, - &orig_str_ptr, - &lc_ptr); - orig_str = orig_str_ptr; - lc = lc_ptr; - - e_uri_free (uri); - - if (!lc) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound, - NULL); - return; - } - - g_assert (lc->refcount > 0); - - lc->refcount--; - if (lc->refcount > 0) - return; - - g_hash_table_remove (priv->uri_client_hash, str_uri); - - g_free (orig_str); - g_signal_handlers_disconnect_matched (lc->client, - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, lc); - if (lc->timeout_id != -1) - g_source_remove (lc->timeout_id); - alarm_queue_remove_client (lc->client); - g_object_unref (G_OBJECT (lc->client)); - e_uri_free (lc->uri); - g_free (lc); -} - - - -/** - * alarm_notify_new: - * - * Creates a new #AlarmNotify object. - * - * Return value: A newly-created #AlarmNotify, or NULL if its corresponding - * CORBA object could not be created. - **/ -AlarmNotify * -alarm_notify_new (void) -{ - AlarmNotify *an; - - an = g_object_new (TYPE_ALARM_NOTIFY, NULL); - return an; -} - -static gboolean -retry_timeout_cb (gpointer data) -{ - LoadedClient *lc = data; - char *str_uri; - - if (cal_client_get_load_state (lc->client) != CAL_CLIENT_LOAD_LOADED) { - str_uri = e_uri_to_string (lc->uri, FALSE); - cal_client_open_calendar (lc->client, str_uri, FALSE); - - g_free (str_uri); - } - - return FALSE; -} - -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - LoadedClient *lc = (LoadedClient *) data; - - if (status == CAL_CLIENT_OPEN_SUCCESS) { - add_uri_to_load (lc->uri); - alarm_queue_add_client (client); - lc->timeout_id = -1; - } - else { - remove_uri_to_load (lc->uri); - - /* we set a timeout of 5 mins before retrying */ - lc->timeout_id = g_timeout_add (300000, (GSourceFunc) retry_timeout_cb, lc); - } -} - -/** - * alarm_notify_add_calendar: - * @an: An alarm notification service. - * @uri: URI of the calendar to load. - * @load_afterwards: Whether this calendar should be loaded in the future - * when the alarm daemon starts up. - * @ev: CORBA environment for exceptions. - * - * Tells the alarm notification service to load a calendar and start monitoring - * its alarms. It can optionally be made to save the URI of this calendar so - * that it can be loaded in the future when the alarm daemon starts up. - **/ -void -alarm_notify_add_calendar (AlarmNotify *an, const char *str_uri, gboolean load_afterwards, - CORBA_Environment *ev) -{ - AlarmNotifyPrivate *priv; - EUri *uri; - CalClient *client; - LoadedClient *lc; - gpointer lc_ptr, s_ptr; - - g_return_if_fail (an != NULL); - g_return_if_fail (IS_ALARM_NOTIFY (an)); - g_return_if_fail (str_uri != NULL); - g_return_if_fail (ev != NULL); - - priv = an->priv; - - uri = e_uri_new (str_uri); - if (!uri) { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI, - NULL); - return; - } - - if (g_hash_table_lookup_extended (priv->uri_client_hash, str_uri, &s_ptr, &lc_ptr)) { - lc = lc_ptr; - lc->refcount++; - } else { - client = cal_client_new (); - - if (client) { - /* we only add the URI to load_afterwards if we open it - correctly */ - lc = g_new (LoadedClient, 1); - - g_signal_connect (G_OBJECT (client), "cal_opened", - G_CALLBACK (cal_opened_cb), - lc); - - if (cal_client_open_calendar (client, str_uri, FALSE)) { - lc->client = client; - lc->uri = uri; - lc->refcount = 1; - lc->timeout_id = -1; - g_hash_table_insert (priv->uri_client_hash, - g_strdup (str_uri), lc); - } else { - g_free (lc); - g_object_unref (G_OBJECT (client)); - client = NULL; - } - } else { - e_uri_free (uri); - - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError, - NULL); - return; - } - } -} diff --git a/calendar/gui/alarm-notify/alarm-notify.glade b/calendar/gui/alarm-notify/alarm-notify.glade deleted file mode 100644 index bc0da43f22..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.glade +++ /dev/null @@ -1,189 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="alarm-notify"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="title" translatable="yes"></property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="vbox2"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="hbox3"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkVBox" id="vbox5"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="Custom" id="frame"> - <property name="visible">True</property> - <property name="creation_function">make_html_display</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Thu, 11 Oct 2001 08:19:04 GMT</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox4"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="close"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">C_lose</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="snooze"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Snoo_ze</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="edit"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Edit appointment</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHSeparator" id="hseparator1"> - <property name="visible">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox4"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Snooze time (minutes)</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="snooze-time"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">5 1 1440 1 5 5</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/alarm-notify/alarm-notify.h b/calendar/gui/alarm-notify/alarm-notify.h deleted file mode 100644 index f3157000c0..0000000000 --- a/calendar/gui/alarm-notify/alarm-notify.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Evolution calendar - Alarm notification service object - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_NOTIFY_H -#define ALARM_NOTIFY_H - -#include <bonobo/bonobo-object.h> -#include "evolution-calendar.h" - - - -#define TYPE_ALARM_NOTIFY (alarm_notify_get_type ()) -#define ALARM_NOTIFY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ALARM_NOTIFY, AlarmNotify)) -#define ALARM_NOTIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ALARM_NOTIFY, \ - AlarmNotifyClass)) -#define IS_ALARM_NOTIFY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ALARM_NOTIFY)) -#define IS_ALARM_NOTIFY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ALARM_NOTIFY)) - -typedef struct _AlarmNotify AlarmNotify; -typedef struct _AlarmNotifyClass AlarmNotifyClass; - -typedef struct _AlarmNotifyPrivate AlarmNotifyPrivate; - -struct _AlarmNotify { - BonoboObject xobject; - - /* Private data */ - AlarmNotifyPrivate *priv; -}; - -struct _AlarmNotifyClass { - BonoboObjectClass parent_class; - - POA_GNOME_Evolution_Calendar_AlarmNotify__epv epv; -}; - -GType alarm_notify_get_type (void); - -AlarmNotify *alarm_notify_new (void); - -void alarm_notify_add_calendar (AlarmNotify *an, const char *str_uri, gboolean load_afterwards, - CORBA_Environment *ev); - - - - -#endif diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c deleted file mode 100644 index 9aff1a8bf0..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ /dev/null @@ -1,1159 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <glib.h> -#include <bonobo-activation/bonobo-activation.h> -#include <bonobo/bonobo-object.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkbox.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkstock.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-exec.h> -#include <libgnome/gnome-sound.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-uidefs.h> -#include <cal-util/timeutil.h> -#include "alarm.h" -#include "alarm-notify-dialog.h" -#include "alarm-queue.h" -#include "config-data.h" -#include "save.h" - - - -/* Whether the queueing system has been initialized */ -static gboolean alarm_queue_inited; - -/* When the alarm queue system is inited, this gets set to the last time an - * alarm notification was issued. This lets us present any notifications that - * should have happened while the alarm daemon was not running. - */ -static time_t saved_notification_time; - -/* Clients we are monitoring for alarms */ -static GHashTable *client_alarms_hash = NULL; - -/* Structure that stores a client we are monitoring */ -typedef struct { - /* Monitored client */ - CalClient *client; - - /* Number of times this client has been registered */ - int refcount; - - /* Hash table of component UID -> CompQueuedAlarms. If an element is - * present here, then it means its cqa->queued_alarms contains at least - * one queued alarm. When all the alarms for a component have been - * dequeued, the CompQueuedAlarms structure is removed from the hash - * table. Thus a CQA exists <=> it has queued alarms. - */ - GHashTable *uid_alarms_hash; -} ClientAlarms; - -/* Pair of a CalComponentAlarms and the mapping from queued alarm IDs to the - * actual alarm instance structures. - */ -typedef struct { - /* The parent client alarms structure */ - ClientAlarms *parent_client; - - /* The component's UID */ - char *uid; - - /* The actual component and its alarm instances */ - CalComponentAlarms *alarms; - - /* List of QueuedAlarm structures */ - GSList *queued_alarms; - - /* Flags */ - gboolean expecting_update; -} CompQueuedAlarms; - -/* Pair of a queued alarm ID and the alarm trigger instance it refers to */ -typedef struct { - /* Alarm ID from alarm.h */ - gpointer alarm_id; - - /* Instance from our parent CompQueuedAlarms->alarms->alarms list */ - CalAlarmInstance *instance; - - /* Whether this is a snoozed queued alarm or a normal one */ - guint snooze : 1; -} QueuedAlarm; - -/* Alarm ID for the midnight refresh function */ -static gpointer midnight_refresh_id = NULL; - -static void display_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id, gboolean use_description); -static void audio_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); -static void mail_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); -static void procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id); - - - -/* Alarm queue engine */ - -static void load_alarms_for_today (ClientAlarms *ca); -static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data); - -/* Queues an alarm trigger for midnight so that we can load the next day's worth - * of alarms. - */ -static void -queue_midnight_refresh (void) -{ - time_t midnight; - icaltimezone *zone; - - g_assert (midnight_refresh_id == NULL); - - zone = config_data_get_timezone (); - - midnight = time_day_end_with_zone (time (NULL), zone); - - midnight_refresh_id = alarm_add (midnight, midnight_refresh_cb, NULL, NULL); - if (!midnight_refresh_id) { - g_message ("queue_midnight_refresh(): Could not set up the midnight refresh alarm!"); - /* FIXME: what to do? */ - } -} - -/* Loads a client's alarms; called from g_hash_table_foreach() */ -static void -add_client_alarms_cb (gpointer key, gpointer value, gpointer data) -{ - ClientAlarms *ca; - - ca = value; - load_alarms_for_today (ca); -} - -/* Loads the alarms for the new day every midnight */ -static void -midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - /* Re-load the alarms for all clients */ - - g_hash_table_foreach (client_alarms_hash, add_client_alarms_cb, NULL); - - /* Re-schedule the midnight update */ - - midnight_refresh_id = NULL; - queue_midnight_refresh (); -} - -/* Looks up a client in the client alarms hash table */ -static ClientAlarms * -lookup_client (CalClient *client) -{ - return g_hash_table_lookup (client_alarms_hash, client); -} - -/* Looks up a queued alarm based on its alarm ID */ -static QueuedAlarm * -lookup_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id) -{ - GSList *l; - QueuedAlarm *qa; - - qa = NULL; - - for (l = cqa->queued_alarms; l; l = l->next) { - qa = l->data; - if (qa->alarm_id == alarm_id) - return qa; - } - - /* not found, might have been updated/removed */ - return NULL; -} - -/* Removes an alarm from the list of alarms of a component. If the alarm was - * the last one listed for the component, it removes the component itself. - */ -static void -remove_queued_alarm (CompQueuedAlarms *cqa, gpointer alarm_id, - gboolean free_object, gboolean remove_alarm) -{ - QueuedAlarm *qa; - GSList *l; - - qa = NULL; - - for (l = cqa->queued_alarms; l; l = l->next) { - qa = l->data; - if (qa->alarm_id == alarm_id) - break; - } - - if (!l) - return; - - cqa->queued_alarms = g_slist_remove_link (cqa->queued_alarms, l); - g_slist_free_1 (l); - - if (remove_alarm) { - cqa->expecting_update = TRUE; - cal_client_discard_alarm (cqa->parent_client->client, cqa->alarms->comp, - qa->instance->auid); - cqa->expecting_update = FALSE; - } - - g_free (qa); - - /* If this was the last queued alarm for this component, remove the - * component itself. - */ - - if (cqa->queued_alarms != NULL) - return; - - if (free_object) { - g_hash_table_remove (cqa->parent_client->uid_alarms_hash, cqa->uid); - g_free (cqa->uid); - cqa->uid = NULL; - cqa->parent_client = NULL; - cal_component_alarms_free (cqa->alarms); - g_free (cqa); - } else { - cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - } -} - -/* Callback used when an alarm triggers */ -static void -alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - CompQueuedAlarms *cqa; - CalComponent *comp; - QueuedAlarm *qa; - CalComponentAlarm *alarm; - CalAlarmAction action; - - cqa = data; - comp = cqa->alarms->comp; - - save_notification_time (trigger); - saved_notification_time = trigger; - - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - /* Decide what to do based on the alarm action. We use the trigger that - * is passed to us instead of the one from the instance structure - * because this may be a snoozed alarm instead of an original - * occurrence. - */ - - alarm = cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - cal_component_alarm_get_action (alarm, &action); - cal_component_alarm_free (alarm); - - switch (action) { - case CAL_ALARM_AUDIO: - audio_notification (trigger, cqa, alarm_id); - break; - - case CAL_ALARM_DISPLAY: - display_notification (trigger, cqa, alarm_id, TRUE); - break; - - case CAL_ALARM_EMAIL: - mail_notification (trigger, cqa, alarm_id); - break; - - case CAL_ALARM_PROCEDURE: - procedure_notification (trigger, cqa, alarm_id); - break; - - default: - g_assert_not_reached (); - break; - } -} - -/* Adds the alarms in a CalComponentAlarms structure to the alarms queued for a - * particular client. Also puts the triggers in the alarm timer queue. - */ -static void -add_component_alarms (ClientAlarms *ca, CalComponentAlarms *alarms) -{ - const char *uid; - CompQueuedAlarms *cqa; - GSList *l; - - /* No alarms? */ - if (alarms->alarms == NULL) { - cal_component_alarms_free (alarms); - return; - } - - cqa = g_new (CompQueuedAlarms, 1); - cqa->parent_client = ca; - cqa->alarms = alarms; - cqa->expecting_update = FALSE; - - cqa->queued_alarms = NULL; - - for (l = alarms->alarms; l; l = l->next) { - CalAlarmInstance *instance; - gpointer alarm_id; - QueuedAlarm *qa; - - instance = l->data; - - alarm_id = alarm_add (instance->trigger, alarm_trigger_cb, cqa, NULL); - if (!alarm_id) { - g_message ("add_component_alarms(): Could not schedule a trigger for " - "%ld, discarding...", (long) instance->trigger); - continue; - } - - qa = g_new (QueuedAlarm, 1); - qa->alarm_id = alarm_id; - qa->instance = instance; - qa->snooze = FALSE; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); - } - - cal_component_get_uid (alarms->comp, &uid); - - /* If we failed to add all the alarms, then we should get rid of the cqa */ - if (cqa->queued_alarms == NULL) { - g_message ("add_component_alarms(): Could not add any of the alarms " - "for the component `%s'; discarding it...", uid); - - cal_component_alarms_free (cqa->alarms); - cqa->alarms = NULL; - - g_free (cqa); - return; - } - - cqa->queued_alarms = g_slist_reverse (cqa->queued_alarms); - cqa->uid = g_strdup (uid); - g_hash_table_insert (ca->uid_alarms_hash, cqa->uid, cqa); -} - -/* Loads the alarms of a client for a given range of time */ -static void -load_alarms (ClientAlarms *ca, time_t start, time_t end) -{ - GSList *comp_alarms; - GSList *l; - - comp_alarms = cal_client_get_alarms_in_range (ca->client, start, end); - - for (l = comp_alarms; l; l = l->next) { - CalComponentAlarms *alarms; - - alarms = l->data; - add_component_alarms (ca, alarms); - } - - g_slist_free (comp_alarms); -} - -/* Loads today's remaining alarms for a client */ -static void -load_alarms_for_today (ClientAlarms *ca) -{ - time_t now, day_end; - icaltimezone *zone; - - now = time (NULL); - - zone = config_data_get_timezone (); - - day_end = time_day_end_with_zone (now, zone); - load_alarms (ca, now, day_end); -} - -/* Adds any alarms that should have occurred while the alarm daemon was not - * running. - */ -static void -load_missed_alarms (ClientAlarms *ca) -{ - time_t now; - - now = time (NULL); - - g_assert (saved_notification_time != -1); - - /* We add 1 to the saved_notification_time to make the time ranges - * half-open; we do not want to display the "last" displayed alarm - * twice, once when it occurs and once when the alarm daemon restarts. - */ - load_alarms (ca, saved_notification_time + 1, now); -} - -/* Called when a calendar client finished loading; we load its alarms */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; - - load_alarms_for_today (ca); - load_missed_alarms (ca); -} - -/* Looks up a component's queued alarm structure in a client alarms structure */ -static CompQueuedAlarms * -lookup_comp_queued_alarms (ClientAlarms *ca, const char *uid) -{ - return g_hash_table_lookup (ca->uid_alarms_hash, uid); -} - -static void -remove_alarms (CompQueuedAlarms *cqa, gboolean free_object) -{ - GSList *l; - - for (l = cqa->queued_alarms; l;) { - QueuedAlarm *qa; - - qa = l->data; - - /* Get the next element here because the list element will go - * away in remove_queued_alarm(). The qa will be freed there as - * well. - */ - l = l->next; - - alarm_remove (qa->alarm_id); - remove_queued_alarm (cqa, qa->alarm_id, free_object, FALSE); - } - -} - -/* Removes a component an its alarms */ -static void -remove_comp (ClientAlarms *ca, const char *uid) -{ - CompQueuedAlarms *cqa; - - cqa = lookup_comp_queued_alarms (ca, uid); - if (!cqa) - return; - - /* If a component is present, then it means we must have alarms queued - * for it. - */ - g_assert (cqa->queued_alarms != NULL); - - remove_alarms (cqa, TRUE); - - /* The list should be empty now, and thus the queued component alarms - * structure should have been freed and removed from the hash table. - */ - g_assert (lookup_comp_queued_alarms (ca, uid) == NULL); -} - -/* Called when a calendar component changes; we must reload its corresponding - * alarms. - */ -static void -obj_updated_cb (CalClient *client, const char *uid, gpointer data) -{ - ClientAlarms *ca; - time_t now, day_end; - CalComponentAlarms *alarms; - gboolean found; - icaltimezone *zone; - CompQueuedAlarms *cqa; - - ca = data; - - now = time (NULL); - - zone = config_data_get_timezone (); - - day_end = time_day_end_with_zone (now, zone); - - found = cal_client_get_alarms_for_object (ca->client, uid, now, day_end, &alarms); - - if (!found) { - remove_comp (ca, uid); - return; - } - - cqa = lookup_comp_queued_alarms (ca, uid); - if (!cqa) - add_component_alarms (ca, alarms); - else { - GSList *l; - - /* if already in the list, just update it */ - remove_alarms (cqa, FALSE); - cqa->alarms = alarms; - cqa->queued_alarms = NULL; - - /* add the new alarms */ - for (l = cqa->alarms->alarms; l; l = l->next) { - CalAlarmInstance *instance; - gpointer alarm_id; - QueuedAlarm *qa; - - instance = l->data; - - alarm_id = alarm_add (instance->trigger, alarm_trigger_cb, cqa, NULL); - if (!alarm_id) { - g_message ("obj_updated_cb(): Could not schedule a trigger for " - "%ld, discarding...", (long) instance->trigger); - continue; - } - - qa = g_new (QueuedAlarm, 1); - qa->alarm_id = alarm_id; - qa->instance = instance; - qa->snooze = FALSE; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); - } - - if (cqa->queued_alarms == NULL) { - if (!cqa->expecting_update) - remove_comp (ca, uid); - } else - cqa->queued_alarms = g_slist_reverse (cqa->queued_alarms); - } -} - -/* Called when a calendar component is removed; we must delete its corresponding - * alarms. - */ -static void -obj_removed_cb (CalClient *client, const char *uid, gpointer data) -{ - ClientAlarms *ca; - - ca = data; - - remove_comp (ca, uid); -} - - - -/* Notification functions */ - -/* Creates a snooze alarm based on an existing one. The snooze offset is - * compued with respect to the current time. - */ -static void -create_snooze (CompQueuedAlarms *cqa, gpointer alarm_id, int snooze_mins) -{ - QueuedAlarm *orig_qa, *qa; - CalAlarmInstance *instance; - time_t t; - gpointer new_id; - - orig_qa = lookup_queued_alarm (cqa, alarm_id); - if (!orig_qa) - return; - - t = time (NULL); - t += snooze_mins * 60; - - new_id = alarm_add (t, alarm_trigger_cb, cqa, NULL); - if (!new_id) { - g_message ("create_snooze(): Could not schedule a trigger for " - "%ld, discarding...", (long) t); - return; - } - - instance = g_new (CalAlarmInstance, 1); - instance->auid = orig_qa->instance->auid; - instance->trigger = t; - instance->occur_start = orig_qa->instance->occur_start; - instance->occur_end = orig_qa->instance->occur_end; - - cqa->alarms->alarms = g_slist_prepend (cqa->alarms->alarms, instance); - - qa = g_new (QueuedAlarm, 1); - qa->alarm_id = new_id; - qa->instance = instance; - qa->snooze = TRUE; - - cqa->queued_alarms = g_slist_prepend (cqa->queued_alarms, qa); -} - -/* Launches a component editor for a component */ -static void -edit_component (CalClient *client, CalComponent *comp) -{ - const char *uid; - const char *uri; - CORBA_Environment ev; - GNOME_Evolution_Calendar_CompEditorFactory factory; - - cal_component_get_uid (comp, &uid); - - uri = cal_client_get_uri (client); - - /* Get the factory */ - - CORBA_exception_init (&ev); - factory = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_CompEditorFactory", - 0, NULL, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_message ("edit_component(): Could not activate the component editor factory"); - CORBA_exception_free (&ev); - return; - } - CORBA_exception_free (&ev); - - /* Edit the component */ - - CORBA_exception_init (&ev); - GNOME_Evolution_Calendar_CompEditorFactory_editExisting (factory, uri, (char *) uid, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("edit_component(): Exception while editing the component"); - - CORBA_exception_free (&ev); - - /* Get rid of the factory */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (factory, &ev); - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("edit_component(): Could not unref the calendar component factory"); - - CORBA_exception_free (&ev); -} - -struct notify_dialog_closure { - CompQueuedAlarms *cqa; - gpointer alarm_id; - CalClient *client; - CalComponent *comp; - gpointer dialog; -}; - -static void -on_dialog_obj_updated_cb (CalClient *client, const char *uid, gpointer data) -{ - struct notify_dialog_closure *c = data; -} - -static void -on_dialog_obj_removed_cb (CalClient *client, const char *uid, gpointer data) -{ - const char *our_uid; - struct notify_dialog_closure *c = data; - - cal_component_get_uid (c->comp, &our_uid); - g_return_if_fail (our_uid && *our_uid); - - if (!strcmp (uid, our_uid)) { - alarm_notify_dialog_disable_buttons (c->dialog); - c->cqa = NULL; - c->alarm_id = NULL; - } -} - -/* Callback used from the alarm notify dialog */ -static void -notify_dialog_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) -{ - struct notify_dialog_closure *c; - - c = data; - - g_signal_handlers_disconnect_matched (c->client, G_SIGNAL_MATCH_FUNC, - 0, 0, NULL, on_dialog_obj_updated_cb, NULL); - g_signal_handlers_disconnect_matched (c->client, G_SIGNAL_MATCH_FUNC, - 0, 0, NULL, on_dialog_obj_removed_cb, NULL); - - switch (result) { - case ALARM_NOTIFY_SNOOZE: - create_snooze (c->cqa, c->alarm_id, snooze_mins); - break; - - case ALARM_NOTIFY_EDIT: - edit_component (c->client, c->comp); - break; - - case ALARM_NOTIFY_CLOSE: - /* Do nothing */ - break; - - default: - g_assert_not_reached (); - } - - if (c->cqa != NULL) - remove_queued_alarm (c->cqa, c->alarm_id, TRUE, TRUE); - g_object_unref (c->comp); - g_object_unref (c->client); - g_free (c); -} - -/* Performs notification of a display alarm */ -static void -display_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id, gboolean use_description) -{ - CalComponent *comp; - CalComponentVType vtype; - CalComponentText text; - QueuedAlarm *qa; - const char *message; - struct notify_dialog_closure *c; - gboolean use_summary; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - vtype = cal_component_get_vtype (comp); - - /* Pick a sensible notification message. First we try the DESCRIPTION - * from the alarm, then the SUMMARY of the component. - */ - - use_summary = TRUE; - message = NULL; - - if (use_description) { - CalComponentAlarm *alarm; - - alarm = cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - cal_component_alarm_get_description (alarm, &text); - cal_component_alarm_free (alarm); - - if (text.value) { - message = text.value; - use_summary = FALSE; - } - } - - if (use_summary) { - cal_component_get_summary (comp, &text); - if (text.value) - message = text.value; - else - message = _("No description available."); - } - - c = g_new (struct notify_dialog_closure, 1); - c->cqa = cqa; - c->alarm_id = alarm_id; - c->comp = cal_component_clone (comp); - c->client = c->cqa->parent_client->client; - g_object_ref (c->client); - - if (!(c->dialog = alarm_notify_dialog (trigger, - qa->instance->occur_start, qa->instance->occur_end, - vtype, message, - notify_dialog_cb, c))) - g_message ("display_notification(): Could not create the alarm notify dialog"); - else { - g_signal_connect (c->client, "obj_updated", - G_CALLBACK (on_dialog_obj_updated_cb), c); - g_signal_connect (c->client, "obj_removed", - G_CALLBACK (on_dialog_obj_removed_cb), c); - } -} - -/* Performs notification of an audio alarm */ -static void -audio_notification (time_t trigger, CompQueuedAlarms *cqa, - gpointer alarm_id) -{ - QueuedAlarm *qa; - CalComponent *comp; - CalComponentAlarm *alarm; - icalattach *attach; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - alarm = cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - cal_component_alarm_get_attach (alarm, &attach); - cal_component_alarm_free (alarm); - - if (attach && icalattach_get_is_url (attach)) { - const char *url; - - url = icalattach_get_url (attach); - - if (url && *url && g_file_test (url, G_FILE_TEST_EXISTS)) - gnome_sound_play (url); /* this sucks */ - else - gdk_beep (); - } - - if (attach) - icalattach_unref (attach); - - /* We present a notification message in addition to playing the sound */ - display_notification (trigger, cqa, alarm_id, FALSE); -} - -/* Performs notification of a mail alarm */ -static void -mail_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id) -{ - GtkWidget *dialog; - GtkWidget *label; - - /* FIXME */ - - display_notification (trigger, cqa, alarm_id, FALSE); - - dialog = gtk_dialog_new_with_buttons (_("Warning"), - NULL, 0, - GTK_STOCK_OK, GTK_RESPONSE_CANCEL, - NULL); - label = gtk_label_new (_("Evolution does not support calendar reminders with\n" - "email notifications yet, but this reminder was\n" - "configured to send an email. Evolution will display\n" - "a normal reminder dialog box instead.")); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE, TRUE, 4); - - gtk_dialog_run (GTK_DIALOG (dialog)); -} - -/* Performs notification of a procedure alarm */ -static gboolean -procedure_notification_dialog (const char *cmd, const char *url) -{ - GtkWidget *dialog, *label, *checkbox; - char *str; - int btn; - - if (is_blessed_program (url)) - return TRUE; - - dialog = gtk_dialog_new_with_buttons (_("Warning"), - NULL, 0, - GTK_STOCK_NO, GTK_RESPONSE_CANCEL, - GTK_STOCK_YES, GTK_RESPONSE_OK, - NULL); - - str = g_strdup_printf (_("An Evolution Calendar reminder is about to trigger. " - "This reminder is configured to run the following program:\n\n" - " %s\n\n" - "Are you sure you want to run this program?"), - cmd); - label = gtk_label_new (str); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - label, TRUE, TRUE, 4); - g_free (str); - - checkbox = gtk_check_button_new_with_label - (_("Do not ask me about this program again.")); - gtk_widget_show (checkbox); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - checkbox, TRUE, TRUE, 4); - - /* Run the dialog */ - btn = gtk_dialog_run (GTK_DIALOG (dialog)); - if (btn == GTK_RESPONSE_OK && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))) - save_blessed_program (url); - gtk_widget_destroy (dialog); - - return (btn == GTK_RESPONSE_OK); -} - -static void -procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpointer alarm_id) -{ - QueuedAlarm *qa; - CalComponent *comp; - CalComponentAlarm *alarm; - CalComponentText description; - icalattach *attach; - const char *url; - char *cmd; - int result; - - comp = cqa->alarms->comp; - qa = lookup_queued_alarm (cqa, alarm_id); - if (!qa) - return; - - alarm = cal_component_get_alarm (comp, qa->instance->auid); - g_assert (alarm != NULL); - - cal_component_alarm_get_attach (alarm, &attach); - cal_component_alarm_get_description (alarm, &description); - cal_component_alarm_free (alarm); - - /* If the alarm has no attachment, simply display a notification dialog. */ - if (!attach) - goto fallback; - - if (!icalattach_get_is_url (attach)) { - icalattach_unref (attach); - goto fallback; - } - - url = icalattach_get_url (attach); - g_assert (url != NULL); - - /* Ask for confirmation before executing the stuff */ - if (description.value) - cmd = g_strconcat (url, " ", description.value, NULL); - else - cmd = (char *) url; - - result = 0; - if (procedure_notification_dialog (cmd, url)) - result = gnome_execute_shell (NULL, cmd); - - if (cmd != (char *) url) - g_free (cmd); - - icalattach_unref (attach); - - /* Fall back to display notification if we got an error */ - if (result < 0) - goto fallback; - - remove_queued_alarm (cqa, alarm_id, TRUE, TRUE); - return; - - fallback: - - display_notification (trigger, cqa, alarm_id, FALSE); -} - - - -/** - * alarm_queue_init: - * - * Initializes the alarm queueing system. This should be called near the - * beginning of the program. - **/ -void -alarm_queue_init (void) -{ - g_return_if_fail (alarm_queue_inited == FALSE); - - client_alarms_hash = g_hash_table_new (g_direct_hash, g_direct_equal); - queue_midnight_refresh (); - - saved_notification_time = get_saved_notification_time (); - if (saved_notification_time == -1) { - saved_notification_time = time (NULL); - save_notification_time (saved_notification_time); - } - - alarm_queue_inited = TRUE; -} - -/** - * alarm_queue_done: - * - * Shuts down the alarm queueing system. This should be called near the end - * of the program. All the monitored calendar clients should already have been - * unregistered with alarm_queue_remove_client(). - **/ -void -alarm_queue_done (void) -{ - g_return_if_fail (alarm_queue_inited); - - /* All clients must be unregistered by now */ - g_return_if_fail (g_hash_table_size (client_alarms_hash) == 0); - - g_hash_table_destroy (client_alarms_hash); - client_alarms_hash = NULL; - - g_assert (midnight_refresh_id != NULL); - alarm_remove (midnight_refresh_id); - midnight_refresh_id = NULL; - - alarm_queue_inited = FALSE; -} - -/** - * alarm_queue_add_client: - * @client: A calendar client. - * - * Adds a calendar client to the alarm queueing system. Alarm trigger - * notifications will be presented at the appropriate times. The client should - * be removed with alarm_queue_remove_client() when receiving notifications - * from it is no longer desired. - * - * A client can be added any number of times to the alarm queueing system, - * but any single alarm trigger will only be presented once for a particular - * client. The client must still be removed the same number of times from the - * queueing system when it is no longer wanted. - **/ -void -alarm_queue_add_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (IS_CAL_CLIENT (client)); - - ca = lookup_client (client); - if (ca) { - ca->refcount++; - return; - } - - ca = g_new (ClientAlarms, 1); - - ca->client = client; - g_object_ref (ca->client); - - ca->refcount = 1; - g_hash_table_insert (client_alarms_hash, client, ca); - - ca->uid_alarms_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (cal_client_get_load_state (client) != CAL_CLIENT_LOAD_LOADED) - g_signal_connect (client, "cal_opened", - G_CALLBACK (cal_opened_cb), - ca); - - g_signal_connect (client, "obj_updated", - G_CALLBACK (obj_updated_cb), - ca); - g_signal_connect (client, "obj_removed", - G_CALLBACK (obj_removed_cb), - ca); - - if (cal_client_get_load_state (client) == CAL_CLIENT_LOAD_LOADED) { - load_alarms_for_today (ca); - load_missed_alarms (ca); - } -} - -/* Called from g_hash_table_foreach(); adds a component UID to a list */ -static void -add_uid_cb (gpointer key, gpointer value, gpointer data) -{ - GSList **uids; - const char *uid; - - uids = data; - uid = key; - - *uids = g_slist_prepend (*uids, (char *) uid); -} - -/* Removes all the alarms queued for a particular calendar client */ -static void -remove_client_alarms (ClientAlarms *ca) -{ - GSList *uids; - GSList *l; - - /* First we build a list of UIDs so that we can remove them one by one */ - - uids = NULL; - g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids); - - for (l = uids; l; l = l->next) { - const char *uid; - - uid = l->data; - - remove_comp (ca, uid); - } - - g_slist_free (uids); - - /* The hash table should be empty now */ - - g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0); -} - -/** - * alarm_queue_remove_client: - * @client: A calendar client. - * - * Removes a calendar client from the alarm queueing system. - **/ -void -alarm_queue_remove_client (CalClient *client) -{ - ClientAlarms *ca; - - g_return_if_fail (alarm_queue_inited); - g_return_if_fail (client != NULL); - g_return_if_fail (IS_CAL_CLIENT (client)); - - ca = lookup_client (client); - g_return_if_fail (ca != NULL); - - g_assert (ca->refcount > 0); - ca->refcount--; - - if (ca->refcount > 0) - return; - - remove_client_alarms (ca); - - /* Clean up */ - - g_signal_handlers_disconnect_matched (ca->client, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, ca); - - g_object_unref (ca->client); - ca->client = NULL; - - g_hash_table_destroy (ca->uid_alarms_hash); - ca->uid_alarms_hash = NULL; - - g_free (ca); - - g_hash_table_remove (client_alarms_hash, client); -} diff --git a/calendar/gui/alarm-notify/alarm-queue.h b/calendar/gui/alarm-notify/alarm-queue.h deleted file mode 100644 index a37119145f..0000000000 --- a/calendar/gui/alarm-notify/alarm-queue.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Evolution calendar - Alarm queueing engine - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_QUEUE_H -#define ALARM_QUEUE_H - -#include <cal-client/cal-client.h> - - -void alarm_queue_init (void); -void alarm_queue_done (void); - -void alarm_queue_add_client (CalClient *client); -void alarm_queue_remove_client (CalClient *client); - - -#endif diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c deleted file mode 100644 index 8c6c4c59cd..0000000000 --- a/calendar/gui/alarm-notify/alarm.c +++ /dev/null @@ -1,305 +0,0 @@ -/* Evolution calendar - Low-level alarm timer mechanism - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <unistd.h> -#include <time.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/time.h> -#include <gdk/gdk.h> -#include "alarm.h" - - - -/* Our glib timeout */ -static guint timeout_id; - -/* The list of pending alarms */ -static GList *alarms = NULL; - -/* A queued alarm structure */ -typedef struct { - time_t trigger; - AlarmFunction alarm_fn; - gpointer data; - AlarmDestroyNotify destroy_notify_fn; -} AlarmRecord; - -static void setup_timeout (time_t now); - - - -/* Removes the head alarm from the queue. Does not touch the timeout_id. */ -static void -pop_alarm (void) -{ - AlarmRecord *ar; - GList *l; - - g_assert (alarms != NULL); - - ar = alarms->data; - - l = alarms; - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - - g_free (ar); -} - -/* Callback from the alarm timeout */ -static gboolean -alarm_ready_cb (gpointer data) -{ - time_t now; - - g_assert (alarms != NULL); - timeout_id = 0; - - now = time (NULL); - - while (alarms) { - AlarmRecord *notify_id, *ar; - AlarmRecord ar_copy; - - ar = alarms->data; - - if (ar->trigger > now) - break; - - notify_id = ar; - - ar_copy = *ar; - ar = &ar_copy; - - pop_alarm (); /* This will free the original AlarmRecord; that's why we copy it */ - - (* ar->alarm_fn) (notify_id, ar->trigger, ar->data); - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (notify_id, ar->data); - } - - if (alarms) { - /* We need this check because one of the alarm_fn above may have - * re-entered and added an alarm of its own, so the timer will - * already be set up. - */ - if (timeout_id == 0) - setup_timeout (now); - } else - g_assert (timeout_id == 0); - - return FALSE; -} - -/* Sets up a timeout for the next minute. We do not need to be concerned with - * timezones here, as this is just a periodic check on the alarm queue. - */ -static void -setup_timeout (time_t now) -{ - time_t next, diff; - struct tm tm; - - g_assert (timeout_id == 0); - g_assert (alarms != NULL); - - tm = *localtime (&now); - tm.tm_sec = 0; - tm.tm_min++; /* next minute */ - - next = mktime (&tm); - g_assert (next != -1); - - diff = next - now; - - g_assert (diff >= 0); - timeout_id = g_timeout_add (diff * 1000, alarm_ready_cb, NULL); -} - -/* Used from g_list_insert_sorted(); compares the trigger times of two AlarmRecord structures. */ -static int -compare_alarm_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->trigger - arb->trigger; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/* Adds an alarm to the queue and sets up the timer */ -static void -queue_alarm (AlarmRecord *ar) -{ - time_t now; - AlarmRecord *old_head; - - if (alarms) { - g_assert (timeout_id != 0); - - old_head = alarms->data; - } else { - g_assert (timeout_id == 0); - - old_head = NULL; - } - - alarms = g_list_insert_sorted (alarms, ar, compare_alarm_by_time); - - if (old_head == alarms->data) - return; - - /* Set the timer for removal upon activation */ - - if (!old_head) { - now = time (NULL); - setup_timeout (now); - } -} - - - -/** - * alarm_add: - * @trigger: Time at which alarm will trigger. - * @alarm_fn: Callback for trigger. - * @data: Closure data for callback. - * - * Adds an alarm to trigger at the specified time. The @alarm_fn will be called - * with the provided data and the alarm will be removed from the trigger list. - * - * Return value: An identifier for this alarm; it can be used to remove the - * alarm later with alarm_remove(). If the trigger time occurs in the past, then - * the alarm will not be queued and the function will return NULL. - **/ -gpointer -alarm_add (time_t trigger, AlarmFunction alarm_fn, gpointer data, - AlarmDestroyNotify destroy_notify_fn) -{ - AlarmRecord *ar; - - g_return_val_if_fail (trigger != -1, NULL); - g_return_val_if_fail (alarm_fn != NULL, NULL); - - ar = g_new (AlarmRecord, 1); - ar->trigger = trigger; - ar->alarm_fn = alarm_fn; - ar->data = data; - ar->destroy_notify_fn = destroy_notify_fn; - - queue_alarm (ar); - - return ar; -} - -/** - * alarm_remove: - * @alarm: A queued alarm identifier. - * - * Removes an alarm from the alarm queue. - **/ -void -alarm_remove (gpointer alarm) -{ - AlarmRecord *notify_id, *ar; - AlarmRecord ar_copy; - AlarmRecord *old_head; - GList *l; - - g_return_if_fail (alarm != NULL); - - ar = alarm; - - l = g_list_find (alarms, ar); - if (!l) { - g_message ("alarm_remove(): Requested removal of nonexistent alarm!"); - return; - } - - old_head = alarms->data; - - notify_id = ar; - - if (old_head == ar) { - ar_copy = *ar; - ar = &ar_copy; - pop_alarm (); /* This will free the original AlarmRecord; that's why we copy it */ - } else { - alarms = g_list_remove_link (alarms, l); - g_list_free_1 (l); - } - - /* Reset the timeout */ - - g_assert (timeout_id != 0); - - if (!alarms) { - g_source_remove (timeout_id); - timeout_id = 0; - } - - /* Notify about destructiono of the alarm */ - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (notify_id, ar->data); - -} - -/** - * alarm_done: - * - * Terminates the alarm timer mechanism. This should be called at the end of - * the program. - **/ -void -alarm_done (void) -{ - GList *l; - - if (timeout_id == 0) { - g_assert (alarms == NULL); - return; - } - - g_assert (alarms != NULL); - - g_source_remove (timeout_id); - timeout_id = 0; - - for (l = alarms; l; l = l->next) { - AlarmRecord *ar; - - ar = l->data; - - if (ar->destroy_notify_fn) - (* ar->destroy_notify_fn) (ar, ar->data); - - g_free (ar); - } - - g_list_free (alarms); - alarms = NULL; -} diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h deleted file mode 100644 index 23fde886c9..0000000000 --- a/calendar/gui/alarm-notify/alarm.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Evolution calendar - Low-level alarm timer mechanism - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_H -#define ALARM_H - -#include <time.h> -#include <glib.h> - - - -typedef void (* AlarmFunction) (gpointer alarm_id, time_t trigger, gpointer data); -typedef void (* AlarmDestroyNotify) (gpointer alarm_id, gpointer data); - -void alarm_done (void); - -gpointer alarm_add (time_t trigger, AlarmFunction alarm_fn, gpointer data, - AlarmDestroyNotify destroy_notify_fn); -void alarm_remove (gpointer alarm); - - - -#endif diff --git a/calendar/gui/alarm-notify/config-data.c b/calendar/gui/alarm-notify/config-data.c deleted file mode 100644 index ce179c9b92..0000000000 --- a/calendar/gui/alarm-notify/config-data.c +++ /dev/null @@ -1,116 +0,0 @@ -/* Evolution calendar - Configuration values for the alarm notification daemon - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "config-data.h" -#include "save.h" - - - -/* Whether we have initied ourselves by reading the data from the configuration engine */ -static gboolean inited = FALSE; -static EConfigListener *config; - - - -/* Copied from ../calendar-config.c; returns whether the locale has 'am' and - * 'pm' strings defined. - */ -static gboolean -locale_supports_12_hour_format (void) -{ - char s[16]; - time_t t = 0; - - strftime (s, sizeof s, "%p", gmtime (&t)); - return s[0] != '\0'; -} - -static void -do_cleanup (void) -{ - g_object_unref (G_OBJECT (config)); - config = NULL; - inited = FALSE; -} - -/* Ensures that the configuration values have been read */ -static void -ensure_inited (void) -{ - if (inited) - return; - - inited = TRUE; - - config = e_config_listener_new (); - if (!E_IS_CONFIG_LISTENER (config)) { - inited = FALSE; - return; - } - - g_atexit ((GVoidFunc) do_cleanup); -} - -EConfigListener * -config_data_get_listener (void) -{ - ensure_inited (); - return config; -} - -icaltimezone * -config_data_get_timezone (void) -{ - char *location; - icaltimezone *local_timezone; - - ensure_inited (); - - location = e_config_listener_get_string_with_default (config, - "/apps/evolution/calendar/display/timezone", - "UTC", NULL); - if (location && location[0]) { - local_timezone = icaltimezone_get_builtin_timezone (location); - } else { - local_timezone = icaltimezone_get_utc_timezone (); - } - - g_free (location); - - return local_timezone; -} - -gboolean -config_data_get_24_hour_format (void) -{ - ensure_inited (); - - if (locale_supports_12_hour_format ()) { - return e_config_listener_get_boolean_with_default ( - config, - "/apps/evolution/calendar/display/use_24hour_format", FALSE, NULL); - } - - return TRUE; -} diff --git a/calendar/gui/alarm-notify/config-data.h b/calendar/gui/alarm-notify/config-data.h deleted file mode 100644 index c7041be111..0000000000 --- a/calendar/gui/alarm-notify/config-data.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Evolution calendar - Configuration values for the alarm notification daemon - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CONFIG_DATA_H -#define CONFIG_DATA_H - -#include <glib.h> -#include <ical.h> -#include <e-util/e-config-listener.h> - -EConfigListener *config_data_get_listener (void); - -icaltimezone *config_data_get_timezone (void); -gboolean config_data_get_24_hour_format (void); - -#endif diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c deleted file mode 100644 index 31541204e3..0000000000 --- a/calendar/gui/alarm-notify/notify-main.c +++ /dev/null @@ -1,203 +0,0 @@ -/* Evolution calendar - Alarm notification service main file - * - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <string.h> -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-init.h> -#include <libgnome/gnome-sound.h> -#include <libgnomeui/gnome-client.h> -#include <libgnomevfs/gnome-vfs-init.h> -#include <glade/glade.h> -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo-activation/bonobo-activation.h> -#include <gtk/gtkmain.h> -#include "alarm.h" -#include "alarm-queue.h" -#include "alarm-notify.h" -#include "save.h" - - - -static GnomeClient *master_client = NULL; - -static BonoboGenericFactory *factory; - -static AlarmNotify *alarm_notify_service = NULL; - - -/* Callback for the master client's "die" signal. We must terminate the daemon - * since the session is ending. - */ -static void -client_die_cb (GnomeClient *client) -{ - gtk_main_quit (); -} - -/* Sees if a session manager is present. If so, it tells the SM how to restart - * the daemon when the session starts. It also sets the die callback so that - * the daemon can terminate properly when the session ends. - */ -static void -set_session_parameters (char **argv) -{ - int flags; - char *args[2]; - - master_client = gnome_master_client (); - flags = gnome_client_get_flags (master_client); - - if (!(flags & GNOME_CLIENT_IS_CONNECTED)) - return; - - /* The daemon should always be started up by the session manager when - * the session starts. The daemon will take care of loading whatever - * calendars it was told to load. - */ - gnome_client_set_restart_style (master_client, GNOME_RESTART_ANYWAY); - - args[0] = argv[0]; - args[1] = NULL; - - gnome_client_set_restart_command (master_client, 1, args); - - g_signal_connect (G_OBJECT (master_client), "die", - G_CALLBACK (client_die_cb), NULL); -} - -/* Factory function for the alarm notify service; just creates and references a - * singleton service object. - */ -static BonoboObject * -alarm_notify_factory_fn (BonoboGenericFactory *factory, const char *component_id, void *data) -{ - if (!alarm_notify_service) { - alarm_notify_service = alarm_notify_new (); - g_assert (alarm_notify_service != NULL); - } - - bonobo_object_ref (BONOBO_OBJECT (alarm_notify_service)); - return BONOBO_OBJECT (alarm_notify_service); -} - -/* Loads the calendars that the alarm daemon has been told to load in the past */ -static gboolean -load_calendars (gpointer user_data) -{ - GPtrArray *uris; - int i; - - alarm_queue_init (); - - /* create the alarm notification service */ - if (!alarm_notify_service) { - alarm_notify_service = alarm_notify_new (); - g_assert (alarm_notify_service != NULL); - } - - uris = get_calendars_to_load (); - if (!uris) { - g_message ("load_calendars(): Could not get the list of calendars to load"); - return TRUE; /* should we continue retrying? */; - } - - for (i = 0; i < uris->len; i++) { - char *uri; - CORBA_Environment ev; - - uri = uris->pdata[i]; - - CORBA_exception_init (&ev); - alarm_notify_add_calendar (alarm_notify_service, uri, FALSE, &ev); - - if (ev._major == CORBA_USER_EXCEPTION) { - char *ex_id; - - ex_id = CORBA_exception_id (&ev); - if (strcmp (ex_id, ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI) == 0) - g_message ("load_calendars(): Invalid URI `%s'; will not load " - "that calendar.", uri); - else if (strcmp (ex_id, - ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError) - == 0) - g_message ("load_calendars(): Could not contact the backend " - "while trying to load `%s'", uri); - } else if (ev._major != CORBA_NO_EXCEPTION) - g_message ("load_calendars(): Exception while loading calendar `%s'", uri); - - CORBA_exception_free (&ev); - - g_free (uri); - } - - g_ptr_array_free (uris, TRUE); - - return FALSE; -} - -int -main (int argc, char **argv) -{ - bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); - textdomain (GETTEXT_PACKAGE); - - gnome_program_init ("evolution-alarm-notify", VERSION, LIBGNOME_MODULE, argc, argv, NULL); - gtk_init (&argc, &argv); - - if (bonobo_init (&argc, argv) == FALSE) - g_error (_("Could not initialize Bonobo")); - - if (!gnome_vfs_init ()) - g_error (_("Could not initialize gnome-vfs")); - - glade_init (); - - gnome_sound_init ("localhost"); - - factory = bonobo_generic_factory_new ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory", - (BonoboFactoryCallback) alarm_notify_factory_fn, NULL); - if (!factory) - g_error (_("Could not create the alarm notify service factory")); - - set_session_parameters (argv); - - g_idle_add ((GSourceFunc) load_calendars, NULL); - - bonobo_main (); - - bonobo_object_unref (BONOBO_OBJECT (factory)); - factory = NULL; - - /* FIXME: free the alarm_notify_service */ - - alarm_queue_done (); - alarm_done (); - - gnome_sound_shutdown (); - gnome_vfs_shutdown (); - - return 0; -} diff --git a/calendar/gui/alarm-notify/save.c b/calendar/gui/alarm-notify/save.c deleted file mode 100644 index e03183ed5d..0000000000 --- a/calendar/gui/alarm-notify/save.c +++ /dev/null @@ -1,191 +0,0 @@ -/* Evolution calendar - Functions to save alarm notification times - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <bonobo/bonobo-arg.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-moniker-util.h> -#include "evolution-calendar.h" -#include "config-data.h" -#include "save.h" -#include <gconf/gconf-client.h> - - - -/* Key names for the configuration values */ - -#define KEY_LAST_NOTIFICATION_TIME "/apps/evolution/calendar/notify/last_notification_time" -#define KEY_CALENDARS "/apps/evolution/calendar/notify/calendars" -#define KEY_PROGRAMS "/apps/evolution/calendar/notify/programs" - - - -/** - * save_notification_time: - * @t: A time value. - * - * Saves the last notification time so that it can be fetched the next time the - * alarm daemon is run. This way the daemon can show alarms that should have - * triggered while it was not running. - **/ -void -save_notification_time (time_t t) -{ - EConfigListener *cl; - time_t current_t; - - g_return_if_fail (t != -1); - - if (!(cl = config_data_get_listener ())) - return; - - /* we only store the new notification time if it is bigger - than the already stored one */ - current_t = e_config_listener_get_long_with_default (cl, KEY_LAST_NOTIFICATION_TIME, - -1, NULL); - if (t > current_t) - e_config_listener_set_long (cl, KEY_LAST_NOTIFICATION_TIME, (long) t); -} - -/** - * get_saved_notification_time: - * - * Queries the last saved value for alarm notification times. - * - * Return value: The last saved value, or -1 if no value had been saved before. - **/ -time_t -get_saved_notification_time (void) -{ - EConfigListener *cl; - long t; - - if (!(cl = config_data_get_listener ())) - return -1; - - t = e_config_listener_get_long_with_default (cl, KEY_LAST_NOTIFICATION_TIME, -1, NULL); - - return (time_t) t; -} - -/** - * save_calendars_to_load: - * @uris: A list of URIs of calendars. - * - * Saves the list of calendars that should be loaded the next time the alarm - * daemon starts up. - **/ -void -save_calendars_to_load (GPtrArray *uris) -{ - int i; - GConfClient *gconf = gconf_client_get_default(); - GSList *l = NULL; - - g_return_if_fail (uris != NULL); - - for (i=0;i<uris->len;i++) - l = g_slist_append(l, uris->pdata[i]); - - gconf_client_set_list(gconf, KEY_CALENDARS, GCONF_VALUE_STRING, l, NULL); - - g_slist_free(l); -} - -/** - * get_calendars_to_load: - * - * Gets the list of calendars that should be loaded when the alarm daemon starts - * up. - * - * Return value: A list of URIs, or NULL if the value could not be retrieved. - **/ -GPtrArray * -get_calendars_to_load (void) -{ - GSList *l, *n; - GPtrArray *uris; - - /* Getting the default value below is not necessarily an error, as we - * may not have saved the list of calendar yet. - */ - - l = gconf_client_get_list (gconf_client_get_default (), KEY_CALENDARS, GCONF_VALUE_STRING, NULL); - uris = g_ptr_array_new (); - while (l) { - n = l->next; - g_ptr_array_add (uris, l->data); - g_slist_free_1(l); - l = n; - } - - return uris; -} - -/** - * save_blessed_program: - * @program: a program name - * - * Saves a program name as "blessed" - **/ -void -save_blessed_program (const char *program) -{ - GConfClient *gconf = gconf_client_get_default(); - GSList *l; - - l = gconf_client_get_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); - l = g_slist_append(l, g_strdup(program)); - gconf_client_set_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, l, NULL); - g_slist_foreach(l, (GFunc)g_free, NULL); - g_slist_free(l); -} - -/** - * is_blessed_program: - * @program: a program name - * - * Checks to see if a program is blessed - * - * Return value: TRUE if program is blessed, FALSE otherwise - **/ -gboolean -is_blessed_program (const char *program) -{ - GConfClient *gconf = gconf_client_get_default(); - GSList *l, *n; - gboolean found = FALSE; - - l = gconf_client_get_list(gconf, KEY_PROGRAMS, GCONF_VALUE_STRING, NULL); - while (l) { - n = l->next; - if (!found) - found = strcmp((char *)l->data, program) == 0; - g_free(l->data); - g_slist_free_1(l); - l = n; - } - - return found; -} diff --git a/calendar/gui/alarm-notify/save.h b/calendar/gui/alarm-notify/save.h deleted file mode 100644 index f7cc75955c..0000000000 --- a/calendar/gui/alarm-notify/save.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Evolution calendar - Functions to save alarm notification times - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 SAVE_H -#define SAVE_H - -#include <time.h> - -void save_notification_time (time_t t); -time_t get_saved_notification_time (void); - -void save_calendars_to_load (GPtrArray *uris); -GPtrArray *get_calendars_to_load (void); - -void save_blessed_program (const char *program); -gboolean is_blessed_program (const char *program); - -#endif diff --git a/calendar/gui/apps_evolution_calendar.schemas b/calendar/gui/apps_evolution_calendar.schemas deleted file mode 100644 index ee69011a33..0000000000 --- a/calendar/gui/apps_evolution_calendar.schemas +++ /dev/null @@ -1,348 +0,0 @@ -<gconfschemafile> - <schemalist> - - <!-- Display --> - - <schema> - <key>/schemas/apps/evolution/calendar/display/timezone</key> - <applyto>/apps/evolution/calendar/display/timezone</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default>UTC</default> - <locale name="C"> - <short>Default timezone for meetings</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/use_24hour_format</key> - <applyto>/apps/evolution/calendar/display/use_24hour_format</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>false</default> - <locale name="C"> - <short>Whether to show times in 24h format instead of using am/pm</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/week_start_day</key> - <applyto>/apps/evolution/calendar/display/week_start_day</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>1</default> - <locale name="C"> - <short>Weekday the week starts on</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/day_start_hour</key> - <applyto>/apps/evolution/calendar/display/day_start_hour</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>9</default> - <locale name="C"> - <short>Hour the workday starts on</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/day_start_minute</key> - <applyto>/apps/evolution/calendar/display/day_start_minute</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>0</default> - <locale name="C"> - <short>Minute the workday starts on</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/day_end_hour</key> - <applyto>/apps/evolution/calendar/display/day_end_hour</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>17</default> - <locale name="C"> - <short>Hour the workday ends on</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/day_end_minute</key> - <applyto>/apps/evolution/calendar/display/day_end_minute</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>0</default> - <locale name="C"> - <short>Minute the workday ends on</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/time_divisions</key> - <applyto>/apps/evolution/calendar/display/time_divisions</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>30</default> - <locale name="C"> - <short>Intervals shown in Day and Work Week views</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/default_view</key> - <applyto>/apps/evolution/calendar/display/default_view</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>0</default> - <locale name="C"> - <short>The view showing when the calendar starts</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/hpane_position</key> - <applyto>/apps/evolution/calendar/display/hpane_position</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>400</default> - <locale name="C"> - <short>Position of the horizontal pane</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/vpane_position</key> - <applyto>/apps/evolution/calendar/display/vpane_position</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>150</default> - <locale name="C"> - <short>Position of the vertical pane</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/month_hpane_position</key> - <applyto>/apps/evolution/calendar/display/month_hpane_position</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>32000</default> - <locale name="C"> - <short>Position of the horizontal pane in the month view</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/month_vpane_position</key> - <applyto>/apps/evolution/calendar/display/month_vpane_position</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>150</default> - <locale name="C"> - <short>Position of the vertical pane in the month view</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/compress_weekend</key> - <applyto>/apps/evolution/calendar/display/compress_weekend</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>true</default> - <locale name="C"> - <short>Allocate less space to weekend appointments</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/show_event_end</key> - <applyto>/apps/evolution/calendar/display/show_event_end</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>true</default> - <locale name="C"> - <short>Show where events end in week and month views</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/display/working_days</key> - <applyto>/apps/evolution/calendar/display/working_days</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>62</default> - <locale name="C"> - <short>Days that are work days</short> - </locale> - </schema> - - <!-- Tasks --> - - <schema> - <key>/schemas/apps/evolution/calendar/tasks/hide_completed</key> - <applyto>/apps/evolution/calendar/tasks/hide_completed</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>false</default> - <locale name="C"> - <short>Whether to hide completed tasks</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/tasks/hide_completed_units</key> - <applyto>/apps/evolution/calendar/tasks/hide_completed_units</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default>days</default> - <locale name="C"> - <short>Units for determining when to hide tasks</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/tasks/hide_completed_value</key> - <applyto>/apps/evolution/calendar/tasks/hide_completed_value</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>1</default> - <locale name="C"> - <short>Number of units for determining when to hide tasks</short> - </locale> - </schema> - - <!-- Tasks: Colors --> - - <schema> - <key>/schemas/apps/evolution/calendar/tasks/colors/due_today</key> - <applyto>/apps/evolution/calendar/tasks/colors/due_today</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default>blue</default> - <locale name="C"> - <short>Color of tasks that are due today</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/tasks/colors/overdue</key> - <applyto>/apps/evolution/calendar/tasks/colors/overdue</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default>red</default> - <locale name="C"> - <short>Color of tasks that are overdue</short> - </locale> - </schema> - - <!-- Miscellaneous --> - - <schema> - <key>/schemas/apps/evolution/calendar/prompts/confirm_delete</key> - <applyto>/apps/evolution/calendar/prompts/confirm_delete</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>true</default> - <locale name="C"> - <short>Whether to ask for confirmation on appointment deletion</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/prompts/confirm_expunge</key> - <applyto>/apps/evolution/calendar/prompts/confirm_expunge</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>true</default> - <locale name="C"> - <short>Whether to ask for confirmation when folder is expunged</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/other/use_default_reminder</key> - <applyto>/apps/evolution/calendar/other/use_default_reminder</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>false</default> - <locale name="C"> - <short>Whether to set a default reminder for events</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/other/default_reminder_interval</key> - <applyto>/apps/evolution/calendar/other/default_reminder_interval</applyto> - <owner>evolution-calendar</owner> - <type>int</type> - <default>15</default> - <locale name="C"> - <short>Number of units for default reminder</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/other/default_reminder_units</key> - <applyto>/apps/evolution/calendar/other/default_reminder_units</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default></default> - <locale name="C"> - <short>Units of default reminder</short> - </locale> - </schema> - - <!-- Date navigator --> - - <schema> - <key>/schemas/apps/evolution/calendar/date_navigator/show_week_numbers</key> - <applyto>/apps/evolution/calendar/date_navigator/show_week_numbers</applyto> - <owner>evolution-calendar</owner> - <type>bool</type> - <default>false</default> - <locale name="C"> - <short>Whether to show week numbers in date navigator</short> - </locale> - </schema> - - <!-- Alarm notification --> - - <schema> - <key>/schemas/apps/evolution/calendar/notify/last_notification_time</key> - <applyto>/apps/evolution/calendar/notify/last_notification_time</applyto> - <owner>evolution-calendar</owner> - <type>string</type> - <default>-1</default> - <locale name="C"> - <short>Time last alarm ran</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/notify/calendars</key> - <applyto>/apps/evolution/calendar/notify/calendars</applyto> - <owner>evolution-calendar</owner> - <type>list</type> - <list_type>string</list_type> - <default>[]</default> - <locale name="C"> - <short>Calendars to run alarms for</short> - </locale> - </schema> - - <schema> - <key>/schemas/apps/evolution/calendar/notify/programs</key> - <applyto>/apps/evolution/calendar/notify/programs</applyto> - <owner>evolution-calendar</owner> - <type>list</type> - <list_type>string</list_type> - <default>[]</default> - <locale name="C"> - <short>Programs that can run as part of alarms</short> - </locale> - </schema> - </schemalist> -</gconfschemafile> diff --git a/calendar/gui/cal-search-bar.c b/calendar/gui/cal-search-bar.c deleted file mode 100644 index d04cbcb492..0000000000 --- a/calendar/gui/cal-search-bar.c +++ /dev/null @@ -1,514 +0,0 @@ -/* Evolution calendar - Search bar widget for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <glib.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkmenuitem.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtksignal.h> -#include <libgnome/gnome-i18n.h> -#include <gal/widgets/e-unicode.h> -#include <gal/util/e-util.h> -#include "cal-search-bar.h" - - - -/* IDs and option items for the ESearchBar */ -enum { - SEARCH_ANY_FIELD_CONTAINS, - SEARCH_SUMMARY_CONTAINS, - SEARCH_DESCRIPTION_CONTAINS, - SEARCH_COMMENT_CONTAINS, - SEARCH_CATEGORY_IS, -}; - -static ESearchBarItem search_option_items[] = { - { N_("Any field contains"), SEARCH_ANY_FIELD_CONTAINS, NULL }, - { N_("Summary contains"), SEARCH_SUMMARY_CONTAINS, NULL }, - { N_("Description contains"), SEARCH_DESCRIPTION_CONTAINS, NULL }, - { N_("Comment contains"), SEARCH_COMMENT_CONTAINS, NULL }, - { N_("Category is"), SEARCH_CATEGORY_IS, NULL }, - { NULL, -1, NULL } -}; - -/* IDs for the categories suboptions */ -#define CATEGORIES_ALL 0 -#define CATEGORIES_UNMATCHED 1 -#define CATEGORIES_OFFSET 3 - -/* Private part of the CalSearchBar structure */ -struct CalSearchBarPrivate { - /* Array of categories */ - GPtrArray *categories; -}; - - - -static void cal_search_bar_class_init (CalSearchBarClass *class); -static void cal_search_bar_init (CalSearchBar *cal_search); -static void cal_search_bar_destroy (GtkObject *object); - -static void cal_search_bar_search_activated (ESearchBar *search); - -static ESearchBarClass *parent_class = NULL; - -/* Signal IDs */ -enum { - SEXP_CHANGED, - CATEGORY_CHANGED, - LAST_SIGNAL -}; - -static guint cal_search_bar_signals[LAST_SIGNAL] = { 0 }; - - - -E_MAKE_TYPE (cal_search_bar, "CalSearchBar", CalSearchBar, cal_search_bar_class_init, - cal_search_bar_init, E_SEARCH_BAR_TYPE); - -/* Class initialization function for the calendar search bar */ -static void -cal_search_bar_class_init (CalSearchBarClass *class) -{ - ESearchBarClass *e_search_bar_class; - GtkObjectClass *object_class; - - e_search_bar_class = (ESearchBarClass *) class; - object_class = (GtkObjectClass *) class; - - parent_class = g_type_class_peek_parent (class); - - cal_search_bar_signals[SEXP_CHANGED] = - gtk_signal_new ("sexp_changed", - GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (CalSearchBarClass, sexp_changed), - gtk_marshal_NONE__STRING, - GTK_TYPE_NONE, 1, - GTK_TYPE_STRING); - - cal_search_bar_signals[CATEGORY_CHANGED] = - gtk_signal_new ("category_changed", - GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (CalSearchBarClass, category_changed), - gtk_marshal_NONE__STRING, - GTK_TYPE_NONE, 1, - GTK_TYPE_STRING); - - class->sexp_changed = NULL; - class->category_changed = NULL; - - e_search_bar_class->search_activated = cal_search_bar_search_activated; - - object_class->destroy = cal_search_bar_destroy; -} - -/* Object initialization function for the calendar search bar */ -static void -cal_search_bar_init (CalSearchBar *cal_search) -{ - CalSearchBarPrivate *priv; - - priv = g_new (CalSearchBarPrivate, 1); - cal_search->priv = priv; - - priv->categories = g_ptr_array_new (); - g_ptr_array_set_size (priv->categories, 0); -} - -/* Frees an array of categories */ -static void -free_categories (GPtrArray *categories) -{ - int i; - - for (i = 0; i < categories->len; i++) { - g_assert (categories->pdata[i] != NULL); - g_free (categories->pdata[i]); - } - - g_ptr_array_free (categories, TRUE); -} - -/* Destroy handler for the calendar search bar */ -static void -cal_search_bar_destroy (GtkObject *object) -{ - CalSearchBar *cal_search; - CalSearchBarPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_CAL_SEARCH_BAR (object)); - - cal_search = CAL_SEARCH_BAR (object); - priv = cal_search->priv; - - if (priv) { - if (priv->categories) { - free_categories (priv->categories); - priv->categories = NULL; - } - - g_free (priv); - cal_search->priv = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - - -/* Emits the "sexp_changed" signal for the calendar search bar */ -static void -notify_sexp_changed (CalSearchBar *cal_search, const char *sexp) -{ - gtk_signal_emit (GTK_OBJECT (cal_search), cal_search_bar_signals[SEXP_CHANGED], - sexp); -} - -/* Returns the string of the currently selected category, NULL for "Unmatched", - * or (const char *) 1 for "All". - */ -static const char * -get_current_category (CalSearchBar *cal_search) -{ - CalSearchBarPrivate *priv; - int id, subid; - - priv = cal_search->priv; - - g_assert (priv->categories != NULL); - - id = e_search_bar_get_item_id (E_SEARCH_BAR (cal_search)); - if (id != SEARCH_CATEGORY_IS) - return NULL; - - subid = e_search_bar_get_subitem_id (E_SEARCH_BAR (cal_search)); - if (subid == CATEGORIES_ALL) - return (const char *) 1; - else if (subid == CATEGORIES_UNMATCHED) - return NULL; - else { - int i; - - i = subid - CATEGORIES_OFFSET; - g_assert (i >= 0 && i < priv->categories->len); - - return priv->categories->pdata[i]; - } -} - -/* Sets the query string to be (contains? "field" "text") */ -static void -notify_query_contains (CalSearchBar *cal_search, const char *field) -{ - char *text; - char *sexp; - - text = e_search_bar_get_text (E_SEARCH_BAR (cal_search)); - if (!text) - return; /* This is an error in the UTF8 conversion, not an empty string! */ - - sexp = g_strdup_printf ("(contains? \"%s\" \"%s\")", field, text); - g_free (text); - - notify_sexp_changed (cal_search, sexp); - g_free (sexp); -} - -/* Returns a sexp for the selected category in the drop-down menu. The "All" - * option is returned as (const char *) 1, and the "Unfiled" option is returned - * as NULL. - */ -static char * -get_category_sexp (CalSearchBar *cal_search) -{ - const char *category; - - category = get_current_category (cal_search); - - if (category == NULL) - return g_strdup ("(has-categories? #f)"); /* Unfiled items */ - else if (category == (const char *) 1) - return NULL; /* All items */ - else - return g_strdup_printf ("(has-categories? \"%s\")", category); /* Specific category */ -} - -/* Sets the query string to the appropriate match for categories */ -static void -notify_category_is (CalSearchBar *cal_search) -{ - char *sexp; - - sexp = get_category_sexp (cal_search); - if (!sexp) - notify_sexp_changed (cal_search, "#t"); /* Match all */ - else - notify_sexp_changed (cal_search, sexp); - - if (sexp) - g_free (sexp); -} - -/* Creates a new query from the values in the widgets and notifies upstream */ -static void -regen_query (CalSearchBar *cal_search) -{ - CalSearchBarPrivate *priv; - int id; - const char *category; - - priv = cal_search->priv; - - /* Fetch the data from the ESearchBar's entry widgets */ - - id = e_search_bar_get_item_id (E_SEARCH_BAR (cal_search)); - - /* Generate the different types of queries */ - - switch (id) { - case SEARCH_ANY_FIELD_CONTAINS: - notify_query_contains (cal_search, "any"); - break; - - case SEARCH_SUMMARY_CONTAINS: - notify_query_contains (cal_search, "summary"); - break; - - case SEARCH_DESCRIPTION_CONTAINS: - notify_query_contains (cal_search, "description"); - break; - - case SEARCH_COMMENT_CONTAINS: - notify_query_contains (cal_search, "comment"); - break; - - case SEARCH_CATEGORY_IS: - notify_category_is (cal_search); - - category = cal_search_bar_get_category (cal_search); - gtk_signal_emit (GTK_OBJECT (cal_search), cal_search_bar_signals[CATEGORY_CHANGED], - category); - break; - - default: - g_assert_not_reached (); - } -} - -/* search_activated handler for the calendar search bar */ -static void -cal_search_bar_search_activated (ESearchBar *search) -{ - CalSearchBar *cal_search; - - cal_search = CAL_SEARCH_BAR (search); - regen_query (cal_search); -} - - - -/* Creates the suboptions menu for the ESearchBar with the list of categories */ -static void -make_suboptions (CalSearchBar *cal_search) -{ - CalSearchBarPrivate *priv; - ESearchBarSubitem *subitems; - int i; - - priv = cal_search->priv; - - g_assert (priv->categories != NULL); - - /* Categories plus "all", "unmatched", separator, terminator */ - subitems = g_new (ESearchBarSubitem, priv->categories->len + 3 + 1); - - /* All, unmatched, separator */ - - subitems[0].text = _("Any Category"); - subitems[0].id = CATEGORIES_ALL; - subitems[0].translate = FALSE; - - subitems[1].text = _("Unmatched"); - subitems[1].id = CATEGORIES_UNMATCHED; - subitems[1].translate = FALSE; - - /* All the other items */ - - if (priv->categories->len > 0) { - subitems[2].text = NULL; /* separator */ - subitems[2].id = 0; - - for (i = 0; i < priv->categories->len; i++) { - const char *category; - char *str; - - category = priv->categories->pdata[i]; - str = g_strdup (category ? category : ""); - - subitems[i + CATEGORIES_OFFSET].text = str; - subitems[i + CATEGORIES_OFFSET].id = i + CATEGORIES_OFFSET; - subitems[i + CATEGORIES_OFFSET].translate = FALSE; - } - - subitems[i + CATEGORIES_OFFSET].id = -1; /* terminator */ - } else - subitems[2].id = -1; /* terminator */ - - e_search_bar_set_suboption (E_SEARCH_BAR (cal_search), SEARCH_CATEGORY_IS, subitems); - - /* Free the strings */ - for (i = 0; i < priv->categories->len; i++) - g_free (subitems[i + CATEGORIES_OFFSET].text); - - g_free (subitems); -} - -/** - * cal_search_bar_construct: - * @cal_search: A calendar search bar. - * - * Constructs a calendar search bar by binding its menu and option items. - * - * Return value: The same value as @cal_search. - **/ -CalSearchBar * -cal_search_bar_construct (CalSearchBar *cal_search) -{ - g_return_val_if_fail (cal_search != NULL, NULL); - g_return_val_if_fail (IS_CAL_SEARCH_BAR (cal_search), NULL); - - e_search_bar_construct (E_SEARCH_BAR (cal_search), NULL, search_option_items); - make_suboptions (cal_search); - - e_search_bar_set_ids (E_SEARCH_BAR (cal_search), SEARCH_CATEGORY_IS, CATEGORIES_ALL); - - return cal_search; -} - -/** - * cal_search_bar_new: - * - * Creates a new calendar search bar. - * - * Return value: A newly-created calendar search bar. You should connect to the - * "sexp_changed" signal to monitor changes in the generated sexps. - **/ -GtkWidget * -cal_search_bar_new (void) -{ - CalSearchBar *cal_search; - - cal_search = g_object_new (TYPE_CAL_SEARCH_BAR, NULL); - return GTK_WIDGET (cal_search_bar_construct (cal_search)); -} - -/* Used from qsort() */ -static int -compare_categories_cb (const void *a, const void *b) -{ - const char **ca, **cb; - - ca = (const char **) a; - cb = (const char **) b; - - /* FIXME: should use some utf8 strcoll() thingy */ - return strcmp (*ca, *cb); -} - -/* Creates a sorted array of categories based on the original one; copies the - * string values. - */ -static GPtrArray * -sort_categories (GPtrArray *categories) -{ - GPtrArray *c; - int i; - - c = g_ptr_array_new (); - g_ptr_array_set_size (c, categories->len); - - for (i = 0; i < categories->len; i++) - c->pdata[i] = g_strdup (categories->pdata[i]); - - qsort (c->pdata, c->len, sizeof (gpointer), compare_categories_cb); - - return c; -} - -/** - * cal_search_bar_set_categories: - * @cal_search: A calendar search bar. - * @categories: Array of pointers to strings for the category names. - * - * Sets the list of categories that are to be shown in the drop-down list - * of a calendar search bar. The search bar will automatically add an item - * for "unfiled" components, that is, those that have no categories assigned - * to them. - **/ -void -cal_search_bar_set_categories (CalSearchBar *cal_search, GPtrArray *categories) -{ - CalSearchBarPrivate *priv; - - g_return_if_fail (cal_search != NULL); - g_return_if_fail (IS_CAL_SEARCH_BAR (cal_search)); - g_return_if_fail (categories != NULL); - - priv = cal_search->priv; - - g_assert (priv->categories != NULL); - free_categories (priv->categories); - - priv->categories = sort_categories (categories); - make_suboptions (cal_search); -} - -/** - * cal_search_bar_get_category: - * @cal_search: A calendar search bar. - * - * Queries the currently selected category name in a calendar search bar. - * If "All" or "Unfiled" are selected, this function will return NULL. - * - * Return value: Name of the selected category, or NULL if there is no - * selected category. - **/ -const char * -cal_search_bar_get_category (CalSearchBar *cal_search) -{ - const char *category; - - category = get_current_category (cal_search); - - if (!category || category == (const char *) 1) - return NULL; - else - return category; -} diff --git a/calendar/gui/cal-search-bar.h b/calendar/gui/cal-search-bar.h deleted file mode 100644 index a8910ba7b4..0000000000 --- a/calendar/gui/cal-search-bar.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Evolution calendar - Search bar widget for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CAL_SEARCH_BAR_H -#define CAL_SEARCH_BAR_H - -#include "widgets/misc/e-search-bar.h" -#include "widgets/misc/e-filter-bar.h" - -G_BEGIN_DECLS - - - -#define TYPE_CAL_SEARCH_BAR (cal_search_bar_get_type ()) -#define CAL_SEARCH_BAR(obj) (GTK_CHECK_CAST ((obj), TYPE_CAL_SEARCH_BAR, CalSearchBar)) -#define CAL_SEARCH_BAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_CAL_SEARCH_BAR, \ - CalSearchBarClass)) -#define IS_CAL_SEARCH_BAR(obj) (GTK_CHECK_TYPE ((obj), TYPE_CAL_SEARCH_BAR)) -#define IS_CAL_SEARCH_BAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_CAL_SEARCH_BAR)) - -typedef struct CalSearchBarPrivate CalSearchBarPrivate; - -typedef struct { - ESearchBar search_bar; - - /* Private data */ - CalSearchBarPrivate *priv; -} CalSearchBar; - -typedef struct { - ESearchBarClass parent_class; - - /* Notification signals */ - - void (* sexp_changed) (CalSearchBar *cal_search, const char *sexp); - void (* category_changed) (CalSearchBar *cal_search, const char *category); -} CalSearchBarClass; - -GtkType cal_search_bar_get_type (void); - -CalSearchBar *cal_search_bar_construct (CalSearchBar *cal_search); - -GtkWidget *cal_search_bar_new (void); - -void cal_search_bar_set_categories (CalSearchBar *cal_search, GPtrArray *categories); - -const char *cal_search_bar_get_category (CalSearchBar *cal_search); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c deleted file mode 100644 index 6dac8ec8a5..0000000000 --- a/calendar/gui/calendar-commands.c +++ /dev/null @@ -1,855 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution calendar - Commands for the calendar GUI control - * - * Copyright (C) 1998 The Free Software Foundation - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <pwd.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gtk/gtkfilesel.h> -#include <gtk/gtkmain.h> -#include <gtk/gtksignal.h> - -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnome/gnome-util.h> -#include <libgnome/gnome-i18n.h> -#include <bonobo/bonobo-ui-util.h> -#include <bonobo/bonobo-exception.h> -#include <cal-util/timeutil.h> -#include "shell/Evolution.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "e-day-view.h" -#include "e-week-view.h" -#include "gnome-cal.h" -#include "goto.h" -#include "print.h" -#include "dialogs/cal-prefs-dialog.h" -#include "itip-utils.h" -#include "evolution-shell-component-utils.h" - -/* A list of all of the calendars started */ -static GList *all_calendars = NULL; - -/* Focusing information for the calendar view. We have to keep track of this - * ourselves because with Bonobo controls, we may get unpaired focus_out events. - */ -typedef struct { - guint calendar_focused : 1; - guint taskpad_focused : 1; -} FocusData; - -/* Prints the calendar at its current view and time range */ -static void -print (GnomeCalendar *gcal, gboolean preview) -{ - time_t start; - GnomeCalendarViewType view_type; - PrintView print_view; - - gnome_calendar_get_current_time_range (gcal, &start, NULL); - view_type = gnome_calendar_get_view (gcal); - - switch (view_type) { - case GNOME_CAL_DAY_VIEW: - print_view = PRINT_VIEW_DAY; - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - case GNOME_CAL_WEEK_VIEW: - print_view = PRINT_VIEW_WEEK; - break; - - case GNOME_CAL_MONTH_VIEW: - print_view = PRINT_VIEW_MONTH; - break; - - default: - g_assert_not_reached (); - return; - } - - print_calendar (gcal, preview, start, print_view); -} - -/* File/Print callback */ -static void -file_print_cb (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - print (gcal, FALSE); -} - -static void -file_print_preview_cb (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - print (gcal, TRUE); -} - -/* This iterates over each calendar telling them to update their config - settings. */ -void -update_all_config_settings (void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_update_config_settings (GNOME_CALENDAR (l->data), FALSE); -} - - -/* Sets a clock cursor for the specified calendar window */ -static void -set_clock_cursor (GnomeCalendar *gcal) -{ - GdkCursor *cursor; - - cursor = gdk_cursor_new (GDK_WATCH); - gdk_window_set_cursor (GTK_WIDGET (gcal)->window, cursor); - gdk_cursor_destroy (cursor); - gdk_flush (); -} - -/* Resets the normal cursor for the specified calendar window */ -static void -set_normal_cursor (GnomeCalendar *gcal) -{ - gdk_window_set_cursor (GTK_WIDGET (gcal)->window, NULL); - gdk_flush (); -} - -static void -previous_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_previous (gcal); - set_normal_cursor (gcal); -} - -static void -next_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_next (gcal); - set_normal_cursor (gcal); -} - -void -calendar_goto_today (GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_goto_today (gcal); - set_normal_cursor (gcal); -} - -static void -today_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - calendar_goto_today (gcal); -} - -static void -goto_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - goto_dialog (gcal); -} - -static void -show_day_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, FALSE, TRUE); -} - -static void -show_work_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gnome_calendar_set_view (gcal, GNOME_CAL_WORK_WEEK_VIEW, FALSE, TRUE); -} - -static void -show_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gnome_calendar_set_view (gcal, GNOME_CAL_WEEK_VIEW, FALSE, TRUE); -} - -static void -show_month_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gnome_calendar_set_view (gcal, GNOME_CAL_MONTH_VIEW, FALSE, TRUE); -} - - - -static void -cut_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - set_clock_cursor (gcal); - gnome_calendar_cut_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -copy_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_copy_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -paste_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_paste_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -delete_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_delete_selection (gcal); - set_normal_cursor (gcal); -} - -static void -delete_occurrence_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_delete_selected_occurrence (gcal); - set_normal_cursor (gcal); -} - -static void -publish_freebusy_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - CalClient *client; - GList *comp_list; - icaltimezone *utc; - time_t start = time (NULL), end; - - gcal = GNOME_CALENDAR (data); - - utc = icaltimezone_get_utc_timezone (); - start = time_day_begin_with_zone (start, utc); - end = time_add_week_with_zone (start, 6, utc); - - client = gnome_calendar_get_cal_client (gcal); - comp_list = cal_client_get_free_busy (client, NULL, start, end); - if (comp_list) { - GList *l; - - for (l = comp_list; l; l = l->next) { - CalComponent *comp = CAL_COMPONENT (l->data); - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, client, NULL); - - g_object_unref (comp); - } - - g_list_free (comp_list); - } -} - -/* Does a queryInterface on the control's parent control frame for the ShellView interface */ -static GNOME_Evolution_ShellView -get_shell_view_interface (BonoboControl *control) -{ - Bonobo_ControlFrame control_frame; - GNOME_Evolution_ShellView shell_view; - CORBA_Environment ev; - - control_frame = bonobo_control_get_control_frame (control, NULL); - - g_assert (control_frame != CORBA_OBJECT_NIL); - - CORBA_exception_init (&ev); - shell_view = Bonobo_Unknown_queryInterface (control_frame, - "IDL:GNOME/Evolution/ShellView:1.0", - &ev); - if (BONOBO_EX (&ev)) { - g_message ("get_shell_view_interface(): " - "Could not queryInterface() on the control frame"); - shell_view = CORBA_OBJECT_NIL; - goto out; - } - - CORBA_exception_free (&ev); - - out: - - return shell_view; -} - -/* Displays the currently displayed time range in the folder bar label on the - shell view, according to which view we are showing. */ -void -calendar_set_folder_bar_label (GnomeCalendar *gcal, BonoboControl *control) -{ - icaltimezone *zone; - struct icaltimetype start_tt, end_tt; - time_t start_time, end_time; - struct tm start_tm, end_tm; - char buffer[512], end_buffer[256]; - GnomeCalendarViewType view; - - gnome_calendar_get_visible_time_range (gcal, &start_time, &end_time); - zone = gnome_calendar_get_timezone (gcal); - - start_tt = icaltime_from_timet_with_zone (start_time, FALSE, zone); - start_tm.tm_year = start_tt.year - 1900; - start_tm.tm_mon = start_tt.month - 1; - start_tm.tm_mday = start_tt.day; - start_tm.tm_hour = start_tt.hour; - start_tm.tm_min = start_tt.minute; - start_tm.tm_sec = start_tt.second; - start_tm.tm_isdst = -1; - start_tm.tm_wday = time_day_of_week (start_tt.day, start_tt.month - 1, - start_tt.year); - - /* Take one off end_time so we don't get an extra day. */ - end_tt = icaltime_from_timet_with_zone (end_time - 1, FALSE, zone); - end_tm.tm_year = end_tt.year - 1900; - end_tm.tm_mon = end_tt.month - 1; - end_tm.tm_mday = end_tt.day; - end_tm.tm_hour = end_tt.hour; - end_tm.tm_min = end_tt.minute; - end_tm.tm_sec = end_tt.second; - end_tm.tm_isdst = -1; - end_tm.tm_wday = time_day_of_week (end_tt.day, end_tt.month - 1, - end_tt.year); - - view = gnome_calendar_get_view (gcal); - - switch (view) { - case GNOME_CAL_DAY_VIEW: - case GNOME_CAL_WORK_WEEK_VIEW: - case GNOME_CAL_WEEK_VIEW: - if (start_tm.tm_year == end_tm.tm_year - && start_tm.tm_mon == end_tm.tm_mon - && start_tm.tm_mday == end_tm.tm_mday) { - strftime (buffer, sizeof (buffer), - _("%A %d %B %Y"), &start_tm); - } else if (start_tm.tm_year == end_tm.tm_year) { - strftime (buffer, sizeof (buffer), - _("%a %d %b"), &start_tm); - strftime (end_buffer, sizeof (end_buffer), - _("%a %d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } else { - strftime (buffer, sizeof (buffer), - _("%a %d %b %Y"), &start_tm); - strftime (end_buffer, sizeof (end_buffer), - _("%a %d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - break; - case GNOME_CAL_MONTH_VIEW: - if (start_tm.tm_year == end_tm.tm_year) { - if (start_tm.tm_mon == end_tm.tm_mon) { - strftime (buffer, sizeof (buffer), - "%d", &start_tm); - strftime (end_buffer, sizeof (end_buffer), - _("%d %B %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } else { - strftime (buffer, sizeof (buffer), - _("%d %B"), &start_tm); - strftime (end_buffer, sizeof (end_buffer), - _("%d %B %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - } else { - strftime (buffer, sizeof (buffer), - _("%d %B %Y"), &start_tm); - strftime (end_buffer, sizeof (end_buffer), - _("%d %B %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - break; - default: - g_assert_not_reached (); - } - - control_util_set_folder_bar_label (control, buffer); -} - -void -control_util_set_folder_bar_label (BonoboControl *control, char *label) -{ - GNOME_Evolution_ShellView shell_view; - CORBA_Environment ev; - - shell_view = get_shell_view_interface (control); - if (shell_view == CORBA_OBJECT_NIL) - return; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellView_setFolderBarLabel (shell_view, label, &ev); - - if (BONOBO_EX (&ev)) - g_message ("control_util_set_folder_bar_label(): Could not set the folder bar label"); - - CORBA_exception_free (&ev); -} - -void -control_util_show_settings (GnomeCalendar *gcal) -{ - BonoboControl *control; - GNOME_Evolution_ShellView shell_view; - CORBA_Environment ev; - - control = g_object_get_data (G_OBJECT (gcal), "control"); - if (control == NULL) - return; - - shell_view = get_shell_view_interface (control); - if (shell_view == CORBA_OBJECT_NIL) - return; - - CORBA_exception_init (&ev); - - GNOME_Evolution_ShellView_showSettings (shell_view, &ev); - - if (BONOBO_EX (&ev)) - g_message ("control_util_show_settings(): Could not show settings"); - - CORBA_exception_free (&ev); -} - -/* Sensitizes the UI Component menu/toolbar calendar commands based on the - * number of selected events. (This will always be 0 or 1 currently.) If enable - * is FALSE, all will be disabled. Otherwise, the currently-selected number of - * events will be used. - */ -static void -sensitize_calendar_commands (GnomeCalendar *gcal, BonoboControl *control, gboolean enable) -{ - BonoboUIComponent *uic; - int n_selected; - gboolean read_only, has_recurrences; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - n_selected = enable ? gnome_calendar_get_num_events_selected (gcal) : 0; - read_only = cal_client_is_read_only (gnome_calendar_get_cal_client (gcal)); - - bonobo_ui_component_set_prop (uic, "/commands/Cut", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Copy", "sensitive", - n_selected == 0 ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Paste", "sensitive", - enable && !read_only ? "1" : "0", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Delete", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - - /* occurrence-related menu items */ - has_recurrences = FALSE; - if (n_selected > 0 && !read_only) { - CalComponent *comp; - GtkWidget *view; - - view = gnome_calendar_get_current_view_widget (gcal); - if (E_IS_DAY_VIEW (view)) - comp = e_day_view_get_selected_event (E_DAY_VIEW (view)); - else if (E_IS_WEEK_VIEW (view)) - comp = e_week_view_get_selected_event (E_WEEK_VIEW (view)); - else - comp = NULL; - - if (comp) { - if (cal_component_has_recurrences (comp)) - has_recurrences = TRUE; - } - } - - bonobo_ui_component_set_prop (uic, "/commands/DeleteOccurrence", "sensitive", - has_recurrences ? "1" : "0", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/DeleteAllOccurrences", "sensitive", - has_recurrences ? "1" : "0", - NULL); -} - -/* Sensitizes the UI Component menu/toolbar tasks commands based on the number - * of selected tasks. If enable is FALSE, all will be disabled. Otherwise, the - * currently-selected number of tasks will be used. - */ -static void -sensitize_taskpad_commands (GnomeCalendar *gcal, BonoboControl *control, gboolean enable) -{ - BonoboUIComponent *uic; - int n_selected; - gboolean read_only; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - n_selected = enable ? gnome_calendar_get_num_tasks_selected (gcal) : 0; - read_only = cal_client_is_read_only (gnome_calendar_get_task_pad_cal_client (gcal)); - - bonobo_ui_component_set_prop (uic, "/commands/Cut", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Copy", "sensitive", - n_selected == 0 ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Paste", "sensitive", - enable && !read_only ? "1" : "0", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/Delete", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); -} - -/* Callback used when the dates shown by the GnomeCalendar are changed. - We want to update the dates in the folder bar. */ -static void -gcal_calendar_dates_change_cb (GnomeCalendar *gcal, gpointer data) -{ - BonoboControl *control; - - control = BONOBO_CONTROL (data); - - calendar_set_folder_bar_label (gcal, control); -} - -/* Callback used when the selection in the calendar views changes */ -static void -gcal_calendar_selection_changed_cb (GnomeCalendar *gcal, gpointer data) -{ - BonoboControl *control; - - control = BONOBO_CONTROL (data); - - sensitize_calendar_commands (gcal, control, TRUE); -} - -/* Callback used when the selection in the taskpad changes */ -static void -gcal_taskpad_selection_changed_cb (GnomeCalendar *gcal, gpointer data) -{ - BonoboControl *control; - - control = BONOBO_CONTROL (data); - - sensitize_taskpad_commands (gcal, control, TRUE); -} - -/* Callback used when the focus changes for a calendar view */ -static void -gcal_calendar_focus_change_cb (GnomeCalendar *gcal, gboolean in, gpointer data) -{ - BonoboControl *control; - FocusData *focus; - - control = BONOBO_CONTROL (data); - - focus = g_object_get_data (G_OBJECT (control), "focus_data"); - g_assert (focus != NULL); - - if (in) { - g_signal_connect (gcal, "calendar_selection_changed", - G_CALLBACK (gcal_calendar_selection_changed_cb), control); - sensitize_calendar_commands (gcal, control, TRUE); - focus->calendar_focused = TRUE; - } else if (focus->calendar_focused) { - gtk_signal_disconnect_by_func (GTK_OBJECT (gcal), - G_CALLBACK (gcal_calendar_selection_changed_cb), - control); - sensitize_calendar_commands (gcal, control, FALSE); - focus->calendar_focused = FALSE; - } -} - -/* Callback used when the taskpad focus changes */ -static void -gcal_taskpad_focus_change_cb (GnomeCalendar *gcal, gboolean in, gpointer data) -{ - BonoboControl *control; - FocusData *focus; - - control = BONOBO_CONTROL (data); - - focus = g_object_get_data (G_OBJECT (control), "focus_data"); - g_assert (focus != NULL); - - if (in) { - g_signal_connect (gcal, "taskpad_selection_changed", - G_CALLBACK (gcal_taskpad_selection_changed_cb), control); - sensitize_taskpad_commands (gcal, control, TRUE); - focus->taskpad_focused = TRUE; - } else if (focus->taskpad_focused) { - /* With Bonobo controls, we may get unpaired focus_out events. - * That is why we have to keep track of this ourselves instead - * of blindly assumming that we are getting this event because - * the taskpad was in fact focused. - */ - gtk_signal_disconnect_by_func (GTK_OBJECT (gcal), - G_CALLBACK (gcal_taskpad_selection_changed_cb), - control); - sensitize_taskpad_commands (gcal, control, FALSE); - focus->taskpad_focused = FALSE; - } - -} - - -static BonoboUIVerb verbs [] = { - BONOBO_UI_VERB ("CalendarPrint", file_print_cb), - BONOBO_UI_VERB ("CalendarPrintPreview", file_print_preview_cb), - - BONOBO_UI_VERB ("Cut", cut_cmd), - BONOBO_UI_VERB ("Copy", copy_cmd), - BONOBO_UI_VERB ("Paste", paste_cmd), - BONOBO_UI_VERB ("Delete", delete_cmd), - BONOBO_UI_VERB ("DeleteOccurrence", delete_occurrence_cmd), - BONOBO_UI_VERB ("DeleteAllOccurrences", delete_cmd), - - BONOBO_UI_VERB ("CalendarPrev", previous_clicked), - BONOBO_UI_VERB ("CalendarToday", today_clicked), - BONOBO_UI_VERB ("CalendarNext", next_clicked), - BONOBO_UI_VERB ("CalendarGoto", goto_clicked), - - BONOBO_UI_VERB ("ShowDayView", show_day_view_clicked), - BONOBO_UI_VERB ("ShowWorkWeekView", show_work_week_view_clicked), - BONOBO_UI_VERB ("ShowWeekView", show_week_view_clicked), - BONOBO_UI_VERB ("ShowMonthView", show_month_view_clicked), - - BONOBO_UI_VERB ("PublishFreeBusy", publish_freebusy_cmd), - - BONOBO_UI_VERB_END -}; - -static EPixmap pixmaps [] = -{ - E_PIXMAP ("/menu/EditPlaceholder/Edit/Cut", "16_cut.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/Copy", "16_copy.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/Paste", "16_paste.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/Delete", "evolution-trash-mini.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/DeleteOccurrence", "evolution-trash-mini.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/DeleteAllOccurrences", "evolution-trash-mini.png"), - E_PIXMAP ("/menu/File/Print/Print", "print.xpm"), - E_PIXMAP ("/menu/File/Print/PrintPreview", "print-preview.xpm"), - E_PIXMAP ("/menu/View/ViewBegin/Goto", "goto-16.png"), - - E_PIXMAP ("/Toolbar/Print", "buttons/print.png"), - E_PIXMAP ("/Toolbar/Delete", "buttons/delete-message.png"), - E_PIXMAP ("/Toolbar/Prev", "buttons/arrow-left-24.png"), - E_PIXMAP ("/Toolbar/Next", "buttons/arrow-right-24.png"), - E_PIXMAP ("/Toolbar/Goto", "buttons/goto-24.png"), - E_PIXMAP ("/Toolbar/DayView", "buttons/dayview.xpm"), - E_PIXMAP ("/Toolbar/WorkWeekView", "buttons/workweekview.xpm"), - E_PIXMAP ("/Toolbar/WeekView", "buttons/weekview.xpm"), - E_PIXMAP ("/Toolbar/MonthView", "buttons/monthview.xpm"), - - E_PIXMAP_END -}; - -void -calendar_control_activate (BonoboControl *control, - GnomeCalendar *gcal) -{ - Bonobo_UIContainer remote_uih; - BonoboUIComponent *uic; - FocusData *focus; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - remote_uih = bonobo_control_get_remote_ui_container (control, NULL); - bonobo_ui_component_set_container (uic, remote_uih, NULL); - bonobo_object_release_unref (remote_uih, NULL); - - gnome_calendar_set_ui_component (gcal, uic); - - bonobo_ui_component_add_verb_list_with_data (uic, verbs, gcal); - - bonobo_ui_component_freeze (uic, NULL); - - bonobo_ui_util_set_ui (uic, PREFIX, - EVOLUTION_UIDIR "/evolution-calendar.xml", - "evolution-calendar", - NULL); - - e_pixmaps_update (uic, pixmaps); - - gnome_calendar_setup_view_menus (gcal, uic); - - g_signal_connect (gcal, "dates_shown_changed", - G_CALLBACK (gcal_calendar_dates_change_cb), - control); - g_signal_connect (gcal, "calendar_focus_change", - G_CALLBACK (gcal_calendar_focus_change_cb), control); - g_signal_connect (gcal, "taskpad_focus_change", - G_CALLBACK (gcal_taskpad_focus_change_cb), control); - - sensitize_calendar_commands (gcal, control, FALSE); - sensitize_taskpad_commands (gcal, control, FALSE); - - bonobo_ui_component_thaw (uic, NULL); - - /* Show the dialog for setting the timezone if the user hasn't chosen - a default timezone already. This is done in the startup wizard now, - so we don't do it here. */ -#if 0 - calendar_config_check_timezone_set (); -#endif - - calendar_set_folder_bar_label (gcal, control); - - focus = g_new (FocusData, 1); - focus->calendar_focused = FALSE; - focus->taskpad_focused = FALSE; - - g_object_set_data (G_OBJECT (control), "focus_data", focus); -} - -void -calendar_control_deactivate (BonoboControl *control, GnomeCalendar *gcal) -{ - FocusData *focus; - BonoboUIComponent *uic; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - gnome_calendar_set_ui_component (gcal, uic); - - focus = g_object_get_data (G_OBJECT (control), "focus_data"); - g_assert (focus != NULL); - - g_object_set_data (G_OBJECT (control), "focus_data", NULL); - g_free (focus); - - gnome_calendar_discard_view_menus (gcal); - - g_signal_handlers_disconnect_matched (gcal, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, control); - - bonobo_ui_component_rm (uic, "/", NULL); - bonobo_ui_component_unset_container (uic, NULL); -} - -/* Removes a calendar from our list of all calendars when it is destroyed. */ -static void -on_calendar_destroyed (GnomeCalendar *gcal) -{ - all_calendars = g_list_remove (all_calendars, gcal); -} - -GnomeCalendar * -new_calendar (void) -{ - GtkWidget *gcal; - - gcal = gnome_calendar_new (); - if (!gcal) { - gnome_warning_dialog (_("Could not create the calendar view. Please check your " - "ORBit and OAF setup.")); - return NULL; - } - - g_signal_connect (gcal, "destroy", - G_CALLBACK (on_calendar_destroyed), NULL); - - all_calendars = g_list_prepend (all_calendars, gcal); - - return GNOME_CALENDAR (gcal); -} diff --git a/calendar/gui/calendar-commands.h b/calendar/gui/calendar-commands.h deleted file mode 100644 index 9ebac6eef4..0000000000 --- a/calendar/gui/calendar-commands.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Evolution calendar - Commands for the calendar GUI control - * - * Copyright (C) 1998 The Free Software Foundation - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CALENDAR_COMMANDS_H -#define CALENDAR_COMMANDS_H - -#include "gnome-cal.h" - -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-ui-component.h> - -/* This tells all the calendars to reload the config settings. */ -void update_all_config_settings (void); - -GnomeCalendar *new_calendar (void); - -void calendar_control_activate (BonoboControl *control, GnomeCalendar *gcal); -void calendar_control_deactivate (BonoboControl *control, GnomeCalendar *gcal); - -void calendar_goto_today (GnomeCalendar *gcal); - -void calendar_set_folder_bar_label (GnomeCalendar *gcal, BonoboControl *control); - -/* Used by calendar and tasks control to set the folder title bar label. */ -void control_util_set_folder_bar_label (BonoboControl *control, char *label); - -/* Used by calendar views and tasks to show the settings dialog */ -void control_util_show_settings (GnomeCalendar *gcal); - -#endif /* CALENDAR_COMMANDS_H */ diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c deleted file mode 100644 index 98f0964cc4..0000000000 --- a/calendar/gui/calendar-component.c +++ /dev/null @@ -1,771 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* component-factory.c - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#include <config.h> - -#include <errno.h> -#include <libgnome/gnome-util.h> -#include <libgnomevfs/gnome-vfs-types.h> -#include <libgnomevfs/gnome-vfs-uri.h> -#include <libgnomevfs/gnome-vfs-ops.h> -#include <libgnomevfs/gnome-vfs-directory.h> -#include <libgnomevfs/gnome-vfs-file-info.h> - -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-exception.h> - -#include "evolution-shell-component.h" -#include "calendar-offline-handler.h" -#include "calendar-component.h" -#include "tasks-control.h" -#include "control-factory.h" -#include "calendar-config.h" -#include "tasks-control.h" -#include "e-comp-editor-registry.h" -#include "dialogs/comp-editor.h" - - -/* OAFIID for the component. */ -#define COMPONENT_ID "OAFIID:GNOME_Evolution_Calendar_ShellComponent" - -/* Folder type IDs */ -#define FOLDER_CALENDAR "calendar" -#define FOLDER_TASKS "tasks" -#define FOLDER_PUBLIC_CALENDAR "calendar/public" -#define FOLDER_PUBLIC_TASKS "tasks/public" - -/* IDs for user creatable items */ -#define CREATE_EVENT_ID "event" -#define CREATE_ALLDAY_EVENT_ID "allday-event" -#define CREATE_MEETING_ID "meeting" -#define CREATE_TASK_ID "task" - -char *evolution_dir = NULL; -EvolutionShellClient *global_shell_client = NULL; -extern ECompEditorRegistry *comp_editor_registry; - -static const EvolutionShellComponentFolderType folder_types[] = { - { FOLDER_CALENDAR, - "evolution-calendar.png", - N_("Calendar"), - N_("Folder containing appointments and events"), - TRUE, NULL, NULL }, - { FOLDER_PUBLIC_CALENDAR, - "evolution-calendar.png", - N_("Public Calendar"), - N_("Public folder containing appointments and events"), - FALSE, NULL, NULL }, - { FOLDER_TASKS, - "evolution-tasks.png", - N_("Tasks"), - N_("Folder containing to-do items"), - TRUE, NULL, NULL }, - { FOLDER_PUBLIC_TASKS, - "evolution-tasks.png", - N_("Public Tasks"), - N_("Public folder containing to-do items"), - FALSE, NULL, NULL }, - { NULL, NULL } -}; - - - -static inline gboolean -type_is_calendar (const char *type) -{ - return !strcmp (type, FOLDER_CALENDAR) || - !strcmp (type, FOLDER_PUBLIC_CALENDAR); -} - -static inline gboolean -type_is_tasks (const char *type) -{ - return !strcmp (type, FOLDER_TASKS) || - !strcmp (type, FOLDER_PUBLIC_TASKS); -} - -/* EvolutionShellComponent methods and signals. */ - -static EvolutionShellComponentResult -create_view (EvolutionShellComponent *shell_component, - const char *physical_uri, - const char *type, - const char *view_info, - BonoboControl **control_return, - void *closure) -{ - BonoboControl *control; - - if (type_is_calendar (type)) { - control = control_factory_new_control (); - if (!control) - return EVOLUTION_SHELL_COMPONENT_CORBAERROR; - } else if (type_is_tasks (type)) { - control = tasks_control_new (); - if (!control) - return EVOLUTION_SHELL_COMPONENT_CORBAERROR; - } else { - return EVOLUTION_SHELL_COMPONENT_UNSUPPORTEDTYPE; - } - - bonobo_control_set_property (control, NULL, "folder_uri", TC_CORBA_string, physical_uri, NULL); - if (type_is_calendar (type) && *view_info) - bonobo_control_set_property (control, NULL, "view", TC_CORBA_string, view_info, NULL); - - *control_return = control; - - return EVOLUTION_SHELL_COMPONENT_OK; -} - -static void -create_folder (EvolutionShellComponent *shell_component, - const char *physical_uri, - const char *type, - const GNOME_Evolution_ShellComponentListener listener, - void *closure) -{ - CORBA_Environment ev; - GnomeVFSURI *uri; - - CORBA_exception_init (&ev); - - if (!type_is_calendar (type) && !type_is_tasks (type)) { - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, - &ev); - CORBA_exception_free (&ev); - return; - } - - uri = gnome_vfs_uri_new (physical_uri); - if (uri) { - /* we don't need to do anything */ - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_OK, &ev); - gnome_vfs_uri_unref (uri); - } - else { - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_INVALID_URI, - &ev); - } - - CORBA_exception_free (&ev); -} - -/* Asks the alarm daemon to stop monitoring the specified URI */ -static void -stop_alarms (GnomeVFSURI *uri) -{ - char *str_uri; - CORBA_Environment ev; - GNOME_Evolution_Calendar_AlarmNotify an; - - /* Activate the alarm notification service */ - - CORBA_exception_init (&ev); - an = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("stop_alarms(): Could not activate the alarm notification service"); - CORBA_exception_free (&ev); - return; - } - CORBA_exception_free (&ev); - - /* Ask the service to remove the URI from its list of calendars */ - - str_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE); - g_assert (str_uri != NULL); - - CORBA_exception_init (&ev); - GNOME_Evolution_Calendar_AlarmNotify_removeCalendar (an, str_uri, &ev); - g_free (str_uri); - - if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI)) { - g_message ("stop_alarms(): Invalid URI reported from the alarm notification service"); - } else if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_AlarmNotify_NotFound)) { - /* This is OK; the service may not have loaded that calendar */ - } else if (BONOBO_EX (&ev)) { - g_message ("stop_alarms(): Could not issue the removeCalendar request"); - } - - CORBA_exception_free (&ev); - - /* Get rid of the service */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (an, &ev); - if (BONOBO_EX (&ev)) - g_message ("stop_alarms(): Could not unref the alarm notification service"); - CORBA_exception_free (&ev); -} - -static void -remove_folder (EvolutionShellComponent *shell_component, - const char *physical_uri, - const char *type, - const GNOME_Evolution_ShellComponentListener listener, - void *closure) -{ - GnomeVFSURI *dir_uri, *data_uri, *backup_uri; - GnomeVFSResult data_result, backup_result; - - /* check type */ - if (!type_is_calendar (type) && !type_is_tasks (type)) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, - &ev); - - if (BONOBO_EX (&ev)) - g_message ("remove_folder(): Could not notify the listener of " - "an unsupported folder type"); - - CORBA_exception_free (&ev); - return; - } - - /* check URI */ - dir_uri = gnome_vfs_uri_new (physical_uri); - if (!dir_uri) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_INVALID_URI, - &ev); - CORBA_exception_free (&ev); - return; - } - - /* Compute the URIs of the appropriate files */ - - if (type_is_calendar (type)) { - data_uri = gnome_vfs_uri_append_file_name (dir_uri, "calendar.ics"); - backup_uri = gnome_vfs_uri_append_file_name (dir_uri, "calendar.ics~"); - } else if (type_is_tasks (type)) { - data_uri = gnome_vfs_uri_append_file_name (dir_uri, "tasks.ics"); - backup_uri = gnome_vfs_uri_append_file_name (dir_uri, "tasks.ics~"); - } else { - g_assert_not_reached (); - return; - } - - if (!data_uri || !backup_uri) { - CORBA_Environment ev; - - g_message ("remove_folder(): Could not generate the data/backup URIs"); - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_INVALID_URI, - &ev); - - if (BONOBO_EX (&ev)) - g_message ("remove_folder(): Could not notify the listener " - "of an invalid URI"); - - CORBA_exception_free (&ev); - - goto out; - } - - /* Ask the alarm daemon to stop monitoring this URI */ - - stop_alarms (data_uri); - - /* Delete the data and backup files; the shell will take care of the rest */ - - data_result = gnome_vfs_unlink_from_uri (data_uri); - backup_result = gnome_vfs_unlink_from_uri (backup_uri); - - if ((data_result == GNOME_VFS_OK || data_result == GNOME_VFS_ERROR_NOT_FOUND) - && (backup_result == GNOME_VFS_OK || backup_result == GNOME_VFS_ERROR_NOT_FOUND)) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_OK, - &ev); - - if (BONOBO_EX (&ev)) - g_message ("remove_folder(): Could not notify the listener about success"); - - CORBA_exception_free (&ev); - } else { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED, - &ev); - - if (BONOBO_EX (&ev)) - g_message ("remove_folder(): Could not notify the listener about failure"); - - CORBA_exception_free (&ev); - } - - out: - - gnome_vfs_uri_unref (dir_uri); - - if (data_uri) - gnome_vfs_uri_unref (data_uri); - - if (backup_uri) - gnome_vfs_uri_unref (backup_uri); -} - -static GNOME_Evolution_ShellComponentListener_Result -xfer_file (GnomeVFSURI *base_src_uri, - GnomeVFSURI *base_dest_uri, - const char *file_name, - int remove_source) -{ - GnomeVFSURI *src_uri, *dest_uri; - GnomeVFSHandle *hin, *hout; - GnomeVFSResult result; - GnomeVFSFileInfo file_info; - GnomeVFSFileSize size; - char *buffer; - - src_uri = gnome_vfs_uri_append_file_name (base_src_uri, file_name); - - result = gnome_vfs_open_uri (&hin, src_uri, GNOME_VFS_OPEN_READ); - if (result == GNOME_VFS_ERROR_NOT_FOUND) { - gnome_vfs_uri_unref (src_uri); - return GNOME_Evolution_ShellComponentListener_OK; /* No need to xfer anything. */ - } - if (result != GNOME_VFS_OK) { - gnome_vfs_uri_unref (src_uri); - return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; - } - - result = gnome_vfs_get_file_info_uri (src_uri, &file_info, GNOME_VFS_FILE_INFO_DEFAULT); - if (result != GNOME_VFS_OK) { - gnome_vfs_uri_unref (src_uri); - return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; - } - - dest_uri = gnome_vfs_uri_append_file_name (base_dest_uri, file_name); - - result = gnome_vfs_create_uri (&hout, dest_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0600); - if (result != GNOME_VFS_OK) { - gnome_vfs_close (hin); - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; - } - - /* write source file to destination file */ - buffer = g_malloc (file_info.size); - result = gnome_vfs_read (hin, buffer, file_info.size, &size); - if (result != GNOME_VFS_OK) { - gnome_vfs_close (hin); - gnome_vfs_close (hout); - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - g_free (buffer); - return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; - } - - result = gnome_vfs_write (hout, buffer, file_info.size, &size); - if (result != GNOME_VFS_OK) { - gnome_vfs_close (hin); - gnome_vfs_close (hout); - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - g_free (buffer); - return GNOME_Evolution_ShellComponentListener_PERMISSION_DENIED; - } - - if (remove_source) { - char *text_uri; - - /* Sigh, we have to do this as there is no gnome_vfs_unlink_uri(). :-( */ - - text_uri = gnome_vfs_uri_to_string (src_uri, GNOME_VFS_URI_HIDE_NONE); - result = gnome_vfs_unlink (text_uri); - g_free (text_uri); - } - - gnome_vfs_close (hin); - gnome_vfs_close (hout); - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - g_free (buffer); - - return GNOME_Evolution_ShellComponentListener_OK; -} - -static void -xfer_folder (EvolutionShellComponent *shell_component, - const char *source_physical_uri, - const char *destination_physical_uri, - const char *type, - gboolean remove_source, - const GNOME_Evolution_ShellComponentListener listener, - void *closure) -{ - CORBA_Environment ev; - GnomeVFSURI *src_uri; - GnomeVFSURI *dest_uri; - GnomeVFSResult result; - char *filename, *backup_filename; - - CORBA_exception_init (&ev); - - /* check type */ - if (!type_is_calendar (type) && !type_is_tasks (type)) { - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, - &ev); - CORBA_exception_free (&ev); - return; - } - - /* check URIs */ - src_uri = gnome_vfs_uri_new (source_physical_uri); - dest_uri = gnome_vfs_uri_new (destination_physical_uri); - if (!src_uri || ! dest_uri) { - GNOME_Evolution_ShellComponentListener_notifyResult ( - listener, - GNOME_Evolution_ShellComponentListener_INVALID_URI, - &ev); - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - CORBA_exception_free (&ev); - return; - } - - if (type_is_calendar (type)) { - filename = "calendar.ics"; - backup_filename = "calendar.ics~"; - } else if (type_is_tasks (type)) { - filename = "tasks.ics"; - backup_filename = "tasks.ics~"; - } else { - g_assert_not_reached (); - return; - } - - result = xfer_file (src_uri, dest_uri, filename, remove_source); - if (result == GNOME_Evolution_ShellComponentListener_OK) - result = xfer_file (src_uri, dest_uri, backup_filename, remove_source); - - GNOME_Evolution_ShellComponentListener_notifyResult (listener, result, &ev); - - gnome_vfs_uri_unref (src_uri); - gnome_vfs_uri_unref (dest_uri); - - CORBA_exception_free (&ev); -} - -static gboolean -request_quit (EvolutionShellComponent *shell_component, void *closure) -{ - return e_comp_editor_registry_close_all (comp_editor_registry); -} - -static void -owner_set_cb (EvolutionShellComponent *shell_component, - EvolutionShellClient *shell_client, - const char *evolution_homedir, - gpointer user_data) -{ - if (evolution_dir) - g_free (evolution_dir); - evolution_dir = g_strdup (evolution_homedir); - global_shell_client = shell_client; -} - -static void -owner_unset_cb (EvolutionShellComponent *shell_component, - gpointer user_data) -{ - global_shell_client = NULL; -} - -/* Computes the final URI for a calendar component */ -static char * -get_data_uri (const char *uri, CalComponentVType vtype) -{ - if (uri) { - if (*uri != '/' && strncmp (uri, "file:", 5) != 0) - return g_strdup (uri); - - if (vtype == CAL_COMPONENT_EVENT) - return cal_util_expand_uri ((char *) uri, FALSE); - else if (vtype == CAL_COMPONENT_TODO) - return cal_util_expand_uri ((char *) uri, TRUE); - else - g_assert_not_reached (); - } else { - if (vtype == CAL_COMPONENT_EVENT) - return g_concat_dir_and_file (g_get_home_dir (), - "evolution/local/Calendar/calendar.ics"); - else if (vtype == CAL_COMPONENT_TODO) - return g_concat_dir_and_file (g_get_home_dir (), - "evolution/local/Tasks/tasks.ics"); - else - g_assert_not_reached (); - } - - return NULL; -} - -/* Creates a calendar component at a specified URI. If the URI is NULL then it - * uses the default folder for that type of component. - */ -static void -create_component (const char *uri, GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type) -{ - char *real_uri; - CORBA_Environment ev; - GNOME_Evolution_Calendar_CompEditorFactory factory; - CalComponentVType vtype; - - switch (type) { - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT: - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_ALLDAY_EVENT: - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING: - vtype = CAL_COMPONENT_EVENT; - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO: - vtype = CAL_COMPONENT_TODO; - break; - default: - g_assert_not_reached (); - return; - } - - real_uri = get_data_uri (uri, vtype); - - /* Get the factory */ - - CORBA_exception_init (&ev); - factory = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_CompEditorFactory", - 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("create_component(): Could not activate the component editor factory"); - CORBA_exception_free (&ev); - g_free (real_uri); - return; - } - CORBA_exception_free (&ev); - - /* Create the item */ - - CORBA_exception_init (&ev); - GNOME_Evolution_Calendar_CompEditorFactory_editNew (factory, real_uri, type, &ev); - - if (BONOBO_EX (&ev)) - g_message ("create_component(): Exception while creating the component"); - - CORBA_exception_free (&ev); - g_free (real_uri); - - /* Get rid of the factory */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (factory, &ev); - if (BONOBO_EX (&ev)) - g_message ("create_component(): Could not unref the calendar component factory"); - - CORBA_exception_free (&ev); -} - -/* Callback used when we must create a user-creatable item */ -static void -sc_user_create_new_item_cb (EvolutionShellComponent *shell_component, - const char *id, - const char *parent_folder_physical_uri, - const char *parent_folder_type) -{ - char *tmp_uri; - - if (strcmp (id, CREATE_EVENT_ID) == 0) { - if (type_is_calendar (parent_folder_type)) - create_component (parent_folder_physical_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT); - else { - tmp_uri = calendar_config_default_calendar_folder (); - create_component (tmp_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT); - g_free (tmp_uri); - } - } else if (strcmp (id, CREATE_ALLDAY_EVENT_ID) == 0) { - if (type_is_calendar (parent_folder_type)) - create_component (parent_folder_physical_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_ALLDAY_EVENT); - else { - tmp_uri = calendar_config_default_calendar_folder (); - create_component (tmp_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_ALLDAY_EVENT); - g_free (tmp_uri); - } - } else if (strcmp (id, CREATE_MEETING_ID) == 0) { - if (type_is_calendar (parent_folder_type)) - create_component (parent_folder_physical_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING); - else { - tmp_uri = calendar_config_default_calendar_folder (); - create_component (tmp_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING); - g_free (tmp_uri); - } - } else if (strcmp (id, CREATE_TASK_ID) == 0) { - if (type_is_tasks (parent_folder_type)) - create_component (parent_folder_physical_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO); - else { - tmp_uri = calendar_config_default_tasks_folder (); - create_component (tmp_uri, - GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO); - g_free (tmp_uri); - } - } else - g_assert_not_reached (); -} - - -/* The factory function. */ - -static void -add_creatable_item (EvolutionShellComponent *shell_component, - const char *id, - const char *description, - const char *menu_description, - const char *tooltip, - const char *folder_type, - char menu_shortcut, - const char *icon_name) -{ - char *icon_path; - GdkPixbuf *icon; - - if (icon_name == NULL) { - icon_path = NULL; - icon = NULL; - } else { - icon_path = g_concat_dir_and_file (EVOLUTION_IMAGESDIR, icon_name); - icon = gdk_pixbuf_new_from_file (icon_path, NULL); - } - - evolution_shell_component_add_user_creatable_item (shell_component, - id, - description, - menu_description, - tooltip, - folder_type, - menu_shortcut, - icon); - - if (icon != NULL) - gdk_pixbuf_unref (icon); - g_free (icon_path); -} - -static BonoboObject * -create_object (void) -{ - EvolutionShellComponent *shell_component; - CalendarOfflineHandler *offline_handler; - - shell_component = evolution_shell_component_new (folder_types, - NULL, - create_view, - create_folder, - remove_folder, - xfer_folder, - NULL, /* populate_folder_context_menu_fn */ - NULL, /* unpopulate_folder_context_menu_fn */ - NULL, /* get_dnd_selection_fn */ - request_quit, - NULL /* closure */); - - /* Offline handler */ - offline_handler = calendar_offline_handler_new (); - bonobo_object_add_interface (BONOBO_OBJECT (shell_component), - BONOBO_OBJECT (offline_handler)); - - g_signal_connect (shell_component, "owner_set", G_CALLBACK (owner_set_cb), NULL); - g_signal_connect (shell_component, "owner_unset", G_CALLBACK (owner_unset_cb), NULL); - - /* User creatable items */ - - add_creatable_item (shell_component, CREATE_EVENT_ID, - _("New appointment"), _("_Appointment"), - _("Create a new appointment"), - FOLDER_CALENDAR, 'a', "new_appointment.xpm"); - - add_creatable_item (shell_component, CREATE_MEETING_ID, - _("New meeting"), _("M_eeting"), - _("Create a new meeting request"), - FOLDER_CALENDAR, 'e', "meeting-request-16.png"); - - add_creatable_item (shell_component, CREATE_TASK_ID, - _("New task"), _("_Task"), - _("Create a new task"), - FOLDER_TASKS, 't', "new_task-16.png"); - - add_creatable_item (shell_component, CREATE_ALLDAY_EVENT_ID, - _("New All Day Appointment"), _("All _Day Appointment"), - _("Create a new all-day appointment"), - FOLDER_CALENDAR, 'd', "new_all_day_event.png"); - - g_signal_connect (shell_component, "user_create_new_item", - G_CALLBACK (sc_user_create_new_item_cb), NULL); - - return BONOBO_OBJECT (shell_component); -} - - -BonoboObject * -calendar_component_get_object (void) -{ - static BonoboObject *object = NULL; - - if (object != NULL) { - bonobo_object_ref (BONOBO_OBJECT (object)); - } else { - object = create_object (); - g_object_add_weak_pointer (G_OBJECT (object), (void *) &object); - } - - return object; -} diff --git a/calendar/gui/calendar-component.h b/calendar/gui/calendar-component.h deleted file mode 100644 index 2d94920adc..0000000000 --- a/calendar/gui/calendar-component.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* component-factory.h - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _COMPONENT_FACTORY_H_ -#define _COMPONENT_FACTORY_H_ - -#include <bonobo/bonobo-object.h> - -extern char *evolution_dir; - -BonoboObject *calendar_component_get_object (void); - -#endif /* _COMPONENT_FACTORY_H_ */ diff --git a/calendar/gui/calendar-config.c b/calendar/gui/calendar-config.c deleted file mode 100644 index e191a6e8d8..0000000000 --- a/calendar/gui/calendar-config.c +++ /dev/null @@ -1,944 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 2000, Ximian, Inc. - * Copyright 2000, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * calendar-config.c - functions to load/save/get/set user settings. - */ - -#include <config.h> -#include <string.h> -#include <time.h> -#include <gtk/gtksignal.h> -#include <libgnome/gnome-config.h> -#include <libgnomeui/gnome-dialog.h> -#include <widgets/e-timezone-dialog/e-timezone-dialog.h> -#include <cal-util/timeutil.h> - -#include "calendar-component.h" -#include "calendar-commands.h" -#include "e-tasks.h" -#include "e-cell-date-edit-text.h" -#include "calendar-config.h" -#include "e-util/e-config-listener.h" - - -static EConfigListener *config = NULL; - -static void on_timezone_set (GnomeDialog *dialog, - int button, - ETimezoneDialog *etd); -static gboolean on_timezone_dialog_delete_event (GnomeDialog *dialog, - GdkEvent *event, - ETimezoneDialog *etd); - -static void -do_cleanup (void) -{ - g_object_unref (config); - config = NULL; -} - -void -calendar_config_init (void) -{ - if (config) - return; - - config = e_config_listener_new (); - g_atexit ((GVoidFunc) do_cleanup); -} - -/* Returns TRUE if the locale has 'am' and 'pm' strings defined, in which - case the user can choose between 12 and 24-hour time formats. */ -gboolean -calendar_config_locale_supports_12_hour_format (void) -{ - char s[16]; - time_t t = 0; - - strftime (s, sizeof s, "%p", gmtime (&t)); - return s[0] != '\0'; -} - -/* Returns the string representation of a units value */ -static const char * -units_to_string (CalUnits units) -{ - switch (units) { - case CAL_DAYS: - return "days"; - - case CAL_HOURS: - return "hours"; - - case CAL_MINUTES: - return "minutes"; - - default: - g_assert_not_reached (); - return NULL; - } -} - -/* - * Calendar Settings. - */ - -/* The current timezone, e.g. "Europe/London". It may be NULL, in which case - you should assume UTC (though Evolution will show the timezone-setting - dialog the next time a calendar or task folder is selected). */ -gchar* -calendar_config_get_timezone (void) -{ - static char *timezone = NULL; - - if (timezone) - g_free (timezone); - - timezone = e_config_listener_get_string_with_default (config, - "/apps/evolution/calendar/display/timezone", - "UTC", NULL); - if (!timezone) - timezone = g_strdup ("UTC"); - - return timezone; -} - - -/* Sets the timezone. If set to NULL it defaults to UTC. - FIXME: Should check it is being set to a valid timezone. */ -void -calendar_config_set_timezone (gchar *timezone) -{ - if (timezone && timezone[0]) - e_config_listener_set_string (config, "/apps/evolution/calendar/display/timezone", timezone); - else - e_config_listener_set_string (config, "/apps/evolution/calendar/display/timezone", "UTC"); -} - - -/* Whether we use 24-hour format or 12-hour format (AM/PM). */ -gboolean -calendar_config_get_24_hour_format (void) -{ - /* If the locale defines 'am' and 'pm' strings then the user has the - choice of 12-hour or 24-hour time format, with 12-hour as the - default. If the locale doesn't have 'am' and 'pm' strings we have - to use 24-hour format, or strftime()/strptime() won't work. */ - if (calendar_config_locale_supports_12_hour_format ()) { - return e_config_listener_get_boolean_with_default ( - config, "/apps/evolution/calendar/display/use_24hour_format", FALSE, NULL); - } - - return TRUE; -} - - -void -calendar_config_set_24_hour_format (gboolean use_24_hour) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/display/use_24hour_format", use_24_hour); -} - - -/* The start day of the week (0 = Sun to 6 = Mon). */ -gint -calendar_config_get_week_start_day (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/week_start_day", 1, NULL); -} - - -void -calendar_config_set_week_start_day (gint week_start_day) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/week_start_day", week_start_day); -} - - -/* The start and end times of the work-day. */ -gint -calendar_config_get_day_start_hour (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/day_start_hour", 9, NULL); -} - - -void -calendar_config_set_day_start_hour (gint day_start_hour) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/day_start_hour", day_start_hour); -} - - -gint -calendar_config_get_day_start_minute (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/day_start_minute", 0, NULL); -} - - -void -calendar_config_set_day_start_minute (gint day_start_min) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/day_start_minute", day_start_min); -} - - -gint -calendar_config_get_day_end_hour (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/day_end_hour", 17, NULL); -} - - -void -calendar_config_set_day_end_hour (gint day_end_hour) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/day_end_hour", day_end_hour); -} - - -gint -calendar_config_get_day_end_minute (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/day_end_minute", 0, NULL); -} - - -void -calendar_config_set_day_end_minute (gint day_end_min) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/day_end_minute", day_end_min); -} - - -/* The time divisions in the Day/Work-Week view in minutes (5/10/15/30/60). */ -gint -calendar_config_get_time_divisions (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/time_divisions", 30, NULL); -} - - -void -calendar_config_set_time_divisions (gint divisions) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/time_divisions", divisions); -} - - -/* Whether we show week numbers in the Date Navigator. */ -gboolean -calendar_config_get_dnav_show_week_no (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/date_navigator/show_week_numbers", FALSE, NULL); -} - - -void -calendar_config_set_dnav_show_week_no (gboolean show_week_no) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/date_navigator/show_week_numbers", show_week_no); -} - - -/* The view to show on start-up, 0 = Day, 1 = WorkWeek, 2 = Week, 3 = Month. */ -gint -calendar_config_get_default_view (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/default_view", 0, NULL); -} - - -void -calendar_config_set_default_view (gint view) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/default_view", view); -} - - -/* The positions of the panes in the normal and month views. */ -gint -calendar_config_get_hpane_pos (void) -{ - return e_config_listener_get_long_with_default (config, - "/apps/evolution/calendar/display/hpane_position", - -1, NULL); -} - - -void -calendar_config_set_hpane_pos (gint hpane_pos) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/hpane_position", hpane_pos); -} - - -gint -calendar_config_get_vpane_pos (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/vpane_position", -1, NULL); -} - - -void -calendar_config_set_vpane_pos (gint vpane_pos) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/vpane_position", vpane_pos); -} - - -gint -calendar_config_get_month_hpane_pos (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/month_hpane_position", -1, NULL); -} - - -void -calendar_config_set_month_hpane_pos (gint hpane_pos) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/month_hpane_position", hpane_pos); -} - - -gint -calendar_config_get_month_vpane_pos (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/display/month_vpane_position", 0, NULL); -} - - -void -calendar_config_set_month_vpane_pos (gint vpane_pos) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/month_vpane_position", vpane_pos); -} - - -/* Whether we compress the weekend in the week/month views. */ -gboolean -calendar_config_get_compress_weekend (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/display/compress_weekend", TRUE, NULL); -} - - -void -calendar_config_set_compress_weekend (gboolean compress) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/display/compress_weekend", compress); -} - - -/* Whether we show event end times. */ -gboolean -calendar_config_get_show_event_end (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/display/show_event_end", TRUE, NULL); -} - - -void -calendar_config_set_show_event_end (gboolean show_end) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/display/show_event_end", show_end); -} - - -/* The working days of the week, a bit-wise combination of flags. */ -CalWeekdays -calendar_config_get_working_days (void) -{ - return e_config_listener_get_long_with_default (config, - "/apps/evolution/calendar/display/working_days", CAL_MONDAY | CAL_TUESDAY | - CAL_WEDNESDAY | CAL_THURSDAY | CAL_FRIDAY, NULL); -} - - -void -calendar_config_set_working_days (CalWeekdays days) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/display/working_days", days); -} - - -/* Settings to hide completed tasks. */ -gboolean -calendar_config_get_hide_completed_tasks (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/tasks/hide_completed", FALSE, NULL); -} - - -void -calendar_config_set_hide_completed_tasks (gboolean hide) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/tasks/hide_completed", hide); -} - - -CalUnits -calendar_config_get_hide_completed_tasks_units (void) -{ - char *units; - CalUnits cu; - - units = e_config_listener_get_string_with_default (config, "/apps/evolution/calendar/tasks/hide_completed_units", "days", NULL); - - if (!strcmp (units, "minutes")) - cu = CAL_MINUTES; - else if (!strcmp (units, "hours")) - cu = CAL_HOURS; - else - cu = CAL_DAYS; - - g_free (units); - - return cu; -} - - -void -calendar_config_set_hide_completed_tasks_units (CalUnits cu) -{ - char *units; - - switch (cu) { - case CAL_MINUTES : - units = g_strdup ("minutes"); - break; - case CAL_HOURS : - units = g_strdup ("hours"); - break; - default : - units = g_strdup ("days"); - } - - e_config_listener_set_string (config, "/apps/evolution/calendar/tasks/hide_completed_sunits", units); - - g_free (units); -} - - -gint -calendar_config_get_hide_completed_tasks_value (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/tasks/hide_completed_value", 1, NULL); -} - - -void -calendar_config_set_hide_completed_tasks_value (gint value) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/tasks/hide_completed_value", value); -} - -/** - * calendar_config_get_confirm_delete: - * - * Queries the configuration value for whether a confirmation dialog is - * presented when deleting calendar/tasks items. - * - * Return value: Whether confirmation is required when deleting items. - **/ -gboolean -calendar_config_get_confirm_delete (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/prompts/confirm_delete", TRUE, NULL); -} - -/** - * calendar_config_set_confirm_delete: - * @confirm: Whether confirmation is required when deleting items. - * - * Sets the configuration value for whether a confirmation dialog is presented - * when deleting calendar/tasks items. - **/ -void -calendar_config_set_confirm_delete (gboolean confirm) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/prompts/confirm_delete", confirm); -} - -/** - * calendar_config_get_confirm_expunge: - * - * Queries the configuration value for whether a confirmation dialog is - * presented when expunging calendar/tasks items. - * - * Return value: Whether confirmation is required when expunging items. - **/ -gboolean -calendar_config_get_confirm_expunge (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/prompts/confirm_expunge", TRUE, NULL); -} - -/** - * calendar_config_set_confirm_expunge: - * @confirm: Whether confirmation is required when expunging items. - * - * Sets the configuration value for whether a confirmation dialog is presented - * when expunging calendar/tasks items. - **/ -void -calendar_config_set_confirm_expunge (gboolean confirm) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/prompts/confirm_expunge", confirm); -} - -/* This sets all the common config settings for an ECalendar widget. - These are the week start day, and whether we show week numbers. */ -void -calendar_config_configure_e_calendar (ECalendar *cal) -{ - gboolean dnav_show_week_no; - gint week_start_day; - - g_return_if_fail (E_IS_CALENDAR (cal)); - - dnav_show_week_no = calendar_config_get_dnav_show_week_no (); - - /* Note that this is 0 (Sun) to 6 (Sat). */ - week_start_day = calendar_config_get_week_start_day (); - - /* Convert it to 0 (Mon) to 6 (Sun), which is what we use. */ - week_start_day = (week_start_day + 6) % 7; - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "show_week_numbers", dnav_show_week_no, - "week_start_day", week_start_day, - NULL); -} - - -/* This sets all the common config settings for an EDateEdit widget. - These are the week start day, whether we show week numbers, and whether we - use 24 hour format. */ -void -calendar_config_configure_e_date_edit (EDateEdit *dedit) -{ - gboolean dnav_show_week_no, use_24_hour; - gint week_start_day; - - g_return_if_fail (E_IS_DATE_EDIT (dedit)); - - dnav_show_week_no = calendar_config_get_dnav_show_week_no (); - - /* Note that this is 0 (Sun) to 6 (Sat). */ - week_start_day = calendar_config_get_week_start_day (); - - /* Convert it to 0 (Mon) to 6 (Sun), which is what we use. */ - week_start_day = (week_start_day + 6) % 7; - - use_24_hour = calendar_config_get_24_hour_format (); - - e_date_edit_set_week_start_day (dedit, week_start_day); - e_date_edit_set_show_week_numbers (dedit, dnav_show_week_no); - e_date_edit_set_use_24_hour_format (dedit, use_24_hour); -} - - -/* This sets all the common config settings for an ECellDateEdit ETable item. - These are the settings for the ECalendar popup and the time list (if we use - 24 hour format, and the hours of the working day). */ -void -calendar_config_configure_e_cell_date_edit (ECellDateEdit *ecde) -{ - gboolean use_24_hour; - gint start_hour, end_hour; - ECellPopup *ecp; - ECellDateEditText *ecd; - char *location; - icaltimezone *zone; - - g_return_if_fail (E_IS_CELL_DATE_EDIT (ecde)); - - ecp = E_CELL_POPUP (ecde); - ecd = E_CELL_DATE_EDIT_TEXT (ecp->child); - - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - calendar_config_configure_e_calendar (E_CALENDAR (ecde->calendar)); - - use_24_hour = calendar_config_get_24_hour_format (); - - start_hour = calendar_config_get_day_start_hour (); - end_hour = calendar_config_get_day_end_hour (); - - /* Round up the end hour. */ - if (calendar_config_get_day_end_minute () != 0) - end_hour++; - - e_cell_date_edit_freeze (ecde); - g_object_set (G_OBJECT (ecde), - "use_24_hour_format", use_24_hour, -#if 0 - /* We use the default 0 - 24 now. */ - "lower_hour", start_hour, - "upper_hour", end_hour, -#endif - NULL); - e_cell_date_edit_thaw (ecde); - - e_cell_date_edit_text_set_timezone (ecd, zone); - e_cell_date_edit_text_set_use_24_hour_format (ecd, use_24_hour); -} - - -/* This sets all the common config settings for an ECalendarTable widget. - These are the settings for the ECalendar popup and the time list (if we use - 24 hour format, and the hours of the working day). */ -void -calendar_config_configure_e_calendar_table (ECalendarTable *cal_table) -{ - CalendarModel *model; - gboolean use_24_hour; - char *location; - icaltimezone *zone; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - use_24_hour = calendar_config_get_24_hour_format (); - - model = e_calendar_table_get_model (cal_table); - calendar_model_set_use_24_hour_format (model, use_24_hour); - - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - calendar_model_set_timezone (model, zone); - - calendar_config_configure_e_cell_date_edit (cal_table->dates_cell); - - /* Reload the event/tasks, since the 'Hide Completed Tasks' option - may have been changed, so the query needs to be updated. */ - calendar_model_refresh (model); -} - - - -void -calendar_config_check_timezone_set () -{ - ETimezoneDialog *timezone_dialog; - GtkWidget *dialog; - GList *elem; - char *zone; - - zone = calendar_config_get_timezone (); - if (zone && zone[0]) - return; - - /* Show timezone dialog. */ - timezone_dialog = e_timezone_dialog_new (); - dialog = e_timezone_dialog_get_toplevel (timezone_dialog); - - /* Hide the cancel button, which is the 2nd button. */ - elem = g_list_nth (GNOME_DIALOG (dialog)->buttons, 1); - gtk_widget_hide (elem->data); - - g_signal_connect (dialog, "clicked", - G_CALLBACK (on_timezone_set), timezone_dialog); - g_signal_connect (dialog, "delete-event", - G_CALLBACK (on_timezone_dialog_delete_event), timezone_dialog); - - gtk_widget_show (dialog); -} - - -static void -on_timezone_set (GnomeDialog *dialog, - int button, - ETimezoneDialog *etd) -{ - icaltimezone *zone; - - zone = e_timezone_dialog_get_timezone (etd); - if (zone) { - calendar_config_set_timezone (icaltimezone_get_location (zone)); - - update_all_config_settings (); - e_tasks_update_all_config_settings (); - } - - g_object_unref (etd); -} - - -static gboolean -on_timezone_dialog_delete_event (GnomeDialog *dialog, - GdkEvent *event, - ETimezoneDialog *etd) -{ - g_object_unref (etd); - return TRUE; -} - - -/** - * calendar_config_get_tasks_due_today_color: - * - * Queries the color to be used to display tasks that are due today. - * - * Return value: An X color specification. - **/ -const char * -calendar_config_get_tasks_due_today_color (void) -{ - static char *color = NULL; - - if (color) - g_free (color); - - color = e_config_listener_get_string_with_default (config, "/apps/evolution/calendar/tasks/colors/due_today", "blue", NULL); - return color; -} - -/** - * calendar_config_set_tasks_due_today_color: - * @color: X color specification - * - * Sets the color to be used to display tasks that are due today. - **/ -void -calendar_config_set_tasks_due_today_color (const char *color) -{ - g_return_if_fail (color != NULL); - - e_config_listener_set_string (config, "/apps/evolution/calendar/tasks/colors/due_today", color); -} - -/** - * calendar_config_get_tasks_overdue_color: - * - * Queries the color to be used to display overdue tasks. - * - * Return value: An X color specification. - **/ -const char * -calendar_config_get_tasks_overdue_color (void) -{ - static char *color = NULL; - - if (color) - g_free (color); - - color = e_config_listener_get_string_with_default (config, "/apps/evolution/calendar/tasks/colors/overdue", "red", NULL); - return color; -} - -/** - * calendar_config_set_tasks_overdue_color: - * @color: X color specification - * - * Sets the color to be used to display overdue tasks. - **/ -void -calendar_config_set_tasks_overdue_color (const char *color) -{ - g_return_if_fail (color != NULL); - - e_config_listener_set_string (config, "/apps/evolution/calendar/tasks/colors/overdue", color); -} - -/** - * calendar_config_get_use_default_reminder: - * - * Queries whether new appointments should be created with a default reminder. - * - * Return value: Boolean value indicating whether new appointments should be - * created with a default reminder from the values of - * calendar_config_get_default_reminder_interval() and - * calendar_config_get_default_reminder_units(). - **/ -gboolean -calendar_config_get_use_default_reminder (void) -{ - return e_config_listener_get_boolean_with_default (config, "/apps/evolution/calendar/other/use_default_reminder", FALSE, NULL); -} - -/** - * calendar_config_set_use_default_reminder: - * @value: Whether to create new appointments with a default reminder. - * - * Sets whether newly-created appointments should get a default reminder set - * them. - **/ -void -calendar_config_set_use_default_reminder (gboolean value) -{ - e_config_listener_set_boolean (config, "/apps/evolution/calendar/other/use_default_reminder", value); -} - -/** - * calendar_config_get_default_reminder_interval: - * - * Queries the interval for the default reminder of newly-created - * appointments, i.e. 5 in "5 minutes". - * - * Return value: Interval for default reminders. - **/ -int -calendar_config_get_default_reminder_interval (void) -{ - return e_config_listener_get_long_with_default (config, "/apps/evolution/calendar/other/default_reminder_interval", 15, NULL); -} - -/** - * calendar_config_set_default_reminder_interval: - * @interval: Interval value, e.g. 5 for "5 minutes". - * - * Sets the interval that should be used for the default reminder in new - * appointments. - **/ -void -calendar_config_set_default_reminder_interval (int interval) -{ - e_config_listener_set_long (config, "/apps/evolution/calendar/other/default_reminder_interval", interval); -} - -/** - * calendar_config_get_default_reminder_units: - * - * Queries the units of time in which default reminders should be created for - * new appointments, e.g. CAL_MINUTES for "5 minutes". - * - * Return value: Time units for default reminders. - **/ -CalUnits -calendar_config_get_default_reminder_units (void) -{ - char *units; - CalUnits cu; - - units = e_config_listener_get_string_with_default (config, "/apps/evolution/calendar/other/default_reminder_units", "minutes", NULL); - - if (!strcmp (units, "days")) - cu = CAL_DAYS; - else if (!strcmp (units, "hours")) - cu = CAL_HOURS; - else - cu = CAL_MINUTES; /* changed from above because - * if bonobo-config fucks up - * we want minutes, not days! - */ - g_free (units); - - return cu; -} - -/** - * calendar_config_set_default_reminder_units: - * @units: Time units, e.g. CAL_MINUTES for "5 minutes". - * - * Sets the units to be used for default reminders in new appointments. - **/ -void -calendar_config_set_default_reminder_units (CalUnits units) -{ - e_config_listener_set_string (config, "/apps/evolution/calendar/other/default_reminder_units", units_to_string(units)); -} - -/** - * calendar_config_get_hide_completed_tasks_sexp: - * - * Returns the subexpression to use to filter out completed tasks according - * to the config settings. The returned sexp should be freed. - **/ -char* -calendar_config_get_hide_completed_tasks_sexp (void) -{ - char *sexp = NULL; - - if (calendar_config_get_hide_completed_tasks ()) { - CalUnits units; - gint value; - - units = calendar_config_get_hide_completed_tasks_units (); - value = calendar_config_get_hide_completed_tasks_value (); - - if (value == 0) { - /* If the value is 0, we want to hide completed tasks - immediately, so we filter out all completed tasks.*/ - sexp = g_strdup ("(not is-completed?)"); - } else { - char *location, *isodate; - icaltimezone *zone; - struct icaltimetype tt; - time_t t; - - /* Get the current time, and subtract the appropriate - number of days/hours/minutes. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - tt = icaltime_current_time_with_zone (zone); - - switch (units) { - case CAL_DAYS: - icaltime_adjust (&tt, -value, 0, 0, 0); - break; - case CAL_HOURS: - icaltime_adjust (&tt, 0, -value, 0, 0); - break; - case CAL_MINUTES: - icaltime_adjust (&tt, 0, 0, -value, 0); - break; - default: - g_assert_not_reached (); - } - - t = icaltime_as_timet_with_zone (tt, zone); - - /* Convert the time to an ISO date string, and build - the query sub-expression. */ - isodate = isodate_from_time_t (t); - sexp = g_strdup_printf ("(not (completed-before? (make-time \"%s\")))", isodate); - } - } - - return sexp; -} - -char * -calendar_config_default_calendar_folder (void) -{ - char *uri; - - uri = e_config_listener_get_string_with_default (config, "/apps/evolution/shell/default_folders/calendar_uri", NULL, NULL); - return uri; -} - -char * -calendar_config_default_tasks_folder (void) -{ - char *uri; - - uri = e_config_listener_get_string_with_default (config, "/apps/evolution/shell/default_folders/tasks_uri", NULL, NULL); - return uri; -} - diff --git a/calendar/gui/calendar-config.h b/calendar/gui/calendar-config.h deleted file mode 100644 index 351f58469d..0000000000 --- a/calendar/gui/calendar-config.h +++ /dev/null @@ -1,187 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 2000, Ximian, Inc. - * Copyright 2000, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * calendar-config.h - functions to load/save/get/set user settings. - */ - -#ifndef _CALENDAR_CONFIG_H_ -#define _CALENDAR_CONFIG_H_ - -#include <widgets/misc/e-calendar.h> -#include <widgets/misc/e-dateedit.h> -#include <widgets/misc/e-cell-date-edit.h> -#include "e-calendar-table.h" - - -/* These are used to get/set the working days in the week. The bit-flags are - combined together. The bits must be from 0 (Sun) to 6 (Sat) to match the - day values used by localtime etc. */ -typedef enum -{ - CAL_SUNDAY = 1 << 0, - CAL_MONDAY = 1 << 1, - CAL_TUESDAY = 1 << 2, - CAL_WEDNESDAY = 1 << 3, - CAL_THURSDAY = 1 << 4, - CAL_FRIDAY = 1 << 5, - CAL_SATURDAY = 1 << 6 -} CalWeekdays; - - -/* Units for settings. */ -typedef enum -{ - CAL_DAYS, - CAL_HOURS, - CAL_MINUTES -} CalUnits; - - -void calendar_config_init (void); - - -/* - * Calendar Settings. - */ - -/* The current timezone, e.g. "Europe/London". */ -gchar* calendar_config_get_timezone (void); -void calendar_config_set_timezone (gchar *timezone); - -/* The working days of the week, a bit-wise combination of flags. */ -CalWeekdays calendar_config_get_working_days (void); -void calendar_config_set_working_days (CalWeekdays days); - -/* The start day of the week (0 = Sun to 6 = Sat). */ -gint calendar_config_get_week_start_day (void); -void calendar_config_set_week_start_day (gint week_start_day); - -/* The start and end times of the work-day. */ -gint calendar_config_get_day_start_hour (void); -void calendar_config_set_day_start_hour (gint day_start_hour); - -gint calendar_config_get_day_start_minute (void); -void calendar_config_set_day_start_minute (gint day_start_min); - -gint calendar_config_get_day_end_hour (void); -void calendar_config_set_day_end_hour (gint day_end_hour); - -gint calendar_config_get_day_end_minute (void); -void calendar_config_set_day_end_minute (gint day_end_min); - -/* Whether we use 24-hour format or 12-hour format (AM/PM). */ -gboolean calendar_config_get_24_hour_format (void); -void calendar_config_set_24_hour_format (gboolean use_24_hour); - -/* The time divisions in the Day/Work-Week view in minutes (5/10/15/30/60). */ -gint calendar_config_get_time_divisions (void); -void calendar_config_set_time_divisions (gint divisions); - -/* Whether we show event end times. */ -gboolean calendar_config_get_show_event_end (void); -void calendar_config_set_show_event_end (gboolean show_end); - -/* Whether we compress the weekend in the week/month views. */ -gboolean calendar_config_get_compress_weekend (void); -void calendar_config_set_compress_weekend (gboolean compress); - -/* Whether we show week numbers in the Date Navigator. */ -gboolean calendar_config_get_dnav_show_week_no (void); -void calendar_config_set_dnav_show_week_no (gboolean show_week_no); - -/* The view to show on start-up, 0 = Day, 1 = WorkWeek, 2 = Week, 3 = Month. */ -gint calendar_config_get_default_view (void); -void calendar_config_set_default_view (gint view); - -/* The positions of the panes in the normal and month views. */ -gint calendar_config_get_hpane_pos (void); -void calendar_config_set_hpane_pos (gint hpane_pos); - -gint calendar_config_get_vpane_pos (void); -void calendar_config_set_vpane_pos (gint vpane_pos); - -gint calendar_config_get_month_hpane_pos (void); -void calendar_config_set_month_hpane_pos (gint hpane_pos); - -gint calendar_config_get_month_vpane_pos (void); -void calendar_config_set_month_vpane_pos (gint vpane_pos); - -/* Colors for the task list */ -const char *calendar_config_get_tasks_due_today_color (void); -void calendar_config_set_tasks_due_today_color (const char *color); - -const char *calendar_config_get_tasks_overdue_color (void); -void calendar_config_set_tasks_overdue_color (const char *color); - -/* Settings to hide completed tasks. */ -gboolean calendar_config_get_hide_completed_tasks (void); -void calendar_config_set_hide_completed_tasks (gboolean hide); - -CalUnits calendar_config_get_hide_completed_tasks_units(void); -void calendar_config_set_hide_completed_tasks_units(CalUnits units); - -gint calendar_config_get_hide_completed_tasks_value(void); -void calendar_config_set_hide_completed_tasks_value(gint value); - -char* calendar_config_get_hide_completed_tasks_sexp (void); - -/* Confirmation options */ -gboolean calendar_config_get_confirm_delete (void); -void calendar_config_set_confirm_delete (gboolean confirm); - -gboolean calendar_config_get_confirm_expunge (void); -void calendar_config_set_confirm_expunge (gboolean confirm); - -/* Default reminder options */ -gboolean calendar_config_get_use_default_reminder (void); -void calendar_config_set_use_default_reminder (gboolean value); - -int calendar_config_get_default_reminder_interval (void); -void calendar_config_set_default_reminder_interval (int interval); - -CalUnits calendar_config_get_default_reminder_units (void); -void calendar_config_set_default_reminder_units (CalUnits units); - - -/* Convenience functions to configure common properties of ECalendar, - EDateEdit & ECalendarTable widgets, and the ECellDateEdit ETable cell. */ -void calendar_config_configure_e_calendar (ECalendar *cal); -void calendar_config_configure_e_date_edit (EDateEdit *dedit); -void calendar_config_configure_e_calendar_table (ECalendarTable *cal_table); -void calendar_config_configure_e_cell_date_edit (ECellDateEdit *ecde); - -/* Shows the timezone dialog if the user hasn't set a default timezone. */ -void calendar_config_check_timezone_set (void); - -/* Returns TRUE if the locale has 'am' and 'pm' strings defined, i.e. it - supports 12-hour time format. */ -gboolean calendar_config_locale_supports_12_hour_format(void); - -/* Default folders, read-only */ -char *calendar_config_default_calendar_folder (void); -char *calendar_config_default_tasks_folder (void); - -#endif /* _CALENDAR_CONFIG_H_ */ diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c deleted file mode 100644 index 9ee184cee6..0000000000 --- a/calendar/gui/calendar-model.c +++ /dev/null @@ -1,2462 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* Evolution calendar - Data model for ETable - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <math.h> -#include <sys/types.h> - -#include <ctype.h> - -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnome/gnome-i18n.h> -#include <gal/widgets/e-unicode.h> -#include <e-util/e-time-utils.h> -#include <cal-util/timeutil.h> -#include "calendar-commands.h" -#include "calendar-config.h" -#include "comp-util.h" -#include "itip-utils.h" -#include "calendar-model.h" -#include "evolution-activity-client.h" -#include "e-cell-date-edit-text.h" -#include "misc.h" - -/* This specifies how often we refresh the list, so that completed tasks are - hidden according to the config setting, and overdue tasks change color etc. - It is in milliseconds, so this is 10 minutes. - Note that if the user is editing an item in the list, they will probably - lose their edit, so this isn't ideal. */ -#define CALENDAR_MODEL_REFRESH_TIMEOUT 1000 * 60 * 10 - -/* These hold the date values of the objects, so we can free the values when - we no longer need them. */ -typedef struct _CalendarModelObjectData CalendarModelObjectData; -struct _CalendarModelObjectData { - ECellDateEditValue *dtstart; - ECellDateEditValue *dtend; - ECellDateEditValue *due; - ECellDateEditValue *completed; -}; - -/* We use a pointer to this value to indicate that the property is not set. */ -static ECellDateEditValue unset_date_edit_value; - -/* Private part of the ECalendarModel structure */ -struct _CalendarModelPrivate { - /* Calendar client we are using */ - CalClient *client; - - /* Types of objects we are dealing with */ - CalObjType type; - - /* S-expression for query and the query object */ - char *sexp; - CalQuery *query; - - /* Array of pointers to calendar objects */ - GArray *objects; - - /* Array of CalendarModelObjectData* holding data for each of the - objects in the objects array above. */ - GArray *objects_data; - - /* UID -> array index hash */ - GHashTable *uid_index_hash; - - /* Type of components to create when using click-to-add in the table */ - CalComponentVType new_comp_vtype; - - /* Whether we display dates in 24-hour format. */ - gboolean use_24_hour_format; - - /* The default category to use when creating new tasks, e.g. when the - filter is set to a certain category we use that category when - creating a new task. */ - gchar *default_category; - - /* Addresses for determining icons */ - EAccountList *accounts; - - /* The current timezone. */ - icaltimezone *zone; - - /* The id of our timeout function for refreshing the list. */ - gint timeout_id; - - /* The activity client used to show messages on the status bar. */ - EvolutionActivityClient *activity; -}; - - - -static void calendar_model_class_init (CalendarModelClass *class); -static void calendar_model_init (CalendarModel *model); -static void calendar_model_finalize (GObject *object); - -static int calendar_model_column_count (ETableModel *etm); -static int calendar_model_row_count (ETableModel *etm); -static void *calendar_model_value_at (ETableModel *etm, int col, int row); -static void calendar_model_set_value_at (ETableModel *etm, int col, int row, const void *value); -static gboolean calendar_model_is_cell_editable (ETableModel *etm, int col, int row); -static void calendar_model_append_row (ETableModel *etm, ETableModel *source, gint row); -static void *calendar_model_duplicate_value (ETableModel *etm, int col, const void *value); -static void calendar_model_free_value (ETableModel *etm, int col, void *value); -static void *calendar_model_initialize_value (ETableModel *etm, int col); -static gboolean calendar_model_value_is_empty (ETableModel *etm, int col, const void *value); -static char * calendar_model_value_to_string (ETableModel *etm, int col, const void *value); -static int remove_object (CalendarModel *model, const char *uid); -static void ensure_task_complete (CalComponent *comp, - time_t completed_date); -static void ensure_task_not_complete (CalComponent *comp); - -static ETableModelClass *parent_class; - - - -/** - * calendar_model_get_type: - * @void: - * - * Registers the #CalendarModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #CalendarModel class. - **/ - -E_MAKE_TYPE (calendar_model, "CalendarModel", CalendarModel, calendar_model_class_init, - calendar_model_init, E_TABLE_MODEL_TYPE); - -/* Class initialization function for the calendar table model */ -static void -calendar_model_class_init (CalendarModelClass *class) -{ - GObjectClass *object_class; - ETableModelClass *etm_class; - - object_class = (GObjectClass *) class; - etm_class = (ETableModelClass *) class; - - parent_class = g_type_class_peek_parent (class); - - object_class->finalize = calendar_model_finalize; - - etm_class->column_count = calendar_model_column_count; - etm_class->row_count = calendar_model_row_count; - etm_class->value_at = calendar_model_value_at; - etm_class->set_value_at = calendar_model_set_value_at; - etm_class->is_cell_editable = calendar_model_is_cell_editable; - etm_class->append_row = calendar_model_append_row; - etm_class->duplicate_value = calendar_model_duplicate_value; - etm_class->free_value = calendar_model_free_value; - etm_class->initialize_value = calendar_model_initialize_value; - etm_class->value_is_empty = calendar_model_value_is_empty; - etm_class->value_to_string = calendar_model_value_to_string; -} - - -static gboolean -calendar_model_timeout_cb (gpointer data) -{ - CalendarModel *model; - - g_return_val_if_fail (IS_CALENDAR_MODEL (data), FALSE); - - model = CALENDAR_MODEL (data); - - GDK_THREADS_ENTER (); - - calendar_model_refresh (model); - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -/* Object initialization function for the calendar table model */ -static void -calendar_model_init (CalendarModel *model) -{ - CalendarModelPrivate *priv; - - priv = g_new0 (CalendarModelPrivate, 1); - model->priv = priv; - - priv->sexp = g_strdup ("#t"); /* match all by default */ - priv->query = NULL; - - priv->objects = g_array_new (FALSE, TRUE, sizeof (CalComponent *)); - priv->objects_data = g_array_new (FALSE, FALSE, sizeof (CalendarModelObjectData)); - priv->uid_index_hash = g_hash_table_new (g_str_hash, g_str_equal); - priv->new_comp_vtype = CAL_COMPONENT_EVENT; - priv->use_24_hour_format = TRUE; - - priv->timeout_id = g_timeout_add (CALENDAR_MODEL_REFRESH_TIMEOUT, - calendar_model_timeout_cb, model); - - priv->accounts = itip_addresses_get (); - - priv->zone = NULL; - - priv->activity = NULL; - - /* Preload here, to avoid corba calls later */ - /* Gross hack because gnome-canvas is not re-entrant */ - calendar_config_get_tasks_due_today_color (); - calendar_config_get_tasks_overdue_color (); - g_free (calendar_config_get_hide_completed_tasks_sexp ()); -} - -static void -calendar_model_free_object_data (CalendarModel *model, - CalendarModelObjectData *object_data) -{ - if (object_data->dtstart != &unset_date_edit_value) - g_free (object_data->dtstart); - - if (object_data->dtend != &unset_date_edit_value) - g_free (object_data->dtend); - - if (object_data->due != &unset_date_edit_value) - g_free (object_data->due); - - if (object_data->completed != &unset_date_edit_value) - g_free (object_data->completed); -} - -/* Called from g_hash_table_foreach_remove(), frees a stored UID->index - * mapping. - */ -static gboolean -free_uid_index (gpointer key, gpointer value, gpointer data) -{ - int *idx; - - idx = value; - g_free (idx); - - return TRUE; -} - -/* Frees the objects stored in the calendar model */ -static void -free_objects (CalendarModel *model) -{ - CalendarModelPrivate *priv; - int i; - - priv = model->priv; - - g_hash_table_foreach_remove (priv->uid_index_hash, free_uid_index, NULL); - - for (i = 0; i < priv->objects->len; i++) { - CalComponent *comp; - CalendarModelObjectData *object_data; - - comp = g_array_index (priv->objects, CalComponent *, i); - g_assert (comp != NULL); - g_object_unref (comp); - - object_data = &g_array_index (priv->objects_data, - CalendarModelObjectData, i); - calendar_model_free_object_data (model, object_data); - } - - g_array_set_size (priv->objects, 0); - g_array_set_size (priv->objects_data, 0); -} - -/* Destroy handler for the calendar table model */ -static void -calendar_model_finalize (GObject *object) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (object)); - - model = CALENDAR_MODEL (object); - priv = model->priv; - - if (priv->timeout_id) { - g_source_remove (priv->timeout_id); - priv->timeout_id = 0; - } - - /* Free the calendar client interface object */ - - if (priv->client) { - g_signal_handlers_disconnect_matched (priv->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model); - g_object_unref (priv->client); - priv->client = NULL; - } - - if (priv->sexp) { - g_free (priv->sexp); - priv->sexp = NULL; - } - - if (priv->query) { - g_signal_handlers_disconnect_matched (priv->query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, model); - g_object_unref (priv->query); - priv->query = NULL; - } - - /* Free the uid->index hash data and the array of UIDs */ - - free_objects (model); - - g_hash_table_destroy (priv->uid_index_hash); - priv->uid_index_hash = NULL; - - g_array_free (priv->objects, TRUE); - priv->objects = NULL; - - g_array_free (priv->objects_data, TRUE); - priv->objects_data = NULL; - - g_free (priv->default_category); - - if (priv->activity) { - g_object_unref (priv->activity); - priv->activity = NULL; - } - - /* Free the private structure */ - - g_free (priv); - model->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* ETableModel methods */ - -/* column_count handler for the calendar table model */ -static int -calendar_model_column_count (ETableModel *etm) -{ - return CAL_COMPONENT_FIELD_NUM_FIELDS; -} - -/* row_count handler for the calendar table model */ -static int -calendar_model_row_count (ETableModel *etm) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - return priv->objects->len; -} - -/* Builds a string based on the list of CATEGORIES properties of a calendar - * component. - */ -static char * -get_categories (CalComponent *comp) -{ - const char *categories; - - cal_component_get_categories (comp, &categories); - - return categories ? (char*) categories : ""; -} - -/* Returns a string based on the CLASSIFICATION property of a calendar component */ -static char * -get_classification (CalComponent *comp) -{ - CalComponentClassification classif; - - cal_component_get_classification (comp, &classif); - - switch (classif) { - case CAL_COMPONENT_CLASS_PRIVATE: - return _("Private"); - - case CAL_COMPONENT_CLASS_CONFIDENTIAL: - return _("Confidential"); - - default: - return _("Public"); - } -} - -/* Returns an ECellDateEditValue* for a COMPLETED property of a - calendar component. Note that we cache these in the objects_data array so - we can free them eventually. */ -static ECellDateEditValue* -get_completed (CalendarModel *model, - CalComponent *comp, - int row) -{ - CalendarModelPrivate *priv; - CalendarModelObjectData *object_data; - struct icaltimetype *completed; - - priv = model->priv; - - object_data = &g_array_index (priv->objects_data, - CalendarModelObjectData, row); - - if (!object_data->completed) { - cal_component_get_completed (comp, &completed); - - if (completed) { - object_data->completed = g_new (ECellDateEditValue, 1); - object_data->completed->tt = *completed; - object_data->completed->zone = icaltimezone_get_utc_timezone (); - cal_component_free_icaltimetype (completed); - } else { - object_data->completed = &unset_date_edit_value; - } - } - - return (object_data->completed == &unset_date_edit_value) - ? NULL : object_data->completed; -} - -/* Returns an ECellDateEditValue* for a DTSTART, DTEND or DUE property of a - calendar component. Note that we cache these in the objects_data array so - we can free them eventually. */ -static ECellDateEditValue* -get_date_edit_value (CalendarModel *model, CalComponent *comp, - int col, int row) -{ - CalendarModelPrivate *priv; - CalComponentDateTime dt; - CalendarModelObjectData *object_data; - ECellDateEditValue **value; - - priv = model->priv; - - object_data = &g_array_index (priv->objects_data, - CalendarModelObjectData, row); - - if (col == CAL_COMPONENT_FIELD_DTSTART) - value = &object_data->dtstart; - else if (col == CAL_COMPONENT_FIELD_DTEND) - value = &object_data->dtend; - else - value = &object_data->due; - - if (!(*value)) { - if (col == CAL_COMPONENT_FIELD_DTSTART) - cal_component_get_dtstart (comp, &dt); - else if (col == CAL_COMPONENT_FIELD_DTEND) - cal_component_get_dtend (comp, &dt); - else - cal_component_get_due (comp, &dt); - - if (dt.value) { - CalClientGetStatus status; - icaltimezone *zone; - - /* For a DTEND with a DATE value, we subtract 1 from - the day to display it. */ - if (col == CAL_COMPONENT_FIELD_DTEND - && dt.value->is_date) { - icaltime_adjust (dt.value, -1, 0, 0, 0); - } - - *value = g_new (ECellDateEditValue, 1); - (*value)->tt = *dt.value; - - /* FIXME: TIMEZONES: Handle error. */ - status = cal_client_get_timezone (model->priv->client, - dt.tzid, &zone); - (*value)->zone = zone; - } else { - *value = &unset_date_edit_value; - } - - cal_component_free_datetime (&dt); - } - - return (*value == &unset_date_edit_value) ? NULL : *value; -} - -/* Builds a string for the GEO property of a calendar component */ -static char* -get_geo (CalComponent *comp) -{ - struct icalgeotype *geo; - static gchar buf[32]; - - cal_component_get_geo (comp, &geo); - - if (!geo) - buf[0] = '\0'; - else { - g_snprintf (buf, sizeof (buf), "%g %s, %g %s", - fabs (geo->lat), - geo->lat >= 0.0 ? _("N") : _("S"), - fabs (geo->lon), - geo->lon >= 0.0 ? _("E") : _("W")); - cal_component_free_geo (geo); - } - - return buf; -} - -/* Builds a string for the PERCENT property of a calendar component */ -static int -get_percent (CalComponent *comp) -{ - int *percent, retval; - - cal_component_get_percent (comp, &percent); - - if (percent) { - retval = *percent; - cal_component_free_percent (percent); - } else { - retval = -1; - } - - return retval; -} - -/* Builds a string for the PRIORITY property of a calendar component */ -static char * -get_priority (CalComponent *comp) -{ - int *priority; - char *retval = ""; - - cal_component_get_priority (comp, &priority); - - if (priority) { - retval = cal_util_priority_to_string (*priority); - cal_component_free_priority (priority); - } - - return retval; -} - -/* Builds a string for the SUMMARY property of a calendar component */ -static char * -get_summary (CalComponent *comp) -{ - CalComponentText summary; - - cal_component_get_summary (comp, &summary); - - if (summary.value) - return (char *) summary.value; - else - return ""; -} - -/* Builds a string for the TRANSPARENCY property of a calendar component */ -static char * -get_transparency (CalComponent *comp) -{ - CalComponentTransparency transp; - - cal_component_get_transparency (comp, &transp); - - if (transp == CAL_COMPONENT_TRANSP_TRANSPARENT) - return _("Free"); - else - return _("Busy"); -} - -/* Builds a string for the URL property of a calendar component */ -static char * -get_url (CalComponent *comp) -{ - const char *url; - - cal_component_get_url (comp, &url); - - if (url) - return (char *) url; - else - return ""; -} - -/* Returns whether the completion date has been set on a component */ -static gboolean -is_complete (CalComponent *comp) -{ - struct icaltimetype *t; - gboolean retval; - - cal_component_get_completed (comp, &t); - retval = (t != NULL); - - if (retval) - cal_component_free_icaltimetype (t); - - return retval; -} - -typedef enum { - CALENDAR_MODEL_DUE_NEVER, - CALENDAR_MODEL_DUE_FUTURE, - CALENDAR_MODEL_DUE_TODAY, - CALENDAR_MODEL_DUE_OVERDUE, - CALENDAR_MODEL_DUE_COMPLETE -} CalendarModelDueStatus; - - -static CalendarModelDueStatus -get_due_status (CalendarModel *model, CalComponent *comp) -{ - CalendarModelPrivate *priv; - CalComponentDateTime dt; - CalendarModelDueStatus retval; - - priv = model->priv; - - cal_component_get_due (comp, &dt); - - /* First, do we have a due date? */ - - if (!dt.value) - retval = CALENDAR_MODEL_DUE_NEVER; - else { - struct icaltimetype now_tt; - CalClientGetStatus status; - icaltimezone *zone; - - /* Second, is it already completed? */ - - if (is_complete (comp)) { - retval = CALENDAR_MODEL_DUE_COMPLETE; - goto out; - } - - /* Third, are we overdue as of right now? */ - - if (dt.value->is_date) { - int cmp; - - now_tt = icaltime_current_time_with_zone (priv->zone); - cmp = icaltime_compare_date_only (*dt.value, now_tt); - - if (cmp < 0) - retval = CALENDAR_MODEL_DUE_OVERDUE; - else if (cmp == 0) - retval = CALENDAR_MODEL_DUE_TODAY; - else - retval = CALENDAR_MODEL_DUE_FUTURE; - } else { - /* Get the current time in the same timezone as the DUE date.*/ - status = cal_client_get_timezone (model->priv->client, dt.tzid, - &zone); - if (status != CAL_CLIENT_GET_SUCCESS) { - retval = CALENDAR_MODEL_DUE_FUTURE; - goto out; - } - - now_tt = icaltime_current_time_with_zone (zone); - - if (icaltime_compare (*dt.value, now_tt) <= 0) - retval = CALENDAR_MODEL_DUE_OVERDUE; - else - if (icaltime_compare_date_only (*dt.value, now_tt) == 0) - retval = CALENDAR_MODEL_DUE_TODAY; - else - retval = CALENDAR_MODEL_DUE_FUTURE; - } - } - - out: - - cal_component_free_datetime (&dt); - - return retval; -} - -/* Returns whether a component is overdue. */ -static gboolean -is_overdue (CalendarModel *model, CalComponent *comp) -{ - switch (get_due_status (model, comp)) { - case CALENDAR_MODEL_DUE_NEVER: - case CALENDAR_MODEL_DUE_FUTURE: - case CALENDAR_MODEL_DUE_COMPLETE: - return FALSE; - case CALENDAR_MODEL_DUE_TODAY: - case CALENDAR_MODEL_DUE_OVERDUE: - return TRUE; - } - - return FALSE; -} - -/* Computes the color to be used to display a component */ -static const char * -get_color (CalendarModel *model, CalComponent *comp) -{ - switch (get_due_status (model, comp)) { - case CALENDAR_MODEL_DUE_NEVER: - case CALENDAR_MODEL_DUE_FUTURE: - case CALENDAR_MODEL_DUE_COMPLETE: - return NULL; - case CALENDAR_MODEL_DUE_TODAY: - return calendar_config_get_tasks_due_today_color (); - case CALENDAR_MODEL_DUE_OVERDUE: - return calendar_config_get_tasks_overdue_color (); - } - - return NULL; -} - -static void * -get_status (CalComponent *comp) -{ - icalproperty_status status; - - cal_component_get_status (comp, &status); - - switch (status) { - case ICAL_STATUS_NONE: - return ""; - - case ICAL_STATUS_NEEDSACTION: - return _("Not Started"); - - case ICAL_STATUS_INPROCESS: - return _("In Progress"); - - case ICAL_STATUS_COMPLETED: - return _("Completed"); - - case ICAL_STATUS_CANCELLED: - return _("Cancelled"); - - default: - g_assert_not_reached (); - return NULL; - } -} - -#if 0 -static void * -get_location (CalComponent *comp) -{ - const char *location; - - cal_component_get_location (comp, &location); - return (void*) location; -} -#endif - -/* value_at handler for the calendar table model */ -static void * -calendar_model_value_at (ETableModel *etm, int col, int row) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - CalComponent *comp; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, NULL); - g_return_val_if_fail (row >= 0 && row < priv->objects->len, NULL); - - comp = g_array_index (priv->objects, CalComponent *, row); - g_assert (comp != NULL); - -#if 0 - g_print ("In calendar_model_value_at: %i\n", col); -#endif - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - return get_categories (comp); - - case CAL_COMPONENT_FIELD_CLASSIFICATION: - return get_classification (comp); - - case CAL_COMPONENT_FIELD_COMPLETED: - return get_completed (model, comp, row); - - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - return get_date_edit_value (model, comp, col, row); - - case CAL_COMPONENT_FIELD_GEO: - return get_geo (comp); - - case CAL_COMPONENT_FIELD_PERCENT: - return GINT_TO_POINTER (get_percent (comp)); - - case CAL_COMPONENT_FIELD_PRIORITY: - return get_priority (comp); - - case CAL_COMPONENT_FIELD_SUMMARY: - return get_summary (comp); - - case CAL_COMPONENT_FIELD_TRANSPARENCY: - return get_transparency (comp); - - case CAL_COMPONENT_FIELD_URL: - return get_url (comp); - - case CAL_COMPONENT_FIELD_HAS_ALARMS: - return GINT_TO_POINTER (cal_component_has_alarms (comp)); - - case CAL_COMPONENT_FIELD_ICON: - { - GSList *attendees = NULL, *sl; - gint retval = 0; - - if (cal_component_has_recurrences (comp)) - return GINT_TO_POINTER (1); - - if (itip_organizer_is_user (comp, priv->client)) - return GINT_TO_POINTER (3); - - cal_component_get_attendee_list (comp, &attendees); - for (sl = attendees; sl != NULL; sl = sl->next) { - CalComponentAttendee *ca = sl->data; - const char *text; - - text = itip_strip_mailto (ca->value); - if (e_account_list_find(priv->accounts, E_ACCOUNT_FIND_ID_ADDRESS, text) != NULL) { - if (ca->delto != NULL) - retval = 3; - else - retval = 2; - break; - } - } - - cal_component_free_attendee_list (attendees); - return GINT_TO_POINTER (retval); - break; - } - case CAL_COMPONENT_FIELD_COMPLETE: - return GINT_TO_POINTER (is_complete (comp)); - - case CAL_COMPONENT_FIELD_RECURRING: - return GINT_TO_POINTER (cal_component_has_recurrences (comp)); - - case CAL_COMPONENT_FIELD_OVERDUE: - return GINT_TO_POINTER (is_overdue (model, comp)); - - case CAL_COMPONENT_FIELD_COLOR: - return (void *) get_color (model, comp); - - case CAL_COMPONENT_FIELD_STATUS: - return get_status (comp); - - case CAL_COMPONENT_FIELD_COMPONENT: - return comp; - -#if 0 - case CAL_COMPONENT_FIELD_LOCATION : - return get_location (comp); -#endif - - default: - g_message ("calendar_model_value_at(): Requested invalid column %d", col); - g_assert_not_reached (); - return NULL; - } -} - -/* Builds a list of categories from a comma-delimited string */ -static GSList * -categories_from_string (const char *value) -{ - GSList *list; - const char *categ_start; - const char *categ_end; - const char *p; - - if (!value) - return NULL; - - list = NULL; - - categ_start = categ_end = NULL; - - for (p = value; *p; p++) { - if (categ_start) { - if (*p == ',') { - char *c; - - c = g_strndup (categ_start, categ_end - categ_start + 1); - list = g_slist_prepend (list, c); - - categ_start = categ_end = NULL; - } else if (!isspace (*p)) - categ_end = p; - } else if (!isspace (*p) && *p != ',') - categ_start = categ_end = p; - } - - if (categ_start) { - char *c; - - c = g_strndup (categ_start, categ_end - categ_start + 1); - list = g_slist_prepend (list, c); - } - - return g_slist_reverse (list); -} - -/* Sets the list of categories from a comma-delimited string */ -static void -set_categories (CalComponent *comp, const char *value) -{ - GSList *list; - GSList *l; - - list = categories_from_string (value); - - cal_component_set_categories_list (comp, list); - - for (l = list; l; l = l->next) { - char *s; - - s = l->data; - g_free (s); - } - - g_slist_free (list); -} - - -static void -set_classification (CalComponent *comp, - const char *value) -{ - CalComponentClassification classif; - - if (!g_strcasecmp (value, _("Private"))) - classif = CAL_COMPONENT_CLASS_PRIVATE; - else if (!g_strcasecmp (value, _("Confidential"))) - classif = CAL_COMPONENT_CLASS_CONFIDENTIAL; - else - classif = CAL_COMPONENT_CLASS_PUBLIC; - - cal_component_set_classification (comp, classif); -} - - -/* Called to set the "Date Completed" field. We also need to update the - Status and Percent fields to make sure they match. */ -static void -set_completed (CalendarModel *model, CalComponent *comp, const void *value) -{ - CalendarModelPrivate *priv = model->priv; - ECellDateEditValue *dv = (ECellDateEditValue*) value; - - if (!dv) { - ensure_task_not_complete (comp); - } else { - time_t t; - - if (dv->tt.is_date) { - /* If its a date, it will be floating, - but completed needs a date time value */ - dv->tt.is_date = FALSE; - t = icaltime_as_timet_with_zone (dv->tt, priv->zone); - } else { - /* We assume that COMPLETED is entered in the current timezone, - even though it gets stored in UTC. */ - t = icaltime_as_timet_with_zone (dv->tt, dv->zone); - } - - ensure_task_complete (comp, t); - } -} - -/* Sets a CalComponentDateTime value */ -static void -set_datetime (CalendarModel *model, CalComponent *comp, const void *value, - void (* set_func) (CalComponent *comp, CalComponentDateTime *dt), - gboolean is_dtend) -{ - ECellDateEditValue *dv = (ECellDateEditValue*) value; - - if (!dv) { - (* set_func) (comp, NULL); - } else { - CalComponentDateTime dt; - - dt.value = &dv->tt; - dt.tzid = icaltimezone_get_tzid (dv->zone); - - /* For a DTEND with a DATE value, we add 1 day to it. */ - if (is_dtend && dt.value->is_date) { - icaltime_adjust (dt.value, 1, 0, 0, 0); - } - - (* set_func) (comp, &dt); - } -} - -/* FIXME: We need to set the "transient_for" property for the dialog, but the - * model doesn't know anything about the windows. - */ -static void -show_geo_warning (void) -{ - GtkWidget *dialog; - - dialog = gnome_message_box_new (_("The geographical position must be entered " - "in the format: \n\n45.436845,125.862501"), - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, NULL); - gtk_widget_show (dialog); -} - -/* Sets the geographical position value of a component */ -static void -set_geo (CalComponent *comp, const char *value) -{ - double latitude, longitude; - int matched; - struct icalgeotype geo; - - if (string_is_empty (value)) { - cal_component_set_geo (comp, NULL); - return; - } - - matched = sscanf (value, "%lg , %lg", &latitude, &longitude); - - if (matched != 2) { - show_geo_warning (); - return; - } - - geo.lat = latitude; - geo.lon = longitude; - cal_component_set_geo (comp, &geo); -} - -/* Sets the percent value of a calendar component */ -static void -set_percent (CalComponent *comp, const void *value) -{ - gint percent = GPOINTER_TO_INT (value); - - g_return_if_fail (percent >= -1); - g_return_if_fail (percent <= 100); - - /* A value of -1 means it isn't set. */ - if (percent == -1) { - cal_component_set_percent (comp, NULL); - ensure_task_not_complete (comp); - } else { - cal_component_set_percent (comp, &percent); - - if (percent == 100) - ensure_task_complete (comp, -1); - else { - ensure_task_not_complete (comp); - if (percent > 0) - cal_component_set_status (comp, ICAL_STATUS_INPROCESS); - } - } -} - -/* Sets the priority of a calendar component */ -static void -set_priority (CalComponent *comp, const char *value) -{ - int priority; - - priority = cal_util_priority_from_string (value); - /* If the priority is invalid (which should never happen) output a - warning and set it to undefined. */ - if (priority == -1) { - g_warning ("Invalid priority"); - priority = 0; - } - - cal_component_set_priority (comp, &priority); -} - -/* Sets the summary of a calendar component */ -static void -set_summary (CalComponent *comp, const char *value) -{ - CalComponentText text; - - if (string_is_empty (value)) { - cal_component_set_summary (comp, NULL); - return; - } - - text.value = value; - text.altrep = NULL; /* FIXME: should we preserve the old ALTREP? */ - - cal_component_set_summary (comp, &text); -} - -/* Sets the transparency of a calendar component */ -static void -set_transparency (CalComponent *comp, const char *value) -{ - CalComponentTransparency transp; - - if (!g_strcasecmp (value, _("Free"))) - transp = CAL_COMPONENT_TRANSP_TRANSPARENT; - else - transp = CAL_COMPONENT_TRANSP_OPAQUE; - - cal_component_set_transparency (comp, transp); -} - -/* Sets the URI of a calendar component */ -static void -set_url (CalComponent *comp, const char *value) -{ - if (string_is_empty (value)) { - cal_component_set_url (comp, NULL); - return; - } - - cal_component_set_url (comp, value); -} - -/* Called to set the checkbutton field which indicates whether a task is - complete. */ -static void -set_complete (CalComponent *comp, const void *value) -{ - gint state = GPOINTER_TO_INT (value); - - if (state) { - ensure_task_complete (comp, -1); - } else { - ensure_task_not_complete (comp); - } -} - -/* Sets the status of a calendar component. */ -static void -set_status (CalComponent *comp, const char *value) -{ - icalproperty_status status; - int percent; - - /* An empty string is the same as 'None'. */ - if (!value[0] || !g_strcasecmp (value, _("None"))) - status = ICAL_STATUS_NONE; - else if (!g_strcasecmp (value, _("Not Started"))) - status = ICAL_STATUS_NEEDSACTION; - else if (!g_strcasecmp (value, _("In Progress"))) - status = ICAL_STATUS_INPROCESS; - else if (!g_strcasecmp (value, _("Completed"))) - status = ICAL_STATUS_COMPLETED; - else if (!g_strcasecmp (value, _("Cancelled"))) - status = ICAL_STATUS_CANCELLED; - else { - g_warning ("Invalid status: %s\n", value); - return; - } - - cal_component_set_status (comp, status); - - if (status == ICAL_STATUS_NEEDSACTION) { - percent = 0; - cal_component_set_percent (comp, &percent); - cal_component_set_completed (comp, NULL); - } else if (status == ICAL_STATUS_INPROCESS) { - ensure_task_not_complete (comp); - percent = 50; - cal_component_set_percent (comp, &percent); - } else if (status == ICAL_STATUS_COMPLETED) { - ensure_task_complete (comp, -1); - } -} - -#if 0 -static void -set_location (CalComponent *comp, const char *value) -{ - if (string_is_empty (value)) { - cal_component_set_location (comp, NULL); - return; - } - - cal_component_set_location (comp, value); -} -#endif - -/* set_value_at handler for the calendar table model */ -static void -calendar_model_set_value_at (ETableModel *etm, int col, int row, const void *value) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - CalComponent *comp; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - g_return_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS); - g_return_if_fail (row >= 0 && row < priv->objects->len); - - comp = g_array_index (priv->objects, CalComponent *, row); - g_assert (comp != NULL); - -#if 0 - g_print ("In calendar_model_set_value_at: %i\n", col); -#endif - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - set_categories (comp, value); - break; - - case CAL_COMPONENT_FIELD_CLASSIFICATION: - set_classification (comp, value); - break; - - case CAL_COMPONENT_FIELD_COMPLETED: - set_completed (model, comp, value); - break; - - case CAL_COMPONENT_FIELD_DTEND: - /* FIXME: Need to reset dtstart if dtend happens before it */ - set_datetime (model, comp, value, cal_component_set_dtend, - TRUE); - break; - - case CAL_COMPONENT_FIELD_DTSTART: - /* FIXME: Need to reset dtend if dtstart happens after it */ - set_datetime (model, comp, value, cal_component_set_dtstart, - FALSE); - break; - - case CAL_COMPONENT_FIELD_DUE: - set_datetime (model, comp, value, cal_component_set_due, - FALSE); - break; - - case CAL_COMPONENT_FIELD_GEO: - set_geo (comp, value); - break; - - case CAL_COMPONENT_FIELD_PERCENT: - set_percent (comp, value); - break; - - case CAL_COMPONENT_FIELD_PRIORITY: - set_priority (comp, value); - break; - - case CAL_COMPONENT_FIELD_SUMMARY: - set_summary (comp, value); - break; - - case CAL_COMPONENT_FIELD_TRANSPARENCY: - set_transparency (comp, value); - break; - - case CAL_COMPONENT_FIELD_URL: - set_url (comp, value); - break; - - case CAL_COMPONENT_FIELD_COMPLETE: - set_complete (comp, value); - break; - - case CAL_COMPONENT_FIELD_STATUS: - set_status (comp, value); - break; - -#if 0 - case CAL_COMPONENT_FIELD_LOCATION : - set_location (comp, value); - break; -#endif - - default: - g_message ("calendar_model_set_value_at(): Requested invalid column %d", col); - g_assert_not_reached (); - return; - } - - if (cal_client_update_object (priv->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("calendar_model_set_value_at(): Could not update the object!"); -} - -/* is_cell_editable handler for the calendar table model */ -static gboolean -calendar_model_is_cell_editable (ETableModel *etm, int col, int row) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, FALSE); - - /* FIXME: We can't check this as 'click-to-add' passes row 0. */ - /*g_return_val_if_fail (row >= 0 && row < priv->objects->len, FALSE);*/ - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - case CAL_COMPONENT_FIELD_CLASSIFICATION: - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PERCENT: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_TRANSPARENCY: - case CAL_COMPONENT_FIELD_URL: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_STATUS: - return TRUE; - - default: - return FALSE; - } -} - -/* append_row handler for the calendar model */ -static void -calendar_model_append_row (ETableModel *etm, ETableModel *source, gint row) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - CalComponent *comp; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - /* Guard against saving before the calendar is open */ - if (!(priv->client && cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - /* FIXME: This should also support journal components */ - switch (priv->new_comp_vtype) { - case CAL_COMPONENT_EVENT: - comp = cal_comp_event_new_with_defaults (priv->client); - break; - case CAL_COMPONENT_TODO: - comp = cal_comp_task_new_with_defaults (priv->client); - break; - default: - comp = cal_component_new (); - cal_component_set_new_vtype (comp, priv->new_comp_vtype); - } - - set_categories (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_CATEGORIES, row)); - set_classification (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_CLASSIFICATION, row)); - set_completed (model, comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_COMPLETED, row)); - /* FIXME: Need to reset dtstart if dtend happens before it */ - set_datetime (model, comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_DTEND, row), cal_component_set_dtend, TRUE); - /* FIXME: Need to reset dtend if dtstart happens after it */ - set_datetime (model, comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_DTSTART, row), cal_component_set_dtstart, FALSE); - set_datetime (model, comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_DUE, row), cal_component_set_due, FALSE); - set_geo (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_GEO, row)); - set_percent (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_PERCENT, row)); - set_priority (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_PRIORITY, row)); - set_summary (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_SUMMARY, row)); - set_transparency (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_TRANSPARENCY, row)); - set_url (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_URL, row)); - set_complete (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_COMPLETE, row)); - set_status (comp, e_table_model_value_at(source, CAL_COMPONENT_FIELD_STATUS, row)); - - if (cal_client_update_object (priv->client, comp) != CAL_CLIENT_RESULT_SUCCESS) { - /* FIXME: Show error dialog. */ - g_message ("calendar_model_append_row(): Could not add new object!"); - } - - g_object_unref (comp); -} - -/* Duplicates a string value */ -static char * -dup_string (const char *value) -{ - return g_strdup (value); -} - -static void* -dup_date_edit_value (const void *value) -{ - ECellDateEditValue *dv, *orig_dv; - - if (value == NULL) - return NULL; - - orig_dv = (ECellDateEditValue*) value; - - dv = g_new (ECellDateEditValue, 1); - *dv = *orig_dv; - - return dv; -} - -/* duplicate_value handler for the calendar table model */ -static void * -calendar_model_duplicate_value (ETableModel *etm, int col, const void *value) -{ - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, NULL); - - /* They are almost all dup_string()s for now, but we'll have real fields - * later. - */ - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - case CAL_COMPONENT_FIELD_CLASSIFICATION: - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_TRANSPARENCY: - case CAL_COMPONENT_FIELD_URL: - case CAL_COMPONENT_FIELD_STATUS: - return dup_string (value); - - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - return dup_date_edit_value (value); - - case CAL_COMPONENT_FIELD_HAS_ALARMS: - case CAL_COMPONENT_FIELD_ICON: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_PERCENT: - case CAL_COMPONENT_FIELD_RECURRING: - case CAL_COMPONENT_FIELD_OVERDUE: - case CAL_COMPONENT_FIELD_COLOR: - return (void *) value; - - case CAL_COMPONENT_FIELD_COMPONENT: { - CalComponent *comp; - - comp = CAL_COMPONENT (value); - g_object_ref (comp); - return comp; - } - - default: - g_message ("calendar_model_duplicate_value(): Requested invalid column %d", col); - return NULL; - } -} - -/* free_value handler for the calendar table model */ -static void -calendar_model_free_value (ETableModel *etm, int col, void *value) -{ - g_return_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS); - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - if (value) - g_free (value); - break; - - case CAL_COMPONENT_FIELD_CLASSIFICATION: - break; - - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_STATUS: - if (value) - g_free (value); - break; - - case CAL_COMPONENT_FIELD_TRANSPARENCY: - break; - - case CAL_COMPONENT_FIELD_URL: - if (value) - g_free (value); - break; - - case CAL_COMPONENT_FIELD_PERCENT: - case CAL_COMPONENT_FIELD_HAS_ALARMS: - case CAL_COMPONENT_FIELD_ICON: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_RECURRING: - case CAL_COMPONENT_FIELD_OVERDUE: - case CAL_COMPONENT_FIELD_COLOR: - break; - - case CAL_COMPONENT_FIELD_COMPONENT: - if (value) - g_object_unref (value); - break; - - default: - g_message ("calendar_model_free_value(): Requested invalid column %d", col); - } -} - -/* Initializes a string value */ -static char * -init_string (void) -{ - return g_strdup (""); -} - -/* initialize_value handler for the calendar table model */ -static void * -calendar_model_initialize_value (ETableModel *etm, int col) -{ - CalendarModel *model; - - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, NULL); - - model = CALENDAR_MODEL (etm); - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - return g_strdup (model->priv->default_category ? model->priv->default_category : ""); - - case CAL_COMPONENT_FIELD_CLASSIFICATION: - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_TRANSPARENCY: - case CAL_COMPONENT_FIELD_URL: - case CAL_COMPONENT_FIELD_STATUS: - return init_string (); - - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - case CAL_COMPONENT_FIELD_HAS_ALARMS: - case CAL_COMPONENT_FIELD_ICON: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_RECURRING: - case CAL_COMPONENT_FIELD_OVERDUE: - case CAL_COMPONENT_FIELD_COLOR: - case CAL_COMPONENT_FIELD_COMPONENT: - return NULL; - - case CAL_COMPONENT_FIELD_PERCENT: - return GINT_TO_POINTER (-1); - - default: - g_message ("calendar_model_initialize_value(): Requested invalid column %d", col); - return NULL; - } -} - -/* value_is_empty handler for the calendar model. This should return TRUE - unless a significant value has been set. The 'click-to-add' feature - checks all fields to see if any are not empty and if so it adds a new - row, so we only want to return FALSE if we have a useful object. */ -static gboolean -calendar_model_value_is_empty (ETableModel *etm, int col, const void *value) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, TRUE); - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - /* This could be a hack or not. If the categories field only - * contains the default category, then it possibly means that - * the user has not entered anything at all in the click-to-add; - * the category is in the value because we put it there in - * calendar_model_initialize_value(). - */ - if (priv->default_category && value && strcmp (priv->default_category, value) == 0) - return TRUE; - else - return string_is_empty (value); - - case CAL_COMPONENT_FIELD_CLASSIFICATION: /* actually goes here, not by itself */ - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_TRANSPARENCY: - case CAL_COMPONENT_FIELD_URL: - case CAL_COMPONENT_FIELD_STATUS: - return string_is_empty (value); - - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - return value ? FALSE : TRUE; - - case CAL_COMPONENT_FIELD_PERCENT: - return (GPOINTER_TO_INT (value) < 0) ? TRUE : FALSE; - - case CAL_COMPONENT_FIELD_HAS_ALARMS: - case CAL_COMPONENT_FIELD_ICON: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_RECURRING: - case CAL_COMPONENT_FIELD_OVERDUE: - case CAL_COMPONENT_FIELD_COLOR: - case CAL_COMPONENT_FIELD_COMPONENT: - return TRUE; - - default: - g_message ("calendar_model_value_is_empty(): Requested invalid column %d", col); - return TRUE; - } -} - -static char* -date_value_to_string (ETableModel *etm, const void *value) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - ECellDateEditValue *dv = (ECellDateEditValue *) value; - struct icaltimetype tt; - struct tm tmp_tm; - char buffer[64]; - - model = CALENDAR_MODEL (etm); - priv = model->priv; - - if (!dv) - return g_strdup (""); - - /* We currently convert all the dates to the current timezone. */ - tt = dv->tt; - icaltimezone_convert_time (&tt, dv->zone, priv->zone); - - tmp_tm.tm_year = tt.year - 1900; - tmp_tm.tm_mon = tt.month - 1; - tmp_tm.tm_mday = tt.day; - tmp_tm.tm_hour = tt.hour; - tmp_tm.tm_min = tt.minute; - tmp_tm.tm_sec = tt.second; - tmp_tm.tm_isdst = -1; - - tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year); - - e_time_format_date_and_time (&tmp_tm, priv->use_24_hour_format, - TRUE, FALSE, - buffer, sizeof (buffer)); - return g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); -} - - -static char * -calendar_model_value_to_string (ETableModel *etm, int col, const void *value) -{ - g_return_val_if_fail (col >= 0 && col < CAL_COMPONENT_FIELD_NUM_FIELDS, NULL); - - switch (col) { - case CAL_COMPONENT_FIELD_CATEGORIES: - case CAL_COMPONENT_FIELD_CLASSIFICATION: - case CAL_COMPONENT_FIELD_GEO: - case CAL_COMPONENT_FIELD_PRIORITY: - case CAL_COMPONENT_FIELD_SUMMARY: - case CAL_COMPONENT_FIELD_TRANSPARENCY: - case CAL_COMPONENT_FIELD_URL: - case CAL_COMPONENT_FIELD_STATUS: - return g_strdup (value); - - case CAL_COMPONENT_FIELD_COMPLETED: - case CAL_COMPONENT_FIELD_DTEND: - case CAL_COMPONENT_FIELD_DTSTART: - case CAL_COMPONENT_FIELD_DUE: - return date_value_to_string (etm, value); - - case CAL_COMPONENT_FIELD_ICON: - if (GPOINTER_TO_INT (value) == 0) - return g_locale_to_utf8 (_("Normal"), -1, NULL, NULL, NULL); - else if (GPOINTER_TO_INT (value) == 1) - return g_locale_to_utf8 (_("Recurring"), -1, NULL, NULL, NULL); - else - return g_locale_to_utf8 (_("Assigned"), -1, NULL, NULL, NULL); - - case CAL_COMPONENT_FIELD_HAS_ALARMS: - case CAL_COMPONENT_FIELD_COMPLETE: - case CAL_COMPONENT_FIELD_RECURRING: - case CAL_COMPONENT_FIELD_OVERDUE: - return g_locale_to_utf8 (value ? _("Yes") : _("No"), -1, NULL, NULL, NULL); - - case CAL_COMPONENT_FIELD_COLOR: - return NULL; - - case CAL_COMPONENT_FIELD_COMPONENT: - return NULL; - - case CAL_COMPONENT_FIELD_PERCENT: - if (GPOINTER_TO_INT (value) < 0) - return g_strdup ("N/A"); - else - return g_strdup_printf ("%i%%", GPOINTER_TO_INT (value)); - - default: - g_message ("calendar_model_value_as_string(): Requested invalid column %d", col); - return NULL; - } -} - - - -/** - * calendar_model_new: - * - * Creates a new calendar model. It must be told about the calendar client - * interface object it will monitor with calendar_model_set_cal_client(). - * - * Return value: A newly-created calendar model. - **/ -CalendarModel * -calendar_model_new (void) -{ - return CALENDAR_MODEL (g_object_new (TYPE_CALENDAR_MODEL, NULL)); -} - - -/* Callback used when a component is updated in the live query */ -static void -query_obj_updated_cb (CalQuery *query, const char *uid, - gboolean query_in_progress, int n_scanned, int total, - gpointer data) -{ - CalendarModel *model; - CalendarModelPrivate *priv; - int orig_idx; - CalComponent *new_comp; - const char *new_comp_uid; - int *new_idx; - CalClientGetStatus status; - CalendarModelObjectData new_object_data = { NULL, NULL, NULL, NULL }; - - model = CALENDAR_MODEL (data); - priv = model->priv; - - e_table_model_pre_change (E_TABLE_MODEL (model)); - - orig_idx = remove_object (model, uid); - - status = cal_client_get_object (priv->client, uid, &new_comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Insert the object into the model */ - - cal_component_get_uid (new_comp, &new_comp_uid); - - if (orig_idx == -1) { - /* The object not in the model originally, so we just append it */ - - g_array_append_val (priv->objects, new_comp); - g_array_append_val (priv->objects_data, new_object_data); - - new_idx = g_new (int, 1); - *new_idx = priv->objects->len - 1; - - g_hash_table_insert (priv->uid_index_hash, (char *) new_comp_uid, new_idx); - e_table_model_row_inserted (E_TABLE_MODEL (model), *new_idx); - } else { - int i; - - /* Insert the new version of the object in its old position */ - - g_array_insert_val (priv->objects, orig_idx, new_comp); - g_array_insert_val (priv->objects_data, orig_idx, - new_object_data); - - new_idx = g_new (int, 1); - *new_idx = orig_idx; - g_hash_table_insert (priv->uid_index_hash, (char *) new_comp_uid, new_idx); - - /* Increase the indices of all subsequent objects */ - - for (i = orig_idx + 1; i < priv->objects->len; i++) { - CalComponent *comp; - int *comp_idx; - const char *comp_uid; - - comp = g_array_index (priv->objects, CalComponent *, i); - g_assert (comp != NULL); - - cal_component_get_uid (comp, &comp_uid); - - comp_idx = g_hash_table_lookup (priv->uid_index_hash, comp_uid); - g_assert (comp_idx != NULL); - - (*comp_idx)++; - } - - e_table_model_row_changed (E_TABLE_MODEL (model), *new_idx); - } - - break; - - case CAL_CLIENT_GET_NOT_FOUND: - /* Nothing; the object may have been removed from the server. We just - * notify that the old object was deleted. - */ - if (orig_idx != -1) - e_table_model_row_deleted (E_TABLE_MODEL (model), orig_idx); - else - e_table_model_no_change (E_TABLE_MODEL (model)); - - break; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("obj_updated_cb(): Syntax error when getting object `%s'", uid); - - /* Same notification as above */ - if (orig_idx != -1) - e_table_model_row_deleted (E_TABLE_MODEL (model), orig_idx); - else - e_table_model_no_change (E_TABLE_MODEL (model)); - - break; - - default: - g_assert_not_reached (); - } -} - -/* Callback used when a component is removed from the live query */ -static void -query_obj_removed_cb (CalQuery *query, const char *uid, gpointer data) -{ - CalendarModel *model; - int idx; - - model = CALENDAR_MODEL (data); - - e_table_model_pre_change (E_TABLE_MODEL (model)); - - idx = remove_object (model, uid); - - if (idx != -1) - e_table_model_row_deleted (E_TABLE_MODEL (model), idx); - else - e_table_model_no_change (E_TABLE_MODEL (model)); -} - -/* Callback used when a query ends */ -static void -query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data) -{ - CalendarModel *model; - - model = CALENDAR_MODEL (data); - - /* FIXME */ - - calendar_model_set_status_message (model, NULL); - - if (status != CAL_QUERY_DONE_SUCCESS) - g_warning ("query done: %s\n", error_str); -} - -/* Callback used when an evaluation error occurs when running a query */ -static void -query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data) -{ - CalendarModel *model; - - model = CALENDAR_MODEL (data); - - /* FIXME */ - - calendar_model_set_status_message (model, NULL); - - g_warning ("eval error: %s\n", error_str); -} - -/* Builds a complete query sexp for the calendar model by adding the predicates - * to filter only for the type of objects that the model supports, and - * whether we want completed tasks. - */ -static char * -adjust_query_sexp (CalendarModel *model, const char *sexp) -{ - CalendarModelPrivate *priv; - CalObjType type; - char *type_sexp; - char *completed_sexp; - char *new_sexp; - - priv = model->priv; - - type = priv->type; - - if (!(type & CALOBJ_TYPE_ANY)) - type_sexp = g_strdup ("#t"); - else - type_sexp = g_strdup_printf ( - "(or %s %s %s)", - (type & CALOBJ_TYPE_EVENT) ? "(= (get-vtype) \"VEVENT\")" : "", - (type & CALOBJ_TYPE_TODO) ? "(= (get-vtype) \"VTODO\")" : "", - (type & CALOBJ_TYPE_JOURNAL) ? "(= (get-vtype) \"VJOURNAL\")" : ""); - - /* Create a sub-expression for filtering out completed tasks, based on - the config settings. */ - completed_sexp = calendar_config_get_hide_completed_tasks_sexp (); - - new_sexp = g_strdup_printf ("(and %s %s %s)", type_sexp, - completed_sexp ? completed_sexp : "", - sexp); - g_free (type_sexp); - g_free (completed_sexp); - -#if 0 - g_print ("Calendar model sexp:\n%s\n", new_sexp); -#endif - - return new_sexp; -} - -/* Restarts a query */ -static void -update_query (CalendarModel *model) -{ - CalendarModelPrivate *priv; - CalQuery *old_query; - char *real_sexp; - - priv = model->priv; - - e_table_model_pre_change (E_TABLE_MODEL (model)); - free_objects (model); - e_table_model_changed (E_TABLE_MODEL (model)); - - if (!(priv->client - && cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - old_query = priv->query; - priv->query = NULL; - - if (old_query) { - g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, model); - g_object_unref (old_query); - } - - g_assert (priv->sexp != NULL); - real_sexp = adjust_query_sexp (model, priv->sexp); - - calendar_model_set_status_message (model, _("Searching")); - priv->query = cal_client_get_query (priv->client, real_sexp); - g_free (real_sexp); - - if (!priv->query) { - g_message ("update_query(): Could not create the query"); - calendar_model_set_status_message (model, NULL); - return; - } - - g_signal_connect (priv->query, "obj_updated", - G_CALLBACK (query_obj_updated_cb), model); - g_signal_connect (priv->query, "obj_removed", - G_CALLBACK (query_obj_removed_cb), model); - g_signal_connect (priv->query, "query_done", - G_CALLBACK (query_query_done_cb), model); - g_signal_connect (priv->query, "eval_error", - G_CALLBACK (query_eval_error_cb), model); -} - -/* Callback used when a calendar is opened into the server */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - CalendarModel *model; - - model = CALENDAR_MODEL (data); - - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; - - update_query (model); -} - - -/* Removes an object from the model and updates all the indices that follow. - * Returns the index of the object that was removed, or -1 if no object with - * such UID was found. - */ -static int -remove_object (CalendarModel *model, const char *uid) -{ - CalendarModelPrivate *priv; - int *idx; - CalComponent *orig_comp; - int i; - int n; - CalendarModelObjectData *object_data; - - priv = model->priv; - - /* Find the index of the object to be removed */ - - idx = g_hash_table_lookup (priv->uid_index_hash, uid); - if (!idx) - return -1; - - orig_comp = g_array_index (priv->objects, CalComponent *, *idx); - g_assert (orig_comp != NULL); - - /* Decrease the indices of all the objects that follow in the array */ - - for (i = *idx + 1; i < priv->objects->len; i++) { - CalComponent *comp; - int *comp_idx; - const char *comp_uid; - - comp = g_array_index (priv->objects, CalComponent *, i); - g_assert (comp != NULL); - - cal_component_get_uid (comp, &comp_uid); - - comp_idx = g_hash_table_lookup (priv->uid_index_hash, comp_uid); - g_assert (comp_idx != NULL); - - (*comp_idx)--; - g_assert (*comp_idx >= 0); - } - - /* Remove this object from the array and hash */ - - g_hash_table_remove (priv->uid_index_hash, uid); - g_array_remove_index (priv->objects, *idx); - - object_data = &g_array_index (priv->objects_data, - CalendarModelObjectData, *idx); - calendar_model_free_object_data (model, object_data); - g_array_remove_index (priv->objects_data, *idx); - - g_object_unref (orig_comp); - - n = *idx; - g_free (idx); - - return n; -} - -/* Displays messages on the status bar */ -#define EVOLUTION_TASKS_PROGRESS_IMAGE "evolution-tasks-mini.png" -static GdkPixbuf *progress_icon[2] = { NULL, NULL }; - -void -calendar_model_set_status_message (CalendarModel *model, const char *message) -{ - extern EvolutionShellClient *global_shell_client; /* ugly */ - CalendarModelPrivate *priv; - - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - priv = model->priv; - - if (!message || !*message) { - if (priv->activity) { - g_object_unref (priv->activity); - priv->activity = NULL; - } - } - else if (!priv->activity) { - int display; - char *client_id = g_strdup_printf ("%p", model); - - if (progress_icon[0] == NULL) - progress_icon[0] = gdk_pixbuf_new_from_file (EVOLUTION_IMAGESDIR "/" EVOLUTION_TASKS_PROGRESS_IMAGE, NULL); - priv->activity = evolution_activity_client_new ( - global_shell_client, client_id, - progress_icon, message, TRUE, &display); - - g_free (client_id); - } - else - evolution_activity_client_update (priv->activity, message, -1.0); -} - -/** - * calendar_model_get_cal_client: - * @model: A calendar model. - * - * Queries the calendar client interface object that a calendar model is using. - * - * Return value: A calendar client interface object. - **/ -CalClient * -calendar_model_get_cal_client (CalendarModel *model) -{ - CalendarModelPrivate *priv; - - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (IS_CALENDAR_MODEL (model), NULL); - - priv = model->priv; - - return priv->client; -} - - -/** - * calendar_model_set_cal_client: - * @model: A calendar model. - * @client: A calendar client interface object. - * @type: Type of objects to present. - * - * Sets the calendar client interface object that a calendar model will monitor. - * It also sets the types of objects this model will present to an #ETable. - **/ -void -calendar_model_set_cal_client (CalendarModel *model, CalClient *client, CalObjType type) -{ - CalendarModelPrivate *priv; - - g_return_if_fail (model != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - if (client) - g_return_if_fail (IS_CAL_CLIENT (client)); - - priv = model->priv; - - if (priv->client == client && priv->type == type) - return; - - if (client) - g_object_ref (client); - - if (priv->client) { - g_signal_handlers_disconnect_matched (priv->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model); - g_object_unref (priv->client); - } - - priv->client = client; - priv->type = type; - - if (priv->client) { - if (cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_LOADED) - update_query (model); - else - g_signal_connect (priv->client, "cal_opened", G_CALLBACK (cal_opened_cb), model); - } -} - -/** - * calendar_model_set_query: - * @model: A calendar model. - * @sexp: Sexp that defines the query. - * - * Sets the query sexp that a calendar model will use to filter its contents. - **/ -void -calendar_model_set_query (CalendarModel *model, const char *sexp) -{ - CalendarModelPrivate *priv; - - g_return_if_fail (model != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (model)); - g_return_if_fail (sexp != NULL); - - priv = model->priv; - - if (priv->sexp) - g_free (priv->sexp); - - priv->sexp = g_strdup (sexp); - - update_query (model); -} - - -/** - * calendar_model_set_new_comp_vtype: - * @model: A calendar model. - * @vtype: Type of calendar components to create. - * - * Sets the type of calendar components that will be created by a calendar table - * model when the click-to-add functionality of the table is used. - **/ -void -calendar_model_set_new_comp_vtype (CalendarModel *model, CalComponentVType vtype) -{ - CalendarModelPrivate *priv; - - g_return_if_fail (model != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (model)); - g_return_if_fail (vtype != CAL_COMPONENT_NO_TYPE); - - priv = model->priv; - priv->new_comp_vtype = vtype; -} - -/** - * calendar_model_get_new_comp_vtype: - * @model: A calendar model. - * - * Queries the type of calendar components that are created by a calendar table - * model when using the click-to-add functionality in a table. - * - * Return value: Type of components that are created. - **/ -CalComponentVType -calendar_model_get_new_comp_vtype (CalendarModel *model) -{ - CalendarModelPrivate *priv; - - g_return_val_if_fail (model != NULL, CAL_COMPONENT_NO_TYPE); - g_return_val_if_fail (IS_CALENDAR_MODEL (model), CAL_COMPONENT_NO_TYPE); - - priv = model->priv; - return priv->new_comp_vtype; -} - - -void -calendar_model_mark_task_complete (CalendarModel *model, - gint row) -{ - CalendarModelPrivate *priv; - CalComponent *comp; - - g_return_if_fail (model != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - priv = model->priv; - - g_return_if_fail (row >= 0 && row < priv->objects->len); - - comp = g_array_index (priv->objects, CalComponent *, row); - g_assert (comp != NULL); - - ensure_task_complete (comp, -1); - - if (cal_client_update_object (priv->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("calendar_model_mark_task_complete(): Could not update the object!"); -} - - -/** - * calendar_model_get_component: - * @model: A calendar model. - * @row: Row number of sought calendar component. - * - * Queries a calendar component from a calendar model based on its row number. - * - * Return value: The sought calendar component. - **/ -CalComponent * -calendar_model_get_component (CalendarModel *model, - gint row) -{ - CalendarModelPrivate *priv; - - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (IS_CALENDAR_MODEL (model), NULL); - - priv = model->priv; - - g_return_val_if_fail (row >= 0 && row < priv->objects->len, NULL); - - return g_array_index (priv->objects, CalComponent *, row); -} - - -/* This makes sure a task is marked as complete. - It makes sure the "Date Completed" property is set. If the completed_date - is not -1, then that is used, otherwise if the "Date Completed" property - is not already set it is set to the current time. - It makes sure the percent is set to 100, and that the status is "Completed". - Note that this doesn't update the component on the server. */ -static void -ensure_task_complete (CalComponent *comp, - time_t completed_date) -{ - struct icaltimetype *old_completed = NULL; - int *old_percent, new_percent; - icalproperty_status status; - gboolean set_completed = TRUE; - - /* Date Completed. */ - if (completed_date == -1) { - cal_component_get_completed (comp, &old_completed); - - if (old_completed) { - cal_component_free_icaltimetype (old_completed); - set_completed = FALSE; - } else { - completed_date = time (NULL); - } - } - - if (set_completed) { - icaltimezone *utc_zone; - struct icaltimetype new_completed; - - /* COMPLETED is stored in UTC. */ - utc_zone = icaltimezone_get_utc_timezone (); - new_completed = icaltime_from_timet_with_zone (completed_date, - FALSE, - utc_zone); - cal_component_set_completed (comp, &new_completed); - } - - /* Percent. */ - cal_component_get_percent (comp, &old_percent); - if (!old_percent || *old_percent != 100) { - new_percent = 100; - cal_component_set_percent (comp, &new_percent); - } - if (old_percent) - cal_component_free_percent (old_percent); - - /* Status. */ - cal_component_get_status (comp, &status); - if (status != ICAL_STATUS_COMPLETED) { - cal_component_set_status (comp, ICAL_STATUS_COMPLETED); - } -} - - -/* This makes sure a task is marked as incomplete. It clears the - "Date Completed" property. If the percent is set to 100 it removes it, - and if the status is "Completed" it sets it to "Needs Action". - Note that this doesn't update the component on the client. */ -static void -ensure_task_not_complete (CalComponent *comp) -{ - icalproperty_status old_status; - int *old_percent; - - /* Date Completed. */ - cal_component_set_completed (comp, NULL); - - /* Percent. */ - cal_component_get_percent (comp, &old_percent); - if (old_percent && *old_percent == 100) - cal_component_set_percent (comp, NULL); - if (old_percent) - cal_component_free_percent (old_percent); - - /* Status. */ - cal_component_get_status (comp, &old_status); - if (old_status == ICAL_STATUS_COMPLETED) - cal_component_set_status (comp, ICAL_STATUS_NEEDSACTION); -} - - -/* Whether we use 24 hour format to display the times. */ -gboolean -calendar_model_get_use_24_hour_format (CalendarModel *model) -{ - g_return_val_if_fail (IS_CALENDAR_MODEL (model), TRUE); - - return model->priv->use_24_hour_format; -} - - -void -calendar_model_set_use_24_hour_format (CalendarModel *model, - gboolean use_24_hour_format) -{ - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - if (model->priv->use_24_hour_format != use_24_hour_format) { - e_table_model_pre_change (E_TABLE_MODEL (model)); - model->priv->use_24_hour_format = use_24_hour_format; - /* Get the views to redraw themselves. */ - e_table_model_changed (E_TABLE_MODEL (model)); - } -} - - -void -calendar_model_set_default_category (CalendarModel *model, - const char *default_category) -{ - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - g_free (model->priv->default_category); - model->priv->default_category = g_strdup (default_category); -} - - - -/* The current timezone. */ -icaltimezone* -calendar_model_get_timezone (CalendarModel *model) -{ - g_return_val_if_fail (IS_CALENDAR_MODEL (model), NULL); - - return model->priv->zone; -} - - -void -calendar_model_set_timezone (CalendarModel *model, - icaltimezone *zone) -{ - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - if (model->priv->zone != zone) { - e_table_model_pre_change (E_TABLE_MODEL (model)); - model->priv->zone = zone; - - /* The timezone affects the times shown for COMPLETED and - maybe other fields, so we need to redisplay everything. */ - e_table_model_changed (E_TABLE_MODEL (model)); - } -} - - -/** - * calendar_model_refresh: - * @model: A calendar model. - * - * Refreshes the calendar model, reloading the events/tasks from the server. - * Be careful about doing this when the user is editing an event/task. - **/ -void -calendar_model_refresh (CalendarModel *model) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (IS_CALENDAR_MODEL (model)); - - update_query (model); -} diff --git a/calendar/gui/calendar-model.h b/calendar/gui/calendar-model.h deleted file mode 100644 index 15936367ef..0000000000 --- a/calendar/gui/calendar-model.h +++ /dev/null @@ -1,99 +0,0 @@ -/* Evolution calendar - Data model for ETable - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CALENDAR_MODEL_H -#define CALENDAR_MODEL_H - -#include <gal/e-table/e-table-model.h> -#include <cal-client/cal-client.h> - -G_BEGIN_DECLS - - - -#define TYPE_CALENDAR_MODEL (calendar_model_get_type ()) -#define CALENDAR_MODEL(obj) (GTK_CHECK_CAST ((obj), TYPE_CALENDAR_MODEL, CalendarModel)) -#define CALENDAR_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_CALENDAR_MODEL, \ - CalendarModelClass)) -#define IS_CALENDAR_MODEL(obj) (GTK_CHECK_TYPE ((obj), TYPE_CALENDAR_MODEL)) -#define IS_CALENDAR_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_CALENDAR_MODEL)) - -typedef struct _CalendarModel CalendarModel; -typedef struct _CalendarModelClass CalendarModelClass; - -typedef struct _CalendarModelPrivate CalendarModelPrivate; - -struct _CalendarModel { - ETableModel model; - - /* Private data */ - CalendarModelPrivate *priv; -}; - -struct _CalendarModelClass { - ETableModelClass parent_class; -}; - -GtkType calendar_model_get_type (void); - -CalendarModel* calendar_model_new (void); - -CalClient* calendar_model_get_cal_client (CalendarModel *model); -void calendar_model_set_cal_client (CalendarModel *model, - CalClient *client, - CalObjType type); - -void calendar_model_set_query (CalendarModel *model, - const char *sexp); - -void calendar_model_refresh (CalendarModel *model); - -void calendar_model_set_new_comp_vtype (CalendarModel *model, - CalComponentVType vtype); -CalComponentVType calendar_model_get_new_comp_vtype (CalendarModel *model); - -void calendar_model_mark_task_complete (CalendarModel *model, - gint row); - -CalComponent* calendar_model_get_component (CalendarModel *model, - gint row); - -/* Whether we use 24 hour format to display the times. */ -gboolean calendar_model_get_use_24_hour_format (CalendarModel *model); -void calendar_model_set_use_24_hour_format (CalendarModel *model, - gboolean use_24_hour_format); - -/* The current timezone. */ -icaltimezone* calendar_model_get_timezone (CalendarModel *model); -void calendar_model_set_timezone (CalendarModel *model, - icaltimezone *zone); - -void calendar_model_set_default_category (CalendarModel *model, - const char *default_category); - -void calendar_model_set_status_message (CalendarModel *model, - const char *message); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/calendar-offline-handler.c b/calendar/gui/calendar-offline-handler.c deleted file mode 100644 index c5b742d614..0000000000 --- a/calendar/gui/calendar-offline-handler.c +++ /dev/null @@ -1,327 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* calendar-offline-handler.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: - * Ettore Perazzoli <ettore@ximian.com> - * Dan Winship <danw@ximian.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtkmain.h> -#include <gtk/gtksignal.h> -#include <bonobo/bonobo-exception.h> -#include <gal/util/e-util.h> -#include "e-util/e-url.h" -#include <cal-client/cal-client.h> -#include "calendar-offline-handler.h" - -#define PARENT_TYPE bonobo_object_get_type () -static BonoboObjectClass *parent_class = NULL; - -struct _CalendarOfflineHandlerPrivate { - CalClient *client; - - GNOME_Evolution_OfflineProgressListener listener_interface; - - gboolean is_offline; -}; - -static void -add_connection (gpointer data, gpointer user_data) -{ - EUri *uri = e_uri_new (data); - GNOME_Evolution_ConnectionList *list = user_data; - - g_return_if_fail (uri != NULL); - - if (uri->host != NULL) - list->_buffer[list->_length].hostName = CORBA_string_dup (uri->host); - else - list->_buffer[list->_length].hostName = CORBA_string_dup ("Unknown"); - if (uri->protocol != NULL) - list->_buffer[list->_length].type = CORBA_string_dup (uri->protocol); - else - list->_buffer[list->_length].type = CORBA_string_dup ("Unknown"); - list->_length++; - - e_uri_free (uri); -} - -static GNOME_Evolution_ConnectionList * -create_connection_list (CalendarOfflineHandler *offline_handler) -{ - CalendarOfflineHandlerPrivate *priv; - GNOME_Evolution_ConnectionList *list; - GList *uris; - - priv = offline_handler->priv; - - uris = cal_client_uri_list (priv->client, CAL_MODE_REMOTE); - - list = GNOME_Evolution_ConnectionList__alloc (); - list->_length = 0; - list->_maximum = g_list_length (uris); - list->_buffer = CORBA_sequence_GNOME_Evolution_Connection_allocbuf (list->_maximum); - - g_list_foreach (uris, add_connection, list); - - return list; -} - -/* GNOME::Evolution::Offline methods. */ -static CORBA_boolean -impl__get_isOffline (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - - offline_handler = CALENDAR_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - return priv->is_offline; -} - -static void -impl_prepareForOffline (PortableServer_Servant servant, - GNOME_Evolution_ConnectionList **active_connection_list, - CORBA_Environment *ev) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - - offline_handler = CALENDAR_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - *active_connection_list = create_connection_list (offline_handler); -} - -static void -update_offline (CalendarOfflineHandler *offline_handler) -{ - CalendarOfflineHandlerPrivate *priv; - GNOME_Evolution_ConnectionList *connection_list; - CORBA_Environment ev; - - priv = offline_handler->priv; - - connection_list = create_connection_list (offline_handler); - - CORBA_exception_init (&ev); - - GNOME_Evolution_OfflineProgressListener_updateProgress (priv->listener_interface, - connection_list, &ev); - - if (BONOBO_EX (&ev)) - g_warning ("Error updating offline progress"); - - CORBA_exception_free (&ev); -} - -static void -backend_cal_set_mode (CalClient *client, CalClientSetModeStatus status, CalMode mode, gpointer data) -{ - CalendarOfflineHandler *offline_handler = data; - - update_offline (offline_handler); -} - -static void -backend_cal_opened_offline (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - CalendarOfflineHandler *offline_handler = data; - - if (status != CAL_CLIENT_OPEN_SUCCESS) { - update_offline (offline_handler); - g_object_unref (client); - return; - } - - g_signal_connect (client, "cal_set_mode", G_CALLBACK (backend_cal_set_mode), offline_handler); - cal_client_set_mode (client, CAL_MODE_LOCAL); -} - -static void -backend_cal_opened_online (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - CalendarOfflineHandler *offline_handler = data; - - if (status != CAL_CLIENT_OPEN_SUCCESS) { - g_object_unref (G_OBJECT (client)); - return; - } - - cal_client_set_mode (client, CAL_MODE_REMOTE); -} - -static void -backend_go_offline (gpointer data, gpointer user_data) -{ - CalendarOfflineHandler *offline_handler = user_data; - char *uri = data; - CalClient *client; - gboolean success; - - client = cal_client_new (); - g_signal_connect (client, "cal_opened", G_CALLBACK (backend_cal_opened_offline), offline_handler); - success = cal_client_open_calendar (client, uri, TRUE); - if (!success) { - update_offline (offline_handler); - g_object_unref (client); - return; - } -} - -static void -backend_go_online (gpointer data, gpointer user_data) -{ - CalendarOfflineHandler *offline_handler = user_data; - char *uri = data; - CalClient *client; - gboolean success; - - client = cal_client_new (); - g_signal_connect (G_OBJECT (client), "cal_opened", - G_CALLBACK (backend_cal_opened_online), offline_handler); - success = cal_client_open_calendar (client, uri, TRUE); - if (!success) { - g_object_unref (G_OBJECT (client)); - return; - } -} - -static void -impl_goOffline (PortableServer_Servant servant, - const GNOME_Evolution_OfflineProgressListener progress_listener, - CORBA_Environment *ev) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - GList *uris; - - offline_handler = CALENDAR_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - /* To update the status */ - priv->listener_interface = CORBA_Object_duplicate (progress_listener, ev); - - uris = cal_client_uri_list (priv->client, CAL_MODE_REMOTE); - - g_list_foreach (uris, backend_go_offline, offline_handler); -} - -static void -impl_goOnline (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - GList *uris; - - offline_handler = CALENDAR_OFFLINE_HANDLER (bonobo_object_from_servant (servant)); - priv = offline_handler->priv; - - uris = cal_client_uri_list (priv->client, CAL_MODE_LOCAL); - - g_list_foreach (uris, backend_go_online, offline_handler); -} - -/* GObject methods. */ - -static void -impl_dispose (GObject *object) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - - offline_handler = CALENDAR_OFFLINE_HANDLER (object); - priv = offline_handler->priv; - - if (priv->listener_interface != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - CORBA_Object_release (priv->listener_interface, &ev); - CORBA_exception_free (&ev); - - priv->listener_interface = CORBA_OBJECT_NIL; - } - -} - -static void -impl_finalize (GObject *object) -{ - CalendarOfflineHandler *offline_handler; - CalendarOfflineHandlerPrivate *priv; - - offline_handler = CALENDAR_OFFLINE_HANDLER (object); - priv = offline_handler->priv; - - g_free (priv); -} - -/* GTK+ type initialization. */ - -static void -calendar_offline_handler_class_init (CalendarOfflineHandlerClass *klass) -{ - GObjectClass *object_class; - POA_GNOME_Evolution_Offline__epv *epv; - - object_class = G_OBJECT_CLASS (klass); - object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; - - epv = & klass->epv; - epv->_get_isOffline = impl__get_isOffline; - epv->prepareForOffline = impl_prepareForOffline; - epv->goOffline = impl_goOffline; - epv->goOnline = impl_goOnline; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -static void -calendar_offline_handler_init (CalendarOfflineHandler *offline_handler) -{ - CalendarOfflineHandlerPrivate *priv; - - priv = g_new (CalendarOfflineHandlerPrivate, 1); - offline_handler->priv = priv; - - priv->client = cal_client_new (); - priv->listener_interface = CORBA_OBJECT_NIL; - priv->is_offline = FALSE; -} - -CalendarOfflineHandler * -calendar_offline_handler_new (void) -{ - CalendarOfflineHandler *new; - - new = g_object_new (calendar_offline_handler_get_type (), NULL); - - return new; -} - -BONOBO_TYPE_FUNC_FULL (CalendarOfflineHandler, GNOME_Evolution_Offline, PARENT_TYPE, calendar_offline_handler); diff --git a/calendar/gui/calendar-offline-handler.h b/calendar/gui/calendar-offline-handler.h deleted file mode 100644 index 3cc61b4f25..0000000000 --- a/calendar/gui/calendar-offline-handler.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* calendar-offline-handler.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _CALENDAR_OFFLINE_HANDLER_H_ -#define _CALENDAR_OFFLINE_HANDLER_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <bonobo/bonobo-object.h> -#include "Evolution.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define CALENDAR_TYPE_OFFLINE_HANDLER (calendar_offline_handler_get_type ()) -#define CALENDAR_OFFLINE_HANDLER(obj) (GTK_CHECK_CAST ((obj), CALENDAR_TYPE_OFFLINE_HANDLER, CalendarOfflineHandler)) -#define CALENDAR_OFFLINE_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CALENDAR_TYPE_OFFLINE_HANDLER, CalendarOfflineHandlerClass)) -#define CALENDAR_IS_OFFLINE_HANDLER(obj) (GTK_CHECK_TYPE ((obj), CALENDAR_TYPE_OFFLINE_HANDLER)) -#define CALENDAR_IS_OFFLINE_HANDLER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), CALENDAR_TYPE_OFFLINE_HANDLER)) - - -typedef struct _CalendarOfflineHandler CalendarOfflineHandler; -typedef struct _CalendarOfflineHandlerPrivate CalendarOfflineHandlerPrivate; -typedef struct _CalendarOfflineHandlerClass CalendarOfflineHandlerClass; - -struct _CalendarOfflineHandler { - BonoboObject parent; - - CalendarOfflineHandlerPrivate *priv; -}; - -struct _CalendarOfflineHandlerClass { - BonoboObjectClass parent_class; - - POA_GNOME_Evolution_Offline__epv epv; -}; - - -GtkType calendar_offline_handler_get_type (void); -CalendarOfflineHandler *calendar_offline_handler_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _CALENDAR_OFFLINE_HANDLER_H_ */ diff --git a/calendar/gui/calendar-view-factory.c b/calendar/gui/calendar-view-factory.c deleted file mode 100644 index f8d2d92ce3..0000000000 --- a/calendar/gui/calendar-view-factory.c +++ /dev/null @@ -1,222 +0,0 @@ -/* Evolution calendar - Generic view factory for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include "calendar-view-factory.h" -#include "calendar-view.h" - - - -/* Private part of the CalendarViewFactory structure */ -struct _CalendarViewFactoryPrivate { - /* Type of views created by this factory */ - GnomeCalendarViewType view_type; -}; - - - -static void calendar_view_factory_class_init (CalendarViewFactoryClass *class); -static void calendar_view_factory_init (CalendarViewFactory *cal_view_factory); -static void calendar_view_factory_finalize (GObject *object); - -static const char *calendar_view_factory_get_title (GalViewFactory *factory); -static const char *calendar_view_factory_get_type_code (GalViewFactory *factory); -static GalView *calendar_view_factory_new_view (GalViewFactory *factory, const char *name); - -static GalViewFactoryClass *parent_class = NULL; - - - -E_MAKE_TYPE (calendar_view_factory, "CalendarViewFactory", CalendarViewFactory, - calendar_view_factory_class_init, calendar_view_factory_init, GAL_VIEW_FACTORY_TYPE); - -/* Class initialization function for the calendar view factory */ -static void -calendar_view_factory_class_init (CalendarViewFactoryClass *class) -{ - GalViewFactoryClass *gal_view_factory_class; - GObjectClass *gobject_class; - - parent_class = g_type_class_peek_parent (class); - - gal_view_factory_class = (GalViewFactoryClass *) class; - gobject_class = (GObjectClass *) class; - - gal_view_factory_class->get_title = calendar_view_factory_get_title; - gal_view_factory_class->get_type_code = calendar_view_factory_get_type_code; - gal_view_factory_class->new_view = calendar_view_factory_new_view; - - gobject_class->finalize = calendar_view_factory_finalize; -} - -/* Object initialization class for the calendar view factory */ -static void -calendar_view_factory_init (CalendarViewFactory *cal_view_factory) -{ - CalendarViewFactoryPrivate *priv; - - priv = g_new0 (CalendarViewFactoryPrivate, 1); - cal_view_factory->priv = priv; -} - -/* Finalize method for the calendar view factory */ -static void -calendar_view_factory_finalize (GObject *object) -{ - CalendarViewFactory *cal_view_factory; - CalendarViewFactoryPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_CALENDAR_VIEW_FACTORY (object)); - - cal_view_factory = CALENDAR_VIEW_FACTORY (object); - priv = cal_view_factory->priv; - - g_free (priv); - cal_view_factory->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_title method for the calendar view factory */ -static const char * -calendar_view_factory_get_title (GalViewFactory *factory) -{ - CalendarViewFactory *cal_view_factory; - CalendarViewFactoryPrivate *priv; - - cal_view_factory = CALENDAR_VIEW_FACTORY (factory); - priv = cal_view_factory->priv; - - switch (priv->view_type) { - case GNOME_CAL_DAY_VIEW: - return _("Day View"); - - case GNOME_CAL_WORK_WEEK_VIEW: - return _("Work Week View"); - - case GNOME_CAL_WEEK_VIEW: - return _("Week View"); - - case GNOME_CAL_MONTH_VIEW: - return _("Month View"); - - default: - g_assert_not_reached (); - return NULL; - } -} - -/* get_type_code method for the calendar view factory */ -static const char * -calendar_view_factory_get_type_code (GalViewFactory *factory) -{ - CalendarViewFactory *cal_view_factory; - CalendarViewFactoryPrivate *priv; - - cal_view_factory = CALENDAR_VIEW_FACTORY (factory); - priv = cal_view_factory->priv; - - switch (priv->view_type) { - case GNOME_CAL_DAY_VIEW: - return "day_view"; - - case GNOME_CAL_WORK_WEEK_VIEW: - return "work_week_view"; - - case GNOME_CAL_WEEK_VIEW: - return "week_view"; - - case GNOME_CAL_MONTH_VIEW: - return "month_view"; - - default: - g_assert_not_reached (); - return NULL; - } -} - -/* new_view method for the calendar view factory */ -static GalView * -calendar_view_factory_new_view (GalViewFactory *factory, const char *name) -{ - CalendarViewFactory *cal_view_factory; - CalendarViewFactoryPrivate *priv; - CalendarView *cal_view; - - cal_view_factory = CALENDAR_VIEW_FACTORY (factory); - priv = cal_view_factory->priv; - - cal_view = calendar_view_new (priv->view_type, name); - return GAL_VIEW (cal_view); -} - - - -/** - * calendar_view_factory_construct: - * @cal_view_factory: A calendar view factory. - * @view_type: Type of calendar views that the factory will create. - * - * Constructs a calendar view factory by setting the type of views it will - * create. - * - * Return value: The same value as @cal_view_factory. - **/ -CalendarViewFactory * -calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, - GnomeCalendarViewType view_type) -{ - CalendarViewFactoryPrivate *priv; - - g_return_val_if_fail (cal_view_factory != NULL, NULL); - g_return_val_if_fail (IS_CALENDAR_VIEW_FACTORY (cal_view_factory), NULL); - - priv = cal_view_factory->priv; - - priv->view_type = view_type; - - return cal_view_factory; -} - -/** - * calendar_view_factory_new: - * @view_type: Type of calendar views that the factory will create. - * - * Creates a new factory for calendar views. - * - * Return value: A newly-created calendar view factory. - **/ -CalendarViewFactory * -calendar_view_factory_new (GnomeCalendarViewType view_type) -{ - CalendarViewFactory *cal_view_factory; - - cal_view_factory = g_object_new (TYPE_CALENDAR_VIEW_FACTORY, NULL); - return calendar_view_factory_construct (cal_view_factory, view_type); -} diff --git a/calendar/gui/calendar-view-factory.h b/calendar/gui/calendar-view-factory.h deleted file mode 100644 index 6d1de25590..0000000000 --- a/calendar/gui/calendar-view-factory.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Evolution calendar - Generic view factory for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CALENDAR_VIEW_FACTORY_H -#define CALENDAR_VIEW_FACTORY_H - -#include <gal/menus/gal-view-factory.h> -#include "gnome-cal.h" - -G_BEGIN_DECLS - - - -#define TYPE_CALENDAR_VIEW_FACTORY (calendar_view_factory_get_type ()) -#define CALENDAR_VIEW_FACTORY(obj) (GTK_CHECK_CAST ((obj), TYPE_CALENDAR_VIEW_FACTORY, \ - CalendarViewFactory)) -#define CALENDAR_VIEW_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), \ - TYPE_CALENDAR_VIEW_FACTORY, CalendarViewClass)) -#define IS_CALENDAR_VIEW_FACTORY(obj) (GTK_CHECK_TYPE ((obj), TYPE_CALENDAR_VIEW_FACTORY)) -#define IS_CALENDAR_VIEW_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), \ - TYPE_CALENDAR_VIEW_FACTORY)) - -typedef struct _CalendarViewFactoryPrivate CalendarViewFactoryPrivate; - -typedef struct { - GalViewFactory factory; - - /* Private data */ - CalendarViewFactoryPrivate *priv; -} CalendarViewFactory; - -typedef struct { - GalViewFactoryClass parent_class; -} CalendarViewFactoryClass; - -GtkType calendar_view_factory_get_type (void); - -CalendarViewFactory *calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, - GnomeCalendarViewType view_type); - -CalendarViewFactory *calendar_view_factory_new (GnomeCalendarViewType view_type); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/calendar-view.c b/calendar/gui/calendar-view.c deleted file mode 100644 index 1aec23ef36..0000000000 --- a/calendar/gui/calendar-view.c +++ /dev/null @@ -1,288 +0,0 @@ -/* Evolution calendar - Generic view object for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "calendar-view.h" - - - -/* Private part of the CalendarView structure */ -struct _CalendarViewPrivate { - /* Type of the view */ - GnomeCalendarViewType view_type; - - /* Title of the view */ - char *title; -}; - - - -static void calendar_view_class_init (CalendarViewClass *class); -static void calendar_view_init (CalendarView *cview); -static void calendar_view_finalize (GObject *object); - -static void calendar_view_edit (GalView *view, GtkWindow *parent_window); -static void calendar_view_load (GalView *view, const char *filename); -static void calendar_view_save (GalView *view, const char *filename); -static const char *calendar_view_get_title (GalView *view); -static void calendar_view_set_title (GalView *view, const char *title); -static const char *calendar_view_get_type_code (GalView *view); -static GalView *calendar_view_clone (GalView *view); - -static GalViewClass *parent_class = NULL; - - - -E_MAKE_TYPE (calendar_view, "CalendarView", CalendarView, calendar_view_class_init, - calendar_view_init, GAL_VIEW_TYPE); - -/* Class initialization function for the calendar view */ -static void -calendar_view_class_init (CalendarViewClass *class) -{ - GalViewClass *gal_view_class; - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - - gal_view_class = (GalViewClass *) class; - object_class = (GObjectClass *) class; - - gal_view_class->edit = calendar_view_edit; - gal_view_class->load = calendar_view_load; - gal_view_class->save = calendar_view_save; - gal_view_class->get_title = calendar_view_get_title; - gal_view_class->set_title = calendar_view_set_title; - gal_view_class->get_type_code = calendar_view_get_type_code; - gal_view_class->clone = calendar_view_clone; - - object_class->finalize = calendar_view_finalize; -} - -/* Object initialization function for the calendar view */ -static void -calendar_view_init (CalendarView *cal_view) -{ - CalendarViewPrivate *priv; - - priv = g_new0 (CalendarViewPrivate, 1); - cal_view->priv = priv; - - priv->title = NULL; -} - -/* Destroy method for the calendar view */ -static void -calendar_view_finalize (GObject *object) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_CALENDAR_VIEW (object)); - - cal_view = CALENDAR_VIEW (object); - priv = cal_view->priv; - - if (priv->title) { - g_free (priv->title); - priv->title = NULL; - } - - g_free (priv); - cal_view->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* edit method of the calendar view */ -static void -calendar_view_edit (GalView *view, GtkWindow *parent_window) -{ - /* nothing */ -} - -/* load method of the calendar view */ -static void -calendar_view_load (GalView *view, const char *filename) -{ - /* nothing */ -} - -/* save method of the calendar view */ -static void -calendar_view_save (GalView *view, const char *filename) -{ - /* nothing */ -} - -/* get_title method of the calendar view */ -static const char * -calendar_view_get_title (GalView *view) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - return priv->title; -} - -/* set_title method of the calendar view */ -static void -calendar_view_set_title (GalView *view, const char *title) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - if (priv->title) - g_free (priv->title); - - priv->title = g_strdup (title); -} - -/* get_type_code method for the calendar view */ -static const char * -calendar_view_get_type_code (GalView *view) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - switch (priv->view_type) { - case GNOME_CAL_DAY_VIEW: - return "day_view"; - - case GNOME_CAL_WORK_WEEK_VIEW: - return "work_week_view"; - - case GNOME_CAL_WEEK_VIEW: - return "week_view"; - - case GNOME_CAL_MONTH_VIEW: - return "month_view"; - - default: - g_assert_not_reached (); - return NULL; - } -} - -/* clone method for the calendar view */ -static GalView * -calendar_view_clone (GalView *view) -{ - CalendarView *cal_view; - CalendarViewPrivate *priv; - CalendarView *new_view; - CalendarViewPrivate *new_priv; - - cal_view = CALENDAR_VIEW (view); - priv = cal_view->priv; - - new_view = g_object_new (TYPE_CALENDAR_VIEW, NULL); - new_priv = new_view->priv; - - new_priv->view_type = priv->view_type; - new_priv->title = g_strdup (priv->title); - - return GAL_VIEW (new_view); -} - - - -/** - * calendar_view_construct: - * @cal_view: A calendar view. - * @view_type: The type of calendar view that this object will represent. - * @title: Title for the view. - * - * Constructs a calendar view by setting its view type and title. - * - * Return value: The same value as @cal_view. - **/ -CalendarView * -calendar_view_construct (CalendarView *cal_view, - GnomeCalendarViewType view_type, - const char *title) -{ - CalendarViewPrivate *priv; - - g_return_val_if_fail (cal_view != NULL, NULL); - g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), NULL); - g_return_val_if_fail (title != NULL, NULL); - - priv = cal_view->priv; - - priv->view_type = view_type; - priv->title = g_strdup (title); - - return cal_view; -} - -/** - * calendar_view_new: - * @view_type: The type of calendar view that this object will represent. - * @title: Title for the view. - * - * Creates a new calendar view object. - * - * Return value: A newly-created calendar view. - **/ -CalendarView * -calendar_view_new (GnomeCalendarViewType view_type, const char *title) -{ - CalendarView *cal_view; - - cal_view = g_object_new (TYPE_CALENDAR_VIEW, NULL); - return calendar_view_construct (cal_view, view_type, title); -} - -/** - * calendar_view_get_view_type: - * @cal_view: A calendar view. - * - * Queries the calendar view type of a calendar view. - * - * Return value: Type of calendar view. - **/ -GnomeCalendarViewType -calendar_view_get_view_type (CalendarView *cal_view) -{ - CalendarViewPrivate *priv; - - g_return_val_if_fail (cal_view != NULL, GNOME_CAL_DAY_VIEW); - g_return_val_if_fail (IS_CALENDAR_VIEW (cal_view), GNOME_CAL_DAY_VIEW); - - priv = cal_view->priv; - return priv->view_type; -} diff --git a/calendar/gui/calendar-view.h b/calendar/gui/calendar-view.h deleted file mode 100644 index 8b85966a90..0000000000 --- a/calendar/gui/calendar-view.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Evolution calendar - Generic view object for calendar views - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CALENDAR_VIEW_H -#define CALENDAR_VIEW_H - -#include <gal/menus/gal-view.h> -#include "gnome-cal.h" - -G_BEGIN_DECLS - - - -#define TYPE_CALENDAR_VIEW (calendar_view_get_type ()) -#define CALENDAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_CALENDAR_VIEW, CalendarView)) -#define CALENDAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_CALENDAR_VIEW, \ - CalendarViewClass)) -#define IS_CALENDAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_CALENDAR_VIEW)) -#define IS_CALENDAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_CALENDAR_VIEW)) - -typedef struct _CalendarViewPrivate CalendarViewPrivate; - -typedef struct { - GalView view; - - /* Private data */ - CalendarViewPrivate *priv; -} CalendarView; - -typedef struct { - GalViewClass parent_class; -} CalendarViewClass; - -GtkType calendar_view_get_type (void); - -CalendarView *calendar_view_construct (CalendarView *cal_view, - GnomeCalendarViewType view_type, - const char *title); - -CalendarView *calendar_view_new (GnomeCalendarViewType view_type, - const char *title); - -GnomeCalendarViewType calendar_view_get_view_type (CalendarView *cal_view); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/comp-editor-factory.c b/calendar/gui/comp-editor-factory.c deleted file mode 100644 index 6c40a0d644..0000000000 --- a/calendar/gui/comp-editor-factory.c +++ /dev/null @@ -1,665 +0,0 @@ -/* Evolution calendar - Component editor factory object - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtkmessagedialog.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-i18n.h> -#include <evolution-calendar.h> -#include <e-util/e-url.h> -#include <cal-client/cal-client.h> -#include "calendar-config.h" -#include "e-comp-editor-registry.h" -#include "comp-editor-factory.h" -#include "comp-util.h" -#include "dialogs/event-editor.h" -#include "dialogs/task-editor.h" - -extern ECompEditorRegistry *comp_editor_registry; - - - -/* A pending request */ - -typedef enum { - REQUEST_EXISTING, - REQUEST_NEW -} RequestType; - -typedef struct { - RequestType type; - - union { - struct { - char *uid; - } existing; - - struct { - GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type; - } new; - } u; -} Request; - -/* A client we have open */ -typedef struct { - /* Our parent CompEditorFactory */ - CompEditorFactory *factory; - - /* Uri of the calendar, used as key in the clients hash table */ - char *uri; - - /* Client of the calendar */ - CalClient *client; - - /* Count editors using this client */ - int editor_count; - - /* Pending requests; they are pending if the client is still being opened */ - GSList *pending; - - /* Whether this is open or still waiting */ - guint open : 1; -} OpenClient; - -/* Private part of the CompEditorFactory structure */ -struct CompEditorFactoryPrivate { - /* Hash table of URI->OpenClient */ - GHashTable *uri_client_hash; -}; - - - -static void comp_editor_factory_class_init (CompEditorFactoryClass *class); -static void comp_editor_factory_init (CompEditorFactory *factory); -static void comp_editor_factory_finalize (GObject *object); - -static void impl_editExisting (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CalObjUID uid, - CORBA_Environment *ev); -static void impl_editNew (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CalObjType type, - CORBA_Environment *ev); - -static BonoboObjectClass *parent_class = NULL; - - - -BONOBO_TYPE_FUNC_FULL (CompEditorFactory, - GNOME_Evolution_Calendar_CompEditorFactory, - BONOBO_OBJECT_TYPE, - comp_editor_factory); - -/* Class initialization function for the component editor factory */ -static void -comp_editor_factory_class_init (CompEditorFactoryClass *class) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) class; - - parent_class = g_type_class_peek_parent (class); - - class->epv.editExisting = impl_editExisting; - class->epv.editNew = impl_editNew; - - object_class->finalize = comp_editor_factory_finalize; -} - -/* Object initialization function for the component editor factory */ -static void -comp_editor_factory_init (CompEditorFactory *factory) -{ - CompEditorFactoryPrivate *priv; - - priv = g_new (CompEditorFactoryPrivate, 1); - factory->priv = priv; - - priv->uri_client_hash = g_hash_table_new (g_str_hash, g_str_equal); -} - -/* Frees a Request structure */ -static void -free_request (Request *r) -{ - if (r->type == REQUEST_EXISTING) { - g_assert (r->u.existing.uid != NULL); - g_free (r->u.existing.uid); - } - - g_free (r); -} - -/* Frees an OpenClient structure */ -static void -free_client (OpenClient *oc) -{ - GSList *l; - - g_free (oc->uri); - oc->uri = NULL; - - g_object_unref (oc->client); - oc->client = NULL; - - for (l = oc->pending; l; l = l->next) { - Request *r; - - r = l->data; - free_request (r); - } - g_slist_free (oc->pending); - oc->pending = NULL; - - g_free (oc); -} - -/* Used from g_hash_table_foreach(); frees a client structure */ -static void -free_client_cb (gpointer key, gpointer value, gpointer data) -{ - OpenClient *oc; - - oc = value; - free_client (oc); -} - -/* Destroy handler for the component editor factory */ -static void -comp_editor_factory_finalize (GObject *object) -{ - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_COMP_EDITOR_FACTORY (object)); - - factory = COMP_EDITOR_FACTORY (object); - priv = factory->priv; - - g_hash_table_foreach (priv->uri_client_hash, free_client_cb, NULL); - g_hash_table_destroy (priv->uri_client_hash); - priv->uri_client_hash = NULL; - - g_free (priv); - factory->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* Callback used when a component editor gets destroyed */ -static void -editor_destroy_cb (GtkObject *object, gpointer data) -{ - OpenClient *oc; - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - - oc = data; - factory = oc->factory; - priv = factory->priv; - - oc->editor_count--; - - /* See if we need to free the client */ - g_assert (oc->pending == NULL); - - if (oc->editor_count != 0) - return; - - g_hash_table_remove (priv->uri_client_hash, oc->uri); - free_client (oc); -} - -/* Starts editing an existing component on a client that is already open */ -static void -edit_existing (OpenClient *oc, const char *uid) -{ - CalComponent *comp; - CalClientGetStatus status; - CompEditor *editor; - CalComponentVType vtype; - - g_assert (oc->open); - - /* Get the object */ - - status = cal_client_get_object (oc->client, uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* see below */ - break; - - case CAL_CLIENT_GET_NOT_FOUND: - /* The object disappeared from the server */ - return; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("edit_exiting(): Syntax error while getting component `%s'", uid); - return; - - default: - g_assert_not_reached (); - return; - } - - /* Create the appropriate type of editor */ - - vtype = cal_component_get_vtype (comp); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - editor = COMP_EDITOR (event_editor_new (oc->client)); - break; - - case CAL_COMPONENT_TODO: - editor = COMP_EDITOR (task_editor_new (oc->client)); - break; - - default: - g_message ("edit_exiting(): Unsupported object type %d", (int) vtype); - g_object_unref (comp); - return; - } - - /* Set the object on the editor */ - comp_editor_edit_comp (editor, comp); - comp_editor_focus (editor); - - oc->editor_count++; - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), oc); - - e_comp_editor_registry_add (comp_editor_registry, editor, TRUE); -} - -/* Creates a component with the appropriate defaults for the specified component - * type. - */ -static CalComponent * -get_default_event (CalClient *client, gboolean all_day) -{ - CalComponent *comp; - struct icaltimetype itt; - CalComponentDateTime dt; - char *location; - icaltimezone *zone; - - comp = cal_comp_event_new_with_defaults (client); - - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - if (all_day) { - itt = icaltime_from_timet_with_zone (time (NULL), 1, zone); - - dt.value = &itt; - dt.tzid = icaltimezone_get_tzid (zone); - - cal_component_set_dtstart (comp, &dt); - cal_component_set_dtend (comp, &dt); - } else { - itt = icaltime_current_time_with_zone (zone); - icaltime_adjust (&itt, 0, 1, -itt.minute, -itt.second); - - dt.value = &itt; - dt.tzid = icaltimezone_get_tzid (zone); - - cal_component_set_dtstart (comp, &dt); - icaltime_adjust (&itt, 0, 1, 0, 0); - cal_component_set_dtend (comp, &dt); - } - - cal_component_commit_sequence (comp); - - return comp; -} - -static CalComponent * -get_default_task (CalClient *client) -{ - CalComponent *comp; - - comp = cal_comp_task_new_with_defaults (client); - - return comp; -} - -/* Edits a new object in the context of a client */ -static void -edit_new (OpenClient *oc, const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type) -{ - CalComponent *comp; - CompEditor *editor; - - switch (type) { - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT: - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING: - editor = COMP_EDITOR (event_editor_new (oc->client)); - comp = get_default_event (oc->client, FALSE); - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_ALLDAY_EVENT: - editor = COMP_EDITOR (event_editor_new (oc->client)); - comp = get_default_event (oc->client, TRUE); - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO: - editor = COMP_EDITOR (task_editor_new (oc->client)); - comp = get_default_task (oc->client); - break; - default: - g_assert_not_reached (); - return; - } - - comp_editor_edit_comp (editor, comp); - if (type == GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING) - event_editor_show_meeting (EVENT_EDITOR (editor)); - comp_editor_focus (editor); - - oc->editor_count++; - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), oc); - - e_comp_editor_registry_add (comp_editor_registry, editor, TRUE); -} - -/* Resolves all the pending requests for a client */ -static void -resolve_pending_requests (OpenClient *oc) -{ - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - GSList *l; - char *location; - icaltimezone *zone; - - factory = oc->factory; - priv = factory->priv; - - g_assert (oc->pending != NULL); - - /* Set the default timezone in the backend. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - if (zone) - cal_client_set_default_timezone (oc->client, zone); - - for (l = oc->pending; l; l = l->next) { - Request *request; - - request = l->data; - - switch (request->type) { - case REQUEST_EXISTING: - edit_existing (oc, request->u.existing.uid); - break; - - case REQUEST_NEW: - edit_new (oc, request->u.new.type); - break; - } - - free_request (request); - } - - g_slist_free (oc->pending); - oc->pending = NULL; -} - -/* Callback used when a client is finished opening. We resolve all the pending - * requests. - */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - OpenClient *oc; - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - GtkWidget *dialog = NULL; - - oc = data; - factory = oc->factory; - priv = factory->priv; - - switch (status) { - case CAL_CLIENT_OPEN_SUCCESS: - oc->open = TRUE; - resolve_pending_requests (oc); - return; - - case CAL_CLIENT_OPEN_ERROR: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Error while opening the calendar")); - break; - - case CAL_CLIENT_OPEN_NOT_FOUND: - /* bullshit; we specified only_if_exists = FALSE */ - g_assert_not_reached (); - return; - - case CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Method not supported when opening the calendar")); - break; - - case CAL_CLIENT_OPEN_PERMISSION_DENIED : - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("Permission denied to open the calendar")); - break; - - default: - g_assert_not_reached (); - return; - } - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_hash_table_remove (priv->uri_client_hash, oc->uri); - free_client (oc); -} - -/* Creates a new OpenClient structure and queues the component editing/creation - * process until the client is open. Returns NULL if it could not issue the - * open request. - */ -static OpenClient * -open_client (CompEditorFactory *factory, const char *uristr) -{ - CompEditorFactoryPrivate *priv; - CalClient *client; - OpenClient *oc; - - priv = factory->priv; - - client = cal_client_new (); - if (!client) - return NULL; - - oc = g_new (OpenClient, 1); - oc->factory = factory; - - oc->uri = g_strdup (uristr); - - oc->client = client; - oc->editor_count = 0; - oc->pending = NULL; - oc->open = FALSE; - - g_signal_connect (oc->client, "cal_opened", G_CALLBACK (cal_opened_cb), oc); - - g_hash_table_insert (priv->uri_client_hash, oc->uri, oc); - - if (!cal_client_open_calendar (oc->client, uristr, FALSE)) { - g_free (oc->uri); - g_object_unref (oc->client); - g_free (oc); - - return NULL; - } - - return oc; -} - -/* Looks up an open client or queues it for being opened. Returns the client or - * NULL on failure; in the latter case it sets the ev exception. - */ -static OpenClient * -lookup_open_client (CompEditorFactory *factory, const char *str_uri, CORBA_Environment *ev) -{ - CompEditorFactoryPrivate *priv; - OpenClient *oc; - EUri *uri; - - priv = factory->priv; - - /* Look up the client */ - - uri = e_uri_new (str_uri); - if (!uri) { - bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CompEditorFactory_InvalidURI); - return NULL; - } - e_uri_free (uri); - - oc = g_hash_table_lookup (priv->uri_client_hash, str_uri); - if (!oc) { - oc = open_client (factory, str_uri); - if (!oc) { - bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CompEditorFactory_BackendContactError); - return NULL; - } - } - - return oc; -} - -/* Queues a request for editing an existing object */ -static void -queue_edit_existing (OpenClient *oc, const char *uid) -{ - Request *request; - - g_assert (!oc->open); - - request = g_new (Request, 1); - request->type = REQUEST_EXISTING; - request->u.existing.uid = g_strdup (uid); - - oc->pending = g_slist_append (oc->pending, request); -} - -/* ::editExisting() method implementation */ -static void -impl_editExisting (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CalObjUID uid, - CORBA_Environment *ev) -{ - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - OpenClient *oc; - CompEditor *editor; - - factory = COMP_EDITOR_FACTORY (bonobo_object_from_servant (servant)); - priv = factory->priv; - - oc = lookup_open_client (factory, str_uri, ev); - if (!oc) - return; - - if (!oc->open) { - queue_edit_existing (oc, uid); - return; - } - - /* Look up the component */ - editor = e_comp_editor_registry_find (comp_editor_registry, uid); - if (editor == NULL) { - edit_existing (oc, uid); - } else { - comp_editor_focus (editor); - } -} - -/* Queues a request for creating a new object */ -static void -queue_edit_new (OpenClient *oc, const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type) -{ - Request *request; - - g_assert (!oc->open); - - request = g_new (Request, 1); - request->type = REQUEST_NEW; - request->u.new.type = type; - - oc->pending = g_slist_append (oc->pending, request); -} - -/* ::editNew() method implementation */ -static void -impl_editNew (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode corba_type, - CORBA_Environment *ev) -{ - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - OpenClient *oc; - - factory = COMP_EDITOR_FACTORY (bonobo_object_from_servant (servant)); - priv = factory->priv; - - oc = lookup_open_client (factory, str_uri, ev); - if (!oc) - return; - - if (!oc->open) - queue_edit_new (oc, corba_type); - else - edit_new (oc, corba_type); -} - - - -/** - * comp_editor_factory_new: - * - * Creates a new calendar component editor factory. - * - * Return value: A newly-created component editor factory. - **/ -CompEditorFactory * -comp_editor_factory_new (void) -{ - return g_object_new (TYPE_COMP_EDITOR_FACTORY, NULL); -} - - diff --git a/calendar/gui/comp-editor-factory.h b/calendar/gui/comp-editor-factory.h deleted file mode 100644 index fca4573497..0000000000 --- a/calendar/gui/comp-editor-factory.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Evolution calendar - Component editor factory object - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 COMP_EDITOR_FACTORY_H -#define COMP_EDITOR_FACTORY_H - -#include <bonobo/bonobo-object.h> -#include "evolution-calendar.h" - - - -#define TYPE_COMP_EDITOR_FACTORY (comp_editor_factory_get_type ()) -#define COMP_EDITOR_FACTORY(obj) (GTK_CHECK_CAST ((obj), TYPE_COMP_EDITOR_FACTORY, \ - CompEditorFactory)) -#define COMP_EDITOR_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), \ - TYPE_COMP_EDITOR_FACTORY, CompEditorFactoryClass)) -#define IS_COMP_EDITOR_FACTORY(obj) (GTK_CHECK_TYPE ((obj), TYPE_COMP_EDITOR_FACTORY)) -#define IS_COMP_EDITOR_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_COMP_EDITOR_FACTORY)) - -typedef struct CompEditorFactoryPrivate CompEditorFactoryPrivate; - -typedef struct { - BonoboObject object; - - /* Private data */ - CompEditorFactoryPrivate *priv; -} CompEditorFactory; - -typedef struct { - BonoboObjectClass parent_class; - - POA_GNOME_Evolution_Calendar_CompEditorFactory__epv epv; -} CompEditorFactoryClass; - -GtkType comp_editor_factory_get_type (void); - -CompEditorFactory *comp_editor_factory_new (void); - - - -#endif diff --git a/calendar/gui/comp-util.c b/calendar/gui/comp-util.c deleted file mode 100644 index fc3496be67..0000000000 --- a/calendar/gui/comp-util.c +++ /dev/null @@ -1,333 +0,0 @@ -/* Evolution calendar - Utilities for manipulating CalComponent objects - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include "calendar-config.h" -#include "comp-util.h" -#include "dialogs/delete-comp.h" - - - -/** - * cal_comp_util_add_exdate: - * @comp: A calendar component object. - * @itt: Time for the exception. - * - * Adds an exception date to the current list of EXDATE properties in a calendar - * component object. - **/ -void -cal_comp_util_add_exdate (CalComponent *comp, time_t t, icaltimezone *zone) -{ - GSList *list; - CalComponentDateTime *cdt; - - g_return_if_fail (comp != NULL); - g_return_if_fail (IS_CAL_COMPONENT (comp)); - - cal_component_get_exdate_list (comp, &list); - - cdt = g_new (CalComponentDateTime, 1); - cdt->value = g_new (struct icaltimetype, 1); - *cdt->value = icaltime_from_timet_with_zone (t, FALSE, zone); - cdt->tzid = g_strdup (icaltimezone_get_tzid (zone)); - - list = g_slist_append (list, cdt); - cal_component_set_exdate_list (comp, list); - cal_component_free_exdate_list (list); -} - - - -/* Returns TRUE if the TZIDs are equivalent, i.e. both NULL or the same. */ -static gboolean -cal_component_compare_tzid (const char *tzid1, const char *tzid2) -{ - gboolean retval = TRUE; - - if (tzid1) { - if (!tzid2 || strcmp (tzid1, tzid2)) - retval = FALSE; - } else { - if (tzid2) - retval = FALSE; - } - - return retval; -} - -/** - * cal_comp_util_compare_event_timezones: - * @comp: A calendar component object. - * @client: A #CalClient. - * - * Checks if the component uses the given timezone for both the start and - * the end time, or if the UTC offsets of the start and end times are the same - * as in the given zone. - * - * Returns: TRUE if the component's start and end time are at the same UTC - * offset in the given timezone. - **/ -gboolean -cal_comp_util_compare_event_timezones (CalComponent *comp, - CalClient *client, - icaltimezone *zone) -{ - CalClientGetStatus status; - CalComponentDateTime start_datetime, end_datetime; - const char *tzid; - gboolean retval = FALSE; - icaltimezone *start_zone, *end_zone; - int offset1, offset2; - - tzid = icaltimezone_get_tzid (zone); - - cal_component_get_dtstart (comp, &start_datetime); - cal_component_get_dtend (comp, &end_datetime); - - /* If either the DTSTART or the DTEND is a DATE value, we return TRUE. - Maybe if one was a DATE-TIME we should check that, but that should - not happen often. */ - if ((start_datetime.value && start_datetime.value->is_date) - || (end_datetime.value && end_datetime.value->is_date)) { - retval = TRUE; - goto out; - } - - /* If the event uses UTC for DTSTART & DTEND, return TRUE. Outlook - will send single events as UTC, so we don't want to mark all of - these. */ - if ((!start_datetime.value || start_datetime.value->is_utc) - && (!end_datetime.value || end_datetime.value->is_utc)) { - retval = TRUE; - goto out; - } - - /* If the event uses floating time for DTSTART & DTEND, return TRUE. - Imported vCalendar files will use floating times, so we don't want - to mark all of these. */ - if (!start_datetime.tzid && !end_datetime.tzid) { - retval = TRUE; - goto out; - } - - /* FIXME: DURATION may be used instead. */ - if (cal_component_compare_tzid (tzid, start_datetime.tzid) - && cal_component_compare_tzid (tzid, end_datetime.tzid)) { - /* If both TZIDs are the same as the given zone's TZID, then - we know the timezones are the same so we return TRUE. */ - retval = TRUE; - } else { - /* If the TZIDs differ, we have to compare the UTC offsets - of the start and end times, using their own timezones and - the given timezone. */ - status = cal_client_get_timezone (client, - start_datetime.tzid, - &start_zone); - if (status != CAL_CLIENT_GET_SUCCESS) - goto out; - - if (start_datetime.value) { - offset1 = icaltimezone_get_utc_offset (start_zone, - start_datetime.value, - NULL); - offset2 = icaltimezone_get_utc_offset (zone, - start_datetime.value, - NULL); - if (offset1 != offset2) - goto out; - } - - status = cal_client_get_timezone (client, - end_datetime.tzid, - &end_zone); - if (status != CAL_CLIENT_GET_SUCCESS) - goto out; - - if (end_datetime.value) { - offset1 = icaltimezone_get_utc_offset (end_zone, - end_datetime.value, - NULL); - offset2 = icaltimezone_get_utc_offset (zone, - end_datetime.value, - NULL); - if (offset1 != offset2) - goto out; - } - - retval = TRUE; - } - - out: - - cal_component_free_datetime (&start_datetime); - cal_component_free_datetime (&end_datetime); - - return retval; -} - -/** - * cal_comp_confirm_delete_empty_comp: - * @comp: A calendar component. - * @client: Calendar client where the component purportedly lives. - * @widget: Widget to be used as the basis for UTF8 conversion. - * - * Assumming a calendar component with an empty SUMMARY property (as per - * string_is_empty()), asks whether the user wants to delete it based on - * whether the appointment is on the calendar server or not. If the - * component is on the server, this function will present a confirmation - * dialog and delete the component if the user tells it to. If the component - * is not on the server it will just return TRUE. - * - * Return value: A result code indicating whether the component - * was not on the server and is to be deleted locally, whether it - * was on the server and the user deleted it, or whether the - * user cancelled the deletion. - **/ -gboolean -cal_comp_is_on_server (CalComponent *comp, CalClient *client) -{ - const char *uid; - CalClientGetStatus status; - CalComponent *server_comp; - - g_return_val_if_fail (comp != NULL, FALSE); - g_return_val_if_fail (IS_CAL_COMPONENT (comp), FALSE); - g_return_val_if_fail (client != NULL, FALSE); - g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); - - /* See if the component is on the server. If it is not, then it likely - * means that the appointment is new, only in the day view, and we - * haven't added it yet to the server. In that case, we don't need to - * confirm and we can just delete the event. Otherwise, we ask - * the user. - */ - cal_component_get_uid (comp, &uid); - - status = cal_client_get_object (client, uid, &server_comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - g_object_unref (server_comp); - return TRUE; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("confirm_delete_empty_appointment(): Syntax error when getting " - "object `%s'", - uid); - return TRUE; - - case CAL_CLIENT_GET_NOT_FOUND: - return FALSE; - - default: - g_assert_not_reached (); - } - - return FALSE; -} - -/** - * cal_comp_event_new_with_defaults: - * - * Creates a new VEVENT component and adds any default alarms to it as set in - * the program's configuration values. - * - * Return value: A newly-created calendar component. - **/ -CalComponent * -cal_comp_event_new_with_defaults (CalClient *client) -{ - CalComponent *comp; - int interval; - CalUnits units; - CalComponentAlarm *alarm; - icalcomponent *icalcomp; - icalproperty *icalprop; - CalAlarmTrigger trigger; - - if (cal_client_get_default_object (client, CALOBJ_TYPE_EVENT, &comp) != CAL_CLIENT_GET_SUCCESS) - return NULL; - - if (!calendar_config_get_use_default_reminder ()) - return comp; - - interval = calendar_config_get_default_reminder_interval (); - units = calendar_config_get_default_reminder_units (); - - alarm = cal_component_alarm_new (); - - /* We don't set the description of the alarm; we'll copy it from the - * summary when it gets committed to the server. For that, we add a - * X-EVOLUTION-NEEDS-DESCRIPTION property to the alarm's component. - */ - icalcomp = cal_component_alarm_get_icalcomponent (alarm); - icalprop = icalproperty_new_x ("1"); - icalproperty_set_x_name (icalprop, "X-EVOLUTION-NEEDS-DESCRIPTION"); - icalcomponent_add_property (icalcomp, icalprop); - - cal_component_alarm_set_action (alarm, CAL_ALARM_DISPLAY); - - trigger.type = CAL_ALARM_TRIGGER_RELATIVE_START; - - memset (&trigger.u.rel_duration, 0, sizeof (trigger.u.rel_duration)); - - trigger.u.rel_duration.is_neg = TRUE; - - switch (units) { - case CAL_MINUTES: - trigger.u.rel_duration.minutes = interval; - break; - - case CAL_HOURS: - trigger.u.rel_duration.hours = interval; - break; - - case CAL_DAYS: - trigger.u.rel_duration.days = interval; - break; - - default: - g_assert_not_reached (); - } - - cal_component_alarm_set_trigger (alarm, trigger); - - cal_component_add_alarm (comp, alarm); - cal_component_alarm_free (alarm); - - return comp; -} - -CalComponent * -cal_comp_task_new_with_defaults (CalClient *client) -{ - CalComponent *comp; - - if (cal_client_get_default_object (client, CALOBJ_TYPE_TODO, &comp) != CAL_CLIENT_GET_SUCCESS) - return NULL; - - return comp; -} diff --git a/calendar/gui/comp-util.h b/calendar/gui/comp-util.h deleted file mode 100644 index c3326fbaa3..0000000000 --- a/calendar/gui/comp-util.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Evolution calendar - Utilities for manipulating CalComponent objects - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 COMP_UTIL_H -#define COMP_UTIL_H - -#include <gtk/gtkwidget.h> -#include <cal-util/cal-component.h> -#include <cal-client/cal-client.h> - -void cal_comp_util_add_exdate (CalComponent *comp, time_t t, icaltimezone *zone); - - -/* Returns TRUE if the component uses the given timezone for both DTSTART - and DTEND, or if the UTC offsets of the start and end times are the same - as in the given zone. */ -gboolean cal_comp_util_compare_event_timezones (CalComponent *comp, - CalClient *client, - icaltimezone *zone); - -gboolean cal_comp_is_on_server (CalComponent *comp, - CalClient *client); - -CalComponent *cal_comp_event_new_with_defaults (CalClient *client); -CalComponent *cal_comp_task_new_with_defaults (CalClient *client); - -#endif diff --git a/calendar/gui/control-factory.c b/calendar/gui/control-factory.c deleted file mode 100644 index 413077de14..0000000000 --- a/calendar/gui/control-factory.c +++ /dev/null @@ -1,203 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* control-factory.c - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <glade/glade.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-persist-file.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-property-bag.h> -#include <glade/glade.h> - -#include <cal-util/timeutil.h> -#include <gui/gnome-cal.h> -#include <gui/calendar-commands.h> - -#include "control-factory.h" - -#define PROPERTY_CALENDAR_URI "folder_uri" -#define PROPERTY_CALENDAR_URI_IDX 1 - -#define PROPERTY_CALENDAR_VIEW "view" -#define PROPERTY_CALENDAR_VIEW_IDX 2 - - -CORBA_Environment ev; -CORBA_ORB orb; - -static void -control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - if (activate) - calendar_control_activate (control, gcal); - else - calendar_control_deactivate (control, gcal); -} - -static void -get_prop (BonoboPropertyBag *bag, - BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - GnomeCalendar *gcal = user_data; - const char *uri; - - switch (arg_id) { - - case PROPERTY_CALENDAR_URI_IDX: - uri = cal_client_get_uri (gnome_calendar_get_cal_client (gcal)); - BONOBO_ARG_SET_STRING (arg, uri); - break; - - case PROPERTY_CALENDAR_VIEW_IDX: - switch (gnome_calendar_get_view (gcal)) { - case GNOME_CAL_DAY_VIEW: - BONOBO_ARG_SET_STRING (arg, "day"); - break; - case GNOME_CAL_WEEK_VIEW: - BONOBO_ARG_SET_STRING (arg, "week"); - break; - case GNOME_CAL_WORK_WEEK_VIEW: - BONOBO_ARG_SET_STRING (arg, "workweek"); - break; - case GNOME_CAL_MONTH_VIEW: - BONOBO_ARG_SET_STRING (arg, "month"); - break; - } - break; - - default: - g_warning ("Unhandled arg %d\n", arg_id); - } -} - - -static void -set_prop (BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - GnomeCalendar *gcal = user_data; - char *string; - GnomeCalendarViewType view; - - switch (arg_id) { - case PROPERTY_CALENDAR_URI_IDX: - string = BONOBO_ARG_GET_STRING (arg); - if (!gnome_calendar_open (gcal, string)) { - char *msg; - - msg = g_strdup_printf (_("Could not open the folder in '%s'"), string); - gnome_error_dialog_parented ( - msg, - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (msg); - } - break; - - case PROPERTY_CALENDAR_VIEW_IDX: - string = BONOBO_ARG_GET_STRING (arg); - if (!strcmp (string, "week")) - view = GNOME_CAL_WEEK_VIEW; - else if (!strcmp (string, "workweek")) - view = GNOME_CAL_WORK_WEEK_VIEW; - else if (!strcmp (string, "month")) - view = GNOME_CAL_MONTH_VIEW; - else if (!strcmp (string, "day")) - view = GNOME_CAL_DAY_VIEW; - else - view = calendar_config_get_default_view (); - - /* This doesn't actually work, because the GalView - * comes along and resets the view. FIXME. - */ - gnome_calendar_set_view (gcal, view, FALSE, TRUE); - break; - - default: - g_warning ("Unhandled arg %d\n", arg_id); - break; - } -} - - -static void -calendar_properties_init (GnomeCalendar *gcal, BonoboControl *control) -{ - BonoboPropertyBag *pbag; - - pbag = bonobo_property_bag_new (get_prop, set_prop, gcal); - - bonobo_property_bag_add (pbag, - PROPERTY_CALENDAR_URI, - PROPERTY_CALENDAR_URI_IDX, - BONOBO_ARG_STRING, - NULL, - _("The URI that the calendar will display"), - 0); - bonobo_property_bag_add (pbag, - PROPERTY_CALENDAR_VIEW, - PROPERTY_CALENDAR_VIEW_IDX, - BONOBO_ARG_STRING, - NULL, - _("The type of view to show"), - 0); - - bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (pbag)), NULL); - bonobo_object_unref (BONOBO_OBJECT (pbag)); -} - -BonoboControl * -control_factory_new_control (void) -{ - BonoboControl *control; - GnomeCalendar *gcal; - - gcal = new_calendar (); - if (!gcal) - return NULL; - - gtk_widget_show (GTK_WIDGET (gcal)); - - control = bonobo_control_new (GTK_WIDGET (gcal)); - if (!control) { - g_message ("control_factory_fn(): could not create the control!"); - return NULL; - } - g_object_set_data (G_OBJECT (gcal), "control", control); - - calendar_properties_init (gcal, control); - - g_signal_connect (control, "activate", G_CALLBACK (control_activate_cb), gcal); - - return control; -} diff --git a/calendar/gui/control-factory.h b/calendar/gui/control-factory.h deleted file mode 100644 index f599f7b3b8..0000000000 --- a/calendar/gui/control-factory.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* control-factory.c - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _CONTROL_FACTORY_H_ -#define _CONTROL_FACTORY_H_ - -BonoboControl *control_factory_new_control (void); - -#endif /* _CONTROL_FACTORY_H_ */ diff --git a/calendar/gui/dialogs/.cvsignore b/calendar/gui/dialogs/.cvsignore deleted file mode 100644 index 182657d5ac..0000000000 --- a/calendar/gui/dialogs/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -.deps -.pure -Makefile -Makefile.in -Evolution-Addressbook-SelectNames-common.c -Evolution-Addressbook-SelectNames-skels.c -Evolution-Addressbook-SelectNames-stubs.c -Evolution-Addressbook-SelectNames.h diff --git a/calendar/gui/dialogs/Makefile.am b/calendar/gui/dialogs/Makefile.am deleted file mode 100644 index 4bbdd90ca5..0000000000 --- a/calendar/gui/dialogs/Makefile.am +++ /dev/null @@ -1,104 +0,0 @@ -IDLS = $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl - -IDL_GENERATED_H = \ - Evolution-Addressbook-SelectNames.h -IDL_GENERATED = $(IDL_GENERATED_H) - -$(IDL_GENERATED_H): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) $(IDL_INCLUDES) \ - --nostubs --noskels --nocommon \ - $(top_srcdir)/addressbook/gui/component/select-names/Evolution-Addressbook-SelectNames.idl - -BUILT_SOURCES = $(IDL_GENERATED) - -INCLUDES = \ - -DG_LOG_DOMAIN=\"calendar-gui\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/calendar \ - -I$(top_srcdir)/calendar/cal-client \ - -I$(top_builddir)/calendar/cal-client \ - -I$(top_srcdir)/libical/src/libical \ - -I$(top_builddir)/libical/src/libical \ - -I$(top_builddir)/shell \ - -I$(top_srcdir)/shell \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_builddir)/addressbook/backend \ - -DEVOLUTION_DATADIR=\""$(datadir)"\" \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" \ - -DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \ - -DEVOLUTION_UIDIR=\""$(evolutionuidir)"\" \ - -DPREFIX=\""$(prefix)"\" \ - $(EVOLUTION_CALENDAR_CFLAGS) - -noinst_LTLIBRARIES = libcal-dialogs.la - -libcal_dialogs_la_SOURCES = \ - $(IDL_GENERATED) \ - alarm-options.c \ - alarm-options.h \ - alarm-page.c \ - alarm-page.h \ - cal-prefs-dialog.c \ - cal-prefs-dialog.h \ - cancel-comp.c \ - cancel-comp.h \ - changed-comp.c \ - changed-comp.h \ - comp-editor.c \ - comp-editor.h \ - comp-editor-page.c \ - comp-editor-page.h \ - comp-editor-util.c \ - comp-editor-util.h \ - delete-comp.c \ - delete-comp.h \ - delete-error.c \ - delete-error.h \ - e-delegate-dialog.c \ - e-delegate-dialog.h \ - event-editor.c \ - event-editor.h \ - event-page.c \ - event-page.h \ - meeting-page.c \ - meeting-page.h \ - recurrence-page.c \ - recurrence-page.h \ - recur-comp.c \ - recur-comp.h \ - save-comp.c \ - save-comp.h \ - schedule-page.c \ - schedule-page.h \ - send-comp.c \ - send-comp.h \ - task-editor.c \ - task-editor.h \ - task-details-page.c \ - task-details-page.h \ - task-page.c \ - task-page.h - -glade_DATA = \ - alarm-options.glade \ - alarm-page.glade \ - cal-prefs-dialog.glade \ - e-delegate-dialog.glade \ - event-page.glade \ - meeting-page.glade \ - recurrence-page.glade \ - schedule-page.glade \ - task-details-page.glade \ - task-page.glade - -etspec_DATA = meeting-page.etspec - -CLEANFILES = $(BUILT_SOURCES) - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) - -EXTRA_DIST = \ - $(glade_DATA) \ - $(etspec_DATA) diff --git a/calendar/gui/dialogs/alarm-options.c b/calendar/gui/dialogs/alarm-options.c deleted file mode 100644 index c201e66979..0000000000 --- a/calendar/gui/dialogs/alarm-options.c +++ /dev/null @@ -1,756 +0,0 @@ -/* Evolution calendar - Alarm options dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtktextbuffer.h> -#include <gtk/gtktextview.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-widget.h> -#include <libgnomeui/gnome-file-entry.h> -#include <glade/glade.h> -#include <ebook/e-destination.h> -#include "Evolution-Addressbook-SelectNames.h" -#include "e-util/e-dialog-widgets.h" -#include "alarm-options.h" - - - -typedef struct { - /* Glade XML data */ - GladeXML *xml; - - /* Toplevel */ - GtkWidget *toplevel; - - /* Alarm repeat widgets */ - gboolean repeat; - GtkWidget *repeat_toggle; - GtkWidget *repeat_group; - GtkWidget *repeat_quantity; - GtkWidget *repeat_value; - GtkWidget *repeat_unit; - - /* Display alarm widgets */ - GtkWidget *dalarm_group; - GtkWidget *dalarm_description; - - /* Audio alarm widgets */ - GtkWidget *aalarm_group; - GtkWidget *aalarm_attach; - - /* Mail alarm widgets */ - const char *email; - GtkWidget *malarm_group; - GtkWidget *malarm_address_group; - GtkWidget *malarm_addresses; - GtkWidget *malarm_addressbook; - GtkWidget *malarm_description; - GNOME_Evolution_Addressbook_SelectNames corba_select_names; - - /* Procedure alarm widgets */ - GtkWidget *palarm_group; - GtkWidget *palarm_program; - GtkWidget *palarm_args; -} Dialog; - -#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames" -static const char *section_name = "Send To"; - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (Dialog *dialog) -{ -#define GW(name) glade_xml_get_widget (dialog->xml, name) - - dialog->toplevel = GW ("alarm-options-toplevel"); - - dialog->repeat_toggle = GW ("repeat-toggle"); - dialog->repeat_group = GW ("repeat-group"); - dialog->repeat_quantity = GW ("repeat-quantity"); - dialog->repeat_value = GW ("repeat-value"); - dialog->repeat_unit = GW ("repeat-unit"); - - dialog->dalarm_group = GW ("dalarm-group"); - dialog->dalarm_description = GW ("dalarm-description"); - - dialog->aalarm_group = GW ("aalarm-group"); - dialog->aalarm_attach = GW ("aalarm-attach"); - - dialog->malarm_group = GW ("malarm-group"); - dialog->malarm_address_group = GW ("malarm-address-group"); - dialog->malarm_addressbook = GW ("malarm-addressbook"); - dialog->malarm_description = GW ("malarm-description"); - - dialog->palarm_group = GW ("palarm-group"); - dialog->palarm_program = GW ("palarm-program"); - dialog->palarm_args = GW ("palarm-args"); - - return (dialog->toplevel - && dialog->repeat_toggle - && dialog->repeat_group - && dialog->repeat_quantity - && dialog->repeat_value - && dialog->repeat_unit - && dialog->dalarm_group - && dialog->dalarm_description - && dialog->aalarm_group - && dialog->aalarm_attach - && dialog->malarm_group - && dialog->malarm_address_group - && dialog->malarm_addressbook - && dialog->malarm_description - && dialog->palarm_group - && dialog->palarm_program - && dialog->palarm_args); -} - -static void -addressbook_clicked_cb (GtkWidget *widget, gpointer data) -{ - Dialog *dialog = data; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_SelectNames_activateDialog (dialog->corba_select_names, - section_name, &ev); - - CORBA_exception_free (&ev); -} - -static gboolean -setup_select_names (Dialog *dialog) -{ - Bonobo_Control corba_control; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - dialog->corba_select_names = bonobo_activation_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev); - if (BONOBO_EX (&ev)) - return FALSE; - - GNOME_Evolution_Addressbook_SelectNames_addSection (dialog->corba_select_names, - section_name, section_name, &ev); - if (BONOBO_EX (&ev)) - return FALSE; - - corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (dialog->corba_select_names, - section_name, &ev); - - if (BONOBO_EX (&ev)) - return FALSE; - - CORBA_exception_free (&ev); - - dialog->malarm_addresses = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL); - gtk_widget_show (dialog->malarm_addresses); - gtk_box_pack_end_defaults (GTK_BOX (dialog->malarm_address_group), dialog->malarm_addresses); - - gtk_signal_connect (GTK_OBJECT (dialog->malarm_addressbook), "clicked", - GTK_SIGNAL_FUNC (addressbook_clicked_cb), dialog); - - return TRUE; -} - - -/* Callback used when the repeat toggle button is toggled. We sensitize the - * repeat group options as appropriate. - */ -static void -repeat_toggle_toggled_cb (GtkToggleButton *toggle, gpointer data) -{ - Dialog *dialog; - gboolean active; - - dialog = data; - - active = gtk_toggle_button_get_active (toggle); - - gtk_widget_set_sensitive (dialog->repeat_group, active); -} - -/* Hooks the widget signals */ -static void -init_widgets (Dialog *dialog) -{ - /* Alarm repeat */ - - g_signal_connect((dialog->repeat_toggle), "toggled", - G_CALLBACK (repeat_toggle_toggled_cb), dialog); -} - -/* Fills the audio alarm widgets with the values from the alarm component */ -static void -alarm_to_aalarm_widgets (Dialog *dialog, CalComponentAlarm *alarm) -{ - icalattach *attach; - const char *url; - - cal_component_alarm_get_attach (alarm, &attach); - - if (!attach) { - e_dialog_editable_set (dialog->aalarm_attach, NULL); - return; - } - - /* FIXME: this does not support inline data */ - - url = NULL; - - if (icalattach_get_is_url (attach)) - url = icalattach_get_url (attach); - else - g_message ("alarm_to_aalarm_widgets(): FIXME: we don't support inline data yet"); - - e_dialog_editable_set (dialog->aalarm_attach, url); - - icalattach_unref (attach); -} - -/* Fills the display alarm widgets with the values from the alarm component */ -static void -alarm_to_dalarm_widgets (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalComponentText description; - GtkTextBuffer *text_buffer; - - cal_component_alarm_get_description (alarm, &description); - - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description)); - gtk_text_buffer_set_text (text_buffer, description.value ? description.value : "", -1); -} - -/* Fills the mail alarm widgets with the values from the alarm component */ -static void -alarm_to_malarm_widgets (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalComponentText description; - GtkTextBuffer *text_buffer; - GSList *attendee_list, *l; - EDestination **destv; - int len, i; - - /* Recipients */ - cal_component_alarm_get_attendee_list (alarm, &attendee_list); - len = g_slist_length (attendee_list); - - if (len <= 0) { - destv = g_new0 (EDestination *, 2); - destv[0] = e_destination_new (); - e_destination_set_email (destv[0], dialog->email); - destv[1] = NULL; - len = 1; - } else { - destv = g_new0 (EDestination *, len + 1); - for (l = attendee_list, i = 0; l != NULL; l = l->next, i++) { - CalComponentAttendee *a = l->data; - EDestination *dest; - - dest = e_destination_new (); - if (a->cn != NULL && *a->cn) - e_destination_set_name (dest, a->cn); - if (a->value != NULL && *a->value) - e_destination_set_email (dest, a->value); - - destv[i] = dest; - } - destv[i] = NULL; - } - - bonobo_widget_set_property (BONOBO_WIDGET (dialog->malarm_addresses), - "destinations", e_destination_exportv (destv), NULL); - - for (i = 0; i < len; i++) - g_object_unref (GTK_OBJECT (destv[i])); - g_free (destv); - - cal_component_free_attendee_list (attendee_list); - - /* Description */ - cal_component_alarm_get_description (alarm, &description); - - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description)); - gtk_text_buffer_set_text (text_buffer, description.value ? description.value : "", -1); -} - -/* Fills the procedure alarm widgets with the values from the alarm component */ -static void -alarm_to_palarm_widgets (Dialog *dialog, CalComponentAlarm *alarm) -{ - icalattach *attach; - CalComponentText description; - - cal_component_alarm_get_attach (alarm, &attach); - cal_component_alarm_get_description (alarm, &description); - - if (attach) { - const char *url; - - if (icalattach_get_is_url (attach)) { - url = icalattach_get_url (attach); - e_dialog_editable_set (dialog->palarm_program, url); - } else - g_message ("alarm_to_palarm_widgets(): Don't know what to do with non-URL " - "attachments"); - - icalattach_unref (attach); - } - - e_dialog_editable_set (dialog->palarm_args, description.value); -} - -enum duration_units { - DUR_MINUTES, - DUR_HOURS, - DUR_DAYS -}; - -static const int duration_units_map[] = { - DUR_MINUTES, - DUR_HOURS, - DUR_DAYS, - -1 -}; - -/* Sigh. Takes an overcomplicated duration value and reduces it to its lowest - * common denominator. - */ -static void -normalize_duration (struct icaldurationtype dur, int *value, enum duration_units *units) -{ - if (dur.seconds != 0 || dur.minutes != 0) { - *value = ((((dur.weeks * 7 + dur.days) * 24 + dur.hours) * 60) + dur.minutes - + dur.seconds / 60 + ((dur.seconds % 60) >= 30 ? 1 : 0)); - *units = DUR_MINUTES; - } else if (dur.hours) { - *value = ((dur.weeks * 7) + dur.days) * 24 + dur.hours; - *units = DUR_HOURS; - } else if (dur.days != 0 || dur.weeks != 0) { - *value = dur.weeks * 7 + dur.days; - *units = DUR_DAYS; - } else { - *value = 0; - *units = DUR_MINUTES; - } -} - -/* Fills the repeat widgets with the values from the alarm component */ -static void -alarm_to_repeat_widgets (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalAlarmRepeat repeat; - int value; - enum duration_units units; - - cal_component_alarm_get_repeat (alarm, &repeat); - - /* Sensitivity */ - - if (!dialog->repeat || repeat.repetitions == 0) { - gtk_widget_set_sensitive (dialog->repeat_toggle, dialog->repeat); - gtk_widget_set_sensitive (dialog->repeat_group, FALSE); - e_dialog_toggle_set (dialog->repeat_toggle, FALSE); - return; - } - - gtk_widget_set_sensitive (dialog->repeat_group, TRUE); - e_dialog_toggle_set (dialog->repeat_toggle, TRUE); - - /* Repetitions */ - e_dialog_spin_set (dialog->repeat_quantity, repeat.repetitions); - - /* Duration */ - - normalize_duration (repeat.duration, &value, &units); - - e_dialog_spin_set (dialog->repeat_value, value); - e_dialog_option_menu_set (dialog->repeat_unit, units, duration_units_map); -} - - -/* Fills the widgets with the values from the alarm component */ -static void -alarm_to_dialog (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalAlarmAction action; - - alarm_to_repeat_widgets (dialog, alarm); - - cal_component_alarm_get_action (alarm, &action); - - switch (action) { - case CAL_ALARM_NONE: - g_assert_not_reached (); - return; - - case CAL_ALARM_AUDIO: - gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Audio Alarm Options")); - gtk_widget_show (dialog->aalarm_group); - gtk_widget_hide (dialog->dalarm_group); - gtk_widget_hide (dialog->malarm_group); - gtk_widget_hide (dialog->palarm_group); - alarm_to_aalarm_widgets (dialog, alarm); - break; - - case CAL_ALARM_DISPLAY: - gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Message Alarm Options")); - gtk_widget_hide (dialog->aalarm_group); - gtk_widget_show (dialog->dalarm_group); - gtk_widget_hide (dialog->malarm_group); - gtk_widget_hide (dialog->palarm_group); - alarm_to_dalarm_widgets (dialog, alarm); - break; - - case CAL_ALARM_EMAIL: - gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Email Alarm Options")); - gtk_widget_hide (dialog->aalarm_group); - gtk_widget_hide (dialog->dalarm_group); - gtk_widget_show (dialog->malarm_group); - gtk_widget_hide (dialog->palarm_group); - alarm_to_malarm_widgets (dialog, alarm); - break; - - case CAL_ALARM_PROCEDURE: - gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Program Alarm Options")); - gtk_widget_hide (dialog->aalarm_group); - gtk_widget_hide (dialog->dalarm_group); - gtk_widget_hide (dialog->malarm_group); - gtk_widget_show (dialog->palarm_group); - alarm_to_palarm_widgets (dialog, alarm); - break; - - case CAL_ALARM_UNKNOWN: - gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Unknown Alarm Options")); - break; - - default: - g_assert_not_reached (); - return; - } -} - - - -/* Fills the alarm data with the values from the repeat/duration widgets */ -static void -repeat_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalAlarmRepeat repeat; - - if (!e_dialog_toggle_get (dialog->repeat_toggle)) { - repeat.repetitions = 0; - - cal_component_alarm_set_repeat (alarm, repeat); - return; - } - - repeat.repetitions = e_dialog_spin_get_int (dialog->repeat_quantity); - - memset (&repeat.duration, 0, sizeof (repeat.duration)); - switch (e_dialog_option_menu_get (dialog->repeat_unit, duration_units_map)) { - case DUR_MINUTES: - repeat.duration.minutes = e_dialog_spin_get_int (dialog->repeat_value); - break; - - case DUR_HOURS: - repeat.duration.hours = e_dialog_spin_get_int (dialog->repeat_value); - break; - - case DUR_DAYS: - repeat.duration.days = e_dialog_spin_get_int (dialog->repeat_value); - break; - - default: - g_assert_not_reached (); - } - - cal_component_alarm_set_repeat (alarm, repeat); - -} - -/* Fills the audio alarm data with the values from the widgets */ -static void -aalarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - char *url; - icalattach *attach; - - url = e_dialog_editable_get (dialog->aalarm_attach); - attach = icalattach_new_from_url (url ? url : ""); - g_free (url); - - cal_component_alarm_set_attach (alarm, attach); - icalattach_unref (attach); -} - -/* Fills the display alarm data with the values from the widgets */ -static void -dalarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - char *str; - CalComponentText description; - GtkTextBuffer *text_buffer; - GtkTextIter text_iter_start, text_iter_end; - icalcomponent *icalcomp; - icalproperty *icalprop; - - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description)); - gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start); - gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end); - str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE); - - description.value = str; - description.altrep = NULL; - - cal_component_alarm_set_description (alarm, &description); - g_free (str); - - /* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that - * we don't re-set the alarm's description */ - icalcomp = cal_component_alarm_get_icalcomponent (alarm); - icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY); - while (icalprop) { - const char *x_name; - - x_name = icalproperty_get_x_name (icalprop); - if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) { - icalcomponent_remove_property (icalcomp, icalprop); - break; - } - - icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY); - } -} - -/* Fills the mail alarm data with the values from the widgets */ -static void -malarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - char *str; - CalComponentText description; - GSList *attendee_list = NULL; - EDestination **destv; - GtkTextBuffer *text_buffer; - GtkTextIter text_iter_start, text_iter_end; - icalcomponent *icalcomp; - icalproperty *icalprop; - int i; - - /* Attendees */ - bonobo_widget_get_property (BONOBO_WIDGET (dialog->malarm_addresses), "destinations", - TC_CORBA_string, &str, NULL); - destv = e_destination_importv (str); - g_free (str); - - for (i = 0; destv[i] != NULL; i++) { - EDestination *dest; - CalComponentAttendee *a; - - dest = destv[i]; - - a = g_new0 (CalComponentAttendee, 1); - a->value = e_destination_get_email (dest); - a->cn = e_destination_get_name (dest); - - attendee_list = g_slist_append (attendee_list, a); - } - - cal_component_alarm_set_attendee_list (alarm, attendee_list); - - cal_component_free_attendee_list (attendee_list); - e_destination_freev (destv); - - /* Description */ - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description)); - gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start); - gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end); - str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE); - - description.value = str; - description.altrep = NULL; - - cal_component_alarm_set_description (alarm, &description); - g_free (str); - - /* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that - * we don't re-set the alarm's description */ - icalcomp = cal_component_alarm_get_icalcomponent (alarm); - icalprop = icalcomponent_get_first_property(icalcomp, ICAL_X_PROPERTY); - while (icalprop) { - const char *x_name; - - x_name = icalproperty_get_x_name (icalprop); - if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) { - icalcomponent_remove_property (icalcomp, icalprop); - break; - } - - icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY); - } -} - -/* Fills the procedure alarm data with the values from the widgets */ -static void -palarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - char *program; - icalattach *attach; - char *str; - CalComponentText description; - icalcomponent *icalcomp; - icalproperty *icalprop; - - program = e_dialog_editable_get (dialog->palarm_program); - attach = icalattach_new_from_url (program ? program : ""); - g_free (program); - - cal_component_alarm_set_attach (alarm, attach); - icalattach_unref (attach); - - str = e_dialog_editable_get (dialog->palarm_args); - description.value = str; - description.altrep = NULL; - - cal_component_alarm_set_description (alarm, &description); - g_free (str); - - /* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that - * we don't re-set the alarm's description */ - icalcomp = cal_component_alarm_get_icalcomponent (alarm); - icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY); - while (icalprop) { - const char *x_name; - - x_name = icalproperty_get_x_name (icalprop); - if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) { - icalcomponent_remove_property (icalcomp, icalprop); - break; - } - - icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY); - } -} - -/* Fills the alarm data with the values from the widgets */ -static void -dialog_to_alarm (Dialog *dialog, CalComponentAlarm *alarm) -{ - CalAlarmAction action; - - repeat_widgets_to_alarm (dialog, alarm); - - cal_component_alarm_get_action (alarm, &action); - - switch (action) { - case CAL_ALARM_NONE: - g_assert_not_reached (); - break; - - case CAL_ALARM_AUDIO: - aalarm_widgets_to_alarm (dialog, alarm); - break; - - case CAL_ALARM_DISPLAY: - dalarm_widgets_to_alarm (dialog, alarm); - break; - - case CAL_ALARM_EMAIL: - malarm_widgets_to_alarm (dialog, alarm); - break; - - case CAL_ALARM_PROCEDURE: - palarm_widgets_to_alarm (dialog, alarm); - break; - - case CAL_ALARM_UNKNOWN: - break; - - default: - g_assert_not_reached (); - } -} - - - -/** - * alarm_options_dialog_run: - * @alarm: Alarm that is to be edited. - * - * Runs an alarm options dialog modally. - * - * Return value: TRUE if the dialog could be created, FALSE otherwise. - **/ -gboolean -alarm_options_dialog_run (CalComponentAlarm *alarm, const char *email, gboolean repeat) -{ - Dialog dialog; - int response_id; - - g_return_val_if_fail (alarm != NULL, FALSE); - - dialog.repeat = repeat; - dialog.email = email; - dialog.xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-options.glade", NULL, NULL); - if (!dialog.xml) { - g_message ("alarm_options_dialog_new(): Could not load the Glade XML file!"); - return FALSE; - } - - if (!get_widgets (&dialog)) { - g_object_unref(dialog.xml); - return FALSE; - } - - if (!setup_select_names (&dialog)) { - g_object_unref (dialog.xml); - return FALSE; - } - - init_widgets (&dialog); - - alarm_to_dialog (&dialog, alarm); - - response_id = gtk_dialog_run (GTK_DIALOG (dialog.toplevel)); - gtk_widget_hide (dialog.toplevel); - - if (response_id == GTK_RESPONSE_OK) - dialog_to_alarm (&dialog, alarm); - - gtk_widget_destroy (dialog.toplevel); - g_object_unref(dialog.xml); - - return TRUE; -} diff --git a/calendar/gui/dialogs/alarm-options.glade b/calendar/gui/dialogs/alarm-options.glade deleted file mode 100644 index 47b17b662b..0000000000 --- a/calendar/gui/dialogs/alarm-options.glade +++ /dev/null @@ -1,573 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> -<requires lib="gnome"/> - -<widget class="GtkDialog" id="alarm-options-toplevel"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="title" translatable="yes">dialog1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">True</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">True</property> - <property name="has_separator">True</property> - - <child internal-child="vbox"> - <widget class="GtkVBox" id="dialog-vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child internal-child="action_area"> - <widget class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - - <child> - <widget class="GtkButton" id="cancelbutton1"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-cancel</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">-6</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="okbutton1"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-ok</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">-5</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox1"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame1"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox1"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkCheckButton" id="repeat-toggle"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="has_focus">True</property> - <property name="label" translatable="yes">Repeat the alarm</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="repeat-group"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">4</property> - - <child> - <widget class="GtkSpinButton" id="repeat-quantity"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 1 999 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">extra times every</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="repeat-value"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 0 999 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="repeat-unit"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">hours</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget4"> - <property name="visible">True</property> - <property name="label" translatable="yes">days</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Alarm Repeat</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="dalarm-group"> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label2"> - <property name="visible">True</property> - <property name="label" translatable="yes">Message to Display:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow1"> - <property name="visible">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTextView" id="dalarm-description"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="justification">GTK_JUSTIFY_LEFT</property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="cursor_visible">True</property> - <property name="pixels_above_lines">0</property> - <property name="pixels_below_lines">0</property> - <property name="pixels_inside_wrap">0</property> - <property name="left_margin">0</property> - <property name="right_margin">0</property> - <property name="indent">0</property> - <property name="text" translatable="yes"></property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="aalarm-group"> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="label" translatable="yes">Play sound:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GnomeFileEntry" id="file-entry1"> - <property name="visible">True</property> - <property name="max_saved">10</property> - <property name="directory_entry">False</property> - <property name="modal">True</property> - - <child internal-child="entry"> - <widget class="GtkEntry" id="aalarm-attach"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="malarm-group"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="malarm-address-group"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="malarm-addressbook"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Send To:</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label7"> - <property name="visible">True</property> - <property name="label" translatable="yes">Message to Send</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow2"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_NONE</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTextView" id="malarm-description"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="justification">GTK_JUSTIFY_LEFT</property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="cursor_visible">True</property> - <property name="pixels_above_lines">0</property> - <property name="pixels_below_lines">0</property> - <property name="pixels_inside_wrap">0</property> - <property name="left_margin">0</property> - <property name="right_margin">0</property> - <property name="indent">0</property> - <property name="text" translatable="yes"></property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="palarm-group"> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="label" translatable="yes">Run program:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="palarm-program"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label6"> - <property name="visible">True</property> - <property name="label" translatable="yes">With these arguments:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="palarm-args"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/alarm-options.h b/calendar/gui/dialogs/alarm-options.h deleted file mode 100644 index 1b4abb56d9..0000000000 --- a/calendar/gui/dialogs/alarm-options.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Evolution calendar - Alarm options dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_OPTIONS_H -#define ALARM_OPTIONS_H - -#include <cal-util/cal-component.h> - -gboolean alarm_options_dialog_run (CalComponentAlarm *alarm, const char *email, gboolean repeat); - -#endif diff --git a/calendar/gui/dialogs/alarm-page.c b/calendar/gui/dialogs/alarm-page.c deleted file mode 100644 index 540f11db92..0000000000 --- a/calendar/gui/dialogs/alarm-page.c +++ /dev/null @@ -1,825 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* Evolution calendar - Alarm page of the calendar component dialogs - * - * Copyright (C) 2001-2003 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * Hans Petter Jansson <hpj@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtkcellrenderertext.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktreeview.h> -#include <gtk/gtktreeselection.h> -#include <gtk/gtkoptionmenu.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include "e-util/e-dialog-widgets.h" -#include "e-util/e-time-utils.h" -#include "cal-util/cal-util.h" -#include "cal-util/timeutil.h" -#include "../calendar-config.h" -#include "comp-editor-util.h" -#include "alarm-options.h" -#include "../e-alarm-list.h" -#include "alarm-page.h" - - - -/* Private part of the AlarmPage structure */ -struct _AlarmPagePrivate { - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - - GtkWidget *main; - - GtkWidget *summary; - GtkWidget *date_time; - - GtkWidget *list; - GtkWidget *add; - GtkWidget *delete; - - GtkWidget *action; - GtkWidget *interval_value; - GtkWidget *value_units; - GtkWidget *relative; - GtkWidget *time; - - GtkWidget *button_options; - - /* Alarm options dialog and the alarm we maintain */ - CalComponentAlarm *alarm; - - /* Alarm store for the GtkTreeView list widget */ - EAlarmList *list_store; - - gboolean updating; -}; - -/* "relative" types */ -enum { - BEFORE, - AFTER -}; - -/* Time units */ -enum { - MINUTES, - HOURS, - DAYS -}; - -/* Option menu maps */ -static const int action_map[] = { - CAL_ALARM_DISPLAY, - CAL_ALARM_AUDIO, - CAL_ALARM_PROCEDURE, - CAL_ALARM_EMAIL, - -1 -}; - -static const char *action_map_cap[] = { - CAL_STATIC_CAPABILITY_NO_DISPLAY_ALARMS, - CAL_STATIC_CAPABILITY_NO_AUDIO_ALARMS, - CAL_STATIC_CAPABILITY_NO_PROCEDURE_ALARMS, - CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS -}; - -static const int value_map[] = { - MINUTES, - HOURS, - DAYS, - -1 -}; - -static const int relative_map[] = { - BEFORE, - AFTER, - -1 -}; - -static const int time_map[] = { - CAL_ALARM_TRIGGER_RELATIVE_START, - CAL_ALARM_TRIGGER_RELATIVE_END, - -1 -}; - - - -static void alarm_page_class_init (AlarmPageClass *class); -static void alarm_page_init (AlarmPage *apage); -static void alarm_page_finalize (GObject *object); - -static GtkWidget *alarm_page_get_widget (CompEditorPage *page); -static void alarm_page_focus_main_widget (CompEditorPage *page); -static void alarm_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean alarm_page_fill_component (CompEditorPage *page, CalComponent *comp); -static void alarm_page_set_summary (CompEditorPage *page, const char *summary); -static void alarm_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * alarm_page_get_type: - * - * Registers the #AlarmPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #AlarmPage class. - **/ - -E_MAKE_TYPE (alarm_page, "AlarmPage", AlarmPage, alarm_page_class_init, - alarm_page_init, TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the alarm page */ -static void -alarm_page_class_init (AlarmPageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *gobject_class; - - editor_page_class = (CompEditorPageClass *) class; - gobject_class = (GObjectClass *) class; - - parent_class = g_type_class_ref (TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = alarm_page_get_widget; - editor_page_class->focus_main_widget = alarm_page_focus_main_widget; - editor_page_class->fill_widgets = alarm_page_fill_widgets; - editor_page_class->fill_component = alarm_page_fill_component; - editor_page_class->set_summary = alarm_page_set_summary; - editor_page_class->set_dates = alarm_page_set_dates; - - gobject_class->finalize = alarm_page_finalize; -} - -/* Object initialization function for the alarm page */ -static void -alarm_page_init (AlarmPage *apage) -{ - AlarmPagePrivate *priv; - icalcomponent *icalcomp; - icalproperty *icalprop; - - priv = g_new0 (AlarmPagePrivate, 1); - apage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - priv->summary = NULL; - priv->date_time = NULL; - priv->list = NULL; - priv->add = NULL; - priv->delete = NULL; - priv->action = NULL; - priv->interval_value = NULL; - priv->value_units = NULL; - priv->relative = NULL; - priv->time = NULL; - priv->button_options = NULL; - - /* create the default alarm, which will contain the - * X-EVOLUTION-NEEDS-DESCRIPTION property, so that we - * set a correct description if none is set */ - priv->alarm = cal_component_alarm_new (); - - icalcomp = cal_component_alarm_get_icalcomponent (priv->alarm); - icalprop = icalproperty_new_x ("1"); - icalproperty_set_x_name (icalprop, "X-EVOLUTION-NEEDS-DESCRIPTION"); - icalcomponent_add_property (icalcomp, icalprop); - - priv->updating = FALSE; -} - -/* Destroy handler for the alarm page */ -static void -alarm_page_finalize (GObject *object) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_ALARM_PAGE (object)); - - apage = ALARM_PAGE (object); - priv = apage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref (priv->xml); - priv->xml = NULL; - } - - if (priv->alarm) { - cal_component_alarm_free (priv->alarm); - priv->alarm = NULL; - } - - if (priv->list_store) { - g_object_unref (priv->list_store); - priv->list_store = NULL; - } - - g_free (priv); - apage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the alarm page */ -static GtkWidget * -alarm_page_get_widget (CompEditorPage *page) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the alarm page */ -static void -alarm_page_focus_main_widget (CompEditorPage *page) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - gtk_widget_grab_focus (priv->action); -} - -/* Fills the widgets with default values */ -static void -clear_widgets (AlarmPage *apage) -{ - AlarmPagePrivate *priv; - - priv = apage->priv; - - /* Summary */ - gtk_label_set_text (GTK_LABEL (priv->summary), ""); - - /* Start date */ - gtk_label_set_text (GTK_LABEL (priv->date_time), ""); - - /* Sane defaults */ - e_dialog_option_menu_set (priv->action, CAL_ALARM_DISPLAY, action_map); - e_dialog_spin_set (priv->interval_value, 15); - e_dialog_option_menu_set (priv->value_units, MINUTES, value_map); - e_dialog_option_menu_set (priv->relative, BEFORE, relative_map); - e_dialog_option_menu_set (priv->time, CAL_ALARM_TRIGGER_RELATIVE_START, time_map); - - /* List data */ - e_alarm_list_clear (priv->list_store); -} - -static void -sensitize_buttons (AlarmPage *apage) -{ - AlarmPagePrivate *priv; - CalClient *client; - GtkTreeSelection *selection; - GtkTreeIter iter; - gboolean have_selected; - - priv = apage->priv; - - client = COMP_EDITOR_PAGE (apage)->client; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->list)); - have_selected = gtk_tree_selection_get_selected (selection, NULL, &iter); - - gtk_widget_set_sensitive (priv->add, - cal_client_get_one_alarm_only (client) && have_selected ? FALSE : TRUE); - gtk_widget_set_sensitive (priv->delete, have_selected); -} - -/* Appends an alarm to the list */ -static void -append_reminder (AlarmPage *apage, CalComponentAlarm *alarm) -{ - AlarmPagePrivate *priv; - GtkTreeView *view; - GtkTreeIter iter; - - priv = apage->priv; - view = GTK_TREE_VIEW (priv->list); - - e_alarm_list_append (priv->list_store, &iter, alarm); - gtk_tree_selection_select_iter (gtk_tree_view_get_selection (view), &iter); - - sensitize_buttons (apage); -} - -/* fill_widgets handler for the alarm page */ -static void -alarm_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - GtkWidget *menu; - CalComponentText text; - GList *alarms, *l; - CompEditorPageDates dates; - int i; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - /* Don't send off changes during this time */ - priv->updating = TRUE; - - /* Clean the page */ - clear_widgets (apage); - - /* Summary */ - cal_component_get_summary (comp, &text); - alarm_page_set_summary (page, text.value); - - /* Dates */ - comp_editor_dates (&dates, comp); - alarm_page_set_dates (page, &dates); - comp_editor_free_dates (&dates); - - /* List */ - if (!cal_component_has_alarms (comp)) - goto out; - - alarms = cal_component_get_alarm_uids (comp); - - for (l = alarms; l != NULL; l = l->next) { - CalComponentAlarm *ca, *ca_copy; - const char *auid; - - auid = l->data; - ca = cal_component_get_alarm (comp, auid); - g_assert (ca != NULL); - - ca_copy = cal_component_alarm_clone (ca); - cal_component_alarm_free (ca); - - append_reminder (apage, ca_copy); - } - cal_obj_uid_list_free (alarms); - - out: - - /* Alarm types */ - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->action)); - for (i = 0, l = GTK_MENU_SHELL (menu)->children; action_map[i] != -1; i++, l = l->next) { - if (cal_client_get_static_capability (page->client, action_map_cap[i])) - gtk_widget_set_sensitive (l->data, FALSE); - else - gtk_widget_set_sensitive (l->data, TRUE); - } - - sensitize_buttons (apage); - - priv->updating = FALSE; -} - -/* fill_component handler for the alarm page */ -static gboolean -alarm_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid_iter; - GList *list, *l; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - /* Remove all the alarms from the component */ - - list = cal_component_get_alarm_uids (comp); - for (l = list; l; l = l->next) { - const char *auid; - - auid = l->data; - cal_component_remove_alarm (comp, auid); - } - cal_obj_uid_list_free (list); - - /* Add the new alarms */ - - view = GTK_TREE_VIEW (priv->list); - model = GTK_TREE_MODEL (priv->list_store); - - for (valid_iter = gtk_tree_model_get_iter_first (model, &iter); valid_iter; - valid_iter = gtk_tree_model_iter_next (model, &iter)) { - CalComponentAlarm *alarm, *alarm_copy; - icalcomponent *icalcomp; - icalproperty *icalprop; - - alarm = (CalComponentAlarm *) e_alarm_list_get_alarm (priv->list_store, &iter); - g_assert (alarm != NULL); - - /* We set the description of the alarm if it's got - * the X-EVOLUTION-NEEDS-DESCRIPTION property. - */ - icalcomp = cal_component_alarm_get_icalcomponent (alarm); - icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY); - while (icalprop) { - const char *x_name; - CalComponentText summary; - - x_name = icalproperty_get_x_name (icalprop); - if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) { - cal_component_get_summary (comp, &summary); - cal_component_alarm_set_description (alarm, &summary); - - icalcomponent_remove_property (icalcomp, icalprop); - break; - } - - icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY); - } - - /* We clone the alarm to maintain the invariant that the alarm - * structures in the list did *not* come from the component. - */ - - alarm_copy = cal_component_alarm_clone (alarm); - cal_component_add_alarm (comp, alarm_copy); - cal_component_alarm_free (alarm_copy); - } - - return TRUE; -} - -/* set_summary handler for the alarm page */ -static void -alarm_page_set_summary (CompEditorPage *page, const char *summary) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - gtk_label_set_text (GTK_LABEL (priv->summary), summary); -} - -/* set_dates handler for the alarm page */ -static void -alarm_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - apage = ALARM_PAGE (page); - priv = apage->priv; - - comp_editor_date_label (dates, priv->date_time); -} - - - -/* Gets the widgets from the XML file and returns TRUE if they are all available. */ -static gboolean -get_widgets (AlarmPage *apage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (apage); - AlarmPagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = apage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("alarm-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - priv->summary = GW ("summary"); - priv->date_time = GW ("date-time"); - - priv->list = GW ("list"); - priv->add = GW ("add"); - priv->delete = GW ("delete"); - - priv->action = GW ("action"); - priv->interval_value = GW ("interval-value"); - priv->value_units = GW ("value-units"); - priv->relative = GW ("relative"); - priv->time = GW ("time"); - - priv->button_options = GW ("button-options"); - -#undef GW - - return (priv->summary - && priv->date_time - && priv->list - && priv->add - && priv->delete - && priv->action - && priv->interval_value - && priv->value_units - && priv->relative - && priv->time - && priv->button_options); -} - -/* This is called when any field is changed; it notifies upstream. */ -static void -field_changed_cb (GtkWidget *widget, gpointer data) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - - apage = ALARM_PAGE (data); - priv = apage->priv; - - if (!priv->updating) - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (apage)); -} - -/* Callback used for the "add reminder" button */ -static void -add_clicked_cb (GtkButton *button, gpointer data) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - CalComponentAlarm *alarm; - CalAlarmTrigger trigger; - CalAlarmAction action; - - apage = ALARM_PAGE (data); - priv = apage->priv; - - alarm = cal_component_alarm_clone (priv->alarm); - - memset (&trigger, 0, sizeof (CalAlarmTrigger)); - trigger.type = e_dialog_option_menu_get (priv->time, time_map); - if (e_dialog_option_menu_get (priv->relative, relative_map) == BEFORE) - trigger.u.rel_duration.is_neg = 1; - else - trigger.u.rel_duration.is_neg = 0; - - switch (e_dialog_option_menu_get (priv->value_units, value_map)) { - case MINUTES: - trigger.u.rel_duration.minutes = - e_dialog_spin_get_int (priv->interval_value); - break; - - case HOURS: - trigger.u.rel_duration.hours = - e_dialog_spin_get_int (priv->interval_value); - break; - - case DAYS: - trigger.u.rel_duration.days = - e_dialog_spin_get_int (priv->interval_value); - break; - - default: - g_assert_not_reached (); - } - cal_component_alarm_set_trigger (alarm, trigger); - - action = e_dialog_option_menu_get (priv->action, action_map); - cal_component_alarm_set_action (alarm, action); - if (action == CAL_ALARM_EMAIL && !cal_component_alarm_has_attendees (alarm)) { - const char *email; - - email = cal_client_get_alarm_email_address (COMP_EDITOR_PAGE (apage)->client); - if (email != NULL) { - CalComponentAttendee *a; - GSList attendee_list; - - a = g_new0 (CalComponentAttendee, 1); - a->value = email; - attendee_list.data = a; - attendee_list.next = NULL; - cal_component_alarm_set_attendee_list (alarm, &attendee_list); - g_free (a); - } - } - - append_reminder (apage, alarm); -} - -/* Callback used for the "delete reminder" button */ -static void -delete_clicked_cb (GtkButton *button, gpointer data) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreePath *path; - gboolean valid_iter; - - apage = ALARM_PAGE (data); - priv = apage->priv; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->list)); - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { - g_warning ("Could not get a selection to delete."); - return; - } - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store), &iter); - e_alarm_list_remove (priv->list_store, &iter); - - /* Select closest item after removal */ - valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path); - if (!valid_iter) { - gtk_tree_path_prev (path); - valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path); - } - - if (valid_iter) - gtk_tree_selection_select_iter (selection, &iter); - - sensitize_buttons (apage); - - gtk_tree_path_free (path); -} - -/* Callback used when the alarm options button is clicked */ -static void -button_options_clicked_cb (GtkWidget *widget, gpointer data) -{ - AlarmPage *apage; - AlarmPagePrivate *priv; - gboolean repeat; - const char *email; - - apage = ALARM_PAGE (data); - priv = apage->priv; - - cal_component_alarm_set_action (priv->alarm, - e_dialog_option_menu_get (priv->action, action_map)); - - repeat = !cal_client_get_static_capability (COMP_EDITOR_PAGE (apage)->client, - CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT); - email = cal_client_get_alarm_email_address (COMP_EDITOR_PAGE (apage)->client); - if (!alarm_options_dialog_run (priv->alarm, email, repeat)) - g_message ("button_options_clicked_cb(): Could not create the alarm options dialog"); -} - -/* Hooks the widget signals */ -static void -init_widgets (AlarmPage *apage) -{ - AlarmPagePrivate *priv; - GtkTreeViewColumn *column; - GtkCellRenderer *cell_renderer; - - priv = apage->priv; - - /* Reminder buttons */ - g_signal_connect ((priv->add), "clicked", - G_CALLBACK (add_clicked_cb), apage); - g_signal_connect ((priv->delete), "clicked", - G_CALLBACK (delete_clicked_cb), apage); - - /* Connect the default signal handler to use to make sure we notify - * upstream of changes to the widget values. - */ - g_signal_connect ((priv->add), "clicked", - G_CALLBACK (field_changed_cb), apage); - g_signal_connect ((priv->delete), "clicked", - G_CALLBACK (field_changed_cb), apage); - - /* Options button */ - g_signal_connect ((priv->button_options), "clicked", - G_CALLBACK (button_options_clicked_cb), apage); - - /* Alarm list */ - - /* Model */ - priv->list_store = e_alarm_list_new (); - gtk_tree_view_set_model (GTK_TREE_VIEW (priv->list), - GTK_TREE_MODEL (priv->list_store)); - - /* View */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, "Action/Trigger"); /* Not shown */ - cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ()); - gtk_tree_view_column_pack_start (column, cell_renderer, TRUE); - gtk_tree_view_column_add_attribute (column, cell_renderer, "text", E_ALARM_LIST_COLUMN_DESCRIPTION); - gtk_tree_view_append_column (GTK_TREE_VIEW (priv->list), column); - -#if 0 - /* If we want the alarm setup widgets to reflect the currently selected alarm, we - * need to do something like this */ - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->list)), "changed", - G_CALLBACK (alarm_selection_changed_cb), apage); -#endif -} - - - -/** - * alarm_page_construct: - * @apage: An alarm page. - * - * Constructs an alarm page by loading its Glade data. - * - * Return value: The same object as @apage, or NULL if the widgets could not be - * created. - **/ -AlarmPage * -alarm_page_construct (AlarmPage *apage) -{ - AlarmPagePrivate *priv; - - priv = apage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-page.glade", - NULL, NULL); - if (!priv->xml) { - g_message ("alarm_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (apage)) { - g_message ("alarm_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - init_widgets (apage); - - return apage; -} - -/** - * alarm_page_new: - * - * Creates a new alarm page. - * - * Return value: A newly-created alarm page, or NULL if the page could not be - * created. - **/ -AlarmPage * -alarm_page_new (void) -{ - AlarmPage *apage; - - apage = g_object_new (TYPE_ALARM_PAGE, NULL); - if (!alarm_page_construct (apage)) { - g_object_unref ((apage)); - return NULL; - } - - return apage; -} diff --git a/calendar/gui/dialogs/alarm-page.glade b/calendar/gui/dialogs/alarm-page.glade deleted file mode 100644 index 7c2f06bae3..0000000000 --- a/calendar/gui/dialogs/alarm-page.glade +++ /dev/null @@ -1,490 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="alarm-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="alarm-page"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame33"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkTable" id="table13"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label62"> - <property name="visible">True</property> - <property name="label" translatable="yes">Summary:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label63"> - <property name="visible">True</property> - <property name="label" translatable="yes">Date/Time:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="summary"> - <property name="visible">True</property> - <property name="label" translatable="yes"></property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">4</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="date-time"> - <property name="visible">True</property> - <property name="label" translatable="yes"></property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xpad">4</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Basics</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame34"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkVBox" id="vbox53"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="hbox54"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkOptionMenu" id="action"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">Display a message</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">Play a sound</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Run a program</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="send_an_email1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Send an Email</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="interval-value"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">True</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 0 999 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="value-units"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget5"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget6"> - <property name="visible">True</property> - <property name="label" translatable="yes">minute(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget7"> - <property name="visible">True</property> - <property name="label" translatable="yes">hour(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget8"> - <property name="visible">True</property> - <property name="label" translatable="yes">day(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="relative"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget9"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget10"> - <property name="visible">True</property> - <property name="label" translatable="yes">before</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget11"> - <property name="visible">True</property> - <property name="label" translatable="yes">after</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="time"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget12"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget13"> - <property name="visible">True</property> - <property name="label" translatable="yes">start of appointment</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget14"> - <property name="visible">True</property> - <property name="label" translatable="yes">end of appointment</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="button-options"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Options...</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox55"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow13"> - <property name="visible">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTreeView" id="list"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="headers_visible">True</property> - <property name="rules_hint">False</property> - <property name="reorderable">False</property> - <property name="enable_search">True</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkVButtonBox" id="vbuttonbox2"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_START</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="add"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-add</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="delete"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-remove</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label64"> - <property name="visible">True</property> - <property name="label" translatable="yes">Reminders</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/alarm-page.h b/calendar/gui/dialogs/alarm-page.h deleted file mode 100644 index d814e850b3..0000000000 --- a/calendar/gui/dialogs/alarm-page.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Evolution calendar - Alarm page of the calendar component dialogs - * - * Copyright (C) 2001-2003 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * Hans Petter Jansson <hpj@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 ALARM_PAGE_H -#define ALARM_PAGE_H - -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_ALARM_PAGE (alarm_page_get_type ()) -#define ALARM_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ALARM_PAGE, AlarmPage)) -#define ALARM_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ALARM_PAGE, AlarmPageClass)) -#define IS_ALARM_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ALARM_PAGE)) -#define IS_ALARM_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_ALARM_PAGE)) - -typedef struct _AlarmPagePrivate AlarmPagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - AlarmPagePrivate *priv; -} AlarmPage; - -typedef struct { - CompEditorPageClass parent_class; -} AlarmPageClass; - - -GtkType alarm_page_get_type (void); -AlarmPage *alarm_page_construct (AlarmPage *apage); -AlarmPage *alarm_page_new (void); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/cal-prefs-dialog.c b/calendar/gui/dialogs/cal-prefs-dialog.c deleted file mode 100644 index 9d8c8eedb2..0000000000 --- a/calendar/gui/dialogs/cal-prefs-dialog.c +++ /dev/null @@ -1,693 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Ettore Perazzoli <ettore@ximian.com> - * - * Copyright 2000, 2001, 2002 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * CalPrefsDialog - a GtkObject which handles a libglade-loaded dialog - * to edit the calendar preference settings. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "../e-timezone-entry.h" -#include "cal-prefs-dialog.h" -#include "../calendar-config.h" -#include "../calendar-commands.h" -#include "../e-tasks.h" - -#include <gtk/gtksignal.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtktogglebutton.h> -#include <libgnomeui/gnome-color-picker.h> -#include <glade/glade.h> -#include <gal/util/e-util.h> -#include <e-util/e-dialog-widgets.h> -#include <widgets/misc/e-dateedit.h> - - -struct _DialogData { - /* Glade XML data */ - GladeXML *xml; - - GtkWidget *page; - - GtkWidget *timezone; - GtkWidget *working_days[7]; - GtkWidget *week_start_day; - GtkWidget *start_of_day; - GtkWidget *end_of_day; - GtkWidget *use_12_hour; - GtkWidget *use_24_hour; - GtkWidget *time_divisions; - GtkWidget *show_end_times; - GtkWidget *compress_weekend; - GtkWidget *dnav_show_week_no; - - /* Widgets for the task list options */ - GtkWidget *tasks_due_today_color; - GtkWidget *tasks_overdue_color; - - GtkWidget *tasks_hide_completed_checkbutton; - GtkWidget *tasks_hide_completed_spinbutton; - GtkWidget *tasks_hide_completed_optionmenu; - - /* Other page options */ - GtkWidget *confirm_delete; - GtkWidget *default_reminder; - GtkWidget *default_reminder_interval; - GtkWidget *default_reminder_units; -}; -typedef struct _DialogData DialogData; - -static const int week_start_day_map[] = { - 1, 2, 3, 4, 5, 6, 0, -1 -}; - -static const int time_division_map[] = { - 60, 30, 15, 10, 5, -1 -}; - -/* The following two are kept separate in case we need to re-order each menu individually */ -static const int hide_completed_units_map[] = { - CAL_MINUTES, CAL_HOURS, CAL_DAYS, -1 -}; - -static const int default_reminder_units_map[] = { - CAL_MINUTES, CAL_HOURS, CAL_DAYS, -1 -}; - - -static gboolean get_widgets (DialogData *data); - -static void widget_changed_callback (GtkWidget *, void *data); -static void connect_changed (GtkWidget *widget, const char *signal_name, EvolutionConfigControl *config_control); -static void setup_changes (DialogData *data, EvolutionConfigControl *config_control); - -static void init_widgets (DialogData *data); -static void show_config (DialogData *data); -static void update_config (DialogData *dialog_data); - -static void config_control_apply_callback (EvolutionConfigControl *config_control, void *data); -static void config_control_destroy_callback (GtkObject *object, void *data); - -static void cal_prefs_dialog_use_24_hour_toggled(GtkWidget *button, void *data); -static void cal_prefs_dialog_end_of_day_changed (GtkWidget *button, void *data); -static void cal_prefs_dialog_start_of_day_changed (GtkWidget *button, void *data); -static void cal_prefs_dialog_hide_completed_tasks_toggled (GtkWidget *button, void *data); - -GtkWidget *cal_prefs_dialog_create_time_edit (void); - - -/** - * cal_prefs_dialog_new: - * - * Creates a new #CalPrefsDialog. - * - * Return value: a new #CalPrefsDialog. - **/ -EvolutionConfigControl * -cal_prefs_dialog_new (void) -{ - DialogData *dialog_data; - EvolutionConfigControl *config_control; - - dialog_data = g_new0 (DialogData, 1); - - /* Load the content widgets */ - - dialog_data->xml = glade_xml_new (EVOLUTION_GLADEDIR "/cal-prefs-dialog.glade", NULL, NULL); - if (!dialog_data->xml) { - g_message ("cal_prefs_dialog_construct(): Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (dialog_data)) { - g_message ("cal_prefs_dialog_construct(): Could not find all widgets in the XML file!"); - return NULL; - } - - init_widgets (dialog_data); - show_config (dialog_data); - - gtk_widget_ref (dialog_data->page); - gtk_container_remove (GTK_CONTAINER (dialog_data->page->parent), dialog_data->page); - config_control = evolution_config_control_new (dialog_data->page); - gtk_widget_unref (dialog_data->page); - - g_signal_connect((config_control), "apply", - G_CALLBACK (config_control_apply_callback), dialog_data); - g_signal_connect((config_control), "destroy", - G_CALLBACK (config_control_destroy_callback), dialog_data); - - setup_changes (dialog_data, config_control); - - return config_control; -} - -static void -widget_changed_callback (GtkWidget *widget, - void *data) -{ - EvolutionConfigControl *config_control; - - config_control = EVOLUTION_CONFIG_CONTROL (data); - - evolution_config_control_changed (config_control); -} - -/* ^*&%!!#! GnomeColorPicker. */ -static void -color_set_callback (GnomeColorPicker *cp, - guint r, - guint g, - guint b, - guint a, - void *data) -{ - EvolutionConfigControl *config_control; - - config_control = EVOLUTION_CONFIG_CONTROL (data); - - evolution_config_control_changed (config_control); -} - -static void -connect_changed (GtkWidget *widget, - const char *signal_name, - EvolutionConfigControl *config_control) -{ - g_signal_connect((widget), signal_name, - G_CALLBACK (widget_changed_callback), config_control); -} - -static void -setup_changes (DialogData *dialog_data, - EvolutionConfigControl *config_control) -{ - int i; - - for (i = 0; i < 7; i ++) - connect_changed (dialog_data->working_days[i], "toggled", config_control); - - connect_changed (dialog_data->timezone, "changed", config_control); - - connect_changed (dialog_data->start_of_day, "changed", config_control); - connect_changed (dialog_data->end_of_day, "changed", config_control); - - connect_changed (GTK_OPTION_MENU (dialog_data->week_start_day)->menu, "selection_done", config_control); - - connect_changed (dialog_data->use_12_hour, "toggled", config_control); - - connect_changed (GTK_OPTION_MENU (dialog_data->time_divisions)->menu, "selection_done", config_control); - - connect_changed (dialog_data->show_end_times, "toggled", config_control); - connect_changed (dialog_data->compress_weekend, "toggled", config_control); - connect_changed (dialog_data->dnav_show_week_no, "toggled", config_control); - - connect_changed (dialog_data->tasks_hide_completed_checkbutton, "toggled", config_control); - connect_changed (dialog_data->tasks_hide_completed_spinbutton, "changed", config_control); - connect_changed (GTK_OPTION_MENU (dialog_data->tasks_hide_completed_optionmenu)->menu, "selection_done", config_control); - - connect_changed (dialog_data->confirm_delete, "toggled", config_control); - connect_changed (dialog_data->default_reminder, "toggled", config_control); - connect_changed (dialog_data->default_reminder_interval, "changed", config_control); - connect_changed (GTK_OPTION_MENU (dialog_data->default_reminder_units)->menu, "selection_done", config_control); - - /* These use GnomeColorPicker so we have to use a different signal. */ - g_signal_connect((dialog_data->tasks_due_today_color), "color_set", - G_CALLBACK (color_set_callback), config_control); - g_signal_connect((dialog_data->tasks_overdue_color), "color_set", - G_CALLBACK (color_set_callback), config_control); -} - -/* Gets the widgets from the XML file and returns if they are all available. - */ -static gboolean -get_widgets (DialogData *data) -{ -#define GW(name) glade_xml_get_widget (data->xml, name) - - data->page = GW ("toplevel-notebook"); - - /* The indices must be 0 (Sun) to 6 (Sat). */ - data->working_days[0] = GW ("sun_button"); - data->working_days[1] = GW ("mon_button"); - data->working_days[2] = GW ("tue_button"); - data->working_days[3] = GW ("wed_button"); - data->working_days[4] = GW ("thu_button"); - data->working_days[5] = GW ("fri_button"); - data->working_days[6] = GW ("sat_button"); - - data->timezone = GW ("timezone"); - data->week_start_day = GW ("first_day_of_week"); - data->start_of_day = GW ("start_of_day"); - gtk_widget_show (data->start_of_day); - data->end_of_day = GW ("end_of_day"); - gtk_widget_show (data->end_of_day); - data->use_12_hour = GW ("use_12_hour"); - data->use_24_hour = GW ("use_24_hour"); - data->time_divisions = GW ("time_divisions"); - data->show_end_times = GW ("show_end_times"); - data->compress_weekend = GW ("compress_weekend"); - data->dnav_show_week_no = GW ("dnav_show_week_no"); - - data->tasks_due_today_color = GW ("tasks_due_today_color"); - data->tasks_overdue_color = GW ("tasks_overdue_color"); - - data->tasks_hide_completed_checkbutton = GW ("tasks-hide-completed-checkbutton"); - data->tasks_hide_completed_spinbutton = GW ("tasks-hide-completed-spinbutton"); - data->tasks_hide_completed_optionmenu = GW ("tasks-hide-completed-optionmenu"); - - data->confirm_delete = GW ("confirm-delete"); - data->default_reminder = GW ("default-reminder"); - data->default_reminder_interval = GW ("default-reminder-interval"); - data->default_reminder_units = GW ("default-reminder-units"); - -#undef GW - - return (data->page - && data->timezone - && data->working_days[0] - && data->working_days[1] - && data->working_days[2] - && data->working_days[3] - && data->working_days[4] - && data->working_days[5] - && data->working_days[6] - && data->week_start_day - && data->start_of_day - && data->end_of_day - && data->use_12_hour - && data->use_24_hour - && data->time_divisions - && data->show_end_times - && data->compress_weekend - && data->dnav_show_week_no - && data->tasks_due_today_color - && data->tasks_overdue_color - && data->tasks_hide_completed_checkbutton - && data->tasks_hide_completed_spinbutton - && data->tasks_hide_completed_optionmenu - && data->confirm_delete - && data->default_reminder - && data->default_reminder_interval - && data->default_reminder_units); -} - - -static void -config_control_destroy_callback (GtkObject *object, - void *data) -{ - DialogData *dialog_data; - - dialog_data = (DialogData *) data; - - g_object_unref((dialog_data->xml)); - - g_free (dialog_data); -} - - -static void -config_control_apply_callback (EvolutionConfigControl *control, - void *data) -{ - DialogData *dialog_data; - - dialog_data = (DialogData *) data; - - update_config (dialog_data); -} - - -/* Called by libglade to create our custom EDateEdit widgets. */ -GtkWidget * -cal_prefs_dialog_create_time_edit (void) -{ - GtkWidget *dedit; - - dedit = e_date_edit_new (); - - e_date_edit_set_use_24_hour_format (E_DATE_EDIT (dedit), calendar_config_get_24_hour_format ()); - e_date_edit_set_time_popup_range (E_DATE_EDIT (dedit), 0, 24); - e_date_edit_set_show_date (E_DATE_EDIT (dedit), FALSE); - - return dedit; -} - - -/* Connects any necessary signal handlers. */ -static void -init_widgets (DialogData *dialog_data) -{ - g_signal_connect((dialog_data->use_24_hour), "toggled", - G_CALLBACK (cal_prefs_dialog_use_24_hour_toggled), - dialog_data); - - g_signal_connect((dialog_data->start_of_day), "changed", - G_CALLBACK (cal_prefs_dialog_start_of_day_changed), - dialog_data); - - g_signal_connect((dialog_data->end_of_day), "changed", - G_CALLBACK (cal_prefs_dialog_end_of_day_changed), - dialog_data); - - g_signal_connect((dialog_data->tasks_hide_completed_checkbutton), - "toggled", - G_CALLBACK (cal_prefs_dialog_hide_completed_tasks_toggled), - dialog_data); -} - - -static void -cal_prefs_dialog_use_24_hour_toggled (GtkWidget *button, - void *data) -{ - DialogData *dialog_data; - gboolean use_24_hour; - - dialog_data = (DialogData *) data; - - use_24_hour = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog_data->use_24_hour)); - - e_date_edit_set_use_24_hour_format (E_DATE_EDIT (dialog_data->start_of_day), use_24_hour); - e_date_edit_set_use_24_hour_format (E_DATE_EDIT (dialog_data->end_of_day), use_24_hour); -} - -static void -cal_prefs_dialog_start_of_day_changed (GtkWidget *button, void *data) -{ - DialogData *dialog_data; - EDateEdit *start, *end; - int start_hour, start_minute, end_hour, end_minute; - - dialog_data = (DialogData *) data; - - start = E_DATE_EDIT (dialog_data->start_of_day); - end = E_DATE_EDIT (dialog_data->end_of_day); - - e_date_edit_get_time_of_day (start, &start_hour, &start_minute); - e_date_edit_get_time_of_day (end, &end_hour, &end_minute); - - if ((start_hour > end_hour) - || (start_hour == end_hour && start_minute > end_minute)) { - - if (start_hour < 23) - e_date_edit_set_time_of_day (end, start_hour + 1, start_minute); - else - e_date_edit_set_time_of_day (end, 23, 59); - } -} - -static void -cal_prefs_dialog_end_of_day_changed (GtkWidget *button, void *data) -{ - DialogData *dialog_data; - EDateEdit *start, *end; - int start_hour, start_minute, end_hour, end_minute; - - dialog_data = (DialogData *) data; - - start = E_DATE_EDIT (dialog_data->start_of_day); - end = E_DATE_EDIT (dialog_data->end_of_day); - - e_date_edit_get_time_of_day (start, &start_hour, &start_minute); - e_date_edit_get_time_of_day (end, &end_hour, &end_minute); - - if ((end_hour < start_hour) - || (end_hour == start_hour && end_minute < start_minute)) { - if (end_hour < 1) - e_date_edit_set_time_of_day (start, 0, 0); - else - e_date_edit_set_time_of_day (start, end_hour - 1, end_minute); - } -} - -static void -cal_prefs_dialog_hide_completed_tasks_toggled (GtkWidget *button, - void *data) -{ - DialogData *dialog_data; - gboolean hide_completed_tasks; - - dialog_data = (DialogData *) data; - - hide_completed_tasks = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog_data->tasks_hide_completed_checkbutton)); - - gtk_widget_set_sensitive (dialog_data->tasks_hide_completed_spinbutton, hide_completed_tasks); - gtk_widget_set_sensitive (dialog_data->tasks_hide_completed_optionmenu, hide_completed_tasks); -} - -/* Sets the color in a color picker from an X color spec */ -static void -set_color_picker (GtkWidget *picker, const char *spec) -{ - GdkColor color; - - g_assert (spec != NULL); - - if (!gdk_color_parse (spec, &color)) { - color.red = color.green = color.blue = 0; - return; - } - - gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (picker), - color.red, - color.green, - color.blue, - 65535); -} - -/* Shows the current task list settings in the dialog */ -static void -show_task_list_config (DialogData *dialog_data) -{ - CalUnits units; - gboolean hide_completed_tasks; - - set_color_picker (dialog_data->tasks_due_today_color, calendar_config_get_tasks_due_today_color ()); - set_color_picker (dialog_data->tasks_overdue_color, calendar_config_get_tasks_overdue_color ()); - - /* Hide Completed Tasks. */ - hide_completed_tasks = calendar_config_get_hide_completed_tasks (); - e_dialog_toggle_set (dialog_data->tasks_hide_completed_checkbutton, - hide_completed_tasks); - - /* Hide Completed Tasks Units. */ - units = calendar_config_get_hide_completed_tasks_units (); - e_dialog_option_menu_set (dialog_data->tasks_hide_completed_optionmenu, - units, hide_completed_units_map); - - /* Hide Completed Tasks Value. */ - e_dialog_spin_set (dialog_data->tasks_hide_completed_spinbutton, - calendar_config_get_hide_completed_tasks_value ()); - - gtk_widget_set_sensitive (dialog_data->tasks_hide_completed_spinbutton, - hide_completed_tasks); - gtk_widget_set_sensitive (dialog_data->tasks_hide_completed_optionmenu, - hide_completed_tasks); -} - -/* Shows the current config settings in the dialog. */ -static void -show_config (DialogData *dialog_data) -{ - CalWeekdays working_days; - gint mask, day, week_start_day, time_divisions; - char *zone_name; - icaltimezone *zone; - gboolean sensitive; - - /* Timezone. */ - zone_name = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (zone_name); - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (dialog_data->timezone), - zone); - - /* Working Days. */ - working_days = calendar_config_get_working_days (); - mask = 1 << 0; - for (day = 0; day < 7; day++) { - e_dialog_toggle_set (dialog_data->working_days[day], (working_days & mask) ? TRUE : FALSE); - mask <<= 1; - } - - /* Week Start Day. */ - week_start_day = calendar_config_get_week_start_day (); - e_dialog_option_menu_set (dialog_data->week_start_day, week_start_day, - week_start_day_map); - - /* Start of Day. */ - e_date_edit_set_time_of_day (E_DATE_EDIT (dialog_data->start_of_day), - calendar_config_get_day_start_hour (), - calendar_config_get_day_start_minute ()); - - /* End of Day. */ - e_date_edit_set_time_of_day (E_DATE_EDIT (dialog_data->end_of_day), - calendar_config_get_day_end_hour (), - calendar_config_get_day_end_minute ()); - - /* 12/24 Hour Format. */ - if (calendar_config_get_24_hour_format ()) - e_dialog_toggle_set (dialog_data->use_24_hour, TRUE); - else - e_dialog_toggle_set (dialog_data->use_12_hour, TRUE); - - sensitive = calendar_config_locale_supports_12_hour_format (); - gtk_widget_set_sensitive (dialog_data->use_12_hour, sensitive); - gtk_widget_set_sensitive (dialog_data->use_24_hour, sensitive); - - - /* Time Divisions. */ - time_divisions = calendar_config_get_time_divisions (); - e_dialog_option_menu_set (dialog_data->time_divisions, time_divisions, - time_division_map); - - /* Show Appointment End Times. */ - e_dialog_toggle_set (dialog_data->show_end_times, calendar_config_get_show_event_end ()); - - /* Compress Weekend. */ - e_dialog_toggle_set (dialog_data->compress_weekend, calendar_config_get_compress_weekend ()); - - /* Date Navigator - Show Week Numbers. */ - e_dialog_toggle_set (dialog_data->dnav_show_week_no, calendar_config_get_dnav_show_week_no ()); - - /* Task list */ - - show_task_list_config (dialog_data); - - /* Other page */ - - e_dialog_toggle_set (dialog_data->confirm_delete, calendar_config_get_confirm_delete ()); - - e_dialog_toggle_set (dialog_data->default_reminder, - calendar_config_get_use_default_reminder ()); - e_dialog_spin_set (dialog_data->default_reminder_interval, - calendar_config_get_default_reminder_interval ()); - e_dialog_option_menu_set (dialog_data->default_reminder_units, - calendar_config_get_default_reminder_units (), - default_reminder_units_map); -} - -/* Returns a pointer to a static string with an X color spec for the current - * value of a color picker. - */ -static const char * -spec_from_picker (GtkWidget *picker) -{ - static char spec[8]; - guint8 r, g, b; - - gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (picker), &r, &g, &b, NULL); - g_snprintf (spec, sizeof (spec), "#%02x%02x%02x", r, g, b); - - return spec; -} - -/* Updates the task list config values from the settings in the dialog */ -static void -update_task_list_config (DialogData *dialog_data) -{ - calendar_config_set_tasks_due_today_color (spec_from_picker (dialog_data->tasks_due_today_color)); - calendar_config_set_tasks_overdue_color (spec_from_picker (dialog_data->tasks_overdue_color)); - - calendar_config_set_hide_completed_tasks (e_dialog_toggle_get (dialog_data->tasks_hide_completed_checkbutton)); - calendar_config_set_hide_completed_tasks_units (e_dialog_option_menu_get (dialog_data->tasks_hide_completed_optionmenu, hide_completed_units_map)); - calendar_config_set_hide_completed_tasks_value (e_dialog_spin_get_int (dialog_data->tasks_hide_completed_spinbutton)); -} - -/* Updates the config values based on the settings in the dialog. */ -static void -update_config (DialogData *dialog_data) -{ - CalWeekdays working_days; - gint mask, day, week_start_day, time_divisions, hour, minute; - icaltimezone *zone; - - /* Timezone. */ - zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (dialog_data->timezone)); - calendar_config_set_timezone (icaltimezone_get_location (zone)); - - /* Working Days. */ - working_days = 0; - mask = 1 << 0; - for (day = 0; day < 7; day++) { - if (e_dialog_toggle_get (dialog_data->working_days[day])) - working_days |= mask; - mask <<= 1; - } - calendar_config_set_working_days (working_days); - - /* Week Start Day. */ - week_start_day = e_dialog_option_menu_get (dialog_data->week_start_day, week_start_day_map); - calendar_config_set_week_start_day (week_start_day); - - /* Start of Day. */ - e_date_edit_get_time_of_day (E_DATE_EDIT (dialog_data->start_of_day), &hour, &minute); - calendar_config_set_day_start_hour (hour); - calendar_config_set_day_start_minute (minute); - - /* End of Day. */ - e_date_edit_get_time_of_day (E_DATE_EDIT (dialog_data->end_of_day), &hour, &minute); - calendar_config_set_day_end_hour (hour); - calendar_config_set_day_end_minute (minute); - - /* 12/24 Hour Format. */ - calendar_config_set_24_hour_format (e_dialog_toggle_get (dialog_data->use_24_hour)); - - /* Time Divisions. */ - time_divisions = e_dialog_option_menu_get (dialog_data->time_divisions, time_division_map); - calendar_config_set_time_divisions (time_divisions); - - /* Show Appointment End Times. */ - calendar_config_set_show_event_end (e_dialog_toggle_get (dialog_data->show_end_times)); - - /* Compress Weekend. */ - calendar_config_set_compress_weekend (e_dialog_toggle_get (dialog_data->compress_weekend)); - - /* Date Navigator - Show Week Numbers. */ - calendar_config_set_dnav_show_week_no (e_dialog_toggle_get (dialog_data->dnav_show_week_no)); - - /* Task list */ - update_task_list_config (dialog_data); - - /* Other page */ - - calendar_config_set_confirm_delete (e_dialog_toggle_get (dialog_data->confirm_delete)); - - calendar_config_set_use_default_reminder (e_dialog_toggle_get (dialog_data->default_reminder)); - - calendar_config_set_default_reminder_interval ( - e_dialog_spin_get_int (dialog_data->default_reminder_interval)); - - calendar_config_set_default_reminder_units ( - e_dialog_option_menu_get (dialog_data->default_reminder_units, default_reminder_units_map)); - - /* Done */ - - update_all_config_settings (); - e_tasks_update_all_config_settings (); -} diff --git a/calendar/gui/dialogs/cal-prefs-dialog.glade b/calendar/gui/dialogs/cal-prefs-dialog.glade deleted file mode 100644 index ff79e2cb2b..0000000000 --- a/calendar/gui/dialogs/cal-prefs-dialog.glade +++ /dev/null @@ -1,1317 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> -<requires lib="gnome"/> - -<widget class="GtkDialog" id="cal-prefs-dialog"> - <property name="title" translatable="yes">Calendar and Tasks Settings</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - <property name="has_separator">True</property> - - <child internal-child="vbox"> - <widget class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child internal-child="action_area"> - <widget class="GtkHButtonBox" id="hbuttonbox1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - - <child> - <widget class="GtkButton" id="button1"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-ok</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">0</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="button2"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-apply</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">0</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="button3"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-close</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">0</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - - <child> - <widget class="GtkNotebook" id="toplevel-notebook"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="show_tabs">True</property> - <property name="show_border">True</property> - <property name="tab_pos">GTK_POS_TOP</property> - <property name="scrollable">False</property> - <property name="enable_popup">False</property> - - <child> - <widget class="GtkVBox" id="vbox10"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame12"> - <property name="border_width">3</property> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkTable" id="table5"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">3</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label22"> - <property name="visible">True</property> - <property name="label" translatable="yes">Time _zone:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label20"> - <property name="visible">True</property> - <property name="label" translatable="yes">Time format:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox10"> - <property name="visible">True</property> - <property name="homogeneous">True</property> - <property name="spacing">4</property> - - <child> - <widget class="GtkAlignment" id="alignment2"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xscale">3.35276e-08</property> - <property name="yscale">1</property> - - <child> - <widget class="GtkRadioButton" id="use_12_hour"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_12 hour (AM/PM)</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="use_24_hour"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_24 hour</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">use_12_hour</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="Custom" id="timezone"> - <property name="visible">True</property> - <property name="creation_function">make_timezone_entry</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Wed, 20 Jun 2001 02:22:46 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">3</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Time</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame9"> - <property name="border_width">3</property> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkTable" id="table8"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">3</property> - <property name="n_columns">4</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label33"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Day begins:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox18"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">3</property> - - <child> - <widget class="Custom" id="start_of_day"> - <property name="visible">True</property> - <property name="creation_function">cal_prefs_dialog_create_time_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Thu, 30 May 2002 19:26:53 GMT</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label34"> - <property name="visible">True</property> - <property name="label" translatable="yes">Day _ends:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_RIGHT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">1</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="Custom" id="end_of_day"> - <property name="visible">True</property> - <property name="creation_function">cal_prefs_dialog_create_time_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Thu, 30 May 2002 19:27:35 GMT</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">4</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox17"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkCheckButton" id="mon_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Mon</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="tue_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Tue</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="wed_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Wed</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="thu_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">T_hu</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="fri_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Fri</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="sat_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Sat</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="sun_button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">S_un</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">4</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="alignment3"> - <property name="visible">True</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">1</property> - - <child> - <widget class="GtkOptionMenu" id="first_day_of_week"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">Monday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">Tuesday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Wednesday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget5"> - <property name="visible">True</property> - <property name="label" translatable="yes">Thursday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget6"> - <property name="visible">True</property> - <property name="label" translatable="yes">Friday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget7"> - <property name="visible">True</property> - <property name="label" translatable="yes">Saturday</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget8"> - <property name="visible">True</property> - <property name="label" translatable="yes">Sunday</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label32"> - <property name="visible">True</property> - <property name="label" translatable="yes">W_eek starts:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">first_day_of_week</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label31"> - <property name="visible">True</property> - <property name="label" translatable="yes">Work days:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label23"> - <property name="visible">True</property> - <property name="label" translatable="yes">Work Week</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame14"> - <property name="border_width">3</property> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkVBox" id="vbox13"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkCheckButton" id="confirm-delete"> - <property name="border_width">3</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Ask for confirmation when deleting items</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox19"> - <property name="border_width">3</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">3</property> - - <child> - <widget class="GtkCheckButton" id="default-reminder"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Sh_ow a reminder</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="default-reminder-interval"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">0 0 9999 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="alignment4"> - <property name="visible">True</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - - <child> - <widget class="GtkOptionMenu" id="default-reminder-units"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget9"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget10"> - <property name="visible">True</property> - <property name="label" translatable="yes">Minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget11"> - <property name="visible">True</property> - <property name="label" translatable="yes">Hours</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget12"> - <property name="visible">True</property> - <property name="label" translatable="yes">Days</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label35"> - <property name="visible">True</property> - <property name="label" translatable="yes">before every appointment</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label35"> - <property name="visible">True</property> - <property name="label" translatable="yes">Alerts</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="tab_expand">False</property> - <property name="tab_fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label21"> - <property name="visible">True</property> - <property name="label" translatable="yes">_General</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">tab</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox8"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="hbox12"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label25"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Time divisions:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">time_divisions</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="time_divisions"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget13"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget14"> - <property name="visible">True</property> - <property name="label" translatable="yes">60 minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget15"> - <property name="visible">True</property> - <property name="label" translatable="yes">30 minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget16"> - <property name="visible">True</property> - <property name="label" translatable="yes">15 minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget17"> - <property name="visible">True</property> - <property name="label" translatable="yes">10 minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget18"> - <property name="visible">True</property> - <property name="label" translatable="yes">05 minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="show_end_times"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Show appointment end times in week and month views</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="compress_weekend"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Compress weekends in month view</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkCheckButton" id="dnav_show_week_no"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Show week _numbers in date navigator</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame13"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkVBox" id="vbox12"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkTable" id="table7"> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label28"> - <property name="visible">True</property> - <property name="label" translatable="yes">T_asks due today:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">tasks_due_today_color</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label29"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Overdue tasks:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">tasks_overdue_color</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GnomeColorPicker" id="tasks_overdue_color"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="dither">True</property> - <property name="use_alpha">False</property> - <property name="title" translatable="yes">Color for overdue tasks</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GnomeColorPicker" id="tasks_due_today_color"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="dither">True</property> - <property name="use_alpha">False</property> - <property name="title" translatable="yes">Color for tasks due today</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox15"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkCheckButton" id="tasks-hide-completed-checkbutton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Hide completed tasks after</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="tasks-hide-completed-spinbutton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 0 9999 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="tasks-hide-completed-optionmenu"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget19"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget20"> - <property name="visible">True</property> - <property name="label" translatable="yes">Minutes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget21"> - <property name="visible">True</property> - <property name="label" translatable="yes">Hours</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget22"> - <property name="visible">True</property> - <property name="label" translatable="yes">Days</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label36"> - <property name="visible">True</property> - <property name="label" translatable="yes">Task List</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="tab_expand">False</property> - <property name="tab_fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label7"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Display</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">tab</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/cal-prefs-dialog.h b/calendar/gui/dialogs/cal-prefs-dialog.h deleted file mode 100644 index db6f5a75fa..0000000000 --- a/calendar/gui/dialogs/cal-prefs-dialog.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2000, Ximian, Inc. - * Copyright 2000, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * CalPrefsDialog - a GtkObject which handles a libglade-loaded dialog - * to edit the calendar preference settings. - */ - -#ifndef _CAL_PREFS_DIALOG_H_ -#define _CAL_PREFS_DIALOG_H_ - -#include "evolution-config-control.h" - -G_BEGIN_DECLS - -EvolutionConfigControl *cal_prefs_dialog_new (void); - -G_END_DECLS - -#endif /* _CAL_PREFS_DIALOG_H_ */ diff --git a/calendar/gui/dialogs/cancel-comp.c b/calendar/gui/dialogs/cancel-comp.c deleted file mode 100644 index 0e48dd3763..0000000000 --- a/calendar/gui/dialogs/cancel-comp.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtkmessagedialog.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-uidefs.h> -#include <gal/widgets/e-unicode.h> -#include "cancel-comp.h" - - - -/** - * cancel_component_dialog: - * - * Pops up a dialog box asking the user whether he wants to send a - * cancel and delete an iTip/iMip message - * - * Return value: TRUE if the user clicked Yes, FALSE otherwise. - **/ -gboolean -cancel_component_dialog (CalClient *client, CalComponent *comp, gboolean deleting) -{ - GtkWidget *dialog; - CalComponentVType vtype; - char *str; - gint response; - - if (deleting && cal_client_get_save_schedules (client)) - return TRUE; - - vtype = cal_component_get_vtype (comp); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - if (deleting) - str = g_strdup_printf (_("The event being deleted is a meeting, " - "would you like to send a cancellation notice?")); - else - str = g_strdup_printf (_("Are you sure you want to cancel " - "and delete this meeting?")); - break; - - case CAL_COMPONENT_TODO: - if (deleting) - str = g_strdup_printf (_("The task being deleted is assigned, " - "would you like to send a cancellation notice?")); - else - str = g_strdup_printf (_("Are you sure you want to cancel " - "and delete this task?")); - break; - - case CAL_COMPONENT_JOURNAL: - if (deleting) - str = g_strdup_printf (_("The journal entry being deleted is published, " - "would you like to send a cancellation notice?")); - else - str = g_strdup_printf (_("Are you sure you want to cancel " - "and delete this journal entry?")); - break; - - default: - g_message ("send_component_dialog(): " - "Cannot handle object of type %d", vtype); - return FALSE; - } - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, str); - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - if (response == GTK_RESPONSE_YES) - return TRUE; - else - return FALSE; -} diff --git a/calendar/gui/dialogs/cancel-comp.h b/calendar/gui/dialogs/cancel-comp.h deleted file mode 100644 index 9c31a49fd8..0000000000 --- a/calendar/gui/dialogs/cancel-comp.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CANCEL_COMP_H -#define CANCEL_COMP_H - -#include <glib.h> -#include <cal-client/cal-client.h> -#include <cal-util/cal-component.h> - -gboolean cancel_component_dialog (CalClient *client, CalComponent *comp, gboolean deleting); - -#endif diff --git a/calendar/gui/dialogs/changed-comp.c b/calendar/gui/dialogs/changed-comp.c deleted file mode 100644 index 7fa2c1d0be..0000000000 --- a/calendar/gui/dialogs/changed-comp.c +++ /dev/null @@ -1,110 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-uidefs.h> -#include <gal/widgets/e-unicode.h> -#include "changed-comp.h" - - - -/** - * changed_component_dialog: - * @comp: A calendar component - * @deleted: Whether the object is being deleted or updated - * @changed: Whether or not the user has made changes - * - * Pops up a dialog box asking the user whether changes made (if any) - * should be thrown away because the item has been updated elsewhere - * - * Return value: TRUE if the user clicked Yes, FALSE otherwise. - **/ -gboolean -changed_component_dialog (CalComponent *comp, gboolean deleted, gboolean changed) -{ - GtkWidget *dialog; - CalComponentVType vtype; - char *str; - - vtype = cal_component_get_vtype (comp); - - if (deleted) { - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = _("This event has been deleted."); - break; - - case CAL_COMPONENT_TODO: - str = _("This task has been deleted."); - break; - - case CAL_COMPONENT_JOURNAL: - str = _("This journal entry has been deleted."); - break; - - default: - g_message ("changed_component_dialog(): " - "Cannot handle object of type %d", vtype); - return FALSE; - } - if (changed) - str = g_strdup_printf (_("%s You have made changes. Forget those changes and close the editor?"), str); - else - str = g_strdup_printf (_("%s You have made no changes, close the editor?"), str); - - } else { - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = _("This event has been changed."); - break; - - case CAL_COMPONENT_TODO: - str = _("This task has been changed."); - break; - - case CAL_COMPONENT_JOURNAL: - str = _("This journal entry has been changed."); - break; - - default: - g_message ("changed_component_dialog(): " - "Cannot handle object of type %d", vtype); - return FALSE; - } - if (changed) - str = g_strdup_printf (_("%s You have made changes. Forget those changes and update the editor?"), str); - else - str = g_strdup_printf (_("%s You have made no changes, update the editor?"), str); - } - - dialog = gnome_question_dialog_modal (str, NULL, NULL); - - if (gnome_dialog_run (GNOME_DIALOG (dialog)) == GNOME_YES) - return TRUE; - else - return FALSE; -} diff --git a/calendar/gui/dialogs/changed-comp.h b/calendar/gui/dialogs/changed-comp.h deleted file mode 100644 index 915d7a5372..0000000000 --- a/calendar/gui/dialogs/changed-comp.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Evolution calendar - Changed calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 CHANGED_COMP_H -#define CHANGED_COMP_H - -#include <glib.h> -#include <cal-util/cal-component.h> - -gboolean changed_component_dialog (CalComponent *comp, gboolean deleted, gboolean changed); - -#endif diff --git a/calendar/gui/dialogs/comp-editor-page.c b/calendar/gui/dialogs/comp-editor-page.c deleted file mode 100644 index 957b1533d5..0000000000 --- a/calendar/gui/dialogs/comp-editor-page.c +++ /dev/null @@ -1,416 +0,0 @@ -/* Evolution calendar - Base class for calendar component editor pages - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtksignal.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include "comp-editor-page.h" - - - -static void comp_editor_page_class_init (CompEditorPageClass *class); -static void comp_editor_page_init (CompEditorPage *page); -static void comp_editor_page_destroy (GtkObject *object); - -static GtkObjectClass *parent_class = NULL; - -/* Signal IDs */ - -enum { - CHANGED, - NEEDS_SEND, - SUMMARY_CHANGED, - DATES_CHANGED, - LAST_SIGNAL -}; - -static guint comp_editor_page_signals[LAST_SIGNAL]; - -#define CLASS(page) (COMP_EDITOR_PAGE_CLASS (G_OBJECT_GET_CLASS (page))) - - - -/** - * comp_editor_page_get_type: - * - * Registers the #CompEditorPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #CompEditorPage class. - **/ -GtkType -comp_editor_page_get_type (void) -{ - static GtkType comp_editor_page_type = 0; - - if (!comp_editor_page_type) { - static const GtkTypeInfo comp_editor_page_info = { - "CompEditorPage", - sizeof (CompEditorPage), - sizeof (CompEditorPageClass), - (GtkClassInitFunc) comp_editor_page_class_init, - (GtkObjectInitFunc) comp_editor_page_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - comp_editor_page_type = - gtk_type_unique (GTK_TYPE_OBJECT, - &comp_editor_page_info); - } - - return comp_editor_page_type; -} - -/* Class initialization function for the abstract editor page */ -static void -comp_editor_page_class_init (CompEditorPageClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - - parent_class = g_type_class_ref(GTK_TYPE_OBJECT); - - comp_editor_page_signals[CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (CompEditorPageClass, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - comp_editor_page_signals[NEEDS_SEND] = - g_signal_new ("needs_send", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (CompEditorPageClass, needs_send), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - comp_editor_page_signals[SUMMARY_CHANGED] = - g_signal_new ("summary_changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (CompEditorPageClass, summary_changed), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - - comp_editor_page_signals[DATES_CHANGED] = - g_signal_new ("dates_changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (CompEditorPageClass, dates_changed), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - - class->changed = NULL; - class->summary_changed = NULL; - class->dates_changed = NULL; - - class->get_widget = NULL; - class->focus_main_widget = NULL; - class->fill_widgets = NULL; - class->fill_component = NULL; - class->set_summary = NULL; - class->set_dates = NULL; - - object_class->destroy = comp_editor_page_destroy; -} - - - -static void -comp_editor_page_init (CompEditorPage *page) -{ - page->client = NULL; - page->accel_group = NULL; -} - - -static void -comp_editor_page_destroy (GtkObject *object) -{ - CompEditorPage *page; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (object)); - - page = COMP_EDITOR_PAGE (object); - - if (page->client) { - g_object_ref((page->client)); - page->client = NULL; - } - - if (page->accel_group) { - gtk_accel_group_unref (page->accel_group); - page->accel_group = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -/** - * comp_editor_page_get_widget: - * @page: An editor page. - * - * Queries the main widget of an editor page. - * - * Return value: The widget that is the page's upper container. It should - * normally be inserted in a notebook widget. - **/ -GtkWidget * -comp_editor_page_get_widget (CompEditorPage *page) -{ - g_return_val_if_fail (page != NULL, NULL); - g_return_val_if_fail (IS_COMP_EDITOR_PAGE (page), NULL); - - g_assert (CLASS (page)->get_widget != NULL); - return (* CLASS (page)->get_widget) (page); -} - -/** - * comp_editor_page_focus_main_widget: - * @page: An editor page. - * - * Makes an editor page focus its main widget. This is used by the component - * editor when it first pops up so that it can focus the main widget in the - * first page. - **/ -void -comp_editor_page_focus_main_widget (CompEditorPage *page) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - g_assert (CLASS (page)->focus_main_widget != NULL); - (* CLASS (page)->focus_main_widget) (page); -} - -/** - * comp_editor_page_fill_widgets: - * @page: An editor page. - * @comp: A calendar component. - * - * Fills the widgets of an editor page with the data from a calendar component. - **/ -void -comp_editor_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - g_return_if_fail (comp != NULL); - - g_assert (CLASS (page)->fill_widgets != NULL); - (* CLASS (page)->fill_widgets) (page, comp); -} - -/** - * comp_editor_page_fill_component: - * @page: An editor page. - * @comp: A calendar component. - * - * Takes the data from the widgets of an editor page and sets it on a calendar - * component, replacing the contents of the properties that the editor page - * knows how to manipulate. - * - * Returns: TRUE if the component could be filled, FALSE otherwise - **/ -gboolean -comp_editor_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - g_return_val_if_fail (page != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR_PAGE (page), FALSE); - g_return_val_if_fail (comp != NULL, FALSE); - - if (CLASS (page)->fill_component != NULL) - return (* CLASS (page)->fill_component) (page, comp); - - return TRUE; -} - -/** - * comp_editor_page_set_cal_client: - * @page: An editor page - * @client: A #CalClient object - * - * Sets the #CalClient for the dialog page to use. - **/ -void -comp_editor_page_set_cal_client (CompEditorPage *page, CalClient *client) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - if (page->client) - g_object_unref((client)); - - page->client = client; - if (page->client) - g_object_ref((client)); -} - -/** - * comp_editor_page_set_summary: - * @page: An editor page - * @summary: The text of the new summary value - * - * Sets the summary value for this group of widgets - **/ -void -comp_editor_page_set_summary (CompEditorPage *page, const char *summary) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - if (CLASS (page)->set_summary != NULL) - (* CLASS (page)->set_summary) (page, summary); -} - -/** - * comp_editor_page_set_dates: - * @page: An editor page - * @dates: A collection of various dates in time_t format - * - * Sets the date values for this group of widgets - **/ -void -comp_editor_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - if (CLASS (page)->set_dates != NULL) - (* CLASS (page)->set_dates) (page, dates); -} - -/** - * comp_editor_page_notify_changed: - * @page: An editor page. - * - * Makes an editor page emit the "changed" signal. This is meant to be - * used only by page implementations. - **/ -void -comp_editor_page_notify_changed (CompEditorPage *page) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - gtk_signal_emit (GTK_OBJECT (page), comp_editor_page_signals[CHANGED]); -} - -/** - * comp_editor_page_notify_needs_send: - * @page: - * - * - **/ -void -comp_editor_page_notify_needs_send (CompEditorPage *page) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - gtk_signal_emit (GTK_OBJECT (page), comp_editor_page_signals[NEEDS_SEND]); -} - -/** - * comp_editor_page_notify_summary_changed: - * @page: An editor page. - * - * Makes an editor page emit the "summary_changed" signal. This is meant to be - * used only by page implementations. - **/ -void -comp_editor_page_notify_summary_changed (CompEditorPage *page, - const char *summary) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - - gtk_signal_emit (GTK_OBJECT (page), - comp_editor_page_signals[SUMMARY_CHANGED], - summary); -} - -/** - * comp_editor_page_notify_dates_changed: - * @page: An editor page. - * - * Makes an editor page emit the "dates_changed" signal. This is meant to be - * used only by page implementations. - **/ -void -comp_editor_page_notify_dates_changed (CompEditorPage *page, - CompEditorPageDates *dates) -{ - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - gtk_signal_emit (GTK_OBJECT (page), - comp_editor_page_signals[DATES_CHANGED], - dates); -} - -/** - * comp_editor_page_display_validation_error: - * @page: An editor page. - * @msg: Error message to display. - * @field: Widget that caused the validation error. - * - * Displays an error message about a validation problem in the - * given field. Once the error message has been displayed, the - * focus is set to the widget that caused the validation error. - */ -void -comp_editor_page_display_validation_error (CompEditorPage *page, - const char *msg, - GtkWidget *field) -{ - GtkWidget *dialog; - char *real_msg; - - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - g_return_if_fail (msg != NULL); - g_return_if_fail (GTK_IS_WIDGET (field)); - - real_msg = g_strdup_printf (_("Validation error: %s"), msg); - dialog = gnome_error_dialog (real_msg); - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - - gtk_widget_grab_focus (field); - - g_free (real_msg); -} diff --git a/calendar/gui/dialogs/comp-editor-page.h b/calendar/gui/dialogs/comp-editor-page.h deleted file mode 100644 index e3d4535391..0000000000 --- a/calendar/gui/dialogs/comp-editor-page.h +++ /dev/null @@ -1,111 +0,0 @@ -/* Evolution calendar - Base class for calendar component editor pages - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 COMP_EDITOR_PAGE_H -#define COMP_EDITOR_PAGE_H - -#include <time.h> -#include <gtk/gtkwidget.h> -#include <cal-util/cal-component.h> -#include "cal-client.h" - -G_BEGIN_DECLS - - - -#define TYPE_COMP_EDITOR_PAGE (comp_editor_page_get_type ()) -#define COMP_EDITOR_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMP_EDITOR_PAGE, CompEditorPage)) -#define COMP_EDITOR_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COMP_EDITOR_PAGE, CompEditorPageClass)) -#define IS_COMP_EDITOR_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMP_EDITOR_PAGE)) -#define IS_COMP_EDITOR_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_COMP_EDITOR_PAGE)) - -typedef struct { - CalComponentDateTime *start; - CalComponentDateTime *end; - CalComponentDateTime *due; - struct icaltimetype *complete; -} CompEditorPageDates; - -typedef struct { - GtkObject object; - - /* Some of the pages need the CalClient to access timezone data. */ - CalClient *client; - - /* The GtkAccelGroup for the page. We install this when the page is - mapped, and uninstall when it is unmapped. libglade would do this - normally, but we create our pages individually so have to do it - ourselves. */ - GtkAccelGroup *accel_group; -} CompEditorPage; - -typedef struct { - GtkObjectClass parent_class; - - /* Notification signals */ - - void (* changed) (CompEditorPage *page); - void (* needs_send) (CompEditorPage *page); - - void (* summary_changed) (CompEditorPage *page, const char *summary); - void (* dates_changed) (CompEditorPage *page, const char *dates); - - /* Virtual methods */ - - GtkWidget *(* get_widget) (CompEditorPage *page); - void (* focus_main_widget) (CompEditorPage *page); - - void (* fill_widgets) (CompEditorPage *page, CalComponent *comp); - gboolean (* fill_component) (CompEditorPage *page, CalComponent *comp); - - void (* set_summary) (CompEditorPage *page, const char *summary); - void (* set_dates) (CompEditorPage *page, CompEditorPageDates *dates); -} CompEditorPageClass; - - -GtkType comp_editor_page_get_type (void); -GtkWidget *comp_editor_page_get_widget (CompEditorPage *page); -void comp_editor_page_focus_main_widget (CompEditorPage *page); -void comp_editor_page_fill_widgets (CompEditorPage *page, - CalComponent *comp); -gboolean comp_editor_page_fill_component (CompEditorPage *page, - CalComponent *comp); -void comp_editor_page_set_cal_client (CompEditorPage *page, - CalClient *client); -void comp_editor_page_set_summary (CompEditorPage *page, - const char *summary); -void comp_editor_page_set_dates (CompEditorPage *page, - CompEditorPageDates *dates); -void comp_editor_page_notify_changed (CompEditorPage *page); -void comp_editor_page_notify_needs_send (CompEditorPage *page); -void comp_editor_page_notify_summary_changed (CompEditorPage *page, - const char *summary); -void comp_editor_page_notify_dates_changed (CompEditorPage *page, - CompEditorPageDates *dates); -void comp_editor_page_display_validation_error (CompEditorPage *page, - const char *msg, - GtkWidget *field); - - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/comp-editor-util.c b/calendar/gui/dialogs/comp-editor-util.c deleted file mode 100644 index 09b78201c5..0000000000 --- a/calendar/gui/dialogs/comp-editor-util.c +++ /dev/null @@ -1,340 +0,0 @@ -/* Evolution calendar - Widget utilities - * - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> -#include <string.h> -#include <ical.h> -#include <glib.h> -#include <gtk/gtklabel.h> -#include <libgnome/gnome-i18n.h> -#include <bonobo-activation/bonobo-activation.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-widget.h> -#include <ebook/e-destination.h> -#include <e-util/e-time-utils.h> -#include <cal-util/timeutil.h> -#include "../calendar-config.h" -#include "comp-editor-util.h" - - - -/** - * comp_editor_dates: - * @dates: A structure to be filled out with dates of a component - * @comp: The component to extract the dates from - * - * Extracts the dates from the calendar component into the - * CompEditorPageDates structure. Call comp_editor_free_dates() to free the - * results. - **/ -void -comp_editor_dates (CompEditorPageDates *dates, CalComponent *comp) -{ - CalComponentDateTime dt; - - dates->start = NULL; - dates->end = NULL; - dates->due = NULL; - dates->complete = NULL; - - /* Note that the CalComponentDateTime's returned contain allocated - icaltimetype and tzid values, so we just take over ownership of - those. */ - cal_component_get_dtstart (comp, &dt); - if (dt.value) { - dates->start = g_new (CalComponentDateTime, 1); - *dates->start = dt; - } - - cal_component_get_dtend (comp, &dt); - if (dt.value) { - dates->end = g_new (CalComponentDateTime, 1); - *dates->end = dt; - } - - cal_component_get_due (comp, &dt); - if (dt.value) { - dates->due = g_new (CalComponentDateTime, 1); - *dates->due = dt; - } - - cal_component_get_completed (comp, &dates->complete); -} - - -/* This frees the dates in the CompEditorPageDates struct. But it doesn't free - * the struct (as that is usually static). - */ -void -comp_editor_free_dates (CompEditorPageDates *dates) -{ - /* Note that cal_component_free_datetime() only frees the fields in - the struct. It doesn't free the struct itself, so we do that. */ - if (dates->start) { - cal_component_free_datetime (dates->start); - g_free (dates->start); - } - - if (dates->end) { - cal_component_free_datetime (dates->end); - g_free (dates->end); - } - - if (dates->due) { - cal_component_free_datetime (dates->due); - g_free (dates->due); - } - - if (dates->complete) - cal_component_free_icaltimetype (dates->complete); -} - - -/* dtstart is only passed in if tt is the dtend. */ -static void -write_label_piece (struct icaltimetype *tt, char *buffer, int size, - char *stext, char *etext, struct icaltimetype *dtstart) -{ - struct tm tmp_tm = { 0 }; - struct icaltimetype tt_copy = *tt; - int len; - - /* FIXME: May want to convert the time to an appropriate zone. */ - - if (stext != NULL) - strcat (buffer, stext); - - /* If we are writing the DTEND (i.e. DTSTART is set), and - DTEND > DTSTART, subtract 1 day. The DTEND date is not inclusive. */ - if (tt_copy.is_date && dtstart - && icaltime_compare_date_only (tt_copy, *dtstart) > 0) { - icaltime_adjust (&tt_copy, -1, 0, 0, 0); - } - - tmp_tm.tm_year = tt_copy.year - 1900; - tmp_tm.tm_mon = tt_copy.month - 1; - tmp_tm.tm_mday = tt_copy.day; - tmp_tm.tm_hour = tt_copy.hour; - tmp_tm.tm_min = tt_copy.minute; - tmp_tm.tm_sec = tt_copy.second; - tmp_tm.tm_isdst = -1; - - tmp_tm.tm_wday = time_day_of_week (tt_copy.day, tt_copy.month - 1, - tt_copy.year); - - len = strlen (buffer); - e_time_format_date_and_time (&tmp_tm, - calendar_config_get_24_hour_format (), - !tt_copy.is_date, FALSE, - &buffer[len], size - len); - if (etext != NULL) - strcat (buffer, etext); -} - -/** - * comp_editor_date_label: - * @dates: The dates to use in constructing a label - * @label: The label whose text is to be set - * - * Set the text of a label based on the dates available and the user's - * formatting preferences - **/ -void -comp_editor_date_label (CompEditorPageDates *dates, GtkWidget *label) -{ - char buffer[1024]; - gboolean start_set = FALSE, end_set = FALSE; - gboolean complete_set = FALSE, due_set = FALSE; - - buffer[0] = '\0'; - - if (dates->start && !icaltime_is_null_time (*dates->start->value)) - start_set = TRUE; - if (dates->end && !icaltime_is_null_time (*dates->end->value)) - end_set = TRUE; - if (dates->complete && !icaltime_is_null_time (*dates->complete)) - complete_set = TRUE; - if (dates->due && !icaltime_is_null_time (*dates->due->value)) - due_set = TRUE; - - if (start_set) - write_label_piece (dates->start->value, buffer, 1024, - NULL, NULL, NULL); - - if (start_set && end_set) - write_label_piece (dates->end->value, buffer, 1024, - _(" to "), NULL, dates->start->value); - - if (complete_set) { - if (start_set) - write_label_piece (dates->complete, buffer, 1024, _(" (Completed "), ")", NULL); - else - write_label_piece (dates->complete, buffer, 1024, _("Completed "), NULL, NULL); - } - - if (due_set && dates->complete == NULL) { - if (start_set) - write_label_piece (dates->due->value, buffer, 1024, _(" (Due "), ")", NULL); - else - write_label_piece (dates->due->value, buffer, 1024, _("Due "), NULL, NULL); - } - - gtk_label_set_text (GTK_LABEL (label), buffer); -} - -/** - * comp_editor_new_date_edit: - * @show_date: Whether to show a date picker in the widget. - * @show_time: Whether to show a time picker in the widget. - * @make_time_insensitive: Whether the time field is made insensitive rather - * than hiding it. This is useful if you want to preserve the layout of the - * widgets. - * - * Creates a new #EDateEdit widget, configured using the calendar's preferences. - * - * Return value: A newly-created #EDateEdit widget. - **/ -GtkWidget * -comp_editor_new_date_edit (gboolean show_date, gboolean show_time, - gboolean make_time_insensitive) -{ - EDateEdit *dedit; - - dedit = E_DATE_EDIT (e_date_edit_new ()); - - e_date_edit_set_show_date (dedit, show_date); - e_date_edit_set_show_time (dedit, show_time); -#if 0 - e_date_edit_set_make_time_insensitive (dedit, make_time_insensitive); -#else - e_date_edit_set_make_time_insensitive (dedit, FALSE); -#endif - calendar_config_configure_e_date_edit (dedit); - - return GTK_WIDGET (dedit); -} - - -/* Returns the current time, for EDateEdit widgets and ECalendar items in the - dialogs. - FIXME: Should probably use the timezone from somewhere in the component - rather than the current timezone. */ -struct tm -comp_editor_get_current_time (GtkObject *object, gpointer data) -{ - char *location; - icaltimezone *zone; - struct icaltimetype tt; - struct tm tmp_tm = { 0 }; - - /* Get the current timezone. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone); - - /* Now copy it to the struct tm and return it. */ - tmp_tm.tm_year = tt.year - 1900; - tmp_tm.tm_mon = tt.month - 1; - tmp_tm.tm_mday = tt.day; - tmp_tm.tm_hour = tt.hour; - tmp_tm.tm_min = tt.minute; - tmp_tm.tm_sec = tt.second; - tmp_tm.tm_isdst = -1; - - return tmp_tm; -} - - - -/** - * comp_editor_strip_categories: - * @categories: A string of category names entered by the user. - * - * Takes a string of the form "categ, categ, categ, ..." and removes the - * whitespace between categories to result in "categ,categ,categ,..." - * - * Return value: The category names stripped of surrounding whitespace - * and separated with commas. - **/ -char * -comp_editor_strip_categories (const char *categories) -{ - char *new_categories; - const char *start, *end; - const char *p; - char *new_p; - - if (!categories) - return NULL; - - new_categories = g_new (char, strlen (categories) + 1); - - start = end = NULL; - new_p = new_categories; - - for (p = categories; *p; p++) { - int c; - - c = *p; - - if (isspace (c)) - continue; - else if (c == ',') { - int len; - - if (!start) - continue; - - g_assert (start <= end); - - len = end - start + 1; - strncpy (new_p, start, len); - new_p[len] = ','; - new_p += len + 1; - - start = end = NULL; - } else { - if (!start) { - start = p; - end = p; - } else - end = p; - } - } - - if (start) { - int len; - - g_assert (start <= end); - - len = end - start + 1; - strncpy (new_p, start, len); - new_p += len; - } - - *new_p = '\0'; - - return new_categories; -} diff --git a/calendar/gui/dialogs/comp-editor-util.h b/calendar/gui/dialogs/comp-editor-util.h deleted file mode 100644 index 04bbe23cf4..0000000000 --- a/calendar/gui/dialogs/comp-editor-util.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Evolution calendar - Widget utilities - * - * Copyright (C) 2000 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 _COMP_EDITOR_UTIL_H_ -#define _COMP_EDITOR_UTIL_H_ - -#include <gtk/gtkwidget.h> -#include "comp-editor-page.h" - -void comp_editor_dates (CompEditorPageDates *date, CalComponent *comp); -void comp_editor_free_dates (CompEditorPageDates *dates); - -void comp_editor_date_label (CompEditorPageDates *dates, GtkWidget *label); - -GtkWidget *comp_editor_new_date_edit (gboolean show_date, gboolean show_time, - gboolean make_time_insensitive); - -struct tm comp_editor_get_current_time (GtkObject *object, gpointer data); - - -char *comp_editor_strip_categories (const char *categories); - -#endif diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c deleted file mode 100644 index 70ad1abe8f..0000000000 --- a/calendar/gui/dialogs/comp-editor.c +++ /dev/null @@ -1,1439 +0,0 @@ -/* Evolution calendar - Framework for a calendar component editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <glib.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkstock.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-uidefs.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-window-icon.h> -#include <libgnomeui/gnome-messagebox.h> -#include <bonobo/bonobo-ui-container.h> -#include <bonobo/bonobo-ui-util.h> -#include <gal/widgets/e-unicode.h> -#include <e-util/e-dialog-utils.h> -#include <evolution-shell-component-utils.h> -#include "../print.h" -#include "save-comp.h" -#include "delete-comp.h" -#include "send-comp.h" -#include "changed-comp.h" -#include "cancel-comp.h" -#include "recur-comp.h" -#include "comp-editor.h" - - - -/* Private part of the CompEditor structure */ -struct _CompEditorPrivate { - /* Client to use */ - CalClient *client; - - /* Calendar object/uid we are editing; this is an internal copy */ - CalComponent *comp; - - /* The pages we have */ - GList *pages; - - /* UI Component for the dialog */ - BonoboUIComponent *uic; - - /* Notebook to hold the pages */ - GtkNotebook *notebook; - - GtkWidget *filesel; - - gboolean changed; - gboolean needs_send; - - CalObjModType mod; - - gboolean existing_org; - gboolean user_org; - - gboolean warned; - - gboolean updating; -}; - - - -static void comp_editor_class_init (CompEditorClass *class); -static void comp_editor_init (CompEditor *editor); -static gint comp_editor_key_press_event (GtkWidget *d, GdkEventKey *e); -static void comp_editor_finalize (GObject *object); - -static void real_set_cal_client (CompEditor *editor, CalClient *client); -static void real_edit_comp (CompEditor *editor, CalComponent *comp); -static gboolean real_send_comp (CompEditor *editor, CalComponentItipMethod method); -static gboolean prompt_to_save_changes (CompEditor *editor, gboolean send); -static void delete_comp (CompEditor *editor); -static void close_dialog (CompEditor *editor); - -static void page_changed_cb (GtkObject *obj, gpointer data); -static void page_summary_changed_cb (GtkObject *obj, const char *summary, gpointer data); -static void page_dates_changed_cb (GtkObject *obj, CompEditorPageDates *dates, gpointer data); - -static void obj_updated_cb (CalClient *client, const char *uid, gpointer data); -static void obj_removed_cb (CalClient *client, const char *uid, gpointer data); - -static void save_cmd (GtkWidget *widget, gpointer data); -static void save_close_cmd (GtkWidget *widget, gpointer data); -static void save_as_cmd (GtkWidget *widget, gpointer data); -static void delete_cmd (GtkWidget *widget, gpointer data); -static void print_cmd (GtkWidget *widget, gpointer data); -static void print_preview_cmd (GtkWidget *widget, gpointer data); -static void print_setup_cmd (GtkWidget *widget, gpointer data); -static void close_cmd (GtkWidget *widget, gpointer data); - -static gint delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data); - -static EPixmap pixmaps [] = -{ - E_PIXMAP ("/menu/File/FileSave", "save-16.png"), - E_PIXMAP ("/menu/File/FileSaveAndClose", "save-16.png"), - E_PIXMAP ("/menu/File/FileSaveAs", "save-as-16.png"), - - E_PIXMAP ("/menu/File/FileDelete", "evolution-trash-mini.png"), - - E_PIXMAP ("/menu/File/FilePrint", "print.xpm"), - E_PIXMAP ("/menu/File/FilePrintPreview", "print-preview.xpm"), - - E_PIXMAP ("/Toolbar/FileSaveAndClose", "buttons/save-24.png"), - E_PIXMAP ("/Toolbar/FilePrint", "buttons/print.png"), - E_PIXMAP ("/Toolbar/FileDelete", "buttons/delete-message.png"), - - E_PIXMAP_END -}; - -static BonoboUIVerb verbs [] = { - BONOBO_UI_UNSAFE_VERB ("FileSave", save_cmd), - BONOBO_UI_UNSAFE_VERB ("FileSaveAndClose", save_close_cmd), - BONOBO_UI_UNSAFE_VERB ("FileSaveAs", save_as_cmd), - BONOBO_UI_UNSAFE_VERB ("FileDelete", delete_cmd), - BONOBO_UI_UNSAFE_VERB ("FilePrint", print_cmd), - BONOBO_UI_UNSAFE_VERB ("FilePrintPreview", print_preview_cmd), - BONOBO_UI_UNSAFE_VERB ("FilePrintSetup", print_setup_cmd), - BONOBO_UI_UNSAFE_VERB ("FileClose", close_cmd), - - BONOBO_UI_VERB_END -}; - -static GtkObjectClass *parent_class; - - - -E_MAKE_TYPE (comp_editor, "CompEditor", CompEditor, comp_editor_class_init, comp_editor_init, - BONOBO_TYPE_WINDOW); - -/* Class initialization function for the calendar component editor */ -static void -comp_editor_class_init (CompEditorClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = G_OBJECT_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - - parent_class = g_type_class_ref(BONOBO_TYPE_WINDOW); - - klass->set_cal_client = real_set_cal_client; - klass->edit_comp = real_edit_comp; - klass->send_comp = real_send_comp; - - widget_class->key_press_event = comp_editor_key_press_event; - object_class->finalize = comp_editor_finalize; -} - -/* Creates the basic in the editor */ -static void -setup_widgets (CompEditor *editor) -{ - CompEditorPrivate *priv; - BonoboUIContainer *container; - GtkWidget *vbox; - - priv = editor->priv; - - /* Window and basic vbox */ - container = bonobo_ui_container_new (); - editor = (CompEditor *) bonobo_window_construct (BONOBO_WINDOW (editor), container, - "event-editor", "iCalendar Editor"); - g_signal_connect((editor), "delete_event", - G_CALLBACK (delete_event_cb), editor); - - priv->uic = bonobo_ui_component_new_default (); - bonobo_ui_component_set_container (priv->uic, - bonobo_object_corba_objref (BONOBO_OBJECT (container)), - NULL); - bonobo_ui_engine_config_set_path (bonobo_window_get_ui_engine (BONOBO_WINDOW (editor)), - "/evolution/UIConf/kvps"); - - bonobo_ui_component_add_verb_list_with_data (priv->uic, verbs, editor); - bonobo_ui_util_set_ui (priv->uic, PREFIX, - EVOLUTION_UIDIR "/evolution-comp-editor.xml", - "evolution-calendar", NULL); - e_pixmaps_update (priv->uic, pixmaps); - - vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_widget_show (vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); - bonobo_window_set_contents (BONOBO_WINDOW (editor), vbox); - - /* Notebook */ - priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ()); - gtk_widget_show (GTK_WIDGET (priv->notebook)); - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->notebook), - TRUE, TRUE, 6); -} - -/* Object initialization function for the calendar component editor */ -static void -comp_editor_init (CompEditor *editor) -{ - CompEditorPrivate *priv; - - priv = g_new0 (CompEditorPrivate, 1); - editor->priv = priv; - - setup_widgets (editor); - - priv->pages = NULL; - priv->changed = FALSE; - priv->needs_send = FALSE; - priv->mod = CALOBJ_MOD_ALL; - priv->existing_org = FALSE; - priv->user_org = FALSE; - priv->warned = FALSE; -} - - -static gint -comp_editor_key_press_event (GtkWidget *d, GdkEventKey *e) -{ - if (e->keyval == GDK_Escape) { - if (prompt_to_save_changes (COMP_EDITOR (d), TRUE)) - close_dialog (COMP_EDITOR (d)); - return TRUE; - } - - if (GTK_WIDGET_CLASS (parent_class)->key_press_event) - return (* GTK_WIDGET_CLASS (parent_class)->key_press_event) (d, e); - - return FALSE; -} - -/* Destroy handler for the calendar component editor */ -static void -comp_editor_finalize (GObject *object) -{ - CompEditor *editor; - CompEditorPrivate *priv; - GList *l; - - editor = COMP_EDITOR (object); - priv = editor->priv; - - g_signal_handlers_disconnect_matched (priv->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor); - - /* We want to destroy the pages after the widgets get destroyed, - since they have lots of signal handlers connected to the widgets - with the pages as the data. */ - for (l = priv->pages; l != NULL; l = l->next) - g_object_unref((l->data)); - - if (priv->comp) { - g_object_unref((priv->comp)); - priv->comp = NULL; - } - - g_free (priv); - editor->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static gboolean -save_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - CalComponent *clone; - GList *l; - CalClientResult result; - - priv = editor->priv; - - if (!priv->changed) - return TRUE; - - clone = cal_component_clone (priv->comp); - for (l = priv->pages; l != NULL; l = l->next) { - if (!comp_editor_page_fill_component (l->data, clone)) { - g_object_unref((clone)); - comp_editor_show_page (editor, COMP_EDITOR_PAGE (l->data)); - return FALSE; - } - } - - /* If we are not the organizer, we don't update the sequence number */ - if (!cal_component_has_organizer (clone) || itip_organizer_is_user (clone, priv->client)) - cal_component_commit_sequence (clone); - else - cal_component_abort_sequence (clone); - - g_object_unref((priv->comp)); - priv->comp = clone; - - priv->updating = TRUE; - - if (cal_component_is_instance (priv->comp)) - result = cal_client_update_object_with_mod (priv->client, priv->comp, priv->mod); - else - result = cal_client_update_object (priv->client, priv->comp); - if (result != CAL_CLIENT_RESULT_SUCCESS) { - GtkWidget *dlg; - char *msg; - - switch (result) { - case CAL_CLIENT_RESULT_INVALID_OBJECT : - msg = g_strdup (_("Could not update invalid object")); - break; - case CAL_CLIENT_RESULT_NOT_FOUND : - msg = g_strdup (_("Object not found, not updated")); - break; - case CAL_CLIENT_RESULT_PERMISSION_DENIED : - msg = g_strdup (_("You don't have permissions to update this object")); - break; - default : - msg = g_strdup (_("Could not update object")); - break; - } - - dlg = gnome_error_dialog (msg); - gnome_dialog_run_and_close (GNOME_DIALOG (dlg)); - g_free (msg); - - return FALSE; - } else { - priv->changed = FALSE; - } - - priv->updating = FALSE; - - return TRUE; -} - -static gboolean -save_comp_with_send (CompEditor *editor) -{ - CompEditorPrivate *priv; - gboolean send; - - priv = editor->priv; - - send = priv->changed && priv->needs_send; - - if (!save_comp (editor)) - return FALSE; - - if (send && send_component_dialog (priv->client, priv->comp, !priv->existing_org)) { - if (itip_organizer_is_user (priv->comp, priv->client)) - return comp_editor_send_comp (editor, CAL_COMPONENT_METHOD_REQUEST); - else - return comp_editor_send_comp (editor, CAL_COMPONENT_METHOD_REPLY); - } - - return TRUE; -} - -static void -delete_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - const char *uid; - - priv = editor->priv; - - cal_component_get_uid (priv->comp, &uid); - priv->updating = TRUE; - cal_client_remove_object (priv->client, uid); - priv->updating = FALSE; - close_dialog (editor); -} - -static gboolean -prompt_to_save_changes (CompEditor *editor, gboolean send) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - if (!priv->changed) - return TRUE; - - switch (save_component_dialog (GTK_WINDOW (editor))) { - case GTK_RESPONSE_YES: /* Save */ - if (cal_component_is_instance (priv->comp)) - if (!recur_component_dialog (priv->comp, &priv->mod, GTK_WINDOW (editor))) - return FALSE; - - if (send && save_comp_with_send (editor)) - return TRUE; - else if (!send && save_comp (editor)) - return TRUE; - else - return FALSE; - case GTK_RESPONSE_NO: /* Discard */ - return TRUE; - case GTK_RESPONSE_CANCEL: /* Cancel */ - default: - return FALSE; - } -} - -/* This sets the focus to the toplevel, so any field being edited is committed. - FIXME: In future we may also want to check some of the fields are valid, - e.g. the EDateEdit fields. */ -static void -commit_all_fields (CompEditor *editor) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - gtk_window_set_focus (GTK_WINDOW (editor), NULL); -} - -/* Closes the dialog box and emits the appropriate signals */ -static void -close_dialog (CompEditor *editor) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - gtk_widget_destroy (GTK_WIDGET (editor)); -} - - - -void -comp_editor_set_existing_org (CompEditor *editor, gboolean existing_org) -{ - CompEditorPrivate *priv; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - priv->existing_org = existing_org; -} - -gboolean -comp_editor_get_existing_org (CompEditor *editor) -{ - CompEditorPrivate *priv; - - g_return_val_if_fail (editor != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); - - priv = editor->priv; - - return priv->existing_org; -} - -void -comp_editor_set_user_org (CompEditor *editor, gboolean user_org) -{ - CompEditorPrivate *priv; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - priv->user_org = user_org; -} - -gboolean -comp_editor_get_user_org (CompEditor *editor) -{ - CompEditorPrivate *priv; - - g_return_val_if_fail (editor != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); - - priv = editor->priv; - - return priv->user_org; -} - - -/** - * comp_editor_set_changed: - * @editor: A component editor - * @changed: Value to set the changed state to - * - * Set the dialog changed state to the given value - **/ -void -comp_editor_set_changed (CompEditor *editor, gboolean changed) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - priv->changed = changed; -} - -/** - * comp_editor_get_changed: - * @editor: A component editor - * - * Gets the changed state of the dialog - * - * Return value: A boolean indicating if the dialog is in a changed - * state - **/ -gboolean -comp_editor_get_changed (CompEditor *editor) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - return priv->changed; -} - -/** - * comp_editor_set_needs_send: - * @editor: A component editor - * @needs_send: Value to set the needs send state to - * - * Set the dialog needs send state to the given value - **/ -void -comp_editor_set_needs_send (CompEditor *editor, gboolean needs_send) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - priv->needs_send = needs_send; -} - -/** - * comp_editor_get_needs_send: - * @editor: A component editor - * - * Gets the needs send state of the dialog - * - * Return value: A boolean indicating if the dialog is in a needs send - * state - **/ -gboolean -comp_editor_get_needs_send (CompEditor *editor) -{ - CompEditorPrivate *priv; - - priv = editor->priv; - - return priv->needs_send; -} - -static void page_mapped_cb (GtkWidget *page_widget, - CompEditorPage *page) -{ - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (page_widget); - if (!GTK_IS_WINDOW (toplevel)) - return; - - if (page->accel_group) { - gtk_window_add_accel_group (GTK_WINDOW (toplevel), - page->accel_group); - } -} - -static void page_unmapped_cb (GtkWidget *page_widget, - CompEditorPage *page) -{ - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (page_widget); - if (!GTK_IS_WINDOW (toplevel)) - return; - - if (page->accel_group) { - gtk_window_remove_accel_group (GTK_WINDOW (toplevel), - page->accel_group); - } -} - -/** - * comp_editor_append_page: - * @editor: A component editor - * @page: A component editor page - * @label: Label of the page - * - * Appends a page to the editor notebook with the given label - **/ -void -comp_editor_append_page (CompEditor *editor, - CompEditorPage *page, - const char *label) -{ - CompEditorPrivate *priv; - GtkWidget *page_widget; - GtkWidget *label_widget; - gboolean is_first_page; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - g_return_if_fail (label != NULL); - - priv = editor->priv; - - g_object_ref((page)); - - /* If we are editing something, fill the widgets with current info */ - if (priv->comp != NULL) { - CalComponent *comp; - - comp = comp_editor_get_current_comp (editor); - comp_editor_page_fill_widgets (page, comp); - g_object_unref((comp)); - } - - page_widget = comp_editor_page_get_widget (page); - g_assert (page_widget != NULL); - - label_widget = gtk_label_new (label); - - is_first_page = (priv->pages == NULL); - - priv->pages = g_list_append (priv->pages, page); - gtk_notebook_append_page (priv->notebook, page_widget, label_widget); - - /* Listen for things happening on the page */ - g_signal_connect(page, "changed", - G_CALLBACK (page_changed_cb), editor); - g_signal_connect(page, "summary_changed", - G_CALLBACK (page_summary_changed_cb), editor); - g_signal_connect(page, "dates_changed", - G_CALLBACK (page_dates_changed_cb), editor); - - /* Listen for when the page is mapped/unmapped so we can - install/uninstall the appropriate GtkAccelGroup. */ - g_signal_connect((page_widget), "map", - G_CALLBACK (page_mapped_cb), page); - g_signal_connect((page_widget), "unmap", - G_CALLBACK (page_unmapped_cb), page); - - /* The first page is the main page of the editor, so we ask it to focus - * its main widget. - */ - if (is_first_page) - comp_editor_page_focus_main_widget (page); -} - -/** - * comp_editor_remove_page: - * @editor: A component editor - * @page: A component editor page - * - * Removes the page from the component editor - **/ -void -comp_editor_remove_page (CompEditor *editor, CompEditorPage *page) -{ - CompEditorPrivate *priv; - GtkWidget *page_widget; - gint page_num; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - priv = editor->priv; - - page_widget = comp_editor_page_get_widget (page); - page_num = gtk_notebook_page_num (priv->notebook, page_widget); - if (page_num == -1) - return; - - /* Disconnect all the signals added in append_page(). */ - g_signal_handlers_disconnect_matched (page, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, editor); - g_signal_handlers_disconnect_matched (page_widget, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, page); - - gtk_notebook_remove_page (priv->notebook, page_num); - - priv->pages = g_list_remove (priv->pages, page); - g_object_unref((page)); -} - -/** - * comp_editor_show_page: - * @editor: - * @page: - * - * - **/ -void -comp_editor_show_page (CompEditor *editor, CompEditorPage *page) -{ - CompEditorPrivate *priv; - GtkWidget *page_widget; - gint page_num; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - g_return_if_fail (page != NULL); - g_return_if_fail (IS_COMP_EDITOR_PAGE (page)); - - priv = editor->priv; - - page_widget = comp_editor_page_get_widget (page); - page_num = gtk_notebook_page_num (priv->notebook, page_widget); - gtk_notebook_set_page (priv->notebook, page_num); -} - -/** - * comp_editor_set_cal_client: - * @editor: A component editor - * @client: The calendar client to use - * - * Sets the calendar client used by the editor to update components - **/ -void -comp_editor_set_cal_client (CompEditor *editor, CalClient *client) -{ - CompEditorClass *klass; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - klass = COMP_EDITOR_CLASS (G_OBJECT_GET_CLASS (editor)); - - if (klass->set_cal_client) - klass->set_cal_client (editor, client); -} - -/** - * comp_editor_get_cal_client: - * @editor: A component editor - * - * Returns the calendar client of the editor - * - * Return value: The calendar client of the editor - **/ -CalClient * -comp_editor_get_cal_client (CompEditor *editor) -{ - CompEditorPrivate *priv; - - g_return_val_if_fail (editor != NULL, NULL); - g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); - - priv = editor->priv; - - return priv->client; -} - -/* Creates an appropriate title for the event editor dialog */ -static char * -make_title_from_comp (CalComponent *comp) -{ - char *title, *title_utf8; - const char *type_string; - CalComponentVType type; - CalComponentText text; - - if (!comp) - return g_strdup (_("Edit Appointment")); - - type = cal_component_get_vtype (comp); - switch (type) { - case CAL_COMPONENT_EVENT: - type_string = _("Appointment - %s"); - break; - case CAL_COMPONENT_TODO: - type_string = _("Task - %s"); - break; - case CAL_COMPONENT_JOURNAL: - type_string = _("Journal entry - %s"); - break; - default: - g_message ("make_title_from_comp(): Cannot handle object of type %d", type); - return NULL; - } - - cal_component_get_summary (comp, &text); - if (text.value) { - title = g_strdup_printf (type_string, text.value); - } else { - title = g_strdup_printf (type_string, _("No summary")); - } - - title_utf8 = g_locale_to_utf8 (title, -1, NULL, NULL, NULL); - g_free (title); - - return title_utf8; -} - -static const char * -make_icon_from_comp (CalComponent *comp) -{ - CalComponentVType type; - - if (!comp) - return EVOLUTION_IMAGESDIR "/evolution-calendar-mini.png"; - - type = cal_component_get_vtype (comp); - switch (type) { - case CAL_COMPONENT_EVENT: - return EVOLUTION_IMAGESDIR "/buttons/new_appointment.png"; - break; - case CAL_COMPONENT_TODO: - return EVOLUTION_IMAGESDIR "/buttons/new_task.png"; - break; - default: - return EVOLUTION_IMAGESDIR "/evolution-calendar-mini.png"; - } -} - -/* Sets the event editor's window title from a calendar component */ -static void -set_title_from_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - char *title; - - priv = editor->priv; - title = make_title_from_comp (priv->comp); - gtk_window_set_title (GTK_WINDOW (editor), title); - g_free (title); -} - -static void -set_icon_from_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - const char *file; - - priv = editor->priv; - file = make_icon_from_comp (priv->comp); - gnome_window_icon_set_from_file (GTK_WINDOW (editor), file); -} - -static void -fill_widgets (CompEditor *editor) -{ - CompEditorPrivate *priv; - GList *l; - - priv = editor->priv; - - for (l = priv->pages; l != NULL; l = l->next) - comp_editor_page_fill_widgets (l->data, priv->comp); -} - -static void -real_set_cal_client (CompEditor *editor, CalClient *client) -{ - CompEditorPrivate *priv; - GList *elem; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - if (client == priv->client) - return; - - if (client) { - g_return_if_fail (IS_CAL_CLIENT (client)); - g_return_if_fail (cal_client_get_load_state (client) == - CAL_CLIENT_LOAD_LOADED); - g_object_ref((client)); - } - - if (priv->client) { - gtk_signal_disconnect_by_data (GTK_OBJECT (priv->client), - editor); - g_object_unref((priv->client)); - } - - priv->client = client; - - /* Pass the client to any pages that need it. */ - for (elem = priv->pages; elem; elem = elem->next) - comp_editor_page_set_cal_client (elem->data, client); - - g_signal_connect((priv->client), "obj_updated", - G_CALLBACK (obj_updated_cb), editor); - - g_signal_connect((priv->client), "obj_removed", - G_CALLBACK (obj_removed_cb), editor); -} - -static void -real_edit_comp (CompEditor *editor, CalComponent *comp) -{ - CompEditorPrivate *priv; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - if (priv->comp) { - g_object_unref((priv->comp)); - priv->comp = NULL; - } - - if (comp) - priv->comp = cal_component_clone (comp); - - priv->existing_org = cal_component_has_organizer (comp); - priv->user_org = itip_organizer_is_user (comp, priv->client); - priv->warned = FALSE; - - set_title_from_comp (editor); - set_icon_from_comp (editor); - fill_widgets (editor); -} - - -static gboolean -real_send_comp (CompEditor *editor, CalComponentItipMethod method) -{ - CompEditorPrivate *priv; - CalComponent *tmp_comp; - - g_return_val_if_fail (editor != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); - - priv = editor->priv; - - if (itip_send_comp (method, priv->comp, priv->client, NULL)) { - tmp_comp = priv->comp; - g_object_ref((tmp_comp)); - comp_editor_edit_comp (editor, tmp_comp); - g_object_unref((tmp_comp)); - - comp_editor_set_changed (editor, TRUE); - save_comp (editor); - - return TRUE; - } - - comp_editor_set_changed (editor, TRUE); - - return FALSE; -} - - -/** - * comp_editor_edit_comp: - * @editor: A component editor - * @comp: A calendar component - * - * Starts the editor editing the given component - **/ -void -comp_editor_edit_comp (CompEditor *editor, CalComponent *comp) -{ - CompEditorClass *klass; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - g_return_if_fail (comp != NULL); - g_return_if_fail (IS_CAL_COMPONENT (comp)); - - klass = COMP_EDITOR_CLASS (G_OBJECT_GET_CLASS (editor)); - - if (klass->edit_comp) - klass->edit_comp (editor, comp); -} - -CalComponent * -comp_editor_get_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - - g_return_val_if_fail (editor != NULL, NULL); - g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); - - priv = editor->priv; - - return priv->comp; -} - -CalComponent * -comp_editor_get_current_comp (CompEditor *editor) -{ - CompEditorPrivate *priv; - CalComponent *comp; - GList *l; - - g_return_val_if_fail (editor != NULL, NULL); - g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); - - priv = editor->priv; - - comp = cal_component_clone (priv->comp); - if (priv->changed) { - for (l = priv->pages; l != NULL; l = l->next) - comp_editor_page_fill_component (l->data, comp); - } - - return comp; -} - -/** - * comp_editor_save_comp: - * @editor: - * - * - **/ -gboolean -comp_editor_save_comp (CompEditor *editor, gboolean send) -{ - return prompt_to_save_changes (editor, send); -} - -/** - * comp_editor_delete_comp: - * @editor: - * - * - **/ -void -comp_editor_delete_comp (CompEditor *editor) -{ - delete_comp (editor); -} - -/** - * comp_editor_send_comp: - * @editor: - * @method: - * - * - **/ -gboolean -comp_editor_send_comp (CompEditor *editor, CalComponentItipMethod method) -{ - CompEditorClass *klass; - - g_return_val_if_fail (editor != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); - - klass = COMP_EDITOR_CLASS (G_OBJECT_GET_CLASS (editor)); - - if (klass->send_comp) - return klass->send_comp (editor, method); - - return FALSE; -} - -gboolean -comp_editor_close (CompEditor *editor) -{ - gboolean close; - - g_return_val_if_fail (editor != NULL, FALSE); - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); - - commit_all_fields (editor); - - close = prompt_to_save_changes (editor, TRUE); - if (close) - close_dialog (editor); - - return close; -} - -/** - * comp_editor_merge_ui: - * @editor: - * @filename: - * @verbs: - * - * - **/ -void -comp_editor_merge_ui (CompEditor *editor, - const char *filename, - BonoboUIVerb *verbs, - EPixmap *component_pixmaps) -{ - CompEditorPrivate *priv; - char *path; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - path = g_strconcat (EVOLUTION_UIDIR "/", filename, NULL); - - bonobo_ui_util_set_ui (priv->uic, EVOLUTION_DATADIR, path, "evolution-calendar", NULL); - bonobo_ui_component_add_verb_list_with_data (priv->uic, verbs, editor); - - g_free (path); - - if (component_pixmaps != NULL) - e_pixmaps_update (priv->uic, component_pixmaps); -} - -/** - * comp_editor_set_ui_prop: - * @editor: - * @path: - * @attr: - * @val: - * - * - **/ -void -comp_editor_set_ui_prop (CompEditor *editor, - const char *path, - const char *attr, - const char *val) -{ - CompEditorPrivate *priv; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - bonobo_ui_component_set_prop (priv->uic, path, attr, val, NULL); -} - - -/* Brings attention to a window by raising it and giving it focus */ -static void -raise_and_focus (GtkWidget *widget) -{ - g_assert (GTK_WIDGET_REALIZED (widget)); - gdk_window_show (widget->window); - gtk_widget_grab_focus (widget); -} - -/** - * comp_editor_focus: - * @editor: A component editor - * - * Brings the editor window to the front and gives it focus - **/ -void -comp_editor_focus (CompEditor *editor) -{ - CompEditorPrivate *priv; - - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = editor->priv; - - gtk_widget_show (GTK_WIDGET (editor)); - raise_and_focus (GTK_WIDGET (editor)); -} - -/* Menu Commands */ -static void -save_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - - priv = editor->priv; - - commit_all_fields (editor); - - if (cal_component_is_instance (priv->comp)) - if (!recur_component_dialog (priv->comp, &priv->mod, GTK_WINDOW (editor))) - return; - - save_comp_with_send (editor); -} - -static void -save_close_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - - priv = editor->priv; - - commit_all_fields (editor); - - if (cal_component_is_instance (priv->comp)) - if (!recur_component_dialog (priv->comp, &priv->mod, GTK_WINDOW (editor))) - return; - - if (save_comp_with_send (editor)) - close_dialog (editor); -} - -static void -save_as_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - char *filename; - char *ical_string; - FILE *file; - - priv = editor->priv; - - commit_all_fields (editor); - - filename = e_file_dialog_save (_("Save as...")); - if (filename == NULL) - return; - - ical_string = cal_client_get_component_as_string (priv->client, priv->comp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - file = fopen (filename, "w"); - if (file == NULL) { - g_warning ("Couldn't save item"); - return; - } - - fprintf (file, ical_string); - g_free (ical_string); - fclose (file); -} - -static void -delete_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - CalComponentVType vtype; - - priv = editor->priv; - - vtype = cal_component_get_vtype (priv->comp); - - if (delete_component_dialog (priv->comp, FALSE, 1, vtype, GTK_WIDGET (editor))) { - if (itip_organizer_is_user (priv->comp, priv->client) - && cancel_component_dialog (priv->client, priv->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, priv->comp, priv->client, NULL); - - delete_comp (editor); - } -} - -static void -print_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CalComponent *comp; - - commit_all_fields (editor); - - comp = comp_editor_get_current_comp (editor); - print_comp (comp, editor->priv->client, FALSE); - g_object_unref((comp)); -} - -static void -print_preview_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CalComponent *comp; - - commit_all_fields (editor); - - comp = comp_editor_get_current_comp (editor); - print_comp (comp, editor->priv->client, TRUE); - g_object_unref((comp)); -} - -static void -print_setup_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - - priv = editor->priv; - - print_setup (); -} - -static void -close_cmd (GtkWidget *widget, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - - commit_all_fields (editor); - - if (prompt_to_save_changes (editor, TRUE)) - close_dialog (editor); -} - -static void -page_changed_cb (GtkObject *obj, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - - priv = editor->priv; - - priv->changed = TRUE; - - if (!priv->warned && priv->existing_org && !priv->user_org) { - e_notice (editor, GTK_MESSAGE_INFO, - _("Changes made to this item may be discarded if an update arrives")); - priv->warned = TRUE; - } - -} - -/* Page signal callbacks */ -static void -page_summary_changed_cb (GtkObject *obj, const char *summary, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - GList *l; - - priv = editor->priv; - - for (l = priv->pages; l != NULL; l = l->next) - if (obj != l->data) - comp_editor_page_set_summary (l->data, summary); - - priv->changed = TRUE; - - if (!priv->warned && priv->existing_org && !priv->user_org) { - e_notice (editor, GTK_MESSAGE_INFO, - _("Changes made to this item may be discarded if an update arrives")); - priv->warned = TRUE; - } -} - -static void -page_dates_changed_cb (GtkObject *obj, - CompEditorPageDates *dates, - gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - GList *l; - - priv = editor->priv; - - for (l = priv->pages; l != NULL; l = l->next) - if (obj != l->data) - comp_editor_page_set_dates (l->data, dates); - - priv->changed = TRUE; - - if (!priv->warned && priv->existing_org && !priv->user_org) { - e_notice (editor, GTK_MESSAGE_INFO, - _("Changes made to this item may be discarded if an update arrives")); - priv->warned = TRUE; - } -} - -static void -obj_updated_cb (CalClient *client, const char *uid, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - CalComponent *comp = NULL; - CalClientGetStatus status; - const char *edit_uid; - - priv = editor->priv; - - cal_component_get_uid (priv->comp, &edit_uid); - - if (!strcmp (uid, edit_uid) && !priv->updating) { - if (changed_component_dialog (priv->comp, FALSE, priv->changed)) { - status = cal_client_get_object (priv->client, uid, &comp); - if (status == CAL_CLIENT_GET_SUCCESS) { - comp_editor_edit_comp (editor, comp); - g_object_unref((comp)); - } else { - GtkWidget *dlg; - - dlg = gnome_error_dialog (_("Unable to obtain current version!")); - gnome_dialog_run_and_close (GNOME_DIALOG (dlg)); - } - } - } -} - -static void -obj_removed_cb (CalClient *client, const char *uid, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - const char *edit_uid; - - priv = editor->priv; - - cal_component_get_uid (priv->comp, &edit_uid); - - if (!strcmp (uid, edit_uid) && !priv->updating) { - if (changed_component_dialog (priv->comp, TRUE, priv->changed)) - close_dialog (editor); - } -} - -static gint -delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - - if (prompt_to_save_changes (editor, TRUE)) - close_dialog (editor); - - return TRUE; -} diff --git a/calendar/gui/dialogs/comp-editor.h b/calendar/gui/dialogs/comp-editor.h deleted file mode 100644 index 8ef14c8edb..0000000000 --- a/calendar/gui/dialogs/comp-editor.h +++ /dev/null @@ -1,109 +0,0 @@ -/* Evolution calendar - Framework for a calendar component editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 COMP_EDITOR_H -#define COMP_EDITOR_H - -#include <gtk/gtk.h> -#include <bonobo/bonobo-window.h> -#include <bonobo/bonobo-ui-engine.h> -#include <bonobo/bonobo-ui-component.h> -#include "cal-client.h" -#include "../itip-utils.h" -#include "comp-editor-page.h" -#include "evolution-shell-component-utils.h" - -G_BEGIN_DECLS - - - -#define TYPE_COMP_EDITOR (comp_editor_get_type ()) -#define COMP_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMP_EDITOR, CompEditor)) -#define COMP_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COMP_EDITOR, CompEditorClass)) -#define IS_COMP_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMP_EDITOR)) -#define IS_COMP_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COMP_EDITOR)) - -typedef struct _CompEditorPrivate CompEditorPrivate; - -typedef struct { - BonoboWindow object; - - /* Private data */ - CompEditorPrivate *priv; -} CompEditor; - -typedef struct { - BonoboWindowClass parent_class; - - /* Virtual functions */ - void (* set_cal_client) (CompEditor *page, CalClient *client); - void (* edit_comp) (CompEditor *page, CalComponent *comp); - gboolean (* send_comp) (CompEditor *page, CalComponentItipMethod method); -} CompEditorClass; - -GtkType comp_editor_get_type (void); -void comp_editor_set_changed (CompEditor *editor, - gboolean changed); -gboolean comp_editor_get_changed (CompEditor *editor); -void comp_editor_set_needs_send (CompEditor *editor, - gboolean needs_send); -gboolean comp_editor_get_needs_send (CompEditor *editor); -void comp_editor_set_existing_org (CompEditor *editor, - gboolean existing_org); -gboolean comp_editor_get_existing_org (CompEditor *editor); -void comp_editor_set_user_org (CompEditor *editor, - gboolean user_org); -gboolean comp_editor_get_user_org (CompEditor *editor); -void comp_editor_append_page (CompEditor *editor, - CompEditorPage *page, - const char *label); -void comp_editor_remove_page (CompEditor *editor, - CompEditorPage *page); -void comp_editor_show_page (CompEditor *editor, - CompEditorPage *page); -void comp_editor_set_cal_client (CompEditor *editor, - CalClient *client); -CalClient *comp_editor_get_cal_client (CompEditor *editor); -void comp_editor_edit_comp (CompEditor *ee, - CalComponent *comp); -CalComponent *comp_editor_get_comp (CompEditor *editor); -CalComponent *comp_editor_get_current_comp (CompEditor *editor); -gboolean comp_editor_save_comp (CompEditor *editor, - gboolean send); -void comp_editor_delete_comp (CompEditor *editor); -gboolean comp_editor_send_comp (CompEditor *editor, - CalComponentItipMethod method); -gboolean comp_editor_close (CompEditor *editor); -void comp_editor_merge_ui (CompEditor *editor, - const char *filename, - BonoboUIVerb *verbs, - EPixmap *pixmaps); -void comp_editor_set_ui_prop (CompEditor *editor, - const char *path, - const char *attr, - const char *val); -void comp_editor_focus (CompEditor *editor); - - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/delete-comp.c b/calendar/gui/dialogs/delete-comp.c deleted file mode 100644 index 995eed72d3..0000000000 --- a/calendar/gui/dialogs/delete-comp.c +++ /dev/null @@ -1,159 +0,0 @@ -/* Evolution calendar - Delete calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkmessagedialog.h> -#include <libgnome/gnome-i18n.h> -#include <gal/widgets/e-unicode.h> -#include "../calendar-config.h" -#include "delete-comp.h" - - - -/** - * delete_component_dialog: - * @comp: A calendar component if a single component is to be deleted, or NULL - * if more that one component is to be deleted. - * @consider_as_untitled: If deleting more than one component, this is ignored. - * Otherwise, whether to consider the component as not having a summary; if - * FALSE then the component's summary string will be used. - * @n_comps: Number of components that are to be deleted. - * @vtype: Type of the components that are to be deleted. This is ignored - * if only one component is to be deleted, and the vtype is extracted from - * the component instead. - * @widget: A widget to use as a basis for conversion from UTF8 into font - * encoding. - * - * Pops up a dialog box asking the user whether he wants to delete a number of - * calendar components. The dialog will not appear, however, if the - * configuration option for confirmation is turned off. - * - * Return value: TRUE if the user clicked Yes, FALSE otherwise. If the - * configuration option for confirmation is turned off, this function will - * unconditionally return TRUE. - **/ -gboolean -delete_component_dialog (CalComponent *comp, - gboolean consider_as_untitled, - int n_comps, CalComponentVType vtype, - GtkWidget *widget) -{ - char *str; - GtkWidget *dialog; - int ret; - - if (comp) { - g_return_val_if_fail (IS_CAL_COMPONENT (comp), FALSE); - g_return_val_if_fail (n_comps == 1, FALSE); - } else { - g_return_val_if_fail (n_comps > 1, FALSE); - g_return_val_if_fail (vtype != CAL_COMPONENT_NO_TYPE, FALSE); - } - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - - if (!calendar_config_get_confirm_delete ()) - return TRUE; - - if (comp) { - CalComponentText summary; - char *tmp; - - vtype = cal_component_get_vtype (comp); - - if (!consider_as_untitled) { - cal_component_get_summary (comp, &summary); - tmp = g_strdup (summary.value); - } else - tmp = NULL; - - switch (vtype) { - case CAL_COMPONENT_EVENT: - if (tmp) - str = g_strdup_printf (_("Are you sure you want to delete " - "the appointment `%s'?"), tmp); - else - str = g_strdup (_("Are you sure you want to delete this " - "untitled appointment?")); - break; - - case CAL_COMPONENT_TODO: - if (tmp) - str = g_strdup_printf (_("Are you sure you want to delete " - "the task `%s'?"), tmp); - else - str = g_strdup (_("Are you sure you want to delete this " - "untitled task?")); - break; - - case CAL_COMPONENT_JOURNAL: - if (tmp) - str = g_strdup_printf (_("Are you sure you want to delete " - "the journal entry `%s'?"), tmp); - else - str = g_strdup (_("Are you sure want to delete this " - "untitled journal entry?")); - break; - - default: - g_message ("delete_component_dialog(): Cannot handle object of type %d", - vtype); - g_free (tmp); - return FALSE; - } - - g_free (tmp); - } else { - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = g_strdup_printf (_("Are you sure you want to delete " - "%d appointments?"), n_comps); - break; - - case CAL_COMPONENT_TODO: - str = g_strdup_printf (_("Are you sure you want to delete " - "%d tasks?"), n_comps); - break; - - case CAL_COMPONENT_JOURNAL: - str = g_strdup_printf (_("Are you sure you want to delete " - "%d journal entries?"), n_comps); - break; - - default: - g_message ("delete_component_dialog(): Cannot handle objects of type %d", - vtype); - return FALSE; - } - } - - dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", str); - g_free (str); - ret = gtk_dialog_run((GtkDialog *)dialog) == GTK_RESPONSE_YES; - gtk_widget_destroy(dialog); - - return ret; -} diff --git a/calendar/gui/dialogs/delete-comp.h b/calendar/gui/dialogs/delete-comp.h deleted file mode 100644 index 64945b5bee..0000000000 --- a/calendar/gui/dialogs/delete-comp.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Evolution calendar - Delete calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 DELETE_COMP_H -#define DELETE_COMP_H - -#include <gtk/gtkwidget.h> -#include <cal-util/cal-component.h> - -gboolean delete_component_dialog (CalComponent *comp, - gboolean consider_as_untitled, - int n_comps, CalComponentVType vtype, - GtkWidget *widget); - -#endif diff --git a/calendar/gui/dialogs/delete-error.c b/calendar/gui/dialogs/delete-error.c deleted file mode 100644 index 947aab1e97..0000000000 --- a/calendar/gui/dialogs/delete-error.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtkmessagedialog.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-uidefs.h> -#include <gal/widgets/e-unicode.h> -#include "delete-error.h" - - - -/** - * delete_error_dialog: - * - * Shows any applicable error messages as the result of deleting and object - * - **/ -void -delete_error_dialog (CalClientResult result, CalComponentVType vtype) -{ - GtkWidget *dialog; - const char *str; - - switch (result) { - case CAL_CLIENT_RESULT_CORBA_ERROR: - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = _("The event could not be deleted due to a corba error"); - break; - case CAL_COMPONENT_TODO: - str = _("The task could not be deleted due to a corba error"); - break; - case CAL_COMPONENT_JOURNAL: - str = _("The journal entry could not be deleted due to a corba error"); - break; - default: - str = _("The item could not be deleted due to a corba error"); - break; - } - break; - case CAL_CLIENT_RESULT_PERMISSION_DENIED: - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = _("The event could not be deleted because permission was denied"); - break; - case CAL_COMPONENT_TODO: - str = _("The task could not be deleted because permission was denied"); - break; - case CAL_COMPONENT_JOURNAL: - str = _("The journal entry could not be deleted because permission was denied"); - break; - default: - str = _("The item could not be deleted because permission was denied"); - break; - } - break; - case CAL_CLIENT_RESULT_INVALID_OBJECT: - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = _("The event could not be deleted because it was invalid"); - break; - case CAL_COMPONENT_TODO: - str = _("The task could not be deleted because it was invalid"); - break; - case CAL_COMPONENT_JOURNAL: - str = _("The journal entry could not be deleted because it was invalid"); - break; - default: - str = _("The item could not be deleted because it was invalid"); - break; - } - break; - case CAL_CLIENT_RESULT_SUCCESS: - case CAL_CLIENT_RESULT_NOT_FOUND: - default: - /* If not found, we don't care - its gone anyhow */ - return; - } - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, str); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} diff --git a/calendar/gui/dialogs/delete-error.h b/calendar/gui/dialogs/delete-error.h deleted file mode 100644 index dcef2fa3be..0000000000 --- a/calendar/gui/dialogs/delete-error.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 DELETE_ERROR_H -#define DELETE_ERROR_H - -#include <glib.h> -#include <cal-client/cal-client.h> -#include <cal-util/cal-component.h> - -void delete_error_dialog (CalClientResult result, CalComponentVType vtype); - -#endif diff --git a/calendar/gui/dialogs/e-delegate-dialog.c b/calendar/gui/dialogs/e-delegate-dialog.c deleted file mode 100644 index d9f05691f6..0000000000 --- a/calendar/gui/dialogs/e-delegate-dialog.c +++ /dev/null @@ -1,322 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution calendar - Delegate selector dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Damon Chaplin <damon@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <bonobo-activation/bonobo-activation.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-widget.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkcombo.h> -#include <gtk/gtkentry.h> -#include <gtk/gtklabel.h> -#include <gnome.h> -#include <ical.h> -#include <glade/glade.h> -#include <gal/util/e-util.h> -#include <widgets/misc/e-map.h> -#include <ebook/e-destination.h> -#include "Evolution-Addressbook-SelectNames.h" -#include "e-delegate-dialog.h" - -struct _EDelegateDialogPrivate { - char *name; - char *address; - - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *app; - GtkWidget *hbox; - GtkWidget *addressbook; - - GNOME_Evolution_Addressbook_SelectNames corba_select_names; - GtkWidget *entry; -}; - -#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames" -static const char *section_name = "Delegate To"; - -static void e_delegate_dialog_class_init (EDelegateDialogClass *class); -static void e_delegate_dialog_init (EDelegateDialog *edd); -static void e_delegate_dialog_finalize (GObject *object); - -static gboolean get_widgets (EDelegateDialog *edd); -static void addressbook_clicked_cb (GtkWidget *widget, gpointer data); - -static GtkObjectClass *parent_class; - -E_MAKE_TYPE (e_delegate_dialog, "EDelegateDialog", EDelegateDialog, e_delegate_dialog_class_init, - e_delegate_dialog_init, G_TYPE_OBJECT); - -/* Class initialization function for the event editor */ -static void -e_delegate_dialog_class_init (EDelegateDialogClass *class) -{ - GObjectClass *gobject_class; - - gobject_class = (GObjectClass *) class; - - parent_class = g_type_class_ref (G_TYPE_OBJECT); - - gobject_class->finalize = e_delegate_dialog_finalize; -} - -/* Object initialization function for the event editor */ -static void -e_delegate_dialog_init (EDelegateDialog *edd) -{ - EDelegateDialogPrivate *priv; - - priv = g_new0 (EDelegateDialogPrivate, 1); - edd->priv = priv; - - priv->address = NULL; -} - -/* Destroy handler for the event editor */ -static void -e_delegate_dialog_finalize (GObject *object) -{ - EDelegateDialog *edd; - EDelegateDialogPrivate *priv; - GtkWidget *dialog; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_DELEGATE_DIALOG (object)); - - edd = E_DELEGATE_DIALOG (object); - priv = edd->priv; - - /* Destroy the actual dialog. */ - dialog = e_delegate_dialog_get_toplevel (edd); - gtk_widget_destroy (dialog); - - g_free (priv->address); - priv->address = NULL; - - g_free (priv); - edd->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - -EDelegateDialog * -e_delegate_dialog_construct (EDelegateDialog *edd, const char *name, const char *address) -{ - EDelegateDialogPrivate *priv; - EDestination *dest; - EDestination *destv[2] = {NULL, NULL}; - Bonobo_Control corba_control; - CORBA_Environment ev; - char *str; - - g_return_val_if_fail (edd != NULL, NULL); - g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL); - - priv = edd->priv; - - /* Load the content widgets */ - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/e-delegate-dialog.glade", - NULL, NULL); - if (!priv->xml) { - g_message ("e_delegate_dialog_construct(): Could not load the Glade XML file!"); - goto error; - } - - if (!get_widgets (edd)) { - g_message ("e_delegate_dialog_construct(): Could not find all widgets in the XML file!"); - goto error; - } - - CORBA_exception_init (&ev); - - priv->corba_select_names = bonobo_activation_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev); - GNOME_Evolution_Addressbook_SelectNames_addSectionWithLimit (priv->corba_select_names, - section_name, - section_name, - 1, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("e_delegate_dialog_construct(): Unable to add section!"); - goto error; - } - - corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (priv->corba_select_names, - section_name, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("e_delegate_dialog_construct(): Unable to get addressbook entry!"); - goto error; - } - - CORBA_exception_free (&ev); - - priv->entry = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL); - gtk_widget_show (priv->entry); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->entry, TRUE, TRUE, 6); - - dest = e_destination_new (); - destv[0] = dest; - if (name != NULL && *name) - e_destination_set_name (dest, name); - if (address != NULL && *address) - e_destination_set_email (dest, address); - str = e_destination_exportv(destv); - bonobo_widget_set_property (BONOBO_WIDGET (priv->entry), "destinations", TC_CORBA_string, str, NULL); - g_free(str); - g_object_unref((dest)); - - g_signal_connect((priv->addressbook), "clicked", - G_CALLBACK (addressbook_clicked_cb), edd); - - return edd; - - error: - - g_object_unref((edd)); - return NULL; -} - -static gboolean -get_widgets (EDelegateDialog *edd) -{ - EDelegateDialogPrivate *priv; - - priv = edd->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->app = GW ("delegate-dialog"); - priv->hbox = GW ("delegate-hbox"); - priv->addressbook = GW ("addressbook"); - - return (priv->app - && priv->hbox - && priv->addressbook); -} - -static void -addressbook_clicked_cb (GtkWidget *widget, gpointer data) -{ - EDelegateDialog *edd = data; - EDelegateDialogPrivate *priv; - CORBA_Environment ev; - - priv = edd->priv; - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_SelectNames_activateDialog (priv->corba_select_names, section_name, &ev); - - CORBA_exception_free (&ev); -} - - -/** - * e_delegate_dialog_new: - * - * Creates a new event editor dialog. - * - * Return value: A newly-created event editor dialog, or NULL if the event - * editor could not be created. - **/ -EDelegateDialog * -e_delegate_dialog_new (const char *name, const char *address) -{ - EDelegateDialog *edd; - - edd = E_DELEGATE_DIALOG (g_object_new (E_TYPE_DELEGATE_DIALOG, NULL)); - return e_delegate_dialog_construct (E_DELEGATE_DIALOG (edd), name, address); -} - -char * -e_delegate_dialog_get_delegate (EDelegateDialog *edd) -{ - EDelegateDialogPrivate *priv; - EDestination **destv; - char *string = NULL; - - g_return_val_if_fail (edd != NULL, NULL); - g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL); - - priv = edd->priv; - - bonobo_widget_get_property (BONOBO_WIDGET (priv->entry), "destinations", TC_CORBA_string, &string, NULL); - destv = e_destination_importv (string); - - if (destv && destv[0] != NULL) { - g_free (priv->address); - priv->address = g_strdup (e_destination_get_email (destv[0])); - g_free (destv); - } - - g_free (string); - - return g_strdup (priv->address); -} - - -char * -e_delegate_dialog_get_delegate_name (EDelegateDialog *edd) -{ - EDelegateDialogPrivate *priv; - EDestination **destv; - char *string = NULL; - - g_return_val_if_fail (edd != NULL, NULL); - g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL); - - priv = edd->priv; - - bonobo_widget_get_property (BONOBO_WIDGET (priv->entry), "destinations", TC_CORBA_string, &string, NULL); - destv = e_destination_importv (string); - - g_message ("importv: [%s]", string); - - if (destv && destv[0] != NULL) { - g_free (priv->name); - priv->name = g_strdup (e_destination_get_name (destv[0])); - g_free (destv); - } - - g_free (string); - - return g_strdup (priv->name); -} - -GtkWidget* -e_delegate_dialog_get_toplevel (EDelegateDialog *edd) -{ - EDelegateDialogPrivate *priv; - - g_return_val_if_fail (edd != NULL, NULL); - g_return_val_if_fail (E_IS_DELEGATE_DIALOG (edd), NULL); - - priv = edd->priv; - - return priv->app; -} - diff --git a/calendar/gui/dialogs/e-delegate-dialog.glade b/calendar/gui/dialogs/e-delegate-dialog.glade deleted file mode 100644 index f7f958007d..0000000000 --- a/calendar/gui/dialogs/e-delegate-dialog.glade +++ /dev/null @@ -1,112 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkDialog" id="delegate-dialog"> - <property name="title" translatable="yes">Enter Delegate</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - <property name="has_separator">True</property> - - <child internal-child="vbox"> - <widget class="GtkVBox" id="dialog-vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">8</property> - - <child internal-child="action_area"> - <widget class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - - <child> - <widget class="GtkButton" id="ok-button"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="has_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-ok</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">-5</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="cancel-button"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-cancel</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">-6</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="delegate-hbox"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="label" translatable="yes">Delegate To:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="addressbook"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Addressbook...</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/e-delegate-dialog.h b/calendar/gui/dialogs/e-delegate-dialog.h deleted file mode 100644 index 2acc853e0a..0000000000 --- a/calendar/gui/dialogs/e-delegate-dialog.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Evolution calendar - Delegate selector dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __E_DELEGATE_DIALOG_H__ -#define __E_DELEGATE_DIALOG_H__ - -#include <gtk/gtkwidget.h> - - - -#define E_TYPE_DELEGATE_DIALOG (e_delegate_dialog_get_type ()) -#define E_DELEGATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_DELEGATE_DIALOG, EDelegateDialog)) -#define E_DELEGATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_DELEGATE_DIALOG, \ - EDelegateDialogClass)) -#define E_IS_DELEGATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_DELEGATE_DIALOG)) -#define E_IS_DELEGATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_DELEGATE_DIALOG)) - - -typedef struct _EDelegateDialog EDelegateDialog; -typedef struct _EDelegateDialogClass EDelegateDialogClass; -typedef struct _EDelegateDialogPrivate EDelegateDialogPrivate; - -struct _EDelegateDialog { - GtkObject object; - - /* Private data */ - EDelegateDialogPrivate *priv; -}; - -struct _EDelegateDialogClass { - GtkObjectClass parent_class; -}; - -GtkType e_delegate_dialog_get_type (void); - -EDelegateDialog* e_delegate_dialog_construct (EDelegateDialog *etd, - const char *name, - const char *address); - -EDelegateDialog* e_delegate_dialog_new (const char *name, - const char *address); - -char* e_delegate_dialog_get_delegate (EDelegateDialog *etd); - -char* e_delegate_dialog_get_delegate_name (EDelegateDialog *etd); - -void e_delegate_dialog_set_delegate (EDelegateDialog *etd, - const char *address); - -GtkWidget* e_delegate_dialog_get_toplevel (EDelegateDialog *etd); - - - - -#endif /* __E_DELEGATE_DIALOG_H__ */ diff --git a/calendar/gui/dialogs/event-editor.c b/calendar/gui/dialogs/event-editor.c deleted file mode 100644 index 93d0a39c53..0000000000 --- a/calendar/gui/dialogs/event-editor.c +++ /dev/null @@ -1,525 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* Evolution calendar - Event editor dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <libgnome/gnome-i18n.h> -#include <widgets/misc/e-dateedit.h> - -#include "event-page.h" -#include "alarm-page.h" -#include "recurrence-page.h" -#include "meeting-page.h" -#include "schedule-page.h" -#include "cancel-comp.h" -#include "event-editor.h" - -struct _EventEditorPrivate { - EventPage *event_page; - AlarmPage *alarm_page; - RecurrencePage *recur_page; - MeetingPage *meet_page; - SchedulePage *sched_page; - - EMeetingModel *model; - - gboolean meeting_shown; - gboolean updating; -}; - - - -static void event_editor_class_init (EventEditorClass *class); -static void event_editor_init (EventEditor *ee); -static void event_editor_set_cal_client (CompEditor *editor, CalClient *client); -static void event_editor_edit_comp (CompEditor *editor, CalComponent *comp); -static gboolean event_editor_send_comp (CompEditor *editor, CalComponentItipMethod method); -static void event_editor_finalize (GObject *object); - -static void schedule_meeting_cmd (GtkWidget *widget, gpointer data); -static void refresh_meeting_cmd (GtkWidget *widget, gpointer data); -static void cancel_meeting_cmd (GtkWidget *widget, gpointer data); -static void forward_cmd (GtkWidget *widget, gpointer data); - -static void model_row_changed_cb (ETableModel *etm, int row, gpointer data); -static void row_count_changed_cb (ETableModel *etm, int row, int count, gpointer data); - -static EPixmap pixmaps [] = { - E_PIXMAP ("/Toolbar/Actions/ActionScheduleMeeting", "schedule-meeting-24.png"), - E_PIXMAP_END -}; - -static BonoboUIVerb verbs [] = { - BONOBO_UI_UNSAFE_VERB ("ActionScheduleMeeting", schedule_meeting_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionRefreshMeeting", refresh_meeting_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionCancelMeeting", cancel_meeting_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionForward", forward_cmd), - - BONOBO_UI_VERB_END -}; - -static CompEditorClass *parent_class; - - - -/** - * event_editor_get_type: - * - * Registers the #EventEditor class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #EventEditor class. - **/ - -E_MAKE_TYPE (event_editor, "EventEditor", EventEditor, event_editor_class_init, - event_editor_init, TYPE_COMP_EDITOR); - -/* Class initialization function for the event editor */ -static void -event_editor_class_init (EventEditorClass *klass) -{ - GObjectClass *gobject_class; - CompEditorClass *editor_class; - - gobject_class = (GObjectClass *) klass; - editor_class = (CompEditorClass *) klass; - - parent_class = g_type_class_ref(TYPE_COMP_EDITOR); - - editor_class->set_cal_client = event_editor_set_cal_client; - editor_class->edit_comp = event_editor_edit_comp; - editor_class->send_comp = event_editor_send_comp; - - gobject_class->finalize = event_editor_finalize; -} - -static void -set_menu_sens (EventEditor *ee) -{ - EventEditorPrivate *priv; - gboolean sens, existing, user, read_only; - - priv = ee->priv; - - existing = comp_editor_get_existing_org (COMP_EDITOR (ee)); - user = comp_editor_get_user_org (COMP_EDITOR (ee)); - read_only = cal_client_is_read_only (comp_editor_get_cal_client (COMP_EDITOR (ee))); - - sens = priv->meeting_shown; - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/ActionScheduleMeeting", - "sensitive", sens || read_only ? "0" : "1"); - - sens = priv->meeting_shown && existing && !user && !read_only; - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/ActionRefreshMeeting", - "sensitive", sens ? "1" : "0"); - - sens = priv->meeting_shown && existing && user && !read_only; - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/ActionCancelMeeting", - "sensitive", sens? "1" : "0"); - - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/FileSave", - "sensitive", read_only ? "0" : "1"); - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/FileSaveAndClose", - "sensitive", read_only ? "0" : "1"); - comp_editor_set_ui_prop (COMP_EDITOR (ee), - "/commands/FileDelete", - "sensitive", read_only ? "0" : "1"); -} - -static void -init_widgets (EventEditor *ee) -{ - EventEditorPrivate *priv; - - priv = ee->priv; - - g_signal_connect((priv->model), "model_row_changed", - G_CALLBACK (model_row_changed_cb), ee); - g_signal_connect((priv->model), "model_rows_inserted", - G_CALLBACK (row_count_changed_cb), ee); - g_signal_connect((priv->model), "model_rows_deleted", - G_CALLBACK (row_count_changed_cb), ee); -} - -/* Object initialization function for the event editor */ -static void -event_editor_init (EventEditor *ee) -{ - EventEditorPrivate *priv; - - priv = g_new0 (EventEditorPrivate, 1); - ee->priv = priv; - - priv->model = E_MEETING_MODEL (e_meeting_model_new ()); - priv->meeting_shown = TRUE; - priv->updating = FALSE; -} - -EventEditor * -event_editor_construct (EventEditor *ee, CalClient *client) -{ - EventEditorPrivate *priv; - - priv = ee->priv; - - priv->event_page = event_page_new (); - g_object_ref (priv->event_page); - gtk_object_sink (GTK_OBJECT (priv->event_page)); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->event_page), - _("Appointment")); - - priv->alarm_page = alarm_page_new (); - g_object_ref (priv->alarm_page); - gtk_object_sink (GTK_OBJECT (priv->alarm_page)); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->alarm_page), - _("Reminder")); - - priv->recur_page = recurrence_page_new (); - g_object_ref (priv->recur_page); - gtk_object_sink (GTK_OBJECT (priv->recur_page)); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->recur_page), - _("Recurrence")); - - priv->sched_page = schedule_page_new (priv->model); - g_object_ref (priv->sched_page); - gtk_object_sink (GTK_OBJECT (priv->sched_page)); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->sched_page), - _("Scheduling")); - - priv->meet_page = meeting_page_new (priv->model, client); - g_object_ref (priv->meet_page); - gtk_object_sink (GTK_OBJECT (priv->meet_page)); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->meet_page), - _("Meeting")); - - comp_editor_set_cal_client (COMP_EDITOR (ee), client); - - comp_editor_merge_ui (COMP_EDITOR (ee), "evolution-event-editor.xml", verbs, pixmaps); - - init_widgets (ee); - set_menu_sens (ee); - - return ee; -} - -static void -event_editor_set_cal_client (CompEditor *editor, CalClient *client) -{ - EventEditor *ee; - EventEditorPrivate *priv; - - ee = EVENT_EDITOR (editor); - priv = ee->priv; - - e_meeting_model_set_cal_client (priv->model, client); - - if (parent_class->set_cal_client) - parent_class->set_cal_client (editor, client); -} - -static void -event_editor_edit_comp (CompEditor *editor, CalComponent *comp) -{ - EventEditor *ee; - EventEditorPrivate *priv; - CalComponentOrganizer organizer; - CalClient *client; - GSList *attendees = NULL; - - ee = EVENT_EDITOR (editor); - priv = ee->priv; - - priv->updating = TRUE; - - if (parent_class->edit_comp) - parent_class->edit_comp (editor, comp); - - client = comp_editor_get_cal_client (COMP_EDITOR (editor)); - - /* Get meeting related stuff */ - cal_component_get_organizer (comp, &organizer); - cal_component_get_attendee_list (comp, &attendees); - - /* Clear things up */ - e_meeting_model_remove_all_attendees (priv->model); - - /* Set up the attendees */ - if (attendees == NULL) { - comp_editor_remove_page (editor, COMP_EDITOR_PAGE (priv->meet_page)); - comp_editor_remove_page (editor, COMP_EDITOR_PAGE (priv->sched_page)); - priv->meeting_shown = FALSE; - } else { - GSList *l; - int row; - - if (!priv->meeting_shown) { - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->sched_page), - _("Scheduling")); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->meet_page), - _("Meeting")); - } - - for (l = attendees; l != NULL; l = l->next) { - CalComponentAttendee *ca = l->data; - EMeetingAttendee *ia; - - ia = E_MEETING_ATTENDEE (e_meeting_attendee_new_from_cal_component_attendee (ca)); - - /* If we aren't the organizer or the attendee is just delegating, don't allow editing */ - if (!comp_editor_get_user_org (editor) || e_meeting_attendee_is_set_delto (ia)) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_NONE); - e_meeting_model_add_attendee (priv->model, ia); - - g_object_unref(ia); - } - - /* If we aren't the organizer we can still change our own status */ - if (!comp_editor_get_user_org (editor)) { - EAccountList *accounts; - EAccount *account; - EIterator *it; - - accounts = itip_addresses_get (); - for (it = e_list_get_iterator((EList *)accounts);e_iterator_is_valid(it);e_iterator_next(it)) { - EMeetingAttendee *ia; - - account = (EAccount*)e_iterator_get(it); - - ia = e_meeting_model_find_attendee (priv->model, account->id->address, &row); - if (ia != NULL) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS); - } - g_object_unref(it); - } else if (cal_client_get_organizer_must_attend (client)) { - EMeetingAttendee *ia; - - ia = e_meeting_model_find_attendee (priv->model, organizer.value, &row); - if (ia != NULL) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_NONE); - } - - priv->meeting_shown = TRUE; - } - cal_component_free_attendee_list (attendees); - - set_menu_sens (ee); - comp_editor_set_needs_send (COMP_EDITOR (ee), priv->meeting_shown && itip_organizer_is_user (comp, client)); - - priv->updating = FALSE; -} - -static gboolean -event_editor_send_comp (CompEditor *editor, CalComponentItipMethod method) -{ - EventEditor *ee = EVENT_EDITOR (editor); - EventEditorPrivate *priv; - CalComponent *comp = NULL; - - priv = ee->priv; - - /* Don't cancel more than once or when just publishing */ - if (method == CAL_COMPONENT_METHOD_PUBLISH || - method == CAL_COMPONENT_METHOD_CANCEL) - goto parent; - - comp = meeting_page_get_cancel_comp (priv->meet_page); - if (comp != NULL) { - CalClient *client; - gboolean result; - - client = e_meeting_model_get_cal_client (priv->model); - result = itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, comp, client, NULL); - g_object_unref((comp)); - - if (!result) - return FALSE; - } - - parent: - if (parent_class->send_comp) - return parent_class->send_comp (editor, method); - - return FALSE; -} - -/* Destroy handler for the event editor */ -static void -event_editor_finalize (GObject *object) -{ - EventEditor *ee; - EventEditorPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_EVENT_EDITOR (object)); - - ee = EVENT_EDITOR (object); - priv = ee->priv; - - g_object_unref((priv->event_page)); - g_object_unref((priv->alarm_page)); - g_object_unref((priv->recur_page)); - g_object_unref((priv->meet_page)); - g_object_unref((priv->sched_page)); - - g_object_unref (priv->model); - - g_free (priv); - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -/** - * event_editor_new: - * @client: a CalClient - * - * Creates a new event editor dialog. - * - * Return value: A newly-created event editor dialog, or NULL if the event - * editor could not be created. - **/ -EventEditor * -event_editor_new (CalClient *client) -{ - EventEditor *ee; - - ee = EVENT_EDITOR (g_object_new (TYPE_EVENT_EDITOR, NULL)); - return event_editor_construct (ee, client); -} - -static void -show_meeting (EventEditor *ee) -{ - EventEditorPrivate *priv; - - priv = ee->priv; - - if (!priv->meeting_shown) { - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->sched_page), - _("Scheduling")); - comp_editor_append_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->meet_page), - _("Meeting")); - priv->meeting_shown = TRUE; - - set_menu_sens (ee); - comp_editor_set_changed (COMP_EDITOR (ee), priv->meeting_shown); - comp_editor_set_needs_send (COMP_EDITOR (ee), priv->meeting_shown); - } - - comp_editor_show_page (COMP_EDITOR (ee), - COMP_EDITOR_PAGE (priv->meet_page)); -} - -void -event_editor_show_meeting (EventEditor *ee) -{ - g_return_if_fail (ee != NULL); - g_return_if_fail (IS_EVENT_EDITOR (ee)); - - - show_meeting (ee); -} - -static void -schedule_meeting_cmd (GtkWidget *widget, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - - show_meeting (ee); -} - -static void -refresh_meeting_cmd (GtkWidget *widget, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - - comp_editor_send_comp (COMP_EDITOR (ee), CAL_COMPONENT_METHOD_REFRESH); -} - -static void -cancel_meeting_cmd (GtkWidget *widget, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - CalComponent *comp; - - comp = comp_editor_get_current_comp (COMP_EDITOR (ee)); - if (cancel_component_dialog (comp_editor_get_cal_client (COMP_EDITOR (ee)), comp, FALSE)) { - comp_editor_send_comp (COMP_EDITOR (ee), CAL_COMPONENT_METHOD_CANCEL); - comp_editor_delete_comp (COMP_EDITOR (ee)); - } -} - -static void -forward_cmd (GtkWidget *widget, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - - if (comp_editor_save_comp (COMP_EDITOR (ee), TRUE)) - comp_editor_send_comp (COMP_EDITOR (ee), CAL_COMPONENT_METHOD_PUBLISH); -} - -static void -model_row_changed_cb (ETableModel *etm, int row, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - EventEditorPrivate *priv; - - priv = ee->priv; - - if (!priv->updating) { - comp_editor_set_changed (COMP_EDITOR (ee), TRUE); - comp_editor_set_needs_send (COMP_EDITOR (ee), TRUE); - } -} - -static void -row_count_changed_cb (ETableModel *etm, int row, int count, gpointer data) -{ - EventEditor *ee = EVENT_EDITOR (data); - EventEditorPrivate *priv; - - priv = ee->priv; - - if (!priv->updating) { - comp_editor_set_changed (COMP_EDITOR (ee), TRUE); - comp_editor_set_needs_send (COMP_EDITOR (ee), TRUE); - } -} diff --git a/calendar/gui/dialogs/event-editor.h b/calendar/gui/dialogs/event-editor.h deleted file mode 100644 index e0ce5043d8..0000000000 --- a/calendar/gui/dialogs/event-editor.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Evolution calendar - Event editor dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 __EVENT_EDITOR_H__ -#define __EVENT_EDITOR_H__ - -#include <gtk/gtkobject.h> -#include "comp-editor.h" - - - -#define TYPE_EVENT_EDITOR (event_editor_get_type ()) -#define EVENT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_EVENT_EDITOR, EventEditor)) -#define EVENT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_EVENT_EDITOR, EventEditorClass)) -#define IS_EVENT_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_EVENT_EDITOR)) -#define IS_EVENT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_EVENT_EDITOR)) - -typedef struct _EventEditor EventEditor; -typedef struct _EventEditorClass EventEditorClass; -typedef struct _EventEditorPrivate EventEditorPrivate; - -struct _EventEditor { - CompEditor parent; - - /* Private data */ - EventEditorPrivate *priv; -}; - -struct _EventEditorClass { - CompEditorClass parent_class; -}; - -GtkType event_editor_get_type (void); -EventEditor *event_editor_construct (EventEditor *ee, - CalClient *client); -EventEditor *event_editor_new (CalClient *client); -void event_editor_show_meeting (EventEditor *ee); - - - -#endif /* __EVENT_EDITOR_H__ */ diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c deleted file mode 100644 index b55e67dedd..0000000000 --- a/calendar/gui/dialogs/event-page.c +++ /dev/null @@ -1,1375 +0,0 @@ -/* Evolution calendar - Main page of the event editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktextview.h> -#include <gtk/gtktogglebutton.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <gal/widgets/e-categories.h> -#include "e-util/e-categories-config.h" -#include "e-util/e-dialog-widgets.h" -#include "widgets/misc/e-dateedit.h" -#include "cal-util/timeutil.h" -#include "../calendar-config.h" -#include "../e-timezone-entry.h" -#include "comp-editor-util.h" -#include "event-page.h" - - - -/* Private part of the EventPage structure */ -struct _EventPagePrivate { - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - - GtkWidget *main; - - GtkWidget *summary; - GtkWidget *location; - - GtkWidget *start_time; - GtkWidget *end_time; - GtkWidget *start_timezone; - GtkWidget *end_timezone; - GtkWidget *all_day_event; - - GtkWidget *description; - - GtkWidget *classification_public; - GtkWidget *classification_private; - GtkWidget *classification_confidential; - - GtkWidget *show_time_frame; - GtkWidget *show_time_as_free; - GtkWidget *show_time_as_busy; - - GtkWidget *categories_btn; - GtkWidget *categories; - - gboolean updating; - - /* This is TRUE if both the start & end timezone are the same. If the - start timezone is then changed, we updated the end timezone to the - same value, since 99% of events start and end in one timezone. */ - gboolean sync_timezones; -}; - - - -static void event_page_class_init (EventPageClass *class); -static void event_page_init (EventPage *epage); -static void event_page_finalize (GObject *object); - -static GtkWidget *event_page_get_widget (CompEditorPage *page); -static void event_page_focus_main_widget (CompEditorPage *page); -static void event_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean event_page_fill_component (CompEditorPage *page, CalComponent *comp); -static void event_page_set_summary (CompEditorPage *page, const char *summary); -static void event_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * event_page_get_type: - * - * Registers the #EventPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #EventPage class. - **/ - -E_MAKE_TYPE (event_page, "EventPage", EventPage, event_page_class_init, event_page_init, - TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the event page */ -static void -event_page_class_init (EventPageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref (TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = event_page_get_widget; - editor_page_class->focus_main_widget = event_page_focus_main_widget; - editor_page_class->fill_widgets = event_page_fill_widgets; - editor_page_class->fill_component = event_page_fill_component; - editor_page_class->set_summary = event_page_set_summary; - editor_page_class->set_dates = event_page_set_dates; - - object_class->finalize = event_page_finalize; -} - -/* Object initialization function for the event page */ -static void -event_page_init (EventPage *epage) -{ - EventPagePrivate *priv; - - priv = g_new0 (EventPagePrivate, 1); - epage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - priv->summary = NULL; - priv->location = NULL; - priv->start_time = NULL; - priv->end_time = NULL; - priv->start_timezone = NULL; - priv->end_timezone = NULL; - priv->all_day_event = NULL; - priv->description = NULL; - priv->classification_public = NULL; - priv->classification_private = NULL; - priv->classification_confidential = NULL; - priv->show_time_frame = NULL; - priv->show_time_as_free = NULL; - priv->show_time_as_busy = NULL; - priv->categories_btn = NULL; - priv->categories = NULL; - - priv->updating = FALSE; - priv->sync_timezones = FALSE; -} - -/* Destroy handler for the event page */ -static void -event_page_finalize (GObject *object) -{ - EventPage *epage; - EventPagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_EVENT_PAGE (object)); - - epage = EVENT_PAGE (object); - priv = epage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - g_free (priv); - epage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -static const int classification_map[] = { - CAL_COMPONENT_CLASS_PUBLIC, - CAL_COMPONENT_CLASS_PRIVATE, - CAL_COMPONENT_CLASS_CONFIDENTIAL, - -1 -}; - -static const int transparency_map[] = { - CAL_COMPONENT_TRANSP_TRANSPARENT, - CAL_COMPONENT_TRANSP_OPAQUE, - -1 -}; - -/* get_widget handler for the event page */ -static GtkWidget * -event_page_get_widget (CompEditorPage *page) -{ - EventPage *epage; - EventPagePrivate *priv; - - epage = EVENT_PAGE (page); - priv = epage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the event page */ -static void -event_page_focus_main_widget (CompEditorPage *page) -{ - EventPage *epage; - EventPagePrivate *priv; - - epage = EVENT_PAGE (page); - priv = epage->priv; - - gtk_widget_grab_focus (priv->summary); -} - -/* Sets the 'All Day Event' flag to the given value (without emitting signals), - * and shows or hides the widgets as appropriate. */ -static void -set_all_day (EventPage *epage, gboolean all_day) -{ - EventPagePrivate *priv; - - priv = epage->priv; - - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->all_day_event), - epage); - e_dialog_toggle_set (priv->all_day_event, all_day); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->all_day_event), - epage); - - e_date_edit_set_show_time (E_DATE_EDIT (priv->start_time), !all_day); - e_date_edit_set_show_time (E_DATE_EDIT (priv->end_time), !all_day); - - /* DATE values do not have timezones, so we hide the fields. */ - if (all_day) { - gtk_widget_hide (priv->start_timezone); - gtk_widget_hide (priv->end_timezone); - } else { - gtk_widget_show (priv->start_timezone); - gtk_widget_show (priv->end_timezone); - } -} - -static void -update_time (EventPage *epage, CalComponentDateTime *start_date, CalComponentDateTime *end_date) -{ - EventPagePrivate *priv; - struct icaltimetype *start_tt, *end_tt, implied_tt; - icaltimezone *start_zone = NULL, *end_zone = NULL; - CalClientGetStatus status; - gboolean all_day_event; - - priv = epage->priv; - - /* Note that if we are creating a new event, the timezones may not be - on the server, so we try to get the builtin timezone with the TZID - first. */ - start_zone = icaltimezone_get_builtin_timezone_from_tzid (start_date->tzid); - if (!start_zone) { - status = cal_client_get_timezone (COMP_EDITOR_PAGE (epage)->client, - start_date->tzid, - &start_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - start_date->tzid ? start_date->tzid : ""); - } - - end_zone = icaltimezone_get_builtin_timezone_from_tzid (end_date->tzid); - if (!end_zone) { - status = cal_client_get_timezone (COMP_EDITOR_PAGE (epage)->client, - end_date->tzid, - &end_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - end_date->tzid ? end_date->tzid : ""); - } - - /* If both times are DATE values, we set the 'All Day Event' checkbox. - Also, if DTEND is after DTSTART, we subtract 1 day from it. */ - all_day_event = FALSE; - start_tt = start_date->value; - end_tt = end_date->value; - if (!end_tt && start_tt->is_date) { - end_tt = &implied_tt; - *end_tt = *start_tt; - icaltime_adjust (end_tt, 1, 0, 0, 0); - } - - if (start_tt->is_date && end_tt->is_date) { - all_day_event = TRUE; - if (icaltime_compare_date_only (*end_tt, *start_tt) > 0) { - icaltime_adjust (end_tt, -1, 0, 0, 0); - } - } - - set_all_day (epage, all_day_event); - - /* If it is an all day event, we set both timezones to the current - timezone, so that if the user toggles the 'All Day Event' checkbox - the event uses the current timezone rather than none at all. */ - if (all_day_event) { - char *location = calendar_config_get_timezone (); - start_zone = end_zone = icaltimezone_get_builtin_timezone (location); - } - - - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_time), - epage); - g_signal_handlers_block_matched (priv->end_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - - e_date_edit_set_date (E_DATE_EDIT (priv->start_time), start_tt->year, - start_tt->month, start_tt->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_time), - start_tt->hour, start_tt->minute); - - e_date_edit_set_date (E_DATE_EDIT (priv->end_time), end_tt->year, - end_tt->month, end_tt->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->end_time), - end_tt->hour, end_tt->minute); - - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_time), - epage); - - /* Set the timezones, and set sync_timezones to TRUE if both timezones - are the same. */ - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_timezone), - epage); - g_signal_handlers_block_matched (priv->end_timezone, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), - start_zone); - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), - end_zone); - - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_timezone), - epage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_timezone), - epage); - - priv->sync_timezones = (start_zone == end_zone) ? TRUE : FALSE; - -} - -/* Fills the widgets with default values */ -static void -clear_widgets (EventPage *epage) -{ - EventPagePrivate *priv; - - priv = epage->priv; - - /* Summary, description */ - e_dialog_editable_set (priv->summary, NULL); - e_dialog_editable_set (priv->location, NULL); - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)), "", 0); - - /* Start and end times */ - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_time), - epage); - g_signal_handlers_block_matched (priv->end_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - - e_date_edit_set_time (E_DATE_EDIT (priv->start_time), 0); - e_date_edit_set_time (E_DATE_EDIT (priv->end_time), 0); - - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_time), - epage); - - set_all_day (epage, FALSE); - - /* Classification */ - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PRIVATE, classification_map); - - /* Show Time As (Transparency) */ - e_dialog_radio_set (priv->show_time_as_free, - CAL_COMPONENT_TRANSP_OPAQUE, transparency_map); - - /* Categories */ - e_dialog_editable_set (priv->categories, NULL); -} - - -/* fill_widgets handler for the event page */ -static void -event_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - EventPage *epage; - EventPagePrivate *priv; - CalComponentText text; - CalComponentClassification cl; - CalComponentTransparency transparency; - CalComponentDateTime start_date, end_date; - const char *location; - const char *categories; - GSList *l; - - g_return_if_fail (page->client != NULL); - - epage = EVENT_PAGE (page); - priv = epage->priv; - - /* Don't send off changes during this time */ - priv->updating = TRUE; - - /* Clean the page */ - clear_widgets (epage); - - /* Summary, location, description(s) */ - - cal_component_get_summary (comp, &text); - e_dialog_editable_set (priv->summary, text.value); - - cal_component_get_location (comp, &location); - e_dialog_editable_set (priv->location, location); - - cal_component_get_description_list (comp, &l); - if (l) { - text = *(CalComponentText *)l->data; - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)), - text.value, -1); - } - cal_component_free_text_list (l); - - /* Start and end times */ - - cal_component_get_dtstart (comp, &start_date); - cal_component_get_dtend (comp, &end_date); - - update_time (epage, &start_date, &end_date); - - cal_component_free_datetime (&start_date); - cal_component_free_datetime (&end_date); - - /* Classification */ - - cal_component_get_classification (comp, &cl); - - switch (cl) { - case CAL_COMPONENT_CLASS_PUBLIC: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PUBLIC, - classification_map); - break; - - case CAL_COMPONENT_CLASS_PRIVATE: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PRIVATE, - classification_map); - break; - - case CAL_COMPONENT_CLASS_CONFIDENTIAL: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_CONFIDENTIAL, - classification_map); - break; - - default: - /* default to PUBLIC */ - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PUBLIC, - classification_map); - break; - } - - - /* Show Time As (Transparency) */ - cal_component_get_transparency (comp, &transparency); - switch (transparency) { - case CAL_COMPONENT_TRANSP_TRANSPARENT: - e_dialog_radio_set (priv->show_time_as_free, - CAL_COMPONENT_TRANSP_TRANSPARENT, - transparency_map); - break; - - default: - e_dialog_radio_set (priv->show_time_as_free, - CAL_COMPONENT_TRANSP_OPAQUE, - transparency_map); - break; - } - if (cal_client_get_static_capability (page->client, CAL_STATIC_CAPABILITY_NO_TRANSPARENCY)) - gtk_widget_hide (priv->show_time_frame); - else - gtk_widget_show (priv->show_time_frame); - - /* Categories */ - cal_component_get_categories (comp, &categories); - e_dialog_editable_set (priv->categories, categories); - - priv->updating = FALSE; -} - -/* fill_component handler for the event page */ -static gboolean -event_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - EventPage *epage; - EventPagePrivate *priv; - CalComponentDateTime start_date, end_date; - struct icaltimetype start_tt, end_tt; - gboolean all_day_event, start_date_set, end_date_set; - char *cat, *str; - CalComponentClassification classif; - CalComponentTransparency transparency; - GtkTextBuffer *text_buffer; - GtkTextIter text_iter_start, text_iter_end; - - epage = EVENT_PAGE (page); - priv = epage->priv; - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)); - - /* Summary */ - - str = e_dialog_editable_get (priv->summary); - if (!str || strlen (str) == 0) - cal_component_set_summary (comp, NULL); - else { - CalComponentText text; - - text.value = str; - text.altrep = NULL; - - cal_component_set_summary (comp, &text); - } - - if (str) - g_free (str); - - /* Location */ - - str = e_dialog_editable_get (priv->location); - if (!str || strlen (str) == 0) - cal_component_set_location (comp, NULL); - else - cal_component_set_location (comp, str); - - if (str) - g_free (str); - - /* Description */ - - gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start); - gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end); - str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE); - - if (!str || strlen (str) == 0) - cal_component_set_description_list (comp, NULL); - else { - GSList l; - CalComponentText text; - - text.value = str; - text.altrep = NULL; - l.data = &text; - l.next = NULL; - - cal_component_set_description_list (comp, &l); - } - - if (str) - g_free (str); - - /* Dates */ - - start_tt = icaltime_null_time (); - start_date.value = &start_tt; - start_date.tzid = NULL; - - end_tt = icaltime_null_time (); - end_date.value = &end_tt; - end_date.tzid = NULL; - - if (!e_date_edit_date_is_valid (E_DATE_EDIT (priv->start_time))) { - comp_editor_page_display_validation_error (page, _("Start date is wrong"), priv->start_time); - return FALSE; - } - start_date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_time), - &start_tt.year, - &start_tt.month, - &start_tt.day); - g_assert (start_date_set); - - if (!e_date_edit_date_is_valid (E_DATE_EDIT (priv->end_time))) { - comp_editor_page_display_validation_error (page, _("End date is wrong"), priv->end_time); - return FALSE; - } - end_date_set = e_date_edit_get_date (E_DATE_EDIT (priv->end_time), - &end_tt.year, - &end_tt.month, - &end_tt.day); - g_assert (end_date_set); - - /* If the all_day toggle is set, we use DATE values for DTSTART and - DTEND. If not, we fetch the hour & minute from the widgets. */ - all_day_event = e_dialog_toggle_get (priv->all_day_event); - - if (all_day_event) { - start_tt.is_date = TRUE; - end_tt.is_date = TRUE; - - /* We have to add 1 day to DTEND, as it is not inclusive. */ - icaltime_adjust (&end_tt, 1, 0, 0, 0); - } else { - icaltimezone *start_zone, *end_zone; - - if (!e_date_edit_time_is_valid (E_DATE_EDIT (priv->start_time))) { - comp_editor_page_display_validation_error (page, _("Start time is wrong"), priv->start_time); - return FALSE; - } - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_time), - &start_tt.hour, - &start_tt.minute); - if (!e_date_edit_time_is_valid (E_DATE_EDIT (priv->end_time))) { - comp_editor_page_display_validation_error (page, _("End time is wrong"), priv->end_time); - return FALSE; - } - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->end_time), - &end_tt.hour, - &end_tt.minute); - start_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - start_date.tzid = icaltimezone_get_tzid (start_zone); - end_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->end_timezone)); - end_date.tzid = icaltimezone_get_tzid (end_zone); - } - - cal_component_set_dtstart (comp, &start_date); - cal_component_set_dtend (comp, &end_date); - - - /* Categories */ - - cat = e_dialog_editable_get (priv->categories); - str = comp_editor_strip_categories (cat); - if (cat) - g_free (cat); - - cal_component_set_categories (comp, str); - - if (str) - g_free (str); - - /* Classification */ - - classif = e_dialog_radio_get (priv->classification_public, - classification_map); - cal_component_set_classification (comp, classif); - - /* Show Time As (Transparency) */ - - transparency = e_dialog_radio_get (priv->show_time_as_free, - transparency_map); - cal_component_set_transparency (comp, transparency); - - return TRUE; -} - -/* set_summary handler for the event page */ -static void -event_page_set_summary (CompEditorPage *page, const char *summary) -{ - /* nothing */ -} - -static void -event_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - update_time (EVENT_PAGE (page), dates->start, dates->end); -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (EventPage *epage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (epage); - EventPagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = epage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("event-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - priv->summary = GW ("general-summary"); - priv->location = GW ("location"); - - /* Glade's visibility flag doesn't seem to work for custom widgets */ - priv->start_time = GW ("start-time"); - gtk_widget_show (priv->start_time); - priv->end_time = GW ("end-time"); - gtk_widget_show (priv->end_time); - - priv->start_timezone = GW ("start-timezone"); - priv->end_timezone = GW ("end-timezone"); - priv->all_day_event = GW ("all-day-event"); - - priv->description = GW ("description"); - - priv->classification_public = GW ("classification-public"); - priv->classification_private = GW ("classification-private"); - priv->classification_confidential = GW ("classification-confidential"); - - priv->show_time_frame = GW ("show-time-frame"); - priv->show_time_as_free = GW ("show-time-as-free"); - priv->show_time_as_busy = GW ("show-time-as-busy"); - - priv->categories_btn = GW ("categories-button"); - priv->categories = GW ("categories"); - -#undef GW - - return (priv->summary - && priv->location - && priv->start_time - && priv->end_time - && priv->start_timezone - && priv->end_timezone - && priv->all_day_event - && priv->description - && priv->classification_public - && priv->classification_private - && priv->classification_confidential - && priv->show_time_frame - && priv->show_time_as_free - && priv->show_time_as_busy - && priv->categories_btn - && priv->categories); -} - -/* Callback used when the summary changes; we emit the notification signal. */ -static void -summary_changed_cb (GtkEditable *editable, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - gchar *summary; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - if (priv->updating) - return; - - summary = e_dialog_editable_get (GTK_WIDGET (editable)); - comp_editor_page_notify_summary_changed (COMP_EDITOR_PAGE (epage), - summary); - g_free (summary); -} - - -/* Note that this assumes that the start_tt and end_tt passed to it are the - dates visible to the user. For DATE values, we have to add 1 day to the - end_tt before emitting the signal. */ -static void -notify_dates_changed (EventPage *epage, struct icaltimetype *start_tt, - struct icaltimetype *end_tt) -{ - EventPagePrivate *priv; - CompEditorPageDates dates; - CalComponentDateTime start_dt, end_dt; - gboolean all_day_event; - icaltimezone *start_zone = NULL, *end_zone = NULL; - - priv = epage->priv; - - all_day_event = e_dialog_toggle_get (priv->all_day_event); - - start_dt.value = start_tt; - end_dt.value = end_tt; - - if (all_day_event) { - /* The actual DTEND is 1 day after the displayed date for - DATE values. */ - icaltime_adjust (end_tt, 1, 0, 0, 0); - } else { - start_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - end_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->end_timezone)); - } - - start_dt.tzid = start_zone ? icaltimezone_get_tzid (start_zone) : NULL; - end_dt.tzid = end_zone ? icaltimezone_get_tzid (end_zone) : NULL; - - dates.start = &start_dt; - dates.end = &end_dt; - - dates.due = NULL; - dates.complete = NULL; - - comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (epage), - &dates); -} - - -static gboolean -check_start_before_end (struct icaltimetype *start_tt, - icaltimezone *start_zone, - struct icaltimetype *end_tt, - icaltimezone *end_zone, - gboolean adjust_end_time) -{ - struct icaltimetype end_tt_copy; - int cmp; - - /* Convert the end time to the same timezone as the start time. */ - end_tt_copy = *end_tt; - icaltimezone_convert_time (&end_tt_copy, end_zone, start_zone); - - /* Now check if the start time is after the end time. If it is, - we need to modify one of the times. */ - cmp = icaltime_compare (*start_tt, end_tt_copy); - if (cmp > 0) { - if (adjust_end_time) { - /* Modify the end time, to be the start + 1 hour. */ - *end_tt = *start_tt; - icaltime_adjust (end_tt, 0, 1, 0, 0); - icaltimezone_convert_time (end_tt, start_zone, - end_zone); - } else { - /* Modify the start time, to be the end - 1 hour. */ - *start_tt = *end_tt; - icaltime_adjust (start_tt, 0, -1, 0, 0); - icaltimezone_convert_time (start_tt, end_zone, - start_zone); - } - return TRUE; - } - - return FALSE; -} - - -/* - * This is called whenever the start or end dates or timezones is changed. - * It makes sure that the start date < end date. It also emits the notification - * signals so the other event editor pages update their labels etc. - * - * If adjust_end_time is TRUE, if the start time < end time it will adjust - * the end time. If FALSE it will adjust the start time. If the user sets the - * start or end time, the other time is adjusted to make it valid. - */ -static void -times_updated (EventPage *epage, gboolean adjust_end_time) -{ - EventPagePrivate *priv; - struct icaltimetype start_tt = icaltime_null_time(); - struct icaltimetype end_tt = icaltime_null_time(); - gboolean date_set, all_day_event; - gboolean set_start_date = FALSE, set_end_date = FALSE; - icaltimezone *start_zone, *end_zone; - - priv = epage->priv; - - if (priv->updating) - return; - - /* Fetch the start and end times and timezones from the widgets. */ - all_day_event = e_dialog_toggle_get (priv->all_day_event); - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_time), - &start_tt.year, - &start_tt.month, - &start_tt.day); - g_assert (date_set); - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->end_time), - &end_tt.year, - &end_tt.month, - &end_tt.day); - g_assert (date_set); - - if (all_day_event) { - /* All Day Events are simple. We just compare the dates and if - start > end we copy one of them to the other. */ - int cmp = icaltime_compare_date_only (start_tt, end_tt); - if (cmp > 0) { - if (adjust_end_time) { - end_tt = start_tt; - set_end_date = TRUE; - } else { - start_tt = end_tt; - set_start_date = TRUE; - } - } - - start_tt.is_date = TRUE; - end_tt.is_date = TRUE; - } else { - /* For DATE-TIME events, we have to convert to the same - timezone before comparing. */ - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_time), - &start_tt.hour, - &start_tt.minute); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->end_time), - &end_tt.hour, - &end_tt.minute); - - start_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - end_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->end_timezone)); - - if (check_start_before_end (&start_tt, start_zone, - &end_tt, end_zone, - adjust_end_time)) { - if (adjust_end_time) - set_end_date = TRUE; - else - set_start_date = TRUE; - } - } - - - if (set_start_date) { - g_signal_handlers_block_matched (priv->start_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - e_date_edit_set_date (E_DATE_EDIT (priv->start_time), - start_tt.year, start_tt.month, - start_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_time), - start_tt.hour, start_tt.minute); - g_signal_handlers_unblock_matched (priv->start_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - } - - if (set_end_date) { - g_signal_handlers_block_matched (priv->end_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - e_date_edit_set_date (E_DATE_EDIT (priv->end_time), - end_tt.year, end_tt.month, end_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->end_time), - end_tt.hour, end_tt.minute); - g_signal_handlers_unblock_matched (priv->end_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); - } - - /* Notify upstream */ - notify_dates_changed (epage, &start_tt, &end_tt); -} - -/* Callback used when the start or end date widgets change. We check that the - * start date < end date and we set the "all day event" button as appropriate. - */ -static void -date_changed_cb (GtkWidget *dedit, gpointer data) -{ - EventPage *epage; - - epage = EVENT_PAGE (data); - - times_updated (epage, dedit == epage->priv->start_time); -} - - -/* Callback used when the start timezone is changed. If sync_timezones is set, - * we set the end timezone to the same value. It also updates the start time - * labels on the other notebook pages. - */ -static void -start_timezone_changed_cb (GtkWidget *widget, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - icaltimezone *zone; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - if (priv->sync_timezones) { - zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - priv->updating = TRUE; - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), zone); - priv->updating = FALSE; - } - - times_updated (epage, TRUE); -} - - -/* Callback used when the end timezone is changed. It checks if the end - * timezone is the same as the start timezone and sets sync_timezones if so. - */ -static void -end_timezone_changed_cb (GtkWidget *widget, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - icaltimezone *start_zone, *end_zone; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - start_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - end_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->end_timezone)); - - priv->sync_timezones = (start_zone == end_zone) ? TRUE : FALSE; - - times_updated (epage, TRUE); -} - -/* Callback: all day event button toggled. - * Note that this should only be called when the user explicitly toggles the - * button. Be sure to block this handler when the toggle button's state is set - * within the code. - */ -static void -all_day_event_toggled_cb (GtkWidget *toggle, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - gboolean all_day; - struct icaltimetype start_tt = icaltime_null_time(); - struct icaltimetype end_tt = icaltime_null_time(); - gboolean date_set; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - /* When the all_day toggle is turned on, the start date is - * rounded down to the start of the day, and end date is - * rounded down to the start of the day on which the event - * ends. The event is then taken to be inclusive of the days - * between the start and end days. Note that if the event end - * is at midnight, we round it down to the previous day, so the - * event times stay the same. - * - * When the all_day_toggle is turned off, then if the event is within - * one day, we set the event start to the start of the working day, - * and set the event end to one hour after it. If the event is longer - * than one day, we set the event end to the end of the day it is on, - * so that the actual event times remain the same. - * - * This may need tweaking to work well with different timezones used - * in the event start & end. - */ - all_day = GTK_TOGGLE_BUTTON (toggle)->active; - - set_all_day (epage, all_day); - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_time), - &start_tt.year, - &start_tt.month, - &start_tt.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_time), - &start_tt.hour, - &start_tt.minute); - g_assert (date_set); - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->end_time), - &end_tt.year, - &end_tt.month, - &end_tt.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->end_time), - &end_tt.hour, - &end_tt.minute); - g_assert (date_set); - - if (all_day) { - /* Round down to the start of the day. */ - start_tt.hour = 0; - start_tt.minute = 0; - start_tt.second = 0; - start_tt.is_date = TRUE; - - /* Round down to the start of the day, or the start of the - previous day if it is midnight. */ - icaltime_adjust (&end_tt, 0, 0, 0, -1); - end_tt.hour = 0; - end_tt.minute = 0; - end_tt.second = 0; - end_tt.is_date = TRUE; - } else { - icaltimezone *start_zone, *end_zone; - - if (end_tt.year == start_tt.year - && end_tt.month == start_tt.month - && end_tt.day == start_tt.day) { - /* The event is within one day, so we set the event - start to the start of the working day, and the end - to one hour later. */ - start_tt.hour = calendar_config_get_day_start_hour (); - start_tt.minute = calendar_config_get_day_start_minute (); - start_tt.second = 0; - - end_tt = start_tt; - icaltime_adjust (&end_tt, 0, 1, 0, 0); - } else { - /* The event is longer than 1 day, so we keep exactly - the same times, just using DATE-TIME rather than - DATE. */ - icaltime_adjust (&end_tt, 1, 0, 0, 0); - } - - /* Make sure that end > start using the timezones. */ - start_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - end_zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->end_timezone)); - check_start_before_end (&start_tt, start_zone, - &end_tt, end_zone, - TRUE); - } - - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->end_time), - epage); - - e_date_edit_set_date (E_DATE_EDIT (priv->start_time), start_tt.year, - start_tt.month, start_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_time), - start_tt.hour, start_tt.minute); - - e_date_edit_set_date (E_DATE_EDIT (priv->end_time), end_tt.year, - end_tt.month, end_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->end_time), - end_tt.hour, end_tt.minute); - - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->start_time), - epage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->end_time), - epage); - - /* Notify upstream */ - notify_dates_changed (epage, &start_tt, &end_tt); -} - -/* Callback used when the categories button is clicked; we must bring up the - * category list dialog. - */ -static void -categories_clicked_cb (GtkWidget *button, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - GtkWidget *entry; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - entry = priv->categories; - e_categories_config_open_dialog_for_entry (GTK_ENTRY (entry)); -} - -/* This is called when any field is changed; it notifies upstream. */ -static void -field_changed_cb (GtkWidget *widget, gpointer data) -{ - EventPage *epage; - EventPagePrivate *priv; - - epage = EVENT_PAGE (data); - priv = epage->priv; - - if (!priv->updating) - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (epage)); -} - -/* Hooks the widget signals */ -static gboolean -init_widgets (EventPage *epage) -{ - EventPagePrivate *priv; - GtkTextBuffer *text_buffer; - char *location; - icaltimezone *zone; - - priv = epage->priv; - - /* Make sure the EDateEdit widgets use our timezones to get the - current time. */ - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->start_time), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - epage, NULL); - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->end_time), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - epage, NULL); - - /* Summary */ - g_signal_connect((priv->summary), "changed", - G_CALLBACK (summary_changed_cb), epage); - - /* Description */ - text_buffer = gtk_text_buffer_new (NULL); - gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->description), text_buffer); - g_object_unref (text_buffer); - - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->description), GTK_WRAP_WORD); - - /* Start and end times */ - g_signal_connect((priv->start_time), "changed", - G_CALLBACK (date_changed_cb), epage); - g_signal_connect((priv->end_time), "changed", - G_CALLBACK (date_changed_cb), epage); - - g_signal_connect((priv->start_timezone), "changed", - G_CALLBACK (start_timezone_changed_cb), epage); - g_signal_connect((priv->end_timezone), "changed", - G_CALLBACK (end_timezone_changed_cb), epage); - - g_signal_connect((priv->all_day_event), "toggled", - G_CALLBACK (all_day_event_toggled_cb), epage); - - /* Categories button */ - g_signal_connect((priv->categories_btn), "clicked", - G_CALLBACK (categories_clicked_cb), epage); - - /* Connect the default signal handler to use to make sure we notify - * upstream of changes to the widget values. - */ - - /* Belongs to priv->description */ - g_signal_connect((text_buffer), "changed", - G_CALLBACK (field_changed_cb), epage); - - g_signal_connect((priv->summary), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->location), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->start_time), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->end_time), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->start_timezone), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->end_timezone), "changed", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->all_day_event), "toggled", - G_CALLBACK (field_changed_cb), epage); - g_signal_connect((priv->classification_public), - "toggled", G_CALLBACK (field_changed_cb), - epage); - g_signal_connect((priv->classification_private), - "toggled", G_CALLBACK (field_changed_cb), - epage); - g_signal_connect((priv->classification_confidential), - "toggled", G_CALLBACK (field_changed_cb), - epage); - g_signal_connect((priv->show_time_as_free), - "toggled", G_CALLBACK (field_changed_cb), - epage); - g_signal_connect((priv->show_time_as_busy), - "toggled", G_CALLBACK (field_changed_cb), - epage); - g_signal_connect((priv->categories), "changed", - G_CALLBACK (field_changed_cb), epage); - - /* Set the default timezone, so the timezone entry may be hidden. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), zone); - e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), zone); - - return TRUE; -} - - - -/** - * event_page_construct: - * @epage: An event page. - * - * Constructs an event page by loading its Glade data. - * - * Return value: The same object as @epage, or NULL if the widgets could not be - * created. - **/ -EventPage * -event_page_construct (EventPage *epage) -{ - EventPagePrivate *priv; - - priv = epage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/event-page.glade", - NULL, NULL); - if (!priv->xml) { - g_message ("event_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (epage)) { - g_message ("event_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - if (!init_widgets (epage)) { - g_message ("event_page_construct(): " - "Could not initialize the widgets!"); - return NULL; - } - - return epage; -} - -/** - * event_page_new: - * - * Creates a new event page. - * - * Return value: A newly-created event page, or NULL if the page could - * not be created. - **/ -EventPage * -event_page_new (void) -{ - EventPage *epage; - - epage = g_object_new (TYPE_EVENT_PAGE, NULL); - if (!event_page_construct (epage)) { - g_object_unref ((epage)); - return NULL; - } - - return epage; -} - -GtkWidget *make_date_edit (void); - -GtkWidget * -make_date_edit (void) -{ - return comp_editor_new_date_edit (TRUE, TRUE, TRUE); -} - -GtkWidget *make_timezone_entry (void); - -GtkWidget * -make_timezone_entry (void) -{ - GtkWidget *w; - - w = e_timezone_entry_new (); - gtk_widget_show (w); - return w; -} diff --git a/calendar/gui/dialogs/event-page.glade b/calendar/gui/dialogs/event-page.glade deleted file mode 100644 index 3217cb5634..0000000000 --- a/calendar/gui/dialogs/event-page.glade +++ /dev/null @@ -1,601 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="event-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="event-page"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkTable" id="table11"> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label56"> - <property name="visible">True</property> - <property name="label" translatable="yes">Su_mmary:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">general-summary</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="general-summary"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label61"> - <property name="visible">True</property> - <property name="label" translatable="yes">L_ocation:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">location</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="location"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame31"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkTable" id="table12"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">4</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label57"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Start time:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">start-time</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label58"> - <property name="visible">True</property> - <property name="label" translatable="yes">_End time:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">end-time</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="start-time"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="creation_function">make_date_edit</property> - <property name="string1"></property> - <property name="string2"></property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Tue, 16 May 2000 19:11:05 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="end-time"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="creation_function">make_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Tue, 16 May 2000 19:11:10 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="end-timezone"> - <property name="visible">True</property> - <property name="creation_function">make_timezone_entry</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Mon, 18 Jun 2001 23:51:40 GMT</property> - </widget> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options"></property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="Custom" id="start-timezone"> - <property name="visible">True</property> - <property name="creation_function">make_timezone_entry</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Mon, 18 Jun 2001 23:51:34 GMT</property> - </widget> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="alignment1"> - <property name="visible">True</property> - <property name="xalign">1</property> - <property name="yalign">7.45058e-09</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - - <child> - <widget class="GtkCheckButton" id="all-day-event"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">A_ll day event</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">3</property> - <property name="right_attach">4</property> - <property name="top_attach">0</property> - <property name="bottom_attach">2</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label62"> - <property name="visible">True</property> - <property name="label" translatable="yes">Date & Time</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow12"> - <property name="visible">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTextView" id="description"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="justification">GTK_JUSTIFY_LEFT</property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="cursor_visible">True</property> - <property name="pixels_above_lines">0</property> - <property name="pixels_below_lines">0</property> - <property name="pixels_inside_wrap">0</property> - <property name="left_margin">0</property> - <property name="right_margin">0</property> - <property name="indent">0</property> - <property name="text" translatable="yes"></property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox54"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame32"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox52"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkRadioButton" id="classification-public"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Pu_blic</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">True</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="classification-private"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Pri_vate</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">classification-public</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="classification-confidential"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Con_fidential</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">classification-public</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label63"> - <property name="visible">True</property> - <property name="label" translatable="yes">Classification</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="show-time-frame"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox55"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkRadioButton" id="show-time-as-free"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">F_ree</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="show-time-as-busy"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">B_usy</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">show-time-as-free</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label64"> - <property name="visible">True</property> - <property name="label" translatable="yes">Show Time As</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox53"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="categories-button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Ca_tegories...</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="categories"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/event-page.h b/calendar/gui/dialogs/event-page.h deleted file mode 100644 index a21f084e01..0000000000 --- a/calendar/gui/dialogs/event-page.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Evolution calendar - Main page of the event editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 EVENT_PAGE_H -#define EVENT_PAGE_H - -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_EVENT_PAGE (event_page_get_type ()) -#define EVENT_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_EVENT_PAGE, EventPage)) -#define EVENT_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_EVENT_PAGE, EventPageClass)) -#define IS_EVENT_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_EVENT_PAGE)) -#define IS_EVENT_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_EVENT_PAGE)) - -typedef struct _EventPagePrivate EventPagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - EventPagePrivate *priv; -} EventPage; - -typedef struct { - CompEditorPageClass parent_class; -} EventPageClass; - - -GtkType event_page_get_type (void); -EventPage *event_page_construct (EventPage *epage); -EventPage *event_page_new (void); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/meeting-page.c b/calendar/gui/dialogs/meeting-page.c deleted file mode 100644 index b511e44f01..0000000000 --- a/calendar/gui/dialogs/meeting-page.c +++ /dev/null @@ -1,924 +0,0 @@ -/* Evolution calendar - Main page of the task editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtkcombo.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkwindow.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <gal/e-table/e-cell-combo.h> -#include <gal/e-table/e-cell-text.h> -#include <gal/e-table/e-table-simple.h> -#include <gal/e-table/e-table-scrolled.h> -#include <gal/widgets/e-unicode.h> -#include <gal/widgets/e-popup-menu.h> -#include <gal/widgets/e-gui-utils.h> -#include <widgets/misc/e-dateedit.h> -#include <e-util/e-dialog-utils.h> -#include <e-util/e-dialog-widgets.h> - -#include "../calendar-component.h" -#include "../e-meeting-attendee.h" -#include "../e-meeting-model.h" -#include "../itip-utils.h" -#include "comp-editor-util.h" -#include "e-delegate-dialog.h" -#include "meeting-page.h" - - - -enum columns { - MEETING_ATTENDEE_COL, - MEETING_MEMBER_COL, - MEETING_TYPE_COL, - MEETING_ROLE_COL, - MEETING_RSVP_COL, - MEETING_DELTO_COL, - MEETING_DELFROM_COL, - MEETING_STATUS_COL, - MEETING_CN_COL, - MEETING_LANG_COL, - MEETING_COLUMN_COUNT -}; - -/* Private part of the MeetingPage structure */ -struct _MeetingPagePrivate { - /* Lists of attendees */ - GPtrArray *deleted_attendees; - - /* To use in case of cancellation */ - CalComponent *comp; - - /* List of identities */ - EAccountList *accounts; - EMeetingAttendee *ia; - char *default_address; - - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *main; - GtkWidget *organizer_table; - GtkWidget *organizer; - GtkWidget *existing_organizer_table; - GtkWidget *existing_organizer; - GtkWidget *existing_organizer_btn; - GtkWidget *invite; - - /* E Table stuff */ - EMeetingModel *model; - ETableScrolled *etable; - gint row; - - /* For handling who the organizer is */ - gboolean existing; - - gboolean updating; -}; - - - -static void meeting_page_class_init (MeetingPageClass *class); -static void meeting_page_init (MeetingPage *mpage); -static void meeting_page_finalize (GObject *object); - -static GtkWidget *meeting_page_get_widget (CompEditorPage *page); -static void meeting_page_focus_main_widget (CompEditorPage *page); -static void meeting_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean meeting_page_fill_component (CompEditorPage *page, CalComponent *comp); - -static gint right_click_cb (ETable *etable, gint row, gint col, GdkEvent *event, gpointer data); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * meeting_page_get_type: - * - * Registers the #MeetingPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #MeetingPage class. - **/ - -E_MAKE_TYPE (meeting_page, "MeetingPage", MeetingPage, meeting_page_class_init, meeting_page_init, - TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the task page */ -static void -meeting_page_class_init (MeetingPageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref (TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = meeting_page_get_widget; - editor_page_class->focus_main_widget = meeting_page_focus_main_widget; - editor_page_class->fill_widgets = meeting_page_fill_widgets; - editor_page_class->fill_component = meeting_page_fill_component; - editor_page_class->set_summary = NULL; - editor_page_class->set_dates = NULL; - - object_class->finalize = meeting_page_finalize; -} - -/* Object initialization function for the task page */ -static void -meeting_page_init (MeetingPage *mpage) -{ - MeetingPagePrivate *priv; - - priv = g_new0 (MeetingPagePrivate, 1); - mpage->priv = priv; - - priv->deleted_attendees = g_ptr_array_new (); - - priv->comp = NULL; - - priv->accounts = NULL; - priv->ia = NULL; - priv->default_address = NULL; - - priv->xml = NULL; - priv->main = NULL; - priv->invite = NULL; - - priv->model = NULL; - priv->etable = NULL; - - priv->updating = FALSE; -} - -static EAccount * -get_current_account (MeetingPage *mpage) -{ - MeetingPagePrivate *priv; - EIterator *it; - const char *str; - - priv = mpage->priv; - - str = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (priv->organizer)->entry)); - if (!str) - return NULL; - - for (it = e_list_get_iterator((EList *)priv->accounts); e_iterator_is_valid(it); e_iterator_next(it)) { - EAccount *a = (EAccount *)e_iterator_get(it); - char *full = g_strdup_printf("%s <%s>", a->id->name, a->id->address); - - if (!strcmp (full, str)) { - g_free (full); - g_object_unref (it); - - return a; - } - - g_free (full); - } - g_object_unref (it); - - return NULL; -} - -static void -set_attendees (CalComponent *comp, const GPtrArray *attendees) -{ - GSList *comp_attendees = NULL, *l; - int i; - - for (i = 0; i < attendees->len; i++) { - EMeetingAttendee *ia = g_ptr_array_index (attendees, i); - CalComponentAttendee *ca; - - ca = e_meeting_attendee_as_cal_component_attendee (ia); - - comp_attendees = g_slist_prepend (comp_attendees, ca); - - } - comp_attendees = g_slist_reverse (comp_attendees); - cal_component_set_attendee_list (comp, comp_attendees); - - for (l = comp_attendees; l != NULL; l = l->next) - g_free (l->data); - g_slist_free (comp_attendees); -} - -static void -cleanup_attendees (GPtrArray *attendees) -{ - int i; - - for (i = 0; i < attendees->len; i++) - g_object_unref((g_ptr_array_index (attendees, i))); -} - -/* Destroy handler for the task page */ -static void -meeting_page_finalize (GObject *object) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_MEETING_PAGE (object)); - - mpage = MEETING_PAGE (object); - priv = mpage->priv; - - if (priv->comp != NULL) - g_object_unref((priv->comp)); - - cleanup_attendees (priv->deleted_attendees); - g_ptr_array_free (priv->deleted_attendees, TRUE); - - if (priv->ia != NULL) - g_object_unref (priv->ia); - - g_object_unref((priv->model)); - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - if (priv->default_address) { - g_free (priv->default_address); - priv->default_address = NULL; - } - - g_free (priv); - mpage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the task page */ -static GtkWidget * -meeting_page_get_widget (CompEditorPage *page) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - mpage = MEETING_PAGE (page); - priv = mpage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the task page */ -static void -meeting_page_focus_main_widget (CompEditorPage *page) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - mpage = MEETING_PAGE (page); - priv = mpage->priv; - - gtk_widget_grab_focus (priv->organizer); -} - -/* Fills the widgets with default values */ -static void -clear_widgets (MeetingPage *mpage) -{ - MeetingPagePrivate *priv; - - priv = mpage->priv; - - gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (priv->organizer)->entry), priv->default_address); - gtk_label_set_text (GTK_LABEL (priv->existing_organizer), _("None")); - - gtk_widget_show (priv->organizer_table); - gtk_widget_hide (priv->existing_organizer_table); - - priv->existing = FALSE; -} - -/* fill_widgets handler for the meeting page */ -static void -meeting_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - CalComponentOrganizer organizer; - - mpage = MEETING_PAGE (page); - priv = mpage->priv; - - priv->updating = TRUE; - - /* Clean out old data */ - if (priv->comp != NULL) - g_object_unref((priv->comp)); - priv->comp = NULL; - - cleanup_attendees (priv->deleted_attendees); - g_ptr_array_set_size (priv->deleted_attendees, 0); - - /* Clean the screen */ - clear_widgets (mpage); - - /* Component for cancellation */ - priv->comp = cal_component_clone (comp); - - /* If there is an existing organizer show it properly */ - if (cal_component_has_organizer (comp)) { - cal_component_get_organizer (comp, &organizer); - if (organizer.value != NULL) { - const gchar *strip = itip_strip_mailto (organizer.value); - gchar *string; - - gtk_widget_hide (priv->organizer_table); - gtk_widget_show (priv->existing_organizer_table); - if (itip_organizer_is_user (comp, page->client)) { - gtk_widget_show (priv->invite); - if (cal_client_get_static_capability ( - page->client, - CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)) - gtk_widget_hide (priv->existing_organizer_btn); - e_meeting_model_etable_click_to_add (priv->model, TRUE); - } else { - if (cal_client_get_static_capability ( - page->client, - CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)) - gtk_widget_hide (priv->existing_organizer_btn); - gtk_widget_hide (priv->invite); - e_meeting_model_etable_click_to_add (priv->model, FALSE); - } - - if (organizer.cn != NULL) - string = g_strdup_printf ("%s <%s>", organizer.cn, strip); - else - string = g_strdup (strip); - gtk_label_set_text (GTK_LABEL (priv->existing_organizer), string); - g_free (string); - - priv->existing = TRUE; - } - } else { - EAccount *a; - - a = get_current_account (mpage); - if (a != NULL) { - priv->ia = e_meeting_model_add_attendee_with_defaults (priv->model); - g_object_ref (priv->ia); - - e_meeting_attendee_set_address (priv->ia, g_strdup_printf ("MAILTO:%s", a->id->address)); - e_meeting_attendee_set_cn (priv->ia, g_strdup (a->id->name)); - e_meeting_attendee_set_status (priv->ia, ICAL_PARTSTAT_ACCEPTED); - } - } - - priv->updating = FALSE; -} - -/* fill_component handler for the meeting page */ -static gboolean -meeting_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - CalComponentOrganizer organizer = {NULL, NULL, NULL, NULL}; - - mpage = MEETING_PAGE (page); - priv = mpage->priv; - - if (!priv->existing) { - EAccount *a; - gchar *addr = NULL; - - /* Find the identity for the organizer or sentby field */ - a = get_current_account (mpage); - - /* Sanity Check */ - if (a == NULL) { - e_notice (page, GTK_MESSAGE_ERROR, - _("The organizer selected no longer has an account.")); - return FALSE; - } - - if (a->id->address == NULL || strlen (a->id->address) == 0) { - e_notice (page, GTK_MESSAGE_ERROR, - _("An organizer is required.")); - return FALSE; - } - - addr = g_strdup_printf ("MAILTO:%s", a->id->address); - - organizer.value = addr; - organizer.cn = a->id->name; - cal_component_set_organizer (comp, &organizer); - - g_free (addr); - } - - if (e_meeting_model_count_actual_attendees (priv->model) < 1) { - e_notice (page, GTK_MESSAGE_ERROR, - _("At least one attendee is required.")); - return FALSE; - } - set_attendees (comp, e_meeting_model_get_attendees (priv->model)); - - return TRUE; -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (MeetingPage *mpage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (mpage); - MeetingPagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = mpage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("meeting-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - /* For making the user the organizer */ - priv->organizer_table = GW ("organizer-table"); - priv->organizer = GW ("organizer"); - gtk_combo_set_value_in_list (GTK_COMBO (priv->organizer), TRUE, FALSE); - - /* For showing existing organizers */ - priv->existing_organizer_table = GW ("existing-organizer-table"); - priv->existing_organizer = GW ("existing-organizer"); - priv->existing_organizer_btn = GW ("existing-organizer-button"); - priv->invite = GW ("invite"); - -#undef GW - - return (priv->invite - && priv->organizer_table - && priv->organizer - && priv->existing_organizer_table - && priv->existing_organizer - && priv->existing_organizer_btn); -} - -static void -org_changed_cb (GtkWidget *widget, gpointer data) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - mpage = MEETING_PAGE (data); - priv = mpage->priv; - - if (priv->updating) - return; - - if (!priv->existing && priv->ia != NULL) { - EAccount *a; - - a = get_current_account (mpage); - if (a != NULL) { - e_meeting_attendee_set_address (priv->ia, g_strdup_printf ("MAILTO:%s", a->id->address)); - e_meeting_attendee_set_cn (priv->ia, g_strdup (a->id->name)); - - if (!e_meeting_model_find_attendee (priv->model, e_meeting_attendee_get_address (priv->ia), NULL)) - e_meeting_model_add_attendee (priv->model, priv->ia); - } else { - e_meeting_model_remove_attendee (priv->model, priv->ia); - } - } - - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (mpage)); -} - -/* Function called to change the organizer */ -static void -change_clicked_cb (GtkWidget *widget, gpointer data) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - mpage = MEETING_PAGE (data); - priv = mpage->priv; - - gtk_widget_show (priv->organizer_table); - gtk_widget_hide (priv->existing_organizer_table); - gtk_widget_show (priv->invite); - e_meeting_model_etable_click_to_add (priv->model, TRUE); - - comp_editor_page_notify_needs_send (COMP_EDITOR_PAGE (mpage)); - - priv->existing = FALSE; -} - -/* Function called to invite more people */ -static void -invite_cb (GtkWidget *widget, gpointer data) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - - mpage = MEETING_PAGE (data); - priv = mpage->priv; - - e_meeting_model_invite_others_dialog (priv->model); -} - -/* Hooks the widget signals */ -static void -init_widgets (MeetingPage *mpage) -{ - MeetingPagePrivate *priv; - - priv = mpage->priv; - - /* Organizer */ - g_signal_connect((GTK_COMBO (priv->organizer)->entry), "changed", - G_CALLBACK (org_changed_cb), mpage); - - g_signal_connect((priv->existing_organizer_btn), "clicked", - G_CALLBACK (change_clicked_cb), mpage); - - /* Invite button */ - g_signal_connect((priv->invite), "clicked", - G_CALLBACK (invite_cb), mpage); -} - -#if 0 -static void -popup_delegate_cb (GtkWidget *widget, gpointer data) -{ - MeetingPage *mpage = MEETING_PAGE (data); - MeetingPagePrivate *priv; - EDelegateDialog *edd; - GtkWidget *dialog; - EMeetingAttendee *ia; - char *address = NULL, *name = NULL; - - priv = mpage->priv; - - ia = e_meeting_model_find_attendee_at_row (priv->model, priv->row); - - /* Show dialog. */ - edd = e_delegate_dialog_new (NULL, itip_strip_mailto (e_meeting_attendee_get_delto (ia))); - dialog = e_delegate_dialog_get_toplevel (edd); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK){ - EMeetingAttendee *ic; - - name = e_delegate_dialog_get_delegate_name (edd); - address = e_delegate_dialog_get_delegate (edd); - - /* Make sure we can add the new delegatee person */ - if (e_meeting_model_find_attendee (priv->model, address, NULL) != NULL) { - e_notice (mpage, GTK_MESSAGE_ERROR, - _("That person is already attending the meeting!")); - goto cleanup; - } - - /* Update information for attendee */ - if (e_meeting_attendee_is_set_delto (ia)) { - EMeetingAttendee *ib; - - ib = e_meeting_model_find_attendee (priv->model, itip_strip_mailto (e_meeting_attendee_get_delto (ia)), NULL); - if (ib != NULL) { - g_object_ref((ib)); - g_ptr_array_add (priv->deleted_attendees, ib); - - e_meeting_model_remove_attendee (priv->model, ib); - } - } - e_meeting_attendee_set_delto (ia, g_strdup_printf ("MAILTO:%s", address)); - - /* Construct delegatee information */ - ic = e_meeting_model_add_attendee_with_defaults (priv->model); - - e_meeting_attendee_set_address (ic, g_strdup_printf ("MAILTO:%s", address)); - e_meeting_attendee_set_delfrom (ic, g_strdup (e_meeting_attendee_get_address (ia))); - e_meeting_attendee_set_cn (ic, g_strdup (name)); - } - - cleanup: - g_free (name); - g_free (address); - g_object_unref((edd)); -} -#endif - -static void -popup_delete_cb (GtkWidget *widget, gpointer data) -{ - MeetingPage *mpage = MEETING_PAGE (data); - MeetingPagePrivate *priv; - EMeetingAttendee *ia; - int pos = 0; - - priv = mpage->priv; - - ia = e_meeting_model_find_attendee_at_row (priv->model, priv->row); - - /* If the user deletes the attendee explicitly, assume they no - longer want the organizer showing up */ - if (ia == priv->ia) { - g_object_unref (priv->ia); - priv->ia = NULL; - } - - /* If this was a delegatee, no longer delegate */ - if (e_meeting_attendee_is_set_delfrom (ia)) { - EMeetingAttendee *ib; - - ib = e_meeting_model_find_attendee (priv->model, e_meeting_attendee_get_delfrom (ia), &pos); - if (ib != NULL) { - e_meeting_attendee_set_delto (ib, NULL); - e_meeting_attendee_set_edit_level (ib, E_MEETING_ATTENDEE_EDIT_FULL); - } - } - - /* Handle deleting all attendees in the delegation chain */ - while (ia != NULL) { - EMeetingAttendee *ib = NULL; - - g_object_ref((ia)); - g_ptr_array_add (priv->deleted_attendees, ia); - e_meeting_model_remove_attendee (priv->model, ia); - - if (e_meeting_attendee_get_delto (ia) != NULL) - ib = e_meeting_model_find_attendee (priv->model, e_meeting_attendee_get_delto (ia), NULL); - ia = ib; - } -} - -enum { - CAN_DELEGATE = 2, - CAN_DELETE = 4 -}; - -static EPopupMenu context_menu[] = { -#if 0 - E_POPUP_ITEM (N_("_Delegate To..."), G_CALLBACK (popup_delegate_cb), CAN_DELEGATE), - - E_POPUP_SEPARATOR, -#endif - E_POPUP_ITEM (N_("_Delete"), G_CALLBACK (popup_delete_cb), CAN_DELETE), - - E_POPUP_TERMINATOR -}; - -/* handle context menu over message-list */ -static gint -right_click_cb (ETable *etable, gint row, gint col, GdkEvent *event, gpointer data) -{ - MeetingPage *mpage = MEETING_PAGE (data); - MeetingPagePrivate *priv; - GtkMenu *menu; - EMeetingAttendee *ia; - int disable_mask = 0, hide_mask = 0, view_row; - - priv = mpage->priv; - - view_row = e_table_model_to_view_row (etable, row); - priv->row = e_meeting_model_etable_view_to_model_row (etable, priv->model, view_row); - - ia = e_meeting_model_find_attendee_at_row (priv->model, priv->row); - if (e_meeting_attendee_get_edit_level (ia) != E_MEETING_ATTENDEE_EDIT_FULL) - disable_mask = CAN_DELETE; - - /* FIXME: if you enable Delegate, then change index to '1'. - * (This has now been enabled). */ - /* context_menu[1].pixmap_widget = gnome_stock_new_with_icon (GNOME_STOCK_MENU_TRASH); */ - context_menu[1].pixmap_widget = - gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_MENU); - - menu = e_popup_menu_create (context_menu, disable_mask, hide_mask, data); - e_auto_kill_popup_menu_on_selection_done (menu); - - gtk_menu_popup (menu, NULL, NULL, NULL, NULL, - event->button.button, event->button.time); - - return TRUE; -} - - - -/* Callback used when the ETable gets a focus-out event. We have to commit any - * pending click-to-add state for if the event editor is being destroyed. - */ -static gint -table_canvas_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - MeetingPage *mpage; - MeetingPagePrivate *priv; - ETable *etable; - - mpage = MEETING_PAGE (data); - priv = mpage->priv; - - etable = e_table_scrolled_get_table (priv->etable); - - e_table_commit_click_to_add (etable); - return TRUE; -} - -/** - * meeting_page_construct: - * @mpage: An task details page. - * - * Constructs an task page by loading its Glade data. - * - * Return value: The same object as @mpage, or NULL if the widgets could not - * be created. - **/ -MeetingPage * -meeting_page_construct (MeetingPage *mpage, EMeetingModel *emm, - CalClient *client) -{ - MeetingPagePrivate *priv; - ETable *real_table; - gchar *filename; - const char *backend_address; - EIterator *it; - EAccount *def_account; - GList *address_strings = NULL, *l; - - priv = mpage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR - "/meeting-page.glade", NULL, NULL); - if (!priv->xml) { - g_message ("meeting_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (mpage)) { - g_message ("meeting_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - /* Address information */ - backend_address = cal_client_get_cal_address (client); - - priv->accounts = itip_addresses_get (); - def_account = itip_addresses_get_default(); - for (it = e_list_get_iterator((EList *)priv->accounts); - e_iterator_is_valid(it); - e_iterator_next(it)) { - EAccount *a = (EAccount *)e_iterator_get(it); - char *full; - - full = g_strdup_printf("%s <%s>", a->id->name, a->id->address); - - address_strings = g_list_append(address_strings, full); - - /* Note that the address specified by the backend gets - * precedence over the default mail address. - */ - if (backend_address && !strcmp (backend_address, a->id->address)) { - if (priv->default_address) - g_free (priv->default_address); - - priv->default_address = g_strdup (full); - } else if (a == def_account && !priv->default_address) { - priv->default_address = g_strdup (full); - } - } - g_object_unref(it); - - if (address_strings) - gtk_combo_set_popdown_strings (GTK_COMBO (priv->organizer), address_strings); - else - g_warning ("No potential organizers!"); - - for (l = address_strings; l != NULL; l = l->next) - g_free (l->data); - g_list_free (address_strings); - - /* The etable displaying attendees and their status */ - g_object_ref((emm)); - priv->model = emm; - - filename = g_strdup_printf ("%s/config/et-header-meeting-page", evolution_dir); - priv->etable = e_meeting_model_etable_from_model (priv->model, - EVOLUTION_ETSPECDIR "/meeting-page.etspec", - filename); - g_free (filename); - - real_table = e_table_scrolled_get_table (priv->etable); - g_signal_connect((real_table), - "right_click", G_CALLBACK (right_click_cb), mpage); - - g_signal_connect((real_table->table_canvas), "focus_out_event", - G_CALLBACK (table_canvas_focus_out_cb), mpage); - - gtk_widget_show (GTK_WIDGET (priv->etable)); - gtk_box_pack_start (GTK_BOX (priv->main), GTK_WIDGET (priv->etable), TRUE, TRUE, 6); - - /* Init the widget signals */ - init_widgets (mpage); - - return mpage; -} - -/** - * meeting_page_new: - * - * Creates a new task details page. - * - * Return value: A newly-created task details page, or NULL if the page could - * not be created. - **/ -MeetingPage * -meeting_page_new (EMeetingModel *emm, CalClient *client) -{ - MeetingPage *mpage; - - mpage = g_object_new (TYPE_MEETING_PAGE, NULL); - if (!meeting_page_construct (mpage, emm, client)) { - g_object_unref((mpage)); - return NULL; - } - - return mpage; -} - -/** - * meeting_page_get_cancel_comp: - * @mpage: - * - * - * - * Return value: - **/ -CalComponent * -meeting_page_get_cancel_comp (MeetingPage *mpage) -{ - MeetingPagePrivate *priv; - - g_return_val_if_fail (mpage != NULL, NULL); - g_return_val_if_fail (IS_MEETING_PAGE (mpage), NULL); - - priv = mpage->priv; - - if (priv->deleted_attendees->len == 0) - return NULL; - - set_attendees (priv->comp, priv->deleted_attendees); - - return cal_component_clone (priv->comp); -} diff --git a/calendar/gui/dialogs/meeting-page.etspec b/calendar/gui/dialogs/meeting-page.etspec deleted file mode 100644 index 96bc480fe9..0000000000 --- a/calendar/gui/dialogs/meeting-page.etspec +++ /dev/null @@ -1,21 +0,0 @@ -<ETableSpecification click-to-add="true" click-to-add-end="true" _click-to-add-message="Click here to add an attendee" draw-grid="true"> - <ETableColumn model_col= "0" _title="Attendee" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "1" _title="Member" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "2" _title="Type" expansion="1.0" minimum_width="10" resizable="true" cell="typeedit" compare="string"/> - <ETableColumn model_col= "3" _title="Role" expansion="1.0" minimum_width="10" resizable="true" cell="roleedit" compare="string"/> - <ETableColumn model_col= "4" _title="RSVP" expansion="1.0" minimum_width="10" resizable="true" cell="rsvpedit" compare="string"/> - <ETableColumn model_col= "5" _title="Delegated To" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "6" _title="Delegated From" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "7" _title="Status" expansion="1.0" minimum_width="10" resizable="true" cell="statusedit" compare="string"/> - <ETableColumn model_col= "8" _title="Common Name" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "9" _title="Language" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - - <ETableState> - <column source="0"/> - <column source="2"/> - <column source="3"/> - <column source="4"/> - <column source="7"/> - <grouping></grouping> - </ETableState> -</ETableSpecification> diff --git a/calendar/gui/dialogs/meeting-page.glade b/calendar/gui/dialogs/meeting-page.glade deleted file mode 100644 index f2b68c03cf..0000000000 --- a/calendar/gui/dialogs/meeting-page.glade +++ /dev/null @@ -1,241 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="meeting-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="meeting-page"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkTable" id="organizer-table"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="n_rows">1</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkCombo" id="organizer"> - <property name="visible">True</property> - <property name="value_in_list">True</property> - <property name="allow_empty">False</property> - <property name="case_sensitive">False</property> - <property name="enable_arrow_keys">True</property> - <property name="enable_arrows_always">False</property> - - <child internal-child="entry"> - <widget class="GtkEntry" id="entry2"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - </child> - - <child internal-child="list"> - <widget class="GtkList" id="convertwidget1"> - <property name="visible">True</property> - <property name="selection_mode">GTK_SELECTION_BROWSE</property> - - <child> - <widget class="GtkListItem" id="convertwidget2"> - <property name="visible">True</property> - - <child> - <widget class="GtkLabel" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes"></property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="organizer-label"> - <property name="visible">True</property> - <property name="label" translatable="yes">Organizer:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkTable" id="existing-organizer-table"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="n_rows">1</property> - <property name="n_columns">3</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Organizer:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options"></property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="existing-organizer-button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Change Organizer</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options"></property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="existing-organizer"> - <property name="visible">True</property> - <property name="label" translatable="yes">None</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <placeholder/> - </child> - - <child> - <widget class="GtkButton" id="invite"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Invite Others...</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/meeting-page.h b/calendar/gui/dialogs/meeting-page.h deleted file mode 100644 index 2a209b586b..0000000000 --- a/calendar/gui/dialogs/meeting-page.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Evolution calendar - Main page of the task editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 MEETING_PAGE_H -#define MEETING_PAGE_H - -#include "../e-meeting-model.h" -#include "../itip-utils.h" -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_MEETING_PAGE (meeting_page_get_type ()) -#define MEETING_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MEETING_PAGE, MeetingPage)) -#define MEETING_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MEETING_PAGE, MeetingPageClass)) -#define IS_MEETING_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MEETING_PAGE)) -#define IS_MEETING_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_MEETING_PAGE)) - -typedef struct _MeetingPagePrivate MeetingPagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - MeetingPagePrivate *priv; -} MeetingPage; - -typedef struct { - CompEditorPageClass parent_class; -} MeetingPageClass; - - -GtkType meeting_page_get_type (void); -MeetingPage *meeting_page_construct (MeetingPage *mpage, - EMeetingModel *emm, - CalClient *client); -MeetingPage *meeting_page_new (EMeetingModel *emm, - CalClient *client); -CalComponent *meeting_page_get_cancel_comp (MeetingPage *mpage); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/recur-comp.c b/calendar/gui/dialogs/recur-comp.c deleted file mode 100644 index 81db34733c..0000000000 --- a/calendar/gui/dialogs/recur-comp.c +++ /dev/null @@ -1,94 +0,0 @@ -/* Evolution calendar - Recurring calendar component dialog - * - * Copyright (C) 2002 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtk.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-uidefs.h> -#include <gal/widgets/e-unicode.h> -#include "recur-comp.h" - - - -gboolean -recur_component_dialog (CalComponent *comp, - CalObjModType *mod, - GtkWindow *parent) -{ - char *str; - GtkWidget *dialog, *rb1, *rb2, *rb3, *hbox; - CalComponentVType vtype; - gboolean ret; - - g_return_val_if_fail (IS_CAL_COMPONENT (comp), CALOBJ_MOD_THIS); - - vtype = cal_component_get_vtype (comp); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - str = g_strdup_printf (_("You are modifying a recurring event, what would you like to modify?")); - break; - - case CAL_COMPONENT_TODO: - str = g_strdup_printf (_("You are modifying a recurring task, what would you like to modify?")); - break; - - case CAL_COMPONENT_JOURNAL: - str = g_strdup_printf (_("You are modifying a recurring journal entry, what would you like to modify?")); - break; - - default: - g_message ("recur_component_dialog(): Cannot handle object of type %d", vtype); - return CALOBJ_MOD_THIS; - } - - - dialog = gtk_message_dialog_new(parent, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "%s", str); - g_free (str); - - hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox); - rb1 = gtk_radio_button_new_with_label (NULL, _("This Instance Only")); - gtk_container_add (GTK_CONTAINER (hbox), rb1); - - rb2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rb1), _("This and Future Instances")); - gtk_container_add (GTK_CONTAINER (hbox), rb2); - rb3 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rb1), _("All Instances")); - gtk_container_add (GTK_CONTAINER (hbox), rb3); - - gtk_widget_show_all (hbox); - - ret = gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK; - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rb1))) - *mod = CALOBJ_MOD_THIS; - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rb2))) - *mod = CALOBJ_MOD_THISANDFUTURE; - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rb3))) - *mod = CALOBJ_MOD_ALL; - - gtk_widget_destroy (dialog); - - return ret; -} diff --git a/calendar/gui/dialogs/recur-comp.h b/calendar/gui/dialogs/recur-comp.h deleted file mode 100644 index 7c3472853b..0000000000 --- a/calendar/gui/dialogs/recur-comp.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Evolution calendar - Recurring calendar component dialog - * - * Copyright (C) 2002 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 RECUR_COMP_H -#define RECUR_COMP_H - -#include <gtk/gtkwidget.h> -#include <cal-util/cal-component.h> -#include <cal-util/cal-util.h> - -gboolean recur_component_dialog (CalComponent *comp, - CalObjModType *mod, - GtkWindow *parent); - -#endif diff --git a/calendar/gui/dialogs/recurrence-page.c b/calendar/gui/dialogs/recurrence-page.c deleted file mode 100644 index 275ba26c44..0000000000 --- a/calendar/gui/dialogs/recurrence-page.c +++ /dev/null @@ -1,2401 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* Evolution calendar - Recurrence page of the calendar component dialogs - * - * Copyright (C) 2001-2003 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * Hans Petter Jansson <hpj@ximiman.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtkcellrenderertext.h> -#include <gtk/gtkmenuitem.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtktreeview.h> -#include <gtk/gtktreeselection.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <e-util/e-dialog-widgets.h> -#include <e-util/e-time-utils.h> -#include <widgets/misc/e-dateedit.h> -#include <cal-util/cal-recur.h> -#include <cal-util/timeutil.h> -#include "../calendar-config.h" -#include "../tag-calendar.h" -#include "../weekday-picker.h" -#include "comp-editor-util.h" -#include "../e-date-time-list.h" -#include "recurrence-page.h" - - - -enum month_num_options { - MONTH_NUM_FIRST, - MONTH_NUM_SECOND, - MONTH_NUM_THIRD, - MONTH_NUM_FOURTH, - MONTH_NUM_LAST, - MONTH_NUM_DAY, - MONTH_NUM_OTHER -}; - -static const int month_num_options_map[] = { - MONTH_NUM_FIRST, - MONTH_NUM_SECOND, - MONTH_NUM_THIRD, - MONTH_NUM_FOURTH, - MONTH_NUM_LAST, - MONTH_NUM_DAY, - MONTH_NUM_OTHER, - -1 -}; - -enum month_day_options { - MONTH_DAY_NTH, - MONTH_DAY_MON, - MONTH_DAY_TUE, - MONTH_DAY_WED, - MONTH_DAY_THU, - MONTH_DAY_FRI, - MONTH_DAY_SAT, - MONTH_DAY_SUN -}; - -static const int month_day_options_map[] = { - MONTH_DAY_NTH, - MONTH_DAY_MON, - MONTH_DAY_TUE, - MONTH_DAY_WED, - MONTH_DAY_THU, - MONTH_DAY_FRI, - MONTH_DAY_SAT, - MONTH_DAY_SUN, - -1 -}; - -enum recur_type { - RECUR_NONE, - RECUR_SIMPLE, - RECUR_CUSTOM -}; - -static const int type_map[] = { - RECUR_NONE, - RECUR_SIMPLE, - RECUR_CUSTOM, - -1 -}; - -static const int freq_map[] = { - ICAL_DAILY_RECURRENCE, - ICAL_WEEKLY_RECURRENCE, - ICAL_MONTHLY_RECURRENCE, - ICAL_YEARLY_RECURRENCE, - -1 -}; - -enum ending_type { - ENDING_FOR, - ENDING_UNTIL, - ENDING_FOREVER -}; - -static const int ending_types_map[] = { - ENDING_FOR, - ENDING_UNTIL, - ENDING_FOREVER, - -1 -}; - -/* Private part of the RecurrencePage structure */ -struct _RecurrencePagePrivate { - /* Component we use to expand the recurrence rules for the preview */ - CalComponent *comp; - - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *main; - - GtkWidget *summary; - GtkWidget *date_time; - - GtkWidget *none; - GtkWidget *simple; - GtkWidget *custom; - - GtkWidget *params; - GtkWidget *interval_value; - GtkWidget *interval_unit; - GtkWidget *special; - GtkWidget *ending_menu; - GtkWidget *ending_special; - GtkWidget *custom_warning_bin; - - /* For weekly recurrences, created by hand */ - GtkWidget *weekday_picker; - guint8 weekday_day_mask; - guint8 weekday_blocked_day_mask; - - /* For monthly recurrences, created by hand */ - int month_index; - - GtkWidget *month_day_menu; - enum month_day_options month_day; - - GtkWidget *month_num_menu; - enum month_num_options month_num; - - /* For ending date, created by hand */ - GtkWidget *ending_date_edit; - struct icaltimetype ending_date_tt; - - /* For ending count of occurrences, created by hand */ - GtkWidget *ending_count_spin; - int ending_count; - - /* More widgets from the Glade file */ - GtkWidget *exception_date; - GtkWidget *exception_list; /* This is a GtkTreeView now */ - GtkWidget *exception_add; - GtkWidget *exception_modify; - GtkWidget *exception_delete; - - GtkWidget *preview_bin; - - /* Store for exception_list */ - EDateTimeList *exception_list_store; - - /* For the recurrence preview, the actual widget */ - GtkWidget *preview_calendar; - - gboolean updating; -}; - - - -static void recurrence_page_class_init (RecurrencePageClass *class); -static void recurrence_page_init (RecurrencePage *rpage); -static void recurrence_page_finalize (GObject *object); - -static GtkWidget *recurrence_page_get_widget (CompEditorPage *page); -static void recurrence_page_focus_main_widget (CompEditorPage *page); -static void recurrence_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean recurrence_page_fill_component (CompEditorPage *page, CalComponent *comp); -static void recurrence_page_set_summary (CompEditorPage *page, const char *summary); -static void recurrence_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); - -static void field_changed (RecurrencePage *apage); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * recurrence_page_get_type: - * - * Registers the #RecurrencePage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #RecurrencePage class. - **/ - -E_MAKE_TYPE (recurrence_page, "RecurrencePage", RecurrencePage, recurrence_page_class_init, - recurrence_page_init, TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the recurrence page */ -static void -recurrence_page_class_init (RecurrencePageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref(TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = recurrence_page_get_widget; - editor_page_class->focus_main_widget = recurrence_page_focus_main_widget; - editor_page_class->fill_widgets = recurrence_page_fill_widgets; - editor_page_class->fill_component = recurrence_page_fill_component; - editor_page_class->set_summary = recurrence_page_set_summary; - editor_page_class->set_dates = recurrence_page_set_dates; - - object_class->finalize = recurrence_page_finalize; -} - -/* Object initialization function for the recurrence page */ -static void -recurrence_page_init (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - - priv = g_new0 (RecurrencePagePrivate, 1); - rpage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - priv->summary = NULL; - priv->date_time = NULL; - priv->none = NULL; - priv->simple = NULL; - priv->custom = NULL; - priv->params = NULL; - priv->interval_value = NULL; - priv->interval_unit = NULL; - priv->special = NULL; - priv->ending_menu = NULL; - priv->ending_special = NULL; - priv->custom_warning_bin = NULL; - priv->weekday_picker = NULL; - priv->month_day_menu = NULL; - priv->month_num_menu = NULL; - priv->ending_date_edit = NULL; - priv->ending_count_spin = NULL; - priv->exception_date = NULL; - priv->exception_list = NULL; - priv->exception_add = NULL; - priv->exception_modify = NULL; - priv->exception_delete = NULL; - priv->preview_bin = NULL; - priv->preview_calendar = NULL; - - priv->comp = NULL; -} - -/* Destroy handler for the recurrence page */ -static void -recurrence_page_finalize (GObject *object) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_RECURRENCE_PAGE (object)); - - rpage = RECURRENCE_PAGE (object); - priv = rpage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - if (priv->comp) { - g_object_unref((priv->comp)); - priv->comp = NULL; - } - - if (priv->exception_list_store) { - g_object_unref (priv->exception_list_store); - priv->exception_list_store = NULL; - } - - g_free (priv); - rpage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the recurrence page */ -static GtkWidget * -recurrence_page_get_widget (CompEditorPage *page) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - - rpage = RECURRENCE_PAGE (page); - priv = rpage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the recurrence page */ -static void -recurrence_page_focus_main_widget (CompEditorPage *page) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - - rpage = RECURRENCE_PAGE (page); - priv = rpage->priv; - - if (e_dialog_toggle_get (priv->none)) - gtk_widget_grab_focus (priv->none); - else if (e_dialog_toggle_get (priv->simple)) - gtk_widget_grab_focus (priv->simple); - else if (e_dialog_toggle_get (priv->custom)) - gtk_widget_grab_focus (priv->custom); - else - g_assert_not_reached (); -} - -/* Fills the widgets with default values */ -static void -clear_widgets (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - GtkAdjustment *adj; - GtkWidget *menu; - - priv = rpage->priv; - - priv->weekday_day_mask = 0; - - priv->month_index = 1; - priv->month_num = MONTH_NUM_DAY; - priv->month_day = MONTH_DAY_NTH; - - g_signal_handlers_block_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_radio_set (priv->none, RECUR_NONE, type_map); - g_signal_handlers_unblock_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->interval_value)); - g_signal_handlers_block_matched (adj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_spin_set (priv->interval_value, 1); - g_signal_handlers_unblock_matched (adj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->interval_unit, - ICAL_DAILY_RECURRENCE, - freq_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - priv->ending_date_tt = icaltime_today (); - priv->ending_count = 1; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->ending_menu)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->ending_menu, - ENDING_FOREVER, - ending_types_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - /* Exceptions list */ - e_date_time_list_clear (priv->exception_list_store); -} - -/* Appends an exception date to the list */ -static void -append_exception (RecurrencePage *rpage, CalComponentDateTime *datetime) -{ - RecurrencePagePrivate *priv; - GtkTreeView *view; - GtkTreeIter iter; - - priv = rpage->priv; - view = GTK_TREE_VIEW (priv->exception_list); - - e_date_time_list_append (priv->exception_list_store, &iter, datetime); - gtk_tree_selection_select_iter (gtk_tree_view_get_selection (view), &iter); -} - -/* Fills in the exception widgets with the data from the calendar component */ -static void -fill_exception_widgets (RecurrencePage *rpage, CalComponent *comp) -{ - RecurrencePagePrivate *priv; - GSList *list, *l; - gboolean added = FALSE; - - priv = rpage->priv; - cal_component_get_exdate_list (comp, &list); - - for (l = list; l; l = l->next) { - CalComponentDateTime *cdt; - - added = TRUE; - - cdt = l->data; - append_exception (rpage, cdt); - } - - cal_component_free_exdate_list (list); -} - -/* Computes a weekday mask for the start day of a calendar component, - * for use in a WeekdayPicker widget. - */ -static guint8 -get_start_weekday_mask (CalComponent *comp) -{ - CalComponentDateTime dt; - guint8 retval; - - cal_component_get_dtstart (comp, &dt); - - if (dt.value) { - short weekday; - - weekday = icaltime_day_of_week (*dt.value); - retval = 0x1 << (weekday - 1); - } else - retval = 0; - - cal_component_free_datetime (&dt); - - return retval; -} - -/* Sets some sane defaults for the data sources for the recurrence special - * widgets, even if they will not be used immediately. - */ -static void -set_special_defaults (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - guint8 mask; - - priv = rpage->priv; - - mask = get_start_weekday_mask (priv->comp); - - priv->weekday_day_mask = mask; - priv->weekday_blocked_day_mask = mask; -} - -/* Sensitizes the recurrence widgets based on the state of the recurrence type - * radio group. - */ -static void -sensitize_recur_widgets (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - enum recur_type type; - GtkWidget *label; - - priv = rpage->priv; - - type = e_dialog_radio_get (priv->none, type_map); - - /* We can't preview that well for instances right now */ - if (cal_component_is_instance (priv->comp)) - gtk_widget_set_sensitive (priv->preview_calendar, FALSE); - else - gtk_widget_set_sensitive (priv->preview_calendar, TRUE); - - if (GTK_BIN (priv->custom_warning_bin)->child) - gtk_widget_destroy (GTK_BIN (priv->custom_warning_bin)->child); - - switch (type) { - case RECUR_NONE: - gtk_widget_set_sensitive (priv->params, FALSE); - gtk_widget_show (priv->params); - gtk_widget_hide (priv->custom_warning_bin); - break; - - case RECUR_SIMPLE: - gtk_widget_set_sensitive (priv->params, TRUE); - gtk_widget_show (priv->params); - gtk_widget_hide (priv->custom_warning_bin); - break; - - case RECUR_CUSTOM: - gtk_widget_set_sensitive (priv->params, FALSE); - gtk_widget_hide (priv->params); - - label = gtk_label_new (_("This appointment contains " - "recurrences that Evolution " - "cannot edit.")); - gtk_container_add (GTK_CONTAINER (priv->custom_warning_bin), - label); - gtk_widget_show_all (priv->custom_warning_bin); - break; - - default: - g_assert_not_reached (); - } -} - -#if 0 -/* Encondes a position/weekday pair into the proper format for - * icalrecurrencetype.by_day. Not needed at present. - */ -static short -nth_weekday (int pos, icalrecurrencetype_weekday weekday) -{ - g_assert (pos > 0 && pos <= 5); - - return (pos << 3) | (int) weekday; -} -#endif - -/* Gets the simple recurrence data from the recurrence widgets and stores it in - * the calendar component. - */ -static void -simple_recur_to_comp (RecurrencePage *rpage, CalComponent *comp) -{ - RecurrencePagePrivate *priv; - struct icalrecurrencetype r; - GSList l; - enum ending_type ending_type; - gboolean date_set; - - priv = rpage->priv; - - icalrecurrencetype_clear (&r); - - /* Frequency, interval, week start */ - - r.freq = e_dialog_option_menu_get (priv->interval_unit, freq_map); - r.interval = e_dialog_spin_get_int (priv->interval_value); - r.week_start = ICAL_SUNDAY_WEEKDAY - + calendar_config_get_week_start_day (); - - /* Frequency-specific data */ - - switch (r.freq) { - case ICAL_DAILY_RECURRENCE: - /* Nothing else is required */ - break; - - case ICAL_WEEKLY_RECURRENCE: { - guint8 day_mask; - int i; - - g_assert (GTK_BIN (priv->special)->child != NULL); - g_assert (priv->weekday_picker != NULL); - g_assert (IS_WEEKDAY_PICKER (priv->weekday_picker)); - - day_mask = weekday_picker_get_days (WEEKDAY_PICKER (priv->weekday_picker)); - - i = 0; - - if (day_mask & (1 << 0)) - r.by_day[i++] = ICAL_SUNDAY_WEEKDAY; - - if (day_mask & (1 << 1)) - r.by_day[i++] = ICAL_MONDAY_WEEKDAY; - - if (day_mask & (1 << 2)) - r.by_day[i++] = ICAL_TUESDAY_WEEKDAY; - - if (day_mask & (1 << 3)) - r.by_day[i++] = ICAL_WEDNESDAY_WEEKDAY; - - if (day_mask & (1 << 4)) - r.by_day[i++] = ICAL_THURSDAY_WEEKDAY; - - if (day_mask & (1 << 5)) - r.by_day[i++] = ICAL_FRIDAY_WEEKDAY; - - if (day_mask & (1 << 6)) - r.by_day[i++] = ICAL_SATURDAY_WEEKDAY; - - break; - } - - case ICAL_MONTHLY_RECURRENCE: { - enum month_num_options month_num; - enum month_day_options month_day; - - g_assert (GTK_BIN (priv->special)->child != NULL); - g_assert (priv->month_day_menu != NULL); - g_assert (GTK_IS_OPTION_MENU (priv->month_day_menu)); - g_assert (priv->month_num_menu != NULL); - g_assert (GTK_IS_OPTION_MENU (priv->month_num_menu)); - - month_num = e_dialog_option_menu_get (priv->month_num_menu, - month_num_options_map ); - month_day = e_dialog_option_menu_get (priv->month_day_menu, - month_day_options_map); - - if (month_num == MONTH_NUM_LAST) - month_num = -1; - else - month_num++; - - switch (month_day) { - case MONTH_DAY_NTH: - if (month_num == -1) - r.by_month_day[0] = -1; - else - r.by_month_day[0] = priv->month_index; - break; - - /* Outlook 2000 uses BYDAY=TU;BYSETPOS=2, and will not - accept BYDAY=2TU. So we now use the same as Outlook - by default. */ - case MONTH_DAY_MON: - r.by_day[0] = ICAL_MONDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_TUE: - r.by_day[0] = ICAL_TUESDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_WED: - r.by_day[0] = ICAL_WEDNESDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_THU: - r.by_day[0] = ICAL_THURSDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_FRI: - r.by_day[0] = ICAL_FRIDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_SAT: - r.by_day[0] = ICAL_SATURDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - case MONTH_DAY_SUN: - r.by_day[0] = ICAL_SUNDAY_WEEKDAY; - r.by_set_pos[0] = month_num; - break; - - default: - g_assert_not_reached (); - } - - break; - } - - case ICAL_YEARLY_RECURRENCE: - /* Nothing else is required */ - break; - - default: - g_assert_not_reached (); - } - - /* Ending date */ - - ending_type = e_dialog_option_menu_get (priv->ending_menu, - ending_types_map); - - switch (ending_type) { - case ENDING_FOR: - g_assert (priv->ending_count_spin != NULL); - g_assert (GTK_IS_SPIN_BUTTON (priv->ending_count_spin)); - - r.count = e_dialog_spin_get_int (priv->ending_count_spin); - break; - - case ENDING_UNTIL: - g_assert (priv->ending_date_edit != NULL); - g_assert (E_IS_DATE_EDIT (priv->ending_date_edit)); - - /* We only allow a DATE value to be set for the UNTIL property, - since we don't support sub-day recurrences. */ - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->ending_date_edit), - &r.until.year, - &r.until.month, - &r.until.day); - g_assert (date_set); - - r.until.is_date = 1; - - break; - - case ENDING_FOREVER: - /* Nothing to be done */ - break; - - default: - g_assert_not_reached (); - } - - /* Set the recurrence */ - - l.data = &r; - l.next = NULL; - - cal_component_set_rrule_list (comp, &l); -} - -/* Fills a component with the data from the recurrence page; in the case of a - * custom recurrence, it leaves it intact. - */ -static gboolean -fill_component (RecurrencePage *rpage, CalComponent *comp) -{ - RecurrencePagePrivate *priv; - enum recur_type recur_type; - GtkTreeModel *model; - GtkTreeIter iter; - gboolean valid_iter; - GSList *list; - - priv = rpage->priv; - model = GTK_TREE_MODEL (priv->exception_list_store); - - recur_type = e_dialog_radio_get (priv->none, type_map); - - switch (recur_type) { - case RECUR_NONE: - cal_component_set_rdate_list (comp, NULL); - cal_component_set_rrule_list (comp, NULL); - cal_component_set_exrule_list (comp, NULL); - break; - - case RECUR_SIMPLE: - cal_component_set_rdate_list (comp, NULL); - cal_component_set_exrule_list (comp, NULL); - simple_recur_to_comp (rpage, comp); - break; - - case RECUR_CUSTOM: - /* We just keep whatever the component has currently */ - break; - - default: - g_assert_not_reached (); - } - - /* Set exceptions */ - - list = NULL; - - for (valid_iter = gtk_tree_model_get_iter_first (model, &iter); valid_iter; - valid_iter = gtk_tree_model_iter_next (model, &iter)) { - const CalComponentDateTime *dt; - CalComponentDateTime *cdt; - - cdt = g_new (CalComponentDateTime, 1); - cdt->value = g_new (struct icaltimetype, 1); - - dt = e_date_time_list_get_date_time (E_DATE_TIME_LIST (model), &iter); - g_assert (dt != NULL); - - if (!icaltime_is_valid_time (*dt->value)) { - comp_editor_page_display_validation_error (COMP_EDITOR_PAGE (rpage), - _("Recurrence date is invalid"), - priv->exception_list); - return FALSE; - } - - *cdt->value = *dt->value; - cdt->tzid = g_strdup (dt->tzid); - - list = g_slist_prepend (list, cdt); - } - - cal_component_set_exdate_list (comp, list); - cal_component_free_exdate_list (list); - - return TRUE; -} - -/* Re-tags the recurrence preview calendar based on the current information of - * the widgets in the recurrence page. - */ -static void -preview_recur (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - CalComponent *comp; - CalComponentDateTime cdt; - GSList *l; - icaltimezone *zone = NULL; - - priv = rpage->priv; - - /* If our component has not been set yet through ::fill_widgets(), we - * cannot preview the recurrence. - */ - if (!priv->comp || cal_component_is_instance (priv->comp)) - return; - - /* Create a scratch component with the start/end and - * recurrence/exception information from the one we are editing. - */ - - comp = cal_component_new (); - cal_component_set_new_vtype (comp, CAL_COMPONENT_EVENT); - - cal_component_get_dtstart (priv->comp, &cdt); - if (cdt.tzid != NULL) { - if (cal_client_get_timezone (COMP_EDITOR_PAGE (rpage)->client, cdt.tzid, &zone) != CAL_CLIENT_GET_SUCCESS) - zone = icaltimezone_get_builtin_timezone_from_tzid (cdt.tzid); - } - cal_component_set_dtstart (comp, &cdt); - cal_component_free_datetime (&cdt); - - cal_component_get_dtend (priv->comp, &cdt); - cal_component_set_dtend (comp, &cdt); - cal_component_free_datetime (&cdt); - - cal_component_get_exdate_list (priv->comp, &l); - cal_component_set_exdate_list (comp, l); - cal_component_free_exdate_list (l); - - cal_component_get_exrule_list (priv->comp, &l); - cal_component_set_exrule_list (comp, l); - cal_component_free_recur_list (l); - - cal_component_get_rdate_list (priv->comp, &l); - cal_component_set_rdate_list (comp, l); - cal_component_free_period_list (l); - - cal_component_get_rrule_list (priv->comp, &l); - cal_component_set_rrule_list (comp, l); - cal_component_free_recur_list (l); - - fill_component (rpage, comp); - - tag_calendar_by_comp (E_CALENDAR (priv->preview_calendar), comp, - COMP_EDITOR_PAGE (rpage)->client, zone, TRUE, FALSE); - g_object_unref(comp); -} - -/* Callback used when the recurrence weekday picker changes */ -static void -weekday_picker_changed_cb (WeekdayPicker *wp, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - preview_recur (rpage); -} - -/* Creates the special contents for weekly recurrences */ -static void -make_weekly_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - GtkWidget *hbox; - GtkWidget *label; - WeekdayPicker *wp; - - priv = rpage->priv; - - g_assert (GTK_BIN (priv->special)->child == NULL); - g_assert (priv->weekday_picker == NULL); - - /* Create the widgets */ - - hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (priv->special), hbox); - - label = gtk_label_new (_("on")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - - wp = WEEKDAY_PICKER (weekday_picker_new ()); - - priv->weekday_picker = GTK_WIDGET (wp); - gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (wp), FALSE, FALSE, 6); - - gtk_widget_show_all (hbox); - - /* Set the weekdays */ - - weekday_picker_set_week_start_day (wp, calendar_config_get_week_start_day ()); - weekday_picker_set_days (wp, priv->weekday_day_mask); - weekday_picker_set_blocked_days (wp, priv->weekday_blocked_day_mask); - - g_signal_connect((wp), "changed", - G_CALLBACK (weekday_picker_changed_cb), - rpage); -} - - -static void -month_num_submenu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - GtkWidget *item; - int month_index; - - item = gtk_menu_get_active (GTK_MENU (menu_shell)); - item = gtk_menu_get_active (GTK_MENU (gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))); - - month_index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (item))); - gtk_object_set_user_data (GTK_OBJECT (data), GINT_TO_POINTER (month_index)); -} - -/* Creates the option menu for the monthly recurrence number */ -static GtkWidget * -make_recur_month_num_submenu (const char *title, int start, int end) -{ - GtkWidget *submenu, *item; - int i; - - submenu = gtk_menu_new (); - for (i = start; i < end; i++) { - item = gtk_menu_item_new_with_label (_(cal_recur_nth[i])); - gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item); - gtk_object_set_user_data (GTK_OBJECT (item), GINT_TO_POINTER (i + 1)); - gtk_widget_show (item); - } - - item = gtk_menu_item_new_with_label (_(title)); - gtk_widget_show (item); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); - - return item; -} - -static GtkWidget * -make_recur_month_num_menu (int month_index) -{ - static const char *options[] = { - N_("first"), - N_("second"), - N_("third"), - N_("fourth"), - N_("last") - }; - - GtkWidget *menu, *submenu, *item, *submenu_item; - GtkWidget *omenu; - int i; - - menu = gtk_menu_new (); - - /* Relation */ - for (i = 0; i < sizeof (options) / sizeof (options[0]); i++) { - item = gtk_menu_item_new_with_label (_(options[i])); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - gtk_widget_show (item); - } - - /* Current date */ - item = gtk_menu_item_new_with_label (_(cal_recur_nth[month_index - 1])); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - gtk_widget_show (item); - - /* Other Submenu */ - submenu = gtk_menu_new (); - submenu_item = gtk_menu_item_new_with_label (_("Other Date")); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), submenu_item); - gtk_widget_show (submenu_item); - - item = make_recur_month_num_submenu ("1st to 10th", 0, 10); - gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item); - item = make_recur_month_num_submenu ("11th to 20th", 10, 20); - gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item); - item = make_recur_month_num_submenu ("21st to 31st", 20, 31); - gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item); - - gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenu_item), submenu); - gtk_object_set_user_data (GTK_OBJECT (submenu_item), GINT_TO_POINTER (month_index)); - g_signal_connect((submenu), "selection_done", - G_CALLBACK (month_num_submenu_selection_done_cb), - submenu_item); - - omenu = gtk_option_menu_new (); - gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); - - return omenu; -} - -/* Creates the option menu for the monthly recurrence days */ -static GtkWidget * -make_recur_month_menu (void) -{ - static const char *options[] = { - N_("day"), - N_("Monday"), - N_("Tuesday"), - N_("Wednesday"), - N_("Thursday"), - N_("Friday"), - N_("Saturday"), - N_("Sunday") - }; - - GtkWidget *menu; - GtkWidget *omenu; - int i; - - menu = gtk_menu_new (); - - for (i = 0; i < sizeof (options) / sizeof (options[0]); i++) { - GtkWidget *item; - - item = gtk_menu_item_new_with_label (_(options[i])); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - gtk_widget_show (item); - } - - omenu = gtk_option_menu_new (); - gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); - - return omenu; -} - -static void -month_num_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - enum month_num_options month_num; - enum month_day_options month_day; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - month_num = e_dialog_option_menu_get (priv->month_num_menu, - month_num_options_map); - month_day = e_dialog_option_menu_get (priv->month_day_menu, - month_day_options_map); - - if (month_num == MONTH_NUM_OTHER) { - GtkWidget *label, *item; - - item = gtk_menu_get_active (GTK_MENU (menu_shell)); - priv->month_index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (item))); - - month_num = MONTH_NUM_DAY; - e_dialog_option_menu_set (priv->month_num_menu, month_num, month_num_options_map); - - label = GTK_BIN (priv->month_num_menu)->child; - gtk_label_set_text (GTK_LABEL (label), _(cal_recur_nth[priv->month_index - 1])); - - e_dialog_option_menu_set (priv->month_num_menu, 0, month_num_options_map); - e_dialog_option_menu_set (priv->month_num_menu, month_num, month_num_options_map); - } - - if (month_num == MONTH_NUM_DAY && month_day != MONTH_DAY_NTH) - e_dialog_option_menu_set (priv->month_day_menu, - MONTH_DAY_NTH, - month_day_options_map); - else if (month_num != MONTH_NUM_DAY && month_num != MONTH_NUM_LAST && month_day == MONTH_DAY_NTH) - e_dialog_option_menu_set (priv->month_day_menu, - MONTH_DAY_MON, - month_num_options_map); - field_changed (rpage); - preview_recur (rpage); -} - -/* Callback used when the monthly day selection menu changes. We need - * to change the valid range of the day index spin button; e.g. days - * are 1-31 while a Sunday is the 1st through 5th. - */ -static void -month_day_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - enum month_num_options month_num; - enum month_day_options month_day; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - month_num = e_dialog_option_menu_get (priv->month_num_menu, - month_num_options_map); - month_day = e_dialog_option_menu_get (priv->month_day_menu, - month_day_options_map); - if (month_day == MONTH_DAY_NTH && month_num != MONTH_NUM_LAST && month_num != MONTH_NUM_DAY) - e_dialog_option_menu_set (priv->month_num_menu, - MONTH_NUM_DAY, - month_num_options_map); - else if (month_day != MONTH_DAY_NTH && month_num == MONTH_NUM_DAY) - e_dialog_option_menu_set (priv->month_num_menu, - MONTH_NUM_FIRST, - month_num_options_map); - field_changed (rpage); - preview_recur (rpage); -} - -/* Callback used when the month index value changes. */ -static void -month_index_value_changed_cb (GtkAdjustment *adj, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - preview_recur (rpage); -} - -/* Creates the special contents for monthly recurrences */ -static void -make_monthly_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - GtkWidget *hbox; - GtkWidget *label; - GtkAdjustment *adj; - GtkWidget *menu; - - priv = rpage->priv; - - g_assert (GTK_BIN (priv->special)->child == NULL); - g_assert (priv->month_day_menu == NULL); - - /* Create the widgets */ - - hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (priv->special), hbox); - - label = gtk_label_new (_("on the")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (1, 1, 31, 1, 10, 10)); - - priv->month_num_menu = make_recur_month_num_menu (priv->month_index); - gtk_box_pack_start (GTK_BOX (hbox), priv->month_num_menu, - FALSE, FALSE, 6); - - priv->month_day_menu = make_recur_month_menu (); - gtk_box_pack_start (GTK_BOX (hbox), priv->month_day_menu, - FALSE, FALSE, 6); - - gtk_widget_show_all (hbox); - - /* Set the options */ - e_dialog_option_menu_set (priv->month_num_menu, - priv->month_num, - month_num_options_map); - e_dialog_option_menu_set (priv->month_day_menu, - priv->month_day, - month_day_options_map); - - g_signal_connect((adj), "value_changed", G_CALLBACK (month_index_value_changed_cb), - rpage); - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->month_num_menu)); - g_signal_connect((menu), "selection_done", - G_CALLBACK (month_num_menu_selection_done_cb), - rpage); - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->month_day_menu)); - g_signal_connect((menu), "selection_done", - G_CALLBACK (month_day_menu_selection_done_cb), - rpage); -} - -/* Changes the recurrence-special widget to match the interval units. - * - * For daily recurrences: nothing. - * For weekly recurrences: weekday selector. - * For monthly recurrences: "on the" <nth> [day, Weekday] - * For yearly recurrences: nothing. - */ -static void -make_recurrence_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - icalrecurrencetype_frequency frequency; - - priv = rpage->priv; - - if (priv->month_num_menu != NULL) { - gtk_widget_destroy (priv->month_num_menu); - priv->month_num_menu = NULL; - } - if (GTK_BIN (priv->special)->child != NULL) { - gtk_widget_destroy (GTK_BIN (priv->special)->child); - - priv->weekday_picker = NULL; - priv->month_day_menu = NULL; - } - - frequency = e_dialog_option_menu_get (priv->interval_unit, freq_map); - - switch (frequency) { - case ICAL_DAILY_RECURRENCE: - gtk_widget_hide (priv->special); - break; - - case ICAL_WEEKLY_RECURRENCE: - make_weekly_special (rpage); - gtk_widget_show (priv->special); - break; - - case ICAL_MONTHLY_RECURRENCE: - make_monthly_special (rpage); - gtk_widget_show (priv->special); - break; - - case ICAL_YEARLY_RECURRENCE: - gtk_widget_hide (priv->special); - break; - - default: - g_assert_not_reached (); - } -} - -/* Counts the elements in the by_xxx fields of an icalrecurrencetype */ -static int -count_by_xxx (short *field, int max_elements) -{ - int i; - - for (i = 0; i < max_elements; i++) - if (field[i] == ICAL_RECURRENCE_ARRAY_MAX) - break; - - return i; -} - -/* Callback used when the ending-until date editor changes */ -static void -ending_until_changed_cb (EDateEdit *de, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - field_changed (rpage); - preview_recur (rpage); -} - -/* Creates the special contents for "ending until" (end date) recurrences */ -static void -make_ending_until_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - EDateEdit *de; - - priv = rpage->priv; - - g_assert (GTK_BIN (priv->ending_special)->child == NULL); - g_assert (priv->ending_date_edit == NULL); - - /* Create the widget */ - - priv->ending_date_edit = comp_editor_new_date_edit (TRUE, FALSE, - FALSE); - de = E_DATE_EDIT (priv->ending_date_edit); - - gtk_container_add (GTK_CONTAINER (priv->ending_special), - GTK_WIDGET (de)); - gtk_widget_show_all (GTK_WIDGET (de)); - - /* Set the value */ - - e_date_edit_set_date (de, priv->ending_date_tt.year, - priv->ending_date_tt.month, - priv->ending_date_tt.day); - - g_signal_connect((de), "changed", - G_CALLBACK (ending_until_changed_cb), rpage); - - /* Make sure the EDateEdit widget uses our timezones to get the - current time. */ - e_date_edit_set_get_time_callback (de, - (EDateEditGetTimeCallback) comp_editor_get_current_time, - rpage, NULL); -} - -/* Callback used when the ending-count value changes */ -static void -ending_count_value_changed_cb (GtkAdjustment *adj, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - field_changed (rpage); - preview_recur (rpage); -} - -/* Creates the special contents for the occurrence count case */ -static void -make_ending_count_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - GtkWidget *hbox; - GtkWidget *label; - GtkAdjustment *adj; - - priv = rpage->priv; - - g_assert (GTK_BIN (priv->ending_special)->child == NULL); - g_assert (priv->ending_count_spin == NULL); - - /* Create the widgets */ - - hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (priv->ending_special), hbox); - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (1, 1, 10000, 1, 10, 10)); - priv->ending_count_spin = gtk_spin_button_new (adj, 1, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->ending_count_spin, - FALSE, FALSE, 6); - - label = gtk_label_new (_("occurrences")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - - gtk_widget_show_all (hbox); - - /* Set the values */ - - e_dialog_spin_set (priv->ending_count_spin, priv->ending_count); - - g_signal_connect((adj), "value_changed", - G_CALLBACK (ending_count_value_changed_cb), - rpage); -} - -/* Changes the recurrence-ending-special widget to match the ending date option - * - * For: <n> [days, weeks, months, years, occurrences] - * Until: <date selector> - * Forever: nothing. - */ -static void -make_ending_special (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - enum ending_type ending_type; - - priv = rpage->priv; - - if (GTK_BIN (priv->ending_special)->child != NULL) { - gtk_widget_destroy (GTK_BIN (priv->ending_special)->child); - - priv->ending_date_edit = NULL; - priv->ending_count_spin = NULL; - } - - ending_type = e_dialog_option_menu_get (priv->ending_menu, - ending_types_map); - - switch (ending_type) { - case ENDING_FOR: - make_ending_count_special (rpage); - gtk_widget_show (priv->ending_special); - break; - - case ENDING_UNTIL: - make_ending_until_special (rpage); - gtk_widget_show (priv->ending_special); - break; - - case ENDING_FOREVER: - gtk_widget_hide (priv->ending_special); - break; - - default: - g_assert_not_reached (); - } -} - -/* Fills the recurrence ending date widgets with the values from the calendar - * component. - */ -static void -fill_ending_date (RecurrencePage *rpage, struct icalrecurrencetype *r) -{ - RecurrencePagePrivate *priv; - GtkWidget *menu; - - priv = rpage->priv; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->ending_menu)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - if (r->count == 0) { - if (r->until.year == 0) { - /* Forever */ - - e_dialog_option_menu_set (priv->ending_menu, - ENDING_FOREVER, - ending_types_map); - } else { - /* Ending date */ - - if (!r->until.is_date) { - CalClient *client = COMP_EDITOR_PAGE (rpage)->client; - CalComponentDateTime dt; - icaltimezone *from_zone, *to_zone; - - cal_component_get_dtstart (priv->comp, &dt); - - if (dt.value->is_date) - to_zone = icaltimezone_get_builtin_timezone (calendar_config_get_timezone ()); - else if (dt.tzid == NULL) - to_zone = icaltimezone_get_utc_timezone (); - else - cal_client_get_timezone (client, dt.tzid, &to_zone); - from_zone = icaltimezone_get_utc_timezone (); - - icaltimezone_convert_time (&r->until, from_zone, to_zone); - - r->until.hour = 0; - r->until.minute = 0; - r->until.second = 0; - r->until.is_date = TRUE; - r->until.is_utc = FALSE; - } - - priv->ending_date_tt = r->until; - e_dialog_option_menu_set (priv->ending_menu, - ENDING_UNTIL, - ending_types_map); - } - } else { - /* Count of occurrences */ - - priv->ending_count = r->count; - e_dialog_option_menu_set (priv->ending_menu, - ENDING_FOR, - ending_types_map); - } - - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - make_ending_special (rpage); -} - -/* fill_widgets handler for the recurrence page. This function is particularly - * tricky because it has to discriminate between recurrences we support for - * editing and the ones we don't. We only support at most one recurrence rule; - * no rdates or exrules (exdates are handled just fine elsewhere). - */ -static void -recurrence_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - CalComponentText text; - CompEditorPageDates dates; - GSList *rrule_list; - int len; - struct icalrecurrencetype *r; - int n_by_second, n_by_minute, n_by_hour; - int n_by_day, n_by_month_day, n_by_year_day; - int n_by_week_no, n_by_month, n_by_set_pos; - GtkWidget *menu; - GtkAdjustment *adj; - - rpage = RECURRENCE_PAGE (page); - priv = rpage->priv; - - /* Keep a copy of the component so that we can expand the recurrence - * set for the preview. - */ - - if (priv->comp) - g_object_unref((priv->comp)); - - priv->comp = cal_component_clone (comp); - - /* Don't send off changes during this time */ - priv->updating = TRUE; - - /* Clean the page */ - clear_widgets (rpage); - - /* Summary */ - cal_component_get_summary (comp, &text); - recurrence_page_set_summary (page, text.value); - - /* Dates */ - comp_editor_dates (&dates, comp); - recurrence_page_set_dates (page, &dates); - comp_editor_free_dates (&dates); - - /* Exceptions */ - fill_exception_widgets (rpage, comp); - - /* Set up defaults for the special widgets */ - set_special_defaults (rpage); - - /* No recurrences? */ - - if (!cal_component_has_rdates (comp) - && !cal_component_has_rrules (comp) - && !cal_component_has_exrules (comp)) { - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->none), - rpage); - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->simple), - rpage); - gtk_signal_handler_block_by_data (GTK_OBJECT (priv->custom), - rpage); - e_dialog_radio_set (priv->none, RECUR_NONE, type_map); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->none), - rpage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->simple), - rpage); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (priv->custom), - rpage); - - gtk_widget_set_sensitive (priv->custom, FALSE); - - sensitize_recur_widgets (rpage); - preview_recur (rpage); - - priv->updating = FALSE; - return; - } - - /* See if it is a custom set we don't support */ - - cal_component_get_rrule_list (comp, &rrule_list); - len = g_slist_length (rrule_list); - if (len > 1 - || cal_component_has_rdates (comp) - || cal_component_has_exrules (comp)) - goto custom; - - /* Down to one rule, so test that one */ - - g_assert (len == 1); - r = rrule_list->data; - - /* Any funky frequency? */ - - if (r->freq == ICAL_SECONDLY_RECURRENCE - || r->freq == ICAL_MINUTELY_RECURRENCE - || r->freq == ICAL_HOURLY_RECURRENCE) - goto custom; - - /* Any funky shit? */ - -#define N_HAS_BY(field) (count_by_xxx (field, sizeof (field) / sizeof (field[0]))) - - n_by_second = N_HAS_BY (r->by_second); - n_by_minute = N_HAS_BY (r->by_minute); - n_by_hour = N_HAS_BY (r->by_hour); - n_by_day = N_HAS_BY (r->by_day); - n_by_month_day = N_HAS_BY (r->by_month_day); - n_by_year_day = N_HAS_BY (r->by_year_day); - n_by_week_no = N_HAS_BY (r->by_week_no); - n_by_month = N_HAS_BY (r->by_month); - n_by_set_pos = N_HAS_BY (r->by_set_pos); - - if (n_by_second != 0 - || n_by_minute != 0 - || n_by_hour != 0) - goto custom; - - /* Filter the funky shit based on the frequency; if there is nothing - * weird we can actually set the widgets. - */ - - switch (r->freq) { - case ICAL_DAILY_RECURRENCE: - if (n_by_day != 0 - || n_by_month_day != 0 - || n_by_year_day != 0 - || n_by_week_no != 0 - || n_by_month != 0 - || n_by_set_pos != 0) - goto custom; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->interval_unit, - ICAL_DAILY_RECURRENCE, - freq_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - break; - - case ICAL_WEEKLY_RECURRENCE: { - int i; - guint8 day_mask; - - if (n_by_month_day != 0 - || n_by_year_day != 0 - || n_by_week_no != 0 - || n_by_month != 0 - || n_by_set_pos != 0) - goto custom; - - day_mask = 0; - - for (i = 0; i < 8 && r->by_day[i] != ICAL_RECURRENCE_ARRAY_MAX; i++) { - enum icalrecurrencetype_weekday weekday; - int pos; - - weekday = icalrecurrencetype_day_day_of_week (r->by_day[i]); - pos = icalrecurrencetype_day_position (r->by_day[i]); - - if (pos != 0) - goto custom; - - switch (weekday) { - case ICAL_SUNDAY_WEEKDAY: - day_mask |= 1 << 0; - break; - - case ICAL_MONDAY_WEEKDAY: - day_mask |= 1 << 1; - break; - - case ICAL_TUESDAY_WEEKDAY: - day_mask |= 1 << 2; - break; - - case ICAL_WEDNESDAY_WEEKDAY: - day_mask |= 1 << 3; - break; - - case ICAL_THURSDAY_WEEKDAY: - day_mask |= 1 << 4; - break; - - case ICAL_FRIDAY_WEEKDAY: - day_mask |= 1 << 5; - break; - - case ICAL_SATURDAY_WEEKDAY: - day_mask |= 1 << 6; - break; - - default: - break; - } - } - - priv->weekday_day_mask = day_mask; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->interval_unit, - ICAL_WEEKLY_RECURRENCE, - freq_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - break; - } - - case ICAL_MONTHLY_RECURRENCE: - if (n_by_year_day != 0 - || n_by_week_no != 0 - || n_by_month != 0 - || n_by_set_pos > 1) - goto custom; - - if (n_by_month_day == 1) { - int nth; - - if (n_by_set_pos != 0) - goto custom; - - nth = r->by_month_day[0]; - if (nth < 1 && nth != -1) - goto custom; - - if (nth == -1) { - CalComponentDateTime dt; - - cal_component_get_dtstart (comp, &dt); - priv->month_index = dt.value->day; - priv->month_num = MONTH_NUM_LAST; - } else { - priv->month_index = nth; - priv->month_num = MONTH_NUM_DAY; - } - priv->month_day = MONTH_DAY_NTH; - - } else if (n_by_day == 1) { - enum icalrecurrencetype_weekday weekday; - int pos; - enum month_day_options month_day; - - /* Outlook 2000 uses BYDAY=TU;BYSETPOS=2, and will not - accept BYDAY=2TU. So we now use the same as Outlook - by default. */ - - weekday = icalrecurrencetype_day_day_of_week (r->by_day[0]); - pos = icalrecurrencetype_day_position (r->by_day[0]); - - if (pos == 0) { - if (n_by_set_pos != 1) - goto custom; - pos = r->by_set_pos[0]; - } else if (pos < 0) { - goto custom; - } - - switch (weekday) { - case ICAL_MONDAY_WEEKDAY: - month_day = MONTH_DAY_MON; - break; - - case ICAL_TUESDAY_WEEKDAY: - month_day = MONTH_DAY_TUE; - break; - - case ICAL_WEDNESDAY_WEEKDAY: - month_day = MONTH_DAY_WED; - break; - - case ICAL_THURSDAY_WEEKDAY: - month_day = MONTH_DAY_THU; - break; - - case ICAL_FRIDAY_WEEKDAY: - month_day = MONTH_DAY_FRI; - break; - - case ICAL_SATURDAY_WEEKDAY: - month_day = MONTH_DAY_SAT; - break; - - case ICAL_SUNDAY_WEEKDAY: - month_day = MONTH_DAY_SUN; - break; - - default: - goto custom; - } - - if (pos == -1) - priv->month_num = MONTH_NUM_LAST; - else - priv->month_num = pos - 1; - priv->month_day = month_day; - } else - goto custom; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->interval_unit, - ICAL_MONTHLY_RECURRENCE, - freq_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - break; - - case ICAL_YEARLY_RECURRENCE: - if (n_by_day != 0 - || n_by_month_day != 0 - || n_by_year_day != 0 - || n_by_week_no != 0 - || n_by_month != 0 - || n_by_set_pos != 0) - goto custom; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_handlers_block_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_option_menu_set (priv->interval_unit, - ICAL_YEARLY_RECURRENCE, - freq_map); - g_signal_handlers_unblock_matched (menu, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - break; - - default: - goto custom; - } - - /* If we got here it means it is a simple recurrence */ - - g_signal_handlers_block_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_radio_set (priv->simple, RECUR_SIMPLE, type_map); - g_signal_handlers_unblock_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - gtk_widget_set_sensitive (priv->custom, FALSE); - - sensitize_recur_widgets (rpage); - make_recurrence_special (rpage); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->interval_value)); - g_signal_handlers_block_matched (adj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_spin_set (priv->interval_value, r->interval); - g_signal_handlers_unblock_matched (adj, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - fill_ending_date (rpage, r); - - goto out; - - custom: - - g_signal_handlers_block_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_block_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - e_dialog_radio_set (priv->custom, RECUR_CUSTOM, type_map); - g_signal_handlers_unblock_matched (priv->none, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->simple, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - g_signal_handlers_unblock_matched (priv->custom, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, rpage); - - gtk_widget_set_sensitive (priv->custom, TRUE); - sensitize_recur_widgets (rpage); - - out: - - cal_component_free_recur_list (rrule_list); - preview_recur (rpage); - - priv->updating = FALSE; -} - -/* fill_component handler for the recurrence page */ -static gboolean -recurrence_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (page); - return fill_component (rpage, comp); -} - -/* set_summary handler for the recurrence page */ -static void -recurrence_page_set_summary (CompEditorPage *page, const char *summary) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - - rpage = RECURRENCE_PAGE (page); - priv = rpage->priv; - - gtk_label_set_text (GTK_LABEL (priv->summary), summary); -} - -/* set_dates handler for the recurrence page */ -static void -recurrence_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - CalComponentDateTime dt; - struct icaltimetype icaltime; - guint8 mask; - - rpage = RECURRENCE_PAGE (page); - priv = rpage->priv; - - comp_editor_date_label (dates, priv->date_time); - - /* Copy the dates to our component */ - - if (!priv->comp) - return; - - dt.value = &icaltime; - - if (dates->start) { - icaltime = *dates->start->value; - dt.tzid = dates->start->tzid; - cal_component_set_dtstart (priv->comp, &dt); - } - - if (dates->end) { - icaltime = *dates->end->value; - dt.tzid = dates->end->tzid; - cal_component_set_dtend (priv->comp, &dt); - } - - /* Update the weekday picker if necessary */ - mask = get_start_weekday_mask (priv->comp); - if (mask != priv->weekday_blocked_day_mask) { - priv->weekday_day_mask = priv->weekday_day_mask | mask; - priv->weekday_blocked_day_mask = mask; - - if (priv->weekday_picker != NULL) { - weekday_picker_set_days (WEEKDAY_PICKER (priv->weekday_picker), - priv->weekday_day_mask); - weekday_picker_set_blocked_days (WEEKDAY_PICKER (priv->weekday_picker), - priv->weekday_blocked_day_mask); - } - } - - /* Make sure the preview gets updated. */ - preview_recur (rpage); -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (RecurrencePage *rpage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (rpage); - RecurrencePagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = rpage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("recurrence-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - priv->summary = GW ("summary"); - priv->date_time = GW ("date-time"); - - priv->none = GW ("none"); - priv->simple = GW ("simple"); - priv->custom = GW ("custom"); - priv->params = GW ("params"); - - priv->interval_value = GW ("interval-value"); - priv->interval_unit = GW ("interval-unit"); - priv->special = GW ("special"); - priv->ending_menu = GW ("ending-menu"); - priv->ending_special = GW ("ending-special"); - priv->custom_warning_bin = GW ("custom-warning-bin"); - - priv->exception_date = GW ("exception-date"); - gtk_widget_show (priv->exception_date); - priv->exception_list = GW ("exception-list"); - priv->exception_add = GW ("exception-add"); - priv->exception_modify = GW ("exception-modify"); - priv->exception_delete = GW ("exception-delete"); - - priv->preview_bin = GW ("preview-bin"); - -#undef GW - - return (priv->summary - && priv->date_time - && priv->none - && priv->simple - && priv->custom - && priv->params - && priv->interval_value - && priv->interval_unit - && priv->special - && priv->ending_menu - && priv->ending_special - && priv->custom_warning_bin - && priv->exception_date - && priv->exception_list - && priv->exception_add - && priv->exception_modify - && priv->exception_delete - && priv->preview_bin); -} - -/* Callback used when the displayed date range in the recurrence preview - * calendar changes. - */ -static void -preview_date_range_changed_cb (ECalendarItem *item, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - preview_recur (rpage); -} - -/* Callback used when one of the recurrence type radio buttons is toggled. We - * enable or disable the recurrence parameters. - */ -static void -type_toggled_cb (GtkToggleButton *toggle, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - - if (toggle->active) { - sensitize_recur_widgets (rpage); - preview_recur (rpage); - } -} - -/* Callback used when the recurrence interval value spin button changes. */ -static void -interval_value_changed_cb (GtkAdjustment *adj, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - preview_recur (rpage); -} - -/* Callback used when the recurrence interval option menu changes. We need to - * change the contents of the recurrence special widget. - */ -static void -interval_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - make_recurrence_special (rpage); - preview_recur (rpage); -} - -/* Callback used when the recurrence ending option menu changes. We need to - * change the contents of the ending special widget. - */ -static void -ending_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - RecurrencePage *rpage; - - rpage = RECURRENCE_PAGE (data); - - field_changed (rpage); - make_ending_special (rpage); - preview_recur (rpage); -} - -/* Callback for the "add exception" button */ -static void -exception_add_cb (GtkWidget *widget, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - CalComponentDateTime dt; - struct icaltimetype icaltime = icaltime_null_time (); - gboolean date_set; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - field_changed (rpage); - - dt.value = &icaltime; - - /* We use DATE values for exceptions, so we don't need a TZID. */ - dt.tzid = NULL; - icaltime.is_date = 1; - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->exception_date), - &icaltime.year, - &icaltime.month, - &icaltime.day); - g_assert (date_set); - - append_exception (rpage, &dt); - preview_recur (rpage); -} - -/* Callback for the "modify exception" button */ -static void -exception_modify_cb (GtkWidget *widget, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - GtkTreeSelection *selection; - CalComponentDateTime dt; - struct icaltimetype icaltime = icaltime_null_time (); - struct icaltimetype *tt; - GtkTreeIter iter; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->exception_list)); - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { - g_warning ("Could not get a selection to modify."); - return; - } - field_changed (rpage); - - dt.value = &icaltime; - tt = dt.value; - e_date_edit_get_date (E_DATE_EDIT (priv->exception_date), - &tt->year, &tt->month, &tt->day); - tt->hour = 0; - tt->minute = 0; - tt->second = 0; - tt->is_date = 1; - - /* No TZID, since we are using a DATE value now. */ - dt.tzid = NULL; - - e_date_time_list_set_date_time (priv->exception_list_store, &iter, &dt); - preview_recur (rpage); -} - -/* Callback for the "delete exception" button */ -static void -exception_delete_cb (GtkWidget *widget, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreePath *path; - gboolean valid_iter; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->exception_list)); - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { - g_warning ("Could not get a selection to delete."); - return; - } - - field_changed (rpage); - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->exception_list_store), &iter); - e_date_time_list_remove (priv->exception_list_store, &iter); - - /* Select closest item after removal */ - valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->exception_list_store), &iter, path); - if (!valid_iter) { - gtk_tree_path_prev (path); - valid_iter = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->exception_list_store), &iter, path); - } - - if (valid_iter) - gtk_tree_selection_select_iter (selection, &iter); - - gtk_tree_path_free (path); - preview_recur (rpage); -} - -/* Callback used when a row is selected in the list of exception - * dates. We must update the date/time widgets to reflect the - * exception's value. - */ -static void -exception_selection_changed_cb (GtkTreeSelection *selection, gpointer data) -{ - RecurrencePage *rpage; - RecurrencePagePrivate *priv; - const CalComponentDateTime *dt; - struct icaltimetype *t; - GtkTreeIter iter; - - rpage = RECURRENCE_PAGE (data); - priv = rpage->priv; - - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { - gtk_widget_set_sensitive (priv->exception_modify, FALSE); - gtk_widget_set_sensitive (priv->exception_delete, FALSE); - return; - } - - gtk_widget_set_sensitive (priv->exception_modify, TRUE); - gtk_widget_set_sensitive (priv->exception_delete, TRUE); - - dt = e_date_time_list_get_date_time (priv->exception_list_store, &iter); - g_assert (dt != NULL); - - t = dt->value; - - e_date_edit_set_date (E_DATE_EDIT (priv->exception_date), - t->year, t->month, t->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->exception_date), - t->hour, t->minute); -} - -/* This is called when any field is changed; it notifies upstream. */ -static void -field_changed (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - - priv = rpage->priv; - - if (!priv->updating) - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (rpage)); -} - -/* Hooks the widget signals */ -static void -init_widgets (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - ECalendar *ecal; - GtkAdjustment *adj; - GtkWidget *menu; - GtkTreeViewColumn *column; - GtkCellRenderer *cell_renderer; - - priv = rpage->priv; - - /* Recurrence preview */ - - priv->preview_calendar = e_calendar_new (); - ecal = E_CALENDAR (priv->preview_calendar); - g_signal_connect((ecal->calitem), "date_range_changed", - G_CALLBACK (preview_date_range_changed_cb), - rpage); - calendar_config_configure_e_calendar (ecal); - e_calendar_item_set_max_days_sel (ecal->calitem, 0); - gtk_container_add (GTK_CONTAINER (priv->preview_bin), - priv->preview_calendar); - gtk_widget_show (priv->preview_calendar); - - /* Make sure the EDateEdit widgets and ECalendarItem use our timezones - to get the current time. */ - e_date_edit_set_show_time (E_DATE_EDIT (priv->exception_date), FALSE); - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->exception_date), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - rpage, NULL); - e_calendar_item_set_get_time_callback (ecal->calitem, - (ECalendarItemGetTimeCallback) comp_editor_get_current_time, - rpage, NULL); - - /* Recurrence types */ - - g_signal_connect((priv->none), "toggled", - G_CALLBACK (type_toggled_cb), rpage); - g_signal_connect((priv->simple), "toggled", - G_CALLBACK (type_toggled_cb), rpage); - g_signal_connect((priv->custom), "toggled", - G_CALLBACK (type_toggled_cb), rpage); - - /* Recurrence interval */ - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->interval_value)); - g_signal_connect((adj), "value_changed", - G_CALLBACK (interval_value_changed_cb), - rpage); - - /* Recurrence units */ - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->interval_unit)); - g_signal_connect((menu), "selection_done", - G_CALLBACK (interval_selection_done_cb), - rpage); - - /* Recurrence ending */ - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (priv->ending_menu)); - g_signal_connect((menu), "selection_done", - G_CALLBACK (ending_selection_done_cb), rpage); - - /* Exception buttons */ - - g_signal_connect((priv->exception_add), "clicked", - G_CALLBACK (exception_add_cb), rpage); - g_signal_connect((priv->exception_modify), "clicked", - G_CALLBACK (exception_modify_cb), rpage); - g_signal_connect((priv->exception_delete), "clicked", - G_CALLBACK (exception_delete_cb), rpage); - - gtk_widget_set_sensitive (priv->exception_modify, FALSE); - gtk_widget_set_sensitive (priv->exception_delete, FALSE); - - /* Exception list */ - - /* Model */ - priv->exception_list_store = e_date_time_list_new (); - gtk_tree_view_set_model (GTK_TREE_VIEW (priv->exception_list), - GTK_TREE_MODEL (priv->exception_list_store)); - - /* View */ - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, "Date/Time"); - cell_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ()); - gtk_tree_view_column_pack_start (column, cell_renderer, TRUE); - gtk_tree_view_column_add_attribute (column, cell_renderer, "text", E_DATE_TIME_LIST_COLUMN_DESCRIPTION); - gtk_tree_view_append_column (GTK_TREE_VIEW (priv->exception_list), column); - - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->exception_list)), "changed", - G_CALLBACK (exception_selection_changed_cb), rpage); -} - - - -/** - * recurrence_page_construct: - * @rpage: A recurrence page. - * - * Constructs a recurrence page by loading its Glade data. - * - * Return value: The same object as @rpage, or NULL if the widgets could not be - * created. - **/ -RecurrencePage * -recurrence_page_construct (RecurrencePage *rpage) -{ - RecurrencePagePrivate *priv; - - priv = rpage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR - "/recurrence-page.glade", NULL, NULL); - if (!priv->xml) { - g_message ("recurrence_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (rpage)) { - g_message ("recurrence_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - init_widgets (rpage); - - return rpage; -} - -/** - * recurrence_page_new: - * - * Creates a new recurrence page. - * - * Return value: A newly-created recurrence page, or NULL if the page could not - * be created. - **/ -RecurrencePage * -recurrence_page_new (void) -{ - RecurrencePage *rpage; - - rpage = g_object_new (TYPE_RECURRENCE_PAGE, NULL); - if (!recurrence_page_construct (rpage)) { - g_object_unref((rpage)); - return NULL; - } - - return rpage; -} - - -GtkWidget *make_exdate_date_edit (void); - -GtkWidget * -make_exdate_date_edit (void) -{ - return comp_editor_new_date_edit (TRUE, TRUE, FALSE); -} - diff --git a/calendar/gui/dialogs/recurrence-page.glade b/calendar/gui/dialogs/recurrence-page.glade deleted file mode 100644 index c5c2158979..0000000000 --- a/calendar/gui/dialogs/recurrence-page.glade +++ /dev/null @@ -1,724 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="recurrence-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="recurrence-page"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame35"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkTable" id="table14"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label66"> - <property name="visible">True</property> - <property name="label" translatable="yes">Summary:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label67"> - <property name="visible">True</property> - <property name="label" translatable="yes">Date/Time:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="summary"> - <property name="visible">True</property> - <property name="label" translatable="yes"></property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">4</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="date-time"> - <property name="visible">True</property> - <property name="label" translatable="yes"></property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">4</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Basics</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox55"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">0</property> - - <child> - <widget class="GtkFrame" id="frame36"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkVBox" id="vbox56"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="hbox56"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkRadioButton" id="none"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_No recurrence</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="simple"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Simple recurrence</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">none</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="custom"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Custom recurrence</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">none</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox57"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="params"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">2</property> - - <child> - <widget class="GtkLabel" id="label68"> - <property name="visible">True</property> - <property name="label" translatable="yes">Every</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="interval-value"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">True</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 1 10000 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="interval-unit"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">day(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">week(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget4"> - <property name="visible">True</property> - <property name="label" translatable="yes">month(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget5"> - <property name="visible">True</property> - <property name="label" translatable="yes">year(s)</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="special"> - <property name="visible">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="ending-menu"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget6"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget7"> - <property name="visible">True</property> - <property name="label" translatable="yes">for</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget8"> - <property name="visible">True</property> - <property name="label" translatable="yes">until</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget9"> - <property name="visible">True</property> - <property name="label" translatable="yes">forever</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="ending-special"> - <property name="visible">True</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="custom-warning-bin"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xscale">1</property> - <property name="yscale">1</property> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label68"> - <property name="visible">True</property> - <property name="label" translatable="yes">Recurrence Rule</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox59"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame37"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox60"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkVBox" id="vbox57"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">4</property> - - <child> - <widget class="GtkButton" id="exception-add"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">A_dd</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="exception-modify"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Modify</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkButton" id="exception-delete"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">_Remove</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox58"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="Custom" id="exception-date"> - <property name="visible">True</property> - <property name="creation_function">make_exdate_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Tue, 16 May 2000 01:42:29 GMT</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow14"> - <property name="visible">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTreeView" id="exception-list"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="headers_visible">True</property> - <property name="rules_hint">False</property> - <property name="reorderable">False</property> - <property name="enable_search">True</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label69"> - <property name="visible">True</property> - <property name="label" translatable="yes">Exceptions</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox59"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label70"> - <property name="visible">True</property> - <property name="label" translatable="yes">Preview</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="preview-bin"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xscale">1</property> - <property name="yscale">1</property> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/recurrence-page.h b/calendar/gui/dialogs/recurrence-page.h deleted file mode 100644 index 7a10eff069..0000000000 --- a/calendar/gui/dialogs/recurrence-page.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Evolution calendar - Recurrence page of the calendar component dialogs - * - * Copyright (C) 2001-2003 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * Hans Petter Jansson <hpj@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 RECURRENCE_PAGE_H -#define RECURRENCE_PAGE_H - -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_RECURRENCE_PAGE (recurrence_page_get_type ()) -#define RECURRENCE_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_RECURRENCE_PAGE, RecurrencePage)) -#define RECURRENCE_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_RECURRENCE_PAGE, RecurrencePageClass)) -#define IS_RECURRENCE_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_RECURRENCE_PAGE)) -#define IS_RECURRENCE_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_RECURRENCE_PAGE)) - -typedef struct _RecurrencePagePrivate RecurrencePagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - RecurrencePagePrivate *priv; -} RecurrencePage; - -typedef struct { - CompEditorPageClass parent_class; -} RecurrencePageClass; - - -GtkType recurrence_page_get_type (void); -RecurrencePage *recurrence_page_construct (RecurrencePage *rpage); -RecurrencePage *recurrence_page_new (void); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/save-comp.c b/calendar/gui/dialogs/save-comp.c deleted file mode 100644 index 499a278dc3..0000000000 --- a/calendar/gui/dialogs/save-comp.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Evolution calendar - Delete calendar component dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <gal/widgets/e-unicode.h> -#include "save-comp.h" - - - -/** - * save_component_dialog: - * @parent: Window to use as the transient dialog's parent. - * - * Pops up a dialog box asking the user whether he wants to save changes for - * a calendar component. - * - * Return value: the response_id of the button selected. - **/ -GtkResponseType -save_component_dialog (GtkWindow *parent) -{ - GtkWidget *dialog; - gint r; - - dialog = gnome_message_box_new (_("Do you want to save changes?"), - GNOME_MESSAGE_BOX_QUESTION, - GTK_STOCK_CANCEL, - GTK_STOCK_NO, - GTK_STOCK_YES, - NULL); - - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gnome_dialog_grab_focus (GNOME_DIALOG (dialog), 0); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent); - - r = gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - if (r == 1) - return GTK_RESPONSE_NO; - else if (r == 2) - return GTK_RESPONSE_YES; - - return GTK_RESPONSE_CANCEL; -} diff --git a/calendar/gui/dialogs/save-comp.h b/calendar/gui/dialogs/save-comp.h deleted file mode 100644 index a9aedd2bce..0000000000 --- a/calendar/gui/dialogs/save-comp.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Evolution calendar - Delete calendar component dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 SAVE_COMP_H -#define SAVE_COMP_H - -#include <gtk/gtkdialog.h> - -GtkResponseType save_component_dialog (GtkWindow *parent); - -#endif diff --git a/calendar/gui/dialogs/schedule-page.c b/calendar/gui/dialogs/schedule-page.c deleted file mode 100644 index 2163d51f1e..0000000000 --- a/calendar/gui/dialogs/schedule-page.c +++ /dev/null @@ -1,527 +0,0 @@ -/* Evolution calendar - Scheduling page - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkwindow.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <glade/glade.h> -#include <gal/e-table/e-cell-combo.h> -#include <gal/e-table/e-cell-text.h> -#include <gal/e-table/e-table-simple.h> -#include <gal/e-table/e-table-scrolled.h> -#include <gal/widgets/e-unicode.h> -#include <gal/widgets/e-popup-menu.h> -#include <gal/widgets/e-gui-utils.h> -#include <widgets/misc/e-dateedit.h> -#include <e-util/e-dialog-widgets.h> -#include "../calendar-config.h" -#include "../e-meeting-time-sel.h" -#include "../itip-utils.h" -#include "comp-editor-util.h" -#include "e-delegate-dialog.h" -#include "schedule-page.h" - - - -/* Private part of the SchedulePage structure */ -struct _SchedulePagePrivate { - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *main; - - /* Model */ - EMeetingModel *model; - - /* Selector */ - EMeetingTimeSelector *sel; - - /* The timezone we use. Note that we use the same timezone for the - start and end date. We convert the end date if it is passed in in - another timezone. */ - icaltimezone *zone; - - gboolean updating; -}; - - - -static void schedule_page_class_init (SchedulePageClass *class); -static void schedule_page_init (SchedulePage *spage); -static void schedule_page_finalize (GObject *object); - -static GtkWidget *schedule_page_get_widget (CompEditorPage *page); -static void schedule_page_focus_main_widget (CompEditorPage *page); -static void schedule_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean schedule_page_fill_component (CompEditorPage *page, CalComponent *comp); -static void schedule_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); - -static void times_changed_cb (GtkWidget *widget, gpointer data); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * schedule_page_get_type: - * - * Registers the #SchedulePage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #SchedulePage class. - **/ - -E_MAKE_TYPE (schedule_page, "SchedulePage", SchedulePage, schedule_page_class_init, - schedule_page_init, TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the schedule page */ -static void -schedule_page_class_init (SchedulePageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref (TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = schedule_page_get_widget; - editor_page_class->focus_main_widget = schedule_page_focus_main_widget; - editor_page_class->fill_widgets = schedule_page_fill_widgets; - editor_page_class->fill_component = schedule_page_fill_component; - editor_page_class->set_summary = NULL; - editor_page_class->set_dates = schedule_page_set_dates; - - object_class->finalize = schedule_page_finalize; -} - -/* Object initialization function for the schedule page */ -static void -schedule_page_init (SchedulePage *spage) -{ - SchedulePagePrivate *priv; - - priv = g_new0 (SchedulePagePrivate, 1); - spage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - - priv->zone = NULL; - - priv->updating = FALSE; -} - -/* Destroy handler for the schedule page */ -static void -schedule_page_finalize (GObject *object) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_SCHEDULE_PAGE (object)); - - spage = SCHEDULE_PAGE (object); - priv = spage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - g_object_unref((priv->model)); - - g_free (priv); - spage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the schedule page */ -static GtkWidget * -schedule_page_get_widget (CompEditorPage *page) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - - spage = SCHEDULE_PAGE (page); - priv = spage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the schedule page */ -static void -schedule_page_focus_main_widget (CompEditorPage *page) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - - spage = SCHEDULE_PAGE (page); - priv = spage->priv; - - gtk_widget_grab_focus (GTK_WIDGET (priv->sel)); -} - -/* Set date/time */ -static void -update_time (SchedulePage *spage, CalComponentDateTime *start_date, CalComponentDateTime *end_date) -{ - SchedulePagePrivate *priv; - struct icaltimetype start_tt, end_tt; - icaltimezone *start_zone = NULL, *end_zone = NULL; - CalClientGetStatus status; - gboolean all_day; - - priv = spage->priv; - - /* Note that if we are creating a new event, the timezones may not be - on the server, so we try to get the builtin timezone with the TZID - first. */ - start_zone = icaltimezone_get_builtin_timezone_from_tzid (start_date->tzid); - if (!start_zone) { - status = cal_client_get_timezone (COMP_EDITOR_PAGE (spage)->client, - start_date->tzid, - &start_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - start_date->tzid ? start_date->tzid : ""); - } - - end_zone = icaltimezone_get_builtin_timezone_from_tzid (end_date->tzid); - if (!end_zone) { - status = cal_client_get_timezone (COMP_EDITOR_PAGE (spage)->client, - end_date->tzid, - &end_zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - end_date->tzid ? end_date->tzid : ""); - } - - start_tt = *start_date->value; - if (!end_date->value && start_tt.is_date) { - end_tt = start_tt; - icaltime_adjust (&end_tt, 1, 0, 0, 0); - } else { - end_tt = *end_date->value; - } - - /* If the end zone is not the same as the start zone, we convert it. */ - priv->zone = start_zone; - if (start_zone != end_zone) { - icaltimezone_convert_time (&end_tt, end_zone, start_zone); - } - e_meeting_model_set_zone (priv->model, priv->zone); - - all_day = (start_tt.is_date && end_tt.is_date) ? TRUE : FALSE; - - /* For All Day Events, if DTEND is after DTSTART, we subtract 1 day - from it. */ - if (all_day) { - if (icaltime_compare_date_only (end_tt, start_tt) > 0) { - icaltime_adjust (&end_tt, -1, 0, 0, 0); - } - } - - e_meeting_time_selector_set_all_day (priv->sel, all_day); - - e_date_edit_set_date (E_DATE_EDIT (priv->sel->start_date_edit), start_tt.year, - start_tt.month, start_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->sel->start_date_edit), - start_tt.hour, start_tt.minute); - - e_date_edit_set_date (E_DATE_EDIT (priv->sel->end_date_edit), end_tt.year, - end_tt.month, end_tt.day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->sel->end_date_edit), - end_tt.hour, end_tt.minute); - -} - - -/* Fills the widgets with default values */ -static void -clear_widgets (SchedulePage *spage) -{ - SchedulePagePrivate *priv; - - priv = spage->priv; -} - -/* fill_widgets handler for the schedule page */ -static void -schedule_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - CalComponentDateTime start_date, end_date; - - spage = SCHEDULE_PAGE (page); - priv = spage->priv; - - priv->updating = TRUE; - - /* Clean the screen */ - clear_widgets (spage); - - /* Start and end times */ - cal_component_get_dtstart (comp, &start_date); - cal_component_get_dtend (comp, &end_date); - update_time (spage, &start_date, &end_date); - - cal_component_free_datetime (&start_date); - cal_component_free_datetime (&end_date); - - priv->updating = FALSE; -} - -/* fill_component handler for the schedule page */ -static gboolean -schedule_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - - spage = SCHEDULE_PAGE (page); - priv = spage->priv; - - return TRUE; -} - -static void -schedule_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - SchedulePage *spage; - SchedulePagePrivate *priv; - - spage = SCHEDULE_PAGE (page); - priv = spage->priv; - - priv->updating = TRUE; - - update_time (spage, dates->start, dates->end); - - priv->updating = FALSE; -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (SchedulePage *spage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (spage); - SchedulePagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = spage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("schedule-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - -#undef GW - - return TRUE; -} - -static gboolean -init_widgets (SchedulePage *spage) -{ - SchedulePagePrivate *priv; - - priv = spage->priv; - - g_signal_connect((priv->sel), - "changed", G_CALLBACK (times_changed_cb), spage); - - return TRUE; - -} - - - -/** - * schedule_page_construct: - * @spage: An schedule page. - * - * Constructs an schedule page by loading its Glade data. - * - * Return value: The same object as @spage, or NULL if the widgets could not - * be created. - **/ -SchedulePage * -schedule_page_construct (SchedulePage *spage, EMeetingModel *emm) -{ - SchedulePagePrivate *priv; - - priv = spage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR - "/schedule-page.glade", NULL, NULL); - if (!priv->xml) { - g_message ("schedule_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (spage)) { - g_message ("schedule_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - /* Model */ - g_object_ref((emm)); - priv->model = emm; - - /* Selector */ - priv->sel = E_MEETING_TIME_SELECTOR (e_meeting_time_selector_new (emm)); - e_meeting_time_selector_set_working_hours (priv->sel, - calendar_config_get_day_start_hour (), - calendar_config_get_day_start_minute (), - calendar_config_get_day_end_hour (), - calendar_config_get_day_end_minute ()); - gtk_widget_show (GTK_WIDGET (priv->sel)); - gtk_box_pack_start (GTK_BOX (priv->main), GTK_WIDGET (priv->sel), TRUE, TRUE, 6); - - if (!init_widgets (spage)) { - g_message ("schedule_page_construct(): " - "Could not initialize the widgets!"); - return NULL; - } - - return spage; -} - -/** - * schedule_page_new: - * - * Creates a new schedule page. - * - * Return value: A newly-created schedule page, or NULL if the page could - * not be created. - **/ -SchedulePage * -schedule_page_new (EMeetingModel *emm) -{ - SchedulePage *spage; - - spage = g_object_new (TYPE_SCHEDULE_PAGE, NULL); - if (!schedule_page_construct (spage, emm)) { - g_object_unref((spage)); - return NULL; - } - - return spage; -} - -static void -times_changed_cb (GtkWidget *widget, gpointer data) -{ - SchedulePage *spage = data; - SchedulePagePrivate *priv; - CompEditorPageDates dates; - CalComponentDateTime start_dt, end_dt; - struct icaltimetype start_tt = icaltime_null_time (); - struct icaltimetype end_tt = icaltime_null_time (); - - priv = spage->priv; - - if (priv->updating) - return; - - e_date_edit_get_date (E_DATE_EDIT (priv->sel->start_date_edit), - &start_tt.year, - &start_tt.month, - &start_tt.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->sel->start_date_edit), - &start_tt.hour, - &start_tt.minute); - e_date_edit_get_date (E_DATE_EDIT (priv->sel->end_date_edit), - &end_tt.year, - &end_tt.month, - &end_tt.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->sel->end_date_edit), - &end_tt.hour, - &end_tt.minute); - - start_dt.value = &start_tt; - end_dt.value = &end_tt; - - if (e_date_edit_get_show_time (E_DATE_EDIT (priv->sel->start_date_edit))) { - /* We set the start and end to the same timezone. */ - start_dt.tzid = icaltimezone_get_tzid (priv->zone); - end_dt.tzid = start_dt.tzid; - } else { - /* For All-Day Events, we set the timezone to NULL, and add - 1 day to DTEND. */ - start_dt.value->is_date = TRUE; - start_dt.tzid = NULL; - end_dt.value->is_date = TRUE; - icaltime_adjust (&end_tt, 1, 0, 0, 0); - end_dt.tzid = NULL; - } - - dates.start = &start_dt; - dates.end = &end_dt; - dates.due = NULL; - dates.complete = NULL; - - comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (spage), - &dates); -} diff --git a/calendar/gui/dialogs/schedule-page.glade b/calendar/gui/dialogs/schedule-page.glade deleted file mode 100644 index 777e910817..0000000000 --- a/calendar/gui/dialogs/schedule-page.glade +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="schedule-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="schedule-page"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/schedule-page.h b/calendar/gui/dialogs/schedule-page.h deleted file mode 100644 index 42745962cd..0000000000 --- a/calendar/gui/dialogs/schedule-page.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Evolution calendar - Scheduling page - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 SCHEDULE_PAGE_H -#define SCHEDULE_PAGE_H - -#include "../e-meeting-model.h" -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_SCHEDULE_PAGE (schedule_page_get_type ()) -#define SCHEDULE_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCHEDULE_PAGE, SchedulePage)) -#define SCHEDULE_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCHEDULE_PAGE, SchedulePageClass)) -#define IS_SCHEDULE_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCHEDULE_PAGE)) -#define IS_SCHEDULE_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_SCHEDULE_PAGE)) - -typedef struct _SchedulePagePrivate SchedulePagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - SchedulePagePrivate *priv; -} SchedulePage; - -typedef struct { - CompEditorPageClass parent_class; -} SchedulePageClass; - - -GtkType schedule_page_get_type (void); -SchedulePage *schedule_page_construct (SchedulePage *mpage, EMeetingModel *emm); -SchedulePage *schedule_page_new (EMeetingModel *emm); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/send-comp.c b/calendar/gui/dialogs/send-comp.c deleted file mode 100644 index de89d607c2..0000000000 --- a/calendar/gui/dialogs/send-comp.c +++ /dev/null @@ -1,94 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gtk/gtkmessagedialog.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-uidefs.h> -#include <gal/widgets/e-unicode.h> -#include "send-comp.h" - - - -/** - * send_component_dialog: - * - * Pops up a dialog box asking the user whether he wants to send a - * iTip/iMip message - * - * Return value: TRUE if the user clicked Yes, FALSE otherwise. - **/ -gboolean -send_component_dialog (CalClient *client, CalComponent *comp, gboolean new) -{ - GtkWidget *dialog; - CalComponentVType vtype; - char *str; - gint response; - - if (cal_client_get_save_schedules (client)) - return FALSE; - - vtype = cal_component_get_vtype (comp); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - if (new) - str = g_strdup_printf (_("The meeting information has " - "been created. Send it?")); - else - str = g_strdup_printf (_("The meeting information has " - "changed. Send an updated " - "version?")); - break; - - case CAL_COMPONENT_TODO: - if (new) - str = g_strdup_printf (_("The task assignment " - "information has been " - "created. Send it?")); - else - str = g_strdup_printf (_("The task information has " - "changed. Send an updated " - "version?")); - break; - - default: - g_message ("send_component_dialog(): " - "Cannot handle object of type %d", vtype); - return FALSE; - } - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, str); - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - if (response == GTK_RESPONSE_YES) - return TRUE; - else - return FALSE; -} diff --git a/calendar/gui/dialogs/send-comp.h b/calendar/gui/dialogs/send-comp.h deleted file mode 100644 index d7e990e5b1..0000000000 --- a/calendar/gui/dialogs/send-comp.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Evolution calendar - Send calendar component dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Author: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 SEND_COMP_H -#define SEND_COMP_H - -#include <glib.h> -#include <cal-client/cal-client.h> -#include <cal-util/cal-component.h> - -gboolean send_component_dialog (CalClient *client, CalComponent *comp, gboolean new); - -#endif diff --git a/calendar/gui/dialogs/task-details-page.c b/calendar/gui/dialogs/task-details-page.c deleted file mode 100644 index 9e6a870f4c..0000000000 --- a/calendar/gui/dialogs/task-details-page.c +++ /dev/null @@ -1,764 +0,0 @@ -/* Evolution calendar - task details page - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtksignal.h> -#include <gtk/gtktogglebutton.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <widgets/misc/e-dateedit.h> -#include <widgets/misc/e-url-entry.h> -#include "e-util/e-dialog-widgets.h" -#include "../calendar-config.h" -#include "../e-timezone-entry.h" -#include "comp-editor-util.h" -#include "task-details-page.h" - - - -/* Private part of the TaskDetailsPage structure */ -struct _TaskDetailsPagePrivate { - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *main; - - GtkWidget *status; - GtkWidget *priority; - GtkWidget *percent_complete; - - GtkWidget *completed_date; - - GtkWidget *url_entry; - GtkWidget *url; - - gboolean updating; -}; - -/* Note that these two arrays must match. */ -static const int status_map[] = { - ICAL_STATUS_NONE, - ICAL_STATUS_INPROCESS, - ICAL_STATUS_COMPLETED, - ICAL_STATUS_CANCELLED, - -1 -}; - -typedef enum { - PRIORITY_HIGH, - PRIORITY_NORMAL, - PRIORITY_LOW, - PRIORITY_UNDEFINED, -} TaskEditorPriority; - -static const int priority_map[] = { - PRIORITY_HIGH, - PRIORITY_NORMAL, - PRIORITY_LOW, - PRIORITY_UNDEFINED, - -1 -}; - - - -static void task_details_page_class_init (TaskDetailsPageClass *class); -static void task_details_page_init (TaskDetailsPage *tdpage); -static void task_details_page_finalize (GObject *object); - -static GtkWidget *task_details_page_get_widget (CompEditorPage *page); -static void task_details_page_focus_main_widget (CompEditorPage *page); -static void task_details_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean task_details_page_fill_component (CompEditorPage *page, CalComponent *comp); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * task_details_page_get_type: - * - * Registers the #TaskDetailsPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #TaskDetailsPage class. - **/ - -E_MAKE_TYPE (task_details_page, "TaskDetailsPage", TaskDetailsPage, task_details_page_class_init, - task_details_page_init, TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the task page */ -static void -task_details_page_class_init (TaskDetailsPageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref(TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = task_details_page_get_widget; - editor_page_class->focus_main_widget = task_details_page_focus_main_widget; - editor_page_class->fill_widgets = task_details_page_fill_widgets; - editor_page_class->fill_component = task_details_page_fill_component; - - object_class->finalize = task_details_page_finalize; -} - -/* Object initialization function for the task page */ -static void -task_details_page_init (TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - - priv = g_new0 (TaskDetailsPagePrivate, 1); - tdpage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - - priv->status = NULL; - priv->priority = NULL; - priv->percent_complete = NULL; - - priv->completed_date = NULL; - - priv->url_entry = NULL; - priv->url = NULL; - - priv->updating = FALSE; -} - -/* Destroy handler for the task page */ -static void -task_details_page_finalize (GObject *object) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_TASK_DETAILS_PAGE (object)); - - tdpage = TASK_DETAILS_PAGE (object); - priv = tdpage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - g_free (priv); - tdpage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the task page */ -static GtkWidget * -task_details_page_get_widget (CompEditorPage *page) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - - tdpage = TASK_DETAILS_PAGE (page); - priv = tdpage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the task page */ -static void -task_details_page_focus_main_widget (CompEditorPage *page) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - - tdpage = TASK_DETAILS_PAGE (page); - priv = tdpage->priv; - - gtk_widget_grab_focus (priv->status); -} - - -static TaskEditorPriority -priority_value_to_index (int priority_value) -{ - TaskEditorPriority retval; - - if (priority_value == 0) - retval = PRIORITY_UNDEFINED; - else if (priority_value <= 4) - retval = PRIORITY_HIGH; - else if (priority_value == 5) - retval = PRIORITY_NORMAL; - else - retval = PRIORITY_LOW; - - return retval; -} - -static int -priority_index_to_value (TaskEditorPriority priority) -{ - int retval; - - switch (priority) { - case PRIORITY_UNDEFINED: - retval = 0; - break; - case PRIORITY_HIGH: - retval = 3; - break; - case PRIORITY_NORMAL: - retval = 5; - break; - case PRIORITY_LOW: - retval = 7; - break; - default: - retval = -1; - g_assert_not_reached (); - break; - } - - return retval; -} - -/* Fills the widgets with default values */ -static void -clear_widgets (TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - - priv = tdpage->priv; - - /* Date completed */ - e_date_edit_set_time (E_DATE_EDIT (priv->completed_date), -1); - - /* URL */ - e_dialog_editable_set (priv->url, NULL); -} - -/* fill_widgets handler for the task page */ -static void -task_details_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - int *priority_value, *percent = NULL; - TaskEditorPriority priority; - icalproperty_status status; - const char *url; - struct icaltimetype *completed = NULL; - - tdpage = TASK_DETAILS_PAGE (page); - priv = tdpage->priv; - - priv->updating = TRUE; - - /* Clean the screen */ - clear_widgets (tdpage); - - /* Percent Complete. */ - cal_component_get_percent (comp, &percent); - if (percent) { - e_dialog_spin_set (priv->percent_complete, *percent); - } else { - /* FIXME: Could check if task is completed and set 100%. */ - e_dialog_spin_set (priv->percent_complete, 0); - } - - /* Status. */ - cal_component_get_status (comp, &status); - if (status == ICAL_STATUS_NONE || status == ICAL_STATUS_NEEDSACTION) { - /* Try to use the percent value. */ - if (percent) { - if (*percent == 100) - status = ICAL_STATUS_COMPLETED; - else if (*percent > 0) - status = ICAL_STATUS_INPROCESS; - else - status = ICAL_STATUS_NONE; - } else - status = ICAL_STATUS_NONE; - } - e_dialog_option_menu_set (priv->status, status, status_map); - - cal_component_free_percent (percent); - - /* Completed Date. */ - cal_component_get_completed (comp, &completed); - if (completed) { - icaltimezone *utc_zone, *zone; - char *location; - - /* Completed is in UTC, but that would confuse the user, so - we convert it to local time. */ - utc_zone = icaltimezone_get_utc_timezone (); - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - icaltimezone_convert_time (completed, utc_zone, zone); - - e_date_edit_set_date (E_DATE_EDIT (priv->completed_date), - completed->year, completed->month, - completed->day); - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->completed_date), - completed->hour, - completed->minute); - - cal_component_free_icaltimetype (completed); - } - - /* Priority. */ - cal_component_get_priority (comp, &priority_value); - if (priority_value) { - priority = priority_value_to_index (*priority_value); - cal_component_free_priority (priority_value); - } else { - priority = PRIORITY_UNDEFINED; - } - e_dialog_option_menu_set (priv->priority, priority, priority_map); - - /* URL */ - cal_component_get_url (comp, &url); - e_dialog_editable_set (priv->url, url); - - priv->updating = FALSE; -} - -/* fill_component handler for the task page */ -static gboolean -task_details_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - struct icaltimetype icaltime; - icalproperty_status status; - TaskEditorPriority priority; - int priority_value, percent; - char *url; - gboolean date_set; - - tdpage = TASK_DETAILS_PAGE (page); - priv = tdpage->priv; - - /* Percent Complete. */ - percent = e_dialog_spin_get_int (priv->percent_complete); - cal_component_set_percent (comp, &percent); - - /* Status. */ - status = e_dialog_option_menu_get (priv->status, status_map); - cal_component_set_status (comp, status); - - /* Priority. */ - priority = e_dialog_option_menu_get (priv->priority, priority_map); - priority_value = priority_index_to_value (priority); - cal_component_set_priority (comp, &priority_value); - - icaltime = icaltime_null_time (); - - /* COMPLETED must be in UTC. */ - icaltime.is_utc = 1; - - /* Completed Date. */ - if (!e_date_edit_date_is_valid (E_DATE_EDIT (priv->completed_date)) || - !e_date_edit_time_is_valid (E_DATE_EDIT (priv->completed_date))) { - comp_editor_page_display_validation_error (page, _("Completed date is wrong"), priv->completed_date); - return FALSE; - } - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->completed_date), - &icaltime.year, - &icaltime.month, - &icaltime.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->completed_date), - &icaltime.hour, - &icaltime.minute); - if (date_set) { - /* COMPLETED must be in UTC, so we assume that the date in the - dialog is in the current timezone, and we now convert it - to UTC. FIXME: We should really use one timezone for the - entire time the dialog is shown. Otherwise if the user - changes the timezone, the COMPLETED date may get changed - as well. */ - char *location = calendar_config_get_timezone (); - icaltimezone *zone = icaltimezone_get_builtin_timezone (location); - icaltimezone_convert_time (&icaltime, zone, - icaltimezone_get_utc_timezone ()); - cal_component_set_completed (comp, &icaltime); - } else { - cal_component_set_completed (comp, NULL); - } - - /* URL. */ - url = e_dialog_editable_get (priv->url); - cal_component_set_url (comp, url); - if (url) - g_free (url); - - return TRUE; -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (TaskDetailsPage *tdpage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (tdpage); - TaskDetailsPagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = tdpage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("task-details-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - priv->status = GW ("status"); - priv->priority = GW ("priority"); - priv->percent_complete = GW ("percent-complete"); - - priv->completed_date = GW ("completed-date"); - gtk_widget_show (priv->completed_date); - - priv->url_entry = GW ("url_entry"); - gtk_widget_show (priv->url_entry); - priv->url = e_url_entry_get_entry (E_URL_ENTRY (priv->url_entry)); - -#undef GW - - return (priv->status - && priv->priority - && priv->percent_complete - && priv->completed_date - && priv->url); -} - - -static void -complete_date_changed (TaskDetailsPage *tdpage, time_t ctime, gboolean complete) -{ - TaskDetailsPagePrivate *priv; - CompEditorPageDates dates = {NULL, NULL, NULL, NULL}; - icaltimezone *zone; - struct icaltimetype completed_tt = icaltime_null_time(); - - priv = tdpage->priv; - - /* Get the current time in UTC. */ - zone = icaltimezone_get_utc_timezone (); - completed_tt = icaltime_from_timet_with_zone (ctime, FALSE, zone); - completed_tt.is_utc = TRUE; - - dates.start = NULL; - dates.end = NULL; - dates.due = NULL; - if (complete) - dates.complete = &completed_tt; - - /* Notify upstream */ - comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (tdpage), - &dates); -} - -static void -date_changed_cb (EDateEdit *dedit, gpointer data) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - CompEditorPageDates dates = {NULL, NULL, NULL, NULL}; - struct icaltimetype completed_tt = icaltime_null_time (); - icalproperty_status status; - gboolean date_set; - - tdpage = TASK_DETAILS_PAGE (data); - priv = tdpage->priv; - - if (priv->updating) - return; - - priv->updating = TRUE; - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->completed_date), - &completed_tt.year, - &completed_tt.month, - &completed_tt.day); - e_date_edit_get_time_of_day (E_DATE_EDIT (priv->completed_date), - &completed_tt.hour, - &completed_tt.minute); - - status = e_dialog_option_menu_get (priv->status, status_map); - - if (!date_set) { - completed_tt = icaltime_null_time (); - if (status == ICAL_STATUS_COMPLETED) { - e_dialog_option_menu_set (priv->status, - ICAL_STATUS_NONE, - status_map); - e_dialog_spin_set (priv->percent_complete, 0); - } - } else { - if (status != ICAL_STATUS_COMPLETED) { - e_dialog_option_menu_set (priv->status, - ICAL_STATUS_COMPLETED, - status_map); - } - e_dialog_spin_set (priv->percent_complete, 100); - } - - priv->updating = FALSE; - - /* Notify upstream */ - dates.complete = &completed_tt; - comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (tdpage), &dates); -} - -static void -status_changed (GtkMenu *menu, TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - icalproperty_status status; - time_t ctime = -1; - - priv = tdpage->priv; - - if (priv->updating) - return; - - priv->updating = TRUE; - - status = e_dialog_option_menu_get (priv->status, status_map); - if (status == ICAL_STATUS_NONE) { - e_dialog_spin_set (priv->percent_complete, 0); - e_date_edit_set_time (E_DATE_EDIT (priv->completed_date), ctime); - complete_date_changed (tdpage, 0, FALSE); - } else if (status == ICAL_STATUS_INPROCESS) { - e_dialog_spin_set (priv->percent_complete, 50); - e_date_edit_set_time (E_DATE_EDIT (priv->completed_date), ctime); - complete_date_changed (tdpage, 0, FALSE); - } else if (status == ICAL_STATUS_COMPLETED) { - e_dialog_spin_set (priv->percent_complete, 100); - ctime = time (NULL); - e_date_edit_set_time (E_DATE_EDIT (priv->completed_date), ctime); - complete_date_changed (tdpage, ctime, TRUE); - } - - priv->updating = FALSE; - - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tdpage)); -} - -static void -percent_complete_changed (GtkAdjustment *adj, TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - gint percent; - icalproperty_status status; - gboolean complete; - time_t ctime = -1; - - priv = tdpage->priv; - - if (priv->updating) - return; - - priv->updating = TRUE; - - percent = e_dialog_spin_get_int (priv->percent_complete); - if (percent == 100) { - complete = TRUE; - ctime = time (NULL); - status = ICAL_STATUS_COMPLETED; - } else { - complete = FALSE; - - if (percent == 0) - status = ICAL_STATUS_NONE; - else - status = ICAL_STATUS_INPROCESS; - } - - e_dialog_option_menu_set (priv->status, status, status_map); - e_date_edit_set_time (E_DATE_EDIT (priv->completed_date), ctime); - complete_date_changed (tdpage, ctime, complete); - - priv->updating = FALSE; - - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tdpage)); -} - -/* This is called when any field is changed; it notifies upstream. */ -static void -field_changed_cb (GtkWidget *widget, gpointer data) -{ - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; - - tdpage = TASK_DETAILS_PAGE (data); - priv = tdpage->priv; - - if (!priv->updating) - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tdpage)); -} - -/* Hooks the widget signals */ -static void -init_widgets (TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - - priv = tdpage->priv; - - /* Make sure the EDateEdit widgets use our timezones to get the - current time. */ - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->completed_date), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - tdpage, NULL); - - /* Connect signals. The Status, Percent Complete & Date Completed - properties are closely related so whenever one changes we may need - to update the other 2. */ - g_signal_connect((GTK_OPTION_MENU (priv->status)->menu), - "deactivate", - G_CALLBACK (status_changed), tdpage); - - g_signal_connect((GTK_SPIN_BUTTON (priv->percent_complete)->adjustment), - "value_changed", - G_CALLBACK (percent_complete_changed), tdpage); - - /* Priority */ - g_signal_connect((GTK_OPTION_MENU (priv->priority)->menu), - "deactivate", - G_CALLBACK (field_changed_cb), tdpage); - - /* Completed Date */ - g_signal_connect((priv->completed_date), "changed", - G_CALLBACK (date_changed_cb), tdpage); - - /* URL */ - g_signal_connect((priv->url), "changed", - G_CALLBACK (field_changed_cb), tdpage); -} - - - -/** - * task_details_page_construct: - * @tdpage: An task details page. - * - * Constructs an task page by loading its Glade data. - * - * Return value: The same object as @tdpage, or NULL if the widgets could not - * be created. - **/ -TaskDetailsPage * -task_details_page_construct (TaskDetailsPage *tdpage) -{ - TaskDetailsPagePrivate *priv; - - priv = tdpage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR - "/task-details-page.glade", NULL, NULL); - if (!priv->xml) { - g_message ("task_details_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (tdpage)) { - g_message ("task_details_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - init_widgets (tdpage); - - return tdpage; -} - -/** - * task_details_page_new: - * - * Creates a new task details page. - * - * Return value: A newly-created task details page, or NULL if the page could - * not be created. - **/ -TaskDetailsPage * -task_details_page_new (void) -{ - TaskDetailsPage *tdpage; - - tdpage = g_object_new (TYPE_TASK_DETAILS_PAGE, NULL); - if (!task_details_page_construct (tdpage)) { - g_object_unref ((tdpage)); - return NULL; - } - - return tdpage; -} - -GtkWidget *task_details_page_create_date_edit (void); - -GtkWidget * -task_details_page_create_date_edit (void) -{ - GtkWidget *dedit; - - dedit = comp_editor_new_date_edit (TRUE, TRUE, FALSE); - e_date_edit_set_allow_no_date_set (E_DATE_EDIT (dedit), TRUE); - - return dedit; -} - diff --git a/calendar/gui/dialogs/task-details-page.glade b/calendar/gui/dialogs/task-details-page.glade deleted file mode 100644 index d1091c320e..0000000000 --- a/calendar/gui/dialogs/task-details-page.glade +++ /dev/null @@ -1,383 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="task-details-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="task-details-page"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkFrame" id="frame2"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkVBox" id="vbox1"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkHBox" id="hbox1"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label17"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Status:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">status</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="status"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">Not Started</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">In Progress</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget5"> - <property name="visible">True</property> - <property name="label" translatable="yes">Completed</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget6"> - <property name="visible">True</property> - <property name="label" translatable="yes">Cancelled</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label18"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Priority:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">priority</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="priority"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget7"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget8"> - <property name="visible">True</property> - <property name="label" translatable="yes">High</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget9"> - <property name="visible">True</property> - <property name="label" translatable="yes">Normal</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget10"> - <property name="visible">True</property> - <property name="label" translatable="yes">Low</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget11"> - <property name="visible">True</property> - <property name="label" translatable="yes">Undefined</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label19"> - <property name="visible">True</property> - <property name="label" translatable="yes">% Complete</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="percent-complete"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">False</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1 0 100 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkTable" id="table1"> - <property name="border_width">4</property> - <property name="visible">True</property> - <property name="n_rows">1</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">2</property> - <property name="column_spacing">4</property> - - <child> - <widget class="GtkLabel" id="label12"> - <property name="visible">True</property> - <property name="label" translatable="yes">Date Completed:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="completed-date"> - <property name="visible">True</property> - <property name="creation_function">task_details_page_create_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Fri, 01 Jun 2001 18:58:51 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Progress</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkTable" id="table2"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="n_rows">1</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label14"> - <property name="visible">True</property> - <property name="label" translatable="yes">URL:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="url_entry"> - <property name="visible">True</property> - <property name="creation_function">e_url_entry_new</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Fri, 08 Feb 2002 21:02:37 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/task-details-page.h b/calendar/gui/dialogs/task-details-page.h deleted file mode 100644 index 98b6832bbf..0000000000 --- a/calendar/gui/dialogs/task-details-page.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Evolution calendar - Main page of the task editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 TASK_DETAILS_PAGE_H -#define TASK_DETAILS_PAGE_H - -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_TASK_DETAILS_PAGE (task_details_page_get_type ()) -#define TASK_DETAILS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TASK_DETAILS_PAGE, TaskDetailsPage)) -#define TASK_DETAILS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TASK_DETAILS_PAGE, TaskDetailsPageClass)) -#define IS_TASK_DETAILS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TASK_DETAILS_PAGE)) -#define IS_TASK_DETAILS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_TASK_DETAILS_PAGE)) - -typedef struct _TaskDetailsPagePrivate TaskDetailsPagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - TaskDetailsPagePrivate *priv; -} TaskDetailsPage; - -typedef struct { - CompEditorPageClass parent_class; -} TaskDetailsPageClass; - - -GtkType task_details_page_get_type (void); -TaskDetailsPage *task_details_page_construct (TaskDetailsPage *tdpage); -TaskDetailsPage *task_details_page_new (void); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/dialogs/task-editor.c b/calendar/gui/dialogs/task-editor.c deleted file mode 100644 index f5add85a29..0000000000 --- a/calendar/gui/dialogs/task-editor.c +++ /dev/null @@ -1,472 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution calendar - Task editor dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <libgnome/gnome-i18n.h> - -#include "task-page.h" -#include "task-details-page.h" -#include "meeting-page.h" -#include "cancel-comp.h" -#include "task-editor.h" - -struct _TaskEditorPrivate { - TaskPage *task_page; - TaskDetailsPage *task_details_page; - MeetingPage *meet_page; - - EMeetingModel *model; - - gboolean assignment_shown; - gboolean updating; -}; - - - -static void task_editor_class_init (TaskEditorClass *class); -static void task_editor_init (TaskEditor *te); -static void task_editor_edit_comp (CompEditor *editor, CalComponent *comp); -static gboolean task_editor_send_comp (CompEditor *editor, CalComponentItipMethod method); -static void task_editor_finalize (GObject *object); - -static void assign_task_cmd (GtkWidget *widget, gpointer data); -static void refresh_task_cmd (GtkWidget *widget, gpointer data); -static void cancel_task_cmd (GtkWidget *widget, gpointer data); -static void forward_cmd (GtkWidget *widget, gpointer data); - -static void model_row_changed_cb (ETableModel *etm, int row, gpointer data); -static void row_count_changed_cb (ETableModel *etm, int row, int count, gpointer data); - -static BonoboUIVerb verbs [] = { - BONOBO_UI_UNSAFE_VERB ("ActionAssignTask", assign_task_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionRefreshTask", refresh_task_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionCancelTask", cancel_task_cmd), - BONOBO_UI_UNSAFE_VERB ("ActionForward", forward_cmd), - - BONOBO_UI_VERB_END -}; - -static CompEditorClass *parent_class; - - - -/** - * task_editor_get_type: - * - * Registers the #TaskEditor class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #TaskEditor class. - **/ - -E_MAKE_TYPE (task_editor, "TaskEditor", TaskEditor, task_editor_class_init, task_editor_init, - TYPE_COMP_EDITOR); - -/* Class initialization function for the event editor */ -static void -task_editor_class_init (TaskEditorClass *klass) -{ - GObjectClass *object_class; - CompEditorClass *editor_class; - - object_class = (GObjectClass *) klass; - editor_class = (CompEditorClass *) klass; - - parent_class = g_type_class_ref(TYPE_COMP_EDITOR); - - editor_class->edit_comp = task_editor_edit_comp; - editor_class->send_comp = task_editor_send_comp; - - object_class->finalize = task_editor_finalize; -} - -static void -set_menu_sens (TaskEditor *te) -{ - TaskEditorPrivate *priv; - gboolean sens, existing, user, read_only; - - priv = te->priv; - - existing = comp_editor_get_existing_org (COMP_EDITOR (te)); - user = comp_editor_get_user_org (COMP_EDITOR (te)); - read_only = cal_client_is_read_only (comp_editor_get_cal_client (COMP_EDITOR (te))); - - sens = cal_client_get_static_capability (comp_editor_get_cal_client (COMP_EDITOR (te)), - CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT) - || priv->assignment_shown || read_only; - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/ActionAssignTask", - "sensitive", sens ? "0" : "1"); - - sens = priv->assignment_shown && existing && !user && !read_only; - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/ActionRefreshTask", - "sensitive", sens ? "1" : "0"); - - sens = priv->assignment_shown && existing && user && !read_only; - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/ActionCancelTask", - "sensitive", sens ? "1" : "0"); - - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/FileSave", - "sensitive", read_only ? "0" : "1"); - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/FileSaveAndClose", - "sensitive", read_only ? "0" : "1"); - comp_editor_set_ui_prop (COMP_EDITOR (te), - "/commands/FileDelete", - "sensitive", read_only ? "0" : "1"); -} - -static void -init_widgets (TaskEditor *te) -{ - TaskEditorPrivate *priv; - - priv = te->priv; - - g_signal_connect((priv->model), "model_row_changed", - G_CALLBACK (model_row_changed_cb), te); - g_signal_connect((priv->model), "model_rows_inserted", - G_CALLBACK (row_count_changed_cb), te); - g_signal_connect((priv->model), "model_rows_deleted", - G_CALLBACK (row_count_changed_cb), te); -} - -/* Object initialization function for the task editor */ -static void -task_editor_init (TaskEditor *te) -{ - TaskEditorPrivate *priv; - - priv = g_new0 (TaskEditorPrivate, 1); - te->priv = priv; - - priv->model = E_MEETING_MODEL (e_meeting_model_new ()); - priv->assignment_shown = TRUE; - priv->updating = FALSE; - -} - -TaskEditor * -task_editor_construct (TaskEditor *te, CalClient *client) -{ - TaskEditorPrivate *priv; - - priv = te->priv; - - priv->task_page = task_page_new (); - g_object_ref (priv->task_page); - gtk_object_sink (GTK_OBJECT (priv->task_page)); - comp_editor_append_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->task_page), - _("Basic")); - - priv->task_details_page = task_details_page_new (); - g_object_ref (priv->task_details_page); - gtk_object_sink (GTK_OBJECT (priv->task_details_page)); - comp_editor_append_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->task_details_page), - _("Details")); - - priv->meet_page = meeting_page_new (priv->model, client); - g_object_ref (priv->meet_page); - gtk_object_sink (GTK_OBJECT (priv->meet_page)); - comp_editor_append_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->meet_page), - _("Assignment")); - - comp_editor_set_cal_client (COMP_EDITOR (te), client); - - comp_editor_merge_ui (COMP_EDITOR (te), "evolution-task-editor.xml", verbs, NULL); - - init_widgets (te); - set_menu_sens (te); - - return te; -} - -static void -task_editor_edit_comp (CompEditor *editor, CalComponent *comp) -{ - TaskEditor *te; - TaskEditorPrivate *priv; - CalComponentOrganizer organizer; - CalClient *client; - GSList *attendees = NULL; - - te = TASK_EDITOR (editor); - priv = te->priv; - - priv->updating = TRUE; - - if (parent_class->edit_comp) - parent_class->edit_comp (editor, comp); - - client = comp_editor_get_cal_client (COMP_EDITOR (editor)); - - /* Get meeting related stuff */ - cal_component_get_organizer (comp, &organizer); - cal_component_get_attendee_list (comp, &attendees); - - /* Clear things up */ - e_meeting_model_remove_all_attendees (priv->model); - - if (attendees == NULL) { - comp_editor_remove_page (editor, COMP_EDITOR_PAGE (priv->meet_page)); - priv->assignment_shown = FALSE; - } else { - GSList *l; - int row; - - if (!priv->assignment_shown) - comp_editor_append_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->meet_page), - _("Assignment")); - - for (l = attendees; l != NULL; l = l->next) { - CalComponentAttendee *ca = l->data; - EMeetingAttendee *ia; - - ia = E_MEETING_ATTENDEE (e_meeting_attendee_new_from_cal_component_attendee (ca)); - /* If we aren't the organizer or the attendee is just delegating, don't allow editing */ - if (!comp_editor_get_user_org (editor) || e_meeting_attendee_is_set_delto (ia)) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_NONE); - e_meeting_model_add_attendee (priv->model, ia); - - g_object_unref(ia); - } - - /* If we aren't the organizer we can still change our own status */ - if (!comp_editor_get_user_org (editor)) { - EAccountList *accounts; - EAccount *account; - EIterator *it; - - accounts = itip_addresses_get (); - for (it = e_list_get_iterator((EList *)accounts);e_iterator_is_valid(it);e_iterator_next(it)) { - EMeetingAttendee *ia; - - account = (EAccount*)e_iterator_get(it); - - ia = e_meeting_model_find_attendee (priv->model, account->id->address, &row); - if (ia != NULL) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS); - } - g_object_unref(it); - } else if (cal_client_get_organizer_must_attend (client)) { - EMeetingAttendee *ia; - - ia = e_meeting_model_find_attendee (priv->model, organizer.value, &row); - if (ia != NULL) - e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_NONE); - } - - priv->assignment_shown = TRUE; - } - cal_component_free_attendee_list (attendees); - - set_menu_sens (te); - comp_editor_set_needs_send (COMP_EDITOR (te), priv->assignment_shown && itip_organizer_is_user (comp, client)); - - priv->updating = FALSE; -} - -static gboolean -task_editor_send_comp (CompEditor *editor, CalComponentItipMethod method) -{ - TaskEditor *te = TASK_EDITOR (editor); - TaskEditorPrivate *priv; - CalComponent *comp = NULL; - - priv = te->priv; - - /* Don't cancel more than once or when just publishing */ - if (method == CAL_COMPONENT_METHOD_PUBLISH || - method == CAL_COMPONENT_METHOD_CANCEL) - goto parent; - - comp = meeting_page_get_cancel_comp (priv->meet_page); - if (comp != NULL) { - CalClient *client; - gboolean result; - - client = e_meeting_model_get_cal_client (priv->model); - result = itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, comp, client, NULL); - g_object_unref((comp)); - - if (!result) - return FALSE; - } - - parent: - if (parent_class->send_comp) - return parent_class->send_comp (editor, method); - - return FALSE; -} - -/* Destroy handler for the event editor */ -static void -task_editor_finalize (GObject *object) -{ - TaskEditor *te; - TaskEditorPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_TASK_EDITOR (object)); - - te = TASK_EDITOR (object); - priv = te->priv; - - g_object_unref((priv->task_page)); - g_object_unref((priv->task_details_page)); - g_object_unref((priv->meet_page)); - - g_object_unref (priv->model); - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -/** - * task_editor_new: - * @client: a CalClient - * - * Creates a new event editor dialog. - * - * Return value: A newly-created event editor dialog, or NULL if the event - * editor could not be created. - **/ -TaskEditor * -task_editor_new (CalClient *client) -{ - TaskEditor *te; - - te = g_object_new (TYPE_TASK_EDITOR, NULL); - return task_editor_construct (te, client); -} - -static void -show_assignment (TaskEditor *te) -{ - TaskEditorPrivate *priv; - - priv = te->priv; - - if (!priv->assignment_shown) { - comp_editor_append_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->meet_page), - _("Assignment")); - priv->assignment_shown = TRUE; - - set_menu_sens (te); - comp_editor_set_needs_send (COMP_EDITOR (te), priv->assignment_shown); - comp_editor_set_changed (COMP_EDITOR (te), TRUE); - } - - comp_editor_show_page (COMP_EDITOR (te), - COMP_EDITOR_PAGE (priv->meet_page)); -} - -void -task_editor_show_assignment (TaskEditor *te) -{ - g_return_if_fail (te != NULL); - g_return_if_fail (IS_TASK_EDITOR (te)); - - show_assignment (te); -} - -static void -assign_task_cmd (GtkWidget *widget, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - - show_assignment (te); -} - -static void -refresh_task_cmd (GtkWidget *widget, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - - comp_editor_send_comp (COMP_EDITOR (te), CAL_COMPONENT_METHOD_REFRESH); -} - -static void -cancel_task_cmd (GtkWidget *widget, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - CalComponent *comp; - - comp = comp_editor_get_current_comp (COMP_EDITOR (te)); - if (cancel_component_dialog (comp_editor_get_cal_client (COMP_EDITOR (te)), comp, FALSE)) { - comp_editor_send_comp (COMP_EDITOR (te), CAL_COMPONENT_METHOD_CANCEL); - comp_editor_delete_comp (COMP_EDITOR (te)); - } -} - -static void -forward_cmd (GtkWidget *widget, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - - if (comp_editor_save_comp (COMP_EDITOR (te), TRUE)) - comp_editor_send_comp (COMP_EDITOR (te), CAL_COMPONENT_METHOD_PUBLISH); -} - -static void -model_row_changed_cb (ETableModel *etm, int row, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - TaskEditorPrivate *priv; - - priv = te->priv; - - if (!priv->updating) { - comp_editor_set_changed (COMP_EDITOR (te), TRUE); - comp_editor_set_needs_send (COMP_EDITOR (te), TRUE); - } -} - -static void -row_count_changed_cb (ETableModel *etm, int row, int count, gpointer data) -{ - TaskEditor *te = TASK_EDITOR (data); - TaskEditorPrivate *priv; - - priv = te->priv; - - if (!priv->updating) { - comp_editor_set_changed (COMP_EDITOR (te), TRUE); - comp_editor_set_needs_send (COMP_EDITOR (te), TRUE); - } -} diff --git a/calendar/gui/dialogs/task-editor.h b/calendar/gui/dialogs/task-editor.h deleted file mode 100644 index aec98b073e..0000000000 --- a/calendar/gui/dialogs/task-editor.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Evolution calendar - Task editor dialog - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 __TASK_EDITOR_H__ -#define __TASK_EDITOR_H__ - -#include <gtk/gtkobject.h> -#include "comp-editor.h" - - - -#define TYPE_TASK_EDITOR (task_editor_get_type ()) -#define TASK_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TASK_EDITOR, TaskEditor)) -#define TASK_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TASK_EDITOR, \ - TaskEditorClass)) -#define IS_TASK_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TASK_EDITOR)) -#define IS_TASK_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TASK_EDITOR)) - -typedef struct _TaskEditor TaskEditor; -typedef struct _TaskEditorClass TaskEditorClass; -typedef struct _TaskEditorPrivate TaskEditorPrivate; - -struct _TaskEditor { - CompEditor parent; - - /* Private data */ - TaskEditorPrivate *priv; -}; - -struct _TaskEditorClass { - CompEditorClass parent_class; -}; - -GtkType task_editor_get_type (void); -TaskEditor *task_editor_construct (TaskEditor *te, - CalClient *client); -TaskEditor *task_editor_new (CalClient *client); -void task_editor_show_assignment(TaskEditor *te); - - -#endif /* __TASK_EDITOR_H__ */ diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c deleted file mode 100644 index c83473ef07..0000000000 --- a/calendar/gui/dialogs/task-page.c +++ /dev/null @@ -1,913 +0,0 @@ -/* Evolution calendar - Main page of the task editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktextview.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtkoptionmenu.h> -#include <libgnome/gnome-i18n.h> -#include <glade/glade.h> -#include <gal/widgets/e-unicode.h> -#include <gal/widgets/e-categories.h> -#include <widgets/misc/e-dateedit.h> -#include "e-util/e-dialog-widgets.h" -#include "e-util/e-categories-config.h" -#include "../e-timezone-entry.h" -#include "../calendar-config.h" -#include "comp-editor-util.h" -#include "task-page.h" - - - -/* Private part of the TaskPage structure */ -struct _TaskPagePrivate { - /* Glade XML data */ - GladeXML *xml; - - /* Widgets from the Glade file */ - GtkWidget *main; - - GtkWidget *summary; - - GtkWidget *due_date; - GtkWidget *start_date; - GtkWidget *due_timezone; - GtkWidget *start_timezone; - - GtkWidget *description; - - GtkWidget *classification_public; - GtkWidget *classification_private; - GtkWidget *classification_confidential; - - GtkWidget *categories_btn; - GtkWidget *categories; - - gboolean updating; -}; - -static const int classification_map[] = { - CAL_COMPONENT_CLASS_PUBLIC, - CAL_COMPONENT_CLASS_PRIVATE, - CAL_COMPONENT_CLASS_CONFIDENTIAL, - -1 -}; - - - -static void task_page_class_init (TaskPageClass *class); -static void task_page_init (TaskPage *tpage); -static void task_page_finalize (GObject *object); - -static GtkWidget *task_page_get_widget (CompEditorPage *page); -static void task_page_focus_main_widget (CompEditorPage *page); -static void task_page_fill_widgets (CompEditorPage *page, CalComponent *comp); -static gboolean task_page_fill_component (CompEditorPage *page, CalComponent *comp); -static void task_page_set_summary (CompEditorPage *page, const char *summary); -static void task_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates); - -static CompEditorPageClass *parent_class = NULL; - - - -/** - * task_page_get_type: - * - * Registers the #TaskPage class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #TaskPage class. - **/ - -E_MAKE_TYPE (task_page, "TaskPage", TaskPage, task_page_class_init, task_page_init, - TYPE_COMP_EDITOR_PAGE); - -/* Class initialization function for the task page */ -static void -task_page_class_init (TaskPageClass *class) -{ - CompEditorPageClass *editor_page_class; - GObjectClass *object_class; - - editor_page_class = (CompEditorPageClass *) class; - object_class = (GObjectClass *) class; - - parent_class = g_type_class_ref(TYPE_COMP_EDITOR_PAGE); - - editor_page_class->get_widget = task_page_get_widget; - editor_page_class->focus_main_widget = task_page_focus_main_widget; - editor_page_class->fill_widgets = task_page_fill_widgets; - editor_page_class->fill_component = task_page_fill_component; - editor_page_class->set_summary = task_page_set_summary; - editor_page_class->set_dates = task_page_set_dates; - - object_class->finalize = task_page_finalize; -} - -/* Object initialization function for the task page */ -static void -task_page_init (TaskPage *tpage) -{ - TaskPagePrivate *priv; - - priv = g_new0 (TaskPagePrivate, 1); - tpage->priv = priv; - - priv->xml = NULL; - - priv->main = NULL; - priv->summary = NULL; - priv->due_date = NULL; - priv->start_date = NULL; - priv->due_timezone = NULL; - priv->start_timezone = NULL; - priv->description = NULL; - priv->classification_public = NULL; - priv->classification_private = NULL; - priv->classification_confidential = NULL; - priv->categories_btn = NULL; - priv->categories = NULL; - - priv->updating = FALSE; -} - -/* Destroy handler for the task page */ -static void -task_page_finalize (GObject *object) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_TASK_PAGE (object)); - - tpage = TASK_PAGE (object); - priv = tpage->priv; - - if (priv->main) - gtk_widget_unref (priv->main); - - if (priv->xml) { - g_object_unref((priv->xml)); - priv->xml = NULL; - } - - g_free (priv); - tpage->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* get_widget handler for the task page */ -static GtkWidget * -task_page_get_widget (CompEditorPage *page) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - - tpage = TASK_PAGE (page); - priv = tpage->priv; - - return priv->main; -} - -/* focus_main_widget handler for the task page */ -static void -task_page_focus_main_widget (CompEditorPage *page) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - - tpage = TASK_PAGE (page); - priv = tpage->priv; - - gtk_widget_grab_focus (priv->summary); -} - -/* Fills the widgets with default values */ -static void -clear_widgets (TaskPage *tpage) -{ - TaskPagePrivate *priv; - - priv = tpage->priv; - - /* Summary, description */ - e_dialog_editable_set (priv->summary, NULL); - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)), "", 0); - - /* Start, due times */ - e_date_edit_set_time (E_DATE_EDIT (priv->start_date), 0); - e_date_edit_set_time (E_DATE_EDIT (priv->due_date), 0); - - /* Classification */ - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PRIVATE, classification_map); - - /* Categories */ - e_dialog_editable_set (priv->categories, NULL); -} - -/* Decode the radio button group for classifications */ -static CalComponentClassification -classification_get (GtkWidget *widget) -{ - return e_dialog_radio_get (widget, classification_map); -} - -/* fill_widgets handler for the task page */ -static void -task_page_fill_widgets (CompEditorPage *page, CalComponent *comp) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - CalComponentText text; - CalComponentDateTime d; - CalComponentClassification cl; - CalClientGetStatus get_tz_status; - GSList *l; - const char *categories; - icaltimezone *zone, *default_zone; - char *location; - - tpage = TASK_PAGE (page); - priv = tpage->priv; - - priv->updating = TRUE; - - /* Clean the screen */ - clear_widgets (tpage); - - /* Summary, description(s) */ - cal_component_get_summary (comp, &text); - e_dialog_editable_set (priv->summary, text.value); - - cal_component_get_description_list (comp, &l); - if (l) { - text = *(CalComponentText *)l->data; - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)), - text.value, -1); - } else { - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)), - "", 0); - } - cal_component_free_text_list (l); - - location = calendar_config_get_timezone (); - default_zone = icaltimezone_get_builtin_timezone (location); - - /* Due Date. */ - cal_component_get_due (comp, &d); - zone = NULL; - if (d.value) { - struct icaltimetype *due_tt = d.value; - e_date_edit_set_date (E_DATE_EDIT (priv->due_date), - due_tt->year, due_tt->month, - due_tt->day); - if (due_tt->is_date) { - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->due_date), - -1, -1); - zone = default_zone; - } else { - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->due_date), - due_tt->hour, - due_tt->minute); - } - } else { - e_date_edit_set_time (E_DATE_EDIT (priv->due_date), -1); - - /* If no time is set, we use the default timezone, so the - user usually doesn't have to set this when they set the - date. */ - zone = default_zone; - } - - /* Note that if we are creating a new task, the timezones may not be - on the server, so we try to get the builtin timezone with the TZID - first. */ - if (!zone) - zone = icaltimezone_get_builtin_timezone_from_tzid (d.tzid); - if (!zone) { - get_tz_status = cal_client_get_timezone (page->client, d.tzid, - &zone); - /* FIXME: Handle error better. */ - if (get_tz_status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - d.tzid ? d.tzid : ""); - } - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->due_timezone), - zone); - - cal_component_free_datetime (&d); - - - /* Start Date. */ - cal_component_get_dtstart (comp, &d); - zone = NULL; - if (d.value) { - struct icaltimetype *start_tt = d.value; - e_date_edit_set_date (E_DATE_EDIT (priv->start_date), - start_tt->year, start_tt->month, - start_tt->day); - if (start_tt->is_date) { - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_date), - -1, -1); - zone = default_zone; - } else { - e_date_edit_set_time_of_day (E_DATE_EDIT (priv->start_date), - start_tt->hour, - start_tt->minute); - } - } else { - e_date_edit_set_time (E_DATE_EDIT (priv->start_date), -1); - - /* If no time is set, we use the default timezone, so the - user usually doesn't have to set this when they set the - date. */ - zone = default_zone; - } - - if (!zone) - zone = icaltimezone_get_builtin_timezone_from_tzid (d.tzid); - if (!zone) { - get_tz_status = cal_client_get_timezone (page->client, d.tzid, - &zone); - /* FIXME: Handle error better. */ - if (get_tz_status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - d.tzid ? d.tzid : ""); - } - e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), - zone); - - cal_component_free_datetime (&d); - - /* Classification. */ - cal_component_get_classification (comp, &cl); - - switch (cl) { - case CAL_COMPONENT_CLASS_PUBLIC: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PUBLIC, - classification_map); - break; - - case CAL_COMPONENT_CLASS_PRIVATE: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PRIVATE, - classification_map); - break; - - case CAL_COMPONENT_CLASS_CONFIDENTIAL: - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_CONFIDENTIAL, - classification_map); - break; - - default: - /* default to PUBLIC */ - e_dialog_radio_set (priv->classification_public, - CAL_COMPONENT_CLASS_PUBLIC, - classification_map); - break; - } - - /* Categories */ - cal_component_get_categories (comp, &categories); - e_dialog_editable_set (priv->categories, categories); - - - priv->updating = FALSE; -} - -/* fill_component handler for the task page */ -static gboolean -task_page_fill_component (CompEditorPage *page, CalComponent *comp) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - CalComponentDateTime date; - struct icaltimetype icaltime; - char *cat, *str; - gboolean date_set, time_set; - icaltimezone *zone; - GtkTextBuffer *text_buffer; - GtkTextIter text_iter_start, text_iter_end; - - tpage = TASK_PAGE (page); - priv = tpage->priv; - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->description)); - - /* Summary. */ - - str = e_dialog_editable_get (priv->summary); - if (!str || strlen (str) == 0) - cal_component_set_summary (comp, NULL); - else { - CalComponentText text; - - text.value = str; - text.altrep = NULL; - - cal_component_set_summary (comp, &text); - } - - if (str) - g_free (str); - - /* Description */ - - gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start); - gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end); - str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE); - - if (!str || strlen (str) == 0) - cal_component_set_description_list (comp, NULL); - else { - GSList l; - CalComponentText text; - - text.value = str; - text.altrep = NULL; - l.data = &text; - l.next = NULL; - - cal_component_set_description_list (comp, &l); - } - - if (!str) - g_free (str); - - /* Dates */ - - icaltime = icaltime_null_time (); - - date.value = &icaltime; - date.tzid = NULL; - - /* Due Date. */ - if (!e_date_edit_date_is_valid (E_DATE_EDIT (priv->due_date)) || - !e_date_edit_time_is_valid (E_DATE_EDIT (priv->due_date))) { - comp_editor_page_display_validation_error (page, _("Due date is wrong"), priv->due_date); - return FALSE; - } - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->due_date), - &icaltime.year, - &icaltime.month, - &icaltime.day); - time_set = e_date_edit_get_time_of_day (E_DATE_EDIT (priv->due_date), - &icaltime.hour, - &icaltime.minute); - if (date_set) { - if (time_set) { - zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->due_timezone)); - date.tzid = icaltimezone_get_tzid (zone); - } else { - icaltime.is_date = TRUE; - date.tzid = NULL; - } - cal_component_set_due (comp, &date); - } else { - cal_component_set_due (comp, NULL); - } - - /* Start Date. */ - if (!e_date_edit_date_is_valid (E_DATE_EDIT (priv->start_date)) || - !e_date_edit_time_is_valid (E_DATE_EDIT (priv->start_date))) { - comp_editor_page_display_validation_error (page, _("Start date is wrong"), priv->start_date); - return FALSE; - } - - icaltime = icaltime_null_time (); - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_date), - &icaltime.year, - &icaltime.month, - &icaltime.day); - time_set = e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_date), - &icaltime.hour, - &icaltime.minute); - if (date_set) { - if (time_set) { - zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - date.tzid = icaltimezone_get_tzid (zone); - } else { - icaltime.is_date = TRUE; - date.tzid = NULL; - } - cal_component_set_dtstart (comp, &date); - } else { - cal_component_set_dtstart (comp, NULL); - } - - /* Classification. */ - cal_component_set_classification (comp, classification_get (priv->classification_public)); - - /* Categories */ - cat = e_dialog_editable_get (priv->categories); - str = comp_editor_strip_categories (cat); - if (cat) - g_free (cat); - - cal_component_set_categories (comp, str); - - if (str) - g_free (str); - - return TRUE; -} - -/* set_summary handler for the task page */ -static void -task_page_set_summary (CompEditorPage *page, const char *summary) -{ - /* nothing */ -} - -static void -task_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - - tpage = TASK_PAGE (page); - priv = tpage->priv; - - if (priv->updating) - return; - - priv->updating = TRUE; - - priv->updating = FALSE; -} - - - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (TaskPage *tpage) -{ - CompEditorPage *page = COMP_EDITOR_PAGE (tpage); - TaskPagePrivate *priv; - GSList *accel_groups; - GtkWidget *toplevel; - - priv = tpage->priv; - -#define GW(name) glade_xml_get_widget (priv->xml, name) - - priv->main = GW ("task-page"); - if (!priv->main) - return FALSE; - - /* Get the GtkAccelGroup from the toplevel window, so we can install - it when the notebook page is mapped. */ - toplevel = gtk_widget_get_toplevel (priv->main); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (accel_groups) { - page->accel_group = accel_groups->data; - gtk_accel_group_ref (page->accel_group); - } - - gtk_widget_ref (priv->main); - gtk_container_remove (GTK_CONTAINER (priv->main->parent), priv->main); - - priv->summary = GW ("summary"); - - /* Glade's visibility flag doesn't seem to work for custom widgets */ - priv->due_date = GW ("due-date"); - gtk_widget_show (priv->due_date); - priv->start_date = GW ("start-date"); - gtk_widget_show (priv->start_date); - - priv->due_timezone = GW ("due-timezone"); - priv->start_timezone = GW ("start-timezone"); - - priv->description = GW ("description"); - - priv->classification_public = GW ("classification-public"); - priv->classification_private = GW ("classification-private"); - priv->classification_confidential = GW ("classification-confidential"); - - priv->categories_btn = GW ("categories-button"); - priv->categories = GW ("categories"); - -#undef GW - - return (priv->summary - && priv->due_date - && priv->start_date - && priv->due_timezone - && priv->start_timezone - && priv->classification_public - && priv->classification_private - && priv->classification_confidential - && priv->description - && priv->categories_btn - && priv->categories); -} - -/* Callback used when the summary changes; we emit the notification signal. */ -static void -summary_changed_cb (GtkEditable *editable, gpointer data) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - gchar *summary; - - tpage = TASK_PAGE (data); - priv = tpage->priv; - - if (priv->updating) - return; - - summary = e_dialog_editable_get (GTK_WIDGET (editable)); - comp_editor_page_notify_summary_changed (COMP_EDITOR_PAGE (tpage), - summary); - g_free (summary); -} - -/* Callback used when the start or due date widgets change. We notify the - * other pages in the task editor, so they can update any labels. - */ -static void -date_changed_cb (EDateEdit *dedit, gpointer data) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - CompEditorPageDates dates; - gboolean date_set, time_set; - CalComponentDateTime start_dt, due_dt; - struct icaltimetype start_tt = icaltime_null_time(); - struct icaltimetype due_tt = icaltime_null_time(); - - tpage = TASK_PAGE (data); - priv = tpage->priv; - - if (priv->updating) - return; - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->start_date), - &start_tt.year, - &start_tt.month, - &start_tt.day); - time_set = e_date_edit_get_time_of_day (E_DATE_EDIT (priv->start_date), - &start_tt.hour, - &start_tt.minute); - if (date_set) { - if (time_set) { - icaltimezone *zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); - start_dt.tzid = icaltimezone_get_tzid (zone); - } else { - start_tt.is_date = TRUE; - start_dt.tzid = NULL; - } - } else { - start_tt = icaltime_null_time (); - start_dt.tzid = NULL; - } - - date_set = e_date_edit_get_date (E_DATE_EDIT (priv->due_date), - &due_tt.year, - &due_tt.month, - &due_tt.day); - time_set = e_date_edit_get_time_of_day (E_DATE_EDIT (priv->due_date), - &due_tt.hour, - &due_tt.minute); - if (date_set) { - if (time_set) { - icaltimezone *zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->due_timezone)); - due_dt.tzid = icaltimezone_get_tzid (zone); - } else { - due_tt.is_date = TRUE; - due_dt.tzid = NULL; - } - } else { - due_tt = icaltime_null_time (); - due_dt.tzid = NULL; - } - - start_dt.value = &start_tt; - dates.start = &start_dt; - dates.end = NULL; - due_dt.value = &due_tt; - dates.due = &due_dt; - dates.complete = NULL; - - /* Notify upstream */ - comp_editor_page_notify_dates_changed (COMP_EDITOR_PAGE (tpage), - &dates); -} - -/* Callback used when the categories button is clicked; we must bring up the - * category list dialog. - */ -static void -categories_clicked_cb (GtkWidget *button, gpointer data) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - GtkWidget *entry; - - tpage = TASK_PAGE (data); - priv = tpage->priv; - - entry = priv->categories; - e_categories_config_open_dialog_for_entry (GTK_ENTRY (entry)); -} - -/* This is called when any field is changed; it notifies upstream. */ -static void -field_changed_cb (GtkWidget *widget, gpointer data) -{ - TaskPage *tpage; - TaskPagePrivate *priv; - - tpage = TASK_PAGE (data); - priv = tpage->priv; - - if (!priv->updating) - comp_editor_page_notify_changed (COMP_EDITOR_PAGE (tpage)); -} - -/* Hooks the widget signals */ -static gboolean -init_widgets (TaskPage *tpage) -{ - TaskPagePrivate *priv; - GtkTextBuffer *text_buffer; - char *location; - icaltimezone *zone; - - priv = tpage->priv; - - /* Make sure the EDateEdit widgets use our timezones to get the - current time. */ - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->start_date), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - tpage, NULL); - e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->due_date), - (EDateEditGetTimeCallback) comp_editor_get_current_time, - tpage, NULL); - - /* Summary */ - g_signal_connect((priv->summary), "changed", - G_CALLBACK (summary_changed_cb), tpage); - - /* Description */ - text_buffer = gtk_text_buffer_new (NULL); - gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->description), text_buffer); - g_object_unref (text_buffer); - - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->description), GTK_WRAP_WORD); - - /* Dates */ - g_signal_connect((priv->start_date), "changed", - G_CALLBACK (date_changed_cb), tpage); - g_signal_connect((priv->due_date), "changed", - G_CALLBACK (date_changed_cb), tpage); - - g_signal_connect((priv->due_timezone), "changed", - G_CALLBACK (field_changed_cb), tpage); - g_signal_connect((priv->start_timezone), "changed", - G_CALLBACK (field_changed_cb), tpage); - - /* Classification */ - g_signal_connect((priv->classification_public), - "toggled", - G_CALLBACK (field_changed_cb), tpage); - g_signal_connect((priv->classification_private), - "toggled", - G_CALLBACK (field_changed_cb), tpage); - g_signal_connect((priv->classification_confidential), - "toggled", - G_CALLBACK (field_changed_cb), tpage); - - /* Connect the default signal handler to use to make sure the "changed" - field gets set whenever a field is changed. */ - - /* Belongs to priv->description */ - g_signal_connect ((text_buffer), "changed", - G_CALLBACK (field_changed_cb), tpage); - - g_signal_connect((priv->categories), "changed", - G_CALLBACK (field_changed_cb), tpage); - - /* Categories button */ - g_signal_connect((priv->categories_btn), "clicked", - G_CALLBACK (categories_clicked_cb), tpage); - - - /* Set the default timezone, so the timezone entry may be hidden. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), zone); - e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->due_timezone), zone); - - return TRUE; -} - - - -/** - * task_page_construct: - * @tpage: An task page. - * - * Constructs an task page by loading its Glade data. - * - * Return value: The same object as @tpage, or NULL if the widgets could not be - * created. - **/ -TaskPage * -task_page_construct (TaskPage *tpage) -{ - TaskPagePrivate *priv; - - priv = tpage->priv; - - priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/task-page.glade", - NULL, NULL); - if (!priv->xml) { - g_message ("task_page_construct(): " - "Could not load the Glade XML file!"); - return NULL; - } - - if (!get_widgets (tpage)) { - g_message ("task_page_construct(): " - "Could not find all widgets in the XML file!"); - return NULL; - } - - if (!init_widgets (tpage)) { - g_message ("event_page_construct(): " - "Could not initialize the widgets!"); - return NULL; - } - - return tpage; -} - -/** - * task_page_new: - * - * Creates a new task page. - * - * Return value: A newly-created task page, or NULL if the page could - * not be created. - **/ -TaskPage * -task_page_new (void) -{ - TaskPage *tpage; - - tpage = gtk_type_new (TYPE_TASK_PAGE); - if (!task_page_construct (tpage)) { - g_object_unref((tpage)); - return NULL; - } - - return tpage; -} - -GtkWidget *task_page_create_date_edit (void); - -GtkWidget * -task_page_create_date_edit (void) -{ - GtkWidget *dedit; - - dedit = comp_editor_new_date_edit (TRUE, TRUE, TRUE); - e_date_edit_set_allow_no_date_set (E_DATE_EDIT (dedit), TRUE); - - return dedit; -} diff --git a/calendar/gui/dialogs/task-page.glade b/calendar/gui/dialogs/task-page.glade deleted file mode 100644 index 9ebda6eb82..0000000000 --- a/calendar/gui/dialogs/task-page.glade +++ /dev/null @@ -1,493 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="task-toplevel"> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - - <child> - <widget class="GtkVBox" id="task-page"> - <property name="border_width">12</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkTable" id="table3"> - <property name="visible">True</property> - <property name="n_rows">1</property> - <property name="n_columns">2</property> - <property name="homogeneous">False</property> - <property name="row_spacing">6</property> - <property name="column_spacing">6</property> - - <child> - <widget class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="label" translatable="yes">Su_mmary:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">summary</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options"></property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="summary"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame2"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox4"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkTable" id="table1"> - <property name="visible">True</property> - <property name="n_rows">2</property> - <property name="n_columns">3</property> - <property name="homogeneous">False</property> - <property name="row_spacing">2</property> - <property name="column_spacing">4</property> - - <child> - <widget class="GtkLabel" id="label6"> - <property name="visible">True</property> - <property name="label" translatable="yes">Sta_rt Date:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">start-date</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Due Date:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">due-date</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="due-date"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="creation_function">task_page_create_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Fri, 01 Jun 2001 18:59:52 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="start-date"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="creation_function">task_page_create_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Fri, 01 Jun 2001 18:59:57 GMT</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="Custom" id="due-timezone"> - <property name="visible">True</property> - <property name="creation_function">make_timezone_entry</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Tue, 19 Jun 2001 04:43:54 GMT</property> - </widget> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="Custom" id="start-timezone"> - <property name="visible">True</property> - <property name="creation_function">make_timezone_entry</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Tue, 19 Jun 2001 04:43:46 GMT</property> - </widget> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="label" translatable="yes">Date & Time</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkLabel" id="label18"> - <property name="visible">True</property> - <property name="label" translatable="yes">Description:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow1"> - <property name="visible">True</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTextView" id="description"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="justification">GTK_JUSTIFY_LEFT</property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="cursor_visible">True</property> - <property name="pixels_above_lines">0</property> - <property name="pixels_below_lines">0</property> - <property name="pixels_inside_wrap">0</property> - <property name="left_margin">0</property> - <property name="right_margin">0</property> - <property name="indent">0</property> - <property name="text" translatable="yes"></property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkFrame" id="frame24"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <property name="label_yalign">0.5</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - - <child> - <widget class="GtkHBox" id="hbox6"> - <property name="border_width">6</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkRadioButton" id="classification-public"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Pu_blic</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">True</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="classification-private"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Pri_vate</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">classification-public</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkRadioButton" id="classification-confidential"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Con_fidential</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - <property name="group">classification-public</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - </widget> - </child> - - <child> - <widget class="GtkLabel" id="label19"> - <property name="visible">True</property> - <property name="label" translatable="yes">Classification</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="type">label_item</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="hbox2"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">6</property> - - <child> - <widget class="GtkButton" id="categories-button"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Ca_tegories...</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - - <child> - <widget class="GtkLabel" id="label17"> - <property name="visible">True</property> - <property name="label" translatable="yes">Ca_tegories...</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">4</property> - <property name="ypad">0</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="categories"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char" translatable="yes">*</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/dialogs/task-page.h b/calendar/gui/dialogs/task-page.h deleted file mode 100644 index 16ced619d7..0000000000 --- a/calendar/gui/dialogs/task-page.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Evolution calendar - Main page of the task editor dialog - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Seth Alves <alves@hungry.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 TASK_PAGE_H -#define TASK_PAGE_H - -#include "comp-editor-page.h" - -G_BEGIN_DECLS - - - -#define TYPE_TASK_PAGE (task_page_get_type ()) -#define TASK_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TASK_PAGE, TaskPage)) -#define TASK_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TASK_PAGE, TaskPageClass)) -#define IS_TASK_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TASK_PAGE)) -#define IS_TASK_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_TASK_PAGE)) - -typedef struct _TaskPagePrivate TaskPagePrivate; - -typedef struct { - CompEditorPage page; - - /* Private data */ - TaskPagePrivate *priv; -} TaskPage; - -typedef struct { - CompEditorPageClass parent_class; -} TaskPageClass; - -GtkType task_page_get_type (void); -TaskPage *task_page_construct (TaskPage *epage); -TaskPage *task_page_new (void); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/e-alarm-list.c b/calendar/gui/e-alarm-list.c deleted file mode 100644 index 4f29829c32..0000000000 --- a/calendar/gui/e-alarm-list.c +++ /dev/null @@ -1,686 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* EAlarmList - list of calendar alarms with GtkTreeModel interface. - * - * Copyright (C) 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - */ - -#include <string.h> -#include <gtk/gtktreemodel.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktreednd.h> -#include <libgnome/gnome-i18n.h> -#include <glib.h> -#include <cal-util/timeutil.h> -#include <e-util/e-time-utils.h> -#include "calendar-config.h" -#include "e-alarm-list.h" - -#define G_LIST(x) ((GList *) x) -#define E_ALARM_LIST_IS_SORTED(list) (E_ALARM_LIST (list)->sort_column_id != -2) -#define IS_VALID_ITER(dt_list, iter) (iter!= NULL && iter->user_data != NULL && \ - dt_list->stamp == iter->stamp) - -static GType column_types [E_ALARM_LIST_NUM_COLUMNS]; - -static void e_alarm_list_init (EAlarmList *file_list); -static void e_alarm_list_class_init (EAlarmListClass *class); -static void e_alarm_list_tree_model_init (GtkTreeModelIface *iface); -static void e_alarm_list_finalize (GObject *object); -static guint e_alarm_list_get_flags (GtkTreeModel *tree_model); -static gint e_alarm_list_get_n_columns (GtkTreeModel *tree_model); -static GType e_alarm_list_get_column_type (GtkTreeModel *tree_model, - gint index); -static gboolean e_alarm_list_get_iter (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreePath *path); -static GtkTreePath *e_alarm_list_get_path (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static void e_alarm_list_get_value (GtkTreeModel *tree_model, - GtkTreeIter *iter, - gint column, - GValue *value); -static gboolean e_alarm_list_iter_next (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gboolean e_alarm_list_iter_children (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent); -static gboolean e_alarm_list_iter_has_child (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gint e_alarm_list_iter_n_children (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gboolean e_alarm_list_iter_nth_child (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n); -static gboolean e_alarm_list_iter_parent (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *child); - -static GObjectClass *parent_class = NULL; - -GtkType -e_alarm_list_get_type (void) -{ - static GType alarm_list_type = 0; - - if (!alarm_list_type) { - static const GTypeInfo alarm_list_info = - { - sizeof (EAlarmListClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) e_alarm_list_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EAlarmList), - 0, - (GInstanceInitFunc) e_alarm_list_init, - }; - - static const GInterfaceInfo tree_model_info = - { - (GInterfaceInitFunc) e_alarm_list_tree_model_init, - NULL, - NULL - }; - - column_types [E_ALARM_LIST_COLUMN_DESCRIPTION] = G_TYPE_STRING; - - alarm_list_type = g_type_register_static (G_TYPE_OBJECT, "EAlarmList", - &alarm_list_info, 0); - g_type_add_interface_static (alarm_list_type, - GTK_TYPE_TREE_MODEL, - &tree_model_info); - } - - return alarm_list_type; -} - -static void -e_alarm_list_class_init (EAlarmListClass *class) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass *) class; - - object_class->finalize = e_alarm_list_finalize; -} - -static void -e_alarm_list_tree_model_init (GtkTreeModelIface *iface) -{ - iface->get_flags = e_alarm_list_get_flags; - iface->get_n_columns = e_alarm_list_get_n_columns; - iface->get_column_type = e_alarm_list_get_column_type; - iface->get_iter = e_alarm_list_get_iter; - iface->get_path = e_alarm_list_get_path; - iface->get_value = e_alarm_list_get_value; - iface->iter_next = e_alarm_list_iter_next; - iface->iter_children = e_alarm_list_iter_children; - iface->iter_has_child = e_alarm_list_iter_has_child; - iface->iter_n_children = e_alarm_list_iter_n_children; - iface->iter_nth_child = e_alarm_list_iter_nth_child; - iface->iter_parent = e_alarm_list_iter_parent; -} - -static void -e_alarm_list_init (EAlarmList *alarm_list) -{ - alarm_list->stamp = g_random_int (); - alarm_list->columns_dirty = FALSE; - alarm_list->list = NULL; -} - -EAlarmList * -e_alarm_list_new (void) -{ - EAlarmList *alarm_list; - - alarm_list = E_ALARM_LIST (g_object_new (e_alarm_list_get_type (), NULL)); - - return alarm_list; -} - -static void -all_rows_deleted (EAlarmList *alarm_list) -{ - GtkTreePath *path; - gint i; - - if (!alarm_list->list) - return; - - path = gtk_tree_path_new (); - i = g_list_length (alarm_list->list); - gtk_tree_path_append_index (path, i); - - for ( ; i >= 0; i--) { - gtk_tree_model_row_deleted (GTK_TREE_MODEL (alarm_list), path); - gtk_tree_path_prev (path); - } - - gtk_tree_path_free (path); -} - -static void -row_deleted (EAlarmList *alarm_list, gint n) -{ - GtkTreePath *path; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - gtk_tree_model_row_deleted (GTK_TREE_MODEL (alarm_list), path); - gtk_tree_path_free (path); -} - -static void -row_added (EAlarmList *alarm_list, gint n) -{ - GtkTreePath *path; - GtkTreeIter iter; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (alarm_list), &iter, path)) - gtk_tree_model_row_inserted (GTK_TREE_MODEL (alarm_list), path, &iter); - - gtk_tree_path_free (path); -} - -static void -row_updated (EAlarmList *alarm_list, gint n) -{ - GtkTreePath *path; - GtkTreeIter iter; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (alarm_list), &iter, path)) - gtk_tree_model_row_changed (GTK_TREE_MODEL (alarm_list), path, &iter); - - gtk_tree_path_free (path); -} - -static void -e_alarm_list_finalize (GObject *object) -{ - EAlarmList *alarm_list = E_ALARM_LIST (object); -} - -/* Fulfill the GtkTreeModel requirements */ -static guint -e_alarm_list_get_flags (GtkTreeModel *tree_model) -{ - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), 0); - - return GTK_TREE_MODEL_LIST_ONLY; -} - -static gint -e_alarm_list_get_n_columns (GtkTreeModel *tree_model) -{ - EAlarmList *alarm_list = (EAlarmList *) tree_model; - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), 0); - - alarm_list->columns_dirty = TRUE; - return E_ALARM_LIST_NUM_COLUMNS; -} - -static GType -e_alarm_list_get_column_type (GtkTreeModel *tree_model, - gint index) -{ - EAlarmList *alarm_list = (EAlarmList *) tree_model; - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), G_TYPE_INVALID); - g_return_val_if_fail (index < E_ALARM_LIST_NUM_COLUMNS && - index >= 0, G_TYPE_INVALID); - - alarm_list->columns_dirty = TRUE; - return column_types [index]; -} - -const CalComponentAlarm * -e_alarm_list_get_alarm (EAlarmList *alarm_list, GtkTreeIter *iter) -{ - g_return_val_if_fail (IS_VALID_ITER (alarm_list, iter), NULL); - - return G_LIST (iter->user_data)->data; -} - -static void -free_alarm (CalComponentAlarm *alarm) -{ - cal_component_alarm_free (alarm); -} - -static CalComponentAlarm * -copy_alarm (const CalComponentAlarm *alarm) -{ - return cal_component_alarm_clone ((CalComponentAlarm *) alarm); -} - -void -e_alarm_list_set_alarm (EAlarmList *alarm_list, GtkTreeIter *iter, - const CalComponentAlarm *alarm) -{ - CalComponentAlarm *alarm_old; - - g_return_if_fail (IS_VALID_ITER (alarm_list, iter)); - - alarm_old = G_LIST (iter->user_data)->data; - free_alarm (alarm_old); - G_LIST (iter->user_data)->data = copy_alarm (alarm); - row_updated (alarm_list, g_list_position (alarm_list->list, G_LIST (iter->user_data))); -} - -void -e_alarm_list_append (EAlarmList *alarm_list, GtkTreeIter *iter, - const CalComponentAlarm *alarm) -{ - g_return_if_fail (alarm != NULL); - - alarm_list->list = g_list_append (alarm_list->list, copy_alarm (alarm)); - row_added (alarm_list, g_list_length (alarm_list->list) - 1); - - if (iter) { - iter->user_data = g_list_last (alarm_list->list); - iter->stamp = alarm_list->stamp; - } -} - -void -e_alarm_list_remove (EAlarmList *alarm_list, GtkTreeIter *iter) -{ - gint n; - - g_return_if_fail (IS_VALID_ITER (alarm_list, iter)); - - n = g_list_position (alarm_list->list, G_LIST (iter->user_data)); - free_alarm ((CalComponentAlarm *) G_LIST (iter->user_data)->data); - alarm_list->list = g_list_delete_link (alarm_list->list, G_LIST (iter->user_data)); - row_deleted (alarm_list, n); -} - -void -e_alarm_list_clear (EAlarmList *alarm_list) -{ - GList *l; - - all_rows_deleted (alarm_list); - - for (l = alarm_list->list; l; l = g_list_next (l)) { - free_alarm ((CalComponentAlarm *) l->data); - } - - g_list_free (alarm_list->list); - alarm_list->list = NULL; -} - -static gboolean -e_alarm_list_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path) -{ - EAlarmList *alarm_list = (EAlarmList *) tree_model; - GList *l; - gint i; - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), FALSE); - g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); - - if (!alarm_list->list) - return FALSE; - - alarm_list->columns_dirty = TRUE; - - i = gtk_tree_path_get_indices (path)[0]; - l = g_list_nth (alarm_list->list, i); - if (!l) - return FALSE; - - iter->user_data = l; - iter->stamp = alarm_list->stamp; - return TRUE; -} - -static GtkTreePath * -e_alarm_list_get_path (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - EAlarmList *alarm_list = (EAlarmList *) tree_model; - GtkTreePath *retval; - GList *l; - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), NULL); - g_return_val_if_fail (iter->stamp == E_ALARM_LIST (tree_model)->stamp, NULL); - - l = iter->user_data; - retval = gtk_tree_path_new (); - gtk_tree_path_append_index (retval, g_list_position (alarm_list->list, l)); - return retval; -} - -/* Builds a string for the duration of the alarm. If the duration is zero, returns NULL. */ -static char * -get_alarm_duration_string (struct icaldurationtype *duration) -{ - GString *string = g_string_new (NULL); - char *ret; - gboolean have_something; - - have_something = FALSE; - - if (duration->days > 1) { - g_string_sprintf (string, _("%d days"), duration->days); - have_something = TRUE; - } else if (duration->days == 1) { - g_string_append (string, _("1 day")); - have_something = TRUE; - } - - if (duration->weeks > 1) { - g_string_sprintf (string, _("%d weeks"), duration->weeks); - have_something = TRUE; - } else if (duration->weeks == 1) { - g_string_append (string, _("1 week")); - have_something = TRUE; - } - - if (duration->hours > 1) { - g_string_sprintf (string, _("%d hours"), duration->hours); - have_something = TRUE; - } else if (duration->hours == 1) { - g_string_append (string, _("1 hour")); - have_something = TRUE; - } - - if (duration->minutes > 1) { - g_string_sprintf (string, _("%d minutes"), duration->minutes); - have_something = TRUE; - } else if (duration->minutes == 1) { - g_string_append (string, _("1 minute")); - have_something = TRUE; - } - - if (duration->seconds > 1) { - g_string_sprintf (string, _("%d seconds"), duration->seconds); - have_something = TRUE; - } else if (duration->seconds == 1) { - g_string_append (string, _("1 second")); - have_something = TRUE; - } - - if (have_something) { - ret = string->str; - g_string_free (string, FALSE); - return ret; - } else { - g_string_free (string, TRUE); - return NULL; - } -} - -static char * -get_alarm_string (CalComponentAlarm *alarm) -{ - CalAlarmAction action; - CalAlarmTrigger trigger; - char string[256]; - char *base, *str = NULL, *dur; - - string [0] = '\0'; - - cal_component_alarm_get_action (alarm, &action); - cal_component_alarm_get_trigger (alarm, &trigger); - - switch (action) { - case CAL_ALARM_AUDIO: - base = _("Play a sound"); - break; - - case CAL_ALARM_DISPLAY: - base = _("Display a message"); - break; - - case CAL_ALARM_EMAIL: - base = _("Send an email"); - break; - - case CAL_ALARM_PROCEDURE: - base = _("Run a program"); - break; - - case CAL_ALARM_NONE: - case CAL_ALARM_UNKNOWN: - default: - base = _("Unknown action to be performed"); - break; - } - - /* FIXME: This does not look like it will localize correctly. */ - - switch (trigger.type) { - case CAL_ALARM_TRIGGER_RELATIVE_START: - dur = get_alarm_duration_string (&trigger.u.rel_duration); - - if (dur) { - if (trigger.u.rel_duration.is_neg) - str = g_strdup_printf (_("%s %s before the start of the appointment"), - base, dur); - else - str = g_strdup_printf (_("%s %s after the start of the appointment"), - base, dur); - - g_free (dur); - } else - str = g_strdup_printf (_("%s at the start of the appointment"), base); - - break; - - case CAL_ALARM_TRIGGER_RELATIVE_END: - dur = get_alarm_duration_string (&trigger.u.rel_duration); - - if (dur) { - if (trigger.u.rel_duration.is_neg) - str = g_strdup_printf (_("%s %s before the end of the appointment"), - base, dur); - else - str = g_strdup_printf (_("%s %s after the end of the appointment"), - base, dur); - - g_free (dur); - } else - str = g_strdup_printf (_("%s at the end of the appointment"), base); - - break; - - case CAL_ALARM_TRIGGER_ABSOLUTE: { - struct icaltimetype itt; - icaltimezone *utc_zone, *current_zone; - char *location; - struct tm tm; - char buf[256]; - - /* Absolute triggers come in UTC, so convert them to the local timezone */ - - itt = trigger.u.abs_time; - - utc_zone = icaltimezone_get_utc_timezone (); - location = calendar_config_get_timezone (); - current_zone = icaltimezone_get_builtin_timezone (location); - - tm = icaltimetype_to_tm_with_zone (&itt, utc_zone, current_zone); - - e_time_format_date_and_time (&tm, calendar_config_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - - str = g_strdup_printf (_("%s at %s"), base, buf); - - break; } - - case CAL_ALARM_TRIGGER_NONE: - default: - str = g_strdup_printf (_("%s for an unknown trigger type"), base); - break; - } - - return str; -} - -static void -e_alarm_list_get_value (GtkTreeModel *tree_model, - GtkTreeIter *iter, - gint column, - GValue *value) -{ - EAlarmList *alarm_list = E_ALARM_LIST (tree_model); - CalComponentAlarm *alarm; - GList *l; - const gchar *str; - - g_return_if_fail (E_IS_ALARM_LIST (tree_model)); - g_return_if_fail (column < E_ALARM_LIST_NUM_COLUMNS); - g_return_if_fail (E_ALARM_LIST (tree_model)->stamp == iter->stamp); - g_return_if_fail (IS_VALID_ITER (alarm_list, iter)); - - g_value_init (value, column_types [column]); - - if (!alarm_list->list) - return; - - l = iter->user_data; - alarm = l->data; - - if (!alarm) - return; - - switch (column) { - case E_ALARM_LIST_COLUMN_DESCRIPTION: - str = get_alarm_string (alarm); - g_value_set_string (value, str); - break; - } -} - -static gboolean -e_alarm_list_iter_next (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - GList *l; - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), FALSE); - g_return_val_if_fail (IS_VALID_ITER (E_ALARM_LIST (tree_model), iter), FALSE); - - if (!E_ALARM_LIST (tree_model)->list) - return FALSE; - - l = iter->user_data; - l = g_list_next (l); - if (l) { - iter->user_data = l; - return TRUE; - } - - return FALSE; -} - -static gboolean -e_alarm_list_iter_children (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent) -{ - EAlarmList *alarm_list = E_ALARM_LIST (tree_model); - - /* this is a list, nodes have no children */ - if (parent) - return FALSE; - - /* but if parent == NULL we return the list itself as children of the - * "root" */ - - if (!alarm_list->list) - return FALSE; - - iter->stamp = E_ALARM_LIST (tree_model)->stamp; - iter->user_data = alarm_list->list; - return TRUE; -} - -static gboolean -e_alarm_list_iter_has_child (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - g_return_val_if_fail (IS_VALID_ITER (E_ALARM_LIST (tree_model), iter), FALSE); - return FALSE; -} - -static gint -e_alarm_list_iter_n_children (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - EAlarmList *alarm_list = E_ALARM_LIST (tree_model); - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), -1); - g_return_val_if_fail (IS_VALID_ITER (alarm_list, iter), -1); - - if (iter == NULL) - return g_list_length (alarm_list->list); - - g_return_val_if_fail (E_ALARM_LIST (tree_model)->stamp == iter->stamp, -1); - return 0; -} - -static gboolean -e_alarm_list_iter_nth_child (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n) -{ - EAlarmList *alarm_list = E_ALARM_LIST (tree_model); - - g_return_val_if_fail (E_IS_ALARM_LIST (tree_model), FALSE); - - if (parent) - return FALSE; - - if (alarm_list->list) { - GList *l; - - l = g_list_nth (alarm_list->list, n); - if (!l) - return FALSE; - - iter->stamp = alarm_list->stamp; - iter->user_data = l; - return TRUE; - } - - return FALSE; -} - -static gboolean -e_alarm_list_iter_parent (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *child) -{ - return FALSE; -} diff --git a/calendar/gui/e-alarm-list.h b/calendar/gui/e-alarm-list.h deleted file mode 100644 index 2a03f9099b..0000000000 --- a/calendar/gui/e-alarm-list.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* EAlarmList - list of calendar alarms with GtkTreeModel interface. - * - * Copyright (C) 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - */ - -#ifndef E_ALARM_LIST_H -#define E_ALARM_LIST_H - -#include <gtk/gtktreemodel.h> -#include <cal-util/cal-component.h> - -G_BEGIN_DECLS - -#define E_TYPE_ALARM_LIST (e_alarm_list_get_type ()) -#define E_ALARM_LIST(obj) (GTK_CHECK_CAST ((obj), E_TYPE_ALARM_LIST, EAlarmList)) -#define E_ALARM_LIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_ALARM_LIST, EAlarmListClass)) -#define E_IS_ALARM_LIST(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_ALARM_LIST)) -#define E_IS_ALARM_LIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_ALARM_LIST)) -#define E_ALARM_LIST_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), E_TYPE_ALARM_LIST, EAlarmListClass)) - -typedef struct _EAlarmList EAlarmList; -typedef struct _EAlarmListClass EAlarmListClass; - -typedef enum -{ - E_ALARM_LIST_COLUMN_DESCRIPTION, - - E_ALARM_LIST_NUM_COLUMNS -} -EAlarmListColumnType; - -struct _EAlarmList -{ - GObject parent; - - /* Private */ - - gint stamp; - GList *list; - - guint columns_dirty : 1; -}; - -struct _EAlarmListClass -{ - GObjectClass parent_class; -}; - -GtkType e_alarm_list_get_type (void); -EAlarmList *e_alarm_list_new (void); - -const CalComponentAlarm *e_alarm_list_get_alarm (EAlarmList *alarm_list, GtkTreeIter *iter); -void e_alarm_list_set_alarm (EAlarmList *alarm_list, GtkTreeIter *iter, - const CalComponentAlarm *datetime); -void e_alarm_list_append (EAlarmList *alarm_list, GtkTreeIter *iter, - const CalComponentAlarm *datetime); -void e_alarm_list_remove (EAlarmList *alarm_list, GtkTreeIter *iter); -void e_alarm_list_clear (EAlarmList *alarm_list); - -G_END_DECLS - -#endif /* E_ALARM_LIST_H */ diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c deleted file mode 100644 index b3ac35e045..0000000000 --- a/calendar/gui/e-calendar-table.c +++ /dev/null @@ -1,1329 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 2000, Ximian, Inc. - * Copyright 2000, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * ECalendarTable - displays the CalComponent objects in a table (an ETable). - * Used for calendar events and tasks. - */ - -#include <config.h> -#include <sys/stat.h> -#include <unistd.h> -#include <gnome.h> -#include <gtk/gtkinvisible.h> -#include <gal/e-table/e-cell-checkbox.h> -#include <gal/e-table/e-cell-toggle.h> -#include <gal/e-table/e-cell-text.h> -#include <gal/e-table/e-cell-combo.h> -#include <gal/widgets/e-popup-menu.h> -#include <e-util/e-dialog-utils.h> -#include <widgets/misc/e-cell-date-edit.h> -#include <widgets/misc/e-cell-percent.h> -#include "e-comp-editor-registry.h" -#include "e-calendar-table.h" -#include "e-cell-date-edit-text.h" -#include "calendar-config.h" -#include "calendar-model.h" -#include "print.h" -#include "dialogs/delete-comp.h" -#include "dialogs/delete-error.h" -#include "dialogs/task-editor.h" - -/* Pixmaps. */ -#include "art/task.xpm" -#include "art/task-recurring.xpm" -#include "art/task-assigned.xpm" -#include "art/task-assigned-to.xpm" - -#include "art/check-filled.xpm" - -extern ECompEditorRegistry *comp_editor_registry; - -static void e_calendar_table_class_init (ECalendarTableClass *class); -static void e_calendar_table_init (ECalendarTable *cal_table); -static void e_calendar_table_destroy (GtkObject *object); - -static void e_calendar_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table); -static gint e_calendar_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEventButton *event, - ECalendarTable *cal_table); -static void e_calendar_table_on_open_task (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_save_as (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_print_task (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_cut (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_copy (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_paste (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_assign (GtkWidget *menuitem, - gpointer data); -static void e_calendar_table_on_forward (GtkWidget *menuitem, - gpointer data); -static gint e_calendar_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - ECalendarTable *cal_table); - -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - ECalendarTable *cal_table); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - ECalendarTable *cal_table); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - ECalendarTable *cal_table); -static void invisible_destroyed (GtkWidget *invisible, - ECalendarTable *cal_table); -static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, - gpointer data); -static void mark_row_complete_cb (int model_row, gpointer data); - - -/* The icons to represent the task. */ -#define E_CALENDAR_MODEL_NUM_ICONS 4 -static char** icon_xpm_data[E_CALENDAR_MODEL_NUM_ICONS] = { - task_xpm, task_recurring_xpm, task_assigned_xpm, task_assigned_to_xpm -}; -static GdkPixbuf* icon_pixbufs[E_CALENDAR_MODEL_NUM_ICONS] = { 0 }; - -static GtkTableClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - -E_MAKE_TYPE (e_calendar_table, "ECalendarTable", ECalendarTable, e_calendar_table_class_init, - e_calendar_table_init, GTK_TYPE_TABLE); - -static void -e_calendar_table_class_init (ECalendarTableClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - /* Method override */ - object_class->destroy = e_calendar_table_destroy; - -#if 0 - widget_class->realize = e_calendar_table_realize; - widget_class->unrealize = e_calendar_table_unrealize; - widget_class->style_set = e_calendar_table_style_set; - widget_class->size_allocate = e_calendar_table_size_allocate; - widget_class->focus_in_event = e_calendar_table_focus_in; - widget_class->focus_out_event = e_calendar_table_focus_out; - widget_class->key_press_event = e_calendar_table_key_press; -#endif - - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -/* Compares two priority values, which may not exist */ -static int -compare_priorities (int *a, int *b) -{ - if (a && b) { - if (*a < *b) - return -1; - else if (*a > *b) - return 1; - else - return 0; - } else if (a) - return -1; - else if (b) - return 1; - else - return 0; -} - -/* Comparison function for the task-sort column. Sorts by due date and then by - * priority. - * - * FIXME: Does this ever get called?? It doesn't seem to. - * I specified that the table should be sorted by this column, but it still - * never calls this function. - * Also, this assumes it is passed pointers to CalComponents, but I think it - * may just be passed pointers to the 2 cell values. - */ -static gint -task_compare_cb (gconstpointer a, gconstpointer b) -{ - CalComponent *ca, *cb; - CalComponentDateTime due_a, due_b; - int *prio_a, *prio_b; - int retval; - - ca = CAL_COMPONENT (a); - cb = CAL_COMPONENT (b); - - cal_component_get_due (ca, &due_a); - cal_component_get_due (cb, &due_b); - cal_component_get_priority (ca, &prio_a); - cal_component_get_priority (cb, &prio_b); - - if (due_a.value && due_b.value) { - int v; - - /* FIXME: TIMEZONES. But currently we have no way to get the - CalClient, so we can't get the timezone. */ - v = icaltime_compare (*due_a.value, *due_b.value); - - if (v == 0) - retval = compare_priorities (prio_a, prio_b); - else - retval = v; - } else if (due_a.value) - retval = -1; - else if (due_b.value) - retval = 1; - else - retval = compare_priorities (prio_a, prio_b); - - cal_component_free_datetime (&due_a); - cal_component_free_datetime (&due_b); - - if (prio_a) - cal_component_free_priority (prio_a); - - if (prio_b) - cal_component_free_priority (prio_b); - - return retval; -} - -static gint -date_compare_cb (gconstpointer a, gconstpointer b) -{ - ECellDateEditValue *dv1 = (ECellDateEditValue *) a; - ECellDateEditValue *dv2 = (ECellDateEditValue *) b; - struct icaltimetype tt; - - /* First check if either is NULL. NULL dates sort last. */ - if (!dv1 || !dv2) { - if (dv1 == dv2) - return 0; - else if (dv1) - return -1; - else - return 1; - } - - /* Copy the 2nd value and convert it to the same timezone as the - first. */ - tt = dv2->tt; - - icaltimezone_convert_time (&tt, dv2->zone, dv1->zone); - - /* Now we can compare them. */ - - return icaltime_compare (dv1->tt, tt); -} - -static gint -percent_compare_cb (gconstpointer a, gconstpointer b) -{ - int percent1 = GPOINTER_TO_INT (a); - int percent2 = GPOINTER_TO_INT (b); - int retval; - - if (percent1 > percent2) - retval = 1; - else if (percent1 < percent2) - retval = -1; - else - retval = 0; - - return retval; -} - -static gint -priority_compare_cb (gconstpointer a, gconstpointer b) -{ - int priority1, priority2; - - priority1 = cal_util_priority_from_string ((const char*) a); - priority2 = cal_util_priority_from_string ((const char*) b); - - /* We change undefined priorities so they appear after 'Low'. */ - if (priority1 <= 0) - priority1 = 10; - if (priority2 <= 0) - priority2 = 10; - - /* We'll just use the ordering of the priority values. */ - if (priority1 < priority2) - return -1; - else if (priority1 > priority2) - return 1; - else - return 0; -} - -static void -e_calendar_table_init (ECalendarTable *cal_table) -{ - GtkWidget *table; - ETable *e_table; - ECell *cell, *popup_cell; - ETableExtras *extras; - gint i; - GdkPixbuf *pixbuf; - GList *strings; - - /* Create the model */ - - cal_table->model = calendar_model_new (); - - /* Create the header columns */ - - extras = e_table_extras_new(); - - /* - * Normal string fields. - */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - NULL); - - e_table_extras_add_cell (extras, "calstring", cell); - - - /* - * Date fields. - */ - cell = e_cell_date_edit_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - NULL); - - popup_cell = e_cell_date_edit_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - e_table_extras_add_cell (extras, "dateedit", popup_cell); - cal_table->dates_cell = E_CELL_DATE_EDIT (popup_cell); - - e_cell_date_edit_set_get_time_callback (E_CELL_DATE_EDIT (popup_cell), - e_calendar_table_get_current_time, - cal_table, NULL); - - - /* - * Combo fields. - */ - - /* Classification field. */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - "editable", FALSE, - NULL); - - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Public")); - strings = g_list_append (strings, (char*) _("Private")); - strings = g_list_append (strings, (char*) _("Confidential")); - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), - strings); - - e_table_extras_add_cell (extras, "classification", popup_cell); - - /* Priority field. */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - "editable", FALSE, - NULL); - - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("High")); - strings = g_list_append (strings, (char*) _("Normal")); - strings = g_list_append (strings, (char*) _("Low")); - strings = g_list_append (strings, (char*) _("Undefined")); - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), - strings); - - e_table_extras_add_cell (extras, "priority", popup_cell); - - /* Percent field. */ - cell = e_cell_percent_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - NULL); - - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("0%")); - strings = g_list_append (strings, (char*) _("10%")); - strings = g_list_append (strings, (char*) _("20%")); - strings = g_list_append (strings, (char*) _("30%")); - strings = g_list_append (strings, (char*) _("40%")); - strings = g_list_append (strings, (char*) _("50%")); - strings = g_list_append (strings, (char*) _("60%")); - strings = g_list_append (strings, (char*) _("70%")); - strings = g_list_append (strings, (char*) _("80%")); - strings = g_list_append (strings, (char*) _("90%")); - strings = g_list_append (strings, (char*) _("100%")); - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), - strings); - - e_table_extras_add_cell (extras, "percent", popup_cell); - - /* Transparency field. */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - "editable", FALSE, - NULL); - - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Free")); - strings = g_list_append (strings, (char*) _("Busy")); - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), - strings); - - e_table_extras_add_cell (extras, "transparency", popup_cell); - - /* Status field. */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "strikeout_column", CAL_COMPONENT_FIELD_COMPLETE, - "bold_column", CAL_COMPONENT_FIELD_OVERDUE, - "color_column", CAL_COMPONENT_FIELD_COLOR, - "editable", FALSE, - NULL); - - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Not Started")); - strings = g_list_append (strings, (char*) _("In Progress")); - strings = g_list_append (strings, (char*) _("Completed")); - strings = g_list_append (strings, (char*) _("Cancelled")); - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), - strings); - - e_table_extras_add_cell (extras, "calstatus", popup_cell); - - /* Task sorting field */ - /* FIXME: This column should not be displayed, but ETableExtras requires - * its shit to be visible columns listed in the XML spec. - */ - e_table_extras_add_compare (extras, "task-sort", task_compare_cb); - - e_table_extras_add_compare (extras, "date-compare", - date_compare_cb); - e_table_extras_add_compare (extras, "percent-compare", - percent_compare_cb); - e_table_extras_add_compare (extras, "priority-compare", - priority_compare_cb); - - /* Create pixmaps */ - - if (!icon_pixbufs[0]) - for (i = 0; i < E_CALENDAR_MODEL_NUM_ICONS; i++) { - icon_pixbufs[i] = gdk_pixbuf_new_from_xpm_data ( - (const char **) icon_xpm_data[i]); - } - - cell = e_cell_toggle_new (0, E_CALENDAR_MODEL_NUM_ICONS, icon_pixbufs); - e_table_extras_add_cell(extras, "icon", cell); - e_table_extras_add_pixbuf(extras, "icon", icon_pixbufs[0]); - - pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) check_filled_xpm); - e_table_extras_add_pixbuf(extras, "complete", pixbuf); - gdk_pixbuf_unref(pixbuf); - - /* Create the table */ - - table = e_table_scrolled_new_from_spec_file (E_TABLE_MODEL (cal_table->model), - extras, - EVOLUTION_ETSPECDIR "/e-calendar-table.etspec", - NULL); - g_object_unref (extras); - - cal_table->etable = table; - gtk_table_attach (GTK_TABLE (cal_table), table, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (table); - - - e_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (table)); - g_signal_connect (e_table, "double_click", G_CALLBACK (e_calendar_table_on_double_click), cal_table); - g_signal_connect (e_table, "right_click", G_CALLBACK (e_calendar_table_on_right_click), cal_table); - g_signal_connect (e_table, "key_press", G_CALLBACK (e_calendar_table_on_key_press), cal_table); - - /* Set up the invisible widget for the clipboard selections */ - cal_table->invisible = gtk_invisible_new (); - gtk_selection_add_target (cal_table->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - g_signal_connect (cal_table->invisible, "selection_get", - G_CALLBACK (selection_get), cal_table); - g_signal_connect (cal_table->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), cal_table); - g_signal_connect (cal_table->invisible, "selection_received", - G_CALLBACK (selection_received), cal_table); - g_signal_connect (cal_table->invisible, "destroy", - G_CALLBACK (invisible_destroyed), cal_table); - - cal_table->clipboard_selection = NULL; -} - - -/** - * e_calendar_table_new: - * @Returns: a new #ECalendarTable. - * - * Creates a new #ECalendarTable. - **/ -GtkWidget * -e_calendar_table_new (void) -{ - GtkWidget *cal_table; - - cal_table = GTK_WIDGET (g_object_new (e_calendar_table_get_type (), NULL)); - - return cal_table; -} - - -/** - * e_calendar_table_get_model: - * @cal_table: A calendar table. - * - * Queries the calendar data model that a calendar table is using. - * - * Return value: A calendar model. - **/ -CalendarModel * -e_calendar_table_get_model (ECalendarTable *cal_table) -{ - g_return_val_if_fail (cal_table != NULL, NULL); - g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); - - return cal_table->model; -} - - -static void -e_calendar_table_destroy (GtkObject *object) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (object); - - g_object_unref (cal_table->model); - cal_table->model = NULL; - - if (cal_table->invisible) - gtk_widget_destroy (cal_table->invisible); - if (cal_table->clipboard_selection) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -/** - * e_calendar_table_get_table: - * @cal_table: A calendar table. - * - * Queries the #ETable widget that the calendar table is using. - * - * Return value: The #ETable widget that the calendar table uses to display its - * data. - **/ -ETable * -e_calendar_table_get_table (ECalendarTable *cal_table) -{ - g_return_val_if_fail (cal_table != NULL, NULL); - g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); - - return e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); -} - -/** - * e_calendar_table_complete_selected: - * @cal_table: A calendar table - * - * Marks the selected items as completed - **/ -void -e_calendar_table_complete_selected (ECalendarTable *cal_table) -{ - ETable *etable; - - g_return_if_fail (cal_table != NULL); - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, mark_row_complete_cb, cal_table); -} - -/* Used from e_table_selected_row_foreach(); puts the selected row number in an - * int pointed to by the closure data. - */ -static void -get_selected_row_cb (int model_row, gpointer data) -{ - int *row; - - row = data; - *row = model_row; -} - -/* Returns the component that is selected in the table; only works if there is - * one and only one selected row. - */ -static CalComponent * -get_selected_comp (ECalendarTable *cal_table) -{ - ETable *etable; - int row; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - if (e_table_selected_count (etable) != 1) - return NULL; - - row = -1; - e_table_selected_row_foreach (etable, - get_selected_row_cb, - &row); - g_assert (row != -1); - - return calendar_model_get_component (cal_table->model, row); -} - -struct get_selected_uids_closure { - ECalendarTable *cal_table; - GSList *uids; -}; - -/* Used from e_table_selected_row_foreach(), builds a list of the selected UIDs */ -static void -add_uid_cb (int model_row, gpointer data) -{ - struct get_selected_uids_closure *closure; - CalComponent *comp; - const char *uid; - - closure = data; - - comp = calendar_model_get_component (closure->cal_table->model, model_row); - cal_component_get_uid (comp, &uid); - - closure->uids = g_slist_prepend (closure->uids, (char *) uid); -} - -static GSList * -get_selected_uids (ECalendarTable *cal_table) -{ - struct get_selected_uids_closure closure; - ETable *etable; - - closure.cal_table = cal_table; - closure.uids = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, add_uid_cb, &closure); - - return closure.uids; -} - -/* Deletes all of the selected components in the table */ -static void -delete_selected_components (ECalendarTable *cal_table) -{ - CalClient *client; - GSList *uids, *l; - - uids = get_selected_uids (cal_table); - - client = calendar_model_get_cal_client (cal_table->model); - - calendar_model_set_status_message (e_calendar_table_get_model (cal_table), - _("Deleting selected objects")); - - for (l = uids; l; l = l->next) { - const char *uid; - - uid = l->data; - - delete_error_dialog (cal_client_remove_object (client, uid), CAL_COMPONENT_TODO); - } - - calendar_model_set_status_message (e_calendar_table_get_model (cal_table), NULL); - - g_slist_free (uids); -} - -/** - * e_calendar_table_delete_selected: - * @cal_table: A calendar table. - * - * Deletes the selected components in the table; asks the user first. - **/ -void -e_calendar_table_delete_selected (ECalendarTable *cal_table) -{ - ETable *etable; - int n_selected; - CalComponent *comp; - - g_return_if_fail (cal_table != NULL); - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - - n_selected = e_table_selected_count (etable); - if (n_selected <= 0) - return; - - if (n_selected == 1) - comp = get_selected_comp (cal_table); - else - comp = NULL; - - /* FIXME: this may be something other than a TODO component */ - - if (delete_component_dialog (comp, FALSE, n_selected, CAL_COMPONENT_TODO, - GTK_WIDGET (cal_table))) - delete_selected_components (cal_table); -} - -/** - * e_calendar_table_cut_clipboard: - * @cal_table: A calendar table. - * - * Cuts selected tasks in the given calendar table - */ -void -e_calendar_table_cut_clipboard (ECalendarTable *cal_table) -{ - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - e_calendar_table_copy_clipboard (cal_table); - delete_selected_components (cal_table); -} - -/* callback for e_table_selected_row_foreach */ -static void -copy_row_cb (int model_row, gpointer data) -{ - ECalendarTable *cal_table; - CalComponent *comp; - gchar *comp_str; - icalcomponent *child; - - cal_table = E_CALENDAR_TABLE (data); - - g_return_if_fail (cal_table->tmp_vcal != NULL); - - comp = calendar_model_get_component (cal_table->model, model_row); - if (!comp) - return; - - /* add timezones to the VCALENDAR component */ - cal_util_add_timezones_from_component (cal_table->tmp_vcal, comp); - - /* add the new component to the VCALENDAR component */ - comp_str = cal_component_get_as_string (comp); - child = icalparser_parse_string (comp_str); - if (child) { - icalcomponent_add_component (cal_table->tmp_vcal, - icalcomponent_new_clone (child)); - icalcomponent_free (child); - } - - g_free (comp_str); -} - -/** - * e_calendar_table_copy_clipboard: - * @cal_table: A calendar table. - * - * Copies selected tasks into the clipboard - */ -void -e_calendar_table_copy_clipboard (ECalendarTable *cal_table) -{ - ETable *etable; - char *comp_str; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - if (cal_table->clipboard_selection) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } - - /* create temporary VCALENDAR object */ - cal_table->tmp_vcal = cal_util_new_top_level (); - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, copy_row_cb, cal_table); - - comp_str = icalcomponent_as_ical_string (cal_table->tmp_vcal); - cal_table->clipboard_selection = g_strdup (comp_str); - icalcomponent_free (cal_table->tmp_vcal); - cal_table->tmp_vcal = NULL; - - gtk_selection_owner_set (cal_table->invisible, clipboard_atom, GDK_CURRENT_TIME); -} - -/** - * e_calendar_table_paste_clipboard: - * @cal_table: A calendar table. - * - * Pastes tasks currently in the clipboard into the given calendar table - */ -void -e_calendar_table_paste_clipboard (ECalendarTable *cal_table) -{ - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - gtk_selection_convert (cal_table->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - -/* Opens a task in the task editor */ -static void -open_task (ECalendarTable *cal_table, CalComponent *comp, gboolean assign) -{ - CompEditor *tedit; - const char *uid; - - cal_component_get_uid (comp, &uid); - - tedit = e_comp_editor_registry_find (comp_editor_registry, uid); - if (tedit == NULL) { - tedit = COMP_EDITOR (task_editor_new (calendar_model_get_cal_client (cal_table->model))); - - comp_editor_edit_comp (tedit, comp); - if (assign) - task_editor_show_assignment (TASK_EDITOR (tedit)); - - e_comp_editor_registry_add (comp_editor_registry, tedit, FALSE); - } - - comp_editor_focus (tedit); -} - -/* Opens the task in the specified row */ -static void -open_task_by_row (ECalendarTable *cal_table, int row) -{ - CalComponent *comp; - - comp = calendar_model_get_component (cal_table->model, row); - open_task (cal_table, comp, FALSE); -} - -static void -e_calendar_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table) -{ - open_task_by_row (cal_table, row); -} - -/* Used from e_table_selected_row_foreach() */ -static void -mark_row_complete_cb (int model_row, gpointer data) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (data); - calendar_model_mark_task_complete (cal_table->model, model_row); -} - -/* Callback used for the "mark tasks as complete" menu item */ -static void -mark_as_complete_cb (GtkWidget *menuitem, gpointer data) -{ - ECalendarTable *cal_table; - ETable *etable; - - cal_table = E_CALENDAR_TABLE (data); - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, mark_row_complete_cb, cal_table); -} - -/* Callback for the "delete tasks" menu item */ -static void -delete_cb (GtkWidget *menuitem, gpointer data) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (data); - e_calendar_table_delete_selected (cal_table); -} - - -enum { - MASK_SINGLE = 1 << 0, /* For commands that work on 1 task. */ - MASK_MULTIPLE = 1 << 1, /* For commands for multiple tasks. */ - MASK_EDITABLE = 1 << 2, /* For commands disabled in read-only folders */ - MASK_ASSIGNABLE = 1 << 3 /* For non-task assignable backends */ -}; - - -static EPopupMenu tasks_popup_menu [] = { - E_POPUP_ITEM (N_("_Open"), GTK_SIGNAL_FUNC (e_calendar_table_on_open_task), MASK_SINGLE), - E_POPUP_ITEM (N_("_Save as..."), GTK_SIGNAL_FUNC (e_calendar_table_on_save_as), MASK_SINGLE), - E_POPUP_ITEM (N_("_Print..."), GTK_SIGNAL_FUNC (e_calendar_table_on_print_task), MASK_SINGLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("C_ut"), GTK_SIGNAL_FUNC (e_calendar_table_on_cut), MASK_EDITABLE), - E_POPUP_ITEM (N_("_Copy"), GTK_SIGNAL_FUNC (e_calendar_table_on_copy), 0), - E_POPUP_ITEM (N_("_Paste"), GTK_SIGNAL_FUNC (e_calendar_table_on_paste), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Assign Task"), GTK_SIGNAL_FUNC (e_calendar_table_on_assign), MASK_SINGLE | MASK_EDITABLE | MASK_ASSIGNABLE), - E_POPUP_ITEM (N_("_Forward as iCalendar"), GTK_SIGNAL_FUNC (e_calendar_table_on_forward), MASK_SINGLE), - E_POPUP_ITEM (N_("_Mark as Complete"), GTK_SIGNAL_FUNC (mark_as_complete_cb), MASK_SINGLE | MASK_EDITABLE), - E_POPUP_ITEM (N_("_Mark Selected Tasks as Complete"), GTK_SIGNAL_FUNC (mark_as_complete_cb), MASK_MULTIPLE | MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Delete"), GTK_SIGNAL_FUNC (delete_cb), MASK_SINGLE | MASK_EDITABLE), - E_POPUP_ITEM (N_("_Delete Selected Tasks"), GTK_SIGNAL_FUNC (delete_cb), MASK_MULTIPLE | MASK_EDITABLE), - - E_POPUP_TERMINATOR -}; - -static gint -e_calendar_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEventButton *event, - ECalendarTable *cal_table) -{ - int n_selected; - int hide_mask = 0; - int disable_mask = 0; - - n_selected = e_table_selected_count (table); - if (n_selected <= 0) - return TRUE; - - if (n_selected == 1) - hide_mask = MASK_MULTIPLE; - else - hide_mask = MASK_SINGLE; - - if (cal_client_is_read_only (calendar_model_get_cal_client (e_calendar_table_get_model (cal_table)))) - disable_mask |= MASK_EDITABLE; - - if (cal_client_get_static_capability (calendar_model_get_cal_client (e_calendar_table_get_model (cal_table)), - CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT)) - disable_mask |= MASK_ASSIGNABLE; - - e_popup_menu_run (tasks_popup_menu, (GdkEvent *) event, - disable_mask, hide_mask, cal_table); - - return TRUE; -} - - -static void -e_calendar_table_on_open_task (GtkWidget *menuitem, - gpointer data) -{ - ECalendarTable *cal_table; - CalComponent *comp; - - cal_table = E_CALENDAR_TABLE (data); - - comp = get_selected_comp (cal_table); - if (comp) - open_task (cal_table, comp, FALSE); -} - -static void -e_calendar_table_on_save_as (GtkWidget *widget, gpointer data) -{ - ECalendarTable *cal_table; - CalClient *client; - CalComponent *comp; - char *filename; - char *ical_string; - FILE *file; - - cal_table = E_CALENDAR_TABLE (data); - - client = calendar_model_get_cal_client (cal_table->model); - comp = get_selected_comp (cal_table); - if (comp == NULL) - return; - - filename = e_file_dialog_save (_("Save as...")); - if (filename == NULL) - return; - - ical_string = cal_client_get_component_as_string (client, comp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - file = fopen (filename, "w"); - if (file == NULL) { - g_warning ("Couldn't save item"); - return; - } - - fprintf (file, ical_string); - g_free (ical_string); - fclose (file); -} - -static void -e_calendar_table_on_print_task (GtkWidget *widget, gpointer data) -{ - ECalendarTable *cal_table; - CalClient *client; - CalComponent *comp; - - cal_table = E_CALENDAR_TABLE (data); - - client = calendar_model_get_cal_client (cal_table->model); - comp = get_selected_comp (cal_table); - if (comp == NULL) - return; - - print_comp (comp, client, FALSE); -} - -static void -e_calendar_table_on_cut (GtkWidget *menuitem, gpointer data) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (data); - e_calendar_table_cut_clipboard (cal_table); -} - -static void -e_calendar_table_on_copy (GtkWidget *menuitem, gpointer data) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (data); - e_calendar_table_copy_clipboard (cal_table); -} - -static void -e_calendar_table_on_paste (GtkWidget *menuitem, gpointer data) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (data); - e_calendar_table_paste_clipboard (cal_table); -} - -static void -e_calendar_table_on_assign (GtkWidget *widget, gpointer data) -{ - ECalendarTable *cal_table; - CalComponent *comp; - - cal_table = E_CALENDAR_TABLE (data); - - comp = get_selected_comp (cal_table); - if (comp) - open_task (cal_table, comp, TRUE); -} - -static void -e_calendar_table_on_forward (GtkWidget *widget, gpointer data) -{ - ECalendarTable *cal_table; - CalClient *client; - CalComponent *comp; - - cal_table = E_CALENDAR_TABLE (data); - - client = calendar_model_get_cal_client (cal_table->model); - comp = get_selected_comp (cal_table); - if (comp) - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, - client, NULL); -} - -static gint -e_calendar_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - ECalendarTable *cal_table) -{ - if (event->keyval == GDK_Delete) { - delete_cb (NULL, cal_table); - return TRUE; - } - - return FALSE; -} - -/* Loads the state of the table (headers shown etc.) from the given file. */ -void -e_calendar_table_load_state (ECalendarTable *cal_table, - gchar *filename) -{ - struct stat st; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - if (stat (filename, &st) == 0 && st.st_size > 0 - && S_ISREG (st.st_mode)) { - e_table_load_state (e_table_scrolled_get_table(E_TABLE_SCROLLED (cal_table->etable)), filename); - } -} - - -/* Saves the state of the table (headers shown etc.) to the given file. */ -void -e_calendar_table_save_state (ECalendarTable *cal_table, - gchar *filename) -{ - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - e_table_save_state (e_table_scrolled_get_table(E_TABLE_SCROLLED (cal_table->etable)), - filename); -} - - -static void -invisible_destroyed (GtkWidget *invisible, ECalendarTable *cal_table) -{ - g_object_unref (cal_table->invisible); - cal_table->invisible = NULL; -} - -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - ECalendarTable *cal_table) -{ - if (cal_table->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - cal_table->clipboard_selection, - strlen (cal_table->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - ECalendarTable *cal_table) -{ - if (cal_table->clipboard_selection != NULL) { - g_free (cal_table->clipboard_selection); - cal_table->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - ECalendarTable *cal_table) -{ - char *comp_str; - icalcomponent *icalcomp; - char *uid; - CalComponent *comp; - icalcomponent_kind kind; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - if (selection_data->length < 0 || - selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } - - comp_str = (char *) selection_data->data; - icalcomp = icalparser_parse_string ((const char *) comp_str); - if (!icalcomp) - return; - - /* check the type of the component */ - kind = icalcomponent_isa (icalcomp); - if (kind != ICAL_VCALENDAR_COMPONENT && - kind != ICAL_VEVENT_COMPONENT && - kind != ICAL_VTODO_COMPONENT && - kind != ICAL_VJOURNAL_COMPONENT) { - return; - } - - calendar_model_set_status_message (e_calendar_table_get_model (cal_table), - _("Updating objects")); - - if (kind == ICAL_VCALENDAR_COMPONENT) { - icalcomponent_kind child_kind; - icalcomponent *subcomp; - icalcomponent *vcal_comp; - - vcal_comp = icalcomp; - subcomp = icalcomponent_get_first_component ( - vcal_comp, ICAL_ANY_COMPONENT); - while (subcomp) { - child_kind = icalcomponent_isa (subcomp); - if (child_kind == ICAL_VEVENT_COMPONENT || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - CalComponent *tmp_comp; - - uid = cal_component_gen_uid (); - tmp_comp = cal_component_new (); - cal_component_set_icalcomponent ( - tmp_comp, icalcomponent_new_clone (subcomp)); - cal_component_set_uid (tmp_comp, uid); - - cal_client_update_object ( - calendar_model_get_cal_client (cal_table->model), - tmp_comp); - free (uid); - g_object_unref (tmp_comp); - } - subcomp = icalcomponent_get_next_component ( - vcal_comp, ICAL_ANY_COMPONENT); - } - } - else { - comp = cal_component_new (); - cal_component_set_icalcomponent (comp, icalcomp); - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, (const char *) uid); - free (uid); - - cal_client_update_object ( - calendar_model_get_cal_client (cal_table->model), - comp); - g_object_unref (comp); - } - - calendar_model_set_status_message (e_calendar_table_get_model (cal_table), NULL); -} - - -/* Returns the current time, for the ECellDateEdit items. - FIXME: Should probably use the timezone of the item rather than the - current timezone, though that may be difficult to get from here. */ -static struct tm -e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data) -{ - char *location; - icaltimezone *zone; - struct tm tmp_tm = { 0 }; - struct icaltimetype tt; - - /* Get the current timezone. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone); - - /* Now copy it to the struct tm and return it. */ - tmp_tm.tm_year = tt.year - 1900; - tmp_tm.tm_mon = tt.month - 1; - tmp_tm.tm_mday = tt.day; - tmp_tm.tm_hour = tt.hour; - tmp_tm.tm_min = tt.minute; - tmp_tm.tm_sec = tt.second; - tmp_tm.tm_isdst = -1; - - return tmp_tm; -} - - -#ifdef TRANSLATORS_ONLY - -static char *test[] = { - N_("Click to add a task") -}; - -#endif diff --git a/calendar/gui/e-calendar-table.etspec b/calendar/gui/e-calendar-table.etspec deleted file mode 100644 index 2e47b817d2..0000000000 --- a/calendar/gui/e-calendar-table.etspec +++ /dev/null @@ -1,26 +0,0 @@ -<ETableSpecification click-to-add="true" _click-to-add-message="Click to add a task" draw-grid="true"> - <ETableColumn model_col= "0" _title="Categories" expansion="1.0" minimum_width="10" resizable="true" cell="calstring" compare="string"/> - <ETableColumn model_col= "1" _title="Classification" expansion="1.0" minimum_width="10" resizable="true" cell="classification" compare="string" priority="-1"/> - <ETableColumn model_col= "2" _title="Completion Date" expansion="2.0" minimum_width="10" resizable="true" cell="dateedit" compare="date-compare" priority="-2"/> - <ETableColumn model_col= "3" _title="End Date" expansion="2.0" minimum_width="10" resizable="true" cell="dateedit" compare="date-compare" priority="-2" disabled="true"/> - <ETableColumn model_col= "4" _title="Start Date" expansion="2.0" minimum_width="10" resizable="true" cell="dateedit" compare="date-compare" priority="-2"/> - <ETableColumn model_col= "5" _title="Due Date" expansion="2.0" minimum_width="10" resizable="true" cell="dateedit" compare="date-compare" priority="-2"/> - <ETableColumn model_col= "6" _title="Geographical Position" expansion="1.0" minimum_width="10" resizable="true" cell="calstring" compare="string"/> - <ETableColumn model_col= "7" _title="% Complete" expansion="1.0" minimum_width="10" resizable="true" cell="percent" compare="percent-compare" priority="-3"/> - <ETableColumn model_col= "8" _title="Priority" expansion="1.0" minimum_width="10" resizable="true" cell="priority" compare="priority-compare" priority="-3"/> - <ETableColumn model_col= "9" _title="Summary" expansion="3.0" minimum_width="10" resizable="true" cell="calstring" compare="string" priority="10"/> - <ETableColumn model_col="10" _title="Show Time As" expansion="1.0" minimum_width="10" resizable="true" cell="transparency" compare="string" priority="-1" disabled="true"/> - <ETableColumn model_col="11" _title="URL" expansion="2.0" minimum_width="10" resizable="true" cell="calstring" compare="string"/> - <ETableColumn model_col="12" _title="Alarms" expansion="1.0" minimum_width="10" resizable="true" cell="calstring" compare="string" disabled="true"/> - <ETableColumn model_col="13" pixbuf="icon" _title="Type" expansion="1.0" minimum_width="16" resizable="false" cell="icon" compare="integer" priority="-4"/> - <ETableColumn model_col="14" pixbuf="complete" _title="Complete" expansion="1.0" minimum_width="16" resizable="false" cell="checkbox" compare="integer" priority="-4"/> - <ETableColumn model_col="18" _title="Status" expansion="1.0" minimum_width="10" resizable="true" cell="calstatus" compare="string" priority="-1"/> - <ETableColumn model_col="19" _title="Task sort" cell="task-sort" compare="task-sort" priority="-4"/> - - <ETableState> - <column source="13"/> - <column source="14"/> - <column source= "9"/> - <grouping></grouping> - </ETableState> -</ETableSpecification> diff --git a/calendar/gui/e-calendar-table.h b/calendar/gui/e-calendar-table.h deleted file mode 100644 index fab3afd85d..0000000000 --- a/calendar/gui/e-calendar-table.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2000, Ximian, Inc. - * Copyright 2000, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_CALENDAR_TABLE_H_ -#define _E_CALENDAR_TABLE_H_ - -#include <gtk/gtktable.h> -#include <gal/e-table/e-table-scrolled.h> -#include <widgets/misc/e-cell-date-edit.h> -#include "calendar-model.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * ECalendarTable - displays the iCalendar objects in a table (an ETable). - * Used for calendar events and tasks. - */ - - -#define E_CALENDAR_TABLE(obj) GTK_CHECK_CAST (obj, e_calendar_table_get_type (), ECalendarTable) -#define E_CALENDAR_TABLE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_calendar_table_get_type (), ECalendarTableClass) -#define E_IS_CALENDAR_TABLE(obj) GTK_CHECK_TYPE (obj, e_calendar_table_get_type ()) - - -typedef struct _ECalendarTable ECalendarTable; -typedef struct _ECalendarTableClass ECalendarTableClass; - - -struct _ECalendarTable -{ - GtkTable table; - - /* The model that we use */ - CalendarModel *model; - - GtkWidget *etable; - - /* The ECell used to view & edit dates. */ - ECellDateEdit *dates_cell; - - /* The invisible widget used for cut/copy/paste */ - GtkWidget *invisible; - gchar *clipboard_selection; - icalcomponent *tmp_vcal; -}; - -struct _ECalendarTableClass -{ - GtkTableClass parent_class; -}; - - -GtkType e_calendar_table_get_type (void); -GtkWidget* e_calendar_table_new (void); - -CalendarModel *e_calendar_table_get_model (ECalendarTable *cal_table); - -ETable *e_calendar_table_get_table (ECalendarTable *cal_table); - -void e_calendar_table_complete_selected (ECalendarTable *cal_table); -void e_calendar_table_delete_selected (ECalendarTable *cal_table); - -/* Clipboard related functions */ -void e_calendar_table_cut_clipboard (ECalendarTable *cal_table); -void e_calendar_table_copy_clipboard (ECalendarTable *cal_table); -void e_calendar_table_paste_clipboard (ECalendarTable *cal_table); - -/* These load and save the state of the table (headers shown etc.) to/from - the given file. */ -void e_calendar_table_load_state (ECalendarTable *cal_table, - gchar *filename); -void e_calendar_table_save_state (ECalendarTable *cal_table, - gchar *filename); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CALENDAR_TABLE_H_ */ diff --git a/calendar/gui/e-cell-date-edit-text.c b/calendar/gui/e-cell-date-edit-text.c deleted file mode 100644 index f6e6e31b60..0000000000 --- a/calendar/gui/e-cell-date-edit-text.c +++ /dev/null @@ -1,235 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * ECellDateEditText - a subclass of ECellText used to show and edit the text - * representation of the date, from a CalComponentDateTime* model value. - */ - -#include <config.h> - -#include <sys/time.h> -#include <time.h> -#include <unistd.h> -#include <string.h> -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnome/gnome-i18n.h> -#include <gal/util/e-util.h> -#include <gal/widgets/e-unicode.h> -#include <e-util/e-time-utils.h> -#include <cal-util/timeutil.h> - -#include "e-cell-date-edit-text.h" - - -#define PARENT_TYPE e_cell_text_get_type () - -static ECellTextClass *parent_class; - - -void -e_cell_date_edit_text_set_timezone (ECellDateEditText *ecd, - icaltimezone *zone) -{ - g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd)); - - ecd->zone = zone; -} - - -void -e_cell_date_edit_text_set_use_24_hour_format (ECellDateEditText *ecd, - gboolean use_24_hour) -{ - g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd)); - - ecd->use_24_hour_format = use_24_hour; -} - - -static char * -ecd_get_text (ECellText *cell, ETableModel *model, int col, int row) -{ - ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell); - ECellDateEditValue *dv = e_table_model_value_at (model, col, row); - struct tm tmp_tm; - char buffer[64]; - - if (!dv) - return g_strdup (""); - - /* Note that although the property may be in a different - timezone, we convert it to the current timezone to display - it in the table. If the user actually edits the value, - it will be set to the current timezone. See set_value(). */ - tmp_tm = icaltimetype_to_tm_with_zone (&dv->tt, dv->zone, ecd->zone); - - e_time_format_date_and_time (&tmp_tm, ecd->use_24_hour_format, - !dv->tt.is_date, FALSE, - buffer, sizeof (buffer)); - return g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); -} - - -static void -ecd_free_text (ECellText *cell, char *text) -{ - g_free (text); -} - - -/* FIXME: We need to set the "transient_for" property for the dialog. */ -static void -show_date_warning (ECellDateEditText *ecd) -{ - GtkWidget *dialog; - char buffer[64], message[256], *format; - time_t t; - struct tm *tmp_tm; - - t = time (NULL); - /* We are only using this as an example, so the timezone doesn't - matter. */ - tmp_tm = localtime (&t); - - if (ecd->use_24_hour_format) - /* strftime format of a weekday, a date and a time, 24-hour. */ - format = _("%a %m/%d/%Y %H:%M:%S"); - else - /* strftime format of a weekday, a date and a time, 12-hour. */ - format = _("%a %m/%d/%Y %I:%M:%S %p"); - - strftime (buffer, sizeof (buffer), format, tmp_tm); - - g_snprintf (message, 256, - _("The date must be entered in the format: \n\n%s"), - buffer); - - dialog = gnome_message_box_new (message, - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, NULL); - gtk_widget_show (dialog); -} - - -static void -ecd_set_value (ECellText *cell, ETableModel *model, int col, int row, - const char *text) -{ - ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell); - ETimeParseStatus status; - struct tm tmp_tm; - ECellDateEditValue *value; - gboolean is_date = TRUE; - - /* Try to parse just a date first. If the value is only a date, we - use a DATE value. */ - status = e_time_parse_date (text, &tmp_tm); - if (status == E_TIME_PARSE_INVALID) { - is_date = FALSE; - status = e_time_parse_date_and_time (text, &tmp_tm); - - if (status == E_TIME_PARSE_INVALID) { - show_date_warning (ecd); - return; - } - } - - if (status == E_TIME_PARSE_NONE) { - value = NULL; - } else { - ECellDateEditValue dv; - - dv.tt = icaltime_null_time (); - - dv.tt.year = tmp_tm.tm_year + 1900; - dv.tt.month = tmp_tm.tm_mon + 1; - dv.tt.day = tmp_tm.tm_mday; - dv.tt.hour = tmp_tm.tm_hour; - dv.tt.minute = tmp_tm.tm_min; - dv.tt.second = tmp_tm.tm_sec; - dv.tt.is_date = is_date; - - /* FIXME: We assume it is being set to the current timezone. - Is that OK? */ - if (is_date) { - dv.zone = NULL; - } else { - dv.zone = ecd->zone; - } - - value = &dv; - } - - e_table_model_set_value_at (model, col, row, value); -} - - -static void -e_cell_date_edit_text_class_init (GtkObjectClass *object_class) -{ - ECellTextClass *ectc = (ECellTextClass *) object_class; - - parent_class = gtk_type_class (PARENT_TYPE); - - ectc->get_text = ecd_get_text; - ectc->free_text = ecd_free_text; - ectc->set_value = ecd_set_value; -} - - -static void -e_cell_date_edit_text_init (GtkObject *object) -{ - ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (object); - - ecd->zone = icaltimezone_get_utc_timezone (); - ecd->use_24_hour_format = TRUE; -} - - -/** - * e_cell_date_edit_text_new: - * - * Creates a new ECell renderer that can be used to render and edit dates that - * that come from the model. The value returned from the model is - * interpreted as being a CalComponentDateTime*. - * - * Returns: an ECell object that can be used to render dates. - */ -ECell * -e_cell_date_edit_text_new (const char *fontname, - GtkJustification justify) -{ - ECellDateEditText *ecd = g_object_new (e_cell_date_edit_text_get_type (), NULL); - - e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify); - - return (ECell *) ecd; -} - - -E_MAKE_TYPE (e_cell_date_edit_text, "ECellDateEditText", ECellDateEditText, - e_cell_date_edit_text_class_init, e_cell_date_edit_text_init, - PARENT_TYPE); diff --git a/calendar/gui/e-cell-date-edit-text.h b/calendar/gui/e-cell-date-edit-text.h deleted file mode 100644 index 2e4a768586..0000000000 --- a/calendar/gui/e-cell-date-edit-text.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * ECellDateEditText - a subclass of ECellText used to show and edit the text - * representation of the date, from a CalComponentDateTime* model value. - */ - -#ifndef _E_CELL_DATE_EDIT_TEXT_H_ -#define _E_CELL_DATE_EDIT_TEXT_H_ - -#include <ical.h> -#include <gal/e-table/e-cell-text.h> - -G_BEGIN_DECLS - -#define E_CELL_DATE_EDIT_TEXT_TYPE (e_cell_date_edit_text_get_type ()) -#define E_CELL_DATE_EDIT_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_DATE_EDIT_TEXT_TYPE, ECellDateEditText)) -#define E_CELL_DATE_EDIT_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_DATE_EDIT_TEXT_TYPE, ECellDateEditTextClass)) -#define E_IS_CELL_DATE_EDIT_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_DATE_EDIT_TEXT_TYPE)) -#define E_IS_CELL_DATE_EDIT_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_DATE_EDIT_TEXT_TYPE)) - -typedef struct _ECellDateEditValue ECellDateEditValue; -struct _ECellDateEditValue { - struct icaltimetype tt; - icaltimezone *zone; -}; - -typedef struct { - ECellText base; - - /* The timezone to display the date in. */ - icaltimezone *zone; - - /* Whether to display in 24-hour format. */ - gboolean use_24_hour_format; -} ECellDateEditText; - -typedef struct { - ECellTextClass parent_class; -} ECellDateEditTextClass; - -GtkType e_cell_date_edit_text_get_type (void); -ECell *e_cell_date_edit_text_new (const char *fontname, - GtkJustification justify); - - -void e_cell_date_edit_text_set_timezone (ECellDateEditText *ecd, - icaltimezone *zone); -void e_cell_date_edit_text_set_use_24_hour_format (ECellDateEditText *ecd, - gboolean use_24_hour); -G_END_DECLS - -#endif /* _E_CELL_DATE_EDIT_TEXT_H_ */ diff --git a/calendar/gui/e-comp-editor-registry.c b/calendar/gui/e-comp-editor-registry.c deleted file mode 100644 index 1e9962c26f..0000000000 --- a/calendar/gui/e-comp-editor-registry.c +++ /dev/null @@ -1,204 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-comp-editor-registry.c - * - * Copyright (C) 2002 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gnome.h> -#include <gal/util/e-util.h> -#include "e-comp-editor-registry.h" - -struct _ECompEditorRegistryPrivate { - GHashTable *editors; -}; - -struct _ECompEditorRegistryData -{ - CompEditor *editor; - char *uid; -}; - -typedef struct _ECompEditorRegistryData ECompEditorRegistryData; -typedef struct _ECompEditorRegistryForeachData ECompEditorRegistryForeachData; - -static GtkObjectClass *parent_class = NULL; - -static void editor_destroy_cb (GtkWidget *widget, gpointer data); - -static void -destroy (GtkObject *obj) -{ - ECompEditorRegistry *reg; - ECompEditorRegistryPrivate *priv; - - reg = E_COMP_EDITOR_REGISTRY (obj); - priv = reg->priv; - - g_hash_table_destroy (priv->editors); - - g_free (priv); -} - -static void -class_init (ECompEditorRegistryClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->destroy = destroy; -} - -static void -init (ECompEditorRegistry *reg) -{ - ECompEditorRegistryPrivate *priv; - - priv = g_new0 (ECompEditorRegistryPrivate, 1); - - reg->priv = priv; - - priv->editors = g_hash_table_new (g_str_hash, g_str_equal); -} - - - -E_MAKE_TYPE (e_comp_editor_registry, "ECompEditorRegistry", ECompEditorRegistry, - class_init, init, gtk_object_get_type ()); - -GtkObject * -e_comp_editor_registry_new (void) -{ - return g_object_new (E_TYPE_COMP_EDITOR_REGISTRY, NULL); -} - -void -e_comp_editor_registry_add (ECompEditorRegistry *reg, CompEditor *editor, gboolean remote) -{ - ECompEditorRegistryPrivate *priv; - ECompEditorRegistryData *rdata; - CalComponent *comp; - const char *uid; - - g_return_if_fail (reg != NULL); - g_return_if_fail (E_IS_COMP_EDITOR_REGISTRY (reg)); - g_return_if_fail (editor != NULL); - g_return_if_fail (IS_COMP_EDITOR (editor)); - - priv = reg->priv; - - comp = comp_editor_get_comp (editor); - cal_component_get_uid (comp, &uid); - - rdata = g_new0 (ECompEditorRegistryData, 1); - - rdata->editor = editor; - rdata->uid = g_strdup (uid); - g_hash_table_insert (priv->editors, rdata->uid, rdata); - - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), reg); - -} - -CompEditor * -e_comp_editor_registry_find (ECompEditorRegistry *reg, const char *uid) -{ - ECompEditorRegistryPrivate *priv; - ECompEditorRegistryData *rdata; - - g_return_val_if_fail (reg != NULL, NULL); - g_return_val_if_fail (E_IS_COMP_EDITOR_REGISTRY (reg), NULL); - g_return_val_if_fail (uid != NULL, NULL); - - priv = reg->priv; - - rdata = g_hash_table_lookup (priv->editors, uid); - if (rdata != NULL) - return rdata->editor; - - return NULL; -} - -static gboolean -foreach_close_cb (gpointer key, gpointer value, gpointer data) -{ - ECompEditorRegistryData *rdata; - - rdata = value; - - g_signal_handlers_block_matched (rdata->editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data); - - comp_editor_focus (rdata->editor); - if (!comp_editor_close (rdata->editor)) { - g_signal_handlers_unblock_matched (rdata->editor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data); - return FALSE; - } - - g_free (rdata->uid); - g_free (rdata); - - return TRUE; -} - -gboolean -e_comp_editor_registry_close_all (ECompEditorRegistry *reg) -{ - ECompEditorRegistryPrivate *priv; - - g_return_val_if_fail (reg != NULL, FALSE); - g_return_val_if_fail (E_IS_COMP_EDITOR_REGISTRY (reg), FALSE); - - priv = reg->priv; - - g_hash_table_foreach_remove (priv->editors, foreach_close_cb, reg); - if (g_hash_table_size (priv->editors) != 0) - return FALSE; - - return TRUE; -} - -static void -editor_destroy_cb (GtkWidget *widget, gpointer data) -{ - ECompEditorRegistry *reg; - ECompEditorRegistryPrivate *priv; - ECompEditorRegistryData *rdata; - CalComponent *comp; - const char *uid; - - reg = E_COMP_EDITOR_REGISTRY (data); - priv = reg->priv; - - comp = comp_editor_get_comp (COMP_EDITOR (widget)); - cal_component_get_uid (comp, &uid); - - rdata = g_hash_table_lookup (priv->editors, uid); - g_assert (rdata != NULL); - - g_hash_table_remove (priv->editors, rdata->uid); - g_free (rdata->uid); - g_free (rdata); -} - diff --git a/calendar/gui/e-comp-editor-registry.h b/calendar/gui/e-comp-editor-registry.h deleted file mode 100644 index dfcc1b21bc..0000000000 --- a/calendar/gui/e-comp-editor-registry.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-comp-editor-registry.h - * - * Copyright (C) 2002 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_COMP_EDITOR_REGISTRY_H_ -#define _E_COMP_EDITOR_REGISTRY_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <dialogs/comp-editor.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_COMP_EDITOR_REGISTRY (e_comp_editor_registry_get_type ()) -#define E_COMP_EDITOR_REGISTRY(obj) (GTK_CHECK_CAST ((obj), E_TYPE_COMP_EDITOR_REGISTRY, ECompEditorRegistry)) -#define E_COMP_EDITOR_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_COMP_EDITOR_REGISTRY, ECompEditorRegistryClass)) -#define E_IS_COMP_EDITOR_REGISTRY(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_COMP_EDITOR_REGISTRY)) -#define E_IS_COMP_EDITOR_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_COMP_EDITOR_REGISTRY)) - - -typedef struct _ECompEditorRegistry ECompEditorRegistry; -typedef struct _ECompEditorRegistryPrivate ECompEditorRegistryPrivate; -typedef struct _ECompEditorRegistryClass ECompEditorRegistryClass; - -struct _ECompEditorRegistry { - GtkObject parent; - - ECompEditorRegistryPrivate *priv; -}; - -struct _ECompEditorRegistryClass { - GtkObjectClass parent_class; -}; - -typedef void (* ECompEditorRegistryForeachFn) (CompEditor *editor, gpointer data); - - - - -GtkType e_comp_editor_registry_get_type (void); -GtkObject *e_comp_editor_registry_new (void); -void e_comp_editor_registry_add (ECompEditorRegistry *reg, - CompEditor *editor, - gboolean remote); -CompEditor *e_comp_editor_registry_find (ECompEditorRegistry *reg, - const char *uid); -gboolean e_comp_editor_registry_close_all (ECompEditorRegistry *reg); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_COMP_EDITOR_REGISTRY_H_ */ - - diff --git a/calendar/gui/e-date-time-list.c b/calendar/gui/e-date-time-list.c deleted file mode 100644 index 13bfc6df28..0000000000 --- a/calendar/gui/e-date-time-list.c +++ /dev/null @@ -1,555 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* EDateTimeList - list of calendar dates/times with GtkTreeModel interface. - * - * Copyright (C) 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - */ - -#include <string.h> -#include <gtk/gtktreemodel.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktreednd.h> -#include <glib.h> -#include <e-util/e-time-utils.h> -#include "e-date-time-list.h" -#include "cal-util/timeutil.h" -#include "calendar-config.h" - -#define G_LIST(x) ((GList *) x) -#define E_DATE_TIME_LIST_IS_SORTED(list) (E_DATE_TIME_LIST (list)->sort_column_id != -2) -#define IS_VALID_ITER(dt_list, iter) (iter!= NULL && iter->user_data != NULL && \ - dt_list->stamp == iter->stamp) - -static GType column_types [E_DATE_TIME_LIST_NUM_COLUMNS]; - -static void e_date_time_list_init (EDateTimeList *file_list); -static void e_date_time_list_class_init (EDateTimeListClass *class); -static void e_date_time_list_tree_model_init (GtkTreeModelIface *iface); -static void e_date_time_list_finalize (GObject *object); -static guint e_date_time_list_get_flags (GtkTreeModel *tree_model); -static gint e_date_time_list_get_n_columns (GtkTreeModel *tree_model); -static GType e_date_time_list_get_column_type (GtkTreeModel *tree_model, - gint index); -static gboolean e_date_time_list_get_iter (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreePath *path); -static GtkTreePath *e_date_time_list_get_path (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static void e_date_time_list_get_value (GtkTreeModel *tree_model, - GtkTreeIter *iter, - gint column, - GValue *value); -static gboolean e_date_time_list_iter_next (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gboolean e_date_time_list_iter_children (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent); -static gboolean e_date_time_list_iter_has_child (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gint e_date_time_list_iter_n_children (GtkTreeModel *tree_model, - GtkTreeIter *iter); -static gboolean e_date_time_list_iter_nth_child (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n); -static gboolean e_date_time_list_iter_parent (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *child); - -static GObjectClass *parent_class = NULL; - -GtkType -e_date_time_list_get_type (void) -{ - static GType date_time_list_type = 0; - - if (!date_time_list_type) { - static const GTypeInfo date_time_list_info = - { - sizeof (EDateTimeListClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) e_date_time_list_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EDateTimeList), - 0, - (GInstanceInitFunc) e_date_time_list_init, - }; - - static const GInterfaceInfo tree_model_info = - { - (GInterfaceInitFunc) e_date_time_list_tree_model_init, - NULL, - NULL - }; - - column_types [E_DATE_TIME_LIST_COLUMN_DESCRIPTION] = G_TYPE_STRING; - - date_time_list_type = g_type_register_static (G_TYPE_OBJECT, "EDateTimeList", - &date_time_list_info, 0); - g_type_add_interface_static (date_time_list_type, - GTK_TYPE_TREE_MODEL, - &tree_model_info); - } - - return date_time_list_type; -} - -static void -e_date_time_list_class_init (EDateTimeListClass *class) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GObjectClass*) class; - - object_class->finalize = e_date_time_list_finalize; -} - -static void -e_date_time_list_tree_model_init (GtkTreeModelIface *iface) -{ - iface->get_flags = e_date_time_list_get_flags; - iface->get_n_columns = e_date_time_list_get_n_columns; - iface->get_column_type = e_date_time_list_get_column_type; - iface->get_iter = e_date_time_list_get_iter; - iface->get_path = e_date_time_list_get_path; - iface->get_value = e_date_time_list_get_value; - iface->iter_next = e_date_time_list_iter_next; - iface->iter_children = e_date_time_list_iter_children; - iface->iter_has_child = e_date_time_list_iter_has_child; - iface->iter_n_children = e_date_time_list_iter_n_children; - iface->iter_nth_child = e_date_time_list_iter_nth_child; - iface->iter_parent = e_date_time_list_iter_parent; -} - -static void -e_date_time_list_init (EDateTimeList *date_time_list) -{ - date_time_list->stamp = g_random_int (); - date_time_list->columns_dirty = FALSE; - date_time_list->list = NULL; -} - -EDateTimeList * -e_date_time_list_new (void) -{ - EDateTimeList *date_time_list; - - date_time_list = E_DATE_TIME_LIST (g_object_new (e_date_time_list_get_type (), NULL)); - - return date_time_list; -} - -static void -all_rows_deleted (EDateTimeList *date_time_list) -{ - GtkTreePath *path; - gint i; - - if (!date_time_list->list) - return; - - path = gtk_tree_path_new (); - i = g_list_length (date_time_list->list); - gtk_tree_path_append_index (path, i); - - for ( ; i >= 0; i--) { - gtk_tree_model_row_deleted (GTK_TREE_MODEL (date_time_list), path); - gtk_tree_path_prev (path); - } - - gtk_tree_path_free (path); -} - -static void -row_deleted (EDateTimeList *date_time_list, gint n) -{ - GtkTreePath *path; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - gtk_tree_model_row_deleted (GTK_TREE_MODEL (date_time_list), path); - gtk_tree_path_free (path); -} - -static void -row_added (EDateTimeList *date_time_list, gint n) -{ - GtkTreePath *path; - GtkTreeIter iter; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (date_time_list), &iter, path)) - gtk_tree_model_row_inserted (GTK_TREE_MODEL (date_time_list), path, &iter); - - gtk_tree_path_free (path); -} - -static void -row_updated (EDateTimeList *date_time_list, gint n) -{ - GtkTreePath *path; - GtkTreeIter iter; - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, n); - - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (date_time_list), &iter, path)) - gtk_tree_model_row_changed (GTK_TREE_MODEL (date_time_list), path, &iter); - - gtk_tree_path_free (path); -} - -static void -e_date_time_list_finalize (GObject *object) -{ - EDateTimeList *date_time_list = E_DATE_TIME_LIST (object); -} - -/* Fulfill the GtkTreeModel requirements */ -static guint -e_date_time_list_get_flags (GtkTreeModel *tree_model) -{ - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), 0); - - return GTK_TREE_MODEL_LIST_ONLY; -} - -static gint -e_date_time_list_get_n_columns (GtkTreeModel *tree_model) -{ - EDateTimeList *date_time_list = (EDateTimeList *) tree_model; - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), 0); - - date_time_list->columns_dirty = TRUE; - return E_DATE_TIME_LIST_NUM_COLUMNS; -} - -static GType -e_date_time_list_get_column_type (GtkTreeModel *tree_model, - gint index) -{ - EDateTimeList *date_time_list = (EDateTimeList *) tree_model; - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), G_TYPE_INVALID); - g_return_val_if_fail (index < E_DATE_TIME_LIST_NUM_COLUMNS && - index >= 0, G_TYPE_INVALID); - - date_time_list->columns_dirty = TRUE; - return column_types [index]; -} - -const CalComponentDateTime * -e_date_time_list_get_date_time (EDateTimeList *date_time_list, GtkTreeIter *iter) -{ - g_return_val_if_fail (IS_VALID_ITER (date_time_list, iter), NULL); - - return G_LIST (iter->user_data)->data; -} - -static void -free_datetime (CalComponentDateTime *datetime) -{ - g_free (datetime->value); - if (datetime->tzid) - g_free ((gchar *) datetime->tzid); - g_free (datetime); -} - -static CalComponentDateTime * -copy_datetime (const CalComponentDateTime *datetime) -{ - CalComponentDateTime *datetime_copy; - - datetime_copy = g_new0 (CalComponentDateTime, 1); - datetime_copy->value = g_new (struct icaltimetype, 1); - *datetime_copy->value = *datetime->value; - - if (datetime->tzid) - datetime_copy->tzid = g_strdup (datetime->tzid); - - return datetime_copy; -} - -void -e_date_time_list_set_date_time (EDateTimeList *date_time_list, GtkTreeIter *iter, - const CalComponentDateTime *datetime) -{ - CalComponentDateTime *datetime_old; - - g_return_if_fail (IS_VALID_ITER (date_time_list, iter)); - - datetime_old = G_LIST (iter->user_data)->data; - free_datetime (datetime_old); - G_LIST (iter->user_data)->data = copy_datetime (datetime); - row_updated (date_time_list, g_list_position (date_time_list->list, G_LIST (iter->user_data))); -} - -void -e_date_time_list_append (EDateTimeList *date_time_list, GtkTreeIter *iter, - const CalComponentDateTime *datetime) -{ - g_return_if_fail (datetime != NULL); - - date_time_list->list = g_list_append (date_time_list->list, copy_datetime (datetime)); - row_added (date_time_list, g_list_length (date_time_list->list) - 1); - - if (iter) { - iter->user_data = g_list_last (date_time_list->list); - iter->stamp = date_time_list->stamp; - } -} - -void -e_date_time_list_remove (EDateTimeList *date_time_list, GtkTreeIter *iter) -{ - gint n; - - g_return_if_fail (IS_VALID_ITER (date_time_list, iter)); - - n = g_list_position (date_time_list->list, G_LIST (iter->user_data)); - free_datetime ((CalComponentDateTime *) G_LIST (iter->user_data)->data); - date_time_list->list = g_list_delete_link (date_time_list->list, G_LIST (iter->user_data)); - row_deleted (date_time_list, n); -} - -void -e_date_time_list_clear (EDateTimeList *date_time_list) -{ - GList *l; - - all_rows_deleted (date_time_list); - - for (l = date_time_list->list; l; l = g_list_next (l)) { - free_datetime ((CalComponentDateTime *) l->data); - } - - g_list_free (date_time_list->list); - date_time_list->list = NULL; -} - -static gboolean -e_date_time_list_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path) -{ - EDateTimeList *date_time_list = (EDateTimeList *) tree_model; - GList *l; - gint i; - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), FALSE); - g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE); - - if (!date_time_list->list) - return FALSE; - - date_time_list->columns_dirty = TRUE; - - i = gtk_tree_path_get_indices (path)[0]; - l = g_list_nth (date_time_list->list, i); - if (!l) - return FALSE; - - iter->user_data = l; - iter->stamp = date_time_list->stamp; - return TRUE; -} - -static GtkTreePath * -e_date_time_list_get_path (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - EDateTimeList *date_time_list = (EDateTimeList *) tree_model; - GtkTreePath *retval; - GList *l; - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), NULL); - g_return_val_if_fail (iter->stamp == E_DATE_TIME_LIST (tree_model)->stamp, NULL); - - l = iter->user_data; - retval = gtk_tree_path_new (); - gtk_tree_path_append_index (retval, g_list_position (date_time_list->list, l)); - return retval; -} - -/* Builds a static string out of an exception date */ -static char * -get_exception_string (CalComponentDateTime *dt) -{ - static char buf [256]; - struct tm tmp_tm; - - tmp_tm.tm_year = dt->value->year - 1900; - tmp_tm.tm_mon = dt->value->month - 1; - tmp_tm.tm_mday = dt->value->day; - tmp_tm.tm_hour = dt->value->hour; - tmp_tm.tm_min = dt->value->minute; - tmp_tm.tm_sec = dt->value->second; - tmp_tm.tm_isdst = -1; - - tmp_tm.tm_wday = time_day_of_week (dt->value->day, - dt->value->month - 1, - dt->value->year); - - e_time_format_date_and_time (&tmp_tm, calendar_config_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - - return buf; -} - -static void -e_date_time_list_get_value (GtkTreeModel *tree_model, - GtkTreeIter *iter, - gint column, - GValue *value) -{ - EDateTimeList *date_time_list = E_DATE_TIME_LIST (tree_model); - CalComponentDateTime *datetime; - GList *l; - const gchar *str; - - g_return_if_fail (E_IS_DATE_TIME_LIST (tree_model)); - g_return_if_fail (column < E_DATE_TIME_LIST_NUM_COLUMNS); - g_return_if_fail (E_DATE_TIME_LIST (tree_model)->stamp == iter->stamp); - g_return_if_fail (IS_VALID_ITER (date_time_list, iter)); - - g_value_init (value, column_types [column]); - - if (!date_time_list->list) - return; - - l = iter->user_data; - datetime = l->data; - - if (!datetime) - return; - - switch (column) { - case E_DATE_TIME_LIST_COLUMN_DESCRIPTION: - str = get_exception_string (datetime); - g_value_set_string (value, str); - break; - } -} - -static gboolean -e_date_time_list_iter_next (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - GList *l; - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), FALSE); - g_return_val_if_fail (IS_VALID_ITER (E_DATE_TIME_LIST (tree_model), iter), FALSE); - - if (!E_DATE_TIME_LIST (tree_model)->list) - return FALSE; - - l = iter->user_data; - l = g_list_next (l); - if (l) { - iter->user_data = l; - return TRUE; - } - - return FALSE; -} - -static gboolean -e_date_time_list_iter_children (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent) -{ - EDateTimeList *date_time_list = E_DATE_TIME_LIST (tree_model); - - /* this is a list, nodes have no children */ - if (parent) - return FALSE; - - /* but if parent == NULL we return the list itself as children of the - * "root" */ - - if (!date_time_list->list) - return FALSE; - - iter->stamp = E_DATE_TIME_LIST (tree_model)->stamp; - iter->user_data = date_time_list->list; - return TRUE; -} - -static gboolean -e_date_time_list_iter_has_child (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - g_return_val_if_fail (IS_VALID_ITER (E_DATE_TIME_LIST (tree_model), iter), FALSE); - return FALSE; -} - -static gint -e_date_time_list_iter_n_children (GtkTreeModel *tree_model, - GtkTreeIter *iter) -{ - EDateTimeList *date_time_list = E_DATE_TIME_LIST (tree_model); - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), -1); - g_return_val_if_fail (IS_VALID_ITER (date_time_list, iter), -1); - - if (iter == NULL) - return g_list_length (date_time_list->list); - - g_return_val_if_fail (E_DATE_TIME_LIST (tree_model)->stamp == iter->stamp, -1); - return 0; -} - -static gboolean -e_date_time_list_iter_nth_child (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n) -{ - EDateTimeList *date_time_list = E_DATE_TIME_LIST (tree_model); - - g_return_val_if_fail (E_IS_DATE_TIME_LIST (tree_model), FALSE); - - if (parent) - return FALSE; - - if (date_time_list->list) { - GList *l; - - l = g_list_nth (date_time_list->list, n); - if (!l) - return FALSE; - - iter->stamp = date_time_list->stamp; - iter->user_data = l; - return TRUE; - } - - return FALSE; -} - -static gboolean -e_date_time_list_iter_parent (GtkTreeModel *tree_model, - GtkTreeIter *iter, - GtkTreeIter *child) -{ - return FALSE; -} diff --git a/calendar/gui/e-date-time-list.h b/calendar/gui/e-date-time-list.h deleted file mode 100644 index 07a7c77b02..0000000000 --- a/calendar/gui/e-date-time-list.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* EDateTimeList - list of calendar dates/times with GtkTreeModel interface. - * - * Copyright (C) 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - */ - -#ifndef E_DATE_TIME_LIST_H -#define E_DATE_TIME_LIST_H - -#include <gtk/gtktreemodel.h> -#include <cal-util/cal-component.h> - -G_BEGIN_DECLS - -#define E_TYPE_DATE_TIME_LIST (e_date_time_list_get_type ()) -#define E_DATE_TIME_LIST(obj) (GTK_CHECK_CAST ((obj), E_TYPE_DATE_TIME_LIST, EDateTimeList)) -#define E_DATE_TIME_LIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_DATE_TIME_LIST, EDateTimeListClass)) -#define E_IS_DATE_TIME_LIST(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_DATE_TIME_LIST)) -#define E_IS_DATE_TIME_LIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_DATE_TIME_LIST)) -#define E_DATE_TIME_LIST_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), E_TYPE_DATE_TIME_LIST, EDateTimeListClass)) - -typedef struct _EDateTimeList EDateTimeList; -typedef struct _EDateTimeListClass EDateTimeListClass; - -typedef enum -{ - E_DATE_TIME_LIST_COLUMN_DESCRIPTION, - - E_DATE_TIME_LIST_NUM_COLUMNS -} -EDateTimeListColumnType; - -struct _EDateTimeList -{ - GObject parent; - - /* Private */ - - gint stamp; - GList *list; - - guint columns_dirty : 1; -}; - -struct _EDateTimeListClass -{ - GObjectClass parent_class; -}; - -GtkType e_date_time_list_get_type (void); -EDateTimeList *e_date_time_list_new (void); - -const CalComponentDateTime *e_date_time_list_get_date_time (EDateTimeList *date_time_list, - GtkTreeIter *iter); -void e_date_time_list_set_date_time (EDateTimeList *date_time_list, - GtkTreeIter *iter, - const CalComponentDateTime *datetime); -void e_date_time_list_append (EDateTimeList *date_time_list, - GtkTreeIter *iter, - const CalComponentDateTime *datetime); -void e_date_time_list_remove (EDateTimeList *date_time_list, - GtkTreeIter *iter); -void e_date_time_list_clear (EDateTimeList *date_time_list); - -G_END_DECLS - -#endif /* E_DATE_TIME_LIST_H */ diff --git a/calendar/gui/e-day-view-layout.c b/calendar/gui/e-day-view-layout.c deleted file mode 100644 index ba843b828c..0000000000 --- a/calendar/gui/e-day-view-layout.c +++ /dev/null @@ -1,352 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * Lays out events for the Day & Work-Week views of the calendar. It is also - * used for printing. - */ - -#include <config.h> - -#include "e-day-view-layout.h" - -static void e_day_view_layout_long_event (EDayViewEvent *event, - guint8 *grid, - gint days_shown, - time_t *day_starts, - gint *rows_in_top_display); - -static void e_day_view_layout_day_event (EDayViewEvent *event, - guint8 *grid, - guint16 *group_starts, - gint8 *cols_per_row, - gint rows, - gint mins_per_row); -static void e_day_view_expand_day_event (EDayViewEvent *event, - guint8 *grid, - gint8 *cols_per_row, - gint mins_per_row); -static void e_day_view_recalc_cols_per_row (gint rows, - gint8 *cols_per_row, - guint16 *group_starts); - - -void -e_day_view_layout_long_events (GArray *events, - gint days_shown, - time_t *day_starts, - gint *rows_in_top_display) -{ - EDayViewEvent *event; - gint event_num; - guint8 *grid; - - /* This is a temporary 2-d grid which is used to place events. - Each element is 0 if the position is empty, or 1 if occupied. - We allocate the maximum size possible here, assuming that each - event will need its own row. */ - grid = g_new0 (guint8, events->len * E_DAY_VIEW_MAX_DAYS); - - /* Reset the number of rows in the top display to 0. It will be - updated as events are layed out below. */ - *rows_in_top_display = 0; - - /* Iterate over the events, finding which days they cover, and putting - them in the first free row available. */ - for (event_num = 0; event_num < events->len; event_num++) { - event = &g_array_index (events, EDayViewEvent, event_num); - e_day_view_layout_long_event (event, grid, - days_shown, day_starts, - rows_in_top_display); - } - - /* Free the grid. */ - g_free (grid); -} - - -static void -e_day_view_layout_long_event (EDayViewEvent *event, - guint8 *grid, - gint days_shown, - time_t *day_starts, - gint *rows_in_top_display) -{ - gint start_day, end_day, free_row, day, row; - - event->num_columns = 0; - - if (!e_day_view_find_long_event_days (event, - days_shown, day_starts, - &start_day, &end_day)) - return; - - /* Try each row until we find a free one. */ - row = 0; - do { - free_row = row; - for (day = start_day; day <= end_day; day++) { - if (grid[row * E_DAY_VIEW_MAX_DAYS + day]) { - free_row = -1; - break; - } - } - row++; - } while (free_row == -1); - - event->start_row_or_col = free_row; - event->num_columns = 1; - - /* Mark the cells as full. */ - for (day = start_day; day <= end_day; day++) { - grid[free_row * E_DAY_VIEW_MAX_DAYS + day] = 1; - } - - /* Update the number of rows in the top canvas if necessary. */ - *rows_in_top_display = MAX (*rows_in_top_display, free_row + 1); -} - - -void -e_day_view_layout_day_events (GArray *events, - gint rows, - gint mins_per_row, - gint8 *cols_per_row) -{ - EDayViewEvent *event; - gint row, event_num; - guint8 *grid; - - /* This is a temporary array which keeps track of rows which are - connected. When an appointment spans multiple rows then the number - of columns in each of these rows must be the same (i.e. the maximum - of all of them). Each element in the array corresponds to one row - and contains the index of the first row in the group of connected - rows. */ - guint16 group_starts[12 * 24]; - - /* Reset the cols_per_row array, and initialize the connected rows so - that all rows are not connected - each row is the start of a new - group. */ - for (row = 0; row < rows; row++) { - cols_per_row[row] = 0; - group_starts[row] = row; - } - - /* This is a temporary 2-d grid which is used to place events. - Each element is 0 if the position is empty, or 1 if occupied. */ - grid = g_new0 (guint8, rows * E_DAY_VIEW_MAX_COLUMNS); - - - /* Iterate over the events, finding which rows they cover, and putting - them in the first free column available. Increment the number of - events in each of the rows it covers, and make sure they are all - in one group. */ - for (event_num = 0; event_num < events->len; event_num++) { - event = &g_array_index (events, EDayViewEvent, event_num); - - e_day_view_layout_day_event (event, grid, group_starts, - cols_per_row, rows, mins_per_row); - } - - /* Recalculate the number of columns needed in each row. */ - e_day_view_recalc_cols_per_row (rows, cols_per_row, group_starts); - - /* Iterate over the events again, trying to expand events horizontally - if there is enough space. */ - for (event_num = 0; event_num < events->len; event_num++) { - event = &g_array_index (events, EDayViewEvent, event_num); - e_day_view_expand_day_event (event, grid, cols_per_row, - mins_per_row); - } - - /* Free the grid. */ - g_free (grid); -} - - -/* Finds the first free position to place the event in. - Increments the number of events in each of the rows it covers, and makes - sure they are all in one group. */ -static void -e_day_view_layout_day_event (EDayViewEvent *event, - guint8 *grid, - guint16 *group_starts, - gint8 *cols_per_row, - gint rows, - gint mins_per_row) -{ - gint start_row, end_row, free_col, col, row, group_start; - - start_row = event->start_minute / mins_per_row; - end_row = (event->end_minute - 1) / mins_per_row; - if (end_row < start_row) - end_row = start_row; - - event->num_columns = 0; - - /* If the event can't currently be seen, just return. */ - if (start_row >= rows || end_row < 0) - return; - - /* Make sure we don't go outside the visible times. */ - start_row = CLAMP (start_row, 0, rows - 1); - end_row = CLAMP (end_row, 0, rows - 1); - - /* Try each column until we find a free one. */ - for (col = 0; col < E_DAY_VIEW_MAX_COLUMNS; col++) { - free_col = col; - for (row = start_row; row <= end_row; row++) { - if (grid[row * E_DAY_VIEW_MAX_COLUMNS + col]) { - free_col = -1; - break; - } - } - - if (free_col != -1) - break; - } - - /* If we can't find space for the event, just return. */ - if (free_col == -1) - return; - - /* The event is assigned 1 col initially, but may be expanded later. */ - event->start_row_or_col = free_col; - event->num_columns = 1; - - /* Determine the start index of the group. */ - group_start = group_starts[start_row]; - - /* Increment number of events in each of the rows the event covers. - We use the cols_per_row array for this. It will be sorted out after - all the events have been layed out. Also make sure all the rows that - the event covers are in one group. */ - for (row = start_row; row <= end_row; row++) { - grid[row * E_DAY_VIEW_MAX_COLUMNS + free_col] = 1; - cols_per_row[row]++; - group_starts[row] = group_start; - } - - /* If any following rows should be in the same group, add them. */ - for (row = end_row + 1; row < rows; row++) { - if (group_starts[row] > end_row) - break; - group_starts[row] = group_start; - } -} - - -/* For each group of rows, find the max number of events in all the - rows, and set the number of cols in each of the rows to that. */ -static void -e_day_view_recalc_cols_per_row (gint rows, - gint8 *cols_per_row, - guint16 *group_starts) -{ - gint start_row = 0, row, next_start_row, max_events; - - while (start_row < rows) { - max_events = 0; - for (row = start_row; row < rows && group_starts[row] == start_row; row++) - max_events = MAX (max_events, cols_per_row[row]); - - next_start_row = row; - - for (row = start_row; row < next_start_row; row++) - cols_per_row[row] = max_events; - - start_row = next_start_row; - } -} - - -/* Expands the event horizontally to fill any free space. */ -static void -e_day_view_expand_day_event (EDayViewEvent *event, - guint8 *grid, - gint8 *cols_per_row, - gint mins_per_row) -{ - gint start_row, end_row, col, row; - gboolean clashed; - - start_row = event->start_minute / mins_per_row; - end_row = (event->end_minute - 1) / mins_per_row; - if (end_row < start_row) - end_row = start_row; - - /* Try each column until we find a free one. */ - clashed = FALSE; - for (col = event->start_row_or_col + 1; col < cols_per_row[start_row]; col++) { - for (row = start_row; row <= end_row; row++) { - if (grid[row * E_DAY_VIEW_MAX_COLUMNS + col]) { - clashed = TRUE; - break; - } - } - - if (clashed) - break; - - event->num_columns++; - } -} - - -/* Find the start and end days for the event. */ -gboolean -e_day_view_find_long_event_days (EDayViewEvent *event, - gint days_shown, - time_t *day_starts, - gint *start_day_return, - gint *end_day_return) -{ - gint day, start_day, end_day; - - start_day = -1; - end_day = -1; - - for (day = 0; day < days_shown; day++) { - if (start_day == -1 - && event->start < day_starts[day + 1]) - start_day = day; - if (event->end > day_starts[day]) - end_day = day; - } - - /* Sanity check. */ - if (start_day < 0 || start_day >= days_shown - || end_day < 0 || end_day >= days_shown - || end_day < start_day) { - g_warning ("Invalid date range for event"); - return FALSE; - } - - *start_day_return = start_day; - *end_day_return = end_day; - - return TRUE; -} - - diff --git a/calendar/gui/e-day-view-layout.h b/calendar/gui/e-day-view-layout.h deleted file mode 100644 index 70d0dd6394..0000000000 --- a/calendar/gui/e-day-view-layout.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_DAY_VIEW_LAYOUT_H_ -#define _E_DAY_VIEW_LAYOUT_H_ - -#include "e-day-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* I've split these functions away from EDayView so we can use them for - printing. */ - -void e_day_view_layout_long_events (GArray *events, - gint days_shown, - time_t *day_starts, - gint *rows_in_top_display); - - -void e_day_view_layout_day_events (GArray *events, - gint rows, - gint mins_per_row, - gint8 *cols_per_row); - -gboolean e_day_view_find_long_event_days (EDayViewEvent *event, - gint days_shown, - time_t *day_starts, - gint *start_day, - gint *end_day); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_DAY_VIEW_LAYOUT_H_ */ diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c deleted file mode 100644 index 56be20e1be..0000000000 --- a/calendar/gui/e-day-view-main-item.c +++ /dev/null @@ -1,763 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EDayViewMainItem - canvas item which displays most of the appointment - * data in the main Day/Work Week display. - */ - -#include <config.h> -#include "e-util/e-categories-config.h" -#include "e-day-view-layout.h" -#include "e-day-view-main-item.h" - -static void e_day_view_main_item_class_init (EDayViewMainItemClass *class); -static void e_day_view_main_item_init (EDayViewMainItem *dvtitem); - -static void e_day_view_main_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_day_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_day_view_main_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_day_view_main_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_day_view_main_item_event (GnomeCanvasItem *item, - GdkEvent *event); - -static void e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_day_view_main_item_draw_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, - int width, int height, - gint day); -static void e_day_view_main_item_draw_day_events (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, - int width, int height, - gint day); -static void e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, - int width, int height, - gint day, gint event_num); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_DAY_VIEW -}; - -E_MAKE_TYPE (e_day_view_main_item, "EDayViewMainItem", EDayViewMainItem, - e_day_view_main_item_class_init, e_day_view_main_item_init, GNOME_TYPE_CANVAS_ITEM); - -static void -e_day_view_main_item_class_init (EDayViewMainItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EDayViewMainItem::day_view", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_DAY_VIEW); - - object_class->set_arg = e_day_view_main_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_day_view_main_item_update; - item_class->draw = e_day_view_main_item_draw; - item_class->point = e_day_view_main_item_point; - item_class->event = e_day_view_main_item_event; -} - - -static void -e_day_view_main_item_init (EDayViewMainItem *dvtitem) -{ - dvtitem->day_view = NULL; -} - - -static void -e_day_view_main_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EDayViewMainItem *dvmitem; - - item = GNOME_CANVAS_ITEM (o); - dvmitem = E_DAY_VIEW_MAIN_ITEM (o); - - switch (arg_id){ - case ARG_DAY_VIEW: - dvmitem->day_view = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_day_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_day_view_main_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EDayViewMainItem *dvmitem; - EDayView *day_view; - GtkStyle *style; - GdkGC *gc; - gint row, row_y, grid_x1, grid_x2; - gint day, grid_y1, grid_y2; - gint work_day_start_y, work_day_end_y; - gint day_x, day_w, work_day; - gint start_row, end_row, rect_x, rect_y, rect_width, rect_height; - struct icaltimetype day_start_tt; - gint weekday; - -#if 0 - g_print ("In e_day_view_main_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - dvmitem = E_DAY_VIEW_MAIN_ITEM (canvas_item); - day_view = dvmitem->day_view; - g_return_if_fail (day_view != NULL); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - - /* Paint the background colors. */ - gc = day_view->main_gc; - work_day_start_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute) - y; - work_day_end_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_end_hour, day_view->work_day_end_minute) - y; - - for (day = 0; day < day_view->days_shown; day++) { - day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, day_view->zone); - weekday = icaltime_day_of_week (day_start_tt) - 1; - - work_day = day_view->working_days & (1 << weekday); - - day_x = day_view->day_offsets[day] - x; - day_w = day_view->day_widths[day]; - - if (work_day) { - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - gdk_draw_rectangle (drawable, gc, TRUE, - day_x, 0 - y, - day_w, work_day_start_y - (0 - y)); - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING]); - gdk_draw_rectangle (drawable, gc, TRUE, - day_x, work_day_start_y, - day_w, work_day_end_y - work_day_start_y); - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - gdk_draw_rectangle (drawable, gc, TRUE, - day_x, work_day_end_y, - day_w, height - work_day_end_y); - } else { - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING]); - gdk_draw_rectangle (drawable, gc, TRUE, - day_x, 0, - day_w, height); - } - } - - /* Paint the selection background. */ - if (day_view->selection_start_day != -1 - && !day_view->selection_in_top_canvas) { - for (day = day_view->selection_start_day; - day <= day_view->selection_end_day; - day++) { - if (day == day_view->selection_start_day - && day_view->selection_start_row != -1) - start_row = day_view->selection_start_row; - else - start_row = 0; - if (day == day_view->selection_end_day - && day_view->selection_end_row != -1) - end_row = day_view->selection_end_row; - else - end_row = day_view->rows - 1; - - rect_x = day_view->day_offsets[day] - x; - rect_width = day_view->day_widths[day]; - rect_y = start_row * day_view->row_height - y; - rect_height = (end_row - start_row + 1) * day_view->row_height; - - if (GTK_WIDGET_HAS_FOCUS(day_view)) - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED]); - else - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED]); - gdk_draw_rectangle (drawable, gc, TRUE, - rect_x, rect_y, - rect_width, rect_height); - } - } - - /* Drawing the horizontal grid lines. */ - grid_x1 = day_view->day_offsets[0] - x; - grid_x2 = day_view->day_offsets[day_view->days_shown] - x; - - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_GRID]); - for (row = 0, row_y = 0 - y; - row < day_view->rows && row_y < height; - row++, row_y += day_view->row_height) { - if (row_y >= 0 && row_y < height) - gdk_draw_line (drawable, gc, - grid_x1, row_y, grid_x2, row_y); - } - - /* Draw the vertical bars down the left of each column. */ - grid_y1 = 0; - grid_y2 = height; - for (day = 0; day < day_view->days_shown; day++) { - grid_x1 = day_view->day_offsets[day] - x; - - /* Skip if it isn't visible. */ - if (grid_x1 >= width || grid_x1 + E_DAY_VIEW_BAR_WIDTH <= 0) - continue; - - gdk_draw_line (drawable, style->black_gc, - grid_x1, grid_y1, - grid_x1, grid_y2); - gdk_draw_line (drawable, style->black_gc, - grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y1, - grid_x1 + E_DAY_VIEW_BAR_WIDTH - 1, grid_y2); - gdk_draw_rectangle (drawable, style->white_gc, TRUE, - grid_x1 + 1, grid_y1, - E_DAY_VIEW_BAR_WIDTH - 2, grid_y2 - grid_y1); - - /* Fill in the bars when the user is busy. */ - e_day_view_main_item_draw_events_in_vbars (dvmitem, drawable, - x, y, - width, height, - day); - } - - /* Fill in the vertical bars corresponding to the busy times from the - long events. */ - e_day_view_main_item_draw_long_events_in_vbars (dvmitem, drawable, - x, y, width, height); - - /* Draw the event borders and backgrounds, and the vertical bars - down the left edges. */ - for (day = 0; day < day_view->days_shown; day++) { - e_day_view_main_item_draw_day_events (dvmitem, drawable, - x, y, width, height, - day); - } -} - - -static void -e_day_view_main_item_draw_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, - int width, int height, - gint day) -{ - EDayView *day_view; - EDayViewEvent *event; - GdkGC *gc; - gint grid_x, event_num, bar_y, bar_h; - CalComponentTransparency transparency; - - day_view = dvmitem->day_view; - - gc = day_view->main_gc; - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR]); - - grid_x = day_view->day_offsets[day] + 1 - x; - - /* Draw the busy times corresponding to the events in the day. */ - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* If the event is TRANSPARENT, skip it. */ - cal_component_get_transparency (event->comp, &transparency); - if (transparency == CAL_COMPONENT_TRANSP_TRANSPARENT) - continue; - - /* We can skip the events in the first column since they will - draw over this anyway. */ - if (event->num_columns > 0 && event->start_row_or_col == 0) - continue; - - bar_y = event->start_minute * day_view->row_height / day_view->mins_per_row; - bar_h = event->end_minute * day_view->row_height / day_view->mins_per_row - bar_y; - bar_y -= y; - - /* Skip it if it isn't visible. */ - if (bar_y >= height || bar_y + bar_h <= 0) - continue; - - gdk_draw_rectangle (drawable, gc, TRUE, - grid_x, bar_y, - E_DAY_VIEW_BAR_WIDTH - 2, bar_h); - } -} - - -static void -e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, - int width, int height) -{ - EDayView *day_view; - EDayViewEvent *event; - gint event_num, start_day, end_day, day, bar_y1, bar_y2, grid_x; - GdkGC *gc; - CalComponentTransparency transparency; - - day_view = dvmitem->day_view; - - gc = day_view->main_gc; - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR]); - - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - /* If the event is TRANSPARENT, skip it. */ - cal_component_get_transparency (event->comp, &transparency); - if (transparency == CAL_COMPONENT_TRANSP_TRANSPARENT) - continue; - - if (!e_day_view_find_long_event_days (event, - day_view->days_shown, - day_view->day_starts, - &start_day, &end_day)) - continue; - - for (day = start_day; day <= end_day; day++) { - grid_x = day_view->day_offsets[day] + 1 - x; - - /* Skip if it isn't visible. */ - if (grid_x >= width - || grid_x + E_DAY_VIEW_BAR_WIDTH <= 0) - continue; - - if (event->start <= day_view->day_starts[day]) { - bar_y1 = 0; - } else { - bar_y1 = event->start_minute * day_view->row_height / day_view->mins_per_row - y; - } - - if (event->end >= day_view->day_starts[day + 1]) { - bar_y2 = height; - } else { - bar_y2 = event->end_minute * day_view->row_height / day_view->mins_per_row - y; - } - - if (bar_y1 < height && bar_y2 > 0 && bar_y2 > bar_y1) { - gdk_draw_rectangle (drawable, gc, TRUE, - grid_x, bar_y1, - E_DAY_VIEW_BAR_WIDTH - 2, - bar_y2 - bar_y1); - } - } - - - } -} - - -static void -e_day_view_main_item_draw_day_events (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, int width, int height, - gint day) -{ - EDayView *day_view; - gint event_num; - - day_view = dvmitem->day_view; - - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - e_day_view_main_item_draw_day_event (dvmitem, drawable, - x, y, width, height, - day, event_num); - } -} - - -static void -e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem, - GdkDrawable *drawable, - int x, int y, int width, int height, - gint day, gint event_num) -{ - EDayView *day_view; - EDayViewEvent *event; - gint item_x, item_y, item_w, item_h, bar_y1, bar_y2; - GtkStyle *style; - GdkGC *gc; - CalComponent *comp; - gint num_icons, icon_x, icon_y, icon_x_inc, icon_y_inc; - gint max_icon_w, max_icon_h; - gboolean draw_reminder_icon, draw_recurrence_icon, draw_timezone_icon, draw_meeting_icon; - GSList *categories_list, *elem; - CalComponentTransparency transparency; - - day_view = dvmitem->day_view; - - /* If the event is currently being dragged, don't draw it. It will - be drawn in the special drag items. */ - if (day_view->drag_event_day == day - && day_view->drag_event_num == event_num) - return; - - style = GTK_WIDGET (day_view)->style; - - gc = day_view->main_gc; - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR]); - - /* Get the position of the event. If it is not shown skip it.*/ - if (!e_day_view_get_event_position (day_view, day, event_num, - &item_x, &item_y, - &item_w, &item_h)) - return; - - item_x -= x; - item_y -= y; - - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* Fill in the white background. Note that for events in the first - column of the day, we might not want to paint over the vertical bar, - since that is used for multiple events. But then you can't see - where the event in the first column finishes. */ -#if 1 - if (event->start_row_or_col == 0) - gdk_draw_rectangle (drawable, style->white_gc, TRUE, - item_x + E_DAY_VIEW_BAR_WIDTH, item_y + 1, - MAX (item_w - E_DAY_VIEW_BAR_WIDTH - 1, 0), - item_h - 2); - else -#endif - gdk_draw_rectangle (drawable, style->white_gc, TRUE, - item_x + 1, item_y + 1, - MAX (item_w - 2, 0), item_h - 2); - - /* Draw the right edge of the vertical bar. */ - gdk_draw_line (drawable, style->black_gc, - item_x + E_DAY_VIEW_BAR_WIDTH - 1, - item_y + 1, - item_x + E_DAY_VIEW_BAR_WIDTH - 1, - item_y + item_h - 2); - - /* Draw the vertical colored bar showing when the appointment - begins & ends. */ - bar_y1 = event->start_minute * day_view->row_height / day_view->mins_per_row - y; - bar_y2 = event->end_minute * day_view->row_height / day_view->mins_per_row - y; - - /* When an item is being resized, we fill the bar up to the new row. */ - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE - && day_view->resize_event_day == day - && day_view->resize_event_num == event_num) { - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_TOP_EDGE) - bar_y1 = item_y + 1; - else if (day_view->resize_drag_pos == E_DAY_VIEW_POS_BOTTOM_EDGE) - bar_y2 = item_y + item_h - 1; - } - - /* Only fill it in if the event isn't TRANSPARENT. */ - cal_component_get_transparency (event->comp, &transparency); - if (transparency != CAL_COMPONENT_TRANSP_TRANSPARENT) { - gdk_draw_rectangle (drawable, gc, TRUE, - item_x + 1, bar_y1, - E_DAY_VIEW_BAR_WIDTH - 2, bar_y2 - bar_y1); - } - - /* Draw the box around the entire event. Do this after drawing - the colored bar so we don't have to worry about being 1 - pixel out. */ - gdk_draw_rectangle (drawable, style->black_gc, FALSE, - item_x, item_y, MAX (item_w - 1, 0), item_h - 1); - -#if 0 - /* Draw the horizontal bars above and beneath the event if it - is currently being edited. */ - if (day_view->editing_event_day == day - && day_view->editing_event_num == event_num) { - gdk_draw_rectangle (drawable, gc, TRUE, - item_x, - item_y - E_DAY_VIEW_BAR_HEIGHT, - item_w, - E_DAY_VIEW_BAR_HEIGHT); - gdk_draw_rectangle (drawable, gc, TRUE, - item_x, item_y + item_h, - item_w, E_DAY_VIEW_BAR_HEIGHT); - } -#endif - - /* Draw the reminder & recurrence icons, if needed. */ - num_icons = 0; - draw_reminder_icon = FALSE; - draw_recurrence_icon = FALSE; - draw_timezone_icon = FALSE; - draw_meeting_icon = FALSE; - icon_x = item_x + E_DAY_VIEW_BAR_WIDTH + E_DAY_VIEW_ICON_X_PAD; - icon_y = item_y + E_DAY_VIEW_EVENT_BORDER_HEIGHT - + E_DAY_VIEW_ICON_Y_PAD; - comp = event->comp; - - if (cal_component_has_alarms (comp)) { - draw_reminder_icon = TRUE; - num_icons++; - } - - if (cal_component_has_recurrences (comp)) { - draw_recurrence_icon = TRUE; - num_icons++; - } - - /* If the DTSTART or DTEND are in a different timezone to our current - timezone, we display the timezone icon. */ - if (event->different_timezone) { - draw_timezone_icon = TRUE; - num_icons++; - } - - if (cal_component_has_organizer (comp)) { - draw_meeting_icon = TRUE; - num_icons++; - } - - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (e_categories_config_get_icon_for (category, &pixmap, &mask)) - num_icons++; - } - - if (num_icons != 0) { - if (item_h >= (E_DAY_VIEW_ICON_HEIGHT + E_DAY_VIEW_ICON_Y_PAD) - * num_icons) { - icon_x_inc = 0; - icon_y_inc = E_DAY_VIEW_ICON_HEIGHT - + E_DAY_VIEW_ICON_Y_PAD; - } else { - icon_x_inc = E_DAY_VIEW_ICON_WIDTH - + E_DAY_VIEW_ICON_X_PAD; - icon_y_inc = 0; - } - - if (draw_reminder_icon) { - max_icon_w = item_x + item_w - icon_x - - E_DAY_VIEW_EVENT_BORDER_WIDTH; - max_icon_h = item_y + item_h - icon_y - - E_DAY_VIEW_EVENT_BORDER_HEIGHT; - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->reminder_mask); - gdk_draw_pixmap (drawable, gc, - day_view->reminder_icon, - 0, 0, icon_x, icon_y, - MIN (E_DAY_VIEW_ICON_WIDTH, - max_icon_w), - MIN (E_DAY_VIEW_ICON_HEIGHT, - max_icon_h)); - icon_x += icon_x_inc; - icon_y += icon_y_inc; - } - - if (draw_recurrence_icon) { - max_icon_w = item_x + item_w - icon_x - - E_DAY_VIEW_EVENT_BORDER_WIDTH; - max_icon_h = item_y + item_h - icon_y - - E_DAY_VIEW_EVENT_BORDER_HEIGHT; - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->recurrence_mask); - gdk_draw_pixmap (drawable, gc, - day_view->recurrence_icon, - 0, 0, icon_x, icon_y, - MIN (E_DAY_VIEW_ICON_WIDTH, - max_icon_w), - MIN (E_DAY_VIEW_ICON_HEIGHT, - max_icon_h)); - - icon_x += icon_x_inc; - icon_y += icon_y_inc; - } - - if (draw_timezone_icon) { - max_icon_w = item_x + item_w - icon_x - - E_DAY_VIEW_EVENT_BORDER_WIDTH; - max_icon_h = item_y + item_h - icon_y - - E_DAY_VIEW_EVENT_BORDER_HEIGHT; - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->timezone_mask); - gdk_draw_pixmap (drawable, gc, - day_view->timezone_icon, - 0, 0, icon_x, icon_y, - MIN (E_DAY_VIEW_ICON_WIDTH, - max_icon_w), - MIN (E_DAY_VIEW_ICON_HEIGHT, - max_icon_h)); - icon_x += icon_x_inc; - icon_y += icon_y_inc; - } - - - if (draw_meeting_icon) { - max_icon_w = item_x + item_w - icon_x - - E_DAY_VIEW_EVENT_BORDER_WIDTH; - max_icon_h = item_y + item_h - icon_y - - E_DAY_VIEW_EVENT_BORDER_HEIGHT; - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->meeting_mask); - gdk_draw_pixmap (drawable, gc, - day_view->meeting_icon, - 0, 0, icon_x, icon_y, - MIN (E_DAY_VIEW_ICON_WIDTH, - max_icon_w), - MIN (E_DAY_VIEW_ICON_HEIGHT, - max_icon_h)); - icon_x += icon_x_inc; - icon_y += icon_y_inc; - } - - /* draw categories icons */ - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (!e_categories_config_get_icon_for (category, &pixmap, &mask)) - continue; - - max_icon_w = item_x + item_w - icon_x - - E_DAY_VIEW_EVENT_BORDER_WIDTH; - max_icon_h = item_y + item_h - icon_y - - E_DAY_VIEW_EVENT_BORDER_HEIGHT; - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - if (mask != NULL) - gdk_gc_set_clip_mask (gc, mask); - gdk_draw_pixmap (drawable, gc, - pixmap, - 0, 0, icon_x, icon_y, - MIN (E_DAY_VIEW_ICON_WIDTH, - max_icon_w), - MIN (E_DAY_VIEW_ICON_HEIGHT, - max_icon_h)); - - gdk_pixmap_unref (pixmap); - if (mask != NULL) - gdk_bitmap_unref (mask); - - icon_x += icon_x_inc; - icon_y += icon_y_inc; - } - - gdk_gc_set_clip_mask (gc, NULL); - } - - /* free memory */ - cal_component_free_categories_list (categories_list); -} - - -/* This is supposed to return the nearest item to the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_day_view_main_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_day_view_main_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EDayViewMainItem *dvtitem; - - dvtitem = E_DAY_VIEW_MAIN_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - - case GDK_BUTTON_RELEASE: - - case GDK_MOTION_NOTIFY: - - default: - break; - } - - return FALSE; -} - - diff --git a/calendar/gui/e-day-view-main-item.h b/calendar/gui/e-day-view-main-item.h deleted file mode 100644 index be7f130606..0000000000 --- a/calendar/gui/e-day-view-main-item.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_DAY_VIEW_MAIN_ITEM_H_ -#define _E_DAY_VIEW_MAIN_ITEM_H_ - -#include "e-day-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EDayViewMainItem - canvas item which displays most of the appointment - * data in the main Day/Work Week display. - */ - -#define E_DAY_VIEW_MAIN_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_day_view_main_item_get_type (), EDayViewMainItem)) -#define E_DAY_VIEW_MAIN_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_day_view_main_item_get_type ())) -#define E_IS_DAY_VIEW_MAIN_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_day_view_main_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The parent EDayView widget. */ - EDayView *day_view; -} EDayViewMainItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EDayViewMainItemClass; - - -GtkType e_day_view_main_item_get_type (void); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_DAY_VIEW_MAIN_ITEM_H_ */ diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c deleted file mode 100644 index 544d9383cf..0000000000 --- a/calendar/gui/e-day-view-time-item.c +++ /dev/null @@ -1,671 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EDayViewTimeItem - canvas item which displays the times down the left of - * the EDayView. - */ - -#include <config.h> -#include <string.h> -#include <glib.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkradiomenuitem.h> -#include <gtk/gtkcheckmenuitem.h> -#include <libgnome/gnome-i18n.h> -#include <gal/widgets/e-gui-utils.h> -#include "e-day-view-time-item.h" -#include "calendar-config.h" - - -/* The spacing between items in the time column. GRID_X_PAD is the space down - either side of the column, i.e. outside the main horizontal grid lines. - HOUR_L_PAD & HOUR_R_PAD are the spaces on the left & right side of the - big hour number (this is inside the horizontal grid lines). - MIN_X_PAD is the spacing either side of the minute number. The smaller - horizontal grid lines match with this. - 60_MIN_X_PAD is the space either side of the HH:MM display used when - we are displaying 60 mins per row (inside the main grid lines). - LARGE_HOUR_Y_PAD is the offset of the large hour string from the top of the - row. - SMALL_FONT_Y_PAD is the offset of the small time/minute string from the top - of the row. */ -#define E_DVTMI_TIME_GRID_X_PAD 4 -#define E_DVTMI_HOUR_L_PAD 4 -#define E_DVTMI_HOUR_R_PAD 2 -#define E_DVTMI_MIN_X_PAD 2 -#define E_DVTMI_60_MIN_X_PAD 4 -#define E_DVTMI_LARGE_HOUR_Y_PAD 1 -#define E_DVTMI_SMALL_FONT_Y_PAD 1 - -static void e_day_view_time_item_class_init (EDayViewTimeItemClass *class); -static void e_day_view_time_item_init (EDayViewTimeItem *dvtmitem); -static void e_day_view_time_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); - -static void e_day_view_time_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_day_view_time_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_day_view_time_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_day_view_time_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static void e_day_view_time_item_increment_time (gint *hour, - gint *minute, - gint mins_per_row); -static void e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, - GdkEvent *event); -static void e_day_view_time_item_on_set_divisions (GtkWidget *item, - EDayViewTimeItem *dvtmitem); -static void e_day_view_time_item_on_button_press (EDayViewTimeItem *dvtmitem, - GdkEvent *event); -static void e_day_view_time_item_on_button_release (EDayViewTimeItem *dvtmitem, - GdkEvent *event); -static void e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, - GdkEvent *event); -static gint e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *dvtmitem, - gint y); - - -static GnomeCanvasItemClass *parent_class; - - -/* The arguments we take */ -enum { - ARG_0, - ARG_DAY_VIEW -}; - -E_MAKE_TYPE (e_day_view_time_item, "EDayViewTimeItem", EDayViewTimeItem, - e_day_view_time_item_class_init, e_day_view_time_item_init, GNOME_TYPE_CANVAS_ITEM); - -static void -e_day_view_time_item_class_init (EDayViewTimeItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EDayViewTimeItem::day_view", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_DAY_VIEW); - - object_class->set_arg = e_day_view_time_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_day_view_time_item_update; - item_class->draw = e_day_view_time_item_draw; - item_class->point = e_day_view_time_item_point; - item_class->event = e_day_view_time_item_event; -} - - -static void -e_day_view_time_item_init (EDayViewTimeItem *dvtmitem) -{ - dvtmitem->dragging_selection = FALSE; -} - - -static void -e_day_view_time_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EDayViewTimeItem *dvtmitem; - - item = GNOME_CANVAS_ITEM (o); - dvtmitem = E_DAY_VIEW_TIME_ITEM (o); - - switch (arg_id){ - case ARG_DAY_VIEW: - dvtmitem->day_view = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_day_view_time_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* Returns the minimum width needed for the column, by adding up all the - maximum widths of the strings. The string widths are all calculated in - the style_set handlers of EDayView and EDayViewTimeCanvas. */ -gint -e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem) -{ - EDayView *day_view; - GtkStyle *style; - gint digit, large_digit_width, max_large_digit_width = 0; - gint max_suffix_width, max_minute_or_suffix_width; - gint column_width_default, column_width_60_min_rows; - PangoContext *context; - - day_view = dvtmitem->day_view; - g_return_val_if_fail (day_view != NULL, 0); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - g_return_val_if_fail (style != NULL, 0); - - context = gtk_widget_get_pango_context (GTK_WIDGET (day_view)); - - /* Find the maximum width a digit can have. FIXME: We could use pango's - * approximation function, but I worry it won't be precise enough. Also - * it needs a language tag that I don't know where to get. */ - for (digit = '0'; digit <= '9'; digit++) { - PangoLayout *layout; - gchar digit_str [2]; - - digit_str [0] = digit; - digit_str [1] = '\0'; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), digit_str); - pango_layout_set_font_description (layout, day_view->large_font_desc); - pango_layout_get_pixel_size (layout, &large_digit_width, NULL); - g_object_unref (layout); - - max_large_digit_width = MAX (max_large_digit_width, - large_digit_width); - } - - /* Calculate the width of each time column, using the maximum of the - default format with large hour numbers, and the 60-min divisions - format which uses small text. */ - max_suffix_width = MAX (day_view->am_string_width, - day_view->pm_string_width); - - max_minute_or_suffix_width = MAX (max_suffix_width, - day_view->max_minute_width); - - column_width_default = max_large_digit_width * 2 - + max_minute_or_suffix_width - + E_DVTMI_MIN_X_PAD * 2 - + E_DVTMI_HOUR_L_PAD - + E_DVTMI_HOUR_R_PAD - + E_DVTMI_TIME_GRID_X_PAD * 2; - - column_width_60_min_rows = day_view->max_small_hour_width - + day_view->colon_width - + max_minute_or_suffix_width - + E_DVTMI_60_MIN_X_PAD * 2 - + E_DVTMI_TIME_GRID_X_PAD * 2; - - dvtmitem->column_width = MAX (column_width_default, - column_width_60_min_rows); - - return dvtmitem->column_width; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_day_view_time_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EDayView *day_view; - EDayViewTimeItem *dvtmitem; - GtkStyle *style; - GdkGC *fg_gc, *dark_gc; - gchar buffer[64], *suffix; - gint hour, display_hour, minute, row; - gint row_y, start_y, large_hour_y_offset, small_font_y_offset; - gint long_line_x1, long_line_x2, short_line_x1; - gint large_hour_x2, minute_x2; - gint hour_width, minute_width, suffix_width; - gint max_suffix_width, max_minute_or_suffix_width; - PangoLayout *layout; - PangoContext *context; - PangoFontDescription *small_font_desc; - PangoFontMetrics *large_font_metrics, *small_font_metrics; - - dvtmitem = E_DAY_VIEW_TIME_ITEM (canvas_item); - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - small_font_desc = style->font_desc; - - context = gtk_widget_get_pango_context (GTK_WIDGET (day_view)); - large_font_metrics = pango_context_get_metrics (context, day_view->large_font_desc, - pango_context_get_language (context)); - small_font_metrics = pango_context_get_metrics (context, small_font_desc, - pango_context_get_language (context)); - - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - - /* The start and end of the long horizontal line between hours. */ - long_line_x1 = E_DVTMI_TIME_GRID_X_PAD - x; - long_line_x2 = dvtmitem->column_width - E_DVTMI_TIME_GRID_X_PAD - x; - - if (day_view->mins_per_row == 60) { - /* The right edge of the complete time string in 60-min - divisions, e.g. "14:00" or "2 pm". */ - minute_x2 = long_line_x2 - E_DVTMI_60_MIN_X_PAD; - - /* These aren't used for 60-minute divisions, but we initialize - them to keep gcc happy. */ - short_line_x1 = 0; - large_hour_x2 = 0; - } else { - max_suffix_width = MAX (day_view->am_string_width, - day_view->pm_string_width); - - max_minute_or_suffix_width = MAX (max_suffix_width, - day_view->max_minute_width); - - /* The start of the short horizontal line between the periods - within each hour. */ - short_line_x1 = long_line_x2 - E_DVTMI_MIN_X_PAD * 2 - - max_minute_or_suffix_width; - - /* The right edge of the large hour string. */ - large_hour_x2 = short_line_x1 - E_DVTMI_HOUR_R_PAD; - - /* The right edge of the minute part of the time. */ - minute_x2 = long_line_x2 - E_DVTMI_MIN_X_PAD; - } - - /* Start with the first hour & minute shown in the EDayView. */ - hour = day_view->first_hour_shown; - minute = day_view->first_minute_shown; - - /* The offset of the large hour string from the top of the row. */ - large_hour_y_offset = E_DVTMI_LARGE_HOUR_Y_PAD; - - /* The offset of the small time/minute string from top of row. */ - small_font_y_offset = E_DVTMI_SMALL_FONT_Y_PAD; - - /* Calculate the minimum y position of the first row we need to draw. - This is normally one row height above the 0 position, but if we - are using the large font we may have to go back a bit further. */ - start_y = 0 - MAX (day_view->row_height, - (pango_font_metrics_get_ascent (large_font_metrics) + - pango_font_metrics_get_descent (large_font_metrics)) / PANGO_SCALE + - E_DVTMI_LARGE_HOUR_Y_PAD); - - /* Step through each row, drawing the times and the horizontal lines - between them. */ - for (row = 0, row_y = 0 - y; - row < day_view->rows && row_y < height; - row++, row_y += day_view->row_height) { - - /* If the row is above the first row we want to draw just - increment the time and skip to the next row. */ - if (row_y < start_y) { - e_day_view_time_item_increment_time (&hour, &minute, - day_view->mins_per_row); - continue; - } - - /* Calculate the actual hour number to display. For 12-hour - format we convert 0-23 to 12-11am/12-11pm. */ - e_day_view_convert_time_to_display (day_view, hour, - &display_hour, - &suffix, &suffix_width); - - if (day_view->mins_per_row == 60) { - /* 60 minute intervals - draw a long horizontal line - between hours and display as one long string, - e.g. "14:00" or "2 pm". */ - gdk_draw_line (drawable, dark_gc, - long_line_x1, row_y, - long_line_x2, row_y); - - if (day_view->use_24_hour_format) { - g_snprintf (buffer, sizeof (buffer), "%i:%02i", - display_hour, minute); - } else { - g_snprintf (buffer, sizeof (buffer), "%i %s", - display_hour, suffix); - } - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - pango_layout_get_pixel_size (layout, &minute_width, NULL); - gdk_draw_layout (drawable, fg_gc, - minute_x2 - minute_width, - row_y + small_font_y_offset, - layout); - g_object_unref (layout); - } else { - /* 5/10/15/30 minute intervals. */ - - if (minute == 0) { - /* On the hour - draw a long horizontal line - before the hour and display the hour in the - large font. */ - gdk_draw_line (drawable, dark_gc, - long_line_x1, row_y, - long_line_x2, row_y); - - g_snprintf (buffer, sizeof (buffer), "%i", - display_hour); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - pango_layout_set_font_description (layout, day_view->large_font_desc); - pango_layout_get_pixel_size (layout, &hour_width, NULL); - gdk_draw_layout (drawable, fg_gc, - large_hour_x2 - hour_width, - row_y + large_hour_y_offset, - layout); - g_object_unref (layout); - } else { - /* Within the hour - draw a short line before - the time. */ - gdk_draw_line (drawable, dark_gc, - short_line_x1, row_y, - long_line_x2, row_y); - } - - /* Normally we display the minute in each - interval, but when using 30-minute intervals - we don't display the '30'. */ - if (day_view->mins_per_row != 30 || minute != 30) { - /* In 12-hour format we display 'am' or 'pm' - instead of '00'. */ - if (minute == 0 - && !day_view->use_24_hour_format) { - strcpy (buffer, suffix); - } else { - g_snprintf (buffer, sizeof (buffer), - "%02i", minute); - } - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - pango_layout_get_pixel_size (layout, &minute_width, NULL); - gdk_draw_layout (drawable, fg_gc, - minute_x2 - minute_width, - row_y + small_font_y_offset, - layout); - g_object_unref (layout); - } - } - - e_day_view_time_item_increment_time (&hour, &minute, - day_view->mins_per_row); - } - - pango_font_metrics_unref (large_font_metrics); - pango_font_metrics_unref (small_font_metrics); -} - - -/* Increment the time by the 5/10/15/30/60 minute interval. - Note that mins_per_row is never > 60, so we never have to - worry about adding more than 60 minutes. */ -static void -e_day_view_time_item_increment_time (gint *hour, - gint *minute, - gint mins_per_row) -{ - *minute += mins_per_row; - if (*minute >= 60) { - *minute -= 60; - /* Currently we never wrap around to the next day, but - we may do if we display extra timezones. */ - *hour = (*hour + 1) % 24; - } -} - - -static double -e_day_view_time_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_day_view_time_item_event (GnomeCanvasItem *item, - GdkEvent *event) -{ - EDayViewTimeItem *dvtmitem; - - dvtmitem = E_DAY_VIEW_TIME_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - e_day_view_time_item_on_button_press (dvtmitem, event); - } else if (event->button.button == 3) { - e_day_view_time_item_show_popup_menu (dvtmitem, event); - return TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) - e_day_view_time_item_on_button_release (dvtmitem, - event); - break; - - case GDK_MOTION_NOTIFY: - e_day_view_time_item_on_motion_notify (dvtmitem, event); - break; - - default: - break; - } - - return FALSE; -} - - -static void -e_day_view_time_item_show_popup_menu (EDayViewTimeItem *dvtmitem, - GdkEvent *event) -{ - static gint divisions[] = { 60, 30, 15, 10, 5 }; - EDayView *day_view; - gint num_divisions = sizeof (divisions) / sizeof (divisions[0]); - GtkWidget *menu, *item; - gchar buffer[256]; - GSList *group = NULL; - gint current_divisions, i; - - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - current_divisions = e_day_view_get_mins_per_row (day_view); - - menu = gtk_menu_new (); - - /* Make sure the menu is destroyed when it disappears. */ - e_auto_kill_popup_menu_on_selection_done (GTK_MENU (menu)); - - for (i = 0; i < num_divisions; i++) { - g_snprintf (buffer, sizeof (buffer), - _("%02i minute divisions"), divisions[i]); - item = gtk_radio_menu_item_new_with_label (group, buffer); - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (item)); - gtk_widget_show (item); - gtk_menu_append (GTK_MENU (menu), item); - - if (current_divisions == divisions[i]) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); - - g_object_set_data (G_OBJECT (item), "divisions", - GINT_TO_POINTER (divisions[i])); - - g_signal_connect (item, "toggled", - G_CALLBACK (e_day_view_time_item_on_set_divisions), dvtmitem); - } - - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button.button, event->button.time); -} - - -static void -e_day_view_time_item_on_set_divisions (GtkWidget *item, - EDayViewTimeItem *dvtmitem) -{ - EDayView *day_view; - gint divisions; - - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item))) - return; - - divisions = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "divisions")); - e_day_view_set_mins_per_row (day_view, divisions); - calendar_config_set_time_divisions (divisions); -} - - -static void -e_day_view_time_item_on_button_press (EDayViewTimeItem *dvtmitem, - GdkEvent *event) -{ - EDayView *day_view; - GnomeCanvas *canvas; - gint row; - - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - canvas = GNOME_CANVAS_ITEM (dvtmitem)->canvas; - - row = e_day_view_time_item_convert_position_to_row (dvtmitem, - event->button.y); - - if (row == -1) - return; - - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (gdk_pointer_grab (GTK_LAYOUT (canvas)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, event->button.time) == 0) { - e_day_view_start_selection (day_view, -1, row); - dvtmitem->dragging_selection = TRUE; - } -} - - -static void -e_day_view_time_item_on_button_release (EDayViewTimeItem *dvtmitem, - GdkEvent *event) -{ - EDayView *day_view; - - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - if (dvtmitem->dragging_selection) { - gdk_pointer_ungrab (event->button.time); - e_day_view_finish_selection (day_view); - e_day_view_stop_auto_scroll (day_view); - } - - dvtmitem->dragging_selection = FALSE; -} - - -static void -e_day_view_time_item_on_motion_notify (EDayViewTimeItem *dvtmitem, - GdkEvent *event) -{ - EDayView *day_view; - GnomeCanvas *canvas; - gdouble window_y; - gint y, row; - - if (!dvtmitem->dragging_selection) - return; - - day_view = dvtmitem->day_view; - g_return_if_fail (day_view != NULL); - - canvas = GNOME_CANVAS_ITEM (dvtmitem)->canvas; - - y = event->motion.y; - row = e_day_view_time_item_convert_position_to_row (dvtmitem, y); - - if (row != -1) { - gnome_canvas_world_to_window (canvas, 0, event->motion.y, - NULL, &window_y); - e_day_view_update_selection (day_view, -1, row); - e_day_view_check_auto_scroll (day_view, -1, (gint) window_y); - } -} - - -/* Returns the row corresponding to the y position, or -1. */ -static gint -e_day_view_time_item_convert_position_to_row (EDayViewTimeItem *dvtmitem, - gint y) -{ - EDayView *day_view; - gint row; - - day_view = dvtmitem->day_view; - g_return_val_if_fail (day_view != NULL, -1); - - if (y < 0) - return -1; - - row = y / day_view->row_height; - if (row >= day_view->rows) - return -1; - - return row; -} diff --git a/calendar/gui/e-day-view-time-item.h b/calendar/gui/e-day-view-time-item.h deleted file mode 100644 index f425363c98..0000000000 --- a/calendar/gui/e-day-view-time-item.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_DAY_VIEW_TIME_ITEM_H_ -#define _E_DAY_VIEW_TIME_ITEM_H_ - -#include "e-day-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EDayViewTimeItem - canvas item which displays the times down the left of - * the EDayView. - */ - -#define E_DAY_VIEW_TIME_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_day_view_time_item_get_type (), EDayViewTimeItem)) -#define E_DAY_VIEW_TIME_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_day_view_time_item_get_type ())) -#define E_IS_DAY_VIEW_TIME_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_day_view_time_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The parent EDayView widget. */ - EDayView *day_view; - - /* The width of the time column. */ - gint column_width; - - /* TRUE if we are currently dragging the selection times. */ - gboolean dragging_selection; -} EDayViewTimeItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EDayViewTimeItemClass; - - -GtkType e_day_view_time_item_get_type (void); - - -gint e_day_view_time_item_get_column_width (EDayViewTimeItem *dvtmitem); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_DAY_VIEW_TIME_ITEM_H_ */ diff --git a/calendar/gui/e-day-view-top-item.c b/calendar/gui/e-day-view-top-item.c deleted file mode 100644 index 82f74c5c4e..0000000000 --- a/calendar/gui/e-day-view-top-item.c +++ /dev/null @@ -1,677 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EDayViewTopItem - displays the top part of the Day/Work Week calendar view. - */ - -#include <config.h> -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include "e-util/e-categories-config.h" -#include "cal-util/timeutil.h" -#include "e-day-view-top-item.h" - -static void e_day_view_top_item_class_init (EDayViewTopItemClass *class); -static void e_day_view_top_item_init (EDayViewTopItem *dvtitem); - -static void e_day_view_top_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_day_view_top_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags); -static void e_day_view_top_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, - gint event_num, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h); -static double e_day_view_top_item_point (GnomeCanvasItem *item, - double x, - double y, - int cx, - int cy, - GnomeCanvasItem **actual_item); -static gint e_day_view_top_item_event (GnomeCanvasItem *item, - GdkEvent *event); - - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_DAY_VIEW -}; - -E_MAKE_TYPE (e_day_view_top_item, "EDayViewTopItem", EDayViewTopItem, e_day_view_top_item_class_init, - e_day_view_top_item_init, GNOME_TYPE_CANVAS_ITEM); - -static void -e_day_view_top_item_class_init (EDayViewTopItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EDayViewTopItem::day_view", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_DAY_VIEW); - - object_class->set_arg = e_day_view_top_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_day_view_top_item_update; - item_class->draw = e_day_view_top_item_draw; - item_class->point = e_day_view_top_item_point; - item_class->event = e_day_view_top_item_event; -} - - -static void -e_day_view_top_item_init (EDayViewTopItem *dvtitem) -{ - dvtitem->day_view = NULL; -} - - -static void -e_day_view_top_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EDayViewTopItem *dvtitem; - - item = GNOME_CANVAS_ITEM (o); - dvtitem = E_DAY_VIEW_TOP_ITEM (o); - - switch (arg_id){ - case ARG_DAY_VIEW: - dvtitem->day_view = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_day_view_top_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_day_view_top_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EDayViewTopItem *dvtitem; - EDayView *day_view; - GtkStyle *style; - GdkGC *gc, *fg_gc, *bg_gc, *light_gc, *dark_gc; - gchar buffer[128], *format; - GdkRectangle clip_rect; - gint canvas_width, canvas_height, left_edge, day, date_width, date_x; - gint item_height, event_num; - struct tm day_start = { 0 }; - struct icaltimetype day_start_tt; - PangoLayout *layout; - -#if 0 - g_print ("In e_day_view_top_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - dvtitem = E_DAY_VIEW_TOP_ITEM (canvas_item); - day_view = dvtitem->day_view; - g_return_if_fail (day_view != NULL); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - gc = day_view->main_gc; - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - light_gc = style->light_gc[GTK_STATE_NORMAL]; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - canvas_width = GTK_WIDGET (canvas_item->canvas)->allocation.width; - canvas_height = GTK_WIDGET (canvas_item->canvas)->allocation.height; - left_edge = 0; - item_height = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - - /* Draw the shadow around the dates. */ - gdk_draw_line (drawable, light_gc, - left_edge - x, 1 - y, - canvas_width - 2 - x, 1 - y); - gdk_draw_line (drawable, light_gc, - left_edge - x, 2 - y, - left_edge - x, item_height - 2 - y); - gdk_draw_line (drawable, dark_gc, - left_edge - x, item_height - 1 - y, - canvas_width - 1 - x, item_height - 1 - y); - gdk_draw_line (drawable, dark_gc, - canvas_width - 1 - x, 1 - y, - canvas_width - 1 - x, item_height - 1 - y); - - /* Draw the background for the dates. */ - gdk_draw_rectangle (drawable, bg_gc, TRUE, - left_edge + 2 - x, 2 - y, - canvas_width - left_edge - 3, - item_height - 3); - - /* Clear the main area background. */ - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS]); - gdk_draw_rectangle (drawable, gc, TRUE, - left_edge - x, item_height - y, - canvas_width - left_edge, - canvas_height - item_height); - - /* Draw the selection background. */ - if (GTK_WIDGET_HAS_FOCUS (day_view) - && day_view->selection_start_day != -1) { - gint start_col, end_col, rect_x, rect_y, rect_w, rect_h; - - start_col = day_view->selection_start_day; - end_col = day_view->selection_end_day; - - if (end_col > start_col - || day_view->selection_start_row == -1 - || day_view->selection_end_row == -1) { - rect_x = day_view->day_offsets[start_col]; - rect_y = item_height; - rect_w = day_view->day_offsets[end_col + 1] - rect_x; - rect_h = canvas_height - 1 - rect_y; - - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED]); - gdk_draw_rectangle (drawable, gc, TRUE, - rect_x - x, rect_y - y, - rect_w, rect_h); - } - } - - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - for (day = 0; day < day_view->days_shown; day++) { - day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, day_view->zone); - day_start.tm_year = day_start_tt.year - 1900; - day_start.tm_mon = day_start_tt.month - 1; - day_start.tm_mday = day_start_tt.day; - day_start.tm_isdst = -1; - - day_start.tm_wday = time_day_of_week (day_start_tt.day, - day_start_tt.month - 1, - day_start_tt.year); - - if (day_view->date_format == E_DAY_VIEW_DATE_FULL) - /* strftime format %A = full weekday name, %d = day of month, - %B = full month name. Don't use any other specifiers. */ - format = _("%A %d %B"); - else if (day_view->date_format == E_DAY_VIEW_DATE_ABBREVIATED) - /* strftime format %a = abbreviated weekday name, %d = day of month, - %b = abbreviated month name. Don't use any other specifiers. */ - format = _("%a %d %b"); - else if (day_view->date_format == E_DAY_VIEW_DATE_NO_WEEKDAY) - /* strftime format %d = day of month, %b = abbreviated month name. - Don't use any other specifiers. */ - format = _("%d %b"); - else - format = "%d"; - - strftime (buffer, sizeof (buffer), format, &day_start); - - clip_rect.x = day_view->day_offsets[day] - x; - clip_rect.y = 2 - y; - clip_rect.width = day_view->day_widths[day]; - clip_rect.height = item_height - 2; - gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - pango_layout_get_pixel_size (layout, &date_width, NULL); - date_x = day_view->day_offsets[day] + (day_view->day_widths[day] - date_width) / 2; - - gdk_draw_layout (drawable, fg_gc, - date_x - x, - 3 - y, - layout); - g_object_unref (layout); - - gdk_gc_set_clip_rectangle (fg_gc, NULL); - - /* Draw the lines down the left and right of the date cols. */ - if (day != 0) { - gdk_draw_line (drawable, light_gc, - day_view->day_offsets[day] - x, - 4 - y, - day_view->day_offsets[day] - x, - item_height - 4 - y); - - gdk_draw_line (drawable, dark_gc, - day_view->day_offsets[day] - 1 - x, - 4 - y, - day_view->day_offsets[day] - 1 - x, - item_height - 4 - y); - } - - /* Draw the lines between each column. */ - if (day != 0) { - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID]); - gdk_draw_line (drawable, gc, - day_view->day_offsets[day] - x, - item_height - y, - day_view->day_offsets[day] - x, - canvas_height - y); - } - } - - /* Draw the long events. */ - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - e_day_view_top_item_draw_long_event (dvtitem, event_num, - drawable, - x, y, width, height); - } -} - - -/* This draws one event in the top canvas. */ -static void -e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, - gint event_num, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EDayView *day_view; - EDayViewEvent *event; - GtkStyle *style; - GdkGC *gc, *fg_gc, *bg_gc; - gint start_day, end_day; - gint item_x, item_y, item_w, item_h; - gint text_x, icon_x, icon_y, icon_x_inc; - CalComponent *comp; - gchar buffer[16]; - gint hour, display_hour, minute, offset, time_width, time_x; - gint min_end_time_x, suffix_width, max_icon_x; - gchar *suffix; - gboolean draw_start_triangle, draw_end_triangle; - GdkRectangle clip_rect; - GSList *categories_list, *elem; - PangoLayout *layout; - - day_view = dvtitem->day_view; - - /* If the event is currently being dragged, don't draw it. It will - be drawn in the special drag items. */ - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->drag_event_num == event_num) - return; - - if (!e_day_view_get_long_event_position (day_view, event_num, - &start_day, &end_day, - &item_x, &item_y, - &item_w, &item_h)) - return; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - style = gtk_widget_get_style (GTK_WIDGET (day_view)); - gc = day_view->main_gc; - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - comp = event->comp; - - /* Draw the lines across the top & bottom of the entire event. */ - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); - gdk_draw_line (drawable, gc, - item_x - x, item_y - y, - item_x + item_w - 1 - x, item_y - y); - gdk_draw_line (drawable, gc, - item_x - x, item_y + item_h - 1 - y, - item_x + item_w - 1 - x, item_y + item_h - 1 - y); - - /* Fill it in. */ - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); - gdk_draw_rectangle (drawable, gc, TRUE, - item_x - x, item_y + 1 - y, - item_w, item_h - 2); - - /* When resizing we don't draw the triangles.*/ - draw_start_triangle = TRUE; - draw_end_triangle = TRUE; - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE - && day_view->resize_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->resize_event_num == event_num) { - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_LEFT_EDGE) - draw_start_triangle = FALSE; - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_RIGHT_EDGE) - draw_end_triangle = FALSE; - } - - /* If the event starts before the first day shown, draw a triangle, - else just draw a vertical line down the left. */ - if (draw_start_triangle - && event->start < day_view->day_starts[start_day]) { - e_day_view_top_item_draw_triangle (dvtitem, drawable, - item_x - x, item_y - y, - -E_DAY_VIEW_BAR_WIDTH, - item_h); - } else { - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); - gdk_draw_line (drawable, gc, - item_x - x, item_y - y, - item_x - x, item_y + item_h - 1 - y); - } - - /* Similar for the event end. */ - if (draw_end_triangle - && event->end > day_view->day_starts[end_day + 1]) { - e_day_view_top_item_draw_triangle (dvtitem, drawable, - item_x + item_w - 1 - x, - item_y - y, - E_DAY_VIEW_BAR_WIDTH, - item_h); - } else { - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); - gdk_draw_line (drawable, gc, - item_x + item_w - 1 - x, - item_y - y, - item_x + item_w - 1 - x, - item_y + item_h - 1 - y); - } - - /* If we are editing the event we don't show the icons or the start - & end times. */ - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->editing_event_num == event_num) - return; - - /* Determine the position of the label, so we know where to place the - icons. Note that since the top canvas never scrolls we don't need - to take the scroll offset into account. It will always be 0. */ - text_x = event->canvas_item->x1; - - /* Draw the start & end times, if necessary. */ - min_end_time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; - - time_width = e_day_view_get_time_string_width (day_view); - - if (event->start > day_view->day_starts[start_day]) { - offset = day_view->first_hour_shown * 60 - + day_view->first_minute_shown + event->start_minute; - hour = offset / 60; - minute = offset % 60; - /* Calculate the actual hour number to display. For 12-hour - format we convert 0-23 to 12-11am/12-11pm. */ - e_day_view_convert_time_to_display (day_view, hour, - &display_hour, - &suffix, &suffix_width); - if (day_view->use_24_hour_format) { - g_snprintf (buffer, sizeof (buffer), "%i:%02i", - display_hour, minute); - } else { - g_snprintf (buffer, sizeof (buffer), "%i:%02i%s", - display_hour, minute, suffix); - } - - clip_rect.x = item_x - x; - clip_rect.y = item_y - y; - clip_rect.width = item_w - E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH; - clip_rect.height = item_h; - gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - - time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; - if (display_hour < 10) - time_x += day_view->digit_width; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - gdk_draw_layout (drawable, fg_gc, - time_x, - item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + - E_DAY_VIEW_LONG_EVENT_Y_PAD - y, - layout); - g_object_unref (layout); - - gdk_gc_set_clip_rectangle (fg_gc, NULL); - - min_end_time_x += time_width - + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; - } - - max_icon_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - - E_DAY_VIEW_ICON_WIDTH; - - if (event->end < day_view->day_starts[end_day + 1]) { - offset = day_view->first_hour_shown * 60 - + day_view->first_minute_shown - + event->end_minute; - hour = offset / 60; - minute = offset % 60; - time_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - time_width - E_DAY_VIEW_LONG_EVENT_TIME_X_PAD - x; - - if (time_x >= min_end_time_x) { - /* Calculate the actual hour number to display. */ - e_day_view_convert_time_to_display (day_view, hour, - &display_hour, - &suffix, - &suffix_width); - if (day_view->use_24_hour_format) { - g_snprintf (buffer, sizeof (buffer), - "%i:%02i", display_hour, minute); - } else { - g_snprintf (buffer, sizeof (buffer), - "%i:%02i%s", display_hour, minute, - suffix); - } - - if (display_hour < 10) - time_x += day_view->digit_width; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); - gdk_draw_layout (drawable, fg_gc, - time_x, - item_y + E_DAY_VIEW_LONG_EVENT_Y_PAD + 1 - y, - layout); - g_object_unref (layout); - - max_icon_x -= time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; - } - } - - /* Draw the icons. */ - icon_x_inc = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD; - icon_x = text_x - E_DAY_VIEW_LONG_EVENT_ICON_R_PAD - - icon_x_inc - x; - icon_y = item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT - + E_DAY_VIEW_ICON_Y_PAD - y; - - if (icon_x <= max_icon_x && cal_component_has_recurrences (comp)) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->recurrence_mask); - gdk_draw_pixmap (drawable, gc, - day_view->recurrence_icon, - 0, 0, icon_x, icon_y, - E_DAY_VIEW_ICON_WIDTH, - E_DAY_VIEW_ICON_HEIGHT); - icon_x -= icon_x_inc; - } - - if (icon_x <= max_icon_x && cal_component_has_alarms (comp)) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->reminder_mask); - gdk_draw_pixmap (drawable, gc, - day_view->reminder_icon, - 0, 0, icon_x, icon_y, - E_DAY_VIEW_ICON_WIDTH, - E_DAY_VIEW_ICON_HEIGHT); - icon_x -= icon_x_inc; - } - - /* draw categories icons */ - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - e_categories_config_get_icon_for (category, &pixmap, &mask); - if (pixmap == NULL) - continue; - - if (icon_x <= max_icon_x) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - if (mask != NULL) - gdk_gc_set_clip_mask (gc, mask); - gdk_draw_pixmap (drawable, gc, - pixmap, - 0, 0, icon_x, icon_y, - E_DAY_VIEW_ICON_WIDTH, - E_DAY_VIEW_ICON_HEIGHT); - icon_x -= icon_x_inc; - } - - gdk_pixmap_unref (pixmap); - if (mask != NULL) - gdk_bitmap_unref (mask); - } - - cal_component_free_categories_list (categories_list); - - gdk_gc_set_clip_mask (gc, NULL); -} - - -/* This draws a little triangle to indicate that an event extends past - the days visible on screen. */ -static void -e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h) -{ - EDayView *day_view; - GtkStyle *style; - GdkGC *gc; - GdkPoint points[3]; - gint c1, c2; - - day_view = dvtitem->day_view; - - style = GTK_WIDGET (day_view)->style; - gc = day_view->main_gc; - - points[0].x = x; - points[0].y = y; - points[1].x = x + w; - points[1].y = y + (h / 2) - 1; - points[2].x = x; - points[2].y = y + h - 1; - - /* If the height is odd we can use the same central point for both - lines. If it is even we use different end-points. */ - c1 = c2 = y + (h / 2); - if (h % 2 == 0) - c1--; - - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); - gdk_draw_polygon (drawable, gc, TRUE, points, 3); - - gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); - gdk_draw_line (drawable, gc, x, y, x + w, c1); - gdk_draw_line (drawable, gc, x, y + h - 1, x + w, c2); -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_day_view_top_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_day_view_top_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EDayViewTopItem *dvtitem; - - dvtitem = E_DAY_VIEW_TOP_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - - case GDK_BUTTON_RELEASE: - - case GDK_MOTION_NOTIFY: - - default: - break; - } - - return FALSE; -} - - diff --git a/calendar/gui/e-day-view-top-item.h b/calendar/gui/e-day-view-top-item.h deleted file mode 100644 index daeb37aca7..0000000000 --- a/calendar/gui/e-day-view-top-item.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_DAY_VIEW_TOP_ITEM_H_ -#define _E_DAY_VIEW_TOP_ITEM_H_ - -#include "e-day-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EDayViewTopItem - displays the top part of the Day/Work Week calendar view. - */ - -#define E_DAY_VIEW_TOP_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_day_view_top_item_get_type (), EDayViewTopItem)) -#define E_DAY_VIEW_TOP_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_day_view_top_item_get_type ())) -#define E_IS_DAY_VIEW_TOP_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_day_view_top_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The parent EDayView widget. */ - EDayView *day_view; -} EDayViewTopItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EDayViewTopItemClass; - - -GtkType e_day_view_top_item_get_type (void); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_DAY_VIEW_TOP_ITEM_H_ */ diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c deleted file mode 100644 index ed6cc4f5cb..0000000000 --- a/calendar/gui/e-day-view.c +++ /dev/null @@ -1,7823 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EDayView - displays the Day & Work-Week views of the calendar. - */ - -#include <config.h> - -#include "e-day-view.h" - -#include <math.h> -#include <time.h> -#include <gdk/gdkkeysyms.h> -#include <gdk/gdkx.h> -#include <gtk/gtkdnd.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtkmain.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkvscrollbar.h> -#include <gtk/gtkwindow.h> -#include <gal/e-text/e-text.h> -#include <gal/widgets/e-canvas-utils.h> -#include <gal/widgets/e-popup-menu.h> -#include <gal/widgets/e-gui-utils.h> -#include <gal/widgets/e-unicode.h> -#include <libgnomecanvas/gnome-canvas-rect-ellipse.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-exec.h> -#include <libgnome/gnome-util.h> -#include <e-util/e-categories-config.h> -#include <e-util/e-dialog-utils.h> - -#include "cal-util/timeutil.h" -#include "dialogs/delete-comp.h" -#include "dialogs/delete-error.h" -#include "dialogs/send-comp.h" -#include "dialogs/cancel-comp.h" -#include "dialogs/recur-comp.h" -#include "print.h" -#include "comp-util.h" -#include "itip-utils.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "goto.h" -#include "e-day-view-time-item.h" -#include "e-day-view-top-item.h" -#include "e-day-view-layout.h" -#include "e-day-view-main-item.h" -#include "misc.h" - -/* Images */ -#include "art/bell.xpm" -#include "art/recur.xpm" -#include "art/timezone-16.xpm" -#include "art/schedule-meeting-16.xpm" - -/* The minimum amount of space wanted on each side of the date string. */ -#define E_DAY_VIEW_DATE_X_PAD 4 - -#define E_DAY_VIEW_LARGE_FONT_PTSIZE 18 - -/* The offset from the top/bottom of the canvas before auto-scrolling starts.*/ -#define E_DAY_VIEW_AUTO_SCROLL_OFFSET 16 - -/* The time between each auto-scroll, in milliseconds. */ -#define E_DAY_VIEW_AUTO_SCROLL_TIMEOUT 50 - -/* The number of timeouts we skip before we start scrolling. */ -#define E_DAY_VIEW_AUTO_SCROLL_DELAY 5 - -/* The number of pixels the mouse has to be moved with the button down before - we start a drag. */ -#define E_DAY_VIEW_DRAG_START_OFFSET 4 - -/* The amount we scroll the main canvas when the Page Up/Down keys are pressed, - as a fraction of the page size. */ -#define E_DAY_VIEW_PAGE_STEP 0.5 - -/* The amount we scroll the main canvas when the mouse wheel buttons are - pressed, as a fraction of the page size. */ -#define E_DAY_VIEW_WHEEL_MOUSE_STEP_SIZE 0.25 - -/* The timeout before we do a layout, so we don't do a layout for each event - we get from the server. */ -#define E_DAY_VIEW_LAYOUT_TIMEOUT 100 - -/* Used for the status bar messages */ -#define EVOLUTION_CALENDAR_PROGRESS_IMAGE "evolution-calendar-mini.png" -static GdkPixbuf *progress_icon[2] = { NULL, NULL }; - -/* Signal IDs */ -enum { - SELECTION_CHANGED, - LAST_SIGNAL -}; -static guint e_day_view_signals[LAST_SIGNAL] = { 0 }; - - -/* Drag and Drop stuff. */ -enum { - TARGET_CALENDAR_EVENT, - TARGET_VCALENDAR -}; -static GtkTargetEntry target_table[] = { - { "application/x-e-calendar-event", 0, TARGET_CALENDAR_EVENT }, - { "text/x-calendar", 0, TARGET_VCALENDAR } -}; -static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); - -static void e_day_view_class_init (EDayViewClass *class); -static void e_day_view_init (EDayView *day_view); -static void e_day_view_destroy (GtkObject *object); -static void e_day_view_realize (GtkWidget *widget); -static void e_day_view_unrealize (GtkWidget *widget); -static void e_day_view_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static void e_day_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gboolean e_day_view_update_scroll_regions (EDayView *day_view); -static gint e_day_view_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_day_view_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static gint e_day_view_key_press (GtkWidget *widget, - GdkEventKey *event); -static void e_day_view_cursor_key_up_shifted (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_down_shifted (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_left_shifted (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_right_shifted (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_up (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_down (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_left (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_cursor_key_right (EDayView *day_view, - GdkEventKey *event); -static void e_day_view_ensure_rows_visible (EDayView *day_view, - gint start_row, - gint end_row); -static void e_day_view_scroll (EDayView *day_view, - gfloat pages_to_scroll); - -static gboolean e_day_view_check_if_new_event_fits (EDayView *day_view); - -static void e_day_view_on_canvas_realized (GtkWidget *widget, - EDayView *day_view); - -static gboolean e_day_view_on_top_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view); -static gboolean e_day_view_on_top_canvas_button_release (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view); -static gboolean e_day_view_on_top_canvas_motion (GtkWidget *widget, - GdkEventMotion *event, - EDayView *day_view); - -static gboolean e_day_view_on_main_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view); -static gboolean e_day_view_on_main_canvas_button_release (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view); - -static gboolean e_day_view_on_time_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view); - -static void e_day_view_update_calendar_selection_time (EDayView *day_view); -static gboolean e_day_view_on_main_canvas_motion (GtkWidget *widget, - GdkEventMotion *event, - EDayView *day_view); -static gboolean e_day_view_convert_event_coords (EDayView *day_view, - GdkEvent *event, - GdkWindow *window, - gint *x_return, - gint *y_return); -static void e_day_view_update_long_event_resize (EDayView *day_view, - gint day); -static void e_day_view_update_resize (EDayView *day_view, - gint row); -static void e_day_view_finish_long_event_resize (EDayView *day_view); -static void e_day_view_finish_resize (EDayView *day_view); -static void e_day_view_abort_resize (EDayView *day_view, - guint32 time); - - -static gboolean e_day_view_on_long_event_button_press (EDayView *day_view, - gint event_num, - GdkEventButton *event, - EDayViewPosition pos, - gint event_x, - gint event_y); -static gboolean e_day_view_on_event_button_press (EDayView *day_view, - gint day, - gint event_num, - GdkEventButton *event, - EDayViewPosition pos, - gint event_x, - gint event_y); -static void e_day_view_on_long_event_click (EDayView *day_view, - gint event_num, - GdkEventButton *bevent, - EDayViewPosition pos, - gint event_x, - gint event_y); -static void e_day_view_on_event_click (EDayView *day_view, - gint day, - gint event_num, - GdkEventButton *event, - EDayViewPosition pos, - gint event_x, - gint event_y); -static void e_day_view_on_event_double_click (EDayView *day_view, - gint day, - gint event_num); -static void e_day_view_on_event_right_click (EDayView *day_view, - GdkEventButton *bevent, - gint day, - gint event_num); - -static void e_day_view_recalc_day_starts (EDayView *day_view, - time_t start_time); -static void e_day_view_recalc_num_rows (EDayView *day_view); -static void e_day_view_recalc_cell_sizes (EDayView *day_view); - -static EDayViewPosition e_day_view_convert_position_in_top_canvas (EDayView *day_view, - gint x, - gint y, - gint *day_return, - gint *event_num_return); -static EDayViewPosition e_day_view_convert_position_in_main_canvas (EDayView *day_view, - gint x, - gint y, - gint *day_return, - gint *row_return, - gint *event_num_return); -static gboolean e_day_view_find_event_from_item (EDayView *day_view, - GnomeCanvasItem *item, - gint *day_return, - gint *event_num_return); -static gboolean e_day_view_find_event_from_uid (EDayView *day_view, - const gchar *uid, - gint *day_return, - gint *event_num_return); - -typedef gboolean (* EDayViewForeachEventCallback) (EDayView *day_view, - gint day, - gint event_num, - gpointer data); - -static void e_day_view_foreach_event (EDayView *day_view, - EDayViewForeachEventCallback callback, - gpointer data); -static void e_day_view_foreach_event_with_uid (EDayView *day_view, - const gchar *uid, - EDayViewForeachEventCallback callback, - gpointer data); - -static void e_day_view_free_events (EDayView *day_view); -static void e_day_view_free_event_array (EDayView *day_view, - GArray *array); -static int e_day_view_add_event (CalComponent *comp, - time_t start, - time_t end, - gpointer data); -static void e_day_view_update_event_label (EDayView *day_view, - gint day, - gint event_num); -static void e_day_view_update_long_event_label (EDayView *day_view, - gint event_num); - -static void e_day_view_reshape_long_events (EDayView *day_view); -static void e_day_view_reshape_long_event (EDayView *day_view, - gint event_num); -static void e_day_view_reshape_day_events (EDayView *day_view, - gint day); -static void e_day_view_reshape_day_event (EDayView *day_view, - gint day, - gint event_num); -static void e_day_view_reshape_main_canvas_resize_bars (EDayView *day_view); -static void e_day_view_reshape_resize_long_event_rect_item (EDayView *day_view); -static void e_day_view_reshape_resize_rect_item (EDayView *day_view); - -static void e_day_view_ensure_events_sorted (EDayView *day_view); - -static void e_day_view_start_editing_event (EDayView *day_view, - gint day, - gint event_num, - gchar *initial_text); -static void e_day_view_stop_editing_event (EDayView *day_view); -static gboolean e_day_view_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EDayView *day_view); -static void e_day_view_on_editing_started (EDayView *day_view, - GnomeCanvasItem *item); -static void e_day_view_on_editing_stopped (EDayView *day_view, - GnomeCanvasItem *item); - -static time_t e_day_view_convert_grid_position_to_time (EDayView *day_view, - gint col, - gint row); -static gboolean e_day_view_convert_time_to_grid_position (EDayView *day_view, - time_t time, - gint *col, - gint *row); - -static void e_day_view_start_auto_scroll (EDayView *day_view, - gboolean scroll_up); -static gboolean e_day_view_auto_scroll_handler (gpointer data); - -static void e_day_view_on_new_appointment (GtkWidget *widget, - gpointer data); -static void e_day_view_on_new_event (GtkWidget *widget, - gpointer data); -static void e_day_view_on_new_meeting (GtkWidget *widget, - gpointer data); -static void e_day_view_on_new_task (GtkWidget *widget, - gpointer data); -static void e_day_view_on_goto_today (GtkWidget *widget, - gpointer data); -static void e_day_view_on_goto_date (GtkWidget *widget, - gpointer data); -static void e_day_view_on_edit_appointment (GtkWidget *widget, - gpointer data); -static void e_day_view_on_save_as (GtkWidget *widget, - gpointer data); -static void e_day_view_on_print (GtkWidget *widget, - gpointer data); -static void e_day_view_on_print_event (GtkWidget *widget, - gpointer data); -static void e_day_view_on_meeting (GtkWidget *widget, - gpointer data); -static void e_day_view_on_forward (GtkWidget *widget, - gpointer data); -static void e_day_view_on_publish (GtkWidget *widget, - gpointer data); -static void e_day_view_on_settings (GtkWidget *widget, - gpointer data); -static void e_day_view_on_delete_occurrence (GtkWidget *widget, - gpointer data); -static void e_day_view_on_delete_appointment (GtkWidget *widget, - gpointer data); -static void e_day_view_on_cut (GtkWidget *widget, gpointer data); -static void e_day_view_on_copy (GtkWidget *widget, gpointer data); -static void e_day_view_on_paste (GtkWidget *widget, gpointer data); -static void e_day_view_on_unrecur_appointment (GtkWidget *widget, - gpointer data); -static EDayViewEvent* e_day_view_get_popup_menu_event (EDayView *day_view); - -static gint e_day_view_on_top_canvas_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EDayView *day_view); -static void e_day_view_update_top_canvas_drag (EDayView *day_view, - gint day); -static void e_day_view_reshape_top_canvas_drag_item (EDayView *day_view); -static gint e_day_view_on_main_canvas_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EDayView *day_view); -static void e_day_view_reshape_main_canvas_drag_item (EDayView *day_view); -static void e_day_view_update_main_canvas_drag (EDayView *day_view, - gint row, - gint day); -static void e_day_view_on_top_canvas_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EDayView *day_view); -static void e_day_view_on_main_canvas_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EDayView *day_view); -static void e_day_view_on_drag_begin (GtkWidget *widget, - GdkDragContext *context, - EDayView *day_view); -static void e_day_view_on_drag_end (GtkWidget *widget, - GdkDragContext *context, - EDayView *day_view); -static void e_day_view_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EDayView *day_view); -static void e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EDayView *day_view); -static void e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EDayView *day_view); - -static gboolean e_day_view_update_event_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data); -static gboolean e_day_view_remove_event_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data); -static void e_day_view_normalize_selection (EDayView *day_view); -static gboolean e_day_view_set_show_times_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data); -static time_t e_day_view_find_work_week_start (EDayView *day_view, - time_t start_time); -static void e_day_view_recalc_work_week (EDayView *day_view); -static void e_day_view_recalc_work_week_days_shown (EDayView *day_view); -static gboolean e_day_view_set_event_font_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data); - -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EDayView *day_view); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EDayView *day_view); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EDayView *day_view); -static void invisible_destroyed (GtkWidget *invisible, EDayView *day_view); - -static void e_day_view_queue_layout (EDayView *day_view); -static void e_day_view_cancel_layout (EDayView *day_view); -static gboolean e_day_view_layout_timeout_cb (gpointer data); - - -static GtkTableClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - -E_MAKE_TYPE (e_day_view, "EDayView", EDayView, e_day_view_class_init, - e_day_view_init, GTK_TYPE_TABLE); - -static void -e_day_view_class_init (EDayViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - e_day_view_signals[SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (EDayViewClass, selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - /* Method override */ - object_class->destroy = e_day_view_destroy; - - widget_class->realize = e_day_view_realize; - widget_class->unrealize = e_day_view_unrealize; - widget_class->style_set = e_day_view_style_set; - widget_class->size_allocate = e_day_view_size_allocate; - widget_class->focus_in_event = e_day_view_focus_in; - widget_class->focus_out_event = e_day_view_focus_out; - widget_class->key_press_event = e_day_view_key_press; - - class->selection_changed = NULL; - - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - - -static void -e_day_view_init (EDayView *day_view) -{ - gint day; - GnomeCanvasGroup *canvas_group; - - GTK_WIDGET_SET_FLAGS (day_view, GTK_CAN_FOCUS); - - day_view->calendar = NULL; - day_view->client = NULL; - day_view->sexp = g_strdup ("#t"); /* match all by default */ - day_view->query = NULL; - - day_view->long_events = g_array_new (FALSE, FALSE, - sizeof (EDayViewEvent)); - day_view->long_events_sorted = TRUE; - day_view->long_events_need_layout = FALSE; - day_view->long_events_need_reshape = FALSE; - - day_view->layout_timeout_id = 0; - - for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) { - day_view->events[day] = g_array_new (FALSE, FALSE, - sizeof (EDayViewEvent)); - day_view->events_sorted[day] = TRUE; - day_view->need_layout[day] = FALSE; - day_view->need_reshape[day] = FALSE; - } - - /* These indicate that the times haven't been set. */ - day_view->lower = 0; - day_view->upper = 0; - - day_view->work_week_view = FALSE; - day_view->days_shown = 1; - - day_view->zone = NULL; - - day_view->mins_per_row = 30; - day_view->date_format = E_DAY_VIEW_DATE_FULL; - day_view->rows_in_top_display = 0; - - /* Note that these don't work yet. It would need a few fixes to the - way event->start_minute and event->end_minute are used, and there - may be problems with events that go outside the visible times. */ - day_view->first_hour_shown = 0; - day_view->first_minute_shown = 0; - day_view->last_hour_shown = 24; - day_view->last_minute_shown = 0; - - day_view->main_gc = NULL; - e_day_view_recalc_num_rows (day_view); - - day_view->working_days = E_DAY_VIEW_MONDAY | E_DAY_VIEW_TUESDAY - | E_DAY_VIEW_WEDNESDAY | E_DAY_VIEW_THURSDAY - | E_DAY_VIEW_FRIDAY; - - day_view->work_day_start_hour = 9; - day_view->work_day_start_minute = 0; - day_view->work_day_end_hour = 17; - day_view->work_day_end_minute = 0; - day_view->show_event_end_times = TRUE; - day_view->week_start_day = 0; - day_view->scroll_to_work_day = TRUE; - - day_view->editing_event_day = -1; - day_view->editing_event_num = -1; - - day_view->resize_bars_event_day = -1; - day_view->resize_bars_event_num = -1; - - day_view->selection_start_row = -1; - day_view->selection_start_day = -1; - day_view->selection_end_row = -1; - day_view->selection_end_day = -1; - day_view->selection_is_being_dragged = FALSE; - day_view->selection_drag_pos = E_DAY_VIEW_DRAG_END; - day_view->selection_in_top_canvas = FALSE; - - day_view->resize_drag_pos = E_DAY_VIEW_POS_NONE; - - day_view->pressed_event_day = -1; - - day_view->drag_event_day = -1; - day_view->drag_last_day = -1; - - day_view->auto_scroll_timeout_id = 0; - - day_view->default_category = NULL; - - day_view->large_font_desc = NULL; - - /* String to use in 12-hour time format for times in the morning. */ - day_view->am_string = _("am"); - - /* String to use in 12-hour time format for times in the afternoon. */ - day_view->pm_string = _("pm"); - - - /* - * Top Canvas - */ - day_view->top_canvas = e_canvas_new (); - gtk_table_attach (GTK_TABLE (day_view), day_view->top_canvas, - 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (day_view->top_canvas); - g_signal_connect_after (day_view->top_canvas, "button_press_event", - G_CALLBACK (e_day_view_on_top_canvas_button_press), day_view); - g_signal_connect_after (day_view->top_canvas, "button_release_event", - G_CALLBACK (e_day_view_on_top_canvas_button_release), day_view); - g_signal_connect_after (day_view->top_canvas, "motion_notify_event", - G_CALLBACK (e_day_view_on_top_canvas_motion), day_view); - g_signal_connect_after (day_view->top_canvas, "drag_motion", - G_CALLBACK (e_day_view_on_top_canvas_drag_motion), day_view); - g_signal_connect_after (day_view->top_canvas, "drag_leave", - G_CALLBACK (e_day_view_on_top_canvas_drag_leave), day_view); - - g_signal_connect (day_view->top_canvas, "drag_begin", - G_CALLBACK (e_day_view_on_drag_begin), day_view); - g_signal_connect (day_view->top_canvas, "drag_end", - G_CALLBACK (e_day_view_on_drag_end), day_view); - g_signal_connect (day_view->top_canvas, "drag_data_get", - G_CALLBACK (e_day_view_on_drag_data_get), day_view); - g_signal_connect (day_view->top_canvas, "drag_data_received", - G_CALLBACK (e_day_view_on_top_canvas_drag_data_received), day_view); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (day_view->top_canvas)->root); - - day_view->top_canvas_item = - gnome_canvas_item_new (canvas_group, - e_day_view_top_item_get_type (), - "EDayViewTopItem::day_view", day_view, - NULL); - - day_view->resize_long_event_rect_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type(), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->resize_long_event_rect_item); - - day_view->drag_long_event_rect_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type (), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->drag_long_event_rect_item); - - day_view->drag_long_event_item = - gnome_canvas_item_new (canvas_group, - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "line_wrap", TRUE, - "clip", TRUE, - "max_lines", 1, - "editable", TRUE, - "draw_background", FALSE, - "fill_color_rgba", GNOME_CANVAS_COLOR(0, 0, 0), - NULL); - gnome_canvas_item_hide (day_view->drag_long_event_item); - - /* - * Main Canvas - */ - day_view->main_canvas = e_canvas_new (); - gtk_table_attach (GTK_TABLE (day_view), day_view->main_canvas, - 1, 2, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (day_view->main_canvas); - g_signal_connect (day_view->main_canvas, "realize", - G_CALLBACK (e_day_view_on_canvas_realized), day_view); - - g_signal_connect_after (day_view->main_canvas, - "button_press_event", - G_CALLBACK (e_day_view_on_main_canvas_button_press), - day_view); - g_signal_connect_after (day_view->main_canvas, - "button_release_event", - G_CALLBACK (e_day_view_on_main_canvas_button_release), - day_view); - g_signal_connect_after (day_view->main_canvas, - "motion_notify_event", - G_CALLBACK (e_day_view_on_main_canvas_motion), - day_view); - g_signal_connect_after (day_view->main_canvas, - "drag_motion", - G_CALLBACK (e_day_view_on_main_canvas_drag_motion), - day_view); - g_signal_connect_after (day_view->main_canvas, - "drag_leave", - G_CALLBACK (e_day_view_on_main_canvas_drag_leave), - day_view); - - g_signal_connect (day_view->main_canvas, "drag_begin", - G_CALLBACK (e_day_view_on_drag_begin), day_view); - g_signal_connect (day_view->main_canvas, "drag_end", - G_CALLBACK (e_day_view_on_drag_end), day_view); - g_signal_connect (day_view->main_canvas, "drag_data_get", - G_CALLBACK (e_day_view_on_drag_data_get), day_view); - g_signal_connect (day_view->main_canvas, "drag_data_received", - G_CALLBACK (e_day_view_on_main_canvas_drag_data_received), day_view); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (day_view->main_canvas)->root); - - day_view->main_canvas_item = - gnome_canvas_item_new (canvas_group, - e_day_view_main_item_get_type (), - "EDayViewMainItem::day_view", day_view, - NULL); - - day_view->resize_rect_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type(), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->resize_rect_item); - - day_view->resize_bar_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type(), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->resize_bar_item); - - day_view->main_canvas_top_resize_bar_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type (), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - - day_view->main_canvas_bottom_resize_bar_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type (), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - - - day_view->drag_rect_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type (), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->drag_rect_item); - - day_view->drag_bar_item = - gnome_canvas_item_new (canvas_group, - gnome_canvas_rect_get_type (), - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (day_view->drag_bar_item); - - day_view->drag_item = - gnome_canvas_item_new (canvas_group, - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "line_wrap", TRUE, - "clip", TRUE, - "editable", TRUE, - "draw_background", FALSE, - "fill_color_rgba", GNOME_CANVAS_COLOR(0, 0, 0), - NULL); - gnome_canvas_item_hide (day_view->drag_item); - - - /* - * Times Canvas - */ - day_view->time_canvas = e_canvas_new (); - gtk_layout_set_vadjustment (GTK_LAYOUT (day_view->time_canvas), - GTK_LAYOUT (day_view->main_canvas)->vadjustment); - gtk_table_attach (GTK_TABLE (day_view), day_view->time_canvas, - 0, 1, 1, 2, - GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (day_view->time_canvas); - g_signal_connect_after (day_view->time_canvas, "button_press_event", - G_CALLBACK (e_day_view_on_time_canvas_button_press), day_view); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (day_view->time_canvas)->root); - - day_view->time_canvas_item = - gnome_canvas_item_new (canvas_group, - e_day_view_time_item_get_type (), - "EDayViewTimeItem::day_view", day_view, - NULL); - - - /* - * Scrollbar. - */ - day_view->vscrollbar = gtk_vscrollbar_new (GTK_LAYOUT (day_view->main_canvas)->vadjustment); - gtk_table_attach (GTK_TABLE (day_view), day_view->vscrollbar, - 2, 3, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (day_view->vscrollbar); - - - /* Create the cursors. */ - day_view->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR); - day_view->move_cursor = gdk_cursor_new (GDK_FLEUR); - day_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - day_view->resize_height_cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW); - day_view->last_cursor_set_in_top_canvas = NULL; - day_view->last_cursor_set_in_main_canvas = NULL; - - /* Set up the drop sites. */ - gtk_drag_dest_set (day_view->top_canvas, - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); - gtk_drag_dest_set (day_view->main_canvas, - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); - - /* Set up the invisible widget for the clipboard selections */ - day_view->invisible = gtk_invisible_new (); - gtk_selection_add_target (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - g_signal_connect (day_view->invisible, "selection_get", - G_CALLBACK (selection_get), (gpointer) day_view); - g_signal_connect (day_view->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), (gpointer) day_view); - g_signal_connect (day_view->invisible, "selection_received", - G_CALLBACK (selection_received), (gpointer) day_view); - g_signal_connect (day_view->invisible, "destroy", - G_CALLBACK (invisible_destroyed), (gpointer) day_view); - - day_view->clipboard_selection = NULL; - - day_view->activity = NULL; -} - - -/* Turn off the background of the canvas windows. This reduces flicker - considerably when scrolling. (Why isn't it in GnomeCanvas?). */ -static void -e_day_view_on_canvas_realized (GtkWidget *widget, - EDayView *day_view) -{ - gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, - NULL, FALSE); -} - - -/** - * e_day_view_new: - * @Returns: a new #EDayView. - * - * Creates a new #EDayView. - **/ -GtkWidget * -e_day_view_new (void) -{ - GtkWidget *day_view; - - day_view = GTK_WIDGET (g_object_new (e_day_view_get_type (), NULL)); - - return day_view; -} - - -static void -e_day_view_destroy (GtkObject *object) -{ - EDayView *day_view; - gint day; - - day_view = E_DAY_VIEW (object); - - e_day_view_cancel_layout (day_view); - - e_day_view_stop_auto_scroll (day_view); - - if (day_view->client) { - g_signal_handlers_disconnect_matched (day_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, day_view); - g_object_unref (day_view->client); - day_view->client = NULL; - } - - if (day_view->sexp) { - g_free (day_view->sexp); - day_view->sexp = NULL; - } - - if (day_view->query) { - g_signal_handlers_disconnect_matched (day_view->query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, day_view); - g_object_unref (day_view->query); - day_view->query = NULL; - } - - if (day_view->large_font_desc) { - pango_font_description_free (day_view->large_font_desc); - day_view->large_font_desc = NULL; - } - - if (day_view->default_category) { - g_free (day_view->default_category); - day_view->default_category = NULL; - } - - gdk_cursor_destroy (day_view->normal_cursor); - gdk_cursor_destroy (day_view->move_cursor); - gdk_cursor_destroy (day_view->resize_width_cursor); - gdk_cursor_destroy (day_view->resize_height_cursor); - - e_day_view_free_events (day_view); - g_array_free (day_view->long_events, TRUE); - day_view->long_events = NULL; - for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) { - g_array_free (day_view->events[day], TRUE); - day_view->events[day] = NULL; - } - - if (day_view->invisible) - gtk_widget_destroy (day_view->invisible); - if (day_view->clipboard_selection) { - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = NULL; - } - - if (day_view->activity) { - g_object_unref (day_view->activity); - day_view->activity = NULL; - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_day_view_realize (GtkWidget *widget) -{ - EDayView *day_view; - GdkColormap *colormap; - gboolean success[E_DAY_VIEW_COLOR_LAST]; - gint nfailed; - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (*GTK_WIDGET_CLASS (parent_class)->realize)(widget); - - day_view = E_DAY_VIEW (widget); - day_view->main_gc = gdk_gc_new (widget->window); - - colormap = gtk_widget_get_colormap (widget); - - /* Allocate the colors. */ - day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING].red = 247 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING].green = 247 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING].blue = 244 * 257; - - day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING].red = 216 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING].green = 216 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_NOT_WORKING].blue = 214 * 257; - - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED].red = 0 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED].green = 0 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED].blue = 156 * 257; - - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED].red = 16 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED].green = 78 * 257; - day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED].blue = 139 * 257; - - day_view->colors[E_DAY_VIEW_COLOR_BG_GRID].red = 0x8000; - day_view->colors[E_DAY_VIEW_COLOR_BG_GRID].green = 0x8000; - day_view->colors[E_DAY_VIEW_COLOR_BG_GRID].blue = 0x8000; - - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS].red = 0x8000; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS].green = 0x8000; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS].blue = 0x8000; - - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED].red = 65535; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED].green = 65535; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED].blue = 65535; - - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID].red = 0; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID].green = 0; - day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID].blue = 0; - - day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR].red = 0; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR].green = 0; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR].blue = 65535; - - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].red = 65535; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].green = 65535; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].blue = 65535; - - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER].red = 0; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER].green = 0; - day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER].blue = 0; - - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].red = 213 * 257; - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].green = 213 * 257; - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].blue = 213 * 257; - - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER].red = 0; - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER].green = 0; - day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER].blue = 0; - - nfailed = gdk_colormap_alloc_colors (colormap, day_view->colors, - E_DAY_VIEW_COLOR_LAST, FALSE, - TRUE, success); - if (nfailed) - g_warning ("Failed to allocate all colors"); - - - /* Create the pixmaps. */ - day_view->reminder_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &day_view->reminder_mask, NULL, bell_xpm); - day_view->recurrence_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &day_view->recurrence_mask, NULL, recur_xpm); - day_view->timezone_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &day_view->timezone_mask, NULL, timezone_16_xpm); - day_view->meeting_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &day_view->meeting_mask, NULL, schedule_meeting_16_xpm); - - - - /* Set the canvas item colors. */ - gnome_canvas_item_set (day_view->resize_long_event_rect_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - gnome_canvas_item_set (day_view->drag_long_event_rect_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - - gnome_canvas_item_set (day_view->resize_rect_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - gnome_canvas_item_set (day_view->resize_bar_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - gnome_canvas_item_set (day_view->main_canvas_top_resize_bar_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - gnome_canvas_item_set (day_view->main_canvas_bottom_resize_bar_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - - gnome_canvas_item_set (day_view->drag_rect_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); - - gnome_canvas_item_set (day_view->drag_bar_item, - "fill_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_VBAR], - "outline_color_gdk", &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BORDER], - NULL); -} - - -static void -e_day_view_unrealize (GtkWidget *widget) -{ - EDayView *day_view; - GdkColormap *colormap; - - day_view = E_DAY_VIEW (widget); - - gdk_gc_unref (day_view->main_gc); - day_view->main_gc = NULL; - - colormap = gtk_widget_get_colormap (widget); - gdk_colormap_free_colors (colormap, day_view->colors, E_DAY_VIEW_COLOR_LAST); - - gdk_pixmap_unref (day_view->reminder_icon); - day_view->reminder_icon = NULL; - gdk_pixmap_unref (day_view->recurrence_icon); - day_view->recurrence_icon = NULL; - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget); -} - - -static void -e_day_view_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EDayView *day_view; - gint top_rows, top_canvas_height; - gint hour, max_large_hour_width; - gint minute, max_minute_width, i; - gint month, day, width; - gint longest_month_width, longest_abbreviated_month_width; - gint longest_weekday_width, longest_abbreviated_weekday_width; - struct tm date_tm; - gchar buffer[128]; - gint times_width; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - (*GTK_WIDGET_CLASS (parent_class)->style_set)(widget, previous_style); - - day_view = E_DAY_VIEW (widget); - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (widget)->font_desc; - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - layout = pango_layout_new (pango_context); - - /* Create the large font. */ - if (day_view->large_font_desc != NULL) - pango_font_description_free (day_view->large_font_desc); - - day_view->large_font_desc = pango_font_description_copy (font_desc); - pango_font_description_set_size (day_view->large_font_desc, - E_DAY_VIEW_LARGE_FONT_PTSIZE * PANGO_SCALE); - - /* Recalculate the height of each row based on the font size. */ - day_view->row_height = - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + - E_DAY_VIEW_EVENT_BORDER_HEIGHT + E_DAY_VIEW_EVENT_Y_PAD * 2 + 2 /* FIXME */; - day_view->row_height = MAX (day_view->row_height, E_DAY_VIEW_ICON_HEIGHT + E_DAY_VIEW_ICON_Y_PAD + 2); - GTK_LAYOUT (day_view->main_canvas)->vadjustment->step_increment = day_view->row_height; - - day_view->top_row_height = - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + - E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT * 2 + E_DAY_VIEW_LONG_EVENT_Y_PAD * 2 + - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - day_view->top_row_height = MAX (day_view->top_row_height, E_DAY_VIEW_ICON_HEIGHT + E_DAY_VIEW_ICON_Y_PAD + 2 + E_DAY_VIEW_TOP_CANVAS_Y_GAP); - - /* Set the height of the top canvas based on the row height and the - number of rows needed (min 1 + 1 for the dates + 1 space for DnD).*/ - top_rows = MAX (1, day_view->rows_in_top_display); - top_canvas_height = (top_rows + 2) * day_view->top_row_height; - gtk_widget_set_usize (day_view->top_canvas, -1, top_canvas_height); - - /* Find the longest full & abbreviated month names. */ - memset (&date_tm, 0, sizeof (date_tm)); - date_tm.tm_year = 100; - date_tm.tm_mday = 1; - date_tm.tm_isdst = -1; - - longest_month_width = 0; - longest_abbreviated_month_width = 0; - for (month = 0; month < 12; month++) { - date_tm.tm_mon = month; - - strftime (buffer, sizeof (buffer), "%B", &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width > longest_month_width) { - longest_month_width = width; - day_view->longest_month_name = month; - } - - strftime (buffer, sizeof (buffer), "%b", &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width > longest_abbreviated_month_width) { - longest_abbreviated_month_width = width; - day_view->longest_abbreviated_month_name = month; - } - } - - /* Find the longest full & abbreviated weekday names. */ - memset (&date_tm, 0, sizeof (date_tm)); - date_tm.tm_year = 100; - date_tm.tm_mon = 0; - date_tm.tm_isdst = -1; - - longest_weekday_width = 0; - longest_abbreviated_weekday_width = 0; - for (day = 0; day < 7; day++) { - date_tm.tm_mday = 2 + day; - date_tm.tm_wday = day; - - strftime (buffer, sizeof (buffer), "%A", &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width > longest_weekday_width) { - longest_weekday_width = width; - day_view->longest_weekday_name = day; - } - - strftime (buffer, sizeof (buffer), "%a", &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width > longest_abbreviated_weekday_width) { - longest_abbreviated_weekday_width = width; - day_view->longest_abbreviated_weekday_name = day; - } - } - - - /* Calculate the widths of all the time strings necessary. */ - day_view->max_small_hour_width = 0; - max_large_hour_width = 0; - for (hour = 0; hour < 24; hour++) { - g_snprintf (buffer, sizeof (buffer), "%02i", hour); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &day_view->small_hour_widths [hour], NULL); - - day_view->max_small_hour_width = MAX (day_view->max_small_hour_width, day_view->small_hour_widths[hour]); - } - - max_minute_width = 0; - for (minute = 0, i = 0; minute < 60; minute += 5, i++) { - gint minute_width; - - g_snprintf (buffer, sizeof (buffer), "%02i", minute); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &minute_width, NULL); - - max_minute_width = MAX (max_minute_width, minute_width); - } - day_view->max_minute_width = max_minute_width; - - pango_layout_set_text (layout, ":", 1); - pango_layout_get_pixel_size (layout, &day_view->colon_width, NULL); - pango_layout_set_text (layout, "0", 1); - pango_layout_get_pixel_size (layout, &day_view->digit_width, NULL); - - pango_layout_set_text (layout, day_view->am_string, -1); - pango_layout_get_pixel_size (layout, &day_view->am_string_width, NULL); - pango_layout_set_text (layout, day_view->pm_string, -1); - pango_layout_get_pixel_size (layout, &day_view->pm_string_width, NULL); - - /* Calculate the width of the time column. */ - times_width = e_day_view_time_item_get_column_width (E_DAY_VIEW_TIME_ITEM (day_view->time_canvas_item)); - gtk_widget_set_usize (day_view->time_canvas, times_width, -1); - - g_object_unref (layout); - pango_font_metrics_unref (font_metrics); -} - - -/* This recalculates the sizes of each column. */ -static void -e_day_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EDayView *day_view; - gint day, scroll_y; - gboolean need_reshape; - gdouble old_x2, old_y2, new_x2, new_y2; - -#if 0 - g_print ("In e_day_view_size_allocate\n"); -#endif - day_view = E_DAY_VIEW (widget); - - (*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - e_day_view_recalc_cell_sizes (day_view); - - /* Set the scroll region of the top canvas to its allocated size. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (day_view->top_canvas), - NULL, NULL, &old_x2, &old_y2); - new_x2 = day_view->top_canvas->allocation.width - 1; - new_y2 = day_view->top_canvas->allocation.height - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) - gnome_canvas_set_scroll_region (GNOME_CANVAS (day_view->top_canvas), - 0, 0, new_x2, new_y2); - - need_reshape = e_day_view_update_scroll_regions (day_view); - - /* Scroll to the start of the working day, if this is the initial - allocation. */ - if (day_view->scroll_to_work_day) { - scroll_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute); - gnome_canvas_scroll_to (GNOME_CANVAS (day_view->main_canvas), - 0, scroll_y); - day_view->scroll_to_work_day = FALSE; - } - - /* Flag that we need to reshape the events. Note that changes in height - don't matter, since the rows are always the same height. */ - if (need_reshape) { - day_view->long_events_need_reshape = TRUE; - for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) - day_view->need_reshape[day] = TRUE; - - e_day_view_check_layout (day_view); - } -} - - -static void -e_day_view_recalc_cell_sizes (EDayView *day_view) -{ - /* An array of dates, one for each month in the year 2000. They must - all be Sundays. */ - static const int days[12] = { 23, 20, 19, 23, 21, 18, - 23, 20, 17, 22, 19, 24 }; - gfloat width, offset; - gint day, max_width; - struct tm date_tm; - char buffer[128]; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoLayout *layout; - gint pango_width; - - g_return_if_fail (((GtkWidget*)day_view)->style != NULL); - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (GTK_WIDGET (day_view))->font_desc; - pango_context = gtk_widget_get_pango_context (GTK_WIDGET (day_view)); - layout = pango_layout_new (pango_context); - - /* Calculate the column sizes, using floating point so that pixels - get divided evenly. Note that we use one more element than the - number of columns, to make it easy to get the column widths. */ - width = day_view->main_canvas->allocation.width; - width /= day_view->days_shown; - offset = 0; - for (day = 0; day <= day_view->days_shown; day++) { - day_view->day_offsets[day] = floor (offset + 0.5); - offset += width; - } - - /* Calculate the days widths based on the offsets. */ - for (day = 0; day < day_view->days_shown; day++) { - day_view->day_widths[day] = day_view->day_offsets[day + 1] - day_view->day_offsets[day]; - } - - /* Determine which date format to use, based on the column widths. - We want to check the widths using the longest full or abbreviated - month name and the longest full or abbreviated weekday name, as - appropriate. */ - max_width = day_view->day_widths[0]; - - memset (&date_tm, 0, sizeof (date_tm)); - date_tm.tm_year = 100; - - /* Try "Thursday 21 January". */ - date_tm.tm_mon = day_view->longest_month_name; - date_tm.tm_mday = days[date_tm.tm_mon] - + day_view->longest_weekday_name; - date_tm.tm_wday = day_view->longest_weekday_name; - date_tm.tm_isdst = -1; - /* strftime format %A = full weekday name, %d = day of month, - %B = full month name. Don't use any other specifiers. */ - strftime (buffer, sizeof (buffer), _("%A %d %B"), &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &pango_width, NULL); - - if (pango_width < max_width) { - day_view->date_format = E_DAY_VIEW_DATE_FULL; - return; - } - - /* Try "Thu 21 Jan". */ - date_tm.tm_mon = day_view->longest_abbreviated_month_name; - date_tm.tm_mday = days[date_tm.tm_mon] - + day_view->longest_abbreviated_weekday_name; - date_tm.tm_wday = day_view->longest_abbreviated_weekday_name; - date_tm.tm_isdst = -1; - /* strftime format %a = abbreviated weekday name, %d = day of month, - %b = abbreviated month name. Don't use any other specifiers. */ - strftime (buffer, sizeof (buffer), _("%a %d %b"), &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &pango_width, NULL); - - if (pango_width < max_width) { - day_view->date_format = E_DAY_VIEW_DATE_ABBREVIATED; - return; - } - - /* Try "23 Jan". */ - date_tm.tm_mon = day_view->longest_abbreviated_month_name; - date_tm.tm_mday = 23; - date_tm.tm_wday = 0; - date_tm.tm_isdst = -1; - /* strftime format %d = day of month, %b = abbreviated month name. - Don't use any other specifiers. */ - strftime (buffer, sizeof (buffer), _("%d %b"), &date_tm); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &pango_width, NULL); - - if (pango_width < max_width) - day_view->date_format = E_DAY_VIEW_DATE_NO_WEEKDAY; - else - day_view->date_format = E_DAY_VIEW_DATE_SHORT; - - g_object_unref (layout); -} - - -static gint -e_day_view_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - EDayView *day_view; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - day_view = E_DAY_VIEW (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - - return FALSE; -} - - -static gint -e_day_view_focus_out (GtkWidget *widget, GdkEventFocus *event) -{ - EDayView *day_view; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - day_view = E_DAY_VIEW (widget); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - - return FALSE; -} - - -void -e_day_view_set_calendar (EDayView *day_view, - GnomeCalendar *calendar) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - day_view->calendar = calendar; -} - - -/* Callback used when a component is updated in the live query */ -static void -query_obj_updated_cb (CalQuery *query, const char *uid, - gboolean query_in_progress, int n_scanned, int total, - gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - CalComponent *comp; - CalClientGetStatus status; - gint day, event_num; - - day_view = E_DAY_VIEW (data); - - /* If our time hasn't been set yet, just return. */ - if (day_view->lower == 0 && day_view->upper == 0) - return; - - /* Get the event from the server. */ - status = cal_client_get_object (day_view->client, uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Everything is fine */ - break; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("query_obj_updated_cb(): Syntax error when getting object `%s'", uid); - return; - - case CAL_CLIENT_GET_NOT_FOUND: - /* The object is no longer in the server, so do nothing */ - return; - - default: - g_assert_not_reached (); - return; - } - - /* If the event already exists and the dates didn't change, we can - update the event fairly easily without changing the events arrays - or computing a new layout. */ - if (e_day_view_find_event_from_uid (day_view, uid, &day, &event_num)) { - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - else - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - if (!cal_component_has_recurrences (comp) - && !cal_component_has_recurrences (event->comp) - && cal_component_event_dates_match (comp, event->comp)) { -#if 0 - g_print ("updated object's dates unchanged\n"); -#endif - e_day_view_foreach_event_with_uid (day_view, uid, e_day_view_update_event_cb, comp); - g_object_unref (comp); - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - return; - } - - /* The dates have changed, so we need to remove the - old occurrrences before adding the new ones. */ -#if 0 - g_print ("dates changed - removing occurrences\n"); -#endif - e_day_view_foreach_event_with_uid (day_view, uid, - e_day_view_remove_event_cb, - NULL); - } - - /* Add the occurrences of the event. */ - cal_recur_generate_instances (comp, day_view->lower, - day_view->upper, - e_day_view_add_event, day_view, - cal_client_resolve_tzid_cb, day_view->client, - day_view->zone); - g_object_unref (comp); - - e_day_view_queue_layout (day_view); -} - -/* Callback used when a component is removed from the live query */ -static void -query_obj_removed_cb (CalQuery *query, const char *uid, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - e_day_view_foreach_event_with_uid (day_view, uid, - e_day_view_remove_event_cb, NULL); - - e_day_view_check_layout (day_view); - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - -/* Callback used when a query ends */ -static void -query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - /* FIXME */ - - e_day_view_set_status_message (day_view, NULL); - - if (status != CAL_QUERY_DONE_SUCCESS) - fprintf (stderr, "query done: %s\n", error_str); -} - -/* Callback used when an evaluation error occurs when running a query */ -static void -query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - /* FIXME */ - - e_day_view_set_status_message (day_view, NULL); - - fprintf (stderr, "eval error: %s\n", error_str); -} - - -/* Builds a complete query sexp for the day view by adding the predicates to - * filter only for VEVENTS that fit in the day view's time range. - */ -static char * -adjust_query_sexp (EDayView *day_view, const char *sexp) -{ - char *start, *end; - char *new_sexp; - - /* If the dates have not been set yet, we just want an empty query. */ - if (day_view->lower == 0 || day_view->upper == 0) - return NULL; - - start = isodate_from_time_t (day_view->lower); - end = isodate_from_time_t (day_view->upper); - - new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")" - " (occur-in-time-range? (make-time \"%s\")" - " (make-time \"%s\"))" - " %s)", - start, end, - sexp); - - g_free (start); - g_free (end); - - return new_sexp; -} - - -/* Restarts a query for the day view */ -static void -update_query (EDayView *day_view) -{ - CalQuery *old_query; - char *real_sexp; - - e_day_view_stop_editing_event (day_view); - - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - e_day_view_free_events (day_view); - e_day_view_queue_layout (day_view); - - if (!(day_view->client - && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - old_query = day_view->query; - day_view->query = NULL; - - if (old_query) { - g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, day_view); - g_object_unref (old_query); - } - - g_assert (day_view->sexp != NULL); - - real_sexp = adjust_query_sexp (day_view, day_view->sexp); - if (!real_sexp) - return; /* No time range is set, so don't start a query */ - - e_day_view_set_status_message (day_view, _("Searching")); - day_view->query = cal_client_get_query (day_view->client, real_sexp); - g_free (real_sexp); - - if (!day_view->query) { - g_message ("update_query(): Could not create the query"); - return; - } - - g_signal_connect (day_view->query, "obj_updated", - G_CALLBACK (query_obj_updated_cb), day_view); - g_signal_connect (day_view->query, "obj_removed", - G_CALLBACK (query_obj_removed_cb), day_view); - g_signal_connect (day_view->query, "query_done", - G_CALLBACK (query_query_done_cb), day_view); - g_signal_connect (day_view->query, "eval_error", - G_CALLBACK (query_eval_error_cb), day_view); -} - -/* Callback used when the calendar client finishes opening */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; - - update_query (day_view); -} - -/** - * e_day_view_set_cal_client: - * @day_view: A day view. - * @client: A calendar client interface object. - * - * Sets the calendar client interface object that a day view will monitor. - **/ -void -e_day_view_set_cal_client (EDayView *day_view, - CalClient *client) -{ - g_return_if_fail (day_view != NULL); - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (client == day_view->client) - return; - - if (client) - g_return_if_fail (IS_CAL_CLIENT (client)); - - if (client) - g_object_ref (client); - - if (day_view->client) { - g_signal_handlers_disconnect_matched (day_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, day_view); - g_object_unref (day_view->client); - } - - day_view->client = client; - - if (day_view->client) { - if (cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED) - update_query (day_view); - else - g_signal_connect (day_view->client, "cal_opened", - G_CALLBACK (cal_opened_cb), day_view); - } -} - -/** - * e_day_view_set_query: - * @day_view: A day view. - * @sexp: S-expression that defines the query. - * - * Sets the query sexp that the day view will use for filtering the displayed - * events. - **/ -void -e_day_view_set_query (EDayView *day_view, const char *sexp) -{ - g_return_if_fail (day_view != NULL); - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - g_return_if_fail (sexp != NULL); - - if (day_view->sexp) - g_free (day_view->sexp); - - day_view->sexp = g_strdup (sexp); - - update_query (day_view); -} - - -/** - * e_day_view_set_default_category: - * @day_view: A day view. - * @category: Default category name or NULL for no category. - * - * Sets the default category that will be used when creating new calendar - * components from the day view. - **/ -void -e_day_view_set_default_category (EDayView *day_view, const char *category) -{ - g_return_if_fail (day_view != NULL); - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->default_category) - g_free (day_view->default_category); - - day_view->default_category = g_strdup (category); -} - -static gboolean -e_day_view_update_event_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data) -{ - EDayViewEvent *event; - CalComponent *comp; - - comp = data; -#if 0 - g_print ("In e_day_view_update_event_cb day:%i event_num:%i\n", - day, event_num); -#endif - if (day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - } else { - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - } - - g_object_unref (event->comp); - event->comp = comp; - g_object_ref (comp); - - if (day == E_DAY_VIEW_LONG_EVENT) { - e_day_view_update_long_event_label (day_view, event_num); - e_day_view_reshape_long_event (day_view, event_num); - } else { - e_day_view_update_event_label (day_view, day, event_num); - e_day_view_reshape_day_event (day_view, day, event_num); - } - return TRUE; -} - - -/* This calls a given function for each event instance (in both views). - If the callback returns FALSE the iteration is stopped. - Note that it is safe for the callback to remove the event (since we - step backwards through the arrays). */ -static void -e_day_view_foreach_event (EDayView *day_view, - EDayViewForeachEventCallback callback, - gpointer data) -{ - EDayViewEvent *event; - gint day, event_num; - - for (day = 0; day < day_view->days_shown; day++) { - for (event_num = day_view->events[day]->len - 1; - event_num >= 0; - event_num--) { - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - if (!(*callback) (day_view, day, event_num, data)) - return; - } - } - - for (event_num = day_view->long_events->len - 1; - event_num >= 0; - event_num--) { - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - - if (!(*callback) (day_view, E_DAY_VIEW_LONG_EVENT, event_num, - data)) - return; - } -} - - -/* This calls a given function for each event instance that matches the given - uid. If the callback returns FALSE the iteration is stopped. - Note that it is safe for the callback to remove the event (since we - step backwards through the arrays). */ -static void -e_day_view_foreach_event_with_uid (EDayView *day_view, - const gchar *uid, - EDayViewForeachEventCallback callback, - gpointer data) -{ - EDayViewEvent *event; - gint day, event_num; - const char *u; - - for (day = 0; day < day_view->days_shown; day++) { - for (event_num = day_view->events[day]->len - 1; - event_num >= 0; - event_num--) { - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - cal_component_get_uid (event->comp, &u); - if (uid && !strcmp (uid, u)) { - if (!(*callback) (day_view, day, event_num, - data)) - return; - } - } - } - - for (event_num = day_view->long_events->len - 1; - event_num >= 0; - event_num--) { - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - - cal_component_get_uid (event->comp, &u); - if (u && !strcmp (uid, u)) { - if (!(*callback) (day_view, E_DAY_VIEW_LONG_EVENT, - event_num, data)) - return; - } - } -} - - -static gboolean -e_day_view_remove_event_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data) -{ - EDayViewEvent *event; - -#if 0 - g_print ("In e_day_view_remove_event_cb day:%i event_num:%i\n", - day, event_num); -#endif - - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - else - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - /* If we were editing this event, set editing_event_day to -1 so - on_editing_stopped doesn't try to update the event. */ - if (day_view->editing_event_day == day - && day_view->editing_event_num == event_num) - day_view->editing_event_day = -1; - - if (event->canvas_item) - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - g_object_unref (event->comp); - - if (day == E_DAY_VIEW_LONG_EVENT) { - g_array_remove_index (day_view->long_events, event_num); - day_view->long_events_need_layout = TRUE; - } else { - g_array_remove_index (day_view->events[day], event_num); - day_view->need_layout[day] = TRUE; - } - return TRUE; -} - - -/* This updates the text shown for an event. If the event start or end do not - lie on a row boundary, the time is displayed before the summary. */ -static void -e_day_view_update_event_label (EDayView *day_view, - gint day, - gint event_num) -{ - EDayViewEvent *event; - char *text, *start_suffix, *end_suffix; - gboolean free_text = FALSE, editing_event = FALSE; - gint offset; - gint start_hour, start_display_hour, start_minute, start_suffix_width; - gint end_hour, end_display_hour, end_minute, end_suffix_width; - CalComponentText summary; - - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* If the event isn't visible just return. */ - if (!event->canvas_item) - return; - - cal_component_get_summary (event->comp, &summary); - text = summary.value ? (char*) summary.value : ""; - - if (day_view->editing_event_day == day - && day_view->editing_event_num == event_num) - editing_event = TRUE; - - if (!editing_event - && (event->start_minute % day_view->mins_per_row != 0 - || (day_view->show_event_end_times - && event->end_minute % day_view->mins_per_row != 0))) { - offset = day_view->first_hour_shown * 60 - + day_view->first_minute_shown; - start_minute = offset + event->start_minute; - end_minute = offset + event->end_minute; - - start_hour = start_minute / 60; - start_minute = start_minute % 60; - - end_hour = end_minute / 60; - end_minute = end_minute % 60; - - e_day_view_convert_time_to_display (day_view, start_hour, - &start_display_hour, - &start_suffix, - &start_suffix_width); - e_day_view_convert_time_to_display (day_view, end_hour, - &end_display_hour, - &end_suffix, - &end_suffix_width); - - if (day_view->use_24_hour_format) { - if (day_view->show_event_end_times) { - /* 24 hour format with end time. */ - text = g_strdup_printf - ("%2i:%02i-%2i:%02i %s", - start_display_hour, start_minute, - end_display_hour, end_minute, - text); - } else { - /* 24 hour format without end time. */ - text = g_strdup_printf - ("%2i:%02i %s", - start_display_hour, start_minute, - text); - } - } else { - if (day_view->show_event_end_times) { - /* 12 hour format with end time. */ - text = g_strdup_printf - ("%2i:%02i%s-%2i:%02i%s %s", - start_display_hour, start_minute, - start_suffix, - end_display_hour, end_minute, - end_suffix, - text); - } else { - /* 12 hour format without end time. */ - text = g_strdup_printf - ("%2i:%02i%s %s", - start_display_hour, start_minute, - start_suffix, - text); - } - } - - free_text = TRUE; - } - - gnome_canvas_item_set (event->canvas_item, - "text", text, - NULL); - - if (free_text) - g_free (text); -} - - -static void -e_day_view_update_long_event_label (EDayView *day_view, - gint event_num) -{ - EDayViewEvent *event; - CalComponentText summary; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - /* If the event isn't visible just return. */ - if (!event->canvas_item) - return; - - cal_component_get_summary (event->comp, &summary); - gnome_canvas_item_set (event->canvas_item, - "text", summary.value ? summary.value : "", - NULL); -} - - -/* Finds the day and index of the event with the given canvas item. - If is is a long event, -1 is returned as the day. - Returns TRUE if the event was found. */ -static gboolean -e_day_view_find_event_from_item (EDayView *day_view, - GnomeCanvasItem *item, - gint *day_return, - gint *event_num_return) -{ - EDayViewEvent *event; - gint day, event_num; - - for (day = 0; day < day_view->days_shown; day++) { - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - if (event->canvas_item == item) { - *day_return = day; - *event_num_return = event_num; - return TRUE; - } - } - } - - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - if (event->canvas_item == item) { - *day_return = E_DAY_VIEW_LONG_EVENT; - *event_num_return = event_num; - return TRUE; - } - } - - return FALSE; -} - - -/* Finds the day and index of the event with the given uid. - If is is a long event, E_DAY_VIEW_LONG_EVENT is returned as the day. - Returns TRUE if an event with the uid was found. - Note that for recurring events there may be several EDayViewEvents, one - for each instance, all with the same iCalObject and uid. So only use this - function if you know the event doesn't recur or you are just checking to - see if any events with the uid exist. */ -static gboolean -e_day_view_find_event_from_uid (EDayView *day_view, - const gchar *uid, - gint *day_return, - gint *event_num_return) -{ - EDayViewEvent *event; - gint day, event_num; - const char *u; - - for (day = 0; day < day_view->days_shown; day++) { - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - cal_component_get_uid (event->comp, &u); - if (u && !strcmp (uid, u)) { - *day_return = day; - *event_num_return = event_num; - return TRUE; - } - } - } - - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - - cal_component_get_uid (event->comp, &u); - if (u && !strcmp (uid, u)) { - *day_return = E_DAY_VIEW_LONG_EVENT; - *event_num_return = event_num; - return TRUE; - } - } - - return FALSE; -} - - -/* This sets the selected time range. The EDayView will show the day or week - corresponding to the start time. If the start_time & end_time are not equal - and are both visible in the view, then the selection is set to those times, - otherwise it is set to 1 hour from the start of the working day. */ -void -e_day_view_set_selected_time_range (EDayView *day_view, - time_t start_time, - time_t end_time) -{ - time_t lower; - gint start_row, start_col, end_row, end_col; - gboolean need_redraw = FALSE, start_in_grid, end_in_grid; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - /* Calculate the first day that should be shown, based on start_time - and the days_shown setting. If we are showing 1 day it is just the - start of the day given by start_time, otherwise it is the previous - work-week start day. */ - if (!day_view->work_week_view) { - lower = time_day_begin_with_zone (start_time, day_view->zone); - } else { - lower = e_day_view_find_work_week_start (day_view, start_time); - } - - /* See if we need to change the days shown. */ - if (lower != day_view->lower) { - e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); - } - - /* Set the selection. */ - start_in_grid = e_day_view_convert_time_to_grid_position (day_view, - start_time, - &start_col, - &start_row); - end_in_grid = e_day_view_convert_time_to_grid_position (day_view, - end_time - 60, - &end_col, - &end_row); - - /* If either of the times isn't in the grid, or the selection covers - an entire day, we set the selection to 1 row from the start of the - working day, in the day corresponding to the start time. */ - if (!start_in_grid || !end_in_grid - || (start_row == 0 && end_row == day_view->rows - 1)) { - end_col = start_col; - - start_row = e_day_view_convert_time_to_row (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute); - start_row = CLAMP (start_row, 0, day_view->rows - 1); - end_row = start_row; - } - - if (start_row != day_view->selection_start_row - || start_col != day_view->selection_start_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = FALSE; - day_view->selection_start_row = start_row; - day_view->selection_start_day = start_col; - } - - if (end_row != day_view->selection_end_row - || end_col != day_view->selection_end_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = FALSE; - day_view->selection_end_row = end_row; - day_view->selection_end_day = end_col; - } - - if (need_redraw) { - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - -static void -e_day_view_set_selected_time_range_in_top_visible (EDayView *day_view, - time_t start_time, - time_t end_time) -{ - gint start_row, start_col, end_row, end_col; - gboolean need_redraw = FALSE, start_in_grid, end_in_grid; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - /* Set the selection. */ - start_in_grid = e_day_view_convert_time_to_grid_position (day_view, - start_time, - &start_col, - &start_row); - end_in_grid = e_day_view_convert_time_to_grid_position (day_view, - end_time - 60, - &end_col, - &end_row); - - if (!start_in_grid) - start_col = 0; - if (!end_in_grid) - end_col = day_view->days_shown - 1; - - if (start_row != day_view->selection_start_row - || start_col != day_view->selection_start_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = TRUE; - day_view->selection_start_row = -1; - day_view->selection_start_day = start_col; - } - - if (end_row != day_view->selection_end_row - || end_col != day_view->selection_end_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = TRUE; - day_view->selection_end_row = -1; - day_view->selection_end_day = end_col; - } - - if (need_redraw) { - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - -static void -e_day_view_set_selected_time_range_visible (EDayView *day_view, - time_t start_time, - time_t end_time) -{ - gint start_row, start_col, end_row, end_col; - gboolean need_redraw = FALSE, start_in_grid, end_in_grid; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - /* Set the selection. */ - start_in_grid = e_day_view_convert_time_to_grid_position (day_view, - start_time, - &start_col, - &start_row); - end_in_grid = e_day_view_convert_time_to_grid_position (day_view, - end_time - 60, - &end_col, - &end_row); - - /* If either of the times isn't in the grid, or the selection covers - an entire day, we set the selection to 1 row from the start of the - working day, in the day corresponding to the start time. */ - if (!start_in_grid || !end_in_grid - || (start_row == 0 && end_row == day_view->rows - 1)) { - end_col = start_col; - - start_row = e_day_view_convert_time_to_row (day_view, day_view->work_day_start_hour, day_view->work_day_start_minute); - start_row = CLAMP (start_row, 0, day_view->rows - 1); - end_row = start_row; - } - - if (start_row != day_view->selection_start_row - || start_col != day_view->selection_start_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = FALSE; - day_view->selection_start_row = start_row; - day_view->selection_start_day = start_col; - } - - if (end_row != day_view->selection_end_row - || end_col != day_view->selection_end_day) { - need_redraw = TRUE; - day_view->selection_in_top_canvas = FALSE; - day_view->selection_end_row = end_row; - day_view->selection_end_day = end_col; - } - - if (need_redraw) { - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - - -/* Finds the start of the working week which includes the given time. */ -static time_t -e_day_view_find_work_week_start (EDayView *day_view, - time_t start_time) -{ - GDate date; - gint weekday, day, i; - guint offset; - struct icaltimetype tt = icaltime_null_time (); - - time_to_gdate_with_zone (&date, start_time, day_view->zone); - - /* The start of the work-week is the first working day after the - week start day. */ - - /* Get the weekday corresponding to start_time, 0 (Sun) to 6 (Sat). */ - weekday = g_date_weekday (&date) % 7; - - /* Calculate the first working day of the week, 0 (Sun) to 6 (Sat). - It will automatically default to the week start day if no days - are set as working days. */ - day = (day_view->week_start_day + 1) % 7; - for (i = 0; i < 7; i++) { - if (day_view->working_days & (1 << day)) - break; - day = (day + 1) % 7; - } - - /* Calculate how many days we need to go back to the first workday. */ - if (weekday < day) { - offset = (day - weekday) % 7; - g_date_add_days (&date, offset); - } else { - offset = (weekday - day) % 7; - g_date_subtract_days (&date, offset); - } - - tt.year = g_date_year (&date); - tt.month = g_date_month (&date); - tt.day = g_date_day (&date); - - return icaltime_as_timet_with_zone (tt, day_view->zone); -} - - -/* Returns the selected time range. */ -void -e_day_view_get_selected_time_range (EDayView *day_view, - time_t *start_time, - time_t *end_time) -{ - gint start_col, start_row, end_col, end_row; - time_t start, end; - - start_col = day_view->selection_start_day; - start_row = day_view->selection_start_row; - end_col = day_view->selection_end_day; - end_row = day_view->selection_end_row; - - if (start_col == -1) { - start_col = 0; - start_row = 0; - end_col = 0; - end_row = 0; - } - - /* Check if the selection is only in the top canvas, in which case - we can simply use the day_starts array. */ - if (day_view->selection_in_top_canvas) { - start = day_view->day_starts[start_col]; - end = day_view->day_starts[end_col + 1]; - } else { - /* Convert the start col + row into a time. */ - start = e_day_view_convert_grid_position_to_time (day_view, start_col, start_row); - end = e_day_view_convert_grid_position_to_time (day_view, end_col, end_row + 1); - } - - if (start_time) - *start_time = start; - - if (end_time) - *end_time = end; -} - - -static void -e_day_view_recalc_day_starts (EDayView *day_view, - time_t start_time) -{ - gint day; - - day_view->day_starts[0] = start_time; - for (day = 1; day <= day_view->days_shown; day++) { - day_view->day_starts[day] = time_add_day_with_zone (day_view->day_starts[day - 1], 1, day_view->zone); - } - -#if 0 - for (day = 0; day <= day_view->days_shown; day++) - g_print ("Day Starts %i: %s", day, ctime (&day_view->day_starts[day])); -#endif - - day_view->lower = start_time; - day_view->upper = day_view->day_starts[day_view->days_shown]; -} - - -/* Whether we are displaying a work-week, in which case the display always - starts on the first day of the working week. */ -gboolean -e_day_view_get_work_week_view (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), FALSE); - - return day_view->work_week_view; -} - - -void -e_day_view_set_work_week_view (EDayView *day_view, - gboolean work_week_view) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->work_week_view == work_week_view) - return; - - day_view->work_week_view = work_week_view; - - if (day_view->work_week_view) - e_day_view_recalc_work_week (day_view); -} - - -gint -e_day_view_get_days_shown (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), -1); - - return day_view->days_shown; -} - - -void -e_day_view_set_days_shown (EDayView *day_view, - gint days_shown) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - g_return_if_fail (days_shown >= 1); - g_return_if_fail (days_shown <= E_DAY_VIEW_MAX_DAYS); - - if (day_view->days_shown == days_shown) - return; - - day_view->days_shown = days_shown; - - /* If the date isn't set, just return. */ - if (day_view->lower == 0 && day_view->upper == 0) - return; - - e_day_view_recalc_day_starts (day_view, day_view->lower); - e_day_view_recalc_cell_sizes (day_view); - - update_query (day_view); -} - - -gint -e_day_view_get_mins_per_row (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), -1); - - return day_view->mins_per_row; -} - - -void -e_day_view_set_mins_per_row (EDayView *day_view, - gint mins_per_row) -{ - gint day; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (mins_per_row != 5 && mins_per_row != 10 && mins_per_row != 15 - && mins_per_row != 30 && mins_per_row != 60) { - g_warning ("Invalid minutes per row setting"); - return; - } - - if (day_view->mins_per_row == mins_per_row) - return; - - day_view->mins_per_row = mins_per_row; - e_day_view_recalc_num_rows (day_view); - - /* If we aren't visible, we'll sort it out later. */ - if (!GTK_WIDGET_VISIBLE (day_view)) - return; - - for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) - day_view->need_layout[day] = TRUE; - - /* We need to update all the day event labels since the start & end - times may or may not be on row boundaries any more. */ - e_day_view_foreach_event (day_view, - e_day_view_set_show_times_cb, NULL); - - /* We must layout the events before updating the scroll region, since - that will result in a redraw which would crash otherwise. */ - e_day_view_check_layout (day_view); - gtk_widget_queue_draw (day_view->time_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - - e_day_view_update_scroll_regions (day_view); -} - - -/* This specifies the working days in the week. The value is a bitwise - combination of day flags. Defaults to Mon-Fri. */ -EDayViewDays -e_day_view_get_working_days (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), 0); - - return day_view->working_days; -} - - -void -e_day_view_set_working_days (EDayView *day_view, - EDayViewDays days) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->working_days == days) - return; - - day_view->working_days = days; - - if (day_view->work_week_view) - e_day_view_recalc_work_week (day_view); - - /* We have to do this, as the new working days may have no effect on - the days shown, but we still want the background color to change. */ - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_recalc_work_week_days_shown (EDayView *day_view) -{ - gint first_day, last_day, i, days_shown; - gboolean has_working_days = FALSE; - - /* Find the first working day in the week, 0 (Sun) to 6 (Sat). */ - first_day = (day_view->week_start_day + 1) % 7; - for (i = 0; i < 7; i++) { - if (day_view->working_days & (1 << first_day)) { - has_working_days = TRUE; - break; - } - first_day = (first_day + 1) % 7; - } - - if (has_working_days) { - /* Now find the last working day of the week, backwards. */ - last_day = day_view->week_start_day % 7; - for (i = 0; i < 7; i++) { - if (day_view->working_days & (1 << last_day)) - break; - last_day = (last_day + 6) % 7; - } - /* Now calculate the days we need to show to include all the - working days in the week. Add 1 to make it inclusive. */ - days_shown = (last_day + 7 - first_day) % 7 + 1; - } else { - /* If no working days are set, just use 7. */ - days_shown = 7; - } - - e_day_view_set_days_shown (day_view, days_shown); -} - - -/* The start and end time of the working day. This only affects the background - colors. */ -void -e_day_view_get_working_day (EDayView *day_view, - gint *start_hour, - gint *start_minute, - gint *end_hour, - gint *end_minute) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - *start_hour = day_view->work_day_start_hour; - *start_minute = day_view->work_day_start_minute; - *end_hour = day_view->work_day_end_hour; - *end_minute = day_view->work_day_end_minute; -} - - -void -e_day_view_set_working_day (EDayView *day_view, - gint start_hour, - gint start_minute, - gint end_hour, - gint end_minute) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - day_view->work_day_start_hour = start_hour; - day_view->work_day_start_minute = start_minute; - day_view->work_day_end_hour = end_hour; - day_view->work_day_end_minute = end_minute; - - gtk_widget_queue_draw (day_view->main_canvas); -} - - -/* Whether we use 12-hour of 24-hour format. */ -gboolean -e_day_view_get_24_hour_format (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), FALSE); - - return day_view->use_24_hour_format; -} - - -void -e_day_view_set_24_hour_format (EDayView *day_view, - gboolean use_24_hour) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->use_24_hour_format == use_24_hour) - return; - - day_view->use_24_hour_format = use_24_hour; - - /* We need to update all the text in the events since they may contain - the time in the old format. */ - e_day_view_foreach_event (day_view, e_day_view_set_show_times_cb, - NULL); - - /* FIXME: We need to re-layout the top canvas since the time - format affects the sizes. */ - gtk_widget_queue_draw (day_view->time_canvas); - gtk_widget_queue_draw (day_view->top_canvas); -} - - -/* Whether we display event end times in the main canvas. */ -gboolean -e_day_view_get_show_event_end_times (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), TRUE); - - return day_view->show_event_end_times; -} - - -void -e_day_view_set_show_event_end_times (EDayView *day_view, - gboolean show) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->show_event_end_times != show) { - day_view->show_event_end_times = show; - e_day_view_foreach_event (day_view, - e_day_view_set_show_times_cb, NULL); - } -} - - -/* The current timezone. */ -icaltimezone* -e_day_view_get_timezone (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); - - return day_view->zone; -} - - -void -e_day_view_set_timezone (EDayView *day_view, - icaltimezone *zone) -{ - icaltimezone *old_zone; - struct icaltimetype tt; - time_t lower; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - old_zone = day_view->zone; - if (old_zone == zone) - return; - - day_view->zone = zone; - - /* If our time hasn't been set yet, just return. */ - if (day_view->lower == 0 && day_view->upper == 0) - return; - - /* Recalculate the new start of the first day. We just use exactly - the same time, but with the new timezone. */ - tt = icaltime_from_timet_with_zone (day_view->lower, FALSE, - old_zone); - - lower = icaltime_as_timet_with_zone (tt, zone); - - e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); -} - - -/* This is a callback used to update all day event labels. */ -static gboolean -e_day_view_set_show_times_cb (EDayView *day_view, - gint day, - gint event_num, - gpointer data) -{ - if (day != E_DAY_VIEW_LONG_EVENT) { - e_day_view_update_event_label (day_view, day, event_num); - } - - return TRUE; -} - - -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint -e_day_view_get_week_start_day (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), 0); - - return day_view->week_start_day; -} - - -void -e_day_view_set_week_start_day (EDayView *day_view, - gint week_start_day) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - g_return_if_fail (week_start_day >= 0); - g_return_if_fail (week_start_day < 7); - - if (day_view->week_start_day == week_start_day) - return; - - day_view->week_start_day = week_start_day; - - if (day_view->work_week_view) - e_day_view_recalc_work_week (day_view); -} - -static EDayViewEvent * -get_current_event (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); - - if (day_view->editing_event_day == -1) - return NULL; - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - return &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - return &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); -} - -void -e_day_view_cut_clipboard (EDayView *day_view) -{ - EDayViewEvent *event; - const char *uid; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - event = get_current_event (day_view); - if (event == NULL) - return; - - e_day_view_set_status_message (day_view, _("Deleting selected objects")); - - e_day_view_copy_clipboard (day_view); - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); - - e_day_view_set_status_message (day_view, NULL); -} - -void -e_day_view_copy_clipboard (EDayView *day_view) -{ - EDayViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - event = get_current_event (day_view); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (day_view->clipboard_selection != NULL) - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = g_strdup (comp_str); - gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -void -e_day_view_paste_clipboard (EDayView *day_view) -{ - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - gtk_selection_convert (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - -static void -e_day_view_recalc_work_week (EDayView *day_view) -{ - time_t lower; - - /* If we aren't showing the work week, just return. */ - if (!day_view->work_week_view) - return; - - e_day_view_recalc_work_week_days_shown (day_view); - - /* If the date isn't set, just return. */ - if (day_view->lower == 0 && day_view->upper == 0) - return; - - lower = e_day_view_find_work_week_start (day_view, day_view->lower); - if (lower != day_view->lower) { - /* Reset the selection, as it may disappear. */ - day_view->selection_start_day = -1; - - e_day_view_recalc_day_starts (day_view, lower); - update_query (day_view); - - /* This updates the date navigator. */ - e_day_view_update_calendar_selection_time (day_view); - } -} - - -static gboolean -e_day_view_update_scroll_regions (EDayView *day_view) -{ - gdouble old_x2, old_y2, new_x2, new_y2; - gboolean need_reshape = FALSE; - - /* Set the scroll region of the time canvas to its allocated width, - but with the height the same as the main canvas. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (day_view->time_canvas), - NULL, NULL, &old_x2, &old_y2); - new_x2 = day_view->time_canvas->allocation.width - 1; - new_y2 = MAX (day_view->rows * day_view->row_height, - day_view->main_canvas->allocation.height) - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) - gnome_canvas_set_scroll_region (GNOME_CANVAS (day_view->time_canvas), - 0, 0, new_x2, new_y2); - - /* Set the scroll region of the main canvas to its allocated width, - but with the height depending on the number of rows needed. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (day_view->main_canvas), - NULL, NULL, &old_x2, &old_y2); - new_x2 = day_view->main_canvas->allocation.width - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) { - need_reshape = TRUE; - gnome_canvas_set_scroll_region (GNOME_CANVAS (day_view->main_canvas), - 0, 0, new_x2, new_y2); - } - - return need_reshape; -} - - -/* This recalculates the number of rows to display, based on the time range - shown and the minutes per row. */ -static void -e_day_view_recalc_num_rows (EDayView *day_view) -{ - gint hours, minutes, total_minutes; - - hours = day_view->last_hour_shown - day_view->first_hour_shown; - /* This could be negative but it works out OK. */ - minutes = day_view->last_minute_shown - day_view->first_minute_shown; - total_minutes = hours * 60 + minutes; - day_view->rows = total_minutes / day_view->mins_per_row; -} - - -/* Converts an hour and minute to a row in the canvas. Note that if we aren't - showing all 24 hours of the day, the returned row may be negative or - greater than day_view->rows. */ -gint -e_day_view_convert_time_to_row (EDayView *day_view, - gint hour, - gint minute) -{ - gint total_minutes, start_minute, offset; - - total_minutes = hour * 60 + minute; - start_minute = day_view->first_hour_shown * 60 - + day_view->first_minute_shown; - offset = total_minutes - start_minute; - if (offset < 0) - return -1; - else - return offset / day_view->mins_per_row; -} - - -/* Converts an hour and minute to a y coordinate in the canvas. */ -gint -e_day_view_convert_time_to_position (EDayView *day_view, - gint hour, - gint minute) -{ - gint total_minutes, start_minute, offset; - - total_minutes = hour * 60 + minute; - start_minute = day_view->first_hour_shown * 60 - + day_view->first_minute_shown; - offset = total_minutes - start_minute; - - return offset * day_view->row_height / day_view->mins_per_row; -} - - -static gboolean -e_day_view_on_top_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view) -{ - gint event_x, event_y, day, event_num; - EDayViewPosition pos; - - /* Convert the coords to the main canvas window, or return if the - window is not found. */ - if (!e_day_view_convert_event_coords (day_view, (GdkEvent*) event, - GTK_LAYOUT (widget)->bin_window, - &event_x, &event_y)) - return FALSE; - - pos = e_day_view_convert_position_in_top_canvas (day_view, - event_x, event_y, - &day, &event_num); - - if (pos == E_DAY_VIEW_POS_OUTSIDE) - return FALSE; - - if (pos != E_DAY_VIEW_POS_NONE) - return e_day_view_on_long_event_button_press (day_view, - event_num, - event, pos, - event_x, - event_y); - - e_day_view_stop_editing_event (day_view); - - if (event->button == 1) { - if (event->type == GDK_2BUTTON_PRESS) { - time_t dtstart, dtend; - - e_day_view_get_selected_time_range (day_view, &dtstart, - &dtend); - gnome_calendar_new_appointment_for (day_view->calendar, - dtstart, dtend, - TRUE, FALSE); - return TRUE; - } - - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (gdk_pointer_grab (GTK_LAYOUT (widget)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, event->time) == 0) { - e_day_view_start_selection (day_view, day, -1); - } - } else if (event->button == 3) { - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (day < day_view->selection_start_day || day > day_view->selection_end_day) { - e_day_view_start_selection (day_view, day, -1); - e_day_view_finish_selection (day_view); - } - - e_day_view_on_event_right_click (day_view, event, -1, -1); - } - - return TRUE; -} - - -static gboolean -e_day_view_convert_event_coords (EDayView *day_view, - GdkEvent *event, - GdkWindow *window, - gint *x_return, - gint *y_return) -{ - gint event_x, event_y, win_x, win_y; - GdkWindow *event_window;; - - /* Get the event window, x & y from the appropriate event struct. */ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - event_x = event->button.x; - event_y = event->button.y; - event_window = event->button.window; - break; - case GDK_MOTION_NOTIFY: - event_x = event->motion.x; - event_y = event->motion.y; - event_window = event->motion.window; - break; - default: - /* Shouldn't get here. */ - g_assert_not_reached (); - return FALSE; - } - - while (event_window && event_window != window - && event_window != GDK_ROOT_PARENT()) { - gdk_window_get_position (event_window, &win_x, &win_y); - event_x += win_x; - event_y += win_y; - event_window = gdk_window_get_parent (event_window); - } - - *x_return = event_x; - *y_return = event_y; - - if (event_window != window) - g_warning ("Couldn't find event window\n"); - - return (event_window == window) ? TRUE : FALSE; -} - - -static gboolean -e_day_view_on_main_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view) -{ - gint event_x, event_y, row, day, event_num; - EDayViewPosition pos; - -#if 0 - g_print ("In e_day_view_on_main_canvas_button_press\n"); -#endif - - /* Handle scroll wheel events */ - if (event->button == 4) { - /* The wheel has been moved up, so scroll the canvas down. */ - e_day_view_scroll (day_view, E_DAY_VIEW_WHEEL_MOUSE_STEP_SIZE); - return TRUE; - } - if (event->button == 5) { - /* The wheel has been moved down, so scroll the canvas up. */ - e_day_view_scroll (day_view, -E_DAY_VIEW_WHEEL_MOUSE_STEP_SIZE); - return TRUE; - } - - /* Convert the coords to the main canvas window, or return if the - window is not found. */ - if (!e_day_view_convert_event_coords (day_view, (GdkEvent*) event, - GTK_LAYOUT (widget)->bin_window, - &event_x, &event_y)) - return FALSE; - - /* Find out where the mouse is. */ - pos = e_day_view_convert_position_in_main_canvas (day_view, - event_x, event_y, - &day, &row, - &event_num); - - if (pos == E_DAY_VIEW_POS_OUTSIDE) - return FALSE; - - if (pos != E_DAY_VIEW_POS_NONE) - return e_day_view_on_event_button_press (day_view, day, - event_num, event, pos, - event_x, event_y); - - e_day_view_stop_editing_event (day_view); - - /* Start the selection drag. */ - if (event->button == 1) { - if (event->type == GDK_2BUTTON_PRESS) { - time_t dtstart, dtend; - - e_day_view_get_selected_time_range (day_view, &dtstart, - &dtend); - gnome_calendar_new_appointment_for (day_view->calendar, - dtstart, dtend, - FALSE, FALSE); - return TRUE; - } - - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (gdk_pointer_grab (GTK_LAYOUT (widget)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, event->time) == 0) { - e_day_view_start_selection (day_view, day, row); - } - } else if (event->button == 3) { - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - - if ((day < day_view->selection_start_day || day > day_view->selection_end_day) - || (day == day_view->selection_start_day && row < day_view->selection_start_row) - || (day == day_view->selection_end_day && row > day_view->selection_end_row)) { - e_day_view_start_selection (day_view, day, row); - e_day_view_finish_selection (day_view); - } - - e_day_view_on_event_right_click (day_view, event, -1, -1); - } - - return TRUE; -} - - -static gboolean -e_day_view_on_time_canvas_button_press (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view) -{ - /* Handle scroll wheel events */ - if (event->button == 4 || event->button == 5) { - GtkAdjustment *adj = GTK_LAYOUT (day_view->main_canvas)->vadjustment; - gfloat new_value; - - new_value = adj->value + ((event->button == 4) ? - -adj->page_increment / 2: - adj->page_increment / 2); - new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); - gtk_adjustment_set_value (adj, new_value); - - return TRUE; - } - - return FALSE; -} - - -/* Callback used when a component is destroyed. Expects the closure data to be - * a pointer to a boolean; will set it to TRUE. - */ -static void -comp_destroy_cb (gpointer data, GObject *deadbeef) -{ - gboolean *destroyed; - - destroyed = data; - *destroyed = TRUE; -} - - -static gboolean -e_day_view_on_long_event_button_press (EDayView *day_view, - gint event_num, - GdkEventButton *event, - EDayViewPosition pos, - gint event_x, - gint event_y) -{ - if (event->button == 1) { - if (event->type == GDK_BUTTON_PRESS) { - e_day_view_on_long_event_click (day_view, event_num, - event, pos, - event_x, event_y); - return TRUE; - } else if (event->type == GDK_2BUTTON_PRESS) { - e_day_view_on_event_double_click (day_view, -1, - event_num); - gtk_signal_emit_stop_by_name (GTK_OBJECT (day_view->top_canvas), - "button_press_event"); - return TRUE; - } - } else if (event->button == 3) { - EDayViewEvent *e; - gboolean destroyed; - - e = &g_array_index (day_view->long_events, EDayViewEvent, event_num); - destroyed = FALSE; - g_object_weak_ref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (!destroyed) { - g_object_weak_unref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - e_day_view_set_selected_time_range_in_top_visible (day_view, e->start, e->end); - - e_day_view_on_event_right_click (day_view, event, - E_DAY_VIEW_LONG_EVENT, - event_num); - } - - return TRUE; - } - return FALSE; -} - - -static gboolean -e_day_view_on_event_button_press (EDayView *day_view, - gint day, - gint event_num, - GdkEventButton *event, - EDayViewPosition pos, - gint event_x, - gint event_y) -{ - if (event->button == 1) { - if (event->type == GDK_BUTTON_PRESS) { - e_day_view_on_event_click (day_view, day, event_num, - event, pos, - event_x, event_y); - return TRUE; - } else if (event->type == GDK_2BUTTON_PRESS) { - e_day_view_on_event_double_click (day_view, day, - event_num); - gtk_signal_emit_stop_by_name (GTK_OBJECT (day_view->main_canvas), - "button_press_event"); - return TRUE; - } - } else if (event->button == 3) { - EDayViewEvent *e; - gboolean destroyed; - - e = &g_array_index (day_view->events[day], EDayViewEvent, event_num); - - destroyed = FALSE; - g_object_weak_ref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (!destroyed) { - g_object_weak_unref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - e_day_view_set_selected_time_range_visible (day_view, e->start, e->end); - - e_day_view_on_event_right_click (day_view, event, - day, event_num); - } - - return TRUE; - } - return FALSE; -} - - -static void -e_day_view_on_long_event_click (EDayView *day_view, - gint event_num, - GdkEventButton *bevent, - EDayViewPosition pos, - gint event_x, - gint event_y) -{ - EDayViewEvent *event; - gint start_day, end_day, day; - gint item_x, item_y, item_w, item_h; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - /* Ignore clicks on the EText while editing. */ - if (pos == E_DAY_VIEW_POS_EVENT - && E_TEXT (event->canvas_item)->editing) - return; - - if ((cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp)) - && (pos == E_DAY_VIEW_POS_LEFT_EDGE - || pos == E_DAY_VIEW_POS_RIGHT_EDGE)) { - gboolean destroyed; - - if (!e_day_view_find_long_event_days (event, - day_view->days_shown, - day_view->day_starts, - &start_day, &end_day)) - return; - - destroyed = FALSE; - g_object_weak_ref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - /* Grab the keyboard focus, so the event being edited is saved - and we can use the Escape key to abort the resize. */ - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (destroyed) - return; - - g_object_weak_unref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - if (gdk_pointer_grab (GTK_LAYOUT (day_view->top_canvas)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, bevent->time) == 0) { - - day_view->resize_event_day = E_DAY_VIEW_LONG_EVENT; - day_view->resize_event_num = event_num; - day_view->resize_drag_pos = pos; - day_view->resize_start_row = start_day; - day_view->resize_end_row = end_day; - - /* Create the edit rect if necessary. */ - e_day_view_reshape_resize_long_event_rect_item (day_view); - - /* Make sure the text item is on top. */ - gnome_canvas_item_raise_to_top (day_view->resize_long_event_rect_item); - - /* Raise the event's item, above the rect as well. */ - gnome_canvas_item_raise_to_top (event->canvas_item); - } - } else if (e_day_view_get_long_event_position (day_view, event_num, - &start_day, &end_day, - &item_x, &item_y, - &item_w, &item_h)) { - /* Remember the item clicked and the mouse position, - so we can start a drag if the mouse moves. */ - day_view->pressed_event_day = E_DAY_VIEW_LONG_EVENT; - day_view->pressed_event_num = event_num; - - day_view->drag_event_x = event_x; - day_view->drag_event_y = event_y; - - e_day_view_convert_position_in_top_canvas (day_view, - event_x, event_y, - &day, NULL); - day_view->drag_event_offset = day - start_day; - } -} - - -static void -e_day_view_on_event_click (EDayView *day_view, - gint day, - gint event_num, - GdkEventButton *bevent, - EDayViewPosition pos, - gint event_x, - gint event_y) -{ - EDayViewEvent *event; - gint tmp_day, row, start_row; - - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* Ignore clicks on the EText while editing. */ - if (pos == E_DAY_VIEW_POS_EVENT - && E_TEXT (event->canvas_item)->editing) - return; - - if ((cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp)) - && (pos == E_DAY_VIEW_POS_TOP_EDGE - || pos == E_DAY_VIEW_POS_BOTTOM_EDGE)) { - gboolean destroyed; - - destroyed = FALSE; - g_object_weak_ref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - /* Grab the keyboard focus, so the event being edited is saved - and we can use the Escape key to abort the resize. */ - if (!GTK_WIDGET_HAS_FOCUS (day_view)) - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - if (destroyed) - return; - - g_object_weak_unref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - if (gdk_pointer_grab (GTK_LAYOUT (day_view->main_canvas)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, bevent->time) == 0) { - - day_view->resize_event_day = day; - day_view->resize_event_num = event_num; - day_view->resize_drag_pos = pos; - day_view->resize_start_row = event->start_minute / day_view->mins_per_row; - day_view->resize_end_row = (event->end_minute - 1) / day_view->mins_per_row; - if (day_view->resize_end_row < day_view->resize_start_row) - day_view->resize_end_row = day_view->resize_start_row; - - day_view->resize_bars_event_day = day; - day_view->resize_bars_event_num = event_num; - - /* Create the edit rect if necessary. */ - e_day_view_reshape_resize_rect_item (day_view); - - e_day_view_reshape_main_canvas_resize_bars (day_view); - - /* Make sure the text item is on top. */ - gnome_canvas_item_raise_to_top (day_view->resize_rect_item); - gnome_canvas_item_raise_to_top (day_view->resize_bar_item); - - /* Raise the event's item, above the rect as well. */ - gnome_canvas_item_raise_to_top (event->canvas_item); - } - - } else { - /* Remember the item clicked and the mouse position, - so we can start a drag if the mouse moves. */ - day_view->pressed_event_day = day; - day_view->pressed_event_num = event_num; - - day_view->drag_event_x = event_x; - day_view->drag_event_y = event_y; - - e_day_view_convert_position_in_main_canvas (day_view, - event_x, event_y, - &tmp_day, &row, - NULL); - start_row = event->start_minute / day_view->mins_per_row; - day_view->drag_event_offset = row - start_row; - } -} - - -static void -e_day_view_reshape_resize_long_event_rect_item (EDayView *day_view) -{ - gint day, event_num, start_day, end_day; - gint item_x, item_y, item_w, item_h; - gdouble x1, y1, x2, y2; - - day = day_view->resize_event_day; - event_num = day_view->resize_event_num; - - /* If we're not resizing an event, or the event is not shown, - hide the resize bars. */ - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_NONE - || !e_day_view_get_long_event_position (day_view, event_num, - &start_day, &end_day, - &item_x, &item_y, - &item_w, &item_h)) { - gnome_canvas_item_hide (day_view->resize_long_event_rect_item); - return; - } - - x1 = item_x; - y1 = item_y; - x2 = item_x + item_w - 1; - y2 = item_y + item_h - 1; - - gnome_canvas_item_set (day_view->resize_long_event_rect_item, - "x1", x1, - "y1", y1, - "x2", x2, - "y2", y2, - NULL); - gnome_canvas_item_show (day_view->resize_long_event_rect_item); -} - - -static void -e_day_view_reshape_resize_rect_item (EDayView *day_view) -{ - gint day, event_num; - gint item_x, item_y, item_w, item_h; - gdouble x1, y1, x2, y2; - - day = day_view->resize_event_day; - event_num = day_view->resize_event_num; - - /* If we're not resizing an event, or the event is not shown, - hide the resize bars. */ - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_NONE - || !e_day_view_get_event_position (day_view, day, event_num, - &item_x, &item_y, - &item_w, &item_h)) { - gnome_canvas_item_hide (day_view->resize_rect_item); - return; - } - - x1 = item_x; - y1 = item_y; - x2 = item_x + item_w - 1; - y2 = item_y + item_h - 1; - - gnome_canvas_item_set (day_view->resize_rect_item, - "x1", x1 + E_DAY_VIEW_BAR_WIDTH - 1, - "y1", y1, - "x2", x2, - "y2", y2, - NULL); - gnome_canvas_item_show (day_view->resize_rect_item); - - gnome_canvas_item_set (day_view->resize_bar_item, - "x1", x1, - "y1", y1, - "x2", x1 + E_DAY_VIEW_BAR_WIDTH - 1, - "y2", y2, - NULL); - gnome_canvas_item_show (day_view->resize_bar_item); -} - - -static void -e_day_view_on_event_double_click (EDayView *day_view, - gint day, - gint event_num) -{ - EDayViewEvent *event; - gboolean destroyed; - - if (day == -1) - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - else - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - destroyed = FALSE; - g_object_weak_ref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - e_day_view_stop_editing_event (day_view); - - if (!destroyed) { - g_object_weak_unref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - if (day_view->calendar) - gnome_calendar_edit_object (day_view->calendar, event->comp, FALSE); - else - g_warning ("Calendar not set"); - } -} - -enum { - /* - * This is used to "flag" events that can not be edited - */ - MASK_EDITABLE = 1, - - /* - * To disable recurring actions to be displayed - */ - MASK_RECURRING = 2, - - /* - * To disable actions for non-recurring items to be displayed - */ - MASK_SINGLE = 4, - - /* - * This is used to when an event is currently being edited - * in another window and we want to disable the event - * from being edited twice - */ - MASK_EDITING = 8, - - /* - * This is used to when an event is already a meeting and - * we want to disable the schedule meeting command - */ - MASK_MEETING = 16, - - /* - * To disable cut and copy for meetings the user is not the - * organizer of - */ - MASK_MEETING_ORGANIZER = 32, - - /* - * To disable things not valid for instances - */ - MASK_INSTANCE = 64 -}; - -static EPopupMenu main_items [] = { - E_POPUP_ITEM (N_("New _Appointment"), - GTK_SIGNAL_FUNC (e_day_view_on_new_appointment), MASK_EDITABLE), - E_POPUP_ITEM (N_("New All Day _Event"), - GTK_SIGNAL_FUNC (e_day_view_on_new_event), MASK_EDITABLE), - E_POPUP_ITEM (N_("New Meeting"), - GTK_SIGNAL_FUNC (e_day_view_on_new_meeting), MASK_EDITABLE), - E_POPUP_ITEM (N_("New Task"), - GTK_SIGNAL_FUNC (e_day_view_on_new_task), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("Print..."), - GTK_SIGNAL_FUNC (e_day_view_on_print), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Paste"), - GTK_SIGNAL_FUNC (e_day_view_on_paste), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_SUBMENU (N_("Current View"), NULL, 0), - - E_POPUP_ITEM (N_("Go to _Today"), - GTK_SIGNAL_FUNC (e_day_view_on_goto_today), 0), - E_POPUP_ITEM (N_("_Go to Date..."), - GTK_SIGNAL_FUNC (e_day_view_on_goto_date), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Publish Free/Busy Information"), - GTK_SIGNAL_FUNC (e_day_view_on_publish), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Settings..."), - GTK_SIGNAL_FUNC (e_day_view_on_settings), 0), - - E_POPUP_TERMINATOR -}; - -static EPopupMenu child_items [] = { - - E_POPUP_ITEM (N_("_Open"), GTK_SIGNAL_FUNC (e_day_view_on_edit_appointment), MASK_EDITING), - E_POPUP_ITEM (N_("_Save As..."), GTK_SIGNAL_FUNC (e_day_view_on_save_as), MASK_EDITING), - E_POPUP_ITEM (N_("_Print..."), GTK_SIGNAL_FUNC (e_day_view_on_print_event), MASK_EDITING), - - /* Only show this separator if one of the above is shown. */ - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("C_ut"), GTK_SIGNAL_FUNC (e_day_view_on_cut), MASK_EDITABLE | MASK_EDITING | MASK_MEETING_ORGANIZER), - E_POPUP_ITEM (N_("_Copy"), GTK_SIGNAL_FUNC (e_day_view_on_copy), MASK_EDITING | MASK_MEETING_ORGANIZER), - E_POPUP_ITEM (N_("_Paste"), GTK_SIGNAL_FUNC (e_day_view_on_paste), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Schedule Meeting..."), GTK_SIGNAL_FUNC (e_day_view_on_meeting), MASK_EDITABLE | MASK_EDITING | MASK_MEETING), - E_POPUP_ITEM (N_("_Forward as iCalendar..."), GTK_SIGNAL_FUNC (e_day_view_on_forward), MASK_EDITING), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Delete"), GTK_SIGNAL_FUNC (e_day_view_on_delete_appointment), MASK_EDITABLE | MASK_SINGLE | MASK_EDITING), - E_POPUP_ITEM (N_("Make this Occurrence _Movable"), GTK_SIGNAL_FUNC (e_day_view_on_unrecur_appointment), MASK_EDITABLE | MASK_RECURRING | MASK_EDITING | MASK_INSTANCE), - E_POPUP_ITEM (N_("Delete this _Occurrence"), GTK_SIGNAL_FUNC (e_day_view_on_delete_occurrence), MASK_EDITABLE | MASK_RECURRING | MASK_EDITING), - E_POPUP_ITEM (N_("Delete _All Occurrences"), GTK_SIGNAL_FUNC (e_day_view_on_delete_appointment), MASK_EDITABLE | MASK_RECURRING | MASK_EDITING), - - E_POPUP_TERMINATOR -}; - -static void -free_view_popup (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - if (day_view->view_menu == NULL) - return; - - gnome_calendar_discard_view_popup (day_view->calendar, day_view->view_menu); - day_view->view_menu = NULL; -} - -static void -e_day_view_on_event_right_click (EDayView *day_view, - GdkEventButton *bevent, - gint day, - gint event_num) -{ - EDayViewEvent *event; - int have_selection; - gboolean being_edited; - EPopupMenu *context_menu; - GtkMenu *popup; - int hide_mask = 0; - int disable_mask = 0; - - /* - * FIXME: - * This used to be set only if the event wasn't being edited - * in the event editor, but we can't check that at present. - * We could possibly set up another method of checking it. - */ - - being_edited = FALSE; - - have_selection = GTK_WIDGET_HAS_FOCUS (day_view) - && day_view->selection_start_day != -1; - - if (event_num == -1) { - day_view->view_menu = gnome_calendar_setup_view_popup (day_view->calendar); - main_items[9].submenu = day_view->view_menu; - context_menu = main_items; - } else { - context_menu = child_items; - - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - else - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - if (cal_component_has_recurrences (event->comp)) - hide_mask |= MASK_SINGLE; - else - hide_mask |= MASK_RECURRING; - - if (cal_component_is_instance (event->comp)) - hide_mask |= MASK_INSTANCE; - - if (cal_component_has_organizer (event->comp)) { - disable_mask |= MASK_MEETING; - - if (!itip_organizer_is_user (event->comp, day_view->client)) - disable_mask |= MASK_MEETING_ORGANIZER; - } - } - - if (cal_client_is_read_only (day_view->client)) - disable_mask |= MASK_EDITABLE; - - if (being_edited) - disable_mask |= MASK_EDITING; - - day_view->popup_event_day = day; - day_view->popup_event_num = event_num; - - popup = e_popup_menu_create (context_menu, disable_mask, hide_mask, day_view); - g_signal_connect (popup, "selection-done", G_CALLBACK (free_view_popup), day_view); - e_popup_menu (popup, (GdkEvent *) bevent); -} - -static void -e_day_view_on_new_appointment (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - time_t dtstart, dtend; - struct icaltimetype itt; - - /* Edit a new event. If only one day is selected in the top canvas, - we set the time to the first 1/2-hour of the working day. */ - if (day_view->selection_in_top_canvas - && day_view->selection_start_day != -1 - && day_view->selection_start_day == day_view->selection_end_day) { - dtstart = day_view->day_starts[day_view->selection_start_day]; - itt = icaltime_from_timet_with_zone (dtstart, FALSE, - day_view->zone); - itt.hour = calendar_config_get_day_start_hour (); - itt.minute = calendar_config_get_day_start_minute (); - dtstart = icaltime_as_timet_with_zone (itt, day_view->zone); - - icaltime_adjust (&itt, 0, 0, 30, 0); - dtend = icaltime_as_timet_with_zone (itt, day_view->zone); - } else { - e_day_view_get_selected_time_range (day_view, &dtstart, - &dtend); - } - - gnome_calendar_new_appointment_for ( - day_view->calendar, dtstart, dtend, FALSE, FALSE); -} - -static void -e_day_view_on_new_event (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - time_t dtstart, dtend; - - e_day_view_get_selected_time_range (day_view, &dtstart, &dtend); - gnome_calendar_new_appointment_for ( - day_view->calendar, dtstart, dtend, TRUE, FALSE); -} - -static void -e_day_view_on_new_meeting (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - time_t dtstart, dtend; - struct icaltimetype itt; - - /* Edit a new event. If only one day is selected in the top canvas, - we set the time to the first 1/2-hour of the working day. */ - if (day_view->selection_in_top_canvas - && day_view->selection_start_day != -1 - && day_view->selection_start_day == day_view->selection_end_day) { - dtstart = day_view->day_starts[day_view->selection_start_day]; - itt = icaltime_from_timet_with_zone (dtstart, FALSE, - day_view->zone); - itt.hour = calendar_config_get_day_start_hour (); - itt.minute = calendar_config_get_day_start_minute (); - dtstart = icaltime_as_timet_with_zone (itt, day_view->zone); - - icaltime_adjust (&itt, 0, 0, 30, 0); - dtend = icaltime_as_timet_with_zone (itt, day_view->zone); - } else { - e_day_view_get_selected_time_range (day_view, &dtstart, - &dtend); - } - - gnome_calendar_new_appointment_for ( - day_view->calendar, dtstart, dtend, FALSE, TRUE); -} - -static void -e_day_view_on_new_task (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - gnome_calendar_new_task (day_view->calendar); -} - -static void -e_day_view_on_goto_date (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - goto_dialog (day_view->calendar); -} - -static void -e_day_view_on_goto_today (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - calendar_goto_today (day_view->calendar); -} - -static void -e_day_view_on_edit_appointment (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - if (day_view->calendar) - gnome_calendar_edit_object (day_view->calendar, event->comp, FALSE); - else - g_warning ("Calendar not set"); -} - -static void -e_day_view_on_save_as (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - char *filename; - char *ical_string; - FILE *file; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - filename = e_file_dialog_save (_("Save as...")); - if (filename == NULL) - return; - - ical_string = cal_client_get_component_as_string (day_view->client, event->comp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - file = fopen (filename, "w"); - if (file == NULL) { - g_warning ("Couldn't save item"); - return; - } - - fprintf (file, ical_string); - g_free (ical_string); - fclose (file); -} - -static void -e_day_view_on_print (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - time_t start; - GnomeCalendarViewType view_type; - PrintView print_view; - - day_view = E_DAY_VIEW (data); - - gnome_calendar_get_current_time_range (day_view->calendar, &start, NULL); - view_type = gnome_calendar_get_view (day_view->calendar); - - switch (view_type) { - case GNOME_CAL_DAY_VIEW: - print_view = PRINT_VIEW_DAY; - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - print_view = PRINT_VIEW_WEEK; - break; - - default: - g_assert_not_reached (); - return; - } - - print_calendar (day_view->calendar, FALSE, start, print_view); -} - -static void -e_day_view_on_print_event (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - print_comp (event->comp, day_view->client, FALSE); -} - -static void -e_day_view_on_meeting (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - if (day_view->calendar) - gnome_calendar_edit_object (day_view->calendar, event->comp, TRUE); - else - g_warning ("Calendar not set"); -} - -static void -e_day_view_on_forward (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, event->comp, - day_view->client, NULL); -} - -static void -e_day_view_on_publish (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - icaltimezone *utc; - time_t start = time (NULL), end; - GList *comp_list; - - day_view = E_DAY_VIEW (data); - - utc = icaltimezone_get_utc_timezone (); - start = time_day_begin_with_zone (start, utc); - end = time_add_week_with_zone (start, 6, utc); - - comp_list = cal_client_get_free_busy (day_view->client, NULL, start, end); - if (comp_list) { - GList *l; - - for (l = comp_list; l; l = l->next) { - CalComponent *comp = CAL_COMPONENT (l->data); - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, - day_view->client, NULL); - - g_object_unref (comp); - } - - g_list_free (comp_list); - } -} - -static void -e_day_view_on_settings (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - - day_view = E_DAY_VIEW (data); - - control_util_show_settings (day_view->calendar); -} - -static void -e_day_view_delete_event_internal (EDayView *day_view, EDayViewEvent *event) -{ - CalComponentVType vtype; - - vtype = cal_component_get_vtype (event->comp); - - if (delete_component_dialog (event->comp, FALSE, 1, vtype, - GTK_WIDGET (day_view))) { - const char *uid; - - if (itip_organizer_is_user (event->comp, day_view->client) - && cancel_component_dialog (day_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, day_view->client, NULL); - - cal_component_get_uid (event->comp, &uid); - - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); - } -} - -static void -e_day_view_on_delete_appointment (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - gboolean destroyed; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - destroyed = FALSE; - g_object_weak_ref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - if (day_view->editing_event_day >= 0) - e_day_view_stop_editing_event (day_view); - - if (!destroyed) { - g_object_weak_unref ((GObject *) event->comp, comp_destroy_cb, &destroyed); - - e_day_view_delete_event_internal (day_view, event); - } -} - -void -e_day_view_delete_event (EDayView *day_view) -{ - EDayViewEvent *event; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->editing_event_day == -1) - return; - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - event = &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); - - e_day_view_delete_event_internal (day_view, event); -} - -static void -e_day_view_delete_occurrence_internal (EDayView *day_view, EDayViewEvent *event) -{ - CalComponent *comp; - - if (cal_component_is_instance (event->comp)) { - const char *uid; - - cal_component_get_uid (event->comp, &uid); - - delete_error_dialog (cal_client_remove_object_with_mod (day_view->client, uid, CALOBJ_MOD_THIS), - CAL_COMPONENT_EVENT); - return; - } - - /* We must duplicate the CalComponent, or we won't know it has changed - when we get the "update_event" callback. */ - comp = cal_component_clone (event->comp); - cal_comp_util_add_exdate (comp, event->start, day_view->zone); - - if (cal_client_update_object (day_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_day_view_on_delete_occurrence(): Could not update the object!"); - - g_object_unref (comp); -} - -static void -e_day_view_on_delete_occurrence (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - e_day_view_delete_occurrence_internal (day_view, event); -} - -void -e_day_view_delete_occurrence (EDayView *day_view) -{ - EDayViewEvent *event; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (day_view->editing_event_day == -1) - return; - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - event = &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); - - e_day_view_delete_occurrence_internal (day_view, event); -} - -static void -e_day_view_on_cut (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - const char *uid; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - e_day_view_on_copy (widget, data); - - if (itip_organizer_is_user (event->comp, day_view->client) - && cancel_component_dialog (day_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, day_view->client, NULL); - - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (day_view->client, uid), CAL_COMPONENT_EVENT); -} - -static void -e_day_view_on_copy (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (day_view->clipboard_selection) - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = g_strdup (comp_str); - - gtk_selection_owner_set (day_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -static void -e_day_view_on_paste (GtkWidget *widget, gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - gtk_selection_convert (day_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - -static void -e_day_view_on_unrecur_appointment (GtkWidget *widget, gpointer data) -{ - EDayView *day_view; - EDayViewEvent *event; - CalComponent *comp, *new_comp; - CalComponentDateTime date; - struct icaltimetype itt; - - day_view = E_DAY_VIEW (data); - - event = e_day_view_get_popup_menu_event (day_view); - if (event == NULL) - return; - - date.value = &itt; - date.tzid = NULL; - - /* For the recurring object, we add an exception to get rid of the - instance. */ - - comp = cal_component_clone (event->comp); - cal_comp_util_add_exdate (comp, event->start, day_view->zone); - - /* For the unrecurred instance we duplicate the original object, - create a new uid for it, get rid of the recurrence rules, and set - the start & end times to the instances times. */ - new_comp = cal_component_clone (event->comp); - cal_component_set_uid (new_comp, cal_component_gen_uid ()); - cal_component_set_rdate_list (new_comp, NULL); - cal_component_set_rrule_list (new_comp, NULL); - cal_component_set_exdate_list (new_comp, NULL); - cal_component_set_exrule_list (new_comp, NULL); - - date.value = &itt; - date.tzid = icaltimezone_get_tzid (day_view->zone); - - *date.value = icaltime_from_timet_with_zone (event->start, FALSE, - day_view->zone); - cal_component_set_dtstart (new_comp, &date); - *date.value = icaltime_from_timet_with_zone (event->end, FALSE, - day_view->zone); - cal_component_set_dtend (new_comp, &date); - - - /* Now update both CalComponents. Note that we do this last since at - * present the updates happen synchronously so our event may disappear. - */ - if (cal_client_update_object (day_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_day_view_on_unrecur_appointment(): Could not update the object!"); - - g_object_unref (comp); - - if (cal_client_update_object (day_view->client, new_comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_day_view_on_unrecur_appointment(): Could not update the object!"); - - g_object_unref (new_comp); -} - - -static EDayViewEvent* -e_day_view_get_popup_menu_event (EDayView *day_view) -{ - if (day_view->popup_event_num == -1) - return NULL; - - if (day_view->popup_event_day == E_DAY_VIEW_LONG_EVENT) - return &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->popup_event_num); - else - return &g_array_index (day_view->events[day_view->popup_event_day], - EDayViewEvent, - day_view->popup_event_num); -} - - -static gboolean -e_day_view_on_top_canvas_button_release (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view) -{ - if (day_view->selection_is_being_dragged) { - gdk_pointer_ungrab (event->time); - e_day_view_finish_selection (day_view); - } else if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - gdk_pointer_ungrab (event->time); - e_day_view_finish_long_event_resize (day_view); - } else if (day_view->pressed_event_day != -1) { - e_day_view_start_editing_event (day_view, - day_view->pressed_event_day, - day_view->pressed_event_num, - NULL); - } - - day_view->pressed_event_day = -1; - - return FALSE; -} - - -static gboolean -e_day_view_on_main_canvas_button_release (GtkWidget *widget, - GdkEventButton *event, - EDayView *day_view) -{ -#if 0 - g_print ("In e_day_view_on_main_canvas_button_release\n"); -#endif - - if (day_view->selection_is_being_dragged) { - gdk_pointer_ungrab (event->time); - e_day_view_finish_selection (day_view); - e_day_view_stop_auto_scroll (day_view); - } else if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - gdk_pointer_ungrab (event->time); - e_day_view_finish_resize (day_view); - e_day_view_stop_auto_scroll (day_view); - } else if (day_view->pressed_event_day != -1) { - e_day_view_start_editing_event (day_view, - day_view->pressed_event_day, - day_view->pressed_event_num, - NULL); - } - - day_view->pressed_event_day = -1; - - return FALSE; -} - - -static void -e_day_view_update_calendar_selection_time (EDayView *day_view) -{ - time_t start, end; - - e_day_view_get_selected_time_range (day_view, &start, &end); - -#if 0 - g_print ("Start: %s", ctime (&start)); - g_print ("End : %s", ctime (&end)); -#endif - - if (day_view->calendar) - gnome_calendar_set_selected_time_range (day_view->calendar, - start, end); -} - - -static gboolean -e_day_view_on_top_canvas_motion (GtkWidget *widget, - GdkEventMotion *mevent, - EDayView *day_view) -{ - EDayViewEvent *event = NULL; - EDayViewPosition pos; - gint event_x, event_y, canvas_x, canvas_y; - gint day, event_num; - GdkCursor *cursor; - -#if 0 - g_print ("In e_day_view_on_top_canvas_motion\n"); -#endif - - /* Convert the coords to the main canvas window, or return if the - window is not found. */ - if (!e_day_view_convert_event_coords (day_view, (GdkEvent*) mevent, - GTK_LAYOUT (widget)->bin_window, - &event_x, &event_y)) - return FALSE; - - canvas_x = event_x; - canvas_y = event_y; - - pos = e_day_view_convert_position_in_top_canvas (day_view, - canvas_x, canvas_y, - &day, &event_num); - if (event_num != -1) - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - if (day_view->selection_is_being_dragged) { - e_day_view_update_selection (day_view, day, -1); - return TRUE; - } else if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - e_day_view_update_long_event_resize (day_view, day); - return TRUE; - } - } else if (day_view->pressed_event_day == E_DAY_VIEW_LONG_EVENT) { - GtkTargetList *target_list; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - day_view->pressed_event_num); - - if ((cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp)) - && (abs (canvas_x - day_view->drag_event_x) - > E_DAY_VIEW_DRAG_START_OFFSET - || abs (canvas_y - day_view->drag_event_y) - > E_DAY_VIEW_DRAG_START_OFFSET)) { - day_view->drag_event_day = day_view->pressed_event_day; - day_view->drag_event_num = day_view->pressed_event_num; - day_view->pressed_event_day = -1; - - /* Hide the horizontal bars. */ - if (day_view->resize_bars_event_day != -1) { - day_view->resize_bars_event_day = -1; - day_view->resize_bars_event_num = -1; - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - } - - target_list = gtk_target_list_new (target_table, - n_targets); - gtk_drag_begin (widget, target_list, - GDK_ACTION_COPY | GDK_ACTION_MOVE, - 1, (GdkEvent*)mevent); - gtk_target_list_unref (target_list); - } - } else { - cursor = day_view->normal_cursor; - - /* Recurring events can't be resized. */ - if (event && (cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp))) { - switch (pos) { - case E_DAY_VIEW_POS_LEFT_EDGE: - case E_DAY_VIEW_POS_RIGHT_EDGE: - cursor = day_view->resize_width_cursor; - break; - default: - break; - } - } - - /* Only set the cursor if it is different to last one set. */ - if (day_view->last_cursor_set_in_top_canvas != cursor) { - day_view->last_cursor_set_in_top_canvas = cursor; - gdk_window_set_cursor (widget->window, cursor); - } - - } - - return FALSE; -} - - -static gboolean -e_day_view_on_main_canvas_motion (GtkWidget *widget, - GdkEventMotion *mevent, - EDayView *day_view) -{ - EDayViewEvent *event = NULL; - EDayViewPosition pos; - gint event_x, event_y, canvas_x, canvas_y; - gint row, day, event_num; - GdkCursor *cursor; - -#if 0 - g_print ("In e_day_view_on_main_canvas_motion\n"); -#endif - - /* Convert the coords to the main canvas window, or return if the - window is not found. */ - if (!e_day_view_convert_event_coords (day_view, (GdkEvent*) mevent, - GTK_LAYOUT (widget)->bin_window, - &event_x, &event_y)) - return FALSE; - - canvas_x = event_x; - canvas_y = event_y; - - pos = e_day_view_convert_position_in_main_canvas (day_view, - canvas_x, canvas_y, - &day, &row, - &event_num); - if (event_num != -1) - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - if (day_view->selection_is_being_dragged) { - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - e_day_view_update_selection (day_view, day, row); - e_day_view_check_auto_scroll (day_view, - event_x, event_y); - return TRUE; - } - } else if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - e_day_view_update_resize (day_view, row); - e_day_view_check_auto_scroll (day_view, - event_x, event_y); - return TRUE; - } - } else if (day_view->pressed_event_day != -1 - && day_view->pressed_event_day != E_DAY_VIEW_LONG_EVENT) { - GtkTargetList *target_list; - - event = &g_array_index (day_view->events[day_view->pressed_event_day], EDayViewEvent, day_view->pressed_event_num); - - if ((cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp)) - && (abs (canvas_x - day_view->drag_event_x) - > E_DAY_VIEW_DRAG_START_OFFSET - || abs (canvas_y - day_view->drag_event_y) - > E_DAY_VIEW_DRAG_START_OFFSET)) { - day_view->drag_event_day = day_view->pressed_event_day; - day_view->drag_event_num = day_view->pressed_event_num; - day_view->pressed_event_day = -1; - - /* Hide the horizontal bars. */ - if (day_view->resize_bars_event_day != -1) { - day_view->resize_bars_event_day = -1; - day_view->resize_bars_event_num = -1; - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - } - - target_list = gtk_target_list_new (target_table, - n_targets); - gtk_drag_begin (widget, target_list, - GDK_ACTION_COPY | GDK_ACTION_MOVE, - 1, (GdkEvent*)mevent); - gtk_target_list_unref (target_list); - } - } else { - cursor = day_view->normal_cursor; - - /* Recurring events can't be resized. */ - if (event && (cal_component_is_instance (event->comp) || !cal_component_has_recurrences (event->comp))) { - switch (pos) { - case E_DAY_VIEW_POS_LEFT_EDGE: - cursor = day_view->move_cursor; - break; - case E_DAY_VIEW_POS_TOP_EDGE: - case E_DAY_VIEW_POS_BOTTOM_EDGE: - cursor = day_view->resize_height_cursor; - break; - default: - break; - } - } - - /* Only set the cursor if it is different to last one set. */ - if (day_view->last_cursor_set_in_main_canvas != cursor) { - day_view->last_cursor_set_in_main_canvas = cursor; - gdk_window_set_cursor (widget->window, cursor); - } - } - - return FALSE; -} - - -/* This sets the selection to a single cell. If day is -1 then the current - start day is reused. If row is -1 then the selection is in the top canvas. -*/ -void -e_day_view_start_selection (EDayView *day_view, - gint day, - gint row) -{ - if (day == -1) { - day = day_view->selection_start_day; - if (day == -1) - day = 0; - } - - day_view->selection_start_day = day; - day_view->selection_end_day = day; - - day_view->selection_start_row = row; - day_view->selection_end_row = row; - - day_view->selection_is_being_dragged = TRUE; - day_view->selection_drag_pos = E_DAY_VIEW_DRAG_END; - day_view->selection_in_top_canvas = (row == -1) ? TRUE : FALSE; - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -/* Updates the selection during a drag. If day is -1 the selection day is - unchanged. */ -void -e_day_view_update_selection (EDayView *day_view, - gint day, - gint row) -{ - gboolean need_redraw = FALSE; - -#if 0 - g_print ("Updating selection %i,%i\n", day, row); -#endif - - day_view->selection_in_top_canvas = (row == -1) ? TRUE : FALSE; - - if (day == -1) - day = (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - ? day_view->selection_start_day - : day_view->selection_end_day; - - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) { - if (row != day_view->selection_start_row - || day != day_view->selection_start_day) { - need_redraw = TRUE; - day_view->selection_start_row = row; - day_view->selection_start_day = day; - } - } else { - if (row != day_view->selection_end_row - || day != day_view->selection_end_day) { - need_redraw = TRUE; - day_view->selection_end_row = row; - day_view->selection_end_day = day; - } - } - - e_day_view_normalize_selection (day_view); - - /* FIXME: Optimise? */ - if (need_redraw) { - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - - -static void -e_day_view_normalize_selection (EDayView *day_view) -{ - gint tmp_row, tmp_day; - - /* Switch the drag position if necessary. */ - if (day_view->selection_start_day > day_view->selection_end_day - || (day_view->selection_start_day == day_view->selection_end_day - && day_view->selection_start_row > day_view->selection_end_row)) { - tmp_row = day_view->selection_start_row; - tmp_day = day_view->selection_start_day; - day_view->selection_start_day = day_view->selection_end_day; - day_view->selection_start_row = day_view->selection_end_row; - day_view->selection_end_day = tmp_day; - day_view->selection_end_row = tmp_row; - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - day_view->selection_drag_pos = E_DAY_VIEW_DRAG_END; - else - day_view->selection_drag_pos = E_DAY_VIEW_DRAG_START; - } -} - - -void -e_day_view_finish_selection (EDayView *day_view) -{ - day_view->selection_is_being_dragged = FALSE; - e_day_view_update_calendar_selection_time (day_view); -} - -static void -e_day_view_update_long_event_resize (EDayView *day_view, - gint day) -{ - EDayViewEvent *event; - gint event_num; - gboolean need_reshape = FALSE; - -#if 0 - g_print ("Updating resize Day:%i\n", day); -#endif - - event_num = day_view->resize_event_num; - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_LEFT_EDGE) { - day = MIN (day, day_view->resize_end_row); - if (day != day_view->resize_start_row) { - need_reshape = TRUE; - day_view->resize_start_row = day; - - } - } else { - day = MAX (day, day_view->resize_start_row); - if (day != day_view->resize_end_row) { - need_reshape = TRUE; - day_view->resize_end_row = day; - } - } - - /* FIXME: Optimise? */ - if (need_reshape) { - e_day_view_reshape_long_event (day_view, event_num); - e_day_view_reshape_resize_long_event_rect_item (day_view); - gtk_widget_queue_draw (day_view->top_canvas); - } -} - - -static void -e_day_view_update_resize (EDayView *day_view, - gint row) -{ - EDayViewEvent *event; - gint day, event_num; - gboolean need_reshape = FALSE; - -#if 0 - g_print ("Updating resize Row:%i\n", row); -#endif - - day = day_view->resize_event_day; - event_num = day_view->resize_event_num; - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_TOP_EDGE) { - row = MIN (row, day_view->resize_end_row); - if (row != day_view->resize_start_row) { - need_reshape = TRUE; - day_view->resize_start_row = row; - - } - } else { - row = MAX (row, day_view->resize_start_row); - if (row != day_view->resize_end_row) { - need_reshape = TRUE; - day_view->resize_end_row = row; - } - } - - /* FIXME: Optimise? */ - if (need_reshape) { - e_day_view_reshape_day_event (day_view, day, event_num); - e_day_view_reshape_resize_rect_item (day_view); - e_day_view_reshape_main_canvas_resize_bars (day_view); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - - -/* This converts the resize start or end row back to a time and updates the - event. */ -static void -e_day_view_finish_long_event_resize (EDayView *day_view) -{ - EDayViewEvent *event; - gint event_num; - CalComponent *comp; - CalComponentDateTime date; - struct icaltimetype itt; - time_t dt; - - event_num = day_view->resize_event_num; - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - /* We use a temporary copy of the comp since we don't want to - change the original comp here. Otherwise we would not detect that - the event's time had changed in the "update_event" callback. */ - comp = cal_component_clone (event->comp); - - date.value = &itt; - /* FIXME: Should probably keep the timezone of the original start - and end times. */ - date.tzid = icaltimezone_get_tzid (day_view->zone); - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_LEFT_EDGE) { - dt = day_view->day_starts[day_view->resize_start_row]; - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtstart (comp, &date); - } else { - dt = day_view->day_starts[day_view->resize_end_row + 1]; - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtend (comp, &date); - } - - if (cal_component_is_instance (comp)) { - CalObjModType mod; - - if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - } else { - g_message ("e_day_view_finish_resize(): Could not update the object!"); - } - } else { - gtk_widget_queue_draw (day_view->top_canvas); - } - } else if (cal_client_update_object (day_view->client, comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - } else { - g_message ("e_day_view_finish_long_event_resize(): Could not update the object!"); - } - - gnome_canvas_item_hide (day_view->resize_long_event_rect_item); - - day_view->resize_drag_pos = E_DAY_VIEW_POS_NONE; - - g_object_unref (comp); -} - - -/* This converts the resize start or end row back to a time and updates the - event. */ -static void -e_day_view_finish_resize (EDayView *day_view) -{ - EDayViewEvent *event; - gint day, event_num; - CalComponent *comp; - CalComponentDateTime date; - struct icaltimetype itt; - time_t dt; - - day = day_view->resize_event_day; - event_num = day_view->resize_event_num; - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* We use a temporary shallow copy of the ico since we don't want to - change the original ico here. Otherwise we would not detect that - the event's time had changed in the "update_event" callback. */ - comp = cal_component_clone (event->comp); - - date.value = &itt; - /* FIXME: Should probably keep the timezone of the original start - and end times. */ - date.tzid = icaltimezone_get_tzid (day_view->zone); - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_TOP_EDGE) { - dt = e_day_view_convert_grid_position_to_time (day_view, day, day_view->resize_start_row); - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtstart (comp, &date); - } else { - dt = e_day_view_convert_grid_position_to_time (day_view, day, day_view->resize_end_row + 1); - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtend (comp, &date); - } - - if (cal_component_is_instance (comp)) { - CalObjModType mod; - - if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - } else { - g_message ("e_day_view_finish_resize(): Could not update the object!"); - } - } else { - gtk_widget_queue_draw (day_view->main_canvas); - } - } else if (cal_client_update_object (day_view->client, comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - } else { - g_message ("e_day_view_finish_resize(): Could not update the object!"); - } - - gnome_canvas_item_hide (day_view->resize_rect_item); - gnome_canvas_item_hide (day_view->resize_bar_item); - - /* Hide the horizontal bars. */ - day_view->resize_bars_event_day = -1; - day_view->resize_bars_event_num = -1; - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - - day_view->resize_drag_pos = E_DAY_VIEW_POS_NONE; - - g_object_unref (comp); -} - - -static void -e_day_view_abort_resize (EDayView *day_view, - guint32 time) -{ - gint day, event_num; - - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_NONE) - return; - - day_view->resize_drag_pos = E_DAY_VIEW_POS_NONE; - gdk_pointer_ungrab (time); - - day = day_view->resize_event_day; - event_num = day_view->resize_event_num; - - if (day == E_DAY_VIEW_LONG_EVENT) { - e_day_view_reshape_long_event (day_view, event_num); - gtk_widget_queue_draw (day_view->top_canvas); - - day_view->last_cursor_set_in_top_canvas = day_view->normal_cursor; - gdk_window_set_cursor (day_view->top_canvas->window, - day_view->normal_cursor); - gnome_canvas_item_hide (day_view->resize_long_event_rect_item); - } else { - e_day_view_reshape_day_event (day_view, day, event_num); - e_day_view_reshape_main_canvas_resize_bars (day_view); - gtk_widget_queue_draw (day_view->main_canvas); - - day_view->last_cursor_set_in_main_canvas = day_view->normal_cursor; - gdk_window_set_cursor (day_view->main_canvas->window, - day_view->normal_cursor); - gnome_canvas_item_hide (day_view->resize_rect_item); - gnome_canvas_item_hide (day_view->resize_bar_item); - } -} - - -static void -e_day_view_free_events (EDayView *day_view) -{ - gint day; - - /* Reset all our indices. */ - day_view->editing_event_day = -1; - day_view->popup_event_day = -1; - day_view->resize_bars_event_day = -1; - day_view->resize_event_day = -1; - day_view->pressed_event_day = -1; - day_view->drag_event_day = -1; - - e_day_view_free_event_array (day_view, day_view->long_events); - - for (day = 0; day < E_DAY_VIEW_MAX_DAYS; day++) - e_day_view_free_event_array (day_view, day_view->events[day]); -} - - -static void -e_day_view_free_event_array (EDayView *day_view, - GArray *array) -{ - EDayViewEvent *event; - gint event_num; - - for (event_num = 0; event_num < array->len; event_num++) { - event = &g_array_index (array, EDayViewEvent, event_num); - if (event->canvas_item) - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - g_object_unref (event->comp); - } - - g_array_set_size (array, 0); -} - - -/* This adds one event to the view, adding it to the appropriate array. */ -static gboolean -e_day_view_add_event (CalComponent *comp, - time_t start, - time_t end, - gpointer data) - -{ - EDayView *day_view; - EDayViewEvent event; - gint day, offset; - struct icaltimetype start_tt, end_tt; - - day_view = E_DAY_VIEW (data); - -#if 0 - g_print ("Day view lower: %s", ctime (&day_view->lower)); - g_print ("Day view upper: %s", ctime (&day_view->upper)); - g_print ("Event start: %s", ctime (&start)); - g_print ("Event end : %s\n", ctime (&end)); -#endif - - /* Check that the event times are valid. */ - g_return_val_if_fail (start <= end, TRUE); - g_return_val_if_fail (start < day_view->upper, TRUE); - g_return_val_if_fail (end > day_view->lower, TRUE); - - start_tt = icaltime_from_timet_with_zone (start, FALSE, - day_view->zone); - end_tt = icaltime_from_timet_with_zone (end, FALSE, - day_view->zone); - - event.comp = comp; - g_object_ref (comp); - event.start = start; - event.end = end; - event.canvas_item = NULL; - - /* Calculate the start & end minute, relative to the top of the - display. */ - offset = day_view->first_hour_shown * 60 - + day_view->first_minute_shown; - event.start_minute = start_tt.hour * 60 + start_tt.minute - offset; - event.end_minute = end_tt.hour * 60 + end_tt.minute - offset; - - event.start_row_or_col = 0; - event.num_columns = 0; - - event.different_timezone = FALSE; - if (!cal_comp_util_compare_event_timezones (comp, day_view->client, - day_view->zone)) - event.different_timezone = TRUE; - - /* Find out which array to add the event to. */ - for (day = 0; day < day_view->days_shown; day++) { - if (start >= day_view->day_starts[day] - && end <= day_view->day_starts[day + 1]) { - - /* Special case for when the appointment ends at - midnight, i.e. the start of the next day. */ - if (end == day_view->day_starts[day + 1]) { - - /* If the event last the entire day, then we - skip it here so it gets added to the top - canvas. */ - if (start == day_view->day_starts[day]) - break; - - event.end_minute = 24 * 60; - } - - g_array_append_val (day_view->events[day], event); - day_view->events_sorted[day] = FALSE; - day_view->need_layout[day] = TRUE; - return TRUE; - } - } - - /* The event wasn't within one day so it must be a long event, - i.e. shown in the top canvas. */ - g_array_append_val (day_view->long_events, event); - day_view->long_events_sorted = FALSE; - day_view->long_events_need_layout = TRUE; - return TRUE; -} - - -/* This lays out the short (less than 1 day) events in the columns. - Any long events are simply skipped. */ -void -e_day_view_check_layout (EDayView *day_view) -{ - gint day, rows_in_top_display, top_canvas_height, top_rows; - - /* Don't bother if we aren't visible. */ - if (!GTK_WIDGET_VISIBLE (day_view)) - return; - - /* Make sure the events are sorted (by start and size). */ - e_day_view_ensure_events_sorted (day_view); - - for (day = 0; day < day_view->days_shown; day++) { - if (day_view->need_layout[day]) - e_day_view_layout_day_events (day_view->events[day], - day_view->rows, - day_view->mins_per_row, - day_view->cols_per_row[day]); - - if (day_view->need_layout[day] - || day_view->need_reshape[day]) { - e_day_view_reshape_day_events (day_view, day); - - if (day_view->resize_bars_event_day == day) - e_day_view_reshape_main_canvas_resize_bars (day_view); - } - - day_view->need_layout[day] = FALSE; - day_view->need_reshape[day] = FALSE; - } - - if (day_view->long_events_need_layout) { - e_day_view_layout_long_events (day_view->long_events, - day_view->days_shown, - day_view->day_starts, - &rows_in_top_display); - - /* Set the height of the top canvas based on the row height - and the number of rows needed (min 1 + 1 for the dates + 1 - space for DnD).*/ - if (day_view->rows_in_top_display != rows_in_top_display) { - day_view->rows_in_top_display = rows_in_top_display; - top_rows = MAX (1, rows_in_top_display); - top_canvas_height = (top_rows + 2) - * day_view->top_row_height; - gtk_widget_set_usize (day_view->top_canvas, -1, - top_canvas_height); - } - } - - - if (day_view->long_events_need_layout - || day_view->long_events_need_reshape) - e_day_view_reshape_long_events (day_view); - - day_view->long_events_need_layout = FALSE; - day_view->long_events_need_reshape = FALSE; -} - - -static void -e_day_view_reshape_long_events (EDayView *day_view) -{ - EDayViewEvent *event; - gint event_num; - - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - if (event->num_columns == 0) { - if (event->canvas_item) { - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - event->canvas_item = NULL; - } - } else { - e_day_view_reshape_long_event (day_view, event_num); - } - } -} - - -static void -e_day_view_reshape_long_event (EDayView *day_view, - gint event_num) -{ - EDayViewEvent *event; - gint start_day, end_day, item_x, item_y, item_w, item_h; - gint text_x, text_w, num_icons, icons_width, width, time_width; - CalComponent *comp; - gint min_text_x, max_text_w, text_width, line_len; - gchar *text, *end_of_line; - gboolean show_icons = TRUE, use_max_width = FALSE; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoLayout *layout; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - if (!e_day_view_get_long_event_position (day_view, event_num, - &start_day, &end_day, - &item_x, &item_y, - &item_w, &item_h)) { - if (event->canvas_item) { - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - event->canvas_item = NULL; - } - return; - } - - /* Take off the border and padding. */ - item_x += E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD; - item_w -= (E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD) * 2; - item_y += E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD; - item_h -= (E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD) * 2; - - /* We don't show the icons while resizing, since we'd have to - draw them on top of the resize rect. Nor when editing. */ - num_icons = 0; - comp = event->comp; - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (GTK_WIDGET (day_view))->font_desc; - pango_context = gtk_widget_get_pango_context (GTK_WIDGET (day_view)); - layout = pango_layout_new (pango_context); - - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE - && day_view->resize_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->resize_event_num == event_num) - show_icons = FALSE; - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->editing_event_num == event_num) { - show_icons = FALSE; - use_max_width = TRUE; - } - - if (show_icons) { - GSList *categories_list, *elem; - - if (cal_component_has_alarms (comp)) - num_icons++; - if (cal_component_has_recurrences (comp)) - num_icons++; - if (event->different_timezone) - num_icons++; - if (cal_component_has_organizer (comp)) - num_icons++; - - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (e_categories_config_get_icon_for (category, &pixmap, &mask)) - num_icons++; - } - cal_component_free_categories_list (categories_list); - } - - if (!event->canvas_item) { - event->canvas_item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (day_view->top_canvas)->root), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "max_lines", 1, - "editable", TRUE, - "use_ellipsis", TRUE, - "draw_background", FALSE, - "fill_color_rgba", GNOME_CANVAS_COLOR(0, 0, 0), - "im_context", E_CANVAS (day_view->top_canvas)->im_context, - NULL); - g_signal_connect (event->canvas_item, "event", - G_CALLBACK (e_day_view_on_text_item_event), day_view); - e_day_view_update_long_event_label (day_view, event_num); - } - - /* Calculate its position. We first calculate the ideal position which - is centered with the icons. We then make sure we haven't gone off - the left edge of the available space. Finally we make sure we don't - go off the right edge. */ - icons_width = (E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD) - * num_icons + E_DAY_VIEW_LONG_EVENT_ICON_R_PAD; - time_width = e_day_view_get_time_string_width (day_view); - - if (use_max_width) { - text_x = item_x; - text_w = item_w; - } else { - /* Get the requested size of the label. */ - g_object_get (G_OBJECT (event->canvas_item), "text", &text, NULL); - text_width = 0; - if (text) { - end_of_line = strchr (text, '\n'); - if (end_of_line) - line_len = end_of_line - text; - else - line_len = strlen (text); - pango_layout_set_text (layout, text, line_len); - pango_layout_get_pixel_size (layout, &text_width, NULL); - g_free (text); - } - - width = text_width + icons_width; - text_x = item_x + (item_w - width) / 2; - - min_text_x = item_x; - if (event->start > day_view->day_starts[start_day]) - min_text_x += time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; - - text_x = MAX (text_x, min_text_x); - - max_text_w = item_x + item_w - text_x; - if (event->end < day_view->day_starts[end_day + 1]) - max_text_w -= time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; - - text_w = MIN (width, max_text_w); - - /* Now take out the space for the icons. */ - text_x += icons_width; - text_w -= icons_width; - } - - text_w = MAX (text_w, 0); - gnome_canvas_item_set (event->canvas_item, - "clip_width", (gdouble) text_w, - "clip_height", (gdouble) item_h, - NULL); - e_canvas_item_move_absolute(event->canvas_item, - text_x, item_y); - - g_object_unref (layout); -} - - -/* This creates or updates the sizes of the canvas items for one day of the - main canvas. */ -static void -e_day_view_reshape_day_events (EDayView *day_view, - gint day) -{ - gint event_num; - - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - e_day_view_reshape_day_event (day_view, day, event_num); - } -} - - -static void -e_day_view_reshape_day_event (EDayView *day_view, - gint day, - gint event_num) -{ - EDayViewEvent *event; - gint item_x, item_y, item_w, item_h; - gint num_icons, icons_offset; - CalComponent *comp; - - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - comp = event->comp; - - if (!e_day_view_get_event_position (day_view, day, event_num, - &item_x, &item_y, - &item_w, &item_h)) { - if (event->canvas_item) { - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - event->canvas_item = NULL; - } - } else { - /* Skip the border and padding. */ - item_x += E_DAY_VIEW_BAR_WIDTH + E_DAY_VIEW_EVENT_X_PAD; - item_w -= E_DAY_VIEW_BAR_WIDTH + E_DAY_VIEW_EVENT_X_PAD * 2; - item_y += E_DAY_VIEW_EVENT_BORDER_HEIGHT + E_DAY_VIEW_EVENT_Y_PAD; - item_h -= (E_DAY_VIEW_EVENT_BORDER_HEIGHT + E_DAY_VIEW_EVENT_Y_PAD) * 2; - - /* We don't show the icons while resizing, since we'd have to - draw them on top of the resize rect. */ - num_icons = 0; - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_NONE - || day_view->resize_event_day != day - || day_view->resize_event_num != event_num) { - GSList *categories_list, *elem; - - if (cal_component_has_alarms (comp)) - num_icons++; - if (cal_component_has_recurrences (comp)) - num_icons++; - if (event->different_timezone) - num_icons++; - if (cal_component_has_organizer (comp)) - num_icons++; - - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (e_categories_config_get_icon_for (category, &pixmap, &mask)) - num_icons++; - } - cal_component_free_categories_list (categories_list); - } - - if (num_icons > 0) { - if (item_h >= (E_DAY_VIEW_ICON_HEIGHT + E_DAY_VIEW_ICON_Y_PAD) * num_icons) - icons_offset = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD * 2; - else - icons_offset = (E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD) * num_icons + E_DAY_VIEW_ICON_X_PAD; - item_x += icons_offset; - item_w -= icons_offset; - } - - if (!event->canvas_item) { - event->canvas_item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (day_view->main_canvas)->root), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "line_wrap", TRUE, - "editable", TRUE, - "clip", TRUE, - "use_ellipsis", TRUE, - "draw_background", FALSE, - "fill_color_rgba", GNOME_CANVAS_COLOR(0, 0, 0), - "im_context", E_CANVAS (day_view->main_canvas)->im_context, - NULL); - g_signal_connect (event->canvas_item, "event", - G_CALLBACK (e_day_view_on_text_item_event), day_view); - e_day_view_update_event_label (day_view, day, event_num); - } - - item_w = MAX (item_w, 0); - gnome_canvas_item_set (event->canvas_item, - "clip_width", (gdouble) item_w, - "clip_height", (gdouble) item_h, - NULL); - e_canvas_item_move_absolute(event->canvas_item, - item_x, item_y); - } -} - - -/* This creates or resizes the horizontal bars used to resize events in the - main canvas. */ -static void -e_day_view_reshape_main_canvas_resize_bars (EDayView *day_view) -{ - gint day, event_num; - gint item_x, item_y, item_w, item_h; - gdouble x, y, w, h; - - day = day_view->resize_bars_event_day; - event_num = day_view->resize_bars_event_num; - - /* If we're not editing an event, or the event is not shown, - hide the resize bars. */ - if (day != -1 && day == day_view->drag_event_day - && event_num == day_view->drag_event_num) { - g_object_get (G_OBJECT (day_view->drag_rect_item), - "x1", &x, - "y1", &y, - "x2", &w, - "y2", &h, - NULL); - w -= x; - x++; - h -= y; - } else if (day != -1 - && e_day_view_get_event_position (day_view, day, event_num, - &item_x, &item_y, - &item_w, &item_h)) { - x = item_x + E_DAY_VIEW_BAR_WIDTH; - y = item_y; - w = item_w - E_DAY_VIEW_BAR_WIDTH; - h = item_h; - } else { - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - return; - } - - gnome_canvas_item_set (day_view->main_canvas_top_resize_bar_item, - "x1", x - E_DAY_VIEW_BAR_WIDTH, - "y1", y - E_DAY_VIEW_BAR_HEIGHT, - "x2", x + w - 1, - "y2", y - 1, - NULL); - gnome_canvas_item_show (day_view->main_canvas_top_resize_bar_item); - - gnome_canvas_item_set (day_view->main_canvas_bottom_resize_bar_item, - "x1", x - E_DAY_VIEW_BAR_WIDTH, - "y1", y + h, - "x2", x + w - 1, - "y2", y + h + E_DAY_VIEW_BAR_HEIGHT - 1, - NULL); - gnome_canvas_item_show (day_view->main_canvas_bottom_resize_bar_item); -} - - -static void -e_day_view_ensure_events_sorted (EDayView *day_view) -{ - gint day; - - /* Sort the long events. */ - if (!day_view->long_events_sorted) { - qsort (day_view->long_events->data, - day_view->long_events->len, - sizeof (EDayViewEvent), - e_day_view_event_sort_func); - day_view->long_events_sorted = TRUE; - } - - /* Sort the events for each day. */ - for (day = 0; day < day_view->days_shown; day++) { - if (!day_view->events_sorted[day]) { - qsort (day_view->events[day]->data, - day_view->events[day]->len, - sizeof (EDayViewEvent), - e_day_view_event_sort_func); - day_view->events_sorted[day] = TRUE; - } - } -} - - -gint -e_day_view_event_sort_func (const void *arg1, - const void *arg2) -{ - EDayViewEvent *event1, *event2; - - event1 = (EDayViewEvent*) arg1; - event2 = (EDayViewEvent*) arg2; - - if (event1->start < event2->start) - return -1; - if (event1->start > event2->start) - return 1; - - if (event1->end > event2->end) - return -1; - if (event1->end < event2->end) - return 1; - - return 0; -} - - -static gint -e_day_view_key_press (GtkWidget *widget, GdkEventKey *event) -{ - EDayView *day_view; - CalComponent *comp; - gint day, event_num; - gchar *initial_text; - guint keyval; - gboolean stop_emission; - time_t dtstart, dtend; - CalComponentDateTime start_dt, end_dt; - struct icaltimetype start_tt, end_tt; - const char *uid; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_DAY_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - day_view = E_DAY_VIEW (widget); - keyval = event->keyval; - - if (!(day_view->client && cal_client_get_load_state (day_view->client) == CAL_CLIENT_LOAD_LOADED)) - return TRUE; - - /* The Escape key aborts a resize operation. */ - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - if (keyval == GDK_Escape) { - e_day_view_abort_resize (day_view, event->time); - } - return FALSE; - } - - /* Handle the cursor keys for moving & extending the selection. */ - stop_emission = TRUE; - if (event->state & GDK_SHIFT_MASK) { - switch (keyval) { - case GDK_Up: - e_day_view_cursor_key_up_shifted (day_view, event); - break; - case GDK_Down: - e_day_view_cursor_key_down_shifted (day_view, event); - break; - case GDK_Left: - e_day_view_cursor_key_left_shifted (day_view, event); - break; - case GDK_Right: - e_day_view_cursor_key_right_shifted (day_view, event); - break; - default: - stop_emission = FALSE; - break; - } - } else { - switch (keyval) { - case GDK_Up: - e_day_view_cursor_key_up (day_view, event); - break; - case GDK_Down: - e_day_view_cursor_key_down (day_view, event); - break; - case GDK_Left: - e_day_view_cursor_key_left (day_view, event); - break; - case GDK_Right: - e_day_view_cursor_key_right (day_view, event); - break; - case GDK_Page_Up: - e_day_view_scroll (day_view, E_DAY_VIEW_PAGE_STEP); - break; - case GDK_Page_Down: - e_day_view_scroll (day_view, -E_DAY_VIEW_PAGE_STEP); - break; - default: - stop_emission = FALSE; - break; - } - } - if (stop_emission) - return TRUE; - - if (day_view->selection_start_day == -1) - return FALSE; - - /* Check if there is room for a new event to be typed in. If there - isn't we don't want to add an event as we will then add a new - event for every key press. */ - if (!e_day_view_check_if_new_event_fits (day_view)) { - return FALSE; - } - - /* We only want to start an edit with a return key or a simple - character. */ - if (keyval == GDK_Return) { - initial_text = NULL; - } else if (((keyval >= 0x20) && (keyval <= 0xFF) - && (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - || (event->length == 0) - || (keyval == GDK_Tab)) { - return FALSE; - } else - initial_text = e_utf8_from_gtk_event_key (widget, event->keyval, event->string); - - /* Add a new event covering the selected range */ - - comp = cal_comp_event_new_with_defaults (day_view->client); - - e_day_view_get_selected_time_range (day_view, &dtstart, &dtend); - - start_tt = icaltime_from_timet_with_zone (dtstart, FALSE, - day_view->zone); - - end_tt = icaltime_from_timet_with_zone (dtend, FALSE, - day_view->zone); - - if (day_view->selection_in_top_canvas) { - start_dt.tzid = NULL; - start_tt.is_date = 1; - end_tt.is_date = 1; - } else { - start_dt.tzid = icaltimezone_get_tzid (day_view->zone); - } - - start_dt.value = &start_tt; - end_dt.value = &end_tt; - end_dt.tzid = start_dt.tzid; - cal_component_set_dtstart (comp, &start_dt); - cal_component_set_dtend (comp, &end_dt); - - cal_component_set_categories (comp, day_view->default_category); - - /* We add the event locally and start editing it. We don't send it - to the server until the user finishes editing it. */ - e_day_view_add_event (comp, dtstart, dtend, day_view); - e_day_view_check_layout (day_view); - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - - cal_component_get_uid (comp, &uid); - if (e_day_view_find_event_from_uid (day_view, uid, &day, &event_num)) { - e_day_view_start_editing_event (day_view, day, event_num, - initial_text); - } else { - g_warning ("Couldn't find event to start editing.\n"); - } - - if (initial_text) - g_free (initial_text); - - g_object_unref (comp); - - return TRUE; -} - - -static void -e_day_view_cursor_key_up_shifted (EDayView *day_view, GdkEventKey *event) -{ - gint *row; - - if (day_view->selection_in_top_canvas) - return; - - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - row = &day_view->selection_start_row; - else - row = &day_view->selection_end_row; - - if (*row == 0) - return; - - *row = *row - 1; - - e_day_view_ensure_rows_visible (day_view, *row, *row); - - e_day_view_normalize_selection (day_view); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_down_shifted (EDayView *day_view, GdkEventKey *event) -{ - gint *row; - - if (day_view->selection_in_top_canvas) - return; - - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - row = &day_view->selection_start_row; - else - row = &day_view->selection_end_row; - - if (*row >= day_view->rows - 1) - return; - - *row = *row + 1; - - e_day_view_ensure_rows_visible (day_view, *row, *row); - - e_day_view_normalize_selection (day_view); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_left_shifted (EDayView *day_view, GdkEventKey *event) -{ - gint *day; - - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - day = &day_view->selection_start_day; - else - day = &day_view->selection_end_day; - - if (*day == 0) - return; - - *day = *day - 1; - - e_day_view_normalize_selection (day_view); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_right_shifted (EDayView *day_view, GdkEventKey *event) -{ - gint *day; - - if (day_view->selection_drag_pos == E_DAY_VIEW_DRAG_START) - day = &day_view->selection_start_day; - else - day = &day_view->selection_end_day; - - if (*day >= day_view->days_shown - 1) - return; - - *day = *day + 1; - - e_day_view_normalize_selection (day_view); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_up (EDayView *day_view, GdkEventKey *event) -{ - if (day_view->selection_start_day == -1) { - day_view->selection_start_day = 0; - day_view->selection_start_row = 0; - } - day_view->selection_end_day = day_view->selection_start_day; - - if (day_view->selection_in_top_canvas) { - return; - } else if (day_view->selection_start_row == 0) { - day_view->selection_in_top_canvas = TRUE; - day_view->selection_start_row = -1; - } else { - day_view->selection_start_row--; - } - day_view->selection_end_row = day_view->selection_start_row; - - if (!day_view->selection_in_top_canvas) - e_day_view_ensure_rows_visible (day_view, - day_view->selection_start_row, - day_view->selection_end_row); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_down (EDayView *day_view, GdkEventKey *event) -{ - if (day_view->selection_start_day == -1) { - day_view->selection_start_day = 0; - day_view->selection_start_row = 0; - } - day_view->selection_end_day = day_view->selection_start_day; - - if (day_view->selection_in_top_canvas) { - day_view->selection_in_top_canvas = FALSE; - day_view->selection_start_row = 0; - } else if (day_view->selection_start_row >= day_view->rows - 1) { - return; - } else { - day_view->selection_start_row++; - } - day_view->selection_end_row = day_view->selection_start_row; - - if (!day_view->selection_in_top_canvas) - e_day_view_ensure_rows_visible (day_view, - day_view->selection_start_row, - day_view->selection_end_row); - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); -} - - -static void -e_day_view_cursor_key_left (EDayView *day_view, GdkEventKey *event) -{ - if (day_view->selection_start_day == 0) { - if (day_view->calendar) - gnome_calendar_previous (day_view->calendar); - } else { - day_view->selection_start_day--; - day_view->selection_end_day--; - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - - -static void -e_day_view_cursor_key_right (EDayView *day_view, GdkEventKey *event) -{ - if (day_view->selection_end_day == day_view->days_shown - 1) { - if (day_view->calendar) - gnome_calendar_next (day_view->calendar); - } else { - day_view->selection_start_day++; - day_view->selection_end_day++; - - e_day_view_update_calendar_selection_time (day_view); - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - } -} - - -/* Scrolls the main canvas up or down. The pages_to_scroll argument - is multiplied with the adjustment's page size and added to the adjustment's - value, while ensuring we stay within the bounds. A positive value will - scroll the canvas down and a negative value will scroll it up. */ -static void -e_day_view_scroll (EDayView *day_view, - gfloat pages_to_scroll) -{ - GtkAdjustment *adj = GTK_LAYOUT (day_view->main_canvas)->vadjustment; - gfloat new_value; - - new_value = adj->value - adj->page_size * pages_to_scroll; - new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); - gtk_adjustment_set_value (adj, new_value); -} - - -static gboolean -e_day_view_check_if_new_event_fits (EDayView *day_view) -{ - gint day, start_row, end_row, row; - - day = day_view->selection_start_day; - start_row = day_view->selection_start_row; - end_row = day_view->selection_end_row; - - /* Long events always fit, since we keep adding rows to the top - canvas. */ - if (day != day_view->selection_end_day) - return TRUE; - if (start_row == 0 && end_row == day_view->rows) - return TRUE; - - /* If any of the rows already have E_DAY_VIEW_MAX_COLUMNS columns, - return FALSE. */ - for (row = start_row; row <= end_row; row++) { - if (day_view->cols_per_row[day][row] >= E_DAY_VIEW_MAX_COLUMNS) - return FALSE; - } - - return TRUE; -} - - -static void -e_day_view_ensure_rows_visible (EDayView *day_view, - gint start_row, - gint end_row) -{ - GtkAdjustment *adj; - gfloat value, min_value, max_value; - - adj = GTK_LAYOUT (day_view->main_canvas)->vadjustment; - - value = adj->value; - - min_value = (end_row + 1) * day_view->row_height - adj->page_size; - if (value < min_value) - value = min_value; - - max_value = start_row * day_view->row_height; - if (value > max_value) - value = max_value; - - if (value != adj->value) { - adj->value = value; - gtk_adjustment_value_changed (adj); - } -} - - -static void -e_day_view_start_editing_event (EDayView *day_view, - gint day, - gint event_num, - gchar *initial_text) -{ - EDayViewEvent *event; - ETextEventProcessor *event_processor = NULL; - ETextEventProcessorCommand command; - -#if 0 - g_print ("In e_day_view_start_editing_event\n"); -#endif - - /* If we are already editing the event, just return. */ - if (day == day_view->editing_event_day - && event_num == day_view->editing_event_num) - return; - - if (day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - } else { - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - } - - /* If the event is not shown, don't try to edit it. */ - if (!event->canvas_item) - return; - - /* We must grab the focus before setting the initial text, since - grabbing the focus will result in a call to - e_day_view_on_editing_started(), which will reset the text to get - rid of the start and end times. */ - e_canvas_item_grab_focus (event->canvas_item, TRUE); - - if (initial_text) { - gnome_canvas_item_set (event->canvas_item, - "text", initial_text, - NULL); - } - - /* Try to move the cursor to the end of the text. */ - g_object_get (G_OBJECT (event->canvas_item), - "event_processor", &event_processor, - NULL); - if (event_processor) { - command.action = E_TEP_MOVE; - command.position = E_TEP_END_OF_BUFFER; - g_signal_emit_by_name (event_processor, - "command", &command); - } -} - - -/* This stops the current edit. If accept is TRUE the event summary is updated, - else the edit is cancelled. */ -static void -e_day_view_stop_editing_event (EDayView *day_view) -{ - GtkWidget *toplevel; - - /* Check we are editing an event. */ - if (day_view->editing_event_day == -1) - return; - - /* Set focus to the toplevel so the item loses focus. */ - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (day_view)); - if (toplevel && GTK_IS_WINDOW (toplevel)) - gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); -} - - -/* Cancels the current edition by resetting the appointment's text to its original value */ -static void -cancel_editing (EDayView *day_view) -{ - int day, event_num; - EDayViewEvent *event; - CalComponentText summary; - - day = day_view->editing_event_day; - event_num = day_view->editing_event_num; - - g_assert (day != -1); - - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, EDayViewEvent, event_num); - else - event = &g_array_index (day_view->events[day], EDayViewEvent, event_num); - - /* Reset the text to what was in the component */ - - cal_component_get_summary (event->comp, &summary); - g_object_set (G_OBJECT (event->canvas_item), - "text", summary.value ? summary.value : "", - NULL); - - /* Stop editing */ - e_day_view_stop_editing_event (day_view); -} - - -static gboolean -e_day_view_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EDayView *day_view) -{ - switch (event->type) { - case GDK_KEY_PRESS: - if (event && event->key.keyval == GDK_Return) { - /* We set the keyboard focus to the EDayView, so the - EText item loses it and stops the edit. */ - gtk_widget_grab_focus (GTK_WIDGET (day_view)); - - /* Stop the signal last or we will also stop any - other events getting to the EText item. */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } else if (event->key.keyval == GDK_Escape) { - cancel_editing (day_view); - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - } - break; - case GDK_2BUTTON_PRESS: -#if 0 - g_print ("Item got double-click\n"); -#endif - break; - - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - /* Only let the EText handle the event while editing. */ - if (!E_TEXT (item)->editing) - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - break; - case GDK_FOCUS_CHANGE: - if (event->focus_change.in) - e_day_view_on_editing_started (day_view, item); - else - e_day_view_on_editing_stopped (day_view, item); - - return FALSE; - default: - break; - } - - return FALSE; -} - - -static void -e_day_view_on_editing_started (EDayView *day_view, - GnomeCanvasItem *item) -{ - gint day, event_num; - - if (!e_day_view_find_event_from_item (day_view, item, - &day, &event_num)) - return; - -#if 0 - g_print ("In e_day_view_on_editing_started Day:%i Event:%i\n", - day, event_num); -#endif - - /* FIXME: This is a temporary workaround for a bug which seems to stop - us getting focus_out signals. It is not a complete fix since if we - don't get focus_out signals we don't save the appointment text so - this may be lost. */ - if (day_view->editing_event_day == day - && day_view->editing_event_num == event_num) - return; - - day_view->editing_event_day = day; - day_view->editing_event_num = event_num; - - if (day == E_DAY_VIEW_LONG_EVENT) { - e_day_view_reshape_long_event (day_view, event_num); - } else { - day_view->resize_bars_event_day = day; - day_view->resize_bars_event_num = event_num; - e_day_view_update_event_label (day_view, day, event_num); - e_day_view_reshape_main_canvas_resize_bars (day_view); - } - - g_object_set (item, "handle_popup", TRUE, NULL); - - gtk_signal_emit (GTK_OBJECT (day_view), - e_day_view_signals[SELECTION_CHANGED]); -} - -static void -e_day_view_on_editing_stopped (EDayView *day_view, - GnomeCanvasItem *item) -{ - gint day, event_num; - gboolean editing_long_event = FALSE; - EDayViewEvent *event; - gchar *text = NULL; - CalComponentText summary; - - /* Note: the item we are passed here isn't reliable, so we just stop - the edit of whatever item was being edited. We also receive this - event twice for some reason. */ - day = day_view->editing_event_day; - event_num = day_view->editing_event_num; - -#if 0 - g_print ("In e_day_view_on_editing_stopped Day:%i Event:%i\n", - day, event_num); -#endif - - /* If no item is being edited, just return. */ - if (day == -1) - return; - - if (day == E_DAY_VIEW_LONG_EVENT) { - editing_long_event = TRUE; - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - } else { - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* Hide the horizontal bars. */ - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - } - - /* Reset the edit fields. */ - day_view->editing_event_day = -1; - day_view->editing_event_num = -1; - - day_view->resize_bars_event_day = -1; - day_view->resize_bars_event_num = -1; - - g_object_set (event->canvas_item, "handle_popup", FALSE, NULL); - g_object_get (G_OBJECT (event->canvas_item), - "text", &text, - NULL); - g_assert (text != NULL); - - if (string_is_empty (text) && !cal_comp_is_on_server (event->comp, day_view->client)) { - const char *uid; - - cal_component_get_uid (event->comp, &uid); - - e_day_view_foreach_event_with_uid (day_view, uid, - e_day_view_remove_event_cb, NULL); - e_day_view_check_layout (day_view); - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - goto out; - } - - /* Only update the summary if necessary. */ - cal_component_get_summary (event->comp, &summary); - if (summary.value && !strcmp (text, summary.value)) { - if (day == E_DAY_VIEW_LONG_EVENT) - e_day_view_reshape_long_event (day_view, event_num); - else - e_day_view_update_event_label (day_view, day, - event_num); - } else if (summary.value || !string_is_empty (text)) { - summary.value = text; - summary.altrep = NULL; - cal_component_set_summary (event->comp, &summary); - - if (cal_component_is_instance (event->comp)) { - CalObjModType mod; - - if (recur_component_dialog (event->comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, event->comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, day_view->client) - && send_component_dialog (day_view->client, event->comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_editing_stopped(): Could not update the object!"); - } - } - } else if (cal_client_update_object (day_view->client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, day_view->client) && send_component_dialog (day_view->client, event->comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_editing_stopped(): Could not update the object!"); - } - } - - out: - - g_free (text); - - gtk_signal_emit (GTK_OBJECT (day_view), - e_day_view_signals[SELECTION_CHANGED]); -} - - -/* FIXME: It is possible that we may produce an invalid time due to daylight - saving times (i.e. when clocks go forward there is a range of time which - is not valid). I don't know the best way to handle daylight saving time. */ -static time_t -e_day_view_convert_grid_position_to_time (EDayView *day_view, - gint col, - gint row) -{ - struct icaltimetype tt; - time_t val; - gint minutes; - - /* Calulate the number of minutes since the start of the day. */ - minutes = day_view->first_hour_shown * 60 - + day_view->first_minute_shown - + row * day_view->mins_per_row; - - /* A special case for midnight, where we can use the start of the - next day. */ - if (minutes == 60 * 24) - return day_view->day_starts[col + 1]; - - /* Create an icaltimetype and convert to a time_t. */ - tt = icaltime_from_timet_with_zone (day_view->day_starts[col], - FALSE, day_view->zone); - tt.hour = minutes / 60; - tt.minute = minutes % 60; - tt.second = 0; - - val = icaltime_as_timet_with_zone (tt, day_view->zone); - return val; -} - - -static gboolean -e_day_view_convert_time_to_grid_position (EDayView *day_view, - time_t time, - gint *col, - gint *row) -{ - struct icaltimetype tt; - gint day, minutes; - - *col = *row = 0; - - if (time < day_view->lower || time >= day_view->upper) - return FALSE; - - /* We can find the column easily using the day_starts array. */ - for (day = 1; day <= day_view->days_shown; day++) { - if (time < day_view->day_starts[day]) { - *col = day - 1; - break; - } - } - - /* To find the row we need to convert the time to an icaltimetype, - calculate the offset in minutes from the top of the display and - divide it by the mins per row setting. */ - tt = icaltime_from_timet_with_zone (time, FALSE, day_view->zone); - - minutes = tt.hour * 60 + tt.minute; - minutes -= day_view->first_hour_shown * 60 + day_view->first_minute_shown; - - *row = minutes / day_view->mins_per_row; - - if (*row < 0 || *row >= day_view->rows) - return FALSE; - - return TRUE; -} - - -/* This starts or stops auto-scrolling when dragging a selection or resizing - an event. */ -void -e_day_view_check_auto_scroll (EDayView *day_view, - gint event_x, - gint event_y) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (day_view->main_canvas), - &scroll_x, &scroll_y); - - event_x -= scroll_x; - event_y -= scroll_y; - - day_view->last_mouse_x = event_x; - day_view->last_mouse_y = event_y; - - if (event_y < E_DAY_VIEW_AUTO_SCROLL_OFFSET) - e_day_view_start_auto_scroll (day_view, TRUE); - else if (event_y >= day_view->main_canvas->allocation.height - - E_DAY_VIEW_AUTO_SCROLL_OFFSET) - e_day_view_start_auto_scroll (day_view, FALSE); - else - e_day_view_stop_auto_scroll (day_view); -} - - -static void -e_day_view_start_auto_scroll (EDayView *day_view, - gboolean scroll_up) -{ - if (day_view->auto_scroll_timeout_id == 0) { - day_view->auto_scroll_timeout_id = g_timeout_add (E_DAY_VIEW_AUTO_SCROLL_TIMEOUT, e_day_view_auto_scroll_handler, day_view); - day_view->auto_scroll_delay = E_DAY_VIEW_AUTO_SCROLL_DELAY; - } - day_view->auto_scroll_up = scroll_up; -} - - -void -e_day_view_stop_auto_scroll (EDayView *day_view) -{ - if (day_view->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (day_view->auto_scroll_timeout_id); - day_view->auto_scroll_timeout_id = 0; - } -} - - -static gboolean -e_day_view_auto_scroll_handler (gpointer data) -{ - EDayView *day_view; - EDayViewPosition pos; - gint scroll_x, scroll_y, new_scroll_y, canvas_x, canvas_y, row, day; - GtkAdjustment *adj; - - g_return_val_if_fail (E_IS_DAY_VIEW (data), FALSE); - - day_view = E_DAY_VIEW (data); - - GDK_THREADS_ENTER (); - - if (day_view->auto_scroll_delay > 0) { - day_view->auto_scroll_delay--; - GDK_THREADS_LEAVE (); - return TRUE; - } - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (day_view->main_canvas), - &scroll_x, &scroll_y); - - adj = GTK_LAYOUT (day_view->main_canvas)->vadjustment; - - if (day_view->auto_scroll_up) - new_scroll_y = MAX (scroll_y - adj->step_increment, 0); - else - new_scroll_y = MIN (scroll_y + adj->step_increment, - adj->upper - adj->page_size); - - if (new_scroll_y != scroll_y) { - /* NOTE: This reduces flicker, but only works if we don't use - canvas items which have X windows. */ - - /* FIXME: Since GNOME 2.0 we can't do this, since the canvas - * won't update when its's thawed. Is this a bug or should we - * really be doing something else? Investigate. */ -#if 0 - gtk_layout_freeze (GTK_LAYOUT (day_view->main_canvas)); -#endif - - gnome_canvas_scroll_to (GNOME_CANVAS (day_view->main_canvas), - scroll_x, new_scroll_y); -#if 0 - gtk_layout_thaw (GTK_LAYOUT (day_view->main_canvas)); -#endif - } - - canvas_x = day_view->last_mouse_x + scroll_x; - canvas_y = day_view->last_mouse_y + new_scroll_y; - - /* The last_mouse_x position is set to -1 when we are selecting using - the time column. In this case we set canvas_x to 0 and we ignore - the resulting day. */ - if (day_view->last_mouse_x == -1) - canvas_x = 0; - - /* Update the selection/resize/drag if necessary. */ - pos = e_day_view_convert_position_in_main_canvas (day_view, - canvas_x, canvas_y, - &day, &row, NULL); - - if (day_view->last_mouse_x == -1) - day = -1; - - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - if (day_view->selection_is_being_dragged) { - e_day_view_update_selection (day_view, day, row); - } else if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE) { - e_day_view_update_resize (day_view, row); - } else if (day_view->drag_item->object.flags - & GNOME_CANVAS_ITEM_VISIBLE) { - e_day_view_update_main_canvas_drag (day_view, row, - day); - } - } - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -gboolean -e_day_view_get_event_position (EDayView *day_view, - gint day, - gint event_num, - gint *item_x, - gint *item_y, - gint *item_w, - gint *item_h) -{ - EDayViewEvent *event; - gint start_row, end_row, cols_in_row, start_col, num_columns; - - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* If the event is flagged as not displayed, return FALSE. */ - if (event->num_columns == 0) - return FALSE; - - start_row = event->start_minute / day_view->mins_per_row; - end_row = (event->end_minute - 1) / day_view->mins_per_row; - if (end_row < start_row) - end_row = start_row; - - cols_in_row = day_view->cols_per_row[day][start_row]; - start_col = event->start_row_or_col; - num_columns = event->num_columns; - - if (cols_in_row == 0) - return FALSE; - - /* If the event is being resize, use the resize position. */ - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE - && day_view->resize_event_day == day - && day_view->resize_event_num == event_num) { - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_TOP_EDGE) - start_row = day_view->resize_start_row; - else if (day_view->resize_drag_pos == E_DAY_VIEW_POS_BOTTOM_EDGE) - end_row = day_view->resize_end_row; - } - - - *item_x = day_view->day_offsets[day] - + day_view->day_widths[day] * start_col / cols_in_row; - *item_w = day_view->day_widths[day] * num_columns / cols_in_row - - E_DAY_VIEW_GAP_WIDTH; - *item_w = MAX (*item_w, 0); - *item_y = start_row * day_view->row_height; -#if 0 - *item_h = (end_row - start_row + 1) * day_view->row_height; -#else - /* This makes the event end on the grid line of the next row, - which maybe looks nicer if you have 2 events on consecutive rows. */ - *item_h = (end_row - start_row + 1) * day_view->row_height + 1; -#endif - return TRUE; -} - - -gboolean -e_day_view_get_long_event_position (EDayView *day_view, - gint event_num, - gint *start_day, - gint *end_day, - gint *item_x, - gint *item_y, - gint *item_w, - gint *item_h) -{ - EDayViewEvent *event; - - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - /* If the event is flagged as not displayed, return FALSE. */ - if (event->num_columns == 0) - return FALSE; - - if (!e_day_view_find_long_event_days (event, - day_view->days_shown, - day_view->day_starts, - start_day, end_day)) - return FALSE; - - /* If the event is being resize, use the resize position. */ - if (day_view->resize_drag_pos != E_DAY_VIEW_POS_NONE - && day_view->resize_event_day == E_DAY_VIEW_LONG_EVENT - && day_view->resize_event_num == event_num) { - if (day_view->resize_drag_pos == E_DAY_VIEW_POS_LEFT_EDGE) - *start_day = day_view->resize_start_row; - else if (day_view->resize_drag_pos == E_DAY_VIEW_POS_RIGHT_EDGE) - *end_day = day_view->resize_end_row; - } - - *item_x = day_view->day_offsets[*start_day] + E_DAY_VIEW_BAR_WIDTH; - *item_w = day_view->day_offsets[*end_day + 1] - *item_x - - E_DAY_VIEW_GAP_WIDTH; - *item_w = MAX (*item_w, 0); - *item_y = (event->start_row_or_col + 1) * day_view->top_row_height; - *item_h = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - return TRUE; -} - - -/* Converts a position within the entire top canvas to a day & event and - a place within the event if appropriate. If event_num_return is NULL, it - simply returns the grid position without trying to find the event. */ -static EDayViewPosition -e_day_view_convert_position_in_top_canvas (EDayView *day_view, - gint x, - gint y, - gint *day_return, - gint *event_num_return) -{ - EDayViewEvent *event; - gint day, row, col; - gint event_num, start_day, end_day, item_x, item_y, item_w, item_h; - - *day_return = -1; - if (event_num_return) - *event_num_return = -1; - - if (x < 0 || y < 0) - return E_DAY_VIEW_POS_OUTSIDE; - - row = y / day_view->top_row_height - 1; - - day = -1; - for (col = 1; col <= day_view->days_shown; col++) { - if (x < day_view->day_offsets[col]) { - day = col - 1; - break; - } - } - if (day == -1) - return E_DAY_VIEW_POS_OUTSIDE; - - *day_return = day; - - /* If only the grid position is wanted, return. */ - if (event_num_return == NULL) - return E_DAY_VIEW_POS_NONE; - - for (event_num = 0; event_num < day_view->long_events->len; - event_num++) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - - if (event->start_row_or_col != row) - continue; - - if (!e_day_view_get_long_event_position (day_view, event_num, - &start_day, &end_day, - &item_x, &item_y, - &item_w, &item_h)) - continue; - - if (x < item_x) - continue; - - if (x >= item_x + item_w) - continue; - - *event_num_return = event_num; - - if (x < item_x + E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH - + E_DAY_VIEW_LONG_EVENT_X_PAD) - return E_DAY_VIEW_POS_LEFT_EDGE; - - if (x >= item_x + item_w - E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH - - E_DAY_VIEW_LONG_EVENT_X_PAD) - return E_DAY_VIEW_POS_RIGHT_EDGE; - - return E_DAY_VIEW_POS_EVENT; - } - - return E_DAY_VIEW_POS_NONE; -} - - -/* Converts a position within the entire main canvas to a day, row, event and - a place within the event if appropriate. If event_num_return is NULL, it - simply returns the grid position without trying to find the event. */ -static EDayViewPosition -e_day_view_convert_position_in_main_canvas (EDayView *day_view, - gint x, - gint y, - gint *day_return, - gint *row_return, - gint *event_num_return) -{ - gint day, row, col, event_num; - gint item_x, item_y, item_w, item_h; - -#if 0 - g_print ("e_day_view_convert_position_in_main_canvas: (%d, %d)\n", x, y); -#endif - - *day_return = -1; - *row_return = -1; - if (event_num_return) - *event_num_return = -1; - - /* Check the position is inside the canvas, and determine the day - and row. */ - if (x < 0 || y < 0) - return E_DAY_VIEW_POS_OUTSIDE; - - row = y / day_view->row_height; - if (row >= day_view->rows) - return E_DAY_VIEW_POS_OUTSIDE; - - day = -1; - for (col = 1; col <= day_view->days_shown; col++) { - if (x < day_view->day_offsets[col]) { - day = col - 1; - break; - } - } - if (day == -1) - return E_DAY_VIEW_POS_OUTSIDE; - - *day_return = day; - *row_return = row; - - /* If only the grid position is wanted, return. */ - if (event_num_return == NULL) - return E_DAY_VIEW_POS_NONE; - - /* Check the selected item first, since the horizontal resizing bars - may be above other events. */ - if (day_view->resize_bars_event_day == day) { - if (e_day_view_get_event_position (day_view, day, - day_view->resize_bars_event_num, - &item_x, &item_y, - &item_w, &item_h)) { - if (x >= item_x && x < item_x + item_w) { - *event_num_return = day_view->resize_bars_event_num; - if (y >= item_y - E_DAY_VIEW_BAR_HEIGHT - && y < item_y + E_DAY_VIEW_EVENT_BORDER_HEIGHT) - return E_DAY_VIEW_POS_TOP_EDGE; - if (y >= item_y + item_h - E_DAY_VIEW_EVENT_BORDER_HEIGHT - && y < item_y + item_h + E_DAY_VIEW_BAR_HEIGHT) - return E_DAY_VIEW_POS_BOTTOM_EDGE; - } - } - } - - /* Try to find the event at the found position. */ - *event_num_return = -1; - for (event_num = 0; event_num < day_view->events[day]->len; - event_num++) { - if (!e_day_view_get_event_position (day_view, day, event_num, - &item_x, &item_y, - &item_w, &item_h)) - continue; - - if (x < item_x || x >= item_x + item_w - || y < item_y || y >= item_y + item_h) - continue; - - *event_num_return = event_num; - - if (x < item_x + E_DAY_VIEW_BAR_WIDTH) - return E_DAY_VIEW_POS_LEFT_EDGE; - - if (y < item_y + E_DAY_VIEW_EVENT_BORDER_HEIGHT - + E_DAY_VIEW_EVENT_Y_PAD) - return E_DAY_VIEW_POS_TOP_EDGE; - - if (y >= item_y + item_h - E_DAY_VIEW_EVENT_BORDER_HEIGHT - - E_DAY_VIEW_EVENT_Y_PAD) - return E_DAY_VIEW_POS_BOTTOM_EDGE; - - return E_DAY_VIEW_POS_EVENT; - } - - return E_DAY_VIEW_POS_NONE; -} - - -static gint -e_day_view_on_top_canvas_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EDayView *day_view) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (widget), - &scroll_x, &scroll_y); - day_view->drag_event_x = x + scroll_x; - day_view->drag_event_y = y + scroll_y; - - e_day_view_reshape_top_canvas_drag_item (day_view); - - return TRUE; -} - - -static void -e_day_view_reshape_top_canvas_drag_item (EDayView *day_view) -{ - EDayViewPosition pos; - gint x, y, day; - - /* Calculate the day & start row of the event being dragged, using - the current mouse position. */ - x = day_view->drag_event_x; - y = day_view->drag_event_y; - pos = e_day_view_convert_position_in_top_canvas (day_view, x, y, - &day, NULL); - /* This shouldn't really happen in a drag. */ - if (pos == E_DAY_VIEW_POS_OUTSIDE) - return; - - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) - day -= day_view->drag_event_offset; - day = MAX (day, 0); - - e_day_view_update_top_canvas_drag (day_view, day); -} - - -static void -e_day_view_update_top_canvas_drag (EDayView *day_view, - gint day) -{ - EDayViewEvent *event = NULL; - gint row, num_days, start_day, end_day; - gdouble item_x, item_y, item_w, item_h; - gchar *text; - - /* Calculate the event's position. If the event is in the same - position we started in, we use the same columns. */ - row = day_view->rows_in_top_display + 1; - num_days = 1; - - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - day_view->drag_event_num); - row = event->start_row_or_col + 1; - - if (!e_day_view_find_long_event_days (event, - day_view->days_shown, - day_view->day_starts, - &start_day, &end_day)) - return; - - num_days = end_day - start_day + 1; - - /* Make sure we don't go off the screen. */ - day = MIN (day, day_view->days_shown - num_days); - - } else if (day_view->drag_event_day != -1) { - event = &g_array_index (day_view->events[day_view->drag_event_day], - EDayViewEvent, - day_view->drag_event_num); - } - - /* If the position hasn't changed, just return. */ - if (day_view->drag_last_day == day - && (day_view->drag_long_event_item->object.flags - & GNOME_CANVAS_ITEM_VISIBLE)) - return; - - day_view->drag_last_day = day; - - - item_x = day_view->day_offsets[day] + E_DAY_VIEW_BAR_WIDTH; - item_w = day_view->day_offsets[day + num_days] - item_x - - E_DAY_VIEW_GAP_WIDTH; - item_y = row * day_view->top_row_height; - item_h = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; - - - /* Set the positions of the event & associated items. */ - gnome_canvas_item_set (day_view->drag_long_event_rect_item, - "x1", item_x, - "y1", item_y, - "x2", item_x + item_w - 1, - "y2", item_y + item_h - 1, - NULL); - - gnome_canvas_item_set (day_view->drag_long_event_item, - "clip_width", item_w - (E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD) * 2, - "clip_height", item_h - (E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD) * 2, - NULL); - e_canvas_item_move_absolute (day_view->drag_long_event_item, - item_x + E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD, - item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD); - - if (!(day_view->drag_long_event_rect_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) { - gnome_canvas_item_raise_to_top (day_view->drag_long_event_rect_item); - gnome_canvas_item_show (day_view->drag_long_event_rect_item); - } - - /* Set the text, if necessary. We don't want to set the text every - time it moves, so we check if it is currently invisible and only - set the text then. */ - if (!(day_view->drag_long_event_item->object.flags - & GNOME_CANVAS_ITEM_VISIBLE)) { - CalComponentText summary; - - if (event) { - cal_component_get_summary (event->comp, &summary); - text = g_strdup (summary.value); - } else { - text = NULL; - } - - gnome_canvas_item_set (day_view->drag_long_event_item, - "text", text ? text : "", - NULL); - gnome_canvas_item_raise_to_top (day_view->drag_long_event_item); - gnome_canvas_item_show (day_view->drag_long_event_item); - - g_free (text); - } -} - - -static gint -e_day_view_on_main_canvas_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EDayView *day_view) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (widget), - &scroll_x, &scroll_y); - - day_view->drag_event_x = x + scroll_x; - day_view->drag_event_y = y + scroll_y; - - e_day_view_reshape_main_canvas_drag_item (day_view); - e_day_view_reshape_main_canvas_resize_bars (day_view); - - e_day_view_check_auto_scroll (day_view, day_view->drag_event_x, day_view->drag_event_y); - - return TRUE; -} - - -static void -e_day_view_reshape_main_canvas_drag_item (EDayView *day_view) -{ - EDayViewPosition pos; - gint x, y, day, row; - - /* Calculate the day & start row of the event being dragged, using - the current mouse position. */ - x = day_view->drag_event_x; - y = day_view->drag_event_y; - pos = e_day_view_convert_position_in_main_canvas (day_view, x, y, - &day, &row, NULL); - /* This shouldn't really happen in a drag. */ - if (pos == E_DAY_VIEW_POS_OUTSIDE) - return; - - if (day_view->drag_event_day != -1 - && day_view->drag_event_day != E_DAY_VIEW_LONG_EVENT) - row -= day_view->drag_event_offset; - row = MAX (row, 0); - - e_day_view_update_main_canvas_drag (day_view, row, day); -} - - -static void -e_day_view_update_main_canvas_drag (EDayView *day_view, - gint row, - gint day) -{ - EDayViewEvent *event = NULL; - gint cols_in_row, start_col, num_columns, num_rows, start_row, end_row; - gdouble item_x, item_y, item_w, item_h; - gchar *text; - - /* If the position hasn't changed, just return. */ - if (day_view->drag_last_day == day - && day_view->drag_last_row == row - && (day_view->drag_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) - return; - - day_view->drag_last_day = day; - day_view->drag_last_row = row; - - /* Calculate the event's position. If the event is in the same - position we started in, we use the same columns. */ - cols_in_row = 1; - start_row = 0; - start_col = 0; - num_columns = 1; - num_rows = 1; - - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - day_view->drag_event_num); - } else if (day_view->drag_event_day != -1) { - event = &g_array_index (day_view->events[day_view->drag_event_day], - EDayViewEvent, - day_view->drag_event_num); - start_row = event->start_minute / day_view->mins_per_row; - end_row = (event->end_minute - 1) / day_view->mins_per_row; - if (end_row < start_row) - end_row = start_row; - - num_rows = end_row - start_row + 1; - } - - if (day_view->drag_event_day == day && start_row == row) { - cols_in_row = day_view->cols_per_row[day][row]; - start_col = event->start_row_or_col; - num_columns = event->num_columns; - } - - item_x = day_view->day_offsets[day] - + day_view->day_widths[day] * start_col / cols_in_row; - item_w = day_view->day_widths[day] * num_columns / cols_in_row - - E_DAY_VIEW_GAP_WIDTH; - item_y = row * day_view->row_height; - item_h = num_rows * day_view->row_height; - - /* Set the positions of the event & associated items. */ - gnome_canvas_item_set (day_view->drag_rect_item, - "x1", item_x + E_DAY_VIEW_BAR_WIDTH - 1, - "y1", item_y, - "x2", item_x + item_w - 1, - "y2", item_y + item_h - 1, - NULL); - - gnome_canvas_item_set (day_view->drag_bar_item, - "x1", item_x, - "y1", item_y, - "x2", item_x + E_DAY_VIEW_BAR_WIDTH - 1, - "y2", item_y + item_h - 1, - NULL); - - gnome_canvas_item_set (day_view->drag_item, - "clip_width", item_w - E_DAY_VIEW_BAR_WIDTH - E_DAY_VIEW_EVENT_X_PAD * 2, - "clip_height", item_h - (E_DAY_VIEW_EVENT_BORDER_HEIGHT + E_DAY_VIEW_EVENT_Y_PAD) * 2, - NULL); - e_canvas_item_move_absolute (day_view->drag_item, - item_x + E_DAY_VIEW_BAR_WIDTH + E_DAY_VIEW_EVENT_X_PAD, - item_y + E_DAY_VIEW_EVENT_BORDER_HEIGHT + E_DAY_VIEW_EVENT_Y_PAD); - - if (!(day_view->drag_bar_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) { - gnome_canvas_item_raise_to_top (day_view->drag_bar_item); - gnome_canvas_item_show (day_view->drag_bar_item); - } - - if (!(day_view->drag_rect_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) { - gnome_canvas_item_raise_to_top (day_view->drag_rect_item); - gnome_canvas_item_show (day_view->drag_rect_item); - } - - /* Set the text, if necessary. We don't want to set the text every - time it moves, so we check if it is currently invisible and only - set the text then. */ - if (!(day_view->drag_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) { - CalComponentText summary; - - if (event) { - cal_component_get_summary (event->comp, &summary); - text = g_strdup (summary.value); - } else { - text = NULL; - } - - gnome_canvas_item_set (day_view->drag_item, - "text", text ? text : "", - NULL); - gnome_canvas_item_raise_to_top (day_view->drag_item); - gnome_canvas_item_show (day_view->drag_item); - - g_free (text); - } -} - - -static void -e_day_view_on_top_canvas_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EDayView *day_view) -{ - day_view->drag_last_day = -1; - - gnome_canvas_item_hide (day_view->drag_long_event_rect_item); - gnome_canvas_item_hide (day_view->drag_long_event_item); -} - - -static void -e_day_view_on_main_canvas_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EDayView *day_view) -{ - day_view->drag_last_day = -1; - - e_day_view_stop_auto_scroll (day_view); - - gnome_canvas_item_hide (day_view->drag_rect_item); - gnome_canvas_item_hide (day_view->drag_bar_item); - gnome_canvas_item_hide (day_view->drag_item); - - /* Hide the resize bars if they are being used in the drag. */ - if (day_view->drag_event_day == day_view->resize_bars_event_day - && day_view->drag_event_num == day_view->resize_bars_event_num) { - gnome_canvas_item_hide (day_view->main_canvas_top_resize_bar_item); - gnome_canvas_item_hide (day_view->main_canvas_bottom_resize_bar_item); - } -} - - -static void -e_day_view_on_drag_begin (GtkWidget *widget, - GdkDragContext *context, - EDayView *day_view) -{ - EDayViewEvent *event; - gint day, event_num; - - day = day_view->drag_event_day; - event_num = day_view->drag_event_num; - - /* These should both be set. */ - g_return_if_fail (day != -1); - g_return_if_fail (event_num != -1); - - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - else - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - - /* Hide the text item, since it will be shown in the special drag - items. */ - gnome_canvas_item_hide (event->canvas_item); -} - - -static void -e_day_view_on_drag_end (GtkWidget *widget, - GdkDragContext *context, - EDayView *day_view) -{ - EDayViewEvent *event; - gint day, event_num; - - day = day_view->drag_event_day; - event_num = day_view->drag_event_num; - - /* If the calendar has already been updated in drag_data_received() - we just return. */ - if (day == -1 || event_num == -1) - return; - - if (day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - event_num); - gtk_widget_queue_draw (day_view->top_canvas); - } else { - event = &g_array_index (day_view->events[day], EDayViewEvent, - event_num); - gtk_widget_queue_draw (day_view->main_canvas); - } - - /* Show the text item again. */ - gnome_canvas_item_show (event->canvas_item); - - day_view->drag_event_day = -1; - day_view->drag_event_num = -1; -} - - -static void -e_day_view_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EDayView *day_view) -{ - EDayViewEvent *event; - gint day, event_num; - - day = day_view->drag_event_day; - event_num = day_view->drag_event_num; - - /* These should both be set. */ - g_return_if_fail (day != -1); - g_return_if_fail (event_num != -1); - - if (day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, event_num); - else - event = &g_array_index (day_view->events[day], - EDayViewEvent, event_num); - - if (info == TARGET_CALENDAR_EVENT) { - const char *event_uid; - - cal_component_get_uid (event->comp, &event_uid); - g_return_if_fail (event_uid != NULL); - - gtk_selection_data_set (selection_data, selection_data->target, - 8, event_uid, strlen (event_uid)); - } else if (info == TARGET_VCALENDAR) { - char *comp_str; - icalcomponent *vcal; - - vcal = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal, event->comp); - icalcomponent_add_component ( - vcal, - icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp))); - - comp_str = icalcomponent_as_ical_string (vcal); - if (comp_str) { - gtk_selection_data_set (selection_data, selection_data->target, - 8, comp_str, strlen (comp_str)); - } - - icalcomponent_free (vcal); - } -} - - -static void -e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EDayView *day_view) -{ - EDayViewEvent *event=NULL; - EDayViewPosition pos; - gint day, start_day, end_day, num_days; - gint start_offset, end_offset; - gchar *event_uid; - CalComponent *comp; - CalComponentDateTime date; - struct icaltimetype itt; - time_t dt; - gboolean all_day_event; - - /* Note that we only support DnD within the EDayView at present. */ - if ((data->length >= 0) && (data->format == 8) - && (day_view->drag_event_day != -1)) { - pos = e_day_view_convert_position_in_top_canvas (day_view, - x, y, &day, - NULL); - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - const char *uid; - num_days = 1; - start_offset = 0; - end_offset = 0; - - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - day_view->drag_event_num); - day -= day_view->drag_event_offset; - day = MAX (day, 0); - - e_day_view_find_long_event_days (event, - day_view->days_shown, - day_view->day_starts, - &start_day, - &end_day); - num_days = end_day - start_day + 1; - /* Make sure we don't go off the screen. */ - day = MIN (day, day_view->days_shown - num_days); - - start_offset = event->start_minute; - end_offset = event->end_minute; - } else { - event = &g_array_index (day_view->events[day_view->drag_event_day], - EDayViewEvent, - day_view->drag_event_num); - } - - event_uid = data->data; - - cal_component_get_uid (event->comp, &uid); - - if (!event_uid || !uid || strcmp (event_uid, uid)) - g_warning ("Unexpected event UID"); - - /* We clone the event since we don't want to change - the original comp here. - Otherwise we would not detect that the event's time - had changed in the "update_event" callback. */ - - comp = cal_component_clone (event->comp); - - if (start_offset == 0 && end_offset == 0) - all_day_event = TRUE; - else - all_day_event = FALSE; - - date.value = &itt; - - dt = day_view->day_starts[day] + start_offset * 60; - itt = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - if (all_day_event) { - itt.is_date = TRUE; - date.tzid = NULL; - } else { - /* FIXME: Should probably keep the timezone of - the original start and end times. */ - date.tzid = icaltimezone_get_tzid (day_view->zone); - } - cal_component_set_dtstart (comp, &date); - - if (end_offset == 0) - dt = day_view->day_starts[day + num_days]; - else - dt = day_view->day_starts[day + num_days - 1] + end_offset * 60; - itt = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - if (all_day_event) { - itt.is_date = TRUE; - date.tzid = NULL; - } else { - /* FIXME: Should probably keep the timezone of - the original start and end times. */ - date.tzid = icaltimezone_get_tzid (day_view->zone); - } - cal_component_set_dtend (comp, &date); - - gtk_drag_finish (context, TRUE, TRUE, time); - - /* Reset this since it will be invalid. */ - day_view->drag_event_day = -1; - - /* Show the text item again, just in case it hasn't - moved. If we don't do this it may not appear. */ - if (event->canvas_item) - gnome_canvas_item_show (event->canvas_item); - - if (cal_component_is_instance (comp)) { - CalObjModType mod; - - if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) - && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " - "not update the object!"); - } - } - } else if (cal_client_update_object (day_view->client, comp) - == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " - "not update the object!"); - } - - g_object_unref (comp); - - return; - } - } - - gtk_drag_finish (context, FALSE, FALSE, time); -} - - -static void -e_day_view_on_main_canvas_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EDayView *day_view) -{ - EDayViewEvent *event = NULL; - EDayViewPosition pos; - gint day, row, start_row, end_row, num_rows, scroll_x, scroll_y; - gint start_offset, end_offset; - gchar *event_uid; - CalComponent *comp; - CalComponentDateTime date; - struct icaltimetype itt; - time_t dt; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (widget), - &scroll_x, &scroll_y); - x += scroll_x; - y += scroll_y; - - /* Note that we only support DnD within the EDayView at present. */ - if ((data->length >= 0) && (data->format == 8) - && (day_view->drag_event_day != -1)) { - pos = e_day_view_convert_position_in_main_canvas (day_view, - x, y, &day, - &row, NULL); - if (pos != E_DAY_VIEW_POS_OUTSIDE) { - const char *uid; - num_rows = 1; - start_offset = 0; - end_offset = 0; - - if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) { - event = &g_array_index (day_view->long_events, EDayViewEvent, - day_view->drag_event_num); - } else { - event = &g_array_index (day_view->events[day_view->drag_event_day], - EDayViewEvent, - day_view->drag_event_num); - row -= day_view->drag_event_offset; - - /* Calculate time offset from start row. */ - start_row = event->start_minute / day_view->mins_per_row; - end_row = (event->end_minute - 1) / day_view->mins_per_row; - if (end_row < start_row) - end_row = start_row; - - num_rows = end_row - start_row + 1; - - start_offset = event->start_minute % day_view->mins_per_row; - end_offset = event->end_minute % day_view->mins_per_row; - if (end_offset != 0) - end_offset = day_view->mins_per_row - end_offset; - } - - event_uid = data->data; - - cal_component_get_uid (event->comp, &uid); - if (!event_uid || !uid || strcmp (event_uid, uid)) - g_warning ("Unexpected event UID"); - - /* We use a temporary shallow copy of comp since we - don't want to change the original comp here. - Otherwise we would not detect that the event's time - had changed in the "update_event" callback. */ - comp = cal_component_clone (event->comp); - - date.value = &itt; - date.tzid = icaltimezone_get_tzid (day_view->zone); - - dt = e_day_view_convert_grid_position_to_time (day_view, day, row) + start_offset * 60; - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtstart (comp, &date); - dt = e_day_view_convert_grid_position_to_time (day_view, day, row + num_rows) - end_offset * 60; - *date.value = icaltime_from_timet_with_zone (dt, FALSE, - day_view->zone); - cal_component_set_dtend (comp, &date); - - gtk_drag_finish (context, TRUE, TRUE, time); - - /* Reset this since it will be invalid. */ - day_view->drag_event_day = -1; - - /* Show the text item again, just in case it hasn't - moved. If we don't do this it may not appear. */ - if (event->canvas_item) - gnome_canvas_item_show (event->canvas_item); - - if (cal_component_is_instance (comp)) { - CalObjModType mod; - - if (recur_component_dialog (comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (day_view->client, comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) - && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_top_canvas_drag_data_received(): Could " - "not update the object!"); - } - } - } else if (cal_client_update_object (day_view->client, comp) - == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, - day_view->client, NULL); - } else { - g_message ("e_day_view_on_main_canvas_drag_data_received(): " - "Could not update the object!"); - } - - g_object_unref (comp); - - return; - } - } - - gtk_drag_finish (context, FALSE, FALSE, time); -} - - -/* Converts an hour from 0-23 to the preferred time format, and returns the - suffix to add and the width of it in the normal font. */ -void -e_day_view_convert_time_to_display (EDayView *day_view, - gint hour, - gint *display_hour, - gchar **suffix, - gint *suffix_width) -{ - /* Calculate the actual hour number to display. For 12-hour - format we convert 0-23 to 12-11am/12-11pm. */ - *display_hour = hour; - if (day_view->use_24_hour_format) { - *suffix = ""; - *suffix_width = 0; - } else { - if (hour < 12) { - *suffix = day_view->am_string; - *suffix_width = day_view->am_string_width; - } else { - *display_hour -= 12; - *suffix = day_view->pm_string; - *suffix_width = day_view->pm_string_width; - } - - /* 12-hour uses 12:00 rather than 0:00. */ - if (*display_hour == 0) - *display_hour = 12; - } -} - - -gint -e_day_view_get_time_string_width (EDayView *day_view) -{ - gint time_width; - - time_width = day_view->digit_width * 4 + day_view->colon_width; - - if (!day_view->use_24_hour_format) - time_width += MAX (day_view->am_string_width, - day_view->pm_string_width); - - return time_width; -} - -static void -invisible_destroyed (GtkWidget *invisible, EDayView *day_view) -{ - g_object_unref (day_view->invisible); - day_view->invisible = NULL; -} - -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EDayView *day_view) -{ - if (day_view->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - day_view->clipboard_selection, - strlen (day_view->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EDayView *day_view) -{ - if (day_view->clipboard_selection != NULL) { - g_free (day_view->clipboard_selection); - day_view->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EDayView *day_view) -{ - char *comp_str; - icalcomponent *icalcomp; - time_t dtstart, dtend; - struct icaltimetype itime; - icalcomponent_kind kind; - CalComponent *comp; - char *uid; - time_t tt_start, tt_end; - struct icaldurationtype ic_dur; - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (selection_data->length < 0 || - selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } - - comp_str = (char *) selection_data->data; - icalcomp = icalparser_parse_string ((const char *) comp_str); - if (!icalcomp) - return; - - /* check the type of the component */ - kind = icalcomponent_isa (icalcomp); - if (kind != ICAL_VCALENDAR_COMPONENT && - kind != ICAL_VEVENT_COMPONENT && - kind != ICAL_VTODO_COMPONENT && - kind != ICAL_VJOURNAL_COMPONENT) { - return; - } - - e_day_view_set_status_message (day_view, _("Updating objects")); - e_day_view_get_selected_time_range (day_view, &dtstart, &dtend); - - if (kind == ICAL_VCALENDAR_COMPONENT) { - icalcomponent_kind child_kind; - icalcomponent *subcomp; - - subcomp = icalcomponent_get_first_component ( - icalcomp, ICAL_ANY_COMPONENT); - while (subcomp) { - child_kind = icalcomponent_isa (subcomp); - if (child_kind == ICAL_VEVENT_COMPONENT || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (subcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (subcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (dtstart, FALSE, day_view->zone); - - icalcomponent_set_dtstart (subcomp, itime); - itime = icaltime_add (itime, ic_dur); - icalcomponent_set_dtend (subcomp, itime); - - uid = cal_component_gen_uid (); - comp = cal_component_new (); - cal_component_set_icalcomponent ( - comp, icalcomponent_new_clone (subcomp)); - cal_component_set_uid (comp, uid); - - cal_client_update_object (day_view->client, comp); - - free (uid); - g_object_unref (comp); - - } - subcomp = icalcomponent_get_next_component ( - icalcomp, ICAL_ANY_COMPONENT); - } - } - else { - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - itime = icaltime_from_timet_with_zone (dtstart, FALSE, day_view->zone); - - icalcomponent_set_dtstart (icalcomp, itime); - itime = icaltime_add (itime, ic_dur); - icalcomponent_set_dtend (icalcomp, itime); - - comp = cal_component_new (); - cal_component_set_icalcomponent (comp, icalcomp); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, (const char *) uid); - free (uid); - - cal_client_update_object (day_view->client, comp); - - if (itip_organizer_is_user (comp, day_view->client) && send_component_dialog (day_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, day_view->client, NULL); - - g_object_unref (comp); - } - - e_day_view_set_status_message (day_view, NULL); -} - - -/* Gets the visible time range. Returns FALSE if no time range has been set. */ -gboolean -e_day_view_get_visible_time_range (EDayView *day_view, - time_t *start_time, - time_t *end_time) -{ - /* If the date isn't set, return FALSE. */ - if (day_view->lower == 0 && day_view->upper == 0) - return FALSE; - - *start_time = day_view->day_starts[0]; - *end_time = day_view->day_starts[day_view->days_shown]; - - return TRUE; -} - - -/* Queues a layout, unless one is already queued. */ -static void -e_day_view_queue_layout (EDayView *day_view) -{ - if (day_view->layout_timeout_id == 0) { - day_view->layout_timeout_id = g_timeout_add (E_DAY_VIEW_LAYOUT_TIMEOUT, e_day_view_layout_timeout_cb, day_view); - } -} - - -/* Removes any queued layout. */ -static void -e_day_view_cancel_layout (EDayView *day_view) -{ - if (day_view->layout_timeout_id != 0) { - gtk_timeout_remove (day_view->layout_timeout_id); - day_view->layout_timeout_id = 0; - } -} - - -static gboolean -e_day_view_layout_timeout_cb (gpointer data) -{ - EDayView *day_view = E_DAY_VIEW (data); - - gtk_widget_queue_draw (day_view->top_canvas); - gtk_widget_queue_draw (day_view->main_canvas); - e_day_view_check_layout (day_view); - - day_view->layout_timeout_id = 0; - return FALSE; -} - - -/* Returns the number of selected events (0 or 1 at present). */ -gint -e_day_view_get_num_events_selected (EDayView *day_view) -{ - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), 0); - - return (day_view->editing_event_day != -1) ? 1 : 0; -} - -/* Returns the currently-selected event, or NULL if none */ -CalComponent * -e_day_view_get_selected_event (EDayView *day_view) -{ - EDayViewEvent *event; - - g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); - g_return_val_if_fail (day_view->editing_event_day != -1, NULL); - - if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) - event = &g_array_index (day_view->long_events, - EDayViewEvent, - day_view->editing_event_num); - else - event = &g_array_index (day_view->events[day_view->editing_event_day], - EDayViewEvent, - day_view->editing_event_num); - - return event ? event->comp : NULL; -} - -/* Displays messages on the status bar. */ -void -e_day_view_set_status_message (EDayView *day_view, const char *message) -{ - extern EvolutionShellClient *global_shell_client; /* ugly */ - - g_return_if_fail (E_IS_DAY_VIEW (day_view)); - - if (!message || !*message) { - if (day_view->activity) { - g_object_unref (day_view->activity); - day_view->activity = NULL; - } - } - else if (!day_view->activity) { - int display; - char *client_id = g_strdup_printf ("%p", day_view); - - if (progress_icon[0] == NULL) - progress_icon[0] = gdk_pixbuf_new_from_file (EVOLUTION_IMAGESDIR "/" EVOLUTION_CALENDAR_PROGRESS_IMAGE, NULL); - day_view->activity = evolution_activity_client_new ( - global_shell_client, client_id, - progress_icon, message, TRUE, &display); - - g_free (client_id); - } - else - evolution_activity_client_update (day_view->activity, message, -1.0); -} diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h deleted file mode 100644 index c8b719aca1..0000000000 --- a/calendar/gui/e-day-view.h +++ /dev/null @@ -1,677 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_DAY_VIEW_H_ -#define _E_DAY_VIEW_H_ - -#include <time.h> -#include <gtk/gtktable.h> -#include <libgnomecanvas/gnome-canvas.h> -#include <gal/widgets/e-popup-menu.h> - -#include "gnome-cal.h" -#include "evolution-activity-client.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EDayView - displays the Day & Work-Week views of the calendar. - */ - -/* The maximum number of days shown. We use the week view for anything more - than about 9 days. */ -#define E_DAY_VIEW_MAX_DAYS 10 - -/* This is used as a special code to signify a long event instead of the day - of a normal event. */ -#define E_DAY_VIEW_LONG_EVENT E_DAY_VIEW_MAX_DAYS - -/* The maximum number of columns of appointments within a day. */ -#define E_DAY_VIEW_MAX_COLUMNS 6 - -/* The width of the gap between appointments. This should be at least - E_DAY_VIEW_BAR_WIDTH, since in the top canvas we use this space to draw - the triangle to represent continuing events. */ -#define E_DAY_VIEW_GAP_WIDTH 7 - -/* The width of the bars down the left of each column and appointment. - This includes the borders on each side of it. */ -#define E_DAY_VIEW_BAR_WIDTH 7 - -/* The height of the horizontal bar above & beneath the selected event. - This includes the borders on the top and bottom. */ -#define E_DAY_VIEW_BAR_HEIGHT 6 - -/* The size of the reminder & recurrence icons, and padding around them. */ -#define E_DAY_VIEW_ICON_WIDTH 16 -#define E_DAY_VIEW_ICON_HEIGHT 16 -#define E_DAY_VIEW_ICON_X_PAD 1 -#define E_DAY_VIEW_ICON_Y_PAD 1 - -/* The space between the icons and the long event text. */ -#define E_DAY_VIEW_LONG_EVENT_ICON_R_PAD 1 - -/* The size of the border around the event. */ -#define E_DAY_VIEW_EVENT_BORDER_WIDTH 1 -#define E_DAY_VIEW_EVENT_BORDER_HEIGHT 1 - -/* The padding on each side of the event text. */ -#define E_DAY_VIEW_EVENT_X_PAD 2 -#define E_DAY_VIEW_EVENT_Y_PAD 1 - -/* The padding on each side of the event text for events in the top canvas. */ -#define E_DAY_VIEW_LONG_EVENT_X_PAD 2 -#define E_DAY_VIEW_LONG_EVENT_Y_PAD 2 - -/* The size of the border around the long events in the top canvas. */ -#define E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH 1 -#define E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT 1 - -/* The space between the time and the icon/text in the top canvas. */ -#define E_DAY_VIEW_LONG_EVENT_TIME_X_PAD 2 - -/* The gap between rows in the top canvas. */ -#define E_DAY_VIEW_TOP_CANVAS_Y_GAP 2 - - -/* These are used to get/set the working days in the week. The bit-flags are - combined together. The bits must be from 0 (Sun) to 6 (Sat) to match the - day values used by localtime etc. */ -typedef enum -{ - E_DAY_VIEW_SUNDAY = 1 << 0, - E_DAY_VIEW_MONDAY = 1 << 1, - E_DAY_VIEW_TUESDAY = 1 << 2, - E_DAY_VIEW_WEDNESDAY = 1 << 3, - E_DAY_VIEW_THURSDAY = 1 << 4, - E_DAY_VIEW_FRIDAY = 1 << 5, - E_DAY_VIEW_SATURDAY = 1 << 6 -} EDayViewDays; - - -/* These are used to specify the type of an appointment. They match those - used in EMeetingTimeSelector. */ -typedef enum -{ - E_DAY_VIEW_BUSY_TENTATIVE = 0, - E_DAY_VIEW_BUSY_OUT_OF_OFFICE = 1, - E_DAY_VIEW_BUSY_BUSY = 2, - - E_DAY_VIEW_BUSY_LAST = 3 -} EDayViewBusyType; - -/* This is used to specify the format used when displaying the dates. - The full format is like 'Thursday 12 September'. The abbreviated format is - like 'Thu 12 Sep'. The no weekday format is like '12 Sep'. The short format - is like '12'. The actual format used is determined in - e_day_view_recalc_cell_sizes(), once we know the font being used. */ -typedef enum -{ - E_DAY_VIEW_DATE_FULL, - E_DAY_VIEW_DATE_ABBREVIATED, - E_DAY_VIEW_DATE_NO_WEEKDAY, - E_DAY_VIEW_DATE_SHORT -} EDayViewDateFormat; - -/* These index our colors array. */ -typedef enum -{ - E_DAY_VIEW_COLOR_BG_WORKING, - E_DAY_VIEW_COLOR_BG_NOT_WORKING, - E_DAY_VIEW_COLOR_BG_SELECTED, - E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED, - E_DAY_VIEW_COLOR_BG_GRID, - - E_DAY_VIEW_COLOR_BG_TOP_CANVAS, - E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED, - E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID, - - E_DAY_VIEW_COLOR_EVENT_VBAR, - E_DAY_VIEW_COLOR_EVENT_BACKGROUND, - E_DAY_VIEW_COLOR_EVENT_BORDER, - - E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND, - E_DAY_VIEW_COLOR_LONG_EVENT_BORDER, - - E_DAY_VIEW_COLOR_LAST -} EDayViewColors; - -/* These specify which part of the selection we are dragging, if any. */ -typedef enum -{ - E_DAY_VIEW_DRAG_START, - E_DAY_VIEW_DRAG_END -} EDayViewDragPosition; - -/* Specifies the position of the mouse. */ -typedef enum -{ - E_DAY_VIEW_POS_OUTSIDE, - E_DAY_VIEW_POS_NONE, - E_DAY_VIEW_POS_EVENT, - E_DAY_VIEW_POS_LEFT_EDGE, - E_DAY_VIEW_POS_RIGHT_EDGE, - E_DAY_VIEW_POS_TOP_EDGE, - E_DAY_VIEW_POS_BOTTOM_EDGE -} EDayViewPosition; - -typedef struct _EDayViewEvent EDayViewEvent; -struct _EDayViewEvent { - CalComponent *comp; - - /* These are the times of this specific occurrence of the event. */ - time_t start; - time_t end; - - /* For events in the main canvas, this contains the start column. - For long events in the top canvas, this is its row. */ - guint8 start_row_or_col; - - /* For events in the main canvas, this is the number of columns that - it covers. For long events this is set to 1 if the event is shown. - For both types of events this is set to 0 if the event is not shown, - i.e. it couldn't fit into the display. Currently long events are - always shown as we just increase the height of the top canvas. */ - guint8 num_columns; - - /* TRUE if the event is at a different UTC offset than our current - timezone, i.e. it is in a different timezone. */ - guint different_timezone : 1; - - /* These are minute offsets from the first time shown in the view. - They range from 0 to 24 * 60. Currently the main canvas always - starts at 12am and the code to handle starting at other times - isn't finished. */ - guint16 start_minute; - guint16 end_minute; - - /* This is the EText item containing the event summary. */ - GnomeCanvasItem *canvas_item; -}; - - -#define E_DAY_VIEW(obj) GTK_CHECK_CAST (obj, e_day_view_get_type (), EDayView) -#define E_DAY_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_day_view_get_type (), EDayViewClass) -#define E_IS_DAY_VIEW(obj) GTK_CHECK_TYPE (obj, e_day_view_get_type ()) - - -typedef struct _EDayView EDayView; -typedef struct _EDayViewClass EDayViewClass; - -struct _EDayView -{ - GtkTable table; - - /* The top canvas where the dates and long appointments are shown. */ - GtkWidget *top_canvas; - GnomeCanvasItem *top_canvas_item; - - /* The main canvas where the rest of the appointments are shown. */ - GtkWidget *main_canvas; - GnomeCanvasItem *main_canvas_item; - - /* The canvas displaying the times of the day. */ - GtkWidget *time_canvas; - GnomeCanvasItem *time_canvas_item; - - GtkWidget *vscrollbar; - - /* The calendar we are associated with. */ - GnomeCalendar *calendar; - - /* Calendar client object we are monitoring */ - CalClient *client; - - /* S-expression for query and the query object */ - char *sexp; - CalQuery *query; - - /* The start and end of the days shown. */ - time_t lower; - time_t upper; - - /* Whether we are showing the work-week view. */ - gboolean work_week_view; - - /* The number of days we are showing. Usually 1 or 5, but can be up - to E_DAY_VIEW_MAX_DAYS, e.g. when the user selects a range of - days in the date navigator. */ - gint days_shown; - - /* The start of each day & an extra element to hold the last time. */ - time_t day_starts[E_DAY_VIEW_MAX_DAYS + 1]; - - /* The timezone. */ - icaltimezone *zone; - - /* An array of EDayViewEvent elements for the top view and each day. */ - GArray *long_events; - GArray *events[E_DAY_VIEW_MAX_DAYS]; - - /* These are set to FALSE whenever an event in the corresponding array - is changed. Any function that needs the events sorted calls - e_day_view_ensure_events_sorted(). */ - gboolean long_events_sorted; - gboolean events_sorted[E_DAY_VIEW_MAX_DAYS]; - - /* This is TRUE if we need to relayout the events before drawing. */ - gboolean long_events_need_layout; - gboolean need_layout[E_DAY_VIEW_MAX_DAYS]; - - /* This is TRUE if we need to reshape the canvas items, but a full - layout is not necessary. */ - gboolean long_events_need_reshape; - gboolean need_reshape[E_DAY_VIEW_MAX_DAYS]; - - /* The ID of the timeout function for doing a new layout. */ - gint layout_timeout_id; - - /* The number of minutes per row. 5, 10, 15, 30 or 60. */ - gint mins_per_row; - - /* The number of rows needed, depending on the times shown and the - minutes per row. */ - gint rows; - - /* The height of each row. */ - gint row_height; - - /* The number of rows in the top display. */ - gint rows_in_top_display; - - /* The height of each row in the top canvas. */ - gint top_row_height; - - /* The first and last times shown in the display. The last time isn't - included in the range. Default is 0:00-24:00 */ - gint first_hour_shown; - gint first_minute_shown; - gint last_hour_shown; - gint last_minute_shown; - - /* Bitwise combination of working days. Defaults to Mon-Fri. */ - EDayViewDays working_days; - - /* The start and end of the work day, rounded to the nearest row. */ - gint work_day_start_hour; - gint work_day_start_minute; - gint work_day_end_hour; - gint work_day_end_minute; - - /* Whether we use 12-hour of 24-hour format. */ - gboolean use_24_hour_format; - - /* Whether we use show event end times in the main canvas. */ - gboolean show_event_end_times; - - /* The first day of the week, 0 (Monday) to 6 (Sunday). */ - gint week_start_day; - - /* This is set to TRUE when the widget is created, so it scrolls to - the start of the working day when first shown. */ - gboolean scroll_to_work_day; - - /* This is the width & offset of each of the day columns in the - display. */ - gint day_widths[E_DAY_VIEW_MAX_DAYS]; - gint day_offsets[E_DAY_VIEW_MAX_DAYS + 1]; - - /* An array holding the number of columns in each row, in each day. - Note that there are a maximum of 12 * 24 rows (when a row is 5 mins) - but we don't always have that many rows. */ - guint8 cols_per_row[E_DAY_VIEW_MAX_DAYS][12 * 24]; - - /* Sizes of the various time strings. */ - gint small_hour_widths[24]; - gint max_small_hour_width; - gint max_minute_width; - gint colon_width; - gint digit_width; /* Size of '0' character. */ - - /* This specifies how we are displaying the dates at the top. */ - EDayViewDateFormat date_format; - - /* These are the longest month & weekday names in the current font. - Months are 0 to 11. Weekdays are 0 (Sun) to 6 (Sat). */ - gint longest_month_name; - gint longest_abbreviated_month_name; - gint longest_weekday_name; - gint longest_abbreviated_weekday_name; - - /* The large font used to display the hours. I don't think we need a - fontset since we only display numbers. */ - PangoFontDescription *large_font_desc; - - /* The GC used for painting in different colors. */ - GdkGC *main_gc; - - /* The icons. */ - GdkPixmap *reminder_icon; - GdkBitmap *reminder_mask; - GdkPixmap *recurrence_icon; - GdkBitmap *recurrence_mask; - GdkPixmap *timezone_icon; - GdkBitmap *timezone_mask; - GdkPixmap *meeting_icon; - GdkBitmap *meeting_mask; - - /* Colors for drawing. */ - GdkColor colors[E_DAY_VIEW_COLOR_LAST]; - - /* The normal & resizing cursors. */ - GdkCursor *normal_cursor; - GdkCursor *move_cursor; - GdkCursor *resize_width_cursor; - GdkCursor *resize_height_cursor; - - /* This remembers the last cursor set on the window. */ - GdkCursor *last_cursor_set_in_top_canvas; - GdkCursor *last_cursor_set_in_main_canvas; - - /* - * Editing, Selection & Dragging data - */ - - /* The horizontal bars to resize events in the main canvas. */ - GnomeCanvasItem *main_canvas_top_resize_bar_item; - GnomeCanvasItem *main_canvas_bottom_resize_bar_item; - - /* The event currently being edited. The day is -1 if no event is - being edited, or E_DAY_VIEW_LONG_EVENT if a long event is edited. */ - gint editing_event_day; - gint editing_event_num; - - /* This is a GnomeCanvasRect which is placed around an item while it - is being resized, so we can raise it above all other EText items. */ - GnomeCanvasItem *resize_long_event_rect_item; - GnomeCanvasItem *resize_rect_item; - GnomeCanvasItem *resize_bar_item; - - /* The event for which a popup menu is being displayed, as above. */ - gint popup_event_day; - gint popup_event_num; - EPopupMenu *view_menu; - - /* The currently selected region. If selection_start_day is -1 there is - no current selection. If start_row or end_row is -1 then the - selection is in the top canvas. */ - gint selection_start_day; - gint selection_end_day; - gint selection_start_row; - gint selection_end_row; - - /* This is TRUE if the selection is currently being dragged using the - mouse. */ - gboolean selection_is_being_dragged; - - /* This specifies which end of the selection is being dragged. */ - EDayViewDragPosition selection_drag_pos; - - /* This is TRUE if the selection is in the top canvas only (i.e. if the - last motion event was in the top canvas). */ - gboolean selection_in_top_canvas; - - /* The last mouse position, relative to the main canvas window. - Used when auto-scrolling to update the selection. */ - gint last_mouse_x; - gint last_mouse_y; - - /* Auto-scroll info for when selecting an area or dragging an item. */ - gint auto_scroll_timeout_id; - gint auto_scroll_delay; - gboolean auto_scroll_up; - - /* These are used for the resize bars. */ - gint resize_bars_event_day; - gint resize_bars_event_num; - - /* These are used when resizing events. */ - gint resize_event_day; - gint resize_event_num; - EDayViewPosition resize_drag_pos; - gint resize_start_row; - gint resize_end_row; - - /* This is the event the mouse button was pressed on. If the button - is released we start editing it, but if the mouse is dragged we set - this to -1. */ - gint pressed_event_day; - gint pressed_event_num; - - /* These are used when dragging events. If drag_event_day is not -1 we - know that we are dragging one of the EDayView events around. */ - gint drag_event_day; - gint drag_event_num; - - /* The last mouse position when dragging, in the entire canvas. */ - gint drag_event_x; - gint drag_event_y; - - /* The offset of the mouse from the top of the event, in rows. - In the top canvas this is the offset from the left, in days. */ - gint drag_event_offset; - - /* The last day & row dragged to, so we know when we need to update - the dragged event's position. */ - gint drag_last_day; - gint drag_last_row; - - /* This is a GnomeCanvasRect which is placed around an item while it - is being resized, so we can raise it above all other EText items. */ - GnomeCanvasItem *drag_long_event_rect_item; - GnomeCanvasItem *drag_long_event_item; - GnomeCanvasItem *drag_rect_item; - GnomeCanvasItem *drag_bar_item; - GnomeCanvasItem *drag_item; - - /* "am" and "pm" in the current locale, and their widths. */ - gchar *am_string; - gchar *pm_string; - gint am_string_width; - gint pm_string_width; - - /* the invisible widget to manage the clipboard selections */ - GtkWidget *invisible; - gchar *clipboard_selection; - - /* The default category for new events */ - char *default_category; - - /* The activity client used to show messages on the status bar. */ - EvolutionActivityClient *activity; -}; - -struct _EDayViewClass -{ - GtkTableClass parent_class; - - /* Notification signals */ - void (* selection_changed) (EDayView *day_view); -}; - - -GtkType e_day_view_get_type (void); -GtkWidget* e_day_view_new (void); - -void e_day_view_set_calendar (EDayView *day_view, - GnomeCalendar *calendar); - -void e_day_view_set_cal_client (EDayView *day_view, - CalClient *client); - -void e_day_view_set_query (EDayView *day_view, - const char *sexp); - -void e_day_view_set_default_category (EDayView *day_view, - const char *category); - -/* This sets the selected time range. The EDayView will show the day or week - corresponding to the start time. If the start_time & end_time are not equal - and are both visible in the view, then the selection is set to those times, - otherwise it is set to 1 hour from the start of the working day. */ -void e_day_view_set_selected_time_range (EDayView *day_view, - time_t start_time, - time_t end_time); - -/* Returns the selected time range. */ -void e_day_view_get_selected_time_range (EDayView *day_view, - time_t *start_time, - time_t *end_time); - -/* Gets the visible time range. Returns FALSE if no time range has been set. */ -gboolean e_day_view_get_visible_time_range (EDayView *day_view, - time_t *start_time, - time_t *end_time); - -/* Whether we are displaying a work-week, in which case the display always - starts on the first day of the working week. */ -gboolean e_day_view_get_work_week_view (EDayView *day_view); -void e_day_view_set_work_week_view (EDayView *day_view, - gboolean work_week_view); - -/* The number of days shown in the EDayView, from 1 to 7. This is normally - either 1 or 5 (for the Work-Week view). */ -gint e_day_view_get_days_shown (EDayView *day_view); -void e_day_view_set_days_shown (EDayView *day_view, - gint days_shown); - -/* This specifies how many minutes are represented by one row in the display. - It can be 60, 30, 15, 10 or 5. The default is 30. */ -gint e_day_view_get_mins_per_row (EDayView *day_view); -void e_day_view_set_mins_per_row (EDayView *day_view, - gint mins_per_row); - -/* This specifies the working days in the week. The value is a bitwise - combination of day flags. Defaults to Mon-Fri. */ -EDayViewDays e_day_view_get_working_days (EDayView *day_view); -void e_day_view_set_working_days (EDayView *day_view, - EDayViewDays days); - -/* The start and end time of the working day. This only affects the background - colors. */ -void e_day_view_get_working_day (EDayView *day_view, - gint *start_hour, - gint *start_minute, - gint *end_hour, - gint *end_minute); -void e_day_view_set_working_day (EDayView *day_view, - gint start_hour, - gint start_minute, - gint end_hour, - gint end_minute); - -/* Whether we use 12-hour or 24-hour format. */ -gboolean e_day_view_get_24_hour_format (EDayView *day_view); -void e_day_view_set_24_hour_format (EDayView *day_view, - gboolean use_24_hour); - -/* Whether we display event end times in the main canvas. */ -gboolean e_day_view_get_show_event_end_times (EDayView *day_view); -void e_day_view_set_show_event_end_times (EDayView *day_view, - gboolean show); - -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint e_day_view_get_week_start_day (EDayView *day_view); -void e_day_view_set_week_start_day (EDayView *day_view, - gint week_start_day); - -/* The current timezone. */ -icaltimezone* e_day_view_get_timezone (EDayView *day_view); -void e_day_view_set_timezone (EDayView *day_view, - icaltimezone *zone); - - -/* Clipboard-related functions */ -void e_day_view_cut_clipboard (EDayView *day_view); -void e_day_view_copy_clipboard (EDayView *day_view); -void e_day_view_paste_clipboard (EDayView *day_view); - -void e_day_view_delete_event (EDayView *day_view); -void e_day_view_delete_occurrence (EDayView *day_view); - - -/* Returns the number of selected events (0 or 1 at present). */ -gint e_day_view_get_num_events_selected (EDayView *day_view); - -CalComponent *e_day_view_get_selected_event (EDayView *day_view); - -/* - * Internal functions called by the associated canvas items. - */ -void e_day_view_check_layout (EDayView *day_view); -gint e_day_view_convert_time_to_row (EDayView *day_view, - gint hour, - gint minute); -gint e_day_view_convert_time_to_position (EDayView *day_view, - gint hour, - gint minute); -gboolean e_day_view_get_event_position (EDayView *day_view, - gint day, - gint event_num, - gint *item_x, - gint *item_y, - gint *item_w, - gint *item_h); -gboolean e_day_view_get_long_event_position (EDayView *day_view, - gint event_num, - gint *start_day, - gint *end_day, - gint *item_x, - gint *item_y, - gint *item_w, - gint *item_h); - -void e_day_view_start_selection (EDayView *day_view, - gint day, - gint row); -void e_day_view_update_selection (EDayView *day_view, - gint day, - gint row); -void e_day_view_finish_selection (EDayView *day_view); - -void e_day_view_check_auto_scroll (EDayView *day_view, - gint event_x, - gint event_y); -void e_day_view_stop_auto_scroll (EDayView *day_view); - -void e_day_view_convert_time_to_display (EDayView *day_view, - gint hour, - gint *display_hour, - gchar **suffix, - gint *suffix_width); -gint e_day_view_get_time_string_width (EDayView *day_view); - - -gint e_day_view_event_sort_func (const void *arg1, - const void *arg2); - -void e_day_view_set_status_message (EDayView *day_view, - const char *message); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_DAY_VIEW_H_ */ diff --git a/calendar/gui/e-itip-control.c b/calendar/gui/e-itip-control.c deleted file mode 100644 index 89434d02c8..0000000000 --- a/calendar/gui/e-itip-control.c +++ /dev/null @@ -1,2373 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-itip-control.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <glib.h> -#include <gtk/gtkmisc.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeui/gnome-uidefs.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-exception.h> -#include <gal/widgets/e-unicode.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> -#include <ical.h> -#include <cal-util/cal-component.h> -#include <cal-util/timeutil.h> -#include <cal-client/cal-client.h> -#include <e-util/e-time-utils.h> -#include <e-util/e-dialog-widgets.h> -#include <evolution-shell-client.h> -#include <evolution-folder-selector-button.h> -#include <camel/camel-mime-filter-tohtml.h> -#include "dialogs/delete-error.h" -#include "calendar-config.h" -#include "itip-utils.h" -#include "e-itip-control.h" - -struct _EItipControlPrivate { - GtkWidget *html; - gboolean html_destroyed; - - GPtrArray *event_clients; - CalClient *event_client; - GPtrArray *task_clients; - CalClient *task_client; - - char *vcalendar; - CalComponent *comp; - icalcomponent *main_comp; - icalcomponent *ical_comp; - icalcomponent *top_level; - icalcompiter iter; - icalproperty_method method; - - int current; - int total; - - gchar *calendar_uri; - - EAccountList *accounts; - - gchar *from_address; - gchar *delegator_address; - gchar *delegator_name; - gchar *my_address; - gboolean view_only; - - gboolean destroyed; -}; - -/* HTML Strings */ -#define HTML_BODY_START "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#336699\">" -#define HTML_SEP "<hr color=#336699 align=\"left\" width=450>" -#define HTML_BODY_END "</body>" -#define HTML_FOOTER "</html>" - -extern EvolutionShellClient *global_shell_client; - -/* We intentionally use "calendar" instead of "calendar / *" here. We - * don't want public calendars. - */ -static const char *calendar_types[] = { "calendar", NULL }; -static const char *tasks_types[] = { "tasks", NULL }; - -static void class_init (EItipControlClass *klass); -static void init (EItipControl *itip); -static void destroy (GtkObject *obj); -static void finalize (GObject *obj); - -static void url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *handle, gpointer data); -static gboolean object_requested_cb (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data); -static void ok_clicked_cb (GtkHTML *html, const gchar *method, const gchar *url, const gchar *encoding, gpointer data); - -static GtkVBoxClass *parent_class = NULL; - -E_MAKE_TYPE (e_itip_control, "EItipControl", EItipControl, class_init, init, - GTK_TYPE_VBOX); - -static void -class_init (EItipControlClass *klass) -{ - GObjectClass *object_class; - GtkObjectClass *gtkobject_class; - - object_class = G_OBJECT_CLASS (klass); - gtkobject_class = GTK_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - gtkobject_class->destroy = destroy; - - object_class->finalize = finalize; -} - - -/* Calendar Server routines */ -static void -start_calendar_server_cb (CalClient *cal_client, - CalClientOpenStatus status, - gpointer data) -{ - int *success = data; - int orig = *success; - - if (status == CAL_CLIENT_OPEN_SUCCESS) - *success = 1; - else - *success = 0; - - if (orig != -1) - gtk_main_quit (); /* end the sub event loop */ -} - -static CalClient * -start_calendar_server (EItipControl *itip, char *uri) -{ - CalClient *client; - int success = -1; - - client = cal_client_new (); - - g_signal_connect (client, "cal_opened", G_CALLBACK (start_calendar_server_cb), &success); - - if (!cal_client_open_calendar (client, uri, TRUE)) - goto error; - - /* run a sub event loop to turn cal-client's async load - notification into a synchronous call */ - if (success == -1 && !itip->priv->destroyed) { - success = 0; - - gtk_signal_connect (GTK_OBJECT (itip), "destroy", - gtk_main_quit, NULL); - - gtk_main (); - - gtk_signal_disconnect_by_func (GTK_OBJECT (itip), - gtk_main_quit, NULL); - } - - if (success == 1) - return client; - -error: - g_object_unref (client); - - return NULL; -} - -static CalClient * -start_default_server (EItipControl *itip, gboolean tasks) -{ - CalClient *client; - gboolean success = FALSE; - - client = cal_client_new (); - - g_signal_connect (client, "cal_opened", G_CALLBACK (start_calendar_server_cb), &success); - - if (tasks) { - if (!cal_client_open_default_tasks (client, FALSE)) - goto error; - } else { - if (!cal_client_open_default_calendar (client, FALSE)) - goto error; - } - - /* run a sub event loop to turn cal-client's async load - notification into a synchronous call */ - if (!itip->priv->destroyed) { - gtk_signal_connect (GTK_OBJECT (itip), "destroy", - gtk_main_quit, NULL); - - gtk_main (); - - gtk_signal_disconnect_by_func (GTK_OBJECT (itip), - gtk_main_quit, NULL); - } - - if (success) - return client; - - error: - g_object_unref (client); - - return NULL; -} - -static GPtrArray * -get_servers (EItipControl *itip, EvolutionShellClient *shell_client, const char *possible_types[], gboolean tasks) -{ - GNOME_Evolution_StorageRegistry registry; - GNOME_Evolution_StorageRegistry_StorageList *storage_list; - GPtrArray *servers; - int i, j, k; - CORBA_Environment ev; - - servers = g_ptr_array_new (); - - g_object_ref (shell_client); - registry = evolution_shell_client_get_storage_registry_interface (shell_client); - - CORBA_exception_init (&ev); - storage_list = GNOME_Evolution_StorageRegistry_getStorageList (registry, &ev); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return servers; - } - - for (i = 0; i < storage_list->_length; i++) { - GNOME_Evolution_Storage storage; - GNOME_Evolution_FolderList *folder_list; - - CORBA_exception_init (&ev); - - storage = storage_list->_buffer[i]; - folder_list = GNOME_Evolution_Storage__get_folderList (storage, &ev); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - continue; - } - - CORBA_exception_free (&ev); - - for (j = 0; j < folder_list->_length; j++) { - GNOME_Evolution_Folder folder; - - folder = folder_list->_buffer[j]; - for (k = 0; possible_types[k] != NULL; k++) { - CalClient *client; - char *uri; - - if (itip->priv->destroyed) - continue; - - if (strcmp (possible_types[k], folder.type)) - continue; - - uri = cal_util_expand_uri (folder.physicalUri, tasks); - client = start_calendar_server (itip, uri); - if (client != NULL) - g_ptr_array_add (servers, client); - g_free (uri); - - break; - } - } - - CORBA_free (folder_list); - } - - g_object_unref (shell_client); - - return servers; -} - -static CalClient * -find_server (GPtrArray *servers, CalComponent *comp) -{ - const char *uid; - int i; - - cal_component_get_uid (comp, &uid); - for (i = 0; i < servers->len; i++) { - CalClient *client; - CalComponent *found_comp; - CalClientGetStatus status; - - client = g_ptr_array_index (servers, i); - status = cal_client_get_object (client, uid, &found_comp); - if (status == CAL_CLIENT_GET_SUCCESS) { - g_object_unref (found_comp); - g_object_ref (client); - - return client; - } - } - - return NULL; -} - -static void -html_destroyed (gpointer data) -{ - EItipControl *itip = data; - EItipControlPrivate *priv; - - priv = itip->priv; - - priv->html_destroyed = TRUE; -} - -static void -init (EItipControl *itip) -{ - EItipControlPrivate *priv; - GtkWidget *scrolled_window; - - priv = g_new0 (EItipControlPrivate, 1); - - itip->priv = priv; - - /* Addresses */ - priv->accounts = itip_addresses_get (); - - /* Initialize the cal clients */ - priv->event_clients = NULL; - priv->event_client = NULL; - priv->task_clients = NULL; - priv->task_client = NULL; - - /* Other fields to init */ - priv->calendar_uri = NULL; - priv->from_address = NULL; - priv->delegator_address = NULL; - priv->delegator_name = NULL; - priv->my_address = NULL; - priv->view_only = FALSE; - - /* Html Widget */ - priv->html = gtk_html_new (); - priv->html_destroyed = FALSE; - gtk_html_set_default_content_type (GTK_HTML (priv->html), - "text/html; charset=utf-8"); - gtk_html_load_from_string (GTK_HTML (priv->html), " ", 1); - gtk_widget_show (priv->html); - - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_widget_show (scrolled_window); - - gtk_container_add (GTK_CONTAINER (scrolled_window), priv->html); - gtk_object_weakref (GTK_OBJECT (priv->html), html_destroyed, itip); - gtk_widget_set_usize (scrolled_window, 600, 400); - gtk_box_pack_start (GTK_BOX (itip), scrolled_window, FALSE, FALSE, 6); - - g_signal_connect (priv->html, "url_requested", G_CALLBACK (url_requested_cb), itip); - g_signal_connect (priv->html, "object_requested", G_CALLBACK (object_requested_cb), itip); - g_signal_connect (priv->html, "submit", G_CALLBACK (ok_clicked_cb), itip); - - priv->destroyed = FALSE; -} - -static void -clean_up (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - if (!priv) - return; - - g_free (priv->vcalendar); - priv->vcalendar = NULL; - - if (priv->comp) { - g_object_unref (priv->comp); - priv->comp = NULL; - } - - if (priv->top_level) { - icalcomponent_free (priv->top_level); - priv->top_level = NULL; - } - - if (priv->main_comp) { - icalcomponent_free (priv->main_comp); - priv->main_comp = NULL; - } - priv->ical_comp = NULL; - - priv->current = 0; - priv->total = 0; - - g_free (priv->calendar_uri); - priv->calendar_uri = NULL; - - g_free (priv->from_address); - priv->from_address = NULL; - g_free (priv->delegator_address); - priv->delegator_address = NULL; - g_free (priv->delegator_name); - priv->delegator_name = NULL; - g_free (priv->my_address); - priv->my_address = NULL; -} - -static void -destroy (GtkObject *obj) -{ - EItipControl *itip = E_ITIP_CONTROL (obj); - EItipControlPrivate *priv; - - priv = itip->priv; - - priv->destroyed = TRUE; -} - -static void -finalize (GObject *obj) -{ - EItipControl *itip = E_ITIP_CONTROL (obj); - EItipControlPrivate *priv; - int i; - - priv = itip->priv; - - clean_up (itip); - - if (priv->html) - gtk_object_weakunref (GTK_OBJECT (priv->html), html_destroyed, itip); - - priv->accounts = NULL; - - if (priv->event_clients) { - for (i = 0; i < priv->event_clients->len; i++) - g_object_unref (g_ptr_array_index (priv->event_clients, i)); - g_ptr_array_free (priv->event_clients, TRUE); - priv->event_client = NULL; - priv->event_clients = NULL; - } - - if (priv->task_clients) { - for (i = 0; i < priv->task_clients->len; i++) - g_object_unref (g_ptr_array_index (priv->task_clients, i)); - g_ptr_array_free (priv->task_clients, TRUE); - priv->task_client = NULL; - priv->task_clients = NULL; - } - - g_free (priv); - itip->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (obj); -} - -GtkWidget * -e_itip_control_new (void) -{ - return g_object_new (E_TYPE_ITIP_CONTROL, NULL); -} - -static void -find_my_address (EItipControl *itip, icalcomponent *ical_comp) -{ - EItipControlPrivate *priv; - icalproperty *prop; - char *my_alt_address = NULL; - - priv = itip->priv; - - /* If the mailer told us the address to use, use that */ - if (priv->delegator_address != NULL) { - priv->my_address = g_strdup (itip_strip_mailto (priv->delegator_address)); - priv->my_address = g_strstrip (priv->my_address); - return; - } - - for (prop = icalcomponent_get_first_property (ical_comp, ICAL_ATTENDEE_PROPERTY); - prop != NULL; - prop = icalcomponent_get_next_property (ical_comp, ICAL_ATTENDEE_PROPERTY)) - { - icalvalue *value; - icalparameter *param; - const char *attendee, *name; - char *attendee_clean, *name_clean; - EIterator *it; - - value = icalproperty_get_value (prop); - if (value != NULL) { - attendee = icalvalue_get_string (value); - attendee_clean = g_strdup (itip_strip_mailto (attendee)); - attendee_clean = g_strstrip (attendee_clean); - } else { - attendee = NULL; - attendee_clean = NULL; - } - - param = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER); - if (param != NULL) { - name = icalparameter_get_cn (param); - name_clean = g_strdup (name); - name_clean = g_strstrip (name_clean); - } else { - name = NULL; - name_clean = NULL; - } - - it = e_list_get_iterator((EList *)priv->accounts); - while (e_iterator_is_valid(it)) { - const EAccount *account = e_iterator_get(it); - - /* Check for a matching address */ - if (attendee_clean != NULL - && !g_ascii_strcasecmp (account->id->address, attendee_clean)) { - priv->my_address = g_strdup (account->id->address); - g_free (attendee_clean); - g_free (name_clean); - g_free (my_alt_address); - g_object_unref(it); - return; - } - - /* Check for a matching cname to fall back on */ - if (name_clean != NULL - && !g_ascii_strcasecmp (account->id->name, name_clean)) - my_alt_address = g_strdup (attendee_clean); - - e_iterator_next(it); - } - g_free (attendee_clean); - g_free (name_clean); - g_object_unref(it); - } - - priv->my_address = my_alt_address; -} - -static icalproperty * -find_attendee (icalcomponent *ical_comp, const char *address) -{ - icalproperty *prop; - - if (address == NULL) - return NULL; - - for (prop = icalcomponent_get_first_property (ical_comp, ICAL_ATTENDEE_PROPERTY); - prop != NULL; - prop = icalcomponent_get_next_property (ical_comp, ICAL_ATTENDEE_PROPERTY)) - { - icalvalue *value; - const char *attendee; - char *text; - - value = icalproperty_get_value (prop); - if (!value) - continue; - - attendee = icalvalue_get_string (value); - - text = g_strdup (itip_strip_mailto (attendee)); - text = g_strstrip (text); - if (!g_strcasecmp (address, text)) { - g_free (text); - break; - } - g_free (text); - } - - return prop; -} - -static void -write_label_piece (EItipControl *itip, CalComponentDateTime *dt, - char *buffer, int size, - const char *stext, const char *etext, - gboolean just_date) -{ - EItipControlPrivate *priv; - struct tm tmp_tm; - char time_buf[64], *time_utf8; - icaltimezone *zone = NULL; - char *display_name; - - priv = itip->priv; - - /* UTC times get converted to the current timezone. This is done for - the COMPLETED property, which is always in UTC, and also because - Outlook sends simple events as UTC times. */ - if (dt->value->is_utc) { - char *location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - icaltimezone_convert_time (dt->value, icaltimezone_get_utc_timezone (), zone); - } - - tmp_tm = icaltimetype_to_tm (dt->value); - if (just_date) - tmp_tm.tm_hour = tmp_tm.tm_min = tmp_tm.tm_sec = 0; - - if (stext != NULL) - strcat (buffer, stext); - - e_time_format_date_and_time (&tmp_tm, - calendar_config_get_24_hour_format (), - FALSE, FALSE, - time_buf, sizeof (time_buf)); - - time_utf8 = g_locale_to_utf8 (time_buf, -1, NULL, NULL, NULL); - strcat (buffer, time_utf8); - g_free (time_utf8); - - if (!dt->value->is_utc && dt->tzid) { - zone = icalcomponent_get_timezone (priv->top_level, dt->tzid); - } - - /* Output timezone after time, e.g. " America/New_York". */ - if (zone && !just_date) { - /* Note that this returns UTF-8, since all iCalendar data is - UTF-8. But it probably is not translated. */ - display_name = icaltimezone_get_display_name (zone); - if (display_name && *display_name) { - strcat (buffer, " <font size=-1>["); - - /* We check if it is one of our builtin timezone names, - in which case we call gettext to translate it. */ - if (icaltimezone_get_builtin_timezone (display_name)) { - strcat (buffer, _(display_name)); - } else { - strcat (buffer, display_name); - } - strcat (buffer, "]</font>"); - } - } - - if (etext != NULL) - strcat (buffer, etext); -} - -static const char * -nth (int n) -{ - if (n == -1) - return "last"; - else if (n < 1 || n > 31) - return "?"; - else - return cal_recur_nth[n]; -} - -static const char *dayname[] = { - N_("Sunday"), - N_("Monday"), - N_("Tuesday"), - N_("Wednesday"), - N_("Thursday"), - N_("Friday"), - N_("Saturday") -}; - -static inline char * -get_dayname (struct icalrecurrencetype *r, int i) -{ - enum icalrecurrencetype_weekday day; - - day = icalrecurrencetype_day_day_of_week (r->by_day[i]); - g_return_val_if_fail (day > 0 && day < 8, "?"); - - return _(dayname[day - 1]); -} - -static void -write_recurrence_piece (EItipControl *itip, CalComponent *comp, - char *buffer, int size) -{ - GSList *rrules; - struct icalrecurrencetype *r; - int len, i; - - strcpy (buffer, "<b>Recurring:</b> "); - len = strlen (buffer); - buffer += len; - size -= len; - - if (!cal_component_has_simple_recurrence (comp)) { - strcpy (buffer, _("Yes. (Complex Recurrence)")); - return; - } - - cal_component_get_rrule_list (comp, &rrules); - g_return_if_fail (rrules && !rrules->next); - - r = rrules->data; - - switch (r->freq) { - case ICAL_DAILY_RECURRENCE: - if (r->interval == 1) - strcpy (buffer, _("Every day")); - else - sprintf (buffer, _("Every %d days"), r->interval); - break; - - case ICAL_WEEKLY_RECURRENCE: - if (r->by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { - if (r->interval == 1) - strcpy (buffer, _("Every week")); - else - sprintf (buffer, _("Every %d weeks"), r->interval); - } else { - if (r->interval == 1) - strcpy (buffer, _("Every week on ")); - else - sprintf (buffer, _("Every %d weeks on "), r->interval); - - for (i = 1; i < 8 && r->by_day[i] != ICAL_RECURRENCE_ARRAY_MAX; i++) { - if (i > 1) - strcat (buffer, ", "); - strcat (buffer, get_dayname (r, i - 1)); - } - if (i > 1) - strcat (buffer, _(" and ")); - strcat (buffer, get_dayname (r, i - 1)); - } - break; - - case ICAL_MONTHLY_RECURRENCE: - if (r->by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { - sprintf (buffer, _("The %s day of "), - nth (r->by_month_day[0])); - } else { - int pos; - - /* Outlook 2000 uses BYDAY=TU;BYSETPOS=2, and will not - accept BYDAY=2TU. So we now use the same as Outlook - by default. */ - - pos = icalrecurrencetype_day_position (r->by_day[0]); - if (pos == 0) - pos = r->by_set_pos[0]; - - sprintf (buffer, _("The %s %s of "), - nth (pos), get_dayname (r, 0)); - } - - if (r->interval == 1) - strcat (buffer, _("every month")); - else { - len = strlen (buffer); - buffer += len; - size -= len; - sprintf (buffer, _("every %d months"), r->interval); - } - break; - - case ICAL_YEARLY_RECURRENCE: - if (r->interval == 1) - strcpy (buffer, _("Every year")); - else { - sprintf (buffer, _("Every %d years"), r->interval); - } - break; - - default: - g_assert_not_reached (); - } - - len = strlen (buffer); - buffer += len; - size -= len; - if (r->count) { - sprintf (buffer, _(" a total of %d times"), r->count); - } else if (!icaltime_is_null_time (r->until)) { - CalComponentDateTime dt; - - dt.value = &r->until; - dt.tzid = r->until.zone; - - write_label_piece (itip, &dt, buffer, size, - _(", ending on "), NULL, TRUE); - } - - strcat (buffer, "<br>"); -} - -static void -set_date_label (EItipControl *itip, GtkHTML *html, GtkHTMLStream *html_stream, - CalComponent *comp) -{ - EItipControlPrivate *priv; - CalComponentDateTime datetime; - static char buffer[1024]; - gboolean wrote = FALSE, task_completed = FALSE; - CalComponentVType type; - - priv = itip->priv; - - type = cal_component_get_vtype (comp); - - buffer[0] = '\0'; - cal_component_get_dtstart (comp, &datetime); - if (datetime.value) { - write_label_piece (itip, &datetime, buffer, 1024, - _("<b>Starts:</b> "), - "<br>", FALSE); - gtk_html_write (html, html_stream, buffer, strlen(buffer)); - wrote = TRUE; - } - cal_component_free_datetime (&datetime); - - buffer[0] = '\0'; - cal_component_get_dtend (comp, &datetime); - if (datetime.value){ - write_label_piece (itip, &datetime, buffer, 1024, _("<b>Ends:</b> "), "<br>", FALSE); - gtk_html_write (html, html_stream, buffer, strlen (buffer)); - wrote = TRUE; - } - cal_component_free_datetime (&datetime); - - buffer[0] = '\0'; - if (cal_component_has_recurrences (comp)) { - write_recurrence_piece (itip, comp, buffer, 1024); - gtk_html_write (html, html_stream, buffer, strlen (buffer)); - wrote = TRUE; - } - - buffer[0] = '\0'; - datetime.tzid = NULL; - cal_component_get_completed (comp, &datetime.value); - if (type == CAL_COMPONENT_TODO && datetime.value) { - /* Pass TRUE as is_utc, so it gets converted to the current - timezone. */ - datetime.value->is_utc = TRUE; - write_label_piece (itip, &datetime, buffer, 1024, _("<b>Completed:</b> "), "<br>", FALSE); - gtk_html_write (html, html_stream, buffer, strlen (buffer)); - wrote = TRUE; - task_completed = TRUE; - } - cal_component_free_datetime (&datetime); - - buffer[0] = '\0'; - cal_component_get_due (comp, &datetime); - if (type == CAL_COMPONENT_TODO && !task_completed && datetime.value) { - write_label_piece (itip, &datetime, buffer, 1024, _("<b>Due:</b> "), "<br>", FALSE); - gtk_html_write (html, html_stream, buffer, strlen (buffer)); - wrote = TRUE; - } - - cal_component_free_datetime (&datetime); - - if (wrote) - gtk_html_stream_printf (html_stream, "<br>"); -} - -static void -set_message (GtkHTML *html, GtkHTMLStream *html_stream, const gchar *message, gboolean err) -{ - if (message == NULL) - return; - - - if (err) { - gtk_html_stream_printf (html_stream, "<b><font color=\"#ff0000\">%s</font></b><br><br>", message); - } else { - gtk_html_stream_printf (html_stream, "<b>%s</b><br><br>", message); - } -} - -static void -write_error_html (EItipControl *itip, const gchar *itip_err) -{ - EItipControlPrivate *priv; - GtkHTMLStream *html_stream; - - priv = itip->priv; - - /* Html widget */ - html_stream = gtk_html_begin (GTK_HTML (priv->html)); - gtk_html_stream_printf (html_stream, - "<html><head><title>%s</title></head>", - _("iCalendar Information")); - - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_START, strlen(HTML_BODY_START)); - - /* The table */ - gtk_html_stream_printf (html_stream, "<table width=450 cellspacing=\"0\" cellpadding=\"4\" border=\"0\">"); - /* The column for the image */ - gtk_html_stream_printf (html_stream, "<tr><td width=48 align=\"center\" valign=\"top\" rowspan=\"8\">"); - /* The image */ - gtk_html_stream_printf (html_stream, "<img src=\"/meeting-request.png\"></td>"); - - gtk_html_stream_printf (html_stream, "<td align=\"left\" valign=\"top\">"); - - /* Title */ - set_message (GTK_HTML (priv->html), html_stream, _("iCalendar Error"), TRUE); - - /* Error */ - gtk_html_write (GTK_HTML (priv->html), html_stream, itip_err, strlen(itip_err)); - - /* Clean up */ - gtk_html_stream_printf (html_stream, "</td></tr></table>"); - - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_END, strlen(HTML_BODY_END)); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_FOOTER, strlen(HTML_FOOTER)); - - gtk_html_end (GTK_HTML (priv->html), html_stream, GTK_HTML_STREAM_OK); -} - -static void -write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, const gchar *options) -{ - EItipControlPrivate *priv; - GtkHTMLStream *html_stream; - CalComponentText text; - CalComponentOrganizer organizer; - CalComponentAttendee *attendee; - GSList *attendees, *l = NULL; - const char *string; - gchar *html; - const gchar *const_html; - - priv = itip->priv; - - if (priv->html_destroyed) - return; - - /* Html widget */ - html_stream = gtk_html_begin (GTK_HTML (priv->html)); - gtk_html_stream_printf (html_stream, - "<html><head><title>%s</title></head>", - _("iCalendar Information")); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_START, strlen(HTML_BODY_START)); - - /* The table */ - const_html = "<table width=450 cellspacing=\"0\" cellpadding=\"4\" border=\"0\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - /* The column for the image */ - const_html = "<tr><td width=48 align=\"center\" valign=\"top\" rowspan=\"8\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - /* The image */ - const_html = "<img src=\"/meeting-request.png\"></td>"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - const_html = "<td align=\"left\" valign=\"top\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - switch (priv->method) { - case ICAL_METHOD_REFRESH: - case ICAL_METHOD_REPLY: - /* An attendee sent this */ - cal_component_get_attendee_list (priv->comp, &attendees); - if (attendees != NULL) { - attendee = attendees->data; - html = g_strdup_printf (itip_desc, - attendee->cn ? - attendee->cn : - itip_strip_mailto (attendee->value)); - } else { - html = g_strdup_printf (itip_desc, _("An unknown person")); - } - break; - case ICAL_METHOD_REQUEST: - /* The organizer sent this */ - cal_component_get_organizer (priv->comp, &organizer); - if (priv->delegator_address != NULL) { - if (organizer.value != NULL) - html = g_strdup_printf (itip_desc, - organizer.cn ? - organizer.cn : - itip_strip_mailto (organizer.value), - priv->delegator_name ? - priv->delegator_name : - priv->delegator_address); - else - html = g_strdup_printf (itip_desc, _("An unknown person"), - priv->delegator_name ? - priv->delegator_name : - priv->delegator_address); - } else { - if (organizer.value != NULL) - html = g_strdup_printf (itip_desc, - organizer.cn ? - organizer.cn : - itip_strip_mailto (organizer.value)); - else - html = g_strdup_printf (itip_desc, _("An unknown person")); - } - - break; - - case ICAL_METHOD_PUBLISH: - case ICAL_METHOD_ADD: - case ICAL_METHOD_CANCEL: - default: - /* The organizer sent this */ - cal_component_get_organizer (priv->comp, &organizer); - if (organizer.value != NULL) - html = g_strdup_printf (itip_desc, - organizer.cn ? - organizer.cn : - itip_strip_mailto (organizer.value)); - else - html = g_strdup_printf (itip_desc, _("An unknown person")); - break; - } - gtk_html_write (GTK_HTML (priv->html), html_stream, html, strlen(html)); - g_free (html); - - /* Describe what the user can do */ - const_html = _("<br> Please review the following information, " - "and then select an action from the menu below."); - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - /* Separator */ - gtk_html_write (GTK_HTML (priv->html), html_stream, HTML_SEP, strlen (HTML_SEP)); - - /* Title */ - set_message (GTK_HTML (priv->html), html_stream, itip_title, FALSE); - - /* Date information */ - set_date_label (itip, GTK_HTML (priv->html), html_stream, priv->comp); - - /* Summary */ - cal_component_get_summary (priv->comp, &text); - html = text.value ? camel_text_to_html (text.value, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL, 0) : _("<i>None</i>"); - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s<br><br>", - _("Summary:"), html); - if (text.value) - g_free (html); - - /* Location */ - cal_component_get_location (priv->comp, &string); - if (string != NULL) { - html = camel_text_to_html (string, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s<br><br>", - _("Location:"), html); - g_free (html); - } - - /* Status */ - if (priv->method == ICAL_METHOD_REPLY) { - GSList *alist; - - cal_component_get_attendee_list (priv->comp, &alist); - - if (alist != NULL) { - CalComponentAttendee *a = alist->data; - - gtk_html_stream_printf (html_stream, "<b>%s</b><br>", - _("Status:")); - - switch (a->status) { - case ICAL_PARTSTAT_ACCEPTED: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Accepted")); - break; - case ICAL_PARTSTAT_TENTATIVE: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Tentatively Accepted")); - break; - case ICAL_PARTSTAT_DECLINED: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Declined")); - break; - default: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Unknown")); - } - } - - cal_component_free_attendee_list (alist); - } - - /* Description */ - cal_component_get_description_list (priv->comp, &l); - if (l) - text = *((CalComponentText *)l->data); - - if (l && text.value) { - html = camel_text_to_html (text.value, CAMEL_MIME_FILTER_TOHTML_CONVERT_NL, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s", - _("Description:"), html); - g_free (html); - } - cal_component_free_text_list (l); - - /* Separator */ - gtk_html_write (GTK_HTML (priv->html), html_stream, HTML_SEP, strlen (HTML_SEP)); - - /* Options */ - if (!e_itip_control_get_view_only (itip)) { - if (options != NULL) { - const_html = "</td></tr><tr><td valign=\"center\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen (const_html)); - gtk_html_write (GTK_HTML (priv->html), html_stream, options, strlen (options)); - } - } - - const_html = "</td></tr></table>"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); - - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_END, strlen(HTML_BODY_END)); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_FOOTER, strlen(HTML_FOOTER)); - - gtk_html_end (GTK_HTML (priv->html), html_stream, GTK_HTML_STREAM_OK); -} - - -static char* -get_publish_options (gboolean selector) -{ - char *html; - - html = g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"U\">%s</option>" - "</select>    " - "<input TYPE=Submit name=\"ok\" value=\"%s\">" - "</form>", - _("Choose an action:"), - _("Update"), - _("OK")); - - if (selector) { - char *sel; - - sel = g_strconcat (html, "<object classid=\"gtk:label\">", NULL); - g_free (html); - html = sel; - } - - return html; -} - -static char* -get_request_options (gboolean selector) -{ - char *html; - - html = g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"A\">%s</option> " - "<option VALUE=\"T\">%s</option> " - "<option VALUE=\"D\">%s</option></select>  " - "<input TYPE=\"checkbox\" name=\"rsvp\" value=\"1\" checked>%s  " - "<input TYPE=\"submit\" name=\"ok\" value=\"%s\"><br> " - "</form>", - _("Choose an action:"), - _("Accept"), - _("Tentatively accept"), - _("Decline"), - _("RSVP"), - _("OK")); - - if (selector) { - char *sel; - - sel = g_strconcat (html, "<object classid=\"gtk:label\">", NULL); - g_free (html); - html = sel; - } - - return html; -} - -static char* -get_request_fb_options () -{ - return g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"F\">%s</option></select>    " - "<input TYPE=Submit name=\"ok\" value=\"%s\">" - "</form>", - _("Choose an action:"), - _("Send Free/Busy Information"), - _("OK")); -} - -static char* -get_reply_options () -{ - return g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"R\">%s</option></select>    " - "<input TYPE=Submit name=\"ok\" value=\"%s\">" - "</form>", - _("Choose an action:"), - _("Update respondent status"), - _("OK")); -} - -static char* -get_refresh_options () -{ - return g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"S\">%s</option></select>    " - "<input TYPE=Submit name=\"ok\" value=\"%s\">" - "</form>", - _("Choose an action:"), - _("Send Latest Information"), - _("OK")); -} - -static char* -get_cancel_options () -{ - return g_strdup_printf ("<form><b>%s</b> " - "<select NAME=\"action\" SIZE=\"1\"> " - "<option VALUE=\"C\">%s</option></select>    " - "<input TYPE=Submit name=\"ok\" value=\"%s\">" - "</form>", - _("Choose an action:"), - _("Cancel"), - _("OK")); -} - - -static CalComponent * -get_real_item (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalComponent *comp; - CalComponentVType type; - CalClientGetStatus status = CAL_CLIENT_GET_NOT_FOUND; - const char *uid; - - priv = itip->priv; - - type = cal_component_get_vtype (priv->comp); - cal_component_get_uid (priv->comp, &uid); - - switch (type) { - case CAL_COMPONENT_EVENT: - if (priv->event_client != NULL) - status = cal_client_get_object (priv->event_client, uid, &comp); - break; - case CAL_COMPONENT_TODO: - if (priv->task_client != NULL) - status = cal_client_get_object (priv->task_client, uid, &comp); - break; - default: - status = CAL_CLIENT_GET_NOT_FOUND; - } - - if (status != CAL_CLIENT_GET_SUCCESS) - return NULL; - - return comp; -} - -static void -adjust_item (EItipControl *itip, CalComponent *comp) -{ - CalComponent *real_comp; - - real_comp = get_real_item (itip); - if (real_comp != NULL) { - CalComponentText text; - const char *string; - GSList *l; - - cal_component_get_summary (real_comp, &text); - cal_component_set_summary (comp, &text); - cal_component_get_location (real_comp, &string); - cal_component_set_location (comp, string); - cal_component_get_description_list (real_comp, &l); - cal_component_set_description_list (comp, l); - cal_component_free_text_list (l); - - g_object_unref (real_comp); - } else { - CalComponentText text = {_("Unknown"), NULL}; - - cal_component_set_summary (comp, &text); - } -} - -static void -show_current_event (EItipControl *itip) -{ - EItipControlPrivate *priv; - const gchar *itip_title, *itip_desc; - char *options; - - priv = itip->priv; - - if (priv->calendar_uri) - priv->event_client = start_calendar_server (itip, priv->calendar_uri); - else - priv->event_client = find_server (priv->event_clients, priv->comp); - - switch (priv->method) { - case ICAL_METHOD_PUBLISH: - itip_desc = _("<b>%s</b> has published meeting information."); - itip_title = _("Meeting Information"); - options = get_publish_options (priv->event_client ? FALSE : TRUE); - break; - case ICAL_METHOD_REQUEST: - if (priv->delegator_address != NULL) - itip_desc = _("<b>%s</b> requests the presence of %s at a meeting."); - else - itip_desc = _("<b>%s</b> requests your presence at a meeting."); - itip_title = _("Meeting Proposal"); - options = get_request_options (priv->event_client ? FALSE : TRUE); - break; - case ICAL_METHOD_ADD: - itip_desc = _("<b>%s</b> wishes to add to an existing meeting."); - itip_title = _("Meeting Update"); - options = get_publish_options (priv->event_client ? FALSE : TRUE); - break; - case ICAL_METHOD_REFRESH: - itip_desc = _("<b>%s</b> wishes to receive the latest meeting information."); - itip_title = _("Meeting Update Request"); - options = get_refresh_options (); - - /* Provide extra info, since its not in the component */ - adjust_item (itip, priv->comp); - break; - case ICAL_METHOD_REPLY: - itip_desc = _("<b>%s</b> has replied to a meeting request."); - itip_title = _("Meeting Reply"); - options = get_reply_options (); - - /* Provide extra info, since might not be in the component */ - adjust_item (itip, priv->comp); - break; - case ICAL_METHOD_CANCEL: - itip_desc = _("<b>%s</b> has cancelled a meeting."); - itip_title = _("Meeting Cancellation"); - options = get_cancel_options (); - - /* Provide extra info, since might not be in the component */ - adjust_item (itip, priv->comp); - break; - default: - itip_desc = _("<b>%s</b> has sent an unintelligible message."); - itip_title = _("Bad Meeting Message"); - options = NULL; - } - - write_html (itip, itip_desc, itip_title, options); - g_free (options); -} - -static void -show_current_todo (EItipControl *itip) -{ - EItipControlPrivate *priv; - const gchar *itip_title, *itip_desc; - char *options; - - priv = itip->priv; - - if (priv->calendar_uri) - priv->task_client = start_calendar_server (itip, priv->calendar_uri); - else - priv->task_client = find_server (priv->task_clients, priv->comp); - - switch (priv->method) { - case ICAL_METHOD_PUBLISH: - itip_desc = _("<b>%s</b> has published task information."); - itip_title = _("Task Information"); - options = get_publish_options (priv->task_client ? FALSE : TRUE); - break; - case ICAL_METHOD_REQUEST: - if (priv->delegator_address != NULL) - itip_desc = _("<b>%s</b> requests %s to perform a task."); - else - itip_desc = _("<b>%s</b> requests you perform a task."); - itip_title = _("Task Proposal"); - options = get_request_options (priv->task_client ? FALSE : TRUE); - break; - case ICAL_METHOD_ADD: - itip_desc = _("<b>%s</b> wishes to add to an existing task."); - itip_title = _("Task Update"); - options = get_publish_options (priv->task_client ? FALSE : TRUE); - break; - case ICAL_METHOD_REFRESH: - itip_desc = _("<b>%s</b> wishes to receive the latest task information."); - itip_title = _("Task Update Request"); - options = get_refresh_options (); - - /* Provide extra info, since its not in the component */ - adjust_item (itip, priv->comp); - break; - case ICAL_METHOD_REPLY: - itip_desc = _("<b>%s</b> has replied to a task assignment."); - itip_title = _("Task Reply"); - options = get_reply_options (); - - /* Provide extra info, since might not be in the component */ - adjust_item (itip, priv->comp); - break; - case ICAL_METHOD_CANCEL: - itip_desc = _("<b>%s</b> has cancelled a task."); - itip_title = _("Task Cancellation"); - options = get_cancel_options (); - - /* Provide extra info, since might not be in the component */ - adjust_item (itip, priv->comp); - break; - default: - itip_desc = _("<b>%s</b> has sent an unintelligible message."); - itip_title = _("Bad Task Message"); - options = NULL; - } - - write_html (itip, itip_desc, itip_title, options); - g_free (options); -} - -static void -show_current_freebusy (EItipControl *itip) -{ - EItipControlPrivate *priv; - const gchar *itip_title, *itip_desc; - char *options; - - priv = itip->priv; - - switch (priv->method) { - case ICAL_METHOD_PUBLISH: - itip_desc = _("<b>%s</b> has published free/busy information."); - itip_title = _("Free/Busy Information"); - options = NULL; - break; - case ICAL_METHOD_REQUEST: - itip_desc = _("<b>%s</b> requests your free/busy information."); - itip_title = _("Free/Busy Request"); - options = get_request_fb_options (); - break; - case ICAL_METHOD_REPLY: - itip_desc = _("<b>%s</b> has replied to a free/busy request."); - itip_title = _("Free/Busy Reply"); - options = NULL; - break; - default: - itip_desc = _("<b>%s</b> has sent an unintelligible message."); - itip_title = _("Bad Free/Busy Message"); - options = NULL; - } - - write_html (itip, itip_desc, itip_title, options); - g_free (options); -} - -static icalcomponent * -get_next (icalcompiter *iter) -{ - icalcomponent *ret = NULL; - icalcomponent_kind kind; - - do { - icalcompiter_next (iter); - ret = icalcompiter_deref (iter); - kind = icalcomponent_isa (ret); - } while (ret != NULL - && kind != ICAL_VEVENT_COMPONENT - && kind != ICAL_VTODO_COMPONENT - && kind != ICAL_VFREEBUSY_COMPONENT); - - return ret; -} - -static void -show_current (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalComponentVType type; - icalcomponent *alarm_comp; - icalcompiter alarm_iter; - icalproperty *prop; - - priv = itip->priv; - - g_object_ref (itip); - - if (priv->comp) - g_object_unref (priv->comp); - if (priv->event_client != NULL) - g_object_unref (priv->event_client); - priv->event_client = NULL; - if (priv->task_client != NULL) - g_object_unref (priv->task_client); - priv->task_client = NULL; - - /* Determine any delegate sections */ - prop = icalcomponent_get_first_property (priv->ical_comp, ICAL_X_PROPERTY); - while (prop) { - const char *x_name, *x_val; - - x_name = icalproperty_get_x_name (prop); - x_val = icalproperty_get_x (prop); - - if (!strcmp (x_name, "X-EVOLUTION-DELEGATOR-CALENDAR-URI")) - e_itip_control_set_calendar_uri (itip, x_val); - else if (!strcmp (x_name, "X-EVOLUTION-DELEGATOR-ADDRESS")) - e_itip_control_set_delegator_address (itip, x_val); - else if (!strcmp (x_name, "X-EVOLUTION-DELEGATOR-NAME")) - e_itip_control_set_delegator_name (itip, x_val); - - prop = icalcomponent_get_next_property (priv->ical_comp, ICAL_X_PROPERTY); - } - - /* Strip out alarms for security purposes */ - alarm_iter = icalcomponent_begin_component (priv->ical_comp, ICAL_VALARM_COMPONENT); - while ((alarm_comp = icalcompiter_deref (&alarm_iter)) != NULL) { - icalcomponent_remove_component (priv->ical_comp, alarm_comp); - - icalcompiter_next (&alarm_iter); - } - - priv->comp = cal_component_new (); - if (!cal_component_set_icalcomponent (priv->comp, priv->ical_comp)) { - write_error_html (itip, _("The message does not appear to be properly formed")); - g_object_unref (priv->comp); - priv->comp = NULL; - g_object_unref (itip); - return; - }; - - /* Add default reminder if the config says so */ - if (calendar_config_get_use_default_reminder ()) { - CalComponentAlarm *acomp; - int interval; - CalUnits units; - CalAlarmTrigger trigger; - - interval = calendar_config_get_default_reminder_interval (); - units = calendar_config_get_default_reminder_units (); - - acomp = cal_component_alarm_new (); - - cal_component_alarm_set_action (acomp, CAL_ALARM_DISPLAY); - - trigger.type = CAL_ALARM_TRIGGER_RELATIVE_START; - memset (&trigger.u.rel_duration, 0, sizeof (trigger.u.rel_duration)); - - trigger.u.rel_duration.is_neg = TRUE; - - switch (units) { - case CAL_MINUTES: - trigger.u.rel_duration.minutes = interval; - break; - case CAL_HOURS: - trigger.u.rel_duration.hours = interval; - break; - case CAL_DAYS: - trigger.u.rel_duration.days = interval; - break; - default: - g_assert_not_reached (); - } - - cal_component_alarm_set_trigger (acomp, trigger); - cal_component_add_alarm (priv->comp, acomp); - - cal_component_alarm_free (acomp); - } - - type = cal_component_get_vtype (priv->comp); - - switch (type) { - case CAL_COMPONENT_EVENT: - if (!priv->event_clients) - priv->event_clients = get_servers (itip, global_shell_client, calendar_types, FALSE); - show_current_event (itip); - break; - case CAL_COMPONENT_TODO: - if (!priv->task_clients) - priv->task_clients = get_servers (itip, global_shell_client, tasks_types, TRUE); - show_current_todo (itip); - break; - case CAL_COMPONENT_FREEBUSY: - show_current_freebusy (itip); - break; - default: - write_error_html (itip, _("The message contains only unsupported requests.")); - } - - find_my_address (itip, priv->ical_comp); - - g_object_unref (itip); -} - -void -e_itip_control_set_data (EItipControl *itip, const gchar *text) -{ - EItipControlPrivate *priv; - icalproperty *prop; - icalcomponent_kind kind = ICAL_NO_COMPONENT; - icalcomponent *tz_comp; - icalcompiter tz_iter; - - priv = itip->priv; - - clean_up (itip); - - if (text == NULL || *text == '\0') { - gtk_html_load_from_string (GTK_HTML (priv->html), " ", 1); - return; - } - - priv->vcalendar = g_strdup (text); - priv->top_level = cal_util_new_top_level (); - - priv->main_comp = icalparser_parse_string (priv->vcalendar); - if (priv->main_comp == NULL) { - write_error_html (itip, _("The attachment does not contain a valid calendar message")); - return; - } - - prop = icalcomponent_get_first_property (priv->main_comp, ICAL_METHOD_PROPERTY); - if (prop == NULL) { - write_error_html (itip, _("The attachment does not contain a valid calendar message")); - return; - } - - priv->method = icalproperty_get_method (prop); - - tz_iter = icalcomponent_begin_component (priv->main_comp, ICAL_VTIMEZONE_COMPONENT); - while ((tz_comp = icalcompiter_deref (&tz_iter)) != NULL) { - icalcomponent *clone; - - clone = icalcomponent_new_clone (tz_comp); - icalcomponent_add_component (priv->top_level, clone); - - icalcompiter_next (&tz_iter); - } - - priv->iter = icalcomponent_begin_component (priv->main_comp, ICAL_ANY_COMPONENT); - priv->ical_comp = icalcompiter_deref (&priv->iter); - kind = icalcomponent_isa (priv->ical_comp); - if (kind != ICAL_VEVENT_COMPONENT - && kind != ICAL_VTODO_COMPONENT - && kind != ICAL_VFREEBUSY_COMPONENT) - priv->ical_comp = get_next (&priv->iter); - - if (priv->ical_comp == NULL) { - write_error_html (itip, _("The attachment has no viewable calendar items")); - return; - } - - priv->total = icalcomponent_count_components (priv->main_comp, ICAL_VEVENT_COMPONENT); - priv->total += icalcomponent_count_components (priv->main_comp, ICAL_VTODO_COMPONENT); - priv->total += icalcomponent_count_components (priv->main_comp, ICAL_VFREEBUSY_COMPONENT); - - if (priv->total > 0) - priv->current = 1; - else - priv->current = 0; - - show_current (itip); -} - -gchar * -e_itip_control_get_data (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return g_strdup (priv->vcalendar); -} - -gint -e_itip_control_get_data_size (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - if (priv->vcalendar == NULL) - return 0; - - return strlen (priv->vcalendar); -} - -void -e_itip_control_set_from_address (EItipControl *itip, const gchar *address) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - if (priv->from_address) - g_free (priv->from_address); - - priv->from_address = g_strdup (address); -} - -const gchar * -e_itip_control_get_from_address (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return priv->from_address; -} - -void -e_itip_control_set_view_only (EItipControl *itip, gboolean view_only) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - priv->view_only = view_only; -} - -gboolean -e_itip_control_get_view_only (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return priv->view_only; -} - - -void -e_itip_control_set_delegator_address (EItipControl *itip, const gchar *address) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - if (priv->delegator_address) - g_free (priv->delegator_address); - - priv->delegator_address = g_strdup (address); -} - -const gchar * -e_itip_control_get_delegator_address (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return priv->delegator_address; -} - - -void -e_itip_control_set_delegator_name (EItipControl *itip, const gchar *name) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - if (priv->delegator_name) - g_free (priv->delegator_name); - - priv->delegator_name = g_strdup (name); -} - -const gchar * -e_itip_control_get_delegator_name (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return priv->delegator_name; -} - -void -e_itip_control_set_calendar_uri (EItipControl *itip, const gchar *uri) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - if (priv->calendar_uri) - g_free (priv->calendar_uri); - - priv->calendar_uri = g_strdup (uri); -} - -const gchar * -e_itip_control_get_calendar_uri (EItipControl *itip) -{ - EItipControlPrivate *priv; - - priv = itip->priv; - - return priv->calendar_uri; -} - - -static gboolean -change_status (icalcomponent *ical_comp, const char *address, icalparameter_partstat status) -{ - icalproperty *prop; - - prop = find_attendee (ical_comp, address); - if (prop) { - icalparameter *param; - - icalproperty_remove_parameter (prop, ICAL_PARTSTAT_PARAMETER); - param = icalparameter_new_partstat (status); - icalproperty_add_parameter (prop, param); - } else { - icalparameter *param; - - if (address != NULL) { - prop = icalproperty_new_attendee (address); - icalcomponent_add_property (ical_comp, prop); - - param = icalparameter_new_role (ICAL_ROLE_OPTPARTICIPANT); - icalproperty_add_parameter (prop, param); - - param = icalparameter_new_partstat (status); - icalproperty_add_parameter (prop, param); - } else { - EAccount *a; - - a = itip_addresses_get_default (); - - prop = icalproperty_new_attendee (a->id->address); - icalcomponent_add_property (ical_comp, prop); - - param = icalparameter_new_cn (a->id->name); - icalproperty_add_parameter (prop, param); - - param = icalparameter_new_role (ICAL_ROLE_REQPARTICIPANT); - icalproperty_add_parameter (prop, param); - - param = icalparameter_new_partstat (status); - icalproperty_add_parameter (prop, param); - } - } - - return TRUE; -} - -static void -update_item (EItipControl *itip) -{ - EItipControlPrivate *priv; - struct icaltimetype stamp; - icalproperty *prop; - icalcomponent *clone; - CalClient *client; - CalComponentVType type; - GtkWidget *dialog; - CalClientResult result; - - priv = itip->priv; - - /* Set X-MICROSOFT-CDO-REPLYTIME to record the time at which - * the user accepted/declined the request. (Outlook ignores - * SEQUENCE in REPLY reponses and instead requires that each - * updated response have a later REPLYTIME than the previous - * one.) This also ends up getting saved in our own copy of - * the meeting, though there's currently no way to see that - * information (unless it's being saved to an Exchange folder - * and you then look at it in Outlook). - */ - stamp = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); - prop = icalproperty_new_x (icaltime_as_ical_string (stamp)); - icalproperty_set_x_name (prop, "X-MICROSOFT-CDO-REPLYTIME"); - icalcomponent_add_property (priv->ical_comp, prop); - - type = cal_component_get_vtype (priv->comp); - if (type == CAL_COMPONENT_TODO) - client = priv->task_client; - else - client = priv->event_client; - - clone = icalcomponent_new_clone (priv->ical_comp); - icalcomponent_add_component (priv->top_level, clone); - icalcomponent_set_method (priv->top_level, priv->method); - - result = cal_client_update_objects (client, priv->top_level); - switch (result) { - case CAL_CLIENT_RESULT_INVALID_OBJECT : - dialog = gnome_warning_dialog (_("Object is invalid and cannot be updated\n")); - break; - case CAL_CLIENT_RESULT_CORBA_ERROR : - dialog = gnome_warning_dialog (_("There was an error on the CORBA system\n")); - break; - case CAL_CLIENT_RESULT_NOT_FOUND : - dialog = gnome_warning_dialog (_("Object could not be found\n")); - break; - case CAL_CLIENT_RESULT_PERMISSION_DENIED : - dialog = gnome_warning_dialog (_("You do not have the right permissions to update the calendar\n")); - break; - case CAL_CLIENT_RESULT_SUCCESS : - dialog = gnome_ok_dialog (_("Update complete\n")); - break; - default : - dialog = gnome_warning_dialog (_("Calendar file could not be updated!\n")); - break; - } - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - - icalcomponent_remove_component (priv->top_level, clone); -} - -static void -update_attendee_status (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalClient *client; - CalClientGetStatus status; - CalComponent *comp = NULL; - CalComponentVType type; - const char *uid; - GtkWidget *dialog; - CalClientResult result; - - priv = itip->priv; - - type = cal_component_get_vtype (priv->comp); - if (type == CAL_COMPONENT_TODO) - client = priv->task_client; - else - client = priv->event_client; - - if (client == NULL) { - dialog = gnome_warning_dialog (_("Attendee status can not be updated " - "because the item no longer exists")); - goto cleanup; - } - - /* Obtain our version */ - cal_component_get_uid (priv->comp, &uid); - status = cal_client_get_object (client, uid, &comp); - - if (status == CAL_CLIENT_GET_SUCCESS) { - GSList *attendees; - - cal_component_get_attendee_list (priv->comp, &attendees); - if (attendees != NULL) { - CalComponentAttendee *a = attendees->data; - icalproperty *prop; - - prop = find_attendee (cal_component_get_icalcomponent (comp), - itip_strip_mailto (a->value)); - - if (prop == NULL) { - dialog = gnome_question_dialog_modal (_("This response is not from a current " - "attendee. Add as an attendee?"), - NULL, NULL); - if (gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == GNOME_YES) { - change_status (cal_component_get_icalcomponent (comp), - itip_strip_mailto (a->value), - a->status); - cal_component_rescan (comp); - } else { - goto cleanup; - } - } else if (a->status == ICAL_PARTSTAT_NONE || a->status == ICAL_PARTSTAT_X) { - dialog = gnome_warning_dialog (_("Attendee status could " - "not be updated because " - "of an invalid status!\n")); - goto cleanup; - } else { - change_status (cal_component_get_icalcomponent (comp), - itip_strip_mailto (a->value), - a->status); - cal_component_rescan (comp); - } - } - - result = cal_client_update_object (client, comp); - switch (result) { - case CAL_CLIENT_RESULT_INVALID_OBJECT : - dialog = gnome_warning_dialog (_("Object is invalid and cannot be updated\n")); - break; - case CAL_CLIENT_RESULT_CORBA_ERROR : - dialog = gnome_warning_dialog (_("There was an error on the CORBA system\n")); - break; - case CAL_CLIENT_RESULT_NOT_FOUND : - dialog = gnome_warning_dialog (_("Object could not be found\n")); - break; - case CAL_CLIENT_RESULT_PERMISSION_DENIED : - dialog = gnome_warning_dialog (_("You don't have the right permissions to update the calendar\n")); - break; - case CAL_CLIENT_RESULT_SUCCESS : - dialog = gnome_ok_dialog (_("Attendee status updated\n")); - break; - default : - dialog = gnome_warning_dialog (_("Attendee status could not be updated!\n")); - } - } else { - dialog = gnome_warning_dialog (_("Attendee status can not be updated " - "because the item no longer exists")); - } - - cleanup: - if (comp != NULL) - g_object_unref (comp); - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); -} - -static void -remove_item (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalClient *client; - CalComponentVType type; - const char *uid; - GtkWidget *dialog; - CalClientResult result; - - priv = itip->priv; - - type = cal_component_get_vtype (priv->comp); - if (type == CAL_COMPONENT_TODO) - client = priv->task_client; - else - client = priv->event_client; - - if (client == NULL) - return; - - cal_component_get_uid (priv->comp, &uid); - result = cal_client_remove_object (client, uid); - if (result == CAL_CLIENT_RESULT_SUCCESS || result == CAL_CLIENT_RESULT_NOT_FOUND) { - dialog = gnome_ok_dialog (_("Removal Complete")); - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - } else { - delete_error_dialog (result, type); - } -} - -static void -send_item (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalComponent *comp; - CalComponentVType vtype; - GtkWidget *dialog; - - priv = itip->priv; - - comp = get_real_item (itip); - vtype = cal_component_get_vtype (comp); - - if (comp != NULL) { - switch (vtype) { - case CAL_COMPONENT_EVENT: - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, priv->event_client, NULL); - break; - case CAL_COMPONENT_TODO: - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, priv->task_client, NULL); - break; - default: - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, NULL, NULL); - } - g_object_unref (comp); - dialog = gnome_ok_dialog (_("Item sent!\n")); - } else { - dialog = gnome_warning_dialog (_("The item could not be sent!\n")); - } - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); -} - -static void -send_freebusy (EItipControl *itip) -{ - EItipControlPrivate *priv; - CalComponentDateTime datetime; - time_t start, end; - GtkWidget *dialog; - GList *comp_list; - icaltimezone *zone; - - priv = itip->priv; - - cal_component_get_dtstart (priv->comp, &datetime); - if (datetime.tzid) { - zone = icalcomponent_get_timezone (priv->top_level, - datetime.tzid); - } else { - zone = NULL; - } - start = icaltime_as_timet_with_zone (*datetime.value, zone); - cal_component_free_datetime (&datetime); - - cal_component_get_dtend (priv->comp, &datetime); - if (datetime.tzid) { - zone = icalcomponent_get_timezone (priv->top_level, - datetime.tzid); - } else { - zone = NULL; - } - end = icaltime_as_timet_with_zone (*datetime.value, zone); - cal_component_free_datetime (&datetime); - - comp_list = cal_client_get_free_busy (priv->event_client, NULL, start, end); - - if (comp_list) { - GList *l; - - for (l = comp_list; l; l = l->next) { - CalComponent *comp = CAL_COMPONENT (l->data); - itip_send_comp (CAL_COMPONENT_METHOD_REPLY, comp, priv->event_client, NULL); - - g_object_unref (comp); - } - dialog = gnome_ok_dialog (_("Item sent!\n")); - - g_list_free (comp_list); - } else { - dialog = gnome_warning_dialog (_("The item could not be sent!\n")); - } - gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); -} - -static void -button_selected_cb (EvolutionFolderSelectorButton *button, GNOME_Evolution_Folder *folder, gpointer data) -{ - EItipControl *itip = E_ITIP_CONTROL (data); - EItipControlPrivate *priv; - CalComponentVType type; - char *uri; - - priv = itip->priv; - - type = cal_component_get_vtype (priv->comp); - if (type == CAL_COMPONENT_TODO) - uri = cal_util_expand_uri (folder->physicalUri, TRUE); - else - uri = cal_util_expand_uri (folder->physicalUri, FALSE); - - g_object_unref (priv->event_client); - priv->event_client = start_calendar_server (itip, uri); - - g_free (uri); -} - -static void -url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *handle, gpointer data) -{ unsigned char buffer[4096]; - int len, fd; - char *path; - - path = g_strdup_printf ("%s/%s", EVOLUTION_IMAGESDIR, url); - - if ((fd = open (path, O_RDONLY)) == -1) { - g_warning ("%s", g_strerror (errno)); - goto cleanup; - } - - while ((len = read (fd, buffer, 4096)) > 0) { - gtk_html_write (html, handle, buffer, len); - } - - if (len < 0) { - /* check to see if we stopped because of an error */ - gtk_html_end (html, handle, GTK_HTML_STREAM_ERROR); - g_warning ("%s", g_strerror (errno)); - goto cleanup; - } - /* done with no errors */ - gtk_html_end (html, handle, GTK_HTML_STREAM_OK); - close (fd); - - cleanup: - g_free (path); -} - -static gboolean -object_requested_cb (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data) -{ - EItipControl *itip = E_ITIP_CONTROL (data); - EItipControlPrivate *priv; - GtkWidget *button; - CalComponentVType vtype; - - priv = itip->priv; - - vtype = cal_component_get_vtype (priv->comp); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - button = evolution_folder_selector_button_new ( - global_shell_client, _("Select Calendar Folder"), - calendar_config_default_calendar_folder (), - calendar_types); - priv->event_client = start_default_server (itip, FALSE); - break; - case CAL_COMPONENT_TODO: - button = evolution_folder_selector_button_new ( - global_shell_client, _("Select Tasks Folder"), - calendar_config_default_tasks_folder (), - tasks_types); - priv->task_client = start_default_server (itip, TRUE); - break; - default: - button = NULL; - } - - g_signal_connect (button, "selected", G_CALLBACK (button_selected_cb), itip); - - gtk_container_add (GTK_CONTAINER (eb), button); - gtk_widget_show (button); - - return TRUE; -} - -static void -ok_clicked_cb (GtkHTML *html, const gchar *method, const gchar *url, const gchar *encoding, gpointer data) -{ - EItipControl *itip = E_ITIP_CONTROL (data); - EItipControlPrivate *priv; - gchar **fields; - gboolean rsvp = FALSE, status = FALSE; - int i; - - priv = itip->priv; - - fields = g_strsplit (encoding, "&", -1); - for (i = 0; fields[i] != NULL; i++) { - gchar **key_value; - - key_value = g_strsplit (fields[i], "=", 2); - - if (key_value[0] != NULL && !strcmp (key_value[0], "action")) { - if (key_value[1] == NULL) - break; - - switch (key_value[1][0]) { - case 'U': - update_item (itip); - break; - case 'A': - status = change_status (priv->ical_comp, priv->my_address, - ICAL_PARTSTAT_ACCEPTED); - if (status) { - cal_component_rescan (priv->comp); - update_item (itip); - } - break; - case 'T': - status = change_status (priv->ical_comp, priv->my_address, - ICAL_PARTSTAT_TENTATIVE); - if (status) { - cal_component_rescan (priv->comp); - update_item (itip); - } - break; - case 'D': - status = change_status (priv->ical_comp, priv->my_address, - ICAL_PARTSTAT_DECLINED); - if (status) { - cal_component_rescan (priv->comp); - remove_item (itip); - } - break; - case 'F': - send_freebusy (itip); - break; - case 'R': - update_attendee_status (itip); - break; - case 'S': - send_item (itip); - break; - case 'C': - update_item (itip); - break; - } - } - - if (key_value[0] != NULL && !strcmp (key_value[0], "rsvp")) - if (*key_value[1] == '1') - rsvp = TRUE; - - g_strfreev (key_value); - - } - g_strfreev (fields); - - if (rsvp && status) { - CalComponent *comp = NULL; - CalComponentVType vtype; - icalcomponent *ical_comp; - icalproperty *prop; - icalvalue *value; - const char *attendee; - GSList *l, *list = NULL; - - comp = cal_component_clone (priv->comp); - if (comp == NULL) - return; - vtype = cal_component_get_vtype (comp); - - if (priv->my_address == NULL) - find_my_address (itip, priv->ical_comp); - g_assert (priv->my_address != NULL); - - ical_comp = cal_component_get_icalcomponent (comp); - - for (prop = icalcomponent_get_first_property (ical_comp, ICAL_ATTENDEE_PROPERTY); - prop != NULL; - prop = icalcomponent_get_next_property (ical_comp, ICAL_ATTENDEE_PROPERTY)) - { - char *text; - - value = icalproperty_get_value (prop); - if (!value) - continue; - - attendee = icalvalue_get_string (value); - - text = g_strdup (itip_strip_mailto (attendee)); - text = g_strstrip (text); - if (g_strcasecmp (priv->my_address, text)) - list = g_slist_prepend (list, prop); - g_free (text); - } - - for (l = list; l; l = l->next) { - prop = l->data; - icalcomponent_remove_property (ical_comp, prop); - icalproperty_free (prop); - } - g_slist_free (list); - - cal_component_rescan (comp); - switch (vtype) { - case CAL_COMPONENT_EVENT: - itip_send_comp (CAL_COMPONENT_METHOD_REPLY, comp, - priv->event_client, priv->top_level); - break; - case CAL_COMPONENT_TODO: - itip_send_comp (CAL_COMPONENT_METHOD_REPLY, comp, - priv->task_client, priv->top_level); - break; - default: - itip_send_comp (CAL_COMPONENT_METHOD_REPLY, comp, NULL, NULL); - } - g_object_unref (comp); - } -} diff --git a/calendar/gui/e-itip-control.glade b/calendar/gui/e-itip-control.glade deleted file mode 100644 index 344bcdeced..0000000000 --- a/calendar/gui/e-itip-control.glade +++ /dev/null @@ -1,493 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd" > - -<glade-interface> - <widget class="GtkWindow" id="window1"> - <property name="visible">no</property> - <property name="title" translatable="yes">window1</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="modal">no</property> - <property name="allow_shrink">no</property> - <property name="allow_grow">yes</property> - <property name="window-position">GTK_WIN_POS_NONE</property> - - <child> - <widget class="GtkFrame" id="main_frame"> - <property name="border_width">4</property> - <property name="label" translatable="yes">Calendar Message</property> - <property name="label_xalign">0</property> - <property name="shadow">GTK_SHADOW_ETCHED_IN</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow1"> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkViewport" id="viewport1"> - <property name="shadow_type">GTK_SHADOW_NONE</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkVBox" id="vbox1"> - <property name="homogeneous">no</property> - <property name="spacing">0</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkTable" id="table1"> - <property name="border_width">3</property> - <property name="homogeneous">no</property> - <property name="row_spacing">3</property> - <property name="column_spacing">3</property> - <property name="n-rows">4</property> - <property name="n-columns">2</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkEntry" id="organizer_entry"> - <property name="can_focus">yes</property> - <property name="editable">no</property> - <property name="text" translatable="yes"></property> - <property name="max-length">0</property> - <property name="visibility">yes</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">expand|fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkEntry" id="summary_entry"> - <property name="can_focus">yes</property> - <property name="editable">no</property> - <property name="text" translatable="yes"></property> - <property name="max-length">0</property> - <property name="visibility">yes</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">expand|fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow2"> - <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkTextView" id="description_box"> - <property name="can_focus">yes</property> - <property name="editable">no</property> - <property name="text" translatable="yes"></property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="visible">yes</property> - </widget> - </child> - - <child internal-child="hscrollbar"> - <widget class="GtkHScrollbar" id="convertwidget3"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - - <child internal-child="vscrollbar"> - <widget class="GtkVScrollbar" id="convertwidget4"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkAlignment" id="alignment1"> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xscale">1</property> - <property name="yscale">1</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkHBox" id="hbox1"> - <property name="homogeneous">no</property> - <property name="spacing">0</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkLabel" id="dtstart_label"> - <property name="label" translatable="yes">date-start</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">no</property> - <property name="xalign">0.5</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label3"> - <property name="label" translatable="yes">--to--</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">no</property> - <property name="xalign">0.5</property> - <property name="yalign">0</property> - <property name="xpad">19</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="dtend_label"> - <property name="label" translatable="yes">date-end</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">no</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">expand|fill</property> - <property name="y_options">fill</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label6"> - <property name="label" translatable="yes">Organizer:</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">no</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label7"> - <property name="label" translatable="yes">Date:</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">no</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label8"> - <property name="label" translatable="yes">Summary:</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">no</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label9"> - <property name="label" translatable="yes">Description:</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">no</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_padding">0</property> - <property name="y_padding">0</property> - <property name="x_options">fill</property> - <property name="y_options">fill</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">6</property> - <property name="expand">yes</property> - <property name="fill">yes</property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label12"> - <property name="label" translatable="yes">Server Message:</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">no</property> - <property name="xalign">7.45058e-09</property> - <property name="yalign">0.5</property> - <property name="xpad">3</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow3"> - <property name="border_width">3</property> - <property name="hscrollbar_policy">GTK_POLICY_NEVER</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_IN</property> - <property name="width-request">365</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkTextView" id="message_text"> - <property name="can_focus">yes</property> - <property name="editable">no</property> - <property name="text" translatable="yes"></property> - <property name="wrap_mode">GTK_WRAP_WORD</property> - <property name="visible">yes</property> - </widget> - </child> - - <child internal-child="hscrollbar"> - <widget class="GtkHScrollbar" id="convertwidget5"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - - <child internal-child="vscrollbar"> - <widget class="GtkVScrollbar" id="convertwidget6"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">yes</property> - <property name="fill">no</property> - </packing> - </child> - - <child> - <widget class="GtkHBox" id="button_box"> - <property name="border_width">3</property> - <property name="homogeneous">no</property> - <property name="spacing">0</property> - <property name="height-request">30</property> - <property name="visible">yes</property> - - <child> - <placeholder /> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - </widget> - </child> - </widget> - </child> - - <child internal-child="hscrollbar"> - <widget class="GtkHScrollbar" id="convertwidget1"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - - <child internal-child="vscrollbar"> - <widget class="GtkVScrollbar" id="convertwidget2"> - <property name="update_policy">GTK_UPDATE_CONTINUOUS</property> - <property name="visible">yes</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - </widget> - <widget class="GtkWindow" id="loading_window"> - <property name="visible">no</property> - <property name="title" translatable="yes">Loading Calendar</property> - <property name="type">GTK_WINDOW_DIALOG</property> - <property name="modal">no</property> - <property name="allow_shrink">no</property> - <property name="allow_grow">yes</property> - <property name="window-position">GTK_WIN_POS_CENTER</property> - - <child> - <widget class="GtkFrame" id="frame1"> - <property name="border_width">4</property> - <property name="label" translatable="yes"></property> - <property name="label_xalign">0</property> - <property name="shadow">GTK_SHADOW_ETCHED_OUT</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkVBox" id="vbox2"> - <property name="border_width">7</property> - <property name="homogeneous">no</property> - <property name="spacing">1</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkHBox" id="hbox2"> - <property name="border_width">6</property> - <property name="homogeneous">no</property> - <property name="spacing">9</property> - <property name="visible">yes</property> - - <child> - <widget class="GtkLabel" id="label10"> - <property name="label" translatable="yes">Loading calendar...</property> - <property name="justify">GTK_JUSTIFY_CENTER</property> - <property name="wrap">no</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="visible">yes</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - - <child> - <widget class="GtkProgressBar" id="loading_progress"> - <property name="bar_style">GTK_PROGRESS_CONTINUOUS</property> - <property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property> - <property name="activity_mode">no</property> - <property name="show_text">no</property> - <property name="format" translatable="yes">%P %%</property> - <property name="text_xalign">0.5</property> - <property name="text_yalign">0.5</property> - <property name="visible">yes</property> - <property name="adjustment">0 0 100 1 10 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">no</property> - <property name="fill">no</property> - </packing> - </child> - </widget> - </child> - </widget> - </child> - </widget> -</glade-interface> diff --git a/calendar/gui/e-itip-control.h b/calendar/gui/e-itip-control.h deleted file mode 100644 index 12ddf7354e..0000000000 --- a/calendar/gui/e-itip-control.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-itip-control.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_ITIP_CONTROL_H_ -#define _E_ITIP_CONTROL_H_ - -#include <gtk/gtk.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_ITIP_CONTROL (e_itip_control_get_type ()) -#define E_ITIP_CONTROL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_ITIP_CONTROL, EItipControl)) -#define E_ITIP_CONTROL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_ITIP_CONTROL, EItipControlClass)) -#define E_IS_ITIP_CONTROL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_ITIP_CONTROL)) -#define E_IS_ITIP_CONTROL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_ITIP_CONTROL)) - - -typedef struct _EItipControl EItipControl; -typedef struct _EItipControlPrivate EItipControlPrivate; -typedef struct _EItipControlClass EItipControlClass; - -struct _EItipControl { - GtkVBox parent; - - EItipControlPrivate *priv; -}; - -struct _EItipControlClass { - GtkVBoxClass parent_class; -}; - - - -GtkType e_itip_control_get_type (void); -GtkWidget * e_itip_control_new (void); -void e_itip_control_set_data (EItipControl *itip, - const gchar *text); -gchar * e_itip_control_get_data (EItipControl *itip); -gint e_itip_control_get_data_size (EItipControl *itip); -void e_itip_control_set_from_address (EItipControl *itip, - const gchar *address); -const gchar *e_itip_control_get_from_address (EItipControl *itip); -void e_itip_control_set_view_only (EItipControl *itip, - gboolean view_only); -gboolean e_itip_control_get_view_only (EItipControl *itip); -void e_itip_control_set_delegator_address (EItipControl *itip, - const gchar *address); -const gchar *e_itip_control_get_delegator_address (EItipControl *itip); -void e_itip_control_set_delegator_name (EItipControl *itip, - const gchar *name); -const gchar *e_itip_control_get_delegator_name (EItipControl *itip); -void e_itip_control_set_calendar_uri (EItipControl *itip, - const gchar *uri); -const gchar *e_itip_control_get_calendar_uri (EItipControl *itip); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ITIP_CONTROL_H_ */ diff --git a/calendar/gui/e-meeting-attendee.c b/calendar/gui/e-meeting-attendee.c deleted file mode 100644 index f25dbc35de..0000000000 --- a/calendar/gui/e-meeting-attendee.c +++ /dev/null @@ -1,997 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-attendee.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <gtk/gtk.h> -#include <gal/util/e-util.h> -#include "e-meeting-attendee.h" - -struct _EMeetingAttendeePrivate { - gchar *address; - gchar *member; - - icalparameter_cutype cutype; - icalparameter_role role; - - gboolean rsvp; - - gchar *delto; - gchar *delfrom; - - icalparameter_partstat status; - - gchar *sentby; - gchar *cn; - gchar *language; - - EMeetingAttendeeEditLevel edit_level; - - gboolean has_calendar_info; - - GArray *busy_periods; - gboolean busy_periods_sorted; - - EMeetingTime busy_periods_start; - EMeetingTime busy_periods_end; - gboolean start_busy_range_set; - gboolean end_busy_range_set; - - gint longest_period_in_days; -}; - -enum { - CHANGED, - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL]; - -static void class_init (EMeetingAttendeeClass *klass); -static void init (EMeetingAttendee *ia); -static void finalize (GObject *obj); - - -static GObjectClass *parent_class = NULL; - -E_MAKE_TYPE (e_meeting_attendee, "EMeetingAttendee", EMeetingAttendee, - class_init, init, G_TYPE_OBJECT); - -static void -class_init (EMeetingAttendeeClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - - signals[CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EMeetingAttendeeClass, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - object_class->finalize = finalize; -} - -static gchar * -string_test (gchar *string) -{ - return string != NULL ? string : g_strdup (""); -} - -static gboolean -string_is_set (gchar *string) -{ - if (string != NULL && *string != '\0') - return TRUE; - - return FALSE; -} - -static void -notify_changed (EMeetingAttendee *ia) -{ - g_signal_emit_by_name (G_OBJECT (ia), "changed"); -} - -static void -init (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = g_new0 (EMeetingAttendeePrivate, 1); - - ia->priv = priv; - - priv->address = string_test (NULL); - priv->member = string_test (NULL); - - priv->cutype = ICAL_CUTYPE_NONE; - priv->role = ICAL_ROLE_NONE; - - priv->rsvp = FALSE; - - priv->delto = string_test (NULL); - priv->delfrom = string_test (NULL); - - priv->status = ICAL_PARTSTAT_NONE; - - priv->sentby = string_test (NULL); - priv->cn = string_test (NULL); - priv->language = string_test (NULL); - - priv->edit_level = E_MEETING_ATTENDEE_EDIT_FULL; - priv->has_calendar_info = FALSE; - - priv->busy_periods = g_array_new (FALSE, FALSE, sizeof (EMeetingFreeBusyPeriod)); - priv->busy_periods_sorted = FALSE; - - g_date_clear (&priv->busy_periods_start.date, 1); - priv->busy_periods_start.hour = 0; - priv->busy_periods_start.minute = 0; - - g_date_clear (&priv->busy_periods_end.date, 1); - priv->busy_periods_end.hour = 0; - priv->busy_periods_end.minute = 0; - - priv->start_busy_range_set = FALSE; - priv->end_busy_range_set = FALSE; - - priv->longest_period_in_days = 0; -} - - -static void -finalize (GObject *obj) -{ - EMeetingAttendee *ia = E_MEETING_ATTENDEE (obj); - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - g_free (priv->address); - g_free (priv->member); - - g_free (priv->delto); - g_free (priv->delfrom); - - g_free (priv->sentby); - g_free (priv->cn); - g_free (priv->language); - - g_array_free (priv->busy_periods, TRUE); - - g_free (priv); -} - -GObject * -e_meeting_attendee_new (void) -{ - return g_object_new (E_TYPE_MEETING_ATTENDEE, NULL); -} - -GObject * -e_meeting_attendee_new_from_cal_component_attendee (CalComponentAttendee *ca) -{ - EMeetingAttendee *ia; - - ia = E_MEETING_ATTENDEE (g_object_new (E_TYPE_MEETING_ATTENDEE, NULL)); - - e_meeting_attendee_set_address (ia, g_strdup (ca->value)); - e_meeting_attendee_set_member (ia, g_strdup (ca->member)); - e_meeting_attendee_set_cutype (ia, ca->cutype); - e_meeting_attendee_set_role (ia, ca->role); - e_meeting_attendee_set_status (ia, ca->status); - e_meeting_attendee_set_rsvp (ia, ca->rsvp); - e_meeting_attendee_set_delto (ia, g_strdup (ca->delto)); - e_meeting_attendee_set_delfrom (ia, g_strdup (ca->delfrom)); - e_meeting_attendee_set_sentby (ia, g_strdup (ca->sentby)); - e_meeting_attendee_set_cn (ia, g_strdup (ca->cn)); - e_meeting_attendee_set_language (ia, g_strdup (ca->language)); - - return G_OBJECT (ia); -} - -CalComponentAttendee * -e_meeting_attendee_as_cal_component_attendee (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - CalComponentAttendee *ca; - - priv = ia->priv; - - ca = g_new0 (CalComponentAttendee, 1); - - ca->value = priv->address; - ca->member = string_is_set (priv->member) ? priv->member : NULL; - ca->cutype= priv->cutype; - ca->role = priv->role; - ca->status = priv->status; - ca->rsvp = priv->rsvp; - ca->delto = string_is_set (priv->delto) ? priv->delto : NULL; - ca->delfrom = string_is_set (priv->delfrom) ? priv->delfrom : NULL; - ca->sentby = string_is_set (priv->sentby) ? priv->sentby : NULL; - ca->cn = string_is_set (priv->cn) ? priv->cn : NULL; - ca->language = string_is_set (priv->language) ? priv->language : NULL; - - return ca; -} - - -const gchar * -e_meeting_attendee_get_address (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->address; -} - -void -e_meeting_attendee_set_address (EMeetingAttendee *ia, gchar *address) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->address != NULL) - g_free (priv->address); - - priv->address = string_test (address); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_address (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->address); -} - -const gchar * -e_meeting_attendee_get_member (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->member; -} - -void -e_meeting_attendee_set_member (EMeetingAttendee *ia, gchar *member) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->member != NULL) - g_free (priv->member); - - priv->member = string_test (member); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_member (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->member); -} - -icalparameter_cutype -e_meeting_attendee_get_cutype (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->cutype; -} - -void -e_meeting_attendee_set_cutype (EMeetingAttendee *ia, icalparameter_cutype cutype) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - priv->cutype = cutype; - - notify_changed (ia); -} - -icalparameter_role -e_meeting_attendee_get_role (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->role; -} - -void -e_meeting_attendee_set_role (EMeetingAttendee *ia, icalparameter_role role) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - priv->role = role; - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_get_rsvp (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->rsvp; -} - -void -e_meeting_attendee_set_rsvp (EMeetingAttendee *ia, gboolean rsvp) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - priv->rsvp = rsvp; - - notify_changed (ia); -} - -const gchar * -e_meeting_attendee_get_delto (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->delto; -} - -void -e_meeting_attendee_set_delto (EMeetingAttendee *ia, gchar *delto) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->delto != NULL) - g_free (priv->delto); - - priv->delto = string_test (delto); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_delto (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->delto); -} - -const gchar * -e_meeting_attendee_get_delfrom (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->delfrom; -} - -void -e_meeting_attendee_set_delfrom (EMeetingAttendee *ia, gchar *delfrom) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->delfrom != NULL) - g_free (priv->delfrom); - - priv->delfrom = string_test (delfrom); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_delfrom (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->delfrom); -} - -icalparameter_partstat -e_meeting_attendee_get_status (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->status; -} - -void -e_meeting_attendee_set_status (EMeetingAttendee *ia, icalparameter_partstat status) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - priv->status = status; - - notify_changed (ia); -} - -const gchar * -e_meeting_attendee_get_sentby (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->sentby; -} - -void -e_meeting_attendee_set_sentby (EMeetingAttendee *ia, gchar *sentby) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->sentby != NULL) - g_free (priv->sentby); - - priv->sentby = string_test (sentby); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_sentby (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->sentby); -} - -const gchar * -e_meeting_attendee_get_cn (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->cn; -} - -void -e_meeting_attendee_set_cn (EMeetingAttendee *ia, gchar *cn) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->cn != NULL) - g_free (priv->cn); - - priv->cn = string_test (cn); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_cn (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->cn); -} - -const gchar * -e_meeting_attendee_get_language (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->language; -} - -void -e_meeting_attendee_set_language (EMeetingAttendee *ia, gchar *language) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->language != NULL) - g_free (priv->language); - - priv->language = string_test (language); - - notify_changed (ia); -} - -gboolean -e_meeting_attendee_is_set_language (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return string_is_set (priv->language); -} - -EMeetingAttendeeType -e_meeting_attendee_get_atype (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->cutype == ICAL_CUTYPE_ROOM - || priv->cutype == ICAL_CUTYPE_RESOURCE) - return E_MEETING_ATTENDEE_RESOURCE; - - if (priv->role == ICAL_ROLE_CHAIR - || priv->role == ICAL_ROLE_REQPARTICIPANT) - return E_MEETING_ATTENDEE_REQUIRED_PERSON; - - return E_MEETING_ATTENDEE_OPTIONAL_PERSON; -} - - -EMeetingAttendeeEditLevel -e_meeting_attendee_get_edit_level (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - g_return_val_if_fail (ia != NULL, E_MEETING_ATTENDEE_EDIT_NONE); - g_return_val_if_fail (E_IS_MEETING_ATTENDEE (ia), E_MEETING_ATTENDEE_EDIT_NONE); - - priv = ia->priv; - - return priv->edit_level; -} - -void -e_meeting_attendee_set_edit_level (EMeetingAttendee *ia, EMeetingAttendeeEditLevel level) -{ - EMeetingAttendeePrivate *priv; - - g_return_if_fail (ia != NULL); - g_return_if_fail (E_IS_MEETING_ATTENDEE (ia)); - - priv = ia->priv; - - priv->edit_level = level; -} - - -static gint -compare_times (EMeetingTime *time1, - EMeetingTime *time2) -{ - gint day_comparison; - - day_comparison = g_date_compare (&time1->date, - &time2->date); - if (day_comparison != 0) - return day_comparison; - - if (time1->hour < time2->hour) - return -1; - if (time1->hour > time2->hour) - return 1; - - if (time1->minute < time2->minute) - return -1; - if (time1->minute > time2->minute) - return 1; - - /* The start times are exactly the same. */ - return 0; -} - -static gint -compare_period_starts (const void *arg1, - const void *arg2) -{ - EMeetingFreeBusyPeriod *period1, *period2; - - period1 = (EMeetingFreeBusyPeriod *) arg1; - period2 = (EMeetingFreeBusyPeriod *) arg2; - - return compare_times (&period1->start, &period2->start); -} - -static void -ensure_periods_sorted (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - if (priv->busy_periods_sorted) - return; - - qsort (priv->busy_periods->data, priv->busy_periods->len, - sizeof (EMeetingFreeBusyPeriod), - compare_period_starts); - - priv->busy_periods_sorted = TRUE; -} - -gboolean -e_meeting_attendee_get_has_calendar_info (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->has_calendar_info; -} - -void -e_meeting_attendee_set_has_calendar_info (EMeetingAttendee *ia, gboolean has_calendar_info) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - priv->has_calendar_info = has_calendar_info; -} - -const GArray * -e_meeting_attendee_get_busy_periods (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - ensure_periods_sorted (ia); - - return priv->busy_periods; -} - -gint -e_meeting_attendee_find_first_busy_period (EMeetingAttendee *ia, GDate *date) -{ - EMeetingAttendeePrivate *priv; - EMeetingFreeBusyPeriod *period; - gint lower, upper, middle = 0, cmp = 0; - GDate tmp_date; - - priv = ia->priv; - - /* Make sure the busy periods have been sorted. */ - ensure_periods_sorted (ia); - - /* Calculate the first day which could have a busy period which - continues onto our given date. */ - tmp_date = *date; - g_date_subtract_days (&tmp_date, priv->longest_period_in_days); - - /* We want the first busy period which starts on tmp_date. */ - lower = 0; - upper = priv->busy_periods->len; - - if (upper == 0) - return -1; - - while (lower < upper) { - middle = (lower + upper) >> 1; - - period = &g_array_index (priv->busy_periods, - EMeetingFreeBusyPeriod, middle); - - cmp = g_date_compare (&tmp_date, &period->start.date); - - if (cmp == 0) - break; - else if (cmp < 0) - upper = middle; - else - lower = middle + 1; - } - - /* There may be several busy periods on the same day so we step - backwards to the first one. */ - if (cmp == 0) { - while (middle > 0) { - period = &g_array_index (priv->busy_periods, - EMeetingFreeBusyPeriod, middle - 1); - if (g_date_compare (&tmp_date, &period->start.date) != 0) - break; - middle--; - } - } else if (cmp > 0) { - /* This means we couldn't find a period on the given day, and - the last one we looked at was before it, so if there are - any more periods after this one we return it. */ - middle++; - if (priv->busy_periods->len <= middle) - return -1; - } - - return middle; -} - -gboolean -e_meeting_attendee_add_busy_period (EMeetingAttendee *ia, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingFreeBusyType busy_type) -{ - EMeetingAttendeePrivate *priv; - EMeetingFreeBusyPeriod period; - gint period_in_days; - - g_return_val_if_fail (ia != NULL, FALSE); - g_return_val_if_fail (E_IS_MEETING_ATTENDEE (ia), FALSE); - g_return_val_if_fail (busy_type >= 0, FALSE); - g_return_val_if_fail (busy_type < E_MEETING_FREE_BUSY_LAST, FALSE); - - priv = ia->priv; - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year)) - return FALSE; - if (!g_date_valid_dmy (end_day, end_month, end_year)) - return FALSE; - if (start_hour < 0 || start_hour > 23) - return FALSE; - if (end_hour < 0 || end_hour > 23) - return FALSE; - if (start_minute < 0 || start_minute > 59) - return FALSE; - if (end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_clear (&period.start.date, 1); - g_date_clear (&period.end.date, 1); - g_date_set_dmy (&period.start.date, start_day, start_month, start_year); - g_date_set_dmy (&period.end.date, end_day, end_month, end_year); - period.start.hour = start_hour; - period.start.minute = start_minute; - period.end.hour = end_hour; - period.end.minute = end_minute; - period.busy_type = busy_type; - - /* Check that the start time is before or equal to the end time. */ - if (compare_times (&period.start, &period.end) > 0) - return FALSE; - - /* If the busy range is not set elsewhere, track it as best we can */ - if (!priv->start_busy_range_set) { - if (!g_date_valid (&priv->busy_periods_start.date)) { - priv->busy_periods_start.date = period.start.date; - priv->busy_periods_start.hour = period.start.hour; - priv->busy_periods_start.minute = period.start.minute; - } else { - switch (g_date_compare (&period.start.date, &priv->busy_periods_start.date)) { - case -1: - priv->busy_periods_start.date = period.start.date; - priv->busy_periods_start.hour = period.start.hour; - priv->busy_periods_start.minute = period.start.minute; - break; - case 0: - if (period.start.hour < priv->busy_periods_start.hour - || (period.start.hour == priv->busy_periods_start.hour - && period.start.minute < priv->busy_periods_start.minute)) { - priv->busy_periods_start.date = period.start.date; - priv->busy_periods_start.hour = period.start.hour; - priv->busy_periods_start.minute = period.start.minute; - break; - } - break; - } - } - } - if (!priv->end_busy_range_set) { - if (!g_date_valid (&priv->busy_periods_end.date)) { - priv->busy_periods_end.date = period.end.date; - priv->busy_periods_end.hour = period.end.hour; - priv->busy_periods_end.minute = period.end.minute; - } else { - switch (g_date_compare (&period.end.date, &priv->busy_periods_end.date)) { - case 0: - if (period.end.hour > priv->busy_periods_end.hour - || (period.end.hour == priv->busy_periods_end.hour - && period.end.minute > priv->busy_periods_end.minute)) { - priv->busy_periods_end.date = period.end.date; - priv->busy_periods_end.hour = period.end.hour; - priv->busy_periods_end.minute = period.end.minute; - break; - } - break; - case 1: - priv->busy_periods_end.date = period.end.date; - priv->busy_periods_end.hour = period.end.hour; - priv->busy_periods_end.minute = period.end.minute; - break; - } - } - } - - g_array_append_val (priv->busy_periods, period); - priv->has_calendar_info = TRUE; - priv->busy_periods_sorted = FALSE; - - period_in_days = g_date_julian (&period.end.date) - g_date_julian (&period.start.date) + 1; - priv->longest_period_in_days = MAX (priv->longest_period_in_days, period_in_days); - - return TRUE; -} - -EMeetingTime -e_meeting_attendee_get_start_busy_range (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->busy_periods_start; -} - -EMeetingTime -e_meeting_attendee_get_end_busy_range (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - priv = ia->priv; - - return priv->busy_periods_end; -} - -gboolean -e_meeting_attendee_set_start_busy_range (EMeetingAttendee *ia, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute) -{ - EMeetingAttendeePrivate *priv; - - g_return_val_if_fail (E_IS_MEETING_ATTENDEE (ia), FALSE); - - priv = ia->priv; - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year)) - return FALSE; - if (start_hour < 0 || start_hour > 23) - return FALSE; - if (start_minute < 0 || start_minute > 59) - return FALSE; - - g_date_clear (&priv->busy_periods_start.date, 1); - g_date_set_dmy (&priv->busy_periods_start.date, - start_day, start_month, start_year); - priv->busy_periods_start.hour = start_hour; - priv->busy_periods_start.minute = start_minute; - - priv->start_busy_range_set = TRUE; - - return TRUE; -} - -gboolean -e_meeting_attendee_set_end_busy_range (EMeetingAttendee *ia, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute) -{ - EMeetingAttendeePrivate *priv; - - g_return_val_if_fail (E_IS_MEETING_ATTENDEE (ia), FALSE); - - priv = ia->priv; - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (end_day, end_month, end_year)) - return FALSE; - if (end_hour < 0 || end_hour > 23) - return FALSE; - if (end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_clear (&priv->busy_periods_end.date, 1); - g_date_set_dmy (&priv->busy_periods_end.date, - end_day, end_month, end_year); - priv->busy_periods_end.hour = end_hour; - priv->busy_periods_end.minute = end_minute; - - priv->end_busy_range_set = TRUE; - - return TRUE; -} - -/* Clears all busy times for the given attendee. */ -void -e_meeting_attendee_clear_busy_periods (EMeetingAttendee *ia) -{ - EMeetingAttendeePrivate *priv; - - g_return_if_fail (E_IS_MEETING_ATTENDEE (ia)); - - priv = ia->priv; - - g_array_set_size (priv->busy_periods, 0); - priv->busy_periods_sorted = TRUE; - - g_date_clear (&priv->busy_periods_start.date, 1); - priv->busy_periods_start.hour = 0; - priv->busy_periods_start.minute = 0; - - g_date_clear (&priv->busy_periods_end.date, 1); - priv->busy_periods_end.hour = 0; - priv->busy_periods_end.minute = 0; - - priv->longest_period_in_days = 0; -} diff --git a/calendar/gui/e-meeting-attendee.h b/calendar/gui/e-meeting-attendee.h deleted file mode 100644 index 5ddc9968b2..0000000000 --- a/calendar/gui/e-meeting-attendee.h +++ /dev/null @@ -1,172 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-meeting_attendee.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_MEETING_ATTENDEE_H_ -#define _E_MEETING_ATTENDEE_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <cal-util/cal-component.h> -#include "e-meeting-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_MEETING_ATTENDEE (e_meeting_attendee_get_type ()) -#define E_MEETING_ATTENDEE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_MEETING_ATTENDEE, EMeetingAttendee)) -#define E_MEETING_ATTENDEE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_MEETING_ATTENDEE, EMeetingAttendeeClass)) -#define E_IS_MEETING_ATTENDEE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_MEETING_ATTENDEE)) -#define E_IS_MEETING_ATTENDEE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_MEETING_ATTENDEE)) - - -typedef struct _EMeetingAttendee EMeetingAttendee; -typedef struct _EMeetingAttendeePrivate EMeetingAttendeePrivate; -typedef struct _EMeetingAttendeeClass EMeetingAttendeeClass; - -/* These specify the type of attendee. Either a person or a resource (e.g. a - meeting room). These are used for the Autopick options, where the user can - ask for a time when, for example, all people and one resource are free. - The default is E_MEETING_ATTENDEE_REQUIRED_PERSON. */ -typedef enum -{ - E_MEETING_ATTENDEE_REQUIRED_PERSON, - E_MEETING_ATTENDEE_OPTIONAL_PERSON, - E_MEETING_ATTENDEE_RESOURCE -} EMeetingAttendeeType; - -typedef enum -{ - E_MEETING_ATTENDEE_EDIT_FULL, - E_MEETING_ATTENDEE_EDIT_STATUS, - E_MEETING_ATTENDEE_EDIT_NONE -} EMeetingAttendeeEditLevel; - -struct _EMeetingAttendee { - GtkObject parent; - - EMeetingAttendeePrivate *priv; -}; - -struct _EMeetingAttendeeClass { - GtkObjectClass parent_class; - - void (* changed) (EMeetingAttendee *ia); -}; - - -GType e_meeting_attendee_get_type (void); -GObject *e_meeting_attendee_new (void); -GObject *e_meeting_attendee_new_from_cal_component_attendee (CalComponentAttendee *ca); - -CalComponentAttendee *e_meeting_attendee_as_cal_component_attendee (EMeetingAttendee *ia); - -const gchar *e_meeting_attendee_get_address (EMeetingAttendee *ia); -void e_meeting_attendee_set_address (EMeetingAttendee *ia, gchar *address); -gboolean e_meeting_attendee_is_set_address (EMeetingAttendee *ia); - -const gchar *e_meeting_attendee_get_member (EMeetingAttendee *ia); -void e_meeting_attendee_set_member (EMeetingAttendee *ia, gchar *member); -gboolean e_meeting_attendee_is_set_member (EMeetingAttendee *ia); - -icalparameter_cutype e_meeting_attendee_get_cutype (EMeetingAttendee *ia); -void e_meeting_attendee_set_cutype (EMeetingAttendee *ia, icalparameter_cutype cutype); - -icalparameter_role e_meeting_attendee_get_role (EMeetingAttendee *ia); -void e_meeting_attendee_set_role (EMeetingAttendee *ia, icalparameter_role role); - -gboolean e_meeting_attendee_get_rsvp (EMeetingAttendee *ia); -void e_meeting_attendee_set_rsvp (EMeetingAttendee *ia, gboolean rsvp); - -const gchar *e_meeting_attendee_get_delto (EMeetingAttendee *ia); -void e_meeting_attendee_set_delto (EMeetingAttendee *ia, gchar *delto); -gboolean e_meeting_attendee_is_set_delto (EMeetingAttendee *ia); - -const gchar *e_meeting_attendee_get_delfrom (EMeetingAttendee *ia); -void e_meeting_attendee_set_delfrom (EMeetingAttendee *ia, gchar *delfrom); -gboolean e_meeting_attendee_is_set_delfrom (EMeetingAttendee *ia); - -icalparameter_partstat e_meeting_attendee_get_status (EMeetingAttendee *ia); -void e_meeting_attendee_set_status (EMeetingAttendee *ia, icalparameter_partstat status); - -const gchar *e_meeting_attendee_get_sentby (EMeetingAttendee *ia); -void e_meeting_attendee_set_sentby (EMeetingAttendee *ia, gchar *sentby); -gboolean e_meeting_attendee_is_set_sentby (EMeetingAttendee *ia); - -const gchar *e_meeting_attendee_get_cn (EMeetingAttendee *ia); -void e_meeting_attendee_set_cn (EMeetingAttendee *ia, gchar *cn); -gboolean e_meeting_attendee_is_set_cn (EMeetingAttendee *ia); - -const gchar *e_meeting_attendee_get_language (EMeetingAttendee *ia); -void e_meeting_attendee_set_language (EMeetingAttendee *ia, gchar *language); -gboolean e_meeting_attendee_is_set_language (EMeetingAttendee *ia); - -EMeetingAttendeeType e_meeting_attendee_get_atype (EMeetingAttendee *ia); - -EMeetingAttendeeEditLevel e_meeting_attendee_get_edit_level (EMeetingAttendee *ia); -void e_meeting_attendee_set_edit_level (EMeetingAttendee *ia, EMeetingAttendeeEditLevel level); - -gboolean e_meeting_attendee_get_has_calendar_info (EMeetingAttendee *ia); -void e_meeting_attendee_set_has_calendar_info (EMeetingAttendee *ia, gboolean has_calendar_info); - -const GArray *e_meeting_attendee_get_busy_periods (EMeetingAttendee *ia); -gint e_meeting_attendee_find_first_busy_period (EMeetingAttendee *ia, GDate *date); -gboolean e_meeting_attendee_add_busy_period (EMeetingAttendee *ia, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingFreeBusyType busy_type); - -EMeetingTime e_meeting_attendee_get_start_busy_range (EMeetingAttendee *ia); -EMeetingTime e_meeting_attendee_get_end_busy_range (EMeetingAttendee *ia); - -gboolean e_meeting_attendee_set_start_busy_range (EMeetingAttendee *ia, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute); -gboolean e_meeting_attendee_set_end_busy_range (EMeetingAttendee *ia, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute); - -void e_meeting_attendee_clear_busy_periods (EMeetingAttendee *ia); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_ATTENDEE_H_ */ diff --git a/calendar/gui/e-meeting-model.c b/calendar/gui/e-meeting-model.c deleted file mode 100644 index dddc1f2f25..0000000000 --- a/calendar/gui/e-meeting-model.c +++ /dev/null @@ -1,1785 +0,0 @@ -/* -*- Mod:e C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* itip-model.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-widget.h> -#include <bonobo/bonobo-exception.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomevfs/gnome-vfs.h> -#include <gal/e-table/e-table-without.h> -#include <gal/e-table/e-cell-text.h> -#include <gal/e-table/e-cell-popup.h> -#include <gal/e-table/e-cell-combo.h> -#include <ebook/e-book.h> -#include <ebook/e-book-util.h> -#include <ebook/e-card-types.h> -#include <ebook/e-card-cursor.h> -#include <ebook/e-card.h> -#include <ebook/e-card-simple.h> -#include <cal-util/cal-component.h> -#include <cal-util/cal-util.h> -#include <cal-util/timeutil.h> -#include "Evolution-Addressbook-SelectNames.h" -#include "calendar-config.h" -#include "itip-utils.h" -#include "e-meeting-utils.h" -#include "e-meeting-attendee.h" -#include "e-meeting-model.h" - -#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames" - -struct _EMeetingModelPrivate -{ - GPtrArray *attendees; - - GList *tables; - - CalClient *client; - icaltimezone *zone; - - EBook *ebook; - gboolean book_loaded; - gboolean book_load_wait; - - GPtrArray *refresh_queue; - GHashTable *refresh_data; - guint refresh_idle_id; - - /* For invite others dialogs */ - GNOME_Evolution_Addressbook_SelectNames corba_select_names; -}; - -#define BUF_SIZE 1024 - -static char *sections[] = {N_("Chair Persons"), - N_("Required Participants"), - N_("Optional Participants"), - N_("Resources"), - NULL}; -static icalparameter_role roles[] = {ICAL_ROLE_CHAIR, - ICAL_ROLE_REQPARTICIPANT, - ICAL_ROLE_OPTPARTICIPANT, - ICAL_ROLE_NONPARTICIPANT, - ICAL_ROLE_NONE}; - -typedef struct _EMeetingModelQueueData EMeetingModelQueueData; -struct _EMeetingModelQueueData { - EMeetingModel *im; - EMeetingAttendee *ia; - - gboolean refreshing; - - EMeetingTime start; - EMeetingTime end; - - char buffer[BUF_SIZE]; - GString *string; - - GPtrArray *call_backs; - GPtrArray *data; -}; - - -static void class_init (EMeetingModelClass *klass); -static void init (EMeetingModel *model); -static void finalize (GObject *obj); - -static void refresh_queue_add (EMeetingModel *im, int row, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data); -static void refresh_queue_remove (EMeetingModel *im, - EMeetingAttendee *ia); -static gboolean refresh_busy_periods (gpointer data); - -static void attendee_changed_cb (EMeetingAttendee *ia, gpointer data); -static void select_names_ok_cb (BonoboListener *listener, - const char *event_name, - const CORBA_any *arg, - CORBA_Environment *ev, - gpointer data); - -static void table_destroy_state_cb (ETableScrolled *etable, gpointer data); -static void table_destroy_list_cb (ETableScrolled *etable, gpointer data); - -static ETableModelClass *parent_class = NULL; - -E_MAKE_TYPE (e_meeting_model, "EMeetingModel", EMeetingModel, - class_init, init, E_TABLE_MODEL_TYPE); - -static void -book_open_cb (EBook *book, EBookStatus status, gpointer data) -{ - EMeetingModel *im = E_MEETING_MODEL (data); - EMeetingModelPrivate *priv; - - priv = im->priv; - - if (status == E_BOOK_STATUS_SUCCESS) - priv->book_loaded = TRUE; - else - g_warning ("Book not loaded"); - - if (priv->book_load_wait) { - priv->book_load_wait = FALSE; - gtk_main_quit (); - } -} - -static void -start_addressbook_server (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - priv->ebook = e_book_new (); - e_book_load_default_book (priv->ebook, book_open_cb, im); -} - -static EMeetingAttendee * -find_match (EMeetingModel *im, const char *address, int *pos) -{ - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - const gchar *ia_address; - int i; - - priv = im->priv; - - if (address == NULL) - return NULL; - - /* Make sure we can add the new delegatee person */ - for (i = 0; i < priv->attendees->len; i++) { - ia = g_ptr_array_index (priv->attendees, i); - - ia_address = e_meeting_attendee_get_address (ia); - if (ia_address != NULL && !g_strcasecmp (itip_strip_mailto (ia_address), itip_strip_mailto (address))) { - if (pos != NULL) - *pos = i; - return ia; - } - } - - return NULL; -} - -static icalparameter_cutype -text_to_type (const char *type) -{ - if (!g_strcasecmp (type, _("Individual"))) - return ICAL_CUTYPE_INDIVIDUAL; - else if (!g_strcasecmp (type, _("Group"))) - return ICAL_CUTYPE_GROUP; - else if (!g_strcasecmp (type, _("Resource"))) - return ICAL_CUTYPE_RESOURCE; - else if (!g_strcasecmp (type, _("Room"))) - return ICAL_CUTYPE_ROOM; - else - return ICAL_CUTYPE_NONE; -} - -static char * -type_to_text (icalparameter_cutype type) -{ - switch (type) { - case ICAL_CUTYPE_INDIVIDUAL: - return _("Individual"); - case ICAL_CUTYPE_GROUP: - return _("Group"); - case ICAL_CUTYPE_RESOURCE: - return _("Resource"); - case ICAL_CUTYPE_ROOM: - return _("Room"); - default: - return _("Unknown"); - } - - return NULL; - -} - -static icalparameter_role -text_to_role (const char *role) -{ - if (!g_strcasecmp (role, _("Chair"))) - return ICAL_ROLE_CHAIR; - else if (!g_strcasecmp (role, _("Required Participant"))) - return ICAL_ROLE_REQPARTICIPANT; - else if (!g_strcasecmp (role, _("Optional Participant"))) - return ICAL_ROLE_OPTPARTICIPANT; - else if (!g_strcasecmp (role, _("Non-Participant"))) - return ICAL_ROLE_NONPARTICIPANT; - else - return ICAL_ROLE_NONE; -} - -static char * -role_to_text (icalparameter_role role) -{ - switch (role) { - case ICAL_ROLE_CHAIR: - return _("Chair"); - case ICAL_ROLE_REQPARTICIPANT: - return _("Required Participant"); - case ICAL_ROLE_OPTPARTICIPANT: - return _("Optional Participant"); - case ICAL_ROLE_NONPARTICIPANT: - return _("Non-Participant"); - default: - return _("Unknown"); - } - - return NULL; -} - -static gboolean -text_to_boolean (const char *role) -{ - if (!g_strcasecmp (role, _("Yes"))) - return TRUE; - else - return FALSE; -} - -static char * -boolean_to_text (gboolean b) -{ - if (b) - return _("Yes"); - else - return _("No"); -} - -static icalparameter_partstat -text_to_partstat (const char *partstat) -{ - if (!g_strcasecmp (partstat, _("Needs Action"))) - return ICAL_PARTSTAT_NEEDSACTION; - else if (!g_strcasecmp (partstat, _("Accepted"))) - return ICAL_PARTSTAT_ACCEPTED; - else if (!g_strcasecmp (partstat, _("Declined"))) - return ICAL_PARTSTAT_DECLINED; - else if (!g_strcasecmp (partstat, _("Tentative"))) - return ICAL_PARTSTAT_TENTATIVE; - else if (!g_strcasecmp (partstat, _("Delegated"))) - return ICAL_PARTSTAT_DELEGATED; - else if (!g_strcasecmp (partstat, _("Completed"))) - return ICAL_PARTSTAT_COMPLETED; - else if (!g_strcasecmp (partstat, _("In Process"))) - return ICAL_PARTSTAT_INPROCESS; - else - return ICAL_PARTSTAT_NONE; -} - -static char * -partstat_to_text (icalparameter_partstat partstat) -{ - switch (partstat) { - case ICAL_PARTSTAT_NEEDSACTION: - return _("Needs Action"); - case ICAL_PARTSTAT_ACCEPTED: - return _("Accepted"); - case ICAL_PARTSTAT_DECLINED: - return _("Declined"); - case ICAL_PARTSTAT_TENTATIVE: - return _("Tentative"); - case ICAL_PARTSTAT_DELEGATED: - return _("Delegated"); - case ICAL_PARTSTAT_COMPLETED: - return _("Completed"); - case ICAL_PARTSTAT_INPROCESS: - return _("In Process"); - case ICAL_PARTSTAT_NONE: - default: - return _("Unknown"); - } - - return NULL; -} - -static int -column_count (ETableModel *etm) -{ - return E_MEETING_MODEL_COLUMN_COUNT; -} - -static int -row_count (ETableModel *etm) -{ - EMeetingModel *im; - EMeetingModelPrivate *priv; - - im = E_MEETING_MODEL (etm); - priv = im->priv; - - return (priv->attendees->len); -} - -static void -append_row (ETableModel *etm, ETableModel *source, int row) -{ - EMeetingModel *im; - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - char *address; - - im = E_MEETING_MODEL (etm); - priv = im->priv; - - address = (char *) e_table_model_value_at (source, E_MEETING_MODEL_ADDRESS_COL, row); - if (find_match (im, address, NULL) != NULL) { - return; - } - - ia = E_MEETING_ATTENDEE (e_meeting_attendee_new ()); - - e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", address)); - e_meeting_attendee_set_member (ia, g_strdup (e_table_model_value_at (source, E_MEETING_MODEL_MEMBER_COL, row))); - e_meeting_attendee_set_cutype (ia, text_to_type (e_table_model_value_at (source, E_MEETING_MODEL_TYPE_COL, row))); - e_meeting_attendee_set_role (ia, text_to_role (e_table_model_value_at (source, E_MEETING_MODEL_ROLE_COL, row))); - e_meeting_attendee_set_rsvp (ia, text_to_boolean (e_table_model_value_at (source, E_MEETING_MODEL_RSVP_COL, row))); - e_meeting_attendee_set_delto (ia, g_strdup (e_table_model_value_at (source, E_MEETING_MODEL_DELTO_COL, row))); - e_meeting_attendee_set_delfrom (ia, g_strdup (e_table_model_value_at (source, E_MEETING_MODEL_DELFROM_COL, row))); - e_meeting_attendee_set_status (ia, text_to_partstat (e_table_model_value_at (source, E_MEETING_MODEL_STATUS_COL, row))); - e_meeting_attendee_set_cn (ia, g_strdup (e_table_model_value_at (source, E_MEETING_MODEL_CN_COL, row))); - e_meeting_attendee_set_language (ia, g_strdup (e_table_model_value_at (source, E_MEETING_MODEL_LANGUAGE_COL, row))); - - e_meeting_model_add_attendee (E_MEETING_MODEL (etm), ia); - g_object_unref (ia); -} - -static void * -value_at (ETableModel *etm, int col, int row) -{ - EMeetingModel *im; - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - - im = E_MEETING_MODEL (etm); - priv = im->priv; - - ia = g_ptr_array_index (priv->attendees, row); - - switch (col) { - case E_MEETING_MODEL_ADDRESS_COL: - return (void *)itip_strip_mailto (e_meeting_attendee_get_address (ia)); - case E_MEETING_MODEL_MEMBER_COL: - return (void *)e_meeting_attendee_get_member (ia); - case E_MEETING_MODEL_TYPE_COL: - return type_to_text (e_meeting_attendee_get_cutype (ia)); - case E_MEETING_MODEL_ROLE_COL: - return role_to_text (e_meeting_attendee_get_role (ia)); - case E_MEETING_MODEL_RSVP_COL: - return boolean_to_text (e_meeting_attendee_get_rsvp (ia)); - case E_MEETING_MODEL_DELTO_COL: - return (void *)itip_strip_mailto (e_meeting_attendee_get_delto (ia)); - case E_MEETING_MODEL_DELFROM_COL: - return (void *)itip_strip_mailto (e_meeting_attendee_get_delfrom (ia)); - case E_MEETING_MODEL_STATUS_COL: - return partstat_to_text (e_meeting_attendee_get_status (ia)); - case E_MEETING_MODEL_CN_COL: - return (void *)e_meeting_attendee_get_cn (ia); - case E_MEETING_MODEL_LANGUAGE_COL: - return (void *)e_meeting_attendee_get_language (ia); - } - - return NULL; -} - -static void -set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - EMeetingModel *im; - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - icalparameter_cutype type; - - im = E_MEETING_MODEL (etm); - priv = im->priv; - - ia = g_ptr_array_index (priv->attendees, row); - - e_table_model_pre_change (etm); - - switch (col) { - case E_MEETING_MODEL_ADDRESS_COL: - if (val != NULL && *((char *)val)) - e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", (char *) val)); - break; - case E_MEETING_MODEL_MEMBER_COL: - e_meeting_attendee_set_member (ia, g_strdup (val)); - break; - case E_MEETING_MODEL_TYPE_COL: - type = text_to_type (val); - e_meeting_attendee_set_cutype (ia, text_to_type (val)); - if (type == ICAL_CUTYPE_RESOURCE) { - e_meeting_attendee_set_role (ia, ICAL_ROLE_NONPARTICIPANT); - e_table_model_cell_changed (etm, E_MEETING_MODEL_ROLE_COL, row); - } - break; - case E_MEETING_MODEL_ROLE_COL: - e_meeting_attendee_set_role (ia, text_to_role (val)); - break; - case E_MEETING_MODEL_RSVP_COL: - e_meeting_attendee_set_rsvp (ia, text_to_boolean (val)); - break; - case E_MEETING_MODEL_DELTO_COL: - e_meeting_attendee_set_delto (ia, g_strdup (val)); - break; - case E_MEETING_MODEL_DELFROM_COL: - e_meeting_attendee_set_delfrom (ia, g_strdup (val)); - break; - case E_MEETING_MODEL_STATUS_COL: - e_meeting_attendee_set_status (ia, text_to_partstat (val)); - break; - case E_MEETING_MODEL_CN_COL: - e_meeting_attendee_set_cn (ia, g_strdup (val)); - break; - case E_MEETING_MODEL_LANGUAGE_COL: - e_meeting_attendee_set_language (ia, g_strdup (val)); - break; - } - - e_table_model_cell_changed (etm, col, row); -} - -static gboolean -is_cell_editable (ETableModel *etm, int col, int row) -{ - EMeetingModel *im; - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - EMeetingAttendeeEditLevel level; - - im = E_MEETING_MODEL (etm); - priv = im->priv; - - if (col == E_MEETING_MODEL_DELTO_COL - || col == E_MEETING_MODEL_DELFROM_COL) - return FALSE; - - if (row == -1) - return TRUE; - if (row >= priv->attendees->len) - return TRUE; - - ia = g_ptr_array_index (priv->attendees, row); - level = e_meeting_attendee_get_edit_level (ia); - - switch (level) { - case E_MEETING_ATTENDEE_EDIT_FULL: - return TRUE; - case E_MEETING_ATTENDEE_EDIT_STATUS: - return col == E_MEETING_MODEL_STATUS_COL; - case E_MEETING_ATTENDEE_EDIT_NONE: - return FALSE; - } - - return TRUE; -} - -static void * -duplicate_value (ETableModel *etm, int col, const void *val) -{ - return g_strdup (val); -} - -static void -free_value (ETableModel *etm, int col, void *val) -{ - g_free (val); -} - -static void * -init_value (ETableModel *etm, int col) -{ - switch (col) { - case E_MEETING_MODEL_ADDRESS_COL: - return g_strdup (""); - case E_MEETING_MODEL_MEMBER_COL: - return g_strdup (""); - case E_MEETING_MODEL_TYPE_COL: - return g_strdup (_("Individual")); - case E_MEETING_MODEL_ROLE_COL: - return g_strdup (_("Required Participant")); - case E_MEETING_MODEL_RSVP_COL: - return g_strdup (_("Yes")); - case E_MEETING_MODEL_DELTO_COL: - return g_strdup (""); - case E_MEETING_MODEL_DELFROM_COL: - return g_strdup (""); - case E_MEETING_MODEL_STATUS_COL: - return g_strdup (_("Needs Action")); - case E_MEETING_MODEL_CN_COL: - return g_strdup (""); - case E_MEETING_MODEL_LANGUAGE_COL: - return g_strdup ("en"); - } - - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etm, int col, const void *val) -{ - - switch (col) { - case E_MEETING_MODEL_ADDRESS_COL: - case E_MEETING_MODEL_MEMBER_COL: - case E_MEETING_MODEL_DELTO_COL: - case E_MEETING_MODEL_DELFROM_COL: - case E_MEETING_MODEL_CN_COL: - if (val && !g_strcasecmp (val, "")) - return TRUE; - else - return FALSE; - default: - ; - } - - return TRUE; -} - -static char * -value_to_string (ETableModel *etm, int col, const void *val) -{ - return g_strdup (val); -} - -static void -class_init (EMeetingModelClass *klass) -{ - GObjectClass *gobject_class; - ETableModelClass *etm_class; - - gobject_class = G_OBJECT_CLASS (klass); - etm_class = E_TABLE_MODEL_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - gobject_class->finalize = finalize; - - etm_class->column_count = column_count; - etm_class->row_count = row_count; - etm_class->value_at = value_at; - etm_class->set_value_at = set_value_at; - etm_class->is_cell_editable = is_cell_editable; - etm_class->append_row = append_row; - etm_class->duplicate_value = duplicate_value; - etm_class->free_value = free_value; - etm_class->initialize_value = init_value; - etm_class->value_is_empty = value_is_empty; - etm_class->value_to_string = value_to_string; -} - - -static void -init (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - priv = g_new0 (EMeetingModelPrivate, 1); - - im->priv = priv; - - priv->attendees = g_ptr_array_new (); - - priv->tables = NULL; - - priv->client = NULL; - priv->zone = icaltimezone_get_builtin_timezone (calendar_config_get_timezone ()); - - priv->ebook = NULL; - priv->book_loaded = FALSE; - priv->book_load_wait = FALSE; - - priv->refresh_queue = g_ptr_array_new (); - priv->refresh_data = g_hash_table_new (g_direct_hash, g_direct_equal); - priv->refresh_idle_id = 0; - - priv->corba_select_names = CORBA_OBJECT_NIL; - - start_addressbook_server (im); -} - -static void -finalize (GObject *obj) -{ - EMeetingModel *im = E_MEETING_MODEL (obj); - EMeetingModelPrivate *priv; - GList *l; - int i; - - priv = im->priv; - - for (i = 0; i < priv->attendees->len; i++) - g_object_unref (g_ptr_array_index (priv->attendees, i)); - g_ptr_array_free (priv->attendees, TRUE); - - for (l = priv->tables; l != NULL; l = l->next) - g_signal_handlers_disconnect_matched (G_OBJECT (l->data), G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, im); - g_list_free (priv->tables); - - if (priv->client != NULL) - g_object_unref (priv->client); - - if (priv->ebook != NULL) - g_object_unref (priv->ebook); - - if (priv->corba_select_names != CORBA_OBJECT_NIL) { - CORBA_Environment ev; - CORBA_exception_init (&ev); - bonobo_object_release_unref (priv->corba_select_names, &ev); - CORBA_exception_free (&ev); - } - - while (priv->refresh_queue->len > 0) - refresh_queue_remove (im, g_ptr_array_index (priv->refresh_queue, 0)); - g_ptr_array_free (priv->refresh_queue, TRUE); - g_hash_table_destroy (priv->refresh_data); - - if (priv->refresh_idle_id) - g_source_remove (priv->refresh_idle_id); - - g_free (priv); -} - -GtkObject * -e_meeting_model_new (void) -{ - return g_object_new (E_TYPE_MEETING_MODEL, NULL); -} - - -CalClient * -e_meeting_model_get_cal_client (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - return priv->client; -} - -void -e_meeting_model_set_cal_client (EMeetingModel *im, CalClient *client) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - if (priv->client != NULL) - g_object_unref (priv->client); - - if (client != NULL) - g_object_ref (client); - priv->client = client; -} - -icaltimezone * -e_meeting_model_get_zone (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - g_return_val_if_fail (im != NULL, NULL); - g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL); - - priv = im->priv; - - return priv->zone; -} - -void -e_meeting_model_set_zone (EMeetingModel *im, icaltimezone *zone) -{ - EMeetingModelPrivate *priv; - - g_return_if_fail (im != NULL); - g_return_if_fail (E_IS_MEETING_MODEL (im)); - - priv = im->priv; - - priv->zone = zone; -} - -static ETableScrolled * -build_etable (ETableModel *model, const gchar *spec_file, const gchar *state_file) -{ - GtkWidget *etable; - ETable *real_table; - ETableExtras *extras; - GList *strings; - ECell *popup_cell, *cell; - - extras = e_table_extras_new (); - - /* For type */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Individual")); - strings = g_list_append (strings, (char*) _("Group")); - strings = g_list_append (strings, (char*) _("Resource")); - strings = g_list_append (strings, (char*) _("Room")); - strings = g_list_append (strings, (char*) _("Unknown")); - - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings); - e_table_extras_add_cell (extras, "typeedit", popup_cell); - - /* For role */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Chair")); - strings = g_list_append (strings, (char*) _("Required Participant")); - strings = g_list_append (strings, (char*) _("Optional Participant")); - strings = g_list_append (strings, (char*) _("Non-Participant")); - strings = g_list_append (strings, (char*) _("Unknown")); - - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings); - e_table_extras_add_cell (extras, "roleedit", popup_cell); - - /* For rsvp */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Yes")); - strings = g_list_append (strings, (char*) _("No")); - - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings); - e_table_extras_add_cell (extras, "rsvpedit", popup_cell); - - /* For status */ - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - popup_cell = e_cell_combo_new (); - e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); - g_object_unref (cell); - - strings = NULL; - strings = g_list_append (strings, (char*) _("Needs Action")); - strings = g_list_append (strings, (char*) _("Accepted")); - strings = g_list_append (strings, (char*) _("Declined")); - strings = g_list_append (strings, (char*) _("Tentative")); - strings = g_list_append (strings, (char*) _("Delegated")); - - e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings); - e_table_extras_add_cell (extras, "statusedit", popup_cell); - - etable = e_table_scrolled_new_from_spec_file (model, extras, spec_file, NULL); - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (etable)); - g_object_set (G_OBJECT (real_table), "uniform_row_height", TRUE, NULL); - e_table_load_state (real_table, state_file); - -#if 0 - g_signal_connect (real_table, "right_click", G_CALLBACK (right_click_cb), mpage); -#endif - - g_signal_connect (etable, "destroy", G_CALLBACK (table_destroy_state_cb), g_strdup (state_file)); - - g_object_unref (extras); - - return E_TABLE_SCROLLED (etable); -} - -void -e_meeting_model_add_attendee (EMeetingModel *im, EMeetingAttendee *ia) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - e_table_model_pre_change (E_TABLE_MODEL (im)); - - g_object_ref (ia); - g_ptr_array_add (priv->attendees, ia); - - g_signal_connect (ia, "changed", G_CALLBACK (attendee_changed_cb), im); - - e_table_model_row_inserted (E_TABLE_MODEL (im), row_count (E_TABLE_MODEL (im)) - 1); -} - -EMeetingAttendee * -e_meeting_model_add_attendee_with_defaults (EMeetingModel *im) -{ - EMeetingAttendee *ia; - char *str; - - ia = E_MEETING_ATTENDEE (e_meeting_attendee_new ()); - - e_meeting_attendee_set_address (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_ADDRESS_COL)); - e_meeting_attendee_set_member (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_MEMBER_COL)); - - str = init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_TYPE_COL); - e_meeting_attendee_set_cutype (ia, text_to_type (str)); - g_free (str); - str = init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_ROLE_COL); - e_meeting_attendee_set_role (ia, text_to_role (str)); - g_free (str); - str = init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_RSVP_COL); - e_meeting_attendee_set_rsvp (ia, text_to_boolean (str)); - g_free (str); - - e_meeting_attendee_set_delto (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_DELTO_COL)); - e_meeting_attendee_set_delfrom (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_DELFROM_COL)); - - str = init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_STATUS_COL); - e_meeting_attendee_set_status (ia, text_to_partstat (str)); - g_free (str); - - e_meeting_attendee_set_cn (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_CN_COL)); - e_meeting_attendee_set_language (ia, init_value (E_TABLE_MODEL (im), E_MEETING_MODEL_LANGUAGE_COL)); - - e_meeting_model_add_attendee (im, ia); - - return ia; -} - -void -e_meeting_model_remove_attendee (EMeetingModel *im, EMeetingAttendee *ia) -{ - EMeetingModelPrivate *priv; - gint i, row = -1; - - priv = im->priv; - - for (i = 0; i < priv->attendees->len; i++) { - if (ia == g_ptr_array_index (priv->attendees, i)) { - row = i; - break; - } - } - - if (row != -1) { - e_table_model_pre_change (E_TABLE_MODEL (im)); - - g_ptr_array_remove_index (priv->attendees, row); - g_object_unref (ia); - - e_table_model_row_deleted (E_TABLE_MODEL (im), row); - } -} - -void -e_meeting_model_remove_all_attendees (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - gint i, len; - - priv = im->priv; - - e_table_model_pre_change (E_TABLE_MODEL (im)); - - len = priv->attendees->len; - - for (i = 0; i < len; i++) { - EMeetingAttendee *ia = g_ptr_array_index (priv->attendees, i); - g_object_unref (ia); - } - g_ptr_array_set_size (priv->attendees, 0); - - e_table_model_rows_deleted (E_TABLE_MODEL (im), 0, len); -} - -EMeetingAttendee * -e_meeting_model_find_attendee (EMeetingModel *im, const gchar *address, gint *row) -{ - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - int i; - - priv = im->priv; - - if (address == NULL) - return NULL; - - for (i = 0; i < priv->attendees->len; i++) { - const gchar *ia_address; - - ia = g_ptr_array_index (priv->attendees, i); - - ia_address = e_meeting_attendee_get_address (ia); - if (ia_address && !g_strcasecmp (itip_strip_mailto (ia_address), itip_strip_mailto (address))) { - if (row != NULL) - *row = i; - - return ia; - } - } - - return NULL; -} - -EMeetingAttendee * -e_meeting_model_find_attendee_at_row (EMeetingModel *im, gint row) -{ - EMeetingModelPrivate *priv; - - g_return_val_if_fail (im != NULL, NULL); - g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL); - g_return_val_if_fail (row >= 0, NULL); - - priv = im->priv; - g_return_val_if_fail (row < priv->attendees->len, NULL); - - return g_ptr_array_index (priv->attendees, row); -} - -gint -e_meeting_model_count_actual_attendees (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - return e_table_model_row_count (E_TABLE_MODEL (im)); -} - -const GPtrArray * -e_meeting_model_get_attendees (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - - priv = im->priv; - - return priv->attendees; -} - -static icaltimezone * -find_zone (icalproperty *ip, icalcomponent *tz_top_level) -{ - icalparameter *param; - icalcomponent *sub_comp; - const char *tzid; - icalcompiter iter; - - if (tz_top_level == NULL) - return NULL; - - param = icalproperty_get_first_parameter (ip, ICAL_TZID_PARAMETER); - if (param == NULL) - return NULL; - tzid = icalparameter_get_tzid (param); - - iter = icalcomponent_begin_component (tz_top_level, ICAL_VTIMEZONE_COMPONENT); - while ((sub_comp = icalcompiter_deref (&iter)) != NULL) { - icalcomponent *clone; - const char *tz_tzid; - - tz_tzid = icalproperty_get_tzid (sub_comp); - if (!strcmp (tzid, tz_tzid)) { - icaltimezone *zone; - - zone = icaltimezone_new (); - clone = icalcomponent_new_clone (sub_comp); - icaltimezone_set_component (zone, clone); - - return zone; - } - - icalcompiter_next (&iter); - } - - return NULL; -} - - -static void -refresh_queue_add (EMeetingModel *im, int row, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data) -{ - EMeetingModelPrivate *priv; - EMeetingAttendee *ia; - EMeetingModelQueueData *qdata; - - priv = im->priv; - - ia = g_ptr_array_index (priv->attendees, row); - if (ia == NULL) - return; - - qdata = g_hash_table_lookup (priv->refresh_data, ia); - if (qdata == NULL) { - qdata = g_new0 (EMeetingModelQueueData, 1); - - qdata->im = im; - qdata->ia = ia; - e_meeting_attendee_clear_busy_periods (ia); - e_meeting_attendee_set_has_calendar_info (ia, FALSE); - - qdata->start = *start; - qdata->end = *end; - qdata->string = g_string_new (NULL); - qdata->call_backs = g_ptr_array_new (); - qdata->data = g_ptr_array_new (); - g_ptr_array_add (qdata->call_backs, call_back); - g_ptr_array_add (qdata->data, data); - - g_hash_table_insert (priv->refresh_data, ia, qdata); - } else { - if (e_meeting_time_compare_times (start, &qdata->start) == -1) - qdata->start = *start; - if (e_meeting_time_compare_times (end, &qdata->end) == 1) - qdata->end = *end; - g_ptr_array_add (qdata->call_backs, call_back); - g_ptr_array_add (qdata->data, data); - } - - g_object_ref (ia); - g_ptr_array_add (priv->refresh_queue, ia); - - if (priv->refresh_idle_id == 0) - priv->refresh_idle_id = g_idle_add (refresh_busy_periods, im); -} - -static void -refresh_queue_remove (EMeetingModel *im, EMeetingAttendee *ia) -{ - EMeetingModelPrivate *priv; - EMeetingModelQueueData *qdata; - - priv = im->priv; - - /* Free the queue data */ - qdata = g_hash_table_lookup (priv->refresh_data, ia); - g_assert (qdata != NULL); - - g_hash_table_remove (priv->refresh_data, ia); - g_ptr_array_free (qdata->call_backs, TRUE); - g_ptr_array_free (qdata->data, TRUE); - g_free (qdata); - - /* Unref the attendee */ - g_ptr_array_remove (priv->refresh_queue, ia); - g_object_unref (ia); -} - -static void -process_callbacks (EMeetingModelQueueData *qdata) -{ - EMeetingModel *im; - int i; - - for (i = 0; i < qdata->call_backs->len; i++) { - EMeetingModelRefreshCallback call_back; - gpointer *data; - - call_back = g_ptr_array_index (qdata->call_backs, i); - data = g_ptr_array_index (qdata->data, i); - - call_back (data); - } - - im = qdata->im; - refresh_queue_remove (qdata->im, qdata->ia); - g_object_unref (im); -} - -static void -process_free_busy_comp (EMeetingAttendee *ia, - icalcomponent *fb_comp, - icaltimezone *zone, - icalcomponent *tz_top_level) -{ - icalproperty *ip; - - ip = icalcomponent_get_first_property (fb_comp, ICAL_DTSTART_PROPERTY); - if (ip != NULL) { - struct icaltimetype dtstart; - icaltimezone *ds_zone; - - dtstart = icalproperty_get_dtstart (ip); - if (!dtstart.is_utc) - ds_zone = find_zone (ip, tz_top_level); - else - ds_zone = icaltimezone_get_utc_timezone (); - icaltimezone_convert_time (&dtstart, ds_zone, zone); - e_meeting_attendee_set_start_busy_range (ia, - dtstart.year, - dtstart.month, - dtstart.day, - dtstart.hour, - dtstart.minute); - } - - ip = icalcomponent_get_first_property (fb_comp, ICAL_DTEND_PROPERTY); - if (ip != NULL) { - struct icaltimetype dtend; - icaltimezone *de_zone; - - dtend = icalproperty_get_dtend (ip); - if (!dtend.is_utc) - de_zone = find_zone (ip, tz_top_level); - else - de_zone = icaltimezone_get_utc_timezone (); - icaltimezone_convert_time (&dtend, de_zone, zone); - e_meeting_attendee_set_end_busy_range (ia, - dtend.year, - dtend.month, - dtend.day, - dtend.hour, - dtend.minute); - } - - ip = icalcomponent_get_first_property (fb_comp, ICAL_FREEBUSY_PROPERTY); - while (ip != NULL) { - icalparameter *param; - struct icalperiodtype fb; - EMeetingFreeBusyType busy_type = E_MEETING_FREE_BUSY_LAST; - icalparameter_fbtype fbtype = ICAL_FBTYPE_BUSY; - - fb = icalproperty_get_freebusy (ip); - param = icalproperty_get_first_parameter (ip, ICAL_FBTYPE_PARAMETER); - if (param != NULL) - fbtype = icalparameter_get_fbtype (param); - - switch (fbtype) { - case ICAL_FBTYPE_BUSY: - busy_type = E_MEETING_FREE_BUSY_BUSY; - break; - - case ICAL_FBTYPE_BUSYUNAVAILABLE: - busy_type = E_MEETING_FREE_BUSY_OUT_OF_OFFICE; - break; - - case ICAL_FBTYPE_BUSYTENTATIVE: - busy_type = E_MEETING_FREE_BUSY_TENTATIVE; - break; - - default: - break; - } - - if (busy_type != E_MEETING_FREE_BUSY_LAST) { - icaltimezone *utc_zone = icaltimezone_get_utc_timezone (); - - icaltimezone_convert_time (&fb.start, utc_zone, zone); - icaltimezone_convert_time (&fb.end, utc_zone, zone); - e_meeting_attendee_add_busy_period (ia, - fb.start.year, - fb.start.month, - fb.start.day, - fb.start.hour, - fb.start.minute, - fb.end.year, - fb.end.month, - fb.end.day, - fb.end.hour, - fb.end.minute, - busy_type); - } - - ip = icalcomponent_get_next_property (fb_comp, ICAL_FREEBUSY_PROPERTY); - } -} - -static void -process_free_busy (EMeetingModelQueueData *qdata, char *text) -{ - EMeetingModel *im = qdata->im; - EMeetingModelPrivate *priv; - EMeetingAttendee *ia = qdata->ia; - icalcomponent *main_comp; - icalcomponent_kind kind = ICAL_NO_COMPONENT; - - priv = im->priv; - - main_comp = icalparser_parse_string (text); - if (main_comp == NULL) { - process_callbacks (qdata); - return; - } - - kind = icalcomponent_isa (main_comp); - if (kind == ICAL_VCALENDAR_COMPONENT) { - icalcompiter iter; - icalcomponent *tz_top_level, *sub_comp; - - tz_top_level = cal_util_new_top_level (); - - iter = icalcomponent_begin_component (main_comp, ICAL_VTIMEZONE_COMPONENT); - while ((sub_comp = icalcompiter_deref (&iter)) != NULL) { - icalcomponent *clone; - - clone = icalcomponent_new_clone (sub_comp); - icalcomponent_add_component (tz_top_level, clone); - - icalcompiter_next (&iter); - } - - iter = icalcomponent_begin_component (main_comp, ICAL_VFREEBUSY_COMPONENT); - while ((sub_comp = icalcompiter_deref (&iter)) != NULL) { - process_free_busy_comp (ia, sub_comp, priv->zone, tz_top_level); - - icalcompiter_next (&iter); - } - icalcomponent_free (tz_top_level); - } else if (kind == ICAL_VFREEBUSY_COMPONENT) { - process_free_busy_comp (ia, main_comp, priv->zone, NULL); - } - - icalcomponent_free (main_comp); - - process_callbacks (qdata); -} - -static void -async_close (GnomeVFSAsyncHandle *handle, - GnomeVFSResult result, - gpointer data) -{ - EMeetingModelQueueData *qdata = data; - - process_free_busy (qdata, qdata->string->str); -} - -static void -async_read (GnomeVFSAsyncHandle *handle, - GnomeVFSResult result, - gpointer buffer, - GnomeVFSFileSize requested, - GnomeVFSFileSize read, - gpointer data) -{ - EMeetingModelQueueData *qdata = data; - GnomeVFSFileSize buf_size = BUF_SIZE - 1; - - if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) { - gnome_vfs_async_close (handle, async_close, qdata); - return; - } - - ((char *)buffer)[read] = '\0'; - qdata->string = g_string_append (qdata->string, buffer); - - if (result == GNOME_VFS_ERROR_EOF) { - gnome_vfs_async_close (handle, async_close, qdata); - return; - } - - gnome_vfs_async_read (handle, qdata->buffer, buf_size, async_read, qdata); -} - -static void -async_open (GnomeVFSAsyncHandle *handle, - GnomeVFSResult result, - gpointer data) -{ - EMeetingModelQueueData *qdata = data; - GnomeVFSFileSize buf_size = BUF_SIZE - 1; - - if (result != GNOME_VFS_OK) { - gnome_vfs_async_close (handle, async_close, qdata); - return; - } - - gnome_vfs_async_read (handle, qdata->buffer, buf_size, async_read, qdata); -} - -static void -cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer data) -{ - EMeetingModelQueueData *qdata = data; - int length, i; - - if (status != E_BOOK_STATUS_SUCCESS) - return; - - length = e_card_cursor_get_length (cursor); - for (i = 0; i < length; i ++) { - GnomeVFSAsyncHandle *handle; - ECard *card = e_card_cursor_get_nth (cursor, i); - const char *addr; - - if (card->fburl == NULL) - continue; - - addr = itip_strip_mailto (e_meeting_attendee_get_address (qdata->ia)); - if (!e_card_email_match_string (card, addr)) - continue; - - /* Read in free/busy data from the url */ - gnome_vfs_async_open (&handle, card->fburl, GNOME_VFS_OPEN_READ, - GNOME_VFS_PRIORITY_DEFAULT, async_open, qdata); - return; - } - - process_callbacks (qdata); -} - -static gboolean -refresh_busy_periods (gpointer data) -{ - EMeetingModel *im = E_MEETING_MODEL (data); - EMeetingModelPrivate *priv; - EMeetingAttendee *ia = NULL; - EMeetingModelQueueData *qdata = NULL; - char *query; - int i; - - priv = im->priv; - - /* Check to see if there are any remaining attendees in the queue */ - for (i = 0; i < priv->refresh_queue->len; i++) { - ia = g_ptr_array_index (priv->refresh_queue, i); - g_assert (ia != NULL); - - qdata = g_hash_table_lookup (priv->refresh_data, ia); - g_assert (qdata != NULL); - - if (!qdata->refreshing) - break; - } - - /* The everything in the queue is being refreshed */ - if (i >= priv->refresh_queue->len) { - priv->refresh_idle_id = 0; - return FALSE; - } - - /* Indicate we are trying to refresh it */ - qdata->refreshing = TRUE; - - /* We take a ref in case we get destroyed in the gui during a callback */ - g_object_ref (qdata->im); - - /* Check the server for free busy data */ - if (priv->client) { - GList *fb_data, *users = NULL; - struct icaltimetype itt; - time_t startt, endt; - const char *user; - - itt = icaltime_null_time (); - itt.year = g_date_year (&qdata->start.date); - itt.month = g_date_month (&qdata->start.date); - itt.day = g_date_day (&qdata->start.date); - itt.hour = qdata->start.hour; - itt.minute = qdata->start.minute; - startt = icaltime_as_timet_with_zone (itt, priv->zone); - - itt = icaltime_null_time (); - itt.year = g_date_year (&qdata->end.date); - itt.month = g_date_month (&qdata->end.date); - itt.day = g_date_day (&qdata->end.date); - itt.hour = qdata->end.hour; - itt.minute = qdata->end.minute; - endt = icaltime_as_timet_with_zone (itt, priv->zone); - - user = itip_strip_mailto (e_meeting_attendee_get_address (ia)); - users = g_list_append (users, g_strdup (user)); - fb_data = cal_client_get_free_busy (priv->client, users, startt, endt); - - g_list_foreach (users, (GFunc)g_free, NULL); - g_list_free (users); - - if (fb_data != NULL) { - CalComponent *comp = fb_data->data; - char *comp_str; - - comp_str = cal_component_get_as_string (comp); - process_free_busy (qdata, comp_str); - g_free (comp_str); - return TRUE; - } - } - - /* Look for fburl's of attendee with no free busy info on server */ - if (!priv->book_loaded) { - priv->book_load_wait = TRUE; - gtk_main (); - } - - if (!e_meeting_attendee_is_set_address (ia)) { - process_callbacks (qdata); - return TRUE; - } - - query = g_strdup_printf ("(contains \"email\" \"%s\")", - itip_strip_mailto (e_meeting_attendee_get_address (ia))); - if (!e_book_get_cursor (priv->ebook, query, cursor_cb, qdata)) - process_callbacks (qdata); - g_free (query); - - return TRUE; -} - -void -e_meeting_model_refresh_all_busy_periods (EMeetingModel *im, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data) -{ - EMeetingModelPrivate *priv; - int i; - - g_return_if_fail (im != NULL); - g_return_if_fail (E_IS_MEETING_MODEL (im)); - - priv = im->priv; - - for (i = 0; i < priv->attendees->len; i++) - refresh_queue_add (im, i, start, end, call_back, data); -} - -void -e_meeting_model_refresh_busy_periods (EMeetingModel *im, - int row, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data) -{ - EMeetingModelPrivate *priv; - - g_return_if_fail (im != NULL); - g_return_if_fail (E_IS_MEETING_MODEL (im)); - - priv = im->priv; - - refresh_queue_add (im, row, start, end, call_back, data); -} - -ETableScrolled * -e_meeting_model_etable_from_model (EMeetingModel *im, const gchar *spec_file, const gchar *state_file) -{ - EMeetingModelPrivate *priv; - ETableScrolled *ets; - - g_return_val_if_fail (im != NULL, NULL); - g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL); - - priv = im->priv; - - ets = build_etable (E_TABLE_MODEL (im), spec_file, state_file); - - priv->tables = g_list_prepend (priv->tables, ets); - - g_signal_connect (ets, "destroy", G_CALLBACK (table_destroy_list_cb), im); - - return ets; -} - -void -e_meeting_model_etable_click_to_add (EMeetingModel *im, gboolean click_to_add) -{ - EMeetingModelPrivate *priv; - GList *l; - - g_return_if_fail (im != NULL); - g_return_if_fail (E_IS_MEETING_MODEL (im)); - - priv = im->priv; - - for (l = priv->tables; l != NULL; l = l->next) { - ETableScrolled *ets; - ETable *real_table; - - ets = l->data; - real_table = e_table_scrolled_get_table (ets); - - g_object_set (G_OBJECT (real_table), "use_click_to_add", click_to_add, NULL); - } -} - -int -e_meeting_model_etable_model_to_view_row (ETable *et, EMeetingModel *im, int model_row) -{ - EMeetingModelPrivate *priv; - - g_return_val_if_fail (im != NULL, -1); - g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1); - - priv = im->priv; - - return e_table_model_to_view_row (et, model_row); -} - -int -e_meeting_model_etable_view_to_model_row (ETable *et, EMeetingModel *im, int view_row) -{ - EMeetingModelPrivate *priv; - - g_return_val_if_fail (im != NULL, -1); - g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1); - - priv = im->priv; - - return e_table_view_to_model_row (et, view_row); -} - - -static void -add_section (GNOME_Evolution_Addressbook_SelectNames corba_select_names, const char *name) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_SelectNames_addSection (corba_select_names, - name, - gettext (name), - &ev); - - CORBA_exception_free (&ev); -} - -static gboolean -get_select_name_dialog (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - CORBA_Environment ev; - int i; - - priv = im->priv; - - if (priv->corba_select_names != CORBA_OBJECT_NIL) { - Bonobo_Control corba_control; - GtkWidget *control_widget; - int i; - - CORBA_exception_init (&ev); - for (i = 0; sections[i] != NULL; i++) { - corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection - (priv->corba_select_names, sections[i], &ev); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return FALSE; - } - - control_widget = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL); - - bonobo_widget_set_property (BONOBO_WIDGET (control_widget), "text", TC_CORBA_string, "", NULL); - } - CORBA_exception_free (&ev); - - return TRUE; - } - - CORBA_exception_init (&ev); - - priv->corba_select_names = bonobo_activation_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev); - - for (i = 0; sections[i] != NULL; i++) - add_section (priv->corba_select_names, sections[i]); - - bonobo_event_source_client_add_listener (priv->corba_select_names, - (BonoboListenerCallbackFn) select_names_ok_cb, - "GNOME/Evolution:ok:dialog", - NULL, im); - - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return FALSE; - } - - CORBA_exception_free (&ev); - - return TRUE; -} - -void -e_meeting_model_invite_others_dialog (EMeetingModel *im) -{ - EMeetingModelPrivate *priv; - CORBA_Environment ev; - - priv = im->priv; - - if (!get_select_name_dialog (im)) - return; - - CORBA_exception_init (&ev); - - GNOME_Evolution_Addressbook_SelectNames_activateDialog ( - priv->corba_select_names, _("Required Participants"), &ev); - - CORBA_exception_free (&ev); -} - -static void -process_section (EMeetingModel *im, GNOME_Evolution_Addressbook_SimpleCardList *cards, icalparameter_role role) -{ - EMeetingModelPrivate *priv; - int i; - - priv = im->priv; - for (i = 0; i < cards->_length; i++) { - EMeetingAttendee *ia; - const char *name, *attendee = NULL, *attr; - GNOME_Evolution_Addressbook_SimpleCard card; - CORBA_Environment ev; - - card = cards->_buffer[i]; - - CORBA_exception_init (&ev); - - /* Get the CN */ - name = GNOME_Evolution_Addressbook_SimpleCard_get (card, GNOME_Evolution_Addressbook_SimpleCard_FullName, &ev); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - continue; - } - - /* Get the field as attendee from the backend */ - attr = cal_client_get_ldap_attribute (priv->client); - if (attr) { - /* FIXME this should be more general */ - if (!strcmp (attr, "icscalendar")) - attendee = GNOME_Evolution_Addressbook_SimpleCard_get (card, GNOME_Evolution_Addressbook_SimpleCard_Icscalendar, &ev); - } - - CORBA_exception_init (&ev); - - /* If we couldn't get the attendee prior, get the email address as the default */ - if (attendee == NULL || *attendee == '\0') { - attendee = GNOME_Evolution_Addressbook_SimpleCard_get (card, GNOME_Evolution_Addressbook_SimpleCard_Email, &ev); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - continue; - } - } - - CORBA_exception_free (&ev); - - if (attendee == NULL || *attendee == '\0') - continue; - - if (e_meeting_model_find_attendee (im, attendee, NULL) == NULL) { - ia = e_meeting_model_add_attendee_with_defaults (im); - - e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", attendee)); - e_meeting_attendee_set_role (ia, role); - if (role == ICAL_ROLE_NONPARTICIPANT) - e_meeting_attendee_set_cutype (ia, ICAL_CUTYPE_RESOURCE); - e_meeting_attendee_set_cn (ia, g_strdup (name)); - } - } -} - -static void -select_names_ok_cb (BonoboListener *listener, - const char *event_name, - const CORBA_any *arg, - CORBA_Environment *ev, - gpointer data) -{ - EMeetingModel *im = data; - EMeetingModelPrivate *priv; - Bonobo_Control corba_control; - GtkWidget *control_widget; - BonoboControlFrame *control_frame; - Bonobo_PropertyBag pb; - BonoboArg *card_arg; - GNOME_Evolution_Addressbook_SimpleCardList cards; - int i; - - priv = im->priv; - - for (i = 0; sections[i] != NULL; i++) { - corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection - (priv->corba_select_names, sections[i], ev); - control_widget = bonobo_widget_new_control_from_objref - (corba_control, CORBA_OBJECT_NIL); - - control_frame = bonobo_widget_get_control_frame (BONOBO_WIDGET (control_widget)); - pb = bonobo_control_frame_get_control_property_bag (control_frame, NULL); - card_arg = bonobo_property_bag_client_get_value_any (pb, "simple_card_list", NULL); - if (card_arg != NULL) { - cards = BONOBO_ARG_GET_GENERAL (card_arg, TC_GNOME_Evolution_Addressbook_SimpleCardList, GNOME_Evolution_Addressbook_SimpleCardList, NULL); - process_section (im, &cards, roles[i]); - bonobo_arg_release (card_arg); - } - } -} - -static void -attendee_changed_cb (EMeetingAttendee *ia, gpointer data) -{ - EMeetingModel *im = E_MEETING_MODEL (data); - EMeetingModelPrivate *priv; - gint row = -1, i; - - priv = im->priv; - - /* FIXME: Ideally I think you are supposed to call pre_change() before - the data structures are changed. */ - e_table_model_pre_change (E_TABLE_MODEL (im)); - - for (i = 0; i < priv->attendees->len; i++) { - if (ia == g_ptr_array_index (priv->attendees, i)) { - row = i; - break; - } - } - - if (row == -1) - e_table_model_no_change (E_TABLE_MODEL (im)); - else - e_table_model_row_changed (E_TABLE_MODEL (im), row); -} - -static void -table_destroy_state_cb (ETableScrolled *etable, gpointer data) -{ - ETable *real_table; - char *filename = data; - - real_table = e_table_scrolled_get_table (etable); - e_table_save_state (real_table, filename); - - g_free (data); -} - -static void -table_destroy_list_cb (ETableScrolled *etable, gpointer data) -{ - EMeetingModel *im = E_MEETING_MODEL (data); - EMeetingModelPrivate *priv; - - priv = im->priv; - - priv->tables = g_list_remove (priv->tables, etable); -} - diff --git a/calendar/gui/e-meeting-model.h b/calendar/gui/e-meeting-model.h deleted file mode 100644 index 50fba6c7a6..0000000000 --- a/calendar/gui/e-meeting-model.h +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-model.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_MEETING_MODEL_H_ -#define _E_MEETING_MODEL_H_ - -#include <gtk/gtk.h> -#include <gal/e-table/e-table-scrolled.h> -#include <gal/e-table/e-table-model.h> -#include <cal-client/cal-client.h> -#include "e-meeting-attendee.h" - -G_BEGIN_DECLS - -#define E_TYPE_MEETING_MODEL (e_meeting_model_get_type ()) -#define E_MEETING_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_MEETING_MODEL, EMeetingModel)) -#define E_MEETING_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_MEETING_MODEL, EMeetingModelClass)) -#define E_IS_MEETING_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_MEETING_MODEL)) -#define E_IS_MEETING_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_MEETING_MODEL)) - - -typedef struct _EMeetingModel EMeetingModel; -typedef struct _EMeetingModelPrivate EMeetingModelPrivate; -typedef struct _EMeetingModelClass EMeetingModelClass; - -typedef enum { - E_MEETING_MODEL_ADDRESS_COL, - E_MEETING_MODEL_MEMBER_COL, - E_MEETING_MODEL_TYPE_COL, - E_MEETING_MODEL_ROLE_COL, - E_MEETING_MODEL_RSVP_COL, - E_MEETING_MODEL_DELTO_COL, - E_MEETING_MODEL_DELFROM_COL, - E_MEETING_MODEL_STATUS_COL, - E_MEETING_MODEL_CN_COL, - E_MEETING_MODEL_LANGUAGE_COL, - E_MEETING_MODEL_COLUMN_COUNT -} EMeetingModelColumns; - -struct _EMeetingModel { - ETableModel parent; - - EMeetingModelPrivate *priv; -}; - -struct _EMeetingModelClass { - ETableModelClass parent_class; -}; - -typedef void (* EMeetingModelRefreshCallback) (gpointer data); - - -GtkType e_meeting_model_get_type (void); -GtkObject *e_meeting_model_new (void); - -CalClient *e_meeting_model_get_cal_client (EMeetingModel *im); -void e_meeting_model_set_cal_client (EMeetingModel *im, CalClient *client); - -icaltimezone *e_meeting_model_get_zone (EMeetingModel *im); -void e_meeting_model_set_zone (EMeetingModel *im, icaltimezone *zone); - -void e_meeting_model_add_attendee (EMeetingModel *im, EMeetingAttendee *ia); -EMeetingAttendee *e_meeting_model_add_attendee_with_defaults (EMeetingModel *im); - -void e_meeting_model_remove_attendee (EMeetingModel *im, EMeetingAttendee *ia); -void e_meeting_model_remove_all_attendees (EMeetingModel *im); - -EMeetingAttendee *e_meeting_model_find_attendee (EMeetingModel *im, const gchar *address, gint *row); -EMeetingAttendee *e_meeting_model_find_attendee_at_row (EMeetingModel *im, gint row); - -gint e_meeting_model_count_actual_attendees (EMeetingModel *im); -const GPtrArray *e_meeting_model_get_attendees (EMeetingModel *im); - -void e_meeting_model_refresh_all_busy_periods (EMeetingModel *im, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data); -void e_meeting_model_refresh_busy_periods (EMeetingModel *im, - int row, - EMeetingTime *start, - EMeetingTime *end, - EMeetingModelRefreshCallback call_back, - gpointer data); - - -/* Helpful functions */ -ETableScrolled *e_meeting_model_etable_from_model (EMeetingModel *im, const gchar *spec_file, const gchar *state_file); -void e_meeting_model_etable_click_to_add (EMeetingModel *im, gboolean click_to_add); -int e_meeting_model_etable_model_to_view_row (ETable *et, EMeetingModel *im, int model_row); -int e_meeting_model_etable_view_to_model_row (ETable *et, EMeetingModel *im, int view_row); - -void e_meeting_model_invite_others_dialog (EMeetingModel *im); - -G_END_DECLS - -#endif diff --git a/calendar/gui/e-meeting-time-sel-item.c b/calendar/gui/e-meeting-time-sel-item.c deleted file mode 100644 index e19a148e72..0000000000 --- a/calendar/gui/e-meeting-time-sel-item.c +++ /dev/null @@ -1,1009 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EMeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <time.h> -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include "calendar-config.h" -#include "e-meeting-time-sel-item.h" -#include "e-meeting-time-sel.h" - -/* Initially the grid lines were drawn at the bottom of cells, but this didn't - line up well with the GtkEntry widgets, which in the default theme draw a - black shadow line across the top. So I've switched our code to draw the - lines across the top of cells. */ -#define E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM 0 - -static void e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class); -static void e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item); -static void e_meeting_time_selector_item_destroy (GtkObject *object); - -static void e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_meeting_time_selector_item_realize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_meeting_time_selector_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_meeting_time_selector_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_meeting_time_selector_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); - -static void e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int y, int width, int height); -static void e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height); -static gint e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row); -static void e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int row, int x, int y, int width, int first_period, EMeetingFreeBusyType busy_type); - -static EMeetingTimeSelectorPosition e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, gint x, gint y); -static gboolean e_meeting_time_selector_item_calculate_busy_range (EMeetingTimeSelector *mts, - gint row, - gint x, - gint width, - gint *start_x, - gint *end_x); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MEETING_TIME_SELECTOR -}; - -E_MAKE_TYPE (e_meeting_time_selector_item, "EMeetingTimeSelectorItem", EMeetingTimeSelectorItem, - e_meeting_time_selector_item_class_init, e_meeting_time_selector_item_init, - GNOME_TYPE_CANVAS_ITEM); - -static void -e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (mts_item_class); - - object_class = (GtkObjectClass *) mts_item_class; - item_class = (GnomeCanvasItemClass *) mts_item_class; - - gtk_object_add_arg_type ("EMeetingTimeSelectorItem::meeting_time_selector", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_MEETING_TIME_SELECTOR); - - object_class->destroy = e_meeting_time_selector_item_destroy; - object_class->set_arg = e_meeting_time_selector_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_meeting_time_selector_item_realize; - item_class->unrealize = e_meeting_time_selector_item_unrealize; - item_class->update = e_meeting_time_selector_item_update; - item_class->draw = e_meeting_time_selector_item_draw; - item_class->point = e_meeting_time_selector_item_point; - item_class->event = e_meeting_time_selector_item_event; -} - - -static void -e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (mts_item); - - mts_item->mts = NULL; - - mts_item->main_gc = NULL; - mts_item->stipple_gc = NULL; - - /* Create the cursors. */ - mts_item->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR); - mts_item->resize_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - mts_item->last_cursor_set = NULL; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_meeting_time_selector_item_destroy (GtkObject *object) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (object); - - if (mts_item->normal_cursor) { - gdk_cursor_destroy (mts_item->normal_cursor); - mts_item->normal_cursor = NULL; - } - if (mts_item->resize_cursor) { - gdk_cursor_destroy (mts_item->resize_cursor); - mts_item->resize_cursor = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (*GTK_OBJECT_CLASS (parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMeetingTimeSelectorItem *mts_item; - - item = GNOME_CANVAS_ITEM (o); - mts_item = E_MEETING_TIME_SELECTOR_ITEM (o); - - switch (arg_id){ - case ARG_MEETING_TIME_SELECTOR: - mts_item->mts = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_meeting_time_selector_item_realize (GnomeCanvasItem *item) -{ - GnomeCanvas *canvas; - GdkWindow *window; - EMeetingTimeSelectorItem *mts_item; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->realize)(item); - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - canvas = item->canvas; - window = GTK_WIDGET (canvas)->window; - - mts_item->main_gc = gdk_gc_new (window); - mts_item->stipple_gc = gdk_gc_new (window); -} - - -static void -e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - gdk_gc_unref (mts_item->main_gc); - mts_item->main_gc = NULL; - gdk_gc_unref (mts_item->stipple_gc); - mts_item->stipple_gc = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize)(item); -} - - -static void -e_meeting_time_selector_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The grid covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorItem *mts_item; - ETable *real_table; - EMeetingAttendee *ia; - gint day_x, meeting_start_x, meeting_end_x, bar_y, bar_height; - gint row, row_y, start_x, end_x; - GDate date, last_date, current_date; - gboolean is_display_top, show_meeting_time; - GdkGC *gc, *stipple_gc; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - mts = mts_item->mts; - g_return_if_fail (mts != NULL); - gc = mts_item->main_gc; - stipple_gc = mts_item->stipple_gc; - - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); - - is_display_top = (GTK_WIDGET (item->canvas) == mts->display_top) - ? TRUE : FALSE; - - /* Calculate the first and last visible days and positions. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, - &date, &day_x); - e_meeting_time_selector_calculate_day_and_position (mts, x + width, - &last_date, NULL); - - /* For the top display draw the 'All Attendees' row background. */ - if (is_display_top) { - gdk_gc_set_foreground (gc, &mts->all_attendees_bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, - 0, mts->row_height * 2 - y, - width, mts->row_height); - } else { - gdk_gc_set_foreground (gc, &mts->bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height); - } - - /* Calculate the x coordinates of the meeting time. */ - show_meeting_time = e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x); - - /* Draw the meeting time background. */ - if (show_meeting_time - && (meeting_end_x - 1 >= x) && (meeting_start_x + 1 < x + width) - && (meeting_end_x - meeting_start_x > 2)) { - gdk_gc_set_foreground (gc, &mts->meeting_time_bg_color); - if (is_display_top) - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, mts->row_height * 2 - y, - meeting_end_x - meeting_start_x - 2, mts->row_height); - else - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, 0, - meeting_end_x - meeting_start_x - 2, height); - } - - /* For the main display draw the stipple background for attendee's - that have no calendar information. */ - if (!is_display_top) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_foreground (stipple_gc, &mts->grid_color); - gdk_gc_set_background (stipple_gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (stipple_gc, mts->stipple); - gnome_canvas_set_stipple_origin (item->canvas, stipple_gc); - gdk_gc_set_fill (stipple_gc, GDK_OPAQUE_STIPPLED); - row = y / mts->row_height; - row_y = row * mts->row_height - y; - while (row < e_meeting_model_count_actual_attendees (mts->model) && row_y < height) { - gint model_row = e_meeting_model_etable_view_to_model_row (real_table, - mts->model, row); - - ia = e_meeting_model_find_attendee_at_row (mts->model, model_row); - - if (e_meeting_attendee_get_has_calendar_info (ia)) { - if (e_meeting_time_selector_item_calculate_busy_range (mts, model_row, x, width, &start_x, &end_x)) { - if (start_x >= width || end_x <= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, width, mts->row_height); - } else { - if (start_x >= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, start_x, mts->row_height); - gdk_draw_line (drawable, gc, start_x, row_y, start_x, row_y + mts->row_height); - } - if (end_x <= width) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, end_x, row_y, width - end_x, mts->row_height); - gdk_draw_line (drawable, gc, end_x, row_y, end_x, row_y + mts->row_height); - } - } - } - } else { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, - 0, row_y, - width, mts->row_height); - } - row++; - row_y += mts->row_height; - } - gdk_gc_set_fill (gc, GDK_SOLID); - } - - /* Now paint the visible days one by one. */ - current_date = date; - for (;;) { - /* Currently we use the same GnomeCanvasItem class for the - top display and the main display. We may use separate - classes in future if necessary. */ - if (is_display_top) - e_meeting_time_selector_item_paint_day_top (mts_item, drawable, ¤t_date, day_x, y, width, height); - else - e_meeting_time_selector_item_paint_day (mts_item, drawable, ¤t_date, day_x, y, width, height); - - day_x += mts_item->mts->day_width; - if (g_date_compare (¤t_date, &last_date) == 0) - break; - g_date_add_days (¤t_date, 1); - } - - /* Draw the busy periods. */ - if (is_display_top) - e_meeting_time_selector_item_paint_all_attendees_busy_periods (mts_item, drawable, &date, x, y, width, height); - else - e_meeting_time_selector_item_paint_busy_periods (mts_item, drawable, &date, x, y, width, height); - - - /* Draw the currently-selected meeting time vertical bars. */ - if (show_meeting_time) { - if (is_display_top) { - bar_y = mts->row_height * 2 - y; - bar_height = mts->row_height; - } else { - bar_y = 0; - bar_height = height; - } - - gdk_gc_set_foreground (gc, &mts->grid_color); - - if ((meeting_start_x + 2 >= x) - && (meeting_start_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x - 2 - x, bar_y, - 5, bar_height); - } - - if ((meeting_end_x + 2 >= x) - && (meeting_end_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_end_x - 2 - x, bar_y, - 5, bar_height); - } - } -} - - -static void -e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - gint y, grid_x; - gchar buffer[128], *format; - gint hour, hour_x, hour_y; - GdkRectangle clip_rect; - PangoLayout *layout; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - gdk_gc_set_foreground (gc, &mts->grid_color); - layout = gtk_widget_create_pango_layout (GTK_WIDGET (mts), NULL); - - /* Draw the horizontal lines. */ - y = mts->row_height - 1 - scroll_y; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - gdk_gc_set_foreground (gc, &mts->grid_shadow_color); - gdk_draw_line (drawable, gc, x, y + 1, x + mts->day_width - 1, y + 1); - gdk_gc_set_foreground (gc, &mts->grid_color); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - - /* Draw the vertical grid lines. */ - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) { - gdk_draw_line (drawable, gc, - x + grid_x, mts->row_height * 2 - 4 - scroll_y, - x + grid_x, height); - } - grid_x = mts->day_width - 2; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - grid_x++; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_FULL) - /* This is a strftime() format string %A = full weekday name, - %B = full month name, %d = month day, %Y = full year. */ - format = _("%A, %B %d, %Y"); - else if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY) - /* This is a strftime() format string %a = abbreviated weekday - name, %m = month number, %d = month day, %Y = full year. */ - format = _("%a %m/%d/%Y"); - else - /* This is a strftime() format string %m = month number, - %d = month day, %Y = full year. */ - format = _("%m/%d/%Y"); - - g_date_strftime (buffer, sizeof (buffer), format, date); - - clip_rect.x = x; - clip_rect.y = -scroll_y; - clip_rect.width = mts->day_width - 2; - clip_rect.height = mts->row_height - 2; - gdk_gc_set_clip_rectangle (gc, &clip_rect); - pango_layout_set_text (layout, buffer, -1); - gdk_draw_layout (drawable, gc, - x + 2, - 4 - scroll_y, - layout); - gdk_gc_set_clip_rectangle (gc, NULL); - - /* Draw the hours. */ - hour = mts->first_hour_shown; - hour_x = x + 2; - hour_y = mts->row_height + 4 - scroll_y; - while (hour < mts->last_hour_shown) { - if (calendar_config_get_24_hour_format ()) - pango_layout_set_text (layout, EMeetingTimeSelectorHours [hour], -1); - else - pango_layout_set_text (layout, EMeetingTimeSelectorHours12 [hour], -1); - - gdk_draw_layout (drawable, gc, - hour_x, - hour_y, - layout); - - hour += mts->zoomed_out ? 3 : 1; - hour_x += mts->col_width; - } - - g_object_unref (layout); -} - - -/* This paints the colored bars representing busy periods for the combined - list of attendees. For now we just paint the bars for each attendee of - each other. If we want to speed it up we could optimise it later. */ -static void -e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingAttendee *ia; - EMeetingFreeBusyType busy_type; - gint row, y; - GdkGC *gc; - gint *first_periods; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = 2 * mts->row_height - scroll_y - 1; - - /* Get the first visible busy periods for all the attendees. */ - first_periods = g_new (gint, e_meeting_model_count_actual_attendees (mts->model)); - for (row = 0; row < e_meeting_model_count_actual_attendees (mts->model); row++) { - ia = e_meeting_model_find_attendee_at_row (mts->model, row); - first_periods[row] = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, row); - } - - for (busy_type = 0; - busy_type < E_MEETING_FREE_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - for (row = 0; row < e_meeting_model_count_actual_attendees (mts->model); row++) { - if (first_periods[row] == -1) - continue; - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, row, first_periods[row], busy_type); - } - } - - g_free (first_periods); -} - - -static void -e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - gint grid_x, grid_y, attendee_index, unused_y; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Draw the grid lines. The grid lines around unused rows are drawn in - a different color. */ - - /* Draw the horizontal grid lines. */ - attendee_index = scroll_y / mts->row_height; -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - for (grid_y = mts->row_height - 1 - (scroll_y % mts->row_height); -#else - for (grid_y = - (scroll_y % mts->row_height); -#endif - grid_y < height; - grid_y += mts->row_height) - { - if (attendee_index <= e_meeting_model_count_actual_attendees (mts->model)) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } else { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } - attendee_index++; - } - - /* Draw the vertical grid lines. */ - unused_y = (e_meeting_model_count_actual_attendees (mts->model) * mts->row_height) - scroll_y; - if (unused_y >= 0) { - gdk_gc_set_foreground (gc, &mts->grid_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, 0, - x + grid_x, unused_y - 1); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, 0, - 2, unused_y); - } - - if (unused_y < height) { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, unused_y, - x + grid_x, height); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, unused_y, - 2, height - unused_y); - } - - -} - - -/* This paints the colored bars representing busy periods for the individual - attendees. */ -static void -e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingFreeBusyType busy_type; - ETable *real_table; - gint row, model_row, y, first_period; - GdkGC *gc; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); - - /* Calculate the first visible attendee row. */ - row = scroll_y / mts->row_height; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = row * mts->row_height - scroll_y; - - /* Step through the attendees painting the busy periods. */ - while (y < height && row < e_meeting_model_count_actual_attendees (mts->model)) { - model_row = e_meeting_model_etable_view_to_model_row (real_table, mts->model, row); - - /* Find the first visible busy period. */ - first_period = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, model_row); - if (first_period != -1) { - /* Paint the different types of busy periods, in - reverse order of precedence, so the highest - precedences are displayed. */ - for (busy_type = 0; - busy_type < E_MEETING_FREE_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, model_row, first_period, busy_type); - } - } - y += mts->row_height; - row++; - } -} - - -/* This subtracts the attendees longest_period_in_days from the given date, - and does a binary search of the attendee's busy periods array to find the - first one which could possible end on the given day or later. - If none are found it returns -1. */ -static gint -e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row) -{ - EMeetingTimeSelector *mts; - EMeetingAttendee *ia; - const GArray *busy_periods; - EMeetingFreeBusyPeriod *period; - gint period_num; - - mts = mts_item->mts; - - ia = e_meeting_model_find_attendee_at_row (mts->model, row); - - period_num = e_meeting_attendee_find_first_busy_period (ia, date); - if (period_num == -1) - return -1; - - /* Check if the period starts after the end of the current canvas - scroll area. */ - busy_periods = e_meeting_attendee_get_busy_periods (ia); - period = &g_array_index (busy_periods, EMeetingFreeBusyPeriod, period_num); - if (g_date_compare (&mts->last_date_shown, &period->start.date) < 0) - return -1; - - return period_num; -} - - -/* This paints the visible busy periods for one attendee which are of a certain - busy type, e.g out of office. It is passed the index of the first visible - busy period of the attendee and continues until it runs off the screen. */ -static void -e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int x, int y, int width, int row, int first_period, EMeetingFreeBusyType busy_type) -{ - EMeetingTimeSelector *mts; - EMeetingAttendee *ia; - const GArray *busy_periods; - EMeetingFreeBusyPeriod *period; - GdkGC *gc; - gint period_num, x1, x2, x2_within_day, x2_within_col; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - ia = e_meeting_model_find_attendee_at_row (mts->model, row); - - busy_periods = e_meeting_attendee_get_busy_periods (ia); - for (period_num = first_period; - period_num < busy_periods->len; - period_num++) { - period = &g_array_index (busy_periods, EMeetingFreeBusyPeriod, period_num); - - if (period->busy_type != busy_type) - continue; - - /* Convert the period start and end times to x coordinates. */ - x1 = e_meeting_time_selector_calculate_time_position (mts, &period->start); - /* If the period is off the right of the area being drawn, we - are finished. */ - if (x1 >= x + width) - return; - - x2 = e_meeting_time_selector_calculate_time_position (mts, &period->end); - /* If the period is off the left edge of the area skip it. */ - if (x2 <= x) - continue; - - /* We paint from x1 to x2 - 1, so that for example a time - from 5:00-6:00 is distinct from 6:00-7:00. - We never finish on a grid line separating days, and we only - ever paint on a normal vertical grid line if the period is - only 1 pixel wide. */ - x2_within_day = x2 % mts->day_width; - if (x2_within_day == 0) { - x2 -= 2; - } else if (x2_within_day == mts->day_width - 1) { - x2 -= 1; - } else { - x2_within_col = x2_within_day % mts->col_width; - if (x2_within_col == 0 && x2 > x1 + 1) - x2 -= 1; - } - - /* Paint the rectangle. We leave a gap of 2 pixels at the - top and bottom, remembering that the grid is painted along - the top/bottom line of each row. */ - if (x2 - x1 > 0) { -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 2, - x2 - x1, mts->row_height - 5); -#else - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 3, - x2 - x1, mts->row_height - 5); -#endif - } - } -} - - -/* - * CANVAS ITEM ROUTINES - functions to be a GnomeCanvasItem. - */ - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_meeting_time_selector_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_meeting_time_selector_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_meeting_time_selector_item_button_press (mts_item, - event); - case GDK_BUTTON_RELEASE: - return e_meeting_time_selector_item_button_release (mts_item, - event); - case GDK_MOTION_NOTIFY: - return e_meeting_time_selector_item_motion_notify (mts_item, - event); - default: - break; - } - - return FALSE; -} - - -/* This handles all button press events for the item. If the cursor is over - one of the meeting time vertical bars we start a drag. If not we set the - meeting time to the nearest half-hour interval. - Note that GnomeCanvas converts the event coords to world coords, - i.e. relative to the entire canvas scroll area. */ -static gint -e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTime start_time, end_time; - EMeetingTimeSelectorPosition position; - GDate *start_date, *end_date; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->button.x; - y = (gint) event->button.y; - - /* Check if we are starting a drag of the vertical meeting time bars.*/ - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - if (position != E_MEETING_TIME_SELECTOR_POS_NONE) { - if (gnome_canvas_item_grab (GNOME_CANVAS_ITEM (mts_item), - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - mts_item->resize_cursor, - event->button.time) == 0 /*Success*/) { - mts->dragging_position = position; - return TRUE; - } - } - - /* Convert the x coordinate into a EMeetingTimeSelectorTime. */ - e_meeting_time_selector_calculate_time (mts, x, &start_time); - start_date = &start_time.date; - end_date = &end_time.date; - - /* Find the nearest half-hour or hour interval, depending on whether - zoomed_out is set. */ - if (!mts->all_day) { - if (mts->zoomed_out) { - start_time.minute = 0; - end_time = start_time; - end_time.hour += 1; - } else { - start_time.minute -= start_time.minute % 30; - end_time = start_time; - end_time.minute += 30; - } - } else { - start_time.hour = 0; - start_time.minute = 0; - end_time = start_time; - g_date_add_days (&end_time.date, 1); - } - - /* Fix any overflows. */ - e_meeting_time_selector_fix_time_overflows (&end_time); - - /* Set the new meeting time. */ - e_meeting_time_selector_set_meeting_time (mts_item->mts, - g_date_year (start_date), - g_date_month (start_date), - g_date_day (start_date), - start_time.hour, - start_time.minute, - g_date_year (end_date), - g_date_month (end_date), - g_date_day (end_date), - end_time.hour, - end_time.minute); - - - return FALSE; -} - - -/* This handles all button release events for the item. If we were dragging, - we finish the drag. */ -static gint -e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - - mts = mts_item->mts; - - /* Reset any drag. */ - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - e_meeting_time_selector_remove_timeout (mts); - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (mts_item), - event->button.time); - } - - return FALSE; -} - - -/* This handles all motion notify events for the item. If button1 is pressed - we check if a drag is in progress. If not, we set the cursor if we are over - the meeting time vertical bars. Note that GnomeCanvas doesn't use motion - hints, which may affect performance. */ -static gint -e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorPosition position; - GdkCursor *cursor; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->motion.x; - y = (gint) event->motion.y; - - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - e_meeting_time_selector_drag_meeting_time (mts, x); - return TRUE; - } - - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - - /* Determine which cursor should be used. */ - if (position == E_MEETING_TIME_SELECTOR_POS_NONE) - cursor = mts_item->normal_cursor; - else - cursor = mts_item->resize_cursor; - - /* Only set the cursor if it is different to the last one we set. */ - if (mts_item->last_cursor_set != cursor) { - mts_item->last_cursor_set = cursor; - gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas)->window, cursor); - } - - return FALSE; -} - - -static EMeetingTimeSelectorPosition -e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, - gint x, gint y) -{ - EMeetingTimeSelector *mts; - gboolean is_display_top; - gint meeting_start_x, meeting_end_x; - - mts = mts_item->mts; - - is_display_top = (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas) == mts->display_top) ? TRUE : FALSE; - - if (is_display_top && y < mts->row_height * 2) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (!e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x)) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (x >= meeting_end_x - 2 && x <= meeting_end_x + 2) - return E_MEETING_TIME_SELECTOR_POS_END; - - if (x >= meeting_start_x - 2 && x <= meeting_start_x + 2) - return E_MEETING_TIME_SELECTOR_POS_START; - - return E_MEETING_TIME_SELECTOR_POS_NONE; -} - - -static gboolean -e_meeting_time_selector_item_calculate_busy_range (EMeetingTimeSelector *mts, - gint row, - gint x, - gint width, - gint *start_x, - gint *end_x) -{ - EMeetingAttendee *ia; - EMeetingTime busy_periods_start; - EMeetingTime busy_periods_end; - - ia = e_meeting_model_find_attendee_at_row (mts->model, row); - busy_periods_start = e_meeting_attendee_get_start_busy_range (ia); - busy_periods_end = e_meeting_attendee_get_end_busy_range (ia); - - *start_x = -1; - *end_x = -1; - - if (!g_date_valid (&busy_periods_start.date) - || !g_date_valid (&busy_periods_end.date)) - return FALSE; - - *start_x = e_meeting_time_selector_calculate_time_position (mts, &busy_periods_start) - x - 1; - - *end_x = e_meeting_time_selector_calculate_time_position (mts, &busy_periods_end) - x; - - return TRUE; -} diff --git a/calendar/gui/e-meeting-time-sel-item.h b/calendar/gui/e-meeting-time-sel-item.h deleted file mode 100644 index 11b355dfa0..0000000000 --- a/calendar/gui/e-meeting-time-sel-item.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * MeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#ifndef _E_MEETING_TIME_SELECTOR_ITEM_H_ -#define _E_MEETING_TIME_SELECTOR_ITEM_H_ - -#include "e-meeting-time-sel.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_MEETING_TIME_SELECTOR_ITEM(obj) (GTK_CHECK_CAST((obj), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItem)) -#define E_MEETING_TIME_SELECTOR_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItemClass)) -#define IS_E_MEETING_TIME_SELECTOR_ITEM(o) (GTK_CHECK_TYPE((o), e_meeting_time_selector_item_get_type ())) - - -typedef struct _EMeetingTimeSelectorItem EMeetingTimeSelectorItem; -typedef struct _EMeetingTimeSelectorItemClass EMeetingTimeSelectorItemClass; - -struct _EMeetingTimeSelectorItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EMeetingTimeSelector widget. */ - EMeetingTimeSelector *mts; - - /* This GC is used for most of the drawing. The fg/bg colors are - changed for each bit. */ - GdkGC *main_gc; - GdkGC *stipple_gc; - - /* The normal & resize cursors. */ - GdkCursor *normal_cursor; - GdkCursor *resize_cursor; - - /* This remembers the last cursor set on the window. */ - GdkCursor *last_cursor_set; -}; - - -struct _EMeetingTimeSelectorItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_meeting_time_selector_item_get_type (void); - - -#endif /* _E_MEETING_TIME_SELECTOR_ITEM_H_ */ diff --git a/calendar/gui/e-meeting-time-sel.c b/calendar/gui/e-meeting-time-sel.c deleted file mode 100644 index b1d7ff0bbc..0000000000 --- a/calendar/gui/e-meeting-time-sel.c +++ /dev/null @@ -1,2918 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-meeting-time-sel.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <glib.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkalignment.h> -#include <gtk/gtkarrow.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkdrawingarea.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkfixed.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkhscrollbar.h> -#include <gtk/gtkhseparator.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkradiomenuitem.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkvscrollbar.h> -#include <libgnomeui/gnome-dateedit.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomecanvas/gnome-canvas-widget.h> - -#include <gal/widgets/e-canvas.h> -#include <gal/widgets/e-canvas-utils.h> -#include <gal/e-table/e-cell-combo.h> -#include <gal/e-table/e-cell-text.h> -#include <gal/e-table/e-table-simple.h> -#include <gal/e-table/e-table-scrolled.h> -#include <gal/e-table/e-table-header-item.h> -#include <gal/e-table/e-table-header-utils.h> - -#include <widgets/misc/e-dateedit.h> - -#include "calendar-component.h" -#include "calendar-config.h" -#include "e-meeting-utils.h" -#include "e-meeting-time-sel-item.h" - -/* An array of hour strings for 24 hour time, "0:00" .. "23:00". */ -const gchar *EMeetingTimeSelectorHours[24] = { - "0:00", "1:00", "2:00", "3:00", "4:00", "5:00", "6:00", "7:00", - "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", - "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" -}; - -/* An array of hour strings for 12 hour time, "12:00am" .. "11:00pm". */ -const gchar *EMeetingTimeSelectorHours12[24] = { - "12:00am", "1:00am", "2:00am", "3:00am", "4:00am", "5:00am", "6:00am", - "7:00am", "8:00am", "9:00am", "10:00am", "11:00am", "12:00pm", - "1:00pm", "2:00pm", "3:00pm", "4:00pm", "5:00pm", "6:00pm", "7:00pm", - "8:00pm", "9:00pm", "10:00pm", "11:00pm" -}; - -/* The number of days shown in the entire canvas. */ -#define E_MEETING_TIME_SELECTOR_DAYS_SHOWN 365 -#define E_MEETING_TIME_SELECTOR_DAYS_START_BEFORE 60 -#define E_MEETING_TIME_SELECTOR_FB_DAYS_BEFORE 7 -#define E_MEETING_TIME_SELECTOR_FB_DAYS_AFTER 28 - -/* This is the number of pixels between the mouse has to move before the - scroll speed is incremented. */ -#define E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH 10 - -/* This is the maximum scrolling speed. */ -#define E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED 4 - -/* Signals */ -enum { - CHANGED, - LAST_SIGNAL -}; - - -static gint mts_signals [LAST_SIGNAL] = { 0 }; - -static void e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass); -static void e_meeting_time_selector_init (EMeetingTimeSelector * mts); -static void e_meeting_time_selector_destroy (GtkObject *object); -static void e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c); -static void e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, - GdkColor *color); -static gint e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color); -static void e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_realize (GtkWidget *widget); -static void e_meeting_time_selector_unrealize (GtkWidget *widget); -static void e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static gint e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void e_meeting_time_selector_draw_shadow (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_table_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data); -static void e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_working_hours_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static gboolean e_meeting_time_selector_on_invite_others_button_expose (GtkWidget *button, - GdkEventExpose *event, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data); -static void e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward); -static void e_meeting_time_selector_calculate_time_difference (EMeetingTime*start, - EMeetingTime*end, - gint *days, - gint *hours, - gint *minutes); -static void e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTime*start_time, - EMeetingTime*end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTime *start_time, - EMeetingTime *end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_adjust_time (EMeetingTime*mtstime, - gint days, gint hours, gint minutes); -static EMeetingFreeBusyPeriod* e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingAttendee *attendee, - EMeetingTime *start_time, - EMeetingTime *end_time); - - -static void e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTime *mtstime); -static void e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTime*mtstime); -static void e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts); -static gboolean e_meeting_time_selector_timeout_handler (gpointer data); -static void e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts); - -static void rows_inserted_cb (ETableModel *etm, int row, int count, gpointer data); -static void cell_changed_cb (ETableModel *etm, int row, int col, gpointer data); -static void rows_deleted_cb (ETableModel *etm, int row, int count, gpointer data); -static void sort_info_changed_cb (ETableSortInfo *info, gpointer data); - -static GtkTableClass *parent_class; - -E_MAKE_TYPE (e_meeting_time_selector, "EMeetingTimeSelector", EMeetingTimeSelector, - e_meeting_time_selector_class_init, e_meeting_time_selector_init, - GTK_TYPE_TABLE); - -static void -e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = g_type_class_peek_parent (klass); - object_class = (GtkObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - mts_signals [CHANGED] = - gtk_signal_new ("changed", GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (EMeetingTimeSelectorClass, - changed), - gtk_signal_default_marshaller, - GTK_TYPE_NONE, 0); - - object_class->destroy = e_meeting_time_selector_destroy; - - widget_class->realize = e_meeting_time_selector_realize; - widget_class->unrealize = e_meeting_time_selector_unrealize; - widget_class->style_set = e_meeting_time_selector_style_set; - widget_class->expose_event = e_meeting_time_selector_expose_event; -} - - -static void -e_meeting_time_selector_init (EMeetingTimeSelector * mts) -{ - /* The shadow is drawn in the border so it must be >= 2 pixels. */ - gtk_container_set_border_width (GTK_CONTAINER (mts), 2); - - mts->accel_group = gtk_accel_group_new (); - - mts->working_hours_only = TRUE; - mts->day_start_hour = 9; - mts->day_start_minute = 0; - mts->day_end_hour = 18; - mts->day_end_minute = 0; - mts->zoomed_out = TRUE; - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - - mts->etable = NULL; -} - - -void -e_meeting_time_selector_construct (EMeetingTimeSelector * mts, EMeetingModel *emm) -{ - GtkWidget *hbox, *vbox, *separator, *button, *label, *table; - GtkWidget *alignment, *child_hbox, *arrow, *menuitem; - GSList *group; - GdkVisual *visual; - GdkColormap *colormap; - guint accel_key; - GtkAccelGroup *menu_accel_group; - time_t meeting_start_time; - struct tm *meeting_start_tm; - char *filename; - ETable *real_table; - guchar stipple_bits[] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - }; - - /* The default meeting time is the nearest half-hour interval in the - future, in working hours. */ - meeting_start_time = time (NULL); - g_date_clear (&mts->meeting_start_time.date, 1); - g_date_set_time (&mts->meeting_start_time.date, meeting_start_time); - meeting_start_tm = localtime (&meeting_start_time); - mts->meeting_start_time.hour = meeting_start_tm->tm_hour; - mts->meeting_start_time.minute = meeting_start_tm->tm_min; - - e_meeting_time_selector_find_nearest_interval (mts, &mts->meeting_start_time, - &mts->meeting_end_time, - 0, 0, 30); - - e_meeting_time_selector_update_dates_shown (mts); - - mts->meeting_positions_valid = FALSE; - - mts->row_height = 19; - mts->col_width = 55; - mts->day_width = 55 * 24 + 1; - - mts->auto_scroll_timeout_id = 0; - - vbox = gtk_vbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (mts), - vbox, 0, 1, 0, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (vbox); - - mts->attendees_vbox_spacer = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), mts->attendees_vbox_spacer, FALSE, FALSE, 0); - gtk_widget_show (mts->attendees_vbox_spacer); - - mts->attendees_vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), mts->attendees_vbox, TRUE, TRUE, 0); - gtk_widget_show (mts->attendees_vbox); - - /* build the etable */ - filename = g_strdup_printf ("%s/config/et-header-meeting-time-sel", evolution_dir); - mts->model = emm; - if (mts->model) - g_object_ref (mts->model); - - g_signal_connect (mts->model, "model_rows_inserted", G_CALLBACK (rows_inserted_cb), mts); - g_signal_connect (mts->model, "model_cell_changed", G_CALLBACK (cell_changed_cb), mts); - g_signal_connect (mts->model, "model_rows_deleted", G_CALLBACK (rows_deleted_cb), mts); - - mts->etable = GTK_WIDGET (e_meeting_model_etable_from_model (mts->model, - EVOLUTION_ETSPECDIR "/e-meeting-time-sel.etspec", - filename)); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mts->etable), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); - g_signal_connect (real_table->sort_info, "sort_info_changed", G_CALLBACK (sort_info_changed_cb), mts); - - gtk_box_pack_start (GTK_BOX (mts->attendees_vbox), mts->etable, TRUE, TRUE, 6); - gtk_widget_show (mts->etable); - g_free (filename); - - /* The free/busy information */ - mts->display_top = gnome_canvas_new (); - gtk_widget_set_usize (mts->display_top, -1, mts->row_height * 3); - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_top, - 1, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->display_top); - g_signal_connect (mts->display_top, "realize", - G_CALLBACK (e_meeting_time_selector_on_canvas_realized), mts); - - mts->display_main = gnome_canvas_new (); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_main, - 1, 4, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (mts->display_main); - g_signal_connect (mts->display_main, "realize", - G_CALLBACK (e_meeting_time_selector_on_canvas_realized), mts); - g_signal_connect (mts->display_main, "size_allocate", - G_CALLBACK (e_meeting_time_selector_on_canvas_size_allocate), mts); - - mts->hscrollbar = gtk_hscrollbar_new (GTK_LAYOUT (mts->display_main)->hadjustment); - GTK_LAYOUT (mts->display_main)->hadjustment->step_increment = mts->col_width; - gtk_table_attach (GTK_TABLE (mts), mts->hscrollbar, - 1, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->hscrollbar); - - mts->vscrollbar = gtk_vscrollbar_new (GTK_LAYOUT (mts->display_main)->vadjustment); - GTK_LAYOUT (mts->display_main)->vadjustment->step_increment = mts->row_height; - gtk_table_attach (GTK_TABLE (mts), mts->vscrollbar, - 4, 5, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (mts->vscrollbar); - - /* Create the item in the top canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_top)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the item in the main canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_main)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the hbox containing the color key. */ - hbox = gtk_hbox_new (FALSE, 2); - gtk_table_attach (GTK_TABLE (mts), hbox, - 1, 4, 3, 4, GTK_FILL, 0, 0, 8); - gtk_widget_show (hbox); - - e_meeting_time_selector_add_key_color (mts, hbox, _("Tentative"), &mts->busy_colors[E_MEETING_FREE_BUSY_TENTATIVE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Busy"), &mts->busy_colors[E_MEETING_FREE_BUSY_BUSY]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Out of Office"), &mts->busy_colors[E_MEETING_FREE_BUSY_OUT_OF_OFFICE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("No Information"), - NULL); - - separator = gtk_hseparator_new (); - gtk_table_attach (GTK_TABLE (mts), separator, - 0, 5, 4, 5, GTK_FILL, 0, 0, 0); - gtk_widget_show (separator); - - /* Create the Invite Others & Options buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 4); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 3, 4, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_Invite Others...")); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6); - gtk_widget_show (button); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (button, "clicked", - G_CALLBACK (e_meeting_time_selector_on_invite_others_button_clicked), mts); - g_signal_connect (button, "expose-event", - G_CALLBACK (e_meeting_time_selector_on_invite_others_button_expose), mts); - - mts->options_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->options_button, TRUE, TRUE, 6); - gtk_widget_show (mts->options_button); - - g_signal_connect (mts->options_button, "clicked", - G_CALLBACK (e_meeting_time_selector_on_options_button_clicked), mts); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->options_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Options")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 6); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->options_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 6); - gtk_widget_show (arrow); - - /* Create the Options menu. */ - mts->options_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->options_menu), mts->options_button, - e_meeting_time_selector_options_menu_detacher); - - menu_accel_group = gtk_accel_group_new (); - gtk_menu_set_accel_group (GTK_MENU (mts->options_menu), menu_accel_group); - /* FIXME: Should unref accel group here? */ - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Only Working Hours")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->working_hours_only); - - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "toggled", - G_CALLBACK (e_meeting_time_selector_on_working_hours_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Zoomed Out")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->zoomed_out); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "toggled", - G_CALLBACK (e_meeting_time_selector_on_zoomed_out_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new (); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Update Free/Busy")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "activate", - G_CALLBACK (e_meeting_time_selector_on_update_free_busy), mts); - gtk_widget_show (menuitem); - - /* Create the 3 AutoPick buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_<<")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6); - gtk_widget_show (button); - g_signal_connect (button, "clicked", - G_CALLBACK (e_meeting_time_selector_on_prev_button_clicked), mts); - - mts->autopick_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->autopick_button, TRUE, TRUE, 6); - gtk_widget_show (mts->autopick_button); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->autopick_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Autopick")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 6); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->autopick_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (mts->autopick_button, "clicked", - G_CALLBACK (e_meeting_time_selector_on_autopick_button_clicked), mts); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 6); - gtk_widget_show (arrow); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _(">_>")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6); - gtk_widget_show (button); - g_signal_connect (button, "clicked", - G_CALLBACK (e_meeting_time_selector_on_next_button_clicked), mts); - - /* Create the Autopick menu. */ - mts->autopick_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->autopick_menu), mts->autopick_button, - e_meeting_time_selector_autopick_menu_detacher); - - menu_accel_group = gtk_accel_group_new (); - gtk_menu_set_accel_group (GTK_MENU (mts->autopick_menu), menu_accel_group); - - menuitem = gtk_radio_menu_item_new_with_label (NULL, ""); - mts->autopick_all_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_All People and Resources")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "toggled", - G_CALLBACK (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_all_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("All _People and One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "toggled", - G_CALLBACK (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Required People")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "activate", - G_CALLBACK (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Required People and _One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - g_signal_connect (menuitem, "activate", - G_CALLBACK (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - /* Create the date entry fields on the right. */ - alignment = gtk_alignment_new (0.0, 0.5, 0, 0); - gtk_table_attach (GTK_TABLE (mts), alignment, - 1, 4, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (alignment); - - table = gtk_table_new (2, 2, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - gtk_widget_show (table); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _start time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 0, 1, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->start_date_edit = e_date_edit_new (); - e_date_edit_set_show_time (E_DATE_EDIT (mts->start_date_edit), TRUE); - e_date_edit_set_use_24_hour_format (E_DATE_EDIT (mts->start_date_edit), - calendar_config_get_24_hour_format ()); - - gtk_table_attach (GTK_TABLE (table), mts->start_date_edit, - 1, 2, 0, 1, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->start_date_edit); - g_signal_connect (mts->start_date_edit, "changed", - G_CALLBACK (e_meeting_time_selector_on_start_time_changed), mts); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _end time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 1, 2, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->end_date_edit = e_date_edit_new (); - e_date_edit_set_show_time (E_DATE_EDIT (mts->end_date_edit), TRUE); - e_date_edit_set_use_24_hour_format (E_DATE_EDIT (mts->end_date_edit), - calendar_config_get_24_hour_format ()); - - gtk_table_attach (GTK_TABLE (table), mts->end_date_edit, - 1, 2, 1, 2, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->end_date_edit); - g_signal_connect (mts->end_date_edit, "changed", - G_CALLBACK (e_meeting_time_selector_on_end_time_changed), mts); - - gtk_table_set_col_spacing (GTK_TABLE (mts), 0, 4); - gtk_table_set_row_spacing (GTK_TABLE (mts), 4, 12); - - /* Allocate the colors. */ - visual = gtk_widget_get_visual (GTK_WIDGET (mts)); - colormap = gtk_widget_get_colormap (GTK_WIDGET (mts)); - e_meeting_time_selector_alloc_named_color (mts, "gray75", &mts->bg_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->all_attendees_bg_color); - gdk_color_black (colormap, &mts->grid_color); - gdk_color_white (colormap, &mts->grid_shadow_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->grid_unused_color); - gdk_color_white (colormap, &mts->meeting_time_bg_color); - gdk_color_white (colormap, &mts->stipple_bg_color); - gdk_color_white (colormap, &mts->attendee_list_bg_color); - - e_meeting_time_selector_alloc_named_color (mts, "LightSkyBlue2", &mts->busy_colors[E_MEETING_FREE_BUSY_TENTATIVE]); - e_meeting_time_selector_alloc_named_color (mts, "blue", &mts->busy_colors[E_MEETING_FREE_BUSY_BUSY]); - e_meeting_time_selector_alloc_named_color (mts, "HotPink3", &mts->busy_colors[E_MEETING_FREE_BUSY_OUT_OF_OFFICE]); - - /* Create the stipple, for attendees with no data. */ - mts->stipple = gdk_bitmap_create_from_data (NULL, (gchar*)stipple_bits, - 8, 8); - - /* Connect handlers to the adjustments scroll the other items. */ - g_signal_connect (GTK_LAYOUT (mts->display_main)->hadjustment, "value_changed", - G_CALLBACK (e_meeting_time_selector_hadjustment_changed), mts); - g_signal_connect (GTK_LAYOUT (mts->display_main)->vadjustment, "value_changed", - G_CALLBACK (e_meeting_time_selector_vadjustment_changed), mts); - g_signal_connect (GTK_LAYOUT (mts->display_main)->vadjustment, "changed", - G_CALLBACK (e_meeting_time_selector_vadjustment_changed), mts); - - g_signal_connect (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (mts->etable)), "value_changed", - G_CALLBACK (e_meeting_time_selector_table_vadjustment_changed), mts); - g_signal_connect (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (mts->etable)), "changed", - G_CALLBACK (e_meeting_time_selector_table_vadjustment_changed), mts); - - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_ensure_meeting_time_shown (mts); - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - e_meeting_time_selector_update_date_popup_menus (mts); - - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); -} - - -/* This adds a color to the color key beneath the main display. If color is - NULL, it displays the No Info stipple instead. */ -static void -e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, GdkColor *color) -{ - GtkWidget *child_hbox, *darea, *label; - - child_hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), child_hbox, TRUE, TRUE, 0); - gtk_widget_show (child_hbox); - - darea = gtk_drawing_area_new (); - gtk_box_pack_start (GTK_BOX (child_hbox), darea, FALSE, FALSE, 0); - gtk_object_set_user_data (GTK_OBJECT (darea), mts); - gtk_widget_set_usize (darea, 14, 14); - gtk_widget_show (darea); - - label = gtk_label_new (label_text); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 6); - gtk_widget_show (label); - - g_signal_connect (darea, "expose_event", - G_CALLBACK (e_meeting_time_selector_expose_key_color), - color); -} - -static gint -e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color) -{ - EMeetingTimeSelector * mts; - GdkGC *gc; - gint width, height; - - mts = gtk_object_get_user_data (GTK_OBJECT (darea)); - gc = mts->color_key_gc; - width = darea->allocation.width; - height = darea->allocation.height; - - gtk_draw_shadow (darea->style, darea->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, 0, 0, width, height); - - if (color) { - gdk_gc_set_foreground (gc, color); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - } else { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_background (gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (gc, mts->stipple); - gdk_gc_set_fill (gc, GDK_OPAQUE_STIPPLED); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - gdk_gc_set_fill (gc, GDK_SOLID); - } - - return TRUE; -} - - -static void -e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c) -{ - GdkColormap *colormap; - - g_return_if_fail (name != NULL); - g_return_if_fail (c != NULL); - - gdk_color_parse (name, c); - colormap = gtk_widget_get_colormap (GTK_WIDGET (mts)); - if (!gdk_colormap_alloc_color (colormap, c, TRUE, TRUE)) - g_warning ("Failed to allocate color: %s\n", name); -} - - -static void -e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->options_menu == (GtkWidget*) menu); - - mts->options_menu = NULL; -} - - -static void -e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->autopick_menu == (GtkWidget*) menu); - - mts->autopick_menu = NULL; -} - - -GtkWidget * -e_meeting_time_selector_new (EMeetingModel *emm) -{ - GtkWidget *mts; - - mts = GTK_WIDGET (g_object_new (e_meeting_time_selector_get_type (), NULL)); - - e_meeting_time_selector_construct (E_MEETING_TIME_SELECTOR (mts), emm); - - return mts; -} - - -static void -e_meeting_time_selector_destroy (GtkObject *object) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (object); - - e_meeting_time_selector_remove_timeout (mts); - - if (mts->stipple) { - gdk_bitmap_unref (mts->stipple); - mts->stipple = NULL; - } - - if (mts->model) { - g_object_unref (mts->model); - mts->model = NULL; - } - - mts->display_top = NULL; - mts->display_main = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (*GTK_OBJECT_CLASS (parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_realize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (*GTK_WIDGET_CLASS (parent_class)->realize)(widget); - - mts = E_MEETING_TIME_SELECTOR (widget); - - mts->color_key_gc = gdk_gc_new (widget->window); -} - - -static void -e_meeting_time_selector_unrealize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - gdk_gc_unref (mts->color_key_gc); - mts->color_key_gc = NULL; - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget); -} - -static void -e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EMeetingTimeSelector *mts; - EMeetingTime saved_time; - ETable *real_table; - ETableHeader *eth; - int hour, max_hour_width; - int numcols, col; - int maxheight; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - (*GTK_WIDGET_CLASS (parent_class)->style_set)(widget, previous_style); - - mts = E_MEETING_TIME_SELECTOR (widget); - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (widget)->font_desc; - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - layout = pango_layout_new (pango_context); - - /* Calculate the widths of the hour strings in the style's font. */ - max_hour_width = 0; - for (hour = 0; hour < 24; hour++) { - if (calendar_config_get_24_hour_format ()) - pango_layout_set_text (layout, EMeetingTimeSelectorHours [hour], -1); - else - pango_layout_set_text (layout, EMeetingTimeSelectorHours12 [hour], -1); - - pango_layout_get_pixel_size (layout, &mts->hour_widths [hour], NULL); - max_hour_width = MAX (max_hour_width, mts->hour_widths[hour]); - } - - /* FIXME the 5 is for the padding etable adds on */ - mts->row_height = - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + 5; - mts->col_width = max_hour_width + 6; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_set_usize (mts->display_top, -1, mts->row_height * 3); - - /* Calculate header height */ - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); - eth = real_table->full_header; - numcols = e_table_header_count (eth); - maxheight = 0; - for (col = 0; col < numcols; col++) { - ETableCol *ecol = e_table_header_get_column (eth, col); - int height; - - height = e_table_header_compute_height (ecol, widget); - - if (height > maxheight) - maxheight = height; - } - /* FIXME the 5 is for the padding etable adds on */ - gtk_widget_set_usize (mts->attendees_vbox_spacer, 1, mts->row_height * 3 - maxheight - 5); - - GTK_LAYOUT (mts->display_main)->hadjustment->step_increment = mts->col_width; - GTK_LAYOUT (mts->display_main)->vadjustment->step_increment = mts->row_height; - - g_object_unref (layout); - pango_font_metrics_unref (font_metrics); -} - -/* This draws a shadow around the top display and main display. */ -static gint -e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - e_meeting_time_selector_draw_shadow (mts); - - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (*GTK_WIDGET_CLASS (parent_class)->expose_event)(widget, event); - - return FALSE; -} - -static void -e_meeting_time_selector_draw_shadow (EMeetingTimeSelector *mts) -{ - GtkWidget *widget; - gint x, y, w, h; - - widget = GTK_WIDGET (mts); - - /* Draw the shadow around the graphical displays. */ - x = mts->display_top->allocation.x - 2; - y = mts->display_top->allocation.y - 2; - w = mts->display_top->allocation.width + 4; - h = mts->display_top->allocation.height + mts->display_main->allocation.height + 4; - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, x, y, w, h); -} - - -/* When the main canvas scrolls, we scroll the other canvases. */ -static void -e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->display_top)->hadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_adjustment_value_changed (adj); - } -} - - -static void -e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (mts->etable)); - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_adjustment_value_changed (adj); - } -} - -static void -e_meeting_time_selector_table_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->display_main)->vadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_adjustment_value_changed (adj); - } -} - - -void -e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute) -{ - *start_year = g_date_year (&mts->meeting_start_time.date); - *start_month = g_date_month (&mts->meeting_start_time.date); - *start_day = g_date_day (&mts->meeting_start_time.date); - *start_hour = mts->meeting_start_time.hour; - *start_minute = mts->meeting_start_time.minute; - - *end_year = g_date_year (&mts->meeting_end_time.date); - *end_month = g_date_month (&mts->meeting_end_time.date); - *end_day = g_date_day (&mts->meeting_end_time.date); - *end_hour = mts->meeting_end_time.hour; - *end_minute = mts->meeting_end_time.minute; -} - - -gboolean -e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute) -{ - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year) - || !g_date_valid_dmy (end_day, end_month, end_year) - || start_hour < 0 || start_hour > 23 - || end_hour < 0 || end_hour > 23 - || start_minute < 0 || start_minute > 59 - || end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_set_dmy (&mts->meeting_start_time.date, start_day, start_month, - start_year); - mts->meeting_start_time.hour = start_hour; - mts->meeting_start_time.minute = start_minute; - g_date_set_dmy (&mts->meeting_end_time.date, end_day, end_month, - end_year); - mts->meeting_end_time.hour = end_hour; - mts->meeting_end_time.minute = end_minute; - - mts->meeting_positions_valid = FALSE; - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the EDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); - - return TRUE; -} - -void -e_meeting_time_selector_set_all_day (EMeetingTimeSelector *mts, - gboolean all_day) -{ - EMeetingTime saved_time; - - mts->all_day = all_day; - - e_date_edit_set_show_time (E_DATE_EDIT (mts->start_date_edit), - !all_day); - e_date_edit_set_show_time (E_DATE_EDIT (mts->end_date_edit), - !all_day); - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only) -{ - EMeetingTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->working_hours_only == working_hours_only) - return; - - mts->working_hours_only = working_hours_only; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute) -{ - EMeetingTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->day_start_hour == day_start_hour - && mts->day_start_minute == day_start_minute - && mts->day_end_hour == day_end_hour - && mts->day_end_minute == day_end_minute) - return; - - mts->day_start_hour = day_start_hour; - mts->day_start_minute = day_start_minute; - - /* Make sure we always show atleast an hour */ - if (day_start_hour * 60 + day_start_minute + 60 < day_end_hour * 60 + day_end_minute) { - mts->day_end_hour = day_end_hour; - mts->day_end_minute = day_end_minute; - } else { - mts->day_end_hour = day_start_hour + 1; - mts->day_end_minute = day_start_minute; - } - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out) -{ - EMeetingTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->zoomed_out == zoomed_out) - return; - - mts->zoomed_out = zoomed_out; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - -static void -e_meeting_time_selector_refresh_cb (gpointer data) -{ - EMeetingTimeSelector *mts = data; - - if (mts->display_top != NULL) - gtk_widget_queue_draw (mts->display_top); - if (mts->display_main != NULL) - gtk_widget_queue_draw (mts->display_main); - - gtk_object_unref (GTK_OBJECT (mts)); -} - -static void -e_meeting_time_selector_refresh_free_busy (EMeetingTimeSelector *mts, int row, gboolean all) -{ - EMeetingTime start, end; - - start = mts->meeting_start_time; - g_date_subtract_days (&start.date, E_MEETING_TIME_SELECTOR_FB_DAYS_BEFORE); - start.hour = 0; - start.minute = 0; - end = mts->meeting_end_time; - g_date_add_days (&end.date, E_MEETING_TIME_SELECTOR_FB_DAYS_AFTER); - end.hour = 0; - end.minute = 0; - - /* Ref ourselves in case we are called back after destruction, - * we can do this because we will get a call back even after - * an error */ - gtk_object_ref (GTK_OBJECT (mts)); - - if (all) - e_meeting_model_refresh_all_busy_periods (mts->model, &start, &end, - e_meeting_time_selector_refresh_cb, mts); - else - e_meeting_model_refresh_busy_periods (mts->model, row, &start, &end, - e_meeting_time_selector_refresh_cb, mts); -} - -EMeetingTimeSelectorAutopickOption -e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts) -{ - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES; - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE; - if (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item)->active) - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE; - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE; -} - - -void -e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option) -{ - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - switch (autopick_option) { - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_one_resource_item), TRUE); - break; - } -} -#if 0 -void -e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->send_meeting_to = send_meeting_to; -} -#endif - -/* - * DEBUGGING ROUTINES - functions to output various bits of data. - */ - -#ifdef E_MEETING_TIME_SELECTOR_DEBUG - -/* Debugging function to dump information on all attendees. */ -void -e_meeting_time_selector_dump (EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - gint row, period_num; - gchar buffer[128]; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - g_print ("\n\nAttendee Information:\n"); - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_print ("Attendee: %s\n", attendee->name); - g_print (" Longest Busy Period: %i days\n", - attendee->longest_period_in_days); - - e_meeting_time_selector_attendee_ensure_periods_sorted (mts, attendee); -#if 1 - for (period_num = 0; - period_num < attendee->busy_periods->len; - period_num++) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, - period_num); - - /* These are just for debugging so don't need i18n. */ - g_date_strftime (buffer, sizeof (buffer), - "%A, %B %d, %Y", &period->start.date); - g_print (" Start: %s %i:%02i\n", buffer, - period->start.hour, period->start.minute); - - g_date_strftime (buffer, sizeof (buffer), - "%A, %B %d, %Y", &period->end.date); - g_print (" End : %s %i:%02i\n", buffer, - period->end.hour, period->end.minute); - } -#endif - } - -} - - -/* This formats a EMeetingTimein a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_time (EMeetingTime*mtstime) -{ - static gchar buffer[128]; - - gchar buffer2[128]; - - /* This is just for debugging so doesn't need i18n. */ - g_date_strftime (buffer, sizeof (buffer), "%A, %B %d, %Y", - &mtstime->date); - sprintf (buffer2, " at %i:%02i", (gint) mtstime->hour, - (gint) mtstime->minute); - strcat (buffer, buffer2); - - return buffer; -} - - -/* This formats a GDate in a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_date (GDate *date) -{ - static gchar buffer[128]; - - /* This is just for debugging so doesn't need i18n. */ - g_date_strftime (buffer, sizeof (buffer), "%A, %B %d, %Y", date); - return buffer; -} - -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -static gboolean -e_meeting_time_selector_on_invite_others_button_expose (GtkWidget *button, - GdkEventExpose *event, - EMeetingTimeSelector *mts) -{ - ETable *real_table; - gboolean click_to_add = TRUE; - - real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (mts->etable)); - g_object_get (G_OBJECT (real_table), "use_click_to_add", &click_to_add, NULL); - - gtk_widget_set_sensitive (button, click_to_add); - return FALSE; -} - -static void -e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_model_invite_others_dialog (mts->model); -} - - -static void -e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->options_menu), NULL, NULL, - e_meeting_time_selector_options_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->options_button->window, x, y); - *x += mts->options_button->allocation.x; - *y += mts->options_button->allocation.y + mts->options_button->allocation.height / 2 - 2; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->options_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - -static void -e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_refresh_free_busy (mts, 0, TRUE); -} - - -static void -e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->autopick_menu), NULL, NULL, - e_meeting_time_selector_autopick_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->autopick_button->window, x, y); - *x += mts->autopick_button->allocation.x; - *y += mts->autopick_button->allocation.y + mts->autopick_button->allocation.height / 2 - 2; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->autopick_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - - -static void -e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->autopick_menu)) - gtk_menu_popdown (GTK_MENU (mts->autopick_menu)); -} - - -static void -e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, FALSE); -} - - -static void -e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, TRUE); -} - - -/* This tries to find the previous or next meeting time for which all - attendees will be available. */ -static void -e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward) -{ - EMeetingTime start_time, end_time, *resource_free; - EMeetingAttendee *attendee; - EMeetingFreeBusyPeriod *period; - EMeetingTimeSelectorAutopickOption autopick_option; - gint duration_days, duration_hours, duration_minutes, row; - gboolean meeting_time_ok, skip_optional = FALSE; - gboolean need_one_resource = FALSE, found_resource; - - /* Get the current meeting duration in days + hours + minutes. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Find the first appropriate start time. */ - start_time = mts->meeting_start_time; - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - - /* Determine if we can skip optional people and if we only need one - resource based on the autopick option. */ - autopick_option = e_meeting_time_selector_get_autopick_option (mts); - if (autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - skip_optional = TRUE; - if (autopick_option == E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - need_one_resource = TRUE; - - /* Keep moving forward or backward until we find a possible meeting - time. */ - for (;;) { - meeting_time_ok = TRUE; - found_resource = FALSE; - resource_free = NULL; - - /* Step through each attendee, checking if the meeting time - intersects one of the attendees busy periods. */ - for (row = 0; row < e_meeting_model_count_actual_attendees (mts->model); row++) { - attendee = e_meeting_model_find_attendee_at_row (mts->model, row); - - /* Skip optional people if they don't matter. */ - if (skip_optional && e_meeting_attendee_get_atype (attendee) == E_MEETING_ATTENDEE_OPTIONAL_PERSON) - continue; - - period = e_meeting_time_selector_find_time_clash (mts, attendee, &start_time, &end_time); - - if (need_one_resource && e_meeting_attendee_get_atype (attendee) == E_MEETING_ATTENDEE_RESOURCE) { - if (period) { - /* We want to remember the closest - prev/next time that one resource is - available, in case we don't find any - free resources. */ - if (forward) { - if (!resource_free || e_meeting_time_compare_times (resource_free, &period->end) > 0) - resource_free = &period->end; - } else { - if (!resource_free || e_meeting_time_compare_times (resource_free, &period->start) < 0) - resource_free = &period->start; - } - - } else { - found_resource = TRUE; - } - } else if (period) { - /* Skip the period which clashed. */ - if (forward) { - start_time = period->end; - } else { - start_time = period->start; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - break; - } - } - - /* Check that we found one resource if necessary. If not, skip - to the closest time that a resource is free. Note that if - there are no resources, resource_free will never get set, - so we assume the meeting time is OK. */ - if (meeting_time_ok && need_one_resource && !found_resource - && resource_free) { - if (forward) { - start_time = *resource_free; - } else { - start_time = *resource_free; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - } - - if (meeting_time_ok) { - mts->meeting_start_time = start_time; - mts->meeting_end_time = end_time; - mts->meeting_positions_valid = FALSE; - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Make sure the time is shown. */ - e_meeting_time_selector_ensure_meeting_time_shown (mts); - - /* Set the times in the EDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); - - return; - } - - /* Move forward to the next possible interval. */ - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - } -} - - -static void -e_meeting_time_selector_calculate_time_difference (EMeetingTime*start, - EMeetingTime*end, - gint *days, - gint *hours, - gint *minutes) -{ - *days = g_date_julian (&end->date) - g_date_julian (&start->date); - *hours = end->hour - start->hour; - *minutes = end->minute - start->minute; - if (*minutes < 0) { - *minutes += 60; - *hours = *hours - 1; - } - if (*hours < 0) { - *hours += 24; - *days = *days - 1; - } -} - - -/* This moves the given time forward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTime*start_time, - EMeetingTime*end_time, - gint days, gint hours, gint mins) -{ - gint minutes_shown; - gboolean set_to_start_of_working_day = FALSE; - - if (!mts->all_day) { - if (mts->zoomed_out) { - start_time->hour++; - start_time->minute = 0; - } else { - start_time->minute += 30; - start_time->minute -= start_time->minute % 30; - } - } else { - g_date_add_days (&start_time->date, 1); - start_time->hour = 0; - start_time->minute = 0; - } - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - onto the start of the next working day. If the meeting time starts - before the working day, move it on as well. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - g_date_add_days (&start_time->date, 1); - set_to_start_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - set_to_start_of_working_day = TRUE; - } - - if (set_to_start_of_working_day) { - start_time->hour = mts->day_start_hour; - start_time->minute = mts->day_start_minute; - - if (mts->zoomed_out) { - if (start_time->minute > 0) { - start_time->hour++; - start_time->minute = 0; - } - } else { - start_time->minute += 29; - start_time->minute -= start_time->minute % 30; - } - - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This moves the given time backward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTime*start_time, - EMeetingTime*end_time, - gint days, gint hours, gint mins) -{ - gint new_hour, minutes_shown; - gboolean set_to_end_of_working_day = FALSE; - - if (!mts->all_day) { - new_hour = start_time->hour; - if (mts->zoomed_out) { - if (start_time->minute == 0) - new_hour--; - start_time->minute = 0; - } else { - if (start_time->minute == 0) { - start_time->minute = 30; - new_hour--; - } else if (start_time->minute <= 30) - start_time->minute = 0; - else - start_time->minute = 30; - } - if (new_hour < 0) { - new_hour += 24; - g_date_subtract_days (&start_time->date, 1); - } - start_time->hour = new_hour; - } else { - g_date_subtract_days (&start_time->date, 1); - start_time->hour = 0; - start_time->minute = 0; - } - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - back to the end of the working day. If the meeting time starts - before the working day, move it back to the end of the previous - working day. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - set_to_end_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - g_date_subtract_days (&end_time->date, 1); - set_to_end_of_working_day = TRUE; - } - - if (set_to_end_of_working_day) { - end_time->hour = mts->day_end_hour; - end_time->minute = mts->day_end_minute; - *start_time = *end_time; - e_meeting_time_selector_adjust_time (start_time, -days, -hours, -mins); - - if (mts->zoomed_out) { - start_time->minute = 0; - } else { - start_time->minute -= start_time->minute % 30; - } - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This adds on the given days, hours & minutes to a EMeetingTimeSelectorTime. - It is used to calculate the end of a period given a start & duration. - Days, hours & minutes can be negative, to move backwards, but they should - be within normal ranges, e.g. hours should be between -23 and 23. */ -static void -e_meeting_time_selector_adjust_time (EMeetingTime*mtstime, - gint days, gint hours, gint minutes) -{ - gint new_hours, new_minutes; - - /* We have to handle negative values for hous and minutes here, since - EMeetingTimeuses guint8s to store them. */ - new_minutes = mtstime->minute + minutes; - if (new_minutes < 0) { - new_minutes += 60; - hours -= 1; - } - - new_hours = mtstime->hour + hours; - if (new_hours < 0) { - new_hours += 24; - days -= 1; - } - - g_date_add_days (&mtstime->date, days); - mtstime->hour = new_hours; - mtstime->minute = new_minutes; - - e_meeting_time_selector_fix_time_overflows (mtstime); -} - - -/* This looks for any busy period of the given attendee which clashes with - the start and end time. It uses a binary search. */ -static EMeetingFreeBusyPeriod * -e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingAttendee *attendee, - EMeetingTime*start_time, - EMeetingTime*end_time) -{ - EMeetingFreeBusyPeriod *period; - const GArray *busy_periods; - gint period_num; - - busy_periods = e_meeting_attendee_get_busy_periods (attendee); - period_num = e_meeting_attendee_find_first_busy_period (attendee, &start_time->date); - - if (period_num == -1) - return NULL; - - /* Step forward through the busy periods until we find a clash or we - go past the end_time. */ - while (period_num < busy_periods->len) { - period = &g_array_index (busy_periods, EMeetingFreeBusyPeriod, period_num); - - /* If the period starts at or after the end time, there is no - clash and we are finished. The busy periods are sorted by - their start times, so all the rest will be later. */ - if (e_meeting_time_compare_times (&period->start, end_time) >= 0) - return NULL; - - /* If the period ends after the start time, we have found a - clash. From the above test we already know the busy period - isn't completely after the meeting time. */ - if (e_meeting_time_compare_times (&period->end, start_time) > 0) - return period; - - period_num++; - } - - return NULL; -} - -static void -e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_zoomed_out (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -static void -e_meeting_time_selector_on_working_hours_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_working_hours_only (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -/* This recalculates day_width, first_hour_shown and last_hour_shown. */ -static void -e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts) -{ - if (mts->working_hours_only) { - mts->first_hour_shown = mts->day_start_hour; - mts->last_hour_shown = mts->day_end_hour; - if (mts->day_end_minute != 0) - mts->last_hour_shown += 1; - } else { - mts->first_hour_shown = 0; - mts->last_hour_shown = 24; - } - - /* In the brief view we use the nearest hours divisible by 3. */ - if (mts->zoomed_out) { - mts->first_hour_shown -= mts->first_hour_shown % 3; - mts->last_hour_shown += 2; - mts->last_hour_shown -= mts->last_hour_shown % 3; - } - - mts->day_width = mts->col_width * (mts->last_hour_shown - mts->first_hour_shown); - if (mts->zoomed_out) - mts->day_width /= 3; - - /* Add one pixel for the extra vertical grid line. */ - mts->day_width++; - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_recalc_date_format (mts); - mts->meeting_positions_valid = FALSE; -} - - -/* This saves the first visible time in the given EMeetingTimeSelectorTime. */ -static void -e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTime*mtstime) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - e_meeting_time_selector_calculate_time (mts, scroll_x, mtstime); -} - - -/* This restores a saved position. */ -static void -e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTime*mtstime) -{ - gint scroll_x, scroll_y, new_scroll_x; - - new_scroll_x = e_meeting_time_selector_calculate_time_position (mts, - mtstime); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This returns the x pixel coords of the meeting time in the entire scroll - region. It recalculates them if they have been marked as invalid. - If it returns FALSE then no meeting time is set or the meeting time is - not visible in the current scroll area. */ -gboolean -e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x) -{ - if (mts->meeting_positions_valid) { - if (mts->meeting_positions_in_scroll_area) { - *start_x = mts->meeting_start_x; - *end_x = mts->meeting_end_x; - return TRUE; - } else { - return FALSE; - } - } - - mts->meeting_positions_valid = TRUE; - - /* Check if the days aren't in our current range. */ - if (g_date_compare (&mts->meeting_start_time.date, &mts->last_date_shown) > 0 - || g_date_compare (&mts->meeting_end_time.date, &mts->first_date_shown) < 0) { - mts->meeting_positions_in_scroll_area = FALSE; - return FALSE; - } - - mts->meeting_positions_in_scroll_area = TRUE; - *start_x = mts->meeting_start_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_start_time); - *end_x = mts->meeting_end_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_end_time); - - return TRUE; -} - - -/* This recalculates the date format to used, by computing the width of the - longest date strings in the widget's font and seeing if they fit. */ -static void -e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts) -{ - /* An array of dates, one for each month in the year 2000. They must - all be Sundays. */ - static const int days[12] = { 23, 20, 19, 23, 21, 18, - 23, 20, 17, 22, 19, 24 }; - GDate date; - gint max_date_width, longest_weekday_width, longest_month_width, width; - gint day, longest_weekday, month, longest_month; - gchar buffer[128]; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoLayout *layout; - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (GTK_WIDGET (mts))->font_desc; - pango_context = gtk_widget_get_pango_context (GTK_WIDGET (mts)); - layout = pango_layout_new (pango_context); - - /* Calculate the maximum date width we can fit into the display. */ - max_date_width = mts->day_width - 2; - - /* Find the biggest full weekday name. We start on a particular - Monday and go through seven days. */ - g_date_clear (&date, 1); - g_date_set_dmy (&date, 3, 1, 2000); /* Monday 3rd Jan 2000. */ - longest_weekday_width = 0; - longest_weekday = G_DATE_MONDAY; - for (day = G_DATE_MONDAY; day <= G_DATE_SUNDAY; day++) { - g_date_strftime (buffer, sizeof (buffer), "%A", &date); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - if (width > longest_weekday_width) { - longest_weekday = day; - longest_weekday_width = width; - } - g_date_add_days (&date, 1); - } - - /* Now find the biggest month name. */ - longest_month_width = 0; - longest_month = G_DATE_JANUARY; - for (month = G_DATE_JANUARY; month <= G_DATE_DECEMBER; month++) { - g_date_set_month (&date, month); - g_date_strftime (buffer, sizeof (buffer), "%B", &date); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - if (width > longest_month_width) { - longest_month = month; - longest_month_width = width; - } - } - - /* See if we can use the full date. We want to use a date with a - month day > 20 and also the longest weekday. We use a - pre-calculated array of days for each month and add on the - weekday (which is 1 (Mon) to 7 (Sun). */ - g_date_set_dmy (&date, days[longest_month - 1] + longest_weekday, - longest_month, 2000); - /* This is a strftime() format string %A = full weekday name, - %B = full month name, %d = month day, %Y = full year. */ - g_date_strftime (buffer, sizeof (buffer), _("%A, %B %d, %Y"), &date); - -#if 0 - g_print ("longest_month: %i longest_weekday: %i date: %s\n", - longest_month, longest_weekday, buffer); -#endif - - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - if (width < max_date_width) { - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_FULL; - return; - } - - /* Now try it with abbreviated weekday names. */ - longest_weekday_width = 0; - longest_weekday = G_DATE_MONDAY; - g_date_set_dmy (&date, 3, 1, 2000); /* Monday 3rd Jan 2000. */ - for (day = G_DATE_MONDAY; day <= G_DATE_SUNDAY; day++) { - g_date_strftime (buffer, sizeof (buffer), "%a", &date); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - if (width > longest_weekday_width) { - longest_weekday = day; - longest_weekday_width = width; - } - g_date_add_days (&date, 1); - } - - g_date_set_dmy (&date, days[longest_month - 1] + longest_weekday, - longest_month, 2000); - /* This is a strftime() format string %a = abbreviated weekday name, - %m = month number, %d = month day, %Y = full year. */ - g_date_strftime (buffer, sizeof (buffer), _("%a %m/%d/%Y"), &date); - -#if 0 - g_print ("longest_month: %i longest_weekday: %i date: %s\n", - longest_month, longest_weekday, buffer); -#endif - - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - if (width < max_date_width) - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY; - else - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_SHORT; - - g_object_unref (layout); -} - - -/* Turn off the background of the canvas windows. This reduces flicker - considerably when scrolling. (Why isn't it in GnomeCanvas?). */ -static void -e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, - NULL, FALSE); -} - - -/* This is called when the meeting start time GnomeDateEdit is changed, - either via the "date_changed". "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gint duration_days, duration_hours, duration_minutes; - EMeetingTime mtstime; - gint hour = 0, minute = 0; - time_t newtime; - - /* Date */ - newtime = e_date_edit_get_time (E_DATE_EDIT (mts->start_date_edit)); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - - /* Time */ - e_date_edit_get_time_of_day (E_DATE_EDIT (mts->start_date_edit), &hour, &minute); - mtstime.hour = hour; - mtstime.minute = minute; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_compare_times (&mtstime, &mts->meeting_start_time) == 0) - return; - - /* Calculate the current meeting duration. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Set the new start time. */ - mts->meeting_start_time = mtstime; - - /* Update the end time so the meeting duration stays the same. */ - mts->meeting_end_time = mts->meeting_start_time; - e_meeting_time_selector_adjust_time (&mts->meeting_end_time, duration_days, duration_hours, duration_minutes); - e_meeting_time_selector_update_end_date_edit (mts); - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); -} - - -/* This is called when the meeting end time GnomeDateEdit is changed, - either via the "date_changed", "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - EMeetingTime mtstime; - gint hour = 0, minute = 0; - time_t newtime; - - /* Date */ - newtime = e_date_edit_get_time (E_DATE_EDIT (mts->end_date_edit)); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - if (mts->all_day) - g_date_add_days (&mtstime.date, 1); - - /* Time */ - e_date_edit_get_time_of_day (E_DATE_EDIT (mts->end_date_edit), &hour, &minute); - mtstime.hour = hour; - mtstime.minute = minute; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_compare_times (&mtstime, &mts->meeting_end_time) == 0) - return; - - /* Set the new end time. */ - mts->meeting_end_time = mtstime; - - /* If the start time is after the end time, set it to the same time. */ - if (e_meeting_time_compare_times (&mtstime, &mts->meeting_start_time) <= 0) { - /* We set it first, before updating the widget, so the signal - handler will just return. */ - mts->meeting_start_time = mtstime; - if (mts->all_day) - g_date_subtract_days (&mts->meeting_start_time.date, 1); - e_meeting_time_selector_update_start_date_edit (mts); - } - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); -} - - -/* This updates the ranges shown in the GnomeDateEdit popup menus, according - to working_hours_only etc. */ -static void -e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts) -{ - EDateEdit *start_edit, *end_edit; - gint low_hour, high_hour; - - start_edit = E_DATE_EDIT (mts->start_date_edit); - end_edit = E_DATE_EDIT (mts->end_date_edit); - - if (mts->working_hours_only) { - low_hour = mts->day_start_hour; - high_hour = mts->day_end_hour; - } else { - low_hour = 0; - high_hour = 23; - } - - e_date_edit_set_time_popup_range (start_edit, low_hour, high_hour); - e_date_edit_set_time_popup_range (end_edit, low_hour, high_hour); -} - - -static void -e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_ensure_meeting_time_shown (mts); -} - -/* This updates the canvas scroll regions according to the number of attendees. - If the total height needed is less than the height of the canvas, we must - use the height of the canvas, or it causes problems. */ -static void -e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts) -{ - gint height, canvas_height; - - height = mts->row_height * (e_meeting_model_count_actual_attendees (mts->model) + 2); - canvas_height = GTK_WIDGET (mts->display_main)->allocation.height; - - height = MAX (height, canvas_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_main), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - height); -} - - -/* This changes the meeting time based on the given x coordinate and whether - we are dragging the start or end bar. It returns the new position, which - will be swapped if the start bar is dragged past the end bar or vice versa. - It make sure the meeting time is never dragged outside the visible canvas - area. */ -void -e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x) -{ - EMeetingTime first_time, last_time, drag_time, *time_to_set; - gint scroll_x, scroll_y, canvas_width; - gboolean set_both_times = FALSE; - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Save the x coordinate for the timeout handler. */ - mts->last_drag_x = (x < scroll_x) ? x - scroll_x - : x - scroll_x - canvas_width + 1; - - /* Check if the mouse is off the edge of the canvas. */ - if (x < scroll_x || x > scroll_x + canvas_width) { - /* If we haven't added a timeout function, add one. */ - if (mts->auto_scroll_timeout_id == 0) { - mts->auto_scroll_timeout_id = g_timeout_add (60, e_meeting_time_selector_timeout_handler, mts); - mts->scroll_count = 0; - - /* Call the handler to start scrolling now. */ - e_meeting_time_selector_timeout_handler (mts); - return; - } - } else { - e_meeting_time_selector_remove_timeout (mts); - } - - /* Calculate the minimum & maximum times we can use, based on the - scroll offsets and whether zoomed_out is set. */ - e_meeting_time_selector_calculate_time (mts, scroll_x, &first_time); - e_meeting_time_selector_calculate_time (mts, scroll_x + canvas_width - 1, - &last_time); - if (!mts->all_day) { - if (mts->zoomed_out) { - if (first_time.minute > 30) - first_time.hour++; - first_time.minute = 0; - last_time.minute = 0; - } else { - first_time.minute += 15; - first_time.minute -= first_time.minute % 30; - last_time.minute -= last_time.minute % 30; - } - } else { - if (first_time.hour > 0 || first_time.minute > 0) - g_date_add_days (&first_time.date, 1); - first_time.hour = 0; - first_time.minute = 0; - last_time.hour = 0; - last_time.minute = 0; - } - e_meeting_time_selector_fix_time_overflows (&first_time); - e_meeting_time_selector_fix_time_overflows (&last_time); - - /* Calculate the time from x coordinate. */ - e_meeting_time_selector_calculate_time (mts, x, &drag_time); - - /* Calculate the nearest half-hour or hour, depending on whether - zoomed_out is set. */ - if (!mts->all_day) { - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - } else { - if (drag_time.hour > 12) - g_date_add_days (&drag_time.date, 1); - drag_time.hour = 0; - drag_time.minute = 0; - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Now make sure we are between first_time & last_time. */ - if (e_meeting_time_compare_times (&drag_time, &first_time) < 0) - drag_time = first_time; - if (e_meeting_time_compare_times (&drag_time, &last_time) > 0) - drag_time = last_time; - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_compare_times (time_to_set, &drag_time) == 0) - return; - - /* Don't let an empty occur for all day events */ - if (mts->all_day - && mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START - && e_meeting_time_compare_times (&mts->meeting_end_time, &drag_time) == 0) - return; - else if (mts->all_day - && mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END - && e_meeting_time_compare_times (&mts->meeting_start_time, &drag_time) == 0) - return; - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_compare_times (&mts->meeting_start_time, - &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Redraw the canvases. */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); -} - - -/* This is the timeout function which handles auto-scrolling when the user is - dragging one of the meeting time vertical bars outside the left or right - edge of the canvas. */ -static gboolean -e_meeting_time_selector_timeout_handler (gpointer data) -{ - EMeetingTimeSelector *mts; - EMeetingTime drag_time, *time_to_set; - gint scroll_x, max_scroll_x, scroll_y, canvas_width; - gint scroll_speed, scroll_offset; - gboolean set_both_times = FALSE; - - mts = E_MEETING_TIME_SELECTOR (data); - - GDK_THREADS_ENTER (); - - /* Return if we don't need to scroll yet. */ - if (mts->scroll_count-- > 0) { - GDK_THREADS_LEAVE (); - return TRUE; - } - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Calculate the scroll delay, between 0 and MAX_SCROLL_SPEED. */ - scroll_speed = abs (mts->last_drag_x / E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH); - scroll_speed = MIN (scroll_speed, - E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED); - - /* Reset the scroll count. */ - mts->scroll_count = E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED - scroll_speed; - - /* Calculate how much we need to scroll. */ - if (mts->last_drag_x >= 0) - scroll_offset = mts->col_width; - else - scroll_offset = -mts->col_width; - - scroll_x += scroll_offset; - max_scroll_x = (mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN) - - canvas_width; - scroll_x = CLAMP (scroll_x, 0, max_scroll_x); - - /* Calculate the minimum or maximum visible time in the canvas, which - we will now set the dragged time to. */ - if (scroll_offset > 0) { - e_meeting_time_selector_calculate_time (mts, - scroll_x + canvas_width - 1, - &drag_time); - if (!mts->all_day) { - if (mts->zoomed_out) { - drag_time.minute = 0; - } else { - drag_time.minute -= drag_time.minute % 30; - } - } else { - drag_time.hour = 0; - drag_time.minute = 0; - } - } else { - e_meeting_time_selector_calculate_time (mts, scroll_x, - &drag_time); - if (!mts->all_day) { - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - } else { - if (drag_time.hour > 0 || drag_time.minute > 0) - g_date_add_days (&drag_time.date, 1); - drag_time.hour = 0; - drag_time.minute = 0; - } - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_compare_times (time_to_set, &drag_time) == 0) { - GDK_THREADS_LEAVE (); - goto scroll; - } - - /* Don't let an empty occur for all day events */ - if (mts->all_day - && mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START - && e_meeting_time_compare_times (&mts->meeting_end_time, &drag_time) == 0) - goto scroll; - else if (mts->all_day - && mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END - && e_meeting_time_compare_times (&mts->meeting_start_time, &drag_time) == 0) - goto scroll; - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_compare_times (&mts->meeting_start_time, &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - gtk_signal_emit (GTK_OBJECT (mts), mts_signals [CHANGED]); - - scroll: - /* Redraw the canvases. We freeze and thaw the layouts so that they - get redrawn completely. Otherwise the pixels get scrolled left or - right which is not good for us (since our vertical bars have been - moved) and causes flicker. */ - gtk_layout_freeze (GTK_LAYOUT (mts->display_main)); - gtk_layout_freeze (GTK_LAYOUT (mts->display_top)); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - scroll_x, scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_top), - scroll_x, scroll_y); - gtk_layout_thaw (GTK_LAYOUT (mts->display_main)); - gtk_layout_thaw (GTK_LAYOUT (mts->display_top)); - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -/* This removes our auto-scroll timeout function, if we have one installed. */ -void -e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts) -{ - if (mts->auto_scroll_timeout_id) { - g_source_remove (mts->auto_scroll_timeout_id); - mts->auto_scroll_timeout_id = 0; - } -} - - -/* This updates the GnomeDateEdit widget displaying the meeting start time. */ -static void -e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts) -{ - e_date_edit_set_date_and_time_of_day (E_DATE_EDIT (mts->start_date_edit), - g_date_year (&mts->meeting_start_time.date), - g_date_month (&mts->meeting_start_time.date), - g_date_day (&mts->meeting_start_time.date), - mts->meeting_start_time.hour, - mts->meeting_start_time.minute); -} - - -/* This updates the GnomeDateEdit widget displaying the meeting end time. */ -static void -e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts) -{ - GDate date; - - date = mts->meeting_end_time.date; - if (mts->all_day) - g_date_subtract_days (&date, 1); - - e_date_edit_set_date_and_time_of_day (E_DATE_EDIT (mts->end_date_edit), - g_date_year (&date), - g_date_month (&date), - g_date_day (&date), - mts->meeting_end_time.hour, - mts->meeting_end_time.minute); -} - - -/* This ensures that the meeting time is shown on screen, by scrolling the - canvas and possibly by changing the range of dates shown in the canvas. */ -static void -e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts) -{ - gint start_x, end_x, scroll_x, scroll_y, canvas_width; - gint new_scroll_x; - gboolean fits_in_canvas; - - /* Check if we need to change the range of dates shown. */ - if (g_date_compare (&mts->meeting_start_time.date, - &mts->first_date_shown) < 0 - || g_date_compare (&mts->meeting_end_time.date, - &mts->last_date_shown) > 0) { - e_meeting_time_selector_update_dates_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - } - - /* If all of the meeting time is visible, just return. */ - e_meeting_time_selector_get_meeting_time_positions (mts, &start_x, - &end_x); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - if (start_x > scroll_x && end_x <= scroll_x + canvas_width) - return; - - fits_in_canvas = end_x - start_x < canvas_width ? TRUE : FALSE; - - /* If the meeting is not entirely visible, either center it if it is - smaller than the canvas, or show the start of it if it is big. */ - if (fits_in_canvas) { - new_scroll_x = (start_x + end_x - canvas_width) / 2; - } else { - new_scroll_x = start_x; - } - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This updates the range of dates shown in the canvas, to make sure that the - currently selected meeting time is in the range. */ -static void -e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts) -{ - mts->first_date_shown = mts->meeting_start_time.date; - g_date_subtract_days (&mts->first_date_shown, - E_MEETING_TIME_SELECTOR_DAYS_START_BEFORE); - - mts->last_date_shown = mts->first_date_shown; - g_date_add_days (&mts->last_date_shown, - E_MEETING_TIME_SELECTOR_DAYS_SHOWN - 1); -} - - -/* This checks if the time's hour is over 24 or its minute is over 60 and if - so it updates the day/hour appropriately. Note that hours and minutes are - stored in guint8's so they can't overflow by much. */ -void -e_meeting_time_selector_fix_time_overflows (EMeetingTime*mtstime) -{ - gint hours_to_add, days_to_add; - - hours_to_add = mtstime->minute / 60; - if (hours_to_add > 0) { - mtstime->minute -= hours_to_add * 60; - mtstime->hour += hours_to_add; - } - - days_to_add = mtstime->hour / 24; - if (days_to_add > 0) { - mtstime->hour -= days_to_add * 24; - g_date_add_days (&mtstime->date, days_to_add); - } -} - -/* - * CONVERSION ROUTINES - functions to convert between different coordinate - * spaces and dates. - */ - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the date in which it falls. If day_position is not NULL it also - returns the x coordinate within the date, relative to the visible part of - the canvas. It is used when painting the days in the item_draw function. - Note that it must handle negative x coordinates in case we are dragging off - the edge of the canvas. */ -void -e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position) -{ - gint days_from_first_shown; - - *date = mts->first_date_shown; - - if (x >= 0) { - days_from_first_shown = x / mts->day_width; - g_date_add_days (date, days_from_first_shown); - if (day_position) - *day_position = - x % mts->day_width; - } else { - days_from_first_shown = -x / mts->day_width + 1; - g_date_subtract_days (date, days_from_first_shown); - if (day_position) - *day_position = -mts->day_width - x % mts->day_width; - } -} - - -/* This takes an x pixel coordinate within a day, and converts it to hours - and minutes, depending on working_hours_only and zoomed_out. */ -void -e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes) -{ - if (mts->zoomed_out) - day_position *= 3; - - /* Calculate the hours & minutes from the first displayed. */ - *hours = day_position / mts->col_width; - *minutes = (day_position % mts->col_width) * 60 / mts->col_width; - - /* Now add on the first hour shown. */ - *hours += mts->first_hour_shown; -} - - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the time in which it falls. Note that it won't be extremely - accurate since hours may only be a few pixels wide in the display. - With zoomed_out set each pixel may represent 5 minutes or more, depending - on how small the font is. */ -void -e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTime*time) -{ - gint day_position; - - /* First get the day and the x position within the day. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, &time->date, - NULL); - - /* Now convert the day_position into an hour and minute. */ - if (x >= 0) - day_position = x % mts->day_width; - else - day_position = mts->day_width + x % mts->day_width; - - e_meeting_time_selector_convert_day_position_to_hours_and_mins (mts, day_position, &time->hour, &time->minute); -} - - -/* This takes a EMeetingTime and calculates the x pixel coordinate - within the entire canvas scroll region. It is used to draw the selected - meeting time and all the busy periods. */ -gint -e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTime *mtstime) -{ - gint x, date_offset, day_offset; - - /* Calculate the number of days since the first date shown in the - entire canvas scroll region. */ - date_offset = g_date_julian (&mtstime->date) - g_date_julian (&mts->first_date_shown); - - /* Calculate the x pixel coordinate of the start of the day. */ - x = date_offset * mts->day_width; - - /* Add on the hours and minutes, depending on whether zoomed_out and - working_hours_only are set. */ - day_offset = (mtstime->hour - mts->first_hour_shown) * 60 - + mtstime->minute; - /* The day width includes an extra vertical grid line so subtract 1. */ - day_offset *= (mts->day_width - 1); - day_offset /= (mts->last_hour_shown - mts->first_hour_shown) * 60; - - /* Clamp the day_offset in case the time isn't actually visible. */ - x += CLAMP (day_offset, 0, mts->day_width); - - return x; -} - -static void -rows_inserted_cb (ETableModel *etm, int row, int count, gpointer data) -{ - EMeetingTimeSelector *mts = E_MEETING_TIME_SELECTOR (data); - int i; - - /* Update the scroll region. */ - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - /* Redraw */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Get the latest free/busy info */ - for (i = 0; i < count; i++) - e_meeting_time_selector_refresh_free_busy (mts, row + i, FALSE); -} - -static void -cell_changed_cb (ETableModel *etm, int col, int row, gpointer data) -{ - EMeetingTimeSelector *mts = E_MEETING_TIME_SELECTOR (data); - - if (col != E_MEETING_MODEL_ADDRESS_COL) - return; - - /* Get the latest free/busy info */ - e_meeting_time_selector_refresh_free_busy (mts, row, FALSE); -} - -static void -rows_deleted_cb (ETableModel *etm, int row, int count, gpointer data) -{ - EMeetingTimeSelector *mts = E_MEETING_TIME_SELECTOR (data); - - /* Update the scroll region. */ - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - /* Redraw */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - -static void -sort_info_changed_cb (ETableSortInfo *info, gpointer data) -{ - EMeetingTimeSelector *mts = E_MEETING_TIME_SELECTOR (data); - - /* Redraw */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} diff --git a/calendar/gui/e-meeting-time-sel.etspec b/calendar/gui/e-meeting-time-sel.etspec deleted file mode 100644 index c0b5c721dd..0000000000 --- a/calendar/gui/e-meeting-time-sel.etspec +++ /dev/null @@ -1,19 +0,0 @@ -<ETableSpecification click-to-add="true" click-to-add-end="true" _click-to-add-message="Click here to add an attendee" draw-grid="true"> - <ETableColumn model_col= "0" _title="Attendee" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "1" _title="Member" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "2" _title="Type" expansion="1.0" minimum_width="10" resizable="true" cell="typeedit" compare="string"/> - <ETableColumn model_col= "3" _title="Role" expansion="1.0" minimum_width="10" resizable="true" cell="roleedit" compare="string"/> - <ETableColumn model_col= "4" _title="RSVP" expansion="1.0" minimum_width="10" resizable="true" cell="rsvpedit" compare="string"/> - <ETableColumn model_col= "5" _title="Delegated To" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "6" _title="Delegated From" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "7" _title="Status" expansion="1.0" minimum_width="10" resizable="true" cell="statusedit" compare="string"/> - <ETableColumn model_col= "8" _title="Common Name" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - <ETableColumn model_col= "9" _title="Language" expansion="2.0" minimum_width="10" resizable="true" cell="string" compare="string"/> - - <ETableState> - <column source="0"/> - <column source="2"/> - <column source="7"/> - <grouping></grouping> - </ETableState> -</ETableSpecification> diff --git a/calendar/gui/e-meeting-time-sel.h b/calendar/gui/e-meeting-time-sel.h deleted file mode 100644 index cbfffb6a25..0000000000 --- a/calendar/gui/e-meeting-time-sel.h +++ /dev/null @@ -1,383 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_MEETING_TIME_SELECTOR_H_ -#define _E_MEETING_TIME_SELECTOR_H_ - -#include <glib.h> -#include <gtk/gtkaccelgroup.h> -#include <gtk/gtktable.h> -#include <gtk/gtkwidget.h> -#include <libgnomecanvas/gnome-canvas.h> -#include <gal/e-text/e-text.h> -#include <gal/e-table/e-table-model.h> -#include <gal/e-table/e-table.h> -#include "e-meeting-model.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EMeetingTimeSelector displays a list of attendees for a meeting and a - * graphical summary of the times which they are free and busy, allowing the - * user to select an appropriate time for a meeting. - */ - -/* Define this to include the debugging functions. */ -#undef E_MEETING_TIME_SELECTOR_DEBUG - -/* This is the width of the icon column in the attendees list. */ -#define E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH 24 - -#define E_MEETING_TIME_SELECTOR_TEXT_Y_PAD 3 -#define E_MEETING_TIME_SELECTOR_TEXT_X_PAD 2 - - -/* This is used to specify the format used when displaying the dates. - The full format is like 'Sunday, September 12, 1999'. The abbreviated format - is like 'Sun 12/9/99'. The short format is like '12/9/99'. The actual - format used is determined in e_meeting_time_selector_style_set(), once we - know the font being used. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_DATE_FULL, - E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY, - E_MEETING_TIME_SELECTOR_DATE_SHORT -} EMeetingTimeSelectorDateFormat; - - -/* This is used to specify a position regarding the vertical bars around the - current meeting time, so we know which one is being dragged. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_POS_NONE, - E_MEETING_TIME_SELECTOR_POS_START, - E_MEETING_TIME_SELECTOR_POS_END -} EMeetingTimeSelectorPosition; - - -/* This is used to specify the autopick option, which determines how we choose - the previous/next appropriate meeting time. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES, - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE -} EMeetingTimeSelectorAutopickOption; - -/* An array of hour strings for 24 hour time, "0:00" .. "23:00". */ -extern const gchar *EMeetingTimeSelectorHours[24]; -/* An array of hour strings for 12 hour time, "12:00am" .. "11:00pm". */ -extern const gchar *EMeetingTimeSelectorHours12[24]; - - -#define E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_CAST (obj, e_meeting_time_selector_get_type (), EMeetingTimeSelector) -#define E_MEETING_TIME_SELECTOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_meeting_time_selector_get_type (), EMeetingTimeSelectorClass) -#define IS_E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_TYPE (obj, e_meeting_time_selector_get_type ()) - - -typedef struct _EMeetingTimeSelector EMeetingTimeSelector; -typedef struct _EMeetingTimeSelectorClass EMeetingTimeSelectorClass; - -struct _EMeetingTimeSelector -{ - /* We subclass a GtkTable which makes it easy to add extra widgets - if neccesary. */ - GtkTable table; - - /* - * User Interface stuff - widgets, colors etc. - */ - - /* This contains our keyboard accelerators, which need to be added to - the toplevel window. */ - GtkAccelGroup *accel_group; - - /* The vbox in the top-left corner, containing the 'All Attendees' - title bar packed at the end. Extra widgets can be added here - with PACK_START if necessary. */ - GtkWidget *attendees_vbox; - GtkWidget *attendees_vbox_spacer; - - /* The etable and model */ - EMeetingModel *model; - GtkWidget *etable; - - /* The canvas displaying the dates, times, and the summary - 'All Attendees' free/busy display. */ - GtkWidget *display_top; - - /* The canvas containing the free/busy displays of individual - attendees. This is separate from display_top since it also scrolls - vertically. */ - GtkWidget *display_main; - - /* This is the 'Options' button & menu. */ - GtkWidget *options_button; - GtkWidget *options_menu; - - /* This is the 'Autopick' button, menu & radio menu items. */ - GtkWidget *autopick_button; - GtkWidget *autopick_menu; - GtkWidget *autopick_all_item; - GtkWidget *autopick_all_people_one_resource_item; - GtkWidget *autopick_required_people_item; - GtkWidget *autopick_required_people_one_resource_item; - - /* The horizontal scrollbar which scrolls display_top & display_main.*/ - GtkWidget *hscrollbar; - - /* The vertical scrollbar which scrolls attendees & display_main. */ - GtkWidget *vscrollbar; - - /* The 2 EDateEdit widgets for the meeting start & end times. */ - GtkWidget *start_date_edit; - GtkWidget *end_date_edit; - - /* Colors. */ - GdkColor bg_color; - GdkColor all_attendees_bg_color; - GdkColor meeting_time_bg_color; - GdkColor stipple_bg_color; - GdkColor attendee_list_bg_color; - GdkColor grid_color; - GdkColor grid_shadow_color; - GdkColor grid_unused_color; - GdkColor busy_colors[E_MEETING_FREE_BUSY_LAST]; - - /* The stipple used for attendees with no data. */ - GdkPixmap *stipple; - - /* GC for drawing the color key. */ - GdkGC *color_key_gc; - - /* Width of the hours strings (e.g. "1:00") in the current font. */ - gint hour_widths[24]; - - /* Whether we are using the full, abbreviated or short date format. */ - EMeetingTimeSelectorDateFormat date_format; - - /* - * Option Settings. - */ - - /* True if we are selecting all day events */ - gboolean all_day; - - /* If this is TRUE we only show hours between day_start_hour and - day_end_hour, defaults to TRUE (9am-6pm). */ - gboolean working_hours_only; - gint day_start_hour; - gint day_start_minute; - gint day_end_hour; - gint day_end_minute; - - /* If TRUE, view is compressed, with one cell for every 3 hours rather - than every hour. Defaults to FALSE. */ - gboolean zoomed_out; - - - /* - * Internal Data. - */ - - /* These are the first & last dates shown in the current scroll area. - We show E_MEETING_TIME_SELECTOR_DAYS_SHOWN days at a time. */ - GDate first_date_shown; - GDate last_date_shown; - - /* This is the current selection of the meeting time. */ - EMeetingTime meeting_start_time; - EMeetingTime meeting_end_time; - - /* These are the x pixel coordinates in the entire scroll region of - the start and end times. Set to meeting_positions_valid to FALSE to - invalidate. They will then be recomputed when needed. Always access - with e_meeting_time_selector_get_meeting_time_positions(). */ - gint meeting_positions_valid; - gint meeting_positions_in_scroll_area; - gint meeting_start_x; - gint meeting_end_x; - - /* These are the width and height of the cells, including the grid - lines which are displayed on the right and top or bottom of cells.*/ - gint row_height; - gint col_width; - - /* This is the width of a day in the display, which depends on - col_width, working_hours_only and zoomed_out. */ - gint day_width; - - /* These are the first and last hour of each day we display, depending - on working_hours_only and zoomed_out. */ - gint first_hour_shown; - gint last_hour_shown; - - /* The id of the source function for auto-scroll timeouts. */ - guint auto_scroll_timeout_id; - - /* This specifies if we are dragging one of the vertical bars around - the meeting time. */ - EMeetingTimeSelectorPosition dragging_position; - - /* The last x coordinate of the mouse, relative to either the left or - right edge of the canvas. Used in the auto_scroll_timeout function - to determine which way to scroll and how fast. */ - gint last_drag_x; - - /* This is used to determine the delay between scrolls. */ - gint scroll_count; -}; - - -struct _EMeetingTimeSelectorClass -{ - GtkTableClass parent_class; - - void (* changed) (EMeetingTimeSelector *mts); -}; - - -/* - * PUBLIC INTERFACE - note that this interface will probably change, when I - * know where the data is coming from. This is mainly just for testing for now. - */ - -GtkType e_meeting_time_selector_get_type (void); -GtkWidget* e_meeting_time_selector_new (EMeetingModel *emm); -void e_meeting_time_selector_construct (EMeetingTimeSelector * mts, EMeetingModel *emm); - -/* This returns the currently selected meeting time. - Note that months are 1-12 and days are 1-31. The start time is guaranteed to - be before or equal to the end time. You may want to check if they are equal - if that if it is a problem. */ -void e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute); - -/* This sets the meeting time, returning TRUE if it is valid. */ -gboolean e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute); - -void e_meeting_time_selector_set_all_day (EMeetingTimeSelector *mts, - gboolean all_day); -void e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only); -void e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute); - -void e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out); - -EMeetingTimeSelectorAutopickOption e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts); -void e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option); - -void e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to); - -/* Clears all busy times for the given attendee. */ -void e_meeting_time_selector_attendee_clear_busy_periods (EMeetingTimeSelector *mts, - gint row); -/* Adds one busy time for the given attendee. */ -gboolean e_meeting_time_selector_attendee_add_busy_period (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingFreeBusyType busy_type); - - - -/* - * INTERNAL ROUTINES - functions to communicate with the canvas items within - * the EMeetingTimeSelector. - */ - -/* This returns the x pixel coordinates of the meeting start and end times, - in the entire canvas scroll area. If it returns FALSE, then the meeting - time isn't in the current scroll area (which shouldn't really happen). */ -gboolean e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x); - -void e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x); - -void e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts); - -void e_meeting_time_selector_fix_time_overflows (EMeetingTime*mtstime); - -void e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position); -void e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes); -void e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTime*time); -gint e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTime *mtstime); - -/* Debugging function to dump information on all attendees. */ -#ifdef E_MEETING_TIME_SELECTOR_DEBUG -void e_meeting_time_selector_dump (EMeetingTimeSelector *mts); -gchar* e_meeting_time_selector_dump_time (EMeetingTime*mtstime); -gchar* e_meeting_time_selector_dump_date (GDate *date); -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_TIME_SELECTOR_H_ */ diff --git a/calendar/gui/e-meeting-types.h b/calendar/gui/e-meeting-types.h deleted file mode 100644 index ab330a6d40..0000000000 --- a/calendar/gui/e-meeting-types.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* itip-attendee.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_MEETING_TYPES_H_ -#define _E_MEETING_TYPES_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include "e-meeting-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - - - -typedef struct _EMeetingTime EMeetingTime; -typedef struct _EMeetingFreeBusyPeriod EMeetingFreeBusyPeriod; - -/* These are used to specify whether an attendee is free or busy at a - particular time. We'll probably replace this with a global calendar type. - These should be ordered in increasing order of preference. Higher precedence - busy periods will be painted over lower precedence ones. These are also - used as for loop counters, so they should start at 0 and be ordered. */ -typedef enum -{ - E_MEETING_FREE_BUSY_TENTATIVE = 0, - E_MEETING_FREE_BUSY_OUT_OF_OFFICE = 1, - E_MEETING_FREE_BUSY_BUSY = 2, - - E_MEETING_FREE_BUSY_LAST = 3 -} EMeetingFreeBusyType; - -/* This is our representation of a time. We use a GDate to store the day, - and guint8s for the hours and minutes. */ -struct _EMeetingTime -{ - GDate date; - guint8 hour; - guint8 minute; -}; - -/* This represents a busy period. */ -struct _EMeetingFreeBusyPeriod -{ - EMeetingTime start; - EMeetingTime end; - EMeetingFreeBusyType busy_type; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_TYPES_H_ */ diff --git a/calendar/gui/e-meeting-utils.c b/calendar/gui/e-meeting-utils.c deleted file mode 100644 index 496bb8ebaa..0000000000 --- a/calendar/gui/e-meeting-utils.c +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* itip-model.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-meeting-utils.h" - -gint -e_meeting_time_compare_times (EMeetingTime*time1, - EMeetingTime*time2) -{ - gint day_comparison; - - day_comparison = g_date_compare (&time1->date, - &time2->date); - if (day_comparison != 0) - return day_comparison; - - if (time1->hour < time2->hour) - return -1; - if (time1->hour > time2->hour) - return 1; - - if (time1->minute < time2->minute) - return -1; - if (time1->minute > time2->minute) - return 1; - - /* The start times are exactly the same. */ - return 0; -} diff --git a/calendar/gui/e-meeting-utils.h b/calendar/gui/e-meeting-utils.h deleted file mode 100644 index 4c2798fcf0..0000000000 --- a/calendar/gui/e-meeting-utils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* itip-attendee.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: JP Rosevear - */ - -#ifndef _E_MEETING_UTILS_H_ -#define _E_MEETING_UTILS_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include "e-meeting-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - - - -gint e_meeting_time_compare_times (EMeetingTime *time1, - EMeetingTime *time2); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_UTILS_H_ */ - - diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c deleted file mode 100644 index 38035400da..0000000000 --- a/calendar/gui/e-tasks.c +++ /dev/null @@ -1,842 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-tasks.c - * - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - */ - -#include <config.h> -#include <gnome.h> -#include <gal/util/e-util.h> -#include <gal/e-table/e-table-scrolled.h> -#include <gal/menus/gal-view-instance.h> -#include <gal/menus/gal-view-factory-etable.h> -#include <gal/menus/gal-view-etable.h> - -#include "e-util/e-url.h" -#include "widgets/menus/gal-view-menus.h" -#include "dialogs/delete-error.h" -#include "dialogs/task-editor.h" -#include "cal-search-bar.h" -#include "calendar-config.h" -#include "calendar-component.h" -#include "comp-util.h" -#include "misc.h" - -#include "e-tasks.h" - -/* A list of all of the ETasks widgets in use. We use this to update the - user preference settings. This will change when we switch to GConf. */ -static GList *all_tasks = NULL; - - -/* Private part of the GnomeCalendar structure */ -struct _ETasksPrivate { - /* The calendar client object we monitor */ - CalClient *client; - CalQuery *query; - - /* The ECalendarTable showing the tasks. */ - GtkWidget *tasks_view; - - /* Calendar search bar for tasks */ - GtkWidget *search_bar; - - /* View instance and the view menus handler */ - GalViewInstance *view_instance; - GalViewMenus *view_menus; -}; - - -static void e_tasks_class_init (ETasksClass *class); -static void e_tasks_init (ETasks *tasks); -static void setup_widgets (ETasks *tasks); -static void e_tasks_destroy (GtkObject *object); - -static void cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data); -static void backend_error_cb (CalClient *client, const char *message, gpointer data); - -/* Signal IDs */ -enum { - SELECTION_CHANGED, - LAST_SIGNAL -}; - -static GtkTableClass *parent_class; -static guint e_tasks_signals[LAST_SIGNAL] = { 0 }; - - -E_MAKE_TYPE (e_tasks, "ETasks", ETasks, - e_tasks_class_init, e_tasks_init, - GTK_TYPE_TABLE) - - -/* Class initialization function for the gnome calendar */ - static void -e_tasks_class_init (ETasksClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - - parent_class = gtk_type_class (GTK_TYPE_TABLE); - - e_tasks_signals[SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (ETasksClass, selection_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, - GTK_TYPE_INT); - - object_class->destroy = e_tasks_destroy; - - class->selection_changed = NULL; -} - - -/* Object initialization function for the gnome calendar */ -static void -e_tasks_init (ETasks *tasks) -{ - ETasksPrivate *priv; - - priv = g_new0 (ETasksPrivate, 1); - tasks->priv = priv; - - priv->client = NULL; - priv->query = NULL; - priv->view_instance = NULL; - priv->view_menus = NULL; -} - -/* Callback used when the selection changes in the table. */ -static void -table_selection_change_cb (ETable *etable, gpointer data) -{ - ETasks *tasks; - int n_selected; - - tasks = E_TASKS (data); - - n_selected = e_table_selected_count (etable); - gtk_signal_emit (GTK_OBJECT (tasks), e_tasks_signals[SELECTION_CHANGED], - n_selected); -} - -/* Callback used when the sexp in the search bar changes */ -static void -search_bar_sexp_changed_cb (CalSearchBar *cal_search, const char *sexp, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - CalendarModel *model; - - tasks = E_TASKS (data); - priv = tasks->priv; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - calendar_model_set_query (model, sexp); -} - -/* Callback used when the selected category in the search bar changes */ -static void -search_bar_category_changed_cb (CalSearchBar *cal_search, const char *category, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - CalendarModel *model; - - tasks = E_TASKS (data); - priv = tasks->priv; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - calendar_model_set_default_category (model, category); -} - -#define E_TASKS_TABLE_DEFAULT_STATE \ - "<?xml version=\"1.0\"?>" \ - "<ETableState>" \ - "<column source=\"13\"/>" \ - "<column source=\"14\"/>" \ - "<column source=\"9\"/>" \ - "<column source=\"5\"/>" \ - "<grouping/>" \ - "</ETableState>" - - -static void -setup_widgets (ETasks *tasks) -{ - ETasksPrivate *priv; - ETable *etable; - CalendarModel *model; - - priv = tasks->priv; - - priv->search_bar = cal_search_bar_new (); - g_signal_connect (priv->search_bar, "sexp_changed", - G_CALLBACK (search_bar_sexp_changed_cb), tasks); - g_signal_connect (priv->search_bar, "category_changed", - G_CALLBACK (search_bar_category_changed_cb), tasks); - - gtk_table_attach (GTK_TABLE (tasks), priv->search_bar, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0, 0); - gtk_widget_show (priv->search_bar); - - priv->tasks_view = e_calendar_table_new (); - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - calendar_model_set_new_comp_vtype (model, CAL_COMPONENT_TODO); - - etable = e_table_scrolled_get_table ( - E_TABLE_SCROLLED (E_CALENDAR_TABLE (priv->tasks_view)->etable)); - e_table_set_state (etable, E_TASKS_TABLE_DEFAULT_STATE); - gtk_table_attach (GTK_TABLE (tasks), priv->tasks_view, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (priv->tasks_view); - - calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->tasks_view)); - - g_signal_connect (etable, "selection_change", G_CALLBACK (table_selection_change_cb), tasks); -} - -/* Callback used when the set of categories changes in the calendar client */ -static void -client_categories_changed_cb (CalClient *client, GPtrArray *categories, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - cal_search_bar_set_categories (CAL_SEARCH_BAR (priv->search_bar), categories); -} - -GtkWidget * -e_tasks_construct (ETasks *tasks) -{ - ETasksPrivate *priv; - CalendarModel *model; - - g_return_val_if_fail (tasks != NULL, NULL); - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - priv = tasks->priv; - - setup_widgets (tasks); - - priv->client = cal_client_new (); - if (!priv->client) - return NULL; - - g_signal_connect (priv->client, "cal_opened", - G_CALLBACK (cal_opened_cb), tasks); - g_signal_connect (priv->client, "backend_error", - G_CALLBACK (backend_error_cb), tasks); - g_signal_connect (priv->client, "categories_changed", - G_CALLBACK (client_categories_changed_cb), tasks); - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - g_assert (model != NULL); - - calendar_model_set_cal_client (model, priv->client, CALOBJ_TYPE_TODO); - - return GTK_WIDGET (tasks); -} - - -GtkWidget * -e_tasks_new (void) -{ - ETasks *tasks; - - tasks = g_object_new (e_tasks_get_type (), NULL); - - if (!e_tasks_construct (tasks)) { - g_message ("e_tasks_new(): Could not construct the tasks GUI"); - g_object_unref (tasks); - return NULL; - } - - all_tasks = g_list_prepend (all_tasks, tasks); - - return GTK_WIDGET (tasks); -} - - -void -e_tasks_set_ui_component (ETasks *tasks, - BonoboUIComponent *ui_component) -{ - g_return_if_fail (E_IS_TASKS (tasks)); - g_return_if_fail (ui_component == NULL || BONOBO_IS_UI_COMPONENT (ui_component)); - - e_search_bar_set_ui_component (E_SEARCH_BAR (tasks->priv->search_bar), ui_component); -} - - -static void -e_tasks_destroy (GtkObject *object) -{ - ETasks *tasks; - ETasksPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TASKS (object)); - - tasks = E_TASKS (object); - priv = tasks->priv; - - if (priv->client) { - g_object_unref (priv->client); - priv->client = NULL; - } - - g_free (priv); - tasks->priv = NULL; - - all_tasks = g_list_remove (all_tasks, tasks); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -set_status_message (ETasks *tasks, const char *message) -{ - ETasksPrivate *priv; - CalendarModel *model; - - priv = tasks->priv; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - calendar_model_set_status_message (model, message); -} - -gboolean -e_tasks_open (ETasks *tasks, - char *file) -{ - ETasksPrivate *priv; - char *message; - EUri *uri; - char *real_uri; - char *urinopwd; - - g_return_val_if_fail (tasks != NULL, FALSE); - g_return_val_if_fail (E_IS_TASKS (tasks), FALSE); - g_return_val_if_fail (file != NULL, FALSE); - - priv = tasks->priv; - - uri = e_uri_new (file); - if (!uri || !g_strncasecmp (uri->protocol, "file", 4)) - real_uri = g_concat_dir_and_file (file, "tasks.ics"); - else - real_uri = g_strdup (file); - - urinopwd = get_uri_without_password (real_uri); - message = g_strdup_printf (_("Opening tasks at %s"), urinopwd); - set_status_message (tasks, message); - g_free (message); - g_free (urinopwd); - - if (!cal_client_open_calendar (priv->client, real_uri, FALSE)) { - g_message ("e_tasks_open(): Could not issue the request"); - g_free (real_uri); - e_uri_free (uri); - - return FALSE; - } - - g_free (real_uri); - e_uri_free (uri); - - return TRUE; -} - - -/* Displays an error to indicate that loading a calendar failed */ -static void -load_error (ETasks *tasks, - const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("Could not load the tasks in `%s'"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks)))); - g_free (msg); - g_free (urinopwd); -} - -/* Displays an error to indicate that the specified URI method is not supported */ -static void -method_error (ETasks *tasks, - const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("The method required to load `%s' is not supported"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks)))); - g_free (msg); - g_free (urinopwd); -} - -/* Displays an error to indicate permission problems */ -static void -permission_error (ETasks *tasks, const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("You don't have permission to open the folder in `%s'"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks)))); - g_free (msg); - g_free (urinopwd); -} - -/* Callback from the calendar client when a calendar is opened */ -static void -cal_opened_cb (CalClient *client, - CalClientOpenStatus status, - gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - char *location; - icaltimezone *zone; - - tasks = E_TASKS (data); - priv = tasks->priv; - - set_status_message (tasks, NULL); - - switch (status) { - case CAL_CLIENT_OPEN_SUCCESS: - /* Everything is OK */ - - /* Set the client's default timezone, if we have one. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - if (zone) - cal_client_set_default_timezone (client, zone); - return; - - case CAL_CLIENT_OPEN_ERROR: - load_error (tasks, cal_client_get_uri (client)); - break; - - case CAL_CLIENT_OPEN_NOT_FOUND: - /* bullshit; we did not specify only_if_exists */ - g_assert_not_reached (); - return; - - case CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED: - method_error (tasks, cal_client_get_uri (client)); - break; - - case CAL_CLIENT_OPEN_PERMISSION_DENIED: - permission_error (tasks, cal_client_get_uri (client)); - break; - - default: - g_assert_not_reached (); - } -} - -/* Callback from the calendar client when an error occurs in the backend */ -static void -backend_error_cb (CalClient *client, const char *message, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - char *errmsg; - char *urinopwd; - - tasks = E_TASKS (data); - priv = tasks->priv; - - urinopwd = get_uri_without_password (cal_client_get_uri (client)); - errmsg = g_strdup_printf (_("Error on %s:\n %s"), urinopwd, message); - gnome_error_dialog_parented (errmsg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks)))); - g_free (errmsg); - g_free (urinopwd); -} - -/** - * e_tasks_get_cal_client: - * @tasks: An #ETasks. - * - * Queries the calendar client interface object that a tasks view is using. - * - * Return value: A calendar client interface object. - **/ -CalClient * -e_tasks_get_cal_client (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - priv = tasks->priv; - - return priv->client; -} - - -void -e_tasks_new_task (ETasks *tasks) -{ - ETasksPrivate *priv; - TaskEditor *tedit; - CalComponent *comp; - const char *category; - - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - tedit = task_editor_new (priv->client); - - comp = cal_comp_task_new_with_defaults (priv->client); - - category = cal_search_bar_get_category (CAL_SEARCH_BAR (priv->search_bar)); - cal_component_set_categories (comp, category); - - comp_editor_edit_comp (COMP_EDITOR (tedit), comp); - g_object_unref (comp); - - comp_editor_focus (COMP_EDITOR (tedit)); -} - -/** - * e_tasks_complete_selected: - * @tasks: A tasks control widget - * - * Marks the selected tasks complete - **/ -void -e_tasks_complete_selected (ETasks *tasks) -{ - ETasksPrivate *priv; - ECalendarTable *cal_table; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - - set_status_message (tasks, _("Completing tasks...")); - e_calendar_table_complete_selected (cal_table); - set_status_message (tasks, NULL); -} - -/** - * e_tasks_delete_selected: - * @tasks: A tasks control widget. - * - * Deletes the selected tasks in the task list. - **/ -void -e_tasks_delete_selected (ETasks *tasks) -{ - ETasksPrivate *priv; - ECalendarTable *cal_table; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - set_status_message (tasks, _("Deleting selected objects...")); - e_calendar_table_delete_selected (cal_table); - set_status_message (tasks, NULL); -} - -static char * -create_sexp (void) -{ - char *sexp; - - sexp = g_strdup ("(and (= (get-vtype) \"VTODO\") (is-completed?))"); -#if 0 - g_print ("Calendar model sexp:\n%s\n", sexp); -#endif - - return sexp; -} - -/* Callback used when a component is updated in the live query */ -static void -query_obj_updated_cb (CalQuery *query, const char *uid, - gboolean query_in_progress, int n_scanned, int total, - gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - delete_error_dialog (cal_client_remove_object (priv->client, uid), CAL_COMPONENT_TODO); -} - -/* Callback used when an evaluation error occurs when running a query */ -static void -query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - g_warning ("eval error: %s\n", error_str); - - set_status_message (tasks, NULL); - - g_signal_handlers_disconnect_matched (priv->query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, tasks); - g_object_unref (priv->query); - priv->query = NULL; -} - -static void -query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - if (status != CAL_QUERY_DONE_SUCCESS) - g_warning ("query done: %s\n", error_str); - - set_status_message (tasks, NULL); - - g_signal_handlers_disconnect_matched (priv->query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, tasks); - g_object_unref (priv->query); - priv->query = NULL; -} -/** - * e_tasks_expunge: - * @tasks: A tasks control widget - * - * Removes all tasks marked as completed - **/ -void -e_tasks_delete_completed (ETasks *tasks) -{ - ETasksPrivate *priv; - char *sexp; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - /* If we have a query, we are already expunging */ - if (priv->query) - return; - - sexp = create_sexp (); - - set_status_message (tasks, _("Expunging")); - priv->query = cal_client_get_query (priv->client, sexp); - g_free (sexp); - - if (!priv->query) { - set_status_message (tasks, NULL); - g_message ("update_query(): Could not create the query"); - return; - } - - g_signal_connect (priv->query, "obj_updated", G_CALLBACK (query_obj_updated_cb), tasks); - g_signal_connect (priv->query, "query_done", G_CALLBACK (query_query_done_cb), tasks); - g_signal_connect (priv->query, "eval_error", G_CALLBACK (query_eval_error_cb), tasks); -} - -/* Callback used from the view collection when we need to display a new view */ -static void -display_view_cb (GalViewInstance *instance, GalView *view, gpointer data) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - - if (GAL_IS_VIEW_ETABLE (view)) { - gal_view_etable_attach_table (GAL_VIEW_ETABLE (view), e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (tasks->priv->tasks_view)->etable))); - } -} - -/** - * e_tasks_setup_view_menus: - * @tasks: A tasks widget. - * @uic: UI controller to use for the menus. - * - * Sets up the #GalView menus for a tasks control. This function should be - * called from the Bonobo control activation callback for this tasks control. - * Also, the menus should be discarded using e_tasks_discard_view_menus(). - **/ -void -e_tasks_setup_view_menus (ETasks *tasks, BonoboUIComponent *uic) -{ - ETasksPrivate *priv; - GalViewFactory *factory; - ETableSpecification *spec; - char *dir; - static GalViewCollection *collection = NULL; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - g_return_if_fail (uic != NULL); - g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); - - priv = tasks->priv; - - g_return_if_fail (priv->view_instance == NULL); - - g_assert (priv->view_instance == NULL); - g_assert (priv->view_menus == NULL); - - /* Create the view instance */ - - if (collection == NULL) { - collection = gal_view_collection_new (); - - gal_view_collection_set_title (collection, _("Tasks")); - - dir = gnome_util_prepend_user_home ("/evolution/views/tasks/"); - gal_view_collection_set_storage_directories (collection, - EVOLUTION_GALVIEWSDIR "/tasks/", - dir); - g_free (dir); - - /* Create the views */ - - spec = e_table_specification_new (); - e_table_specification_load_from_file (spec, - EVOLUTION_ETSPECDIR "/e-calendar-table.etspec"); - - factory = gal_view_factory_etable_new (spec); - g_object_unref (spec); - gal_view_collection_add_factory (collection, factory); - g_object_unref (factory); - - /* Load the collection and create the menus */ - - gal_view_collection_load (collection); - } - - priv->view_instance = gal_view_instance_new (collection, cal_client_get_uri (priv->client)); - - priv->view_menus = gal_view_menus_new (priv->view_instance); - gal_view_menus_apply (priv->view_menus, uic, NULL); - g_signal_connect (priv->view_instance, "display_view", G_CALLBACK (display_view_cb), tasks); - display_view_cb (priv->view_instance, gal_view_instance_get_current_view (priv->view_instance), tasks); -} - -/** - * e_tasks_discard_view_menus: - * @tasks: A tasks widget. - * - * Discards the #GalView menus used by a tasks control. This function should be - * called from the Bonobo control deactivation callback for this tasks control. - * The menus should have been set up with e_tasks_setup_view_menus(). - **/ -void -e_tasks_discard_view_menus (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - g_return_if_fail (priv->view_instance != NULL); - - g_assert (priv->view_instance != NULL); - g_assert (priv->view_menus != NULL); - - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - - g_object_unref (priv->view_menus); - priv->view_menus = NULL; -} - -/** - * e_tasks_get_calendar_table: - * @tasks: A tasks widget. - * - * Queries the #ECalendarTable contained in a tasks widget. - * - * Return value: The #ECalendarTable that the tasks widget uses to display its - * information. - **/ -ECalendarTable * -e_tasks_get_calendar_table (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_val_if_fail (tasks != NULL, NULL); - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - priv = tasks->priv; - return E_CALENDAR_TABLE (priv->tasks_view); -} - -/* This updates all the preference settings for all the ETasks widgets in use. - */ -void -e_tasks_update_all_config_settings (void) -{ - ETasks *tasks; - ETasksPrivate *priv; - GList *elem; - char *location; - icaltimezone *zone; - - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - for (elem = all_tasks; elem; elem = elem->next) { - tasks = E_TASKS (elem->data); - priv = tasks->priv; - - calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->tasks_view)); - - if (zone) - cal_client_set_default_timezone (priv->client, zone); - } -} diff --git a/calendar/gui/e-tasks.h b/calendar/gui/e-tasks.h deleted file mode 100644 index b88e495dcc..0000000000 --- a/calendar/gui/e-tasks.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-tasks.h - * - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - */ - -#ifndef _E_TASKS_H_ -#define _E_TASKS_H_ - -#include <gtk/gtktable.h> -#include <cal-client/cal-client.h> -#include "e-calendar-table.h" - -#define E_TYPE_TASKS (e_tasks_get_type ()) -#define E_TASKS(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TASKS, ETasks)) -#define E_TASKS_CLASS(klass) (GTK_CHECK_CAST_CLASS ((klass), E_TYPE_TASKS, \ - ETasksClass)) -#define E_IS_TASKS(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TASKS)) -#define E_IS_TASKS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TASKS)) - -typedef struct _ETasks ETasks; -typedef struct _ETasksClass ETasksClass; -typedef struct _ETasksPrivate ETasksPrivate; - -struct _ETasks { - GtkTable table; - - /* Private data */ - ETasksPrivate *priv; -}; - -struct _ETasksClass { - GtkTableClass parent_class; - - /* Notification signals */ - void (* selection_changed) (ETasks *tasks, int n_selected); -}; - - -GtkType e_tasks_get_type (void); -GtkWidget *e_tasks_construct (ETasks *tasks); - -GtkWidget *e_tasks_new (void); - -void e_tasks_set_ui_component (ETasks *tasks, - BonoboUIComponent *ui_component); - -gboolean e_tasks_open (ETasks *tasks, - char *file); - -CalClient *e_tasks_get_cal_client (ETasks *tasks); - -void e_tasks_new_task (ETasks *tasks); -void e_tasks_complete_selected (ETasks *tasks); -void e_tasks_delete_selected (ETasks *tasks); -void e_tasks_delete_completed (ETasks *tasks); - - -void e_tasks_setup_view_menus (ETasks *tasks, BonoboUIComponent *uic); -void e_tasks_discard_view_menus (ETasks *tasks); - -ECalendarTable *e_tasks_get_calendar_table (ETasks *tasks); - -/* This updates all the preference settings for all the ETasks widgets in use. - */ -void e_tasks_update_all_config_settings (void); - -#endif /* _E_TASKS_H_ */ diff --git a/calendar/gui/e-timezone-entry.c b/calendar/gui/e-timezone-entry.c deleted file mode 100644 index 6d514ccc93..0000000000 --- a/calendar/gui/e-timezone-entry.c +++ /dev/null @@ -1,294 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * ETimezoneEntry - a field for setting a timezone. It shows the timezone in - * a GtkEntry with a '...' button beside it which shows a dialog for changing - * the timezone. The dialog contains a map of the world with a point for each - * timezone, and an option menu as an alternative way of selecting the - * timezone. - */ - -#include <config.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkentry.h> -#include <gtk/gtksignal.h> -#include <gnome.h> -#include <gal/util/e-util.h> -#include <gal/widgets/e-unicode.h> -#include <widgets/e-timezone-dialog/e-timezone-dialog.h> -#include "e-timezone-entry.h" - -/* The timezone icon for the button. */ -#include "art/timezone-16.xpm" - -struct _ETimezoneEntryPrivate { - /* The current timezone, set in e_timezone_entry_set_timezone() - or from the timezone dialog. Note that we don't copy it or - use a ref count - we assume it is never destroyed for the - lifetime of this widget. */ - icaltimezone *zone; - - /* This can be set to the default timezone. If the current timezone - setting in the ETimezoneEntry matches this, then the entry field - is hidden. This makes the user interface simpler. */ - icaltimezone *default_zone; - - GtkWidget *entry; - GtkWidget *button; -}; - - -enum { - CHANGED, - LAST_SIGNAL -}; - - -static void e_timezone_entry_class_init (ETimezoneEntryClass *class); -static void e_timezone_entry_init (ETimezoneEntry *tentry); -static void e_timezone_entry_destroy (GtkObject *object); - -static void on_entry_changed (GtkEntry *entry, - ETimezoneEntry *tentry); -static void on_button_clicked (GtkWidget *widget, - ETimezoneEntry *tentry); - -static void e_timezone_entry_set_entry (ETimezoneEntry *tentry); - - -static GtkHBoxClass *parent_class; -static guint timezone_entry_signals[LAST_SIGNAL] = { 0 }; - -E_MAKE_TYPE (e_timezone_entry, "ETimezoneEntry", ETimezoneEntry, - e_timezone_entry_class_init, e_timezone_entry_init, GTK_TYPE_HBOX); - -static void -e_timezone_entry_class_init (ETimezoneEntryClass *class) -{ - GtkObjectClass *object_class = (GtkObjectClass *) class; - - object_class = (GtkObjectClass*) class; - - parent_class = g_type_class_peek_parent (class); - - timezone_entry_signals[CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (ETimezoneEntryClass, - changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - object_class->destroy = e_timezone_entry_destroy; - - class->changed = NULL; -} - - -static void -e_timezone_entry_init (ETimezoneEntry *tentry) -{ - ETimezoneEntryPrivate *priv; - GdkColormap *colormap; - GdkPixmap *timezone_icon; - GdkBitmap *timezone_mask; - GtkWidget *pixmap; - - tentry->priv = priv = g_new0 (ETimezoneEntryPrivate, 1); - - priv->zone = NULL; - priv->default_zone = NULL; - - priv->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (priv->entry), FALSE); - /*gtk_widget_set_usize (priv->date_entry, 90, 0);*/ - gtk_box_pack_start (GTK_BOX (tentry), priv->entry, TRUE, TRUE, 6); - gtk_widget_show (priv->entry); - g_signal_connect (priv->entry, "changed", G_CALLBACK (on_entry_changed), tentry); - - priv->button = gtk_button_new (); - g_signal_connect (priv->button, "clicked", G_CALLBACK (on_button_clicked), tentry); - gtk_box_pack_start (GTK_BOX (tentry), priv->button, FALSE, FALSE, 6); - gtk_widget_show (priv->button); - - colormap = gtk_widget_get_colormap (priv->button); - timezone_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &timezone_mask, NULL, timezone_16_xpm); - - pixmap = gtk_pixmap_new (timezone_icon, timezone_mask); - gtk_container_add (GTK_CONTAINER (priv->button), pixmap); - gtk_widget_show (pixmap); -} - - -/** - * e_timezone_entry_new: - * - * Description: Creates a new #ETimezoneEntry widget which can be used - * to provide an easy to use way for entering dates and times. - * - * Returns: a new #ETimezoneEntry widget. - */ -GtkWidget * -e_timezone_entry_new (void) -{ - ETimezoneEntry *tentry; - - tentry = g_object_new (e_timezone_entry_get_type (), NULL); - - return GTK_WIDGET (tentry); -} - - -static void -e_timezone_entry_destroy (GtkObject *object) -{ - ETimezoneEntry *tentry; - ETimezoneEntryPrivate *priv; - - g_return_if_fail (E_IS_TIMEZONE_ENTRY (object)); - - tentry = E_TIMEZONE_ENTRY (object); - priv = tentry->priv; - - g_free (tentry->priv); - tentry->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -/* The arrow button beside the date field has been clicked, so we show the - popup with the ECalendar in. */ -static void -on_button_clicked (GtkWidget *widget, - ETimezoneEntry *tentry) -{ - ETimezoneEntryPrivate *priv; - ETimezoneDialog *timezone_dialog; - GtkWidget *dialog; - - priv = tentry->priv; - - timezone_dialog = e_timezone_dialog_new (); - - e_timezone_dialog_set_timezone (timezone_dialog, priv->zone); - - dialog = e_timezone_dialog_get_toplevel (timezone_dialog); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - priv->zone = e_timezone_dialog_get_timezone (timezone_dialog); - e_timezone_entry_set_entry (tentry); - } - - g_object_unref (timezone_dialog); -} - - -static void -on_entry_changed (GtkEntry *entry, - ETimezoneEntry *tentry) -{ - gtk_signal_emit (GTK_OBJECT (tentry), timezone_entry_signals[CHANGED]); -} - - -icaltimezone* -e_timezone_entry_get_timezone (ETimezoneEntry *tentry) -{ - ETimezoneEntryPrivate *priv; - - g_return_val_if_fail (E_IS_TIMEZONE_ENTRY (tentry), NULL); - - priv = tentry->priv; - - return priv->zone; -} - - -void -e_timezone_entry_set_timezone (ETimezoneEntry *tentry, - icaltimezone *zone) -{ - ETimezoneEntryPrivate *priv; - - g_return_if_fail (E_IS_TIMEZONE_ENTRY (tentry)); - - priv = tentry->priv; - - priv->zone = zone; - - e_timezone_entry_set_entry (tentry); -} - - -/* Sets the default timezone. If the current timezone matches this, then the - entry field is hidden. This is useful since most people do not use timezones - so it makes the user interface simpler. */ -void -e_timezone_entry_set_default_timezone (ETimezoneEntry *tentry, - icaltimezone *zone) -{ - ETimezoneEntryPrivate *priv; - - g_return_if_fail (E_IS_TIMEZONE_ENTRY (tentry)); - - priv = tentry->priv; - - priv->default_zone = zone; - - e_timezone_entry_set_entry (tentry); -} - - -static void -e_timezone_entry_set_entry (ETimezoneEntry *tentry) -{ - ETimezoneEntryPrivate *priv; - const char *display_name; - - priv = tentry->priv; - - if (priv->zone) { - display_name = icaltimezone_get_display_name (priv->zone); - - /* We check if it is one of our builtin timezone - names, in which case we call gettext to translate - it. If it isn't a builtin timezone name, we - don't. */ - if (icaltimezone_get_builtin_timezone (display_name)) - display_name = _(display_name); - } else - display_name = ""; - - gtk_entry_set_text (GTK_ENTRY (priv->entry), display_name); - - if (!priv->default_zone || (priv->zone != priv->default_zone)) - gtk_widget_show (priv->entry); - else - gtk_widget_hide (priv->entry); -} - diff --git a/calendar/gui/e-timezone-entry.h b/calendar/gui/e-timezone-entry.h deleted file mode 100644 index 4f94cd88a1..0000000000 --- a/calendar/gui/e-timezone-entry.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * ETimezoneEntry - a field for setting a timezone. It shows the timezone in - * a GtkEntry with a '...' button beside it which shows a dialog for changing - * the timezone. The dialog contains a map of the world with a point for each - * timezone, and an option menu as an alternative way of selecting the - * timezone. - */ - -#ifndef __E_TIMEZONE_ENTRY_H_ -#define __E_TIMEZONE_ENTRY_H_ - -#include <gtk/gtkhbox.h> -#include <cal-client/cal-client.h> - -G_BEGIN_DECLS - - -#define E_TYPE_TIMEZONE_ENTRY (e_timezone_entry_get_type ()) -#define E_TIMEZONE_ENTRY(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TIMEZONE_ENTRY, ETimezoneEntry)) -#define E_TIMEZONE_ENTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TIMEZONE_ENTRY, ETimezoneEntryClass)) -#define E_IS_TIMEZONE_ENTRY(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TIMEZONE_ENTRY)) -#define E_IS_TIMEZONE_ENTRY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TIMEZONE_ENTRY)) - - -typedef struct _ETimezoneEntry ETimezoneEntry; -typedef struct _ETimezoneEntryPrivate ETimezoneEntryPrivate; -typedef struct _ETimezoneEntryClass ETimezoneEntryClass; - -struct _ETimezoneEntry { - GtkHBox hbox; - - /*< private >*/ - ETimezoneEntryPrivate *priv; -}; - -struct _ETimezoneEntryClass { - GtkHBoxClass parent_class; - - void (* changed) (ETimezoneEntry *tentry); -}; - -GType e_timezone_entry_get_type (void); -GtkWidget* e_timezone_entry_new (void); - -icaltimezone* e_timezone_entry_get_timezone (ETimezoneEntry *tentry); -void e_timezone_entry_set_timezone (ETimezoneEntry *tentry, - icaltimezone *zone); - -/* Sets the default timezone. If the current timezone matches this, then the - entry field is hidden. This is useful since most people do not use timezones - so it makes the user interface simpler. */ -void e_timezone_entry_set_default_timezone(ETimezoneEntry *tentry, - icaltimezone *zone); - -G_END_DECLS - -#endif /* __E_TIMEZONE_ENTRY_H_ */ diff --git a/calendar/gui/e-week-view-event-item.c b/calendar/gui/e-week-view-event-item.c deleted file mode 100644 index 749bcbad65..0000000000 --- a/calendar/gui/e-week-view-event-item.c +++ /dev/null @@ -1,914 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EWeekViewEventItem - displays the background, times and icons for an event - * in the week/month views. A separate EText canvas item is used to display & - * edit the text. - */ - -#include <config.h> - -#include "e-util/e-categories-config.h" -#include "e-week-view-event-item.h" - -#include <gtk/gtksignal.h> -#include <gal/e-text/e-text.h> - -static void e_week_view_event_item_class_init (EWeekViewEventItemClass *class); -static void e_week_view_event_item_init (EWeekViewEventItem *wveitem); - -static void e_week_view_event_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_week_view_event_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags); -static void e_week_view_event_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_week_view_draw_time (EWeekView *week_view, - GdkDrawable *drawable, - gint time_x, - gint time_y, - gint hour, - gint minute); -static void e_week_view_event_item_draw_icons (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint icon_x, - gint icon_y, - gint x2, - gboolean right_align); -static void e_week_view_event_item_draw_triangle (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h); -static double e_week_view_event_item_point (GnomeCanvasItem *item, - double x, - double y, - int cx, - int cy, - GnomeCanvasItem **actual_item); -static gint e_week_view_event_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gboolean e_week_view_event_item_button_press (EWeekViewEventItem *wveitem, - GdkEvent *event); -static gboolean e_week_view_event_item_button_release (EWeekViewEventItem *wveitem, - GdkEvent *event); -static gboolean e_week_view_event_item_double_click (EWeekViewEventItem *wveitem, - GdkEvent *bevent); -static EWeekViewPosition e_week_view_event_item_get_position (EWeekViewEventItem *wveitem, - gdouble x, - gdouble y); - - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_EVENT_NUM, - ARG_SPAN_NUM -}; - -E_MAKE_TYPE (e_week_view_event_item, "EWeekViewEventItem", EWeekViewEventItem, - e_week_view_event_item_class_init, e_week_view_event_item_init, - GNOME_TYPE_CANVAS_ITEM); - -static void -e_week_view_event_item_class_init (EWeekViewEventItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EWeekViewEventItem::event_num", - GTK_TYPE_INT, GTK_ARG_WRITABLE, - ARG_EVENT_NUM); - gtk_object_add_arg_type ("EWeekViewEventItem::span_num", - GTK_TYPE_INT, GTK_ARG_WRITABLE, - ARG_SPAN_NUM); - - object_class->set_arg = e_week_view_event_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_week_view_event_item_update; - item_class->draw = e_week_view_event_item_draw; - item_class->point = e_week_view_event_item_point; - item_class->event = e_week_view_event_item_event; -} - - -static void -e_week_view_event_item_init (EWeekViewEventItem *wveitem) -{ - wveitem->event_num = -1; - wveitem->span_num = -1; -} - - -static void -e_week_view_event_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EWeekViewEventItem *wveitem; - gboolean needs_update = FALSE; - - item = GNOME_CANVAS_ITEM (o); - wveitem = E_WEEK_VIEW_EVENT_ITEM (o); - - switch (arg_id){ - case ARG_EVENT_NUM: - wveitem->event_num = GTK_VALUE_INT (*arg); - needs_update = TRUE; - break; - case ARG_SPAN_NUM: - wveitem->span_num = GTK_VALUE_INT (*arg); - needs_update = TRUE; - break; - } - - if (needs_update) - gnome_canvas_item_request_update (item); -} - - -static void -e_week_view_event_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - EWeekViewEventItem *wveitem; - EWeekView *week_view; - gint span_x, span_y, span_w; - -#if 0 - g_print ("In e_week_view_event_item_update\n"); -#endif - - wveitem = E_WEEK_VIEW_EVENT_ITEM (item); - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - if (wveitem->event_num != -1 && wveitem->span_num != -1) { - if (e_week_view_get_span_position (week_view, - wveitem->event_num, - wveitem->span_num, - &span_x, &span_y, - &span_w)) { -#if 0 - g_print (" Event:%i Span:%i %i,%i W:%i\n", - wveitem->event_num, wveitem->span_num, - span_x, span_y, span_w); -#endif - item->x1 = span_x; - item->y1 = span_y; - item->x2 = span_x + span_w - 1; - item->y2 = span_y + week_view->row_height - 1; - } - } -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_week_view_event_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EWeekViewEventItem *wveitem; - EWeekView *week_view; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - GtkStyle *style; - GdkGC *gc; - gint x1, y1, x2, y2, time_x, time_y; - gint icon_x, icon_y, time_width, min_end_time_x, max_icon_x; - gint rect_x, rect_w, rect_x2; - gboolean one_day_event, editing_span = FALSE; - gint start_hour, start_minute, end_hour, end_minute; - gboolean draw_start, draw_end; - gboolean draw_start_triangle = FALSE, draw_end_triangle = FALSE; - GdkRectangle clip_rect; - -#if 0 - g_print ("In e_week_view_event_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wveitem = E_WEEK_VIEW_EVENT_ITEM (canvas_item); - week_view = E_WEEK_VIEW (GTK_WIDGET (canvas_item->canvas)->parent); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (wveitem->event_num == -1 || wveitem->span_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + wveitem->span_num); - - style = GTK_WIDGET (week_view)->style; - gc = week_view->main_gc; - - x1 = canvas_item->x1 - x; - y1 = canvas_item->y1 - y; - x2 = canvas_item->x2 - x; - y2 = canvas_item->y2 - y; - - if (x1 == x2 || y1 == y2) - return; - - icon_x = 0; - icon_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD; - - /* Get the start & end times in 24-hour format. */ - start_hour = event->start_minute / 60; - start_minute = event->start_minute % 60; - end_hour = event->end_minute / 60; - end_minute = event->end_minute % 60; - - time_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT - + E_WEEK_VIEW_EVENT_TEXT_Y_PAD; - - time_width = e_week_view_get_time_string_width (week_view); - - one_day_event = e_week_view_is_one_day_event (week_view, - wveitem->event_num); - if (one_day_event) { - time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; - - /* Draw the start and end times, as required. */ - switch (week_view->time_format) { - case E_WEEK_VIEW_TIME_BOTH_SMALL_MIN: - case E_WEEK_VIEW_TIME_BOTH: - draw_start = TRUE; - draw_end = TRUE; - break; - - case E_WEEK_VIEW_TIME_START_SMALL_MIN: - case E_WEEK_VIEW_TIME_START: - draw_start = TRUE; - draw_end = FALSE; - break; - - case E_WEEK_VIEW_TIME_NONE: - draw_start = FALSE; - draw_end = FALSE; - break; - default: - g_assert_not_reached(); - draw_start = FALSE; - draw_end = FALSE; - break; - } - - if (draw_start) { - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - start_hour, start_minute); - time_x += time_width; - } - - if (draw_end) { - time_x += E_WEEK_VIEW_EVENT_TIME_SPACING; - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - end_hour, end_minute); - time_x += time_width; - } - - icon_x = time_x; - if (draw_start) - icon_x += E_WEEK_VIEW_EVENT_TIME_X_PAD; - - /* Draw the icons. */ - e_week_view_event_item_draw_icons (wveitem, drawable, - icon_x, icon_y, - x2, FALSE); - - } else { - rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; - rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - - E_WEEK_VIEW_EVENT_R_PAD + 1; - - /* Draw the triangles at the start & end, if needed. - They also use the first few pixels at the edge of the - event so we update rect_x & rect_w so we don't draw over - them. */ - if (event->start < week_view->day_starts[span->start_day]) { - draw_start_triangle = TRUE; - rect_x += 2; - rect_w -= 2; - } - - if (event->end > week_view->day_starts[span->start_day - + span->num_days]) { - draw_end_triangle = TRUE; - rect_w -= 2; - } - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); - gdk_draw_rectangle (drawable, gc, TRUE, - rect_x, y1 + 1, rect_w, y2 - y1 - 1); - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); - rect_x2 = rect_x + rect_w - 1; - gdk_draw_line (drawable, gc, rect_x, y1, rect_x2, y1); - gdk_draw_line (drawable, gc, rect_x, y2, rect_x2, y2); - - if (draw_start_triangle) { - e_week_view_event_item_draw_triangle (wveitem, drawable, x1 + E_WEEK_VIEW_EVENT_L_PAD + 2, y1, -3, y2 - y1 + 1); - } else { - gdk_draw_line (drawable, gc, rect_x, y1, rect_x, y2); - } - - if (draw_end_triangle) { - e_week_view_event_item_draw_triangle (wveitem, drawable, x2 - E_WEEK_VIEW_EVENT_R_PAD - 2, y1, 3, y2 - y1 + 1); - } else { - gdk_draw_line (drawable, gc, rect_x2, y1, rect_x2, y2); - } - - if (span->text_item && E_TEXT (span->text_item)->editing) - editing_span = TRUE; - - /* Draw the start & end times, if they are not on day - boundaries. The start time would always be shown if it was - needed, though it may be clipped as the window shrinks. - The end time is only displayed if there is enough room. - We calculate the minimum position for the end time, which - depends on whether the start time is displayed. If the end - time doesn't fit, then we don't draw it. */ - min_end_time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD; - if (!editing_span - && event->start > week_view->day_starts[span->start_day]) { - time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD; - - clip_rect.x = x1; - clip_rect.y = y1; - clip_rect.width = x2 - x1 - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH + 1; - clip_rect.height = y2 - y1 + 1; - gdk_gc_set_clip_rectangle (gc, &clip_rect); - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT]); - - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - start_hour, start_minute); - - gdk_gc_set_clip_rectangle (gc, NULL); - - /* We don't want the end time to be drawn over the - start time, so we increase the minimum position. */ - min_end_time_x += time_width - + E_WEEK_VIEW_EVENT_TIME_X_PAD; - } - - max_icon_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD; - - if (!editing_span - && event->end < week_view->day_starts[span->start_day - + span->num_days]) { - /* Calculate where the end time should be displayed. */ - time_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD - - time_width; - - /* Draw the end time, if the position is greater than - the minimum calculated above. */ - if (time_x >= min_end_time_x) { - e_week_view_draw_time (week_view, drawable, - time_x, time_y, - end_hour, end_minute); - max_icon_x -= time_width - + E_WEEK_VIEW_EVENT_TIME_X_PAD; - } - } - - /* Draw the icons. */ - if (span->text_item - && (week_view->editing_event_num != wveitem->event_num - || week_view->editing_span_num != wveitem->span_num)) { - icon_x = span->text_item->x1 - E_WEEK_VIEW_ICON_R_PAD - x; - e_week_view_event_item_draw_icons (wveitem, drawable, - icon_x, icon_y, - max_icon_x, TRUE); - } - } -} - - -static void -e_week_view_draw_time (EWeekView *week_view, - GdkDrawable *drawable, - gint time_x, - gint time_y, - gint hour, - gint minute) -{ - GtkStyle *style; - GdkGC *gc; - gint hour_to_display, suffix_width; - gint time_y_normal_font, time_y_small_font; - gchar buffer[128], *suffix; - PangoLayout *layout; - PangoFontDescription *small_font_desc; - - style = gtk_widget_get_style (GTK_WIDGET (week_view)); - small_font_desc = week_view->small_font_desc; - gc = week_view->main_gc; - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT]); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (week_view), NULL); - - time_y_normal_font = time_y_small_font = time_y; - if (small_font_desc) - time_y_small_font = time_y; - - e_week_view_convert_time_to_display (week_view, hour, &hour_to_display, - &suffix, &suffix_width); - - if (week_view->use_small_font && week_view->small_font_desc) { - g_snprintf (buffer, sizeof (buffer), "%2i:%02i", - hour_to_display, minute); - - /* Draw the hour. */ - if (hour_to_display < 10) { - pango_layout_set_text (layout, buffer + 1, 1); - gdk_draw_layout (drawable, gc, - time_x + week_view->digit_width, - time_y_normal_font, - layout); - } else { - pango_layout_set_text (layout, buffer, 2); - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - - time_x += week_view->digit_width * 2; - - /* Draw the start minute, in the small font. */ - pango_layout_set_font_description (layout, week_view->small_font_desc); - pango_layout_set_text (layout, buffer + 3, 2); - gdk_draw_layout (drawable, gc, - time_x, - time_y_small_font, - layout); - - pango_layout_set_font_description (layout, style->font_desc); - - time_x += week_view->small_digit_width * 2; - - /* Draw the 'am'/'pm' suffix, if 12-hour format. */ - if (!week_view->use_24_hour_format) { - pango_layout_set_text (layout, suffix, -1); - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - } else { - /* Draw the start time in one go. */ - g_snprintf (buffer, sizeof (buffer), "%2i:%02i%s", - hour_to_display, minute, suffix); - if (hour_to_display < 10) { - pango_layout_set_text (layout, buffer + 1, -1); - gdk_draw_layout (drawable, gc, - time_x + week_view->digit_width, - time_y_normal_font, - layout); - } else { - pango_layout_set_text (layout, buffer, -1); - gdk_draw_layout (drawable, gc, - time_x, - time_y_normal_font, - layout); - } - - } - - g_object_unref (layout); -} - - -static void -e_week_view_event_item_draw_icons (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint icon_x, - gint icon_y, - gint x2, - gboolean right_align) -{ - EWeekView *week_view; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - CalComponent *comp; - GdkGC *gc; - gint num_icons = 0, icon_x_inc; - gboolean draw_reminder_icon = FALSE, draw_recurrence_icon = FALSE; - gboolean draw_timezone_icon = FALSE; - GSList *categories_list, *elem; - - week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + wveitem->span_num); - comp = event->comp; - - gc = week_view->main_gc; - - if (cal_component_has_alarms (comp)) { - draw_reminder_icon = TRUE; - num_icons++; - } - - if (cal_component_has_recurrences (comp)) { - draw_recurrence_icon = TRUE; - num_icons++; - } - - if (event->different_timezone) { - draw_timezone_icon = TRUE; - num_icons++; - } - - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (e_categories_config_get_icon_for (category, &pixmap, &mask)) - num_icons++; - } - - icon_x_inc = E_WEEK_VIEW_ICON_WIDTH + E_WEEK_VIEW_ICON_X_PAD; - - if (right_align) - icon_x -= icon_x_inc * num_icons; - - if (draw_reminder_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, week_view->reminder_mask); - gdk_draw_pixmap (drawable, gc, - week_view->reminder_icon, - 0, 0, icon_x, icon_y, - E_WEEK_VIEW_ICON_WIDTH, - E_WEEK_VIEW_ICON_HEIGHT); - icon_x += icon_x_inc; - } - - if (draw_recurrence_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, week_view->recurrence_mask); - gdk_draw_pixmap (drawable, gc, - week_view->recurrence_icon, - 0, 0, icon_x, icon_y, - E_WEEK_VIEW_ICON_WIDTH, - E_WEEK_VIEW_ICON_HEIGHT); - icon_x += icon_x_inc; - } - - if (draw_timezone_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, week_view->timezone_mask); - gdk_draw_pixmap (drawable, gc, - week_view->timezone_icon, - 0, 0, icon_x, icon_y, - E_WEEK_VIEW_ICON_WIDTH, - E_WEEK_VIEW_ICON_HEIGHT); - icon_x += icon_x_inc; - } - - /* draw categories icons */ - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (!e_categories_config_get_icon_for (category, &pixmap, &mask)) - continue; - - if (icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - if (mask != NULL) - gdk_gc_set_clip_mask (gc, mask); - gdk_draw_pixmap (drawable, gc, - pixmap, - 0, 0, icon_x, icon_y, - E_WEEK_VIEW_ICON_WIDTH, - E_WEEK_VIEW_ICON_HEIGHT); - icon_x += icon_x_inc; - } - gdk_pixmap_unref (pixmap); - if (mask != NULL) - gdk_bitmap_unref (mask); - } - - cal_component_free_categories_list (categories_list); - - gdk_gc_set_clip_mask (gc, NULL); -} - - -/* This draws a little triangle to indicate that an event extends past - the days visible on screen. */ -static void -e_week_view_event_item_draw_triangle (EWeekViewEventItem *wveitem, - GdkDrawable *drawable, - gint x, - gint y, - gint w, - gint h) -{ - EWeekView *week_view; - GdkGC *gc; - GdkPoint points[3]; - gint c1, c2; - - week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent); - - gc = week_view->main_gc; - - points[0].x = x; - points[0].y = y; - points[1].x = x + w; - points[1].y = y + (h / 2) - 1; - points[2].x = x; - points[2].y = y + h - 1; - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]); - gdk_draw_polygon (drawable, gc, TRUE, points, 3); - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); - - /* If the height is odd we can use the same central point for both - lines. If it is even we use different end-points. */ - c1 = c2 = y + (h / 2); - if (h % 2 == 0) - c1--; - - gdk_draw_line (drawable, gc, x, y, x + w, c1); - gdk_draw_line (drawable, gc, x, y + h - 1, x + w, c2); -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_week_view_event_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_week_view_event_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EWeekViewEventItem *wveitem; - - wveitem = E_WEEK_VIEW_EVENT_ITEM (item); - - switch (event->type) { - case GDK_2BUTTON_PRESS: - return e_week_view_event_item_double_click (wveitem, event); - case GDK_BUTTON_PRESS: - return e_week_view_event_item_button_press (wveitem, event); - case GDK_BUTTON_RELEASE: - return e_week_view_event_item_button_release (wveitem, event); - case GDK_MOTION_NOTIFY: - break; - default: - break; - } - - return FALSE; -} - - -static gboolean -e_week_view_event_item_button_press (EWeekViewEventItem *wveitem, - GdkEvent *bevent) -{ - EWeekView *week_view; - EWeekViewPosition pos; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + wveitem->span_num); - -#if 0 - g_print ("In e_week_view_event_item_button_press\n"); -#endif - - pos = e_week_view_event_item_get_position (wveitem, bevent->button.x, - bevent->button.y); - if (pos == E_WEEK_VIEW_POS_NONE) - return FALSE; - - if (bevent->button.button == 1) { - week_view->pressed_event_num = wveitem->event_num; - week_view->pressed_span_num = wveitem->span_num; - - /* Ignore clicks on the event while editing. */ - if (E_TEXT (span->text_item)->editing) - return FALSE; - - /* Remember the item clicked and the mouse position, - so we can start a drag if the mouse moves. */ - week_view->drag_event_x = bevent->button.x; - week_view->drag_event_y = bevent->button.y; - - /* FIXME: Remember the day offset from the start of the event. - */ - - return TRUE; - } else if (bevent->button.button == 3) { - if (!GTK_WIDGET_HAS_FOCUS (week_view)) - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - - e_week_view_set_selected_time_range_visible (week_view, event->start, event->end); - - e_week_view_show_popup_menu (week_view, - (GdkEventButton*) bevent, - wveitem->event_num); - gtk_signal_emit_stop_by_name (GTK_OBJECT (item->canvas), - "button_press_event"); - - return TRUE; - } - - return FALSE; -} - - -static gboolean -e_week_view_event_item_button_release (EWeekViewEventItem *wveitem, - GdkEvent *event) -{ - EWeekView *week_view; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - -#if 0 - g_print ("In e_week_view_event_item_button_release\n"); -#endif - - if (week_view->pressed_event_num != -1 - && week_view->pressed_event_num == wveitem->event_num - && week_view->pressed_span_num == wveitem->span_num) { - e_week_view_start_editing_event (week_view, - wveitem->event_num, - wveitem->span_num, - NULL); - week_view->pressed_event_num = -1; - return TRUE; - } - - week_view->pressed_event_num = -1; - - return FALSE; -} - - -static gboolean -e_week_view_event_item_double_click (EWeekViewEventItem *wveitem, - GdkEvent *bevent) -{ - EWeekView *week_view; - EWeekViewEvent *event; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - event = &g_array_index (week_view->events, EWeekViewEvent, - wveitem->event_num); - - e_week_view_stop_editing_event (week_view); - - if (week_view->calendar) - gnome_calendar_edit_object (week_view->calendar, event->comp, FALSE); - else - g_warning ("Calendar not set"); - - return TRUE; -} - - -static EWeekViewPosition -e_week_view_event_item_get_position (EWeekViewEventItem *wveitem, - gdouble x, - gdouble y) -{ - EWeekView *week_view; - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (wveitem); - - week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent); - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), E_WEEK_VIEW_POS_NONE); - -#if 0 - g_print ("In e_week_view_event_item_get_position item: %g,%g %g,%g point: %g,%g\n", item->x1, item->y1, item->x2, item->y2, x, y); -#endif - - if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD - || x >= item->x2 - E_WEEK_VIEW_EVENT_R_PAD) - return E_WEEK_VIEW_POS_NONE; - - /* Support left/right edge for long events only. */ - if (!e_week_view_is_one_day_event (week_view, wveitem->event_num)) { - if (x < item->x1 + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD) - return E_WEEK_VIEW_POS_LEFT_EDGE; - - if (x >= item->x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD) - return E_WEEK_VIEW_POS_RIGHT_EDGE; - } - - return E_WEEK_VIEW_POS_EVENT; -} diff --git a/calendar/gui/e-week-view-event-item.h b/calendar/gui/e-week-view-event-item.h deleted file mode 100644 index 20cace0132..0000000000 --- a/calendar/gui/e-week-view-event-item.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_WEEK_VIEW_EVENT_ITEM_H_ -#define _E_WEEK_VIEW_EVENT_ITEM_H_ - -#include "e-week-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EWeekViewEventItem - displays the background, times and icons for an event - * in the week/month views. A separate EText canvas item is used to display & - * edit the text. - */ - -#define E_WEEK_VIEW_EVENT_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_week_view_event_item_get_type (), EWeekViewEventItem)) -#define E_WEEK_VIEW_EVENT_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_week_view_event_item_get_type ())) -#define E_IS_WEEK_VIEW_EVENT_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_week_view_event_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The event index in the EWeekView events array. */ - gint event_num; - - /* The span index within the event. */ - gint span_num; -} EWeekViewEventItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EWeekViewEventItemClass; - - -GtkType e_week_view_event_item_get_type (void); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_WEEK_VIEW_EVENT_ITEM_H_ */ diff --git a/calendar/gui/e-week-view-layout.c b/calendar/gui/e-week-view-layout.c deleted file mode 100644 index 4ab1cf1fd9..0000000000 --- a/calendar/gui/e-week-view-layout.c +++ /dev/null @@ -1,425 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * Lays out events for the Week & Month views of the calendar. It is also - * used for printing. - */ - -#include <config.h> - -#include "e-week-view-layout.h" - - -static void e_week_view_layout_event (EWeekViewEvent *event, - guint8 *grid, - GArray *spans, - GArray *old_spans, - gboolean multi_week_view, - gint weeks_shown, - gboolean compress_weekend, - gint start_weekday, - time_t *day_starts, - gint *rows_per_day); -static gint e_week_view_find_day (time_t time_to_find, - gboolean include_midnight_in_prev_day, - gint days_shown, - time_t *day_starts); -static gint e_week_view_find_span_end (gboolean multi_week_view, - gboolean compress_weekend, - gint display_start_day, - gint day); - - -GArray* -e_week_view_layout_events (GArray *events, - GArray *old_spans, - gboolean multi_week_view, - gint weeks_shown, - gboolean compress_weekend, - gint start_weekday, - time_t *day_starts, - gint *rows_per_day) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint num_days, day, event_num, span_num; - guint8 *grid; - GArray *spans; - - /* This is a temporary 2-d grid which is used to place events. - Each element is 0 if the position is empty, or 1 if occupied. - We allocate the maximum size possible here, assuming that each - event will need its own row. */ - grid = g_new0 (guint8, E_WEEK_VIEW_MAX_ROWS_PER_CELL * 7 - * E_WEEK_VIEW_MAX_WEEKS); - - /* We create a new array of spans, which will replace the old one. */ - spans = g_array_new (FALSE, FALSE, sizeof (EWeekViewEventSpan)); - - /* Clear the number of rows used per day. */ - num_days = multi_week_view ? weeks_shown * 7 : 7; - for (day = 0; day < num_days; day++) { - rows_per_day[day] = 0; - } - - /* Iterate over the events, finding which weeks they cover, and putting - them in the first free row available. */ - for (event_num = 0; event_num < events->len; event_num++) { - event = &g_array_index (events, EWeekViewEvent, event_num); - e_week_view_layout_event (event, grid, spans, old_spans, - multi_week_view, - weeks_shown, compress_weekend, - start_weekday, day_starts, - rows_per_day); - } - - /* Free the grid. */ - g_free (grid); - - /* Destroy the old spans array, destroying any unused canvas items. */ - if (old_spans) { - for (span_num = 0; span_num < old_spans->len; span_num++) { - span = &g_array_index (old_spans, EWeekViewEventSpan, - span_num); - if (span->background_item) - gtk_object_destroy (GTK_OBJECT (span->background_item)); - if (span->text_item) - gtk_object_destroy (GTK_OBJECT (span->text_item)); - } - g_array_free (old_spans, TRUE); - } - - return spans; -} - - -static void -e_week_view_layout_event (EWeekViewEvent *event, - guint8 *grid, - GArray *spans, - GArray *old_spans, - gboolean multi_week_view, - gint weeks_shown, - gboolean compress_weekend, - gint start_weekday, - time_t *day_starts, - gint *rows_per_day) -{ - gint start_day, end_day, span_start_day, span_end_day, rows_per_cell; - gint free_row, row, day, span_num, spans_index, num_spans, days_shown; - EWeekViewEventSpan span, *old_span; - - days_shown = multi_week_view ? weeks_shown * 7 : 7; - start_day = e_week_view_find_day (event->start, FALSE, days_shown, - day_starts); - end_day = e_week_view_find_day (event->end, TRUE, days_shown, - day_starts); - start_day = CLAMP (start_day, 0, days_shown - 1); - end_day = CLAMP (end_day, 0, days_shown - 1); - -#if 0 - g_print ("In e_week_view_layout_event Start:%i End: %i\n", - start_day, end_day); -#endif - - /* Iterate through each of the spans of the event, where each span - is a sequence of 1 or more days displayed next to each other. */ - span_start_day = start_day; - rows_per_cell = E_WEEK_VIEW_MAX_ROWS_PER_CELL; - span_num = 0; - spans_index = spans->len; - num_spans = 0; - while (span_start_day <= end_day) { - span_end_day = e_week_view_find_span_end (multi_week_view, - compress_weekend, - start_weekday, - span_start_day); - span_end_day = MIN (span_end_day, end_day); -#if 0 - g_print (" Span start:%i end:%i\n", span_start_day, - span_end_day); -#endif - /* Try each row until we find a free one or we fall off the - bottom of the available rows. */ - row = 0; - free_row = -1; - while (free_row == -1 && row < rows_per_cell) { - free_row = row; - for (day = span_start_day; day <= span_end_day; - day++) { - if (grid[day * rows_per_cell + row]) { - free_row = -1; - break; - } - } - row++; - }; - - if (free_row != -1) { - /* Mark the cells as full. */ - for (day = span_start_day; day <= span_end_day; - day++) { - grid[day * rows_per_cell + free_row] = 1; - rows_per_day[day] = MAX (rows_per_day[day], - free_row + 1); - } -#if 0 - g_print (" Span start:%i end:%i row:%i\n", - span_start_day, span_end_day, free_row); -#endif - /* Add the span to the array, and try to reuse any - canvas items from the old spans. */ - span.start_day = span_start_day; - span.num_days = span_end_day - span_start_day + 1; - span.row = free_row; - span.background_item = NULL; - span.text_item = NULL; - if (event->num_spans > span_num) { - old_span = &g_array_index (old_spans, EWeekViewEventSpan, event->spans_index + span_num); - span.background_item = old_span->background_item; - span.text_item = old_span->text_item; - old_span->background_item = NULL; - old_span->text_item = NULL; - } - - g_array_append_val (spans, span); - num_spans++; - } - - span_start_day = span_end_day + 1; - span_num++; - } - - /* Set the event's spans. */ - event->spans_index = spans_index; - event->num_spans = num_spans; -} - - -/* Finds the day containing the given time. - If include_midnight_in_prev_day is TRUE then if the time exactly - matches the start of a day the previous day is returned. This is useful - when calculating the end day of an event. */ -static gint -e_week_view_find_day (time_t time_to_find, - gboolean include_midnight_in_prev_day, - gint days_shown, - time_t *day_starts) -{ - gint day; - - if (time_to_find < day_starts[0]) - return -1; - if (time_to_find > day_starts[days_shown]) - return days_shown; - - for (day = 1; day <= days_shown; day++) { - if (time_to_find <= day_starts[day]) { - if (time_to_find == day_starts[day] - && !include_midnight_in_prev_day) - return day; - return day - 1; - } - } - - g_assert_not_reached (); - return days_shown; -} - - -/* This returns the last possible day in the same span as the given day. - A span is all the days which are displayed next to each other from left to - right. In the week view all spans are only 1 day, since Tuesday is below - Monday rather than beside it etc. In the month view, if the weekends are not - compressed then each week is a span, otherwise we have to break a span up - on Saturday, use a separate span for Sunday, and start again on Monday. */ -static gint -e_week_view_find_span_end (gboolean multi_week_view, - gboolean compress_weekend, - gint display_start_day, - gint day) -{ - gint week, col, sat_col, end_col; - - if (multi_week_view) { - week = day / 7; - col = day % 7; - - /* We default to the last column in the row. */ - end_col = 6; - - /* If the weekend is compressed we must end any spans on - Saturday and Sunday. */ - if (compress_weekend) { - sat_col = (5 + 7 - display_start_day) % 7; - if (col <= sat_col) - end_col = sat_col; - else if (col == sat_col + 1) - end_col = sat_col + 1; - } - - return week * 7 + end_col; - } else { - return day; - } -} - - -void -e_week_view_layout_get_day_position (gint day, - gboolean multi_week_view, - gint weeks_shown, - gint display_start_day, - gboolean compress_weekend, - gint *day_x, - gint *day_y, - gint *rows) -{ - gint week, day_of_week, row, col, weekend_col, box, weekend_box; - - *day_x = *day_y = *rows = 0; - g_return_if_fail (day >= 0); - - if (multi_week_view) { - g_return_if_fail (day < weeks_shown * 7); - - week = day / 7; - col = day % 7; - day_of_week = (display_start_day + day) % 7; - if (compress_weekend && day_of_week >= 5) { - /* In the compressed view Saturday is above Sunday and - both have just one row as opposed to 2 for all the - other days. */ - if (day_of_week == 5) { - *day_y = week * 2; - *rows = 1; - } else { - *day_y = week * 2 + 1; - *rows = 1; - col--; - } - /* Both Saturday and Sunday are in the same column. */ - *day_x = col; - } else { - /* If the weekend is compressed and the day is after - the weekend we have to move back a column. */ - if (compress_weekend) { - /* Calculate where the weekend column is. - Note that 5 is Saturday. */ - weekend_col = (5 + 7 - display_start_day) % 7; - if (col > weekend_col) - col--; - } - - *day_y = week * 2; - *rows = 2; - *day_x = col; - } - } else { - g_return_if_fail (day < 7); - - /* Calculate which box to place the day in, from 0-5. - Note that in the week view the weekends are always - compressed and share a box. */ - box = day; - day_of_week = (display_start_day + day) % 7; - weekend_box = (5 + 7 - display_start_day) % 7; - if (box > weekend_box) - box--; - - if (box < 3) - *day_x = 0; - else - *day_x = 1; - - row = (box % 3) * 2; - if (day_of_week < 5) { - *day_y = row; - *rows = 2; - } else if (day_of_week == 5) { - /* Saturday. */ - *day_y = row; - *rows = 1; - - } else { - /* Sunday. */ - *day_y = row + 1; - *rows = 1; - } - } -} - - -/* Returns TRUE if the event span is visible or FALSE if it isn't. - It also returns the number of days of the span that are visible. - Usually this can easily be determined by the start & end days and row of - the span, which are set in e_week_view_layout_event(). Though we need a - special case for the weekends when they are compressed, since the span may - not fit. */ -gboolean -e_week_view_layout_get_span_position (EWeekViewEvent *event, - EWeekViewEventSpan *span, - gint rows_per_cell, - gint rows_per_compressed_cell, - gint display_start_day, - gboolean multi_week_view, - gboolean compress_weekend, - gint *span_num_days) -{ - gint end_day_of_week; - - if (span->row >= rows_per_cell) - return FALSE; - - end_day_of_week = (display_start_day + span->start_day - + span->num_days - 1) % 7; - *span_num_days = span->num_days; - /* Check if the row will not be visible in compressed cells. */ - if (span->row >= rows_per_compressed_cell) { - if (multi_week_view) { - if (compress_weekend) { - /* If it ends on a Saturday and is 1 day long - we skip it, else we shorten it. If it ends - on a Sunday it must be 1 day long and we - skip it. */ - if (end_day_of_week == 5) { /* Sat */ - if (*span_num_days == 1) { - return FALSE; - } else { - (*span_num_days)--; - } - } else if (end_day_of_week == 6) { /* Sun */ - return FALSE; - } - } - } else { - /* All spans are 1 day long in the week view, so we - just skip it. */ - if (end_day_of_week > 4) - return FALSE; - } - } - - return TRUE; -} diff --git a/calendar/gui/e-week-view-layout.h b/calendar/gui/e-week-view-layout.h deleted file mode 100644 index 2c6d5a29d8..0000000000 --- a/calendar/gui/e-week-view-layout.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_WEEK_VIEW_LAYOUT_H_ -#define _E_WEEK_VIEW_LAYOUT_H_ - -#include "e-week-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* I've split these functions away from EWeekView so we can use them for - printing. */ - -GArray* e_week_view_layout_events (GArray *events, - GArray *old_spans, - gboolean multi_week_view, - gint weeks_shown, - gboolean compress_weekend, - gint start_weekday, - time_t *day_starts, - gint *rows_per_day); - -/* Returns which 'cell' in the table the day appears in. Note that most days - have a height of 2 rows, but Sat/Sun are sometimes compressed so they have - a height of only 1 row. */ -void e_week_view_layout_get_day_position(gint day, - gboolean multi_week_view, - gint weeks_shown, - gint display_start_day, - gboolean compress_weekend, - gint *cell_x, - gint *cell_y, - gint *rows); - -gboolean e_week_view_layout_get_span_position (EWeekViewEvent *event, - EWeekViewEventSpan *span, - gint rows_per_cell, - gint rows_per_compressed_cell, - gint display_start_day, - gboolean multi_week_view, - gboolean compress_weekend, - gint *span_num_days); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_WEEK_VIEW_LAYOUT_H_ */ diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c deleted file mode 100644 index 68a1681a32..0000000000 --- a/calendar/gui/e-week-view-main-item.c +++ /dev/null @@ -1,399 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EWeekViewMainItem - displays the background grid and dates for the Week and - * Month calendar views. - */ - -#include <config.h> - -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include "e-week-view-main-item.h" - -static void e_week_view_main_item_class_init (EWeekViewMainItemClass *class); -static void e_week_view_main_item_init (EWeekViewMainItem *wvmitem); - -static void e_week_view_main_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_week_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags); -static void e_week_view_main_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, - gint day, - GDate *date, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height); -static double e_week_view_main_item_point (GnomeCanvasItem *item, - double x, - double y, - int cx, - int cy, - GnomeCanvasItem **actual_item); - - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_WEEK_VIEW -}; - -E_MAKE_TYPE (e_week_view_main_item, "EWeekViewMainItem", EWeekViewMainItem, - e_week_view_main_item_class_init, e_week_view_main_item_init, - GNOME_TYPE_CANVAS_ITEM); - -static void -e_week_view_main_item_class_init (EWeekViewMainItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EWeekViewMainItem::week_view", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_WEEK_VIEW); - - object_class->set_arg = e_week_view_main_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_week_view_main_item_update; - item_class->draw = e_week_view_main_item_draw; - item_class->point = e_week_view_main_item_point; -} - - -static void -e_week_view_main_item_init (EWeekViewMainItem *wvmitem) -{ - wvmitem->week_view = NULL; -} - - -static void -e_week_view_main_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EWeekViewMainItem *wvmitem; - - item = GNOME_CANVAS_ITEM (o); - wvmitem = E_WEEK_VIEW_MAIN_ITEM (o); - - switch (arg_id){ - case ARG_WEEK_VIEW: - wvmitem->week_view = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_week_view_main_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_week_view_main_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EWeekViewMainItem *wvmitem; - EWeekView *week_view; - GDate date; - gint num_days, day, day_x, day_y, day_w, day_h; - -#if 0 - g_print ("In e_week_view_main_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wvmitem = E_WEEK_VIEW_MAIN_ITEM (canvas_item); - week_view = wvmitem->week_view; - g_return_if_fail (week_view != NULL); - - /* Step through each of the days. */ - date = week_view->first_day_shown; - - /* If no date has been set, we just use Dec 1999/January 2000. */ - if (!g_date_valid (&date)) - g_date_set_dmy (&date, 27, 12, 1999); - - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - for (day = 0; day < num_days; day++) { - e_week_view_get_day_position (week_view, day, - &day_x, &day_y, - &day_w, &day_h); - /* Skip any days which are outside the area. */ - if (day_x < x + width && day_x + day_w >= x - && day_y < y + height && day_y + day_h >= y) { - e_week_view_main_item_draw_day (wvmitem, day, &date, - drawable, - day_x - x, day_y - y, - day_w, day_h); - } - g_date_add_days (&date, 1); - } -} - - -static void -e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem, - gint day, - GDate *date, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) -{ - EWeekView *week_view; - GtkStyle *style; - GdkGC *gc; - gint right_edge, bottom_edge, date_width, date_x, line_y; - gboolean show_day_name, show_month_name, selected; - gchar buffer[128], *format_string; - gint month, day_of_month, max_width; - GdkColor *bg_color; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - -#if 0 - g_print ("Drawing Day:%i at %i,%i\n", day, x, y); -#endif - week_view = wvmitem->week_view; - style = gtk_widget_get_style (GTK_WIDGET (week_view)); - gc = week_view->main_gc; - - /* Set up Pango prerequisites */ - font_desc = style->font_desc; - pango_context = gtk_widget_get_pango_context (GTK_WIDGET (week_view)); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - - g_return_if_fail (gc != NULL); - - month = g_date_month (date); - day_of_month = g_date_day (date); - line_y = y + E_WEEK_VIEW_DATE_T_PAD + - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + - E_WEEK_VIEW_DATE_LINE_T_PAD; - - /* Draw the background of the day. In the month view odd months are - one color and even months another, so you can easily see when each - month starts (defaults are white for odd - January, March, ... and - light gray for even). In the week view the background is always the - same color, the color used for the odd months in the month view. */ - if (week_view->multi_week_view && (month % 2 == 0)) - bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS]; - else - bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS]; - - gdk_gc_set_foreground (gc, bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, x, y, width, height); - - /* Draw the lines on the right and bottom of the cell. The canvas is - sized so that the lines on the right & bottom edges will be off the - edge of the canvas, so we don't have to worry about them. */ - right_edge = x + width - 1; - bottom_edge = y + height - 1; - - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_GRID]); - gdk_draw_line (drawable, gc, - right_edge, y, right_edge, bottom_edge); - gdk_draw_line (drawable, gc, - x, bottom_edge, right_edge, bottom_edge); - - /* If the day is selected, draw the blue background. */ - selected = TRUE; - if (week_view->selection_start_day == -1 - || week_view->selection_start_day > day - || week_view->selection_end_day < day) - selected = FALSE; - if (selected) { - if (GTK_WIDGET_HAS_FOCUS (week_view)) - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_SELECTED]); - else - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_SELECTED_UNFOCUSSED]); - - if (week_view->multi_week_view) { - gdk_draw_rectangle (drawable, gc, TRUE, - x + 2, y + 1, - width - 5, - E_WEEK_VIEW_DATE_T_PAD - 1 + - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics))); - } else { - gdk_draw_rectangle (drawable, gc, TRUE, - x + 2, y + 1, - width - 5, line_y - y); - } - } - - /* Display the date in the top of the cell. - In the week view, display the long format "10 January" in all cells, - or abbreviate it to "10 Jan" or "10" if that doesn't fit. - In the month view, only use the long format for the first cell and - the 1st of each month, otherwise use "10". */ - show_day_name = FALSE; - show_month_name = FALSE; - if (!week_view->multi_week_view) { - show_day_name = TRUE; - show_month_name = TRUE; - } else if (day == 0 || day_of_month == 1) { - show_month_name = TRUE; - } - - /* Now find the longest form of the date that will fit. */ - max_width = width - 4; - format_string = NULL; - if (show_day_name) { - if (week_view->max_day_width + week_view->digit_width * 2 - + week_view->space_width * 2 - + week_view->month_widths[month - 1] < max_width) - /* strftime format %A = full weekday name, %d = day of - month, %B = full month name. You can change the - order but don't change the specifiers or add - anything. */ - format_string = _("%A %d %B"); - else if (week_view->max_abbr_day_width - + week_view->digit_width * 2 - + week_view->space_width * 2 - + week_view->abbr_month_widths[month - 1] < max_width) - /* strftime format %a = abbreviated weekday name, - %d = day of month, %b = abbreviated month name. - You can change the order but don't change the - specifiers or add anything. */ - format_string = _("%a %d %b"); - } - if (!format_string && show_month_name) { - if (week_view->digit_width * 2 + week_view->space_width - + week_view->month_widths[month - 1] < max_width) - /* strftime format %d = day of month, %B = full - month name. You can change the order but don't - change the specifiers or add anything. */ - format_string = _("%d %B"); - else if (week_view->digit_width * 2 + week_view->space_width - + week_view->abbr_month_widths[month - 1] < max_width) - /* strftime format %d = day of month, %b = abbreviated - month name. You can change the order but don't - change the specifiers or add anything. */ - format_string = _("%d %b"); - } - - if (selected) { - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED]); - } else if (week_view->multi_week_view) { - struct icaltimetype tt; - - /* Check if we are drawing today */ - tt = icaltime_from_timet_with_zone (time (NULL), FALSE, week_view->zone); - if (g_date_year (date) == tt.year - && g_date_month (date) == tt.month - && g_date_day (date) == tt.day) - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_TODAY]); - else - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]); - } else { - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]); - } - - g_date_strftime (buffer, sizeof (buffer), - format_string ? format_string : "%d", date); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (week_view), buffer); - pango_layout_get_pixel_size (layout, &date_width, NULL); - date_x = x + width - date_width - E_WEEK_VIEW_DATE_R_PAD; - date_x = MAX (date_x, x + 1); - - gdk_draw_layout (drawable, gc, - date_x, - y + E_WEEK_VIEW_DATE_T_PAD, - layout); - g_object_unref (layout); - - /* Draw the line under the date. */ - if (!week_view->multi_week_view) { - gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_GRID]); - gdk_draw_line (drawable, gc, - x + E_WEEK_VIEW_DATE_LINE_L_PAD, line_y, - right_edge, line_y); - } - - pango_font_metrics_unref (font_metrics); -} - - - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_week_view_main_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - diff --git a/calendar/gui/e-week-view-main-item.h b/calendar/gui/e-week-view-main-item.h deleted file mode 100644 index 35740479da..0000000000 --- a/calendar/gui/e-week-view-main-item.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_WEEK_VIEW_MAIN_ITEM_H_ -#define _E_WEEK_VIEW_MAIN_ITEM_H_ - -#include "e-week-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EWeekViewMainItem - displays the background grid and dates for the Week and - * Month calendar views. - */ - -#define E_WEEK_VIEW_MAIN_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_week_view_main_item_get_type (), EWeekViewMainItem)) -#define E_WEEK_VIEW_MAIN_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_week_view_main_item_get_type ())) -#define E_IS_WEEK_VIEW_MAIN_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_week_view_main_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The parent EWeekView widget. */ - EWeekView *week_view; -} EWeekViewMainItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EWeekViewMainItemClass; - - -GtkType e_week_view_main_item_get_type (void); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_WEEK_VIEW_MAIN_ITEM_H_ */ diff --git a/calendar/gui/e-week-view-titles-item.c b/calendar/gui/e-week-view-titles-item.c deleted file mode 100644 index 733bec9a81..0000000000 --- a/calendar/gui/e-week-view-titles-item.c +++ /dev/null @@ -1,296 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EWeekViewTitlesItem - displays the 'Monday', 'Tuesday' etc. at the top of - * the Month calendar view. - */ - -#include <config.h> -#include <string.h> -#include "e-week-view-titles-item.h" - -static void e_week_view_titles_item_class_init (EWeekViewTitlesItemClass *class); -static void e_week_view_titles_item_init (EWeekViewTitlesItem *wvtitem); - -static void e_week_view_titles_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_week_view_titles_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags); -static void e_week_view_titles_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static double e_week_view_titles_item_point (GnomeCanvasItem *item, - double x, - double y, - int cx, - int cy, - GnomeCanvasItem **actual_item); - - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_WEEK_VIEW -}; - -E_MAKE_TYPE (e_week_view_titles_item, "EWeekViewTitlesItem", EWeekViewTitlesItem, - e_week_view_titles_item_class_init, e_week_view_titles_item_init, - GNOME_TYPE_CANVAS_ITEM); - -static void -e_week_view_titles_item_class_init (EWeekViewTitlesItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = g_type_class_peek_parent (class); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EWeekViewTitlesItem::week_view", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_WEEK_VIEW); - - object_class->set_arg = e_week_view_titles_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_week_view_titles_item_update; - item_class->draw = e_week_view_titles_item_draw; - item_class->point = e_week_view_titles_item_point; -} - - -static void -e_week_view_titles_item_init (EWeekViewTitlesItem *wvtitem) -{ - wvtitem->week_view = NULL; -} - - -static void -e_week_view_titles_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EWeekViewTitlesItem *wvtitem; - - item = GNOME_CANVAS_ITEM (o); - wvtitem = E_WEEK_VIEW_TITLES_ITEM (o); - - switch (arg_id){ - case ARG_WEEK_VIEW: - wvtitem->week_view = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_week_view_titles_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_week_view_titles_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - EWeekViewTitlesItem *wvtitem; - EWeekView *week_view; - GtkStyle *style; - GdkGC *fg_gc, *bg_gc, *light_gc, *dark_gc; - gint canvas_width, canvas_height, col_width, col, date_width, date_x; - gchar buffer[128], *date_format; - GDate date; - GdkRectangle clip_rect; - gboolean long_format; - gint weekday; - PangoLayout *layout; - -#if 0 - g_print ("In e_week_view_titles_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - - wvtitem = E_WEEK_VIEW_TITLES_ITEM (canvas_item); - week_view = wvtitem->week_view; - g_return_if_fail (week_view != NULL); - - style = gtk_widget_get_style (GTK_WIDGET (week_view)); - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - light_gc = style->light_gc[GTK_STATE_NORMAL]; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - canvas_width = GTK_WIDGET (canvas_item->canvas)->allocation.width; - canvas_height = GTK_WIDGET (canvas_item->canvas)->allocation.height; - layout = gtk_widget_create_pango_layout (GTK_WIDGET (week_view), NULL); - - /* Draw the shadow around the dates. */ - gdk_draw_line (drawable, light_gc, - 1 - x, 1 - y, - canvas_width - 2 - x, 1 - y); - gdk_draw_line (drawable, light_gc, - 1 - x, 2 - y, - 1 - x, canvas_height - 1 - y); - - gdk_draw_rectangle (drawable, dark_gc, FALSE, - 0 - x, 0 - y, - canvas_width - 1, canvas_height); - - /* Determine the format to use. */ - col_width = canvas_width / week_view->columns; - if (col_width > week_view->max_day_width + 2) { - date_format = "%A"; - long_format = TRUE; - } else { - date_format = "%a"; - long_format = FALSE; - } - - /* Shift right one pixel to account for the shadow around the main - canvas. */ - x--; - - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - g_date_clear (&date, 1); - /* Note that 20th March 2000 is a Monday. We only care about the - weekday. */ - weekday = week_view->display_start_day; - g_date_set_dmy (&date, 20 + weekday, 3, 2000); - for (col = 0; col < week_view->columns; col++) { - if (weekday == 5 && week_view->compress_weekend) { - g_date_strftime (buffer, 128, "%a/", &date); - g_date_add_days (&date, 1); - g_date_strftime (buffer + strlen (buffer), 100, - "%a", &date); - } else { - g_date_strftime (buffer, 128, date_format, &date); - } - - clip_rect.x = week_view->col_offsets[col] - x; - clip_rect.y = 2 - y; - clip_rect.width = week_view->col_widths[col]; - clip_rect.height = canvas_height - 2; - gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - - if (weekday == 5 && week_view->compress_weekend) - date_width = week_view->abbr_day_widths[5] - + week_view->slash_width - + week_view->abbr_day_widths[6]; - else if (long_format) - date_width = week_view->day_widths[weekday]; - else - date_width = week_view->abbr_day_widths[weekday]; - - date_x = week_view->col_offsets[col] - + (week_view->col_widths[col] - date_width) / 2; - date_x = MAX (date_x, week_view->col_offsets[col]); - - pango_layout_set_text (layout, buffer, -1); - gdk_draw_layout (drawable, fg_gc, - date_x - x, - 3 - y, - layout); - - gdk_gc_set_clip_rectangle (fg_gc, NULL); - - /* Draw the lines down the left and right of the date cols. */ - if (col != 0) { - gdk_draw_line (drawable, light_gc, - week_view->col_offsets[col] - x, - 4 - y, - week_view->col_offsets[col] - x, - canvas_height - 4 - y); - - gdk_draw_line (drawable, dark_gc, - week_view->col_offsets[col] - 1 - x, - 4 - y, - week_view->col_offsets[col] - 1 - x, - canvas_height - 4 - y); - } - - /* Draw the lines between each column. */ - if (col != 0) { - gdk_draw_line (drawable, style->black_gc, - week_view->col_offsets[col] - x, - canvas_height - y, - week_view->col_offsets[col] - x, - canvas_height - y); - } - - if (weekday == 5 && week_view->compress_weekend) - weekday += 2; - else - weekday++; - - weekday = weekday % 7; - - g_date_add_days (&date, 1); - } - - g_object_unref (layout); -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_week_view_titles_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - diff --git a/calendar/gui/e-week-view-titles-item.h b/calendar/gui/e-week-view-titles-item.h deleted file mode 100644 index 77fed506c8..0000000000 --- a/calendar/gui/e-week-view-titles-item.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_WEEK_VIEW_TITLES_ITEM_H_ -#define _E_WEEK_VIEW_TITLES_ITEM_H_ - -#include "e-week-view.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EWeekViewTitlesItem - displays the 'Monday', 'Tuesday' etc. at the top of - * the Month calendar view. - */ - -#define E_WEEK_VIEW_TITLES_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_week_view_titles_item_get_type (), EWeekViewTitlesItem)) -#define E_WEEK_VIEW_TITLES_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_week_view_titles_item_get_type ())) -#define E_IS_WEEK_VIEW_TITLES_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_week_view_titles_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The parent EWeekView widget. */ - EWeekView *week_view; -} EWeekViewTitlesItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} EWeekViewTitlesItemClass; - - -GtkType e_week_view_titles_item_get_type (void); - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_WEEK_VIEW_TITLES_ITEM_H_ */ diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c deleted file mode 100644 index 406a3876d1..0000000000 --- a/calendar/gui/e-week-view.c +++ /dev/null @@ -1,4496 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Authors : - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 - */ - -/* - * EWeekView - displays the Week & Month views of the calendar. - */ - -#include <config.h> - -#include "e-week-view.h" - -#include <math.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtkselection.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkvscrollbar.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkmain.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-exec.h> -#include <libgnome/gnome-util.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <libgnomecanvas/gnome-canvas-pixbuf.h> -#include <gal/e-text/e-text.h> -#include <gal/widgets/e-canvas-utils.h> -#include <gal/widgets/e-gui-utils.h> -#include <gal/widgets/e-unicode.h> -#include <e-util/e-categories-config.h> -#include <e-util/e-dialog-utils.h> -#include "dialogs/delete-comp.h" -#include "dialogs/delete-error.h" -#include "dialogs/send-comp.h" -#include "dialogs/cancel-comp.h" -#include "dialogs/recur-comp.h" -#include "comp-util.h" -#include "itip-utils.h" -#include "cal-util/timeutil.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "print.h" -#include "goto.h" -#include "e-week-view-event-item.h" -#include "e-week-view-layout.h" -#include "e-week-view-main-item.h" -#include "e-week-view-titles-item.h" -#include "misc.h" - -/* Images */ -#include "art/bell.xpm" -#include "art/recur.xpm" -#include "art/timezone-16.xpm" -#include "art/jump.xpm" - -#define E_WEEK_VIEW_SMALL_FONT_PTSIZE 7 - -#define E_WEEK_VIEW_JUMP_BUTTON_WIDTH 16 -#define E_WEEK_VIEW_JUMP_BUTTON_HEIGHT 8 - -#define E_WEEK_VIEW_JUMP_BUTTON_X_PAD 3 -#define E_WEEK_VIEW_JUMP_BUTTON_Y_PAD 3 - -/* The timeout before we do a layout, so we don't do a layout for each event - we get from the server. */ -#define E_WEEK_VIEW_LAYOUT_TIMEOUT 100 - -/* Used for the status bar messages */ -#define EVOLUTION_CALENDAR_PROGRESS_IMAGE "evolution-calendar-mini.png" -static GdkPixbuf *progress_icon[2] = { NULL, NULL }; - -/* Signal IDs */ -enum { - SELECTION_CHANGED, - LAST_SIGNAL -}; -static guint e_week_view_signals[LAST_SIGNAL] = { 0 }; - - -static void e_week_view_class_init (EWeekViewClass *class); -static void e_week_view_init (EWeekView *week_view); -static void e_week_view_destroy (GtkObject *object); -static void e_week_view_realize (GtkWidget *widget); -static void e_week_view_unrealize (GtkWidget *widget); -static void e_week_view_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static void e_week_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void e_week_view_recalc_cell_sizes (EWeekView *week_view); -static gint e_week_view_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_week_view_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static gint e_week_view_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void e_week_view_draw_shadow (EWeekView *week_view); - -static gboolean e_week_view_on_button_press (GtkWidget *widget, - GdkEventButton *event, - EWeekView *week_view); -static gboolean e_week_view_on_button_release (GtkWidget *widget, - GdkEventButton *event, - EWeekView *week_view); -static gboolean e_week_view_on_motion (GtkWidget *widget, - GdkEventMotion *event, - EWeekView *week_view); -static gint e_week_view_convert_position_to_day (EWeekView *week_view, - gint x, - gint y); -static void e_week_view_update_selection (EWeekView *week_view, - gint day); - -static void e_week_view_free_events (EWeekView *week_view); -static gboolean e_week_view_add_event (CalComponent *comp, - time_t start, - time_t end, - gpointer data); -static void e_week_view_check_layout (EWeekView *week_view); -static void e_week_view_ensure_events_sorted (EWeekView *week_view); -static void e_week_view_reshape_events (EWeekView *week_view); -static void e_week_view_reshape_event_span (EWeekView *week_view, - gint event_num, - gint span_num); -static void e_week_view_recalc_day_starts (EWeekView *week_view, - time_t lower); -static void e_week_view_on_adjustment_changed (GtkAdjustment *adjustment, - EWeekView *week_view); -static void e_week_view_on_editing_started (EWeekView *week_view, - GnomeCanvasItem *item); -static void e_week_view_on_editing_stopped (EWeekView *week_view, - GnomeCanvasItem *item); -static gboolean e_week_view_find_event_from_item (EWeekView *week_view, - GnomeCanvasItem *item, - gint *event_num, - gint *span_num); -static gboolean e_week_view_find_event_from_uid (EWeekView *week_view, - const gchar *uid, - gint *event_num_return); -typedef gboolean (* EWeekViewForeachEventCallback) (EWeekView *week_view, - gint event_num, - gpointer data); - -static void e_week_view_foreach_event_with_uid (EWeekView *week_view, - const gchar *uid, - EWeekViewForeachEventCallback callback, - gpointer data); -static gboolean e_week_view_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EWeekView *week_view); -static gboolean e_week_view_on_jump_button_event (GnomeCanvasItem *item, - GdkEvent *event, - EWeekView *week_view); -static gint e_week_view_key_press (GtkWidget *widget, GdkEventKey *event); -static void e_week_view_on_new_appointment (GtkWidget *widget, - gpointer data); -static void e_week_view_on_new_event (GtkWidget *widget, - gpointer data); -static void e_week_view_on_new_meeting (GtkWidget *widget, - gpointer data); -static void e_week_view_on_new_task (GtkWidget *widget, - gpointer data); -static void e_week_view_on_goto_today (GtkWidget *widget, - gpointer data); -static void e_week_view_on_goto_date (GtkWidget *widget, - gpointer data); -static void e_week_view_on_edit_appointment (GtkWidget *widget, - gpointer data); -static void e_week_view_on_save_as (GtkWidget *widget, - gpointer data); -static void e_week_view_on_print (GtkWidget *widget, - gpointer data); -static void e_week_view_on_print_event (GtkWidget *widget, - gpointer data); -static void e_week_view_on_meeting (GtkWidget *widget, - gpointer data); -static void e_week_view_on_forward (GtkWidget *widget, - gpointer data); -static void e_week_view_on_publish (GtkWidget *widget, - gpointer data); -static void e_week_view_on_settings (GtkWidget *widget, - gpointer data); -static void e_week_view_on_delete_occurrence (GtkWidget *widget, - gpointer data); -static void e_week_view_on_delete_appointment (GtkWidget *widget, - gpointer data); -static void e_week_view_on_cut (GtkWidget *widget, gpointer data); -static void e_week_view_on_copy (GtkWidget *widget, gpointer data); -static void e_week_view_on_paste (GtkWidget *widget, gpointer data); -static void e_week_view_on_unrecur_appointment (GtkWidget *widget, - gpointer data); - -static gboolean e_week_view_update_event_cb (EWeekView *week_view, - gint event_num, - gpointer data); -static gboolean e_week_view_remove_event_cb (EWeekView *week_view, - gint event_num, - gpointer data); -static gboolean e_week_view_recalc_display_start_day (EWeekView *week_view); - -static void invisible_destroyed (GtkWidget *invisible, EWeekView *week_view); -static void selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EWeekView *week_view); -static void selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EWeekView *week_view); -static void selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EWeekView *week_view); - -static void e_week_view_queue_layout (EWeekView *week_view); -static void e_week_view_cancel_layout (EWeekView *week_view); -static gboolean e_week_view_layout_timeout_cb (gpointer data); - - -static GtkTableClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - -E_MAKE_TYPE (e_week_view, "EWeekView", EWeekView, e_week_view_class_init, - e_week_view_init, GTK_TYPE_TABLE); - -static void -e_week_view_class_init (EWeekViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = g_type_class_peek_parent (class); - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - e_week_view_signals[SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (EWeekViewClass, selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - /* Method override */ - object_class->destroy = e_week_view_destroy; - - widget_class->realize = e_week_view_realize; - widget_class->unrealize = e_week_view_unrealize; - widget_class->style_set = e_week_view_style_set; - widget_class->size_allocate = e_week_view_size_allocate; - widget_class->focus_in_event = e_week_view_focus_in; - widget_class->focus_out_event = e_week_view_focus_out; - widget_class->key_press_event = e_week_view_key_press; - widget_class->expose_event = e_week_view_expose_event; - - class->selection_changed = NULL; - - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - - -static void -e_week_view_init (EWeekView *week_view) -{ - GnomeCanvasGroup *canvas_group; - GtkObject *adjustment; - GdkPixbuf *pixbuf; - gint i; - - GTK_WIDGET_SET_FLAGS (week_view, GTK_CAN_FOCUS); - - week_view->calendar = NULL; - week_view->client = NULL; - week_view->sexp = g_strdup ("#t"); /* match all by default */ - week_view->query = NULL; - - week_view->events = g_array_new (FALSE, FALSE, - sizeof (EWeekViewEvent)); - week_view->events_sorted = TRUE; - week_view->events_need_layout = FALSE; - week_view->events_need_reshape = FALSE; - - week_view->layout_timeout_id = 0; - - week_view->spans = NULL; - - week_view->zone = NULL; - week_view->multi_week_view = FALSE; - week_view->weeks_shown = 6; - week_view->rows = 6; - week_view->columns = 2; - week_view->compress_weekend = TRUE; - week_view->show_event_end_times = TRUE; - week_view->week_start_day = 0; /* Monday. */ - week_view->display_start_day = 0; /* Monday. */ - - g_date_clear (&week_view->base_date, 1); - g_date_clear (&week_view->first_day_shown, 1); - - week_view->row_height = 10; - week_view->rows_per_cell = 1; - - week_view->selection_start_day = -1; - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE; - - week_view->pressed_event_num = -1; - week_view->editing_event_num = -1; - - week_view->main_gc = NULL; - - week_view->default_category = NULL; - - /* Create the small font. */ - week_view->use_small_font = TRUE; - - week_view->small_font_desc = - pango_font_description_copy (gtk_widget_get_style (GTK_WIDGET (week_view))->font_desc); - pango_font_description_set_size (week_view->small_font_desc, - E_WEEK_VIEW_SMALL_FONT_PTSIZE * PANGO_SCALE); - - /* String to use in 12-hour time format for times in the morning. */ - week_view->am_string = _("am"); - - /* String to use in 12-hour time format for times in the afternoon. */ - week_view->pm_string = _("pm"); - - - /* - * Titles Canvas. Note that we don't show it is only shown in the - * Month view. - */ - week_view->titles_canvas = e_canvas_new (); - gtk_table_attach (GTK_TABLE (week_view), week_view->titles_canvas, - 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->titles_canvas)->root); - - week_view->titles_canvas_item = - gnome_canvas_item_new (canvas_group, - e_week_view_titles_item_get_type (), - "EWeekViewTitlesItem::week_view", week_view, - NULL); - - /* - * Main Canvas - */ - week_view->main_canvas = e_canvas_new (); - gtk_table_attach (GTK_TABLE (week_view), week_view->main_canvas, - 1, 2, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1); - gtk_widget_show (week_view->main_canvas); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->main_canvas)->root); - - week_view->main_canvas_item = - gnome_canvas_item_new (canvas_group, - e_week_view_main_item_get_type (), - "EWeekViewMainItem::week_view", week_view, - NULL); - - g_signal_connect_after (week_view->main_canvas, "button_press_event", - G_CALLBACK (e_week_view_on_button_press), week_view); - g_signal_connect_after (week_view->main_canvas, "button_release_event", - G_CALLBACK (e_week_view_on_button_release), week_view); - g_signal_connect_after (week_view->main_canvas, "motion_notify_event", - G_CALLBACK (e_week_view_on_motion), week_view); - - /* Create the buttons to jump to each days. */ - pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**) jump_xpm); - - for (i = 0; i < E_WEEK_VIEW_MAX_WEEKS * 7; i++) { - week_view->jump_buttons[i] = gnome_canvas_item_new - (canvas_group, - gnome_canvas_pixbuf_get_type (), - "GnomeCanvasPixbuf::pixbuf", pixbuf, - NULL); - - g_signal_connect (week_view->jump_buttons[i], "event", - G_CALLBACK (e_week_view_on_jump_button_event), week_view); - } - gdk_pixbuf_unref (pixbuf); - - /* - * Scrollbar. - */ - adjustment = gtk_adjustment_new (0, -52, 52, 1, 1, 1); - gtk_signal_connect (adjustment, "value_changed", - G_CALLBACK (e_week_view_on_adjustment_changed), - week_view); - - week_view->vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (adjustment)); - gtk_table_attach (GTK_TABLE (week_view), week_view->vscrollbar, - 2, 3, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (week_view->vscrollbar); - - /* Create the cursors. */ - week_view->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR); - week_view->move_cursor = gdk_cursor_new (GDK_FLEUR); - week_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - week_view->last_cursor_set = NULL; - - /* Set up the inivisible widget for the clipboard selections */ - week_view->invisible = gtk_invisible_new (); - gtk_selection_add_target (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - 0); - - g_signal_connect (week_view->invisible, "selection_get", - G_CALLBACK (selection_get), (gpointer) week_view); - g_signal_connect (week_view->invisible, "selection_clear_event", - G_CALLBACK (selection_clear_event), (gpointer) week_view); - g_signal_connect (week_view->invisible, "selection_received", - G_CALLBACK (selection_received), (gpointer) week_view); - g_signal_connect (week_view->invisible, "destroy", - G_CALLBACK (invisible_destroyed), (gpointer) week_view); - - week_view->clipboard_selection = NULL; - - week_view->activity = NULL; -} - - -/** - * e_week_view_new: - * @Returns: a new #EWeekView. - * - * Creates a new #EWeekView. - **/ -GtkWidget * -e_week_view_new (void) -{ - GtkWidget *week_view; - - week_view = GTK_WIDGET (g_object_new (e_week_view_get_type (), NULL)); - - return week_view; -} - - -static void -e_week_view_destroy (GtkObject *object) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (object); - - e_week_view_cancel_layout (week_view); - - e_week_view_free_events (week_view); - g_array_free (week_view->events, TRUE); - week_view->events = NULL; - - if (week_view->client) { - g_signal_handlers_disconnect_matched (week_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, week_view); - g_object_unref (week_view->client); - week_view->client = NULL; - } - - if (week_view->sexp) { - g_free (week_view->sexp); - week_view->sexp = NULL; - } - - if (week_view->query) { - g_signal_handlers_disconnect_matched (week_view->query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, week_view); - g_object_unref (week_view->query); - week_view->query = NULL; - } - - if (week_view->small_font_desc) { - pango_font_description_free (week_view->small_font_desc); - week_view->small_font_desc = NULL; - } - - if (week_view->default_category) { - g_free (week_view->default_category); - week_view->default_category = NULL; - } - - gdk_cursor_destroy (week_view->normal_cursor); - gdk_cursor_destroy (week_view->move_cursor); - gdk_cursor_destroy (week_view->resize_width_cursor); - - if (week_view->invisible) - gtk_widget_destroy (week_view->invisible); - if (week_view->clipboard_selection) { - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = NULL; - } - - if (week_view->activity) { - g_object_unref (week_view->activity); - week_view->activity = NULL; - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_week_view_realize (GtkWidget *widget) -{ - EWeekView *week_view; - GdkColormap *colormap; - gboolean success[E_WEEK_VIEW_COLOR_LAST]; - gint nfailed; - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (*GTK_WIDGET_CLASS (parent_class)->realize)(widget); - - week_view = E_WEEK_VIEW (widget); - week_view->main_gc = gdk_gc_new (widget->window); - - colormap = gtk_widget_get_colormap (widget); - - /* Allocate the colors. */ - week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].red = 0xe0e0; - week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].green = 0xe0e0; - week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].blue = 0xe0e0; - - week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].red = 65535; - week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].green = 65535; - week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].blue = 65535; - - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].red = 213 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].green = 213 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].blue = 213 * 257; - - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].red = 0; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].green = 0; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].blue = 0; - - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].red = 0; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].green = 0; - week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].blue = 0; - - week_view->colors[E_WEEK_VIEW_COLOR_GRID].red = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_GRID].green = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_GRID].blue = 0 * 257; - - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].red = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].green = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].blue = 156 * 257; - - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED_UNFOCUSSED].red = 16 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED_UNFOCUSSED].green = 78 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_SELECTED_UNFOCUSSED].blue = 139 * 257; - - week_view->colors[E_WEEK_VIEW_COLOR_DATES].red = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_DATES].green = 0 * 257; - week_view->colors[E_WEEK_VIEW_COLOR_DATES].blue = 0 * 257; - - week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].red = 65535; - week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].green = 65535; - week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].blue = 65535; - - week_view->colors[E_WEEK_VIEW_COLOR_TODAY].red = 65535; - week_view->colors[E_WEEK_VIEW_COLOR_TODAY].green = 0; - week_view->colors[E_WEEK_VIEW_COLOR_TODAY].blue = 0; - - nfailed = gdk_colormap_alloc_colors (colormap, week_view->colors, - E_WEEK_VIEW_COLOR_LAST, FALSE, - TRUE, success); - if (nfailed) - g_warning ("Failed to allocate all colors"); - - - /* Create the pixmaps. */ - week_view->reminder_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->reminder_mask, NULL, bell_xpm); - week_view->recurrence_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->recurrence_mask, NULL, recur_xpm); - week_view->timezone_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->timezone_mask, NULL, timezone_16_xpm); -} - - -static void -e_week_view_unrealize (GtkWidget *widget) -{ - EWeekView *week_view; - GdkColormap *colormap; - - week_view = E_WEEK_VIEW (widget); - - gdk_gc_unref (week_view->main_gc); - week_view->main_gc = NULL; - - colormap = gtk_widget_get_colormap (widget); - gdk_colormap_free_colors (colormap, week_view->colors, E_WEEK_VIEW_COLOR_LAST); - - gdk_pixmap_unref (week_view->reminder_icon); - week_view->reminder_icon = NULL; - gdk_pixmap_unref (week_view->recurrence_icon); - week_view->recurrence_icon = NULL; - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget); -} - -static gint -get_string_width (PangoLayout *layout, const gchar *string) -{ - gint width; - - pango_layout_set_text (layout, string, -1); - pango_layout_get_pixel_size (layout, &width, NULL); - return width; -} - -/* FIXME: This is also needed in e-day-view-time-item.c. We should probably use - * pango's approximation function, but it needs a language tag. Find out how to - * get one of those properly. */ -static gint -get_digit_width (PangoLayout *layout) -{ - gint digit; - gint max_digit_width = 1; - - for (digit = '0'; digit <= '9'; digit++) { - gchar digit_char; - gint digit_width; - - digit_char = digit; - - pango_layout_set_text (layout, &digit_char, 1); - pango_layout_get_pixel_size (layout, &digit_width, NULL); - - max_digit_width = MAX (max_digit_width, digit_width); - } - - return max_digit_width; -} - -static void -e_week_view_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EWeekView *week_view; - GtkStyle *style; - gint day, day_width, max_day_width, max_abbr_day_width; - gint month, month_width, max_month_width, max_abbr_month_width; - GDate date; - gchar buffer[128]; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - (*GTK_WIDGET_CLASS (parent_class)->style_set)(widget, previous_style); - - week_view = E_WEEK_VIEW (widget); - style = gtk_widget_get_style (widget); - - /* Set up Pango prerequisites */ - font_desc = style->font_desc; - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - layout = pango_layout_new (pango_context); - - /* Recalculate the height of each row based on the font size. */ - week_view->row_height = PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + - E_WEEK_VIEW_EVENT_BORDER_HEIGHT * 2 + E_WEEK_VIEW_EVENT_TEXT_Y_PAD * 2; - week_view->row_height = MAX (week_view->row_height, E_WEEK_VIEW_ICON_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD + E_WEEK_VIEW_EVENT_BORDER_HEIGHT * 2); - - /* Check that the small font is smaller than the default font. - If it isn't, we won't use it. */ - if (week_view->small_font_desc) { - if (PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) - <= E_WEEK_VIEW_SMALL_FONT_PTSIZE) - week_view->use_small_font = FALSE; - } - - /* Set the height of the top canvas. */ - gtk_widget_set_usize (week_view->titles_canvas, -1, - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) + 5); - - /* Save the sizes of various strings in the font, so we can quickly - decide which date formats to use. */ - g_date_clear (&date, 1); - g_date_set_dmy (&date, 27, 3, 2000); /* Must be a Monday. */ - - max_day_width = 0; - max_abbr_day_width = 0; - for (day = 0; day < 7; day++) { - g_date_strftime (buffer, 128, "%A", &date); - day_width = get_string_width (layout, buffer); - week_view->day_widths[day] = day_width; - max_day_width = MAX (max_day_width, day_width); - - g_date_strftime (buffer, 128, "%a", &date); - day_width = get_string_width (layout, buffer); - week_view->abbr_day_widths[day] = day_width; - max_abbr_day_width = MAX (max_abbr_day_width, day_width); - - g_date_add_days (&date, 1); - } - - max_month_width = 0; - max_abbr_month_width = 0; - for (month = 0; month < 12; month++) { - g_date_set_month (&date, month + 1); - - g_date_strftime (buffer, 128, "%B", &date); - month_width = get_string_width (layout, buffer); - week_view->month_widths[month] = month_width; - max_month_width = MAX (max_month_width, month_width); - - g_date_strftime (buffer, 128, "%b", &date); - month_width = get_string_width (layout, buffer); - week_view->abbr_month_widths[month] = month_width; - max_abbr_month_width = MAX (max_abbr_month_width, month_width); - } - - week_view->space_width = get_string_width (layout, " "); - week_view->colon_width = get_string_width (layout, ":"); - week_view->slash_width = get_string_width (layout, "/"); - week_view->digit_width = get_digit_width (layout); - if (week_view->small_font_desc) { - pango_layout_set_font_description (layout, week_view->small_font_desc); - week_view->small_digit_width = get_digit_width (layout); - pango_layout_set_font_description (layout, style->font_desc); - } - week_view->max_day_width = max_day_width; - week_view->max_abbr_day_width = max_abbr_day_width; - week_view->max_month_width = max_month_width; - week_view->max_abbr_month_width = max_abbr_month_width; - - week_view->am_string_width = get_string_width (layout, - week_view->am_string); - week_view->pm_string_width = get_string_width (layout, - week_view->pm_string); - - g_object_unref (layout); - pango_font_metrics_unref (font_metrics); -} - - -/* This recalculates the sizes of each column. */ -static void -e_week_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EWeekView *week_view; - gdouble old_x2, old_y2, new_x2, new_y2; - - week_view = E_WEEK_VIEW (widget); - - (*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - e_week_view_recalc_cell_sizes (week_view); - - /* Set the scroll region of the top canvas to its allocated size. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (week_view->titles_canvas), - NULL, NULL, &old_x2, &old_y2); - new_x2 = week_view->titles_canvas->allocation.width - 1; - new_y2 = week_view->titles_canvas->allocation.height - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) - gnome_canvas_set_scroll_region (GNOME_CANVAS (week_view->titles_canvas), - 0, 0, new_x2, new_y2); - - - /* Set the scroll region of the main canvas to its allocated width, - but with the height depending on the number of rows needed. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (week_view->main_canvas), - NULL, NULL, &old_x2, &old_y2); - new_x2 = week_view->main_canvas->allocation.width - 1; - new_y2 = week_view->main_canvas->allocation.height - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) - gnome_canvas_set_scroll_region (GNOME_CANVAS (week_view->main_canvas), - 0, 0, new_x2, new_y2); - - /* Flag that we need to reshape the events. */ - if (old_x2 != new_x2 || old_y2 != new_y2) { - week_view->events_need_reshape = TRUE; - e_week_view_check_layout (week_view); - } -} - - -static void -e_week_view_recalc_cell_sizes (EWeekView *week_view) -{ - gfloat canvas_width, canvas_height, offset; - gint row, col; - GtkWidget *widget; - GtkStyle *style; - gint width, height, time_width; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - - if (week_view->multi_week_view) { - week_view->rows = week_view->weeks_shown * 2; - week_view->columns = week_view->compress_weekend ? 6 : 7; - } else { - week_view->rows = 6; - week_view->columns = 2; - } - - /* Calculate the column sizes, using floating point so that pixels - get divided evenly. Note that we use one more element than the - number of columns, to make it easy to get the column widths. - We also add one to the width so that the right border of the last - column is off the edge of the displayed area. */ - canvas_width = week_view->main_canvas->allocation.width + 1; - canvas_width /= week_view->columns; - offset = 0; - for (col = 0; col <= week_view->columns; col++) { - week_view->col_offsets[col] = floor (offset + 0.5); - offset += canvas_width; - } - - /* Calculate the cell widths based on the offsets. */ - for (col = 0; col < week_view->columns; col++) { - week_view->col_widths[col] = week_view->col_offsets[col + 1] - - week_view->col_offsets[col]; - } - - /* Now do the same for the row heights. */ - canvas_height = week_view->main_canvas->allocation.height + 1; - canvas_height /= week_view->rows; - offset = 0; - for (row = 0; row <= week_view->rows; row++) { - week_view->row_offsets[row] = floor (offset + 0.5); - offset += canvas_height; - } - - /* Calculate the cell heights based on the offsets. */ - for (row = 0; row < week_view->rows; row++) { - week_view->row_heights[row] = week_view->row_offsets[row + 1] - - week_view->row_offsets[row]; - } - - - /* If the font hasn't been set yet just return. */ - widget = GTK_WIDGET (week_view); - style = gtk_widget_get_style (widget); - if (!style) - return; - font_desc = style->font_desc; - if (!font_desc) - return; - - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - - - /* Calculate the number of rows of events in each cell, for the large - cells and the compressed weekend cells. */ - if (week_view->multi_week_view) { - week_view->events_y_offset = E_WEEK_VIEW_DATE_T_PAD + - + PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) - + PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) - + E_WEEK_VIEW_DATE_B_PAD; - } else { - week_view->events_y_offset = E_WEEK_VIEW_DATE_T_PAD - + PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) - + PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) - + E_WEEK_VIEW_DATE_LINE_T_PAD + 1 - + E_WEEK_VIEW_DATE_LINE_B_PAD; - } - - height = week_view->row_heights[0]; - week_view->rows_per_cell = (height * 2 - week_view->events_y_offset) - / (week_view->row_height + E_WEEK_VIEW_EVENT_Y_SPACING); - week_view->rows_per_cell = MIN (week_view->rows_per_cell, - E_WEEK_VIEW_MAX_ROWS_PER_CELL); - - week_view->rows_per_compressed_cell = - (height - week_view->events_y_offset) - / (week_view->row_height + E_WEEK_VIEW_EVENT_Y_SPACING); - week_view->rows_per_compressed_cell = MIN (week_view->rows_per_compressed_cell, - E_WEEK_VIEW_MAX_ROWS_PER_CELL); - - /* Determine which time format to use, based on the width of the cells. - We only allow the time to take up about half of the width. */ - width = week_view->col_widths[0]; - - time_width = e_week_view_get_time_string_width (week_view); - - week_view->time_format = E_WEEK_VIEW_TIME_NONE; - if (week_view->use_small_font && week_view->small_font_desc) { - if (week_view->show_event_end_times - && width / 2 > time_width * 2 + E_WEEK_VIEW_EVENT_TIME_SPACING) - week_view->time_format = E_WEEK_VIEW_TIME_BOTH_SMALL_MIN; - else if (width / 2 > time_width) - week_view->time_format = E_WEEK_VIEW_TIME_START_SMALL_MIN; - } else { - if (week_view->show_event_end_times - && width / 2 > time_width * 2 + E_WEEK_VIEW_EVENT_TIME_SPACING) - week_view->time_format = E_WEEK_VIEW_TIME_BOTH; - else if (width / 2 > time_width) - week_view->time_format = E_WEEK_VIEW_TIME_START; - } - - pango_font_metrics_unref (font_metrics); -} - - -static gint -e_week_view_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - EWeekView *week_view; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - week_view = E_WEEK_VIEW (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - - gtk_widget_queue_draw (week_view->main_canvas); - - return FALSE; -} - - -static gint -e_week_view_focus_out (GtkWidget *widget, GdkEventFocus *event) -{ - EWeekView *week_view; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - week_view = E_WEEK_VIEW (widget); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - - gtk_widget_queue_draw (week_view->main_canvas); - - return FALSE; -} - - -/* This draws a shadow around the top display and main display. */ -static gint -e_week_view_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (widget); - - e_week_view_draw_shadow (week_view); - - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (*GTK_WIDGET_CLASS (parent_class)->expose_event)(widget, event); - - return FALSE; -} - -static void -e_week_view_draw_shadow (EWeekView *week_view) -{ - gint x1, y1, x2, y2; - GtkStyle *style; - GdkGC *light_gc, *dark_gc; - GdkWindow *window; - - /* Draw the shadow around the graphical displays. */ - x1 = week_view->main_canvas->allocation.x - 1; - y1 = week_view->main_canvas->allocation.y - 1; - x2 = x1 + week_view->main_canvas->allocation.width + 2; - y2 = y1 + week_view->main_canvas->allocation.height + 2; - - style = GTK_WIDGET (week_view)->style; - dark_gc = style->dark_gc[GTK_STATE_NORMAL]; - light_gc = style->light_gc[GTK_STATE_NORMAL]; - - window = GTK_WIDGET (week_view)->window; - gdk_draw_line (window, dark_gc, x1, y1, x1, y2); - gdk_draw_line (window, dark_gc, x1, y1, x2, y1); - gdk_draw_line (window, light_gc, x2, y1, x2, y2); - gdk_draw_line (window, light_gc, x1, y2, x2, y2); -} - -static void -e_week_view_new_appointment (EWeekView *week_view, gboolean meeting) -{ - time_t dtstart, dtend; - struct icaltimetype itt; - gboolean all_day = FALSE; - - /* Edit a new event. If only one day is selected we set the time to - the first 1/2-hour of the working day. */ - if (week_view->selection_start_day == week_view->selection_end_day) { - dtstart = week_view->day_starts[week_view->selection_start_day]; - itt = icaltime_from_timet_with_zone (dtstart, FALSE, - week_view->zone); - itt.hour = calendar_config_get_day_start_hour (); - itt.minute = calendar_config_get_day_start_minute (); - dtstart = icaltime_as_timet_with_zone (itt, week_view->zone); - - icaltime_adjust (&itt, 0, 0, 30, 0); - dtend = icaltime_as_timet_with_zone (itt, week_view->zone); - } else { - dtstart = week_view->day_starts[week_view->selection_start_day]; - dtend = week_view->day_starts[week_view->selection_end_day + 1]; - all_day = TRUE; - } - - gnome_calendar_new_appointment_for (week_view->calendar, dtstart, dtend, all_day, meeting); -} - -void -e_week_view_set_calendar (EWeekView *week_view, - GnomeCalendar *calendar) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - week_view->calendar = calendar; -} - - -/* Callback used when a component is updated in the live query */ -static void -query_obj_updated_cb (CalQuery *query, const char *uid, - gboolean query_in_progress, int n_scanned, int total, - gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - gint event_num, num_days; - CalComponent *comp; - CalClientGetStatus status; - - week_view = E_WEEK_VIEW (data); - - /* If we don't have a valid date set yet, just return. */ - if (!g_date_valid (&week_view->first_day_shown)) - return; - - /* Get the event from the server. */ - status = cal_client_get_object (week_view->client, uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Everything is fine */ - break; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("obj_updated_cb(): Syntax error when getting object `%s'", uid); - return; - - case CAL_CLIENT_GET_NOT_FOUND: - /* The object is no longer in the server, so do nothing */ - return; - } - - /* If the event already exists and the dates didn't change, we can - update the event fairly easily without changing the events arrays - or computing a new layout. */ - if (e_week_view_find_event_from_uid (week_view, uid, &event_num)) { - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - if (!cal_component_has_recurrences (comp) - && !cal_component_has_recurrences (event->comp) - && cal_component_event_dates_match (comp, event->comp)) { -#if 0 - g_print ("updated object's dates unchanged\n"); -#endif - e_week_view_foreach_event_with_uid (week_view, uid, e_week_view_update_event_cb, comp); - g_object_unref (comp); - gtk_widget_queue_draw (week_view->main_canvas); - return; - } - - /* The dates have changed, so we need to remove the - old occurrrences before adding the new ones. */ -#if 0 - g_print ("dates changed - removing occurrences\n"); -#endif - e_week_view_foreach_event_with_uid (week_view, uid, - e_week_view_remove_event_cb, - NULL); - } - - /* Add the occurrences of the event. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - - cal_recur_generate_instances (comp, - week_view->day_starts[0], - week_view->day_starts[num_days], - e_week_view_add_event, week_view, - cal_client_resolve_tzid_cb, week_view->client, - week_view->zone); - - g_object_unref (comp); - - e_week_view_queue_layout (week_view); -} - -/* Callback used when a component is removed from the live query */ -static void -query_obj_removed_cb (CalClient *client, const char *uid, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - e_week_view_foreach_event_with_uid (week_view, uid, - e_week_view_remove_event_cb, NULL); - - gtk_widget_queue_draw (week_view->main_canvas); - e_week_view_check_layout (week_view); -} - -/* Callback used when a query ends */ -static void -query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - /* FIXME */ - - e_week_view_set_status_message (week_view, NULL); - - if (status != CAL_QUERY_DONE_SUCCESS) - fprintf (stderr, "query done: %s\n", error_str); - - gtk_widget_queue_draw (week_view->main_canvas); -} - -/* Callback used when an evaluation error occurs when running a query */ -static void -query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - /* FIXME */ - - e_week_view_set_status_message (week_view, NULL); - - fprintf (stderr, "eval error: %s\n", error_str); - - gtk_widget_queue_draw (week_view->main_canvas); -} - -/* Builds a complete query sexp for the week view by adding the predicates to - * filter only for VEVENTS that fit in the week view's time range. - */ -static char * -adjust_query_sexp (EWeekView *week_view, const char *sexp) -{ - int num_days; - char *start, *end; - char *new_sexp; - - /* If the dates have not been set yet, we just want an empty query. */ - if (!g_date_valid (&week_view->first_day_shown)) - return NULL; - - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - - start = isodate_from_time_t (week_view->day_starts[0]); - end = isodate_from_time_t (week_view->day_starts[num_days]); - - new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")" - " (occur-in-time-range? (make-time \"%s\")" - " (make-time \"%s\"))" - " %s)", - start, end, - sexp); - - g_free (start); - g_free (end); - - return new_sexp; -} - -/* Restarts a query for the week view */ -static void -update_query (EWeekView *week_view) -{ - CalQuery *old_query; - char *real_sexp; - - gtk_widget_queue_draw (week_view->main_canvas); - e_week_view_free_events (week_view); - e_week_view_queue_layout (week_view); - - if (!(week_view->client - && cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - old_query = week_view->query; - week_view->query = NULL; - - if (old_query) { - g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, week_view); - g_object_unref (old_query); - } - - g_assert (week_view->sexp != NULL); - - real_sexp = adjust_query_sexp (week_view, week_view->sexp); - if (!real_sexp) { - return; /* No time range is set, so don't start a query */ - } - - e_week_view_set_status_message (week_view, _("Searching")); - week_view->query = cal_client_get_query (week_view->client, real_sexp); - g_free (real_sexp); - - if (!week_view->query) { - g_message ("update_query(): Could not create the query"); - return; - } - - g_signal_connect (week_view->query, "obj_updated", - G_CALLBACK (query_obj_updated_cb), week_view); - g_signal_connect (week_view->query, "obj_removed", - G_CALLBACK (query_obj_removed_cb), week_view); - g_signal_connect (week_view->query, "query_done", - G_CALLBACK (query_query_done_cb), week_view); - g_signal_connect (week_view->query, "eval_error", - G_CALLBACK (query_eval_error_cb), week_view); -} - -/* Callback used when the calendar client finishes opening */ -static void -cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - if (status != CAL_CLIENT_OPEN_SUCCESS) - return; - - update_query (week_view); -} - -/** - * e_week_view_set_cal_client: - * @week_view: A week view. - * @client: A calendar client interface object. - * - * Sets the calendar client interface object that a week view will monitor. - **/ -void -e_week_view_set_cal_client (EWeekView *week_view, - CalClient *client) -{ - g_return_if_fail (week_view != NULL); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (client == week_view->client) - return; - - if (client) - g_return_if_fail (IS_CAL_CLIENT (client)); - - if (client) - g_object_ref (client); - - if (week_view->client) { - g_signal_handlers_disconnect_matched (week_view->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, week_view); - g_object_unref (week_view->client); - } - - week_view->client = client; - - if (week_view->client) { - if (cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED) - update_query (week_view); - else - g_signal_connect (week_view->client, "cal_opened", - G_CALLBACK (cal_opened_cb), week_view); - } -} - -/** - * e_week_view_set_query: - * @week_view: A week view. - * @sexp: S-expression that defines the query. - * - * Sets the query sexp that the week view will use for filtering the displayed - * events. - **/ -void -e_week_view_set_query (EWeekView *week_view, const char *sexp) -{ - g_return_if_fail (week_view != NULL); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - g_return_if_fail (sexp != NULL); - - if (week_view->sexp) - g_free (week_view->sexp); - - week_view->sexp = g_strdup (sexp); - - update_query (week_view); -} - - -/** - * e_week_view_set_default_category: - * @week_view: A week view. - * @category: Default category name or NULL for no category. - * - * Sets the default category that will be used when creating new calendar - * components from the week view. - **/ -void -e_week_view_set_default_category (EWeekView *week_view, const char *category) -{ - g_return_if_fail (week_view != NULL); - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->default_category) - g_free (week_view->default_category); - - week_view->default_category = g_strdup (category); -} - - -/* This sets the selected time range. The EWeekView will show the corresponding - month and the days between start_time and end_time will be selected. - To select a single day, use the same value for start_time & end_time. */ -void -e_week_view_set_selected_time_range (EWeekView *week_view, - time_t start_time, - time_t end_time) -{ - GDate date, base_date, end_date; - gint day_offset, weekday, week_start_offset, num_days; - gboolean update_adjustment_value = FALSE; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - time_to_gdate_with_zone (&date, start_time, week_view->zone); - - if (week_view->multi_week_view) { - /* Find the number of days since the start of the month. */ - day_offset = g_date_day (&date) - 1; - - /* Find the 1st week which starts at or before the start of - the month. */ - base_date = date; - g_date_set_day (&base_date, 1); - - /* Calculate the weekday of the 1st of the month, 0 = Mon. */ - weekday = g_date_weekday (&base_date) - 1; - - /* Convert it to an offset from the start of the display. */ - week_start_offset = (weekday + 7 - week_view->display_start_day) % 7; - - /* Add it to the day offset so we go back to the 1st week at - or before the start of the month. */ - day_offset += week_start_offset; - } else { - /* Calculate the weekday of the given date, 0 = Mon. */ - weekday = g_date_weekday (&date) - 1; - - /* Convert it to an offset from the start of the display. */ - week_start_offset = (weekday + 7 - week_view->display_start_day) % 7; - - /* Set the day_offset to the result, so we move back to the - start of the week. */ - day_offset = week_start_offset; - } - - /* Calculate the base date, i.e. the first day shown when the - scrollbar adjustment value is 0. */ - base_date = date; - g_date_subtract_days (&base_date, day_offset); - - /* See if we need to update the base date. */ - if (!g_date_valid (&week_view->base_date) - || g_date_compare (&week_view->base_date, &base_date)) { - week_view->base_date = base_date; - update_adjustment_value = TRUE; - } - - /* See if we need to update the first day shown. */ - if (!g_date_valid (&week_view->first_day_shown) - || g_date_compare (&week_view->first_day_shown, &base_date)) { - week_view->first_day_shown = base_date; - start_time = time_add_day_with_zone (start_time, -day_offset, - week_view->zone); - start_time = time_day_begin_with_zone (start_time, - week_view->zone); - e_week_view_recalc_day_starts (week_view, start_time); - update_query (week_view); - } - - /* Set the selection to the given days. */ - week_view->selection_start_day = g_date_julian (&date) - - g_date_julian (&base_date); - if (end_time == start_time - || end_time <= time_add_day_with_zone (start_time, 1, - week_view->zone)) - week_view->selection_end_day = week_view->selection_start_day; - else { - time_to_gdate_with_zone (&end_date, end_time - 60, week_view->zone); - week_view->selection_end_day = g_date_julian (&end_date) - - g_date_julian (&base_date); - } - - /* Make sure the selection is valid. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - num_days--; - week_view->selection_start_day = CLAMP (week_view->selection_start_day, - 0, num_days); - week_view->selection_end_day = CLAMP (week_view->selection_end_day, - week_view->selection_start_day, - num_days); - - /* Reset the adjustment value to 0 if the base address has changed. - Note that we do this after updating first_day_shown so that our - signal handler will not try to reload the events. */ - if (update_adjustment_value) - gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0); - - gtk_widget_queue_draw (week_view->main_canvas); -} - -void -e_week_view_set_selected_time_range_visible (EWeekView *week_view, - time_t start_time, - time_t end_time) -{ - GDate date, end_date; - gint num_days; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - time_to_gdate_with_zone (&date, start_time, week_view->zone); - - /* Set the selection to the given days. */ - week_view->selection_start_day = g_date_julian (&date) - - g_date_julian (&week_view->first_day_shown); - if (end_time == start_time - || end_time <= time_add_day_with_zone (start_time, 1, - week_view->zone)) - week_view->selection_end_day = week_view->selection_start_day; - else { - time_to_gdate_with_zone (&end_date, end_time - 60, week_view->zone); - week_view->selection_end_day = g_date_julian (&end_date) - - g_date_julian (&week_view->first_day_shown); - } - - /* Make sure the selection is valid. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - num_days--; - week_view->selection_start_day = CLAMP (week_view->selection_start_day, - 0, num_days); - week_view->selection_end_day = CLAMP (week_view->selection_end_day, - week_view->selection_start_day, - num_days); - - gtk_widget_queue_draw (week_view->main_canvas); -} - - -/* Returns the selected time range. */ -void -e_week_view_get_selected_time_range (EWeekView *week_view, - time_t *start_time, - time_t *end_time) -{ - gint start_day, end_day; - - start_day = week_view->selection_start_day; - end_day = week_view->selection_end_day; - - if (start_day == -1) { - start_day = 0; - end_day = 0; - } - - if (start_time) - *start_time = week_view->day_starts[start_day]; - - if (end_time) - *end_time = week_view->day_starts[end_day + 1]; -} - - -/* Note that the returned date may be invalid if no date has been set yet. */ -void -e_week_view_get_first_day_shown (EWeekView *week_view, - GDate *date) -{ - *date = week_view->first_day_shown; -} - - -/* This sets the first day shown in the view. It will be rounded down to the - nearest week. */ -void -e_week_view_set_first_day_shown (EWeekView *week_view, - GDate *date) -{ - GDate base_date; - gint weekday, day_offset, num_days; - gboolean update_adjustment_value = FALSE; - guint32 old_selection_start_julian = 0, old_selection_end_julian = 0; - struct icaltimetype start_tt = icaltime_null_time (); - time_t start_time; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - /* Calculate the old selection range. */ - if (week_view->selection_start_day != -1) { - old_selection_start_julian = - g_date_julian (&week_view->base_date) - + week_view->selection_start_day; - old_selection_end_julian = - g_date_julian (&week_view->base_date) - + week_view->selection_end_day; - } - - /* Calculate the weekday of the given date, 0 = Mon. */ - weekday = g_date_weekday (date) - 1; - - /* Convert it to an offset from the start of the display. */ - day_offset = (weekday + 7 - week_view->display_start_day) % 7; - - /* Calculate the base date, i.e. the first day shown when the - scrollbar adjustment value is 0. */ - base_date = *date; - g_date_subtract_days (&base_date, day_offset); - - /* See if we need to update the base date. */ - if (!g_date_valid (&week_view->base_date) - || g_date_compare (&week_view->base_date, &base_date)) { - week_view->base_date = base_date; - update_adjustment_value = TRUE; - } - - /* See if we need to update the first day shown. */ - if (!g_date_valid (&week_view->first_day_shown) - || g_date_compare (&week_view->first_day_shown, &base_date)) { - week_view->first_day_shown = base_date; - - start_tt.year = g_date_year (&base_date); - start_tt.month = g_date_month (&base_date); - start_tt.day = g_date_day (&base_date); - - start_time = icaltime_as_timet_with_zone (start_tt, - week_view->zone); - - e_week_view_recalc_day_starts (week_view, start_time); - update_query (week_view); - } - - /* Try to keep the previous selection, but if it is no longer shown - just select the first day. */ - if (week_view->selection_start_day != -1) { - week_view->selection_start_day = old_selection_start_julian - - g_date_julian (&base_date); - week_view->selection_end_day = old_selection_end_julian - - g_date_julian (&base_date); - - /* Make sure the selection is valid. */ - num_days = week_view->multi_week_view - ? week_view->weeks_shown * 7 : 7; - num_days--; - week_view->selection_start_day = - CLAMP (week_view->selection_start_day, 0, num_days); - week_view->selection_end_day = - CLAMP (week_view->selection_end_day, - week_view->selection_start_day, - num_days); - } - - /* Reset the adjustment value to 0 if the base address has changed. - Note that we do this after updating first_day_shown so that our - signal handler will not try to reload the events. */ - if (update_adjustment_value) - gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0); - - gtk_widget_queue_draw (week_view->main_canvas); -} - - -/* Recalculates the time_t corresponding to the start of each day. */ -static void -e_week_view_recalc_day_starts (EWeekView *week_view, - time_t lower) -{ - gint num_days, day; - time_t tmp_time; - - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - - tmp_time = lower; - week_view->day_starts[0] = tmp_time; - for (day = 1; day <= num_days; day++) { - tmp_time = time_add_day_with_zone (tmp_time, 1, - week_view->zone); - week_view->day_starts[day] = tmp_time; - } -} - - -gboolean -e_week_view_get_multi_week_view (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - return week_view->multi_week_view; -} - - -void -e_week_view_set_multi_week_view (EWeekView *week_view, - gboolean multi_week_view) -{ - GtkAdjustment *adjustment; - gint page_increment, page_size; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->multi_week_view == multi_week_view) - return; - - week_view->multi_week_view = multi_week_view; - - if (multi_week_view) { - gtk_widget_show (week_view->titles_canvas); - page_increment = 4; - page_size = 5; - } else { - gtk_widget_hide (week_view->titles_canvas); - page_increment = page_size = 1; - } - - adjustment = GTK_RANGE (week_view->vscrollbar)->adjustment; - adjustment->page_increment = page_increment; - adjustment->page_size = page_size; - gtk_adjustment_changed (adjustment); - - e_week_view_recalc_cell_sizes (week_view); - - if (g_date_valid (&week_view->first_day_shown)) - e_week_view_set_first_day_shown (week_view, - &week_view->first_day_shown); -} - - -gint -e_week_view_get_weeks_shown (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 1); - - return week_view->weeks_shown; -} - - -void -e_week_view_set_weeks_shown (EWeekView *week_view, - gint weeks_shown) -{ - GtkAdjustment *adjustment; - gint page_increment, page_size; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - weeks_shown = MIN (weeks_shown, E_WEEK_VIEW_MAX_WEEKS); - - if (week_view->weeks_shown == weeks_shown) - return; - - week_view->weeks_shown = weeks_shown; - - if (week_view->multi_week_view) { - page_increment = 4; - page_size = 5; - - adjustment = GTK_RANGE (week_view->vscrollbar)->adjustment; - adjustment->page_increment = page_increment; - adjustment->page_size = page_size; - gtk_adjustment_changed (adjustment); - - e_week_view_recalc_cell_sizes (week_view); - - if (g_date_valid (&week_view->first_day_shown)) - e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown); - - update_query (week_view); - } -} - - -gboolean -e_week_view_get_compress_weekend (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - return week_view->compress_weekend; -} - - -void -e_week_view_set_compress_weekend (EWeekView *week_view, - gboolean compress) -{ - gboolean need_reload = FALSE; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->compress_weekend == compress) - return; - - week_view->compress_weekend = compress; - - /* The option only affects the month view. */ - if (!week_view->multi_week_view) - return; - - e_week_view_recalc_cell_sizes (week_view); - - need_reload = e_week_view_recalc_display_start_day (week_view); - - /* If the display_start_day has changed we need to recalculate the - date range shown and reload all events, otherwise we only need to - do a reshape. */ - if (need_reload) { - /* Recalculate the days shown and reload if necessary. */ - if (g_date_valid (&week_view->first_day_shown)) - e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown); - } else { - week_view->events_need_reshape = TRUE; - e_week_view_check_layout (week_view); - } -} - - -/* Whether we display event end times. */ -gboolean -e_week_view_get_show_event_end_times (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), TRUE); - - return week_view->show_event_end_times; -} - - -void -e_week_view_set_show_event_end_times (EWeekView *week_view, - gboolean show) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->show_event_end_times != show) { - week_view->show_event_end_times = show; - e_week_view_recalc_cell_sizes (week_view); - week_view->events_need_reshape = TRUE; - e_week_view_check_layout (week_view); - } -} - - -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint -e_week_view_get_week_start_day (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 0); - - return week_view->week_start_day; -} - - -void -e_week_view_set_week_start_day (EWeekView *week_view, - gint week_start_day) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - g_return_if_fail (week_start_day >= 0); - g_return_if_fail (week_start_day < 7); - - if (week_view->week_start_day == week_start_day) - return; - - week_view->week_start_day = week_start_day; - - e_week_view_recalc_display_start_day (week_view); - - /* Recalculate the days shown and reload if necessary. */ - if (g_date_valid (&week_view->first_day_shown)) - e_week_view_set_first_day_shown (week_view, - &week_view->first_day_shown); -} - - -/* Whether we use 12-hour or 24-hour format. */ -gboolean -e_week_view_get_24_hour_format (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - - return week_view->use_24_hour_format; -} - - -void -e_week_view_set_24_hour_format (EWeekView *week_view, - gboolean use_24_hour) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->use_24_hour_format == use_24_hour) - return; - - week_view->use_24_hour_format = use_24_hour; - - /* We need to re-layout the events since the time format affects the - sizes. */ - e_week_view_recalc_cell_sizes (week_view); - week_view->events_need_reshape = TRUE; - e_week_view_check_layout (week_view); - gtk_widget_queue_draw (week_view->main_canvas); -} - - -/* The current timezone. */ -icaltimezone* -e_week_view_get_timezone (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL); - - return week_view->zone; -} - - -void -e_week_view_set_timezone (EWeekView *week_view, - icaltimezone *zone) -{ - icaltimezone *old_zone; - struct icaltimetype tt = icaltime_null_time (); - time_t lower; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - old_zone = week_view->zone; - if (old_zone == zone) - return; - - week_view->zone = zone; - - /* If we don't have a valid date set yet, just return. */ - if (!g_date_valid (&week_view->first_day_shown)) - return; - - /* Recalculate the new start of the first week. We just use exactly - the same time, but with the new timezone. */ - tt.year = g_date_year (&week_view->first_day_shown); - tt.month = g_date_month (&week_view->first_day_shown); - tt.day = g_date_day (&week_view->first_day_shown); - - lower = icaltime_as_timet_with_zone (tt, zone); - - e_week_view_recalc_day_starts (week_view, lower); - update_query (week_view); -} - - -void -e_week_view_cut_clipboard (EWeekView *week_view) -{ - EWeekViewEvent *event; - const char *uid; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->editing_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - if (event == NULL) - return; - - e_week_view_set_status_message (week_view, _("Deleting selected objects")); - - e_week_view_copy_clipboard (week_view); - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); - - e_week_view_set_status_message (week_view, NULL); -} - -void -e_week_view_copy_clipboard (EWeekView *week_view) -{ - EWeekViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - if (event == NULL) - return; - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (week_view->clipboard_selection != NULL) - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = g_strdup (comp_str); - gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -void -e_week_view_paste_clipboard (EWeekView *week_view) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - gtk_selection_convert (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - - -static gboolean -e_week_view_recalc_display_start_day (EWeekView *week_view) -{ - gint display_start_day; - - /* The display start day defaults to week_start_day, but we have - to use Saturday if the weekend is compressed and week_start_day - is Sunday. */ - display_start_day = week_view->week_start_day; - - if (display_start_day == 6 - && (!week_view->multi_week_view || week_view->compress_weekend)) - display_start_day = 5; - - if (week_view->display_start_day != display_start_day) { - week_view->display_start_day = display_start_day; - return TRUE; - } - - return FALSE; -} - - -static gboolean -e_week_view_update_event_cb (EWeekView *week_view, - gint event_num, - gpointer data) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint span_num; - gchar *text; - CalComponent *comp; - - comp = data; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - - g_object_unref (event->comp); - event->comp = comp; - g_object_ref (comp); - - for (span_num = 0; span_num < event->num_spans; span_num++) { - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - - if (span->text_item) { - CalComponentText t; - - cal_component_get_summary (event->comp, &t); - text = (char*) t.value; - gnome_canvas_item_set (span->text_item, - "text", text ? text : "", - NULL); - - e_week_view_reshape_event_span (week_view, event_num, - span_num); - } - } - - return TRUE; -} - - -/* This calls a given function for each event instance that matches the given - uid. Note that it is safe for the callback to remove the event (since we - step backwards through the arrays). */ -static void -e_week_view_foreach_event_with_uid (EWeekView *week_view, - const gchar *uid, - EWeekViewForeachEventCallback callback, - gpointer data) -{ - EWeekViewEvent *event; - gint event_num; - - for (event_num = week_view->events->len - 1; - event_num >= 0; - event_num--) { - const char *u; - - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - cal_component_get_uid (event->comp, &u); - if (u && !strcmp (uid, u)) { - if (!(*callback) (week_view, event_num, data)) - return; - } - } -} - - -static gboolean -e_week_view_remove_event_cb (EWeekView *week_view, - gint event_num, - gpointer data) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint span_num; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - - /* If we were editing this event, set editing_event_num to -1 so - on_editing_stopped doesn't try to update the event. */ - if (week_view->editing_event_num == event_num) - week_view->editing_event_num = -1; - - /* We leave the span elements in the array, but set the canvas item - pointers to NULL. */ - for (span_num = 0; span_num < event->num_spans; span_num++) { - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - - if (span->text_item) { - gtk_object_destroy (GTK_OBJECT (span->text_item)); - span->text_item = NULL; - } - if (span->background_item) { - gtk_object_destroy (GTK_OBJECT (span->background_item)); - span->background_item = NULL; - } - } - - g_object_unref (event->comp); - - g_array_remove_index (week_view->events, event_num); - week_view->events_need_layout = TRUE; - - return TRUE; -} - - -void -e_week_view_get_day_position (EWeekView *week_view, - gint day, - gint *day_x, - gint *day_y, - gint *day_w, - gint *day_h) -{ - gint cell_x, cell_y, cell_h; - - e_week_view_layout_get_day_position (day, - week_view->multi_week_view, - week_view->weeks_shown, - week_view->display_start_day, - week_view->compress_weekend, - &cell_x, &cell_y, &cell_h); - - *day_x = week_view->col_offsets[cell_x]; - *day_y = week_view->row_offsets[cell_y]; - - *day_w = week_view->col_widths[cell_x]; - *day_h = week_view->row_heights[cell_y]; - if (cell_h == 2) - *day_h += week_view->row_heights[cell_y + 1]; -} - - -/* Returns the bounding box for a span of an event. Usually this can easily - be determined by the start & end days and row of the span, which are set in - e_week_view_layout_event(). Though we need a special case for the weekends - when they are compressed, since the span may not fit. - The bounding box includes the entire width of the days in the view (but - not the vertical line down the right of the last day), though the displayed - event doesn't normally extend to the edges of the day. - It returns FALSE if the span isn't visible. */ -gboolean -e_week_view_get_span_position (EWeekView *week_view, - gint event_num, - gint span_num, - gint *span_x, - gint *span_y, - gint *span_w) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint num_days; - gint start_x, start_y, start_w, start_h; - gint end_x, end_y, end_w, end_h; - - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE); - g_return_val_if_fail (event_num < week_view->events->len, FALSE); - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - - g_return_val_if_fail (span_num < event->num_spans, FALSE); - - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - - if (!e_week_view_layout_get_span_position (event, span, - week_view->rows_per_cell, - week_view->rows_per_compressed_cell, - week_view->display_start_day, - week_view->multi_week_view, - week_view->compress_weekend, - &num_days)) { - return FALSE; - } - - e_week_view_get_day_position (week_view, span->start_day, - &start_x, &start_y, &start_w, &start_h); - *span_y = start_y + week_view->events_y_offset - + span->row * (week_view->row_height - + E_WEEK_VIEW_EVENT_Y_SPACING); - if (num_days == 1) { - *span_x = start_x; - *span_w = start_w - 1; - } else { - e_week_view_get_day_position (week_view, - span->start_day + num_days - 1, - &end_x, &end_y, &end_w, &end_h); - *span_x = start_x; - *span_w = end_x + end_w - start_x - 1; - } - - return TRUE; -} - - - -static gboolean -e_week_view_on_button_press (GtkWidget *widget, - GdkEventButton *event, - EWeekView *week_view) -{ - gint x, y, day; - -#if 0 - g_print ("In e_week_view_on_button_press\n"); - if (event->type == GDK_2BUTTON_PRESS) - g_print (" is a double-click\n"); - if (week_view->pressed_event_num != -1) - g_print (" item is pressed\n"); -#endif - - /* Handle scroll wheel events */ - if (event->button == 4 || event->button == 5) { - GtkAdjustment *adj = GTK_RANGE (week_view->vscrollbar)->adjustment; - gfloat new_value; - - new_value = adj->value + ((event->button == 4) ? - -adj->page_increment: - adj->page_increment); - new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); - gtk_adjustment_set_value (adj, new_value); - - return TRUE; - } - - /* Convert the mouse position to a week & day. */ - x = event->x; - y = event->y; - day = e_week_view_convert_position_to_day (week_view, x, y); - if (day == -1) - return FALSE; - - /* If an event is pressed just return. */ - if (week_view->pressed_event_num != -1) - return FALSE; - - if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { - e_week_view_new_appointment (week_view, FALSE); - return TRUE; - } - - if (event->button == 1) { - /* Start the selection drag. */ - if (!GTK_WIDGET_HAS_FOCUS (week_view)) - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - - if (gdk_pointer_grab (GTK_LAYOUT (widget)->bin_window, FALSE, - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - FALSE, NULL, event->time) == 0) { - week_view->selection_start_day = day; - week_view->selection_end_day = day; - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_END; - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (week_view->main_canvas); - } - } else if (event->button == 3) { - if (!GTK_WIDGET_HAS_FOCUS (week_view)) - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - - if (day < week_view->selection_start_day || day > week_view->selection_end_day) { - week_view->selection_start_day = day; - week_view->selection_end_day = day; - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE; - - /* FIXME: Optimise? */ - gtk_widget_queue_draw (week_view->main_canvas); - } - - e_week_view_show_popup_menu (week_view, event, -1); - } - - return FALSE; -} - - -static gboolean -e_week_view_on_button_release (GtkWidget *widget, - GdkEventButton *event, - EWeekView *week_view) -{ - time_t start, end; - -#if 0 - g_print ("In e_week_view_on_button_release\n"); -#endif - - if (week_view->selection_drag_pos != E_WEEK_VIEW_DRAG_NONE) { - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE; - gdk_pointer_ungrab (event->time); - start = week_view->day_starts[week_view->selection_start_day]; - end = week_view->day_starts[week_view->selection_end_day + 1]; - - if (week_view->calendar) - gnome_calendar_set_selected_time_range (week_view->calendar, start, end); - } - - return FALSE; -} - - -static gboolean -e_week_view_on_motion (GtkWidget *widget, - GdkEventMotion *mevent, - EWeekView *week_view) -{ - gint x, y, day; - -#if 0 - g_print ("In e_week_view_on_motion\n"); -#endif - - /* Convert the mouse position to a week & day. */ - x = mevent->x; - y = mevent->y; - day = e_week_view_convert_position_to_day (week_view, x, y); - if (day == -1) - return FALSE; - - if (week_view->selection_drag_pos != E_WEEK_VIEW_DRAG_NONE) { - e_week_view_update_selection (week_view, day); - return TRUE; - } - - return FALSE; -} - - -/* Converts a position in the canvas window to a day offset from the first - day displayed. Returns -1 if the position is outside the grid. */ -static gint -e_week_view_convert_position_to_day (EWeekView *week_view, - gint x, - gint y) -{ - gint col, row, grid_x = -1, grid_y = -1, week, day; - gint weekend_col, box, weekend_box; - - /* First we convert it to a grid position. */ - for (col = 0; col <= week_view->columns; col++) { - if (x < week_view->col_offsets[col]) { - grid_x = col - 1; - break; - } - } - - for (row = 0; row <= week_view->rows; row++) { - if (y < week_view->row_offsets[row]) { - grid_y = row - 1; - break; - } - } - - /* If the mouse is outside the grid return FALSE. */ - if (grid_x == -1 || grid_y == -1) - return -1; - - /* Now convert the grid position to a week and day. */ - if (week_view->multi_week_view) { - week = grid_y / 2; - day = grid_x; - - if (week_view->compress_weekend) { - weekend_col = (5 + 7 - week_view->display_start_day) % 7; - if (grid_x > weekend_col - || (grid_x == weekend_col && grid_y % 2 == 1)) - day++; - } - } else { - week = 0; - - box = grid_x * 3 + grid_y / 2; - weekend_box = (5 + 7 - week_view->display_start_day) % 7; - day = box; - if (box > weekend_box - ||( box == weekend_box && grid_y % 2 == 1)) - day++; - } - - return week * 7 + day; -} - - -static void -e_week_view_update_selection (EWeekView *week_view, - gint day) -{ - gint tmp_day; - gboolean need_redraw = FALSE; - -#if 0 - g_print ("Updating selection %i,%i\n", week, day); -#endif - - if (week_view->selection_drag_pos == E_WEEK_VIEW_DRAG_START) { - if (day != week_view->selection_start_day) { - need_redraw = TRUE; - week_view->selection_start_day = day; - } - } else { - if (day != week_view->selection_end_day) { - need_redraw = TRUE; - week_view->selection_end_day = day; - } - } - - /* Switch the drag position if necessary. */ - if (week_view->selection_start_day > week_view->selection_end_day) { - tmp_day = week_view->selection_start_day; - week_view->selection_start_day = week_view->selection_end_day; - week_view->selection_end_day = tmp_day; - if (week_view->selection_drag_pos == E_WEEK_VIEW_DRAG_START) - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_END; - else - week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_START; - } - - /* FIXME: Optimise? */ - if (need_redraw) { - gtk_widget_queue_draw (week_view->main_canvas); - } -} - - -static void -e_week_view_free_events (EWeekView *week_view) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint event_num, span_num, num_days, day; - - /* Reset all our indices. */ - week_view->pressed_event_num = -1; - week_view->pressed_span_num = -1; - week_view->editing_event_num = -1; - week_view->editing_span_num = -1; - week_view->popup_event_num = -1; - - for (event_num = 0; event_num < week_view->events->len; event_num++) { - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - g_object_unref (event->comp); - } - - g_array_set_size (week_view->events, 0); - - /* Destroy all the old canvas items. */ - if (week_view->spans) { - for (span_num = 0; span_num < week_view->spans->len; - span_num++) { - span = &g_array_index (week_view->spans, - EWeekViewEventSpan, span_num); - if (span->background_item) - gtk_object_destroy (GTK_OBJECT (span->background_item)); - if (span->text_item) - gtk_object_destroy (GTK_OBJECT (span->text_item)); - } - g_array_free (week_view->spans, TRUE); - week_view->spans = NULL; - } - - /* Clear the number of rows used per day. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - for (day = 0; day <= num_days; day++) { - week_view->rows_per_day[day] = 0; - } - - /* Hide all the jump buttons. */ - for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) { - gnome_canvas_item_hide (week_view->jump_buttons[day]); - } -} - - -/* This adds one event to the view, adding it to the appropriate array. */ -static gboolean -e_week_view_add_event (CalComponent *comp, - time_t start, - time_t end, - gpointer data) - -{ - EWeekView *week_view; - EWeekViewEvent event; - gint num_days; - struct icaltimetype start_tt, end_tt; - - week_view = E_WEEK_VIEW (data); - - /* Check that the event times are valid. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - -#if 0 - g_print ("View start:%li end:%li Event start:%li end:%li\n", - week_view->day_starts[0], week_view->day_starts[num_days], - start, end); -#endif - - g_return_val_if_fail (start <= end, TRUE); - g_return_val_if_fail (start < week_view->day_starts[num_days], TRUE); - g_return_val_if_fail (end > week_view->day_starts[0], TRUE); - - start_tt = icaltime_from_timet_with_zone (start, FALSE, - week_view->zone); - end_tt = icaltime_from_timet_with_zone (end, FALSE, - week_view->zone); - - event.comp = comp; - g_object_ref (event.comp); - event.start = start; - event.end = end; - event.spans_index = 0; - event.num_spans = 0; - - event.start_minute = start_tt.hour * 60 + start_tt.minute; - event.end_minute = end_tt.hour * 60 + end_tt.minute; - if (event.end_minute == 0 && start != end) - event.end_minute = 24 * 60; - - event.different_timezone = FALSE; - if (!cal_comp_util_compare_event_timezones (comp, week_view->client, - week_view->zone)) - event.different_timezone = TRUE; - - g_array_append_val (week_view->events, event); - week_view->events_sorted = FALSE; - week_view->events_need_layout = TRUE; - - return TRUE; -} - - -/* This lays out the events, or reshapes them, as necessary. */ -static void -e_week_view_check_layout (EWeekView *week_view) -{ - /* Don't bother if we aren't visible. */ - if (!GTK_WIDGET_VISIBLE (week_view)) - return; - - /* Make sure the events are sorted (by start and size). */ - e_week_view_ensure_events_sorted (week_view); - - if (week_view->events_need_layout) - week_view->spans = e_week_view_layout_events - (week_view->events, week_view->spans, - week_view->multi_week_view, - week_view->weeks_shown, - week_view->compress_weekend, - week_view->display_start_day, - week_view->day_starts, - week_view->rows_per_day); - - if (week_view->events_need_layout || week_view->events_need_reshape) - e_week_view_reshape_events (week_view); - - week_view->events_need_layout = FALSE; - week_view->events_need_reshape = FALSE; -} - - -static void -e_week_view_ensure_events_sorted (EWeekView *week_view) -{ - if (!week_view->events_sorted) { - qsort (week_view->events->data, - week_view->events->len, - sizeof (EWeekViewEvent), - e_week_view_event_sort_func); - week_view->events_sorted = TRUE; - } -} - - -gint -e_week_view_event_sort_func (const void *arg1, - const void *arg2) -{ - EWeekViewEvent *event1, *event2; - - event1 = (EWeekViewEvent*) arg1; - event2 = (EWeekViewEvent*) arg2; - - if (event1->start < event2->start) - return -1; - if (event1->start > event2->start) - return 1; - - if (event1->end > event2->end) - return -1; - if (event1->end < event2->end) - return 1; - - return 0; -} - - -static void -e_week_view_reshape_events (EWeekView *week_view) -{ - EWeekViewEvent *event; - gint event_num, span_num; - gint num_days, day, day_x, day_y, day_w, day_h, max_rows; - gboolean is_weekend; - - for (event_num = 0; event_num < week_view->events->len; event_num++) { - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - for (span_num = 0; span_num < event->num_spans; span_num++) { - e_week_view_reshape_event_span (week_view, event_num, - span_num); - } - } - - /* Reshape the jump buttons and show/hide them as appropriate. */ - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - for (day = 0; day < num_days; day++) { - - is_weekend = ((week_view->display_start_day + day) % 7 >= 5) ? TRUE : FALSE; - if (!is_weekend || (week_view->multi_week_view - && !week_view->compress_weekend)) - max_rows = week_view->rows_per_cell; - else - max_rows = week_view->rows_per_compressed_cell; - - /* Determine whether the jump button should be shown. */ - if (week_view->rows_per_day[day] <= max_rows) { - gnome_canvas_item_hide (week_view->jump_buttons[day]); - } else { - e_week_view_get_day_position (week_view, day, - &day_x, &day_y, - &day_w, &day_h); - - gnome_canvas_item_set (week_view->jump_buttons[day], - "GnomeCanvasPixbuf::x", (gdouble) (day_x + day_w - E_WEEK_VIEW_JUMP_BUTTON_X_PAD - E_WEEK_VIEW_JUMP_BUTTON_WIDTH), - "GnomeCanvasPixbuf::y", (gdouble) (day_y + day_h - E_WEEK_VIEW_JUMP_BUTTON_Y_PAD - E_WEEK_VIEW_JUMP_BUTTON_HEIGHT), - NULL); - - gnome_canvas_item_show (week_view->jump_buttons[day]); - gnome_canvas_item_raise_to_top (week_view->jump_buttons[day]); - } - } - - for (day = num_days; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) { - gnome_canvas_item_hide (week_view->jump_buttons[day]); - } -} - - -static void -e_week_view_reshape_event_span (EWeekView *week_view, - gint event_num, - gint span_num) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint span_x, span_y, span_w, num_icons, icons_width, time_width; - gint min_text_x, max_text_w, width; - gboolean show_icons = TRUE, use_max_width = FALSE; - gboolean one_day_event; - CalComponent *comp; - gdouble text_x, text_y, text_w, text_h; - gchar *text, *end_of_line; - gint line_len, text_width; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - comp = event->comp; - - one_day_event = e_week_view_is_one_day_event (week_view, event_num); - - /* If the span will not be visible destroy the canvas items and - return. */ - if (!e_week_view_get_span_position (week_view, event_num, span_num, - &span_x, &span_y, &span_w)) { - if (span->background_item) - gtk_object_destroy (GTK_OBJECT (span->background_item)); - if (span->text_item) - gtk_object_destroy (GTK_OBJECT (span->text_item)); - span->background_item = NULL; - span->text_item = NULL; - return; - } - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (GTK_WIDGET (week_view))->font_desc; - pango_context = gtk_widget_get_pango_context (GTK_WIDGET (week_view)); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - layout = pango_layout_new (pango_context); - - /* If we are editing a long event we don't show the icons and the EText - item uses the maximum width available. */ - if (!one_day_event && week_view->editing_event_num == event_num - && week_view->editing_span_num == span_num) { - show_icons = FALSE; - use_max_width = TRUE; - } - - /* Calculate how many icons we need to show. */ - num_icons = 0; - if (show_icons) { - GSList *categories_list, *elem; - - if (cal_component_has_alarms (comp)) - num_icons++; - if (cal_component_has_recurrences (comp)) - num_icons++; - if (event->different_timezone) - num_icons++; - - cal_component_get_categories_list (comp, &categories_list); - for (elem = categories_list; elem; elem = elem->next) { - char *category; - GdkPixmap *pixmap = NULL; - GdkBitmap *mask = NULL; - - category = (char *) elem->data; - if (e_categories_config_get_icon_for (category, &pixmap, &mask)) - num_icons++; - } - - cal_component_free_categories_list (categories_list); - } - - /* Create the background canvas item if necessary. */ - if (!span->background_item) { - span->background_item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->main_canvas)->root), - e_week_view_event_item_get_type (), - NULL); - } - - gnome_canvas_item_set (span->background_item, - "event_num", event_num, - "span_num", span_num, - NULL); - - /* Create the text item if necessary. */ - if (!span->text_item) { - CalComponentText text; - - cal_component_get_summary (comp, &text); - span->text_item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->main_canvas)->root), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "max_lines", 1, - "editable", TRUE, - "text", text.value ? text.value : "", - "use_ellipsis", TRUE, - "fill_color_rgba", GNOME_CANVAS_COLOR(0, 0, 0), - "im_context", E_CANVAS (week_view->main_canvas)->im_context, - NULL); - g_signal_connect (span->text_item, "event", - G_CALLBACK (e_week_view_on_text_item_event), - week_view); - } - - /* Calculate the position of the text item. - For events < 1 day it starts after the times & icons and ends at the - right edge of the span. - For events >= 1 day we need to determine whether times are shown at - the start and end of the span, then try to center the text item with - the icons in the middle, but making sure we don't go over the times. - */ - - - /* Calculate the space necessary to display a time, e.g. "13:00". */ - time_width = e_week_view_get_time_string_width (week_view); - - /* Calculate the space needed for the icons. */ - icons_width = (E_WEEK_VIEW_ICON_WIDTH + E_WEEK_VIEW_ICON_X_PAD) - * num_icons - E_WEEK_VIEW_ICON_X_PAD + E_WEEK_VIEW_ICON_R_PAD; - - /* The y position and height are the same for both event types. */ - text_y = span_y + E_WEEK_VIEW_EVENT_BORDER_HEIGHT - + E_WEEK_VIEW_EVENT_TEXT_Y_PAD; - - text_h = - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)); - - if (one_day_event) { - /* Note that 1-day events don't have a border. Although we - still use the border height to position the events - vertically so they still line up neatly (see above), - we don't use the border width or edge padding at all. */ - text_x = span_x + E_WEEK_VIEW_EVENT_L_PAD; - - switch (week_view->time_format) { - case E_WEEK_VIEW_TIME_BOTH_SMALL_MIN: - case E_WEEK_VIEW_TIME_BOTH: - /* These have 2 time strings with a small space between - them and some space before the EText item. */ - text_x += time_width * 2 - + E_WEEK_VIEW_EVENT_TIME_SPACING - + E_WEEK_VIEW_EVENT_TIME_X_PAD; - break; - case E_WEEK_VIEW_TIME_START_SMALL_MIN: - case E_WEEK_VIEW_TIME_START: - /* These have just 1 time string with some space - before the EText item. */ - text_x += time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; - break; - case E_WEEK_VIEW_TIME_NONE: - break; - } - - /* The icons_width includes space on the right of the icons. */ - text_x += icons_width; - - /* The width of the EText item extends right to the edge of the - event, just inside the border. */ - text_w = span_x + span_w - E_WEEK_VIEW_EVENT_R_PAD - text_x; - - } else { - if (use_max_width) { - /* When we are editing the event we use all the - available width. */ - text_x = span_x + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD; - text_w = span_x + span_w - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD - text_x; - } else { - /* Get the width of the text of the event. This is a - bit of a hack. It would be better if EText could - tell us this. */ - g_object_get (G_OBJECT (span->text_item), "text", &text, NULL); - text_width = 0; - if (text) { - /* It should only have one line of text in it. - I'm not sure we need this any more. */ - end_of_line = strchr (text, '\n'); - if (end_of_line) - line_len = end_of_line - text; - else - line_len = strlen (text); - - pango_layout_set_text (layout, text, line_len); - pango_layout_get_pixel_size (layout, &text_width, NULL); - g_free (text); - } - - /* Add on the width of the icons and find the default - position, which centers the icons + text. */ - width = text_width + icons_width; - text_x = span_x + (span_w - width) / 2; - - /* Now calculate the left-most valid position, and make - sure we don't go to the left of that. */ - min_text_x = span_x + E_WEEK_VIEW_EVENT_L_PAD - + E_WEEK_VIEW_EVENT_BORDER_WIDTH - + E_WEEK_VIEW_EVENT_EDGE_X_PAD; - /* See if we will want to display the start time, and - if so take that into account. */ - if (event->start > week_view->day_starts[span->start_day]) - min_text_x += time_width - + E_WEEK_VIEW_EVENT_TIME_X_PAD; - - /* Now make sure we don't go to the left of the minimum - position. */ - text_x = MAX (text_x, min_text_x); - - /* Now calculate the largest valid width, using the - calculated x position, and make sure we don't - exceed that. */ - max_text_w = span_x + span_w - E_WEEK_VIEW_EVENT_R_PAD - - E_WEEK_VIEW_EVENT_BORDER_WIDTH - - E_WEEK_VIEW_EVENT_EDGE_X_PAD - text_x; - if (event->end < week_view->day_starts[span->start_day - + span->num_days]) - max_text_w -= time_width - + E_WEEK_VIEW_EVENT_TIME_X_PAD; - - text_w = MIN (width, max_text_w); - - /* Now take out the space for the icons. */ - text_x += icons_width; - text_w -= icons_width; - } - } - - /* Make sure we don't try to use a negative width. */ - text_w = MAX (text_w, 0); - - gnome_canvas_item_set (span->text_item, - "clip_width", (gdouble) text_w, - "clip_height", (gdouble) text_h, - NULL); - e_canvas_item_move_absolute (span->text_item, text_x, text_y); - - g_object_unref (layout); - pango_font_metrics_unref (font_metrics); -} - - -static void -e_week_view_on_adjustment_changed (GtkAdjustment *adjustment, - EWeekView *week_view) -{ - GDate date; - gint week_offset; - struct icaltimetype start_tt = icaltime_null_time (); - time_t lower, start, end; - guint32 old_first_day_julian, new_first_day_julian; - - /* If we don't have a valid date set yet, just return. */ - if (!g_date_valid (&week_view->first_day_shown)) - return; - - /* Determine the first date shown. */ - date = week_view->base_date; - week_offset = floor (adjustment->value + 0.5); - g_date_add_days (&date, week_offset * 7); - - /* Convert the old & new first days shown to julian values. */ - old_first_day_julian = g_date_julian (&week_view->first_day_shown); - new_first_day_julian = g_date_julian (&date); - - /* If we are already showing the date, just return. */ - if (old_first_day_julian == new_first_day_julian) - return; - - /* Set the new first day shown. */ - week_view->first_day_shown = date; - - /* Convert it to a time_t. */ - start_tt.year = g_date_year (&date); - start_tt.month = g_date_month (&date); - start_tt.day = g_date_day (&date); - - lower = icaltime_as_timet_with_zone (start_tt, week_view->zone); - - e_week_view_recalc_day_starts (week_view, lower); - update_query (week_view); - - /* Update the selection, if needed. */ - if (week_view->selection_start_day != -1) { - start = week_view->day_starts[week_view->selection_start_day]; - end = week_view->day_starts[week_view->selection_end_day + 1]; - if (week_view->calendar) - gnome_calendar_set_selected_time_range (week_view->calendar, start, end); - } -} - - -void -e_week_view_start_editing_event (EWeekView *week_view, - gint event_num, - gint span_num, - gchar *initial_text) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - ETextEventProcessor *event_processor = NULL; - ETextEventProcessorCommand command; - - /* If we are already editing the event, just return. */ - if (event_num == week_view->editing_event_num - && span_num == week_view->editing_span_num) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - - /* If the event is not shown, don't try to edit it. */ - if (!span->text_item) - return; - - if (initial_text) { - gnome_canvas_item_set (span->text_item, - "text", initial_text, - NULL); - } - - /* FIXME: This implicitly stops any edit of another item, causing it - to be sent to the server and resulting in a call to obj_updated_cb() - which may reload all the events and so our span and text item may - actually be destroyed. So we often get a SEGV. */ - e_canvas_item_grab_focus (span->text_item, TRUE); - - /* Try to move the cursor to the end of the text. */ - g_object_get (G_OBJECT (span->text_item), "event_processor", &event_processor, NULL); - if (event_processor) { - command.action = E_TEP_MOVE; - command.position = E_TEP_END_OF_BUFFER; - g_signal_emit_by_name (event_processor, - "command", &command); - } -} - - -/* This stops any current edit. */ -void -e_week_view_stop_editing_event (EWeekView *week_view) -{ - GtkWidget *toplevel; - - /* Check we are editing an event. */ - if (week_view->editing_event_num == -1) - return; - - /* Set focus to the toplevel so the item loses focus. */ - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (week_view)); - if (toplevel && GTK_IS_WINDOW (toplevel)) - gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); -} - - -/* Cancels the current edition by resetting the appointment's text to its original value */ -static void -cancel_editing (EWeekView *week_view) -{ - int event_num, span_num; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - CalComponentText summary; - - event_num = week_view->editing_event_num; - span_num = week_view->editing_span_num; - - g_assert (event_num != -1); - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, event->spans_index + span_num); - - /* Reset the text to what was in the component */ - - cal_component_get_summary (event->comp, &summary); - g_object_set (G_OBJECT (span->text_item), "text", summary.value ? summary.value : "", NULL); - - /* Stop editing */ - e_week_view_stop_editing_event (week_view); -} - -/* Callback used when a component is destroyed. Expects the closure data to be - * a pointer to a boolean; will set it to TRUE. - */ -static void -comp_destroy_cb (gpointer data, GObject *deadbeef) -{ - gboolean *destroyed; - - destroyed = data; - *destroyed = TRUE; -} - - -static gboolean -e_week_view_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *gdkevent, - EWeekView *week_view) -{ - EWeekViewEvent *event; - gint event_num, span_num; - -#if 0 - g_print ("In e_week_view_on_text_item_event\n"); -#endif - - switch (gdkevent->type) { - case GDK_KEY_PRESS: - if (gdkevent && gdkevent->key.keyval == GDK_Return) { - /* We set the keyboard focus to the EDayView, so the - EText item loses it and stops the edit. */ - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - - /* Stop the signal last or we will also stop any - other events getting to the EText item. */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } else if (gdkevent->key.keyval == GDK_Escape) { - cancel_editing (week_view); - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - } - break; - case GDK_2BUTTON_PRESS: - if (!e_week_view_find_event_from_item (week_view, item, - &event_num, &span_num)) - return FALSE; - - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - if (week_view->calendar) - gnome_calendar_edit_object (week_view->calendar, - event->comp, FALSE); - else - g_warning ("Calendar not set"); - - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - case GDK_BUTTON_PRESS: - if (!e_week_view_find_event_from_item (week_view, item, - &event_num, &span_num)) - return FALSE; - - if (gdkevent->button.button == 3 && !E_TEXT (item)->editing) { - EWeekViewEvent *e; - gboolean destroyed; - - e = &g_array_index (week_view->events, EWeekViewEvent, event_num); - - destroyed = FALSE; - g_object_weak_ref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - if (!GTK_WIDGET_HAS_FOCUS (week_view)) - gtk_widget_grab_focus (GTK_WIDGET (week_view)); - - if (!destroyed) { - g_object_weak_unref ((GObject *) e->comp, comp_destroy_cb, &destroyed); - - e_week_view_set_selected_time_range_visible (week_view, e->start, e->end); - - e_week_view_show_popup_menu (week_view, - (GdkEventButton*) gdkevent, - event_num); - } - - gtk_signal_emit_stop_by_name (GTK_OBJECT (item->canvas), - "button_press_event"); - return TRUE; - } - - if (gdkevent->button.button != 3) { - week_view->pressed_event_num = event_num; - week_view->pressed_span_num = span_num; - } - - /* Only let the EText handle the event while editing. */ - if (!E_TEXT (item)->editing) { - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - - if (gdkevent) { - week_view->drag_event_x = gdkevent->button.x; - week_view->drag_event_y = gdkevent->button.y; - } else - g_warning ("No GdkEvent"); - - /* FIXME: Remember the day offset from the start of - the event, for DnD. */ - - return TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (!E_TEXT (item)->editing) { - /* This shouldn't ever happen. */ - if (!e_week_view_find_event_from_item (week_view, - item, - &event_num, - &span_num)) - return FALSE; - - if (week_view->pressed_event_num != -1 - && week_view->pressed_event_num == event_num - && week_view->pressed_span_num == span_num) { - e_week_view_start_editing_event (week_view, - event_num, - span_num, - NULL); - week_view->pressed_event_num = -1; - } - - /* Stop the signal last or we will also stop any - other events getting to the EText item. */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } - week_view->pressed_event_num = -1; - break; - case GDK_FOCUS_CHANGE: - if (gdkevent->focus_change.in) { - e_week_view_on_editing_started (week_view, item); - } else { - e_week_view_on_editing_stopped (week_view, item); - } - - return FALSE; - default: - break; - } - - return FALSE; -} - - -static void -e_week_view_on_editing_started (EWeekView *week_view, - GnomeCanvasItem *item) -{ - gint event_num, span_num; - - if (!e_week_view_find_event_from_item (week_view, item, - &event_num, &span_num)) - return; - -#if 0 - g_print ("In e_week_view_on_editing_started event_num:%i span_num:%i\n", event_num, span_num); -#endif - - week_view->editing_event_num = event_num; - week_view->editing_span_num = span_num; - - /* We need to reshape long events so the whole width is used while - editing. */ - if (!e_week_view_is_one_day_event (week_view, event_num)) { - e_week_view_reshape_event_span (week_view, event_num, - span_num); - } - - g_object_set (item, "handle_popup", TRUE, NULL); - - gtk_signal_emit (GTK_OBJECT (week_view), - e_week_view_signals[SELECTION_CHANGED]); -} - - -static void -e_week_view_on_editing_stopped (EWeekView *week_view, - GnomeCanvasItem *item) -{ - gint event_num, span_num; - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gchar *text = NULL; - CalComponentText summary; - const char *uid; - - /* Note: the item we are passed here isn't reliable, so we just stop - the edit of whatever item was being edited. We also receive this - event twice for some reason. */ - event_num = week_view->editing_event_num; - span_num = week_view->editing_span_num; - - /* If no item is being edited, just return. */ - if (event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index + span_num); - - /* Reset the edit fields. */ - week_view->editing_event_num = -1; - - /* Check that the event is still valid. */ - cal_component_get_uid (event->comp, &uid); - if (!uid) - return; - - g_object_set (span->text_item, "handle_popup", FALSE, NULL); - g_object_get (G_OBJECT (span->text_item), "text", &text, NULL); - g_assert (text != NULL); - - if (string_is_empty (text) && !cal_comp_is_on_server (event->comp, week_view->client)) { - const char *uid; - - cal_component_get_uid (event->comp, &uid); - - e_week_view_foreach_event_with_uid (week_view, uid, - e_week_view_remove_event_cb, NULL); - gtk_widget_queue_draw (week_view->main_canvas); - e_week_view_check_layout (week_view); - goto out; - } - - /* Only update the summary if necessary. */ - cal_component_get_summary (event->comp, &summary); - if (summary.value && !strcmp (text, summary.value)) { - if (!e_week_view_is_one_day_event (week_view, event_num)) - e_week_view_reshape_event_span (week_view, event_num, - span_num); - } else if (summary.value || !string_is_empty (text)) { - summary.value = text; - summary.altrep = NULL; - cal_component_set_summary (event->comp, &summary); - - if (cal_component_is_instance (event->comp)) { - CalObjModType mod; - - if (recur_component_dialog (event->comp, &mod, NULL)) { - if (cal_client_update_object_with_mod (week_view->client, event->comp, mod) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, week_view->client) - && send_component_dialog (week_view->client, event->comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - week_view->client, NULL); - } else { - g_message ("e_week_view_on_editing_stopped(): Could not update the object!"); - } - } - } else if (cal_client_update_object (week_view->client, event->comp) == CAL_CLIENT_RESULT_SUCCESS) { - if (itip_organizer_is_user (event->comp, week_view->client) && send_component_dialog (week_view->client, event->comp, FALSE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, event->comp, - week_view->client, NULL); - } else { - g_message ("e_week_view_on_editing_stopped(): Could not update the object!"); - } - } - - out: - - g_free (text); - - gtk_signal_emit (GTK_OBJECT (week_view), - e_week_view_signals[SELECTION_CHANGED]); -} - - -static gboolean -e_week_view_find_event_from_item (EWeekView *week_view, - GnomeCanvasItem *item, - gint *event_num_return, - gint *span_num_return) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - gint event_num, span_num, num_events; - - num_events = week_view->events->len; - for (event_num = 0; event_num < num_events; event_num++) { - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - for (span_num = 0; span_num < event->num_spans; span_num++) { - span = &g_array_index (week_view->spans, - EWeekViewEventSpan, - event->spans_index + span_num); - if (span->text_item == item) { - *event_num_return = event_num; - *span_num_return = span_num; - return TRUE; - } - } - } - - return FALSE; -} - - -/* Finds the index of the event with the given uid. - Returns TRUE if an event with the uid was found. - Note that for recurring events there may be several EWeekViewEvents, one - for each instance, all with the same iCalObject and uid. So only use this - function if you know the event doesn't recur or you are just checking to - see if any events with the uid exist. */ -static gboolean -e_week_view_find_event_from_uid (EWeekView *week_view, - const gchar *uid, - gint *event_num_return) -{ - EWeekViewEvent *event; - gint event_num, num_events; - - num_events = week_view->events->len; - for (event_num = 0; event_num < num_events; event_num++) { - const char *u; - - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - cal_component_get_uid (event->comp, &u); - if (u && !strcmp (uid, u)) { - *event_num_return = event_num; - return TRUE; - } - } - - return FALSE; -} - - -gboolean -e_week_view_is_one_day_event (EWeekView *week_view, - gint event_num) -{ - EWeekViewEvent *event; - EWeekViewEventSpan *span; - - event = &g_array_index (week_view->events, EWeekViewEvent, event_num); - if (event->num_spans != 1) - return FALSE; - - span = &g_array_index (week_view->spans, EWeekViewEventSpan, - event->spans_index); - - if (event->start == week_view->day_starts[span->start_day] - && event->end == week_view->day_starts[span->start_day + 1]) - return FALSE; - - if (span->num_days == 1 - && event->start >= week_view->day_starts[span->start_day] - && event->end <= week_view->day_starts[span->start_day + 1]) - return TRUE; - - return FALSE; -} - - -static gint -e_week_view_key_press (GtkWidget *widget, GdkEventKey *event) -{ - EWeekView *week_view; - CalComponent *comp; - gint event_num; - gchar *initial_text; - CalComponentDateTime date; - struct icaltimetype itt; - time_t dtstart, dtend; - const char *uid; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - week_view = E_WEEK_VIEW (widget); - - if (cal_client_get_load_state (week_view->client) != CAL_CLIENT_LOAD_LOADED) - return TRUE; - - /* The Escape key aborts a resize operation. */ -#if 0 - if (week_view->resize_drag_pos != E_WEEK_VIEW_POS_NONE) { - if (event->keyval == GDK_Escape) { - e_week_view_abort_resize (week_view, event->time); - } - return FALSE; - } -#endif - - if (week_view->selection_start_day == -1) - return FALSE; - - /* We only want to start an edit with a return key or a simple - character. */ - if (event->keyval == GDK_Return) { - initial_text = NULL; - } else if (((event->keyval >= 0x20) && (event->keyval <= 0xFF) - && (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))) - || (event->length == 0) - || (event->keyval == GDK_Tab)) { - return FALSE; - } else - initial_text = e_utf8_from_gtk_event_key (widget, event->keyval, event->string); - - /* Add a new event covering the selected range. */ - comp = cal_comp_event_new_with_defaults (week_view->client); - - dtstart = week_view->day_starts[week_view->selection_start_day]; - dtend = week_view->day_starts[week_view->selection_end_day + 1]; - - date.value = &itt; - date.tzid = NULL; - - /* We use DATE values now, so we don't need the timezone. */ - /*date.tzid = icaltimezone_get_tzid (week_view->zone);*/ - - *date.value = icaltime_from_timet_with_zone (dtstart, TRUE, - week_view->zone); - cal_component_set_dtstart (comp, &date); - - *date.value = icaltime_from_timet_with_zone (dtend, TRUE, - week_view->zone); - cal_component_set_dtend (comp, &date); - - cal_component_set_categories (comp, week_view->default_category); - - /* We add the event locally and start editing it. We don't send it - to the server until the user finishes editing it. */ - e_week_view_add_event (comp, dtstart, dtend, week_view); - e_week_view_check_layout (week_view); - gtk_widget_queue_draw (week_view->main_canvas); - - cal_component_get_uid (comp, &uid); - if (e_week_view_find_event_from_uid (week_view, uid, &event_num)) { - e_week_view_start_editing_event (week_view, event_num, 0, - initial_text); - } else { - g_warning ("Couldn't find event to start editing.\n"); - } - - if (initial_text) - g_free (initial_text); - - g_object_unref (comp); - - return TRUE; -} - -enum { - /* - * This is used to "flag" events that can not be editted - */ - MASK_EDITABLE = 1, - - /* - * To disable recurring actions to be displayed - */ - MASK_RECURRING = 2, - - /* - * To disable actions for non-recurring items to be displayed - */ - MASK_SINGLE = 4, - - /* - * This is used to when an event is currently being edited - * in another window and we want to disable the event - * from being edited twice - */ - MASK_EDITING = 8, - - /* - * This is used to when an event is already a meeting and - * we want to disable the schedule meeting command - */ - MASK_MEETING = 16, - - /* - * To disable cut and copy for meetings the user is not the - * organizer of - */ - MASK_MEETING_ORGANIZER = 32, - - /* - * To disable things not valid for instances - */ - MASK_INSTANCE = 64 -}; - -static EPopupMenu main_items [] = { - E_POPUP_ITEM (N_("New _Appointment..."), GTK_SIGNAL_FUNC (e_week_view_on_new_appointment), MASK_EDITABLE), - E_POPUP_ITEM (N_("New All Day _Event"), GTK_SIGNAL_FUNC (e_week_view_on_new_event), MASK_EDITABLE), - E_POPUP_ITEM (N_("New Meeting"), GTK_SIGNAL_FUNC (e_week_view_on_new_meeting), MASK_EDITABLE), - E_POPUP_ITEM (N_("New Task"), GTK_SIGNAL_FUNC (e_week_view_on_new_task), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Print..."), GTK_SIGNAL_FUNC (e_week_view_on_print), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Paste"), GTK_SIGNAL_FUNC (e_week_view_on_paste), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_SUBMENU (N_("Current View"), NULL, 0), - - E_POPUP_ITEM (N_("Go to _Today"), GTK_SIGNAL_FUNC (e_week_view_on_goto_today), 0), - E_POPUP_ITEM (N_("_Go to Date..."), GTK_SIGNAL_FUNC (e_week_view_on_goto_date), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Publish Free/Busy Information"), GTK_SIGNAL_FUNC (e_week_view_on_publish), 0), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Settings..."), GTK_SIGNAL_FUNC (e_week_view_on_settings), 0), - - E_POPUP_TERMINATOR -}; - -static EPopupMenu child_items [] = { - E_POPUP_ITEM (N_("_Open"), GTK_SIGNAL_FUNC (e_week_view_on_edit_appointment), MASK_EDITING), - E_POPUP_ITEM (N_("_Save As..."), GTK_SIGNAL_FUNC (e_week_view_on_save_as), MASK_EDITING), - E_POPUP_ITEM (N_("_Print..."), GTK_SIGNAL_FUNC (e_week_view_on_print_event), MASK_EDITING), - - /* Only show this separator if one of the above is shown. */ - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("C_ut"), GTK_SIGNAL_FUNC (e_week_view_on_cut), MASK_EDITING | MASK_EDITABLE | MASK_MEETING_ORGANIZER), - E_POPUP_ITEM (N_("_Copy"), GTK_SIGNAL_FUNC (e_week_view_on_copy), MASK_EDITING | MASK_MEETING_ORGANIZER), - E_POPUP_ITEM (N_("_Paste"), GTK_SIGNAL_FUNC (e_week_view_on_paste), MASK_EDITABLE), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Schedule Meeting..."), GTK_SIGNAL_FUNC (e_week_view_on_meeting), MASK_EDITABLE | MASK_EDITING | MASK_MEETING), - E_POPUP_ITEM (N_("_Forward as iCalendar..."), GTK_SIGNAL_FUNC (e_week_view_on_forward), MASK_EDITING), - - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("_Delete"), GTK_SIGNAL_FUNC (e_week_view_on_delete_appointment), MASK_EDITABLE | MASK_SINGLE | MASK_EDITING), - E_POPUP_ITEM (N_("Make this Occurrence _Movable"), GTK_SIGNAL_FUNC (e_week_view_on_unrecur_appointment), MASK_RECURRING | MASK_EDITING | MASK_EDITABLE | MASK_INSTANCE), - E_POPUP_ITEM (N_("Delete this _Occurrence"), GTK_SIGNAL_FUNC (e_week_view_on_delete_occurrence), MASK_RECURRING | MASK_EDITING | MASK_EDITABLE), - E_POPUP_ITEM (N_("Delete _All Occurrences"), GTK_SIGNAL_FUNC (e_week_view_on_delete_appointment), MASK_RECURRING | MASK_EDITING | MASK_EDITABLE), - - E_POPUP_TERMINATOR -}; - -static void -free_view_popup (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - if (week_view->view_menu == NULL) - return; - - gnome_calendar_discard_view_popup (week_view->calendar, week_view->view_menu); - week_view->view_menu = NULL; -} - -void -e_week_view_show_popup_menu (EWeekView *week_view, - GdkEventButton *bevent, - gint event_num) -{ - EWeekViewEvent *event; - int have_selection; - gboolean being_edited; - guint32 disable_mask = 0, hide_mask = 0; - EPopupMenu *context_menu; - GtkMenu *popup; - - have_selection = GTK_WIDGET_HAS_FOCUS (week_view) - && week_view->selection_start_day != -1; - - /* - * This used to be set only if the event wasn't being edited - * in the event editor, but we can't check that at present. - * We could possibly set up another method of checking it. - */ - being_edited = FALSE; - - if (event_num == -1) { - week_view->view_menu = gnome_calendar_setup_view_popup (week_view->calendar); - main_items[9].submenu = week_view->view_menu; - context_menu = main_items; - } else { - context_menu = child_items; - event = &g_array_index (week_view->events, - EWeekViewEvent, event_num); - - if (cal_component_has_recurrences (event->comp)) - hide_mask |= MASK_SINGLE; - else - hide_mask |= MASK_RECURRING; - - if (cal_component_is_instance (event->comp)) - hide_mask |= MASK_INSTANCE; - - if (cal_component_has_organizer (event->comp)) { - disable_mask |= MASK_MEETING; - - if (!itip_organizer_is_user (event->comp, week_view->client)) - disable_mask |= MASK_MEETING_ORGANIZER; - } - } - - if (cal_client_is_read_only (week_view->client)) - disable_mask |= MASK_EDITABLE; - - if (being_edited) - disable_mask |= MASK_EDITING; - week_view->popup_event_num = event_num; - - popup = e_popup_menu_create (context_menu, disable_mask, hide_mask, week_view); - g_signal_connect (popup, "selection-done", G_CALLBACK (free_view_popup), week_view); - e_popup_menu (popup, (GdkEvent *) bevent); -} - - -static void -e_week_view_on_new_appointment (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - e_week_view_new_appointment (week_view, FALSE); -} - - -static void -e_week_view_on_new_event (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - time_t dtstart, dtend; - - dtstart = week_view->day_starts[week_view->selection_start_day]; - dtend = week_view->day_starts[week_view->selection_end_day + 1]; - gnome_calendar_new_appointment_for ( - week_view->calendar, dtstart, dtend, TRUE, FALSE); -} - -static void -e_week_view_on_new_meeting (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - e_week_view_new_appointment (week_view, TRUE); -} - -static void -e_week_view_on_new_task (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - gnome_calendar_new_task (week_view->calendar); -} - -static void -e_week_view_on_goto_date (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - goto_dialog (week_view->calendar); -} - -static void -e_week_view_on_goto_today (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - calendar_goto_today (week_view->calendar); -} - -static void -e_week_view_on_edit_appointment (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - if (week_view->calendar) - gnome_calendar_edit_object (week_view->calendar, event->comp, - FALSE); - else - g_warning ("Calendar not set"); -} - -static void -e_week_view_on_print (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - time_t start; - GnomeCalendarViewType view_type; - PrintView print_view; - - week_view = E_WEEK_VIEW (data); - - gnome_calendar_get_current_time_range (week_view->calendar, &start, NULL); - view_type = gnome_calendar_get_view (week_view->calendar); - - switch (view_type) { - case GNOME_CAL_WEEK_VIEW: - print_view = PRINT_VIEW_WEEK; - break; - - case GNOME_CAL_MONTH_VIEW: - print_view = PRINT_VIEW_MONTH; - break; - - default: - g_assert_not_reached (); - return; - } - - print_calendar (week_view->calendar, FALSE, start, print_view); -} - -static void -e_week_view_on_save_as (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - char *filename; - char *ical_string; - FILE *file; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - filename = e_file_dialog_save (_("Save as...")); - if (filename == NULL) - return; - - ical_string = cal_client_get_component_as_string (week_view->client, event->comp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - file = fopen (filename, "w"); - if (file == NULL) { - g_warning ("Couldn't save item"); - return; - } - - fprintf (file, ical_string); - g_free (ical_string); - fclose (file); -} - -static void -e_week_view_on_print_event (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - print_comp (event->comp, week_view->client, FALSE); -} - -static void -e_week_view_on_meeting (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - if (week_view->calendar) - gnome_calendar_edit_object (week_view->calendar, event->comp, TRUE); - else - g_warning ("Calendar not set"); -} - -static void -e_week_view_on_forward (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, event->comp, - week_view->client, NULL); -} - -static void -e_week_view_on_publish (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - icaltimezone *utc; - time_t start = time (NULL), end; - GList *comp_list; - - week_view = E_WEEK_VIEW (data); - - utc = icaltimezone_get_utc_timezone (); - start = time_day_begin_with_zone (start, utc); - end = time_add_week_with_zone (start, 6, utc); - - comp_list = cal_client_get_free_busy (week_view->client, NULL, start, end); - if (comp_list) { - GList *l; - - for (l = comp_list; l; l = l->next) { - CalComponent *comp = CAL_COMPONENT (l->data); - itip_send_comp (CAL_COMPONENT_METHOD_PUBLISH, comp, - week_view->client, NULL); - - g_object_unref (comp); - } - - g_list_free (comp_list); - } -} - -static void -e_week_view_on_settings (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - control_util_show_settings (week_view->calendar); -} - -static void -e_week_view_delete_event_internal (EWeekView *week_view, gint event_num) -{ - CalComponentVType vtype; - EWeekViewEvent *event; - - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - vtype = cal_component_get_vtype (event->comp); - - if (delete_component_dialog (event->comp, FALSE, 1, vtype, - GTK_WIDGET (week_view))) { - const char *uid; - - if (itip_organizer_is_user (event->comp, week_view->client) - && cancel_component_dialog (week_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, week_view->client, NULL); - - cal_component_get_uid (event->comp, &uid); - - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); - } -} - - -static void -e_week_view_on_delete_appointment (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - e_week_view_delete_event_internal (week_view, - week_view->popup_event_num); -} - - -void -e_week_view_delete_event (EWeekView *week_view) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->editing_event_num == -1) - return; - - e_week_view_delete_event_internal (week_view, - week_view->editing_event_num); -} - - -static void -e_week_view_delete_occurrence_internal (EWeekView *week_view, gint event_num) -{ - EWeekViewEvent *event; - CalComponent *comp; - - event = &g_array_index (week_view->events, EWeekViewEvent, - event_num); - - if (cal_component_is_instance (event->comp)) { - const char *uid; - - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object_with_mod (week_view->client, uid, CALOBJ_MOD_THIS), - CAL_COMPONENT_EVENT); - return; - } - - /* We must duplicate the CalComponent, or we won't know it has changed - when we get the "update_event" callback. */ - - comp = cal_component_clone (event->comp); - cal_comp_util_add_exdate (comp, event->start, week_view->zone); - - if (cal_client_update_object (week_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_week_view_on_delete_occurrence(): Could not update the object!"); - - g_object_unref (comp); -} - -static void -e_week_view_on_delete_occurrence (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - e_week_view_delete_occurrence_internal (week_view, week_view->popup_event_num); -} - -void -e_week_view_delete_occurrence (EWeekView *week_view) -{ - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (week_view->editing_event_num == -1) - return; - - e_week_view_delete_occurrence_internal (week_view, week_view->editing_event_num); -} - -static void -e_week_view_on_cut (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - const char *uid; - - week_view = E_WEEK_VIEW (data); - - e_week_view_on_copy (widget, data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - if (itip_organizer_is_user (event->comp, week_view->client) - && cancel_component_dialog (week_view->client, event->comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_CANCEL, event->comp, week_view->client, NULL); - - cal_component_get_uid (event->comp, &uid); - delete_error_dialog (cal_client_remove_object (week_view->client, uid), CAL_COMPONENT_EVENT); -} - -static void -e_week_view_on_copy (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - char *comp_str; - icalcomponent *vcal_comp; - icalcomponent *new_icalcomp; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - /* create top-level VCALENDAR component and add VTIMEZONE's */ - vcal_comp = cal_util_new_top_level (); - cal_util_add_timezones_from_component (vcal_comp, event->comp); - - new_icalcomp = icalcomponent_new_clone (cal_component_get_icalcomponent (event->comp)); - icalcomponent_add_component (vcal_comp, new_icalcomp); - - comp_str = icalcomponent_as_ical_string (vcal_comp); - if (week_view->clipboard_selection) - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = g_strdup (comp_str); - - gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME); - - /* free memory */ - icalcomponent_free (vcal_comp); -} - -static void -e_week_view_on_paste (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - gtk_selection_convert (week_view->invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - GDK_CURRENT_TIME); -} - -static void -e_week_view_on_unrecur_appointment (GtkWidget *widget, gpointer data) -{ - EWeekView *week_view; - EWeekViewEvent *event; - CalComponent *comp, *new_comp; - CalComponentDateTime date; - struct icaltimetype itt; - - week_view = E_WEEK_VIEW (data); - - if (week_view->popup_event_num == -1) - return; - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->popup_event_num); - - /* For the recurring object, we add a exception to get rid of the - instance. */ - comp = cal_component_clone (event->comp); - cal_comp_util_add_exdate (comp, event->start, week_view->zone); - - /* For the unrecurred instance we duplicate the original object, - create a new uid for it, get rid of the recurrence rules, and set - the start & end times to the instances times. */ - new_comp = cal_component_clone (event->comp); - cal_component_set_uid (new_comp, cal_component_gen_uid ()); - cal_component_set_rdate_list (new_comp, NULL); - cal_component_set_rrule_list (new_comp, NULL); - cal_component_set_exdate_list (new_comp, NULL); - cal_component_set_exrule_list (new_comp, NULL); - - date.value = &itt; - date.tzid = icaltimezone_get_tzid (week_view->zone); - - *date.value = icaltime_from_timet_with_zone (event->start, FALSE, - week_view->zone); - cal_component_set_dtstart (new_comp, &date); - *date.value = icaltime_from_timet_with_zone (event->end, FALSE, - week_view->zone); - cal_component_set_dtend (new_comp, &date); - - /* Now update both CalComponents. Note that we do this last since at - present the updates happen synchronously so our event may disappear. - */ - if (cal_client_update_object (week_view->client, comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_week_view_on_unrecur_appointment(): Could not update the object!"); - - g_object_unref (comp); - - if (cal_client_update_object (week_view->client, new_comp) != CAL_CLIENT_RESULT_SUCCESS) - g_message ("e_week_view_on_unrecur_appointment(): Could not update the object!"); - - g_object_unref (new_comp); -} - - -static gboolean -e_week_view_on_jump_button_event (GnomeCanvasItem *item, - GdkEvent *event, - EWeekView *week_view) -{ - gint day; - - if (event->type == GDK_BUTTON_PRESS) { - for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) { - if (item == week_view->jump_buttons[day]) { - if (week_view->calendar) - gnome_calendar_dayjump - (week_view->calendar, - week_view->day_starts[day]); - else - g_warning ("Calendar not set"); - return TRUE; - } - } - - } - - return FALSE; -} - - -/* Converts an hour from 0-23 to the preferred time format, and returns the - suffix to add and the width of it in the normal font. */ -void -e_week_view_convert_time_to_display (EWeekView *week_view, - gint hour, - gint *display_hour, - gchar **suffix, - gint *suffix_width) -{ - /* Calculate the actual hour number to display. For 12-hour - format we convert 0-23 to 12-11am/12-11pm. */ - *display_hour = hour; - if (week_view->use_24_hour_format) { - *suffix = ""; - *suffix_width = 0; - } else { - if (hour < 12) { - *suffix = week_view->am_string; - *suffix_width = week_view->am_string_width; - } else { - *display_hour -= 12; - *suffix = week_view->pm_string; - *suffix_width = week_view->pm_string_width; - } - - /* 12-hour uses 12:00 rather than 0:00. */ - if (*display_hour == 0) - *display_hour = 12; - } -} - - -gint -e_week_view_get_time_string_width (EWeekView *week_view) -{ - gint time_width; - - if (week_view->use_small_font && week_view->small_font_desc) - time_width = week_view->digit_width * 2 - + week_view->small_digit_width * 2; - else - time_width = week_view->digit_width * 4 - + week_view->colon_width; - - if (!week_view->use_24_hour_format) - time_width += MAX (week_view->am_string_width, - week_view->pm_string_width); - - return time_width; -} - -static void -invisible_destroyed (GtkWidget *invisible, EWeekView *week_view) -{ - gtk_object_unref (GTK_OBJECT (week_view->invisible)); - week_view->invisible = NULL; -} - -static void -selection_get (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EWeekView *week_view) -{ - if (week_view->clipboard_selection != NULL) { - gtk_selection_data_set (selection_data, - GDK_SELECTION_TYPE_STRING, - 8, - week_view->clipboard_selection, - strlen (week_view->clipboard_selection)); - } -} - -static void -selection_clear_event (GtkWidget *invisible, - GdkEventSelection *event, - EWeekView *week_view) -{ - if (week_view->clipboard_selection != NULL) { - g_free (week_view->clipboard_selection); - week_view->clipboard_selection = NULL; - } -} - -static void -selection_received (GtkWidget *invisible, - GtkSelectionData *selection_data, - guint time, - EWeekView *week_view) -{ - char *comp_str; - icalcomponent *icalcomp; - icalcomponent_kind kind; - CalComponent *comp; - time_t selected_time; - struct icaltimetype itime; - struct icaltimetype tmp_itime; - time_t tt_start, tt_end; - struct icaldurationtype ic_dur; - char *uid; - CalComponentDateTime ccdt; - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (selection_data->length < 0 || - selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } - - comp_str = (char *) selection_data->data; - icalcomp = icalparser_parse_string ((const char *) comp_str); - if (!icalcomp) - return; - - /* check the type of the component */ - kind = icalcomponent_isa (icalcomp); - if (kind != ICAL_VCALENDAR_COMPONENT && - kind != ICAL_VEVENT_COMPONENT && - kind != ICAL_VTODO_COMPONENT && - kind != ICAL_VJOURNAL_COMPONENT) { - return; - } - - e_week_view_set_status_message (week_view, _("Updating objects")); - selected_time = week_view->day_starts[week_view->selection_start_day]; - - if (kind == ICAL_VCALENDAR_COMPONENT) { - icalcomponent_kind child_kind; - icalcomponent *subcomp; - - subcomp = icalcomponent_get_first_component ( - icalcomp, ICAL_ANY_COMPONENT); - while (subcomp) { - child_kind = icalcomponent_isa (subcomp); - if (child_kind == ICAL_VEVENT_COMPONENT || - child_kind == ICAL_VTODO_COMPONENT || - child_kind == ICAL_VJOURNAL_COMPONENT) { - icalcomponent *new_icalcomp; - - new_icalcomp = icalcomponent_new_clone (subcomp); - comp = cal_component_new (); - - /* change the day for the event */ - tt_start = icaltime_as_timet ( - icalcomponent_get_dtstart (new_icalcomp)); - tt_end = icaltime_as_timet ( - icalcomponent_get_dtend (new_icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - - tmp_itime = icaltime_from_timet_with_zone ( - selected_time, FALSE, week_view->zone); - itime = icalcomponent_get_dtstart (new_icalcomp); - itime.year = tmp_itime.year; - itime.month = tmp_itime.month; - itime.day = tmp_itime.day; - - cal_component_set_icalcomponent (comp, new_icalcomp); - ccdt.value = &itime; - ccdt.tzid = icaltimezone_get_tzid (week_view->zone); - cal_component_set_dtstart (comp, &ccdt); - - itime = icaltime_add (itime, ic_dur); - ccdt.value = &itime; - cal_component_set_dtend (comp, &ccdt); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, uid); - - cal_client_update_object (week_view->client, comp); - - g_free (uid); - g_object_unref (comp); - } - subcomp = icalcomponent_get_next_component ( - icalcomp, ICAL_ANY_COMPONENT); - } - - icalcomponent_free (icalcomp); - - } - else { - comp = cal_component_new (); - - /* change the day for the event */ - tt_start = icaltime_as_timet (icalcomponent_get_dtstart (icalcomp)); - tt_end = icaltime_as_timet (icalcomponent_get_dtend (icalcomp)); - ic_dur = icaldurationtype_from_int (tt_end - tt_start); - - tmp_itime = icaltime_from_timet_with_zone ( - selected_time, FALSE, week_view->zone); - itime = icalcomponent_get_dtstart (icalcomp); - itime.year = tmp_itime.year; - itime.month = tmp_itime.month; - itime.day = tmp_itime.day; - - cal_component_set_icalcomponent (comp, icalcomp); - ccdt.value = &itime; - ccdt.tzid = icaltimezone_get_tzid (week_view->zone); - cal_component_set_dtstart (comp, &ccdt); - - itime = icaltime_add (itime, ic_dur); - ccdt.value = &itime; - cal_component_set_dtend (comp, &ccdt); - - uid = cal_component_gen_uid (); - cal_component_set_uid (comp, (const char *) uid); - - cal_client_update_object (week_view->client, comp); - - if (itip_organizer_is_user (comp, week_view->client) && send_component_dialog (week_view->client, comp, TRUE)) - itip_send_comp (CAL_COMPONENT_METHOD_REQUEST, comp, week_view->client, NULL); - - g_free (uid); - g_object_unref (comp); - } - - e_week_view_set_status_message (week_view, NULL); -} - - -/* Gets the visible time range. Returns FALSE if no time range has been set. */ -gboolean -e_week_view_get_visible_time_range (EWeekView *week_view, - time_t *start_time, - time_t *end_time) -{ - gint num_days; - - /* If we don't have a valid date set yet, return FALSE. */ - if (!g_date_valid (&week_view->first_day_shown)) - return FALSE; - - num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7; - *start_time = week_view->day_starts[0]; - *end_time = week_view->day_starts[num_days]; - - return TRUE; -} - - -/* Queues a layout, unless one is already queued. */ -static void -e_week_view_queue_layout (EWeekView *week_view) -{ - if (week_view->layout_timeout_id == 0) { - week_view->layout_timeout_id = g_timeout_add (E_WEEK_VIEW_LAYOUT_TIMEOUT, e_week_view_layout_timeout_cb, week_view); - } -} - - -/* Removes any queued layout. */ -static void -e_week_view_cancel_layout (EWeekView *week_view) -{ - if (week_view->layout_timeout_id != 0) { - gtk_timeout_remove (week_view->layout_timeout_id); - week_view->layout_timeout_id = 0; - } -} - - -static gboolean -e_week_view_layout_timeout_cb (gpointer data) -{ - EWeekView *week_view = E_WEEK_VIEW (data); - - gtk_widget_queue_draw (week_view->main_canvas); - e_week_view_check_layout (week_view); - - week_view->layout_timeout_id = 0; - return FALSE; -} - - -/* Returns the number of selected events (0 or 1 at present). */ -gint -e_week_view_get_num_events_selected (EWeekView *week_view) -{ - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 0); - - return (week_view->editing_event_num != -1) ? 1 : 0; -} - -/* Returns the currently-selected event, or NULL if none */ -CalComponent * -e_week_view_get_selected_event (EWeekView *week_view) -{ - EWeekViewEvent *event; - - g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL); - g_return_val_if_fail (week_view->editing_event_num != -1, NULL); - - event = &g_array_index (week_view->events, EWeekViewEvent, - week_view->editing_event_num); - - return event ? event->comp : NULL; -} - -/* Displays a message on the activity client. */ -void -e_week_view_set_status_message (EWeekView *week_view, const char *message) -{ - extern EvolutionShellClient *global_shell_client; /* ugly */ - - g_return_if_fail (E_IS_WEEK_VIEW (week_view)); - - if (!message || !*message) { - if (week_view->activity) { - g_object_unref (week_view->activity); - week_view->activity = NULL; - } - } - else if (!week_view->activity) { - int display; - char *client_id = g_strdup_printf ("%p", week_view); - - if (progress_icon[0] == NULL) - progress_icon[0] = gdk_pixbuf_new_from_file (EVOLUTION_IMAGESDIR "/" EVOLUTION_CALENDAR_PROGRESS_IMAGE, NULL); - week_view->activity = evolution_activity_client_new ( - global_shell_client, client_id, - progress_icon, message, TRUE, &display); - - g_free (client_id); - } - else - evolution_activity_client_update (week_view->activity, message, -1.0); -} diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h deleted file mode 100644 index fc481bdc4a..0000000000 --- a/calendar/gui/e-week-view.h +++ /dev/null @@ -1,519 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@ximian.com> - * - * Copyright 1999, Ximian, Inc. - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_WEEK_VIEW_H_ -#define _E_WEEK_VIEW_H_ - -#include <gtk/gtktable.h> -#include <libgnomecanvas/gnome-canvas.h> -#include <gal/widgets/e-popup-menu.h> - -#include "gnome-cal.h" -#include "evolution-activity-client.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EWeekView - displays the Week & Month views of the calendar. - */ - -/* The maximum number of weeks we show. 5 is usually enough for 1 month, - but we allow 6 for longer selections. */ -#define E_WEEK_VIEW_MAX_WEEKS 6 - -/* The size of the reminder & recurrence icons, and padding around them. - X_PAD is the padding between icons. R_PAD is the padding on the right of - the last icon, before the event text. */ -#define E_WEEK_VIEW_ICON_WIDTH 16 -#define E_WEEK_VIEW_ICON_HEIGHT 16 -#define E_WEEK_VIEW_ICON_X_PAD 1 -#define E_WEEK_VIEW_ICON_Y_PAD 1 -#define E_WEEK_VIEW_ICON_R_PAD 1 - -/* The space on the left & right outside of the event. (The triangle to - indicate the event continues is displayed in this space). */ -#define E_WEEK_VIEW_EVENT_L_PAD 2 -#define E_WEEK_VIEW_EVENT_R_PAD 2 - -/* The vertical spacing between rows of events. */ -#define E_WEEK_VIEW_EVENT_Y_SPACING 1 - -/* The size of the border around long events. */ -#define E_WEEK_VIEW_EVENT_BORDER_WIDTH 1 -#define E_WEEK_VIEW_EVENT_BORDER_HEIGHT 1 - -/* The padding on the top and bottom of the event text. */ -#define E_WEEK_VIEW_EVENT_TEXT_Y_PAD 1 - -/* The space between the start and end times. */ -#define E_WEEK_VIEW_EVENT_TIME_SPACING 2 - -/* The space between the time and the event text or icons. */ -#define E_WEEK_VIEW_EVENT_TIME_X_PAD 2 - -/* The space between the borders of long events and any text of icons. */ -#define E_WEEK_VIEW_EVENT_EDGE_X_PAD 2 - -/* The padding above and on the right of the date string at the top of each - cell. */ -#define E_WEEK_VIEW_DATE_T_PAD 2 -#define E_WEEK_VIEW_DATE_R_PAD 4 - -/* The padding above and below the line under the date string, in the Week - view, and also the space on the left of it. */ -#define E_WEEK_VIEW_DATE_LINE_T_PAD 1 -#define E_WEEK_VIEW_DATE_LINE_B_PAD 1 -#define E_WEEK_VIEW_DATE_LINE_L_PAD 10 - -/* The padding below the date string in the Month view. */ -#define E_WEEK_VIEW_DATE_B_PAD 1 - -/* We use a 7-bit field to store row numbers in EWeekViewEventSpan, so the - maximum number or rows we can allow is 127. It is very unlikely to be - reached anyway. */ -#define E_WEEK_VIEW_MAX_ROWS_PER_CELL 127 - -/* These index our colors array. */ -typedef enum -{ - E_WEEK_VIEW_COLOR_EVEN_MONTHS, - E_WEEK_VIEW_COLOR_ODD_MONTHS, - E_WEEK_VIEW_COLOR_EVENT_BACKGROUND, - E_WEEK_VIEW_COLOR_EVENT_BORDER, - E_WEEK_VIEW_COLOR_EVENT_TEXT, - E_WEEK_VIEW_COLOR_GRID, - E_WEEK_VIEW_COLOR_SELECTED, - E_WEEK_VIEW_COLOR_SELECTED_UNFOCUSSED, - E_WEEK_VIEW_COLOR_DATES, - E_WEEK_VIEW_COLOR_DATES_SELECTED, - E_WEEK_VIEW_COLOR_TODAY, - - E_WEEK_VIEW_COLOR_LAST -} EWeekViewColors; - -/* These specify which part of the selection we are dragging, if any. */ -typedef enum -{ - E_WEEK_VIEW_DRAG_NONE, - E_WEEK_VIEW_DRAG_START, - E_WEEK_VIEW_DRAG_END -} EWeekViewDragPosition; - -/* These specify which times are shown for the 1-day events. We use the small - font for the minutes if it can be loaded and the option is on. */ -typedef enum -{ - E_WEEK_VIEW_TIME_NONE, - E_WEEK_VIEW_TIME_START, - E_WEEK_VIEW_TIME_BOTH, - E_WEEK_VIEW_TIME_START_SMALL_MIN, - E_WEEK_VIEW_TIME_BOTH_SMALL_MIN -} EWeekViewTimeFormat; - -/* Specifies the position of the mouse. */ -typedef enum -{ - E_WEEK_VIEW_POS_OUTSIDE, - E_WEEK_VIEW_POS_NONE, - E_WEEK_VIEW_POS_EVENT, - E_WEEK_VIEW_POS_LEFT_EDGE, - E_WEEK_VIEW_POS_RIGHT_EDGE -} EWeekViewPosition; - - -typedef struct _EWeekViewEventSpan EWeekViewEventSpan; -struct _EWeekViewEventSpan { - guint start_day : 6; - guint num_days : 3; - guint row : 7; - GnomeCanvasItem *background_item; - GnomeCanvasItem *text_item; -}; - -typedef struct _EWeekViewEvent EWeekViewEvent; -struct _EWeekViewEvent { - CalComponent *comp; - time_t start; - time_t end; - guint16 start_minute; /* Minutes from the start of the day. */ - guint16 end_minute; - gint spans_index; - guint8 num_spans; - - /* TRUE if the event is at a different UTC offset than our current - timezone, i.e. it is in a different timezone. */ - guint different_timezone : 1; -}; - - -#define E_WEEK_VIEW(obj) GTK_CHECK_CAST (obj, e_week_view_get_type (), EWeekView) -#define E_WEEK_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_week_view_get_type (), EWeekViewClass) -#define E_IS_WEEK_VIEW(obj) GTK_CHECK_TYPE (obj, e_week_view_get_type ()) - - -typedef struct _EWeekView EWeekView; -typedef struct _EWeekViewClass EWeekViewClass; - -struct _EWeekView -{ - GtkTable table; - - /* The top canvas where the dates are shown. */ - GtkWidget *titles_canvas; - GnomeCanvasItem *titles_canvas_item; - - /* The main canvas where the appointments are shown. */ - GtkWidget *main_canvas; - GnomeCanvasItem *main_canvas_item; - - GnomeCanvasItem *jump_buttons[E_WEEK_VIEW_MAX_WEEKS * 7]; - - GtkWidget *vscrollbar; - - /* The calendar we are associated with. */ - GnomeCalendar *calendar; - - /* Calendar client object we are monitoring */ - CalClient *client; - - /* S-expression for query and the query object */ - char *sexp; - CalQuery *query; - - /* The array of EWeekViewEvent elements. */ - GArray *events; - gboolean events_sorted; - gboolean events_need_layout; - gboolean events_need_reshape; - - /* The ID of the timeout function for doing a new layout. */ - gint layout_timeout_id; - - /* An array of EWeekViewEventSpan elements. Each event has its own - space within this array, and uses the spans_index and num_spans - fields of the EWeekViewEvent struct to access it. */ - GArray *spans; - - /* The start of each day displayed. */ - time_t day_starts[E_WEEK_VIEW_MAX_WEEKS * 7 + 1]; - - /* The timezone. */ - icaltimezone *zone; - - /* The base date, where the adjustment value is 0. */ - GDate base_date; - - /* The first day shown in the view. */ - GDate first_day_shown; - - /* If we are displaying multiple weeks in rows. If this is FALSE only - one week is shown, with a different layout. */ - gboolean multi_week_view; - - /* How many weeks we are showing. This is only relevant if - display_month is TRUE. */ - gint weeks_shown; - - /* If Sat & Sun are compressed. Only applicable in month view, since - they are always compressed into 1 cell in the week view. */ - gboolean compress_weekend; - - /* Whether we use show event end times. */ - gboolean show_event_end_times; - - /* The first day of the week, 0 (Monday) to 6 (Sunday). */ - gint week_start_day; - - /* Whether we use 12-hour of 24-hour format. */ - gboolean use_24_hour_format; - - /* The first day of the week we display, 0 (Monday) to 6 (Sunday). - This will usually be week_start_day, but if the weekend is - compressed, and week_start_day is Sunday we have to use Saturday. */ - gint display_start_day; - - /* The vertical offset of the events from the top of the cells. */ - gint events_y_offset; - - /* The height of the events, not including spacing between them. */ - gint row_height; - - /* The number of rows of events in each cell. */ - gint rows_per_cell; - gint rows_per_compressed_cell; - - /* The number of rows we have used for each day (i.e. each cell) */ - gint rows_per_day[E_WEEK_VIEW_MAX_WEEKS * 7]; - - /* If the small font is used for displaying the minutes. */ - gboolean use_small_font; - - /* Small font to display the minutes. */ - PangoFontDescription *small_font_desc; - - /* The widths of various pieces of text, used to determine which of - several date formats to display, set in e_week_view_style_set(). */ - gint space_width; /* One space character ' '. */ - gint colon_width; /* Size of ':' in the font. */ - gint slash_width; /* Size of '/' in the font. */ - gint digit_width; /* Size of a '0' digit. */ - gint small_digit_width; /* Size of a small_font '0' digit. */ - gint day_widths[7]; /* Monday first. */ - gint max_day_width; - gint abbr_day_widths[7]; - gint max_abbr_day_width; - gint month_widths[12]; - gint max_month_width; - gint abbr_month_widths[12]; - gint max_abbr_month_width; - - /* The size of the main grid of days and of the cells. A row - corresponds to a compressed day, so normal days usually take - up 2 rows. Note that the offsets arrays have one more element - than the widths/heights arrays since they also contain the - right/bottom edge. */ - gint rows; - gint columns; - gint col_widths[7]; - gint col_offsets[8]; - gint row_heights[E_WEEK_VIEW_MAX_WEEKS * 2]; - gint row_offsets[E_WEEK_VIEW_MAX_WEEKS * 2 + 1]; - - /* This specifies which times we are showing for the events, depending - on how much room is available. */ - EWeekViewTimeFormat time_format; - - /* The GC used for painting in different colors. */ - GdkGC *main_gc; - - /* The icons. */ - GdkPixmap *reminder_icon; - GdkBitmap *reminder_mask; - GdkPixmap *recurrence_icon; - GdkBitmap *recurrence_mask; - GdkPixmap *timezone_icon; - GdkBitmap *timezone_mask; - - /* Colors for drawing. */ - GdkColor colors[E_WEEK_VIEW_COLOR_LAST]; - - /* The normal & resizing cursors. */ - GdkCursor *normal_cursor; - GdkCursor *move_cursor; - GdkCursor *resize_width_cursor; - - /* This remembers the last cursor set on the window. */ - GdkCursor *last_cursor_set; - - /* The currently selected region, in days from the first day shown. - If selection_start_day is -1 there is no current selection. */ - gint selection_start_day; - gint selection_end_day; - - /* This specifies which end of the selection is being dragged, or is - E_WEEK_VIEW_DRAG_NONE if the selection isn't being dragged. */ - EWeekViewDragPosition selection_drag_pos; - - /* This is the event the mouse button was pressed on. If the button - is released we start editing it, but if the mouse is dragged we set - this to -1. */ - gint pressed_event_num; - gint pressed_span_num; - - /* The event span currently being edited. The num is -1 if no event is - being edited. */ - gint editing_event_num; - gint editing_span_num; - - /* The event that the context menu is for. */ - gint popup_event_num; - EPopupMenu *view_menu; - - /* The last mouse position when dragging, in the entire canvas. */ - gint drag_event_x; - gint drag_event_y; - - /* "am" and "pm" in the current locale, and their widths. */ - gchar *am_string; - gchar *pm_string; - gint am_string_width; - gint pm_string_width; - - /* the invisible widget to manage the clipboard selections */ - GtkWidget *invisible; - gchar *clipboard_selection; - - /* The default category for new events */ - char *default_category; - - /* The activity client used to show messages on the status bar. */ - EvolutionActivityClient *activity; -}; - -struct _EWeekViewClass -{ - GtkTableClass parent_class; - - /* Notification signals */ - void (* selection_changed) (EWeekView *week_view); -}; - - -GtkType e_week_view_get_type (void); -GtkWidget* e_week_view_new (void); - -void e_week_view_set_calendar (EWeekView *week_view, - GnomeCalendar *calendar); - -/* The first day shown. Note that it will be rounded down to the start of a - week when set. The returned value will be invalid if no date has been set - yet. */ -void e_week_view_get_first_day_shown (EWeekView *week_view, - GDate *date); -void e_week_view_set_first_day_shown (EWeekView *week_view, - GDate *date); - -void e_week_view_set_cal_client (EWeekView *week_view, - CalClient *client); - -void e_week_view_set_query (EWeekView *week_view, - const char *sexp); - -void e_week_view_set_default_category (EWeekView *week_view, - const char *category); - -/* The selected time range. The EWeekView will show the corresponding - month and the days between start_time and end_time will be selected. - To select a single day, use the same value for start_time & end_time. */ -void e_week_view_get_selected_time_range (EWeekView *week_view, - time_t *start_time, - time_t *end_time); -void e_week_view_set_selected_time_range (EWeekView *week_view, - time_t start_time, - time_t end_time); - -void e_week_view_set_selected_time_range_visible (EWeekView *week_view, - time_t start_time, - time_t end_time); - -/* Gets the visible time range. Returns FALSE if no time range has been set. */ -gboolean e_week_view_get_visible_time_range (EWeekView *week_view, - time_t *start_time, - time_t *end_time); - -/* Whether to display 1 week or 1 month (5 weeks). It defaults to 1 week. */ -gboolean e_week_view_get_multi_week_view (EWeekView *week_view); -void e_week_view_set_multi_week_view (EWeekView *week_view, - gboolean multi_week_view); - -/* The number of weeks shown in the multi-week view. */ -gint e_week_view_get_weeks_shown (EWeekView *week_view); -void e_week_view_set_weeks_shown (EWeekView *week_view, - gint weeks_shown); - -/* Whether the weekend (Sat/Sun) should be compressed into 1 cell in the Month - view. In the Week view they are always compressed. */ -gboolean e_week_view_get_compress_weekend (EWeekView *week_view); -void e_week_view_set_compress_weekend (EWeekView *week_view, - gboolean compress); - -/* Whether we display event end times. */ -gboolean e_week_view_get_show_event_end_times (EWeekView *week_view); -void e_week_view_set_show_event_end_times (EWeekView *week_view, - gboolean show); - -/* The first day of the week, 0 (Monday) to 6 (Sunday). */ -gint e_week_view_get_week_start_day (EWeekView *week_view); -void e_week_view_set_week_start_day (EWeekView *week_view, - gint week_start_day); - -/* Whether we use 12-hour or 24-hour format. */ -gboolean e_week_view_get_24_hour_format (EWeekView *week_view); -void e_week_view_set_24_hour_format (EWeekView *week_view, - gboolean use_24_hour); - -/* The current timezone. */ -icaltimezone* e_week_view_get_timezone (EWeekView *week_view); -void e_week_view_set_timezone (EWeekView *week_view, - icaltimezone *zone); - -/* Clipboard related functions */ -void e_week_view_cut_clipboard (EWeekView *week_view); -void e_week_view_copy_clipboard (EWeekView *week_view); -void e_week_view_paste_clipboard (EWeekView *week_view); - -void e_week_view_delete_event (EWeekView *week_view); -void e_week_view_delete_occurrence (EWeekView *week_view); - -/* Returns the number of selected events (0 or 1 at present). */ -gint e_week_view_get_num_events_selected (EWeekView *week_view); - -CalComponent *e_week_view_get_selected_event (EWeekView *week_view); - -/* - * Internal functions called by the associated canvas items. - */ -void e_week_view_get_day_position (EWeekView *week_view, - gint day, - gint *day_x, - gint *day_y, - gint *day_w, - gint *day_h); -gboolean e_week_view_get_span_position (EWeekView *week_view, - gint event_num, - gint span_num, - gint *span_x, - gint *span_y, - gint *span_w); -gboolean e_week_view_is_one_day_event (EWeekView *week_view, - gint event_num); -void e_week_view_start_editing_event (EWeekView *week_view, - gint event_num, - gint span_num, - gchar *initial_text); -void e_week_view_stop_editing_event (EWeekView *week_view); - -void e_week_view_show_popup_menu (EWeekView *week_view, - GdkEventButton *event, - gint event_num); - -void e_week_view_convert_time_to_display (EWeekView *week_view, - gint hour, - gint *display_hour, - gchar **suffix, - gint *suffix_width); -gint e_week_view_get_time_string_width (EWeekView *week_view); - -gint e_week_view_event_sort_func (const void *arg1, - const void *arg2); - -void e_week_view_set_status_message (EWeekView *week_view, - const char *message); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_WEEK_VIEW_H_ */ diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c deleted file mode 100644 index bd480381a8..0000000000 --- a/calendar/gui/gnome-cal.c +++ /dev/null @@ -1,2887 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution calendar - Main calendar view widget - * - * Copyright (C) 1998 The Free Software Foundation - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <unistd.h> -#include <signal.h> -#include <sys/wait.h> -#include <fcntl.h> -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <bonobo/bonobo-exception.h> -#include "e-util/e-url.h" -#include <cal-util/timeutil.h> -#include "widgets/menus/gal-view-menus.h" -#include "e-comp-editor-registry.h" -#include "dialogs/event-editor.h" -#include "dialogs/task-editor.h" -#include "comp-util.h" -#include "e-day-view.h" -#include "e-week-view.h" -#include "evolution-calendar.h" -#include "gnome-cal.h" -#include "calendar-component.h" -#include "cal-search-bar.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "calendar-view.h" -#include "calendar-view-factory.h" -#include "tag-calendar.h" -#include "misc.h" - -extern ECompEditorRegistry *comp_editor_registry; - - - -/* Private part of the GnomeCalendar structure */ -struct _GnomeCalendarPrivate { - /* - * The Calendar Folder. - */ - - /* The calendar client object we monitor */ - CalClient *client; - - /* Set of categories from the calendar client */ - GPtrArray *cal_categories; - - /* - * The TaskPad Folder. - */ - - /* The calendar client object we monitor */ - CalClient *task_pad_client; - - /* Set of categories from the tasks client */ - GPtrArray *tasks_categories; - - /* - * Fields for the calendar view - */ - - /* This is the last selection explicitly selected by the user. We try - to keep it the same when we switch views, but we may have to alter - it depending on the view (e.g. the week views only select days, so - any times are lost. */ - time_t selection_start_time; - time_t selection_end_time; - - /* Widgets */ - - GtkWidget *search_bar; - - GtkWidget *hpane; - GtkWidget *notebook; - GtkWidget *vpane; - ECalendar *date_navigator; - GtkWidget *todo; - - GtkWidget *day_view; - GtkWidget *work_week_view; - GtkWidget *week_view; - GtkWidget *month_view; - - /* Calendar query for the date navigator */ - CalQuery *dn_query; - char *sexp; - - /* This is the view currently shown. We use it to keep track of the - positions of the panes. range_selected is TRUE if a range of dates - was selected in the date navigator to show the view. */ - GnomeCalendarViewType current_view_type; - gboolean range_selected; - - /* These are the saved positions of the panes. They are multiples of - calendar month widths & heights in the date navigator, so that they - will work OK after theme changes. */ - gint hpane_pos; - gint vpane_pos; - gint hpane_pos_month_view; - gint vpane_pos_month_view; - - /* The signal handler id for our GtkCalendar "day_selected" handler. */ - guint day_selected_id; - - /* View instance and menus for the control */ - GalViewInstance *view_instance; - GalViewMenus *view_menus; - - /* Our current timezone. */ - icaltimezone *zone; - - /* The dates currently shown. If they are -1 then we have no dates - shown. We only use these to check if we need to emit a - 'dates-shown-changed' signal.*/ - time_t visible_start; - time_t visible_end; -}; - -/* Signal IDs */ - -enum { - DATES_SHOWN_CHANGED, - CALENDAR_SELECTION_CHANGED, - TASKPAD_SELECTION_CHANGED, - CALENDAR_FOCUS_CHANGE, - TASKPAD_FOCUS_CHANGE, - LAST_SIGNAL -}; - -/* Used to indicate who has the focus within the calendar view */ -typedef enum { - FOCUS_CALENDAR, - FOCUS_TASKPAD, - FOCUS_OTHER -} FocusLocation; - -static guint gnome_calendar_signals[LAST_SIGNAL]; - - - - -static void gnome_calendar_class_init (GnomeCalendarClass *class); -static void gnome_calendar_init (GnomeCalendar *gcal); -static void gnome_calendar_destroy (GtkObject *object); - -static void gnome_calendar_set_pane_positions (GnomeCalendar *gcal); -static void gnome_calendar_update_view_times (GnomeCalendar *gcal); -static void gnome_calendar_update_date_navigator (GnomeCalendar *gcal); - -static void gnome_calendar_hpane_realized (GtkWidget *w, GnomeCalendar *gcal); -static void gnome_calendar_vpane_realized (GtkWidget *w, GnomeCalendar *gcal); -static gboolean gnome_calendar_vpane_resized (GtkWidget *w, GdkEventButton *e, GnomeCalendar *gcal); -static gboolean gnome_calendar_hpane_resized (GtkWidget *w, GdkEventButton *e, GnomeCalendar *gcal); - -static void gnome_calendar_on_date_navigator_date_range_changed (ECalendarItem *calitem, - GnomeCalendar *gcal); -static void gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, - GnomeCalendar *gcal); -static void gnome_calendar_notify_dates_shown_changed (GnomeCalendar *gcal); - -static void add_alarms (const char *uri); -static void update_query (GnomeCalendar *gcal); - - -static GtkVBoxClass *parent_class; - - - - -E_MAKE_TYPE (gnome_calendar, "GnomeCalendar", GnomeCalendar, gnome_calendar_class_init, - gnome_calendar_init, GTK_TYPE_VBOX); - -/* Class initialization function for the gnome calendar */ -static void -gnome_calendar_class_init (GnomeCalendarClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - - parent_class = g_type_class_peek_parent (class); - - gnome_calendar_signals[DATES_SHOWN_CHANGED] = - gtk_signal_new ("dates_shown_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (GnomeCalendarClass, - dates_shown_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gnome_calendar_signals[CALENDAR_SELECTION_CHANGED] = - gtk_signal_new ("calendar_selection_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (GnomeCalendarClass, calendar_selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gnome_calendar_signals[TASKPAD_SELECTION_CHANGED] = - gtk_signal_new ("taskpad_selection_changed", - GTK_RUN_LAST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (GnomeCalendarClass, taskpad_selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gnome_calendar_signals[CALENDAR_FOCUS_CHANGE] = - gtk_signal_new ("calendar_focus_change", - GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (GnomeCalendarClass, calendar_focus_change), - gtk_marshal_NONE__BOOL, - GTK_TYPE_NONE, 1, - GTK_TYPE_BOOL); - - gnome_calendar_signals[TASKPAD_FOCUS_CHANGE] = - gtk_signal_new ("taskpad_focus_change", - GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (GnomeCalendarClass, taskpad_focus_change), - gtk_marshal_NONE__BOOL, - GTK_TYPE_NONE, 1, - GTK_TYPE_BOOL); - - object_class->destroy = gnome_calendar_destroy; - - class->dates_shown_changed = NULL; - class->calendar_selection_changed = NULL; - class->taskpad_selection_changed = NULL; - class->calendar_focus_change = NULL; - class->taskpad_focus_change = NULL; -} - -/* Callback used when the calendar query reports of an updated object */ -static void -dn_query_obj_updated_cb (CalQuery *query, const char *uid, - gboolean query_in_progress, int n_scanned, int total, - gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - CalComponent *comp; - CalClientGetStatus status; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - /* If this is an update that is not part of an ongoing query, we have to - * retag the whole thing: an event may change dates and the - * tag_calendar_by_comp() below would not know how to untag the old - * dates. - */ - if (!query_in_progress) { - update_query (gcal); - return; - } - - status = cal_client_get_object (priv->client, uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Everything is fine */ - break; - - case CAL_CLIENT_GET_SYNTAX_ERROR: - g_message ("dn_query_obj_updated_cb(): Syntax error while getting object `%s'", uid); - break; - - case CAL_CLIENT_GET_NOT_FOUND: - /* The object is no longer in the server, so do nothing */ - break; - - default: - g_assert_not_reached (); - return; - } - - tag_calendar_by_comp (priv->date_navigator, comp, priv->client, NULL, - FALSE, TRUE); - g_object_unref (comp); -} - -/* Callback used when the calendar query reports of a removed object */ -static void -dn_query_obj_removed_cb (CalQuery *query, const char *uid, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - /* Just retag the whole thing */ - update_query (gcal); -} - -/* Callback used when the calendar query is done */ -static void -dn_query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, - gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - /* FIXME */ - - if (status != CAL_QUERY_DONE_SUCCESS) - fprintf (stderr, "query done: %s\n", error_str); -} - -/* Callback used when the calendar query reports an evaluation error */ -static void -dn_query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - /* FIXME */ - - fprintf (stderr, "eval error: %s\n", error_str); -} - -/* Returns the current view widget, a EDayView or EWeekView. */ -GtkWidget* -gnome_calendar_get_current_view_widget (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GtkWidget *retval = NULL; - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - retval = priv->day_view; - break; - case GNOME_CAL_WORK_WEEK_VIEW: - retval = priv->work_week_view; - break; - case GNOME_CAL_WEEK_VIEW: - retval = priv->week_view; - break; - case GNOME_CAL_MONTH_VIEW: - retval = priv->month_view; - break; - default: - g_assert_not_reached (); - } - - return retval; -} - -/* Gets the focus location based on who is the focused widget within the - * calendar view. - */ -static FocusLocation -get_focus_location (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - ETable *etable; - - priv = gcal->priv; - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - - if (GTK_WIDGET_HAS_FOCUS (etable->table_canvas)) - return FOCUS_TASKPAD; - else { - GtkWidget *widget; - EDayView *dv; - EWeekView *wv; - - widget = gnome_calendar_get_current_view_widget (gcal); - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - case GNOME_CAL_WORK_WEEK_VIEW: - dv = E_DAY_VIEW (widget); - - if (GTK_WIDGET_HAS_FOCUS (dv->top_canvas) - || GTK_WIDGET_HAS_FOCUS (dv->main_canvas)) - return FOCUS_CALENDAR; - else - return FOCUS_OTHER; - - case GNOME_CAL_WEEK_VIEW: - case GNOME_CAL_MONTH_VIEW: - wv = E_WEEK_VIEW (widget); - - if (GTK_WIDGET_HAS_FOCUS (wv->main_canvas)) - return FOCUS_CALENDAR; - else - return FOCUS_OTHER; - - default: - g_assert_not_reached (); - return FOCUS_OTHER; - } - } -} - -/* Computes the range of time that the date navigator is showing */ -static void -get_date_navigator_range (GnomeCalendar *gcal, time_t *start_time, time_t *end_time) -{ - GnomeCalendarPrivate *priv; - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - struct icaltimetype start_tt; - struct icaltimetype end_tt; - - priv = gcal->priv; - - start_tt = icaltime_null_time (); - end_tt = icaltime_null_time (); - - if (!e_calendar_item_get_date_range (priv->date_navigator->calitem, - &start_year, &start_month, &start_day, - &end_year, &end_month, &end_day)) { - *start_time = -1; - *end_time = -1; - return; - } - - start_tt.year = start_year; - start_tt.month = start_month + 1; - start_tt.day = start_day; - - end_tt.year = end_year; - end_tt.month = end_month + 1; - end_tt.day = end_day; - - icaltime_adjust (&end_tt, 1, 0, 0, 0); - - *start_time = icaltime_as_timet_with_zone (start_tt, priv->zone); - *end_time = icaltime_as_timet_with_zone (end_tt, priv->zone); -} - -/* Adjusts a given query sexp with the time range of the date navigator */ -static char * -adjust_query_sexp (GnomeCalendar *gcal, const char *sexp) -{ - time_t start_time, end_time; - char *start, *end; - char *new_sexp; - - get_date_navigator_range (gcal, &start_time, &end_time); - if (start_time == -1 || end_time == -1) - return NULL; - - start = isodate_from_time_t (start_time); - end = isodate_from_time_t (end_time); - - new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")" - " (occur-in-time-range? (make-time \"%s\")" - " (make-time \"%s\"))" - " %s)", - start, end, - sexp); - - g_free (start); - g_free (end); - - return new_sexp; -} - -/* Restarts a query for the date navigator in the calendar */ -static void -update_query (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - CalQuery *old_query; - char *real_sexp; - - priv = gcal->priv; - - e_calendar_item_clear_marks (priv->date_navigator->calitem); - - if (!(priv->client - && cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_LOADED)) - return; - - old_query = priv->dn_query; - priv->dn_query = NULL; - - if (old_query) { - g_signal_handlers_disconnect_matched (old_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - g_object_unref (old_query); - } - - g_assert (priv->sexp != NULL); - - real_sexp = adjust_query_sexp (gcal, priv->sexp); - if (!real_sexp) - return; /* No time range is set, so don't start a query */ - - priv->dn_query = cal_client_get_query (priv->client, real_sexp); - g_free (real_sexp); - - if (!priv->dn_query) { - g_message ("update_query(): Could not create the query"); - return; - } - - g_signal_connect (priv->dn_query, "obj_updated", - G_CALLBACK (dn_query_obj_updated_cb), gcal); - g_signal_connect (priv->dn_query, "obj_removed", - G_CALLBACK (dn_query_obj_removed_cb), gcal); - g_signal_connect (priv->dn_query, "query_done", - G_CALLBACK (dn_query_query_done_cb), gcal); - g_signal_connect (priv->dn_query, "eval_error", - G_CALLBACK (dn_query_eval_error_cb), gcal); -} - -/** - * gnome_calendar_set_query: - * @gcal: A calendar. - * @sexp: Sexp that defines the query. - * - * Sets the query sexp for all the views in a calendar. - **/ -void -gnome_calendar_set_query (GnomeCalendar *gcal, const char *sexp) -{ - GnomeCalendarPrivate *priv; - CalendarModel *model; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (sexp != NULL); - - priv = gcal->priv; - - /* Set the query on the date navigator */ - - if (priv->sexp) - g_free (priv->sexp); - - priv->sexp = g_strdup (sexp); - - update_query (gcal); - - /* Set the query on the main view */ - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_set_query (E_DAY_VIEW (priv->day_view), sexp); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_set_query (E_DAY_VIEW (priv->work_week_view), sexp); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_set_query (E_WEEK_VIEW (priv->week_view), sexp); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_set_query (E_WEEK_VIEW (priv->month_view), sexp); - break; - - default: - g_warning ("A penguin bit my hand!"); - g_assert_not_reached (); - } - - /* Set the query on the task pad */ - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - calendar_model_set_query (model, sexp); -} - -/* Returns the current time, for the ECalendarItem. */ -static struct tm -get_current_time (ECalendarItem *calitem, gpointer data) -{ - GnomeCalendar *cal = data; - struct tm tmp_tm = { 0 }; - struct icaltimetype tt; - - g_return_val_if_fail (cal != NULL, tmp_tm); - g_return_val_if_fail (GNOME_IS_CALENDAR (cal), tmp_tm); - - tt = icaltime_from_timet_with_zone (time (NULL), FALSE, - cal->priv->zone); - - /* Now copy it to the struct tm and return it. */ - tmp_tm = icaltimetype_to_tm (&tt); - - return tmp_tm; -} - -/* Callback used when the sexp changes in the calendar search bar */ -static void -search_bar_sexp_changed_cb (CalSearchBar *cal_search, const char *sexp, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - gnome_calendar_set_query (gcal, sexp); -} - -/* Callback used when the selected category in the search bar changes */ -static void -search_bar_category_changed_cb (CalSearchBar *cal_search, const char *category, gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - CalendarModel *model; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - e_day_view_set_default_category (E_DAY_VIEW (priv->day_view), category); - e_day_view_set_default_category (E_DAY_VIEW (priv->work_week_view), category); - e_week_view_set_default_category (E_WEEK_VIEW (priv->week_view), category); - e_week_view_set_default_category (E_WEEK_VIEW (priv->month_view), category); - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - calendar_model_set_default_category (model, category); -} - -static void -view_selection_changed_cb (GtkWidget *view, GnomeCalendar *gcal) -{ - gtk_signal_emit (GTK_OBJECT (gcal), - gnome_calendar_signals[CALENDAR_SELECTION_CHANGED]); -} - - -/* Callback used when the taskpad receives a focus event. We emit the - * corresponding signal so that parents can change the menus as appropriate. - */ -static gint -table_canvas_focus_change_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gtk_signal_emit (GTK_OBJECT (gcal), gnome_calendar_signals [TASKPAD_FOCUS_CHANGE], - event->in ? TRUE : FALSE); - - return FALSE; -} - -static gint -calendar_focus_change_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - gtk_signal_emit (GTK_OBJECT (gcal), gnome_calendar_signals [CALENDAR_FOCUS_CHANGE], - event->in ? TRUE : FALSE); - - return FALSE; -} - -/* Connects to the focus change signals of a day view widget */ -static void -connect_day_view_focus (GnomeCalendar *gcal, EDayView *dv) -{ - g_signal_connect (dv->top_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect (dv->top_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - - g_signal_connect (dv->main_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect (dv->main_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); -} - -/* Connects to the focus change signals of a week view widget */ -static void -connect_week_view_focus (GnomeCalendar *gcal, EWeekView *wv) -{ - g_signal_connect (wv->main_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect (wv->main_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); -} - -/* Callback used when the selection in the taskpad table changes. We just proxy - * the signal with our own one. - */ -static void -table_selection_change_cb (ETable *etable, gpointer data) -{ - GnomeCalendar *gcal; - int n_selected; - - gcal = GNOME_CALENDAR (data); - - n_selected = e_table_selected_count (etable); - gtk_signal_emit (GTK_OBJECT (gcal), gnome_calendar_signals[TASKPAD_SELECTION_CHANGED]); -} - -static void -setup_widgets (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GtkWidget *w; - gchar *filename; - CalendarModel *model; - ETable *etable; - - priv = gcal->priv; - - priv->search_bar = cal_search_bar_new (); - g_signal_connect (priv->search_bar, "sexp_changed", - G_CALLBACK (search_bar_sexp_changed_cb), gcal); - g_signal_connect (priv->search_bar, "category_changed", - G_CALLBACK (search_bar_category_changed_cb), gcal); - - gtk_widget_show (priv->search_bar); - gtk_box_pack_start (GTK_BOX (gcal), priv->search_bar, FALSE, FALSE, 6); - - /* The main HPaned, with the notebook of calendar views on the left - and the ECalendar and ToDo list on the right. */ - priv->hpane = gtk_hpaned_new (); - g_signal_connect_after(priv->hpane, "realize", - G_CALLBACK(gnome_calendar_hpane_realized), gcal); - g_signal_connect (priv->hpane, "button_release_event", - G_CALLBACK (gnome_calendar_hpane_resized), gcal); - gtk_widget_show (priv->hpane); - gtk_box_pack_start (GTK_BOX (gcal), priv->hpane, TRUE, TRUE, 6); - - /* The Notebook containing the 4 calendar views. */ - priv->notebook = gtk_notebook_new (); - gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE); - gtk_widget_show (priv->notebook); - gtk_paned_pack1 (GTK_PANED (priv->hpane), priv->notebook, FALSE, TRUE); - - /* The VPaned widget, to contain the GtkCalendar & ToDo list. */ - priv->vpane = gtk_vpaned_new (); - g_signal_connect_after (priv->vpane, "realize", - G_CALLBACK(gnome_calendar_vpane_realized), gcal); - g_signal_connect (priv->vpane, "button_release_event", - G_CALLBACK (gnome_calendar_vpane_resized), gcal); - gtk_widget_show (priv->vpane); - gtk_paned_pack2 (GTK_PANED (priv->hpane), priv->vpane, TRUE, TRUE); - - /* The ECalendar. */ - w = e_calendar_new (); - priv->date_navigator = E_CALENDAR (w); - e_calendar_item_set_days_start_week_sel (priv->date_navigator->calitem, 9); - e_calendar_item_set_max_days_sel (priv->date_navigator->calitem, 42); - gtk_widget_show (w); - e_calendar_item_set_get_time_callback (priv->date_navigator->calitem, - (ECalendarItemGetTimeCallback) get_current_time, - gcal, NULL); - - gtk_paned_pack1 (GTK_PANED (priv->vpane), w, FALSE, TRUE); - - g_signal_connect (priv->date_navigator->calitem, "selection_changed", - G_CALLBACK (gnome_calendar_on_date_navigator_selection_changed), gcal); - g_signal_connect (priv->date_navigator->calitem, "date_range_changed", - G_CALLBACK (gnome_calendar_on_date_navigator_date_range_changed), gcal); - - /* The ToDo list. */ - priv->todo = e_calendar_table_new (); - calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->todo)); - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - calendar_model_set_new_comp_vtype (model, CAL_COMPONENT_TODO); - gtk_paned_pack2 (GTK_PANED (priv->vpane), priv->todo, TRUE, TRUE); - gtk_widget_show (priv->todo); - - filename = g_strdup_printf ("%s/config/TaskPad", evolution_dir); - e_calendar_table_load_state (E_CALENDAR_TABLE (priv->todo), filename); - g_free (filename); - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - g_signal_connect (etable->table_canvas, "focus_in_event", - G_CALLBACK (table_canvas_focus_change_cb), gcal); - g_signal_connect (etable->table_canvas, "focus_out_event", - G_CALLBACK (table_canvas_focus_change_cb), gcal); - - g_signal_connect (etable, "selection_change", - G_CALLBACK (table_selection_change_cb), gcal); - - /* The Day View. */ - priv->day_view = e_day_view_new (); - e_day_view_set_calendar (E_DAY_VIEW (priv->day_view), gcal); - gtk_widget_show (priv->day_view); - gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), - priv->day_view, gtk_label_new ("")); - g_signal_connect (priv->day_view, "selection_changed", - G_CALLBACK (view_selection_changed_cb), gcal); - - connect_day_view_focus (gcal, E_DAY_VIEW (priv->day_view)); - - /* The Work Week View. */ - priv->work_week_view = e_day_view_new (); - e_day_view_set_work_week_view (E_DAY_VIEW (priv->work_week_view), - TRUE); - e_day_view_set_days_shown (E_DAY_VIEW (priv->work_week_view), 5); - e_day_view_set_calendar (E_DAY_VIEW (priv->work_week_view), gcal); - gtk_widget_show (priv->work_week_view); - gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), - priv->work_week_view, gtk_label_new ("")); - g_signal_connect (priv->work_week_view, "selection_changed", - G_CALLBACK (view_selection_changed_cb), gcal); - - connect_day_view_focus (gcal, E_DAY_VIEW (priv->work_week_view)); - - /* The Week View. */ - priv->week_view = e_week_view_new (); - e_week_view_set_calendar (E_WEEK_VIEW (priv->week_view), gcal); - gtk_widget_show (priv->week_view); - gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), - priv->week_view, gtk_label_new ("")); - g_signal_connect (priv->week_view, "selection_changed", - G_CALLBACK (view_selection_changed_cb), gcal); - - connect_week_view_focus (gcal, E_WEEK_VIEW (priv->week_view)); - - /* The Month View. */ - priv->month_view = e_week_view_new (); - e_week_view_set_calendar (E_WEEK_VIEW (priv->month_view), gcal); - e_week_view_set_multi_week_view (E_WEEK_VIEW (priv->month_view), TRUE); - gtk_widget_show (priv->month_view); - gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), - priv->month_view, gtk_label_new ("")); - g_signal_connect (priv->month_view, "selection_changed", - G_CALLBACK (view_selection_changed_cb), gcal); - - connect_week_view_focus (gcal, E_WEEK_VIEW (priv->month_view)); - - gnome_calendar_update_config_settings (gcal, TRUE); -} - -/* Object initialization function for the gnome calendar */ -static void -gnome_calendar_init (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = g_new0 (GnomeCalendarPrivate, 1); - gcal->priv = priv; - - priv->cal_categories = NULL; - priv->tasks_categories = NULL; - - priv->current_view_type = GNOME_CAL_DAY_VIEW; - priv->range_selected = FALSE; - - setup_widgets (gcal); - priv->dn_query = NULL; - priv->sexp = g_strdup ("#t"); /* Match all */ - - priv->selection_start_time = time_day_begin_with_zone (time (NULL), - priv->zone); - priv->selection_end_time = time_add_day_with_zone (priv->selection_start_time, 1, priv->zone); - - priv->view_instance = NULL; - priv->view_menus = NULL; - - priv->visible_start = -1; - priv->visible_end = -1; -} - -/* Frees a set of categories */ -static void -free_categories (GPtrArray *categories) -{ - int i; - - if (!categories) - return; - - for (i = 0; i < categories->len; i++) - g_free (categories->pdata[i]); - - g_ptr_array_free (categories, TRUE); -} - -static void -gnome_calendar_destroy (GtkObject *object) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - gchar *filename; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (object)); - - gcal = GNOME_CALENDAR (object); - priv = gcal->priv; - - free_categories (priv->cal_categories); - priv->cal_categories = NULL; - - free_categories (priv->tasks_categories); - priv->tasks_categories = NULL; - - /* Save the TaskPad layout. */ - filename = g_strdup_printf ("%s/config/TaskPad", evolution_dir); - e_calendar_table_save_state (E_CALENDAR_TABLE (priv->todo), filename); - g_free (filename); - - if (priv->dn_query) { - g_signal_handlers_disconnect_matched (priv->dn_query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - g_object_unref (priv->dn_query); - priv->dn_query = NULL; - } - - if (priv->sexp) { - g_free (priv->sexp); - priv->sexp = NULL; - } - - if (priv->client) { - g_signal_handlers_disconnect_matched (priv->client, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - g_object_unref (priv->client); - priv->client = NULL; - } - - if (priv->task_pad_client) { - g_signal_handlers_disconnect_matched (priv->task_pad_client, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - g_object_unref (priv->task_pad_client); - priv->task_pad_client = NULL; - } - - if (priv->view_instance) { - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - } - - if (priv->view_menus) { - g_object_unref (priv->view_menus); - priv->view_menus = NULL; - } - - g_free (priv); - gcal->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -void -gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time) -{ - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (new_time != -1); - - priv = gcal->priv; - - priv->selection_start_time = time_day_begin_with_zone (new_time, - priv->zone); - priv->selection_end_time = time_add_day_with_zone (priv->selection_start_time, 1, priv->zone); - - gnome_calendar_update_view_times (gcal); - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); -} - - -static void -gnome_calendar_update_view_times (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_set_selected_time_range (E_DAY_VIEW (priv->day_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_set_selected_time_range (E_DAY_VIEW (priv->work_week_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_set_selected_time_range (E_WEEK_VIEW (priv->week_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_set_selected_time_range (E_WEEK_VIEW (priv->month_view), - priv->selection_start_time, - priv->selection_end_time); - break; - - default: - g_warning ("My penguin is gone!"); - g_assert_not_reached (); - } -} - -static void -gnome_calendar_direction (GnomeCalendar *gcal, int direction) -{ - GnomeCalendarPrivate *priv; - time_t start_time, end_time; - - priv = gcal->priv; - - start_time = priv->selection_start_time; - end_time = priv->selection_end_time; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - start_time = time_add_day_with_zone (start_time, direction, - priv->zone); - end_time = time_add_day_with_zone (end_time, direction, - priv->zone); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - start_time = time_add_week_with_zone (start_time, direction, - priv->zone); - end_time = time_add_week_with_zone (end_time, direction, - priv->zone); - break; - - case GNOME_CAL_WEEK_VIEW: - start_time = time_add_week_with_zone (start_time, direction, - priv->zone); - end_time = time_add_week_with_zone (end_time, direction, - priv->zone); - break; - - case GNOME_CAL_MONTH_VIEW: - start_time = time_add_month_with_zone (start_time, direction, - priv->zone); - end_time = time_add_month_with_zone (end_time, direction, - priv->zone); - break; - - default: - g_warning ("Weee! Where did the penguin go?"); - g_assert_not_reached (); - return; - } - - priv->selection_start_time = start_time; - priv->selection_end_time = end_time; - - gnome_calendar_update_view_times (gcal); - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); -} - -void -gnome_calendar_next (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_direction (gcal, 1); -} - -void -gnome_calendar_previous (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_direction (gcal, -1); -} - -void -gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time) -{ - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - priv->selection_start_time = time_day_begin_with_zone (time, - priv->zone); - priv->selection_end_time = time_add_day_with_zone (priv->selection_start_time, 1, priv->zone); - - gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, FALSE, TRUE); -} - -static void -focus_current_view (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - gtk_widget_grab_focus (priv->day_view); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - gtk_widget_grab_focus (priv->work_week_view); - break; - - case GNOME_CAL_WEEK_VIEW: - gtk_widget_grab_focus (priv->week_view); - break; - - case GNOME_CAL_MONTH_VIEW: - gtk_widget_grab_focus (priv->month_view); - break; - - default: - g_warning ("A penguin fell on its face!"); - g_assert_not_reached (); - } -} - -void -gnome_calendar_goto_today (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_goto (gcal, time (NULL)); - focus_current_view (gcal); -} - -/** - * gnome_calendar_get_view: - * @gcal: A calendar. - * - * Queries the type of the view that is being shown in a calendar. - * - * Return value: Type of the view that is currently shown. - **/ -GnomeCalendarViewType -gnome_calendar_get_view (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_val_if_fail (gcal != NULL, GNOME_CAL_DAY_VIEW); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), GNOME_CAL_DAY_VIEW); - - priv = gcal->priv; - return priv->current_view_type; -} - -/* Sets the view without changing the selection or updating the date - * navigator. If a range of dates isn't selected it will also reset the number - * of days/weeks shown to the default (i.e. 1 day for the day view or 5 weeks - * for the month view). - */ -static void -set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type, - gboolean range_selected, gboolean grab_focus) -{ - GnomeCalendarPrivate *priv; - gboolean round_selection; - GtkWidget *focus_widget; - const char *view_id; - static gboolean updating = FALSE; - - if (updating) - return; - - priv = gcal->priv; - - round_selection = FALSE; - focus_widget = NULL; - - switch (view_type) { - case GNOME_CAL_DAY_VIEW: - view_id = "Day_View"; - focus_widget = priv->day_view; - - if (!range_selected) - e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), 1); - - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - view_id = "Work_Week_View"; - focus_widget = priv->work_week_view; - break; - - case GNOME_CAL_WEEK_VIEW: - view_id = "Week_View"; - focus_widget = priv->week_view; - round_selection = TRUE; - break; - - case GNOME_CAL_MONTH_VIEW: - view_id = "Month_View"; - focus_widget = priv->month_view; - - if (!range_selected) - e_week_view_set_weeks_shown (E_WEEK_VIEW (priv->month_view), 5); - - round_selection = TRUE; - break; - - default: - g_warning ("A penguin is loose!"); - g_assert_not_reached (); - return; - } - - priv->current_view_type = view_type; - priv->range_selected = range_selected; - - g_assert (focus_widget != NULL); - - calendar_config_set_default_view (view_type); - - updating = TRUE; - gtk_notebook_set_page (GTK_NOTEBOOK (priv->notebook), (int) view_type); - if (priv->view_instance) - gal_view_instance_set_current_view_id (priv->view_instance, view_id); - updating = FALSE; - - if (grab_focus) - gtk_widget_grab_focus (focus_widget); - - gnome_calendar_set_pane_positions (gcal); - - /* For the week & month views we want the selection in the date - navigator to be rounded to the nearest week when the arrow buttons - are pressed to move to the previous/next month. */ - g_object_set (G_OBJECT (priv->date_navigator->calitem), - "round_selection_when_moving", round_selection, - NULL); -} - -/** - * gnome_calendar_set_view: - * @gcal: A calendar. - * @view_type: Type of view to show. - * @range_selected: If false, the range of days/weeks shown will be reset to the - * default value (1 for day view, 5 for week view, respectively). If true, the - * currently displayed range will be kept. - * @grab_focus: Whether the view widget should grab the focus. - * - * Sets the view that should be shown in a calendar. If @reset_range is true, - * this function will automatically set the number of days or weeks shown in - * the view; otherwise the last configuration will be kept. - **/ -void -gnome_calendar_set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type, - gboolean range_selected, gboolean grab_focus) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - set_view (gcal, view_type, range_selected, grab_focus); - gnome_calendar_update_view_times (gcal); - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); -} - -/* Callback used when the view collection asks us to display a particular view */ -static void -display_view_cb (GalViewInstance *view_instance, GalView *view, gpointer data) -{ - GnomeCalendar *gcal; - CalendarView *cal_view; - - gcal = GNOME_CALENDAR (data); - - if (!IS_CALENDAR_VIEW (view)) - g_error ("display_view_cb(): Unknown type of view for GnomeCalendar"); - - cal_view = CALENDAR_VIEW (view); - - gnome_calendar_set_view (gcal, calendar_view_get_view_type (cal_view), FALSE, TRUE); -} - -/** - * gnome_calendar_setup_view_menus: - * @gcal: A calendar. - * @uic: UI controller to use for the menus. - * - * Sets up the #GalView menus for a calendar. This function should be called - * from the Bonobo control activation callback for this calendar. Also, the - * menus should be discarded using gnome_calendar_discard_view_menus(). - **/ -void -gnome_calendar_setup_view_menus (GnomeCalendar *gcal, BonoboUIComponent *uic) -{ - GnomeCalendarPrivate *priv; - char *path; - CalendarViewFactory *factory; - static GalViewCollection *collection = NULL; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (uic != NULL); - g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); - - priv = gcal->priv; - - g_return_if_fail (priv->view_instance == NULL); - - g_assert (priv->view_instance == NULL); - g_assert (priv->view_menus == NULL); - - /* Create the view instance */ - - if (collection == NULL) { - collection = gal_view_collection_new (); - - gal_view_collection_set_title (collection, _("Calendar")); - - path = gnome_util_prepend_user_home ("/evolution/views/calendar/"); - gal_view_collection_set_storage_directories (collection, - EVOLUTION_GALVIEWSDIR "/calendar/", - path); - g_free (path); - - /* Create the views */ - - factory = calendar_view_factory_new (GNOME_CAL_DAY_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_WORK_WEEK_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_WEEK_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_MONTH_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - /* Load the collection and create the menus */ - - gal_view_collection_load (collection); - } - - g_print ("Making GAL view instance.\n"); - priv->view_instance = gal_view_instance_new (collection, cal_client_get_uri (priv->client)); - - priv->view_menus = gal_view_menus_new (priv->view_instance); - gal_view_menus_set_show_define_views (priv->view_menus, FALSE); - gal_view_menus_apply (priv->view_menus, uic, NULL); - gnome_calendar_set_view (gcal, priv->current_view_type, TRUE, FALSE); - - g_signal_connect (priv->view_instance, "display_view", - G_CALLBACK (display_view_cb), gcal); - display_view_cb (priv->view_instance, gal_view_instance_get_current_view (priv->view_instance), gcal); -} - -/** - * gnome_calendar_discard_view_menus: - * @gcal: A calendar. - * - * Discards the #GalView menus used by a calendar. This function should be - * called from the Bonobo control deactivation callback for this calendar. The - * menus should have been set up with gnome_calendar_setup_view_menus(). - **/ -void -gnome_calendar_discard_view_menus (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - - priv = gcal->priv; - - g_return_if_fail (priv->view_instance != NULL); - - g_assert (priv->view_instance != NULL); - g_assert (priv->view_menus != NULL); - - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - - g_object_unref (priv->view_menus); - priv->view_menus = NULL; -} - -EPopupMenu * -gnome_calendar_setup_view_popup (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - priv = gcal->priv; - - g_return_val_if_fail (priv->view_instance != NULL, NULL); - - return gal_view_instance_get_popup_menu (priv->view_instance); -} - -void -gnome_calendar_discard_view_popup (GnomeCalendar *gcal, EPopupMenu *popup) -{ - - - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - g_return_if_fail (priv->view_instance != NULL); - - gal_view_instance_free_popup_menu (priv->view_instance, popup); -} - -static void -gnome_calendar_set_pane_positions (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos_month_view); - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos_month_view); - } else { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos); - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos); - } -} - -/* Displays an error to indicate that opening a calendar failed */ -static void -open_error (GnomeCalendar *gcal, const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("Could not open the folder in `%s'"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (msg); - g_free (urinopwd); -} - -/* Displays an error to indicate that the specified URI method is not supported */ -static void -method_error (GnomeCalendar *gcal, const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("The method required to open `%s' is not supported"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (msg); - g_free (urinopwd); -} - -/* Displays an error to indicate permission problems */ -static void -permission_error (GnomeCalendar *gcal, const char *uri) -{ - char *msg; - char *urinopwd; - - urinopwd = get_uri_without_password (uri); - msg = g_strdup_printf (_("You don't have permission to open the folder in `%s'"), urinopwd); - gnome_error_dialog_parented (msg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (msg); - g_free (urinopwd); -} - -/* Callback from the calendar client when a calendar is loaded */ -static void -client_cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - char *msg; - char *uristr; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - switch (status) { - case CAL_CLIENT_OPEN_SUCCESS: - /* If this is the main CalClient, update the Date Navigator. */ - if (client == priv->client) { - update_query (gcal); - } - - /* Set the client's default timezone, if we have one. */ - if (priv->zone) { - cal_client_set_default_timezone (client, priv->zone); - } - - /* add the alarms for this client */ - uristr = get_uri_without_password (cal_client_get_uri (client)); - msg = g_strdup_printf (_("Adding alarms for %s"), uristr); - g_free (uristr); - if (client == priv->client) { - e_week_view_set_status_message (E_WEEK_VIEW (priv->week_view), msg); - } - else if (client == priv->task_pad_client) { - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), msg); - } - g_free (msg); - - add_alarms (cal_client_get_uri (client)); - break; - - case CAL_CLIENT_OPEN_ERROR: - open_error (gcal, cal_client_get_uri (client)); - break; - - case CAL_CLIENT_OPEN_NOT_FOUND: - /* bullshit; we did not specify only_if_exists */ - g_assert_not_reached (); - return; - - case CAL_CLIENT_OPEN_METHOD_NOT_SUPPORTED: - method_error (gcal, cal_client_get_uri (client)); - break; - - case CAL_CLIENT_OPEN_PERMISSION_DENIED : - permission_error (gcal, cal_client_get_uri (client)); - break; - - default: - g_assert_not_reached (); - return; - } - - if (client == priv->client) { - e_week_view_set_status_message (E_WEEK_VIEW (priv->week_view), NULL); - } - else if (client == priv->task_pad_client) { - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), NULL); - } -} - -/* Duplicates an array of categories */ -static GPtrArray * -copy_categories (GPtrArray *categories) -{ - GPtrArray *c; - int i; - - c = g_ptr_array_new (); - g_ptr_array_set_size (c, categories->len); - - for (i = 0; i < categories->len; i++) - c->pdata[i] = g_strdup (categories->pdata[i]); - - return c; -} - -/* Adds the categories from an array to a hash table if they don't exist there - * already. - */ -static void -add_categories (GHashTable *categories, GPtrArray *c) -{ - int i; - - if (!c) - return; - - for (i = 0; i < c->len; i++) { - const char *cat; - const char *str; - - cat = c->pdata[i]; - str = g_hash_table_lookup (categories, cat); - - if (!str) - g_hash_table_insert (categories, (char *) cat, NULL); - } -} - -/* Used to append categories from a hash table to an array */ -struct append_category_closure { - GPtrArray *c; - - int i; -}; - -/* Appends a category from the hash table to the array */ -static void -append_category_cb (gpointer key, gpointer value, gpointer data) -{ - struct append_category_closure *closure; - const char *category; - - category = key; - closure = data; - - closure->c->pdata[closure->i] = g_strdup (category); - closure->i++; -} - -/* Creates the union of two sets of categories */ -static GPtrArray * -merge_categories (GPtrArray *a, GPtrArray *b) -{ - GHashTable *categories; - int n; - GPtrArray *c; - struct append_category_closure closure; - - categories = g_hash_table_new (g_str_hash, g_str_equal); - - add_categories (categories, a); - add_categories (categories, b); - - n = g_hash_table_size (categories); - - c = g_ptr_array_new (); - g_ptr_array_set_size (c, n); - - closure.c = c; - closure.i = 0; - g_hash_table_foreach (categories, append_category_cb, &closure); - g_hash_table_destroy (categories); - - return c; -} - -/* Callback from the calendar client when the set of categories changes. We - * have to merge the categories of the calendar and tasks clients. - */ -static void -client_categories_changed_cb (CalClient *client, GPtrArray *categories, gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - GPtrArray *merged; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - if (client == priv->client) { - free_categories (priv->cal_categories); - priv->cal_categories = copy_categories (categories); - } else if (client == priv->task_pad_client) { - free_categories (priv->tasks_categories); - priv->tasks_categories = copy_categories (categories); - } else - g_assert_not_reached (); - - merged = merge_categories (priv->cal_categories, priv->tasks_categories); - cal_search_bar_set_categories (CAL_SEARCH_BAR (priv->search_bar), merged); - free_categories (merged); -} - -/* Callback when we get an error message from the backend */ -static void -backend_error_cb (CalClient *client, const char *message, gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - char *errmsg; - char *uristr; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - uristr = get_uri_without_password (cal_client_get_uri (client)); - errmsg = g_strdup_printf (_("Error on %s:\n %s"), uristr, message); - gnome_error_dialog_parented (errmsg, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (errmsg); - g_free (uristr); -} - -/* Callback when the backend dies */ -static void -backend_died_cb (CalClient *client, gpointer data) -{ - GnomeCalendar *gcal; - GnomeCalendarPrivate *priv; - char *message; - char *uristr; - - gcal = GNOME_CALENDAR (data); - priv = gcal->priv; - - uristr = get_uri_without_password (cal_client_get_uri (priv->client)); - if (client == priv->client) { - message = g_strdup_printf (_("The calendar backend for\n%s\n has crashed. " - "You will have to restart Evolution in order " - "to use it again"), - uristr); - e_day_view_set_status_message (E_DAY_VIEW (priv->day_view), NULL); - e_day_view_set_status_message (E_DAY_VIEW (priv->work_week_view), NULL); - e_week_view_set_status_message (E_WEEK_VIEW (priv->week_view), NULL); - e_week_view_set_status_message (E_WEEK_VIEW (priv->month_view), NULL); - } else if (client == priv->task_pad_client) { - message = g_strdup_printf (_("The task backend for\n%s\n has crashed. " - "You will have to restart Evolution in order " - "to use it again"), - uristr); - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), NULL); - } else { - message = NULL; - g_assert_not_reached (); - } - - gnome_error_dialog_parented (message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - g_free (message); - g_free (uristr); -} - -GtkWidget * -gnome_calendar_construct (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GnomeCalendarViewType view_type; - CalendarModel *model; - - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - priv = gcal->priv; - - /* - * Calendar Folder Client. - */ - priv->client = cal_client_new (); - if (!priv->client) - return NULL; - - g_signal_connect (priv->client, "cal_opened", - G_CALLBACK (client_cal_opened_cb), gcal); - g_signal_connect (priv->client, "backend_error", - G_CALLBACK (backend_error_cb), gcal); - g_signal_connect (priv->client, "categories_changed", - G_CALLBACK (client_categories_changed_cb), gcal); - g_signal_connect (priv->client, "backend_died", - G_CALLBACK (backend_died_cb), gcal); - - e_day_view_set_cal_client (E_DAY_VIEW (priv->day_view), - priv->client); - e_day_view_set_cal_client (E_DAY_VIEW (priv->work_week_view), - priv->client); - e_week_view_set_cal_client (E_WEEK_VIEW (priv->week_view), - priv->client); - e_week_view_set_cal_client (E_WEEK_VIEW (priv->month_view), - priv->client); - - /* - * TaskPad Folder Client. - */ - priv->task_pad_client = cal_client_new (); - if (!priv->task_pad_client) - return NULL; - - g_signal_connect (priv->task_pad_client, "cal_opened", - G_CALLBACK (client_cal_opened_cb), gcal); - g_signal_connect (priv->task_pad_client, "backend_error", - G_CALLBACK (backend_error_cb), gcal); - g_signal_connect (priv->task_pad_client, "categories_changed", - G_CALLBACK (client_categories_changed_cb), gcal); - g_signal_connect (priv->task_pad_client, "backend_died", - G_CALLBACK (backend_died_cb), gcal); - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - g_assert (model != NULL); - - calendar_model_set_cal_client (model, priv->task_pad_client, CALOBJ_TYPE_TODO); - - /* Get the default view to show. */ - view_type = calendar_config_get_default_view (); - if (view_type < GNOME_CAL_DAY_VIEW || view_type > GNOME_CAL_MONTH_VIEW) - view_type = GNOME_CAL_DAY_VIEW; - - gnome_calendar_set_view (gcal, view_type, FALSE, FALSE); - - return GTK_WIDGET (gcal); -} - -GtkWidget * -gnome_calendar_new (void) -{ - GnomeCalendar *gcal; - - gcal = g_object_new (gnome_calendar_get_type (), NULL); - - if (!gnome_calendar_construct (gcal)) { - g_message ("gnome_calendar_new(): Could not construct the calendar GUI"); - g_object_unref (gcal); - return NULL; - } - - return GTK_WIDGET (gcal); -} - -void -gnome_calendar_set_ui_component (GnomeCalendar *gcal, - BonoboUIComponent *ui_component) -{ - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (ui_component == NULL || BONOBO_IS_UI_COMPONENT (ui_component)); - - e_search_bar_set_ui_component (E_SEARCH_BAR (gcal->priv->search_bar), ui_component); -} - -/** - * gnome_calendar_get_cal_client: - * @gcal: A calendar view. - * - * Queries the calendar client interface object that a calendar view is using. - * - * Return value: A calendar client interface object. - **/ -CalClient * -gnome_calendar_get_cal_client (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - priv = gcal->priv; - - return priv->client; -} - -/** - * gnome_calendar_get_task_pad_cal_client: - * @gcal: A calendar view. - * - * Queries the calendar client interface object that a calendar view is using - * for the Task Pad. - * - * Return value: A calendar client interface object. - **/ -CalClient * -gnome_calendar_get_task_pad_cal_client (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - priv = gcal->priv; - - return priv->task_pad_client; -} - -/* Adds the specified URI to the alarm notification service */ -static void -add_alarms (const char *uri) -{ - CORBA_Environment ev; - GNOME_Evolution_Calendar_AlarmNotify an; - - /* Activate the alarm notification service */ - - CORBA_exception_init (&ev); - an = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_warning ("add_alarms(): Could not activate the alarm notification service: %s", - CORBA_exception_id (&ev)); - CORBA_exception_free (&ev); - return; - } - CORBA_exception_free (&ev); - - /* Ask the service to load the URI */ - - CORBA_exception_init (&ev); - GNOME_Evolution_Calendar_AlarmNotify_addCalendar (an, uri, &ev); - - if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_AlarmNotify_InvalidURI)) - g_message ("add_calendar(): Invalid URI reported from the " - "alarm notification service"); - else if (BONOBO_USER_EX (&ev, ex_GNOME_Evolution_Calendar_AlarmNotify_BackendContactError)) - g_message ("add_calendar(): The alarm notification service could " - "not contact the backend"); - else if (BONOBO_EX (&ev)) - g_message ("add_calendar(): Could not issue the addCalendar request"); - - CORBA_exception_free (&ev); - - /* Get rid of the service */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (an, &ev); - if (BONOBO_EX (&ev)) - g_message ("add_alarms(): Could not unref the alarm notification service"); - - CORBA_exception_free (&ev); -} - -gboolean -gnome_calendar_open (GnomeCalendar *gcal, const char *str_uri) -{ - GnomeCalendarPrivate *priv; - char *tasks_uri; - gboolean success; - EUri *uri; - char *message; - char *real_uri; - char *urinopwd; - - g_return_val_if_fail (gcal != NULL, FALSE); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), FALSE); - g_return_val_if_fail (str_uri != NULL, FALSE); - - priv = gcal->priv; - - g_return_val_if_fail ( - cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_NOT_LOADED, - FALSE); - - g_return_val_if_fail ( - cal_client_get_load_state (priv->task_pad_client) == CAL_CLIENT_LOAD_NOT_LOADED, - FALSE); - - uri = e_uri_new (str_uri); - if (!uri || !g_strncasecmp (uri->protocol, "file", 4)) - real_uri = g_concat_dir_and_file (str_uri, "calendar.ics"); - else - real_uri = g_strdup (str_uri); - - urinopwd = get_uri_without_password (real_uri); - message = g_strdup_printf (_("Opening calendar at %s"), urinopwd); - g_free (urinopwd); - e_week_view_set_status_message (E_WEEK_VIEW (priv->week_view), message); - g_free (message); - - if (!cal_client_open_calendar (priv->client, real_uri, FALSE)) { - g_message ("gnome_calendar_open(): Could not issue the request to open the calendar folder"); - g_free (real_uri); - e_uri_free (uri); - e_week_view_set_status_message (E_WEEK_VIEW (priv->week_view), NULL); - - return FALSE; - } - - /* Open the appropriate Tasks folder to show in the TaskPad */ - - if (!uri) { - tasks_uri = g_strdup_printf ("%s/local/Tasks/tasks.ics", evolution_dir); - message = g_strdup_printf (_("Opening tasks at %s"), tasks_uri); - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), message); - g_free (message); - - success = cal_client_open_calendar (priv->task_pad_client, tasks_uri, FALSE); - g_free (tasks_uri); - } - else { - if (!g_strncasecmp (uri->protocol, "file", 4)) { - tasks_uri = g_strdup_printf ("%s/local/Tasks/tasks.ics", evolution_dir); - message = g_strdup_printf (_("Opening tasks at %s"), tasks_uri); - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), message); - g_free (message); - - success = cal_client_open_calendar (priv->task_pad_client, tasks_uri, FALSE); - g_free (tasks_uri); - } - else { - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), - _("Opening default tasks folder")); - success = cal_client_open_default_tasks (priv->task_pad_client, FALSE); - } - } - - g_free (real_uri); - e_uri_free (uri); - - if (!success) { - g_message ("gnome_calendar_open(): Could not issue the request to open the tasks folder"); - calendar_model_set_status_message ( - e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), NULL); - return FALSE; - } - - return TRUE; -} - -/* Tells the calendar to reload all config settings. - If initializing is TRUE it sets the pane positions as well. (We don't - want to reset the pane positions after the user clicks 'Apply' in the - preferences dialog.) */ -void -gnome_calendar_update_config_settings (GnomeCalendar *gcal, - gboolean initializing) -{ - GnomeCalendarPrivate *priv; - CalWeekdays working_days; - gint week_start_day, time_divisions; - gint start_hour, start_minute, end_hour, end_minute; - gboolean use_24_hour, show_event_end, compress_weekend; - char *location; - - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - working_days = calendar_config_get_working_days (); - /* CalWeekdays and EDayViewDays use the same bit-masks, so we can - use the same value. */ - e_day_view_set_working_days (E_DAY_VIEW (priv->day_view), - (EDayViewDays) working_days); - e_day_view_set_working_days (E_DAY_VIEW (priv->work_week_view), - (EDayViewDays) working_days); - - /* Note that this is 0 (Sun) to 6 (Sat). */ - week_start_day = calendar_config_get_week_start_day (); - - /* Convert it to 0 (Mon) to 6 (Sun), which is what we use. */ - week_start_day = (week_start_day + 6) % 7; - - e_day_view_set_week_start_day (E_DAY_VIEW (priv->day_view), - week_start_day); - e_day_view_set_week_start_day (E_DAY_VIEW (priv->work_week_view), - week_start_day); - e_week_view_set_week_start_day (E_WEEK_VIEW (priv->week_view), - week_start_day); - e_week_view_set_week_start_day (E_WEEK_VIEW (priv->month_view), - week_start_day); - - start_hour = calendar_config_get_day_start_hour (); - start_minute = calendar_config_get_day_start_minute (); - end_hour = calendar_config_get_day_end_hour (); - end_minute = calendar_config_get_day_end_minute (); - e_day_view_set_working_day (E_DAY_VIEW (priv->day_view), - start_hour, start_minute, - end_hour, end_minute); - e_day_view_set_working_day (E_DAY_VIEW (priv->work_week_view), - start_hour, start_minute, - end_hour, end_minute); - - use_24_hour = calendar_config_get_24_hour_format (); - e_day_view_set_24_hour_format (E_DAY_VIEW (priv->day_view), - use_24_hour); - e_day_view_set_24_hour_format (E_DAY_VIEW (priv->work_week_view), - use_24_hour); - e_week_view_set_24_hour_format (E_WEEK_VIEW (priv->week_view), - use_24_hour); - e_week_view_set_24_hour_format (E_WEEK_VIEW (priv->month_view), - use_24_hour); - - time_divisions = calendar_config_get_time_divisions (); - e_day_view_set_mins_per_row (E_DAY_VIEW (priv->day_view), - time_divisions); - e_day_view_set_mins_per_row (E_DAY_VIEW (priv->work_week_view), - time_divisions); - - show_event_end = calendar_config_get_show_event_end (); - e_day_view_set_show_event_end_times (E_DAY_VIEW (priv->day_view), - show_event_end); - e_day_view_set_show_event_end_times (E_DAY_VIEW (priv->work_week_view), - show_event_end); - e_week_view_set_show_event_end_times (E_WEEK_VIEW (priv->week_view), - show_event_end); - e_week_view_set_show_event_end_times (E_WEEK_VIEW (priv->month_view), - show_event_end); - - compress_weekend = calendar_config_get_compress_weekend (); - e_week_view_set_compress_weekend (E_WEEK_VIEW (priv->month_view), - compress_weekend); - - calendar_config_configure_e_calendar (E_CALENDAR (priv->date_navigator)); - - calendar_config_configure_e_calendar_table (E_CALENDAR_TABLE (priv->todo)); - - location = calendar_config_get_timezone (); - priv->zone = icaltimezone_get_builtin_timezone (location); - - if (priv->client - && cal_client_get_load_state (priv->client) == CAL_CLIENT_LOAD_LOADED) { - cal_client_set_default_timezone (priv->client, priv->zone); - } - if (priv->task_pad_client - && cal_client_get_load_state (priv->task_pad_client) == CAL_CLIENT_LOAD_LOADED) { - cal_client_set_default_timezone (priv->task_pad_client, - priv->zone); - } - - e_day_view_set_timezone (E_DAY_VIEW (priv->day_view), priv->zone); - e_day_view_set_timezone (E_DAY_VIEW (priv->work_week_view), priv->zone); - e_week_view_set_timezone (E_WEEK_VIEW (priv->week_view), priv->zone); - e_week_view_set_timezone (E_WEEK_VIEW (priv->month_view), priv->zone); - - if (initializing) { - priv->hpane_pos = calendar_config_get_hpane_pos (); - priv->vpane_pos = calendar_config_get_vpane_pos (); - priv->hpane_pos_month_view = calendar_config_get_month_hpane_pos (); - priv->vpane_pos_month_view = calendar_config_get_month_vpane_pos (); - } - - /* The range of days shown may have changed, so we update the date - navigator if needed. */ - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); -} - - -void -gnome_calendar_set_selected_time_range (GnomeCalendar *gcal, - time_t start_time, - time_t end_time) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - priv->selection_start_time = start_time; - priv->selection_end_time = end_time; - - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); -} - -/** - * gnome_calendar_get_selected_time_range: - * @gcal: A calendar view. - * @start_time: Return value for the start of the time selection. - * @end_time: Return value for the end of the time selection. - * - * Queries the time selection range on the calendar view. - **/ -void -gnome_calendar_get_selected_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time) -{ - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - if (start_time) - *start_time = priv->selection_start_time; - - if (end_time) - *end_time = priv->selection_end_time; -} - -void -gnome_calendar_edit_object (GnomeCalendar *gcal, CalComponent *comp, - gboolean meeting) -{ - GnomeCalendarPrivate *priv; - CompEditor *ce; - const char *uid; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (comp != NULL); - - priv = gcal->priv; - - cal_component_get_uid (comp, &uid); - - ce = e_comp_editor_registry_find (comp_editor_registry, uid); - if (!ce) { - EventEditor *ee; - - ee = event_editor_new (priv->client); - if (!ee) { - g_message ("gnome_calendar_edit_object(): Could not create the event editor"); - return; - } - ce = COMP_EDITOR (ee); - - comp_editor_edit_comp (ce, comp); - if (meeting) - event_editor_show_meeting (ee); - - e_comp_editor_registry_add (comp_editor_registry, ce, FALSE); - } - - comp_editor_focus (ce); -} - -/** - * gnome_calendar_new_appointment_for: - * @gcal: An Evolution calendar. - * @dtstart: a Unix time_t that marks the beginning of the appointment. - * @dtend: a Unix time_t that marks the end of the appointment. - * @all_day: if true, the dtstart and dtend are expanded to cover the entire - * day, and the event is set to TRANSPARENT. - * - * Opens an event editor dialog for a new appointment. - * - **/ -void -gnome_calendar_new_appointment_for (GnomeCalendar *cal, - time_t dtstart, time_t dtend, - gboolean all_day, - gboolean meeting) -{ - GnomeCalendarPrivate *priv; - struct icaltimetype itt; - CalComponentDateTime dt; - CalComponent *comp; - CalComponentTransparency transparency; - const char *category; - - g_return_if_fail (cal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (cal)); - - priv = cal->priv; - - dt.value = &itt; - if (all_day) - dt.tzid = NULL; - else - dt.tzid = icaltimezone_get_tzid (priv->zone); - - comp = cal_comp_event_new_with_defaults (priv->client); - - /* DTSTART, DTEND */ - - itt = icaltime_from_timet_with_zone (dtstart, FALSE, priv->zone); - if (all_day) { - itt.hour = itt.minute = itt.second = 0; - itt.is_date = TRUE; - } - cal_component_set_dtstart (comp, &dt); - - itt = icaltime_from_timet_with_zone (dtend, FALSE, priv->zone); - if (all_day) { - /* We round it up to the end of the day, unless it is already - set to midnight. */ - if (itt.hour != 0 || itt.minute != 0 || itt.second != 0) { - icaltime_adjust (&itt, 1, 0, 0, 0); - } - itt.hour = itt.minute = itt.second = 0; - itt.is_date = TRUE; - } - cal_component_set_dtend (comp, &dt); - - transparency = all_day ? CAL_COMPONENT_TRANSP_TRANSPARENT - : CAL_COMPONENT_TRANSP_OPAQUE; - cal_component_set_transparency (comp, transparency); - - - /* Category */ - - category = cal_search_bar_get_category (CAL_SEARCH_BAR (priv->search_bar)); - cal_component_set_categories (comp, category); - - /* Edit! */ - - cal_component_commit_sequence (comp); - - gnome_calendar_edit_object (cal, comp, meeting); - g_object_unref (comp); -} - -/** - * gnome_calendar_new_appointment: - * @gcal: An Evolution calendar. - * - * Opens an event editor dialog for a new appointment. The appointment's start - * and end times are set to the currently selected time range in the calendar - * views. - **/ -void -gnome_calendar_new_appointment (GnomeCalendar *gcal) -{ - time_t dtstart, dtend; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_get_current_time_range (gcal, &dtstart, &dtend); - gnome_calendar_new_appointment_for (gcal, dtstart, dtend, FALSE, FALSE); -} - -/** - * gnome_calendar_new_task: - * @gcal: An Evolution calendar. - * - * Opens a task editor dialog for a new task. - **/ -void -gnome_calendar_new_task (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - TaskEditor *tedit; - CalComponent *comp; - const char *category; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - tedit = task_editor_new (priv->task_pad_client); - - comp = cal_comp_task_new_with_defaults (priv->client); - - category = cal_search_bar_get_category (CAL_SEARCH_BAR (priv->search_bar)); - cal_component_set_categories (comp, category); - - comp_editor_edit_comp (COMP_EDITOR (tedit), comp); - g_object_unref (comp); - - comp_editor_focus (COMP_EDITOR (tedit)); -} - - -/* Returns the selected time range for the current view. Note that this may be - different from the fields in the GnomeCalendar, since the view may clip - this or choose a more appropriate time. */ -void -gnome_calendar_get_current_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - e_day_view_get_selected_time_range (E_DAY_VIEW (priv->day_view), - start_time, end_time); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - e_day_view_get_selected_time_range (E_DAY_VIEW (priv->work_week_view), - start_time, end_time); - break; - - case GNOME_CAL_WEEK_VIEW: - e_week_view_get_selected_time_range (E_WEEK_VIEW (priv->week_view), - start_time, end_time); - break; - - case GNOME_CAL_MONTH_VIEW: - e_week_view_get_selected_time_range (E_WEEK_VIEW (priv->month_view), - start_time, end_time); - break; - - default: - g_message ("My penguin is gone!"); - g_assert_not_reached (); - } -} - - -/* Gets the visible time range for the current view. Returns FALSE if no - time range has been set yet. */ -gboolean -gnome_calendar_get_visible_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time) -{ - GnomeCalendarPrivate *priv; - gboolean retval = FALSE; - - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), FALSE); - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - retval = e_day_view_get_visible_time_range (E_DAY_VIEW (priv->day_view), start_time, end_time); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - retval = e_day_view_get_visible_time_range (E_DAY_VIEW (priv->work_week_view), start_time, end_time); - break; - - case GNOME_CAL_WEEK_VIEW: - retval = e_week_view_get_visible_time_range (E_WEEK_VIEW (priv->week_view), start_time, end_time); - break; - - case GNOME_CAL_MONTH_VIEW: - retval = e_week_view_get_visible_time_range (E_WEEK_VIEW (priv->month_view), start_time, end_time); - break; - - default: - g_assert_not_reached (); - } - - return retval; -} - - - -static void -get_days_shown (GnomeCalendar *gcal, GDate *start_date, gint *days_shown) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - time_to_gdate_with_zone (start_date, - E_DAY_VIEW (priv->day_view)->lower, - priv->zone); - *days_shown = e_day_view_get_days_shown (E_DAY_VIEW (priv->day_view)); - break; - - case GNOME_CAL_WORK_WEEK_VIEW: - time_to_gdate_with_zone (start_date, - E_DAY_VIEW (priv->work_week_view)->lower, - priv->zone); - *days_shown = e_day_view_get_days_shown (E_DAY_VIEW (priv->work_week_view)); - break; - - case GNOME_CAL_WEEK_VIEW: - *start_date = E_WEEK_VIEW (priv->week_view)->first_day_shown; - if (e_week_view_get_multi_week_view (E_WEEK_VIEW (priv->week_view))) - *days_shown = e_week_view_get_weeks_shown ( - E_WEEK_VIEW (priv->week_view)) * 7; - else - *days_shown = 7; - - break; - - case GNOME_CAL_MONTH_VIEW: - *start_date = E_WEEK_VIEW (priv->month_view)->first_day_shown; - if (e_week_view_get_multi_week_view (E_WEEK_VIEW (priv->month_view))) - *days_shown = e_week_view_get_weeks_shown ( - E_WEEK_VIEW (priv->month_view)) * 7; - else - *days_shown = 7; - - break; - - default: - g_assert_not_reached (); - } -} - - -/* This updates the month shown and the days selected in the calendar, if - necessary. */ -static void -gnome_calendar_update_date_navigator (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GDate start_date, end_date; - gint days_shown; - - priv = gcal->priv; - - /* If the ECalendar isn't visible, we just return. */ - if (!GTK_WIDGET_VISIBLE (priv->date_navigator)) - return; - - get_days_shown (gcal, &start_date, &days_shown); - - end_date = start_date; - g_date_add_days (&end_date, days_shown - 1); - - e_calendar_item_set_selection (priv->date_navigator->calitem, - &start_date, &end_date); -} - - -static void -gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, - GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GDate start_date, end_date, new_start_date, new_end_date; - gint days_shown, new_days_shown; - gboolean starts_on_week_start_day; - struct icaltimetype tt; - - priv = gcal->priv; - - starts_on_week_start_day = FALSE; - - get_days_shown (gcal, &start_date, &days_shown); - - end_date = start_date; - g_date_add_days (&end_date, days_shown - 1); - - e_calendar_item_get_selection (calitem, &new_start_date, &new_end_date); - - /* If the selection hasn't changed just return. */ - if (!g_date_compare (&start_date, &new_start_date) - && !g_date_compare (&end_date, &new_end_date)) - return; - - new_days_shown = g_date_julian (&new_end_date) - g_date_julian (&new_start_date) + 1; - - /* If a complete week is selected we show the Week view. - Note that if weekends are compressed and the week start day is set - to Sunday we don't actually show complete weeks in the Week view, - so this may need tweaking. */ - if (g_date_weekday (&new_start_date) % 7 == calendar_config_get_week_start_day ()) - starts_on_week_start_day = TRUE; - - /* Update selection to be in the new time range */ - tt = icaltime_null_time (); - tt.year = g_date_year (&new_start_date); - tt.month = g_date_month (&new_start_date); - tt.day = g_date_day (&new_start_date); - priv->selection_start_time = icaltime_as_timet_with_zone (tt, priv->zone); - icaltime_adjust (&tt, 1, 0, 0, 0); - priv->selection_end_time = icaltime_as_timet_with_zone (tt, priv->zone); - - /* Switch views as appropriate, and change the number of days or weeks - shown. */ - if (new_days_shown > 9) { - e_week_view_set_weeks_shown (E_WEEK_VIEW (priv->month_view), - (new_days_shown + 6) / 7); - e_week_view_set_first_day_shown (E_WEEK_VIEW (priv->month_view), &new_start_date); - - set_view (gcal, GNOME_CAL_MONTH_VIEW, TRUE, FALSE); - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); - } else if (new_days_shown == 7 && starts_on_week_start_day) { - e_week_view_set_first_day_shown (E_WEEK_VIEW (priv->week_view), &new_start_date); - - set_view (gcal, GNOME_CAL_WEEK_VIEW, TRUE, FALSE); - gnome_calendar_update_date_navigator (gcal); - gnome_calendar_notify_dates_shown_changed (gcal); - } else { - e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), new_days_shown); - - if (new_days_shown == 5 && priv->current_view_type == GNOME_CAL_WORK_WEEK_VIEW) - gnome_calendar_set_view (gcal, GNOME_CAL_WORK_WEEK_VIEW, TRUE, FALSE); - else - gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, TRUE, FALSE); - - } - - focus_current_view (gcal); -} - - -static void -gnome_calendar_on_date_navigator_date_range_changed (ECalendarItem *calitem, - GnomeCalendar *gcal) -{ - update_query (gcal); -} - -static void -gnome_calendar_hpane_realized (GtkWidget *w, GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos_month_view); - } else { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos); - } -} - -static void -gnome_calendar_vpane_realized (GtkWidget *w, GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos_month_view); - } else { - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos); - } -} - -static gboolean -gnome_calendar_vpane_resized (GtkWidget *w, GdkEventButton *e, GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - priv->vpane_pos_month_view = gtk_paned_get_position (priv->vpane); - calendar_config_set_month_vpane_pos (priv->vpane_pos_month_view); - } else { - priv->vpane_pos = gtk_paned_get_position (priv->vpane); - calendar_config_set_vpane_pos (priv->vpane_pos); - } - - return FALSE; -} - -static gboolean -gnome_calendar_hpane_resized (GtkWidget *w, GdkEventButton *e, GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - priv->hpane_pos_month_view = gtk_paned_get_position (priv->hpane); - calendar_config_set_month_hpane_pos (priv->hpane_pos_month_view); - } else { - priv->hpane_pos = gtk_paned_get_position (priv->hpane); - calendar_config_set_hpane_pos (priv->hpane_pos); - } - - return FALSE; -} - -void -gnome_calendar_cut_clipboard (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - FocusLocation location; - - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW : - e_day_view_cut_clipboard (E_DAY_VIEW (priv->day_view)); - break; - case GNOME_CAL_WORK_WEEK_VIEW : - e_day_view_cut_clipboard (E_DAY_VIEW (priv->work_week_view)); - break; - case GNOME_CAL_WEEK_VIEW : - e_week_view_cut_clipboard (E_WEEK_VIEW (priv->week_view)); - break; - case GNOME_CAL_MONTH_VIEW : - e_week_view_cut_clipboard (E_WEEK_VIEW (priv->month_view)); - break; - default: - g_assert_not_reached (); - } - } else if (location == FOCUS_TASKPAD) - e_calendar_table_cut_clipboard (E_CALENDAR_TABLE (priv->todo)); - else - g_assert_not_reached (); -} - -void -gnome_calendar_copy_clipboard (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - FocusLocation location; - - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW : - e_day_view_copy_clipboard (E_DAY_VIEW (priv->day_view)); - break; - case GNOME_CAL_WORK_WEEK_VIEW : - e_day_view_copy_clipboard (E_DAY_VIEW (priv->work_week_view)); - break; - case GNOME_CAL_WEEK_VIEW : - e_week_view_copy_clipboard (E_WEEK_VIEW (priv->week_view)); - break; - case GNOME_CAL_MONTH_VIEW : - e_week_view_copy_clipboard (E_WEEK_VIEW (priv->month_view)); - break; - default: - g_assert_not_reached (); - } - } else if (location == FOCUS_TASKPAD) - e_calendar_table_copy_clipboard (E_CALENDAR_TABLE (priv->todo)); - else - g_assert_not_reached (); -} - -void -gnome_calendar_paste_clipboard (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - FocusLocation location; - - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW : - e_day_view_paste_clipboard (E_DAY_VIEW (priv->day_view)); - break; - case GNOME_CAL_WORK_WEEK_VIEW : - e_day_view_paste_clipboard (E_DAY_VIEW (priv->work_week_view)); - break; - case GNOME_CAL_WEEK_VIEW : - e_week_view_paste_clipboard (E_WEEK_VIEW (priv->week_view)); - break; - case GNOME_CAL_MONTH_VIEW : - e_week_view_paste_clipboard (E_WEEK_VIEW (priv->month_view)); - break; - } - } else if (location == FOCUS_TASKPAD) - e_calendar_table_paste_clipboard (E_CALENDAR_TABLE (priv->todo)); - else - g_assert_not_reached (); -} - - -/* Get the current timezone. */ -icaltimezone* -gnome_calendar_get_timezone (GnomeCalendar *gcal) -{ - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - return gcal->priv->zone; -} - - -static void -gnome_calendar_notify_dates_shown_changed (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - time_t start_time, end_time; - - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - /* If no time range is set yet, just return. */ - if (!gnome_calendar_get_visible_time_range (gcal, &start_time, - &end_time)) - return; - - /* We check if the visible date range has changed, and only emit the - signal if it has. (This makes sure we only change the folder title - bar label in the shell when we need to.) */ - if (priv->visible_start != start_time - || priv->visible_end != end_time) { - priv->visible_start = start_time; - priv->visible_end = end_time; - - gtk_signal_emit (GTK_OBJECT (gcal), - gnome_calendar_signals[DATES_SHOWN_CHANGED]); - } -} - - -/* Returns the number of selected events (0 or 1 at present). */ -gint -gnome_calendar_get_num_events_selected (GnomeCalendar *gcal) -{ - GtkWidget *view; - gint retval = 0; - - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), 0); - - view = gnome_calendar_get_current_view_widget (gcal); - if (E_IS_DAY_VIEW (view)) - retval = e_day_view_get_num_events_selected (E_DAY_VIEW (view)); - else - retval = e_week_view_get_num_events_selected (E_WEEK_VIEW (view)); - - return retval; -} - -/** - * gnome_calendar_get_num_tasks_selected: - * @gcal: A calendar view. - * - * Queries the number of tasks that are currently selected in the task pad of a - * calendar view. - * - * Return value: Number of selected tasks. - **/ -gint -gnome_calendar_get_num_tasks_selected (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - ETable *etable; - - g_return_val_if_fail (gcal != NULL, -1); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), -1); - - priv = gcal->priv; - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - return e_table_selected_count (etable); -} - - -void -gnome_calendar_delete_selection (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - FocusLocation location; - GtkWidget *view; - - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - view = gnome_calendar_get_current_view_widget (gcal); - - if (E_IS_DAY_VIEW (view)) - e_day_view_delete_event (E_DAY_VIEW (view)); - else - e_week_view_delete_event (E_WEEK_VIEW (view)); - } else if (location == FOCUS_TASKPAD) - e_calendar_table_delete_selected (E_CALENDAR_TABLE (priv->todo)); - else - g_assert_not_reached (); -} - -void -gnome_calendar_delete_selected_occurrence (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - FocusLocation location; - GtkWidget *view; - - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - - view = gnome_calendar_get_current_view_widget (gcal); - - if (E_IS_DAY_VIEW (view)) - e_day_view_delete_occurrence (E_DAY_VIEW (view)); - else - e_week_view_delete_occurrence (E_WEEK_VIEW (view)); - } -} - -ECalendarTable* -gnome_calendar_get_task_pad (GnomeCalendar *gcal) -{ - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - return E_CALENDAR_TABLE (gcal->priv->todo); -} - diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h deleted file mode 100644 index 52c2cf5176..0000000000 --- a/calendar/gui/gnome-cal.h +++ /dev/null @@ -1,177 +0,0 @@ -/* Evolution calendar - Main calendar view widget - * - * Copyright (C) 1998 The Free Software Foundation - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Seth Alves <alves@hungry.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 GNOME_CALENDAR_APP_H -#define GNOME_CALENDAR_APP_H - -#include <time.h> -#include <gtk/gtkvbox.h> -#include <bonobo/bonobo-ui-component.h> -#include <gal/widgets/e-popup-menu.h> -#include <widgets/misc/e-calendar.h> -#include <cal-client/cal-client.h> - -#include "e-calendar-table.h" - -G_BEGIN_DECLS - - - -#define GNOME_TYPE_CALENDAR (gnome_calendar_get_type ()) -#define GNOME_CALENDAR(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_CALENDAR, GnomeCalendar)) -#define GNOME_CALENDAR_CLASS(klass) (GTK_CHECK_CAST_CLASS ((klass), GNOME_TYPE_CALENDAR, \ - GnomeCalendarClass)) -#define GNOME_IS_CALENDAR(obj) (GTK_CHECK_TYPE ((obj), GNOME_TYPE_CALENDAR)) -#define GNOME_IS_CALENDAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CALENDAR)) - -typedef struct _GnomeCalendar GnomeCalendar; -typedef struct _GnomeCalendarClass GnomeCalendarClass; -typedef struct _GnomeCalendarPrivate GnomeCalendarPrivate; - -/* View types */ -typedef enum { - GNOME_CAL_DAY_VIEW, - GNOME_CAL_WORK_WEEK_VIEW, - GNOME_CAL_WEEK_VIEW, - GNOME_CAL_MONTH_VIEW -} GnomeCalendarViewType; - -struct _GnomeCalendar { - GtkVBox vbox; - - /* Private data */ - GnomeCalendarPrivate *priv; -}; - -struct _GnomeCalendarClass { - GtkVBoxClass parent_class; - - /* Notification signals */ - void (* dates_shown_changed) (GnomeCalendar *gcal); - - void (* calendar_selection_changed) (GnomeCalendar *gcal); - void (* taskpad_selection_changed) (GnomeCalendar *gcal); - - void (* calendar_focus_change) (GnomeCalendar *gcal, gboolean in); - void (* taskpad_focus_change) (GnomeCalendar *gcal, gboolean in); -}; - - -GtkType gnome_calendar_get_type (void); -GtkWidget *gnome_calendar_construct (GnomeCalendar *gcal); - -GtkWidget *gnome_calendar_new (void); - -void gnome_calendar_set_ui_component (GnomeCalendar *cal, - BonoboUIComponent *ui_component); - -ECalendarTable *gnome_calendar_get_task_pad (GnomeCalendar *gcal); - -CalClient *gnome_calendar_get_cal_client (GnomeCalendar *gcal); -CalClient *gnome_calendar_get_task_pad_cal_client(GnomeCalendar *gcal); - -gboolean gnome_calendar_open (GnomeCalendar *gcal, const char *str_uri); - -void gnome_calendar_set_query (GnomeCalendar *gcal, const char *sexp); - -void gnome_calendar_next (GnomeCalendar *gcal); -void gnome_calendar_previous (GnomeCalendar *gcal); -void gnome_calendar_goto (GnomeCalendar *gcal, - time_t new_time); -void gnome_calendar_dayjump (GnomeCalendar *gcal, - time_t time); -/* Jumps to the current day */ -void gnome_calendar_goto_today (GnomeCalendar *gcal); - -GnomeCalendarViewType gnome_calendar_get_view (GnomeCalendar *gcal); -void gnome_calendar_set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type, - gboolean range_selected, gboolean grab_focus); - -GtkWidget *gnome_calendar_get_current_view_widget (GnomeCalendar *gcal); -void gnome_calendar_setup_view_menus (GnomeCalendar *gcal, BonoboUIComponent *uic); -void gnome_calendar_discard_view_menus (GnomeCalendar *gcal); - -EPopupMenu *gnome_calendar_setup_view_popup (GnomeCalendar *gcal); -void gnome_calendar_discard_view_popup (GnomeCalendar *gcal, EPopupMenu *popup); - -void gnome_calendar_set_selected_time_range (GnomeCalendar *gcal, - time_t start_time, - time_t end_time); -void gnome_calendar_get_selected_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time); - -void gnome_calendar_edit_object (GnomeCalendar *gcal, - CalComponent *comp, - gboolean meeting); - -void gnome_calendar_new_appointment (GnomeCalendar *gcal); -void gnome_calendar_new_appointment_for (GnomeCalendar *cal, - time_t dtstart, time_t dtend, - gboolean all_day, - gboolean meeting); - -void gnome_calendar_new_task (GnomeCalendar *gcal); - -/* Returns the selected time range for the current view. Note that this may be - different from the fields in the GnomeCalendar, since the view may clip - this or choose a more appropriate time. */ -void gnome_calendar_get_current_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time); - -/* Gets the visible time range for the current view. Returns FALSE if no - time range has been set yet. */ -gboolean gnome_calendar_get_visible_time_range (GnomeCalendar *gcal, - time_t *start_time, - time_t *end_time); - -/* Returns the number of selected events (0 or 1 at present). */ -gint gnome_calendar_get_num_events_selected (GnomeCalendar *gcal); - -/* Returns the number of selected tasks */ -gint gnome_calendar_get_num_tasks_selected (GnomeCalendar *gcal); - -/* Tells the calendar to reload all config settings. initializing should be - TRUE when we are setting the config settings for the first time. */ -void gnome_calendar_update_config_settings (GnomeCalendar *gcal, - gboolean initializing); - -/* Get the current timezone. */ -icaltimezone *gnome_calendar_get_timezone (GnomeCalendar *gcal); - - -/* Clipboard operations */ -void gnome_calendar_cut_clipboard (GnomeCalendar *gcal); -void gnome_calendar_copy_clipboard (GnomeCalendar *gcal); -void gnome_calendar_paste_clipboard (GnomeCalendar *gcal); - -void gnome_calendar_delete_selection (GnomeCalendar *gcal); -void gnome_calendar_delete_selected_occurrence (GnomeCalendar *gcal); - - - -G_END_DECLS - -#endif diff --git a/calendar/gui/gnome-calendar-conduit.png b/calendar/gui/gnome-calendar-conduit.png Binary files differdeleted file mode 100644 index e867ba90b2..0000000000 --- a/calendar/gui/gnome-calendar-conduit.png +++ /dev/null diff --git a/calendar/gui/goto-dialog.glade b/calendar/gui/goto-dialog.glade deleted file mode 100644 index b268e03294..0000000000 --- a/calendar/gui/goto-dialog.glade +++ /dev/null @@ -1,225 +0,0 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkDialog" id="goto-dialog"> - <property name="title" translatable="yes">Go To Date</property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - <property name="has_separator">True</property> - - <child internal-child="vbox"> - <widget class="GtkVBox" id="dialog-vbox1"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">8</property> - - <child internal-child="action_area"> - <widget class="GtkHButtonBox" id="dialog-action_area1"> - <property name="visible">True</property> - <property name="layout_style">GTK_BUTTONBOX_END</property> - - <child> - <widget class="GtkButton" id="button4"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Go To Today</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">0</property> - </widget> - </child> - - <child> - <widget class="GtkButton" id="button5"> - <property name="visible">True</property> - <property name="can_default">True</property> - <property name="can_focus">True</property> - <property name="label">gtk-cancel</property> - <property name="use_stock">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="response_id">-6</property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">GTK_PACK_END</property> - </packing> - </child> - - <child> - <widget class="GtkVBox" id="vbox"> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">4</property> - - <child> - <widget class="GtkHBox" id="hbox12"> - <property name="visible">True</property> - <property name="homogeneous">True</property> - <property name="spacing">4</property> - - <child> - <widget class="GtkOptionMenu" id="month"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child internal-child="menu"> - <widget class="GtkMenu" id="convertwidget1"> - <property name="visible">True</property> - - <child> - <widget class="GtkMenuItem" id="convertwidget2"> - <property name="visible">True</property> - <property name="label" translatable="yes">January</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget3"> - <property name="visible">True</property> - <property name="label" translatable="yes">February</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget4"> - <property name="visible">True</property> - <property name="label" translatable="yes">March</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget5"> - <property name="visible">True</property> - <property name="label" translatable="yes">April</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget6"> - <property name="visible">True</property> - <property name="label" translatable="yes">May</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget7"> - <property name="visible">True</property> - <property name="label" translatable="yes">June</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget8"> - <property name="visible">True</property> - <property name="label" translatable="yes">July</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget9"> - <property name="visible">True</property> - <property name="label" translatable="yes">August</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget10"> - <property name="visible">True</property> - <property name="label" translatable="yes">September</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget11"> - <property name="visible">True</property> - <property name="label" translatable="yes">October</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget12"> - <property name="visible">True</property> - <property name="label" translatable="yes">November</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="convertwidget13"> - <property name="visible">True</property> - <property name="label" translatable="yes">December</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - - <child> - <widget class="GtkSpinButton" id="year"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">True</property> - <property name="update_policy">GTK_UPDATE_IF_VALID</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">1969 1969 2038 1 5 10</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <placeholder/> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c deleted file mode 100644 index 2ce74507d5..0000000000 --- a/calendar/gui/goto.c +++ /dev/null @@ -1,253 +0,0 @@ -/* Go to date dialog for Evolution - * - * Copyright (C) 1998 Red Hat, Inc. - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena <federico@ximian.com> - * JP Rosevear <jpr@ximian.com> - */ - -#include <config.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkspinbutton.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkdialog.h> -#include <libgnomeui/gnome-dialog.h> -#include <glade/glade.h> -#include "calendar-commands.h" -#include "calendar-config.h" -#include "tag-calendar.h" -#include "goto.h" - -typedef struct -{ - GladeXML *xml; - GtkWidget *dialog; - - GtkWidget *month; - GtkWidget *year; - ECalendar *ecal; - GtkWidget *vbox; - - GnomeCalendar *gcal; - gint year_val; - gint month_val; - gint day_val; - -} GoToDialog; - -GoToDialog *dlg = NULL; - -/* Callback used when the year adjustment is changed */ -static void -year_changed (GtkAdjustment *adj, gpointer data) -{ - GoToDialog *dlg = data; - - dlg->year_val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dlg->year)); - e_calendar_item_set_first_month (dlg->ecal->calitem, dlg->year_val, dlg->month_val); -} - -/* Callback used when a month button is toggled */ -static void -month_changed (GtkToggleButton *toggle, gpointer data) -{ - GoToDialog *dlg = data; - GtkWidget *menu, *active; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (dlg->month)); - active = gtk_menu_get_active (GTK_MENU (menu)); - dlg->month_val = g_list_index (GTK_MENU_SHELL (menu)->children, active); - - e_calendar_item_set_first_month (dlg->ecal->calitem, dlg->year_val, dlg->month_val); -} - -static void -ecal_date_range_changed (ECalendarItem *calitem, gpointer user_data) -{ - GoToDialog *dlg = user_data; - CalClient *client; - - client = gnome_calendar_get_cal_client (dlg->gcal); - if (client) - tag_calendar_by_client (dlg->ecal, client); -} - -/* Event handler for day groups in the month item. A button press makes the calendar jump to the - * selected day and destroys the Go-to dialog box. - */ -static void -ecal_event (ECalendarItem *calitem, gpointer user_data) -{ - GoToDialog *dlg = user_data; - GDate start_date, end_date; - struct icaltimetype tt = icaltime_null_time (); - time_t et; - - e_calendar_item_get_selection (calitem, &start_date, &end_date); - - tt.year = g_date_year (&start_date); - tt.month = g_date_month (&start_date); - tt.day = g_date_day (&start_date); - - et = icaltime_as_timet_with_zone (tt, gnome_calendar_get_timezone (dlg->gcal)); - - gnome_calendar_goto (dlg->gcal, et); - - gtk_dialog_response (GTK_DIALOG (dlg->dialog), GTK_RESPONSE_NONE); - /* gnome_dialog_close (GNOME_DIALOG (dlg->dialog)); */ -} - -/* Returns the current time, for the ECalendarItem. */ -static struct tm -get_current_time (ECalendarItem *calitem, gpointer data) -{ - char *location; - icaltimezone *zone; - struct tm tmp_tm = { 0 }; - struct icaltimetype tt; - - /* Get the current timezone. */ - location = calendar_config_get_timezone (); - zone = icaltimezone_get_builtin_timezone (location); - - tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone); - - /* Now copy it to the struct tm and return it. */ - tmp_tm.tm_year = tt.year - 1900; - tmp_tm.tm_mon = tt.month - 1; - tmp_tm.tm_mday = tt.day; - tmp_tm.tm_hour = tt.hour; - tmp_tm.tm_min = tt.minute; - tmp_tm.tm_sec = tt.second; - tmp_tm.tm_isdst = -1; - - return tmp_tm; -} - -/* Creates the ecalendar */ -static void -create_ecal (GoToDialog *dlg) -{ - ECalendarItem *calitem; - - dlg->ecal = E_CALENDAR (e_calendar_new ()); - calitem = dlg->ecal->calitem; - - e_calendar_item_set_display_popup (calitem, FALSE); - gtk_widget_show (GTK_WIDGET (dlg->ecal)); - gtk_box_pack_start (GTK_BOX (dlg->vbox), GTK_WIDGET (dlg->ecal), TRUE, TRUE, 0); - - e_calendar_item_set_first_month (calitem, dlg->year_val, dlg->month_val); - e_calendar_item_set_get_time_callback (calitem, - get_current_time, - dlg, NULL); - - ecal_date_range_changed (calitem, dlg); -} - -static void -goto_today (GoToDialog *dlg) -{ - gnome_calendar_goto_today (dlg->gcal); -} - -/* Gets the widgets from the XML file and returns if they are all available. */ -static gboolean -get_widgets (GoToDialog *dlg) -{ -#define GW(name) glade_xml_get_widget (dlg->xml, name) - - dlg->dialog = GW ("goto-dialog"); - - dlg->month = GW ("month"); - dlg->year = GW ("year"); - dlg->vbox = GW ("vbox"); - -#undef GW - - return (dlg->dialog - && dlg->month - && dlg->year - && dlg->vbox); -} - -static void -goto_dialog_init_widgets (GoToDialog *dlg) -{ - GtkWidget *menu; - GtkAdjustment *adj; - GList *l; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (dlg->month)); - for (l = GTK_MENU_SHELL (menu)->children; l != NULL; l = l->next) - g_signal_connect (menu, "selection_done", G_CALLBACK (month_changed), dlg); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (dlg->year)); - g_signal_connect (adj, "value_changed", G_CALLBACK (year_changed), dlg); - - g_signal_connect (dlg->ecal->calitem, "date_range_changed", G_CALLBACK (ecal_date_range_changed), dlg); - g_signal_connect (dlg->ecal->calitem, "selection_changed", G_CALLBACK (ecal_event), dlg); -} - -/* Creates a "goto date" dialog and runs it */ -void -goto_dialog (GnomeCalendar *gcal) -{ - GtkWidget *menu; - time_t start_time; - struct icaltimetype tt; - int b; - - if (dlg) { - return; - } - - dlg = g_new0 (GoToDialog, 1); - - /* Load the content widgets */ - dlg->xml = glade_xml_new (EVOLUTION_GLADEDIR "/goto-dialog.glade", NULL, NULL); - if (!dlg->xml) { - g_message ("goto_dialog(): Could not load the Glade XML file!"); - g_free (dlg); - return; - } - - if (!get_widgets (dlg)) { - g_message ("goto_dialog(): Could not find all widgets in the XML file!"); - g_free (dlg); - return; - } - dlg->gcal = gcal; - - gnome_calendar_get_selected_time_range (dlg->gcal, &start_time, NULL); - tt = icaltime_from_timet_with_zone (start_time, FALSE, gnome_calendar_get_timezone (gcal)); - dlg->year_val = tt.year; - dlg->month_val = tt.month - 1; - dlg->day_val = tt.day; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (dlg->month)); - gtk_option_menu_set_history (GTK_OPTION_MENU (dlg->month), dlg->month_val); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->year), dlg->year_val); - - create_ecal (dlg); - - goto_dialog_init_widgets (dlg); - - gtk_window_set_transient_for (GTK_WINDOW (dlg->dialog), - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); - - b = gtk_dialog_run (GTK_DIALOG (dlg->dialog)); - gtk_widget_destroy (dlg->dialog); - - if (b == 0) - goto_today (dlg); - - g_object_unref (dlg->xml); - g_free (dlg); - dlg = NULL; -} diff --git a/calendar/gui/goto.h b/calendar/gui/goto.h deleted file mode 100644 index 9ecfeeeb83..0000000000 --- a/calendar/gui/goto.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Evolution calendar - Go To Date dialog - * - * Copyright (C) 1998 Red Hat, Inc. - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena <federico@ximian.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 GOTO_DIALOG_H -#define GOTO_DIALOG_H - -#include "gnome-cal.h" - -void goto_dialog (GnomeCalendar *gcal); - -#endif diff --git a/calendar/gui/itip-bonobo-control.c b/calendar/gui/itip-bonobo-control.c deleted file mode 100644 index 3f020afce4..0000000000 --- a/calendar/gui/itip-bonobo-control.c +++ /dev/null @@ -1,265 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution calendar - Control for displaying iTIP mail messages - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Jesse Pavel <jpavel@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <string.h> -#include <glib.h> -#include <gtk/gtkobject.h> -#include <gtk/gtkwidget.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> -#include <bonobo/bonobo-persist-stream.h> -#include <bonobo/bonobo-stream-client.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-exception.h> -#include <ical.h> - -#include "e-itip-control.h" -#include "itip-bonobo-control.h" - -extern gchar *evolution_dir; - -enum E_ITIP_BONOBO_ARGS { - FROM_ADDRESS_ARG_ID, - VIEW_ONLY_ARG_ID -}; - -/* - * Bonobo::PersistStream - * - * These two functions implement the Bonobo::PersistStream load and - * save methods which allow data to be loaded into and out of the - * BonoboObject. - */ - -static char * -stream_read (Bonobo_Stream stream) -{ - Bonobo_Stream_iobuf *buffer; - CORBA_Environment ev; - gchar *data = NULL; - gint length = 0; - - CORBA_exception_init (&ev); - do { -#define READ_CHUNK_SIZE 65536 - Bonobo_Stream_read (stream, READ_CHUNK_SIZE, - &buffer, &ev); - - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return NULL; - } - - if (buffer->_length <= 0) - break; - - data = g_realloc (data, length + buffer->_length + 1); - memcpy (data + length, buffer->_buffer, buffer->_length); - length += buffer->_length; - data[length] = '\0'; - - CORBA_free (buffer); -#undef READ_CHUNK_SIZE - } while (1); - - CORBA_free (buffer); - CORBA_exception_free (&ev); - - if (data == NULL) - data = g_strdup(""); - - return data; -} /* stream_read */ - -/* - * This function implements the Bonobo::PersistStream:load method. - */ -typedef struct { - EItipControl *itip; - char *text; -} idle_data; - -static gboolean -set_data_idle_cb (gpointer data) -{ - idle_data *id = data; - - e_itip_control_set_data (id->itip, id->text); - g_object_unref (id->itip); - g_free (id->text); - g_free (id); - - return FALSE; -} - -static void -pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream, - Bonobo_Persist_ContentType type, void *data, - CORBA_Environment *ev) -{ - EItipControl *itip = data; - idle_data *id; - - if (type && g_strcasecmp (type, "text/calendar") != 0 && - g_strcasecmp (type, "text/x-calendar") != 0) { - bonobo_exception_set (ev, ex_Bonobo_Persist_WrongDataType); - return; - } - - id = g_new0 (idle_data, 1); - if ((id->text = stream_read (stream)) == NULL) { - bonobo_exception_set (ev, ex_Bonobo_Persist_FileNotFound); - g_free (id); - return; - } - g_object_ref (itip); - id->itip = itip; - - g_idle_add (set_data_idle_cb, id); -} -/* - * This function implements the Bonobo::PersistStream:save method. - */ -static void -pstream_save (BonoboPersistStream *ps, const Bonobo_Stream stream, - Bonobo_Persist_ContentType type, void *data, - CORBA_Environment *ev) -{ - EItipControl *itip = data; - gchar *text; - gint len; - - if (type && g_strcasecmp (type, "text/calendar") != 0 && - g_strcasecmp (type, "text/x-calendar") != 0) { - bonobo_exception_set (ev, ex_Bonobo_Persist_WrongDataType); - return; - } - - text = e_itip_control_get_data (itip); - len = e_itip_control_get_data_size (itip); - - bonobo_stream_client_write (stream, text, len, ev); - g_free (text); -} /* pstream_save */ - -static CORBA_long -pstream_get_max_size (BonoboPersistStream *ps, void *data, - CORBA_Environment *ev) -{ - EItipControl *itip = data; - gint len; - - len = e_itip_control_get_data_size (itip); - - if (len > 0) - return len; - - return 0L; -} - -static Bonobo_Persist_ContentTypeList * -pstream_get_content_types (BonoboPersistStream *ps, void *closure, - CORBA_Environment *ev) -{ - return bonobo_persist_generate_content_types (2, "text/calendar", "text/x-calendar"); -} - -static void -get_prop (BonoboPropertyBag *bag, - BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - EItipControl *itip = user_data; - - switch (arg_id) { - case FROM_ADDRESS_ARG_ID: - BONOBO_ARG_SET_STRING (arg, e_itip_control_get_from_address (itip)); - break; - case VIEW_ONLY_ARG_ID: - BONOBO_ARG_SET_BOOLEAN (arg, e_itip_control_get_view_only (itip)); - break; - } -} - -static void -set_prop ( BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - EItipControl *itip = user_data; - - switch (arg_id) { - case FROM_ADDRESS_ARG_ID: - e_itip_control_set_from_address (itip, BONOBO_ARG_GET_STRING (arg)); - break; - case VIEW_ONLY_ARG_ID: - e_itip_control_set_view_only (itip, BONOBO_ARG_GET_BOOLEAN (arg)); - break; - } -} - - -BonoboControl * -itip_bonobo_control_new (void) -{ - BonoboControl *control; - BonoboPropertyBag *prop_bag; - BonoboPersistStream *stream; - GtkWidget *itip; - - itip = e_itip_control_new (); - gtk_widget_show (itip); - control = bonobo_control_new (itip); - - /* create a property bag */ - prop_bag = bonobo_property_bag_new (get_prop, set_prop, itip); - bonobo_property_bag_add (prop_bag, "from_address", FROM_ADDRESS_ARG_ID, BONOBO_ARG_STRING, NULL, - "from_address", 0 ); - bonobo_property_bag_add (prop_bag, "view_only", VIEW_ONLY_ARG_ID, BONOBO_ARG_BOOLEAN, NULL, - "view_only", 0 ); - - bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (prop_bag)), NULL); - bonobo_object_unref (BONOBO_OBJECT (prop_bag)); - - bonobo_control_set_automerge (control, TRUE); - - stream = bonobo_persist_stream_new (pstream_load, pstream_save, - pstream_get_content_types, - "OAFIID:GNOME_Evolution_Calendar_iTip_Control", - itip); - - if (stream == NULL) { - bonobo_object_unref (BONOBO_OBJECT (control)); - return NULL; - } - - bonobo_object_add_interface (BONOBO_OBJECT (control), - BONOBO_OBJECT (stream)); - - return control; -} diff --git a/calendar/gui/itip-bonobo-control.h b/calendar/gui/itip-bonobo-control.h deleted file mode 100644 index 11b33e6602..0000000000 --- a/calendar/gui/itip-bonobo-control.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Evolution calendar - Control for displaying iTIP mail messages - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: - * Jesse Pavel <jpavel@ximian.com> - * JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 __ITIP_CONTROL_FACTORY_H__ -#define __ITIP_CONTROL_FACTORY_H__ - -#include <bonobo/bonobo-control.h> - -BonoboControl *itip_bonobo_control_new (void); - -#endif /* __ITIP_CONTROL_H__ */ diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c deleted file mode 100644 index 5215237930..0000000000 --- a/calendar/gui/itip-utils.c +++ /dev/null @@ -1,980 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * JP Rosevear <jpr@ximian.com> - * - * Copyright 2001, Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-moniker-util.h> -#include <libgnome/gnome-i18n.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkwidget.h> -#include <gal/widgets/e-unicode.h> -#include <gal/util/e-util.h> -#include <ical.h> -#include <Evolution-Composer.h> -#include <e-util/e-dialog-utils.h> -#include <e-util/e-time-utils.h> -#include <cal-util/timeutil.h> -#include <cal-util/cal-util.h> -#include "calendar-config.h" -#include "itip-utils.h" - -#define GNOME_EVOLUTION_COMPOSER_OAFIID "OAFIID:GNOME_Evolution_Mail_Composer" - -static gchar *itip_methods[] = { - "PUBLISH", - "REQUEST", - "REPLY", - "ADD", - "CANCEL", - "RERESH", - "COUNTER", - "DECLINECOUNTER" -}; - -static icalproperty_method itip_methods_enum[] = { - ICAL_METHOD_PUBLISH, - ICAL_METHOD_REQUEST, - ICAL_METHOD_REPLY, - ICAL_METHOD_ADD, - ICAL_METHOD_CANCEL, - ICAL_METHOD_REFRESH, - ICAL_METHOD_COUNTER, - ICAL_METHOD_DECLINECOUNTER, -}; - -static EAccountList *accounts = NULL; - -EAccountList * -itip_addresses_get (void) -{ - if (accounts == NULL) - accounts = e_account_list_new(gconf_client_get_default()); - - return accounts; -} - -EAccount * -itip_addresses_get_default (void) -{ - return (EAccount *)e_account_list_get_default(itip_addresses_get()); -} - -gboolean -itip_organizer_is_user (CalComponent *comp, CalClient *client) -{ - CalComponentOrganizer organizer; - const char *strip; - gboolean user_org = FALSE; - - if (!cal_component_has_organizer (comp)) - return FALSE; - - cal_component_get_organizer (comp, &organizer); - if (organizer.value != NULL) { - - strip = itip_strip_mailto (organizer.value); - - if (cal_client_get_static_capability (client, CAL_STATIC_CAPABILITY_ORGANIZER_NOT_EMAIL_ADDRESS)) { - const char *email; - - email = cal_client_get_cal_address (client); - if (email && !g_strcasecmp (email, strip)) - return TRUE; - - return FALSE; - } - - user_org = e_account_list_find(itip_addresses_get(), E_ACCOUNT_FIND_ID_ADDRESS, strip) != NULL; - } - - return user_org; -} - -gboolean -itip_sentby_is_user (CalComponent *comp) -{ - CalComponentOrganizer organizer; - const char *strip; - gboolean user_sentby = FALSE; - - if (!cal_component_has_organizer (comp)) - return FALSE; - - cal_component_get_organizer (comp, &organizer); - if (organizer.sentby != NULL) { - strip = itip_strip_mailto (organizer.sentby); - user_sentby = e_account_list_find(itip_addresses_get(), E_ACCOUNT_FIND_ID_ADDRESS, strip) != NULL; - } - - return user_sentby; -} - -const gchar * -itip_strip_mailto (const gchar *address) -{ - if (address == NULL) - return NULL; - - if (!g_strncasecmp (address, "mailto:", 7)) - address += 7; - - return address; -} - -static char * -get_label (struct icaltimetype *tt) -{ - char buffer[1000]; - struct tm tmp_tm; - - tmp_tm = icaltimetype_to_tm (tt); - e_time_format_date_and_time (&tmp_tm, - calendar_config_get_24_hour_format (), - FALSE, FALSE, - buffer, 1000); - - return g_strdup (buffer); -} - -typedef struct { - GHashTable *tzids; - icalcomponent *icomp; - CalClient *client; - icalcomponent *zones; -} ItipUtilTZData; - - -static void -foreach_tzid_callback (icalparameter *param, gpointer data) -{ - ItipUtilTZData *tz_data = data; - const char *tzid; - icaltimezone *zone = NULL; - icalcomponent *vtimezone_comp; - - /* Get the TZID string from the parameter. */ - tzid = icalparameter_get_tzid (param); - if (!tzid || g_hash_table_lookup (tz_data->tzids, tzid)) - return; - - /* Look for the timezone */ - if (tz_data->zones != NULL) - zone = icalcomponent_get_timezone (tz_data->zones, tzid); - if (zone == NULL) - zone = icaltimezone_get_builtin_timezone_from_tzid (tzid); - if (zone == NULL && tz_data->client != NULL) - cal_client_get_timezone (tz_data->client, tzid, &zone); - if (zone == NULL) - return; - - /* Convert it to a string and add it to the hash. */ - vtimezone_comp = icaltimezone_get_component (zone); - if (!vtimezone_comp) - return; - - icalcomponent_add_component (tz_data->icomp, icalcomponent_new_clone (vtimezone_comp)); - g_hash_table_insert (tz_data->tzids, (char *)tzid, (char *)tzid); -} - -static icalcomponent * -comp_toplevel_with_zones (CalComponentItipMethod method, CalComponent *comp, CalClient *client, icalcomponent *zones) -{ - icalcomponent *top_level, *icomp; - icalproperty *prop; - icalvalue *value; - ItipUtilTZData tz_data; - - top_level = cal_util_new_top_level (); - - prop = icalproperty_new (ICAL_METHOD_PROPERTY); - value = icalvalue_new_method (itip_methods_enum[method]); - icalproperty_set_value (prop, value); - icalcomponent_add_property (top_level, prop); - - icomp = cal_component_get_icalcomponent (comp); - icomp = icalcomponent_new_clone (icomp); - - tz_data.tzids = g_hash_table_new (g_str_hash, g_str_equal); - tz_data.icomp = top_level; - tz_data.client = client; - tz_data.zones = zones; - icalcomponent_foreach_tzid (icomp, foreach_tzid_callback, &tz_data); - g_hash_table_destroy (tz_data.tzids); - - icalcomponent_add_component (top_level, icomp); - - return top_level; -} - -static gboolean -users_has_attendee (GList *users, const char *address) -{ - GList *l; - - for (l = users; l != NULL; l = l->next) { - if (!g_strcasecmp (address, l->data)) - return TRUE; - } - - return FALSE; -} - -static CORBA_char * -comp_from (CalComponentItipMethod method, CalComponent *comp) -{ - CalComponentOrganizer organizer; - CalComponentAttendee *attendee; - GSList *attendees; - CORBA_char *str; - - switch (method) { - case CAL_COMPONENT_METHOD_PUBLISH: - return CORBA_string_dup (""); - - case CAL_COMPONENT_METHOD_REQUEST: - case CAL_COMPONENT_METHOD_CANCEL: - case CAL_COMPONENT_METHOD_ADD: - cal_component_get_organizer (comp, &organizer); - if (organizer.value == NULL) { - e_notice (NULL, GTK_MESSAGE_ERROR, - _("An organizer must be set.")); - return NULL; - } - - return CORBA_string_dup (itip_strip_mailto (organizer.value)); - - default: - if (!cal_component_has_attendees (comp)) - return CORBA_string_dup (""); - - cal_component_get_attendee_list (comp, &attendees); - attendee = attendees->data; - str = CORBA_string_dup (attendee->value ? itip_strip_mailto (attendee->value) : ""); - cal_component_free_attendee_list (attendees); - - return str; - } -} - -static GNOME_Evolution_Composer_RecipientList * -comp_to_list (CalComponentItipMethod method, CalComponent *comp, GList *users) -{ - GNOME_Evolution_Composer_RecipientList *to_list; - GNOME_Evolution_Composer_Recipient *recipient; - CalComponentOrganizer organizer; - GSList *attendees, *l; - gint len; - - switch (method) { - case CAL_COMPONENT_METHOD_REQUEST: - case CAL_COMPONENT_METHOD_CANCEL: - cal_component_get_attendee_list (comp, &attendees); - len = g_slist_length (attendees); - if (len <= 0) { - e_notice (NULL, GTK_MESSAGE_ERROR, - _("At least one attendee is necessary")); - cal_component_free_attendee_list (attendees); - return NULL; - } - - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = len; - to_list->_length = 0; - to_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (len); - - cal_component_get_organizer (comp, &organizer); - if (organizer.value == NULL) { - e_notice (NULL, GTK_MESSAGE_ERROR, - _("An organizer must be set.")); - return NULL; - } - - for (l = attendees; l != NULL; l = l->next) { - CalComponentAttendee *att = l->data; - - if (users_has_attendee (users, att->value)) - continue; - else if (!g_strcasecmp (att->value, organizer.value)) - continue; - - recipient = &(to_list->_buffer[to_list->_length]); - if (att->cn) - recipient->name = CORBA_string_dup (att->cn); - else - recipient->name = CORBA_string_dup (""); - recipient->address = CORBA_string_dup (itip_strip_mailto (att->value)); - - to_list->_length++; - } - cal_component_free_attendee_list (attendees); - break; - - case CAL_COMPONENT_METHOD_REPLY: - case CAL_COMPONENT_METHOD_ADD: - case CAL_COMPONENT_METHOD_REFRESH: - case CAL_COMPONENT_METHOD_COUNTER: - case CAL_COMPONENT_METHOD_DECLINECOUNTER: - cal_component_get_organizer (comp, &organizer); - if (organizer.value == NULL) { - e_notice (NULL, GTK_MESSAGE_ERROR, - _("An organizer must be set.")); - return NULL; - } - - len = 1; - - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = len; - to_list->_length = len; - to_list->_buffer = CORBA_sequence_GNOME_Evolution_Composer_Recipient_allocbuf (len); - recipient = &(to_list->_buffer[0]); - - if (organizer.cn != NULL) - recipient->name = CORBA_string_dup (organizer.cn); - else - recipient->name = CORBA_string_dup (""); - recipient->address = CORBA_string_dup (itip_strip_mailto (organizer.value)); - break; - - default: - to_list = GNOME_Evolution_Composer_RecipientList__alloc (); - to_list->_maximum = to_list->_length = 0; - break; - } - CORBA_sequence_set_release (to_list, TRUE); - - return to_list; -} - -static CORBA_char * -comp_subject (CalComponentItipMethod method, CalComponent *comp) -{ - CalComponentText caltext; - const char *description, *prefix = NULL; - GSList *alist; - CORBA_char *subject; - - cal_component_get_summary (comp, &caltext); - if (caltext.value != NULL) - description = caltext.value; - else { - switch (cal_component_get_vtype (comp)) { - case CAL_COMPONENT_EVENT: - description = _("Event information"); - case CAL_COMPONENT_TODO: - description = _("Task information"); - case CAL_COMPONENT_JOURNAL: - description = _("Journal information"); - case CAL_COMPONENT_FREEBUSY: - description = _("Free/Busy information"); - default: - description = _("Calendar information"); - } - } - - switch (method) { - case CAL_COMPONENT_METHOD_PUBLISH: - case CAL_COMPONENT_METHOD_REQUEST: - /* FIXME: If this is an update to a previous - * PUBLISH or REQUEST, then - prefix = U_("Updated"); - */ - break; - - case CAL_COMPONENT_METHOD_REPLY: - cal_component_get_attendee_list (comp, &alist); - if (alist != NULL) { - CalComponentAttendee *a = alist->data; - - switch (a->status) { - case ICAL_PARTSTAT_ACCEPTED: - prefix = _("Accepted"); - break; - case ICAL_PARTSTAT_TENTATIVE: - prefix = _("Tentatively Accepted"); - break; - case ICAL_PARTSTAT_DECLINED: - prefix = _("Declined"); - break; - default: - break; - } - cal_component_free_attendee_list (alist); - } - break; - - case CAL_COMPONENT_METHOD_ADD: - prefix = _("Updated"); - break; - - case CAL_COMPONENT_METHOD_CANCEL: - prefix = _("Cancel"); - break; - - case CAL_COMPONENT_METHOD_REFRESH: - prefix = _("Refresh"); - break; - - case CAL_COMPONENT_METHOD_COUNTER: - prefix = _("Counter-proposal"); - break; - - case CAL_COMPONENT_METHOD_DECLINECOUNTER: - prefix = _("Declined"); - break; - - default: - break; - } - - if (prefix) { - subject = CORBA_string_alloc (strlen (description) + - strlen (prefix) + 3); - sprintf (subject, "%s: %s", prefix, description); - } else - subject = CORBA_string_dup (description); - - return subject; -} - -static CORBA_char * -comp_content_type (CalComponent *comp, CalComponentItipMethod method) -{ - char tmp[256]; - - sprintf (tmp, "text/calendar; name=\"%s\"; charset=utf-8; METHOD=%s", - cal_component_get_vtype (comp) == CAL_COMPONENT_FREEBUSY ? - "freebusy.ifb" : "calendar.ics", itip_methods[method]); - return CORBA_string_dup (tmp); - -} - -static CORBA_char * -comp_filename (CalComponent *comp) -{ - switch (cal_component_get_vtype (comp)) { - case CAL_COMPONENT_FREEBUSY: - return CORBA_string_dup ("freebusy.ifb"); - default: - return CORBA_string_dup ("calendar.ics"); - } -} - -static CORBA_char * -comp_description (CalComponent *comp) -{ - CORBA_char *description; - CalComponentDateTime dt; - char *start = NULL, *end = NULL; - - switch (cal_component_get_vtype (comp)) { - case CAL_COMPONENT_EVENT: - return CORBA_string_dup (_("Event information")); - case CAL_COMPONENT_TODO: - return CORBA_string_dup (_("Task information")); - case CAL_COMPONENT_JOURNAL: - return CORBA_string_dup (_("Journal information")); - case CAL_COMPONENT_FREEBUSY: - cal_component_get_dtstart (comp, &dt); - if (dt.value) - start = get_label (dt.value); - cal_component_free_datetime (&dt); - - cal_component_get_dtend (comp, &dt); - if (dt.value) - end = get_label (dt.value); - cal_component_free_datetime (&dt); - - if (start != NULL && end != NULL) { - char *tmp, *tmp_utf; - tmp = g_strdup_printf (_("Free/Busy information (%s to %s)"), start, end); - tmp_utf = g_locale_to_utf8 (tmp, -1, NULL, NULL, NULL); - description = CORBA_string_dup (tmp_utf); - g_free (tmp_utf); - g_free (tmp); - } else { - description = CORBA_string_dup (_("Free/Busy information")); - } - g_free (start); - g_free (end); - return description; - default: - return CORBA_string_dup (_("iCalendar information")); - } -} - -static gboolean -comp_server_send (CalComponentItipMethod method, CalComponent *comp, CalClient *client, - icalcomponent *zones, GList **users) -{ - CalClientSendResult result; - icalcomponent *top_level, *new_top_level = NULL; - char error_msg[256]; - gboolean retval = TRUE; - - top_level = comp_toplevel_with_zones (method, comp, client, zones); - result = cal_client_send_object (client, top_level, &new_top_level, users, error_msg); - - if (result == CAL_CLIENT_SEND_SUCCESS) { - icalcomponent *ical_comp; - - ical_comp = icalcomponent_get_inner (new_top_level); - icalcomponent_remove_component (new_top_level, ical_comp); - cal_component_set_icalcomponent (comp, ical_comp); - icalcomponent_free (new_top_level); - } else if (result == CAL_CLIENT_SEND_BUSY) { - e_notice (NULL, GTK_MESSAGE_ERROR, error_msg); - - retval = FALSE; - } - - icalcomponent_free (top_level); - - return retval; -} - -static gboolean -comp_limit_attendees (CalComponent *comp) -{ - icalcomponent *icomp; - icalproperty *prop; - gboolean found = FALSE, match = FALSE; - GSList *l, *list = NULL; - - icomp = cal_component_get_icalcomponent (comp); - - for (prop = icalcomponent_get_first_property (icomp, ICAL_ATTENDEE_PROPERTY); - prop != NULL; - prop = icalcomponent_get_next_property (icomp, ICAL_ATTENDEE_PROPERTY)) - { - icalvalue *value; - const char *attendee; - char *text; - - /* If we've already found something, just erase the rest */ - if (found) { - list = g_slist_prepend (list, prop); - continue; - } - - value = icalproperty_get_value (prop); - if (!value) - continue; - - attendee = icalvalue_get_string (value); - - text = g_strdup (itip_strip_mailto (attendee)); - text = g_strstrip (text); - found = match = e_account_list_find(itip_addresses_get(), E_ACCOUNT_FIND_ID_ADDRESS, text) != NULL; - g_free (text); - - if (!match) - list = g_slist_prepend (list, prop); - match = FALSE; - } - - for (l = list; l != NULL; l = l->next) { - prop = l->data; - - icalcomponent_remove_property (icomp, prop); - icalproperty_free (prop); - } - g_slist_free (list); - - return found; -} - -static void -comp_sentby (CalComponent *comp, CalClient *client) -{ - CalComponentOrganizer organizer; - - cal_component_get_organizer (comp, &organizer); - if (!organizer.value) { - EAccount *a = itip_addresses_get_default (); - - organizer.value = g_strdup_printf ("MAILTO:%s", a->id->address); - organizer.sentby = NULL; - organizer.cn = a->id->name; - organizer.language = NULL; - - cal_component_set_organizer (comp, &organizer); - g_free ((char *) organizer.value); - - return; - } - - if (!itip_organizer_is_user (comp, client) && !itip_sentby_is_user (comp)) { - EAccount *a = itip_addresses_get_default (); - - organizer.value = g_strdup (organizer.value); - organizer.sentby = g_strdup_printf ("MAILTO:%s", a->id->address); - organizer.cn = g_strdup (organizer.cn); - organizer.language = g_strdup (organizer.language); - - cal_component_set_organizer (comp, &organizer); - - g_free ((char *)organizer.value); - g_free ((char *)organizer.sentby); - g_free ((char *)organizer.cn); - g_free ((char *)organizer.language); - } -} -static CalComponent * -comp_minimal (CalComponent *comp, gboolean attendee) -{ - CalComponent *clone; - icalcomponent *icomp, *icomp_clone; - icalproperty *prop; - CalComponentOrganizer organizer; - const char *uid; - GSList *comments; - struct icaltimetype itt; - CalComponentRange recur_id; - - clone = cal_component_new (); - cal_component_set_new_vtype (clone, cal_component_get_vtype (comp)); - - if (attendee) { - GSList *attendees; - - cal_component_get_attendee_list (comp, &attendees); - cal_component_set_attendee_list (clone, attendees); - - if (!comp_limit_attendees (clone)) { - e_notice (NULL, GTK_MESSAGE_ERROR, - _("You must be an attendee of the event.")); - goto error; - } - } - - itt = icaltime_from_timet_with_zone (time (NULL), FALSE, - icaltimezone_get_utc_timezone ()); - cal_component_set_dtstamp (clone, &itt); - - cal_component_get_organizer (comp, &organizer); - if (organizer.value == NULL) - goto error; - cal_component_set_organizer (clone, &organizer); - - cal_component_get_uid (comp, &uid); - cal_component_set_uid (clone, uid); - - cal_component_get_comment_list (comp, &comments); - if (g_slist_length (comments) <= 1) { - cal_component_set_comment_list (clone, comments); - } else { - GSList *l = comments; - - comments = g_slist_remove_link (comments, l); - cal_component_set_comment_list (clone, l); - cal_component_free_text_list (l); - } - cal_component_free_text_list (comments); - - cal_component_get_recurid (comp, &recur_id); - if (recur_id.datetime.value != NULL) - cal_component_set_recurid (clone, &recur_id); - - icomp = cal_component_get_icalcomponent (comp); - icomp_clone = cal_component_get_icalcomponent (clone); - for (prop = icalcomponent_get_first_property (icomp, ICAL_X_PROPERTY); - prop != NULL; - prop = icalcomponent_get_next_property (icomp, ICAL_X_PROPERTY)) - { - icalproperty *p; - - p = icalproperty_new_clone (prop); - icalcomponent_add_property (icomp_clone, p); - } - - cal_component_rescan (clone); - - return clone; - - error: - g_object_unref (clone); - return NULL; -} - -static CalComponent * -comp_compliant (CalComponentItipMethod method, CalComponent *comp, CalClient *client, icalcomponent *zones) -{ - CalComponent *clone, *temp_clone; - struct icaltimetype itt; - - clone = cal_component_clone (comp); - itt = icaltime_from_timet_with_zone (time (NULL), FALSE, - icaltimezone_get_utc_timezone ()); - cal_component_set_dtstamp (clone, &itt); - - /* Make UNTIL date a datetime in a simple recurrence */ - if (cal_component_has_recurrences (clone) - && cal_component_has_simple_recurrence (clone)) { - GSList *rrule_list; - struct icalrecurrencetype *r; - - cal_component_get_rrule_list (clone, &rrule_list); - r = rrule_list->data; - - if (!icaltime_is_null_time (r->until) && r->until.is_date) { - CalComponentDateTime dt; - icaltimezone *from_zone = NULL, *to_zone; - - cal_component_get_dtstart (clone, &dt); - - if (dt.value->is_date) { - from_zone = icaltimezone_get_builtin_timezone (calendar_config_get_timezone ()); - } else if (dt.tzid == NULL) { - from_zone = icaltimezone_get_utc_timezone (); - } else { - if (zones != NULL) - from_zone = icalcomponent_get_timezone (zones, dt.tzid); - if (from_zone == NULL) - from_zone = icaltimezone_get_builtin_timezone_from_tzid (dt.tzid); - if (from_zone == NULL && client != NULL) - cal_client_get_timezone (client, dt.tzid, &from_zone); - } - - to_zone = icaltimezone_get_utc_timezone (); - - r->until.hour = dt.value->hour; - r->until.minute = dt.value->minute; - r->until.second = dt.value->second; - r->until.is_date = FALSE; - - icaltimezone_convert_time (&r->until, from_zone, to_zone); - r->until.is_utc = TRUE; - - cal_component_set_rrule_list (clone, rrule_list); - cal_component_abort_sequence (clone); - } - - cal_component_free_recur_list (rrule_list); - } - - /* We delete incoming alarms anyhow, and this helps with outlook */ - cal_component_remove_all_alarms (clone); - - /* Strip X-LIC-ERROR stuff */ - cal_component_strip_errors (clone); - - /* Comply with itip spec */ - switch (method) { - case CAL_COMPONENT_METHOD_PUBLISH: - comp_sentby (clone, client); - cal_component_set_attendee_list (clone, NULL); - break; - case CAL_COMPONENT_METHOD_REQUEST: - comp_sentby (clone, client); - break; - case CAL_COMPONENT_METHOD_CANCEL: - comp_sentby (clone, client); - break; - case CAL_COMPONENT_METHOD_REPLY: - break; - case CAL_COMPONENT_METHOD_ADD: - break; - case CAL_COMPONENT_METHOD_REFRESH: - /* Need to remove almost everything */ - temp_clone = comp_minimal (clone, TRUE); - g_object_unref (clone); - clone = temp_clone; - break; - case CAL_COMPONENT_METHOD_COUNTER: - break; - case CAL_COMPONENT_METHOD_DECLINECOUNTER: - /* Need to remove almost everything */ - temp_clone = comp_minimal (clone, FALSE); - g_object_unref (clone); - clone = temp_clone; - break; - default: - break; - } - - return clone; -} - -gboolean -itip_send_comp (CalComponentItipMethod method, CalComponent *send_comp, - CalClient *client, icalcomponent *zones) -{ - GNOME_Evolution_Composer composer_server; - CalComponent *comp = NULL; - icalcomponent *top_level = NULL; - GList *users = NULL; - GNOME_Evolution_Composer_RecipientList *to_list = NULL; - GNOME_Evolution_Composer_RecipientList *cc_list = NULL; - GNOME_Evolution_Composer_RecipientList *bcc_list = NULL; - CORBA_char *subject = NULL, *body = NULL, *content_type = NULL; - CORBA_char *from = NULL, *filename = NULL, *description = NULL; - GNOME_Evolution_Composer_AttachmentData *attach_data = NULL; - char *ical_string; - CORBA_Environment ev; - gboolean retval = FALSE; - - CORBA_exception_init (&ev); - - /* Give the server a chance to manipulate the comp */ - if (method != CAL_COMPONENT_METHOD_PUBLISH) { - if (!comp_server_send (method, send_comp, client, zones, &users)) - goto cleanup; - } - - /* Tidy up the comp */ - comp = comp_compliant (method, send_comp, client, zones); - if (comp == NULL) - goto cleanup; - - /* Recipients */ - to_list = comp_to_list (method, comp, users); - if (method != CAL_COMPONENT_METHOD_PUBLISH) { - if (to_list == NULL || to_list->_length == 0) { - /* We sent them all via the server */ - retval = TRUE; - goto cleanup; - } - } - - cc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - cc_list->_maximum = cc_list->_length = 0; - bcc_list = GNOME_Evolution_Composer_RecipientList__alloc (); - bcc_list->_maximum = bcc_list->_length = 0; - - /* Subject information */ - subject = comp_subject (method, comp); - - /* From address */ - from = comp_from (method, comp); - - /* Obtain an object reference for the Composer. */ - composer_server = bonobo_activation_activate_from_id (GNOME_EVOLUTION_COMPOSER_OAFIID, 0, NULL, &ev); - if (BONOBO_EX (&ev)) { - g_warning ("Could not activate composer: %s", bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - return FALSE; - } - - /* Set recipients, subject */ - GNOME_Evolution_Composer_setHeaders (composer_server, from, to_list, cc_list, bcc_list, subject, &ev); - if (BONOBO_EX (&ev)) { - g_warning ("Unable to set composer headers while sending iTip message: %s", - bonobo_exception_get_text (&ev)); - goto cleanup; - } - - - /* Content type */ - content_type = comp_content_type (comp, method); - - top_level = comp_toplevel_with_zones (method, comp, client, zones); - ical_string = icalcomponent_as_ical_string (top_level); - - if (cal_component_get_vtype (comp) == CAL_COMPONENT_EVENT) { - GNOME_Evolution_Composer_setBody (composer_server, ical_string, content_type, &ev); - } else { - GNOME_Evolution_Composer_setMultipartType (composer_server, GNOME_Evolution_Composer_MIXED, &ev); - if (BONOBO_EX (&ev)) { - g_warning ("Unable to set multipart type while sending iTip message"); - goto cleanup; - } - - filename = comp_filename (comp); - description = comp_description (comp); - - GNOME_Evolution_Composer_setBody (composer_server, description, "text/plain", &ev); - if (BONOBO_EX (&ev)) { - g_warning ("Unable to set body text while sending iTip message"); - goto cleanup; - } - - attach_data = GNOME_Evolution_Composer_AttachmentData__alloc (); - attach_data->_length = strlen (ical_string) + 1; - attach_data->_maximum = attach_data->_length; - attach_data->_buffer = CORBA_sequence_CORBA_char_allocbuf (attach_data->_length); - strcpy (attach_data->_buffer, ical_string); - - GNOME_Evolution_Composer_attachData (composer_server, - content_type, filename, description, - TRUE, attach_data, - &ev); - } - - if (BONOBO_EX (&ev)) { - g_warning ("Unable to place iTip message in composer"); - goto cleanup; - } - - if (method == CAL_COMPONENT_METHOD_PUBLISH) { - GNOME_Evolution_Composer_show (composer_server, &ev); - if (BONOBO_EX (&ev)) - g_warning ("Unable to show the composer while sending iTip message"); - else - retval = TRUE; - } else { - GNOME_Evolution_Composer_send (composer_server, &ev); - if (BONOBO_EX (&ev)) - g_warning ("Unable to send iTip message"); - else - retval = TRUE; - } - - cleanup: - CORBA_exception_free (&ev); - - if (comp != NULL) - g_object_unref (comp); - if (top_level != NULL) - icalcomponent_free (top_level); - - if (to_list != NULL) - CORBA_free (to_list); - if (cc_list != NULL) - CORBA_free (cc_list); - if (bcc_list != NULL) - CORBA_free (bcc_list); - - if (from != NULL) - CORBA_free (from); - if (subject != NULL) - CORBA_free (subject); - if (body != NULL) - CORBA_free (body); - if (content_type != NULL) - CORBA_free (content_type); - if (filename != NULL) - CORBA_free (filename); - if (description != NULL) - CORBA_free (description); - if (attach_data != NULL) { - CORBA_free (attach_data->_buffer); - CORBA_free (attach_data); - } - - return retval; -} - diff --git a/calendar/gui/itip-utils.h b/calendar/gui/itip-utils.h deleted file mode 100644 index c73f11673c..0000000000 --- a/calendar/gui/itip-utils.h +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef ITIP_UTILS_HEADER -#define ITIP_UTILS_HEADER - -#include <ical.h> -#include <string.h> -#include <glib.h> -#include <cal-client/cal-client.h> -#include <cal-util/cal-component.h> -#include <e-util/e-account-list.h> - -typedef enum { - CAL_COMPONENT_METHOD_PUBLISH, - CAL_COMPONENT_METHOD_REQUEST, - CAL_COMPONENT_METHOD_REPLY, - CAL_COMPONENT_METHOD_ADD, - CAL_COMPONENT_METHOD_CANCEL, - CAL_COMPONENT_METHOD_REFRESH, - CAL_COMPONENT_METHOD_COUNTER, - CAL_COMPONENT_METHOD_DECLINECOUNTER -} CalComponentItipMethod; - -EAccountList *itip_addresses_get (void); -EAccount *itip_addresses_get_default (void); - -gboolean itip_organizer_is_user (CalComponent *comp, CalClient *client); -gboolean itip_sentby_is_user (CalComponent *comp); - -const gchar *itip_strip_mailto (const gchar *address); - -gboolean itip_send_comp (CalComponentItipMethod method, CalComponent *comp, - CalClient *client, icalcomponent *zones); - - -#endif diff --git a/calendar/gui/main.c b/calendar/gui/main.c deleted file mode 100644 index f0534adbd1..0000000000 --- a/calendar/gui/main.c +++ /dev/null @@ -1,179 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* main.c - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-init.h> -#include <libgnomevfs/gnome-vfs-init.h> -#include <glade/glade.h> - -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-shlib-factory.h> -#include <bonobo/bonobo-exception.h> - -#include <gal/widgets/e-cursors.h> - -#include <evolution-shell-client.h> - -#include "dialogs/cal-prefs-dialog.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "calendar-component.h" -#include "e-comp-editor-registry.h" -#include "comp-editor-factory.h" -#include "control-factory.h" -#include "itip-bonobo-control.h" -#include "tasks-control.h" - - -#define FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_Factory" - -#define CALENDAR_COMPONENT_ID "OAFIID:GNOME_Evolution_Calendar_ShellComponent" -#define CALENDAR_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_Control" -#define TASKS_CONTROL_ID "OAFIID:GNOME_Evolution_Tasks_Control" -#define ITIP_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_iTip_Control" -#define CONFIG_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_ConfigControl" -#define COMP_EDITOR_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_CompEditorFactory" - -ECompEditorRegistry *comp_editor_registry = NULL; - -/* The component editor factory */ -static CompEditorFactory *comp_editor_factory = NULL; - - -/* Factory function for the calendar component factory; just creates and - * references a singleton service object. - */ -static BonoboObject * -comp_editor_factory_fn (void) -{ - if (!comp_editor_factory) { - comp_editor_factory = comp_editor_factory_new (); - if (!comp_editor_factory) - return NULL; - } - - bonobo_object_ref (BONOBO_OBJECT (comp_editor_factory)); - return BONOBO_OBJECT (comp_editor_factory); -} - - -/* Does a simple activation and unreffing of the alarm notification service so - * that the daemon will be launched if it is not running yet. - */ -static gboolean -launch_alarm_daemon_cb (gpointer data) -{ - CORBA_Environment ev; - GNOME_Evolution_Calendar_AlarmNotify an; - guint *idle_id = (guint *) data; - - /* remove the idle function */ - g_source_remove (*idle_id); - g_free (idle_id); - - /* activate the alarm daemon */ - CORBA_exception_init (&ev); - an = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify", 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("launch_alarm_daemon_cb(): Could not activate the alarm notification service"); - CORBA_exception_free (&ev); - return FALSE; - } - CORBA_exception_free (&ev); - - /* Just get rid of it; what we are interested in is that it gets launched */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (an, &ev); - if (BONOBO_EX (&ev)) - g_message ("add_alarms(): Could not unref the alarm notification service"); - - CORBA_exception_free (&ev); - - return FALSE; -} - -static void -launch_alarm_daemon (void) -{ - guint *idle_id; - - idle_id = g_new0 (guint, 1); - *idle_id = g_idle_add ((GSourceFunc) launch_alarm_daemon_cb, idle_id); -} - -static void -initialize (void) -{ - comp_editor_registry = E_COMP_EDITOR_REGISTRY (e_comp_editor_registry_new ()); - - calendar_config_init (); - -#if 0 - itip_control_factory_init (); - component_editor_factory_init (); -#endif - - launch_alarm_daemon (); -} - - -static BonoboObject * -factory (BonoboGenericFactory *factory, - const char *component_id, - void *closure) -{ - static gboolean initialized = FALSE; - - if (! initialized) - initialize (); - - if (strcmp (component_id, CALENDAR_COMPONENT_ID) == 0) - return calendar_component_get_object (); - if (strcmp (component_id, CALENDAR_CONTROL_ID) == 0) - return BONOBO_OBJECT (control_factory_new_control ()); - if (strcmp (component_id, TASKS_CONTROL_ID) == 0) - return BONOBO_OBJECT (tasks_control_new ()); - if (strcmp (component_id, ITIP_CONTROL_ID) == 0) - return BONOBO_OBJECT (itip_bonobo_control_new ()); - if (strcmp (component_id, CONFIG_CONTROL_ID) == 0) { - extern EvolutionShellClient *global_shell_client; /* FIXME ugly */ - - if (global_shell_client == NULL) - return NULL; - else - return BONOBO_OBJECT (cal_prefs_dialog_new ()); - } - if (strcmp (component_id, COMP_EDITOR_FACTORY_ID) == 0) - return BONOBO_OBJECT (comp_editor_factory_fn ()); - - g_warning (FACTORY_ID ": Don't know what to do with %s", component_id); - return NULL; -} - -BONOBO_ACTIVATION_SHLIB_FACTORY (FACTORY_ID, "Evolution Calendar component factory", factory, NULL) diff --git a/calendar/gui/misc.c b/calendar/gui/misc.c deleted file mode 100644 index e286442a89..0000000000 --- a/calendar/gui/misc.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Evolution calendar - Miscellaneous utility functions - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> -#include <e-util/e-url.h> -#include "misc.h" - - - -/** - * string_is_empty: - * @value: A string. - * - * Returns whether a string is NULL, the empty string, or completely made up of - * whitespace characters. - * - * Return value: TRUE if the string is empty, FALSE otherwise. - **/ -gboolean -string_is_empty (const char *value) -{ - const char *p; - gboolean empty; - - empty = TRUE; - - if (value) { - p = value; - while (*p) { - if (!isspace ((unsigned char) *p)) { - empty = FALSE; - break; - } - p++; - } - } - return empty; - -} - -/** - * get_uri_without_password - */ -char * -get_uri_without_password (const char *full_uri) -{ - EUri *uri; - char *uristr; - - uri = e_uri_new (full_uri); - if (!uri) - return NULL; - - uristr = e_uri_to_string (uri, FALSE); - e_uri_free (uri); - - return uristr; - } diff --git a/calendar/gui/misc.h b/calendar/gui/misc.h deleted file mode 100644 index d32739f9f5..0000000000 --- a/calendar/gui/misc.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Evolution calendar - Miscellaneous utility functions - * - * Copyright (C) 2001 Ximian, Inc. - * - * Authors: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 MISC_H -#define MISC_H - -#include <glib.h> - -gboolean string_is_empty (const char *value); -char *get_uri_without_password (const char *uri); - -#endif diff --git a/calendar/gui/print.c b/calendar/gui/print.c deleted file mode 100644 index dff86a02a2..0000000000 --- a/calendar/gui/print.c +++ /dev/null @@ -1,2660 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* Evolution calendar - Print support - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Michael Zucchi <notzed@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 <sys/time.h> -#include <math.h> -#include <string.h> -#include <time.h> -#include <glib.h> -#include <gtk/gtkradiobutton.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-uidefs.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-paper.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> -#include <libgnomeprintui/gnome-print-paper-selector.h> -#include <libgnomeprintui/gnome-print-preview.h> -#include <libgnomeprintui/gnome-print-dialog.h> -#include <e-util/e-dialog-widgets.h> -#include <e-util/e-time-utils.h> -#include <gal/widgets/e-unicode.h> -#include <cal-util/timeutil.h> -#include "calendar-commands.h" -#include "calendar-config.h" -#include "e-day-view.h" -#include "e-day-view-layout.h" -#include "e-week-view.h" -#include "e-week-view-layout.h" -#include "gnome-cal.h" -#include "print.h" - - - -/* - * Note that most dimensions are in points (1/72 of an inch) since that is - * what gnome-print uses. - */ - -/* GtkHTML prints using a fixed margin. It has code to get the margins from - * gnome-print keys, but it's commented out. The corresponding code here - * doesn't seem to work either (getting zero margins), so we adopt - * gtkhtml's cheat. */ -#define TEMP_MARGIN .05 - -/* The fonts to use */ -#define REGULAR_FONT "Sans Regular" -#define BOLD_FONT "Sans Bold" - -/* The font size to use for normal text. */ -#define DAY_NORMAL_FONT_SIZE 12 -#define WEEK_NORMAL_FONT_SIZE 12 -#define MONTH_NORMAL_FONT_SIZE 8 - -/* The height of the header bar across the top of the Day, Week & Month views, - which contains the dates shown and the 2 small calendar months. */ -#define HEADER_HEIGHT 80 - -/* The width of the small calendar months, the space from the right edge of - the header rectangle, and the space between the months. */ -#define SMALL_MONTH_WIDTH 80 -#define SMALL_MONTH_PAD 4 -#define SMALL_MONTH_SPACING 12 - -/* The minimum number of rows we leave space for for the long events in the - day view. */ -#define DAY_VIEW_MIN_ROWS_IN_TOP_DISPLAY 2 - -/* The row height for long events in the day view. */ -#define DAY_VIEW_ROW_HEIGHT 20 - -/* The minutes per row in the day view printout. */ -#define DAY_VIEW_MINS_PER_ROW 30 - -#define DAY_VIEW_ROWS ((60 / DAY_VIEW_MINS_PER_ROW) * 24) - -/* The width of the column with all the times in it. */ -#define DAY_VIEW_TIME_COLUMN_WIDTH 36 - -/* The space on the right of each event. */ -#define DAY_VIEW_EVENT_X_PAD 8 - -/* Allowance for small errors in floating point comparisons. */ -#define EPSILON 0.01 - -/* 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 SEPT_1752_START 2 /* Start day within month */ -#define SEPT_1752_END 20 /* End day within month */ - - -struct pdinfo -{ - gint days_shown; - time_t day_starts[E_DAY_VIEW_MAX_DAYS + 1]; - - GArray *long_events; - GArray *events[E_DAY_VIEW_MAX_DAYS]; - - gint start_hour; - gint end_hour; - gint start_minute_offset; - gint end_minute_offset; - gint rows; - gint mins_per_row; - gint8 cols_per_row[DAY_VIEW_ROWS]; - gboolean use_24_hour_format; -}; - -struct psinfo -{ - gint days_shown; - time_t day_starts[E_WEEK_VIEW_MAX_WEEKS * 7 + 1]; - - GArray *events; - - int rows_per_cell; - int rows_per_compressed_cell; - int display_start_weekday; - gboolean multi_week_view; - int weeks_shown; - int month; - gboolean compress_weekend; - gboolean use_24_hour_format; - double row_height; - double header_row_height; -}; - -struct ptinfo -{ - GList *todos; -}; - -struct einfo -{ - char *text; - time_t start; - time_t end; - int count; -}; - -static GnomePrintConfig *print_config = NULL; - - -/* Convenience function to help the transition to timezone functions. - It returns the current timezone. */ -static icaltimezone* -get_timezone (void) -{ - char *location = calendar_config_get_timezone (); - return icaltimezone_get_builtin_timezone (location); -} - - -/* Convenience function to help the transition to timezone functions. - It converts a time_t to a struct tm. */ -static struct tm* -convert_timet_to_struct_tm (time_t time, icaltimezone *zone) -{ - static struct tm my_tm; - struct icaltimetype tt; - - /* Convert it to an icaltimetype. */ - tt = icaltime_from_timet_with_zone (time, FALSE, zone); - - /* Fill in the struct tm. */ - my_tm.tm_year = tt.year - 1900; - my_tm.tm_mon = tt.month - 1; - my_tm.tm_mday = tt.day; - my_tm.tm_hour = tt.hour; - my_tm.tm_min = tt.minute; - my_tm.tm_sec = tt.second; - my_tm.tm_isdst = tt.is_daylight; - - my_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year); - - return &my_tm; -} - - -/* 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 *days, int *start, int *end) -{ - int i; - int d_month, d_week, week_start_day; - - /* 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 = time_days_in_month (year, month); - /* Get the start weekday in the month, 0=Sun to 6=Sat. */ - d_week = time_day_of_week (1, month, year); - - /* Get the configuration setting specifying which weekday we put on - the left column, 0=Sun to 6=Sat. */ - week_start_day = calendar_config_get_week_start_day (); - - /* Figure out which square we want to put the 1 in. */ - d_week = (d_week + 7 - week_start_day) % 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; -} - -static GnomeFont * -get_font_for_size (double h, GnomeFontWeight weight, gboolean italic) -{ - GnomeFontFace *face; - GnomeFont *font; - double asc, desc, size; - gchar *font_name; - - if (weight <= GNOME_FONT_BOOK) - font_name = REGULAR_FONT; - else - font_name = BOLD_FONT; - - if (italic) - font_name = g_strconcat (font_name, " Italic", NULL); - - /* This function is broken in gnome-print (it doesn't find a suitable face). - * face = gnome_font_face_find_closest_from_weight_slant (DEFAULT_FONT, weight, italic); */ - face = gnome_font_face_find (font_name); - - asc = gnome_font_face_get_ascender (face); - desc = abs (gnome_font_face_get_descender (face)); - size = h * 1000 / (asc + desc); - - g_print ("Print Info: %f, %f, %f\n", asc, desc, size); - - /* This function is broken in gnome-print (it doesn't find a suitable font). - * font = gnome_font_find_closest_from_weight_slant (DEFAULT_FONT, weight, italic, size); */ - font = gnome_font_find_closest (font_name, size); - - g_object_unref (face); - if (italic) - g_free (font_name); - return font; -} - -enum align_box { - ALIGN_LEFT=1, - ALIGN_RIGHT, - ALIGN_CENTER, - ALIGN_BORDER= 1<<8 -}; - - -/* Prints a rectangle, with or without a border, filled or outline, and - possibly with triangular arrows at one or both horizontal edges. - width = width of border, -ve means no border. - fillcolor = shade of fill, -ve means no fill. - left_triangle_width, right_triangle_width = width from edge of rectangle to - point of triangle, or -ve for no triangle. */ -static void -print_border_with_triangles (GnomePrintContext *pc, - double l, double r, double t, double b, - double width, double fillcolor, - double left_triangle_width, - double right_triangle_width) -{ - gnome_print_gsave (pc); - - /* Fill in the interior of the rectangle, if desired. */ - if (fillcolor >= -EPSILON) { - gnome_print_moveto (pc, l, t); - if (left_triangle_width > 0.0) - gnome_print_lineto (pc, l - left_triangle_width, - (t + b) / 2); - gnome_print_lineto (pc, l, b); - gnome_print_lineto (pc, r, b); - if (right_triangle_width > 0.0) - gnome_print_lineto (pc, r + right_triangle_width, - (t + b) / 2); - gnome_print_lineto (pc, r, t); - gnome_print_closepath (pc); - gnome_print_setrgbcolor (pc, fillcolor, fillcolor, - fillcolor); - gnome_print_fill (pc); - } - - /* Draw the outline, if desired. */ - if (width >= -EPSILON) { - gnome_print_moveto (pc, l, t); - if (left_triangle_width > 0.0) - gnome_print_lineto (pc, l - left_triangle_width, - (t + b) / 2); - gnome_print_lineto (pc, l, b); - gnome_print_lineto (pc, r, b); - if (right_triangle_width > 0.0) - gnome_print_lineto (pc, r + right_triangle_width, - (t + b) / 2); - gnome_print_lineto (pc, r, t); - gnome_print_closepath (pc); - gnome_print_setrgbcolor (pc, 0, 0, 0); - gnome_print_setlinewidth (pc, width); - gnome_print_stroke (pc); - } - - gnome_print_grestore (pc); -} - - -/* Prints a rectangle, with or without a border, and filled or outline. - width = width of border, -ve means no border. - fillcolor = shade of fill, -ve means no fill. */ -static void -print_border (GnomePrintContext *pc, - double l, double r, double t, double b, - double width, double fillcolor) -{ - print_border_with_triangles (pc, l, r, t, b, width, fillcolor, - -1.0, -1.0); -} - - -/* Prints 1 line of aligned text in a box. It is centered vertically, and - the horizontal alignment can be either ALIGN_LEFT, ALIGN_RIGHT, or - ALIGN_CENTER. */ -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, y; - - gnome_print_gsave (pc); - - w = gnome_font_get_width_utf8 (font, text); - - switch (align & 3) { - case ALIGN_LEFT: - default: - x = l; - break; - case ALIGN_RIGHT: - x = r - w; - break; - case ALIGN_CENTER: - x = l + ((r - l) - w) / 2; - break; - } - - /* Make sure we don't go off the left edge. */ - x = MAX (l, x); - - /* Now calculate the baseline. */ - y = t - gnome_font_get_ascender (font); - - /* Set a clipping rectangle. */ - gnome_print_moveto (pc, l, t); - gnome_print_lineto (pc, r, t); - gnome_print_lineto (pc, r, b); - gnome_print_lineto (pc, l, b); - gnome_print_closepath (pc); - gnome_print_clip (pc); - - gnome_print_newpath (pc); - gnome_print_moveto (pc, x, y); - 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 book font */ -static void -print_text_size(GnomePrintContext *pc, const char *text, - enum align_box align, double l, double r, double t, double b) -{ - GnomeFont *font; - - font = get_font_for_size (t - b, GNOME_FONT_BOOK, FALSE); - print_text(pc, font, text, align, l, r, t, b); - g_object_unref (font); -} - -/* gets/frees the font for you, as a bold font */ -static void -print_text_size_bold(GnomePrintContext *pc, const char *text, - enum align_box align, double l, double r, double t, double b) -{ - GnomeFont *font; - - font = get_font_for_size (t - b, GNOME_FONT_BOLD, FALSE); - print_text(pc, font, text, align, l, r, t, b); - g_object_unref (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) -{ - double size; - - size = gnome_font_get_size (font); - - if (align & ALIGN_BORDER) { - print_border (pc, *l, *r, *t, *t - size * 1.4, - linewidth, 0.9); - print_border (pc, *l, *r, *t - size * 1.4, *b, - linewidth, -1.0); - - *l += 2; - *r -= 2; - *b += 2; - } - - print_text (pc, font, text, align, *l, *r, *t, *t - size * 1.4); - *t -= 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) -{ - icaltimezone *zone = get_timezone (); - char fmt[64]; - struct tm tm; - char *utf_str; - - tm = *convert_timet_to_struct_tm (time, zone); - - 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); - utf_str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); - strncpy (buffer, utf_str, bufflen - 1); - buffer[bufflen - 1] = '\0'; - g_free (utf_str); - 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) -{ - icaltimezone *zone = get_timezone (); - CalClient *client; - GnomeFont *font, *font_bold, *font_normal; - time_t now, next; - int x, y; - int days[42]; - int day, weekday, week_start_day; - char buf[100]; - struct tm tm; - double font_size, max_font_size; - double header_size, col_width, row_height, text_xpad, w; - double cell_top, cell_bottom, cell_left, cell_right, text_right; - char *daynames[] = { N_("Su"), N_("Mo"), N_("Tu"), N_("We"), - N_("Th"), N_("Fr"), N_("Sa") }; - - /* Print the title, e.g. 'June 2001', in the top 16% of the area. */ - format_date (month, titleflags, buf, 100); - header_size = (top - bottom) * 0.16; - font = get_font_for_size (header_size, GNOME_FONT_BOLD, FALSE); - if (bordertitle) { - print_border (pc, left, right, top, top - header_size, - 1.0, 0.9); - } - print_text (pc, font, buf, ALIGN_CENTER, left, right, - top, top - header_size); - g_object_unref (font); - - top -= header_size; - - client = gnome_calendar_get_cal_client (gcal); - - col_width = (right - left) / 7; - - /* The top row with the day abbreviations gets an extra bit of - vertical space around it. */ - row_height = (top - bottom) / 7.4; - - /* First we need to calculate a reasonable font size. We start with a - rough guess of just under the height of each row. */ - font_size = row_height; - - /* Check that it isn't going to be too wide. The characters are about - twice as high as they are wide, but we need to fit two characters - into each cell, so we don't want to go over col_width. */ - max_font_size = col_width * 0.65; - - font_size = row_height; - - /* get month days */ - tm = *convert_timet_to_struct_tm (month, zone); - build_month (tm.tm_mon, tm.tm_year + 1900, days, 0, 0); - - font_normal = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); - font_bold = get_font_for_size (font_size, GNOME_FONT_BOLD, FALSE); - - /* Get a reasonable estimate of the largest number we will need, - and use it to calculate the offset from the right edge of the - cell that we should put the numbers. */ - w = gnome_font_get_width_utf8 (font_bold, "23"); - text_xpad = (col_width - w) / 2; - - gnome_print_setrgbcolor (pc, 0, 0, 0); - - /* Print the abbreviated day names across the top in bold. */ - week_start_day = calendar_config_get_week_start_day (); - weekday = week_start_day; - for (x = 0; x < 7; x++) { - print_text (pc, font_bold, _(daynames[weekday]), ALIGN_CENTER, - left + x * col_width, left + (x + 1) * col_width, - top, top - row_height * 1.4); - weekday = (weekday + 1) % 7; - } - - top -= row_height * 1.4; - - now = time_month_begin_with_zone (month, zone); - for (y = 0; y < 6; y++) { - - cell_top = top - y * row_height; - cell_bottom = cell_top - row_height; - - for (x = 0; x < 7; x++) { - - cell_left = left + x * col_width; - /* We add a 0.05 to make sure the cells meet up with - each other. Otherwise you sometimes get lines - between them which looks bad. Maybe I'm not using - coords in the way gnome-print expects. */ - cell_right = cell_left + col_width + 0.05; - text_right = cell_right - text_xpad; - - day = days[y * 7 + x]; - if (day != 0) { - GList *uids; - - sprintf (buf, "%d", day); - - /* this is a slow messy way to do this ... but easy ... */ - uids = cal_client_get_objects_in_range (client, - CALOBJ_TYPE_EVENT, - now, time_day_end_with_zone (now, zone)); - font = uids ? font_bold : font_normal; - cal_obj_uid_list_free (uids); - - next = time_add_day_with_zone (now, 1, zone); - if ((now >= greystart && now < greyend) - || (greystart >= now && greystart < next)) { - print_border (pc, - cell_left, cell_right, - cell_top, cell_bottom, - -1.0, 0.75); - } - print_text (pc, font, buf, ALIGN_RIGHT, - cell_left, text_right, - cell_top, cell_bottom); - - now = next; - } - } - } - g_object_unref (font_normal); - g_object_unref (font_bold); -} - - - -/* wraps text into the print context, not taking up more than its allowed space */ -static double -bound_text(GnomePrintContext *pc, GnomeFont *font, const char *text, - double left, double right, double top, double bottom, double indent) -{ - double maxwidth = right-left; - double width; - const 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 -= gnome_font_get_size (font); - 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_glyph_width(font, gnome_font_lookup_default (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_utf8_sized(font, outbuffer, o-wordstart); - o=outbuffer+(o-wordstart); - wordstart = outbuffer; - top -= gnome_font_get_size (font); - 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 -= gnome_font_get_size (font); - } - g_free(outbuffer); - return top; -} - - -/* Draw the borders, lines, and times down the left of the day view. */ -static void -print_day_background (GnomePrintContext *pc, GnomeCalendar *gcal, - time_t whence, struct pdinfo *pdi, - double left, double right, double top, double bottom) -{ - GnomeFont *font_hour, *font_minute; - double yinc, y; - double width = DAY_VIEW_TIME_COLUMN_WIDTH; - double font_size, max_font_size, hour_font_size, minute_font_size; - char buf[20]; - const char *minute; - gboolean use_24_hour; - int i, hour, row; - - /* Fill the time column in light-gray. */ - print_border (pc, left, left + width, top, bottom, -1.0, 0.9); - - /* Draw the border around the entire view. */ - gnome_print_setrgbcolor (pc, 0, 0, 0); - print_border (pc, left, right, top, bottom, 1.0, -1.0); - - /* Draw the vertical line on the right of the time column. */ - gnome_print_setlinewidth (pc, 0.0); - gnome_print_moveto (pc, left + width, bottom); - gnome_print_lineto (pc, left + width, top); - gnome_print_stroke (pc); - - /* Calculate the row height. */ - yinc = (top - bottom) / (pdi->end_hour - pdi->start_hour); - - /* Get the 2 fonts we need. */ - font_size = yinc * 0.6; - max_font_size = width * 0.5; - hour_font_size = MIN (font_size, max_font_size); - font_hour = get_font_for_size (hour_font_size, GNOME_FONT_BOLD, FALSE); - - font_size = yinc * 0.33; - max_font_size = width * 0.25; - minute_font_size = MIN (font_size, max_font_size); - font_minute = get_font_for_size (minute_font_size, GNOME_FONT_BOLD, FALSE); - - use_24_hour = calendar_config_get_24_hour_format (); - - row = 0; - for (i = pdi->start_hour; i < pdi->end_hour; i++) { - y = top - yinc * (row + 1); - gnome_print_setrgbcolor (pc, 0, 0, 0); - - if (use_24_hour) { - hour = i; - minute = "00"; - } else { - if (i < 12) - minute = _("am"); - else - minute = _("pm"); - - hour = i % 12; - if (hour == 0) - hour = 12; - } - - /* the hour label/minute */ - sprintf (buf, "%d", hour); - print_text (pc, font_hour, buf, ALIGN_RIGHT, - left, left + width * 0.58, - y + yinc - 4, y + yinc - 4 - hour_font_size); - print_text (pc, font_minute, minute, ALIGN_RIGHT, - left, left + width - 3, - y + yinc - 3, y + yinc - 3 - minute_font_size); - - /* Draw the horizontal line between hours, across the entire - width of the day view. */ - gnome_print_moveto (pc, left, y); - gnome_print_lineto (pc, right, y); - gnome_print_stroke (pc); - - /* Draw the horizontal line for the 1/2-hours, across the - entire width except for part of the time column. */ - gnome_print_moveto (pc, left + width * 0.6, y + yinc / 2); - gnome_print_lineto (pc, right, y + yinc / 2); - gnome_print_stroke (pc); - - row++; - } - - g_object_unref (font_hour); - g_object_unref (font_minute); -} - - -/* This adds one event to the view, adding it to the appropriate array. */ -static gint -print_day_add_event (CalComponent *comp, - time_t start, - time_t end, - gint days_shown, - time_t *day_starts, - GArray *long_events, - GArray **events) - -{ - icaltimezone *zone = get_timezone (); - EDayViewEvent event; - gint day, offset; - struct icaltimetype start_tt, end_tt; - -#if 0 - g_print ("Day view lower: %s", ctime (&day_starts[0])); - g_print ("Day view upper: %s", ctime (&day_starts[days_shown])); - g_print ("Event start: %s", ctime (&start)); - g_print ("Event end : %s\n", ctime (&end)); -#endif - - /* Check that the event times are valid. */ - g_return_val_if_fail (start <= end, -1); - g_return_val_if_fail (start < day_starts[days_shown], -1); - g_return_val_if_fail (end > day_starts[0], -1); - - start_tt = icaltime_from_timet_with_zone (start, FALSE, zone); - end_tt = icaltime_from_timet_with_zone (end, FALSE, zone); - - event.comp = comp; - g_object_ref (comp); - event.start = start; - event.end = end; - event.canvas_item = NULL; - - /* Calculate the start & end minute, relative to the top of the - display. */ - /*offset = day_view->first_hour_shown * 60 - + day_view->first_minute_shown;*/ - offset = 0; - event.start_minute = start_tt.hour * 60 + start_tt.minute - offset; - event.end_minute = end_tt.hour * 60 + end_tt.minute - offset; - - event.start_row_or_col = 0; - event.num_columns = 0; - - /* Find out which array to add the event to. */ - for (day = 0; day < days_shown; day++) { - if (start >= day_starts[day] && end <= day_starts[day + 1]) { - - /* Special case for when the appointment ends at - midnight, i.e. the start of the next day. */ - if (end == day_starts[day + 1]) { - - /* If the event last the entire day, then we - skip it here so it gets added to the top - canvas. */ - if (start == day_starts[day]) - break; - - event.end_minute = 24 * 60; - } - - g_array_append_val (events[day], event); - return day; - } - } - - /* The event wasn't within one day so it must be a long event, - i.e. shown in the top canvas. */ - g_array_append_val (long_events, event); - return E_DAY_VIEW_LONG_EVENT; -} - - -static gboolean -print_day_details_cb (CalComponent *comp, time_t istart, time_t iend, - gpointer data) -{ - struct pdinfo *pdi = (struct pdinfo *)data; - - print_day_add_event (comp, istart, iend, - pdi->days_shown, pdi->day_starts, - pdi->long_events, pdi->events); - - return TRUE; -} - - -static void -free_event_array (GArray *array) -{ - EDayViewEvent *event; - gint event_num; - - for (event_num = 0; event_num < array->len; event_num++) { - event = &g_array_index (array, EDayViewEvent, event_num); - if (event->canvas_item) - gtk_object_destroy (GTK_OBJECT (event->canvas_item)); - g_object_unref (event->comp); - } - - g_array_set_size (array, 0); -} - - -static void -print_day_long_event (GnomePrintContext *pc, GnomeFont *font, - double left, double right, double top, double bottom, - double row_height, EDayViewEvent *event, - struct pdinfo *pdi) -{ - CalComponentText summary; - double x1, x2, y1, y2; - double left_triangle_width = -1.0, right_triangle_width = -1.0; - char *text; - char buffer[32]; - struct tm date_tm; - - /* If the event starts before the first day being printed, draw a - triangle. (Note that I am assuming we are just showing 1 day at - the moment.) */ - if (event->start < pdi->day_starts[0]) - left_triangle_width = 4; - - /* If the event ends after the last day being printed, draw a - triangle. */ - if (event->end > pdi->day_starts[1]) - right_triangle_width = 4; - - x1 = left + 10; - x2 = right - 10; - y1 = top - event->start_row_or_col * row_height - 4; - y2 = y1 - row_height + 4; - print_border_with_triangles (pc, x1, x2, y1, y2, 0.5, 0.95, - left_triangle_width, - right_triangle_width); - - /* If the event starts after the first day being printed, we need to - print the start time. */ - if (event->start > pdi->day_starts[0]) { - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->start_minute / 60; - date_tm.tm_min = event->start_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, pdi->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - x1 += 4; - print_text (pc, font, buffer, ALIGN_LEFT, x1, x2, y1, y2); - x1 += gnome_font_get_width_utf8 (font, buffer); - } - - /* If the event ends before the end of the last day being printed, - we need to print the end time. */ - if (event->end < pdi->day_starts[1]) { - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->end_minute / 60; - date_tm.tm_min = event->end_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, pdi->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - x2 -= 4; - print_text (pc, font, buffer, ALIGN_RIGHT, x1, x2, y1, y2); - x2 -= gnome_font_get_width_utf8 (font, buffer); - } - - /* Print the text. */ - cal_component_get_summary (event->comp, &summary); - text = summary.value ? (char*) summary.value : ""; - - x1 += 4; - x2 -= 4; - print_text (pc, font, text, ALIGN_CENTER, x1, x2, y1, y2); -} - - -static void -print_day_event (GnomePrintContext *pc, GnomeFont *font, - double left, double right, double top, double bottom, - EDayViewEvent *event, struct pdinfo *pdi) -{ - CalComponentText summary; - double x1, x2, y1, y2, col_width, row_height; - int start_offset, end_offset, start_row, end_row; - char *text, start_buffer[32], end_buffer[32]; - gboolean display_times = FALSE, free_text = FALSE; - struct tm date_tm; - - if ((event->start_minute >= pdi->end_minute_offset) - || (event->end_minute <= pdi->start_minute_offset)) - return; - - start_offset = event->start_minute - pdi->start_minute_offset; - end_offset = event->end_minute - pdi->start_minute_offset; - - start_row = start_offset / pdi->mins_per_row; - start_row = MAX (0, start_row); - end_row = (end_offset - 1) / pdi->mins_per_row; - end_row = MIN (pdi->rows - 1, end_row); - col_width = (right - left) / pdi->cols_per_row[event->start_minute / pdi->mins_per_row]; - - if (start_offset != start_row * pdi->mins_per_row - || end_offset != (end_row + 1) * pdi->mins_per_row) - display_times = TRUE; - - x1 = left + event->start_row_or_col * col_width; - x2 = x1 + event->num_columns * col_width - DAY_VIEW_EVENT_X_PAD; - - row_height = (top - bottom) / pdi->rows; - y1 = top - start_row * row_height; - y2 = top - (end_row + 1) * row_height; - -#if 0 - g_print ("Event: %g,%g %g,%g\n row_height: %g start_row: %i top: %g rows: %i\n", - x1, y1, x2, y2, row_height, start_row, top, pdi->rows); -#endif - - print_border (pc, x1, x2, y1, y2, 1.0, 0.95); - - cal_component_get_summary (event->comp, &summary); - text = summary.value ? (char*) summary.value : ""; - - - if (display_times) { - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->start_minute / 60; - date_tm.tm_min = event->start_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, pdi->use_24_hour_format, FALSE, - start_buffer, sizeof (start_buffer)); - - date_tm.tm_hour = event->end_minute / 60; - date_tm.tm_min = event->end_minute % 60; - - e_time_format_time (&date_tm, pdi->use_24_hour_format, FALSE, - end_buffer, sizeof (end_buffer)); - - text = g_strdup_printf ("%s - %s %s ", start_buffer, - end_buffer, text); - - free_text = TRUE; - } - - bound_text (pc, font, text, x1 + 2, x2 - 2, y1, y2, 0); - - if (free_text) - g_free (text); -} - - -static void -print_day_details (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - CalClient *client; - EDayViewEvent *event; - GnomeFont *font; - time_t start, end; - struct pdinfo pdi; - gint rows_in_top_display, i; - double font_size, max_font_size; - - start = time_day_begin_with_zone (whence, zone); - end = time_day_end_with_zone (start, zone); - - pdi.days_shown = 1; - pdi.day_starts[0] = start; - pdi.day_starts[1] = end; - pdi.long_events = g_array_new (FALSE, FALSE, sizeof (EDayViewEvent)); - pdi.events[0] = g_array_new (FALSE, FALSE, sizeof (EDayViewEvent)); - pdi.start_hour = calendar_config_get_day_start_hour (); - pdi.end_hour = calendar_config_get_day_end_hour (); - if (calendar_config_get_day_end_minute () != 0) - pdi.end_hour++; - pdi.rows = (pdi.end_hour - pdi.start_hour) * 2; - pdi.mins_per_row = 30; - pdi.start_minute_offset = pdi.start_hour * 60; - pdi.end_minute_offset = pdi.end_hour * 60; - pdi.use_24_hour_format = calendar_config_get_24_hour_format (); - - /* Get the events from the server. */ - client = gnome_calendar_get_cal_client (gcal); - cal_client_generate_instances (client, CALOBJ_TYPE_EVENT, start, end, - print_day_details_cb, &pdi); - qsort (pdi.long_events->data, pdi.long_events->len, - sizeof (EDayViewEvent), e_day_view_event_sort_func); - qsort (pdi.events[0]->data, pdi.events[0]->len, - sizeof (EDayViewEvent), e_day_view_event_sort_func); - - /* Also print events outside of work hours */ - if (pdi.events[0]->len > 0) { - icaltimezone *zone = get_timezone (); - struct icaltimetype tt; - - event = &g_array_index (pdi.events[0], EDayViewEvent, 0); - tt = icaltime_from_timet_with_zone (event->start, FALSE, zone); - if (tt.hour < pdi.start_hour) - pdi.start_hour = tt.hour; - pdi.start_minute_offset = pdi.start_hour * 60; - - event = &g_array_index (pdi.events[0], EDayViewEvent, pdi.events[0]->len - 1); - tt = icaltime_from_timet_with_zone (event->end, FALSE, zone); - if (tt.hour > pdi.end_hour || tt.hour == 0) { - pdi.end_hour = tt.hour ? tt.hour : 24; - if (tt.minute > 0) - pdi.end_hour++; - } - pdi.end_minute_offset = pdi.end_hour * 60; - - pdi.rows = (pdi.end_hour - pdi.start_hour) * 2; - } - - /* Lay them out the long events, across the top of the page. */ - e_day_view_layout_long_events (pdi.long_events, pdi.days_shown, - pdi.day_starts, &rows_in_top_display); - - /* Print the long events. */ - font = get_font_for_size (12, GNOME_FONT_BOOK, FALSE); - for (i = 0; i < pdi.long_events->len; i++) { - event = &g_array_index (pdi.long_events, EDayViewEvent, i); - print_day_long_event (pc, font, left, right, top, bottom, - DAY_VIEW_ROW_HEIGHT, event, &pdi); - } - g_object_unref (font); - - /* We always leave space for DAY_VIEW_MIN_ROWS_IN_TOP_DISPLAY in the - top display, but we may have more rows than that, in which case - the main display area will be compressed. */ - rows_in_top_display = MAX (rows_in_top_display, - DAY_VIEW_MIN_ROWS_IN_TOP_DISPLAY); - - /* Draw the border around the long events. */ - gnome_print_setrgbcolor (pc, 0, 0, 0); - print_border (pc, left, right, - top, top - rows_in_top_display * DAY_VIEW_ROW_HEIGHT - 4, - 1.0, -1.0); - - /* Adjust the area containing the main display. */ - top -= rows_in_top_display * DAY_VIEW_ROW_HEIGHT + 4; - - /* Draw the borders, lines, and times down the left. */ - print_day_background (pc, gcal, whence, &pdi, - left, right, top, bottom); - - /* Now adjust to get rid of the time column. */ - left += DAY_VIEW_TIME_COLUMN_WIDTH; - - /* Lay out the short events, within the day. */ - e_day_view_layout_day_events (pdi.events[0], DAY_VIEW_ROWS, - DAY_VIEW_MINS_PER_ROW, pdi.cols_per_row); - - /* Print the short events. */ - max_font_size = ((top - bottom) / pdi.rows) - 4; - font_size = MIN (DAY_NORMAL_FONT_SIZE, max_font_size); - font = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); - for (i = 0; i < pdi.events[0]->len; i++) { - event = &g_array_index (pdi.events[0], EDayViewEvent, i); - print_day_event (pc, font, left, right, top, bottom, - event, &pdi); - } - g_object_unref (font); - - /* Free everything. */ - free_event_array (pdi.long_events); - g_array_free (pdi.long_events, TRUE); - free_event_array (pdi.events[0]); - g_array_free (pdi.events[0], TRUE); -} - - -/* This adds one event to the view, adding it to the appropriate array. */ -static gboolean -print_week_summary_cb (CalComponent *comp, - time_t start, - time_t end, - gpointer data) - -{ - icaltimezone *zone = get_timezone (); - EWeekViewEvent event; - struct icaltimetype start_tt, end_tt; - - struct psinfo *psi = (struct psinfo *)data; - - /* Check that the event times are valid. */ - -#if 0 - g_print ("View start:%li end:%li Event start:%li end:%li\n", - psi->day_starts[0], psi->day_starts[psi->days_shown], - start, end); -#endif - - g_return_val_if_fail (start <= end, TRUE); - g_return_val_if_fail (start < psi->day_starts[psi->days_shown], TRUE); - g_return_val_if_fail (end > psi->day_starts[0], TRUE); - - start_tt = icaltime_from_timet_with_zone (start, FALSE, zone); - end_tt = icaltime_from_timet_with_zone (end, FALSE, zone); - - event.comp = comp; - g_object_ref (event.comp); - event.start = start; - event.end = end; - event.spans_index = 0; - event.num_spans = 0; - - event.start_minute = start_tt.hour * 60 + start_tt.minute; - event.end_minute = end_tt.hour * 60 + end_tt.minute; - if (event.end_minute == 0 && start != end) - event.end_minute = 24 * 60; - - g_array_append_val (psi->events, event); - - return TRUE; -} - - -/* Returns TRUE if the event is a one-day event (i.e. not a long event). */ -static gboolean -print_is_one_day_week_event (EWeekViewEvent *event, - EWeekViewEventSpan *span, - time_t *day_starts) -{ - if (event->start == day_starts[span->start_day] - && event->end == day_starts[span->start_day + 1]) - return FALSE; - - if (span->num_days == 1 - && event->start >= day_starts[span->start_day] - && event->end <= day_starts[span->start_day + 1]) - return TRUE; - - return FALSE; -} - - -static void -print_week_long_event (GnomePrintContext *pc, GnomeFont *font, - struct psinfo *psi, - double x1, double x2, double y1, double y2, - EWeekViewEvent *event, EWeekViewEventSpan *span, - char *text) -{ - double left_triangle_width = -1.0, right_triangle_width = -1.0; - struct tm date_tm; - char buffer[32]; - - /* If the event starts before the first day of the span, draw a - triangle to indicate it continues. */ - if (event->start < psi->day_starts[span->start_day]) - left_triangle_width = 4; - - /* If the event ends after the last day of the span, draw a - triangle. */ - if (event->end > psi->day_starts[span->start_day + span->num_days]) - right_triangle_width = 4; - - print_border_with_triangles (pc, x1, x2, y1, y2, 0.5, 0.9, - left_triangle_width, - right_triangle_width); - - /* If the event starts after the first day being printed, we need to - print the start time. */ - if (event->start > psi->day_starts[span->start_day]) { - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->start_minute / 60; - date_tm.tm_min = event->start_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - x1 += 4; - print_text_size (pc, buffer, ALIGN_LEFT, x1, x2, y1, y2); - x1 += gnome_font_get_width_utf8 (font, buffer); - } - - /* If the event ends before the end of the last day being printed, - we need to print the end time. */ - if (event->end < psi->day_starts[span->start_day + span->num_days]) { - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->end_minute / 60; - date_tm.tm_min = event->end_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - x2 -= 4; - print_text_size (pc, buffer, ALIGN_RIGHT, x1, x2, y1, y2); - x2 -= gnome_font_get_width_utf8 (font, buffer); - } - - x1 += 4; - x2 -= 4; - print_text_size (pc, text, ALIGN_CENTER, x1, x2, y1, y2); -} - - -static void -print_week_day_event (GnomePrintContext *pc, GnomeFont *font, - struct psinfo *psi, - double x1, double x2, double y1, double y2, - EWeekViewEvent *event, EWeekViewEventSpan *span, - char *text) -{ - struct tm date_tm; - char buffer[32]; - - date_tm.tm_year = 2001; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = event->start_minute / 60; - date_tm.tm_min = event->start_minute % 60; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - - e_time_format_time (&date_tm, psi->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - print_text_size (pc, buffer, ALIGN_LEFT, x1, x2, y1, y2); - x1 += gnome_font_get_width_utf8 (font, buffer); - - x1 += 4; - print_text_size (pc, text, ALIGN_LEFT, x1, x2, y1, y2); -} - - -static void -print_week_event (GnomePrintContext *pc, GnomeFont *font, - struct psinfo *psi, - double left, double top, - double cell_width, double cell_height, - EWeekViewEvent *event, GArray *spans) -{ - EWeekViewEventSpan *span; - gint span_num; - CalComponentText summary; - char *text; - int num_days, start_x, start_y, start_h, end_x, end_y, end_h; - double x1, x2, y1, y2; - - cal_component_get_summary (event->comp, &summary); - text = summary.value ? (char*) summary.value : ""; - - for (span_num = 0; span_num < event->num_spans; span_num++) { - span = &g_array_index (spans, EWeekViewEventSpan, - event->spans_index + span_num); - - if (e_week_view_layout_get_span_position - (event, span, - psi->rows_per_cell, - psi->rows_per_compressed_cell, - psi->display_start_weekday, - psi->multi_week_view, - psi->compress_weekend, - &num_days)) { - - e_week_view_layout_get_day_position - (span->start_day, - psi->multi_week_view, - psi->weeks_shown, - psi->display_start_weekday, - psi->compress_weekend, - &start_x, &start_y, &start_h); - - if (num_days == 1) { - end_x = start_x; - end_y = start_y; - end_h = start_h; - } else { - e_week_view_layout_get_day_position - (span->start_day + num_days - 1, - psi->multi_week_view, - psi->weeks_shown, - psi->display_start_weekday, - psi->compress_weekend, - &end_x, &end_y, &end_h); - } - - x1 = left + start_x * cell_width + 6; - x2 = left + (end_x + 1) * cell_width - 6; - y1 = top - start_y * cell_height - - psi->header_row_height - - span->row * psi->row_height; - y2 = y1 - psi->row_height * 0.9; - - if (print_is_one_day_week_event (event, span, - psi->day_starts)) { - print_week_day_event (pc, font, psi, - x1, x2, y1, y2, - event, span, text); - } else { - print_week_long_event (pc, font, psi, - x1, x2, y1, y2, - event, span, text); - } - } - } -} - - -static void -print_week_view_background (GnomePrintContext *pc, GnomeFont *font, - struct psinfo *psi, - double left, double top, - double cell_width, double cell_height) -{ - icaltimezone *zone = get_timezone (); - int day, day_x, day_y, day_h; - double x1, x2, y1, y2, font_size, fillcolor; - struct tm tm; - char *format_string, buffer[128], *utf_str; - - font_size = gnome_font_get_size (font); - - for (day = 0; day < psi->days_shown; day++) { - e_week_view_layout_get_day_position - (day, psi->multi_week_view, psi->weeks_shown, - psi->display_start_weekday, psi->compress_weekend, - &day_x, &day_y, &day_h); - - x1 = left + day_x * cell_width; - x2 = left + (day_x + 1) * cell_width; - y1 = top - day_y * cell_height; - y2 = y1 - day_h * cell_height; - - tm = *convert_timet_to_struct_tm (psi->day_starts[day], zone); - - /* In the month view we draw a grey background for the end - of the previous month and the start of the following. */ - fillcolor = -1.0; - if (psi->multi_week_view && (tm.tm_mon != psi->month)) - fillcolor = 0.9; - - print_border (pc, x1, x2, y1, y2, 1.0, fillcolor); - - if (psi->multi_week_view) { - if (tm.tm_mday == 1) - format_string = _("%d %B"); - else - format_string = "%d"; - } else { - gnome_print_moveto (pc, x1 + 0.1 * cell_width, - y1 - psi->header_row_height + 3); - gnome_print_lineto (pc, x2, - y1 - psi->header_row_height + 3); - gnome_print_setrgbcolor (pc, 0, 0, 0); - gnome_print_setlinewidth (pc, 0.5); - gnome_print_stroke (pc); - - /* strftime format %A = full weekday name, %d = day of - month, %B = full month name. You can change the - order but don't change the specifiers or add - anything. */ - format_string = _("%A %d %B"); - - } - - strftime (buffer, sizeof (buffer), format_string, &tm); - utf_str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); - print_text_size (pc, utf_str, ALIGN_RIGHT, - x1, x2 - 4, y1 - 2, y1 - 2 - font_size); - g_free (utf_str); - } -} - - - -static void -print_week_summary (GnomePrintContext *pc, GnomeCalendar *gcal, - time_t whence, gboolean multi_week_view, int weeks_shown, - int month, double font_size, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - CalClient *client; - EWeekViewEvent *event; - struct psinfo psi; - time_t day_start; - gint rows_per_day[E_WEEK_VIEW_MAX_WEEKS * 7], day, event_num; - GArray *spans; - GnomeFont *font; - double cell_width, cell_height; - - psi.days_shown = weeks_shown * 7; - psi.events = g_array_new (FALSE, FALSE, sizeof (EWeekViewEvent)); - psi.multi_week_view = multi_week_view; - psi.weeks_shown = weeks_shown; - psi.month = month; - - /* Get a few config settings. */ - if (multi_week_view) - psi.compress_weekend = calendar_config_get_compress_weekend (); - else - psi.compress_weekend = TRUE; - psi.use_24_hour_format = calendar_config_get_24_hour_format (); - - /* We convert this from (0 = Sun, 6 = Sat) to (0 = Mon, 6 = Sun). */ - psi.display_start_weekday = calendar_config_get_week_start_day (); - psi.display_start_weekday = (psi.display_start_weekday + 6) % 7; - - /* If weekends are compressed then we can't start on a Sunday. */ - if (psi.compress_weekend && psi.display_start_weekday == 6) - psi.display_start_weekday = 5; - - day_start = time_day_begin_with_zone (whence, zone); - for (day = 0; day <= psi.days_shown; day++) { - psi.day_starts[day] = day_start; - day_start = time_add_day_with_zone (day_start, 1, zone); - } - - /* Get the events from the server. */ - client = gnome_calendar_get_cal_client (gcal); - cal_client_generate_instances (client, CALOBJ_TYPE_EVENT, - psi.day_starts[0], - psi.day_starts[psi.days_shown], - print_week_summary_cb, &psi); - qsort (psi.events->data, psi.events->len, - sizeof (EWeekViewEvent), e_week_view_event_sort_func); - - /* Layout the events. */ - spans = e_week_view_layout_events (psi.events, NULL, - psi.multi_week_view, - psi.weeks_shown, - psi.compress_weekend, - psi.display_start_weekday, - psi.day_starts, rows_per_day); - - /* Calculate the size of the cells. */ - if (multi_week_view) { - cell_width = (right - left) / (psi.compress_weekend ? 6 : 7); - cell_height = (top - bottom) / (weeks_shown * 2); - } else { - cell_width = (right - left) / 2; - cell_height = (top - bottom) / 6; - } - - /* Calculate the row height, using the normal font and with room for - space or a rectangle around it. */ - psi.row_height = font_size * 1.2; - psi.header_row_height = font_size * 1.5; - - /* Calculate how many rows we can fit into each type of cell. */ - psi.rows_per_cell = ((cell_height * 2) - psi.header_row_height) - / psi.row_height; - psi.rows_per_compressed_cell = (cell_height - psi.header_row_height) - / psi.row_height; - - font = get_font_for_size (font_size, GNOME_FONT_BOOK, FALSE); - - /* Draw the grid and the day names/numbers. */ - print_week_view_background (pc, font, &psi, left, top, - cell_width, cell_height); - - /* Print the events. */ - for (event_num = 0; event_num < psi.events->len; event_num++) { - event = &g_array_index (psi.events, EWeekViewEvent, event_num); - print_week_event (pc, font, &psi, left, top, - cell_width, cell_height, event, spans); - } - - g_object_unref (font); - - /* Free everything. */ - for (event_num = 0; event_num < psi.events->len; event_num++) { - event = &g_array_index (psi.events, EWeekViewEvent, event_num); - g_object_unref (event->comp); - } - g_array_free (psi.events, TRUE); - g_array_free (spans, TRUE); -} - - -static void -print_year_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, - double left, double right, double top, double bottom, - int morerows) -{ - icaltimezone *zone = get_timezone (); - double row_height, col_width, l, r, t, b; - time_t now; - int col, row, rows, cols; - - l = left; - t = top; - - /* If morerows is set we do 4 rows and 3 columns instead of 3 rows and - 4 columns. This is useful if we switch paper orientation. */ - if (morerows) { - rows = 4; - cols = 3; - } else { - rows = 3; - cols = 4; - } - - row_height = (top - bottom) / rows; - col_width = (right - left) / cols; - r = l + col_width; - b = top - row_height; - now = time_year_begin_with_zone (whence, zone); - - for (row = 0; row < rows; row++) { - t = top - row_height * row; - b = t - row_height; - for (col = 0; col < cols; col++) { - l = left + col_width * col; - r = l + col_width; - print_month_small (pc, gcal, now, - l + 8, r - 8, t - 8, b + 8, - DATE_MONTH, 0, 0, TRUE); - now = time_add_month_with_zone (now, 1, zone); - } - } -} - -static void -print_month_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - time_t date; - struct tm tm; - struct icaltimetype tt; - char buffer[100]; - GnomeFont *font; - gboolean compress_weekend; - int columns, col, weekday, len, month; - double font_size, cell_width, x1, x2, y1, y2; - - weekday = calendar_config_get_week_start_day (); - compress_weekend = calendar_config_get_compress_weekend (); - - /* Remember which month we want. */ - tt = icaltime_from_timet_with_zone (whence, FALSE, zone); - month = tt.month - 1; - - /* Find the start of the month, and then the start of the week on - or before that day. */ - date = time_month_begin_with_zone (whence, zone); - date = time_week_begin_with_zone (date, weekday, zone); - - /* If weekends are compressed then we can't start on a Sunday. */ - if (compress_weekend && weekday == 0) - date = time_add_day_with_zone (date, -1, zone); - - /* do day names ... */ - - /* We are only interested in outputting the weekday here, but we want - to be able to step through the week without worrying about - overflows making strftime choke, so we move near to the start of - the month. */ - tm = *convert_timet_to_struct_tm (date, zone); - tm.tm_mday = (tm.tm_mday % 7) + 7; - - font = get_font_for_size (MONTH_NORMAL_FONT_SIZE, GNOME_FONT_BOLD, FALSE); - font_size = gnome_font_get_size (font); - gnome_print_setfont (pc, font); - - columns = compress_weekend ? 6 : 7; - cell_width = (right - left) / columns; - y1 = top; - y2 = top - font_size * 1.5; - - for (col = 0; col < columns; col++) { - char *utf_str; - - if (tm.tm_wday == 6 && compress_weekend) { - strftime (buffer, sizeof (buffer), "%a/", &tm); - len = strlen (buffer); - tm.tm_mday++; - tm.tm_wday = (tm.tm_wday + 1) % 7; - strftime (buffer + len, sizeof (buffer) - len, - "%a", &tm); - } else { - strftime (buffer, sizeof (buffer), "%A", &tm); - } - - x1 = left + cell_width * col; - x2 = x1 + cell_width; - - print_border (pc, x1, x2, y1, y2, 1.0, -1.0); - utf_str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); - print_text_size (pc, utf_str, ALIGN_CENTER, x1, x2, y1, y2); - g_free (utf_str); - - tm.tm_mday++; - tm.tm_wday = (tm.tm_wday + 1) % 7; - } - g_object_unref (font); - - top = y2; - print_week_summary (pc, gcal, date, TRUE, 6, month, - MONTH_NORMAL_FONT_SIZE, - left, right, top, bottom); -} - - -static void -print_todo_details (GnomePrintContext *pc, GnomeCalendar *gcal, - time_t start, time_t end, - double left, double right, double top, double bottom) -{ - CalClient *client; - GnomeFont *font_summary; - double y, yend, x, xend; - struct icaltimetype *tt; - ECalendarTable *task_pad; - ETable *table; - CalendarModel *model; - gint rows, row; - - /* We get the tasks directly from the TaskPad ETable. This means we - get them filtered & sorted for free. */ - task_pad = gnome_calendar_get_task_pad (gcal); - table = e_calendar_table_get_table (task_pad); - model = e_calendar_table_get_model (task_pad); - client = gnome_calendar_get_task_pad_cal_client (gcal); - - font_summary = get_font_for_size (10, GNOME_FONT_BOOK, FALSE); - - gnome_print_setrgbcolor (pc, 0, 0, 0); - gnome_print_setlinewidth (pc, 0.0); - - titled_box (pc, _("Tasks"), font_summary, ALIGN_CENTER | ALIGN_BORDER, - &left, &right, &top, &bottom, 1.0); - - y = top - 3; - yend = bottom - 2; - - rows = e_table_model_row_count (E_TABLE_MODEL (model)); - for (row = 0; row < rows; row++) { - CalComponent *comp; - CalComponentText summary; - int model_row; - - model_row = e_table_view_to_model_row (table, row); - comp = calendar_model_get_component (model, model_row); - - cal_component_get_summary (comp, &summary); - - if (!summary.value) - continue; - - x = left; - xend = right - 2; - - if (y < bottom) - break; - - /* Print the box to put the tick in. */ - print_border (pc, x + 2, x + 8, y - 3, y - 11, 0.1, -1.0); - - /* If the task is complete, print a tick in the box. */ - cal_component_get_completed (comp, &tt); - if (tt) { - cal_component_free_icaltimetype (tt); - - gnome_print_setrgbcolor (pc, 0, 0, 0); - gnome_print_setlinewidth (pc, 1.0); - gnome_print_moveto (pc, x + 3, y - 8); - gnome_print_lineto (pc, x + 5, y - 10); - gnome_print_lineto (pc, x + 7, y - 3.5); - gnome_print_stroke (pc); - } - - y = bound_text (pc, font_summary, summary.value, - x + 10, xend, y, yend, 0); - y += gnome_font_get_size (font_summary) - 6; - gnome_print_moveto (pc, x, y); - gnome_print_lineto (pc, xend, y); - gnome_print_stroke (pc); - y -= 3; - } - - g_object_unref (font_summary); -} - - -/* Value for the PrintView enum */ -static const int print_view_map[] = { - PRINT_VIEW_DAY, - PRINT_VIEW_WEEK, - PRINT_VIEW_MONTH, - PRINT_VIEW_YEAR, - -1 -}; - -/* Creates the range selector widget for printing a calendar */ -static GtkWidget * -range_selector_new (GtkWidget *dialog, time_t at, int *view) -{ - icaltimezone *zone = get_timezone (); - GtkWidget *box; - GtkWidget *radio; - GSList *group; - char text[1024]; - char str1[512]; - char str2[512]; - struct tm tm; - time_t week_begin, week_end; - struct tm week_begin_tm, week_end_tm; - gint week_start_day; - - box = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - - tm = *convert_timet_to_struct_tm (at, zone); - - /* Day */ - - strftime (text, sizeof (text), _("Selected day (%a %b %d %Y)"), &tm); - radio = gtk_radio_button_new_with_label (NULL, text); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Week */ - - week_start_day = calendar_config_get_week_start_day (); - week_begin = time_week_begin_with_zone (at, week_start_day, zone); - /* If the week starts on a Sunday, we have to show the Saturday first, - since the weekend is compressed. If the original date passed in was - a Saturday, we need to move on to the next Saturday, else we move - back to the last one. */ - if (week_start_day == 0) { - if (tm.tm_wday == 6) - week_begin = time_add_day_with_zone (week_begin, 6, zone); - else - week_begin = time_add_day_with_zone (week_begin, -1, zone); - } - week_end = time_add_day_with_zone (week_begin, 6, zone); - - week_begin_tm = *convert_timet_to_struct_tm (week_begin, zone); - week_end_tm = *convert_timet_to_struct_tm (week_end, zone); - - if (week_begin_tm.tm_mon == week_end_tm.tm_mon) { - strftime (str1, sizeof (str1), _("%a %b %d"), &week_begin_tm); - strftime (str2, sizeof (str2), _("%a %d %Y"), &week_end_tm); - } else { - if (week_begin_tm.tm_year == week_end_tm.tm_year) { - strftime (str1, sizeof (str1), _("%a %b %d"), &week_begin_tm); - strftime (str2, sizeof (str2), _("%a %b %d %Y"), &week_end_tm); - } else { - strftime (str1, sizeof (str1), _("%a %b %d %Y"), &week_begin_tm); - strftime (str2, sizeof (str2), _("%a %b %d %Y"), &week_end_tm); - } - } - - g_snprintf (text, sizeof (text), _("Selected week (%s - %s)"), str1, str2); - - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Month */ - - strftime (text, sizeof (text), _("Selected month (%b %Y)"), &tm); - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Year */ - - strftime (text, sizeof (text), _("Selected year (%Y)"), &tm); - radio = gtk_radio_button_new_with_label (group, text); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio)); - gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0); - - /* Select default */ - - e_dialog_widget_hook_value (dialog, radio, view, (gpointer) print_view_map); - - gtk_widget_show_all (box); - return box; -} - - -static void -print_day_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - int i, days = 1; - double todo, header, l; - char buf[100]; - - for (i = 0; i < days; i++) { - todo = (right - left) * 0.75 + left; - header = top - HEADER_HEIGHT; - - gnome_print_beginpage (pc, NULL); - - /* Print the main view with all the events in. */ - print_day_details (pc, gcal, date, - left, todo - 2.0, header, bottom); - - /* Print the TaskPad down the right. */ - print_todo_details (pc, gcal, 0, INT_MAX, - todo, right, header, bottom); - - /* Print the filled border around the header. */ - print_border (pc, left, right, top, header + 2.0, 1.0, 0.9); - - /* Print the 2 mini calendar-months. */ - l = right - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 - - SMALL_MONTH_SPACING; - print_month_small (pc, gcal, date, - l, l + SMALL_MONTH_WIDTH, - top - 4, header + 4, - DATE_MONTH | DATE_YEAR, date, date, FALSE); - - l += SMALL_MONTH_SPACING + SMALL_MONTH_WIDTH; - print_month_small (pc, gcal, - time_add_month_with_zone (date, 1, zone), - l, l + SMALL_MONTH_WIDTH, - top - 4, header + 4, - DATE_MONTH | DATE_YEAR, 0, 0, FALSE); - - /* Print the date, e.g. '8th May, 2001'. */ - format_date (date, DATE_DAY | DATE_MONTH | DATE_YEAR, - buf, 100); - print_text_size_bold (pc, buf, ALIGN_LEFT, - left + 4, todo, top - 4, top - 4 - 24); - - /* Print the day, e.g. 'Tuesday'. */ - format_date (date, DATE_DAYNAME, buf, 100); - print_text_size_bold (pc, buf, ALIGN_LEFT, - left + 4, todo, top - 32, top - 32 - 18); - - gnome_print_showpage (pc); - date = time_add_day_with_zone (date, 1, zone); - } -} - - -static void -print_week_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - double header, l; - char buf[100]; - time_t when; - gint week_start_day; - struct tm tm; - - header = top - HEADER_HEIGHT; - - gnome_print_beginpage (pc, NULL); - - tm = *convert_timet_to_struct_tm (date, zone); - week_start_day = calendar_config_get_week_start_day (); - when = time_week_begin_with_zone (date, week_start_day, zone); - /* If the week starts on a Sunday, we have to show the Saturday first, - since the weekend is compressed. */ - if (week_start_day == 0) { - if (tm.tm_wday == 6) - when = time_add_day_with_zone (when, 6, zone); - else - when = time_add_day_with_zone (when, -1, zone); - } - - /* Print the main week view. */ - print_week_summary (pc, gcal, when, FALSE, 1, 0, - WEEK_NORMAL_FONT_SIZE, - left, right, header, bottom); - - /* Print the border around the main view. */ - print_border (pc, left, right, header, bottom, 1.0, -1.0); - - /* Print the border around the header area. */ - print_border (pc, left, right, top, header + 2.0, 1.0, 0.9); - - /* Print the 2 mini calendar-months. */ - l = right - SMALL_MONTH_PAD - SMALL_MONTH_WIDTH * 2 - - SMALL_MONTH_SPACING; - print_month_small (pc, gcal, when, - l, l + SMALL_MONTH_WIDTH, - top - 4, header + 4, - DATE_MONTH | DATE_YEAR, when, - time_add_week_with_zone (when, 1, zone), FALSE); - - l += SMALL_MONTH_SPACING + SMALL_MONTH_WIDTH; - print_month_small (pc, gcal, - time_add_month_with_zone (when, 1, zone), - l, l + SMALL_MONTH_WIDTH, - top - 4, header + 4, - DATE_MONTH | DATE_YEAR, when, - time_add_week_with_zone (when, 1, zone), FALSE); - - /* Print the start day of the week, e.g. '7th May 2001'. */ - format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pc, buf, ALIGN_LEFT, - left + 3, right, top - 4, top - 4 - 24); - - /* Print the end day of the week, e.g. '13th May 2001'. */ - when = time_add_day_with_zone (when, 6, zone); - format_date (when, DATE_DAY | DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pc, buf, ALIGN_LEFT, - left + 3, right, top - 24 - 3, top - 24 - 3 - 24); - - gnome_print_showpage (pc); -} - - -static void -print_month_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) -{ - icaltimezone *zone = get_timezone (); - double header; - char buf[100]; - - header = top - HEADER_HEIGHT; - - gnome_print_beginpage (pc, NULL); - - /* Print the main month view. */ - print_month_summary (pc, gcal, date, left, right, header, bottom); - - /* Print the border around the header. */ - print_border (pc, left, right, top, header, 1.0, 0.9); - - /* Print the 2 mini calendar-months. */ - print_month_small (pc, gcal, - time_add_month_with_zone (date, 1, zone), - right - (right - left) / 7 + 2, right - 8, - top - 4, header, - DATE_MONTH | DATE_YEAR, 0, 0, FALSE); - print_month_small (pc, gcal, - time_add_month_with_zone (date, -1, zone), - left + 8, left + (right - left) / 7 - 2, - top - 4, header, - DATE_MONTH | DATE_YEAR, 0, 0, FALSE); - - /* Print the month, e.g. 'May 2001'. */ - format_date (date, DATE_MONTH | DATE_YEAR, buf, 100); - print_text_size_bold (pc, buf, ALIGN_CENTER, - left + 3, right - 3, top - 3, top - 3 - 24); - - gnome_print_showpage (pc); -} - - -static void -print_year_view (GnomePrintContext *pc, GnomeCalendar *gcal, time_t date, - double left, double right, double top, double bottom) -{ - char buf[100]; - - gnome_print_beginpage (pc, NULL); - - print_year_summary (pc, gcal, date, left, right, top - 50, bottom, - TRUE); - - /* centered title */ - format_date (date, DATE_YEAR, buf, 100); - print_text_size_bold (pc, buf, ALIGN_CENTER, - left+3, right, top-3, top - 27); - - gnome_print_showpage (pc); -} - -static void -write_label_piece (time_t t, char *buffer, int size, char *stext, char *etext) -{ - icaltimezone *zone = get_timezone (); - struct tm *tmp_tm; - int len; - - tmp_tm = convert_timet_to_struct_tm (t, zone); - - if (stext != NULL) - strcat (buffer, stext); - - len = strlen (buffer); - e_time_format_date_and_time (tmp_tm, - calendar_config_get_24_hour_format (), - FALSE, FALSE, - &buffer[len], size - len); - if (etext != NULL) - strcat (buffer, etext); -} - -static icaltimezone* -get_zone_from_tzid (CalClient *client, const char *tzid) -{ - icaltimezone *zone; - - /* Note that the timezones may not be on the server, so we try to get - the builtin timezone with the TZID first. */ - zone = icaltimezone_get_builtin_timezone_from_tzid (tzid); - if (!zone) { - CalClientGetStatus status; - - status = cal_client_get_timezone (client, tzid, &zone); - /* FIXME: Handle error better. */ - if (status != CAL_CLIENT_GET_SUCCESS) - g_warning ("Couldn't get timezone from server: %s", - tzid ? tzid : ""); - } - - return zone; -} - -static void -print_date_label (GnomePrintContext *pc, CalComponent *comp, CalClient *client, - double left, double right, double top, double bottom) -{ - icaltimezone *start_zone, *end_zone, *due_zone, *completed_zone; - CalComponentDateTime datetime; - time_t start = 0, end = 0, complete = 0, due = 0; - static char buffer[1024], *utf_text; - - cal_component_get_dtstart (comp, &datetime); - if (datetime.value) { - start_zone = get_zone_from_tzid (client, datetime.tzid); - start = icaltime_as_timet_with_zone (*datetime.value, - start_zone); - } - cal_component_free_datetime (&datetime); - - cal_component_get_dtend (comp, &datetime); - if (datetime.value) { - end_zone = get_zone_from_tzid (client, datetime.tzid); - end = icaltime_as_timet_with_zone (*datetime.value, - end_zone); - } - cal_component_free_datetime (&datetime); - - cal_component_get_due (comp, &datetime); - if (datetime.value) { - due_zone = get_zone_from_tzid (client, datetime.tzid); - due = icaltime_as_timet_with_zone (*datetime.value, - due_zone); - } - cal_component_free_datetime (&datetime); - - cal_component_get_completed (comp, &datetime.value); - if (datetime.value) { - completed_zone = icaltimezone_get_utc_timezone (); - complete = icaltime_as_timet_with_zone (*datetime.value, - completed_zone); - cal_component_free_icaltimetype (datetime.value); - } - - buffer[0] = '\0'; - - if (start > 0) - write_label_piece (start, buffer, 1024, NULL, NULL); - - if (end > 0 && start > 0) - write_label_piece (end, buffer, 1024, _(" to "), NULL); - - if (complete > 0) { - if (start > 0) - write_label_piece (complete, buffer, 1024, _(" (Completed "), ")"); - else - write_label_piece (complete, buffer, 1024, _("Completed "), NULL); - } - - if (due > 0 && complete == 0) { - if (start > 0) - write_label_piece (due, buffer, 1024, _(" (Due "), ")"); - else - write_label_piece (due, buffer, 1024, _("Due "), NULL); - } - - utf_text = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); - print_text_size_bold (pc, utf_text, ALIGN_LEFT, - left, right, top, top - 15); - g_free (utf_text); -} - -static void -print_comp_item (GnomePrintContext *pc, CalComponent *comp, CalClient *client, - double left, double right, double top, double bottom) -{ - GnomeFont *font; - CalComponentVType vtype; - CalComponentText text; - GSList *desc, *l; - const char *title, *categories; - char *categories_string; - GSList *contact_list, *elem; - gint header_size; - - vtype = cal_component_get_vtype (comp); - - /* We should only be asked to print VEVENTs or VTODOs. */ - if (vtype == CAL_COMPONENT_EVENT) - title = _("Appointment"); - else if (vtype == CAL_COMPONENT_TODO) - title = _("Task"); - else - return; - - gnome_print_beginpage (pc, NULL); - - /* Print the title in a box at the top of the page. */ - font = get_font_for_size (18, GNOME_FONT_BOLD, FALSE); - header_size = 50; - print_border (pc, left, right, top, top - header_size, - 1.0, 0.9); - print_text (pc, font, title, ALIGN_CENTER, left, right, - top - header_size * 0.1, top - header_size); - g_object_unref (font); - - top -= header_size + 10; - - /* Summary */ - font = get_font_for_size (18, GNOME_FONT_BOLD, FALSE); - cal_component_get_summary (comp, &text); - top = bound_text (pc, font, text.value, left, right, - top - 3, bottom, 0); - g_object_unref (font); - - /* Date information */ - print_date_label (pc, comp, client, left, right, top-3, top - 15); - top -= 20; - - font = get_font_for_size (12, GNOME_FONT_BOOK, FALSE); - - /* For a VTODO we print the Status, Priority, % Complete and URL. */ - if (vtype == CAL_COMPONENT_TODO) { - icalproperty_status status; - const char *status_string = NULL; - int *percent; - int *priority; - const char *url; - - /* Status */ - cal_component_get_status (comp, &status); - if (status != ICAL_STATUS_NONE) { - switch (status) { - case ICAL_STATUS_NEEDSACTION: - status_string = _("Not Started"); - break; - case ICAL_STATUS_INPROCESS: - status_string = _("In Progress"); - break; - case ICAL_STATUS_COMPLETED: - status_string = _("Completed"); - break; - case ICAL_STATUS_CANCELLED: - status_string = _("Cancelled"); - break; - default: - break; - } - - if (status_string) { - char *text = g_strdup_printf (_("Status: %s"), - status_string); - top = bound_text (pc, font, text, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - g_free (text); - } - } - - /* Priority */ - cal_component_get_priority (comp, &priority); - if (priority && *priority >= 0) { - char *priority_string, *priority_utf8, *text; - - priority_string = cal_util_priority_to_string (*priority); - cal_component_free_priority (priority); - - priority_utf8 = g_locale_to_utf8 (priority_string, -1, NULL, NULL, NULL); - text = g_strdup_printf (_("Priority: %s"), - priority_utf8); - top = bound_text (pc, font, text, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - g_free (text); - g_free (priority_utf8); - } - - /* Percent Complete */ - cal_component_get_percent (comp, &percent); - if (percent) { - char *percent_string; - - percent_string = g_strdup_printf (_("Percent Complete: %i"), *percent); - cal_component_free_percent (percent); - - top = bound_text (pc, font, percent_string, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - } - - - /* URL */ - cal_component_get_url (comp, &url); - if (url && url[0]) { - char *url_string = g_strdup_printf (_("URL: %s"), - url); - - top = bound_text (pc, font, url_string, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - - g_free (url_string); - } - } - - /* Categories */ - cal_component_get_categories (comp, &categories); - if (categories && categories[0]) { - categories_string = g_strdup_printf (_("Categories: %s"), - categories); - top = bound_text (pc, font, categories_string, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - g_free (categories_string); - } - - /* Contacts */ - cal_component_get_contact_list (comp, &contact_list); - if (contact_list) { - GString *contacts = g_string_new (_("Contacts: ")); - for (elem = contact_list; elem; elem = elem->next) { - CalComponentText *t = elem->data; - /* Put a comma between contacts. */ - if (elem != contact_list) - g_string_append (contacts, ", "); - g_string_append (contacts, t->value); - } - cal_component_free_text_list (contact_list); - - top = bound_text (pc, font, contacts->str, - left, right, top, bottom, 0); - top += gnome_font_get_size (font) - 6; - - g_string_free (contacts, TRUE); - } - - top -= 16; - - /* Description */ - cal_component_get_description_list (comp, &desc); - for (l = desc; l != NULL; l = l->next) { - CalComponentText *text = l->data; - - if (text->value != NULL) - top = bound_text (pc, font, text->value, left, right, top-3, bottom, 0); - } - cal_component_free_text_list (desc); - g_object_unref (font); - - gnome_print_showpage (pc); -} - -void -print_calendar (GnomeCalendar *gcal, gboolean preview, time_t date, - PrintView default_view) -{ - GnomePrintJob *gpm; - GnomePrintContext *pc; - int copies, collate; - double l, r, t, b, temp_d; - gchar *old_orientation; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - if (!print_config) - print_config = gnome_print_config_default (); - - copies = 1; - collate = FALSE; - - gpm = gnome_print_job_new (print_config); - - if (!preview) { - GtkWidget *gpd; - GtkWidget *range; - int view; - - gpd = gnome_print_dialog_new (gpm, _("Print"), 0); - - view = (int) default_view; - range = range_selector_new (gpd, date, &view); - gnome_print_dialog_construct_range_custom (GNOME_PRINT_DIALOG (gpd), range); - - gtk_dialog_set_default_response (GTK_DIALOG (gpd), - GNOME_PRINT_DIALOG_RESPONSE_PRINT); - - /* Run dialog */ - - switch (gtk_dialog_run (GTK_DIALOG (gpd))) { - case GNOME_PRINT_DIALOG_RESPONSE_PRINT: - break; - - case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW: - preview = TRUE; - break; - - case -1: - return; - - default: - gtk_widget_destroy (gpd); - return; - } - - e_dialog_get_values (gpd); - default_view = (PrintView) view; - - gtk_widget_destroy (gpd); - } - - old_orientation = gnome_print_config_get (print_config, GNOME_PRINT_KEY_PAGE_ORIENTATION); - - if (default_view == PRINT_VIEW_MONTH) - gnome_print_config_set (print_config, GNOME_PRINT_KEY_PAGE_ORIENTATION, "R90"); - - pc = gnome_print_job_get_context (gpm); - gnome_print_config_get_page_size (print_config, &r, &t); - - /* See top of source for an explanation of this */ - - /* gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &temp_d); - * t -= temp_d; - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &temp_d); - * r -= temp_d; - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &b); - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &l); - * b = l = TEMP_MARGIN; */ - - b = t * TEMP_MARGIN; - l = r * TEMP_MARGIN; - t *= (1.0 - TEMP_MARGIN); - r *= (1.0 - TEMP_MARGIN); - - /* depending on the view, do a different output */ - switch (default_view) { - case PRINT_VIEW_DAY: - print_day_view (pc, gcal, date, l, r, t, b); - break; - case PRINT_VIEW_WEEK: - print_week_view (pc, gcal, date, l, r, t, b); - break; - case PRINT_VIEW_MONTH: - print_month_view (pc, gcal, date, l, r, t, b); - break; - case PRINT_VIEW_YEAR: - print_year_view (pc, gcal, date, l, r, t, b); - break; - default: - g_assert_not_reached (); - } - - gnome_print_job_close (gpm); - - if (preview) { - GtkWidget *gpmp; - - gpmp = gnome_print_job_preview_new (gpm, _("Print Preview")); - gtk_widget_show (gpmp); - } else { - gnome_print_job_print (gpm); - } - - gnome_print_config_set (print_config, GNOME_PRINT_KEY_PAGE_ORIENTATION, old_orientation); - g_free (old_orientation); - g_object_unref (gpm); -} - - -void -print_comp (CalComponent *comp, CalClient *client, gboolean preview) -{ - GnomePrintJob *gpm; - GnomePrintContext *pc; - int copies, collate; - double l, r, t, b, temp_d; - - g_return_if_fail (comp != NULL); - g_return_if_fail (IS_CAL_COMPONENT (comp)); - - if (!print_config) - print_config = gnome_print_config_default (); - - copies = 1; - collate = FALSE; - - gpm = gnome_print_job_new (print_config); - - if (!preview) { - GtkWidget *gpd; - - gpd = gnome_print_dialog_new (gpm, _("Print Item"), - GNOME_PRINT_DIALOG_COPIES); - - gtk_dialog_set_default_response (GTK_DIALOG (gpd), - GNOME_PRINT_DIALOG_RESPONSE_PRINT); - - /* Run dialog */ - - switch (gtk_dialog_run (GTK_DIALOG (gpd))) { - case GNOME_PRINT_DIALOG_RESPONSE_PRINT: - break; - - case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW: - preview = TRUE; - break; - - case -1: - return; - - default: - gtk_widget_destroy (gpd); - return; - } - - e_dialog_get_values (gpd); - gtk_widget_destroy (gpd); - } - - pc = gnome_print_job_get_context (gpm); - gnome_print_config_get_page_size (print_config, &r, &t); - - /* See top of source for an explanation of this */ - - /* gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &temp_d); - * t -= temp_d; - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &temp_d); - * r -= temp_d; - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &b); - * gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &l); - * b = l = TEMP_MARGIN; */ - - b = t * TEMP_MARGIN; - l = r * TEMP_MARGIN; - t *= (1.0 - TEMP_MARGIN); - r *= (1.0 - TEMP_MARGIN); - - print_comp_item (pc, comp, client, l, r, t, b); - gnome_print_job_close (gpm); - - if (preview) { - GtkWidget *gpmp; - - gpmp = gnome_print_job_preview_new (gpm, _("Print Preview")); - gtk_widget_show (gpmp); - } else { - gnome_print_job_print (gpm); - } - - g_object_unref (gpm); -} - -void -print_setup (void) -{ - GtkWidget *ps; - - if (!print_config) - print_config = gnome_print_config_default (); - - ps = gnome_paper_selector_new (print_config); - gtk_widget_show (ps); - -#if 0 - dlg = gtk_dialog_new_with_buttons (_("Print Setup"), - NULL, /* FIXME: Set a sensible parent */ - 0, - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), ps, TRUE, TRUE, 2); - - btn = gtk_dialog_run (GTK_DIALOG (dlg)); - if (btn == 0) { - gchar *name; - - print_config = gnome_paper_selector_get_config (ps); - - name = gnome_paper_selector_get_name (GNOME_PAPER_SELECTOR (ps)); - paper_info = gnome_paper_with_name (name); - } - - gtk_widget_destroy (dlg); -#endif -} diff --git a/calendar/gui/print.h b/calendar/gui/print.h deleted file mode 100644 index 4571b36976..0000000000 --- a/calendar/gui/print.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Evolution calendar - Print support - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Michael Zucchi <notzed@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 PRINT_H -#define PRINT_H - -#include "gnome-cal.h" - - - -typedef enum { - PRINT_VIEW_DAY, - PRINT_VIEW_WEEK, - PRINT_VIEW_MONTH, - PRINT_VIEW_YEAR -} PrintView; - -void print_calendar (GnomeCalendar *gcal, gboolean preview, time_t at, PrintView default_view); -void print_comp (CalComponent *comp, CalClient *client, gboolean preview); - -void print_setup (void); - - - -#endif diff --git a/calendar/gui/tag-calendar.c b/calendar/gui/tag-calendar.c deleted file mode 100644 index 03e0b3dee4..0000000000 --- a/calendar/gui/tag-calendar.c +++ /dev/null @@ -1,231 +0,0 @@ -/* Evolution calendar - Utilities for tagging ECalendar widgets - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Damon Chaplin <damon@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <cal-util/timeutil.h> -#include "calendar-config.h" -#include "tag-calendar.h" - - - -struct calendar_tag_closure { - ECalendarItem *calitem; - icaltimezone *zone; - time_t start_time; - time_t end_time; - - gboolean skip_transparent_events; -}; - -/* Clears all the tags in a calendar and fills a closure structure with the - * necessary information for iterating over occurrences. - * Returns FALSE if the calendar has no dates shown. - */ -static gboolean -prepare_tag (ECalendar *ecal, struct calendar_tag_closure *c, icaltimezone *zone, gboolean clear_first) -{ - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - struct icaltimetype start_tt = icaltime_null_time (); - struct icaltimetype end_tt = icaltime_null_time (); - char *location; - - if (clear_first) - e_calendar_item_clear_marks (ecal->calitem); - - if (!e_calendar_item_get_date_range (ecal->calitem, - &start_year, &start_month, - &start_day, - &end_year, &end_month, &end_day)) - return FALSE; - - start_tt.year = start_year; - start_tt.month = start_month + 1; - start_tt.day = start_day; - - end_tt.year = end_year; - end_tt.month = end_month + 1; - end_tt.day = end_day; - - icaltime_adjust (&end_tt, 1, 0, 0, 0); - - c->calitem = ecal->calitem; - - if (zone) { - c->zone = zone; - } else { - location = calendar_config_get_timezone (); - c->zone = icaltimezone_get_builtin_timezone (location); - } - - c->start_time = icaltime_as_timet_with_zone (start_tt, c->zone); - c->end_time = icaltime_as_timet_with_zone (end_tt, c->zone); - - return TRUE; -} - -/* Marks the specified range in an ECalendar; called from cal_client_generate_instances() */ -static gboolean -tag_calendar_cb (CalComponent *comp, - time_t istart, - time_t iend, - gpointer data) -{ - struct calendar_tag_closure *c = data; - struct icaltimetype start_tt, end_tt; - CalComponentTransparency transparency; - - /* If we are skipping TRANSPARENT events, return if the event is - transparent. */ - if (c->skip_transparent_events) { - cal_component_get_transparency (comp, &transparency); - if (transparency == CAL_COMPONENT_TRANSP_TRANSPARENT) - return TRUE; - } - - start_tt = icaltime_from_timet_with_zone (istart, FALSE, c->zone); - end_tt = icaltime_from_timet_with_zone (iend - 1, FALSE, c->zone); - e_calendar_item_mark_days (c->calitem, - start_tt.year, start_tt.month - 1, - start_tt.day, - end_tt.year, end_tt.month - 1, - end_tt.day, - E_CALENDAR_ITEM_MARK_BOLD); - - return TRUE; -} - -/** - * tag_calendar_by_client: - * @ecal: Calendar widget to tag. - * @client: A calendar client object. - * - * Tags an #ECalendar widget with the events that occur in its current time - * range. The occurrences are extracted from the specified calendar @client. - **/ -void -tag_calendar_by_client (ECalendar *ecal, CalClient *client) -{ - struct calendar_tag_closure c; - - g_return_if_fail (ecal != NULL); - g_return_if_fail (E_IS_CALENDAR (ecal)); - g_return_if_fail (client != NULL); - g_return_if_fail (IS_CAL_CLIENT (client)); - - /* If the ECalendar isn't visible, we just return. */ - if (!GTK_WIDGET_VISIBLE (ecal)) - return; - - if (cal_client_get_load_state (client) != CAL_CLIENT_LOAD_LOADED) - return; - - if (!prepare_tag (ecal, &c, NULL, TRUE)) - return; - - c.skip_transparent_events = TRUE; - -#if 0 - g_print ("DateNavigator generating instances\n"); -#endif - cal_client_generate_instances (client, CALOBJ_TYPE_EVENT, - c.start_time, c.end_time, - tag_calendar_cb, &c); -} - -/* Resolves TZIDs for the recurrence generator, for when the comp is not on - the server. We need to try to use builtin timezones first, as they may not - be added to the server yet. */ -static icaltimezone* -resolve_tzid_cb (const char *tzid, gpointer data) -{ - CalClient *client; - icaltimezone *zone = NULL; - CalClientGetStatus status; - - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (IS_CAL_CLIENT (data), NULL); - - client = CAL_CLIENT (data); - - /* Try to find the builtin timezone first. */ - zone = icaltimezone_get_builtin_timezone_from_tzid (tzid); - - if (!zone) { - /* FIXME: Handle errors. */ - status = cal_client_get_timezone (client, tzid, &zone); - } - - return zone; -} - -/** - * tag_calendar_by_comp: - * @ecal: Calendar widget to tag. - * @comp: A calendar component object. - * @clear_first: Whether the #ECalendar should be cleared of any marks first. - * - * Tags an #ECalendar widget with any occurrences of a specific calendar - * component that occur within the calendar's current time range. - * Note that TRANSPARENT events are also tagged here. - * - * If comp_is_on_server is FALSE, it will try to resolve TZIDs using builtin - * timezones first, before querying the server, since the timezones may not - * have been added to the calendar on the server yet. - **/ -void -tag_calendar_by_comp (ECalendar *ecal, CalComponent *comp, CalClient *client, icaltimezone *display_zone, - gboolean clear_first, gboolean comp_is_on_server) -{ - struct calendar_tag_closure c; - - g_return_if_fail (ecal != NULL); - g_return_if_fail (E_IS_CALENDAR (ecal)); - g_return_if_fail (comp != NULL); - g_return_if_fail (IS_CAL_COMPONENT (comp)); - - /* If the ECalendar isn't visible, we just return. */ - if (!GTK_WIDGET_VISIBLE (ecal)) - return; - - if (!prepare_tag (ecal, &c, display_zone, clear_first)) - return; - - c.skip_transparent_events = FALSE; - -#if 0 - g_print ("DateNavigator generating instances\n"); -#endif - if (comp_is_on_server) { - cal_recur_generate_instances (comp, c.start_time, c.end_time, - tag_calendar_cb, &c, - cal_client_resolve_tzid_cb, - client, c.zone); - } else { - cal_recur_generate_instances (comp, c.start_time, c.end_time, - tag_calendar_cb, &c, - resolve_tzid_cb, - client, c.zone); - } -} diff --git a/calendar/gui/tag-calendar.h b/calendar/gui/tag-calendar.h deleted file mode 100644 index dc146e9c9f..0000000000 --- a/calendar/gui/tag-calendar.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Evolution calendar - Utilities for tagging ECalendar widgets - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: Damon Chaplin <damon@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 TAG_CALENDAR_H -#define TAG_CALENDAR_H - -#include <widgets/misc/e-calendar.h> -#include <cal-client/cal-client.h> - -void tag_calendar_by_client (ECalendar *ecal, CalClient *client); -void tag_calendar_by_comp (ECalendar *ecal, CalComponent *comp, - CalClient *client, icaltimezone *display_zone, - gboolean clear_first, gboolean comp_is_on_server); - -#endif diff --git a/calendar/gui/tasks-control.c b/calendar/gui/tasks-control.c deleted file mode 100644 index 010fdce485..0000000000 --- a/calendar/gui/tasks-control.c +++ /dev/null @@ -1,650 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* tasks-control.c - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Damon Chaplin <damon@ximian.com> - * Ettore Perazzoli - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkcheckbutton.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-dialog-util.h> -#include <libgnomeui/gnome-stock-icons.h> -#include <libgnomeprint/gnome-print.h> -#include <libgnomeprint/gnome-print-paper.h> -#include <libgnomeprint/gnome-print-job.h> -#include <libgnomeprintui/gnome-print-job-preview.h> -#include <libgnomeprintui/gnome-print-paper-selector.h> -#include <libgnomeprintui/gnome-print-preview.h> -#include <libgnomeprintui/gnome-print-dialog.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> -#include <bonobo/bonobo-ui-util.h> -#include <gal/widgets/e-gui-utils.h> -#include <e-util/e-dialog-utils.h> -#include "dialogs/cal-prefs-dialog.h" -#include "calendar-config.h" -#include "calendar-commands.h" -#include "e-tasks.h" -#include "tasks-control.h" -#include "evolution-shell-component-utils.h" - -#define TASKS_CONTROL_PROPERTY_URI "folder_uri" -#define TASKS_CONTROL_PROPERTY_URI_IDX 1 - - -static void tasks_control_properties_init (BonoboControl *control, - ETasks *tasks); -static void tasks_control_get_property (BonoboPropertyBag *bag, - BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data); -static void tasks_control_set_property (BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data); -static void tasks_control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data); -static void tasks_control_activate (BonoboControl *control, - ETasks *tasks); -static void tasks_control_deactivate (BonoboControl *control, - ETasks *tasks); - -static void tasks_control_new_task_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); -static void tasks_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); -static void tasks_control_complete_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); -static void tasks_control_expunge_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); -static void tasks_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); -static void tasks_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path); - - -static GnomePrintConfig *print_config = NULL; - - -BonoboControl * -tasks_control_new (void) -{ - BonoboControl *control; - GtkWidget *tasks; - - tasks = e_tasks_new (); - if (!tasks) - return NULL; - gtk_widget_show (tasks); - - control = bonobo_control_new (tasks); - if (!control) { - gtk_widget_destroy (tasks); - g_message ("control_factory_fn(): could not create the control!"); - return NULL; - } - - tasks_control_properties_init (control, E_TASKS (tasks)); - - g_signal_connect (control, "activate", G_CALLBACK (tasks_control_activate_cb), tasks); - - return control; -} - - -/* Creates the property bag for our new control. */ -static void -tasks_control_properties_init (BonoboControl *control, - ETasks *tasks) - -{ - BonoboPropertyBag *pbag; - - pbag = bonobo_property_bag_new (tasks_control_get_property, - tasks_control_set_property, tasks); - - bonobo_property_bag_add (pbag, - TASKS_CONTROL_PROPERTY_URI, - TASKS_CONTROL_PROPERTY_URI_IDX, - BONOBO_ARG_STRING, - NULL, - _("The URI of the tasks folder to display"), - 0); - - bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (pbag)), NULL); - bonobo_object_unref (BONOBO_OBJECT (pbag)); -} - - -/* Gets a property of our control. FIXME: Finish. */ -static void -tasks_control_get_property (BonoboPropertyBag *bag, - BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - ETasks *tasks = user_data; - const char *uri; - - switch (arg_id) { - - case TASKS_CONTROL_PROPERTY_URI_IDX: - uri = cal_client_get_uri (e_tasks_get_cal_client (tasks)); - BONOBO_ARG_SET_STRING (arg, uri); - break; - - default: - g_warning ("Unhandled arg %d\n", arg_id); - } -} - - -static void -tasks_control_set_property (BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - ETasks *tasks = user_data; - char *uri; - - switch (arg_id) { - - case TASKS_CONTROL_PROPERTY_URI_IDX: - uri = BONOBO_ARG_GET_STRING (arg); - if (!e_tasks_open (tasks, uri)) { - char *msg; - - msg = g_strdup_printf (_("Could not load the tasks in `%s'"), uri); - gnome_error_dialog_parented ( - msg, - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks)))); - g_free (msg); - } - break; - - default: - g_warning ("Unhandled arg %d\n", arg_id); - break; - } -} - - -static void -tasks_control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data) -{ - ETasks *tasks; - - tasks = E_TASKS (user_data); - - if (activate) - tasks_control_activate (control, tasks); - else - tasks_control_deactivate (control, tasks); -} - -/* Sensitizes the UI Component menu/toolbar commands based on the number of - * selected tasks. - */ -static void -sensitize_commands (ETasks *tasks, BonoboControl *control, int n_selected) -{ - BonoboUIComponent *uic; - gboolean read_only; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - read_only = cal_client_is_read_only (e_tasks_get_cal_client (tasks)); - - bonobo_ui_component_set_prop (uic, "/commands/TasksCut", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/TasksCopy", "sensitive", - n_selected == 0 ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/TasksPaste", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/TasksDelete", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/TasksMarkComplete", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/TasksExpunge", "sensitive", - read_only ? "0" : "1", - NULL); -} - -/* Callback used when the selection in the table changes */ -static void -selection_changed_cb (ETasks *tasks, int n_selected, gpointer data) -{ - BonoboControl *control; - - control = BONOBO_CONTROL (data); - - sensitize_commands (tasks, control, n_selected); -} - -static BonoboUIVerb verbs [] = { - BONOBO_UI_VERB ("TasksNewTask", tasks_control_new_task_cmd), - BONOBO_UI_VERB ("TasksCut", tasks_control_cut_cmd), - BONOBO_UI_VERB ("TasksCopy", tasks_control_copy_cmd), - BONOBO_UI_VERB ("TasksPaste", tasks_control_paste_cmd), - BONOBO_UI_VERB ("TasksDelete", tasks_control_delete_cmd), - BONOBO_UI_VERB ("TasksMarkComplete", tasks_control_complete_cmd), - BONOBO_UI_VERB ("TasksExpunge", tasks_control_expunge_cmd), - BONOBO_UI_VERB ("TasksPrint", tasks_control_print_cmd), - BONOBO_UI_VERB ("TasksPrintPreview", tasks_control_print_preview_cmd), - - BONOBO_UI_VERB_END -}; - -static EPixmap pixmaps [] = { - E_PIXMAP ("/menu/File/Print/Print", "print.xpm"), - E_PIXMAP ("/menu/File/Print/PrintPreview", "print-preview.xpm"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/TasksCut", "16_cut.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/TasksCopy", "16_copy.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/TasksPaste", "16_paste.png"), - E_PIXMAP ("/menu/EditPlaceholder/Edit/TasksDelete", "evolution-trash-mini.png"), - E_PIXMAP ("/Toolbar/Cut", "buttons/cut.png"), - E_PIXMAP ("/Toolbar/Copy", "buttons/copy.png"), - E_PIXMAP ("/Toolbar/Paste", "buttons/paste.png"), - E_PIXMAP ("/Toolbar/Delete", "buttons/delete-message.png"), - E_PIXMAP ("/Toolbar/Print", "buttons/print.png"), - E_PIXMAP_END -}; - -static void -tasks_control_activate (BonoboControl *control, ETasks *tasks) -{ - Bonobo_UIContainer remote_uih; - BonoboUIComponent *uic; - int n_selected; - ECalendarTable *cal_table; - ETable *etable; - - uic = bonobo_control_get_ui_component (control); - g_assert (uic != NULL); - - remote_uih = bonobo_control_get_remote_ui_container (control, NULL); - bonobo_ui_component_set_container (uic, remote_uih, NULL); - bonobo_object_release_unref (remote_uih, NULL); - - e_tasks_set_ui_component (tasks, uic); - - bonobo_ui_component_add_verb_list_with_data (uic, verbs, tasks); - - bonobo_ui_component_freeze (uic, NULL); - - bonobo_ui_util_set_ui (uic, PREFIX, - EVOLUTION_UIDIR "/evolution-tasks.xml", - "evolution-tasks", - NULL); - - e_pixmaps_update (uic, pixmaps); - - e_tasks_setup_view_menus (tasks, uic); - - /* Signals from the tasks widget; also sensitize the menu items as appropriate */ - - g_signal_connect (tasks, "selection_changed", G_CALLBACK (selection_changed_cb), control); - - cal_table = e_tasks_get_calendar_table (tasks); - etable = e_calendar_table_get_table (cal_table); - n_selected = e_table_selected_count (etable); - - sensitize_commands (tasks, control, n_selected); - - bonobo_ui_component_thaw (uic, NULL); - - /* Show the dialog for setting the timezone if the user hasn't chosen - a default timezone already. This is done in the startup wizard now, - so we don't do it here. */ -#if 0 - calendar_config_check_timezone_set (); -#endif - - control_util_set_folder_bar_label (control, ""); -} - - -static void -tasks_control_deactivate (BonoboControl *control, ETasks *tasks) -{ - BonoboUIComponent *uic = bonobo_control_get_ui_component (control); - - g_assert (uic != NULL); - - e_tasks_set_ui_component (tasks, NULL); - - e_tasks_discard_view_menus (tasks); - - /* Stop monitoring the "selection_changed" signal */ - g_signal_handlers_disconnect_matched (tasks, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, control); - - bonobo_ui_component_rm (uic, "/", NULL); - bonobo_ui_component_unset_container (uic, NULL); -} - - -static void -tasks_control_new_task_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - e_tasks_new_task (tasks); -} - -static void -tasks_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_cut_clipboard (cal_table); -} - -static void -tasks_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_copy_clipboard (cal_table); -} - -static void -tasks_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_paste_clipboard (cal_table); -} - -static void -tasks_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - e_tasks_delete_selected (tasks); -} - -static void -tasks_control_complete_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - e_tasks_complete_selected (tasks); -} - -static void -parent_destroyed (GnomeDialog *dialog, GObject *deadbeef) -{ - gnome_dialog_close (GNOME_DIALOG (dialog)); -} - -static gboolean -confirm_expunge (ETasks *tasks) -{ - GtkWidget *dialog, *label, *checkbox, *parent; - int button; - - if (!calendar_config_get_confirm_expunge ()) - return TRUE; - - dialog = gnome_dialog_new (_("Warning"), - GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, - NULL); - - parent = gtk_widget_get_toplevel (GTK_WIDGET (tasks)); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (parent)); - g_object_weak_ref ((GObject *) parent, (GWeakNotify) parent_destroyed, dialog); - - label = gtk_label_new (_("This operation will permanently erase all tasks marked as completed. If you continue, you will not be able to recover these tasks.\n\nReally erase these tasks?")); - - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 6); - - checkbox = gtk_check_button_new_with_label (_("Do not ask me again.")); - gtk_widget_show (checkbox); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), checkbox, TRUE, TRUE, 6); - - button = gnome_dialog_run (GNOME_DIALOG (dialog)); - if (button == 0 && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))) - calendar_config_set_confirm_expunge (FALSE); - gnome_dialog_close (GNOME_DIALOG (dialog)); - - if (button == 0) - return TRUE; - else - return FALSE; -} - -static void -tasks_control_expunge_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - - if (confirm_expunge (tasks)) - e_tasks_delete_completed (tasks); -} - - -static void -print_title (GnomePrintContext *pc, - double page_width, double page_height) -{ - GnomeFont *font; - char *text; - double w, x, y; - - font = gnome_font_find_closest ("Sans Bold", 18); - - text = _("Tasks"); - w = gnome_font_get_width_utf8 (font, text); - - x = (page_width - w) / 2; - y = page_height - gnome_font_get_ascender (font); - - gnome_print_moveto (pc, x, y); - gnome_print_setfont (pc, font); - gnome_print_setrgbcolor (pc, 0, 0, 0); - gnome_print_show (pc, text); - - g_object_unref (font); -} - -static void -print_tasks (ETasks *tasks, gboolean preview) -{ - ECalendarTable *cal_table; - EPrintable *printable; - ETable *etable; - GnomePrintContext *pc; - GnomePrintJob *gpm; - double l, r, t, b, page_width, page_height, left_margin, bottom_margin, temp_d; - - if (!print_config) - print_config = gnome_print_config_default (); - - cal_table = e_tasks_get_calendar_table (tasks); - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (cal_table)); - printable = e_table_get_printable (etable); - e_printable_reset (printable); - - gpm = gnome_print_job_new (print_config); - pc = gnome_print_job_get_context (gpm); - - gnome_print_config_get_page_size (print_config, &r, &t); - - gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &temp_d); - t -= temp_d; - gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &temp_d); - r -= temp_d; - gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &b); - gnome_print_config_get_double (print_config, GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &l); - - page_width = r - l; - page_height = t - b; - left_margin = l; - bottom_margin = b; - - while (e_printable_data_left (printable)) { - gnome_print_beginpage (pc, "Tasks"); - gnome_print_gsave (pc); - - gnome_print_translate (pc, left_margin, bottom_margin); - - print_title (pc, page_width, page_height); - - e_printable_print_page (printable, pc, - page_width, page_height - 24, TRUE); - - gnome_print_grestore (pc); - gnome_print_showpage (pc); - } - - gnome_print_job_close (gpm); - - if (preview) { - GtkWidget *gpmp; - gpmp = gnome_print_job_preview_new (gpm, _("Print Preview")); - gtk_widget_show (gpmp); - } else { - gnome_print_job_print (gpm); - } - - g_object_unref (gpm); - g_object_unref (printable); -} - - -/* File/Print callback */ -static void -tasks_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - GtkWidget *gpd; - gboolean preview = FALSE; - GnomePrintJob *gpm; - - tasks = E_TASKS (data); - - if (!print_config) - print_config = gnome_print_config_default (); - - gpm = gnome_print_job_new (print_config); - - gpd = gnome_print_dialog_new (gpm, _("Print Tasks"), GNOME_PRINT_DIALOG_COPIES); - gtk_dialog_set_default_response (GTK_DIALOG (gpd), GNOME_PRINT_DIALOG_RESPONSE_PRINT); - - /* Run dialog */ - switch (gtk_dialog_run (GTK_DIALOG (gpd))) { - case GNOME_PRINT_DIALOG_RESPONSE_PRINT: - break; - - case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW: - preview = TRUE; - break; - - case -1: - return; - - default: - gtk_widget_destroy (gpd); - return; - } - - gtk_widget_destroy (gpd); - print_tasks (tasks, preview); -} - -static void -tasks_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const char *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - - print_tasks (tasks, TRUE); -} - diff --git a/calendar/gui/tasks-control.h b/calendar/gui/tasks-control.h deleted file mode 100644 index c74b6d220b..0000000000 --- a/calendar/gui/tasks-control.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* tasks-control.h - * - * Copyright (C) 2000, 2001, 2002, 2003 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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. - * - * Authors: Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - */ - -#ifndef _TASKS_CONTROL_H_ -#define _TASKS_CONTROL_H_ - - -BonoboControl *tasks_control_new (void); - - -#endif /* _TASKS_CONTROL_H_ */ diff --git a/calendar/gui/weekday-picker.c b/calendar/gui/weekday-picker.c deleted file mode 100644 index 1eb4d96f6a..0000000000 --- a/calendar/gui/weekday-picker.c +++ /dev/null @@ -1,557 +0,0 @@ -/* Evolution calendar - Week day picker widget - * - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtksignal.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomecanvas/gnome-canvas-rect-ellipse.h> -#include <libgnomecanvas/gnome-canvas-text.h> -#include <gal/util/e-util.h> -#include "weekday-picker.h" - - - -#define PADDING 2 - -/* Private part of the WeekdayPicker structure */ -struct _WeekdayPickerPrivate { - /* Selected days; see weekday_picker_set_days() */ - guint8 day_mask; - - /* Blocked days; these cannot be modified */ - guint8 blocked_day_mask; - - /* Day that defines the start of the week; 0 = Sunday, ..., 6 = Saturday */ - int week_start_day; - - /* Metrics */ - int font_ascent, font_descent; - int max_letter_width; - - /* Components */ - GnomeCanvasItem *boxes[7]; - GnomeCanvasItem *labels[7]; -}; - - - -/* Signal IDs */ -enum { - CHANGED, - LAST_SIGNAL -}; - -static void weekday_picker_class_init (WeekdayPickerClass *class); -static void weekday_picker_init (WeekdayPicker *wp); -static void weekday_picker_destroy (GtkObject *object); - -static void weekday_picker_realize (GtkWidget *widget); -static void weekday_picker_size_request (GtkWidget *widget, GtkRequisition *requisition); -static void weekday_picker_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static void weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style); - -static GnomeCanvasClass *parent_class; - -static guint wp_signals[LAST_SIGNAL]; - - - -E_MAKE_TYPE (weekday_picker, "WeekdayPicker", WeekdayPicker, - weekday_picker_class_init, weekday_picker_init, GNOME_TYPE_CANVAS); - -/* Class initialization function for the weekday picker */ -static void -weekday_picker_class_init (WeekdayPickerClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = g_type_class_peek_parent (class); - - wp_signals[CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_FIRST, - G_TYPE_FROM_CLASS (object_class), - GTK_SIGNAL_OFFSET (WeekdayPickerClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - object_class->destroy = weekday_picker_destroy; - - widget_class->realize = weekday_picker_realize; - widget_class->size_request = weekday_picker_size_request; - widget_class->size_allocate = weekday_picker_size_allocate; - widget_class->style_set = weekday_picker_style_set; - - class->changed = NULL; -} - -/* Event handler for the day items */ -static gint -day_event_cb (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - WeekdayPicker *wp; - WeekdayPickerPrivate *priv; - int i; - guint8 day_mask; - - wp = WEEKDAY_PICKER (data); - priv = wp->priv; - - if (!(event->type == GDK_BUTTON_PRESS && event->button.button == 1)) - return FALSE; - - /* Find which box was clicked */ - - for (i = 0; i < 7; i++) - if (priv->boxes[i] == item || priv->labels[i] == item) - break; - - g_assert (i != 7); - - /* Turn on that day */ - - i += priv->week_start_day; - if (i >= 7) - i -= 7; - - if (priv->blocked_day_mask & (0x1 << i)) - return TRUE; - - if (priv->day_mask & (0x1 << i)) - day_mask = priv->day_mask & ~(0x1 << i); - else - day_mask = priv->day_mask | (0x1 << i); - - weekday_picker_set_days (wp, day_mask); - - return TRUE; -} - - -/* Creates the canvas items for the weekday picker. The items are empty until - * they are configured elsewhere. - */ -static void -create_items (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - GnomeCanvasGroup *parent; - int i; - - priv = wp->priv; - - parent = gnome_canvas_root (GNOME_CANVAS (wp)); - - for (i = 0; i < 7; i++) { - priv->boxes[i] = gnome_canvas_item_new (parent, - GNOME_TYPE_CANVAS_RECT, - NULL); - g_signal_connect (priv->boxes[i], "event", G_CALLBACK (day_event_cb), wp); - - priv->labels[i] = gnome_canvas_item_new (parent, - GNOME_TYPE_CANVAS_TEXT, - NULL); - g_signal_connect (priv->labels[i], "event", G_CALLBACK (day_event_cb), wp); - } -} - -/* Object initialization function for the weekday picker */ -static void -weekday_picker_init (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - - GTK_WIDGET_UNSET_FLAGS (wp, GTK_CAN_FOCUS); - - priv = g_new0 (WeekdayPickerPrivate, 1); - - wp->priv = priv; - - create_items (wp); -} - -/* Finalize handler for the weekday picker */ -static void -weekday_picker_destroy (GtkObject *object) -{ - WeekdayPicker *wp; - WeekdayPickerPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_WEEKDAY_PICKER (object)); - - wp = WEEKDAY_PICKER (object); - priv = wp->priv; - - g_free (priv); - wp->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -colorize_items (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - GdkColor *outline; - GdkColor *fill, *sel_fill; - GdkColor *text_fill, *sel_text_fill; - int i; - - priv = wp->priv; - - outline = >K_WIDGET (wp)->style->fg[GTK_WIDGET_STATE (wp)]; - - fill = >K_WIDGET (wp)->style->base[GTK_WIDGET_STATE (wp)]; - text_fill = >K_WIDGET (wp)->style->fg[GTK_WIDGET_STATE (wp)]; - - sel_fill = >K_WIDGET (wp)->style->bg[GTK_STATE_SELECTED]; - sel_text_fill = >K_WIDGET (wp)->style->fg[GTK_STATE_SELECTED]; - - for (i = 0; i < 7; i++) { - int day; - GdkColor *f, *t; - - day = i + priv->week_start_day; - if (day >= 7) - day -= 7; - - if (priv->day_mask & (0x1 << day)) { - f = sel_fill; - t = sel_text_fill; - } else { - f = fill; - t = text_fill; - } - - gnome_canvas_item_set (priv->boxes[i], - "fill_color_gdk", f, - "outline_color_gdk", outline, - NULL); - - gnome_canvas_item_set (priv->labels[i], - "fill_color_gdk", t, - NULL); - } -} - -/* Configures the items in the weekday picker by setting their attributes. */ -static void -configure_items (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - int width, height; - int box_width; - const char *str; - int i; - - priv = wp->priv; - - width = GTK_WIDGET (wp)->allocation.width; - height = GTK_WIDGET (wp)->allocation.height; - - box_width = (width - 1) / 7; - str = _("SMTWTFS"); - - for (i = 0; i < 7; i++) { - char *c; - int day; - - day = i + priv->week_start_day; - if (day >= 7) - day -= 7; - - gnome_canvas_item_set (priv->boxes[i], - "x1", (double) (i * box_width), - "y1", (double) 0, - "x2", (double) ((i + 1) * box_width), - "y2", (double) (height - 1), - "width_pixels", 0, - NULL); - - c = g_strndup (str + day, 1); - gnome_canvas_item_set (priv->labels[i], - "text", c, -#if 0 - "font_gdk", gtk_style_get_font (gtk_widget_get_style (GTK_WIDGET (wp))), -#endif - "x", (double) (i * box_width) + box_width / 2.0, - "y", (double) (1 + PADDING), - "anchor", GTK_ANCHOR_N, - NULL); - g_free (c); - } - - colorize_items (wp); -} - -/* Realize handler for the weekday picker */ -static void -weekday_picker_realize (GtkWidget *widget) -{ - WeekdayPicker *wp; - - wp = WEEKDAY_PICKER (widget); - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); - - configure_items (wp); -} - -/* Size_request handler for the weekday picker */ -static void -weekday_picker_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - WeekdayPicker *wp; - WeekdayPickerPrivate *priv; - - wp = WEEKDAY_PICKER (widget); - priv = wp->priv; - - requisition->width = (priv->max_letter_width + 2 * PADDING + 1) * 7 + 1; - requisition->height = (priv->font_ascent + priv->font_descent + 2 * PADDING + 2); -} - -/* Size_allocate handler for the weekday picker */ -static void -weekday_picker_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - WeekdayPicker *wp; - - wp = WEEKDAY_PICKER (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 (wp), - 0, 0, allocation->width, allocation->height); - - configure_items (wp); -} - -/* Style_set handler for the weekday picker */ -static void -weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style) -{ - WeekdayPicker *wp; - WeekdayPickerPrivate *priv; - int max_width; - const char *str; - int i, len; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - PangoLayout *layout; - - wp = WEEKDAY_PICKER (widget); - priv = wp->priv; - - /* Set up Pango prerequisites */ - font_desc = gtk_widget_get_style (widget)->font_desc; - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - layout = pango_layout_new (pango_context); - - priv->font_ascent = PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)); - priv->font_descent = PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)); - - max_width = 0; - - str = _("SMTWTFS"); - len = strlen (str); - - for (i = 0; i < len; i++) { - int w; - - pango_layout_set_text (layout, str + i, 1); - pango_layout_get_pixel_size (layout, &w, NULL); - - if (w > max_width) - max_width = w; - } - - priv->max_letter_width = max_width; - - configure_items (wp); - g_object_unref (layout); - pango_font_metrics_unref (font_metrics); - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - (* GTK_WIDGET_CLASS (parent_class)->style_set) (widget, previous_style); -} - - - -/** - * weekday_picker_new: - * @void: - * - * Creates a new weekday picker widget. - * - * Return value: A newly-created weekday picker. - **/ -GtkWidget * -weekday_picker_new (void) -{ - return g_object_new (TYPE_WEEKDAY_PICKER, NULL); -} - -/** - * weekday_picker_set_days: - * @wp: A weekday picker. - * @day_mask: Bitmask with the days to be selected. - * - * Sets the days that are selected in a weekday picker. In the @day_mask, - * Sunday is bit 0, Monday is bit 1, etc. - **/ -void -weekday_picker_set_days (WeekdayPicker *wp, guint8 day_mask) -{ - WeekdayPickerPrivate *priv; - - g_return_if_fail (wp != NULL); - g_return_if_fail (IS_WEEKDAY_PICKER (wp)); - - priv = wp->priv; - - priv->day_mask = day_mask; - colorize_items (wp); - - gtk_signal_emit (GTK_OBJECT (wp), wp_signals[CHANGED]); -} - -/** - * weekday_picker_get_days: - * @wp: A weekday picker. - * - * Queries the days that are selected in a weekday picker. - * - * Return value: Bit mask of selected days. Sunday is bit 0, Monday is bit 1, - * etc. - **/ -guint8 -weekday_picker_get_days (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - - g_return_val_if_fail (wp != NULL, 0); - g_return_val_if_fail (IS_WEEKDAY_PICKER (wp), 0); - - priv = wp->priv; - return priv->day_mask; -} - -/** - * weekday_picker_set_blocked_days: - * @wp: A weekday picker. - * @blocked_day_mask: Bitmask with the days to be blocked. - * - * Sets the days that the weekday picker will prevent from being modified by the - * user. The @blocked_day_mask is specified in the same way as in - * weekday_picker_set_days(). - **/ -void -weekday_picker_set_blocked_days (WeekdayPicker *wp, guint8 blocked_day_mask) -{ - WeekdayPickerPrivate *priv; - - g_return_if_fail (wp != NULL); - g_return_if_fail (IS_WEEKDAY_PICKER (wp)); - - priv = wp->priv; - priv->blocked_day_mask = blocked_day_mask; -} - -/** - * weekday_picker_get_blocked_days: - * @wp: A weekday picker. - * - * Queries the set of days that the weekday picker prevents from being modified - * by the user. - * - * Return value: Bit mask of blocked days, with the same format as that returned - * by weekday_picker_get_days(). - **/ -guint -weekday_picker_get_blocked_days (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - - g_return_val_if_fail (wp != NULL, 0); - g_return_val_if_fail (IS_WEEKDAY_PICKER (wp), 0); - - priv = wp->priv; - return priv->blocked_day_mask; -} - -/** - * weekday_picker_set_week_start_day: - * @wp: A weekday picker. - * @week_start_day: Index of the day that defines the start of the week; 0 is - * Sunday, 1 is Monday, etc. - * - * Sets the day that defines the start of the week for a weekday picker. - **/ -void -weekday_picker_set_week_start_day (WeekdayPicker *wp, int week_start_day) -{ - WeekdayPickerPrivate *priv; - - g_return_if_fail (wp != NULL); - g_return_if_fail (IS_WEEKDAY_PICKER (wp)); - g_return_if_fail (week_start_day >= 0 && week_start_day < 7); - - priv = wp->priv; - priv->week_start_day = week_start_day; - - configure_items (wp); -} - -/** - * weekday_picker_get_week_start_day: - * @wp: A weekday picker. - * - * Queries the day that defines the start of the week in a weekday picker. - * - * Return value: Index of the day that defines the start of the week. See - * weekday_picker_set_week_start_day() to see how this is represented. - **/ -int -weekday_picker_get_week_start_day (WeekdayPicker *wp) -{ - WeekdayPickerPrivate *priv; - - g_return_val_if_fail (wp != NULL, -1); - g_return_val_if_fail (IS_WEEKDAY_PICKER (wp), -1); - - priv = wp->priv; - return priv->week_start_day; -} diff --git a/calendar/gui/weekday-picker.h b/calendar/gui/weekday-picker.h deleted file mode 100644 index 67a72f9ebd..0000000000 --- a/calendar/gui/weekday-picker.h +++ /dev/null @@ -1,71 +0,0 @@ -/* Evolution calendar - Week day picker widget - * - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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 WEEKDAY_PICKER_H -#define WEEKDAY_PICKER_H - -#include <libgnomecanvas/gnome-canvas.h> - -G_BEGIN_DECLS - - - -#define TYPE_WEEKDAY_PICKER (weekday_picker_get_type ()) -#define WEEKDAY_PICKER(obj) (GTK_CHECK_CAST ((obj), TYPE_WEEKDAY_PICKER, WeekdayPicker)) -#define WEEKDAY_PICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_WEEKDAY_PICKER, \ - WeekdayPickerClass)) -#define IS_WEEKDAY_PICKER(obj) (GTK_CHECK_TYPE ((obj), TYPE_WEEKDAY_PICKER)) -#define IS_WEEKDAY_PICKER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_WEEKDAY_PICKER)) - -typedef struct _WeekdayPicker WeekdayPicker; -typedef struct _WeekdayPickerClass WeekdayPickerClass; -typedef struct _WeekdayPickerPrivate WeekdayPickerPrivate; - -struct _WeekdayPicker { - GnomeCanvas canvas; - - /* Private data */ - WeekdayPickerPrivate *priv; -}; - -struct _WeekdayPickerClass { - GnomeCanvasClass parent_class; - - void (* changed) (WeekdayPicker *wp); -}; - -GtkType weekday_picker_get_type (void); - -GtkWidget *weekday_picker_new (void); - -void weekday_picker_set_days (WeekdayPicker *wp, guint8 day_mask); -guint8 weekday_picker_get_days (WeekdayPicker *wp); - -void weekday_picker_set_blocked_days (WeekdayPicker *wp, guint8 blocked_day_mask); -guint weekday_picker_get_blocked_days (WeekdayPicker *wp); - -void weekday_picker_set_week_start_day (WeekdayPicker *wp, int week_start_day); -int weekday_picker_get_week_start_day (WeekdayPicker *wp); - - - -G_END_DECLS - -#endif |