Commit for if my laptop dies - Federico

svn path=/trunk/; revision=3185
This commit is contained in:
Federico Mena Quintero
2000-05-23 20:52:12 +00:00
parent 4670021197
commit 910e86eba6
28 changed files with 1881 additions and 4213 deletions

View File

@ -1,3 +1,31 @@
2000-05-22 Federico Mena Quintero <federico@helixcode.com>
* gui/calendar-commands.c (calendar_get_events_in_range): Removed
function.
* gui/mark.c (mark_month_item): Use
cal_client_get_events_in_range().
* gui/calendar-commands.c (show_year_view_clicked): Comment out,
since we don't have a year view.
* gui/gnome-cal.c (setup_widgets): Removed the year view stuff.
(gnome_calendar_get_current_view_name): Likewise.
(gnome_calendar_update_view_times): Likewise.
(gnome_calendar_direction): Likewise.
(gnome_calendar_set_view): Likewise.
(gnome_calendar_update_all): Likewise.
(gnome_calendar_object_updated_cb): Likewise.
(gnome_calendar_object_removed_cb): Likewise.
(gnome_calendar_time_format_changed): Likewise.
(gnome_calendar_get_current_time_range): Likewise.
* gui/gnome-cal.h (GnomeCalendar): Removed the year view stuff.
* gui/Makefile.am (evolution_calendar_SOURCES): Added layout.[ch],
print.[ch]. Removed quick-view.[ch], year-view.[ch] since they
are no longer used. Removed all the old Pilot crap.
2000-05-20 Damon Chaplin <damon@helixcode.com>
* cal-util/cal-recur.[hc]: new files to implement iCalendar recurrence

View File

@ -2,13 +2,6 @@ SUBDIRS = dialogs
help_base = $(datadir)/gnome/help/cal
#if HAVE_GNOME_PILOT
#extra_pilot_bins = \
# calendar-conduit-control-applet \
# calendar-pilot-sync
#endif
CPPFLAGS = \
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\"
@ -43,6 +36,8 @@ bin_PROGRAMS = evolution-calendar
evolution_calendar_SOURCES = \
alarm.c \
alarm.h \
calendar-commands.c \
calendar-commands.h \
e-day-view-main-item.c \
e-day-view-main-item.h \
e-day-view-time-item.c \
@ -59,8 +54,11 @@ evolution_calendar_SOURCES = \
e-week-view-titles-item.h \
e-week-view.c \
e-week-view.h \
event-editor.c \
event-editor.h \
event-editor-utils.c \
event-editor-utils.h \
evolution-calendar-control.c \
getdate.y \
gncal-todo.c \
gncal-todo.h \
@ -69,27 +67,15 @@ evolution_calendar_SOURCES = \
gnome-cal.c \
gnome-cal.h \
goto.c \
layout.c \
layout.h \
mark.c \
mark.h \
popup-menu.c \
popup-menu.h \
prop.c \
quick-view.c \
quick-view.h \
todo-conduit.h \
year-view.c \
year-view.h \
calendar-commands.c \
calendar-commands.h \
event-editor.c \
event-editor.h \
evolution-calendar-control.c
# eventedit.c \
# eventedit.h \
print.c \
print.h \
prop.c
evolution_calendar_LDADD = \
$(EXTRA_GNOME_LIBS) \
@ -108,98 +94,6 @@ gnorbadir = $(sysconfdir)/CORBA/servers
gnorba_DATA = calendar-control.gnorba
endif
#calendar_pilot_sync_SOURCES = \
# GnomeCal-common.c \
# GnomeCal-stubs.c \
# alarm.c \
# calendar-pilot-sync.c \
# calendar.c \
# calendar.h
#calendar_pilot_sync_LDADD = \
# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \
# $(LINK_FLAGS)
#if HAVE_GNOME_PILOT
##calendar_conduit
#calendar_conduitsdir=$(libdir)/gnome-pilot/conduits
#
#calendar_conduits_LTLIBRARIES = libcalendar_conduit.la
#endif
#libcalendar_conduit_la_SOURCES = \
# GnomeCal-common.c \
# GnomeCal-stubs.c \
# calendar-conduit.h \
# calendar-conduit.c \
# alarm.c \
# calendar.c
#libcalendar_conduit_la_LDFLAGS = \
# -rpath $(libdir)
#libcalendar_conduit_la_LIBADD = \
# ../libversit/libversit.la \
# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \
# $(GNOME_LIBDIR) \
# $(GNOME_LIBS)
#calendar_conduit_control_applet_SOURCES = \
# calendar-conduit-control-applet.c
#calendar_conduit_control_applet_LDADD = \
# $(CAPPLET_LIBS) \
# $(GNOME_LIBDIR) \
# $(GNOME_CAPPLET_LIBS) \
# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \
# $(GNOMEUI_LIBS) \
# $(GNOME_PILOT_LIBS) \
# $(INTLLIBS)
#todo_conduit
#todo_conduitsdir=$(libdir)/gnome-pilot/conduits
#todo_conduits_LTLIBRARIES = libtodo_conduit.la
#libtodo_conduit_la_LDFLAGS = \
# -rpath $(libdir)
#libtodo_conduit_la_LIBADD = \
# $(GNOME_LIBDIR) \
# $(GNOME_LIBS)
#libtodo_conduit_la_SOURCES = \
# todo-conduit.c
#todo-conduit.c: GnomeCal.h
#todo_conduit_control_applet_SOURCES = \
# todo-conduit-control-applet.c
#todo_conduit_control_applet_LDADD = \
# $(CAPPLET_LIBS) \
# $(GNOME_LIBDIR) \
# $(GNOME_CAPPLET_LIBS) \
# $(PISOCK_LIBDIR) $(PISOCK_LIBS) \
# $(GNOMEUI_LIBS) \
# $(GNOME_PILOT_LIBS) \
# $(INTLLIBS)
#if HAVE_GNOME_PILOT
#ccenterdir = $(datadir)/control-center
#Rootdir = $(ccenterdir)
#PalmPilotdir = $(ccenterdir)/Peripherals/PalmPilot
#Conduitsdir = $(PalmPilotdir)/Conduits
#
#Conduits_DATA = \
# calendar-conduit-control-applet.desktop
## todo-conduit-control-applet.desktop
#
#Conduits_seconddir = $(datadir)/gnome/apps/Settings/Peripherals/PalmPilot/Conduits/
#Conduits_second_DATA = $(Conduits_DATA)
#endif
EXTRA_DIST = \
bell.xpm \
recur.xpm \
@ -211,18 +105,8 @@ EXTRA_DIST = \
calendar-control.gnorba \
calendar-control.oafinfo
# gnome-calendar-conduit.png
# todo-conduit-control-applet.desktop
# $(idl_DATA)
# $(gnorba_DATA)
# calendar-conduit-control-applet.desktop
#appicondir = $(datadir)/pixmaps
#appicon_DATA = gnome-calendar-conduit.png
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(help_base)/C
# $(mkinstalldirs) $(Conduitsdir)
if ENABLE_PURIFY
PLINK = $(LIBTOOL) --mode=link $(PURIFY) $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@

View File

