diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-26 10:42:23 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-26 10:42:23 +0800 |
commit | cb78b84aecf1c011e0b013cc94a079e2dc0eabbc (patch) | |
tree | e6fbbd6a08aa152bbb79f3ebd9eee80ae6c35f7c /calendar | |
parent | 9515b98403f2f7ef77dc6c51f82505fccef08c2b (diff) | |
download | gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar.gz gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar.bz2 gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar.lz gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar.xz gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.tar.zst gsoc2013-evolution-cb78b84aecf1c011e0b013cc94a079e2dc0eabbc.zip |
Tasks and memos progress. Hoping to merge ECalendarTable and EMemoTable,
or at least make EMemoTable derived from ECalendarTable. Possibly do the
same with other calendar/memo class pairs.
svn path=/branches/kill-bonobo/; revision=36454
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/gui/e-calendar-table.c | 418 | ||||
-rw-r--r-- | calendar/gui/e-calendar-table.h | 21 | ||||
-rw-r--r-- | calendar/gui/e-memo-table.c | 644 | ||||
-rw-r--r-- | calendar/gui/e-memo-table.h | 19 | ||||
-rw-r--r-- | calendar/gui/e-memos.c | 52 | ||||
-rw-r--r-- | calendar/gui/e-tasks.c | 103 | ||||
-rw-r--r-- | calendar/modules/e-memo-shell-content.c | 8 | ||||
-rw-r--r-- | calendar/modules/e-memo-shell-view-actions.c | 207 | ||||
-rw-r--r-- | calendar/modules/e-memo-shell-view-private.c | 104 | ||||
-rw-r--r-- | calendar/modules/e-memo-shell-view-private.h | 11 | ||||
-rw-r--r-- | calendar/modules/e-task-shell-view-private.c | 271 | ||||
-rw-r--r-- | calendar/modules/e-task-shell-view-private.h | 18 |
12 files changed, 964 insertions, 912 deletions
diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index ed254d0680..61c43bae26 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -71,44 +71,32 @@ struct _ECalendarTablePrivate { gpointer shell_view; /* weak pointer */ +}; - EActivity *activity; +enum { + PROP_0, + PROP_SHELL_VIEW }; -enum TargetType{ +enum { + OPEN_COMPONENT, + POPUP_EVENT, + STATUS_MESSAGE, + USER_CREATED, + LAST_SIGNAL +}; + +enum { TARGET_TYPE_VCALENDAR }; static GtkTargetEntry target_types[] = { - { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR }, - { "text/calendar", 0, TARGET_TYPE_VCALENDAR } + { "text/calendar", 0, TARGET_TYPE_VCALENDAR }, + { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR } }; static guint n_target_types = G_N_ELEMENTS (target_types); -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, void *data); @@ -116,14 +104,9 @@ static void mark_as_complete_cb (EPopup *ep, EPopupItem *pitem, void *data); static void hide_completed_rows (ECalModel *model, GList *clients_list, char *hide_sexp, GPtrArray *comp_objects); static void show_completed_rows (ECalModel *model, GList *clients_list, char *show_sexp, GPtrArray *comp_objects); -/* Signal IDs */ -enum { - USER_CREATED, - LAST_SIGNAL -}; - 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 @@ -132,7 +115,26 @@ static const char* 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) +{ + g_signal_emit (cal_table, signals[OPEN_COMPONENT], 0, comp_data); +} + +static void +calendar_table_emit_popup_event (ECalendarTable *cal_table, + GdkEvent *event) +{ + g_signal_emit (cal_table, signals[POPUP_EVENT], 0, event); +} + +static void +calendar_table_emit_status_message (ECalendarTable *cal_table, + const gchar *message) +{ + g_signal_emit (cal_table, signals[STATUS_MESSAGE], 0, message); +} static void calendar_table_emit_user_created (ECalendarTable *cal_table) @@ -140,6 +142,66 @@ calendar_table_emit_user_created (ECalendarTable *cal_table) g_signal_emit (cal_table, signals[USER_CREATED], 0); } +static gint +calendar_table_date_compare_cb (gconstpointer a, + gconstpointer b) +{ + ECellDateEditValue *dv1 = (ECellDateEditValue *) a; + ECellDateEditValue *dv2 = (ECellDateEditValue *) b; + struct icaltimetype tt; + + /* First check if either is NULL. NULL dates sort last. */ + if (!dv1 || !dv2) { + if (dv1 == dv2) + return 0; + else if (dv1) + return -1; + else + return 1; + } + + /* Copy the 2nd value and convert it to the same timezone as the + first. */ + tt = dv2->tt; + + icaltimezone_convert_time (&tt, dv2->zone, dv1->zone); + + /* Now we can compare them. */ + + return icaltime_compare (dv1->tt, tt); +} + +static void +calendar_table_double_click_cb (ECalendarTable *cal_table, + gint row, + gint col, + GdkEvent *event) +{ + ECalModelComponent *comp_data; + + comp_data = e_cal_model_get_component_at (cal_table->model, row); + calendar_table_emit_open_component (cal_table, comp_data); +} + +static gboolean +calendar_table_popup_menu_cb (ECalendarTable *cal_table) +{ + calendar_table_emit_popup_event (cal_table, NULL); + + return TRUE; +} + +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 TRUE; +} + static void calendar_table_set_shell_view (ECalendarTable *cal_table, EShellView *shell_view) @@ -199,13 +261,6 @@ calendar_table_dispose (GObject *object) cal_table->model = NULL; } - if (cal_table->priv->activity != NULL) { - /* XXX Activity is not cancellable. */ - e_activity_complete (cal_table->priv->activity); - g_object_unref (cal_table->priv->activity); - cal_table->priv->activity = NULL; - } - /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -219,16 +274,48 @@ calendar_table_class_init (ECalendarTableClass *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; - 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); + 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); + + signal[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_STATUS_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_STRUCT_OFFSET (ECalendarTableClass, user_created), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); } @@ -236,8 +323,8 @@ calendar_table_class_init (ECalendarTableClass *class) static void calendar_table_init (ECalendarTable *cal_table) { - GtkWidget *table; - ETable *e_table; + GtkWidget *widget; + ETable *table; ECell *cell, *popup_cell; ETableExtras *extras; gint i; @@ -263,7 +350,7 @@ calendar_table_init (ECalendarTable *cal_table) * 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, @@ -276,7 +363,7 @@ 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, @@ -285,13 +372,13 @@ 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. @@ -299,7 +386,7 @@ 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, @@ -416,7 +503,7 @@ 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); e_table_extras_add_compare (extras, "priority-compare", @@ -441,34 +528,33 @@ 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 (cal_table->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); */ - - 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); - - - 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); + table = e_table_scrolled_get_table (E_TABLE_SCROLLED (widget)); + g_signal_connect_swapped ( + table, "double-click", + G_CALLBACK (calendar_table_double_click), cal_table); + g_signal_connect_swapped ( + table, "popup-menu", + G_CALLBACK (calendar_table_popup_menu), cal_table); + g_signal_connect_swapped ( + table, "right-click", + G_CALLBACK (calendar_table_right_click), cal_table); + g_signal_connect_swapped ( + table, "query-tooltip", + G_CALLBACK (calendar_table_query_tooltip_cb), cal_table); + gtk_widget_set_has_tooltip (GTK_WIDGET (table), TRUE); - a11y = gtk_widget_get_accessible ((GtkWidget *)e_table); + a11y = gtk_widget_get_accessible (GTK_WIDGET (table)); if (a11y) atk_object_set_name (a11y, _("Tasks")); } @@ -526,34 +612,6 @@ e_calendar_table_get_shell_view (ECalendarTable *cal_table) } static gint -date_compare_cb (gconstpointer a, gconstpointer b) -{ - ECellDateEditValue *dv1 = (ECellDateEditValue *) a; - ECellDateEditValue *dv2 = (ECellDateEditValue *) b; - struct icaltimetype tt; - - /* First check if either is NULL. NULL dates sort last. */ - if (!dv1 || !dv2) { - if (dv1 == dv2) - return 0; - else if (dv1) - return -1; - else - return 1; - } - - /* Copy the 2nd value and convert it to the same timezone as the - first. */ - tt = dv2->tt; - - icaltimezone_convert_time (&tt, dv2->zone, dv1->zone); - - /* Now we can compare them. */ - - return icaltime_compare (dv1->tt, tt); -} - -static gint percent_compare_cb (gconstpointer a, gconstpointer b) { int percent1 = GPOINTER_TO_INT (a); @@ -860,10 +918,13 @@ e_calendar_table_get_model (ECalendarTable *cal_table) ETable * e_calendar_table_get_table (ECalendarTable *cal_table) { - g_return_val_if_fail (cal_table != NULL, NULL); + ETableScrolled *table_scrolled; + g_return_val_if_fail (E_IS_CALENDAR_TABLE (cal_table), NULL); - return e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + table_scrolled = E_TABLE_SCROLLED (cal_table->etable); + + return e_table_scrolled_get_table (table_scrolled); } void @@ -1352,43 +1413,6 @@ e_calendar_table_paste_clipboard (ECalendarTable *cal_table) 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 char *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, int row) @@ -1741,45 +1765,6 @@ e_calendar_table_show_popup_menu (ETable *table, 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); -} - -static gboolean -e_calendar_table_on_popup_menu (GtkWidget *widget, gpointer data) -{ - ETable *table = E_TABLE(widget); - g_return_val_if_fail(table, FALSE); - - 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; -} - static void hide_completed_rows (ECalModel *model, GList *clients_list, char *hide_sexp, GPtrArray *comp_objects) { @@ -1929,59 +1914,6 @@ static char *test[] = { #endif -void -e_calendar_table_set_status_message (ECalendarTable *cal_table, - const gchar *message, - gdouble percent) -{ - EActivity *activity; - EShellView *shell_view; - - g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - - activity = cal_table->priv->activity; - shell_view = e_calendar_table_get_shell_view (cal_table); - - if (message == NULL || *message == '\0') { - if (activity != NULL) { - e_activity_complete (activity); - g_object_unref (activity); - cal_table->priv->activity = NULL; - } - - } else if (activity == NULL) { - activity = e_activity_new (message); - cal_able->priv->activity = activity; - e_activity_set_percent (activity, percent); - e_shell_view_add_activity (shell_view, activity); - - } else { - e_activity_set_percent (activity, percent); - e_activity_set_primary_text (activity, message); - } - - 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) { - cal_table->activity_id = e_activity_handler_operation_started ( - cal_table->activity_handler, message, TRUE); - } 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 6647572e89..4394d24c03 100644 --- a/calendar/gui/e-calendar-table.h +++ b/calendar/gui/e-calendar-table.h @@ -76,16 +76,23 @@ struct _ECalendarTable { * 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); + 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); @@ -109,14 +116,6 @@ void e_calendar_table_load_state (ECalendarTable *cal_table, void e_calendar_table_save_state (ECalendarTable *cal_table, gchar *filename); -void e_calendar_table_set_status_message - (ECalendarTable *cal_table, - const gchar *message, - gdouble 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); diff --git a/calendar/gui/e-memo-table.c b/calendar/gui/e-memo-table.c index 8f495a000d..75b3eccd6e 100644 --- a/calendar/gui/e-memo-table.c +++ b/calendar/gui/e-memo-table.c @@ -37,7 +37,6 @@ #include <glib/gi18n.h> #include <glib/gstdio.h> #include <gdk/gdkkeysyms.h> -#include <libgnome/gnome-url.h> #include <widgets/misc/e-gui-utils.h> #include <table/e-cell-checkbox.h> #include <table/e-cell-toggle.h> @@ -65,8 +64,6 @@ struct _EMemoTablePrivate { gpointer shell_view; /* weak pointer */ - - EActivity *activity; }; enum { @@ -74,53 +71,32 @@ enum { PROP_SHELL_VIEW }; -enum TargetType{ +enum { + OPEN_COMPONENT, + POPUP_EVENT, + STATUS_MESSAGE, + USER_CREATED, + LAST_SIGNAL +}; + +enum { TARGET_TYPE_VCALENDAR }; static GtkTargetEntry target_types[] = { - { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR }, - { "text/calendar", 0, TARGET_TYPE_VCALENDAR } + { "text/calendar", 0, TARGET_TYPE_VCALENDAR }, + { "text/x-calendar", 0, TARGET_TYPE_VCALENDAR } }; static guint n_target_types = G_N_ELEMENTS (target_types); - -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 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 @@ -129,7 +105,26 @@ static const char* icon_names[E_MEMO_MODEL_NUM_ICONS] = { }; static GdkPixbuf* icon_pixbufs[E_MEMO_MODEL_NUM_ICONS] = { NULL }; -static GdkAtom clipboard_atom = GDK_NONE; +static void +memo_table_emit_open_component (EMemoTable *memo_table, + ECalModelComponent *comp_data) +{ + g_signal_emit (memo_table, signals[OPEN_COMPONENT], 0, comp_data); +} + +static void +memo_table_emit_popup_event (EMemoTable *memo_table, + GdkEvent *event) +{ + g_signal_emit (memo_table, signals[POPUP_EVENT], 0, event); +} + +static void +memo_table_emit_status_message (EMemoTable *memo_table, + const gchar *message) +{ + g_signal_emit (memo_table, signals[STATUS_MESSAGE], 0, message); +} static void memo_table_emit_user_created (EMemoTable *memo_table) @@ -138,7 +133,8 @@ memo_table_emit_user_created (EMemoTable *memo_table) } static gint -memo_table_date_compare_cb (gconstpointer a, gconstpointer b) +memo_table_date_compare_cb (gconstpointer a, + gconstpointer b) { ECellDateEditValue *dv1 = (ECellDateEditValue *) a; ECellDateEditValue *dv2 = (ECellDateEditValue *) b; @@ -166,6 +162,37 @@ memo_table_date_compare_cb (gconstpointer a, gconstpointer b) } static void +memo_table_double_click_cb (EMemoTable *memo_table, + gint row, + gint col, + GdkEvent *event) +{ + ECalModelComponent *comp_data; + + comp_data = e_cal_model_get_component_at (memo_table->model, row); + memo_table_emit_open_component (memo_table, comp_data); +} + +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; +} + +static void memo_table_set_shell_view (EMemoTable *memo_table, EShellView *shell_view) { @@ -224,13 +251,6 @@ memo_table_dispose (GObject *object) memo_table->model = NULL; } - if (memo_table->priv->activity != NULL) { - /* XXX Activity is not cancellable. */ - e_activity_complete (memo_table->priv->activity); - g_object_unref (memo_table->priv->activity); - memo_table->priv->activity = NULL; - } - /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -248,14 +268,44 @@ memo_table_class_init (EMemoTableClass *class) object_class->get_property = memo_table_get_property; object_class->dispose = memo_table_dispose; - signals[USER_CREATED] = - g_signal_new ("user_created", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EMemoTableClass, user_created), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + 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); } @@ -263,8 +313,8 @@ memo_table_class_init (EMemoTableClass *class) static void memo_table_init (EMemoTable *memo_table) { - GtkWidget *table; - ETable *e_table; + GtkWidget *widget; + ETable *table; ECell *cell, *popup_cell; ETableExtras *extras; gint i; @@ -288,33 +338,29 @@ memo_table_init (EMemoTable *memo_table) * 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", - memo_table_date_compare_cb); + e_table_extras_add_compare ( + extras, "date-compare", memo_table_date_compare_cb); /* Create pixmaps */ @@ -324,37 +370,34 @@ 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 (memo_table->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); */ - - 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); - - - 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); + 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, "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); - a11y = gtk_widget_get_accessible (GTK_WIDGET(e_table)); + a11y = gtk_widget_get_accessible (GTK_WIDGET (table)); if (a11y) atk_object_set_name (a11y, _("Memos")); } @@ -441,20 +484,13 @@ e_memo_table_get_model (EMemoTable *memo_table) 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 @@ -479,7 +515,8 @@ get_selected_comp (EMemoTable *memo_table) ETable *etable; int row; - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); + etable = e_memo_table_get_table (memo_table); + if (e_table_selected_count (etable) != 1) return NULL; @@ -511,30 +548,17 @@ add_uid_cb (int model_row, gpointer data) 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); for (l = objs; l; l = l->next) { ECalModelComponent *comp_data = (ECalModelComponent *) l->data; @@ -546,7 +570,7 @@ 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); g_slist_free (objs); } @@ -563,7 +587,17 @@ delete_selected_components (EMemoTable *memo_table) GSList * e_memo_table_get_selected (EMemoTable *memo_table) { - return get_selected_objects(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; } /** @@ -583,7 +617,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) @@ -694,7 +728,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 (memo_table->tmp_vcal); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (memo_table), clipboard_atom); @@ -721,6 +755,7 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) ECalComponent *comp; ECal *client; icalcomponent_kind kind; + const gchar *status_message; g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); @@ -740,7 +775,8 @@ clipboard_get_calendar_data (EMemoTable *memo_table, const gchar *text) client = e_cal_model_get_default_client (memo_table->model); - e_memo_table_set_status_message (memo_table, _("Updating objects")); + status_message = _("Updating objects"); + memo_table_emit_status_message (memo_table, _("Updating objects")); if (kind == ICAL_VCALENDAR_COMPONENT) { icalcomponent_kind child_kind; @@ -783,7 +819,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); } static void @@ -792,7 +828,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; @@ -827,332 +863,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 char *uid; - - uid = icalcomponent_get_uid (comp_data->icalcomp); - - medit = comp_editor_find_instance (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); - } - - gtk_window_present (GTK_WINDOW (medit)); -} - -/* Opens the task in the specified row */ -static void -open_memo_by_row (EMemoTable *memo_table, int 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, void *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, void *data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - ECalModelComponent *comp_data; - char *filename; - char *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, void *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, void *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, void *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, void *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, void *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); - - g_object_unref (comp); - } -} - -/* Opens the URL of the memo */ -static void -open_url_cb (EPopup *ep, EPopupItem *pitem, void *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; - - gnome_url_show (icalproperty_get_url (prop), NULL); -} - -/* Callback for the "delete tasks" menu item */ -static void -delete_cb (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMemoTable *memo_table = E_MEMO_TABLE (data); - - e_memo_table_delete_selected (memo_table); -} - -static EPopupItem memos_popup_items [] = { - { E_POPUP_ITEM, "00.open", N_("_Open"), e_memo_table_on_open_memo, NULL, GTK_STOCK_OPEN, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, "05.openweb", N_("Open _Web Page"), open_url_cb, NULL, NULL, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_HASURL }, - { E_POPUP_ITEM, "10.saveas", N_("_Save As..."), e_memo_table_on_save_as, NULL, GTK_STOCK_SAVE_AS, E_CAL_POPUP_SELECT_ONE }, - { E_POPUP_ITEM, "20.print", N_("P_rint..."), e_memo_table_on_print_memo, NULL, GTK_STOCK_PRINT, E_CAL_POPUP_SELECT_ONE }, - - { E_POPUP_BAR, "30.bar" }, - - { E_POPUP_ITEM, "40.cut", N_("C_ut"), e_memo_table_on_cut, NULL, GTK_STOCK_CUT, 0, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, "50.copy", N_("_Copy"), e_memo_table_on_copy, NULL, GTK_STOCK_COPY, 0, 0 }, - { E_POPUP_ITEM, "60.paste", N_("_Paste"), e_memo_table_on_paste, NULL, GTK_STOCK_PASTE, 0, E_CAL_POPUP_SELECT_EDITABLE }, - - { E_POPUP_BAR, "70.bar" }, - - { E_POPUP_ITEM, "80.forward", N_("_Forward as iCalendar"), e_memo_table_on_forward, NULL, "mail-forward", E_CAL_POPUP_SELECT_ONE }, - - { E_POPUP_BAR, "90.bar" }, - - { E_POPUP_ITEM, "a0.delete", N_("_Delete"), delete_cb, NULL, GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_ONE, E_CAL_POPUP_SELECT_EDITABLE }, - { E_POPUP_ITEM, "b0.deletemany", N_("_Delete Selected Memos"), delete_cb, NULL, GTK_STOCK_DELETE, E_CAL_POPUP_SELECT_MANY, E_CAL_POPUP_SELECT_EDITABLE }, -}; - -static void -emt_popup_free(EPopup *ep, GSList *items, void *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; - int 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. @@ -1190,31 +938,3 @@ static char *test[] = { }; #endif - -void -e_memo_table_set_status_message (EMemoTable *memo_table, - const gchar *message) -{ - EActivity *activity; - EShellView *shell_view; - - g_return_if_fail (E_IS_MEMO_TABLE (memo_table)); - - activity = memo_table->priv->activity; - shell_view = e_memo_table_get_shell_view (memo_table); - - if (message == NULL || *message == '\0') { - if (activity != NULL) { - e_activity_complete (activity); - g_object_unref (activity); - memo_table->priv->activity = NULL; - } - - } else if (activity == NULL) { - activity = e_activity_new (message); - memo_table->priv->activity = activity; - e_shell_view_add_activity (shell_view, activity); - - } else - e_activity_set_primary_text (activity, message); -} diff --git a/calendar/gui/e-memo-table.h b/calendar/gui/e-memo-table.h index 2c31ee5b02..fcd6b6ee97 100644 --- a/calendar/gui/e-memo-table.h +++ b/calendar/gui/e-memo-table.h @@ -85,17 +85,21 @@ struct _EMemoTable { 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); + void (*user_created) (EMemoTable *memo_table); }; - GType e_memo_table_get_type (void); GtkWidget * e_memo_table_new (EShellView *shell_view); 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_open_selected (EMemoTable *memo_table); void e_memo_table_delete_selected (EMemoTable *memo_table); GSList * e_memo_table_get_selected (EMemoTable *memo_table); @@ -107,12 +111,9 @@ 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); + const gchar *filename); void e_memo_table_save_state (EMemoTable *memo_table, - gchar *filename); - -void e_memo_table_set_status_message (EMemoTable *memo_table, - const gchar *message); + const gchar *filename); G_END_DECLS diff --git a/calendar/gui/e-memos.c b/calendar/gui/e-memos.c index 5e162f8a28..ed65be2e32 100644 --- a/calendar/gui/e-memos.c +++ b/calendar/gui/e-memos.c @@ -630,58 +630,6 @@ open_ecal (EMemos *memos, ECal *cal, gboolean only_if_exists, open_func of) } gboolean -e_memos_add_memo_source (EMemos *memos, ESource *source) -{ - EMemosPrivate *priv; - ECal *client; - const char *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; diff --git a/calendar/gui/e-tasks.c b/calendar/gui/e-tasks.c index 732f031c1c..e32b8ca66a 100644 --- a/calendar/gui/e-tasks.c +++ b/calendar/gui/e-tasks.c @@ -880,57 +880,6 @@ set_status_message (ETasks *tasks, const char *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 char *message, gpointer data) -{ - ETasks *tasks; - GtkWidget *dialog; - char *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) @@ -1137,58 +1086,6 @@ e_tasks_show_preview (ETasks *tasks, gboolean state) } gboolean -e_tasks_add_todo_source (ETasks *tasks, ESource *source) -{ - ETasksPrivate *priv; - ECal *client; - const char *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) { ETasksPrivate *priv; diff --git a/calendar/modules/e-memo-shell-content.c b/calendar/modules/e-memo-shell-content.c index a3a3104b47..a7b50fc967 100644 --- a/calendar/modules/e-memo-shell-content.c +++ b/calendar/modules/e-memo-shell-content.c @@ -90,15 +90,13 @@ memo_shell_content_display_view_cb (EMemoShellContent *memo_shell_content, GalView *gal_view) { EMemoTable *memo_table; - ETableScrolled *table_scrolled; ETable *table; if (!GAL_IS_VIEW_ETABLE (gal_view)) return; memo_table = E_MEMO_TABLE (memo_shell_content->priv->memo_table); - table_scrolled = E_TABLE_SCROLLED (memo_table->etable); - table = e_table_scrolled_get_table (table_scrolled); + table = e_memo_table_get_table (memo_table); gal_view_etable_attach_table (GAL_VIEW_ETABLE (gal_view), table); } @@ -184,7 +182,6 @@ memo_shell_content_model_row_changed_cb (EMemoShellContent *memo_shell_content, { ECalModelComponent *comp_data; EMemoTable *memo_table; - ETableScrolled *table_scrolled; ETable *table; const gchar *current_uid; const gchar *uid; @@ -202,8 +199,7 @@ memo_shell_content_model_row_changed_cb (EMemoShellContent *memo_shell_content, return; memo_table = E_MEMO_TABLE (memo_shell_content->priv->memo_table); - table_scrolled = E_TABLE_SCROLLED (memo_table->etable); - table = e_table_scrolled_get_table (table_scrolled); + table = e_memo_table_get_table (memo_table); memo_shell_content_cursor_change_cb (memo_shell_content, 0, table); } diff --git a/calendar/modules/e-memo-shell-view-actions.c b/calendar/modules/e-memo-shell-view-actions.c index e20ec46949..29dacabafc 100644 --- a/calendar/modules/e-memo-shell-view-actions.c +++ b/calendar/modules/e-memo-shell-view-actions.c @@ -82,6 +82,35 @@ action_memo_delete_cb (GtkAction *action, } static void +action_memo_forward_cb (GtkAction *action, + EMemoShellView *memo_shell_view) +{ + EMemoShellContent *memo_shell_content; + EMemoTable *memo_table; + ECalModelComponent *comp_data; + ECalComponent *comp; + icalcomponent *clone; + ECalComponentItipMethod method; + GSList *list; + + memo_shell_content = memo_shell_view->priv->memo_shell_content; + memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); + + list = e_memo_table_get_selected (memo_table); + g_return_if_fail (list != NULL); + comp_data = list->data; + g_slist_free (list); + + /* XXX We only forward the first selected memo. */ + comp = e_cal_component_new (); + clone = icalcomponent_new_clone (comp_data->icalcomp); + method = E_CAL_COMPONENT_METHOD_PUBLISH; + e_cal_component_set_icalcomponent (comp, clone); + itip_send_comp (method, comp, comp_data->client, NULL, NULL, NULL); + g_object_unref (comp); +} + +static void action_memo_list_copy_cb (GtkAction *action, EMemoShellView *memo_shell_view) { @@ -108,6 +137,40 @@ action_memo_list_new_cb (GtkAction *action, } static void +action_memo_list_print_cb (GtkAction *action, + EMemoShellView *memo_shell_view) +{ + EMemoShellContent *memo_shell_content; + EMemoTable *memo_table; + ETable *table; + GtkPrintOperationAction print_action; + + memo_shell_content = memo_shell_view->priv->memo_shell_content; + memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); + table = e_memo_table_get_table (memo_table); + + print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; + print_table (table, _("Print Memos"), _("Memos"), print_action); +} + +static void +action_memo_list_print_preview_cb (GtkAction *action, + EMemoShellView *memo_shell_view) +{ + EMemoShellContent *memo_shell_content; + EMemoTable *memo_table; + ETable *table; + GtkPrintOperationAction print_action; + + memo_shell_content = memo_shell_view->priv->memo_shell_content; + memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); + table = e_memo_table_get_table (memo_table); + + print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; + print_table (table, _("Print Memos"), _("Memos"), print_action); +} + +static void action_memo_list_properties_cb (GtkAction *action, EMemoShellView *memo_shell_view) { @@ -134,10 +197,54 @@ action_memo_open_cb (GtkAction *action, { EMemoShellContent *memo_shell_content; EMemoTable *memo_table; + ECalModelComponent *comp_data; + GSList *list; memo_shell_content = memo_shell_view->priv->memo_shell_content; memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); - e_memo_table_open_selected (memo_table); + + list = e_memo_table_get_selected (memo_table); + g_return_if_fail (list != NULL); + comp_data = list->data; + g_slist_free (list); + + /* XXX We only open the first selected memo. */ + e_memo_shell_view_open_memo (memo_shell_view, comp_data); +} + +static void +action_memo_open_url_cb (GtkAction *action, + EMemoShellView *memo_shell_view) +{ + EMemoShellContent *memo_shell_content; + EMemoTable *memo_table; + ECalModelComponent *comp_data; + icalproperty *prop; + GdkScreen *screen; + const gchar *uri; + GSList *list; + GError *error = NULL; + + memo_shell_content = memo_shell_view->priv->memo_shell_content; + memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); + + list = e_memo_table_get_selected (memo_table); + g_return_if_fail (list != NULL); + comp_data = list->data; + + /* XXX We only open the URI of the first selected memo. */ + prop = icalcomponent_get_first_property ( + comp_data->icalcomp, ICAL_URL_PROPERTY); + g_return_if_fail (prop == NULL); + + screen = gtk_widget_get_screen (GTK_WIDGET (memo_shell_view)); + uri = icalproperty_get_url (prop); + gtk_show_uri (screen, uri, GDK_CURRENT_TIME, &error); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } } static void @@ -158,32 +265,63 @@ action_memo_print_cb (GtkAction *action, { EMemoShellContent *memo_shell_content; EMemoTable *memo_table; - ETable *table; + ECalModelComponent *comp_data; + ECalComponent *comp; + icalcomponent *clone; + GtkPrintOperationAction print_action; + GSList *list; memo_shell_content = memo_shell_view->priv->memo_shell_content; memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); - table = e_memo_table_get_table (memo_table); - print_table ( - table, _("Print Memos"), _("Memos"), - GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG); + list = e_memo_table_get_selected (memo_table); + g_return_if_fail (list != NULL); + comp_data = list->data; + g_slist_free (list); + + /* XXX We only print the first selected memo. */ + comp = e_cal_component_new (); + clone = icalcomponent_new_clone (comp_data->icalcomp); + print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; + e_cal_component_set_icalcomponent (comp, clone); + print_comp (comp, comp_data->client, print_action); + g_object_unref (comp); } static void -action_memo_print_preview_cb (GtkAction *action, - EMemoShellView *memo_shell_view) +action_memo_save_as_cb (GtkAction *action, + EMemoShellView *memo_shell_view) { EMemoShellContent *memo_shell_content; EMemoTable *memo_table; - ETable *table; + ECalModelComponent *comp_data; + GSList *list; + gchar *filename; + gchar *string; memo_shell_content = memo_shell_view->priv->memo_shell_content; memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); - table = e_memo_table_get_table (memo_table); - print_table ( - table, _("Print Memos"), _("Memos"), - GTK_PRINT_OPERATION_ACTION_PREVIEW); + list = e_memo_table_get_selected (memo_table); + g_return_if_fail (list != NULL); + comp_data = list->data; + g_slist_free (list); + + filename = e_file_dialog_save (_("Save as..."), NULL); + if (filename == NULL) + return; + + string = e_cal_get_component_as_string ( + comp_data->client, comp_data->icalcomp); + if (string == NULL) { + g_warning ("Could not convert memo to a string"); + return; + } + + e_write_file_uri (filename, string); + + g_free (filename); + g_free (string); } static GtkActionEntry memo_entries[] = { @@ -211,11 +349,18 @@ static GtkActionEntry memo_entries[] = { { "memo-delete", GTK_STOCK_DELETE, - NULL, + N_("Delete Memo"), NULL, N_("Delete selected memos"), G_CALLBACK (action_memo_delete_cb) }, + { "memo-forward", + "mail-forward", + N_("_Forward as iCalendar"), + NULL, + NULL, /* XXX Add a tooltip! */ + G_CALLBACK (action_memo_forward_cb) }, + { "memo-list-copy", GTK_STOCK_COPY, N_("_Copy..."), @@ -237,6 +382,20 @@ static GtkActionEntry memo_entries[] = { N_("Create a new memo list"), G_CALLBACK (action_memo_list_new_cb) }, + { "memo-list-print", + GTK_STOCK_PRINT, + NULL, + NULL, + N_("Print the list of memos"), + G_CALLBACK (action_memo_list_print_cb) }, + + { "memo-list-print-preview", + GTK_STOCK_PRINT_PREVIEW, + NULL, + NULL, + N_("Preview the list of memos to be printed"), + G_CALLBACK (action_memo_list_print_preview_cb) }, + { "memo-list-properties", GTK_STOCK_PROPERTIES, NULL, @@ -251,19 +410,26 @@ static GtkActionEntry memo_entries[] = { N_("View the selected memo"), G_CALLBACK (action_memo_open_cb) }, + { "memo-open-url", + NULL, + N_("Open _Web Page"), + NULL, + NULL, /* XXX Add a tooltip! */ + G_CALLBACK (action_memo_open_url_cb) }, + { "memo-print", GTK_STOCK_PRINT, NULL, NULL, - N_("Print the list of memos"), + N_("Print the selected memo"), G_CALLBACK (action_memo_print_cb) }, - { "memo-print-preview", - GTK_STOCK_PRINT_PREVIEW, + { "memo-save-as", + GTK_STOCK_SAVE_AS, NULL, NULL, - N_("Preview the list of memos to be printed"), - G_CALLBACK (action_memo_print_preview_cb) }, + NULL, /* XXX Add a tooltip! */ + G_CALLBACK (action_memo_save_as_cb) } }; static GtkToggleActionEntry memo_toggle_entries[] = { @@ -326,6 +492,7 @@ e_memo_shell_view_actions_update (EMemoShellView *memo_shell_view) EShellView *shell_view; EShellWindow *shell_window; GtkAction *action; + const gchar *label; gboolean read_only = TRUE; gboolean sensitive; gint n_selected; @@ -364,4 +531,6 @@ e_memo_shell_view_actions_update (EMemoShellView *memo_shell_view) action = ACTION (MEMO_DELETE); sensitive = (n_selected > 0) && !read_only; gtk_action_set_sensitive (action, sensitive); + label = ngettext ("Delete Memo", "Delete Memos", n_selected); + g_object_set (action, "label", label, NULL); } diff --git a/calendar/modules/e-memo-shell-view-private.c b/calendar/modules/e-memo-shell-view-private.c index a6ce81a560..076ed3fc5d 100644 --- a/calendar/modules/e-memo-shell-view-private.c +++ b/calendar/modules/e-memo-shell-view-private.c @@ -155,8 +155,24 @@ memo_shell_view_add_source (EMemoShellView *memo_shell_view, } static void -memo_shell_view_user_created_cb (EMemoShellView *memo_shell_view, - EMemoTable *memo_table) +memo_shell_view_table_popup_event_cb (EMemoShellView *memo_shell_view, + GdkEvent *event) +{ + EShellView *shell_view; + EShellWindow *shell_window; + const gchar *widget_path; + + shell_view = E_SHELL_VIEW (memo_shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + widget_path = "/memo-popup"; + + e_memo_shell_view_actions_update (memo_shell_view); + e_shell_window_show_popup_menu (shell_window, widget_path, event); +} + +static void +memo_shell_view_table_user_created_cb (EMemoShellView *memo_shell_view, + EMemoTable *memo_table) { ECal *client; ESource *source; @@ -275,8 +291,23 @@ e_memo_shell_view_private_constructed (EMemoShellView *memo_shell_view) priv->memo_shell_content); g_signal_connect_swapped ( + memo_table, "open-component", + G_CALLBACK (e_memo_shell_view_open_memo), + memo_shell_view); + + g_signal_connect_swapped ( + memo_table, "popup-event", + G_CALLBACK (memo_shell_view_table_popup_event_cb), + memo_shell_view); + + g_signal_connect_swapped ( + memo_table, "status-message", + G_CALLBACK (e_memo_shell_view_set_status_message), + memo_shell_view); + + g_signal_connect_swapped ( memo_table, "user-created", - G_CALLBACK (memo_shell_view_user_created_cb), + G_CALLBACK (memo_shell_view_table_user_created_cb), memo_shell_view); e_memo_shell_view_actions_update (memo_shell_view); @@ -296,6 +327,13 @@ e_memo_shell_view_private_dispose (EMemoShellView *memo_shell_view) g_hash_table_remove_all (priv->client_table); DISPOSE (priv->default_client); + + if (memo_shell_view->priv->activity != NULL) { + /* XXX Activity is not cancellable. */ + e_activity_complete (memo_shell_view->priv->activity); + g_object_unref (memo_shell_view->priv->activity); + memo_shell_view->priv->activity = NULL; + } } void @@ -307,10 +345,68 @@ e_memo_shell_view_private_finalize (EMemoShellView *memo_shell_view) } void +e_memo_shell_view_open_memo (EMemoShellView *memo_shell_view, + ECalModelComponent *comp_data) +{ + CompEditor *editor; + CompEditorFlags flags = 0; + ECalComponent *comp; + icalcomponent *clone; + const gchar *uid; + + g_return_if_fail (E_IS_MEMO_SHELL_VIEW (memo_shell_view)); + g_return_if_fail (E_IS_CAL_MODEL_COMPONENT (comp_data)); + + uid = icalcomponent_get_uid (comp_data->icalcomp); + editor = comp_editor_find_instance (uid); + + if (editor == NULL) + goto exit; + + comp = e_cal_component_new (); + clone = icalcomponent_new_clone (comp_data->icalcomp); + e_cal_component_set_icalcomponent (comp, clone); + + 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; + + editor = memo_editor_new (comp_data->client, flags); + comp_editor_edit_comp (editor, comp); + + g_object_unref (comp); + +exit: + gtk_window_present (GTK_WINDOW (editor)); +} + +void e_memo_shell_view_set_status_message (EMemoShellView *memo_shell_view, const gchar *status_message) { + EActivity *activity; + EShellView *shell_view; + g_return_if_fail (E_IS_MEMO_SHELL_VIEW (memo_shell_view)); - /* FIXME */ + activity = memo_shell_view->priv->activity; + shell_view = E_SHELL_VIEW (memo_shell_view); + + if (status_message == NULL || *status_message == '\0') { + if (activity != NULL) { + e_activity_complete (activity); + g_object_unref (activity); + activity = NULL; + } + + } else if (activity == NULL) { + activity = e_activity_new (status_message); + e_shell_view_add_activity (shell_view, activity); + + } else + e_activity_set_primary_text (activity, status_message); + + memo_shell_view->priv->activity = activity; } diff --git a/calendar/modules/e-memo-shell-view-private.h b/calendar/modules/e-memo-shell-view-private.h index 1fb44c12a6..7d8958eae7 100644 --- a/calendar/modules/e-memo-shell-view-private.h +++ b/calendar/modules/e-memo-shell-view-private.h @@ -26,14 +26,16 @@ #include <string.h> #include <glib/gi18n.h> +#include "e-util/e-dialog-utils.h" #include "e-util/e-error.h" #include "e-util/e-util.h" +#include "calendar/common/authentication.h" #include "calendar/gui/misc.h" #include "calendar/gui/e-calendar-selector.h" #include "calendar/gui/e-memo-preview.h" -#include "calendar/common/authentication.h" #include "calendar/gui/dialogs/calendar-setup.h" +#include "calendar/gui/dialogs/memo-editor.h" #include "e-memo-shell-content.h" #include "e-memo-shell-sidebar.h" @@ -76,9 +78,11 @@ struct _EMemoShellViewPrivate { EMemoShellContent *memo_shell_content; EMemoShellSidebar *memo_shell_sidebar; - /* UID -> ECal */ + /* UID -> Client */ GHashTable *client_table; ECal *default_client; + + EActivity *activity; }; void e_memo_shell_view_private_init @@ -97,6 +101,9 @@ void e_memo_shell_view_actions_init (EMemoShellView *memo_shell_view); void e_memo_shell_view_actions_update (EMemoShellView *memo_shell_view); +void e_memo_shell_view_open_memo + (EMemoShellView *memo_shell_view, + ECalModelComponent *comp_data); void e_memo_shell_view_set_status_message (EMemoShellView *memo_shell_view, const gchar *status_message); diff --git a/calendar/modules/e-task-shell-view-private.c b/calendar/modules/e-task-shell-view-private.c index 465f715ecd..b16ac80edb 100644 --- a/calendar/modules/e-task-shell-view-private.c +++ b/calendar/modules/e-task-shell-view-private.c @@ -23,6 +23,174 @@ #include <widgets/menus/gal-view-factory-etable.h> static void +task_shell_view_backend_died_cb (ETaskShellView *task_shell_view, + ECal *client) +{ + EShellView *shell_view; + EShellWindow *shell_window; + GHashTable *client_table; + ESource *source; + const gchar *uid; + + shell_view = E_SHELL_VIEW (task_shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + + source = e_cal_get_source (client); + uid = e_source_peek_uid (source); + + g_object_ref (source); + + g_hash_table_remove (client_table, uid); + e_task_shell_view_set_status_message (task_shell_view, NULL); + + e_error_run ( + GTK_WINDOW (shell_window), + "calendar:tasks-crashed", NULL); + + g_object_unref (source); +} + +static void +task_shell_view_backend_error_cb (ETaskShellView *task_shell_view, + const gchar *message, + ECal *client) +{ + EShellView *shell_view; + EShellWindow *shell_window; + GtkWidget *dialog; + const gchar *uri; + gchar *uri_no_passwd; + + shell_view = E_SHELL_VIEW (task_shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + + uri = e_cal_get_uri (client); + uri_no_passwd = get_uri_without_password (uri); + + dialog = gtk_message_dialog_new ( + GTK_WINDOW (shell_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + _("Error on %s:\n%s"), + uri_no_passwd, message); + + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + g_free (uri_no_passwd); +} + +static void +task_shell_view_client_opened_cb (ETaskShellView *task_shell_view, + ECalendarStatus status, + ECal *client) +{ + /* FIXME */ +} + +static gboolean +task_shell_view_add_source (ETaskShellView *task_shell_view, + ESource *source) +{ + GHashTable *client_table; + ECal *default_client; + ECal *client; + const gchar *uid; + const gchar *uri; + gchar *status_message; + + client_table = task_shell_view->priv->client_table; + default_client = task_shell_view->priv->default_client; + + uid = e_source_peek_uid (source); + client = g_hash_table_lookup (client_table, uid); + + if (client != NULL) + return TRUE; + + if (default_client != NULL) { + ESource *default_source; + const gchar *default_uid; + + default_source = e_cal_get_source (default_client); + default_uid = e_source_peek_uid (default_source); + + if (strcmp (uid, default_uid) == 0) + client = g_object_ref (default_client); + } + + if (client == NULL) + client = auth_new_cal_from_source ( + source, E_CAL_SOURCE_TYPE_TODO); + + if (client == NULL) + return FALSE; + + g_signal_connect_swapped ( + client, "backend-died", + G_CALLBACK (task_shell_view_backend_died_cb), + task_shell_view); + + g_signal_connect_swapped ( + client, "backend-error", + G_CALLBACK (task_shell_view_backend_error_cb), + task_shell_view); + + g_hash_table_insert (client_table, g_strdup (uid), client); + + uri = e_cal_get_uri (client); + + status_message = g_strdup_printf (_("Opening tasks at %s"), uri); + e_task_shell_view_set_status_message (task_shell_view, status_message); + g_free (status_message); + + g_signal_connect_swapped ( + client, "cal-opened", + G_CALLBACK (task_shell_view_client_opened_cb), + task_shell_view); + + e_cal_open_async (client, FALSE); + + return TRUE; +} + +static void +task_shell_view_table_popup_event_cb (ETaskShellView *task_shell_view, + GdkEvent *event) +{ + EShellView *shell_view; + EShellWindow *shell_window; + const gchar *widget_path; + + shell_view = E_SHELL_VIEW (task_shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + widget_path = "/task-popup"; + + e_task_shell_view_actions_update (task_shell_view); + e_shell_window_show_popup_menu (shell_window, widget_path, event); +} + +static void +task_shell_view_table_user_created (ETaskShellView *task_shell_view, + ETaskTable *task_table) +{ + ECal *client; + ESource *source; + + if (task_table->user_created_cal != NULL) + client = task_table->user_created_cal; + else { + ECalModel *model; + + model = e_task_table_get_model (task_table); + client = e_cal_model_get_default_client (model); + } + + source = e_cal_get_source (client); + task_shell_view_add_source (task_shell_view, source); +} + +static void task_shell_view_load_view_collection (EShellViewClass *shell_view_class) { GalViewCollection *collection; @@ -78,14 +246,21 @@ e_task_shell_view_private_init (ETaskShellView *task_shell_view, { ETaskShellViewPrivate *priv = task_shell_view->priv; ESourceList *source_list; + GHashTable *client_table; GObject *object; object = G_OBJECT (shell_view_class->type_module); source_list = g_object_get_data (object, "source-list"); g_return_if_fail (E_IS_SOURCE_LIST (source_list)); + client_table = g_hash_table_new_full ( + g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_object_unref); + priv->source_list = g_object_ref (source_list); priv->task_actions = gtk_action_group_new ("tasks"); + priv->client_table = client_table; if (!gal_view_collection_loaded (shell_view_class->view_collection)) task_shell_view_load_view_collection (shell_view_class); @@ -102,6 +277,7 @@ e_task_shell_view_private_constructed (ETaskShellView *task_shell_view) EShellContent *shell_content; EShellSidebar *shell_sidebar; EShellView *shell_view; + ETaskTable *task_table; shell_view = E_SHELL_VIEW (task_shell_view); shell_content = e_shell_view_get_shell_content (shell_view); @@ -110,6 +286,31 @@ e_task_shell_view_private_constructed (ETaskShellView *task_shell_view) /* Cache these to avoid lots of awkward casting. */ priv->task_shell_content = g_object_ref (shell_content); priv->task_shell_sidebar = g_object_ref (shell_sidebar); + + task_table = e_task_shell_content_get_task_table ( + priv->task_shell_content); + + g_signal_connect_swapped ( + task_table, "open-component", + G_CALLBACK (e_task_shell_view_open_task), + task_shell_view); + + g_signal_connect_swapped ( + task_table, "popup-event", + G_CALLBACK (task_shell_view_table_popup_event_cb), + task_shell_view); + + g_signal_connect_swapped ( + task_table, "status-message", + G_CALLBACK (e_task_shell_view_set_status_message), + task_shell_view); + + g_signal_connect_swapped ( + task_table, "user-created", + G_CALLBACK (task_shell_view_table_user_created_cb), + task_shell_view); + + e_task_shell_view_actions_update (task_shell_view); } void @@ -123,19 +324,87 @@ e_task_shell_view_private_dispose (ETaskShellView *task_shell_view) DISPOSE (priv->task_shell_content); DISPOSE (priv->task_shell_sidebar); + + g_hash_table_remove_all (priv->client_table); + DISPOSE (priv->default_client); + + if (task_shell_view->priv->activity != NULL) { + /* XXX Activity is no cancellable. */ + e_activity_complete (task_shell_view->priv->activity); + g_object_unref (task_shell_view->priv->activity); + task_shell_view->priv->activity = NULL; + } } void e_task_shell_view_private_finalize (ETaskShellView *task_shell_view) { ETaskShellViewPrivate *priv = task_shell_view->priv; + + g_hash_table_destroy (priv->client_table); +} + +void +e_task_shell_view_open_task (ETaskShellView *task_shell_view, + ECalModelComponent *comp_data) +{ + CompEditor *editor; + CompEditorFlags flags = 0; + ECalComponent *comp; + icalcomponent *clone; + const gchar *uid; + + g_return_if_fail (E_IS_TASK_SHELL_VIEW (task_shell_view)); + g_return_if_fail (E_IS_CAL_MODEL_COMPONENT (comp_data)); + + uid = icalcomponent_get_uid (comp_data->icalcomp); + editor = comp_editor_find_instance (uid); + + if (editor == NULL) + goto exit; + + comp = e_cal_component_new (); + clone = icalcomponent_new_clone (comp_data->icalcomp); + e_cal_component_set_icalcomponent (comp, clone); + + /* FIXME Do special stuff if task is assigned. */ + + editor = task_editor_new (comp_data->client, flags); + comp_editor_edit_comp (editor, comp); + + g_object_ref (comp); + + /* FIXME More special stuff here... */ + +exit: + gtk_window_present (GTK_WINDOW (editor)); } void e_task_shell_view_set_status_message (ETaskShellView *task_shell_view, const gchar *status_message) { + EActivity *activity; + EShellView *shell_view; + g_return_if_fail (E_IS_TASK_SHELL_VIEW (task_shell_view)); - /* FIXME */ + activity = task_shell_view->priv->activity; + shell_view = E_SHELL_VIEW (task_shell_view); + + if (status_message == NULL || *status_message == '\0') { + if (activity != NULL) { + e_activity_complete (activity); + g_object_unref (activity); + activity = NULL; + } + + } else if (activity == NULL) { + activity = e_activity_new (status_message); + e_shell_view_add_activity (shell_view, activity); + + } else + e_activity_set_primary_text (activity, status_message); + + task_shell_view->priv->activity = activity; } diff --git a/calendar/modules/e-task-shell-view-private.h b/calendar/modules/e-task-shell-view-private.h index 697ec7a120..ac6accfbcf 100644 --- a/calendar/modules/e-task-shell-view-private.h +++ b/calendar/modules/e-task-shell-view-private.h @@ -26,8 +26,17 @@ #include <string.h> #include <glib/gi18n.h> +#include "e-util/e-dialog-utils.h" +#include "e-util/e-error.h" #include "e-util/e-util.h" +#include "calendar/common/authentication.h" +#include "calendar/gui/misc.h" +#include "calendar/gui/e-calendar-selector.h" +#include "calendar/gui/e-task-preview.h" +#include "calendar/gui/dialogs/calendar-setup.h" +#include "calendar/gui/dialogs/task-editor.h" + #include "e-task-shell-content.h" #include "e-task-shell-sidebar.h" #include "e-task-shell-view-actions.h" @@ -68,6 +77,12 @@ struct _ETaskShellViewPrivate { /* These are just for convenience. */ ETaskShellContent *task_shell_content; ETaskShellSidebar *task_shell_sidebar; + + /* UID -> Client */ + GHashTable *client_table; + ECal *default_client; + + EActivity *activity; }; void e_task_shell_view_private_init @@ -86,6 +101,9 @@ void e_task_shell_view_actions_init (ETaskShellView *task_shell_view); void e_task_shell_view_actions_update (ETaskShellView *task_shell_view); +void e_task_shell_view_open_task + (ETaskShellView *task_shell_view, + ECalModelComponent *comp_data); void e_task_shell_view_set_status_message (ETaskShellView *task_shell_view, const gchar *status_message); |