diff options
author | Seth Alves <alves@src.gnome.org> | 2000-04-06 04:13:45 +0800 |
---|---|---|
committer | Seth Alves <alves@src.gnome.org> | 2000-04-06 04:13:45 +0800 |
commit | ce3b224ed64f470fd5031342930f7c8f773c6eeb (patch) | |
tree | fc3d645e2378d131901f99b193cf304b394f248e /calendar | |
parent | 0c061c70785480f5d528722f89df2d32bf558121 (diff) | |
download | gsoc2013-evolution-ce3b224ed64f470fd5031342930f7c8f773c6eeb.tar.gz gsoc2013-evolution-ce3b224ed64f470fd5031342930f7c8f773c6eeb.tar.zst gsoc2013-evolution-ce3b224ed64f470fd5031342930f7c8f773c6eeb.zip |
build test-calendar-widget and evolution-calendar, common stuff is in a
* gui/Makefile.am: build test-calendar-widget and evolution-calendar,
common stuff is in a library
* gui/gnome-cal.c (gnome_calendar_get_type): made the calendar widget
based on a gtk_frame rather than a gnome_app
* gui/calendar-commands.c: split out some of main.c
* gui/evolution-calendar-control.c: bonobo bung so evolution
can use the calendar widget
svn path=/trunk/; revision=2294
Diffstat (limited to 'calendar')
26 files changed, 1219 insertions, 889 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 2319186602..2e1b6c52a4 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,9 +1,26 @@ +2000-04-05 Seth Alves <alves@hungry.com> + + * gui/Makefile.am: build test-calendar-widget and evolution-calendar, + common stuff is in a library + + * gui/gnome-cal.c (gnome_calendar_get_type): made the calendar widget + based on a gtk_frame rather than a gnome_app + + * gui/calendar-commands.c: split out some of main.c + + * gui/evolution-calendar-control.c: bonobo bung so evolution + can use the calendar widget + 2000-04-01 Matt Loper <matt@helixcode.com> * pcs/.cvsignore: Added *.lo. 2000-03-30 Seth Alves <alves@hungry.com> + * gui/main.c (calendar_get_events_in_range): + cal_client_get_events_in_range returns a list of CalObjInstance *, not + a list of (char *) uid. + * Makefile.am (SUBDIRS): readded the gui directory * gui/main.c: temporarily added alarm_defaults back in, diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 168ec31d72..710212ba7c 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* Evolution calendar client * * Copyright (C) 2000 Helix Code, Inc. @@ -603,7 +604,9 @@ cal_client_get_uids (CalClient *client, CalObjType type) g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + /*g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL);*/ + if (priv->load_state != LOAD_STATE_LOADED) + return NULL; t = (((type & CALOBJ_TYPE_EVENT) ? Evolution_Calendar_TYPE_EVENT : 0) | ((type & CALOBJ_TYPE_TODO) ? Evolution_Calendar_TYPE_TODO : 0) @@ -656,7 +659,9 @@ cal_client_get_events_in_range (CalClient *client, time_t start, time_t end) g_return_val_if_fail (IS_CAL_CLIENT (client), NULL); priv = client->priv; - g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL); + /*g_return_val_if_fail (priv->load_state == LOAD_STATE_LOADED, NULL);*/ + if (priv->load_state != LOAD_STATE_LOADED) + return NULL; g_return_val_if_fail (start != -1 && end != -1, NULL); g_return_val_if_fail (start <= end, NULL); diff --git a/calendar/gui/.cvsignore b/calendar/gui/.cvsignore index 5c39acb0e8..0a9fac91ec 100644 --- a/calendar/gui/.cvsignore +++ b/calendar/gui/.cvsignore @@ -4,7 +4,8 @@ Makefile _libs .libs gncal -gnomecal +evolution-calendar +test-calendar-widget getdate.c GnomeCal-skels.c GnomeCal-common.c diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index c506044f7d..6f35ed7ed2 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -1,15 +1,11 @@ help_base = $(datadir)/gnome/help/cal -#bin_PROGRAMS = gnomecal $(extra_pilot_bins) -bin_PROGRAMS = gnomecal - #if HAVE_GNOME_PILOT #extra_pilot_bins = \ # calendar-conduit-control-applet \ # calendar-pilot-sync #endif -ICAL_LINK_FLAGS = $(top_builddir)/libical/src/libical/libical.la INCLUDES = \ -I$(includedir) \ @@ -21,7 +17,20 @@ INCLUDES = \ -I$(top_srcdir)/libical/src/libical \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" -gnomecal_SOURCES = \ + +LINK_FLAGS = \ + $(BONOBO_VFS_GNOME_LIBS) \ + $(INTLLIBS) \ + $(top_builddir)/calendar/cal-util/libcalutil.la \ + $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/widgets/e-text/libetext.a \ + $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/libical/src/libical/libical.la \ + $(top_builddir)/calendar/cal-client/libcal-client.la + +noinst_LIBRARIES = libcalendarwidget.a + +libcalendarwidget_a_SOURCES = \ alarm.c \ alarm.h \ e-day-view-main-item.c \ @@ -66,8 +75,36 @@ gnomecal_SOURCES = \ view-utils.c \ year-view.c \ year-view.h \ - main.c \ - main.h + calendar-commands.c \ + calendar-commands.h + + +bin_PROGRAMS = evolution-calendar +noinst_PROGRAMS = test-calendar-widget +test_calendar_widget_SOURCES = main.c +test_calendar_widget_INCLUDES = \ + $(INCLUDES) \ + -DG_LOG_DOMAIN=\"test-calendar-widget\" +test_calendar_widget_LDADD = \ + libcalendarwidget.a \ + $(LINK_FLAGS) + +evolution_calendar_SOURCES = evolution-calendar-control.c + +evolution_calendar_LDADD = \ + $(EXTRA_GNOME_LIBS) \ + $(BONOBO_HTML_GNOME_LIBS) \ + $(top_builddir)/calendar/gui/libcalendarwidget.a \ + $(top_builddir)/widgets/e-minicard/libeminicard.a \ + $(top_builddir)/widgets/e-table/libetable.a \ + $(top_builddir)/widgets/e-text/libetext.a \ + $(top_builddir)/e-util/libeutil.la \ + $(LINK_FLAGS) + +evolution_calendar_LDFLAGS = `gnome-config --libs gdk_pixbuf` + +gnorbadir = $(sysconfdir)/CORBA/servers +gnorba_DATA = calendar-control.gnorba #calendar_pilot_sync_SOURCES = \ # GnomeCal-common.c \ @@ -77,15 +114,6 @@ gnomecal_SOURCES = \ # calendar.c \ # calendar.h -LINK_FLAGS = \ - $(BONOBO_VFS_GNOME_LIBS) \ - $(INTLLIBS) \ - $(top_builddir)/calendar/cal-util/libcalutil.la \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/libversit/libversit.la \ - $(ICAL_LINK_FLAGS) \ - $(top_builddir)/calendar/cal-client/libcal-client.la #calendar_pilot_sync_LDADD = \ # $(PISOCK_LIBDIR) $(PISOCK_LIBS) \ @@ -156,12 +184,6 @@ LINK_FLAGS = \ # $(GNOME_PILOT_LIBS) \ # $(INTLLIBS) -gnomecal_INCLUDES = \ - $(INCLUDES) \ - -DG_LOG_DOMAIN=\"gnomecal\" - -gnomecal_LDADD = $(LINK_FLAGS) - #if HAVE_GNOME_PILOT #ccenterdir = $(datadir)/control-center #Rootdir = $(ccenterdir) diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c new file mode 100644 index 0000000000..7323a04e5b --- /dev/null +++ b/calendar/gui/calendar-commands.c @@ -0,0 +1,792 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Main file for the GNOME Calendar program + * Copyright (C) 1998 the Free Software Foundation + * + * Authors: + * Miguel de Icaza (miguel@kernel.org) + * Federico Mena (federico@helixcode.com) + */ + +#include <config.h> +#include <pwd.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> +#include <gnome.h> +#include <libgnorba/gnorba.h> +#include <bonobo.h> +#include <cal-util/timeutil.h> +#include "alarm.h" +#include "eventedit.h" +#include "gnome-cal.h" +#include "calendar-commands.h" + + +/* The username, used to set the `owner' field of the event */ +char *user_name; + +/* The full user name from the Gecos field */ +char *full_name; + +/* The user's default calendar file */ +char *user_calendar_file; + +/* a gnome-config string prefix that can be used to access the calendar config info */ +char *calendar_settings; + +/* Day begin, day end parameters */ +int day_begin, day_end; + +/* Whether weeks starts on Sunday or Monday */ +int week_starts_on_monday; + +/* If true, enable debug output for alarms */ +int debug_alarms = 0; + + +/* The array of color properties -- keep in sync with the enumeration defined in main.h. The color + * values specified here are the defaults for the program. + */ +struct color_prop color_props[] = { + { 0x3e72, 0x35ec, 0x8ba2, N_("Outline:"), "/calendar/Colors/outline" }, + { 0xffff, 0xffff, 0xffff, N_("Headings:"), "/calendar/Colors/headings" }, + { 0xf26c, 0xecec, 0xbbe7, N_("Empty days:"), "/calendar/Colors/empty_bg" }, + { 0xfc1e, 0xf87f, 0x5f80, N_("Appointments:"), "/calendar/Colors/mark_bg" }, + { 0xd364, 0xc6b7, 0x7969, N_("Highlighted day:"), "/calendar/Colors/prelight_bg" }, + { 0x01f0, 0x01f0, 0x01f0, N_("Day numbers:"), "/calendar/Colors/day_fg" }, + { 0x0000, 0x0000, 0xffff, N_("Current day's number:"), "/calendar/Colors/current_fg" }, + { 0xbbbb, 0xbbbb, 0x0000, N_("To-Do item that is not yet due:"), "/calendar/Colors/todo_not_yet" }, + { 0xdddd, 0xbbbb, 0x0000, N_("To-Do item that is due today:"), "/calendar/Colors/todo_today" }, + { 0xbbbb, 0xdddd, 0x0000, N_("To-Do item that is overdue:"), "/calendar/Colors/todo_overdue" } +}; + +/* Number of active calendars */ +int active_calendars = 0; + +/* A list of all of the calendars started */ +GList *all_calendars = NULL; + +/* If set, beep on display alarms */ +gboolean beep_on_display = 0; + +/* If true, timeout the beeper on audio alarms */ + +gboolean enable_aalarm_timeout = 0; +guint audio_alarm_timeout = 0; +const guint MAX_AALARM_TIMEOUT = 3600; +const guint MAX_SNOOZE_SECS = 3600; +gboolean enable_snooze = 0; +guint snooze_secs = 60; + +/*extern CalendarAlarm alarm_defaults[4];*/ +CalendarAlarm alarm_defaults[4] = { + { ALARM_MAIL, 0, 15, ALARM_MINUTES }, + { ALARM_PROGRAM, 0, 15, ALARM_MINUTES }, + { ALARM_DISPLAY, 0, 15, ALARM_MINUTES }, + { ALARM_AUDIO, 0, 15, ALARM_MINUTES } +}; + + +static void +init_username (void) +{ + user_name = g_strdup(g_get_user_name()); + full_name = g_strdup(g_get_real_name()); +} + +static int +range_check_hour (int hour) +{ + if (hour < 0) + hour = 0; + else if (hour >= 24) + hour = 23; + + return hour; +} + +static void +init_default_alarms (void) +{ + int i; + gboolean def; + + alarm_defaults [ALARM_DISPLAY].type = ALARM_DISPLAY; + alarm_defaults [ALARM_AUDIO].type = ALARM_AUDIO; + alarm_defaults [ALARM_PROGRAM].type = ALARM_PROGRAM; + alarm_defaults [ALARM_MAIL].type = ALARM_MAIL; + + for (i = 0; i < 4; i++) { + switch (alarm_defaults [i].type) { + case ALARM_DISPLAY: + gnome_config_push_prefix ("/calendar/alarms/def_disp_"); + break; + case ALARM_AUDIO: + gnome_config_push_prefix ("/calendar/alarms/def_audio_"); + break; + case ALARM_PROGRAM: + gnome_config_push_prefix ("/calendar/alarms/def_prog_"); + break; + case ALARM_MAIL: + gnome_config_push_prefix ("/calendar/alarms/def_mail_"); + break; + } + + alarm_defaults[i].enabled = gnome_config_get_int ("enabled=0"); + if (alarm_defaults[i].type != ALARM_MAIL) { + alarm_defaults[i].count = gnome_config_get_int ("count=15"); + alarm_defaults[i].units = gnome_config_get_int ("units=0"); + } else { + alarm_defaults[i].count = gnome_config_get_int ("count=1"); + alarm_defaults[i].count = gnome_config_get_int ("count=2"); + } + + alarm_defaults[i].data = gnome_config_get_string_with_default ("data=", + &def); + if (def) + alarm_defaults[i].data = NULL; + + gnome_config_pop_prefix (); + } +} + + +/* static void save_calendar_cmd (GtkWidget *widget, void *data); DELETE */ + +static void +about_calendar_cmd (GtkWidget *widget, void *data) +{ + GtkWidget *about; + const gchar *authors[] = { + "Miguel de Icaza (miguel@kernel.org)", + "Federico Mena (federico@gimp.org)", + "Arturo Espinosa (arturo@nuclecu.unam.mx)", + "Russell Steinthal (rms39@columbia.edu)", + NULL + }; + + about = gnome_about_new (_("Gnome Calendar"), VERSION, + "(C) 1998 the Free Software Foundation", + authors, + _("The GNOME personal calendar and schedule manager."), + NULL); + gtk_window_set_modal (GTK_WINDOW (about), TRUE); + gnome_dialog_set_close (GNOME_DIALOG (about), TRUE); + gtk_widget_show (about); +} + +static void +display_objedit (GtkWidget *widget, GnomeCalendar *gcal) +{ + GtkWidget *ee; + iCalObject *ico; + + /* Default to the day the user is looking at */ + ico = ical_new ("", user_name, ""); + ico->new = 1; + ico->dtstart = time_add_minutes (gcal->current_display, day_begin * 60); + ico->dtend = time_add_minutes (ico->dtstart, day_begin * 60 + 30 ); + + ee = event_editor_new (gcal, ico); + gtk_widget_show (ee); +} + +static void +display_objedit_today (GtkWidget *widget, GnomeCalendar *gcal) +{ + GtkWidget *ee; + + ee = event_editor_new (gcal, NULL); + gtk_widget_show (ee); +} + +void +time_format_changed (void) +{ + GList *l; + + for (l = all_calendars; l; l = l->next) + gnome_calendar_time_format_changed (GNOME_CALENDAR (l->data)); +} + +void +colors_changed (void) +{ + GList *l; + + for (l = all_calendars; l; l = l->next) + gnome_calendar_colors_changed (GNOME_CALENDAR (l->data)); +} + +void +todo_properties_changed(void) +{ + GList *l; + + for (l = all_calendars; l; l = l->next) + gnome_calendar_todo_properties_changed (GNOME_CALENDAR (l->data)); +} + +/* 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 (GtkWidget *widget, GnomeCalendar *gcal) +{ + set_clock_cursor (gcal); + gnome_calendar_previous (gcal); + set_normal_cursor (gcal); +} + +static void +next_clicked (GtkWidget *widget, GnomeCalendar *gcal) +{ + set_clock_cursor (gcal); + gnome_calendar_next (gcal); + set_normal_cursor (gcal); +} + +static void +today_clicked (GtkWidget *widget, GnomeCalendar *gcal) +{ + set_clock_cursor (gcal); + gnome_calendar_goto_today (gcal); + set_normal_cursor (gcal); +} + +static void +goto_clicked (GtkWidget *widget, GnomeCalendar *gcal) +{ + goto_dialog (gcal); +} + +static void +new_calendar_cmd (GtkWidget *widget, void *data) +{ + new_calendar (full_name, NULL, NULL, NULL, FALSE); +} + +void +close_cmd (GtkWidget *widget, GnomeCalendar *gcal) +{ + all_calendars = g_list_remove (all_calendars, gcal); + + /* DELETE + FIXME -- what do i do here? + if (gcal->cal->modified){ + if (!gcal->cal->filename) + save_calendar_cmd (widget, gcal); + else + calendar_save (gcal->cal, gcal->cal->filename); + } + */ + + gtk_widget_destroy (GTK_WIDGET (gcal)); + active_calendars--; + + if (active_calendars == 0) + gtk_main_quit (); +} + + +void +quit_cmd (void) +{ + while (all_calendars){ + GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data); + + close_cmd (GTK_WIDGET (cal), cal); + } +} + + +static void +open_ok (GtkWidget *widget, GtkFileSelection *fs) +{ + GtkWidget *error_dialog; + int ret; + if(!g_file_exists (gtk_file_selection_get_filename (fs))) { + error_dialog = gnome_message_box_new ( + _("File not found"), + GNOME_MESSAGE_BOX_ERROR, + GNOME_STOCK_BUTTON_OK, + NULL); + + gnome_dialog_set_parent (GNOME_DIALOG (error_dialog), GTK_WINDOW (fs)); + ret = gnome_dialog_run (GNOME_DIALOG (error_dialog)); + } else { + /* FIXME: find out who owns this calendar and use that name */ + new_calendar ("Somebody", gtk_file_selection_get_filename (fs), NULL, NULL, FALSE); + gtk_widget_destroy (GTK_WIDGET (fs)); + } +} + +static void +open_calendar_cmd (GtkWidget *widget, void *data) +{ + GtkFileSelection *fs; + + fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Open calendar"))); + + gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", + (GtkSignalFunc) open_ok, + fs); + gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", + (GtkSignalFunc) gtk_widget_destroy, + GTK_OBJECT (fs)); + + gtk_widget_show (GTK_WIDGET (fs)); + gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me */ +} + +static void +save_ok (GtkWidget *widget, GtkFileSelection *fs) +{ + GnomeCalendar *gcal; + gchar *fname; + + gcal = GNOME_CALENDAR (gtk_object_get_user_data (GTK_OBJECT (fs))); + gtk_window_set_wmclass (GTK_WINDOW (gcal), "gnomecal", "gnomecal"); + + fname = g_strdup (gtk_file_selection_get_filename (fs)); + /* calendar_save (gcal->cal, fname); DELETE / FIXME*/ + g_free(fname); + gtk_main_quit (); +} + +static gint +close_save (GtkWidget *w) +{ + gtk_main_quit (); + return TRUE; +} + +static void +save_as_calendar_cmd (GtkWidget *widget, void *data) +{ + GtkFileSelection *fs; + + fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Save calendar"))); + gtk_object_set_user_data (GTK_OBJECT (fs), data); + + gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", + (GtkSignalFunc) save_ok, + fs); + gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", + (GtkSignalFunc) close_save, + GTK_OBJECT (fs)); + gtk_signal_connect_object (GTK_OBJECT (fs), "delete_event", + GTK_SIGNAL_FUNC (close_save), + GTK_OBJECT (fs)); + gtk_widget_show (GTK_WIDGET (fs)); + gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me even more */ + gtk_main (); + gtk_widget_destroy (GTK_WIDGET (fs)); +} + +static void +properties_cmd (GtkWidget *widget, GtkWidget *gcal) +{ + properties (gcal); +} + +# if 0 /* DELETE */ +static void +save_calendar_cmd (GtkWidget *widget, void *data) +{ + GnomeCalendar *gcal = data; + + if (gcal->cal->filename){ + struct stat s; + + if (stat (gcal->cal->filename, &s) == -1){ + if (errno == ENOENT) + calendar_save (gcal->cal, gcal->cal->filename); + + return; + } + + if (s.st_mtime != gcal->cal->file_time){ + GtkWidget *box; + char *str; + int b; + + str = g_strdup_printf ( + _("File %s has changed since it was loaded\nContinue?"), + gcal->cal->filename); + box = gnome_message_box_new (str, GNOME_MESSAGE_BOX_INFO, + GNOME_STOCK_BUTTON_YES, + GNOME_STOCK_BUTTON_NO, + NULL); + g_free (str); + gnome_dialog_set_default (GNOME_DIALOG (box), 1); + b = gnome_dialog_run (GNOME_DIALOG (box)); + + if (b != 0) + return; + } + + calendar_save (gcal->cal, gcal->cal->filename); + } else + save_as_calendar_cmd (widget, data); +} +#endif /* 0 */ + +static GnomeUIInfo gnome_cal_file_menu [] = { + GNOMEUIINFO_MENU_NEW_ITEM(N_("_New calendar"), + N_("Create a new calendar"), + new_calendar_cmd, NULL), + + GNOMEUIINFO_MENU_OPEN_ITEM(open_calendar_cmd, NULL), + + /* GNOMEUIINFO_MENU_SAVE_ITEM(save_calendar_cmd, NULL), FIXME */ + + GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_calendar_cmd, NULL), + + GNOMEUIINFO_SEPARATOR, + + GNOMEUIINFO_MENU_CLOSE_ITEM(close_cmd, NULL), + + GNOMEUIINFO_MENU_EXIT_ITEM(quit_cmd, NULL), + + GNOMEUIINFO_END +}; + +static GnomeUIInfo gnome_cal_edit_menu [] = { + { GNOME_APP_UI_ITEM, N_("_New appointment..."), + N_("Create a new appointment"), display_objedit, NULL, NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, + { GNOME_APP_UI_ITEM, N_("New appointment for _today..."), + N_("Create a new appointment for today"), + display_objedit_today, NULL, NULL, + GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, + GNOMEUIINFO_END +}; + +static GnomeUIInfo gnome_cal_help_menu [] = { + GNOMEUIINFO_HELP ("gnomecal"), + + GNOMEUIINFO_MENU_ABOUT_ITEM(about_calendar_cmd, NULL), + + GNOMEUIINFO_END +}; + +static GnomeUIInfo gnome_cal_settings_menu [] = { + GNOMEUIINFO_MENU_PREFERENCES_ITEM(properties_cmd, NULL), + + GNOMEUIINFO_END +}; + +static GnomeUIInfo gnome_cal_menu [] = { + GNOMEUIINFO_MENU_FILE_TREE(gnome_cal_file_menu), + GNOMEUIINFO_MENU_EDIT_TREE(gnome_cal_edit_menu), + GNOMEUIINFO_MENU_SETTINGS_TREE(gnome_cal_settings_menu), + GNOMEUIINFO_MENU_HELP_TREE(gnome_cal_help_menu), + GNOMEUIINFO_END +}; + +static GnomeUIInfo gnome_toolbar [] = { + GNOMEUIINFO_ITEM_STOCK (N_("New"), N_("Create a new appointment"), display_objedit, GNOME_STOCK_PIXMAP_NEW), + + GNOMEUIINFO_SEPARATOR, + + GNOMEUIINFO_ITEM_STOCK (N_("Prev"), N_("Go back in time"), previous_clicked, GNOME_STOCK_PIXMAP_BACK), + GNOMEUIINFO_ITEM_STOCK (N_("Today"), N_("Go to present time"), today_clicked, GNOME_STOCK_PIXMAP_HOME), + GNOMEUIINFO_ITEM_STOCK (N_("Next"), N_("Go forward in time"), next_clicked, GNOME_STOCK_PIXMAP_FORWARD), + + GNOMEUIINFO_SEPARATOR, + + GNOMEUIINFO_ITEM_STOCK (N_("Go to"), N_("Go to a specific date"), goto_clicked, GNOME_STOCK_PIXMAP_JUMP_TO), + + GNOMEUIINFO_END +}; + +static void +setup_menu (GtkWidget *gcal) +{ + /* + gnome_app_create_menus_with_data (GNOME_APP (gcal), gnome_cal_menu, gcal); + gnome_app_create_toolbar_with_data (GNOME_APP (gcal), gnome_toolbar, gcal); + gnome_app_install_menu_hints(GNOME_APP(gcal), gnome_cal_menu); + */ +#warning "menus and toolbar are commented out here" +} + +static void +setup_appbar (GtkWidget *gcal) +{ + GtkWidget *appbar; + + appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_USER); + /*gnome_app_set_statusbar (GNOME_APP (gcal), GTK_WIDGET (appbar));*/ +#warning "appbar is commented out here" +} + +static gint +calendar_close_event (GtkWidget *widget, GdkEvent *event, GnomeCalendar *gcal) +{ + close_cmd (widget, gcal); + return TRUE; +} + +GnomeCalendar * +new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, gboolean hidden) +{ + GtkWidget *toplevel; + char title[128]; + int xpos, ypos, width, height; + + /* i18n: This "%s%s" indicates possession. Languages where the order is + * the inverse should translate it to "%2$s%1$s". + */ + g_snprintf(title, 128, _("%s%s"), full_name, _("'s calendar")); + + toplevel = gnome_calendar_new (title); + + if (gnome_parse_geometry (geometry, &xpos, &ypos, &width, &height)){ + if (xpos != -1) + gtk_widget_set_uposition (toplevel, xpos, ypos); +#if 0 + if (width != -1) + gtk_widget_set_usize (toplevel, width, 600); +#endif + } +#if 0 + gtk_widget_set_usize (toplevel, width, 600); +#endif + + setup_appbar (toplevel); + setup_menu (toplevel); + + + if (page) + gnome_calendar_set_view (GNOME_CALENDAR (toplevel), page); + + if (calendar_file && g_file_exists (calendar_file)) + gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); + /* FIX ME + else + GNOME_CALENDAR (toplevel)->client->filename = g_strdup (calendar_file); + */ + + gtk_signal_connect (GTK_OBJECT (toplevel), "delete_event", + GTK_SIGNAL_FUNC(calendar_close_event), toplevel); + + active_calendars++; + all_calendars = g_list_prepend (all_calendars, toplevel); + + if (hidden){ + GnomeWinState state; + + /* Realize the toplevel window to prevent a segfault */ + gtk_widget_realize (toplevel); + state = gnome_win_hints_get_state (toplevel); + + state |= WIN_STATE_MINIMIZED; + gnome_win_hints_set_state (toplevel, state); + } + + gtk_widget_show (toplevel); + + return GNOME_CALENDAR (toplevel); +} + + + + +/* + * Initializes the calendar internal variables, loads defaults + */ +void init_calendar (void) +{ + int i; + char *cspec, *color; + char *str; + + init_username (); + /*user_calendar_file = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/user-cal.vcf");*/ +#warning "unhardcode home directory" + user_calendar_file = g_concat_dir_and_file ("/home/alves", ".gnome/user-cal.vcf"); + + gnome_config_push_prefix (calendar_settings); + + /* Read calendar settings */ + + day_begin = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day start=8")); + day_end = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day end=17")); + am_pm_flag = gnome_config_get_bool ("/calendar/Calendar/AM PM flag=0"); + week_starts_on_monday = gnome_config_get_bool ("/calendar/Calendar/Week starts on Monday=0"); + + if (day_end < day_begin){ + day_begin = 8; + day_end = 17; + } + + /* Read color settings */ + + for (i = 0; i < COLOR_PROP_LAST; i++) { + cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b); + str = g_strconcat (color_props[i].key, "=", cspec, NULL); + + color = gnome_config_get_string (str); + parse_color_spec (color, &color_props[i].r, &color_props[i].g, &color_props[i].b); + + g_free (str); + g_free (color); + } + + /* read todolist settings */ + + todo_show_time_remaining = gnome_config_get_bool("/calendar/Todo/show_time_remain"); + todo_show_due_date = gnome_config_get_bool("/calendar/Todo/show_due_date"); + + todo_item_dstatus_highlight_overdue = gnome_config_get_bool("/calendar/Todo/highlight_overdue"); + + todo_item_dstatus_highlight_due_today = gnome_config_get_bool("/calendar/Todo/highlight_due_today"); + + todo_item_dstatus_highlight_not_due_yet = gnome_config_get_bool("/calendar/Todo/highlight_not_due_yet"); + + todo_current_sort_column = gnome_config_get_int("/calendar/Todo/sort_column"); + + todo_current_sort_type = gnome_config_get_int("/calendar/Todo/sort_type"); + + todo_show_priority = gnome_config_get_bool("/calendar/Todo/show_priority"); + + /* read alarm settings */ + beep_on_display = gnome_config_get_bool ("/calendar/alarms/beep_on_display=FALSE"); + enable_aalarm_timeout = gnome_config_get_bool ("/calendar/alarms/enable_audio_timeout=FALSE"); + audio_alarm_timeout = gnome_config_get_int ("/calendar/alarms/audio_alarm_timeout=60"); + if (audio_alarm_timeout < 1) + audio_alarm_timeout = 1; + if (audio_alarm_timeout > MAX_AALARM_TIMEOUT) + audio_alarm_timeout = MAX_AALARM_TIMEOUT; + enable_snooze = gnome_config_get_bool ("/calendar/alarms/enable_snooze=FALSE"); + snooze_secs = gnome_config_get_int ("/calendar/alarms/snooze_secs=300"); + if (snooze_secs < 1) + snooze_secs = 1; + if (snooze_secs > MAX_SNOOZE_SECS) + snooze_secs = MAX_SNOOZE_SECS; + + init_default_alarms (); + + + /* Done */ + + gnome_config_pop_prefix (); +} + + + +/* FIXME -- where should this go? */ +void +calendar_iterate (GnomeCalendar *cal, + time_t start, time_t end, + calendarfn cb, void *closure) +{ + GList *l, *uids = 0; + + uids = cal_client_get_uids (cal->client, CALOBJ_TYPE_EVENT); + + for (l = uids; l; l = l->next){ + CalObjFindStatus status; + iCalObject *ico; + char *uid = l->data; + char *obj_string = cal_client_get_object (cal->client, uid); + + /*iCalObject *obj = string_to_ical_object (obj_string);*/ + status = ical_object_find_in_string (uid, obj_string, &ico); + switch (status){ + case CAL_OBJ_FIND_SUCCESS: + ical_object_generate_events (ico, start, end, + cb, closure); + break; + case CAL_OBJ_FIND_SYNTAX_ERROR: + printf("calendar_iterate: syntax error uid=%s\n",uid); + break; + case CAL_OBJ_FIND_NOT_FOUND: + printf("calendar_iterate: obj not found uid=%s\n",uid); + break; + } + + g_free (l->data); + } + g_list_free (uids); +} + + + +static gint +calendar_object_compare_by_start (gconstpointer a, gconstpointer b) +{ + const CalendarObject *ca = a; + const CalendarObject *cb = b; + time_t diff; + + diff = ca->ev_start - cb->ev_start; + return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; +} + +/* FIXME -- where should this (and calendar_object_compare_by_start) go? */ +/* returns a list of events in the form of CalendarObject* */ +GList *calendar_get_events_in_range (CalClient *calc, + time_t start, time_t end) +{ + GList *l, *uids, *res = 0; + uids = cal_client_get_events_in_range (calc, start, end); + + for (l = uids; l; l = l->next){ + CalObjFindStatus status; + CalObjInstance *coi = l->data; + char *uid = coi->uid; + char *obj_string = cal_client_get_object (calc, uid); + iCalObject *ico; + + + status = ical_object_find_in_string (uid, obj_string, &ico); + switch (status){ + case CAL_OBJ_FIND_SUCCESS: + { + CalendarObject *co = g_new (CalendarObject, 1); + co->ev_start = start; + co->ev_end = end; + co->ico = ico; + + res = g_list_insert_sorted (res, co, + calendar_object_compare_by_start); + break; + } + case CAL_OBJ_FIND_SYNTAX_ERROR: + printf ("calendar_get_events_in_range: " + "syntax error uid=%s\n", uid); + break; + case CAL_OBJ_FIND_NOT_FOUND: + printf ("calendar_get_events_in_range: " + "obj not found uid=%s\n", uid); + break; + } + + } + + return res; +} diff --git a/calendar/gui/calendar-commands.h b/calendar/gui/calendar-commands.h new file mode 100644 index 0000000000..2f6c25f04c --- /dev/null +++ b/calendar/gui/calendar-commands.h @@ -0,0 +1,131 @@ +#ifndef CALENDAR_COMMANDS_H +#define CALENDAR_COMMANDS_H + +/* This enum and the following array define the color preferences */ + +typedef enum { + COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */ + COLOR_PROP_HEADING_COLOR, /* Color for headings */ + COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */ + COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */ + COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ + COLOR_PROP_DAY_FG, /* Color for day numbers */ + COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ + COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */ + COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */ + COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */ + COLOR_PROP_LAST /* Number of color properties */ +} ColorProp; + +struct color_prop { + int r; /* Values are in [0, 65535] */ + int g; + int b; + char *label; /* Label for properties dialog */ + char *key; /* Key for gnome_config */ +}; + +extern struct color_prop color_props[]; + + +#define COOKIE_USER_HOME_DIR ((char *) -1) + + +/* Calendar preferences */ + +extern int day_begin, day_end; +extern char *user_name; +extern int am_pm_flag; +extern int week_starts_on_monday; + +/* todo preferences */ +extern int todo_show_due_date; + +extern int todo_item_dstatus_highlight_overdue; +extern int todo_item_dstatus_highlight_due_today; +extern int todo_item_dstatus_highlight_not_due_yet; + +extern int todo_show_time_remaining; +extern int todo_show_priority; +extern char *todo_overdue_font_text; +extern gboolean todo_style_changed; +extern gint todo_current_sort_column; +extern gint todo_current_sort_type; + +/* alarm stuff */ +extern CalendarAlarm alarm_defaults[4]; +extern gboolean beep_on_display; +extern gboolean enable_aalarm_timeout; +extern guint audio_alarm_timeout; +extern const guint MAX_AALARM_TIMEOUT; +extern gboolean enable_snooze; +extern guint snooze_secs; +extern const guint MAX_SNOOZE_SECS; + +/* Creates and runs the preferences dialog box */ +void properties (GtkWidget *toplevel); + +/* Asks for all the time-related displays to be updated when the user changes the time format + * preferences. + */ +void time_format_changed (void); + +/* Asks for all the month items' colors to be reset */ +void colors_changed (void); + +/* Asks for all todo lists to reflect the accurate properties */ +void todo_properties_changed(void); + +/* Creates and runs the Go-to date dialog */ +void goto_dialog (GnomeCalendar *gcal); + +/* Returns a pointer to a statically-allocated string with a representation of the specified color. + * Values must be in [0, 65535]. + */ +char *build_color_spec (int r, int g, int b); + +/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */ +void parse_color_spec (char *spec, int *r, int *g, int *b); + +/* Calls build_color_spec() for the color in the specified property number */ +char *color_spec_from_prop (ColorProp propnum); + +GnomeCalendar *new_calendar (char *full_name, char *calendar_file, + char *geometry, char *page, gboolean hidden); + + +/*----------------------------------------------------------------------*/ +/* FIX ME -- where should this stuff go? */ +/*----------------------------------------------------------------------*/ + +/* This is only used by the calendar_get_events_in_range routine to get + * a list of objects that recur on a specific date + */ +typedef struct { + time_t ev_start; + time_t ev_end; + iCalObject *ico; +} CalendarObject; + +GList *calendar_get_events_in_range (CalClient *calc, + time_t start, time_t end); +void +calendar_iterate (GnomeCalendar *cal, + time_t start, time_t end, + calendarfn cb, void *closure); + +void init_calendar (void); + + + +void close_cmd (GtkWidget *widget, GnomeCalendar *gcal); +void quit_cmd (void); + +extern char *user_calendar_file; +extern char *user_name; +extern char *full_name; +extern int debug_alarms; +extern int active_calendars; +extern GList *all_calendars; + +#endif /* CALENDAR_COMMANDS_H */ diff --git a/calendar/gui/calendar-control.gnorba b/calendar/gui/calendar-control.gnorba new file mode 100644 index 0000000000..20032ef1c7 --- /dev/null +++ b/calendar/gui/calendar-control.gnorba @@ -0,0 +1,11 @@ +[control-factory:calendar] +type=exe +repo_id=IDL:GNOME/GenericFactory:1.0 +description=Factory for the sample Calendar control +location_info=evolution-calendar + +[control:calendar] +type=factory +repo_id=IDL:BonoboControl/calendar-control:1.0 IDL:GNOME/Control:1.0 +description=A sample Bonobo control which displays an calendar. +location_info=control-factory:calendar diff --git a/calendar/gui/corba-cal-factory.c b/calendar/gui/corba-cal-factory.c index 68f98f4229..591c486f62 100644 --- a/calendar/gui/corba-cal-factory.c +++ b/calendar/gui/corba-cal-factory.c @@ -10,8 +10,7 @@ #include <unistd.h> #include <sys/stat.h> #include "gnome-cal.h" -#include "main.h" -/*#include "alarm.h"*/ +#include "calendar-commands.h" #include "cal-util/timeutil.h" #include "libversit/vcc.h" #include <libgnorba/gnorba.h> diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index ef1e55520c..99a9817a33 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -36,7 +36,7 @@ #include "e-day-view-time-item.h" #include "e-day-view-top-item.h" #include "e-day-view-main-item.h" -#include "main.h" +#include "calendar-commands.h" #include "popup-menu.h" #include "eventedit.h" #include "../e-util/e-canvas.h" @@ -4443,7 +4443,7 @@ e_day_view_on_top_canvas_drag_data_received (GtkWidget *widget, { EDayViewEvent *event; EDayViewPosition pos; - gint day, row, scroll_x, scroll_y, start_day, end_day, num_days; + gint day, /* row, scroll_x, scroll_y,*/ start_day, end_day, num_days; gchar *event_uid; g_print ("In e_day_view_on_top_canvas_drag_data_received\n"); diff --git a/calendar/gui/eventedit.c b/calendar/gui/eventedit.c index 7f2c543f56..b4696a8dd6 100644 --- a/calendar/gui/eventedit.c +++ b/calendar/gui/eventedit.c @@ -8,9 +8,8 @@ #include <config.h> #include <gnome.h> #include <string.h> -/* #include "calendar.h" DELETE */ #include "eventedit.h" -#include "main.h" +#include "calendar-commands.h" #include "cal-util/timeutil.h" diff --git a/calendar/gui/evolution-calendar-control.c b/calendar/gui/evolution-calendar-control.c new file mode 100644 index 0000000000..ceee4335eb --- /dev/null +++ b/calendar/gui/evolution-calendar-control.c @@ -0,0 +1,85 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#include <config.h> +#include <gnome.h> +#include <libgnorba/gnorba.h> +#include <bonobo.h> +#include <bonobo/bonobo-control.h> + + +#include <cal-util/timeutil.h> +#include <gui/alarm.h> +#include <gui/eventedit.h> +#include <gui/gnome-cal.h> +#include <gui/calendar-commands.h> +/*#include <control/calendar-control.h>*/ + + +CORBA_Environment ev; +CORBA_ORB orb; + + + +static BonoboObject * +calendar_factory (BonoboGenericFactory *Factory, void *closure) +{ + BonoboControl *control; + GnomeCalendar *cal; + + /* Create the control. */ + //cal = gnome_calendar_new ("unnamed"); + cal = new_calendar ("title", NULL, NULL, NULL, 0); + gtk_widget_show (GTK_WIDGET (cal)); + control = bonobo_control_new (GTK_WIDGET (cal)); + + return BONOBO_OBJECT (control); +} + + +static void +calendar_factory_init (void) +{ + static BonoboGenericFactory *calendar_control_factory = NULL; + + if (calendar_control_factory != NULL) + return; + + calendar_control_factory = + bonobo_generic_factory_new ("control-factory:calendar", + calendar_factory, NULL); + + if (calendar_control_factory == NULL) { + g_error ("I could not register a Calendar factory."); + } +} + + +static void +init_bonobo (int argc, char **argv) +{ + gnome_CORBA_init_with_popt_table ( + "evolution-calendar", "0.0", + &argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev); + + orb = gnome_CORBA_ORB (); + + if (bonobo_init (orb, NULL, NULL) == FALSE) + g_error (_("Could not initialize Bonobo")); +} + +int +main (int argc, char **argv) +{ + alarm_init (); + init_calendar (); + + CORBA_exception_init (&ev); + + init_bonobo (argc, argv); + + calendar_factory_init (); + + bonobo_main (); + + return 0; +} diff --git a/calendar/gui/gncal-day-panel.c b/calendar/gui/gncal-day-panel.c index 2a886d6a3b..1b3b5360f8 100644 --- a/calendar/gui/gncal-day-panel.c +++ b/calendar/gui/gncal-day-panel.c @@ -9,7 +9,7 @@ #include <gnome.h> #include <gtk/gtkhseparator.h> #include "gncal-day-panel.h" -#include "main.h" +#include "calendar-commands.h" #include "cal-util/timeutil.h" diff --git a/calendar/gui/gncal-day-view.c b/calendar/gui/gncal-day-view.c index 82175ba85c..2daa13009e 100644 --- a/calendar/gui/gncal-day-view.c +++ b/calendar/gui/gncal-day-view.c @@ -10,7 +10,7 @@ #include "gncal-day-view.h" #include "cal-util/timeutil.h" #include "view-utils.h" -#include "main.h" +#include "calendar-commands.h" #include "eventedit.h" #include "popup-menu.h" #include "quick-view.h" diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c index 05c863058d..e387e98824 100644 --- a/calendar/gui/gncal-full-day.c +++ b/calendar/gui/gncal-full-day.c @@ -13,7 +13,7 @@ #include "gncal-full-day.h" #include "view-utils.h" #include "layout.h" -#include "main.h" +#include "calendar-commands.h" #include "popup-menu.h" /* Images */ diff --git a/calendar/gui/gncal-todo.c b/calendar/gui/gncal-todo.c index c1ed806612..8b249c3fb7 100644 --- a/calendar/gui/gncal-todo.c +++ b/calendar/gui/gncal-todo.c @@ -9,7 +9,7 @@ #include <string.h> #include <gnome.h> #include "gncal-todo.h" -#include "main.h" +#include "calendar-commands.h" #include "popup-menu.h" #include "eventedit.h" @@ -516,6 +516,7 @@ gncal_todo_new (GnomeCalendar *calendar) return GTK_WIDGET (todo); } +#if 0 static char * convert_time_t_to_char (time_t t) { @@ -527,7 +528,10 @@ convert_time_t_to_char (time_t t) return g_strdup (buf); } +#endif /* 0 */ + +#if 0 enum todo_styles { TODO_STYLE_OVERDUE, TODO_STYLE_DUE_TODAY, @@ -570,10 +574,10 @@ make_todo_style(GncalTodo *todo, todo_status style_type) style->base[GTK_STATE_NORMAL] = style_color; return style; } +#endif /* 0 */ - - +#if 0 static todo_status todo_item_due_status(time_t *todo_due_time) { struct tm due_tm_time; @@ -600,6 +604,7 @@ todo_status todo_item_due_status(time_t *todo_due_time) { return TODO_ITEM_DSTATUS_NOT_DUE_YET; } +#endif /* 0 */ enum todo_remaining_time_form { @@ -611,6 +616,7 @@ enum todo_remaining_time_form { }; typedef enum todo_remaining_time_form todo_remaining_time_form; +#if 0 static void insert_in_clist (GncalTodo *todo, iCalObject *ico) { @@ -791,6 +797,7 @@ insert_in_clist (GncalTodo *todo, iCalObject *ico) /* keep the list in order */ gtk_clist_sort (todo->clist); } +#endif /* 0 */ void gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags) diff --git a/calendar/gui/gncal-week-view.c b/calendar/gui/gncal-week-view.c index 553977e076..55e956d49e 100644 --- a/calendar/gui/gncal-week-view.c +++ b/calendar/gui/gncal-week-view.c @@ -11,7 +11,7 @@ #include <string.h> #include <gtk/gtk.h> #include "gncal-week-view.h" -#include "main.h" +#include "calendar-commands.h" #include "cal-util/timeutil.h" static void gncal_week_view_init (GncalWeekView *wview); diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 5abcb46b29..775762ca85 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * GnomeCalendar widget * Copyright (C) 1998 the Free Software Foundation @@ -12,6 +13,7 @@ #include <fcntl.h> #include <gtk/gtkmain.h> #include <gtk/gtknotebook.h> +#include <gtk/gtkframe.h> #include <libgnomeui/gnome-messagebox.h> #include <cal-util/timeutil.h> #include "alarm.h" @@ -20,7 +22,7 @@ #include "gncal-week-view.h" #include "month-view.h" #include "year-view.h" -#include "main.h" +#include "calendar-commands.h" @@ -40,8 +42,12 @@ gnome_calendar_get_type (void) (GtkArgSetFunc) NULL, (GtkArgGetFunc) NULL, }; + /* gnome_calendar_type = gtk_type_unique(gnome_app_get_type(), &gnome_calendar_info); parent_class = gtk_type_class (gnome_app_get_type()); + */ + gnome_calendar_type = gtk_type_unique (gtk_frame_get_type (), &gnome_calendar_info); + parent_class = gtk_type_class (gtk_frame_get_type ()); } return gnome_calendar_type; } @@ -74,7 +80,11 @@ setup_widgets (GnomeCalendar *gcal) gtk_widget_show_all (gcal->notebook); - gnome_app_set_contents (GNOME_APP (gcal), gcal->notebook); + /*gnome_app_set_contents (GNOME_APP (gcal), gcal->notebook);*/ + gtk_container_add (GTK_CONTAINER (gcal), gcal->notebook); + + + gtk_widget_show (GTK_WIDGET (gcal)); } static GtkWidget * @@ -214,24 +224,26 @@ gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name) gtk_notebook_set_page (GTK_NOTEBOOK (gcal->notebook), page); } + GtkWidget * gnome_calendar_new (char *title) { GtkWidget *retval; GnomeCalendar *gcal; - GnomeApp *app; + /*GnomeApp *app;*/ retval = gtk_type_new (gnome_calendar_get_type ()); - app = GNOME_APP (retval); + /*app = GNOME_APP (retval);*/ gcal = GNOME_CALENDAR (retval); + /* app->name = g_strdup ("calendar"); app->prefix = g_strconcat ("/", app->name, "/", NULL); + */ - gtk_window_set_title(GTK_WINDOW(retval), title); + /* gtk_window_set_title(GTK_WINDOW(retval), title); */ gcal->current_display = time_day_begin (time (NULL)); - /*gcal->cal = calendar_new (title, CALENDAR_INIT_ALARMS); DELETE */ gcal->client = cal_client_new (); setup_widgets (gcal); diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index dbe2493a2f..edc39b9676 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -42,7 +42,7 @@ typedef struct { } GnomeCalendarClass; guint gnome_calendar_get_type (void); -GtkWidget *gnome_calendar_new (char *title); +GtkWidget *gnome_calendar_new (char *title); int gnome_calendar_load (GnomeCalendar *gcal, char *file); void gnome_calendar_add_object (GnomeCalendar *gcal, diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c index 57ba67f821..0acc19a331 100644 --- a/calendar/gui/goto.c +++ b/calendar/gui/goto.c @@ -9,7 +9,7 @@ #include <gnome.h> #include "gnome-cal.h" #include "gnome-month-item.h" -#include "main.h" +#include "calendar-commands.h" #include "mark.h" #include "cal-util/timeutil.h" diff --git a/calendar/gui/main.c b/calendar/gui/main.c index 7200ffea04..ccafc2b286 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -20,694 +20,42 @@ #include <libgnorba/gnorba.h> #include <bonobo.h> #include <cal-util/timeutil.h> -/* #include "calendar.h" DELETE */ -#include "alarm.h" -#include "eventedit.h" -#include "gnome-cal.h" -#include "main.h" +#include <gui/alarm.h> +#include <gui/eventedit.h> +#include <gui/gnome-cal.h> +#include <gui/calendar-commands.h> - -#define COOKIE_USER_HOME_DIR ((char *) -1) - - -/* The username, used to set the `owner' field of the event */ -char *user_name; - -/* The full user name from the Gecos field */ -char *full_name; - -/* The user's default calendar file */ -char *user_calendar_file; - -/* a gnome-config string prefix that can be used to access the calendar config info */ -char *calendar_settings; - -/* Day begin, day end parameters */ -int day_begin, day_end; - -/* Whether weeks starts on Sunday or Monday */ -int week_starts_on_monday; - -/* If true, do not show our top level window */ -int startup_hidden = 0; - -/* If true, enable debug output for alarms */ -int debug_alarms = 0; - -/* The array of color properties -- keep in sync with the enumeration defined in main.h. The color - * values specified here are the defaults for the program. - */ -struct color_prop color_props[] = { - { 0x3e72, 0x35ec, 0x8ba2, N_("Outline:"), "/calendar/Colors/outline" }, - { 0xffff, 0xffff, 0xffff, N_("Headings:"), "/calendar/Colors/headings" }, - { 0xf26c, 0xecec, 0xbbe7, N_("Empty days:"), "/calendar/Colors/empty_bg" }, - { 0xfc1e, 0xf87f, 0x5f80, N_("Appointments:"), "/calendar/Colors/mark_bg" }, - { 0xd364, 0xc6b7, 0x7969, N_("Highlighted day:"), "/calendar/Colors/prelight_bg" }, - { 0x01f0, 0x01f0, 0x01f0, N_("Day numbers:"), "/calendar/Colors/day_fg" }, - { 0x0000, 0x0000, 0xffff, N_("Current day's number:"), "/calendar/Colors/current_fg" }, - { 0xbbbb, 0xbbbb, 0x0000, N_("To-Do item that is not yet due:"), "/calendar/Colors/todo_not_yet" }, - { 0xdddd, 0xbbbb, 0x0000, N_("To-Do item that is due today:"), "/calendar/Colors/todo_today" }, - { 0xbbbb, 0xdddd, 0x0000, N_("To-Do item that is overdue:"), "/calendar/Colors/todo_overdue" } +enum { + GEOMETRY_KEY = -1, + USERFILE_KEY = -2, + VIEW_KEY = -3, + HIDDEN_KEY = -4, + TODO_KEY = -5, + DEBUG_KEY = -6 }; -/* Number of active calendars */ -int active_calendars = 0; - -/* A list of all of the calendars started */ -GList *all_calendars = NULL; +/* Lists used to startup various GnomeCalendars */ +static GList *start_calendars; +static GList *start_geometries; +static GList *start_views; /* For dumping part of a calendar */ static time_t from_t, to_t; -/* File to load instead of the user default's file */ -static char *load_file; - /* If set, show events for the specified date and quit */ static int show_events; /* If set, show todo items quit */ static int show_todo; -/* If set, beep on display alarms */ -gboolean beep_on_display = 0; - -/* If true, timeout the beeper on audio alarms */ - -gboolean enable_aalarm_timeout = 0; -guint audio_alarm_timeout = 0; -const guint MAX_AALARM_TIMEOUT = 3600; -const guint MAX_SNOOZE_SECS = 3600; -gboolean enable_snooze = 0; -guint snooze_secs = 60; - -/*extern CalendarAlarm alarm_defaults[4];*/ -CalendarAlarm alarm_defaults[4] = { - { ALARM_MAIL, 0, 15, ALARM_MINUTES }, - { ALARM_PROGRAM, 0, 15, ALARM_MINUTES }, - { ALARM_DISPLAY, 0, 15, ALARM_MINUTES }, - { ALARM_AUDIO, 0, 15, ALARM_MINUTES } -}; - - -static void -init_username (void) -{ - user_name = g_strdup(g_get_user_name()); - full_name = g_strdup(g_get_real_name()); -} - -static int -range_check_hour (int hour) -{ - if (hour < 0) - hour = 0; - else if (hour >= 24) - hour = 23; - - return hour; -} - -static void -init_default_alarms (void) -{ - int i; - gboolean def; - - alarm_defaults [ALARM_DISPLAY].type = ALARM_DISPLAY; - alarm_defaults [ALARM_AUDIO].type = ALARM_AUDIO; - alarm_defaults [ALARM_PROGRAM].type = ALARM_PROGRAM; - alarm_defaults [ALARM_MAIL].type = ALARM_MAIL; - - for (i = 0; i < 4; i++) { - switch (alarm_defaults [i].type) { - case ALARM_DISPLAY: - gnome_config_push_prefix ("/calendar/alarms/def_disp_"); - break; - case ALARM_AUDIO: - gnome_config_push_prefix ("/calendar/alarms/def_audio_"); - break; - case ALARM_PROGRAM: - gnome_config_push_prefix ("/calendar/alarms/def_prog_"); - break; - case ALARM_MAIL: - gnome_config_push_prefix ("/calendar/alarms/def_mail_"); - break; - } - - alarm_defaults[i].enabled = gnome_config_get_int ("enabled=0"); - if (alarm_defaults[i].type != ALARM_MAIL) { - alarm_defaults[i].count = gnome_config_get_int ("count=15"); - alarm_defaults[i].units = gnome_config_get_int ("units=0"); - } else { - alarm_defaults[i].count = gnome_config_get_int ("count=1"); - alarm_defaults[i].count = gnome_config_get_int ("count=2"); - } - - alarm_defaults[i].data = gnome_config_get_string_with_default ("data=", - &def); - if (def) - alarm_defaults[i].data = NULL; - - gnome_config_pop_prefix (); - } -} - - -/* - * Initializes the calendar internal variables, loads defaults - */ -static void -init_calendar (void) -{ - int i; - char *cspec, *color; - char *str; - - init_username (); - user_calendar_file = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/user-cal.vcf"); - - gnome_config_push_prefix (calendar_settings); - - /* Read calendar settings */ - - day_begin = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day start=8")); - day_end = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day end=17")); - am_pm_flag = gnome_config_get_bool ("/calendar/Calendar/AM PM flag=0"); - week_starts_on_monday = gnome_config_get_bool ("/calendar/Calendar/Week starts on Monday=0"); - - if (day_end < day_begin){ - day_begin = 8; - day_end = 17; - } - - /* Read color settings */ - - for (i = 0; i < COLOR_PROP_LAST; i++) { - cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b); - str = g_strconcat (color_props[i].key, "=", cspec, NULL); - - color = gnome_config_get_string (str); - parse_color_spec (color, &color_props[i].r, &color_props[i].g, &color_props[i].b); - - g_free (str); - g_free (color); - } - - /* read todolist settings */ - - todo_show_time_remaining = gnome_config_get_bool("/calendar/Todo/show_time_remain"); - todo_show_due_date = gnome_config_get_bool("/calendar/Todo/show_due_date"); - - todo_item_dstatus_highlight_overdue = gnome_config_get_bool("/calendar/Todo/highlight_overdue"); - - todo_item_dstatus_highlight_due_today = gnome_config_get_bool("/calendar/Todo/highlight_due_today"); - - todo_item_dstatus_highlight_not_due_yet = gnome_config_get_bool("/calendar/Todo/highlight_not_due_yet"); - - todo_current_sort_column = gnome_config_get_int("/calendar/Todo/sort_column"); - - todo_current_sort_type = gnome_config_get_int("/calendar/Todo/sort_type"); - - todo_show_priority = gnome_config_get_bool("/calendar/Todo/show_priority"); - - /* read alarm settings */ - beep_on_display = gnome_config_get_bool ("/calendar/alarms/beep_on_display=FALSE"); - enable_aalarm_timeout = gnome_config_get_bool ("/calendar/alarms/enable_audio_timeout=FALSE"); - audio_alarm_timeout = gnome_config_get_int ("/calendar/alarms/audio_alarm_timeout=60"); - if (audio_alarm_timeout < 1) - audio_alarm_timeout = 1; - if (audio_alarm_timeout > MAX_AALARM_TIMEOUT) - audio_alarm_timeout = MAX_AALARM_TIMEOUT; - enable_snooze = gnome_config_get_bool ("/calendar/alarms/enable_snooze=FALSE"); - snooze_secs = gnome_config_get_int ("/calendar/alarms/snooze_secs=300"); - if (snooze_secs < 1) - snooze_secs = 1; - if (snooze_secs > MAX_SNOOZE_SECS) - snooze_secs = MAX_SNOOZE_SECS; - - init_default_alarms (); - - - /* Done */ - - gnome_config_pop_prefix (); -} - - - -/* static void save_calendar_cmd (GtkWidget *widget, void *data); DELETE */ - -static void -about_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkWidget *about; - const gchar *authors[] = { - "Miguel de Icaza (miguel@kernel.org)", - "Federico Mena (federico@gimp.org)", - "Arturo Espinosa (arturo@nuclecu.unam.mx)", - "Russell Steinthal (rms39@columbia.edu)", - NULL - }; - - about = gnome_about_new (_("Gnome Calendar"), VERSION, - "(C) 1998 the Free Software Foundation", - authors, - _("The GNOME personal calendar and schedule manager."), - NULL); - gtk_window_set_modal (GTK_WINDOW (about), TRUE); - gnome_dialog_set_close (GNOME_DIALOG (about), TRUE); - gtk_widget_show (about); -} - -static void -display_objedit (GtkWidget *widget, GnomeCalendar *gcal) -{ - GtkWidget *ee; - iCalObject *ico; - - /* Default to the day the user is looking at */ - ico = ical_new ("", user_name, ""); - ico->new = 1; - ico->dtstart = time_add_minutes (gcal->current_display, day_begin * 60); - ico->dtend = time_add_minutes (ico->dtstart, day_begin * 60 + 30 ); - - ee = event_editor_new (gcal, ico); - gtk_widget_show (ee); -} - -static void -display_objedit_today (GtkWidget *widget, GnomeCalendar *gcal) -{ - GtkWidget *ee; - - ee = event_editor_new (gcal, NULL); - gtk_widget_show (ee); -} - -static void -close_cmd (GtkWidget *widget, GnomeCalendar *gcal) -{ - all_calendars = g_list_remove (all_calendars, gcal); - - /* DELETE - FIXME -- what do i do here? - if (gcal->cal->modified){ - if (!gcal->cal->filename) - save_calendar_cmd (widget, gcal); - else - calendar_save (gcal->cal, gcal->cal->filename); - } - */ - - gtk_widget_destroy (GTK_WIDGET (gcal)); - active_calendars--; - - if (active_calendars == 0) - gtk_main_quit (); -} - -void -time_format_changed (void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_time_format_changed (GNOME_CALENDAR (l->data)); -} - -void -colors_changed (void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_colors_changed (GNOME_CALENDAR (l->data)); -} - -void -todo_properties_changed(void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_todo_properties_changed (GNOME_CALENDAR (l->data)); -} - - - -static void -quit_cmd (void) -{ - while (all_calendars){ - GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data); - - close_cmd (GTK_WIDGET (cal), cal); - } -} - -/* 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 (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_previous (gcal); - set_normal_cursor (gcal); -} - -static void -next_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_next (gcal); - set_normal_cursor (gcal); -} - -static void -today_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_goto_today (gcal); - set_normal_cursor (gcal); -} - -static void -goto_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - goto_dialog (gcal); -} - -static void -new_calendar_cmd (GtkWidget *widget, void *data) -{ - new_calendar (full_name, NULL, NULL, NULL, FALSE); -} - -static void -open_ok (GtkWidget *widget, GtkFileSelection *fs) -{ - GtkWidget *error_dialog; - int ret; - if(!g_file_exists (gtk_file_selection_get_filename (fs))) { - error_dialog = gnome_message_box_new ( - _("File not found"), - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, - NULL); - - gnome_dialog_set_parent (GNOME_DIALOG (error_dialog), GTK_WINDOW (fs)); - ret = gnome_dialog_run (GNOME_DIALOG (error_dialog)); - } else { - /* FIXME: find out who owns this calendar and use that name */ - new_calendar ("Somebody", gtk_file_selection_get_filename (fs), NULL, NULL, FALSE); - gtk_widget_destroy (GTK_WIDGET (fs)); - } -} - -static void -open_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkFileSelection *fs; - - fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Open calendar"))); - - gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", - (GtkSignalFunc) open_ok, - fs); - gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", - (GtkSignalFunc) gtk_widget_destroy, - GTK_OBJECT (fs)); - - gtk_widget_show (GTK_WIDGET (fs)); - gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me */ -} - -static void -save_ok (GtkWidget *widget, GtkFileSelection *fs) -{ - GnomeCalendar *gcal; - gchar *fname; - - gcal = GNOME_CALENDAR (gtk_object_get_user_data (GTK_OBJECT (fs))); - gtk_window_set_wmclass (GTK_WINDOW (gcal), "gnomecal", "gnomecal"); - - fname = g_strdup (gtk_file_selection_get_filename (fs)); - /* calendar_save (gcal->cal, fname); DELETE / FIXME*/ - g_free(fname); - gtk_main_quit (); -} - -static gint -close_save (GtkWidget *w) -{ - gtk_main_quit (); - return TRUE; -} - -static void -save_as_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkFileSelection *fs; - - fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Save calendar"))); - gtk_object_set_user_data (GTK_OBJECT (fs), data); - - gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", - (GtkSignalFunc) save_ok, - fs); - gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", - (GtkSignalFunc) close_save, - GTK_OBJECT (fs)); - gtk_signal_connect_object (GTK_OBJECT (fs), "delete_event", - GTK_SIGNAL_FUNC (close_save), - GTK_OBJECT (fs)); - gtk_widget_show (GTK_WIDGET (fs)); - gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me even more */ - gtk_main (); - gtk_widget_destroy (GTK_WIDGET (fs)); -} - -static void -properties_cmd (GtkWidget *widget, GtkWidget *gcal) -{ - properties (gcal); -} - -# if 0 /* DELETE */ -static void -save_calendar_cmd (GtkWidget *widget, void *data) -{ - GnomeCalendar *gcal = data; - - if (gcal->cal->filename){ - struct stat s; - - if (stat (gcal->cal->filename, &s) == -1){ - if (errno == ENOENT) - calendar_save (gcal->cal, gcal->cal->filename); - - return; - } - - if (s.st_mtime != gcal->cal->file_time){ - GtkWidget *box; - char *str; - int b; - - str = g_strdup_printf ( - _("File %s has changed since it was loaded\nContinue?"), - gcal->cal->filename); - box = gnome_message_box_new (str, GNOME_MESSAGE_BOX_INFO, - GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, - NULL); - g_free (str); - gnome_dialog_set_default (GNOME_DIALOG (box), 1); - b = gnome_dialog_run (GNOME_DIALOG (box)); - - if (b != 0) - return; - } - - calendar_save (gcal->cal, gcal->cal->filename); - } else - save_as_calendar_cmd (widget, data); -} -#endif /* 0 */ - -static GnomeUIInfo gnome_cal_file_menu [] = { - GNOMEUIINFO_MENU_NEW_ITEM(N_("_New calendar"), - N_("Create a new calendar"), - new_calendar_cmd, NULL), - - GNOMEUIINFO_MENU_OPEN_ITEM(open_calendar_cmd, NULL), - - /* GNOMEUIINFO_MENU_SAVE_ITEM(save_calendar_cmd, NULL), FIXME */ - - GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_calendar_cmd, NULL), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_MENU_CLOSE_ITEM(close_cmd, NULL), - - GNOMEUIINFO_MENU_EXIT_ITEM(quit_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_edit_menu [] = { - { GNOME_APP_UI_ITEM, N_("_New appointment..."), - N_("Create a new appointment"), display_objedit, NULL, NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, - { GNOME_APP_UI_ITEM, N_("New appointment for _today..."), - N_("Create a new appointment for today"), - display_objedit_today, NULL, NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_help_menu [] = { - GNOMEUIINFO_HELP ("gnomecal"), - - GNOMEUIINFO_MENU_ABOUT_ITEM(about_calendar_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_settings_menu [] = { - GNOMEUIINFO_MENU_PREFERENCES_ITEM(properties_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_menu [] = { - GNOMEUIINFO_MENU_FILE_TREE(gnome_cal_file_menu), - GNOMEUIINFO_MENU_EDIT_TREE(gnome_cal_edit_menu), - GNOMEUIINFO_MENU_SETTINGS_TREE(gnome_cal_settings_menu), - GNOMEUIINFO_MENU_HELP_TREE(gnome_cal_help_menu), - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_toolbar [] = { - GNOMEUIINFO_ITEM_STOCK (N_("New"), N_("Create a new appointment"), display_objedit, GNOME_STOCK_PIXMAP_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Prev"), N_("Go back in time"), previous_clicked, GNOME_STOCK_PIXMAP_BACK), - GNOMEUIINFO_ITEM_STOCK (N_("Today"), N_("Go to present time"), today_clicked, GNOME_STOCK_PIXMAP_HOME), - GNOMEUIINFO_ITEM_STOCK (N_("Next"), N_("Go forward in time"), next_clicked, GNOME_STOCK_PIXMAP_FORWARD), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Go to"), N_("Go to a specific date"), goto_clicked, GNOME_STOCK_PIXMAP_JUMP_TO), - - GNOMEUIINFO_END -}; - -static void -setup_menu (GtkWidget *gcal) -{ - gnome_app_create_menus_with_data (GNOME_APP (gcal), gnome_cal_menu, gcal); - gnome_app_create_toolbar_with_data (GNOME_APP (gcal), gnome_toolbar, gcal); - gnome_app_install_menu_hints(GNOME_APP(gcal), gnome_cal_menu); -} - -static void -setup_appbar (GtkWidget *gcal) -{ - GtkWidget *appbar; - - appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_USER); - gnome_app_set_statusbar (GNOME_APP (gcal), GTK_WIDGET (appbar)); -} - -static gint -calendar_close_event (GtkWidget *widget, GdkEvent *event, GnomeCalendar *gcal) -{ - close_cmd (widget, gcal); - return TRUE; -} - -GnomeCalendar * -new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, gboolean hidden) -{ - GtkWidget *toplevel; - char title[128]; - int xpos, ypos, width, height; - - /* i18n: This "%s%s" indicates possession. Languages where the order is - * the inverse should translate it to "%2$s%1$s". - */ - g_snprintf(title, 128, _("%s%s"), full_name, _("'s calendar")); - - toplevel = gnome_calendar_new (title); - - if (gnome_parse_geometry (geometry, &xpos, &ypos, &width, &height)){ - if (xpos != -1) - gtk_widget_set_uposition (toplevel, xpos, ypos); -#if 0 - if (width != -1) - gtk_widget_set_usize (toplevel, width, 600); -#endif - } -#if 0 - gtk_widget_set_usize (toplevel, width, 600); -#endif - - setup_appbar (toplevel); - setup_menu (toplevel); - - - if (page) - gnome_calendar_set_view (GNOME_CALENDAR (toplevel), page); - - if (calendar_file && g_file_exists (calendar_file)) - gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); - /* FIX ME - else - GNOME_CALENDAR (toplevel)->client->filename = g_strdup (calendar_file); - */ - - gtk_signal_connect (GTK_OBJECT (toplevel), "delete_event", - GTK_SIGNAL_FUNC(calendar_close_event), toplevel); - - active_calendars++; - all_calendars = g_list_prepend (all_calendars, toplevel); - - if (hidden){ - GnomeWinState state; - - /* Realize the toplevel window to prevent a segfault */ - gtk_widget_realize (toplevel); - state = gnome_win_hints_get_state (toplevel); +/* If true, do not show our top level window */ +int startup_hidden = 0; - state |= WIN_STATE_MINIMIZED; - gnome_win_hints_set_state (toplevel, state); - } - - gtk_widget_show (toplevel); +/* File to load instead of the user default's file */ +static char *load_file; - return GNOME_CALENDAR (toplevel); -} +extern time_t get_date (); static void process_dates (void) @@ -719,19 +67,6 @@ process_dates (void) to_t = time_add_day (from_t, 1); } -enum { - GEOMETRY_KEY = -1, - USERFILE_KEY = -2, - VIEW_KEY = -3, - HIDDEN_KEY = -4, - TODO_KEY = -5, - DEBUG_KEY = -6 -}; - -/* Lists used to startup various GnomeCalendars */ -static GList *start_calendars; -static GList *start_geometries; -static GList *start_views; static int same_day (struct tm *a, struct tm *b) @@ -800,6 +135,7 @@ dump_events (void) exit (0); } + static void dump_todo (void) { @@ -843,7 +179,58 @@ dump_todo (void) exit (0); } -extern time_t get_date (); +static void +session_die (void) +{ + quit_cmd (); +} + +/* + * Save the session callback + */ +static int +session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown, + GnomeInteractStyle interact_style, gint fast, gpointer client_data) +{ + char *sess_id; + char **argv = (char **) g_malloc (sizeof (char *) * ((active_calendars * 6) + 3)); + GList *l, *free_list = 0; + int i; + + sess_id = gnome_client_get_id (client); + + argv [0] = client_data; + for (i = 1, l = all_calendars; l; l = l->next){ + GnomeCalendar *gcal = GNOME_CALENDAR (l->data); + char *geometry; + + geometry = gnome_geometry_string (GTK_WIDGET (gcal)->window); + + /* FIX ME + if (strcmp (gcal->client->filename, user_calendar_file) == 0) + argv [i++] = "--userfile"; + else { + argv [i++] = "--file"; + argv [i++] = gcal->client->filename; + } + */ + + argv [i++] = "--geometry"; + argv [i++] = geometry; + argv [i++] = "--view"; + argv [i++] = gnome_calendar_get_current_view_name (gcal); + free_list = g_list_append (free_list, geometry); + } + argv [i] = NULL; + gnome_client_set_clone_command (client, i, argv); + gnome_client_set_restart_command (client, i, argv); + + for (l = free_list; l; l = l->next) + g_free (l->data); + g_list_free (free_list); + + return 1; +} static void parse_an_arg (poptContext ctx, @@ -903,6 +290,9 @@ parse_an_arg (poptContext ctx, } } + + + static const struct poptOption options [] = { { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL }, { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"), @@ -920,66 +310,14 @@ static const struct poptOption options [] = { { NULL, '\0', 0, NULL, 0} }; -static void -session_die (void) -{ - quit_cmd (); -} - -/* - * Save the session callback - */ -static int -session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer client_data) -{ - char *sess_id; - char **argv = (char **) g_malloc (sizeof (char *) * ((active_calendars * 6) + 3)); - GList *l, *free_list = 0; - int i; - - sess_id = gnome_client_get_id (client); - - argv [0] = client_data; - for (i = 1, l = all_calendars; l; l = l->next){ - GnomeCalendar *gcal = GNOME_CALENDAR (l->data); - char *geometry; - - geometry = gnome_geometry_string (GTK_WIDGET (gcal)->window); - - /* FIX ME - if (strcmp (gcal->client->filename, user_calendar_file) == 0) - argv [i++] = "--userfile"; - else { - argv [i++] = "--file"; - argv [i++] = gcal->client->filename; - } - */ - - argv [i++] = "--geometry"; - argv [i++] = geometry; - argv [i++] = "--view"; - argv [i++] = gnome_calendar_get_current_view_name (gcal); - free_list = g_list_append (free_list, geometry); - } - argv [i] = NULL; - gnome_client_set_clone_command (client, i, argv); - gnome_client_set_restart_command (client, i, argv); - - for (l = free_list; l; l = l->next) - g_free (l->data); - g_list_free (free_list); - - return 1; -} - - int main (int argc, char **argv) { GnomeClient *client; CORBA_Environment ev; + GtkWidget *cal_window; + GnomeCalendar *cal_frame; bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); @@ -1047,7 +385,10 @@ main (int argc, char **argv) else title = file; - new_calendar (title, file, geometry, page_name, startup_hidden); + cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + cal_frame = new_calendar (title, file, geometry, page_name, startup_hidden); + gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame)); + gtk_widget_show (cal_window); p = p->next; if (g) @@ -1060,104 +401,12 @@ main (int argc, char **argv) char *geometry = start_geometries ? start_geometries->data : NULL; char *page_name = start_views ? start_views->data : NULL; - new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden); + cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + cal_frame = new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden); + gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame)); + gtk_widget_show (cal_window); } bonobo_main (); return 0; } - - - -/* FIXME -- where should this go? */ -void -calendar_iterate (GnomeCalendar *cal, - time_t start, time_t end, - calendarfn cb, void *closure) -{ - GList *l, *uids = 0; - - uids = cal_client_get_uids (cal->client, CALOBJ_TYPE_EVENT); - - for (l = uids; l; l = l->next){ - CalObjFindStatus status; - iCalObject *ico; - char *uid = l->data; - char *obj_string = cal_client_get_object (cal->client, uid); - - /*iCalObject *obj = string_to_ical_object (obj_string);*/ - status = ical_object_find_in_string (uid, obj_string, &ico); - switch (status){ - case CAL_OBJ_FIND_SUCCESS: - ical_object_generate_events (ico, start, end, - cb, closure); - break; - case CAL_OBJ_FIND_SYNTAX_ERROR: - printf("calendar_iterate: syntax error uid=%s\n",uid); - break; - case CAL_OBJ_FIND_NOT_FOUND: - printf("calendar_iterate: obj not found uid=%s\n",uid); - break; - } - - g_free (l->data); - } - g_list_free (uids); -} - - - -static gint -calendar_object_compare_by_start (gconstpointer a, gconstpointer b) -{ - const CalendarObject *ca = a; - const CalendarObject *cb = b; - time_t diff; - - diff = ca->ev_start - cb->ev_start; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/* FIXME -- where should this (and calendar_object_compare_by_start) go? */ -/* returns a list of events in the form of CalendarObject* */ -GList *calendar_get_events_in_range (CalClient *calc, - time_t start, time_t end) -{ - GList *l, *uids, *res = 0; - uids = cal_client_get_events_in_range (calc, start, end); - - for (l = uids; l; l = l->next){ - CalObjFindStatus status; - CalObjInstance *coi = l->data; - char *uid = coi->uid; - char *obj_string = cal_client_get_object (calc, uid); - iCalObject *ico; - - - status = ical_object_find_in_string (uid, obj_string, &ico); - switch (status){ - case CAL_OBJ_FIND_SUCCESS: - { - CalendarObject *co = g_new (CalendarObject, 1); - co->ev_start = start; - co->ev_end = end; - co->ico = ico; - - res = g_list_insert_sorted (res, co, - calendar_object_compare_by_start); - break; - } - case CAL_OBJ_FIND_SYNTAX_ERROR: - printf ("calendar_get_events_in_range: " - "syntax error uid=%s\n", uid); - break; - case CAL_OBJ_FIND_NOT_FOUND: - printf ("calendar_get_events_in_range: " - "obj not found uid=%s\n", uid); - break; - } - - } - - return res; -} diff --git a/calendar/gui/mark.c b/calendar/gui/mark.c index b9c64bea52..a868123545 100644 --- a/calendar/gui/mark.c +++ b/calendar/gui/mark.c @@ -7,7 +7,7 @@ #include <config.h> #include "gnome-cal.h" -#include "main.h" +#include "calendar-commands.h" #include "mark.h" #include "cal-util/timeutil.h" diff --git a/calendar/gui/month-view.c b/calendar/gui/month-view.c index 518eecc1c8..449892fb17 100644 --- a/calendar/gui/month-view.c +++ b/calendar/gui/month-view.c @@ -11,7 +11,7 @@ #include "eventedit.h" #include "layout.h" #include "month-view.h" -#include "main.h" +#include "calendar-commands.h" #include "mark.h" #include "quick-view.h" #include "cal-util/timeutil.h" diff --git a/calendar/gui/prop.c b/calendar/gui/prop.c index 8e91f4d730..43b89df74a 100644 --- a/calendar/gui/prop.c +++ b/calendar/gui/prop.c @@ -14,7 +14,7 @@ #include <gnome.h> #include "gnome-cal.h" #include "gnome-month-item.h" -#include "main.h" +#include "calendar-commands.h" #include "mark.h" /* These specify the page numbers in the preferences notebook */ diff --git a/calendar/gui/quick-view.c b/calendar/gui/quick-view.c index 179f22b1e7..5b5dd10014 100644 --- a/calendar/gui/quick-view.c +++ b/calendar/gui/quick-view.c @@ -17,7 +17,7 @@ #include <libgnomeui/gnome-canvas-text.h> #include <libgnomeui/gnome-uidefs.h> #include "quick-view.h" -#include "main.h" +#include "calendar-commands.h" #define QUICK_VIEW_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" diff --git a/calendar/gui/view-utils.c b/calendar/gui/view-utils.c index 98e04f0e1c..2de95a4781 100644 --- a/calendar/gui/view-utils.c +++ b/calendar/gui/view-utils.c @@ -10,7 +10,7 @@ #include "view-utils.h" #include <libgnomeui/gnome-icon-text.h> #include "gnome-cal.h" -#include "main.h" +#include "calendar-commands.h" int am_pm_flag = 0; diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c index 18526c3b2e..d5c56c5633 100644 --- a/calendar/gui/year-view.c +++ b/calendar/gui/year-view.c @@ -11,7 +11,7 @@ #include <gnome.h> #include "eventedit.h" #include "year-view.h" -#include "main.h" +#include "calendar-commands.h" #include "mark.h" #include "quick-view.h" #include "cal-util/timeutil.h" |