diff options
author | Federico Mena Quintero <federico@src.gnome.org> | 2001-06-20 01:26:04 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-06-20 01:26:04 +0800 |
commit | 4583098b34dfc46701ec05531bba90a7c59d8d92 (patch) | |
tree | 2c00fba88a8ba20ae218fe68f679958bbf963e2d /calendar | |
parent | 2e156596a6e8099c3f540ca362b1415613ed30dd (diff) | |
download | gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar.gz gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar.bz2 gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar.lz gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar.xz gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.tar.zst gsoc2013-evolution-4583098b34dfc46701ec05531bba90a7c59d8d92.zip |
Sync - Federico
svn path=/trunk/; revision=10293
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 29 | ||||
-rw-r--r-- | calendar/gui/Makefile.am | 4 | ||||
-rw-r--r-- | calendar/gui/calendar-commands.c | 49 | ||||
-rw-r--r-- | calendar/gui/calendar-commands.h | 5 | ||||
-rw-r--r-- | calendar/gui/calendar-view-factory.c | 253 | ||||
-rw-r--r-- | calendar/gui/calendar-view-factory.h | 66 | ||||
-rw-r--r-- | calendar/gui/calendar-view.c | 317 | ||||
-rw-r--r-- | calendar/gui/calendar-view.h | 68 | ||||
-rw-r--r-- | calendar/gui/control-factory.c | 12 | ||||
-rw-r--r-- | calendar/gui/dialogs/comp-editor.c | 2 | ||||
-rw-r--r-- | calendar/gui/e-tasks.c | 4 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.c | 679 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.h | 23 |
13 files changed, 1236 insertions, 275 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 6e0911c935..a00da94dbc 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -41,6 +41,35 @@ (conduit_get_gpilot_conduit): Tweaked for some gnome-pilot api changes +2001-06-15 Federico Mena Quintero <federico@ximian.com> + + * gui/calendar-view.[ch]: New files with the generic calendar view + object. It sucks that we have to implement at least two classes + to define a GalView and its factory. + + * gui/calendar-view-factory.[ch]: New files; factory for calendar + views. + + * gui/gnome-cal.h (GnomeCalendarViewType): Moved from gnome-cal.c + and renamed from ViewType. We no longer use strings to identify + the view types. + + * gui/gnome-cal.c (gnome_calendar_get_view_type): New function. + (set_view): Renamed from gnome_calendar_set_view_internal(). + (gnome_calendar_set_query): Made public; renamed from set_query(). + (gnome_calendar_setup_view_menus): New function to set up the view + collection and the GalViewMenus. + (gnome_calendar_discard_view_menus): New function to discard them. + + * gui/calendar-commands.c (calendar_control_activate): Set up the + GalView menus. + (calendar_control_deactivate): Discard the GalView menus. + + * gui/e-day-view.c: #include <gtk/gtkinvisible.h> + + * gui/dialogs/comp-editor.c (comp_editor_get_type): The type info + structure should be static. + 2001-06-15 Rodrigo Moya <rodrigo@ximian.com> * gui/e-day-view.c (selection_received): generate a new UID diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 6c6b52302a..4aec1db792 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -53,6 +53,10 @@ evolution_calendar_SOURCES = \ calendar-commands.h \ calendar-model.c \ calendar-model.h \ + calendar-view.c \ + calendar-view.h \ + calendar-view-factory.c \ + calendar-view-factory.h \ comp-util.c \ comp-util.h \ control-factory.c \ diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 526a547c91..b63946cc53 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -75,7 +75,7 @@ new_event_cb (BonoboUIComponent *uic, gpointer data, const char *path) { GnomeCalendar *gcal; time_t dtstart, dtend; - + gcal = GNOME_CALENDAR (data); gnome_calendar_get_current_time_range (gcal, &dtstart, &dtend); gnome_calendar_new_appointment_for (gcal, dtstart, dtend, TRUE); @@ -86,21 +86,29 @@ static void print (GnomeCalendar *gcal, gboolean preview) { time_t start; - const char *view; + GnomeCalendarViewType view_type; PrintView print_view; gnome_calendar_get_current_time_range (gcal, &start, NULL); - view = gnome_calendar_get_current_view_name (gcal); + view_type = gnome_calendar_get_view (gcal); - if (strcmp (view, "dayview") == 0) + switch (view_type) { + case GNOME_CAL_DAY_VIEW: print_view = PRINT_VIEW_DAY; - else if (strcmp (view, "workweekview") == 0 || strcmp (view, "weekview") == 0) + break; + + case GNOME_CAL_WORK_WEEK_VIEW: + case GNOME_CAL_WEEK_VIEW: print_view = PRINT_VIEW_WEEK; - else if (strcmp (view, "monthview") == 0) + break; + + case GNOME_CAL_MONTH_VIEW: print_view = PRINT_VIEW_MONTH; - else { + break; + + default: g_assert_not_reached (); - print_view = PRINT_VIEW_DAY; + return; } print_calendar (gcal, preview, start, print_view); @@ -216,7 +224,7 @@ show_day_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) gcal = GNOME_CALENDAR (data); - gnome_calendar_set_view (gcal, "dayview", FALSE, TRUE); + gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, FALSE, TRUE); } static void @@ -226,7 +234,7 @@ show_work_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char * gcal = GNOME_CALENDAR (data); - gnome_calendar_set_view (gcal, "workweekview", FALSE, TRUE); + gnome_calendar_set_view (gcal, GNOME_CAL_WORK_WEEK_VIEW, FALSE, TRUE); } static void @@ -236,7 +244,7 @@ show_week_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path) gcal = GNOME_CALENDAR (data); - gnome_calendar_set_view (gcal, "weekview", FALSE, TRUE); + gnome_calendar_set_view (gcal, GNOME_CAL_WEEK_VIEW, FALSE, TRUE); } static void @@ -246,7 +254,7 @@ show_month_view_clicked (BonoboUIComponent *uic, gpointer data, const char *path gcal = GNOME_CALENDAR (data); - gnome_calendar_set_view (gcal, "monthview", FALSE, TRUE); + gnome_calendar_set_view (gcal, GNOME_CAL_MONTH_VIEW, FALSE, TRUE); } @@ -366,12 +374,12 @@ static BonoboUIVerb verbs [] = { BONOBO_UI_VERB ("EditNewAppointment", new_appointment_cb), BONOBO_UI_VERB ("EditNewEvent", new_event_cb), BONOBO_UI_VERB ("CalendarPreferences", properties_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), @@ -399,7 +407,7 @@ static EPixmap pixmaps [] = void calendar_control_activate (BonoboControl *control, - GnomeCalendar *cal) + GnomeCalendar *gcal) { Bonobo_UIContainer remote_uih; BonoboUIComponent *uic; @@ -426,9 +434,8 @@ calendar_control_activate (BonoboControl *control, /* This makes the appropriate radio button in the toolbar active. */ gnome_calendar_update_view_buttons (cal); #endif - - bonobo_ui_component_add_verb_list_with_data ( - uic, verbs, cal); + + bonobo_ui_component_add_verb_list_with_data (uic, verbs, gcal); bonobo_ui_component_freeze (uic, NULL); @@ -438,15 +445,19 @@ calendar_control_activate (BonoboControl *control, e_pixmaps_update (uic, pixmaps); + gnome_calendar_setup_view_menus (gcal, uic); + bonobo_ui_component_thaw (uic, NULL); } void -calendar_control_deactivate (BonoboControl *control) +calendar_control_deactivate (BonoboControl *control, GnomeCalendar *gcal) { BonoboUIComponent *uic = bonobo_control_get_ui_component (control); g_assert (uic != NULL); + gnome_calendar_discard_view_menus (gcal); + bonobo_ui_component_rm (uic, "/", NULL); bonobo_ui_component_unset_container (uic); } diff --git a/calendar/gui/calendar-commands.h b/calendar/gui/calendar-commands.h index 3dfad41dab..aaa0c43055 100644 --- a/calendar/gui/calendar-commands.h +++ b/calendar/gui/calendar-commands.h @@ -34,9 +34,8 @@ void update_all_config_settings (void); GnomeCalendar *new_calendar (void); -void calendar_control_activate (BonoboControl *control, - GnomeCalendar *cal); -void calendar_control_deactivate (BonoboControl *control); +void calendar_control_activate (BonoboControl *control, GnomeCalendar *gcal); +void calendar_control_deactivate (BonoboControl *control, GnomeCalendar *gcal); void calendar_goto_today (GnomeCalendar *gcal); diff --git a/calendar/gui/calendar-view-factory.c b/calendar/gui/calendar-view-factory.c new file mode 100644 index 0000000000..23cad04f9c --- /dev/null +++ b/calendar/gui/calendar-view-factory.c @@ -0,0 +1,253 @@ +/* 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 the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <libgnome/gnome-defs.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_destroy (GtkObject *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; + + + +/** + * calendar_view_factory_get_type: + * + * Registers the #CalendarViewFactory class if necessary, and returns the type + * ID associated to it. + * + * Return value: The type ID of the #CalendarViewFactory class. + **/ +GtkType +calendar_view_factory_get_type (void) +{ + static GtkType calendar_view_factory_type; + + if (!calendar_view_factory_type) { + static const GtkTypeInfo calendar_view_factory_info = { + "CalendarViewFactory", + sizeof (CalendarViewFactory), + sizeof (CalendarViewFactoryClass), + (GtkClassInitFunc) calendar_view_factory_class_init, + (GtkObjectInitFunc) calendar_view_factory_init, + NULL, /* reserved_1 */ + NULL, /* reserved_2 */ + (GtkClassInitFunc) NULL + }; + + calendar_view_factory_type = gtk_type_unique (GAL_VIEW_FACTORY_TYPE, + &calendar_view_factory_info); + } + + return calendar_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; + GtkObjectClass *object_class; + + parent_class = gtk_type_class (GAL_VIEW_FACTORY_TYPE); + + gal_view_factory_class = (GalViewFactoryClass *) class; + object_class = (GtkObjectClass *) 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; + + object_class->destroy = calendar_view_factory_destroy; +} + +/* 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; +} + +/* Destroy method for the calendar view factory */ +static void +calendar_view_factory_destroy (GtkObject *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 (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (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 = gtk_type_new (TYPE_CALENDAR_VIEW_FACTORY); + 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 new file mode 100644 index 0000000000..fb87a90dda --- /dev/null +++ b/calendar/gui/calendar-view-factory.h @@ -0,0 +1,66 @@ +/* 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 the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef CALENDAR_VIEW_FACTORY_H +#define CALENDAR_VIEW_FACTORY_H + +#include <libgnome/gnome-defs.h> +#include <gal/menus/gal-view-factory.h> +#include "gnome-cal.h" + +BEGIN_GNOME_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); + + + +END_GNOME_DECLS + +#endif diff --git a/calendar/gui/calendar-view.c b/calendar/gui/calendar-view.c new file mode 100644 index 0000000000..7a3a2b3fd1 --- /dev/null +++ b/calendar/gui/calendar-view.c @@ -0,0 +1,317 @@ +/* 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 the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <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_destroy (GtkObject *object); + +static void calendar_view_edit (GalView *view); +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; + + + +/** + * calendar_view_get_type: + * + * Registers the #CalendarView class if necessary, and returns the type ID + * associated to it. + * + * Return value: The type ID of the #CalendarView class. + **/ +GtkType +calendar_view_get_type (void) +{ + static GtkType calendar_view_type; + + if (!calendar_view_type) { + static const GtkTypeInfo calendar_view_info = { + "CalendarView", + sizeof (CalendarView), + sizeof (CalendarViewClass), + (GtkClassInitFunc) calendar_view_class_init, + (GtkObjectInitFunc) calendar_view_init, + NULL, /* reserved_1 */ + NULL, /* reserved_2 */ + (GtkClassInitFunc) NULL + }; + + calendar_view_type = gtk_type_unique (GAL_VIEW_TYPE, &calendar_view_info); + } + + return calendar_view_type; +} + +/* Class initialization function for the calendar view */ +static void +calendar_view_class_init (CalendarViewClass *class) +{ + GalViewClass *gal_view_class; + GtkObjectClass *object_class; + + parent_class = gtk_type_class (GAL_VIEW_TYPE); + + gal_view_class = (GalViewClass *) class; + object_class = (GtkObjectClass *) 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->destroy = calendar_view_destroy; +} + +/* 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_destroy (GtkObject *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 (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + + +/* edit method of the calendar view */ +static void +calendar_view_edit (GalView *view) +{ + /* 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 = gtk_type_new (TYPE_CALENDAR_VIEW); + 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 = gtk_type_new (TYPE_CALENDAR_VIEW); + 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 new file mode 100644 index 0000000000..f0bf0bcbfd --- /dev/null +++ b/calendar/gui/calendar-view.h @@ -0,0 +1,68 @@ +/* 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 the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef CALENDAR_VIEW_H +#define CALENDAR_VIEW_H + +#include <libgnome/gnome-defs.h> +#include <gal/menus/gal-view.h> +#include "gnome-cal.h" + +BEGIN_GNOME_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); + + + +END_GNOME_DECLS + +#endif diff --git a/calendar/gui/control-factory.c b/calendar/gui/control-factory.c index 8788a19c58..be41f9d420 100644 --- a/calendar/gui/control-factory.c +++ b/calendar/gui/control-factory.c @@ -49,14 +49,16 @@ CORBA_ORB orb; static void -control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data) +control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) { + GnomeCalendar *gcal; + + gcal = GNOME_CALENDAR (data); + if (activate) - calendar_control_activate (control, user_data); + calendar_control_activate (control, gcal); else - calendar_control_deactivate (control); + calendar_control_deactivate (control, gcal); } diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 6ab62671f5..2d894f3ff2 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -75,7 +75,7 @@ comp_editor_get_type (void) static GtkType comp_editor_type = 0; if (!comp_editor_type) { - GtkTypeInfo comp_editor_info = { + static const GtkTypeInfo comp_editor_info = { "CompEditor", sizeof (CompEditor), sizeof (CompEditorClass), diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index 4a25646676..c73bc4961f 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -54,6 +54,10 @@ struct _ETasksPrivate { /* The option menu showing the categories, and the popup menu. */ GtkWidget *categories_option_menu; GtkWidget *categories_menu; + + /* View collection and the view menus handler */ + GalViewCollection *view_collection; + GalViewMenus *view_menus; }; diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 46cc26292f..73ac19aabc 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -32,11 +32,13 @@ #include <glib.h> #include <libgnome/gnome-defs.h> #include <libgnome/gnome-i18n.h> +#include <libgnome/gnome-util.h> #include <libgnomeui/gnome-dialog.h> #include <libgnomeui/gnome-dialog-util.h> #include <gal/e-paned/e-hpaned.h> #include <gal/e-paned/e-vpaned.h> #include <cal-util/timeutil.h> +#include "widgets/menus/gal-view-menus.h" #include "widgets/misc/e-search-bar.h" #include "widgets/misc/e-filter-bar.h" #include "dialogs/alarm-notify-dialog.h" @@ -48,19 +50,12 @@ #include "component-factory.h" #include "calendar-commands.h" #include "calendar-config.h" +#include "calendar-view.h" +#include "calendar-view-factory.h" #include "tag-calendar.h" -/* These must match the page numbers in the GtkNotebook. */ -typedef enum { - VIEW_NOT_SET = -1, - VIEW_DAY = 0, - VIEW_WORK_WEEK, - VIEW_WEEK, - VIEW_MONTH -} ViewType; - /* Private part of the GnomeCalendar structure */ struct _GnomeCalendarPrivate { /* @@ -115,7 +110,7 @@ struct _GnomeCalendarPrivate { /* 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. */ - ViewType current_view_type; + GnomeCalendarViewType current_view_type; gboolean range_selected; /* These are the saved positions of the panes. They are multiples of @@ -129,6 +124,10 @@ struct _GnomeCalendarPrivate { /* The signal handler id for our GtkCalendar "day_selected" handler. */ guint day_selected_id; + /* View collection and menus for the control */ + GalViewCollection *view_collection; + GalViewMenus *view_menus; + /* Whether we are being destroyed and should not mess with the object * editor hash table. */ @@ -141,10 +140,6 @@ 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_view_internal (GnomeCalendar *gcal, - char *page_name, - gboolean range_selected, - gboolean focus); 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); @@ -160,10 +155,6 @@ static void gnome_calendar_on_date_navigator_date_range_changed (ECalendarItem * GnomeCalendar *gcal); static void gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, GnomeCalendar *gcal); -static gboolean gnome_calendar_get_days_shown (GnomeCalendar *gcal, - GDate *start_date, - gint *days_shown); - static GtkVBoxClass *parent_class; @@ -206,16 +197,6 @@ gnome_calendar_class_init (GnomeCalendarClass *class) object_class->destroy = gnome_calendar_destroy; } -static GtkWidget * -get_current_page (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - return GTK_NOTEBOOK (priv->notebook)->cur_page->child; -} - static ESearchBarItem search_menu_items[] = { E_FILTERBAR_RESET, { NULL, -1 } @@ -238,24 +219,42 @@ static ESearchBarItem search_option_items[] = { { NULL, -1 } }; -/* Sets the query sexp for the current view in the calendar */ -static void -set_query (GnomeCalendar *gcal, char *sexp) +/** + * 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, char *sexp) { GnomeCalendarPrivate *priv; - GtkWidget *page; - g_assert (sexp != NULL); + g_return_if_fail (gcal != NULL); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + g_return_if_fail (sexp != NULL); priv = gcal->priv; - page = get_current_page (gcal); + switch (priv->current_view_type) { + case GNOME_CAL_DAY_VIEW: + e_day_view_set_query (E_DAY_VIEW (priv->day_view), sexp); + break; - if (page == priv->day_view || page == priv->work_week_view) - e_day_view_set_query (E_DAY_VIEW (page), sexp); - else if (page == priv->week_view || page == priv->month_view) - e_week_view_set_query (E_WEEK_VIEW (page), sexp); - else { + 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 (); } @@ -268,7 +267,7 @@ set_query_contains (GnomeCalendar *gcal, const char *field, const char *text) char *sexp; sexp = g_strdup_printf ("(contains? \"%s\" \"%s\")", field, text); - set_query (gcal, sexp); + gnome_calendar_set_query (gcal, sexp); g_free (sexp); } @@ -309,7 +308,7 @@ search_bar_query_changed_cb (ESearchBar *search_bar, gpointer data) char *sexp; sexp = g_strdup_printf ("(has-categories? \"%s\")", text); - set_query (gcal, sexp); + gnome_calendar_set_query (gcal, sexp); g_free (sexp); break; } @@ -331,7 +330,7 @@ search_bar_menu_activated_cb (ESearchBar *search_bar, int item, gpointer data) switch (item) { case E_FILTERBAR_RESET_ID: - set_query (gcal, "#t"); /* match all */ + gnome_calendar_set_query (gcal, "#t"); /* match all */ /* FIXME: should we change the rest of the search bar so that * the user sees that he selected "show all" instead of some * type/text search combination? @@ -463,13 +462,16 @@ gnome_calendar_init (GnomeCalendar *gcal) priv->object_editor_hash = g_hash_table_new (g_str_hash, g_str_equal); - priv->current_view_type = VIEW_NOT_SET; + priv->current_view_type = GNOME_CAL_DAY_VIEW; priv->range_selected = FALSE; setup_widgets (gcal); priv->selection_start_time = time_day_begin (time (NULL)); priv->selection_end_time = time_add_day (priv->selection_start_time, 1); + + priv->view_collection = NULL; + priv->view_menus = NULL; } /* Used from g_hash_table_foreach(); frees an UID string */ @@ -521,6 +523,16 @@ gnome_calendar_destroy (GtkObject *object) g_hash_table_destroy (priv->object_editor_hash); priv->object_editor_hash = NULL; + if (priv->view_collection) { + gtk_object_unref (GTK_OBJECT (priv->view_collection)); + priv->view_collection = NULL; + } + + if (priv->view_menus) { + gtk_object_unref (GTK_OBJECT (priv->view_menus)); + priv->view_menus = NULL; + } + g_free (priv); gcal->priv = NULL; @@ -528,33 +540,6 @@ gnome_calendar_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } -char * -gnome_calendar_get_current_view_name (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - GtkWidget *page; - - g_return_val_if_fail (gcal != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - priv = gcal->priv; - - page = get_current_page (gcal); - - if (page == priv->day_view) - return "dayview"; - else if (page == priv->work_week_view) - return "workweekview"; - else if (page == priv->week_view) - return "weekview"; - else if (page == priv->month_view) - return "monthview"; - else { - g_assert_not_reached (); - return NULL; - } -} - void gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time) { @@ -578,21 +563,35 @@ static void gnome_calendar_update_view_times (GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - GtkWidget *page; priv = gcal->priv; - page = get_current_page (gcal); + 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; - if (page == priv->day_view || page == priv->work_week_view) { - e_day_view_set_selected_time_range (E_DAY_VIEW (page), + 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); - } else if (page == priv->week_view || page == priv->month_view) { - e_week_view_set_selected_time_range (E_WEEK_VIEW (page), + 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); - } else { + 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 (); } @@ -602,29 +601,35 @@ static void gnome_calendar_direction (GnomeCalendar *gcal, int direction) { GnomeCalendarPrivate *priv; - GtkWidget *cp; time_t start_time, end_time; priv = gcal->priv; - cp = get_current_page (gcal); - start_time = priv->selection_start_time; end_time = priv->selection_end_time; - if (cp == priv->day_view) { + switch (priv->current_view_type) { + case GNOME_CAL_DAY_VIEW: start_time = time_add_day (start_time, direction); end_time = time_add_day (end_time, direction); - } else if (cp == priv->work_week_view) { + break; + + case GNOME_CAL_WORK_WEEK_VIEW: start_time = time_add_week (start_time, direction); end_time = time_add_week (end_time, direction); - } else if (cp == priv->week_view) { + break; + + case GNOME_CAL_WEEK_VIEW: start_time = time_add_week (start_time, direction); end_time = time_add_week (end_time, direction); - } else if (cp == priv->month_view) { + break; + + case GNOME_CAL_MONTH_VIEW: start_time = time_add_month (start_time, direction); end_time = time_add_month (end_time, direction); - } else { + break; + + default: g_warning ("Weee! Where did the penguin go?"); g_assert_not_reached (); return; @@ -667,95 +672,134 @@ gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time) priv->selection_start_time = time_day_begin (time); priv->selection_end_time = time_add_day (priv->selection_start_time, 1); + if (priv->day_button) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->day_button), TRUE); else - gnome_calendar_set_view (gcal, "dayview", FALSE, TRUE); + gnome_calendar_set_view (gcal, GNOME_CAL_DAY_VIEW, FALSE, TRUE); } -void -gnome_calendar_goto_today (GnomeCalendar *gcal) +static void +focus_current_view (GnomeCalendar *gcal) { - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + GnomeCalendarPrivate *priv; - gnome_calendar_goto (gcal, time (NULL)); + priv = gcal->priv; - gtk_widget_grab_focus (get_current_page (gcal)); -} + 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 (); + } +} -/* This sets which view is currently shown. It also updates the selection time - of the view so it shows the appropriate days. */ void -gnome_calendar_set_view (GnomeCalendar *gcal, - char *page_name, - gboolean range_selected, - gboolean focus) +gnome_calendar_goto_today (GnomeCalendar *gcal) { g_return_if_fail (gcal != NULL); g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (page_name != NULL); - gnome_calendar_set_view_internal (gcal, page_name, range_selected, focus); - gnome_calendar_update_view_times (gcal); - gnome_calendar_update_date_navigator (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; -/* This 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). */ + 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 -gnome_calendar_set_view_internal (GnomeCalendar *gcal, - char *page_name, - gboolean range_selected, - gboolean focus) +set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type, + gboolean range_selected, gboolean grab_focus) { GnomeCalendarPrivate *priv; - int view; gboolean round_selection; GtkWidget *focus_widget; priv = gcal->priv; round_selection = FALSE; + focus_widget = NULL; - if (!strcmp (page_name, "dayview")) { - view = VIEW_DAY; + switch (view_type) { + case GNOME_CAL_DAY_VIEW: focus_widget = priv->day_view; if (!range_selected) e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), 1); - } else if (!strcmp (page_name, "workweekview")) { - view = VIEW_WORK_WEEK; + + break; + + case GNOME_CAL_WORK_WEEK_VIEW: focus_widget = priv->work_week_view; - } else if (!strcmp (page_name, "weekview")) { - view = VIEW_WEEK; + break; + + case GNOME_CAL_WEEK_VIEW: focus_widget = priv->week_view; round_selection = TRUE; - } else if (!strcmp (page_name, "monthview")) { - view = VIEW_MONTH; + break; + + case GNOME_CAL_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; - } else { - g_warning ("Unknown calendar view: %s", page_name); + break; + + default: + g_warning ("A penguin is loose!"); g_assert_not_reached (); return; } - priv->current_view_type = view; + priv->current_view_type = view_type; priv->range_selected = range_selected; - calendar_config_set_default_view (view); + g_assert (focus_widget != NULL); + + calendar_config_set_default_view (view_type); - gtk_notebook_set_page (GTK_NOTEBOOK (priv->notebook), view); + gtk_notebook_set_page (GTK_NOTEBOOK (priv->notebook), (int) view_type); - if (focus) + if (grab_focus) gtk_widget_grab_focus (focus_widget); gnome_calendar_set_pane_positions (gcal); @@ -768,6 +812,142 @@ gnome_calendar_set_view_internal (GnomeCalendar *gcal, 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); +} + +/* Callback used when the view collection asks us to display a particular view */ +static void +display_view_cb (GalViewCollection *view_collection, 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; + + 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_collection == NULL); + + g_assert (priv->view_collection == NULL); + g_assert (priv->view_menus == NULL); + + /* Create the view collection */ + + priv->view_collection = gal_view_collection_new (); + + path = gnome_util_prepend_user_home ("/evolution/views/calendar/"); + gal_view_collection_set_storage_directories (priv->view_collection, + EVOLUTION_DATADIR "/evolution/views/calendar/", + path); + g_free (path); + + /* Create the views */ + + factory = calendar_view_factory_new (GNOME_CAL_DAY_VIEW); + gal_view_collection_add_factory (priv->view_collection, GAL_VIEW_FACTORY (factory)); + gtk_object_unref (GTK_OBJECT (factory)); + + factory = calendar_view_factory_new (GNOME_CAL_WORK_WEEK_VIEW); + gal_view_collection_add_factory (priv->view_collection, GAL_VIEW_FACTORY (factory)); + gtk_object_unref (GTK_OBJECT (factory)); + + factory = calendar_view_factory_new (GNOME_CAL_WEEK_VIEW); + gal_view_collection_add_factory (priv->view_collection, GAL_VIEW_FACTORY (factory)); + gtk_object_unref (GTK_OBJECT (factory)); + + factory = calendar_view_factory_new (GNOME_CAL_MONTH_VIEW); + gal_view_collection_add_factory (priv->view_collection, GAL_VIEW_FACTORY (factory)); + gtk_object_unref (GTK_OBJECT (factory)); + + /* Load the collection and create the menus */ + + gal_view_collection_load (priv->view_collection); + + priv->view_menus = gal_view_menus_new (priv->view_collection); + gal_view_menus_apply (priv->view_menus, uic, NULL); + gtk_signal_connect (GTK_OBJECT (priv->view_collection), "display_view", + GTK_SIGNAL_FUNC (display_view_cb), 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_collection != NULL); + + g_assert (priv->view_collection != NULL); + g_assert (priv->view_menus != NULL); + + gtk_object_unref (GTK_OBJECT (priv->view_collection)); + priv->view_collection = NULL; + + gtk_object_unref (GTK_OBJECT (priv->view_menus)); + priv->view_menus = NULL; +} static void gnome_calendar_set_pane_positions (GnomeCalendar *gcal) @@ -788,7 +968,7 @@ gnome_calendar_set_pane_positions (GnomeCalendar *gcal) "column_width", &col_width, NULL); - if (priv->current_view_type == VIEW_MONTH && !priv->range_selected) { + if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { right_pane_width = priv->hpane_pos_month_view; top_pane_height = priv->vpane_pos_month_view; } else { @@ -919,8 +1099,7 @@ GtkWidget * gnome_calendar_construct (GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - gint view; - gchar *page; + GnomeCalendarViewType view_type; g_return_val_if_fail (gcal != NULL, NULL); g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); @@ -973,23 +1152,11 @@ gnome_calendar_construct (GnomeCalendar *gcal) /* Get the default view to show. */ - view = calendar_config_get_default_view (); - switch (view) { - case 1: - page = "workweekview"; - break; - case 2: - page = "weekview"; - break; - case 3: - page = "monthview"; - break; - default: - page = "dayview"; - break; - } + 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, page, FALSE, FALSE); + gnome_calendar_set_view (gcal, view_type, FALSE, FALSE); return GTK_WIDGET (gcal); } @@ -1341,7 +1508,7 @@ gnome_calendar_new_appointment_for (GnomeCalendar *cal, dtstart = time_day_begin (dtstart); dtend = time_day_end (dtend); } - + dt.value = &itt; dt.tzid = NULL; @@ -1389,78 +1556,105 @@ gnome_calendar_get_current_time_range (GnomeCalendar *gcal, time_t *end_time) { GnomeCalendarPrivate *priv; - GtkWidget *page; priv = gcal->priv; - page = get_current_page (gcal); + 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; - if (page == priv->day_view || page == priv->work_week_view) - e_day_view_get_selected_time_range (E_DAY_VIEW (page), start_time, end_time); - else if (page == priv->week_view || page == priv->month_view) - e_week_view_get_selected_time_range (E_WEEK_VIEW (page), start_time, end_time); - else { + default: g_message ("My penguin is gone!"); 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) +get_days_shown (GnomeCalendar *gcal, GDate *start_date, gint *days_shown) { 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; + switch (priv->current_view_type) { + case GNOME_CAL_DAY_VIEW: + g_date_clear (start_date, 1); + g_date_set_time (start_date, E_DAY_VIEW (priv->day_view)->lower); + *days_shown = e_day_view_get_days_shown (E_DAY_VIEW (priv->day_view)); + break; - if (gnome_calendar_get_days_shown (gcal, &start_date, &days_shown)) { - end_date = start_date; - g_date_add_days (&end_date, days_shown - 1); + case GNOME_CAL_WORK_WEEK_VIEW: + g_date_clear (start_date, 1); + g_date_set_time (start_date, E_DAY_VIEW (priv->work_week_view)->lower); + *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; - e_calendar_item_set_selection (priv->date_navigator->calitem, - &start_date, &end_date); + default: + g_assert_not_reached (); } } -static gboolean -gnome_calendar_get_days_shown (GnomeCalendar *gcal, - GDate *start_date, - gint *days_shown) +/* 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; - GtkWidget *page; + GDate start_date, end_date; + gint days_shown; priv = gcal->priv; - page = get_current_page (gcal); + /* If the ECalendar isn't visible, we just return. */ + if (!GTK_WIDGET_VISIBLE (priv->date_navigator)) + return; - if (page == priv->day_view || page == priv->work_week_view) { - g_date_clear (start_date, 1); - g_date_set_time (start_date, E_DAY_VIEW (page)->lower); - *days_shown = e_day_view_get_days_shown (E_DAY_VIEW (page)); - return TRUE; - } else if (page == priv->week_view || page == priv->month_view) { - *start_date = E_WEEK_VIEW (page)->first_day_shown; - if (e_week_view_get_multi_week_view (E_WEEK_VIEW (page))) - *days_shown = e_week_view_get_weeks_shown (E_WEEK_VIEW (page)) * 7; - else - *days_shown = 7; + get_days_shown (gcal, &start_date, &days_shown); - return TRUE; - } else { - g_assert_not_reached (); - return FALSE; - } + 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); } @@ -1480,8 +1674,7 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, starts_on_week_start_day = FALSE; - if (!gnome_calendar_get_days_shown (gcal, &start_date, &days_shown)) - return; + get_days_shown (gcal, &start_date, &days_shown); end_date = start_date; g_date_add_days (&end_date, days_shown - 1); @@ -1509,12 +1702,12 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, (new_days_shown + 6) / 7); e_week_view_set_first_day_shown (E_WEEK_VIEW (priv->month_view), &new_start_date); - gnome_calendar_set_view_internal (gcal, "monthview", TRUE, FALSE); + set_view (gcal, GNOME_CAL_MONTH_VIEW, TRUE, FALSE); gnome_calendar_update_date_navigator (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); - gnome_calendar_set_view_internal (gcal, "weekview", TRUE, FALSE); + set_view (gcal, GNOME_CAL_WEEK_VIEW, TRUE, FALSE); gnome_calendar_update_date_navigator (gcal); } else { start_year = g_date_year (&new_start_date); @@ -1543,11 +1736,11 @@ gnome_calendar_on_date_navigator_selection_changed (ECalendarItem *calitem, priv->selection_end_time = mktime (&tm); e_day_view_set_days_shown (E_DAY_VIEW (priv->day_view), new_days_shown); - gnome_calendar_set_view (gcal, "dayview", TRUE, FALSE); + set_view (gcal, GNOME_CAL_DAY_VIEW, TRUE, FALSE); } gnome_calendar_update_view_buttons (gcal); - gtk_widget_grab_focus (get_current_page (gcal)); + focus_current_view (gcal); } @@ -1628,40 +1821,37 @@ gnome_calendar_on_date_navigator_size_allocate (GtkWidget *widget, gcal = GNOME_CALENDAR (data); priv = gcal->priv; - if (priv->current_view_type != VIEW_NOT_SET) { - e_calendar_get_border_size (priv->date_navigator, - &top_border, &bottom_border, - &left_border, &right_border); - gtk_object_get (GTK_OBJECT (priv->date_navigator->calitem), - "row_height", &row_height, - "column_width", &col_width, - NULL); - - /* We subtract one from each dimension since we added 1 in - gnome_calendar_set_view_internal(). */ - width = allocation->width - 1; - height = allocation->height - 1; - - /* We add the border sizes to work around the EPaned - quantized feature. */ - col_width += left_border + right_border; - row_height += top_border + bottom_border; - - hpane_pos = (gfloat) width / col_width; - vpane_pos = (gfloat) height / row_height; - - if (priv->current_view_type == VIEW_MONTH - && !priv->range_selected) { - priv->hpane_pos_month_view = hpane_pos; - priv->vpane_pos_month_view = vpane_pos; - calendar_config_set_month_hpane_pos (hpane_pos); - calendar_config_set_month_vpane_pos (vpane_pos); - } else { - priv->hpane_pos = hpane_pos; - priv->vpane_pos = vpane_pos; - calendar_config_set_hpane_pos (hpane_pos); - calendar_config_set_vpane_pos (vpane_pos); - } + e_calendar_get_border_size (priv->date_navigator, + &top_border, &bottom_border, + &left_border, &right_border); + gtk_object_get (GTK_OBJECT (priv->date_navigator->calitem), + "row_height", &row_height, + "column_width", &col_width, + NULL); + + /* We subtract one from each dimension since we added 1 in + set_view(). */ + width = allocation->width - 1; + height = allocation->height - 1; + + /* We add the border sizes to work around the EPaned + quantized feature. */ + col_width += left_border + right_border; + row_height += top_border + bottom_border; + + hpane_pos = (gfloat) width / col_width; + vpane_pos = (gfloat) height / row_height; + + if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { + priv->hpane_pos_month_view = hpane_pos; + priv->vpane_pos_month_view = vpane_pos; + calendar_config_set_month_hpane_pos (hpane_pos); + calendar_config_set_month_vpane_pos (vpane_pos); + } else { + priv->hpane_pos = hpane_pos; + priv->vpane_pos = vpane_pos; + calendar_config_set_hpane_pos (hpane_pos); + calendar_config_set_vpane_pos (vpane_pos); } } @@ -1700,28 +1890,33 @@ void gnome_calendar_update_view_buttons (GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - GtkWidget *page, *button; + GtkWidget *button; priv = gcal->priv; - page = get_current_page (gcal); - - if (page == priv->day_view) + switch (priv->current_view_type) { + case GNOME_CAL_DAY_VIEW: button = priv->day_button; - else if (page == priv->work_week_view) + break; + + case GNOME_CAL_WORK_WEEK_VIEW: button = priv->work_week_button; - else if (page == priv->week_view) + break; + + case GNOME_CAL_WEEK_VIEW: button = priv->week_button; - else if (page == priv->month_view) + break; + + case GNOME_CAL_MONTH_VIEW: button = priv->month_button; - else { + break; + + default: g_assert_not_reached (); return; } - if (button) { - gtk_signal_handler_block_by_data (GTK_OBJECT (button), gcal); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - gtk_signal_handler_unblock_by_data (GTK_OBJECT (button), gcal); - } + gtk_signal_handler_block_by_data (GTK_OBJECT (button), gcal); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + gtk_signal_handler_unblock_by_data (GTK_OBJECT (button), gcal); } diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index dbda38c593..9ff25c50f5 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -29,6 +29,7 @@ #include <time.h> #include <libgnome/gnome-defs.h> #include <gtk/gtkvbox.h> +#include <bonobo/bonobo-ui-component.h> #include <widgets/misc/e-calendar.h> #include <cal-client/cal-client.h> @@ -47,6 +48,14 @@ 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; @@ -69,6 +78,8 @@ 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, char *sexp); + void gnome_calendar_next (GnomeCalendar *gcal); void gnome_calendar_previous (GnomeCalendar *gcal); void gnome_calendar_goto (GnomeCalendar *gcal, @@ -77,11 +88,13 @@ void gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time); /* Jumps to the current day */ void gnome_calendar_goto_today (GnomeCalendar *gcal); -char *gnome_calendar_get_current_view_name (GnomeCalendar *gcal); -void gnome_calendar_set_view (GnomeCalendar *gcal, - char *page_name, - gboolean reset_range_shown, - gboolean focus); + +GnomeCalendarViewType gnome_calendar_get_view (GnomeCalendar *gcal); +void gnome_calendar_set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_type, + gboolean range_selected, gboolean grab_focus); + +void gnome_calendar_setup_view_menus (GnomeCalendar *gcal, BonoboUIComponent *uic); +void gnome_calendar_discard_view_menus (GnomeCalendar *gcal); void gnome_calendar_set_selected_time_range (GnomeCalendar *gcal, time_t start_time, |