diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2013-08-18 00:02:35 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-09-08 10:45:02 +0800 |
commit | 39ed315af4dbddfcb9d9485a6a22e72be57ff782 (patch) | |
tree | f196cfb51457d166ffb581ed4e12324840c05b63 /e-util | |
parent | 74508069b860033b1f731d4e26c163d9741f2064 (diff) | |
download | gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar.gz gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar.bz2 gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar.lz gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar.xz gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.tar.zst gsoc2013-evolution-39ed315af4dbddfcb9d9485a6a22e72be57ff782.zip |
Add properties and widgets to support archive extraction
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-attachment-store.c | 74 | ||||
-rw-r--r-- | e-util/e-attachment-view.c | 1 | ||||
-rw-r--r-- | e-util/e-attachment.c | 85 | ||||
-rw-r--r-- | e-util/e-attachment.h | 6 |
4 files changed, 164 insertions, 2 deletions
diff --git a/e-util/e-attachment-store.c b/e-util/e-attachment-store.c index 3720baf16b..4635abc1d3 100644 --- a/e-util/e-attachment-store.c +++ b/e-util/e-attachment-store.c @@ -28,6 +28,7 @@ #include <errno.h> #include <glib/gi18n.h> +#include <gnome-autoar/autoar.h> #include "e-mktemp.h" @@ -522,6 +523,20 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, GtkFileChooser *file_chooser; GtkFileChooserAction action; GtkWidget *dialog; + + GtkBox *extra_box; + GtkWidget *extra_box_widget; + + GtkBox *extract_box; + GtkWidget *extract_box_widget; + + GSList *extract_group; + GtkWidget *extract_only, *extract_org; + GtkToggleButton *extract_only_toggle; + + GtkWidget *extract_yes; + GtkToggleButton *extract_yes_toggle; + GFile *destination; const gchar *title; gint response; @@ -552,10 +567,42 @@ 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"); + extra_box_widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + extra_box = GTK_BOX (extra_box_widget); + + extract_yes = gtk_check_button_new_with_mnemonic ( + _("E_xtract files from the attachment if it is an archive")); + extract_yes_toggle = GTK_TOGGLE_BUTTON (extract_yes); + gtk_box_pack_start (extra_box, extract_yes, FALSE, FALSE, 0); + + 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_only = gtk_radio_button_new_with_mnemonic (NULL, + _("Save extracted files _only")); + extract_only_toggle = GTK_TOGGLE_BUTTON (extract_only); + extract_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (extract_only)); + gtk_box_pack_start (extract_box, extract_only, FALSE, FALSE, 0); + + 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); + + g_object_bind_property (extract_yes, "active", extract_box, "visible", 0); + gtk_toggle_button_set_active (extract_yes_toggle, TRUE); + gtk_toggle_button_set_active (extract_only_toggle, TRUE); + + gtk_widget_show_all (extra_box_widget); + gtk_file_chooser_set_extra_widget (file_chooser, extra_box_widget); + if (action == GTK_FILE_CHOOSER_ACTION_SAVE) { EAttachment *attachment; + AutoarPref *arpref; + GSettings *settings; GFileInfo *file_info; const gchar *name = NULL; + gchar *mime_type; attachment = attachment_list->data; file_info = e_attachment_ref_file_info (attachment); @@ -569,15 +616,38 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, gtk_file_chooser_set_current_name (file_chooser, name); + 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_toggle_button_set_active (extract_yes_toggle, FALSE); + } + g_clear_object (&file_info); + g_clear_object (&settings); + g_clear_object (&arpref); + g_free (mime_type); } response = gtk_dialog_run (GTK_DIALOG (dialog)); - if (response == GTK_RESPONSE_OK) + if (response == GTK_RESPONSE_OK) { + GList *iter; + gboolean save_self, save_extracted; + destination = gtk_file_chooser_get_file (file_chooser); - else + save_self = !gtk_toggle_button_get_active (extract_yes_toggle) || + !gtk_toggle_button_get_active (extract_only_toggle); + save_extracted = gtk_toggle_button_get_active (extract_yes_toggle); + + for (iter = attachment_list; iter != NULL; iter = iter->next) { + e_attachment_set_save_self (iter->data, save_self); + e_attachment_set_save_extracted (iter->data, save_extracted); + } + } else { destination = NULL; + } gtk_widget_destroy (dialog); diff --git a/e-util/e-attachment-view.c b/e-util/e-attachment-view.c index 383fc12e21..131e0c56d7 100644 --- a/e-util/e-attachment-view.c +++ b/e-util/e-attachment-view.c @@ -257,6 +257,7 @@ action_save_all_cb (GtkAction *action, GList *list, *iter; GFile *destination; gpointer parent; + gboolean save_attachments, save_extracted_files; store = e_attachment_view_get_store (view); diff --git a/e-util/e-attachment.c b/e-util/e-attachment.c index bad4e0b460..16f4a6dbac 100644 --- a/e-util/e-attachment.c +++ b/e-util/e-attachment.c @@ -74,6 +74,9 @@ struct _EAttachmentPrivate { guint saving : 1; guint shown : 1; + guint save_self : 1; + guint save_extracted : 1; + camel_cipher_validity_encrypt_t encrypted; camel_cipher_validity_sign_t signed_; @@ -103,6 +106,8 @@ enum { PROP_MIME_PART, PROP_PERCENT, PROP_REFERENCE, + PROP_SAVE_SELF, + PROP_SAVE_EXTRACTED, PROP_SAVING, PROP_SHOWN, PROP_SIGNED @@ -665,6 +670,18 @@ attachment_set_property (GObject *object, E_ATTACHMENT (object), g_value_get_int (value)); return; + + case PROP_SAVE_SELF: + e_attachment_set_save_self ( + E_ATTACHMENT (object), + g_value_get_boolean (value)); + return; + + case PROP_SAVE_EXTRACTED: + e_attachment_set_save_extracted ( + E_ATTACHMENT (object), + g_value_get_boolean (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -754,6 +771,20 @@ attachment_get_property (GObject *object, E_ATTACHMENT (object))); return; + case PROP_SAVE_SELF: + g_value_set_boolean ( + value, + e_attachment_get_save_self ( + E_ATTACHMENT (object))); + return; + + case PROP_SAVE_EXTRACTED: + g_value_set_boolean ( + value, + e_attachment_get_save_extracted ( + E_ATTACHMENT (object))); + return; + case PROP_SAVING: g_value_set_boolean ( value, @@ -947,6 +978,26 @@ e_attachment_class_init (EAttachmentClass *class) g_object_class_install_property ( object_class, + PROP_SAVE_SELF, + g_param_spec_boolean ( + "save-self", + "Save self", + NULL, + TRUE, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_SAVE_EXTRACTED, + g_param_spec_boolean ( + "save-extracted", + "Save extracted", + NULL, + FALSE, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, PROP_SAVING, g_param_spec_boolean ( "saving", @@ -1520,6 +1571,40 @@ e_attachment_set_shown (EAttachment *attachment, g_object_notify (G_OBJECT (attachment), "shown"); } +gboolean +e_attachment_get_save_self (EAttachment *attachment) +{ + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), TRUE); + + return attachment->priv->save_self; +} + +void +e_attachment_set_save_self (EAttachment *attachment, + gboolean save_self) +{ + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + + attachment->priv->save_self = save_self; +} + +gboolean +e_attachment_get_save_extracted (EAttachment *attachment) +{ + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE); + + return attachment->priv->save_extracted; +} + +void +e_attachment_set_save_extracted (EAttachment *attachment, + gboolean save_extracted) +{ + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + + attachment->priv->save_extracted = save_extracted; +} + camel_cipher_validity_encrypt_t e_attachment_get_encrypted (EAttachment *attachment) { diff --git a/e-util/e-attachment.h b/e-util/e-attachment.h index b21a0f2899..2942d042de 100644 --- a/e-util/e-attachment.h +++ b/e-util/e-attachment.h @@ -100,6 +100,12 @@ gboolean e_attachment_get_saving (EAttachment *attachment); gboolean e_attachment_get_shown (EAttachment *attachment); void e_attachment_set_shown (EAttachment *attachment, gboolean shown); +gboolean e_attachment_get_save_self (EAttachment *attachment); +void e_attachment_set_save_self (EAttachment *attachment, + gboolean save_self); +gboolean e_attachment_get_save_extracted (EAttachment *attachment); +void e_attachment_set_save_extracted (EAttachment *attachment, + gboolean save_extracted); camel_cipher_validity_encrypt_t e_attachment_get_encrypted (EAttachment *attachment); void e_attachment_set_encrypted (EAttachment *attachment, |