@ -325,9 +325,11 @@ show_month_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path
static void
show_year_view_clicked (BonoboUIHandler *uih, void *user_data, const char *path)
{
#if 0
GnomeCalendar *gcal = GNOME_CALENDAR (user_data);
gnome_calendar_set_view (gcal, "yearview");
gtk_widget_grab_focus (gcal->year_view);
#endif
}
static void
@ -878,71 +880,3 @@ calendar_iterate_free_cache_entry (gpointer key,
{
ical_object_unref ((iCalObject*) value);
}
static gint
calendar_object_compare_by_start (gconstpointer a, gconstpointer b)
{
const CalendarObject *ca = a;
const CalendarObject *cb = b;
time_t diff;
diff = ca->ev_start - cb->ev_start;
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
/* FIXME -- where should this (and calendar_object_compare_by_start) go? */
/* FIXME -- for recurring events we should only load the iCalObject once. */
/* returns a list of events in the form of CalendarObject* */
GList*
calendar_get_events_in_range (CalClient *calc,
time_t start, time_t end)
{
GList *l, *cois, *res = NULL;
CalObjFindStatus status;
CalObjInstance *coi;
char *uid, *obj_string;
iCalObject *ico;
CalendarObject *co;
cois = cal_client_get_events_in_range (calc, start, end);
for (l = cois; l; l = l->next) {
coi = l->data;
uid = coi->uid;
obj_string = cal_client_get_object (calc, uid);
status = ical_object_find_in_string (uid, obj_string, &ico);
g_free (obj_string);
switch (status){
case CAL_OBJ_FIND_SUCCESS:
co = g_new (CalendarObject, 1);
co->ev_start = coi->start;
co->ev_end = coi->end;
co->ico = ico;
res = g_list_prepend (res, co);
break;
case CAL_OBJ_FIND_SYNTAX_ERROR:
printf ("calendar_get_events_in_range: "
"syntax error uid=%s\n", uid);
break;
case CAL_OBJ_FIND_NOT_FOUND:
printf ("calendar_get_events_in_range: "
"obj not found uid=%s\n", uid);
break;
}
g_free (uid);
g_free (coi);
}
g_list_free (cois);
/* Sort the list here, since it is more efficient to sort it once
rather doing lots of sorted insertions. */
res = g_list_sort (res, calendar_object_compare_by_start);
return res;
}

View File

@ -106,17 +106,6 @@ void calendar_set_uri (GnomeCalendar *gcal, char *calendar_file);
/* FIXME -- where should this stuff go? */
/*----------------------------------------------------------------------*/
/* This is only used by the calendar_get_events_in_range routine to get
* a list of objects that recur on a specific date
*/
typedef struct {
time_t ev_start;
time_t ev_end;
iCalObject *ico;
} CalendarObject;
GList *calendar_get_events_in_range (CalClient *calc,
time_t start, time_t end);
void
calendar_iterate (GnomeCalendar *cal,
time_t start, time_t end,

View File

@ -1,668 +0,0 @@
/*
* Calendar manager object
*
* This keeps track of a given calendar. Eventually this will abtract everything
* related to getting calendars/saving calendars locally or to a remote Calendar Service
*
* Copyright (C) 1998, 1999 the Free Software Foundation
*
* Authors:
* Miguel de Icaza (miguel@gnu.org)
* Federico Mena (quartic@gimp.org)
*
*/
#include <gnome.h>
#include <stdio.h>
#include <config.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cal-util/timeutil.h>
#include "calendar.h"
#include "alarm.h"
#include "libversit/vcc.h"
#ifdef HAVE_TZNAME
extern char *tzname[2];
#endif
/* Our day range */
time_t calendar_day_begin, calendar_day_end;
static void calendar_init_alarms (Calendar *cal);
static void calendar_set_day (void);
Calendar *
calendar_new (char *title,CalendarNewOptions options)
{
Calendar *cal;
cal = g_new0 (Calendar, 1);
cal->title = g_strdup (title);
#if 0
if (options & CALENDAR_USE_ICAL)
cal->format = CAL_ICAL;
else
cal->format = CAL_VCAL;
#endif
if ((calendar_day_begin == 0) || (calendar_day_end == 0))
calendar_set_day ();
cal->event_hash = g_hash_table_new (g_str_hash, g_str_equal);
if (options & CALENDAR_INIT_ALARMS) {
calendar_init_alarms (cal);
}
return cal;
}
static void
try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end)
{
alarm->trigger = start-alarm->offset;
if (alarm->trigger < calendar_day_begin)
return;
if (alarm->trigger > calendar_day_end)
return;
alarm_add (alarm, &calendar_notify, ico);
}
static int
add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure)
{
if (obj->aalarm.enabled)
try_add (obj, &obj->aalarm, start, end);
if (obj->dalarm.enabled)
try_add (obj, &obj->dalarm, start, end);
if (obj->palarm.enabled)
try_add (obj,&obj->palarm, start, end);
if (obj->malarm.enabled)
try_add (obj, &obj->malarm, start, end);
return TRUE;
}
#define max(a,b) ((a > b) ? a : b)
static void
ical_object_try_alarms (iCalObject *obj)
{
int ao, po, od, mo;
int max_o;
ao = alarm_compute_offset (&obj->aalarm);
po = alarm_compute_offset (&obj->palarm);
od = alarm_compute_offset (&obj->dalarm);
mo = alarm_compute_offset (&obj->malarm);
max_o = max (ao, max (po, max (od, mo)));
if (max_o == -1)
return;
ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj);
}
void
calendar_add_object (Calendar *cal, iCalObject *obj)
{
g_return_if_fail (cal != NULL);
g_return_if_fail (obj != NULL);
g_return_if_fail (obj->uid != NULL);
obj->new = 0;
switch (obj->type){
case ICAL_EVENT:
g_hash_table_insert (cal->event_hash, obj->uid, obj);
cal->events = g_list_prepend (cal->events, obj);
ical_object_try_alarms (obj);
#ifdef DEBUGGING_MAIL_ALARM
obj->malarm.trigger = 0;
calendar_notify (0, obj);
#endif
break;
case ICAL_TODO:
cal->todo = g_list_prepend (cal->todo, obj);
break;
case ICAL_JOURNAL:
cal->journal = g_list_prepend (cal->journal, obj);
break;
default:
g_assert_not_reached ();
}
if (!obj->uid){
char buffer [80];
snprintf (buffer, sizeof (buffer), "GnomeCalendar-%ld\n", time (NULL));
obj->uid = g_strdup (buffer);
}
cal->modified = TRUE;
obj->last_mod = time (NULL);
}
void
calendar_remove_object (Calendar *cal, iCalObject *obj)
{
switch (obj->type){
case ICAL_EVENT:
cal->events = g_list_remove (cal->events, obj);
g_hash_table_remove (cal->event_hash, obj->uid);
break;
case ICAL_TODO:
cal->todo = g_list_remove (cal->todo, obj);
break;
case ICAL_JOURNAL:
cal->journal = g_list_remove (cal->journal, obj);
break;
default:
g_assert_not_reached ();
}
cal->modified = TRUE;
}
void
calendar_destroy (Calendar *cal)
{
g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->events);
g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->todo);
g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL);
g_list_free (cal->journal);
g_hash_table_destroy (cal->event_hash);
if (cal->title)
g_free (cal->title);
if (cal->filename)
g_free (cal->filename);
g_free (cal);
}
void
calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure)
{
for (; objects; objects = objects->next){
iCalObject *object = objects->data;
ical_object_generate_events (object, start, end, cb, closure);
}
}
void
calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure)
{
calendar_iterate_on_objects (cal->events, start, end, cb, closure);
}
GList *
calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func)
{
GList *new_events = 0;
for (; objects; objects = objects->next){
iCalObject *object = objects->data;
if ((start <= object->dtstart) && (object->dtend <= end)){
if (sort_func)
new_events = g_list_insert_sorted (new_events, object, sort_func);
else
new_events = g_list_prepend (new_events, object);
}
}
/* Put the list in increasing order if no sort function was specified */
if (!sort_func)
new_events = g_list_reverse (new_events);
return new_events;
}
GList *
calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func)
{
return calendar_get_objects_in_range (cal->todo, start, end, sort_func);
}
GList *
calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func)
{
return calendar_get_objects_in_range (cal->journal, start, end, sort_func);
}
gint
calendar_compare_by_dtstart (gpointer a, gpointer b)
{
iCalObject *obj1, *obj2;
time_t diff;
obj1 = a;
obj2 = b;
diff = obj1->dtstart - obj2->dtstart;
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
#define str_val(obj) (char *) vObjectUStringZValue (obj)
/* Loads our calendar contents from a vObject */
void
calendar_load_from_vobject (Calendar *cal, VObject *vcal)
{
VObjectIterator i;
initPropIterator (&i, vcal);
while (moreIteration (&i)){
VObject *this = nextVObject (&i);
iCalObject *ical;
const char *object_name = vObjectName (this);
if (strcmp (object_name, VCDCreatedProp) == 0){
cal->created = time_from_isodate (str_val (this));
continue;
}
if (strcmp (object_name, VCLocationProp) == 0)
continue; /* FIXME: imlement */
if (strcmp (object_name, VCProdIdProp) == 0)
continue; /* FIXME: implement */
if (strcmp (object_name, VCVersionProp) == 0)
continue; /* FIXME: implement */
if (strcmp (object_name, VCTimeZoneProp) == 0)
continue; /* FIXME: implement */
ical = ical_object_create_from_vobject (this, object_name);
if (ical)
calendar_add_object (cal, ical);
}
}
static void
calendar_set_day (void)
{
time_t calendar_today;
calendar_today = time (NULL);
calendar_day_begin = time_day_begin (calendar_today);
calendar_day_end = time_day_end (calendar_today);
}
/* Loads a calendar from a file */
char *
calendar_load (Calendar *cal, char *fname)
{
VObject *vcal;
struct stat s;
if (cal->filename){
g_warning ("Calendar load called again\n");
return "Internal error";
}
cal->filename = g_strdup (fname);
stat (fname, &s);
cal->file_time = s.st_mtime;
calendar_set_day ();
#if 0
switch (cal->format) {
case CAL_VCAL:
#endif
vcal = Parse_MIME_FromFileName (fname);
if (!vcal)
return "Could not load the calendar";
calendar_load_from_vobject (cal, vcal);
cleanVObject (vcal);
cleanStrTbl ();
#if 0
break;
/*
case CAL_ICAL:
icalendar_calendar_load (cal, fname);
break;
*/
default:
return "Unknown calendar format";
}
#endif
return NULL;
}
/*
* calendar_load_from_memory:
* @cal: calendar on which we load the information
* @buffer: A buffer that contains a vCalendar file
*
* Loads the information from the vCalendar information in @buffer
* into the Calendar
*/
char *
calendar_load_from_memory (Calendar *cal, const char *buffer)
{
VObject *vcal;
g_return_val_if_fail (buffer != NULL, NULL);
cal->filename = g_strdup ("memory-based-calendar");
vcal = Parse_MIME (buffer, strlen (buffer));
if (!vcal)
return "Could not load the calendar";
cal->file_time = time (NULL);
calendar_load_from_vobject (cal, vcal);
cleanVObject (vcal);
cleanStrTbl ();
return NULL;
}
static VObject *
vcalendar_create_from_calendar (Calendar *cal)
{
VObject *vcal;
GList *l;
time_t now = time (NULL);
struct tm tm;
/* WE call localtime for the side effect of setting tzname */
tm = *localtime (&now);
vcal = newVObject (VCCalProp);
addPropValue (vcal, VCProdIdProp, "-//GNOME//NONSGML GnomeCalendar//EN");
#if defined(HAVE_TM_ZONE)
addPropValue (vcal, VCTimeZoneProp, tm.tm_zone);
#elif defined(HAVE_TZNAME)
addPropValue (vcal, VCTimeZoneProp, tzname[0]);
#endif
addPropValue (vcal, VCVersionProp, VERSION);
cal->temp = vcal;
/* Events */
for (l = cal->events; l; l = l->next) {
VObject *obj;
obj = ical_object_to_vobject ((iCalObject *) l->data);
addVObjectProp (vcal, obj);
}
/* To-do entries */
for (l = cal->todo; l; l = l->next) {
VObject *obj;
obj = ical_object_to_vobject ((iCalObject *) l->data);
addVObjectProp (vcal, obj);
}
return vcal;
}
void
calendar_save (Calendar *cal, char *fname)
{
VObject *vcal;
FILE *fp;
GtkWidget *dlg;
struct stat s;
int status;
if (fname == NULL)
fname = cal->filename;
vcal = vcalendar_create_from_calendar (cal);
if (g_file_exists (fname)){
char *backup_name = g_strconcat (fname, "~", NULL);
if (g_file_exists (backup_name)){
unlink (backup_name);
}
rename (fname, backup_name);
g_free (backup_name);
}
fp = fopen(fname,"w");
if (fp) {
writeVObject(fp, vcal);
fclose(fp);
if (strcmp(cal->filename, fname)) {
if (cal->filename)
g_free (cal->filename);
cal->filename = g_strdup (fname);
}
status = stat (fname, &s);
cal->file_time = s.st_mtime;
} else {
dlg = gnome_message_box_new(_("Failed to save calendar!"),
GNOME_MESSAGE_BOX_ERROR, "Ok", NULL);
gtk_widget_show(dlg);
}
cleanVObject (vcal);
cleanStrTbl ();
}
char *
calendar_get_as_vcal_string (Calendar *cal)
{
VObject *vcal;
char *result;
g_return_val_if_fail (cal != NULL, NULL);
vcal = vcalendar_create_from_calendar (cal);
result = writeMemVObject (NULL, 0, vcal);
cleanVObject (vcal);
cleanStrTbl ();
return result;
}
static gint
calendar_object_compare_by_start (gconstpointer a, gconstpointer b)
{
const CalendarObject *ca = a;
const CalendarObject *cb = b;
time_t diff;
diff = ca->ev_start - cb->ev_start;
return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
}
static int
assemble_event_list (iCalObject *obj, time_t start, time_t end, void *c)
{
CalendarObject *co;
GList **l = c;
co = g_new (CalendarObject, 1);
co->ev_start = start;
co->ev_end = end;
co->ico = obj;
*l = g_list_insert_sorted (*l, co, calendar_object_compare_by_start);
return 1;
}
void
calendar_destroy_event_list (GList *l)
{
GList *p;
for (p = l; p; p = p->next)
g_free (p->data);
g_list_free (l);
}
GList *
calendar_get_events_in_range (Calendar *cal, time_t start, time_t end)
{
GList *l = 0;
calendar_iterate (cal, start, end, assemble_event_list, &l);
return l;
}
void
calendar_object_changed (Calendar *cal, iCalObject *obj, int flags)
{
obj->last_mod = time (NULL);
obj->pilot_status = ICAL_PILOT_SYNC_MOD;
if (!(flags & CHANGE_DATES))
return;
/* Remove any alarms on the alarm list for this object */
while (alarm_kill (obj))
;
ical_object_try_alarms (obj);
}
static void
calendar_day_change (time_t time, CalendarAlarm *which, void *closure)
{
GList *events;
Calendar *cal = closure;
calendar_set_day ();
calendar_init_alarms (cal);
for (events = cal->events; events; events = events->next){
iCalObject *obj = events->data;
ical_object_try_alarms (obj);
}
}
static void
calendar_init_alarms (Calendar *cal)
{
CalendarAlarm day_change_alarm;
day_change_alarm.trigger = calendar_day_end;
alarm_add (&day_change_alarm, calendar_day_change, cal);
}
static iCalObject *
calendar_object_find_in_list (Calendar *cal, GList *list, const char *uid)
{
GList *l;
for (l = list; l; l = l->next){
iCalObject *obj = l->data;
if (strcmp (obj->uid, uid) == 0)
return obj;
}
return NULL;
}
iCalObject *
calendar_object_find_event (Calendar *cal, const char *uid)
{
g_return_val_if_fail (cal != NULL, NULL);
g_return_val_if_fail (uid != NULL, NULL);
return g_hash_table_lookup (cal->event_hash, uid);
}
iCalObject *
calendar_object_find_todo (Calendar *cal, const char *uid)
{
g_return_val_if_fail (cal != NULL, NULL);
g_return_val_if_fail (uid != NULL, NULL);
return calendar_object_find_in_list (cal, cal->todo, uid);
}
iCalObject *
calendar_object_find (Calendar *cal, const char *uid)
{
iCalObject *obj;
g_return_val_if_fail (cal != NULL, NULL);
g_return_val_if_fail (uid != NULL, NULL);
obj = calendar_object_find_in_list (cal, cal->todo, uid);
if (obj == NULL)
obj = calendar_object_find_in_list (cal, cal->events, uid);
return obj;
}
iCalObject *
calendar_object_find_by_pilot (Calendar *cal, int pilot_id)
{
GList *l;
g_return_val_if_fail (cal != NULL, NULL);
for (l = cal->events; l; l = l->next){
iCalObject *obj = l->data;
if (obj->pilot_id == pilot_id)
return obj;
}
for (l = cal->todo; l; l = l->next){
iCalObject *obj = l->data;
if (obj->pilot_id == pilot_id)
return obj;
}
return NULL;
}
/*
* calendar_string_from_object:
*
* Returns the iCalObject @object armored around a vCalendar
* object as a string.
*/
char *
calendar_string_from_object (iCalObject *object)
{
Calendar *cal;
char *str;
g_return_val_if_fail (object != NULL, NULL);
cal = calendar_new ("Temporal",CALENDAR_INIT_NIL);
calendar_add_object (cal, object);
str = calendar_get_as_vcal_string (cal);
calendar_remove_object (cal, object);
calendar_destroy (cal);
return str;
}

View File

@ -1,90 +0,0 @@
#ifndef CALENDAR_H
#define CALENDAR_H
#include "cal-util/calobj.h"
BEGIN_GNOME_DECLS
typedef struct {
/* This calendar's title */
char *title;
/* backing store for this calendar object */
char *filename;
/* The list of events; todo's and journal entries */
GList *events;
GList *todo;
GList *journal;
GList *timezones; /* required for iCalendar */
GHashTable *event_hash;
/* Time at which the calendar was created */
time_t created;
/* Timestamp in the filename */
time_t file_time;
/* If the calendar was last modified */
int modified;
void *temp;
void *corba_server;
} Calendar;
/* This is only used by the calendar_get_events_in_range routine to get
* a list of objects that recur on a specific date
*/
typedef struct {
time_t ev_start;
time_t ev_end;
iCalObject *ico;
} CalendarObject;
typedef enum {
CALENDAR_INIT_NIL = 0,
CALENDAR_INIT_ALARMS = 1 << 0,
CALENDAR_USE_ICAL = 1 << 1
} CalendarNewOptions;
Calendar *calendar_new (char *title,CalendarNewOptions options);
char *calendar_get_as_vcal_string (Calendar *cal);
char *calendar_string_from_object (iCalObject *object);
char *calendar_load (Calendar *cal, char *fname);
char *calendar_load_from_memory (Calendar *cal, const char *buffer);
void calendar_load_from_vobject (Calendar *cal, VObject *vcal);
void calendar_save (Calendar *cal, char *fname);
void calendar_add_object (Calendar *cal, iCalObject *obj);
void calendar_remove_object (Calendar *cal, iCalObject *obj);
void calendar_destroy (Calendar *cal);
GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func);
gint calendar_compare_by_dtstart (gpointer a, gpointer b);
void calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure);
void calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure);
/* Returns a list of CalendarObject structures. These represent the events in the calendar that are
* in the specified range.
*/
GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end);
/* Destroy list returned by calendar_get_events_in_range() with this function */
void calendar_destroy_event_list (GList *l);
/* Informs the calendar that obj information has changed */
void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags);
void calendar_notify (time_t time, CalendarAlarm *which, void *data);
iCalObject *calendar_object_find_event (Calendar *cal, const char *uid);
iCalObject *calendar_object_find_todo (Calendar *cal, const char *uid);
iCalObject *calendar_object_find (Calendar *cal, const char *uid);
iCalObject *calendar_object_find_by_pilot (Calendar *cal, int pilot_id);
END_GNOME_DECLS
#endif

View File

@ -1,129 +0,0 @@
/*
* corba-cal-factory.c: Service that provides access to the calendar repositories.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "gnome-cal.h"
#include "calendar-commands.h"
#include <cal-util/timeutil.h>
#include "libversit/vcc.h"
#include <libgnorba/gnorba.h>
#include <bonobo.h>
#include "GnomeCal.h"
#include "corba-cal-factory.h"
#include "corba-cal.h"
CORBA_ORB orb;
PortableServer_POA poa;
PortableServer_POAManager poa_manager;
static POA_Bonobo_GenericFactory__epv calendar_epv;
static POA_Bonobo_GenericFactory__vepv calendar_vepv;
/*
* Servant and Object Factory
*/
static POA_Bonobo_GenericFactory calendar_servant;
static Bonobo_GenericFactory calendar_factory;
static CORBA_boolean
calendar_supports (PortableServer_Servant servant,
CORBA_char * obj_goad_id,
CORBA_Environment * ev)
{
if (strcmp (obj_goad_id, "IDL:GNOME:Calendar:Repository:1.0") == 0)
return CORBA_TRUE;
else
return CORBA_FALSE;
}
static CORBA_Object
calendar_create_object (PortableServer_Servant servant,
CORBA_char *goad_id,
const GNOME_stringlist *params,
CORBA_Environment *ev)
{
GnomeCalendar *gcal;
struct stat s;
char *name;
if (params->_length == 1)
name = params->_buffer [0];
else
name = NULL;
if (strcmp (goad_id, "IDL:GNOME:Calendar:Repository:1.0") != 0){
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_GenericFactory_CannotActivate,
NULL);
return CORBA_OBJECT_NIL;
}
gcal = gnome_calendar_locate (name);
if (gcal != NULL)
return CORBA_Object_duplicate (gcal->calc->corba_server, ev);
if (stat (name, &s) != 0){
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_Bonobo_GenericFactory_CannotActivate,
NULL);
return CORBA_OBJECT_NIL;
}
gcal = new_calendar ("", name, NULL, NULL, FALSE);
return CORBA_Object_duplicate (gcal->calc->corba_server, ev);
}
void
init_corba_server (void)
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
poa_manager = PortableServer_POA__get_the_POAManager (poa, &ev);
if (ev._major != CORBA_NO_EXCEPTION){
g_warning ("Can not get the POA manager");
CORBA_exception_free (&ev);
return;
}
PortableServer_POAManager_activate (poa_manager, &ev);
/* First create the locator for the repositories as a factory object */
calendar_vepv.Bonobo_GenericFactory_epv = &calendar_epv;
calendar_epv.supports = calendar_supports;
calendar_epv.create_object = calendar_create_object;
calendar_servant.vepv = &calendar_vepv;
POA_Bonobo_GenericFactory__init ((PortableServer_Servant) &calendar_servant, &ev);
CORBA_free (PortableServer_POA_activate_object (
poa, (PortableServer_Servant)&calendar_servant, &ev));
calendar_factory = PortableServer_POA_servant_to_reference (
poa, (PortableServer_Servant) &calendar_servant, &ev);
goad_server_register (
CORBA_OBJECT_NIL, calendar_factory,
"IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev);
CORBA_exception_free (&ev);
}
void
unregister_calendar_services (void)
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
goad_server_unregister (
CORBA_OBJECT_NIL,
"IDL:GNOME:Calendar:RepositoryLocator:1.0", "object", &ev);
CORBA_exception_free (&ev);
}

View File

@ -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_ */

View File

