static void action_calendar_taskpad_save_as_cb (GtkAction *action, ECalShellView *cal_shell_view) { EShell *shell; EShellView *shell_view; EShellWindow *shell_window; EShellBackend *shell_backend; ECalShellContent *cal_shell_content; ECalModelComponent *comp_data; ETaskTable *task_table; EActivity *activity; GSList *list; GFile *file; gchar *string; shell_view = E_SHELL_VIEW (cal_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); shell_backend = e_shell_view_get_shell_backend (shell_view); shell = e_shell_window_get_shell (shell_window); cal_shell_content = cal_shell_view->priv->cal_shell_content; task_table = e_cal_shell_content_get_task_table (cal_shell_content); list = e_task_table_get_selected (task_table); g_return_if_fail (list != NULL); comp_data = list->data; g_slist_free (list); /* Translators: Default filename part saving a task to a file when * no summary is filed, the '.ics' extension is concatenated to it. */ string = icalcomp_suggest_filename (comp_data->icalcomp, _("task")); file = e_shell_run_save_dialog ( shell, _("Save as iCalendar"), string, "*.ics:text/calendar", NULL, NULL); g_free (string); if (file == NULL) return; string = e_cal_client_get_component_as_string ( comp_data->client, comp_data->icalcomp); if (string == NULL) { g_warning ("Could not convert task to a string"); g_object_unref (file); return; } /* XXX No callback means errors are discarded. */ activity = e_file_replace_contents_async ( file, string, strlen (string), NULL, FALSE, G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL); e_shell_backend_add_activity (shell_backend, activity); /* Free the string when the activity is finalized. */ g_object_set_data_full ( G_OBJECT (activity), "file-content", string, (GDestroyNotify) g_free); g_object_unref (file); }
static void action_contact_save_as_cb (GtkAction *action, EBookShellView *book_shell_view) { EShell *shell; EShellView *shell_view; EShellWindow *shell_window; EShellBackend *shell_backend; EBookShellContent *book_shell_content; EAddressbookView *view; EActivity *activity; GSList *list; GFile *file; gchar *string; shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); shell_backend = e_shell_view_get_shell_backend (shell_view); shell = e_shell_window_get_shell (shell_window); book_shell_content = book_shell_view->priv->book_shell_content; view = e_book_shell_content_get_current_view (book_shell_content); g_return_if_fail (view != NULL); list = e_addressbook_view_get_selected (view); if (list == NULL) goto exit; string = eab_suggest_filename (list); file = e_shell_run_save_dialog ( /* Translators: This is a save dialog title */ shell, _("Save as vCard"), string, "*.vcf:text/x-vcard,text/directory", NULL, NULL); g_free (string); if (file == NULL) goto exit; string = eab_contact_list_to_string (list); if (string == NULL) { g_warning ("Could not convert contact list to a string"); g_object_unref (file); goto exit; } /* XXX No callback means errors are discarded. * * There's an EAlert for this which I'm not using * until I figure out a better way to display errors: * * "addressbook:save-error" */ activity = e_file_replace_contents_async ( file, string, strlen (string), NULL, FALSE, G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL); e_shell_backend_add_activity (shell_backend, activity); /* Free the string when the activity is finalized. */ g_object_set_data_full ( G_OBJECT (activity), "file-content", string, (GDestroyNotify) g_free); g_object_unref (file); exit: e_client_util_free_object_slist (list); }