GtkTreeModel *model;
GtkTreeRowReference *row_reference;
TnyFolder *folder;
+ TnyHeader *header;
} HeaderActivatedHelper;
/*
g_return_if_fail (MODEST_IS_WINDOW(obj));
g_return_if_fail (user_data != NULL);
+
+ /* TODO: Show an error? (review the specs) */
+ if (!msg)
+ return;
+
parent_win = MODEST_WINDOW(obj);
helper = (HeaderActivatedHelper *) user_data;
+ /* Mark header as read */
+ headers_action_mark_as_read (helper->header, MODEST_WINDOW(parent_win), NULL);
+
/* Get account */
account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(parent_win)));
if (!account)
g_free(account);
/* g_object_unref (G_OBJECT(msg)); */
g_object_unref (G_OBJECT(helper->folder));
+ g_object_unref (G_OBJECT(helper->header));
gtk_tree_row_reference_free (helper->row_reference);
g_slice_free (HeaderActivatedHelper, helper);
}
}
}
-
-static gboolean
-action_send (const gchar* account_name)
-{
- TnyAccount *tny_account;
- ModestTnySendQueue *send_queue;
-
- g_return_val_if_fail (account_name, FALSE);
-
- /* Get the transport account according to the open connection,
- * because the account might specify connection-specific SMTP servers.
- */
- tny_account =
- modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
- account_name);
- if (!tny_account) {
- g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
- return FALSE;
- }
-
- send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
- if (!send_queue) {
- g_object_unref (G_OBJECT(tny_account));
- g_printerr ("modest: cannot get send queue for %s\n", account_name);
- return FALSE;
- }
-
- modest_tny_send_queue_flush (send_queue);
-
- g_object_unref (G_OBJECT(send_queue));
- g_object_unref (G_OBJECT(tny_account));
-
- return TRUE;
-}
-
-
-static gboolean
-action_receive (const gchar* account_name,
- ModestWindow *win)
-{
- TnyAccount *tny_account;
- ModestMailOperation *mail_op;
-
- g_return_val_if_fail (account_name, FALSE);
-
- tny_account =
- modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
- account_name,
- TNY_ACCOUNT_TYPE_STORE);
- if (!tny_account) {
- g_printerr ("modest: cannot get tny store account for %s\n", account_name);
- return FALSE;
- }
-
- /* 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, 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));
-
- g_object_unref (G_OBJECT(tny_account));
- g_object_unref (G_OBJECT (mail_op));
-
- return TRUE;
-}
-
/** Check that an appropriate connection is open.
*/
gboolean check_for_connection (const gchar *account_name)
* for SMTP we should send,
* first receiving, then sending:
*/
- if (!action_receive(acc_name, win))
- g_printerr ("modest: failed to receive\n");
- if (!action_send(acc_name))
- g_printerr ("modest: failed to send\n");
+ /* Create the mail operation */
+ /* TODO: The spec wants us to first do any pending deletions, before receiving. */
+ ModestMailOperation *mail_op;
+ 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, acc_name);
+ g_object_unref (G_OBJECT (mail_op));
}
/* Free */
g_free (acc_name);
ModestWindowMgr *mgr = NULL;
ModestWindow *win = NULL;
GtkTreeModel *model = NULL;
- GtkTreeIter iter;
GtkTreeSelection *sel = NULL;
GList *sel_list = NULL;
- GList *tmp = NULL;
g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
/* Build helper */
helper = g_slice_new0 (HeaderActivatedHelper);
helper->folder = tny_header_get_folder (header);
+ helper->header = g_object_ref(header);
helper->model = NULL;
- /* Get headers tree model and selected iter to build message view */
+ /* Get headers tree model and selected row reference to build message view */
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
if (sel_list != NULL) {
helper->model = model;
helper->row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
- /* Mark as read */
- for (tmp=sel_list; tmp; tmp=g_list_next(tmp)) {
- gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) tmp->data);
- gtk_tree_model_get (model, &iter, TNY_GTK_HEADER_LIST_MODEL_INSTANCE_COLUMN,
- &header, -1);
-
- headers_action_mark_as_read (header, MODEST_WINDOW(main_window), NULL);
-
- g_object_unref(header);
- }
-
g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (sel_list);
}
g_object_unref (mail_op);
}
+static void
+set_active_account_from_tny_account (TnyAccount *account,
+ ModestWindow *window)
+{
+ TnyAccount *modest_server_account;
+ const gchar *server_acc_name;
+ gchar *modest_acc_name;
+
+ server_acc_name = tny_account_get_id (account);
+ /* We need the TnyAccount provided by the
+ account store because that is the one that
+ knows the name of the Modest account */
+ modest_server_account =
+ modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store (),
+ server_acc_name);
+ modest_acc_name = (gchar *) g_object_get_data (G_OBJECT (modest_server_account), "modest_account");
+ modest_window_set_active_account (window, modest_acc_name);
+ g_object_unref (modest_server_account);
+}
+
void
modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
TnyFolderStore *folder_store,
{
ModestConf *conf;
GtkWidget *header_view;
+ TnyAccount *account;
g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
if (TNY_IS_FOLDER (folder_store)) {
if (selected) {
+ /* Update the active account */
+ account = tny_folder_get_account (TNY_FOLDER (folder_store));
+ set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
+ g_object_unref (account);
+
+ /* Set folder on header view */
modest_main_window_set_contents_style (main_window,
MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
modest_widget_memory_restore (conf, G_OBJECT(header_view),
MODEST_CONF_HEADER_VIEW_KEY);
} else {
+ /* Update the active account */
+ modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
+ /* Do not show folder */
modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
}
} else if (TNY_IS_ACCOUNT (folder_store)) {
-
+ /* Update active account */
+ set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
+ /* Show account details */
modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
}
}