@ -1,449 +0,0 @@
/*
* corba-cal.c: Service that provides access to the calendar repository
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
/*#include "calendar.h" DELETE */
#include "gnome-cal.h"
#include "alarm.h"
#include <cal-util/timeutil.h>
#include "libversit/vcc.h"
#include <libgnorba/gnome-factory.h>
#include "GnomeCal.h"
#include "corba-cal-factory.h"
#include "corba-cal.h"
static iCalObject *
calendar_object_find_by_pilot (GnomeCalendar *cal, int pilot_id);
typedef struct {
POA_GNOME_Calendar_Repository servant;
GnomeCalendar *calendar;
} CalendarServant;
/*
* Vectors
*/
static POA_GNOME_Calendar_Repository__epv calendar_repository_epv;
static POA_GNOME_Calendar_Repository__vepv calendar_repository_vepv;
/*
* Servant and Object Factory
*/
static POA_GNOME_Calendar_Repository calendar_repository_servant;
static inline GnomeCalendar *
gnomecal_from_servant (PortableServer_Servant servant)
{
CalendarServant *cs = (CalendarServant *) servant;
return cs->calendar;
}
static CORBA_char *
cal_repo_get_object (PortableServer_Servant servant,
const CORBA_char *uid,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
iCalObject *obj;
char *obj_string;
char *buffer;
CORBA_char *ret;
/*obj = calendar_object_find_event (gcal->cal, uid); DELETE */
obj_string = cal_client_get_object (gcal->calc, uid);
obj = string_to_ical_object (obj_string);
free (obj_string);
if (obj == NULL){
GNOME_Calendar_Repository_NotFound *exn;
exn = GNOME_Calendar_Repository_NotFound__alloc();
CORBA_exception_set (
ev,
CORBA_USER_EXCEPTION,
ex_GNOME_Calendar_Repository_NotFound,
exn);
return NULL;
}
/* buffer = calendar_string_from_object (obj); DELETE */
buffer = ical_object_to_string (obj);
ret = CORBA_string_dup (buffer);
free (buffer);
return ret;
}
static CORBA_char *
cal_repo_get_object_by_pilot_id (PortableServer_Servant servant,
CORBA_long pilot_id,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
iCalObject *obj;
char *buffer;
CORBA_char *ret;
obj = calendar_object_find_by_pilot (gcal, pilot_id);
if (obj == NULL){
GNOME_Calendar_Repository_NotFound *exn;
exn = GNOME_Calendar_Repository_NotFound__alloc();
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
ex_GNOME_Calendar_Repository_NotFound, exn);
return NULL;
}
/* buffer = calendar_string_from_object (obj); DELETE */
buffer = ical_object_to_string (obj);
ret = CORBA_string_dup (buffer);
free (buffer);
return ret;
}
/* where should this go? FIX ME */
static iCalObject *
calendar_object_find_by_pilot (GnomeCalendar *cal, int pilot_id)
{
GList *l, *uids;
g_return_val_if_fail (cal != NULL, NULL);
uids = cal_client_get_uids (cal->calc, CALOBJ_TYPE_ANY);
for (l = uids; l; l = l->next){
char *obj_string = cal_client_get_object (cal->calc, l->data);
iCalObject *obj = string_to_ical_object (obj_string);
g_free (obj_string);
if (obj->pilot_id == pilot_id)
return obj;
}
/* DELETE
for (l = cal->todo; l; l = l->next){
iCalObject *obj = l->data;
if (obj->pilot_id == pilot_id)
return obj;
}
*/
return NULL;
}
static CORBA_char *
cal_repo_get_id_from_pilot_id (PortableServer_Servant servant,
CORBA_long pilot_id,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
iCalObject *obj;
obj = calendar_object_find_by_pilot (gcal, pilot_id);
if (obj == NULL){
GNOME_Calendar_Repository_NotFound *exn;
exn = GNOME_Calendar_Repository_NotFound__alloc();
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
ex_GNOME_Calendar_Repository_NotFound, exn);
return NULL;
}
return CORBA_string_dup (obj->uid);
}
static void
cal_repo_delete_object (PortableServer_Servant servant,
const CORBA_char *uid,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
iCalObject *obj;
char *obj_string;
/* obj = calendar_object_find_event (gcal->cal, uid); */
obj_string = cal_client_get_object (gcal->calc, uid);
obj = string_to_ical_object (obj_string);
free (obj_string);
if (obj == NULL){
GNOME_Calendar_Repository_NotFound *exn;
exn = GNOME_Calendar_Repository_NotFound__alloc();
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
ex_GNOME_Calendar_Repository_NotFound,
exn);
return;
}
gnome_calendar_remove_object (gcal, obj);
}
static void
cal_repo_update_object (PortableServer_Servant servant,
const CORBA_char *uid,
const CORBA_char *vcalendar_object,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
/* iCalObject *obj; char *obj_string; */
iCalObject *new_object;
char *new_object_string;
new_object = ical_object_new_from_string (vcalendar_object);
#if 0 /* it looks like this is taken care of in cal_client_update_object? */
/* DELETE */
/* obj = calendar_object_find_event (gcal->cal, uid); DELETE */
obj_string = cal_client_get_object (gcal->calc, uid);
obj = string_to_ical_object (obj_string);
free (obj_string);
if (obj != NULL){
/* calendar_remove_object (gcal->cal, obj); DELETE */
cal_client_remove_object (gcal->calc, uid);
}
#endif /* 0 */
/* calendar_add_object (gcal->cal, new_object); DELETE */
new_object_string = ical_object_to_string (new_object);
cal_client_update_object (gcal->calc, uid, new_object_string);
free (new_object_string);
}
static void
cal_repo_update_pilot_id (PortableServer_Servant servant,
const CORBA_char *uid,
const CORBA_long pilot_id,
const CORBA_long pilot_status,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
iCalObject *obj;
char *obj_string;
/* obj = calendar_object_find_event (gcal->cal, uid); DELETE */
obj_string = cal_client_get_object (gcal->calc, uid);
obj = string_to_ical_object (obj_string);
free (obj_string);
if (obj == NULL){
GNOME_Calendar_Repository_NotFound *exn;
exn = GNOME_Calendar_Repository_NotFound__alloc();
CORBA_exception_set (
ev,
CORBA_USER_EXCEPTION,
ex_GNOME_Calendar_Repository_NotFound,
exn);
return;
}
obj->pilot_id = pilot_id;
obj->pilot_status = pilot_status;
}
static void list_free_string (gpointer data, gpointer user_data)
{
free (data);
}
static CORBA_long
cal_repo_get_number_of_objects (PortableServer_Servant servant,
GNOME_Calendar_Repository_RecordStatus record_status,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
CORBA_long res;
iCalPilotState real_record_status;
GList *l, *uids;
if (record_status == GNOME_Calendar_Repository_ANY) {
/* return g_list_length(gcal->cal->events); DELETE */
GList *uids = cal_client_get_uids (gcal->calc,
CALOBJ_TYPE_EVENT);
res = g_list_length (uids);
g_list_foreach (uids, list_free_string, NULL);
g_list_free (uids);
return res;
}
switch (record_status) {
case GNOME_Calendar_Repository_NEW:
real_record_status = ICAL_PILOT_SYNC_MOD;
break;
case GNOME_Calendar_Repository_MODIFIED:
real_record_status = ICAL_PILOT_SYNC_MOD;
break;
case GNOME_Calendar_Repository_DELETED:
real_record_status = ICAL_PILOT_SYNC_DEL;
break;
}
res = 0;
uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT);
for (l = uids; l; l = l->next){
char *obj_string = cal_client_get_object (gcal->calc, l->data);
iCalObject *obj = string_to_ical_object (obj_string);
if (obj->pilot_status == real_record_status)
res ++;
g_free (l->data);
}
g_list_free (uids);
return res;
}
static GNOME_Calendar_Repository_String_Sequence*
cal_repo_get_object_id_list(PortableServer_Servant servant,
CORBA_Environment *ev)
{
GnomeCalendar *gcal = gnomecal_from_servant (servant);
GList *l, *uids;
GNOME_Calendar_Repository_String_Sequence *result;
int counter;
uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT);
result = GNOME_Calendar_Repository_String_Sequence__alloc();
result->_length = g_list_length (uids);
result->_buffer =
CORBA_sequence_CORBA_string_allocbuf(result->_length);
counter = 0;
for (l = uids; l; l = l->next){
result->_buffer[counter] = CORBA_string_dup(l->data);
counter++;
g_free (l->data);
}
g_list_free (uids);
return result;
}
static CORBA_char *
cal_repo_get_updated_objects (PortableServer_Servant servant,
CORBA_Environment *ev)
{
/* FIX ME -- this might be wrong */
GnomeCalendar *gcal = gnomecal_from_servant (servant);
/* Calendar *dirty_cal; DELETE */
VObject *vcalobj, *vobj;
GList *l, *uids;
CORBA_char *res;
char *str;
/* dirty_cal = calendar_new ("Temporal",CALENDAR_INIT_NIL); DELETE */
vcalobj = newVObject (VCCalProp);
uids = cal_client_get_uids (gcal->calc, CALOBJ_TYPE_EVENT);
for (l = uids; l; l = l->next){
char *obj_string = cal_client_get_object (gcal->calc, l->data);
iCalObject *obj = string_to_ical_object (obj_string);
if (obj->pilot_status != ICAL_PILOT_SYNC_MOD)
continue;
/* calendar_add_object (dirty_cal, obj); DELETE */
vobj = ical_object_to_vobject (obj);
addVObjectProp (vcalobj, vobj);
g_free (l->data);
}
g_list_free (uids);
# if 0
/* DELETE */
str = calendar_get_as_vcal_string (dirty_cal);
res = CORBA_string_dup (str);
free (str); /* calendar_get_as_vcal_string() uses writeMemVObject(), which uses realloc() */
calendar_destroy (dirty_cal);
# endif /* 0 */
str = writeMemVObject (NULL, NULL, vcalobj);
res = CORBA_string_dup (str);
free (str); /* calendar_get_as_vcal_string() uses writeMemVObject(),
which uses realloc() */
cleanVObject (vcalobj);
cleanStrTbl ();
return res;
}
static void
cal_repo_done (PortableServer_Servant servant,
CORBA_Environment *ev)
{
/* GnomeCalendar *gcal = gnomecal_from_servant (servant); */
/* calendar_save (gcal->cal, NULL); DELETE */
/* FIX ME -- i dont know what to do here */
}
static void
init_calendar_repo_class (void)
{
calendar_repository_epv.get_object = cal_repo_get_object;
calendar_repository_epv.get_object_by_pilot_id = cal_repo_get_object_by_pilot_id;
calendar_repository_epv.get_id_from_pilot_id = cal_repo_get_id_from_pilot_id;
calendar_repository_epv.delete_object = cal_repo_delete_object;
calendar_repository_epv.update_object = cal_repo_update_object;
calendar_repository_epv.get_number_of_objects = cal_repo_get_number_of_objects;
calendar_repository_epv.get_updated_objects = cal_repo_get_updated_objects;
calendar_repository_epv.update_pilot_id = cal_repo_update_pilot_id;
calendar_repository_epv.get_object_id_list = cal_repo_get_object_id_list;
calendar_repository_epv.done = cal_repo_done;
calendar_repository_vepv.GNOME_Calendar_Repository_epv =
&calendar_repository_epv;
calendar_repository_servant.vepv = &calendar_repository_vepv;
}
/*
* Initializes the CORBA parts of the @calendar object
*/
void
gnome_calendar_create_corba_server (GnomeCalendar *calendar)
{
static gboolean class_inited = FALSE;
CalendarServant *calendar_servant;
CORBA_Environment ev;
if (!class_inited){
init_calendar_repo_class ();
class_inited = TRUE;
}
calendar_servant = g_new0 (CalendarServant, 1);
calendar_servant->servant.vepv = &calendar_repository_vepv;
calendar_servant->calendar = calendar;
CORBA_exception_init (&ev);
POA_GNOME_Calendar_Repository__init ((PortableServer_Servant) calendar_servant, &ev);
CORBA_free (
PortableServer_POA_activate_object (poa, calendar_servant, &ev));
calendar->calc->corba_server =
PortableServer_POA_servant_to_reference (poa, calendar_servant, &ev);
CORBA_exception_free (&ev);
}

View File

@ -1,6 +0,0 @@
#ifndef _CORBA_CAL_H_
#define _CORBA_CAL_H_
void gnome_calendar_create_corba_server (GnomeCalendar *calendar);
#endif /* _CORBA_CAL_H_ */

View File

