diff options
Diffstat (limited to 'calendar/gui/e-itip-control.c')
-rw-r--r-- | calendar/gui/e-itip-control.c | 196 |
1 files changed, 76 insertions, 120 deletions
diff --git a/calendar/gui/e-itip-control.c b/calendar/gui/e-itip-control.c index ed15183552..154f23e170 100644 --- a/calendar/gui/e-itip-control.c +++ b/calendar/gui/e-itip-control.c @@ -58,12 +58,13 @@ struct _EItipControlPrivate { GtkWidget *html; + gboolean html_destroyed; GPtrArray *event_clients; CalClient *event_client; GPtrArray *task_clients; CalClient *task_client; - + char *vcalendar; CalComponent *comp; icalcomponent *main_comp; @@ -187,13 +188,43 @@ error: return NULL; } -static gboolean -start_default_server_async (EItipControl *itip, CalClient *client, gboolean tasks) +static CalClient * +start_default_server (EItipControl *itip, gboolean tasks) { - if (tasks) - return cal_client_open_default_tasks (client, FALSE); - else - return cal_client_open_default_calendar (client, FALSE); + CalClient *client; + gboolean success = FALSE; + + client = cal_client_new (); + + g_signal_connect (client, "cal_opened", G_CALLBACK (start_calendar_server_cb), &success); + + if (tasks) { + if (!cal_client_open_default_tasks (client, FALSE)) + goto error; + } else { + if (!cal_client_open_default_calendar (client, FALSE)) + goto error; + } + + /* run a sub event loop to turn cal-client's async load + notification into a synchronous call */ + if (!itip->priv->destroyed) { + gtk_signal_connect (GTK_OBJECT (itip), "destroy", + gtk_main_quit, NULL); + + gtk_main (); + + gtk_signal_disconnect_by_func (GTK_OBJECT (itip), + gtk_main_quit, NULL); + } + + if (success) + return client; + + error: + g_object_unref (client); + + return NULL; } static GPtrArray * @@ -274,11 +305,9 @@ find_server (GPtrArray *servers, CalComponent *comp) for (i = 0; i < servers->len; i++) { CalClient *client; icalcomponent *icalcomp; - CalClientGetStatus status; client = g_ptr_array_index (servers, i); - status = cal_client_get_object (client, uid, &icalcomp); - if (status == CAL_CLIENT_GET_SUCCESS) { + if (cal_client_get_object (client, uid, NULL, &icalcomp, NULL)) { icalcomponent_free (icalcomp); g_object_ref (client); @@ -297,7 +326,7 @@ html_destroyed (gpointer data) priv = itip->priv; - priv->html = NULL; + priv->html_destroyed = TRUE; } static void @@ -329,6 +358,7 @@ init (EItipControl *itip) /* Html Widget */ priv->html = gtk_html_new (); + priv->html_destroyed = FALSE; gtk_html_set_default_content_type (GTK_HTML (priv->html), "text/html; charset=utf-8"); gtk_html_load_from_string (GTK_HTML (priv->html), " ", 1); @@ -401,12 +431,10 @@ destroy (GtkObject *obj) { EItipControl *itip = E_ITIP_CONTROL (obj); EItipControlPrivate *priv; - + priv = itip->priv; - + priv->destroyed = TRUE; - - (* GTK_OBJECT_CLASS (parent_class)->destroy) (obj); } static void @@ -913,7 +941,7 @@ write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, priv = itip->priv; - if (priv->html == NULL) + if (priv->html_destroyed) return; /* Html widget */ @@ -1220,7 +1248,7 @@ get_real_item (EItipControl *itip) CalComponent *comp; icalcomponent *icalcomp; CalComponentVType type; - CalClientGetStatus status = CAL_CLIENT_GET_NOT_FOUND; + gboolean found = FALSE; const char *uid; priv = itip->priv; @@ -1231,17 +1259,17 @@ get_real_item (EItipControl *itip) switch (type) { case CAL_COMPONENT_EVENT: if (priv->event_client != NULL) - status = cal_client_get_object (priv->event_client, uid, &icalcomp); + found = cal_client_get_object (priv->event_client, uid, NULL, &icalcomp, NULL); break; case CAL_COMPONENT_TODO: if (priv->task_client != NULL) - status = cal_client_get_object (priv->task_client, uid, &icalcomp); + found = cal_client_get_object (priv->task_client, uid, NULL, &icalcomp, NULL); break; default: - status = CAL_CLIENT_GET_NOT_FOUND; + found = FALSE; } - if (status != CAL_CLIENT_GET_SUCCESS) + if (!found) return NULL; comp = cal_component_new (); @@ -1853,7 +1881,6 @@ update_item (EItipControl *itip) CalClient *client; CalComponentVType type; GtkWidget *dialog; - CalClientResult result; priv = itip->priv; @@ -1881,32 +1908,18 @@ update_item (EItipControl *itip) icalcomponent_add_component (priv->top_level, clone); icalcomponent_set_method (priv->top_level, priv->method); - result = cal_client_update_objects (client, priv->top_level); - switch (result) { - case CAL_CLIENT_RESULT_INVALID_OBJECT : - dialog = gnome_warning_dialog (_("Object is invalid and cannot be updated\n")); - break; - case CAL_CLIENT_RESULT_CORBA_ERROR : - dialog = gnome_warning_dialog (_("There was an error on the CORBA system\n")); - break; - case CAL_CLIENT_RESULT_NOT_FOUND : - dialog = gnome_warning_dialog (_("Object could not be found\n")); - break; - case CAL_CLIENT_RESULT_PERMISSION_DENIED : - dialog = gnome_warning_dialog (_("You do not have the right permissions to update the calendar\n")); - break; - case CAL_CLIENT_RESULT_SUCCESS : - dialog = gnome_ok_dialog (_("Update complete\n")); - break; - default : + /* FIXME Better error dialog */ + if (!cal_client_receive_objects (client, priv->top_level, NULL)) { dialog = gnome_warning_dialog (_("Calendar file could not be updated!\n")); - break; + } else { + dialog = gnome_ok_dialog (_("Update complete\n")); } gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); icalcomponent_remove_component (priv->top_level, clone); } +#if 0 static void update_attendee_status (EItipControl *itip) { @@ -1936,7 +1949,7 @@ update_attendee_status (EItipControl *itip) /* Obtain our version */ cal_component_get_uid (priv->comp, &uid); - status = cal_client_get_object (client, uid, &icalcomp); + status = cal_client_get_object (client, uid, NULL, &icalcomp); if (status == CAL_CLIENT_GET_SUCCESS) { GSList *attendees; @@ -2010,6 +2023,7 @@ update_attendee_status (EItipControl *itip) g_object_unref (comp); gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); } +#endif static void remove_item (EItipControl *itip) @@ -2019,7 +2033,7 @@ remove_item (EItipControl *itip) CalComponentVType type; const char *uid; GtkWidget *dialog; - CalClientResult result; + GError *error = NULL; priv = itip->priv; @@ -2033,13 +2047,15 @@ remove_item (EItipControl *itip) return; cal_component_get_uid (priv->comp, &uid); - result = cal_client_remove_object (client, uid); - if (result == CAL_CLIENT_RESULT_SUCCESS || result == CAL_CLIENT_RESULT_NOT_FOUND) { + cal_client_remove_object (client, uid, &error); + if (!error || error->code == E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { dialog = gnome_ok_dialog (_("Removal Complete")); gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); } else { - delete_error_dialog (result, type); - } + delete_error_dialog (error, type); + } + + g_clear_error (&error); } static void @@ -2081,7 +2097,7 @@ send_freebusy (EItipControl *itip) CalComponentDateTime datetime; time_t start, end; GtkWidget *dialog; - GList *comp_list; + GList *comp_list = NULL; icaltimezone *zone; priv = itip->priv; @@ -2106,9 +2122,7 @@ send_freebusy (EItipControl *itip) end = icaltime_as_timet_with_zone (*datetime.value, zone); cal_component_free_datetime (&datetime); - comp_list = cal_client_get_free_busy (priv->event_client, NULL, start, end); - - if (comp_list) { + if (cal_client_get_free_busy (priv->event_client, NULL, start, end, &comp_list, NULL)) { GList *l; for (l = comp_list; l; l = l->next) { @@ -2179,34 +2193,16 @@ url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *handle, gpoint g_free (path); } -typedef struct -{ - EItipControl *itip; - GtkHTMLEmbedded *eb; - CalClient *client; -} -ObjectRequestContext; - -static void -default_server_started_cb (CalClient *client, CalClientOpenStatus status, gpointer data) +static gboolean +object_requested_cb (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data) { - ObjectRequestContext *context = data; + EItipControl *itip = E_ITIP_CONTROL (data); EItipControlPrivate *priv; GtkWidget *button; CalComponentVType vtype; + + priv = itip->priv; - priv = context->itip->priv; - - if (status != CAL_CLIENT_OPEN_SUCCESS || - context->itip->priv->destroyed || - context->itip->priv->html == NULL) { - g_object_unref (context->client); - g_object_unref (context->itip); - g_free (context); - return; - } - - priv->event_client = client; vtype = cal_component_get_vtype (priv->comp); switch (vtype) { @@ -2215,65 +2211,24 @@ default_server_started_cb (CalClient *client, CalClientOpenStatus status, gpoint global_shell_client, _("Select Calendar Folder"), calendar_config_default_calendar_folder (), calendar_types); + priv->event_client = start_default_server (itip, FALSE); break; case CAL_COMPONENT_TODO: button = evolution_folder_selector_button_new ( global_shell_client, _("Select Tasks Folder"), calendar_config_default_tasks_folder (), tasks_types); + priv->task_client = start_default_server (itip, TRUE); break; default: button = NULL; } - g_signal_connect (button, "selected", G_CALLBACK (button_selected_cb), context->itip); + g_signal_connect (button, "selected", G_CALLBACK (button_selected_cb), itip); - gtk_container_add (GTK_CONTAINER (context->eb), button); + gtk_container_add (GTK_CONTAINER (eb), button); gtk_widget_show (button); - g_object_unref (context->itip); - g_free (context); - return; -} - -static gboolean -object_requested_cb (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data) -{ - EItipControl *itip = E_ITIP_CONTROL (data); - ObjectRequestContext *context; - EItipControlPrivate *priv; - CalComponentVType vtype; - gboolean success; - - priv = itip->priv; - vtype = cal_component_get_vtype (priv->comp); - - context = g_new0 (ObjectRequestContext, 1); - context->itip = itip; - context->eb = eb; - context->client = cal_client_new (); - - g_object_ref (itip); - g_signal_connect (context->client, "cal_opened", - G_CALLBACK (default_server_started_cb), context); - - switch (vtype) { - case CAL_COMPONENT_EVENT: - success = start_default_server_async (itip, context->client, FALSE); - break; - case CAL_COMPONENT_TODO: - success = start_default_server_async (itip, context->client, TRUE); - break; - default: - success = FALSE; - } - - if (!success) { - g_object_unref (itip); - g_object_unref (context->client); - g_free (context); - } - return TRUE; } @@ -2330,7 +2285,8 @@ ok_clicked_cb (GtkHTML *html, const gchar *method, const gchar *url, const gchar send_freebusy (itip); break; case 'R': - update_attendee_status (itip); + /* FIXME Make sure this does the right thing in the backend */ + update_item (itip); break; case 'S': send_item (itip); |