gboolean show_toolbars_fullscreen;
GSList *windows_that_prevent_hibernation;
+ GSList *preregistered_uids;
GHashTable *destroy_handlers;
};
#define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
priv->main_window = NULL;
priv->fullscreen_mode = FALSE;
+ priv->preregistered_uids = NULL;
+
/* Could not initialize it from gconf, singletons are not
ready yet */
priv->show_toolbars = FALSE;
priv->window_list = NULL;
}
+ g_slist_foreach (priv->preregistered_uids, (GFunc)g_free, NULL);
+ g_slist_free (priv->preregistered_uids);
+
+
/* Free the hash table with the handlers */
if (priv->destroy_handlers) {
g_hash_table_destroy (priv->destroy_handlers);
return MODEST_WINDOW_MGR(g_object_new(MODEST_TYPE_WINDOW_MGR, NULL));
}
+
+
+
+/* do we have uid? */
+static gboolean
+has_uid (GSList *list, const gchar *uid)
+{
+ GSList *cursor = list;
+
+ if (!uid)
+ return FALSE;
+
+ while (cursor) {
+ if (cursor->data && strcmp (cursor->data, uid) == 0)
+ return TRUE;
+ cursor = g_slist_next (cursor);
+ }
+ return FALSE;
+}
+
+
+/* remove all from the list have have uid = uid */
+static GSList*
+remove_uid (GSList *list, const gchar *uid)
+{
+ GSList *cursor = list, *start = list;
+
+ if (!uid)
+ return FALSE;
+
+ while (cursor) {
+ GSList *next = g_slist_next (cursor);
+ if (cursor->data && strcmp (cursor->data, uid) == 0) {
+ g_free (cursor->data);
+ start = g_slist_delete_link (start, cursor);
+ }
+ cursor = next;
+ }
+ return start;
+}
+
+
+static GSList *
+append_uid (GSList *list, const gchar *uid)
+{
+ return g_slist_append (list, g_strdup(uid));
+}
+
+
+
+void
+modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header)
+{
+ ModestWindowMgrPrivate *priv;
+ gchar* uid;
+
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+ g_return_if_fail (TNY_IS_HEADER(header));
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+ uid = modest_tny_folder_get_header_unique_id (header);
+
+ if (!has_uid (priv->preregistered_uids, uid))
+ priv->preregistered_uids = append_uid (priv->preregistered_uids, uid);
+
+ g_free (uid);
+}
+
+void
+modest_window_mgr_unregister_header (ModestWindowMgr *self, TnyHeader *header)
+{
+ ModestWindowMgrPrivate *priv;
+ gchar* uid;
+
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+ g_return_if_fail (TNY_IS_HEADER(header));
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+ uid = modest_tny_folder_get_header_unique_id (header);
+
+ if (has_uid (priv->preregistered_uids, uid))
+ priv->preregistered_uids = remove_uid (priv->preregistered_uids, uid);
+
+ g_free (uid);
+}
+
+static gint
+compare_msguids (ModestWindow *win,
+ const gchar *uid)
+{
+ const gchar *msg_uid;
+
+ if (!MODEST_IS_MSG_VIEW_WINDOW (win))
+ return 1;
+
+ /* Get message uid from msg window */
+ msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
+
+ if (msg_uid && uid &&!strcmp (msg_uid, uid))
+ return 0;
+ else
+ return 1;
+}
+
+
+
+gboolean
+modest_window_mgr_find_registered_header (ModestWindowMgr *self, TnyHeader *header,
+ ModestWindow **win)
+{
+ ModestWindowMgrPrivate *priv;
+ gchar* uid;
+ gboolean retval = FALSE;
+ GList *item = NULL;
+
+ g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), FALSE);
+ g_return_val_if_fail (TNY_IS_HEADER(header), FALSE);
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ uid = modest_tny_folder_get_header_unique_id (header);
+
+ /* first, look for the window */
+ /* note, the UID cannot be in both the window list and the preregistered uid list */
+ if (priv->window_list) {
+ item = g_list_find_custom (priv->window_list,
+ uid, (GCompareFunc) compare_msguids);
+ if (item)
+ retval = TRUE;
+ if (win)
+ *win = item ? MODEST_WINDOW(item->data) : NULL;
+ }
+
+
+ /* IF It's not in the window list. maybe it's in our uid list... */
+ retval = retval || has_uid (priv->preregistered_uids, uid);
+
+ g_free (uid);
+
+ return retval;
+}
+
+
+
void
modest_window_mgr_register_window (ModestWindowMgr *self,
ModestWindow *window)
}
}
+ /* remove from the list of pre-registered uids */
+ if (MODEST_IS_MSG_VIEW_WINDOW(window)) {
+ priv->preregistered_uids =
+ remove_uid (priv->preregistered_uids,
+ modest_msg_view_window_get_message_uid
+ (MODEST_MSG_VIEW_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);
handler_id = *tmp;
g_hash_table_remove (priv->destroy_handlers, window);
- /* Remove the reference to the window. We need to block the
- destroy event handler to avoid recursive calls */
- g_signal_handler_block (window, handler_id);
+ /* Remove the reference to the window. Disconnect also the
+ delete-event handler, we won't need it anymore */
+ g_signal_handler_disconnect (window, handler_id);
gtk_widget_destroy (win->data);
- if (G_IS_OBJECT (window))
- g_signal_handler_unblock (window, handler_id);
/* If there are no more windows registered then exit program */
if (priv->window_list == NULL) {
}
}
-static gint
-compare_msguids (ModestWindow *win,
- const gchar *uid)
-{
- const gchar *msg_uid;
-
- if (!MODEST_IS_MSG_VIEW_WINDOW (win))
- return 1;
-
- /* Get message uid from msg window */
- msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (win));
-
- if (msg_uid && uid &&!strcmp (msg_uid, uid))
- return 0;
- else
- return 1;
-}
-
-ModestWindow*
-modest_window_mgr_find_window_by_header (ModestWindowMgr *self,
- TnyHeader *header)
-{
- ModestWindowMgrPrivate *priv;
- GList *win = NULL;
- gchar *msg_uid;
-
- g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL);
- g_return_val_if_fail (TNY_IS_HEADER (header), NULL);
-
- priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
- msg_uid = modest_tny_folder_get_header_unique_id (header);
-
- /* Look for the window */
- if (priv->window_list)
- win = g_list_find_custom (priv->window_list,
- msg_uid,
- (GCompareFunc) compare_msguids);
- /* Free */
- g_free (msg_uid);
-
- /* Return the window */
- if (win)
- return win->data;
- else
- return NULL;
-}
-
void
modest_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
gboolean on)