@ -27,7 +27,6 @@
#include "eventedit.h"
#include "gncal-todo.h"
#include "gnome-cal.h"
#include "year-view.h"
#include "calendar-commands.h"
@ -227,23 +226,6 @@ setup_widgets (GnomeCalendar *gcal)
gtk_widget_show (gcal->month_view);
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->main_notebook),
gcal->month_view, gtk_label_new (""));
/* The Year View. */
gcal->year_view = year_view_new (gcal, gcal->selection_start_time);
#if 0
gtk_widget_show (gcal->year_view);
#endif
gcal->year_view_sw = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (gcal->year_view_sw);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (gcal->year_view_sw),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (gcal->year_view_sw),
gcal->year_view);
GTK_LAYOUT (gcal->year_view)->vadjustment->step_increment = 10.0;
gtk_adjustment_changed (GTK_LAYOUT (gcal->year_view)->vadjustment);
gtk_notebook_append_page (GTK_NOTEBOOK (gcal->main_notebook),
gcal->year_view_sw, gtk_label_new (""));
}
static GtkWidget *
@ -276,8 +258,6 @@ gnome_calendar_get_current_view_name (GnomeCalendar *gcal)
return "weekview";
else if (page == gcal->month_view)
return "monthview";
else if (page == gcal->year_view_sw)
return "yearview";
else
return "dayview";
}
@ -314,9 +294,6 @@ gnome_calendar_update_view_times (GnomeCalendar *gcal,
e_week_view_set_selected_time_range (E_WEEK_VIEW (page),
gcal->selection_start_time,
gcal->selection_end_time);
else if (page == gcal->year_view_sw)
year_view_set (YEAR_VIEW (gcal->year_view),
gcal->selection_start_time);
else {
g_warning ("My penguin is gone!");
g_assert_not_reached ();
@ -339,8 +316,6 @@ gnome_calendar_direction (GnomeCalendar *gcal, int direction)
new_time = time_add_week (current_time, direction);
else if (cp == gcal->month_view)
new_time = time_add_month (current_time, direction);
else if (cp == gcal->year_view_sw)
new_time = time_add_year (current_time, direction);
else {
g_warning ("Weee! Where did the penguin go?");
g_assert_not_reached ();
@ -412,9 +387,6 @@ gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name)
} else if (strcmp (page_name, "monthview") == 0) {
page = gcal->month_view;
main_page = 1;
} else if (strcmp (page_name, "yearview") == 0) {
page = gcal->year_view_sw;
main_page = 2;
} else {
g_warning ("Unknown calendar view: %s", page_name);
return;
@ -819,10 +791,6 @@ gnome_calendar_update_all (GnomeCalendar *cal)
e_week_view_update_all_events (E_WEEK_VIEW (cal->week_view));
e_week_view_update_all_events (E_WEEK_VIEW (cal->month_view));
#if 0
year_view_update (YEAR_VIEW (cal->year_view), NULL, TRUE);
#endif
gncal_todo_update (GNCAL_TODO (cal->todo), NULL, TRUE);
gnome_calendar_tag_calendar (cal, cal->gtk_calendar);
}
@ -897,11 +865,6 @@ gnome_calendar_object_updated_cb (GtkWidget *cal_client,
e_week_view_update_event (E_WEEK_VIEW (gcal->week_view), uid);
e_week_view_update_event (E_WEEK_VIEW (gcal->month_view), uid);
/* FIXME: optimize these? */
#if 0
year_view_update (YEAR_VIEW (gcal->year_view), NULL, TRUE);
#endif
gncal_todo_update (GNCAL_TODO (gcal->todo), NULL, TRUE);
gnome_calendar_tag_calendar (gcal, gcal->gtk_calendar);
}
@ -922,10 +885,6 @@ gnome_calendar_object_removed_cb (GtkWidget *cal_client,
e_week_view_remove_event (E_WEEK_VIEW (gcal->week_view), uid);
e_week_view_remove_event (E_WEEK_VIEW (gcal->month_view), uid);
/* FIXME: optimize these? */
#if 0
year_view_update (YEAR_VIEW (gcal->year_view), NULL, CHANGE_ALL);
#endif
gncal_todo_update (GNCAL_TODO (gcal->todo), NULL, CHANGE_ALL);
gnome_calendar_tag_calendar (gcal, gcal->gtk_calendar);
}
@ -1300,8 +1259,6 @@ gnome_calendar_time_format_changed (GnomeCalendar *gcal)
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
year_view_time_format_changed (YEAR_VIEW (gcal->year_view));
gtk_calendar_display_options (gcal->gtk_calendar,
(week_starts_on_monday
? (gcal->gtk_calendar->display_flags
@ -1365,11 +1322,6 @@ gnome_calendar_get_current_time_range (GnomeCalendar *gcal,
|| page == gcal->month_view)
e_week_view_get_selected_time_range (E_WEEK_VIEW (page),
start_time, end_time);
#if 0
else if (page == gcal->year_view_sw)
year_view_set (YEAR_VIEW (gcal->year_view),
gcal->selection_start_time);
#endif
else {
g_warning ("My penguin is gone!");
g_assert_not_reached ();

View File

@ -45,8 +45,6 @@ typedef struct {
GtkWidget *work_week_view;
GtkWidget *week_view;
GtkWidget *month_view;
GtkWidget *year_view;
GtkWidget *year_view_sw;
void *event_editor;
@ -113,8 +111,6 @@ void gnome_calendar_object_changed (GnomeCalendar *gcal,
iCalObject *obj,
int flags);
void calendar_notify (time_t time, CalendarAlarm *which, void *data);
GnomeCalendar *gnome_calendar_locate (const char *pathname);
/* Notifies the calendar that the time format has changed and it must update all its views */

309
calendar/gui/layout.c Normal file
View File

@ -0,0 +1,309 @@
/* Evolution calendar - Event layout engine
*
* Copyright (C) 2000 Helix Code, Inc.
*
* Authors: Miguel de Icaza <miguel@helixcode.com>
* Federico Mena-Quintero <federico@helixcode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <stdlib.h>
#include "layout.h"
/* This structure is used to pass around layout information among the internal
* layout functions.
*/
struct layout_info {
GList *events; /* List of events from client */
int num_events; /* The number of events (length of the list) */
LayoutQueryTimeFunc func; /* Function to convert a list item to a start/end time pair */
int num_rows; /* Size of the time partition */
time_t *partition; /* The time partition containing start and end time values */
int *array; /* Working array of free and allocated time slots */
int *allocations; /* Returned array of slot allocations */
int *slots; /* Returned array of slots used */
int num_slots; /* Number of slots used */
};
/* This defines the maximum number of events to overlap per row. More than that
* number of events will not be displayed. This is not ideal, so sue me.
*/
#define MAX_EVENTS_PER_ROW 32
/* Compares two time_t values, used for qsort() */
static int
compare_time_t (const void *a, const void *b)
{
time_t ta, tb;
ta = *((time_t *) a);
tb = *((time_t *) b);
if (ta < tb)
return -1;
else if (ta > tb)
return 1;
else
return 0;
}
/* Builds a partition of the time range occupied by the events in the list. It returns an array
* with the times that define the partition and the number of items in the partition.
*/
static void
build_partition (struct layout_info *li)
{
time_t *rows, *p, *q;
GList *list;
int i, unique_vals;
/* This is the maximum number of rows we would need */
li->num_rows = li->num_events * 2;
/* Fill the rows with the times */
rows = g_new (time_t, li->num_rows);
for (list = li->events, p = rows; list; list = list->next) {
(* li->func) (list, &p[0], &p[1]);
p += 2;
}
/* Do a sort | uniq on the array */
qsort (rows, li->num_rows, sizeof (time_t), compare_time_t);
p = rows;
q = rows + 1;
unique_vals = 1;
for (i = 1; i < li->num_rows; i++, q++)
if (*q != *p) {
unique_vals++;
p++;
*p = *q;
}
/* Return the number of unique values in the partition and the partition array itself */
li->num_rows = unique_vals;
li->partition = rows;
}
/* Returns the index of the element in the partition that corresponds to the specified time */
static int
find_index (struct layout_info *li, time_t t)
{
int i;
for (i = 0; ; i++)
if (li->partition[i] == t)
return i;
g_assert_not_reached ();
}
#define xy(li, x, y) li->array[(y * MAX_EVENTS_PER_ROW) + (x)]
/* Checks that all the cells in the slot array at the specified slot column are free to use by an
* event that has the specified range.
*/
static int
range_is_empty (struct layout_info *li, int slot, time_t start, time_t end)
{
int i;
for (i = find_index (li, start); li->partition[i] < end; i++)
if (xy (li, slot, i) != -1)
return FALSE;
return TRUE;
}
/* Allocates a time in the slot array for the specified event's index */
static void
range_allocate (struct layout_info *li, int slot, time_t start, time_t end, int ev_num)
{
int i;
for (i = find_index (li, start); li->partition[i] < end; i++)
xy (li, slot, i) = ev_num;
}
/* Performs the initial allocation of slots for events. Each event gets one column; they will be
* expanded in a later stage. Returns the number of columns used.
*/
static void
initial_allocate (struct layout_info *li)
{
GList *events;
int i;
int slot;
int num_slots;
time_t start, end;
num_slots = 0;
for (i = 0, events = li->events; events; events = events->next, i++) {
(* li->func) (events, &start, &end);
/* Start with no allocation, no columns */
li->allocations[i] = -1;
li->slots[i] = 0;
/* Find a free column for the event */
for (slot = 0; slot < MAX_EVENTS_PER_ROW; slot++)
if (range_is_empty (li, slot, start, end)) {
range_allocate (li, slot, start, end, i);
li->allocations[i] = slot;
li->slots[i] = 1;
if ((slot + 1) > num_slots)
num_slots = slot + 1;
break;
}
}
li->num_slots = num_slots;
}
/* Returns the maximum number of columns that an event can expanded by in the slot array */
static int
columns_to_expand (struct layout_info *li, int ev_num, time_t start, time_t end)
{
int cols;
int slot;
int i_start;
int i;
cols = 0;
i_start = find_index (li, start);
for (slot = li->allocations[ev_num] + 1; slot < li->num_slots; slot++) {
for (i = i_start; li->partition[i] < end; i++)
if (xy (li, slot, i) != -1)
return cols;
cols++;
}
return cols;
}
/* Expands an event by the specified number of columns */
static void
do_expansion (struct layout_info *li, int ev_num, time_t start, time_t end, int num_cols)
{
int i, j;
int slot;
for (i = find_index (li, start); li->partition[i] < end; i++) {
slot = li->allocations[ev_num] + 1;
for (j = 0; j < num_cols; j++)
xy (li, slot + j, i) = ev_num;
}
}
/* Expands the events in the slot array to occupy as many columns as possible. This is the second
* pass of the layout algorithm.
*/
static void
expand_events (struct layout_info *li)
{
GList *events;
time_t start, end;
int i;
int cols;
for (i = 0, events = li->events; events; events = events->next, i++) {
(* li->func) (events, &start, &end);
cols = columns_to_expand (li, i, start, end);
if (cols == 0)
continue; /* We can't expand this event */
do_expansion (li, i, start, end, cols);
li->slots[i] += cols;
}
}
void
layout_events (GList *events, LayoutQueryTimeFunc func,
int *num_slots, int **allocations, int **slots)
{
struct layout_info li;
int i;
g_return_if_fail (num_slots != NULL);
g_return_if_fail (allocations != NULL);
g_return_if_fail (slots != NULL);
if (!events) {
*num_slots = 0;
*allocations = NULL;
*slots = NULL;
return;
}
li.events = events;
li.num_events = g_list_length (events);
li.func = func;
/* Build the partition of the time range, and then build the array of slots */
build_partition (&li);
li.array = g_new (int, li.num_rows * MAX_EVENTS_PER_ROW);
for (i = 0; i < (li.num_rows * MAX_EVENTS_PER_ROW); i++)
li.array[i] = -1; /* This is our 'empty' value */
/* Build the arrays for allocations and columns used */
li.allocations = g_new (int, li.num_events);
li.slots = g_new (int, li.num_events);
/* Perform initial allocation and then expand the events to as many
* slots as they can occupy.
*/
initial_allocate (&li);
expand_events (&li);
/* Clean up and return values */
g_free (li.partition);
g_free (li.array);
*num_slots = li.num_slots;
*allocations = li.allocations;
*slots = li.slots;
}

56
calendar/gui/layout.h Normal file
View File

@ -0,0 +1,56 @@
/* Evolution calendar - Event layout engine
*
* Copyright (C) 2000 Helix Code, Inc.
*
* Authors: Miguel de Icaza <miguel@helixcode.com>
* Federico Mena-Quintero <federico@helixcode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef LAYOUT_H
#define LAYOUT_H
#include <glib.h>
#include <time.h>
/* Functions of this type must translate the list item into two time_t values
* for the start and end of an event.
*/
typedef void (* LayoutQueryTimeFunc) (GList *event, time_t *start, time_t *end);
/* This is the main layout function for overlapping events. You pass in a list
* of (presumably) events and a function that should take a list element and
* return the start and end times for the event corresponding to that list
* element.
*
* It returns the number of slots ("columns") that you need to take into account
* when actually painting the events, the array of the first slot index that
* each event occupies, and the array of number of slots that each event
* occupies. You have to free both arrays.
*
* You will get somewhat better-looking results if the list of events is sorted
* by using the start time as the primary sort key and the end time as the
* secondary sort key -- so that "longer" events go first in the list.
*/
void layout_events (GList *events, LayoutQueryTimeFunc func,
int *num_slots, int **allocations, int **slots);
#endif

View File

@ -1,434 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Main file for the GNOME Calendar program
* Copyright (C) 1998 the Free Software Foundation
*
* Authors:
* Miguel de Icaza (miguel@kernel.org)
* Federico Mena (federico@helixcode.com)
*/
#include <config.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <gnome.h>
#include <libgnorba/gnorba.h>
#include <bonobo.h>
#include <cal-util/timeutil.h>
#include <gui/alarm.h>
#include <gui/eventedit.h>
#include <gui/gnome-cal.h>
#include <gui/calendar-commands.h>
enum {
GEOMETRY_KEY = -1,
USERFILE_KEY = -2,
VIEW_KEY = -3,
HIDDEN_KEY = -4,
TODO_KEY = -5,
DEBUG_KEY = -6
};
/* Lists used to startup various GnomeCalendars */
static GList *start_calendars;
static GList *start_geometries;
static GList *start_views;
/* For dumping part of a calendar */
static time_t from_t, to_t;
/* If set, show events for the specified date and quit */
/*static int show_events;*/
/* If set, show todo items quit */
/*static int show_todo;*/
/* If true, do not show our top level window */
int startup_hidden = 0;
/* File to load instead of the user default's file */
static char *load_file;
extern time_t get_date ();
static void
process_dates (void)
{
if (!from_t)
from_t = time_day_begin (time (NULL));
if (!to_t || to_t < from_t)
to_t = time_add_day (from_t, 1);
}
static int
same_day (struct tm *a, struct tm *b)
{
return (a->tm_mday == b->tm_mday &&
a->tm_mon == b->tm_mon &&
a->tm_year == b->tm_year);
}
#if 0
static void
dump_events (void)
{
CalClient *calc;
gboolean r;
GList *l;
time_t now = time (NULL);
struct tm today = *localtime (&now);
process_dates ();
init_calendar ();
/* FIXME: this is not waiting for the calendar to be loaded */
/* DELETE
cal = calendar_new (full_name, CALENDAR_INIT_ALARMS);
s = calendar_load (cal, load_file ? load_file : user_calendar_file);
if (s){
printf ("error: %s\n", s);
exit (1);
}
*/
r = cal_client_load_calendar (calc,
load_file ? load_file : user_calendar_file);
if (r == FALSE) {
printf ("error: loading %s\n",
load_file ? load_file : user_calendar_file);
exit (1);
}
l = calendar_get_events_in_range (calc, from_t, to_t);
for (; l; l = l->next){
char start [80], end [80];
CalendarObject *co = l->data;
struct tm ts, te;
char *format;
ts = *localtime (&co->ev_start);
te = *localtime (&co->ev_end);
if (same_day (&today, &ts))
format = N_("%H:%M");
else
format = N_("%A %b %d, %H:%M");
strftime (start, sizeof (start), _(format), &ts);
if (!same_day (&ts, &te))
format = N_("%A %b %d, %H:%M");
strftime (end, sizeof (start), _(format), &te);
printf ("%s -- %s\n", start, end);
printf (" %s\n", co->ico->summary);
}
/* calendar_destroy_event_list (l); DELETE / FIXME */
/* calendar_destroy (cal); DELETE */
exit (0);
}
#endif /* 0 */
#if 0
static void
dump_todo (void)
{
CalClient *calc;
gboolean r;
GList *l;
process_dates ();
init_calendar ();
/* FIXME: this is not waiting for the calendar to be loaded */
/* DELETE
cal = calendar_new (full_name, CALENDAR_INIT_ALARMS);
s = calendar_load (cal, load_file ? load_file : user_calendar_file);
if (s){
printf ("error: %s\n", s);
exit (1);
}
*/
r = cal_client_load_calendar (calc,
load_file ? load_file : user_calendar_file);
if (r == FALSE) {
printf ("error: loading %s\n",
load_file ? load_file : user_calendar_file);
exit (1);
}
l = calendar_get_events_in_range (calc, from_t, to_t);
for (; l; l = l->next){
CalendarObject *co = l->data;
iCalObject *object = co->ico;
if (object->type != ICAL_TODO)
continue;
printf ("[%s]: %s\n",object->organizer->addr, object->summary);
}
/* calendar_destroy (cal); DELETE */
exit (0);
}
#endif /* 0 */
static void
session_die (void)
{
quit_cmd (NULL, NULL, NULL);
}
/*
* Save the session callback
*/
static int
session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown,
GnomeInteractStyle interact_style, gint fast, gpointer client_data)
{
char *sess_id;
char **argv = (char **) g_malloc (sizeof (char *) * ((active_calendars * 6) + 3));
GList *l, *free_list = 0;
int i;
sess_id = gnome_client_get_id (client);
argv [0] = client_data;
for (i = 1, l = all_calendars; l; l = l->next){
GnomeCalendar *gcal = GNOME_CALENDAR (l->data);
char *geometry;
geometry = gnome_geometry_string (GTK_WIDGET (gcal)->window);
/* FIX ME
if (strcmp (gcal->client->filename, user_calendar_file) == 0)
argv [i++] = "--userfile";
else {
argv [i++] = "--file";
argv [i++] = gcal->client->filename;
}
*/
argv [i++] = "--geometry";
argv [i++] = geometry;
argv [i++] = "--view";
argv [i++] = gnome_calendar_get_current_view_name (gcal);
free_list = g_list_append (free_list, geometry);
}
argv [i] = NULL;
gnome_client_set_clone_command (client, i, argv);
gnome_client_set_restart_command (client, i, argv);
for (l = free_list; l; l = l->next)
g_free (l->data);
g_list_free (free_list);
return 1;
}
static void
parse_an_arg (poptContext ctx,
enum poptCallbackReason reason,
const struct poptOption *opt,
char *arg, void *data)
{
switch (opt->val){
case 'f':
from_t = get_date (arg, NULL);
break;
case 't':
to_t = get_date (arg, NULL);
break;
case GEOMETRY_KEY:
start_geometries = g_list_append (start_geometries, arg);
break;
case USERFILE_KEY:
/* This is a special key that tells the program to load
* the user's calendar file. This allows session management
* to work even if the User's home directory changes location
* (ie, on a networked setup).
*/
arg = COOKIE_USER_HOME_DIR;
/* fall through */
break;
case VIEW_KEY:
start_views = g_list_append (start_views, arg);
break;
case 'F':
start_calendars = g_list_append (start_calendars, arg);
break;
/*
case TODO_KEY:
show_todo = 1;
break;
*/
/*
case 'e':
show_events = 1;
break;
*/
case HIDDEN_KEY:
startup_hidden = 1;
break;
case DEBUG_KEY:
if (!g_strcasecmp (arg, "alarms"))
debug_alarms = 1;
break;
default:
}
}
static const struct poptOption options [] = {
{ NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL },
{ "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"),
NULL },
{ "todo", 0, POPT_ARG_NONE, NULL, TODO_KEY, N_("Show TO-DO items and quit"),
NULL },
{ "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") },
{ "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") },
{ "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL },
{ "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") },
{ "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode (dayview, weekview, monthview, yearview)"), N_("VIEW") },
{ "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") },
{ "hidden", 0, POPT_ARG_NONE, NULL, HIDDEN_KEY, N_("If used, starts in iconic mode"), NULL },
{ "debug", 'd', POPT_ARG_STRING, NULL, DEBUG_KEY, N_("Enable debugging output of TYPE (alarms)"), N_("TYPE") },
{ NULL, '\0', 0, NULL, 0}
};
int
main (int argc, char **argv)
{
GnomeClient *client;
GtkWidget *cal_window;
GnomeCalendar *cal_frame;
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#ifdef USING_OAF
gnome_init_with_popt_table ("calendar", VERSION, argc, argv, oaf_popt_options,
0, NULL);
oaf_init (argc, argv);
#else
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
gnome_CORBA_init_with_popt_table ("calendar", VERSION, &argc, argv,
options, 0, NULL, 0, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("main(): could not initialize the ORB");
CORBA_exception_free (&ev);
exit (EXIT_FAILURE);
}
CORBA_exception_free (&ev);
}
#endif
if (!bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) {
g_message ("main(): could not initialize Bonobo");
exit (EXIT_FAILURE);
}
process_dates ();
# if 0
if (show_events)
dump_events ();
if (show_todo)
dump_todo ();
# endif /* 0 */
client = gnome_master_client ();
if (client) {
gtk_signal_connect (GTK_OBJECT (client), "save_yourself",
GTK_SIGNAL_FUNC (session_save_state), argv [0]);
gtk_signal_connect (GTK_OBJECT (client), "die",
GTK_SIGNAL_FUNC (session_die), NULL);
}
alarm_init ();
init_calendar ();
/* FIXME: the following is broken-ish, since geometries/views are not matched
* to calendars, but they are just picked in whatever order they came in
* from the command line.
*/
/* Load all of the calendars specified in the command line with the
* geometry specified, if any.
*/
if (start_calendars) {
GList *p, *g, *v;
char *title;
p = start_calendars;
g = start_geometries;
v = start_views;
while (p) {
char *file = p->data;
char *geometry = g ? g->data : NULL;
char *page_name = v ? v->data : NULL;
if (file == COOKIE_USER_HOME_DIR)
file = user_calendar_file;
if (strcmp (file, user_calendar_file) == 0)
title = full_name;
else
title = file;
cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
cal_frame = new_calendar (title, file, geometry, page_name, startup_hidden);
gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame));
gtk_widget_show (cal_window);
p = p->next;
if (g)
g = g->next;
if (v)
v = v->next;
}
g_list_free (p);
} else {
char *geometry = start_geometries ? start_geometries->data : NULL;
char *page_name = start_views ? start_views->data : NULL;
cal_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
cal_frame = new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden);
gtk_container_add (GTK_CONTAINER (cal_window), GTK_WIDGET (cal_frame));
gtk_widget_show (cal_window);
}
bonobo_main ();
return 0;
}

