diff options
Diffstat (limited to 'calendar/gui')
109 files changed, 10192 insertions, 11563 deletions
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index 6b515f442a..e460d3d5ff 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -1,31 +1,9 @@ if OS_WIN32 -WIN32_BOOTSTRAP_LIBS = $(top_builddir)/win32/libevolution-mail-shared.la +WIN32_BOOTSTRAP_LIBS = $(top_builddir)/win32/libevolution-mail.la endif -## CORBA stuff - -IDLS = \ - $(top_srcdir)/calendar/idl/evolution-calendar.idl - -CALENDAR_IDL_GENERATED_H = \ - evolution-calendar.h -CALENDAR_IDL_GENERATED_C = \ - evolution-calendar-common.c \ - evolution-calendar-skels.c \ - evolution-calendar-stubs.c -CALENDAR_IDL_GENERATED = $(CALENDAR_IDL_GENERATED_C) $(CALENDAR_IDL_GENERATED_H) - -$(CALENDAR_IDL_GENERATED_H): $(IDLS) - $(ORBIT_IDL) -I $(srcdir) $(IDL_INCLUDES) \ - $(top_srcdir)/calendar/idl/evolution-calendar.idl -$(CALENDAR_IDL_GENERATED_C): $(CALENDAR_IDL_GENERATED_H) - -IDL_GENERATED = $(CALENDAR_IDL_GENERATED) - SUBDIRS = alarm-notify dialogs -component_LTLIBRARIES = libevolution-calendar.la - ecalendarincludedir = $(privincludedir)/calendar/gui ecalendarinclude_HEADERS = \ @@ -46,7 +24,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/calendar \ -I$(top_srcdir)/widgets \ -I$(top_srcdir)/widgets/misc \ - -I$(top_srcdir)/a11y/calendar \ -DSEARCH_RULE_DIR=\"$(ruledir)\" \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ -DEVOLUTION_ETSPECDIR=\""$(etspecdir)"\" \ @@ -67,35 +44,33 @@ etspec_DATA = \ e-cal-list-view.etspec \ e-memo-table.etspec -libevolution_calendar_la_SOURCES = \ - $(IDL_GENERATED) \ +noinst_LTLIBRARIES = libcal-gui.la + +# Removed from SOURCES +# cal-search-bar.c +# cal-search-bar.h +# gnome-cal.c + +libcal_gui_la_SOURCES = \ e-attachment-handler-calendar.c \ e-attachment-handler-calendar.h \ - cal-search-bar.c \ - cal-search-bar.h \ + e-calendar-view.c \ + e-calendar-view.h \ + e-calendar-table.c \ + e-calendar-table.h \ calendar-config.c \ calendar-config.h \ calendar-config-keys.h \ - calendar-commands.c \ - calendar-commands.h \ - calendar-component.c \ - calendar-component.h \ calendar-view.c \ calendar-view.h \ calendar-view-factory.c \ calendar-view-factory.h \ - comp-editor-factory.c \ - comp-editor-factory.h \ comp-util.c \ comp-util.h \ - control-factory.c \ - control-factory.h \ e-alarm-list.c \ e-alarm-list.h \ e-cal-component-preview.c \ e-cal-component-preview.h \ - e-cal-component-memo-preview.c \ - e-cal-component-memo-preview.h \ e-cal-config.c \ e-cal-config.h \ e-cal-event.c \ @@ -111,18 +86,16 @@ libevolution_calendar_la_SOURCES = \ e-cal-model.h \ e-cal-popup.h \ e-cal-popup.c \ - e-calendar-view.c \ - e-calendar-view.h \ e-cal-list-view.c \ e-cal-list-view.h \ e-cal-list-view-config.c \ e-cal-list-view-config.h \ e-cal-model-memos.c \ e-cal-model-memos.h \ - e-calendar-table.c \ - e-calendar-table.h \ e-calendar-table-config.c \ e-calendar-table-config.h \ + e-calendar-selector.c \ + e-calendar-selector.h \ e-cell-date-edit-config.c \ e-cell-date-edit-config.h \ e-cell-date-edit-text.h \ @@ -160,18 +133,20 @@ libevolution_calendar_la_SOURCES = \ e-meeting-types.h \ e-meeting-utils.c \ e-meeting-utils.h \ + e-memo-list-selector.c \ + e-memo-list-selector.h \ e-memo-table.c \ e-memo-table.h \ e-memo-table-config.c \ e-memo-table-config.h \ - e-memos.c \ - e-memos.h \ e-mini-calendar-config.c \ e-mini-calendar-config.h \ e-select-names-editable.c \ e-select-names-editable.h \ e-select-names-renderer.c \ e-select-names-renderer.h \ + e-task-list-selector.c \ + e-task-list-selector.h \ e-week-view-config.c \ e-week-view-config.h \ e-week-view-event-item.c \ @@ -184,60 +159,68 @@ libevolution_calendar_la_SOURCES = \ e-week-view-titles-item.h \ e-week-view.c \ e-week-view.h \ - e-tasks.c \ - e-tasks.h \ e-timezone-entry.c \ e-timezone-entry.h \ - gnome-cal.c \ - gnome-cal.h \ goto.c \ goto.h \ - itip-bonobo-control.c \ - itip-bonobo-control.h \ + gnome-cal.h \ itip-utils.c \ itip-utils.h \ - main.c \ - memos-component.c \ - memos-component.h \ - memos-control.c \ - memos-control.h \ - migration.c \ - migration.h \ misc.c \ misc.h \ print.c \ print.h \ tag-calendar.c \ tag-calendar.h \ - tasks-component.c \ - tasks-component.h \ - tasks-control.c \ - tasks-control.h \ weekday-picker.c \ weekday-picker.h -libevolution_calendar_la_LIBADD = \ - $(WIN32_BOOTSTRAP_LIBS) \ +# no gnome-cal no a11y. FIXME: KILL-BONOBO +# ea-calendar.c \ +# ea-calendar.h \ +# ea-calendar-helpers.c \ +# ea-calendar-helpers.h \ +# ea-cal-view.c \ +# ea-cal-view.h \ +# ea-cal-view-event.c \ +# ea-cal-view-event.h \ +# ea-day-view.c \ +# ea-day-view.h \ +# ea-day-view-main-item.c \ +# ea-day-view-main-item.h \ +# ea-day-view-cell.c \ +# ea-day-view-cell.h \ +# ea-week-view.c \ +# ea-week-view.h \ +# ea-week-view-main-item.c \ +# ea-week-view-main-item.h \ +# ea-week-view-cell.c \ +# ea-week-view-cell.h \ +# ea-jump-button.c \ +# ea-jump-button.h \ +# ea-gnome-calendar.c \ +# ea-gnome-calendar.h + +libcal_gui_la_LIBADD = \ + $(top_builddir)/composer/libcomposer.la \ + $(top_builddir)/addressbook/gui/contact-editor/libecontacteditor.la \ + $(top_builddir)/addressbook/gui/contact-list-editor/libecontactlisteditor.la \ $(top_builddir)/widgets/menus/libmenus.la \ $(top_builddir)/shell/libeshell.la \ $(top_builddir)/calendar/common/libevolution-calendarprivate.la \ $(top_builddir)/calendar/gui/dialogs/libcal-dialogs.la \ $(top_builddir)/calendar/importers/libevolution-calendar-importers.la \ $(top_builddir)/widgets/e-timezone-dialog/libetimezonedialog.la \ - $(top_builddir)/widgets/misc/libefilterbar.la \ $(top_builddir)/widgets/misc/libemiscwidgets.la \ + $(top_builddir)/widgets/table/libetable.la \ $(top_builddir)/filter/libfilter.la \ $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/a11y/calendar/libevolution-calendar-a11y.la \ $(LIBSOUP_LIBS) \ $(CAMEL_LIBS) \ $(EVOLUTION_CALENDAR_LIBS) -libevolution_calendar_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED) +libcal_gui_la_LDFLAGS = -avoid-version -module $(NO_UNDEFINED) -server_in_files = GNOME_Evolution_Calendar.server.in.in -server_DATA = $(server_in_files:.server.in.in=.server) -@EVO_SERVER_RULE@ @INTLTOOL_SERVER_RULE@ # GConf schemas @@ -252,10 +235,8 @@ EXTRA_DIST = \ $(glade_DATA) \ $(schema_in_files) \ $(etspec_DATA) \ - $(server_in_files) \ $(search_files) -BUILT_SOURCES = $(IDL_GENERATED) $(server_DATA) CLEANFILES = $(BUILT_SOURCES) DISTCLEANFILES = $(schema_DATA) diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index 180542eb6e..e4aca02699 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -904,6 +904,7 @@ create_snooze (CompQueuedAlarms *cqa, gpointer alarm_id, gint snooze_mins) static void edit_component (ECal *client, ECalComponent *comp) { +#if 0 /* KILL-BONOBO */ const gchar *uid; const gchar *uri; ECalSourceType source_type; @@ -947,6 +948,7 @@ edit_component (ECal *client, ECalComponent *comp) /* Get rid of the factory */ bonobo_object_release_unref (factory, NULL); +#endif } typedef struct { diff --git a/calendar/gui/apps_evolution_calendar.schemas.in b/calendar/gui/apps_evolution_calendar.schemas.in index 48c5100ad8..6e5e057c14 100644 --- a/calendar/gui/apps_evolution_calendar.schemas.in +++ b/calendar/gui/apps_evolution_calendar.schemas.in @@ -268,11 +268,11 @@ </locale> </schema> <schema> - <key>/schemas/apps/evolution/calendar/display/tag_vpane_position</key> - <applyto>/apps/evolution/calendar/display/tag_vpane_position</applyto> + <key>/schemas/apps/evolution/calendar/display/date_navigator_pane_position</key> + <applyto>/apps/evolution/calendar/display/date_navigator_pane_position</applyto> <owner>evolution-calendar</owner> - <type>float</type> - <default>0.5</default> + <type>int</type> + <default>150</default> <locale name="C"> <short>Month view vertical pane position </short> <long>Position of the vertical pane, between the calendar lists and the date navigator calendar.</long> @@ -293,13 +293,25 @@ </schema> <schema> + <key>/schemas/apps/evolution/calendar/display/memo_vpane_position</key> + <applyto>/apps/evolution/calendar/display/memo_vpane_position</applyto> + <owner>evolution-calendar</owner> + <type>int</type> + <default>400</default> + <locale name="C"> + <short>Memos vertical pane position</short> + <long>Position of the vertical pane, between the memo list and the memo preview pane, in pixels.</long> + </locale> + </schema> + + <schema> <key>/schemas/apps/evolution/calendar/display/task_vpane_position</key> <applyto>/apps/evolution/calendar/display/task_vpane_position</applyto> <owner>evolution-calendar</owner> <type>int</type> <default>400</default> <locale name="C"> - <short>Tasks vertical pane position </short> + <short>Tasks vertical pane position</short> <long>Position of the vertical pane, between the task list and the task preview pane, in pixels.</long> </locale> </schema> diff --git a/calendar/gui/cal-search-bar.c b/calendar/gui/cal-search-bar.c index 424db0d5e4..c509561a17 100644 --- a/calendar/gui/cal-search-bar.c +++ b/calendar/gui/cal-search-bar.c @@ -72,12 +72,12 @@ enum { /* Comments are disabled because they are kind of useless right now, see bug 33247 */ static ESearchBarItem search_option_items[] = { - { (gchar *) N_("Summary contains"), SEARCH_SUMMARY_CONTAINS, ESB_ITEMTYPE_RADIO }, - { (gchar *) N_("Description contains"), SEARCH_DESCRIPTION_CONTAINS, ESB_ITEMTYPE_RADIO }, - { (gchar *) N_("Category is"), SEARCH_CATEGORY_IS, ESB_ITEMTYPE_RADIO }, - { (gchar *) N_("Comment contains"), SEARCH_COMMENT_CONTAINS, ESB_ITEMTYPE_RADIO }, - { (gchar *) N_("Location contains"), SEARCH_LOCATION_CONTAINS, ESB_ITEMTYPE_RADIO }, - { (gchar *) N_("Any field contains"), SEARCH_ANY_FIELD_CONTAINS, ESB_ITEMTYPE_RADIO }, + { N_("Summary contains"), SEARCH_SUMMARY_CONTAINS }, + { N_("Description contains"), SEARCH_DESCRIPTION_CONTAINS }, + { N_("Category is"), SEARCH_CATEGORY_IS }, + { N_("Comment contains"), SEARCH_COMMENT_CONTAINS }, + { N_("Location contains"), SEARCH_LOCATION_CONTAINS }, + { N_("Any field contains"), SEARCH_ANY_FIELD_CONTAINS }, }; /* IDs for the categories suboptions */ diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 9b665ce44e..01e4fe5439 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -66,53 +66,6 @@ typedef struct { guint taskpad_focused : 1; } FocusData; -static void -file_open_event_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - e_calendar_view_open_event (E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (gcal))); -} - - -/* Prints the calendar at its current view and time range */ -void -calendar_command_print (GnomeCalendar *gcal, GtkPrintOperationAction action) -{ - if (gnome_calendar_get_view (gcal) == GNOME_CAL_LIST_VIEW) { - ECalListView *list_view; - ETable *table; - - list_view = E_CAL_LIST_VIEW (gnome_calendar_get_current_view_widget (gcal)); - table = e_table_scrolled_get_table (list_view->table_scrolled); - print_table (table, _("Print"), _("Calendar"), action); - } else { - time_t start; - - gnome_calendar_get_current_time_range (gcal, &start, NULL); - print_calendar (gcal, action, start); - } -} - -/* File/Print callback */ -static void -file_print_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal = GNOME_CALENDAR (data); - - calendar_command_print (gcal, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); -} - -static void -file_print_preview_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal = GNOME_CALENDAR (data); - - calendar_command_print (gcal, GTK_PRINT_OPERATION_ACTION_PREVIEW); -} - /* Sets a clock cursor for the specified calendar window */ static void set_clock_cursor (GnomeCalendar *gcal) @@ -134,58 +87,6 @@ set_normal_cursor (GnomeCalendar *gcal) } static void -previous_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_previous (gcal); - set_normal_cursor (gcal); -} - -static void -next_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_next (gcal); - set_normal_cursor (gcal); -} - -void -calendar_goto_today (GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_goto_today (gcal); - set_normal_cursor (gcal); -} - -static void -today_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - calendar_goto_today (gcal); -} - -static void -goto_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - goto_dialog (gcal); -} - -static void show_day_view_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path) { GnomeCalendar *gcal; @@ -238,65 +139,6 @@ show_list_view_clicked (BonoboUIComponent *uic, gpointer data, const gchar *path static void -cut_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - set_clock_cursor (gcal); - gnome_calendar_cut_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -copy_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_copy_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -paste_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_paste_clipboard (gcal); - set_normal_cursor (gcal); -} - -static void -delete_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_delete_selection (gcal); - set_normal_cursor (gcal); -} - -static void -delete_occurrence_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - set_clock_cursor (gcal); - gnome_calendar_delete_selected_occurrence (gcal); - set_normal_cursor (gcal); -} - -static void purge_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) { GnomeCalendar *gcal; @@ -368,69 +210,6 @@ sensitize_items(BonoboUIComponent *uic, struct _sensitize_item *items, guint32 m } } -static struct _sensitize_item calendar_sensitize_table[] = { - { "EventOpen", E_CAL_MENU_SELECT_ONE }, - { "Cut", E_CAL_MENU_SELECT_EDITABLE }, - { "Copy", E_CAL_MENU_SELECT_ANY }, - { "Paste", E_CAL_MENU_SELECT_EDITABLE }, - { "Delete", E_CAL_MENU_SELECT_EDITABLE|E_CAL_MENU_SELECT_NONRECURRING }, - { "DeleteOccurrence", E_CAL_MENU_SELECT_EDITABLE|E_CAL_MENU_SELECT_RECURRING }, - { "DeleteAllOccurrences", E_CAL_MENU_SELECT_EDITABLE|E_CAL_MENU_SELECT_RECURRING }, - { NULL } -}; - -/* Sensitizes the UI Component menu/toolbar calendar commands based on the - * number of selected events. (This will always be 0 or 1 currently.) If enable - * is FALSE, all will be disabled. Otherwise, the currently-selected number of - * events will be used. - */ -void -calendar_control_sensitize_calendar_commands (BonoboControl *control, GnomeCalendar *gcal, gboolean enable) -{ - BonoboUIComponent *uic; - GtkWidget *view; - ECalMenu *menu; - ECalModel *model; - GPtrArray *events; - GList *selected, *l; - ECalMenuTargetSelect *t; - - uic = bonobo_control_get_ui_component (control); - g_return_if_fail (uic != NULL); - - if (bonobo_ui_component_get_container (uic) == CORBA_OBJECT_NIL) - return; - - view = gnome_calendar_get_current_view_widget (gcal); - - menu = gnome_calendar_get_calendar_menu (gcal); - model = e_calendar_view_get_model((ECalendarView *)view); - events = g_ptr_array_new(); - selected = e_calendar_view_get_selected_events((ECalendarView *)view); - for (l=selected;l;l=g_list_next(l)) { - ECalendarViewEvent *event = l->data; - if (event && event->comp_data) - g_ptr_array_add (events, e_cal_model_copy_component_data(event->comp_data)); - } - g_list_free(selected); - - t = e_cal_menu_target_new_select(menu, model, events); - if (!enable) - t->target.mask = ~0; - - sensitize_items(uic, calendar_sensitize_table, t->target.mask); -#if 0 - /* retrieve read-onlyness of the default client */ - e_cal = e_cal_model_get_default_client (gnome_calendar_get_calendar_model (gcal)); - if (e_cal) - e_cal_is_read_only (e_cal, &default_read_only, NULL); - else - default_read_only = TRUE; -#endif - - e_menu_update_target((EMenu *)menu, (EMenuTarget *)t); -} - static struct _sensitize_item taskpad_sensitize_table[] = { { "Cut", E_CAL_MENU_SELECT_EDITABLE }, { "Copy", E_CAL_MENU_SELECT_ANY }, @@ -558,21 +337,6 @@ help_debug (BonoboUIComponent *uid, gpointer data, const gchar *path) } static BonoboUIVerb verbs [] = { - BONOBO_UI_VERB ("EventOpen", file_open_event_cb), - BONOBO_UI_VERB ("CalendarPrint", file_print_cb), - BONOBO_UI_VERB ("CalendarPrintPreview", file_print_preview_cb), - - BONOBO_UI_VERB ("Cut", cut_cmd), - BONOBO_UI_VERB ("Copy", copy_cmd), - BONOBO_UI_VERB ("Paste", paste_cmd), - BONOBO_UI_VERB ("Delete", delete_cmd), - BONOBO_UI_VERB ("DeleteOccurrence", delete_occurrence_cmd), - BONOBO_UI_VERB ("DeleteAllOccurrences", delete_cmd), - - BONOBO_UI_VERB ("CalendarPrev", previous_clicked), - BONOBO_UI_VERB ("CalendarToday", today_clicked), - BONOBO_UI_VERB ("CalendarNext", next_clicked), - BONOBO_UI_VERB ("CalendarGoto", goto_clicked), BONOBO_UI_VERB ("ShowDayView", show_day_view_clicked), BONOBO_UI_VERB ("ShowWorkWeekView", show_work_week_view_clicked), @@ -585,35 +349,6 @@ static BonoboUIVerb verbs [] = { BONOBO_UI_VERB_END }; -static EPixmap pixmaps [] = { - E_PIXMAP ("/commands/CalendarPrev", "go-previous", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/CalendarPrint", "document-print", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/DeleteAllOccurrences", "edit-delete", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/DeleteOccurrence", "edit-delete", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/CalendarGoto", "go-jump", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/CalendarNext", "go-next", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/CalendarPrintPreview", "document-print-preview", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/Copy", "edit-copy", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/Cut", "edit-cut", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/Delete", "edit-delete", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/Paste", "edit-paste", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/CalendarToday", "go-today", GTK_ICON_SIZE_MENU), - - E_PIXMAP ("/Toolbar/Print", "document-print", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Delete", "edit-delete", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Prev", "go-previous", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Next", "go-next", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Goto", "go-jump", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/DayView", "view-calendar-day", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/WorkWeekView", "view-calendar-workweek", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/WeekView", "view-calendar-week", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/MonthView", "view-calendar-month", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/ListView", "view-calendar-list", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Today", "go-today", GTK_ICON_SIZE_LARGE_TOOLBAR), - - E_PIXMAP_END -}; - void calendar_control_activate (BonoboControl *control, GnomeCalendar *gcal) @@ -645,8 +380,6 @@ calendar_control_activate (BonoboControl *control, NULL); g_free (xmlfile); - e_pixmaps_update (uic, pixmaps); - gnome_calendar_setup_view_menus (gcal, uic); g_signal_connect (gcal, "calendar_focus_change", diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c index 5fbf0313ab..daa7e1c9a9 100644 --- a/calendar/gui/calendar-component.c +++ b/calendar/gui/calendar-component.c @@ -65,26 +65,9 @@ #define CREATE_MEETING_ID "meeting" #define CREATE_ALLDAY_EVENT_ID "allday-event" #define CREATE_CALENDAR_ID "calendar" -#define WEB_BASE_URI "webcal://" -#define CONTACTS_BASE_URI "contacts://" -#define WEATHER_BASE_URI "weather://" -#define PERSONAL_RELATIVE_URI "system" #define CALENDAR_ERROR_LEVEL_KEY "/apps/evolution/calendar/display/error_level" #define CALENDAR_ERROR_TIME_OUT_KEY "/apps/evolution/calendar/display/error_timeout" -enum DndTargetType { - DND_TARGET_TYPE_CALENDAR_LIST -}; -#define CALENDAR_TYPE "text/calendar" -#define XCALENDAR_TYPE "text/x-calendar" -static GtkTargetEntry drag_types[] = { - { (gchar *) CALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST }, - { (gchar *) XCALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST } -}; -static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]); -#define CALENDAR_COMPONENT_DEFAULT(cc) if (cc == NULL) cc = calendar_component_peek() -#define PARENT_TYPE bonobo_object_get_type () - static BonoboObjectClass *parent_class = NULL; typedef struct @@ -99,27 +82,17 @@ typedef struct GnomeCalendar *calendar; - EInfoLabel *info_label; GtkWidget *source_selector; BonoboControl *view_control; - BonoboControl *sidebar_control; - BonoboControl *statusbar_control; GList *notifications; - EUserCreatableItemsHandler *creatable_items_handler; - - EActivityHandler *activity_handler; - gfloat vpane_pos; } CalendarComponentView; struct _CalendarComponentPrivate { - gchar *base_directory; - gchar *config_directory; - GConfClient *gconf_client; gint gconf_notify_id; ESourceList *source_list; @@ -136,9 +109,6 @@ struct _CalendarComponentPrivate { GList *notifications; }; -/* FIXME This should be gnome cal likely */ -extern ECompEditorRegistry *comp_editor_registry; - static void calcomp_vpane_realized (GtkWidget *vpane, CalendarComponentView *view) { @@ -156,158 +126,6 @@ calcomp_vpane_resized (GtkWidget *vpane, GdkEventButton *e, CalendarComponentVie return FALSE; } -static void -ensure_sources (CalendarComponent *component) -{ - ESourceList *source_list; - ESourceGroup *on_this_computer; - ESourceGroup *contacts; - ESource *personal_source; - ESource *birthdays_source; - gchar *base_uri, *base_uri_proto, base_uri_proto_seventh; - const gchar *base_dir; - gchar *create_source; - - personal_source = NULL; - birthdays_source = NULL; - - if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_EVENT, NULL)) { - g_warning ("Could not get calendar source list from GConf!"); - return; - } - - base_dir = calendar_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - if (strlen (base_uri_proto) > 7) { - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ - base_uri_proto_seventh = base_uri_proto[7]; - base_uri_proto[7] = 0; - } else { - base_uri_proto_seventh = -1; - } - - on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); - contacts = e_source_list_ensure_group (source_list, _("Contacts"), CONTACTS_BASE_URI, TRUE); - e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); - e_source_list_ensure_group (source_list, _("Weather"), WEATHER_BASE_URI, FALSE); - - if (base_uri_proto_seventh != -1) { - base_uri_proto[7] = base_uri_proto_seventh; - } - - if (on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - personal_source = source; - break; - } - } - /* Make sure we have the correct base uri. This can change when user's - homedir name changes */ - if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) { - e_source_group_set_base_uri (on_this_computer, base_uri_proto); - - /* *sigh* . We shouldn't need this sync call here as set_base_uri - call results in synching to gconf, but that happens in idle loop - and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ - e_source_list_sync (source_list,NULL); - } - } - - if (personal_source) { - /* ensure the source name is in current locale, not read from configuration */ - e_source_set_name (personal_source, _("Personal")); - } else { - gchar *primary_calendar = calendar_config_get_primary_calendar(); - GSList *calendars_selected; - - /* Create the default Person addressbook */ - personal_source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (on_this_computer, personal_source, -1); - g_object_unref (personal_source); - - calendars_selected = calendar_config_get_calendars_selected (); - if (!primary_calendar && !calendars_selected) { - GSList selected; - - calendar_config_set_primary_calendar (e_source_peek_uid (personal_source)); - - selected.data = (gpointer)e_source_peek_uid (personal_source); - selected.next = NULL; - calendar_config_set_calendars_selected (&selected); - } - - if (calendars_selected) { - g_slist_foreach (calendars_selected, (GFunc) g_free, NULL); - g_slist_free (calendars_selected); - } - - g_free (primary_calendar); - e_source_set_color_spec (personal_source, "#BECEDD"); - } - - if (contacts) { - GSList *sources = e_source_group_peek_sources (contacts); - if (sources) { - birthdays_source = E_SOURCE (sources->data); /* There is only one source under Contacts Group*/ - - if (sources->next) { - /* Ensure we have only one contacts source - we was able to create more than one before */ - GSList *l = NULL, *p; - - for (p = sources->next; p; p = p->next) - l = g_slist_prepend (l, p->data); - - for (p = l; p; p = p->next) - e_source_group_remove_source (contacts, p->data); - - g_slist_free (l); - } - } - } - - create_source = e_source_group_get_property (contacts, "create_source"); - if (!create_source) - e_source_group_set_property (contacts, "create_source", "no"); - g_free (create_source); - - if (birthdays_source) { - /* ensure the source name is in current locale, not read from configuration */ - e_source_set_name (birthdays_source, _("Birthdays & Anniversaries")); - } else { - birthdays_source = e_source_new (_("Birthdays & Anniversaries"), "/"); - e_source_group_add_source (contacts, birthdays_source, -1); - g_object_unref (birthdays_source); - } - - if (!e_source_get_property (birthdays_source, "delete")) - e_source_set_property(birthdays_source, "delete", "no"); - - if (e_source_peek_color_spec (birthdays_source) == NULL) - e_source_set_color_spec (birthdays_source, "#DDBECE"); - - component->priv->source_list = source_list; - - g_object_unref (on_this_computer); - g_object_unref (contacts); - g_free (base_uri_proto); - g_free (base_uri); -} - - /* Utility functions. */ static gboolean @@ -341,88 +159,6 @@ is_in_uids (GSList *uids, ESource *source) } static void -update_uris_for_selection (CalendarComponentView *component_view) -{ - GSList *selection, *l, *uids_selected = NULL; - - selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - - for (l = component_view->source_selection; l; l = l->next) { - ESource *old_selected_source = l->data; - - if (!is_in_selection (selection, old_selected_source)) - gnome_calendar_remove_source (component_view->calendar, E_CAL_SOURCE_TYPE_EVENT, old_selected_source); - } - - for (l = selection; l; l = l->next) { - ESource *selected_source = l->data; - - if (gnome_calendar_add_source (component_view->calendar, E_CAL_SOURCE_TYPE_EVENT, selected_source)) - uids_selected = g_slist_append (uids_selected, (gchar *) e_source_peek_uid (selected_source)); - } - - e_source_selector_free_selection (component_view->source_selection); - component_view->source_selection = selection; - - /* Save the selection for next time we start up */ - calendar_config_set_calendars_selected (uids_selected); - g_slist_free (uids_selected); -} - -static void -update_uri_for_primary_selection (CalendarComponentView *component_view) -{ - ESource *source; - - source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!source) - return; - - /* Set the default */ - gnome_calendar_set_default_source (component_view->calendar, E_CAL_SOURCE_TYPE_EVENT, source); - - /* Make sure we are embedded first */ - calendar_control_sensitize_calendar_commands (component_view->view_control, component_view->calendar, TRUE); - - /* Save the selection for next time we start up */ - calendar_config_set_primary_calendar (e_source_peek_uid (source)); -} - -static void -update_selection (CalendarComponentView *component_view) -{ - GSList *selection, *uids_selected, *l; - - /* Get the selection in gconf */ - uids_selected = calendar_config_get_calendars_selected (); - - /* Remove any that aren't there any more */ - selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - - for (l = selection; l; l = l->next) { - ESource *source = l->data; - - if (!is_in_uids (uids_selected, source)) - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - } - - e_source_selector_free_selection (selection); - - /* Make sure the whole selection is there */ - for (l = uids_selected; l; l = l->next) { - gchar *uid = l->data; - ESource *source; - - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - if (source) - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - - g_free (uid); - } - g_slist_free (uids_selected); -} - -static void update_task_memo_selection (CalendarComponentView *component_view, ECalSourceType type) { GSList *uids_selected, *l, *source_selection; @@ -472,28 +208,6 @@ update_task_memo_selection (CalendarComponentView *component_view, ECalSourceTyp } static void -update_primary_selection (CalendarComponentView *component_view) -{ - ESource *source = NULL; - gchar *uid; - - uid = calendar_config_get_primary_calendar (); - if (uid) { - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - g_free (uid); - } - - if (source) { - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } else { - /* Try to create a default if there isn't one */ - source = e_source_list_peek_source_any (component_view->source_list); - if (source) - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } -} - -static void update_primary_task_memo_selection (CalendarComponentView *component_view, ECalSourceType type) { ESource *source = NULL; @@ -518,314 +232,6 @@ update_primary_task_memo_selection (CalendarComponentView *component_view, ECalS gnome_calendar_set_default_source (component_view->calendar, type, source); } -/* Callbacks. */ -static void -copy_calendar_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - CalendarComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - copy_source_dialog (GTK_WINDOW (gtk_widget_get_toplevel (ep->target->widget)), selected_source, E_CAL_SOURCE_TYPE_EVENT); -} - -static void -delete_calendar_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - CalendarComponentView *component_view = data; - ESource *selected_source; - ECal *cal; - gchar *uri; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - if (e_error_run((GtkWindow *)gtk_widget_get_toplevel(ep->target->widget), - "calendar:prompt-delete-calendar", e_source_peek_name(selected_source), NULL) != GTK_RESPONSE_YES) - return; - - /* first, ask the backend to remove the calendar */ - uri = e_source_get_uri (selected_source); - cal = e_cal_model_get_client_for_uri (gnome_calendar_get_calendar_model (component_view->calendar), uri); - if (!cal) - cal = e_cal_new_from_uri (uri, E_CAL_SOURCE_TYPE_EVENT); - g_free (uri); - if (cal) { - if (e_cal_remove (cal, NULL)) { - if (e_source_selector_source_is_selected (E_SOURCE_SELECTOR (component_view->source_selector), - selected_source)) { - gnome_calendar_remove_source (component_view->calendar, E_CAL_SOURCE_TYPE_EVENT, selected_source); - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), - selected_source); - } - - e_source_group_remove_source (e_source_peek_group (selected_source), selected_source); - e_source_list_sync (component_view->source_list, NULL); - } - } -} - -static void -new_calendar_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - calendar_setup_edit_calendar (GTK_WINDOW (gtk_widget_get_toplevel(ep->target->widget)), NULL, pitem->user_data); -} - -static void -rename_calendar_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - CalendarComponentView *component_view = data; - ESourceSelector *selector; - - selector = E_SOURCE_SELECTOR (component_view->source_selector); - e_source_selector_edit_primary_selection (selector); -} - -static void -edit_calendar_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - CalendarComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - calendar_setup_edit_calendar (GTK_WINDOW (gtk_widget_get_toplevel(ep->target->widget)), selected_source, NULL); -} - -static void -set_offline_availability (EPopup *ep, EPopupItem *pitem, gpointer data, const gchar *value) -{ - CalendarComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - e_source_set_property (selected_source, "offline_sync", value); -} - -static void -mark_no_offline_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - set_offline_availability (ep, pitem, data, "0"); -} - -static void -mark_offline_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - set_offline_availability (ep, pitem, data, "1"); -} - -static EPopupItem ecc_source_popups[] = { - { E_POPUP_ITEM, (gchar *) "10.new", (gchar *) N_("_New Calendar"), new_calendar_cb, NULL, (gchar *) "x-office-calendar", 0, 0 }, - { E_POPUP_ITEM, (gchar *) "15.copy", (gchar *) N_("_Copy..."), copy_calendar_cb, NULL, (gchar *) "edit-copy", 0, E_CAL_POPUP_SOURCE_PRIMARY }, - { E_POPUP_ITEM, (gchar *) "18.rename", (gchar *) N_("_Rename..."), rename_calendar_cb, NULL, NULL, 0, E_CAL_POPUP_SOURCE_PRIMARY }, - - { E_POPUP_BAR, (gchar *) "20.bar" }, - { E_POPUP_ITEM, (gchar *) "20.delete", (gchar *) N_("_Delete"), delete_calendar_cb, NULL, (gchar *) "edit-delete", 0,E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY|E_CAL_POPUP_SOURCE_DELETE }, - { E_POPUP_ITEM, (gchar *) "30.mark_calendar_offline", (gchar *) N_("_Make available for offline use"), mark_offline_cb, NULL, (gchar *) "stock_disconnect", E_CAL_POPUP_SOURCE_OFFLINE, E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY|E_CAL_POPUP_SOURCE_OFFLINE }, - { E_POPUP_ITEM, (gchar *) "40.mark_calendar_no_offline", (gchar *) N_("_Do not make available for offline use"), mark_no_offline_cb, NULL, (gchar *) "stock_connect", E_CAL_POPUP_SOURCE_NO_OFFLINE, E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY|E_CAL_POPUP_SOURCE_NO_OFFLINE }, - - { E_POPUP_BAR, (gchar *) "99.bar" }, - { E_POPUP_ITEM, (gchar *) "99.properties", (gchar *) N_("_Properties"), edit_calendar_cb, NULL, (gchar *) "document-properties", 0, E_CAL_POPUP_SOURCE_PRIMARY }, -}; - -static void -ecc_source_popup_free(EPopup *ep, GSList *list, gpointer data) -{ - g_slist_free(list); -} - -static gboolean -popup_event_cb(ESourceSelector *selector, ESource *insource, GdkEventButton *event, CalendarComponentView *component_view) -{ - ECalPopup *ep; - ECalPopupTargetSource *t; - GSList *menus = NULL; - gint i; - GtkMenu *menu; - - /** @HookPoint-ECalPopup: Calendar Source Selector Context Menu - * @Id: org.gnome.evolution.calendar.source.popup - * @Class: org.gnome.evolution.calendar.popup:1.0 - * @Target: ECalPopupTargetSource - * - * The context menu on the source selector in the calendar window. - */ - ep = e_cal_popup_new("org.gnome.evolution.calendar.source.popup"); - t = e_cal_popup_target_new_source(ep, selector); - t->target.widget = (GtkWidget *)component_view->calendar; - - for (i=0;i<sizeof(ecc_source_popups)/sizeof(ecc_source_popups[0]);i++) - menus = g_slist_prepend(menus, &ecc_source_popups[i]); - - e_popup_add_items((EPopup *)ep, menus, NULL, ecc_source_popup_free, component_view); - - menu = e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0); - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event?event->button:0, event?event->time:gtk_get_current_event_time()); - - return TRUE; -} - -static void -source_selection_changed_cb (ESourceSelector *selector, CalendarComponentView *component_view) -{ - update_uris_for_selection (component_view); -} - -static void -primary_source_selection_changed_cb (ESourceSelector *selector, CalendarComponentView *component_view) -{ - update_uri_for_primary_selection (component_view); -} - -static void -source_changed_cb (ESource *source, GnomeCalendar *calendar) -{ - if (calendar) { - GtkWidget *widget = gnome_calendar_get_current_view_widget (calendar); - - if (widget) - gtk_widget_queue_draw (widget); - } -} - -static void -source_added_cb (GnomeCalendar *calendar, ECalSourceType source_type, ESource *source, CalendarComponentView *component_view) -{ - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), calendar); - break; - default: - break; - } -} - -static void -source_removed_cb (GnomeCalendar *calendar, ECalSourceType source_type, ESource *source, CalendarComponentView *component_view) -{ - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - g_signal_handlers_disconnect_by_func (source, G_CALLBACK (source_changed_cb), calendar); - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - break; - default: - break; - } -} - -static void -set_info (CalendarComponentView *component_view) -{ - icaltimezone *zone; - struct icaltimetype start_tt, end_tt; - time_t start_time, end_time; - struct tm start_tm, end_tm; - gchar buffer[512], end_buffer[256]; - GnomeCalendarViewType view; - - gnome_calendar_get_visible_time_range (component_view->calendar, &start_time, &end_time); - zone = gnome_calendar_get_timezone (component_view->calendar); - - start_tt = icaltime_from_timet_with_zone (start_time, FALSE, zone); - start_tm.tm_year = start_tt.year - 1900; - start_tm.tm_mon = start_tt.month - 1; - start_tm.tm_mday = start_tt.day; - start_tm.tm_hour = start_tt.hour; - start_tm.tm_min = start_tt.minute; - start_tm.tm_sec = start_tt.second; - start_tm.tm_isdst = -1; - start_tm.tm_wday = time_day_of_week (start_tt.day, start_tt.month - 1, - start_tt.year); - - /* Take one off end_time so we don't get an extra day. */ - end_tt = icaltime_from_timet_with_zone (end_time - 1, FALSE, zone); - end_tm.tm_year = end_tt.year - 1900; - end_tm.tm_mon = end_tt.month - 1; - end_tm.tm_mday = end_tt.day; - end_tm.tm_hour = end_tt.hour; - end_tm.tm_min = end_tt.minute; - end_tm.tm_sec = end_tt.second; - end_tm.tm_isdst = -1; - end_tm.tm_wday = time_day_of_week (end_tt.day, end_tt.month - 1, - end_tt.year); - - view = gnome_calendar_get_view (component_view->calendar); - - switch (view) { - case GNOME_CAL_DAY_VIEW: - case GNOME_CAL_WORK_WEEK_VIEW: - case GNOME_CAL_WEEK_VIEW: - if (start_tm.tm_year == end_tm.tm_year - && start_tm.tm_mon == end_tm.tm_mon - && start_tm.tm_mday == end_tm.tm_mday) { - e_utf8_strftime (buffer, sizeof (buffer), - _("%A %d %b %Y"), &start_tm); - } else if (start_tm.tm_year == end_tm.tm_year) { - e_utf8_strftime (buffer, sizeof (buffer), - _("%a %d %b"), &start_tm); - e_utf8_strftime (end_buffer, sizeof (end_buffer), - _("%a %d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } else { - e_utf8_strftime (buffer, sizeof (buffer), - _("%a %d %b %Y"), &start_tm); - e_utf8_strftime (end_buffer, sizeof (end_buffer), - _("%a %d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - break; - case GNOME_CAL_MONTH_VIEW: - case GNOME_CAL_LIST_VIEW: - if (start_tm.tm_year == end_tm.tm_year) { - if (start_tm.tm_mon == end_tm.tm_mon) { - e_utf8_strftime (buffer, sizeof (buffer), - "%d", &start_tm); - e_utf8_strftime (end_buffer, sizeof (end_buffer), - _("%d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } else { - e_utf8_strftime (buffer, sizeof (buffer), - _("%d %b"), &start_tm); - e_utf8_strftime (end_buffer, sizeof (end_buffer), - _("%d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - } else { - e_utf8_strftime (buffer, sizeof (buffer), - _("%d %b %Y"), &start_tm); - e_utf8_strftime (end_buffer, sizeof (end_buffer), - _("%d %b %Y"), &end_tm); - strcat (buffer, " - "); - strcat (buffer, end_buffer); - } - break; - default: - g_return_if_reached (); - } - - e_info_label_set_info (component_view->info_label, _("Calendars"), buffer); -} - -static void -calendar_dates_changed_cb (GnomeCalendar *calendar, CalendarComponentView *component_view) -{ - set_info (component_view); -} - static void config_primary_selection_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) { @@ -948,85 +354,6 @@ impl_handleURI (PortableServer_Servant servant, const gchar *uri, CORBA_Environm } static void -impl_upgradeFromVersion (PortableServer_Servant servant, - CORBA_short major, - CORBA_short minor, - CORBA_short revision, - CORBA_Environment *ev) -{ - GError *err = NULL; - CalendarComponent *calendar_component = CALENDAR_COMPONENT (bonobo_object_from_servant (servant)); - - if (!migrate_calendars (calendar_component, major, minor, revision, &err)) { - GNOME_Evolution_Component_UpgradeFailed *failedex; - - failedex = GNOME_Evolution_Component_UpgradeFailed__alloc(); - failedex->what = CORBA_string_dup(_("Failed upgrading calendars.")); - failedex->why = CORBA_string_dup(err->message); - CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UpgradeFailed, failedex); - } - - if (err) - g_error_free(err); -} - -static gboolean -selector_tree_data_dropped (ESourceSelector *selector, - GtkSelectionData *data, - ESource *destination, - GdkDragAction action, - guint info, - CalendarComponent *component) -{ - gboolean success = FALSE; - ECal *client; - - client = auth_new_cal_from_source (destination, E_CAL_SOURCE_TYPE_EVENT); - - if (!client || !e_cal_open (client, TRUE, NULL)) { - if (client) - g_object_unref (client); - - return FALSE; - } - - if (data->data) { - icalcomponent *icalcomp = NULL; - gchar *comp_str; /* do not free this! */ - - /* data->data is "source_uid\ncomponent_string" */ - comp_str = strchr ((gchar *)data->data, '\n'); - if (comp_str) { - comp_str [0] = 0; - comp_str++; - - icalcomp = icalparser_parse_string (comp_str); - - if (icalcomp) { - success = cal_comp_process_source_list_drop (client, icalcomp, action, (gchar *)data->data, component->priv->source_list); - icalcomponent_free (icalcomp); - } - } - } - - return success; -} - -static void -control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) -{ - CalendarComponentView *component_view = data; - - if (activate) { - BonoboUIComponent *uic; - uic = bonobo_control_get_ui_component (component_view->view_control); - - e_user_creatable_items_handler_activate (component_view->creatable_items_handler, uic); - } -} - - -static void config_create_ecal_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) { CalendarComponent *calendar_component = data; @@ -1124,79 +451,13 @@ setup_create_ecal (CalendarComponent *calendar_component, CalendarComponentView return priv->create_ecal; } -static gboolean -create_new_event (CalendarComponent *calendar_component, CalendarComponentView *component_view, gboolean is_allday, gboolean is_meeting) -{ - ECal *ecal; - ECalendarView *view; - - ecal = setup_create_ecal (calendar_component, component_view); - if (!ecal) - return FALSE; - - if (component_view && (view = E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (component_view->calendar)))) { - e_calendar_view_new_appointment_full (view, is_allday, is_meeting, TRUE); - } else { - ECalComponent *comp; - CompEditor *editor; - CompEditorFlags flags; - - flags = COMP_EDITOR_USER_ORG | COMP_EDITOR_NEW_ITEM; - if (is_meeting) - flags |= COMP_EDITOR_MEETING; - comp = cal_comp_event_new_with_current_time (ecal, is_allday); - editor = event_editor_new (ecal, flags); - e_cal_component_commit_sequence (comp); - - comp_editor_edit_comp (editor, comp); - if (is_meeting) - event_editor_show_meeting (EVENT_EDITOR (editor)); - gtk_window_present (GTK_WINDOW (editor)); - - e_comp_editor_registry_add (comp_editor_registry, editor, TRUE); - } - - return TRUE; -} - -static void -create_local_item_cb (EUserCreatableItemsHandler *handler, const gchar *item_type_name, gpointer data) -{ - CalendarComponent *calendar_component = data; - CalendarComponentPrivate *priv; - CalendarComponentView *component_view = NULL; - GList *l; - - priv = calendar_component->priv; - - for (l = priv->views; l; l = l->next) { - component_view = l->data; - - if (component_view->creatable_items_handler == handler) - break; - - component_view = NULL; - } - - if (strcmp (item_type_name, CREATE_EVENT_ID) == 0) - create_new_event (calendar_component, component_view, FALSE, FALSE); - else if (strcmp (item_type_name, CREATE_ALLDAY_EVENT_ID) == 0) - create_new_event (calendar_component, component_view, TRUE, FALSE); - else if (strcmp (item_type_name, CREATE_MEETING_ID) == 0) - create_new_event (calendar_component, component_view, FALSE, TRUE); - else if (strcmp (item_type_name, CREATE_CALENDAR_ID) == 0) - calendar_setup_new_calendar (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (component_view->calendar)))); -} - static CalendarComponentView * create_component_view (CalendarComponent *calendar_component) { CalendarComponentPrivate *priv; CalendarComponentView *component_view; - GtkWidget *selector_scrolled_window, *vbox, *vpane; - GtkWidget *statusbar_widget; + GtkWidget **vpane; guint not; - AtkObject *a11y; priv = calendar_component->priv; @@ -1213,14 +474,8 @@ create_component_view (CalendarComponent *calendar_component) component_view->source_list = g_object_ref (priv->source_list); component_view->task_source_list = g_object_ref (priv->task_source_list); component_view->memo_source_list = g_object_ref (priv->memo_source_list); - component_view->vpane_pos = calendar_config_get_tag_vpane_pos (); - /* Create sidebar selector */ component_view->source_selector = e_source_selector_new (calendar_component->priv->source_list); - e_source_selector_set_select_new ((ESourceSelector *)component_view->source_selector, TRUE); - a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector)); - atk_object_set_name (a11y, _("Calendar Source Selector")); - g_signal_connect ( component_view->source_selector, "data-dropped", G_CALLBACK (selector_tree_data_dropped), calendar_component); @@ -1290,18 +545,11 @@ create_component_view (CalendarComponent *calendar_component) g_signal_connect (component_view->source_selector, "popup_event", G_CALLBACK (popup_event_cb), component_view); +>>>>>>> 23df769955ea54f756a579c19964df87ae6fd5c8:calendar/gui/calendar-component.c /* Set up the "new" item handler */ - component_view->creatable_items_handler = e_user_creatable_items_handler_new ("calendar", create_local_item_cb, calendar_component); g_signal_connect (component_view->view_control, "activate", G_CALLBACK (control_activate_cb), component_view); - /* We use this to update the component information */ - set_info (component_view); - g_signal_connect (component_view->calendar, "dates_shown_changed", - G_CALLBACK (calendar_dates_changed_cb), component_view); - /* Load the selection from the last run */ - update_selection (component_view); - update_primary_selection (component_view); update_task_memo_selection (component_view, E_CAL_SOURCE_TYPE_TODO); update_primary_task_memo_selection (component_view, E_CAL_SOURCE_TYPE_TODO); update_task_memo_selection (component_view, E_CAL_SOURCE_TYPE_JOURNAL); @@ -1349,12 +597,6 @@ destroy_component_view (CalendarComponentView *component_view) calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); g_list_free (component_view->notifications); - if (component_view->creatable_items_handler) - g_object_unref (component_view->creatable_items_handler); - - if (component_view->activity_handler) - g_object_unref (component_view->activity_handler); - if (component_view->task_source_selection) { g_slist_foreach (component_view->task_source_selection, (GFunc) g_free, NULL); g_slist_free (component_view->task_source_selection); @@ -1389,109 +631,6 @@ view_destroyed_cb (gpointer data, GObject *where_the_object_was) } } -static GNOME_Evolution_ComponentView -impl_createView (PortableServer_Servant servant, - GNOME_Evolution_ShellView parent, - CORBA_boolean select_item, - CORBA_Environment *ev) -{ - CalendarComponent *calendar_component = CALENDAR_COMPONENT (bonobo_object_from_servant (servant)); - CalendarComponentPrivate *priv; - CalendarComponentView *component_view; - EComponentView *ecv; - - priv = calendar_component->priv; - - /* Create the calendar component view */ - component_view = create_component_view (calendar_component); - if (!component_view) { - /* FIXME Should we describe the problem in a control? */ - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); - - return CORBA_OBJECT_NIL; - } - - g_object_weak_ref (G_OBJECT (component_view->view_control), view_destroyed_cb, calendar_component); - priv->views = g_list_append (priv->views, component_view); - - /* TODO: Make CalendarComponentView just subclass EComponentView */ - ecv = e_component_view_new_controls (parent, "calendar", component_view->sidebar_control, - component_view->view_control, component_view->statusbar_control); - - return BONOBO_OBJREF(ecv); -} - - -static GNOME_Evolution_CreatableItemTypeList * -impl__get_userCreatableItems (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GNOME_Evolution_CreatableItemTypeList *list = GNOME_Evolution_CreatableItemTypeList__alloc (); - - list->_length = 4; - list->_maximum = list->_length; - list->_buffer = GNOME_Evolution_CreatableItemTypeList_allocbuf (list->_length); - - CORBA_sequence_set_release (list, FALSE); - - list->_buffer[0].id = (gchar *) CREATE_EVENT_ID; - list->_buffer[0].description = (gchar *) _("New appointment"); - list->_buffer[0].menuDescription = (gchar *) C_("New", "_Appointment"); - list->_buffer[0].tooltip = (gchar *) _("Create a new appointment"); - list->_buffer[0].menuShortcut = 'a'; - list->_buffer[0].iconName = (gchar *) "appointment-new"; - list->_buffer[0].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[1].id = (gchar *) CREATE_MEETING_ID; - list->_buffer[1].description = (gchar *) _("New meeting"); - list->_buffer[1].menuDescription = (gchar *) C_("New", "M_eeting"); - list->_buffer[1].tooltip = (gchar *) _("Create a new meeting request"); - list->_buffer[1].menuShortcut = 'e'; - list->_buffer[1].iconName = (gchar *) "stock_new-meeting"; - list->_buffer[1].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[2].id = (gchar *) CREATE_ALLDAY_EVENT_ID; - list->_buffer[2].description = (gchar *) _("New all day appointment"); - list->_buffer[2].menuDescription = (gchar *) C_("New", "All Day A_ppointment"); - list->_buffer[2].tooltip = (gchar *) _("Create a new all-day appointment"); - list->_buffer[2].menuShortcut = '\0'; - list->_buffer[2].iconName = (gchar *) "stock_new-24h-appointment"; - list->_buffer[2].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[3].id = (gchar *) CREATE_CALENDAR_ID; - list->_buffer[3].description = (gchar *) _("New calendar"); - list->_buffer[3].menuDescription = (gchar *) C_("New", "Cale_ndar"); - list->_buffer[3].tooltip = (gchar *) _("Create a new calendar"); - list->_buffer[3].menuShortcut = '\0'; - list->_buffer[3].iconName = (gchar *) "x-office-calendar"; - list->_buffer[3].type = GNOME_Evolution_CREATABLE_FOLDER; - - return list; -} - -static void -impl_requestCreateItem (PortableServer_Servant servant, - const CORBA_char *item_type_name, - CORBA_Environment *ev) -{ - CalendarComponent *calendar_component = CALENDAR_COMPONENT (bonobo_object_from_servant (servant)); - gboolean result = FALSE; - - if (strcmp (item_type_name, CREATE_EVENT_ID) == 0) - result = create_new_event (calendar_component, NULL, FALSE, FALSE); - else if (strcmp (item_type_name, CREATE_ALLDAY_EVENT_ID) == 0) - result = create_new_event (calendar_component, NULL, TRUE, FALSE); - else if (strcmp (item_type_name, CREATE_MEETING_ID) == 0) - result = create_new_event (calendar_component, NULL, FALSE, TRUE); - else if (strcmp (item_type_name, CREATE_CALENDAR_ID) == 0) - /* FIXME Should we use the last opened window? */ - calendar_setup_new_calendar (NULL); - else - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_UnknownType); - - if (!result) - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); -} /* GObject methods. */ @@ -1507,9 +646,9 @@ impl_dispose (GObject *object) priv->source_list = NULL; } - if (priv->gconf_client != NULL) { - g_object_unref (priv->gconf_client); - priv->gconf_client = NULL; + if (priv->activity_handler != NULL) { + g_object_unref (priv->activity_handler); + priv->activity_handler = NULL; } if (priv->activity_handler != NULL) { @@ -1539,27 +678,6 @@ impl_dispose (GObject *object) } static void -impl_finalize (GObject *object) -{ - CalendarComponentPrivate *priv = CALENDAR_COMPONENT (object)->priv; - GList *l; - - for (l = priv->views; l; l = l->next) { - CalendarComponentView *component_view = l->data; - - destroy_component_view (component_view); - } - g_list_free (priv->views); - - g_free (priv->base_directory); - g_free (priv->config_directory); - g_object_unref (priv->logger); - g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void calendar_component_class_init (CalendarComponentClass *class) { POA_GNOME_Evolution_Component__epv *epv = &class->epv; @@ -1570,17 +688,9 @@ calendar_component_class_init (CalendarComponentClass *class) parent_class = g_type_class_peek_parent (class); - epv->upgradeFromVersion = impl_upgradeFromVersion; - epv->createView = impl_createView; - epv->_get_userCreatableItems = impl__get_userCreatableItems; - epv->requestCreateItem = impl_requestCreateItem; epv->handleURI = impl_handleURI; object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; - - /* Register attachment handler types. */ - e_attachment_handler_calendar_get_type (); } static void @@ -1589,15 +699,6 @@ calendar_component_init (CalendarComponent *component) CalendarComponentPrivate *priv; guint not; - priv = g_new0 (CalendarComponentPrivate, 1); - - priv->base_directory = g_build_filename (e_get_user_data_dir (), "calendar", NULL); - priv->config_directory = g_build_filename (priv->base_directory, "config", NULL); - - /* EPFIXME: Should use a custom one instead? Also we should add - * calendar_component_peek_gconf_client(). */ - priv->gconf_client = gconf_client_get_default (); - not = calendar_config_add_notification_primary_calendar (config_primary_selection_changed_cb, component); priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); @@ -1608,68 +709,7 @@ calendar_component_init (CalendarComponent *component) e_activity_handler_set_error_flush_time (priv->activity_handler,eni_config_get_error_timeout (CALENDAR_ERROR_TIME_OUT_KEY)*1000); component->priv = priv; - ensure_sources (component); e_cal_get_sources (&priv->task_source_list, E_CAL_SOURCE_TYPE_TODO, NULL); e_cal_get_sources (&priv->memo_source_list, E_CAL_SOURCE_TYPE_JOURNAL, NULL); } - - -/* Public API. */ - -CalendarComponent * -calendar_component_peek (void) -{ - static CalendarComponent *component = NULL; - - if (component == NULL) { - component = g_object_new (calendar_component_get_type (), NULL); - - if (g_mkdir_with_parents (calendar_component_peek_config_directory (component), 0777) != 0) { - g_warning (G_STRLOC ": Cannot create directory %s: %s", - calendar_component_peek_config_directory (component), - g_strerror (errno)); - g_object_unref (component); - component = NULL; - } - } - - return component; -} - -const gchar * -calendar_component_peek_base_directory (CalendarComponent *component) -{ - return component->priv->base_directory; -} - -const gchar * -calendar_component_peek_config_directory (CalendarComponent *component) -{ - return component->priv->config_directory; -} - -ESourceList * -calendar_component_peek_source_list (CalendarComponent *component) -{ - return component->priv->source_list; -} - -EActivityHandler * -calendar_component_peek_activity_handler (CalendarComponent *component) -{ - CALENDAR_COMPONENT_DEFAULT(component); - - return component->priv->activity_handler; -} - -void -calendar_component_show_logger (gpointer top) -{ - CalendarComponent *cc = calendar_component_peek (); - ELogger *logger = cc->priv->logger; - - eni_show_logger(logger, top, CALENDAR_ERROR_TIME_OUT_KEY, CALENDAR_ERROR_LEVEL_KEY); -} - -BONOBO_TYPE_FUNC_FULL (CalendarComponent, GNOME_Evolution_Component, PARENT_TYPE, calendar_component) diff --git a/calendar/gui/calendar-component.h b/calendar/gui/calendar-component.h index 851c4c3237..1106d8ec62 100644 --- a/calendar/gui/calendar-component.h +++ b/calendar/gui/calendar-component.h @@ -56,12 +56,4 @@ struct _CalendarComponentClass { GType calendar_component_get_type (void); -CalendarComponent *calendar_component_peek (void); - -const gchar *calendar_component_peek_base_directory (CalendarComponent *component); -const gchar *calendar_component_peek_config_directory (CalendarComponent *component); -ESourceList *calendar_component_peek_source_list (CalendarComponent *component); -EActivityHandler *calendar_component_peek_activity_handler (CalendarComponent *component); -void calendar_component_show_logger (gpointer); - #endif /* _CALENDAR_COMPONENT_H_ */ diff --git a/calendar/gui/calendar-config-keys.h b/calendar/gui/calendar-config-keys.h index 37724a53e9..b4e95c2bd7 100644 --- a/calendar/gui/calendar-config-keys.h +++ b/calendar/gui/calendar-config-keys.h @@ -28,18 +28,10 @@ G_BEGIN_DECLS #define CALENDAR_CONFIG_PREFIX "/apps/evolution/calendar" /* Display settings */ -#define CALENDAR_CONFIG_USE_SYSTEM_TIMEZONE CALENDAR_CONFIG_PREFIX "/display/use_system_timezone" #define CALENDAR_CONFIG_TIMEZONE CALENDAR_CONFIG_PREFIX "/display/timezone" #define CALENDAR_CONFIG_SELECTED_CALENDARS CALENDAR_CONFIG_PREFIX "/display/selected_calendars" -#define CALENDAR_CONFIG_PRIMARY_CALENDAR CALENDAR_CONFIG_PREFIX "/display/primary_calendar" #define CALENDAR_CONFIG_24HOUR CALENDAR_CONFIG_PREFIX "/display/use_24hour_format" #define CALENDAR_CONFIG_SHOW_ATTENDEE CALENDAR_CONFIG_PREFIX "/display/show_attendee" -#define CALENDAR_CONFIG_SHOW_ROLE CALENDAR_CONFIG_PREFIX "/display/show_role" -#define CALENDAR_CONFIG_SHOW_STATUS CALENDAR_CONFIG_PREFIX "/display/show_status" -#define CALENDAR_CONFIG_SHOW_TYPE CALENDAR_CONFIG_PREFIX "/display/show_type" -#define CALENDAR_CONFIG_SHOW_RSVP CALENDAR_CONFIG_PREFIX "/display/show_rsvp" -#define CALENDAR_CONFIG_SHOW_TIMEZONE CALENDAR_CONFIG_PREFIX "/display/show_timezone" -#define CALENDAR_CONFIG_SHOW_CATEGORIES CALENDAR_CONFIG_PREFIX "/display/show_categories" #define CALENDAR_CONFIG_WEEK_START CALENDAR_CONFIG_PREFIX "/display/week_start_day" #define CALENDAR_CONFIG_DAY_START_HOUR CALENDAR_CONFIG_PREFIX "/display/day_start_hour" #define CALENDAR_CONFIG_DAY_START_MINUTE CALENDAR_CONFIG_PREFIX "/display/day_start_minute" diff --git a/calendar/gui/calendar-config.c b/calendar/gui/calendar-config.c index 02b051a095..f0b492d59c 100644 --- a/calendar/gui/calendar-config.c +++ b/calendar/gui/calendar-config.c @@ -29,12 +29,13 @@ #include <config.h> #endif -#include <string.h> #include <time.h> -#include <libedataserver/e-data-server-util.h> +#include <string.h> #include <e-util/e-util.h> -#include <widgets/e-timezone-dialog/e-timezone-dialog.h> #include <libecal/e-cal-time-util.h> +#include <libedataserver/e-data-server-util.h> +#include <widgets/e-timezone-dialog/e-timezone-dialog.h> +#include <shell/e-shell.h> #include "calendar-config-keys.h" #include "calendar-config.h" @@ -150,73 +151,23 @@ calendar_config_add_notification_calendars_selected (GConfClientNotifyFunc func, return id; } -/* The primary calendar */ -gchar * -calendar_config_get_primary_calendar (void) -{ - calendar_config_init (); - - return gconf_client_get_string (config, CALENDAR_CONFIG_PRIMARY_CALENDAR, NULL); -} - -void -calendar_config_set_primary_calendar (const gchar *primary_uid) -{ - calendar_config_init (); - - gconf_client_set_string (config, CALENDAR_CONFIG_PRIMARY_CALENDAR, primary_uid, NULL); -} - - -guint -calendar_config_add_notification_primary_calendar (GConfClientNotifyFunc func, gpointer data) -{ - guint id; - - calendar_config_init (); - - id = gconf_client_notify_add (config, CALENDAR_CONFIG_PRIMARY_CALENDAR, func, data, NULL, NULL); - - return id; -} - -gboolean -calendar_config_get_use_system_timezone (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_USE_SYSTEM_TIMEZONE, NULL); -} - -void -calendar_config_set_use_system_timezone (gboolean use) -{ - calendar_config_init (); - - if (calendar_config_get_use_system_timezone () != use) { - gconf_client_set_bool (config, CALENDAR_CONFIG_USE_SYSTEM_TIMEZONE, use, NULL); - gconf_client_notify (config, CALENDAR_CONFIG_TIMEZONE); - - /* FIXME: notify CALENDAR_CONFIG_TIMEZONE change on system timezone change - itself too, when using system timezone. How to receive such change? */ - } -} - -guint -calendar_config_add_notification_use_system_timezone (GConfClientNotifyFunc func, gpointer data) -{ - calendar_config_init (); - - return gconf_client_notify_add (config, CALENDAR_CONFIG_USE_SYSTEM_TIMEZONE, func, data, NULL, NULL); -} - /* The current timezone, e.g. "Europe/London". It may be NULL, in which case you should assume UTC (though Evolution will show the timezone-setting dialog the next time a calendar or task folder is selected). */ gchar * calendar_config_get_timezone (void) { - if (calendar_config_get_use_system_timezone ()) + EShell *shell; + EShellSettings *shell_settings; + gboolean use_system_timezone; + + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + + use_system_timezone = e_shell_settings_get_boolean ( + shell_settings, "cal-use-system-timezone"); + + if (use_system_timezone) return e_cal_util_get_system_timezone_location (); return calendar_config_get_timezone_stored (); @@ -309,107 +260,6 @@ calendar_config_add_notification_24_hour_format (GConfClientNotifyFunc func, gpo return id; } -/* Show RSVP*/ -gboolean -calendar_config_get_show_rsvp (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_RSVP, NULL); -} - -void -calendar_config_set_show_rsvp (gboolean state) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_RSVP, state, NULL); -} - -/* Show Role*/ -gboolean -calendar_config_get_show_role (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_ROLE, NULL); -} - -void -calendar_config_set_show_role (gboolean state) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_ROLE, state, NULL); -} - -/* Show Type*/ -gboolean -calendar_config_get_show_type (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_TYPE, NULL); -} - -void -calendar_config_set_show_type (gboolean state) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_TYPE, state, NULL); -} - -/* Show status */ -gboolean -calendar_config_get_show_status (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_STATUS, NULL); -} - -void -calendar_config_set_show_status (gboolean state) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_STATUS, state, NULL); -} - -/* Show timezone */ -gboolean -calendar_config_get_show_timezone (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_TIMEZONE, NULL); -} - -void -calendar_config_set_show_timezone (gboolean status) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_TIMEZONE, status, NULL); -} - -gboolean -calendar_config_get_show_categories (void) -{ - calendar_config_init (); - - return gconf_client_get_bool (config, CALENDAR_CONFIG_SHOW_CATEGORIES, NULL); -} -void -calendar_config_set_show_categories (gboolean status) -{ - calendar_config_init (); - - gconf_client_set_bool (config, CALENDAR_CONFIG_SHOW_CATEGORIES, status, NULL); -} - - /* The start day of the week (0 = Sun to 6 = Mon). */ gint calendar_config_get_week_start_day (void) diff --git a/calendar/gui/calendar-config.h b/calendar/gui/calendar-config.h index c7f0556ac8..adcf2c0c37 100644 --- a/calendar/gui/calendar-config.h +++ b/calendar/gui/calendar-config.h @@ -68,16 +68,6 @@ GSList *calendar_config_get_calendars_selected (void); void calendar_config_set_calendars_selected (GSList *selected); guint calendar_config_add_notification_calendars_selected (GConfClientNotifyFunc func, gpointer data); -/* The primary calendar */ -gchar *calendar_config_get_primary_calendar (void); -void calendar_config_set_primary_calendar (const gchar *primary_uid); -guint calendar_config_add_notification_primary_calendar (GConfClientNotifyFunc func, gpointer data); - -/* Use system timezone; if TRUE, then influences also the current timezone functions. */ -gboolean calendar_config_get_use_system_timezone (void); -void calendar_config_set_use_system_timezone (gboolean use); -guint calendar_config_add_notification_use_system_timezone (GConfClientNotifyFunc func, gpointer data); - /* The current timezone, e.g. "Europe/London". */ gchar * calendar_config_get_timezone (void); gchar * calendar_config_get_timezone_stored (void); @@ -117,25 +107,6 @@ gboolean calendar_config_get_24_hour_format (void); void calendar_config_set_24_hour_format (gboolean use_24_hour); guint calendar_config_add_notification_24_hour_format (GConfClientNotifyFunc func, gpointer data); -gboolean calendar_config_get_show_status (void); -void calendar_config_set_show_status (gboolean status); - -gboolean calendar_config_get_show_type (void); -void calendar_config_set_show_type (gboolean status); - -gboolean calendar_config_get_show_rsvp (void); -void calendar_config_set_show_rsvp (gboolean status); - -gboolean calendar_config_get_show_timezone (void); -void calendar_config_set_show_timezone (gboolean status); - -gboolean calendar_config_get_show_categories (void); -void calendar_config_set_show_categories (gboolean status); - -gboolean calendar_config_get_show_role (void); -void calendar_config_set_show_role (gboolean state); - - /* The time divisions in the Day/Work-Week view in minutes (5/10/15/30/60). */ gint calendar_config_get_time_divisions (void); void calendar_config_set_time_divisions (gint divisions); diff --git a/calendar/gui/calendar-view-factory.c b/calendar/gui/calendar-view-factory.c index 95497b1782..34e8344a88 100644 --- a/calendar/gui/calendar-view-factory.c +++ b/calendar/gui/calendar-view-factory.c @@ -181,7 +181,7 @@ calendar_view_factory_new_view (GalViewFactory *factory, const gchar *name) * * Return value: The same value as @cal_view_factory. **/ -CalendarViewFactory * +GalViewFactory * calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, GnomeCalendarViewType view_type) { @@ -194,7 +194,7 @@ calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, priv->view_type = view_type; - return cal_view_factory; + return GAL_VIEW_FACTORY (cal_view_factory); } /** @@ -205,7 +205,7 @@ calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, * * Return value: A newly-created calendar view factory. **/ -CalendarViewFactory * +GalViewFactory * calendar_view_factory_new (GnomeCalendarViewType view_type) { CalendarViewFactory *cal_view_factory; diff --git a/calendar/gui/calendar-view-factory.h b/calendar/gui/calendar-view-factory.h index 0f182a11e1..c0b90f2bd9 100644 --- a/calendar/gui/calendar-view-factory.h +++ b/calendar/gui/calendar-view-factory.h @@ -57,10 +57,10 @@ typedef struct { GType calendar_view_factory_get_type (void); -CalendarViewFactory *calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, +GalViewFactory *calendar_view_factory_construct (CalendarViewFactory *cal_view_factory, GnomeCalendarViewType view_type); -CalendarViewFactory *calendar_view_factory_new (GnomeCalendarViewType view_type); +GalViewFactory *calendar_view_factory_new (GnomeCalendarViewType view_type); diff --git a/calendar/gui/comp-editor-factory.c b/calendar/gui/comp-editor-factory.c deleted file mode 100644 index 6a1c71740f..0000000000 --- a/calendar/gui/comp-editor-factory.c +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Evolution calendar - Component editor factory object - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Federico Mena-Quintero <federico@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <glib/gi18n.h> -#include <bonobo/bonobo-exception.h> -#include <evolution-calendar.h> -#include <libedataserver/e-url.h> -#include <libecal/e-cal.h> -#include "calendar-config.h" -#include "e-comp-editor-registry.h" -#include "comp-editor-factory.h" -#include "comp-util.h" -#include "common/authentication.h" -#include "dialogs/event-editor.h" -#include "dialogs/task-editor.h" - -extern ECompEditorRegistry *comp_editor_registry; - - - -/* A pending request */ - -typedef enum { - REQUEST_EXISTING, - REQUEST_NEW -} RequestType; - -typedef struct { - RequestType type; - - union { - struct { - gchar *uid; - } existing; - - struct { - GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type; - } new; - } u; -} Request; - -/* A client we have open */ -typedef struct { - /* Our parent CompEditorFactory */ - CompEditorFactory *factory; - - /* Uri of the calendar, used as key in the clients hash table */ - gchar *uri; - - /* Client of the calendar */ - ECal *client; - - /* Count editors using this client */ - gint editor_count; - - /* Pending requests; they are pending if the client is still being opened */ - GSList *pending; - - /* Whether this is open or still waiting */ - guint open : 1; -} OpenClient; - -/* Private part of the CompEditorFactory structure */ -struct CompEditorFactoryPrivate { - /* Hash table of URI->OpenClient */ - GHashTable *uri_client_hash; -}; - - - -static void comp_editor_factory_class_init (CompEditorFactoryClass *class); -static void comp_editor_factory_init (CompEditorFactory *factory); -static void comp_editor_factory_finalize (GObject *object); - -static void impl_editExisting (PortableServer_Servant servant, - const CORBA_char *str_uri, - const CORBA_char *uid, - const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode corba_type, - CORBA_Environment *ev); -static void impl_editNew (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CalObjType type, - CORBA_Environment *ev); - -static BonoboObjectClass *parent_class = NULL; - - - -BONOBO_TYPE_FUNC_FULL (CompEditorFactory, - GNOME_Evolution_Calendar_CompEditorFactory, - BONOBO_OBJECT_TYPE, - comp_editor_factory) - -/* Class initialization function for the component editor factory */ -static void -comp_editor_factory_class_init (CompEditorFactoryClass *class) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) class; - - parent_class = g_type_class_peek_parent (class); - - class->epv.editExisting = impl_editExisting; - class->epv.editNew = impl_editNew; - - object_class->finalize = comp_editor_factory_finalize; -} - -/* Frees a Request structure */ -static void -free_request (Request *r) -{ - if (r->type == REQUEST_EXISTING) - g_free (r->u.existing.uid); - - g_free (r); -} - -/* Frees an OpenClient structure */ -static void -free_client (OpenClient *oc) -{ - GSList *l; - - g_free (oc->uri); - oc->uri = NULL; - - g_object_unref (oc->client); - oc->client = NULL; - - for (l = oc->pending; l; l = l->next) { - Request *r; - - r = l->data; - free_request (r); - } - g_slist_free (oc->pending); - oc->pending = NULL; - - g_free (oc); -} - -/* Object initialization function for the component editor factory */ -static void -comp_editor_factory_init (CompEditorFactory *factory) -{ - CompEditorFactoryPrivate *priv; - - priv = g_new (CompEditorFactoryPrivate, 1); - factory->priv = priv; - - priv->uri_client_hash = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) free_client); -} - -/* Destroy handler for the component editor factory */ -static void -comp_editor_factory_finalize (GObject *object) -{ - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_COMP_EDITOR_FACTORY (object)); - - factory = COMP_EDITOR_FACTORY (object); - priv = factory->priv; - - g_hash_table_destroy (priv->uri_client_hash); - priv->uri_client_hash = NULL; - - g_free (priv); - factory->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - - - -/* Callback used when a component editor gets destroyed */ -static void -editor_destroy_cb (GtkObject *object, gpointer data) -{ - OpenClient *oc; - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - - oc = data; - factory = oc->factory; - priv = factory->priv; - - oc->editor_count--; - - /* See if we need to free the client */ - g_return_if_fail (oc->pending == NULL); - - if (oc->editor_count != 0) - return; - - g_hash_table_remove (priv->uri_client_hash, oc->uri); -} - -/* Starts editing an existing component on a client that is already open */ -static void -edit_existing (OpenClient *oc, const gchar *uid) -{ - ECalComponent *comp; - icalcomponent *icalcomp; - CompEditor *editor; - ECalComponentVType vtype; - CompEditorFlags flags = { 0, }; - - g_return_if_fail (oc->open); - - /* Get the object */ - if (!e_cal_get_object (oc->client, uid, NULL, &icalcomp, NULL)) { - /* FIXME Better error handling */ - g_warning (G_STRLOC ": Syntax error while getting component `%s'", uid); - - return; - } - - comp = e_cal_component_new (); - if (!e_cal_component_set_icalcomponent (comp, icalcomp)) { - g_object_unref (comp); - icalcomponent_free (icalcomp); - return; - } - - /* Create the appropriate type of editor */ - - vtype = e_cal_component_get_vtype (comp); - if (itip_organizer_is_user (comp, oc->client)) - flags |= COMP_EDITOR_USER_ORG; - - - switch (vtype) { - case E_CAL_COMPONENT_EVENT: - if (e_cal_component_has_attendees (comp)) - flags |= COMP_EDITOR_MEETING; - - editor = event_editor_new (oc->client, flags); - break; - - case E_CAL_COMPONENT_TODO: - editor = COMP_EDITOR (task_editor_new (oc->client, flags)); - break; - - default: - g_message ("edit_exiting(): Unsupported object type %d", (gint) vtype); - g_object_unref (comp); - return; - } - - /* Set the object on the editor */ - comp_editor_edit_comp (editor, comp); - gtk_window_present (GTK_WINDOW (editor)); - g_object_unref (comp); - - oc->editor_count++; - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), oc); - - e_comp_editor_registry_add (comp_editor_registry, editor, TRUE); -} - -static ECalComponent * -get_default_task (ECal *client) -{ - ECalComponent *comp; - - comp = cal_comp_task_new_with_defaults (client); - - return comp; -} - -/* Edits a new object in the context of a client */ -static void -edit_new (OpenClient *oc, const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type) -{ - ECalComponent *comp; - CompEditor *editor; - - switch (type) { - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT: - editor = event_editor_new (oc->client, FALSE); - comp = cal_comp_event_new_with_current_time (oc->client, FALSE); - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING: - editor = event_editor_new (oc->client, TRUE); - comp = cal_comp_event_new_with_current_time (oc->client, FALSE); - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_ALLDAY_EVENT: - editor = event_editor_new (oc->client, FALSE); - comp = cal_comp_event_new_with_current_time (oc->client, TRUE); - break; - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO: - editor = COMP_EDITOR (task_editor_new (oc->client, FALSE)); - comp = get_default_task (oc->client); - break; - default: - g_return_if_reached (); - return; - } - - comp_editor_edit_comp (editor, comp); - if (type == GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_MEETING) - event_editor_show_meeting (EVENT_EDITOR (editor)); - gtk_window_present (GTK_WINDOW (editor)); - - oc->editor_count++; - g_signal_connect (editor, "destroy", G_CALLBACK (editor_destroy_cb), oc); - - e_comp_editor_registry_add (comp_editor_registry, editor, TRUE); -} - -/* Resolves all the pending requests for a client */ -static void -resolve_pending_requests (OpenClient *oc) -{ - GSList *l; - icaltimezone *zone; - - if (!oc->pending) - return; - - /* Set the default timezone in the backend. */ - zone = calendar_config_get_icaltimezone (); - - /* FIXME Error handling? */ - e_cal_set_default_timezone (oc->client, zone, NULL); - - for (l = oc->pending; l; l = l->next) { - Request *request; - - request = l->data; - - switch (request->type) { - case REQUEST_EXISTING: - edit_existing (oc, request->u.existing.uid); - break; - - case REQUEST_NEW: - edit_new (oc, request->u.new.type); - break; - } - - free_request (request); - } - - g_slist_free (oc->pending); - oc->pending = NULL; -} - -/* Callback used when a client is finished opening. We resolve all the pending - * requests. - */ -static void -cal_opened_cb (ECal *client, ECalendarStatus status, gpointer data) -{ - OpenClient *oc; - CompEditorFactory *factory; - CompEditorFactoryPrivate *priv; - GtkWidget *dialog = NULL; - - oc = data; - factory = oc->factory; - priv = factory->priv; - - switch (status) { - case E_CALENDAR_STATUS_OK: - oc->open = TRUE; - resolve_pending_requests (oc); - return; - - case E_CALENDAR_STATUS_OTHER_ERROR: - case E_CALENDAR_STATUS_NO_SUCH_CALENDAR: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Error while opening the calendar")); - break; - - case E_CALENDAR_STATUS_PROTOCOL_NOT_SUPPORTED: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Method not supported when opening the calendar")); - break; - - case E_CALENDAR_STATUS_PERMISSION_DENIED : - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Permission denied to open the calendar")); - break; - - case E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Authentication Required")); - break; - - case E_CALENDAR_STATUS_AUTHENTICATION_FAILED : - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Authentication Failed")); - break; - - default: - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", _("Unknown error")); - return; - } - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_hash_table_remove (priv->uri_client_hash, oc->uri); -} - -/* Creates a new OpenClient structure and queues the component editing/creation - * process until the client is open. Returns NULL if it could not issue the - * open request. - */ -static OpenClient * -open_client (CompEditorFactory *factory, ECalSourceType source_type, const gchar *uristr) -{ - CompEditorFactoryPrivate *priv; - ECal *client; - OpenClient *oc; - GError *error = NULL; - - priv = factory->priv; - - client = auth_new_cal_from_uri (uristr, source_type); - if (!client) - return NULL; - - oc = g_new (OpenClient, 1); - oc->factory = factory; - - oc->uri = g_strdup (uristr); - - oc->client = client; - oc->editor_count = 0; - oc->pending = NULL; - oc->open = FALSE; - - g_signal_connect (oc->client, "cal_opened", G_CALLBACK (cal_opened_cb), oc); - - g_hash_table_insert (priv->uri_client_hash, oc->uri, oc); - - if (!e_cal_open (oc->client, FALSE, &error)) { - g_warning (G_STRLOC ": %s", error->message); - g_free (oc->uri); - g_object_unref (oc->client); - g_free (oc); - g_error_free (error); - - return NULL; - } - - return oc; -} - -/* Looks up an open client or queues it for being opened. Returns the client or - * NULL on failure; in the latter case it sets the ev exception. - */ -static OpenClient * -lookup_open_client (CompEditorFactory *factory, ECalSourceType source_type, const gchar *str_uri, CORBA_Environment *ev) -{ - CompEditorFactoryPrivate *priv; - OpenClient *oc; - EUri *uri; - - priv = factory->priv; - - /* Look up the client */ - - uri = e_uri_new (str_uri); - if (!uri) { - bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CompEditorFactory_InvalidURI); - return NULL; - } - e_uri_free (uri); - - oc = g_hash_table_lookup (priv->uri_client_hash, str_uri); - if (!oc) { - oc = open_client (factory, source_type, str_uri); - if (!oc) { - bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_CompEditorFactory_BackendContactError); - return NULL; - } - } - - return oc; -} - -/* Queues a request for editing an existing object */ -static void -queue_edit_existing (OpenClient *oc, const gchar *uid) -{ - Request *request; - - g_return_if_fail (!oc->open); - - request = g_new (Request, 1); - request->type = REQUEST_EXISTING; - request->u.existing.uid = g_strdup (uid); - - oc->pending = g_slist_append (oc->pending, request); -} - -/* ::editExisting() method implementation */ -static void -impl_editExisting (PortableServer_Servant servant, - const CORBA_char *str_uri, - const CORBA_char *uid, - const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode corba_type, - CORBA_Environment *ev) -{ - CompEditorFactory *factory; - OpenClient *oc; - CompEditor *editor; - ECalSourceType source_type; - - factory = COMP_EDITOR_FACTORY (bonobo_object_from_servant (servant)); - - switch (corba_type) { - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO: - source_type = E_CAL_SOURCE_TYPE_TODO; - break; - default: - source_type = E_CAL_SOURCE_TYPE_EVENT; - } - - oc = lookup_open_client (factory, source_type, str_uri, ev); - if (!oc) - return; - - if (!oc->open) { - queue_edit_existing (oc, uid); - return; - } - - /* Look up the component */ - editor = e_comp_editor_registry_find (comp_editor_registry, uid); - if (editor == NULL) { - edit_existing (oc, uid); - } else { - gtk_window_present (GTK_WINDOW (editor)); - } -} - -/* Queues a request for creating a new object */ -static void -queue_edit_new (OpenClient *oc, const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode type) -{ - Request *request; - - g_return_if_fail (!oc->open); - - request = g_new (Request, 1); - request->type = REQUEST_NEW; - request->u.new.type = type; - - oc->pending = g_slist_append (oc->pending, request); -} - -/* ::editNew() method implementation */ -static void -impl_editNew (PortableServer_Servant servant, - const CORBA_char *str_uri, - const GNOME_Evolution_Calendar_CompEditorFactory_CompEditorMode corba_type, - CORBA_Environment *ev) -{ - CompEditorFactory *factory; - OpenClient *oc; - ECalSourceType source_type; - - factory = COMP_EDITOR_FACTORY (bonobo_object_from_servant (servant)); - - switch (corba_type) { - case GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_TODO: - source_type = E_CAL_SOURCE_TYPE_TODO; - break; - default: - source_type = E_CAL_SOURCE_TYPE_EVENT; - } - - oc = lookup_open_client (factory, source_type, str_uri, ev); - if (!oc) - return; - - if (!oc->open) - queue_edit_new (oc, corba_type); - else - edit_new (oc, corba_type); -} - - - -/** - * comp_editor_factory_new: - * - * Creates a new calendar component editor factory. - * - * Return value: A newly-created component editor factory. - **/ -CompEditorFactory * -comp_editor_factory_new (void) -{ - return g_object_new (TYPE_COMP_EDITOR_FACTORY, NULL); -} - - diff --git a/calendar/gui/comp-editor-factory.h b/calendar/gui/comp-editor-factory.h deleted file mode 100644 index 3e79992d67..0000000000 --- a/calendar/gui/comp-editor-factory.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Evolution calendar - Component editor factory object - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Federico Mena-Quintero <federico@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef COMP_EDITOR_FACTORY_H -#define COMP_EDITOR_FACTORY_H - -#include <bonobo/bonobo-object.h> -#include "evolution-calendar.h" - - - -#define TYPE_COMP_EDITOR_FACTORY (comp_editor_factory_get_type ()) -#define COMP_EDITOR_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMP_EDITOR_FACTORY, \ - CompEditorFactory)) -#define COMP_EDITOR_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TYPE_COMP_EDITOR_FACTORY, CompEditorFactoryClass)) -#define IS_COMP_EDITOR_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMP_EDITOR_FACTORY)) -#define IS_COMP_EDITOR_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COMP_EDITOR_FACTORY)) - -typedef struct CompEditorFactoryPrivate CompEditorFactoryPrivate; - -typedef struct { - BonoboObject object; - - /* Private data */ - CompEditorFactoryPrivate *priv; -} CompEditorFactory; - -typedef struct { - BonoboObjectClass parent_class; - - POA_GNOME_Evolution_Calendar_CompEditorFactory__epv epv; -} CompEditorFactoryClass; - -GType comp_editor_factory_get_type (void); - -CompEditorFactory *comp_editor_factory_new (void); - - - -#endif diff --git a/calendar/gui/control-factory.c b/calendar/gui/control-factory.c deleted file mode 100644 index 3e7b7499cc..0000000000 --- a/calendar/gui/control-factory.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Ettore Perazzoli <ettore@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include <config.h> -#include <string.h> -#include <gtk/gtk.h> -#include <glade/glade.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-persist-file.h> -#include <bonobo/bonobo-context.h> -#include <glade/glade.h> - -#include <libecal/e-cal-time-util.h> -#include <gui/gnome-cal.h> -#include <gui/calendar-commands.h> -#include <gui/calendar-config.h> - -#include "control-factory.h" - -/* Are these supposed to be global or static? */ -CORBA_Environment ev; -CORBA_ORB orb; - -static void -control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - if (activate) - calendar_control_activate (control, gcal); - else - calendar_control_deactivate (control, gcal); -} - -BonoboControl * -control_factory_new_control (void) -{ - BonoboControl *control; - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (gnome_calendar_new ()); - if (!gcal) - return NULL; - - gtk_widget_show (GTK_WIDGET (gcal)); - - control = bonobo_control_new (GTK_WIDGET (gcal)); - if (!control) { - g_message ("control_factory_fn(): could not create the control!"); - return NULL; - } - g_object_set_data (G_OBJECT (gcal), "control", control); - - g_signal_connect (control, "activate", G_CALLBACK (control_activate_cb), gcal); - - return control; -} diff --git a/calendar/gui/dialogs/cal-prefs-dialog.c b/calendar/gui/dialogs/cal-prefs-dialog.c index 96f91c741f..af4c4b8e1a 100644 --- a/calendar/gui/dialogs/cal-prefs-dialog.c +++ b/calendar/gui/dialogs/cal-prefs-dialog.c @@ -31,6 +31,7 @@ #include "../calendar-config.h" #include "cal-prefs-dialog.h" #include <widgets/misc/e-dateedit.h> +#include <e-util/e-binding.h> #include <e-util/e-dialog-widgets.h> #include <e-util/e-util-private.h> #include <glib/gi18n.h> @@ -486,7 +487,9 @@ template_url_changed (GtkEntry *entry, CalendarPrefsDialog *prefs) } static void -update_system_tz_widgets (CalendarPrefsDialog *prefs) +update_system_tz_widgets (EShellSettings *shell_settings, + GParamSpec *pspec, + CalendarPrefsDialog *prefs) { icaltimezone *zone; @@ -498,15 +501,6 @@ update_system_tz_widgets (CalendarPrefsDialog *prefs) } else { gtk_label_set_text (GTK_LABEL (prefs->system_tz_label), "(UTC)"); } - - gtk_widget_set_sensitive (prefs->timezone, !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->use_system_tz_check))); -} - -static void -use_system_tz_changed (GtkWidget *check, CalendarPrefsDialog *prefs) -{ - calendar_config_set_use_system_timezone (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check))); - update_system_tz_widgets (prefs); } static void @@ -517,7 +511,6 @@ setup_changes (CalendarPrefsDialog *prefs) for (i = 0; i < 7; i ++) g_signal_connect (G_OBJECT (prefs->working_days[i]), "toggled", G_CALLBACK (working_days_changed), prefs); - g_signal_connect (G_OBJECT (prefs->use_system_tz_check), "toggled", G_CALLBACK (use_system_tz_changed), prefs); g_signal_connect (G_OBJECT (prefs->timezone), "changed", G_CALLBACK (timezone_changed), prefs); g_signal_connect (G_OBJECT (prefs->day_second_zone), "clicked", G_CALLBACK (day_second_zone_clicked), prefs); @@ -652,11 +645,6 @@ show_config (CalendarPrefsDialog *prefs) CalUnits units; gint interval; - /* Use system timezone */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->use_system_tz_check), calendar_config_get_use_system_timezone ()); - gtk_widget_set_sensitive (prefs->system_tz_label, FALSE); - update_system_tz_widgets (prefs); - /* Timezone. */ location = calendar_config_get_timezone_stored (); zone = icaltimezone_get_builtin_timezone (location); @@ -666,6 +654,9 @@ show_config (CalendarPrefsDialog *prefs) /* Day's second zone */ update_day_second_zone_caption (prefs); + /* Day's second zone */ + update_day_second_zone_caption (prefs); + /* Working Days. */ working_days = calendar_config_get_working_days (); mask = 1 << 0; @@ -759,13 +750,16 @@ eccp_free (EConfig *ec, GSList *items, gpointer data) } static void -calendar_prefs_dialog_construct (CalendarPrefsDialog *prefs) +calendar_prefs_dialog_construct (CalendarPrefsDialog *prefs, + EShell *shell) { GladeXML *gui; ECalConfig *ec; ECalConfigTargetPrefs *target; + EShellSettings *shell_settings; gint i; GtkWidget *toplevel; + GtkWidget *widget; GSList *l; const gchar *working_day_names[] = { "sun_button", @@ -778,6 +772,8 @@ calendar_prefs_dialog_construct (CalendarPrefsDialog *prefs) }; gchar *gladefile; + shell_settings = e_shell_get_shell_settings (shell); + gladefile = g_build_filename (EVOLUTION_GLADEDIR, "cal-prefs-dialog.glade", NULL); @@ -801,8 +797,20 @@ calendar_prefs_dialog_construct (CalendarPrefsDialog *prefs) l = g_slist_prepend (l, &eccp_items[i]); e_config_add_items ((EConfig *) ec, l, NULL, NULL, eccp_free, prefs); + widget = glade_xml_get_widget (gui, "use-system-tz-check"); + e_mutual_binding_new ( + G_OBJECT (shell_settings), "cal-use-system-timezone", + G_OBJECT (widget), "active"); + g_signal_connect ( + G_OBJECT (shell_settings), "notify::cal-use-system-timezone", + G_CALLBACK (update_system_tz_widgets), prefs); + + widget = glade_xml_get_widget (gui, "timezone"); + e_mutual_binding_new_with_negation ( + G_OBJECT (shell_settings), "cal-use-system-timezone", + G_OBJECT (widget), "sensitive"); + /* General tab */ - prefs->use_system_tz_check = glade_xml_get_widget (gui, "use-system-tz-check"); prefs->system_tz_label = glade_xml_get_widget (gui, "system-tz-label"); prefs->timezone = glade_xml_get_widget (gui, "timezone"); prefs->day_second_zone = glade_xml_get_widget (gui, "day_second_zone"); @@ -873,14 +881,18 @@ calendar_prefs_dialog_get_type (void) } GtkWidget * -calendar_prefs_dialog_new (void) +calendar_prefs_dialog_new (EShell *shell) { CalendarPrefsDialog *dialog; - dialog = (CalendarPrefsDialog *) g_object_new (calendar_prefs_dialog_get_type (), NULL); - calendar_prefs_dialog_construct (dialog); + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + + dialog = g_object_new (CALENDAR_TYPE_PREFS_DIALOG, NULL); + + /* FIXME Kill this function. */ + calendar_prefs_dialog_construct (dialog, shell); - return (GtkWidget *) dialog; + return GTK_WIDGET (dialog); } /* called by libglade to create our custom EDateEdit widgets. */ diff --git a/calendar/gui/dialogs/cal-prefs-dialog.h b/calendar/gui/dialogs/cal-prefs-dialog.h index 647df417df..397cb35cfa 100644 --- a/calendar/gui/dialogs/cal-prefs-dialog.h +++ b/calendar/gui/dialogs/cal-prefs-dialog.h @@ -21,14 +21,33 @@ * */ -#ifndef _CAL_PREFS_DIALOG_H_ -#define _CAL_PREFS_DIALOG_H_ +#ifndef CAL_PREFS_DIALOG_H +#define CAL_PREFS_DIALOG_H #include <gtk/gtk.h> #include <glade/glade.h> #include <gconf/gconf-client.h> #include <libedataserverui/e-source-selector.h> -#include "evolution-config-control.h" +#include <shell/e-shell.h> + +/* Standard GObject macros */ +#define CALENDAR_TYPE_PREFS_DIALOG \ + (calendar_prefs_dialog_get_type ()) +#define CALENDAR_PREFS_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), CALENDAR_TYPE_PREFS_DIALOG, CalendarPrefsDialog)) +#define CALENDAR_PREFS_DIALOG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), CALENDAR_TYPE_PREFS_DIALOG, CalendarPrefsDialogClass)) +#define CALENDAR_IS_PREFS_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), CALENDAR_TYPE_PREFS_DIALOG)) +#define CALENDAR_IS_PREFS_DIALOG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), CALENDAR_TYPE_PREFS_DIALOG)) +#define CALENDAR_PREFS_DIALOG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), CALENDAR_TYPE_PREFS_DIALOG, CalendarPrefsDialogClass)) G_BEGIN_DECLS @@ -43,7 +62,6 @@ struct _CalendarPrefsDialog { GConfClient *gconf; /* General tab */ - GtkWidget *use_system_tz_check; GtkWidget *system_tz_label; GtkWidget *timezone; GtkWidget *day_second_zone; @@ -95,9 +113,9 @@ struct _CalendarPrefsDialogClass { GtkVBoxClass parent; }; -GType calendar_prefs_dialog_get_type (void); -GtkWidget *calendar_prefs_dialog_new (void); +GType calendar_prefs_dialog_get_type (void); +GtkWidget * calendar_prefs_dialog_new (EShell *shell); G_END_DECLS -#endif /* _CAL_PREFS_DIALOG_H_ */ +#endif /* CAL_PREFS_DIALOG_H */ diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index ba43eaf98d..64f80b4557 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -39,7 +39,7 @@ #include <e-util/e-dialog-utils.h> #include <e-util/e-util-private.h> #include <e-util/gconf-bridge.h> -#include <evolution-shell-component-utils.h> +#include <shell/e-shell.h> #include <camel/camel-url.h> #include <camel/camel-exception.h> @@ -76,6 +76,9 @@ /* Private part of the CompEditor structure */ struct _CompEditorPrivate { + + gpointer shell; /* weak pointer */ + /* Client to use */ ECal *client; @@ -125,6 +128,7 @@ enum { PROP_CHANGED, PROP_CLIENT, PROP_FLAGS, + PROP_SHELL, PROP_SUMMARY }; @@ -133,7 +137,10 @@ static const gchar *ui = " <menubar action='main-menu'>" " <menu action='file-menu'>" " <menuitem action='save'/>" +" <separator/>" +" <menuitem action='print-preview'/>" " <menuitem action='print'/>" +" <separator/>" " <menuitem action='close'/>" " </menu>" " <menu action='edit-menu'>" @@ -170,8 +177,8 @@ static void close_dialog (CompEditor *editor); static void page_dates_changed_cb (CompEditor *editor, CompEditorPageDates *dates, CompEditorPage *page); -static void obj_modified_cb (ECal *client, GList *objs, gpointer data); -static void obj_removed_cb (ECal *client, GList *uids, gpointer data); +static void obj_modified_cb (ECal *client, GList *objs, CompEditor *editor); +static void obj_removed_cb (ECal *client, GList *uids, CompEditor *editor); G_DEFINE_TYPE (CompEditor, comp_editor, GTK_TYPE_WINDOW) @@ -180,7 +187,15 @@ enum { LAST_SIGNAL }; -static guint comp_editor_signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL]; +static GList *active_editors; + +static void +comp_editor_weak_notify_cb (gpointer unused, + GObject *where_the_object_was) +{ + active_editors = g_list_remove (active_editors, where_the_object_was); +} static void attachment_store_changed_cb (CompEditor *editor) @@ -707,17 +722,22 @@ action_print_cb (GtkAction *action, CompEditor *editor) { CompEditorPrivate *priv = editor->priv; + GtkPrintOperationAction print_action; ECalComponent *comp; GList *l; - icalcomponent *icalcomp = e_cal_component_get_icalcomponent (priv->comp); + icalcomponent *component; + icalcomponent *clone; comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (icalcomp)); + component = e_cal_component_get_icalcomponent (priv->comp); + clone = icalcomponent_new_clone (component); + e_cal_component_set_icalcomponent (comp, clone); for (l = priv->pages; l != NULL; l = l->next) comp_editor_page_fill_component (l->data, comp); - print_comp (comp, priv->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); + print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; + print_comp (comp, priv->client, print_action); g_object_unref (comp); } @@ -727,15 +747,22 @@ action_print_preview_cb (GtkAction *action, CompEditor *editor) { CompEditorPrivate *priv = editor->priv; + GtkPrintOperationAction print_action; ECalComponent *comp; GList *l; - icalcomponent *icalcomp = e_cal_component_get_icalcomponent (priv->comp); + icalcomponent *component; + icalcomponent *clone; comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (icalcomp)); + component = e_cal_component_get_icalcomponent (priv->comp); + clone = icalcomponent_new_clone (component); + e_cal_component_set_icalcomponent (comp, clone); + for (l = priv->pages; l != NULL; l = l->next) comp_editor_page_fill_component (l->data, comp); - print_comp (comp, priv->client, TRUE); + + print_action = GTK_PRINT_OPERATION_ACTION_PREVIEW; + print_comp (comp, priv->client, print_action); g_object_unref (comp); } @@ -803,12 +830,10 @@ action_save_cb (GtkAction *action, if (e_cal_component_has_recurrences (priv->comp)) { if (!recur_component_dialog (priv->client, priv->comp, &priv->mod, GTK_WINDOW (editor), delegated)) return; - } else if (e_cal_component_is_instance (priv->comp)) priv->mod = CALOBJ_MOD_THIS; comp = comp_editor_get_current_comp (editor, &correct); - e_cal_component_get_summary (comp, &text); g_object_unref (comp); @@ -1190,6 +1215,17 @@ comp_editor_setup_recent_menu (CompEditor *editor) } static void +comp_editor_set_shell (CompEditor *editor, + EShell *shell) +{ + g_return_if_fail (editor->priv->shell == NULL); + + editor->priv->shell = shell; + + g_object_add_weak_pointer (G_OBJECT (shell), &editor->priv->shell); +} + +static void comp_editor_set_property (GObject *object, guint property_id, const GValue *value, @@ -1214,6 +1250,12 @@ comp_editor_set_property (GObject *object, g_value_get_int (value)); return; + case PROP_SHELL: + comp_editor_set_shell ( + COMP_EDITOR (object), + g_value_get_object (value)); + return; + case PROP_SUMMARY: comp_editor_set_summary ( COMP_EDITOR (object), @@ -1249,6 +1291,12 @@ comp_editor_get_property (GObject *object, COMP_EDITOR (object))); return; + case PROP_SHELL: + g_value_set_object ( + value, comp_editor_get_shell ( + COMP_EDITOR (object))); + return; + case PROP_SUMMARY: g_value_set_string ( value, comp_editor_get_summary ( @@ -1266,6 +1314,12 @@ comp_editor_dispose (GObject *object) priv = COMP_EDITOR_GET_PRIVATE (object); + if (priv->shell != NULL) { + g_object_remove_weak_pointer ( + G_OBJECT (priv->shell), &priv->shell); + priv->shell = NULL; + } + if (priv->client) { g_object_unref (priv->client); priv->client = NULL; @@ -1324,42 +1378,39 @@ static void comp_editor_map (GtkWidget *widget) { CompEditor *editor = COMP_EDITOR (widget); - GConfBridge *bridge = gconf_bridge_get (); + GConfBridge *bridge; GtkAction *action; + const gchar *key; + + bridge = gconf_bridge_get (); /* Give subclasses a chance to construct their pages before * we fiddle with their widgets. That's why we don't do this * until after object construction. */ + key = "/apps/evolution/calendar/display/show_categories"; action = comp_editor_get_action (editor, "view-categories"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_CATEGORIES, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); + key = "/apps/evolution/calendar/display/show_role"; action = comp_editor_get_action (editor, "view-role"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_ROLE, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); + key = "/apps/evolution/calendar/display/show_rsvp"; action = comp_editor_get_action (editor, "view-rsvp"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_RSVP, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); + key = "/apps/evolution/calendar/display/show_status"; action = comp_editor_get_action (editor, "view-status"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_STATUS, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); + key = "/apps/evolution/calendar/display/show_timezone"; action = comp_editor_get_action (editor, "view-time-zone"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_TIMEZONE, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); + key = "/apps/evolution/calendar/display/show_type"; action = comp_editor_get_action (editor, "view-type"); - gconf_bridge_bind_property ( - bridge, CALENDAR_CONFIG_SHOW_TYPE, - G_OBJECT (action), "active"); + gconf_bridge_bind_property (bridge, key, G_OBJECT (action), "active"); /* Chain up to parent's map() method. */ GTK_WIDGET_CLASS (comp_editor_parent_class)->map (widget); @@ -1506,6 +1557,17 @@ comp_editor_class_init (CompEditorClass *class) g_object_class_install_property ( object_class, + PROP_SHELL, + g_param_spec_object ( + "shell", + NULL, + NULL, + E_TYPE_SHELL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property ( + object_class, PROP_SUMMARY, g_param_spec_string ( "summary", @@ -1514,7 +1576,7 @@ comp_editor_class_init (CompEditorClass *class) NULL, G_PARAM_READWRITE)); - comp_editor_signals[OBJECT_CREATED] = + signals[OBJECT_CREATED] = g_signal_new ("object_created", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_LAST, @@ -1537,11 +1599,18 @@ comp_editor_init (CompEditor *editor) GtkAction *action; GtkWidget *container; GtkWidget *widget; + EShell *shell; gint n_targets; GError *error = NULL; editor->priv = priv = COMP_EDITOR_GET_PRIVATE (editor); + g_object_weak_ref ( + G_OBJECT (editor), (GWeakNotify) + comp_editor_weak_notify_cb, NULL); + + active_editors = g_list_prepend (active_editors, editor); + priv->pages = NULL; priv->changed = FALSE; priv->needs_send = FALSE; @@ -1675,6 +1744,10 @@ comp_editor_init (CompEditor *editor) g_signal_connect_swapped ( store, "row-inserted", G_CALLBACK (attachment_store_changed_cb), editor); + + /* FIXME Shell should be passed in. */ + shell = e_shell_get_default (); + e_shell_watch_window (shell, GTK_WINDOW (editor)); } static gboolean @@ -1757,7 +1830,18 @@ close_dialog (CompEditor *editor) gtk_widget_destroy (GTK_WIDGET (editor)); } - +gint +comp_editor_compare (CompEditor *editor_a, + CompEditor *editor_b) +{ + const gchar *uid_a = NULL; + const gchar *uid_b = NULL; + + e_cal_component_get_uid (editor_a->priv->comp, &uid_a); + e_cal_component_get_uid (editor_b->priv->comp, &uid_b); + + return g_strcmp0 (uid_a, uid_b); +} void comp_editor_set_existing_org (CompEditor *editor, gboolean existing_org) @@ -1843,6 +1927,14 @@ comp_editor_get_classification (CompEditor *editor) return gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); } +EShell * +comp_editor_get_shell (CompEditor *editor) +{ + g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); + + return editor->priv->shell; +} + void comp_editor_set_summary (CompEditor *editor, const gchar *summary) @@ -1948,11 +2040,10 @@ comp_editor_set_flags (CompEditor *editor, g_object_notify (G_OBJECT (editor), "flags"); } - CompEditorFlags comp_editor_get_flags (CompEditor *editor) { - g_return_val_if_fail (IS_COMP_EDITOR (editor), FALSE); + g_return_val_if_fail (IS_COMP_EDITOR (editor), 0); return editor->priv->flags; } @@ -2010,6 +2101,20 @@ comp_editor_get_managed_widget (CompEditor *editor, return widget; } +CompEditor * +comp_editor_find_instance (const gchar *uid) +{ + GList *link; + + g_return_val_if_fail (uid != NULL, NULL); + + link = g_list_find_custom ( + active_editors, uid, + (GCompareFunc) comp_editor_compare); + + return (link != NULL) ? link->data : NULL; +} + /** * comp_editor_set_needs_send: * @editor: A component editor @@ -2333,8 +2438,14 @@ fill_widgets (CompEditor *editor) EAttachmentStore *store; EAttachmentView *view; CompEditorPrivate *priv; - GList *l; GtkAction *action; + GList *iter; + + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); + + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); store = e_attachment_view_get_store (view); @@ -2357,12 +2468,14 @@ fill_widgets (CompEditor *editor) } action = comp_editor_get_action (editor, "classify-public"); - g_signal_handlers_block_by_func (action, G_CALLBACK (action_classification_cb), editor); + g_signal_handlers_block_by_func ( + action, G_CALLBACK (action_classification_cb), editor); - for (l = priv->pages; l != NULL; l = l->next) - comp_editor_page_fill_widgets (l->data, priv->comp); + for (iter = priv->pages; iter != NULL; iter = iter->next) + comp_editor_page_fill_widgets (iter->data, priv->comp); - g_signal_handlers_unblock_by_func (action, G_CALLBACK (action_classification_cb), editor); + g_signal_handlers_unblock_by_func ( + action, G_CALLBACK (action_classification_cb), editor); } static void @@ -2768,9 +2881,10 @@ page_dates_changed_cb (CompEditor *editor, } static void -obj_modified_cb (ECal *client, GList *objects, gpointer data) +obj_modified_cb (ECal *client, + GList *objects, + CompEditor *editor) { - CompEditor *editor = COMP_EDITOR (data); CompEditorPrivate *priv; ECalComponent *comp = NULL; @@ -2803,12 +2917,11 @@ obj_modified_cb (ECal *client, GList *objects, gpointer data) } static void -obj_removed_cb (ECal *client, GList *uids, gpointer data) +obj_removed_cb (ECal *client, + GList *uids, + CompEditor *editor) { - CompEditor *editor = COMP_EDITOR (data); - CompEditorPrivate *priv; - - priv = editor->priv; + CompEditorPrivate *priv = editor->priv; if (changed_component_dialog ((GtkWindow *) editor, priv->comp, TRUE, priv->changed)) close_dialog (editor); diff --git a/calendar/gui/dialogs/comp-editor.h b/calendar/gui/dialogs/comp-editor.h index ec1b991592..6a8f8e4f93 100644 --- a/calendar/gui/dialogs/comp-editor.h +++ b/calendar/gui/dialogs/comp-editor.h @@ -29,6 +29,7 @@ #include <libecal/e-cal.h> #include "../itip-utils.h" #include "comp-editor-page.h" +#include <shell/e-shell.h> /* Standard GObject macros */ #define TYPE_COMP_EDITOR \ @@ -87,6 +88,8 @@ typedef enum { } CompEditorFlags; GType comp_editor_get_type (void); +gint comp_editor_compare (CompEditor *editor_a, + CompEditor *editor_b); void comp_editor_set_changed (CompEditor *editor, gboolean changed); gboolean comp_editor_get_changed (CompEditor *editor); @@ -106,6 +109,7 @@ void comp_editor_set_classification (CompEditor *editor, ECalComponentClassification classification); ECalComponentClassification comp_editor_get_classification (CompEditor *editor); +EShell * comp_editor_get_shell (CompEditor *editor); void comp_editor_set_summary (CompEditor *editor, const gchar *summary); const gchar * comp_editor_get_summary (CompEditor *editor); @@ -150,6 +154,7 @@ GtkActionGroup * const gchar *group_name); GtkWidget * comp_editor_get_managed_widget (CompEditor *editor, const gchar *widget_path); +CompEditor * comp_editor_find_instance (const gchar *uid); G_END_DECLS diff --git a/calendar/gui/dialogs/event-editor.c b/calendar/gui/dialogs/event-editor.c index 4643f8f697..6f0f338bf4 100644 --- a/calendar/gui/dialogs/event-editor.c +++ b/calendar/gui/dialogs/event-editor.c @@ -36,7 +36,6 @@ #include <misc/e-dateedit.h> #include <e-util/e-plugin-ui.h> #include <e-util/e-util-private.h> -#include <evolution-shell-component-utils.h> #include "event-page.h" #include "recurrence-page.h" @@ -466,6 +465,7 @@ event_editor_init (EventEditor *ee) GtkUIManager *ui_manager; GtkActionGroup *action_group; GtkAction *action; + const gchar *id; GError *error = NULL; ee->priv = EVENT_EDITOR_GET_PRIVATE (ee); @@ -488,7 +488,10 @@ event_editor_init (EventEditor *ee) ui_manager = comp_editor_get_ui_manager (editor); gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); - e_plugin_ui_register_manager ("event-editor", ui_manager, ee); + + id = "org.gnome.evolution.event-editor"; + e_plugin_ui_register_manager (ui_manager, id, ee); + e_plugin_ui_enable_manager (ui_manager, id); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); @@ -662,13 +665,16 @@ event_editor_send_comp (CompEditor *editor, ECalComponentItipMethod method, gboo * editor could not be created. **/ CompEditor * -event_editor_new (ECal *client, CompEditorFlags flags) +event_editor_new (ECal *client, + EShell *shell, + CompEditorFlags flags) { g_return_val_if_fail (E_IS_CAL (client), NULL); + g_return_val_if_fail (E_IS_SHELL (client), NULL); return g_object_new ( TYPE_EVENT_EDITOR, - "flags", flags, "client", client, NULL); + "client", client, "flags", flags, "shell", shell, NULL); } void diff --git a/calendar/gui/dialogs/event-editor.h b/calendar/gui/dialogs/event-editor.h index 03afd6448a..abb8f0e659 100644 --- a/calendar/gui/dialogs/event-editor.h +++ b/calendar/gui/dialogs/event-editor.h @@ -66,6 +66,7 @@ struct _EventEditorClass { GType event_editor_get_type (void); CompEditor * event_editor_new (ECal *client, + EShell *shell, CompEditorFlags flags); void event_editor_show_meeting (EventEditor *ee); diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index f43dcc1d41..29e5e1da76 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -381,9 +381,11 @@ update_time (EventPage *epage, ECalComponentDateTime *start_date, ECalComponentD EventPagePrivate *priv = epage->priv; CompEditor *editor; ECal *client; + GtkAction *action; struct icaltimetype *start_tt, *end_tt, implied_tt; icaltimezone *start_zone = NULL, *def_zone = NULL; gboolean all_day_event, homezone=TRUE; + gboolean show_timezone; editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (epage)); client = comp_editor_get_client (editor); @@ -455,7 +457,9 @@ update_time (EventPage *epage, ECalComponentDateTime *start_date, ECalComponentD if (!def_zone || !start_zone || strcmp (icaltimezone_get_tzid(def_zone), icaltimezone_get_tzid (start_zone))) homezone = FALSE; - event_page_set_show_timezone (epage, (calendar_config_get_show_timezone()|| !homezone) & !all_day_event); + action = comp_editor_get_action (editor, "view-time-zone"); + show_timezone = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + event_page_set_show_timezone (epage, (show_timezone || !homezone) & !all_day_event); /*unblock the endtimezone widget*/ g_signal_handlers_unblock_matched (priv->end_timezone, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); @@ -1815,15 +1819,10 @@ remove_clicked_cb (GtkButton *btn, EventPage *epage) } static void -invite_cb (GtkWidget *widget, gpointer data) +invite_cb (GtkWidget *widget, + EventPage *page) { - EventPage *page; - EventPagePrivate *priv; - - page = EVENT_PAGE (data); - priv = page->priv; - - e_meeting_list_view_invite_others_dialog (priv->list_view); + e_meeting_list_view_invite_others_dialog (page->priv->list_view); } static void @@ -2013,6 +2012,7 @@ event_page_set_all_day_event (EventPage *epage, gboolean all_day) CompEditor *editor; GtkAction *action; gboolean date_set; + gboolean active; editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (epage)); @@ -2091,7 +2091,10 @@ event_page_set_all_day_event (EventPage *epage, gboolean all_day) TRUE); } - event_page_set_show_timezone (epage, calendar_config_get_show_timezone() & !all_day); + action = comp_editor_get_action (editor, "view-time-zone"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + event_page_set_show_timezone (epage, active & !all_day); + g_signal_handlers_block_matched (priv->start_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); g_signal_handlers_block_matched (priv->end_time, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, epage); @@ -2173,10 +2176,12 @@ event_page_set_info_string (EventPage *epage, const gchar *icon, const gchar *ms static gboolean get_widgets (EventPage *epage) { + CompEditor *editor; CompEditorPage *page = COMP_EDITOR_PAGE (epage); GtkEntryCompletion *completion; EventPagePrivate *priv; GSList *accel_groups; + GtkAction *action; GtkWidget *toplevel; GtkWidget *sw; @@ -2184,6 +2189,8 @@ get_widgets (EventPage *epage) #define GW(name) glade_xml_get_widget (priv->xml, name) + editor = comp_editor_page_get_editor (page); + priv->main = GW ("event-page"); if (!priv->main) return FALSE; @@ -2205,7 +2212,8 @@ get_widgets (EventPage *epage) gtk_widget_show (priv->status_icons); - if (!calendar_config_get_show_timezone()) { + action = comp_editor_get_action (editor, "view-time-zone"); + if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { gtk_widget_hide (priv->timezone_label); gtk_widget_hide (priv->start_timezone); } else { @@ -2483,14 +2491,10 @@ times_updated (EventPage *epage, gboolean adjust_end_time) * start date < end date and we set the "all day event" button as appropriate. */ static void -start_date_changed_cb (GtkWidget *dedit, gpointer data) +start_date_changed_cb (GtkWidget *dedit, + EventPage *epage) { - EventPage *epage; - - epage = EVENT_PAGE (data); - hour_minute_changed (epage); - times_updated (epage, TRUE); } @@ -2498,12 +2502,9 @@ start_date_changed_cb (GtkWidget *dedit, gpointer data) * start date < end date and we set the "all day event" button as appropriate. */ static void -end_date_changed_cb (GtkWidget *dedit, gpointer data) +end_date_changed_cb (GtkWidget *dedit, + EventPage *epage) { - EventPage *epage; - - epage = EVENT_PAGE (data); - times_updated (epage, FALSE); } @@ -2512,15 +2513,12 @@ end_date_changed_cb (GtkWidget *dedit, gpointer data) * labels on the other notebook pages. */ static void -start_timezone_changed_cb (GtkWidget *widget, gpointer data) +start_timezone_changed_cb (GtkWidget *widget, + EventPage *epage) { - EventPage *epage; - EventPagePrivate *priv; + EventPagePrivate *priv = epage->priv; icaltimezone *zone; - epage = EVENT_PAGE (data); - priv = epage->priv; - if (priv->sync_timezones) { zone = e_timezone_entry_get_timezone (E_TIMEZONE_ENTRY (priv->start_timezone)); comp_editor_page_set_updating (COMP_EDITOR_PAGE (epage), TRUE); @@ -2537,17 +2535,13 @@ start_timezone_changed_cb (GtkWidget *widget, gpointer data) * category list dialog. */ static void -categories_clicked_cb (GtkWidget *button, gpointer data) +categories_clicked_cb (GtkWidget *button, + EventPage *epage) { - EventPage *epage; - EventPagePrivate *priv; - GtkWidget *entry; + GtkEntry *entry; - epage = EVENT_PAGE (data); - priv = epage->priv; - - entry = priv->categories; - e_categories_config_open_dialog_for_entry (GTK_ENTRY (entry)); + entry = GTK_ENTRY (epage->priv->categories); + e_categories_config_open_dialog_for_entry (entry); } void @@ -2666,13 +2660,10 @@ set_subscriber_info_string (EventPage *epage, const gchar *backend_address) } static void -alarm_changed_cb (GtkWidget *widget, gpointer data) +alarm_changed_cb (GtkWidget *widget, + EventPage *epage) { - EventPage *epage; - EventPagePrivate *priv; - - epage = EVENT_PAGE (data); - priv = epage->priv; + EventPagePrivate *priv = epage->priv; if (e_dialog_combo_box_get (priv->alarm_time_combo, priv->alarm_map) != ALARM_NONE) { ECalComponentAlarm *ca; @@ -2814,7 +2805,9 @@ init_widgets (EventPage *epage) GtkTextBuffer *text_buffer; icaltimezone *zone; gchar *combo_label = NULL; + GtkAction *action; GtkTreeSelection *selection; + gboolean active; ECal *client; editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (epage)); @@ -2871,11 +2864,28 @@ init_widgets (EventPage *epage) g_signal_connect((priv->start_timezone), "changed", G_CALLBACK (start_timezone_changed_cb), epage); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_ATTENDEE_COL, TRUE); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_ROLE_COL, calendar_config_get_show_role ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_RSVP_COL, calendar_config_get_show_rsvp ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_STATUS_COL, calendar_config_get_show_status ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_TYPE_COL, calendar_config_get_show_type ()); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_ATTENDEE_COL, TRUE); + + action = comp_editor_get_action (editor, "view-role"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_ROLE_COL, active); + + action = comp_editor_get_action (editor, "view-rsvp"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_RSVP_COL, active); + + action = comp_editor_get_action (editor, "view-status"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_STATUS_COL, active); + + action = comp_editor_get_action (editor, "view-type"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_TYPE_COL, active); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->list_view)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); @@ -2911,7 +2921,8 @@ init_widgets (EventPage *epage) gtk_widget_show (GTK_WIDGET (priv->list_view)); /* categories */ - if (!calendar_config_get_show_categories()) { + action = comp_editor_get_action (editor, "view-categories"); + if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { gtk_widget_hide (priv->categories_btn); gtk_widget_hide (priv->categories); } else { @@ -3005,7 +3016,9 @@ init_widgets (EventPage *epage) e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->start_timezone), zone); e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->end_timezone), zone); - event_page_set_show_timezone (epage, calendar_config_get_show_timezone()); + action = comp_editor_get_action (editor, "view-time-zone"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + event_page_set_show_timezone (epage, active); return TRUE; } diff --git a/calendar/gui/dialogs/memo-editor.c b/calendar/gui/dialogs/memo-editor.c index cf3781a3c2..bda54e55eb 100644 --- a/calendar/gui/dialogs/memo-editor.c +++ b/calendar/gui/dialogs/memo-editor.c @@ -34,7 +34,6 @@ #include <e-util/e-plugin-ui.h> #include <e-util/e-util-private.h> -#include <evolution-shell-component-utils.h> #include "memo-page.h" #include "cancel-comp.h" @@ -135,6 +134,7 @@ memo_editor_init (MemoEditor *me) { CompEditor *editor = COMP_EDITOR (me); GtkUIManager *ui_manager; + const gchar *id; GError *error = NULL; me->priv = MEMO_EDITOR_GET_PRIVATE (me); @@ -142,7 +142,10 @@ memo_editor_init (MemoEditor *me) ui_manager = comp_editor_get_ui_manager (editor); gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); - e_plugin_ui_register_manager ("memo-editor", ui_manager, me); + + id = "org.gnome.evolution.memo-editor"; + e_plugin_ui_register_manager (ui_manager, id, me); + e_plugin_ui_enable_manager (ui_manager, id); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); @@ -160,11 +163,14 @@ memo_editor_init (MemoEditor *me) * editor could not be created. **/ CompEditor * -memo_editor_new (ECal *client, CompEditorFlags flags) +memo_editor_new (ECal *client, + EShell *shell, + CompEditorFlags flags) { g_return_val_if_fail (E_IS_CAL (client), NULL); + g_return_val_if_fail (E_IS_SHELL (shell), NULL); return g_object_new ( TYPE_MEMO_EDITOR, - "flags", flags, "client", client, NULL); + "client", client, "flags", flags, "shell", shell, NULL); } diff --git a/calendar/gui/dialogs/memo-editor.h b/calendar/gui/dialogs/memo-editor.h index 2e431b507f..cd4bc194ac 100644 --- a/calendar/gui/dialogs/memo-editor.h +++ b/calendar/gui/dialogs/memo-editor.h @@ -68,6 +68,7 @@ struct _MemoEditorClass { GType memo_editor_get_type (void); CompEditor * memo_editor_new (ECal *client, + EShell *shell, CompEditorFlags flags); G_END_DECLS diff --git a/calendar/gui/dialogs/memo-page.c b/calendar/gui/dialogs/memo-page.c index 0b76d783c9..4254dce774 100644 --- a/calendar/gui/dialogs/memo-page.c +++ b/calendar/gui/dialogs/memo-page.c @@ -929,9 +929,14 @@ to_button_clicked_cb (GtkButton *button, static gboolean init_widgets (MemoPage *mpage) { + CompEditor *editor; MemoPagePrivate *priv = mpage->priv; GtkTextBuffer *buffer; GtkTextView *view; + GtkAction *action; + gboolean active; + + editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (mpage)); /* Generic informative messages */ gtk_widget_hide (priv->info_hbox); @@ -996,8 +1001,9 @@ init_widgets (MemoPage *mpage) G_CALLBACK (comp_editor_page_changed), mpage); } - memo_page_set_show_categories ( - mpage, calendar_config_get_show_categories()); + action = comp_editor_get_action (editor, "view-categories"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + memo_page_set_show_categories (mpage, active); return TRUE; } diff --git a/calendar/gui/dialogs/memo-page.glade b/calendar/gui/dialogs/memo-page.glade index b1ff10f3f4..8728c9366e 100644 --- a/calendar/gui/dialogs/memo-page.glade +++ b/calendar/gui/dialogs/memo-page.glade @@ -159,6 +159,7 @@ <widget class="GtkLabel" id="label18"> <property name="visible">True</property> <property name="label" translatable="yes">_Description:</property> + <property name="mnemonic_widget">memo_content</property> <property name="use_underline">True</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_CENTER</property> diff --git a/calendar/gui/dialogs/task-details-page.c b/calendar/gui/dialogs/task-details-page.c index 23f4b1f840..eeacc0774f 100644 --- a/calendar/gui/dialogs/task-details-page.c +++ b/calendar/gui/dialogs/task-details-page.c @@ -517,16 +517,15 @@ complete_date_changed (TaskDetailsPage *tdpage, time_t ctime, gboolean complete) } static void -date_changed_cb (EDateEdit *dedit, gpointer data) +date_changed_cb (EDateEdit *dedit, + TaskDetailsPage *tdpage) { - TaskDetailsPage *tdpage; - TaskDetailsPagePrivate *priv; + TaskDetailsPagePrivate *priv = tdpage->priv; CompEditorPageDates dates = {NULL, NULL, NULL, NULL}; struct icaltimetype completed_tt = icaltime_null_time (); icalproperty_status status; gboolean date_set; - tdpage = TASK_DETAILS_PAGE (data); priv = tdpage->priv; if (comp_editor_page_get_updating (COMP_EDITOR_PAGE (tdpage))) diff --git a/calendar/gui/dialogs/task-details-page.glade b/calendar/gui/dialogs/task-details-page.glade index 44fc3b2fbb..aac90876ed 100644 --- a/calendar/gui/dialogs/task-details-page.glade +++ b/calendar/gui/dialogs/task-details-page.glade @@ -4,7 +4,7 @@ <glade-interface> <widget class="GtkWindow" id="task-details-toplevel"> - <property name="title">window1</property> + <property name="title" translatable="no">window1</property> <property name="type">GTK_WINDOW_TOPLEVEL</property> <property name="window_position">GTK_WIN_POS_NONE</property> <property name="modal">False</property> @@ -15,8 +15,6 @@ <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> - <property name="focus_on_map">True</property> - <property name="urgency_hint">False</property> <child> <widget class="GtkVBox" id="task-details-page"> @@ -38,10 +36,6 @@ <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="padding">0</property> @@ -69,10 +63,6 @@ <property name="yalign">0.5</property> <property name="xpad">12</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="padding">0</property> @@ -103,10 +93,7 @@ <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> + <property name="mnemonic_widget">status</property> </widget> <packing> <property name="left_attach">0</property> @@ -132,10 +119,6 @@ <property name="xpad">0</property> <property name="ypad">0</property> <property name="mnemonic_widget">percent-complete</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="left_attach">0</property> @@ -160,10 +143,7 @@ <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> + <property name="mnemonic_widget">priority</property> </widget> <packing> <property name="left_attach">0</property> @@ -188,10 +168,6 @@ <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="left_attach">0</property> @@ -204,85 +180,153 @@ </child> <child> - <widget class="GtkSpinButton" id="percent-complete"> + <widget class="GtkOptionMenu" id="priority"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="climb_rate">1</property> - <property name="digits">0</property> - <property name="numeric">True</property> - <property name="update_policy">GTK_UPDATE_ALWAYS</property> - <property name="snap_to_ticks">False</property> - <property name="wrap">False</property> - <property name="adjustment">0 0 100 1 10 0</property> + <property name="history">0</property> + + <child internal-child="menu"> + <widget class="GtkMenu" id="convertwidget7"> + <property name="visible">True</property> + + <child> + <widget class="GtkMenuItem" id="convertwidget8"> + <property name="visible">True</property> + <property name="label" translatable="yes">High</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget9"> + <property name="visible">True</property> + <property name="label" translatable="yes">Normal</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget10"> + <property name="visible">True</property> + <property name="label" translatable="yes">Low</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget11"> + <property name="visible">True</property> + <property name="label" translatable="yes">Undefined</property> + <property name="use_underline">True</property> + </widget> + </child> + </widget> + </child> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> </child> <child> - <widget class="Custom" id="completed-date"> + <widget class="GtkOptionMenu" id="status"> <property name="visible">True</property> - <property name="creation_function">task_details_page_create_date_edit</property> - <property name="int1">0</property> - <property name="int2">0</property> - <property name="last_modification_time">Fri, 01 Jun 2001 18:58:51 GMT</property> - <accessibility> - <atkrelation target="date_completed_label" type="labelled-by"/> - </accessibility> + <property name="can_focus">True</property> + <property name="history">0</property> + + <child internal-child="menu"> + <widget class="GtkMenu" id="convertwidget1"> + <property name="visible">True</property> + + <child> + <widget class="GtkMenuItem" id="convertwidget2"> + <property name="visible">True</property> + <property name="label" translatable="yes">Not Started</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget3"> + <property name="visible">True</property> + <property name="label" translatable="yes">In Progress</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget5"> + <property name="visible">True</property> + <property name="label" translatable="yes">Completed</property> + <property name="use_underline">True</property> + </widget> + </child> + + <child> + <widget class="GtkMenuItem" id="convertwidget6"> + <property name="visible">True</property> + <property name="label" translatable="yes">Canceled</property> + <property name="use_underline">True</property> + </widget> + </child> + </widget> + </child> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> </child> <child> - <widget class="GtkComboBox" id="priority-combobox"> + <widget class="GtkSpinButton" id="percent-complete"> <property name="visible">True</property> - <property name="items" translatable="yes">High -Normal -Low -Undefined</property> - <property name="add_tearoffs">False</property> - <property name="focus_on_click">True</property> + <property name="can_focus">True</property> + <property name="climb_rate">1</property> + <property name="digits">0</property> + <property name="numeric">True</property> + <property name="update_policy">GTK_UPDATE_ALWAYS</property> + <property name="snap_to_ticks">False</property> + <property name="wrap">False</property> + <property name="adjustment">0 0 100 1 10 0</property> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="x_options">fill</property> - <property name="y_options">fill</property> + <property name="y_options"></property> </packing> </child> <child> - <widget class="GtkComboBox" id="status-combobox"> + <widget class="Custom" id="completed-date"> <property name="visible">True</property> - <property name="items" translatable="yes">Not Started -In Progress -Completed -Canceled</property> - <property name="add_tearoffs">False</property> - <property name="focus_on_click">True</property> + <property name="creation_function">task_details_page_create_date_edit</property> + <property name="int1">0</property> + <property name="int2">0</property> + <property name="last_modification_time">Fri, 01 Jun 2001 18:58:51 GMT</property> + <accessibility> + <atkrelation target="date_completed_label" type="labelled-by"/> + </accessibility> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> <property name="x_options">fill</property> - <property name="y_options">fill</property> + <property name="y_options"></property> </packing> </child> </widget> @@ -313,10 +357,6 @@ Canceled</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="padding">0</property> @@ -344,10 +384,6 @@ Canceled</property> <property name="yalign">0.5</property> <property name="xpad">12</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="padding">0</property> @@ -379,10 +415,6 @@ Canceled</property> <property name="yalign">0.5</property> <property name="xpad">0</property> <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> </widget> <packing> <property name="left_attach">0</property> diff --git a/calendar/gui/dialogs/task-editor.c b/calendar/gui/dialogs/task-editor.c index 9377e0970b..c74ed46db3 100644 --- a/calendar/gui/dialogs/task-editor.c +++ b/calendar/gui/dialogs/task-editor.c @@ -35,7 +35,6 @@ #include <e-util/e-plugin-ui.h> #include <e-util/e-util-private.h> -#include <evolution-shell-component-utils.h> #include "task-page.h" #include "task-details-page.h" @@ -304,6 +303,7 @@ task_editor_init (TaskEditor *te) CompEditor *editor = COMP_EDITOR (te); GtkUIManager *ui_manager; GtkActionGroup *action_group; + const gchar *id; GError *error = NULL; te->priv = TASK_EDITOR_GET_PRIVATE (te); @@ -346,7 +346,10 @@ task_editor_init (TaskEditor *te) ui_manager = comp_editor_get_ui_manager (editor); gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); - e_plugin_ui_register_manager ("task-editor", ui_manager, te); + + id = "org.gnome.evolution.task-editor"; + e_plugin_ui_register_manager (ui_manager, id, te); + e_plugin_ui_enable_manager (ui_manager, id); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); @@ -489,13 +492,16 @@ task_editor_send_comp (CompEditor *editor, ECalComponentItipMethod method, gbool * editor could not be created. **/ CompEditor * -task_editor_new (ECal *client, CompEditorFlags flags) +task_editor_new (ECal *client, + EShell *shell, + CompEditorFlags flags) { g_return_val_if_fail (E_IS_CAL (client), NULL); + g_return_val_if_fail (E_IS_SHELL (shell), NULL); return g_object_new ( TYPE_TASK_EDITOR, - "flags", flags, "client", client, NULL); + "client", client, "flags", flags, "shell", shell, NULL); } void diff --git a/calendar/gui/dialogs/task-editor.h b/calendar/gui/dialogs/task-editor.h index 57ab33b54f..f026acae0c 100644 --- a/calendar/gui/dialogs/task-editor.h +++ b/calendar/gui/dialogs/task-editor.h @@ -66,6 +66,7 @@ struct _TaskEditorClass { GType task_editor_get_type (void); CompEditor * task_editor_new (ECal *client, + EShell *shell, CompEditorFlags flags); void task_editor_show_assignment (TaskEditor *te); diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c index faaba68317..3cdbe344e9 100644 --- a/calendar/gui/dialogs/task-page.c +++ b/calendar/gui/dialogs/task-page.c @@ -451,12 +451,14 @@ task_page_fill_widgets (CompEditorPage *page, ECalComponent *comp) ECalComponentClassification cl; CompEditor *editor; CompEditorFlags flags; + GtkAction *action; ECal *client; GSList *l; icalcomponent *icalcomp; const gchar *categories, *uid; icaltimezone *zone, *default_zone; gchar *backend_addr = NULL; + gboolean active; tpage = TASK_PAGE (page); priv = tpage->priv; @@ -538,7 +540,10 @@ task_page_fill_widgets (CompEditorPage *page, ECalComponent *comp) e_timezone_entry_set_timezone (E_TIMEZONE_ENTRY (priv->timezone), zone ? zone : default_zone); - task_page_set_show_timezone (tpage, calendar_config_get_show_timezone()); + + action = comp_editor_get_action (editor, "view-time-zone"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + task_page_set_show_timezone (tpage, active); if (!(flags & COMP_EDITOR_NEW_ITEM) && !zone) { GtkAction *action; @@ -1125,15 +1130,10 @@ remove_clicked_cb (GtkButton *btn, TaskPage *page) } static void -invite_cb (GtkWidget *widget, gpointer data) +invite_cb (GtkWidget *widget, + TaskPage *page) { - TaskPage *page; - TaskPagePrivate *priv; - - page = TASK_PAGE (data); - priv = page->priv; - - e_meeting_list_view_invite_others_dialog (priv->list_view); + e_meeting_list_view_invite_others_dialog (page->priv->list_view); } static void @@ -1494,17 +1494,16 @@ summary_changed_cb (GtkEditable *editable, * other pages in the task editor, so they can update any labels. */ static void -date_changed_cb (EDateEdit *dedit, gpointer data) +date_changed_cb (EDateEdit *dedit, + TaskPage *tpage) { - TaskPage *tpage; - TaskPagePrivate *priv; + TaskPagePrivate *priv = tpage->priv; CompEditorPageDates dates; gboolean date_set, time_set; ECalComponentDateTime start_dt, due_dt; struct icaltimetype start_tt = icaltime_null_time(); struct icaltimetype due_tt = icaltime_null_time(); - tpage = TASK_PAGE (data); priv = tpage->priv; if (comp_editor_page_get_updating (COMP_EDITOR_PAGE (tpage))) @@ -1563,33 +1562,24 @@ date_changed_cb (EDateEdit *dedit, gpointer data) } static void -timezone_changed_cb (EDateEdit *dedit, gpointer data) +timezone_changed_cb (EDateEdit *dedit, + TaskPage *tpage) { - TaskPage *tpage; - TaskPagePrivate *priv; - - tpage = TASK_PAGE (data); - priv = tpage->priv; - - date_changed_cb ((EDateEdit *) priv->start_date, tpage); - date_changed_cb ((EDateEdit *) priv->due_date, tpage); + date_changed_cb ((EDateEdit *) tpage->priv->start_date, tpage); + date_changed_cb ((EDateEdit *) tpage->priv->due_date, tpage); } /* Callback used when the categories button is clicked; we must bring up the * category list dialog. */ static void -categories_clicked_cb (GtkWidget *button, gpointer data) +categories_clicked_cb (GtkWidget *button, + TaskPage *tpage) { - TaskPage *tpage; - TaskPagePrivate *priv; - GtkWidget *entry; + GtkEntry *entry; - tpage = TASK_PAGE (data); - priv = tpage->priv; - - entry = priv->categories; - e_categories_config_open_dialog_for_entry (GTK_ENTRY (entry)); + entry = GTK_ENTRY (tpage->priv->categories); + e_categories_config_open_dialog_for_entry (entry); } static gboolean @@ -1844,12 +1834,17 @@ task_page_sendoptions_clicked_cb (TaskPage *tpage) static gboolean init_widgets (TaskPage *tpage) { + CompEditor *editor; TaskPagePrivate *priv; + GtkAction *action; GtkTextBuffer *text_buffer; icaltimezone *zone; + gboolean active; priv = tpage->priv; + editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (tpage)); + /* Make sure the EDateEdit widgets use our timezones to get the current time. */ e_date_edit_set_get_time_callback (E_DATE_EDIT (priv->start_date), @@ -1945,15 +1940,36 @@ init_widgets (TaskPage *tpage) zone = calendar_config_get_icaltimezone (); e_timezone_entry_set_default_timezone (E_TIMEZONE_ENTRY (priv->timezone), zone); - task_page_set_show_timezone (tpage, calendar_config_get_show_timezone()); + action = comp_editor_get_action (editor, "view-time-zone"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + task_page_set_show_timezone (tpage, active); + + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_ATTENDEE_COL, TRUE); + + action = comp_editor_get_action (editor, "view-role"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_ROLE_COL, active); + + action = comp_editor_get_action (editor, "view-rsvp"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_RSVP_COL, active); + + action = comp_editor_get_action (editor, "view-status"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_STATUS_COL, active); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_ATTENDEE_COL, TRUE); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_ROLE_COL, calendar_config_get_show_role ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_RSVP_COL, calendar_config_get_show_rsvp ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_STATUS_COL, calendar_config_get_show_status ()); - e_meeting_list_view_column_set_visible (priv->list_view, E_MEETING_STORE_TYPE_COL, calendar_config_get_show_type ()); + action = comp_editor_get_action (editor, "view-type"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + e_meeting_list_view_column_set_visible ( + priv->list_view, E_MEETING_STORE_TYPE_COL, active); - task_page_set_show_categories (tpage, calendar_config_get_show_categories()); + action = comp_editor_get_action (editor, "view-categories"); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + task_page_set_show_categories (tpage, active); return TRUE; } diff --git a/calendar/gui/e-cal-component-memo-preview.c b/calendar/gui/e-cal-component-memo-preview.c deleted file mode 100644 index 20190a8f80..0000000000 --- a/calendar/gui/e-cal-component-memo-preview.c +++ /dev/null @@ -1,368 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - * Rodrigo Moya <rodrigo@ximian.com> - * Nathan Owens <pianocomp81@yahoo.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <gtk/gtk.h> -#include <glib/gi18n.h> -#include <libecal/e-cal-time-util.h> -#include <libedataserver/e-categories.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> -#include <libedataserver/e-time-utils.h> -#include <e-util/e-util.h> -#include <e-util/e-categories-config.h> -#include "calendar-config.h" -#include "e-cal-component-memo-preview.h" -#include "e-cal-component-preview.h" -#include <camel/camel-mime-filter-tohtml.h> - -struct _ECalComponentMemoPreviewPrivate { - GtkWidget *html; - - icaltimezone *zone; -}; - -G_DEFINE_TYPE (ECalComponentMemoPreview, e_cal_component_memo_preview, GTK_TYPE_TABLE) - - -static void -on_link_clicked (GtkHTML *html, const gchar *url, gpointer data) -{ - /* FIXME Pass a parent window. */ - e_show_uri (NULL, url); -} - -static void -on_url_cb (GtkHTML *html, const gchar *url, gpointer data) -{ -#if 0 - gchar *msg; - ECalComponentMemoPreview *preview = data; - - if (url && *url) { - msg = g_strdup_printf (_("Click to open %s"), url); - e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), msg); - g_free (msg); - } else - e_calendar_table_set_status_message (e_tasks_get_calendar_table (tasks), NULL); -#endif -} - -/* Converts a time_t to a string, relative to the specified timezone */ -static gchar * -timet_to_str_with_zone (ECalComponentDateTime *dt, ECal *ecal, icaltimezone *default_zone) -{ - struct icaltimetype itt; - icaltimezone *zone; - struct tm tm; - gchar buf[256]; - - if (dt->tzid) { - /* If we can't find the zone, we'll guess its "local" */ - if (!e_cal_get_timezone (ecal, dt->tzid, &zone, NULL)) - zone = NULL; - } else if (dt->value->is_utc) { - zone = icaltimezone_get_utc_timezone (); - } else { - zone = NULL; - } - - - itt = *dt->value; - if (zone) - icaltimezone_convert_time (&itt, zone, default_zone); - tm = icaltimetype_to_tm (&itt); - - e_time_format_date_and_time (&tm, calendar_config_get_24_hour_format (), - FALSE, FALSE, buf, sizeof (buf)); - - return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); -} - -static void -write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone *default_zone) -{ - ECalComponentText text; - ECalComponentDateTime dt; - gchar *str; - GSList *l; - gboolean one_added = FALSE; - - g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - - /* write document header */ - e_cal_component_get_summary (comp, &text); - - if (text.value) - gtk_html_stream_printf (stream, - "<HTML><BODY><H1>%s</H1>", - text.value); - else - gtk_html_stream_printf (stream, - "<HTML><BODY><H1><I>%s</I></H1>", - _("Untitled")); - - /* write icons for the categories */ - e_cal_component_get_categories_list (comp, &l); - if (l) { - GSList *node; - GString *string = g_string_new (NULL); - - - gtk_html_stream_printf(stream, "<H3>%s: ", _("Categories")); - - for (node = l; node != NULL; node = node->next) { - const gchar *icon_file; - - icon_file = e_categories_get_icon_file_for ((const gchar *) node->data); - if (icon_file && g_file_test(icon_file, G_FILE_TEST_EXISTS)) { - gchar *icon_file_uri = g_filename_to_uri (icon_file, NULL, NULL); - gtk_html_stream_printf (stream, "<IMG ALT=\"%s\" SRC=\"%s\">", - (const gchar *) node->data, icon_file_uri); - g_free (icon_file_uri); - one_added = TRUE; - } - else{ - if(one_added == FALSE){ - g_string_append_printf (string, "%s", (const gchar *) node->data); - one_added = TRUE; - } - else{ - g_string_append_printf (string, ", %s", (const gchar *) node->data); - } - } - } - - if (string->len > 0) - gtk_html_stream_printf(stream, "%s", string->str); - - g_string_free (string, TRUE); - - gtk_html_stream_printf(stream, "</H3>"); - - e_cal_component_free_categories_list (l); - } - - /* Start table */ - gtk_html_stream_printf (stream, "<TABLE BORDER=\"0\" WIDTH=\"80%%\">" - "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"></TD></TR>"); - - /* write start date */ - e_cal_component_get_dtstart (comp, &dt); - if (dt.value != NULL) { - str = timet_to_str_with_zone (&dt, ecal, default_zone); - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Start Date:"), str); - - g_free (str); - } - e_cal_component_free_datetime (&dt); - - /* write description and URL */ - gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); - - e_cal_component_get_description_list (comp, &l); - if (l) { - GSList *node; - - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Description:")); - - gtk_html_stream_printf (stream, "<TD><TT>"); - - for (node = l; node != NULL; node = node->next) { - gchar *html; - - text = * (ECalComponentText *) node->data; - html = camel_text_to_html (text.value ? text.value : "", CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES | CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0); - - if (html) - gtk_html_stream_printf (stream, "%s", html); - - g_free (html); - } - - gtk_html_stream_printf (stream, "</TT></TD></TR>"); - - e_cal_component_free_text_list (l); - } - - /* URL */ - e_cal_component_get_url (comp, (const gchar **) &str); - if (str) { - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Web Page:")); - gtk_html_stream_printf (stream, "<TD><A HREF=\"%s\">%s</A></TD></TR>", str, str); - } - - gtk_html_stream_printf (stream, "</TABLE>"); - - /* close document */ - gtk_html_stream_printf (stream, "</BODY></HTML>"); -} - -static void -e_cal_component_memo_preview_init (ECalComponentMemoPreview *preview) -{ - ECalComponentMemoPreviewPrivate *priv; - GtkWidget *scroll; - - priv = g_new0 (ECalComponentMemoPreviewPrivate, 1); - preview->priv = priv; - - priv->html = gtk_html_new (); - gtk_html_set_default_content_type (GTK_HTML (priv->html), "charset=utf-8"); - gtk_html_load_empty (GTK_HTML (priv->html)); - - g_signal_connect (G_OBJECT (priv->html), "url_requested", - G_CALLBACK (e_cal_comp_preview_url_requested_cb), NULL); - g_signal_connect (G_OBJECT (priv->html), "link_clicked", - G_CALLBACK (on_link_clicked), preview); - g_signal_connect (G_OBJECT (priv->html), "on_url", - G_CALLBACK (on_url_cb), preview); - - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - - gtk_container_add (GTK_CONTAINER (scroll), priv->html); - gtk_container_add (GTK_CONTAINER (preview), scroll); - gtk_widget_show_all (scroll); - - priv->zone = icaltimezone_get_utc_timezone (); -} - -static void -e_cal_component_memo_preview_destroy (GtkObject *object) -{ - ECalComponentMemoPreview *preview; - ECalComponentMemoPreviewPrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (object)); - - preview = E_CAL_COMPONENT_MEMO_PREVIEW (object); - priv = preview->priv; - - if (priv) { - - g_free (priv); - preview->priv = NULL; - } - - if (GTK_OBJECT_CLASS (e_cal_component_memo_preview_parent_class)->destroy) - (* GTK_OBJECT_CLASS (e_cal_component_memo_preview_parent_class)->destroy) (object); -} - -static void -e_cal_component_memo_preview_class_init (ECalComponentMemoPreviewClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) klass; - - object_class->destroy = e_cal_component_memo_preview_destroy; -} - -GtkWidget * -e_cal_component_memo_preview_new (void) -{ - ECalComponentMemoPreview *preview; - - preview = g_object_new (e_cal_component_memo_preview_get_type (), NULL); - - return GTK_WIDGET (preview); -} - -icaltimezone * -e_cal_component_memo_preview_get_default_timezone (ECalComponentMemoPreview *preview) -{ - ECalComponentMemoPreviewPrivate *priv; - - g_return_val_if_fail (preview != NULL, NULL); - g_return_val_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview), NULL); - - priv = preview->priv; - - return priv->zone; -} - -void -e_cal_component_memo_preview_set_default_timezone (ECalComponentMemoPreview *preview, icaltimezone *zone) -{ - ECalComponentMemoPreviewPrivate *priv; - - g_return_if_fail (preview != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview)); - g_return_if_fail (zone != NULL); - - priv = preview->priv; - - priv->zone = zone; -} - -void -e_cal_component_memo_preview_display (ECalComponentMemoPreview *preview, ECal *ecal, ECalComponent *comp) -{ - ECalComponentMemoPreviewPrivate *priv; - GtkHTMLStream *stream; - - g_return_if_fail (preview != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview)); - g_return_if_fail (comp != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - - priv = preview->priv; - - stream = gtk_html_begin (GTK_HTML (priv->html)); - write_html (stream, ecal, comp, priv->zone); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); -} - -void -e_cal_component_memo_preview_clear (ECalComponentMemoPreview *preview) -{ - ECalComponentMemoPreviewPrivate *priv; - - g_return_if_fail (preview != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview)); - - priv = preview->priv; - - gtk_html_load_empty (GTK_HTML (priv->html)); -} - -GtkWidget * -e_cal_component_memo_preview_get_html (ECalComponentMemoPreview *preview) -{ - g_return_val_if_fail (preview != NULL, NULL); - g_return_val_if_fail (E_IS_CAL_COMPONENT_MEMO_PREVIEW (preview), NULL); - - return preview->priv->html; -} diff --git a/calendar/gui/e-cal-component-memo-preview.h b/calendar/gui/e-cal-component-memo-preview.h deleted file mode 100644 index 2c697231aa..0000000000 --- a/calendar/gui/e-cal-component-memo-preview.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - * Nathan Owens <pianocomp81@yahoo.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CAL_COMPONENT_MEMO_PREVIEW_H_ -#define _E_CAL_COMPONENT_MEMO_PREVIEW_H_ - -#include <gtk/gtk.h> -#include <libecal/e-cal.h> - -#define E_TYPE_CAL_COMPONENT_MEMO_PREVIEW (e_cal_component_memo_preview_get_type ()) -#define E_CAL_COMPONENT_MEMO_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CAL_COMPONENT_MEMO_PREVIEW, ECalComponentMemoPreview)) -#define E_CAL_COMPONENT_MEMO_PREVIEW_CLASS(klass) (G_TYPE_CHECK_INSTANCE_CAST_CLASS ((klass), E_TYPE_CAL_COMPONENT_MEMO_PREVIEW, \ - ECalComponentMemoPreviewClass)) -#define E_IS_CAL_COMPONENT_MEMO_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CAL_COMPONENT_MEMO_PREVIEW)) -#define E_IS_CAL_COMPONENT_MEMO_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CAL_COMPONENT_MEMO_PREVIEW)) - -typedef struct _ECalComponentMemoPreview ECalComponentMemoPreview; -typedef struct _ECalComponentMemoPreviewClass ECalComponentMemoPreviewClass; -typedef struct _ECalComponentMemoPreviewPrivate ECalComponentMemoPreviewPrivate; - -struct _ECalComponentMemoPreview { - GtkTable table; - - /* Private data */ - ECalComponentMemoPreviewPrivate *priv; -}; - -struct _ECalComponentMemoPreviewClass { - GtkTableClass parent_class; - - /* Notification signals */ - void (* selection_changed) (ECalComponentMemoPreview *preview, gint n_selected); -}; - - -GType e_cal_component_memo_preview_get_type (void); -GtkWidget *e_cal_component_memo_preview_new (void); - -icaltimezone *e_cal_component_memo_preview_get_default_timezone (ECalComponentMemoPreview *preview); -void e_cal_component_memo_preview_set_default_timezone (ECalComponentMemoPreview *preview, icaltimezone *zone); - -void e_cal_component_memo_preview_display (ECalComponentMemoPreview *preview, ECal *ecal, ECalComponent *comp); -void e_cal_component_memo_preview_clear (ECalComponentMemoPreview *preview); -GtkWidget *e_cal_component_memo_preview_get_html (ECalComponentMemoPreview *preview); - -#endif /* _E_CAL_COMPONENT_MEMO_PREVIEW_H_ */ diff --git a/calendar/gui/e-cal-component-preview.c b/calendar/gui/e-cal-component-preview.c index 0cee29614d..4340f9cdd8 100644 --- a/calendar/gui/e-cal-component-preview.c +++ b/calendar/gui/e-cal-component-preview.c @@ -22,42 +22,41 @@ * */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif +#include "e-cal-component-preview.h" #include <string.h> -#include <gio/gio.h> #include <gtk/gtk.h> #include <glib/gi18n.h> -#include <libedataserver/e-categories.h> #include <libecal/e-cal-time-util.h> -#include <gtkhtml/gtkhtml.h> +#include <libedataserver/e-categories.h> #include <gtkhtml/gtkhtml-stream.h> #include <libedataserver/e-time-utils.h> #include <e-util/e-util.h> #include <e-util/e-categories-config.h> #include "calendar-config.h" -#include "e-cal-component-preview.h" #include <camel/camel-mime-filter-tohtml.h> -struct _ECalComponentPreviewPrivate { - GtkWidget *html; +#define E_CAL_COMPONENT_PREVIEW_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreviewPrivate)) +struct _ECalComponentPreviewPrivate { icaltimezone *zone; }; -G_DEFINE_TYPE (ECalComponentPreview, e_cal_component_preview, GTK_TYPE_TABLE) +static gpointer parent_class; static void -on_link_clicked (GtkHTML *html, const gchar *url, gpointer data) +cal_component_preview_link_clicked (GtkHTML *html, + const gchar *uri) { /* FIXME Pass a parent window. */ - e_show_uri (NULL, url); + e_show_uri (NULL, uri); } static void -on_url_cb (GtkHTML *html, const gchar *url, gpointer data) +cal_component_preview_on_url (GtkHTML *html, + const gchar *url) { #if 0 gchar *msg; @@ -72,51 +71,11 @@ on_url_cb (GtkHTML *html, const gchar *url, gpointer data) #endif } -/* Callback used when the user selects a URL in the HTML widget */ -void -e_cal_comp_preview_url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *html_stream, gpointer data) -{ - gint len = strlen ("file:///"); - - if (!strncmp ("file:///", url, len)) { - GFile *file; - const gchar *path = url + len - 1; - - g_return_if_fail (html_stream != NULL); - g_return_if_fail (path != NULL); - - file = g_file_new_for_path (path); - if (file) { - gchar buffer[4096]; - GInputStream *stream; - - /* ignore errors here */ - stream = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); - - if (stream) { - gssize bread; - - do { - /* ignore errors here as well */ - bread = g_input_stream_read (stream, buffer, sizeof (buffer), NULL, NULL); - if (bread > 0) - gtk_html_stream_write (html_stream, buffer, bread); - } while (bread > 0); - - g_input_stream_close (stream, NULL, NULL); - g_object_unref (stream); - - gtk_html_stream_close (html_stream, GTK_HTML_STREAM_OK); - } - - g_object_unref (file); - } - } -} - /* Converts a time_t to a string, relative to the specified timezone */ static gchar * -timet_to_str_with_zone (ECalComponentDateTime *dt, ECal *ecal, icaltimezone *default_zone) +timet_to_str_with_zone (ECalComponentDateTime *dt, + ECal *ecal, + icaltimezone *default_zone) { struct icaltimetype itt; icaltimezone *zone; @@ -146,12 +105,18 @@ timet_to_str_with_zone (ECalComponentDateTime *dt, ECal *ecal, icaltimezone *def } static void -write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone *default_zone) +cal_component_preview_write_html (GtkHTMLStream *stream, + ECal *ecal, + ECalComponent *comp, + icaltimezone *default_zone) { ECalComponentText text; ECalComponentDateTime dt; gchar *str; - GSList *l; + GString *string; + GSList *list, *iter; + icalcomponent *icalcomp; + icalproperty *icalprop; icalproperty_status status; const gchar *location; gint *priority_value; @@ -170,28 +135,34 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone "<HTML><BODY><H1><I>%s</I></H1>", _("Untitled")); - /* write icons for the categories */ - e_cal_component_get_categories_list (comp, &l); - if (l) { - GSList *node; - - for (node = l; node != NULL; node = node->next) { - const gchar *icon_file; - - icon_file = e_categories_get_icon_file_for ((const gchar *) node->data); - if (icon_file) { - gchar *icon_file_uri = g_filename_to_uri (icon_file, NULL, NULL); - gtk_html_stream_printf (stream, "<IMG ALT=\"%s\" SRC=\"%s\">", - (const gchar *) node->data, icon_file_uri); - g_free (icon_file_uri); - } + string = g_string_new (NULL); + e_cal_component_get_categories_list (comp, &list); + if (list != NULL) + gtk_html_stream_printf (stream, "<H3>%s ", _("Categories:")); + for (iter = list; iter != NULL; iter = iter->next) { + const gchar *category = iter->data; + const gchar *icon_file; + + icon_file = e_categories_get_icon_file_for (category); + if (icon_file && g_file_test (icon_file, G_FILE_TEST_EXISTS)) { + gchar *uri; + + uri = g_filename_to_uri (icon_file, NULL, NULL); + gtk_html_stream_printf ( + stream, "<IMG ALT=\"%s\" SRC=\"%s\">", + category, uri); + g_free (uri); + } else { + if (iter != list) + g_string_append_len (string, ", ", 2); + g_string_append (string, category); } - - e_cal_component_free_categories_list (l); - - gtk_html_stream_printf (stream, "<BR><BR><BR>"); } + if (string->len > 0) + gtk_html_stream_printf (stream, "%s</H3>", string->str); + e_cal_component_free_categories_list (list); + g_string_free (string, TRUE); /* Start table */ gtk_html_stream_printf (stream, "<TABLE BORDER=\"0\" WIDTH=\"80%%\">" @@ -237,26 +208,31 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone e_cal_component_free_datetime (&dt); /* write status */ - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:")); - e_cal_component_get_status (comp, &status); - switch (status) { - case ICAL_STATUS_INPROCESS : - str = g_strdup (_("In Progress")); - break; - case ICAL_STATUS_COMPLETED : - str = g_strdup (_("Completed")); - break; - case ICAL_STATUS_CANCELLED : - str = g_strdup (_("Canceled")); - break; - case ICAL_STATUS_NONE : - default : - str = g_strdup (_("Not Started")); - break; - } + icalcomp = e_cal_component_get_icalcomponent (comp); + icalprop = icalcomponent_get_first_property ( + icalcomp, ICAL_STATUS_PROPERTY); + if (icalprop != NULL) { + gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:")); + e_cal_component_get_status (comp, &status); + switch (status) { + case ICAL_STATUS_INPROCESS : + str = g_strdup (_("In Progress")); + break; + case ICAL_STATUS_COMPLETED : + str = g_strdup (_("Completed")); + break; + case ICAL_STATUS_CANCELLED : + str = g_strdup (_("Canceled")); + break; + case ICAL_STATUS_NONE : + default : + str = g_strdup (_("Not Started")); + break; + } - gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); - g_free (str); + gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); + g_free (str); + } /* write priority */ e_cal_component_get_priority (comp, &priority_value); @@ -280,15 +256,15 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone /* write description and URL */ gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); - e_cal_component_get_description_list (comp, &l); - if (l) { + e_cal_component_get_description_list (comp, &list); + if (list) { GSList *node; gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Description:")); gtk_html_stream_printf (stream, "<TD><TT>"); - for (node = l; node != NULL; node = node->next) { + for (node = list; node != NULL; node = node->next) { gchar *html; text = * (ECalComponentText *) node->data; @@ -302,7 +278,7 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone gtk_html_stream_printf (stream, "</TT></TD></TR>"); - e_cal_component_free_text_list (l); + e_cal_component_free_text_list (list); } /* URL */ @@ -319,143 +295,120 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone } static void -e_cal_component_preview_init (ECalComponentPreview *preview) +cal_component_preview_finalize (GObject *object) { ECalComponentPreviewPrivate *priv; - GtkWidget *scroll; - priv = g_new0 (ECalComponentPreviewPrivate, 1); - preview->priv = priv; + priv = E_CAL_COMPONENT_PREVIEW_GET_PRIVATE (object); + + /* XXX Nothing to do? */ - priv->html = gtk_html_new (); - gtk_html_set_default_content_type (GTK_HTML (priv->html), "charset=utf-8"); - gtk_html_load_empty (GTK_HTML (priv->html)); + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} - g_signal_connect (G_OBJECT (priv->html), "url_requested", - G_CALLBACK (e_cal_comp_preview_url_requested_cb), NULL); - g_signal_connect (G_OBJECT (priv->html), "link_clicked", - G_CALLBACK (on_link_clicked), preview); - g_signal_connect (G_OBJECT (priv->html), "on_url", - G_CALLBACK (on_url_cb), preview); +static void +cal_component_preview_class_init (ECalComponentPreviewClass *class) +{ + GObjectClass *object_class; + GtkHTMLClass *gtkhtml_class; - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ECalComponentPreviewPrivate)); - gtk_container_add (GTK_CONTAINER (scroll), priv->html); - gtk_container_add (GTK_CONTAINER (preview), scroll); - gtk_widget_show_all (scroll); + object_class = G_OBJECT_CLASS (class); + object_class->finalize = cal_component_preview_finalize; - priv->zone = icaltimezone_get_utc_timezone (); + gtkhtml_class = GTK_HTML_CLASS (class); + gtkhtml_class->link_clicked = cal_component_preview_link_clicked; + gtkhtml_class->on_url = cal_component_preview_on_url; } static void -e_cal_component_preview_destroy (GtkObject *object) +cal_component_preview_init (ECalComponentPreview *preview) { - ECalComponentPreview *preview; ECalComponentPreviewPrivate *priv; + GtkHTML *html; - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (object)); - - preview = E_CAL_COMPONENT_PREVIEW (object); - priv = preview->priv; - - if (priv) { + preview->priv = E_CAL_COMPONENT_PREVIEW_GET_PRIVATE (preview); - g_free (priv); - preview->priv = NULL; - } + html = GTK_HTML (preview); + gtk_html_set_default_content_type (html, "charset=utf-8"); + gtk_html_load_empty (html); - if (GTK_OBJECT_CLASS (e_cal_component_preview_parent_class)->destroy) - (* GTK_OBJECT_CLASS (e_cal_component_preview_parent_class)->destroy) (object); + priv->zone = icaltimezone_get_utc_timezone (); } -static void -e_cal_component_preview_class_init (ECalComponentPreviewClass *klass) +GType +e_cal_component_preview_get_type (void) { - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) klass; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (ECalComponentPreviewClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) cal_component_preview_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ECalComponentPreview), + 0, /* n_preallocs */ + (GInstanceInitFunc) cal_component_preview_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_HTML, "ECalComponentPreview", &type_info, 0); + } - object_class->destroy = e_cal_component_preview_destroy; + return type; } GtkWidget * e_cal_component_preview_new (void) { - ECalComponentPreview *preview; - - preview = g_object_new (e_cal_component_preview_get_type (), NULL); - - return GTK_WIDGET (preview); + return g_object_new (E_TYPE_CAL_COMPONENT_PREVIEW, NULL); } icaltimezone * e_cal_component_preview_get_default_timezone (ECalComponentPreview *preview) { - ECalComponentPreviewPrivate *priv; - - g_return_val_if_fail (preview != NULL, NULL); g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), NULL); - priv = preview->priv; - - return priv->zone; + return preview->priv->zone; } void -e_cal_component_preview_set_default_timezone (ECalComponentPreview *preview, icaltimezone *zone) +e_cal_component_preview_set_default_timezone (ECalComponentPreview *preview, + icaltimezone *zone) { - ECalComponentPreviewPrivate *priv; - - g_return_if_fail (preview != NULL); g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); g_return_if_fail (zone != NULL); - priv = preview->priv; - - priv->zone = zone; + preview->priv->zone = zone; } void -e_cal_component_preview_display (ECalComponentPreview *preview, ECal *ecal, ECalComponent *comp) +e_cal_component_preview_display (ECalComponentPreview *preview, + ECal *ecal, + ECalComponent *comp) { - ECalComponentPreviewPrivate *priv; GtkHTMLStream *stream; - g_return_if_fail (preview != NULL); g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); - g_return_if_fail (comp != NULL); g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - priv = preview->priv; - - stream = gtk_html_begin (GTK_HTML (priv->html)); - write_html (stream, ecal, comp, priv->zone); + stream = gtk_html_begin (GTK_HTML (preview)); + cal_component_preview_write_html ( + stream, ecal, comp, preview->priv->zone); gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); } void e_cal_component_preview_clear (ECalComponentPreview *preview) { - ECalComponentPreviewPrivate *priv; - - g_return_if_fail (preview != NULL); g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); - priv = preview->priv; - - gtk_html_load_empty (GTK_HTML (priv->html)); -} - -GtkWidget * -e_cal_component_preview_get_html (ECalComponentPreview *preview) -{ - g_return_val_if_fail (preview != NULL, NULL); - g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), NULL); - - return preview->priv->html; + gtk_html_load_empty (GTK_HTML (preview)); } diff --git a/calendar/gui/e-cal-component-preview.h b/calendar/gui/e-cal-component-preview.h index dd355c01ce..053c3c8266 100644 --- a/calendar/gui/e-cal-component-preview.h +++ b/calendar/gui/e-cal-component-preview.h @@ -1,5 +1,4 @@ /* - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -22,52 +21,63 @@ * */ -#ifndef _E_CAL_COMPONENT_PREVIEW_H_ -#define _E_CAL_COMPONENT_PREVIEW_H_ +#ifndef E_CAL_COMPONENT_PREVIEW_H +#define E_CAL_COMPONENT_PREVIEW_H #include <gtk/gtk.h> #include <libecal/e-cal.h> #include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> -#define E_TYPE_CAL_COMPONENT_PREVIEW (e_cal_component_preview_get_type ()) -#define E_CAL_COMPONENT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreview)) -#define E_CAL_COMPONENT_PREVIEW_CLASS(klass) (G_TYPE_CHECK_INSTANCE_CAST_CLASS ((klass), E_TYPE_CAL_COMPONENT_PREVIEW, \ - ECalComponentPreviewClass)) -#define E_IS_CAL_COMPONENT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CAL_COMPONENT_PREVIEW)) -#define E_IS_CAL_COMPONENT_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CAL_COMPONENT_PREVIEW)) +/* Standard GObject macros */ +#define E_TYPE_CAL_COMPONENT_PREVIEW \ + (e_cal_component_preview_get_type ()) +#define E_CAL_COMPONENT_PREVIEW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreview)) +#define E_CAL_COMPONENT_PREVIEW_CLASS(cls) \ + (G_TYPE_CHECK_INSTANCE_CAST_CLASS \ + ((cls), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreviewClass)) +#define E_IS_CAL_COMPONENT_PREVIEW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_CAL_COMPONENT_PREVIEW)) +#define E_IS_CAL_COMPONENT_PREVIEW_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_CAL_COMPONENT_PREVIEW)) +#define E_CAL_COMPONENT_PREVIEW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_CAL_COMPONENT_PREVIEW, ECalComponentPreviewClass)) + +G_BEGIN_DECLS typedef struct _ECalComponentPreview ECalComponentPreview; typedef struct _ECalComponentPreviewClass ECalComponentPreviewClass; typedef struct _ECalComponentPreviewPrivate ECalComponentPreviewPrivate; struct _ECalComponentPreview { - GtkTable table; - - /* Private data */ + GtkHTML parent; ECalComponentPreviewPrivate *priv; }; struct _ECalComponentPreviewClass { - GtkTableClass parent_class; + GtkHTMLClass parent_class; /* Notification signals */ void (* selection_changed) (ECalComponentPreview *preview, gint n_selected); }; -GType e_cal_component_preview_get_type (void); -GtkWidget *e_cal_component_preview_new (void); - -icaltimezone *e_cal_component_preview_get_default_timezone (ECalComponentPreview *preview); -void e_cal_component_preview_set_default_timezone (ECalComponentPreview *preview, icaltimezone *zone); - -void e_cal_component_preview_display (ECalComponentPreview *preview, ECal *ecal, ECalComponent *comp); -void e_cal_component_preview_clear (ECalComponentPreview *preview); - -/* Callback used when GtkHTML widget requests URL */ -void e_cal_comp_preview_url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *html_stream, gpointer data); +GType e_cal_component_preview_get_type(void); +GtkWidget * e_cal_component_preview_new (void); +icaltimezone * e_cal_component_preview_get_default_timezone + (ECalComponentPreview *preview); +void e_cal_component_preview_set_default_timezone + (ECalComponentPreview *preview, + icaltimezone *zone); +void e_cal_component_preview_display (ECalComponentPreview *preview, + ECal *ecal, + ECalComponent *comp); +void e_cal_component_preview_clear (ECalComponentPreview *preview); -GtkWidget *e_cal_component_preview_get_html (ECalComponentPreview *preview); +G_END_DECLS -#endif /* _E_CAL_COMPONENT_PREVIEW_H_ */ +#endif /* E_CAL_COMPONENT_PREVIEW_H */ diff --git a/calendar/gui/e-cal-event.c b/calendar/gui/e-cal-event.c index 86bd20e4e7..a05711a7f4 100644 --- a/calendar/gui/e-cal-event.c +++ b/calendar/gui/e-cal-event.c @@ -43,10 +43,10 @@ static void ece_target_free (EEvent *ev, EEventTarget *t) { switch (t->type) { - case E_CAL_EVENT_TARGET_COMPONENT: { - ECalEventTargetComponent *s = (ECalEventTargetComponent *) t; - if (s->component) - g_object_unref (s->component); + case E_CAL_EVENT_TARGET_MODULE: { + ECalEventTargetModule *s = (ECalEventTargetModule *) t; + if (s->shell_backend) + g_object_unref (s->shell_backend); break; } } @@ -92,12 +92,12 @@ e_cal_event_peek (void) return e_cal_event; } -ECalEventTargetComponent * -e_cal_event_target_new_component (ECalEvent *ece, struct _CalendarComponent *component, guint32 flags) +ECalEventTargetModule * +e_cal_event_target_new_module (ECalEvent *ece, EShellBackend *shell_backend, guint32 flags) { - ECalEventTargetComponent *t = e_event_target_new (&ece->event, E_CAL_EVENT_TARGET_COMPONENT, sizeof (*t)); + ECalEventTargetModule *t = e_event_target_new (&ece->event, E_CAL_EVENT_TARGET_MODULE, sizeof (*t)); - t->component = g_object_ref (component); + t->shell_backend = g_object_ref (shell_backend); t->target.mask = ~flags; return t; @@ -107,13 +107,13 @@ e_cal_event_target_new_component (ECalEvent *ece, struct _CalendarComponent *com static gpointer eceh_parent_class; -static const EEventHookTargetMask eceh_component_masks[] = { - { "migration", E_CAL_EVENT_COMPONENT_MIGRATION }, +static const EEventHookTargetMask eceh_module_masks[] = { + { "migration", E_CAL_EVENT_MODULE_MIGRATION }, { NULL }, }; static const EEventHookTargetMap eceh_targets[] = { - { "component", E_CAL_EVENT_TARGET_COMPONENT, eceh_component_masks }, + { "module", E_CAL_EVENT_TARGET_MODULE, eceh_module_masks }, { NULL }, }; diff --git a/calendar/gui/e-cal-event.h b/calendar/gui/e-cal-event.h index 8fb28dfd17..e219679f89 100644 --- a/calendar/gui/e-cal-event.h +++ b/calendar/gui/e-cal-event.h @@ -27,6 +27,7 @@ #include <glib-object.h> #include "e-util/e-event.h" +#include "shell/e-shell-backend.h" G_BEGIN_DECLS @@ -34,20 +35,19 @@ typedef struct _ECalEvent ECalEvent; typedef struct _ECalEventClass ECalEventClass; enum _e_cal_event_target_t { - E_CAL_EVENT_TARGET_COMPONENT + E_CAL_EVENT_TARGET_MODULE, }; -/* Flags that describe TARGET_COMPONENT */ +/* Flags that describe TARGET_MODULE */ enum { - E_CAL_EVENT_COMPONENT_MIGRATION = 1 << 0 + E_CAL_EVENT_MODULE_MIGRATION = 1 << 0, }; -typedef struct _ECalEventTargetComponent ECalEventTargetComponent; +typedef struct _ECalEventTargetModule ECalEventTargetModule; -struct _ECalEventTargetComponent { +struct _ECalEventTargetModule { EEventTarget target; - - struct _CalendarComponent *component; + EShellBackend *shell_backend; }; struct _ECalEvent { @@ -62,7 +62,7 @@ struct _ECalEventClass { GType e_cal_event_get_type (void); ECalEvent* e_cal_event_peek (void); -ECalEventTargetComponent* e_cal_event_target_new_component (ECalEvent *ece, struct _CalendarComponent *component, guint32 flags); +ECalEventTargetModule* e_cal_event_target_new_module (ECalEvent *ece, EShellBackend *shell_backend, guint32 flags); /* ********************************************************************** */ diff --git a/calendar/gui/e-cal-list-view.c b/calendar/gui/e-cal-list-view.c index f62db91985..26edef8bcd 100644 --- a/calendar/gui/e-cal-list-view.c +++ b/calendar/gui/e-cal-list-view.c @@ -25,7 +25,7 @@ #endif #include "e-cal-list-view.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ #include <math.h> #include <time.h> @@ -41,7 +41,7 @@ #include <table/e-cell-text.h> #include <table/e-cell-combo.h> #include <misc/e-popup-menu.h> -#include <misc/e-cell-date-edit.h> +#include <table/e-cell-date-edit.h> #include <e-util/e-categories-config.h> #include <e-util/e-dialog-utils.h> #include <e-util/e-util-private.h> @@ -56,7 +56,6 @@ #include "dialogs/recur-comp.h" #include "comp-util.h" #include "itip-utils.h" -#include "calendar-commands.h" #include "calendar-config.h" #include "goto.h" #include "misc.h" @@ -358,10 +357,12 @@ e_cal_list_view_destroy (GtkObject *object) static void e_cal_list_view_show_popup_menu (ECalListView *cal_list_view, gint row, GdkEvent *gdk_event) { +#if 0 /* KILL-BONOBO */ GtkMenu *menu; menu = e_calendar_view_create_popup_menu (E_CALENDAR_VIEW (cal_list_view)); gtk_menu_popup(menu, NULL, NULL, NULL, NULL, gdk_event?gdk_event->button.button:0, gdk_event?gdk_event->button.time:gtk_get_current_event_time()); +#endif } static gboolean diff --git a/calendar/gui/e-cal-model-memos.c b/calendar/gui/e-cal-model-memos.c index 414a0698e3..995ed9c5cb 100644 --- a/calendar/gui/e-cal-model-memos.c +++ b/calendar/gui/e-cal-model-memos.c @@ -261,7 +261,7 @@ ecmm_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data, /** * e_cal_model_memos_new */ -ECalModelMemos * +ECalModel * e_cal_model_memos_new (void) { return g_object_new (E_TYPE_CAL_MODEL_MEMOS, NULL); diff --git a/calendar/gui/e-cal-model-memos.h b/calendar/gui/e-cal-model-memos.h index 34b8e5a14d..f7a5d17091 100644 --- a/calendar/gui/e-cal-model-memos.h +++ b/calendar/gui/e-cal-model-memos.h @@ -55,8 +55,8 @@ typedef struct { ECalModelClass parent_class; } ECalModelMemosClass; -GType e_cal_model_memos_get_type (void); -ECalModelMemos *e_cal_model_memos_new (void); +GType e_cal_model_memos_get_type (void); +ECalModel * e_cal_model_memos_new (void); G_END_DECLS diff --git a/calendar/gui/e-cal-model-tasks.c b/calendar/gui/e-cal-model-tasks.c index 63bc37af4e..5a0a75bea2 100644 --- a/calendar/gui/e-cal-model-tasks.c +++ b/calendar/gui/e-cal-model-tasks.c @@ -1108,7 +1108,7 @@ ecmt_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data, /** * e_cal_model_tasks_new */ -ECalModelTasks * +ECalModel * e_cal_model_tasks_new (void) { return g_object_new (E_TYPE_CAL_MODEL_TASKS, NULL); diff --git a/calendar/gui/e-cal-model-tasks.h b/calendar/gui/e-cal-model-tasks.h index 0900d1e155..88b0d071e2 100644 --- a/calendar/gui/e-cal-model-tasks.h +++ b/calendar/gui/e-cal-model-tasks.h @@ -64,7 +64,7 @@ typedef struct { } ECalModelTasksClass; GType e_cal_model_tasks_get_type (void); -ECalModelTasks *e_cal_model_tasks_new (void); +ECalModel * e_cal_model_tasks_new (void); void e_cal_model_tasks_mark_comp_complete (ECalModelTasks *model, ECalModelComponent *comp_data); void e_cal_model_tasks_mark_comp_incomplete (ECalModelTasks *model, ECalModelComponent *comp_data); diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index eec7403ff3..4af9b88994 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -35,8 +35,8 @@ #include "e-cal-model.h" #include "itip-utils.h" #include "misc.h" -#include "e-util/e-util.h" #include "calendar-config.h" +#include "e-util/e-util.h" typedef struct { ECal *client; diff --git a/calendar/gui/e-calendar-selector.c b/calendar/gui/e-calendar-selector.c new file mode 100644 index 0000000000..54858e56f9 --- /dev/null +++ b/calendar/gui/e-calendar-selector.c @@ -0,0 +1,226 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-calendar-selector.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-calendar-selector.h" + +#include <libecal/e-cal.h> +#include "common/authentication.h" + +#define E_CALENDAR_SELECTOR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorPrivate)) + +struct _ECalendarSelectorPrivate { + gint dummy_value; +}; + +enum { + DND_TARGET_TYPE_CALENDAR_LIST +}; + +static GtkTargetEntry drag_types[] = { + { "text/calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST }, + { "text/x-calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST } +}; + +static gpointer parent_class; + +static gboolean +calendar_selector_update_single_object (ECal *client, + icalcomponent *icalcomp) +{ + gchar *uid; + icalcomponent *tmp_icalcomp; + + uid = (gchar *) icalcomponent_get_uid (icalcomp); + + if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, NULL)) + return e_cal_modify_object ( + client, icalcomp, CALOBJ_MOD_ALL, NULL); + + return e_cal_create_object (client, icalcomp, &uid, NULL); +} + +static gboolean +calendar_selector_update_objects (ECal *client, + icalcomponent *icalcomp) +{ + icalcomponent *subcomp; + icalcomponent_kind kind; + + kind = icalcomponent_isa (icalcomp); + if (kind == ICAL_VTODO_COMPONENT || kind == ICAL_VEVENT_COMPONENT) + return calendar_selector_update_single_object ( + client, icalcomp); + else if (kind != ICAL_VCALENDAR_COMPONENT) + return FALSE; + + subcomp = icalcomponent_get_first_component ( + icalcomp, ICAL_ANY_COMPONENT); + while (subcomp != NULL) { + gboolean success; + + kind = icalcomponent_isa (subcomp); + if (kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + + success = e_cal_add_timezone (client, zone, NULL); + icaltimezone_free (zone, 1); + if (!success) + return FALSE; + } else if (kind == ICAL_VTODO_COMPONENT || + kind == ICAL_VEVENT_COMPONENT) { + success = calendar_selector_update_single_object ( + client, subcomp); + if (!success) + return FALSE; + } + + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + return TRUE; +} + +static gboolean +calendar_selector_data_dropped (ESourceSelector *selector, + GtkSelectionData *selection_data, + ESource *destination, + GdkDragAction action, + guint info) +{ + GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreePath *path = NULL; + ECal *client; + icalcomponent *icalcomp; + const gchar *string; + gboolean remove_from_source; + gboolean success = FALSE; + gpointer object = NULL; + + tree_view = GTK_TREE_VIEW (selector); + model = gtk_tree_view_get_model (tree_view); + + string = (const gchar *) selection_data->data; + remove_from_source = (action == GDK_ACTION_MOVE); + + icalcomp = icalparser_parse_string (string); + + if (icalcomp == NULL) + goto exit; + + /* FIXME Deal with GDK_ACTION_ASK. */ + if (action == GDK_ACTION_COPY) { + gchar *uid; + + uid = e_cal_component_gen_uid (); + icalcomponent_set_uid (icalcomp, uid); + } + + client = auth_new_cal_from_source ( + destination, E_CAL_SOURCE_TYPE_EVENT); + + if (client != NULL) { + if (e_cal_open (client, TRUE, NULL)) { + success = TRUE; + calendar_selector_update_objects (client, icalcomp); + } + + g_object_unref (client); + } + + icalcomponent_free (icalcomp); + + success = TRUE; + +exit: + if (path != NULL) + gtk_tree_path_free (path); + + if (object != NULL) + g_object_unref (object); + + return TRUE; +} + +static void +calendar_selector_class_init (ECalendarSelectorClass *class) +{ + ESourceSelectorClass *source_selector_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ECalendarSelectorPrivate)); + + source_selector_class = E_SOURCE_SELECTOR_CLASS (class); + source_selector_class->data_dropped = calendar_selector_data_dropped; +} + +static void +calendar_selector_init (ECalendarSelector *selector) +{ + selector->priv = E_CALENDAR_SELECTOR_GET_PRIVATE (selector); + + gtk_drag_dest_set ( + GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL, + drag_types, G_N_ELEMENTS (drag_types), + GDK_ACTION_COPY | GDK_ACTION_MOVE); +} + +GType +e_calendar_selector_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (ECalendarSelectorClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) calendar_selector_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ECalendarSelector), + 0, /* n_preallocs */ + (GInstanceInitFunc) calendar_selector_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + E_TYPE_SOURCE_SELECTOR, "ECalendarSelector", + &type_info, 0); + } + + return type; +} + +GtkWidget * +e_calendar_selector_new (ESourceList *source_list) +{ + g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL); + + return g_object_new ( + E_TYPE_CALENDAR_SELECTOR, + "source-list", source_list, NULL); +} diff --git a/calendar/gui/e-calendar-selector.h b/calendar/gui/e-calendar-selector.h new file mode 100644 index 0000000000..65d9a2fc81 --- /dev/null +++ b/calendar/gui/e-calendar-selector.h @@ -0,0 +1,66 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-calendar-selector.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef E_CALENDAR_SELECTOR_H +#define E_CALENDAR_SELECTOR_H + +#include <libedataserver/e-source-list.h> +#include <libedataserverui/e-source-selector.h> + +/* Standard GObject macros */ +#define E_TYPE_CALENDAR_SELECTOR \ + (e_calendar_selector_get_type ()) +#define E_CALENDAR_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelector)) +#define E_CALENDAR_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorClass)) +#define E_IS_CALENDAR_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_CALENDAR_SELECTOR)) +#define E_IS_CALENDAR_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_CALENDAR_SELECTOR)) +#define E_CALENDAR_SELECTOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_CALENDAR_SELECTOR, ECalendarSelectorClass)) + +G_BEGIN_DECLS + +typedef struct _ECalendarSelector ECalendarSelector; +typedef struct _ECalendarSelectorClass ECalendarSelectorClass; +typedef struct _ECalendarSelectorPrivate ECalendarSelectorPrivate; + +struct _ECalendarSelector { + ESourceSelector parent; + ECalendarSelectorPrivate *priv; +}; + +struct _ECalendarSelectorClass { + ESourceSelectorClass parent_class; +}; + +GType e_calendar_selector_get_type (void); +GtkWidget * e_calendar_selector_new (ESourceList *source_list); + +G_END_DECLS + +#endif /* E_CALENDAR_SELECTOR_H */ diff --git a/calendar/gui/e-calendar-table-config.c b/calendar/gui/e-calendar-table-config.c index fb8d18c189..8b73056f51 100644 --- a/calendar/gui/e-calendar-table-config.c +++ b/calendar/gui/e-calendar-table-config.c @@ -24,221 +24,245 @@ #include "e-cell-date-edit-config.h" #include "e-calendar-table-config.h" +#define E_CALENDAR_TABLE_CONFIG_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_CALENDAR_TABLE_CONFIG, ECalendarTableConfigPrivate)) + struct _ECalendarTableConfigPrivate { ECalendarTable *table; - ECellDateEditConfig *cell_config; - GList *notifications; }; -/* Property IDs */ -enum props { +enum { PROP_0, PROP_TABLE }; -G_DEFINE_TYPE (ECalendarTableConfig, e_calendar_table_config, G_TYPE_OBJECT) +static gpointer parent_class; static void -e_calendar_table_config_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +calendar_table_config_set_timezone (ECalendarTable *table) { - ECalendarTableConfig *table_config; - - table_config = E_CALENDAR_TABLE_CONFIG (object); + ECalModel *model; + icaltimezone *zone; - switch (property_id) { - case PROP_TABLE: - e_calendar_table_config_set_table (table_config, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } + zone = calendar_config_get_icaltimezone (); + model = e_calendar_table_get_model (table); + if (model != NULL) + e_cal_model_set_timezone (model, zone); } static void -e_calendar_table_config_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +calendar_table_config_timezone_changed_cb (GConfClient *client, + guint id, + GConfEntry *entry, + gpointer data) { - ECalendarTableConfig *table_config; - - table_config = E_CALENDAR_TABLE_CONFIG (object); + ECalendarTableConfig *table_config = data; - switch (property_id) { - case PROP_TABLE: - g_value_set_object (value, e_calendar_table_config_get_table (table_config)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } + calendar_table_config_set_timezone (table_config->priv->table); } static void -e_calendar_table_config_dispose (GObject *object) +calendar_table_config_set_twentyfour_hour (ECalendarTable *table) { - ECalendarTableConfig *table_config = E_CALENDAR_TABLE_CONFIG (object); + ECalModel *model; + gboolean use_24_hour; - e_calendar_table_config_set_table (table_config, NULL); + use_24_hour = calendar_config_get_24_hour_format (); - if (G_OBJECT_CLASS (e_calendar_table_config_parent_class)->dispose) - G_OBJECT_CLASS (e_calendar_table_config_parent_class)->dispose (object); + model = e_calendar_table_get_model (table); + if (model != NULL) + e_cal_model_set_use_24_hour_format (model, use_24_hour); } static void -e_calendar_table_config_finalize (GObject *object) +calendar_table_config_twentyfour_hour_changed_cb (GConfClient *client, + guint id, + GConfEntry *entry, + gpointer data) { - ECalendarTableConfig *table_config = E_CALENDAR_TABLE_CONFIG (object); - ECalendarTableConfigPrivate *priv; - - priv = table_config->priv; - - g_free (priv); + ECalendarTableConfig *table_config = data; - if (G_OBJECT_CLASS (e_calendar_table_config_parent_class)->finalize) - G_OBJECT_CLASS (e_calendar_table_config_parent_class)->finalize (object); + calendar_table_config_set_twentyfour_hour (table_config->priv->table); } static void -e_calendar_table_config_class_init (ECalendarTableConfigClass *klass) +calendar_table_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *spec; - - /* Method override */ - gobject_class->set_property = e_calendar_table_config_set_property; - gobject_class->get_property = e_calendar_table_config_get_property; - gobject_class->dispose = e_calendar_table_config_dispose; - gobject_class->finalize = e_calendar_table_config_finalize; - - spec = g_param_spec_object ("table", NULL, NULL, e_calendar_table_get_type (), - G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT); - g_object_class_install_property (gobject_class, PROP_TABLE, spec); + switch (property_id) { + case PROP_TABLE: + e_calendar_table_config_set_table ( + E_CALENDAR_TABLE_CONFIG (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -e_calendar_table_config_init (ECalendarTableConfig *table_config) +calendar_table_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - table_config->priv = g_new0 (ECalendarTableConfigPrivate, 1); + switch (property_id) { + case PROP_TABLE: + g_value_set_object ( + value, e_calendar_table_config_get_table ( + E_CALENDAR_TABLE_CONFIG (object))); + return; + } + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } -ECalendarTableConfig * -e_calendar_table_config_new (ECalendarTable *table) +static void +calendar_table_config_dispose (GObject *object) { - ECalendarTableConfig *table_config; + ECalendarTableConfig *table_config = E_CALENDAR_TABLE_CONFIG (object); - table_config = g_object_new (e_calendar_table_config_get_type (), "table", table, NULL); + e_calendar_table_config_set_table (table_config, NULL); - return table_config; + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); } -ECalendarTable * -e_calendar_table_config_get_table (ECalendarTableConfig *table_config) +static void +calendar_table_config_class_init (ECalendarTableConfigClass *class) { - ECalendarTableConfigPrivate *priv; - - g_return_val_if_fail (table_config != NULL, NULL); - g_return_val_if_fail (E_IS_CALENDAR_TABLE_CONFIG (table_config), NULL); - - priv = table_config->priv; - - return priv->table; + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ECalendarTableConfigPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = calendar_table_config_set_property; + object_class->get_property = calendar_table_config_get_property; + object_class->dispose = calendar_table_config_dispose; + + g_object_class_install_property ( + object_class, + PROP_TABLE, + g_param_spec_object ( + "table", + NULL, + NULL, + E_TYPE_CALENDAR_TABLE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); } static void -set_timezone (ECalendarTable *table) +calendar_table_config_init (ECalendarTableConfig *table_config) { - ECalModel *model; - icaltimezone *zone; - - zone = calendar_config_get_icaltimezone (); - model = e_calendar_table_get_model (table); - if (model) - e_cal_model_set_timezone (model, zone); + table_config->priv = + E_CALENDAR_TABLE_CONFIG_GET_PRIVATE (table_config); } -static void -timezone_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) +GType +e_calendar_table_config_get_type (void) { - ECalendarTableConfig *table_config = data; - ECalendarTableConfigPrivate *priv; - - priv = table_config->priv; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (ECalendarTableConfigClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) calendar_table_config_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ECalendarTableConfig), + 0, /* n_preallocs */ + (GInstanceInitFunc) calendar_table_config_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + G_TYPE_OBJECT, "ECalendarTableConfig", &type_info, 0); + } - set_timezone (priv->table); + return type; } -static void -set_twentyfour_hour (ECalendarTable *table) +ECalendarTableConfig * +e_calendar_table_config_new (ECalendarTable *table) { - ECalModel *model; - gboolean use_24_hour; + g_return_val_if_fail (E_IS_CALENDAR_TABLE (table), NULL); - use_24_hour = calendar_config_get_24_hour_format (); - - model = e_calendar_table_get_model (table); - if (model) - e_cal_model_set_use_24_hour_format (model, use_24_hour); + return g_object_new ( + E_TYPE_CALENDAR_TABLE_CONFIG, + "table", table, NULL); } -static void -twentyfour_hour_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) +ECalendarTable * +e_calendar_table_config_get_table (ECalendarTableConfig *table_config) { - ECalendarTableConfig *table_config = data; - ECalendarTableConfigPrivate *priv; - - priv = table_config->priv; + g_return_val_if_fail (E_IS_CALENDAR_TABLE_CONFIG (table_config), NULL); - set_twentyfour_hour (priv->table); + return table_config->priv->table; } void -e_calendar_table_config_set_table (ECalendarTableConfig *table_config, ECalendarTable *table) +e_calendar_table_config_set_table (ECalendarTableConfig *table_config, + ECalendarTable *table) { ECalendarTableConfigPrivate *priv; - guint not; - GList *l; + guint notification; + GList *list, *iter; - g_return_if_fail (table_config != NULL); g_return_if_fail (E_IS_CALENDAR_TABLE_CONFIG (table_config)); priv = table_config->priv; - if (priv->table) { - g_object_unref (priv->table); - priv->table = NULL; + if (table_config->priv->table) { + g_object_unref (table_config->priv->table); + table_config->priv->table = NULL; } - if (priv->cell_config) { - g_object_unref (priv->cell_config); - priv->cell_config = NULL; + if (table_config->priv->cell_config) { + g_object_unref (table_config->priv->cell_config); + table_config->priv->cell_config = NULL; } - for (l = priv->notifications; l; l = l->next) - calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); - - g_list_free (priv->notifications); - priv->notifications = NULL; + list = table_config->priv->notifications; + for (iter = list; iter != NULL; iter = iter->next) { + notification = GPOINTER_TO_UINT (iter->data); + calendar_config_remove_notification (notification); + } + g_list_free (list); + table_config->priv->notifications = NULL; - /* If the new view is NULL, return right now */ - if (!table) + if (table == NULL) return; - priv->table = g_object_ref (table); + table_config->priv->table = g_object_ref (table); /* Time zone */ - set_timezone (table); + calendar_table_config_set_timezone (table); - not = calendar_config_add_notification_timezone (timezone_changed_cb, table_config); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); + notification = calendar_config_add_notification_timezone ( + calendar_table_config_timezone_changed_cb, table_config); + table_config->priv->notifications = g_list_prepend ( + table_config->priv->notifications, + GUINT_TO_POINTER (notification)); /* 24 Hour format */ - set_twentyfour_hour (table); + calendar_table_config_set_twentyfour_hour (table); - not = calendar_config_add_notification_24_hour_format (twentyfour_hour_changed_cb, table_config); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); + notification = calendar_config_add_notification_24_hour_format ( + calendar_table_config_twentyfour_hour_changed_cb, table_config); + table_config->priv->notifications = g_list_prepend ( + table_config->priv->notifications, + GUINT_TO_POINTER (notification)); /* Date cell */ - priv->cell_config = e_cell_date_edit_config_new (table->dates_cell); + table_config->priv->cell_config = + e_cell_date_edit_config_new (table->dates_cell); } diff --git a/calendar/gui/e-calendar-table-config.h b/calendar/gui/e-calendar-table-config.h index 93588a6e57..36745064d1 100644 --- a/calendar/gui/e-calendar-table-config.h +++ b/calendar/gui/e-calendar-table-config.h @@ -21,24 +21,38 @@ * */ -#ifndef _E_CALENDAR_TABLE_CONFIG_H_ -#define _E_CALENDAR_TABLE_CONFIG_H_ +#ifndef E_CALENDAR_TABLE_CONFIG_H +#define E_CALENDAR_TABLE_CONFIG_H #include "e-calendar-table.h" -G_BEGIN_DECLS +/* Standard GObject macros */ +#define E_TYPE_CALENDAR_TABLE_CONFIG \ + (e_calendar_table_config_get_type ()) +#define E_CALENDAR_TABLE_CONFIG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_CALENDAR_TABLE_CONFIG, ECalendarTableConfig)) +#define E_CALENDAR_TABLE_CONFIG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_CALENDAR_TABLE_CONFIG, ECalendarTableConfigClass)) +#define E_IS_CALENDAR_TABLE_CONFIG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_CALENDAR_TABLE_CONFIG)) +#define E_IS_CALENDAR_TABLE_CONFIG_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_CALENDAR_TABLE_CONFIG)) +#define E_CALENDAR_TABLE_CONFIG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_CALENDAR_TABLE_CONFIG, ECalendarTableConfigClass)) -#define E_CALENDAR_TABLE_CONFIG(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, e_calendar_table_config_get_type (), ECalendarTableConfig) -#define E_CALENDAR_TABLE_CONFIG_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, e_calendar_table_config_get_type (), ECalendarTableConfigClass) -#define E_IS_CALENDAR_TABLE_CONFIG(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, e_calendar_table_config_get_type ()) +G_BEGIN_DECLS -typedef struct _ECalendarTableConfig ECalendarTableConfig; -typedef struct _ECalendarTableConfigClass ECalendarTableConfigClass; +typedef struct _ECalendarTableConfig ECalendarTableConfig; +typedef struct _ECalendarTableConfigClass ECalendarTableConfigClass; typedef struct _ECalendarTableConfigPrivate ECalendarTableConfigPrivate; struct _ECalendarTableConfig { GObject parent; - ECalendarTableConfigPrivate *priv; }; @@ -46,11 +60,15 @@ struct _ECalendarTableConfigClass { GObjectClass parent_class; }; -GType e_calendar_table_config_get_type (void); -ECalendarTableConfig *e_calendar_table_config_new (ECalendarTable *table); -ECalendarTable *e_calendar_table_config_get_table (ECalendarTableConfig *view_config); -void e_calendar_table_config_set_table (ECalendarTableConfig *view_config, ECalendarTable *table); +GType e_calendar_table_config_get_type(void); +ECalendarTableConfig * + e_calendar_table_config_new (ECalendarTable *table); +ECalendarTable *e_calendar_table_config_get_table + (ECalendarTableConfig *table_config); +void e_calendar_table_config_set_table + (ECalendarTableConfig *table_config, + ECalendarTable *table); G_END_DECLS -#endif +#endif /* E_CALENDAR_TABLE_CONFIG_H */ diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index 9eb53d9006..7771be234f 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -32,7 +32,6 @@ #include <sys/stat.h> #include <unistd.h> -#include <glib.h> #include <glib/gi18n.h> #include <glib/gstdio.h> #include <gtk/gtk.h> @@ -44,12 +43,11 @@ #include <table/e-cell-combo.h> #include <e-util/e-dialog-utils.h> #include <e-util/e-util-private.h> -#include <misc/e-cell-date-edit.h> -#include <misc/e-cell-percent.h> +#include <table/e-cell-date-edit.h> +#include <table/e-cell-percent.h> #include <libecal/e-cal-time-util.h> #include <libedataserver/e-time-utils.h> -#include "calendar-component.h" #include "calendar-config.h" #include "dialogs/delete-comp.h" #include "dialogs/delete-error.h" @@ -58,65 +56,50 @@ #include "e-calendar-table.h" #include "e-calendar-view.h" #include "e-cell-date-edit-text.h" -#include "e-comp-editor-registry.h" #include "print.h" #include <e-util/e-icon-factory.h> #include "e-cal-popup.h" -#include "e-tasks.h" #include "misc.h" -enum TargetType{ - TARGET_TYPE_VCALENDAR -}; +#define E_CALENDAR_TABLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_CALENDAR_TABLE, ECalendarTablePrivate)) -static GtkTargetEntry target_types[] = { - { (gchar *) "text/x-calendar", 0, TARGET_TYPE_VCALENDAR }, - { (gchar *) "text/calendar", 0, TARGET_TYPE_VCALENDAR } +struct _ECalendarTablePrivate { + gpointer shell_view; /* weak pointer */ + ECalModel *model; }; -static guint n_target_types = G_N_ELEMENTS (target_types); +enum { + PROP_0, + PROP_MODEL, + PROP_SHELL_VIEW +}; -extern ECompEditorRegistry *comp_editor_registry; - -static void e_calendar_table_destroy (GtkObject *object); - -static void e_calendar_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table); -static gint e_calendar_table_show_popup_menu (ETable *table, - GdkEvent *gdk_event, - ECalendarTable *cal_table); - -static gint e_calendar_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table); -static gboolean e_calendar_table_on_popup_menu (GtkWidget *widget, - gpointer data); - -static gint e_calendar_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - ECalendarTable *cal_table); - -static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, - gpointer data); -static void mark_as_complete_cb (EPopup *ep, EPopupItem *pitem, gpointer data); - -static void hide_completed_rows (ECalModel *model, GList *clients_list, gchar *hide_sexp, GPtrArray *comp_objects); -static void show_completed_rows (ECalModel *model, GList *clients_list, gchar *show_sexp, GPtrArray *comp_objects); - -/* Signal IDs */ enum { + OPEN_COMPONENT, + POPUP_EVENT, + STATUS_MESSAGE, USER_CREATED, LAST_SIGNAL }; -static guint signals[LAST_SIGNAL] = { 0 }; +enum { + TARGET_TYPE_VCALENDAR +}; + +static GtkTargetEntry target_types[] = { + { "text/calendar", 0, TARGET_TYPE_VCALENDAR }, + { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR } +}; + +static guint n_target_types = G_N_ELEMENTS (target_types); + +static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data); + +static gpointer parent_class; +static guint signals[LAST_SIGNAL]; +static GdkAtom clipboard_atom; /* The icons to represent the task. */ #define E_CALENDAR_MODEL_NUM_ICONS 4 @@ -125,36 +108,45 @@ static const gchar * icon_names[E_CALENDAR_MODEL_NUM_ICONS] = { }; static GdkPixbuf* icon_pixbufs[E_CALENDAR_MODEL_NUM_ICONS] = { NULL }; -static GdkAtom clipboard_atom = GDK_NONE; +static void +calendar_table_emit_open_component (ECalendarTable *cal_table, + ECalModelComponent *comp_data) +{ + guint signal_id = signals[OPEN_COMPONENT]; -G_DEFINE_TYPE (ECalendarTable, e_calendar_table, GTK_TYPE_TABLE) + g_signal_emit (cal_table, signal_id, 0, comp_data); +} static void -e_calendar_table_class_init (ECalendarTableClass *class) +calendar_table_emit_popup_event (ECalendarTable *cal_table, + GdkEvent *event) { - GtkObjectClass *object_class; + guint signal_id = signals[POPUP_EVENT]; - object_class = (GtkObjectClass *) class; + g_signal_emit (cal_table, signal_id, 0, event); +} - /* Method override */ - object_class->destroy = e_calendar_table_destroy; +static void +calendar_table_emit_status_message (ECalendarTable *cal_table, + const gchar *message, + gdouble percent) +{ + guint signal_id = signals[STATUS_MESSAGE]; + + g_signal_emit (cal_table, signal_id, 0, message, percent); +} - signals[USER_CREATED] = - g_signal_new ("user_created", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECalendarTableClass, user_created), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); +static void +calendar_table_emit_user_created (ECalendarTable *cal_table) +{ + guint signal_id = signals[USER_CREATED]; - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); + g_signal_emit (cal_table, signal_id, 0); } static gint -date_compare_cb (gconstpointer a, gconstpointer b) +calendar_table_date_compare_cb (gconstpointer a, + gconstpointer b) { ECellDateEditValue *dv1 = (ECellDateEditValue *) a; ECellDateEditValue *dv2 = (ECellDateEditValue *) b; @@ -182,24 +174,18 @@ date_compare_cb (gconstpointer a, gconstpointer b) } static gint -percent_compare_cb (gconstpointer a, gconstpointer b) +calendar_table_percent_compare_cb (gconstpointer a, + gconstpointer b) { gint percent1 = GPOINTER_TO_INT (a); gint percent2 = GPOINTER_TO_INT (b); - gint retval; - if (percent1 > percent2) - retval = 1; - else if (percent1 < percent2) - retval = -1; - else - retval = 0; - - return retval; + return (percent1 < percent2) ? -1 : (percent1 > percent2); } static gint -priority_compare_cb (gconstpointer a, gconstpointer b) +calendar_table_priority_compare_cb (gconstpointer a, + gconstpointer b) { gint priority1, priority2; @@ -213,71 +199,85 @@ priority_compare_cb (gconstpointer a, gconstpointer b) priority2 = 10; /* We'll just use the ordering of the priority values. */ - if (priority1 < priority2) - return -1; - else if (priority1 > priority2) - return 1; - else - return 0; + return (priority1 < priority2) ? -1 : (priority1 > priority2); } static gint -status_from_string (const gchar *str) -{ - gint status = -2; - - if (!str || !str[0]) - status = -1; - else if (!g_utf8_collate (str, _("Not Started"))) - status = 0; - else if (!g_utf8_collate (str, _("In Progress"))) - status = 1; - else if (!g_utf8_collate (str, _("Completed"))) - status = 2; - else if (!g_utf8_collate (str, _("Canceled"))) - status = 3; - - return status; +calendar_table_status_compare_cb (gconstpointer a, + gconstpointer b) +{ + const gchar *string_a = a; + const gchar *string_b = b; + gint status_a = -2; + gint status_b = -2; + + if (string_a == NULL || *string_a == '\0') + status_a = -1; + else if (!g_utf8_collate (string_a, _("Not Started"))) + status_a = 0; + else if (!g_utf8_collate (string_a, _("In Progress"))) + status_a = 1; + else if (!g_utf8_collate (string_a, _("Completed"))) + status_a = 2; + else if (!g_utf8_collate (string_a, _("Canceled"))) + status_a = 3; + + if (string_b == NULL || *string_b == '\0') + status_b = -1; + else if (!g_utf8_collate (string_b, _("Not Started"))) + status_b = 0; + else if (!g_utf8_collate (string_b, _("In Progress"))) + status_b = 1; + else if (!g_utf8_collate (string_b, _("Completed"))) + status_b = 2; + else if (!g_utf8_collate (string_b, _("Canceled"))) + status_b = 3; + + return (status_a < status_b) ? -1 : (status_a > status_b); } -static gint -status_compare_cb (gconstpointer a, gconstpointer b) +static void +calendar_table_double_click_cb (ECalendarTable *cal_table, + gint row, + gint col, + GdkEvent *event) { - gint sa = status_from_string ((const gchar *)a); - gint sb = status_from_string ((const gchar *)b); - - if (sa < sb) - return -1; - else if (sa > sb) - return 1; + ECalModel *model; + ECalModelComponent *comp_data; - return 0; + model = e_calendar_table_get_model (cal_table); + comp_data = e_cal_model_get_component_at (model, row); + calendar_table_emit_open_component (cal_table, comp_data); } static void -row_appended_cb (ECalModel *model, ECalendarTable *cal_table) +calendar_table_model_cal_view_progress_cb (ECalendarTable *cal_table, + const gchar *message, + gint progress, + ECalSourceType type) { - g_signal_emit (cal_table, signals[USER_CREATED], 0); + gdouble percent = (gdouble) progress; + + calendar_table_emit_status_message (cal_table, message, percent); } static void -get_time_as_text (struct icaltimetype *tt, icaltimezone *f_zone, icaltimezone *t_zone, gchar *buff, gint buff_len) +calendar_table_model_cal_view_done_cb (ECalendarTable *cal_table, + ECalendarStatus status, + ECalSourceType type) { - struct tm tmp_tm; - - buff [0] = 0; - - tmp_tm = icaltimetype_to_tm_with_zone (tt, f_zone, t_zone); - e_time_format_date_and_time (&tmp_tm, - calendar_config_get_24_hour_format (), - FALSE, FALSE, - buff, buff_len); + calendar_table_emit_status_message (cal_table, NULL, -1.0); } -gboolean -ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, GtkWidget *etable_wgt, ECalModel *model) +static gboolean +calendar_table_query_tooltip_cb (ECalendarTable *cal_table, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip) { - ECalModelComponent *comp; + ECalModel *model; + ECalModelComponent *comp_data; gint row = -1, col = -1; GtkWidget *box, *l, *w; GtkStyle *style = gtk_widget_get_default_style (); @@ -289,44 +289,44 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk ECalComponent *new_comp; ECalComponentOrganizer organizer; ECalComponentDateTime dtstart, dtdue; + icalcomponent *clone; icaltimezone *zone, *default_zone; GSList *desc, *p; gint len; ETable *etable; ESelectionModel *esm; + struct tm tmp_tm; if (keyboard_mode) return FALSE; - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (tooltip != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE (etable_wgt), FALSE); - g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE); - - etable = E_TABLE (etable_wgt); - + etable = e_calendar_table_get_table (cal_table); e_table_get_mouse_over_cell (etable, &row, &col); if (row == -1 || !etable) return FALSE; - /* respect sorting option, the 'e_table_get_mouse_over_cell' returns sorted row, not the model one */ + /* Respect sorting option; the 'e_table_get_mouse_over_cell' + * returns sorted row, not the model one. */ esm = e_table_get_selection_model (etable); if (esm && esm->sorter && e_sorter_needs_sorting (esm->sorter)) row = e_sorter_sorted_to_model (esm->sorter, row); - comp = e_cal_model_get_component_at (model, row); - if (!comp || !comp->icalcomp) + model = e_calendar_table_get_model (cal_table); + comp_data = e_cal_model_get_component_at (model, row); + if (!comp_data || !comp_data->icalcomp) return FALSE; new_comp = e_cal_component_new (); - if (!e_cal_component_set_icalcomponent (new_comp, icalcomponent_new_clone (comp->icalcomp))) { + clone = icalcomponent_new_clone (comp_data->icalcomp); + if (!e_cal_component_set_icalcomponent (new_comp, clone)) { g_object_unref (new_comp); return FALSE; } box = gtk_vbox_new (FALSE, 0); - str = e_calendar_view_get_icalcomponent_summary (comp->client, comp->icalcomp, &free_text); + str = e_calendar_view_get_icalcomponent_summary ( + comp_data->client, comp_data->icalcomp, &free_text); if (!(str && *str)) { if (free_text) g_free ((gchar *)str); @@ -366,7 +366,7 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk if (ptr) { ptr++; - /* To Translators: It will display "Organiser: NameOfTheUser <email@ofuser.com>" */ + /* To Translators: It will display "Organizer: NameOfTheUser <email@ofuser.com>" */ tmp = g_strdup_printf (_("Organizer: %s <%s>"), organizer.cn, ptr); } else { /* With SunOne accounts, there may be no ':' in organiser.value */ @@ -383,12 +383,13 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk e_cal_component_get_dtstart (new_comp, &dtstart); e_cal_component_get_due (new_comp, &dtdue); - default_zone = e_cal_model_get_timezone (model); + default_zone = e_cal_model_get_timezone (model); if (dtstart.tzid) { zone = icalcomponent_get_timezone (e_cal_component_get_icalcomponent (new_comp), dtstart.tzid); if (!zone) - e_cal_get_timezone (comp->client, dtstart.tzid, &zone, NULL); + e_cal_get_timezone ( + comp_data->client, dtstart.tzid, &zone, NULL); if (!zone) zone = default_zone; } else { @@ -398,7 +399,13 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk tmp2 = g_string_new (""); if (dtstart.value) { - get_time_as_text (dtstart.value, zone, default_zone, buff, 1000); + buff[0] = 0; + + tmp_tm = icaltimetype_to_tm_with_zone ( + dtstart.value, zone, default_zone); + e_time_format_date_and_time ( + &tmp_tm, calendar_config_get_24_hour_format (), + FALSE, FALSE, buff, 1000); if (buff [0]) { g_string_append (tmp2, _("Start: ")); @@ -407,7 +414,13 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk } if (dtdue.value) { - get_time_as_text (dtdue.value, zone, default_zone, buff, 1000); + buff[0] = 0; + + tmp_tm = icaltimetype_to_tm_with_zone ( + dtdue.value, zone, default_zone); + e_time_format_date_and_time ( + &tmp_tm, calendar_config_get_24_hour_format (), + FALSE, FALSE, buff, 1000); if (buff [0]) { if (tmp2->len) @@ -429,7 +442,8 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk e_cal_component_free_datetime (&dtstart); e_cal_component_free_datetime (&dtdue); - tmp = e_calendar_view_get_attendees_status_info (new_comp, comp->client); + tmp = e_calendar_view_get_attendees_status_info ( + new_comp, comp_data->client); if (tmp) { l = gtk_label_new (tmp); gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); @@ -474,22 +488,135 @@ ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk } static gboolean -query_tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data) +calendar_table_popup_menu_cb (ECalendarTable *cal_table) { - ECalendarTable *cal_table; + calendar_table_emit_popup_event (cal_table, NULL); - g_return_val_if_fail (E_IS_CALENDAR_TABLE (user_data), FALSE); + return TRUE; +} - cal_table = E_CALENDAR_TABLE (user_data); +static gint +calendar_table_right_click_cb (ECalendarTable *cal_table, + gint row, + gint col, + GdkEvent *event) +{ + calendar_table_emit_popup_event (cal_table, event); - return ec_query_tooltip (widget, x, y, keyboard_mode, tooltip, GTK_WIDGET (e_calendar_table_get_table (cal_table)), cal_table->model); + return TRUE; } static void -e_calendar_table_init (ECalendarTable *cal_table) +calendar_table_set_model (ECalendarTable *cal_table, + ECalModel *model) { - GtkWidget *table; - ETable *e_table; + g_return_if_fail (cal_table->priv->model == NULL); + + cal_table->priv->model = g_object_ref (model); + + g_signal_connect_swapped ( + model, "row_appended", + G_CALLBACK (calendar_table_emit_user_created), cal_table); + + g_signal_connect_swapped ( + model, "cal-view-progress", + G_CALLBACK (calendar_table_model_cal_view_progress_cb), + cal_table); + + g_signal_connect_swapped ( + model, "cal-view-done", + G_CALLBACK (calendar_table_model_cal_view_done_cb), + cal_table); +} + +static void +calendar_table_set_shell_view (ECalendarTable *cal_table, + EShellView *shell_view) +{ + g_return_if_fail (cal_table->priv->shell_view == NULL); + + cal_table->priv->shell_view = shell_view; + + g_object_add_weak_pointer ( + G_OBJECT (shell_view), + &cal_table->priv->shell_view); +} + +static void +calendar_table_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_MODEL: + calendar_table_set_model ( + E_CALENDAR_TABLE (object), + g_value_get_object (value)); + return; + + case PROP_SHELL_VIEW: + calendar_table_set_shell_view ( + E_CALENDAR_TABLE (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +calendar_table_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_MODEL: + g_value_set_object ( + value, e_calendar_table_get_model ( + E_CALENDAR_TABLE (object))); + return; + + case PROP_SHELL_VIEW: + g_value_set_object ( + value, e_calendar_table_get_shell_view ( + E_CALENDAR_TABLE (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +calendar_table_dispose (GObject *object) +{ + ECalendarTablePrivate *priv; + + priv = E_CALENDAR_TABLE_GET_PRIVATE (object); + + if (priv->shell_view != NULL) { + g_object_remove_weak_pointer ( + G_OBJECT (priv->shell_view), &priv->shell_view); + priv->shell_view = NULL; + } + + if (priv->model != NULL) { + g_object_unref (priv->model); + priv->model = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +calendar_table_constructed (GObject *object) +{ + ECalendarTable *cal_table; + GtkWidget *widget; + ECalModel *model; + ETable *table; ECell *cell, *popup_cell; ETableExtras *extras; gint i; @@ -498,22 +625,18 @@ e_calendar_table_init (ECalendarTable *cal_table) AtkObject *a11y; gchar *etspecfile; - /* Create the model */ - - cal_table->model = (ECalModel *) e_cal_model_tasks_new (); - g_signal_connect (cal_table->model, "row_appended", G_CALLBACK (row_appended_cb), cal_table); - - cal_table->user_created_cal = NULL; + cal_table = E_CALENDAR_TABLE (object); + model = e_calendar_table_get_model (cal_table); /* Create the header columns */ - extras = e_table_extras_new(); + extras = e_table_extras_new (); /* * Normal string fields. */ cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), + g_object_set (cell, "strikeout_column", E_CAL_MODEL_TASKS_FIELD_STRIKEOUT, "bold_column", E_CAL_MODEL_TASKS_FIELD_OVERDUE, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, @@ -526,7 +649,7 @@ e_calendar_table_init (ECalendarTable *cal_table) * Date fields. */ cell = e_cell_date_edit_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), + g_object_set (cell, "strikeout_column", E_CAL_MODEL_TASKS_FIELD_STRIKEOUT, "bold_column", E_CAL_MODEL_TASKS_FIELD_OVERDUE, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, @@ -535,13 +658,13 @@ e_calendar_table_init (ECalendarTable *cal_table) popup_cell = e_cell_date_edit_new (); e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); g_object_unref (cell); + e_table_extras_add_cell (extras, "dateedit", popup_cell); cal_table->dates_cell = E_CELL_DATE_EDIT (popup_cell); - e_cell_date_edit_set_get_time_callback (E_CELL_DATE_EDIT (popup_cell), - e_calendar_table_get_current_time, - cal_table, NULL); - + e_cell_date_edit_set_get_time_callback ( + E_CELL_DATE_EDIT (popup_cell), + e_calendar_table_get_current_time, cal_table, NULL); /* * Combo fields. @@ -549,7 +672,7 @@ e_calendar_table_init (ECalendarTable *cal_table) /* Classification field. */ cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), + g_object_set (cell, "strikeout_column", E_CAL_MODEL_TASKS_FIELD_STRIKEOUT, "bold_column", E_CAL_MODEL_TASKS_FIELD_OVERDUE, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, @@ -666,13 +789,13 @@ e_calendar_table_init (ECalendarTable *cal_table) e_table_extras_add_cell (extras, "calstatus", popup_cell); e_table_extras_add_compare (extras, "date-compare", - date_compare_cb); + calendar_table_date_compare_cb); e_table_extras_add_compare (extras, "percent-compare", - percent_compare_cb); + calendar_table_percent_compare_cb); e_table_extras_add_compare (extras, "priority-compare", - priority_compare_cb); + calendar_table_priority_compare_cb); e_table_extras_add_compare (extras, "status-compare", - status_compare_cb); + calendar_table_status_compare_cb); /* Create pixmaps */ @@ -691,55 +814,175 @@ e_calendar_table_init (ECalendarTable *cal_table) /* Create the table */ - etspecfile = g_build_filename (EVOLUTION_ETSPECDIR, - "e-calendar-table.etspec", - NULL); - table = e_table_scrolled_new_from_spec_file (E_TABLE_MODEL (cal_table->model), - extras, - etspecfile, - NULL); + etspecfile = g_build_filename ( + EVOLUTION_ETSPECDIR, "e-calendar-table.etspec", NULL); + widget = e_table_scrolled_new_from_spec_file ( + E_TABLE_MODEL (model), extras, etspecfile, NULL); + gtk_table_attach ( + GTK_TABLE (cal_table), widget, 0, 1, 0, 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + cal_table->etable = widget; + gtk_widget_show (widget); g_free (etspecfile); - /* FIXME: this causes a message from GLib about 'extras' having only a floating - reference */ - /* g_object_unref (extras); */ + table = e_table_scrolled_get_table (E_TABLE_SCROLLED (widget)); + g_signal_connect_swapped ( + table, "double-click", + G_CALLBACK (calendar_table_double_click_cb), cal_table); + g_signal_connect_swapped ( + table, "query-tooltip", + G_CALLBACK (calendar_table_query_tooltip_cb), cal_table); + g_signal_connect_swapped ( + table, "popup-menu", + G_CALLBACK (calendar_table_popup_menu_cb), cal_table); + g_signal_connect_swapped ( + table, "right-click", + G_CALLBACK (calendar_table_right_click_cb), cal_table); + gtk_widget_set_has_tooltip (GTK_WIDGET (table), TRUE); + + a11y = gtk_widget_get_accessible (GTK_WIDGET (table)); + if (a11y) + atk_object_set_name (a11y, _("Tasks")); +} - cal_table->etable = table; - gtk_table_attach (GTK_TABLE (cal_table), table, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (table); +static void +calendar_table_class_init (ECalendarTableClass *class) +{ + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ECalendarTablePrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = calendar_table_set_property; + object_class->get_property = calendar_table_get_property; + object_class->dispose = calendar_table_dispose; + object_class->constructed = calendar_table_constructed; + + g_object_class_install_property ( + object_class, + PROP_MODEL, + g_param_spec_object ( + "model", + _("Model"), + NULL, + E_TYPE_CAL_MODEL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property ( + object_class, + PROP_SHELL_VIEW, + g_param_spec_object ( + "shell-view", + _("Shell View"), + NULL, + E_TYPE_SHELL_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + signals[OPEN_COMPONENT] = g_signal_new ( + "open-component", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (ECalendarTableClass, open_component), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + E_TYPE_CAL_MODEL_COMPONENT); + + signals[POPUP_EVENT] = g_signal_new ( + "popup-event", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (ECalendarTableClass, popup_event), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + + signals[STATUS_MESSAGE] = g_signal_new ( + "status-message", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (ECalendarTableClass, status_message), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + signals[USER_CREATED] = g_signal_new ( + "user-created", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (ECalendarTableClass, user_created), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); +} +static void +calendar_table_init (ECalendarTable *cal_table) +{ + cal_table->priv = E_CALENDAR_TABLE_GET_PRIVATE (cal_table); +} - e_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (table)); - g_signal_connect (e_table, "double_click", G_CALLBACK (e_calendar_table_on_double_click), cal_table); - g_signal_connect (e_table, "right_click", G_CALLBACK (e_calendar_table_on_right_click), cal_table); - g_signal_connect (e_table, "key_press", G_CALLBACK (e_calendar_table_on_key_press), cal_table); - g_signal_connect (e_table, "popup_menu", G_CALLBACK (e_calendar_table_on_popup_menu), cal_table); - g_signal_connect (e_table, "query-tooltip", G_CALLBACK (query_tooltip_cb), cal_table); - gtk_widget_set_has_tooltip (GTK_WIDGET (e_table), TRUE); +GType +e_calendar_table_get_type (void) +{ + static GType type = 0; - a11y = gtk_widget_get_accessible ((GtkWidget *)e_table); - if (a11y) - atk_object_set_name (a11y, _("Tasks")); -} + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (ECalendarTableClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) calendar_table_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ECalendarTable), + 0, /* n_preallocs */ + (GInstanceInitFunc) calendar_table_init, + NULL /* value_table */ + }; + type = g_type_register_static ( + GTK_TYPE_TABLE, "ECalendarTable", &type_info, 0); + } + + return type; +} /** * e_calendar_table_new: - * @Returns: a new #ECalendarTable. + * @shell_view: an #EShellView + * @model: an #ECalModel for the table + * + * Returns a new #ECalendarTable. * - * Creates a new #ECalendarTable. + * Returns: a new #ECalendarTable **/ GtkWidget * -e_calendar_table_new (void) +e_calendar_table_new (EShellView *shell_view, + ECalModel *model) { - GtkWidget *cal_table; + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL); - cal_table = GTK_WIDGET (g_object_new (e_calendar_table_get_type (), NULL)); - - return cal_table; + return g_object_new ( + E_TYPE_CALENDAR_TABLE, + "model", model, "shell-view", shell_view, NULL); } +EShellView * +e_calendar_table_get_shell_view (ECalendarTable *cal_table) +{ + g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); + + return cal_table->priv->shell_view; +} /** * e_calendar_table_get_model: @@ -752,28 +995,12 @@ e_calendar_table_new (void) ECalModel * e_calendar_table_get_model (ECalendarTable *cal_table) { - g_return_val_if_fail (cal_table != NULL, NULL); g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); - return cal_table->model; + return cal_table->priv->model; } -static void -e_calendar_table_destroy (GtkObject *object) -{ - ECalendarTable *cal_table; - - cal_table = E_CALENDAR_TABLE (object); - - if (cal_table->model) { - g_object_unref (cal_table->model); - cal_table->model = NULL; - } - - GTK_OBJECT_CLASS (e_calendar_table_parent_class)->destroy (object); -} - /** * e_calendar_table_get_table: * @cal_table: A calendar table. @@ -786,37 +1013,13 @@ e_calendar_table_destroy (GtkObject *object) ETable * e_calendar_table_get_table (ECalendarTable *cal_table) { - g_return_val_if_fail (cal_table != NULL, NULL); - g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); - - return e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); -} - -void -e_calendar_table_open_selected (ECalendarTable *cal_table) -{ - ECalModelComponent *comp_data; - icalproperty *prop; + ETableScrolled *table_scrolled; - comp_data = e_calendar_table_get_selected_comp (cal_table); - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_ATTENDEE_PROPERTY); - if (comp_data != NULL) - e_calendar_table_open_task (cal_table, comp_data->client, comp_data->icalcomp, prop ? TRUE : FALSE); -} + g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); -/** - * e_calendar_table_complete_selected: - * @cal_table: A calendar table - * - * Marks the selected items as completed - **/ -void -e_calendar_table_complete_selected (ECalendarTable *cal_table) -{ - g_return_if_fail (cal_table != NULL); - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); + table_scrolled = E_TABLE_SCROLLED (cal_table->etable); - mark_as_complete_cb (NULL, NULL, cal_table); + return e_table_scrolled_get_table (table_scrolled); } /* Used from e_table_selected_row_foreach(); puts the selected row number in an @@ -831,16 +1034,19 @@ get_selected_row_cb (gint model_row, gpointer data) *row = model_row; } -/* Returns the component that is selected in the table; only works if there is +/* + * Returns the component that is selected in the table; only works if there is * one and only one selected row. */ -ECalModelComponent * -e_calendar_table_get_selected_comp (ECalendarTable *cal_table) +static ECalModelComponent * +get_selected_comp (ECalendarTable *cal_table) { + ECalModel *model; ETable *etable; gint row; - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + model = e_calendar_table_get_model (cal_table); + etable = e_calendar_table_get_table (cal_table); if (e_table_selected_count (etable) != 1) return NULL; @@ -850,7 +1056,7 @@ e_calendar_table_get_selected_comp (ECalendarTable *cal_table) &row); g_return_val_if_fail (row != -1, NULL); - return e_cal_model_get_component_at (cal_table->model, row); + return e_cal_model_get_component_at (model, row); } struct get_selected_uids_closure { @@ -862,40 +1068,27 @@ struct get_selected_uids_closure { static void add_uid_cb (gint model_row, gpointer data) { - struct get_selected_uids_closure *closure; + struct get_selected_uids_closure *closure = data; ECalModelComponent *comp_data; + ECalModel *model; - closure = data; - - comp_data = e_cal_model_get_component_at (closure->cal_table->model, model_row); + model = e_calendar_table_get_model (closure->cal_table); + comp_data = e_cal_model_get_component_at (model, model_row); closure->objects = g_slist_prepend (closure->objects, comp_data); } -static GSList * -get_selected_objects (ECalendarTable *cal_table) -{ - struct get_selected_uids_closure closure; - ETable *etable; - - closure.cal_table = cal_table; - closure.objects = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, add_uid_cb, &closure); - - return closure.objects; -} - /* Deletes all of the selected components in the table */ static void delete_selected_components (ECalendarTable *cal_table) { GSList *objs, *l; + const gchar *status_message; - objs = get_selected_objects (cal_table); + objs = e_calendar_table_get_selected (cal_table); - e_calendar_table_set_status_message (cal_table, _("Deleting selected objects"), -1); + status_message = _("Deleting selected objects"); + calendar_table_emit_status_message (cal_table, status_message, -1.0); for (l = objs; l; l = l->next) { ECalModelComponent *comp_data = (ECalModelComponent *) l->data; @@ -907,7 +1100,7 @@ delete_selected_components (ECalendarTable *cal_table) g_clear_error (&error); } - e_calendar_table_set_status_message (cal_table, NULL, -1); + calendar_table_emit_status_message (cal_table, NULL, -1.0); g_slist_free (objs); } @@ -968,14 +1161,14 @@ e_calendar_table_delete_selected (ECalendarTable *cal_table) g_return_if_fail (cal_table != NULL); g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + etable = e_calendar_table_get_table (cal_table); n_selected = e_table_selected_count (etable); if (n_selected <= 0) return; if (n_selected == 1) - comp_data = e_calendar_table_get_selected_comp (cal_table); + comp_data = get_selected_comp (cal_table); else comp_data = NULL; @@ -1039,7 +1232,16 @@ e_calendar_table_delete_selected (ECalendarTable *cal_table) GSList * e_calendar_table_get_selected (ECalendarTable *cal_table) { - return get_selected_objects(cal_table); + struct get_selected_uids_closure closure; + ETable *etable; + + closure.cal_table = cal_table; + closure.objects = NULL; + + etable = e_calendar_table_get_table (cal_table); + e_table_selected_row_foreach (etable, add_uid_cb, &closure); + + return closure.objects; } /** @@ -1083,6 +1285,7 @@ copy_row_cb (gint model_row, gpointer data) { ECalendarTable *cal_table; ECalModelComponent *comp_data; + ECalModel *model; gchar *comp_str; icalcomponent *child; @@ -1090,7 +1293,8 @@ copy_row_cb (gint model_row, gpointer data) g_return_if_fail (cal_table->tmp_vcal != NULL); - comp_data = e_cal_model_get_component_at (cal_table->model, model_row); + model = e_calendar_table_get_model (cal_table); + comp_data = e_cal_model_get_component_at (model, model_row); if (!comp_data) return; @@ -1126,14 +1330,13 @@ e_calendar_table_copy_clipboard (ECalendarTable *cal_table) /* create temporary VCALENDAR object */ cal_table->tmp_vcal = e_cal_util_new_top_level (); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + etable = e_calendar_table_get_table (cal_table); e_table_selected_row_foreach (etable, copy_row_cb, cal_table); comp_str = icalcomponent_as_ical_string_r (cal_table->tmp_vcal); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (cal_table), clipboard_atom); if (!gtk_clipboard_set_with_data(clipboard, target_types, n_target_types, clipboard_get_calendar_cb, NULL, comp_str)) { - /* no-op */ } else { gtk_clipboard_set_can_store (clipboard, target_types + 1, n_target_types - 1); @@ -1151,8 +1354,10 @@ clipboard_get_calendar_data (ECalendarTable *cal_table, const gchar *text) icalcomponent *icalcomp; gchar *uid; ECalComponent *comp; + ECalModel *model; ECal *client; icalcomponent_kind kind; + const gchar *status_message; g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); @@ -1172,9 +1377,11 @@ clipboard_get_calendar_data (ECalendarTable *cal_table, const gchar *text) return; } - client = e_cal_model_get_default_client (cal_table->model); + model = e_calendar_table_get_model (cal_table); + client = e_cal_model_get_default_client (model); - e_calendar_table_set_status_message (cal_table, _("Updating objects"), -1); + status_message = _("Updating objects"); + calendar_table_emit_status_message (cal_table, status_message, -1.0); if (kind == ICAL_VCALENDAR_COMPONENT) { icalcomponent_kind child_kind; @@ -1219,7 +1426,7 @@ clipboard_get_calendar_data (ECalendarTable *cal_table, const gchar *text) g_object_unref (comp); } - e_calendar_table_set_status_message (cal_table, NULL, -1); + calendar_table_emit_status_message (cal_table, NULL, -1.0); } static void @@ -1228,7 +1435,7 @@ clipboard_paste_received_cb (GtkClipboard *clipboard, gpointer data) { ECalendarTable *cal_table = E_CALENDAR_TABLE (data); - ETable *e_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + ETable *e_table = e_calendar_table_get_table (cal_table); GnomeCanvas *canvas = e_table->table_canvas; GnomeCanvasItem *item = GNOME_CANVAS (canvas)->focused_item; @@ -1263,446 +1470,15 @@ void e_calendar_table_paste_clipboard (ECalendarTable *cal_table) { GtkClipboard *clipboard; - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (cal_table), clipboard_atom); - g_object_ref (cal_table); - - gtk_clipboard_request_contents (clipboard, - gdk_atom_intern (target_types[0].target, FALSE), - clipboard_paste_received_cb, cal_table); -} - -/* Opens a task in the task editor */ -void -e_calendar_table_open_task (ECalendarTable *cal_table, ECal *client, icalcomponent *icalcomp, gboolean assign) -{ - CompEditor *tedit; - const gchar *uid; - guint32 flags = 0; - - uid = icalcomponent_get_uid (icalcomp); - - tedit = e_comp_editor_registry_find (comp_editor_registry, uid); - if (tedit == NULL) { - ECalComponent *comp; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (icalcomp)); - - if (assign) { - flags |= COMP_EDITOR_IS_ASSIGNED; - - if (itip_organizer_is_user (comp, client) || - !e_cal_component_has_attendees (comp)) - flags |= COMP_EDITOR_USER_ORG; - } - - tedit = task_editor_new (client, flags); - comp_editor_edit_comp (tedit, comp); - g_object_unref (comp); - - if (flags & COMP_EDITOR_IS_ASSIGNED) - task_editor_show_assignment (TASK_EDITOR (tedit)); - - e_comp_editor_registry_add (comp_editor_registry, tedit, FALSE); - } - gtk_window_present (GTK_WINDOW (tedit)); -} - -/* Opens the task in the specified row */ -static void -open_task_by_row (ECalendarTable *cal_table, gint row) -{ - ECalModelComponent *comp_data; - icalproperty *prop; - - comp_data = e_cal_model_get_component_at (cal_table->model, row); - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_ATTENDEE_PROPERTY); - e_calendar_table_open_task (cal_table, comp_data->client, comp_data->icalcomp, prop ? TRUE : FALSE); -} - -static void -e_calendar_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table) -{ - open_task_by_row (cal_table, row); -} - -/* popup menu callbacks */ - -static void -e_calendar_table_on_open_task (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - icalproperty *prop; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - - if (!comp_data) - return; - - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_ATTENDEE_PROPERTY); - e_calendar_table_open_task (cal_table, comp_data->client, comp_data->icalcomp, prop ? TRUE : FALSE); -} - -static void -e_calendar_table_on_save_as (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - gchar *filename; - gchar *ical_string; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data == NULL) - return; - - filename = e_file_dialog_save (_("Save as..."), NULL); - if (filename == NULL) - return; - - ical_string = e_cal_get_component_as_string (comp_data->client, comp_data->icalcomp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - e_write_file_uri (filename, ical_string); - - g_free (ical_string); -} - -static void -e_calendar_table_on_print_task (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - ECalComponent *comp; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data == NULL) - return; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - print_comp (comp, comp_data->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); - - g_object_unref (comp); -} - -static void -e_calendar_table_on_cut (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - - e_calendar_table_cut_clipboard (cal_table); -} - -static void -e_calendar_table_on_copy (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - - e_calendar_table_copy_clipboard (cal_table); -} - -static void -e_calendar_table_on_paste (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - - e_calendar_table_paste_clipboard (cal_table); -} - -static void -e_calendar_table_on_assign (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data) - e_calendar_table_open_task (cal_table, comp_data->client, comp_data->icalcomp, TRUE); -} - -static void -e_calendar_table_on_forward (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data) { - ECalComponent *comp; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - itip_send_comp (E_CAL_COMPONENT_METHOD_PUBLISH, comp, comp_data->client, NULL, NULL, NULL, TRUE); - - g_object_unref (comp); - } -} - -struct AffectedComponents { - ECalendarTable *cal_table; - GSList *components; /* contains pointers to ECalModelComponent */ -}; - -/** - * get_selected_components_cb - * Helper function to fill list of selected components in ECalendarTable. - * This function is called from e_table_selected_row_foreach. - **/ -static void -get_selected_components_cb (gint model_row, gpointer data) -{ - struct AffectedComponents *ac = (struct AffectedComponents *) data; - - if (!ac || !ac->cal_table) - return; - - ac->components = g_slist_prepend (ac->components, e_cal_model_get_component_at (E_CAL_MODEL (ac->cal_table->model), model_row)); -} - -/** - * do_for_selected_components - * Calls function func for all selected components in cal_table. - * - * @param cal_table Table with selected components of our interest - * @param func Function to be called on each selected component from cal_table. - * The first parameter of this function is a pointer to ECalModelComponent and - * the second parameter of this function is pointer to cal_table - **/ -static void -do_for_selected_components (ECalendarTable *cal_table, GFunc func) -{ - ETable *etable; - struct AffectedComponents ac; - - g_return_if_fail (cal_table != NULL); - - ac.cal_table = cal_table; - ac.components = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, get_selected_components_cb, &ac); - - g_slist_foreach (ac.components, func, cal_table); - g_slist_free (ac.components); -} - -/** - * mark_comp_complete_cb - * Function used in call to @ref do_for_selected_components to mark each component as complete - **/ -static void -mark_comp_complete_cb (gpointer data, gpointer user_data) -{ - ECalendarTable *cal_table; - ECalModelComponent *comp_data; - - comp_data = (ECalModelComponent *) data; - cal_table = E_CALENDAR_TABLE (user_data); - - e_cal_model_tasks_mark_comp_complete (E_CAL_MODEL_TASKS (cal_table->model), comp_data); -} - -/** - * mark_comp_incomplete_cb - * Function used in call to @ref do_for_selected_components to mark each component as incomplete - **/ -static void -mark_comp_incomplete_cb (gpointer data, gpointer user_data) -{ - ECalendarTable *cal_table; - ECalModelComponent *comp_data; - comp_data = (ECalModelComponent *) data; - cal_table = E_CALENDAR_TABLE (user_data); - - e_cal_model_tasks_mark_comp_incomplete (E_CAL_MODEL_TASKS (cal_table->model), comp_data); -} - -/* Callback used for the "mark tasks as incomplete" menu item */ -static void -mark_as_incomplete_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - do_for_selected_components (data, mark_comp_incomplete_cb); -} - -/* Callback used for the "mark tasks as complete" menu item */ -static void -mark_as_complete_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - do_for_selected_components (data, mark_comp_complete_cb); -} - -/* Opens the URL of the task */ -static void -open_url_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ECalModelComponent *comp_data; - icalproperty *prop; - - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (!comp_data) - return; - - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_URL_PROPERTY); - if (!prop) - return; - - /* FIXME Pass a parent window. */ - e_show_uri (NULL, icalproperty_get_url (prop)); -} - -/* Opens a new task editor */ -static void -on_new_task (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - ETasks *tasks = g_object_get_data (G_OBJECT (cal_table), "tasks"); - - if (!tasks) - return; - - e_tasks_new_task (tasks); - -} - -/* Callback for the "delete tasks" menu item */ -static void -delete_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - ECalendarTable *cal_table = data; - - e_calendar_table_delete_selected (cal_table); -} - -static EPopupItem tasks_popup_items [] = { - { E_POPUP_ITEM, (gchar *) "00.newtask", (gchar *) N_("New _Task"), on_new_task, NULL, (gchar *) "stock_task", 0, 0}, - { E_POPUP_BAR, (gchar *) "01.bar" }, - - { E_POPUP_ITEM, (gchar *) "03.open", (gchar *) N_("_Open"), e_calendar_table_on_open_task, NULL, (gchar *) GTK_STOCK_OPEN, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, (gchar *) "05.openweb", (gchar *) N_("Open _Web Page"), open_url_cb, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_HASURL }, - { E_POPUP_ITEM, (gchar *) "10.saveas", (gchar *) N_("_Save As..."), e_calendar_table_on_save_as, NULL, (gchar *) GTK_STOCK_SAVE_AS, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, (gchar *) "20.print", (gchar *) N_("P_rint..."), e_calendar_table_on_print_task, NULL, (gchar *) GTK_STOCK_PRINT, E_CAL_POPUP_SELECT_ONE }, - - { E_POPUP_BAR, (gchar *) "30.bar" }, - - { E_POPUP_ITEM, (gchar *) "40.cut", (gchar *) N_("C_ut"), e_calendar_table_on_cut, NULL, (gchar *) GTK_STOCK_CUT, 0, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, (gchar *) "50.copy", (gchar *) N_("_Copy"), e_calendar_table_on_copy, NULL, (gchar *) GTK_STOCK_COPY, 0, 0 }, - { E_POPUP_ITEM, (gchar *) "60.paste", (gchar *) N_("_Paste"), e_calendar_table_on_paste, NULL, (gchar *) GTK_STOCK_PASTE, 0, E_CAL_POPUP_SELECT_EDITABLE }, - - { E_POPUP_BAR, (gchar *) "70.bar" }, - - { E_POPUP_ITEM, (gchar *) "80.assign", (gchar *) N_("_Assign Task"), e_calendar_table_on_assign, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE|E_CAL_POPUP_SELECT_ASSIGNABLE }, - { E_POPUP_ITEM, (gchar *) "90.forward", (gchar *) N_("_Forward as iCalendar"), e_calendar_table_on_forward, NULL, (gchar *) "mail-forward", E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, (gchar *) "a0.markonecomplete", (gchar *) N_("_Mark as Complete"), mark_as_complete_cb, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE | E_CAL_POPUP_SELECT_NOTCOMPLETE}, - { E_POPUP_ITEM, (gchar *) "b0.markmanycomplete", (gchar *) N_("_Mark Selected Tasks as Complete"), mark_as_complete_cb, NULL, NULL, E_CAL_POPUP_SELECT_MANY, E_CAL_POPUP_SELECT_EDITABLE | E_CAL_POPUP_SELECT_NOTCOMPLETE }, - { E_POPUP_ITEM, (gchar *) "c0.markoneincomplete", (gchar *) N_("_Mark as Incomplete"), mark_as_incomplete_cb, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE|E_CAL_POPUP_SELECT_COMPLETE}, - { E_POPUP_ITEM, (gchar *) "d0.markmanyincomplete", (gchar *) N_("_Mark Selected Tasks as Incomplete"), mark_as_incomplete_cb, NULL, NULL, E_CAL_POPUP_SELECT_MANY, E_CAL_POPUP_SELECT_EDITABLE | E_CAL_POPUP_SELECT_COMPLETE }, - - { E_POPUP_BAR, (gchar *) "e0.bar" }, - - { E_POPUP_ITEM, (gchar *) "f0.delete", (gchar *) N_("_Delete"), delete_cb, NULL, (gchar *) GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, (gchar *) "g0.deletemany", (gchar *) N_("_Delete Selected Tasks"), delete_cb, NULL, (gchar *) GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_MANY, E_CAL_POPUP_SELECT_EDITABLE }, -}; - -static void -ect_popup_free(EPopup *ep, GSList *items, gpointer data) -{ - g_slist_free(items); -} - -static gint -e_calendar_table_show_popup_menu (ETable *table, - GdkEvent *gdk_event, - ECalendarTable *cal_table) -{ - GtkMenu *menu; - GSList *selection, *l, *menus = NULL; - GPtrArray *events; - ECalPopup *ep; - ECalPopupTargetSelect *t; - gint i; - - selection = get_selected_objects (cal_table); - if (!selection) - return TRUE; - - /** @HookPoint-ECalPopup: Tasks Table Context Menu - * @Id: org.gnome.evolution.tasks.table.popup - * @Class: org.gnome.evolution.calendar.popup:1.0 - * @Target: ECalPopupTargetSelect - * - * The context menu on the tasks table. - */ - ep = e_cal_popup_new("org.gnome.evolution.tasks.table.popup"); - - events = g_ptr_array_new(); - for (l=selection;l;l=g_slist_next(l)) - g_ptr_array_add(events, e_cal_model_copy_component_data((ECalModelComponent *)l->data)); - g_slist_free(selection); - - t = e_cal_popup_target_new_select(ep, cal_table->model, events); - t->target.widget = (GtkWidget *)cal_table; - - for (i=0;i<sizeof(tasks_popup_items)/sizeof(tasks_popup_items[0]);i++) - menus = g_slist_prepend(menus, &tasks_popup_items[i]); - e_popup_add_items((EPopup *)ep, menus, NULL, ect_popup_free, cal_table); - - menu = e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0); - - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, gdk_event?gdk_event->button.button:0, - gdk_event?gdk_event->button.time:gtk_get_current_event_time()); - - return TRUE; -} - -static gint -e_calendar_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - ECalendarTable *cal_table) -{ - return e_calendar_table_show_popup_menu (table, event, cal_table); -} + g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); -static gboolean -e_calendar_table_on_popup_menu (GtkWidget *widget, gpointer data) -{ - ETable *table = E_TABLE(widget); - g_return_val_if_fail(table, FALSE); + clipboard = gtk_widget_get_clipboard ( + GTK_WIDGET (cal_table), clipboard_atom); - return e_calendar_table_show_popup_menu (table, NULL, - E_CALENDAR_TABLE(data)); -} - -static gint -e_calendar_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - ECalendarTable *cal_table) -{ - if (event->keyval == GDK_Delete) { - delete_cb (NULL, NULL, cal_table); - return TRUE; - } else if ((event->keyval == GDK_o) - &&(event->state & GDK_CONTROL_MASK)) { - open_task_by_row (cal_table, row); - return TRUE; - } - - return FALSE; + gtk_clipboard_request_contents ( + clipboard, gdk_atom_intern (target_types[0].target, FALSE), + clipboard_paste_received_cb, g_object_ref (cal_table)); } static void @@ -1793,29 +1569,31 @@ show_completed_rows (ECalModel *model, GList *clients_list, gchar *show_sexp, GP /* Loads the state of the table (headers shown etc.) from the given file. */ void -e_calendar_table_load_state (ECalendarTable *cal_table, - gchar *filename) +e_calendar_table_load_state (ECalendarTable *cal_table, + const gchar *filename) { - struct stat st; + ETable *table; g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); + g_return_if_fail (filename != NULL); - if (g_stat (filename, &st) == 0 && st.st_size > 0 - && S_ISREG (st.st_mode)) { - e_table_load_state (e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)), filename); - } + table = e_calendar_table_get_table (cal_table); + e_table_load_state (table, filename); } /* Saves the state of the table (headers shown etc.) to the given file. */ void -e_calendar_table_save_state (ECalendarTable *cal_table, - gchar *filename) +e_calendar_table_save_state (ECalendarTable *cal_table, + const gchar *filename) { + ETable *table; + g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); + g_return_if_fail (filename != NULL); - e_table_save_state (e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)), - filename); + table = e_calendar_table_get_table (cal_table); + e_table_save_state (table, filename); } /* Returns the current time, for the ECellDateEdit items. @@ -1845,57 +1623,6 @@ e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data) return tmp_tm; } - -#ifdef TRANSLATORS_ONLY - -static gchar *test[] = { - N_("Click to add a task") -}; - -#endif - -void -e_calendar_table_set_activity_handler (ECalendarTable *cal_table, EActivityHandler *activity_handler) -{ - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - cal_table->activity_handler = activity_handler; -} - -void -e_calendar_table_set_status_message (ECalendarTable *cal_table, const gchar *message, gint percent) -{ - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - if (!cal_table->activity_handler) - return; - - if (!message || !*message) { - if (cal_table->activity_id != 0) { - e_activity_handler_operation_finished (cal_table->activity_handler, cal_table->activity_id); - cal_table->activity_id = 0; - } - } else if (cal_table->activity_id == 0) { - gchar *client_id = g_strdup_printf ("%p", (gpointer) cal_table); - - cal_table->activity_id = e_activity_handler_operation_started ( - cal_table->activity_handler, client_id, message, TRUE); - - g_free (client_id); - } else { - - double progress; - - if (percent < 0) - progress = -1.0; - else { - progress = ((double) percent / 100); - } - - e_activity_handler_operation_progressing (cal_table->activity_handler, cal_table->activity_id, message, progress); - } -} - /** * e_calendar_table_hide_completed_tasks: * @table: A calendar table model. diff --git a/calendar/gui/e-calendar-table.h b/calendar/gui/e-calendar-table.h index e91886b5d4..4645be188b 100644 --- a/calendar/gui/e-calendar-table.h +++ b/calendar/gui/e-calendar-table.h @@ -23,34 +23,43 @@ #ifndef _E_CALENDAR_TABLE_H_ #define _E_CALENDAR_TABLE_H_ -#include <gtk/gtk.h> +#include <shell/e-shell-view.h> #include <table/e-table-scrolled.h> -#include <misc/e-cell-date-edit.h> -#include "e-activity-handler.h" +#include <table/e-cell-date-edit.h> #include "e-cal-model.h" -G_BEGIN_DECLS - /* * ECalendarTable - displays the iCalendar objects in a table (an ETable). * Used for calendar events and tasks. */ +/* Standard GObject macros */ +#define E_TYPE_CALENDAR_TABLE \ + (e_calendar_table_get_type ()) +#define E_CALENDAR_TABLE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_CALENDAR_TABLE, ECalendarTable)) +#define E_CALENDAR_TABLE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_CALENDAR_TABLE, ECalendarTableClass)) +#define E_IS_CALENDAR_TABLE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_CALENDAR_TABLE)) +#define E_IS_CALENDAR_TABLE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_CALENDAR_TABLE)) +#define E_CALENDAR_TABLE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_CALENDAR_TABLE, ECalendarTableClass)) -#define E_CALENDAR_TABLE(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, e_calendar_table_get_type (), ECalendarTable) -#define E_CALENDAR_TABLE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, e_calendar_table_get_type (), ECalendarTableClass) -#define E_IS_CALENDAR_TABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, e_calendar_table_get_type ()) - - -typedef struct _ECalendarTable ECalendarTable; -typedef struct _ECalendarTableClass ECalendarTableClass; +G_BEGIN_DECLS +typedef struct _ECalendarTable ECalendarTable; +typedef struct _ECalendarTableClass ECalendarTableClass; +typedef struct _ECalendarTablePrivate ECalendarTablePrivate; struct _ECalendarTable { - GtkTable table; - - /* The model that we use */ - ECalModel *model; + GtkTable parent; GtkWidget *etable; @@ -60,61 +69,55 @@ struct _ECalendarTable { /* Fields used for cut/copy/paste */ icalcomponent *tmp_vcal; - /* Activity ID for the EActivityHandler (i.e. the status bar). */ - EActivityHandler *activity_handler; - guint activity_id; - - /* We should know which calendar has been used to create object, so store it here - before emitting "user_created" signal and make it NULL just after the emit. */ - ECal *user_created_cal; + ECalendarTablePrivate *priv; }; struct _ECalendarTableClass { GtkTableClass parent_class; - /* Notification signals */ - void (* user_created) (ECalendarTable *cal_table); + /* Signals */ + void (*open_component) (ECalendarTable *cal_table, + ECalModelComponent *comp_data); + void (*popup_event) (ECalendarTable *cal_table, + GdkEvent *event); + void (*status_message) (ECalendarTable *cal_table, + const gchar *message, + gdouble percent); + void (*user_created) (ECalendarTable *cal_table); }; - -GType e_calendar_table_get_type (void); -GtkWidget* e_calendar_table_new (void); - -ECalModel *e_calendar_table_get_model (ECalendarTable *cal_table); - -ETable *e_calendar_table_get_table (ECalendarTable *cal_table); - -void e_calendar_table_open_selected (ECalendarTable *cal_table); -void e_calendar_table_complete_selected (ECalendarTable *cal_table); -void e_calendar_table_delete_selected (ECalendarTable *cal_table); - -GSList *e_calendar_table_get_selected (ECalendarTable *cal_table); +GType e_calendar_table_get_type (void); +GtkWidget * e_calendar_table_new (EShellView *shell_view, + ECalModel *model); +ECalModel * e_calendar_table_get_model (ECalendarTable *cal_table); +ETable * e_calendar_table_get_table (ECalendarTable *cal_table); +EShellView * e_calendar_table_get_shell_view (ECalendarTable *cal_table); +void e_calendar_table_delete_selected(ECalendarTable *cal_table); +GSList * e_calendar_table_get_selected (ECalendarTable *cal_table); /* Clipboard related functions */ -void e_calendar_table_cut_clipboard (ECalendarTable *cal_table); -void e_calendar_table_copy_clipboard (ECalendarTable *cal_table); -void e_calendar_table_paste_clipboard (ECalendarTable *cal_table); +void e_calendar_table_cut_clipboard (ECalendarTable *cal_table); +void e_calendar_table_copy_clipboard (ECalendarTable *cal_table); +void e_calendar_table_paste_clipboard(ECalendarTable *cal_table); /* These load and save the state of the table (headers shown etc.) to/from the given file. */ -void e_calendar_table_load_state (ECalendarTable *cal_table, - gchar *filename); -void e_calendar_table_save_state (ECalendarTable *cal_table, - gchar *filename); - -void e_calendar_table_set_activity_handler (ECalendarTable *cal_table, - EActivityHandler *activity_handler); -void e_calendar_table_set_status_message (ECalendarTable *cal_table, - const gchar *message, - gint percent); -void e_calendar_table_open_task (ECalendarTable *cal_table, - ECal *client, - icalcomponent *icalcomp, - gboolean assign); -ECalModelComponent * e_calendar_table_get_selected_comp (ECalendarTable *cal_table); -void e_calendar_table_hide_completed_tasks (ECalendarTable *table, GList *clients_list, gboolean config_changed); - -void e_calendar_table_process_completed_tasks (ECalendarTable *table, GList *clients_list, gboolean config_changed); +void e_calendar_table_load_state (ECalendarTable *cal_table, + const gchar *filename); +void e_calendar_table_save_state (ECalendarTable *cal_table, + const gchar *filename); + +ECalModelComponent * + e_calendar_table_get_selected_comp + (ECalendarTable *cal_table); +void e_calendar_table_hide_completed_tasks + (ECalendarTable *table, + GList *clients_list, + gboolean config_changed); +void e_calendar_table_process_completed_tasks + (ECalendarTable *table, + GList *clients_list, + gboolean config_changed); gboolean ec_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, GtkWidget *etable_wgt, ECalModel *model); diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c index 2bca3e7ed9..03d6e6991f 100644 --- a/calendar/gui/e-calendar-view.c +++ b/calendar/gui/e-calendar-view.c @@ -37,15 +37,13 @@ #include <e-util/e-icon-factory.h> #include <libecal/e-cal-time-util.h> #include <libecal/e-cal-component.h> +#include <shell/e-shell.h> #include "common/authentication.h" -#include "calendar-commands.h" -#include "calendar-component.h" #include "calendar-config.h" #include "comp-util.h" #include "e-cal-model-calendar.h" #include "e-calendar-view.h" -#include "e-comp-editor-registry.h" #include "itip-utils.h" #include "dialogs/delete-comp.h" #include "dialogs/delete-error.h" @@ -56,7 +54,7 @@ #include "dialogs/select-source-dialog.h" #include "print.h" #include "goto.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ #include "e-cal-popup.h" #include "misc.h" @@ -67,10 +65,6 @@ struct _ECalendarViewPrivate { /* The calendar model we are monitoring */ ECalModel *model; - /* Current activity (for the EActivityHandler, i.e. the status bar). */ - EActivityHandler *activity_handler; - guint activity_id; - /* The default category */ gchar *default_category; }; @@ -79,7 +73,6 @@ static void e_calendar_view_get_property (GObject *object, guint property_id, GV static void e_calendar_view_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); static void e_calendar_view_destroy (GtkObject *object); -extern ECompEditorRegistry *comp_editor_registry; /* Property IDs */ enum props { @@ -254,8 +247,10 @@ e_calendar_view_class_init (ECalendarViewClass *klass) GDK_CONTROL_MASK, "open_event", 0); +#if 0 /* KILL-BONOBO */ /* init the accessibility support for e_day_view */ e_cal_view_a11y_init (); +#endif } @@ -263,6 +258,7 @@ void e_calendar_view_add_event (ECalendarView *cal_view, ECal *client, time_t dtstart, icaltimezone *default_zone, icalcomponent *icalcomp, gboolean in_top_canvas) { +#if 0 /* KILL-BONOBO */ ECalComponent *comp; struct icaltimetype itime, old_dtstart, old_dtend; time_t tt_start, tt_end, new_dtstart = 0; @@ -380,6 +376,7 @@ e_calendar_view_add_event (ECalendarView *cal_view, ECal *client, time_t dtstart } g_object_unref (comp); +#endif } static void @@ -536,55 +533,6 @@ e_calendar_view_set_use_24_hour_format (ECalendarView *cal_view, gboolean use_24 e_cal_model_set_use_24_hour_format (cal_view->priv->model, use_24_hour); } -void -e_calendar_view_set_activity_handler (ECalendarView *cal_view, EActivityHandler *activity_handler) -{ - ECalendarViewPrivate *priv; - - g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view)); - - priv = cal_view->priv; - - priv->activity_handler = activity_handler; -} - -void -e_calendar_view_set_status_message (ECalendarView *cal_view, const gchar *message, gint percent) -{ - ECalendarViewPrivate *priv; - - g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view)); - - priv = cal_view->priv; - - if (!priv->activity_handler) - return; - - if (!message || !*message) { - if (priv->activity_id != 0) { - e_activity_handler_operation_finished (priv->activity_handler, priv->activity_id); - priv->activity_id = 0; - } - } else if (priv->activity_id == 0) { - gchar *client_id = g_strdup_printf ("%p", (gpointer) cal_view); - - priv->activity_id = e_activity_handler_operation_started ( - priv->activity_handler, client_id, message, TRUE); - - g_free (client_id); - } else { - double progress; - - if (percent < 0) - progress = -1.0; - else { - progress = ((double) percent / 100); - } - - e_activity_handler_operation_progressing (priv->activity_handler, priv->activity_id, message, progress); - } -} - GList * e_calendar_view_get_selected_events (ECalendarView *cal_view) { @@ -655,7 +603,9 @@ e_calendar_view_cut_clipboard (ECalendarView *cal_view) if (!selected) return; +#if 0 /* KILL-BONOBO */ e_calendar_view_set_status_message (cal_view, _("Deleting selected objects"), -1); +#endif e_calendar_view_copy_clipboard (cal_view); for (l = selected; l != NULL; l = l->next) { @@ -700,7 +650,9 @@ e_calendar_view_cut_clipboard (ECalendarView *cal_view) g_object_unref (comp); } +#if 0 /* KILL-BONOBO */ e_calendar_view_set_status_message (cal_view, NULL, -1); +#endif g_list_free (selected); } @@ -869,7 +821,9 @@ clipboard_get_calendar_data (ECalendarView *cal_view, const gchar *text) if (kind != ICAL_VCALENDAR_COMPONENT && kind != ICAL_VEVENT_COMPONENT) return; +#if 0 /* KILL-BONOBO */ e_calendar_view_set_status_message (cal_view, _("Updating objects"), -1); +#endif e_calendar_view_get_selected_time_range (cal_view, &selected_time_start, &selected_time_end); if ((selected_time_end - selected_time_start) == 60 * 60 * 24) @@ -917,7 +871,9 @@ clipboard_get_calendar_data (ECalendarView *cal_view, const gchar *text) e_calendar_view_add_event (cal_view, client, selected_time_start, default_zone, icalcomp, in_top_canvas); } +#if 0 /* KILL-BONOBO */ e_calendar_view_set_status_message (cal_view, NULL, -1); +#endif } static void @@ -1268,11 +1224,13 @@ on_new_meeting (EPopup *ep, EPopupItem *pitem, gpointer data) static void on_new_task (EPopup *ep, EPopupItem *pitem, gpointer data) { +#if 0 /* KILL-BONOBO */ ECalendarView *cal_view = data; time_t dtstart, dtend; e_calendar_view_get_selected_time_range (cal_view, &dtstart, &dtend); gnome_calendar_new_task (cal_view->priv->calendar, &dtstart, &dtend); +#endif } static void @@ -1286,9 +1244,11 @@ on_goto_date (EPopup *ep, EPopupItem *pitem, gpointer data) static void on_goto_today (EPopup *ep, EPopupItem *pitem, gpointer data) { +#if 0 /* KILL-BONOBO */ ECalendarView *cal_view = data; - calendar_goto_today (cal_view->priv->calendar); + gnome_calendar_goto_today (cal_view->priv->calendar); +#endif } static void @@ -1313,9 +1273,11 @@ on_edit_appointment (EPopup *ep, EPopupItem *pitem, gpointer data) static void on_print (EPopup *ep, EPopupItem *pitem, gpointer data) { +#if 0 /* KILL-BONOBO */ ECalendarView *cal_view = data; calendar_command_print (cal_view->priv->calendar, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); +#endif } static void @@ -1475,16 +1437,20 @@ transfer_selected_items (ECalendarView *cal_view, gboolean remove_item) return; } +#if 0 /* KILL-BONOBO */ /* process all selected events */ if (remove_item) e_calendar_view_set_status_message (cal_view, _("Moving items"), -1); else e_calendar_view_set_status_message (cal_view, _("Copying items"), -1); +#endif for (l = selected; l != NULL; l = l->next) transfer_item_to ((ECalendarViewEvent *) l->data, dest_client, remove_item); +#if 0 /* KILL-BONOBO */ e_calendar_view_set_status_message (cal_view, NULL, -1); +#endif /* free memory */ g_object_unref (destination_source); @@ -1836,69 +1802,6 @@ static EPopupItem ecv_child_items [] = { { E_POPUP_ITEM, (gchar *) "54.delete", (gchar *) N_("Delete _All Occurrences"), on_delete_appointment, NULL, (gchar *) GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_RECURRING, E_CAL_POPUP_SELECT_NOTEDITING | E_CAL_POPUP_SELECT_EDITABLE }, }; -static void -ecv_popup_free (EPopup *ep, GSList *list, gpointer data) -{ - g_slist_free(list); -} - -GtkMenu * -e_calendar_view_create_popup_menu (ECalendarView *cal_view) -{ - ECalPopup *ep; - GSList *menus = NULL; - GList *selected, *l; - gint i; - ECalPopupTargetSelect *t; - ECalModel *model; - GPtrArray *events; - - g_return_val_if_fail (E_IS_CALENDAR_VIEW (cal_view), NULL); - - /* We could do this using a factory on the ECalPopup class, - * that way we would get called implicitly whenever a popup - * menu was created rather than everyone having to call us. - * We could also have a different menu id for each view */ - - /** @HookPoint-ECalPopup: Calendar Main View Context Menu - * @Id: org.gnome.evolution.calendar.view.popup - * @Class: org.gnome.evolution.calendar.popup:1.0 - * @Target: ECalPopupTargetSelect - * - * The context menu on the main calendar view. This menu - * applies to all view types. - */ - ep = e_cal_popup_new("org.gnome.evolution.calendar.view.popup"); - - model = e_calendar_view_get_model(cal_view); - events = g_ptr_array_new(); - selected = e_calendar_view_get_selected_events(cal_view); - for (l=selected;l;l=g_list_next(l)) { - ECalendarViewEvent *event = l->data; - - if (event) - g_ptr_array_add(events, e_cal_model_copy_component_data(event->comp_data)); - } - g_list_free(selected); - - t = e_cal_popup_target_new_select(ep, model, events); - t->target.widget = (GtkWidget *)cal_view; - - if (t->events->len == 0) { - for (i=0;i<sizeof(ecv_main_items)/sizeof(ecv_main_items[0]);i++) - menus = g_slist_prepend(menus, &ecv_main_items[i]); - - gnome_calendar_view_popup_factory(cal_view->priv->calendar, (EPopup *)ep, "60.view"); - } else { - for (i=0;i<sizeof(ecv_child_items)/sizeof(ecv_child_items[0]);i++) - menus = g_slist_prepend(menus, &ecv_child_items[i]); - } - - e_popup_add_items((EPopup *)ep, menus, NULL, ecv_popup_free, cal_view); - - return e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0); -} - void e_calendar_view_open_event (ECalendarView *cal_view) { @@ -2097,7 +2000,9 @@ e_calendar_view_new_appointment (ECalendarView *cal_view) static void object_created_cb (CompEditor *ce, ECalendarView *cal_view) { +#if 0 /* KILL-BONOBO */ gnome_calendar_emit_user_created_signal (cal_view, e_calendar_view_get_calendar (cal_view), comp_editor_get_client (ce)); +#endif } CompEditor * @@ -2106,13 +2011,16 @@ e_calendar_view_open_event_with_flags (ECalendarView *cal_view, ECal *client, ic CompEditor *ce; const gchar *uid; ECalComponent *comp; + EShell *shell; + /* FIXME ECalendarView should own an EShell pointer. */ + shell = e_shell_get_default (); uid = icalcomponent_get_uid (icalcomp); - ce = e_comp_editor_registry_find (comp_editor_registry, uid); + ce = comp_editor_find_instance (uid); if (!ce) { - ce = event_editor_new (client, flags); + ce = event_editor_new (client, shell, flags); g_signal_connect (ce, "object_created", G_CALLBACK (object_created_cb), cal_view); @@ -2122,8 +2030,6 @@ e_calendar_view_open_event_with_flags (ECalendarView *cal_view, ECal *client, ic if (flags & COMP_EDITOR_MEETING) event_editor_show_meeting (EVENT_EDITOR (ce)); - e_comp_editor_registry_add (comp_editor_registry, ce, FALSE); - g_object_unref (comp); } @@ -2660,29 +2566,8 @@ draw_curved_rectangle (cairo_t *cr, double x0, double y0, static void error_response(GtkWidget *widget, gint response, gpointer data) { - gtk_widget_destroy (widget); -} - -void -e_calendar_utils_show_error_silent (GtkWidget *widget) -{ - EActivityHandler *handler = calendar_component_peek_activity_handler (calendar_component_peek ()); - - if(!g_object_get_data ((GObject *) widget, "response-handled")) { - g_signal_connect(widget, "response", G_CALLBACK(error_response), NULL); - } - - e_activity_handler_make_error (handler, "calendar", E_LOG_ERROR, widget); -} - -void -e_calendar_utils_show_info_silent (GtkWidget *widget) -{ - EActivityHandler *handler = calendar_component_peek_activity_handler (calendar_component_peek ()); - - if(!g_object_get_data ((GObject *) widget, "response-handled")) { - g_signal_connect(widget, "response", G_CALLBACK(error_response), NULL); - } - - e_activity_handler_make_error (handler, "calendar", E_LOG_WARNINGS, widget); + if (response == GTK_RESPONSE_DELETE_EVENT) + gtk_widget_destroy(widget); + else if (response == GTK_RESPONSE_OK) + gtk_widget_destroy(widget); } diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h index 57cc811ae7..8d3ac6f8ac 100644 --- a/calendar/gui/e-calendar-view.h +++ b/calendar/gui/e-calendar-view.h @@ -27,7 +27,6 @@ #include <gtk/gtk.h> #include "e-cal-model.h" #include "gnome-cal.h" -#include "e-activity-handler.h" #include "dialogs/comp-editor.h" G_BEGIN_DECLS @@ -130,7 +129,6 @@ void e_calendar_view_set_default_category (ECalendarView *cal_view, co gboolean e_calendar_view_get_use_24_hour_format (ECalendarView *view); void e_calendar_view_set_use_24_hour_format (ECalendarView *view, gboolean use_24_hour); -void e_calendar_view_set_activity_handler (ECalendarView *cal_view, EActivityHandler *activity_handler); void e_calendar_view_set_status_message (ECalendarView *cal_view, const gchar *message, gint percent); GList *e_calendar_view_get_selected_events (ECalendarView *cal_view); diff --git a/calendar/gui/e-cell-date-edit-config.h b/calendar/gui/e-cell-date-edit-config.h index 455cca7287..9917378dd1 100644 --- a/calendar/gui/e-cell-date-edit-config.h +++ b/calendar/gui/e-cell-date-edit-config.h @@ -24,7 +24,7 @@ #ifndef _E_CELL_DATE_EDIT_CONFIG_H_ #define _E_CELL_DATE_EDIT_CONFIG_H_ -#include <misc/e-cell-date-edit.h> +#include <table/e-cell-date-edit.h> #include "e-cell-date-edit-text.h" G_BEGIN_DECLS diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c index 48830be99f..a1ed7c0900 100644 --- a/calendar/gui/e-day-view-main-item.c +++ b/calendar/gui/e-day-view-main-item.c @@ -32,7 +32,7 @@ #include "e-util/e-categories-config.h" #include "e-day-view-layout.h" #include "e-day-view-main-item.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ #include "e-calendar-view.h" #include "comp-util.h" #include <libecal/e-cal-time-util.h> @@ -111,7 +111,9 @@ e_day_view_main_item_class_init (EDayViewMainItemClass *class) G_PARAM_WRITABLE)); /* init the accessibility support for e_day_view */ +#if 0 /* KILL-BONOBO */ e_day_view_main_item_a11y_init (); +#endif } diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c index a0ac7098e1..173fa054a6 100644 --- a/calendar/gui/e-day-view.c +++ b/calendar/gui/e-day-view.c @@ -26,7 +26,7 @@ #endif #include "e-day-view.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ #include <math.h> #include <time.h> @@ -35,7 +35,7 @@ #include <misc/e-canvas-utils.h> #include <misc/e-popup-menu.h> #include <misc/e-gui-utils.h> -#include <misc/e-unicode.h> +#include <e-util/e-unicode.h> #include <libgnomecanvas/gnome-canvas-rect-ellipse.h> #include <glib/gi18n.h> #include <e-util/e-categories-config.h> @@ -51,7 +51,6 @@ #include "print.h" #include "comp-util.h" #include "itip-utils.h" -#include "calendar-commands.h" #include "calendar-config.h" #include "goto.h" #include "e-cal-model-calendar.h" @@ -466,8 +465,10 @@ e_day_view_class_init (EDayViewClass *class) view_class->get_visible_time_range = e_day_view_get_visible_time_range; view_class->paste_text = e_day_view_paste_text; +#if 0 /* KILL-BONOBO */ /* init the accessibility support for e_day_view */ e_day_view_a11y_init (); +#endif } static void @@ -3397,9 +3398,11 @@ e_day_view_show_popup_menu (EDayView *day_view, day_view->popup_event_day = day; day_view->popup_event_num = event_num; +#if 0 /* KILL-BONOBO */ popup = e_calendar_view_create_popup_menu (E_CALENDAR_VIEW (day_view)); g_object_weak_ref (G_OBJECT (popup), popup_destroyed_cb, day_view); gtk_menu_popup (popup, NULL, NULL, NULL, NULL, gdk_event?gdk_event->button.button:0, gdk_event?gdk_event->button.time:gtk_get_current_event_time()); +#endif } static gboolean @@ -5606,6 +5609,7 @@ e_day_view_cursor_key_down (EDayView *day_view, GdkEventKey *event) static void e_day_view_cursor_key_left (EDayView *day_view, GdkEventKey *event) { +#if 0 /* KILL-BONOBO */ if (day_view->selection_start_day == 0) { gnome_calendar_previous (e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view))); } else { @@ -5619,12 +5623,14 @@ e_day_view_cursor_key_left (EDayView *day_view, GdkEventKey *event) gtk_widget_queue_draw (day_view->main_canvas); } g_signal_emit_by_name (day_view, "selected_time_changed"); +#endif } static void e_day_view_cursor_key_right (EDayView *day_view, GdkEventKey *event) { +#if 0 /* KILL-BONOBO */ if (day_view->selection_end_day == day_view->days_shown - 1) { gnome_calendar_next (e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view))); } else { @@ -5638,6 +5644,7 @@ e_day_view_cursor_key_right (EDayView *day_view, GdkEventKey *event) gtk_widget_queue_draw (day_view->main_canvas); } g_signal_emit_by_name (day_view, "selected_time_changed"); +#endif } @@ -6372,8 +6379,10 @@ e_day_view_on_editing_stopped (EDayView *day_view, if (!on_server) { if (!e_cal_create_object (client, icalcomp, NULL, NULL)) g_message (G_STRLOC ": Could not create the object!"); +#if 0 /* KILL-BONOBO */ else gnome_calendar_emit_user_created_signal (day_view, e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view)), client); +#endif /* we remove the object since we either got the update from the server or failed */ e_day_view_remove_event_cb (day_view, day, event_num, NULL); diff --git a/calendar/gui/e-itip-control.c b/calendar/gui/e-itip-control.c index d3928d6c6a..d849c465d8 100644 --- a/calendar/gui/e-itip-control.c +++ b/calendar/gui/e-itip-control.c @@ -31,8 +31,6 @@ #include <unistd.h> #include <glib/gi18n.h> #include <glib/gstdio.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-exception.h> #include <gtkhtml/gtkhtml.h> #include <gtkhtml/gtkhtml-embedded.h> #include <gtkhtml/gtkhtml-stream.h> @@ -52,6 +50,7 @@ #include "itip-utils.h" #include "e-itip-control.h" #include "common/authentication.h" +#include <shell/e-shell.h> struct _EItipControlPrivate { GtkWidget *html; @@ -243,12 +242,18 @@ source_changed_cb (ESourceComboBox *escb, EItipControl *itip) static void find_cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) { + EShell *shell; + EShellSettings *shell_settings; EItipControlFindData *fd = data; EItipControlPrivate *priv; ESource *source; ECalSourceType source_type; icalcomponent *icalcomp; + /* FIXME Pass this in. */ + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + source_type = e_cal_get_source_type (ecal); source = e_cal_get_source (ecal); @@ -275,20 +280,24 @@ find_cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) if (fd->count == 0) { if (fd->show_selector && !priv->current_ecal && priv->vbox.widget) { GtkWidget *escb; + const gchar *property_name; gchar *uid; switch (priv->type) { case E_CAL_SOURCE_TYPE_EVENT: - uid = calendar_config_get_primary_calendar (); + property_name = "cal-primary-calendar"; break; case E_CAL_SOURCE_TYPE_TODO: - uid = calendar_config_get_primary_tasks (); + property_name = "cal-primary-tasks"; break; default: uid = NULL; g_return_if_reached (); } + uid = e_shell_settings_get_string ( + shell_settings, property_name); + if (uid) { source = e_source_list_peek_source_by_uid (priv->source_lists[priv->type], uid); g_free (uid); diff --git a/calendar/gui/e-meeting-time-sel.c b/calendar/gui/e-meeting-time-sel.c index 1ea1c9082a..16b6a9d48c 100644 --- a/calendar/gui/e-meeting-time-sel.c +++ b/calendar/gui/e-meeting-time-sel.c @@ -35,14 +35,13 @@ #include <glib/gi18n.h> #include <libgnomecanvas/gnome-canvas-widget.h> -#include <misc/e-canvas.h> -#include <misc/e-canvas-utils.h> +#include "misc/e-canvas.h" +#include "misc/e-canvas-utils.h" -#include <misc/e-dateedit.h> -#include <e-util/e-cursor.h> -#include <e-util/e-util.h> +#include "misc/e-dateedit.h" +#include "e-util/e-cursor.h" +#include "e-util/e-util.h" -#include "calendar-component.h" #include "calendar-config.h" #include "e-meeting-utils.h" #include "e-meeting-list-view.h" diff --git a/calendar/gui/e-memo-list-selector.c b/calendar/gui/e-memo-list-selector.c new file mode 100644 index 0000000000..e31a9d4b6e --- /dev/null +++ b/calendar/gui/e-memo-list-selector.c @@ -0,0 +1,287 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-memo-list-selector.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-memo-list-selector.h" + +#include <string.h> +#include <libecal/e-cal.h> +#include "calendar/common/authentication.h" +#include "calendar/gui/comp-util.h" + +#define E_MEMO_LIST_SELECTOR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MEMO_LIST_SELECTOR, EMemoListSelectorPrivate)) + +struct _EMemoListSelectorPrivate { + gint dummy_value; +}; + +enum { + DND_TARGET_TYPE_CALENDAR_LIST +}; + +static GtkTargetEntry drag_types[] = { + { (gchar *) "text/calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST }, + { (gchar *) "text/x-calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST } +}; + +static gpointer parent_class; + +static gboolean +memo_list_selector_update_single_object (ECal *client, + icalcomponent *icalcomp) +{ + gchar *uid; + icalcomponent *tmp_icalcomp; + + uid = (gchar *) icalcomponent_get_uid (icalcomp); + + if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, NULL)) + return e_cal_modify_object ( + client, icalcomp, CALOBJ_MOD_ALL, NULL); + + return e_cal_create_object (client, icalcomp, &uid, NULL); +} + +static gboolean +memo_list_selector_update_objects (ECal *client, + icalcomponent *icalcomp) +{ + icalcomponent *subcomp; + icalcomponent_kind kind; + + kind = icalcomponent_isa (icalcomp); + if (kind == ICAL_VJOURNAL_COMPONENT) + return memo_list_selector_update_single_object ( + client, icalcomp); + else if (kind != ICAL_VCALENDAR_COMPONENT) + return FALSE; + + subcomp = icalcomponent_get_first_component ( + icalcomp, ICAL_ANY_COMPONENT); + while (subcomp != NULL) { + gboolean success; + + kind = icalcomponent_isa (subcomp); + if (kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + + success = e_cal_add_timezone (client, zone, NULL); + icaltimezone_free (zone, 1); + if (!success) + return FALSE; + } else if (kind == ICAL_VJOURNAL_COMPONENT) { + success = memo_list_selector_update_single_object ( + client, subcomp); + if (!success) + return FALSE; + } + + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + return TRUE; +} + +static gboolean +memo_list_selector_process_data (ESourceSelector *selector, + ECal *client, + const gchar *source_uid, + icalcomponent *icalcomp, + GdkDragAction action) +{ + ESourceList *source_list; + ESource *source; + icalcomponent *tmp_icalcomp = NULL; + const gchar *uid; + gchar *old_uid = NULL; + gboolean success = FALSE; + gboolean read_only = TRUE; + GError *error = NULL; + + /* FIXME Deal with GDK_ACTION_ASK. */ + if (action == GDK_ACTION_COPY) { + old_uid = g_strdup (icalcomponent_get_uid (icalcomp)); + uid = e_cal_component_gen_uid (); + icalcomponent_set_uid (icalcomp, uid); + } + + uid = icalcomponent_get_uid (icalcomp); + if (old_uid == NULL) + old_uid = g_strdup (uid); + + if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, &error)) { + icalcomponent_free (tmp_icalcomp); + success = TRUE; + goto exit; + } + + if (error != NULL && error->code != E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { + g_message ( + "Failed to search the object in destination " + "task list: %s", error->message); + g_error_free (error); + goto exit; + } + + success = memo_list_selector_update_objects (client, icalcomp); + + if (!success || action != GDK_ACTION_MOVE) + goto exit; + + source_list = e_source_selector_get_source_list (selector); + source = e_source_list_peek_source_by_uid (source_list, source_uid); + + if (!E_IS_SOURCE (source) || e_source_get_readonly (source)) + goto exit; + + client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_JOURNAL); + if (client == NULL) { + g_message ("Cannot create source client to remove old memo"); + goto exit; + } + + e_cal_is_read_only (client, &read_only, NULL); + if (!read_only && e_cal_open (client, TRUE, NULL)) + e_cal_remove_object (client, old_uid, NULL); + else if (!read_only) + g_message ("Cannot open source client to remove old memo"); + + g_object_unref (client); + +exit: + g_free (old_uid); + + return success; +} + +static gboolean +memo_list_selector_data_dropped (ESourceSelector *selector, + GtkSelectionData *selection_data, + ESource *destination, + GdkDragAction action, + guint info) +{ + ECal *client; + GSList *list, *iter; + gboolean success = FALSE; + + client = auth_new_cal_from_source ( + destination, E_CAL_SOURCE_TYPE_JOURNAL); + + if (client == NULL || !e_cal_open (client, TRUE, NULL)) + goto exit; + + list = cal_comp_selection_get_string_list (selection_data); + + for (iter = list; iter != NULL; iter = iter->next) { + gchar *source_uid = iter->data; + icalcomponent *icalcomp; + gchar *component_string; + + /* Each string is "source_uid\ncomponent_string". */ + component_string = strchr (source_uid, '\n'); + if (component_string == NULL) + continue; + + *component_string++ = '\0'; + icalcomp = icalparser_parse_string (component_string); + if (icalcomp == NULL) + continue; + + success = memo_list_selector_process_data ( + selector, client, source_uid, icalcomp, action); + + icalcomponent_free (icalcomp); + } + + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); + +exit: + if (client != NULL) + g_object_unref (client); + + return success; +} + +static void +memo_list_selector_class_init (EMemoListSelectorClass *class) +{ + ESourceSelectorClass *source_selector_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMemoListSelectorPrivate)); + + source_selector_class = E_SOURCE_SELECTOR_CLASS (class); + source_selector_class->data_dropped = memo_list_selector_data_dropped; +} + +static void +memo_list_selector_init (EMemoListSelector *selector) +{ + selector->priv = E_MEMO_LIST_SELECTOR_GET_PRIVATE (selector); + + gtk_drag_dest_set ( + GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL, + drag_types, G_N_ELEMENTS (drag_types), + GDK_ACTION_COPY | GDK_ACTION_MOVE); +} + +GType +e_memo_list_selector_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EMemoListSelectorClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) memo_list_selector_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMemoListSelector), + 0, /* n_preallocs */ + (GInstanceInitFunc) memo_list_selector_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + E_TYPE_SOURCE_SELECTOR, "EMemoListSelector", + &type_info, 0); + } + + return type; +} + +GtkWidget * +e_memo_list_selector_new (ESourceList *source_list) +{ + g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL); + + return g_object_new ( + E_TYPE_MEMO_LIST_SELECTOR, + "source-list", source_list, NULL); +} diff --git a/calendar/gui/e-memo-list-selector.h b/calendar/gui/e-memo-list-selector.h new file mode 100644 index 0000000000..c10cff2a2e --- /dev/null +++ b/calendar/gui/e-memo-list-selector.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-memo-list-selector.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* XXX This widget is nearly identical to ETaskListSelector. If + * ECalendarSelector ever learns how to move selections from + * one source to another, perhaps these ESourceSelector sub- + * classes could someday be combined. */ + +#ifndef E_MEMO_LIST_SELECTOR_H +#define E_MEMO_LIST_SELECTOR_H + +#include <libedataserver/e-source-list.h> +#include <libedataserverui/e-source-selector.h> + +/* Standard GObject macros */ +#define E_TYPE_MEMO_LIST_SELECTOR \ + (e_memo_list_selector_get_type ()) +#define E_MEMO_LIST_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MEMO_LIST_SELECTOR, EMemoListSelector)) +#define E_MEMO_LIST_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MEMO_LIST_SELECTOR, EMemoListSelectorClass)) +#define E_IS_MEMO_LIST_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MEMO_LIST_SELECTOR)) +#define E_IS_MEMO_LIST_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MEMO_LIST_SELECTOR)) +#define E_MEMO_LIST_SELECTOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MEMO_LIST_SELECTOR, EMemoListSelectorClass)) + +G_BEGIN_DECLS + +typedef struct _EMemoListSelector EMemoListSelector; +typedef struct _EMemoListSelectorClass EMemoListSelectorClass; +typedef struct _EMemoListSelectorPrivate EMemoListSelectorPrivate; + +struct _EMemoListSelector { + ESourceSelector parent; + EMemoListSelectorPrivate *priv; +}; + +struct _EMemoListSelectorClass { + ESourceSelectorClass parent_class; +}; + +GType e_memo_list_selector_get_type (void); +GtkWidget * e_memo_list_selector_new (ESourceList *source_list); + +G_END_DECLS + +#endif /* E_MEMO_LIST_SELECTOR_H */ diff --git a/calendar/gui/e-memo-table.c b/calendar/gui/e-memo-table.c index ea03097ca8..4c6cd9b865 100644 --- a/calendar/gui/e-memo-table.c +++ b/calendar/gui/e-memo-table.c @@ -24,7 +24,7 @@ /* * EMemoTable - displays the ECalComponent objects in a table (an ETable). - * Used for memos. + * Used for calendar events and tasks. */ #ifdef HAVE_CONFIG_H @@ -35,15 +35,17 @@ #include <unistd.h> #include <glib/gi18n.h> #include <glib/gstdio.h> -#include <gdk/gdkkeysyms.h> #include <widgets/misc/e-gui-utils.h> #include <table/e-cell-checkbox.h> #include <table/e-cell-toggle.h> #include <table/e-cell-text.h> #include <table/e-cell-combo.h> #include <e-util/e-dialog-utils.h> -#include <widgets/misc/e-cell-date-edit.h> -#include <widgets/misc/e-cell-percent.h> +#include <e-util/e-util-private.h> +#include <table/e-cell-date-edit.h> +#include <table/e-cell-percent.h> +#include <libecal/e-cal-time-util.h> +#include <libedataserver/e-time-utils.h> #include "calendar-config.h" #include "dialogs/delete-comp.h" @@ -51,64 +53,52 @@ #include "dialogs/memo-editor.h" #include "e-cal-model-memos.h" #include "e-memo-table.h" +#include "e-calendar-view.h" #include "e-cell-date-edit-text.h" -#include "e-comp-editor-registry.h" #include "print.h" #include <e-util/e-icon-factory.h> -#include <e-util/e-util-private.h> #include "e-cal-popup.h" -#include "e-calendar-table.h" +#include "misc.h" + +#define E_MEMO_TABLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MEMO_TABLE, EMemoTablePrivate)) + +struct _EMemoTablePrivate { + gpointer shell_view; /* weak pointer */ + ECalModel *model; +}; + +enum { + PROP_0, + PROP_MODEL, + PROP_SHELL_VIEW +}; -enum TargetType{ +enum { + OPEN_COMPONENT, + POPUP_EVENT, + STATUS_MESSAGE, + USER_CREATED, + LAST_SIGNAL +}; + +enum { TARGET_TYPE_VCALENDAR }; static GtkTargetEntry target_types[] = { - { (gchar *) "text/x-calendar", 0, TARGET_TYPE_VCALENDAR }, - { (gchar *) "text/calendar", 0, TARGET_TYPE_VCALENDAR } + { (gchar *) "text/calendar", 0, TARGET_TYPE_VCALENDAR }, + { (gchar *) "text/x-calendar", 0, TARGET_TYPE_VCALENDAR } }; static guint n_target_types = G_N_ELEMENTS (target_types); - -extern ECompEditorRegistry *comp_editor_registry; - -static void e_memo_table_destroy (GtkObject *object); - -static void e_memo_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - EMemoTable *memo_table); -static gint e_memo_table_show_popup_menu (ETable *table, - GdkEvent *gdk_event, - EMemoTable *memo_table); - -static gint e_memo_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - EMemoTable *memo_table); -static gboolean e_memo_table_on_popup_menu (GtkWidget *widget, - gpointer data); - -static gint e_memo_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - EMemoTable *memo_table); static struct tm e_memo_table_get_current_time (ECellDateEdit *ecde, gpointer data); -static ECalModelComponent *get_selected_comp (EMemoTable *memo_table); -static void open_memo (EMemoTable *memo_table, ECalModelComponent *comp_data); - -/* Signal IDs */ -enum { - USER_CREATED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; +static gpointer parent_class; +static guint signals[LAST_SIGNAL]; +static GdkAtom clipboard_atom; /* The icons to represent the task. */ #define E_MEMO_MODEL_NUM_ICONS 2 @@ -117,37 +107,45 @@ static const gchar * icon_names[E_MEMO_MODEL_NUM_ICONS] = { }; static GdkPixbuf* icon_pixbufs[E_MEMO_MODEL_NUM_ICONS] = { NULL }; -static GdkAtom clipboard_atom = GDK_NONE; - -G_DEFINE_TYPE (EMemoTable, e_memo_table, GTK_TYPE_TABLE) +static void +memo_table_emit_open_component (EMemoTable *memo_table, + ECalModelComponent *comp_data) +{ + guint signal_id = signals[OPEN_COMPONENT]; + g_signal_emit (memo_table, signal_id, 0, comp_data); +} static void -e_memo_table_class_init (EMemoTableClass *klass) +memo_table_emit_popup_event (EMemoTable *memo_table, + GdkEvent *event) { - GtkObjectClass *object_class; + guint signal_id = signals[POPUP_EVENT]; - object_class = (GtkObjectClass *) klass; + g_signal_emit (memo_table, signal_id, 0, event); +} + +static void +memo_table_emit_status_message (EMemoTable *memo_table, + const gchar *message, + gdouble percent) +{ + guint signal_id = signals[STATUS_MESSAGE]; - /* Method override */ - object_class->destroy = e_memo_table_destroy; + g_signal_emit (memo_table, signal_id, 0, message, percent); +} - signals[USER_CREATED] = - g_signal_new ("user_created", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EMemoTableClass, user_created), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); +static void +memo_table_emit_user_created (EMemoTable *memo_table) +{ + guint signal_id = signals[USER_CREATED]; - /* clipboard atom */ - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); + g_signal_emit (memo_table, signal_id, 0); } static gint -date_compare_cb (gconstpointer a, gconstpointer b) +memo_table_date_compare_cb (gconstpointer a, + gconstpointer b) { ECellDateEditValue *dv1 = (ECellDateEditValue *) a; ECellDateEditValue *dv2 = (ECellDateEditValue *) b; @@ -175,76 +173,414 @@ date_compare_cb (gconstpointer a, gconstpointer b) } static void -row_appended_cb (ECalModel *model, EMemoTable *memo_table) +memo_table_double_click_cb (EMemoTable *memo_table, + gint row, + gint col, + GdkEvent *event) +{ + ECalModel *model; + ECalModelComponent *comp_data; + + model = e_memo_table_get_model (memo_table); + comp_data = e_cal_model_get_component_at (model, row); + memo_table_emit_open_component (memo_table, comp_data); +} + +static void +memo_table_model_cal_view_progress_cb (EMemoTable *memo_table, + const gchar *message, + gint progress, + ECalSourceType type) +{ + gdouble percent = (gdouble) progress; + + memo_table_emit_status_message (memo_table, message, percent); +} + +static void +memo_table_model_cal_view_done_cb (EMemoTable *memo_table, + ECalendarStatus status, + ECalSourceType type) { - g_signal_emit (memo_table, signals[USER_CREATED], 0); + memo_table_emit_status_message (memo_table, NULL, -1.0); } static gboolean -query_tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data) +memo_table_query_tooltip_cb (EMemoTable *memo_table, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip) { - EMemoTable *memo_table; + ECalModel *model; + ECalModelComponent *comp_data; + gint row = -1, col = -1; + GtkWidget *box, *l, *w; + GtkStyle *style = gtk_widget_get_default_style (); + gchar *tmp; + const gchar *str; + GString *tmp2; + gchar buff[1001]; + gboolean free_text = FALSE; + ECalComponent *new_comp; + ECalComponentOrganizer organizer; + ECalComponentDateTime dtstart, dtdue; + icalcomponent *clone; + icaltimezone *zone, *default_zone; + GSList *desc, *p; + gint len; + ETable *etable; + ESelectionModel *esm; + struct tm tmp_tm; + + if (keyboard_mode) + return FALSE; + + etable = e_memo_table_get_table (memo_table); + e_table_get_mouse_over_cell (etable, &row, &col); + if (row == -1 || !etable) + return FALSE; + + /* Respect sorting option; the 'e_table_get_mouse_over_cell' + * returns sorted row, not the model one. */ + esm = e_table_get_selection_model (etable); + if (esm && esm->sorter && e_sorter_needs_sorting (esm->sorter)) + row = e_sorter_sorted_to_model (esm->sorter, row); + + model = e_memo_table_get_model (memo_table); + comp_data = e_cal_model_get_component_at (model, row); + if (!comp_data || !comp_data->icalcomp) + return FALSE; + + new_comp = e_cal_component_new (); + clone = icalcomponent_new_clone (comp_data->icalcomp); + if (!e_cal_component_set_icalcomponent (new_comp, clone)) { + g_object_unref (new_comp); + return FALSE; + } + + box = gtk_vbox_new (FALSE, 0); + + str = e_calendar_view_get_icalcomponent_summary ( + comp_data->client, comp_data->icalcomp, &free_text); + if (!(str && *str)) { + if (free_text) + g_free ((gchar *)str); + free_text = FALSE; + str = _("* No Summary *"); + } + + l = gtk_label_new (NULL); + tmp = g_markup_printf_escaped ("<b>%s</b>", str); + gtk_label_set_line_wrap (GTK_LABEL (l), TRUE); + gtk_label_set_markup (GTK_LABEL (l), tmp); + gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); + w = gtk_event_box_new (); + + gtk_widget_modify_bg (w, GTK_STATE_NORMAL, &(style->bg[GTK_STATE_SELECTED])); + gtk_widget_modify_fg (l, GTK_STATE_NORMAL, &(style->text[GTK_STATE_SELECTED])); + gtk_container_add (GTK_CONTAINER (w), l); + gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); + g_free (tmp); + + if (free_text) + g_free ((gchar *)str); + free_text = FALSE; + + w = gtk_event_box_new (); + gtk_widget_modify_bg (w, GTK_STATE_NORMAL, &(style->bg[GTK_STATE_NORMAL])); + + l = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (w), l); + gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0); + w = l; + + e_cal_component_get_organizer (new_comp, &organizer); + if (organizer.cn) { + gchar *ptr; + ptr = strchr( organizer.value, ':'); + + if (ptr) { + ptr++; + /* To Translators: It will display "Organizer: NameOfTheUser <email@ofuser.com>" */ + tmp = g_strdup_printf (_("Organizer: %s <%s>"), organizer.cn, ptr); + } else { + /* With SunOne accounts, there may be no ':' in organiser.value */ + tmp = g_strdup_printf (_("Organizer: %s"), organizer.cn); + } + + l = gtk_label_new (tmp); + gtk_label_set_line_wrap (GTK_LABEL (l), FALSE); + gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0); + g_free (tmp); + } + + e_cal_component_get_dtstart (new_comp, &dtstart); + e_cal_component_get_due (new_comp, &dtdue); + + default_zone = e_cal_model_get_timezone (model); - g_return_val_if_fail (E_IS_MEMO_TABLE (user_data), FALSE); + if (dtstart.tzid) { + zone = icalcomponent_get_timezone (e_cal_component_get_icalcomponent (new_comp), dtstart.tzid); + if (!zone) + e_cal_get_timezone ( + comp_data->client, dtstart.tzid, &zone, NULL); + if (!zone) + zone = default_zone; + } else { + zone = NULL; + } + + tmp2 = g_string_new (""); + + if (dtstart.value) { + buff[0] = 0; + + tmp_tm = icaltimetype_to_tm_with_zone ( + dtstart.value, zone, default_zone); + e_time_format_date_and_time ( + &tmp_tm, calendar_config_get_24_hour_format (), + FALSE, FALSE, buff, 1000); + + if (buff [0]) { + g_string_append (tmp2, _("Start: ")); + g_string_append (tmp2, buff); + } + } + + if (dtdue.value) { + buff[0] = 0; + + tmp_tm = icaltimetype_to_tm_with_zone ( + dtdue.value, zone, default_zone); + e_time_format_date_and_time ( + &tmp_tm, calendar_config_get_24_hour_format (), + FALSE, FALSE, buff, 1000); + + if (buff [0]) { + if (tmp2->len) + g_string_append (tmp2, "; "); + + g_string_append (tmp2, _("Due: ")); + g_string_append (tmp2, buff); + } + } + + if (tmp2->len) { + l = gtk_label_new (tmp2->str); + gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0); + } + + g_string_free (tmp2, TRUE); + + e_cal_component_free_datetime (&dtstart); + e_cal_component_free_datetime (&dtdue); + + tmp2 = g_string_new (""); + e_cal_component_get_description_list (new_comp, &desc); + for (len = 0, p = desc; p != NULL; p = p->next) { + ECalComponentText *text = p->data; + + if (text->value != NULL) { + len += strlen (text->value); + g_string_append (tmp2, text->value); + if (len > 1024) { + g_string_set_size (tmp2, 1020); + g_string_append (tmp2, "..."); + break; + } + } + } + e_cal_component_free_text_list (desc); + + if (tmp2->len) { + l = gtk_label_new (tmp2->str); + gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0); + } + + g_string_free (tmp2, TRUE); + + gtk_widget_show_all (box); + gtk_tooltip_set_custom (tooltip, box); + + g_object_unref (new_comp); - memo_table = E_MEMO_TABLE (user_data); + return TRUE; +} + +static gboolean +memo_table_popup_menu_cb (EMemoTable *memo_table) +{ + memo_table_emit_popup_event (memo_table, NULL); + + return TRUE; +} + +static gint +memo_table_right_click_cb (EMemoTable *memo_table, + gint row, + gint col, + GdkEvent *event) +{ + memo_table_emit_popup_event (memo_table, event); + + return TRUE; +} - return ec_query_tooltip (widget, x, y, keyboard_mode, tooltip, GTK_WIDGET (e_memo_table_get_table (memo_table)), memo_table->model); +static void +memo_table_set_model (EMemoTable *memo_table, + ECalModel *model) +{ + g_return_if_fail (memo_table->priv->model == NULL); + + memo_table->priv->model = g_object_ref (model); + + g_signal_connect_swapped ( + model, "row-appended", + G_CALLBACK (memo_table_emit_user_created), memo_table); + + g_signal_connect_swapped ( + model, "cal-view-progress", + G_CALLBACK (memo_table_model_cal_view_progress_cb), + memo_table); + + g_signal_connect_swapped ( + model, "cal-view-done", + G_CALLBACK (memo_table_model_cal_view_done_cb), + memo_table); +} + +static void +memo_table_set_shell_view (EMemoTable *memo_table, + EShellView *shell_view) +{ + g_return_if_fail (memo_table->priv->shell_view == NULL); + + memo_table->priv->shell_view = shell_view; + + g_object_add_weak_pointer ( + G_OBJECT (shell_view), + &memo_table->priv->shell_view); } static void -e_memo_table_init (EMemoTable *memo_table) +memo_table_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - GtkWidget *table; - ETable *e_table; + switch (property_id) { + case PROP_MODEL: + memo_table_set_model ( + E_MEMO_TABLE (object), + g_value_get_object (value)); + return; + + case PROP_SHELL_VIEW: + memo_table_set_shell_view ( + E_MEMO_TABLE (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +memo_table_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_MODEL: + g_value_set_object ( + value, e_memo_table_get_model ( + E_MEMO_TABLE (object))); + return; + + case PROP_SHELL_VIEW: + g_value_set_object ( + value, e_memo_table_get_shell_view ( + E_MEMO_TABLE (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +memo_table_dispose (GObject *object) +{ + EMemoTablePrivate *priv; + + priv = E_MEMO_TABLE_GET_PRIVATE (object); + + if (priv->shell_view != NULL) { + g_object_remove_weak_pointer ( + G_OBJECT (priv->shell_view), &priv->shell_view); + priv->shell_view = NULL; + } + + if (priv->model != NULL) { + g_object_unref (priv->model); + priv->model = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +memo_table_constructed (GObject *object) +{ + EMemoTable *memo_table; + GtkWidget *widget; + ECalModel *model; + ETable *table; ECell *cell, *popup_cell; ETableExtras *extras; gint i; AtkObject *a11y; gchar *etspecfile; - /* Create the model */ - - memo_table->model = (ECalModel *) e_cal_model_memos_new (); - g_signal_connect (memo_table->model, "row_appended", G_CALLBACK (row_appended_cb), memo_table); - - memo_table->user_created_cal = NULL; + memo_table = E_MEMO_TABLE (object); + model = e_memo_table_get_model (memo_table); /* Create the header columns */ - extras = e_table_extras_new(); + extras = e_table_extras_new (); /* * Normal string fields. */ cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "bg_color_column", E_CAL_MODEL_FIELD_COLOR, - NULL); - + g_object_set (cell, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, NULL); e_table_extras_add_cell (extras, "calstring", cell); /* * Date fields. */ cell = e_cell_date_edit_text_new (NULL, GTK_JUSTIFY_LEFT); - g_object_set (G_OBJECT (cell), - "bg_color_column", E_CAL_MODEL_FIELD_COLOR, - NULL); + g_object_set (cell, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, NULL); popup_cell = e_cell_date_edit_new (); e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell); g_object_unref (cell); + e_table_extras_add_cell (extras, "dateedit", popup_cell); memo_table->dates_cell = E_CELL_DATE_EDIT (popup_cell); - e_cell_date_edit_set_get_time_callback (E_CELL_DATE_EDIT (popup_cell), - e_memo_table_get_current_time, - memo_table, NULL); + e_cell_date_edit_set_get_time_callback ( + E_CELL_DATE_EDIT (popup_cell), + e_memo_table_get_current_time, memo_table, NULL); /* Sorting */ - e_table_extras_add_compare (extras, "date-compare", - date_compare_cb); + e_table_extras_add_compare ( + extras, "date-compare", memo_table_date_compare_cb); /* Create pixmaps */ @@ -254,60 +590,180 @@ e_memo_table_init (EMemoTable *memo_table) } cell = e_cell_toggle_new (0, E_MEMO_MODEL_NUM_ICONS, icon_pixbufs); - e_table_extras_add_cell(extras, "icon", cell); - e_table_extras_add_pixbuf(extras, "icon", icon_pixbufs[0]); + e_table_extras_add_cell (extras, "icon", cell); + e_table_extras_add_pixbuf (extras, "icon", icon_pixbufs[0]); /* Create the table */ - etspecfile = g_build_filename (EVOLUTION_ETSPECDIR, - "e-memo-table.etspec", - NULL); - table = e_table_scrolled_new_from_spec_file (E_TABLE_MODEL (memo_table->model), - extras, - etspecfile, - NULL); + etspecfile = g_build_filename ( + EVOLUTION_ETSPECDIR, "e-memo-table.etspec", NULL); + widget = e_table_scrolled_new_from_spec_file ( + E_TABLE_MODEL (model), extras, etspecfile, NULL); + gtk_table_attach ( + GTK_TABLE (memo_table), widget, 0, 1, 0, 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + memo_table->etable = widget; + gtk_widget_show (widget); g_free (etspecfile); - /* FIXME: this causes a message from GLib about 'extras' having only a floating - reference */ - /* g_object_unref (extras); */ + table = e_table_scrolled_get_table (E_TABLE_SCROLLED (widget)); + g_signal_connect_swapped ( + table, "double-click", + G_CALLBACK (memo_table_double_click_cb), memo_table); + g_signal_connect_swapped ( + table, "query-tooltip", + G_CALLBACK (memo_table_query_tooltip_cb), memo_table); + g_signal_connect_swapped ( + table, "popup-menu", + G_CALLBACK (memo_table_popup_menu_cb), memo_table); + g_signal_connect_swapped ( + table, "right-click", + G_CALLBACK (memo_table_right_click_cb), memo_table); + gtk_widget_set_has_tooltip (GTK_WIDGET (table), TRUE); + + a11y = gtk_widget_get_accessible (GTK_WIDGET (table)); + if (a11y) + atk_object_set_name (a11y, _("Memos")); +} - memo_table->etable = table; - gtk_table_attach (GTK_TABLE (memo_table), table, 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (table); +static void +memo_table_class_init (EMemoTableClass *class) +{ + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMemoTablePrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = memo_table_set_property; + object_class->get_property = memo_table_get_property; + object_class->dispose = memo_table_dispose; + object_class->constructed = memo_table_constructed; + + g_object_class_install_property ( + object_class, + PROP_MODEL, + g_param_spec_object ( + "model", + _("Model"), + NULL, + E_TYPE_CAL_MODEL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property ( + object_class, + PROP_SHELL_VIEW, + g_param_spec_object ( + "shell-view", + _("Shell View"), + NULL, + E_TYPE_SHELL_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + signals[OPEN_COMPONENT] = g_signal_new ( + "open-component", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMemoTableClass, open_component), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + E_TYPE_CAL_MODEL_COMPONENT); + + signals[POPUP_EVENT] = g_signal_new ( + "popup-event", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMemoTableClass, popup_event), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + + signals[STATUS_MESSAGE] = g_signal_new ( + "status-message", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMemoTableClass, status_message), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + signals[USER_CREATED] = g_signal_new ( + "user-created", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMemoTableClass, user_created), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); +} +static void +memo_table_init (EMemoTable *memo_table) +{ + memo_table->priv = E_MEMO_TABLE_GET_PRIVATE (memo_table); +} - e_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (table)); - g_signal_connect (e_table, "double_click", G_CALLBACK (e_memo_table_on_double_click), memo_table); - g_signal_connect (e_table, "right_click", G_CALLBACK (e_memo_table_on_right_click), memo_table); - g_signal_connect (e_table, "key_press", G_CALLBACK (e_memo_table_on_key_press), memo_table); - g_signal_connect (e_table, "popup_menu", G_CALLBACK (e_memo_table_on_popup_menu), memo_table); - g_signal_connect (e_table, "query-tooltip", G_CALLBACK (query_tooltip_cb), memo_table); - gtk_widget_set_has_tooltip (GTK_WIDGET (e_table), TRUE); +GType +e_memo_table_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMemoTableClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) memo_table_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMemoTable), + 0, /* n_preallocs */ + (GInstanceInitFunc) memo_table_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_TABLE, "EMemoTable", &type_info, 0); + } - a11y = gtk_widget_get_accessible (GTK_WIDGET(e_table)); - if (a11y) - atk_object_set_name (a11y, _("Memos")); + return type; } - /** * e_memo_table_new: - * @Returns: a new #EMemoTable. + * @shell_view: an #EShellView + * @model: an #ECalModel for the table + * + * Returns a new #EMemoTable. * - * Creates a new #EMemoTable. + * Returns: a new #EMemoTable **/ GtkWidget * -e_memo_table_new (void) +e_memo_table_new (EShellView *shell_view, + ECalModel *model) { - GtkWidget *memo_table; - - memo_table = GTK_WIDGET (g_object_new (e_memo_table_get_type (), NULL)); + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL); - return memo_table; + return g_object_new ( + E_TYPE_MEMO_TABLE, + "model", model, "shell-view", shell_view, NULL); } +EShellView * +e_memo_table_get_shell_view (EMemoTable *memo_table) +{ + g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL); + + return memo_table->priv->shell_view; +} /** * e_memo_table_get_model: @@ -323,25 +779,10 @@ e_memo_table_get_model (EMemoTable *memo_table) g_return_val_if_fail (memo_table != NULL, NULL); g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL); - return memo_table->model; + return memo_table->priv->model; } -static void -e_memo_table_destroy (GtkObject *object) -{ - EMemoTable *memo_table; - - memo_table = E_MEMO_TABLE (object); - - if (memo_table->model) { - g_object_unref (memo_table->model); - memo_table->model = NULL; - } - - GTK_OBJECT_CLASS (e_memo_table_parent_class)->destroy (object); -} - /** * e_memo_table_get_table: * @memo_table: A calendar table. @@ -354,20 +795,13 @@ e_memo_table_destroy (GtkObject *object) ETable * e_memo_table_get_table (EMemoTable *memo_table) { - g_return_val_if_fail (memo_table != NULL, NULL); - g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL); + ETableScrolled *table_scrolled; - return e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); -} + g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL); -void -e_memo_table_open_selected (EMemoTable *memo_table) -{ - ECalModelComponent *comp_data; + table_scrolled = E_TABLE_SCROLLED (memo_table->etable); - comp_data = get_selected_comp (memo_table); - if (comp_data != NULL) - open_memo (memo_table, comp_data); + return e_table_scrolled_get_table (table_scrolled); } /* Used from e_table_selected_row_foreach(); puts the selected row number in an @@ -389,10 +823,12 @@ get_selected_row_cb (gint model_row, gpointer data) static ECalModelComponent * get_selected_comp (EMemoTable *memo_table) { + ECalModel *model; ETable *etable; gint row; - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); + model = e_memo_table_get_model (memo_table); + etable = e_memo_table_get_table (memo_table); if (e_table_selected_count (etable) != 1) return NULL; @@ -402,7 +838,7 @@ get_selected_comp (EMemoTable *memo_table) &row); g_return_val_if_fail (row != -1, NULL); - return e_cal_model_get_component_at (memo_table->model, row); + return e_cal_model_get_component_at (model, row); } struct get_selected_uids_closure { @@ -416,38 +852,27 @@ add_uid_cb (gint model_row, gpointer data) { struct get_selected_uids_closure *closure; ECalModelComponent *comp_data; + ECalModel *model; closure = data; - comp_data = e_cal_model_get_component_at (closure->memo_table->model, model_row); + model = e_memo_table_get_model (closure->memo_table); + comp_data = e_cal_model_get_component_at (model, model_row); closure->objects = g_slist_prepend (closure->objects, comp_data); } -static GSList * -get_selected_objects (EMemoTable *memo_table) -{ - struct get_selected_uids_closure closure; - ETable *etable; - - closure.memo_table = memo_table; - closure.objects = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); - e_table_selected_row_foreach (etable, add_uid_cb, &closure); - - return closure.objects; -} - /* Deletes all of the selected components in the table */ static void delete_selected_components (EMemoTable *memo_table) { GSList *objs, *l; + const gchar *status_message; - objs = get_selected_objects (memo_table); + objs = e_memo_table_get_selected (memo_table); - e_memo_table_set_status_message (memo_table, _("Deleting selected objects")); + status_message = _("Deleting selected objects"); + memo_table_emit_status_message (memo_table, status_message, -1.0); for (l = objs; l; l = l->next) { ECalModelComponent *comp_data = (ECalModelComponent *) l->data; @@ -459,27 +884,12 @@ delete_selected_components (EMemoTable *memo_table) g_clear_error (&error); } - e_memo_table_set_status_message (memo_table, NULL); + memo_table_emit_status_message (memo_table, NULL, -1.0); g_slist_free (objs); } /** - * e_memo_table_get_selected: - * @memo_table: - * - * Get the currently selected ECalModelComponent's on the table. - * - * Return value: A GSList of the components, which should be - * g_slist_free'd when finished with. - **/ -GSList * -e_memo_table_get_selected (EMemoTable *memo_table) -{ - return get_selected_objects(memo_table); -} - -/** * e_memo_table_delete_selected: * @memo_table: A memo table. * @@ -496,7 +906,7 @@ e_memo_table_delete_selected (EMemoTable *memo_table) g_return_if_fail (memo_table != NULL); g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); + etable = e_memo_table_get_table (memo_table); n_selected = e_table_selected_count (etable); if (n_selected <= 0) @@ -524,6 +934,30 @@ e_memo_table_delete_selected (EMemoTable *memo_table) } /** + * e_memo_table_get_selected: + * @memo_table: + * + * Get the currently selected ECalModelComponent's on the table. + * + * Return value: A GSList of the components, which should be + * g_slist_free'd when finished with. + **/ +GSList * +e_memo_table_get_selected (EMemoTable *memo_table) +{ + struct get_selected_uids_closure closure; + ETable *etable; + + closure.memo_table = memo_table; + closure.objects = NULL; + + etable = e_memo_table_get_table (memo_table); + e_table_selected_row_foreach (etable, add_uid_cb, &closure); + + return closure.objects; +} + +/** * e_memo_table_cut_clipboard: * @memo_table: A calendar table. * @@ -538,12 +972,33 @@ e_memo_table_cut_clipboard (EMemoTable *memo_table) delete_selected_components (memo_table); } +static void +clipboard_get_calendar_cb (GtkClipboard *clipboard, + GtkSelectionData *selection_data, + guint info, + gpointer data) +{ + gchar *comp_str = (gchar *) data; + + switch (info) { + case TARGET_TYPE_VCALENDAR: + gtk_selection_data_set (selection_data, + gdk_atom_intern (target_types[info].target, FALSE), 8, + (const guchar *) comp_str, + (gint) strlen (comp_str)); + break; + default: + break; + } +} + /* callback for e_table_selected_row_foreach */ static void copy_row_cb (gint model_row, gpointer data) { EMemoTable *memo_table; ECalModelComponent *comp_data; + ECalModel *model; gchar *comp_str; icalcomponent *child; @@ -551,7 +1006,8 @@ copy_row_cb (gint model_row, gpointer data) g_return_if_fail (memo_table->tmp_vcal != NULL); - comp_data = e_cal_model_get_component_at (memo_table->model, model_row); + model = e_memo_table_get_model (memo_table); + comp_data = e_cal_model_get_component_at (model, model_row); if (!comp_data) return; @@ -569,26 +1025,6 @@ copy_row_cb (gint model_row, gpointer data) g_free (comp_str); } -static void -clipboard_get_calendar_cb (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - guint info, - gpointer data) -{ - gchar *comp_str = (gchar *) data; - - switch (info) { - case TARGET_TYPE_VCALENDAR: - gtk_selection_data_set (selection_data, - gdk_atom_intern (target_types[info].target, FALSE), 8, - (const guchar *) comp_str, - (gint) strlen (comp_str)); - break; - default: - break; - } -} - /** * e_memo_table_copy_clipboard: * @memo_table: A calendar table. @@ -607,7 +1043,7 @@ e_memo_table_copy_clipboard (EMemoTable *memo_table) /* create temporary VCALENDAR object */ memo_table->tmp_vcal = e_cal_util_new_top_level (); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); + etable = e_memo_table_get_table (memo_table); e_table_selected_row_foreach (etable, copy_row_cb, memo_table); comp_str = icalcomponent_as_ical_string_r (memo_table->tmp_vcal); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (memo_table), clipboard_atom); @@ -632,7 +1068,9 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) gchar *uid; ECalComponent *comp; ECal *client; + ECalModel *model; icalcomponent_kind kind; + const gchar *status_message; g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); @@ -646,13 +1084,17 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) /* check the type of the component */ kind = icalcomponent_isa (icalcomp); if (kind != ICAL_VCALENDAR_COMPONENT && + kind != ICAL_VEVENT_COMPONENT && + kind != ICAL_VTODO_COMPONENT && kind != ICAL_VJOURNAL_COMPONENT) { return; } - client = e_cal_model_get_default_client (memo_table->model); + model = e_memo_table_get_model (memo_table); + client = e_cal_model_get_default_client (model); - e_memo_table_set_status_message (memo_table, _("Updating objects")); + status_message = _("Updating objects"); + memo_table_emit_status_message (memo_table, status_message, -1.0); if (kind == ICAL_VCALENDAR_COMPONENT) { icalcomponent_kind child_kind; @@ -664,7 +1106,9 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) vcal_comp, ICAL_ANY_COMPONENT); while (subcomp) { child_kind = icalcomponent_isa (subcomp); - if (child_kind == ICAL_VJOURNAL_COMPONENT) { + if (child_kind == ICAL_VEVENT_COMPONENT || + child_kind == ICAL_VTODO_COMPONENT || + child_kind == ICAL_VJOURNAL_COMPONENT) { ECalComponent *tmp_comp; uid = e_cal_component_gen_uid (); @@ -695,7 +1139,7 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) g_object_unref (comp); } - e_memo_table_set_status_message (memo_table, NULL); + memo_table_emit_status_message (memo_table, NULL, -1.0); } static void @@ -704,7 +1148,7 @@ clipboard_paste_received_cb (GtkClipboard *clipboard, gpointer data) { EMemoTable *memo_table = E_MEMO_TABLE (data); - ETable *e_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); + ETable *e_table = e_memo_table_get_table (memo_table); GnomeCanvas *canvas = e_table->table_canvas; GnomeCanvasItem *item = GNOME_CANVAS (canvas)->focused_item; @@ -739,335 +1183,44 @@ void e_memo_table_paste_clipboard (EMemoTable *memo_table) { GtkClipboard *clipboard; - g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - - - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (memo_table), clipboard_atom); - g_object_ref (memo_table); - - gtk_clipboard_request_contents (clipboard, - gdk_atom_intern (target_types[0].target, FALSE), - clipboard_paste_received_cb, memo_table); -} - -/* Opens a task in the task editor */ -static void -open_memo (EMemoTable *memo_table, ECalModelComponent *comp_data) -{ - CompEditor *medit; - const gchar *uid; - - uid = icalcomponent_get_uid (comp_data->icalcomp); - - medit = e_comp_editor_registry_find (comp_editor_registry, uid); - if (medit == NULL) { - ECalComponent *comp; - CompEditorFlags flags = 0; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - - if (e_cal_component_has_organizer (comp)) - flags |= COMP_EDITOR_IS_SHARED; - - if (itip_organizer_is_user (comp, comp_data->client)) - flags |= COMP_EDITOR_USER_ORG; - - medit = memo_editor_new (comp_data->client, flags); - - comp_editor_edit_comp (medit, comp); - g_object_unref (comp); - - e_comp_editor_registry_add (comp_editor_registry, medit, FALSE); - } - - gtk_window_present (GTK_WINDOW (medit)); -} - -/* Opens the task in the specified row */ -static void -open_memo_by_row (EMemoTable *memo_table, gint row) -{ - ECalModelComponent *comp_data; - - comp_data = e_cal_model_get_component_at (memo_table->model, row); - open_memo (memo_table, comp_data); -} - -static void -e_memo_table_on_double_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - EMemoTable *memo_table) -{ - open_memo_by_row (memo_table, row); -} - - -static void -e_memo_table_on_open_memo (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - - comp_data = get_selected_comp (memo_table); - if (comp_data) - open_memo (memo_table, comp_data); -} - -static void -e_memo_table_on_save_as (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - gchar *filename; - gchar *ical_string; - - comp_data = get_selected_comp (memo_table); - if (comp_data == NULL) - return; - - filename = e_file_dialog_save (_("Save as..."), NULL); - if (filename == NULL) - return; - - ical_string = e_cal_get_component_as_string (comp_data->client, comp_data->icalcomp); - if (ical_string == NULL) { - g_warning ("Couldn't convert item to a string"); - return; - } - - e_write_file_uri (filename, ical_string); - g_free (ical_string); -} - -static void -e_memo_table_on_print_memo (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - ECalComponent *comp; - - comp_data = get_selected_comp (memo_table); - if (comp_data == NULL) - return; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - print_comp (comp, comp_data->client, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); - - g_object_unref (comp); -} - -static void -e_memo_table_on_cut (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - e_memo_table_cut_clipboard (memo_table); -} - -static void -e_memo_table_on_copy (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - - e_memo_table_copy_clipboard (memo_table); -} - -static void -e_memo_table_on_paste (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - - e_memo_table_paste_clipboard (memo_table); -} - -static void -e_memo_table_on_forward (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - - comp_data = get_selected_comp (memo_table); - if (comp_data) { - ECalComponent *comp; - - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - itip_send_comp (E_CAL_COMPONENT_METHOD_PUBLISH, comp, comp_data->client, NULL, NULL, NULL, TRUE); - - g_object_unref (comp); - } -} - -/* Opens the URL of the memo */ -static void -open_url_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - icalproperty *prop; - - comp_data = get_selected_comp (memo_table); - if (!comp_data) - return; - - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_URL_PROPERTY); - if (!prop) - return; - - /* FIXME Pass a parent window. */ - e_show_uri (NULL, icalproperty_get_url (prop)); -} - -/* Callback for the "delete tasks" menu item */ -static void -delete_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - - e_memo_table_delete_selected (memo_table); -} - -static EPopupItem memos_popup_items [] = { - { E_POPUP_ITEM, (gchar *) "00.open", (gchar *) N_("_Open"), e_memo_table_on_open_memo, NULL, (gchar *) GTK_STOCK_OPEN, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, (gchar *) "05.openweb", (gchar *) N_("Open _Web Page"), open_url_cb, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_HASURL }, - { E_POPUP_ITEM, (gchar *) "10.saveas", (gchar *) N_("_Save As..."), e_memo_table_on_save_as, NULL, (gchar *) GTK_STOCK_SAVE_AS, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, (gchar *) "20.print", (gchar *) N_("P_rint..."), e_memo_table_on_print_memo, NULL, (gchar *) GTK_STOCK_PRINT, E_CAL_POPUP_SELECT_ONE }, - - { E_POPUP_BAR, (gchar *) "30.bar" }, - - { E_POPUP_ITEM, (gchar *) "40.cut", (gchar *) N_("C_ut"), e_memo_table_on_cut, NULL, (gchar *) GTK_STOCK_CUT, 0, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, (gchar *) "50.copy", (gchar *) N_("_Copy"), e_memo_table_on_copy, NULL, (gchar *) GTK_STOCK_COPY, 0, 0 }, - { E_POPUP_ITEM, (gchar *) "60.paste", (gchar *) N_("_Paste"), e_memo_table_on_paste, NULL, (gchar *) GTK_STOCK_PASTE, 0, E_CAL_POPUP_SELECT_EDITABLE }, - - { E_POPUP_BAR, (gchar *) "70.bar" }, - - { E_POPUP_ITEM, (gchar *) "80.forward", (gchar *) N_("_Forward as iCalendar"), e_memo_table_on_forward, NULL, (gchar *) "mail-forward", E_CAL_POPUP_SELECT_ONE }, - - { E_POPUP_BAR, (gchar *) "90.bar" }, - - { E_POPUP_ITEM, (gchar *) "a0.delete", (gchar *) N_("_Delete"), delete_cb, NULL, (gchar *) GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, (gchar *) "b0.deletemany", (gchar *) N_("_Delete Selected Memos"), delete_cb, NULL, (gchar *) GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_MANY, E_CAL_POPUP_SELECT_EDITABLE }, -}; - -static void -emt_popup_free(EPopup *ep, GSList *items, gpointer data) -{ - g_slist_free(items); -} - -static gint -e_memo_table_show_popup_menu (ETable *table, - GdkEvent *gdk_event, - EMemoTable *memo_table) -{ - GtkMenu *menu; - GSList *selection, *l, *menus = NULL; - GPtrArray *events; - ECalPopup *ep; - ECalPopupTargetSelect *t; - gint i; - - selection = get_selected_objects (memo_table); - if (!selection) - return TRUE; - - /** @HookPoint-ECalPopup: Tasks Table Context Menu - * @Id: org.gnome.evolution.tasks.table.popup - * @Class: org.gnome.evolution.calendar.popup:1.0 - * @Target: ECalPopupTargetSelect - * - * The context menu on the tasks table. - */ - ep = e_cal_popup_new("org.gnome.evolution.memos.table.popup"); - - events = g_ptr_array_new(); - for (l=selection;l;l=g_slist_next(l)) - g_ptr_array_add(events, e_cal_model_copy_component_data((ECalModelComponent *)l->data)); - g_slist_free(selection); - - t = e_cal_popup_target_new_select(ep, memo_table->model, events); - t->target.widget = (GtkWidget *)memo_table; - - for (i=0;i<sizeof(memos_popup_items)/sizeof(memos_popup_items[0]);i++) - menus = g_slist_prepend(menus, &memos_popup_items[i]); - e_popup_add_items((EPopup *)ep, menus, NULL, emt_popup_free, memo_table); - - menu = e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0); - - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, gdk_event?gdk_event->button.button:0, - gdk_event?gdk_event->button.time:gtk_get_current_event_time()); - - return TRUE; -} - -static gint -e_memo_table_on_right_click (ETable *table, - gint row, - gint col, - GdkEvent *event, - EMemoTable *memo_table) -{ - return e_memo_table_show_popup_menu (table, event, memo_table); -} + g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); -static gboolean -e_memo_table_on_popup_menu (GtkWidget *widget, gpointer data) -{ - ETable *table = E_TABLE(widget); - g_return_val_if_fail(table, FALSE); + clipboard = gtk_widget_get_clipboard ( + GTK_WIDGET (memo_table), clipboard_atom); - return e_memo_table_show_popup_menu (table, NULL, - E_MEMO_TABLE(data)); -} - -static gint -e_memo_table_on_key_press (ETable *table, - gint row, - gint col, - GdkEventKey *event, - EMemoTable *memo_table) -{ - if (event->keyval == GDK_Delete) { - delete_cb (NULL, NULL, memo_table); - return TRUE; - } else if ((event->keyval == GDK_o) - &&(event->state & GDK_CONTROL_MASK)) { - open_memo_by_row (memo_table, row); - return TRUE; - } - - return FALSE; + gtk_clipboard_request_contents ( + clipboard, gdk_atom_intern (target_types[0].target, FALSE), + clipboard_paste_received_cb, g_object_ref (memo_table)); } /* Loads the state of the table (headers shown etc.) from the given file. */ void e_memo_table_load_state (EMemoTable *memo_table, - gchar *filename) + const gchar *filename) { - struct stat st; + ETable *table; g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); + g_return_if_fail (filename != NULL); - if (g_stat (filename, &st) == 0 && st.st_size > 0 - && S_ISREG (st.st_mode)) { - e_table_load_state (e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)), filename); - } + table = e_memo_table_get_table (memo_table); + e_table_load_state (table, filename); } /* Saves the state of the table (headers shown etc.) to the given file. */ void -e_memo_table_save_state (EMemoTable *memo_table, - gchar *filename) +e_memo_table_save_state (EMemoTable *memo_table, + const gchar *filename) { + ETable *table; + g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); + g_return_if_fail (filename != NULL); - e_table_save_state (e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)), - filename); + table = e_memo_table_get_table (memo_table); + e_table_save_state (table, filename); } /* Returns the current time, for the ECellDateEdit items. @@ -1096,45 +1249,3 @@ e_memo_table_get_current_time (ECellDateEdit *ecde, gpointer data) return tmp_tm; } - - -#ifdef TRANSLATORS_ONLY - -static gchar *test[] = { - N_("Click to add a memo") -}; - -#endif - -void -e_memo_table_set_activity_handler (EMemoTable *memo_table, EActivityHandler *activity_handler) -{ - g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - - memo_table->activity_handler = activity_handler; -} - -void -e_memo_table_set_status_message (EMemoTable *memo_table, const gchar *message) -{ - g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - - if (!memo_table->activity_handler) - return; - - if (!message || !*message) { - if (memo_table->activity_id != 0) { - e_activity_handler_operation_finished (memo_table->activity_handler, memo_table->activity_id); - memo_table->activity_id = 0; - } - } else if (memo_table->activity_id == 0) { - gchar *client_id = g_strdup_printf ("%p", (gpointer) memo_table); - - memo_table->activity_id = e_activity_handler_operation_started ( - memo_table->activity_handler, client_id, message, TRUE); - - g_free (client_id); - } else { - e_activity_handler_operation_progressing (memo_table->activity_handler, memo_table->activity_id, message, -1.0); - } -} diff --git a/calendar/gui/e-memo-table.h b/calendar/gui/e-memo-table.h index b593b9445b..f3b02e0c04 100644 --- a/calendar/gui/e-memo-table.h +++ b/calendar/gui/e-memo-table.h @@ -25,34 +25,47 @@ #ifndef _E_MEMO_TABLE_H_ #define _E_MEMO_TABLE_H_ -#include <gtk/gtk.h> +#include <shell/e-shell-view.h> #include <table/e-table-scrolled.h> -#include <widgets/misc/e-cell-date-edit.h> -#include "e-activity-handler.h" +#include <table/e-cell-date-edit.h> #include "e-cal-model.h" -G_BEGIN_DECLS - /* * EMemoTable - displays the iCalendar objects in a table (an ETable). * Used for memo events and tasks. + * + * XXX We should look at merging this back into ECalendarTable, or at + * least making ECalendarTable subclassable so we don't have so + * much duplicate code. */ +/* Standard GObject macros */ +#define E_TYPE_MEMO_TABLE \ + (e_memo_table_get_type ()) +#define E_MEMO_TABLE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MEMO_TABLE, EMemoTable)) +#define E_MEMO_TABLE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MEMO_TABLE, EMemoTableClass)) +#define E_IS_MEMO_TABLE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MEMO_TABLE)) +#define E_IS_MEMO_TABLE_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MEMO_TABLE)) +#define E_MEMO_TABLE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MEMO_TABLE, EMemoTableClass)) -#define E_MEMO_TABLE(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, e_memo_table_get_type (), EMemoTable) -#define E_MEMO_TABLE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, e_memo_table_get_type (), EMemoTableClass) -#define E_IS_MEMO_TABLE(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, e_memo_table_get_type ()) - - -typedef struct _EMemoTable EMemoTable; -typedef struct _EMemoTableClass EMemoTableClass; +G_BEGIN_DECLS +typedef struct _EMemoTable EMemoTable; +typedef struct _EMemoTableClass EMemoTableClass; +typedef struct _EMemoTablePrivate EMemoTablePrivate; struct _EMemoTable { - GtkTable table; - - /* The model that we use */ - ECalModel *model; + GtkTable parent; GtkWidget *etable; @@ -62,51 +75,43 @@ struct _EMemoTable { /* Fields used for cut/copy/paste */ icalcomponent *tmp_vcal; - /* Activity ID for the EActivityHandler (i.e. the status bar). */ - EActivityHandler *activity_handler; - guint activity_id; - - /* We should know which calendar has been used to create object, so store it here - before emitting "user_created" signal and make it NULL just after the emit. */ - ECal *user_created_cal; + EMemoTablePrivate *priv; }; struct _EMemoTableClass { GtkTableClass parent_class; - /* Notification signals */ - void (* user_created) (EMemoTable *memo_table); + /* Signals */ + void (*open_component) (EMemoTable *memo_table, + ECalModelComponent *comp_data); + void (*popup_event) (EMemoTable *memo_table, + GdkEvent *event); + void (*status_message) (EMemoTable *memo_table, + const gchar *message, + gdouble percent); + void (*user_created) (EMemoTable *memo_table); }; - -GType e_memo_table_get_type (void); -GtkWidget* e_memo_table_new (void); - -ECalModel *e_memo_table_get_model (EMemoTable *memo_table); - -ETable *e_memo_table_get_table (EMemoTable *memo_table); - -void e_memo_table_open_selected (EMemoTable *memo_table); -void e_memo_table_delete_selected (EMemoTable *memo_table); - -GSList *e_memo_table_get_selected (EMemoTable *memo_table); +GType e_memo_table_get_type (void); +GtkWidget * e_memo_table_new (EShellView *shell_view, + ECalModel *model); +ECalModel * e_memo_table_get_model (EMemoTable *memo_table); +ETable * e_memo_table_get_table (EMemoTable *memo_table); +EShellView * e_memo_table_get_shell_view (EMemoTable *memo_table); +void e_memo_table_delete_selected (EMemoTable *memo_table); +GSList * e_memo_table_get_selected (EMemoTable *memo_table); /* Clipboard related functions */ -void e_memo_table_cut_clipboard (EMemoTable *memo_table); -void e_memo_table_copy_clipboard (EMemoTable *memo_table); -void e_memo_table_paste_clipboard (EMemoTable *memo_table); +void e_memo_table_cut_clipboard (EMemoTable *memo_table); +void e_memo_table_copy_clipboard (EMemoTable *memo_table); +void e_memo_table_paste_clipboard (EMemoTable *memo_table); /* These load and save the state of the table (headers shown etc.) to/from the given file. */ -void e_memo_table_load_state (EMemoTable *memo_table, - gchar *filename); -void e_memo_table_save_state (EMemoTable *memo_table, - gchar *filename); - -void e_memo_table_set_activity_handler (EMemoTable *memo_table, - EActivityHandler *activity_handler); -void e_memo_table_set_status_message (EMemoTable *memo_table, - const gchar *message); +void e_memo_table_load_state (EMemoTable *memo_table, + const gchar *filename); +void e_memo_table_save_state (EMemoTable *memo_table, + const gchar *filename); G_END_DECLS diff --git a/calendar/gui/e-memos.c b/calendar/gui/e-memos.c index 4b8d234cee..3ac375abba 100644 --- a/calendar/gui/e-memos.c +++ b/calendar/gui/e-memos.c @@ -38,7 +38,6 @@ #include "e-util/e-error.h" #include "e-util/e-categories-config.h" #include "e-util/e-util-private.h" -#include "shell/e-user-creatable-items-handler.h" #include <libecal/e-cal-time-util.h> #include <libedataserver/e-url.h> #include <libedataserver/e-categories.h> @@ -46,11 +45,9 @@ #include "dialogs/delete-error.h" #include "calendar-config.h" #include "cal-search-bar.h" -#include "calendar-component.h" #include "comp-util.h" #include "e-memo-table-config.h" #include "misc.h" -#include "memos-component.h" #include "e-cal-component-memo-preview.h" #include "e-memos.h" #include "common/authentication.h" @@ -72,9 +69,6 @@ struct _EMemosPrivate { /* Calendar search bar for memos */ GtkWidget *search_bar; - /* Paned widget */ - GtkWidget *paned; - /* The preview */ GtkWidget *preview; @@ -93,7 +87,6 @@ static void e_memos_destroy (GtkObject *object); static void update_view (EMemos *memos); static void categories_changed_cb (gpointer object, gpointer user_data); -static void backend_error_cb (ECal *client, const gchar *message, gpointer data); /* Signal IDs */ enum { @@ -103,100 +96,10 @@ enum { LAST_SIGNAL }; -enum DndTargetType { - TARGET_VCALENDAR -}; - -static GtkTargetEntry list_drag_types[] = { - { (gchar *) "text/calendar", 0, TARGET_VCALENDAR }, - { (gchar *) "text/x-calendar", 0, TARGET_VCALENDAR } -}; -static const gint num_list_drag_types = sizeof (list_drag_types) / sizeof (list_drag_types[0]); - static guint e_memos_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (EMemos, e_memos, GTK_TYPE_TABLE) -/* Callback used when the cursor changes in the table */ -static void -table_cursor_change_cb (ETable *etable, gint row, gpointer data) -{ - EMemos *memos; - EMemosPrivate *priv; - ECalModel *model; - ECalModelComponent *comp_data; - ECalComponent *comp; - const gchar *uid; - - gint n_selected; - - memos = E_MEMOS (data); - priv = memos->priv; - - n_selected = e_table_selected_count (etable); - - /* update the HTML widget */ - if (n_selected != 1) { - e_cal_component_memo_preview_clear (E_CAL_COMPONENT_MEMO_PREVIEW (priv->preview)); - - return; - } - - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - - comp_data = e_cal_model_get_component_at (model, e_table_get_cursor_row (etable)); - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - - e_cal_component_memo_preview_display (E_CAL_COMPONENT_MEMO_PREVIEW (priv->preview), comp_data->client, comp); - - e_cal_component_get_uid (comp, &uid); - if (priv->current_uid) - g_free (priv->current_uid); - priv->current_uid = g_strdup (uid); - - g_object_unref (comp); -} - -/* Callback used when the selection changes in the table. */ -static void -table_selection_change_cb (ETable *etable, gpointer data) -{ - EMemos *memos; - gint n_selected; - - memos = E_MEMOS (data); - - n_selected = e_table_selected_count (etable); - g_signal_emit (memos, e_memos_signals[SELECTION_CHANGED], 0, n_selected); - - if (n_selected != 1) - e_cal_component_memo_preview_clear (E_CAL_COMPONENT_MEMO_PREVIEW (memos->priv->preview)); - -} - -static void -user_created_cb (GtkWidget *view, EMemos *memos) -{ - EMemosPrivate *priv; - EMemoTable *memo_table; - ECal *ecal; - - priv = memos->priv; - memo_table = E_MEMO_TABLE (priv->memos_view); - - if (memo_table->user_created_cal) - ecal = memo_table->user_created_cal; - else { - ECalModel *model; - - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - ecal = e_cal_model_get_default_client (model); - } - - e_memos_add_memo_source (memos, e_cal_get_source (ecal)); -} - /* Callback used when the sexp in the search bar changes */ static void search_bar_sexp_changed_cb (CalSearchBar *cal_search, const gchar *sexp, gpointer data) @@ -230,14 +133,6 @@ search_bar_category_changed_cb (CalSearchBar *cal_search, const gchar *category, e_cal_model_set_default_category (model, category); } -static gboolean -vpaned_resized_cb (GtkWidget *widget, GdkEventButton *event, EMemos *memos) -{ - calendar_config_set_task_vpane_pos (gtk_paned_get_position (GTK_PANED (widget))); - - return FALSE; -} - static void set_timezone (EMemos *memos) { @@ -256,10 +151,6 @@ set_timezone (EMemos *memos) e_cal_set_default_timezone (client, zone, NULL); } - if (priv->default_client && e_cal_get_load_state (priv->default_client) == E_CAL_LOAD_LOADED) - /* FIXME Error checking */ - e_cal_set_default_timezone (priv->default_client, zone, NULL); - if (priv->preview) e_cal_component_memo_preview_set_default_timezone (E_CAL_COMPONENT_MEMO_PREVIEW (priv->preview), zone); } @@ -288,33 +179,6 @@ update_view (EMemos *memos) } static void -model_row_changed_cb (ETableModel *etm, gint row, gpointer data) -{ - EMemos *memos; - EMemosPrivate *priv; - ECalModelComponent *comp_data; - - memos = E_MEMOS (data); - priv = memos->priv; - - if (priv->current_uid) { - const gchar *uid; - - comp_data = e_cal_model_get_component_at (E_CAL_MODEL (etm), row); - if (comp_data) { - uid = icalcomponent_get_uid (comp_data->icalcomp); - if (!strcmp (uid ? uid : "", priv->current_uid)) { - ETable *etable; - - etable = e_table_scrolled_get_table ( - E_TABLE_SCROLLED (E_MEMO_TABLE (priv->memos_view)->etable)); - table_cursor_change_cb (etable, 0, memos); - } - } - } -} - -static void setup_config (EMemos *memos) { EMemosPrivate *priv; @@ -329,155 +193,6 @@ setup_config (EMemos *memos) priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); } -struct AffectedComponents { - EMemoTable *memo_table; - GSList *components; /* contains pointers to ECalModelComponent */ -}; - -/** - * get_selected_components_cb - * Helper function to fill list of selected components in EMemoTable. - * This function is called from e_table_selected_row_foreach. - **/ -static void -get_selected_components_cb (gint model_row, gpointer data) -{ - struct AffectedComponents *ac = (struct AffectedComponents *) data; - - if (!ac || !ac->memo_table) - return; - - ac->components = g_slist_prepend (ac->components, e_cal_model_get_component_at (E_CAL_MODEL (e_memo_table_get_model (ac->memo_table)), model_row)); -} - -/** - * do_for_selected_components - * Calls function func for all selected components in memo_table. - * - * @param memo_table Table with selected components of our interest. - * @param func Function to be called on each selected component from cal_table. - * The first parameter of this function is a pointer to ECalModelComponent and - * the second parameter of this function is pointer to cal_table - * @param user_data User data, will be passed to func. - **/ -static void -do_for_selected_components (EMemoTable *memo_table, GFunc func, gpointer user_data) -{ - ETable *etable; - struct AffectedComponents ac; - - g_return_if_fail (memo_table != NULL); - - ac.memo_table = memo_table; - ac.components = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); - e_table_selected_row_foreach (etable, get_selected_components_cb, &ac); - - g_slist_foreach (ac.components, func, user_data); - g_slist_free (ac.components); -} - -/** - * obtain_list_of_components - * As a callback function to convert each ECalModelComponent to string - * of format "source_uid\ncomponent_str" and add this newly allocated - * string to the list of components. Strings should be freed with g_free. - * - * @param data ECalModelComponent object. - * @param user_data Pointer to GSList list, where to put new strings. - **/ -static void -obtain_list_of_components (gpointer data, gpointer user_data) -{ - GSList **list; - ECalModelComponent *comp_data; - - list = (GSList **) user_data; - comp_data = (ECalModelComponent *) data; - - if (list && comp_data) { - gchar *comp_str; - icalcomponent *vcal; - - vcal = e_cal_util_new_top_level (); - e_cal_util_add_timezones_from_component (vcal, comp_data->icalcomp); - icalcomponent_add_component (vcal, icalcomponent_new_clone (comp_data->icalcomp)); - - comp_str = icalcomponent_as_ical_string_r (vcal); - if (comp_str) { - ESource *source = e_cal_get_source (comp_data->client); - const gchar *source_uid = e_source_peek_uid (source); - - *list = g_slist_prepend (*list, g_strdup_printf ("%s\n%s", source_uid, comp_str)); - - /* do not free this pointer, it owns libical */ - /* g_free (comp_str); */ - } - - icalcomponent_free (vcal); - g_free (comp_str); - } -} - -static void -table_drag_data_get (ETable *table, - gint row, - gint col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EMemos *memos) -{ - EMemosPrivate *priv; - - priv = memos->priv; - - if (info == TARGET_VCALENDAR) { - /* we will pass an icalcalendar component for both types */ - GSList *components = NULL; - - do_for_selected_components (E_MEMO_TABLE (priv->memos_view), obtain_list_of_components, &components); - - if (components) { - cal_comp_selection_set_string_list (selection_data, components); - - g_slist_foreach (components, (GFunc)g_free, NULL); - g_slist_free (components); - } - } -} - -static void -table_drag_data_delete (ETable *table, - gint row, - gint col, - GdkDragContext *context, - EMemos *memos) -{ - /* Moved components are deleted from source immediately when moved, - because some of them can be part of destination source, and we - don't want to delete not-moved tasks. There is no such information - which event has been moved and which not, so skip this method. - */ -} - -#define E_MEMOS_TABLE_DEFAULT_STATE \ - "<?xml version=\"1.0\"?>" \ - "<ETableState>" \ - "<column source=\"1\"/>" \ - "<column source=\"0\"/>" \ - "<column source=\"2\"/>" \ - "<grouping></grouping>" \ - "</ETableState>" - -static void -pane_realized (GtkWidget *widget, EMemos *memos) -{ - gtk_paned_set_position ((GtkPaned *)widget, calendar_config_get_task_vpane_pos ()); -} - static void setup_widgets (EMemos *memos) { @@ -499,51 +214,12 @@ setup_widgets (EMemos *memos) GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0, 0); gtk_widget_show (priv->search_bar); - /* add the paned widget for the memo list and memo detail areas */ - priv->paned = gtk_vpaned_new (); - g_signal_connect (priv->paned, "realize", G_CALLBACK (pane_realized), memos); - - g_signal_connect (G_OBJECT (priv->paned), "button_release_event", - G_CALLBACK (vpaned_resized_cb), memos); - gtk_table_attach (GTK_TABLE (memos), priv->paned, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (priv->paned); - /* create the memo list */ priv->memos_view = e_memo_table_new (); priv->memos_view_config = e_memo_table_config_new (E_MEMO_TABLE (priv->memos_view)); - g_signal_connect (priv->memos_view, "user_created", G_CALLBACK (user_created_cb), memos); - - etable = e_table_scrolled_get_table ( - E_TABLE_SCROLLED (E_MEMO_TABLE (priv->memos_view)->etable)); - e_table_set_state (etable, E_MEMOS_TABLE_DEFAULT_STATE); - - gtk_paned_add1 (GTK_PANED (priv->paned), priv->memos_view); - gtk_widget_show (priv->memos_view); - - - e_table_drag_source_set (etable, GDK_BUTTON1_MASK, - list_drag_types, num_list_drag_types, - GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_ASK); - g_signal_connect (etable, "table_drag_data_get", G_CALLBACK(table_drag_data_get), memos); - g_signal_connect (etable, "table_drag_data_delete", - G_CALLBACK(table_drag_data_delete), memos); - - g_signal_connect (etable, "cursor_change", G_CALLBACK (table_cursor_change_cb), memos); - g_signal_connect (etable, "selection_change", G_CALLBACK (table_selection_change_cb), memos); - - /* create the memo detail */ - priv->preview = e_cal_component_memo_preview_new (); - e_cal_component_memo_preview_set_default_timezone (E_CAL_COMPONENT_MEMO_PREVIEW (priv->preview), calendar_config_get_icaltimezone ()); - gtk_paned_add2 (GTK_PANED (priv->paned), priv->preview); - gtk_widget_show (priv->preview); - - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - g_signal_connect (G_OBJECT (model), "model_row_changed", - G_CALLBACK (model_row_changed_cb), memos); } /* Class initialization function for the gnome calendar */ @@ -637,32 +313,9 @@ e_memos_init (EMemos *memos) priv->view_menus = NULL; priv->current_uid = NULL; priv->sexp = g_strdup ("#t"); - priv->default_client = NULL; update_view (memos); } -GtkWidget * -e_memos_new (void) -{ - EMemos *memos; - - memos = g_object_new (e_memos_get_type (), NULL); - - return GTK_WIDGET (memos); -} - - -void -e_memos_set_ui_component (EMemos *memos, - BonoboUIComponent *ui_component) -{ - g_return_if_fail (E_IS_MEMOS (memos)); - g_return_if_fail (ui_component == NULL || BONOBO_IS_UI_COMPONENT (ui_component)); - - e_search_bar_set_ui_component (E_SEARCH_BAR (memos->priv->search_bar), ui_component); -} - - static void e_memos_destroy (GtkObject *object) { @@ -689,10 +342,6 @@ e_memos_destroy (GtkObject *object) g_hash_table_destroy (priv->clients); g_list_free (priv->clients_list); - if (priv->default_client) - g_object_unref (priv->default_client); - priv->default_client = NULL; - if (priv->current_uid) { g_free (priv->current_uid); priv->current_uid = NULL; @@ -720,325 +369,6 @@ e_memos_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (e_memos_parent_class)->destroy) (object); } -static void -set_status_message (EMemos *memos, const gchar *message, ...) -{ - EMemosPrivate *priv; - va_list args; - gchar sz[2048], *msg_string = NULL; - - if (message) { - va_start (args, message); - vsnprintf (sz, sizeof sz, message, args); - va_end (args); - msg_string = sz; - } - - priv = memos->priv; - - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memos_view), msg_string); -} - -/* Callback from the calendar client when an error occurs in the backend */ -static void -backend_error_cb (ECal *client, const gchar *message, gpointer data) -{ - EMemos *memos; - GtkWidget *dialog; - gchar *urinopwd; - - memos = E_MEMOS (data); - - urinopwd = get_uri_without_password (e_cal_get_uri (client)); - - dialog = gtk_message_dialog_new ( - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (memos))), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("Error on %s:\n %s"), urinopwd, message); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_free (urinopwd); -} - -/* Callback from the calendar client when the backend dies */ -static void -backend_died_cb (ECal *client, gpointer data) -{ - EMemos *memos; - EMemosPrivate *priv; - ESource *source; - - memos = E_MEMOS (data); - priv = memos->priv; - - source = g_object_ref (e_cal_get_source (client)); - - priv->clients_list = g_list_remove (priv->clients_list, client); - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (memos, e_memos_signals[SOURCE_REMOVED], 0, source); - - e_memo_table_set_status_message (E_MEMO_TABLE (e_memos_get_calendar_table (memos)), NULL); - - e_error_run (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (memos))), - "calendar:memos-crashed", NULL); - - g_object_unref (source); -} - -/* Callback from the calendar client when the calendar is opened */ -static void -client_cal_opened_cb (ECal *ecal, ECalendarStatus status, EMemos *memos) -{ - ECalModel *model; - ESource *source; - EMemosPrivate *priv; - - priv = memos->priv; - - source = e_cal_get_source (ecal); - - if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) - auth_cal_forget_password (ecal); - - switch (status) { - case E_CALENDAR_STATUS_OK : - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, client_cal_opened_cb, NULL); - - set_status_message (memos, _("Loading memos")); - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - e_cal_model_add_client (model, ecal); - - set_timezone (memos); - set_status_message (memos, NULL); - break; - case E_CALENDAR_STATUS_AUTHENTICATION_FAILED: - /* try to reopen calendar - it'll ask for a password once again */ - e_cal_open_async (ecal, FALSE); - return; - case E_CALENDAR_STATUS_BUSY : - break; - case E_CALENDAR_STATUS_REPOSITORY_OFFLINE: - e_error_run (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (memos))), "calendar:prompt-no-contents-offline-memos", NULL); - default : - /* Make sure the source doesn't disappear on us */ - g_object_ref (source); - - priv->clients_list = g_list_remove (priv->clients_list, ecal); - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, memos); - - /* Do this last because it unrefs the client */ - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (memos, e_memos_signals[SOURCE_REMOVED], 0, source); - - set_status_message (memos, NULL); - g_object_unref (source); - - break; - } -} - -static void -default_client_cal_opened_cb (ECal *ecal, ECalendarStatus status, EMemos *memos) -{ - ECalModel *model; - ESource *source; - EMemosPrivate *priv; - - priv = memos->priv; - - source = e_cal_get_source (ecal); - - if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) - auth_cal_forget_password (ecal); - - switch (status) { - case E_CALENDAR_STATUS_OK : - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, default_client_cal_opened_cb, NULL); - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - - set_timezone (memos); - e_cal_model_set_default_client (model, ecal); - set_status_message (memos, NULL); - break; - case E_CALENDAR_STATUS_AUTHENTICATION_FAILED: - /* try to reopen calendar - it'll ask for a password once again */ - e_cal_open_async (ecal, FALSE); - return; - case E_CALENDAR_STATUS_BUSY: - break; - default : - /* Make sure the source doesn't disappear on us */ - g_object_ref (source); - - priv->clients_list = g_list_remove (priv->clients_list, ecal); - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, memos); - - /* Do this last because it unrefs the client */ - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (memos, e_memos_signals[SOURCE_REMOVED], 0, source); - - set_status_message (memos, NULL); - g_object_unref (priv->default_client); - priv->default_client = NULL; - g_object_unref (source); - - break; - } -} - -typedef void (*open_func) (ECal *, ECalendarStatus, EMemos *); - -static gboolean -open_ecal (EMemos *memos, ECal *cal, gboolean only_if_exists, open_func of) -{ - set_status_message (memos, _("Opening memos at %s"), e_cal_get_uri (cal)); - - g_signal_connect (G_OBJECT (cal), "cal_opened", G_CALLBACK (of), memos); - e_cal_open_async (cal, only_if_exists); - - return TRUE; -} - -void -e_memos_open_memo (EMemos *memos) -{ - EMemoTable *cal_table; - - cal_table = e_memos_get_calendar_table (memos); - e_memo_table_open_selected (cal_table); -} - -void -e_memos_new_memo (EMemos *memos) -{ - /* used for click_to_add ?? Can't figure out anything else it's used for */ -} - -gboolean -e_memos_add_memo_source (EMemos *memos, ESource *source) -{ - EMemosPrivate *priv; - ECal *client; - const gchar *uid; - - g_return_val_if_fail (memos != NULL, FALSE); - g_return_val_if_fail (E_IS_MEMOS (memos), FALSE); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - priv = memos->priv; - - uid = e_source_peek_uid (source); - client = g_hash_table_lookup (priv->clients, uid); - if (client) { - /* We already have it */ - - return TRUE; - } else { - ESource *default_source; - - if (priv->default_client) { - default_source = e_cal_get_source (priv->default_client); - - /* We don't have it but the default client is it */ - if (!strcmp (e_source_peek_uid (default_source), uid)) - client = g_object_ref (priv->default_client); - } - - /* Create a new one */ - if (!client) { - client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_JOURNAL); - if (!client) - return FALSE; - } - } - - g_signal_connect (G_OBJECT (client), "backend_error", G_CALLBACK (backend_error_cb), memos); - g_signal_connect (G_OBJECT (client), "backend_died", G_CALLBACK (backend_died_cb), memos); - - /* add the client to internal structure */ - g_hash_table_insert (priv->clients, g_strdup (uid) , client); - priv->clients_list = g_list_prepend (priv->clients_list, client); - - g_signal_emit (memos, e_memos_signals[SOURCE_ADDED], 0, source); - - open_ecal (memos, client, FALSE, client_cal_opened_cb); - - return TRUE; -} - -gboolean -e_memos_remove_memo_source (EMemos *memos, ESource *source) -{ - EMemosPrivate *priv; - ECal *client; - ECalModel *model; - const gchar *uid; - - g_return_val_if_fail (memos != NULL, FALSE); - g_return_val_if_fail (E_IS_MEMOS (memos), FALSE); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - priv = memos->priv; - - uid = e_source_peek_uid (source); - client = g_hash_table_lookup (priv->clients, uid); - if (!client) - return TRUE; - - - priv->clients_list = g_list_remove (priv->clients_list, client); - g_signal_handlers_disconnect_matched (client, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, memos); - - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view)); - e_cal_model_remove_client (model, client); - - g_hash_table_remove (priv->clients, uid); - - - g_signal_emit (memos, e_memos_signals[SOURCE_REMOVED], 0, source); - - return TRUE; -} - -gboolean -e_memos_set_default_source (EMemos *memos, ESource *source) -{ - EMemosPrivate *priv; - ECal *ecal; - - g_return_val_if_fail (memos != NULL, FALSE); - g_return_val_if_fail (E_IS_MEMOS (memos), FALSE); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - priv = memos->priv; - - ecal = g_hash_table_lookup (priv->clients, e_source_peek_uid (source)); - - if (priv->default_client) - g_object_unref (priv->default_client); - - if (ecal) { - priv->default_client = g_object_ref (ecal); - } else { - priv->default_client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_JOURNAL); - if (!priv->default_client) - return FALSE; - } - - open_ecal (memos, priv->default_client, FALSE, default_client_cal_opened_cb); - - return TRUE; -} - ECal * e_memos_get_default_client (EMemos *memos) { @@ -1051,188 +381,3 @@ e_memos_get_default_client (EMemos *memos) return e_cal_model_get_default_client (e_memo_table_get_model (E_MEMO_TABLE (priv->memos_view))); } - - -/** - * e_memos_delete_selected: - * @memos: A memos control widget. - * - * Deletes the selected memos in the memo list. - **/ -void -e_memos_delete_selected (EMemos *memos) -{ - EMemosPrivate *priv; - EMemoTable *cal_table; - - g_return_if_fail (memos != NULL); - g_return_if_fail (E_IS_MEMOS (memos)); - - priv = memos->priv; - - cal_table = E_MEMO_TABLE (priv->memos_view); - set_status_message (memos, _("Deleting selected objects...")); - e_memo_table_delete_selected (cal_table); - set_status_message (memos, NULL); - - e_cal_component_memo_preview_clear (E_CAL_COMPONENT_MEMO_PREVIEW (priv->preview)); -} - - -/* Callback used from the view collection when we need to display a new view */ -static void -display_view_cb (GalViewInstance *instance, GalView *view, gpointer data) -{ - EMemos *memos; - - memos = E_MEMOS (data); - - if (GAL_IS_VIEW_ETABLE (view)) { - gal_view_etable_attach_table (GAL_VIEW_ETABLE (view), e_table_scrolled_get_table (E_TABLE_SCROLLED (E_MEMO_TABLE (memos->priv->memos_view)->etable))); - } - - gtk_paned_set_position ((GtkPaned *)memos->priv->paned, calendar_config_get_task_vpane_pos ()); -} - -/** - * e_memos_setup_view_menus: - * @memos: A memos widget. - * @uic: UI controller to use for the menus. - * - * Sets up the #GalView menus for a memos control. This function should be - * called from the Bonobo control activation callback for this memos control. - * Also, the menus should be discarded using e_memos_discard_view_menus(). - */ -void -e_memos_setup_view_menus (EMemos *memos, BonoboUIComponent *uic) -{ - EMemosPrivate *priv; - GalViewFactory *factory; - ETableSpecification *spec; - gchar *dir0, *dir1, *filename; - static GalViewCollection *collection = NULL; - - g_return_if_fail (memos != NULL); - g_return_if_fail (E_IS_MEMOS (memos)); - g_return_if_fail (uic != NULL); - g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); - - priv = memos->priv; - - g_return_if_fail (priv->view_instance == NULL); - - g_return_if_fail (priv->view_instance == NULL); - g_return_if_fail (priv->view_menus == NULL); - - /* Create the view instance */ - - if (collection == NULL) { - collection = gal_view_collection_new (); - - gal_view_collection_set_title (collection, _("Memos")); - - dir0 = g_build_filename (EVOLUTION_GALVIEWSDIR, - "memos", - NULL); - dir1 = g_build_filename (memos_component_peek_base_directory (memos_component_peek ()), - "views", NULL); - gal_view_collection_set_storage_directories (collection, - dir0, - dir1); - g_free (dir1); - g_free (dir0); - - /* Create the views */ - - spec = e_table_specification_new (); - filename = g_build_filename (EVOLUTION_ETSPECDIR, - "e-memo-table.etspec", - NULL); - if (!e_table_specification_load_from_file (spec, filename)) - g_error ("Unable to load ETable specification file " - "for memos"); - g_free (filename); - - factory = gal_view_factory_etable_new (spec); - g_object_unref (spec); - gal_view_collection_add_factory (collection, factory); - g_object_unref (factory); - - /* Load the collection and create the menus */ - - gal_view_collection_load (collection); - } - - priv->view_instance = gal_view_instance_new (collection, NULL); - - priv->view_menus = gal_view_menus_new (priv->view_instance); - gal_view_menus_apply (priv->view_menus, uic, NULL); - g_signal_connect (priv->view_instance, "display_view", G_CALLBACK (display_view_cb), memos); - display_view_cb (priv->view_instance, gal_view_instance_get_current_view (priv->view_instance), memos); -} - -/** - * e_memos_discard_view_menus: - * @memos: A memos widget. - * - * Discards the #GalView menus used by a memos control. This function should be - * called from the Bonobo control deactivation callback for this memos control. - * The menus should have been set up with e_memos_setup_view_menus(). - **/ -void -e_memos_discard_view_menus (EMemos *memos) -{ - EMemosPrivate *priv; - - g_return_if_fail (memos != NULL); - g_return_if_fail (E_IS_MEMOS (memos)); - - priv = memos->priv; - - g_return_if_fail (priv->view_instance != NULL); - - g_return_if_fail (priv->view_instance != NULL); - g_return_if_fail (priv->view_menus != NULL); - - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - - g_object_unref (priv->view_menus); - priv->view_menus = NULL; -} - -/** - * e_memos_get_calendar_table: - * @memos: A memos widget. - * - * Queries the #EMemoTable contained in a memos widget. - * - * Return value: The #EMemoTable that the memos widget uses to display its - * information. - **/ -EMemoTable * -e_memos_get_calendar_table (EMemos *memos) -{ - EMemosPrivate *priv; - - g_return_val_if_fail (memos != NULL, NULL); - g_return_val_if_fail (E_IS_MEMOS (memos), NULL); - - priv = memos->priv; - return E_MEMO_TABLE (priv->memos_view); -} - -/** - * e_memos_get_preview: - * @memos: A memos widget. - * - * Queries the #ECalComponentMemoPreview contained in a memos widget. - **/ -GtkWidget * -e_memos_get_preview (EMemos *memos) -{ - g_return_val_if_fail (memos != NULL, NULL); - g_return_val_if_fail (E_IS_MEMOS (memos), NULL); - - return memos->priv->preview; -} diff --git a/calendar/gui/e-memos.h b/calendar/gui/e-memos.h index 12aeea858e..2c0f69f87d 100644 --- a/calendar/gui/e-memos.h +++ b/calendar/gui/e-memos.h @@ -25,7 +25,6 @@ #ifndef _E_MEMOS_H_ #define _E_MEMOS_H_ -#include <bonobo/bonobo-ui-component.h> #include <gtk/gtk.h> #include <libedataserver/e-source.h> #include <libecal/e-cal.h> @@ -64,9 +63,6 @@ GtkWidget *e_memos_construct (EMemos *memos); GtkWidget *e_memos_new (void); -void e_memos_set_ui_component (EMemos *memos, - BonoboUIComponent *ui_component); - gboolean e_memos_add_memo_source (EMemos *memos, ESource *source); gboolean e_memos_remove_memo_source (EMemos *memos, ESource *source); gboolean e_memos_set_default_source (EMemos *memos, ESource *source); diff --git a/calendar/gui/e-task-list-selector.c b/calendar/gui/e-task-list-selector.c new file mode 100644 index 0000000000..fa6bd328d9 --- /dev/null +++ b/calendar/gui/e-task-list-selector.c @@ -0,0 +1,288 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-list-selector.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-task-list-selector.h" + +#include <string.h> +#include <libecal/e-cal.h> +#include "calendar/common/authentication.h" +#include "calendar/gui/comp-util.h" + +#define E_TASK_LIST_SELECTOR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_TASK_LIST_SELECTOR, ETaskListSelectorPrivate)) + +struct _ETaskListSelectorPrivate { + gint dummy_value; +}; + +enum { + DND_TARGET_TYPE_CALENDAR_LIST +}; + +static GtkTargetEntry drag_types[] = { + { (gchar *) "text/calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST }, + { (gchar *) "text/x-calendar", 0, DND_TARGET_TYPE_CALENDAR_LIST } +}; + +static gpointer parent_class; + +static gboolean +task_list_selector_update_single_object (ECal *client, + icalcomponent *icalcomp) +{ + gchar *uid; + icalcomponent *tmp_icalcomp; + + uid = (gchar *) icalcomponent_get_uid (icalcomp); + + if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, NULL)) + return e_cal_modify_object ( + client, icalcomp, CALOBJ_MOD_ALL, NULL); + + return e_cal_create_object (client, icalcomp, &uid, NULL); +} + +static gboolean +task_list_selector_update_objects (ECal *client, + icalcomponent *icalcomp) +{ + icalcomponent *subcomp; + icalcomponent_kind kind; + + kind = icalcomponent_isa (icalcomp); + if (kind == ICAL_VTODO_COMPONENT || kind == ICAL_VEVENT_COMPONENT) + return task_list_selector_update_single_object ( + client, icalcomp); + else if (kind != ICAL_VCALENDAR_COMPONENT) + return FALSE; + + subcomp = icalcomponent_get_first_component ( + icalcomp, ICAL_ANY_COMPONENT); + while (subcomp != NULL) { + gboolean success; + + kind = icalcomponent_isa (subcomp); + if (kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + + success = e_cal_add_timezone (client, zone, NULL); + icaltimezone_free (zone, 1); + if (!success) + return FALSE; + } else if (kind == ICAL_VTODO_COMPONENT || + kind == ICAL_VEVENT_COMPONENT) { + success = task_list_selector_update_single_object ( + client, subcomp); + if (!success) + return FALSE; + } + + subcomp = icalcomponent_get_next_component ( + icalcomp, ICAL_ANY_COMPONENT); + } + + return TRUE; +} + +static gboolean +task_list_selector_process_data (ESourceSelector *selector, + ECal *client, + const gchar *source_uid, + icalcomponent *icalcomp, + GdkDragAction action) +{ + ESourceList *source_list; + ESource *source; + icalcomponent *tmp_icalcomp = NULL; + const gchar *uid; + gchar *old_uid = NULL; + gboolean success = FALSE; + gboolean read_only = TRUE; + GError *error = NULL; + + /* FIXME Deal with GDK_ACTION_ASK. */ + if (action == GDK_ACTION_COPY) { + old_uid = g_strdup (icalcomponent_get_uid (icalcomp)); + uid = e_cal_component_gen_uid (); + icalcomponent_set_uid (icalcomp, uid); + } + + uid = icalcomponent_get_uid (icalcomp); + if (old_uid == NULL) + old_uid = g_strdup (uid); + + if (e_cal_get_object (client, uid, NULL, &tmp_icalcomp, &error)) { + icalcomponent_free (tmp_icalcomp); + success = TRUE; + goto exit; + } + + if (error != NULL && error->code != E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { + g_message ( + "Failed to search the object in destination " + "task list: %s", error->message); + g_error_free (error); + goto exit; + } + + success = task_list_selector_update_objects (client, icalcomp); + + if (!success || action != GDK_ACTION_MOVE) + goto exit; + + source_list = e_source_selector_get_source_list (selector); + source = e_source_list_peek_source_by_uid (source_list, source_uid); + + if (!E_IS_SOURCE (source) || e_source_get_readonly (source)) + goto exit; + + client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_TODO); + if (client == NULL) { + g_message ("Cannot create source client to remove old task"); + goto exit; + } + + e_cal_is_read_only (client, &read_only, NULL); + if (!read_only && e_cal_open (client, TRUE, NULL)) + e_cal_remove_object (client, old_uid, NULL); + else if (!read_only) + g_message ("Cannot open source client to remove old task"); + + g_object_unref (client); + +exit: + g_free (old_uid); + + return success; +} + +static gboolean +task_list_selector_data_dropped (ESourceSelector *selector, + GtkSelectionData *selection_data, + ESource *destination, + GdkDragAction action, + guint info) +{ + ECal *client; + GSList *list, *iter; + gboolean success = FALSE; + + client = auth_new_cal_from_source ( + destination, E_CAL_SOURCE_TYPE_TODO); + + if (client == NULL || !e_cal_open (client, TRUE, NULL)) + goto exit; + + list = cal_comp_selection_get_string_list (selection_data); + + for (iter = list; iter != NULL; iter = iter->next) { + gchar *source_uid = iter->data; + icalcomponent *icalcomp; + gchar *component_string; + + /* Each string is "source_uid\ncomponent_string". */ + component_string = strchr (source_uid, '\n'); + if (component_string == NULL) + continue; + + *component_string++ = '\0'; + icalcomp = icalparser_parse_string (component_string); + if (icalcomp == NULL) + continue; + + success = task_list_selector_process_data ( + selector, client, source_uid, icalcomp, action); + + icalcomponent_free (icalcomp); + } + + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); + +exit: + if (client != NULL) + g_object_unref (client); + + return success; +} + +static void +task_list_selector_class_init (ETaskListSelectorClass *class) +{ + ESourceSelectorClass *source_selector_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ETaskListSelectorPrivate)); + + source_selector_class = E_SOURCE_SELECTOR_CLASS (class); + source_selector_class->data_dropped = task_list_selector_data_dropped; +} + +static void +task_list_selector_init (ETaskListSelector *selector) +{ + selector->priv = E_TASK_LIST_SELECTOR_GET_PRIVATE (selector); + + gtk_drag_dest_set ( + GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL, + drag_types, G_N_ELEMENTS (drag_types), + GDK_ACTION_COPY | GDK_ACTION_MOVE); +} + +GType +e_task_list_selector_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (ETaskListSelectorClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) task_list_selector_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ETaskListSelector), + 0, /* n_preallocs */ + (GInstanceInitFunc) task_list_selector_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + E_TYPE_SOURCE_SELECTOR, "ETaskListSelector", + &type_info, 0); + } + + return type; +} + +GtkWidget * +e_task_list_selector_new (ESourceList *source_list) +{ + g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL); + + return g_object_new ( + E_TYPE_TASK_LIST_SELECTOR, + "source-list", source_list, NULL); +} diff --git a/calendar/gui/e-task-list-selector.h b/calendar/gui/e-task-list-selector.h new file mode 100644 index 0000000000..847a221ba4 --- /dev/null +++ b/calendar/gui/e-task-list-selector.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-task-list-selector.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* XXX This widget is nearly identical to EMemoListSelector. If + * ECalendarSelector ever learns how to move selections from + * one source to another, perhaps these ESourceSelector sub- + * classes could someday be combined. */ + +#ifndef E_TASK_LIST_SELECTOR_H +#define E_TASK_LIST_SELECTOR_H + +#include <libedataserver/e-source-list.h> +#include <libedataserverui/e-source-selector.h> + +/* Standard GObject macros */ +#define E_TYPE_TASK_LIST_SELECTOR \ + (e_task_list_selector_get_type ()) +#define E_TASK_LIST_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_TASK_LIST_SELECTOR, ETaskListSelector)) +#define E_TASK_LIST_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_TASK_LIST_SELECTOR, ETaskListSelectorClass)) +#define E_IS_TASK_LIST_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_TASK_LIST_SELECTOR)) +#define E_IS_TASK_LIST_SELECTOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_TASK_LIST_SELECTOR)) +#define E_TASK_LIST_SELECTOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_TASK_LIST_SELECTOR, ETaskListSelectorClass)) + +G_BEGIN_DECLS + +typedef struct _ETaskListSelector ETaskListSelector; +typedef struct _ETaskListSelectorClass ETaskListSelectorClass; +typedef struct _ETaskListSelectorPrivate ETaskListSelectorPrivate; + +struct _ETaskListSelector { + ESourceSelector parent; + ETaskListSelectorPrivate *priv; +}; + +struct _ETaskListSelectorClass { + ESourceSelectorClass parent_class; +}; + +GType e_task_list_selector_get_type (void); +GtkWidget * e_task_list_selector_new (ESourceList *source_list); + +G_END_DECLS + +#endif /* E_TASK_LIST_SELECTOR_H */ diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index 5acdcc0f65..9a5a894f4c 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -73,9 +73,6 @@ struct _ETasksPrivate { /* Calendar search bar for tasks */ GtkWidget *search_bar; - /* Tasks menu */ - ECalMenu *tasks_menu; - /* Paned widget */ GtkWidget *paned; @@ -86,18 +83,12 @@ struct _ETasksPrivate { gchar *sexp; guint update_timeout; - /* View instance and the view menus handler */ - GalViewInstance *view_instance; - GalViewMenus *view_menus; - GList *notifications; }; static void setup_widgets (ETasks *tasks); static void e_tasks_destroy (GtkObject *object); -static void update_view (ETasks *tasks); -static void categories_changed_cb (gpointer object, gpointer user_data); static void backend_error_cb (ECal *client, const gchar *message, gpointer data); /* Signal IDs */ @@ -108,126 +99,10 @@ enum { LAST_SIGNAL }; -enum DndTargetType { - TARGET_VCALENDAR -}; - -static GtkTargetEntry list_drag_types[] = { - { (gchar *) "text/calendar", 0, TARGET_VCALENDAR }, - { (gchar *) "text/x-calendar", 0, TARGET_VCALENDAR } -}; -static const gint num_list_drag_types = sizeof (list_drag_types) / sizeof (list_drag_types[0]); - static guint e_tasks_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (ETasks, e_tasks, GTK_TYPE_TABLE) -/* Callback used when the cursor changes in the table */ -static void -table_cursor_change_cb (ETable *etable, gint row, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - ECalModel *model; - ECalModelComponent *comp_data; - ECalComponent *comp; - const gchar *uid; - - gint n_selected; - - tasks = E_TASKS (data); - priv = tasks->priv; - - n_selected = e_table_selected_count (etable); - - /* update the HTML widget */ - if (n_selected != 1) { - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); - - return; - } - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - - comp_data = e_cal_model_get_component_at (model, e_table_get_cursor_row (etable)); - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - - e_cal_component_preview_display (E_CAL_COMPONENT_PREVIEW (priv->preview), comp_data->client, comp); - - e_cal_component_get_uid (comp, &uid); - if (priv->current_uid) - g_free (priv->current_uid); - priv->current_uid = g_strdup (uid); - - g_object_unref (comp); -} - -ECalMenu * -e_tasks_get_tasks_menu (ETasks *tasks) -{ - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - return tasks->priv->tasks_menu; -} - - -/* Callback used when the selection changes in the table. */ -static void -table_selection_change_cb (ETable *etable, gpointer data) -{ - ETasks *tasks; - gint n_selected; - - tasks = E_TASKS (data); - - n_selected = e_table_selected_count (etable); - g_signal_emit (tasks, e_tasks_signals[SELECTION_CHANGED], 0, n_selected); - - if (n_selected != 1) - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (tasks->priv->preview)); -} - -static void -user_created_cb (GtkWidget *view, ETasks *tasks) -{ - ETasksPrivate *priv; - ECalendarTable *cal_table; - ECal *ecal; - - priv = tasks->priv; - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - - if (cal_table->user_created_cal) - ecal = cal_table->user_created_cal; - else { - ECalModel *model; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - ecal = e_cal_model_get_default_client (model); - } - - e_tasks_add_todo_source (tasks, e_cal_get_source (ecal)); -} - -/* Callback used when the sexp in the search bar changes */ -static void -search_bar_sexp_changed_cb (CalSearchBar *cal_search, const gchar *sexp, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - - tasks = E_TASKS (data); - priv = tasks->priv; - - if (priv->sexp) - g_free (priv->sexp); - - priv->sexp = g_strdup (sexp); - - update_view (tasks); -} - /* Callback used when the selected category in the search bar changes */ static void search_bar_category_changed_cb (CalSearchBar *cal_search, const gchar *category, gpointer data) @@ -243,194 +118,6 @@ search_bar_category_changed_cb (CalSearchBar *cal_search, const gchar *category, e_cal_model_set_default_category (model, category); } -static gboolean -vpaned_resized_cb (GtkWidget *widget, GdkEventButton *event, ETasks *tasks) -{ - calendar_config_set_task_vpane_pos (gtk_paned_get_position (GTK_PANED (widget))); - - return FALSE; -} - -static void -set_timezone (ETasks *tasks) -{ - ETasksPrivate *priv; - icaltimezone *zone; - GList *l; - - priv = tasks->priv; - - zone = calendar_config_get_icaltimezone (); - for (l = priv->clients_list; l != NULL; l = l->next) { - ECal *client = l->data; - /* FIXME Error checking */ - e_cal_set_default_timezone (client, zone, NULL); - } - - if (priv->default_client) - /* FIXME Error checking */ - e_cal_set_default_timezone (priv->default_client, zone, NULL); - - if (priv->preview) - e_cal_component_preview_set_default_timezone (E_CAL_COMPONENT_PREVIEW (priv->preview), zone); -} - -static void -timezone_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) -{ - ETasks *tasks = data; - - set_timezone (tasks); -} - -static void -update_view (ETasks *tasks) -{ - ETasksPrivate *priv; - ECalModel *model; - gchar *real_sexp = NULL; - gchar *new_sexp = NULL; - - priv = tasks->priv; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - - if ((new_sexp = calendar_config_get_hide_completed_tasks_sexp (FALSE)) != NULL) { - real_sexp = g_strdup_printf ("(and %s %s)", new_sexp, priv->sexp); - e_cal_model_set_search_query (model, real_sexp); - g_free (new_sexp); - g_free (real_sexp); - } else - e_cal_model_set_search_query (model, priv->sexp); - - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); -} - -static void -process_completed_tasks (ETasks *tasks, gboolean config_changed) -{ - ETasksPrivate *priv; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - e_calendar_table_process_completed_tasks (e_tasks_get_calendar_table (tasks), priv->clients_list, config_changed); -} - -static gboolean -update_view_cb (ETasks *tasks) -{ - ECalModel *model; - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (tasks->priv->tasks_view)); - - process_completed_tasks (tasks, FALSE); - e_cal_model_tasks_update_due_tasks (E_CAL_MODEL_TASKS (model)); - - return TRUE; -} - -static void -config_hide_completed_tasks_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) -{ - process_completed_tasks (data, TRUE); - update_view (data); -} - -static void -model_row_changed_cb (ETableModel *etm, gint row, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - ECalModelComponent *comp_data; - - tasks = E_TASKS (data); - priv = tasks->priv; - - if (priv->current_uid) { - const gchar *uid; - - comp_data = e_cal_model_get_component_at (E_CAL_MODEL (etm), row); - if (comp_data) { - uid = icalcomponent_get_uid (comp_data->icalcomp); - if (!strcmp (uid ? uid : "", priv->current_uid)) { - ETable *etable; - - etable = e_table_scrolled_get_table ( - E_TABLE_SCROLLED (E_CALENDAR_TABLE (priv->tasks_view)->etable)); - table_cursor_change_cb (etable, 0, tasks); - } - } - } -} - -static void -view_progress_cb (ECalModel *model, const gchar *message, gint percent, ECalSourceType type, ETasks *tasks) -{ - e_calendar_table_set_status_message (E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks)), - message, percent); -} - -static void -view_done_cb (ECalModel *model, ECalendarStatus status, ECalSourceType type, ETasks *tasks) -{ - e_calendar_table_set_status_message (E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks)), - NULL, -1); - -} - -static void -config_preview_state_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) -{ - gboolean state; - GConfValue *value; - ETasks *tasks = (ETasks *)data; - - g_return_if_fail (gconf_entry_get_key (entry) != NULL); - g_return_if_fail ((value = gconf_entry_get_value (entry)) != NULL); - - state = gconf_value_get_bool (value); - e_tasks_show_preview (tasks, state); - bonobo_ui_component_set_prop (E_SEARCH_BAR (tasks->priv->search_bar)->ui_component, "/commands/ViewPreview", "state", state ? "1" : "0", NULL); -} - -static void -setup_config (ETasks *tasks) -{ - ETasksPrivate *priv; - guint not; - - priv = tasks->priv; - - /* Timezone */ - set_timezone (tasks); - - not = calendar_config_add_notification_timezone (timezone_changed_cb, tasks); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); - - not = calendar_config_add_notification_hide_completed_tasks (config_hide_completed_tasks_changed_cb, - tasks); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); - - not = calendar_config_add_notification_hide_completed_tasks_units (config_hide_completed_tasks_changed_cb, - tasks); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); - - not = calendar_config_add_notification_hide_completed_tasks_value (config_hide_completed_tasks_changed_cb, - tasks); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); - - not = calendar_config_add_notification_preview_state (config_preview_state_changed_cb, tasks); - priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); -} - -struct AffectedComponents { - ECalendarTable *cal_table; - GSList *components; /* contains pointers to ECalModelComponent */ -}; - /** * get_selected_components_cb * Helper function to fill list of selected components in ECalendarTable. @@ -614,7 +301,6 @@ setup_widgets (ETasks *tasks) G_CALLBACK (search_bar_sexp_changed_cb), tasks); g_signal_connect (priv->search_bar, "category_changed", G_CALLBACK (search_bar_category_changed_cb), tasks); - categories_changed_cb (NULL, tasks); gtk_table_attach (GTK_TABLE (tasks), priv->search_bar, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0, 0); @@ -624,8 +310,6 @@ setup_widgets (ETasks *tasks) priv->paned = gtk_vpaned_new (); g_signal_connect (priv->paned, "realize", G_CALLBACK (pane_realized), tasks); - g_signal_connect (G_OBJECT (priv->paned), "button_release_event", - G_CALLBACK (vpaned_resized_cb), tasks); gtk_table_attach (GTK_TABLE (tasks), priv->paned, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (priv->paned); @@ -665,12 +349,8 @@ setup_widgets (ETasks *tasks) "table_drag_data_received", G_CALLBACK(table_drag_data_received_cb), editor); */ - g_signal_connect (etable, "cursor_change", G_CALLBACK (table_cursor_change_cb), tasks); g_signal_connect (etable, "selection_change", G_CALLBACK (table_selection_change_cb), tasks); - /* Timeout check to hide completed items */ - priv->update_timeout = g_timeout_add_full (G_PRIORITY_LOW, 60000, (GSourceFunc) update_view_cb, tasks, NULL); - /* create the task detail */ priv->preview = e_cal_component_preview_new (); e_cal_component_preview_set_default_timezone (E_CAL_COMPONENT_PREVIEW (priv->preview), calendar_config_get_icaltimezone ()); @@ -679,15 +359,6 @@ setup_widgets (ETasks *tasks) if (state) gtk_widget_show (priv->preview); - - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - g_signal_connect (G_OBJECT (model), "model_row_changed", - G_CALLBACK (model_row_changed_cb), tasks); - - g_signal_connect (G_OBJECT (model), "cal_view_progress", - G_CALLBACK (view_progress_cb), tasks); - g_signal_connect (G_OBJECT (model), "cal_view_done", - G_CALLBACK (view_done_cb), tasks); } /* Class initialization function for the gnome calendar */ @@ -738,29 +409,6 @@ e_tasks_class_init (ETasksClass *class) } -static void -categories_changed_cb (gpointer object, gpointer user_data) -{ - GList *cat_list; - GPtrArray *cat_array; - ETasksPrivate *priv; - ETasks *tasks = user_data; - - priv = tasks->priv; - - cat_array = g_ptr_array_new (); - cat_list = e_categories_get_list (); - while (cat_list != NULL) { - if (e_categories_is_searchable ((const gchar *) cat_list->data)) - g_ptr_array_add (cat_array, cat_list->data); - cat_list = g_list_remove (cat_list, cat_list->data); - } - - cal_search_bar_set_categories ((CalSearchBar *)priv->search_bar, cat_array); - - g_ptr_array_free (cat_array, TRUE); -} - /* Object initialization function for the gnome calendar */ static void e_tasks_init (ETasks *tasks) @@ -770,20 +418,13 @@ e_tasks_init (ETasks *tasks) priv = g_new0 (ETasksPrivate, 1); tasks->priv = priv; - e_categories_register_change_listener (G_CALLBACK (categories_changed_cb), tasks); - - setup_config (tasks); setup_widgets (tasks); priv->clients = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->query = NULL; - priv->view_instance = NULL; - priv->view_menus = NULL; priv->current_uid = NULL; priv->sexp = g_strdup ("#t"); priv->default_client = NULL; - priv->tasks_menu = e_cal_menu_new ("org.gnome.evolution.tasks.view"); - update_view (tasks); } GtkWidget * @@ -796,18 +437,6 @@ e_tasks_new (void) return GTK_WIDGET (tasks); } - -void -e_tasks_set_ui_component (ETasks *tasks, - BonoboUIComponent *ui_component) -{ - g_return_if_fail (E_IS_TASKS (tasks)); - g_return_if_fail (ui_component == NULL || BONOBO_IS_UI_COMPONENT (ui_component)); - - e_search_bar_set_ui_component (E_SEARCH_BAR (tasks->priv->search_bar), ui_component); -} - - static void e_tasks_destroy (GtkObject *object) { @@ -823,8 +452,6 @@ e_tasks_destroy (GtkObject *object) if (priv) { GList *l; - e_categories_unregister_change_listener (G_CALLBACK (categories_changed_cb), tasks); - /* disconnect from signals on all the clients */ for (l = priv->clients_list; l != NULL; l = l->next) { g_signal_handlers_disconnect_matched (l->data, G_SIGNAL_MATCH_DATA, @@ -848,11 +475,6 @@ e_tasks_destroy (GtkObject *object) priv->sexp = NULL; } - if (priv->update_timeout) { - g_source_remove (priv->update_timeout); - priv->update_timeout = 0; - } - if (priv->tasks_view_config) { g_object_unref (priv->tasks_view_config); priv->tasks_view_config = NULL; @@ -889,160 +511,6 @@ set_status_message (ETasks *tasks, const gchar *message, ...) e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->tasks_view), msg_string, -1); } -/* Callback from the calendar client when an error occurs in the backend */ -static void -backend_error_cb (ECal *client, const gchar *message, gpointer data) -{ - ETasks *tasks; - GtkWidget *dialog; - gchar *urinopwd; - - tasks = E_TASKS (data); - - urinopwd = get_uri_without_password (e_cal_get_uri (client)); - - dialog = gtk_message_dialog_new ( - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks))), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("Error on %s:\n %s"), - urinopwd, message); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_free (urinopwd); -} - -/* Callback from the calendar client when the backend dies */ -static void -backend_died_cb (ECal *client, gpointer data) -{ - ETasks *tasks; - ETasksPrivate *priv; - ESource *source; - - tasks = E_TASKS (data); - priv = tasks->priv; - - source = g_object_ref (e_cal_get_source (client)); - - priv->clients_list = g_list_remove (priv->clients_list, client); - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (tasks, e_tasks_signals[SOURCE_REMOVED], 0, source); - - e_calendar_table_set_status_message (E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks)), NULL, -1); - - e_error_run (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks))), - "calendar:tasks-crashed", NULL); - - g_object_unref (source); -} - -/* Callback from the calendar client when the calendar is opened */ -static void -client_cal_opened_cb (ECal *ecal, ECalendarStatus status, ETasks *tasks) -{ - ECalModel *model; - ESource *source; - ETasksPrivate *priv; - - priv = tasks->priv; - - source = e_cal_get_source (ecal); - - if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) - auth_cal_forget_password (ecal); - - switch (status) { - case E_CALENDAR_STATUS_OK : - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, client_cal_opened_cb, NULL); - - set_status_message (tasks, _("Loading tasks")); - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - e_cal_model_add_client (model, ecal); - - set_status_message (tasks, NULL); - break; - case E_CALENDAR_STATUS_AUTHENTICATION_FAILED: - /* try to reopen calendar - it'll ask for a password once again */ - e_cal_open_async (ecal, FALSE); - return; - case E_CALENDAR_STATUS_BUSY : - break; - case E_CALENDAR_STATUS_REPOSITORY_OFFLINE: - e_error_run (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tasks))), "calendar:prompt-no-contents-offline-tasks", NULL); - default : - /* Make sure the source doesn't disappear on us */ - g_object_ref (source); - - priv->clients_list = g_list_remove (priv->clients_list, ecal); - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, tasks); - - /* Do this last because it unrefs the client */ - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (tasks, e_tasks_signals[SOURCE_REMOVED], 0, source); - - set_status_message (tasks, NULL); - g_object_unref (source); - - break; - } -} - -static void -default_client_cal_opened_cb (ECal *ecal, ECalendarStatus status, ETasks *tasks) -{ - ECalModel *model; - ESource *source; - ETasksPrivate *priv; - - priv = tasks->priv; - - source = e_cal_get_source (ecal); - - if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) - auth_cal_forget_password (ecal); - - switch (status) { - case E_CALENDAR_STATUS_OK : - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, default_client_cal_opened_cb, NULL); - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - - e_cal_model_set_default_client (model, ecal); - set_status_message (tasks, NULL); - break; - case E_CALENDAR_STATUS_AUTHENTICATION_FAILED: - /* try to reopen calendar - it'll ask for a password once again */ - e_cal_open_async (ecal, FALSE); - return; - case E_CALENDAR_STATUS_BUSY: - break; - default : - /* Make sure the source doesn't disappear on us */ - g_object_ref (source); - - priv->clients_list = g_list_remove (priv->clients_list, ecal); - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, tasks); - - /* Do this last because it unrefs the client */ - g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - - g_signal_emit (tasks, e_tasks_signals[SOURCE_REMOVED], 0, source); - - set_status_message (tasks, NULL); - g_object_unref (priv->default_client); - priv->default_client = NULL; - g_object_unref (source); - - break; - } -} - typedef void (*open_func) (ECal *, ECalendarStatus, ETasks *); static gboolean @@ -1107,104 +575,6 @@ e_tasks_new_task (ETasks *tasks) gtk_window_present (GTK_WINDOW (editor)); } -void -e_tasks_show_preview (ETasks *tasks, gboolean state) -{ - ETasksPrivate *priv; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - priv = tasks->priv; - - if (state) { - ECalModel *model; - ECalModelComponent *comp_data; - ECalComponent *comp; - ETable *etable; - const gchar *uid; - gint n_selected; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (priv->tasks_view)->etable)); - n_selected = e_table_selected_count (etable); - - if (n_selected != 1) { - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); - } else { - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view)); - - comp_data = e_cal_model_get_component_at (model, e_table_get_cursor_row (etable)); - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - - e_cal_component_preview_display (E_CAL_COMPONENT_PREVIEW (priv->preview), comp_data->client, comp); - - e_cal_component_get_uid (comp, &uid); - if (priv->current_uid) - g_free (priv->current_uid); - priv->current_uid = g_strdup (uid); - - g_object_unref (comp); - } - gtk_widget_show (priv->preview); - - } else { - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); - gtk_widget_hide (priv->preview); - } -} - -gboolean -e_tasks_add_todo_source (ETasks *tasks, ESource *source) -{ - ETasksPrivate *priv; - ECal *client; - const gchar *uid; - - g_return_val_if_fail (tasks != NULL, FALSE); - g_return_val_if_fail (E_IS_TASKS (tasks), FALSE); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - - priv = tasks->priv; - - uid = e_source_peek_uid (source); - client = g_hash_table_lookup (priv->clients, uid); - if (client) { - /* We already have it */ - - return TRUE; - } else { - ESource *default_source; - - if (priv->default_client) { - default_source = e_cal_get_source (priv->default_client); - - /* We don't have it but the default client is it */ - if (!strcmp (e_source_peek_uid (default_source), uid)) - client = g_object_ref (priv->default_client); - } - - /* Create a new one */ - if (!client) { - client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_TODO); - if (!client) - return FALSE; - } - } - - g_signal_connect (G_OBJECT (client), "backend_error", G_CALLBACK (backend_error_cb), tasks); - g_signal_connect (G_OBJECT (client), "backend_died", G_CALLBACK (backend_died_cb), tasks); - - /* add the client to internal structure */ - g_hash_table_insert (priv->clients, g_strdup (uid) , client); - priv->clients_list = g_list_prepend (priv->clients_list, client); - - g_signal_emit (tasks, e_tasks_signals[SOURCE_ADDED], 0, source); - - open_ecal (tasks, client, FALSE, client_cal_opened_cb); - - return TRUE; -} - gboolean e_tasks_remove_todo_source (ETasks *tasks, ESource *source) { @@ -1270,68 +640,6 @@ e_tasks_set_default_source (ETasks *tasks, ESource *source) return TRUE; } -ECal * -e_tasks_get_default_client (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_val_if_fail (tasks != NULL, NULL); - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - priv = tasks->priv; - - return e_cal_model_get_default_client (e_calendar_table_get_model (E_CALENDAR_TABLE (priv->tasks_view))); -} - -/** - * e_tasks_complete_selected: - * @tasks: A tasks control widget - * - * Marks the selected tasks complete - **/ -void -e_tasks_complete_selected (ETasks *tasks) -{ - ETasksPrivate *priv; - ECalendarTable *cal_table; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - - set_status_message (tasks, _("Completing tasks...")); - e_calendar_table_complete_selected (cal_table); - set_status_message (tasks, NULL); -} - -/** - * e_tasks_delete_selected: - * @tasks: A tasks control widget. - * - * Deletes the selected tasks in the task list. - **/ -void -e_tasks_delete_selected (ETasks *tasks) -{ - ETasksPrivate *priv; - ECalendarTable *cal_table; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - cal_table = E_CALENDAR_TABLE (priv->tasks_view); - set_status_message (tasks, _("Deleting selected objects...")); - e_calendar_table_delete_selected (cal_table); - set_status_message (tasks, NULL); - - e_cal_component_preview_clear (E_CAL_COMPONENT_PREVIEW (priv->preview)); -} - /** * e_tasks_expunge: * @tasks: A tasks control widget @@ -1383,126 +691,6 @@ e_tasks_delete_completed (ETasks *tasks) g_free (sexp); } -/* Callback used from the view collection when we need to display a new view */ -static void -display_view_cb (GalViewInstance *instance, GalView *view, gpointer data) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - - if (GAL_IS_VIEW_ETABLE (view)) { - gal_view_etable_attach_table (GAL_VIEW_ETABLE (view), e_table_scrolled_get_table (E_TABLE_SCROLLED (E_CALENDAR_TABLE (tasks->priv->tasks_view)->etable))); - } - - gtk_paned_set_position ((GtkPaned *)tasks->priv->paned, calendar_config_get_task_vpane_pos ()); -} - -/** - * e_tasks_setup_view_menus: - * @tasks: A tasks widget. - * @uic: UI controller to use for the menus. - * - * Sets up the #GalView menus for a tasks control. This function should be - * called from the Bonobo control activation callback for this tasks control. - * Also, the menus should be discarded using e_tasks_discard_view_menus(). - **/ -void -e_tasks_setup_view_menus (ETasks *tasks, BonoboUIComponent *uic) -{ - ETasksPrivate *priv; - GalViewFactory *factory; - ETableSpecification *spec; - gchar *dir0, *dir1, *filename; - static GalViewCollection *collection = NULL; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - g_return_if_fail (uic != NULL); - g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); - - priv = tasks->priv; - - g_return_if_fail (priv->view_instance == NULL); - - g_return_if_fail (priv->view_instance == NULL); - g_return_if_fail (priv->view_menus == NULL); - - /* Create the view instance */ - - if (collection == NULL) { - collection = gal_view_collection_new (); - - gal_view_collection_set_title (collection, _("Tasks")); - - dir0 = g_build_filename (EVOLUTION_GALVIEWSDIR, - "tasks", - NULL); - dir1 = g_build_filename (tasks_component_peek_base_directory (tasks_component_peek ()), - "tasks", "views", NULL); - gal_view_collection_set_storage_directories (collection, - dir0, - dir1); - g_free (dir1); - g_free (dir0); - - /* Create the views */ - - spec = e_table_specification_new (); - filename = g_build_filename (EVOLUTION_ETSPECDIR, - "e-calendar-table.etspec", - NULL); - if (!e_table_specification_load_from_file (spec, filename)) - g_error ("Unable to load ETable specification file " - "for tasks"); - g_free (filename); - - factory = gal_view_factory_etable_new (spec); - g_object_unref (spec); - gal_view_collection_add_factory (collection, factory); - g_object_unref (factory); - - /* Load the collection and create the menus */ - - gal_view_collection_load (collection); - } - - priv->view_instance = gal_view_instance_new (collection, NULL); - - priv->view_menus = gal_view_menus_new (priv->view_instance); - gal_view_menus_apply (priv->view_menus, uic, NULL); - g_signal_connect (priv->view_instance, "display_view", G_CALLBACK (display_view_cb), tasks); - display_view_cb (priv->view_instance, gal_view_instance_get_current_view (priv->view_instance), tasks); -} - -/** - * e_tasks_discard_view_menus: - * @tasks: A tasks widget. - * - * Discards the #GalView menus used by a tasks control. This function should be - * called from the Bonobo control deactivation callback for this tasks control. - * The menus should have been set up with e_tasks_setup_view_menus(). - **/ -void -e_tasks_discard_view_menus (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_if_fail (tasks != NULL); - g_return_if_fail (E_IS_TASKS (tasks)); - - priv = tasks->priv; - - g_return_if_fail (priv->view_instance != NULL); - g_return_if_fail (priv->view_menus != NULL); - - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - - g_object_unref (priv->view_menus); - priv->view_menus = NULL; -} - void e_tasks_open_task_id (ETasks *tasks, const gchar *src_uid, @@ -1541,39 +729,3 @@ e_tasks_open_task_id (ETasks *tasks, return; } - -/** - * e_tasks_get_calendar_table: - * @tasks: A tasks widget. - * - * Queries the #ECalendarTable contained in a tasks widget. - * - * Return value: The #ECalendarTable that the tasks widget uses to display its - * information. - **/ -ECalendarTable * -e_tasks_get_calendar_table (ETasks *tasks) -{ - ETasksPrivate *priv; - - g_return_val_if_fail (tasks != NULL, NULL); - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - priv = tasks->priv; - return E_CALENDAR_TABLE (priv->tasks_view); -} - -/** - * e_tasks_get_preview: - * @tasks: A tasks widget. - * - * Queries the #ECalComponentPreview contained in a tasks widget. - **/ -GtkWidget * -e_tasks_get_preview (ETasks *tasks) -{ - g_return_val_if_fail (tasks != NULL, NULL); - g_return_val_if_fail (E_IS_TASKS (tasks), NULL); - - return tasks->priv->preview; -} diff --git a/calendar/gui/e-tasks.h b/calendar/gui/e-tasks.h index 47e38c8a5b..628c34ace1 100644 --- a/calendar/gui/e-tasks.h +++ b/calendar/gui/e-tasks.h @@ -63,30 +63,15 @@ GtkWidget *e_tasks_construct (ETasks *tasks); GtkWidget *e_tasks_new (void); -void e_tasks_set_ui_component (ETasks *tasks, - BonoboUIComponent *ui_component); - gboolean e_tasks_add_todo_source (ETasks *tasks, ESource *source); gboolean e_tasks_remove_todo_source (ETasks *tasks, ESource *source); gboolean e_tasks_set_default_source (ETasks *tasks, ESource *source); -ECal *e_tasks_get_default_client (ETasks *tasks); - void e_tasks_open_task (ETasks *tasks); void e_tasks_open_task_id (ETasks *tasks, const gchar *src_uid, const gchar *comp_uid, const gchar *comp_rid); void e_tasks_new_task (ETasks *tasks); -void e_tasks_complete_selected (ETasks *tasks); -void e_tasks_delete_selected (ETasks *tasks); void e_tasks_delete_completed (ETasks *tasks); -void e_tasks_show_preview (ETasks *tasks, gboolean state); -void e_tasks_setup_view_menus (ETasks *tasks, BonoboUIComponent *uic); -void e_tasks_discard_view_menus (ETasks *tasks); - -struct _ECalMenu *e_tasks_get_tasks_menu (ETasks *tasks); -ECalendarTable *e_tasks_get_calendar_table (ETasks *tasks); -GtkWidget *e_tasks_get_preview (ETasks *tasks); - #endif /* _E_TASKS_H_ */ diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c index 34bbe0f0c0..bfc95ebe2e 100644 --- a/calendar/gui/e-week-view-main-item.c +++ b/calendar/gui/e-week-view-main-item.c @@ -29,7 +29,7 @@ #include <glib.h> #include <glib/gi18n.h> #include "e-week-view-main-item.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ static void e_week_view_main_item_set_property (GObject *object, guint property_id, @@ -91,8 +91,10 @@ e_week_view_main_item_class_init (EWeekViewMainItemClass *class) NULL, G_PARAM_WRITABLE)); +#if 0 /* KILL-BONOBO */ /* init the accessibility support for e_week_view_main_item */ e_week_view_main_item_a11y_init (); +#endif } diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c index 839cad6688..1e84aeaea3 100644 --- a/calendar/gui/e-week-view.c +++ b/calendar/gui/e-week-view.c @@ -30,7 +30,7 @@ #endif #include "e-week-view.h" -#include "ea-calendar.h" +/*#include "a11y/ea-calendar.h"*/ /* KILL-BONOBO */ #include <math.h> #include <gdk/gdkkeysyms.h> @@ -39,7 +39,7 @@ #include <text/e-text.h> #include <misc/e-canvas-utils.h> #include <misc/e-gui-utils.h> -#include <misc/e-unicode.h> +#include <e-util/e-unicode.h> #include <e-util/e-categories-config.h> #include <e-util/e-dialog-utils.h> #include <e-util/e-util.h> @@ -51,7 +51,6 @@ #include "comp-util.h" #include "itip-utils.h" #include <libecal/e-cal-time-util.h> -#include "calendar-commands.h" #include "calendar-config.h" #include "print.h" #include "goto.h" @@ -226,8 +225,10 @@ e_week_view_class_init (EWeekViewClass *class) view_class->get_visible_time_range = e_week_view_get_visible_time_range; view_class->paste_text = e_week_view_paste_text; +#if 0 /* KILL-BONOBO */ /* init the accessibility support for e_week_view */ e_week_view_a11y_init (); +#endif } static void @@ -1937,6 +1938,9 @@ set_text_as_bold (EWeekViewEvent *event, EWeekViewEventSpan *span) break; } } + e_cal_component_free_attendee_list (attendees); + g_free (address); + g_object_unref (comp); /* The attendee has not yet accepted the meeting, display the summary as bolded. If the attendee is not present, it might have come through a mailing list. @@ -3612,8 +3616,10 @@ e_week_view_on_editing_stopped (EWeekView *week_view, if (!on_server) { if (!e_cal_create_object (client, icalcomp, NULL, NULL)) g_message (G_STRLOC ": Could not create the object!"); +#if 0 /* KILL-BONOBO */ else gnome_calendar_emit_user_created_signal (week_view, e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view)), client); +#endif /* we remove the object since we either got the update from the server or failed */ e_week_view_remove_event_cb (week_view, event_num, NULL); @@ -4032,6 +4038,8 @@ e_week_view_cursor_key_right (EWeekView *week_view, GnomeCalendarViewType view_t static gboolean e_week_view_add_new_event_in_selected_range (EWeekView *week_view, const gchar *initial_text) { +#if 0 /* KILL-BONOBO */ + EWeekView *week_view; ECal *ecal; ECalModel *model; ECalComponent *comp; @@ -4220,6 +4228,7 @@ e_week_view_do_key_press (GtkWidget *widget, GdkEventKey *event) g_free (initial_text); return ret_val; +#endif } static gint @@ -4255,6 +4264,7 @@ e_week_view_get_adjust_days_for_move_right (EWeekView *week_view,gint current_da static gboolean e_week_view_key_press (GtkWidget *widget, GdkEventKey *event) { +#if 0 /* KILL-BONOBO */ gboolean handled = FALSE; handled = e_week_view_do_key_press (widget, event); @@ -4262,6 +4272,7 @@ e_week_view_key_press (GtkWidget *widget, GdkEventKey *event) if (!handled) handled = GTK_WIDGET_CLASS (e_week_view_parent_class)->key_press_event (widget, event); return handled; +#endif } static void @@ -4281,9 +4292,11 @@ e_week_view_show_popup_menu (EWeekView *week_view, week_view->popup_event_num = event_num; +#if 0 /* KILL-BONOBO */ popup = e_calendar_view_create_popup_menu (E_CALENDAR_VIEW (week_view)); g_object_weak_ref (G_OBJECT (popup), popup_destroyed_cb, week_view); gtk_menu_popup (popup, NULL, NULL, NULL, NULL, bevent?bevent->button:0, bevent?bevent->time:gtk_get_current_event_time()); +#endif } static gboolean @@ -4298,6 +4311,7 @@ e_week_view_popup_menu (GtkWidget *widget) void e_week_view_jump_to_button_item (EWeekView *week_view, GnomeCanvasItem *item) { +#if 0 /* KILL-BONOBO */ gint day; GnomeCalendar *calendar; @@ -4313,6 +4327,7 @@ e_week_view_jump_to_button_item (EWeekView *week_view, GnomeCanvasItem *item) return; } } +#endif } static gboolean diff --git a/calendar/gui/ea-cal-view-event.c b/calendar/gui/ea-cal-view-event.c new file mode 100644 index 0000000000..5da164323f --- /dev/null +++ b/calendar/gui/ea-cal-view-event.c @@ -0,0 +1,573 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-cal-view-event.h" +#include "ea-calendar-helpers.h" +#include "ea-day-view.h" +#include "ea-week-view.h" +#include <text/e-text.h> +#include <glib/gi18n.h> + +static void ea_cal_view_event_class_init (EaCalViewEventClass *klass); +static void ea_cal_view_event_init (EaCalViewEvent *a11y); + +static void ea_cal_view_event_dispose (GObject *object); +static G_CONST_RETURN gchar * ea_cal_view_event_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_cal_view_event_get_description (AtkObject *accessible); +static AtkObject* ea_cal_view_event_get_parent (AtkObject *accessible); +static gint ea_cal_view_event_get_index_in_parent (AtkObject *accessible); +static AtkStateSet *ea_cal_view_event_ref_state_set (AtkObject *accessible); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void ea_cal_view_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type); +/* action interface */ +static void atk_action_interface_init (AtkActionIface *iface); +static gboolean ea_cal_view_event_do_action (AtkAction *action, gint i); +static gint ea_cal_view_event_get_n_actions (AtkAction *action); +static G_CONST_RETURN gchar * ea_cal_view_event_action_get_name (AtkAction *action, gint i); + + +#ifdef ACC_DEBUG +static gint n_ea_cal_view_event_created = 0, n_ea_cal_view_event_destroyed = 0; +static void ea_cal_view_finalize (GObject *object); +#endif + +static gpointer parent_class = NULL; + +GType +ea_cal_view_event_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaCalViewEventClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_cal_view_event_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaCalViewEvent), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) ea_cal_view_event_init, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + static const GInterfaceInfo atk_action_info = { + (GInterfaceInitFunc) atk_action_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (atk object for E_TEXT, in this case) + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + E_TYPE_TEXT); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + /* we inherit the component, text and other interfaces from E_TEXT */ + type = g_type_register_static (derived_atk_type, + "EaCalViewEvent", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + g_type_add_interface_static (type, ATK_TYPE_ACTION, + &atk_action_info); + + + } + + return type; +} + +static void +ea_cal_view_event_class_init (EaCalViewEventClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); +#ifdef ACC_DEBUG + gobject_class->finalize = ea_cal_view_finalize; +#endif + + parent_class = g_type_class_peek_parent (klass); + + gobject_class->dispose = ea_cal_view_event_dispose; + + class->get_name = ea_cal_view_event_get_name; + class->get_description = ea_cal_view_event_get_description; + class->get_parent = ea_cal_view_event_get_parent; + class->get_index_in_parent = ea_cal_view_event_get_index_in_parent; + class->ref_state_set = ea_cal_view_event_ref_state_set; + +} + +static void +ea_cal_view_event_init (EaCalViewEvent *a11y) +{ + a11y->state_set = atk_state_set_new (); + atk_state_set_add_state (a11y->state_set, ATK_STATE_TRANSIENT); + atk_state_set_add_state (a11y->state_set, ATK_STATE_ENABLED); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SENSITIVE); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SELECTABLE); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SHOWING); + atk_state_set_add_state (a11y->state_set, ATK_STATE_FOCUSABLE); +} + +#ifdef ACC_DEBUG +static void ea_cal_view_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); + + ++n_ea_cal_view_event_destroyed; + printf ("ACC_DEBUG: n_ea_cal_view_event_destroyed = %d\n", + n_ea_cal_view_event_destroyed); +} +#endif + +AtkObject* +ea_cal_view_event_new (GObject *obj) +{ + AtkObject *atk_obj = NULL; + GObject *target_obj; + ECalendarView *cal_view; + + g_return_val_if_fail (E_IS_TEXT (obj), NULL); + cal_view = ea_calendar_helpers_get_cal_view_from (GNOME_CANVAS_ITEM (obj)); + if (!cal_view) + return NULL; + + if (E_IS_WEEK_VIEW (cal_view)) { + gint event_num, span_num; + EWeekViewEvent *week_view_event; + EWeekViewEventSpan *event_span; + EWeekView *week_view = E_WEEK_VIEW (cal_view); + + /* for week view, we need to check if a atkobject exists for + * the first span of the same event + */ + if (!e_week_view_find_event_from_item (week_view, + GNOME_CANVAS_ITEM (obj), + &event_num, + &span_num)) + return NULL; + week_view_event = &g_array_index (week_view->events, + EWeekViewEvent, + event_num); + /* get the first span */ + event_span = &g_array_index (week_view->spans, + EWeekViewEventSpan, + week_view_event->spans_index); + target_obj = G_OBJECT (event_span->text_item); + atk_obj = g_object_get_data (target_obj, "accessible-object"); + + } + else + target_obj = obj; + + if (!atk_obj) { + static AtkRole event_role = ATK_ROLE_INVALID; + atk_obj = ATK_OBJECT (g_object_new (EA_TYPE_CAL_VIEW_EVENT, + NULL)); + atk_object_initialize (atk_obj, target_obj); + if (event_role == ATK_ROLE_INVALID) + event_role = atk_role_register ("Calendar Event"); + atk_obj->role = event_role; +#ifdef ACC_DEBUG + ++n_ea_cal_view_event_created; + printf ("ACC_DEBUG: n_ea_cal_view_event_created = %d\n", + n_ea_cal_view_event_created); +#endif + } + + /* the registered factory for E_TEXT is cannot create a EaCalViewEvent, + * we should save the EaCalViewEvent object in it. + */ + g_object_set_data (obj, "accessible-object", atk_obj); + + return atk_obj; +} + +static void +ea_cal_view_event_dispose (GObject *object) +{ + EaCalViewEvent *a11y = EA_CAL_VIEW_EVENT (object); + + if (a11y->state_set) { + g_object_unref (a11y->state_set); + a11y->state_set = NULL; + } + + if (G_OBJECT_CLASS(parent_class)->dispose) + G_OBJECT_CLASS(parent_class)->dispose (object); +} + +static G_CONST_RETURN gchar * +ea_cal_view_event_get_name (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarViewEvent *event; + gchar *name_string; + const gchar *alarm_string; + const gchar *recur_string; + const gchar *meeting_string; + gchar *summary_string; + const gchar *summary; + + + g_return_val_if_fail (EA_IS_CAL_VIEW_EVENT (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj || !E_IS_TEXT (g_obj)) + return NULL; + event = ea_calendar_helpers_get_cal_view_event_from (GNOME_CANVAS_ITEM(g_obj)); + + alarm_string = recur_string = meeting_string = ""; + if (event && event->comp_data) { + if (e_cal_util_component_has_alarms (event->comp_data->icalcomp)) + alarm_string = _("It has alarms."); + + if (e_cal_util_component_has_recurrences (event->comp_data->icalcomp)) + recur_string = _("It has recurrences."); + + if (e_cal_util_component_has_organizer (event->comp_data->icalcomp)) + meeting_string = _("It is a meeting."); + + } + + summary = icalcomponent_get_summary (event->comp_data->icalcomp); + if (summary) + summary_string = g_strdup_printf (_("Calendar Event: Summary is %s."), summary); + else + summary_string = g_strdup (_("Calendar Event: It has no summary.")); + + name_string = g_strdup_printf ("%s %s %s %s", summary_string, alarm_string, recur_string, meeting_string); + g_free (summary_string); + + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_string); +#ifdef ACC_DEBUG + printf("EvoAcc: name for event accobj=%p, is %s\n", + (gpointer)accessible, new_name); +#endif + g_free (name_string); + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_cal_view_event_get_description (AtkObject *accessible) +{ + if (accessible->description) + return accessible->description; + + return _("calendar view event"); +} + +static AtkObject * +ea_cal_view_event_get_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + GnomeCanvasItem *canvas_item; + ECalendarView *cal_view; + + g_return_val_if_fail (EA_IS_CAL_VIEW_EVENT (accessible), NULL); + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (g_obj == NULL) + /* Object is defunct */ + return NULL; + canvas_item = GNOME_CANVAS_ITEM (g_obj); + + cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item); + + if (!cal_view) + return NULL; + + return gtk_widget_get_accessible (GTK_WIDGET (cal_view)); +} + +static gint +ea_cal_view_event_get_index_in_parent (AtkObject *accessible) +{ + GObject *g_obj; + GnomeCanvasItem *canvas_item; + ECalendarView *cal_view; + ECalendarViewEvent *cal_view_event; + + g_return_val_if_fail (EA_IS_CAL_VIEW_EVENT (accessible), -1); + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + /* defunct object*/ + return -1; + + canvas_item = GNOME_CANVAS_ITEM (g_obj); + cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item); + if (!cal_view) + return -1; + + cal_view_event = ea_calendar_helpers_get_cal_view_event_from (canvas_item); + if (!cal_view_event) + return -1; + + if (E_IS_DAY_VIEW (cal_view)) { + gint day, event_num, num_before; + EDayViewEvent *day_view_event; + EDayView *day_view = E_DAY_VIEW (cal_view); + + /* the long event comes first in the order */ + for (event_num = day_view->long_events->len - 1; event_num >= 0; + --event_num) { + day_view_event = &g_array_index (day_view->long_events, + EDayViewEvent, event_num); + if (cal_view_event == (ECalendarViewEvent*)day_view_event) + return event_num; + + } + num_before = day_view->long_events->len; + + for (day = 0; day < day_view->days_shown; ++day) { + for (event_num = day_view->events[day]->len - 1; event_num >= 0; + --event_num) { + day_view_event = &g_array_index (day_view->events[day], + EDayViewEvent, event_num); + if (cal_view_event == (ECalendarViewEvent*)day_view_event) + return num_before + event_num; + } + num_before += day_view->events[day]->len; + } + } + else if (E_IS_WEEK_VIEW (cal_view)) { + AtkObject *atk_parent, *atk_child; + gint index = 0; + + atk_parent = atk_object_get_parent (accessible); + while ((atk_child = atk_object_ref_accessible_child (atk_parent, + index)) != NULL) { + if (atk_child == accessible) { + g_object_unref (atk_child); + return index; + } + g_object_unref (atk_child); + ++index; + } + } + else { + g_return_val_if_reached (-1); + } + return -1; +} + +static AtkStateSet * +ea_cal_view_event_ref_state_set (AtkObject *accessible) +{ + EaCalViewEvent *atk_event = EA_CAL_VIEW_EVENT (accessible); + + g_return_val_if_fail (atk_event->state_set, NULL); + + g_object_ref (atk_event->state_set); + + return atk_event->state_set; +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = ea_cal_view_get_extents; +} + +static void +ea_cal_view_get_extents (AtkComponent *component, + gint *x, + gint *y, + gint *width, + gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + GnomeCanvasItem *canvas_item; + gint x_window, y_window; + gint scroll_x, scroll_y; + ECalendarView *cal_view; + gint item_x, item_y, item_w, item_h; + GtkWidget *canvas = NULL; + + g_return_if_fail (EA_IS_CAL_VIEW_EVENT (component)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + g_return_if_fail (E_IS_TEXT (g_obj)); + + canvas_item = GNOME_CANVAS_ITEM (g_obj); + cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item); + if (!cal_view) + return; + + if (E_IS_DAY_VIEW (cal_view)) { + gint day, event_num; + + if (!e_day_view_find_event_from_item (E_DAY_VIEW (cal_view), + canvas_item, + &day, &event_num)) + return; + if (day == E_DAY_VIEW_LONG_EVENT) { + gint start_day, end_day; + if (!e_day_view_get_long_event_position (E_DAY_VIEW (cal_view), + event_num, + &start_day, + &end_day, + &item_x, + &item_y, + &item_w, + &item_h)) + return; + canvas = E_DAY_VIEW (cal_view)->top_canvas; + } + else { + if (!e_day_view_get_event_position (E_DAY_VIEW (cal_view), day, + event_num, + &item_x, &item_y, + &item_w, &item_h)) + + return; + canvas = E_DAY_VIEW (cal_view)->main_canvas; + } + } + else if (E_IS_WEEK_VIEW (cal_view)) { + gint event_num, span_num; + if (!e_week_view_find_event_from_item (E_WEEK_VIEW (cal_view), + canvas_item, &event_num, + &span_num)) + return; + + if (!e_week_view_get_span_position (E_WEEK_VIEW (cal_view), + event_num, span_num, + &item_x, &item_y, &item_w)) + return; + item_h = E_WEEK_VIEW_ICON_HEIGHT; + canvas = E_WEEK_VIEW (cal_view)->main_canvas; + } + else + return; + + if (!canvas) + return; + + gdk_window_get_origin (canvas->window, + &x_window, &y_window); + gnome_canvas_get_scroll_offsets (GNOME_CANVAS (canvas), &scroll_x, &scroll_y); + + *x = item_x + x_window - scroll_x; + *y = item_y + y_window - scroll_y; + *width = item_w; + *height = item_h; + + if (coord_type == ATK_XY_WINDOW) { + GdkWindow *window; + gint x_toplevel, y_toplevel; + + window = gdk_window_get_toplevel (GTK_WIDGET (cal_view)->window); + gdk_window_get_origin (window, &x_toplevel, &y_toplevel); + + *x -= x_toplevel; + *y -= y_toplevel; + } + +#ifdef ACC_DEBUG + printf ("Event Bounds (%d, %d, %d, %d)\n", *x, *y, *width, *height); +#endif +} + +#define CAL_VIEW_EVENT_ACTION_NUM 1 + +static const gchar * action_name [CAL_VIEW_EVENT_ACTION_NUM] = { + N_("Grab Focus") +}; + +static void +atk_action_interface_init (AtkActionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->do_action = ea_cal_view_event_do_action; + iface->get_n_actions = ea_cal_view_event_get_n_actions; + iface->get_name = ea_cal_view_event_action_get_name; +} + +static gboolean +ea_cal_view_event_do_action (AtkAction *action, gint i) +{ + AtkGObjectAccessible *atk_gobj; + AtkComponent *atk_comp; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (action); + + if (i == 0) { + atk_comp = (AtkComponent *)atk_gobj; + return atk_component_grab_focus (atk_comp); + } + + return FALSE; + +} + +static gint +ea_cal_view_event_get_n_actions (AtkAction *action) +{ + return CAL_VIEW_EVENT_ACTION_NUM; +} + +static G_CONST_RETURN gchar * +ea_cal_view_event_action_get_name (AtkAction *action, gint i) +{ + if (i >= 0 && i < CAL_VIEW_EVENT_ACTION_NUM) + return action_name [i]; + return NULL; +} + diff --git a/calendar/gui/ea-cal-view-event.h b/calendar/gui/ea-cal-view-event.h new file mode 100644 index 0000000000..548e42b4a7 --- /dev/null +++ b/calendar/gui/ea-cal-view-event.h @@ -0,0 +1,58 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_CAL_VIEW_EVENT_H__ +#define __EA_CAL_VIEW_EVENT_H__ + +#include <atk/atkgobjectaccessible.h> + +G_BEGIN_DECLS + +#define EA_TYPE_CAL_VIEW_EVENT (ea_cal_view_event_get_type ()) +#define EA_CAL_VIEW_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CAL_VIEW_EVENT, EaCalViewEvent)) +#define EA_CAL_VIEW_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CAL_VIEW_EVENT, EaCalViewEventClass)) +#define EA_IS_CAL_VIEW_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CAL_VIEW_EVENT)) +#define EA_IS_CAL_VIEW_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CAL_VIEW_EVENT)) +#define EA_CAL_VIEW_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CAL_VIEW_EVENT, EaCalViewEventClass)) + +typedef struct _EaCalViewEvent EaCalViewEvent; +typedef struct _EaCalViewEventClass EaCalViewEventClass; + +struct _EaCalViewEvent +{ + AtkGObjectAccessible parent; + AtkStateSet *state_set; +}; + +GType ea_cal_view_event_get_type (void); + +struct _EaCalViewEventClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject *ea_cal_view_event_new (GObject *obj); + +G_END_DECLS + + +#endif /* __EA_CAL_VIEW_EVENT_H__ */ diff --git a/calendar/gui/ea-cal-view.c b/calendar/gui/ea-cal-view.c new file mode 100644 index 0000000000..952afcc791 --- /dev/null +++ b/calendar/gui/ea-cal-view.c @@ -0,0 +1,426 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-cal-view.h" +#include "ea-calendar-helpers.h" +#include "e-day-view.h" +#include "e-week-view.h" +#include "calendar-commands.h" +#include "goto.h" +#include <glib.h> +#include <glib/gi18n.h> + +static void ea_cal_view_class_init (EaCalViewClass *klass); + +static AtkObject* ea_cal_view_get_parent (AtkObject *accessible); +static void ea_cal_view_real_initialize (AtkObject *accessible, gpointer data); + +static void ea_cal_view_event_changed_cb (ECalendarView *cal_view, + ECalendarViewEvent *event, gpointer data); +static void ea_cal_view_event_added_cb (ECalendarView *cal_view, + ECalendarViewEvent *event, gpointer data); + +static gboolean idle_dates_changed (gpointer data); +static void ea_cal_view_dates_change_cb (GnomeCalendar *gcal, gpointer data); + +static void atk_action_interface_init (AtkActionIface *iface); +static gboolean action_interface_do_action (AtkAction *action, gint i); +static gint action_interface_get_n_actions (AtkAction *action); +static G_CONST_RETURN gchar * +action_interface_get_description(AtkAction *action, gint i); +static G_CONST_RETURN gchar * +action_interface_get_keybinding (AtkAction *action, gint i); +static G_CONST_RETURN gchar * +action_interface_action_get_name(AtkAction *action, gint i); + +static gpointer parent_class = NULL; + +GType +ea_cal_view_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaCalViewClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_cal_view_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaCalView), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_action_info = { + (GInterfaceInitFunc) atk_action_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (GailWidget, in this case) + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + GTK_TYPE_WIDGET); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaCalView", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_ACTION, + &atk_action_info); + } + + return type; +} + +static void +ea_cal_view_class_init (EaCalViewClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + class->get_parent = ea_cal_view_get_parent; + class->initialize = ea_cal_view_real_initialize; +} + +AtkObject* +ea_cal_view_new (GtkWidget *widget) +{ + GObject *object; + AtkObject *accessible; + + g_return_val_if_fail (E_IS_CALENDAR_VIEW (widget), NULL); + + object = g_object_new (EA_TYPE_CAL_VIEW, NULL); + + accessible = ATK_OBJECT (object); + atk_object_initialize (accessible, widget); + + return accessible; +} + +static void +ea_cal_view_real_initialize (AtkObject *accessible, gpointer data) +{ + ECalendarView *cal_view; + GnomeCalendar *gcal; + static AtkRole role = ATK_ROLE_INVALID; + + g_return_if_fail (EA_IS_CAL_VIEW (accessible)); + g_return_if_fail (E_IS_CALENDAR_VIEW (data)); + + ATK_OBJECT_CLASS (parent_class)->initialize (accessible, data); + if (role == ATK_ROLE_INVALID) + role = atk_role_register ("Calendar View"); + accessible->role = role; + cal_view = E_CALENDAR_VIEW (data); + + /* add listener for event_changed, event_added + * we don't need to listen on event_removed. When the e_text + * of the event is removed, the cal_view_event will go to the state + * of "defunct" (changed by weak ref callback of atkgobjectaccessible + */ + g_signal_connect (G_OBJECT(cal_view), "event_changed", + G_CALLBACK (ea_cal_view_event_changed_cb), NULL); + g_signal_connect (G_OBJECT(cal_view), "event_added", + G_CALLBACK (ea_cal_view_event_added_cb), NULL); + + /* listen for date changes of calendar */ + gcal = e_calendar_view_get_calendar (cal_view); + + if (gcal) + g_signal_connect (gcal, "dates_shown_changed", + G_CALLBACK (ea_cal_view_dates_change_cb), + accessible); +} + +static AtkObject* +ea_cal_view_get_parent (AtkObject *accessible) +{ + ECalendarView *cal_view; + GnomeCalendar *gnomeCalendar; + + g_return_val_if_fail (EA_IS_CAL_VIEW (accessible), NULL); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + cal_view = E_CALENDAR_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + gnomeCalendar = e_calendar_view_get_calendar (cal_view); + + return gtk_widget_get_accessible (GTK_WIDGET(gnomeCalendar)); +} + +static void +ea_cal_view_event_changed_cb (ECalendarView *cal_view, ECalendarViewEvent *event, + gpointer data) +{ + AtkObject *atk_obj; + AtkObject *event_atk_obj = NULL; + + g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view)); + + atk_obj = gtk_widget_get_accessible (GTK_WIDGET(cal_view)); + if (!EA_IS_CAL_VIEW (atk_obj)) + return; + + if ((E_IS_DAY_VIEW (cal_view)) && event && event->canvas_item) { + event_atk_obj = + ea_calendar_helpers_get_accessible_for (event->canvas_item); + } + else if ((E_IS_WEEK_VIEW (cal_view)) && event) { + EWeekViewEventSpan *span; + EWeekViewEvent *week_view_event = (EWeekViewEvent *)event; + EWeekView *week_view = E_WEEK_VIEW (cal_view); + /* get the first span of the event */ + span = &g_array_index (week_view->spans, EWeekViewEventSpan, + week_view_event->spans_index); + if (span && span->text_item) + event_atk_obj = ea_calendar_helpers_get_accessible_for (span->text_item); + } + if (event_atk_obj) { +#ifdef ACC_DEBUG + printf ("AccDebug: event=%p changed\n", (gpointer)event); +#endif + g_object_notify (G_OBJECT(event_atk_obj), "accessible-name"); + g_signal_emit_by_name (event_atk_obj, "visible_data_changed"); + } + +} + +static void +ea_cal_view_event_added_cb (ECalendarView *cal_view, ECalendarViewEvent *event, + gpointer data) +{ + AtkObject *atk_obj; + AtkObject *event_atk_obj = NULL; + gint index; + + g_return_if_fail (E_IS_CALENDAR_VIEW (cal_view)); + + atk_obj = gtk_widget_get_accessible (GTK_WIDGET(cal_view)); + if (!EA_IS_CAL_VIEW (atk_obj)) + return; + + if ((E_IS_DAY_VIEW (cal_view)) && event && event->canvas_item) { + event_atk_obj = + ea_calendar_helpers_get_accessible_for (event->canvas_item); + } + else if ((E_IS_WEEK_VIEW (cal_view)) && event) { + EWeekViewEventSpan *span; + EWeekViewEvent *week_view_event = (EWeekViewEvent *)event; + EWeekView *week_view = E_WEEK_VIEW (cal_view); + /* get the first span of the event */ + span = &g_array_index (week_view->spans, EWeekViewEventSpan, + week_view_event->spans_index); + if (span && span->text_item) + event_atk_obj = ea_calendar_helpers_get_accessible_for (span->text_item); + + } + if (event_atk_obj) { + index = atk_object_get_index_in_parent (event_atk_obj); + if (index < 0) + return; +#ifdef ACC_DEBUG + printf ("AccDebug: event=%p added\n", (gpointer)event); +#endif + g_signal_emit_by_name (atk_obj, "children_changed::add", + index, event_atk_obj, NULL); + } +} + +static gboolean +idle_dates_changed (gpointer data) +{ + AtkObject *ea_cal_view; + + g_return_val_if_fail (data, FALSE); + g_return_val_if_fail (EA_IS_CAL_VIEW (data), FALSE); + + ea_cal_view = ATK_OBJECT(data); + + if (ea_cal_view->name) { + g_free (ea_cal_view->name); + ea_cal_view->name = NULL; + } + g_object_notify (G_OBJECT (ea_cal_view), "accessible-name"); + g_signal_emit_by_name (ea_cal_view, "visible_data_changed"); + g_signal_emit_by_name (ea_cal_view, "children_changed", NULL, NULL, NULL); +#ifdef ACC_DEBUG + printf ("AccDebug: cal view date changed\n"); +#endif + + return FALSE; +} + +static void +ea_cal_view_dates_change_cb (GnomeCalendar *gcal, gpointer data) +{ + g_idle_add (idle_dates_changed, data); +} + +/* atk action interface */ + +#define CAL_VIEW_ACTION_NUM 5 + +static const gchar * action_name [CAL_VIEW_ACTION_NUM] = { + N_("New Appointment"), + N_("New All Day Event"), + N_("New Meeting"), + N_("Go to Today"), + N_("Go to Date") +}; + +static void +atk_action_interface_init (AtkActionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->do_action = action_interface_do_action; + iface->get_n_actions = action_interface_get_n_actions; + iface->get_description = action_interface_get_description; + iface->get_keybinding = action_interface_get_keybinding; + iface->get_name = action_interface_action_get_name; +} + +static gboolean +action_interface_do_action (AtkAction *action, gint index) +{ + GtkWidget *widget; + gboolean return_value = TRUE; + time_t dtstart, dtend; + ECalendarView *cal_view; + + widget = GTK_ACCESSIBLE (action)->widget; + if (widget == NULL) + /* + * State is defunct + */ + return FALSE; + + if (!GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget)) + return FALSE; + + cal_view = E_CALENDAR_VIEW (widget); + switch (index) { + case 0: + /* New Appointment */ + e_calendar_view_new_appointment (cal_view); + break; + case 1: + /* New All Day Event */ + e_calendar_view_get_selected_time_range (cal_view, + &dtstart, &dtend); + e_calendar_view_new_appointment_for (cal_view, + dtstart, dtend, TRUE, FALSE); + break; + case 2: + /* New Meeting */ + e_calendar_view_get_selected_time_range (cal_view, + &dtstart, &dtend); + e_calendar_view_new_appointment_for (cal_view, + dtstart, dtend, FALSE, TRUE); + break; + case 3: + /* Go to today */ + break; + calendar_goto_today (e_calendar_view_get_calendar (cal_view)); + case 4: + /* Go to date */ + goto_dialog (e_calendar_view_get_calendar (cal_view)); + break; + default: + return_value = FALSE; + break; + } + return return_value; +} + +static gint +action_interface_get_n_actions (AtkAction *action) +{ + return CAL_VIEW_ACTION_NUM; +} + +static G_CONST_RETURN gchar * +action_interface_get_description(AtkAction *action, gint index) +{ + return action_interface_action_get_name (action, index); +} + +static G_CONST_RETURN gchar * +action_interface_get_keybinding (AtkAction *action, gint index) +{ + GtkWidget *widget; + + widget = GTK_ACCESSIBLE (action)->widget; + if (widget == NULL) + /* + * State is defunct + */ + return NULL; + + if (!GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget)) + return NULL; + + switch (index) { + case 0: + /* New Appointment */ + return "<Alt>fna;<Control>n"; + case 1: + /* New Event */ + return "<Alt>fnd;<Shift><Control>d"; + case 2: + /* New Meeting */ + return "<Alt>fne;<Shift><Control>e"; + case 3: + /* Go to today */ + return "<Alt>vt;<Alt><Control>t"; + case 4: + /* Go to date */ + return "<Alt>vd;<Alt><Control>g"; + default: + break; + } + return NULL; +} + +static G_CONST_RETURN gchar * +action_interface_action_get_name(AtkAction *action, gint i) +{ + if (i >= 0 && i < CAL_VIEW_ACTION_NUM) + return action_name [i]; + return NULL; +} diff --git a/calendar/gui/ea-cal-view.h b/calendar/gui/ea-cal-view.h new file mode 100644 index 0000000000..959f7816b5 --- /dev/null +++ b/calendar/gui/ea-cal-view.h @@ -0,0 +1,58 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_CAL_VIEW_H__ +#define __EA_CAL_VIEW_H__ + +#include <gtk/gtk.h> +#include "e-calendar-view.h" + +G_BEGIN_DECLS + +#define EA_TYPE_CAL_VIEW (ea_cal_view_get_type ()) +#define EA_CAL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CAL_VIEW, EaCalView)) +#define EA_CAL_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CAL_VIEW, EaCalViewClass)) +#define EA_IS_CAL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CAL_VIEW)) +#define EA_IS_CAL_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CAL_VIEW)) +#define EA_CAL_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CAL_VIEW, EaCalViewClass)) + +typedef struct _EaCalView EaCalView; +typedef struct _EaCalViewClass EaCalViewClass; + +struct _EaCalView +{ + GtkAccessible parent; +}; + +GType ea_cal_view_get_type (void); + +struct _EaCalViewClass +{ + GtkAccessibleClass parent_class; +}; + +AtkObject* ea_cal_view_new (GtkWidget *widget); + +G_END_DECLS + +#endif /* __EA_CAL_VIEW_H__ */ diff --git a/calendar/gui/ea-calendar-helpers.c b/calendar/gui/ea-calendar-helpers.c new file mode 100644 index 0000000000..f07cdfa086 --- /dev/null +++ b/calendar/gui/ea-calendar-helpers.c @@ -0,0 +1,156 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-calendar-helpers.h" +#include "ea-cal-view-event.h" +#include "ea-jump-button.h" +#include "e-day-view.h" +#include "e-week-view.h" + +#include <text/e-text.h> +#include <libgnomecanvas/gnome-canvas-pixbuf.h> + +/** + * ea_calendar_helpers_get_accessible_for + * @canvas_item: the canvas item for a event or a jump button + * @returns: the atk object for the canvas_item + * + **/ +AtkObject * +ea_calendar_helpers_get_accessible_for (GnomeCanvasItem *canvas_item) +{ + AtkObject *atk_obj = NULL; + GObject *g_obj; + + g_return_val_if_fail ((E_IS_TEXT (canvas_item)) || (GNOME_IS_CANVAS_ITEM (canvas_item)), NULL);; + + g_obj = G_OBJECT (canvas_item); + /* we cannot use atk_gobject_accessible_for_object here, + * EaDayViewEvent/EaWeekViewEvent cannot be created by the + * registered facotry of E_TEXT + */ + atk_obj = g_object_get_data (g_obj, "accessible-object"); + if (!atk_obj) { + if (E_IS_TEXT (canvas_item)) { + atk_obj = ea_cal_view_event_new (g_obj); + } + else if (GNOME_IS_CANVAS_PIXBUF(canvas_item)) { + atk_obj = ea_jump_button_new (g_obj); + } + else + return NULL; + } + return atk_obj; +} + +/** + * ea_calendar_helpers_get_view_widget_from: + * @canvas_item: the canvas item for a event or a jump button + * @returns: the cal view widget if exists + * + * Get the cal view widget contains the canvas_item. + * + **/ +ECalendarView * +ea_calendar_helpers_get_cal_view_from (GnomeCanvasItem *canvas_item) +{ + GnomeCanvas *canvas; + GtkWidget *view_widget = NULL; + + g_return_val_if_fail (canvas_item, NULL); + g_return_val_if_fail ((E_IS_TEXT (canvas_item)) || (GNOME_IS_CANVAS_ITEM (canvas_item)), NULL); + + /* canvas_item is the e_text for the event */ + /* canvas_item->canvas is the ECanvas for day view */ + /* parent of canvas_item->canvas is the EDayView or EWeekView widget */ + canvas = canvas_item->canvas; + view_widget = gtk_widget_get_parent (GTK_WIDGET(canvas)); + if (!view_widget || !E_IS_CALENDAR_VIEW (view_widget)) + return NULL; + + return E_CALENDAR_VIEW (view_widget); +} + +/** + * ea_calendar_helpers_get_cal_view_event_from + * @canvas_item: the cavas_item (e_text) for the event + * @returns: the ECalendarViewEvent + * + * Get the ECalendarViewEvent for the canvas_item. + * + **/ +ECalendarViewEvent * +ea_calendar_helpers_get_cal_view_event_from (GnomeCanvasItem *canvas_item) +{ + ECalendarView *cal_view; + gboolean event_found; + ECalendarViewEvent *cal_view_event; + + g_return_val_if_fail (E_IS_TEXT (canvas_item), NULL); + + cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item); + + if (!cal_view) + return NULL; + + if (E_IS_DAY_VIEW (cal_view)) { + gint event_day, event_num; + EDayViewEvent *day_view_event; + EDayView *day_view = E_DAY_VIEW (cal_view); + event_found = e_day_view_find_event_from_item (day_view, canvas_item, + &event_day, &event_num); + if (!event_found) + return NULL; + if (event_day == E_DAY_VIEW_LONG_EVENT) { + /* a long event */ + day_view_event = &g_array_index (day_view->long_events, + EDayViewEvent, event_num); + } + else { + /* a main canvas event */ + day_view_event = &g_array_index (day_view->events[event_day], + EDayViewEvent, event_num); + } + cal_view_event = (ECalendarViewEvent *) day_view_event; + } + else if (E_IS_WEEK_VIEW (cal_view)) { + gint event_num, span_num; + EWeekViewEvent *week_view_event; + EWeekView *week_view = E_WEEK_VIEW (cal_view); + event_found = e_week_view_find_event_from_item (week_view, + canvas_item, + &event_num, + &span_num); + if (!event_found) + return NULL; + + week_view_event = &g_array_index (week_view->events, EWeekViewEvent, + event_num); + + cal_view_event = (ECalendarViewEvent *)week_view_event; + } + else { + g_return_val_if_reached (NULL); + } + return cal_view_event; +} diff --git a/calendar/gui/control-factory.h b/calendar/gui/ea-calendar-helpers.h index c79d70b5ba..a4045cd7af 100644 --- a/calendar/gui/control-factory.h +++ b/calendar/gui/ea-calendar-helpers.h @@ -15,17 +15,27 @@ * * * Authors: - * Ettore Perazzoli <ettore@ximian.com> + * Bolian Yin <bolian.yin@sun.com> * * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * */ -#ifndef _CONTROL_FACTORY_H_ -#define _CONTROL_FACTORY_H_ +/* Evolution Accessibility + */ + +#ifndef _EA_CALENDAR_HELPERS_H__ +#define _EA_CALENDAR_HELPERS_H__ + +#include "ea-cal-view.h" + +AtkObject * +ea_calendar_helpers_get_accessible_for (GnomeCanvasItem *canvas_item); -#include <bonobo/bonobo-control.h> +ECalendarView * +ea_calendar_helpers_get_cal_view_from (GnomeCanvasItem *canvas_item); -BonoboControl *control_factory_new_control (void); +ECalendarViewEvent * +ea_calendar_helpers_get_cal_view_event_from (GnomeCanvasItem *canvas_item); -#endif /* _CONTROL_FACTORY_H_ */ +#endif /* _EA_CALENDAR_HELPERS_H__ */ diff --git a/calendar/gui/ea-calendar.c b/calendar/gui/ea-calendar.c new file mode 100644 index 0000000000..d09efae4d2 --- /dev/null +++ b/calendar/gui/ea-calendar.c @@ -0,0 +1,204 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include <text/e-text.h> +#include <libgnomecanvas/gnome-canvas-pixbuf.h> +#include "ea-calendar-helpers.h" +#include "a11y/ea-factory.h" +#include "ea-calendar.h" + +#include "calendar/ea-cal-view.h" +#include "calendar/ea-cal-view-event.h" +#include "calendar/ea-day-view.h" +#include "calendar/ea-day-view-main-item.h" +#include "calendar/ea-week-view.h" +#include "calendar/ea-week-view-main-item.h" +#include "calendar/ea-gnome-calendar.h" + + +EA_FACTORY (EA_TYPE_CAL_VIEW, ea_cal_view, ea_cal_view_new) +EA_FACTORY (EA_TYPE_DAY_VIEW, ea_day_view, ea_day_view_new) +EA_FACTORY_GOBJECT (EA_TYPE_DAY_VIEW_MAIN_ITEM, ea_day_view_main_item, ea_day_view_main_item_new) +EA_FACTORY (EA_TYPE_WEEK_VIEW, ea_week_view, ea_week_view_new) +EA_FACTORY_GOBJECT (EA_TYPE_WEEK_VIEW_MAIN_ITEM, ea_week_view_main_item, ea_week_view_main_item_new) +EA_FACTORY (EA_TYPE_GNOME_CALENDAR, ea_gnome_calendar, ea_gnome_calendar_new) + +static gboolean ea_calendar_focus_watcher (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data); + +static gpointer e_text_type, pixbuf_type, e_day_view_type, e_week_view_type; +static gpointer e_day_view_main_item_type, e_week_view_main_item_type; + +void +gnome_calendar_a11y_init (void) +{ + /* we only add focus watcher when accessibility is enabled + */ + if (atk_get_root ()) { + EA_SET_FACTORY (gnome_calendar_get_type(), ea_gnome_calendar); + + /* force loading some types */ + e_text_type = g_type_class_ref (E_TYPE_TEXT); + pixbuf_type = g_type_class_ref (GNOME_TYPE_CANVAS_PIXBUF); + e_day_view_type = g_type_class_ref (e_day_view_get_type ()); + e_week_view_type = g_type_class_ref (e_week_view_get_type ()); + e_day_view_main_item_type = g_type_class_ref (e_day_view_main_item_get_type ()); + e_week_view_main_item_type = g_type_class_ref (e_week_view_main_item_get_type ()); + + g_signal_add_emission_hook (g_signal_lookup ("event", E_TYPE_TEXT), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + g_signal_add_emission_hook (g_signal_lookup ("event", GNOME_TYPE_CANVAS_PIXBUF), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + g_signal_add_emission_hook (g_signal_lookup ("event-after", + e_day_view_get_type()), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + g_signal_add_emission_hook (g_signal_lookup ("event", + e_day_view_main_item_get_type()), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + g_signal_add_emission_hook (g_signal_lookup ("event-after", + e_week_view_get_type()), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + g_signal_add_emission_hook (g_signal_lookup ("event", + e_week_view_main_item_get_type()), + 0, ea_calendar_focus_watcher, + NULL, (GDestroyNotify) NULL); + + } +} + +void +e_cal_view_a11y_init (void) +{ + EA_SET_FACTORY (e_calendar_view_get_type(), ea_cal_view); +} + +void +e_day_view_a11y_init (void) +{ + EA_SET_FACTORY (e_day_view_get_type(), ea_day_view); +} + +void +e_day_view_main_item_a11y_init (void) +{ + EA_SET_FACTORY (e_day_view_main_item_get_type (), ea_day_view_main_item); +} + +void +e_week_view_a11y_init (void) +{ + EA_SET_FACTORY (e_week_view_get_type(), ea_week_view); +} + +void +e_week_view_main_item_a11y_init (void) +{ + EA_SET_FACTORY (e_week_view_main_item_get_type (), ea_week_view_main_item); +} + +static gboolean +ea_calendar_focus_watcher (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data) +{ + GObject *object; + GdkEvent *event; + AtkObject *ea_event = NULL; + + object = g_value_get_object (param_values + 0); + event = g_value_get_boxed (param_values + 1); + + if ((E_IS_TEXT (object)) || (GNOME_IS_CANVAS_PIXBUF (object))) { + /* "event" signal on canvas item + */ + GnomeCanvasItem *canvas_item; + + canvas_item = GNOME_CANVAS_ITEM (object); + if (event->type == GDK_FOCUS_CHANGE) { + if (event->focus_change.in) { + ea_event = + ea_calendar_helpers_get_accessible_for (canvas_item); + if (!ea_event) + /* not canvas item we want */ + return TRUE; + + } + atk_focus_tracker_notify (ea_event); + } + } + else if (E_IS_DAY_VIEW (object)) { + EDayView *day_view = E_DAY_VIEW (object); + if (event->type == GDK_FOCUS_CHANGE) { + if (event->focus_change.in) { + /* give main item chance to emit focus */ + gnome_canvas_item_grab_focus (day_view->main_canvas_item); + } + } + } + else if (E_IS_DAY_VIEW_MAIN_ITEM (object)) { + if (event->type == GDK_FOCUS_CHANGE) { + if (event->focus_change.in) { + /* we should emit focus on main item */ + ea_event = atk_gobject_accessible_for_object (object); + } + else + /* focus out */ + ea_event = NULL; +#ifdef ACC_DEBUG + printf ("EvoAcc: focus notify on day main item %p\n", (gpointer)object); +#endif + atk_focus_tracker_notify (ea_event); + } + } else if (E_IS_WEEK_VIEW (object)) { + EWeekView *week_view = E_WEEK_VIEW (object); + if (event->type == GDK_FOCUS_CHANGE) { + if (event->focus_change.in) { + /* give main item chance to emit focus */ + gnome_canvas_item_grab_focus (week_view->main_canvas_item); + } + } + } + else if (E_IS_WEEK_VIEW_MAIN_ITEM (object)) { + if (event->type == GDK_FOCUS_CHANGE) { + if (event->focus_change.in) { + /* we should emit focus on main item */ + ea_event = atk_gobject_accessible_for_object (object); + } + else + /* focus out */ + ea_event = NULL; +#ifdef ACC_DEBUG + printf ("EvoAcc: focus notify on week main item %p\n", (gpointer)object); +#endif + atk_focus_tracker_notify (ea_event); + } + } + return TRUE; +} diff --git a/calendar/gui/itip-bonobo-control.h b/calendar/gui/ea-calendar.h index c79b8f7d09..b2238ffdbc 100644 --- a/calendar/gui/itip-bonobo-control.h +++ b/calendar/gui/ea-calendar.h @@ -1,7 +1,5 @@ /* * - * Evolution calendar - Control for displaying iTIP mail messages - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -17,18 +15,23 @@ * * * Authors: - * Jesse Pavel <jpavel@ximian.com> - * JP Rosevear <jpr@ximian.com> + * Bolian Yin <bolian.yin@sun.com> * * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * */ -#ifndef __ITIP_CONTROL_FACTORY_H__ -#define __ITIP_CONTROL_FACTORY_H__ +/* Evolution Accessibility +*/ -#include <bonobo/bonobo-control.h> +#ifndef _EA_CALENDAR_H__ +#define _EA_CALENDAR_H__ -BonoboControl *itip_bonobo_control_new (void); +void gnome_calendar_a11y_init (void); +void e_cal_view_a11y_init (void); +void e_day_view_a11y_init (void); +void e_day_view_main_item_a11y_init (void); +void e_week_view_a11y_init (void); +void e_week_view_main_item_a11y_init (void); -#endif /* __ITIP_CONTROL_H__ */ +#endif /* _EA_CALENDAR_H__ */ diff --git a/calendar/gui/ea-day-view-cell.c b/calendar/gui/ea-day-view-cell.c new file mode 100644 index 0000000000..fa491e87ea --- /dev/null +++ b/calendar/gui/ea-day-view-cell.c @@ -0,0 +1,396 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-day-view-cell.h" +#include "ea-day-view-main-item.h" +#include "ea-day-view.h" +#include "a11y/ea-factory.h" + +/* EDayViewCell */ + +static void e_day_view_cell_class_init (EDayViewCellClass *class); + +EA_FACTORY_GOBJECT (EA_TYPE_DAY_VIEW_CELL, ea_day_view_cell, ea_day_view_cell_new) + +GType +e_day_view_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EDayViewCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) e_day_view_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EDayViewCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, + "EDayViewCell", &tinfo, 0); + } + + return type; +} + +static void +e_day_view_cell_class_init (EDayViewCellClass *class) +{ + EA_SET_FACTORY (e_day_view_cell_get_type (), ea_day_view_cell); +} + +EDayViewCell * +e_day_view_cell_new (EDayView *day_view, gint row, gint column) +{ + GObject *object; + EDayViewCell *cell; + + g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL); + + object = g_object_new (E_TYPE_DAY_VIEW_CELL, NULL); + cell = E_DAY_VIEW_CELL (object); + cell->day_view = day_view; + cell->row = row; + cell->column = column; + +#ifdef ACC_DEBUG + printf ("EvoAcc: e_day_view_cell created %p\n", (gpointer)cell); +#endif + + return cell; +} + +/* EaDayViewCell */ + +static void ea_day_view_cell_class_init (EaDayViewCellClass *klass); + +static G_CONST_RETURN gchar * ea_day_view_cell_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_day_view_cell_get_description (AtkObject *accessible); +static AtkStateSet* ea_day_view_cell_ref_state_set (AtkObject *obj); +static AtkObject * ea_day_view_cell_get_parent (AtkObject *accessible); +static gint ea_day_view_cell_get_index_in_parent (AtkObject *accessible); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, + gint *width, gint *height, + AtkCoordType coord_type); +static gboolean component_interface_grab_focus (AtkComponent *component); + +static gpointer parent_class = NULL; + +#ifdef ACC_DEBUG +static gint n_ea_day_view_cell_created = 0, n_ea_day_view_cell_destroyed = 0; +static void ea_day_view_cell_finalize (GObject *object); +#endif + +GType +ea_day_view_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaDayViewCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_day_view_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaDayViewCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + type = g_type_register_static (ATK_TYPE_GOBJECT_ACCESSIBLE, + "EaDayViewCell", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + } + + return type; +} + +static void +ea_day_view_cell_class_init (EaDayViewCellClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + +#ifdef ACC_DEBUG + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = ea_day_view_cell_finalize; +#endif + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_day_view_cell_get_name; + class->get_description = ea_day_view_cell_get_description; + class->ref_state_set = ea_day_view_cell_ref_state_set; + + class->get_parent = ea_day_view_cell_get_parent; + class->get_index_in_parent = ea_day_view_cell_get_index_in_parent; +} + +AtkObject* +ea_day_view_cell_new (GObject *obj) +{ + gpointer object; + AtkObject *atk_object; + + g_return_val_if_fail (E_IS_DAY_VIEW_CELL (obj), NULL); + + object = g_object_new (EA_TYPE_DAY_VIEW_CELL, NULL); + atk_object = ATK_OBJECT (object); + atk_object_initialize (atk_object, obj); + atk_object->role = ATK_ROLE_UNKNOWN; + +#ifdef ACC_DEBUG + ++n_ea_day_view_cell_created; + printf ("ACC_DEBUG: n_ea_day_view_cell_created = %d\n", + n_ea_day_view_cell_created); +#endif + return atk_object; +} + +#ifdef ACC_DEBUG +static void ea_day_view_cell_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); + + ++n_ea_day_view_cell_destroyed; + printf ("ACC_DEBUG: n_ea_day_view_cell_destroyed = %d\n", + n_ea_day_view_cell_destroyed); +} +#endif + +static G_CONST_RETURN gchar * +ea_day_view_cell_get_name (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewCell *cell; + + g_return_val_if_fail (EA_IS_DAY_VIEW_CELL (accessible), NULL); + + if (!accessible->name) { + AtkObject *ea_main_item; + GnomeCanvasItem *main_item; + gchar *new_name = g_strdup (""); + const gchar *row_label, *column_label; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + cell = E_DAY_VIEW_CELL (g_obj); + main_item = cell->day_view->main_canvas_item; + ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item)); + column_label = atk_table_get_column_description (ATK_TABLE (ea_main_item), + cell->column); + row_label = atk_table_get_row_description (ATK_TABLE (ea_main_item), + cell->row); + new_name = g_strconcat (column_label, " ", row_label, NULL); + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, new_name); + g_free (new_name); + } + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_day_view_cell_get_description (AtkObject *accessible) +{ + return ea_day_view_cell_get_name (accessible); +} + +static AtkStateSet* +ea_day_view_cell_ref_state_set (AtkObject *obj) +{ + AtkStateSet *state_set; + GObject *g_obj; + AtkObject *parent; + gint x, y, width, height; + gint parent_x, parent_y, parent_width, parent_height; + + state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj); + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(obj)); + if (!g_obj) + return state_set; + + atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); + + parent = atk_object_get_parent (obj); + atk_component_get_extents (ATK_COMPONENT (obj), &x, &y, + &width, &height, ATK_XY_WINDOW); + atk_component_get_extents (ATK_COMPONENT (parent), &parent_x, &parent_y, + &parent_width, &parent_height, ATK_XY_WINDOW); + + + if (x + width < parent_x || x > parent_x + parent_width || + y + height < parent_y || y > parent_y + parent_height) + /* the cell is out of the main canvas */ + ; + else + atk_state_set_add_state (state_set, ATK_STATE_VISIBLE); + + return state_set; +} + +static AtkObject * +ea_day_view_cell_get_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewCell *cell; + + g_return_val_if_fail (EA_IS_DAY_VIEW_CELL (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + cell = E_DAY_VIEW_CELL (g_obj); + return atk_gobject_accessible_for_object (G_OBJECT (cell->day_view->main_canvas_item)); +} + +static gint +ea_day_view_cell_get_index_in_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewCell *cell; + AtkObject *parent; + + g_return_val_if_fail (EA_IS_DAY_VIEW_CELL (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + cell = E_DAY_VIEW_CELL (g_obj); + parent = atk_object_get_parent (accessible); + return atk_table_get_index_at (ATK_TABLE (parent), + cell->row, cell->column); +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = component_interface_get_extents; + iface->grab_focus = component_interface_grab_focus; +} + +static void +component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + AtkObject *atk_obj; + EDayViewCell *cell; + EDayView *day_view; + GtkWidget *main_canvas; + gint day_view_width, day_view_height; + gint scroll_x, scroll_y; + + *x = *y = *width = *height = 0; + + g_return_if_fail (EA_IS_DAY_VIEW_CELL (component)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + + cell = E_DAY_VIEW_CELL (g_obj); + day_view = cell->day_view; + main_canvas = cell->day_view->main_canvas; + + atk_obj = atk_gobject_accessible_for_object (G_OBJECT (main_canvas)); + atk_component_get_extents (ATK_COMPONENT (atk_obj), + x, y, + &day_view_width, &day_view_height, + coord_type); + gnome_canvas_get_scroll_offsets (GNOME_CANVAS (day_view->main_canvas), + &scroll_x, &scroll_y); + *x += day_view->day_offsets[cell->column] - scroll_x; + *y += day_view->row_height * cell->row + - scroll_y; + *width = day_view->day_widths[cell->column]; + *height = day_view->row_height; +} + +static gboolean +component_interface_grab_focus (AtkComponent *comp) +{ + GObject *g_obj; + EDayViewCell *cell; + EDayView *day_view; + GtkWidget *toplevel; + + g_return_val_if_fail (EA_IS_DAY_VIEW_CELL (comp), FALSE); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (comp)); + if (!g_obj) + return FALSE; + + cell = E_DAY_VIEW_CELL (g_obj); + day_view = cell->day_view; + + day_view->selection_start_day = cell->column; + day_view->selection_end_day = cell->column; + day_view->selection_start_row = cell->row; + day_view->selection_end_row = cell->row; + + e_day_view_ensure_rows_visible (day_view, + day_view->selection_start_row, + day_view->selection_end_row); + e_day_view_update_calendar_selection_time (day_view); + gtk_widget_queue_draw (day_view->main_canvas); + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (day_view)); + if (GTK_WIDGET_TOPLEVEL (toplevel)) + gtk_window_present (GTK_WINDOW (toplevel)); + + return TRUE; +} + diff --git a/calendar/gui/ea-day-view-cell.h b/calendar/gui/ea-day-view-cell.h new file mode 100644 index 0000000000..669fb1abae --- /dev/null +++ b/calendar/gui/ea-day-view-cell.h @@ -0,0 +1,85 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_DAY_VIEW_CELL_H__ +#define __EA_DAY_VIEW_CELL_H__ + +#include <atk/atkgobjectaccessible.h> +#include "e-day-view.h" + +G_BEGIN_DECLS + +#define E_TYPE_DAY_VIEW_CELL (e_day_view_cell_get_type ()) +#define E_DAY_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_DAY_VIEW_CELL, EDayViewCell)) +#define E_DAY_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_DAY_VIEW_CELL, EDayViewCellClass)) +#define E_IS_DAY_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_DAY_VIEW_CELL)) +#define E_IS_DAY_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_DAY_VIEW_CELL)) +#define E_DAY_VIEW_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_DAY_VIEW_CELL, EDayViewCellClass)) + +typedef struct _EDayViewCell EDayViewCell; +typedef struct _EDayViewCellClass EDayViewCellClass; + +struct _EDayViewCell +{ + GObject parent; + EDayView *day_view; + gint row; + gint column; +}; + +GType e_day_view_cell_get_type (void); + +struct _EDayViewCellClass +{ + GObjectClass parent_class; +}; + +EDayViewCell * e_day_view_cell_new (EDayView *day_view, gint row, gint column); + +#define EA_TYPE_DAY_VIEW_CELL (ea_day_view_cell_get_type ()) +#define EA_DAY_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_DAY_VIEW_CELL, EaDayViewCell)) +#define EA_DAY_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_DAY_VIEW_CELL, EaDayViewCellClass)) +#define EA_IS_DAY_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_DAY_VIEW_CELL)) +#define EA_IS_DAY_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_DAY_VIEW_CELL)) +#define EA_DAY_VIEW_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_DAY_VIEW_CELL, EaDayViewCellClass)) + +typedef struct _EaDayViewCell EaDayViewCell; +typedef struct _EaDayViewCellClass EaDayViewCellClass; + +struct _EaDayViewCell +{ + AtkGObjectAccessible parent; +}; + +GType ea_day_view_cell_get_type (void); + +struct _EaDayViewCellClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject* ea_day_view_cell_new (GObject *gobj); + +G_END_DECLS + +#endif /* __EA_DAY_VIEW_CELL_H__ */ diff --git a/calendar/gui/ea-day-view-main-item.c b/calendar/gui/ea-day-view-main-item.c new file mode 100644 index 0000000000..3bfd56f0b3 --- /dev/null +++ b/calendar/gui/ea-day-view-main-item.c @@ -0,0 +1,1289 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-day-view-main-item.h" +#include "e-day-view-top-item.h" +#include "ea-day-view.h" +#include "ea-day-view-cell.h" +#include "ea-cell-table.h" +#include <glib/gi18n.h> + +/* EaDayViewMainItem */ +static void ea_day_view_main_item_class_init (EaDayViewMainItemClass *klass); + +static void ea_day_view_main_item_finalize (GObject *object); +static G_CONST_RETURN gchar * ea_day_view_main_item_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_day_view_main_item_get_description (AtkObject *accessible); + +static gint ea_day_view_main_item_get_n_children (AtkObject *obj); +static AtkObject* ea_day_view_main_item_ref_child (AtkObject *obj, + gint i); +static AtkObject * ea_day_view_main_item_get_parent (AtkObject *accessible); +static gint ea_day_view_main_item_get_index_in_parent (AtkObject *accessible); + +/* callbacks */ +static void ea_day_view_main_item_dates_change_cb (GnomeCalendar *gcal, gpointer data); +static void ea_day_view_main_item_time_change_cb (EDayView *day_view, gpointer data); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, + gint *width, gint *height, + AtkCoordType coord_type); +/* atk table interface */ +static void atk_table_interface_init (AtkTableIface *iface); +static gint table_interface_get_index_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_column_at_index (AtkTable *table, + gint index); +static gint table_interface_get_row_at_index (AtkTable *table, + gint index); +static AtkObject* table_interface_ref_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_n_rows (AtkTable *table); +static gint table_interface_get_n_columns (AtkTable *table); +static gint table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_row_extent_at (AtkTable *table, + gint row, + gint column); + +static gboolean table_interface_is_row_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_column_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_selected (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected); +static gint table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected); +static gboolean table_interface_add_row_selection (AtkTable *table, gint row); +static gboolean table_interface_remove_row_selection (AtkTable *table, + gint row); +static gboolean table_interface_add_column_selection (AtkTable *table, + gint column); +static gboolean table_interface_remove_column_selection (AtkTable *table, + gint column); +static AtkObject* table_interface_get_row_header (AtkTable *table, gint row); +static AtkObject* table_interface_get_column_header (AtkTable *table, + gint in_col); +static AtkObject* table_interface_get_caption (AtkTable *table); + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, gint in_col); + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, gint row); + +static AtkObject* table_interface_get_summary (AtkTable *table); + +/* atk selection interface */ +static void atk_selection_interface_init (AtkSelectionIface *iface); +static gboolean selection_interface_add_selection (AtkSelection *selection, + gint i); +static gboolean selection_interface_clear_selection (AtkSelection *selection); +static AtkObject* selection_interface_ref_selection (AtkSelection *selection, + gint i); +static gint selection_interface_get_selection_count (AtkSelection *selection); +static gboolean selection_interface_is_child_selected (AtkSelection *selection, + gint i); + +/* helpers */ +static EaCellTable * +ea_day_view_main_item_get_cell_data (EaDayViewMainItem *ea_main_item); + +static void +ea_day_view_main_item_destory_cell_data (EaDayViewMainItem *ea_main_item); + +static gint +ea_day_view_main_item_get_child_index_at (EaDayViewMainItem *ea_main_item, + gint row, gint column); +static gint +ea_day_view_main_item_get_row_at_index (EaDayViewMainItem *ea_main_item, + gint index); +static gint +ea_day_view_main_item_get_column_at_index (EaDayViewMainItem *ea_main_item, + gint index); +static gint +ea_day_view_main_item_get_row_label (EaDayViewMainItem *ea_main_item, + gint row, gchar *buffer, + gint buffer_size); + +#ifdef ACC_DEBUG +static gint n_ea_day_view_main_item_created = 0; +static gint n_ea_day_view_main_item_destroyed = 0; +#endif + +static gpointer parent_class = NULL; + +GType +ea_day_view_main_item_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaDayViewMainItemClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_day_view_main_item_class_init, + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaDayViewMainItem), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + static const GInterfaceInfo atk_table_info = { + (GInterfaceInitFunc) atk_table_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + static const GInterfaceInfo atk_selection_info = { + (GInterfaceInitFunc) atk_selection_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (GailCanvasItem, in this case) + * + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + e_day_view_main_item_get_type()); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaDayViewMainItem", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + g_type_add_interface_static (type, ATK_TYPE_TABLE, + &atk_table_info); + g_type_add_interface_static (type, ATK_TYPE_SELECTION, + &atk_selection_info); + } + + return type; +} + +static void +ea_day_view_main_item_class_init (EaDayViewMainItemClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + gobject_class->finalize = ea_day_view_main_item_finalize; + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_day_view_main_item_get_name; + class->get_description = ea_day_view_main_item_get_description; + + class->get_n_children = ea_day_view_main_item_get_n_children; + class->ref_child = ea_day_view_main_item_ref_child; + class->get_parent = ea_day_view_main_item_get_parent; + class->get_index_in_parent = ea_day_view_main_item_get_index_in_parent; +} + +AtkObject* +ea_day_view_main_item_new (GObject *obj) +{ + AtkObject *accessible; + GnomeCalendar *gcal; + EDayViewMainItem *main_item; + + g_return_val_if_fail (E_IS_DAY_VIEW_MAIN_ITEM (obj), NULL); + + accessible = ATK_OBJECT (g_object_new (EA_TYPE_DAY_VIEW_MAIN_ITEM, + NULL)); + + atk_object_initialize (accessible, obj); + accessible->role = ATK_ROLE_TABLE; + +#ifdef ACC_DEBUG + ++n_ea_day_view_main_item_created; + printf ("ACC_DEBUG: n_ea_day_view_main_item_created = %d\n", + n_ea_day_view_main_item_created); +#endif + main_item = E_DAY_VIEW_MAIN_ITEM (obj); + g_signal_connect (main_item->day_view, "selected_time_changed", + G_CALLBACK (ea_day_view_main_item_time_change_cb), + accessible); + + /* listen for date changes of calendar */ + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (main_item->day_view)); + if (gcal) + g_signal_connect (gcal, "dates_shown_changed", + G_CALLBACK (ea_day_view_main_item_dates_change_cb), + accessible); + + return accessible; +} + +static void +ea_day_view_main_item_finalize (GObject *object) +{ + EaDayViewMainItem *ea_main_item; + + g_return_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (object)); + + ea_main_item = EA_DAY_VIEW_MAIN_ITEM (object); + + /* Free the allocated cell data */ + ea_day_view_main_item_destory_cell_data (ea_main_item); + + G_OBJECT_CLASS (parent_class)->finalize (object); +#ifdef ACC_DEBUG + ++n_ea_day_view_main_item_destroyed; + printf ("ACC_DEBUG: n_ea_day_view_main_item_destroyed = %d\n", + n_ea_day_view_main_item_destroyed); +#endif +} + +static G_CONST_RETURN gchar * +ea_day_view_main_item_get_name (AtkObject *accessible) +{ + AtkObject *parent; + g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), NULL); + parent = atk_object_get_parent (accessible); + + if (!parent) + return NULL; + + return atk_object_get_name (parent); +} + +static G_CONST_RETURN gchar * +ea_day_view_main_item_get_description (AtkObject *accessible) +{ + return _("a table to view and select the current time range"); +} + +static gint +ea_day_view_main_item_get_n_children (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + + g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + return day_view->rows * day_view->days_shown; +} + +static AtkObject * +ea_day_view_main_item_ref_child (AtkObject *accessible, gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + gint n_children; + EDayViewCell *cell; + EaCellTable *cell_data; + EaDayViewMainItem *ea_main_item; + + g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + n_children = ea_day_view_main_item_get_n_children (accessible); + if (index < 0 || index >= n_children) + return NULL; + + ea_main_item = EA_DAY_VIEW_MAIN_ITEM (accessible); + cell_data = ea_day_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + + cell = ea_cell_table_get_cell_at_index (cell_data, index); + if (!cell) { + gint row, column; + + row = ea_day_view_main_item_get_row_at_index (ea_main_item, index); + column = ea_day_view_main_item_get_column_at_index (ea_main_item, index); + cell = e_day_view_cell_new (day_view, row, column); + ea_cell_table_set_cell_at_index (cell_data, index, cell); + g_object_unref (cell); + } + return g_object_ref (atk_gobject_accessible_for_object (G_OBJECT(cell))); +} + +static AtkObject * +ea_day_view_main_item_get_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + + g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + return gtk_widget_get_accessible (GTK_WIDGET (main_item->day_view)); +} + +static gint +ea_day_view_main_item_get_index_in_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + + g_return_val_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + /* always the first child of ea-day-view */ + return 0; +} + +/* callbacks */ + +static void +ea_day_view_main_item_dates_change_cb (GnomeCalendar *gcal, gpointer data) +{ + EaDayViewMainItem *ea_main_item; + + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + g_return_if_fail (data); + g_return_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (data)); + + ea_main_item = EA_DAY_VIEW_MAIN_ITEM (data); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_day_view_main_item update cb\n"); +#endif + + ea_day_view_main_item_destory_cell_data (ea_main_item); +} + +static void +ea_day_view_main_item_time_change_cb (EDayView *day_view, gpointer data) +{ + EaDayViewMainItem *ea_main_item; + AtkObject *item_cell = NULL; + + g_return_if_fail (E_IS_DAY_VIEW (day_view)); + g_return_if_fail (data); + g_return_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (data)); + + ea_main_item = EA_DAY_VIEW_MAIN_ITEM (data); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_day_view_main_item time changed cb\n"); +#endif + /* only deal with the first selected child, for now */ + item_cell = atk_selection_ref_selection (ATK_SELECTION (ea_main_item), + 0); + if (item_cell) { + AtkStateSet *state_set; + state_set = atk_object_ref_state_set (item_cell); + atk_state_set_add_state (state_set, ATK_STATE_FOCUSED); + g_object_unref (state_set); + + g_signal_emit_by_name (ea_main_item, + "active-descendant-changed", + item_cell); + g_signal_emit_by_name (data, "selection_changed"); + + atk_focus_tracker_notify (item_cell); + g_object_unref (item_cell); + } + +} + +/* helpers */ + +static gint +ea_day_view_main_item_get_child_index_at (EaDayViewMainItem *ea_main_item, + gint row, gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (row >= 0 && row < day_view->rows && + column >= 0 && column < day_view->days_shown) + return column * day_view->rows + row; + return -1; +} + +static gint +ea_day_view_main_item_get_row_at_index (EaDayViewMainItem *ea_main_item, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + gint n_children; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + n_children = ea_day_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); + if (index >= 0 && index < n_children) + return index % day_view->rows; + return -1; +} + +static gint +ea_day_view_main_item_get_column_at_index (EaDayViewMainItem *ea_main_item, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + gint n_children; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + n_children = ea_day_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); + if (index >= 0 && index < n_children) + return index / day_view->rows; + return -1; +} + +static gint +ea_day_view_main_item_get_row_label (EaDayViewMainItem *ea_main_item, + gint row, gchar *buffer, gint buffer_size) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + const gchar *suffix; + gint hour, minute, suffix_width; + + g_return_val_if_fail (ea_main_item, 0); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return 0; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + hour = day_view->first_hour_shown; + minute = day_view->first_minute_shown; + minute += row * day_view->mins_per_row; + hour = (hour + minute / 60) % 24; + minute %= 60; + + e_day_view_convert_time_to_display (day_view, hour, &hour, + &suffix, &suffix_width); + return g_snprintf (buffer, buffer_size, "%i:%02i %s", + hour, minute, suffix); +} + +static EaCellTable * +ea_day_view_main_item_get_cell_data (EaDayViewMainItem *ea_main_item) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaCellTable *cell_data; + + g_return_val_if_fail (ea_main_item, NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + cell_data = g_object_get_data (G_OBJECT(ea_main_item), + "ea-day-view-cell-table"); + if (!cell_data) { + cell_data = ea_cell_table_create (day_view->rows, + day_view->days_shown, TRUE); + g_object_set_data (G_OBJECT(ea_main_item), + "ea-day-view-cell-table", cell_data); + } + return cell_data; +} + +static void +ea_day_view_main_item_destory_cell_data (EaDayViewMainItem *ea_main_item) +{ + EaCellTable *cell_data; + + g_return_if_fail (ea_main_item); + + cell_data = g_object_get_data (G_OBJECT(ea_main_item), + "ea-day-view-cell-table"); + if (cell_data) { + g_object_set_data (G_OBJECT(ea_main_item), + "ea-day-view-cell-table", NULL); + ea_cell_table_destroy (cell_data); + } +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = component_interface_get_extents; +} + +static void +component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + AtkObject *ea_canvas; + EDayViewMainItem *main_item; + EDayView *day_view; + + *x = *y = *width = *height = 0; + + g_return_if_fail (EA_IS_DAY_VIEW_MAIN_ITEM (component)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + ea_canvas = gtk_widget_get_accessible (day_view->main_canvas); + atk_component_get_extents (ATK_COMPONENT (ea_canvas), x, y, + width, height, coord_type); +} + +/* atk table interface */ + +static void +atk_table_interface_init (AtkTableIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->ref_at = table_interface_ref_at; + + iface->get_n_rows = table_interface_get_n_rows; + iface->get_n_columns = table_interface_get_n_columns; + iface->get_index_at = table_interface_get_index_at; + iface->get_column_at_index = table_interface_get_column_at_index; + iface->get_row_at_index = table_interface_get_row_at_index; + iface->get_column_extent_at = table_interface_get_column_extent_at; + iface->get_row_extent_at = table_interface_get_row_extent_at; + + iface->is_selected = table_interface_is_selected; + iface->get_selected_rows = table_interface_get_selected_rows; + iface->get_selected_columns = table_interface_get_selected_columns; + iface->is_row_selected = table_interface_is_row_selected; + iface->is_column_selected = table_interface_is_column_selected; + iface->add_row_selection = table_interface_add_row_selection; + iface->remove_row_selection = table_interface_remove_row_selection; + iface->add_column_selection = table_interface_add_column_selection; + iface->remove_column_selection = table_interface_remove_column_selection; + + iface->get_row_header = table_interface_get_row_header; + iface->get_column_header = table_interface_get_column_header; + iface->get_caption = table_interface_get_caption; + iface->get_summary = table_interface_get_summary; + iface->get_row_description = table_interface_get_row_description; + iface->get_column_description = table_interface_get_column_description; +} + +static AtkObject* +table_interface_ref_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + index = ea_day_view_main_item_get_child_index_at (ea_main_item, + row, column); + return ea_day_view_main_item_ref_child (ATK_OBJECT (ea_main_item), index); +} + +static gint +table_interface_get_n_rows (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + return day_view->rows; +} + +static gint +table_interface_get_n_columns (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + return day_view->days_shown; +} + +static gint +table_interface_get_index_at (AtkTable *table, + gint row, + gint column) +{ + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + return ea_day_view_main_item_get_child_index_at (ea_main_item, + row, column); +} + +static gint +table_interface_get_column_at_index (AtkTable *table, + gint index) +{ + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + return ea_day_view_main_item_get_column_at_index (ea_main_item, index); +} + +static gint +table_interface_get_row_at_index (AtkTable *table, + gint index) +{ + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + return ea_day_view_main_item_get_row_at_index (ea_main_item, index); +} + +static gint +table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + gint width = 0, height = 0; + AtkObject *child; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + index = ea_day_view_main_item_get_child_index_at (ea_main_item, + row, column); + child = atk_object_ref_accessible_child (ATK_OBJECT (ea_main_item), + index); + if (child) + atk_component_get_size (ATK_COMPONENT (child), + &width, &height); + + return width; +} + +static gint +table_interface_get_row_extent_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + gint width = 0, height = 0; + AtkObject *child; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + index = ea_day_view_main_item_get_child_index_at (ea_main_item, + row, column); + child = atk_object_ref_accessible_child (ATK_OBJECT (ea_main_item), + index); + if (child) + atk_component_get_size (ATK_COMPONENT (child), + &width, &height); + + return height; +} + +static gboolean +table_interface_is_row_selected (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (day_view->selection_start_day == -1) + /* no selection */ + return FALSE; + if (day_view->selection_start_day != day_view->selection_end_day) + /* all row is selected */ + return TRUE; + if (row >= day_view->selection_start_row && + row <= day_view->selection_end_row) + return TRUE; + return FALSE; +} + +static gboolean +table_interface_is_selected (AtkTable *table, + gint row, + gint column) +{ + return table_interface_is_row_selected (table, row) && + table_interface_is_column_selected (table, column); +} + +static gboolean +table_interface_is_column_selected (AtkTable *table, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (column >= day_view->selection_start_day && + column <= day_view->selection_end_day) + return TRUE; + return FALSE; +} + +static gint +table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + gint start_row = -1, n_rows = 0; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (day_view->selection_start_day == -1) + return 0; + + if (day_view->selection_start_day != day_view->selection_end_day) { + /* all the rows should be selected */ + n_rows = day_view->rows; + start_row = 0; + } + else if (day_view->selection_start_row != -1) { + start_row = day_view->selection_start_row; + n_rows = day_view->selection_end_row - start_row + 1; + } + if (n_rows > 0 && start_row != -1 && rows_selected) { + gint index; + + *rows_selected = (gint *) g_malloc (n_rows * sizeof (gint)); + for (index = 0; index < n_rows; ++index) + (*rows_selected)[index] = start_row + index; + } + return n_rows; +} + +static gint +table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + gint start_column = -1, n_columns = 0; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (day_view->selection_start_day == -1) + return 0; + + start_column = day_view->selection_start_day; + n_columns = day_view->selection_end_day - start_column + 1; + if (n_columns > 0 && start_column != -1 && columns_selected) { + gint index; + + *columns_selected = (gint *) g_malloc (n_columns * sizeof (gint)); + for (index = 0; index < n_columns; ++index) + (*columns_selected)[index] = start_column + index; + } + return n_columns; +} + +static gboolean +table_interface_add_row_selection (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + /* FIXME: we need multi-selection */ + + day_view->selection_start_day = 0; + day_view->selection_end_day = 0; + day_view->selection_start_row = row; + day_view->selection_end_row = row; + + e_day_view_ensure_rows_visible (day_view, + day_view->selection_start_row, + day_view->selection_end_row); + e_day_view_update_calendar_selection_time (day_view); + gtk_widget_queue_draw (day_view->main_canvas); + return TRUE; +} + +static gboolean +table_interface_remove_row_selection (AtkTable *table, + gint row) +{ + return FALSE; +} + +static gboolean +table_interface_add_column_selection (AtkTable *table, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + /* FIXME: we need multi-selection */ + + day_view->selection_start_day = column; + day_view->selection_end_day = column; + day_view->selection_start_row = 0; + day_view->selection_end_row = day_view->rows; + + e_day_view_update_calendar_selection_time (day_view); + gtk_widget_queue_draw (day_view->main_canvas); + return TRUE; +} + +static gboolean +table_interface_remove_column_selection (AtkTable *table, + gint column) +{ + /* FIXME: NOT IMPLEMENTED */ + return FALSE; +} + +static AtkObject* +table_interface_get_row_header (AtkTable *table, + gint row) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_column_header (AtkTable *table, + gint in_col) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_caption (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, + gint in_col) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + const gchar *description; + EaCellTable *cell_data; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (in_col < 0 || in_col >= day_view->days_shown) + return NULL; + cell_data = ea_day_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_column_label (cell_data, in_col); + if (!description) { + gchar buffer[128]; + e_day_view_top_item_get_day_label (day_view, in_col, buffer, 128); + ea_cell_table_set_column_label (cell_data, in_col, buffer); + description = ea_cell_table_get_column_label (cell_data, in_col); + } + return description; +} + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (table); + const gchar *description; + EaCellTable *cell_data; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + if (row < 0 || row >= 12 * 24) + return NULL; + cell_data = ea_day_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_row_label (cell_data, row); + if (!description) { + gchar buffer[128]; + ea_day_view_main_item_get_row_label (ea_main_item, row, buffer, sizeof (buffer)); + ea_cell_table_set_row_label (cell_data, row, buffer); + description = ea_cell_table_get_row_label (cell_data, + row); + } + return description; +} + +static AtkObject* +table_interface_get_summary (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +/* atkselection interface */ + +static void +atk_selection_interface_init (AtkSelectionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->add_selection = selection_interface_add_selection; + iface->clear_selection = selection_interface_clear_selection; + iface->ref_selection = selection_interface_ref_selection; + iface->get_selection_count = selection_interface_get_selection_count; + iface->is_child_selected = selection_interface_is_child_selected; +} + +static gboolean +selection_interface_add_selection (AtkSelection *selection, gint i) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); + gint column, row; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + row = ea_day_view_main_item_get_row_at_index (ea_main_item, i); + column = ea_day_view_main_item_get_column_at_index (ea_main_item, i); + + if (row == -1 || column == -1) + return FALSE; + + /*FIXME: multi-selection is needed */ + day_view->selection_start_day = column; + day_view->selection_end_day = column; + day_view->selection_start_row = row; + day_view->selection_end_row = row; + + e_day_view_ensure_rows_visible (day_view, + day_view->selection_start_row, + day_view->selection_end_row); + e_day_view_update_calendar_selection_time (day_view); + gtk_widget_queue_draw (day_view->main_canvas); + return TRUE; +} + +static gboolean +selection_interface_clear_selection (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + day_view->selection_start_row = -1; + day_view->selection_start_day = -1; + day_view->selection_end_row = -1; + day_view->selection_end_day = -1; + + e_day_view_update_calendar_selection_time (day_view); + gtk_widget_queue_draw (day_view->main_canvas); + + return TRUE; +} + +static AtkObject* +selection_interface_ref_selection (AtkSelection *selection, gint i) +{ + gint count; + GObject *g_obj; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); + gint start_index; + + count = selection_interface_get_selection_count (selection); + if (i < 0 || i >=count) + return NULL; + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_main_item)); + day_view = E_DAY_VIEW_MAIN_ITEM (g_obj)->day_view; + start_index = ea_day_view_main_item_get_child_index_at (ea_main_item, + day_view->selection_start_row, + day_view->selection_start_day); + + return ea_day_view_main_item_ref_child (ATK_OBJECT (selection), start_index + i); +} + +static gint +selection_interface_get_selection_count (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); + gint start_index, end_index; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return 0; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + if (day_view->selection_start_day == -1 || + day_view->selection_start_row == -1) + return 0; + start_index = ea_day_view_main_item_get_child_index_at (ea_main_item, + day_view->selection_start_row, + day_view->selection_start_day); + end_index = ea_day_view_main_item_get_child_index_at (ea_main_item, + day_view->selection_end_row, + day_view->selection_end_day); + + return end_index - start_index + 1; +} + +static gboolean +selection_interface_is_child_selected (AtkSelection *selection, gint i) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EDayViewMainItem *main_item; + EDayView *day_view; + EaDayViewMainItem* ea_main_item = EA_DAY_VIEW_MAIN_ITEM (selection); + gint column, row; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_DAY_VIEW_MAIN_ITEM (g_obj); + day_view = main_item->day_view; + + row = ea_day_view_main_item_get_row_at_index (ea_main_item, i); + column = ea_day_view_main_item_get_column_at_index (ea_main_item, i); + + if (column < day_view->selection_start_day || + column > day_view->selection_end_day) + return FALSE; + + if ((column == day_view->selection_start_day || + column == day_view->selection_end_day) && + (row < day_view->selection_start_row || + row > day_view->selection_end_row)) + return FALSE; + + /* if comes here, the cell is selected */ + return TRUE; +} diff --git a/calendar/gui/ea-day-view-main-item.h b/calendar/gui/ea-day-view-main-item.h new file mode 100644 index 0000000000..c782e6acc8 --- /dev/null +++ b/calendar/gui/ea-day-view-main-item.h @@ -0,0 +1,58 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_DAY_VIEW_MAIN_ITEM_H__ +#define __EA_DAY_VIEW_MAIN_ITEM_H__ + +#include <atk/atkgobjectaccessible.h> +#include "e-day-view-main-item.h" + +G_BEGIN_DECLS + +#define EA_TYPE_DAY_VIEW_MAIN_ITEM (ea_day_view_main_item_get_type ()) +#define EA_DAY_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_DAY_VIEW_MAIN_ITEM, EaDayViewMainItem)) +#define EA_DAY_VIEW_MAIN_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_DAY_VIEW_MAIN_ITEM, EaDayViewMainItemClass)) +#define EA_IS_DAY_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_DAY_VIEW_MAIN_ITEM)) +#define EA_IS_DAY_VIEW_MAIN_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_DAY_VIEW_MAIN_ITEM)) +#define EA_DAY_VIEW_MAIN_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_DAY_VIEW_MAIN_ITEM, EaDayViewMainItemClass)) + +typedef struct _EaDayViewMainItem EaDayViewMainItem; +typedef struct _EaDayViewMainItemClass EaDayViewMainItemClass; + +struct _EaDayViewMainItem +{ + AtkGObjectAccessible parent; +}; + +GType ea_day_view_main_item_get_type (void); + +struct _EaDayViewMainItemClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject* ea_day_view_main_item_new (GObject *obj); + +G_END_DECLS + +#endif /* __EA_DAY_VIEW_MAIN_ITEM_H__ */ diff --git a/calendar/gui/ea-day-view.c b/calendar/gui/ea-day-view.c new file mode 100644 index 0000000000..9eb3e343f3 --- /dev/null +++ b/calendar/gui/ea-day-view.c @@ -0,0 +1,277 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-day-view.h" +#include "ea-cal-view-event.h" + +#include "ea-calendar-helpers.h" +#include "ea-gnome-calendar.h" +#include "calendar-commands.h" +#include <glib.h> +#include <glib/gi18n.h> + +static void ea_day_view_class_init (EaDayViewClass *klass); + +static G_CONST_RETURN gchar * ea_day_view_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_day_view_get_description (AtkObject *accessible); +static gint ea_day_view_get_n_children (AtkObject *obj); +static AtkObject* ea_day_view_ref_child (AtkObject *obj, + gint i); +static gpointer parent_class = NULL; + +GType +ea_day_view_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaDayViewClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_day_view_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaDayView), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (EaCalView, in this case) + * + * Note: we must still use run-time deriving here, because + * our parent class EaCalView is run-time deriving. + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + e_calendar_view_get_type()); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaDayView", &tinfo, 0); + } + + return type; +} + +static void +ea_day_view_class_init (EaDayViewClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_day_view_get_name; + class->get_description = ea_day_view_get_description; + + class->get_n_children = ea_day_view_get_n_children; + class->ref_child = ea_day_view_ref_child; +} + +AtkObject* +ea_day_view_new (GtkWidget *widget) +{ + GObject *object; + AtkObject *accessible; + + g_return_val_if_fail (E_IS_DAY_VIEW (widget), NULL); + + object = g_object_new (EA_TYPE_DAY_VIEW, NULL); + + accessible = ATK_OBJECT (object); + atk_object_initialize (accessible, widget); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_day_view created %p\n", (gpointer)accessible); +#endif + + return accessible; +} + +static G_CONST_RETURN gchar * +ea_day_view_get_name (AtkObject *accessible) +{ + EDayView *day_view; + GnomeCalendar *gcal; + const gchar *label_text; + GnomeCalendarViewType view_type; + gint n_events; + gchar *event_str, *name_str; + + g_return_val_if_fail (EA_IS_DAY_VIEW (accessible), NULL); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + + day_view = E_DAY_VIEW (GTK_ACCESSIBLE (accessible)->widget); + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view)); + if (!GTK_WIDGET_VISIBLE (GTK_WIDGET (gcal))) + return NULL; + + label_text = ea_gnome_calendar_get_label_description (gcal); + + n_events = atk_object_get_n_accessible_children (accessible); + /* the child main item is always there */ + --n_events; + if (n_events >= 1) + /* To translators: Here, "It" is either like "Work Week View: July + 10th - July 14th, 2006." or "Day View: Thursday July 13th, 2006." */ + event_str = g_strdup_printf (ngettext ("It has %d event.", "It has %d events.", n_events), n_events); + else + /* To translators: Here, "It" is either like "Work Week View: July + 10th - July 14th, 2006." or "Day View: Thursday July 13th, 2006." */ + event_str = g_strdup (_("It has no events.")); + + view_type = gnome_calendar_get_view (gcal); + if (view_type == GNOME_CAL_WORK_WEEK_VIEW) + /* To translators: First %s is the week, for example "July 10th - + July 14th, 2006". Second %s is the number of events in this work + week, for example "It has %d event/events." or "It has no events." */ + name_str = g_strdup_printf (_("Work Week View: %s. %s"), + label_text, event_str); + else + /* To translators: First %s is the day, for example "Thursday July + 13th, 2006". Second %s is the number of events on this day, for + example "It has %d event/events." or "It has no events." */ + name_str = g_strdup_printf (_("Day View: %s. %s"), + label_text, event_str); + + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_str); + g_free (name_str); + g_free (event_str); + + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_day_view_get_description (AtkObject *accessible) +{ + EDayView *day_view; + + g_return_val_if_fail (EA_IS_DAY_VIEW (accessible), NULL); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + day_view = E_DAY_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + if (accessible->description) + return accessible->description; + else { + GnomeCalendar *gcal; + GnomeCalendarViewType view_type; + + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view)); + view_type = gnome_calendar_get_view (gcal); + + if (view_type == GNOME_CAL_WORK_WEEK_VIEW) + return _("calendar view for a work week"); + else + return _("calendar view for one or more days"); + } +} + +static gint +ea_day_view_get_n_children (AtkObject *accessible) +{ + EDayView *day_view; + gint day; + gint child_num = 0; + + g_return_val_if_fail (EA_IS_DAY_VIEW (accessible), -1); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return -1; + + day_view = E_DAY_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + child_num += day_view->long_events->len; + + for (day = 0; day < day_view->days_shown; day++) { + child_num += day_view->events[day]->len; + } + + /* "+1" for the main item */ + return child_num + 1; +} + +static AtkObject * +ea_day_view_ref_child (AtkObject *accessible, gint index) +{ + EDayView *day_view; + gint child_num; + gint day; + AtkObject *atk_object = NULL; + EDayViewEvent *event = NULL; + + g_return_val_if_fail (EA_IS_DAY_VIEW (accessible), NULL); + + child_num = atk_object_get_n_accessible_children (accessible); + if (child_num <= 0 || index < 0 || index >= child_num) + return NULL; + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + day_view = E_DAY_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + if (index == 0) { + /* index == 0 is the main item */ + atk_object = atk_gobject_accessible_for_object (G_OBJECT (day_view->main_canvas_item)); + g_object_ref (atk_object); + } + else { + --index; + /* a long event */ + if (index < day_view->long_events->len) { + event = &g_array_index (day_view->long_events, + EDayViewEvent, index); + } + else { + index -= day_view->long_events->len; + day = 0; + while (index >= day_view->events[day]->len) { + index -= day_view->events[day]->len; + ++day; + } + + event = &g_array_index (day_view->events[day], + EDayViewEvent, index); + } + if (event && event->canvas_item) { + /* Not use atk_gobject_accessible_for_object here, + * we need to do special thing here + */ + atk_object = ea_calendar_helpers_get_accessible_for (event->canvas_item); + g_object_ref (atk_object); + } + } + return atk_object; +} diff --git a/calendar/gui/ea-day-view.h b/calendar/gui/ea-day-view.h new file mode 100644 index 0000000000..33399f6600 --- /dev/null +++ b/calendar/gui/ea-day-view.h @@ -0,0 +1,57 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_DAY_VIEW_H__ +#define __EA_DAY_VIEW_H__ + +#include "ea-cal-view.h" +#include "e-day-view.h" + +G_BEGIN_DECLS + +#define EA_TYPE_DAY_VIEW (ea_day_view_get_type ()) +#define EA_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_DAY_VIEW, EaDayView)) +#define EA_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_DAY_VIEW, EaDayViewClass)) +#define EA_IS_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_DAY_VIEW)) +#define EA_IS_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_DAY_VIEW)) +#define EA_DAY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_DAY_VIEW, EaDayViewClass)) + +typedef struct _EaDayView EaDayView; +typedef struct _EaDayViewClass EaDayViewClass; + +struct _EaDayView +{ + EaCalView parent; +}; + +GType ea_day_view_get_type (void); + +struct _EaDayViewClass +{ + EaCalViewClass parent_class; +}; + +AtkObject* ea_day_view_new (GtkWidget *widget); + +G_END_DECLS + +#endif /* __EA_DAY_VIEW_H__ */ diff --git a/calendar/gui/ea-gnome-calendar.c b/calendar/gui/ea-gnome-calendar.c new file mode 100644 index 0000000000..e5d9654c1a --- /dev/null +++ b/calendar/gui/ea-gnome-calendar.c @@ -0,0 +1,351 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-gnome-calendar.h" +#include "calendar-commands.h" +#include <string.h> +#include <gtk/gtk.h> +#include <libecal/e-cal-time-util.h> +#include <libedataserver/e-data-server-util.h> +#include <glib/gi18n.h> + +static void ea_gnome_calendar_class_init (EaGnomeCalendarClass *klass); + +static G_CONST_RETURN gchar * ea_gnome_calendar_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_gnome_calendar_get_description (AtkObject *accessible); +static gint ea_gnome_calendar_get_n_children (AtkObject* obj); +static AtkObject * ea_gnome_calendar_ref_child (AtkObject *obj, gint i); + +static void ea_gcal_switch_view_cb (GtkNotebook *widget, GtkNotebookPage *page, + guint index, gpointer data); +static void ea_gcal_dates_change_cb (GnomeCalendar *gcal, gpointer data); + +static gpointer parent_class = NULL; + +GType +ea_gnome_calendar_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaGnomeCalendarClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_gnome_calendar_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaGnomeCalendar), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (GailWidget, in this case) + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + GTK_TYPE_WIDGET); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaGnomeCalendar", &tinfo, 0); + + } + + return type; +} + +static void +ea_gnome_calendar_class_init (EaGnomeCalendarClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_gnome_calendar_get_name; + class->get_description = ea_gnome_calendar_get_description; + + class->get_n_children = ea_gnome_calendar_get_n_children; + class->ref_child = ea_gnome_calendar_ref_child; +} + +AtkObject* +ea_gnome_calendar_new (GtkWidget *widget) +{ + GObject *object; + AtkObject *accessible; + GnomeCalendar *gcal; + GtkWidget *notebook; + + g_return_val_if_fail (GNOME_IS_CALENDAR (widget), NULL); + + object = g_object_new (EA_TYPE_GNOME_CALENDAR, NULL); + + accessible = ATK_OBJECT (object); + atk_object_initialize (accessible, widget); + + accessible->role = ATK_ROLE_FILLER; + + gcal = GNOME_CALENDAR (widget); + + /* listen on view type change + */ + g_signal_connect (widget, "dates_shown_changed", + G_CALLBACK (ea_gcal_dates_change_cb), + accessible); + notebook = gnome_calendar_get_view_notebook_widget (gcal); + if (notebook) { + g_signal_connect (notebook, "switch_page", + G_CALLBACK (ea_gcal_switch_view_cb), + accessible); + } + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea-gnome-calendar created: %p\n", (gpointer)accessible); +#endif + + return accessible; +} + +const gchar * +ea_gnome_calendar_get_label_description (GnomeCalendar *gcal) +{ + icaltimezone *zone; + struct icaltimetype start_tt, end_tt; + time_t start_time, end_time; + struct tm start_tm, end_tm; + static gchar buffer[512]; + gchar end_buffer[256]; + GnomeCalendarViewType view; + + gnome_calendar_get_visible_time_range (gcal, &start_time, &end_time); + zone = gnome_calendar_get_timezone (gcal); + + start_tt = icaltime_from_timet_with_zone (start_time, FALSE, zone); + start_tm.tm_year = start_tt.year - 1900; + start_tm.tm_mon = start_tt.month - 1; + start_tm.tm_mday = start_tt.day; + start_tm.tm_hour = start_tt.hour; + start_tm.tm_min = start_tt.minute; + start_tm.tm_sec = start_tt.second; + start_tm.tm_isdst = -1; + start_tm.tm_wday = time_day_of_week (start_tt.day, start_tt.month - 1, + start_tt.year); + + /* Take one off end_time so we don't get an extra day. */ + end_tt = icaltime_from_timet_with_zone (end_time - 1, FALSE, zone); + end_tm.tm_year = end_tt.year - 1900; + end_tm.tm_mon = end_tt.month - 1; + end_tm.tm_mday = end_tt.day; + end_tm.tm_hour = end_tt.hour; + end_tm.tm_min = end_tt.minute; + end_tm.tm_sec = end_tt.second; + end_tm.tm_isdst = -1; + end_tm.tm_wday = time_day_of_week (end_tt.day, end_tt.month - 1, + end_tt.year); + + view = gnome_calendar_get_view (gcal); + + switch (view) { + case GNOME_CAL_DAY_VIEW: + case GNOME_CAL_WORK_WEEK_VIEW: + case GNOME_CAL_WEEK_VIEW: + if (start_tm.tm_year == end_tm.tm_year + && start_tm.tm_mon == end_tm.tm_mon + && start_tm.tm_mday == end_tm.tm_mday) { + e_utf8_strftime (buffer, sizeof (buffer), + _("%A %d %b %Y"), &start_tm); + } else if (start_tm.tm_year == end_tm.tm_year) { + e_utf8_strftime (buffer, sizeof (buffer), + _("%a %d %b"), &start_tm); + e_utf8_strftime (end_buffer, sizeof (end_buffer), + _("%a %d %b %Y"), &end_tm); + strcat (buffer, " - "); + strcat (buffer, end_buffer); + } else { + e_utf8_strftime (buffer, sizeof (buffer), + _("%a %d %b %Y"), &start_tm); + e_utf8_strftime (end_buffer, sizeof (end_buffer), + _("%a %d %b %Y"), &end_tm); + strcat (buffer, " - "); + strcat (buffer, end_buffer); + } + break; + case GNOME_CAL_MONTH_VIEW: + case GNOME_CAL_LIST_VIEW: + if (start_tm.tm_year == end_tm.tm_year) { + if (start_tm.tm_mon == end_tm.tm_mon) { + if (start_tm.tm_mday == end_tm.tm_mday) { + buffer [0] = '\0'; + } else { + e_utf8_strftime (buffer, sizeof (buffer), + "%d", &start_tm); + strcat (buffer, " - "); + } + e_utf8_strftime (end_buffer, sizeof (end_buffer), + _("%d %b %Y"), &end_tm); + strcat (buffer, end_buffer); + } else { + e_utf8_strftime (buffer, sizeof (buffer), + _("%d %b"), &start_tm); + e_utf8_strftime (end_buffer, sizeof (end_buffer), + _("%d %b %Y"), &end_tm); + strcat (buffer, " - "); + strcat (buffer, end_buffer); + } + } else { + e_utf8_strftime (buffer, sizeof (buffer), + _("%d %b %Y"), &start_tm); + e_utf8_strftime (end_buffer, sizeof (end_buffer), + _("%d %b %Y"), &end_tm); + strcat (buffer, " - "); + strcat (buffer, end_buffer); + } + break; + default: + g_return_val_if_reached (NULL); + } + return buffer; +} + +static G_CONST_RETURN gchar * +ea_gnome_calendar_get_name (AtkObject *accessible) +{ + if (accessible->name) + return accessible->name; + return _("Gnome Calendar"); +} + +static G_CONST_RETURN gchar * +ea_gnome_calendar_get_description (AtkObject *accessible) +{ + if (accessible->description) + return accessible->description; + return _("Gnome Calendar"); +} + +static gint +ea_gnome_calendar_get_n_children (AtkObject* obj) +{ + g_return_val_if_fail (EA_IS_GNOME_CALENDAR (obj), 0); + + if (!GTK_ACCESSIBLE (obj)->widget) + return -1; + return 4; +} + +static AtkObject * +ea_gnome_calendar_ref_child (AtkObject *obj, gint i) +{ + AtkObject * child = NULL; + GnomeCalendar * calendarWidget; + GtkWidget *childWidget; + + g_return_val_if_fail (EA_IS_GNOME_CALENDAR (obj), NULL); + /* valid child index range is [0-3] */ + if (i < 0 || i >3 ) + return NULL; + + if (!GTK_ACCESSIBLE (obj)->widget) + return NULL; + calendarWidget = GNOME_CALENDAR (GTK_ACCESSIBLE (obj)->widget); + + switch (i) { + case 0: + /* for the search bar */ + childWidget = gnome_calendar_get_search_bar_widget (calendarWidget); + child = gtk_widget_get_accessible (childWidget); + atk_object_set_parent (child, obj); + atk_object_set_name (child, _("search bar")); + atk_object_set_description (child, _("evolution calendar search bar")); + break; + case 1: + /* for the day/week view */ + childWidget = gnome_calendar_get_current_view_widget (calendarWidget); + child = gtk_widget_get_accessible (childWidget); + atk_object_set_parent (child, obj); + break; + case 2: + /* for calendar */ + childWidget = gnome_calendar_get_e_calendar_widget (calendarWidget); + child = gtk_widget_get_accessible (childWidget); + break; + case 3: + /* for todo list */ + childWidget = GTK_WIDGET (gnome_calendar_get_task_pad (calendarWidget)); + child = gtk_widget_get_accessible (childWidget); + break; + default: + break; + } + if (child) + g_object_ref(child); + return child; +} + +static void +ea_gcal_switch_view_cb (GtkNotebook *widget, GtkNotebookPage *page, + guint index, gpointer data) +{ + GtkWidget *new_widget; + + new_widget = gtk_notebook_get_nth_page (widget, index); + + /* views are always the second child in gnome calendar + */ + if (new_widget) + g_signal_emit_by_name (G_OBJECT(data), "children_changed::add", + 1, gtk_widget_get_accessible (new_widget), NULL); + +#ifdef ACC_DEBUG + printf ("AccDebug: view switch to widget %p (index=%d) \n", + (gpointer)new_widget, index); +#endif +} + +static void +ea_gcal_dates_change_cb (GnomeCalendar *gcal, gpointer data) +{ + const gchar *new_name; + + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + g_return_if_fail (data); + g_return_if_fail (EA_IS_GNOME_CALENDAR (data)); + + new_name = ea_gnome_calendar_get_label_description (gcal); + atk_object_set_name (ATK_OBJECT(data), new_name); + g_signal_emit_by_name (data, "visible_data_changed"); + +#ifdef ACC_DEBUG + printf ("AccDebug: calendar dates changed, label=%s\n", new_name); +#endif +} diff --git a/calendar/gui/ea-gnome-calendar.h b/calendar/gui/ea-gnome-calendar.h new file mode 100644 index 0000000000..b0d2cf71d2 --- /dev/null +++ b/calendar/gui/ea-gnome-calendar.h @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_GNOME_CALENDAR_H__ +#define __EA_GNOME_CALENDAR_H__ + +#include <gtk/gtk.h> +#include "gnome-cal.h" + +G_BEGIN_DECLS + +#define EA_TYPE_GNOME_CALENDAR (ea_gnome_calendar_get_type ()) +#define EA_GNOME_CALENDAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_GNOME_CALENDAR, EaGnomeCalendar)) +#define EA_GNOME_CALENDAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_GNOME_CALENDAR, EaGnomeCalendarClass)) +#define EA_IS_GNOME_CALENDAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_GNOME_CALENDAR)) +#define EA_IS_GNOME_CALENDAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_GNOME_CALENDAR)) +#define EA_GNOME_CALENDAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_GNOME_CALENDAR, EaGnomeCalendarClass)) + +typedef struct _EaGnomeCalendar EaGnomeCalendar; +typedef struct _EaGnomeCalendarClass EaGnomeCalendarClass; + +struct _EaGnomeCalendar +{ + GtkAccessible parent; +}; + +GType ea_gnome_calendar_get_type (void); + +struct _EaGnomeCalendarClass +{ + GtkAccessibleClass parent_class; +}; + +AtkObject* ea_gnome_calendar_new (GtkWidget *widget); + +const gchar * ea_gnome_calendar_get_label_description (GnomeCalendar *gcal); + +G_END_DECLS + + +#endif /* __EA_GNOME_CALENDAR_H__ */ diff --git a/calendar/gui/ea-jump-button.c b/calendar/gui/ea-jump-button.c new file mode 100644 index 0000000000..eb24bea42c --- /dev/null +++ b/calendar/gui/ea-jump-button.c @@ -0,0 +1,224 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Yang Wu <yang.wu@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-jump-button.h" +#include "ea-calendar-helpers.h" +#include "ea-week-view.h" +#include "e-week-view.h" +#include <libgnomecanvas/gnome-canvas.h> +#include <glib/gi18n.h> + +static void ea_jump_button_class_init (EaJumpButtonClass *klass); + +static G_CONST_RETURN gchar * ea_jump_button_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_jump_button_get_description (AtkObject *accessible); + +/* action interface */ +static void atk_action_interface_init (AtkActionIface *iface); +static gboolean jump_button_do_action (AtkAction *action, + gint i); +static gint jump_button_get_n_actions (AtkAction *action); +static G_CONST_RETURN gchar * jump_button_get_keybinding (AtkAction *action, + gint i); + +static gpointer parent_class = NULL; + +GType +ea_jump_button_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaJumpButtonClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_jump_button_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaJumpButton), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_action_info = + { + (GInterfaceInitFunc) atk_action_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (atk object for GNOME_TYPE_CANVAS_ITEM, in this case) + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + GNOME_TYPE_CANVAS_ITEM); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + /* we inherit the component and other interfaces from GNOME_TYPE_CANVAS_ITEM */ + type = g_type_register_static (derived_atk_type, + "EaJumpButton", &tinfo, 0); + + g_type_add_interface_static (type, ATK_TYPE_ACTION, + &atk_action_info); + } + + return type; +} + +static void +ea_jump_button_class_init (EaJumpButtonClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_jump_button_get_name; + class->get_description = ea_jump_button_get_description; +} + +AtkObject* +ea_jump_button_new (GObject *obj) +{ + AtkObject *atk_obj = NULL; + GObject *target_obj; + + g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (obj), NULL); + + target_obj = obj; + atk_obj = g_object_get_data (target_obj, "accessible-object"); + + if (!atk_obj) { + static AtkRole event_role = ATK_ROLE_INVALID; + atk_obj = ATK_OBJECT (g_object_new (EA_TYPE_JUMP_BUTTON, + NULL)); + atk_object_initialize (atk_obj, target_obj); + if (event_role == ATK_ROLE_INVALID) + event_role = atk_role_register ("Jump Button"); + atk_obj->role = event_role; + } + + /* the registered factory for GNOME_TYPE_CANVAS_ITEM is cannot create a EaJumpbutton, + * we should save the EaJumpbutton object in it. + */ + g_object_set_data (obj, "accessible-object", atk_obj); + + return atk_obj; +} + +static G_CONST_RETURN gchar * +ea_jump_button_get_name (AtkObject *accessible) +{ + g_return_val_if_fail (EA_IS_JUMP_BUTTON (accessible), NULL); + + if (accessible->name) + return accessible->name; + return _("Jump button"); +} + +static G_CONST_RETURN gchar * +ea_jump_button_get_description (AtkObject *accessible) +{ + if (accessible->description) + return accessible->description; + + return _("Click here, you can find more events."); +} + +static void +atk_action_interface_init (AtkActionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->do_action = jump_button_do_action; + iface->get_n_actions = jump_button_get_n_actions; + iface->get_keybinding = jump_button_get_keybinding; +} + +static gboolean +jump_button_do_action (AtkAction *action, + gint i) +{ + gboolean return_value = TRUE; + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + GnomeCanvasItem *item; + ECalendarView *cal_view; + EWeekView *week_view; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (action); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + item = GNOME_CANVAS_ITEM (g_obj); + cal_view = ea_calendar_helpers_get_cal_view_from (GNOME_CANVAS_ITEM (item)); + week_view = E_WEEK_VIEW (cal_view); + + switch (i) + { + case 0: + e_week_view_jump_to_button_item (week_view, GNOME_CANVAS_ITEM (item)); + break; + default: + return_value = FALSE; + break; + } + return return_value; +} + +static gint +jump_button_get_n_actions (AtkAction *action) +{ + return 1; +} + +static G_CONST_RETURN gchar * +jump_button_get_keybinding (AtkAction *action, + gint i) +{ + const gchar *return_value = NULL; + + switch (i) + { + case 0: + { + return_value = "space or enter"; + break; + } + default: + break; + } + return return_value; +} diff --git a/calendar/gui/ea-jump-button.h b/calendar/gui/ea-jump-button.h new file mode 100644 index 0000000000..cd3b6e26bb --- /dev/null +++ b/calendar/gui/ea-jump-button.h @@ -0,0 +1,58 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Yang Wu <yang.wu@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_JUMP_BUTTON_H__ +#define __EA_JUMP_BUTTON_H__ + +#include <atk/atkgobjectaccessible.h> + +G_BEGIN_DECLS + +#define EA_TYPE_JUMP_BUTTON (ea_jump_button_get_type ()) +#define EA_JUMP_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_JUMP_BUTTON, EaJumpButton)) +#define EA_JUMP_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_JUMP_BUTTON, EaJumpButtonClass)) +#define EA_IS_JUMP_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_JUMP_BUTTON)) +#define EA_IS_JUMP_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_JUMP_BUTTON)) +#define EA_JUMP_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_JUMP_BUTTON, EaJumpButtonClass)) + +typedef struct _EaJumpButton EaJumpButton; +typedef struct _EaJumpButtonClass EaJumpButtonClass; + +struct _EaJumpButton +{ + AtkGObjectAccessible parent; +}; + +GType ea_jump_button_get_type (void); + +struct _EaJumpButtonClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject *ea_jump_button_new (GObject *obj); + +G_END_DECLS + + +#endif /* __EA_JUMP_BUTTON_H__ */ diff --git a/calendar/gui/ea-week-view-cell.c b/calendar/gui/ea-week-view-cell.c new file mode 100644 index 0000000000..e724592ec8 --- /dev/null +++ b/calendar/gui/ea-week-view-cell.c @@ -0,0 +1,478 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * Yang Wu <Yang.Wu@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-week-view-cell.h" +#include "ea-week-view-main-item.h" +#include "a11y/ea-factory.h" + +/* EWeekViewCell */ + +static void e_week_view_cell_class_init (EWeekViewCellClass *class); + +EA_FACTORY_GOBJECT (EA_TYPE_WEEK_VIEW_CELL, ea_week_view_cell, ea_week_view_cell_new) + +GType +e_week_view_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EWeekViewCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) e_week_view_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EWeekViewCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, + "EWeekViewCell", &tinfo, 0); + } + + return type; +} + +static void +e_week_view_cell_class_init (EWeekViewCellClass *class) +{ + EA_SET_FACTORY (e_week_view_cell_get_type (), ea_week_view_cell); +} + +EWeekViewCell * +e_week_view_cell_new (EWeekView *week_view, gint row, gint column) +{ + GObject *object; + EWeekViewCell *cell; + + g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL); + + object = g_object_new (E_TYPE_WEEK_VIEW_CELL, NULL); + cell = E_WEEK_VIEW_CELL (object); + cell->week_view = week_view; + cell->row = row; + cell->column = column; + +#ifdef ACC_DEBUG + printf ("EvoAcc: e_week_view_cell created %p\n", (gpointer)cell); +#endif + + return cell; +} + +/* EaWeekViewCell */ + +static void ea_week_view_cell_class_init (EaWeekViewCellClass *klass); + +static G_CONST_RETURN gchar * ea_week_view_cell_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_week_view_cell_get_description (AtkObject *accessible); +static AtkStateSet* ea_week_view_cell_ref_state_set (AtkObject *obj); +static AtkObject * ea_week_view_cell_get_parent (AtkObject *accessible); +static gint ea_week_view_cell_get_index_in_parent (AtkObject *accessible); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, + gint *width, gint *height, + AtkCoordType coord_type); +static gboolean component_interface_grab_focus (AtkComponent *component); + +static gpointer parent_class = NULL; + +#ifdef ACC_DEBUG +static gint n_ea_week_view_cell_created = 0, n_ea_week_view_cell_destroyed = 0; +static void ea_week_view_cell_finalize (GObject *object); +#endif + +GType +ea_week_view_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaWeekViewCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_week_view_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaWeekViewCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + type = g_type_register_static (ATK_TYPE_GOBJECT_ACCESSIBLE, + "EaWeekViewCell", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + + } + + return type; +} + +static void +ea_week_view_cell_class_init (EaWeekViewCellClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + +#ifdef ACC_DEBUG + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = ea_week_view_cell_finalize; +#endif + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_week_view_cell_get_name; + class->get_description = ea_week_view_cell_get_description; + class->ref_state_set = ea_week_view_cell_ref_state_set; + + class->get_parent = ea_week_view_cell_get_parent; + class->get_index_in_parent = ea_week_view_cell_get_index_in_parent; + +} + +AtkObject* +ea_week_view_cell_new (GObject *obj) +{ + gpointer object; + AtkObject *atk_object; + + g_return_val_if_fail (E_IS_WEEK_VIEW_CELL (obj), NULL); + object = g_object_new (EA_TYPE_WEEK_VIEW_CELL, NULL); + atk_object = ATK_OBJECT (object); + atk_object_initialize (atk_object, obj); + atk_object->role = ATK_ROLE_UNKNOWN; + +#ifdef ACC_DEBUG + ++n_ea_week_view_cell_created; + printf ("ACC_DEBUG: n_ea_week_view_cell_created = %d\n", + n_ea_week_view_cell_created); +#endif + return atk_object; +} + +#ifdef ACC_DEBUG +static void ea_week_view_cell_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); + + ++n_ea_week_view_cell_destroyed; + printf ("ACC_DEBUG: n_ea_week_view_cell_destroyed = %d\n", + n_ea_week_view_cell_destroyed); +} +#endif + +static G_CONST_RETURN gchar * +ea_week_view_cell_get_name (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewCell *cell; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL); + + if (!accessible->name) { + AtkObject *ea_main_item; + GnomeCanvasItem *main_item; + gchar *new_name = g_strdup (""); + const gchar *row_label, *column_label; + gint new_column, new_row; + gint start_day; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + cell = E_WEEK_VIEW_CELL (g_obj); + main_item = cell->week_view->main_canvas_item; + ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item)); + + start_day = cell->week_view->display_start_day; + if (cell->column + start_day >= 7) { + new_column = cell->column + start_day - 7; + new_row = cell->row + 1; + } else { + new_column = cell->column + start_day; + new_row = cell->row; + } + + column_label = atk_table_get_column_description (ATK_TABLE (ea_main_item), + new_column); + row_label = atk_table_get_row_description (ATK_TABLE (ea_main_item), + new_row); + new_name = g_strconcat (column_label, " ", row_label, NULL); + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, new_name); + g_free (new_name); + } + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_week_view_cell_get_description (AtkObject *accessible) +{ + return ea_week_view_cell_get_name (accessible); +} + +static AtkStateSet* +ea_week_view_cell_ref_state_set (AtkObject *obj) +{ + AtkStateSet *state_set; + GObject *g_obj; + AtkObject *parent; + gint x, y, width, height; + gint parent_x, parent_y, parent_width, parent_height; + + state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj); + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(obj)); + if (!g_obj) + return state_set; + + atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); + + parent = atk_object_get_parent (obj); + atk_component_get_extents (ATK_COMPONENT (obj), &x, &y, + &width, &height, ATK_XY_WINDOW); + atk_component_get_extents (ATK_COMPONENT (parent), &parent_x, &parent_y, + &parent_width, &parent_height, ATK_XY_WINDOW); + + + if (x + width < parent_x || x > parent_x + parent_width || + y + height < parent_y || y > parent_y + parent_height) + /* the cell is out of the main canvas */ + ; + else + atk_state_set_add_state (state_set, ATK_STATE_VISIBLE); + + return state_set; +} + +static AtkObject * +ea_week_view_cell_get_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewCell *cell; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + cell = E_WEEK_VIEW_CELL (g_obj); + return atk_gobject_accessible_for_object (G_OBJECT (cell->week_view->main_canvas_item)); +} + +static gint +ea_week_view_cell_get_index_in_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewCell *cell; + AtkObject *parent; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + cell = E_WEEK_VIEW_CELL (g_obj); + parent = atk_object_get_parent (accessible); + return atk_table_get_index_at (ATK_TABLE (parent), + cell->row, cell->column); +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = component_interface_get_extents; + iface->grab_focus = component_interface_grab_focus; +} + +static void +component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + AtkObject *atk_obj; + EWeekViewCell *cell; + EWeekView *week_view; + GtkWidget *main_canvas; + gint week_view_width, week_view_height; + gint scroll_x, scroll_y; + gint start_day; + + *x = *y = *width = *height = 0; + + g_return_if_fail (EA_IS_WEEK_VIEW_CELL (component)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + + cell = E_WEEK_VIEW_CELL (g_obj); + week_view = cell->week_view; + main_canvas = cell->week_view->main_canvas; + + atk_obj = atk_gobject_accessible_for_object (G_OBJECT (main_canvas)); + atk_component_get_extents (ATK_COMPONENT (atk_obj), + x, y, + &week_view_width, &week_view_height, + coord_type); + gnome_canvas_get_scroll_offsets (GNOME_CANVAS (week_view->main_canvas), + &scroll_x, &scroll_y); + start_day = week_view->display_start_day; + if (week_view->multi_week_view) { + if (week_view->compress_weekend && (cell->column == (5 - start_day))) { + *height = week_view->row_heights[cell->row*2]; + *width = week_view->col_widths[cell->column]; + *x += week_view->col_offsets[cell->column] - scroll_x; + *y += week_view->row_offsets[cell->row*2]- scroll_y; + } else if (week_view->compress_weekend && (cell->column == (6 - start_day))) { + *height = week_view->row_heights[cell->row*2]; + *width = week_view->col_widths[cell->column - 1]; + *x += week_view->col_offsets[cell->column - 1]- scroll_x; + *y += week_view->row_offsets[cell->row*2 + 1]- scroll_y; + } else if (week_view->compress_weekend && (cell->column > (6 - start_day))){ + *height = week_view->row_heights[cell->row*2]*2; + *width = week_view->col_widths[cell->column - 1]; + *x += week_view->col_offsets[cell->column - 1] - scroll_x; + *y += week_view->row_offsets[cell->row*2]- scroll_y; + } else { + *height = week_view->row_heights[cell->row*2]*2; + *width = week_view->col_widths[cell->column]; + *x += week_view->col_offsets[cell->column] - scroll_x; + *y += week_view->row_offsets[cell->row*2]- scroll_y; + } + } else { + if (start_day < 3) { + if (cell->column < 3) { + *height = week_view->row_heights[cell->column*2]*2; + *width = week_view->col_widths[0]; + *x += week_view->col_offsets[0] - scroll_x; + *y += week_view->row_offsets[cell->column*2]- scroll_y; + } else { + if (cell->column == 5 - start_day) { + *height = week_view->row_heights[(cell->column - 3)*2]; + *width = week_view->col_widths[1]; + *x += week_view->col_offsets[1] - scroll_x; + *y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y; + } else if (cell->column == 6 - start_day) { + *height = week_view->row_heights[(cell->column - 4)*2]; + *width = week_view->col_widths[1]; + *x += week_view->col_offsets[1] - scroll_x; + *y += week_view->row_offsets[(cell->column - 3)*2 - 1]- scroll_y; + } else if (cell->column > 6 - start_day) { + *height = week_view->row_heights[(cell->column - 4)*2]*2; + *width = week_view->col_widths[1]; + *x += week_view->col_offsets[1] - scroll_x; + *y += week_view->row_offsets[(cell->column - 4)*2]- scroll_y; + } else { + *height = week_view->row_heights[(cell->column - 3)*2]*2; + *width = week_view->col_widths[1]; + *x += week_view->col_offsets[1] - scroll_x; + *y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y; + } + } + } else if (cell->column < 4) { + if (cell->column == 5 - start_day) { + *height = week_view->row_heights[cell->column*2]; + *width = week_view->col_widths[0]; + *x += week_view->col_offsets[0] - scroll_x; + *y += week_view->row_offsets[cell->column*2]- scroll_y; + } else if (cell->column == 6 - start_day) { + *height = week_view->row_heights[(cell->column - 1)*2]; + *width = week_view->col_widths[0]; + *x += week_view->col_offsets[0] - scroll_x; + *y += week_view->row_offsets[cell->column*2 - 1]- scroll_y; + } else if (cell->column > 6 - start_day) { + *height = week_view->row_heights[(cell->column - 1)*2]*2; + *width = week_view->col_widths[0]; + *x += week_view->col_offsets[0] - scroll_x; + *y += week_view->row_offsets[(cell->column - 1)*2]- scroll_y; + } else { + *height = week_view->row_heights[(cell->column)*2]*2; + *width = week_view->col_widths[0]; + *x += week_view->col_offsets[0] - scroll_x; + *y += week_view->row_offsets[cell->column*2]- scroll_y; + } + } else { + *height = week_view->row_heights[(cell->column - 4)*2]*2; + *width = week_view->col_widths[1]; + *x += week_view->col_offsets[1] - scroll_x; + *y += week_view->row_offsets[(cell->column - 4)*2]- scroll_y; + } + } +} + +static gboolean +component_interface_grab_focus (AtkComponent *comp) +{ + GObject *g_obj; + EWeekViewCell *cell; + EWeekView *week_view; + GtkWidget *toplevel; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (comp), FALSE); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (comp)); + if (!g_obj) + return FALSE; + + cell = E_WEEK_VIEW_CELL (g_obj); + week_view = cell->week_view; + + week_view->selection_start_day = cell->row * 7 + cell->column; + week_view->selection_end_day = cell->row * 7 + cell->column; + gtk_widget_queue_draw (week_view->main_canvas); + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (week_view)); + if (GTK_WIDGET_TOPLEVEL (toplevel)) + gtk_window_present (GTK_WINDOW (toplevel)); + + return TRUE; +} diff --git a/calendar/gui/ea-week-view-cell.h b/calendar/gui/ea-week-view-cell.h new file mode 100644 index 0000000000..1524e9d3a8 --- /dev/null +++ b/calendar/gui/ea-week-view-cell.h @@ -0,0 +1,85 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * Yang Wu <yang.wu@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_WEEK_VIEW_CELL_H__ +#define __EA_WEEK_VIEW_CELL_H__ + +#include <atk/atkgobjectaccessible.h> +#include "e-week-view.h" + +G_BEGIN_DECLS + +#define E_TYPE_WEEK_VIEW_CELL (e_week_view_cell_get_type ()) +#define E_WEEK_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_WEEK_VIEW_CELL, EWeekViewCell)) +#define E_WEEK_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_WEEK_VIEW_CELL, EWeekViewCellClass)) +#define E_IS_WEEK_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_WEEK_VIEW_CELL)) +#define E_IS_WEEK_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_WEEK_VIEW_CELL)) +#define E_WEEK_VIEW_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_WEEK_VIEW_CELL, EWeekViewCellClass)) + +typedef struct _EWeekViewCell EWeekViewCell; +typedef struct _EWeekViewCellClass EWeekViewCellClass; + +struct _EWeekViewCell +{ + GObject parent; + EWeekView *week_view; + gint row; + gint column; +}; + +GType e_week_view_cell_get_type (void); + +struct _EWeekViewCellClass +{ + GObjectClass parent_class; +}; + +EWeekViewCell * e_week_view_cell_new (EWeekView *week_view, gint row, gint column); + +#define EA_TYPE_WEEK_VIEW_CELL (ea_week_view_cell_get_type ()) +#define EA_WEEK_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_WEEK_VIEW_CELL, EaWeekViewCell)) +#define EA_WEEK_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_WEEK_VIEW_CELL, EaWeekViewCellClass)) +#define EA_IS_WEEK_VIEW_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_WEEK_VIEW_CELL)) +#define EA_IS_WEEK_VIEW_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_WEEK_VIEW_CELL)) +#define EA_WEEK_VIEW_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_WEEK_VIEW_CELL, EaWeekViewCellClass)) + +typedef struct _EaWeekViewCell EaWeekViewCell; +typedef struct _EaWeekViewCellClass EaWeekViewCellClass; + +struct _EaWeekViewCell +{ + AtkGObjectAccessible parent; +}; + +GType ea_week_view_cell_get_type (void); + +struct _EaWeekViewCellClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject* ea_week_view_cell_new (GObject *gobj); + +G_END_DECLS + +#endif /* __EA_WEEK_VIEW_CELL_H__ */ diff --git a/calendar/gui/ea-week-view-main-item.c b/calendar/gui/ea-week-view-main-item.c new file mode 100644 index 0000000000..74f4695a69 --- /dev/null +++ b/calendar/gui/ea-week-view-main-item.c @@ -0,0 +1,1247 @@ +/* + * Evolution Accessibility: ea-week-view-main-item.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-week-view-main-item.h" +#include "ea-week-view.h" +#include "ea-week-view-cell.h" +#include "ea-cell-table.h" +#include <glib/gi18n.h> + +/* EaWeekViewMainItem */ +static void ea_week_view_main_item_class_init (EaWeekViewMainItemClass *klass); + +static void ea_week_view_main_item_finalize (GObject *object); +static G_CONST_RETURN gchar * ea_week_view_main_item_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_week_view_main_item_get_description (AtkObject *accessible); + +static gint ea_week_view_main_item_get_n_children (AtkObject *obj); +static AtkObject* ea_week_view_main_item_ref_child (AtkObject *obj, + gint i); +static AtkObject * ea_week_view_main_item_get_parent (AtkObject *accessible); +static gint ea_week_view_main_item_get_index_in_parent (AtkObject *accessible); + +/* callbacks */ +static void ea_week_view_main_item_dates_change_cb (GnomeCalendar *gcal, gpointer data); +static void ea_week_view_main_item_time_change_cb (EWeekView *week_view, gpointer data); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, + gint *width, gint *height, + AtkCoordType coord_type); + +/* atk table interface */ +static void atk_table_interface_init (AtkTableIface *iface); +static gint table_interface_get_index_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_column_at_index (AtkTable *table, + gint index); +static gint table_interface_get_row_at_index (AtkTable *table, + gint index); +static AtkObject* table_interface_ref_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_n_rows (AtkTable *table); +static gint table_interface_get_n_columns (AtkTable *table); +static gint table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_row_extent_at (AtkTable *table, + gint row, + gint column); + +static gboolean table_interface_is_row_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_column_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_selected (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected); +static gint table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected); +static gboolean table_interface_add_row_selection (AtkTable *table, gint row); +static gboolean table_interface_remove_row_selection (AtkTable *table, + gint row); +static gboolean table_interface_add_column_selection (AtkTable *table, + gint column); +static gboolean table_interface_remove_column_selection (AtkTable *table, + gint column); +static AtkObject* table_interface_get_row_header (AtkTable *table, gint row); +static AtkObject* table_interface_get_column_header (AtkTable *table, + gint in_col); +static AtkObject* table_interface_get_caption (AtkTable *table); + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, gint in_col); + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, gint row); + +static AtkObject* table_interface_get_summary (AtkTable *table); + +/* atk selection interface */ +static void atk_selection_interface_init (AtkSelectionIface *iface); +static gboolean selection_interface_add_selection (AtkSelection *selection, + gint i); +static gboolean selection_interface_clear_selection (AtkSelection *selection); +static AtkObject* selection_interface_ref_selection (AtkSelection *selection, + gint i); +static gint selection_interface_get_selection_count (AtkSelection *selection); +static gboolean selection_interface_is_child_selected (AtkSelection *selection, + gint i); + +/* helpers */ +static EaCellTable * +ea_week_view_main_item_get_cell_data (EaWeekViewMainItem *ea_main_item); + +static void +ea_week_view_main_item_destory_cell_data (EaWeekViewMainItem *ea_main_item); + +static gint +ea_week_view_main_item_get_child_index_at (EaWeekViewMainItem *ea_main_item, + gint row, gint column); +static gint +ea_week_view_main_item_get_row_at_index (EaWeekViewMainItem *ea_main_item, + gint index); +static gint +ea_week_view_main_item_get_column_at_index (EaWeekViewMainItem *ea_main_item, + gint index); +static gint +ea_week_view_main_item_get_row_label (EaWeekViewMainItem *ea_main_item, + gint row, gchar *buffer, + gint buffer_size); + +#ifdef ACC_DEBUG +static gint n_ea_week_view_main_item_created = 0; +static gint n_ea_week_view_main_item_destroyed = 0; +#endif + +static gpointer parent_class = NULL; + +GType +ea_week_view_main_item_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaWeekViewMainItemClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_week_view_main_item_class_init, + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaWeekViewMainItem), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + static const GInterfaceInfo atk_table_info = { + (GInterfaceInitFunc) atk_table_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + static const GInterfaceInfo atk_selection_info = { + (GInterfaceInitFunc) atk_selection_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (GailCanvasItem, in this case) + * + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + e_week_view_main_item_get_type()); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaWeekViewMainItem", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + g_type_add_interface_static (type, ATK_TYPE_TABLE, + &atk_table_info); + g_type_add_interface_static (type, ATK_TYPE_SELECTION, + &atk_selection_info); + } + + return type; +} + +static void +ea_week_view_main_item_class_init (EaWeekViewMainItemClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + gobject_class->finalize = ea_week_view_main_item_finalize; + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_week_view_main_item_get_name; + class->get_description = ea_week_view_main_item_get_description; + + class->get_n_children = ea_week_view_main_item_get_n_children; + class->ref_child = ea_week_view_main_item_ref_child; + class->get_parent = ea_week_view_main_item_get_parent; + class->get_index_in_parent = ea_week_view_main_item_get_index_in_parent; +} + +AtkObject* +ea_week_view_main_item_new (GObject *obj) +{ + AtkObject *accessible; + GnomeCalendar *gcal; + EWeekViewMainItem *main_item; + + g_return_val_if_fail (E_IS_WEEK_VIEW_MAIN_ITEM (obj), NULL); + + accessible = ATK_OBJECT (g_object_new (EA_TYPE_WEEK_VIEW_MAIN_ITEM, + NULL)); + + atk_object_initialize (accessible, obj); + accessible->role = ATK_ROLE_TABLE; + +#ifdef ACC_DEBUG + ++n_ea_week_view_main_item_created; + printf ("ACC_DEBUG: n_ea_week_view_main_item_created = %d\n", + n_ea_week_view_main_item_created); +#endif + main_item = E_WEEK_VIEW_MAIN_ITEM (obj); + g_signal_connect (main_item->week_view, "selected_time_changed", + G_CALLBACK (ea_week_view_main_item_time_change_cb), + accessible); + + /* listen for date changes of calendar */ + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (main_item->week_view)); + if (gcal) + g_signal_connect (gcal, "dates_shown_changed", + G_CALLBACK (ea_week_view_main_item_dates_change_cb), + accessible); + + return accessible; +} + +static void +ea_week_view_main_item_finalize (GObject *object) +{ + EaWeekViewMainItem *ea_main_item; + + g_return_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (object)); + + ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (object); + + /* Free the allocated cell data */ + ea_week_view_main_item_destory_cell_data (ea_main_item); + + G_OBJECT_CLASS (parent_class)->finalize (object); +#ifdef ACC_DEBUG + ++n_ea_week_view_main_item_destroyed; + printf ("ACC_DEBUG: n_ea_week_view_main_item_destroyed = %d\n", + n_ea_week_view_main_item_destroyed); +#endif +} + +static G_CONST_RETURN gchar * +ea_week_view_main_item_get_name (AtkObject *accessible) +{ + AtkObject *parent; + g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), NULL); + parent = atk_object_get_parent (accessible); + return atk_object_get_name (parent); + +} + +static G_CONST_RETURN gchar * +ea_week_view_main_item_get_description (AtkObject *accessible) +{ + return _("a table to view and select the current time range"); +} + +static gint +ea_week_view_main_item_get_n_children (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (week_view->multi_week_view) + return 7 * week_view->weeks_shown; + else + return 7; +} + +static AtkObject * +ea_week_view_main_item_ref_child (AtkObject *accessible, gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + gint n_children; + EWeekViewCell *cell; + EaCellTable *cell_data; + EaWeekViewMainItem *ea_main_item; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + n_children = ea_week_view_main_item_get_n_children (accessible); + if (index < 0 || index >= n_children) + return NULL; + + ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (accessible); + cell_data = ea_week_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + cell = ea_cell_table_get_cell_at_index (cell_data, index); + if (!cell) { + gint row, column; + + row = ea_week_view_main_item_get_row_at_index (ea_main_item, index); + column = ea_week_view_main_item_get_column_at_index (ea_main_item, index); + cell = e_week_view_cell_new (week_view, row, column); + ea_cell_table_set_cell_at_index (cell_data, index, cell); + g_object_unref (cell); + } + + return g_object_ref (atk_gobject_accessible_for_object (G_OBJECT(cell))); +} + +static AtkObject * +ea_week_view_main_item_get_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + return gtk_widget_get_accessible (GTK_WIDGET (main_item->week_view)); +} + +static gint +ea_week_view_main_item_get_index_in_parent (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + + g_return_val_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + /* always the first child of ea-week-view */ + return 0; +} + +/* callbacks */ + +static void +ea_week_view_main_item_dates_change_cb (GnomeCalendar *gcal, gpointer data) +{ + EaWeekViewMainItem *ea_main_item; + + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); + g_return_if_fail (data); + g_return_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (data)); + + ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (data); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_week_view_main_item update cb\n"); +#endif + + ea_week_view_main_item_destory_cell_data (ea_main_item); +} + +static void +ea_week_view_main_item_time_change_cb (EWeekView *week_view, gpointer data) +{ + EaWeekViewMainItem *ea_main_item; + AtkObject *item_cell = NULL; + + g_return_if_fail (E_IS_WEEK_VIEW (week_view)); + g_return_if_fail (data); + g_return_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (data)); + + ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (data); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_week_view_main_item time changed cb\n"); +#endif + /* only deal with the first selected child, for now */ + item_cell = atk_selection_ref_selection (ATK_SELECTION (ea_main_item), + 0); + if (item_cell) { + AtkStateSet *state_set; + state_set = atk_object_ref_state_set (item_cell); + atk_state_set_add_state (state_set, ATK_STATE_FOCUSED); + g_object_unref (state_set); + + g_signal_emit_by_name (ea_main_item, + "active-descendant-changed", + item_cell); + g_signal_emit_by_name (data, "selection_changed"); + atk_focus_tracker_notify (item_cell); + g_object_unref (item_cell); + } +} + +/* helpers */ + +static gint +ea_week_view_main_item_get_child_index_at (EaWeekViewMainItem *ea_main_item, + gint row, gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (row >= 0 && row < week_view->weeks_shown && + column >= 0 && column < 7) + return row * 7 + column; + + return -1; +} + +static gint +ea_week_view_main_item_get_row_at_index (EaWeekViewMainItem *ea_main_item, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + gint n_children; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + n_children = ea_week_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); + if (index >= 0 && index < n_children) + return index / 7; + return -1; +} + +static gint +ea_week_view_main_item_get_column_at_index (EaWeekViewMainItem *ea_main_item, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + gint n_children; + + g_return_val_if_fail (ea_main_item, -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + n_children = ea_week_view_main_item_get_n_children (ATK_OBJECT (ea_main_item)); + if (index >= 0 && index < n_children) + return index % 7; + return -1; +} + +static gint +ea_week_view_main_item_get_row_label (EaWeekViewMainItem *ea_main_item, + gint row, gchar *buffer, gint buffer_size) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + + g_return_val_if_fail (ea_main_item, 0); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return 0; + + return g_snprintf (buffer, buffer_size, "the %i week", + row + 1); + +} + +static EaCellTable * +ea_week_view_main_item_get_cell_data (EaWeekViewMainItem *ea_main_item) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaCellTable *cell_data; + + g_return_val_if_fail (ea_main_item, NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + cell_data = g_object_get_data (G_OBJECT(ea_main_item), + "ea-week-view-cell-table"); + if (!cell_data) { + cell_data = ea_cell_table_create (week_view->weeks_shown, 7, TRUE); + g_object_set_data (G_OBJECT(ea_main_item), + "ea-week-view-cell-table", cell_data); + } + return cell_data; +} + +static void +ea_week_view_main_item_destory_cell_data (EaWeekViewMainItem *ea_main_item) +{ + EaCellTable *cell_data; + + g_return_if_fail (ea_main_item); + + cell_data = g_object_get_data (G_OBJECT(ea_main_item), + "ea-week-view-cell-table"); + if (cell_data) { + g_object_set_data (G_OBJECT(ea_main_item), + "ea-week-view-cell-table", NULL); + ea_cell_table_destroy (cell_data); + } +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = component_interface_get_extents; +} + +static void +component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + AtkObject *ea_canvas; + EWeekViewMainItem *main_item; + EWeekView *week_view; + + *x = *y = *width = *height = 0; + + g_return_if_fail (EA_IS_WEEK_VIEW_MAIN_ITEM (component)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + ea_canvas = gtk_widget_get_accessible (week_view->main_canvas); + atk_component_get_extents (ATK_COMPONENT (ea_canvas), x, y, + width, height, coord_type); +} + +/* atk table interface */ + +static void +atk_table_interface_init (AtkTableIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->ref_at = table_interface_ref_at; + + iface->get_n_rows = table_interface_get_n_rows; + iface->get_n_columns = table_interface_get_n_columns; + iface->get_index_at = table_interface_get_index_at; + iface->get_column_at_index = table_interface_get_column_at_index; + iface->get_row_at_index = table_interface_get_row_at_index; + iface->get_column_extent_at = table_interface_get_column_extent_at; + iface->get_row_extent_at = table_interface_get_row_extent_at; + + iface->is_selected = table_interface_is_selected; + iface->get_selected_rows = table_interface_get_selected_rows; + iface->get_selected_columns = table_interface_get_selected_columns; + iface->is_row_selected = table_interface_is_row_selected; + iface->is_column_selected = table_interface_is_column_selected; + iface->add_row_selection = table_interface_add_row_selection; + iface->remove_row_selection = table_interface_remove_row_selection; + iface->add_column_selection = table_interface_add_column_selection; + iface->remove_column_selection = table_interface_remove_column_selection; + + iface->get_row_header = table_interface_get_row_header; + iface->get_column_header = table_interface_get_column_header; + iface->get_caption = table_interface_get_caption; + iface->get_summary = table_interface_get_summary; + iface->get_row_description = table_interface_get_row_description; + iface->get_column_description = table_interface_get_column_description; +} + +static AtkObject* +table_interface_ref_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + index = ea_week_view_main_item_get_child_index_at (ea_main_item, + row, column); + return ea_week_view_main_item_ref_child (ATK_OBJECT (ea_main_item), index); +} + +static gint +table_interface_get_n_rows (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + return week_view->weeks_shown; +} + +static gint +table_interface_get_n_columns (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + return 7; +} + +static gint +table_interface_get_index_at (AtkTable *table, + gint row, + gint column) +{ + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + return ea_week_view_main_item_get_child_index_at (ea_main_item, + row, column); +} + +static gint +table_interface_get_column_at_index (AtkTable *table, + gint index) +{ + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + return ea_week_view_main_item_get_column_at_index (ea_main_item, index); +} + +static gint +table_interface_get_row_at_index (AtkTable *table, + gint index) +{ + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + return ea_week_view_main_item_get_row_at_index (ea_main_item, index); +} + +static gint +table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + gint width = 0, height = 0; + AtkObject *child; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + index = ea_week_view_main_item_get_child_index_at (ea_main_item, + row, column); + child = atk_object_ref_accessible_child (ATK_OBJECT (ea_main_item), + index); + if (child) + atk_component_get_size (ATK_COMPONENT (child), + &width, &height); + + return width; +} + +static gint +table_interface_get_row_extent_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + gint width = 0, height = 0; + AtkObject *child; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + index = ea_week_view_main_item_get_child_index_at (ea_main_item, + row, column); + child = atk_object_ref_accessible_child (ATK_OBJECT (ea_main_item), + index); + if (child) + atk_component_get_size (ATK_COMPONENT (child), + &width, &height); + + return height; +} + +static gboolean +table_interface_is_row_selected (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (week_view->selection_start_day == -1) + /* no selection */ + return FALSE; + if ((row < 0)&&(row + 1 > week_view->weeks_shown )) + return FALSE; + if (((week_view->selection_start_day < row*7)&&(week_view->selection_end_day<row*7)) + ||((week_view->selection_start_day > row*7+6)&&(week_view->selection_end_day > row*7+6))) + return FALSE; + else + return TRUE; +} + +static gboolean +table_interface_is_selected (AtkTable *table, + gint row, + gint column) +{ + return table_interface_is_row_selected (table, row) && table_interface_is_column_selected(table, column); +} + +static gboolean +table_interface_is_column_selected (AtkTable *table, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if ((column <0)||(column >6)) + return FALSE; + else { + gint i; + for (i=0;i<week_view->weeks_shown;i++) + if ((column + i*7>= week_view->selection_start_day ) && + (column + i*7<= week_view->selection_end_day)) + return TRUE; + return FALSE; + } +} + +static gint +table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + gint start_row = -1, n_rows = 0; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (week_view->selection_start_day == -1) + return 0; + + start_row = week_view->selection_start_day; + n_rows = week_view->selection_end_day - start_row + 1; + + if (n_rows > 0 && start_row != -1 && rows_selected) { + gint index; + + *rows_selected = (gint *) g_malloc (n_rows * sizeof (gint)); + for (index = 0; index < n_rows; ++index) + (*rows_selected)[index] = start_row + index; + } + return n_rows; +} + +static gint +table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + gint start_column = -1, n_columns = 0; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (week_view->selection_start_day == -1) + return 0; + if (week_view->selection_end_day - week_view->selection_start_day >= 6 ) { + start_column = 0; + n_columns =7; + } else { + start_column = week_view->selection_start_day % 7; + n_columns = (week_view->selection_end_day % 7) - start_column + 1; + } + if (n_columns > 0 && start_column != -1 && columns_selected) { + gint index; + + *columns_selected = (gint *) g_malloc (n_columns * sizeof (gint)); + for (index = 0; index < n_columns; ++index) + (*columns_selected)[index] = start_column + index; + } + return n_columns; +} + +static gboolean +table_interface_add_row_selection (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + /* FIXME: we need multi-selection */ + + week_view->selection_start_day = row * 7; + week_view->selection_end_day = row *7 + 6; + + gtk_widget_queue_draw (week_view->main_canvas); + return TRUE; +} + +static gboolean +table_interface_remove_row_selection (AtkTable *table, + gint row) +{ + return FALSE; +} + +static gboolean +table_interface_add_column_selection (AtkTable *table, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + /* FIXME: we need multi-selection */ + + week_view->selection_start_day = column; + week_view->selection_end_day = (week_view->weeks_shown - 1)*7+column; + + gtk_widget_queue_draw (week_view->main_canvas); + return TRUE; +} + +static gboolean +table_interface_remove_column_selection (AtkTable *table, + gint column) +{ + /* FIXME: NOT IMPLEMENTED */ + return FALSE; +} + +static AtkObject* +table_interface_get_row_header (AtkTable *table, + gint row) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_column_header (AtkTable *table, + gint in_col) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_caption (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, + gint in_col) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + const gchar *description; + EaCellTable *cell_data; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + if (in_col < 0 || in_col > 6) + return NULL; + cell_data = ea_week_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_column_label (cell_data, in_col); + if (!description) { + gchar buffer[128]; + + switch (in_col) { + case 0: + g_snprintf(buffer,128,"Monday"); + break; + case 1: + g_snprintf(buffer,128,"Tuesday"); + break; + case 2: + g_snprintf(buffer,128,"Wednesday"); + break; + case 3: + g_snprintf(buffer,128,"Thursday"); + break; + case 4: + g_snprintf(buffer,128,"Friday"); + break; + case 5: + g_snprintf(buffer,128,"Saturday"); + break; + case 6: + g_snprintf(buffer,128,"Sunday"); + break; + default: + break; + } + + ea_cell_table_set_column_label (cell_data, in_col, buffer); + description = ea_cell_table_get_column_label (cell_data, in_col); + } + return description; +} + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (table); + const gchar *description; + EaCellTable *cell_data; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (row < 0 || row >= week_view->weeks_shown) + return NULL; + cell_data = ea_week_view_main_item_get_cell_data (ea_main_item); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_row_label (cell_data, row); + if (!description) { + gchar buffer[128]; + ea_week_view_main_item_get_row_label (ea_main_item, row, buffer, sizeof (buffer)); + ea_cell_table_set_row_label (cell_data, row, buffer); + description = ea_cell_table_get_row_label (cell_data, + row); + } + return description; +} + +static AtkObject* +table_interface_get_summary (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +/* atkselection interface */ + +static void +atk_selection_interface_init (AtkSelectionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->add_selection = selection_interface_add_selection; + iface->clear_selection = selection_interface_clear_selection; + iface->ref_selection = selection_interface_ref_selection; + iface->get_selection_count = selection_interface_get_selection_count; + iface->is_child_selected = selection_interface_is_child_selected; +} + +static gboolean +selection_interface_add_selection (AtkSelection *selection, gint i) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (i < 0 || i > week_view->weeks_shown * 7 -1) + return FALSE; + + /*FIXME: multi-selection is needed */ + week_view->selection_start_day = i; + week_view->selection_end_day = i; + + gtk_widget_queue_draw (week_view->main_canvas); + return TRUE; +} + +static gboolean +selection_interface_clear_selection (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + week_view->selection_start_day = -1; + week_view->selection_end_day = -1; + + gtk_widget_queue_draw (week_view->main_canvas); + + return TRUE; +} + +static AtkObject* +selection_interface_ref_selection (AtkSelection *selection, gint i) +{ + gint count; + GObject *g_obj; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); + gint start_index; + + count = selection_interface_get_selection_count (selection); + if (i < 0 || i >=count) + return NULL; + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_main_item)); + week_view = E_WEEK_VIEW_MAIN_ITEM (g_obj)->week_view; + start_index = ea_week_view_main_item_get_child_index_at (ea_main_item, + week_view->selection_start_day / 7, + week_view->selection_start_day % 7); + + return ea_week_view_main_item_ref_child (ATK_OBJECT (selection), start_index + i); +} + +static gint +selection_interface_get_selection_count (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return 0; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if (week_view->selection_start_day == -1 || + week_view->selection_end_day == -1) + return 0; + + return week_view->selection_end_day - week_view->selection_start_day + 1; +} + +static gboolean +selection_interface_is_child_selected (AtkSelection *selection, gint i) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EWeekViewMainItem *main_item; + EWeekView *week_view; + EaWeekViewMainItem* ea_main_item = EA_WEEK_VIEW_MAIN_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_main_item); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + main_item = E_WEEK_VIEW_MAIN_ITEM (g_obj); + week_view = main_item->week_view; + + if ((week_view->selection_start_day <= i)&&(week_view->selection_end_day >= i)) + return TRUE; + else + return FALSE; +} + diff --git a/calendar/gui/ea-week-view-main-item.h b/calendar/gui/ea-week-view-main-item.h new file mode 100644 index 0000000000..d9110160c4 --- /dev/null +++ b/calendar/gui/ea-week-view-main-item.h @@ -0,0 +1,59 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * Yang Wu <Yang.Wu@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_WEEK_VIEW_MAIN_ITEM_H__ +#define __EA_WEEK_VIEW_MAIN_ITEM_H__ + +#include <atk/atkgobjectaccessible.h> +#include "e-week-view-main-item.h" + +G_BEGIN_DECLS + +#define EA_TYPE_WEEK_VIEW_MAIN_ITEM (ea_week_view_main_item_get_type ()) +#define EA_WEEK_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_WEEK_VIEW_MAIN_ITEM, EaWeekViewMainItem)) +#define EA_WEEK_VIEW_MAIN_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_WEEK_VIEW_MAIN_ITEM, EaWeekViewMainItemClass)) +#define EA_IS_WEEK_VIEW_MAIN_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_WEEK_VIEW_MAIN_ITEM)) +#define EA_IS_WEEK_VIEW_MAIN_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_WEEK_VIEW_MAIN_ITEM)) +#define EA_WEEK_VIEW_MAIN_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_WEEK_VIEW_MAIN_ITEM, EaWeekViewMainItemClass)) + +typedef struct _EaWeekViewMainItem EaWeekViewMainItem; +typedef struct _EaWeekViewMainItemClass EaWeekViewMainItemClass; + +struct _EaWeekViewMainItem +{ + AtkGObjectAccessible parent; +}; + +GType ea_week_view_main_item_get_type (void); + +struct _EaWeekViewMainItemClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject* ea_week_view_main_item_new (GObject *obj); + +G_END_DECLS + +#endif /* __EA_WEEK_VIEW_MAIN_ITEM_H__ */ diff --git a/calendar/gui/ea-week-view.c b/calendar/gui/ea-week-view.c new file mode 100644 index 0000000000..97a8dae25d --- /dev/null +++ b/calendar/gui/ea-week-view.c @@ -0,0 +1,321 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "ea-week-view.h" +#include "ea-cal-view-event.h" +#include "ea-calendar-helpers.h" +#include "ea-gnome-calendar.h" +#include "calendar-commands.h" +#include <text/e-text.h> +#include <glib/gi18n.h> + +static void ea_week_view_class_init (EaWeekViewClass *klass); + +static G_CONST_RETURN gchar * ea_week_view_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_week_view_get_description (AtkObject *accessible); +static gint ea_week_view_get_n_children (AtkObject *obj); +static AtkObject* ea_week_view_ref_child (AtkObject *obj, + gint i); + +static gpointer parent_class = NULL; + +GType +ea_week_view_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaWeekViewClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_week_view_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaWeekView), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (EaCalView, in this case) + * + * Note: we must still use run-time deriving here, because + * our parent class EaCalView is run-time deriving. + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + e_calendar_view_get_type()); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaWeekView", &tinfo, 0); + + } + + return type; +} + +static void +ea_week_view_class_init (EaWeekViewClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_week_view_get_name; + class->get_description = ea_week_view_get_description; + + class->get_n_children = ea_week_view_get_n_children; + class->ref_child = ea_week_view_ref_child; +} + +AtkObject* +ea_week_view_new (GtkWidget *widget) +{ + GObject *object; + AtkObject *accessible; + + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + + object = g_object_new (EA_TYPE_WEEK_VIEW, NULL); + + accessible = ATK_OBJECT (object); + atk_object_initialize (accessible, widget); + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_week_view created %p\n", (gpointer)accessible); +#endif + + return accessible; +} + +static G_CONST_RETURN gchar * +ea_week_view_get_name (AtkObject *accessible) +{ + EWeekView *week_view; + GnomeCalendar *gcal; + const gchar *label_text; + GnomeCalendarViewType view_type; + gint n_events; + gchar *event_str, *name_str; + + g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible), NULL); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + + week_view = E_WEEK_VIEW (GTK_ACCESSIBLE (accessible)->widget); + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view)); + if (!GTK_WIDGET_VISIBLE (GTK_WIDGET (gcal))) + return NULL; + + label_text = ea_gnome_calendar_get_label_description (gcal); + + n_events = atk_object_get_n_accessible_children (accessible); + /* the child main item is always there */ + --n_events; + if (n_events >= 1) + event_str = g_strdup_printf (ngettext ("It has %d event.", "It has %d events.", n_events), n_events); + else + event_str = g_strdup (_("It has no events.")); + + view_type = gnome_calendar_get_view (gcal); + + if (view_type == GNOME_CAL_MONTH_VIEW) + name_str = g_strdup_printf (_("Month View: %s. %s"), + label_text, event_str); + + else + name_str = g_strdup_printf (_("Week View: %s. %s"), + label_text, event_str); + + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_str); + g_free (name_str); + g_free (event_str); + + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_week_view_get_description (AtkObject *accessible) +{ + EWeekView *week_view; + + g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible), NULL); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + week_view = E_WEEK_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + if (accessible->description) + return accessible->description; + else { + GnomeCalendar *gcal; + GnomeCalendarViewType view_type; + + gcal = e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view)); + view_type = gnome_calendar_get_view (gcal); + + if (view_type == GNOME_CAL_MONTH_VIEW) + return _("calendar view for a month"); + else + return _("calendar view for one or more weeks"); + } +} + +static gint +ea_week_view_get_n_children (AtkObject *accessible) +{ + EWeekView *week_view; + gint i, count = 0; + gint event_index; + + g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible), -1); + + if (!GTK_ACCESSIBLE (accessible)->widget) + return -1; + week_view = E_WEEK_VIEW (GTK_ACCESSIBLE (accessible)->widget); + + for (event_index = 0; event_index < week_view->events->len; + ++event_index) { + EWeekViewEvent *event; + EWeekViewEventSpan *span; + + /* If week_view->spans == NULL, there is no visible events. */ + if (!week_view->spans) + break; + + event = &g_array_index (week_view->events, + EWeekViewEvent, event_index); + if (!event) + continue; + span = &g_array_index (week_view->spans, EWeekViewEventSpan, + event->spans_index + 0); + + if (!span) + continue; + + /* at least one of the event spans is visible, count it */ + if (span->text_item) + ++count; + } + + /* add the number of visible jump buttons */ + for (i = 0; i < E_WEEK_VIEW_MAX_WEEKS * 7; i++) { + if (week_view->jump_buttons[i]->object.flags & GNOME_CANVAS_ITEM_VISIBLE) + ++count; + } + + /* "+1" for the main item */ + count++; + +#ifdef ACC_DEBUG + printf("AccDebug: week view %p has %d children\n", (gpointer)week_view, count); +#endif + return count; +} + +static AtkObject * +ea_week_view_ref_child (AtkObject *accessible, gint index) +{ + EWeekView *week_view; + gint child_num, max_count; + AtkObject *atk_object = NULL; + gint event_index; + gint jump_button = -1; + gint span_num = 0; + gint count = 0; + + g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible), NULL); + + child_num = atk_object_get_n_accessible_children (accessible); + if (child_num <= 0 || index < 0 || index >= child_num) + return NULL; + + if (!GTK_ACCESSIBLE (accessible)->widget) + return NULL; + week_view = E_WEEK_VIEW (GTK_ACCESSIBLE (accessible)->widget); + max_count = week_view->events->len; + + if (index == 0) { + /* index == 0 is the main item */ + atk_object = atk_gobject_accessible_for_object (G_OBJECT (week_view->main_canvas_item)); + g_object_ref (atk_object); + } else + for (event_index = 0; event_index < max_count; ++event_index) { + EWeekViewEvent *event; + EWeekViewEventSpan *span; + gint current_day; + + event = &g_array_index (week_view->events, + EWeekViewEvent, event_index); + if (!event) + continue; + + span = &g_array_index (week_view->spans, EWeekViewEventSpan, + event->spans_index + span_num); + + if (!span) + continue; + + current_day = span->start_day; + if (span->text_item) + ++count; + else if (current_day != jump_button) { + /* we should go to the jump button */ + jump_button = current_day; + ++count; + } + else + continue; + + if (count == index) { + if (span->text_item) { + /* Not use atk_gobject_accessible_for_object for event + * text_item we need to do special thing here + */ + atk_object = ea_calendar_helpers_get_accessible_for (span->text_item); + } + else { + atk_object = ea_calendar_helpers_get_accessible_for (week_view->jump_buttons[current_day == -1 ? 0 : current_day]); + } + g_object_ref (atk_object); + break; + } + } + +#ifdef ACC_DEBUG + printf ("EvoAcc: ea_week_view_ref_child [%d]=%p\n", + index, (gpointer)atk_object); +#endif + return atk_object; +} diff --git a/calendar/gui/ea-week-view.h b/calendar/gui/ea-week-view.h new file mode 100644 index 0000000000..bb71c17e74 --- /dev/null +++ b/calendar/gui/ea-week-view.h @@ -0,0 +1,59 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Authors: + * Bolian Yin <bolian.yin@sun.com> + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_WEEK_VIEW_H__ +#define __EA_WEEK_VIEW_H__ + +#include "ea-cal-view.h" +#include "e-week-view.h" + +G_BEGIN_DECLS + +#define EA_TYPE_WEEK_VIEW (ea_week_view_get_type ()) +#define EA_WEEK_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_WEEK_VIEW, EaWeekView)) +#define EA_WEEK_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_WEEK_VIEW, EaWeekViewClass)) +#define EA_IS_WEEK_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_WEEK_VIEW)) +#define EA_IS_WEEK_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_WEEK_VIEW)) +#define EA_WEEK_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_WEEK_VIEW, EaWeekViewClass)) + +typedef struct _EaWeekView EaWeekView; +typedef struct _EaWeekViewClass EaWeekViewClass; + +struct _EaWeekView +{ + EaCalView parent; +}; + +GType ea_week_view_get_type (void); + +struct _EaWeekViewClass +{ + EaCalViewClass parent_class; +}; + +AtkObject* ea_week_view_new (GtkWidget *widget); + +G_END_DECLS + + +#endif /* __EA_WEEK_VIEW_H__ */ diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 1e943eeb14..8fe302293f 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -53,7 +53,6 @@ #include "e-comp-editor-registry.h" #include "dialogs/delete-error.h" #include "dialogs/event-editor.h" -#include "dialogs/task-editor.h" #include "comp-util.h" #include "e-cal-model-calendar.h" #include "e-day-view.h" @@ -65,11 +64,9 @@ #include "e-cal-list-view-config.h" #include "e-mini-calendar-config.h" #include "e-calendar-table-config.h" -#include "e-memo-table-config.h" #include "evolution-calendar.h" #include "gnome-cal.h" #include "calendar-component.h" -#include "memos-component.h" #include "cal-search-bar.h" #include "calendar-commands.h" #include "calendar-config.h" @@ -77,11 +74,10 @@ #include "calendar-view-factory.h" #include "tag-calendar.h" #include "misc.h" -#include "ea-calendar.h" +#include "a11y/ea-calendar.h" #include "common/authentication.h" #include "e-cal-popup.h" #include "e-cal-menu.h" -#include "e-cal-model-tasks.h" /* FIXME glib 2.4 and above has this */ #ifndef G_MAXINT32 @@ -97,9 +93,9 @@ static GHashTable *non_intrusive_error_table = NULL; struct _GnomeCalendarPrivate { /* The clients for display */ - GHashTable *clients[E_CAL_SOURCE_TYPE_LAST]; - GList *clients_list[E_CAL_SOURCE_TYPE_LAST]; - ECal *default_client[E_CAL_SOURCE_TYPE_LAST]; + GHashTable *clients; + GList *clients_list; + ECal *default_client; /* * Fields for the calendar view @@ -118,11 +114,6 @@ struct _GnomeCalendarPrivate { ECalendar *date_navigator; EMiniCalendarConfig *date_navigator_config; - GtkWidget *todo; - ECalendarTableConfig *todo_config; - - GtkWidget *memo; - EMemoTableConfig *memo_config; GtkWidget *day_view; GtkWidget *work_week_view; @@ -135,8 +126,6 @@ struct _GnomeCalendarPrivate { /* plugin menu managers */ ECalMenu *calendar_menu; - ECalMenu *taskpad_menu; - ECalMenu *memopad_menu; /* Calendar query for the date navigator */ GList *dn_queries; /* list of CalQueries */ @@ -167,10 +156,6 @@ struct _GnomeCalendarPrivate { /* The signal handler id for our GtkCalendar "day_selected" handler. */ guint day_selected_id; - /* View instance and menus for the control */ - GalViewInstance *view_instance; - GalViewMenus *view_menus; - /* Our current week start */ gint week_start; @@ -201,11 +186,6 @@ struct _GnomeCalendarPrivate { enum { DATES_SHOWN_CHANGED, CALENDAR_SELECTION_CHANGED, - TASKPAD_SELECTION_CHANGED, - MEMOPAD_SELECTION_CHANGED, - CALENDAR_FOCUS_CHANGE, - TASKPAD_FOCUS_CHANGE, - MEMOPAD_FOCUS_CHANGE, GOTO_DATE, SOURCE_ADDED, SOURCE_REMOVED, @@ -213,14 +193,6 @@ enum { LAST_SIGNAL }; -/* Used to indicate who has the focus within the calendar view */ -typedef enum { - FOCUS_CALENDAR, - FOCUS_TASKPAD, - FOCUS_MEMOPAD, - FOCUS_OTHER -} FocusLocation; - static guint gnome_calendar_signals[LAST_SIGNAL]; @@ -317,55 +289,6 @@ gnome_calendar_class_init (GnomeCalendarClass *class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - gnome_calendar_signals[TASKPAD_SELECTION_CHANGED] = - g_signal_new ("taskpad_selection_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GnomeCalendarClass, taskpad_selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - gnome_calendar_signals[MEMOPAD_SELECTION_CHANGED] = - g_signal_new ("memopad_selection_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GnomeCalendarClass, memopad_selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - - gnome_calendar_signals[CALENDAR_FOCUS_CHANGE] = - g_signal_new ("calendar_focus_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GnomeCalendarClass, calendar_focus_change), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, - G_TYPE_BOOLEAN); - - gnome_calendar_signals[TASKPAD_FOCUS_CHANGE] = - g_signal_new ("taskpad_focus_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GnomeCalendarClass, taskpad_focus_change), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, - G_TYPE_BOOLEAN); - - gnome_calendar_signals[MEMOPAD_FOCUS_CHANGE] = - g_signal_new ("memopad_focus_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GnomeCalendarClass, memopad_focus_change), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, - G_TYPE_BOOLEAN); - gnome_calendar_signals[SOURCE_ADDED] = g_signal_new ("source_added", G_TYPE_FROM_CLASS (object_class), @@ -414,11 +337,6 @@ gnome_calendar_class_init (GnomeCalendarClass *class) class->dates_shown_changed = NULL; class->calendar_selection_changed = NULL; - class->taskpad_selection_changed = NULL; - class->memopad_selection_changed = NULL; - class->calendar_focus_change = NULL; - class->taskpad_focus_change = NULL; - class->memopad_focus_change = NULL; class->source_added = NULL; class->source_removed = NULL; class->goto_date = gnome_calendar_goto_date; @@ -734,69 +652,6 @@ get_times_for_views (GnomeCalendar *gcal, GnomeCalendarViewType view_type, time_ } } -/* Gets the focus location based on who is the focused widget within the - * calendar view. - */ -static FocusLocation -get_focus_location (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - ETable *etable, *m_etable; - - priv = gcal->priv; - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - m_etable = e_memo_table_get_table (E_MEMO_TABLE (priv->memo)); - - if (GTK_WIDGET_HAS_FOCUS (etable->table_canvas)) - return FOCUS_TASKPAD; - else if (GTK_WIDGET_HAS_FOCUS (m_etable->table_canvas)) - return FOCUS_MEMOPAD; - else { - GtkWidget *widget; - EDayView *dv; - EWeekView *wv; - ECalListView *lv; - - widget = gnome_calendar_get_current_view_widget (gcal); - - switch (priv->current_view_type) { - case GNOME_CAL_DAY_VIEW: - case GNOME_CAL_WORK_WEEK_VIEW: - dv = E_DAY_VIEW (widget); - - if (GTK_WIDGET_HAS_FOCUS (dv->top_canvas) - || GNOME_CANVAS (dv->top_canvas)->focused_item != NULL - || GTK_WIDGET_HAS_FOCUS (dv->main_canvas) - || GNOME_CANVAS (dv->main_canvas)->focused_item != NULL) - return FOCUS_CALENDAR; - else - return FOCUS_OTHER; - - case GNOME_CAL_WEEK_VIEW: - case GNOME_CAL_MONTH_VIEW: - wv = E_WEEK_VIEW (widget); - - if (GTK_WIDGET_HAS_FOCUS (wv->main_canvas) - || GNOME_CANVAS (wv->main_canvas)->focused_item != NULL) - return FOCUS_CALENDAR; - else - return FOCUS_OTHER; - - case GNOME_CAL_LIST_VIEW: - lv = E_CAL_LIST_VIEW (widget); - - if (GTK_WIDGET_HAS_FOCUS (e_table_scrolled_get_table (lv->table_scrolled))) - return FOCUS_CALENDAR; - else - return FOCUS_OTHER; - - default: - g_return_val_if_reached (FOCUS_OTHER); - } - } -} - /* Computes the range of time that the date navigator is showing */ static void get_date_navigator_range (GnomeCalendar *gcal, time_t *start_time, time_t *end_time) @@ -900,7 +755,7 @@ update_query_async (struct _date_query_msg *msg) } /* create queries for each loaded client */ - for (l = priv->clients_list[E_CAL_SOURCE_TYPE_EVENT]; l != NULL; l = l->next) { + for (l = priv->clients_list; l != NULL; l = l->next) { GError *error = NULL; gint tries = 0; @@ -1070,8 +925,9 @@ search_bar_category_changed_cb (CalSearchBar *cal_search, const gchar *category, category); } + /* [KILL-BONOBO] Delete this when moved to ECalShellView. model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - e_cal_model_set_default_category (model, category); + e_cal_model_set_default_category (model, category); */ } static void @@ -1122,112 +978,6 @@ user_created_cb (GtkWidget *view, GnomeCalendar *gcal) } -/* Callback used when the taskpad receives a focus event. We emit the - * corresponding signal so that parents can change the menus as appropriate. - */ -static gint -table_canvas_focus_change_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - g_signal_emit (gcal, gnome_calendar_signals [TASKPAD_FOCUS_CHANGE], 0, - event->in ? TRUE : FALSE); - - return FALSE; -} - -static gint -memo_canvas_focus_change_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - g_signal_emit (gcal, gnome_calendar_signals [MEMOPAD_FOCUS_CHANGE], 0, - event->in ? TRUE : FALSE); - - return FALSE; -} - -static gint -calendar_focus_change_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - g_signal_emit (gcal, gnome_calendar_signals [CALENDAR_FOCUS_CHANGE], 0, - event->in ? TRUE : FALSE); - - return FALSE; -} - -/* Connects to the focus change signals of a day view widget */ -static void -connect_day_view_focus (GnomeCalendar *gcal, EDayView *dv) -{ - g_signal_connect_after (dv->top_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect_after (dv->top_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - - g_signal_connect_after (dv->main_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect_after (dv->main_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); -} - -/* Connects to the focus change signals of a week view widget */ -static void -connect_week_view_focus (GnomeCalendar *gcal, EWeekView *wv) -{ - if (!E_IS_WEEK_VIEW (wv)) - return; - - g_signal_connect (wv->main_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect (wv->main_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); -} - -static void -connect_list_view_focus (GnomeCalendar *gcal, ECalListView *lv) -{ - ETable *etable; - - etable = e_table_scrolled_get_table (lv->table_scrolled); - - g_signal_connect (etable->table_canvas, "focus_in_event", - G_CALLBACK (calendar_focus_change_cb), gcal); - g_signal_connect (etable->table_canvas, "focus_out_event", - G_CALLBACK (calendar_focus_change_cb), gcal); -} - -/* Callback used when the selection in the taskpad table changes. We just proxy - * the signal with our own one. - */ -static void -table_selection_change_cb (ETable *etable, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - g_signal_emit (gcal, gnome_calendar_signals[TASKPAD_SELECTION_CHANGED], 0); -} - -static void -memo_selection_change_cb (ETable *etable, gpointer data) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (data); - - g_signal_emit (gcal, gnome_calendar_signals[MEMOPAD_SELECTION_CHANGED], 0); -} - static void set_week_start (GnomeCalendar *calendar) { @@ -1280,27 +1030,18 @@ static void set_timezone (GnomeCalendar *calendar) { GnomeCalendarPrivate *priv; - gint i; + GList *l; priv = calendar->priv; priv->zone = calendar_config_get_icaltimezone (); - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { - GList *l; - - for (l = priv->clients_list[i]; l != NULL; l = l->next) { - ECal *client = l->data; - - if (e_cal_get_load_state (client) == E_CAL_LOAD_LOADED) - /* FIXME Error checking */ - e_cal_set_default_timezone (client, priv->zone, NULL); - } + for (l = priv->clients_list; l != NULL; l = l->next) { + ECal *client = l->data; - if (priv->default_client[i] - && e_cal_get_load_state (priv->default_client[i]) == E_CAL_LOAD_LOADED) + if (e_cal_get_load_state (client) == E_CAL_LOAD_LOADED) /* FIXME Error checking */ - e_cal_set_default_timezone (priv->default_client[i], priv->zone, NULL); + e_cal_set_default_timezone (client, priv->zone, NULL); } if (priv->views [priv->current_view_type]) @@ -1576,26 +1317,15 @@ categories_changed_cb (gpointer object, gpointer user_data) static void view_progress_cb (ECalModel *model, const gchar *message, gint percent, ECalSourceType type, GnomeCalendar *gcal) { - if (type == E_CAL_SOURCE_TYPE_EVENT) { + if (type == E_CAL_SOURCE_TYPE_EVENT) e_calendar_view_set_status_message (E_CALENDAR_VIEW (gcal->priv->week_view), message, percent); - } else if (type == E_CAL_SOURCE_TYPE_TODO) { - e_calendar_table_set_status_message (E_CALENDAR_TABLE (gcal->priv->todo), message, percent); - } else if (type == E_CAL_SOURCE_TYPE_JOURNAL) { - e_memo_table_set_status_message (E_MEMO_TABLE (gcal->priv->memo), message); - } } static void view_done_cb (ECalModel *model, ECalendarStatus status, ECalSourceType type, GnomeCalendar *gcal) { - if (type == E_CAL_SOURCE_TYPE_EVENT) { + if (type == E_CAL_SOURCE_TYPE_EVENT) e_calendar_view_set_status_message (E_CALENDAR_VIEW (gcal->priv->week_view), NULL, -1); - } else if (type == E_CAL_SOURCE_TYPE_TODO) { - e_calendar_table_set_status_message (E_CALENDAR_TABLE (gcal->priv->todo), NULL, -1); - } else if (type == E_CAL_SOURCE_TYPE_JOURNAL) { - e_memo_table_set_status_message (E_MEMO_TABLE (gcal->priv->memo), NULL); - } - } GtkWidget * @@ -1700,36 +1430,11 @@ setup_widgets (GnomeCalendar *gcal) g_free (tmp); gtk_box_pack_start ((GtkBox *)vbox, label, FALSE, TRUE, 0); - priv->todo = e_calendar_table_new (); - priv->todo_config = e_calendar_table_config_new (E_CALENDAR_TABLE (priv->todo)); - gtk_paned_pack1 (GTK_PANED (priv->vpane), vbox, FALSE, FALSE); - gtk_box_pack_end ((GtkBox *)vbox, priv->todo, TRUE, TRUE, 0); - - gtk_widget_show (priv->todo); gtk_widget_show (label); gtk_widget_show (vbox); gtk_widget_show (sep); - filename = g_build_filename (calendar_component_peek_config_directory (calendar_component_peek ()), - "TaskPad", NULL); - e_calendar_table_load_state (E_CALENDAR_TABLE (priv->todo), filename); - /* update_todo_view (gcal); */ - g_free (filename); - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - g_signal_connect (etable->table_canvas, "focus_in_event", - G_CALLBACK (table_canvas_focus_change_cb), gcal); - g_signal_connect (etable->table_canvas, "focus_out_event", - G_CALLBACK (table_canvas_focus_change_cb), gcal); - - g_signal_connect (etable, "selection_change", - G_CALLBACK (table_selection_change_cb), gcal); - - g_signal_connect (e_calendar_table_get_model ((ECalendarTable *)priv->todo), "cal_view_progress", - G_CALLBACK (view_progress_cb), gcal); - g_signal_connect (e_calendar_table_get_model ((ECalendarTable *)priv->todo), "cal_view_done", - G_CALLBACK (view_done_cb), gcal); /* Timeout check to hide completed items */ priv->update_timeout = g_timeout_add_full (G_PRIORITY_LOW, 60000, (GSourceFunc) update_todo_view_cb, gcal, NULL); @@ -1744,7 +1449,6 @@ setup_widgets (GnomeCalendar *gcal) e_calendar_view_set_timezone (E_CALENDAR_VIEW (priv->day_view), priv->zone); g_signal_connect (priv->day_view, "selection_changed", G_CALLBACK (view_selection_changed_cb), gcal); - connect_day_view_focus (gcal, E_DAY_VIEW (priv->day_view)); /* The Work Week View. */ priv->work_week_view = e_day_view_new (cal_model); @@ -1753,7 +1457,6 @@ setup_widgets (GnomeCalendar *gcal) e_day_view_set_days_shown (E_DAY_VIEW (priv->work_week_view), 5); e_calendar_view_set_calendar (E_CALENDAR_VIEW (priv->work_week_view), gcal); e_calendar_view_set_timezone (E_CALENDAR_VIEW (priv->work_week_view), priv->zone); - connect_day_view_focus (gcal, E_DAY_VIEW (priv->work_week_view)); /* The Marcus Bains line */ priv->update_marcus_bains_line_timeout = g_timeout_add_full (G_PRIORITY_LOW, 60000, (GSourceFunc) update_marcus_bains_line_cb, gcal, NULL); @@ -1765,8 +1468,6 @@ setup_widgets (GnomeCalendar *gcal) g_signal_connect (priv->week_view, "selection_changed", G_CALLBACK (view_selection_changed_cb), gcal); - connect_week_view_focus (gcal, E_WEEK_VIEW (priv->week_view)); - adjustment = gtk_range_get_adjustment (GTK_RANGE (E_WEEK_VIEW (priv->week_view)->vscrollbar)); g_signal_connect (adjustment, "value_changed", G_CALLBACK (week_view_adjustment_changed_cb), @@ -1786,8 +1487,6 @@ setup_widgets (GnomeCalendar *gcal) g_signal_connect (priv->month_view, "selection_changed", G_CALLBACK (view_selection_changed_cb), gcal); - connect_week_view_focus (gcal, E_WEEK_VIEW (priv->month_view)); - adjustment = gtk_range_get_adjustment (GTK_RANGE (E_WEEK_VIEW (priv->month_view)->vscrollbar)); g_signal_connect (adjustment, "value_changed", G_CALLBACK (month_view_adjustment_changed_cb), @@ -1801,8 +1500,6 @@ setup_widgets (GnomeCalendar *gcal) g_signal_connect (priv->list_view, "selection_changed", G_CALLBACK (view_selection_changed_cb), gcal); - connect_list_view_focus (gcal, E_CAL_LIST_VIEW (priv->list_view)); - priv->views[GNOME_CAL_DAY_VIEW] = E_CALENDAR_VIEW (priv->day_view); priv->configs[GNOME_CAL_DAY_VIEW] = G_OBJECT (e_day_view_config_new (E_DAY_VIEW (priv->views[GNOME_CAL_DAY_VIEW]))); priv->views[GNOME_CAL_WORK_WEEK_VIEW] = E_CALENDAR_VIEW (priv->work_week_view); @@ -1831,38 +1528,14 @@ setup_widgets (GnomeCalendar *gcal) gtk_label_set_markup ((GtkLabel *)label, tmp); g_free (tmp); gtk_box_pack_start ((GtkBox *)vbox, label, FALSE, TRUE, 0); - priv->memo = e_memo_table_new (); - priv->memo_config = e_memo_table_config_new (E_MEMO_TABLE (priv->memo)); - gtk_paned_pack2 (GTK_PANED (priv->vpane), vbox, TRUE, FALSE); - gtk_box_pack_end ((GtkBox *)vbox, priv->memo, TRUE, TRUE, 0); - - gtk_widget_show (priv->memo); gtk_widget_show (label); gtk_widget_show (vbox); - filename = g_build_filename (memos_component_peek_config_directory (memos_component_peek ()), - "MemoPad", NULL); - e_memo_table_load_state (E_MEMO_TABLE (priv->memo), filename); + e_cal_model_set_default_time_func (e_memo_table_get_model (E_MEMO_TABLE (priv->memo)), gc_get_default_time, gcal); e_cal_model_set_default_time_func (e_memo_table_get_model (E_MEMO_TABLE (priv->memo)), gc_get_default_time, gcal); update_memo_view (gcal); - g_free (filename); - - etable = e_memo_table_get_table (E_MEMO_TABLE (priv->memo)); - g_signal_connect (etable->table_canvas, "focus_in_event", - G_CALLBACK (memo_canvas_focus_change_cb), gcal); - g_signal_connect (etable->table_canvas, "focus_out_event", - G_CALLBACK (memo_canvas_focus_change_cb), gcal); - - g_signal_connect (etable, "selection_change", - G_CALLBACK (memo_selection_change_cb), gcal); - - g_signal_connect (e_memo_table_get_model ((EMemoTable *)priv->memo), "cal_view_progress", - G_CALLBACK (view_progress_cb), gcal); - g_signal_connect (e_memo_table_get_model ((EMemoTable *)priv->memo), "cal_view_done", - G_CALLBACK (view_done_cb), gcal); - } /* Object initialization function for the gnome calendar */ @@ -1870,13 +1543,14 @@ static void gnome_calendar_init (GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - gint i; priv = g_new0 (GnomeCalendarPrivate, 1); gcal->priv = priv; - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) - priv->clients[i] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + priv->clients = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); + + if (non_intrusive_error_table == NULL) + non_intrusive_error_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); if (non_intrusive_error_table == NULL) non_intrusive_error_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); @@ -1893,8 +1567,6 @@ gnome_calendar_init (GnomeCalendar *gcal) setup_widgets (gcal); priv->calendar_menu = e_cal_menu_new("org.gnome.evolution.calendar.view"); - priv->taskpad_menu = e_cal_menu_new("org.gnome.evolution.calendar.taskpad"); - priv->memopad_menu = e_cal_menu_new ("org.gnome.evolution.calendar.memopad"); priv->dn_queries = NULL; priv->sexp = g_strdup ("#t"); /* Match all */ @@ -1902,7 +1574,6 @@ gnome_calendar_init (GnomeCalendar *gcal) priv->memo_sexp = g_strdup ("#t"); priv->view_instance = NULL; - priv->view_menus = NULL; priv->visible_start = -1; priv->visible_end = -1; @@ -1930,37 +1601,24 @@ gnome_calendar_destroy (GtkObject *object) e_categories_unregister_change_listener (G_CALLBACK (categories_changed_cb), gcal); /* Clean up the clients */ - for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { - for (l = priv->clients_list[i]; l != NULL; l = l->next) { - ESource *source = e_cal_get_source (l->data); - - g_signal_handlers_disconnect_matched (l->data, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - - if (source) - g_signal_handlers_disconnect_matched (source, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, gcal); - } - - g_hash_table_destroy (priv->clients[i]); - g_list_free (priv->clients_list[i]); - - priv->clients[i] = NULL; - priv->clients_list[i] = NULL; - - if (priv->default_client[i]) { - ESource *source = e_cal_get_source (priv->default_client[i]); + for (l = priv->clients_list; l != NULL; l = l->next) { + g_signal_handlers_disconnect_matched (l->data, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, gcal); + } - g_signal_handlers_disconnect_matched (priv->default_client[i], - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); + g_hash_table_destroy (priv->clients); + g_list_free (priv->clients_list); - if (source) - g_signal_handlers_disconnect_matched (source, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, gcal); + priv->clients = NULL; + priv->clients_list = NULL; - g_object_unref (priv->default_client[i]); - } - priv->default_client[i] = NULL; + if (priv->default_client) { + g_signal_handlers_disconnect_matched (priv->default_client, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, gcal); + g_object_unref (priv->default_client); } + priv->default_client = NULL; for (i = 0; i < GNOME_CAL_LAST_VIEW; i++) { if (priv->configs[i]) @@ -1968,26 +1626,12 @@ gnome_calendar_destroy (GtkObject *object) priv->configs[i] = NULL; } g_object_unref (priv->date_navigator_config); - g_object_unref (priv->todo_config); - g_object_unref (priv->memo_config); for (l = priv->notifications; l; l = l->next) calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); g_list_free (priv->notifications); priv->notifications = NULL; - /* Save the TaskPad layout. */ - filename = g_build_filename (calendar_component_peek_config_directory (calendar_component_peek ()), - "TaskPad", NULL); - e_calendar_table_save_state (E_CALENDAR_TABLE (priv->todo), filename); - g_free (filename); - - /* Save the MemoPad layout. */ - filename = g_build_filename (memos_component_peek_config_directory (memos_component_peek ()), - "MemoPad", NULL); - e_memo_table_save_state (E_MEMO_TABLE (priv->memo), filename); - g_free (filename); - if (priv->dn_queries) { for (l = priv->dn_queries; l != NULL; l = l->next) { g_signal_handlers_disconnect_matched ((ECalView *) l->data, G_SIGNAL_MATCH_DATA, @@ -2009,50 +1653,21 @@ gnome_calendar_destroy (GtkObject *object) priv->sexp = NULL; } - if (priv->todo_sexp) { - g_free (priv->todo_sexp); - priv->todo_sexp = NULL; - } - - if (priv->memo_sexp) { - g_free (priv->memo_sexp); - priv->memo_sexp = NULL; - } - if (priv->update_timeout) { g_source_remove (priv->update_timeout); priv->update_timeout = 0; } - if (priv->view_instance) { - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - } - if (priv->update_marcus_bains_line_timeout) { g_source_remove (priv->update_marcus_bains_line_timeout); priv->update_marcus_bains_line_timeout = 0; } - if (priv->view_menus) { - g_object_unref (priv->view_menus); - priv->view_menus = NULL; - } - if (priv->calendar_menu) { g_object_unref (priv->calendar_menu); priv->calendar_menu = NULL; } - if (priv->taskpad_menu) { - g_object_unref (priv->taskpad_menu); - priv->taskpad_menu = NULL; - } - - if (priv->memopad_menu) { - g_object_unref (priv->memopad_menu); - priv->memopad_menu = NULL; - } /* Disconnect all handlers */ cal_model = e_calendar_view_get_model ((ECalendarView *)priv->week_view); g_signal_handlers_disconnect_by_func (cal_model, @@ -2060,17 +1675,7 @@ gnome_calendar_destroy (GtkObject *object) g_signal_handlers_disconnect_by_func (cal_model, G_CALLBACK (view_done_cb), gcal); - cal_model = e_calendar_table_get_model ((ECalendarTable *) priv->todo); - g_signal_handlers_disconnect_by_func (cal_model, - G_CALLBACK (view_progress_cb), gcal); - g_signal_handlers_disconnect_by_func (cal_model, - G_CALLBACK (view_done_cb), gcal); - - cal_model = e_memo_table_get_model ((EMemoTable *)priv->memo); - g_signal_handlers_disconnect_by_func (cal_model, - G_CALLBACK (view_progress_cb), gcal); - g_signal_handlers_disconnect_by_func (cal_model, - G_CALLBACK (view_done_cb), gcal); + g_mutex_free (priv->todo_update_lock); g_mutex_free (priv->todo_update_lock); @@ -2498,272 +2103,55 @@ display_view_cb (GalViewInstance *view_instance, GalView *view, gpointer data) } -/** - * gnome_calendar_setup_view_menus: - * @gcal: A calendar. - * @uic: UI controller to use for the menus. - * - * Sets up the #GalView menus for a calendar. This function should be called - * from the Bonobo control activation callback for this calendar. Also, the - * menus should be discarded using gnome_calendar_discard_view_menus(). - **/ -void -gnome_calendar_setup_view_menus (GnomeCalendar *gcal, BonoboUIComponent *uic) +static void +gnome_calendar_set_pane_positions (GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - gchar *path0, *path1, *etspecfile; - CalendarViewFactory *factory; - GalViewFactory *gal_factory; - static GalViewCollection *collection = NULL; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (uic != NULL); - g_return_if_fail (BONOBO_IS_UI_COMPONENT (uic)); priv = gcal->priv; - g_return_if_fail (priv->view_instance == NULL); - g_return_if_fail (priv->view_menus == NULL); - - /* Create the view instance */ - if (collection == NULL) { - ETableSpecification *spec; - - collection = gal_view_collection_new (); - - gal_view_collection_set_title (collection, _("Calendar")); - - path0 = g_build_filename (EVOLUTION_GALVIEWSDIR, - "calendar", - NULL); - path1 = g_build_filename (calendar_component_peek_base_directory (calendar_component_peek ()), - "views", NULL); - gal_view_collection_set_storage_directories (collection, - path0, - path1); - g_free (path1); - g_free (path0); - - /* Create the views */ - - factory = calendar_view_factory_new (GNOME_CAL_DAY_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_WORK_WEEK_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_WEEK_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - factory = calendar_view_factory_new (GNOME_CAL_MONTH_VIEW); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (factory)); - g_object_unref (factory); - - spec = e_table_specification_new (); - etspecfile = g_build_filename (EVOLUTION_ETSPECDIR, - "e-cal-list-view.etspec", - NULL); - if (!e_table_specification_load_from_file (spec, etspecfile)) - g_error ("Unable to load ETable specification file " - "for calendar"); - g_free (etspecfile); - gal_factory = gal_view_factory_etable_new (spec); - g_object_unref (spec); - gal_view_collection_add_factory (collection, GAL_VIEW_FACTORY (gal_factory)); - g_object_unref (gal_factory); - - /* Load the collection and create the menus */ - - gal_view_collection_load (collection); - + if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { + gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos_month_view); + gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos_month_view); + } else { + gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos); + gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos); } - - priv->view_instance = gal_view_instance_new (collection, NULL); - priv->view_menus = gal_view_menus_new (priv->view_instance); - gal_view_menus_apply (priv->view_menus, uic, NULL); - - g_signal_connect (priv->view_instance, "display_view", G_CALLBACK (display_view_cb), gcal); - display_view_cb (priv->view_instance, gal_view_instance_get_current_view (priv->view_instance), gcal); } -/** - * gnome_calendar_discard_view_menus: - * @gcal: A calendar. - * - * Discards the #GalView menus used by a calendar. This function should be - * called from the Bonobo control deactivation callback for this calendar. The - * menus should have been set up with gnome_calendar_setup_view_menus(). - **/ -void -gnome_calendar_discard_view_menus (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - - g_return_if_fail (gcal != NULL); - - priv = gcal->priv; - - g_return_if_fail (priv->view_instance != NULL); - g_return_if_fail (priv->view_menus != NULL); - - g_object_unref (priv->view_instance); - priv->view_instance = NULL; - - g_object_unref (priv->view_menus); - priv->view_menus = NULL; -} - -/* This is copied/moved from gal-view-instance, only the calendar uses this for a popup menu */ -static void -gc_set_view(EPopup *ep, EPopupItem *pitem, gpointer data) -{ - GnomeCalendar *gcal = data; - - if (pitem->type & E_POPUP_ACTIVE) - gal_view_instance_set_current_view_id(gcal->priv->view_instance, (gchar *)pitem->user_data); -} - -static void -gc_save_custom_view(EPopup *ep, EPopupItem *pitem, gpointer data) -{ - GnomeCalendar *gcal = data; - - gal_view_instance_save_as(gcal->priv->view_instance); -} - -static void -gc_define_views_response(GtkWidget *d, gint id, GnomeCalendar *gcal) -{ - if (id == GTK_RESPONSE_OK) - gal_view_collection_save(gcal->priv->view_instance->collection); - - gtk_widget_destroy(d); -} - -static void -gc_define_views(EPopup *ep, EPopupItem *pitem, gpointer data) -{ - GnomeCalendar *gcal = data; - GtkWidget *dialog = gal_define_views_dialog_new(gcal->priv->view_instance->collection); - - g_signal_connect(dialog, "response", G_CALLBACK(gc_define_views_response), data); - gtk_widget_show(dialog); -} - -static EPopupItem gc_popups[] = { - /* Code generates the path to fit */ - { E_POPUP_BAR, NULL }, - { E_POPUP_RADIO|E_POPUP_ACTIVE, NULL, (gchar *) N_("_Custom View"), }, - { E_POPUP_ITEM, NULL, (gchar *) N_("_Save Custom View"), gc_save_custom_view }, - - /* index == 3, when we have non-custom view */ - - { E_POPUP_BAR, NULL }, - { E_POPUP_ITEM, NULL, (gchar *) N_("_Define Views..."), gc_define_views }, +struct _mclient_msg { + Message header; + ECalModel *model; + ECal *client; }; static void -gc_popup_free (EPopup *ep, GSList *list, gpointer data) +add_mclient_async (struct _mclient_msg *msg) { - while (list) { - GSList *n = list->next; - EPopupItem *pitem = list->data; - - g_free(pitem->path); - g_free(pitem->label); - g_free(pitem->user_data); - g_free(pitem); - g_slist_free_1(list); - list = n; - } -} + e_cal_model_add_client (msg->model, msg->client); -static void -gc_popup_free_static (EPopup *ep, GSList *list, gpointer data) -{ - while (list) { - GSList *n = list->next; - EPopupItem *pitem = list->data; - - g_free(pitem->path); - g_free(pitem); - g_slist_free_1(list); - list = n; - } + g_object_unref (msg->client); + g_object_unref (msg->model); + g_slice_free (struct _mclient_msg, msg); } -void -gnome_calendar_view_popup_factory (GnomeCalendar *gcal, EPopup *ep, const gchar *prefix) +static void +add_mclient (ECalModel *model, ECal *client) { - GnomeCalendarPrivate *priv; - gint length; - gint i; - gboolean found = FALSE; - gchar *id; - GSList *menus = NULL; - EPopupItem *pitem; - - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (prefix != NULL); - - priv = gcal->priv; - - g_return_if_fail (priv->view_instance != NULL); - - length = gal_view_collection_get_count(priv->view_instance->collection); - id = gal_view_instance_get_current_view_id (priv->view_instance); - - for (i = 0; i < length; i++) { - GalViewCollectionItem *item = gal_view_collection_get_view_item(priv->view_instance->collection, i); - - pitem = g_malloc0(sizeof(*pitem)); - pitem->type = E_POPUP_RADIO; - pitem->path = g_strdup_printf("%s/%02d.item", prefix, i); - pitem->label = g_strdup(item->title); - pitem->activate = gc_set_view; - pitem->user_data = g_strdup(item->id); - - if (!found && id && !strcmp (id, item->id)) { - found = TRUE; - pitem->type |= E_POPUP_ACTIVE; - } - - menus = g_slist_prepend(menus, pitem); - } - - if (menus) - e_popup_add_items(ep, menus, NULL, gc_popup_free, gcal); + struct _mclient_msg *msg; - menus = NULL; - for (i = found?3:0; i<sizeof(gc_popups)/sizeof(gc_popups[0]);i++) { - pitem = g_malloc0(sizeof(*pitem)); - memcpy(pitem, &gc_popups[i], sizeof(*pitem)); - pitem->path = g_strdup_printf("%s/%02d.item", prefix, i+length); - menus = g_slist_prepend(menus, pitem); - } + msg = g_slice_new0 (struct _mclient_msg); + msg->header.func = (MessageFunc) add_mclient_async; + msg->model = g_object_ref (model); + msg->client = g_object_ref (client); - e_popup_add_items(ep, menus, NULL, gc_popup_free_static, gcal); + message_push ((Message *) msg); } static void -gnome_calendar_set_pane_positions (GnomeCalendar *gcal) +non_intrusive_error_remove(GtkWidget *w, gpointer data) { - GnomeCalendarPrivate *priv; - - priv = gcal->priv; - - if (priv->current_view_type == GNOME_CAL_MONTH_VIEW && !priv->range_selected) { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos_month_view); - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos_month_view); - } else { - gtk_paned_set_position (GTK_PANED (priv->hpane), priv->hpane_pos); - gtk_paned_set_position (GTK_PANED (priv->vpane), priv->vpane_pos); - } + g_hash_table_remove(non_intrusive_error_table, data); } struct _mclient_msg { @@ -2805,7 +2193,6 @@ static void client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - ECalSourceType source_type; ESource *source; ECalModel *model; ECalLoadState state; @@ -2815,23 +2202,9 @@ client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar *gcal) priv = gcal->priv; - source_type = e_cal_get_source_type (ecal); source = e_cal_get_source (ecal); state = e_cal_get_load_state (ecal); - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); - break; - case E_CAL_SOURCE_TYPE_TODO: - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), NULL, -1); - break; - case E_CAL_SOURCE_TYPE_JOURNAL: - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), NULL); - default: - break; - } - if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) auth_cal_forget_password (ecal); @@ -2863,32 +2236,27 @@ client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar *gcal) e_cal_open_async (ecal, FALSE); return; case E_CALENDAR_STATUS_REPOSITORY_OFFLINE: - if (source_type == E_CAL_SOURCE_TYPE_EVENT) - { - /* check to see if we have dialog already running for this operation */ - id = g_strdup ("calendar:unable-to-load-the-calendar"); - - if (g_hash_table_lookup(non_intrusive_error_table, id)) { - /* We already have it */ - g_message("Error occurred while existing dialog active:\n"); - return; - } + /* check to see if we have dialog already running for this operation */ + id = g_strdup ("calendar:unable-to-load-the-calendar"); - w = e_error_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal))), "calendar:unable-to-load-the-calendar", e_cal_get_error_message (status), NULL); - e_calendar_utils_show_error_silent (w); - g_hash_table_insert (non_intrusive_error_table, id, g_object_ref(w)); - g_signal_connect(w, "destroy", G_CALLBACK(non_intrusive_error_remove), id); + if (g_hash_table_lookup(non_intrusive_error_table, id)) { + /* We already have it */ + g_message("Error occurred while existing dialog active:\n"); + return; } + + w = e_error_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal))), "calendar:unable-to-load-the-calendar", e_cal_get_error_message (status), NULL); + e_calendar_utils_show_error_silent (w); + g_hash_table_insert (non_intrusive_error_table, id, g_object_ref(w)); + g_signal_connect(w, "destroy", G_CALLBACK(non_intrusive_error_remove), id); default: /* Make sure the source doesn't disappear on us */ g_object_ref (source); - g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, gcal); - - priv->clients_list[source_type] = g_list_remove (priv->clients_list[source_type], ecal); - g_hash_table_remove (priv->clients[source_type], e_source_peek_uid (source)); + priv->clients_list = g_list_remove (priv->clients_list, ecal); + g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); + g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source); g_object_unref (source); g_warning ("Unable to load the calendar %s \n", e_cal_get_error_message (status)); @@ -2898,74 +2266,35 @@ client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar *gcal) g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, client_cal_opened_cb, NULL); - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT : - msg = g_strdup_printf (_("Loading appointments at %s"), e_cal_get_uri (ecal)); - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), msg, -1); - g_free (msg); - - /* add client to the views */ - model = e_calendar_view_get_model (priv->views[priv->current_view_type]); - add_mclient (model, ecal); - - /* update date navigator query */ - update_query (gcal); - - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); - break; + msg = g_strdup_printf (_("Loading appointments at %s"), e_cal_get_uri (ecal)); + e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), msg, -1); + g_free (msg); - case E_CAL_SOURCE_TYPE_TODO : - msg = g_strdup_printf (_("Loading tasks at %s"), e_cal_get_uri (ecal)); - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), msg, -1); - g_free (msg); + /* add client to the views */ + model = e_calendar_view_get_model (priv->views[priv->current_view_type]); + add_mclient (model, ecal); - e_cal_model_add_client (e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), ecal); + /* update date navigator query */ + update_query (gcal); - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), NULL, -1); - break; - case E_CAL_SOURCE_TYPE_JOURNAL: - msg = g_strdup_printf (_("Loading memos at %s"), e_cal_get_uri (ecal)); - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), msg); - g_free (msg); - e_cal_model_add_client (e_memo_table_get_model (E_MEMO_TABLE (priv->memo)), ecal); - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), NULL); - break; - default: - g_return_if_reached (); - } + e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); } static void default_client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar *gcal) { GnomeCalendarPrivate *priv; - ECalSourceType source_type; ESource *source; ECalLoadState state; priv = gcal->priv; - source_type = e_cal_get_source_type (ecal); source = e_cal_get_source (ecal); state = e_cal_get_load_state (ecal); if (status == E_CALENDAR_STATUS_AUTHENTICATION_FAILED || status == E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED) auth_cal_forget_password (ecal); - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); - break; - case E_CAL_SOURCE_TYPE_TODO: - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), NULL, -1); - break; - case E_CAL_SOURCE_TYPE_JOURNAL: - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), NULL); - break; - default: - break; - } - switch (status) { case E_CALENDAR_STATUS_OK: break; @@ -2986,15 +2315,15 @@ default_client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, gcal); /* FIXME should we do this to prevent multiple error dialogs? */ - priv->clients_list[source_type] = g_list_remove (priv->clients_list[source_type], ecal); - g_hash_table_remove (priv->clients[source_type], e_source_peek_uid (source)); + priv->clients_list = g_list_remove (priv->clients_list, ecal); + g_hash_table_remove (priv->clients, e_source_peek_uid (source)); /* FIXME Is there a better way to handle this? */ - if (priv->default_client[source_type]) - g_object_unref (priv->default_client[source_type]); - priv->default_client[source_type] = NULL; + if (priv->default_client) + g_object_unref (priv->default_client); + priv->default_client = NULL; - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); + g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source); g_object_unref (source); g_warning ("Unable to load the calendar %s \n", e_cal_get_error_message (status)); @@ -3004,22 +2333,10 @@ default_client_cal_opened_cb (ECal *ecal, ECalendarStatus status, GnomeCalendar g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, default_client_cal_opened_cb, NULL); - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - e_cal_model_set_default_client ( - e_calendar_view_get_model (E_CALENDAR_VIEW (priv->views[priv->current_view_type])), - ecal); - break; - - case E_CAL_SOURCE_TYPE_TODO: - e_cal_model_set_default_client (e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)), ecal); - break; - case E_CAL_SOURCE_TYPE_JOURNAL: - e_cal_model_set_default_client (e_memo_table_get_model (E_MEMO_TABLE (priv->memo)), ecal); - break; - default: - break; - } + e_cal_model_set_default_client ( + e_calendar_view_get_model ( + E_CALENDAR_VIEW (priv->views[priv->current_view_type])), + ecal); } typedef void (*open_func) (ECal *, ECalendarStatus, GnomeCalendar *); @@ -3037,20 +2354,7 @@ open_ecal (GnomeCalendar *gcal, ECal *cal, gboolean only_if_exists, open_func of e_cal_set_default_timezone (cal, zone, NULL); msg = g_strdup_printf (_("Opening %s"), e_cal_get_uri (cal)); - switch (e_cal_get_source_type (cal)) { - case E_CAL_SOURCE_TYPE_EVENT : - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), msg, -1); - break; - case E_CAL_SOURCE_TYPE_TODO : - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), msg, -1); - break; - case E_CAL_SOURCE_TYPE_JOURNAL: - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), msg); - break; - default: - g_free (msg); - g_return_val_if_reached (FALSE); - } + e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), msg, -1); g_free (msg); @@ -3095,7 +2399,6 @@ backend_died_cb (ECal *ecal, gpointer data) { GnomeCalendar *gcal; GnomeCalendarPrivate *priv; - ECalSourceType source_type; ESource *source; const gchar *id; GtkWidget *w = NULL; @@ -3106,39 +2409,16 @@ backend_died_cb (ECal *ecal, gpointer data) /* FIXME What about default sources? */ /* Make sure the source doesn't go away on us since we use it below */ - source_type = e_cal_get_source_type (ecal); source = g_object_ref (e_cal_get_source (ecal)); - priv->clients_list[source_type] = g_list_remove (priv->clients_list[source_type], ecal); - g_hash_table_remove (priv->clients[source_type], e_source_peek_uid (source)); - - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - id = g_strdup ("calendar:calendar-crashed"); - - e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); - - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); - break; - - case E_CAL_SOURCE_TYPE_TODO: - id = g_strdup ("calendar:calendar-crashed"); + priv->clients_list = g_list_remove (priv->clients_list, ecal); + g_hash_table_remove (priv->clients, e_source_peek_uid (source)); - e_calendar_table_set_status_message (E_CALENDAR_TABLE (priv->todo), NULL, -1); + id = g_strdup ("calendar:calendar-crashed"); - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); - break; - - case E_CAL_SOURCE_TYPE_JOURNAL: - id = g_strdup ("calendar:calendar-crashed"); - - e_memo_table_set_status_message (E_MEMO_TABLE (priv->memo), NULL); + e_calendar_view_set_status_message (E_CALENDAR_VIEW (priv->week_view), NULL, -1); - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); - break; - default: - g_return_if_reached (); - } + g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source); g_object_unref (source); @@ -3183,35 +2463,6 @@ gnome_calendar_new (void) return GTK_WIDGET (gcal); } -void -gnome_calendar_set_activity_handler (GnomeCalendar *cal, EActivityHandler *activity_handler) -{ - GnomeCalendarPrivate *priv; - gint i; - - g_return_if_fail (cal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (cal)); - - priv = cal->priv; - - priv->activity_handler = activity_handler; - - for (i = 0; i < GNOME_CAL_LAST_VIEW; i++) - e_calendar_view_set_activity_handler (priv->views[i], activity_handler); - - e_calendar_table_set_activity_handler (E_CALENDAR_TABLE (priv->todo), activity_handler); -} - -void -gnome_calendar_set_ui_component (GnomeCalendar *gcal, - BonoboUIComponent *ui_component) -{ - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (ui_component == NULL || BONOBO_IS_UI_COMPONENT (ui_component)); - - e_search_bar_set_ui_component (E_SEARCH_BAR (gcal->priv->search_bar), ui_component); -} - /** * gnome_calendar_get_calendar_model: * @gcal: A calendar view. @@ -3259,7 +2510,7 @@ gnome_calendar_get_default_client (GnomeCalendar *gcal) * Returns: TRUE if successful, FALSE if error. */ gboolean -gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source) +gnome_calendar_add_source (GnomeCalendar *gcal, ESource *source) { GnomeCalendarPrivate *priv; ECal *client; @@ -3270,7 +2521,7 @@ gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESou priv = gcal->priv; - client = g_hash_table_lookup (priv->clients[source_type], e_source_peek_uid (source)); + client = g_hash_table_lookup (priv->clients, e_source_peek_uid (source)); if (client) { /* We already have it */ @@ -3278,18 +2529,18 @@ gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESou } else { ESource *default_source; - if (priv->default_client[source_type]) { - default_source = e_cal_get_source (priv->default_client[source_type]); + if (priv->default_client) { + default_source = e_cal_get_source (priv->default_client); g_message ("Check if default client matches (%s %s)", e_source_peek_uid (default_source), e_source_peek_uid (source)); /* We don't have it but the default client is it */ if (!strcmp (e_source_peek_uid (default_source), e_source_peek_uid (source))) - client = g_object_ref (priv->default_client[source_type]); + client = g_object_ref (priv->default_client); } /* Create a new one */ if (!client) { - client = auth_new_cal_from_source (source, source_type); + client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_EVENT); if (!client) return FALSE; } @@ -3299,10 +2550,10 @@ gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESou g_signal_connect (G_OBJECT (client), "backend_died", G_CALLBACK (backend_died_cb), gcal); /* add the client to internal structure */ - g_hash_table_insert (priv->clients[source_type], g_strdup (e_source_peek_uid (source)), client); - priv->clients_list[source_type] = g_list_prepend (priv->clients_list[source_type], client); + g_hash_table_insert (priv->clients, g_strdup (e_source_peek_uid (source)), client); + priv->clients_list = g_list_prepend (priv->clients_list, client); - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_ADDED], 0, source_type, source); + g_signal_emit (gcal, gnome_calendar_signals[SOURCE_ADDED], 0, source); open_ecal (gcal, client, FALSE, client_cal_opened_cb); @@ -3320,7 +2571,7 @@ gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESou * Returns: TRUE if successful, FALSE otherwise. */ gboolean -gnome_calendar_remove_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source) +gnome_calendar_remove_source (GnomeCalendar *gcal, ESource *source) { gboolean result; @@ -3328,15 +2579,15 @@ gnome_calendar_remove_source (GnomeCalendar *gcal, ECalSourceType source_type, E g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), FALSE); g_return_val_if_fail (E_IS_SOURCE (source), FALSE); - result = gnome_calendar_remove_source_by_uid (gcal, source_type, e_source_peek_uid (source)); + result = gnome_calendar_remove_source_by_uid (gcal, e_source_peek_uid (source)); if (result) - g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source_type, source); + g_signal_emit (gcal, gnome_calendar_signals[SOURCE_REMOVED], 0, source); return result; } gboolean -gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, ECalSourceType source_type, const gchar *uid) +gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, const gchar *uid) { GnomeCalendarPrivate *priv; ECal *client; @@ -3349,51 +2600,34 @@ gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, ECalSourceType source_ priv = gcal->priv; - client = g_hash_table_lookup (priv->clients[source_type], uid); + client = g_hash_table_lookup (priv->clients, uid); if (!client) return TRUE; - priv->clients_list[source_type] = g_list_remove (priv->clients_list[source_type], client); + priv->clients_list = g_list_remove (priv->clients_list, client); g_signal_handlers_disconnect_matched (client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, gcal); - switch (source_type) { - case E_CAL_SOURCE_TYPE_EVENT: - /* remove the query for this client */ - for (l = priv->dn_queries; l != NULL; l = l->next) { - ECalView *query = l->data; + /* remove the query for this client */ + for (l = priv->dn_queries; l != NULL; l = l->next) { + ECalView *query = l->data; - if (query && (client == e_cal_view_get_client (query))) { - g_signal_handlers_disconnect_matched (query, G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, gcal); - priv->dn_queries = g_list_remove (priv->dn_queries, query); - g_object_unref (query); - break; - } + if (query && (client == e_cal_view_get_client (query))) { + g_signal_handlers_disconnect_matched (query, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, gcal); + priv->dn_queries = g_list_remove (priv->dn_queries, query); + g_object_unref (query); + break; } + } - model = e_calendar_view_get_model (priv->views[priv->current_view_type]); - e_cal_model_remove_client (model, client); - - /* update date navigator query */ - update_query (gcal); - break; - - case E_CAL_SOURCE_TYPE_TODO: - model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo)); - e_cal_model_remove_client (model, client); - break; - - case E_CAL_SOURCE_TYPE_JOURNAL: - model = e_memo_table_get_model (E_MEMO_TABLE (priv->memo)); - e_cal_model_remove_client (model, client); - break; + model = e_calendar_view_get_model (priv->views[priv->current_view_type]); + e_cal_model_remove_client (model, client); - default: - g_return_val_if_reached (TRUE); - } + /* update date navigator query */ + update_query (gcal); - g_hash_table_remove (priv->clients[source_type], uid); + g_hash_table_remove (priv->clients, uid); return TRUE; } @@ -3411,7 +2645,7 @@ gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, ECalSourceType source_ * otherwise **/ gboolean -gnome_calendar_set_default_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source) +gnome_calendar_set_default_source (GnomeCalendar *gcal, ESource *source) { GnomeCalendarPrivate *priv; ECal *client; @@ -3422,21 +2656,21 @@ gnome_calendar_set_default_source (GnomeCalendar *gcal, ECalSourceType source_ty priv = gcal->priv; - client = g_hash_table_lookup (priv->clients[source_type], e_source_peek_uid (source)); + client = g_hash_table_lookup (priv->clients, e_source_peek_uid (source)); - if (priv->default_client[source_type]) - g_object_unref (priv->default_client[source_type]); + if (priv->default_client) + g_object_unref (priv->default_client); if (client) { - priv->default_client[source_type] = g_object_ref (client); + priv->default_client = g_object_ref (client); } else { - priv->default_client[source_type] = auth_new_cal_from_source (source, source_type); - if (!priv->default_client[source_type]) + priv->default_client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_EVENT); + if (!priv->default_client) return FALSE; } - open_ecal (gcal, priv->default_client[source_type], FALSE, default_client_cal_opened_cb); + open_ecal (gcal, priv->default_client, FALSE, default_client_cal_opened_cb); return TRUE; } @@ -3799,55 +3033,34 @@ gnome_calendar_vpane_resized (GtkWidget *w, GdkEventButton *e, GnomeCalendar *gc void gnome_calendar_cut_clipboard (GnomeCalendar *gcal) { - GnomeCalendarPrivate *priv; - FocusLocation location; - - priv = gcal->priv; + GtkWidget *widget; - location = get_focus_location (gcal); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - if (location == FOCUS_CALENDAR) { - e_calendar_view_cut_clipboard (E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (gcal))); - } else if (location == FOCUS_TASKPAD) - e_calendar_table_cut_clipboard (E_CALENDAR_TABLE (priv->todo)); - else if (location == FOCUS_MEMOPAD) - e_memo_table_cut_clipboard (E_MEMO_TABLE (priv->memo)); + widget = gnome_calendar_get_current_view_widget (gcal); + e_calendar_view_cut_clipboard (E_CALENDAR_VIEW (widget)); } void gnome_calendar_copy_clipboard (GnomeCalendar *gcal) { - GnomeCalendarPrivate *priv; - FocusLocation location; - - priv = gcal->priv; + GtkWidget *widget; - location = get_focus_location (gcal); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - if (location == FOCUS_CALENDAR) { - e_calendar_view_copy_clipboard (E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (gcal))); - } else if (location == FOCUS_TASKPAD) - e_calendar_table_copy_clipboard (E_CALENDAR_TABLE (priv->todo)); - else if (location == FOCUS_MEMOPAD) - e_memo_table_copy_clipboard (E_MEMO_TABLE (priv->memo)); + widget = gnome_calendar_get_current_view_widget (gcal); + e_calendar_view_copy_clipboard (E_CALENDAR_VIEW (widget)); } void gnome_calendar_paste_clipboard (GnomeCalendar *gcal) { - GnomeCalendarPrivate *priv; - FocusLocation location; + GtkWidget *widget; - priv = gcal->priv; - - location = get_focus_location (gcal); + g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - if (location == FOCUS_CALENDAR) { - e_calendar_view_paste_clipboard (E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (gcal))); - } else if (location == FOCUS_TASKPAD) - e_calendar_table_paste_clipboard (E_CALENDAR_TABLE (priv->todo)); - else if (location == FOCUS_MEMOPAD) - e_memo_table_paste_clipboard (E_MEMO_TABLE (priv->memo)); + widget = gnome_calendar_get_current_view_widget (gcal); + e_calendar_view_paste_clipboard (E_CALENDAR_VIEW (widget)); } @@ -3909,69 +3122,26 @@ gnome_calendar_get_num_events_selected (GnomeCalendar *gcal) return retval; } -/** - * gnome_calendar_get_num_tasks_selected: - * @gcal: A calendar view. - * - * Queries the number of tasks that are currently selected in the task pad of a - * calendar view. - * - * Return value: Number of selected tasks. - **/ -gint -gnome_calendar_get_num_tasks_selected (GnomeCalendar *gcal) -{ - GnomeCalendarPrivate *priv; - ETable *etable; - - g_return_val_if_fail (gcal != NULL, -1); - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), -1); - - priv = gcal->priv; - - etable = e_calendar_table_get_table (E_CALENDAR_TABLE (priv->todo)); - return e_table_selected_count (etable); -} - - void -gnome_calendar_delete_selection (GnomeCalendar *gcal) +gnome_calendar_delete_selection (GnomeCalendar *gcal) { - GnomeCalendarPrivate *priv; - FocusLocation location; - GtkWidget *view; + GtkWidget *widget; g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - priv = gcal->priv; - - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - view = gnome_calendar_get_current_view_widget (gcal); - - e_calendar_view_delete_selected_events (E_CALENDAR_VIEW (view)); - } else if (location == FOCUS_TASKPAD) - e_calendar_table_delete_selected (E_CALENDAR_TABLE (priv->todo)); - else if (location == FOCUS_MEMOPAD) - e_memo_table_delete_selected (E_MEMO_TABLE (priv->memo)); + widget = gnome_calendar_get_current_view_widget (gcal); + e_calendar_view_delete_selected_events (E_CALENDAR_VIEW (widget)); } void gnome_calendar_delete_selected_occurrence (GnomeCalendar *gcal) { - FocusLocation location; - GtkWidget *view; + GtkWidget *widget; g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - location = get_focus_location (gcal); - - if (location == FOCUS_CALENDAR) { - - view = gnome_calendar_get_current_view_widget (gcal); - e_calendar_view_delete_selected_occurrence (E_CALENDAR_VIEW (view)); - } + widget = gnome_calendar_get_current_view_widget (gcal); + e_calendar_view_delete_selected_occurrence (E_CALENDAR_VIEW (widget)); } static gboolean @@ -4070,14 +3240,6 @@ gnome_calendar_purge (GnomeCalendar *gcal, time_t older_than) } -ECalendarTable* -gnome_calendar_get_task_pad (GnomeCalendar *gcal) -{ - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - return E_CALENDAR_TABLE (gcal->priv->todo); -} - GtkWidget * gnome_calendar_get_e_calendar_widget (GnomeCalendar *gcal) { @@ -4102,13 +3264,6 @@ gnome_calendar_get_view_notebook_widget (GnomeCalendar *gcal) return GTK_WIDGET(gcal->priv->notebook); } -ECalMenu *gnome_calendar_get_taskpad_menu (GnomeCalendar *gcal) -{ - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - return gcal->priv->taskpad_menu; -} - ECalMenu *gnome_calendar_get_calendar_menu (GnomeCalendar *gcal) { g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); @@ -4116,14 +3271,6 @@ ECalMenu *gnome_calendar_get_calendar_menu (GnomeCalendar *gcal) return gcal->priv->calendar_menu; } -ECalMenu *gnome_calendar_get_memopad_menu (GnomeCalendar *gcal) -{ - g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL); - - return gcal->priv->memopad_menu; -} - - void gnome_calendar_edit_appointment (GnomeCalendar *gcal, const gchar * src_uid, diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h index 978bad4c0b..0803a4fb63 100644 --- a/calendar/gui/gnome-cal.h +++ b/calendar/gui/gnome-cal.h @@ -87,17 +87,13 @@ struct _GnomeCalendarClass { void (* dates_shown_changed) (GnomeCalendar *gcal); void (* calendar_selection_changed) (GnomeCalendar *gcal); - void (* taskpad_selection_changed) (GnomeCalendar *gcal); - void (* memopad_selection_changed) (GnomeCalendar *gcal); void (* calendar_focus_change) (GnomeCalendar *gcal, gboolean in); - void (* taskpad_focus_change) (GnomeCalendar *gcal, gboolean in); - void (* memopad_focus_change) (GnomeCalendar *gcal, gboolean in); void (* change_view) (GnomeCalendar *gcal, GnomeCalendarViewType view_type); - void (* source_added) (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source); - void (* source_removed) (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source); + void (* source_added) (GnomeCalendar *gcal, ESource *source); + void (* source_removed) (GnomeCalendar *gcal, ESource *source); /* Action signals */ void (* goto_date) (GnomeCalendar *gcal, GnomeCalendarGotoDateType date); @@ -109,16 +105,15 @@ GtkWidget *gnome_calendar_construct (GnomeCalendar *gcal); GtkWidget *gnome_calendar_new (void); -void gnome_calendar_set_activity_handler (GnomeCalendar *cal, EActivityHandler *activity_handler); -void gnome_calendar_set_ui_component (GnomeCalendar *cal, BonoboUIComponent *ui_component); +ECalendarTable *gnome_calendar_get_task_pad (GnomeCalendar *gcal); ECalModel *gnome_calendar_get_calendar_model (GnomeCalendar *gcal); ECal *gnome_calendar_get_default_client (GnomeCalendar *gcal); -gboolean gnome_calendar_add_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source); -gboolean gnome_calendar_remove_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source); -gboolean gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, ECalSourceType source_type, const gchar *uid); -gboolean gnome_calendar_set_default_source (GnomeCalendar *gcal, ECalSourceType source_type, ESource *source); +gboolean gnome_calendar_add_source (GnomeCalendar *gcal, ESource *source); +gboolean gnome_calendar_remove_source (GnomeCalendar *gcal, ESource *source); +gboolean gnome_calendar_remove_source_by_uid (GnomeCalendar *gcal, const gchar *uid); +gboolean gnome_calendar_set_default_source (GnomeCalendar *gcal, ESource *source); void gnome_calendar_next (GnomeCalendar *gcal); void gnome_calendar_previous (GnomeCalendar *gcal); @@ -134,20 +129,12 @@ void gnome_calendar_set_view (GnomeCalendar *gcal, GnomeCalendarViewType view_ty GtkWidget *gnome_calendar_get_current_view_widget (GnomeCalendar *gcal); -ECalendarTable *gnome_calendar_get_task_pad (GnomeCalendar *gcal); GtkWidget *gnome_calendar_get_e_calendar_widget (GnomeCalendar *gcal); GtkWidget *gnome_calendar_get_search_bar_widget (GnomeCalendar *gcal); GtkWidget *gnome_calendar_get_view_notebook_widget (GnomeCalendar *gcal); GtkWidget *gnome_calendar_get_tag (GnomeCalendar *gcal); -ECalMenu *gnome_calendar_get_taskpad_menu (GnomeCalendar *gcal); ECalMenu *gnome_calendar_get_calendar_menu (GnomeCalendar *gcal); -ECalMenu *gnome_calendar_get_memopad_menu (GnomeCalendar *gcal); - -void gnome_calendar_setup_view_menus (GnomeCalendar *gcal, BonoboUIComponent *uic); -void gnome_calendar_discard_view_menus (GnomeCalendar *gcal); - -void gnome_calendar_view_popup_factory (GnomeCalendar *gcal, EPopup *ep, const gchar *prefix); void gnome_calendar_set_selected_time_range (GnomeCalendar *gcal, time_t start_time, @@ -174,9 +161,6 @@ gboolean gnome_calendar_get_visible_time_range (GnomeCalendar *gcal, /* Returns the number of selected events (0 or 1 at present). */ gint gnome_calendar_get_num_events_selected (GnomeCalendar *gcal); -/* Returns the number of selected tasks */ -gint gnome_calendar_get_num_tasks_selected (GnomeCalendar *gcal); - /* Get the current timezone. */ icaltimezone *gnome_calendar_get_timezone (GnomeCalendar *gcal); diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c index 06986efdd6..dcbe643901 100644 --- a/calendar/gui/goto.c +++ b/calendar/gui/goto.c @@ -28,7 +28,6 @@ #include <gtk/gtk.h> #include <glade/glade.h> #include "e-util/e-util-private.h" -#include "calendar-commands.h" #include "calendar-config.h" #include "tag-calendar.h" #include "goto.h" @@ -76,12 +75,14 @@ month_changed (GtkToggleButton *toggle, gpointer data) static void ecal_date_range_changed (ECalendarItem *calitem, gpointer user_data) { +#if 0 /* KILL-BONOBO */ GoToDialog *dlg = user_data; ECal *client; client = gnome_calendar_get_default_client (dlg->gcal); if (client) tag_calendar_by_client (dlg->ecal, client); +#endif } /* Event handler for day groups in the month item. A button press makes the calendar jump to the @@ -90,6 +91,7 @@ ecal_date_range_changed (ECalendarItem *calitem, gpointer user_data) static void ecal_event (ECalendarItem *calitem, gpointer user_data) { +#if 0 /* KILL-BONOBO */ GoToDialog *dlg = user_data; GDate start_date, end_date; struct icaltimetype tt = icaltime_null_time (); @@ -106,6 +108,7 @@ ecal_event (ECalendarItem *calitem, gpointer user_data) gnome_calendar_goto (dlg->gcal, et); gtk_dialog_response (GTK_DIALOG (dlg->dialog), GTK_RESPONSE_NONE); +#endif } /* Returns the current time, for the ECalendarItem. */ @@ -160,7 +163,9 @@ create_ecal (GoToDialog *dlg) static void goto_today (GoToDialog *dlg) { +#if 0 /* KILL-BONOBO */ gnome_calendar_goto_today (dlg->gcal); +#endif } /* Gets the widgets from the XML file and returns if they are all available. */ @@ -201,6 +206,7 @@ goto_dialog_init_widgets (GoToDialog *dlg) void goto_dialog (GnomeCalendar *gcal) { +#if 0 /* KILL-BONOBO */ time_t start_time; struct icaltimetype tt; gint b; @@ -269,4 +275,5 @@ goto_dialog (GnomeCalendar *gcal) g_object_unref (dlg->xml); g_free (dlg); dlg = NULL; +#endif } diff --git a/calendar/gui/itip-bonobo-control.c b/calendar/gui/itip-bonobo-control.c deleted file mode 100644 index ab107ad29c..0000000000 --- a/calendar/gui/itip-bonobo-control.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Evolution calendar - Control for displaying iTIP mail messages - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Jesse Pavel <jpavel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include <config.h> -#include <string.h> -#include <gtk/gtk.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> -#include <bonobo/bonobo-persist-stream.h> -#include <bonobo/bonobo-stream-client.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-exception.h> -#include <libical/ical.h> - -#include "e-itip-control.h" -#include "itip-bonobo-control.h" - -extern gchar *evolution_dir; - -enum E_ITIP_BONOBO_ARGS { - FROM_ADDRESS_ARG_ID, - VIEW_ONLY_ARG_ID -}; - -/* - * Bonobo::PersistStream - * - * These two functions implement the Bonobo::PersistStream load and - * save methods which allow data to be loaded into and out of the - * BonoboObject. - */ - -static gchar * -stream_read (Bonobo_Stream stream) -{ - Bonobo_Stream_iobuf *buffer; - CORBA_Environment ev; - gchar *data = NULL; - gint length = 0; - - CORBA_exception_init (&ev); - do { -#define READ_CHUNK_SIZE 65536 - Bonobo_Stream_read (stream, READ_CHUNK_SIZE, - &buffer, &ev); - - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return NULL; - } - - if (buffer->_length <= 0) - break; - - data = g_realloc (data, length + buffer->_length + 1); - memcpy (data + length, buffer->_buffer, buffer->_length); - length += buffer->_length; - data[length] = '\0'; - - CORBA_free (buffer); -#undef READ_CHUNK_SIZE - } while (1); - - CORBA_free (buffer); - CORBA_exception_free (&ev); - - if (data == NULL) - data = g_strdup(""); - - return data; -} /* stream_read */ - -/* - * This function implements the Bonobo::PersistStream:load method. - */ -typedef struct { - EItipControl *itip; - gchar *text; -} idle_data; - -static gboolean -set_data_idle_cb (gpointer data) -{ - idle_data *id = data; - - e_itip_control_set_data (id->itip, id->text); - g_object_unref (id->itip); - g_free (id->text); - g_free (id); - - return FALSE; -} - -static void -pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream, - Bonobo_Persist_ContentType type, gpointer data, - CORBA_Environment *ev) -{ - EItipControl *itip = data; - idle_data *id; - - if (type && g_ascii_strcasecmp (type, "text/calendar") != 0 && - g_ascii_strcasecmp (type, "text/x-calendar") != 0) { - bonobo_exception_set (ev, ex_Bonobo_Persist_WrongDataType); - return; - } - - id = g_new0 (idle_data, 1); - if ((id->text = stream_read (stream)) == NULL) { - bonobo_exception_set (ev, ex_Bonobo_Persist_FileNotFound); - g_free (id); - return; - } - g_object_ref (itip); - id->itip = itip; - - g_idle_add (set_data_idle_cb, id); -} -/* - * This function implements the Bonobo::PersistStream:save method. - */ -static void -pstream_save (BonoboPersistStream *ps, const Bonobo_Stream stream, - Bonobo_Persist_ContentType type, gpointer data, - CORBA_Environment *ev) -{ - EItipControl *itip = data; - gchar *text; - gint len; - - if (type && g_ascii_strcasecmp (type, "text/calendar") != 0 && - g_ascii_strcasecmp (type, "text/x-calendar") != 0) { - bonobo_exception_set (ev, ex_Bonobo_Persist_WrongDataType); - return; - } - - text = e_itip_control_get_data (itip); - len = e_itip_control_get_data_size (itip); - - bonobo_stream_client_write (stream, text, len, ev); - g_free (text); -} /* pstream_save */ - -/* static CORBA_long */ -/* pstream_get_max_size (BonoboPersistStream *ps, gpointer data, */ -/* CORBA_Environment *ev) */ -/* { */ -/* EItipControl *itip = data; */ -/* gint len; */ - -/* len = e_itip_control_get_data_size (itip); */ - -/* if (len > 0) */ -/* return len; */ - -/* return 0L; */ -/* } */ - -static Bonobo_Persist_ContentTypeList * -pstream_get_content_types (BonoboPersistStream *ps, gpointer closure, - CORBA_Environment *ev) -{ - return bonobo_persist_generate_content_types (2, "text/calendar", "text/x-calendar"); -} - -static void -get_prop (BonoboPropertyBag *bag, - BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - EItipControl *itip = user_data; - - switch (arg_id) { - case FROM_ADDRESS_ARG_ID: - BONOBO_ARG_SET_STRING (arg, e_itip_control_get_from_address (itip)); - break; - case VIEW_ONLY_ARG_ID: - BONOBO_ARG_SET_INT (arg, e_itip_control_get_view_only (itip)); - break; - } -} - -static void -set_prop ( BonoboPropertyBag *bag, - const BonoboArg *arg, - guint arg_id, - CORBA_Environment *ev, - gpointer user_data) -{ - EItipControl *itip = user_data; - - switch (arg_id) { - case FROM_ADDRESS_ARG_ID: - e_itip_control_set_from_address (itip, BONOBO_ARG_GET_STRING (arg)); - break; - case VIEW_ONLY_ARG_ID: - e_itip_control_set_view_only (itip, BONOBO_ARG_GET_INT (arg)); - break; - } -} - - -BonoboControl * -itip_bonobo_control_new (void) -{ - BonoboControl *control; - BonoboPropertyBag *prop_bag; - BonoboPersistStream *stream; - GtkWidget *itip; - - itip = e_itip_control_new (); - gtk_widget_show (itip); - control = bonobo_control_new (itip); - - /* create a property bag */ - prop_bag = bonobo_property_bag_new (get_prop, set_prop, itip); - bonobo_property_bag_add (prop_bag, "from_address", FROM_ADDRESS_ARG_ID, BONOBO_ARG_STRING, NULL, - "from_address", 0 ); - bonobo_property_bag_add (prop_bag, "view_only", VIEW_ONLY_ARG_ID, BONOBO_ARG_INT, NULL, - "view_only", 0 ); - - bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (prop_bag)), NULL); - bonobo_object_unref (BONOBO_OBJECT (prop_bag)); - - bonobo_control_set_automerge (control, TRUE); - - stream = bonobo_persist_stream_new (pstream_load, pstream_save, - pstream_get_content_types, - "OAFIID:GNOME_Evolution_Calendar_iTip_Control:" BASE_VERSION, - itip); - - if (stream == NULL) { - bonobo_object_unref (BONOBO_OBJECT (control)); - return NULL; - } - - bonobo_object_add_interface (BONOBO_OBJECT (control), - BONOBO_OBJECT (stream)); - - return control; -} diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c index cc290b2c3d..2287f59248 100644 --- a/calendar/gui/itip-utils.c +++ b/calendar/gui/itip-utils.c @@ -37,7 +37,6 @@ #include <time.h> #include <composer/e-msg-composer.h> -#include <mail/em-composer-utils.h> #include <camel/camel-mime-filter-tohtml.h> static const gchar *itip_methods[] = { @@ -1250,7 +1249,6 @@ itip_send_comp (ECalComponentItipMethod method, ECalComponent *send_comp, composer = e_msg_composer_new (); table = e_msg_composer_get_header_table (composer); - em_composer_utils_setup_default_callbacks (composer); e_composer_header_table_set_subject (table, subject); e_composer_header_table_set_account_name (table, from); @@ -1358,7 +1356,6 @@ reply_to_calendar_comp (ECalComponentItipMethod method, composer = e_msg_composer_new (); table = e_msg_composer_get_header_table (composer); - em_composer_utils_setup_default_callbacks (composer); e_composer_header_table_set_subject (table, subject); e_composer_header_table_set_account_name (table, from); diff --git a/calendar/gui/main.c b/calendar/gui/main.c deleted file mode 100644 index a3a3a3339e..0000000000 --- a/calendar/gui/main.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Ettore Perazzoli <ettore@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <glib/gi18n.h> -#include <libgnome/gnome-init.h> -#include <glade/glade.h> - -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-shlib-factory.h> -#include <bonobo/bonobo-exception.h> - -#include "dialogs/cal-prefs-dialog.h" -#include "calendar-commands.h" -#include "calendar-config.h" -#include "calendar-component.h" -#include "e-comp-editor-registry.h" -#include "comp-editor-factory.h" -#include "control-factory.h" -#include "itip-bonobo-control.h" -#include "tasks-control.h" -#include "tasks-component.h" -#include "memos-component.h" - -#include <e-util/e-plugin.h> -#include <e-util/e-import.h> -#include "e-cal-config.h" -#include "e-cal-popup.h" -#include "e-cal-menu.h" -#include "e-cal-event.h" -#include "calendar/importers/evolution-calendar-importer.h" - -#define FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_Factory:" BASE_VERSION - -#define CALENDAR_COMPONENT_ID "OAFIID:GNOME_Evolution_Calendar_Component:" BASE_VERSION -#define TASKS_COMPONENT_ID "OAFIID:GNOME_Evolution_Tasks_Component:" BASE_VERSION -#define MEMOS_COMPONENT_ID "OAFIID:GNOME_Evolution_Memos_Component:" BASE_VERSION -#define ITIP_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_iTip_Control:" BASE_VERSION -#define CONFIG_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_ConfigControl:" BASE_VERSION -#define COMP_EDITOR_FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_CompEditorFactory:" BASE_VERSION - -ECompEditorRegistry *comp_editor_registry = NULL; - -/* The component editor factory */ -static CompEditorFactory *comp_editor_factory = NULL; - - -/* Factory function for the calendar component factory; just creates and - * references a singleton service object. - */ -static BonoboObject * -comp_editor_factory_fn (void) -{ - if (!comp_editor_factory) { - comp_editor_factory = comp_editor_factory_new (); - if (!comp_editor_factory) - return NULL; - } - - bonobo_object_ref (BONOBO_OBJECT (comp_editor_factory)); - return BONOBO_OBJECT (comp_editor_factory); -} - - -/* Does a simple activation and unreffing of the alarm notification service so - * that the daemon will be launched if it is not running yet. - */ -static gboolean -launch_alarm_daemon_cb (gpointer data) -{ - CORBA_Environment ev; - CORBA_Object an; - - /* activate the alarm daemon */ - CORBA_exception_init (&ev); - an = bonobo_activation_activate_from_id ( - (Bonobo_ActivationID) "OAFIID:GNOME_Evolution_Calendar_AlarmNotify:" BASE_VERSION, 0, NULL, &ev); - - if (BONOBO_EX (&ev)) { - g_message ("launch_alarm_daemon_cb(): %s", bonobo_exception_get_text (&ev)); - CORBA_exception_free (&ev); - return FALSE; - } - CORBA_exception_free (&ev); - - /* Just get rid of it; what we are interested in is that it gets launched */ - - CORBA_exception_init (&ev); - bonobo_object_release_unref (an, &ev); - if (BONOBO_EX (&ev)) - g_message ("add_alarms(): Could not unref the alarm notification service"); - - CORBA_exception_free (&ev); - - return FALSE; -} - -static void -launch_alarm_daemon (void) -{ - g_idle_add ((GSourceFunc) launch_alarm_daemon_cb, NULL); -} - -static void -initialize (void) -{ - EImportClass *klass; - - comp_editor_registry = E_COMP_EDITOR_REGISTRY (e_comp_editor_registry_new ()); - -#if 0 - itip_control_factory_init (); - component_editor_factory_init (); -#endif - - launch_alarm_daemon (); - - - /* Initialize plugin system */ - e_plugin_hook_register_type (e_cal_popup_hook_get_type()); - e_plugin_hook_register_type (e_cal_menu_hook_get_type()); - e_plugin_hook_register_type (e_cal_config_hook_get_type ()); - e_plugin_hook_register_type (e_cal_event_hook_get_type ()); - - klass = g_type_class_ref(e_import_get_type()); - e_import_class_add_importer(klass, gnome_calendar_importer_peek(), NULL, NULL); - e_import_class_add_importer(klass, ical_importer_peek(), NULL, NULL); - e_import_class_add_importer(klass, vcal_importer_peek(), NULL, NULL); -} - -static BonoboObject * -factory (BonoboGenericFactory *factory, - const gchar *component_id, - gpointer closure) -{ - static gboolean initialized = FALSE; - - if (! initialized) { - initialize (); - initialized = TRUE; - } - - if (strcmp (component_id, CALENDAR_COMPONENT_ID) == 0) { - BonoboObject *object = BONOBO_OBJECT (calendar_component_peek ()); - bonobo_object_ref (object); - return object; - } else if (strcmp (component_id, TASKS_COMPONENT_ID) == 0) { - BonoboObject *object = BONOBO_OBJECT (tasks_component_peek ()); - bonobo_object_ref (object); - return object; - } else if (strcmp (component_id, MEMOS_COMPONENT_ID) == 0){ - BonoboObject *object = BONOBO_OBJECT (memos_component_peek ()); - bonobo_object_ref (object); - return object; - } else if (strcmp (component_id, ITIP_CONTROL_ID) == 0) - return BONOBO_OBJECT (itip_bonobo_control_new ()); - else if (strcmp (component_id, CONFIG_CONTROL_ID) == 0) { - GtkWidget *prefs; - EvolutionConfigControl *control; - - prefs = calendar_prefs_dialog_new (); - gtk_widget_show (prefs); - control = evolution_config_control_new (prefs); - - return BONOBO_OBJECT (control); - } else if (strcmp (component_id, COMP_EDITOR_FACTORY_ID) == 0) - return BONOBO_OBJECT (comp_editor_factory_fn ()); - - g_warning (FACTORY_ID ": Don't know what to do with %s", component_id); - return NULL; -} - -BONOBO_ACTIVATION_SHLIB_FACTORY (FACTORY_ID, "Evolution Calendar component factory", factory, NULL) diff --git a/calendar/gui/memos-component.c b/calendar/gui/memos-component.c index 1efc7e64ea..2e45ad4ec9 100644 --- a/calendar/gui/memos-component.c +++ b/calendar/gui/memos-component.c @@ -58,28 +58,13 @@ #define CREATE_SHARED_MEMO_ID "shared-memo" #define CREATE_MEMO_LIST_ID "memo-list" -enum DndTargetType { - DND_TARGET_TYPE_CALENDAR_LIST -}; -#define CALENDAR_TYPE "text/calendar" -#define XCALENDAR_TYPE "text/x-calendar" #define WEB_BASE_URI "webcal://" #define PERSONAL_RELATIVE_URI "system" -static GtkTargetEntry drag_types[] = { - { (gchar *) CALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST }, - { (gchar *) XCALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST } -}; -static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]); - #define PARENT_TYPE bonobo_object_get_type () static BonoboObjectClass *parent_class = NULL; -/* Memos should have their own registry */ -extern ECompEditorRegistry *comp_editor_registry; - - typedef struct _MemosComponentView { ESourceList *source_list; @@ -90,29 +75,17 @@ typedef struct _MemosComponentView ETable *table; ETableModel *model; - EInfoLabel *info_label; GtkWidget *source_selector; - BonoboControl *view_control; - BonoboControl *sidebar_control; - BonoboControl *statusbar_control; - GList *notifications; - EUserCreatableItemsHandler *creatable_items_handler; - - EActivityHandler *activity_handler; } MemosComponentView; struct _MemosComponentPrivate { - gchar *base_directory; - gchar *config_directory; ESourceList *source_list; GSList *source_selection; - GList *views; - ECal *create_ecal; GList *notifications; @@ -120,109 +93,6 @@ struct _MemosComponentPrivate { #define d(x) -static void -ensure_sources (MemosComponent *component) -{ - ESourceList *source_list; - ESourceGroup *on_this_computer; - ESource *personal_source; - gchar *base_uri, *base_uri_proto, base_uri_proto_seventh; - const gchar *base_dir; - - personal_source = NULL; - - if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_JOURNAL, NULL)) { - g_warning ("Could not get memo source list from GConf!"); - return; - } - - base_dir = memos_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - if (strlen (base_uri_proto) > 7) { - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ - base_uri_proto_seventh = base_uri_proto[7]; - base_uri_proto[7] = 0; - } else { - base_uri_proto_seventh = -1; - } - - on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); - e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); - - if (base_uri_proto_seventh != -1) { - base_uri_proto[7] = base_uri_proto_seventh; - } - - if (on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - personal_source = source; - break; - } - } - /* Make sure we have the correct base uri. This can change when user's - homedir name changes */ - if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) { - e_source_group_set_base_uri (on_this_computer, base_uri_proto); - - /* *sigh* . We shouldn't need this sync call here as set_base_uri - call results in synching to gconf, but that happens in idle loop - and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ - e_source_list_sync (source_list,NULL); - } - } - - if (personal_source) { - /* ensure the source name is in current locale, not read from configuration */ - e_source_set_name (personal_source, _("Personal")); - } else { - GSList *memos_selected; - /* Create the default Person addressbook */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (on_this_computer, source, -1); - g_object_unref (source); - - memos_selected = calendar_config_get_memos_selected (); - - if (!calendar_config_get_primary_memos () && !memos_selected) { - GSList selected; - - calendar_config_set_primary_memos (e_source_peek_uid (source)); - - selected.data = (gpointer)e_source_peek_uid (source); - selected.next = NULL; - calendar_config_set_memos_selected (&selected); - } - - if (memos_selected) { - g_slist_foreach (memos_selected, (GFunc) g_free, NULL); - g_slist_free (memos_selected); - } - - e_source_set_color_spec (source, "#BECEDD"); - personal_source = source; - } - - component->priv->source_list = source_list; - - g_object_unref (on_this_computer); - g_free (base_uri_proto); - g_free (base_uri); -} - /* Utility functions. */ /* FIXME Some of these are duplicated from calendar-component.c */ static gboolean @@ -256,7 +126,7 @@ is_in_uids (GSList *uids, ESource *source) } static void -update_uris_for_selection (MemosComponentView *component_view) +source_selection_changed_cb (ESourceSelector *selector, MemosComponentView *component_view) { GSList *selection, *l, *uids_selected = NULL; @@ -284,339 +154,8 @@ update_uris_for_selection (MemosComponentView *component_view) g_slist_free (uids_selected); } -static void -update_uri_for_primary_selection (MemosComponentView *component_view) -{ - ESource *source; - EMemoTable *cal_table; - ETable *etable; - - source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!source) - return; - - /* Set the default */ - e_memos_set_default_source (component_view->memos, source); - - cal_table = e_memos_get_calendar_table (component_view->memos); - etable = e_memo_table_get_table (cal_table); - - memos_control_sensitize_commands (component_view->view_control, component_view->memos, e_table_selected_count (etable)); - - /* Save the selection for next time we start up */ - calendar_config_set_primary_memos (e_source_peek_uid (source)); -} - -static void -update_selection (MemosComponentView *component_view) -{ - GSList *selection, *uids_selected, *l; - - d(g_message("memos-component.c: update_selection called");) - - /* Get the selection in gconf */ - uids_selected = calendar_config_get_memos_selected (); - - /* Remove any that aren't there any more */ - selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - - for (l = selection; l; l = l->next) { - ESource *source = l->data; - - if (!is_in_uids (uids_selected, source)) - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - } - - e_source_selector_free_selection (selection); - - /* Make sure the whole selection is there */ - for (l = uids_selected; l; l = l->next) { - gchar *uid = l->data; - ESource *source; - - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - if (source) - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - - g_free (uid); - } - g_slist_free (uids_selected); -} - -static void -update_primary_selection (MemosComponentView *component_view) -{ - ESource *source = NULL; - gchar *uid; - - uid = calendar_config_get_primary_memos (); - if (uid) { - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - g_free (uid); - } - - if (source) { - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } else { - /* Try to create a default if there isn't one */ - source = e_source_list_peek_source_any (component_view->source_list); - if (source) - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } - -} - - -/* Callbacks. */ -/* TODO: doesn't work! */ -static void -copy_memo_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - MemosComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - copy_source_dialog (GTK_WINDOW (gtk_widget_get_toplevel(ep->target->widget)), selected_source, E_CAL_SOURCE_TYPE_JOURNAL); -} - -static void -delete_memo_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - MemosComponentView *component_view = data; - ESource *selected_source; - ECal *cal; - gchar *uri; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - if (e_error_run((GtkWindow *)gtk_widget_get_toplevel(ep->target->widget), - "calendar:prompt-delete-memo-list", e_source_peek_name(selected_source), NULL) != GTK_RESPONSE_YES) - return; - - /* first, ask the backend to remove the memo list */ - uri = e_source_get_uri (selected_source); - cal = e_cal_model_get_client_for_uri ( - e_memo_table_get_model (E_MEMO_TABLE (e_memos_get_calendar_table (component_view->memos))), - uri); - if (!cal) - cal = e_cal_new_from_uri (uri, E_CAL_SOURCE_TYPE_JOURNAL); - g_free (uri); - if (cal) { - if (e_cal_remove (cal, NULL)) { - if (e_source_selector_source_is_selected (E_SOURCE_SELECTOR (component_view->source_selector), - selected_source)) { - e_memos_remove_memo_source (component_view->memos, selected_source); - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), - selected_source); - } - - e_source_group_remove_source (e_source_peek_group (selected_source), selected_source); - e_source_list_sync (component_view->source_list, NULL); - } - } -} - -static void -new_memo_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - calendar_setup_new_memo_list (GTK_WINDOW (gtk_widget_get_toplevel(ep->target->widget))); -} - -static void -rename_memo_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - MemosComponentView *component_view = data; - ESourceSelector *selector; - - selector = E_SOURCE_SELECTOR (component_view->source_selector); - e_source_selector_edit_primary_selection (selector); -} - -static void -edit_memo_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - MemosComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - calendar_setup_edit_memo_list (GTK_WINDOW (gtk_widget_get_toplevel(ep->target->widget)), selected_source); -} - -static void -set_offline_availability (EPopup *ep, EPopupItem *pitem, gpointer data, const gchar *value) -{ - MemosComponentView *component_view = data; - ESource *selected_source; - - selected_source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - if (!selected_source) - return; - - e_source_set_property (selected_source, "offline_sync", value); -} - -static void -mark_no_offline_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - set_offline_availability (ep, pitem, data, "0"); -} - -static void -mark_offline_cb (EPopup *ep, EPopupItem *pitem, gpointer data) -{ - set_offline_availability (ep, pitem, data, "1"); -} - -static EPopupItem emc_source_popups[] = { - { E_POPUP_ITEM, (gchar *) "10.new", (gchar *) N_("_New Memo List"), new_memo_list_cb, NULL, (gchar *) "stock_notes", 0, 0 }, - { E_POPUP_ITEM, (gchar *) "15.copy", (gchar *) N_("_Copy..."), copy_memo_list_cb, NULL, (gchar *) "edit-copy", 0, E_CAL_POPUP_SOURCE_PRIMARY }, - { E_POPUP_ITEM, (gchar *) "18.rename", (gchar *) N_("_Rename..."), rename_memo_list_cb, NULL, NULL, 0, E_CAL_POPUP_SOURCE_PRIMARY }, - - { E_POPUP_BAR, (gchar *) "20.bar" }, - { E_POPUP_ITEM, (gchar *) "20.delete", (gchar *) N_("_Delete"), delete_memo_list_cb, NULL, (gchar *) "edit-delete", 0, E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY }, - { E_POPUP_ITEM, (gchar *) "30.mark_memos_offline", (gchar *) N_("_Make available for offline use"), mark_offline_cb, NULL, (gchar *) "stock_disconnect", E_CAL_POPUP_SOURCE_OFFLINE, E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY|E_CAL_POPUP_SOURCE_OFFLINE }, - { E_POPUP_ITEM, (gchar *) "40.mark_memos_no_offline", (gchar *) N_("_Do not make available for offline use"), mark_no_offline_cb, NULL, (gchar *) "stock_connect", E_CAL_POPUP_SOURCE_NO_OFFLINE, E_CAL_POPUP_SOURCE_USER|E_CAL_POPUP_SOURCE_PRIMARY|E_CAL_POPUP_SOURCE_NO_OFFLINE }, - - { E_POPUP_BAR, (gchar *) "99.bar" }, - { E_POPUP_ITEM, (gchar *) "99.properties", (gchar *) N_("_Properties"), edit_memo_list_cb, NULL, (gchar *) "document-properties", 0, E_CAL_POPUP_SOURCE_PRIMARY }, -}; - -static void -emc_source_popup_free(EPopup *ep, GSList *list, gpointer data) -{ - g_slist_free(list); -} - -static gboolean -popup_event_cb(ESourceSelector *selector, ESource *insource, GdkEventButton *event, MemosComponentView *component_view) -{ - ECalPopup *ep; - ECalPopupTargetSource *t; - GSList *menus = NULL; - gint i; - GtkMenu *menu; - - /** @HookPoint-ECalPopup: Memos Source Selector Context Menu - * @Id: org.gnome.evolution.memos.source.popup - * @Class: org.gnome.evolution.calendar.popup:1.0 - * @Target: ECalPopupTargetSource - * - * The context menu on the source selector in the memos window. - */ - ep = e_cal_popup_new("org.gnome.evolution.memos.source.popup"); - t = e_cal_popup_target_new_source(ep, selector); - t->target.widget = (GtkWidget *)component_view->memos; - - for (i=0;i<sizeof(emc_source_popups)/sizeof(emc_source_popups[0]);i++) - menus = g_slist_prepend(menus, &emc_source_popups[i]); - - e_popup_add_items((EPopup *)ep, menus, NULL,emc_source_popup_free, component_view); - - menu = e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0); - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event?event->button:0, event?event->time:gtk_get_current_event_time()); - - return TRUE; -} - -static void -source_selection_changed_cb (ESourceSelector *selector, MemosComponentView *component_view) -{ - update_uris_for_selection (component_view); -} - -static void -primary_source_selection_changed_cb (ESourceSelector *selector, MemosComponentView *component_view) -{ - update_uri_for_primary_selection (component_view); -} - -static void -source_added_cb (EMemos *memos, ESource *source, MemosComponentView *component_view) -{ - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); -} - -static void -source_removed_cb (EMemos *memos, ESource *source, MemosComponentView *component_view) -{ - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); -} - -static void -set_info (MemosComponentView *component_view) -{ - GString *message = g_string_new (NULL); - gint rows, selected_rows; - - rows = e_table_model_row_count (component_view->model); - selected_rows = e_table_selected_count (component_view->table); - - g_string_append_printf(message, ngettext("%d memo", "%d memos", rows), rows); - if (selected_rows > 0) - g_string_append_printf(message, ngettext(", %d selected", ", %d selected", selected_rows), selected_rows); - - e_info_label_set_info (component_view->info_label, _("Memos"), message->str); - - g_string_free (message, TRUE); -} - -static void -table_selection_change_cb (ETableModel *etm, MemosComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_changed_cb (ETableModel *etm, MemosComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_rows_inserted_cb (ETableModel *etm, gint row, gint count, MemosComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_rows_deleted_cb (ETableModel *etm, gint row, gint count, MemosComponentView *component_view) -{ - set_info (component_view); -} - /* Evolution::Component CORBA methods */ -static void -impl_upgradeFromVersion (PortableServer_Servant servant, - CORBA_short major, - CORBA_short minor, - CORBA_short revision, - CORBA_Environment *ev) -{ - GError *err = NULL; - MemosComponent *component = MEMOS_COMPONENT (bonobo_object_from_servant (servant)); - - if (!migrate_memos(component, major, minor, revision, &err)) { - GNOME_Evolution_Component_UpgradeFailed *failedex; - - failedex = GNOME_Evolution_Component_UpgradeFailed__alloc(); - failedex->what = CORBA_string_dup(_("Failed upgrading memos.")); - failedex->why = CORBA_string_dup(err->message); - CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UpgradeFailed, failedex); - } - - if (err) - g_error_free(err); -} - static gboolean selector_tree_data_dropped (ESourceSelector *selector, GtkSelectionData *data, @@ -668,19 +207,6 @@ selector_tree_data_dropped (ESourceSelector *selector, } static void -control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) -{ - MemosComponentView *component_view = data; - - if (activate) { - BonoboUIComponent *uic; - uic = bonobo_control_get_ui_component (component_view->view_control); - - e_user_creatable_items_handler_activate (component_view->creatable_items_handler, uic); - } -} - -static void config_create_ecal_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) { MemosComponent *component = data; @@ -812,140 +338,32 @@ create_new_memo (MemosComponent *memo_component, gboolean is_assigned, MemosComp return TRUE; } -static void -create_local_item_cb (EUserCreatableItemsHandler *handler, const gchar *item_type_name, gpointer data) -{ - MemosComponent *memos_component = data; - MemosComponentPrivate *priv; - MemosComponentView *component_view = NULL; - GList *l; - - priv = memos_component->priv; - - for (l = priv->views; l; l = l->next) { - component_view = l->data; - - if (component_view->creatable_items_handler == handler) - break; - - component_view = NULL; - } - - if (strcmp (item_type_name, CREATE_MEMO_ID) == 0) { - create_new_memo (memos_component, FALSE, component_view); - } else if (strcmp (item_type_name, CREATE_SHARED_MEMO_ID) == 0) { - create_new_memo (memos_component, TRUE, component_view); - } else if (strcmp (item_type_name, CREATE_MEMO_LIST_ID) == 0) { - calendar_setup_new_memo_list (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (component_view->memos)))); - } -} - static MemosComponentView * create_component_view (MemosComponent *memos_component) { MemosComponentPrivate *priv; MemosComponentView *component_view; - GtkWidget *selector_scrolled_window, *vbox; GtkWidget *statusbar_widget; - AtkObject *a11y; priv = memos_component->priv; /* Create the calendar component view */ component_view = g_new0 (MemosComponentView, 1); - /* Add the source lists */ - component_view->source_list = g_object_ref (priv->source_list); - /* Create sidebar selector */ - component_view->source_selector = e_source_selector_new (memos_component->priv->source_list); - e_source_selector_set_select_new ((ESourceSelector *)component_view->source_selector, TRUE); - a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector)); - atk_object_set_name (a11y, _("Memo Source Selector")); - - g_signal_connect ( - component_view->source_selector, "data-dropped", - G_CALLBACK (selector_tree_data_dropped), memos_component); - - gtk_drag_dest_set(component_view->source_selector, GTK_DEST_DEFAULT_ALL, drag_types, - num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE); - - gtk_widget_show (component_view->source_selector); - - selector_scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (selector_scrolled_window), component_view->source_selector); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selector_scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (selector_scrolled_window), - GTK_SHADOW_IN); - gtk_widget_show (selector_scrolled_window); - - component_view->info_label = (EInfoLabel *)e_info_label_new("evolution-memos"); - e_info_label_set_info(component_view->info_label, _("Memos"), ""); - gtk_widget_show (GTK_WIDGET (component_view->info_label)); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (component_view->info_label), FALSE, TRUE, 0); - gtk_box_pack_start(GTK_BOX (vbox), selector_scrolled_window, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - component_view->sidebar_control = bonobo_control_new (vbox); - - /* Create main view */ - component_view->view_control = memos_control_new (); - if (!component_view->view_control) { - /* FIXME free memory */ - - return NULL; - } + g_signal_connect (component_view->source_selector, "drag-data-received", + G_CALLBACK (selector_tree_drag_data_received), memos_component); component_view->memos = (EMemos *) bonobo_control_get_widget (component_view->view_control); component_view->table = e_memo_table_get_table (e_memos_get_calendar_table (component_view->memos)); component_view->model = E_TABLE_MODEL (e_memo_table_get_model (e_memos_get_calendar_table (component_view->memos))); - /* This signal is thrown if backends die - we update the selector */ - g_signal_connect (component_view->memos, "source_added", - G_CALLBACK (source_added_cb), component_view); - g_signal_connect (component_view->memos, "source_removed", - G_CALLBACK (source_removed_cb), component_view); - - /* Create status bar */ - statusbar_widget = e_task_bar_new (); - component_view->activity_handler = e_activity_handler_new (); - e_activity_handler_attach_task_bar (component_view->activity_handler, E_TASK_BAR (statusbar_widget)); - gtk_widget_show (statusbar_widget); - - component_view->statusbar_control = bonobo_control_new (statusbar_widget); - - e_memo_table_set_activity_handler (e_memos_get_calendar_table (component_view->memos), component_view->activity_handler); - /* connect after setting the initial selections, or we'll get unwanted calls to calendar_control_sensitize_calendar_commands */ g_signal_connect (component_view->source_selector, "selection_changed", G_CALLBACK (source_selection_changed_cb), component_view); g_signal_connect (component_view->source_selector, "primary_selection_changed", G_CALLBACK (primary_source_selection_changed_cb), component_view); - g_signal_connect (component_view->source_selector, "popup_event", - G_CALLBACK (popup_event_cb), component_view); - - /* Set up the "new" item handler */ - component_view->creatable_items_handler = e_user_creatable_items_handler_new ("memos", create_local_item_cb, memos_component); - g_signal_connect (component_view->view_control, "activate", G_CALLBACK (control_activate_cb), component_view); - - /* We use this to update the component information */ - set_info (component_view); - g_signal_connect (component_view->table, "selection_change", - G_CALLBACK (table_selection_change_cb), component_view); - g_signal_connect (component_view->model, "model_changed", - G_CALLBACK (model_changed_cb), component_view); - g_signal_connect (component_view->model, "model_rows_inserted", - G_CALLBACK (model_rows_inserted_cb), component_view); - g_signal_connect (component_view->model, "model_rows_deleted", - G_CALLBACK (model_rows_deleted_cb), component_view); - - /* Load the selection from the last run */ - update_selection (component_view); - update_primary_selection (component_view); return component_view; } @@ -965,130 +383,9 @@ destroy_component_view (MemosComponentView *component_view) calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); g_list_free (component_view->notifications); - if (component_view->creatable_items_handler) - g_object_unref (component_view->creatable_items_handler); - - if (component_view->activity_handler) - g_object_unref (component_view->activity_handler); - g_free (component_view); } -static void -view_destroyed_cb (gpointer data, GObject *where_the_object_was) -{ - MemosComponent *memos_component = data; - MemosComponentPrivate *priv; - GList *l; - - priv = memos_component->priv; - - for (l = priv->views; l; l = l->next) { - MemosComponentView *component_view = l->data; - - if (G_OBJECT (component_view->view_control) == where_the_object_was) { - priv->views = g_list_remove (priv->views, component_view); - destroy_component_view (component_view); - - break; - } - } -} - -static GNOME_Evolution_ComponentView -impl_createView (PortableServer_Servant servant, - GNOME_Evolution_ShellView parent, - CORBA_boolean select_item, - CORBA_Environment *ev) -{ - MemosComponent *component = MEMOS_COMPONENT (bonobo_object_from_servant (servant)); - MemosComponentPrivate *priv; - MemosComponentView *component_view; - EComponentView *ecv; - - priv = component->priv; - - /* Create the calendar component view */ - component_view = create_component_view (component); - if (!component_view) { - /* FIXME Should we describe the problem in a control? */ - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); - - return CORBA_OBJECT_NIL; - } - - g_object_weak_ref (G_OBJECT (component_view->view_control), view_destroyed_cb, component); - priv->views = g_list_append (priv->views, component_view); - - /* TODO: Make CalendarComponentView just subclass EComponentView */ - ecv = e_component_view_new_controls (parent, "memos", component_view->sidebar_control, - component_view->view_control, component_view->statusbar_control); - - return BONOBO_OBJREF(ecv); -} - -static GNOME_Evolution_CreatableItemTypeList * -impl__get_userCreatableItems (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GNOME_Evolution_CreatableItemTypeList *list = GNOME_Evolution_CreatableItemTypeList__alloc (); - - list->_length = 3; - list->_maximum = list->_length; - list->_buffer = GNOME_Evolution_CreatableItemTypeList_allocbuf (list->_length); - - CORBA_sequence_set_release (list, FALSE); - - list->_buffer[0].id = (gchar *) CREATE_MEMO_ID; - list->_buffer[0].description = (gchar *) _("New memo"); - list->_buffer[0].menuDescription = (gchar *) C_("New", "Mem_o"); - list->_buffer[0].tooltip = (gchar *) _("Create a new memo"); - list->_buffer[0].menuShortcut = 'o'; - list->_buffer[0].iconName = (gchar *) "stock_insert-note"; - list->_buffer[0].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[1].id = (gchar *) CREATE_SHARED_MEMO_ID; - list->_buffer[1].description = (gchar *) _("New shared memo"); - list->_buffer[1].menuDescription = (gchar *) C_("New", "_Shared memo"); - list->_buffer[1].tooltip = (gchar *) _("Create a shared new memo"); - list->_buffer[1].menuShortcut = 'h'; - list->_buffer[1].iconName = (gchar *) "stock_insert-note"; - list->_buffer[1].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[2].id = (gchar *) CREATE_MEMO_LIST_ID; - list->_buffer[2].description = (gchar *) _("New memo list"); - list->_buffer[2].menuDescription = (gchar *) C_("New", "Memo li_st"); - list->_buffer[2].tooltip = (gchar *) _("Create a new memo list"); - list->_buffer[2].menuShortcut = '\0'; - list->_buffer[2].iconName = (gchar *) "stock_notes"; - list->_buffer[2].type = GNOME_Evolution_CREATABLE_FOLDER; - - return list; -} - -static void -impl_requestCreateItem (PortableServer_Servant servant, - const CORBA_char *item_type_name, - CORBA_Environment *ev) -{ - MemosComponent *memos_component = MEMOS_COMPONENT (bonobo_object_from_servant (servant)); - - if (strcmp (item_type_name, CREATE_MEMO_ID) == 0) { - if (!create_new_memo (memos_component, FALSE, NULL)) - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); - } - else if (strcmp (item_type_name, CREATE_MEMO_LIST_ID) == 0) { - /* FIXME Should we use the last opened window? */ - calendar_setup_new_memo_list (NULL); - } else if (strcmp (item_type_name, CREATE_SHARED_MEMO_ID) == 0) { - if (!create_new_memo (memos_component, TRUE, NULL)) - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); - } - else { - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_UnknownType); - } -} - /* GObject methods. */ static void @@ -1112,14 +409,6 @@ impl_dispose (GObject *object) priv->create_ecal = NULL; } - for (l = priv->views; l; l = l->next) { - MemosComponentView *component_view = l->data; - - g_object_weak_unref (G_OBJECT (component_view->view_control), view_destroyed_cb, memos_component); - } - g_list_free (priv->views); - priv->views = NULL; - for (l = priv->notifications; l; l = l->next) calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); g_list_free (priv->notifications); @@ -1127,98 +416,3 @@ impl_dispose (GObject *object) (* G_OBJECT_CLASS (parent_class)->dispose) (object); } - -static void -impl_finalize (GObject *object) -{ - MemosComponentPrivate *priv = MEMOS_COMPONENT (object)->priv; - GList *l; - - for (l = priv->views; l; l = l->next) { - MemosComponentView *component_view = l->data; - - destroy_component_view (component_view); - } - g_list_free (priv->views); - - g_free (priv->base_directory); - g_free (priv->config_directory); - g_free (priv); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static void -memos_component_class_init (MemosComponentClass *klass) -{ - POA_GNOME_Evolution_Component__epv *epv = &klass->epv; - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - - parent_class = g_type_class_peek_parent (klass); - - epv->upgradeFromVersion = impl_upgradeFromVersion; - epv->createView = impl_createView; - epv->_get_userCreatableItems = impl__get_userCreatableItems; - epv->requestCreateItem = impl_requestCreateItem; - - object_class->dispose = impl_dispose; - object_class->finalize = impl_finalize; -} - -static void -memos_component_init (MemosComponent *component, MemosComponentClass *klass) -{ - MemosComponentPrivate *priv; - - priv = g_new0 (MemosComponentPrivate, 1); - - priv->base_directory = g_build_filename (e_get_user_data_dir (), "memos", NULL); - priv->config_directory = g_build_filename (priv->base_directory, "config", NULL); - - component->priv = priv; - ensure_sources (component); -} - -/* Public API */ - -MemosComponent * -memos_component_peek (void) -{ - static MemosComponent *component = NULL; - - if (component == NULL) { - component = g_object_new (memos_component_get_type (), NULL); - - if (g_mkdir_with_parents (component->priv->config_directory, 0777) != 0) { - g_warning (G_STRLOC ": Cannot create directory %s: %s", - component->priv->config_directory, g_strerror (errno)); - g_object_unref (component); - component = NULL; - } - } - - return component; -} - -const gchar * -memos_component_peek_base_directory (MemosComponent *component) -{ - return component->priv->base_directory; -} - -const gchar * -memos_component_peek_config_directory (MemosComponent *component) -{ - return component->priv->config_directory; -} - -ESourceList * -memos_component_peek_source_list (MemosComponent *component) -{ - return component->priv->source_list; -} - -BONOBO_TYPE_FUNC_FULL (MemosComponent, GNOME_Evolution_Component, PARENT_TYPE, memos_component) diff --git a/calendar/gui/memos-component.h b/calendar/gui/memos-component.h index bba81a44f2..f1ba3de204 100644 --- a/calendar/gui/memos-component.h +++ b/calendar/gui/memos-component.h @@ -57,8 +57,4 @@ struct _MemosComponentClass { GType memos_component_get_type (void); MemosComponent *memos_component_peek (void); -const gchar *memos_component_peek_base_directory (MemosComponent *component); -const gchar *memos_component_peek_config_directory (MemosComponent *component); -ESourceList *memos_component_peek_source_list (MemosComponent *component); - #endif /* _MEMOS_COMPONENT_H_ */ diff --git a/calendar/gui/memos-control.c b/calendar/gui/memos-control.c deleted file mode 100644 index 46719a55fe..0000000000 --- a/calendar/gui/memos-control.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * Ettore Perazzoli - * Nathan Owens <pianocomp81@yahoo.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <glib/gi18n.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-ui-util.h> -#include <e-util/e-dialog-utils.h> -#include <e-util/e-icon-factory.h> -#include <e-util/e-print.h> -#include <e-util/e-util-private.h> -#include <gtkhtml/gtkhtml.h> - -#include "calendar-config.h" -#include "e-memos.h" -#include "e-memo-table.h" -#include "print.h" -#include "memos-control.h" -#include "e-cal-component-memo-preview.h" -#include "evolution-shell-component-utils.h" - -#define FIXED_MARGIN .05 - - -static void memos_control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data); -static void memos_control_open_memo_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_new_memo_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void memos_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); - -struct focus_changed_data { - BonoboControl *control; - EMemos *memos; -}; - -static gboolean memos_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data); - -BonoboControl * -memos_control_new (void) -{ - BonoboControl *control; - GtkWidget *memos, *preview; - struct focus_changed_data *fc_data; - - memos = e_memos_new (); - if (!memos) - return NULL; - gtk_widget_show (memos); - - control = bonobo_control_new (memos); - if (!control) { - gtk_widget_destroy (memos); - g_message ("control_factory_fn(): could not create the control!"); - return NULL; - } - - g_signal_connect (control, "activate", G_CALLBACK (memos_control_activate_cb), memos); - - fc_data = g_new0 (struct focus_changed_data, 1); - fc_data->control = control; - fc_data->memos = E_MEMOS (memos); - - preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (fc_data->memos))); - g_object_set_data_full (G_OBJECT (preview), "memos-ctrl-fc-data", fc_data, g_free); - g_signal_connect (preview, "focus-in-event", G_CALLBACK (memos_control_focus_changed), fc_data); - g_signal_connect (preview, "focus-out-event", G_CALLBACK (memos_control_focus_changed), fc_data); - - return control; -} - - -static void -memos_control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data) -{ - EMemos *memos; - - memos = E_MEMOS (user_data); - - if (activate) - memos_control_activate (control, memos); - else - memos_control_deactivate (control, memos); -} - -/* Sensitizes the UI Component menu/toolbar commands based on the number of - * selected memos. - */ -void -memos_control_sensitize_commands (BonoboControl *control, EMemos *memos, gint n_selected) -{ - BonoboUIComponent *uic; - gboolean read_only = TRUE, preview_active; - ECal *ecal; - ECalModel *model; - GtkWidget *preview; - - uic = bonobo_control_get_ui_component (control); - g_return_if_fail (uic != NULL); - - if (bonobo_ui_component_get_container (uic) == CORBA_OBJECT_NIL) - return; - - preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (memos))); - preview_active = preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview); - - model = e_memo_table_get_model (e_memos_get_calendar_table (memos)); - ecal = e_cal_model_get_default_client (model); - if (ecal) - e_cal_is_read_only (ecal, &read_only, NULL); - - bonobo_ui_component_set_prop (uic, "/commands/MemosOpenMemo", "sensitive", - n_selected != 1 ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/MemosCut", "sensitive", - n_selected == 0 || read_only || preview_active ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/MemosCopy", "sensitive", - n_selected == 0 ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/MemosPaste", "sensitive", - read_only || preview_active ? "0" : "1", - NULL); - bonobo_ui_component_set_prop (uic, "/commands/MemosDelete", "sensitive", - n_selected == 0 || read_only ? "0" : "1", - NULL); -} - -/* Callback used when the selection in the table changes */ -static void -selection_changed_cb (EMemos *memos, gint n_selected, gpointer data) -{ - BonoboControl *control; - - control = BONOBO_CONTROL (data); - - memos_control_sensitize_commands (control, memos, n_selected); -} - -static gboolean -memos_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data) -{ - g_return_val_if_fail (fc_data != NULL, FALSE); - - memos_control_sensitize_commands (fc_data->control, fc_data->memos, e_table_selected_count (e_memo_table_get_table (e_memos_get_calendar_table (fc_data->memos)))); - - return FALSE; -} - -static BonoboUIVerb verbs [] = { - BONOBO_UI_VERB ("MemosOpenMemo", memos_control_open_memo_cmd), - BONOBO_UI_VERB ("MemosNewMemo", memos_control_new_memo_cmd), - BONOBO_UI_VERB ("MemosCut", memos_control_cut_cmd), - BONOBO_UI_VERB ("MemosCopy", memos_control_copy_cmd), - BONOBO_UI_VERB ("MemosPaste", memos_control_paste_cmd), - BONOBO_UI_VERB ("MemosDelete", memos_control_delete_cmd), - BONOBO_UI_VERB ("MemosPrint", memos_control_print_cmd), - BONOBO_UI_VERB ("MemosPrintPreview", memos_control_print_preview_cmd), - - BONOBO_UI_VERB_END -}; - -static EPixmap pixmaps [] = { - E_PIXMAP ("/commands/MemosCopy", "edit-copy", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/MemosCut", "edit-cut", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/MemosDelete", "edit-delete", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/MemosPaste", "edit-paste", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/MemosPrint", "document-print", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/MemosPrintPreview", "document-print-preview", GTK_ICON_SIZE_MENU), - - E_PIXMAP ("/Toolbar/Cut", "edit-cut", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Copy", "edit-copy", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Paste", "edit-paste", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Print", "document-print", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Delete", "edit-delete", GTK_ICON_SIZE_LARGE_TOOLBAR), - - E_PIXMAP_END -}; - -void -memos_control_activate (BonoboControl *control, EMemos *memos) -{ - Bonobo_UIContainer remote_uih; - BonoboUIComponent *uic; - gint n_selected; - EMemoTable *cal_table; - ETable *etable; - gchar *xmlfile; - - uic = bonobo_control_get_ui_component (control); - g_return_if_fail (uic != NULL); - - remote_uih = bonobo_control_get_remote_ui_container (control, NULL); - bonobo_ui_component_set_container (uic, remote_uih, NULL); - bonobo_object_release_unref (remote_uih, NULL); - - e_memos_set_ui_component (memos, uic); - - bonobo_ui_component_add_verb_list_with_data (uic, verbs, memos); - - bonobo_ui_component_freeze (uic, NULL); - - xmlfile = g_build_filename (EVOLUTION_UIDIR, - "evolution-memos.xml", - NULL); - bonobo_ui_util_set_ui (uic, PREFIX, - xmlfile, - "evolution-memos", - NULL); - g_free (xmlfile); - - e_pixmaps_update (uic, pixmaps); - - e_memos_setup_view_menus (memos, uic); - - /* Signals from the memos widget; also sensitize the menu items as appropriate */ - - g_signal_connect (memos, "selection_changed", G_CALLBACK (selection_changed_cb), control); - - cal_table = e_memos_get_calendar_table (memos); - etable = e_memo_table_get_table (cal_table); - n_selected = e_table_selected_count (etable); - - memos_control_sensitize_commands (control, memos, n_selected); - - bonobo_ui_component_thaw (uic, NULL); -} - - -void -memos_control_deactivate (BonoboControl *control, EMemos *memos) -{ - BonoboUIComponent *uic = bonobo_control_get_ui_component (control); - - g_return_if_fail (uic != NULL); - - e_memos_set_ui_component (memos, NULL); - - e_memos_discard_view_menus (memos); - - /* Stop monitoring the "selection_changed" signal */ - g_signal_handlers_disconnect_matched (memos, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, control); - - bonobo_ui_component_rm (uic, "/", NULL); - bonobo_ui_component_unset_container (uic, NULL); -} - -static void memos_control_open_memo_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - - memos = E_MEMOS (data); - e_memos_open_memo (memos); -} - -static void -memos_control_new_memo_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - - memos = E_MEMOS (data); - e_memos_new_memo (memos); -} - -static void -memos_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - EMemoTable *cal_table; - - memos = E_MEMOS (data); - cal_table = e_memos_get_calendar_table (memos); - e_memo_table_cut_clipboard (cal_table); -} - -static void -memos_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - EMemoTable *cal_table; - GtkWidget *preview; - - memos = E_MEMOS (data); - - preview = e_cal_component_memo_preview_get_html (E_CAL_COMPONENT_MEMO_PREVIEW (e_memos_get_preview (memos))); - if (preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview)) { - /* copy selected text in a preview when that's shown and focused */ - gtk_html_copy (GTK_HTML (preview)); - } else { - cal_table = e_memos_get_calendar_table (memos); - e_memo_table_copy_clipboard (cal_table); - } -} - -static void -memos_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - EMemoTable *cal_table; - - memos = E_MEMOS (data); - cal_table = e_memos_get_calendar_table (memos); - e_memo_table_paste_clipboard (cal_table); -} - -static void -memos_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos; - - memos = E_MEMOS (data); - e_memos_delete_selected (memos); -} - -/* File/Print callback */ -static void -memos_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos = E_MEMOS (data); - ETable *table; - - table = e_memo_table_get_table ( - E_MEMO_TABLE (e_memos_get_calendar_table (memos))); - - print_table ( - table, _("Print Memos"), _("Memos"), - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); -} - -static void -memos_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - EMemos *memos = E_MEMOS (data); - ETable *table; - - table = e_memo_table_get_table ( - E_MEMO_TABLE (e_memos_get_calendar_table (memos))); - - print_table ( - table, _("Print Memos"), _("Memos"), - GTK_PRINT_OPERATION_ACTION_PREVIEW); -} diff --git a/calendar/gui/memos-control.h b/calendar/gui/memos-control.h deleted file mode 100644 index 854f5f9d9b..0000000000 --- a/calendar/gui/memos-control.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Federico Mena Quintero <federico@ximian.com> - * Damon Chaplin <damon@ximian.com> - * Nathan Owens <pianocomp81@yahoo.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _MEMOS_CONTROL_H_ -#define _MEMOS_CONTROL_H_ - -#include "e-memos.h" - -BonoboControl *memos_control_new (void); -void memos_control_activate (BonoboControl *control, EMemos *memos); -void memos_control_deactivate (BonoboControl *control, EMemos *memos); -void memos_control_sensitize_commands (BonoboControl *control, EMemos *memos, gint n_selected); - -#endif /* _MEMOS_CONTROL_H_ */ diff --git a/calendar/gui/migration.c b/calendar/gui/migration.c deleted file mode 100644 index 6ebf17fd6c..0000000000 --- a/calendar/gui/migration.c +++ /dev/null @@ -1,1245 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include <config.h> - -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <gtk/gtk.h> -#include <glib/gi18n.h> -#include <glib/gstdio.h> - -#include <libecal/e-cal.h> - -#include <libebackend/e-dbhash.h> -#include <libedataserver/e-xml-hash-utils.h> -#include <libedataserver/e-xml-utils.h> -#include <libedataserver/e-account-list.h> -#include <camel/camel-url.h> - -#include "e-util/e-bconf-map.h" -#include "e-util/e-folder-map.h" -#include "e-util/e-util-private.h" - -#include "calendar-config-keys.h" -#include "calendar-config.h" -#include "e-cal-event.h" -#include "migration.h" - -#ifndef G_OS_WIN32 - -/* No previous versions have been available on Win32, so don't - * bother with upgrade support from 1.x on Win32. - */ - -static e_gconf_map_t calendar_display_map[] = { - /* /Calendar/Display */ - { "Timezone", "calendar/display/timezone", E_GCONF_MAP_STRING }, - { "Use24HourFormat", "calendar/display/use_24hour_format", E_GCONF_MAP_BOOL }, - { "WeekStartDay", "calendar/display/week_start_day", E_GCONF_MAP_INT }, - { "DayStartHour", "calendar/display/day_start_hour", E_GCONF_MAP_INT }, - { "DayStartMinute", "calendar/display/day_start_minute", E_GCONF_MAP_INT }, - { "DayEndHour", "calendar/display/day_end_hour", E_GCONF_MAP_INT }, - { "DayEndMinute", "calendar/display/day_end_minute", E_GCONF_MAP_INT }, - { "TimeDivisions", "calendar/display/time_divisions", E_GCONF_MAP_INT }, - { "View", "calendar/display/default_view", E_GCONF_MAP_INT }, - { "HPanePosition", "calendar/display/hpane_position", E_GCONF_MAP_FLOAT }, - { "VPanePosition", "calendar/display/vpane_position", E_GCONF_MAP_FLOAT }, - { "MonthHPanePosition", "calendar/display/month_hpane_position", E_GCONF_MAP_FLOAT }, - { "MonthVPanePosition", "calendar/display/month_vpane_position", E_GCONF_MAP_FLOAT }, - { "CompressWeekend", "calendar/display/compress_weekend", E_GCONF_MAP_BOOL }, - { "ShowEventEndTime", "calendar/display/show_event_end", E_GCONF_MAP_BOOL }, - { "WorkingDays", "calendar/display/working_days", E_GCONF_MAP_INT }, - { NULL }, -}; - -static e_gconf_map_t calendar_tasks_map[] = { - /* /Calendar/Tasks */ - { "HideCompletedTasks", "calendar/tasks/hide_completed", E_GCONF_MAP_BOOL }, - { "HideCompletedTasksUnits", "calendar/tasks/hide_completed_units", E_GCONF_MAP_STRING }, - { "HideCompletedTasksValue", "calendar/tasks/hide_completed_value", E_GCONF_MAP_INT }, - { NULL }, -}; - -static e_gconf_map_t calendar_tasks_colours_map[] = { - /* /Calendar/Tasks/Colors */ - { "TasksDueToday", "calendar/tasks/colors/due_today", E_GCONF_MAP_STRING }, - { "TasksOverDue", "calendar/tasks/colors/overdue", E_GCONF_MAP_STRING }, - { "TasksDueToday", "calendar/tasks/colors/due_today", E_GCONF_MAP_STRING }, - { NULL }, -}; - -static e_gconf_map_t calendar_other_map[] = { - /* /Calendar/Other */ - { "ConfirmDelete", "calendar/prompts/confirm_delete", E_GCONF_MAP_BOOL }, - { "ConfirmExpunge", "calendar/prompts/confirm_purge", E_GCONF_MAP_BOOL }, - { "UseDefaultReminder", "calendar/other/use_default_reminder", E_GCONF_MAP_BOOL }, - { "DefaultReminderInterval", "calendar/other/default_reminder_interval", E_GCONF_MAP_INT }, - { "DefaultReminderUnits", "calendar/other/default_reminder_units", E_GCONF_MAP_STRING }, - { NULL }, -}; - -static e_gconf_map_t calendar_datenavigator_map[] = { - /* /Calendar/DateNavigator */ - { "ShowWeekNumbers", "calendar/date_navigator/show_week_numbers", E_GCONF_MAP_BOOL }, - { NULL }, -}; - -static e_gconf_map_t calendar_alarmnotify_map[] = { - /* /Calendar/AlarmNotify */ - { "LastNotificationTime", "calendar/notify/last_notification_time", E_GCONF_MAP_INT }, - { "CalendarToLoad%i", "calendar/notify/calendars", E_GCONF_MAP_STRING|E_GCONF_MAP_LIST }, - { "BlessedProgram%i", "calendar/notify/programs", E_GCONF_MAP_STRING|E_GCONF_MAP_LIST }, - { NULL }, -}; - -static e_gconf_map_list_t calendar_remap_list[] = { - - { "/Calendar/Display", calendar_display_map }, - { "/Calendar/Other/Map", calendar_other_map }, - { "/Calendar/DateNavigator", calendar_datenavigator_map }, - { "/Calendar/AlarmNotify", calendar_alarmnotify_map }, - - { NULL }, -}; - -static e_gconf_map_list_t task_remap_list[] = { - - { "/Calendar/Tasks", calendar_tasks_map }, - { "/Calendar/Tasks/Colors", calendar_tasks_colours_map }, - - { NULL }, -}; - -static GtkWidget *window; -static GtkLabel *label; -static GtkProgressBar *progress; - -static void -setup_progress_dialog (gboolean tasks) -{ - GtkWidget *vbox, *hbox, *w; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title ((GtkWindow *) window, _("Migrating...")); - gtk_window_set_modal ((GtkWindow *) window, TRUE); - gtk_container_set_border_width ((GtkContainer *) window, 6); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - gtk_container_add ((GtkContainer *) window, vbox); - - if (tasks) - w = gtk_label_new (_("The location and hierarchy of the Evolution task " - "folders has changed since Evolution 1.x.\n\nPlease be " - "patient while Evolution migrates your folders...")); - else - w = gtk_label_new (_("The location and hierarchy of the Evolution calendar " - "folders has changed since Evolution 1.x.\n\nPlease be " - "patient while Evolution migrates your folders...")); - - gtk_label_set_line_wrap ((GtkLabel *) w, TRUE); - gtk_widget_show (w); - gtk_box_pack_start ((GtkBox *) vbox, w, TRUE, TRUE, 0); - - hbox = gtk_hbox_new (FALSE, 6); - gtk_widget_show (hbox); - gtk_box_pack_start ((GtkBox *) vbox, hbox, TRUE, TRUE, 0); - - label = (GtkLabel *) gtk_label_new (""); - gtk_widget_show ((GtkWidget *) label); - gtk_box_pack_start ((GtkBox *) hbox, (GtkWidget *) label, TRUE, TRUE, 0); - - progress = (GtkProgressBar *) gtk_progress_bar_new (); - gtk_widget_show ((GtkWidget *) progress); - gtk_box_pack_start ((GtkBox *) hbox, (GtkWidget *) progress, TRUE, TRUE, 0); - - gtk_widget_show (window); -} - -static void -dialog_close (void) -{ - gtk_widget_destroy ((GtkWidget *) window); -} - -static void -dialog_set_folder_name (const gchar *folder_name) -{ - gchar *text; - - text = g_strdup_printf (_("Migrating '%s':"), folder_name); - gtk_label_set_text (label, text); - g_free (text); - - gtk_progress_bar_set_fraction (progress, 0.0); - - while (gtk_events_pending ()) - gtk_main_iteration (); -} - -static void -dialog_set_progress (double percent) -{ - gchar text[5]; - - snprintf (text, sizeof (text), "%d%%", (gint) (percent * 100.0f)); - - gtk_progress_bar_set_fraction (progress, percent); - gtk_progress_bar_set_text (progress, text); - - while (gtk_events_pending ()) - gtk_main_iteration (); -} - -static gboolean -check_for_conflict (ESourceGroup *group, gchar *name) -{ - GSList *sources; - GSList *s; - - sources = e_source_group_peek_sources (group); - - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - - if (!strcmp (e_source_peek_name (source), name)) - return TRUE; - } - - return FALSE; -} - -static gchar * -get_source_name (ESourceGroup *group, const gchar *path) -{ - gchar **p = g_strsplit (path, "/", 0); - gint i, j, starting_index; - gint num_elements; - gboolean conflict; - GString *s = g_string_new (NULL); - - for (i = 0; p[i]; i ++); - - num_elements = i; - i--; - - /* p[i] is now the last path element */ - - /* check if it conflicts */ - starting_index = i; - do { - for (j = starting_index; j < num_elements; j += 2) { - if (j != starting_index) - g_string_append_c (s, '_'); - g_string_append (s, p[j]); - } - - conflict = check_for_conflict (group, s->str); - - - /* if there was a conflict back up 2 levels (skipping the /subfolder/ element) */ - if (conflict) - starting_index -= 2; - - /* we always break out if we can't go any further, - regardless of whether or not we conflict. */ - if (starting_index < 0) - break; - - } while (conflict); - g_strfreev (p); - - return g_string_free (s, FALSE); -} - -static gboolean -migrate_ical (ECal *old_ecal, ECal *new_ecal) -{ - GList *l, *objects; - gint num_added = 0; - gint num_objects; - gboolean retval = TRUE; - - /* both ecals are loaded, start the actual migration */ - if (!e_cal_get_object_list (old_ecal, "#t", &objects, NULL)) - return FALSE; - - num_objects = g_list_length (objects); - for (l = objects; l; l = l->next) { - icalcomponent *ical_comp = l->data; - GError *error = NULL; - - if (!e_cal_create_object (new_ecal, ical_comp, NULL, &error)) { - g_warning ("Migration of object failed: %s", error->message); - retval = FALSE; - } - - g_clear_error (&error); - - num_added ++; - dialog_set_progress ((double)num_added / num_objects); - } - - g_list_foreach (objects, (GFunc) icalcomponent_free, NULL); - g_list_free (objects); - - return retval; -} - -static gboolean -migrate_ical_folder_to_source (gchar *old_path, ESource *new_source, ECalSourceType type) -{ - ECal *old_ecal = NULL, *new_ecal = NULL; - ESource *old_source; - ESourceGroup *group; - gchar *old_uri = g_filename_to_uri (old_path, NULL, NULL); - GError *error = NULL; - gboolean retval = FALSE; - - group = e_source_group_new ("", old_uri); - old_source = e_source_new ("", ""); - e_source_group_add_source (group, old_source, -1); - - dialog_set_folder_name (e_source_peek_name (new_source)); - - if (!(old_ecal = e_cal_new (old_source, type))) { - g_warning ("could not find a backend for '%s'", e_source_get_uri (old_source)); - goto finish; - } - if (!e_cal_open (old_ecal, FALSE, &error)) { - g_warning ("failed to load source ecal for migration: '%s' (%s)", error->message, - e_source_get_uri (old_source)); - goto finish; - } - - if (!(new_ecal = e_cal_new (new_source, type))) { - g_warning ("could not find a backend for '%s'", e_source_get_uri (new_source)); - goto finish; - } - if (!e_cal_open (new_ecal, FALSE, &error)) { - g_warning ("failed to load destination ecal for migration: '%s' (%s)", error->message, - e_source_get_uri (new_source)); - goto finish; - } - - retval = migrate_ical (old_ecal, new_ecal); - -finish: - g_clear_error (&error); - if (old_ecal) - g_object_unref (old_ecal); - g_object_unref (group); - if (new_ecal) - g_object_unref (new_ecal); - g_free (old_uri); - - return retval; -} - -static gboolean -migrate_ical_folder (gchar *old_path, ESourceGroup *dest_group, gchar *source_name, ECalSourceType type) -{ - ESource *new_source; - gboolean retval; - - new_source = e_source_new (source_name, source_name); - e_source_set_relative_uri (new_source, e_source_peek_uid (new_source)); - e_source_group_add_source (dest_group, new_source, -1); - - retval = migrate_ical_folder_to_source (old_path, new_source, type); - - g_object_unref (new_source); - - return retval; -} - -#endif /* !G_OS_WIN32 */ - -#define WEBCAL_BASE_URI "webcal://" -#define CONTACTS_BASE_URI "contacts://" -#define BAD_CONTACTS_BASE_URI "contact://" -#define PERSONAL_RELATIVE_URI "system" -#define GROUPWISE_BASE_URI "groupwise://" - -static ESourceGroup * -create_calendar_contact_source (ESourceList *source_list) -{ - ESourceGroup *group; - ESource *source; - - /* Create the contacts group */ - group = e_source_group_new (_("Contacts"), CONTACTS_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - source = e_source_new (_("Birthdays & Anniversaries"), "/"); - e_source_group_add_source (group, source, -1); - g_object_unref (source); - - e_source_set_color_spec (source, "#FED4D3"); - e_source_group_set_readonly (group, TRUE); - - return group; -} - -static void -create_calendar_sources (CalendarComponent *component, - ESourceList *source_list, - ESourceGroup **on_this_computer, - ESource **personal_source, - ESourceGroup **on_the_web, - ESourceGroup **contacts) -{ - GSList *groups; - ESourceGroup *group; - gchar *base_uri, *base_uri_proto; - const gchar *base_dir; - - *on_this_computer = NULL; - *on_the_web = NULL; - *contacts = NULL; - *personal_source = NULL; - - base_dir = calendar_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - if (!strcmp (BAD_CONTACTS_BASE_URI, e_source_group_peek_base_uri (group))) - e_source_group_set_base_uri (group, CONTACTS_BASE_URI); - - if (!strcmp (base_uri, e_source_group_peek_base_uri (group))) - e_source_group_set_base_uri (group, base_uri_proto); - - if (!*on_this_computer && !strcmp (base_uri_proto, e_source_group_peek_base_uri (group))) - *on_this_computer = g_object_ref (group); - else if (!*on_the_web && !strcmp (WEBCAL_BASE_URI, e_source_group_peek_base_uri (group))) - *on_the_web = g_object_ref (group); - else if (!*contacts && !strcmp (CONTACTS_BASE_URI, e_source_group_peek_base_uri (group))) - *contacts = g_object_ref (group); - } - } - - if (*on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (*on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - *personal_source = g_object_ref (source); - break; - } - } - } else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - *on_this_computer = group; - } - - if (!*personal_source) { - gchar *primary_calendar = calendar_config_get_primary_calendar (); - - /* Create the default Person calendar */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (*on_this_computer, source, -1); - - if (!primary_calendar && !calendar_config_get_calendars_selected ()) { - GSList selected; - - calendar_config_set_primary_calendar (e_source_peek_uid (source)); - - selected.data = (gpointer)e_source_peek_uid (source); - selected.next = NULL; - calendar_config_set_calendars_selected (&selected); - } - - g_free (primary_calendar); - e_source_set_color_spec (source, "#BECEDD"); - *personal_source = source; - } - - if (!*on_the_web) { - /* Create the Webcal source group */ - group = e_source_group_new (_("On The Web"), WEBCAL_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - *on_the_web = group; - } - - if (!*contacts) { - group = create_calendar_contact_source (source_list); - - *contacts = group; - } - - g_free (base_uri_proto); - g_free (base_uri); -} - -static void -create_task_sources (TasksComponent *component, - ESourceList *source_list, - ESourceGroup **on_this_computer, - ESourceGroup **on_the_web, - ESource **personal_source) -{ - GSList *groups; - ESourceGroup *group; - gchar *base_uri, *base_uri_proto; - const gchar *base_dir; - - *on_this_computer = NULL; - *on_the_web = NULL; - *personal_source = NULL; - - base_dir = tasks_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - if (!*on_this_computer && !strcmp (base_uri_proto, e_source_group_peek_base_uri (group))) - *on_this_computer = g_object_ref (group); - else if (!*on_the_web && !strcmp (WEBCAL_BASE_URI, e_source_group_peek_base_uri (group))) - *on_the_web = g_object_ref (group); - } - } - - if (*on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (*on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - *personal_source = g_object_ref (source); - break; - } - } - } else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - *on_this_computer = group; - } - - if (!*personal_source) { - /* Create the default Person task list */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (*on_this_computer, source, -1); - - if (!calendar_config_get_primary_tasks () && !calendar_config_get_tasks_selected ()) { - GSList selected; - - calendar_config_set_primary_tasks (e_source_peek_uid (source)); - - selected.data = (gpointer)e_source_peek_uid (source); - selected.next = NULL; - calendar_config_set_tasks_selected (&selected); - } - - e_source_set_color_spec (source, "#BECEDD"); - *personal_source = source; - } - - if (!*on_the_web) { - /* Create the Webcal source group */ - group = e_source_group_new (_("On The Web"), WEBCAL_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - *on_the_web = group; - } - - g_free (base_uri_proto); - g_free (base_uri); -} - -#ifndef G_OS_WIN32 - -static void -migrate_pilot_db_key (const gchar *key, gpointer user_data) -{ - EXmlHash *xmlhash = user_data; - - e_xmlhash_add (xmlhash, key, ""); -} - -static void -migrate_pilot_data (const gchar *component, const gchar *conduit, const gchar *old_path, const gchar *new_path) -{ - gchar *changelog, *map; - const gchar *dent; - const gchar *ext; - gchar *filename; - GDir *dir; - - if (!(dir = g_dir_open (old_path, 0, NULL))) - return; - - map = g_alloca (12 + strlen (conduit)); - sprintf (map, "pilot-map-%s-", conduit); - - changelog = g_alloca (24 + strlen (conduit)); - sprintf (changelog, "pilot-sync-evolution-%s-", conduit); - - while ((dent = g_dir_read_name (dir))) { - if (!strncmp (dent, map, strlen (map)) && - ((ext = strrchr (dent, '.')) && !strcmp (ext, ".xml"))) { - /* pilot map file - src and dest file formats are identical */ - guchar inbuf[4096]; - gsize nread, nwritten; - gint fd0, fd1; - gssize n; - - filename = g_build_filename (old_path, dent, NULL); - if ((fd0 = g_open (filename, O_RDONLY|O_BINARY, 0)) == -1) { - g_free (filename); - continue; - } - - g_free (filename); - filename = g_build_filename (new_path, dent, NULL); - if ((fd1 = g_open (filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) == -1) { - g_free (filename); - close (fd0); - continue; - } - - do { - do { - n = read (fd0, inbuf, sizeof (inbuf)); - } while (n == -1 && errno == EINTR); - - if (n < 1) - break; - - nread = n; - nwritten = 0; - do { - do { - n = write (fd1, inbuf + nwritten, nread - nwritten); - } while (n == -1 && errno == EINTR); - - if (n > 0) - nwritten += n; - } while (nwritten < nread && n != -1); - - if (n == -1) - break; - } while (1); - - if (n != -1) - n = fsync (fd1); - - if (n == -1) { - g_warning ("Failed to migrate %s: %s", dent, g_strerror (errno)); - g_unlink (filename); - } - - close (fd0); - close (fd1); - g_free (filename); - } else if (!strncmp (dent, changelog, strlen (changelog)) && - ((ext = strrchr (dent, '.')) && !strcmp (ext, ".db"))) { - /* src and dest formats differ, src format is db3 while dest format is xml */ - EXmlHash *xmlhash; - EDbHash *dbhash; - struct stat st; - - filename = g_build_filename (old_path, dent, NULL); - if (g_stat (filename, &st) == -1) { - g_free (filename); - continue; - } - - dbhash = e_dbhash_new (filename); - g_free (filename); - - filename = g_strdup_printf ("%s/%s.ics-%s", new_path, component, dent); - if (g_stat (filename, &st) != -1) - g_unlink (filename); - xmlhash = e_xmlhash_new (filename); - g_free (filename); - - e_dbhash_foreach_key (dbhash, migrate_pilot_db_key, xmlhash); - - e_dbhash_destroy (dbhash); - - e_xmlhash_write (xmlhash); - e_xmlhash_destroy (xmlhash); - } - } - - g_dir_close (dir); -} - -#endif - -gboolean -migrate_calendars (CalendarComponent *component, gint major, gint minor, gint revision, GError **err) -{ - ESourceGroup *on_this_computer = NULL, *on_the_web = NULL, *contacts = NULL; - ESource *personal_source = NULL; - ECalEvent *ece; - ECalEventTargetComponent *target; - gboolean retval = FALSE; - - /* we call this unconditionally now - create_groups either - creates the groups/sources or it finds the necessary - groups/sources. */ - create_calendar_sources (component, calendar_component_peek_source_list (component), &on_this_computer, &personal_source, &on_the_web, &contacts); - -#ifndef G_OS_WIN32 - if (major == 1) { - xmlDocPtr config_doc = NULL; - gchar *conf_file; - struct stat st; - - conf_file = g_build_filename (g_get_home_dir (), "evolution", "config.xmldb", NULL); - if (lstat (conf_file, &st) == 0 && S_ISREG (st.st_mode)) - config_doc = xmlParseFile (conf_file); - g_free (conf_file); - - if (config_doc && minor <= 2) { - GConfClient *gconf; - gint res = 0; - - /* move bonobo config to gconf */ - gconf = gconf_client_get_default (); - - res = e_bconf_import (gconf, config_doc, calendar_remap_list); - - g_object_unref (gconf); - - xmlFreeDoc(config_doc); - - if (res != 0) { - /* FIXME: set proper domain/code */ - g_set_error(err, 0, 0, _("Unable to migrate old settings from evolution/config.xmldb")); - goto fail; - } - } - - if (minor <= 4) { - GSList *migration_dirs, *l; - gchar *path, *local_cal_folder; - - setup_progress_dialog (FALSE); - - path = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - migration_dirs = e_folder_map_local_folders (path, "calendar"); - local_cal_folder = g_build_filename (path, "Calendar", NULL); - g_free (path); - - if (personal_source) - migrate_ical_folder_to_source (local_cal_folder, personal_source, E_CAL_SOURCE_TYPE_EVENT); - - for (l = migration_dirs; l; l = l->next) { - gchar *source_name; - - if (personal_source && !strcmp ((gchar *)l->data, local_cal_folder)) - continue; - - source_name = get_source_name (on_this_computer, (gchar *)l->data); - - if (!migrate_ical_folder (l->data, on_this_computer, source_name, E_CAL_SOURCE_TYPE_EVENT)) { - /* FIXME: domain/code */ - g_set_error(err, 0, 0, _("Unable to migrate calendar `%s'"), source_name); - g_free(source_name); - goto fail; - } - - g_free (source_name); - } - - g_free (local_cal_folder); - - dialog_close (); - } - - if (minor <= 4 || (minor == 5 && revision < 5)) { - GConfClient *gconf; - GConfValue *gconf_val; - gint i; - const gchar *keys[] = { - CALENDAR_CONFIG_HPANE_POS, - CALENDAR_CONFIG_VPANE_POS, - CALENDAR_CONFIG_MONTH_HPANE_POS, - CALENDAR_CONFIG_MONTH_VPANE_POS, - NULL - }; - - gconf = gconf_client_get_default (); - - for (i = 0; keys[i]; i++) { - gconf_val = gconf_client_get (gconf, keys[i], NULL); - if (gconf_val) { - if (gconf_val->type != GCONF_VALUE_INT) - gconf_client_unset (gconf, keys[i], NULL); - gconf_value_free (gconf_val); - } - } - - g_object_unref (gconf); - } - - if (minor < 5 || (minor == 5 && revision <= 10)) { - gchar *old_path, *new_path; - - old_path = g_build_filename (g_get_home_dir (), "evolution", "local", "Calendar", NULL); - new_path = g_build_filename (calendar_component_peek_base_directory (component), - "local", "system", NULL); - migrate_pilot_data ("calendar", "calendar", old_path, new_path); - g_free (new_path); - g_free (old_path); - } - - /* we only need to do this next step if people ran - older versions of 1.5. We need to clear out the - absolute URI's that were assigned to ESources - during one phase of development, as they take - precedent over relative uris (but aren't updated - when editing an ESource). */ - if (minor == 5 && revision <= 11) { - GSList *g; - for (g = e_source_list_peek_groups (calendar_component_peek_source_list (component)); g; g = g->next) { - ESourceGroup *group = g->data; - GSList *s; - - for (s = e_source_group_peek_sources (group); s; s = s->next) { - ESource *source = s->data; - e_source_set_absolute_uri (source, NULL); - } - } - } - - } -#endif /* !G_OS_WIN32 */ - - e_source_list_sync (calendar_component_peek_source_list (component), NULL); - - /** @Event: component.migration - * @Title: Migration step in component initialization - * @Target: ECalEventTargetComponent - * - * component.migration is emitted during the calendar component - * initialization process. This allows new calendar backend types - * to be distributed as an e-d-s backend and a plugin without - * reaching their grubby little fingers into migration.c - */ - /* Fire off migration event */ - ece = e_cal_event_peek (); - target = e_cal_event_target_new_component (ece, calendar_component_peek (), 0); - e_event_emit ((EEvent *) ece, "component.migration", (EEventTarget *) target); - - retval = TRUE; -fail: - if (on_this_computer) - g_object_unref (on_this_computer); - if (on_the_web) - g_object_unref (on_the_web); - if (contacts) - g_object_unref (contacts); - if (personal_source) - g_object_unref (personal_source); - - return retval; -} - -gboolean -migrate_tasks (TasksComponent *component, gint major, gint minor, gint revision, GError **err) -{ - ESourceGroup *on_this_computer = NULL; - ESourceGroup *on_the_web = NULL; - ESource *personal_source = NULL; - gboolean retval = FALSE; - - /* we call this unconditionally now - create_groups either - creates the groups/sources or it finds the necessary - groups/sources. */ - create_task_sources (component, tasks_component_peek_source_list (component), &on_this_computer, &on_the_web, &personal_source); - -#ifndef G_OS_WIN32 - if (major == 1) { - xmlDocPtr config_doc = NULL; - gchar *conf_file; - - conf_file = g_build_filename (g_get_home_dir (), "evolution", "config.xmldb", NULL); - if (g_file_test (conf_file, G_FILE_TEST_IS_REGULAR)) - config_doc = e_xml_parse_file (conf_file); - g_free (conf_file); - - if (config_doc && minor <= 2) { - GConfClient *gconf; - gint res = 0; - - /* move bonobo config to gconf */ - gconf = gconf_client_get_default (); - - res = e_bconf_import (gconf, config_doc, task_remap_list); - - g_object_unref (gconf); - - xmlFreeDoc(config_doc); - - if (res != 0) { - g_set_error(err, 0, 0, _("Unable to migrate old settings from evolution/config.xmldb")); - goto fail; - } - } - - if (minor <= 4) { - GSList *migration_dirs, *l; - gchar *path, *local_task_folder; - - setup_progress_dialog (TRUE); - - path = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); - migration_dirs = e_folder_map_local_folders (path, "tasks"); - local_task_folder = g_build_filename (path, "Tasks", NULL); - g_free (path); - - if (personal_source) - migrate_ical_folder_to_source (local_task_folder, personal_source, E_CAL_SOURCE_TYPE_TODO); - - for (l = migration_dirs; l; l = l->next) { - gchar *source_name; - - if (personal_source && !strcmp ((gchar *)l->data, local_task_folder)) - continue; - - source_name = get_source_name (on_this_computer, (gchar *)l->data); - - if (!migrate_ical_folder (l->data, on_this_computer, source_name, E_CAL_SOURCE_TYPE_TODO)) { - /* FIXME: domain/code */ - g_set_error(err, 0, 0, _("Unable to migrate tasks `%s'"), source_name); - g_free(source_name); - goto fail; - } - - g_free (source_name); - } - - g_free (local_task_folder); - - dialog_close (); - } - - if (minor < 5 || (minor == 5 && revision <= 10)) { - gchar *old_path, *new_path; - - old_path = g_build_filename (g_get_home_dir (), "evolution", "local", "Tasks", NULL); - new_path = g_build_filename (tasks_component_peek_base_directory (component), - "local", "system", NULL); - migrate_pilot_data ("tasks", "todo", old_path, new_path); - g_free (new_path); - g_free (old_path); - } - - /* we only need to do this next step if people ran - older versions of 1.5. We need to clear out the - absolute URI's that were assigned to ESources - during one phase of development, as they take - precedent over relative uris (but aren't updated - when editing an ESource). */ - if (minor == 5 && revision <= 11) { - GSList *g; - for (g = e_source_list_peek_groups (tasks_component_peek_source_list (component)); g; g = g->next) { - ESourceGroup *group = g->data; - GSList *s; - - for (s = e_source_group_peek_sources (group); s; s = s->next) { - ESource *source = s->data; - e_source_set_absolute_uri (source, NULL); - } - } - } - } -#endif /* !G_OS_WIN32 */ - e_source_list_sync (tasks_component_peek_source_list (component), NULL); - retval = TRUE; -fail: - if (on_this_computer) - g_object_unref (on_this_computer); - if (on_the_web) - g_object_unref (on_the_web); - if (personal_source) - g_object_unref (personal_source); - - return retval; -} - -/******************************************************************************************************** - * - * MEMOS - * - ********************************************************************************************************/ - -static void -create_memo_sources (MemosComponent *component, - ESourceList *source_list, - ESourceGroup **on_this_computer, - ESourceGroup **on_the_web, - ESource **personal_source) -{ - GSList *groups; - ESourceGroup *group; - gchar *base_uri, *base_uri_proto; - const gchar *base_dir; - - *on_this_computer = NULL; - *on_the_web = NULL; - *personal_source = NULL; - - base_dir = memos_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - if (!*on_this_computer && !strcmp (base_uri_proto, e_source_group_peek_base_uri (group))) - *on_this_computer = g_object_ref (group); - else if (!*on_the_web && !strcmp (WEBCAL_BASE_URI, e_source_group_peek_base_uri (group))) - *on_the_web = g_object_ref (group); - } - } - - if (*on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (*on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - *personal_source = g_object_ref (source); - break; - } - } - } else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - *on_this_computer = group; - } - - if (!*personal_source) { - /* Create the default Person task list */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (*on_this_computer, source, -1); - - if (!calendar_config_get_primary_memos () && !calendar_config_get_memos_selected ()) { - GSList selected; - - calendar_config_set_primary_memos (e_source_peek_uid (source)); - - selected.data = (gpointer)e_source_peek_uid (source); - selected.next = NULL; - calendar_config_set_memos_selected (&selected); - } - - e_source_set_color_spec (source, "#BECEDD"); - *personal_source = source; - } - - if (!*on_the_web) { - /* Create the Webcal source group */ - group = e_source_group_new (_("On The Web"), WEBCAL_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - *on_the_web = group; - } - - g_free (base_uri_proto); - g_free (base_uri); -} - -static gboolean -is_groupwise_account (EAccount *account) -{ - if (account->source->url != NULL) { - return g_str_has_prefix (account->source->url, GROUPWISE_BASE_URI); - } else { - return FALSE; - } -} - -static void -add_gw_esource (ESourceList *source_list, const gchar *group_name, const gchar *source_name, CamelURL *url, GConfClient *client) -{ - ESourceGroup *group; - ESource *source; - GSList *ids, *temp; - GError *error = NULL; - gchar *relative_uri; - const gchar *soap_port; - const gchar * use_ssl; - const gchar *poa_address; - const gchar *offline_sync; - - - poa_address = url->host; - if (!poa_address || strlen (poa_address) ==0) - return; - soap_port = camel_url_get_param (url, "soap_port"); - - if (!soap_port || strlen (soap_port) == 0) - soap_port = "7191"; - - use_ssl = camel_url_get_param (url, "use_ssl"); - offline_sync = camel_url_get_param (url, "offline_sync"); - - group = e_source_group_new (group_name, GROUPWISE_BASE_URI); - if (!e_source_list_add_group (source_list, group, -1)) - return; - relative_uri = g_strdup_printf ("%s@%s/", url->user, poa_address); - - source = e_source_new (source_name, relative_uri); - e_source_set_property (source, "auth", "1"); - e_source_set_property (source, "username", url->user); - e_source_set_property (source, "port", camel_url_get_param (url, "soap_port")); - e_source_set_property (source, "auth-domain", "Groupwise"); - e_source_set_property (source, "use_ssl", use_ssl); - e_source_set_property (source, "offline_sync", offline_sync ? "1" : "0" ); - - e_source_set_color_spec (source, "#EEBC60"); - e_source_group_add_source (group, source, -1); - - ids = gconf_client_get_list (client, CALENDAR_CONFIG_MEMOS_SELECTED_MEMOS, GCONF_VALUE_STRING, &error); - if ( error != NULL ) { - g_warning("%s (%s) %s\n", G_STRLOC, G_STRFUNC, error->message); - g_error_free(error); - } - ids = g_slist_append (ids, g_strdup (e_source_peek_uid (source))); - gconf_client_set_list (client, CALENDAR_CONFIG_MEMOS_SELECTED_MEMOS, GCONF_VALUE_STRING, ids, NULL); - temp = ids; - for (; temp != NULL; temp = g_slist_next (temp)) - g_free (temp->data); - - g_slist_free (ids); - g_object_unref (source); - g_object_unref (group); - g_free (relative_uri); -} - -gboolean -migrate_memos (MemosComponent *component, gint major, gint minor, gint revision, struct _GError **err) -{ - ESourceGroup *on_this_computer = NULL; - ESourceGroup *on_the_web = NULL; - ESource *personal_source = NULL; - ESourceList *source_list = NULL; - gboolean retval = FALSE; - - source_list = memos_component_peek_source_list (component); - - /* we call this unconditionally now - create_groups either - creates the groups/sources or it finds the necessary - groups/sources. */ - create_memo_sources (component, source_list, &on_this_computer, &on_the_web, &personal_source); - - /* Migration for Gw accounts between versions < 2.8 */ - if (major == 2 && minor < 8) { - EAccountList *al; - EAccount *a; - CamelURL *url; - EIterator *it; - GConfClient *gconf_client = gconf_client_get_default (); - al = e_account_list_new (gconf_client); - for (it = e_list_get_iterator((EList *)al); - e_iterator_is_valid(it); - e_iterator_next(it)) { - a = (EAccount *) e_iterator_get(it); - if (!a->enabled || !is_groupwise_account (a)) - continue; - url = camel_url_new (a->source->url, NULL); - add_gw_esource (source_list, a->name, _("Notes"), url, gconf_client); - camel_url_free (url); - } - g_object_unref (al); - g_object_unref (gconf_client); - } - - e_source_list_sync (source_list, NULL); - retval = TRUE; - - if (on_this_computer) - g_object_unref (on_this_computer); - if (on_the_web) - g_object_unref (on_the_web); - if (personal_source) - g_object_unref (personal_source); - - return retval; -} diff --git a/calendar/gui/migration.h b/calendar/gui/migration.h deleted file mode 100644 index 78bc501599..0000000000 --- a/calendar/gui/migration.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef MIGRATION_H -#define MIGRATION_H - -#include <libedataserver/e-source-group.h> -#include "calendar-component.h" -#include "tasks-component.h" -#include "memos-component.h" - -gboolean migrate_calendars (CalendarComponent *component, gint major, gint minor, gint revision, GError **err); -gboolean migrate_tasks (TasksComponent *component, gint major, gint minor, gint revision, GError **err); -gboolean migrate_memos (MemosComponent *component, gint major, gint minor, gint revision, GError **err); -#endif diff --git a/calendar/gui/print.c b/calendar/gui/print.c index eced381faa..7501374cea 100644 --- a/calendar/gui/print.c +++ b/calendar/gui/print.c @@ -43,7 +43,6 @@ #include <e-util/e-print.h> #include <libecal/e-cal-time-util.h> #include <libecal/e-cal-component.h> -#include "calendar-commands.h" #include "calendar-config.h" #include "e-cal-model.h" #include "e-day-view.h" @@ -579,6 +578,7 @@ print_month_small (GtkPrintContext *context, GnomeCalendar *gcal, time_t month, gint titleflags, time_t greystart, time_t greyend, gint bordertitle) { +#if 0 /* KILL-BONOBO */ icaltimezone *zone = calendar_config_get_icaltimezone (); PangoFontDescription *font, *font_bold, *font_normal; time_t now, next; @@ -704,6 +704,7 @@ print_month_small (GtkPrintContext *context, GnomeCalendar *gcal, time_t month, } pango_font_description_free (font_normal); pango_font_description_free (font_bold); +#endif } /* wraps text into the print context, not taking up more than its allowed space */ @@ -1248,6 +1249,7 @@ static void print_day_details (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, double left, double right, double top, double bottom) { +#if 0 /* KILL-BONOBO */ icaltimezone *zone = calendar_config_get_icaltimezone (); EDayViewEvent *event; PangoFontDescription *font; @@ -1366,6 +1368,7 @@ print_day_details (GtkPrintContext *context, GnomeCalendar *gcal, time_t whence, g_array_free (pdi.long_events, TRUE); free_event_array (pdi.events[0]); g_array_free (pdi.events[0], TRUE); +#endif } /* Returns TRUE if the event is a one-day event (i.e. not a long event). */ @@ -1741,6 +1744,7 @@ print_week_summary (GtkPrintContext *context, GnomeCalendar *gcal, gint month, double font_size, double left, double right, double top, double bottom) { +#if 0 /* KILL-BONOBO */ icaltimezone *zone = calendar_config_get_icaltimezone (); EWeekViewEvent *event; struct psinfo psi; @@ -1834,6 +1838,7 @@ print_week_summary (GtkPrintContext *context, GnomeCalendar *gcal, } g_array_free (psi.events, TRUE); g_array_free (spans, TRUE); +#endif } @@ -1965,6 +1970,7 @@ print_todo_details (GtkPrintContext *context, GnomeCalendar *gcal, time_t start, time_t end, double left, double right, double top, double bottom) { +#if 0 /* KILL-BONOBO */ PangoFontDescription *font_summary; double y, yend, x, xend; struct icaltimetype *tt; @@ -2054,6 +2060,7 @@ print_todo_details (GtkPrintContext *context, GnomeCalendar *gcal, } pango_font_description_free (font_summary); +#endif } static void @@ -2395,6 +2402,7 @@ print_calendar_draw_page (GtkPrintOperation *operation, gint page_nr, PrintCalItem *pcali) { +#if 0 /* KILL-BONOBO */ switch (gnome_calendar_get_view (pcali->gcal)) { case GNOME_CAL_DAY_VIEW: print_day_view (context, pcali->gcal, pcali->start); @@ -2409,12 +2417,14 @@ print_calendar_draw_page (GtkPrintOperation *operation, default: g_return_if_reached (); } +#endif } void print_calendar (GnomeCalendar *gcal, GtkPrintOperationAction action, time_t start) { +#if 0 /* KILL-BONOBO */ GtkPrintOperation *operation; PrintCalItem pcali; @@ -2434,6 +2444,7 @@ print_calendar (GnomeCalendar *gcal, GtkPrintOperationAction action, gtk_print_operation_run (operation, action, NULL, NULL); g_object_unref (operation); +#endif } /* returns number of required pages, when page_nr is -1 */ diff --git a/calendar/gui/print.h b/calendar/gui/print.h index 39482b33f2..39d5608222 100644 --- a/calendar/gui/print.h +++ b/calendar/gui/print.h @@ -25,9 +25,7 @@ #ifndef PRINT_H #define PRINT_H -#include "gnome-cal.h" - - +#include "calendar/gui/gnome-cal.h" typedef enum { PRINT_VIEW_DAY, diff --git a/calendar/gui/tasks-component.c b/calendar/gui/tasks-component.c index 7d98e7c305..02783496f6 100644 --- a/calendar/gui/tasks-component.c +++ b/calendar/gui/tasks-component.c @@ -57,28 +57,13 @@ #define CREATE_TASK_ASSIGNED_ID "task-assigned" #define CREATE_TASK_LIST_ID "task-list" -enum DndTargetType { - DND_TARGET_TYPE_CALENDAR_LIST -}; -#define CALENDAR_TYPE "text/calendar" -#define XCALENDAR_TYPE "text/x-calendar" #define WEB_BASE_URI "webcal://" #define PERSONAL_RELATIVE_URI "system" -static GtkTargetEntry drag_types[] = { - { (gchar *) CALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST }, - { (gchar *) XCALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST } -}; -static gint num_drag_types = sizeof(drag_types) / sizeof(drag_types[0]); - #define PARENT_TYPE bonobo_object_get_type () static BonoboObjectClass *parent_class = NULL; -/* Tasks should have their own registry */ -extern ECompEditorRegistry *comp_editor_registry; - - typedef struct { ESourceList *source_list; @@ -89,23 +74,15 @@ typedef struct ETable *table; ETableModel *model; - EInfoLabel *info_label; GtkWidget *source_selector; BonoboControl *view_control; - BonoboControl *sidebar_control; - BonoboControl *statusbar_control; GList *notifications; - EUserCreatableItemsHandler *creatable_items_handler; - - EActivityHandler *activity_handler; } TasksComponentView; struct _TasksComponentPrivate { - gchar *base_directory; - gchar *config_directory; ESourceList *source_list; GSList *source_selection; @@ -117,109 +94,6 @@ struct _TasksComponentPrivate { GList *notifications; }; -static void -ensure_sources (TasksComponent *component) -{ - ESourceList *source_list; - ESourceGroup *on_this_computer; - ESource *personal_source; - gchar *base_uri, *base_uri_proto, base_uri_proto_seventh; - const gchar *base_dir; - - personal_source = NULL; - - if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_TODO, NULL)) { - g_warning ("Could not get task source list from GConf!"); - return; - } - - base_dir = tasks_component_peek_base_directory (component); - base_uri = g_build_filename (base_dir, "local", NULL); - - base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); - if (strlen (base_uri_proto) > 7) { - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ - base_uri_proto_seventh = base_uri_proto[7]; - base_uri_proto[7] = 0; - } else { - base_uri_proto_seventh = -1; - } - - on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); - e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); - - if (base_uri_proto_seventh != -1) { - base_uri_proto[7] = base_uri_proto_seventh; - } - - if (on_this_computer) { - /* make sure "Personal" shows up as a source under - this group */ - GSList *sources = e_source_group_peek_sources (on_this_computer); - GSList *s; - for (s = sources; s; s = s->next) { - ESource *source = E_SOURCE (s->data); - const gchar *relative_uri; - - relative_uri = e_source_peek_relative_uri (source); - if (relative_uri == NULL) - continue; - if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) { - personal_source = source; - break; - } - } - /* Make sure we have the correct base uri. This can change when user's - homedir name changes */ - if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) { - e_source_group_set_base_uri (on_this_computer, base_uri_proto); - - /* *sigh* . We shouldn't need this sync call here as set_base_uri - call results in synching to gconf, but that happens in idle loop - and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ - e_source_list_sync (source_list,NULL); - } - } - - if (personal_source) { - /* ensure the source name is in current locale, not read from configuration */ - e_source_set_name (personal_source, _("Personal")); - } else { - GSList *tasks_selected; - /* Create the default Person addressbook */ - ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI); - e_source_group_add_source (on_this_computer, source, -1); - g_object_unref (source); - - tasks_selected = calendar_config_get_tasks_selected (); - - if (!calendar_config_get_primary_tasks () && !tasks_selected) { - GSList selected; - - calendar_config_set_primary_tasks (e_source_peek_uid (source)); - - selected.data = (gpointer)e_source_peek_uid (source); - selected.next = NULL; - calendar_config_set_tasks_selected (&selected); - } - - if (tasks_selected) { - g_slist_foreach (tasks_selected, (GFunc) g_free, NULL); - g_slist_free (tasks_selected); - } - - e_source_set_color_spec (source, "#BECEDD"); - personal_source = source; - } - - component->priv->source_list = source_list; - - g_object_unref (on_this_computer); - g_free (base_uri_proto); - g_free (base_uri); -} - /* Utility functions. */ /* FIXME Some of these are duplicated from calendar-component.c */ static gboolean @@ -304,62 +178,6 @@ update_uri_for_primary_selection (TasksComponentView *component_view) calendar_config_set_primary_tasks (e_source_peek_uid (source)); } -static void -update_selection (TasksComponentView *component_view) -{ - GSList *selection, *uids_selected, *l; - - /* Get the selection in gconf */ - uids_selected = calendar_config_get_tasks_selected (); - - /* Remove any that aren't there any more */ - selection = e_source_selector_get_selection (E_SOURCE_SELECTOR (component_view->source_selector)); - - for (l = selection; l; l = l->next) { - ESource *source = l->data; - - if (!is_in_uids (uids_selected, source)) - e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - } - - e_source_selector_free_selection (selection); - - /* Make sure the whole selection is there */ - for (l = uids_selected; l; l = l->next) { - gchar *uid = l->data; - ESource *source; - - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - if (source) - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); - - g_free (uid); - } - g_slist_free (uids_selected); -} - -static void -update_primary_selection (TasksComponentView *component_view) -{ - ESource *source = NULL; - gchar *uid; - - uid = calendar_config_get_primary_tasks (); - if (uid) { - source = e_source_list_peek_source_by_uid (component_view->source_list, uid); - g_free (uid); - } - - if (source) { - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } else { - /* Try to create a default if there isn't one */ - source = e_source_list_peek_source_any (component_view->source_list); - if (source) - e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (component_view->source_selector), source); - } -} - /* Callbacks. */ static void copy_task_list_cb (EPopup *ep, EPopupItem *pitem, gpointer data) @@ -531,84 +349,11 @@ primary_source_selection_changed_cb (ESourceSelector *selector, TasksComponentVi } static void -source_added_cb (ETasks *tasks, ESource *source, TasksComponentView *component_view) -{ - e_source_selector_select_source (E_SOURCE_SELECTOR (component_view->source_selector), source); -} - -static void source_removed_cb (ETasks *tasks, ESource *source, TasksComponentView *component_view) { e_source_selector_unselect_source (E_SOURCE_SELECTOR (component_view->source_selector), source); } -static void -set_info (TasksComponentView *component_view) -{ - GString *message = g_string_new (NULL); - gint rows, selected_rows; - - rows = e_table_model_row_count (component_view->model); - selected_rows = e_table_selected_count (component_view->table); - - g_string_append_printf(message, ngettext("%d task", "%d tasks", rows), rows); - if (selected_rows > 0) - g_string_append_printf(message, ngettext(", %d selected", ", %d selected", selected_rows), selected_rows); - - e_info_label_set_info (component_view->info_label, _("Tasks"), message->str); - - g_string_free (message, TRUE); -} - -static void -table_selection_change_cb (ETableModel *etm, TasksComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_changed_cb (ETableModel *etm, TasksComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_rows_inserted_cb (ETableModel *etm, gint row, gint count, TasksComponentView *component_view) -{ - set_info (component_view); -} - -static void -model_rows_deleted_cb (ETableModel *etm, gint row, gint count, TasksComponentView *component_view) -{ - set_info (component_view); -} - -/* Evolution::Component CORBA methods */ - -static void -impl_upgradeFromVersion (PortableServer_Servant servant, - CORBA_short major, - CORBA_short minor, - CORBA_short revision, - CORBA_Environment *ev) -{ - GError *err = NULL; - TasksComponent *component = TASKS_COMPONENT (bonobo_object_from_servant (servant)); - - if (!migrate_tasks(component, major, minor, revision, &err)) { - GNOME_Evolution_Component_UpgradeFailed *failedex; - - failedex = GNOME_Evolution_Component_UpgradeFailed__alloc(); - failedex->what = CORBA_string_dup(_("Failed upgrading tasks.")); - failedex->why = CORBA_string_dup(err->message); - CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UpgradeFailed, failedex); - } - - if (err) - g_error_free(err); -} - static gboolean selector_tree_data_dropped (ESourceSelector *selector, GtkSelectionData *data, @@ -659,19 +404,6 @@ selector_tree_data_dropped (ESourceSelector *selector, } static void -control_activate_cb (BonoboControl *control, gboolean activate, gpointer data) -{ - TasksComponentView *component_view = data; - - if (activate) { - BonoboUIComponent *uic; - uic = bonobo_control_get_ui_component (component_view->view_control); - - e_user_creatable_items_handler_activate (component_view->creatable_items_handler, uic); - } -} - -static void config_create_ecal_changed_cb (GConfClient *client, guint id, GConfEntry *entry, gpointer data) { TasksComponent *component = data; @@ -808,42 +540,11 @@ create_new_todo (TasksComponent *task_component, gboolean is_assigned, TasksComp return TRUE; } -static void -create_local_item_cb (EUserCreatableItemsHandler *handler, const gchar *item_type_name, gpointer data) -{ - TasksComponent *tasks_component = data; - TasksComponentPrivate *priv; - TasksComponentView *component_view = NULL; - GList *l; - - priv = tasks_component->priv; - - for (l = priv->views; l; l = l->next) { - component_view = l->data; - - if (component_view->creatable_items_handler == handler) - break; - - component_view = NULL; - } - - if (strcmp (item_type_name, CREATE_TASK_ID) == 0) { - create_new_todo (tasks_component, FALSE, component_view); - } else if (strcmp (item_type_name, CREATE_TASK_ASSIGNED_ID) == 0) { - create_new_todo (tasks_component, TRUE, component_view); - } else if (strcmp (item_type_name, CREATE_TASK_LIST_ID) == 0) { - calendar_setup_new_task_list (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (component_view->tasks)))); - } -} - static TasksComponentView * create_component_view (TasksComponent *tasks_component) { TasksComponentPrivate *priv; TasksComponentView *component_view; - GtkWidget *selector_scrolled_window, *vbox; - GtkWidget *statusbar_widget; - AtkObject *a11y; priv = tasks_component->priv; @@ -855,66 +556,18 @@ create_component_view (TasksComponent *tasks_component) /* Create sidebar selector */ component_view->source_selector = e_source_selector_new (tasks_component->priv->source_list); - e_source_selector_set_select_new ((ESourceSelector *)component_view->source_selector, TRUE); - a11y = gtk_widget_get_accessible (GTK_WIDGET (component_view->source_selector)); - atk_object_set_name (a11y, _("Task Source Selector")); - - g_signal_connect ( - component_view->source_selector, "data-dropped", - G_CALLBACK (selector_tree_data_dropped), tasks_component); - - gtk_drag_dest_set(component_view->source_selector, GTK_DEST_DEFAULT_ALL, drag_types, - num_drag_types, GDK_ACTION_COPY | GDK_ACTION_MOVE); - - gtk_widget_show (component_view->source_selector); - - selector_scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (selector_scrolled_window), component_view->source_selector); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selector_scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (selector_scrolled_window), - GTK_SHADOW_IN); - gtk_widget_show (selector_scrolled_window); - - component_view->info_label = (EInfoLabel *)e_info_label_new("evolution-tasks"); - e_info_label_set_info(component_view->info_label, _("Tasks"), ""); - gtk_widget_show (GTK_WIDGET (component_view->info_label)); - vbox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX (vbox), GTK_WIDGET (component_view->info_label), FALSE, TRUE, 0); - gtk_box_pack_start(GTK_BOX (vbox), selector_scrolled_window, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - component_view->sidebar_control = bonobo_control_new (vbox); - - /* Create main view */ - component_view->view_control = tasks_control_new (); - if (!component_view->view_control) { - /* FIXME free memory */ - - return NULL; - } + g_signal_connect (component_view->source_selector, "drag-data-received", + G_CALLBACK (selector_tree_drag_data_received), tasks_component); component_view->tasks = (ETasks *) bonobo_control_get_widget (component_view->view_control); component_view->table = e_calendar_table_get_table (e_tasks_get_calendar_table (component_view->tasks)); component_view->model = E_TABLE_MODEL (e_calendar_table_get_model (e_tasks_get_calendar_table (component_view->tasks))); /* This signal is thrown if backends die - we update the selector */ - g_signal_connect (component_view->tasks, "source_added", - G_CALLBACK (source_added_cb), component_view); g_signal_connect (component_view->tasks, "source_removed", G_CALLBACK (source_removed_cb), component_view); - /* Create status bar */ - statusbar_widget = e_task_bar_new (); - component_view->activity_handler = e_activity_handler_new (); - e_activity_handler_attach_task_bar (component_view->activity_handler, E_TASK_BAR (statusbar_widget)); - gtk_widget_show (statusbar_widget); - - component_view->statusbar_control = bonobo_control_new (statusbar_widget); - - e_calendar_table_set_activity_handler (e_tasks_get_calendar_table (component_view->tasks), component_view->activity_handler); - /* connect after setting the initial selections, or we'll get unwanted calls to calendar_control_sensitize_calendar_commands */ g_signal_connect (component_view->source_selector, "selection_changed", @@ -924,25 +577,6 @@ create_component_view (TasksComponent *tasks_component) g_signal_connect (component_view->source_selector, "popup_event", G_CALLBACK (popup_event_cb), component_view); - /* Set up the "new" item handler */ - component_view->creatable_items_handler = e_user_creatable_items_handler_new ("tasks", create_local_item_cb, tasks_component); - g_signal_connect (component_view->view_control, "activate", G_CALLBACK (control_activate_cb), component_view); - - /* We use this to update the component information */ - set_info (component_view); - g_signal_connect (component_view->table, "selection_change", - G_CALLBACK (table_selection_change_cb), component_view); - g_signal_connect (component_view->model, "model_changed", - G_CALLBACK (model_changed_cb), component_view); - g_signal_connect (component_view->model, "model_rows_inserted", - G_CALLBACK (model_rows_inserted_cb), component_view); - g_signal_connect (component_view->model, "model_rows_deleted", - G_CALLBACK (model_rows_deleted_cb), component_view); - - /* Load the selection from the last run */ - update_selection (component_view); - update_primary_selection (component_view); - return component_view; } @@ -963,12 +597,6 @@ destroy_component_view (TasksComponentView *component_view) calendar_config_remove_notification (GPOINTER_TO_UINT (l->data)); g_list_free (component_view->notifications); - if (component_view->creatable_items_handler) - g_object_unref (component_view->creatable_items_handler); - - if (component_view->activity_handler) - g_object_unref (component_view->activity_handler); - g_free (component_view); } @@ -993,38 +621,6 @@ view_destroyed_cb (gpointer data, GObject *where_the_object_was) } } -static GNOME_Evolution_ComponentView -impl_createView (PortableServer_Servant servant, - GNOME_Evolution_ShellView parent, - CORBA_boolean select_item, - CORBA_Environment *ev) -{ - TasksComponent *component = TASKS_COMPONENT (bonobo_object_from_servant (servant)); - TasksComponentPrivate *priv; - TasksComponentView *component_view; - EComponentView *ecv; - - priv = component->priv; - - /* Create the calendar component view */ - component_view = create_component_view (component); - if (!component_view) { - /* FIXME Should we describe the problem in a control? */ - bonobo_exception_set (ev, ex_GNOME_Evolution_Component_Failed); - - return CORBA_OBJECT_NIL; - } - - g_object_weak_ref (G_OBJECT (component_view->view_control), view_destroyed_cb, component); - priv->views = g_list_append (priv->views, component_view); - - /* TODO: Make TasksComponentView just subclass EComponentView */ - ecv = e_component_view_new_controls (parent, "tasks", component_view->sidebar_control, - component_view->view_control, component_view->statusbar_control); - - return BONOBO_OBJREF(ecv); -} - static void impl_handleURI (PortableServer_Servant servant, const gchar *uri, CORBA_Environment *ev) { @@ -1098,45 +694,6 @@ impl_handleURI (PortableServer_Servant servant, const gchar *uri, CORBA_Environm return; } -static GNOME_Evolution_CreatableItemTypeList * -impl__get_userCreatableItems (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - GNOME_Evolution_CreatableItemTypeList *list = GNOME_Evolution_CreatableItemTypeList__alloc (); - - list->_length = 3; - list->_maximum = list->_length; - list->_buffer = GNOME_Evolution_CreatableItemTypeList_allocbuf (list->_length); - - CORBA_sequence_set_release (list, FALSE); - - list->_buffer[0].id = (gchar *) CREATE_TASK_ID; - list->_buffer[0].description = (gchar *) _("New task"); - list->_buffer[0].menuDescription = (gchar *) C_("New", "_Task"); - list->_buffer[0].tooltip = (gchar *) _("Create a new task"); - list->_buffer[0].menuShortcut = 't'; - list->_buffer[0].iconName = (gchar *) "stock_task"; - list->_buffer[0].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[1].id = (gchar *) CREATE_TASK_ASSIGNED_ID; - list->_buffer[1].description = (gchar *) _("New assigned task"); - list->_buffer[1].menuDescription = (gchar *) C_("New", "Assigne_d Task"); - list->_buffer[1].tooltip = (gchar *) _("Create a new assigned task"); - list->_buffer[1].menuShortcut = '\0'; - list->_buffer[1].iconName = (gchar *) "stock_task"; - list->_buffer[1].type = GNOME_Evolution_CREATABLE_OBJECT; - - list->_buffer[2].id = (gchar *) CREATE_TASK_LIST_ID; - list->_buffer[2].description = (gchar *) _("New task list"); - list->_buffer[2].menuDescription = (gchar *) C_("New", "Tas_k list"); - list->_buffer[2].tooltip = (gchar *) _("Create a new task list"); - list->_buffer[2].menuShortcut = '\0'; - list->_buffer[2].iconName = (gchar *) "stock_todo"; - list->_buffer[2].type = GNOME_Evolution_CREATABLE_FOLDER; - - return list; -} - static void impl_requestCreateItem (PortableServer_Servant servant, const CORBA_char *item_type_name, @@ -1210,8 +767,6 @@ impl_finalize (GObject *object) } g_list_free (priv->views); - g_free (priv->base_directory); - g_free (priv->config_directory); g_free (priv); (* G_OBJECT_CLASS (parent_class)->finalize) (object); @@ -1228,9 +783,6 @@ tasks_component_class_init (TasksComponentClass *klass) parent_class = g_type_class_peek_parent (klass); - epv->upgradeFromVersion = impl_upgradeFromVersion; - epv->createView = impl_createView; - epv->_get_userCreatableItems = impl__get_userCreatableItems; epv->requestCreateItem = impl_requestCreateItem; epv->handleURI = impl_handleURI; @@ -1245,50 +797,5 @@ tasks_component_init (TasksComponent *component, TasksComponentClass *klass) priv = g_new0 (TasksComponentPrivate, 1); - priv->base_directory = g_build_filename (e_get_user_data_dir (), "tasks", NULL); - priv->config_directory = g_build_filename (priv->base_directory, "config", NULL); - component->priv = priv; - ensure_sources (component); -} - -/* Public API */ - -TasksComponent * -tasks_component_peek (void) -{ - static TasksComponent *component = NULL; - - if (component == NULL) { - component = g_object_new (tasks_component_get_type (), NULL); - - if (g_mkdir_with_parents (component->priv->config_directory, 0777) != 0) { - g_warning (G_STRLOC ": Cannot create directory %s: %s", - component->priv->config_directory, g_strerror (errno)); - g_object_unref (component); - component = NULL; - } - } - - return component; -} - -const gchar * -tasks_component_peek_base_directory (TasksComponent *component) -{ - return component->priv->base_directory; -} - -const gchar * -tasks_component_peek_config_directory (TasksComponent *component) -{ - return component->priv->config_directory; -} - -ESourceList * -tasks_component_peek_source_list (TasksComponent *component) -{ - return component->priv->source_list; } - -BONOBO_TYPE_FUNC_FULL (TasksComponent, GNOME_Evolution_Component, PARENT_TYPE, tasks_component) diff --git a/calendar/gui/tasks-component.h b/calendar/gui/tasks-component.h index 2a48209896..aae49fc287 100644 --- a/calendar/gui/tasks-component.h +++ b/calendar/gui/tasks-component.h @@ -54,10 +54,5 @@ struct _TasksComponentClass { GType tasks_component_get_type (void); -TasksComponent *tasks_component_peek (void); - -const gchar *tasks_component_peek_base_directory (TasksComponent *component); -const gchar *tasks_component_peek_config_directory (TasksComponent *component); -ESourceList *tasks_component_peek_source_list (TasksComponent *component); #endif /* _TASKS_COMPONENT_H_ */ diff --git a/calendar/gui/tasks-control.c b/calendar/gui/tasks-control.c index e5109da7a0..5fa7f7a541 100644 --- a/calendar/gui/tasks-control.c +++ b/calendar/gui/tasks-control.c @@ -53,36 +53,15 @@ static void tasks_control_activate_cb (BonoboControl *control, gboolean activate, gpointer user_data); -static void tasks_control_open_task_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); static void tasks_control_new_task_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path); -static void tasks_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); static void tasks_control_complete_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path); static void tasks_control_purge_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path); -static void tasks_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); -static void tasks_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path); static void tasks_control_assign_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path); @@ -91,68 +70,6 @@ static void tasks_control_forward_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path); -static void tasks_control_view_preview (BonoboUIComponent *uic, - const gchar *path, - Bonobo_UIComponent_EventType type, - const gchar *state, - gpointer data); - -struct focus_changed_data { - BonoboControl *control; - ETasks *tasks; -}; - -static gboolean tasks_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct focus_changed_data *fc_data); - -BonoboControl * -tasks_control_new (void) -{ - BonoboControl *control; - GtkWidget *tasks, *preview; - struct focus_changed_data *fc_data; - - tasks = e_tasks_new (); - if (!tasks) - return NULL; - gtk_widget_show (tasks); - - control = bonobo_control_new (tasks); - if (!control) { - gtk_widget_destroy (tasks); - g_message ("control_factory_fn(): could not create the control!"); - return NULL; - } - - g_signal_connect (control, "activate", G_CALLBACK (tasks_control_activate_cb), tasks); - - fc_data = g_new0 (struct focus_changed_data, 1); - fc_data->control = control; - fc_data->tasks = E_TASKS (tasks); - - preview = e_cal_component_preview_get_html (E_CAL_COMPONENT_PREVIEW (e_tasks_get_preview (fc_data->tasks))); - g_object_set_data_full (G_OBJECT (preview), "tasks-ctrl-fc-data", fc_data, g_free); - g_signal_connect (preview, "focus-in-event", G_CALLBACK (tasks_control_focus_changed), fc_data); - g_signal_connect (preview, "focus-out-event", G_CALLBACK (tasks_control_focus_changed), fc_data); - - return control; -} - - -static void -tasks_control_activate_cb (BonoboControl *control, - gboolean activate, - gpointer user_data) -{ - ETasks *tasks; - - tasks = E_TASKS (user_data); - - if (activate) - tasks_control_activate (control, tasks); - else - tasks_control_deactivate (control, tasks); -} - struct _tasks_sensitize_item { const gchar *command; guint32 enable; @@ -267,38 +184,14 @@ tasks_control_focus_changed (GtkWidget *widget, GdkEventFocus *event, struct foc } static BonoboUIVerb verbs [] = { - BONOBO_UI_VERB ("TasksOpenTask", tasks_control_open_task_cmd), BONOBO_UI_VERB ("TasksNewTask", tasks_control_new_task_cmd), - BONOBO_UI_VERB ("TasksCut", tasks_control_cut_cmd), - BONOBO_UI_VERB ("TasksCopy", tasks_control_copy_cmd), - BONOBO_UI_VERB ("TasksPaste", tasks_control_paste_cmd), - BONOBO_UI_VERB ("TasksDelete", tasks_control_delete_cmd), BONOBO_UI_VERB ("TasksMarkComplete", tasks_control_complete_cmd), BONOBO_UI_VERB ("TasksPurge", tasks_control_purge_cmd), - BONOBO_UI_VERB ("TasksPrint", tasks_control_print_cmd), - BONOBO_UI_VERB ("TasksPrintPreview", tasks_control_print_preview_cmd), BONOBO_UI_VERB ("TasksAssign", tasks_control_assign_cmd), BONOBO_UI_VERB ("TasksForward", tasks_control_forward_cmd), BONOBO_UI_VERB_END }; -static EPixmap pixmaps [] = { - E_PIXMAP ("/commands/TasksCopy", "edit-copy", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksCut", "edit-cut", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksDelete", "edit-delete", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksForward", "mail-forward", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksPaste", "edit-paste", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksPrint", "document-print", GTK_ICON_SIZE_MENU), - E_PIXMAP ("/commands/TasksPrintPreview", "document-print-preview", GTK_ICON_SIZE_MENU), - - E_PIXMAP ("/Toolbar/Cut", "edit-cut", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Copy", "edit-copy", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Paste", "edit-paste", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Print", "document-print", GTK_ICON_SIZE_LARGE_TOOLBAR), - E_PIXMAP ("/Toolbar/Delete", "edit-delete", GTK_ICON_SIZE_LARGE_TOOLBAR), - - E_PIXMAP_END -}; void tasks_control_activate (BonoboControl *control, ETasks *tasks) { @@ -332,8 +225,6 @@ tasks_control_activate (BonoboControl *control, ETasks *tasks) NULL); g_free (xmlfile); - e_pixmaps_update (uic, pixmaps); - e_tasks_setup_view_menus (tasks, uic); /* Signals from the tasks widget; also sensitize the menu items as appropriate */ @@ -375,16 +266,6 @@ tasks_control_deactivate (BonoboControl *control, ETasks *tasks) bonobo_ui_component_unset_container (uic, NULL); } -static void tasks_control_open_task_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - e_tasks_open_task (tasks); -} - static void tasks_control_new_task_cmd (BonoboUIComponent *uic, gpointer data, @@ -397,65 +278,6 @@ tasks_control_new_task_cmd (BonoboUIComponent *uic, } static void -tasks_control_cut_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_cut_clipboard (cal_table); -} - -static void -tasks_control_copy_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - GtkWidget *preview; - - tasks = E_TASKS (data); - - - preview = e_cal_component_preview_get_html (E_CAL_COMPONENT_PREVIEW (e_tasks_get_preview (tasks))); - if (preview && GTK_WIDGET_VISIBLE (preview) && GTK_WIDGET_HAS_FOCUS (preview)) { - /* copy selected text in a preview when that's shown and focused */ - gtk_html_copy (GTK_HTML (preview)); - } else { - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_copy_clipboard (cal_table); - } -} - -static void -tasks_control_paste_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - e_calendar_table_paste_clipboard (cal_table); -} - -static void -tasks_control_delete_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - - tasks = E_TASKS (data); - e_tasks_delete_selected (tasks); -} - -static void tasks_control_complete_cmd (BonoboUIComponent *uic, gpointer data, const gchar *path) @@ -511,87 +333,3 @@ tasks_control_purge_cmd (BonoboUIComponent *uic, if (confirm_purge (tasks)) e_tasks_delete_completed (tasks); } - -/* File/Print callback */ -static void -tasks_control_print_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks = E_TASKS (data); - ETable *table; - - table = e_calendar_table_get_table ( - E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks))); - - print_table ( - table, _("Print Tasks"), _("Tasks"), - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); -} - -static void -tasks_control_print_preview_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks = E_TASKS (data); - ETable *table; - - table = e_calendar_table_get_table ( - E_CALENDAR_TABLE (e_tasks_get_calendar_table (tasks))); - - print_table ( - table, _("Print Tasks"), _("Tasks"), - GTK_PRINT_OPERATION_ACTION_PREVIEW); -} - -static void -tasks_control_assign_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - ECalModelComponent *comp_data; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data) - e_calendar_table_open_task (cal_table, comp_data->client, comp_data->icalcomp, TRUE); -} - -static void -tasks_control_forward_cmd (BonoboUIComponent *uic, - gpointer data, - const gchar *path) -{ - ETasks *tasks; - ECalendarTable *cal_table; - ECalModelComponent *comp_data; - - tasks = E_TASKS (data); - cal_table = e_tasks_get_calendar_table (tasks); - comp_data = e_calendar_table_get_selected_comp (cal_table); - if (comp_data) { - ECalComponent *comp; - comp = e_cal_component_new (); - e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp)); - itip_send_comp (E_CAL_COMPONENT_METHOD_PUBLISH, comp, comp_data->client, NULL, NULL, NULL, TRUE); - g_object_unref (comp); - } -} - -static void -tasks_control_view_preview (BonoboUIComponent *uic, const gchar *path, Bonobo_UIComponent_EventType type, const gchar *state, gpointer data) -{ - ETasks *tasks; - - if (type != Bonobo_UIComponent_STATE_CHANGED) - return; - - tasks = E_TASKS (data); - - calendar_config_set_preview_state (state[0] != '0'); - e_tasks_show_preview (tasks, state[0] != '0'); -} |