gchar * mail_config_folder_to_cachename (CamelFolder *folder, const gchar *prefix) { gchar *folder_uri, *basename, *filename; const gchar *config_dir; config_dir = mail_session_get_config_dir (); basename = g_build_filename (config_dir, "folders", NULL); if (!g_file_test (basename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { /* create the folder if does not exist */ g_mkdir_with_parents (basename, 0700); } g_free (basename); folder_uri = e_mail_folder_uri_from_folder (folder); e_filename_make_safe (folder_uri); basename = g_strdup_printf ("%s%s", prefix, folder_uri); filename = g_build_filename (config_dir, "folders", basename, NULL); g_free (basename); g_free (folder_uri); return filename; }
static void set_attachments (ECalClient *client, ECalComponent *comp, CamelMimeMessage *message) { /* XXX Much of this is copied from CompEditor::get_attachment_list(). * Perhaps it should be split off as a separate utility? */ EAttachmentStore *store; CamelDataWrapper *content; CamelMultipart *multipart; GFile *destination; GList *attachment_list = NULL; GSList *uri_list = NULL; const gchar *comp_uid = NULL; const gchar *local_store; gchar *filename_prefix, *tmp; gint ii, n_parts; struct _att_async_cb_data cb_data; cb_data.flag = e_flag_new (); cb_data.uris = NULL; content = camel_medium_get_content ((CamelMedium *) message); if (!content || !CAMEL_IS_MULTIPART (content)) return; n_parts = camel_multipart_get_number (CAMEL_MULTIPART (content)); if (n_parts < 1) return; e_cal_component_get_uid (comp, &comp_uid); g_return_if_fail (comp_uid != NULL); tmp = g_strdup (comp_uid); e_filename_make_safe (tmp); filename_prefix = g_strconcat (tmp, "-", NULL); g_free (tmp); local_store = e_cal_client_get_local_attachment_store (client); destination = g_file_new_for_path (local_store); /* Create EAttachments from the MIME parts and add them to the * attachment store. */ multipart = CAMEL_MULTIPART (content); store = E_ATTACHMENT_STORE (e_attachment_store_new ()); for (ii = 1; ii < n_parts; ii++) { EAttachment *attachment; CamelMimePart *mime_part; attachment = e_attachment_new (); mime_part = camel_multipart_get_part (multipart, ii); e_attachment_set_mime_part (attachment, mime_part); attachment_list = g_list_append (attachment_list, attachment); } e_flag_clear (cb_data.flag); e_attachment_store_load_async ( store, attachment_list, (GAsyncReadyCallback) attachment_load_finished, &cb_data); /* Loading should be instantaneous since we already have * the full content, but we need to wait for the callback. */ e_flag_wait (cb_data.flag); g_list_foreach (attachment_list, (GFunc) g_object_unref, NULL); g_list_free (attachment_list); cb_data.uris = NULL; e_flag_clear (cb_data.flag); e_attachment_store_save_async ( store, destination, filename_prefix, (GAsyncReadyCallback) attachment_save_finished, &cb_data); g_free (filename_prefix); /* We can't return until we have results. */ e_flag_wait (cb_data.flag); if (cb_data.uris == NULL) { e_flag_free (cb_data.flag); g_warning ("No attachment URIs retrieved."); return; } /* Transfer the URI strings to the GSList. */ for (ii = 0; cb_data.uris[ii] != NULL; ii++) { uri_list = g_slist_prepend (uri_list, cb_data.uris[ii]); cb_data.uris[ii] = NULL; } e_flag_free (cb_data.flag); g_free (cb_data.uris); /* XXX Does this take ownership of the list? */ e_cal_component_set_attachment_list (comp, uri_list); e_attachment_store_remove_all (store); g_object_unref (destination); g_object_unref (store); }
static gboolean shell_xdg_migrate_rename_files (const gchar *src_directory, const gchar *dst_directory) { GDir *dir; GHashTable *corrections; const gchar *basename; const gchar *home_dir; gchar *old_base_dir; gchar *new_base_dir; dir = g_dir_open (src_directory, 0, NULL); if (dir == NULL) return FALSE; /* This is to avoid renaming files which we're iterating over the * directory. POSIX says the outcome of that is unspecified. */ corrections = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_free); g_mkdir_with_parents (dst_directory, 0700); home_dir = g_get_home_dir (); old_base_dir = g_build_filename (home_dir, ".evolution", NULL); e_filename_make_safe (old_base_dir); new_base_dir = g_strdup (e_get_user_data_dir ()); e_filename_make_safe (new_base_dir); while ((basename = g_dir_read_name (dir)) != NULL) { GString *buffer; gchar *old_filename; gchar *new_filename; gchar *cp; buffer = g_string_new (basename); if ((cp = strstr (basename, old_base_dir)) != NULL) { g_string_erase ( buffer, cp - basename, strlen (old_base_dir)); g_string_insert ( buffer, cp - basename, new_base_dir); } old_filename = g_build_filename ( src_directory, basename, NULL); new_filename = g_build_filename ( dst_directory, buffer->str, NULL); g_string_free (buffer, TRUE); g_hash_table_insert (corrections, old_filename, new_filename); } g_free (old_base_dir); g_free (new_base_dir); g_dir_close (dir); shell_xdg_migrate_process_corrections (corrections); g_hash_table_destroy (corrections); /* It's tempting to want to remove the source directory here. * Don't. We might be iterating over the source directory's * parent directory, and removing the source directory would * screw up the iteration. */ return TRUE; }
/** * e_shell_run_save_dialog: * @shell: an #EShell * @title: file chooser dialog title * @suggestion: file name suggestion, or %NULL * @filters: Possible filters for dialog, or %NULL * @customize_func: optional dialog customization function * @customize_data: optional data to pass to @customize_func * * Runs a #GtkFileChooserDialog in save mode with the given title and * returns the selected #GFile. If @customize_func is provided, the * function is called just prior to running the dialog (the file chooser * is the first argument, @customize_data is the second). If the user * cancels the dialog the function will return %NULL. * * With non-%NULL @filters will be added also file filters to the dialog. * The string format is "pat1:mt1;pat2:mt2:...", where 'pat' is a pattern * and 'mt' is a MIME type for the pattern to be used. There can be more * than one MIME type, those are separated by comma. * * Returns: the #GFile to save to, or %NULL **/ GFile * e_shell_run_save_dialog (EShell *shell, const gchar *title, const gchar *suggestion, const gchar *filters, GtkCallback customize_func, gpointer customize_data) { GtkFileChooser *file_chooser; GFile *chosen_file = NULL; GtkWidget *dialog; GtkWindow *parent; g_return_val_if_fail (E_IS_SHELL (shell), NULL); parent = e_shell_get_active_window (shell); dialog = gtk_file_chooser_dialog_new ( title, parent, GTK_FILE_CHOOSER_ACTION_SAVE, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Save"), GTK_RESPONSE_ACCEPT, NULL); file_chooser = GTK_FILE_CHOOSER (dialog); gtk_dialog_set_default_response ( GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_file_chooser_set_local_only (file_chooser, FALSE); gtk_file_chooser_set_do_overwrite_confirmation (file_chooser, TRUE); if (suggestion != NULL) { gchar *current_name; current_name = g_strdup (suggestion); e_filename_make_safe (current_name); gtk_file_chooser_set_current_name (file_chooser, current_name); g_free (current_name); } if (filters != NULL) { gchar **flts = g_strsplit (filters, ";", -1); gint i; for (i = 0; flts && flts[i]; i++) { GtkFileFilter *filter = gtk_file_filter_new (); gchar *flt = flts[i]; gchar *delim = strchr (flt, ':'), *next = NULL; if (delim) { *delim = 0; next = strchr (delim + 1, ','); } gtk_file_filter_add_pattern (filter, flt); if (g_ascii_strcasecmp (flt, "*.mbox") == 0) gtk_file_filter_set_name ( filter, _("Berkeley Mailbox (mbox)")); else if (g_ascii_strcasecmp (flt, "*.vcf") == 0) gtk_file_filter_set_name ( filter, _("vCard (.vcf)")); else if (g_ascii_strcasecmp (flt, "*.ics") == 0) gtk_file_filter_set_name ( filter, _("iCalendar (.ics)")); else gtk_file_filter_set_name (filter, flt); while (delim) { delim++; if (next) *next = 0; gtk_file_filter_add_mime_type (filter, delim); delim = next; if (next) next = strchr (next + 1, ','); } gtk_file_chooser_add_filter (file_chooser, filter); } if (flts && flts[0]) { GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*"); gtk_file_filter_set_name (filter, _("All Files (*)")); gtk_file_chooser_add_filter (file_chooser, filter); } g_strfreev (flts); } /* Allow further customizations before running the dialog. */ if (customize_func != NULL) customize_func (dialog, customize_data); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) chosen_file = gtk_file_chooser_get_file (file_chooser); gtk_widget_destroy (dialog); return chosen_file; }