View File

@ -1,114 +0,0 @@
#ifndef MAIN_H
#define MAIN_H
/* Calendar preferences */
extern int day_begin, day_end;
extern char *user_name;
extern int am_pm_flag;
extern int week_starts_on_monday;
/* This enum and the following array define the color preferences */
typedef enum {
COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */
COLOR_PROP_HEADING_COLOR, /* Color for headings */
COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */
COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */
COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */
COLOR_PROP_DAY_FG, /* Color for day numbers */
COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */
COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */
COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */
COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */
COLOR_PROP_LAST /* Number of color properties */
} ColorProp;
struct color_prop {
int r; /* Values are in [0, 65535] */
int g;
int b;
char *label; /* Label for properties dialog */
char *key; /* Key for gnome_config */
};
extern struct color_prop color_props[];
/* todo preferences */
extern int todo_show_due_date;
extern int todo_item_dstatus_highlight_overdue;
extern int todo_item_dstatus_highlight_due_today;
extern int todo_item_dstatus_highlight_not_due_yet;
extern int todo_show_time_remaining;
extern int todo_show_priority;
extern char *todo_overdue_font_text;
extern gboolean todo_style_changed;
extern gint todo_current_sort_column;
extern gint todo_current_sort_type;
/* alarm stuff */
extern CalendarAlarm alarm_defaults[4];
extern gboolean beep_on_display;
extern gboolean enable_aalarm_timeout;
extern guint audio_alarm_timeout;
extern const guint MAX_AALARM_TIMEOUT;
extern gboolean enable_snooze;
extern guint snooze_secs;
extern const guint MAX_SNOOZE_SECS;
/* Creates and runs the preferences dialog box */
void properties (GtkWidget *toplevel);
/* Asks for all the time-related displays to be updated when the user changes the time format
* preferences.
*/
void time_format_changed (void);
/* Asks for all the month items' colors to be reset */
void colors_changed (void);
/* Asks for all todo lists to reflect the accurate properties */
void todo_properties_changed(void);
/* Creates and runs the Go-to date dialog */
void goto_dialog (GnomeCalendar *gcal);
/* Returns a pointer to a statically-allocated string with a representation of the specified color.
* Values must be in [0, 65535].
*/
char *build_color_spec (int r, int g, int b);
/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */
void parse_color_spec (char *spec, int *r, int *g, int *b);
/* Calls build_color_spec() for the color in the specified property number */
char *color_spec_from_prop (ColorProp propnum);
GnomeCalendar *new_calendar (char *full_name, char *calendar_file,
char *geometry, char *page, gboolean hidden);
/*----------------------------------------------------------------------*/
/* FIX ME -- where should this stuff go? */
/*----------------------------------------------------------------------*/
/* This is only used by the calendar_get_events_in_range routine to get
* a list of objects that recur on a specific date
*/
typedef struct {
time_t ev_start;
time_t ev_end;
iCalObject *ico;
} CalendarObject;
GList *calendar_get_events_in_range (CalClient *calc,
time_t start, time_t end);
void
calendar_iterate (GnomeCalendar *cal,
time_t start, time_t end,
calendarfn cb, void *closure);
#endif

View File

@ -1,8 +1,22 @@
/* Functions to mark calendars
/* Evolution calendar - Functions to mark calendars
*
* Copyright (C) 1998 Red Hat Software, Inc.
*
* Author: Federico Mena <federico@nuclecu.unam.mx>
* Author: Federico Mena-Quintero <federico@helixcode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
@ -11,6 +25,7 @@
#include "calendar-commands.h"
#include "mark.h"
/* Frees the specified data when an object is destroyed */
static void
@ -101,30 +116,35 @@ mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
}
void
mark_month_item (GnomeMonthItem *mitem, GnomeCalendar *cal)
mark_month_item (GnomeMonthItem *mitem, GnomeCalendar *gcal)
{
time_t month_begin, month_end;
GList *list, *l;
CalendarObject *co;
GList *events;
GList *l;
g_return_if_fail (mitem != NULL);
g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
g_return_if_fail (cal != NULL);
g_return_if_fail (gcal != NULL);
g_return_if_fail (GNOME_IS_CALENDAR (gcal));
month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1));
month_end = time_month_end (month_begin);
list = calendar_get_events_in_range (cal->client, month_begin, month_end);
events = cal_client_get_events_in_range (gcal->client, month_begin, month_end);
for (l = list; l; l = l->next) {
co = l->data;
for (l = events; l; l = l->next) {
CalObjInstance *coi;
coi = l->data;
/* We clip the event's start and end times to the month's limits */
mark_event_in_month (mitem, MAX (co->ev_start, month_begin), MIN (co->ev_end, month_end));
mark_event_in_month (mitem,
MAX (coi->start, month_begin),
MIN (coi->end, month_end));
}
/* calendar_destroy_event_list (list); DELETE / FIX ME */
cal_obj_instance_list_free (events);
}
void

View File

@ -1,8 +1,22 @@
/* Functions to mark calendars
/* Evolution calendar - Functions to mark calendars
*
* Copyright (C) 1998 Red Hat Software, Inc.
*
* Author: Federico Mena <federico@nuclecu.unam.mx>
* Author: Federico Mena-Quintero <federico@helixcode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef MARK_H
@ -11,6 +25,7 @@
/*#include "calendar.h"*/
#include "gnome-month-item.h"
/* These are the fonts used for the montly calendars */
@ -55,5 +70,6 @@ void month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpoi
*/
char *default_color_func (ColorProp prop_num, gpointer data);
#endif

View File

