+
+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)) {
+ /* FIXME: format size */
+ 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 = (TnyAccount *) modest_folder_view_get_selected (priv->folder_view);
+ if (TNY_IS_ACCOUNT (account) &&
+ !strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
+ GList *children;
+ GtkLabel *label;
+ const gchar *device_name;
+ gchar *new_text;
+
+ /* Get label */
+ children = gtk_container_get_children (GTK_CONTAINER (priv->details_widget));
+ label = GTK_LABEL (children->data);
+
+ device_name = modest_conf_get_string (modest_runtime_get_conf(),
+ MODEST_CONF_DEVICE_NAME, NULL);
+
+ new_text = g_strdup_printf ("%s: %s",
+ _("mcen_fi_localroot_description"),
+ device_name);
+
+ gtk_label_set_text (label, new_text);
+ gtk_widget_show (GTK_WIDGET (label));
+
+ g_free (new_text);
+ g_list_free (children);
+ }
+}
+
+static void
+set_toolbar_mode (ModestMainWindow *self,
+ ModestToolBarModes mode)
+{
+ ModestWindowPrivate *parent_priv = NULL;
+ ModestMainWindowPrivate *priv = NULL;
+ GtkAction *sort_action = NULL, *refresh_action = NULL, *cancel_action = NULL;
+
+ g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+
+ parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ g_return_if_fail (GTK_IS_TOOLBAR(parent_priv->toolbar));
+
+ sort_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSort");
+ refresh_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSendReceive");
+ cancel_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarCancel");
+
+ /* Sets current toolbar mode */
+ priv->current_toolbar_mode = mode;
+
+ /* Show and hide toolbar items */
+ switch (mode) {
+ case TOOLBAR_MODE_NORMAL:
+ if (sort_action)
+ gtk_action_set_visible (sort_action, TRUE);
+ if (refresh_action)
+ gtk_action_set_visible (refresh_action, TRUE);
+ if (priv->progress_toolitem) {
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE);
+ gtk_widget_hide (priv->progress_toolitem);
+ }
+ if (priv->progress_bar)
+ gtk_widget_hide (priv->progress_bar);
+
+ if (cancel_action)
+ gtk_action_set_visible (cancel_action, FALSE);
+
+ /* Hide toolbar if optimized view is enabled */
+ if (priv->optimized_view)
+ gtk_widget_hide (GTK_WIDGET(parent_priv->toolbar));
+ break;
+ case TOOLBAR_MODE_TRANSFER:
+ if (sort_action)
+ gtk_action_set_visible (sort_action, FALSE);
+ if (refresh_action)
+ gtk_action_set_visible (refresh_action, FALSE);
+ if (cancel_action)
+ gtk_action_set_visible (cancel_action, TRUE);
+ if (priv->progress_toolitem) {
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), TRUE);
+ gtk_widget_show (priv->progress_toolitem);
+ }
+ if (priv->progress_bar)
+ gtk_widget_show (priv->progress_bar);
+
+ /* Show toolbar if it's hiden (optimized view ) */
+ if (priv->optimized_view)
+ gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
+ break;
+ default:
+ g_return_if_reached ();
+ }
+}
+
+static void
+cancel_progressbar (GtkToolButton *toolbutton,
+ ModestMainWindow *self)
+{
+ GSList *tmp;
+ ModestMainWindowPrivate *priv;
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ /* Get operation observers and cancel its current operation */
+ tmp = priv->progress_widgets;
+ while (tmp) {
+ modest_progress_object_cancel_current_operation (MODEST_PROGRESS_OBJECT(tmp->data));
+ tmp=g_slist_next(tmp);
+ }
+}
+
+static gboolean
+observers_empty (ModestMainWindow *self)
+{
+ GSList *tmp = NULL;
+ ModestMainWindowPrivate *priv;
+ gboolean is_empty = TRUE;
+ guint pending_ops = 0;
+
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ tmp = priv->progress_widgets;
+
+ /* Check all observers */
+ while (tmp && is_empty) {
+ pending_ops = modest_progress_object_num_pending_operations (MODEST_PROGRESS_OBJECT(tmp->data));
+ is_empty = pending_ops == 0;
+
+ tmp = g_slist_next(tmp);
+ }
+
+ return is_empty;
+}
+
+static void
+on_queue_changed (ModestMailOperationQueue *queue,
+ ModestMailOperation *mail_op,
+ ModestMailOperationQueueNotification type,
+ ModestMainWindow *self)
+{
+ ModestMainWindowPrivate *priv;
+ ModestMailOperationId op_id;
+ ModestToolBarModes mode;
+ GSList *tmp;
+ gboolean mode_changed = FALSE;
+
+ g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+ /* Get toolbar mode from operation id*/
+ op_id = modest_mail_operation_get_id (mail_op);
+ switch (op_id) {
+ case MODEST_MAIL_OPERATION_ID_SEND:
+ case MODEST_MAIL_OPERATION_ID_RECEIVE:
+ mode = TOOLBAR_MODE_TRANSFER;
+ if (priv->current_toolbar_mode == TOOLBAR_MODE_NORMAL)
+ mode_changed = TRUE;
+ break;
+ default:
+ mode = TOOLBAR_MODE_NORMAL;
+
+ }
+
+
+ /* Add operation observers and change toolbar if neccessary*/
+ tmp = priv->progress_widgets;
+ switch (type) {
+ case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED:
+ if (mode_changed)
+ set_toolbar_mode (self, mode);
+ if (mode == TOOLBAR_MODE_TRANSFER) {
+ while (tmp) {
+ modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ mail_op);
+ tmp = g_slist_next (tmp);
+ }
+ }
+ break;
+ case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
+ if (mode == TOOLBAR_MODE_TRANSFER) {
+ while (tmp) {
+ modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
+ mail_op);
+ tmp = g_slist_next (tmp);
+ }
+
+ /* If no more operations are being observed, NORMAL mode is enabled again */
+ if (observers_empty (self))
+ set_toolbar_mode (self, TOOLBAR_MODE_NORMAL);
+ }
+ break;
+ }
+}