aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-attachment-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc/e-attachment-store.c')
-rw-r--r--widgets/misc/e-attachment-store.c81
1 files changed, 46 insertions, 35 deletions
diff --git a/widgets/misc/e-attachment-store.c b/widgets/misc/e-attachment-store.c
index 9d0fe6d21e..216a60d32a 100644
--- a/widgets/misc/e-attachment-store.c
+++ b/widgets/misc/e-attachment-store.c
@@ -360,12 +360,35 @@ e_attachment_store_add_to_multipart (EAttachmentStore *store,
CamelMultipart *multipart,
const gchar *default_charset)
{
+ GList *list, *iter;
+
+ g_return_if_fail (E_IS_ATTACHMENT_STORE (store));
+ g_return_if_fail (CAMEL_MULTIPART (multipart));
+
+ list = e_attachment_store_get_attachments (store);
+
+ for (iter = list; iter != NULL; iter = iter->next) {
+ EAttachment *attachment = iter->data;
+
+ /* Skip the attachment if it's still loading. */
+ if (!e_attachment_get_loading (attachment))
+ e_attachment_add_to_multipart (
+ attachment, multipart, default_charset);
+ }
+
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
+}
+
+GList *
+e_attachment_store_get_attachments (EAttachmentStore *store)
+{
+ GList *list = NULL;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean valid;
- g_return_if_fail (E_IS_ATTACHMENT_STORE (store));
- g_return_if_fail (CAMEL_MULTIPART (multipart));
+ g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), NULL);
model = GTK_TREE_MODEL (store);
valid = gtk_tree_model_get_iter_first (model, &iter);
@@ -377,15 +400,12 @@ e_attachment_store_add_to_multipart (EAttachmentStore *store,
column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT;
gtk_tree_model_get (model, &iter, column_id, &attachment, -1);
- /* Skip the attachment if it's still loading. */
- if (!e_attachment_get_loading (attachment))
- e_attachment_add_to_multipart (
- attachment, multipart, default_charset);
-
- g_object_unref (attachment);
+ list = g_list_prepend (list, attachment);
valid = gtk_tree_model_iter_next (model, &iter);
}
+
+ return g_list_reverse (list);
}
const gchar *
@@ -422,60 +442,48 @@ e_attachment_store_get_num_attachments (EAttachmentStore *store)
guint
e_attachment_store_get_num_loading (EAttachmentStore *store)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GList *list, *iter;
guint num_loading = 0;
- gboolean valid;
g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), 0);
- model = GTK_TREE_MODEL (store);
- valid = gtk_tree_model_get_iter_first (model, &iter);
+ list = e_attachment_store_get_attachments (store);
- while (valid) {
- EAttachment *attachment;
- gint column_id;
+ for (iter = list; iter != NULL; iter = iter->next) {
+ EAttachment *attachment = iter->data;
- column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT;
- gtk_tree_model_get (model, &iter, column_id, &attachment, -1);
if (e_attachment_get_loading (attachment))
num_loading++;
- g_object_unref (attachment);
-
- valid = gtk_tree_model_iter_next (model, &iter);
}
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
+
return num_loading;
}
goffset
e_attachment_store_get_total_size (EAttachmentStore *store)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GList *list, *iter;
goffset total_size = 0;
- gboolean valid;
g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), 0);
- model = GTK_TREE_MODEL (store);
- valid = gtk_tree_model_get_iter_first (model, &iter);
+ list = e_attachment_store_get_attachments (store);
- while (valid) {
- EAttachment *attachment;
+ for (iter = list; iter != NULL; iter = iter->next) {
+ EAttachment *attachment = iter->data;
GFileInfo *file_info;
- gint column_id;
- column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT;
- gtk_tree_model_get (model, &iter, column_id, &attachment, -1);
file_info = e_attachment_get_file_info (attachment);
if (file_info != NULL)
total_size += g_file_info_get_size (file_info);
- g_object_unref (attachment);
-
- valid = gtk_tree_model_iter_next (model, &iter);
}
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
+
return total_size;
}
@@ -839,11 +847,13 @@ e_attachment_store_get_uris_async (EAttachmentStore *store,
/* Any remaining attachments in the list should have MIME parts
* only, so we need to save them all to a temporary directory.
- * We use a directory so the files can retain their basenames. */
+ * We use a directory so the files can retain their basenames.
+ * XXX This could trigger a blocking temp directory cleanup. */
template = g_strdup_printf (PACKAGE "-%s-XXXXXX", g_get_user_name ());
path = e_mkdtemp (template);
g_free (template);
+ /* XXX Let's hope errno got set property. */
if (path == NULL) {
GSimpleAsyncResult *simple;
@@ -871,6 +881,7 @@ e_attachment_store_get_uris_async (EAttachmentStore *store,
uri_context);
g_object_unref (temp_directory);
+ g_free (path);
}
gchar **