}
static void
-on_destroy (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
-{
- gtk_main_quit();
-}
-
-
-
-static void
connect_signals (ModestMainWindow *self)
{
ModestWindowPrivate *parent_priv;
self);
/* window */
- g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
}
/* Set status message */
modest_gnome_info_bar_set_message (MODEST_GNOME_INFO_BAR (priv->main_bar), msg);
}
+
+gboolean
+modest_main_window_close_all (ModestMainWindow *self)
+{
+ /* TODO: show a dialog to ask the user for permission to close
+ all */
+ return TRUE;
+}
return modest_msg_view_get_message (MODEST_MSG_VIEW(msg_view));
}
+const gchar*
+modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self)
+{
+ TnyMsg *msg;
+ TnyHeader *header;
+ const gchar *retval = NULL;
+
+ msg = modest_msg_view_window_get_message (self);
+
+ if (!msg)
+ return NULL;
+
+ header = tny_msg_get_header (msg);
+ if (header) {
+ retval = tny_header_get_uid (header);
+ g_object_unref (header);
+ }
+ return retval;
+}
+
ModestWindow*
modest_msg_view_window_new_with_header_model (TnyMsg *msg,
const gchar *account,
/* View */
{ "ViewSort", NULL, N_("mcen_me_inbox_sort"), NULL, NULL, NULL },
- { "ViewFolders", NULL, N_("mcen_me_inbox_hidefolders"), NULL, NULL, NULL },
- { "ViewFullscreen", NULL, N_("mcen_me_inbox_fullscreen"), NULL, NULL, NULL },
+/* { "ViewFolders", NULL, N_("mcen_me_inbox_hidefolders"), NULL, NULL, NULL }, */
+/* { "ViewFullscreen", NULL, N_("mcen_me_inbox_fullscreen"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_toggle_fullscreen) }, */
{ "ViewShowToolbar", NULL, N_("mcen_me_inbox_toolbar") }, /* submenu */
{ "ViewShowToolbarNormalScreen", NULL, N_("mcen_me_inbox_normalview"), NULL, NULL, NULL },
{ "ViewShowToolbarFullScreen", NULL, N_("mcen_me_inbox_optimizedview"), NULL, NULL, NULL },
{ "ShowToggleFullscreen", GTK_STOCK_FULLSCREEN, N_("Full screen"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_toggle_fullscreen), FALSE },
};
-
G_END_DECLS
#endif /* __MODEST_MAIN_WINDOW_UI_PRIV_H__ */
*/
#include <hildon-widgets/hildon-window.h>
+#include <hildon-widgets/hildon-note.h>
#include <glib/gi18n.h>
#include <gtk/gtktreeviewcolumn.h>
ModestFolderView *folder_view;
};
-
-
#define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_MAIN_WINDOW, \
ModestMainWindowPrivate))
TnyIterator *iter;
} GetMsgAsyncHelper;
+
+/* FIXME use an enum not values, UI actions must know them. Create a
+ modest-window-mgr-ui.h and include it here? */
+static const GtkRadioActionEntry main_window_radio_action_entries [] = {
+ { "ViewFolders", NULL, N_("mcen_me_inbox_hidefolders"), NULL, NULL, 0 },
+ { "ViewFullscreen", NULL, N_("mcen_me_inbox_fullscreen"), NULL, NULL, 1 },
+};
+
/* globals */
static GtkWindowClass *parent_class = NULL;
return toolbar;
}
-
-static void
-on_destroy (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
-{
- gtk_main_quit();
-}
-
static void
connect_signals (ModestMainWindow *self)
{
G_CALLBACK(modest_ui_actions_on_item_not_found), self);
/* window */
- g_signal_connect (G_OBJECT(self), "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
modest_action_entries,
G_N_ELEMENTS (modest_action_entries),
self);
+
+ gtk_action_group_add_radio_actions (action_group,
+ main_window_radio_action_entries,
+ G_N_ELEMENTS (main_window_radio_action_entries),
+ 0,
+ G_CALLBACK (modest_ui_actions_on_change_fullscreen),
+ self);
gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
g_object_unref (action_group);
return MODEST_WINDOW(self);
}
+
+gboolean
+modest_main_window_close_all (ModestMainWindow *self)
+{
+ GtkWidget *note;
+ GtkResponseType response;
+
+ /* Create the confirmation dialog MSG-NOT308 */
+ note = hildon_note_new_confirmation_add_buttons (GTK_WINDOW (self),
+ _("emev_nc_close_windows"),
+ _("mcen_db_yes"), GTK_RESPONSE_YES,
+ _("mcen_db_no"), GTK_RESPONSE_NO,
+ NULL);
+
+ response = gtk_dialog_run (GTK_DIALOG (note));
+ gtk_widget_destroy (GTK_WIDGET (note));
+
+ if (response == GTK_RESPONSE_YES)
+ return TRUE;
+ else
+ return FALSE;
+}
return modest_msg_view_get_message (msg_view);
}
+const gchar*
+modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self)
+{
+ TnyMsg *msg;
+ TnyHeader *header;
+ const gchar *retval = NULL;
+
+ msg = modest_msg_view_window_get_message (self);
+
+ if (!msg)
+ return NULL;
+
+ header = tny_msg_get_header (msg);
+ if (header) {
+ retval = tny_header_get_uid (header);
+ g_object_unref (header);
+ }
+ return retval;
+}
+
static void
modest_msg_view_window_toggle_find_toolbar (GtkToggleAction *toggle,
gpointer data)
g_mutex_lock (priv->queue_lock);
if (priv->op_queue) {
+ /* Cancel all */
if (!g_queue_is_empty (priv->op_queue))
- g_queue_foreach (priv->op_queue, (GFunc) g_object_unref, NULL);
+ modest_mail_operation_queue_cancel_all (MODEST_MAIL_OPERATION_QUEUE (obj));
g_queue_free (priv->op_queue);
}
priv->platform_fact = NULL;
}
-
+ if (priv->mail_op_queue) {
+ g_object_unref (G_OBJECT(priv->mail_op_queue));
+ modest_runtime_verify_object_death(priv->mail_op_queue,"");
+ priv->mail_op_queue = NULL;
+ }
+ if (priv->window_mgr) {
+ g_object_unref (G_OBJECT(priv->window_mgr));
+ modest_runtime_verify_object_death(priv->window_mgr,"");
+ priv->window_mgr = NULL;
+ }
+
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
ModestWindow *win;
TnyFolder *folder = NULL;
TnyMsg *msg = NULL;
- gchar *account = NULL;
- GtkTreeModel *model = NULL;
- GtkTreeSelection *sel = NULL;
- GtkTreeIter iter;
ModestWindowMgr *mgr;
g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
goto cleanup;
}
- account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
- if (!account)
- account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
+ /* Look if we already have a message view for that header */
+ mgr = modest_runtime_get_window_mgr ();
+ win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
+
+ /* If not, create a new window */
+ if (!win) {
+ gchar *account;
+
+ account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
+ if (!account)
+ account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
- /* Create and register message view window */
- sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
- if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
- win = modest_msg_view_window_new_with_header_model (msg, account, model, iter);
- } else {
win = modest_msg_view_window_new (msg, account);
- }
- mgr = modest_runtime_get_window_mgr ();
- modest_window_mgr_register_window (mgr, win);
+ modest_window_mgr_register_window (mgr, win);
+
+ gtk_window_set_transient_for (GTK_WINDOW (win),
+ GTK_WINDOW (main_window));
- gtk_window_set_transient_for (GTK_WINDOW (win),
- GTK_WINDOW (main_window));
+ g_free (account);
+ }
gtk_widget_show_all (GTK_WIDGET(win));
cleanup:
- g_free (account);
-
if (folder)
g_object_unref (G_OBJECT (folder));
if (msg)
}
}
+void
+modest_ui_actions_on_toggle_fullscreen (GtkAction *action,
+ ModestWindow *window)
+{
+ ModestWindowMgr *mgr;
+ gboolean active;
+
+ mgr = modest_runtime_get_window_mgr ();
+ /* set/unset the application fullscreen mode */
+ active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+ modest_window_mgr_set_fullscreen_mode (mgr, active);
+
+ /* Bring the current window to the front. The above call will
+ put all the windows in fullscreen mode, so we can not be
+ sure that the last fullscreen-ed window is the current
+ one */
+ gtk_window_present (GTK_WINDOW (window));
+}
+
void
modest_ui_actions_on_change_zoom (GtkRadioAction *action,
GtkRadioAction *selected,
}
}
-void
-modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
- ModestWindow *window)
-{
- g_return_if_fail (MODEST_IS_WINDOW (window));
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle))) {
- gtk_window_fullscreen (GTK_WINDOW (window));
- } else {
- gtk_window_unfullscreen (GTK_WINDOW (window));
- }
-}
-
static void
modest_ui_actions_message_details_cb (gpointer msg_data,
gpointer helper_data)
g_return_if_reached ();
}
}
+
+void
+modest_ui_actions_on_change_fullscreen (GtkRadioAction *action,
+ GtkRadioAction *selected,
+ ModestWindow *window)
+{
+ gint value;
+ ModestWindowMgr *mgr;
+
+ value = gtk_radio_action_get_current_value (selected);
+ mgr = modest_runtime_get_window_mgr ();
+
+ if (value == 0)
+ modest_window_mgr_set_fullscreen_mode (mgr, FALSE);
+ else
+ modest_window_mgr_set_fullscreen_mode (mgr, TRUE);
+
+ gtk_window_present (GTK_WINDOW (window));
+}
gchar **password, gboolean *cancel,
gboolean *remember, ModestMainWindow *main_window);
-void modest_ui_actions_on_cut (GtkAction *action,
- ModestWindow *window);
-void modest_ui_actions_on_copy (GtkAction *action,
- ModestWindow *window);
-void modest_ui_actions_on_paste (GtkAction *action,
- ModestWindow *window);
-void modest_ui_actions_on_select_all (GtkAction *action,
- ModestWindow *window);
-
-void modest_ui_actions_on_change_zoom (GtkRadioAction *action,
- GtkRadioAction *selected,
- ModestWindow *window);
-
-void modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
- ModestWindow *window);
-
+void modest_ui_actions_on_cut (GtkAction *action,
+ ModestWindow *window);
+
+void modest_ui_actions_on_copy (GtkAction *action,
+ ModestWindow *window);
+
+void modest_ui_actions_on_paste (GtkAction *action,
+ ModestWindow *window);
+
+void modest_ui_actions_on_select_all (GtkAction *action,
+ ModestWindow *window);
+
+/**
+ * modest_ui_actions_on_toggle_fullscreen:
+ * @action: the #GtkAction
+ * @window: the window that will be shown in fullscreen mode
+ *
+ * puts a window in fullscreen mode
+ **/
+void modest_ui_actions_on_toggle_fullscreen (GtkAction *action,
+ ModestWindow *window);
+
+void modest_ui_actions_on_change_zoom (GtkRadioAction *action,
+ GtkRadioAction *selected,
+ ModestWindow *window);
+
+void modest_ui_actions_on_change_fullscreen (GtkRadioAction *action,
+ GtkRadioAction *selected,
+ ModestWindow *window);
G_END_DECLS
#endif /* __MODEST_UI_ACTIONS_H__ */
MODEST_WIDGET_TYPE_NUM,
} ModestWidgetType;
+
/**
* modest_main_window_get_child_widget
*
GtkWidget* modest_main_window_get_child_widget (ModestMainWindow *self,
ModestWidgetType widget_type);
+/**
+ * modest_main_window_close_all:
+ * @self:
+ *
+ * this function will ask the user about if the user wants to close
+ * all the windows or just the main one
+ *
+ * Returns: TRUE if the user selected to close all the windows, otherwise FALSE
+ **/
+gboolean modest_main_window_close_all (ModestMainWindow *self);
+
G_END_DECLS
#endif /* __MODEST_MAIN_WINDOW_H__ */
*
* Returns: a new #TnyMsg instance, or NULL in case of error
*/
-TnyMsg* modest_msg_view_window_get_message (ModestMsgViewWindow *window);
+TnyMsg* modest_msg_view_window_get_message (ModestMsgViewWindow *window);
+
+/**
+ * modest_msg_view_window_get_message_uid:
+ * @msg: an #ModestMsgViewWindow instance
+ *
+ * gets the unique identifier for the message in this msg view. The
+ * returned value *must* not be freed
+ *
+ * Returns: the id of the #TnyMsg being shown, or NULL in case of error
+ */
+const gchar* modest_msg_view_window_get_message_uid (ModestMsgViewWindow *window);
/**
* modest_msg_view_window_select_next_message:
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <string.h>
#include "modest-window-mgr.h"
+#include "widgets/modest-main-window.h"
+#include "widgets/modest-msg-edit-window.h"
+#include "widgets/modest-msg-view-window.h"
/* include other impl specific header files */
/* 'private'/'protected' functions */
typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate;
struct _ModestWindowMgrPrivate {
GList *window_list;
+ gboolean fullscreen_mode;
};
#define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_WINDOW_MGR, \
ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj);
priv->window_list = NULL;
+ priv->fullscreen_mode = FALSE;
}
static void
/* Listen to object destruction */
g_signal_connect (window, "destroy", G_CALLBACK (on_window_destroy), self);
+
+ /* Put into fullscreen if needed */
+ if (priv->fullscreen_mode)
+ gtk_window_fullscreen (GTK_WINDOW (window));
}
static void
on_window_destroy (ModestWindow *window, ModestWindowMgr *self)
{
+ /* Specific stuff first */
+ if (MODEST_IS_MAIN_WINDOW (window)) {
+ ModestWindowMgrPrivate *priv;
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* If more than one window already opened */
+ if (g_list_length (priv->window_list) > 1) {
+
+ /* If the user wants to close all the windows */
+ if (modest_main_window_close_all (MODEST_MAIN_WINDOW (window))) {
+ GList *iter = priv->window_list;
+ do {
+ if (iter->data != window) {
+ GList *tmp = iter->next;
+ on_window_destroy (MODEST_WINDOW (iter->data),
+ self);
+ iter = tmp;
+ } else {
+ iter = g_list_next (iter);
+ }
+ } while (iter);
+ }
+ }
+ } else {
+ if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
+ /* TODO: Save currently edited message to Drafts
+ folder */
+ }
+ }
+
+ /* Unregister window */
modest_window_mgr_unregister_window (self, window);
}
/* Remove from list. Remove the reference to the window */
g_object_unref (win->data);
priv->window_list = g_list_remove_link (priv->window_list, win);
+
+ /* If there are no more windows registered then exit program */
+ if (priv->window_list == NULL)
+ gtk_main_quit ();
}
-ModestWindow *
-modest_window_mgr_find_window_for_msgid (ModestWindowMgr *self,
- gchar *msgid,
- GType modest_window_type)
+static gint
+compare_msguids (ModestWindow *win,
+ const gchar *uid)
{
- /* TODO */
+ const gchar *msg_uid;
- return NULL;
+ 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 && !strcmp (msg_uid, uid))
+ return 0;
+ else
+ return 1;
+}
+
+ModestWindow*
+modest_window_mgr_find_window_by_msguid (ModestWindowMgr *self,
+ const gchar *msguid)
+{
+ ModestWindowMgrPrivate *priv;
+ GList *win = NULL;
+
+ g_return_val_if_fail (MODEST_IS_WINDOW_MGR (self), NULL);
+ g_return_val_if_fail (msguid != NULL, NULL);
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* Look for the window */
+ if (priv->window_list)
+ win = g_list_find_custom (priv->window_list,
+ msguid,
+ (GCompareFunc) compare_msguids);
+
+ if (win)
+ return win->data;
+ else
+ return NULL;
+}
+
+void
+modest_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
+ gboolean on)
+{
+ ModestWindowMgrPrivate *priv;
+ GList *win = NULL;
+
+ g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
+
+ priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
+
+ /* If there is no change do nothing */
+ if (priv->fullscreen_mode == on)
+ return;
+
+ priv->fullscreen_mode = on;
+
+ /* Update windows */
+ win = priv->window_list;
+ while (win) {
+ if (on)
+ gtk_window_fullscreen (GTK_WINDOW (win->data));
+ else
+ gtk_window_unfullscreen (GTK_WINDOW (win->data));
+ win = g_list_next (win);
+ }
}
#define __MODEST_WINDOW_MGR_H__
#include <glib-object.h>
-#include "widgets/modest-window.h"
+#include "widgets/modest-msg-view-window.h"
G_BEGIN_DECLS
/**
- * modest_window_mgr_find_window_for_msgid:
+ * modest_window_mgr_find_window_by_msguid:
* @self: the #ModestWindowMgr
- * @msgid: the message id
- * @modest_window_type: the type of the #ModestWindow we're looking for
+ * @msgid: the message uid
*
- * Looks for a window of a given type that have a relationship with
- * the message specified by the message id passed as argument
+ * Looks for a #ModestWindow that shows the message specified by the
+ * message uid passed as argument
*
* Return value: the #ModestWindow if found, else NULL
**/
-ModestWindow* modest_window_mgr_find_window_for_msgid (ModestWindowMgr *self,
- gchar *msgid,
- GType modest_window_type);
-
+ModestWindow* modest_window_mgr_find_window_by_msguid (ModestWindowMgr *self,
+ const gchar *msguid);
+
+/**
+ * modest_window_mgr_set_fullscreen_mode:
+ * @self:
+ * @on:
+ *
+ * sets/unsets the application windows in fullscreen mode
+ **/
+void modest_window_mgr_set_fullscreen_mode (ModestWindowMgr *self,
+ gboolean on);
G_END_DECLS
#endif /* __MODEST_WINDOW_MGR_H__ */