+/* The modest_msg_view_window_update_model_replaced implements update
+ * function for ModestHeaderViewObserver. Checks whether the TnyFolder
+ * actually belongs to the header-view is the same as the TnyFolder of
+ * the message of msg-view or not. If they are different, there is
+ * nothing to do. If they are the same, then the model has replaced and
+ * the reference in msg-view shall be replaced from the old model to
+ * the new model. In this case the view will be detached from it's
+ * header folder. From this point the next/prev buttons are dimmed.
+ */
+void modest_msg_view_window_update_model_replaced(
+ ModestHeaderViewObserver *observer,
+ GtkTreeModel *model,
+ const gchar *tny_folder_id){
+ ModestMsgViewWindowPrivate *priv = NULL;
+ ModestMsgViewWindow *window = NULL;
+
+ g_assert(MODEST_IS_HEADER_VIEW_OBSERVER(observer));
+ g_assert(MODEST_IS_MSG_VIEW_WINDOW(observer));
+
+ window = MODEST_MSG_VIEW_WINDOW(observer);
+ priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(window);
+
+ /* If there is an other folder in the header-view then we do
+ * not care about it's model (msg list). Else if the
+ * header-view shows the folder the msg shown by us is in, we
+ * shall replace our model reference and make some check. */
+ if(tny_folder_id == NULL ||
+ !g_str_equal(tny_folder_id, priv->header_folder_id))
+ return;
+
+ /* Model is changed(replaced), so we should forget the old
+ * one. Because there might be other references and there
+ * might be some change on the model even if we unreferenced
+ * it, we need to disconnect our signals here. */
+ if (g_signal_handler_is_connected(G_OBJECT (priv->header_model),
+ priv->row_changed_handler))
+ g_signal_handler_disconnect(G_OBJECT (priv->header_model),
+ priv->row_changed_handler);
+ priv->row_changed_handler = 0;
+ if (g_signal_handler_is_connected(G_OBJECT (priv->header_model),
+ priv->row_deleted_handler))
+ g_signal_handler_disconnect(G_OBJECT (priv->header_model),
+ priv->row_deleted_handler);
+ priv->row_deleted_handler = 0;
+ if (g_signal_handler_is_connected(G_OBJECT (priv->header_model),
+ priv->row_inserted_handler))
+ g_signal_handler_disconnect(G_OBJECT (priv->header_model),
+ priv->row_inserted_handler);
+ priv->row_inserted_handler = 0;
+ if (g_signal_handler_is_connected(G_OBJECT (priv->header_model),
+ priv->rows_reordered_handler))
+ g_signal_handler_disconnect(G_OBJECT (priv->header_model),
+ priv->rows_reordered_handler);
+ priv->rows_reordered_handler = 0;
+ g_object_unref(priv->header_model);
+ priv->header_model = NULL;
+ g_object_unref(priv->row_reference);
+ priv->row_reference = NULL;
+ g_object_unref(priv->next_row_reference);
+ priv->next_row_reference = NULL;
+
+ modest_ui_actions_check_toolbar_dimming_rules(MODEST_WINDOW(window));
+
+ if(tny_folder_id == NULL)
+ return;
+
+ g_assert(model != NULL);
+
+ /* Also we must connect to the new model for row insertions.
+ * Only for insertions now. We will need other ones only after
+ * the msg is show by msg-view is added to the new model. */
+ priv->row_inserted_handler = g_signal_connect (
+ model, "row-inserted",
+ G_CALLBACK(modest_msg_view_window_on_row_inserted),
+ window);
+}
+