diff options
Diffstat (limited to 'calendar')
66 files changed, 0 insertions, 20102 deletions
diff --git a/calendar/GnomeCal.idl b/calendar/GnomeCal.idl deleted file mode 100644 index 3838c7c0bc..0000000000 --- a/calendar/GnomeCal.idl +++ /dev/null @@ -1,104 +0,0 @@ -#include <Bonobo.idl> - -module GNOME { - - module Calendar { - - interface Repository { - - exception NotFound {}; - typedef sequence<string> String_Sequence; - - /* - * get_object: - * @uid: Unique Identifier for the object - * - * Returns a vCalendar object for the object - * that matches the UID @uid. - */ - string get_object (in string uid) - raises (NotFound); - - /* - * get_object_by_pilot_id: - * @pilot_id: the pilot id - * - * Returns the object that has the @pilot_id - * identifier. - */ - string get_object_by_pilot_id (in long pilot_id) - raises (NotFound); - - /* - * get_id_from_pilot_id: - * @pilot_id: the pilot id - * - * Returns the object id that matches the @pilot_id - * identifier. - */ - string get_id_from_pilot_id (in long pilot_id) - raises (NotFound); - - /* - * delete_object: - * @uid: Unique Identifier for the object - */ - void delete_object (in string uid) - raises (NotFound); - - /* - * update_object: - * @uid: uid of object to update - * @object: vcard object to update - */ - void update_object (in string uid, in string object); - - /* - * update_pilot_id: - * @uid: Unique identifier for the event we want to update - * @pilot_id: new ID assigned by the pilot - * @pilot_status: Status to flag the event with - */ - void update_pilot_id (in string uid, in long pilot_id, in long pilot_status) - raises (NotFound); - - /* - * get_object_id_list - * - * Returns a sequence of the UID's of the entries - */ - String_Sequence get_object_id_list(); - - /* - * get_updated_objects: - * - * Returns a vCalendar with all the objects that have been - * modified since the last Pilot Sync - */ - string get_updated_objects (); - - /* - * Returns the number of objects of a specific type in the calendar - * repository. - */ - - enum RecordStatus { - ANY, /* This means all records */ - NEW, - MODIFIED, - DELETED - }; - - long get_number_of_objects(in RecordStatus record_status); - - /* - * done: - * - * Informs the calendar that we are done using it, - * gets a chance to destroy windows and save information. - */ - void done (); - }; - }; -}; - diff --git a/calendar/alarm.c b/calendar/alarm.c deleted file mode 100644 index b720d7a4e5..0000000000 --- a/calendar/alarm.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Alarm handling for the GNOME Calendar. - * - * (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ -#include <config.h> -#include <time.h> -#include <gnome.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/time.h> -#include "pcs/calobj.h" -#include "alarm.h" - -/* The pipes used to notify about an alarm */ -int alarm_pipes [2]; - -/* The list of pending alarms */ -static GList *alarms; - -static void *head_alarm; - -typedef struct { - time_t activation_time; - AlarmFunction fn; - void *closure; - CalendarAlarm *alarm; -} AlarmRecord; - -enum DebugAction { - ALARM_ACTIVATED, - ALARM_ADDED, - ALARM_NOT_ADDED -}; - -void debug_alarm (AlarmRecord* ar, enum DebugAction action); -void calendar_notify (time_t time, CalendarAlarm *which, void *data); -extern int debug_alarms; - -/* - * SIGALRM handler. Notifies the callback about the alarm - */ -static void -alarm_activate () -{ - char c = 0; - - write (alarm_pipes [1], &c, 1); -} - -/* - * SIGUSR1 handler. Toggles debugging output - */ -static void -toggle_debugging () -{ - debug_alarms = !debug_alarms; -} - -static void -alarm_ready (void *closure, int fd, GdkInputCondition cond) -{ - AlarmRecord *ar = head_alarm; - time_t now = time (NULL); - char c; - - if (read (alarm_pipes [0], &c, 1) != 1) - return; - - if (ar == NULL){ - g_warning ("Empty events. This should not happen\n"); - return; - } - - while (head_alarm){ - if (debug_alarms) - debug_alarm (ar, ALARM_ACTIVATED); - (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); - alarms = g_list_remove (alarms, head_alarm); - - /* Schedule next alarm */ - if (alarms){ - AlarmRecord *next; - - head_alarm = alarms->data; - next = head_alarm; - - if (next->activation_time > now){ - struct itimerval itimer; - - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = next->activation_time - now; - itimer.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &itimer, NULL); - break; - } else { - g_free (ar); - ar = next; - } - } else - head_alarm = NULL; - } - g_free (ar); -} - -static int -alarm_compare_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->activation_time - arb->activation_time; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/** - * alarm_add: - * - * Tries to schedule @alarm. - * - * Returns TRUE if the alarm was scheduled. - */ -gboolean -alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) -{ - time_t now = time (NULL); - AlarmRecord *ar; - time_t alarm_time = alarm->trigger; - - ar = g_new0 (AlarmRecord, 1); - ar->activation_time = alarm_time; - ar->fn = fn; - ar->closure = closure; - ar->alarm = alarm; - - /* If it already expired, do not add it */ - if (alarm_time < now) { - if (debug_alarms) - debug_alarm (ar, ALARM_NOT_ADDED); - return FALSE; - } - - alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); - - /* If first alarm is not the previous first alarm, reschedule SIGALRM */ - if (head_alarm != alarms->data){ - struct itimerval itimer; - int v; - - /* Set the timer to disable upon activation */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = alarm_time - now; - itimer.it_value.tv_usec = 0; - v = setitimer (ITIMER_REAL, &itimer, NULL); - head_alarm = alarms->data; - } - if (debug_alarms) - debug_alarm (ar, ALARM_ADDED); - return TRUE; -} - -int -alarm_kill (void *closure_key) -{ - GList *p; - - for (p = alarms; p; p = p->next){ - AlarmRecord *ar = p->data; - - if (ar->closure == closure_key){ - alarms = g_list_remove (alarms, p->data); - if (alarms) - head_alarm = alarms->data; - else - head_alarm = NULL; - return 1; - } - } - return 0; -} - -void -alarm_init (void) -{ - struct sigaction sa; - struct sigaction debug_sa; - int flags = 0; - - pipe (alarm_pipes); - - /* set non blocking mode */ - fcntl (alarm_pipes [0], F_GETFL, &flags); - fcntl (alarm_pipes [0], F_SETFL, flags | O_NONBLOCK); - gdk_input_add (alarm_pipes [0], GDK_INPUT_READ, alarm_ready, 0); - - /* Setup the signal handler */ - sa.sa_handler = alarm_activate; - sigemptyset (&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction (SIGALRM, &sa, NULL); - - /* Setup a signal handler to toggle debugging */ - debug_sa.sa_handler = toggle_debugging; - sigemptyset (&debug_sa.sa_mask); - debug_sa.sa_flags = SA_RESTART; - sigaction (SIGUSR1, &debug_sa, NULL); -} - -void -debug_alarm (AlarmRecord* ar, enum DebugAction action) -{ - time_t now = time (NULL); - iCalObject *ico = ar->closure; - printf ("%s", ctime(&now)); - switch (action) { - case ALARM_ADDED: - printf ("Added alarm for %s", ctime(&ar->activation_time)); - break; - case ALARM_NOT_ADDED: - printf ("Alarm not added for %s", ctime(&ar->activation_time)); - break; - case ALARM_ACTIVATED: - printf ("Activated alarm\n"); - break; - } - - if (ar->fn!=&calendar_notify) return; - printf ("--- Summary: %s\n", ico->summary); - switch (ar->alarm->type) { - case ALARM_MAIL: - printf ("--- Type: Mail\n"); - break; - case ALARM_PROGRAM: - printf ("--- Type: Program\n"); - break; - case ALARM_DISPLAY: - printf ("--- Type: Display\n"); - break; - case ALARM_AUDIO: - printf ("--- Type: Audio\n"); - break; - } -} - - diff --git a/calendar/alarm.h b/calendar/alarm.h deleted file mode 100644 index 6bb5c1afa5..0000000000 --- a/calendar/alarm.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ALARM_H -#define ALARM_H - -#include <time.h> -#include "pcs/calobj.h" - -typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse); - -void alarm_init (void); -gboolean alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure); -int alarm_kill (void *closure); - -#endif diff --git a/calendar/bell.xpm b/calendar/bell.xpm deleted file mode 100644 index b1ab537a17..0000000000 --- a/calendar/bell.xpm +++ /dev/null @@ -1,83 +0,0 @@ -/* XPM */ -static char * bell_xpm[] = { -"16 16 64 1", -" c None", -". c #000000", -"+ c #E3BB43", -"@ c #E6C049", -"# c #EED275", -"$ c #F4E193", -"% c #F4DF8C", -"& c #EAC95C", -"* c #EFD57A", -"= c #FAEFBB", -"- c #FDF6D3", -"; c #FDF5C6", -"> c #F4E18F", -", c #E4BD43", -"' c #F6E295", -") c #FEF9D8", -"! c #FFFFFF", -"~ c #FFFADA", -"{ c #FCEEAA", -"] c #EBCA5A", -"^ c #E9C550", -"/ c #FAEA9C", -"( c #FEF7CB", -"_ c #FFF8CC", -": c #FDF1A8", -"< c #EED060", -"[ c #D39D12", -"} c #F2D55D", -"| c #FCEC91", -"1 c #FFF4AE", -"2 c #FFF5B6", -"3 c #FEEF97", -"4 c #F3D65E", -"5 c #D5A216", -"6 c #FAE05C", -"7 c #FFED7C", -"8 c #FFEF8C", -"9 c #FFF092", -"0 c #FDEB7A", -"a c #F4D750", -"b c #D8A717", -"c c #EAC01D", -"d c #F6D83E", -"e c #FAE255", -"f c #FAE362", -"g c #F9E161", -"h c #F6DE5B", -"i c #F1D145", -"j c #E6BE28", -"k c #D09B09", -"l c #B67E00", -"m c #CE9100", -"n c #D69F04", -"o c #E0B011", -"p c #E6BA1D", -"q c #E3B721", -"r c #E0B21E", -"s c #DCAB16", -"t c #D7A20D", -"u c #CC9303", -"v c #BE8400", -"w c #AC7500", -"x c #A06B00", -"y c #FFDD00", -" ", -" .. ", -" .+@. ", -" .#$%&. ", -" .*=-;>,. ", -" .')!~{]. ", -" .^/(~_:<[. ", -" .}|121345. ", -" .678980ab. ", -" .cdefghijkl. ", -" .mnopqrstuvwx. ", -" .............. ", -" .8y. ", -" .. ", -" ", -" "}; diff --git a/calendar/cal_struct.h b/calendar/cal_struct.h deleted file mode 100644 index 411036c7aa..0000000000 --- a/calendar/cal_struct.h +++ /dev/null @@ -1,27 +0,0 @@ -#define MAX_SZ 30 - -enum RepeatType { - Single, - Days, - Months, - WeekDays, - MonthDays -}; - - -struct actionitem { - char date[MAX_SZ]; - int time; /* Minutes past midnight */ -}; - -struct event { - struct actionitem start; - struct actionitem end; - - enum RepeatType repeat; - int repeatcount; - char description[MAX_SZ]; - char subtype[MAX_SZ]; - GList *properties; -}; - diff --git a/calendar/calendar-conduit-control-applet.c b/calendar/calendar-conduit-control-applet.c deleted file mode 100644 index 2d6fb60ef5..0000000000 --- a/calendar/calendar-conduit-control-applet.c +++ /dev/null @@ -1,360 +0,0 @@ -/* Control applet ("capplet") for the gnome-pilot calendar conduit, */ -/* based on */ -/* gpilotd control applet ('capplet') for use with the GNOME control center */ -/* $Id$ */ - -#include <pwd.h> -#include <sys/types.h> -#include <signal.h> -#include <gnome.h> -#include <ctype.h> - -#include <config.h> -#include <capplet-widget.h> - -#include <gpilotd/gpilotd-conduit-mgmt.h> -#include <gpilotd/gpilotd-app.h> -#include <gpilotd/gpilotd-app-dummy-callbacks.h> - -#include "calendar-conduit.h" - -/* tell changes callbacks to ignore changes or not */ -static gboolean ignore_changes=FALSE; - -/* capplet widget */ -static GtkWidget *capplet=NULL; - -/* host/device/pilot configuration windows */ -GtkWidget *cfgOptionsWindow=NULL; -GtkWidget *cfgStateWindow=NULL; -GtkWidget *dialogWindow=NULL; - -GnomePilotConduitMgmt *conduit; - -static void doTrySettings(GtkWidget *widget, gpointer); -static void doRevertSettings(GtkWidget *widget, gpointer); -static void doSaveSettings(GtkWidget *widget, gpointer); - -static void readStateCfg(GtkWidget *w,GCalConduitCfg *cfg); -static void setStateCfg(GtkWidget *w,GCalConduitCfg *cfg); -void about_cb (GtkWidget *, gpointer); -GCalConduitCfg *origState = NULL; -GCalConduitCfg *curState = NULL; - -gint pilotId; -CORBA_Environment ev; - -/* This array must be in the same order as enumerations - in GnomePilotConduitSyncType as they are used as index. - Custom type implies Disabled state. -*/ -static gchar* sync_options[] ={ N_("Disabled"), - N_("Synchronize"), - N_("Copy From Pilot"), - N_("Copy To Pilot"), - N_("Merge From Pilot"), - N_("Merge To Pilot")}; -#define SYNC_OPTIONS_COUNT 6 - -static void -setSettings(GCalConduitCfg* conduitCfg) -{ - if(conduitCfg->sync_type!=GnomePilotConduitSyncTypeCustom) - gpilotd_conduit_mgmt_enable_with_first_sync(conduit,pilotId, - conduitCfg->sync_type, - conduitCfg->sync_type, - TRUE); - else - gpilotd_conduit_mgmt_disable(conduit,pilotId); - - gcalconduit_save_configuration(conduitCfg); -} - -static void -doTrySettings(GtkWidget *widget, gpointer whatever) -{ - readStateCfg(cfgStateWindow,curState); - setSettings(curState); -} - -static void -doSaveSettings(GtkWidget *widget, gpointer whatever) -{ - doTrySettings(widget,whatever); -} - -static void -doCancelSettings(GtkWidget *widget, gpointer whatever) -{ - setSettings(origState); -} - -static void -doRevertSettings(GtkWidget *widget, gpointer whatever) -{ - gcalconduit_destroy_configuration(&curState); - curState = gcalconduit_dupe_configuration(origState); - setStateCfg(cfgStateWindow,curState); - setSettings(curState); -} - -static void -insert_dir_callback (GtkEditable *editable, const gchar *text, - gint len, gint *position, void *data) -{ - gint i; - gchar *curname; - - curname = gtk_entry_get_text(GTK_ENTRY(editable)); - if (*curname == '\0' && len > 0) { - if (isspace(text[0])) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text"); - return; - } - } else { - for (i=0; i<len; i++) { - if (isspace(text[i])) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), - "insert_text"); - return; - } - } - } -} -static void -insert_dir_callback2(GtkEditable *editable, const gchar *text, - gint length, gint *position, - void *data) -{ - if (!ignore_changes) - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -static void -clist_changed(GtkWidget *widget, gpointer data) -{ - if (!ignore_changes) - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -void about_cb (GtkWidget *widget, gpointer data) { - GtkWidget *about; - const gchar *authors[] = {_("Eskil Heyn Olsen <deity@eskil.dk>"),NULL}; - - about = gnome_about_new(_("GnomeCalendar Conduit"), VERSION, - _("(C) 1998"), - authors, - _("Configuration utility for the calendar conduit.\n"), - _("gnome-calendar-conduit.png")); - gtk_widget_show (about); - - return; -} - -static void toggled_cb(GtkWidget *widget, gpointer data) { - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -/* called by the sync_type GtkOptionMenu */ -static void -sync_action_selection(GtkMenuShell *widget, gpointer unused) -{ - if (!ignore_changes) { - capplet_widget_state_changed(CAPPLET_WIDGET (capplet), TRUE); - } -} - -/* called by the sync_type GtkOptionMenu */ -static void -activate_sync_type(GtkMenuItem *widget, gpointer data) -{ - curState->sync_type = GPOINTER_TO_INT(data); - if(!ignore_changes) - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -static GtkWidget -*createStateCfgWindow(void) -{ - GtkWidget *vbox, *table; - GtkWidget *label; - GtkWidget *optionMenu,*menuItem; - GtkMenu *menu; - gint i; - - vbox = gtk_vbox_new(FALSE, GNOME_PAD); - - table = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, GNOME_PAD); - - label = gtk_label_new(_("Synchronize Action")); - gtk_box_pack_start(GTK_BOX(table), label, FALSE, FALSE, GNOME_PAD); - - optionMenu=gtk_option_menu_new(); - gtk_object_set_data(GTK_OBJECT(vbox), "conduit_state", optionMenu); - menu = GTK_MENU(gtk_menu_new()); - - for (i=0; i<SYNC_OPTIONS_COUNT;i++) { - sync_options[i]=_(sync_options[i]); - menuItem = gtk_menu_item_new_with_label(sync_options[i]); - gtk_widget_show(menuItem); - gtk_signal_connect(GTK_OBJECT(menuItem),"activate", - GTK_SIGNAL_FUNC(activate_sync_type), - GINT_TO_POINTER(i)); - gtk_menu_append(menu,menuItem); - } - - gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu)); - gtk_signal_connect(GTK_OBJECT(menu), "selection-done", - GTK_SIGNAL_FUNC(sync_action_selection), - NULL); - - gtk_box_pack_start(GTK_BOX(table), optionMenu, FALSE, FALSE, 0); - - return vbox; -} - -static void -setStateCfg(GtkWidget *widget,GCalConduitCfg *cfg) -{ - GtkOptionMenu *optionMenu; - GtkMenu *menu; - - optionMenu = gtk_object_get_data(GTK_OBJECT(widget), "conduit_state"); - g_assert(optionMenu!=NULL); - menu = GTK_MENU(gtk_option_menu_get_menu(optionMenu)); - - - ignore_changes = TRUE; - /* Here were are relying on the items in menu being the same - order as in GnomePilotConduitSyncType. */ - gtk_option_menu_set_history(optionMenu,(int)cfg->sync_type); - ignore_changes = FALSE; -} - - -static void -readStateCfg(GtkWidget *w,GCalConduitCfg *cfg) -{ -/* - GtkWidget *button; - - button = gtk_object_get_data(GTK_OBJECT(w), "conduit_on_off"); - - g_assert(button!=NULL); - - activated = GTK_TOGGLE_BUTTON(button)->active; -*/ -} - -static void -pilot_capplet_setup(void) -{ - GtkWidget *frame, *table; - - capplet = capplet_widget_new(); - - table = gtk_table_new(1, 2, FALSE); - gtk_container_border_width(GTK_CONTAINER(table), GNOME_PAD); - gtk_container_add(GTK_CONTAINER(capplet), table); - - frame = gtk_frame_new(_("Conduit state")); - gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL); - gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1); - cfgStateWindow = createStateCfgWindow(); - gtk_container_add(GTK_CONTAINER(frame), cfgStateWindow); - - gtk_signal_connect(GTK_OBJECT(capplet), "try", - GTK_SIGNAL_FUNC(doTrySettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "revert", - GTK_SIGNAL_FUNC(doRevertSettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "ok", - GTK_SIGNAL_FUNC(doSaveSettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "cancel", - GTK_SIGNAL_FUNC(doCancelSettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "help", - GTK_SIGNAL_FUNC(about_cb), NULL); - - - setStateCfg(cfgStateWindow,curState); - - gtk_widget_show_all(capplet); -} - -static void -run_error_dialog(gchar *mesg,...) { - char tmp[80]; - va_list ap; - - va_start(ap,mesg); - vsnprintf(tmp,79,mesg,ap); - dialogWindow = gnome_message_box_new(mesg,GNOME_MESSAGE_BOX_ERROR,GNOME_STOCK_BUTTON_OK,NULL); - gnome_dialog_run_and_close(GNOME_DIALOG(dialogWindow)); - va_end(ap); -} - -gint get_pilot_id_from_gpilotd() { - gint *pilots; - int i; - - i=0; - gpilotd_get_pilot_ids(&pilots); - if(pilots) { - while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return -1; - } else { - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return -1; - } -} - -int -main( int argc, char *argv[] ) -{ - /* we're a capplet */ - gnome_capplet_init ("calendar conduit control applet", NULL, argc, argv, - NULL, - 0, NULL); - - /* get pilot name from gpilotd */ - /* 1. initialize the gpilotd connection */ - if (gpilotd_init(&argc,argv)!=0) { - run_error_dialog(_("Cannot initialze the GnomePilot Daemon")); - g_error(_("Cannot initialze the GnomePilot Daemon")); - return -1; - } - - /* 2 connect to gpilotd */ - if (gpilotd_connect()!=0) { - run_error_dialog(_("Cannot connect to the GnomePilot Daemon")); - g_error(_("Cannot connect to the GnomePilot Daemon")); - return -1; - } - - pilotId = get_pilot_id_from_gpilotd(); - if(!pilotId) return -1; - - /* put all code to set things up in here */ - conduit = gpilotd_conduit_mgmt_new("calendar_conduit",pilotId); - gcalconduit_load_configuration(&origState,pilotId); - gpilotd_conduit_mgmt_get_sync_type(conduit,pilotId,&origState->sync_type); - - curState = gcalconduit_dupe_configuration(origState); - - pilot_capplet_setup(); - - - /* done setting up, now run main loop */ - capplet_gtk_main(); - return 0; -} diff --git a/calendar/calendar-conduit-control-applet.desktop b/calendar/calendar-conduit-control-applet.desktop deleted file mode 100644 index 43c429ef97..0000000000 --- a/calendar/calendar-conduit-control-applet.desktop +++ /dev/null @@ -1,7 +0,0 @@ -[Desktop Entry] -Name=GnomeCalendar -Comment=Configure the GnomeCal conduit -Exec=calendar-conduit-control-applet --cap-id=1 -Terminal=0 -Type=Application -Icon=gnome-calendar-conduit.png diff --git a/calendar/calendar-conduit.c b/calendar/calendar-conduit.c deleted file mode 100644 index 9c758b3263..0000000000 --- a/calendar/calendar-conduit.c +++ /dev/null @@ -1,1416 +0,0 @@ -/* $Id$ */ - -#include <glib.h> -#include <gnome.h> - -#include <pi-source.h> -#include <pi-socket.h> -#include <pi-file.h> -#include <pi-dlp.h> -#include <pi-version.h> - -#include <sys/stat.h> -#include <sys/types.h> -#include <utime.h> -#include <unistd.h> -#include <pwd.h> -#include <signal.h> -#include <errno.h> - -#include <libgnorba/gnorba.h> -#include <libgnorba/gnome-factory.h> - -#include <gpilotd/gnome-pilot-conduit.h> -#include <gpilotd/gnome-pilot-conduit-standard-abs.h> - -#include "GnomeCal.h" -#include "calobj.h" -#include "calendar.h" -#include "timeutil.h" - -#include "calendar-conduit.h" - -int debug_alarms = 0; /* needed to satisfy some other part of gncal */ -/* Default values for alarms */ /* needed to satisfy some other part of gncal */ -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 } -}; - -GnomePilotConduit * conduit_get_gpilot_conduit (guint32); -void conduit_destroy_gpilot_conduit (GnomePilotConduit*); -void local_record_from_icalobject(GCalLocalRecord *local,iCalObject *obj); - -#define CONDUIT_VERSION "0.8.11" -#ifdef G_LOG_DOMAIN -#undef G_LOG_DOMAIN -#endif -#define G_LOG_DOMAIN "gcalconduit" - -#define DEBUG_CALCONDUIT -#undef DEBUG_CALCONDUIT - -#ifdef DEBUG_CALCONDUIT -#define show_exception(e) g_warning ("Exception: %s\n", CORBA_exception_id (e)) -#define LOG(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE, e) -#else -#define show_exception(e) -#define LOG(e...) -#endif - -#define WARN(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING, e) -#define INFO(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE, e) - -#define catch_ret_val(_env,ret) \ - if (_env._major != CORBA_NO_EXCEPTION) { \ - g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE,"%s:%d: Caught exception",__FILE__,__LINE__); \ - g_warning ("Exception: %s\n", CORBA_exception_id (&(_env))); \ - CORBA_exception_free(&(_env)); \ - return ret; \ - } - -static int -start_calendar_server (GnomePilotConduitStandardAbs *conduit, - GCalConduitContext *ctxt) -{ - - g_return_val_if_fail(conduit!=NULL,-2); - g_return_val_if_fail(ctxt!=NULL,-2); - - ctxt->calendar = goad_server_activate_with_id (NULL, - "IDL:GNOME:Calendar:Repository:1.0", - 0, NULL); - if (ctxt->calendar == CORBA_OBJECT_NIL) { - g_warning ("Can not communicate with GnomeCalendar server"); - return -1; - } - - if (ctxt->ev._major != CORBA_NO_EXCEPTION){ - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return -1; - } - return 0; -} - - -/* Just a stub to link with */ -void -calendar_notify (time_t time, CalendarAlarm *which, void *data) -{ -} - -static GSList * -get_calendar_objects(GnomePilotConduitStandardAbs *conduit, - gboolean *status, - GCalConduitContext *ctxt) -{ - GSList *result; - GNOME_Calendar_Repository_String_Sequence *uids; - - g_return_val_if_fail(conduit!=NULL,NULL); - g_return_val_if_fail(ctxt!=NULL,NULL); - - result = NULL; - uids = GNOME_Calendar_Repository_get_object_id_list (ctxt->calendar, &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - INFO ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - if(status!=NULL) (*status) = FALSE; - return NULL; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - if(status!=NULL) (*status) = FALSE; - return NULL; - } - - if(status!=NULL) (*status) = TRUE; - if(uids->_length>0) { - int i; - for(i=0;i<uids->_length;i++) { - result = g_slist_prepend(result,g_strdup(uids->_buffer[i])); - } - } else { - INFO ("No entries found"); - } - - CORBA_free(uids); - - return result; -} - -static void -local_record_from_ical_uid(GCalLocalRecord *local, - char *uid, - GCalConduitContext *ctxt) -{ - iCalObject *obj; - char *vcalendar_string; - - g_assert(local!=NULL); - - vcalendar_string = GNOME_Calendar_Repository_get_object(ctxt->calendar, uid, &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - INFO ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return; - } - g_return_if_fail(vcalendar_string!=NULL); - - obj = ical_object_new_from_string (vcalendar_string); - - local_record_from_icalobject(local,obj); - - return; -} - - -/* - * converts a iCalObject to a GCalLocalRecord - */ - -void -local_record_from_icalobject(GCalLocalRecord *local, - iCalObject *obj) -{ - g_return_if_fail(local!=NULL); - g_return_if_fail(obj!=NULL); - - local->ical = obj; - local->local.ID = local->ical->pilot_id; - -/* - LOG ("local->Id = %ld [%s], status = %d", - local->local.ID,obj->summary,local->ical->pilot_status); -*/ - switch(local->ical->pilot_status) { - case ICAL_PILOT_SYNC_NONE: - local->local.attr = GnomePilotRecordNothing; - break; - case ICAL_PILOT_SYNC_MOD: - local->local.attr = GnomePilotRecordModified; - break; - case ICAL_PILOT_SYNC_DEL: - local->local.attr = GnomePilotRecordDeleted; - break; - } - - /* Records without a pilot_id are new */ - if(local->local.ID == 0) - local->local.attr = GnomePilotRecordNew; - - local->local.secret = 0; - if(obj->class!=NULL) - if(strcmp(obj->class,"PRIVATE")==0) - local->local.secret = 1; - - local->local.archived = 0; -} - -/* - * Given a PilotRecord, find the matching record in - * the calendar repository. If no match, return NULL - */ -static GCalLocalRecord * -find_record_in_repository(GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - char *vcal_string; - GCalLocalRecord *loc; - - g_return_val_if_fail(conduit!=NULL,NULL); - g_return_val_if_fail(remote!=NULL,NULL); - - LOG ("requesting %ld", remote->ID); - - vcal_string = - GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - INFO ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return NULL; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return NULL; - } else { - LOG ("Found"); - loc = g_new0(GCalLocalRecord,1); - /* memory allocated in new_from_string is freed in free_match */ - local_record_from_icalobject(loc, - ical_object_new_from_string (vcal_string)); - /* g_free(vcal_string); FIXME: this coredumps, but won't it leak without ? */ - return loc; - } - - return NULL; -} - -/* - * updates an given iCalObject in the repository - */ -static void -update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, - iCalObject *obj, - GCalConduitContext *ctxt) -{ - char *str; - - g_return_if_fail(conduit!=NULL); - g_return_if_fail(obj!=NULL); - - str = calendar_string_from_object (obj); - - GNOME_Calendar_Repository_update_object (ctxt->calendar, obj->uid, str, &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - INFO ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return; - } - - free (str); -} - -static iCalObject * -ical_from_remote_record(GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote, - iCalObject *in_obj) -{ - iCalObject *obj; - int i; - struct Appointment a; - time_t now; - - now = time (NULL); - - g_return_val_if_fail(remote!=NULL,NULL); - memset(&a,0,sizeof(struct Appointment)); - unpack_Appointment(&a,remote->record,remote->length); - - if (in_obj == NULL) - obj = ical_new (a.note ? a.note : "", - g_get_user_name (), - a.description ? a.description : ""); - else - obj = in_obj; - - if (a.note) { - g_free(obj->comment); - obj->comment = g_strdup(a.note); - } - if (a.description) { - g_free(obj->summary); - obj->summary = g_strdup(a.description); - } - - obj->created = now; - obj->last_mod = now; - obj->priority = 0; - obj->transp = 0; - obj->related = NULL; - obj->pilot_id = remote->ID; - obj->pilot_status = ICAL_PILOT_SYNC_NONE; - - /* - * Begin and end - */ - - if (a.event) - { - /* turn day-long events into a full day's appointment - FIXME: get settings from gnomecal */ - a.begin.tm_sec = 0; - a.begin.tm_min = 0; - a.begin.tm_hour = 0; - - a.end.tm_sec = 0; - a.end.tm_min =59; - a.end.tm_hour = 23; - } - - obj->dtstart = mktime (&a.begin); - obj->dtend = mktime (&a.end); - - /* Special case: daily repetitions are converted to a multi-day event */ - /* This sucketh, a pilot event scheduled for dailyRepeat, freq 1, end on - whatever is cleary converted wrong - if (a.repeatType == repeatDaily){ - time_t newt = time_add_day (obj->dtend, a.repeatFrequency); - - obj->dtend = newt; - } - */ - - /* - * Alarm - */ - if (a.alarm){ - obj->aalarm.type = ALARM_AUDIO; - obj->aalarm.enabled = 1; - obj->aalarm.count = a.advance; - - switch (a.advanceUnits){ - case advMinutes: - obj->aalarm.units = ALARM_MINUTES; - break; - - case advHours: - obj->aalarm.units = ALARM_HOURS; - break; - - case advDays: - obj->aalarm.units = ALARM_DAYS; - break; - default: - } - } - - /* - * Recurrence - */ - if (a.repeatFrequency){ - obj->recur = g_new0 (Recurrence, 1); - - switch (a.repeatType){ - case repeatDaily: - /* - * In the Pilot daily repetitions are actually - * multi-day events - */ - obj->recur->type = RECUR_DAILY; - break; - - case repeatMonthlyByDate: - obj->recur->type = RECUR_MONTHLY_BY_DAY; - obj->recur->u.month_day = a.repeatFrequency; - break; - - case repeatWeekly: - { - int wd; - - obj->recur->type = RECUR_WEEKLY; - for (wd = 0; wd < 7; wd++) - if (a.repeatDays [wd]) - obj->recur->weekday |= 1 << wd; - - if (obj->recur->weekday == 0){ - struct tm tm = *localtime (&obj->dtstart); - - obj->recur->weekday = 1 << tm.tm_wday; - } - break; - } - - case repeatMonthlyByDay: - obj->recur->type = RECUR_MONTHLY_BY_POS; - obj->recur->u.month_pos = a.repeatFrequency; - obj->recur->weekday = (a.repeatDay / 7); - break; - - case repeatYearly: - obj->recur->type = RECUR_YEARLY_BY_DAY; - break; - - default: - g_assert_not_reached(); - } - - if (a.repeatForever) - obj->recur->duration = 0; - else - obj->recur->_enddate = mktime (&a.repeatEnd); - - obj->recur->interval = a.repeatFrequency; - } - - /* - * Load exception dates - */ - obj->exdate = NULL; - for (i = 0; i < a.exceptions; i++){ - time_t *t = g_new (time_t, 1); - - *t = mktime (&(a.exception [i])); - obj->exdate = g_list_prepend (obj->exdate, t); - } - - g_free (obj->class); - - if (remote->attr & dlpRecAttrSecret) - obj->class = g_strdup ("PRIVATE"); - else - obj->class = g_strdup ("PUBLIC"); - - - free_Appointment(&a); - - return obj; -} - -/* Code blatantly stolen from - * calendar-pilot-sync.c: - * - * (C) 1999 International GNOME Support - * - * Author: - * Miguel de Icaza (miguel@gnome-support.com) - * - */ -static gint -update_record (GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - char *vcal_string; - iCalObject *obj; - struct Appointment a; - - g_return_val_if_fail(remote!=NULL,-1); - - memset(&a,0,sizeof(struct Appointment)); - unpack_Appointment(&a,remote->record,remote->length); - - obj = ical_new (a.note ? a.note : "", - g_get_user_name (), - a.description ? a.description : ""); - - LOG ("requesting %ld [%s]", remote->ID, a.description); - vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - LOG ("Object did not exist, creating a new one"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - ical_from_remote_record(conduit,remote,obj); - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - ical_object_destroy (obj); - free_Appointment(&a); - return -1; - } else { - LOG ("Found"); - ical_object_destroy (obj); - obj = ical_object_new_from_string (vcal_string); - ical_from_remote_record(conduit,remote,obj); - CORBA_free(vcal_string); - } - - /* update record on server */ - - update_calendar_entry_in_repository(conduit,obj,ctxt); - - /* - * Shutdown - */ - ical_object_destroy (obj); - free_Appointment(&a); - - return 0; -} - -static void -check_for_slow_setting(GnomePilotConduit *c, - GCalConduitContext *ctxt) -{ - CORBA_long entry_number; - entry_number = - GNOME_Calendar_Repository_get_number_of_objects(ctxt->calendar, - GNOME_Calendar_Repository_ANY, - &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - } else { - LOG (_("Calendar holds %d entries"),entry_number); - /* If the local base is empty, do a slow sync */ - if ( entry_number <= 0) { - gnome_pilot_conduit_standard_set_slow(GNOME_PILOT_CONDUIT_STANDARD(c)); - } - } -} - -static gint -pre_sync(GnomePilotConduit *c, - GnomePilotDBInfo *dbi, - GCalConduitContext *ctxt) -{ - int l; - gint num_records; - unsigned char *buf; - - g_message ("GnomeCal Conduit v.%s",CONDUIT_VERSION); - - ctxt->calendar = CORBA_OBJECT_NIL; - - if (start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c),ctxt) != 0) { - WARN(_("Could not start gnomecal server")); - gnome_pilot_conduit_error(GNOME_PILOT_CONDUIT(c), - _("Could not start gnomecal server")); - return -1; - } - - /* Set the counters for the progress bar crap */ - num_records = GNOME_Calendar_Repository_get_number_of_objects (ctxt->calendar, GNOME_Calendar_Repository_ANY, &(ctxt->ev)); - catch_ret_val(ctxt->ev,-1); - gnome_pilot_conduit_standard_abs_set_num_local_records(GNOME_PILOT_CONDUIT_STANDARD_ABS(c), - num_records); - num_records = GNOME_Calendar_Repository_get_number_of_objects (ctxt->calendar, GNOME_Calendar_Repository_MODIFIED, &(ctxt->ev)); - catch_ret_val(ctxt->ev,-1); - gnome_pilot_conduit_standard_abs_set_num_updated_local_records(GNOME_PILOT_CONDUIT_STANDARD_ABS(c), - num_records); - num_records = GNOME_Calendar_Repository_get_number_of_objects (ctxt->calendar, GNOME_Calendar_Repository_NEW, &(ctxt->ev)); - catch_ret_val(ctxt->ev,-1); - gnome_pilot_conduit_standard_abs_set_num_new_local_records(GNOME_PILOT_CONDUIT_STANDARD_ABS(c), - num_records); - num_records = GNOME_Calendar_Repository_get_number_of_objects (ctxt->calendar, GNOME_Calendar_Repository_DELETED, &(ctxt->ev)); - catch_ret_val(ctxt->ev,-1); - gnome_pilot_conduit_standard_abs_set_num_deleted_local_records(GNOME_PILOT_CONDUIT_STANDARD_ABS(c), - num_records); - - gtk_object_set_data(GTK_OBJECT(c),"dbinfo",dbi); - - /* load_records(c); */ - - buf = (unsigned char*)g_malloc(0xffff); - if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff)) < 0) { - WARN(_("Could not read pilot's DateBook application block")); - WARN("dlp_ReadAppBlock(...) = %d",l); - gnome_pilot_conduit_error(GNOME_PILOT_CONDUIT(c), - _("Could not read pilot's DateBook application block")); - return -1; - } - unpack_AppointmentAppInfo(&(ctxt->ai),buf,l); - g_free(buf); - - check_for_slow_setting(c,ctxt); - - return 0; -} - -/** - * Find (if possible) the local record which matches - * the given PilotRecord. - * if successfull, return non-zero and set *local to - * a non-null value (the located local record), - * otherwise return 0 and set *local = NULL; - */ - -static gint -match_record (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord **local, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - LOG ("in match_record"); - - g_return_val_if_fail(local!=NULL,-1); - g_return_val_if_fail(remote!=NULL,-1); - - *local = find_record_in_repository(conduit,remote,ctxt); - - if (*local==NULL) return -1; - return 0; -} - -/** - * Free the data allocated by a previous match_record call. - * If successfull, return non-zero and ser *local=NULL, otherwise - * return 0. - */ -static gint -free_match (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord **local, - GCalConduitContext *ctxt) -{ - LOG ("entering free_match"); - - g_return_val_if_fail(local!=NULL,-1); - g_return_val_if_fail(*local!=NULL,-1); - - ical_object_destroy (GCAL_LOCALRECORD(*local)->ical); - g_free(*local); - - *local = NULL; - return 0; -} - -/* - Move to archive and set status to Nothing - */ -static gint -archive_local (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - GCalConduitContext *ctxt) -{ - LOG ("entering archive_local"); - - g_return_val_if_fail(local!=NULL,-1); - - return -1; -} - -/* - Store in archive and set status to Nothing - */ -static gint -archive_remote (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - LOG ("entering archive_remote"); - - g_return_val_if_fail(remote!=NULL,-1); - g_return_val_if_fail(local!=NULL,-1); - - return -1; -} - -/* - Store and set status to Nothing - */ -static gint -store_remote (GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - LOG ("entering store_remote"); - - g_return_val_if_fail(remote!=NULL,-1); - remote->attr = GnomePilotRecordNothing; - - return update_record(conduit,remote,ctxt); -} - -static gint -clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - GCalConduitContext *ctxt) -{ - LOG ("entering clear_status_archive_local"); - - g_return_val_if_fail(local!=NULL,-1); - - return -1; -} - -static gint -iterate (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord **local, - GCalConduitContext *ctxt) -{ - static GSList *events,*iterator; - static int hest; - - g_return_val_if_fail(local!=NULL,-1); - - if(*local==NULL) { - LOG ("beginning iteration"); - - events = get_calendar_objects(conduit,NULL,ctxt); - hest = 0; - - if(events!=NULL) { - LOG ("iterating over %d records",g_slist_length(events)); - *local = g_new0(GCalLocalRecord,1); - - local_record_from_ical_uid(*local,(gchar*)events->data,ctxt); - iterator = events; - } else { - LOG ("no events"); - (*local) = NULL; - } - } else { - /*LOG ("continuing iteration");*/ - hest++; - if(g_slist_next(iterator)==NULL) { - GSList *l; - - LOG ("ending"); - /** free stuff allocated for iteration */ - g_free((*local)); - - LOG ("iterated over %d records",hest); - for(l=events;l;l=l->next) - g_free(l->data); - - g_slist_free(events); - - /* ends iteration */ - (*local) = NULL; - return 0; - } else { - iterator = g_slist_next(iterator); - local_record_from_ical_uid(*local,(gchar*)(iterator->data),ctxt); - } - } - return 1; -} - -static gint -iterate_specific (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord **local, - gint flag, - gint archived, - GCalConduitContext *ctxt) -{ -#ifdef DEBUG_CALCONDUIT - { - gchar *tmp; - switch (flag) { - case GnomePilotRecordNothing: tmp = g_strdup("RecordNothing"); break; - case GnomePilotRecordModified: tmp = g_strdup("RecordModified"); break; - case GnomePilotRecordNew: tmp = g_strdup("RecordNew"); break; - default: tmp = g_strdup_printf("0x%x",flag); break; - } - LOG ("entering iterate_specific(flag = %s)",tmp); - g_free(tmp); - } -#endif - g_return_val_if_fail(local!=NULL,-1); - - /* iterate until a record meets the criteria */ - while(gnome_pilot_conduit_standard_abs_iterate(conduit,(LocalRecord**)local)) { - if((*local)==NULL) break; - if(archived && ((*local)->local.archived==archived)) break; - if(((*local)->local.attr == flag)) break; - } - - return (*local)==NULL?0:1; -} - -static gint -purge (GnomePilotConduitStandardAbs *conduit, - GCalConduitContext *ctxt) -{ - LOG ("entering purge"); - - - /* HEST, gem posterne her */ - - return -1; -} - -static gint -set_status (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - gint status, - GCalConduitContext *ctxt) -{ - LOG ("entering set_status(status=%d)",status); - - g_return_val_if_fail(local!=NULL,-1); - - g_assert(local->ical!=NULL); - - local->local.attr = status; - switch(status) { - case GnomePilotRecordPending: - case GnomePilotRecordNothing: - local->ical->pilot_status = ICAL_PILOT_SYNC_NONE; - break; - case GnomePilotRecordDeleted: - break; - case GnomePilotRecordNew: - case GnomePilotRecordModified: - local->ical->pilot_status = ICAL_PILOT_SYNC_MOD; - break; - } - - if ( status == GnomePilotRecordDeleted) { - GNOME_Calendar_Repository_delete_object(ctxt->calendar,local->ical->uid,&(ctxt->ev)); - } else { - GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, - local->ical->uid, - local->local.ID, - local->ical->pilot_status, - &(ctxt->ev)); - } - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - LOG ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return -1; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return -1; - } - return 0; -} - -static gint -set_archived (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - gint archived, - GCalConduitContext *ctxt) -{ - LOG ("entering set_archived"); - - g_return_val_if_fail(local!=NULL,-1); - g_assert(local->ical!=NULL); - - local->local.archived = archived; - update_calendar_entry_in_repository(conduit,local->ical,ctxt); - /* FIXME: This should move the entry into a speciel - calendar file, eg. Archive, or (by config option), simply - delete it */ - return 0; -} - -static gint -set_pilot_id (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - guint32 ID, - GCalConduitContext *ctxt) -{ - LOG ("entering set_pilot_id(id=%d)",ID); - - g_return_val_if_fail(local!=NULL,-1); - g_assert(local->ical!=NULL); - - local->local.ID = ID; - local->ical->pilot_id = ID; - GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, - local->ical->uid, - local->local.ID, - local->ical->pilot_status, - &(ctxt->ev)); - - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - LOG ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return -1; - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - return -1; - } - return 0; -} - -static gint -transmit (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - PilotRecord **remote, - GCalConduitContext *ctxt) -{ - PilotRecord *p; - int daycount; - - LOG ("entering transmit"); - - g_return_val_if_fail(local!=NULL,-1); - g_return_val_if_fail(remote!=NULL,-1); - g_assert(local->ical!=NULL); - - p = g_new0(PilotRecord,1); - - p->ID = local->local.ID; - p->attr = local->local.attr; - p->archived = local->local.archived; - p->secret = local->local.secret; - - local->a = g_new0(struct Appointment,1); - - local->a->event = 0; /* if no start time, leave at 1 */ - local->a->begin = *localtime(&local->ical->dtstart); - local->a->end = *localtime(&local->ical->dtend); - - /* set the Audio Alarm parameters */ - if(local->ical->aalarm.enabled) { - local->a->alarm = 1; - local->a->advance = local->ical->aalarm.count; - switch(local->ical->aalarm.units) { - case ALARM_MINUTES: - local->a->advanceUnits = advMinutes; - break; - case ALARM_HOURS: - local->a->advanceUnits = advHours; - break; - case ALARM_DAYS: - local->a->advanceUnits = advDays; - break; - } - } else { - local->a->alarm = 0; - local->a->advance = 0; - local->a->advanceUnits = advMinutes; - } - - /* set the recurrence parameters */ - if (local->ical->recur != NULL) { - switch (local->ical->recur->type) { - case RECUR_DAILY: - local->a->repeatType = repeatDaily; - break; - case RECUR_WEEKLY: - local->a->repeatType = repeatWeekly; - break; - case RECUR_MONTHLY_BY_POS: - local->a->repeatType = repeatMonthlyByDate; - break; - case RECUR_MONTHLY_BY_DAY: - local->a->repeatType = repeatMonthlyByDay; - break; - case RECUR_YEARLY_BY_MONTH: - local->a->repeatType = repeatYearly; - break; - case RECUR_YEARLY_BY_DAY: - local->a->repeatType = repeatYearly; - break; - } - if (local->ical->recur->duration == 0) { - local->a->repeatForever = 1; - } else { - local->a->repeatForever = 0; - local->a->repeatEnd = *localtime(&local->ical->recur->_enddate); - } - local->a->repeatFrequency = local->ical->recur->interval; - - - for ( daycount=0; daycount<7; daycount++ ) { - if (local->ical->recur->weekday & (1 << daycount)) - local->a->repeatDays[daycount] = 1; - } - } else { - local->a->repeatType = repeatNone; - local->a->repeatForever = 0; - local->a->repeatEnd = local->a->end; - local->a->repeatFrequency = 0; - local->a->repeatDay = dom1stSun; - local->a->repeatDays[0] = 0; - local->a->repeatDays[1] = 0; - local->a->repeatDays[2] = 0; - local->a->repeatDays[3] = 0; - local->a->repeatDays[4] = 0; - local->a->repeatDays[5] = 0; - local->a->repeatDays[6] = 0; - local->a->repeatWeekstart = 0; - local->a->exceptions = 0; - local->a->exception = NULL; - } - - /* STOP: don't replace these with g_strdup, since free_Appointment - uses free to deallocte */ - local->a->note = - local->ical->comment==NULL?NULL:strdup(local->ical->comment); - local->a->description = - local->ical->summary==NULL?NULL:strdup(local->ical->summary); - - /* Generate pilot record structure */ - p->record = g_new0(char,0xffff); - p->length = pack_Appointment(local->a,p->record,0xffff); - -#if 0 - /* This is some debug code that hexdumps the calendar entry... - You won't need this. */ - { - int x,y; - g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); - - g_message("local->a->note = %s",local->a->note); - g_message("local->a->description = %s",local->a->description); - g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); - for(x=0;x<p->length;x+=32) { - for(y=x;y<x+32;y++) - if(p->record[y]<33 || p->record[y]>128) - printf("%02X",p->record[y]); - else - printf(" %c",p->record[y]); - printf("\n"); - } - } -#endif - - *remote = p; - - return 0; -} - -static gint -free_transmit (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - PilotRecord **remote, - GCalConduitContext *ctxt) -{ - LOG ("entering free_transmit"); - - g_return_val_if_fail(local!=NULL,-1); - g_return_val_if_fail(remote!=NULL,-1); - - free_Appointment(local->a); - g_free((*remote)->record); - *remote = NULL; - return 0; -} - -static gint -compare (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - /* used by the quick compare */ - PilotRecord *remoteOfLocal; - int err; - int retval; - - /* used by the tedious compare */ - struct Appointment a; - int daycount; - - g_message ("entering compare"); - - g_return_val_if_fail (local!=NULL,-1); - g_return_val_if_fail (remote!=NULL,-1); -#if 1 - err = transmit(conduit,local,&remoteOfLocal,ctxt); - if (err != 0) return err; - - retval = 0; - if (remote->length == remoteOfLocal->length) { - if (memcmp(remoteOfLocal->record,remote->record,remote->length)!=0) { - g_message("compare failed on contents"); - retval = 1; - } - } else { - g_message("compare failed on length"); - retval = 1; - } - - free_transmit(conduit,local,&remoteOfLocal,ctxt); - return retval; - -#else - /** FIXME: All the { LOG("yadayada"); return 1; } bloat is for debug purposes. - Once this is known to work, compact to return 1;'s */ - - /* Check record attributes */ - if (local->local.ID != remote->ID) { - LOG("failed local->local.ID == remote->ID"); - return 1; - } - if (local->local.attr != remote->attr) { - LOG("failed local->local.attr == remote->attr"); - return 1; - } - if (local->local.archived != remote->archived) { - LOG("failed local->local.archived == remote->archived"); - return 1; - } - if (local->local.secret != remote->secret) { - LOG("failed local->local.secret == remote->secret"); - return 1; - } - - unpack_Appointment(&a,remote->record,remote->length); - - /* Check records begin/end time */ - if (a.event==0) { -/* FIXME - if (a.begin != *localtime(&local->ical->dtstart)) { - LOG("a.begin == *localtime(&local->ical->dtstart)"); - return 1; - } - if (a.end != *localtime(&local->ical->dtend)) { - LOG("a.end == *localtime(&local->ical->dtend)"); - return 1; - } -*/ - } else { - LOG("failed local->a.event != 0, unsupported by gnomecal"); - return 1; - } - - /* Check records alarm settings */ - if(a.alarm == 1) { - if (local->ical->aalarm.enabled == 1) { - if (a.advance != local->ical->aalarm.count) { - LOG("failed a.advance == local->ical->aalarm.count"); - return 1; - } - switch(local->ical->aalarm.units) { - case ALARM_MINUTES: - if (a.advanceUnits != advMinutes) { - LOG("failed local->ical->aalarm.units == a.advanceUnits"); - return 1; - } - break; - case ALARM_HOURS: - if (a.advanceUnits != advHours) { - LOG("failed local->ical->aalarm.units == a.advanceUnits"); - return 1; - } - break; - case ALARM_DAYS: - if (a.advanceUnits != advDays) { - LOG("failed local->ical->aalarm.units == a.advanceUnits"); - return 1; - } - break; - } - } else { - LOG("failed a.alarm == 1 && local->ical->aalarm.enabled == 1"); - return 1; - } - } else if (local->ical->aalarm.enabled == 1) { - LOG("failed a.alarm != 1 && local->ical->aalarm.enabled != 1"); - return 1; - } - - /* Check records recurrence settings */ - /* If this code is broken, a more or less safe although not efficient - approach is (other the fixing the bug), if either has recurrence, - return 1, thus failing the comparision */ - if (local->ical->recur != NULL) { - if (a.repeatType == repeatNone) { - LOG("failed: local->ical->recur != NULL && a.repeatType != repeatNone"); - return 1; - } - switch (local->ical->recur->type) { - case RECUR_DAILY: - if (a.repeatType != repeatDaily) { - LOG("failed a.repeatType == repeatDaily"); - return 1; } - break; - case RECUR_WEEKLY: - if (a.repeatType != repeatWeekly) { - LOG("failed a.repeatType == repeatWeekly"); - return 1; } - break; - case RECUR_MONTHLY_BY_POS: - if (a.repeatType != repeatMonthlyByDate) { - LOG("failed a.repeatType == repeatMonthlyByDate"); - return 1; } - break; - case RECUR_MONTHLY_BY_DAY: - if (a.repeatType != repeatMonthlyByDay) { - LOG("failed a.repeatType == repeatMonthlyByDay"); - return 1; } - break; - case RECUR_YEARLY_BY_MONTH: - if (a.repeatType != repeatYearly) { - LOG("failed a.repeatType == repeatYearly"); - return 1; } - break; - case RECUR_YEARLY_BY_DAY: - if (a.repeatType != repeatYearly) { - LOG("failed a.repeatType == repeatYearly"); - return 1; } - break; - } - if (local->ical->recur->duration == 0) { - if(a.repeatForever != 1) { - LOG("failed local->ical->recur->duration == 0 && a.repeatForever == 1"); - return 1; - } - } else { - if(a.repeatForever != 0) { - LOG("failed local->ical->recur->duration != 0 && ! a.repeatForever == 0"); - return 1; - } -/* FIXME - if(a.repeatEnd != *localtime(&local->ical->recur->_enddate)) { - LOG("failed a.repeatEnd == *localtime(&local->ical->recur->_enddate)"); - return 1; - } -*/ - } - if (a.repeatFrequency != local->ical->recur->interval) { - LOG("failed a.repeatFrequency == local->ical->recur->interval"); - return 1; - } - for (daycount = 0; daycount<7; daycount++) { - if(local->ical->recur->weekday & (1<<daycount)) { - if (a.repeatDays[daycount]!=1) { - LOG("failed local->ical->recur->weekday & (1<<daycount) && a.repeatDays[daycount]==1"); - return 1; - } - } else { - if (a.repeatDays[daycount]!=0) { - LOG("failed local->ical->recur->weekday &! (1<<daycount) && a.repeatDays[daycount]==0"); - return 1; - } - } - } - } else if (a.repeatType != repeatNone ) { - LOG("failed: local->ical->recur == NULL && a.repeatType == repeatNone"); - return 1; - } - - /* check the note and description */ - if(a.note!=NULL) { - if(local->ical->comment==NULL) { - LOG("failed a.note != NULL && local->ical->coment != NULL"); - return 1; - } - if(strcmp(local->ical->comment,a.note)!=0) { - LOG("failed strcmp(local->ical->comment,a.note)==0"); - return 1; - } - } if(local->ical->comment!=NULL) { - LOG("failed a.note == NULL && local->ical->coment == NULL"); - return 1; - } - if(a.description!=NULL) { - if(local->ical->summary==NULL) { - LOG("failed a.description != NULL && local->ical->coment != NULL"); - return 1; - } - if(strcmp(local->ical->summary,a.description)!=0) { - LOG("failed strcmp(local->ical->summary,a.description)==0"); - return 1; - } - } if(local->ical->summary!=NULL) { - LOG("failed a.description == NULL && local->ical->coment == NULL"); - return 1; - } -#endif - return 0; -} - -static gint -compare_backup (GnomePilotConduitStandardAbs *conduit, - GCalLocalRecord *local, - PilotRecord *remote, - GCalConduitContext *ctxt) -{ - LOG ("entering compare_backup"); - - g_return_val_if_fail(local!=NULL,-1); - g_return_val_if_fail(remote!=NULL,-1); - - return -1; -} - -static gint -delete_all (GnomePilotConduitStandardAbs *conduit, - GCalConduitContext *ctxt) -{ - GSList *events,*it; - gboolean error; - - events = get_calendar_objects(conduit,&error,ctxt); - - if (error == FALSE) return -1; - for (it=events;it;it = g_slist_next(it)) { - GNOME_Calendar_Repository_delete_object(ctxt->calendar, - it->data, - &(ctxt->ev)); - if (ctxt->ev._major == CORBA_USER_EXCEPTION){ - INFO ("Object did not exist"); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { - WARN (_("Error while communicating with calendar server")); - show_exception(&(ctxt->ev)); - CORBA_exception_free(&(ctxt->ev)); - /* destroy loop, free data */ - for (it=events;it;it = g_slist_next(it)) g_free(it->data); - g_slist_free(events); - return -1; - } - g_free(it->data); - } - g_slist_free(events); - return -1; -} - -GnomePilotConduit * -conduit_get_gpilot_conduit (guint32 pilotId) -{ - GtkObject *retval; - GCalConduitCfg *cfg; - GCalConduitContext *ctxt; - - - retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465); - g_assert (retval != NULL); - gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"GnomeCalConduit"); - - gcalconduit_load_configuration(&cfg,pilotId); - gtk_object_set_data(retval,"gcalconduit_cfg",cfg); - - gcalconduit_new_context(&ctxt,cfg); - gtk_object_set_data(GTK_OBJECT(retval),"gcalconduit_context",ctxt); - - gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, ctxt); - gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, ctxt); - gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, ctxt); - gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, ctxt); - gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, ctxt); - gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, ctxt); - gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, ctxt); - gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, ctxt); - gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, ctxt); - gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, ctxt); - gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, ctxt); - gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, ctxt); - gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, ctxt); - gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, ctxt); - gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, ctxt); - gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, ctxt); - gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, ctxt); - gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, ctxt); - - return GNOME_PILOT_CONDUIT (retval); -} - -void -conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) -{ - GCalConduitCfg *cc; - GCalConduitContext *ctxt; - - cc = GET_GCALCONFIG(conduit); - ctxt = GET_GCALCONTEXT(conduit); - - if(ctxt->calendar!=CORBA_OBJECT_NIL) - GNOME_Calendar_Repository_done (ctxt->calendar, &(ctxt->ev)); - - gcalconduit_destroy_configuration(&cc); - - gcalconduit_destroy_context(&ctxt); - - gtk_object_destroy (GTK_OBJECT (conduit)); - -} - - diff --git a/calendar/calendar-conduit.h b/calendar/calendar-conduit.h deleted file mode 100644 index 711609e96a..0000000000 --- a/calendar/calendar-conduit.h +++ /dev/null @@ -1,138 +0,0 @@ -/* $Id$ */ - -#ifndef __CALENDAR_CONDUIT_H__ -#define __CALENDAR_CONDUIT_H__ - -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <pi-datebook.h> -#include <gnome.h> - -#include "GnomeCal.h" -#include "calobj.h" -#include "calendar.h" -#include "timeutil.h" - -#include <gpilotd/gnome-pilot-conduit.h> -#include <gpilotd/gnome-pilot-conduit-standard-abs.h> - -/* This is the local record structure for the GnomeCal conduit. */ -typedef struct _GCalLocalRecord GCalLocalRecord; -struct _GCalLocalRecord { - /* The stuff from gnome-pilot-conduit-standard-abs.h - Must be first in the structure, or instances of this - structure cannot be used by gnome-pilot-conduit-standard-abs. - */ - LocalRecord local; - /* The corresponding iCal object, as found by GnomeCal. */ - iCalObject *ical; - /* pilot-link appointment structure, used for implementing Transmit. */ - struct Appointment *a; -}; -#define GCAL_LOCALRECORD(s) ((GCalLocalRecord*)(s)) - -/* This is the configuration of the GnomeCal conduit. */ -typedef struct _GCalConduitCfg GCalConduitCfg; -struct _GCalConduitCfg { - gboolean open_secret; - guint32 pilotId; - GnomePilotConduitSyncType sync_type; /* only used by capplet */ -}; -#define GET_GCALCONFIG(c) ((GCalConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_cfg")) - -/* This is the context for all the GnomeCal conduit methods. */ -typedef struct _GCalConduitContext GCalConduitContext; -struct _GCalConduitContext { - struct AppointmentAppInfo ai; - GCalConduitCfg *cfg; - GNOME_Calendar_Repository calendar; - CORBA_Environment ev; - CORBA_ORB orb; -}; -#define GET_GCALCONTEXT(c) ((GCalConduitContext*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_context")) - -/* Given a GCalConduitCfg*, allocates the structure and - loads the configuration data for the given pilot. */ -static void -gcalconduit_load_configuration(GCalConduitCfg **c, - guint32 pilotId) -{ - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/calendard-conduit/Pilot_%u/",pilotId); - - *c = g_new0(GCalConduitCfg,1); - g_assert(*c != NULL); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open_secret=FALSE"); - (*c)->sync_type = GnomePilotConduitSyncTypeCustom; /* set in capplets main */ - gnome_config_pop_prefix(); - - (*c)->pilotId = pilotId; -} - -/* Saves the configuration data. */ -static void -gcalconduit_save_configuration(GCalConduitCfg *c) -{ - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool("open_secret",c->open_secret); - gnome_config_pop_prefix(); - - gnome_config_sync(); - gnome_config_drop_all(); -} - -/* Creates a duplicate of the configuration data */ -static GCalConduitCfg* -gcalconduit_dupe_configuration(GCalConduitCfg *c) { - GCalConduitCfg *retval; - g_return_val_if_fail(c!=NULL,NULL); - retval = g_new0(GCalConduitCfg,1); - retval->sync_type = c->sync_type; - retval->open_secret = c->open_secret; - retval->pilotId = c->pilotId; - return retval; -} - -/* Destroys any data allocated by gcalconduit_load_configuration - and deallocates the given configuration. */ -static void -gcalconduit_destroy_configuration(GCalConduitCfg **c) -{ - g_return_if_fail(c!=NULL); - g_return_if_fail(*c!=NULL); - g_free(*c); - *c = NULL; -} - -/* Given a GCalConduitContxt*, allocates the structure */ -static void -gcalconduit_new_context(GCalConduitContext **ctxt, - GCalConduitCfg *c) -{ - *ctxt = g_new0(GCalConduitContext,1); - g_assert(ctxt!=NULL); - (*ctxt)->cfg = c; - CORBA_exception_init (&((*ctxt)->ev)); -} - -/* Destroys any data allocated by gcalconduit_new_context - and deallocates its data. */ -static void -gcalconduit_destroy_context(GCalConduitContext **ctxt) -{ - g_return_if_fail(ctxt!=NULL); - g_return_if_fail(*ctxt!=NULL); -/* - if ((*ctxt)->cfg!=NULL) - gcalconduit_destroy_configuration(&((*ctxt)->cfg)); -*/ - g_free(*ctxt); - *ctxt = NULL; -} -#endif __CALENDAR_CONDUIT_H__ diff --git a/calendar/calendar-pilot-sync.c b/calendar/calendar-pilot-sync.c deleted file mode 100644 index 5039bb37b7..0000000000 --- a/calendar/calendar-pilot-sync.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - * calendar-pilot-sync.c: - * - * (C) 1999 International GNOME Support - * - * Author: - * Miguel de Icaza (miguel@gnome-support.com) - * - */ -#include <config.h> -#include <gnome.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libgnorba/gnome-factory.h> -#include <libgnorba/gnorba.h> -#include "calobj.h" -#include "calendar.h" -#include "timeutil.h" -#include "GnomeCal.h" -#include "pi-source.h" -#include "pi-socket.h" -#include "pi-datebook.h" -#include "pi-dlp.h" - -/* the CORBA ORB */ -CORBA_ORB orb; - -/* The default port to communicate with */ -char *pilot_port = "/dev/pilot"; - -CORBA_Environment ev; - -/* Our pi-socket address where we connect to */ -struct pi_sockaddr addr; - -/* The Pilot DB identifier for DateBook */ -int db; - -/* If true, enable debug output for alarms */ -int debug_alarms = 0; - -/* True if you want to dump the flags bits from the records */ -int debug_attrs = 0; - -/* Default values for alarms */ -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 } -}; - -int only_desktop_to_pilot = 0; - -int only_pilot_to_desktop = 0; - -const struct poptOption calendar_sync_options [] = { - { "pilot", 0, POPT_ARG_STRING, &pilot_port, 0, - N_("Specifies the port on which the Pilot is"), N_("PORT") }, - { "debug-attrs", 0, POPT_ARG_NONE, &debug_attrs, 0, - N_("If you want to debug the attributes on records"), NULL }, - { "only-desktop", 0, POPT_ARG_NONE, &only_desktop_to_pilot, 0, - N_("Only syncs from desktop to pilot"), NULL }, - { "only-pilot", 0, POPT_ARG_INT, &only_pilot_to_desktop, 0, - N_("Only syncs from pilot to desktop"), NULL }, - { NULL, '\0', 0, NULL, 0 } -}; - -static void -conduit_free_Appointment (struct Appointment *a) -{ - /* free_Appointment is brain-dead with respect to guarding against - double-frees */ - - free_Appointment (a); - a->exception = 0; - a->description = 0; - a->note = 0; -} - -static int -setup_connection (void) -{ - int socket; - int ret, news; - - if (!(socket = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) - g_error (_("Can not create Pilot socket\n")); - - addr.pi_family = PI_AF_SLP; - strncpy ((void *) &addr.pi_device, pilot_port, sizeof (addr.pi_device)); - - ret = pi_bind (socket, (struct sockaddr *)&addr, sizeof (addr)); - if (ret == -1) - g_error (_("Can not bind to device %s\n"), pilot_port); - - if (pi_listen (socket, 1) == -1) - g_error (_("Failed to get a connection from the Pilot device")); - - if ((news = pi_accept (socket, 0, 0)) == -1) - g_error (_("pi_accept failed")); - - return news; -} - -static GNOME_Calendar_Repository -locate_calendar_server (void) -{ - GNOME_Calendar_Repository repo; - - repo = goad_server_activate_with_id ( - NULL, "IDL:GNOME:Calendar:Repository:1.0", - 0, NULL); - - if (repo == CORBA_OBJECT_NIL) - g_error ("Can not communicate with GnomeCalendar server"); - - if (ev._major != CORBA_NO_EXCEPTION){ - printf ("Exception: %s\n", CORBA_exception_id (&ev)); - abort (); - } - - return repo; -} - -static void -delete_record (GNOME_Calendar_Repository repo, int id) -{ - char *uid; - - uid = GNOME_Calendar_Repository_get_id_from_pilot_id (repo, id, &ev); - - /* The record was already deleted */ - if (ev._major != CORBA_NO_EXCEPTION) - return; - - GNOME_Calendar_Repository_delete_object (repo, uid, &ev); - CORBA_free (uid); -} - -static void -update_record (GNOME_Calendar_Repository repo, int id, struct Appointment *a, int attr) -{ - char *vcal_string; - iCalObject *obj; - int i; - char *str; - - obj = ical_new (a->note ? a->note : "", - g_get_user_name (), - a->description ? a->description : ""); - - printf ("requesting %d [%s]\n", id, a->description); - vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (repo, id, &ev); - - if (ev._major == CORBA_USER_EXCEPTION){ - time_t now = time (NULL); - - obj->created = now; - obj->last_mod = now; - obj->priority = 0; - obj->transp = 0; - obj->related = NULL; - obj->pilot_id = id; - obj->pilot_status = ICAL_PILOT_SYNC_NONE; - printf (_("\tObject did not exist, creating a new one\n")); - } else { - printf ("\tFound\n"); - obj = ical_object_new_from_string (vcal_string); - } - - if (obj->pilot_status == ICAL_PILOT_SYNC_MOD){ - printf (_("\tObject has been modified on desktop and on the pilot, desktop takes precedence\n")); - ical_object_destroy (obj); - return; - } - - /* - * Begin and end - */ - - if (a->event) - { - /* turn day-long events into a full day's appointment */ - a->begin.tm_sec = 0; - a->begin.tm_min = 0; - a->begin.tm_hour = 6; - - a->end.tm_sec = 0; - a->end.tm_min = 0; - a->end.tm_hour = 10; - } - - obj->dtstart = mktime (&a->begin); - obj->dtend = mktime (&a->end); - - /* Special case: daily repetitions are converted to a multi-day event */ - if (a->repeatType == repeatDaily){ - time_t newt = time_add_day (obj->dtend, a->repeatFrequency); - - obj->dtend = newt; - } - - /* - * Alarm - */ - if (a->alarm){ - obj->aalarm.type = ALARM_AUDIO; - obj->aalarm.enabled = 1; - obj->aalarm.count = a->advance; - - switch (a->advanceUnits){ - case advMinutes: - obj->aalarm.units = ALARM_MINUTES; - break; - - case advHours: - obj->aalarm.units = ALARM_HOURS; - break; - - case advDays: - obj->aalarm.units = ALARM_DAYS; - break; - default: - } - } - - /* - * Recurrence - */ - if (a->repeatFrequency && a->repeatType != repeatDaily){ - obj->recur = g_new0 (Recurrence, 1); - - switch (a->repeatType){ - case repeatDaily: - /* - * In the Pilot daily repetitions are actually - * multi-day events - */ - g_warning ("Should not have got here"); - break; - - case repeatMonthlyByDate: - obj->recur->type = RECUR_MONTHLY_BY_DAY; - obj->recur->u.month_day = a->repeatFrequency; - break; - - case repeatWeekly: - { - int wd; - - obj->recur->type = RECUR_WEEKLY; - for (wd = 0; wd < 7; wd++) - if (a->repeatDays [wd]) - obj->recur->weekday |= 1 << wd; - - if (obj->recur->weekday == 0){ - struct tm tm = *localtime (&obj->dtstart); - - obj->recur->weekday = 1 << tm.tm_wday; - } - break; - } - - case repeatMonthlyByDay: - obj->recur->type = RECUR_MONTHLY_BY_POS; - obj->recur->u.month_pos = a->repeatFrequency; - obj->recur->weekday = (a->repeatDay / 7); - break; - - case repeatYearly: - obj->recur->type = RECUR_YEARLY_BY_DAY; - break; - - default: - g_warning ("Unhandled repeate case"); - } - - if (a->repeatForever) - obj->recur->duration = 0; - else - obj->recur->_enddate = mktime (&a->repeatEnd); - } - - /* - * Load exception dates - */ - obj->exdate = NULL; - for (i = 0; i < a->exceptions; i++){ - time_t *t = g_new (time_t, 1); - - *t = mktime (&(a->exception [i])); - obj->exdate = g_list_prepend (obj->exdate, t); - } - - g_free (obj->class); - - if (attr & dlpRecAttrSecret) - obj->class = g_strdup ("PRIVATE"); - else - obj->class = g_strdup ("PUBLIC"); - - /* - * Now, convert the in memory iCalObject to a full vCalendar we can send - */ - str = calendar_string_from_object (obj); - - GNOME_Calendar_Repository_update_object (repo, obj->uid, str, &ev); - - free (str); - - /* - * Shutdown - */ - ical_object_destroy (obj); -} - -/* - * Sets the alarm for Appointment based on @alarm - */ -static int -try_alarm (CalendarAlarm *alarm, struct Appointment *a) -{ - if (!alarm->enabled) - return 0; - - a->advance = alarm->count; - switch (alarm->type){ - case ALARM_DAYS: - a->advanceUnits = advDays; - break; - - case ALARM_HOURS: - a->advanceUnits = advHours; - break; - - case ALARM_MINUTES: - a->advanceUnits = advMinutes; - break; - - default: - return 0; - } - a->alarm = 1; - return 1; -} - -static void -sync_object_to_pilot (GNOME_Calendar_Repository repo, iCalObject *obj, int pilot_fd) -{ - char buffer [65536]; - struct Appointment *a; - int wd, i, idx, attr, cat, rec_len; - recordid_t new_id; - GList *l; - - a = g_new0 (struct Appointment, 1); - - attr = 0; - cat = 0; - idx = 0; - - if (obj->pilot_id){ - rec_len = dlp_ReadRecordById (pilot_fd, db, obj->pilot_id, - buffer, &idx, &rec_len, &attr, &cat); - - if (rec_len > 0) - unpack_Appointment (a, buffer, rec_len); - } else { - attr = 0; - cat = 0; - } - - /* a contains the appointment either cleared or with the data from the Pilot */ - a->begin = *localtime (&obj->dtstart); - a->end = *localtime (&obj->dtend); - - /* FIXME: add support for timeless */ - a->event = 0; - - /* Alarms, try the various ones. Probably we should only do Audio? - * Otherwise going gnomecal->pilot->gnomecal would get the gnomecal - * with *possibly* an alarm that was not originally defined. - */ - a->alarm = 0; - if (try_alarm (&obj->aalarm, a) == 0) - if (try_alarm (&obj->dalarm, a) == 0) - try_alarm (&obj->palarm, a); - - /* Recurrence */ - if (obj->recur){ - a->repeatFrequency = obj->recur->interval; - - switch (obj->recur->type){ - case RECUR_MONTHLY_BY_POS: - a->repeatType = repeatMonthlyByDay; - a->repeatFrequency = obj->recur->u.month_pos; - a->repeatDay = obj->recur->weekday * 7; - break; - - case RECUR_MONTHLY_BY_DAY: - a->repeatType = repeatMonthlyByDate; - a->repeatFrequency = obj->recur->u.month_day; - break; - - case RECUR_YEARLY_BY_DAY: - a->repeatType = repeatYearly; - break; - - case RECUR_WEEKLY: - for (wd = 0; wd < 7; wd++) - if (obj->recur->weekday & (1 << wd)) - a->repeatDays [wd] = 1; - a->repeatType = repeatWeekly; - break; - case RECUR_DAILY: - - default: - a->repeatType = repeatNone; - break; - } - if (obj->recur->enddate == 0){ - a->repeatForever = 1; - } else - a->repeatEnd = *localtime (&obj->recur->enddate); - } - - /* - * Pilot uses a repeat-daily for a multi-day event, adjust for that case - */ - if ((a->end.tm_mday != a->begin.tm_mday) || - (a->end.tm_mon != a->begin.tm_mon) || - (a->end.tm_year != a->begin.tm_year)){ - a->event = 1; - a->begin.tm_sec = 0; - a->begin.tm_min = 0; - a->begin.tm_hour = 0; - - a->end.tm_sec = 0; - a->end.tm_min = 0; - a->end.tm_hour = 0; - - a->repeatEnd = a->end; - a->repeatForever = 0; - a->repeatFrequency = 1; - a->repeatType = repeatDaily; - } - - /* - * Exceptions - */ - a->exceptions = g_list_length (obj->exdate); - a->exception = (struct tm *) malloc (sizeof (struct tm) * a->exceptions); - for (i = 0, l = obj->exdate; l; l = l->next, i++){ - time_t *exdate = l->data; - - a->exception [i] = *localtime (exdate); - } - - /* - * Description and note. - * - * We use strdup to be correct. free_Appointment assumes we used - * malloc. - */ - if (obj->comment) - a->note = strdup (obj->comment); - else - a->note = 0; - - if (obj->summary) - a->description = strdup (obj->summary); - else - a->description = strdup (_("No description")); - - if (strcmp (obj->class, "PUBLIC") != 0) - attr |= dlpRecAttrSecret; - else - attr &= ~dlpRecAttrSecret; - - /* - * Send the appointment to the pilot - */ - rec_len = pack_Appointment (a, buffer, sizeof (buffer)); - attr &= ~dlpRecAttrDirty; - - dlp_WriteRecord ( - pilot_fd, db, 0, - obj->pilot_id, 0, buffer, rec_len, &new_id); - - GNOME_Calendar_Repository_update_pilot_id (repo, obj->uid, new_id, ICAL_PILOT_SYNC_NONE, &ev); - - conduit_free_Appointment (a); - g_free (a); -} - -static void -sync_cal_to_pilot (GNOME_Calendar_Repository repo, Calendar *cal, int pilot_fd) -{ - GList *l; - int c = g_list_length (cal->events); - int i; - - printf ("\n"); - for (i = 0, l = cal->events; l; l = l->next, i++){ - iCalObject *obj = l->data; - - printf ("Syncing desktop to pilot: %d/%d\r", i + 1, c); - fflush (stdout); - if (obj->pilot_status != ICAL_PILOT_SYNC_MOD){ - g_warning ("Strange, we were supposed to get only a dirty object"); - continue; - } - - sync_object_to_pilot (repo, obj, pilot_fd); - } - printf ("\n"); -} - -static void -dump_attr (int flags) -{ - if (flags & dlpRecAttrDeleted) - fprintf(stderr, " Deleted"); - if (flags & dlpRecAttrDirty) - fprintf(stderr, " Dirty"); - if (flags & dlpRecAttrBusy) - fprintf(stderr, " Busy"); - if (flags & dlpRecAttrSecret) - fprintf(stderr, " Secret"); - if (flags & dlpRecAttrArchived) - fprintf(stderr, " Archive"); - fprintf (stderr, "\n"); -} - -static void -sync_pilot (GNOME_Calendar_Repository repo, int pilot_fd) -{ - struct PilotUser user_info; - int record; - unsigned char buffer [65536]; - Calendar *dirty_cal; - char *vcalendar_string; - char *error; - - printf (_("Syncing with the pilot...")); - dlp_ReadUserInfo (pilot_fd, &user_info); - - /* This informs the user of the progress on the Pilot */ - dlp_OpenConduit (pilot_fd); - - if (dlp_OpenDB (pilot_fd, 0, 0x80 | 0x40, "DatebookDB", &db) < 0){ - g_warning (_("Could not open DatebookDB on the Pilot")); - dlp_AddSyncLogEntry (pilot_fd, _("Unable to open DatebookDB")); - pi_close (pilot_fd); - exit (1); - } - - /* - * 1. Pull all the records from the Pilot, and make any updates - * required on the desktop side - */ - if (!only_desktop_to_pilot){ - for (record = 0;; record++){ - struct Appointment a; - int rec_len, attr, size; - recordid_t id; - - rec_len = dlp_ReadRecordByIndex ( - pilot_fd, db, - record, buffer, &id, &size, &attr, 0); - - if (rec_len < 0) - break; - - printf ("processing record %d\n", record); - unpack_Appointment (&a, buffer, rec_len); - - if (debug_attrs) - dump_attr (attr); - - /* If the object was deleted, remove it from the database */ - if (attr & dlpRecAttrDeleted){ - printf ("Deleting id %ld\n", id); - delete_record (repo, id); - conduit_free_Appointment (&a); - dlp_DeleteRecord (pilot_fd, db, 0, id); - continue; - } - - if (attr & dlpRecAttrArchived) - continue; - - printf ("updating record\n"); - update_record (repo, id, &a, attr); - - conduit_free_Appointment (&a); - } - } - - /* - * 2. Pull all the records from the Calendar, and move any new items - * to the pilot - */ - if (!only_pilot_to_desktop){ - vcalendar_string = GNOME_Calendar_Repository_get_updated_objects (repo, &ev); - dirty_cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); - error = calendar_load_from_memory (dirty_cal, vcalendar_string); - if (!error) - sync_cal_to_pilot (repo, dirty_cal, pilot_fd); - calendar_destroy (dirty_cal); - } - - - dlp_CloseDB (pilot_fd, db); - dlp_AddSyncLogEntry (pilot_fd, _("Synced DateBook from Pilot to GnomeCal")); - pi_close (pilot_fd); -} - -int -main (int argc, char *argv []) -{ - int link; - GNOME_Calendar_Repository repository; - - CORBA_exception_init (&ev); - orb = gnome_CORBA_init_with_popt_table ( - "calendar-pilot-sync", VERSION, &argc, argv, - calendar_sync_options, 0, NULL, 0, &ev); - - printf ("Please, press HotSync button on the palm..."); - fflush (stdout); - link = setup_connection (); - printf ("Connected\n"); - - printf ("Launching GnomeCal..."); - fflush (stdout); - repository = locate_calendar_server (); - printf ("Done\n"); - - printf ("<Syncing>\n"); - sync_pilot (repository, link); - printf ("</Syncing>\n"); - - GNOME_Calendar_Repository_done (repository, &ev); - - CORBA_exception_free (&ev); - - return 0; -} - -/* Just a stub to link with */ -void -calendar_notify (time_t time, CalendarAlarm *which, void *data) -{ -} - diff --git a/calendar/calendar.c b/calendar/calendar.c deleted file mode 100644 index 776f38452d..0000000000 --- a/calendar/calendar.c +++ /dev/null @@ -1,663 +0,0 @@ -/* - * Calendar manager object - * - * This keeps track of a given calendar. Eventually this will abtract everything - * related to getting calendars/saving calendars locally or to a remote Calendar Service - * - * Copyright (C) 1998, 1999 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (quartic@gimp.org) - * - */ - -#include <gnome.h> -#include <stdio.h> -#include <config.h> -#include <unistd.h> -#include <sys/stat.h> -#include "calendar.h" -#include "alarm.h" -#include "timeutil.h" -#include "libversit/vcc.h" -#include "icalendar.h" - -#ifdef HAVE_TZNAME -extern char *tzname[2]; -#endif - -/* Our day range */ -time_t calendar_day_begin, calendar_day_end; - -static void calendar_init_alarms (Calendar *cal); -static void calendar_set_day (void); - -Calendar * -calendar_new (char *title,CalendarNewOptions options) -{ - Calendar *cal; - - cal = g_new0 (Calendar, 1); - - cal->title = g_strdup (title); - if (options & CALENDAR_USE_ICAL) - cal->format = CAL_ICAL; - else - cal->format = CAL_VCAL; - - if ((calendar_day_begin == 0) || (calendar_day_end == 0)) - calendar_set_day (); - - cal->event_hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (options & CALENDAR_INIT_ALARMS) { - calendar_init_alarms (cal); - } - - return cal; -} - -static void -try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end) -{ - alarm->trigger = start-alarm->offset; - - if (alarm->trigger < calendar_day_begin) - return; - if (alarm->trigger > calendar_day_end) - return; - alarm_add (alarm, &calendar_notify, ico); -} - -static int -add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure) -{ - if (obj->aalarm.enabled) - try_add (obj, &obj->aalarm, start, end); - if (obj->dalarm.enabled) - try_add (obj, &obj->dalarm, start, end); - if (obj->palarm.enabled) - try_add (obj,&obj->palarm, start, end); - if (obj->malarm.enabled) - try_add (obj, &obj->malarm, start, end); - - return TRUE; -} - -#define max(a,b) ((a > b) ? a : b) - -static void -ical_object_try_alarms (iCalObject *obj) -{ - int ao, po, od, mo; - int max_o; - - ao = alarm_compute_offset (&obj->aalarm); - po = alarm_compute_offset (&obj->palarm); - od = alarm_compute_offset (&obj->dalarm); - mo = alarm_compute_offset (&obj->malarm); - - max_o = max (ao, max (po, max (od, mo))); - if (max_o == -1) - return; - - ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj); -} - -void -calendar_add_object (Calendar *cal, iCalObject *obj) -{ - g_return_if_fail (cal != NULL); - g_return_if_fail (obj != NULL); - g_return_if_fail (obj->uid != NULL); - - obj->new = 0; - switch (obj->type){ - case ICAL_EVENT: - g_hash_table_insert (cal->event_hash, obj->uid, obj); - cal->events = g_list_prepend (cal->events, obj); - ical_object_try_alarms (obj); -#ifdef DEBUGGING_MAIL_ALARM - obj->malarm.trigger = 0; - calendar_notify (0, obj); -#endif - break; - - case ICAL_TODO: - cal->todo = g_list_prepend (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_prepend (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - if (!obj->uid){ - char buffer [80]; - - snprintf (buffer, sizeof (buffer), "GnomeCalendar-%ld\n", time (NULL)); - obj->uid = g_strdup (buffer); - } - - cal->modified = TRUE; - - obj->last_mod = time (NULL); -} - -void -calendar_remove_object (Calendar *cal, iCalObject *obj) -{ - switch (obj->type){ - case ICAL_EVENT: - cal->events = g_list_remove (cal->events, obj); - g_hash_table_remove (cal->event_hash, obj->uid); - break; - - case ICAL_TODO: - cal->todo = g_list_remove (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_remove (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - cal->modified = TRUE; -} - -void -calendar_destroy (Calendar *cal) -{ - g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->events); - - g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->todo); - - g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->journal); - - g_hash_table_destroy (cal->event_hash); - - if (cal->title) - g_free (cal->title); - if (cal->filename) - g_free (cal->filename); - - g_free (cal); -} - -void -calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure) -{ - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - ical_object_generate_events (object, start, end, cb, closure); - } -} - -void -calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure) -{ - calendar_iterate_on_objects (cal->events, start, end, cb, closure); -} - -GList * -calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func) -{ - GList *new_events = 0; - - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - if ((start <= object->dtstart) && (object->dtend <= end)){ - if (sort_func) - new_events = g_list_insert_sorted (new_events, object, sort_func); - else - new_events = g_list_prepend (new_events, object); - } - } - - /* Put the list in increasing order if no sort function was specified */ - - if (!sort_func) - new_events = g_list_reverse (new_events); - - return new_events; -} - -GList * -calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->todo, start, end, sort_func); -} - -GList * -calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->journal, start, end, sort_func); -} - -gint -calendar_compare_by_dtstart (gpointer a, gpointer b) -{ - iCalObject *obj1, *obj2; - time_t diff; - - obj1 = a; - obj2 = b; - - diff = obj1->dtstart - obj2->dtstart; - - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -#define str_val(obj) (char *) vObjectUStringZValue (obj) - -/* Loads our calendar contents from a vObject */ -void -calendar_load_from_vobject (Calendar *cal, VObject *vcal) -{ - VObjectIterator i; - - initPropIterator (&i, vcal); - - while (moreIteration (&i)){ - VObject *this = nextVObject (&i); - iCalObject *ical; - const char *object_name = vObjectName (this); - - if (strcmp (object_name, VCDCreatedProp) == 0){ - cal->created = time_from_isodate (str_val (this)); - continue; - } - - if (strcmp (object_name, VCLocationProp) == 0) - continue; /* FIXME: imlement */ - - if (strcmp (object_name, VCProdIdProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCVersionProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCTimeZoneProp) == 0) - continue; /* FIXME: implement */ - - ical = ical_object_create_from_vobject (this, object_name); - - if (ical) - calendar_add_object (cal, ical); - } -} - -static void -calendar_set_day (void) -{ - time_t calendar_today; - - calendar_today = time (NULL); - calendar_day_begin = time_day_begin (calendar_today); - calendar_day_end = time_day_end (calendar_today); -} - -/* Loads a calendar from a file */ -char * -calendar_load (Calendar *cal, char *fname) -{ - VObject *vcal; - struct stat s; - - if (cal->filename){ - g_warning ("Calendar load called again\n"); - return "Internal error"; - } - - cal->filename = g_strdup (fname); - - stat (fname, &s); - cal->file_time = s.st_mtime; - - calendar_set_day (); - - switch (cal->format) { - case CAL_VCAL: - vcal = Parse_MIME_FromFileName (fname); - if (!vcal) - return "Could not load the calendar"; - calendar_load_from_vobject (cal, vcal); - cleanVObject (vcal); - cleanStrTbl (); - break; - /* - case CAL_ICAL: - icalendar_calendar_load (cal, fname); - break; - */ - default: - return "Unknown calendar format"; - } - - return NULL; -} - -/* - * calendar_load_from_memory: - * @cal: calendar on which we load the information - * @buffer: A buffer that contains a vCalendar file - * - * Loads the information from the vCalendar information in @buffer - * into the Calendar - */ -char * -calendar_load_from_memory (Calendar *cal, const char *buffer) -{ - VObject *vcal; - - g_return_val_if_fail (buffer != NULL, NULL); - - cal->filename = g_strdup ("memory-based-calendar"); - vcal = Parse_MIME (buffer, strlen (buffer)); - if (!vcal) - return "Could not load the calendar"; - - cal->file_time = time (NULL); - calendar_load_from_vobject (cal, vcal); - cleanVObject (vcal); - cleanStrTbl (); - - return NULL; -} - -static VObject * -vcalendar_create_from_calendar (Calendar *cal) -{ - VObject *vcal; - GList *l; - time_t now = time (NULL); - struct tm tm; - - /* WE call localtime for the side effect of setting tzname */ - tm = *localtime (&now); - - vcal = newVObject (VCCalProp); - addPropValue (vcal, VCProdIdProp, "-//GNOME//NONSGML GnomeCalendar//EN"); -#if defined(HAVE_TM_ZONE) - addPropValue (vcal, VCTimeZoneProp, tm.tm_zone); -#elif defined(HAVE_TZNAME) - addPropValue (vcal, VCTimeZoneProp, tzname[0]); -#endif - addPropValue (vcal, VCVersionProp, VERSION); - cal->temp = vcal; - - /* Events */ - - for (l = cal->events; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - /* To-do entries */ - - for (l = cal->todo; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - return vcal; -} - -void -calendar_save (Calendar *cal, char *fname) -{ - VObject *vcal; - FILE *fp; - GtkWidget *dlg; - struct stat s; - int status; - - if (fname == NULL) - fname = cal->filename; - - vcal = vcalendar_create_from_calendar (cal); - if (g_file_exists (fname)){ - char *backup_name = g_strconcat (fname, "~", NULL); - - if (g_file_exists (backup_name)){ - unlink (backup_name); - } - rename (fname, backup_name); - g_free (backup_name); - } - - fp = fopen(fname,"w"); - if (fp) { - writeVObject(fp, vcal); - fclose(fp); - if (strcmp(cal->filename, fname)) { - if (cal->filename) - g_free (cal->filename); - cal->filename = g_strdup (fname); - } - status = stat (fname, &s); - cal->file_time = s.st_mtime; - } else { - dlg = gnome_message_box_new(_("Failed to save calendar!"), - GNOME_MESSAGE_BOX_ERROR, "Ok", NULL); - gtk_widget_show(dlg); - } - - cleanVObject (vcal); - cleanStrTbl (); -} - -char * -calendar_get_as_vcal_string (Calendar *cal) -{ - VObject *vcal; - char *result; - - g_return_val_if_fail (cal != NULL, NULL); - - vcal = vcalendar_create_from_calendar (cal); - result = writeMemVObject (NULL, 0, vcal); - - cleanVObject (vcal); - cleanStrTbl (); - - return result; -} - -static gint -calendar_object_compare_by_start (gconstpointer a, gconstpointer b) -{ - const CalendarObject *ca = a; - const CalendarObject *cb = b; - time_t diff; - - diff = ca->ev_start - cb->ev_start; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -static int -assemble_event_list (iCalObject *obj, time_t start, time_t end, void *c) -{ - CalendarObject *co; - GList **l = c; - - co = g_new (CalendarObject, 1); - - co->ev_start = start; - co->ev_end = end; - co->ico = obj; - *l = g_list_insert_sorted (*l, co, calendar_object_compare_by_start); - - return 1; -} - -void -calendar_destroy_event_list (GList *l) -{ - GList *p; - - for (p = l; p; p = p->next) - g_free (p->data); - g_list_free (l); -} - -GList * -calendar_get_events_in_range (Calendar *cal, time_t start, time_t end) -{ - GList *l = 0; - - calendar_iterate (cal, start, end, assemble_event_list, &l); - return l; -} - -void -calendar_object_changed (Calendar *cal, iCalObject *obj, int flags) -{ - obj->last_mod = time (NULL); - obj->pilot_status = ICAL_PILOT_SYNC_MOD; - - if (!(flags & CHANGE_DATES)) - return; - - /* Remove any alarms on the alarm list for this object */ - while (alarm_kill (obj)) - ; - - ical_object_try_alarms (obj); -} - -static void -calendar_day_change (time_t time, CalendarAlarm *which, void *closure) -{ - GList *events; - Calendar *cal = closure; - - calendar_set_day (); - calendar_init_alarms (cal); - - for (events = cal->events; events; events = events->next){ - iCalObject *obj = events->data; - - ical_object_try_alarms (obj); - } -} - -static void -calendar_init_alarms (Calendar *cal) -{ - CalendarAlarm day_change_alarm; - - day_change_alarm.trigger = calendar_day_end; - alarm_add (&day_change_alarm, calendar_day_change, cal); -} - -static iCalObject * -calendar_object_find_in_list (Calendar *cal, GList *list, const char *uid) -{ - GList *l; - - for (l = list; l; l = l->next){ - iCalObject *obj = l->data; - - if (strcmp (obj->uid, uid) == 0) - return obj; - } - - return NULL; -} - -iCalObject * -calendar_object_find_event (Calendar *cal, const char *uid) -{ - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - return g_hash_table_lookup (cal->event_hash, uid); -} - -iCalObject * -calendar_object_find_todo (Calendar *cal, const char *uid) -{ - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - return calendar_object_find_in_list (cal, cal->todo, uid); -} - -iCalObject * -calendar_object_find (Calendar *cal, const char *uid) -{ - iCalObject *obj; - - g_return_val_if_fail (cal != NULL, NULL); - g_return_val_if_fail (uid != NULL, NULL); - - obj = calendar_object_find_in_list (cal, cal->todo, uid); - - if (obj == NULL) - obj = calendar_object_find_in_list (cal, cal->events, uid); - - return obj; -} - -iCalObject * -calendar_object_find_by_pilot (Calendar *cal, int pilot_id) -{ - GList *l; - - g_return_val_if_fail (cal != NULL, NULL); - - for (l = cal->events; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_id == pilot_id) - return obj; - } - - for (l = cal->todo; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_id == pilot_id) - return obj; - } - - return NULL; -} - -/* - * calendar_string_from_object: - * - * Returns the iCalObject @object armored around a vCalendar - * object as a string. - */ -char * -calendar_string_from_object (iCalObject *object) -{ - Calendar *cal; - char *str; - - g_return_val_if_fail (object != NULL, NULL); - - cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); - calendar_add_object (cal, object); - str = calendar_get_as_vcal_string (cal); - calendar_remove_object (cal, object); - - calendar_destroy (cal); - - return str; -} diff --git a/calendar/calendar.h b/calendar/calendar.h deleted file mode 100644 index 83a5f67c84..0000000000 --- a/calendar/calendar.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef CALENDAR_H -#define CALENDAR_H - -#include "pcs/calobj.h" - -BEGIN_GNOME_DECLS - -typedef struct { - /* This calendar's title */ - char *title; - - /* backing store for this calendar object */ - char *filename; - - /* The list of events; todo's and journal entries */ - GList *events; - GList *todo; - GList *journal; - GList *timezones; /* required for iCalendar */ - - GHashTable *event_hash; - - /* Time at which the calendar was created */ - time_t created; - - /* Timestamp in the filename */ - time_t file_time; - - /* If the calendar was last modified */ - int modified; - void *temp; - - void *corba_server; -} Calendar; - -/* This is only used by the calendar_get_events_in_range routine to get - * a list of objects that recur on a specific date - */ -typedef struct { - time_t ev_start; - time_t ev_end; - iCalObject *ico; -} CalendarObject; - -typedef enum { - CALENDAR_INIT_NIL = 0, - CALENDAR_INIT_ALARMS = 1 << 0, - CALENDAR_USE_ICAL = 1 << 1 -} CalendarNewOptions; - -Calendar *calendar_new (char *title,CalendarNewOptions options); -char *calendar_get_as_vcal_string (Calendar *cal); -char *calendar_string_from_object (iCalObject *object); - -char *calendar_load (Calendar *cal, char *fname); -char *calendar_load_from_memory (Calendar *cal, const char *buffer); -void calendar_load_from_vobject (Calendar *cal, VObject *vcal); -void calendar_save (Calendar *cal, char *fname); -void calendar_add_object (Calendar *cal, iCalObject *obj); -void calendar_remove_object (Calendar *cal, iCalObject *obj); -void calendar_destroy (Calendar *cal); -GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -gint calendar_compare_by_dtstart (gpointer a, gpointer b); - -void calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure); -void calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure); - -/* Returns a list of CalendarObject structures. These represent the events in the calendar that are - * in the specified range. - */ -GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end); - -/* Destroy list returned by calendar_get_events_in_range() with this function */ -void calendar_destroy_event_list (GList *l); - -/* Informs the calendar that obj information has changed */ -void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags); - -void calendar_notify (time_t time, CalendarAlarm *which, void *data); - -iCalObject *calendar_object_find_event (Calendar *cal, const char *uid); -iCalObject *calendar_object_find_todo (Calendar *cal, const char *uid); -iCalObject *calendar_object_find (Calendar *cal, const char *uid); -iCalObject *calendar_object_find_by_pilot (Calendar *cal, int pilot_id); - -END_GNOME_DECLS - -#endif diff --git a/calendar/corba-cal-factory.c b/calendar/corba-cal-factory.c deleted file mode 100644 index a0630fda73..0000000000 --- a/calendar/corba-cal-factory.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * corba-cal-factory.c: Service that provides access to the calendar repositories. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ - -#include <config.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/stat.h> -#include "gnome-cal.h" -#include "main.h" -#include "alarm.h" -#include "cal-util/timeutil.h" -#include "libversit/vcc.h" -#include <libgnorba/gnorba.h> -#include <bonobo.h> -#include "GnomeCal.h" -#include "corba-cal-factory.h" -#include "corba-cal.h" - -CORBA_ORB orb; -PortableServer_POA poa; -PortableServer_POAManager poa_manager; - -static POA_Bonobo_GenericFactory__epv calendar_epv; -static POA_Bonobo_GenericFactory__vepv calendar_vepv; - -/* - * Servant and Object Factory - */ -static POA_Bonobo_GenericFactory calendar_servant; -static Bonobo_GenericFactory calendar_factory; - -static CORBA_boolean -calendar_supports (PortableServer_Servant servant, - CORBA_char * obj_goad_id, - CORBA_Environment * ev) -{ - if (strcmp (obj_goad_id, "IDL:GNOME:Calendar:Repository:1.0") == 0) - return CORBA_TRUE; - else - return CORBA_FALSE; -} - -static CORBA_Object -calendar_create_object (PortableServer_Servant servant, - CORBA_char *goad_id, - const GNOME_stringlist *params, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal; - struct stat s; - char *name; - - if (params->_length == 1) - name = params->_buffer [0]; - else - name = NULL; - - if (strcmp (goad_id, "IDL:GNOME:Calendar:Repository:1.0") != 0){ - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_GenericFactory_CannotActivate, - NULL); - return CORBA_OBJECT_NIL; - } - - gcal = gnome_calendar_locate (name); - if (gcal != NULL) - return CORBA_Object_duplicate (gcal->cal->corba_server, ev); - - if (stat (name, &s) != 0){ - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_GenericFactory_CannotActivate, - NULL); - return CORBA_OBJECT_NIL; - } - - gcal = new_calendar ("", name, NULL, NULL, FALSE); - - return CORBA_Object_duplicate (gcal->cal->corba_server, ev); -} - -void -init_corba_server (void) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - poa_manager = PortableServer_POA__get_the_POAManager (poa, &ev); - if (ev._major != CORBA_NO_EXCEPTION){ - g_warning ("Can not get the POA manager"); - CORBA_exception_free (&ev); - return; - } - - PortableServer_POAManager_activate (poa_manager, &ev); - - /* First create the locator for the repositories as a factory object */ - calendar_vepv.Bonobo_GenericFactory_epv = &calendar_epv; - calendar_epv.supports = calendar_supports; - calendar_epv.create_object = calendar_create_object; - - calendar_servant.vepv = &calendar_vepv; - POA_Bonobo_GenericFactory__init ((PortableServer_Servant) &calendar_servant, &ev); - CORBA_free (PortableServer_POA_activate_object ( - poa, (PortableServer_Servant)&calendar_servant, &ev)); - - calendar_factory = PortableServer_POA_servant_to_reference ( - poa, (PortableServer_Servant) &calendar_servant, &ev); - - goad_server_register ( - CORBA_OBJECT_NIL, calendar_factory, - "IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev); - CORBA_exception_free (&ev); -} - -void -unregister_calendar_services (void) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - goad_server_unregister ( - CORBA_OBJECT_NIL, - "IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev); - CORBA_exception_free (&ev); -} diff --git a/calendar/corba-cal-factory.h b/calendar/corba-cal-factory.h deleted file mode 100644 index 096baef012..0000000000 --- a/calendar/corba-cal-factory.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _CORBA_CAL_FACTORY_H_ -#define _CORBA_CAL_FACTORY_H_ - -/* The CORBA globals */ -CORBA_ORB orb; -PortableServer_POA poa; - -void init_corba_server (void); -void unregister_calendar_services (void); - -#endif /* _CORBA_CAL_FACTORY_H_ */ diff --git a/calendar/corba-cal.c b/calendar/corba-cal.c deleted file mode 100644 index 759b989893..0000000000 --- a/calendar/corba-cal.c +++ /dev/null @@ -1,343 +0,0 @@ -/* - * corba-cal.c: Service that provides access to the calendar repository - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ - -#include <config.h> -#include <stdio.h> -#include <unistd.h> -#include <sys/stat.h> -#include "calendar.h" -#include "gnome-cal.h" -#include "alarm.h" -#include "cal-util/timeutil.h" -#include "libversit/vcc.h" -#include <libgnorba/gnome-factory.h> -#include "GnomeCal.h" -#include "corba-cal-factory.h" -#include "corba-cal.h" - -typedef struct { - POA_GNOME_Calendar_Repository servant; - GnomeCalendar *calendar; -} CalendarServant; - -/* - * Vectors - */ -static POA_GNOME_Calendar_Repository__epv calendar_repository_epv; -static POA_GNOME_Calendar_Repository__vepv calendar_repository_vepv; - -/* - * Servant and Object Factory - */ -static POA_GNOME_Calendar_Repository calendar_repository_servant; - -static inline GnomeCalendar * -gnomecal_from_servant (PortableServer_Servant servant) -{ - CalendarServant *cs = (CalendarServant *) servant; - - return cs->calendar; -} - -static CORBA_char * -cal_repo_get_object (PortableServer_Servant servant, - const CORBA_char *uid, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *buffer; - CORBA_char *ret; - - obj = calendar_object_find_event (gcal->cal, uid); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set ( - ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, - exn); - return NULL; - } - - buffer = calendar_string_from_object (obj); - ret = CORBA_string_dup (buffer); - free (buffer); - - return ret; -} - -static CORBA_char * -cal_repo_get_object_by_pilot_id (PortableServer_Servant servant, - CORBA_long pilot_id, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - char *buffer; - CORBA_char *ret; - - obj = calendar_object_find_by_pilot (gcal->cal, pilot_id); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, exn); - return NULL; - } - - buffer = calendar_string_from_object (obj); - ret = CORBA_string_dup (buffer); - free (buffer); - - return ret; - -} - -static CORBA_char * -cal_repo_get_id_from_pilot_id (PortableServer_Servant servant, - CORBA_long pilot_id, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - - obj = calendar_object_find_by_pilot (gcal->cal, pilot_id); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, exn); - return NULL; - } - - return CORBA_string_dup (obj->uid); -} - -static void -cal_repo_delete_object (PortableServer_Servant servant, - const CORBA_char *uid, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - - obj = calendar_object_find_event (gcal->cal, uid); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set (ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, exn); - return; - } - - gnome_calendar_remove_object (gcal, obj); -} - -static void -cal_repo_update_object (PortableServer_Servant servant, - const CORBA_char *uid, - const CORBA_char *vcalendar_object, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - iCalObject *new_object; - - new_object = ical_object_new_from_string (vcalendar_object); - - obj = calendar_object_find_event (gcal->cal, uid); - if (obj != NULL){ - calendar_remove_object (gcal->cal, obj); - } - - calendar_add_object (gcal->cal, new_object); -} - -static void -cal_repo_update_pilot_id (PortableServer_Servant servant, - const CORBA_char *uid, - const CORBA_long pilot_id, - const CORBA_long pilot_status, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - iCalObject *obj; - - obj = calendar_object_find_event (gcal->cal, uid); - if (obj == NULL){ - GNOME_Calendar_Repository_NotFound *exn; - - exn = GNOME_Calendar_Repository_NotFound__alloc(); - CORBA_exception_set ( - ev, - CORBA_USER_EXCEPTION, - ex_GNOME_Calendar_Repository_NotFound, - exn); - return; - } - - obj->pilot_id = pilot_id; - obj->pilot_status = pilot_status; -} - -static CORBA_long -cal_repo_get_number_of_objects (PortableServer_Servant servant, - GNOME_Calendar_Repository_RecordStatus record_status, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - CORBA_long res; - GList *l; - iCalPilotState real_record_status; - - if (record_status == GNOME_Calendar_Repository_ANY) { - return g_list_length(gcal->cal->events); - } - - switch (record_status) { - case GNOME_Calendar_Repository_NEW: - real_record_status = ICAL_PILOT_SYNC_MOD; - break; - case GNOME_Calendar_Repository_MODIFIED: - real_record_status = ICAL_PILOT_SYNC_MOD; - break; - case GNOME_Calendar_Repository_DELETED: - real_record_status = ICAL_PILOT_SYNC_DEL; - break; - } - - res = 0; - - for (l = gcal->cal->events; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_status == real_record_status) - res ++; - } - - return res; -} - -static GNOME_Calendar_Repository_String_Sequence* -cal_repo_get_object_id_list(PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - GList *l; - GNOME_Calendar_Repository_String_Sequence *result; - int counter; - - result = GNOME_Calendar_Repository_String_Sequence__alloc(); - result->_length = g_list_length(gcal->cal->events); - result->_buffer = CORBA_sequence_CORBA_string_allocbuf(result->_length); - - counter = 0; - for (l = gcal->cal->events ; l; l = l->next){ - iCalObject *obj = l->data; - result->_buffer[counter] = CORBA_string_dup(obj->uid); - counter++; - } - - return result; -} - -static CORBA_char * -cal_repo_get_updated_objects (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - Calendar *dirty_cal; - GList *l; - CORBA_char *res; - char *str; - - dirty_cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); - - for (l = gcal->cal->events; l; l = l->next){ - iCalObject *obj = l->data; - - if (obj->pilot_status != ICAL_PILOT_SYNC_MOD) - continue; - - obj = ical_object_duplicate (l->data); - - calendar_add_object (dirty_cal, obj); - } - str = calendar_get_as_vcal_string (dirty_cal); - res = CORBA_string_dup (str); - free (str); /* calendar_get_as_vcal_string() uses writeMemVObject(), which uses realloc() */ - calendar_destroy (dirty_cal); - - return res; -} - -static void -cal_repo_done (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GnomeCalendar *gcal = gnomecal_from_servant (servant); - - calendar_save (gcal->cal, NULL); -} - -static void -init_calendar_repo_class (void) -{ - calendar_repository_epv.get_object = cal_repo_get_object; - calendar_repository_epv.get_object_by_pilot_id = cal_repo_get_object_by_pilot_id; - calendar_repository_epv.get_id_from_pilot_id = cal_repo_get_id_from_pilot_id; - calendar_repository_epv.delete_object = cal_repo_delete_object; - calendar_repository_epv.update_object = cal_repo_update_object; - calendar_repository_epv.get_number_of_objects = cal_repo_get_number_of_objects; - calendar_repository_epv.get_updated_objects = cal_repo_get_updated_objects; - calendar_repository_epv.update_pilot_id = cal_repo_update_pilot_id; - calendar_repository_epv.get_object_id_list = cal_repo_get_object_id_list; - - calendar_repository_epv.done = cal_repo_done; - - calendar_repository_vepv.GNOME_Calendar_Repository_epv = - &calendar_repository_epv; - - calendar_repository_servant.vepv = &calendar_repository_vepv; -} - -/* - * Initializes the CORBA parts of the @calendar object - */ -void -gnome_calendar_create_corba_server (GnomeCalendar *calendar) -{ - static gboolean class_inited = FALSE; - CalendarServant *calendar_servant; - CORBA_Environment ev; - - if (!class_inited){ - init_calendar_repo_class (); - class_inited = TRUE; - } - - calendar_servant = g_new0 (CalendarServant, 1); - calendar_servant->servant.vepv = &calendar_repository_vepv; - calendar_servant->calendar = calendar; - - CORBA_exception_init (&ev); - POA_GNOME_Calendar_Repository__init ((PortableServer_Servant) calendar_servant, &ev); - CORBA_free ( - PortableServer_POA_activate_object (poa, calendar_servant, &ev)); - calendar->cal->corba_server = PortableServer_POA_servant_to_reference ( - poa, calendar_servant, &ev); - CORBA_exception_free (&ev); -} diff --git a/calendar/corba-cal.h b/calendar/corba-cal.h deleted file mode 100644 index 47caacba70..0000000000 --- a/calendar/corba-cal.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _CORBA_CAL_H_ -#define _CORBA_CAL_H_ - -void gnome_calendar_create_corba_server (GnomeCalendar *calendar); - -#endif /* _CORBA_CAL_H_ */ diff --git a/calendar/eventedit.c b/calendar/eventedit.c deleted file mode 100644 index e65db4e3da..0000000000 --- a/calendar/eventedit.c +++ /dev/null @@ -1,1584 +0,0 @@ -/* - * EventEditor widget - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: Miguel de Icaza (miguel@kernel.org) - * Federico Mena (quartic@gimp.org) - */ -#include <config.h> -#include <gnome.h> -#include <string.h> -#include "calendar.h" -#include "eventedit.h" -#include "main.h" -#include "cal-util/timeutil.h" - - -static void event_editor_class_init (EventEditorClass *class); -static void event_editor_init (EventEditor *ee); -static void event_editor_destroy (GtkObject *object); - -GtkWidget* make_spin_button (int val, int low, int high); -void ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType type, - int y, gboolean control_sens, GtkSignalFunc dirty_func); -void ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type); - -/* Note: do not i18n these strings, they are part of the vCalendar protocol */ -static char *class_names [] = { "PUBLIC", "PRIVATE", "CONFIDENTIAL" }; - -static GnomeDialogClass *parent_class; - -struct numbered_item { - char *text; - int num; -}; - - -guint -event_editor_get_type (void) -{ - static guint event_editor_type = 0; - - if(!event_editor_type) { - GtkTypeInfo event_editor_info = { - "EventEditor", - sizeof(EventEditor), - sizeof(EventEditorClass), - (GtkClassInitFunc) event_editor_class_init, - (GtkObjectInitFunc) event_editor_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL, - }; - event_editor_type = gtk_type_unique (gnome_dialog_get_type (), &event_editor_info); - } - return event_editor_type; -} - -static void -event_editor_class_init (EventEditorClass *class) -{ - GtkObjectClass *object_class; - - parent_class = gtk_type_class (gnome_dialog_get_type ()); - object_class = (GtkObjectClass*) class; - object_class->destroy = event_editor_destroy; -} - -GtkWidget * -make_spin_button (int val, int low, int high) -{ - GtkAdjustment *adj; - GtkWidget *spin; - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (val, low, high, 1, 10, 10)); - spin = gtk_spin_button_new (adj, 0.5, 0); - gtk_widget_set_usize (spin, 60, 0); - - return spin; -} - -/* - * Checks if the day range occupies all the day, and if so, check the - * box accordingly - */ -static void -ee_check_all_day (EventEditor *ee) -{ - time_t ev_start, ev_end; - - ev_start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - ev_end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (get_time_t_hour (ev_start) <= day_begin && get_time_t_hour (ev_end) >= day_end) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->general_allday), 1); - else - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->general_allday), 0); -} - -/* - * Callback: checks that the dates are start < end - */ -static void -check_dates (GnomeDateEdit *gde, EventEditor *ee) -{ - time_t start, end; - struct tm tm_start, tm_end; - - start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (start > end) { - tm_start = *localtime (&start); - tm_end = *localtime (&end); - - if (GTK_WIDGET (gde) == ee->start_time) { - tm_end.tm_year = tm_start.tm_year; - tm_end.tm_mon = tm_start.tm_mon; - tm_end.tm_mday = tm_start.tm_mday; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (&tm_end)); - } else if (GTK_WIDGET (gde) == ee->end_time) { - tm_start.tm_year = tm_end.tm_year; - tm_start.tm_mon = tm_end.tm_mon; - tm_start.tm_mday = tm_end.tm_mday; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (&tm_start)); - } - } -} - -/* - * Callback: checks that start_time < end_time and whether the - * selected hour range spans all of the day - */ -static void -check_times (GnomeDateEdit *gde, EventEditor *ee) -{ - time_t start, end; - struct tm tm_start, tm_end; - - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_flush (); - - start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (start >= end) { - tm_start = *localtime (&start); - tm_end = *localtime (&end); - - if (GTK_WIDGET (gde) == ee->start_time) { - tm_end.tm_min = tm_start.tm_min; - tm_end.tm_sec = tm_start.tm_sec; - - tm_end.tm_hour = tm_start.tm_hour + 1; - - if (tm_end.tm_hour >= 24) { - tm_end.tm_hour = 24; /* mktime() will bump the day */ - tm_end.tm_min = 0; - tm_end.tm_sec = 0; - } - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (&tm_end)); - } else if (GTK_WIDGET (gde) == ee->end_time) { - tm_start.tm_min = tm_end.tm_min; - tm_start.tm_sec = tm_end.tm_sec; - - tm_start.tm_hour = tm_end.tm_hour - 1; - - if (tm_start.tm_hour < 0) { - tm_start.tm_hour = 0; - tm_start.tm_min = 0; - tm_start.tm_min = 0; - } - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (&tm_start)); - } - } - - /* Check whether the event spans the whole day */ - - ee_check_all_day (ee); -} - -/* - * Callback: all day event box clicked - */ -static void -set_all_day (GtkToggleButton *toggle, EventEditor *ee) -{ - struct tm tm; - time_t start_t; - - start_t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - tm = *localtime (&start_t); - tm.tm_hour = day_begin; - tm.tm_min = 0; - tm.tm_sec = 0; - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (&tm)); - - if (toggle->active) - tm.tm_hour = day_end; - else - tm.tm_hour++; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (&tm)); -} - -/* Convenience function to create a properly-configured date editor widget */ -GtkWidget * -date_edit_new (time_t the_time, int show_time) -{ - return gnome_date_edit_new_flags (the_time, - ((show_time ? GNOME_DATE_EDIT_SHOW_TIME : 0) - | (am_pm_flag ? 0 : GNOME_DATE_EDIT_24_HR) - | (week_starts_on_monday - ? GNOME_DATE_EDIT_WEEK_STARTS_ON_MONDAY - : 0))); -} - -static GtkWidget * -event_editor_setup_time_frame (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *start_time, *end_time; - GtkTable *t; - - frame = gtk_frame_new (_("Time")); - t = GTK_TABLE (ee->general_time_table = gtk_table_new (1, 1, 0)); - gtk_container_border_width (GTK_CONTAINER (t), 4); - gtk_table_set_row_spacings (t, 4); - gtk_table_set_col_spacings (t, 4); - gtk_container_add (GTK_CONTAINER (frame), ee->general_time_table); - - /* 1. Start time */ - if (ee->ical->dtstart == 0){ - ee->ical->dtstart = time (NULL); - ee->ical->dtend = time_add_minutes (ee->ical->dtstart, 30); - } - ee->start_time = start_time = date_edit_new (ee->ical->dtstart, TRUE); - gnome_date_edit_set_popup_range ((GnomeDateEdit *) start_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (start_time), "date_changed", - GTK_SIGNAL_FUNC (check_dates), ee); - gtk_signal_connect (GTK_OBJECT (start_time), "time_changed", - GTK_SIGNAL_FUNC (check_times), ee); - gtk_table_attach (t, gtk_label_new (_("Start time:")), 1, 2, 1, 2, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_table_attach (t, start_time, 2, 3, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - /* 2. End time */ - ee->end_time = end_time = date_edit_new (ee->ical->dtend, TRUE); - gnome_date_edit_set_popup_range ((GnomeDateEdit *) end_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (end_time), "date_changed", - GTK_SIGNAL_FUNC (check_dates), ee); - gtk_signal_connect (GTK_OBJECT (end_time), "time_changed", - GTK_SIGNAL_FUNC (check_times), ee); - gtk_table_attach (t, gtk_label_new (_("End time:")), 1, 2, 2, 3, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_table_attach (t, end_time, 2, 3, 2, 3, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - /* 3. All day checkbox */ - ee->general_allday = gtk_check_button_new_with_label (_("All day event")); - gtk_signal_connect (GTK_OBJECT (ee->general_allday), "toggled", - GTK_SIGNAL_FUNC (set_all_day), ee); - gtk_table_attach (t, ee->general_allday, 3, 4, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 4, 0); - ee_check_all_day (ee); - - return frame; -} - -static GtkWidget * -timesel_new (void) -{ - GtkWidget *menu, *option_menu; - char *items [] = { N_("Minutes"), N_("Hours"), N_("Days") }; - int i; - - option_menu = gtk_option_menu_new (); - menu = gtk_menu_new (); - for (i = 0; i < 3; i++){ - GtkWidget *item; - - item = gtk_menu_item_new_with_label (_(items [i])); - gtk_menu_append (GTK_MENU (menu), item); - gtk_widget_show (item); - } - gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); - return option_menu; -} - -/* - * Set the sensitive state depending on whether the alarm enabled flag. - */ -static void -ee_alarm_setting (CalendarAlarm *alarm, int sensitive) -{ - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_count), sensitive); - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_timesel), sensitive); - - if (alarm->type == ALARM_PROGRAM || alarm->type == ALARM_MAIL){ - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_entry), sensitive); - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_label), sensitive); - } -} - -static void -alarm_toggle (GtkToggleButton *toggle, CalendarAlarm *alarm) -{ - ee_alarm_setting (alarm, toggle->active); -} - -#define FXS (GTK_FILL | GTK_EXPAND | GTK_SHRINK) -#define FS (GTK_FILL | GTK_SHRINK) - -void -ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType type, int y, gboolean control_sens, GtkSignalFunc dirty_func) -{ - GtkWidget *entry; - - alarm->w_enabled = gtk_check_button_new_with_label (str); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), - alarm->enabled); - if (control_sens) - gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", - GTK_SIGNAL_FUNC (alarm_toggle), alarm); - if (dirty_func) - gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", - GTK_SIGNAL_FUNC (dirty_func), NULL); - gtk_table_attach (table, alarm->w_enabled, 0, 1, y, y+1, FS, FS, 0, 0); - - alarm->w_count = make_spin_button (alarm->count, 0, 10000); - if (dirty_func) - gtk_signal_connect (GTK_OBJECT (alarm->w_count), "changed", - GTK_SIGNAL_FUNC (dirty_func), NULL); - gtk_table_attach (table, alarm->w_count, 1, 2, y, y+1, FS, FS, 0, 0); - - alarm->w_timesel = timesel_new (); - /* is there a "changed" signal which we can connect to? */ - gtk_option_menu_set_history (GTK_OPTION_MENU (alarm->w_timesel), alarm->units); - gtk_table_attach (table, alarm->w_timesel, 2, 3, y, y+1, FS, FS, 0, 0); - - switch (type){ - case ALARM_MAIL: - alarm->w_label = gtk_label_new (_("Mail to:")); - gtk_misc_set_alignment (GTK_MISC (alarm->w_label), 1.0, 0.5); - gtk_table_attach (table, alarm->w_label, 3, 4, y, y+1, FS, FS, 0, 0); - alarm->w_entry = gtk_entry_new (); - gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); - gtk_entry_set_text (GTK_ENTRY (alarm->w_entry), alarm->data ? alarm->data : ""); - if (dirty_func) - gtk_signal_connect (GTK_OBJECT (alarm->w_entry), - "changed", - GTK_SIGNAL_FUNC (dirty_func), - NULL); - break; - - case ALARM_PROGRAM: - alarm->w_label = gtk_label_new (_("Run program:")); - gtk_misc_set_alignment (GTK_MISC (alarm->w_label), 1.0, 0.5); - gtk_table_attach (table, alarm->w_label, 3, 4, y, y+1, FS, FS, 0, 0); - alarm->w_entry = gnome_file_entry_new ("alarm-program", _("Select program to run at alarm time")); - entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (alarm->w_entry)); - gtk_entry_set_text (GTK_ENTRY (entry), alarm->data ? alarm->data : ""); - gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); - if (dirty_func) - gtk_signal_connect (GTK_OBJECT (entry), - "changed", - GTK_SIGNAL_FUNC (dirty_func), - NULL); - break; - - default: - break; - } - - if (control_sens) - ee_alarm_setting (alarm, alarm->enabled); - else - ee_alarm_setting (alarm, TRUE); -} - -static GtkWidget * -ee_alarm_widgets (EventEditor *ee) -{ - GtkWidget *table, *mailto, *mailte, *l; - - l = gtk_frame_new (_("Alarms")); - - table = gtk_table_new (1, 1, 0); - gtk_container_border_width (GTK_CONTAINER (table), 4); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_table_set_col_spacings (GTK_TABLE (table), 4); - gtk_container_add (GTK_CONTAINER (l), table); - - mailto = gtk_label_new (_("Mail to:")); - mailte = gtk_entry_new (); - - ee_create_ae (GTK_TABLE (table), _("Display"), &ee->ical->dalarm, ALARM_DISPLAY, 1, TRUE, NULL); - ee_create_ae (GTK_TABLE (table), _("Audio"), &ee->ical->aalarm, ALARM_AUDIO, 2, TRUE, NULL); - ee_create_ae (GTK_TABLE (table), _("Program"), &ee->ical->palarm, ALARM_PROGRAM, 3, TRUE, NULL); - ee_create_ae (GTK_TABLE (table), _("Mail"), &ee->ical->malarm, ALARM_MAIL, 4, TRUE, NULL); - - return l; -} - -static GtkWidget * -ee_classification_widgets (EventEditor *ee) -{ - GtkWidget *rpub, *rpriv, *rconf; - GtkWidget *frame, *hbox; - - frame = gtk_frame_new (_("Classification")); - - hbox = gtk_hbox_new (TRUE, 0); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - rpub = gtk_radio_button_new_with_label (NULL, _("Public")); - rpriv = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rpub), _("Private")); - rconf = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rpub), _("Confidential")); - - gtk_box_pack_start (GTK_BOX (hbox), rpub, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), rpriv, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), rconf, FALSE, FALSE, 0); - - if (strcmp (ee->ical->class, class_names[0]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rpub), TRUE); - else if (strcmp (ee->ical->class, class_names[1]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rpriv), TRUE); - else if (strcmp (ee->ical->class, class_names[2]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rconf), TRUE); - - ee->general_radios = rpub; - - return frame; -} - -/* - * Retrieves the information from the CalendarAlarm widgets and stores them - * on the CalendarAlarm generic values - */ -void -ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type) -{ - GtkWidget *item; - GtkMenu *menu; - GList *child; - int idx; - - if (alarm->data){ - g_free (alarm->data); - alarm->data = 0; - } - - alarm->enabled = GTK_TOGGLE_BUTTON (alarm->w_enabled)->active; - - if (!alarm->enabled) - return; - - if (type == ALARM_PROGRAM) - alarm->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (gnome_file_entry_gtk_entry (alarm->w_entry)))); - if (type == ALARM_MAIL) - alarm->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (alarm->w_entry))); - - /* Find out the index */ - menu = GTK_MENU (GTK_OPTION_MENU (alarm->w_timesel)->menu); - - item = gtk_menu_get_active (menu); - - for (idx = 0, child = GTK_MENU_SHELL (menu)->children; child->data != item; child = child->next) - idx++; - - alarm->units = idx; - alarm->count = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (alarm->w_count)); -} - -static void -ee_store_general_values_to_ical (EventEditor *ee) -{ - GtkRadioButton *radio = GTK_RADIO_BUTTON (ee->general_radios); - iCalObject *ical = ee->ical; - GSList *list = radio->group; - int idx; - time_t now; - - now = time (NULL); - ical->dtstart = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - ical->dtend = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (ical->summary) - g_free (ical->summary); - - ical->summary = gtk_editable_get_chars (GTK_EDITABLE (ee->general_summary), 0, -1); - - ee_store_alarm (&ical->dalarm, ALARM_DISPLAY); - ee_store_alarm (&ical->aalarm, ALARM_AUDIO); - ee_store_alarm (&ical->palarm, ALARM_PROGRAM); - ee_store_alarm (&ical->malarm, ALARM_MAIL); - - for (idx = 2; list; list = list->next) { - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - idx--; /* The group is stored in reverse order of insertion */ - } - - g_free (ical->class); - ical->class = g_strdup (class_names [idx]); -} - -static int -option_menu_active_number (GtkWidget *omenu) -{ - GtkWidget *menu; - GtkWidget *item; - struct numbered_item *ni; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu)); - item = gtk_menu_get_active (GTK_MENU (menu)); - - ni = gtk_object_get_user_data (GTK_OBJECT (item)); - - return ni->num; -} - -static int -ee_store_recur_rule_to_ical (EventEditor *ee) -{ - iCalObject *ical; - int i, j; - GSList *list; - - ical = ee->ical; - - for (i = 0, list = ee->recur_rr_group; list; i++, list = list->next) - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - - i = g_slist_length (ee->recur_rr_group) - i - 1; /* buttons are stored in reverse order of insertion */ - - /* None selected, no rule to be stored */ - if (i == 0) - return 0; - - if (!ical->recur) - ical->recur = g_new0 (Recurrence, 1); - - switch (i) { - case 1: - /* Daily */ - ical->recur->type = RECUR_DAILY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_day_period)); - break; - - case 2: - /* Weekly */ - ical->recur->type = RECUR_WEEKLY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_week_period)); - ical->recur->weekday = 0; - - for (j = 0; j < 7; j++) - if (GTK_TOGGLE_BUTTON (ee->recur_rr_week_days[j])->active) { - if (j == 6) - ical->recur->weekday |= 1 << 0; /* sunday is at bit 0 */ - else - ical->recur->weekday |= 1 << (j + 1); - } - - break; - - case 3: - /* Monthly */ - - if (GTK_WIDGET_SENSITIVE (ee->recur_rr_month_date)) { - /* by day */ - - ical->recur->type = RECUR_MONTHLY_BY_DAY; - ical->recur->u.month_day = - gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (ee->recur_rr_month_date)); - ical->recur->interval = - gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (ee->recur_rr_month_period)); - } else { - /* by position */ - - ical->recur->type = RECUR_MONTHLY_BY_POS; - - ical->recur->u.month_pos = - option_menu_active_number (ee->recur_rr_month_day); - ical->recur->weekday = - option_menu_active_number (ee->recur_rr_month_weekday); - ical->recur->interval = - gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (ee->recur_rr_month_period)); - } - - break; - - case 4: - /* Yearly */ - ical->recur->type = RECUR_YEARLY_BY_DAY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_year_period)); - /* FIXME: need to specify anything else? I am assuming the code will look at the dtstart - * to figure out when to recur. - Federico - */ - break; - - default: - g_assert_not_reached (); - } - return 1; -} - -static void -ee_store_recur_end_to_ical (EventEditor *ee) -{ - iCalObject *ical; - GSList *list; - int i; - - /* Ending date of recurrence */ - - ical = ee->ical; - - for (i = 0, list = ee->recur_ed_group; list; i++, list = list->next) - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - - i = g_slist_length (ee->recur_ed_group) - i - 1; /* the list is stored in reverse order of insertion */ - - switch (i) { - case 0: - /* repeat forever */ - ical->recur->_enddate = 0; - ical->recur->enddate = 0; - ical->recur->duration = 0; - break; - - case 1: - /* end date */ - /* Also here, to ensure that the event is used, we add 86400 secs to get - get next day, in accordance to the RFC */ - ical->recur->_enddate = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ed_end_on)) + 86400; - ical->recur->enddate = ical->recur->_enddate; - ical->recur->duration = 0; - break; - - case 2: - /* end after n occurrences */ - ical->recur->duration = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_ed_end_after)); - ical_object_compute_end (ical); - break; - - default: - g_assert_not_reached (); - break; - } -} - -static void -free_exdate (iCalObject *ical) -{ - GList *list; - - if (!ical->exdate) - return; - - for (list = ical->exdate; list; list = list->next) - g_free (list->data); - - g_list_free (ical->exdate); - ical->exdate = NULL; -} - -static void -ee_store_recur_exceptions_to_ical (EventEditor *ee) -{ - iCalObject *ical; - GtkCList *clist; - int i; - time_t *t; - - ical = ee->ical; - clist = GTK_CLIST (ee->recur_ex_clist); - - free_exdate (ical); - - for (i = 0; i < clist->rows; i++) { - t = gtk_clist_get_row_data (clist, i); - ical->exdate = g_list_prepend (ical->exdate, t); - } -} - -static void -ee_store_recur_values_to_ical (EventEditor *ee) -{ - if (ee_store_recur_rule_to_ical (ee)){ - ee_store_recur_exceptions_to_ical (ee); - ee_store_recur_end_to_ical (ee); - } else if (ee->ical->recur) { - g_free (ee->ical->recur); - ee->ical->recur = NULL; - if (ee->ical->exdate){ - GList *l = ee->ical->exdate; - - for (; l; l = l->next) - g_free (l->data); - g_list_free (l); - } - } -} - -/* - * Retrieves all of the information from the different widgets and updates - * the iCalObject accordingly. - */ -static void -ee_store_dlg_values_to_ical (EventEditor *ee) -{ - time_t now; - - ee_store_general_values_to_ical (ee); - ee_store_recur_values_to_ical (ee); - - now = time (NULL); - - /* FIXME: This is not entirely correct; we should check if the values actually changed */ - ee->ical->last_mod = now; - - if (ee->ical->new) - ee->ical->created = now; -} - -static void -ee_ok (GtkWidget *widget, EventEditor *ee) -{ - ee_store_dlg_values_to_ical (ee); - - if (ee->ical->new) - gnome_calendar_add_object (ee->gnome_cal, ee->ical); - else - gnome_calendar_object_changed (ee->gnome_cal, ee->ical, CHANGE_ALL); - - save_default_calendar (ee->gnome_cal); - ee->ical->new = 0; -} - -static void -ee_cancel (GtkWidget *widget, EventEditor *ee) -{ - if (ee->ical->new) { - ical_object_destroy (ee->ical); - ee->ical = NULL; - } - -} - -static void -ee_create_buttons (EventEditor *ee) -{ - gnome_dialog_append_buttons(GNOME_DIALOG(ee), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, NULL); - gnome_dialog_set_default (GNOME_DIALOG (ee), 0); - gnome_dialog_button_connect (GNOME_DIALOG (ee), 0, GTK_SIGNAL_FUNC(ee_ok), ee); - gnome_dialog_button_connect (GNOME_DIALOG (ee), 1, GTK_SIGNAL_FUNC(ee_cancel), ee); - - return; -} - -/* - * Load the contents in a delayed fashion, as the GtkText widget needs it - */ -static void -ee_fill_summary (GtkWidget *widget, EventEditor *ee) -{ - int pos = 0; - - gtk_editable_insert_text (GTK_EDITABLE (ee->general_summary), ee->ical->summary, - strlen (ee->ical->summary), &pos); - gtk_text_thaw (GTK_TEXT (ee->general_summary)); -} - -enum { - OWNER_LINE, - DESC_LINE, - SUMMARY_LINE, - TIME_LINE, - ALARM_LINE, - CLASS_LINE -}; - -/* Create/setup the general page */ -static void -ee_init_general_page (EventEditor *ee) -{ - GtkWidget *l; - GtkWidget *hbox; - - ee->general_table = gtk_table_new (1, 1, FALSE); - gtk_container_border_width (GTK_CONTAINER (ee->general_table), 4); - gtk_table_set_row_spacings (GTK_TABLE (ee->general_table), 4); - gtk_table_set_col_spacings (GTK_TABLE (ee->general_table), 4); - gtk_notebook_append_page (GTK_NOTEBOOK (ee->notebook), GTK_WIDGET (ee->general_table), - gtk_label_new (_("General"))); - - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (ee->general_table), hbox, - 0, 1, OWNER_LINE, OWNER_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 4); - - l = gtk_label_new (_("Owner:")); - gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0); - - ee->general_owner = gtk_label_new (ee->ical->organizer->addr ? - ee->ical->organizer->addr : _("?")); - gtk_misc_set_alignment (GTK_MISC (ee->general_owner), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox), ee->general_owner, TRUE, TRUE, 4); - - l = gtk_label_new (_("Summary:")); - gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, DESC_LINE, DESC_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - ee->general_summary = gtk_text_new (NULL, NULL); - gtk_text_freeze (GTK_TEXT (ee->general_summary)); - gtk_signal_connect (GTK_OBJECT (ee->general_summary), "realize", - GTK_SIGNAL_FUNC (ee_fill_summary), ee); - gtk_widget_set_usize (ee->general_summary, 0, 60); - gtk_text_set_editable (GTK_TEXT (ee->general_summary), 1); - gtk_table_attach (GTK_TABLE (ee->general_table), ee->general_summary, - 0, 1, SUMMARY_LINE, SUMMARY_LINE+1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = ee_alarm_widgets (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, ALARM_LINE, ALARM_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = event_editor_setup_time_frame (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, TIME_LINE, TIME_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = ee_classification_widgets (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, CLASS_LINE, CLASS_LINE + 1, - GTK_EXPAND | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); -} - -static void -ee_init_summary_page (EventEditor *ee) -{ -} - -struct { - char *name; -} recurrence_types [] = { - { N_("None") }, - { N_("Daily") }, - { N_("Weekly") }, - { N_("Monthly") }, - { N_("Yearly") }, - { 0 } -}; - -static void -recurrence_toggled (GtkRadioButton *radio, EventEditor *ee) -{ - GSList *list = ee->recur_rr_group; - int which; - - if (!GTK_TOGGLE_BUTTON (radio)->active) - return; - - for (which = 0; list; list = list->next, which++) { - if (list->data == radio) { - gtk_notebook_set_page (GTK_NOTEBOOK (ee->recur_rr_notebook), 4 - which); - return; - } - } -} - -static struct numbered_item weekday_positions[] = { - { N_("1st"), 1 }, - { N_("2nd"), 2 }, - { N_("3rd"), 3 }, - { N_("4th"), 4 }, - { N_("5th"), 5 }, - { 0 } -}; - -static struct numbered_item weekday_names[] = { - { N_("Monday"), 1 }, - { N_("Tuesday"), 2 }, - { N_("Wednesday"), 3 }, - { N_("Thursday"), 4 }, - { N_("Friday"), 5 }, - { N_("Saturday"), 6 }, - { N_("Sunday"), 0 }, /* on the spec, Sunday is zero */ - { 0 } -}; - -static GtkWidget * -make_numbered_menu (struct numbered_item *items, int sel) -{ - GtkWidget *option_menu, *menu; - int i; - - option_menu = gtk_option_menu_new (); - menu = gtk_menu_new (); - - for (i = 0; items[i].text; i++) { - GtkWidget *item; - - item = gtk_menu_item_new_with_label (_(items[i].text)); - gtk_object_set_user_data (GTK_OBJECT (item), &items[i]); - gtk_menu_append (GTK_MENU (menu), item); - gtk_widget_show (item); - } - - gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); - gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), sel); - - return option_menu; -} - -static void -month_sensitize (EventEditor *ee, int state) -{ - gtk_widget_set_sensitive (ee->recur_rr_month_date, state); - gtk_widget_set_sensitive (ee->recur_rr_month_date_label, state); - - gtk_widget_set_sensitive (ee->recur_rr_month_day, !state); - gtk_widget_set_sensitive (ee->recur_rr_month_weekday, !state); -} - -static void -recur_month_enable_date (GtkToggleButton *button, EventEditor *ee) -{ - month_sensitize (ee, button->active); -} - -static void -desensitize_on_toggle (GtkToggleButton *toggle, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), !toggle->active); -} - -static void -ee_rp_init_rule (EventEditor *ee) -{ - static char *day_names [] = { N_("Mon"), N_("Tue"), N_("Wed"), N_("Thu"), N_("Fri"), N_("Sat"), N_("Sun") }; - GtkWidget *r, *re, *r1, *f, *vbox, *hbox, *b, *week_hbox, *week_day, *w; - GtkWidget *none, *daily, *weekly, *monthly, *yearly; - GtkNotebook *notebook; - GSList *group; - int i, page, day_period, week_period, month_period, year_period; - int week_vector, default_day, def_pos, def_off; - struct tm tm; - - tm = *localtime (&ee->ical->dtstart); - - f = gtk_frame_new (_("Recurrence rule")); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (f), hbox); - - vbox = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (hbox), gtk_vseparator_new (), FALSE, FALSE, 0); - - ee->recur_rr_notebook = gtk_notebook_new (); - notebook = GTK_NOTEBOOK (ee->recur_rr_notebook); - gtk_box_pack_start (GTK_BOX (hbox), ee->recur_rr_notebook, TRUE, TRUE, 0); - - day_period = 1; - week_period = 1; - month_period = 1; - year_period = 1; - - /* Default to today */ - - week_vector = 1 << tm.tm_wday; - default_day = tm.tm_mday; - def_pos = 0; - def_off = 0; - - /* Determine which should be the default selection */ - - page = 0; - if (ee->ical->recur) { - enum RecurType type = ee->ical->recur->type; - int interval = ee->ical->recur->interval; - - switch (type) { - case RECUR_DAILY: - page = 1; - day_period = interval; - break; - - case RECUR_WEEKLY: - page = 2; - week_period = interval; - week_vector = ee->ical->recur->weekday; - break; - - case RECUR_MONTHLY_BY_POS: - page = 3; - month_period = interval; - def_pos = ee->ical->recur->u.month_pos; - default_day = ee->ical->recur->weekday; /* you can't use u.month_pos and u.month_day-- it's a union... */ - break; - - case RECUR_MONTHLY_BY_DAY: - page = 3; - month_period = interval; - default_day = ee->ical->recur->u.month_day; - break; - - case RECUR_YEARLY_BY_MONTH: - page = 4; - year_period = interval; - break; - - case RECUR_YEARLY_BY_DAY: - page = 4; - year_period = interval; - break; - } - } else - page = 0; - - /* The recurrency selector */ - - for (i = 0, group = NULL; recurrence_types [i].name; i++) { - r = gtk_radio_button_new_with_label (group, _(recurrence_types [i].name)); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (r)); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (r), i == page); - gtk_signal_connect (GTK_OBJECT (r), "toggled", GTK_SIGNAL_FUNC (recurrence_toggled), ee); - gtk_box_pack_start (GTK_BOX (vbox), r, FALSE, FALSE, 0); - - if (i == 0) - gtk_signal_connect (GTK_OBJECT (r), "toggled", - (GtkSignalFunc) desensitize_on_toggle, - ee->recur_hbox); - } - - ee->recur_rr_group = group; - - /* 0. No recurrence */ - none = gtk_label_new (""); - - /* 1. The daily recurrence */ - - daily = gtk_vbox_new (FALSE, 0); - - b = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (daily), b, FALSE, FALSE, 0); - - ee->recur_rr_day_period = make_spin_button (day_period, 1, 10000); - /* in some languages "Every" can follow the gender of the word it - refers to (here "day(s)"). leave the two leadin letter "d_" - in the translation they are ther on purpose */ - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("d_Every") +2), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), ee->recur_rr_day_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("day(s)")), FALSE, FALSE, 0); - - /* 2. The weekly recurrence */ - - weekly = gtk_vbox_new (FALSE, 4); - - week_hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (weekly), week_hbox, FALSE, FALSE, 0); - - /* 2.1 The week period selector */ - - ee->recur_rr_week_period = make_spin_button (week_period, 1, 10000); - /* in some languages "Every" can follow the gender of the word it - refers to (here "week(s)"). leave the two leadin letter "w_" - in the translation they are ther on purpose */ - gtk_box_pack_start (GTK_BOX (week_hbox), gtk_label_new (_("w_Every") +2), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (week_hbox), ee->recur_rr_week_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (week_hbox), gtk_label_new (_("week(s)")), FALSE, FALSE, 0); - - /* 2.2 The week day selector */ - - week_day = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (weekly), week_day, FALSE, FALSE, 0); - - for (i = 0; i < 7; i++) { - ee->recur_rr_week_days [i] = gtk_check_button_new_with_label (_(day_names [i])); - gtk_box_pack_start (GTK_BOX (week_day), ee->recur_rr_week_days [i], FALSE, FALSE, 0); - - if (week_vector & (1 << ((i + 1) % 7))) /* on the spec, Sunday is 0 */ - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->recur_rr_week_days [i]), TRUE); - } - - /* 3. The monthly recurrence */ - - monthly = gtk_table_new (0, 0, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (monthly), 4); - gtk_table_set_col_spacings (GTK_TABLE (monthly), 4); - - re = gtk_radio_button_new_with_label (NULL, _("Recur on the")); - ee->recur_rr_month_date = make_spin_button (default_day, 1, 31); - ee->recur_rr_month_date_label = w = gtk_label_new (_("th day of the month")); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (monthly), re, - 0, 1, 0, 1, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_date, - 1, 2, 0, 1, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), w, - 2, 3, 0, 1, FS, FS, 0, 0); - gtk_signal_connect (GTK_OBJECT (re), "toggled", GTK_SIGNAL_FUNC (recur_month_enable_date), ee); - - r1 = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (re)), _("Recur on the")); - ee->recur_rr_month_day = make_numbered_menu (weekday_positions, def_pos); - ee->recur_rr_month_weekday = make_numbered_menu (weekday_names, default_day); - gtk_table_attach (GTK_TABLE (monthly), r1, - 0, 1, 1, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_day, - 1, 2, 1, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_weekday, - 2, 3, 1, 2, FS, FS, 0, 0); - - /* in some languages "Every" can follow the gender of the word it - refers to (here "month(s)"). leave the two leadin letter "m_" - in the translation they are ther on purpose */ - gtk_table_attach (GTK_TABLE (monthly), gtk_label_new (_("m_Every") +2), - 3, 4, 0, 2, FS, FS, 0, 0); - ee->recur_rr_month_period = make_spin_button (month_period, 1, 10000); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_period, - 4, 5, 0, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), gtk_label_new (_("month(s)")), - 5, 6, 0, 2, FS, FS, 0, 0); - - if (ee->ical->recur) { - if (ee->ical->recur->type == RECUR_MONTHLY_BY_POS) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (r1), 1); - } else - recur_month_enable_date (GTK_TOGGLE_BUTTON (re), ee); - - /* 4. The yearly recurrence */ - - yearly = gtk_vbox_new (FALSE, 0); - - b = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (yearly), b, FALSE, FALSE, 0); - - ee->recur_rr_year_period = make_spin_button (year_period, 1, 10000); - /* in some languages "Every" can follow the gender of the word it - refers to (here "year(s)"). leave the two leadin letter "y_" - in the translation they are ther on purpose */ - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("y_Every") +2), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), ee->recur_rr_year_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("year(s)")), FALSE, FALSE, 0); - - /* Finish setting this up */ - - gtk_notebook_append_page (notebook, none, gtk_label_new ("")); - gtk_notebook_append_page (notebook, daily, gtk_label_new ("")); - gtk_notebook_append_page (notebook, weekly, gtk_label_new ("")); - gtk_notebook_append_page (notebook, monthly, gtk_label_new ("")); - gtk_notebook_append_page (notebook, yearly, gtk_label_new ("")); - gtk_notebook_set_show_tabs (notebook, FALSE); - gtk_notebook_set_show_border (notebook, FALSE); - - gtk_notebook_set_page (notebook, page); - - /* Attach to the main box */ - - gtk_box_pack_start (GTK_BOX (ee->recur_vbox), f, FALSE, FALSE, 0); -} - -static void -sensitize_on_toggle (GtkToggleButton *toggle, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), toggle->active); -} - -static void -ee_rp_init_ending_date (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *vbox; - GSList *group; - GtkWidget *radio0, *radio1, *radio2; - GtkWidget *hbox; - GtkWidget *ihbox; - GtkWidget *widget; - time_t enddate; - int repeat; - - frame = gtk_frame_new (_("Ending date")); - - vbox = gtk_vbox_new (TRUE, 4); - gtk_container_border_width (GTK_CONTAINER (vbox), 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - group = NULL; - - /* repeat forever */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio0 = gtk_radio_button_new_with_label (group, _("Repeat forever")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio0)); - gtk_box_pack_start (GTK_BOX (hbox), radio0, FALSE, FALSE, 0); - - /* end on date */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio1 = gtk_radio_button_new_with_label (group, _("End on")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio1)); - gtk_box_pack_start (GTK_BOX (hbox), radio1, FALSE, FALSE, 0); - - ihbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ihbox, FALSE); - gtk_box_pack_start (GTK_BOX (hbox), ihbox, FALSE, FALSE, 0); - - if (ee->ical->recur) { - /* Shorten by one day, as we store end-on date a day ahead */ - enddate = ee->ical->recur->enddate - 86400; - } else - enddate = ee->ical->dtend; - - ee->recur_ed_end_on = widget = date_edit_new (enddate, FALSE); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - gtk_signal_connect (GTK_OBJECT (radio1), "toggled", - (GtkSignalFunc) sensitize_on_toggle, - ihbox); - - /* end after n occurrences */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio2 = gtk_radio_button_new_with_label (group, _("End after")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio2)); - gtk_box_pack_start (GTK_BOX (hbox), radio2, FALSE, FALSE, 0); - - ihbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ihbox, FALSE); - gtk_box_pack_start (GTK_BOX (hbox), ihbox, FALSE, FALSE, 0); - - if (ee->ical->recur && ee->ical->recur->duration) - repeat = ee->ical->recur->duration; - else - repeat = 2; - - ee->recur_ed_end_after = widget = make_spin_button (repeat, 1, 10000); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - widget = gtk_label_new (_("occurrence(s)")); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - gtk_signal_connect (GTK_OBJECT (radio2), "toggled", - (GtkSignalFunc) sensitize_on_toggle, - ihbox); - - /* Activate appropriate item */ - - if (ee->ical->recur) { - if (ee->ical->recur->_enddate == 0) { - if (ee->ical->recur->duration == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio0), TRUE); - else { - gtk_spin_button_set_value (GTK_SPIN_BUTTON (ee->recur_ed_end_after), - ee->ical->recur->duration); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio2), TRUE); - } - } else { - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->recur_ed_end_on), ee->ical->recur->enddate); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio1), TRUE); - } - } - - /* Done, add to main table */ - - ee->recur_ed_group = group; - - gtk_box_pack_start (GTK_BOX (ee->recur_hbox), frame, FALSE, FALSE, 0); -} - -static char * -get_exception_string (time_t t) -{ - static char buf[256]; - - strftime (buf, sizeof(buf), _("%a %b %d %Y"), localtime (&t)); - return buf; -} - -static void -append_exception (EventEditor *ee, time_t t) -{ - time_t *tt; - char *c[1]; - int i; - - c[0] = get_exception_string (t); - - tt = g_new (time_t, 1); - *tt = t; - - i = gtk_clist_append (GTK_CLIST (ee->recur_ex_clist), c); - gtk_clist_set_row_data (GTK_CLIST (ee->recur_ex_clist), i, tt); - gtk_clist_select_row (GTK_CLIST (ee->recur_ex_clist), i, 0); - - gtk_widget_set_sensitive (ee->recur_ex_vbox, TRUE); -} - -static void -fill_exception_clist (EventEditor *ee) -{ - GList *list; - - for (list = ee->ical->exdate; list; list = list->next) - append_exception (ee, *((time_t *) list->data)); -} - -static void -add_exception (GtkWidget *widget, EventEditor *ee) -{ - time_t t; - - t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ex_date)); - append_exception (ee, t); -} - -static void -change_exception (GtkWidget *widget, EventEditor *ee) -{ - GtkCList *clist; - time_t *t; - int sel; - - clist = GTK_CLIST (ee->recur_ex_clist); - sel = GPOINTER_TO_INT(clist->selection->data); - - t = gtk_clist_get_row_data (clist, sel); - *t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ex_date)); - - gtk_clist_set_text (clist, sel, 0, get_exception_string (*t)); -} - -static void -delete_exception (GtkWidget *widget, EventEditor *ee) -{ - GtkCList *clist; - int sel, length; - - clist = GTK_CLIST (ee->recur_ex_clist); - sel = GPOINTER_TO_INT(clist->selection->data); - - g_free (gtk_clist_get_row_data (clist, sel)); /* free the time_t stored there */ - - gtk_clist_remove (clist, sel); - length = g_list_length(clist->row_list); - if (sel >= length) - sel--; - gtk_clist_select_row (GTK_CLIST (ee->recur_ex_clist), sel, 0); - - if (clist->rows == 0) - gtk_widget_set_sensitive (ee->recur_ex_vbox, FALSE); -} - -static void -ee_rp_init_exceptions (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *ivbox; - GtkWidget *widget; - GtkWidget *sw; - - frame = gtk_frame_new (_("Exceptions")); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - vbox = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); - - ee->recur_ex_date = widget = date_edit_new (time (NULL), FALSE); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Add exception")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) add_exception, - ee); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - - ee->recur_ex_vbox = ivbox = gtk_vbox_new (FALSE, 4); - gtk_widget_set_sensitive (ivbox, FALSE); /* at first there are no items to change or delete */ - gtk_box_pack_start (GTK_BOX (vbox), ivbox, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Change selected")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) change_exception, - ee); - gtk_box_pack_start (GTK_BOX (ivbox), widget, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Delete selected")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) delete_exception, - ee); - gtk_box_pack_start (GTK_BOX (ivbox), widget, FALSE, FALSE, 0); - - ee->recur_ex_clist = widget = gtk_clist_new (1); - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (sw), widget); - gtk_clist_set_selection_mode (GTK_CLIST (widget), GTK_SELECTION_BROWSE); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - fill_exception_clist (ee); - gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0); - - /* Done, add to main table */ - - gtk_box_pack_start (GTK_BOX (ee->recur_hbox), frame, TRUE, TRUE, 0); -} - -static void -ee_init_recurrence_page (EventEditor *ee) -{ - ee->recur_vbox = gtk_vbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (ee->recur_vbox), 4); - - ee->recur_hbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ee->recur_hbox, FALSE); - - ee->recur_page_label = gtk_label_new (_("Recurrence")); - - gtk_notebook_append_page (GTK_NOTEBOOK (ee->notebook), ee->recur_vbox, - ee->recur_page_label); - - ee_rp_init_rule (ee); - - /* pack here so that the box gets inserted after the recurrence rule frame */ - gtk_box_pack_start (GTK_BOX (ee->recur_vbox), ee->recur_hbox, FALSE, FALSE, 0); - - ee_rp_init_ending_date (ee); - ee_rp_init_exceptions (ee); -} - -static void -event_editor_init_widgets (EventEditor *ee) -{ - ee->notebook = gtk_notebook_new (); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG(ee)->vbox), ee->notebook, 1, 1, 0); - - /* Init the various configuration pages */ - ee_init_general_page (ee); - ee_init_summary_page (ee); - ee_init_recurrence_page (ee); - - /* Buttons */ - ee_create_buttons(ee); - - /* We show all of the contained widgets */ - gtk_widget_show_all (GTK_BIN (ee)->child); -} - -static void -event_editor_init (EventEditor *ee) -{ - ee->ical = 0; - gnome_dialog_set_close (GNOME_DIALOG(ee), TRUE); -} - -static void -event_editor_destroy (GtkObject *object) -{ - EventEditor *ee; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_EVENT_EDITOR (object)); - - ee = EVENT_EDITOR (object); - - if (ee->ical) - ee->ical->user_data = NULL; /* we are no longer editing it */ -} - -GtkWidget * -event_editor_new (GnomeCalendar *gcal, iCalObject *ical) -{ - GtkWidget *retval; - EventEditor *ee; - - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_flush (); - - retval = gtk_type_new (event_editor_get_type ()); - ee = EVENT_EDITOR (retval); - - if (ical == 0){ - ical = ical_new ("", user_name, ""); - ical->new = 1; - } - - if (ical->new){ - gtk_window_set_title (GTK_WINDOW (ee), _("Create new appointment")); - } else { - gtk_window_set_title (GTK_WINDOW (ee), _("Edit appointment")); - } - - ical->user_data = ee; /* so that the world can know we are editing it */ - - ee->ical = ical; - ee->gnome_cal = gcal; - event_editor_init_widgets (ee); - - return retval; -} - -void -event_editor_new_whole_day (GnomeCalendar *owner, time_t day) -{ - struct tm tm; - iCalObject *ico; - GtkWidget *ee; - - g_return_if_fail (owner != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (owner)); - - ico = ical_new ("", user_name, ""); - ico->new = TRUE; - - tm = *localtime (&day); - - /* Set the start time of the event to the beginning of the day */ - - tm.tm_hour = day_begin; - tm.tm_min = 0; - tm.tm_sec = 0; - ico->dtstart = mktime (&tm); - - /* Set the end time of the event to the end of the day */ - - tm.tm_hour = day_end; - ico->dtend = mktime (&tm); - - /* Launch the event editor */ - - ee = event_editor_new (owner, ico); - gtk_widget_show (ee); -} diff --git a/calendar/eventedit.h b/calendar/eventedit.h deleted file mode 100644 index 4d605892dd..0000000000 --- a/calendar/eventedit.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * EventEditor widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ - -#ifndef EVENT_EDITOR_H -#define EVENT_EDITOR_H - -#include "gnome-cal.h" -#include <libgnomeui/gnome-dialog.h> - -BEGIN_GNOME_DECLS - - -#define EVENT_EDITOR(obj) GTK_CHECK_CAST(obj, event_editor_get_type(), EventEditor) -#define EVENT_EDITOR_CLASS(class) GTK_CHECK_CAST_CLASS(class, event_editor_get_type(), EventEditorClass) -#define IS_EVENT_EDITOR(obj) GTK_CHECK_TYPE(obj, event_editor_get_type()) - - -typedef struct { - GnomeDialog dialog; - GtkWidget *notebook; - - GtkWidget *general; - GtkWidget *general_table; - GtkWidget *general_time_table; - GtkWidget *general_allday; - GtkWidget *general_owner; - GtkWidget *general_summary; - GtkWidget *start_time, *end_time; - GtkWidget *general_radios; - - GtkWidget *recur_page_label; - GtkWidget *recur_vbox; - GtkWidget *recur_hbox; - - GSList *recur_rr_group; - GtkWidget *recur_rr_notebook; - GtkWidget *recur_rr_day_period; - GtkWidget *recur_rr_week_period; - GtkWidget *recur_rr_week_days [7]; - GtkWidget *recur_rr_month_date; - GtkWidget *recur_rr_month_date_label; - GtkWidget *recur_rr_month_day; - GtkWidget *recur_rr_month_weekday; - GtkWidget *recur_rr_month_period; - GtkWidget *recur_rr_year_period; - - GSList *recur_ed_group; - GtkWidget *recur_ed_end_on; - GtkWidget *recur_ed_end_after; - - GtkWidget *recur_ex_date; - GtkWidget *recur_ex_vbox; - GtkWidget *recur_ex_clist; - - /* The associated ical object */ - iCalObject *ical; - - /* The calendar owner of this event */ - GnomeCalendar *gnome_cal; -} EventEditor; - -typedef struct { - GnomeDialogClass parent_class; -} EventEditorClass; - - -guint event_editor_get_type (void); -GtkWidget *event_editor_new (GnomeCalendar *owner, iCalObject *); - -/* Convenience function to create and show a new event editor for an event that goes from day_begin - * to day_end of the specified day. - */ -void event_editor_new_whole_day (GnomeCalendar *owner, time_t day); - -GtkWidget *date_edit_new (time_t the_time, int show_time); - -END_GNOME_DECLS - -#endif diff --git a/calendar/getdate.y b/calendar/getdate.y deleted file mode 100644 index 6df71bddda..0000000000 --- a/calendar/getdate.y +++ /dev/null @@ -1,1001 +0,0 @@ -%{ -/* -** Originally) written by Steven M. Bellovin <smb@research.att.com> while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990; -** send any email to Rich. -** -** This grammar has 10 shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -*/ -/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */ -/* SUPPRESS 288 on yyerrlab *//* Label unused */ - -#include <config.h> -#include <gnome.h> - -/* Since the code of getdate.y is not included in the Emacs executable - itself, there is no need to #define static in this file. Even if - the code were included in the Emacs executable, it probably - wouldn't do any harm to #undef it here; this will only cause - problems if we try to write to a static variable, which I don't - think this code needs to do. */ -#ifdef emacs -#undef static -#endif - -#include <stdio.h> -#include <ctype.h> - -/* The code at the top of get_date which figures out the offset of the - current time zone checks various CPP symbols to see if special - tricks are need, but defaults to using the gettimeofday system call. - Include <sys/time.h> if that will be used. */ - -#if defined(vms) - -#include <types.h> -#include <time.h> - -#else - -#include <sys/types.h> - -#ifdef TIME_WITH_SYS_TIME -#include <sys/time.h> -#include <time.h> -#else -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#else -#include <time.h> -#endif -#endif - -#ifdef timezone -#undef timezone /* needed for sgi */ -#endif - -#if defined(HAVE_SYS_TIMEB_H) -#include <sys/timeb.h> -#else -/* -** We use the obsolete `struct timeb' as part of our interface! -** Since the system doesn't have it, we define it here; -** our callers must do likewise. -*/ -struct timeb { - time_t time; /* Seconds since the epoch */ - unsigned short millitm; /* Field not used */ - short timezone; /* Minutes west of GMT */ - short dstflag; /* Field not used */ -}; -#endif /* defined(HAVE_SYS_TIMEB_H) */ - -#endif /* defined(vms) */ - -#if defined (STDC_HEADERS) || defined (USG) -#include <string.h> -#endif - -/* Some old versions of bison generate parsers that use bcopy. - That loses on systems that don't provide the function, so we have - to redefine it here. */ -#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy) -#define bcopy(from, to, len) memcpy ((to), (from), (len)) -#endif - -#if defined (STDC_HEADERS) -#include <stdlib.h> -#endif - -/* NOTES on rebuilding getdate.c (particularly for inclusion in CVS - releases): - - We don't want to mess with all the portability hassles of alloca. - In particular, most (all?) versions of bison will use alloca in - their parser. If bison works on your system (e.g. it should work - with gcc), then go ahead and use it, but the more general solution - is to use byacc instead of bison, which should generate a portable - parser. I played with adding "#define alloca dont_use_alloca", to - give an error if the parser generator uses alloca (and thus detect - unportable getdate.c's), but that seems to cause as many problems - as it solves. */ - -extern struct tm *gmtime(); -extern struct tm *localtime(); - -#define yyparse getdate_yyparse -#define yylex getdate_yylex -#define yyerror getdate_yyerror - -static int yylex (); -static int yyerror (); - -#define EPOCH 1970 -#define HOUR(x) ((time_t)(x) * 60) -#define SECSPERDAY (24L * 60L * 60L) - - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - char *name; - int type; - time_t value; -} TABLE; - - -/* -** Daylight-savings mode: on, off, or not yet known. -*/ -typedef enum _DSTMODE { - DSTon, DSToff, DSTmaybe -} DSTMODE; - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of these by using a good -** union as the yacc stack. (This routine was originally written before -** yacc had the %union construct.) Maybe someday; right now we only use -** the %union very rarely. -*/ -static char *yyInput; -static DSTMODE yyDSTmode; -static time_t yyDayOrdinal; -static time_t yyDayNumber; -static int yyHaveDate; -static int yyHaveDay; -static int yyHaveRel; -static int yyHaveTime; -static int yyHaveZone; -static time_t yyTimezone; -static time_t yyDay; -static time_t yyHour; -static time_t yyMinutes; -static time_t yyMonth; -static time_t yySeconds; -static time_t yyYear; -static MERIDIAN yyMeridian; -static time_t yyRelMonth; -static time_t yyRelSeconds; - -%} - -%union { - time_t Number; - enum _MERIDIAN Meridian; -} - -%token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT -%token tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST - -%type <Number> tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT -%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE -%type <Meridian> tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; - } - | zone { - yyHaveZone++; - } - | date { - yyHaveDate++; - } - | day { - yyHaveDay++; - } - | rel { - yyHaveRel++; - } - | number - ; - -time : tUNUMBER tMERIDIAN { - yyHour = $1; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($4 % 100 + ($4 / 100) * 60); - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($6 % 100 + ($6 / 100) * 60); - } - ; - -zone : tZONE { - yyTimezone = $1; - yyDSTmode = DSToff; - } - | tDAYZONE { - yyTimezone = $1; - yyDSTmode = DSTon; - } - | - tZONE tDST { - yyTimezone = $1; - yyDSTmode = DSTon; - } - ; - -day : tDAY { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tDAY ',' { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tUNUMBER tDAY { - yyDayOrdinal = $1; - yyDayNumber = $2; - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - yyYear = $5; - } - | tUNUMBER tSNUMBER tSNUMBER { - /* ISO 8601 format. yyyy-mm-dd. */ - yyYear = $1; - yyMonth = -$2; - yyDay = -$3; - } - | tUNUMBER tMONTH tSNUMBER { - /* e.g. 17-JUN-1992. */ - yyDay = $1; - yyMonth = $2; - yyYear = -$3; - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - yyYear = $4; - } - | tUNUMBER tMONTH { - yyMonth = $2; - yyDay = $1; - } - | tUNUMBER tMONTH tUNUMBER { - yyMonth = $2; - yyDay = $1; - yyYear = $3; - } - ; - -rel : relunit tAGO { - yyRelSeconds = -yyRelSeconds; - yyRelMonth = -yyRelMonth; - } - | relunit - ; - -relunit : tUNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tSNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tMINUTE_UNIT { - yyRelSeconds += $1 * 60L; - } - | tSNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tSEC_UNIT { - yyRelSeconds++; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - ; - -number : tUNUMBER { - if (yyHaveTime && yyHaveDate && !yyHaveRel) - yyYear = $1; - else { - if($1>10000) { - yyHaveDate++; - yyDay= ($1)%100; - yyMonth= ($1/100)%100; - yyYear = $1/10000; - } - else { - yyHaveTime++; - if ($1 < 100) { - yyHour = $1; - yyMinutes = 0; - } - else { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = MER24; - } - } - } - ; - -o_merid : /* NULL */ { - $$ = MER24; - } - | tMERIDIAN { - $$ = $1; - } - ; - -%% - -/* Month and day table. */ -static TABLE const MonthDayTable[] = { - { N_("january"), tMONTH, 1 }, - { N_("february"), tMONTH, 2 }, - { N_("march"), tMONTH, 3 }, - { N_("april"), tMONTH, 4 }, - { N_("may"), tMONTH, 5 }, - { N_("june"), tMONTH, 6 }, - { N_("july"), tMONTH, 7 }, - { N_("august"), tMONTH, 8 }, - { N_("september"), tMONTH, 9 }, - { N_("sept"), tMONTH, 9 }, - { N_("october"), tMONTH, 10 }, - { N_("november"), tMONTH, 11 }, - { N_("december"), tMONTH, 12 }, - { N_("sunday"), tDAY, 0 }, - { N_("monday"), tDAY, 1 }, - { N_("tuesday"), tDAY, 2 }, - { N_("tues"), tDAY, 2 }, - { N_("wednesday"), tDAY, 3 }, - { N_("wednes"), tDAY, 3 }, - { N_("thursday"), tDAY, 4 }, - { N_("thur"), tDAY, 4 }, - { N_("thurs"), tDAY, 4 }, - { N_("friday"), tDAY, 5 }, - { N_("saturday"), tDAY, 6 }, - { NULL } -}; - -/* Time units table. */ -static TABLE const UnitsTable[] = { - { N_("year"), tMONTH_UNIT, 12 }, - { N_("month"), tMONTH_UNIT, 1 }, - { N_("fortnight"), tMINUTE_UNIT, 14 * 24 * 60 }, - { N_("week"), tMINUTE_UNIT, 7 * 24 * 60 }, - { N_("day"), tMINUTE_UNIT, 1 * 24 * 60 }, - { N_("hour"), tMINUTE_UNIT, 60 }, - { N_("minute"), tMINUTE_UNIT, 1 }, - { N_("min"), tMINUTE_UNIT, 1 }, - { N_("second"), tSEC_UNIT, 1 }, - { N_("sec"), tSEC_UNIT, 1 }, - { NULL } -}; - -/* Assorted relative-time words. */ -static TABLE const OtherTable[] = { - { N_("tomorrow"), tMINUTE_UNIT, 1 * 24 * 60 }, - { N_("yesterday"), tMINUTE_UNIT, -1 * 24 * 60 }, - { N_("today"), tMINUTE_UNIT, 0 }, - { N_("now"), tMINUTE_UNIT, 0 }, - { N_("last"), tUNUMBER, -1 }, - { N_("this"), tMINUTE_UNIT, 0 }, - { N_("next"), tUNUMBER, 2 }, - { N_("first"), tUNUMBER, 1 }, -/* { N_("second"), tUNUMBER, 2 }, */ - { N_("third"), tUNUMBER, 3 }, - { N_("fourth"), tUNUMBER, 4 }, - { N_("fifth"), tUNUMBER, 5 }, - { N_("sixth"), tUNUMBER, 6 }, - { N_("seventh"), tUNUMBER, 7 }, - { N_("eighth"), tUNUMBER, 8 }, - { N_("ninth"), tUNUMBER, 9 }, - { N_("tenth"), tUNUMBER, 10 }, - { N_("eleventh"), tUNUMBER, 11 }, - { N_("twelfth"), tUNUMBER, 12 }, - { N_("ago"), tAGO, 1 }, - { NULL } -}; - -/* The timezone table. */ -/* Some of these are commented out because a time_t can't store a float. */ -static TABLE const TimezoneTable[] = { - { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */ - { "utc", tZONE, HOUR( 0) }, - { "wet", tZONE, HOUR( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ - { "wat", tZONE, HOUR( 1) }, /* West Africa */ - { "at", tZONE, HOUR( 2) }, /* Azores */ -#if 0 - /* For completeness. BST is also British Summer, and GST is - * also Guam Standard. */ - { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ - { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ -#endif -#if 0 - { "nft", tZONE, HOUR(3.5) }, /* Newfoundland */ - { "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */ -#endif - { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */ - { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */ - { "est", tZONE, HOUR( 5) }, /* Eastern Standard */ - { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */ - { "cst", tZONE, HOUR( 6) }, /* Central Standard */ - { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */ - { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */ - { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */ - { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */ - { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */ - { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */ - { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */ - { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ - { "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */ - { "cat", tZONE, HOUR(10) }, /* Central Alaska */ - { "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */ - { "nt", tZONE, HOUR(11) }, /* Nome */ - { "idlw", tZONE, HOUR(12) }, /* International Date Line West */ - { "cet", tZONE, -HOUR(1) }, /* Central European */ - { "met", tZONE, -HOUR(1) }, /* Middle European */ - { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */ - { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */ - { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */ - { "fwt", tZONE, -HOUR(1) }, /* French Winter */ - { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */ - { "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */ - { "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */ -#if 0 - { "it", tZONE, -HOUR(3.5) },/* Iran */ -#endif - { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */ -#if 0 - { "ist", tZONE, -HOUR(5.5) },/* Indian Standard */ -#endif - { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */ -#if 0 - /* For completeness. NST is also Newfoundland Stanard, and SST is - * also Swedish Summer. */ - { "nst", tZONE, -HOUR(6.5) },/* North Sumatra */ - { "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */ -#endif /* 0 */ - { "wast", tZONE, -HOUR(7) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */ -#if 0 - { "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */ -#endif - { "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */ - { "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */ -#if 0 - { "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */ - { "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */ -#endif - { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ - { "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */ - { "nzt", tZONE, -HOUR(12) }, /* New Zealand */ - { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ - { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { NULL } -}; - -/* Military timezone table. */ -static TABLE const MilitaryTable[] = { - { "a", tZONE, HOUR( 1) }, - { "b", tZONE, HOUR( 2) }, - { "c", tZONE, HOUR( 3) }, - { "d", tZONE, HOUR( 4) }, - { "e", tZONE, HOUR( 5) }, - { "f", tZONE, HOUR( 6) }, - { "g", tZONE, HOUR( 7) }, - { "h", tZONE, HOUR( 8) }, - { "i", tZONE, HOUR( 9) }, - { "k", tZONE, HOUR( 10) }, - { "l", tZONE, HOUR( 11) }, - { "m", tZONE, HOUR( 12) }, - { "n", tZONE, HOUR(- 1) }, - { "o", tZONE, HOUR(- 2) }, - { "p", tZONE, HOUR(- 3) }, - { "q", tZONE, HOUR(- 4) }, - { "r", tZONE, HOUR(- 5) }, - { "s", tZONE, HOUR(- 6) }, - { "t", tZONE, HOUR(- 7) }, - { "u", tZONE, HOUR(- 8) }, - { "v", tZONE, HOUR(- 9) }, - { "w", tZONE, HOUR(-10) }, - { "x", tZONE, HOUR(-11) }, - { "y", tZONE, HOUR(-12) }, - { "z", tZONE, HOUR( 0) }, - { NULL } -}; - - - - -/* ARGSUSED */ -static int -yyerror(s) - char *s; -{ - return 0; -} - - -static time_t -ToSeconds(Hours, Minutes, Seconds, Meridian) - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; -{ - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) - return -1; - switch (Meridian) { - case MER24: - if (Hours < 0 || Hours > 23) - return -1; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERam: - if (Hours < 1 || Hours > 12) - return -1; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERpm: - if (Hours < 1 || Hours > 12) - return -1; - return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; - default: - abort (); - } - /* NOTREACHED */ -} - - -static time_t -Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) - time_t Month; - time_t Day; - time_t Year; - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; - DSTMODE DSTmode; -{ - static int DaysInMonth[12] = { - 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - time_t tod; - time_t Julian; - int i; - - if (Year < 0) - Year = -Year; - if (Year < 100) - Year += 1900; - DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) - ? 29 : 28; - if (Year < EPOCH || Year > 1999 - || Month < 1 || Month > 12 - /* Lint fluff: "conversion from long may lose accuracy" */ - || Day < 1 || Day > DaysInMonth[(int)--Month]) - return -1; - - for (Julian = Day - 1, i = 0; i < Month; i++) - Julian += DaysInMonth[i]; - for (i = EPOCH; i < Year; i++) - Julian += 365 + (i % 4 == 0); - Julian *= SECSPERDAY; - Julian += yyTimezone * 60L; - if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) - return -1; - Julian += tod; - if (DSTmode == DSTon - || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) - Julian -= 60 * 60; - return Julian; -} - - -static time_t -DSTcorrect(Start, Future) - time_t Start; - time_t Future; -{ - time_t StartDay; - time_t FutureDay; - - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; -} - - -static time_t -RelativeDate(Start, DayOrdinal, DayNumber) - time_t Start; - time_t DayOrdinal; - time_t DayNumber; -{ - struct tm *tm; - time_t now; - - now = Start; - tm = localtime(&now); - now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); - now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); - return DSTcorrect(Start, now); -} - - -static time_t -RelativeMonth(Start, RelMonth) - time_t Start; - time_t RelMonth; -{ - struct tm *tm; - time_t Month; - time_t Year; - - if (RelMonth == 0) - return 0; - tm = localtime(&Start); - Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; - Year = Month / 12; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - MER24, DSTmaybe)); -} - - -static int -LookupWord(buff) - char *buff; -{ - register char *p; - register char *q; - register const TABLE *tp; - int i; - int abbrev; - - /* Make it lowercase. */ - for (p = buff; *p; p++) - if (isupper(*p)) - *p = tolower(*p); - - if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) { - yylval.Meridian = MERam; - return tMERIDIAN; - } - if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { - yylval.Meridian = MERpm; - return tMERIDIAN; - } - - /* See if we have an abbreviation for a month. */ - if (strlen(buff) == 3) - abbrev = 1; - else if (strlen(buff) == 4 && buff[3] == '.') { - abbrev = 1; - buff[3] = '\0'; - } - else - abbrev = 0; - - for (tp = MonthDayTable; tp->name; tp++) { - if (abbrev) { - if (strncmp(buff, tp->name, 3) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - else if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - if (strcmp(buff, "dst") == 0) - return tDST; - - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - i = strlen(buff) - 1; - if (buff[i] == 's') { - buff[i] = '\0'; - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ - } - - for (tp = OtherTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Military timezones. */ - if (buff[1] == '\0' && isalpha(*buff)) { - for (tp = MilitaryTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - /* Drop out any periods and try the timezone table again. */ - for (i = 0, p = q = buff; *q; q++) - if (*q != '.') - *p++ = *q; - else - i++; - *p = '\0'; - if (i) - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - return tID; -} - - -static int -yylex() -{ - register char c; - register char *p; - char buff[20]; - int Count; - int sign; - - for ( ; ; ) { - while (isspace(*yyInput)) - yyInput++; - - if (isdigit(c = *yyInput) || c == '-' || c == '+') { - if (c == '-' || c == '+') { - sign = c == '-' ? -1 : 1; - if (!isdigit(*++yyInput)) - /* skip the '-' sign */ - continue; - } - else - sign = 0; - for (yylval.Number = 0; isdigit(c = *yyInput++); ) - yylval.Number = 10 * yylval.Number + c - '0'; - yyInput--; - if (sign < 0) - yylval.Number = -yylval.Number; - return sign ? tSNUMBER : tUNUMBER; - } - if (isalpha(c)) { - for (p = buff; isalpha(c = *yyInput++) || c == '.'; ) - if (p < &buff[sizeof buff - 1]) - *p++ = c; - *p = '\0'; - yyInput--; - return LookupWord(buff); - } - if (c != '(') - return *yyInput++; - Count = 0; - do { - c = *yyInput++; - if (c == '\0') - return c; - if (c == '(') - Count++; - else if (c == ')') - Count--; - } while (Count > 0); - } -} - -#define TM_YEAR_ORIGIN 1900 - -/* Yield A - B, measured in seconds. */ -static long -difftm (a, b) - struct tm *a, *b; -{ - int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); - int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - int days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay/100 - by/100) - + ((ay/100 >> 2) - (by/100 >> 2)) - /* + difference in years * 365 */ - + (long)(ay-by) * 365 - ); - return (60*(60*(24*days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec)); -} - -time_t -get_date(p, now) - char *p; - struct timeb *now; -{ - struct tm *tm, gmt; - struct timeb ftz; - time_t Start; - time_t tod; - time_t nowtime; - - yyInput = p; - if (now == NULL) { - now = &ftz; - (void)time (&nowtime); - - if (! (tm = gmtime (&nowtime))) - return -1; - gmt = *tm; /* Make a copy, in case localtime modifies *tm. */ - - if (! (tm = localtime (&nowtime))) - return -1; - - ftz.timezone = difftm (&gmt, tm) / 60; - if(tm->tm_isdst) - ftz.timezone += 60; - } - else - { - nowtime = now->time; - } - - tm = localtime(&nowtime); - yyYear = tm->tm_year; - yyMonth = tm->tm_mon + 1; - yyDay = tm->tm_mday; - yyTimezone = now->timezone; - yyDSTmode = DSTmaybe; - yyHour = 0; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMonth = 0; - yyHaveDate = 0; - yyHaveDay = 0; - yyHaveRel = 0; - yyHaveTime = 0; - yyHaveZone = 0; - - if (yyparse() - || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1) - return -1; - - if (yyHaveDate || yyHaveTime || yyHaveDay) { - Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, - yyMeridian, yyDSTmode); - if (Start < 0) - return -1; - } - else { - Start = nowtime; - if (!yyHaveRel) - Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec; - } - - Start += yyRelSeconds; - Start += RelativeMonth(Start, yyRelMonth); - - if (yyHaveDay && !yyHaveDate) { - tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber); - Start += tod; - } - - /* Have to do *something* with a legitimate -1 so it's distinguishable - * from the error return value. (Alternately could set errno on error.) */ - return Start == -1 ? 0 : Start; -} - - -#if defined(TEST) - -/* ARGSUSED */ -int -main(ac, av) - int ac; - char *av[]; -{ - char buff[128]; - time_t d; - - (void)printf("Enter date, or blank line to exit.\n\t> "); - (void)fflush(stdout); - while (gets(buff) && buff[0]) { - d = get_date(buff, (struct timeb *)NULL); - if (d == -1) - (void)printf("Bad format - couldn't convert.\n"); - else - (void)printf("%s", ctime(&d)); - (void)printf("\t> "); - (void)fflush(stdout); - } - exit(0); - /* NOTREACHED */ -} -#endif /* defined(TEST) */ diff --git a/calendar/gncal-day-panel.c b/calendar/gncal-day-panel.c deleted file mode 100644 index 8d21b6fabc..0000000000 --- a/calendar/gncal-day-panel.c +++ /dev/null @@ -1,277 +0,0 @@ -/* Day view notebook panel for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <config.h> -#include <gnome.h> -#include <gtk/gtkhseparator.h> -#include "gncal-day-panel.h" -#include "main.h" -#include "cal-util/timeutil.h" - - -guint -gncal_day_panel_get_type (void) -{ - static guint day_panel_type = 0; - - if (!day_panel_type) { - GtkTypeInfo day_panel_info = { - "GncalDayPanel", - sizeof (GncalDayPanel), - sizeof (GncalDayPanelClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) NULL, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - day_panel_type = gtk_type_unique (gtk_table_get_type (), &day_panel_info); - } - - return day_panel_type; -} - -static void -day_view_range_activated (GncalFullDay *fullday, GncalDayPanel *dpanel) -{ - iCalObject *ical; - - ical = ical_new ("", user_name, ""); - ical->new = 1; - - gncal_full_day_selection_range (fullday, &ical->dtstart, &ical->dtend); - - gnome_calendar_add_object (dpanel->calendar, ical); - save_default_calendar (dpanel->calendar); - gncal_full_day_focus_child (fullday, ical); -} - -static void -full_day_size_allocated (GtkWidget *widget, GtkAllocation *allocation, GncalDayPanel *dpanel) -{ - GtkAdjustment *adj; - int yoffset; - gfloat newval; - - adj = gtk_scrolled_window_get_vadjustment (dpanel->fullday_sw); - - yoffset = gncal_full_day_get_day_start_yoffset (GNCAL_FULL_DAY (widget)); - - newval = adj->lower + (adj->upper - adj->lower) * (double) yoffset / allocation->height; - if (newval != adj->value) - gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); -} - -static void -calendar_day_selected (GtkCalendar *calendar, GncalDayPanel *dpanel) -{ - gint y, m, d; - struct tm tm; - - gtk_calendar_get_date (calendar, &y, &m, &d); - - tm.tm_year = y - 1900; - tm.tm_mon = m; - tm.tm_mday = d; - tm.tm_hour = 5; /* for daylight savings time fix */ - tm.tm_min = 0; - tm.tm_sec = 0; - - gnome_calendar_goto (dpanel->calendar, mktime (&tm)); -} - -static void -retag_calendar (GtkCalendar *calendar, GncalDayPanel *dpanel) -{ - gnome_calendar_tag_calendar (dpanel->calendar, GTK_CALENDAR (dpanel->gtk_calendar)); -} - -GtkWidget * -gncal_day_panel_new (GnomeCalendar *calendar, time_t start_of_day) -{ - GncalDayPanel *dpanel; - GtkWidget *w; - GtkWidget *hpane, *vpane; - gint start_pos = 265; - struct tm tm; - - g_return_val_if_fail (calendar != NULL, NULL); - - dpanel = gtk_type_new (gncal_day_panel_get_type ()); - - gtk_container_border_width (GTK_CONTAINER (dpanel), 4); - gtk_table_set_row_spacings (GTK_TABLE (dpanel), 4); - gtk_table_set_col_spacings (GTK_TABLE (dpanel), 4); - - dpanel->calendar = calendar; - - /* Date label */ - - w = gtk_label_new (""); - dpanel->date_label = GTK_LABEL (w); - gtk_table_attach (GTK_TABLE (dpanel), w, - 0, 1, 0, 1, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - /* Create horizontal pane */ - - hpane = gtk_hpaned_new (); - gtk_table_attach (GTK_TABLE (dpanel), hpane, - 0, 1, 2, 4, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - - /* Full day */ - - w = gtk_scrolled_window_new (NULL, NULL); - dpanel->fullday_sw = GTK_SCROLLED_WINDOW (w); - gtk_scrolled_window_set_policy (dpanel->fullday_sw, - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_paned_pack1 (GTK_PANED (hpane), w, FALSE, TRUE); - /*gtk_paned_add1 (GTK_PANED (hpane), w);*/ - gtk_widget_show (w); - - w = gncal_full_day_new (calendar, time_day_begin (start_of_day), time_day_end (start_of_day)); - dpanel->fullday = GNCAL_FULL_DAY (w); - gtk_signal_connect (GTK_OBJECT (dpanel->fullday), "range_activated", - (GtkSignalFunc) day_view_range_activated, - dpanel); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (dpanel->fullday_sw), w); - gtk_widget_show (w); - - /* We'll scroll the list to the proper initial position */ - - gtk_signal_connect (GTK_OBJECT (dpanel->fullday), "size_allocate", - (GtkSignalFunc) full_day_size_allocated, - dpanel); - - /* Create vertical pane */ - - vpane = gtk_vpaned_new (); - gtk_paned_pack2 (GTK_PANED (hpane), GTK_WIDGET (vpane), TRUE, TRUE); - /*gtk_paned_add2 (GTK_PANED (hpane), GTK_WIDGET (vpane));*/ - - /* Gtk calendar */ - - tm = *localtime (&start_of_day); - - w = gtk_calendar_new (); - dpanel->gtk_calendar = GTK_CALENDAR (w); - gtk_calendar_display_options (dpanel->gtk_calendar, - (GTK_CALENDAR_SHOW_HEADING - | GTK_CALENDAR_SHOW_DAY_NAMES - | (week_starts_on_monday - ? GTK_CALENDAR_WEEK_START_MONDAY : 0))); - gtk_calendar_select_month (dpanel->gtk_calendar, tm.tm_mon, tm.tm_year + 1900); - gtk_calendar_select_day (dpanel->gtk_calendar, tm.tm_mday); - dpanel->day_selected_id = gtk_signal_connect (GTK_OBJECT (dpanel->gtk_calendar), - "day_selected_double_click", - (GtkSignalFunc) calendar_day_selected, - dpanel); - gtk_signal_connect (GTK_OBJECT (dpanel->gtk_calendar), "month_changed", - GTK_SIGNAL_FUNC (retag_calendar), dpanel); - gtk_paned_add1 (GTK_PANED (vpane), w); - gtk_widget_show (w); - - /* To-do */ - - w = gncal_todo_new (calendar); - dpanel->todo = GNCAL_TODO (w); - gtk_paned_add2 (GTK_PANED (vpane), w); - gtk_widget_show (w); - - /* Done */ - - gncal_day_panel_set (dpanel, start_of_day); - - gtk_paned_set_position (GTK_PANED (hpane), start_pos); - - return GTK_WIDGET (dpanel); -} - -static void -update (GncalDayPanel *dpanel, int update_fullday, iCalObject *ico, int flags) -{ - char buf [80]; - - if (update_fullday){ - gncal_full_day_update (dpanel->fullday, ico, flags); - retag_calendar (dpanel->gtk_calendar, dpanel); - } - gncal_todo_update (dpanel->todo, ico, flags); - - strftime (buf, sizeof (buf), _("%a %b %d %Y"), localtime (&dpanel->start_of_day)); - gtk_label_set (GTK_LABEL (dpanel->date_label), buf); -} - -void -gncal_day_panel_update (GncalDayPanel *dpanel, iCalObject *ico, int flags) -{ - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - update (dpanel, TRUE, ico, flags); -} - -void -gncal_day_panel_set (GncalDayPanel *dpanel, time_t start_of_day) -{ - char buf[80]; - struct tm tm; - - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - dpanel->start_of_day = time_day_begin(start_of_day); - if (dpanel->fullday->lower == dpanel->start_of_day) - return; - - tm = *localtime (&dpanel->start_of_day); - strftime (buf, sizeof (buf), _("%a %b %d %Y"), &tm); - gtk_label_set (GTK_LABEL (dpanel->date_label), buf); - - gncal_full_day_set_bounds (dpanel->fullday, dpanel->start_of_day, time_day_end (dpanel->start_of_day)); - - gtk_calendar_select_month (dpanel->gtk_calendar, tm.tm_mon, tm.tm_year + 1900); - - gtk_signal_handler_block (GTK_OBJECT (dpanel->gtk_calendar), dpanel->day_selected_id); - gtk_calendar_select_day (dpanel->gtk_calendar, tm.tm_mday); - gtk_signal_handler_unblock (GTK_OBJECT (dpanel->gtk_calendar), dpanel->day_selected_id); - - update (dpanel, FALSE, NULL, 0); -} - -void -gncal_day_panel_time_format_changed (GncalDayPanel *dpanel) -{ - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - gtk_calendar_display_options (dpanel->gtk_calendar, - (week_starts_on_monday - ? (dpanel->gtk_calendar->display_flags - | GTK_CALENDAR_WEEK_START_MONDAY) - : (dpanel->gtk_calendar->display_flags - & ~GTK_CALENDAR_WEEK_START_MONDAY))); -} - -void -todo_list_properties_changed (GncalDayPanel *dpanel) -{ - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - gncal_todo_update (dpanel->todo, NULL, 0); -} - - - diff --git a/calendar/gncal-day-panel.h b/calendar/gncal-day-panel.h deleted file mode 100644 index 6bf8768d9c..0000000000 --- a/calendar/gncal-day-panel.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Day view notebook panel for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_DAY_PANEL_H -#define GNCAL_DAY_PANEL_H - -#include <gtk/gtklabel.h> -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtktable.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gncal-full-day.h" -#include "gncal-todo.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_DAY_PANEL(obj) GTK_CHECK_CAST (obj, gncal_day_panel_get_type (), GncalDayPanel) -#define GNCAL_DAY_PANEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_panel_get_type (), GncalDayPanelClass) -#define GNCAL_IS_DAY_PANEL(obj) GTK_CHECK_TYPE (obj, gncal_day_panel_get_type ()) - - -typedef struct _GncalDayPanel GncalDayPanel; -typedef struct _GncalDayPanelClass GncalDayPanelClass; - -struct _GncalDayPanel { - GtkTable table; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - time_t start_of_day; - - GtkLabel *date_label; - GncalFullDay *fullday; - GtkScrolledWindow *fullday_sw; - GtkCalendar *gtk_calendar; - GncalTodo *todo; - - guint day_selected_id; -}; - -struct _GncalDayPanelClass { - GtkTableClass parent_class; -}; - - -guint gncal_day_panel_get_type (void); -GtkWidget *gncal_day_panel_new (GnomeCalendar *calendar, time_t start_of_day); - -void gncal_day_panel_update (GncalDayPanel *dpanel, iCalObject *ico, int flags); -void gncal_day_panel_set (GncalDayPanel *dpanel, time_t start_of_day); -void gncal_day_panel_time_format_changed (GncalDayPanel *dpanel); - -void todo_list_properties_changed (GncalDayPanel *dpanel); - - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gncal-day-view.c b/calendar/gncal-day-view.c deleted file mode 100644 index 955aac0ef9..0000000000 --- a/calendar/gncal-day-view.c +++ /dev/null @@ -1,411 +0,0 @@ -/* Day view widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <gnome.h> -#include "gncal-day-view.h" -#include "cal-util/timeutil.h" -#include "view-utils.h" -#include "main.h" -#include "eventedit.h" -#include "popup-menu.h" -#include "quick-view.h" - -#define TEXT_BORDER 2 -#define MIN_INFO_WIDTH 50 - - -static void gncal_day_view_class_init (GncalDayViewClass *class); -static void gncal_day_view_init (GncalDayView *dview); -static void gncal_day_view_destroy (GtkObject *object); -static void gncal_day_view_realize (GtkWidget *widget); -static void gncal_day_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static gint gncal_day_view_expose (GtkWidget *widget, - GdkEventExpose *event); -static gint gncal_day_view_button_press (GtkWidget *widget, - GdkEventButton *event); - - -static GtkWidgetClass *parent_class; - - -guint -gncal_day_view_get_type (void) -{ - static guint day_view_type = 0; - - if (!day_view_type) { - GtkTypeInfo day_view_info = { - "GncalDayView", - sizeof (GncalDayView), - sizeof (GncalDayViewClass), - (GtkClassInitFunc) gncal_day_view_class_init, - (GtkObjectInitFunc) gncal_day_view_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - day_view_type = gtk_type_unique (gtk_widget_get_type (), &day_view_info); - } - - return day_view_type; -} - -static void -gncal_day_view_class_init (GncalDayViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gtk_widget_get_type ()); - - object_class->destroy = gncal_day_view_destroy; - - widget_class->realize = gncal_day_view_realize; - widget_class->size_request = gncal_day_view_size_request; - widget_class->expose_event = gncal_day_view_expose; - widget_class->button_press_event = gncal_day_view_button_press; -} - -static void -gncal_day_view_init (GncalDayView *dview) -{ - GTK_WIDGET_UNSET_FLAGS (dview, GTK_NO_WINDOW); - - dview->calendar = NULL; - - dview->lower = 0; - dview->upper = 0; - - dview->shadow_type = GTK_SHADOW_ETCHED_IN; -} - -static void -gncal_day_view_destroy (GtkObject *object) -{ - GncalDayView *dview; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (object)); - - dview = GNCAL_DAY_VIEW (object); - - if (dview->day_str) - g_free (dview->day_str); - if (dview->events) - calendar_destroy_event_list (dview->events); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static int -new_appointment (GtkWidget *widget, gpointer data) -{ - GncalDayView *dayview = GNCAL_DAY_VIEW (data); - iCalObject *ico; - GtkWidget *ee; - struct tm tm; - - ico = ical_new ("", user_name, ""); - ico->new = 1; - - tm = *localtime (&dayview->lower); - tm.tm_hour = day_begin; - ico->dtstart = mktime (&tm); - tm.tm_hour++; - ico->dtend = mktime (&tm); - ee = event_editor_new (dayview->calendar, ico); - gtk_widget_show (ee); - return 1; -} - -static void -context_menu (GncalDayView *dayview, GdkEventButton *event) -{ - static struct menu_item main_items[] = { - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - main_items [0].data = dayview; - popup_menu (main_items, 1, event); -} - -static gint -gncal_day_view_button_press (GtkWidget *widget, GdkEventButton *event) -{ - GncalDayView *dayview; - - dayview = GNCAL_DAY_VIEW (widget); - - if (event->button == 3) - context_menu (dayview, event); - - if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) - gnome_calendar_dayjump (dayview->calendar, dayview->lower); - -#if 0 - else if (event->button == 1 && event->type == GDK_BUTTON_PRESS) { - time_t day_begin_time, day_end_time; - GList *list; - GtkWidget *qv; - char date_str [256]; - - strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), - localtime (&dayview->lower)); - qv = quick_view_new (dayview->calendar, date_str, dayview->events); - quick_view_do_popup (QUICK_VIEW (qv), event); - gtk_widget_destroy (qv); - } -#endif - - return TRUE; -} - -GtkWidget * -gncal_day_view_new (GnomeCalendar *calendar, time_t lower, time_t upper) -{ - GncalDayView *dview; - - g_return_val_if_fail (calendar != NULL, NULL); - - dview = gtk_type_new (gncal_day_view_get_type ()); - - dview->calendar = calendar; - dview->lower = lower; - dview->upper = upper; - dview->events = 0; - - gncal_day_view_update (dview, NULL, 0); - - return GTK_WIDGET (dview); -} - -static void -gncal_day_view_realize (GtkWidget *widget) -{ - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = (gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - - gdk_window_set_background (widget->window, &widget->style->bg[GTK_STATE_PRELIGHT]); -} - -static void -gncal_day_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GncalDayView *dview; - int str_width, width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - dview = GNCAL_DAY_VIEW (widget); - - /* border and min width */ - - str_width = gdk_string_width (widget->style->font, dview->day_str); - - width = MAX (MIN_INFO_WIDTH, str_width); - - requisition->width = 2 * (widget->style->klass->xthickness + TEXT_BORDER) + width; - requisition->height = 2 * (widget->style->klass->ythickness + TEXT_BORDER); - - /* division line */ - - requisition->height += 2 * TEXT_BORDER + widget->style->klass->ythickness; - - /* title and at least one line of text */ - - requisition->height += 2 * (widget->style->font->ascent + widget->style->font->descent); -} - -static gint -gncal_day_view_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GncalDayView *dview; - int x1, y1, width, height; - GdkRectangle rect, dest; - GdkFont *font; - int str_width; - GdkGC *gc; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_DAY_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return FALSE; - - gc = widget->style->fg_gc [GTK_STATE_NORMAL]; - dview = GNCAL_DAY_VIEW (widget); - - x1 = widget->style->klass->xthickness; - y1 = widget->style->klass->ythickness; - width = widget->allocation.width - 2 * x1; - height = widget->allocation.height - 2 * y1; - - /* Clear and paint frame shadow */ - - gdk_window_clear_area (widget->window, - event->area.x, event->area.y, - event->area.width, event->area.height); - - gtk_draw_shadow (widget->style, widget->window, - GTK_STATE_NORMAL, dview->shadow_type, - 0, 0, - widget->allocation.width, - widget->allocation.height); - - /* Clear and paint title */ - - font = widget->style->font; - - rect.x = x1; - rect.y = y1; - rect.width = width; - rect.height = 2 * TEXT_BORDER + font->ascent + font->descent; - - if (gdk_rectangle_intersect (&rect, &event->area, &dest)) { - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - dest = rect; - - dest.x += TEXT_BORDER; - dest.y += TEXT_BORDER; - dest.width -= 2 * TEXT_BORDER; - dest.height -= 2 * TEXT_BORDER; - - gdk_gc_set_clip_rectangle (gc, &dest); - - str_width = gdk_string_width (font, dview->day_str); - - gdk_draw_string (widget->window, font, gc, - dest.x + (dest.width - str_width) / 2, - dest.y + font->ascent, - dview->day_str); - - gdk_gc_set_clip_rectangle (gc, NULL); - } - - /* Division line */ - - gtk_draw_hline (widget->style, - widget->window, - GTK_STATE_NORMAL, - rect.x, - rect.x + rect.width - 1, - rect.y + rect.height); - - /* Text */ - - if (dview->events != NULL){ - rect.x = x1 + TEXT_BORDER; - rect.y = y1 + 3 * TEXT_BORDER + - font->ascent + font->descent + - widget->style->klass->ythickness; - rect.width = width - 2 * TEXT_BORDER; - rect.height = height - (rect.y - y1) - TEXT_BORDER; - - if (gdk_rectangle_intersect (&rect, &event->area, &dest)) - view_utils_draw_events ( - widget, widget->window, gc, - &rect, - VIEW_UTILS_DRAW_END | VIEW_UTILS_DRAW_SPLIT, - dview->events, - dview->lower, - dview->upper); - } - - return FALSE; -} - -void -gncal_day_view_update (GncalDayView *dview, iCalObject *ico, int flags) -{ - struct tm tm; - char buf[256]; - - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - g_return_if_fail (dview->calendar->cal); - - if (dview->day_str) - g_free (dview->day_str); - - tm = *localtime (&dview->lower); - strftime (buf, sizeof (buf)-1, "%A %d", &tm); - dview->day_str = g_strdup (buf); - - if (dview->events) - calendar_destroy_event_list (dview->events); - - dview->events = calendar_get_events_in_range (dview->calendar->cal, - dview->lower, - dview->upper); - - gtk_widget_draw (GTK_WIDGET (dview), NULL); -} - -void -gncal_day_view_set_bounds (GncalDayView *dview, time_t lower, time_t upper) -{ - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - - if ((lower != dview->lower) || (upper != dview->upper)) { - dview->lower = lower; - dview->upper = upper; - - gncal_day_view_update (dview, NULL, 0); - } -} - -void -gncal_day_view_set_shadow (GncalDayView *dview, GtkShadowType shadow_type) -{ - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - - if (shadow_type != dview->shadow_type) { - dview->shadow_type = shadow_type; - - gtk_widget_draw (GTK_WIDGET (dview), NULL); - } -} diff --git a/calendar/gncal-day-view.h b/calendar/gncal-day-view.h deleted file mode 100644 index dae1897fb6..0000000000 --- a/calendar/gncal-day-view.h +++ /dev/null @@ -1,56 +0,0 @@ -/* Day view widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_DAY_VIEW_H -#define GNCAL_DAY_VIEW_H - - -#include <gtk/gtkwidget.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - -BEGIN_GNOME_DECLS - - -#define GNCAL_DAY_VIEW(obj) GTK_CHECK_CAST (obj, gncal_day_view_get_type (), GncalDayView) -#define GNCAL_DAY_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_view_get_type (), GncalDayViewClass) -#define GNCAL_IS_DAY_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_day_view_get_type ()) - - -typedef struct _GncalDayView GncalDayView; -typedef struct _GncalDayViewClass GncalDayViewClass; - -struct _GncalDayView { - GtkWidget widget; - - GnomeCalendar *calendar;/* the calendar we are associated to */ - - time_t lower; /* lower and upper times to display */ - time_t upper; /* these include the full day */ - - char *day_str; /* what day is it? */ - GList *events; /* the events for the this day */ - GtkShadowType shadow_type; -}; - -struct _GncalDayViewClass { - GtkWidgetClass parent_class; -}; - - -guint gncal_day_view_get_type (void); -GtkWidget *gncal_day_view_new (GnomeCalendar *calendar, time_t lower, time_t upper); - -void gncal_day_view_update (GncalDayView *dview, iCalObject *ico, int flags); -void gncal_day_view_set_bounds (GncalDayView *dview, time_t lower, time_t upper); - -void gncal_day_view_set_shadow (GncalDayView *dview, GtkShadowType shadow_type); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gncal-full-day.c b/calendar/gncal-full-day.c deleted file mode 100644 index c07d9a5710..0000000000 --- a/calendar/gncal-full-day.c +++ /dev/null @@ -1,2287 +0,0 @@ -/* Full day widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ -#include <config.h> -#include <string.h> -#include <gdk/gdkkeysyms.h> -#include <gnome.h> -#include "eventedit.h" -#include "gncal-full-day.h" -#include "view-utils.h" -#include "layout.h" -#include "main.h" -#include "popup-menu.h" - -/* Images */ -#include "bell.xpm" -#include "recur.xpm" - -#define TEXT_BORDER 2 -#define HANDLE_SIZE 8 -#define MIN_WIDTH 200 -#define XOR_RECT_WIDTH 2 -#define UNSELECT_TIMEOUT 0 /* ms */ - -/* Size of the pixmaps */ -#define DECOR_WIDTH 16 -#define DECOR_HEIGHT 16 - -typedef struct { - iCalObject *ico; - GtkWidget *widget; - GdkWindow *window; - GdkWindow *decor_window; - guint focus_out_id; - int lower_row; /* zero is first displayed row */ - int rows_used; - int x; /* coords of child's window */ - int y; - int width; - int height; - int decor_width; - int decor_height; - int items; /* number of decoration bitmaps */ - time_t start, end; -} Child; - -struct drag_info { - enum { - DRAG_NONE, - DRAG_SELECT, /* selecting a range in the main window */ - DRAG_MOVE, /* moving a child */ - DRAG_SIZE_TOP, /* resizing a child */ - DRAG_SIZE_BOTTOM - } drag_mode; - - Child *child; - int child_click_y; - int child_start_row; - int child_rows_used; - - int sel_click_row; - int sel_start_row; - int sel_rows_used; - guint32 click_time; -}; - - -enum { - RANGE_ACTIVATED, - LAST_SIGNAL -}; - - -static void gncal_full_day_class_init (GncalFullDayClass *class); -static void gncal_full_day_init (GncalFullDay *fullday); -static void gncal_full_day_destroy (GtkObject *object); -static void gncal_full_day_map (GtkWidget *widget); -static void gncal_full_day_unmap (GtkWidget *widget); -static void gncal_full_day_realize (GtkWidget *widget); -static void gncal_full_day_unrealize (GtkWidget *widget); -static void gncal_full_day_draw (GtkWidget *widget, - GdkRectangle *area); -static void gncal_full_day_draw_focus (GtkWidget *widget); -static void gncal_full_day_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void gncal_full_day_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint gncal_full_day_button_press (GtkWidget *widget, - GdkEventButton *event); -static gint gncal_full_day_button_release (GtkWidget *widget, - GdkEventButton *event); -static gint gncal_full_day_motion (GtkWidget *widget, - GdkEventMotion *event); -static gint gncal_full_day_expose (GtkWidget *widget, - GdkEventExpose *event); -static gint gncal_full_day_key_press (GtkWidget *widget, - GdkEventKey *event); -static gint gncal_full_day_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint gncal_full_day_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static void gncal_full_day_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void range_activated (GncalFullDay *fullday); - -static GtkContainerClass *parent_class; - -static int fullday_signals[LAST_SIGNAL] = { 0 }; - -/* The little images */ -static GdkPixmap *pixmap_bell, *pixmap_recur; - -static void -get_tm_range (GncalFullDay *fullday, - time_t time_lower, time_t time_upper, - struct tm *lower, struct tm *upper, - int *lower_row, int *rows_used) -{ - struct tm tm_lower, tm_upper; - int lmin, umin; - int lrow; - - /* Lower */ - - tm_lower = *localtime (&time_lower); - - if ((tm_lower.tm_min % fullday->interval) != 0) { - tm_lower.tm_min -= tm_lower.tm_min % fullday->interval; /* round down */ - mktime (&tm_lower); - } - - /* Upper */ - - tm_upper = *localtime (&time_upper); - - if ((tm_upper.tm_min % fullday->interval) != 0) { - tm_upper.tm_min += fullday->interval - (tm_upper.tm_min % fullday->interval); /* round up */ - mktime (&tm_upper); - } - - if (lower) - *lower = tm_lower; - - if (upper) - *upper = tm_upper; - - lmin = 60 * tm_lower.tm_hour + tm_lower.tm_min; - umin = 60 * tm_upper.tm_hour + tm_upper.tm_min; - - if (umin == 0) /* midnight of next day? */ - umin = 60 * 24; - - lrow = lmin / fullday->interval; - - if (lower_row) - *lower_row = lrow; - - if (rows_used) - *rows_used = (umin - lmin) / fullday->interval; -} - -static void -child_map (GncalFullDay *fullday, Child *child) -{ - gdk_window_show (child->window); - if (child->decor_width) - gdk_window_show (child->decor_window); - gtk_widget_show (child->widget); /* OK, not just a map... */ -} - -static void -child_unmap (GncalFullDay *fullday, Child *child) -{ - gdk_window_hide (child->window); - gdk_window_hide (child->decor_window); - if (GTK_WIDGET_MAPPED (child->widget)) - gtk_widget_unmap (child->widget); -} - -static void -child_set_text_pos (Child *child) -{ - GtkAllocation allocation; - int has_focus; - int handle_size; - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - handle_size = (child->ico->recur) ? 0 : HANDLE_SIZE; - - allocation.x = handle_size; - allocation.y = has_focus ? handle_size : 0; - allocation.width = child->width - handle_size - child->decor_width; - allocation.height = child->height - (has_focus ? (2 * handle_size) : 0); - - gtk_widget_size_request (child->widget, NULL); - gtk_widget_size_allocate (child->widget, &allocation); -} - -static void -child_realize (GncalFullDay *fullday, Child *child) -{ - GdkWindowAttr attributes; - gint attributes_mask; - GtkWidget *widget; - GdkColor c; - - widget = GTK_WIDGET (fullday); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = child->x; - attributes.y = child->y; - attributes.width = child->width - child->decor_width;; - attributes.height = child->height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.cursor = fullday->up_down_cursor; - attributes.event_mask = (GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_KEY_PRESS_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR; - child->window = gdk_window_new (widget->window, &attributes, attributes_mask); - gdk_window_set_user_data (child->window, widget); - gtk_style_set_background (widget->style, child->window, GTK_STATE_NORMAL); - gtk_widget_set_parent_window (child->widget, child->window); - - /* Create the decoration window */ - attributes.x = child->x + child->width - child->decor_width; - attributes.width = child->decor_width ? child->decor_width : 1; - attributes.height = child->decor_height ? child->decor_height : 1; - attributes.visual = gdk_imlib_get_visual (); - attributes.colormap = gdk_imlib_get_colormap (); - attributes.event_mask = (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - child->decor_window = gdk_window_new (widget->window, &attributes, attributes_mask); - gdk_color_white (gdk_imlib_get_colormap (), &c); - gdk_window_set_background (child->decor_window, &c); - gdk_window_set_user_data (child->decor_window, widget); - - if (!pixmap_bell){ - GdkImlibImage *imlib_bell, *imlib_recur; - GdkPixmap *mask; - - imlib_bell = gdk_imlib_create_image_from_xpm_data (bell_xpm); - gdk_imlib_render (imlib_bell, DECOR_WIDTH, DECOR_HEIGHT); - pixmap_bell = gdk_imlib_move_image (imlib_bell); - mask = gdk_imlib_move_mask (imlib_bell); - gdk_imlib_destroy_image (imlib_bell); - fullday->bell_gc = gdk_gc_new (child->decor_window); - if (mask) - gdk_gc_set_clip_mask (fullday->bell_gc, mask); - - imlib_recur = gdk_imlib_create_image_from_xpm_data (recur_xpm); - gdk_imlib_render (imlib_recur, DECOR_WIDTH, DECOR_HEIGHT); - pixmap_recur = gdk_imlib_move_image (imlib_recur); - mask = gdk_imlib_move_mask (imlib_recur); - gdk_imlib_destroy_image (imlib_recur); - fullday->recur_gc = gdk_gc_new (child->decor_window); - if (mask) - gdk_gc_set_clip_mask (fullday->recur_gc, mask); - } - child_set_text_pos (child); -} - -static void -child_unrealize (GncalFullDay *fullday, Child *child) -{ - if (GTK_WIDGET_REALIZED (child->widget)) - gtk_widget_unrealize (child->widget); - - gdk_window_set_user_data (child->window, NULL); - gdk_window_destroy (child->window); - child->window = NULL; -} - -static void -child_draw_decor (GncalFullDay *fullday, Child *child) -{ - iCalObject *ico = child->ico; - int ry = 0; - - if (ico->recur) { - gdk_gc_set_clip_origin (fullday->recur_gc, 0, ry); - gdk_draw_pixmap (child->decor_window, - fullday->recur_gc, - pixmap_recur, - 0, 0, - 0, ry, - DECOR_WIDTH, DECOR_HEIGHT); - ry += DECOR_HEIGHT; - } - - if (ico->dalarm.enabled || ico->malarm.enabled || ico->palarm.enabled || ico->aalarm.enabled) { - gdk_gc_set_clip_origin (fullday->bell_gc, 0, ry); - gdk_draw_pixmap (child->decor_window, - fullday->bell_gc, - pixmap_bell, - 0, 0, - 0, ry, - DECOR_WIDTH, DECOR_HEIGHT); - ry += DECOR_HEIGHT; - } -} - -static void -child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, GdkWindow *window, int draw_child) -{ - GdkRectangle arect, rect, dest; - int has_focus; - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - if (!window || (window == child->window)) { - if (!area) { - arect.x = 0; - arect.y = 0; - arect.width = child->width; - arect.height = child->height; - - area = &arect; - } - - /* Left handle */ - - rect.x = 0; - rect.y = has_focus ? HANDLE_SIZE : 0; - rect.width = HANDLE_SIZE; - rect.height = has_focus ? (child->height - 2 * HANDLE_SIZE) : child->height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, &rect, GTK_SHADOW_OUT); - - if (has_focus) { - /* Top handle */ - - rect.x = 0; - rect.y = 0; - rect.width = child->width - child->decor_width; - rect.height = HANDLE_SIZE; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, - &rect, GTK_SHADOW_OUT); - - /* Bottom handle */ - - rect.y = child->height - HANDLE_SIZE; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, - &rect, GTK_SHADOW_OUT); - } - - } else if (!window || (window == child->decor_window)) { - if (!area) { - arect.x = 0; - arect.y = 0; - arect.width = child->decor_width; - arect.height = child->decor_height; - - area = &arect; - } - - child_draw_decor (fullday, child); - } - - if (draw_child) - gtk_widget_draw (child->widget, NULL); -} - -static void -child_range_changed (GncalFullDay *fullday, Child *child) -{ - struct tm start, end; - int lower_row, rows_used; - int f_lower_row; - - /* Calc display range for event */ - - get_tm_range (fullday, child->start, child->end, &start, &end, &lower_row, &rows_used); - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, &f_lower_row, NULL); - - child->lower_row = lower_row - f_lower_row; - child->rows_used = rows_used; -} - -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - GncalFullDay *fullday; - GtkWidget *ee; - iCalObject *ico; - - fullday = GNCAL_FULL_DAY (data); - - ico = ical_new ("", user_name, ""); - ico->new = 1; - - gncal_full_day_selection_range (fullday, &ico->dtstart, &ico->dtend); - ee = event_editor_new (fullday->calendar, ico); - gtk_widget_show (ee); -} - -static void -edit_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GtkWidget *ee; - - child = data; - - ee = event_editor_new (GNCAL_FULL_DAY (child->widget->parent)->calendar, child->ico); - gtk_widget_show (ee); -} - -static void -delete_occurance (GtkWidget *widget, gpointer data) -{ - Child *child = data; - iCalObject *ical; - time_t *t; - GnomeCalendar *gcal = GNCAL_FULL_DAY (child->widget->parent)->calendar; - - child = data; - ical = child->ico; - t = g_new(time_t, 1); - *t = child->start; - ical->exdate = g_list_prepend(ical->exdate, t); - gnome_calendar_object_changed (gcal, child->ico, CHANGE_DATES); - save_default_calendar (gcal); - -} - -static void -delete_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - child = data; - - fullday = GNCAL_FULL_DAY (child->widget->parent); - - gnome_calendar_remove_object (fullday->calendar, child->ico); - save_default_calendar (fullday->calendar); -} - -static void -unrecur_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - iCalObject *new; - - child = data; - fullday = GNCAL_FULL_DAY (child->widget->parent); - - /* New object */ - new = ical_object_duplicate (child->ico); - g_free (new->recur); - new->recur = 0; - new->dtstart = child->start; - new->dtend = child->end; - - /* Duplicate, and eliminate the recurrency fields */ - ical_object_add_exdate (child->ico, child->start); - gnome_calendar_object_changed (fullday->calendar, child->ico, CHANGE_ALL); - - gnome_calendar_add_object (fullday->calendar, new); - save_default_calendar (fullday->calendar); -} - -static void -child_popup_menu (GncalFullDay *fullday, Child *child, GdkEventButton *event) -{ - int sensitive, items; - struct menu_item *context_menu; - - static struct menu_item child_items[] = { - { N_("Edit this appointment..."), (GtkSignalFunc) edit_appointment, NULL, TRUE }, - { N_("Delete this appointment"), (GtkSignalFunc) delete_appointment, NULL, TRUE }, - { NULL, NULL, NULL, TRUE }, - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - static struct menu_item recur_child_items[] = { - { N_("Make this appointment movable"), (GtkSignalFunc) unrecur_appointment, NULL, TRUE }, - { N_("Edit this appointment..."), (GtkSignalFunc) edit_appointment, NULL, TRUE }, - { N_("Delete this occurance"), (GtkSignalFunc) delete_occurance, NULL, TRUE }, - { N_("Delete all occurances"), (GtkSignalFunc) delete_appointment, NULL, TRUE }, - { NULL, NULL, NULL, TRUE }, - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - sensitive = (child->ico->user_data == NULL); - - if (child->ico->recur){ - items = 6; - context_menu = &recur_child_items[0]; - context_menu[2].data = child; - context_menu[3].data = child; - context_menu[3].sensitive = sensitive; - context_menu[4].data = fullday; - context_menu[5].data = fullday; - } else { - items = 4; - context_menu = &child_items[0]; - context_menu[3].data = fullday; - } - /* These settings are common for each context sensitive menu */ - context_menu[0].data = child; - context_menu[1].data = child; - context_menu[0].sensitive = sensitive; - context_menu[1].sensitive = sensitive; - context_menu[2].sensitive = sensitive; - - popup_menu (context_menu, items, event); -} - -static void -child_realized_setup (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - child = data; - fullday = GNCAL_FULL_DAY (widget->parent); - - gdk_window_set_cursor (widget->window, fullday->beam_cursor); -} - -static void -child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) -{ - const int decor_width = child->decor_width; - - child->x = x; - child->y = y; - child->width = width; - child->height = height; - - if (!child->window) /* realized? */ - return; - - child_set_text_pos (child); - gdk_window_move_resize (child->window, x, y, width - decor_width, height); - - if (decor_width){ - gdk_window_move_resize (child->decor_window, x + width - decor_width, y, - decor_width, child->decor_height); - } -} - -static int -calc_row_height (GncalFullDay *fullday) -{ - int f_rows; - GtkWidget *widget; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - widget = GTK_WIDGET (fullday); - - return (widget->allocation.height - 2 * widget->style->klass->ythickness) / f_rows; -} - -static void -child_set_size (Child *child) -{ - int row_height; - int x, y, width, height; - GncalFullDay *fullday; - - fullday = GNCAL_FULL_DAY (child->widget->parent); - - row_height = calc_row_height (fullday); - - x = child->x; - y = child->lower_row * row_height + GTK_WIDGET (fullday)->style->klass->ythickness; - width = child->width; - height = child->rows_used * row_height; - - if (GTK_WIDGET_HAS_FOCUS (child->widget) && !child->ico->recur) { - y -= HANDLE_SIZE; - height += 2 * HANDLE_SIZE; - } - - child_set_pos (fullday, child, x, y, width, height); -} - -static gint -child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - child_set_size (data); - return FALSE; -} - -static gint -child_focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - char *text; - - child = data; - - child_set_size (child); - - /* Update summary in calendar object */ - - text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); - if (child->ico->summary && strcmp (text, child->ico->summary) == 0) - return FALSE; - - if (child->ico->summary) - g_free (child->ico->summary); - - child->ico->summary = text; - - /* Notify calendar of change */ - - fullday = GNCAL_FULL_DAY (widget->parent); - - gnome_calendar_object_changed (fullday->calendar, child->ico, CHANGE_SUMMARY); - save_default_calendar (fullday->calendar); - - return FALSE; -} - -static gint -child_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data) -{ - if (event->keyval != GDK_Escape) - return FALSE; - - /* If user pressed Esc, un-focus the child by focusing the fullday widget */ - - gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); - gtk_widget_grab_focus (widget->parent); - - return FALSE; -} - -static gint -child_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - if (event->button != 3) - return FALSE; - - child = data; - fullday = GNCAL_FULL_DAY (widget->parent); - - gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "button_press_event"); - gtk_widget_grab_focus (widget); - child_popup_menu (fullday, child, event); - - return TRUE; -} - -/* - * compute the space required to display the decorations - */ -static void -child_compute_decor (Child *child) -{ - iCalObject *ico = child->ico; - int rows_used; - - child->items = 0; - rows_used = (child->rows_used < 1) ? 1 : child->rows_used; - if (ico->recur) - child->items++; - if (ico->dalarm.enabled || ico->aalarm.enabled || ico->palarm.enabled || ico->malarm.enabled) - child->items++; - - if (child->items > rows_used){ - child->decor_width = DECOR_WIDTH * 2; - child->decor_height = DECOR_HEIGHT; - } else { - child->decor_width = DECOR_WIDTH * (child->items ? 1 : 0); - child->decor_height = DECOR_HEIGHT * child->items; - } -} - -static Child * -child_new (GncalFullDay *fullday, time_t start, time_t end, iCalObject *ico) -{ - Child *child; - - child = g_new (Child, 1); - - child->ico = ico; - child->widget = gtk_text_new (NULL, NULL); - child->window = NULL; - child->x = 0; - child->y = 0; - child->width = 0; - child->height = 0; - child->start = start; - child->end = end; - child_range_changed (fullday, child); - child_compute_decor (child); - - if (ico->summary) - gtk_text_insert (GTK_TEXT (child->widget), NULL, NULL, NULL, - ico->summary, - strlen (ico->summary)); - - /* We set the i-beam cursor of the text widget upon realization */ - - gtk_signal_connect (GTK_OBJECT (child->widget), "realize", - (GtkSignalFunc) child_realized_setup, - child); - - gtk_signal_connect_after (GTK_OBJECT (child->widget), "focus_in_event", - (GtkSignalFunc) child_focus_in, - child); - - child->focus_out_id = gtk_signal_connect_after (GTK_OBJECT (child->widget), "focus_out_event", - (GtkSignalFunc) child_focus_out, - child); - - gtk_signal_connect (GTK_OBJECT (child->widget), "key_press_event", - (GtkSignalFunc) child_key_press, - child); - - gtk_signal_connect (GTK_OBJECT (child->widget), "button_press_event", - (GtkSignalFunc) child_button_press, - child); - - /* Finish setup */ - - gtk_text_set_editable (GTK_TEXT (child->widget), TRUE); - gtk_text_set_word_wrap (GTK_TEXT (child->widget), TRUE); - - gtk_widget_set_parent (child->widget, GTK_WIDGET (fullday)); - - return child; -} - -static void -squick (GtkWidget *widget, gpointer data) -{ -} - -static void -child_destroy (GncalFullDay *fullday, Child *child) -{ - /* Disconnect the focus_out_event signal since we will get such an event - * from the destroy call. - */ - gtk_signal_disconnect (GTK_OBJECT (child->widget), child->focus_out_id); - - if (GTK_WIDGET_MAPPED (fullday)) - child_unmap (fullday, child); - - if (GTK_WIDGET_REALIZED (fullday)) - child_unrealize (fullday, child); - - /* Unparent the child widget manually as we don't have a remove method */ - - gtk_signal_connect (GTK_OBJECT (child->widget), "destroy", - (GtkSignalFunc) squick, - NULL); - - gtk_widget_unparent (child->widget); - g_free (child); -} - -static int -calc_labels_width (GncalFullDay *fullday) -{ - struct tm cur, upper; - time_t tim, time_upper; - int width, max_w; - char buf[40]; - - get_tm_range (fullday, fullday->lower, fullday->upper, &cur, &upper, NULL, NULL); - - max_w = 0; - - tim = mktime (&cur); - time_upper = mktime (&upper); - - while (tim < time_upper) { - if (am_pm_flag) - strftime (buf, sizeof (buf), "%I:%M%p", &cur); - else - strftime (buf, sizeof (buf), "%H:%M", &cur); - - - width = gdk_string_width (GTK_WIDGET (fullday)->style->font, buf); - - if (width > max_w) - max_w = width; - - cur.tm_min += fullday->interval; - tim = mktime (&cur); - } - - return max_w; -} - -/* Used with layout_events(), takes in a list element and returns the start and end times for the - * event corresponding to that element. - */ -static void -child_layout_query_func (GList *event, time_t *start, time_t *end) -{ - Child *child; - - child = event->data; - - *start = child->start; - *end = child->end; -} - -/* Takes the list of children in the full day view and lays them out nicely without overlapping. - * Basically it calls the layout_events() function in layout.c and resizes the fullday's children. - */ -static void -layout_children (GncalFullDay *fullday) -{ - GtkWidget *widget; - GList *children; - Child *child; - int num_slots; - int *allocations; - int *slots; - int left_x; - int usable_pixels, pixels_per_col, extra_pixels; - int i; - - if (!fullday->children) - return; - - layout_events (fullday->children, child_layout_query_func, &num_slots, &allocations, &slots); - - /* Set the size and position of each child */ - - widget = GTK_WIDGET (fullday); - left_x = 2 * (widget->style->klass->xthickness + TEXT_BORDER) + calc_labels_width (fullday); - - usable_pixels = widget->allocation.width - left_x - widget->style->klass->xthickness; - pixels_per_col = usable_pixels / num_slots; - extra_pixels = usable_pixels % num_slots; - - for (children = fullday->children, i = 0; children; children = children->next, i++) { - child = children->data; - - child->x = left_x + pixels_per_col * allocations[i]; - child->width = pixels_per_col * slots[i]; - - if ((allocations[i] + slots[i]) == num_slots) - child->width += extra_pixels; - - child_set_size (child); - } - - g_free (allocations); - g_free (slots); -} - -guint -gncal_full_day_get_type (void) -{ - static guint full_day_type = 0; - - if (!full_day_type) { - GtkTypeInfo full_day_info = { - "GncalFullDay", - sizeof (GncalFullDay), - sizeof (GncalFullDayClass), - (GtkClassInitFunc) gncal_full_day_class_init, - (GtkObjectInitFunc) gncal_full_day_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - full_day_type = gtk_type_unique (gtk_container_get_type (), &full_day_info); - } - - return full_day_type; -} - -static void -gncal_full_day_class_init (GncalFullDayClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - parent_class = gtk_type_class (gtk_container_get_type ()); - - fullday_signals[RANGE_ACTIVATED] = - gtk_signal_new ("range_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (GncalFullDayClass, range_activated), - gtk_signal_default_marshaller, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, fullday_signals, LAST_SIGNAL); - - object_class->destroy = gncal_full_day_destroy; - - widget_class->map = gncal_full_day_map; - widget_class->unmap = gncal_full_day_unmap; - widget_class->realize = gncal_full_day_realize; - widget_class->unrealize = gncal_full_day_unrealize; - widget_class->draw = gncal_full_day_draw; - widget_class->draw_focus = gncal_full_day_draw_focus; - widget_class->size_request = gncal_full_day_size_request; - widget_class->size_allocate = gncal_full_day_size_allocate; - widget_class->button_press_event = gncal_full_day_button_press; - widget_class->button_release_event = gncal_full_day_button_release; - widget_class->motion_notify_event = gncal_full_day_motion; - widget_class->expose_event = gncal_full_day_expose; - widget_class->key_press_event = gncal_full_day_key_press; - widget_class->focus_in_event = gncal_full_day_focus_in; - widget_class->focus_out_event = gncal_full_day_focus_out; - - container_class->forall = gncal_full_day_forall; - - class->range_activated = range_activated; -} - -static void -gncal_full_day_init (GncalFullDay *fullday) -{ - GTK_WIDGET_UNSET_FLAGS (fullday, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (fullday, GTK_CAN_FOCUS); - - fullday->calendar = NULL; - - fullday->lower = 0; - fullday->upper = 0; - fullday->interval = 30; /* 30 minutes by default */ - - fullday->children = NULL; - fullday->drag_info = g_new0 (struct drag_info, 1); - - fullday->up_down_cursor = NULL; - fullday->beam_cursor = NULL; - fullday->recur_gc = NULL; - fullday->bell_gc = NULL; -} - -/* Destroys all the children in the full day widget */ -static void -destroy_children (GncalFullDay *fullday) -{ - GList *children; - - for (children = fullday->children; children; children = children->next) - child_destroy (fullday, children->data); - - g_list_free (fullday->children); - fullday->children = NULL; -} - -static void -gncal_full_day_destroy (GtkObject *object) -{ - GncalFullDay *fullday; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (object)); - - fullday = GNCAL_FULL_DAY (object); - - destroy_children (fullday); - - g_free (fullday->drag_info); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -GtkWidget * -gncal_full_day_new (GnomeCalendar *calendar, time_t lower, time_t upper) -{ - GncalFullDay *fullday; - - g_return_val_if_fail (calendar != NULL, NULL); - - fullday = gtk_type_new (gncal_full_day_get_type ()); - - fullday->calendar = calendar; - - gncal_full_day_set_bounds (fullday, lower, upper); - - return GTK_WIDGET (fullday); -} - -static void -gncal_full_day_map (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - - fullday = GNCAL_FULL_DAY (widget); - - gdk_window_show (widget->window); - - for (children = fullday->children; children; children = children->next) - child_map (fullday, children->data); -} - -static void -gncal_full_day_unmap (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - - fullday = GNCAL_FULL_DAY (widget); - - gdk_window_hide (widget->window); - - for (children = fullday->children; children; children = children->next) - child_unmap (fullday, children->data); -} - -static void -gncal_full_day_realize (GtkWidget *widget) -{ - GncalFullDay *fullday; - GdkWindowAttr attributes; - gint attributes_mask; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - fullday = GNCAL_FULL_DAY (widget); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = (gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_background (widget->window, &widget->style->bg[GTK_STATE_PRELIGHT]); - - fullday->up_down_cursor = gdk_cursor_new (GDK_DOUBLE_ARROW); - fullday->beam_cursor = gdk_cursor_new (GDK_XTERM); - - for (children = fullday->children; children; children = children->next) - child_realize (fullday, children->data); - -} - -static void -gncal_full_day_unrealize (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - fullday = GNCAL_FULL_DAY (widget); - - for (children = fullday->children; children; children = children->next) - child_unrealize (fullday, children->data); - - gdk_cursor_destroy (fullday->up_down_cursor); - fullday->up_down_cursor = NULL; - - gdk_cursor_destroy (fullday->beam_cursor); - fullday->beam_cursor = NULL; - - if (fullday->bell_gc) - gdk_gc_destroy (fullday->bell_gc); - if (fullday->recur_gc) - gdk_gc_destroy (fullday->recur_gc); - - if (pixmap_bell){ - gdk_pixmap_unref (pixmap_bell); - pixmap_bell = NULL; - } - - if (pixmap_recur){ - gdk_pixmap_unref (pixmap_recur); - pixmap_recur = NULL; - } - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -struct paint_info { - GtkWidget *widget; - struct drag_info *di; - GdkRectangle *area; - int x1, y1, width, height; - int labels_width; - int row_height; - struct tm start_tm; -}; - -static void -paint_row (GncalFullDay *fullday, int row, struct paint_info *p) -{ - GdkRectangle rect, dest; - GdkGC *left_gc, *right_gc, *text_gc; - int begin_row, end_row; - struct tm tm; - char buf[40]; - - begin_row = (day_begin * 60) / fullday->interval; - end_row = (day_end * 60) / fullday->interval; - - /* See which GCs we will use */ - - if ((p->di->sel_rows_used != 0) - && (row >= p->di->sel_start_row) - && (row < (p->di->sel_start_row + p->di->sel_rows_used))) { - left_gc = p->widget->style->bg_gc[GTK_STATE_SELECTED]; - right_gc = left_gc; - text_gc = p->widget->style->fg_gc[GTK_STATE_SELECTED]; - } else if ((row < begin_row) || (row >= end_row)) { - left_gc = p->widget->style->bg_gc[GTK_STATE_NORMAL]; - right_gc = p->widget->style->bg_gc[GTK_STATE_ACTIVE]; - text_gc = p->widget->style->fg_gc[GTK_STATE_NORMAL]; - } else { - left_gc = p->widget->style->bg_gc[GTK_STATE_NORMAL]; - right_gc = p->widget->style->bg_gc[GTK_STATE_PRELIGHT]; - text_gc = p->widget->style->fg_gc[GTK_STATE_NORMAL]; - } - - /* Left background and text */ - - rect.x = p->x1; - rect.y = p->y1 + row * p->row_height; - rect.width = 2 * TEXT_BORDER + p->labels_width; - rect.height = p->row_height - 1; - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) { - gdk_draw_rectangle (p->widget->window, - left_gc, - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - tm = p->start_tm; - tm.tm_min += row * fullday->interval; - mktime (&tm); - - if (am_pm_flag) - strftime (buf, sizeof (buf), "%I:%M%p", &tm); - else - strftime (buf, sizeof (buf), "%H:%M", &tm); - - gdk_draw_string (p->widget->window, - p->widget->style->font, - text_gc, - rect.x + TEXT_BORDER, - rect.y + TEXT_BORDER + p->widget->style->font->ascent, - buf); - } - - /* Right background */ - - rect.x += rect.width + p->widget->style->klass->xthickness; - rect.width = p->width - (rect.x - p->x1); - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) - gdk_draw_rectangle (p->widget->window, - right_gc, - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - /* Horizontal division at bottom of row */ - - rect.x = p->x1; - rect.y += rect.height; - rect.width = p->width; - rect.height = 1; - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) - gdk_draw_line (p->widget->window, - p->widget->style->black_gc, - rect.x, rect.y, - rect.x + rect.width - 1, rect.y); -} - -static void -paint_back (GncalFullDay *fullday, GdkRectangle *area) -{ - struct paint_info p; - int start_row, end_row; - int i; - GdkRectangle rect, dest, aarea; - int f_rows; - int draw_focus; - - p.widget = GTK_WIDGET (fullday); - p.di = fullday->drag_info; - - if (!area) { - area = &aarea; - - area->x = 0; - area->y = 0; - area->width = p.widget->allocation.width; - area->height = p.widget->allocation.height; - } - p.area = area; - - p.x1 = p.widget->style->klass->xthickness; - p.y1 = p.widget->style->klass->ythickness; - p.width = p.widget->allocation.width - 2 * p.x1; - p.height = p.widget->allocation.height - 2 * p.y1; - - p.labels_width = calc_labels_width (fullday); - p.row_height = calc_row_height (fullday); - get_tm_range (fullday, fullday->lower, fullday->upper, &p.start_tm, NULL, NULL, &f_rows); - - /* Frame shadow */ - - rect.x = 0; - rect.y = 0; - rect.width = p.widget->allocation.width; - rect.height = p.widget->style->klass->ythickness; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - - if (!draw_focus) { - rect.y = p.widget->allocation.height - rect.height; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (!draw_focus) { - rect.y = p.widget->style->klass->ythickness; - rect.width = p.widget->style->klass->xthickness; - rect.height = p.widget->allocation.height - 2 * rect.y; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (!draw_focus) { - rect.x = p.widget->allocation.width - rect.width; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (draw_focus) - gtk_widget_draw_focus (p.widget); - - /* Rows */ - - start_row = (area->y - p.y1) / p.row_height; - end_row = (area->y + area->height - 1 - p.y1) / p.row_height; - - if (end_row >= f_rows) - end_row = f_rows - 1; - - for (i = start_row; i <= end_row; i++) - paint_row (fullday, i, &p); - - /* Slack area at bottom of widget */ - - rect.x = p.x1; - rect.y = p.y1 + f_rows * p.row_height; - rect.width = p.width; - rect.height = p.height - (rect.y - p.y1); - - if (gdk_rectangle_intersect (&rect, area, &dest)) - gdk_draw_rectangle (p.widget->window, - p.widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - /* Vertical division */ - - rect.x = p.x1 + 2 * TEXT_BORDER + p.labels_width; - rect.y = p.y1; - rect.width = p.widget->style->klass->xthickness; - rect.height = p.height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - gtk_draw_vline (p.widget->style, p.widget->window, - GTK_STATE_NORMAL, - rect.y, - rect.y + rect.height - 1, - rect.x); -} - -static void -paint_back_rows (GncalFullDay *fullday, int start_row, int rows_used) -{ - int row_height; - int xthickness, ythickness; - GtkWidget *widget; - GdkRectangle area; - - widget = GTK_WIDGET (fullday); - - row_height = calc_row_height (fullday); - - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; - - area.x = xthickness; - area.y = ythickness + start_row * row_height; - area.width = widget->allocation.width - 2 * xthickness; - area.height = rows_used * row_height; - - paint_back (fullday, &area); -} - -static void -gncal_full_day_draw (GtkWidget *widget, GdkRectangle *area) -{ - GncalFullDay *fullday; - GList *children; - Child *child; - GdkRectangle rect, dest; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (area != NULL); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return; - - fullday = GNCAL_FULL_DAY (widget); - - paint_back (fullday, area); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - rect.x = child->x; - rect.y = child->y; - rect.width = child->width; - rect.height = child->height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) { - child_draw (fullday, child, NULL, NULL, TRUE); - } - } -} - -static void -gncal_full_day_draw_focus (GtkWidget *widget) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return; - - gtk_draw_shadow (widget->style, widget->window, - GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN, - 0, 0, - widget->allocation.width, - widget->allocation.height); - - if (GTK_WIDGET_HAS_FOCUS (widget)) - gdk_draw_rectangle (widget->window, - widget->style->black_gc, - FALSE, - 0, 0, - widget->allocation.width - 1, - widget->allocation.height - 1); -} - -static void -gncal_full_day_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GncalFullDay *fullday; - int labels_width; - int rows; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (requisition != NULL); - - fullday = GNCAL_FULL_DAY (widget); - - /* Border and min width */ - - labels_width = calc_labels_width (fullday); - - requisition->width = 2 * widget->style->klass->xthickness + 4 * TEXT_BORDER + labels_width + MIN_WIDTH; - requisition->height = 2 * widget->style->klass->ythickness; - - /* Rows */ - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &rows); - - requisition->height += (rows * (2 * TEXT_BORDER + widget->style->font->ascent + widget->style->font->descent) - + (rows - 1)); /* division lines */ -} - -static void -gncal_full_day_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - GncalFullDay *fullday; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - - fullday = GNCAL_FULL_DAY (widget); - - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - - layout_children (fullday); -} - -static Child * -find_child_by_window (GncalFullDay *fullday, GdkWindow *window, int *on_text) -{ - GList *children; - Child *child; - GtkWidget *owner; - - *on_text = FALSE; - - gdk_window_get_user_data (window, (gpointer *) &owner); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->window == window || child->decor_window == window) - return child; - - if (child->widget == owner) { - *on_text = TRUE; - return child; - } - } - - return NULL; -} - -static void -draw_xor_rect (GncalFullDay *fullday) -{ - GtkWidget *widget; - struct drag_info *di; - int i; - int row_height; - int ythickness; - - widget = GTK_WIDGET (fullday); - - gdk_gc_set_function (widget->style->white_gc, GDK_INVERT); - gdk_gc_set_subwindow (widget->style->white_gc, GDK_INCLUDE_INFERIORS); - - ythickness = widget->style->klass->ythickness; - - di = fullday->drag_info; - - row_height = calc_row_height (fullday); - - for (i = 0; i < XOR_RECT_WIDTH; i++) - gdk_draw_rectangle (widget->window, - widget->style->white_gc, - FALSE, - di->child->x + i, - di->child_start_row * row_height + ythickness + i, - di->child->width - 2 * i - 1, - di->child_rows_used * row_height - 2 - 2 * i); - - gdk_gc_set_function (widget->style->white_gc, GDK_COPY); - gdk_gc_set_subwindow (widget->style->white_gc, GDK_CLIP_BY_CHILDREN); -} - -static int -get_row_from_y (GncalFullDay *fullday, int y, int round) -{ - GtkWidget *widget; - int row_height; - int f_rows; - int ythickness; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - row_height = calc_row_height (fullday); - - widget = GTK_WIDGET (fullday); - - ythickness = widget->style->klass->ythickness; - - y -= ythickness; - - if (y < 0) - y = 0; - else if (y >= (f_rows * row_height)) - y = f_rows * row_height - 1; - - if (round) - y += row_height / 2; - - y /= row_height; - - if (y > f_rows) - y = f_rows; /* note that this is 1 more than the last row's index */ - - return y; -} - -static int -button_1 (GncalFullDay *fullday, GdkEventButton *event) -{ - GtkWidget *widget; - Child *child; - int on_text; - struct drag_info *di; - gint y; - int row_height; - int has_focus; - int old_start_row, old_rows_used; - int old_max; - int paint_start_row, paint_rows_used; - - widget = GTK_WIDGET (fullday); - - if (event->window == widget->window) { - /* Clicked on main window */ - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - /* Prepare for drag */ - - di = fullday->drag_info; - - di->drag_mode = DRAG_SELECT; - - old_start_row = di->sel_start_row; - old_rows_used = di->sel_rows_used; - - di->sel_click_row = get_row_from_y (fullday, event->y, FALSE); - di->sel_start_row = di->sel_click_row; - di->sel_rows_used = 1; - - di->click_time = event->time; - - gdk_pointer_grab (widget->window, FALSE, - (GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_RELEASE_MASK), - NULL, - fullday->up_down_cursor, - event->time); - - if (old_rows_used == 0) { - paint_start_row = di->sel_start_row; - paint_rows_used = di->sel_rows_used; - } else { - paint_start_row = MIN (old_start_row, di->sel_start_row); - old_max = old_start_row + old_rows_used - 1; - paint_rows_used = MAX (old_max, di->sel_start_row) - paint_start_row + 1; - } - - paint_back_rows (fullday, paint_start_row, paint_rows_used); - - return TRUE; - } else { - /* Clicked on a child? */ - - child = find_child_by_window (fullday, event->window, &on_text); - - if (!child || on_text || child->ico->recur) - return FALSE; - - /* Prepare for drag */ - - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - if (has_focus) { - if (event->y < HANDLE_SIZE) - di->drag_mode = DRAG_SIZE_TOP; - else if (event->y >= (child->height - HANDLE_SIZE)) - di->drag_mode = DRAG_SIZE_BOTTOM; - else - di->drag_mode = DRAG_MOVE; - } else - di->drag_mode = DRAG_MOVE; - - row_height = calc_row_height (fullday); - - di->child = child; - - di->child_click_y = event->y; - di->child_start_row = child->lower_row; - di->child_rows_used = child->rows_used; - - gdk_pointer_grab (child->window, FALSE, - (GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_RELEASE_MASK), - NULL, - fullday->up_down_cursor, - event->time); - - draw_xor_rect (fullday); - - return TRUE; - } - - return FALSE; -} - -static int -button_3 (GncalFullDay *fullday, GdkEventButton *event) -{ - static struct menu_item main_items[] = { - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - GtkWidget *widget; - Child *child; - int on_text; - - widget = GTK_WIDGET (fullday); - - if (event->window == widget->window) { - /* Clicked on main window */ - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - main_items[0].data = fullday; - - popup_menu (main_items, sizeof (main_items) / sizeof (main_items[0]), event); - - return TRUE; - } else { - child = find_child_by_window (fullday, event->window, &on_text); - - if (!child || on_text) - return FALSE; - - child_popup_menu (fullday, child, event); - - return TRUE; - } - - return FALSE; -} - -static gint -gncal_full_day_button_press (GtkWidget *widget, GdkEventButton *event) -{ - GncalFullDay *fullday; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - switch (event->button) { - case 1: - return button_1 (fullday, event); - - case 3: - return button_3 (fullday, event); - - default: - break; - } - - return FALSE; -} - -static void -recompute_motion (GncalFullDay *fullday, int y) -{ - struct drag_info *di; - int f_rows; - int row; - int has_focus; - - di = fullday->drag_info; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - switch (di->drag_mode) { - case DRAG_SELECT: - row = get_row_from_y (fullday, y, FALSE); - - if (row >= f_rows) - row = f_rows - 1; - - if (row < di->sel_click_row) { - di->sel_start_row = row; - di->sel_rows_used = di->sel_click_row - row + 1; - } else { - di->sel_start_row = di->sel_click_row; - di->sel_rows_used = row - di->sel_start_row + 1; - } - - break; - - case DRAG_MOVE: - has_focus = GTK_WIDGET_HAS_FOCUS (di->child->widget); - - if (has_focus) - child_focus_out (di->child->widget, NULL, di->child); - - row = get_row_from_y (fullday, y - di->child_click_y + (has_focus ? HANDLE_SIZE : 0), TRUE); - - if (row > (f_rows - di->child_rows_used)) - row = f_rows - di->child_rows_used; - - di->child_start_row = row; - - break; - - case DRAG_SIZE_TOP: - has_focus = GTK_WIDGET_HAS_FOCUS (di->child->widget); - - if (has_focus) - child_focus_out (di->child->widget, NULL, di->child); - - row = get_row_from_y (fullday, y + HANDLE_SIZE, TRUE); - - if (row > (di->child_start_row + di->child_rows_used - 1)) - row = di->child_start_row + di->child_rows_used - 1; - - di->child_rows_used = (di->child_start_row + di->child_rows_used) - row; - di->child_start_row = row; - - break; - - case DRAG_SIZE_BOTTOM: - has_focus = GTK_WIDGET_HAS_FOCUS (di->child->widget); - - if (has_focus) - child_focus_out (di->child->widget, NULL, di->child); - - row = get_row_from_y (fullday, y - HANDLE_SIZE, TRUE); - - if (row <= di->child_start_row) - row = di->child_start_row + 1; - else if (row > f_rows) - row = f_rows; - - di->child_rows_used = row - di->child_start_row; - - break; - - default: - g_assert_not_reached (); - } -} - -static void -get_time_from_rows (GncalFullDay *fullday, int start_row, int rows_used, time_t *t_lower, time_t *t_upper) -{ - struct tm tm; - int row_height; - - get_tm_range (fullday, fullday->lower, fullday->upper, &tm, NULL, NULL, NULL); - - row_height = calc_row_height (fullday); - - tm.tm_min += fullday->interval * start_row; - *t_lower = mktime (&tm); - - tm.tm_min += fullday->interval * rows_used; - *t_upper = mktime (&tm); -} - -static void -update_from_drag_info (GncalFullDay *fullday) -{ - struct drag_info *di; - GtkWidget *widget; - - di = fullday->drag_info; - - widget = GTK_WIDGET (fullday); - - get_time_from_rows (fullday, di->child_start_row, di->child_rows_used, - &di->child->ico->dtstart, - &di->child->ico->dtend); - - child_range_changed (fullday, di->child); - - /* Notify calendar of change */ - - gnome_calendar_object_changed (fullday->calendar, di->child->ico, CHANGE_DATES); - save_default_calendar (fullday->calendar); -} - -static gint -gncal_full_day_button_release (GtkWidget *widget, GdkEventButton *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - gint y; - int retval; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - retval = FALSE; - - switch (di->drag_mode) { - case DRAG_NONE: - break; - - case DRAG_SELECT: - if ((event->time - di->click_time) < UNSELECT_TIMEOUT) - di->sel_rows_used = 0; - else - recompute_motion (fullday, y); - - gdk_pointer_ungrab (event->time); - - paint_back_rows (fullday, di->sel_start_row, MAX (di->sel_rows_used, 1)); - - retval = TRUE; - break; - - case DRAG_MOVE: - case DRAG_SIZE_TOP: - case DRAG_SIZE_BOTTOM: - draw_xor_rect (fullday); - recompute_motion (fullday, y); - gdk_pointer_ungrab (event->time); - - update_from_drag_info (fullday); - - di->child_rows_used = 0; - - retval = TRUE; - break; - - default: - g_assert_not_reached (); - } - - di->drag_mode = DRAG_NONE; - di->child = NULL; - - return retval; -} - -static gint -gncal_full_day_motion (GtkWidget *widget, GdkEventMotion *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - gint y; - int old_min, old_max; - int new_min, new_max; - int new_start_row, new_rows_used; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - switch (di->drag_mode) { - case DRAG_NONE: - break; - - case DRAG_SELECT: - old_min = di->sel_start_row; - old_max = di->sel_start_row + di->sel_rows_used - 1; - - recompute_motion (fullday, y); - - new_min = di->sel_start_row; - new_max = di->sel_start_row + di->sel_rows_used - 1; - - new_start_row = MIN (old_min, new_min); - new_rows_used = MAX (old_max, new_max) - new_start_row + 1; - - paint_back_rows (fullday, new_start_row, new_rows_used); - - return TRUE; - - case DRAG_MOVE: - case DRAG_SIZE_TOP: - case DRAG_SIZE_BOTTOM: - draw_xor_rect (fullday); - recompute_motion (fullday, y); - draw_xor_rect (fullday); - - return TRUE; - - default: - g_assert_not_reached (); - } - - return FALSE; -} - -static gint -gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GncalFullDay *fullday; - Child *child; - int on_text; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return FALSE; - - fullday = GNCAL_FULL_DAY (widget); - - if (event->window == widget->window) - paint_back (fullday, &event->area); - else { - child = find_child_by_window (fullday, event->window, &on_text); - - if (child && !on_text) - child_draw (fullday, child, &event->area, event->window, FALSE); - } - - return FALSE; -} - -static gint -gncal_full_day_key_press (GtkWidget *widget, GdkEventKey *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - GList *children; - Child *child; - gint pos; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - di = fullday->drag_info; - - if (di->sel_rows_used == 0) - return FALSE; - - if (event->keyval == GDK_Return) { - gtk_signal_emit (GTK_OBJECT (fullday), fullday_signals[RANGE_ACTIVATED]); - return TRUE; - } - - /* - * If a non-printable key was pressed, bail. Otherwise, begin - * editing the appointment. - */ - if ((event->keyval < 0x20) || (event->keyval > 0xFF) - || (event->length == 0) || (event->state & GDK_CONTROL_MASK) - || (event->state & GDK_MOD1_MASK)) - return FALSE; - - gtk_signal_emit (GTK_OBJECT (fullday), - fullday_signals[RANGE_ACTIVATED]); - - /* - * Find the new child, which should hopefully be focused, and - * insert the keypress. - */ - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (GTK_WIDGET_HAS_FOCUS (child->widget)) { - pos = gtk_text_get_length (GTK_TEXT (child->widget)); - - gtk_editable_insert_text (GTK_EDITABLE (child->widget), - event->string, - event->length, - &pos); - - return TRUE; - } - } - - return FALSE; -} - -static gint -gncal_full_day_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - gtk_widget_draw_focus (widget); - - return FALSE; -} - -static gint -gncal_full_day_focus_out (GtkWidget *widget, GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - gtk_widget_draw_focus (widget); - - return FALSE; -} - -static void -gncal_full_day_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) -{ - GncalFullDay *fullday; - GList *children; - Child *child; - - g_return_if_fail (container != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (container)); - g_return_if_fail (callback != NULL); - - fullday = GNCAL_FULL_DAY (container); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - (*callback) (child->widget, callback_data); - } -} - -static gint -child_compare (gconstpointer a, gconstpointer b) -{ - const Child *ca = a; - const Child *cb = b; - time_t diff; - - diff = ca->start - cb->start; - - if (diff == 0) - diff = cb->end - ca->end; - - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -static int -fullday_add_children (iCalObject *obj, time_t start, time_t end, void *c) -{ - GncalFullDay *fullday = c; - Child *child; - - child = child_new (fullday, start, end, obj); - fullday->children = g_list_insert_sorted (fullday->children, child, child_compare); - - return 1; -} - -void -gncal_full_day_update (GncalFullDay *fullday, iCalObject *ico, int flags) -{ - GList *children; - Child *child; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - if (!fullday->calendar->cal) - return; - - /* Try to find child that changed */ - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->ico == ico) - break; - } - - /* If child was found and nothing but the summary changed, we can just paint the child and return */ - - if (children && !(flags & ~CHANGE_SUMMARY)) { - child_draw (fullday, child, NULL, NULL, TRUE); - return; - } - - /* We have to regenerate and layout our list of children */ - - destroy_children (fullday); - - calendar_iterate (fullday->calendar->cal, - fullday->lower, - fullday->upper, - fullday_add_children, - fullday); - - layout_children (fullday); - - /* Realize and map children */ - - for (children = fullday->children; children; children = children->next) { - if (GTK_WIDGET_REALIZED (fullday)) - child_realize (fullday, children->data); - - if (GTK_WIDGET_MAPPED (fullday)) - child_map (fullday, children->data); - } - - gtk_widget_draw (GTK_WIDGET (fullday), NULL); -} - -void -gncal_full_day_set_bounds (GncalFullDay *fullday, time_t lower, time_t upper) -{ - struct drag_info *di; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - if ((lower != fullday->lower) || (upper != fullday->upper)) { - fullday->lower = lower; - fullday->upper = upper; - - di = fullday->drag_info; - - di->sel_rows_used = 0; /* clear selection */ - - gncal_full_day_update (fullday, NULL, 0); - } -} - -int -gncal_full_day_selection_range (GncalFullDay *fullday, time_t *lower, time_t *upper) -{ - struct drag_info *di; - time_t alower, aupper; - - g_return_val_if_fail (fullday != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (fullday), FALSE); - - di = fullday->drag_info; - - if (di->sel_rows_used == 0){ - time_t now = time (NULL); - struct tm tm = *localtime (&now); - struct tm thisd = *localtime (&fullday->lower); - - thisd.tm_hour = tm.tm_hour; - thisd.tm_min = tm.tm_min; - thisd.tm_sec = 0; - *lower = mktime (&thisd); - thisd.tm_hour++; - *upper = mktime (&thisd); - return FALSE; - } - - get_time_from_rows (fullday, di->sel_start_row, di->sel_rows_used, &alower, &aupper); - - if (lower) - *lower = alower; - - if (upper) - *upper= aupper; - - return TRUE; -} - -void -gncal_full_day_focus_child (GncalFullDay *fullday, iCalObject *ico) -{ - GList *children; - Child *child; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (ico != NULL); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->ico == ico) { - gtk_widget_grab_focus (child->widget); - break; - } - } -} - -int -gncal_full_day_get_day_start_yoffset (GncalFullDay *fullday) -{ - GtkWidget *widget; - int begin_row; - - g_return_val_if_fail (fullday != NULL, 0); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (fullday), 0); - - widget = GTK_WIDGET (fullday); - - begin_row = (day_begin * 60) / fullday->interval; - - return widget->style->klass->ythickness + begin_row * calc_row_height (fullday); -} - -static void -range_activated (GncalFullDay *fullday) -{ - struct drag_info *di; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - di = fullday->drag_info; - - /* Remove selection; at this point someone should already have added an appointment */ - - di->sel_rows_used = 0; - - paint_back (fullday, NULL); -} diff --git a/calendar/gncal-full-day.h b/calendar/gncal-full-day.h deleted file mode 100644 index 287c5f63f6..0000000000 --- a/calendar/gncal-full-day.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Full day widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_FULL_DAY_H -#define GNCAL_FULL_DAY_H - - -#include <gtk/gtkcontainer.h> -#include <libgnome/gnome-defs.h> -#include "calendar.h" -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_FULL_DAY(obj) GTK_CHECK_CAST (obj, gncal_full_day_get_type (), GncalFullDay) -#define GNCAL_FULL_DAY_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_full_day_get_type (), GncalFullDayClass) -#define GNCAL_IS_FULL_DAY(obj) GTK_CHECK_TYPE (obj, gncal_full_day_get_type ()) - - -typedef struct _GncalFullDay GncalFullDay; -typedef struct _GncalFullDayClass GncalFullDayClass; - -struct _GncalFullDay { - GtkContainer container; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - time_t lower; /* lower time to display */ - time_t upper; /* upper time to display */ - int interval; /* interval between rows in minutes */ - - GList *children; /* container children */ - gpointer drag_info; /* internal drag information */ - - GdkCursor *up_down_cursor; /* for dragging children */ - GdkCursor *beam_cursor; /* for the text widgets */ - GdkGC *recur_gc; /* The gc used to draw the recur image */ - GdkGC *bell_gc; /* The gc used to draw on imlib windows */ - -}; - -struct _GncalFullDayClass { - GtkContainerClass parent_class; - - void (* range_activated) (GncalFullDay *fullday); -}; - - -guint gncal_full_day_get_type (void); -GtkWidget *gncal_full_day_new (GnomeCalendar *calendar, time_t lower, time_t upper); - -void gncal_full_day_update (GncalFullDay *fullday, iCalObject *ico, int flags); -void gncal_full_day_set_bounds (GncalFullDay *fullday, time_t lower, time_t upper); - -/* Returns the selected range in lower and upper. If nothing is - * selected, return value is FALSE, otherwise it is TRUE. - * The lower and upper values are always set to proper values, regardless of - * the selection value - */ -int gncal_full_day_selection_range (GncalFullDay *fullday, time_t *lower, time_t *upper); - -void gncal_full_day_focus_child (GncalFullDay *fullday, iCalObject *ico); - -int gncal_full_day_get_day_start_yoffset (GncalFullDay *fullday); - -END_GNOME_DECLS - -#endif diff --git a/calendar/gncal-todo.c b/calendar/gncal-todo.c deleted file mode 100644 index 64ea8d0638..0000000000 --- a/calendar/gncal-todo.c +++ /dev/null @@ -1,877 +0,0 @@ -/* To-do widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <config.h> -#include <string.h> -#include <gnome.h> -#include "gncal-todo.h" -#include "main.h" -#include "popup-menu.h" -#include "eventedit.h" - -int todo_show_due_date = 0; -int todo_show_priority = 0; -int todo_show_time_remaining = 0; - -int todo_item_dstatus_highlight_overdue = 0; -int todo_item_dstatus_highlight_due_today = 0; -int todo_item_dstatus_highlight_not_due_yet = 0; - - -char *todo_overdue_font_text; -gint todo_current_sort_column = 0; -gint todo_current_sort_type = GTK_SORT_ASCENDING; - -gboolean todo_style_changed =0; -gboolean todo_list_autoresize = 1; -gboolean todo_list_redraw_in_progess = 0; -static void gncal_todo_init (GncalTodo *todo); - - -guint -gncal_todo_get_type (void) -{ - static guint todo_type = 0; - - if (!todo_type) { - GtkTypeInfo todo_info = { - "GncalTodo", - sizeof (GncalTodo), - sizeof (GncalTodoClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) gncal_todo_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - todo_type = gtk_type_unique (gtk_vbox_get_type (), &todo_info); - } - - return todo_type; -} - -static void -ok_button (GtkWidget *widget, GnomeDialog *dialog) -{ - iCalObject *ico; - GncalTodo *todo; - GtkEntry *entry; - GnomeDateEdit *due_date; - GtkText *comment; - GtkSpinButton *priority; - - ico = gtk_object_get_user_data (GTK_OBJECT (dialog)); - - todo = GNCAL_TODO (gtk_object_get_data (GTK_OBJECT (dialog), "gncal_todo")); - entry = GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (dialog), "summary_entry")); - due_date = GNOME_DATE_EDIT (gtk_object_get_data(GTK_OBJECT(dialog), "due_date")); - priority = GTK_SPIN_BUTTON (gtk_object_get_data(GTK_OBJECT(dialog), "priority")); - comment = GTK_TEXT(gtk_object_get_data (GTK_OBJECT(dialog), "comment")); - if (ico->summary) - g_free (ico->summary); - if (ico->comment) - g_free (ico->comment); - ico->dtend = gnome_date_edit_get_date (due_date); - ico->summary = g_strdup (gtk_entry_get_text (entry)); - ico->priority = gtk_spin_button_get_value_as_int (priority); - ico->comment = gtk_editable_get_chars( GTK_EDITABLE(comment), 0, -1); - ico->user_data = NULL; - - if (ico->new) { - gnome_calendar_add_object (todo->calendar, ico); - ico->new = FALSE; - } else - gnome_calendar_object_changed (todo->calendar, ico, CHANGE_ALL); /* ok, summary only... */ - - save_default_calendar (todo->calendar); - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -static void -cancel_button (GtkWidget *widget, GnomeDialog *dialog) -{ - iCalObject *ico; - - ico = gtk_object_get_user_data (GTK_OBJECT (dialog)); - - ico->user_data = NULL; - - if (ico->new) - ical_object_destroy (ico); - - gtk_widget_destroy (GTK_WIDGET (dialog)); - - -} - -static gint -delete_event (GtkWidget *widget, GdkEvent *event, GnomeDialog *dialog) -{ - cancel_button (NULL, dialog); - return TRUE; -} - -static void -simple_todo_editor (GncalTodo *todo, iCalObject *ico) -{ - GtkWidget *dialog; - GtkWidget *hbox; - GtkWidget *due_box; - GtkWidget *due_label; - GtkWidget *due_entry; - GtkWidget *comment_box; - GtkWidget *comment_label; - GtkWidget *comment_text; - GtkWidget *comment_internal_box; - GtkWidget *comment_sep; - GtkWidget *w; - GtkWidget *pri_box; - GtkWidget *pri_label; - GtkWidget *pri_spin; - GtkObject *pri_adj; - - GtkWidget *entry; - - dialog = gnome_dialog_new (ico->new ? _("Create to-do item") : _("Edit to-do item"), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (todo->calendar)); - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - - due_box = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (due_box), 4); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), due_box, FALSE, FALSE, 0); - gtk_widget_show (due_box); - - pri_box = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (pri_box), 4); - gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (dialog)->vbox), pri_box, FALSE, FALSE, 0); - gtk_widget_show (pri_box); - - comment_box = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (comment_box), 4); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), comment_box, FALSE, FALSE, 0); - gtk_widget_show (comment_box); - - comment_internal_box = gtk_vbox_new(FALSE,2); - gtk_container_border_width (GTK_CONTAINER (comment_internal_box), 4); - - gtk_box_pack_start (GTK_BOX (comment_box), comment_internal_box, TRUE, TRUE, 0); - gtk_widget_show (comment_internal_box); - - w = gtk_label_new (_("Summary:")); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), ico->summary); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - gtk_widget_show (entry); - - - due_label = gtk_label_new (_("Due Date:")); - gtk_box_pack_start (GTK_BOX (due_box), due_label, FALSE, FALSE, 0); - gtk_widget_show (due_label); - - due_entry = gtk_entry_new (); - due_entry = date_edit_new (ico->dtend, TRUE); - gtk_box_pack_start (GTK_BOX (due_box), due_entry, TRUE, TRUE, 0); - gtk_widget_show (due_entry); - - pri_label = gtk_label_new (_("Priority:")); - gtk_box_pack_start (GTK_BOX (pri_box), pri_label, FALSE, FALSE, 0); - gtk_widget_show (pri_label); - - pri_adj = gtk_adjustment_new (5.0, 1.0, 9.0, 1.0, 3.0, 0.0); - pri_spin = gtk_spin_button_new (GTK_ADJUSTMENT(pri_adj), 0.0, 0); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (pri_spin), TRUE); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (pri_spin), FALSE); - gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (pri_spin), FALSE); - gtk_box_pack_start (GTK_BOX (pri_box), pri_spin, FALSE, FALSE, 0); - gtk_widget_show (pri_spin); - - comment_sep = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (comment_box), comment_sep, FALSE, FALSE, 0); - gtk_widget_show(comment_sep); - - comment_label = gtk_label_new (_("Item Comments:")); - gtk_label_set_justify(GTK_LABEL(comment_label), GTK_JUSTIFY_LEFT); - gtk_box_pack_start (GTK_BOX (comment_internal_box), comment_label, TRUE, TRUE, 0); - gtk_widget_show (comment_label); - - - - - comment_text = gtk_text_new (NULL, NULL); - gtk_text_set_editable (GTK_TEXT (comment_text), TRUE); - gtk_text_set_word_wrap( GTK_TEXT(comment_text), TRUE); - gtk_text_freeze(GTK_TEXT(comment_text)); - if(ico->comment) { - gtk_text_insert(GTK_TEXT(comment_text), NULL, NULL, NULL, ico->comment, strlen(ico->comment)); - } - gtk_text_thaw(GTK_TEXT(comment_text)); - gtk_box_pack_start (GTK_BOX (comment_internal_box), comment_text, FALSE, TRUE, 0); - gtk_widget_show (comment_text); - - ico->user_data = dialog; - - gtk_object_set_user_data (GTK_OBJECT (dialog), ico); - - gtk_object_set_data (GTK_OBJECT (dialog), "gncal_todo", todo); - gtk_object_set_data (GTK_OBJECT (dialog), "summary_entry", entry); - gtk_object_set_data (GTK_OBJECT (dialog), "due_date", due_entry); - gtk_object_set_data (GTK_OBJECT (dialog), "priority", pri_spin); - gtk_object_set_data (GTK_OBJECT (dialog), "comment", comment_text); - - gnome_dialog_button_connect (GNOME_DIALOG (dialog), 0, (GtkSignalFunc) ok_button, dialog); - gnome_dialog_button_connect (GNOME_DIALOG (dialog), 1, (GtkSignalFunc) cancel_button, dialog); - - gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", - (GtkSignalFunc) delete_event, - dialog); - - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE(entry)); - - gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); - gtk_widget_show (dialog); - gtk_widget_grab_focus (entry); -} - -static iCalObject * -get_clist_selected_ico (GtkCList *clist) -{ - gint sel; - - if (!clist->selection) - return NULL; - - sel = GPOINTER_TO_INT(clist->selection->data); - - return gtk_clist_get_row_data (clist, sel); -} - -static void -add_todo (GncalTodo *todo) -{ - iCalObject *ico; - - ico = ical_new ("", user_name, ""); - ico->type = ICAL_TODO; - ico->new = TRUE; - - simple_todo_editor (todo, ico); -} - -static void -edit_todo (GncalTodo *todo) -{ - simple_todo_editor (todo, get_clist_selected_ico (todo->clist)); -} - -static void -delete_todo (GncalTodo *todo) -{ - gnome_calendar_remove_object (todo->calendar, get_clist_selected_ico (todo->clist)); - save_default_calendar (todo->calendar); - -} - -static void -add_activated (GtkWidget *widget, GncalTodo *todo) -{ - GtkWidget *w; - - while ((w = gtk_grab_get_current ()) != NULL) - gtk_grab_remove (w); - - add_todo (todo); -} - -static void -edit_activated (GtkWidget *widget, GncalTodo *todo) -{ - GtkWidget *w; - - while ((w = gtk_grab_get_current ()) != NULL) - gtk_grab_remove (w); - - edit_todo (todo); -} - -static void -delete_activated (GtkWidget *widget, GncalTodo *todo) -{ - delete_todo (todo); -} - - -static void -clist_row_selected (GtkCList *clist, gint row, gint column, GdkEventButton *event, GncalTodo *todo) -{ - static struct menu_item items[] = { - { N_("Add to-do item..."), (GtkSignalFunc) add_activated, NULL, TRUE }, - { N_("Edit this item..."), (GtkSignalFunc) edit_activated, NULL, TRUE }, - { N_("Delete this item"), (GtkSignalFunc) delete_activated, NULL, TRUE } - }; - - int i; - - gtk_widget_set_sensitive (todo->edit_button, (todo->clist->selection != NULL)); - gtk_widget_set_sensitive (todo->delete_button, (todo->clist->selection != NULL)); - - if (!event) - return; - - switch (event->button) { - case 1: - if (event->type == GDK_2BUTTON_PRESS) - edit_todo (todo); - break; - - case 3: - for (i = 0; i < (sizeof (items) / sizeof (items[0])); i++) - items[i].data = todo; - - popup_menu (items, sizeof (items) / sizeof (items[0]), event); - break; - - default: - break; - } -} - -/* - * once we get a call back stating that a column - * has been resized never ever automatically resize again - */ -static void -column_resized (GtkWidget *widget, GncalTodo *todo) -{ - /* disabling autoresize of columns */ - if (todo_list_autoresize && !todo_list_redraw_in_progess){ - todo_list_autoresize = 0; - } -} - -/* - * restore the previously set settings for sorting the - * todo list - */ -static void -init_column_sorting (GtkCList *clist) -{ - - /* due date isn't shown so we can't sort by it */ - if (todo_current_sort_column == 1 && ! todo_show_due_date) - todo_current_sort_column = 0; - - clist->sort_type = todo_current_sort_type; - clist->sort_column = todo_current_sort_column; - - gtk_clist_set_sort_column (clist, todo_current_sort_column); - gtk_clist_sort (clist); -} - -static void -todo_click_column (GtkCList *clist, gint column, gpointer data) -{ - if (column == clist->sort_column) - { - if (clist->sort_type == GTK_SORT_ASCENDING) { - clist->sort_type = GTK_SORT_DESCENDING; - todo_current_sort_type = GTK_SORT_DESCENDING; - } else { - clist->sort_type = GTK_SORT_ASCENDING; - todo_current_sort_type = GTK_SORT_ASCENDING; - } - } - else { - gtk_clist_set_sort_column (clist, column); - todo_current_sort_column = column; - } - - gtk_clist_sort (clist); - - /* - * save the sorting preferences cause I hate to have the user - * click twice - */ - - gnome_config_set_int("/calendar/Todo/sort_column", todo_current_sort_column); - gnome_config_set_int("/calendar/Todo/sort_type", todo_current_sort_type); - gnome_config_sync(); -} - -static void -gncal_todo_init (GncalTodo *todo) -{ - GtkWidget *w; - GtkWidget *sw; - GtkWidget *hbox; - gchar *titles[4] = { - N_("Summary"), - N_("Due Date"), - N_("Priority"), - N_("Time Left") - }; - char *tmp[4]; - tmp[0] = _(titles[0]); - tmp[1] = _(titles[1]); - tmp[2] = _(titles[2]); - tmp[3] = _(titles[3]); - - gtk_box_set_spacing (GTK_BOX (todo), 4); - - /* Label */ - - w = gtk_label_new (_("To-do list")); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (todo), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Clist */ - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_box_pack_start (GTK_BOX (todo), sw, TRUE, TRUE, 0); - gtk_widget_show (sw); - - - w = gtk_clist_new_with_titles(4, tmp); - - todo->clist = GTK_CLIST (w); - gtk_clist_set_selection_mode (todo->clist, GTK_SELECTION_BROWSE); - - gtk_signal_connect (GTK_OBJECT (todo->clist), "select_row", - (GtkSignalFunc) clist_row_selected, - todo); - gtk_clist_set_button_actions (todo->clist, 2, GTK_BUTTON_SELECTS); - gtk_signal_connect (GTK_OBJECT (todo->clist), "resize_column", - (GtkSignalFunc) column_resized, - todo); - gtk_signal_connect (GTK_OBJECT (todo->clist), "click_column", - (GtkSignalFunc) todo_click_column, NULL); - - gtk_container_add (GTK_CONTAINER (sw), w); - gtk_widget_show (w); - - /* Box for buttons */ - - hbox = gtk_hbox_new (TRUE, 4); - gtk_box_pack_start (GTK_BOX (todo), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - /* Add */ - - w = gtk_button_new_with_label (_("Add...")); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) add_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - /* Edit */ - - w = gtk_button_new_with_label (_("Edit...")); - todo->edit_button = w; - gtk_widget_set_sensitive (w, FALSE); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) edit_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - /* Delete */ - - w = gtk_button_new_with_label (_("Delete")); - todo->delete_button = w; - gtk_widget_set_sensitive (w, FALSE); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) delete_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); -} - -GtkWidget * -gncal_todo_new (GnomeCalendar *calendar) -{ - GncalTodo *todo; - - g_return_val_if_fail (calendar != NULL, NULL); - - todo = gtk_type_new (gncal_todo_get_type ()); - - todo->calendar = calendar; - - gncal_todo_update (todo, NULL, 0); - - return GTK_WIDGET (todo); -} - -static char * -convert_time_t_to_char (time_t t) -{ - char buf[100]; - struct tm tm; - - tm = *localtime (&t); - strftime(buf, sizeof (buf), "%m/%d/%Y", &tm); - - return g_strdup (buf); -} - -enum todo_styles { - TODO_STYLE_OVERDUE, - TODO_STYLE_DUE_TODAY, - TODO_STYLE_NOT_DUE -}; - - -enum todo_status { - TODO_ITEM_DSTATUS_NOT_DUE_YET, - TODO_ITEM_DSTATUS_DUE_TODAY, - TODO_ITEM_DSTATUS_OVERDUE, - TODO_ITEM_DSTATUS_LAST_DUE_STATUS -}; -typedef enum todo_status todo_status; - -static GtkStyle * -make_todo_style(GncalTodo *todo, todo_status style_type) -{ - GtkStyle *style = NULL; - GdkColor style_color; - int color_prop = 0; - switch(style_type) { - case TODO_ITEM_DSTATUS_NOT_DUE_YET: - color_prop = COLOR_PROP_TODO_NOT_DUE_YET; - break; - case TODO_ITEM_DSTATUS_DUE_TODAY: - color_prop = COLOR_PROP_TODO_DUE_TODAY; - break; - case TODO_ITEM_DSTATUS_OVERDUE: - color_prop = COLOR_PROP_TODO_OVERDUE; - break; - case TODO_ITEM_DSTATUS_LAST_DUE_STATUS: - } - - style_color.red = color_props[color_prop].r; - style_color.green = color_props[color_prop].g; - style_color.blue = color_props[color_prop].b; - - style = gtk_style_copy (GTK_WIDGET (todo->clist)->style); - style->base[GTK_STATE_NORMAL] = style_color; - return style; -} - - - - -static -todo_status todo_item_due_status(time_t *todo_due_time) { - struct tm due_tm_time; - struct tm current_time; - struct tm *temp_tm; - time_t current_time_val = time(NULL); - temp_tm = localtime(todo_due_time); - /* make a copy so it dosen't get over written */ - memcpy(&due_tm_time, temp_tm, sizeof(struct tm)); - - - temp_tm = localtime(¤t_time_val); - memcpy(¤t_time, temp_tm, sizeof(struct tm)); - - if(due_tm_time.tm_mon == current_time.tm_mon && - due_tm_time.tm_mday == current_time.tm_mday && - due_tm_time.tm_year == current_time.tm_year) { - return TODO_ITEM_DSTATUS_DUE_TODAY; - } - - if((*todo_due_time) < current_time_val) { - return TODO_ITEM_DSTATUS_OVERDUE; - } - - return TODO_ITEM_DSTATUS_NOT_DUE_YET; -} - - -enum todo_remaining_time_form { - TODO_ITEM_REMAINING_WEEKS, - TODO_ITEM_REMAINING_DAYS, - TODO_ITEM_REMAINING_HOURS, - TODO_ITEM_REMAINING_MINUTES, - TODO_ITEM_REMAINING_SECONDS -}; -typedef enum todo_remaining_time_form todo_remaining_time_form; - -static void -insert_in_clist (GncalTodo *todo, iCalObject *ico) -{ - int i; - char *text[4]; - char time_remaining_buffer[100]; - time_t time_remain; - todo_remaining_time_form time_remaining_form; - int sec_in_week = 3600*7*24; - int sec_in_day = 3600*24; - int sec_in_hour = 3600; - int sec_in_minute = 60; - int weeks = 0; - int days = 0; - int hours = 0; - int minutes = 0; - int seconds = 0; - - - /* an array for the styles of items */ - static GtkStyle *dstatus_styles[TODO_ITEM_DSTATUS_LAST_DUE_STATUS]; - /* we want to remake the styles when the status is changed, - also we need to check for the null value in the pointer so we init them - at startup */ - if (todo_style_changed || !dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]) { - g_free(dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]); - g_free(dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE]); - g_free(dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY]); - - dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET] = make_todo_style(todo, TODO_ITEM_DSTATUS_NOT_DUE_YET); - dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE] = make_todo_style(todo, TODO_ITEM_DSTATUS_OVERDUE); - dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY] = make_todo_style(todo, TODO_ITEM_DSTATUS_DUE_TODAY); - - todo_style_changed = 0; - } - - - - - - text[0] = ico->summary; - - if(todo_show_time_remaining) { - memset(time_remaining_buffer, 0, 100); - /* we need to make a string that represents the amount of time remaining - before this task is due */ - - /* for right now all I'll do is up to the hours. */ - time_remain = (ico->dtend - time(NULL)); - if(time_remain < 0) { - text[3] = "Overdue!"; - } - else { - - /* lets determine a decent denomination to display */ - if(time_remain / (sec_in_week)) - { - /* we have weeks available */ - time_remaining_form = TODO_ITEM_REMAINING_WEEKS; - weeks = time_remain / sec_in_week; - days = (time_remain % (sec_in_week))/sec_in_day; - } - else if(time_remain / (sec_in_day)) - { - /* we have days available */ - time_remaining_form = TODO_ITEM_REMAINING_DAYS; - days = time_remain / sec_in_day; - hours = (time_remain % sec_in_day)/sec_in_hour; - } - else if(time_remain / (sec_in_hour)) - { - /* we have hours available */ - time_remaining_form = TODO_ITEM_REMAINING_HOURS; - hours = time_remain /sec_in_hour; - minutes = (time_remain % sec_in_hour) / sec_in_minute; - } - else if(time_remain / sec_in_minute) - { - time_remaining_form = TODO_ITEM_REMAINING_MINUTES; - minutes = time_remain / sec_in_minute; - seconds = time_remain % sec_in_minute; - } - else - { - time_remaining_form = TODO_ITEM_REMAINING_SECONDS; - seconds = time_remain; - } - - switch(time_remaining_form) - { - case TODO_ITEM_REMAINING_WEEKS: - snprintf(time_remaining_buffer, 100, "%d %s %d %s", weeks, - (weeks > 1) ? _("Weeks") : _("Week"), - days, (days > 1) ? _("Days") : _("Day")); - break; - case TODO_ITEM_REMAINING_DAYS: - snprintf(time_remaining_buffer, 100, "%d %s %d %s", days, - (days > 1) ? _("Days") : _("Day"), - hours, (hours > 1) ? _("Hours") : _("Hour")); - break; - case TODO_ITEM_REMAINING_HOURS: - snprintf(time_remaining_buffer, 100, "%d %s %d %s", hours, - (hours > 1) ? _("Hours") : _("Hour"), - minutes, (minutes > 1) ? _("Minutes") : _("Minute")); - break; - case TODO_ITEM_REMAINING_MINUTES: - snprintf(time_remaining_buffer, 100, "%d %s %d %s", minutes, - (minutes > 1) ? _("Minutes") : _("Minute"), - seconds, (seconds > 1) ? _("Seconds") : _("Second")); - break; - case TODO_ITEM_REMAINING_SECONDS: - snprintf(time_remaining_buffer, 100, "%d %s", seconds, - (seconds > 1) ? _("Seconds") : _("Second")); - break; - } - text[3] = g_strdup(time_remaining_buffer); - todo->data_ptrs = g_slist_append(todo->data_ptrs, text[3]); - } - - } - else { - text[3] = "Loose penguini!"; - } - /* - * right now column 0 will be the summary - * and column 1 will be the due date. - * WISH: this should be able to be changed on the fly - */ - - if(ico->dtend && todo_show_due_date) - { - text[1] = convert_time_t_to_char (ico->dtend); - /* Append the data's pointer so later it can be properly freed */ - todo->data_ptrs = g_slist_append (todo->data_ptrs, text[1]); - } - else - text[1] = NULL; - - if(ico->priority && todo_show_priority) - { - text[2] = g_strdup_printf ("%d", ico->priority); - todo->data_ptrs = g_slist_append (todo->data_ptrs, text[2]); - } - else - text[2] = NULL; - - i = gtk_clist_append (todo->clist, text); - - gtk_clist_set_row_data (todo->clist, i, ico); - - /* - * determine if the task is overdue.. - * if so mark with the apropriate style - */ - - switch(todo_item_due_status(&ico->dtend)) { - case TODO_ITEM_DSTATUS_NOT_DUE_YET: - if(todo_item_dstatus_highlight_not_due_yet) - { - gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_NOT_DUE_YET]); - } - break; - case TODO_ITEM_DSTATUS_DUE_TODAY: - if(todo_item_dstatus_highlight_due_today) - { - gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_DUE_TODAY]); - } - break; - case TODO_ITEM_DSTATUS_OVERDUE: - if(todo_item_dstatus_highlight_overdue) - { - gtk_clist_set_row_style(todo->clist, i, dstatus_styles[TODO_ITEM_DSTATUS_OVERDUE]); - } - break; - case TODO_ITEM_DSTATUS_LAST_DUE_STATUS: - } - - /* keep the list in order */ - gtk_clist_sort (todo->clist); -} - -void -gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags) -{ - GList *list; - GSList *current_list; - - g_return_if_fail (todo != NULL); - g_return_if_fail (GNCAL_IS_TODO (todo)); - - /* - * shut down the resize handler cause we are playing with the list. - * In otherwords turn off the event handler - */ - todo_list_redraw_in_progess =1; - - /* freeze the list */ - gtk_clist_freeze (todo->clist); - init_column_sorting (todo->clist); - - /* - * before here we have to free some of the memory that - * stores the due date, or else we have a memory leak. - * luckily all of the pointers are stored in todo->data_ptrs; - */ - - /* check on the columns that we should display */ - /* check for due date */ - - if(todo_show_due_date) { - gtk_clist_set_column_visibility (todo->clist, 1, 1); - } - else { - gtk_clist_set_column_visibility (todo->clist, 1, 0); - } - - if(todo_show_time_remaining) { - gtk_clist_set_column_visibility (todo->clist, 3, 1); - } - else { - gtk_clist_set_column_visibility (todo->clist, 3, 0); - } - - - if(todo_show_priority) - gtk_clist_set_column_visibility (todo->clist, 2, 1); - else - gtk_clist_set_column_visibility (todo->clist, 2, 0); - - /* free the memory locations that were used in the previous display */ - for (current_list = todo->data_ptrs; current_list != NULL; current_list = g_slist_next(current_list)){ - g_free(current_list->data); - } - - /* free the list and clear out the pointer */ - g_slist_free(todo->data_ptrs); - todo->data_ptrs = NULL; - - gtk_clist_clear (todo->clist); - - for (list = todo->calendar->cal->todo; list; list = list->next) - insert_in_clist (todo, list->data); - - /* if we are autoresizing then do it now */ - if(todo_list_autoresize && todo->clist->rows != 0) - gtk_clist_columns_autosize (todo->clist); - - gtk_clist_thaw (todo->clist); - - gtk_widget_set_sensitive (todo->edit_button, (todo->clist->selection != NULL)); - gtk_widget_set_sensitive (todo->delete_button, (todo->clist->selection != NULL)); - todo_list_redraw_in_progess = 0; -} - - - - - - - - diff --git a/calendar/gncal-todo.h b/calendar/gncal-todo.h deleted file mode 100644 index 51cfadea3f..0000000000 --- a/calendar/gncal-todo.h +++ /dev/null @@ -1,55 +0,0 @@ -/* To-do widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_TODO_H -#define GNCAL_TODO_H - -#include <gtk/gtkclist.h> -#include <gtk/gtkvbox.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_TODO(obj) GTK_CHECK_CAST (obj, gncal_todo_get_type (), GncalTodo) -#define GNCAL_TODO_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_todo_get_type (), GncalTodoClass) -#define GNCAL_IS_TODO(obj) GTK_CHECK_TYPE (obj, gncal_todo_get_type ()) - - -typedef struct _GncalTodo GncalTodo; -typedef struct _GncalTodoClass GncalTodoClass; - -struct _GncalTodo { - GtkVBox vbox; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - GtkCList *clist; - - GtkWidget *edit_button; - GtkWidget *delete_button; - GSList *data_ptrs; - - -}; - -struct _GncalTodoClass { - GtkVBoxClass parent_class; -}; - - -guint gncal_todo_get_type (void); -GtkWidget *gncal_todo_new (GnomeCalendar *calendar); - -void gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gncal-week-view.c b/calendar/gncal-week-view.c deleted file mode 100644 index 553977e076..0000000000 --- a/calendar/gncal-week-view.c +++ /dev/null @@ -1,255 +0,0 @@ -/* Week view composite widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <config.h> -#include <gnome.h> -#include <string.h> -#include <gtk/gtk.h> -#include "gncal-week-view.h" -#include "main.h" -#include "cal-util/timeutil.h" - -static void gncal_week_view_init (GncalWeekView *wview); - - -guint -gncal_week_view_get_type (void) -{ - static guint week_view_type = 0; - - if (!week_view_type) { - GtkTypeInfo week_view_info = { - "GncalWeekView", - sizeof (GncalWeekView), - sizeof (GncalWeekViewClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) gncal_week_view_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - week_view_type = gtk_type_unique (gtk_vbox_get_type (), &week_view_info); - } - - return week_view_type; -} - -static void -gncal_week_view_init (GncalWeekView *wview) -{ - int i; - - wview->calendar = NULL; - memset (&wview->start_of_week, 0, sizeof (wview->start_of_week)); - - for (i = 0; i < 7; i++) - wview->days[i] = NULL; - - wview->gtk_calendar = NULL; -} - -static void -jump_to_day (GtkCalendar *cal, GncalWeekView *wview, int day) -{ - struct tm tm; - time_t t; - static int inside; - - if (inside) - return; - inside = 1; - tm.tm_mday = day; - tm.tm_mon = cal->month; - tm.tm_year = cal->year - 1900; - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_isdst = -1; - t = mktime (&tm); - - gncal_week_view_set (wview, t); - inside = 0; -} - -static void -jump_to_day_click (GtkCalendar *cal, GncalWeekView *wview) -{ - jump_to_day (cal, wview, cal->selected_day); -} - -static void -sync_week (GtkCalendar *cal, GncalWeekView *wview) -{ - jump_to_day (cal, wview, wview->start_of_week.tm_mday + 7); - gnome_calendar_tag_calendar (wview->calendar, wview->gtk_calendar); -} - -static void -double_click_on_weekday (GtkWidget *widget, GdkEvent *e, GncalWeekView *wview) -{ -} - -GtkWidget * -gncal_week_view_new (GnomeCalendar *calendar, time_t start_of_week) -{ - GncalWeekView *wview; - GtkWidget *table; - int i; - - g_return_val_if_fail (calendar != NULL, NULL); - - wview = gtk_type_new (gncal_week_view_get_type ()); - - table = gtk_table_new (0, 0, 0); - gtk_table_set_homogeneous (GTK_TABLE (table), TRUE); - wview->label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (wview), wview->label, 0, 0, 0); - gtk_box_pack_start (GTK_BOX (wview), table, 1, 1, 0); - wview->calendar = calendar; - for (i = 0; i < 7; i++) { - wview->days[i] = GNCAL_DAY_VIEW (gncal_day_view_new (calendar, 0, 0)); - gtk_signal_connect (GTK_OBJECT (wview->days [i]), "button_press_event", - GTK_SIGNAL_FUNC(double_click_on_weekday), wview); - - if (i < 5) - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->days[i]), - i, i + 1, - 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - else - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->days[i]), - i - 2, i - 1, - 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - - gtk_widget_show (GTK_WIDGET (wview->days[i])); - } - - wview->gtk_calendar = GTK_CALENDAR (gtk_calendar_new ()); - - gtk_signal_connect (GTK_OBJECT (wview->gtk_calendar), "day_selected_double_click", - GTK_SIGNAL_FUNC(jump_to_day_click), wview); - gtk_signal_connect (GTK_OBJECT (wview->gtk_calendar), "month_changed", - GTK_SIGNAL_FUNC(sync_week), wview); - - gtk_calendar_display_options (wview->gtk_calendar, - (GTK_CALENDAR_SHOW_HEADING - | GTK_CALENDAR_SHOW_DAY_NAMES - | (week_starts_on_monday - ? GTK_CALENDAR_WEEK_START_MONDAY : 0))); - - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->gtk_calendar), - 0, 3, - 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 4, 4); - gtk_widget_show (GTK_WIDGET (wview->gtk_calendar)); - - gncal_week_view_set (wview, start_of_week); - - return GTK_WIDGET (wview); -} - -static void -update (GncalWeekView *wview, int update_days, iCalObject *object, int flags) -{ - int i; - - if (update_days) - for (i = 0; i < 7; i++) - gncal_day_view_update (wview->days[i], object, flags); - - /* FIXME: update extra widgets */ -} - -void -gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags) -{ - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - update (wview, TRUE, ico, flags); -} - -void -gncal_week_view_set (GncalWeekView *wview, time_t start_of_week) -{ - struct tm tm; - time_t day_start, day_end, week_start, week_end; - int i; - - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - tm = *localtime (&start_of_week); - - /* back up to start of week (Monday) */ - - tm.tm_mday -= (tm.tm_wday == 0) ? 6 : (tm.tm_wday - 1); - - /* Start of day */ - - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - - day_start = week_start = mktime (&tm); - - /* Calendar */ - - gtk_calendar_select_month (wview->gtk_calendar, tm.tm_mon, tm.tm_year + 1900); - - /* Day views */ - - for (i = 0; i < 7; i++) { /* rest of days */ - tm.tm_mday++; - day_end = mktime (&tm); - - gncal_day_view_set_bounds (wview->days[i], day_start, day_end - 1); - - day_start = day_end; - } - - update (wview, FALSE, NULL, 0); - - /* The label */ - { - char buf [3][100]; - - week_end = time_add_day (week_start, 6); - - strftime (buf[0], sizeof (buf[0]), _("%a %b %d %Y"), - localtime(&week_start)); - - strftime (buf[1], sizeof (buf[1]), _("%a %b %d %Y"), - localtime(&week_end)); - - g_snprintf(buf[2], sizeof(buf[2]), "%s - %s", buf[0], buf[1]); - gtk_label_set (GTK_LABEL (wview->label), buf[2]); - - } -} - -void -gncal_week_view_time_format_changed (GncalWeekView *wview) -{ - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - gtk_calendar_display_options (wview->gtk_calendar, - (week_starts_on_monday - ? (wview->gtk_calendar->display_flags - | GTK_CALENDAR_WEEK_START_MONDAY) - : (wview->gtk_calendar->display_flags - & ~GTK_CALENDAR_WEEK_START_MONDAY))); -} diff --git a/calendar/gncal-week-view.h b/calendar/gncal-week-view.h deleted file mode 100644 index ab06161844..0000000000 --- a/calendar/gncal-week-view.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Week view composite widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef WEEK_VIEW_H -#define WEEK_VIEW_H - - -#include <gtk/gtkvbox.h> -#include <gtk/gtktable.h> -#include <gtk/gtkvbox.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gncal-day-view.h" - -BEGIN_GNOME_DECLS - - -#define GNCAL_WEEK_VIEW(obj) GTK_CHECK_CAST (obj, gncal_week_view_get_type (), GncalWeekView) -#define GNCAL_WEEK_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_week_view_get_type (), GncalWeekViewClass) -#define GNCAL_IS_WEEK_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_week_view_get_type ()) - - -typedef struct _GncalWeekView GncalWeekView; -typedef struct _GncalWeekViewClass GncalWeekViewClass; - -struct _GncalWeekView { - GtkVBox box; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - struct tm start_of_week; - - GncalDayView *days[7]; /* the day view widgets */ - GtkCalendar *gtk_calendar; /* At least for now; see the FIXME comments in the .c file */ - GtkWidget *label; -}; - -struct _GncalWeekViewClass { - GtkVBoxClass parent_class; -}; - - -guint gncal_week_view_get_type (void); -GtkWidget *gncal_week_view_new (GnomeCalendar *calendar, time_t start_of_week); - -void gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags); -void gncal_week_view_set (GncalWeekView *wview, time_t start_of_week); -void gncal_week_view_time_format_changed (GncalWeekView *wview); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gncal.desktop b/calendar/gncal.desktop deleted file mode 100644 index 9ee2a2db9b..0000000000 --- a/calendar/gncal.desktop +++ /dev/null @@ -1,37 +0,0 @@ -[Desktop Entry] -Name=Calendar -Name[da]=Kalender -Name[de]=Kalender -Name[el]=Çìåñïëüãéï -Name[es]=Calendario -Name[et]=Kalender -Name[fi]=Kalenteri -Name[fr]=Calendrier -Name[gl]=Axenda -Name[ja]=¥«¥ì¥ó¥À¡¼ -Name[ko]=´Þ·Â -Name[no]=Kalender -Name[pt]=Agenda -Name[pt_BR]=Calendário -Name[ru]=ëÁÌÅÎÄÁÒØ -Name[sv]=Kalender -Comment=Calendar application -Comment[da]=Gnome Kalender -Comment[de]=Gnome Kalender -Comment[el]=Çìåñïëüãéï ôïõ Gnome -Comment[es]=Calendario de Gnome -Comment[et]=GNOME kalender -Comment[fi]=GNOME-kalenteri -Comment[fr]=Calendrier GNOME -Comment[gl]=Axenda de GNOME -Comment[ja]=GNOME¥«¥ì¥ó¥À¡¼ -Comment[ko]=±×³ð ´Þ·Â -Comment[no]=Gnome Kalender -Comment[pt]=Agenda Gnome -Comment[pt_BR]=Calendário GNOME -Comment[ru]=ëÁÌÅÎÄÁÒØ Gnome -Comment[sv]=Gnome-kalender -Exec=gnomecal -Icon=gnome-calendar.png -Terminal=0 -Type=Application diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c deleted file mode 100644 index 8682099900..0000000000 --- a/calendar/gnome-cal.c +++ /dev/null @@ -1,616 +0,0 @@ -/* - * GnomeCalendar widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ -#include <config.h> -#include <gnome.h> -#include <unistd.h> -#include <signal.h> -#include <sys/wait.h> -#include <fcntl.h> -#include "alarm.h" -#include "calendar.h" -#include "gnome-cal.h" -#include "gncal-day-panel.h" -#include "gncal-week-view.h" -#include "month-view.h" -#include "year-view.h" -#include "cal-util/timeutil.h" -#include "main.h" -#include "corba-cal.h" - -GnomeApp *parent_class; - -guint -gnome_calendar_get_type (void) -{ - static guint gnome_calendar_type = 0; - if(!gnome_calendar_type) { - GtkTypeInfo gnome_calendar_info = { - "GnomeCalendar", - sizeof(GnomeCalendar), - sizeof(GnomeCalendarClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) NULL, - (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()); - } - return gnome_calendar_type; -} - -static void -setup_widgets (GnomeCalendar *gcal) -{ - time_t now; - - now = time (NULL); - - gcal->notebook = gtk_notebook_new (); - gcal->day_view = gncal_day_panel_new (gcal, now); - gcal->week_view = gncal_week_view_new (gcal, now); - gcal->month_view = month_view_new (gcal, now); - gcal->year_view = year_view_new (gcal, now); - - gcal->year_view_sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (gcal->year_view_sw), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (gcal->year_view_sw), gcal->year_view); - GTK_LAYOUT (gcal->year_view)->vadjustment->step_increment = 10.0; - gtk_adjustment_changed (GTK_ADJUSTMENT (GTK_LAYOUT (gcal->year_view)->vadjustment)); - - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->day_view, gtk_label_new (_("Day View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->week_view, gtk_label_new (_("Week View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->month_view, gtk_label_new (_("Month View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->year_view_sw, gtk_label_new (_("Year View"))); - - gtk_widget_show_all (gcal->notebook); - - gnome_app_set_contents (GNOME_APP (gcal), gcal->notebook); -} - -static GtkWidget * -get_current_page (GnomeCalendar *gcal) -{ - return GTK_NOTEBOOK (gcal->notebook)->cur_page->child; -} - -char * -gnome_calendar_get_current_view_name (GnomeCalendar *gcal) -{ - GtkWidget *page; - - g_return_val_if_fail (gcal != NULL, "dayview"); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), "dayview"); - - page = get_current_page (gcal); - - if (page == gcal->day_view) - return "dayview"; - else if (page == gcal->week_view) - return "weekview"; - else if (page == gcal->month_view) - return "monthview"; - else if (page == gcal->year_view_sw) - return "yearview"; - else - return "dayview"; -} - -void -gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time) -{ - GtkWidget *current; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (new_time != -1); - - current = get_current_page (gcal); - new_time = time_day_begin (new_time); - - if (current == gcal->day_view) - gncal_day_panel_set (GNCAL_DAY_PANEL (gcal->day_view), new_time); - else if (current == gcal->week_view) - gncal_week_view_set (GNCAL_WEEK_VIEW (gcal->week_view), new_time); - else if (current == gcal->month_view) - month_view_set (MONTH_VIEW (gcal->month_view), new_time); - else if (current == gcal->year_view_sw) - year_view_set (YEAR_VIEW (gcal->year_view), new_time); - else { - g_warning ("My penguin is gone!"); - g_assert_not_reached (); - } - - gcal->current_display = new_time; -} - -static void -gnome_calendar_direction (GnomeCalendar *gcal, int direction) -{ - GtkWidget *cp = get_current_page (gcal); - time_t new_time; - - if (cp == gcal->day_view) - new_time = time_add_day (time_day_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->week_view) - new_time = time_add_week (time_week_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->month_view) - new_time = time_add_month (time_month_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->year_view_sw) - new_time = time_add_year (time_year_begin (gcal->current_display), 1 * direction); - else { - g_warning ("Weee! Where did the penguin go?"); - g_assert_not_reached (); - new_time = 0; - } - - gnome_calendar_goto (gcal, new_time); -} - -void -gnome_calendar_next (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_direction (gcal, 1); -} - -void -gnome_calendar_previous (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_direction (gcal, -1); -} - -void -gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gtk_notebook_set_page (GTK_NOTEBOOK (gcal->notebook), 0); - gnome_calendar_goto (gcal, time); -} - -void -gnome_calendar_goto_today (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - gnome_calendar_goto (gcal, time (NULL)); -} - -void -gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name) -{ - int page = 0; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (page_name != NULL); - - - if (strcmp (page_name, "dayview") == 0) - page = 0; - else if (strcmp (page_name, "weekview") == 0) - page = 1; - else if (strcmp (page_name, "monthview") == 0) - page = 2; - else if (strcmp (page_name, "yearview") == 0) - page = 3; - gtk_notebook_set_page (GTK_NOTEBOOK (gcal->notebook), page); -} - -GtkWidget * -gnome_calendar_new (char *title) -{ - GtkWidget *retval; - GnomeCalendar *gcal; - GnomeApp *app; - - retval = gtk_type_new (gnome_calendar_get_type ()); - 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); - - gcal->current_display = time_day_begin (time (NULL)); - gcal->cal = calendar_new (title, CALENDAR_INIT_ALARMS); - setup_widgets (gcal); - gnome_calendar_create_corba_server (gcal); - - return retval; -} - -static void -gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags) -{ - gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), object, flags); - gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags); - month_view_update (MONTH_VIEW (cal->month_view), object, flags); - year_view_update (YEAR_VIEW (cal->year_view), object, flags); -} - -int -gnome_calendar_load (GnomeCalendar *gcal, char *file) -{ - char *r; - - g_return_val_if_fail (gcal != NULL, 0); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), 0); - g_return_val_if_fail (file != NULL, 0); - - if ((r = calendar_load (gcal->cal, file)) != NULL){ - printf ("Error loading calendar: %s\n", r); - return 0; - } - gnome_calendar_update_all (gcal, NULL, 0); - return 1; -} - -void -gnome_calendar_add_object (GnomeCalendar *gcal, iCalObject *obj) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (obj != NULL); - - calendar_add_object (gcal->cal, obj); - gnome_calendar_update_all (gcal, obj, CHANGE_NEW); -} - -void -gnome_calendar_remove_object (GnomeCalendar *gcal, iCalObject *obj) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (obj != NULL); - - calendar_remove_object (gcal->cal, obj); - gnome_calendar_update_all (gcal, obj, CHANGE_ALL); -} - -void -gnome_calendar_object_changed (GnomeCalendar *gcal, iCalObject *obj, int flags) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (obj != NULL); - - gcal->cal->modified = TRUE; - - gnome_calendar_update_all (gcal, obj, flags); - calendar_object_changed (gcal->cal, obj, flags); -} - -static int -max_open_files (void) -{ - static int files; - - if (files) - return files; - - files = sysconf (_SC_OPEN_MAX); - if (files != -1) - return files; -#ifdef OPEN_MAX - return files = OPEN_MAX; -#else - return files = 256; -#endif -} - -static void -execute (char *command, int close_standard) -{ - struct sigaction ignore, save_intr, save_quit; - int status = 0, i; - pid_t pid; - - ignore.sa_handler = SIG_IGN; - sigemptyset (&ignore.sa_mask); - ignore.sa_flags = 0; - - sigaction (SIGINT, &ignore, &save_intr); - sigaction (SIGQUIT, &ignore, &save_quit); - - if ((pid = fork ()) < 0){ - fprintf (stderr, "\n\nfork () = -1\n"); - return; - } - if (pid == 0){ - pid = fork (); - if (pid == 0){ - const int top = max_open_files (); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); - - for (i = (close_standard ? 0 : 3); i < top; i++) - close (i); - - /* FIXME: As an excercise to the reader, copy the - * code from mc to setup shell properly instead of - * /bin/sh. Yes, this comment is larger than a cut and paste. - */ - execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); - - _exit (127); - } else { - _exit (127); - } - } - wait (&status); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); -} - -static void -mail_notify (char *mail_address, char *text, time_t app_time) -{ - pid_t pid; - int p [2]; - char *command; - - pipe (p); - pid = fork (); - if (pid == 0){ - int dev_null; - - dev_null = open ("/dev/null", O_RDWR); - dup2 (p [0], 0); - dup2 (dev_null, 1); - dup2 (dev_null, 2); - execl ("/usr/lib/sendmail", "/usr/lib/sendmail", - mail_address, NULL); - _exit (127); - } - command = g_strconcat ("To: ", mail_address, "\n", - "Subject: ", _("Reminder of your appointment at "), - ctime (&app_time), "\n\n", text, "\n", NULL); - write (p [1], command, strlen (command)); - close (p [1]); - close (p [0]); - g_free (command); -} - -static void -stop_beeping (GtkObject* object, gpointer data) -{ - guint timer_tag, beep_tag; - timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag")); - beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag")); - - if (beep_tag > 0) { - gtk_timeout_remove (beep_tag); - gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0)); - } - if (timer_tag > 0) { - gtk_timeout_remove (timer_tag); - gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0)); - } -} - -static gint -start_beeping (gpointer data) -{ - gdk_beep (); - - return TRUE; -} - -static gint -timeout_beep (gpointer data) -{ - stop_beeping (data, NULL); - return FALSE; -} - -void -calendar_notify (time_t activation_time, CalendarAlarm *which, void *data) -{ - iCalObject *ico = data; - guint beep_tag, timer_tag; - int ret; - gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL); - time_t now, diff; - - if (&ico->aalarm == which){ - time_t app = ico->aalarm.trigger + ico->aalarm.offset; - GtkWidget *w; - char *msg; - - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - - /* Idea: we need Snooze option :-) */ - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL); - beep_tag = gtk_timeout_add (1000, start_beeping, NULL); - if (enable_aalarm_timeout) - timer_tag = gtk_timeout_add (audio_alarm_timeout*1000, - timeout_beep, w); - else - timer_tag = 0; - gtk_object_set_data (GTK_OBJECT (w), "timer_tag", - GINT_TO_POINTER (timer_tag)); - gtk_object_set_data (GTK_OBJECT (w), "beep_tag", - GINT_TO_POINTER (beep_tag)); - gtk_widget_ref (w); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - stop_beeping (GTK_OBJECT (w), NULL); - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - stop_beeping (GTK_OBJECT (w), NULL); - break; - } - - gtk_widget_unref (w); - return; - } - - if (&ico->palarm == which){ - execute (ico->palarm.data, 0); - return; - } - - if (&ico->malarm == which){ - time_t app = ico->malarm.trigger + ico->malarm.offset; - - mail_notify (ico->malarm.data, ico->summary, app); - return; - } - - if (&ico->dalarm == which){ - time_t app = ico->dalarm.trigger + ico->dalarm.offset; - GtkWidget *w; - char *msg; - - if (beep_on_display) - gdk_beep (); - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, - _("Ok"), snooze_button, NULL); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - break; - } - - return; - } -} - -/* - * called from the calendar_iterate routine to mark the days of a GtkCalendar - */ -static int -mark_gtk_calendar_day (iCalObject *obj, time_t start, time_t end, void *c) -{ - GtkCalendar *gtk_cal = c; - struct tm tm_s; - time_t t, day_end; - - tm_s = *localtime (&start); - day_end = time_day_end (end); - - for (t = start; t <= day_end; t += 60*60*24){ - time_t new = mktime (&tm_s); - struct tm tm_day; - - tm_day = *localtime (&new); - gtk_calendar_mark_day (gtk_cal, tm_day.tm_mday); - tm_s.tm_mday++; - } - return TRUE; -} - -/* - * Tags the dates with appointments in a GtkCalendar based on the - * GnomeCalendar contents - */ -void -gnome_calendar_tag_calendar (GnomeCalendar *cal, GtkCalendar *gtk_cal) -{ - time_t month_begin, month_end; - struct tm tm; - - g_return_if_fail (cal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (cal)); - g_return_if_fail (gtk_cal != NULL); - g_return_if_fail (GTK_IS_CALENDAR (gtk_cal)); - - /* compute month_begin */ - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday = 1; /* setting this to zero is a no-no; it will set mktime back to the end of the - previous month, which may be 28,29,30; this may chop some days from the calendar */ - tm.tm_mon = gtk_cal->month; - tm.tm_year = gtk_cal->year - 1900; - tm.tm_isdst= -1; - - month_begin = mktime (&tm); - tm.tm_mon++; - month_end = mktime (&tm); - - gtk_calendar_freeze (gtk_cal); - gtk_calendar_clear_marks (gtk_cal); - calendar_iterate (cal->cal, month_begin, month_end, mark_gtk_calendar_day, gtk_cal); - gtk_calendar_thaw (gtk_cal); -} - -void -gnome_calendar_time_format_changed (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - /* FIXME: the queue resizes will do until we rewrite those views... */ - - gncal_day_panel_time_format_changed (GNCAL_DAY_PANEL (gcal->day_view)); - gtk_widget_queue_resize (gcal->day_view); - gncal_week_view_time_format_changed (GNCAL_WEEK_VIEW (gcal->week_view)); - gtk_widget_queue_resize (gcal->week_view); - month_view_time_format_changed (MONTH_VIEW (gcal->month_view)); - year_view_time_format_changed (YEAR_VIEW (gcal->year_view)); -} - -void -gnome_calendar_colors_changed (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - /* FIXME: add day and week view when they are done */ - - month_view_colors_changed (MONTH_VIEW (gcal->month_view)); - year_view_colors_changed (YEAR_VIEW (gcal->year_view)); - todo_style_changed = 1; - todo_list_properties_changed (GNCAL_DAY_PANEL (gcal->day_view)); -} - -void -gnome_calendar_todo_properties_changed (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - /* FIXME: add day and week view when they are done */ - - todo_style_changed = 1; - todo_list_properties_changed (GNCAL_DAY_PANEL (gcal->day_view)); -} - - diff --git a/calendar/gnome-cal.h b/calendar/gnome-cal.h deleted file mode 100644 index da53f29882..0000000000 --- a/calendar/gnome-cal.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * GnomeCalendar widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ - -#ifndef GNOME_CALENDAR_APP_H -#define GNOME_CALENDAR_APP_H - -#include <gnome.h> - -#include "calendar.h" - -BEGIN_GNOME_DECLS - -#define GNOME_CALENDAR(obj) GTK_CHECK_CAST(obj, gnome_calendar_get_type(), GnomeCalendar) -#define GNOME_CALENDAR_CLASS(class) GTK_CHECK_CAST_CLASS(class, gnome_calendar_get_type(), GnomeCalendarClass) -#define GNOME_IS_CALENDAR(obj) GTK_CHECK_TYPE(obj, gnome_calendar_get_type()) - -typedef struct { - GnomeApp gnome_app; - Calendar *cal; - time_t current_display; - - GtkWidget *notebook; - GtkWidget *day_view; - GtkWidget *week_view; - GtkWidget *month_view; - GtkWidget *year_view; - GtkWidget *year_view_sw; - void *event_editor; -} GnomeCalendar; - -typedef struct { - GnomeAppClass parent_class; -} GnomeCalendarClass; - -guint gnome_calendar_get_type (void); -GtkWidget *gnome_calendar_new (char *title); -int gnome_calendar_load (GnomeCalendar *gcal, - char *file); -void gnome_calendar_add_object (GnomeCalendar *gcal, - iCalObject *obj); -void gnome_calendar_remove_object (GnomeCalendar *gcal, - iCalObject *obj); -void gnome_calendar_next (GnomeCalendar *gcal); -void gnome_calendar_previous (GnomeCalendar *gcal); -void gnome_calendar_goto (GnomeCalendar *gcal, - time_t new_time); -void gnome_calendar_dayjump (GnomeCalendar *gcal, - time_t time); -/* Jumps to the current day */ -void gnome_calendar_goto_today (GnomeCalendar *gcal); -void gnome_calendar_tag_calendar (GnomeCalendar *cal, - GtkCalendar *gtk_cal); -char *gnome_calendar_get_current_view_name (GnomeCalendar *gcal); -void gnome_calendar_set_view (GnomeCalendar *gcal, - char *page_name); - -/* Flags is a bitmask of CalObjectChange values */ -void gnome_calendar_object_changed (GnomeCalendar *gcal, - iCalObject *obj, - int flags); - -GnomeCalendar *gnome_calendar_locate (const char *pathname); - -/* Notifies the calendar that the time format has changed and it must update all its views */ -void gnome_calendar_time_format_changed (GnomeCalendar *gcal); - -/* Notifies the calendar that the todo list properties have changed and its time to update the views */ -void -gnome_calendar_colors_changed (GnomeCalendar *gcal); - -/* Notifies the calendar that the todo list properties have changed and its time to update the views */ -void -gnome_calendar_todo_properties_changed (GnomeCalendar *gcal); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gnome-cal.html b/calendar/gnome-cal.html deleted file mode 100644 index 5a7d0a537f..0000000000 --- a/calendar/gnome-cal.html +++ /dev/null @@ -1,44 +0,0 @@ -<!-- Some simple instructions on how to use the help browser --> -<BODY> -<!-- <TITLE>GNOME Calendar Documentation</TITLE> --> -<H2> GNOME Calendar Documentation </H2> -<p> -The GNOME calendar program is the calendaring program of the GNOME -system. It uses the vCalendar standard for transfering calendar -information (and is also the on-disk format used). - -<p> - -<a name="cmdline"> -<h2>Command line options</h2> - -Several options are available on the command line, they are: -<ul> - <li><tt>--events</tt> Displays the events for the date - specified (or today, if no date is specified). - - <li><tt>--from DATE</tt> Define the beginning of the range for - the event display, or the startup day on the calenday views. - By default, the event will span the whole day specified in - DATE. - - <li><tt>--to DATE</tt> Define the range end for the event - display. If this is not specified, it will default to the end - of the day specified by the <tt>--from</tt> option. - - <li><tt>--file FILE</tt> Set the calendar to the FILE - specified on the command line. - - <li><tt>--todo</tt> Dumps the to-do values to standard output. -</ul> - -<p> - -DATE is interpreted as being in the local time- zone, unless a -specific timezone is specified. Examples of valid date specifications -include: "1 month ago", "2 hours ago", "400000 seconds ago", "last -year", "last Monday", "yesterday", "a fortnight ago", "3/31/92 -10:00:07 PST", "January 23, 1987 10:05pm", "22:00 GMT". - -</BODY> - diff --git a/calendar/gnome-calendar-conduit.png b/calendar/gnome-calendar-conduit.png Binary files differdeleted file mode 100644 index e867ba90b2..0000000000 --- a/calendar/gnome-calendar-conduit.png +++ /dev/null diff --git a/calendar/gnome-month-item.c b/calendar/gnome-month-item.c deleted file mode 100644 index 58e393e4ee..0000000000 --- a/calendar/gnome-month-item.c +++ /dev/null @@ -1,1246 +0,0 @@ -/* General-purpose monthly calendar canvas item for GNOME - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <math.h> -#include <time.h> -#include <gnome.h> -#include "gnome-month-item.h" - - -#define DEFAULT_FONT "-*-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" - - -/* Number of days in a month, for normal and leap years */ -static const int days_in_month[2][12] = { - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - -/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the - * Gregorian reformation. - */ -static const int sept_1752[42] = { - 0, 0, 1, 2, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 -}; - -#define REFORMATION_DAY 639787 /* First day of the reformation, counted from 1 Jan 1 */ -#define MISSING_DAYS 11 /* They corrected out 11 days */ -#define THURSDAY 4 /* First day of reformation */ -#define SATURDAY 6 /* Offset value; 1 Jan 1 was a Saturday */ -#define SEPT_1752_START 2 /* Start day within month */ -#define SEPT_1752_END 20 /* End day within month */ - - -enum { - ARG_0, - ARG_YEAR, - ARG_MONTH, - ARG_X, - ARG_Y, - ARG_WIDTH, - ARG_HEIGHT, - ARG_ANCHOR, - ARG_HEAD_PADDING, - ARG_DAY_PADDING, - ARG_DAY_NAMES, - ARG_HEADING_HEIGHT, - ARG_HEADING_ANCHOR, - ARG_DAY_ANCHOR, - ARG_START_ON_MONDAY, - ARG_HEAD_FONT, - ARG_HEAD_FONTSET, - ARG_HEAD_FONT_GDK, - ARG_DAY_FONT, - ARG_DAY_FONTSET, - ARG_DAY_FONT_GDK, - ARG_HEAD_COLOR, - ARG_HEAD_COLOR_GDK, - ARG_OUTLINE_COLOR, - ARG_OUTLINE_COLOR_GDK, - ARG_DAY_BOX_COLOR, - ARG_DAY_BOX_COLOR_GDK, - ARG_DAY_COLOR, - ARG_DAY_COLOR_GDK -}; - - -static void gnome_month_item_class_init (GnomeMonthItemClass *class); -static void gnome_month_item_init (GnomeMonthItem *mitem); -static void gnome_month_item_destroy (GtkObject *object); -static void gnome_month_item_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void gnome_month_item_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); - - - -static GnomeCanvasGroupClass *parent_class; - - -GtkType -gnome_month_item_get_type (void) -{ - static GtkType month_item_type = 0; - - if (!month_item_type) { - GtkTypeInfo month_item_info = { - "GnomeMonthItem", - sizeof (GnomeMonthItem), - sizeof (GnomeMonthItemClass), - (GtkClassInitFunc) gnome_month_item_class_init, - (GtkObjectInitFunc) gnome_month_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - month_item_type = gtk_type_unique (gnome_canvas_group_get_type (), &month_item_info); - } - - return month_item_type; -} - -static void -gnome_month_item_class_init (GnomeMonthItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - parent_class = gtk_type_class (gnome_canvas_group_get_type ()); - - gtk_object_add_arg_type ("GnomeMonthItem::year", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_YEAR); - gtk_object_add_arg_type ("GnomeMonthItem::month", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_MONTH); - gtk_object_add_arg_type ("GnomeMonthItem::x", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X); - gtk_object_add_arg_type ("GnomeMonthItem::y", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y); - gtk_object_add_arg_type ("GnomeMonthItem::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("GnomeMonthItem::height", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEIGHT); - gtk_object_add_arg_type ("GnomeMonthItem::anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::heading_padding", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEAD_PADDING); - gtk_object_add_arg_type ("GnomeMonthItem::day_padding", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_DAY_PADDING); - gtk_object_add_arg_type ("GnomeMonthItem::day_names", GTK_TYPE_POINTER, GTK_ARG_WRITABLE, ARG_DAY_NAMES); - gtk_object_add_arg_type ("GnomeMonthItem::heading_height", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEADING_HEIGHT); - gtk_object_add_arg_type ("GnomeMonthItem::heading_anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_HEADING_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_DAY_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::start_on_monday", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_START_ON_MONDAY); - gtk_object_add_arg_type ("GnomeMonthItem::heading_font", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_FONT); - gtk_object_add_arg_type ("GnomeMonthItem::heading_fontset", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_FONTSET); - gtk_object_add_arg_type ("GnomeMonthItem::heading_font_gdk", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_HEAD_FONT_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_font", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_FONT); - gtk_object_add_arg_type ("GnomeMonthItem::day_fontset", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_FONTSET); - gtk_object_add_arg_type ("GnomeMonthItem::day_font_gdk", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_DAY_FONT_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::heading_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::heading_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_HEAD_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::outline_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_OUTLINE_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::outline_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_OUTLINE_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_box_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_BOX_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_box_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_BOX_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_COLOR_GDK); - - object_class->destroy = gnome_month_item_destroy; - object_class->set_arg = gnome_month_item_set_arg; - object_class->get_arg = gnome_month_item_get_arg; -} - -/* Calculates the minimum heading height based on the heading font size and padding. It also - * calculates the minimum width of the month item based on the width of the headings. - */ -static void -check_heading_sizes (GnomeMonthItem *mitem) -{ - double m_height; - double m_width; - int width; - int max_width; - int i; - - /* Calculate minimum height */ - - m_height = mitem->head_font->ascent + mitem->head_font->descent + 2 * mitem->head_padding; - - if (mitem->head_height < m_height) - mitem->head_height = m_height; - - /* Go through each heading and remember the widest one */ - - max_width = 0; - - for (i = 0; i < 7; i++) { - width = gdk_string_width (mitem->head_font, mitem->day_names[i]); - if (max_width < width) - max_width = width; - } - - m_width = 7 * (max_width + 2 * mitem->head_padding); - - if (mitem->width < m_width) - mitem->width = m_width; -} - -/* Calculates the minimum width and height of the month item based on the day font size and padding. - * Assumes that the minimum heading height has already been computed. - */ -static void -check_day_sizes (GnomeMonthItem *mitem) -{ - double m_height; - double m_width; - int width; - int max_width; - char buf[100]; - int i; - - /* Calculate minimum height */ - - m_height = mitem->head_height + 6 * (mitem->day_font->ascent + mitem->day_font->descent + 2 * mitem->day_padding); - - if (mitem->height < m_height) - mitem->height = m_height; - - /* Calculate minimum width */ - - max_width = 0; - - for (i = 1; i < 32; i++) { - sprintf (buf, "%d", i); - width = gdk_string_width (mitem->day_font, buf); - if (max_width < width) - max_width = width; - } - - m_width = 7 * (max_width + 2 * mitem->day_padding); - - if (mitem->width < m_width) - mitem->width = m_width; -} - -/* Calculates the minimum size of the month item based on the font sizes and paddings. If the - * current size of the month item is smaller than the required minimum size, this function will - * change the size to the appropriate values. - */ -static void -check_sizes (GnomeMonthItem *mitem) -{ - check_heading_sizes (mitem); - check_day_sizes (mitem); -} - -/* Recalculates the position of the toplevel calendar group based on the logical position and anchor */ -static void -reanchor (GnomeMonthItem *mitem) -{ - double x, y; - - x = mitem->x; - y = mitem->y; - - switch (mitem->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= mitem->width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= mitem->width; - break; - } - - switch (mitem->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= mitem->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= mitem->height; - break; - } - - /* Explicitly use the canvas group class prefix since the month item class has x and y - * arguments as well. - */ - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "GnomeCanvasGroup::x", x, - "GnomeCanvasGroup::y", y, - NULL); -} - -/* Takes an anchor specification and the corners of a rectangle, and returns an anchored point with - * respect to that rectangle. - */ -static void -get_label_anchor (GtkAnchorType anchor, double x1, double y1, double x2, double y2, double *x, double *y) -{ - switch (anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - *x = x1; - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x = (x1 + x2) / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x = x2; - break; - } - - switch (anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - *y = y1; - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y = (y1 + y2) / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y = y2; - break; - } -} - -/* Resets the position of the day name headings in the calendar */ -static void -reshape_headings (GnomeMonthItem *mitem) -{ - double width; - int i; - double x, y; - - width = mitem->width / 7; - - for (i = 0; i < 7; i++) { - /* Group */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i], - "x", width * i, - "y", 0.0, - NULL); - - /* Box */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i], - "x1", 0.0, - "y1", 0.0, - "x2", width, - "y2", mitem->head_height, - NULL); - - /* Label */ - get_label_anchor (mitem->head_anchor, - mitem->head_padding, - mitem->head_padding, - width - mitem->head_padding, - mitem->head_height - mitem->head_padding, - &x, &y); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "x", x, - "y", y, - "anchor", mitem->head_anchor, - NULL); - } -} - -/* Resets the position of the days in the calendar */ -static void -reshape_days (GnomeMonthItem *mitem) -{ - double width, height; - double x, y; - int row, col; - int i; - - width = mitem->width / 7; - height = (mitem->height - mitem->head_height) / 6; - - i = 0; - - for (row = 0; row < 6; row++) - for (col = 0; col < 7; col++) { - /* Group */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i], - "x", width * col, - "y", mitem->head_height + height * row, - NULL); - - /* Box */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i], - "x1", 0.0, - "y1", 0.0, - "x2", width, - "y2", height, - NULL); - - /* Label */ - get_label_anchor (mitem->day_anchor, - mitem->day_padding, - mitem->day_padding, - width - mitem->day_padding, - height - mitem->day_padding, - &x, &y); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "x", x, - "y", y, - "anchor", mitem->day_anchor, - NULL); - - i++; - } -} - -/* Changes the positions and resizes the items in the calendar to match the new size of the - * calendar. - */ -static void -reshape (GnomeMonthItem *mitem) -{ - check_sizes (mitem); - reanchor (mitem); - reshape_headings (mitem); - reshape_days (mitem); -} - -/* Sets the font for all the day headings */ -static void -set_head_font (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 7; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "font_gdk", mitem->head_font, - NULL); -} - -/* Sets the color for all the headings */ -static void -set_head_color (GnomeMonthItem *mitem) -{ - int i; - GdkColor outline; - GdkColor head; - - outline.pixel = mitem->outline_pixel; - head.pixel = mitem->head_pixel; - - for (i = 0; i < 7; i++) { - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i], - "fill_color_gdk", &outline, - NULL); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "fill_color_gdk", &head, - NULL); - } -} - -/* Creates the items for the day name headings */ -static void -create_headings (GnomeMonthItem *mitem) -{ - int i; - - /* Just create the items; they will be positioned and configured by a call to reshape() */ - - for (i = 0; i < 7; i++) { - /* Group */ - mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), - gnome_canvas_group_get_type (), - NULL); - - /* Box */ - mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), - gnome_canvas_rect_get_type (), - NULL); - - /* Label */ - mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), - gnome_canvas_text_get_type (), - NULL); - } - - set_head_font (mitem); - set_head_color (mitem); -} - -/* Returns the number of leap years since year 1 up to (but not including) the specified year */ -static int -leap_years_up_to (int year) -{ - return (year / 4 /* trivial leapness */ - - ((year > 1700) ? (year / 100 - 17) : 0) /* minus centuries since 1700 */ - + ((year > 1600) ? ((year - 1600) / 400) : 0)); /* plus centuries since 1700 divisible by 400 */ -} - -/* Returns whether the specified year is a leap year */ -static int -is_leap_year (int year) -{ - if (year <= 1752) - return !(year % 4); - else - return (!(year % 4) && (year % 100)) || !(year % 400); -} - -/* Returns the 1-based day number within the year of the specified date */ -static int -day_in_year (int day, int month, int year) -{ - int is_leap, i; - - is_leap = is_leap_year (year); - - for (i = 0; i < month; i++) - day += days_in_month [is_leap][i]; - - return day; -} - -/* Returns the day of the week (zero-based, zero is Sunday) for the specified date. For the days - * that were removed on the Gregorian reformation, it returns Thursday. - */ -static int -day_in_week (int day, int month, int year) -{ - int n; - - n = (year - 1) * 365 + leap_years_up_to (year - 1) + day_in_year (day, month, year); - - if (n < REFORMATION_DAY) - return (n - 1 + SATURDAY) % 7; - - if (n >= (REFORMATION_DAY + MISSING_DAYS)) - return (n - 1 + SATURDAY - MISSING_DAYS) % 7; - - return THURSDAY; -} - -/* Fills the 42-element days array with the day numbers for the specified month. Slots outside the - * bounds of the month are filled with zeros. The starting and ending indexes of the days are - * returned in the start and end arguments. - */ -static void -build_month (int month, int year, int start_on_monday, int *days, int *start, int *end) -{ - int i; - int d_month, d_week; - - /* Note that months are zero-based, so September is month 8 */ - - if ((year == 1752) && (month == 8)) { - memcpy (days, sept_1752, 42 * sizeof (int)); - - if (start) - *start = SEPT_1752_START; - - if (end) - *end = SEPT_1752_END; - - return; - } - - for (i = 0; i < 42; i++) - days[i] = 0; - - d_month = days_in_month[is_leap_year (year)][month]; - d_week = day_in_week (1, month, year); - - if (start_on_monday) - d_week = (d_week + 6) % 7; - - for (i = 0; i < d_month; i++) - days[d_week + i] = i + 1; - - if (start) - *start = d_week; - - if (end) - *end = d_week + d_month - 1; -} - -/* Set the day numbers in the monthly calendar */ -static void -set_days (GnomeMonthItem *mitem) -{ - int i; - int start, end; - char buf[100]; - - build_month (mitem->month, mitem->year, mitem->start_on_monday, mitem->day_numbers, &start, &end); - - /* Clear days before start of month */ - - for (i = 0; i < start; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", NULL, - NULL); - - /* Set days of month */ - - for (; start <= end; start++, i++) { - sprintf (buf, "%d", mitem->day_numbers[start]); - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", buf, - NULL); - } - - /* Clear days after end of month */ - - for (; i < 42; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", NULL, - NULL); -} - -/* Sets the font for all the day numbers */ -static void -set_day_font (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 42; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "font_gdk", mitem->day_font, - NULL); -} - -/* Sets the color for all the day items */ -static void -set_day_color (GnomeMonthItem *mitem) -{ - int i; - GdkColor outline; - GdkColor day_box; - GdkColor day; - - outline.pixel = mitem->outline_pixel; - day_box.pixel = mitem->day_box_pixel; - day.pixel = mitem->day_pixel; - - for (i = 0; i < 42; i++) { - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i], - "outline_color_gdk", &outline, - "fill_color_gdk", &day_box, - NULL); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "fill_color_gdk", &day, - NULL); - } -} - -/* Creates the items for the days */ -static void -create_days (GnomeMonthItem *mitem) -{ - int i; - - /* Just create the items; they will be positioned and configured by a call to reshape() */ - - for (i = 0; i < 42; i++) { - /* Group */ - mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), - gnome_canvas_group_get_type (), - NULL); - - /* Box */ - mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), - gnome_canvas_rect_get_type (), - NULL); - - /* Label */ - mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), - gnome_canvas_text_get_type (), - NULL); - } - - set_day_font (mitem); - set_day_color (mitem); - set_days (mitem); -} - -/* Resets the text of the day name headings */ -static void -set_day_names (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 7; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "text", mitem->day_names[mitem->start_on_monday ? ((i + 1) % 7) : i], - NULL); -} - -/* Creates all the canvas items that make up the calendar */ -static void -create_items (GnomeMonthItem *mitem) -{ - mitem->items = g_new (GnomeCanvasItem *, GNOME_MONTH_ITEM_LAST); - - create_headings (mitem); - create_days (mitem); - - /* Initialize by default to three-letter day names */ - - mitem->day_names[0] = g_strdup (_("Sun")); - mitem->day_names[1] = g_strdup (_("Mon")); - mitem->day_names[2] = g_strdup (_("Tue")); - mitem->day_names[3] = g_strdup (_("Wed")); - mitem->day_names[4] = g_strdup (_("Thu")); - mitem->day_names[5] = g_strdup (_("Fri")); - mitem->day_names[6] = g_strdup (_("Sat")); - - set_day_names (mitem); - reshape (mitem); -} - -static void -gnome_month_item_init (GnomeMonthItem *mitem) -{ - time_t t; - struct tm tm; - - /* Initialize to the current month by default */ - - t = time (NULL); - tm = *localtime (&t); - - mitem->year = tm.tm_year + 1900; - mitem->month = tm.tm_mon; - - mitem->x = 0.0; - mitem->y = 0.0; - mitem->width = 150.0; /* not unreasonable defaults, I hope */ - mitem->height = 100.0; - mitem->anchor = GTK_ANCHOR_NW; - mitem->head_padding = 0.0; - mitem->day_padding = 2.0; - mitem->head_height = 14.0; - mitem->head_anchor = GTK_ANCHOR_CENTER; - mitem->day_anchor = GTK_ANCHOR_CENTER; - - /* Load the default fonts */ - - mitem->head_font = gdk_font_load (DEFAULT_FONT); - if (!mitem->head_font) { - mitem->head_font = gdk_font_load ("fixed"); - g_assert (mitem->head_font != NULL); - } - - mitem->day_font = gdk_font_load (DEFAULT_FONT); - if (!mitem->day_font) { - mitem->day_font = gdk_font_load ("fixed"); - g_assert (mitem->day_font != NULL); - } -} - -GnomeCanvasItem * -gnome_month_item_new (GnomeCanvasGroup *parent) -{ - GnomeMonthItem *mitem; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (parent), NULL); - - mitem = GNOME_MONTH_ITEM (gnome_canvas_item_new (parent, - gnome_month_item_get_type (), - NULL)); - - gnome_month_item_construct (mitem); - - return GNOME_CANVAS_ITEM (mitem); -} - -void -gnome_month_item_construct (GnomeMonthItem *mitem) -{ - GdkColor color; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - - gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "#d6d6d6d6d6d6", &color); - mitem->head_pixel = color.pixel; - mitem->day_box_pixel = color.pixel; - - gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "black", &color); - mitem->outline_pixel = color.pixel; - mitem->day_pixel = color.pixel; - - create_items (mitem); -} - -static void -free_day_names (GnomeMonthItem *mitem) -{ - int i; - - if (mitem->day_names[0]) - for (i = 0; i < 7; i++) - g_free (mitem->day_names[i]); -} - -static void -gnome_month_item_destroy (GtkObject *object) -{ - GnomeMonthItem *mitem; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (object)); - - mitem = GNOME_MONTH_ITEM (object); - - free_day_names (mitem); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -/* Sets the color of the specified pixel value to that of the specified argument, which must be in - * GdkColor format if format is TRUE, otherwise it must be in string format. - */ -static void -set_color_arg (GnomeMonthItem *mitem, gulong *pixel, GtkArg *arg, int gdk_format, int set_head, int set_day) -{ - GdkColor color; - - if (gdk_format) - *pixel = ((GdkColor *) GTK_VALUE_BOXED (*arg))->pixel; - else { - if (gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, GTK_VALUE_STRING (*arg), &color)) - *pixel = color.pixel; - else - *pixel = 0; - } - - if (set_head) - set_head_color (mitem); - - if (set_day) - set_day_color (mitem); -} - -static void -gnome_month_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeMonthItem *mitem; - char **day_names; - int i; - - mitem = GNOME_MONTH_ITEM (object); - - switch (arg_id) { - case ARG_YEAR: - mitem->year = GTK_VALUE_UINT (*arg); - set_days (mitem); - break; - - case ARG_MONTH: - mitem->month = GTK_VALUE_UINT (*arg); - set_days (mitem); - break; - - case ARG_X: - mitem->x = GTK_VALUE_DOUBLE (*arg); - reanchor (mitem); - break; - - case ARG_Y: - mitem->y = GTK_VALUE_DOUBLE (*arg); - reanchor (mitem); - break; - - case ARG_WIDTH: - mitem->width = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_HEIGHT: - mitem->height = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_ANCHOR: - mitem->anchor = GTK_VALUE_ENUM (*arg); - reanchor (mitem); - break; - - case ARG_HEAD_PADDING: - mitem->head_padding = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_DAY_PADDING: - mitem->day_padding = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_DAY_NAMES: - day_names = GTK_VALUE_POINTER (*arg); - - /* First, check that none of the names is null */ - - for (i = 0; i < 7; i++) - if (!day_names[i]) { - g_warning ("Day number %d was NULL; day names cannot be NULL!", i); - return; - } - - /* Set the new names */ - - free_day_names (mitem); - for (i = 0; i < 7; i++) - mitem->day_names[i] = g_strdup (day_names[i]); - - set_day_names (mitem); - reshape (mitem); - break; - - case ARG_HEADING_HEIGHT: - mitem->head_height = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_HEADING_ANCHOR: - mitem->head_anchor = GTK_VALUE_ENUM (*arg); - reshape (mitem); - break; - - case ARG_DAY_ANCHOR: - mitem->day_anchor = GTK_VALUE_ENUM (*arg); - reshape (mitem); - break; - - case ARG_START_ON_MONDAY: - mitem->start_on_monday = GTK_VALUE_BOOL (*arg); - set_day_names (mitem); - set_days (mitem); - break; - - case ARG_HEAD_FONT: - gdk_font_unref (mitem->head_font); - - mitem->head_font = gdk_font_load (GTK_VALUE_STRING (*arg)); - if (!mitem->head_font) { - mitem->head_font = gdk_font_load ("fixed"); - g_assert (mitem->head_font != NULL); - } - - set_head_font (mitem); - reshape (mitem); - break; - - case ARG_HEAD_FONTSET: - gdk_font_unref (mitem->head_font); - - mitem->head_font = gdk_fontset_load (GTK_VALUE_STRING (*arg)); - if (!mitem->head_font) { - mitem->head_font = - gdk_fontset_load ("-*-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-*"); - g_assert (mitem->head_font != NULL); - } - - set_head_font (mitem); - reshape (mitem); - break; - - case ARG_HEAD_FONT_GDK: - gdk_font_unref (mitem->head_font); - - mitem->head_font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (mitem->head_font); - set_head_font (mitem); - reshape (mitem); - break; - - case ARG_DAY_FONT: - gdk_font_unref (mitem->day_font); - - mitem->day_font = gdk_font_load (GTK_VALUE_STRING (*arg)); - if (!mitem->day_font) { - mitem->day_font = gdk_font_load ("fixed"); - g_assert (mitem->day_font != NULL); - } - - set_day_font (mitem); - reshape (mitem); - break; - - case ARG_DAY_FONTSET: - gdk_font_unref (mitem->day_font); - - mitem->day_font = gdk_fontset_load (GTK_VALUE_STRING (*arg)); - if (!mitem->day_font) { - mitem->day_font = - gdk_fontset_load ("-*-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-*"); - g_assert (mitem->day_font != NULL); - } - - set_day_font (mitem); - reshape (mitem); - break; - - case ARG_DAY_FONT_GDK: - gdk_font_unref (mitem->day_font); - - mitem->day_font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (mitem->day_font); - set_day_font (mitem); - reshape (mitem); - break; - - case ARG_HEAD_COLOR: - set_color_arg (mitem, &mitem->head_pixel, arg, FALSE, TRUE, FALSE); - break; - - case ARG_HEAD_COLOR_GDK: - set_color_arg (mitem, &mitem->head_pixel, arg, TRUE, TRUE, FALSE); - break; - - case ARG_OUTLINE_COLOR: - set_color_arg (mitem, &mitem->outline_pixel, arg, FALSE, TRUE, TRUE); - break; - - case ARG_OUTLINE_COLOR_GDK: - set_color_arg (mitem, &mitem->outline_pixel, arg, TRUE, TRUE, TRUE); - break; - - case ARG_DAY_BOX_COLOR: - set_color_arg (mitem, &mitem->day_box_pixel, arg, FALSE, FALSE, TRUE); - break; - - case ARG_DAY_BOX_COLOR_GDK: - set_color_arg (mitem, &mitem->day_box_pixel, arg, TRUE, FALSE, TRUE); - break; - - case ARG_DAY_COLOR: - set_color_arg (mitem, &mitem->day_pixel, arg, FALSE, FALSE, TRUE); - break; - - case ARG_DAY_COLOR_GDK: - set_color_arg (mitem, &mitem->day_pixel, arg, TRUE, FALSE, TRUE); - break; - - default: - break; - } -} - -/* Allocates a GdkColor structure filled with the specified pixel, and puts it into the specified - * arg for returning it in the get_arg method. - */ -static void -get_color_arg (GnomeMonthItem *mitem, gulong pixel, GtkArg *arg) -{ - GdkColor *color; - - color = g_new (GdkColor, 1); - color->pixel = pixel; - gdk_color_context_query_color (GNOME_CANVAS_ITEM (mitem)->canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; -} - -static void -gnome_month_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeMonthItem *mitem; - - mitem = GNOME_MONTH_ITEM (object); - - switch (arg_id) { - case ARG_YEAR: - GTK_VALUE_UINT (*arg) = mitem->year; - break; - - case ARG_MONTH: - GTK_VALUE_UINT (*arg) = mitem->month; - break; - - case ARG_X: - GTK_VALUE_DOUBLE (*arg) = mitem->x; - break; - - case ARG_Y: - GTK_VALUE_DOUBLE (*arg) = mitem->y; - break; - - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = mitem->width; - break; - - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = mitem->height; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->anchor; - break; - - case ARG_HEAD_PADDING: - GTK_VALUE_DOUBLE (*arg) = mitem->head_padding; - break; - - case ARG_DAY_PADDING: - GTK_VALUE_DOUBLE (*arg) = mitem->day_padding; - break; - - case ARG_HEADING_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = mitem->head_height; - break; - - case ARG_HEADING_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->head_anchor; - break; - - case ARG_DAY_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->day_anchor; - break; - - case ARG_START_ON_MONDAY: - GTK_VALUE_BOOL (*arg) = mitem->start_on_monday; - break; - - case ARG_HEAD_FONT_GDK: - GTK_VALUE_BOXED (*arg) = mitem->head_font; - break; - - case ARG_DAY_FONT_GDK: - GTK_VALUE_BOXED (*arg) = mitem->day_font; - break; - - case ARG_HEAD_COLOR_GDK: - get_color_arg (mitem, mitem->head_pixel, arg); - break; - - case ARG_OUTLINE_COLOR_GDK: - get_color_arg (mitem, mitem->outline_pixel, arg); - break; - - case ARG_DAY_BOX_COLOR_GDK: - get_color_arg (mitem, mitem->day_box_pixel, arg); - break; - - case ARG_DAY_COLOR_GDK: - get_color_arg (mitem, mitem->day_pixel, arg); - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -GnomeCanvasItem * -gnome_month_item_num2child (GnomeMonthItem *mitem, int child_num) -{ - g_return_val_if_fail (mitem != NULL, NULL); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), NULL); - - return mitem->items[child_num]; -} - -int -gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child) -{ - int i; - - g_return_val_if_fail (mitem != NULL, -1); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); - g_return_val_if_fail (child != NULL, -1); - g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (child), -1); - - for (i = 0; i < GNOME_MONTH_ITEM_LAST; i++) - if (mitem->items[i] == child) - return i; - - return -1; -} - -int -gnome_month_item_num2day (GnomeMonthItem *mitem, int child_num) -{ - g_return_val_if_fail (mitem != NULL, 0); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), 0); - - if ((child_num >= GNOME_MONTH_ITEM_DAY_GROUP) && (child_num < GNOME_MONTH_ITEM_LAST)) { - child_num = (child_num - GNOME_MONTH_ITEM_DAY_GROUP) % 42; - return mitem->day_numbers[child_num]; - } else - return 0; -} - -int -gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num) -{ - int i; - - g_return_val_if_fail (mitem != NULL, -1); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); - g_return_val_if_fail (day_num >= 1, -1); - - /* Find first day of month */ - - for (i = 0; mitem->day_numbers[i] == 0; i++) - ; - - /* Find the specified day */ - - for (; (mitem->day_numbers[i] != 0) && (i < 42); i++) - if (mitem->day_numbers[i] == day_num) - return i; - - /* Bail out */ - - return -1; -} diff --git a/calendar/gnome-month-item.h b/calendar/gnome-month-item.h deleted file mode 100644 index 0ec4fd484c..0000000000 --- a/calendar/gnome-month-item.h +++ /dev/null @@ -1,165 +0,0 @@ -/* General-purpose monthly calendar canvas item for GNOME - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef GNOME_MONTH_ITEM_H -#define GNOME_MONTH_ITEM_H - -#include <libgnome/gnome-defs.h> -#include <gtk/gtkpacker.h> /* why the hell is GtkAnchorType here and not in gtkenums.h? */ -#include <libgnomeui/gnome-canvas.h> - - -BEGIN_GNOME_DECLS - - -/* These values are used to identify the canvas items that make up a complete GnomeMonthItem, which - * is made up of the following "pieces": - * - * Headings line: - * - 7 GnomeCanvasGroups: - * Each group contains one box (GnomeCanvasRectangle) and one label - * (GnomeCanvasText) - * - * Day slots: - * - 42 GnomeCanvasGroups: - * Each group contains one box (GnomeCanvasRectangle) and one label - * (GnomeCanvasText) - * - * The headings are organized from left to right. The day slots are organized as a table in - * row-major order. - * - * If you want to access the individual items of the GnomeMonthItem, you can use these numbers with - * the gnome_month_item_num2child() function. If you want to convert a number into the - * corresponding GnomeCanvasItem, you can use the gnome_month_item_child2num() function. - */ -typedef enum { - GNOME_MONTH_ITEM_HEAD_GROUP = 0, /* 7 groups for headings */ - GNOME_MONTH_ITEM_HEAD_BOX = 7, /* 7 boxes for headings */ - GNOME_MONTH_ITEM_HEAD_LABEL = 14, /* 7 labels for headings */ - GNOME_MONTH_ITEM_DAY_GROUP = 21, /* 42 groups for days */ - GNOME_MONTH_ITEM_DAY_BOX = 63, /* 42 boxes for days */ - GNOME_MONTH_ITEM_DAY_LABEL = 105, /* 42 labels for days */ - GNOME_MONTH_ITEM_LAST = 147 /* total number of items */ -} GnomeMonthItemChild; - -/* The MonthItem canvas item defines a simple monthly calendar. It is made out of a number of - * canvas items, which can be accessed using the functions provided. The monthly calendar is - * anchored with respect to a point. The following arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * year uint RW Full year (1-9999) - * month uint RW Number of month (0-11) - * x double RW X position of anchor point - * y double RW Y position of anchor point - * width double RW Width of calendar in canvas units - * height double RW Height of calendar in canvas units - * anchor GtkAnchorType RW Anchor side for calendar - * heading_padding double RW Padding inside heading boxes - * day_padding double RW Padding inside day boxes - * day_names char ** W Array of strings corresponding to the day names (sun-sat) - * heading_height double RW Height of headings bar in canvas units - * heading_anchor GtkAnchorType RW Anchor side for headings inside heading boxes - * day_anchor GtkAnchorType RW Anchor side for day numbers inside day boxes - * start_on_monday boolean RW Specifies whether the week starts on Monday or Sunday - * heading_font string W X logical font descriptor for the headings - * heading_fontset string W X logical fontset descriptor for the headings - * heading_font_gdk GdkFont * RW Pointer to GdkFont for the headings - * day_font string W X logical font descriptor for the day numbers - * day_fontset string W X logical fontset descriptor for the day numbers - * day_font_gdk GdkFont * RW Pointer to GdkFont for the day numbers - * heading_color string W X color specification for heading labels - * heading_color_gdk GdkColor * RW Pointer to an allocated GdkColor for heading labels - * outline_color string W X color specification for outline (lines and fill of heading boxes) - * outline_color_gdk GdkColor * RW Pointer to an allocated GdkColor for outline - * day_box_color string W X color specification for day boxes - * day_box_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day boxes - * day_color string W X color specification for day number labels - * day_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day number labels - */ - -#define GNOME_TYPE_MONTH_ITEM (gnome_month_item_get_type ()) -#define GNOME_MONTH_ITEM(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_MONTH_ITEM, GnomeMonthItem)) -#define GNOME_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_MONTH_ITEM, GnomeMonthItemClass)) -#define GNOME_IS_MONTH_ITEM(obj) (GTK_CHECK_TYPE ((obj), GNOME_TYPE_MONTH_ITEM)) -#define GNOME_IS_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_MONTH_ITEM)) - - -typedef struct _GnomeMonthItem GnomeMonthItem; -typedef struct _GnomeMonthItemClass GnomeMonthItemClass; - -struct _GnomeMonthItem { - GnomeCanvasGroup group; - - int year; /* Year to show (full, no two-digit crap) */ - int month; /* Month to show (0-11) */ - - double x, y; /* Position at anchor */ - double width, height; /* Size of calendar */ - GtkAnchorType anchor; /* Anchor side for calendar */ - - double head_padding; /* Padding to use between heading lines and text */ - double day_padding; /* Padding to use between day number lines and text */ - - char *day_names[7]; /* Names to use for the day labels, starting from Sunday */ - - double head_height; /* Height of the headings row */ - GtkAnchorType head_anchor; /* Anchor side for the heading labels */ - GtkAnchorType day_anchor; /* Anchor side for the day number labels */ - - GnomeCanvasItem **items; /* All the items that make up the calendar */ - int day_numbers[42]; /* The numbers of the days, as they are shown in the display */ - - GdkFont *head_font; /* Font for the headings */ - GdkFont *day_font; /* Font for the day numbers */ - - gulong head_pixel; /* Color for heading labels */ - gulong outline_pixel; /* Color for the outline (lines and heading boxes) */ - gulong day_box_pixel; /* Color for the day boxes */ - gulong day_pixel; /* Color for day number labels */ - - int start_on_monday : 1; /* Start the week on Monday? If false, then start from Sunday */ -}; - -struct _GnomeMonthItemClass { - GnomeCanvasGroupClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType gnome_month_item_get_type (void); - -/* Creates a new month item with the specified group as parent */ -GnomeCanvasItem *gnome_month_item_new (GnomeCanvasGroup *parent); - -/* Constructor function useful for derived classes */ -void gnome_month_item_construct (GnomeMonthItem *mitem); - -/* Returns the child item defined by the child number (as specified on the GnomeMonthItemChild - * enumeration above). - */ -GnomeCanvasItem *gnome_month_item_num2child (GnomeMonthItem *mitem, int child_num); - -/* Returns the number of the specified child item, as defined on the GnomeMonthItemChild enumeration - * above. If the specified object is not found, it returns -1. - */ -int gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child); - -/* Returns the number of the day relevant to the specified child item. Day numbers are 1-based. If - * the specified child is outside the range of displayed days, then it returns 0. - */ -int gnome_month_item_num2day (GnomeMonthItem *mitem, int child_num); - -/* Returns the index (0-41) of the specified date within the table of days. If the day number is - * invalid for the current monthly calendar, then -1 is returned. - */ -int gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gnomecal.gnorba b/calendar/gnomecal.gnorba deleted file mode 100644 index 74df8ecf04..0000000000 --- a/calendar/gnomecal.gnorba +++ /dev/null @@ -1,11 +0,0 @@ -[IDL:GNOME:Calendar:Repository:1.0] -type=factory -repo_id=IDL:Gnome/Calendar/Repository:1.0 -description=Calendar Repository -location_info=IDL:GNOME:Calendar:RepositoryLocator:1.0 - -[IDL:GNOME:Calendar:RepositoryLocator:1.0] -type=exe -repo_id=IDL:GNOME/GenericFactory:1.0 -description=Calendar Server -location_info=gnomecal diff --git a/calendar/goto.c b/calendar/goto.c deleted file mode 100644 index ef756a5463..0000000000 --- a/calendar/goto.c +++ /dev/null @@ -1,323 +0,0 @@ -/* Go to date dialog for gnomecal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gnome.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" -#include "main.h" -#include "mark.h" -#include "cal-util/timeutil.h" - - -static GtkWidget *goto_win; /* The goto dialog window */ -static GnomeMonthItem *month_item; /* The month item in the dialog */ -static GnomeCalendar *gnome_calendar; /* The gnome calendar the dialog refers to */ -static int current_index; /* The index of the day marked as current, or -1 if none */ - - -/* Updates the specified month item by marking it appropriately from the calendar the dialog refers - * to. Also marks the current day if appropriate. - */ -static void -update (void) -{ - GnomeCanvasItem *item; - time_t t; - struct tm tm; - - unmark_month_item (month_item); - mark_month_item (month_item, gnome_calendar->cal); - - if (current_index != -1) { - item = gnome_month_item_num2child (month_item, - GNOME_MONTH_ITEM_DAY_LABEL + current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "fontset", NORMAL_DAY_FONTSET, - NULL); - current_index = -1; - } - - t = time (NULL); - tm = *localtime (&t); - - if (((tm.tm_year + 1900) == month_item->year) && (tm.tm_mon == month_item->month)) { - current_index = gnome_month_item_day2index (month_item, tm.tm_mday); - g_assert (current_index != -1); - - item = gnome_month_item_num2child (month_item, - GNOME_MONTH_ITEM_DAY_LABEL + current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "fontset", CURRENT_DAY_FONTSET, - NULL); - } -} - -/* Callback used when the year adjustment is changed */ -static void -year_changed (GtkAdjustment *adj, gpointer data) -{ - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "year", (int) adj->value, - NULL); - update (); -} - -/* Creates the year control with its adjustment */ -static GtkWidget * -create_year (int year) -{ - GtkWidget *hbox; - GtkAdjustment *adj; - GtkWidget *w; - - hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - - w = gtk_label_new (_("Year:")); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (year, 1900, 9999, 1, 10, 10)); - gtk_signal_connect (GTK_OBJECT (adj), "value_changed", - (GtkSignalFunc) year_changed, - NULL); - - w = gtk_spin_button_new (adj, 1.0, 0); - gtk_widget_set_usize (w, 60, 0); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - return hbox; -} - -/* Callback used when a month button is toggled */ -static void -month_toggled (GtkToggleButton *toggle, gpointer data) -{ - if (!toggle->active) - return; - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "month", GPOINTER_TO_INT (data), - NULL); - update (); -} - -/* Creates the months control */ -static GtkWidget * -create_months (int month) -{ - GtkWidget *table; - GtkWidget *w; - GSList *group; - int i, row, col; - struct tm tm; - char buf[100]; - - tm = *localtime (&gnome_calendar->current_display); - - table = gtk_table_new (2, 6, TRUE); - - group = NULL; - - for (i = 0; i < 12; i++) { - row = i / 6; - col = i % 6; - - tm.tm_mon = i; - strftime (buf, 100, "%b", &tm); - - w = gtk_radio_button_new (group); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (w)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (w), FALSE); - - gtk_container_add (GTK_CONTAINER (w), gtk_label_new (buf)); - - if (i == month) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (w), TRUE); - - gtk_signal_connect (GTK_OBJECT (w), "toggled", - (GtkSignalFunc) month_toggled, - GINT_TO_POINTER (i)); - gtk_table_attach (GTK_TABLE (table), w, - col, col + 1, - row, row + 1, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - gtk_widget_show_all (w); - } - - return table; -} - -/* Sets the scrolling region of the canvas to the allocation size */ -static void -set_scroll_region (GtkWidget *widget, GtkAllocation *allocation) -{ - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - 1), - NULL); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, - allocation->width, allocation->height); -} - -/* Event handler for day groups in the month item. A button press makes the calendar jump to the - * selected day and destroys the Go-to dialog box. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - int child_num, day; - - child_num = gnome_month_item_child2num (month_item, item); - day = gnome_month_item_num2day (month_item, child_num); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((event->button.button == 1) && (day != 0)) { - gnome_calendar_goto (gnome_calendar, - time_from_day (month_item->year, month_item->month, day)); - gtk_widget_destroy (goto_win); - } - break; - - default: - break; - } - - return FALSE; -} - -/* Creates the canvas with the month item for selecting days */ -static GtkWidget * -create_days (int day, int month, int year) -{ - GtkWidget *canvas; - int i; - GnomeCanvasItem *day_group; - - canvas = gnome_canvas_new (); - gtk_widget_set_usize (canvas, 150, 120); - - month_item = GNOME_MONTH_ITEM (gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)))); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "month", month, - "year", year, - "start_on_monday", week_starts_on_monday, - NULL); - colorify_month_item (month_item, default_color_func, NULL); - month_item_prepare_prelight (month_item, default_color_func, NULL); - update (); - - /* Connect to size_allocate so that we can change the size of the month item and the - * scrolling region appropriately. - */ - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - (GtkSignalFunc) set_scroll_region, - NULL); - - /* Bind the day groups to our event handler */ - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (month_item, i + GNOME_MONTH_ITEM_DAY_GROUP); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - NULL); - } - - return canvas; -} - -static void -goto_today (GtkWidget *widget, gpointer data) -{ - gnome_calendar_goto_today (gnome_calendar); - gtk_widget_destroy (goto_win); -} - -/* Creates a "goto date" dialog and runs it */ -void -goto_dialog (GnomeCalendar *gcal) -{ - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *w; - GtkWidget *days; - struct tm tm; - - gnome_calendar = gcal; - current_index = -1; - - tm = *localtime (&gnome_calendar->current_display); - - goto_win = gnome_dialog_new (_("Go to date"), - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_set_parent (GNOME_DIALOG (goto_win), GTK_WINDOW (gcal)); - - vbox = GNOME_DIALOG (goto_win)->vbox; - - /* Instructions */ - - w = gtk_label_new (_("Please select the date you want to go to.\n" - "When you click on a day, you will be taken\n" - "to that date.")); - gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Create month item before creating the year controls, since the latter ones need the - * month_item to be created. - */ - - days = create_days (tm.tm_mday, tm.tm_mon, tm.tm_year + 1900); - - /* Year */ - - w = create_year (tm.tm_year + 1900); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Month */ - - w = create_months (tm.tm_mon); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Days (canvas with month item) */ - - gtk_box_pack_start (GTK_BOX (vbox), days, TRUE, TRUE, 0); - gtk_widget_show (days); - - /* Today button */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - w = gtk_button_new_with_label (_("Go to today")); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) goto_today, - NULL); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Run! */ - - gtk_window_set_modal (GTK_WINDOW (goto_win), TRUE); - gnome_dialog_set_close (GNOME_DIALOG (goto_win), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (goto_win), GTK_WINDOW (gnome_calendar)); - gtk_widget_show (goto_win); -} diff --git a/calendar/icalendar-types b/calendar/icalendar-types deleted file mode 100644 index e11f4c1789..0000000000 --- a/calendar/icalendar-types +++ /dev/null @@ -1,39 +0,0 @@ -evento todo journal fbrequest fbreply busytime timezone - attach attach attach - attendee attendee attendee attendee attendee attendee - categories categories categories - class class class - comment comment comment comment comment comment comment - completed - contact contact contact - created created created created - description description description - dtstamp dtstamp - dtend/duration due->dtend dtend [duration] dtend dtend - dtstart dtstart dtstart dtstart dtstart dtstart dtstart - exdate exdate exdate - exrule exrule exrule - geo geo - last-mod last-mod last-mod last-mod last-mod - location location - organizer organizer organizer - percent - priority priority - rstatus rstatus rstatus rstatus - related related related - resources resources - rdate rdate rdate [rdate/rrule] - rrule rrule rrule - dtstamp dtstamp dtstamp dtstamp - seq seq seq seq seq - status status - summary summary summary - transp - uid uid uid uid uid - url url url url url - recurid recurid recurid - freebusy freebusy - tzname - tzoffset-to - tzoffset-from - diff --git a/calendar/layout.c b/calendar/layout.c deleted file mode 100644 index 4195c464ae..0000000000 --- a/calendar/layout.c +++ /dev/null @@ -1,288 +0,0 @@ -/* Event layout engine for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <stdlib.h> -#include "layout.h" - - -/* This structure is used to pass around layout information among the internal layout functions */ -struct layout_info { - GList *events; /* List of events from client */ - int num_events; /* The number of events (length of the list) */ - LayoutQueryTimeFunc func; /* Function to convert a list item to a start/end time pair */ - int num_rows; /* Size of the time partition */ - time_t *partition; /* The time partition containing start and end time values */ - int *array; /* Working array of free and allocated time slots */ - int *allocations; /* Returned array of slot allocations */ - int *slots; /* Returned array of slots used */ - int num_slots; /* Number of slots used */ -}; - - -/* This defines the maximum number of events to overlap per row. More than that number of events - * will not be displayed. This is not ideal, so sue me. - */ -#define MAX_EVENTS_PER_ROW 32 - - -/* Compares two time_t values, used for qsort() */ -static int -compare_time_t (const void *a, const void *b) -{ - time_t ta, tb; - - ta = *((time_t *) a); - tb = *((time_t *) b); - - if (ta < tb) - return -1; - else if (ta > tb) - return 1; - else - return 0; -} - -/* Builds a partition of the time range occupied by the events in the list. It returns an array - * with the times that define the partition and the number of items in the partition. - */ -static void -build_partition (struct layout_info *li) -{ - time_t *rows, *p, *q; - GList *list; - int i, unique_vals; - - /* This is the maximum number of rows we would need */ - - li->num_rows = li->num_events * 2; - - /* Fill the rows with the times */ - - rows = g_new (time_t, li->num_rows); - - for (list = li->events, p = rows; list; list = list->next) { - (* li->func) (list, &p[0], &p[1]); - p += 2; - } - - /* Do a sort | uniq on the array */ - - qsort (rows, li->num_rows, sizeof (time_t), compare_time_t); - - p = rows; - q = rows + 1; - unique_vals = 1; - - for (i = 1; i < li->num_rows; i++, q++) - if (*q != *p) { - unique_vals++; - p++; - *p = *q; - } - - /* Return the number of unique values in the partition and the partition array itself */ - - li->num_rows = unique_vals; - li->partition = rows; -} - -/* Returns the index of the element in the partition that corresponds to the specified time */ -static int -find_index (struct layout_info *li, time_t t) -{ - int i; - - for (i = 0; ; i++) - if (li->partition[i] == t) - return i; - - g_assert_not_reached (); -} - -#define xy(li, x, y) li->array[(y * MAX_EVENTS_PER_ROW) + (x)] - -/* Checks that all the cells in the slot array at the specified slot column are free to use by an - * event that has the specified range. - */ -static int -range_is_empty (struct layout_info *li, int slot, time_t start, time_t end) -{ - int i; - - for (i = find_index (li, start); li->partition[i] < end; i++) - if (xy (li, slot, i) != -1) - return FALSE; - - return TRUE; -} - -/* Allocates a time in the slot array for the specified event's index */ -static void -range_allocate (struct layout_info *li, int slot, time_t start, time_t end, int ev_num) -{ - int i; - - for (i = find_index (li, start); li->partition[i] < end; i++) - xy (li, slot, i) = ev_num; -} - -/* Performs the initial allocation of slots for events. Each event gets one column; they will be - * expanded in a later stage. Returns the number of columns used. - */ -static void -initial_allocate (struct layout_info *li) -{ - GList *events; - int i; - int slot; - int num_slots; - time_t start, end; - - num_slots = 0; - - for (i = 0, events = li->events; events; events = events->next, i++) { - (* li->func) (events, &start, &end); - - /* Start with no allocation, no columns */ - - li->allocations[i] = -1; - li->slots[i] = 0; - - /* Find a free column for the event */ - - for (slot = 0; slot < MAX_EVENTS_PER_ROW; slot++) - if (range_is_empty (li, slot, start, end)) { - range_allocate (li, slot, start, end, i); - - li->allocations[i] = slot; - li->slots[i] = 1; - - if ((slot + 1) > num_slots) - num_slots = slot + 1; - - break; - } - } - - li->num_slots = num_slots; -} - -/* Returns the maximum number of columns that an event can expanded by in the slot array */ -static int -columns_to_expand (struct layout_info *li, int ev_num, time_t start, time_t end) -{ - int cols; - int slot; - int i_start; - int i; - - cols = 0; - - i_start = find_index (li, start); - - for (slot = li->allocations[ev_num] + 1; slot < li->num_slots; slot++) { - for (i = i_start; li->partition[i] < end; i++) - if (xy (li, slot, i) != -1) - return cols; - - cols++; - } - - return cols; -} - -/* Expands an event by the specified number of columns */ -static void -do_expansion (struct layout_info *li, int ev_num, time_t start, time_t end, int num_cols) -{ - int i, j; - int slot; - - for (i = find_index (li, start); li->partition[i] < end; i++) { - slot = li->allocations[ev_num] + 1; - - for (j = 0; j < num_cols; j++) - xy (li, slot + j, i) = ev_num; - } -} - -/* Expands the events in the slot array to occupy as many columns as possible. This is the second - * pass of the layout algorithm. - */ -static void -expand_events (struct layout_info *li) -{ - GList *events; - time_t start, end; - int i; - int cols; - - for (i = 0, events = li->events; events; events = events->next, i++) { - (* li->func) (events, &start, &end); - - cols = columns_to_expand (li, i, start, end); - - if (cols == 0) - continue; /* We can't expand this event */ - - do_expansion (li, i, start, end, cols); - - li->slots[i] += cols; - } -} - -void -layout_events (GList *events, LayoutQueryTimeFunc func, int *num_slots, int **allocations, int **slots) -{ - struct layout_info li; - int i; - - g_return_if_fail (num_slots != NULL); - g_return_if_fail (allocations != NULL); - g_return_if_fail (slots != NULL); - - if (!events) { - *num_slots = 0; - *allocations = NULL; - *slots = NULL; - - return; - } - - li.events = events; - li.num_events = g_list_length (events); - li.func = func; - - /* Build the partition of the time range, and then build the array of slots */ - - build_partition (&li); - - li.array = g_new (int, li.num_rows * MAX_EVENTS_PER_ROW); - for (i = 0; i < (li.num_rows * MAX_EVENTS_PER_ROW); i++) - li.array[i] = -1; /* This is our 'empty' value */ - - /* Build the arrays for allocations and columns used */ - - li.allocations = g_new (int, li.num_events); - li.slots = g_new (int, li.num_events); - - /* Perform initial allocation and then expand the events to as many slots as they can occupy */ - - initial_allocate (&li); - expand_events (&li); - - /* Clean up and return values */ - - g_free (li.partition); - g_free (li.array); - - *num_slots = li.num_slots; - *allocations = li.allocations; - *slots = li.slots; -} diff --git a/calendar/layout.h b/calendar/layout.h deleted file mode 100644 index 734b720b8b..0000000000 --- a/calendar/layout.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Event layout engine for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef LAYOUT_H -#define LAYOUT_H - -#include <glib.h> -#include <time.h> - - -/* Functions of this type must translate the list item into two time_t values for the start and end - * of an event. - */ -typedef void (* LayoutQueryTimeFunc) (GList *event, time_t *start, time_t *end); - - -/* This is the main layout function for overlapping events. You pass in a list of (presumably) - * events and a function that should take a list element and return the start and end times for the - * event corresponding to that list element. - * - * It returns the number of slots ("columns") that you need to take into account when actually - * painting the events, the array of the first slot index that each event occupies, and the array of - * number of slots that each event occupies. You have to free both arrays. - * - * You will get somewhat better-looking results if the list of events is sorted by using the start - * time as the primary sort key and the end time as the secondary sort key -- so that "longer" - * events go first in the list. - */ -void layout_events (GList *events, LayoutQueryTimeFunc func, int *num_slots, int **allocations, int **slots); - - -#endif diff --git a/calendar/main.c b/calendar/main.c deleted file mode 100644 index c4db8701ad..0000000000 --- a/calendar/main.c +++ /dev/null @@ -1,1044 +0,0 @@ -/* - * Main file for the GNOME Calendar program - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * Federico Mena (federico@nuclecu.unam.mx) - */ - -#include <config.h> -#include <gnome.h> -#include <libgnorba/gnorba.h> -#include <pwd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include "calendar.h" -#include "alarm.h" -#include "eventedit.h" -#include "gnome-cal.h" -#include "main.h" -#include "cal-util/timeutil.h" -#include "corba-cal-factory.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" } -}; - -/* Number of active calendars */ -int active_calendars = 0; - -/* A list of all of the calendars started */ -GList *all_calendars = NULL; - -/* 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; - -/* Default values for alarms */ -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); - -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); -} - -GnomeCalendar * -gnome_calendar_locate (const char *pathname) -{ - GList *l; - - if (pathname == NULL || pathname [0] == 0) - pathname = user_calendar_file; - - for (l = all_calendars; l; l = l->next){ - GnomeCalendar *gcal = l->data; - - if (strcmp (gcal->cal->filename, pathname) == 0){ - return gcal; - } - } - return NULL; -} - -static void -close_cmd (GtkWidget *widget, GnomeCalendar *gcal) -{ - all_calendars = g_list_remove (all_calendars, gcal); - - 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){ - unregister_calendar_services (); - 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); - 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); -} - -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); -} - -/* - * Saves @gcal if it is the default calendar - */ -void -save_default_calendar (GnomeCalendar *gcal) -{ - if (!gcal->cal->filename) - return; - - save_calendar_cmd (NULL, gcal); -} - -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), - - 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); - else - GNOME_CALENDAR (toplevel)->cal->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); -} - -static void -process_dates (void) -{ - if (!from_t) - from_t = time_day_begin (time (NULL)); - - if (!to_t || to_t < from_t) - to_t = time_add_day (from_t, 1); -} - -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) -{ - return (a->tm_mday == b->tm_mday && - a->tm_mon == b->tm_mon && - a->tm_year == b->tm_year); -} - -static void -dump_events (void) -{ - Calendar *cal; - GList *l; - char *s; - time_t now = time (NULL); - struct tm today = *localtime (&now); - - process_dates (); - init_calendar (); - - cal = calendar_new (full_name, CALENDAR_INIT_ALARMS); - s = calendar_load (cal, load_file ? load_file : user_calendar_file); - if (s){ - printf ("error: %s\n", s); - exit (1); - } - l = calendar_get_events_in_range (cal, from_t, to_t); - for (; l; l = l->next){ - char start [80], end [80]; - CalendarObject *co = l->data; - struct tm ts, te; - char *format; - - ts = *localtime (&co->ev_start); - te = *localtime (&co->ev_end); - - if (same_day (&today, &ts)) - format = N_("%H:%M"); - else - format = N_("%A %b %d, %H:%M"); - strftime (start, sizeof (start), _(format), &ts); - - if (!same_day (&ts, &te)) - format = N_("%A %b %d, %H:%M"); - strftime (end, sizeof (start), _(format), &te); - - printf ("%s -- %s\n", start, end); - printf (" %s\n", co->ico->summary); - } - calendar_destroy_event_list (l); - calendar_destroy (cal); - exit (0); -} - -static void -dump_todo (void) -{ - Calendar *cal; - GList *l; - char *s; - - process_dates (); - init_calendar (); - - cal = calendar_new (full_name, CALENDAR_INIT_ALARMS); - s = calendar_load (cal, load_file ? load_file : user_calendar_file); - if (s){ - printf ("error: %s\n", s); - exit (1); - } - for (l = cal->todo; l; l = l->next){ - iCalObject *object = l->data; - - if (object->type != ICAL_TODO) - continue; - - printf ("[%s]: %s\n",object->organizer->addr, object->summary); - } - calendar_destroy (cal); - exit (0); -} - -extern time_t get_date (); - -static void -parse_an_arg (poptContext ctx, - enum poptCallbackReason reason, - const struct poptOption *opt, - char *arg, void *data) -{ - switch (opt->val){ - case 'f': - from_t = get_date (arg, NULL); - break; - - case 't': - to_t = get_date (arg, NULL); - break; - - case GEOMETRY_KEY: - start_geometries = g_list_append (start_geometries, arg); - break; - - case USERFILE_KEY: - /* This is a special key that tells the program to load - * the user's calendar file. This allows session management - * to work even if the User's home directory changes location - * (ie, on a networked setup). - */ - arg = COOKIE_USER_HOME_DIR; - /* fall through */ - break; - - case VIEW_KEY: - start_views = g_list_append (start_views, arg); - break; - - case 'F': - start_calendars = g_list_append (start_calendars, arg); - break; - - case TODO_KEY: - show_todo = 1; - break; - - case 'e': - show_events = 1; - break; - - case HIDDEN_KEY: - startup_hidden = 1; - break; - - case DEBUG_KEY: - if (!g_strcasecmp (arg, "alarms")) - debug_alarms = 1; - break; - - default: - } -} - -static const struct poptOption options [] = { - { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL }, - { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"), - NULL }, - { "todo", 0, POPT_ARG_NONE, NULL, TODO_KEY, N_("Show TO-DO items and quit"), - NULL }, - { "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") }, - { "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") }, - { "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL }, - { "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") }, - { "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode (dayview, weekview, monthview, yearview)"), N_("VIEW") }, - { "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") }, - { "hidden", 0, POPT_ARG_NONE, NULL, HIDDEN_KEY, N_("If used, starts in iconic mode"), NULL }, - { "debug", 'd', POPT_ARG_STRING, NULL, DEBUG_KEY, N_("Enable debugging output of TYPE (alarms)"), N_("TYPE") }, - { NULL, '\0', 0, NULL, 0} -}; - -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); - - if (strcmp (gcal->cal->filename, user_calendar_file) == 0) - argv [i++] = "--userfile"; - else { - argv [i++] = "--file"; - argv [i++] = gcal->cal->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); - calendar_save (gcal->cal, gcal->cal->filename); - } - 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; - - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE); - - CORBA_exception_init (&ev); - - gnome_CORBA_init_with_popt_table ( - "calendar", VERSION, &argc, argv, - options, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev); - - orb = gnome_CORBA_ORB (); - poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev); - if (ev._major == CORBA_NO_EXCEPTION){ - init_corba_server (); - } - - if (show_events) - dump_events (); - if (show_todo) - dump_todo (); - - client = gnome_master_client (); - if (client){ - gtk_signal_connect (GTK_OBJECT (client), "save_yourself", - GTK_SIGNAL_FUNC (session_save_state), argv [0]); - gtk_signal_connect (GTK_OBJECT (client), "die", - GTK_SIGNAL_FUNC (session_die), NULL); - } - - process_dates (); - alarm_init (); - init_calendar (); - - /* - * Load all of the calendars specifies in the command line with - * the geometry specificied -if any- - */ - if (start_calendars){ - GList *p, *g, *v; - char *title; - - p = start_calendars; - g = start_geometries; - v = start_views; - while (p){ - char *file = p->data; - char *geometry = g ? g->data : NULL; - char *page_name = v ? v->data : NULL; - - if (file == COOKIE_USER_HOME_DIR) - file = user_calendar_file; - - if (strcmp (file, user_calendar_file) == 0) - title = full_name; - else - title = file; - new_calendar (title, file, geometry, page_name, startup_hidden); - - p = p->next; - if (g) - g = g->next; - if (v) - v = v->next; - } - g_list_free (p); - } else { - char *geometry = start_geometries ? start_geometries->data : NULL; - char *page_name = start_views ? start_views->data : NULL; - - new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden); - } - gtk_main (); - return 0; -} diff --git a/calendar/main.h b/calendar/main.h deleted file mode 100644 index 2785e1d2d1..0000000000 --- a/calendar/main.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef MAIN_H -#define MAIN_H - -/* Calendar preferences */ - -extern int day_begin, day_end; -extern char *user_name; -extern int am_pm_flag; -extern int week_starts_on_monday; - - -/* This enum and the following array define the color preferences */ - -typedef enum { - COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */ - COLOR_PROP_HEADING_COLOR, /* Color for headings */ - COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */ - COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */ - COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ - COLOR_PROP_DAY_FG, /* Color for day numbers */ - COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ - COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */ - COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */ - COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */ - COLOR_PROP_LAST /* Number of color properties */ -} ColorProp; - -struct color_prop { - int r; /* Values are in [0, 65535] */ - int g; - int b; - char *label; /* Label for properties dialog */ - char *key; /* Key for gnome_config */ -}; - -extern struct color_prop color_props[]; - - -/* todo preferences */ -extern int todo_show_due_date; - -extern int todo_item_dstatus_highlight_overdue; -extern int todo_item_dstatus_highlight_due_today; -extern int todo_item_dstatus_highlight_not_due_yet; - -extern int todo_show_time_remaining; -extern int todo_show_priority; -extern char *todo_overdue_font_text; -extern gboolean todo_style_changed; -extern gint todo_current_sort_column; -extern gint todo_current_sort_type; - -/* alarm stuff */ -extern CalendarAlarm alarm_defaults[4]; -extern gboolean beep_on_display; -extern gboolean enable_aalarm_timeout; -extern guint audio_alarm_timeout; -extern const guint MAX_AALARM_TIMEOUT; -extern gboolean enable_snooze; -extern guint snooze_secs; -extern const guint MAX_SNOOZE_SECS; - -/* Creates and runs the preferences dialog box */ -void properties (GtkWidget *toplevel); - -/* Asks for all the time-related displays to be updated when the user changes the time format - * preferences. - */ -void time_format_changed (void); - -/* Asks for all the month items' colors to be reset */ -void colors_changed (void); - -/* Asks for all todo lists to reflect the accurate properties */ -void todo_properties_changed(void); - -/* Creates and runs the Go-to date dialog */ -void goto_dialog (GnomeCalendar *gcal); - -/* Returns a pointer to a statically-allocated string with a representation of the specified color. - * Values must be in [0, 65535]. - */ -char *build_color_spec (int r, int g, int b); - -/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */ -void parse_color_spec (char *spec, int *r, int *g, int *b); - -/* Calls build_color_spec() for the color in the specified property number */ -char *color_spec_from_prop (ColorProp propnum); - -void save_default_calendar (GnomeCalendar *gcal); - -GnomeCalendar *new_calendar (char *full_name, char *calendar_file, - char *geometry, char *page, gboolean hidden); - -#endif - - - - - diff --git a/calendar/mark.c b/calendar/mark.c deleted file mode 100644 index 288b6d3b11..0000000000 --- a/calendar/mark.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Functions to mark calendars - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include "gnome-cal.h" -#include "main.h" -#include "mark.h" -#include "cal-util/timeutil.h" - - -/* Frees the specified data when an object is destroyed */ -static void -free_data (GtkObject *object, gpointer data) -{ - g_free (data); -} - -/* If the array of "marked" attributes for the days in a a month item has not been created yet, this - * function creates the array and clears it. Otherwise, it just returns the existing array. - */ -static char * -get_attributes (GnomeMonthItem *mitem) -{ - char *attrs; - - attrs = gtk_object_get_data (GTK_OBJECT (mitem), "day_mark_attributes"); - - if (!attrs) { - attrs = g_new0 (char, 42); - gtk_object_set_data (GTK_OBJECT (mitem), "day_mark_attributes", attrs); - gtk_signal_connect (GTK_OBJECT (mitem), "destroy", - (GtkSignalFunc) free_data, - attrs); - } - - return attrs; -} - -void -colorify_month_item (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data) -{ - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (func != NULL); - - unmark_month_item (mitem); - - /* We have to do this in several calls to gnome_canvas_item_set(), as color_spec_from_prop() - * returns a pointer to a static string -- and we need several values. - */ - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "heading_color", (* func) (COLOR_PROP_HEADING_COLOR, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "outline_color", (* func) (COLOR_PROP_OUTLINE_COLOR, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "day_box_color", (* func) (COLOR_PROP_EMPTY_DAY_BG, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "day_color", (* func) (COLOR_PROP_DAY_FG, func_data), - NULL); -} - -/* In the month item, marks all the days that are touched by the specified time span. Assumes that - * the time span is completely contained within the month. The array of day attributes is modified - * accordingly. - */ -static void -mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end) -{ - struct tm tm; - int day_index; - - tm = *localtime (&start); - - for (; start <= end; start += 60 * 60 * 24) { - mktime (&tm); /* normalize the time */ - - /* Figure out the day index that corresponds to this time */ - - day_index = gnome_month_item_day2index (mitem, tm.tm_mday); - g_assert (day_index >= 0); - - /* Mark the day box */ - - mark_month_item_index (mitem, day_index, default_color_func, NULL); - - /* Next day */ - - tm.tm_mday++; - } -} - -void -mark_month_item (GnomeMonthItem *mitem, Calendar *cal) -{ - time_t month_begin, month_end; - GList *list, *l; - CalendarObject *co; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (cal != NULL); - - month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1)); - month_end = time_month_end (month_begin); - - list = calendar_get_events_in_range (cal, month_begin, month_end); - - for (l = list; l; l = l->next) { - co = l->data; - - /* We clip the event's start and end times to the month's limits */ - - mark_event_in_month (mitem, MAX (co->ev_start, month_begin), MIN (co->ev_end, month_end)); - } - - calendar_destroy_event_list (list); -} - -void -mark_month_item_index (GnomeMonthItem *mitem, int index, GetColorFunc func, gpointer func_data) -{ - char *attrs; - GnomeCanvasItem *item; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail ((index >= 0) && (index < 42)); - g_return_if_fail (func != NULL); - - attrs = get_attributes (mitem); - - attrs[index] = TRUE; - - item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + index); - gnome_canvas_item_set (item, - "fill_color", (* func) (COLOR_PROP_MARK_DAY_BG, func_data), - NULL); -} - -void -unmark_month_item (GnomeMonthItem *mitem) -{ - int i; - char *attrs; - GnomeCanvasItem *item; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - - attrs = get_attributes (mitem); - - /* Find marked days and unmark them by turning off their marked attribute flag and changing - * the color. - */ - - for (i = 0; i < 42; i++) - if (attrs[i]) { - attrs[i] = FALSE; - - item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + i); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_EMPTY_DAY_BG), - NULL); - } -} - -/* Handles EnterNotify and LeaveNotify events from the month item's day groups, and performs - * appropriate prelighting. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - GnomeMonthItem *mitem; - GnomeCanvasItem *box; - int child_num, day; - GetColorFunc func; - gpointer func_data; - char *color; - char *attrs; - - /* We only accept enters and leaves */ - - if (!((event->type == GDK_ENTER_NOTIFY) || (event->type == GDK_LEAVE_NOTIFY))) - return FALSE; - - /* Get index information */ - - mitem = GNOME_MONTH_ITEM (data); - child_num = gnome_month_item_child2num (mitem, item); - day = gnome_month_item_num2day (mitem, child_num); - - if (day == 0) - return FALSE; /* it was a day outside the month's range */ - - child_num -= GNOME_MONTH_ITEM_DAY_GROUP; - box = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + child_num); - - /* Get colors */ - - func = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_func"); - func_data = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_data"); - - /* Now actually set the proper color in the item */ - - switch (event->type) { - case GDK_ENTER_NOTIFY: - color = (* func) (COLOR_PROP_PRELIGHT_DAY_BG, func_data); - gnome_canvas_item_set (box, - "fill_color", color, - NULL); - break; - - case GDK_LEAVE_NOTIFY: - attrs = get_attributes (mitem); - color = (* func) (attrs[child_num] ? COLOR_PROP_MARK_DAY_BG : COLOR_PROP_EMPTY_DAY_BG, - func_data); - gnome_canvas_item_set (box, - "fill_color", color, - NULL); - break; - - default: - g_assert_not_reached (); - } - - return TRUE; -} - -void -month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data) -{ - GnomeCanvasItem *day_group; - int i; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (func != NULL); - - /* Store the function in the object data */ - - gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_func", func); - gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_data", func_data); - - /* Connect the appropriate signals to perform prelighting */ - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - mitem); - } -} - -char * -default_color_func (ColorProp propnum, gpointer data) -{ - return color_spec_from_prop (propnum); -} diff --git a/calendar/mark.h b/calendar/mark.h deleted file mode 100644 index cf8f7c1496..0000000000 --- a/calendar/mark.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Functions to mark calendars - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef MARK_H -#define MARK_H - -#include "calendar.h" -#include "gnome-month-item.h" - - -/* These are the fonts used for the montly calendars */ - -#define HEADING_FONTSET "-adobe-helvetica-medium-r-*-*-14-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-17-*-*-*-p-*-koi8-r,-*-*-medium-r-*-*-14-*-*-*-*-*-ksc5601.1987-0,*" -#define TITLE_FONTSET "-adobe-helvetica-bold-r-normal--12-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-14-*-*-*-p-*-koi8-r,-*-*-bold-r-normal--12-*-*-*-*-*-ksc5601.1987-0,*" -#define DAY_HEADING_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" -#define NORMAL_DAY_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" -#define CURRENT_DAY_FONTSET "-adobe-helvetica-bold-r-normal--12-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-14-*-*-*-p-*-koi8-r,-*-*-bold-r-normal--12-*-*-*-*-*-ksc5601.1987-0,*" -#define BIG_DAY_HEADING_FONTSET "-adobe-helvetica-bold-r-normal--14-*-*-*-p-*-*-*,-cronyx-helvetica-bold-r-normal-*-17-*-*-*-p-*-koi8-r,-*-*-bold-r-normal--14-*-*-*-*-*-ksc5601.1987-0,*" -#define BIG_NORMAL_DAY_FONTSET "-adobe-helvetica-medium-r-normal--14-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-17-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--14-*-*-*-*-*-ksc5601.1987-0,*" -#define BIG_CURRENT_DAY_FONTSET "-adobe-helvetica-bold-r-normal--14-*-*-*-p-*-*-*,-cronyx-helvetica-bold-r-normal-*-17-*-*-*-p-*-koi8-r,-*-*-bold-r-normal--14-*-*-*-*-*-ksc5601.1987-0,*" -#define EVENT_FONTSET "-adobe-helvetica-medium-r-*-*-10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" - - -/* Functions of this type are used by the marking functions to fetch color specifications. Such - * a function must return a color spec based on the property passed to it. - */ -typedef char * (* GetColorFunc) (ColorProp propnum, gpointer data); - - -/* Sets the user-configured colors and font for a month item. It also tags the days as unmarked. */ -void colorify_month_item (GnomeMonthItem *month, GetColorFunc func, gpointer func_data); - -/* Takes a monthly calendar item and marks the days that have events scheduled for them in the - * specified calendar. It also highlights the current day. - */ -void mark_month_item (GnomeMonthItem *mitem, Calendar *cal); - -/* Marks a day specified by index, not by day number */ -void mark_month_item_index (GnomeMonthItem *mitem, int index, GetColorFunc func, gpointer func_data); - -/* Unmarks all the days in the specified month item */ -void unmark_month_item (GnomeMonthItem *mitem); - -/* Prepares a monthly calendar item to prelight when the mouse goes over the days. */ - -void month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data); - -/* This is the default prelight function you can use for most puposes. You can use NULL as the - * func_data. - */ -char *default_color_func (ColorProp prop_num, gpointer data); - - -#endif diff --git a/calendar/month-view.c b/calendar/month-view.c deleted file mode 100644 index 0a7386f9e4..0000000000 --- a/calendar/month-view.c +++ /dev/null @@ -1,798 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gnome.h> -#include <libgnomeui/gnome-canvas-text.h> -#include "eventedit.h" -#include "layout.h" -#include "month-view.h" -#include "main.h" -#include "mark.h" -#include "quick-view.h" -#include "cal-util/timeutil.h" - - -/* Spacing between title and calendar */ -#define SPACING 4 - -/* Padding between day borders and event text */ -#define EVENT_PADDING 3 - - -static void month_view_class_init (MonthViewClass *class); -static void month_view_init (MonthView *mv); -static void month_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void month_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvasClass *parent_class; - - -GtkType -month_view_get_type (void) -{ - static GtkType month_view_type = 0; - - if (!month_view_type) { - GtkTypeInfo month_view_info = { - "MonthView", - sizeof (MonthView), - sizeof (MonthViewClass), - (GtkClassInitFunc) month_view_class_init, - (GtkObjectInitFunc) month_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - month_view_type = gtk_type_unique (gnome_canvas_get_type (), &month_view_info); - } - - return month_view_type; -} - -static void -month_view_class_init (MonthViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - widget_class->size_request = month_view_size_request; - widget_class->size_allocate = month_view_size_allocate; -} - -/* Creates the quick view when a day is clicked in the month view */ -static void -do_quick_view_popup (MonthView *mv, GdkEventButton *event, int day) -{ - time_t day_begin_time, day_end_time; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_begin_time = time_from_day (mv->year, mv->month, day); - day_end_time = time_day_end (day_begin_time); - - list = calendar_get_events_in_range (mv->calendar->cal, day_begin_time, day_end_time); - - strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_begin_time)); - qv = quick_view_new (mv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - calendar_destroy_event_list (list); -} - -/* Callback used to destroy the popup menu when the month view is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Creates a new appointment in the current day */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (mv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (mv->calendar, view_name); - gnome_calendar_goto (mv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_year (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "yearview"); -} - -static GnomeUIInfo mv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _year"), NULL, jump_to_year, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Creates the popup menu for the month view if it does not yet exist, and attaches it to the month - * view object so that it can be destroyed when appropriate. - */ -static GtkWidget * -get_popup_menu (MonthView *mv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (mv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (mv_popup_menu); - gtk_object_set_data (GTK_OBJECT (mv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (mv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Pops up the menu for the month view. */ -static void -do_popup_menu (MonthView *mv, GdkEventButton *event, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (mv); - - /* Enable or disable items as appropriate */ - - gtk_widget_set_sensitive (mv_popup_menu[0].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[2].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[3].widget, day != 0); - - if (day == 0) - day = 1; - - /* Store the time for the menu item callbacks to use */ - - t = time_from_day (mv->year, mv->month, day); - - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, mv); -} - -/* Event handler for day groups. When mouse button 1 is pressed, it will pop up a quick view with - * the events in that day. When mouse button 3 is pressed, it will pop up a menu. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - int child_num; - int day; - - mv = MONTH_VIEW (data); - - child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (mv->mitem), item); - day = gnome_month_item_num2day (GNOME_MONTH_ITEM (mv->mitem), child_num); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((event->button.button == 1) && (day != 0)) { - do_quick_view_popup (mv, (GdkEventButton *) event, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (mv, (GdkEventButton *) event, day); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Returns the index of the specified arrow in the array of arrows */ -static int -get_arrow_index (MonthView *mv, GnomeCanvasItem *arrow) -{ - int i; - - for (i = 0; i < 42; i++) - if (mv->up[i] == arrow) - return i; - else if (mv->down[i] == arrow) - return i + 42; - - g_warning ("Eeeek, arrow %p not found in month view %p", arrow, mv); - return -1; -} - -/* Checks whether arrows need to be displayed at the specified day index or not */ -static void -check_arrow_visibility (MonthView *mv, int day_index) -{ - GtkArg args[3]; - double text_height; - double clip_height; - double y_offset; - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 3, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - - /* Check up arrow */ - - if (y_offset < 0.0) - gnome_canvas_item_show (mv->up[day_index]); - else - gnome_canvas_item_hide (mv->up[day_index]); - - if (y_offset > (clip_height - text_height)) - gnome_canvas_item_show (mv->down[day_index]); - else - gnome_canvas_item_hide (mv->down[day_index]); -} - -/* Finds which arrow was clicked and scrolls the corresponding text item in the month view */ -static void -do_arrow_click (MonthView *mv, GnomeCanvasItem *arrow) -{ - int arrow_index; - int day_index; - int up; - GtkArg args[4]; - double text_height, clip_height; - double y_offset; - GdkFont *font; - - arrow_index = get_arrow_index (mv, arrow); - up = (arrow_index < 42); - day_index = up ? arrow_index : (arrow_index - 42); - - /* See how much we can scroll */ - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - args[3].name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 4, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - font = GTK_VALUE_BOXED (args[3]); - - if (up) - y_offset += font->ascent + font->descent; - else - y_offset -= font->ascent + font->descent; - - if (y_offset > 0.0) - y_offset = 0.0; - else if (y_offset < (clip_height - text_height)) - y_offset = clip_height - text_height; - - /* Scroll */ - - gnome_canvas_item_set (mv->text[day_index], - "y_offset", y_offset, - NULL); - - check_arrow_visibility (mv, day_index); -} - -/* Event handler for the scroll arrows in the month view */ -static gint -arrow_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - - mv = MONTH_VIEW (data); - - switch (event->type) { - case GDK_ENTER_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG), - NULL); - return TRUE; - - case GDK_LEAVE_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - NULL); - return TRUE; - - case GDK_BUTTON_PRESS: - if (event->button.button != 1) - break; - - do_arrow_click (mv, item); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Creates a new arrow out of the specified points and connects the proper signals to it */ -static GnomeCanvasItem * -new_arrow (MonthView *mv, GnomeCanvasGroup *group, GnomeCanvasPoints *points) -{ - GnomeCanvasItem *item; - char *color_spec; - - color_spec = color_spec_from_prop (COLOR_PROP_DAY_FG); - - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", color_spec, - "outline_color", color_spec, - NULL); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) arrow_event, - mv); - - return item; -} - -static void -month_view_init (MonthView *mv) -{ - int i; - GnomeCanvasItem *day_group; - GnomeCanvasPoints *points; - - /* Title */ - - mv->title = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (mv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "fontset", HEADING_FONTSET, - "fill_color", "black", - NULL); - - /* Month item */ - - mv->mitem = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (mv))); - gnome_canvas_item_set (mv->mitem, - "x", 0.0, - "anchor", GTK_ANCHOR_NW, - "day_anchor", GTK_ANCHOR_NE, - "start_on_monday", week_starts_on_monday, - "heading_padding", 2.0, - "heading_fontset", BIG_DAY_HEADING_FONTSET, - "day_fontset", BIG_NORMAL_DAY_FONTSET, - NULL); - - /* Arrows and text items. The arrows start hidden by default; they will be shown as - * appropriate by the item adjustment code. Also, connect to the event signal of the - * day groups so that we can pop up the quick view when appropriate. - */ - - points = gnome_canvas_points_new (3); - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - i + GNOME_MONTH_ITEM_DAY_GROUP); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - mv); - - /* Up arrow */ - - points->coords[0] = 3; - points->coords[1] = 10; - points->coords[2] = 11; - points->coords[3] = 10; - points->coords[4] = 7; - points->coords[5] = 3; - - mv->up[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Down arrow */ - - points->coords[0] = 13; - points->coords[1] = 3; - points->coords[2] = 17; - points->coords[3] = 10; - points->coords[4] = 21; - points->coords[5] = 3; - - mv->down[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Text item */ - - mv->text[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (day_group), - gnome_canvas_text_get_type (), - "fontset", EVENT_FONTSET, - "anchor", GTK_ANCHOR_NW, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "clip", TRUE, - NULL); - } - gnome_canvas_points_free (points); - - mv->old_current_index = -1; -} - -GtkWidget * -month_view_new (GnomeCalendar *calendar, time_t month) -{ - MonthView *mv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - mv = gtk_type_new (month_view_get_type ()); - mv->calendar = calendar; - - month_view_colors_changed (mv); - month_view_set (mv, month); - return GTK_WIDGET (mv); -} - -static void -month_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - if (GTK_WIDGET_CLASS (parent_class)->size_request) - (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition); - - requisition->width = 200; - requisition->height = 150; -} - -/* Adjusts the text items for events in the month view to the appropriate size. It also makes the - * corresponding arrows visible or invisible, as appropriate. - */ -static void -adjust_children (MonthView *mv) -{ - int i; - GnomeCanvasItem *item; - double x1, y1, x2, y2; - GtkArg arg; - - for (i = 0; i < 42; i++) { - /* Get dimensions of the day group */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_GROUP); - gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2); - - /* Normalize and add paddings */ - - x2 -= x1 + EVENT_PADDING; - x1 = EVENT_PADDING; - y2 -= y1 + EVENT_PADDING; - y1 = EVENT_PADDING; - - /* Add height of day label to y1 */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_LABEL); - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 1, &arg); - y1 += GTK_VALUE_DOUBLE (arg); - - /* Set the position and clip size */ - - gnome_canvas_item_set (mv->text[i], - "x", x1, - "y", y1, - "clip_width", x2 - x1, - "clip_height", y2 - y1, - "x_offset", 0.0, - "y_offset", 0.0, - NULL); - - /* See what visibility state the arrows should be set to */ - - check_arrow_visibility (mv, i); - } -} - -static void -month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - MonthView *mv; - GdkFont *font; - GtkArg arg; - int y; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - mv = MONTH_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mv), 0, 0, allocation->width, allocation->height); - - /* Adjust items to new size */ - - arg.name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->title), 1, &arg); - font = GTK_VALUE_BOXED (arg); - - gnome_canvas_item_set (mv->title, - "x", (double) allocation->width / 2.0, - "y", (double) SPACING, - NULL); - - y = font->ascent + font->descent + 2 * SPACING; - gnome_canvas_item_set (mv->mitem, - "y", (double) y, - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - y - 1), - NULL); - - /* Adjust children */ - - adjust_children (mv); -} - -/* This defines the environment for the calendar iterator function that is used to populate the - * month view with events. - */ -struct iter_info { - MonthView *mv; /* The month view we are creating children for */ - int first_day_index; /* Index of the first day of the month within the month item */ - time_t month_begin, month_end; /* Beginning and end of month */ - GString **strings; /* Array of strings to populate */ -}; - -/* This is the calendar iterator function used to populate the string array with event information. - * For each event, it iterates through all the days that the event touches and appends the proper - * information to the string array in the iter_info structure. - */ -static int -add_event (iCalObject *ico, time_t start, time_t end, void *data) -{ - struct iter_info *ii; - struct tm tm; - time_t t; - time_t day_begin_time, day_end_time; - - ii = data; - - /* Get the first day of the event */ - - t = MAX (start, ii->month_begin); - day_begin_time = time_day_begin (t); - day_end_time = time_day_end (day_begin_time); - - /* Loop until the event ends or the month ends. For each day touched, append the proper - * information to the corresponding string. - */ - - do { - tm = *localtime (&day_begin_time); - g_string_sprintfa (ii->strings[ii->first_day_index + tm.tm_mday - 1], "%s\n", ico->summary); - - /* Next day */ - - day_begin_time = time_add_day (day_begin_time, 1); - day_end_time = time_day_end (day_begin_time); - } while ((end > day_begin_time) && (day_begin_time < ii->month_end)); - - return TRUE; /* this means we are not finished yet with event generation */ -} - -void -month_view_update (MonthView *mv, iCalObject *object, int flags) -{ - struct iter_info ii; - GString *strings[42]; - int i; - time_t t; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - ii.mv = mv; - - /* Create an array of empty GStrings */ - - ii.strings = strings; - - for (i = 0; i < 42; i++) - strings[i] = g_string_new (NULL); - - ii.first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), 1); - g_assert (ii.first_day_index != -1); - - /* Populate the array of strings with events */ - - t = time_from_day (mv->year, mv->month, 1); - ii.month_begin = time_month_begin (t); - ii.month_end = time_month_end (t); - - calendar_iterate (mv->calendar->cal, ii.month_begin, ii.month_end, add_event, &ii); - - for (i = 0; i < 42; i++) { - /* Delete the last character if it is a newline */ - - if (strings[i]->str && strings[i]->len && (strings[i]->str[strings[i]->len - 1] == '\n')) - g_string_truncate (strings[i], strings[i]->len - 1); - - gnome_canvas_item_set (mv->text[i], - "text", strings[i]->str, - NULL); - g_string_free (strings[i], TRUE); - } - - /* Adjust children for scrolling */ - - adjust_children (mv); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (MonthView *mv) -{ - time_t t; - struct tm tm; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (mv->old_current_index != -1) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "fontset", BIG_NORMAL_DAY_FONTSET, - NULL); - - mv->old_current_index = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = *localtime (&t); - - if (((tm.tm_year + 1900) == mv->year) && (tm.tm_mon == mv->month)) { - mv->old_current_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), tm.tm_mday); - g_assert (mv->old_current_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "fontset", BIG_CURRENT_DAY_FONTSET, - NULL); - } -} - -void -month_view_set (MonthView *mv, time_t month) -{ - struct tm tm; - char buf[100]; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - /* Title */ - - tm = *localtime (&month); - - mv->year = tm.tm_year + 1900; - mv->month = tm.tm_mon; - - strftime (buf, 100, _("%B %Y"), &tm); - - gnome_canvas_item_set (mv->title, - "text", buf, - NULL); - - /* Month item */ - - gnome_canvas_item_set (mv->mitem, - "year", mv->year, - "month", mv->month, - NULL); - - /* Update events */ - - month_view_update (mv, NULL, 0); - mark_current_day (mv); -} - -void -month_view_time_format_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - gnome_canvas_item_set (mv->mitem, - "start_on_monday", week_starts_on_monday, - NULL); - - month_view_set (mv, time_month_begin (time_from_day (mv->year, mv->month, 1))); -} - -void -month_view_colors_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - colorify_month_item (GNOME_MONTH_ITEM (mv->mitem), default_color_func, NULL); - mark_current_day (mv); - - /* FIXME: set children to the marked color */ -} diff --git a/calendar/month-view.h b/calendar/month-view.h deleted file mode 100644 index 6e49c2f931..0000000000 --- a/calendar/month-view.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef MONTH_VIEW_H -#define MONTH_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_MONTH_VIEW (month_view_get_type ()) -#define MONTH_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_MONTH_VIEW, MonthView)) -#define MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_MONTH_VIEW, MonthViewClass)) -#define IS_MONTH_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_MONTH_VIEW)) -#define IS_MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_MONTH_VIEW)) - - -typedef struct _MonthView MonthView; -typedef struct _MonthViewClass MonthViewClass; - -struct _MonthView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year of the month we are displaying */ - int month; /* The month we are displaying */ - int old_current_index; /* The index of the day marked as current, or -1 if none */ - - GnomeCanvasItem *up[42]; /* Arrows to go up in the days */ - GnomeCanvasItem *down[42]; /* Arrows to go down in the days */ - GnomeCanvasItem *text[42]; /* Text items for the events */ - - GnomeCanvasItem *title; /* The title heading with the month/year */ - GnomeCanvasItem *mitem; /* The canvas month item used by this month view */ -}; - -struct _MonthViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType month_view_get_type (void); - -/* Creates a new month view widget associated to the specified calendar */ -GtkWidget *month_view_new (GnomeCalendar *calendar, time_t month); - -/* Notifies the month view that a calendar object has changed */ -void month_view_update (MonthView *mv, iCalObject *ico, int flags); - -/* Notifies the month view about a change of date */ -void month_view_set (MonthView *mv, time_t month); - -/* Notifies the month view that the time format has changed */ -void month_view_time_format_changed (MonthView *mv); - -/* Notifies the month view that the colors have changed */ -void month_view_colors_changed (MonthView *mv); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/popup-menu.c b/calendar/popup-menu.c deleted file mode 100644 index 3686183146..0000000000 --- a/calendar/popup-menu.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Popup menu utilities for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <config.h> -#include <gnome.h> -#include "popup-menu.h" - - -void -popup_menu (struct menu_item *items, int nitems, GdkEventButton *event) -{ - GtkWidget *menu; - GtkWidget *item; - int i; - - menu = gtk_menu_new (); /* FIXME: this baby is never freed */ - - for (i = 0; i < nitems; i++) { - if (items[i].text) { - item = gtk_menu_item_new_with_label (_(items[i].text)); - gtk_signal_connect (GTK_OBJECT (item), "activate", - items[i].callback, - items[i].data); - gtk_widget_set_sensitive (item, items[i].sensitive); - } else - item = gtk_menu_item_new (); - - gtk_widget_show (item); - gtk_menu_append (GTK_MENU (menu), item); - } - - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); -} diff --git a/calendar/popup-menu.h b/calendar/popup-menu.h deleted file mode 100644 index a4590dbb98..0000000000 --- a/calendar/popup-menu.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Popup menu utilities for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef POPUP_MENU_H -#define POPUP_MENU_H - -#include <gdk/gdktypes.h> -#include <gtk/gtksignal.h> - - -struct menu_item { - char *text; - GtkSignalFunc callback; - gpointer data; - int sensitive; -}; - -void popup_menu (struct menu_item *items, int nitems, GdkEventButton *event); - - -#endif diff --git a/calendar/prop.c b/calendar/prop.c deleted file mode 100644 index 8e91f4d730..0000000000 --- a/calendar/prop.c +++ /dev/null @@ -1,927 +0,0 @@ -/* Calendar properties dialog box - * - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@kernel.org> - * Federico Mena <federico@nuclecu.unam.mx> - */ -#include <config.h> -#ifdef HAVE_LANGINGO_H -#include <langinfo.h> -#else -#include <locale.h> -#endif -#include <gnome.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" -#include "main.h" -#include "mark.h" - -/* These specify the page numbers in the preferences notebook */ -enum { - PROP_TIME_DISPLAY, - PROP_COLORS, - PROP_TODO, - PROP_ALARMS -}; - -static GtkWidget *prop_win; /* The preferences dialog */ - -/* Widgets for the time display page */ - -static GtkWidget *time_format_12; /* Radio button for 12-hour format */ -static GtkWidget *time_format_24; /* Radio button for 24-hour format */ -static GtkWidget *start_on_sunday; /* Check button for weeks starting on Sunday */ -static GtkWidget *start_on_monday; /* Check button for weeks starting on Monday */ -static GtkWidget *start_omenu; /* Option menu for start of day */ -static GtkWidget *end_omenu; /* Option menu for end of day */ -static GtkWidget *start_items[24]; /* Menu items for start of day menu */ -static GtkWidget *end_items[24]; /* Menu items for end of day menu */ - -/* Widgets for the colors page */ - -static GtkWidget *color_pickers[COLOR_PROP_LAST]; -static GnomeCanvasItem *month_item; - -/* Widgets for the todo page */ -static GtkWidget *due_date_show_button; - -static GtkWidget *todo_item_time_remaining_show_button; - -static GtkWidget *todo_item_highlight_overdue; -static GtkWidget *todo_item_highlight_not_due_yet; -static GtkWidget *todo_item_highlight_due_today; - -static GtkWidget *priority_show_button; - -/* Widgets for the alarm page */ -static GtkWidget *enable_display_beep; -static GtkWidget *to_cb; -static GtkWidget *to_spin; -static GtkWidget *snooze_cb; -static GtkWidget *snooze_spin; - -/* prototypes */ -static void prop_apply_alarms (void); -static void create_alarm_page (void); -static void to_cb_changed (GtkWidget* object, gpointer data); -static void snooze_cb_changed (GtkWidget* object, gpointer data); - -GtkWidget* make_spin_button (int val, int low, int high); -void ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, - enum AlarmType type, int y, gboolean sens, - GtkSignalFunc dirty_func); -void ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type); - -/* Callback used when the property box is closed -- just sets the prop_win variable to null. */ -static int -prop_cancel (void) -{ - prop_win = NULL; - return FALSE; -} - -/* Returns the index of the active item in a menu */ -static int -get_active_index (GtkWidget *menu) -{ - GtkWidget *active; - - active = gtk_menu_get_active (GTK_MENU (menu)); - return GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (active))); -} - -/* Applies the settings in the time display page */ -static void -prop_apply_time_display (void) -{ - /* Day begin/end */ - - day_begin = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (start_omenu))); - day_end = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (end_omenu))); - gnome_config_set_int ("/calendar/Calendar/Day start", day_begin); - gnome_config_set_int ("/calendar/Calendar/Day end", day_end); - - /* Time format */ - - am_pm_flag = GTK_TOGGLE_BUTTON (time_format_12)->active; - gnome_config_set_bool ("/calendar/Calendar/AM PM flag", am_pm_flag); - - /* Week start */ - - week_starts_on_monday = GTK_TOGGLE_BUTTON (start_on_monday)->active; - gnome_config_set_bool ("/calendar/Calendar/Week starts on Monday", week_starts_on_monday); - - gnome_config_sync (); - time_format_changed (); -} - -/* Applies the settings in the colors page */ -static void -prop_apply_colors (void) -{ - int i; - char *cspec; - gushort r, g, b; - - for (i = 0; i < COLOR_PROP_LAST; i++) { - gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[i]), &r, &g, &b, NULL); - color_props[i].r = r; - color_props[i].g = g; - color_props[i].b = b; - - cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b); - gnome_config_set_string (color_props[i].key, cspec); - } - - gnome_config_sync (); - colors_changed (); -} -/* Applies the settings in the todo page (FIX THIS IF ITS NOT WRITTEN) */ -static void -prop_apply_todo(void) -{ - todo_show_due_date = GTK_TOGGLE_BUTTON (due_date_show_button)->active; - - todo_item_dstatus_highlight_overdue = GTK_TOGGLE_BUTTON(todo_item_highlight_overdue)->active; - todo_item_dstatus_highlight_not_due_yet = GTK_TOGGLE_BUTTON(todo_item_highlight_not_due_yet)->active; - todo_item_dstatus_highlight_due_today = GTK_TOGGLE_BUTTON(todo_item_highlight_due_today)->active; - - todo_show_priority = GTK_TOGGLE_BUTTON (priority_show_button)->active; - - todo_show_time_remaining = GTK_TOGGLE_BUTTON (todo_item_time_remaining_show_button)->active; - - /* storing the values */ - - gnome_config_set_bool("/calendar/Todo/show_time_remain", todo_show_time_remaining); - gnome_config_set_bool("/calendar/Todo/highlight_overdue", todo_item_dstatus_highlight_overdue); - - gnome_config_set_bool("/calendar/Todo/highlight_due_today", todo_item_dstatus_highlight_due_today); - - gnome_config_set_bool("/calendar/Todo/highlight_not_due_yet", todo_item_dstatus_highlight_not_due_yet); - gnome_config_set_bool("/calendar/Todo/show_due_date", todo_show_due_date); - gnome_config_set_bool("/calendar/Todo/show_priority", todo_show_priority); - /* need to sync our config changes. */ - gnome_config_sync (); - - /* apply the current changes */ - todo_properties_changed(); -} - - -/* Callback used when the Apply button is clicked. */ -static void -prop_apply (GtkWidget *w, int page) -{ - switch (page) { - case PROP_TIME_DISPLAY: - prop_apply_time_display (); - break; - - case PROP_COLORS: - prop_apply_colors (); - break; - - case PROP_TODO: - prop_apply_todo (); - break; - - case PROP_ALARMS: - prop_apply_alarms (); - break; - - case -1: - break; - - default: - g_warning ("We have a loose penguin!"); - g_assert_not_reached (); - } -} - -/* Notifies the property box that the data has changed */ -static void -prop_changed (void) -{ - gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win)); -} - -/* Builds and returns a two-element radio button group surrounded by a frame. The radio buttons are - * stored in the specified variables, and the first radio button's state is set according to the - * specified flag value. The buttons are connected to the prop_changed() function to update the property - * box's dirty state. - */ -static GtkWidget * -build_two_radio_group (char *title, - char *radio_1_title, GtkWidget **radio_1_widget, - char *radio_2_title, GtkWidget **radio_2_widget, - int radio_1_value) -{ - GtkWidget *frame; - GtkWidget *vbox; - - frame = gtk_frame_new (title); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - *radio_1_widget = gtk_radio_button_new_with_label (NULL, radio_1_title); - gtk_box_pack_start (GTK_BOX (vbox), *radio_1_widget, FALSE, FALSE, 0); - - *radio_2_widget = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (*radio_1_widget), - radio_2_title); - gtk_box_pack_start (GTK_BOX (vbox), *radio_2_widget, FALSE, FALSE, 0); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (*radio_1_widget), radio_1_value); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (*radio_2_widget), !radio_1_value); - - gtk_signal_connect (GTK_OBJECT (*radio_1_widget), "toggled", - (GtkSignalFunc) prop_changed, - NULL); - - return frame; -} - -/* Callback invoked when a menu item from the start/end time option menus is selected. It adjusts - * the other menu to the proper time, if needed. - */ -static void -hour_activated (GtkWidget *widget, gpointer data) -{ - int start, end; - - if (data == start_omenu) { - /* Adjust the end menu */ - - start = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (widget))); - end = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (end_omenu))); - - if (end < start) - gtk_option_menu_set_history (GTK_OPTION_MENU (end_omenu), start); - } else if (data == end_omenu) { - /* Adjust the start menu */ - - end = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (widget))); - start = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (start_omenu))); - - if (start > end) - gtk_option_menu_set_history (GTK_OPTION_MENU (start_omenu), end); - } else - g_assert_not_reached (); - - gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win)); -} - -/* Builds an option menu of 24 hours */ -static GtkWidget * -build_hours_menu (GtkWidget **items, int active) -{ - GtkWidget *omenu; - GtkWidget *menu; - int i; - char buf[100]; - struct tm tm; - int am_pm_flag; - - omenu = gtk_option_menu_new (); - menu = gtk_menu_new (); - am_pm_flag = GTK_TOGGLE_BUTTON (time_format_12)->active; - - memset (&tm, 0, sizeof (tm)); - - for (i = 0; i < 24; i++) { - tm.tm_hour = i; - if (am_pm_flag) - strftime (buf, 100, "%I:%M %p", &tm); - else - strftime (buf, 100, "%H:%M", &tm); - - items[i] = gtk_menu_item_new_with_label (buf); - gtk_object_set_user_data (GTK_OBJECT (items[i]), GINT_TO_POINTER (i)); - gtk_signal_connect (GTK_OBJECT (items[i]), "activate", - (GtkSignalFunc) hour_activated, - omenu); - - gtk_menu_append (GTK_MENU (menu), items[i]); - gtk_widget_show (items[i]); - } - - gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); - gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), active); - return omenu; -} - -/* Creates the time display page in the preferences dialog */ -static void -create_time_display_page (void) -{ - GtkWidget *table; - GtkWidget *vbox; - GtkWidget *frame; - GtkWidget *hbox2; - GtkWidget *hbox3; - GtkWidget *w; - - table = gtk_table_new (2, 2, FALSE); - gtk_container_set_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL); - gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), table, - gtk_label_new (_("Time display"))); - - /* Time format */ - - w = build_two_radio_group (_("Time format"), - _("12-hour (AM/PM)"), &time_format_12, - _("24-hour"), &time_format_24, - am_pm_flag); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - /* Weeks start on */ - - w = build_two_radio_group (_("Weeks start on"), - _("Sunday"), &start_on_sunday, - _("Monday"), &start_on_monday, - !week_starts_on_monday); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - /* Day range */ - - frame = gtk_frame_new (_("Day range")); - gtk_table_attach (GTK_TABLE (table), frame, - 1, 2, 0, 2, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - w = gtk_label_new (_("Please select the start and end hours you want\n" - "to be displayed in the day view and week view.\n" - "Times outside this range will not be displayed\n" - "by default.")); - gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - hbox2 = gtk_hbox_new (FALSE, GNOME_PAD); - gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); - - /* Day start */ - - hbox3 = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox2), hbox3, FALSE, FALSE, 0); - - w = gtk_label_new (_("Day start:")); - gtk_box_pack_start (GTK_BOX (hbox3), w, FALSE, FALSE, 0); - - start_omenu = build_hours_menu (start_items, day_begin); - gtk_box_pack_start (GTK_BOX (hbox3), start_omenu, FALSE, FALSE, 0); - - /* Day end */ - - hbox3 = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox2), hbox3, FALSE, FALSE, 0); - - w = gtk_label_new (_("Day end:")); - gtk_box_pack_start (GTK_BOX (hbox3), w, FALSE, FALSE, 0); - - end_omenu = build_hours_menu (end_items, day_end); - gtk_box_pack_start (GTK_BOX (hbox3), end_omenu, FALSE, FALSE, 0); -} - -/* Called when the canvas for the month item is size allocated. We use this to change the canvas' - * scrolling region and the month item's size. - */ -static void -canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data) -{ - gnome_canvas_item_set (month_item, - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - 1), - NULL); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, - allocation->width, allocation->height); -} - -/* Returns a color spec based on the color pickers */ -static char * -color_spec_from_picker (int num) -{ - gushort r, g, b; - - gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[num]), &r, &g, &b, NULL); - - return build_color_spec (r, g, b); -} - -/* Callback used to query color information for the properties box */ -static char * -fetch_color_spec (ColorProp propnum, gpointer data) -{ - return color_spec_from_picker (propnum); -} - -/* Marks fake event days in the month item sample */ -static void -fake_mark_days (void) -{ - static int day_nums[] = { 1, 4, 8, 16, 17, 18, 20, 25, 28 }; /* some random days */ - int first_day_index; - int i; - - first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (month_item), 1); - - for (i = 0; i < (sizeof (day_nums) / sizeof (day_nums[0])); i++) - mark_month_item_index (GNOME_MONTH_ITEM (month_item), first_day_index + day_nums[i] - 1, - fetch_color_spec, NULL); -} - -/* Switches the month item to the current date and highlights the current day's number */ -static void -set_current_day (void) -{ - struct tm tm; - time_t t; - GnomeCanvasItem *item; - int day_index; - - /* Set the date */ - - t = time (NULL); - tm = *localtime (&t); - - gnome_canvas_item_set (month_item, - "year", tm.tm_year + 1900, - "month", tm.tm_mon, - NULL); - - /* Highlight current day */ - - day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (month_item), tm.tm_mday); - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item), GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_picker (COLOR_PROP_CURRENT_DAY_FG), - "fontset", CURRENT_DAY_FONTSET, - NULL); -} - -/* This is the version of a color spec query function that is appropriate for the preferences dialog */ -static char * -prop_color_func (ColorProp propnum, gpointer data) -{ - return color_spec_from_picker (propnum); -} - -/* Sets the colors of the month item to the current prerences */ -static void -reconfigure_month (void) -{ - colorify_month_item (GNOME_MONTH_ITEM (month_item), prop_color_func, NULL); - fake_mark_days (); - set_current_day (); - - /* Reset prelighting information */ - - month_item_prepare_prelight (GNOME_MONTH_ITEM (month_item), fetch_color_spec, NULL); -} - -/* Callback used when a color is changed */ -static void -color_set (void) -{ - reconfigure_month (); - prop_changed (); -} - -/* Creates the colors page in the preferences dialog */ -static void -create_colors_page (void) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *table; - GtkWidget *w; - int i; - - frame = gtk_frame_new (_("Colors for display")); - gtk_container_set_border_width (GTK_CONTAINER (frame), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), frame, - gtk_label_new (_("Colors"))); - - hbox = gtk_hbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - table = gtk_table_new (COLOR_PROP_LAST, 2, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0); - - /* Create the color pickers */ - - for (i = 0; i < COLOR_PROP_LAST; i++) { - /* Label */ - - w = gtk_label_new (_(color_props[i].label)); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, i, i + 1, - GTK_FILL, 0, - 0, 0); - - /* Color picker */ - - color_pickers[i] = gnome_color_picker_new (); - gnome_color_picker_set_title (GNOME_COLOR_PICKER (color_pickers[i]), _(color_props[i].label)); - gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (color_pickers[i]), - color_props[i].r, color_props[i].g, color_props[i].b, 0); - gtk_table_attach (GTK_TABLE (table), color_pickers[i], - 1, 2, i, i + 1, - 0, 0, - 0, 0); - gtk_signal_connect (GTK_OBJECT (color_pickers[i]), "color_set", - (GtkSignalFunc) color_set, - NULL); - } - - /* Create the sample calendar */ - - w = gnome_canvas_new (); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - - month_item = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (w))); - gnome_canvas_item_set (month_item, - "start_on_monday", week_starts_on_monday, - NULL); - reconfigure_month (); - - gtk_signal_connect (GTK_OBJECT (w), "size_allocate", - canvas_size_allocate, - NULL); - -} - - -static void -set_todo_page_options(void) -{ - - - while (gtk_events_pending ()) - gtk_main_iteration (); -} - -static void -todo_option_set (void) -{ - prop_changed (); - set_todo_page_options (); -} - -/* Creates the colors page in the preferences dialog */ -static GtkWidget * -build_list_options_frame(void) -{ - GtkWidget *frame; - GtkWidget *vbox; - frame = gtk_frame_new (_("Show on TODO List:")); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - due_date_show_button = gtk_check_button_new_with_label (_("Due Date")); - priority_show_button = gtk_check_button_new_with_label (_("Priority")); - todo_item_time_remaining_show_button = gtk_check_button_new_with_label (_("Time Until Due")); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(due_date_show_button), todo_show_due_date); - gtk_signal_connect (GTK_OBJECT(due_date_show_button), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - gtk_box_pack_start (GTK_BOX (vbox), due_date_show_button, FALSE, FALSE, 0); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_time_remaining_show_button), todo_show_time_remaining); - gtk_signal_connect (GTK_OBJECT(todo_item_time_remaining_show_button), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - gtk_box_pack_start (GTK_BOX (vbox), todo_item_time_remaining_show_button, FALSE, FALSE, 0); - - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(priority_show_button), todo_show_priority); - gtk_signal_connect (GTK_OBJECT(priority_show_button), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - gtk_box_pack_start (GTK_BOX (vbox), priority_show_button, FALSE, FALSE, 0); - return frame; -} -static GtkWidget * -build_style_list_options_frame(void) -{ - GtkWidget *frame; - GtkWidget *vbox; - - frame = gtk_frame_new (_("To Do List style options:")); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - todo_item_highlight_overdue = gtk_check_button_new_with_label (_("Highlight overdue items")); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_overdue), - todo_item_dstatus_highlight_overdue); - todo_item_highlight_not_due_yet = gtk_check_button_new_with_label (_("Highlight not yet due items")); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_not_due_yet), - todo_item_dstatus_highlight_overdue); - todo_item_highlight_due_today = gtk_check_button_new_with_label (_("Highlight items due today")); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON(todo_item_highlight_due_today), - todo_item_dstatus_highlight_overdue); - - gtk_signal_connect (GTK_OBJECT(todo_item_highlight_overdue), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - gtk_signal_connect (GTK_OBJECT(todo_item_highlight_not_due_yet), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - gtk_signal_connect (GTK_OBJECT(todo_item_highlight_due_today), - "clicked", - (GtkSignalFunc) todo_option_set, - NULL); - - gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_overdue, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_due_today, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), todo_item_highlight_not_due_yet, FALSE, FALSE, 0); - return frame; -} -static void -create_todo_page (void) -{ - GtkWidget *frame; - GtkWidget *main_box; - GtkWidget *hbox; - - - frame = gtk_frame_new (_("To Do List Properties")); - gtk_container_set_border_width (GTK_CONTAINER (frame), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), frame, - gtk_label_new (_("To Do List"))); - - /* first vbox*/ - main_box = gtk_vbox_new(FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (main_box), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), main_box); - - - /* first hbox*/ - hbox = gtk_hbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (main_box), hbox); - - gtk_box_pack_start (GTK_BOX(hbox), build_list_options_frame(), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(hbox), build_style_list_options_frame(), FALSE, FALSE, 0); - - set_todo_page_options(); -} - -/* Creates and displays the preferences dialog for the whole application */ -void -properties (GtkWidget *toplevel) -{ - static GnomeHelpMenuEntry help_entry = { NULL, "properties" }; - - help_entry.name = gnome_app_id; - - if (prop_win) - return; - - prop_win = gnome_property_box_new (); - gtk_window_set_title (GTK_WINDOW (prop_win), _("Preferences")); - gnome_dialog_set_parent (GNOME_DIALOG (prop_win), GTK_WINDOW (toplevel)); - - create_time_display_page (); - create_colors_page (); - create_todo_page (); - create_alarm_page (); - - gtk_signal_connect (GTK_OBJECT (prop_win), "destroy", - (GtkSignalFunc) prop_cancel, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "delete_event", - (GtkSignalFunc) prop_cancel, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "apply", - (GtkSignalFunc) prop_apply, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "help", - GTK_SIGNAL_FUNC (gnome_help_pbox_display), - &help_entry); - - gtk_widget_show_all (prop_win); -} - -char * -build_color_spec (int r, int g, int b) -{ - static char spec[100]; - - sprintf (spec, "#%04x%04x%04x", r, g, b); - return spec; -} - -void -parse_color_spec (char *spec, int *r, int *g, int *b) -{ - g_return_if_fail (spec != NULL); - g_return_if_fail (r != NULL); - g_return_if_fail (r != NULL); - g_return_if_fail (r != NULL); - - if (sscanf (spec, "#%04x%04x%04x", r, g, b) != 3) { - g_warning ("Invalid color specification %s, returning black", spec); - - *r = *g = *b = 0; - } -} - -char * -color_spec_from_prop (ColorProp propnum) -{ - return build_color_spec (color_props[propnum].r, color_props[propnum].g, color_props[propnum].b); -} - -static void -create_alarm_page (void) -{ - GtkWidget *main_box; - GtkWidget *default_frame; - GtkWidget *default_table; - GtkWidget *misc_frame; - GtkWidget *misc_box; - GtkWidget *box, *l; - - main_box = gtk_vbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (main_box), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), - main_box, gtk_label_new (_("Alarms"))); - - /* build miscellaneous box */ - misc_frame = gtk_frame_new (_("Alarm Properties")); - gtk_container_set_border_width (GTK_CONTAINER (misc_frame), - GNOME_PAD_SMALL); - misc_box = gtk_vbox_new (FALSE, GNOME_PAD); - - gtk_container_set_border_width (GTK_CONTAINER (misc_frame), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (misc_frame), misc_box); - - gtk_box_pack_start (GTK_BOX (main_box), misc_frame, FALSE, FALSE, 0); - - enable_display_beep = gtk_check_button_new_with_label (_("Beep on display alarms")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_display_beep), - beep_on_display); - gtk_box_pack_start (GTK_BOX (misc_box), enable_display_beep, FALSE, FALSE, 0); - gtk_signal_connect (GTK_OBJECT (enable_display_beep), "toggled", - (GtkSignalFunc) prop_changed, - NULL); - - /* audio timeout widgets */ - box = gtk_hbox_new (FALSE, GNOME_PAD); - to_cb = gtk_check_button_new_with_label (_("Audio alarms timeout after")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (to_cb), - enable_aalarm_timeout); - gtk_signal_connect (GTK_OBJECT (to_cb), "toggled", - (GtkSignalFunc) to_cb_changed, NULL); - gtk_box_pack_start (GTK_BOX (box), to_cb, FALSE, FALSE, 0); - to_spin = make_spin_button (audio_alarm_timeout, 1, MAX_AALARM_TIMEOUT); - gtk_widget_set_sensitive (to_spin, enable_aalarm_timeout); - gtk_signal_connect (GTK_OBJECT (to_spin), "changed", - (GtkSignalFunc) prop_changed, NULL); - gtk_box_pack_start (GTK_BOX (box), to_spin, FALSE, FALSE, 0); - l = gtk_label_new (_(" seconds")); - gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (misc_box), box, FALSE, FALSE, 0); - - /* snooze widgets */ - box = gtk_hbox_new (FALSE, GNOME_PAD); - snooze_cb = gtk_check_button_new_with_label (_("Enable snoozing for ")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (snooze_cb), - enable_snooze); - gtk_signal_connect (GTK_OBJECT (snooze_cb), "toggled", - (GtkSignalFunc) snooze_cb_changed, NULL); - gtk_box_pack_start (GTK_BOX (box), snooze_cb, FALSE, FALSE, 0); - snooze_spin = make_spin_button (snooze_secs, 1, MAX_SNOOZE_SECS); - gtk_widget_set_sensitive (snooze_spin, enable_snooze); - gtk_signal_connect (GTK_OBJECT (snooze_spin), "changed", - (GtkSignalFunc) prop_changed, NULL); - gtk_box_pack_start (GTK_BOX (box), snooze_spin, FALSE, FALSE, 0); - l = gtk_label_new (_(" seconds")); - gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (misc_box), box, FALSE, FALSE, 0); - - /* populate default frame/box */ - default_frame = gtk_frame_new (_("Defaults")); - gtk_container_set_border_width (GTK_CONTAINER (default_frame), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (main_box), default_frame, FALSE, FALSE, 0); - default_table = gtk_table_new (1, 1, 0); - gtk_container_set_border_width (GTK_CONTAINER (default_table), 4); - gtk_table_set_row_spacings (GTK_TABLE (default_table), 4); - gtk_table_set_col_spacings (GTK_TABLE (default_table), 4); - gtk_container_add (GTK_CONTAINER (default_frame), default_table); - - ee_create_ae (GTK_TABLE (default_table), _("Display"), - &alarm_defaults [ALARM_DISPLAY], ALARM_DISPLAY, 1, - FALSE, prop_changed); - ee_create_ae (GTK_TABLE (default_table), _("Audio"), - &alarm_defaults [ALARM_AUDIO], ALARM_AUDIO, 2, - FALSE, prop_changed); - ee_create_ae (GTK_TABLE (default_table), _("Program"), - &alarm_defaults [ALARM_PROGRAM], ALARM_PROGRAM, 3, - FALSE, prop_changed); - ee_create_ae (GTK_TABLE (default_table), _("Mail"), - &alarm_defaults [ALARM_MAIL], ALARM_MAIL, 4, - FALSE, prop_changed); -} - -static void -prop_store_alarm_default_values (CalendarAlarm* alarm) -{ - ee_store_alarm (alarm, alarm->type); - - switch (alarm->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; - } - - gnome_config_set_int ("enabled", alarm->enabled); - gnome_config_set_int ("count", alarm->count); - gnome_config_set_int ("units", alarm->units); - if (alarm->data) - gnome_config_set_string ("data", alarm->data); - - gnome_config_pop_prefix (); - gnome_config_sync (); -} - -static void -prop_apply_alarms () -{ - int i; - for (i=0; i < 4; i++) - prop_store_alarm_default_values (&alarm_defaults [i]); - - beep_on_display = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enable_display_beep)); - gnome_config_set_bool ("/calendar/alarms/beep_on_display", beep_on_display); - enable_aalarm_timeout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (to_cb)); - gnome_config_set_bool ("/calendar/alarms/enable_audio_timeout", enable_aalarm_timeout); - audio_alarm_timeout = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (to_spin)); - gnome_config_set_int ("/calendar/alarms/audio_alarm_timeout", audio_alarm_timeout); - enable_snooze = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (snooze_cb)); - gnome_config_set_bool ("/calendar/alarms/enable_snooze", enable_snooze); - snooze_secs = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (snooze_spin)); - gnome_config_set_int ("/calendar/alarms/snooze_secs", snooze_secs); - - gnome_config_sync(); -} - -static void -to_cb_changed (GtkWidget *object, gpointer data) -{ - gboolean active = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (to_cb)); - gtk_widget_set_sensitive (to_spin, active); - prop_changed (); -} - -static void -snooze_cb_changed (GtkWidget *object, gpointer data) -{ - gboolean active = - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (snooze_cb)); - gtk_widget_set_sensitive (snooze_spin, active); - prop_changed (); -} - - diff --git a/calendar/quick-view.c b/calendar/quick-view.c deleted file mode 100644 index 42da747259..0000000000 --- a/calendar/quick-view.c +++ /dev/null @@ -1,274 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#include <config.h> -#include "quick-view.h" -#include "main.h" - - -#define QUICK_VIEW_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*" - - -static void quick_view_class_init (QuickViewClass *class); -static void quick_view_init (QuickView *qv); - -static gint quick_view_button_release (GtkWidget *widget, GdkEventButton *event); -static gint quick_view_map_event (GtkWidget *widget, GdkEventAny *event); - - -static GtkWindowClass *parent_class; - - -GtkType -quick_view_get_type (void) -{ - static GtkType quick_view_type = 0; - - if (!quick_view_type) { - GtkTypeInfo quick_view_info = { - "QuickView", - sizeof (QuickView), - sizeof (QuickViewClass), - (GtkClassInitFunc) quick_view_class_init, - (GtkObjectInitFunc) quick_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - quick_view_type = gtk_type_unique (gtk_window_get_type (), &quick_view_info); - } - - return quick_view_type; -} - -static void -quick_view_class_init (QuickViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gtk_window_get_type ()); - - widget_class->button_release_event = quick_view_button_release; - widget_class->map_event = quick_view_map_event; -} - -static void -quick_view_init (QuickView *qv) -{ - GTK_WINDOW (qv)->type = GTK_WINDOW_POPUP; - gtk_window_set_position (GTK_WINDOW (qv), GTK_WIN_POS_MOUSE); -} - -static gint -quick_view_button_release (GtkWidget *widget, GdkEventButton *event) -{ - QuickView *qv; - - qv = QUICK_VIEW (widget); - - if (event->button != qv->button) - return FALSE; - - gdk_pointer_ungrab (event->time); - gtk_grab_remove (GTK_WIDGET (qv)); - gtk_widget_hide (GTK_WIDGET (qv)); - - gtk_main_quit (); /* End modality of the quick view */ - return TRUE; -} - -static gint -quick_view_map_event (GtkWidget *widget, GdkEventAny *event) -{ - GdkCursor *cursor; - - cursor = gdk_cursor_new (GDK_ARROW); - gdk_pointer_grab (widget->window, - TRUE, - GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, - GDK_CURRENT_TIME); - gdk_cursor_destroy (cursor); - - return FALSE; -} - -/* Creates the items corresponding to a single calendar object. Takes in the y position of the - * items to create and returns the y position of the next item to create. Also takes in the current - * maximum width for items and returns the new maximum width. - */ -static void -create_items_for_event (QuickView *qv, CalendarObject *co, double *y, double *max_width) -{ - GnomeCanvas *canvas; - GnomeCanvasItem *item; - char start[100], end[100]; - struct tm start_tm, end_tm; - char *str; - GtkArg args[2]; - - /* FIXME: make this nice */ - - canvas = GNOME_CANVAS (qv->canvas); - - start_tm = *localtime (&co->ev_start); - end_tm = *localtime (&co->ev_end); - - if (am_pm_flag) { - strftime (start, sizeof (start), "%I:%M%p", &start_tm); - strftime (end, sizeof (end), "%I:%M%p", &end_tm); - } else { - strftime (start, sizeof (start), "%H:%M", &start_tm); - strftime (end, sizeof (end), "%H:%M", &end_tm); - } - - str = g_strconcat (start, " - ", end, " ", co->ico->summary, NULL); - - item = gnome_canvas_item_new (gnome_canvas_root (canvas), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", *y, - "anchor", GTK_ANCHOR_NW, - "text", str, - "fontset", QUICK_VIEW_FONTSET, - NULL); - - g_free (str); - - /* Measure the text and return the proper size values */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - if (GTK_VALUE_DOUBLE (args[0]) > *max_width) - *max_width = GTK_VALUE_DOUBLE (args[0]); - - *y += GTK_VALUE_DOUBLE (args[1]); -} - -/* Creates the canvas items corresponding to the events in the list */ -static void -setup_event_list (QuickView *qv, GList *event_list) -{ - CalendarObject *co; - GnomeCanvasItem *item; - GtkArg args[2]; - double y, max_width; - - /* If there are no events, then just put a simple label */ - - if (!event_list) { - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (qv->canvas)), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", 0.0, - "anchor", GTK_ANCHOR_NW, - "text", _("No appointments for this day"), - "fontset", QUICK_VIEW_FONTSET, - NULL); - - /* Measure the text and set the proper sizes */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - y = GTK_VALUE_DOUBLE (args[1]); - max_width = GTK_VALUE_DOUBLE (args[0]); - } else { - /* Create the items for all the events in the list */ - - y = 0.0; - max_width = 0.0; - - for (; event_list; event_list = event_list->next) { - co = event_list->data; - create_items_for_event (qv, co, &y, &max_width); - } - } - - /* Set the scrolling region to fit all the items */ - - gnome_canvas_set_scroll_region (GNOME_CANVAS (qv->canvas), - 0.0, 0.0, - max_width, y); - - gtk_widget_set_usize (qv->canvas, max_width, y); -} - -GtkWidget * -quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list) -{ - QuickView *qv; - GtkWidget *vbox; - GtkWidget *w; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - qv = gtk_type_new (quick_view_get_type ()); - qv->calendar = calendar; - - /* Create base widgets for the popup window */ - - w = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_ETCHED_OUT); - gtk_container_add (GTK_CONTAINER (qv), w); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (w), vbox); - - w = gtk_label_new (title); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_set_border_width (GTK_CONTAINER (w), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0); - - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - - qv->canvas = gnome_canvas_new (); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - gtk_container_add (GTK_CONTAINER (w), qv->canvas); - - /* Set up the event list */ - - setup_event_list (qv, event_list); - - return GTK_WIDGET (qv); -} - -void -quick_view_do_popup (QuickView *qv, GdkEventButton *event) -{ - g_return_if_fail (qv != NULL); - g_return_if_fail (IS_QUICK_VIEW (qv)); - g_return_if_fail (event != NULL); - - /* Pop up the window */ - - gtk_widget_show_all (GTK_WIDGET (qv)); - gtk_grab_add (GTK_WIDGET (qv)); - - qv->button = event->button; - - gtk_main (); /* Begin modality */ - - /* The button release event handler will call gtk_main_quit() */ -} diff --git a/calendar/quick-view.h b/calendar/quick-view.h deleted file mode 100644 index c6b2cf8814..0000000000 --- a/calendar/quick-view.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#ifndef QUICK_VIEW_H -#define QUICK_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_QUICK_VIEW (quick_view_get_type ()) -#define QUICK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_QUICK_VIEW, QuickView)) -#define QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_QUICK_VIEW, QuickViewClass)) -#define IS_QUICK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_QUICK_VIEW)) -#define IS_QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_QUICK_VIEW)) - - -typedef struct _QuickView QuickView; -typedef struct _QuickViewClass QuickViewClass; - -struct _QuickView { - GtkWindow window; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - GtkWidget *canvas; /* The canvas that displays the contents of the quick view */ - - int button; /* The button that was pressed to pop up the quick view */ -}; - -struct _QuickViewClass { - GtkWindowClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType quick_view_get_type (void); - -/* Creates a new quick view with the specified title and the specified event list. It is associated - * to the specified calendar. The event list must be a list of CalendarObject structures. - */ -GtkWidget *quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list); - -/* Pops up the quick view widget modally and loops until the uses closes it by releasing the mouse - * button. You can destroy the quick view when this function returns. - */ -void quick_view_do_popup (QuickView *qv, GdkEventButton *event); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/recur.xpm b/calendar/recur.xpm deleted file mode 100644 index 49836b62e7..0000000000 --- a/calendar/recur.xpm +++ /dev/null @@ -1,83 +0,0 @@ -/* XPM */ -static char * recur_xpm[] = { -"16 16 64 1", -" c None", -". c #350000", -"+ c #2A0000", -"@ c #1B0000", -"# c #280000", -"$ c #430000", -"% c #090000", -"& c #160000", -"* c #250000", -"= c #460000", -"- c #550000", -"; c #610000", -"> c #0D0000", -", c #1F0000", -"' c #4B0000", -") c #5E0000", -"! c #6B0000", -"~ c #750000", -"{ c #790000", -"] c #810000", -"^ c #FFFF83", -"/ c #FFFF89", -"( c #FFFF93", -"_ c #8B0000", -": c #900000", -"< c #930000", -"[ c #FFFF62", -"} c #A10000", -"| c #FFFF41", -"1 c #FFFF3B", -"2 c #FFFF31", -"3 c #B70000", -"4 c #B20000", -"5 c #AE0000", -"6 c #FFFF22", -"7 c #FFFF16", -"8 c #FFFF06", -"9 c #C90000", -"0 c #C10000", -"a c #BB0000", -"b c #FFF600", -"c c #FFE100", -"d c #FFC500", -"e c #E40000", -"f c #D70000", -"g c #CD0000", -"h c #FFDB00", -"i c #FFA900", -"j c #FF8500", -"k c #FF5900", -"l c #FF2800", -"m c #FC0000", -"n c #ED0000", -"o c #E10000", -"p c #FFAF00", -"q c #FF9400", -"r c #FF7400", -"s c #FF5000", -"t c #FF0100", -"u c #F30000", -"v c #E80000", -"w c #FF6900", -"x c #FF4900", -"y c #FF0800", -" ", -" . ", -" +. ", -" @#.$ ", -" %&*.=-; ", -" >,.')!~ ", -" &. !{] ", -" ^/( . _:< ", -" [[[ }}} ", -" |12 345 ", -" 678 90a ", -" bcd efg ", -" hdijklmnof ", -" pqrsltuv ", -" wxly ", -" "}; diff --git a/calendar/test.vcf b/calendar/test.vcf deleted file mode 100644 index bfe93b3c14..0000000000 --- a/calendar/test.vcf +++ /dev/null @@ -1,133 +0,0 @@ -BEGIN:VCALENDAR -PRODID:-//GNOME//NONSGML GnomeCalendar//EN -TZ:MST -VERSION:0.13 -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980601T150000 -DTEND:19980601T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Cada dos dias de 06/01 al 07/01 -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D2 19980701T140000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T140000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:5 dias. -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980429T004635 -SUMMARY:Diariamente de 05/01 al 06/01 -STATUS:NEEDS ACTION -CLASS:PRIVATE -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 19980601T000000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VTODO -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980415T140000 -DUE:19691231T180000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Normal -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T120000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semanal -- 4 semanas -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 WE #4 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T003000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semana: Mi, Ju, Vi, Dom (10 veces) -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 SU WE TH FR #10 -END:VTODO - -END:VCALENDAR - diff --git a/calendar/test2.vcf b/calendar/test2.vcf deleted file mode 100644 index 6446507989..0000000000 --- a/calendar/test2.vcf +++ /dev/null @@ -1,133 +0,0 @@ -BEGIN:VCALENDAR -PRODID:-//GNOME//NONSGML GnomeCalendar//EN -TZ:MST -VERSION:0.13 -BEGIN:VEVENT -UID:KOrganizer - 8469308861 -SEQUENCE:1 -DTSTART:19980601T150000 -DTEND:19980601T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Cada dos dias de 06/01 al 07/01 -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D2 19980701T140000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 8469308862 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T140000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:5 dias. -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 8469308863 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980429T004635 -SUMMARY:Diariamente de 05/01 al 06/01 -STATUS:NEEDS ACTION -CLASS:PRIVATE -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 19980601T000000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 18042893834 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 18042893835 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VTODO -UID:KOrganizer - 8469308866 -SEQUENCE:1 -DTSTART:19980415T140000 -DUE:19691231T180000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Normal -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 18042893837 -SEQUENCE:1 -DTSTART:19980415T120000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semanal -- 4 semanas -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 WE #4 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 18042893838 -SEQUENCE:1 -DTSTART:19980415T003000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semana: Mi, Ju, Vi, Dom (10 veces) -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 SU WE TH FR #10 -END:VTODO - -END:VCALENDAR - diff --git a/calendar/todo-conduit-control-applet.c b/calendar/todo-conduit-control-applet.c deleted file mode 100644 index 54a26715ef..0000000000 --- a/calendar/todo-conduit-control-applet.c +++ /dev/null @@ -1,287 +0,0 @@ -/* Control applet ("capplet") for the gnome-pilot todo conduit, */ -/* based on */ -/* gpilotd control applet ('capplet') for use with the GNOME control center */ -/* $Id$ */ - -#include <pwd.h> -#include <sys/types.h> -#include <signal.h> -#include <gnome.h> - -#include <config.h> -#include <capplet-widget.h> - -#include <gpilotd/gpilotd-conduit-mgmt.h> -#include <gpilotd/gpilotd-app.h> -#include <gpilotd/gpilotd-app-dummy-callbacks.h> - -#include "todo-conduit.h" - -/* tell changes callbacks to ignore changes or not */ -static gboolean ignore_changes=FALSE; - -/* capplet widget */ -static GtkWidget *capplet=NULL; - -/* host/device/pilot configuration windows */ -GtkWidget *cfgOptionsWindow=NULL; -GtkWidget *cfgStateWindow=NULL; -GtkWidget *dialogWindow=NULL; - -gboolean activated,org_activation_state; -GnomePilotConduitMgmt *conduit; - -static void doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); - -static void readStateCfg(GtkWidget *w); -static void setStateCfg(GtkWidget *w); - -gint pilotId; -CORBA_Environment ev; - -static void -doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) -{ - readStateCfg(cfgStateWindow); - if(activated) - gpilotd_conduit_mgmt_enable(conduit,pilotId,GnomePilotConduitSyncTypeSynchronize); - else - gpilotd_conduit_mgmt_disable(conduit,pilotId); -} - -static void -doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg) -{ - doTrySettings(widget, conduitCfg); - save_configuration(NULL); -} - - -static void -doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg) -{ - activated = org_activation_state; - setStateCfg(cfgStateWindow); -} - -static void -insert_dir_callback (GtkEditable *editable, const gchar *text, - gint len, gint *position, void *data) -{ - gint i; - gchar *curname; - - curname = gtk_entry_get_text(GTK_ENTRY(editable)); - if (*curname == '\0' && len > 0) { - if (isspace(text[0])) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text"); - return; - } - } else { - for (i=0; i<len; i++) { - if (isspace(text[i])) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), - "insert_text"); - return; - } - } - } -} -static void -insert_dir_callback2(GtkEditable *editable, const gchar *text, - gint length, gint *position, - void *data) -{ - if (!ignore_changes) - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -static void -clist_changed(GtkWidget *widget, gpointer data) -{ - if (!ignore_changes) - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -void about_cb (GtkWidget *widget, gpointer data) { - GtkWidget *about; - const gchar *authors[] = {_("Eskil Heyn Olsen <deity@eskil.dk>"),NULL}; - - about = gnome_about_new(_("Gpilotd todo conduit"), VERSION, - _("(C) 1998 the Free Software Foundation"), - authors, - _("Configuration utility for the todo conduit.\n"), - _("gnome-unknown.xpm")); - gtk_widget_show (about); - - return; -} - -static void toggled_cb(GtkWidget *widget, gpointer data) { - gtk_widget_set_sensitive(cfgOptionsWindow,GTK_TOGGLE_BUTTON(widget)->active); - capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE); -} - -static GtkWidget -*createStateCfgWindow(void) -{ - GtkWidget *vbox, *table; - GtkWidget *entry, *label; - GtkWidget *button; - - vbox = gtk_vbox_new(FALSE, GNOME_PAD); - - table = gtk_table_new(2, 2, FALSE); - gtk_table_set_row_spacings(GTK_TABLE(table), 4); - gtk_table_set_col_spacings(GTK_TABLE(table), 10); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, GNOME_PAD); - - label = gtk_label_new(_("Enabled")); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1,2); - - button = gtk_check_button_new(); - gtk_object_set_data(GTK_OBJECT(vbox), "conduit_on_off", button); - gtk_signal_connect(GTK_OBJECT(button), "toggled", - GTK_SIGNAL_FUNC(toggled_cb), - NULL); - gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 1,2); - - return vbox; -} - -static void -setStateCfg(GtkWidget *cfg) -{ - GtkWidget *button; - gchar num[40]; - - button = gtk_object_get_data(GTK_OBJECT(cfg), "conduit_on_off"); - - g_assert(button!=NULL); - - ignore_changes = TRUE; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),activated); - gtk_widget_set_sensitive(cfgOptionsWindow,GTK_TOGGLE_BUTTON(button)->active); - ignore_changes = FALSE; -} - - -static void -readStateCfg(GtkWidget *cfg) -{ - GtkWidget *button; - - button = gtk_object_get_data(GTK_OBJECT(cfg), "conduit_on_off"); - - g_assert(button!=NULL); - - activated = GTK_TOGGLE_BUTTON(button)->active; -} - -static void -pilot_capplet_setup(void) -{ - GtkWidget *frame, *table; - - capplet = capplet_widget_new(); - - table = gtk_table_new(1, 2, FALSE); - gtk_container_border_width(GTK_CONTAINER(table), GNOME_PAD); - gtk_container_add(GTK_CONTAINER(capplet), table); - - frame = gtk_frame_new(_("Conduit state")); - gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL); - gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 0, 1); - cfgStateWindow = createStateCfgWindow(); - gtk_container_add(GTK_CONTAINER(frame), cfgStateWindow); - - gtk_signal_connect(GTK_OBJECT(capplet), "try", - GTK_SIGNAL_FUNC(doTrySettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "revert", - GTK_SIGNAL_FUNC(doRevertSettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "ok", - GTK_SIGNAL_FUNC(doSaveSettings), NULL); - gtk_signal_connect(GTK_OBJECT(capplet), "help", - GTK_SIGNAL_FUNC(about_cb), NULL); - - - setStateCfg(cfgStateWindow); - - gtk_widget_show_all(capplet); -} - -void run_error_dialog(gchar *mesg,...) { - char tmp[80]; - va_list ap; - - va_start(ap,mesg); - vsnprintf(tmp,79,mesg,ap); - dialogWindow = gnome_message_box_new(mesg,GNOME_MESSAGE_BOX_ERROR,GNOME_STOCK_BUTTON_OK,NULL); - gnome_dialog_run_and_close(GNOME_DIALOG(dialogWindow)); - va_end(ap); -} - -gint get_pilot_id_from_gpilotd() { - gint *pilots; - int i; - - i=0; - gpilotd_get_pilot_ids(&pilots); - if(pilots) { - while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return -1; - } else { - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return -1; - } -} - -int -main( int argc, char *argv[] ) -{ - /* we're a capplet */ - gnome_capplet_init ("todo conduit control applet", NULL, argc, argv, - NULL, - 0, NULL); - - /* put all code to set things up in here */ - conduit = gpilotd_conduit_mgmt_new("todo_conduit"); - - /* get pilot name from gpilotd */ - /* 1. initialize the gpilotd connection */ - if (gpilotd_init(&argc,argv)!=0) { - run_error_dialog(_("Cannot initialze the GnomePilot Daemon")); - g_error(_("Cannot initialze the GnomePilot Daemon")); - return -1; - } - - /* 2 connect to gpilotd */ - if (gpilotd_connect()!=0) { - run_error_dialog(_("Cannot connect to the GnomePilot Daemon")); - g_error(_("Cannot connect to the GnomePilot Daemon")); - return -1; - } - - pilotId = get_pilot_id_from_gpilotd(); - if(!pilotId) return -1; - org_activation_state = activated = gpilotd_conduit_mgmt_is_enabled(conduit,pilotId); - - pilot_capplet_setup(); - - - /* done setting up, now run main loop */ - capplet_gtk_main(); - return 0; -} diff --git a/calendar/todo-conduit-control-applet.desktop b/calendar/todo-conduit-control-applet.desktop deleted file mode 100644 index 87788bde08..0000000000 --- a/calendar/todo-conduit-control-applet.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Name=Todo conduit -Comment=Configure the todo conduit -Exec=todo-conduit-control-applet --cap-id=1 -Terminal=0 -Type=Application diff --git a/calendar/todo-conduit.c b/calendar/todo-conduit.c deleted file mode 100644 index 3a543816af..0000000000 --- a/calendar/todo-conduit.c +++ /dev/null @@ -1,256 +0,0 @@ -/* $Id$ */ - -#include <glib.h> -#include <gnome.h> - -#include <pi-source.h> -#include <pi-socket.h> -#include <pi-file.h> -#include <pi-dlp.h> -#include <pi-version.h> - -#include <sys/stat.h> -#include <sys/types.h> -#include <utime.h> -#include <unistd.h> -#include <pwd.h> -#include <signal.h> -#include <errno.h> -#include <gpilotd/gnome-pilot-conduit.h> -#include <gpilotd/gnome-pilot-conduit-standard-abs.h> - -#include "todo-conduit.h" - -static gint -load_records(GnomePilotConduit *c) -{ - return 0; -} - -static gint -pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) { - int l; - unsigned char *buf; - - gtk_object_set_data(GTK_OBJECT(c),"dbinfo",dbi); - - load_records(c); - - buf = (unsigned char*)g_malloc(0xffff); - if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) { - return -1; - } - unpack_ToDoAppInfo(&(GET_DATA(c)->ai),buf,l); - g_free(buf); - - return 0; -} - -static gint -post_sync(GnomePilotConduit *c) { - return 0; -} - -static gint -match_record (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord **local, - PilotRecord *remote, - gpointer data) -{ - g_print ("in match_record\n"); - return 0; -} -static gint -free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord **local, - gpointer data) -{ - g_print ("entering free_match\n"); - *local = NULL; - - return 0; -} -static gint -archive_local (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - gpointer data) -{ - g_print ("entering archive_local\n"); - return 1; - -} -static gint -archive_remote (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - PilotRecord *remote, - gpointer data) -{ - g_print ("entering archive_remote\n"); - return 1; -} -static gint -store_remote (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - PilotRecord *remote, - gpointer data) -{ - g_print ("entering store_remote\n"); - g_print ("Rec:%s:\nLength:%d\n", remote->record, remote->length); - return 1; -} -static gint -clear_status_archive_local (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - gpointer data) -{ - g_print ("entering clear_status_archive_local\n"); - return 1; -} -static gint -iterate (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord **local, - gpointer data) -{ - g_print ("entering iterate\n"); - return 1; -} -static gint -iterate_specific (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord **local, - gint flag, - gint archived, - gpointer data) -{ - g_print ("entering iterate_specific\n"); - return 1; -} -static gint -purge (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - gpointer data) -{ - g_print ("entering purge\n"); - return 1; -} -static gint -set_status (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - gint status, - gpointer data) -{ - g_print ("entering set_status\n"); - return 1; -} -static gint -set_archived (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - gint archived, - gpointer data) -{ - g_print ("entering set_archived\n"); - return 1; -} -static gint -set_pilot_id (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - guint32 ID, - gpointer data) -{ - g_print ("entering set_pilot_id\n"); - return 1; -} -static gint -compare (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - PilotRecord *remote, - gpointer data) -{ - g_print ("entering compare\n"); - return 1; -} -static gint -compare_backup (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - PilotRecord *remote, - gpointer data) -{ - g_print ("entering compare_backup\n"); - return 1; -} -static gint -free_transmit (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - PilotRecord *remote, - gpointer data) -{ - g_print ("entering free_transmit\n"); - return 1; -} -static gint -delete_all (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - gpointer data) -{ - g_print ("entering delete_all\n"); - return 1; -} -static PilotRecord * -transmit (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs, - LocalRecord *local, - gpointer data) -{ - g_print ("entering transmit\n"); - return NULL; -} - -static GnomePilotConduit * -conduit_get_gpilot_conduit (guint32 pilotId) -{ - GtkObject *retval; - ConduitCfg *cfg; - ConduitData *cdata; - - g_print ("creating our new conduit\n"); - retval = gnome_pilot_conduit_standard_abs_new ("TodoDB", 0x0); - g_assert (retval != NULL); - gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"todo"); - - cfg = g_new0(ConduitCfg,1); - g_assert(cfg != NULL); - gtk_object_set_data(retval,"conduit_cfg",cfg); - - cdata = g_new0(ConduitData,1); - g_assert(cdata != NULL); - gtk_object_set_data(retval,"conduit_data",cdata); - - gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, NULL); - gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, NULL); - gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, NULL); - gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, NULL); - gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, NULL); - gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, NULL); - gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, NULL); - gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, NULL); - gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, NULL); - gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, NULL); - gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, NULL); - gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, NULL); - gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, NULL); - gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, NULL); - gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, NULL); - gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, NULL); - gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, NULL); - gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, NULL); - gtk_signal_connect (retval, "post_sync", (GtkSignalFunc) post_sync, NULL); - - load_configuration(&cfg,pilotId); - - return GNOME_PILOT_CONDUIT (retval); -} -static void -conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) -{ - ConduitCfg *cc; - cc = GET_CONFIG(conduit); - destroy_configuration(&cc); - gtk_object_destroy (GTK_OBJECT (conduit)); -} - - diff --git a/calendar/todo-conduit.h b/calendar/todo-conduit.h deleted file mode 100644 index c224b2b1f3..0000000000 --- a/calendar/todo-conduit.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $Id$ */ - -#ifndef __TODO_CONDUIT_H__ -#define __TODO_CONDUIT_H__ - -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <pi-todo.h> -#include <gnome.h> - -typedef struct _ConduitCfg ConduitCfg; - -struct _ConduitCfg { - gboolean open_secret; - guint32 pilotId; -}; - -#define GET_CONFIG(c) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"conduit_cfg")) - -typedef struct _ConduitData ConduitData; - -struct _ConduitData { - struct ToDoAppInfo ai; -}; - -#define GET_DATA(c) ((ConduitData*)gtk_object_get_data(GTK_OBJECT(c),"conduit_data")) - -static void load_configuration(ConduitCfg **c,guint32 pilotId) { - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/todod-conduit/Pilot_%u/",pilotId); - - *c = g_new0(ConduitCfg,1); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open secret=FALSE"); - gnome_config_pop_prefix(); - - (*c)->pilotId = pilotId; -} - -static void save_configuration(ConduitCfg *c) { - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/todo-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool("open secret",c->open_secret); - gnome_config_pop_prefix(); - - gnome_config_sync(); - gnome_config_drop_all(); -} - -static void destroy_configuration(ConduitCfg **c) { - g_free(*c); - *c = NULL; -} - -#endif __TODO_CONDUIT_H__ diff --git a/calendar/topic.dat b/calendar/topic.dat deleted file mode 100644 index edc7813b26..0000000000 --- a/calendar/topic.dat +++ /dev/null @@ -1,2 +0,0 @@ -gnome-cal.html Manual -gnome-cal.html#cmdline Command line options
\ No newline at end of file diff --git a/calendar/view-utils.c b/calendar/view-utils.c deleted file mode 100644 index 8cb7893377..0000000000 --- a/calendar/view-utils.c +++ /dev/null @@ -1,201 +0,0 @@ -/* Miscellaneous utility functions for the calendar view widgets - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <string.h> -#include "view-utils.h" -#include <libgnomeui/gnome-icon-text.h> - -int am_pm_flag = 0; - -static char * -nicetime (struct tm *tm) -{ - static char buf [20]; - char *p = buf; - - if (am_pm_flag){ - if (tm->tm_min) - strftime (buf, sizeof (buf), "%l:%M%p", tm); - else - strftime (buf, sizeof (buf), "%l%p", tm); - } else { - if (tm->tm_min) - strftime (buf, sizeof (buf), "%H:%M", tm); - else - strftime (buf, sizeof (buf), "%H", tm); - } - while (*p == ' ') - p++; - return p; -} - -typedef struct { - GnomeIconTextInfo *layout; - int lines; - int assigned_lines; -} line_info_t; - -void -view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, - int flags, GList *events, time_t start, time_t end) -{ - GdkFont *font = widget->style->font; - int font_height; - int y, max_y, items, i, need_more, nlines, base, extra; - GList *list; - line_info_t *lines; - - if (events == NULL) - return; - - items = g_list_length (events); - lines = g_new0 (line_info_t, items); - - font_height = font->ascent + font->descent; - max_y = area->y + area->height - font_height * ((flags & VIEW_UTILS_DRAW_SPLIT) ? 2 : 1); - - /* - * Layout all the lines, measure the space needs - */ - for (i = 0, list = events; list; list = list->next, i++){ - CalendarObject *co = list->data; - struct tm tm_start, tm_end; - iCalObject *ico = co->ico; - char buf [60]; - char *full_text; - - tm_start = *localtime (&co->ev_start); - tm_end = *localtime (&co->ev_end); - - strcpy (buf, nicetime (&tm_start)); - - if (flags & VIEW_UTILS_DRAW_END){ - strcat (buf, "-"); - strcat (buf, nicetime (&tm_end)); - } - - full_text = g_strconcat (buf, ": ", ico->summary, NULL); - lines [i].layout = gnome_icon_layout_text ( - font, full_text, "\n -,.;:=#", area->width, TRUE); - lines [i].lines = g_list_length (lines [i].layout->rows); - - g_free (full_text); - } - - /* - * Compute how many lines we will give to each row - */ - nlines = 1 + max_y / font_height; - base = nlines / items; - extra = nlines % items; - need_more = 0; - - for (i = 0; i < items; i++){ - if (lines [i].lines <= base){ - extra += base - lines [i].lines; - lines [i].assigned_lines = lines [i].lines; - } else { - need_more++; - lines [i].assigned_lines = base; - } - } - - /* - * use any extra space - */ - while (need_more && extra > 0){ - need_more = 0; - - for (i = 0; i < items; i++){ - if (lines [i].lines > lines [i].assigned_lines){ - lines [i].assigned_lines++; - extra--; - } - - if (extra == 0) - break; - - if (lines [i].lines > lines [i].assigned_lines) - need_more = 1; - } - } - - /* - * Draw the information - */ - gdk_gc_set_clip_rectangle (gc, area); - y = area->y; - for (i = 0; i < items; i++){ - int line; - - list = lines [i].layout->rows; - - for (line = 0; line < lines [i].assigned_lines; line++){ - GnomeIconTextInfoRow *row = list->data; - - list = list->next; - - if (row) - gdk_draw_string ( - window, font, gc, - area->x, y + font->ascent, - row->text); - y += font_height; - } - } - - gdk_gc_set_clip_rectangle (gc, NULL); - - /* - * Free resources. - */ - - for (i = 0; i < items; i++) - gnome_icon_text_info_free (lines [i].layout); - g_free (lines); -} - -void -view_utils_draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow) -{ - int x, y; - int xthick, ythick; - GdkGC *light_gc, *dark_gc; - - gdk_draw_rectangle (window, - widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - rect->x, rect->y, - rect->width, rect->height); - - light_gc = widget->style->light_gc[GTK_STATE_NORMAL]; - dark_gc = widget->style->dark_gc[GTK_STATE_NORMAL]; - - xthick = widget->style->klass->xthickness; - ythick = widget->style->klass->ythickness; - - gdk_gc_set_clip_rectangle (light_gc, rect); - gdk_gc_set_clip_rectangle (dark_gc, rect); - - for (y = rect->y + ythick; y < (rect->y + rect->height - ythick); y += 3) - for (x = rect->x + xthick; x < (rect->x + rect->width - xthick); x += 6) { - gdk_draw_point (window, light_gc, x, y); - gdk_draw_point (window, dark_gc, x + 1, y + 1); - - gdk_draw_point (window, light_gc, x + 3, y + 1); - gdk_draw_point (window, dark_gc, x + 4, y + 2); - } - - gdk_gc_set_clip_rectangle (light_gc, NULL); - gdk_gc_set_clip_rectangle (dark_gc, NULL); - - gtk_draw_shadow (widget->style, window, - GTK_STATE_NORMAL, shadow, - rect->x, rect->y, - rect->width, rect->height); -} diff --git a/calendar/view-utils.h b/calendar/view-utils.h deleted file mode 100644 index a1876b6032..0000000000 --- a/calendar/view-utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Miscellaneous utility functions for the calendar view widgets - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef VIEW_UTILS_H -#define VIEW_UTILS_H - - -#include <gtk/gtk.h> -#include "calendar.h" - - -enum { - VIEW_UTILS_DRAW_END = 1 << 0, - VIEW_UTILS_DRAW_SPLIT = 1 << 1 -}; - - -void view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, - int flags, GList *events, time_t start, time_t end); - -void view_utils_draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow); - - -#endif diff --git a/calendar/week-view.c b/calendar/week-view.c deleted file mode 100644 index 89e489a92d..0000000000 --- a/calendar/week-view.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Week view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include "year-view.h" - - -static void week_view_class_init (WeekViewClass *class); -static void week_view_init (WeekView *wv); - - -GtkType -week_view_get_type (void) -{ - static GtkType week_view_type = 0; - - if (!week_view_type) { - GtkTypeInfo week_view_info = { - "WeekView", - sizeof (WeekView), - sizeof (WeekViewClass), - (GtkClassInitFunc) week_view_class_init, - (GtkObjectInitFunc) week_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - week_view_type = gtk_type_unique (gnome_canvas_get_type (), &week_view_info); - } - - return week_view_type; -} - -static void -week_view_class_init (WeekViewClass *class) -{ - /* FIXME */ -} - -static void -week_view_init (WeekView *wv) -{ - GnomeCanvasGroup *root; - - root = gnome_canvas_root (GNOME_CANVAS (wv)); - - /* Title */ - - wv->title = gnome_canvas_item_new (root, - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "font", HEADING_FONT, - "fill_color", "black", - NULL); -} - -GtkWidget * -week_view_new (GnomeCalendar *calendar, time_t week) -{ - WeekView *wv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - wv = gtk_type_new (week_view_get_type ()); - wv->calendar = calendar; - - week_view_colors_changed (wv); - week_view_set (wv, week); - return GTK_WIDGET (wv); -} - -void -week_view_update (WeekView *wv, iCalObject *ico, int flags) -{ - /* FIXME */ -} - -void -week_view_set (WeekView *wv, time_t week) -{ - /* FIXME */ -} - -void -week_view_time_format_changed (WeekView *wv) -{ - /* FIXME */ -} - -void -week_view_colors_changed (WeekView *wv) -{ - /* FIXME */ -} diff --git a/calendar/week-view.h b/calendar/week-view.h deleted file mode 100644 index 1bf6a4ed02..0000000000 --- a/calendar/week-view.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Week view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef WEEK_VIEW_H -#define WEEK_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - -BEGIN_GNOME_DECLS - - -#define TYPE_WEEK_VIEW (week_view_get_type ()) -#define WEEK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_WEEK_VIEW, WeekView)) -#define WEEK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_WEEK_VIEW, WeekViewClass)) -#define IS_WEEK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_WEEK_VIEW)) -#define IS_WEEK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_WEEK_VIEW)) - - -typedef struct _WeekView WeekView; -typedef struct _WeekViewClass WeekViewClass; - -struct _WeekView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - time_t week; /* Start of the week we are viewing */ - - GnomeCanvasItem *title; /* The title of the week view */ -}; - -struct _WeekViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType week_view_get_type (void); - -/* Creates a new week view associated to the specified calendar */ -GtkWidget *week_view_new (GnomeCalendar *calendar, time_t week); - -/* Notifies the week view that a calendar object has changed */ -void week_view_update (WeekView *wv, iCalObject *ico, int flags); - -/* Notifies the week view about a change of date */ -void week_view_set (WeekView *wv, time_t week); - -/* Notifies the week view that the time format has changed */ -void week_view_time_format_changed (WeekView *wv); - -/* Notifies the week view that the colors have changed */ -void week_view_colors_changed (WeekView *wv); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/year-view.c b/calendar/year-view.c deleted file mode 100644 index 567340bde1..0000000000 --- a/calendar/year-view.c +++ /dev/null @@ -1,741 +0,0 @@ -/* Year view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gtk/gtkmain.h> -#include <gnome.h> -#include "eventedit.h" -#include "year-view.h" -#include "main.h" -#include "mark.h" -#include "quick-view.h" -#include "cal-util/timeutil.h" - - -#define HEAD_SPACING 4 /* Spacing between year heading and months */ -#define TITLE_SPACING 1 /* Spacing between title and calendar */ -#define SPACING 4 /* Spacing between months */ - - -static void year_view_class_init (YearViewClass *class); -static void year_view_init (YearView *yv); -static void year_view_destroy (GtkObject *object); -static void year_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void year_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvas *parent_class; - - -GtkType -year_view_get_type (void) -{ - static GtkType year_view_type = 0; - - if (!year_view_type) { - GtkTypeInfo year_view_info = { - "YearView", - sizeof (YearView), - sizeof (YearViewClass), - (GtkClassInitFunc) year_view_class_init, - (GtkObjectInitFunc) year_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info); - } - - return year_view_type; -} - -static void -year_view_class_init (YearViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - object_class->destroy = year_view_destroy; - - widget_class->size_request = year_view_size_request; - widget_class->size_allocate = year_view_size_allocate; -} - -/* Resizes the year view's child items. This is done in the idle loop for - * performance (we avoid resizing on every size allocation). - */ -static gint -idle_handler (gpointer data) -{ - YearView *yv; - GtkArg arg; - double head_height; - double title_height; - double width, height; - double month_width; - double month_height; - double month_yofs; - double xofs, yofs; - double x, y; - int i; - - yv = data; - - /* Compute the size we can use */ - - width = MAX (GTK_WIDGET (yv)->allocation.width, yv->min_width); - height = MAX (GTK_WIDGET (yv)->allocation.height, yv->min_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, width, height); - - width--; - height--; - - /* Get the heights of the heading and the titles */ - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg); - head_height = GTK_VALUE_DOUBLE (arg) + 2 * HEAD_SPACING; - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg); - title_height = GTK_VALUE_DOUBLE (arg); - - /* Offsets */ - - xofs = (width + SPACING) / 3.0; - yofs = (height - head_height + SPACING) / 4.0; - - /* Month item vertical offset */ - - month_yofs = title_height + TITLE_SPACING; - - /* Month item dimensions */ - - month_width = (width - 2 * SPACING) / 3.0; - month_height = (yofs - SPACING) - month_yofs; - - /* Adjust the year heading */ - - gnome_canvas_item_set (yv->heading, - "x", width / 2.0, - "y", (double) HEAD_SPACING, - NULL); - - /* Adjust titles and months */ - - for (i = 0; i < 12; i++) { - x = (i % 3) * xofs; - y = head_height + (i / 3) * yofs; - - gnome_canvas_item_set (yv->titles[i], - "x", x + month_width / 2.0, - "y", y, - NULL); - - gnome_canvas_item_set (yv->mitems[i], - "x", x, - "y", y + month_yofs, - "width", month_width, - "height", month_height, - NULL); - } - - /* Done */ - - yv->need_resize = FALSE; - return FALSE; -} - -/* Marks the year view as needing a resize, which will be performed during the idle loop */ -static void -need_resize (YearView *yv) -{ - if (yv->need_resize) - return; - - yv->need_resize = TRUE; - yv->idle_id = gtk_idle_add (idle_handler, yv); -} - -/* Callback used to destroy the year view's popup menu when the year view itself is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Create a new appointment in the highlighted day from the year view's popup menu */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (yv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (yv->calendar, view_name); - gnome_calendar_goto (yv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_month (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "monthview"); -} - -/* Information for the year view's popup menu */ -static GnomeUIInfo yv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _month"), NULL, jump_to_month, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Returns the popup menu cooresponding to the specified year view. If the menu has not been - * created yet, it creates it and attaches it to the year view. - */ -static GtkWidget * -get_popup_menu (YearView *yv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (yv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (yv_popup_menu); - gtk_object_set_data (GTK_OBJECT (yv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (yv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Executes the year view's popup menu. It may disable/enable some menu items based on the - * specified flags. A pointer to a time_t value containing the specified time data is set in the - * "time_data" object data key of the menu items. - */ -static void -do_popup_menu (YearView *yv, GdkEventButton *event, int allow_new, int allow_day, int allow_week, int allow_month, - int year, int month, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (yv); - - /* Enable/disable items as appropriate */ - - gtk_widget_set_sensitive (yv_popup_menu[0].widget, allow_new); - gtk_widget_set_sensitive (yv_popup_menu[2].widget, allow_day); - gtk_widget_set_sensitive (yv_popup_menu[3].widget, allow_week); - gtk_widget_set_sensitive (yv_popup_menu[4].widget, allow_month); - - /* Set the day item relevant to the context */ - - t = time_from_day (year, month, day); - - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, yv); -} - -/* Creates the quick view when the user clicks on a day */ -static void -do_quick_view_popup (YearView *yv, GdkEventButton *event, int year, int month, int day) -{ - time_t day_start, day_end; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_start = time_from_day (year, month, day); - day_end = time_day_end (day_start); - - list = calendar_get_events_in_range (yv->calendar->cal, day_start, day_end); - - strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_start)); - qv = quick_view_new (yv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - calendar_destroy_event_list (list); -} - -/* Event handler for days in the year's month items */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - int child_num, day; - - mitem = GNOME_MONTH_ITEM (data); - child_num = gnome_month_item_child2num (mitem, item); - day = gnome_month_item_num2day (mitem, child_num); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (day == 0) - break; - - if (event->button.button == 1) { - do_quick_view_popup (yv, (GdkEventButton *) event, mitem->year, mitem->month, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (yv, (GdkEventButton *) event, TRUE, TRUE, TRUE, TRUE, - mitem->year, mitem->month, day); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Event handler for whole month items */ -static gint -month_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - - mitem = GNOME_MONTH_ITEM (item); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button != 3) - break; - - do_popup_menu (yv, (GdkEventButton *) event, FALSE, FALSE, FALSE, TRUE, - mitem->year, mitem->month, 1); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Sets up the month item with the specified index -- connects signals for handling events, etc. */ -static void -setup_month_item (YearView *yv, int n) -{ - GnomeCanvasItem *mitem; - GnomeCanvasItem *item; - int i; - - mitem = yv->mitems[n]; - - /* Connect the day signals */ - - for (i = 0; i < 42; i++) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i); - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) day_event, - mitem); - } - - /* Connect the month signals */ - - gtk_signal_connect (GTK_OBJECT (mitem), "event", - (GtkSignalFunc) month_event, - NULL); - - /* Prepare for prelighting */ - - month_item_prepare_prelight (GNOME_MONTH_ITEM (mitem), default_color_func, NULL); -} - -/* Computes the minimum size for the year view and stores it in its internal fields */ -static void -compute_min_size (YearView *yv) -{ - GtkArg args[2]; - double m_width; - double m_height; - double max_width; - double w; - int i; - - /* Compute the minimum size of the year heading */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 2, args); - - m_width = GTK_VALUE_DOUBLE (args[0]); - m_height = 2 * HEAD_SPACING + GTK_VALUE_DOUBLE (args[1]); - - /* Add height of month titles and their spacings */ - - args[0].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &args[0]); - - m_height += 4 * (GTK_VALUE_DOUBLE (args[0]) + TITLE_SPACING); - - /* Add width of month titles */ - - max_width = 0.0; - - for (i = 0; i < 12; i++) { - args[0].name = "text_width"; - gtk_object_getv (GTK_OBJECT (yv->titles[i]), 1, &args[0]); - - w = GTK_VALUE_DOUBLE (args[0]); - if (max_width < w) - max_width = w; - } - - max_width = 3 * max_width + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add width of month items */ - - args[0].name = "width"; - args[1].name = "height"; - gtk_object_getv (GTK_OBJECT (yv->mitems[0]), 2, args); - - max_width = 3 * GTK_VALUE_DOUBLE (args[0]) + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add height of month items */ - - m_height += 4 * GTK_VALUE_DOUBLE (args[1]) + 3 * SPACING; - - /* Finally, set the minimum width and height in the year view */ - - yv->min_width = (int) (m_width + 0.5); - yv->min_height = (int) (m_height + 0.5); -} - -static void -year_view_init (YearView *yv) -{ - int i; - char buf[100]; - struct tm tm; - - memset (&tm, 0, sizeof (tm)); - - /* Heading */ - - yv->heading = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "fontset", HEADING_FONTSET, - "fill_color", "black", - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) { - /* Title */ - - strftime (buf, 100, "%B", &tm); - tm.tm_mon++; - - yv->titles[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "text", buf, - "anchor", GTK_ANCHOR_N, - "fontset", TITLE_FONTSET, - "fill_color", "black", - NULL); - - /* Month item */ - - yv->mitems[i] = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (yv))); - gnome_canvas_item_set (yv->mitems[i], - "anchor", GTK_ANCHOR_NW, - "start_on_monday", week_starts_on_monday, - "heading_fontset", DAY_HEADING_FONTSET, - "day_fontset", NORMAL_DAY_FONTSET, - NULL); - setup_month_item (yv, i); - } - - /* We will need to resize the items when we paint for the first time */ - - yv->old_marked_day = -1; - yv->idle_id = -1; - need_resize (yv); -} - -static void -year_view_destroy (GtkObject *object) -{ - YearView *yv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_YEAR_VIEW (object)); - - yv = YEAR_VIEW (object); - - if (yv->need_resize) { - yv->need_resize = FALSE; - gtk_idle_remove (yv->idle_id); - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -GtkWidget * -year_view_new (GnomeCalendar *calendar, time_t year) -{ - YearView *yv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - yv = gtk_type_new (year_view_get_type ()); - yv->calendar = calendar; - - year_view_colors_changed (yv); - year_view_set (yv, year); - compute_min_size (yv); - - return GTK_WIDGET (yv); -} - -static void -year_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - yv = YEAR_VIEW (widget); - - requisition->width = yv->min_width; - requisition->height = yv->min_height; -} - -static void -year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - yv = YEAR_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - need_resize (yv); -} - -void -year_view_update (YearView *yv, iCalObject *object, int flags) -{ - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - /* If only the summary changed, we don't care */ - - if (object && ((flags & CHANGE_SUMMARY) == flags)) - return; - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (YearView *yv) -{ - time_t t; - struct tm tm; - int month_index, day_index; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (yv->old_marked_day != -1) { - month_index = yv->old_marked_day / 42; - day_index = yv->old_marked_day % 42; - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "fontset", NORMAL_DAY_FONTSET, - NULL); - - yv->old_marked_day = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = *localtime (&t); - - if ((tm.tm_year + 1900) == yv->year) { - month_index = tm.tm_mon; - day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (yv->mitems[month_index]), tm.tm_mday); - g_assert (day_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "fontset", CURRENT_DAY_FONTSET, - NULL); - - yv->old_marked_day = month_index * 42 + day_index; - } -} - -void -year_view_set (YearView *yv, time_t year) -{ - struct tm tm; - char buf[100]; - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - tm = *localtime (&year); - yv->year = tm.tm_year + 1900; - - /* Heading */ - - sprintf (buf, "%d", yv->year); - gnome_canvas_item_set (yv->heading, - "text", buf, - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "year", yv->year, - "month", i, - NULL); - - /* Unmark and re-mark all the months */ - - for (i = 0; i < 12; i++) { - unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i])); - mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal); - } - - mark_current_day (yv); -} - -void -year_view_time_format_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "start_on_monday", week_starts_on_monday, - NULL); - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -void -year_view_colors_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) { - colorify_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), default_color_func, NULL); - mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal); - } - - mark_current_day (yv); -} diff --git a/calendar/year-view.h b/calendar/year-view.h deleted file mode 100644 index 77e63366d5..0000000000 --- a/calendar/year-view.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Year view display for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef YEAR_VIEW_H -#define YEAR_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_YEAR_VIEW (year_view_get_type ()) -#define YEAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_YEAR_VIEW, YearView)) -#define YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_YEAR_VIEW, YearViewClass)) -#define IS_YEAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_YEAR_VIEW)) -#define IS_YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_YEAR_VIEW)) - - -typedef struct _YearView YearView; -typedef struct _YearViewClass YearViewClass; - -struct _YearView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year we are displaying */ - - GnomeCanvasItem *heading; /* Big heading with year */ - GnomeCanvasItem *titles[12]; /* Titles for months */ - GnomeCanvasItem *mitems[12]; /* Month items */ - - int old_marked_day; /* The day that is marked as the current day */ - - int min_width; /* Minimum dimensions of year view, used for size_request*/ - int min_height; - - guint idle_id; /* ID of idle handler for resize */ - - int need_resize : 1; /* Specifies whether we need to resize the canvas items or not */ -}; - -struct _YearViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType year_view_get_type (void); - -/* Creates a new year view widget associated to the specified calendar */ -GtkWidget *year_view_new (GnomeCalendar *calendar, time_t year); - -/* Notifies the year view that a calendar object has changed */ -void year_view_update (YearView *yv, iCalObject *ico, int flags); - -/* Notifies the year view about a change of date */ -void year_view_set (YearView *yv, time_t year); - -/* Notifies the year view that the time format has changed */ -void year_view_time_format_changed (YearView *yv); - -/* Notifies the year view that colors have changed */ -void year_view_colors_changed (YearView *yv); - - -END_GNOME_DECLS - -#endif |