aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-05-23 00:11:49 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-05-24 04:36:01 +0800
commit256422cab27d0b7adbe99fdeaceb72cd78c129bb (patch)
tree8d087e570e7656e7d088232d98c52636c95baed0 /e-util
parent37c5951635a4f45ba26b0f95ce7af61275d47fba (diff)
downloadgsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.gz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.bz2
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.lz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.xz
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.tar.zst
gsoc2013-evolution-256422cab27d0b7adbe99fdeaceb72cd78c129bb.zip
Attachment-related cleanups.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-attachment-button.c99
-rw-r--r--e-util/e-attachment-handler-image.c14
-rw-r--r--e-util/e-attachment-store.c16
-rw-r--r--e-util/e-attachment.c140
4 files changed, 137 insertions, 132 deletions
diff --git a/e-util/e-attachment-button.c b/e-util/e-attachment-button.c
index a2057e3354..7778bb106f 100644
--- a/e-util/e-attachment-button.c
+++ b/e-util/e-attachment-button.c
@@ -271,58 +271,57 @@ attachment_button_expand_drag_data_get_cb (EAttachmentButton *button,
guint time)
{
EAttachmentView *view;
+ EAttachment *attachment;
+ gchar *mime_type = NULL;
- if (button->priv->attachment) {
- gchar *mime_type;
-
- mime_type = e_attachment_get_mime_type (
- button->priv->attachment);
-
- if (mime_type) {
- gboolean processed = FALSE;
- GdkAtom atom;
- gchar *atom_name;
-
- atom = gtk_selection_data_get_target (selection);
- atom_name = gdk_atom_name (atom);
-
- if (g_strcmp0 (atom_name, mime_type) == 0) {
- CamelMimePart *mime_part;
-
- mime_part = e_attachment_get_mime_part (
- button->priv->attachment);
-
- if (CAMEL_IS_MIME_PART (mime_part)) {
- CamelDataWrapper *wrapper;
- CamelStream *stream;
- GByteArray *buffer;
-
- buffer = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (
- CAMEL_STREAM_MEM (stream),
- buffer);
- wrapper = camel_medium_get_content (
- CAMEL_MEDIUM (mime_part));
- camel_data_wrapper_decode_to_stream_sync (
- wrapper, stream, NULL, NULL);
- g_object_unref (stream);
-
- gtk_selection_data_set (
- selection, atom, 8,
- buffer->data, buffer->len);
- processed = TRUE;
-
- g_byte_array_free (buffer, TRUE);
- }
- }
+ attachment = e_attachment_button_get_attachment (button);
+
+ if (attachment != NULL)
+ mime_type = e_attachment_get_mime_type (attachment);
+
+ if (mime_type != NULL) {
+ gboolean processed = FALSE;
+ GdkAtom atom;
+ gchar *atom_name;
+
+ atom = gtk_selection_data_get_target (selection);
+ atom_name = gdk_atom_name (atom);
+
+ if (g_strcmp0 (atom_name, mime_type) == 0) {
+ CamelMimePart *mime_part;
+
+ mime_part = e_attachment_get_mime_part (attachment);
- g_free (atom_name);
- g_free (mime_type);
+ if (mime_part != NULL) {
+ CamelDataWrapper *wrapper;
+ CamelStream *stream;
+ GByteArray *buffer;
- if (processed)
- return;
+ buffer = g_byte_array_new ();
+ stream = camel_stream_mem_new ();
+ camel_stream_mem_set_byte_array (
+ CAMEL_STREAM_MEM (stream),
+ buffer);
+ wrapper = camel_medium_get_content (
+ CAMEL_MEDIUM (mime_part));
+ camel_data_wrapper_decode_to_stream_sync (
+ wrapper, stream, NULL, NULL);
+ g_object_unref (stream);
+
+ gtk_selection_data_set (
+ selection, atom, 8,
+ buffer->data, buffer->len);
+ processed = TRUE;
+
+ g_byte_array_free (buffer, TRUE);
+ }
}
+
+ g_free (atom_name);
+ g_free (mime_type);
+
+ if (processed)
+ return;
}
view = e_attachment_button_get_view (button);
@@ -787,11 +786,11 @@ e_attachment_button_set_attachment (EAttachmentButton *button,
list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_uri_targets (list, 0);
- if (attachment) {
+ if (attachment != NULL) {
gchar *simple_type;
simple_type = e_attachment_get_mime_type (attachment);
- if (simple_type) {
+ if (simple_type != NULL) {
GtkTargetEntry attach_entry[] = { { NULL, 0, 2 } };
attach_entry[0].target = simple_type;
diff --git a/e-util/e-attachment-handler-image.c b/e-util/e-attachment-handler-image.c
index 36c3a83614..602f001ba6 100644
--- a/e-util/e-attachment-handler-image.c
+++ b/e-util/e-attachment-handler-image.c
@@ -155,9 +155,7 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
EAttachmentHandler *handler)
{
EAttachment *attachment;
- GFileInfo *file_info;
GtkActionGroup *action_group;
- const gchar *content_type;
gchar *mime_type;
GList *selected;
gboolean visible = FALSE;
@@ -168,10 +166,6 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
goto exit;
attachment = E_ATTACHMENT (selected->data);
- file_info = e_attachment_get_file_info (attachment);
-
- if (file_info == NULL)
- goto exit;
if (e_attachment_get_loading (attachment))
goto exit;
@@ -179,10 +173,10 @@ attachment_handler_image_update_actions_cb (EAttachmentView *view,
if (e_attachment_get_saving (attachment))
goto exit;
- content_type = g_file_info_get_content_type (file_info);
-
- mime_type = g_content_type_get_mime_type (content_type);
- visible = (g_ascii_strncasecmp (mime_type, "image/", 6) == 0);
+ mime_type = e_attachment_get_mime_type (attachment);
+ visible =
+ (mime_type != NULL) &&
+ (g_ascii_strncasecmp (mime_type, "image/", 6) == 0);
g_free (mime_type);
exit:
diff --git a/e-util/e-attachment-store.c b/e-util/e-attachment-store.c
index 55bc795095..8ea2f8965b 100644
--- a/e-util/e-attachment-store.c
+++ b/e-util/e-attachment-store.c
@@ -727,18 +727,18 @@ e_attachment_store_get_uris_async (EAttachmentStore *store,
for (iter = attachment_list; iter != NULL; iter = iter->next) {
EAttachment *attachment = iter->data;
GFile *file;
- gchar *uri;
file = e_attachment_get_file (attachment);
- if (file == NULL)
- continue;
+ if (file != NULL) {
+ gchar *uri;
- uri = g_file_get_uri (file);
- uri_context->uris[uri_context->index++] = uri;
+ uri = g_file_get_uri (file);
+ uri_context->uris[uri_context->index++] = uri;
- /* Mark the list node for deletion. */
- trash = g_list_prepend (trash, iter);
- g_object_unref (attachment);
+ /* Mark the list node for deletion. */
+ trash = g_list_prepend (trash, iter);
+ g_object_unref (attachment);
+ }
}
/* Expunge the list. */
diff --git a/e-util/e-attachment.c b/e-util/e-attachment.c
index 495c805f16..9f758c510c 100644
--- a/e-util/e-attachment.c
+++ b/e-util/e-attachment.c
@@ -110,34 +110,35 @@ create_system_thumbnail (EAttachment *attachment,
{
GFile *file;
GFile *icon_file;
+ gchar *file_path = NULL;
gchar *thumbnail = NULL;
+ gboolean success = FALSE;
- g_return_val_if_fail (attachment != NULL, FALSE);
+ g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
g_return_val_if_fail (icon != NULL, FALSE);
file = e_attachment_get_file (attachment);
+ if (file != NULL)
+ file_path = g_file_get_path (file);
- if (file && g_file_has_uri_scheme (file, "file")) {
- gchar *path = g_file_get_path (file);
- if (path) {
- thumbnail = e_icon_factory_create_thumbnail (path);
- g_free (path);
- }
+ if (file_path != NULL) {
+ thumbnail = e_icon_factory_create_thumbnail (file_path);
+ g_free (file_path);
}
if (thumbnail == NULL)
- return FALSE;
+ goto exit;
icon_file = g_file_new_for_path (thumbnail);
- if (*icon)
+ if (*icon != NULL)
g_object_unref (*icon);
*icon = g_file_icon_new (icon_file);
g_object_unref (icon_file);
- if (file) {
+ if (file != NULL) {
GFileInfo *file_info;
const gchar *attribute;
@@ -151,7 +152,10 @@ create_system_thumbnail (EAttachment *attachment,
g_free (thumbnail);
- return TRUE;
+ success = TRUE;
+
+exit:
+ return success;
}
static gchar *
@@ -535,7 +539,7 @@ attachment_set_property (GObject *object,
case PROP_MIME_PART:
e_attachment_set_mime_part (
E_ATTACHMENT (object),
- g_value_get_boxed (value));
+ g_value_get_object (value));
return;
case PROP_REFERENCE:
@@ -563,79 +567,92 @@ attachment_get_property (GObject *object,
switch (property_id) {
case PROP_CAN_SHOW:
g_value_set_boolean (
- value, e_attachment_get_can_show (
+ value,
+ e_attachment_get_can_show (
E_ATTACHMENT (object)));
return;
case PROP_DISPOSITION:
g_value_set_string (
- value, e_attachment_get_disposition (
+ value,
+ e_attachment_get_disposition (
E_ATTACHMENT (object)));
return;
case PROP_ENCRYPTED:
g_value_set_int (
- value, e_attachment_get_encrypted (
+ value,
+ e_attachment_get_encrypted (
E_ATTACHMENT (object)));
return;
case PROP_FILE:
g_value_set_object (
- value, e_attachment_get_file (
+ value,
+ e_attachment_get_file (
E_ATTACHMENT (object)));
return;
case PROP_FILE_INFO:
g_value_set_object (
- value, e_attachment_get_file_info (
+ value,
+ e_attachment_get_file_info (
E_ATTACHMENT (object)));
return;
case PROP_ICON:
g_value_set_object (
- value, e_attachment_get_icon (
+ value,
+ e_attachment_get_icon (
E_ATTACHMENT (object)));
return;
case PROP_SHOWN:
g_value_set_boolean (
- value, e_attachment_get_shown (
+ value,
+ e_attachment_get_shown (
E_ATTACHMENT (object)));
return;
case PROP_LOADING:
g_value_set_boolean (
- value, e_attachment_get_loading (
+ value,
+ e_attachment_get_loading (
E_ATTACHMENT (object)));
return;
case PROP_MIME_PART:
- g_value_set_boxed (
- value, e_attachment_get_mime_part (
+ g_value_set_object (
+ value,
+ e_attachment_get_mime_part (
E_ATTACHMENT (object)));
return;
case PROP_PERCENT:
g_value_set_int (
- value, e_attachment_get_percent (
+ value,
+ e_attachment_get_percent (
E_ATTACHMENT (object)));
return;
case PROP_REFERENCE:
g_value_set_boxed (
- value, e_attachment_get_reference (
+ value,
+ e_attachment_get_reference (
E_ATTACHMENT (object)));
return;
case PROP_SAVING:
g_value_set_boolean (
- value, e_attachment_get_saving (
+ value,
+ e_attachment_get_saving (
E_ATTACHMENT (object)));
return;
case PROP_SIGNED:
g_value_set_int (
- value, e_attachment_get_signed (
+ value,
+ e_attachment_get_signed (
E_ATTACHMENT (object)));
return;
}
@@ -650,30 +667,11 @@ attachment_dispose (GObject *object)
priv = E_ATTACHMENT_GET_PRIVATE (object);
- if (priv->file != NULL) {
- g_object_unref (priv->file);
- priv->file = NULL;
- }
-
- if (priv->icon != NULL) {
- g_object_unref (priv->icon);
- priv->icon = NULL;
- }
-
- if (priv->file_info != NULL) {
- g_object_unref (priv->file_info);
- priv->file_info = NULL;
- }
-
- if (priv->cancellable != NULL) {
- g_object_unref (priv->cancellable);
- priv->cancellable = NULL;
- }
-
- if (priv->mime_part != NULL) {
- g_object_unref (priv->mime_part);
- priv->mime_part = NULL;
- }
+ g_clear_object (&priv->file);
+ g_clear_object (&priv->icon);
+ g_clear_object (&priv->file_info);
+ g_clear_object (&priv->cancellable);
+ g_clear_object (&priv->mime_part);
if (priv->emblem_timeout_id > 0) {
g_source_remove (priv->emblem_timeout_id);
@@ -1198,10 +1196,13 @@ e_attachment_set_file_info (EAttachment *attachment,
/**
* e_attachment_get_mime_type:
+ * @attachment: an #EAttachment
+ *
+ * Returns the MIME type of @attachment according to its #GFileInfo.
+ * If the @attachment has no #GFileInfo then the function returns %NULL.
+ * Free the returned MIME type string with g_free().
*
- * Returns mime_type part of the file_info as a newly allocated string,
- * which should be freed with g_free().
- * Returns NULL, if mime_type not found or set on the attachment.
+ * Returns: a newly-allocated MIME type string, or %NULL
**/
gchar *
e_attachment_get_mime_type (EAttachment *attachment)
@@ -1415,7 +1416,9 @@ e_attachment_is_rfc822 (EAttachment *attachment)
g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE);
mime_type = e_attachment_get_mime_type (attachment);
- is_rfc822 = mime_type && g_ascii_strcasecmp (mime_type, "message/rfc822") == 0;
+ is_rfc822 =
+ (mime_type != NULL) &&
+ (g_ascii_strcasecmp (mime_type, "message/rfc822") == 0);
g_free (mime_type);
return is_rfc822;
@@ -1789,7 +1792,8 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
CamelStream *null;
CamelDataWrapper *dw;
- load_context = g_object_get_data (G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT);
+ load_context = g_object_get_data (
+ G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT);
g_return_if_fail (load_context != NULL);
g_object_set_data (G_OBJECT (simple), ATTACHMENT_LOAD_CONTEXT, NULL);
@@ -1849,15 +1853,16 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
} else {
CamelDataWrapper *content;
- content = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ content = camel_medium_get_content (
+ CAMEL_MEDIUM (mime_part));
if (CAMEL_IS_MIME_MESSAGE (content))
msg = CAMEL_MIME_MESSAGE (content);
}
- if (msg)
+ if (msg != NULL)
subject = camel_mime_message_get_subject (msg);
- if (subject && *subject)
+ if (subject != NULL && *subject != '\0')
string = subject;
}
} else {
@@ -1883,7 +1888,8 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
null = camel_stream_null_new ();
/* this actually downloads the part and makes it available later */
- camel_data_wrapper_decode_to_stream_sync (dw, null, attachment->priv->cancellable, NULL);
+ camel_data_wrapper_decode_to_stream_sync (
+ dw, null, attachment->priv->cancellable, NULL);
g_file_info_set_size (file_info, CAMEL_STREAM_NULL (null)->written);
g_object_unref (null);
@@ -1944,7 +1950,9 @@ e_attachment_load_async (EAttachment *attachment,
attachment_load_query_info_cb, load_context);
} else if (mime_part != NULL) {
- g_object_set_data (G_OBJECT (load_context->simple), ATTACHMENT_LOAD_CONTEXT, load_context);
+ g_object_set_data (
+ G_OBJECT (load_context->simple),
+ ATTACHMENT_LOAD_CONTEXT, load_context);
g_simple_async_result_run_in_thread (
load_context->simple,
@@ -1967,14 +1975,18 @@ e_attachment_load_finish (EAttachment *attachment,
simple = G_SIMPLE_ASYNC_RESULT (result);
load_context = g_simple_async_result_get_op_res_gpointer (simple);
- if (load_context && load_context->mime_part) {
+
+ if (load_context != NULL && load_context->mime_part != NULL) {
const gchar *string;
- string = camel_mime_part_get_disposition (load_context->mime_part);
+ string = camel_mime_part_get_disposition (
+ load_context->mime_part);
e_attachment_set_disposition (attachment, string);
- e_attachment_set_file_info (attachment, load_context->file_info);
- e_attachment_set_mime_part (attachment, load_context->mime_part);
+ e_attachment_set_file_info (
+ attachment, load_context->file_info);
+ e_attachment_set_mime_part (
+ attachment, load_context->mime_part);
}
g_simple_async_result_propagate_error (simple, error);