@ -1,800 +0,0 @@
/* Month view display for gncal
*
* Copyright (C) 1998 Red Hat Software, Inc.
*
* Author: Federico Mena <federico@nuclecu.unam.mx>
*/
#include <config.h>
#include <gnome.h>
#include <libgnomeui/gnome-canvas-text.h>
#include <cal-util/timeutil.h>
#include "eventedit.h"
#include "layout.h"
#include "month-view.h"
#include "calendar-commands.h"
#include "mark.h"
#include "quick-view.h"
/* Spacing between title and calendar */
#define SPACING 4
/* Padding between day borders and event text */
#define EVENT_PADDING 3
static void month_view_class_init (MonthViewClass *class);
static void month_view_init (MonthView *mv);
static void month_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void month_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static GnomeCanvasClass *parent_class;
GtkType
month_view_get_type (void)
{
static GtkType month_view_type = 0;
if (!month_view_type) {
GtkTypeInfo month_view_info = {
"MonthView",
sizeof (MonthView),
sizeof (MonthViewClass),
(GtkClassInitFunc) month_view_class_init,
(GtkObjectInitFunc) month_view_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
month_view_type = gtk_type_unique (gnome_canvas_get_type (), &month_view_info);
}
return month_view_type;
}
static void
month_view_class_init (MonthViewClass *class)
{
GtkWidgetClass *widget_class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gnome_canvas_get_type ());
widget_class->size_request = month_view_size_request;
widget_class->size_allocate = month_view_size_allocate;
}
/* Creates the quick view when a day is clicked in the month view */
static void
do_quick_view_popup (MonthView *mv, GdkEventButton *event, int day)
{
time_t day_begin_time, day_end_time;
GList *list;
GtkWidget *qv;
char date_str[256];
day_begin_time = time_from_day (mv->year, mv->month, day);
day_end_time = time_day_end (day_begin_time);
list = calendar_get_events_in_range (mv->calendar->client,
day_begin_time, day_end_time);
strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_begin_time));
qv = quick_view_new (mv->calendar, date_str, list);
quick_view_do_popup (QUICK_VIEW (qv), event);
gtk_widget_destroy (qv);
/* calendar_destroy_event_list (list); DELETE / FIX ME*/
}
/* Callback used to destroy the popup menu when the month view is destroyed */
static void
destroy_menu (GtkWidget *widget, gpointer data)
{
gtk_widget_destroy (GTK_WIDGET (data));
}
/* Creates a new appointment in the current day */
static void
new_appointment (GtkWidget *widget, gpointer data)
{
MonthView *mv;
time_t *t;
mv = MONTH_VIEW (data);
t = gtk_object_get_data (GTK_OBJECT (widget), "time_data");
event_editor_new_whole_day (mv->calendar, *t);
}
/* Convenience functions to jump to a view and set the time */
static void
do_jump (GtkWidget *widget, gpointer data, char *view_name)
{
MonthView *mv;
time_t *t;
mv = MONTH_VIEW (data);
/* Get the time data from the menu item */
t = gtk_object_get_data (GTK_OBJECT (widget), "time_data");
/* Set the view and time */
gnome_calendar_set_view (mv->calendar, view_name);
gnome_calendar_goto (mv->calendar, *t);
}
/* The following three callbacks set the view in the calendar and change the time */
static void
jump_to_day (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "dayview");
}
static void
jump_to_week (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "weekview");
}
static void
jump_to_year (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "yearview");
}
static GnomeUIInfo mv_popup_menu[] = {
GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _year"), NULL, jump_to_year, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_END
};
/* Creates the popup menu for the month view if it does not yet exist, and attaches it to the month
* view object so that it can be destroyed when appropriate.
*/
static GtkWidget *
get_popup_menu (MonthView *mv)
{
GtkWidget *menu;
menu = gtk_object_get_data (GTK_OBJECT (mv), "popup_menu");
if (!menu) {
menu = gnome_popup_menu_new (mv_popup_menu);
gtk_object_set_data (GTK_OBJECT (mv), "popup_menu", menu);
gtk_signal_connect (GTK_OBJECT (mv), "destroy",
(GtkSignalFunc) destroy_menu,
menu);
}
return menu;
}
/* Pops up the menu for the month view. */
static void
do_popup_menu (MonthView *mv, GdkEventButton *event, int day)
{
GtkWidget *menu;
static time_t t;
menu = get_popup_menu (mv);
/* Enable or disable items as appropriate */
gtk_widget_set_sensitive (mv_popup_menu[0].widget, day != 0);
gtk_widget_set_sensitive (mv_popup_menu[2].widget, day != 0);
gtk_widget_set_sensitive (mv_popup_menu[3].widget, day != 0);
if (day == 0)
day = 1;
/* Store the time for the menu item callbacks to use */
t = time_from_day (mv->year, mv->month, day);
gtk_object_set_data (GTK_OBJECT (mv_popup_menu[0].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (mv_popup_menu[2].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (mv_popup_menu[3].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (mv_popup_menu[4].widget), "time_data", &t);
gnome_popup_menu_do_popup (menu, NULL, NULL, event, mv);
}
/* Event handler for day groups. When mouse button 1 is pressed, it will pop up a quick view with
* the events in that day. When mouse button 3 is pressed, it will pop up a menu.
*/
static gint
day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
MonthView *mv;
int child_num;
int day;
mv = MONTH_VIEW (data);
child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (mv->mitem), item);
day = gnome_month_item_num2day (GNOME_MONTH_ITEM (mv->mitem), child_num);
switch (event->type) {
case GDK_BUTTON_PRESS:
if ((event->button.button == 1) && (day != 0)) {
do_quick_view_popup (mv, (GdkEventButton *) event, day);
return TRUE;
} else if (event->button.button == 3) {
do_popup_menu (mv, (GdkEventButton *) event, day);
return TRUE;
}
break;
default:
break;
}
return FALSE;
}
/* Returns the index of the specified arrow in the array of arrows */
static int
get_arrow_index (MonthView *mv, GnomeCanvasItem *arrow)
{
int i;
for (i = 0; i < 42; i++)
if (mv->up[i] == arrow)
return i;
else if (mv->down[i] == arrow)
return i + 42;
g_warning ("Eeeek, arrow %p not found in month view %p", arrow, mv);
return -1;
}
/* Checks whether arrows need to be displayed at the specified day index or not */
static void
check_arrow_visibility (MonthView *mv, int day_index)
{
GtkArg args[3];
double text_height;
double clip_height;
double y_offset;
args[0].name = "text_height";
args[1].name = "clip_height";
args[2].name = "y_offset";
gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 3, args);
text_height = GTK_VALUE_DOUBLE (args[0]);
clip_height = GTK_VALUE_DOUBLE (args[1]);
y_offset = GTK_VALUE_DOUBLE (args[2]);
/* Check up arrow */
if (y_offset < 0.0)
gnome_canvas_item_show (mv->up[day_index]);
else
gnome_canvas_item_hide (mv->up[day_index]);
if (y_offset > (clip_height - text_height))
gnome_canvas_item_show (mv->down[day_index]);
else
gnome_canvas_item_hide (mv->down[day_index]);
}
/* Finds which arrow was clicked and scrolls the corresponding text item in the month view */
static void
do_arrow_click (MonthView *mv, GnomeCanvasItem *arrow)
{
int arrow_index;
int day_index;
int up;
GtkArg args[4];
double text_height, clip_height;
double y_offset;
GdkFont *font;
arrow_index = get_arrow_index (mv, arrow);
up = (arrow_index < 42);
day_index = up ? arrow_index : (arrow_index - 42);
/* See how much we can scroll */
args[0].name = "text_height";
args[1].name = "clip_height";
args[2].name = "y_offset";
args[3].name = "font_gdk";
gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 4, args);
text_height = GTK_VALUE_DOUBLE (args[0]);
clip_height = GTK_VALUE_DOUBLE (args[1]);
y_offset = GTK_VALUE_DOUBLE (args[2]);
font = GTK_VALUE_BOXED (args[3]);
if (up)
y_offset += font->ascent + font->descent;
else
y_offset -= font->ascent + font->descent;
if (y_offset > 0.0)
y_offset = 0.0;
else if (y_offset < (clip_height - text_height))
y_offset = clip_height - text_height;
/* Scroll */
gnome_canvas_item_set (mv->text[day_index],
"y_offset", y_offset,
NULL);
check_arrow_visibility (mv, day_index);
}
/* Event handler for the scroll arrows in the month view */
static gint
arrow_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
MonthView *mv;
mv = MONTH_VIEW (data);
switch (event->type) {
case GDK_ENTER_NOTIFY:
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG),
NULL);
return TRUE;
case GDK_LEAVE_NOTIFY:
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
NULL);
return TRUE;
case GDK_BUTTON_PRESS:
if (event->button.button != 1)
break;
do_arrow_click (mv, item);
return TRUE;
default:
break;
}
return FALSE;
}
/* Creates a new arrow out of the specified points and connects the proper signals to it */
static GnomeCanvasItem *
new_arrow (MonthView *mv, GnomeCanvasGroup *group, GnomeCanvasPoints *points)
{
GnomeCanvasItem *item;
char *color_spec;
color_spec = color_spec_from_prop (COLOR_PROP_DAY_FG);
item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group),
gnome_canvas_polygon_get_type (),
"points", points,
"fill_color", color_spec,
"outline_color", color_spec,
NULL);
gtk_signal_connect (GTK_OBJECT (item), "event",
(GtkSignalFunc) arrow_event,
mv);
return item;
}
static void
month_view_init (MonthView *mv)
{
int i;
GnomeCanvasItem *day_group;
GnomeCanvasPoints *points;
/* Title */
mv->title = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (mv)),
gnome_canvas_text_get_type (),
"anchor", GTK_ANCHOR_N,
"fontset", HEADING_FONTSET,
"fill_color", "black",
NULL);
/* Month item */
mv->mitem = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (mv)));
gnome_canvas_item_set (mv->mitem,
"x", 0.0,
"anchor", GTK_ANCHOR_NW,
"day_anchor", GTK_ANCHOR_NE,
"start_on_monday", week_starts_on_monday,
"heading_padding", 2.0,
"heading_fontset", BIG_DAY_HEADING_FONTSET,
"day_fontset", BIG_NORMAL_DAY_FONTSET,
NULL);
/* Arrows and text items. The arrows start hidden by default; they will be shown as
* appropriate by the item adjustment code. Also, connect to the event signal of the
* day groups so that we can pop up the quick view when appropriate.
*/
points = gnome_canvas_points_new (3);
for (i = 0; i < 42; i++) {
day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem),
i + GNOME_MONTH_ITEM_DAY_GROUP);
gtk_signal_connect (GTK_OBJECT (day_group), "event",
(GtkSignalFunc) day_event,
mv);
/* Up arrow */
points->coords[0] = 3;
points->coords[1] = 10;
points->coords[2] = 11;
points->coords[3] = 10;
points->coords[4] = 7;
points->coords[5] = 3;
mv->up[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points);
/* Down arrow */
points->coords[0] = 13;
points->coords[1] = 3;
points->coords[2] = 17;
points->coords[3] = 10;
points->coords[4] = 21;
points->coords[5] = 3;
mv->down[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points);
/* Text item */
mv->text[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (day_group),
gnome_canvas_text_get_type (),
"fontset", EVENT_FONTSET,
"anchor", GTK_ANCHOR_NW,
"fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
"clip", TRUE,
NULL);
}
gnome_canvas_points_free (points);
mv->old_current_index = -1;
}
GtkWidget *
month_view_new (GnomeCalendar *calendar, time_t month)
{
MonthView *mv;
g_return_val_if_fail (calendar != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
mv = gtk_type_new (month_view_get_type ());
mv->calendar = calendar;
month_view_colors_changed (mv);
month_view_set (mv, month);
return GTK_WIDGET (mv);
}
static void
month_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (requisition != NULL);
if (GTK_WIDGET_CLASS (parent_class)->size_request)
(* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
requisition->width = 200;
requisition->height = 150;
}
/* Adjusts the text items for events in the month view to the appropriate size. It also makes the
* corresponding arrows visible or invisible, as appropriate.
*/
static void
adjust_children (MonthView *mv)
{
int i;
GnomeCanvasItem *item;
double x1, y1, x2, y2;
GtkArg arg;
for (i = 0; i < 42; i++) {
/* Get dimensions of the day group */
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_GROUP);
gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2);
/* Normalize and add paddings */
x2 -= x1 + EVENT_PADDING;
x1 = EVENT_PADDING;
y2 -= y1 + EVENT_PADDING;
y1 = EVENT_PADDING;
/* Add height of day label to y1 */
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_LABEL);
arg.name = "text_height";
gtk_object_getv (GTK_OBJECT (item), 1, &arg);
y1 += GTK_VALUE_DOUBLE (arg);
/* Set the position and clip size */
gnome_canvas_item_set (mv->text[i],
"x", x1,
"y", y1,
"clip_width", x2 - x1,
"clip_height", y2 - y1,
"x_offset", 0.0,
"y_offset", 0.0,
NULL);
/* See what visibility state the arrows should be set to */
check_arrow_visibility (mv, i);
}
}
static void
month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
MonthView *mv;
GdkFont *font;
GtkArg arg;
int y;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_MONTH_VIEW (widget));
g_return_if_fail (allocation != NULL);
mv = MONTH_VIEW (widget);
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
(* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
gnome_canvas_set_scroll_region (GNOME_CANVAS (mv), 0, 0, allocation->width, allocation->height);
/* Adjust items to new size */
arg.name = "font_gdk";
gtk_object_getv (GTK_OBJECT (mv->title), 1, &arg);
font = GTK_VALUE_BOXED (arg);
gnome_canvas_item_set (mv->title,
"x", (double) allocation->width / 2.0,
"y", (double) SPACING,
NULL);
y = font->ascent + font->descent + 2 * SPACING;
gnome_canvas_item_set (mv->mitem,
"y", (double) y,
"width", (double) (allocation->width - 1),
"height", (double) (allocation->height - y - 1),
NULL);
/* Adjust children */
adjust_children (mv);
}
/* This defines the environment for the calendar iterator function that is used to populate the
* month view with events.
*/
struct iter_info {
MonthView *mv; /* The month view we are creating children for */
int first_day_index; /* Index of the first day of the month within the month item */
time_t month_begin, month_end; /* Beginning and end of month */
GString **strings; /* Array of strings to populate */
};
/* This is the calendar iterator function used to populate the string array with event information.
* For each event, it iterates through all the days that the event touches and appends the proper
* information to the string array in the iter_info structure.
*/
static int
add_event (iCalObject *ico, time_t start, time_t end, void *data)
{
struct iter_info *ii;
struct tm tm;
time_t t;
time_t day_begin_time, day_end_time;
ii = data;
/* Get the first day of the event */
t = MAX (start, ii->month_begin);
day_begin_time = time_day_begin (t);
day_end_time = time_day_end (day_begin_time);
/* Loop until the event ends or the month ends. For each day touched, append the proper
* information to the corresponding string.
*/
do {
tm = *localtime (&day_begin_time);
g_string_sprintfa (ii->strings[ii->first_day_index + tm.tm_mday - 1], "%s\n", ico->summary);
/* Next day */
day_begin_time = time_add_day (day_begin_time, 1);
day_end_time = time_day_end (day_begin_time);
} while ((end > day_begin_time) && (day_begin_time < ii->month_end));
return TRUE; /* this means we are not finished yet with event generation */
}
void
month_view_update (MonthView *mv, iCalObject *object, int flags)
{
struct iter_info ii;
GString *strings[42];
int i;
time_t t;
g_return_if_fail (mv != NULL);
g_return_if_fail (IS_MONTH_VIEW (mv));
ii.mv = mv;
/* Create an array of empty GStrings */
ii.strings = strings;
for (i = 0; i < 42; i++)
strings[i] = g_string_new (NULL);
ii.first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), 1);
g_assert (ii.first_day_index != -1);
/* Populate the array of strings with events */
t = time_from_day (mv->year, mv->month, 1);
ii.month_begin = time_month_begin (t);
ii.month_end = time_month_end (t);
calendar_iterate (mv->calendar,
ii.month_begin, ii.month_end, add_event, &ii);
for (i = 0; i < 42; i++) {
/* Delete the last character if it is a newline */
if (strings[i]->str && strings[i]->len && (strings[i]->str[strings[i]->len - 1] == '\n'))
g_string_truncate (strings[i], strings[i]->len - 1);
gnome_canvas_item_set (mv->text[i],
"text", strings[i]->str,
NULL);
g_string_free (strings[i], TRUE);
}
/* Adjust children for scrolling */
adjust_children (mv);
}
/* Unmarks the old day that was marked as current and marks the current day if appropriate */
static void
mark_current_day (MonthView *mv)
{
time_t t;
struct tm tm;
GnomeCanvasItem *item;
/* Unmark the old day */
if (mv->old_current_index != -1) {
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem),
GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index);
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
"fontset", BIG_NORMAL_DAY_FONTSET,
NULL);
mv->old_current_index = -1;
}
/* Mark the new day */
t = time (NULL);
tm = *localtime (&t);
if (((tm.tm_year + 1900) == mv->year) && (tm.tm_mon == mv->month)) {
mv->old_current_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), tm.tm_mday);
g_assert (mv->old_current_index != -1);
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem),
GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index);
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG),
"fontset", BIG_CURRENT_DAY_FONTSET,
NULL);
}
}
void
month_view_set (MonthView *mv, time_t month)
{
struct tm tm;
char buf[100];
g_return_if_fail (mv != NULL);
g_return_if_fail (IS_MONTH_VIEW (mv));
/* Title */
tm = *localtime (&month);
mv->year = tm.tm_year + 1900;
mv->month = tm.tm_mon;
strftime (buf, 100, _("%B %Y"), &tm);
gnome_canvas_item_set (mv->title,
"text", buf,
NULL);
/* Month item */
gnome_canvas_item_set (mv->mitem,
"year", mv->year,
"month", mv->month,
NULL);
/* Update events */
month_view_update (mv, NULL, 0);
mark_current_day (mv);
}
void
month_view_time_format_changed (MonthView *mv)
{
g_return_if_fail (mv != NULL);
g_return_if_fail (IS_MONTH_VIEW (mv));
gnome_canvas_item_set (mv->mitem,
"start_on_monday", week_starts_on_monday,
NULL);
month_view_set (mv, time_month_begin (time_from_day (mv->year, mv->month, 1)));
}
void
month_view_colors_changed (MonthView *mv)
{
g_return_if_fail (mv != NULL);
g_return_if_fail (IS_MONTH_VIEW (mv));
colorify_month_item (GNOME_MONTH_ITEM (mv->mitem), default_color_func, NULL);
mark_current_day (mv);
/* FIXME: set children to the marked color */
}

View File

@ -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

1186
calendar/gui/print.c Normal file

File diff suppressed because it is too large Load Diff

22
calendar/gui/print.h Normal file
View File

