+
+ 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_bd_yes"), GTK_RESPONSE_YES,
+ _("mcen_bd_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;
+}
+
+void
+modest_main_window_set_style (ModestMainWindow *self,
+ ModestMainWindowStyle style)
+{
+ ModestMainWindowPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ /* no change -> nothing to do */
+ if (priv->style == style)
+ return;
+
+ priv->style = style;
+
+ switch (style) {
+ case MODEST_MAIN_WINDOW_STYLE_SIMPLE:
+ /* Remove main paned */
+ g_object_ref (priv->main_paned);
+ gtk_container_remove (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
+
+ /* Reparent the contents widget to the main vbox */
+ gtk_widget_reparent (priv->contents_widget, priv->main_vbox);
+
+ break;
+ case MODEST_MAIN_WINDOW_STYLE_SPLIT:
+ /* Remove header view */
+ g_object_ref (priv->contents_widget);
+ gtk_container_remove (GTK_CONTAINER (priv->main_vbox), priv->contents_widget);
+
+ /* Reparent the main paned */
+ gtk_paned_add2 (GTK_PANED (priv->main_paned), priv->contents_widget);
+ gtk_container_add (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ /* Let header view grab the focus if it's being shown */
+ if (priv->contents_style == MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
+ gtk_widget_grab_focus (GTK_WIDGET (priv->header_view));
+ else
+ gtk_widget_grab_focus (GTK_WIDGET (priv->contents_widget));
+
+ /* Show changes */
+ gtk_widget_show_all (GTK_WIDGET (priv->main_vbox));
+}
+
+ModestMainWindowStyle
+modest_main_window_get_style (ModestMainWindow *self)
+{
+ ModestMainWindowPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (self), -1);
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ return priv->style;
+}
+
+static gboolean
+modest_main_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
+{
+ if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
+ ModestWindowPrivate *parent_priv;
+ ModestWindowMgr *mgr;
+ gboolean is_fullscreen;
+ GtkAction *fs_toggle_action;
+ gboolean active;
+
+ mgr = modest_runtime_get_window_mgr ();
+
+ is_fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
+
+ fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
+ active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
+ if (is_fullscreen != active) {
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
+ }
+ }
+
+ return FALSE;
+
+}
+
+static void
+set_homogeneous (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (widget), TRUE);
+ gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), TRUE);
+}
+
+static void
+modest_main_window_show_toolbar (ModestWindow *self,
+ gboolean show_toolbar)
+{
+ ModestWindowPrivate *parent_priv;
+ GtkWidget *reply_button = NULL, *menu = NULL;
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
+
+ if (!parent_priv->toolbar && show_toolbar) {
+ parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager,
+ "/ToolBar");
+
+ /* Set homogeneous toolbar */
+ gtk_container_foreach (GTK_CONTAINER (parent_priv->toolbar),
+ set_homogeneous, NULL);
+
+ /* Add to window */
+ hildon_window_add_toolbar (HILDON_WINDOW (self),
+ GTK_TOOLBAR (parent_priv->toolbar));
+
+ /* Set reply button tap and hold menu */
+ reply_button = gtk_ui_manager_get_widget (parent_priv->ui_manager,
+ "/ToolBar/ToolbarMessageReply");
+ menu = gtk_ui_manager_get_widget (parent_priv->ui_manager,
+ "/ToolbarReplyContextMenu");
+ gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0);
+
+ /* Set send & receive button tap and hold menu */
+ on_account_update (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ NULL, self);
+ }
+
+
+ if (show_toolbar)
+ gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
+ else
+ gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
+}
+
+/*
+ * TODO: modify the menu dinamically. Add handlers to each item of the
+ * menu when created
+ */
+static void
+on_account_update (TnyAccountStore *account_store,
+ gchar *accout_name,
+ gpointer user_data)
+{
+ ModestMainWindow *self;
+ ModestMainWindowPrivate *priv;
+ ModestWindowPrivate *parent_priv;
+ TnyList *account_list;
+ GtkWidget *item, *send_receive_button;
+ TnyIterator *iter;
+ ModestAccountMgr *mgr;
+ gchar *default_account;
+
+ self = MODEST_MAIN_WINDOW (user_data);
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self);
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
+
+ /* If there is no toolbar then exit */
+ if (!parent_priv->toolbar)
+ return;
+
+ if (priv->accounts_popup)
+ gtk_menu_detach (GTK_MENU (priv->accounts_popup));
+
+ /* Get accounts */
+ account_list = tny_simple_list_new ();
+ tny_account_store_get_accounts (account_store,
+ account_list,
+ TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+
+ /* If there is only one account do not show any menu */
+ if (tny_list_get_length (account_list) <= 1)
+ goto free;
+
+ /* Get send receive button */
+ send_receive_button = gtk_ui_manager_get_widget (parent_priv->ui_manager,
+ "/ToolBar/ToolbarSendReceive");
+
+ /* Create the menu */
+ priv->accounts_popup = gtk_menu_new ();
+ item = gtk_menu_item_new_with_label (_("mcen_me_toolbar_sendreceive_all"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+
+ iter = tny_list_create_iterator (account_list);
+ mgr = modest_runtime_get_account_mgr ();
+ default_account = modest_account_mgr_get_default_account (mgr);
+
+ do {
+ TnyAccount *acc;
+ const gchar *acc_name;
+ gchar *display_name;
+
+ /* Create tool item */
+ acc = TNY_ACCOUNT (tny_iterator_get_current (iter));
+ acc_name = tny_account_get_name (acc);
+
+ /* Create display name */
+ if (!strcmp (default_account, acc_name))
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), acc_name);
+ else
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"), acc_name);
+
+ item = gtk_menu_item_new_with_label (display_name);
+
+ /* Free */
+ g_free (display_name);
+ g_object_unref (acc);
+
+ /* Append item */
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+
+ /* Go to next */
+ tny_iterator_next (iter);
+
+ } while (!tny_iterator_is_done (iter));
+
+ g_object_unref (iter);
+
+ /* Mandatory in order to view the menu contents */
+ gtk_widget_show_all (priv->accounts_popup);
+
+ /* Setup tap_and_hold */
+ gtk_widget_tap_and_hold_setup (send_receive_button, priv->accounts_popup, NULL, 0);
+
+ free:
+
+ /* Free */
+ g_object_unref (account_list);
+}
+
+/*
+ * This function manages the key events used to navigate between
+ * header and folder views (when the window is in split view)
+ *
+ * FROM KEY ACTION
+ * -------------------------------------------------
+ * HeaderView GDK_Left Move focus to folder view
+ * FolderView GDK_Right Move focus to header view
+ *
+ * There is no need to scroll to selected row, the widgets will be the
+ * responsibles of doing that (probably managing the focus-in event
+ */
+static gboolean
+on_inner_widgets_key_pressed (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer user_data)
+{
+ ModestMainWindowPrivate *priv;
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE (user_data);
+
+ /* Do nothing if we're in SIMPLE style */
+ if (priv->style == MODEST_MAIN_WINDOW_STYLE_SIMPLE)
+ return FALSE;
+
+ if (MODEST_IS_HEADER_VIEW (widget) && event->keyval == GDK_Left)
+ gtk_widget_grab_focus (GTK_WIDGET (priv->folder_view));
+ else if (MODEST_IS_FOLDER_VIEW (widget) && event->keyval == GDK_Right)
+ gtk_widget_grab_focus (GTK_WIDGET (priv->header_view));
+
+ return FALSE;
+}
+
+static void
+set_alignment (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
+ gtk_misc_set_padding (GTK_MISC (widget), 0, 0);
+}
+
+static GtkWidget *
+create_details_widget (TnyAccount *account)
+{
+ GtkWidget *vbox;
+ gchar *label;
+
+ vbox = gtk_vbox_new (FALSE, 0);
+
+ /* Account description */
+ if (!strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
+ gchar *device_name;
+
+ /* Get device name */
+ device_name = modest_conf_get_string (modest_runtime_get_conf(),
+ MODEST_CONF_DEVICE_NAME, NULL);
+
+ label = g_strdup_printf ("%s: %s",
+ _("mcen_fi_localroot_description"),
+ device_name);
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_free (device_name);
+ g_free (label);
+ } else if (!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) {
+ /* TODO: MMC ? */
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0);
+ } else {
+ GString *proto;
+
+ /* Put proto in uppercase */
+ proto = g_string_new (tny_account_get_proto (account));
+ proto = g_string_ascii_up (proto);
+
+ label = g_strdup_printf ("%s %s: %s",
+ proto->str,
+ _("mcen_fi_remoteroot_account"),
+ tny_account_get_name (account));
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_string_free (proto, TRUE);
+ g_free (label);
+ }
+
+ /* Message count */
+ label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_messages"),
+ modest_tny_account_get_message_count (account));
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_free (label);
+
+ /* Folder count */
+ label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_folders"),
+ modest_tny_account_get_folder_count (account));
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_free (label);
+
+ /* Size / Date */
+ if (!strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
+ label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_size"),
+ modest_tny_account_get_local_size (account));
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_free (label);
+ } else if (!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) {
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0);
+ } else {
+ label = g_strdup_printf ("%s: %s", _("mcen_ti_lastupdated"), "08/08/08");
+ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
+ g_free (label);
+ }
+
+ /* Set alignment */
+ gtk_container_foreach (GTK_CONTAINER (vbox), (GtkCallback) set_alignment, NULL);
+
+ return vbox;
+}
+
+void
+modest_main_window_set_contents_style (ModestMainWindow *self,
+ ModestMainWindowContentsStyle style)
+{
+ ModestMainWindowPrivate *priv;
+ GtkWidget *content;
+ TnyAccount *account;
+
+ g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ /* We allow to set the same content style than the previously
+ set if there are details, because it could happen when we're
+ selecting different accounts consecutively */
+ if ((priv->contents_style == style) &&
+ (priv->contents_style == MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS))
+ return;
+
+ /* Remove previous child. Delete it if it was an account
+ details widget */
+ content = gtk_bin_get_child (GTK_BIN (priv->contents_widget));
+ if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
+ g_object_ref (content);
+ gtk_container_remove (GTK_CONTAINER (priv->contents_widget), content);
+
+ priv->contents_style = style;
+
+ switch (priv->contents_style) {
+ case MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS:
+ wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET (priv->header_view));
+ break;
+ case MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS:
+ /* TODO: show here account details */
+ account = TNY_ACCOUNT (modest_folder_view_get_selected (priv->folder_view));
+ priv->details_widget = create_details_widget (account);
+
+ wrap_in_scrolled_window (priv->contents_widget,
+ priv->details_widget);
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ /* Show */
+ gtk_widget_show_all (priv->contents_widget);
+}
+
+static void
+on_configuration_key_changed (ModestConf* conf,
+ const gchar *key,
+ ModestConfEvent event,
+ ModestMainWindow *self)
+{
+ ModestMainWindowPrivate *priv;
+ TnyAccount *account;
+
+ if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME))
+ return;
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
+ return;
+
+ account = TNY_ACCOUNT (modest_folder_view_get_selected (priv->folder_view));
+ if (!strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
+ /* TODO: change device name */
+ }