+ /* Try to get the message, if it's already downloaded
+ we don't need to connect */
+ if (account) {
+ folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), msg_uid, NULL);
+ } else {
+ ModestTnyAccountStore *account_store;
+ ModestTnyLocalFoldersAccount *local_folders_account;
+
+ account_store = modest_runtime_get_account_store ();
+ local_folders_account = MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (
+ modest_tny_account_store_get_local_folders_account (account_store));
+ folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
+ g_object_unref (local_folders_account);
+ }
+ if (folder) {
+ TnyDevice *device;
+ gboolean device_online;
+
+ device = modest_runtime_get_device();
+ device_online = tny_device_is_online (device);
+ if (device_online) {
+ message_reader (window, priv, NULL, msg_uid, folder, NULL);
+ } else {
+ TnyMsg *msg = tny_folder_find_msg (folder, uri, NULL);
+ if (msg) {
+ tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+ g_object_unref (msg);
+ } else {
+ message_reader (window, priv, NULL, msg_uid, folder, NULL);
+ }
+ }
+ g_object_unref (folder);
+ }
+
+ }
+
+ /* Check dimming rules */
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+ modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+
+ return MODEST_WINDOW(window);
+}
+
+
+
+/* FIXME: parameter checks */
+ModestWindow *
+modest_msg_view_window_new_with_header_model (TnyMsg *msg,
+ const gchar *modest_account_name,
+ const gchar *mailbox, /*ignored */
+ const gchar *msg_uid,
+ GtkTreeModel *model,
+ GtkTreeRowReference *row_reference)
+{
+ ModestMsgViewWindow *window = NULL;
+ ModestMsgViewWindowPrivate *priv = NULL;
+ TnyFolder *header_folder = NULL;
+ ModestHeaderView *header_view = NULL;
+ ModestWindow *main_window = NULL;
+ ModestWindowMgr *mgr = NULL;
+
+ MODEST_DEBUG_BLOCK (
+ modest_tny_mime_part_to_string (TNY_MIME_PART (msg), 0);
+ );
+
+ mgr = modest_runtime_get_window_mgr ();
+ window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
+
+ modest_msg_view_window_construct (window, modest_account_name, msg_uid);
+
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+ /* Remember the message list's TreeModel so we can detect changes
+ * and change the list selection when necessary: */
+
+ main_window = modest_window_mgr_get_main_window(mgr, FALSE); /* don't create */
+ if (main_window) {
+ header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget(
+ MODEST_MAIN_WINDOW(main_window),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
+ }
+
+ if (header_view != NULL){
+ header_folder = modest_header_view_get_folder(header_view);
+ /* This could happen if the header folder was
+ unseleted before opening this msg window (for
+ example if the user selects an account in the
+ folder view of the main window */
+ if (header_folder) {
+ priv->is_outbox = (modest_tny_folder_guess_folder_type (header_folder) == TNY_FOLDER_TYPE_OUTBOX);
+ priv->header_folder_id = tny_folder_get_id(header_folder);
+ g_assert(priv->header_folder_id != NULL);
+ g_object_unref(header_folder);
+ }
+ }
+
+ /* Setup row references and connect signals */
+ priv->header_model = g_object_ref (model);
+
+ if (row_reference) {
+ priv->row_reference = gtk_tree_row_reference_copy (row_reference);
+ priv->next_row_reference = gtk_tree_row_reference_copy (row_reference);
+ select_next_valid_row (model, &(priv->next_row_reference), TRUE, priv->is_outbox);
+ } else {
+ priv->row_reference = NULL;
+ priv->next_row_reference = NULL;
+ }
+
+ /* Connect signals */
+ priv->row_changed_handler =
+ g_signal_connect (GTK_TREE_MODEL(model), "row-changed",
+ G_CALLBACK(modest_msg_view_window_on_row_changed),
+ window);
+ priv->row_deleted_handler =
+ g_signal_connect (GTK_TREE_MODEL(model), "row-deleted",
+ G_CALLBACK(modest_msg_view_window_on_row_deleted),
+ window);
+ priv->row_inserted_handler =
+ g_signal_connect (GTK_TREE_MODEL(model), "row-inserted",
+ G_CALLBACK(modest_msg_view_window_on_row_inserted),
+ window);
+ priv->rows_reordered_handler =
+ g_signal_connect(GTK_TREE_MODEL(model), "rows-reordered",
+ G_CALLBACK(modest_msg_view_window_on_row_reordered),
+ window);
+
+ if (header_view != NULL){
+ modest_header_view_add_observer(header_view,
+ MODEST_HEADER_VIEW_OBSERVER(window));
+ }
+
+ tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+ update_window_title (MODEST_MSG_VIEW_WINDOW (window));
+ gtk_widget_show_all (GTK_WIDGET (window));
+ modest_msg_view_window_update_priority (window);
+
+ /* Check dimming rules */
+ modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+ modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
+ modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);