if (!from) {
g_printerr ("modest: no from address for account '%s'\n", account_name);
} else {
- ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND);
+ ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL);
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
modest_mail_operation_send_new_mail (mail_operation,
switch (type) {
case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED:
if (mode_changed)
- set_toolbar_mode (MODEST_MAIN_WINDOW(self), mode);
+ set_toolbar_mode (self, mode);
if (mode == TOOLBAR_MODE_TRANSFER) {
while (tmp) {
modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
}
/* If no more operations are being observed, NORMAL mode is enabled again */
- if (observers_empty (MODEST_MAIN_WINDOW(self)))
- set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL);
+ if (observers_empty (self))
+ set_toolbar_mode (self, TOOLBAR_MODE_NORMAL);
}
break;
}
tmp=g_slist_next(tmp);
}
}
+static gboolean
+observers_empty (ModestMsgViewWindow *self)
+{
+ GSList *tmp = NULL;
+ ModestMsgViewWindowPrivate *priv;
+ gboolean is_empty = TRUE;
+ guint pending_ops = 0;
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+ tmp = priv->progress_widgets;
+
+ /* Check all observers */
+ while (tmp && is_empty) {
+ pending_ops = modest_progress_object_num_pending_operations (MODEST_PROGRESS_OBJECT(tmp->data));
+ is_empty = pending_ops == 0;
+
+ tmp = g_slist_next(tmp);
+ }
+
+ return is_empty;
+}
+
static void
on_queue_changed (ModestMailOperationQueue *queue,
g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
+ /* If this operations was created by another window, do nothing */
+ if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
+ return;
+
/* Get toolbar mode from operation id*/
op_id = modest_mail_operation_get_id (mail_op);
switch (op_id) {
tmp = priv->progress_widgets;
switch (type) {
case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED:
- if (mode != TOOLBAR_MODE_NORMAL)
+ if (mode == TOOLBAR_MODE_TRANSFER) {
+ while (tmp) {
+ modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ mail_op);
+ tmp = g_slist_next (tmp);
+ }
+
+ /* Enable transfer toolbar mode */
set_toolbar_mode (MODEST_MSG_VIEW_WINDOW(self), mode);
- while (tmp) {
- modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
- mail_op);
- tmp = g_slist_next (tmp);
}
break;
case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
- if (mode != TOOLBAR_MODE_NORMAL)
+ if (mode == TOOLBAR_MODE_TRANSFER) {
set_toolbar_mode (MODEST_MSG_VIEW_WINDOW(self), TOOLBAR_MODE_NORMAL);
- while (tmp) {
- modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ while (tmp) {
+ modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
mail_op);
- tmp = g_slist_next (tmp);
+ tmp = g_slist_next (tmp);
+
+ }
+
+ /* If no more operations are being observed, NORMAL mode is enabled again */
+ if (observers_empty (self))
+ set_toolbar_mode (self, TOOLBAR_MODE_NORMAL);
}
break;
}
guint total;
ModestMailOperationStatus status;
ModestMailOperationId id;
+ GObject *source;
GError *error;
};
priv->error = NULL;
priv->done = 0;
priv->total = 0;
+ priv->source = NULL;
}
static void
g_error_free (priv->error);
priv->error = NULL;
}
+ if (priv->source) {
+ g_object_unref (priv->source);
+ priv->source = NULL;
+ }
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
ModestMailOperation*
-modest_mail_operation_new (ModestMailOperationId id)
+modest_mail_operation_new (ModestMailOperationId id,
+ GObject *source)
{
ModestMailOperation *obj;
ModestMailOperationPrivate *priv;
-
-
+
obj = MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
priv->id = id;
+ if (source != NULL)
+ priv->source = g_object_ref(source);
return obj;
}
-
ModestMailOperationId
modest_mail_operation_get_id (ModestMailOperation *self)
{
return priv->id;
}
+gboolean
+modest_mail_operation_is_mine (ModestMailOperation *self,
+ GObject *me)
+{
+ ModestMailOperationPrivate *priv;
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
+ if (priv->source == NULL) return FALSE;
+
+ return priv->source == me;
+}
+
+
void
modest_mail_operation_send_mail (ModestMailOperation *self,
TnyTransportAccount *transport_account,
/* member functions */
GType modest_mail_operation_get_type (void) G_GNUC_CONST;
-/* typical parameter-less _new function */
-ModestMailOperation* modest_mail_operation_new (ModestMailOperationId id);
+/**
+ * modest_mail_operation_new:
+ * @id: a #ModestMailOperationId identification of operation type.
+ * @source: a #GObject which creates this new operation.
+ *
+ * Creates a new instance of class #ModestMailOperation, using parameters
+ * to initialize its private structure. @source parameter may be NULL.
+ **/
+ModestMailOperation* modest_mail_operation_new (ModestMailOperationId id,
+ GObject *source);
/**
* modest_mail_operation_get_id
*
* Gets the private id field of mail operation. This id identifies
* the class/type of mail operation.
- **/
+ **/
ModestMailOperationId
modest_mail_operation_get_id (ModestMailOperation *self);
+/**
+ * modest_mail_operation_get_id
+ * @self: a #ModestMailOperation
+ * @source: a #GObject to check if it have created @self operation.
+ *
+ * Check if @source object its owner of @self mail operation.
+ *
+ * returns: TRUE if source its owner, FALSE otherwise.
+ **/
+gboolean
+modest_mail_operation_is_mine (ModestMailOperation *self,
+ GObject *me);
+
/* fill in other public functions, eg.: */
/**
from_string = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
account_name);
- mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND);
+ mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, NULL);
modest_mail_operation_send_new_mail (mail_operation, account,
from_string, mailto,
cc, bcc, subject, body, NULL,
tny_stream_reset (stream);
tny_mime_part_decode_to_stream (body, stream);
tny_stream_reset (stream);
-
- g_object_unref (G_OBJECT(stream));
- g_object_unref (G_OBJECT(body));
gtk_text_buffer_get_bounds (buf, &start, &end);
to_quote = gtk_text_buffer_get_text (buf, &start, &end, FALSE);
g_free (to_quote);
to_quote = to_quote_converted;
}
+
g_object_unref (buf);
+ g_object_unref (G_OBJECT(stream));
+ g_object_unref (G_OBJECT(body));
return to_quote;
}
ModestMailOperation *mail_op;
/* TODO: add confirmation dialog */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
TnyList *header_list;
guint reply_forward_type;
TnyHeader *header;
-/* TnyFolder *folder; */
GetMsgAsyncHelper *helper;
ReplyForwardHelper *rf_helper;
reply_forward_func (msg, helper);
} else {
header = TNY_HEADER (tny_iterator_get_current (helper->iter));
-
-/* folder = tny_header_get_folder (header); */
-/* if (folder) { */
-/* /\* The callback will call it per each header *\/ */
-/* tny_folder_get_msg_async (folder, header, get_msg_cb, NULL, helper); */
-/* g_object_unref (G_OBJECT (folder)); */
-/* } else */
-/* g_printerr ("modest: no folder for header\n"); */
- helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op);
modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper);
static gboolean
-action_receive (const gchar* account_name)
+action_receive (const gchar* account_name,
+ ModestWindow *win)
{
TnyAccount *tny_account;
ModestMailOperation *mail_op;
/* Create the mail operation */
/* TODO: The spec wants us to first do any pending deletions, before receiving. */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
* for SMTP we should send,
* first receiving, then sending:
*/
- if (!action_receive(account_name))
+ if (!action_receive(account_name, win))
g_printerr ("modest: failed to receive\n");
if (!action_send(account_name))
g_printerr ("modest: failed to send\n");
* for SMTP we should send,
* first receiving, then sending:
*/
- if (!action_receive(account_name))
+ if (!action_receive(account_name, win))
g_printerr ("modest: failed to receive for account %s\n", account_name);
if (!action_send(account_name))
g_printerr ("modest: failed to send for account %s\n", account_name);
headers = tny_iterator_get_list (helper->iter);
g_object_unref (G_OBJECT (headers));
g_object_unref (G_OBJECT (helper->iter));
+ g_object_unref (G_OBJECT (helper->mail_op));
if (rf_helper != NULL) {
g_free (rf_helper->account_name);
g_slice_free (ReplyForwardHelper, rf_helper);
} else {
TnyHeader *header;
header = TNY_HEADER (tny_iterator_get_current (helper->iter));
-/* tny_folder_get_msg_async (folder, header, */
-/* get_msg_cb, NULL, helper); */
modest_mail_operation_process_msg (helper->mail_op, header, helper->num_ops, get_msg_cb, helper);
g_object_unref (G_OBJECT(header));
ModestWindow *win = NULL;
TnyFolder *folder = NULL;
TnyMsg *msg = NULL;
+ TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
ModestWindowMgr *mgr;
GtkTreeModel *model;
GtkTreeIter iter;
g_printerr ("modest: cannot get folder for header\n");
return;
}
+ if (modest_tny_folder_is_local_folder (folder))
+ folder_type = modest_tny_folder_get_local_folder_type (folder);
/* FIXME: make async?; check error */
msg = tny_folder_get_msg (folder, header, NULL);
if (sel_list != NULL) {
gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) sel_list->data);
- win = modest_msg_view_window_new_with_header_model (msg, account, model, iter);
+ switch (folder_type) {
+ case TNY_FOLDER_TYPE_DRAFTS:
+ win = modest_msg_edit_window_new (msg, account);
+ break;
+ default:
+ win = modest_msg_view_window_new_with_header_model (msg, account, model, iter);
+ }
+
g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (sel_list);
} else {
from = modest_account_mgr_get_from_string (account_mgr, account_name);
/* Create the mail operation */
- mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO);
+ mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
modest_mail_operation_save_to_drafts (mail_operation,
from = modest_account_mgr_get_from_string (account_mgr, account_name);
/* Create the mail operation */
- mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND);
+ mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
modest_mail_operation_send_new_mail (mail_operation,
if (result == GTK_RESPONSE_REJECT) {
finished = TRUE;
} else {
- ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO);
+ ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
TnyFolder *new_folder = NULL;
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
if (folder_name != NULL && strlen (folder_name) > 0) {
ModestMailOperation *mail_op;
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
g_free (message);
if (response == GTK_RESPONSE_OK) {
- ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE);
+ ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
if (TNY_IS_FOLDER (src_folder)) {
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
/* Transfer messages */
if (response == GTK_RESPONSE_OK) {
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
ModestMailOperation *mail_op;
/* Create mail op */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
&folder, -1);
/* Transfer message */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
&folder, -1);
/* Do the mail operation */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, NULL);
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);
g_signal_connect (G_OBJECT (mail_op), "progress-changed",
modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder)
{
ModestHeaderViewPrivate *priv;
+ ModestWindow *win = NULL;
priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
+ win = MODEST_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(self)));
+ g_return_if_fail (MODEST_IS_WINDOW (win));
if (priv->folder) {
g_object_unref (priv->folder);
g_signal_emit (G_OBJECT(self), signals[HEADER_SELECTED_SIGNAL], 0, NULL);
/* Create the mail operation */
- mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
+ mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
mail_op);