* update code for new mu_msg_part_for_each API

This commit is contained in:
djcb 2012-02-13 22:36:22 +02:00
parent 3bb93a401b
commit 0d08ff903d
4 changed files with 51 additions and 42 deletions

View File

@ -418,7 +418,7 @@ SCM_DEFINE_PUBLIC (get_parts, "mu:get-parts", 1, 1, 0,
attinfo.attachments_only = ATTS_ONLY == SCM_BOOL_T ? TRUE : FALSE; attinfo.attachments_only = ATTS_ONLY == SCM_BOOL_T ? TRUE : FALSE;
msgwrap = (MuMsgWrapper*) SCM_CDR(MSG); msgwrap = (MuMsgWrapper*) SCM_CDR(MSG);
mu_msg_part_foreach (msgwrap->_msg, mu_msg_part_foreach (msgwrap->_msg, FALSE,
(MuMsgPartForeachFunc)each_part, (MuMsgPartForeachFunc)each_part,
&attinfo); &attinfo);

View File

@ -39,13 +39,19 @@ save_part (MuMsg *msg, const char *targetdir, guint partidx, gboolean overwrite,
GError *err; GError *err;
gchar *filepath; gchar *filepath;
filepath = mu_msg_part_filepath (msg, targetdir, partidx); err = NULL;
filepath = mu_msg_part_filepath (msg, targetdir, partidx, &err);
if (!filepath) { if (!filepath) {
g_warning ("failed to get filepath"); if (err) {
g_warning ("failed to save MIME-part: %s",
err->message);
g_error_free (err);
}
g_free (filepath);
return FALSE; return FALSE;
} }
err = NULL;
if (!mu_msg_part_save (msg, filepath, partidx, overwrite, FALSE, &err)) { if (!mu_msg_part_save (msg, filepath, partidx, overwrite, FALSE, &err)) {
if (err) { if (err) {
g_warning ("failed to save MIME-part: %s", g_warning ("failed to save MIME-part: %s",
@ -203,21 +209,24 @@ save_part_if (MuMsg *msg, MuMsgPart *part, SaveData *sd)
rv = FALSE; rv = FALSE;
filepath = NULL; filepath = NULL;
filepath = mu_msg_part_filepath (msg, sd->targetdir, part->index);
if (!filepath)
goto leave;
err = NULL; err = NULL;
filepath = mu_msg_part_filepath (msg, sd->targetdir, part->index, &err);
if (!filepath) {
g_warning ("failed to get file path: %s",
err&&err->message ? err->message : "error");
g_clear_error (&err);
goto leave;
}
if (!mu_msg_part_save (msg, filepath, part->index, if (!mu_msg_part_save (msg, filepath, part->index,
sd->overwrite, FALSE, &err)) { sd->overwrite, FALSE, &err)) {
g_warning ("failed to save MIME-part: %s", g_warning ("failed to save MIME-part: %s",
err&&err->message ? err->message : "error"); err&&err->message ? err->message : "error");
if (err) g_clear_error (&err);
g_error_free (err);
goto leave; goto leave;
} }
if (sd->play && !mu_util_play (filepath, TRUE, FALSE)) if (sd->play && !mu_util_play (filepath, TRUE, FALSE))
goto leave; goto leave;
rv = TRUE; rv = TRUE;
@ -241,7 +250,7 @@ save_certain_parts (MuMsg *msg, gboolean attachments_only,
sd.targetdir = targetdir; sd.targetdir = targetdir;
sd.play = play; sd.play = play;
mu_msg_part_foreach (msg, mu_msg_part_foreach (msg, FALSE,
(MuMsgPartForeachFunc)save_part_if, (MuMsgPartForeachFunc)save_part_if,
&sd); &sd);
@ -344,7 +353,7 @@ show_parts (const char* path, MuConfig *opts, GError **err)
g_print ("MIME-parts in this message:\n"); g_print ("MIME-parts in this message:\n");
mu_msg_part_foreach mu_msg_part_foreach
(msg,(MuMsgPartForeachFunc)each_part_show, (msg, FALSE, (MuMsgPartForeachFunc)each_part_show,
GUINT_TO_POINTER(!opts->nocolor)); GUINT_TO_POINTER(!opts->nocolor));
mu_msg_unref (msg); mu_msg_unref (msg);

View File

@ -504,7 +504,8 @@ add_terms_values_attach (Xapian::Document& doc, MuMsg *msg,
MuMsgFieldId mfid) MuMsgFieldId mfid)
{ {
PartData pdata (doc, mfid); PartData pdata (doc, mfid);
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &pdata); mu_msg_part_foreach (msg, TRUE,
(MuMsgPartForeachFunc)each_part, &pdata);
} }

View File

@ -25,7 +25,7 @@ enum {
ICON_COL, ICON_COL,
NAME_COL, NAME_COL,
PARTNUM_COL, PARTNUM_COL,
NUM_COL NUM_COL
}; };
@ -61,7 +61,7 @@ set_message (MuMsgAttachView *self, MuMsg *msg)
{ {
if (self->_priv->_msg == msg) if (self->_priv->_msg == msg)
return; /* nothing to todo */ return; /* nothing to todo */
if (self->_priv->_msg) { if (self->_priv->_msg) {
mu_msg_unref (self->_priv->_msg); mu_msg_unref (self->_priv->_msg);
self->_priv->_msg = NULL; self->_priv->_msg = NULL;
@ -82,7 +82,7 @@ mu_msg_attach_view_class_init (MuMsgAttachViewClass *klass)
gobject_class->finalize = mu_msg_attach_view_finalize; gobject_class->finalize = mu_msg_attach_view_finalize;
g_type_class_add_private (gobject_class, sizeof(MuMsgAttachViewPrivate)); g_type_class_add_private (gobject_class, sizeof(MuMsgAttachViewPrivate));
signals[ATTACH_ACTIVATED] = signals[ATTACH_ACTIVATED] =
g_signal_new ("attach-activated", g_signal_new ("attach-activated",
G_TYPE_FROM_CLASS (gobject_class), G_TYPE_FROM_CLASS (gobject_class),
@ -100,16 +100,16 @@ item_activated (MuMsgAttachView *self, GtkTreePath *tpath)
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
guint partnum; guint partnum;
model = gtk_icon_view_get_model (GTK_ICON_VIEW(self)); model = gtk_icon_view_get_model (GTK_ICON_VIEW(self));
if (!gtk_tree_model_get_iter (model, &iter, tpath)) { if (!gtk_tree_model_get_iter (model, &iter, tpath)) {
g_warning ("could not find path"); g_warning ("could not find path");
} }
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
PARTNUM_COL, &partnum, PARTNUM_COL, &partnum,
-1); -1);
g_signal_emit (G_OBJECT (self), g_signal_emit (G_OBJECT (self),
signals[ATTACH_ACTIVATED], 0, signals[ATTACH_ACTIVATED], 0,
partnum, self->_priv->_msg); partnum, self->_priv->_msg);
@ -152,12 +152,12 @@ on_drag_data_get (MuMsgAttachView *self, GdkDragContext *drag_context,
GSList *lst, *cur; GSList *lst, *cur;
char **uris; char **uris;
int i; int i;
lst = NULL; lst = NULL;
gtk_icon_view_selected_foreach (GTK_ICON_VIEW(self), gtk_icon_view_selected_foreach (GTK_ICON_VIEW(self),
(GtkIconViewForeachFunc)accumulate_parts, (GtkIconViewForeachFunc)accumulate_parts,
&lst); &lst);
uris = g_new(char*, g_slist_length(lst) + 1); uris = g_new(char*, g_slist_length(lst) + 1);
for (cur = lst, i = 0; cur; cur = g_slist_next(cur)) for (cur = lst, i = 0; cur; cur = g_slist_next(cur))
uris[i++] = (gchar*)cur->data; uris[i++] = (gchar*)cur->data;
@ -168,21 +168,21 @@ on_drag_data_get (MuMsgAttachView *self, GdkDragContext *drag_context,
g_free (uris); g_free (uris);
g_slist_foreach (lst, (GFunc)g_free, NULL); g_slist_foreach (lst, (GFunc)g_free, NULL);
g_slist_free (lst); g_slist_free (lst);
} }
static void static void
mu_msg_attach_view_init (MuMsgAttachView *obj) mu_msg_attach_view_init (MuMsgAttachView *obj)
{ {
GtkListStore *store; GtkListStore *store;
obj->_priv = MU_MSG_ATTACH_VIEW_GET_PRIVATE(obj); obj->_priv = MU_MSG_ATTACH_VIEW_GET_PRIVATE(obj);
obj->_priv->_msg = NULL; obj->_priv->_msg = NULL;
store = gtk_list_store_new (NUM_COL,GDK_TYPE_PIXBUF, store = gtk_list_store_new (NUM_COL,GDK_TYPE_PIXBUF,
G_TYPE_STRING, G_TYPE_UINT); G_TYPE_STRING, G_TYPE_UINT);
gtk_icon_view_set_model (GTK_ICON_VIEW(obj), GTK_TREE_MODEL(store)); gtk_icon_view_set_model (GTK_ICON_VIEW(obj), GTK_TREE_MODEL(store));
g_object_unref (store); g_object_unref (store);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW(obj), ICON_COL); gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW(obj), ICON_COL);
gtk_icon_view_set_text_column (GTK_ICON_VIEW(obj), NAME_COL); gtk_icon_view_set_text_column (GTK_ICON_VIEW(obj), NAME_COL);
@ -196,22 +196,22 @@ mu_msg_attach_view_init (MuMsgAttachView *obj)
g_signal_connect (G_OBJECT(obj), "item-activated", g_signal_connect (G_OBJECT(obj), "item-activated",
G_CALLBACK(item_activated), NULL); G_CALLBACK(item_activated), NULL);
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW(obj), gtk_icon_view_set_selection_mode (GTK_ICON_VIEW(obj),
GTK_SELECTION_MULTIPLE); GTK_SELECTION_MULTIPLE);
/* drag & drop */ /* drag & drop */
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW(obj), 0, NULL, 0, gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW(obj), 0, NULL, 0,
GDK_ACTION_COPY); GDK_ACTION_COPY);
gtk_drag_source_add_uri_targets(GTK_WIDGET(obj)); gtk_drag_source_add_uri_targets(GTK_WIDGET(obj));
g_signal_connect (obj, "drag-data-get", G_CALLBACK(on_drag_data_get), NULL); g_signal_connect (obj, "drag-data-get", G_CALLBACK(on_drag_data_get), NULL);
} }
static void static void
mu_msg_attach_view_finalize (GObject *obj) mu_msg_attach_view_finalize (GObject *obj)
{ {
set_message (MU_MSG_ATTACH_VIEW(obj), NULL); set_message (MU_MSG_ATTACH_VIEW(obj), NULL);
G_OBJECT_CLASS(parent_class)->finalize (obj); G_OBJECT_CLASS(parent_class)->finalize (obj);
} }
@ -236,17 +236,17 @@ each_part (MuMsg *msg, MuMsgPart *part, CBData *cbdata)
GtkTreeIter treeiter; GtkTreeIter treeiter;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
char ctype[128]; char ctype[128];
if (!mu_msg_part_looks_like_attachment (part, FALSE)) if (!mu_msg_part_looks_like_attachment (part, FALSE))
return; return;
if (!part->type || !part->subtype) if (!part->type || !part->subtype)
snprintf (ctype, sizeof(ctype), "%s", snprintf (ctype, sizeof(ctype), "%s",
"application/octet-stream"); "application/octet-stream");
else else
snprintf (ctype, sizeof(ctype), "%s/%s", snprintf (ctype, sizeof(ctype), "%s/%s",
part->type, part->subtype); part->type, part->subtype);
pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type (ctype, 16); pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type (ctype, 16);
if (!pixbuf) { if (!pixbuf) {
g_warning ("%s: could not get icon pixbuf for '%s'", g_warning ("%s: could not get icon pixbuf for '%s'",
@ -254,7 +254,7 @@ each_part (MuMsg *msg, MuMsgPart *part, CBData *cbdata)
pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type
("application/octet-stream", 16); ("application/octet-stream", 16);
} }
gtk_list_store_append (cbdata->store, &treeiter); gtk_list_store_append (cbdata->store, &treeiter);
gtk_list_store_set (cbdata->store, &treeiter, gtk_list_store_set (cbdata->store, &treeiter,
NAME_COL, mu_msg_part_file_name (part), NAME_COL, mu_msg_part_file_name (part),
@ -263,7 +263,7 @@ each_part (MuMsg *msg, MuMsgPart *part, CBData *cbdata)
-1); -1);
if (pixbuf) if (pixbuf)
g_object_unref (pixbuf); g_object_unref (pixbuf);
++cbdata->count; ++cbdata->count;
} }
@ -272,22 +272,21 @@ mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg)
{ {
GtkListStore *store; GtkListStore *store;
CBData cbdata; CBData cbdata;
g_return_val_if_fail (MU_IS_MSG_ATTACH_VIEW(self), -1); g_return_val_if_fail (MU_IS_MSG_ATTACH_VIEW(self), -1);
store = GTK_LIST_STORE (gtk_icon_view_get_model (GTK_ICON_VIEW(self))); store = GTK_LIST_STORE (gtk_icon_view_get_model (GTK_ICON_VIEW(self)));
gtk_list_store_clear (store); gtk_list_store_clear (store);
set_message (self, msg); set_message (self, msg);
if (!msg) if (!msg)
return 0; return 0;
cbdata.store = store; cbdata.store = store;
cbdata.count = 0; cbdata.count = 0;
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &cbdata); mu_msg_part_foreach (msg, FALSE, (MuMsgPartForeachFunc)each_part, &cbdata);
return cbdata.count; return cbdata.count;
} }