@ -0,0 +1,22 @@
/* Evolution calendar - Print support
*
* Copyright (C) 2000 Helix Code, Inc.
*
* Authors: Michael Zucchi <notzed@helixcode.com>
* Federico Mena-Quintero <federico@helixcode.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/

View File

@ -1,284 +0,0 @@
/* Quick view widget for Gnomecal
*
* Copyright (C) 1998 The Free Software Foundation
*
* Author: Federico Mena <federico@nuclecu.unam.mx
*/
#include <config.h>
#include <gdk_imlib.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkhseparator.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkvbox.h>
#include <libgnomeui/gnome-canvas.h>
#include <libgnomeui/gnome-canvas-text.h>
#include <libgnomeui/gnome-uidefs.h>
#include "quick-view.h"
#include "calendar-commands.h"
#define QUICK_VIEW_FONTSET "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*,-cronyx-helvetica-medium-r-normal-*-11-*-*-*-p-*-koi8-r,-*-*-medium-r-normal--10-*-*-*-*-*-ksc5601.1987-0,*"
static void quick_view_class_init (QuickViewClass *class);
static void quick_view_init (QuickView *qv);
static gint quick_view_button_release (GtkWidget *widget, GdkEventButton *event);
static gint quick_view_map_event (GtkWidget *widget, GdkEventAny *event);
static GtkWindowClass *parent_class;
GtkType
quick_view_get_type (void)
{
static GtkType quick_view_type = 0;
if (!quick_view_type) {
GtkTypeInfo quick_view_info = {
"QuickView",
sizeof (QuickView),
sizeof (QuickViewClass),
(GtkClassInitFunc) quick_view_class_init,
(GtkObjectInitFunc) quick_view_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
quick_view_type = gtk_type_unique (gtk_window_get_type (), &quick_view_info);
}
return quick_view_type;
}
static void
quick_view_class_init (QuickViewClass *class)
{
GtkWidgetClass *widget_class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_window_get_type ());
widget_class->button_release_event = quick_view_button_release;
widget_class->map_event = quick_view_map_event;
}
static void
quick_view_init (QuickView *qv)
{
GTK_WINDOW (qv)->type = GTK_WINDOW_POPUP;
gtk_window_set_position (GTK_WINDOW (qv), GTK_WIN_POS_MOUSE);
}
static gint
quick_view_button_release (GtkWidget *widget, GdkEventButton *event)
{
QuickView *qv;
qv = QUICK_VIEW (widget);
if (event->button != qv->button)
return FALSE;
gdk_pointer_ungrab (event->time);
gtk_grab_remove (GTK_WIDGET (qv));
gtk_widget_hide (GTK_WIDGET (qv));
gtk_main_quit (); /* End modality of the quick view */
return TRUE;
}
static gint
quick_view_map_event (GtkWidget *widget, GdkEventAny *event)
{
GdkCursor *cursor;
cursor = gdk_cursor_new (GDK_ARROW);
gdk_pointer_grab (widget->window,
TRUE,
GDK_BUTTON_RELEASE_MASK,
NULL,
cursor,
GDK_CURRENT_TIME);
gdk_cursor_destroy (cursor);
return FALSE;
}
/* Creates the items corresponding to a single calendar object. Takes in the y position of the
* items to create and returns the y position of the next item to create. Also takes in the current
* maximum width for items and returns the new maximum width.
*/
static void
create_items_for_event (QuickView *qv, CalendarObject *co, double *y, double *max_width)
{
GnomeCanvas *canvas;
GnomeCanvasItem *item;
char start[100], end[100];
struct tm start_tm, end_tm;
char *str;
GtkArg args[2];
/* FIXME: make this nice */
canvas = GNOME_CANVAS (qv->canvas);
start_tm = *localtime (&co->ev_start);
end_tm = *localtime (&co->ev_end);
if (am_pm_flag) {
strftime (start, sizeof (start), "%I:%M%p", &start_tm);
strftime (end, sizeof (end), "%I:%M%p", &end_tm);
} else {
strftime (start, sizeof (start), "%H:%M", &start_tm);
strftime (end, sizeof (end), "%H:%M", &end_tm);
}
str = g_strconcat (start, " - ", end, " ", co->ico->summary, NULL);
item = gnome_canvas_item_new (gnome_canvas_root (canvas),
gnome_canvas_text_get_type (),
"x", 0.0,
"y", *y,
"anchor", GTK_ANCHOR_NW,
"text", str,
"fontset", QUICK_VIEW_FONTSET,
NULL);
g_free (str);
/* Measure the text and return the proper size values */
args[0].name = "text_width";
args[1].name = "text_height";
gtk_object_getv (GTK_OBJECT (item), 2, args);
if (GTK_VALUE_DOUBLE (args[0]) > *max_width)
*max_width = GTK_VALUE_DOUBLE (args[0]);
*y += GTK_VALUE_DOUBLE (args[1]);
}
/* Creates the canvas items corresponding to the events in the list */
static void
setup_event_list (QuickView *qv, GList *event_list)
{
CalendarObject *co;
GnomeCanvasItem *item;
GtkArg args[2];
double y, max_width;
/* If there are no events, then just put a simple label */
if (!event_list) {
item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (qv->canvas)),
gnome_canvas_text_get_type (),
"x", 0.0,
"y", 0.0,
"anchor", GTK_ANCHOR_NW,
"text", _("No appointments for this day"),
"fontset", QUICK_VIEW_FONTSET,
NULL);
/* Measure the text and set the proper sizes */
args[0].name = "text_width";
args[1].name = "text_height";
gtk_object_getv (GTK_OBJECT (item), 2, args);
y = GTK_VALUE_DOUBLE (args[1]);
max_width = GTK_VALUE_DOUBLE (args[0]);
} else {
/* Create the items for all the events in the list */
y = 0.0;
max_width = 0.0;
for (; event_list; event_list = event_list->next) {
co = event_list->data;
create_items_for_event (qv, co, &y, &max_width);
}
}
/* Set the scrolling region to fit all the items */
gnome_canvas_set_scroll_region (GNOME_CANVAS (qv->canvas),
0.0, 0.0,
max_width, y);
gtk_widget_set_usize (qv->canvas, max_width, y);
}
GtkWidget *
quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list)
{
QuickView *qv;
GtkWidget *vbox;
GtkWidget *w;
g_return_val_if_fail (calendar != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
qv = gtk_type_new (quick_view_get_type ());
qv->calendar = calendar;
/* Create base widgets for the popup window */
w = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_ETCHED_OUT);
gtk_container_add (GTK_CONTAINER (qv), w);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (w), vbox);
w = gtk_label_new (title);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
w = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (w), GNOME_PAD_SMALL);
gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
gtk_widget_push_visual (gdk_imlib_get_visual ());
gtk_widget_push_colormap (gdk_imlib_get_colormap ());
qv->canvas = gnome_canvas_new ();
gtk_widget_pop_colormap ();
gtk_widget_pop_visual ();
gtk_container_add (GTK_CONTAINER (w), qv->canvas);
/* Set up the event list */
setup_event_list (qv, event_list);
return GTK_WIDGET (qv);
}
void
quick_view_do_popup (QuickView *qv, GdkEventButton *event)
{
g_return_if_fail (qv != NULL);
g_return_if_fail (IS_QUICK_VIEW (qv));
g_return_if_fail (event != NULL);
/* Pop up the window */
gtk_widget_show_all (GTK_WIDGET (qv));
gtk_grab_add (GTK_WIDGET (qv));
qv->button = event->button;
gtk_main (); /* Begin modality */
/* The button release event handler will call gtk_main_quit() */
}

View File

@ -1,60 +0,0 @@
/* Quick view widget for Gnomecal
*
* Copyright (C) 1998 The Free Software Foundation
*
* Author: Federico Mena <federico@nuclecu.unam.mx
*/
#ifndef QUICK_VIEW_H
#define QUICK_VIEW_H
#include <libgnome/gnome-defs.h>
#include <gtk/gtkwindow.h>
#include "gnome-cal.h"
BEGIN_GNOME_DECLS
#define TYPE_QUICK_VIEW (quick_view_get_type ())
#define QUICK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_QUICK_VIEW, QuickView))
#define QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_QUICK_VIEW, QuickViewClass))
#define IS_QUICK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_QUICK_VIEW))
#define IS_QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_QUICK_VIEW))
typedef struct _QuickView QuickView;
typedef struct _QuickViewClass QuickViewClass;
struct _QuickView {
GtkWindow window;
GnomeCalendar *calendar; /* The calendar we are associated to */
GtkWidget *canvas; /* The canvas that displays the contents of the quick view */
int button; /* The button that was pressed to pop up the quick view */
};
struct _QuickViewClass {
GtkWindowClass parent_class;
};
/* Standard Gtk function */
GtkType quick_view_get_type (void);
/* Creates a new quick view with the specified title and the specified event list. It is associated
* to the specified calendar. The event list must be a list of CalendarObject structures.
*/
GtkWidget *quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list);
/* Pops up the quick view widget modally and loops until the uses closes it by releasing the mouse
* button. You can destroy the quick view when this function returns.
*/
void quick_view_do_popup (QuickView *qv, GdkEventButton *event);
END_GNOME_DECLS
#endif

View File

@ -1,744 +0,0 @@
/* Year view display for gncal
*
* Copyright (C) 1998 The Free Software Foundation
*
* Authors: Arturo Espinosa <arturo@nuclecu.unam.mx>
* Federico Mena <federico@nuclecu.unam.mx>
*/
#include <config.h>
#include <gtk/gtkmain.h>
#include <gnome.h>
#include <cal-util/timeutil.h>
#include "eventedit.h"
#include "year-view.h"
#include "calendar-commands.h"
#include "mark.h"
#include "quick-view.h"
#define HEAD_SPACING 4 /* Spacing between year heading and months */
#define TITLE_SPACING 1 /* Spacing between title and calendar */
#define SPACING 4 /* Spacing between months */
static void year_view_class_init (YearViewClass *class);
static void year_view_init (YearView *yv);
static void year_view_destroy (GtkObject *object);
static void year_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void year_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static GnomeCanvas *parent_class;
GtkType
year_view_get_type (void)
{
static GtkType year_view_type = 0;
if (!year_view_type) {
GtkTypeInfo year_view_info = {
"YearView",
sizeof (YearView),
sizeof (YearViewClass),
(GtkClassInitFunc) year_view_class_init,
(GtkObjectInitFunc) year_view_init,
NULL, /* reserved_1 */
NULL, /* reserved_2 */
(GtkClassInitFunc) NULL
};
year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info);
}
return year_view_type;
}
static void
year_view_class_init (YearViewClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gnome_canvas_get_type ());
object_class->destroy = year_view_destroy;
widget_class->size_request = year_view_size_request;
widget_class->size_allocate = year_view_size_allocate;
}
/* Resizes the year view's child items. This is done in the idle loop for
* performance (we avoid resizing on every size allocation).
*/
static gint
idle_handler (gpointer data)
{
YearView *yv;
GtkArg arg;
double head_height;
double title_height;
double width, height;
double month_width;
double month_height;
double month_yofs;
double xofs, yofs;
double x, y;
int i;
yv = data;
/* Compute the size we can use */
width = MAX (GTK_WIDGET (yv)->allocation.width, yv->min_width);
height = MAX (GTK_WIDGET (yv)->allocation.height, yv->min_height);
gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, width, height);
width--;
height--;
/* Get the heights of the heading and the titles */
arg.name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg);
head_height = GTK_VALUE_DOUBLE (arg) + 2 * HEAD_SPACING;
arg.name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg);
title_height = GTK_VALUE_DOUBLE (arg);
/* Offsets */
xofs = (width + SPACING) / 3.0;
yofs = (height - head_height + SPACING) / 4.0;
/* Month item vertical offset */
month_yofs = title_height + TITLE_SPACING;
/* Month item dimensions */
month_width = (width - 2 * SPACING) / 3.0;
month_height = (yofs - SPACING) - month_yofs;
/* Adjust the year heading */
gnome_canvas_item_set (yv->heading,
"x", width / 2.0,
"y", (double) HEAD_SPACING,
NULL);
/* Adjust titles and months */
for (i = 0; i < 12; i++) {
x = (i % 3) * xofs;
y = head_height + (i / 3) * yofs;
gnome_canvas_item_set (yv->titles[i],
"x", x + month_width / 2.0,
"y", y,
NULL);
gnome_canvas_item_set (yv->mitems[i],
"x", x,
"y", y + month_yofs,
"width", month_width,
"height", month_height,
NULL);
}
/* Done */
yv->need_resize = FALSE;
return FALSE;
}
/* Marks the year view as needing a resize, which will be performed during the idle loop */
static void
need_resize (YearView *yv)
{
if (yv->need_resize)
return;
yv->need_resize = TRUE;
yv->idle_id = gtk_idle_add (idle_handler, yv);
}
/* Callback used to destroy the year view's popup menu when the year view itself is destroyed */
static void
destroy_menu (GtkWidget *widget, gpointer data)
{
gtk_widget_destroy (GTK_WIDGET (data));
}
/* Create a new appointment in the highlighted day from the year view's popup menu */
static void
new_appointment (GtkWidget *widget, gpointer data)
{
YearView *yv;
time_t *t;
yv = YEAR_VIEW (data);
t = gtk_object_get_data (GTK_OBJECT (widget), "time_data");
event_editor_new_whole_day (yv->calendar, *t);
}
/* Convenience functions to jump to a view and set the time */
static void
do_jump (GtkWidget *widget, gpointer data, char *view_name)
{
YearView *yv;
time_t *t;
yv = YEAR_VIEW (data);
/* Get the time data from the menu item */
t = gtk_object_get_data (GTK_OBJECT (widget), "time_data");
/* Set the view and time */
gnome_calendar_set_view (yv->calendar, view_name);
gnome_calendar_goto (yv->calendar, *t);
}
/* The following three callbacks set the view in the calendar and change the time */
static void
jump_to_day (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "dayview");
}
static void
jump_to_week (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "weekview");
}
static void
jump_to_month (GtkWidget *widget, gpointer data)
{
do_jump (widget, data, "monthview");
}
/* Information for the year view's popup menu */
static GnomeUIInfo yv_popup_menu[] = {
GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _month"), NULL, jump_to_month, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_END
};
/* Returns the popup menu cooresponding to the specified year view. If the menu has not been
* created yet, it creates it and attaches it to the year view.
*/
static GtkWidget *
get_popup_menu (YearView *yv)
{
GtkWidget *menu;
menu = gtk_object_get_data (GTK_OBJECT (yv), "popup_menu");
if (!menu) {
menu = gnome_popup_menu_new (yv_popup_menu);
gtk_object_set_data (GTK_OBJECT (yv), "popup_menu", menu);
gtk_signal_connect (GTK_OBJECT (yv), "destroy",
(GtkSignalFunc) destroy_menu,
menu);
}
return menu;
}
/* Executes the year view's popup menu. It may disable/enable some menu items based on the
* specified flags. A pointer to a time_t value containing the specified time data is set in the
* "time_data" object data key of the menu items.
*/
static void
do_popup_menu (YearView *yv, GdkEventButton *event, int allow_new, int allow_day, int allow_week, int allow_month,
int year, int month, int day)
{
GtkWidget *menu;
static time_t t;
menu = get_popup_menu (yv);
/* Enable/disable items as appropriate */
gtk_widget_set_sensitive (yv_popup_menu[0].widget, allow_new);
gtk_widget_set_sensitive (yv_popup_menu[2].widget, allow_day);
gtk_widget_set_sensitive (yv_popup_menu[3].widget, allow_week);
gtk_widget_set_sensitive (yv_popup_menu[4].widget, allow_month);
/* Set the day item relevant to the context */
t = time_from_day (year, month, day);
gtk_object_set_data (GTK_OBJECT (yv_popup_menu[0].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (yv_popup_menu[2].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (yv_popup_menu[3].widget), "time_data", &t);
gtk_object_set_data (GTK_OBJECT (yv_popup_menu[4].widget), "time_data", &t);
gnome_popup_menu_do_popup (menu, NULL, NULL, event, yv);
}
/* Creates the quick view when the user clicks on a day */
static void
do_quick_view_popup (YearView *yv, GdkEventButton *event, int year, int month, int day)
{
time_t day_start, day_end;
GList *list;
GtkWidget *qv;
char date_str[256];
day_start = time_from_day (year, month, day);
day_end = time_day_end (day_start);
list = calendar_get_events_in_range (yv->calendar->client,
day_start, day_end);
strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), localtime (&day_start));
qv = quick_view_new (yv->calendar, date_str, list);
quick_view_do_popup (QUICK_VIEW (qv), event);
gtk_widget_destroy (qv);
/* calendar_destroy_event_list (list); DELETE */
}
/* Event handler for days in the year's month items */
static gint
day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
YearView *yv;
GnomeMonthItem *mitem;
int child_num, day;
mitem = GNOME_MONTH_ITEM (data);
child_num = gnome_month_item_child2num (mitem, item);
day = gnome_month_item_num2day (mitem, child_num);
yv = YEAR_VIEW (item->canvas);
switch (event->type) {
case GDK_BUTTON_PRESS:
if (day == 0)
break;
if (event->button.button == 1) {
do_quick_view_popup (yv, (GdkEventButton *) event, mitem->year, mitem->month, day);
return TRUE;
} else if (event->button.button == 3) {
do_popup_menu (yv, (GdkEventButton *) event, TRUE, TRUE, TRUE, TRUE,
mitem->year, mitem->month, day);
/* We have to stop the signal emission because mark.c will grab it too and
* set the return value to FALSE. Blargh.
*/
gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event");
return TRUE;
}
break;
default:
break;
}
return FALSE;
}
/* Event handler for whole month items */
static gint
month_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
YearView *yv;
GnomeMonthItem *mitem;
mitem = GNOME_MONTH_ITEM (item);
yv = YEAR_VIEW (item->canvas);
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button != 3)
break;
do_popup_menu (yv, (GdkEventButton *) event, FALSE, FALSE, FALSE, TRUE,
mitem->year, mitem->month, 1);
/* We have to stop the signal emission because mark.c will grab it too and
* set the return value to FALSE. Blargh.
*/
gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event");
return TRUE;
default:
break;
}
return FALSE;
}
/* Sets up the month item with the specified index -- connects signals for handling events, etc. */
static void
setup_month_item (YearView *yv, int n)
{
GnomeCanvasItem *mitem;
GnomeCanvasItem *item;
int i;
mitem = yv->mitems[n];
/* Connect the day signals */
for (i = 0; i < 42; i++) {
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i);
gtk_signal_connect (GTK_OBJECT (item), "event",
(GtkSignalFunc) day_event,
mitem);
}
/* Connect the month signals */
gtk_signal_connect (GTK_OBJECT (mitem), "event",
(GtkSignalFunc) month_event,
NULL);
/* Prepare for prelighting */
month_item_prepare_prelight (GNOME_MONTH_ITEM (mitem), default_color_func, NULL);
}
/* Computes the minimum size for the year view and stores it in its internal fields */
static void
compute_min_size (YearView *yv)
{
GtkArg args[2];
double m_width;
double m_height;
double max_width;
double w;
int i;
/* Compute the minimum size of the year heading */
args[0].name = "text_width";
args[1].name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->heading), 2, args);
m_width = GTK_VALUE_DOUBLE (args[0]);
m_height = 2 * HEAD_SPACING + GTK_VALUE_DOUBLE (args[1]);
/* Add height of month titles and their spacings */
args[0].name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &args[0]);
m_height += 4 * (GTK_VALUE_DOUBLE (args[0]) + TITLE_SPACING);
/* Add width of month titles */
max_width = 0.0;
for (i = 0; i < 12; i++) {
args[0].name = "text_width";
gtk_object_getv (GTK_OBJECT (yv->titles[i]), 1, &args[0]);
w = GTK_VALUE_DOUBLE (args[0]);
if (max_width < w)
max_width = w;
}
max_width = 3 * max_width + 2 * SPACING;
if (m_width < max_width)
m_width = max_width;
/* Add width of month items */
args[0].name = "width";
args[1].name = "height";
gtk_object_getv (GTK_OBJECT (yv->mitems[0]), 2, args);
max_width = 3 * GTK_VALUE_DOUBLE (args[0]) + 2 * SPACING;
if (m_width < max_width)
m_width = max_width;
/* Add height of month items */
m_height += 4 * GTK_VALUE_DOUBLE (args[1]) + 3 * SPACING;
/* Finally, set the minimum width and height in the year view */
yv->min_width = (int) (m_width + 0.5);
yv->min_height = (int) (m_height + 0.5);
}
static void
year_view_init (YearView *yv)
{
int i;
char buf[100];
struct tm tm;
memset (&tm, 0, sizeof (tm));
/* Heading */
yv->heading = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)),
gnome_canvas_text_get_type (),
"anchor", GTK_ANCHOR_N,
"fontset", HEADING_FONTSET,
"fill_color", "black",
NULL);
/* Months */
for (i = 0; i < 12; i++) {
/* Title */
strftime (buf, 100, "%B", &tm);
tm.tm_mon++;
yv->titles[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)),
gnome_canvas_text_get_type (),
"text", buf,
"anchor", GTK_ANCHOR_N,
"fontset", TITLE_FONTSET,
"fill_color", "black",
NULL);
/* Month item */
yv->mitems[i] = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (yv)));
gnome_canvas_item_set (yv->mitems[i],
"anchor", GTK_ANCHOR_NW,
"start_on_monday", week_starts_on_monday,
"heading_fontset", DAY_HEADING_FONTSET,
"day_fontset", NORMAL_DAY_FONTSET,
NULL);
setup_month_item (yv, i);
}
/* We will need to resize the items when we paint for the first time */
yv->old_marked_day = -1;
yv->idle_id = -1;
need_resize (yv);
}
static void
year_view_destroy (GtkObject *object)
{
YearView *yv;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_YEAR_VIEW (object));
yv = YEAR_VIEW (object);
if (yv->need_resize) {
yv->need_resize = FALSE;
gtk_idle_remove (yv->idle_id);
}
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
GtkWidget *
year_view_new (GnomeCalendar *calendar, time_t year)
{
YearView *yv;
g_return_val_if_fail (calendar != NULL, NULL);
g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL);
yv = gtk_type_new (year_view_get_type ());
yv->calendar = calendar;
year_view_colors_changed (yv);
year_view_set (yv, year);
compute_min_size (yv);
return GTK_WIDGET (yv);
}
static void
year_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
YearView *yv;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_YEAR_VIEW (widget));
g_return_if_fail (requisition != NULL);
yv = YEAR_VIEW (widget);
requisition->width = yv->min_width;
requisition->height = yv->min_height;
}
static void
year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
YearView *yv;
g_return_if_fail (widget != NULL);
g_return_if_fail (IS_YEAR_VIEW (widget));
g_return_if_fail (allocation != NULL);
yv = YEAR_VIEW (widget);
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
(* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);
need_resize (yv);
}
void
year_view_update (YearView *yv, iCalObject *object, int flags)
{
g_return_if_fail (yv != NULL);
g_return_if_fail (IS_YEAR_VIEW (yv));
/* If only the summary changed, we don't care */
if (object && ((flags & CHANGE_SUMMARY) == flags))
return;
year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
/* Unmarks the old day that was marked as current and marks the current day if appropriate */
static void
mark_current_day (YearView *yv)
{
time_t t;
struct tm tm;
int month_index, day_index;
GnomeCanvasItem *item;
/* Unmark the old day */
if (yv->old_marked_day != -1) {
month_index = yv->old_marked_day / 42;
day_index = yv->old_marked_day % 42;
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]),
GNOME_MONTH_ITEM_DAY_LABEL + day_index);
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
"fontset", NORMAL_DAY_FONTSET,
NULL);
yv->old_marked_day = -1;
}
/* Mark the new day */
t = time (NULL);
tm = *localtime (&t);
if ((tm.tm_year + 1900) == yv->year) {
month_index = tm.tm_mon;
day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (yv->mitems[month_index]), tm.tm_mday);
g_assert (day_index != -1);
item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]),
GNOME_MONTH_ITEM_DAY_LABEL + day_index);
gnome_canvas_item_set (item,
"fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG),
"fontset", CURRENT_DAY_FONTSET,
NULL);
yv->old_marked_day = month_index * 42 + day_index;
}
}
void
year_view_set (YearView *yv, time_t year)
{
struct tm tm;
char buf[100];
int i;
g_return_if_fail (yv != NULL);
g_return_if_fail (IS_YEAR_VIEW (yv));
tm = *localtime (&year);
yv->year = tm.tm_year + 1900;
/* Heading */
sprintf (buf, "%d", yv->year);
gnome_canvas_item_set (yv->heading,
"text", buf,
NULL);
/* Months */
for (i = 0; i < 12; i++)
gnome_canvas_item_set (yv->mitems[i],
"year", yv->year,
"month", i,
NULL);
/* Unmark and re-mark all the months */
for (i = 0; i < 12; i++) {
unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]));
mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]),
yv->calendar);
}
mark_current_day (yv);
}
void
year_view_time_format_changed (YearView *yv)
{
int i;
g_return_if_fail (yv != NULL);
g_return_if_fail (IS_YEAR_VIEW (yv));
for (i = 0; i < 12; i++)
gnome_canvas_item_set (yv->mitems[i],
"start_on_monday", week_starts_on_monday,
NULL);
year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
void
year_view_colors_changed (YearView *yv)
{
int i;
g_return_if_fail (yv != NULL);
g_return_if_fail (IS_YEAR_VIEW (yv));
for (i = 0; i < 12; i++) {
colorify_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), default_color_func, NULL);
mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]),
yv->calendar);
}
mark_current_day (yv);
}

