static void on_view_attachments_toggled(GtkWidget *widget, ModestUI *modest_ui);
+static void on_attach_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin);
+
#if 1
static void on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin);
#else
ModestUI *modest_ui;
ModestEditorWindow *edit_win;
GladeXML *glade_xml;
+ GList *attachments;
} EditWinData;
g_object_unref(G_OBJECT(glade_xml));
return NULL;
}
+
+ win_data->attachments = NULL; /* redundant */
return GTK_CONTAINER(top_container);
}
return TRUE;
}
+
+gboolean
+modest_ui_editor_window_update_attachments(gpointer window_data)
+{
+ GladeXML *glade_xml;
+
+ glade_xml = ((EditWinData *) window_data)->glade_xml;
+
+ //body_view = glade_xml_get_widget(glade_xml, "body_view");
+
+ return TRUE;
+}
#if 0
gboolean
modest_ui_new_edit_window (ModestUI *modest_ui, const gchar* to,
gpointer user_data)
{
GtkWidget *edit_win;
- EditWinData *windata;
-
+
edit_win = (GtkWidget *)user_data;
- windata = (EditWinData *)modest_editor_window_get_data(MODEST_EDITOR_WINDOW(edit_win));
-
modest_editor_window_set_modified(MODEST_EDITOR_WINDOW(edit_win), TRUE);
}
btn = glade_xml_get_widget (glade_xml, "toolb_send");
g_signal_connect (btn, "clicked", G_CALLBACK(on_send_button_clicked),
edit_win);
+ btn = glade_xml_get_widget (glade_xml, "toolb_attach");
+ g_signal_connect (btn, "clicked", G_CALLBACK(on_attach_button_clicked),
+ edit_win);
w = glade_xml_get_widget (glade_xml, "to_entry");
g_signal_connect(w, "changed", G_CALLBACK(on_editor_entry_changed), edit_win);
btn = glade_xml_get_widget (glade_xml, "toolb_send");
g_signal_connect (btn, "clicked", G_CALLBACK(on_send_button_clicked),
edit_win);
+ btn = glade_xml_get_widget (glade_xml, "toolb_attach");
+ g_signal_connect (btn, "clicked", G_CALLBACK(on_attach_button_clicked),
+ edit_win);
w = glade_xml_get_widget (glade_xml, "to_entry");
g_signal_connect(w, "changed", G_CALLBACK(on_editor_entry_changed), edit_win);
static void
+on_attach_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
+{
+ /* open file selector */
+ GtkWidget *dialog;
+ gchar *mime_type;
+ gchar *filename = NULL;
+
+ dialog = gtk_file_chooser_dialog_new ("Open File",
+ GTK_WINDOW(modest_editwin),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ printf ("file:%s\n", filename);
+ }
+ gtk_widget_destroy (dialog);
+
+ /* check file */
+ if (!filename)
+ return;
+
+ g_return_if_fail(g_str_has_suffix(filename, ".jpg")); /* for now... */
+
+ /* get mime type */
+ mime_type = "image/jpeg";
+
+ /* attach file */
+
+ modest_editor_window_attach_file(modest_editwin, filename);
+
+ g_free (filename);
+}
+
+
+static void
on_send_button_clicked (GtkWidget *widget, ModestEditorWindow *modest_editwin)
{
ModestTnyTransportActions *actions;
TnyAccountStoreIface *account_store;
const GList *transport_accounts;
TnyTransportAccountIface *transport_account;
- ModestConf *conf;
ModestIdentityMgr *id_mgr;
EditWinData *win_data;
+ GList * attachments;
win_data = modest_editor_window_get_data(modest_editwin);
email_from = modest_identity_mgr_get_identity_string(id_mgr,
MODEST_IDENTITY_DEFAULT_IDENTITY,
MODEST_IDENTITY_EMAIL, NULL);
-
+ attachments = modest_editor_window_get_attachments(modest_editwin);
+ /* while (attachments) {
+ printf("att: %s\n", (gchar *) attachments->data);
+ attachments = attachments->next;
+ } */
if (!email_from)
email_from = "";
transport_account,
email_from,
to, "", "", subject,
- body);
+ body,
+ attachments);
g_free (body);
g_object_unref (G_OBJECT(actions));
struct _ModestEditorWindowPrivate {
gpointer user_data;
gboolean modified;
+ GList *attachments;
};
#define MODEST_EDITOR_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_EDITOR_WINDOW, \
priv->user_data = NULL;
priv->modified = FALSE;
+ priv->attachments = NULL;
}
static void
return modest_ui_editor_window_set_body(body, priv->user_data);
}
+
+
+gboolean modest_editor_window_attach_file(ModestEditorWindow *edit_win, const gchar *filename)
+{
+ ModestEditorWindowPrivate *priv;
+
+ if (!edit_win)
+ return FALSE;
+ priv = MODEST_EDITOR_WINDOW_GET_PRIVATE(edit_win);
+
+ priv->attachments = g_list_append(
+ priv->attachments,
+ g_strdup(filename));
+
+ return modest_ui_editor_window_update_attachments(priv->user_data);
+}
+
+GList * modest_editor_window_set_attachments(ModestEditorWindow *edit_win, GList* attachments)
+{
+ ModestEditorWindowPrivate *priv;
+
+ g_return_val_if_fail(edit_win, NULL);
+
+ priv = MODEST_EDITOR_WINDOW_GET_PRIVATE(edit_win);
+
+ priv->attachments = attachments;
+ return priv->attachments;
+}
+
+GList * modest_editor_window_get_attachments(ModestEditorWindow *edit_win)
+{
+ ModestEditorWindowPrivate *priv;
+
+ g_return_val_if_fail(edit_win, NULL);
+
+ priv = MODEST_EDITOR_WINDOW_GET_PRIVATE(edit_win);
+ return priv->attachments;
+}
const gchar *cc,
const gchar *bcc,
const gchar *subject,
- const gchar *body)
+ const gchar *body,
+ const GList *attachments_list)
{
TnyMsgIface *new_msg;
- TnyMsgMimePartIface *body_part;
+ TnyMsgMimePartIface *body_part, *attachment_part;
TnyMsgHeaderIface *headers;
- TnyStreamIface *body_stream;
- gchar *content_type;
+ TnyStreamIface *body_stream, *attachment_stream;
+ gchar *content_type, *attachment_content_type;
+ GList *attachment;
new_msg = TNY_MSG_IFACE(tny_msg_new ());
headers = TNY_MSG_HEADER_IFACE(tny_msg_header_new ());
tny_msg_mime_part_iface_construct_from_stream (TNY_MSG_MIME_PART_IFACE(new_msg),
body_stream, content_type);
+
+ attachment = (GList *)attachments_list;
+ while (attachment) {
+ gchar * att_buf;
+ struct stat stat_data;
+ int file;
+
+ printf("att: %s\n", (gchar *) attachment->data);
+ /* leaks galore! */
+ /* of course, the attachment should _not_ be read into mem... */
+ file = open(attachment->data, O_RDONLY);
+ fstat(file, &stat_data);
+ att_buf = g_malloc0(stat_data.st_size + 1);
+ read(file, att_buf, stat_data.st_size);
+ close(file);
+
+ attachment_stream = TNY_STREAM_IFACE (tny_stream_camel_new
+ (camel_stream_mem_new_with_buffer
+ (att_buf, stat_data.st_size)));
+
+ attachment_part = TNY_MSG_MIME_PART_IFACE (tny_msg_mime_part_new
+ (camel_mime_part_new()));
+
+ attachment_content_type = "image/jpeg"; /* later... */
+
+ tny_msg_mime_part_iface_construct_from_stream (attachment_part, attachment_stream,
+ content_type);
+
+ tny_stream_iface_reset (attachment_stream);
+ tny_msg_mime_part_iface_set_content_type(attachment_part, attachment_content_type);
+ tny_msg_iface_add_part (new_msg, attachment_part);
+
+ attachment = attachment->next;
+ }
tny_transport_account_iface_send (transport_account, new_msg);