- win = g_list_find (priv->window_list, window);
- if (win) {
- g_warning ("%s: trying to re-register a window",
- __FUNCTION__);
- return;
- }
-
- /* Check that it's not a second main window */
- if (MODEST_IS_MAIN_WINDOW (window)) {
- if (priv->main_window) {
- g_warning ("%s: trying to register a second main window",
- __FUNCTION__);
- return;
- } else {
- priv->main_window = window;
- }
- }
-
- /* remove from the list of pre-registered uids */
- if (MODEST_IS_MSG_VIEW_WINDOW(window)) {
- const gchar *uid = modest_msg_view_window_get_message_uid
- (MODEST_MSG_VIEW_WINDOW (window));
-
- if (!has_uid (priv->preregistered_uids, uid))
- g_debug ("weird: no uid for window (%s)", uid);
-
- g_debug ("registering window for %s", uid ? uid : "<none>");
-
- priv->preregistered_uids =
- remove_uid (priv->preregistered_uids,
- modest_msg_view_window_get_message_uid
- (MODEST_MSG_VIEW_WINDOW (window)));
- } else if (MODEST_IS_MSG_EDIT_WINDOW(window)) {
- const gchar *uid = modest_msg_edit_window_get_message_uid
- (MODEST_MSG_EDIT_WINDOW (window));
-
- g_debug ("registering window for %s", uid);
-
- priv->preregistered_uids =
- remove_uid (priv->preregistered_uids,
- modest_msg_edit_window_get_message_uid
- (MODEST_MSG_EDIT_WINDOW (window)));
- }
-
- /* Add to list. Keep a reference to the window */
- g_object_ref (window);
- priv->window_list = g_list_prepend (priv->window_list, window);
-
- /* Listen to object destruction */
- handler_id = g_malloc0 (sizeof (gint));
- *handler_id = g_signal_connect (window, "delete-event", G_CALLBACK (on_window_destroy), self);
- g_hash_table_insert (priv->destroy_handlers, window, handler_id);
-
- /* If there is a msg view window, let the main window listen the msg-changed signal */
- if (MODEST_IS_MSG_VIEW_WINDOW(window) && priv->main_window) {
- gulong *handler;
- handler = g_malloc0 (sizeof (gulong));
- *handler = g_signal_connect (window, "msg-changed",
- G_CALLBACK (modest_main_window_on_msg_view_window_msg_changed),
- priv->main_window);
- g_hash_table_insert (priv->viewer_handlers, window, handler);
- }