aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-attachment-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'e-util/e-attachment-store.c')
-rw-r--r--e-util/e-attachment-store.c207
1 files changed, 199 insertions, 8 deletions
diff --git a/e-util/e-attachment-store.c b/e-util/e-attachment-store.c
index e867327e47..10970bb8cc 100644
--- a/e-util/e-attachment-store.c
+++ b/e-util/e-attachment-store.c
@@ -28,6 +28,11 @@
#include <errno.h>
#include <glib/gi18n.h>
+#ifdef HAVE_AUTOAR
+#include <gnome-autoar/autoar.h>
+#include <gnome-autoar/autoar-gtk.h>
+#endif
+
#include "e-mktemp.h"
#define E_ATTACHMENT_STORE_GET_PRIVATE(obj) \
@@ -448,26 +453,56 @@ e_attachment_store_run_load_dialog (EAttachmentStore *store,
{
GtkFileChooser *file_chooser;
GtkWidget *dialog;
- GtkWidget *option;
+
+ GtkBox *extra_box;
+ GtkWidget *extra_box_widget;
+ GtkWidget *option_display;
+
+#ifdef HAVE_AUTOAR
+ GtkBox *option_format_box;
+ GtkWidget *option_format_box_widget;
+ GtkWidget *option_format_label;
+ GtkWidget *option_format_combo;
+#endif
+
GtkImage *preview;
+
GSList *files, *iter;
const gchar *disposition;
gboolean active;
gint response;
+#ifdef HAVE_AUTOAR
+ GSettings *settings;
+ AutoarPref *arpref;
+ gint format, filter;
+#endif
+
g_return_if_fail (E_IS_ATTACHMENT_STORE (store));
g_return_if_fail (GTK_IS_WINDOW (parent));
dialog = gtk_file_chooser_dialog_new (
_("Add Attachment"), parent,
GTK_FILE_CHOOSER_ACTION_OPEN,
+#ifdef HAVE_AUTOAR
+ _("_Open"), GTK_RESPONSE_OK,
+#endif
_("_Cancel"), GTK_RESPONSE_CANCEL,
- _("A_ttach"), GTK_RESPONSE_OK, NULL);
+#ifdef HAVE_AUTOAR
+ _("A_ttach"), GTK_RESPONSE_CLOSE,
+#else
+ _("A_ttach"), GTK_RESPONSE_OK,
+#endif
+ NULL);
file_chooser = GTK_FILE_CHOOSER (dialog);
gtk_file_chooser_set_local_only (file_chooser, FALSE);
gtk_file_chooser_set_select_multiple (file_chooser, TRUE);
+#ifdef HAVE_AUTOAR
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
+#else
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+#endif
gtk_window_set_icon_name (GTK_WINDOW (dialog), "mail-attachment");
preview = GTK_IMAGE (gtk_image_new ());
@@ -478,20 +513,52 @@ e_attachment_store_run_load_dialog (EAttachmentStore *store,
file_chooser, "update-preview",
G_CALLBACK (update_preview_cb), preview);
- option = gtk_check_button_new_with_mnemonic (
+ extra_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ extra_box = GTK_BOX (extra_box_widget);
+
+ option_display = gtk_check_button_new_with_mnemonic (
_("_Suggest automatic display of attachment"));
- gtk_file_chooser_set_extra_widget (file_chooser, option);
- gtk_widget_show (option);
+ gtk_box_pack_start (extra_box, option_display, FALSE, FALSE, 0);
+
+#ifdef HAVE_AUTOAR
+ option_format_box_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ option_format_box = GTK_BOX (option_format_box_widget);
+ gtk_box_pack_start (extra_box, option_format_box_widget, FALSE, FALSE, 0);
+
+ settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
+ arpref = autoar_pref_new_with_gsettings (settings);
+
+ option_format_label = gtk_label_new (
+ _("Archive selected directories using this format:"));
+ option_format_combo = autoar_gtk_chooser_simple_new (
+ autoar_pref_get_default_format (arpref),
+ autoar_pref_get_default_filter (arpref));
+ gtk_box_pack_start (option_format_box, option_format_label, FALSE, FALSE, 0);
+ gtk_box_pack_start (option_format_box, option_format_combo, FALSE, FALSE, 0);
+#endif
+
+ gtk_file_chooser_set_extra_widget (file_chooser, extra_box_widget);
+ gtk_widget_show_all (extra_box_widget);
response = gtk_dialog_run (GTK_DIALOG (dialog));
+#ifdef HAVE_AUTOAR
+ if (response != GTK_RESPONSE_OK && response != GTK_RESPONSE_CLOSE)
+#else
if (response != GTK_RESPONSE_OK)
+#endif
goto exit;
files = gtk_file_chooser_get_files (file_chooser);
- active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (option));
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (option_display));
disposition = active ? "inline" : "attachment";
+#ifdef HAVE_AUTOAR
+ autoar_gtk_chooser_simple_get (option_format_combo, &format, &filter);
+ autoar_pref_set_default_format (arpref, format);
+ autoar_pref_set_default_filter (arpref, filter);
+#endif
+
for (iter = files; iter != NULL; iter = g_slist_next (iter)) {
EAttachment *attachment;
GFile *file = iter->data;
@@ -500,6 +567,12 @@ e_attachment_store_run_load_dialog (EAttachmentStore *store,
e_attachment_set_file (attachment, file);
e_attachment_set_disposition (attachment, disposition);
e_attachment_store_add_attachment (store, attachment);
+
+#ifdef HAVE_AUTOAR
+ g_object_set_data_full (G_OBJECT (attachment),
+ "autoar-pref", g_object_ref (arpref), g_object_unref);
+#endif
+
e_attachment_load_async (
attachment, (GAsyncReadyCallback)
e_attachment_load_handle_error, parent);
@@ -511,6 +584,10 @@ e_attachment_store_run_load_dialog (EAttachmentStore *store,
exit:
gtk_widget_destroy (dialog);
+#ifdef HAVE_AUTOAR
+ g_object_unref (settings);
+ g_object_unref (arpref);
+#endif
}
GFile *
@@ -521,6 +598,18 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store,
GtkFileChooser *file_chooser;
GtkFileChooserAction action;
GtkWidget *dialog;
+
+#ifdef HAVE_AUTOAR
+ GtkBox *extra_box;
+ GtkWidget *extra_box_widget;
+
+ GtkBox *extract_box;
+ GtkWidget *extract_box_widget;
+
+ GSList *extract_group;
+ GtkWidget *extract_dont, *extract_only, *extract_org;
+#endif
+
GFile *destination;
const gchar *title;
gint response;
@@ -551,11 +640,45 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store,
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_window_set_icon_name (GTK_WINDOW (dialog), "mail-attachment");
+#ifdef HAVE_AUTOAR
+ extra_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ extra_box = GTK_BOX (extra_box_widget);
+
+ extract_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ extract_box = GTK_BOX (extract_box_widget);
+ gtk_box_pack_start (extra_box, extract_box_widget, FALSE, FALSE, 5);
+
+ extract_dont = gtk_radio_button_new_with_mnemonic (NULL,
+ _("Do _not extract files from the attachment"));
+ gtk_box_pack_start (extract_box, extract_dont, FALSE, FALSE, 0);
+
+ extract_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (extract_dont));
+ extract_only = gtk_radio_button_new_with_mnemonic (extract_group,
+ _("Save extracted files _only"));
+ gtk_box_pack_start (extract_box, extract_only, FALSE, FALSE, 0);
+
+ extract_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (extract_only));
+ extract_org = gtk_radio_button_new_with_mnemonic (extract_group,
+ _("Save extracted files and the original _archive"));
+ gtk_box_pack_start (extract_box, extract_org, FALSE, FALSE, 0);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (extract_dont), TRUE);
+
+ gtk_widget_show_all (extra_box_widget);
+ gtk_file_chooser_set_extra_widget (file_chooser, extra_box_widget);
+#endif
+
if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
EAttachment *attachment;
GFileInfo *file_info;
const gchar *name = NULL;
+#ifdef HAVE_AUTOAR
+ AutoarPref *arpref;
+ GSettings *settings;
+ gchar *mime_type;
+#endif
+
attachment = attachment_list->data;
file_info = e_attachment_ref_file_info (attachment);
@@ -568,15 +691,83 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store,
gtk_file_chooser_set_current_name (file_chooser, name);
+#ifdef HAVE_AUTOAR
+ mime_type = e_attachment_dup_mime_type (attachment);
+ settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
+ arpref = autoar_pref_new_with_gsettings (settings);
+ if (!autoar_pref_check_file_name (arpref, name) &&
+ !autoar_pref_check_mime_type_d (arpref, mime_type)) {
+ gtk_widget_hide (extra_box_widget);
+ }
+
+ g_clear_object (&settings);
+ g_clear_object (&arpref);
+ g_free (mime_type);
+#endif
+
g_clear_object (&file_info);
}
response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (response == GTK_RESPONSE_OK)
+ if (response == GTK_RESPONSE_OK) {
+#ifdef HAVE_AUTOAR
+ gboolean save_self, save_extracted;
+#endif
+
destination = gtk_file_chooser_get_file (file_chooser);
- else
+
+#ifdef HAVE_AUTOAR
+ save_self =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extract_dont)) ||
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extract_org));
+ save_extracted =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extract_only)) ||
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (extract_org));
+
+ if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
+ e_attachment_set_save_self (attachment_list->data, save_self);
+ e_attachment_set_save_extracted (attachment_list->data, save_extracted);
+ } else {
+ AutoarPref *arpref;
+ GSettings *settings;
+ GList *iter;
+
+ settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
+ arpref = autoar_pref_new_with_gsettings (settings);
+
+ for (iter = attachment_list; iter != NULL; iter = iter->next) {
+ EAttachment *attachment;
+ GFileInfo *file_info;
+ const gchar *name;
+ gchar *mime_type;
+
+ attachment = iter->data;
+ file_info = e_attachment_ref_file_info (attachment);
+ name = g_file_info_get_display_name (file_info);
+ mime_type = e_attachment_dup_mime_type (attachment);
+
+ if ((name != NULL &&
+ autoar_pref_check_file_name (arpref, name)) ||
+ autoar_pref_check_mime_type_d (arpref, mime_type)) {
+ e_attachment_set_save_self (attachment, save_self);
+ e_attachment_set_save_extracted (attachment, save_extracted);
+ } else {
+ e_attachment_set_save_self (attachment, TRUE);
+ e_attachment_set_save_extracted (attachment, FALSE);
+ }
+
+ g_object_unref (file_info);
+ g_free (mime_type);
+ }
+
+ g_object_unref (settings);
+ g_object_unref (arpref);
+ }
+#endif
+ } else {
destination = NULL;
+ }
gtk_widget_destroy (dialog);