View File

@ -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

View File

@ -1,3 +1,19 @@
2000-05-23 Federico Mena Quintero <federico@helixcode.com>
* e-dialog-widgets.c (get_radio_value): Implemented. Amazing that
one has to go through so much pain to get a stupid value from
GTK+.
(hook_option_menu): Implemented. Same complaint.
(get_toggle_value): Implemented.
(get_spin_button_value): Implemented.
(get_entry_value): Implemented.
(e_dialog_widget_hook_value): Function to hook a widget to the
variable it will modify.
(e_dialog_get_values): Function to feed the variables from a
dialog's widgets.
(e_dialog_xml_widget_hook_value): Function to hook a widget from
a Glade file.
2000-05-23 Christopher James Lahey <clahey@helixcode.com>
* e-util.c, e-util.h: Added e_write_file.

View File

@ -30,9 +30,16 @@
/* A widget, a pointer to the variable it will modify, and extra information */
typedef struct {
/* Widgets that are hooked */
GSList *widgets;
GtkWidget *widget;
gpointer value_var;
gpointer info;
} WidgetHook;
/* Hook information for a complete dialog */
typedef struct {
GSList *whooks;
} DialogHooks;
@ -45,8 +52,8 @@ dialog_destroy_cb (GtkObject *dialog, gpointer data)
hooks = data;
g_slist_free (hooks->widgets);
hooks->widgets = NULL;
g_slist_free (hooks->whooks);
hooks->whooks = NULL;
g_free (hooks);
gtk_object_set_data (dialog, "dialog-hooks", NULL);
@ -156,6 +163,41 @@ hook_radio (GtkWidget *dialog, GtkRadioButton *radio, gpointer value_var, gpoint
GTK_SIGNAL_FUNC (toggled_cb), dialog);
}
/* Gets the value of a radio button group */
static void
get_radio_value (GtkRadioButton *radio, gpointer value_var, gpointer info)
{
GSList *group;
GSList *l;
int i;
int *value;
const int *value_map;
int v;
group = gtk_radio_button_group (radio);
for (i = 0, l = group; l; l = l->next) {
radio = GTK_RADIO_BUTTON (l->data);
if (GTK_TOGGLE_BUTTON (radio)->active)
break;
}
if (!l)
g_assert_not_reached ();
value = (int *) value_var;
value_map = (const int *) info;
v = index_to_value (value_map, i);
if (v == -1) {
g_message ("get_radio_value(): could not find index %d in value map!", i);
return;
}
*value = v;
}
/* Callback for the "activate" signal of menu items */
static void
activate_cb (GtkMenuItem *item, gpointer data)
@ -199,6 +241,46 @@ hook_option_menu (GtkWidget *dialog, GtkOptionMenu *omenu, gpointer value_var, g
}
}
/* Gets the value of an option menu */
static void
get_option_menu_value (GtkOptionMenu *omenu, gpointer value_var, gpointer info)
{
GtkMenu *menu;
GtkWidget *active;
GList *children;
GList *l;
int i;
int *value;
const int *value_map;
int v;
menu = GTK_MENU (gtk_option_menu_get_menu (omenu));
active = gtk_menu_get_active (menu);
g_assert (active != NULL);
children = GTK_MENU_SHELL (menu)->children;
for (i = 0, l = children; l; l = l->next) {
if (GTK_WIDGET (l->data) == active)
break;
}
if (!l)
g_assert_not_reached ();
value = (int *) value_var;
value_map = (const int *) info;
v = index_to_value (value_map, i);
if (v == -1) {
g_message ("get_option_menu_value(): could not find index %d in value map!", i);
return;
}
*value = v;
}
/* Hooks a toggle button */
static void
hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpointer info)
@ -217,6 +299,16 @@ hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpo
GTK_SIGNAL_FUNC (toggled_cb), dialog);
}
/* Gets the value of a toggle button */
static void
get_toggle_value (GtkToggleButton *toggle, gpointer value_var, gpointer info)
{
gboolean *value;
value = (gboolean *) value;
*value = toggle->active ? TRUE : FALSE;
}
/* Callback for the "value_changed" signal of the adjustment of a spin button */
static void
value_changed_cb (GtkAdjustment *adj, gpointer data)
@ -249,10 +341,58 @@ hook_spin_button (GtkWidget *dialog, GtkSpinButton *spin, gpointer value_var, gp
GTK_SIGNAL_FUNC (value_changed_cb), dialog);
}
/* Gets the value of a spin button */
static void
get_spin_button_value (GtkSpinButton *spin, gpointer value_var, gpointer info)
{
double *value;
GtkAdjustment *adj;
value = (double *) value_var;
adj = gtk_spin_button_get_adjustment (spin);
*value = adj->value;
}
/* Callback for the "changed" signal of an entry widget */
static void
changed_cb (GtkEntry *entry, gpointer data)
{
GnomePropertyBox *pbox;
pbox = GNOME_PROPERTY_BOX (data);
gnome_property_box_changed (pbox);
}
/* Hooks an entry widget */
static void
hook_entry (GtkWidget *dialog, GtkEntry *entry, gpointer value_var, gpointer info)
{
char **value;
/* Set the value */
value = (char **) value_var;
gtk_entry_set_text (entry, *value);
/* Hook to changed */
if (GNOME_IS_PROPERTY_BOX (dialog))
gtk_signal_connect (GTK_OBJECT (entry), "changed",
GTK_SIGNAL_FUNC (changed_cb), dialog);
}
/* Gets the value of an entry widget */
static void
get_entry_value (GtkEntry *entry, gpointer value_var, gpointer data)
{
char **value;
value = (char **) value_var;
if (*value)
g_free (*value);
*value = g_strdup (gtk_entry_get_text (entry));
}
gboolean
@ -260,6 +400,7 @@ e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget,
gpointer value_var, gpointer info)
{
DialogHooks *hooks;
WidgetHook *wh;
g_return_val_if_fail (dialog != NULL, FALSE);
g_return_val_if_fail (widget != NULL, FALSE);
@ -285,7 +426,64 @@ e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget,
else
return FALSE;
hooks->widgets = g_slist_prepend (hooks->widgets, widget);
wh = g_new (WidgetHook, 1);
wh->widget = widget;
wh->value_var = value_var;
wh->info = info;
hooks->whooks = g_slist_prepend (hooks->whooks, wh);
return TRUE;
}
void
e_dialog_get_values (GtkWidget *dialog)
{
DialogHooks *hooks;
GSList *l;
g_return_if_fail (dialog != NULL);
hooks = get_dialog_hooks (dialog);
for (l = hooks->whooks; l; l = l->next) {
WidgetHook *wh;
wh = l->data;
if (GTK_IS_RADIO_BUTTON (wh->widget))
get_radio_value (GTK_RADIO_BUTTON (wh->widget), wh->value_var, wh->info);
else if (GTK_IS_OPTION_MENU (wh->widget))
get_option_menu_value (GTK_OPTION_MENU (wh->widget), wh->value_var, wh->info);
else if (GTK_IS_TOGGLE_BUTTON (wh->widget))
get_toggle_value (GTK_TOGGLE_BUTTON (wh->widget), wh->value_var, wh->info);
else if (GTK_IS_SPIN_BUTTON (wh->widget))
get_spin_button_value (GTK_SPIN_BUTTON (wh->widget), wh->value_var, wh->info);
else if (GTK_IS_ENTRY (wh->widget))
get_entry_value (GTK_ENTRY (wh->widget), wh->value_var, wh->info);
else
g_assert_not_reached ();
}
}
gboolean
e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const char *widget_name,
gpointer value_var, gpointer info)
{
GtkWidget *widget;
g_return_val_if_fail (xml != NULL, FALSE);
g_return_val_if_fail (GLADE_IS_XML (xml), FALSE);
g_return_val_if_fail (dialog != NULL, FALSE);
g_return_val_if_fail (widget_name != NULL, FALSE);
g_return_val_if_fail (value_var != NULL, FALSE);
widget = glade_xml_get_widget (xml, widget_name);
if (!widget) {
g_message ("e_dialog_xml_widget_hook_value(): could not find widget `%s' in "
"Glade data!", widget_name);
return FALSE;
}
return e_dialog_widget_hook_value (dialog, widget, value_var, info);
}