+ gtk_widget_show (GTK_WIDGET (window));
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), -1);
+ modest_shell_window_set_shell (MODEST_SHELL_WINDOW (window), shell);
+ update_title (shell);
+}
+
+gint
+modest_shell_count_windows (ModestShell *shell)
+{
+ ModestShellPrivate *priv;
+
+ priv = MODEST_SHELL_GET_PRIVATE (shell);
+
+ return gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+}
+
+void
+modest_shell_set_title (ModestShell *shell, ModestWindow *window, const gchar *title)
+{
+ ModestShellPrivate *priv;
+
+ priv = MODEST_SHELL_GET_PRIVATE (shell);
+
+ gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), title);
+
+ update_title (shell);
+}
+
+static void
+show_next_frame (ModestShell *shell)
+{
+ ModestShellPrivate *priv;
+
+ priv = MODEST_SHELL_GET_PRIVATE (shell);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (priv->progress_icon), priv->progress_frames[priv->next_frame]);
+
+ priv->next_frame++;
+ if (priv->next_frame >= 31)
+ priv->next_frame = 0;
+}
+
+static gboolean
+on_progress_timeout (ModestShell *shell)
+{
+ show_next_frame (shell);
+ return TRUE;
+}
+
+void
+modest_shell_show_progress (ModestShell *shell, ModestWindow *window, gboolean show)
+{
+ ModestShellPrivate *priv;
+
+ priv = MODEST_SHELL_GET_PRIVATE (shell);
+
+ if (show) {
+ if (priv->progress_timeout_id == 0) {
+ priv->progress_timeout_id = g_timeout_add (100, (GSourceFunc) on_progress_timeout, shell);
+ show_next_frame (shell);
+ }
+ gtk_widget_show (priv->progress_icon);
+ } else {
+ if (priv->progress_timeout_id) {
+ g_source_remove (priv->progress_timeout_id);
+ priv->progress_timeout_id = 0;
+ }
+ gtk_widget_hide (priv->progress_icon);
+ }
+}
+
+static void
+update_title (ModestShell *self)
+{
+ gint n_pages, i;
+ ModestShellPrivate *priv;
+ GtkWidget *child;
+ GString *title_buffer;
+ GString *subtitle_buffer;
+ const gchar *tab_label_text;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+ if (n_pages == 0) {
+ gtk_label_set_text (GTK_LABEL (priv->title_label), "");
+ gtk_label_set_text (GTK_LABEL (priv->subtitle_label), "");
+ return;
+ }
+
+ child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), n_pages - 1);
+ title_buffer = g_string_new ("");
+ title_buffer = g_string_append (title_buffer, "<b>");
+ tab_label_text = gtk_notebook_get_tab_label_text (GTK_NOTEBOOK (priv->notebook), child);
+ if (tab_label_text)
+ title_buffer = g_string_append (title_buffer, tab_label_text);
+ title_buffer = g_string_append (title_buffer, "</b>");
+ gtk_label_set_markup (GTK_LABEL (priv->title_label),
+ title_buffer->str);
+ g_string_free (title_buffer, TRUE);
+
+ subtitle_buffer = g_string_new ("");
+ subtitle_buffer = g_string_append (subtitle_buffer, "<small>");
+ for (i = 0; i < n_pages - 1; i++) {
+ child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
+ if (i != 0) {
+ subtitle_buffer = g_string_append (subtitle_buffer, " / ");
+ }
+ subtitle_buffer = g_string_append (subtitle_buffer,
+ gtk_notebook_get_tab_label_text (GTK_NOTEBOOK (priv->notebook), child));
+ }
+ subtitle_buffer = g_string_append (subtitle_buffer, "</small>");
+ gtk_label_set_markup (GTK_LABEL (priv->subtitle_label),
+ subtitle_buffer->str);
+ g_string_free (subtitle_buffer, TRUE);
+}
+
+static void
+on_back_button_clicked (GtkToolButton *button, ModestShell *self)
+{
+ ModestShellPrivate *priv;
+ gint n_pages;
+ gboolean delete_event_retval;
+ GtkWidget *child;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+ if (n_pages < 1)
+ return;
+
+ child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), -1);
+ g_signal_emit_by_name (G_OBJECT (child), "delete-event", NULL, &delete_event_retval);
+
+ if (!delete_event_retval) {
+ update_title (self);
+ }
+}
+
+static void
+menu_position_cb (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ ModestShell *self)
+{
+ ModestShellPrivate *priv;
+ GtkAllocation *alloc;
+ GdkWindow *parent_window;
+ gint pos_x, pos_y;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ alloc = &(GTK_WIDGET (priv->title_button)->allocation);
+ parent_window = gtk_widget_get_parent_window (GTK_WIDGET (priv->title_button));
+ gdk_window_get_position (parent_window, &pos_x, &pos_y);
+ *x = pos_x + alloc->x;
+ *y = pos_y + alloc->y + alloc->height;
+ *push_in = TRUE;
+
+}
+
+static void
+on_title_button_clicked (GtkToolButton *button, ModestShell *self)
+{
+ ModestShellPrivate *priv;
+ gint n_pages;
+ GtkWidget *child;
+ GtkWidget *menu;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+ if (n_pages < 1)
+ return;
+
+ child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), -1);
+ menu = modest_shell_window_get_menu (MODEST_SHELL_WINDOW (child));
+
+ if (menu) {
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ (GtkMenuPositionFunc) menu_position_cb, (gpointer) self,
+ 1, gtk_get_current_event_time ());
+ }
+}
+
+static void
+on_new_msg_button_clicked (GtkToolButton *button, ModestShell *self)
+{
+ ModestShellPrivate *priv;
+ gint n_pages;
+ GtkWidget *child;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+ if (n_pages < 1)
+ return;
+
+ child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), -1);
+
+ modest_ui_actions_on_new_msg (NULL, MODEST_WINDOW (child));
+}
+
+static void
+on_style_set (GtkWidget *widget,
+ GtkStyle *old_style,
+ ModestShell *self)
+{
+ ModestShellPrivate *priv;
+ gint icon_w, icon_h;
+ GdkPixbuf *progress_pixbuf;
+ int n;
+
+ priv = MODEST_SHELL_GET_PRIVATE (self);
+
+ if (!gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_w, &icon_h))
+ return;
+ progress_pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "process-working", icon_w, 0, NULL);
+
+ for (n = 0; n < 31; n++) {
+ if (priv->progress_frames[n] != NULL) {
+ g_object_unref (priv->progress_frames[n]);
+ }
+ priv->progress_frames[n] = NULL;
+ }
+
+ if (progress_pixbuf) {
+ gint max_x, max_y;
+ gint i, j;
+
+ icon_w = gdk_pixbuf_get_width (progress_pixbuf) / 8;
+
+ n = 0;
+ max_x = 8;
+ max_y = 4;
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 8; j++) {
+ GdkPixbuf *frame;
+
+ if ((i == 0) && (j == 0))
+ continue;
+ frame = gdk_pixbuf_new_subpixbuf (progress_pixbuf,
+ j*icon_w, i*icon_w,
+ icon_w, icon_w);
+ priv->progress_frames[n] = frame;
+ n++;
+ }
+ }
+ g_object_unref (progress_pixbuf);
+ }
+