+ ModestAccountMgr *mgr;
+ gint i, num_accounts;
+ GtkActionGroup *action_group;
+ GList *groups;
+ gchar *default_account;
+ GtkWidget *send_receive_button, *item;
+
+ self = MODEST_MAIN_WINDOW (user_data);
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self);
+ parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
+
+ /* Get enabled account IDs */
+ mgr = modest_runtime_get_account_mgr ();
+ account_names = modest_account_mgr_account_names (mgr, TRUE);
+ iter = account_names;
+ accounts = NULL;
+
+ while (iter) {
+ ModestAccountData *account_data =
+ modest_account_mgr_get_account_data (mgr, (gchar*) iter->data);
+ accounts = g_slist_prepend (accounts, account_data);
+
+ iter = iter->next;
+ }
+ modest_account_mgr_free_account_names (account_names);
+ account_names = NULL;
+
+ /* Order the list of accounts by its display name */
+ accounts = g_slist_sort (accounts, (GCompareFunc) compare_display_names);
+ num_accounts = g_slist_length (accounts);
+
+ /* Delete old send&receive popup items. We can not just do a
+ menu_detach because it does not work well with
+ tap_and_hold */
+ if (priv->accounts_popup)
+ gtk_container_foreach (GTK_CONTAINER (priv->accounts_popup),
+ (GtkCallback) gtk_widget_destroy, NULL);
+
+ /* Delete old entries in the View menu. Do not free groups, it
+ belongs to Gtk+ */
+ groups = gtk_ui_manager_get_action_groups (parent_priv->ui_manager);
+ while (groups) {
+ if (!strcmp (MODEST_MAIN_WINDOW_ACTION_GROUP_ADDITIONS,
+ gtk_action_group_get_name (GTK_ACTION_GROUP (groups->data)))) {
+ gtk_ui_manager_remove_action_group (parent_priv->ui_manager,
+ GTK_ACTION_GROUP (groups->data));
+ groups = NULL;
+ /* Remove uis */
+ if (priv->merge_ids) {
+ for (i = 0; i < priv->merge_ids->len; i++)
+ gtk_ui_manager_remove_ui (parent_priv->ui_manager, priv->merge_ids->data[i]);
+ g_byte_array_free (priv->merge_ids, TRUE);
+ }
+ /* We need to call this in order to ensure
+ that the new actions are added in the right
+ order (alphabetical */
+ gtk_ui_manager_ensure_update (parent_priv->ui_manager);
+ } else
+ groups = g_list_next (groups);
+ }
+ priv->merge_ids = g_byte_array_sized_new (num_accounts);
+
+ /* Get send receive button */
+ send_receive_button = gtk_ui_manager_get_widget (parent_priv->ui_manager,
+ "/ToolBar/ToolbarSendReceive");
+
+ /* Create the menu */
+ if (num_accounts > 1) {
+ if (!priv->accounts_popup)
+ 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));
+ g_signal_connect (G_OBJECT (item),
+ "activate",
+ G_CALLBACK (on_send_receive_csm_activated),
+ NULL);
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+ }
+
+ /* Create a new action group */
+ default_account = modest_account_mgr_get_default_account (mgr);
+ action_group = gtk_action_group_new (MODEST_MAIN_WINDOW_ACTION_GROUP_ADDITIONS);
+ for (i = 0; i < num_accounts; i++) {
+ gchar *display_name = NULL;
+
+ ModestAccountData *account_data = (ModestAccountData *) g_slist_nth_data (accounts, i);
+
+ /* Create display name. The default account is shown differently */
+ if (default_account && account_data->account_name &&
+ !(strcmp (default_account, account_data->account_name) == 0)) {
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"),
+ account_data->display_name);
+ }
+ else {
+ display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"),
+ account_data->display_name);
+ }
+
+ /* Create action and add it to the action group. The
+ action name must be the account name, this way we
+ could know in the handlers the account to show */
+ if(account_data->account_name) {
+ gchar* item_name, *refresh_action_name;
+ guint8 merge_id;
+ GtkAction *view_account_action, *refresh_account_action;
+
+ view_account_action = gtk_action_new (account_data->account_name,
+ display_name, NULL, NULL);
+ gtk_action_group_add_action (action_group, view_account_action);
+
+ /* Add ui from account data. We allow 2^9-1 account
+ changes in a single execution because we're
+ downcasting the guint to a guint8 in order to use a
+ GByteArray, it should be enough */
+ item_name = g_strconcat (account_data->account_name, "Menu", NULL);
+ merge_id = (guint8) gtk_ui_manager_new_merge_id (parent_priv->ui_manager);
+ priv->merge_ids = g_byte_array_append (priv->merge_ids, &merge_id, 1);
+ gtk_ui_manager_add_ui (parent_priv->ui_manager,
+ merge_id,
+ "/MenuBar/ViewMenu/ViewMenuAdditions",
+ item_name,
+ account_data->account_name,
+ GTK_UI_MANAGER_MENUITEM,
+ FALSE);
+
+ /* Connect the action signal "activate" */
+ g_signal_connect (G_OBJECT (view_account_action),
+ "activate",
+ G_CALLBACK (on_show_account_action_activated),
+ self);
+
+ /* Create the items for the Tools->Send&Receive submenu */
+ refresh_action_name = g_strconcat ("SendReceive", account_data->account_name, NULL);
+ refresh_account_action = gtk_action_new ((const gchar*) refresh_action_name,
+ display_name, NULL, NULL);
+ gtk_action_group_add_action (action_group, refresh_account_action);
+
+ merge_id = (guint8) gtk_ui_manager_new_merge_id (parent_priv->ui_manager);
+ priv->merge_ids = g_byte_array_append (priv->merge_ids, &merge_id, 1);
+ gtk_ui_manager_add_ui (parent_priv->ui_manager,
+ merge_id,
+ "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsMenuAdditions",
+ item_name,
+ refresh_action_name,
+ GTK_UI_MANAGER_MENUITEM,
+ FALSE);
+ g_free (refresh_action_name);
+
+ g_signal_connect_data (G_OBJECT (refresh_account_action),
+ "activate",
+ G_CALLBACK (on_refresh_account_action_activated),
+ g_strdup (account_data->account_name),
+ (GClosureNotify) g_free,
+ 0);
+
+ /* Create item and add it to the send&receive
+ CSM. If there is only one account then
+ it'll be no menu */
+ if (priv->accounts_popup) {
+ item = gtk_menu_item_new_with_label (display_name);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
+ g_signal_connect_data (G_OBJECT (item),
+ "activate",
+ G_CALLBACK (on_send_receive_csm_activated),
+ g_strdup (account_data->account_name),
+ (GClosureNotify) g_free,
+ 0);
+ }
+ g_free (item_name);
+ }
+
+ /* Frees */
+ g_free (display_name);
+ modest_account_mgr_free_account_data (mgr, account_data);
+ }
+ gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 1);
+
+ if (priv->accounts_popup) {
+ /* Mandatory in order to view the menu contents */
+ gtk_widget_show_all (priv->accounts_popup);
+
+ /* Setup tap_and_hold just if was not done before*/
+ if (!gtk_menu_get_attach_widget (GTK_MENU (priv->accounts_popup)))
+ gtk_widget_tap_and_hold_setup (send_receive_button, priv->accounts_popup, NULL, 0);
+ }
+
+ /* Frees */
+ g_slist_free (accounts);
+ g_free (default_account);
+}
+
+/*
+ * 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_empty_view (void)
+{
+ GtkLabel *label = NULL;
+ GtkWidget *align = NULL;
+
+ align = gtk_alignment_new(XALIGN, YALIGN, XSPACE, YSPACE);
+ label = GTK_LABEL(gtk_label_new (_("mcen_ia_nomessages")));
+ gtk_label_set_justify (label, GTK_JUSTIFY_CENTER);
+ gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET(label));
+
+ return GTK_WIDGET(align);
+}
+
+static GtkWidget *
+create_details_widget (TnyAccount *account)
+{
+ GtkWidget *vbox;
+ gchar *label;
+
+ vbox = gtk_vbox_new (FALSE, 0);
+
+ /* Account description: */
+
+ if (modest_tny_account_is_virtual_local_folders (account)) {
+ /* Local folders: */
+
+ /* Get device name */
+ gchar *device_name = modest_conf_get_string (modest_runtime_get_conf(),
+ MODEST_CONF_DEVICE_NAME, NULL);
+
+ label = g_strdup_printf (_("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)) {
+ gtk_box_pack_start (GTK_BOX (vbox),
+ gtk_label_new (tny_account_get_name (account)),
+ FALSE, FALSE, 0);
+ } else {
+ /* Other accounts, such as IMAP and POP: */
+
+ GString *proto;
+ gchar *tmp;