[anjal: 1/2] Make it possible to open mails in new tab. Limited functionality. You
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: svn-commits-list gnome org
- Subject: [anjal: 1/2] Make it possible to open mails in new tab. Limited functionality. You
- Date: Tue, 24 Mar 2009 05:52:09 -0400 (EDT)
commit f8c0f31504fa4608cd289c959b3bc492ba3cd59f
Author: Srinivasa Ragavan <sragavan novell com>
Date: Tue Mar 24 15:14:51 2009 +0530
Make it possible to open mails in new tab. Limited functionality. You
can't browse next/prev mails. But just open in new tab on middle click.
---
src/mail-composer-view.c | 2 +-
src/mail-conv-view.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-
src/mail-conv-view.h | 5 ++-
src/mail-folder-view.c | 44 +++++++++++++++++++++--
src/mail-folder-view.h | 1 +
src/mail-view.c | 83 ++++++++++++++++++++++++++----------------
src/mail-view.h | 4 ++-
7 files changed, 189 insertions(+), 40 deletions(-)
diff --git a/src/mail-composer-view.c b/src/mail-composer-view.c
index 25f04f0..008ca9d 100644
--- a/src/mail-composer-view.c
+++ b/src/mail-composer-view.c
@@ -162,7 +162,7 @@ mail_composer_view_activate (MailComposerView *mfv, GtkWidget *folder_tree, GtkW
{
if (!folder_tree || !check_mail || !sort_by)
return;
- gtk_widget_set_sensitive (folder_tree, act);
+ gtk_widget_hide (folder_tree);
gtk_widget_set_sensitive (check_mail, act);
gtk_widget_set_sensitive (sort_by, act);
}
diff --git a/src/mail-conv-view.c b/src/mail-conv-view.c
index 44ff37b..f9f699e 100644
--- a/src/mail-conv-view.c
+++ b/src/mail-conv-view.c
@@ -25,11 +25,19 @@
#endif
#include <glib/gi18n.h>
#include "mail-conv-view.h"
+#include "e-util/e-icon-factory.h"
#include <gdk/gdkkeysyms.h>
G_DEFINE_TYPE (MailConvView, mail_conv_view, GTK_TYPE_VBOX)
+enum {
+ VIEW_CLOSE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
struct _MailConvViewPrivate {
GtkWidget *viewport;
GList *child;
@@ -40,6 +48,7 @@ static void
mail_conv_view_init (MailConvView *shell)
{
shell->priv = g_new0(MailConvViewPrivate, 1);
+ shell->type = -1;
}
static void
@@ -59,8 +68,9 @@ mcv_focus (GtkWidget *widget,
{
MailConvView *shell = (MailConvView *)widget;
MailConvViewPrivate *priv = shell->priv;
-
- gtk_widget_grab_focus (priv->child->data);
+
+ if (priv->child)
+ gtk_widget_grab_focus (priv->child->data);
return TRUE;
}
@@ -157,6 +167,15 @@ mail_conv_view_class_init (MailConvViewClass *klass)
GObjectClass * object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass * widget_class = (GtkWidgetClass *) klass;
+ signals[VIEW_CLOSE] =
+ g_signal_new ("view-close",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (MailConvViewClass , view_close),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
mail_conv_view_parent_class = g_type_class_peek_parent (klass);
object_class->finalize = mail_conv_view_finalize;
widget_class->focus = mcv_focus;
@@ -354,3 +373,70 @@ mail_conv_view_new ()
return mcview;
}
+
+void
+mail_conv_view_activate (MailConvView *mcv, GtkWidget *tree, GtkWidget *folder_tree, GtkWidget *check_mail, GtkWidget *sort_by, gboolean act)
+{
+ if (!folder_tree || !check_mail || !sort_by)
+ return;
+ gtk_widget_hide (folder_tree);
+ gtk_widget_set_sensitive (check_mail, act);
+ gtk_widget_set_sensitive (sort_by, act);
+}
+
+static gboolean
+mcv_btn_expose (GtkWidget *w, GdkEventExpose *event, MailConvView *mfv)
+{
+ GdkPixbuf *img = g_object_get_data (w, "pbuf");
+ cairo_t *cr = gdk_cairo_create (w->window);
+ int wid = w->allocation.width;
+ int heig = w->allocation.height;
+ cairo_save (cr);
+ gdk_cairo_set_source_pixbuf (cr, img, event->area.x-4, event->area.y-5);
+ cairo_paint(cr);
+ cairo_restore(cr);
+ cairo_destroy (cr);
+
+ return TRUE;
+}
+
+static void
+mcv_close (GtkButton *w, MailConvView *mfv)
+{
+ g_signal_emit (mfv, signals[VIEW_CLOSE], 0);
+}
+
+GtkWidget *
+mail_conv_view_get_tab_widget(MailConvView *mcv)
+{
+ GdkPixbuf *pbuf = e_icon_factory_get_icon ("gtk-close", E_ICON_SIZE_MENU);
+ GtkWidget *tool, *box, *img;
+ int w=-1, h=-1;
+ GtkWidget *tab_label;
+
+ img = gtk_image_new_from_pixbuf (pbuf);
+ g_object_set_data (img, "pbuf", pbuf);
+ g_signal_connect (img, "expose-event", mcv_btn_expose, mcv);
+
+ tool = gtk_button_new ();
+ gtk_button_set_relief(tool, GTK_RELIEF_NONE);
+ gtk_button_set_focus_on_click (tool, FALSE);
+ gtk_widget_set_tooltip_text (tool, _("Close Tab"));
+ g_signal_connect (tool, "clicked", G_CALLBACK(mcv_close), mcv);
+
+ box = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (box, img, FALSE, FALSE, 0);
+ gtk_container_add (tool, box);
+ gtk_widget_show_all (tool);
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings(tool) , GTK_ICON_SIZE_MENU, &w, &h);
+ gtk_widget_set_size_request (tool, w+2, h+2);
+
+ box = gtk_label_new (_("Message"));
+ tab_label = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (tab_label, box, FALSE, FALSE, 0);
+ gtk_box_pack_start (tab_label, tool, FALSE, FALSE, 0);
+ gtk_widget_show_all (tab_label);
+
+ return tab_label;
+
+}
diff --git a/src/mail-conv-view.h b/src/mail-conv-view.h
index 9ab6670..315fdec 100644
--- a/src/mail-conv-view.h
+++ b/src/mail-conv-view.h
@@ -39,7 +39,9 @@ typedef struct _MailConvViewPrivate MailConvViewPrivate;
typedef struct _MailConvView {
GtkVBox parent;
+ int type;
+ /* Base class */
GtkWidget *header;
GtkWidget *scroller;
GtkWidget *child_box;
@@ -51,9 +53,10 @@ typedef struct _MailConvView {
typedef struct _MailConvViewClass {
GtkVBoxClass parent_class;
+ void (* view_close) (MailConvView *);
} MailConvViewClass;
MailConvView * mail_conv_view_new (void);
void mail_conv_view_set_thread (MailConvView *, CamelFolder *folder, GPtrArray *);
-
+void mail_conv_view_activate (MailConvView *mcv, GtkWidget *tree, GtkWidget *folder_tree, GtkWidget *check_mail, GtkWidget *sort_by, gboolean act);
#endif
diff --git a/src/mail-folder-view.c b/src/mail-folder-view.c
index 6bb773b..6aded2e 100644
--- a/src/mail-folder-view.c
+++ b/src/mail-folder-view.c
@@ -60,6 +60,7 @@ struct _MailFolderViewPrivate {
enum {
MESSAGE_SHOWN,
VIEW_CLOSE,
+ MESSAGE_NEW,
LAST_SIGNAL
};
@@ -157,8 +158,11 @@ mfv_save (MailFolderView *mfv)
const char *uid = mfv_get_selected_uid (mfv->tree, mfv);
double pos;
char *state;
+
+ if (!mfv->priv->folder)
+ return;
- if (uid && *uid && mfv->priv->folder)
+ if (uid && *uid)
camel_object_meta_set (mfv->priv->folder, "anjal:selected_uid", uid);
pos = gtk_adjustment_get_value(gtk_scrolled_window_get_vadjustment (mfv->priv->view_scroller));
@@ -432,7 +436,15 @@ mail_folder_view_class_init (MailFolderViewClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
+ signals[MESSAGE_NEW] =
+ g_signal_new ("message-new",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (MailFolderViewClass , message_new),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
mail_folder_view_parent_class = g_type_class_peek_parent (klass);
object_class->finalize = mail_folder_view_finalize;
@@ -742,6 +754,30 @@ mfv_get_selected_uid (GtkTreeView *tree, MailFolderView *mfv)
return em_tree_store_get_uid_from_iter (mfv->model, &iter);
}
+static gboolean
+mfv_button_clicked (GtkWidget *w, GdkEventButton *event, MailFolderView *mfv)
+{
+ if (event->button == 2) {
+ MailConvView *mcv = NULL;
+ GtkTreePath *path=NULL;
+ GtkTreeIter iter;
+ GPtrArray *uids;
+
+ g_signal_emit (mfv, signals[MESSAGE_NEW], 0, &mcv);
+ if (!mcv)
+ return FALSE;
+ if (gtk_tree_view_get_path_at_pos (mfv->tree, event->x, event->y, &path, NULL, NULL, NULL)) {
+ if (gtk_tree_model_get_iter (mfv->model, &iter, path)) {
+ uids = em_tree_store_get_child_sorted_tree (mfv->model, &iter);
+ mail_conv_view_set_thread (mcv, mfv->priv->folder, uids);
+ }
+ gtk_tree_path_free(path);
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
static void
mfv_message_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, MailFolderView *shell)
{
@@ -858,6 +894,7 @@ mail_folder_view_construct (MailFolderView *shell)
gtk_tree_view_set_show_expanders (shell->tree, shell->priv->show_thread);
g_signal_connect (shell->tree, "row-activated", G_CALLBACK (mfv_message_activated), shell);
+ g_signal_connect (shell->tree, "button-press-event", G_CALLBACK(mfv_button_clicked), shell);
/* Create the single column */
column = gtk_tree_view_column_new ();
@@ -1114,6 +1151,7 @@ mail_folder_view_activate (MailFolderView *mfv, GtkWidget *tree, GtkWidget *fold
{
if (!folder_tree || !check_mail || !sort_by)
return;
+ gtk_widget_show(folder_tree);
gtk_widget_set_sensitive (folder_tree, act);
gtk_widget_set_sensitive (check_mail, act);
gtk_widget_set_sensitive (sort_by, act);
@@ -1132,5 +1170,5 @@ mail_folder_view_check_mail (MailFolderView *mfv)
void
mail_folder_view_save (MailFolderView *mfv)
{
- mfv_close(NULL, mfv);
+ mfv_save(mfv);
}
diff --git a/src/mail-folder-view.h b/src/mail-folder-view.h
index b00be36..987cdce 100644
--- a/src/mail-folder-view.h
+++ b/src/mail-folder-view.h
@@ -59,6 +59,7 @@ typedef struct _MailFolderViewClass {
void (* message_shown) (MailConvView *);
void (* view_close) (MailConvView *);
+ void (* message_new) (MailConvView *, gpointer);
} MailFolderViewClass;
MailFolderView * mail_folder_view_new (void);
diff --git a/src/mail-view.c b/src/mail-view.c
index 40e8082..c99ef13 100644
--- a/src/mail-view.c
+++ b/src/mail-view.c
@@ -28,6 +28,7 @@
#include "mail-view.h"
#include "mail-folder-view.h"
#include "mail-composer-view.h"
+#include "mail-conv-view.h"
#include "mail/em-folder-tree.h"
#include <e-util/e-icon-factory.h>
@@ -102,6 +103,9 @@ mv_switch (GtkNotebook *notebook,GtkNotebookPage *page, guint page_num, gpoi
mail_composer_view_activate (child, shell->folder_tree, shell->check_mail, shell->sort_by, TRUE);
else if (child->type == MAIL_VIEW_FOLDER)
mail_folder_view_activate (child, shell->tree, shell->folder_tree, shell->check_mail, shell->sort_by, TRUE);
+ else if (child->type == MAIL_VIEW_MESSAGE)
+ mail_conv_view_activate (child, shell->tree, shell->folder_tree, shell->check_mail, shell->sort_by, FALSE);
+
}
}
@@ -193,7 +197,7 @@ list_data_pos (GList *list, gpointer data)
}
static void
-mv_close_mfv (MailFolderView *mfv, MailView *mv)
+mv_close_mcv (MailFolderView *mfv, MailView *mv)
{
int n = list_data_pos (mv->priv->children, mfv);
int pos = gtk_notebook_get_current_page (mv);
@@ -209,6 +213,13 @@ mv_close_mfv (MailFolderView *mfv, MailView *mv)
}
static void
+mv_message_new (MailFolderView *mfv, gpointer data, MailView *mv)
+{
+ *(MailConvView **)data = (MailConvView *)mail_view_add_page (mv, MAIL_VIEW_MESSAGE);
+ return;
+}
+
+static MailViewChild *
mail_view_add_folder (MailView *mv)
{
MailFolderView *mfv = mail_folder_view_new ();
@@ -217,75 +228,83 @@ mail_view_add_folder (MailView *mv)
mv->priv->current_view = mfv;
mv->priv->children = g_list_append (mv->priv->children, mfv);
position = gtk_notebook_append_page (mv, mfv, mfv->tab_label);
- g_signal_connect (mfv, "view-close", G_CALLBACK(mv_close_mfv), mv);
+ g_signal_connect (mfv, "view-close", G_CALLBACK(mv_close_mcv), mv);
gtk_notebook_set_tab_reorderable (mv, mfv, TRUE);
gtk_notebook_set_current_page (mv, position);
gtk_notebook_set_tab_label_packing (mv, mfv, FALSE, FALSE, 0);
g_signal_connect (mfv, "message-shown", G_CALLBACK(mv_message_shown), mv);
+ g_signal_connect (mfv, "message-new", G_CALLBACK(mv_message_new), mv);
+
mail_folder_view_activate (mfv, mv->tree, mv->folder_tree, mv->check_mail, mv->sort_by, TRUE);
+
+ return mfv;
}
-static void
-mail_view_close_mcv (MailComposerView *mfv, MailView *mv)
+static MailViewChild *
+mail_view_add_composer (MailView *mv)
{
- int n = list_data_pos (mv->priv->children, mfv);
- int pos = gtk_notebook_get_current_page (mv);
+ MailComposerView *mcv = mail_composer_view_new ();
+ gint position = 0;
+
+ mv->priv->current_view = mcv;
+ mv->priv->children = g_list_append (mv->priv->children, mcv);
- if (g_list_length(mv->priv->children) == 1)
- return;
- g_signal_handlers_block_by_func(mv, mv_switch, mv);
- gtk_notebook_remove_page (mv, n);
- g_signal_handlers_unblock_by_func(mv, mv_switch, mv);
- if (pos == g_list_length(mv->priv->children) -1)
- gtk_notebook_set_current_page (mv, pos -1);
- mv->priv->children = g_list_remove (mv->priv->children, mfv);
-}
+ position = gtk_notebook_append_page (mv, mcv, mcv->tab_label);
+ gtk_notebook_set_tab_reorderable (mv, mcv, TRUE);
+ gtk_notebook_set_current_page (mv, position);
+ gtk_notebook_set_tab_label_packing (mv, mcv, FALSE, FALSE, 0);
+ mail_composer_view_activate (mcv, mv->folder_tree, mv->check_mail, mv->sort_by, FALSE);
-static void
-BAD_mail_view_close_mcv (MailFolderView *mcv, MailView *mv)
-{
- gint position = -2;
- position = gtk_notebook_page_num (mv, mcv);
- /* gtk_notebook_remove_page (mv, position); */
+ g_signal_connect (mcv, "view-close", G_CALLBACK(mv_close_mcv), mv);
- /* mv->priv->children = g_list_remove (mv->priv->children, mcv); */
+ return mcv;
}
-static void
-mail_view_add_composer (MailView *mv)
+static MailViewChild *
+mail_view_add_message (MailView *mv)
{
- MailComposerView *mcv = mail_composer_view_new ();
+ MailConvView *mcv = mail_conv_view_new ();
gint position = 0;
+ gtk_widget_show (mcv);
+ mcv->type = MAIL_VIEW_MESSAGE;
mv->priv->current_view = mcv;
mv->priv->children = g_list_append (mv->priv->children, mcv);
- position = gtk_notebook_append_page (mv, mcv, mcv->tab_label);
+ position = gtk_notebook_append_page (mv, mcv, mail_conv_view_get_tab_widget(mcv));
gtk_notebook_set_tab_reorderable (mv, mcv, TRUE);
gtk_notebook_set_current_page (mv, position);
gtk_notebook_set_tab_label_packing (mv, mcv, FALSE, FALSE, 0);
- mail_composer_view_activate (mcv, mv->folder_tree, mv->check_mail, mv->sort_by, FALSE);
+ mail_conv_view_activate (mcv, mv->tree, mv->folder_tree, mv->check_mail, mv->sort_by, FALSE);
+
+ g_signal_connect (mcv, "view-close", G_CALLBACK(mv_close_mcv), mv);
- g_signal_connect (mcv, "view-close", G_CALLBACK(mail_view_close_mcv), mv);
+ return mcv;
}
-void
+MailViewChild *
mail_view_add_page (MailView *mv, guint16 type)
{
+ MailViewChild *child = NULL;
+
g_signal_handlers_block_by_func(mv, mv_switch, mv);
switch (type){
case MAIL_VIEW_FOLDER:
- mail_view_add_folder (mv);
+ child = mail_view_add_folder (mv);
break;
case MAIL_VIEW_COMPOSER:
- mail_view_add_composer (mv);
+ child = mail_view_add_composer (mv);
+ break;
+ case MAIL_VIEW_MESSAGE:
+ child = mail_view_add_message (mv);
break;
}
gtk_notebook_reorder_child (mv, mv->priv->new, -1);
gtk_notebook_set_current_page (mv, g_list_length (mv->priv->children)-1);
g_signal_handlers_unblock_by_func(mv, mv_switch, mv);
+ return child;
}
void
@@ -392,7 +411,7 @@ mail_view_save (MailView *mv)
while (child) {
cview = (MailViewChild *)child->data;
- if (cview->type = MAIL_VIEW_FOLDER) {
+ if (cview->type == MAIL_VIEW_FOLDER) {
mail_folder_view_save (cview);
}
child = child->next;
diff --git a/src/mail-view.h b/src/mail-view.h
index 68dd17f..4420118 100644
--- a/src/mail-view.h
+++ b/src/mail-view.h
@@ -34,7 +34,8 @@
enum {
MAIL_VIEW_FOLDER=1,
- MAIL_VIEW_COMPOSER
+ MAIL_VIEW_COMPOSER,
+ MAIL_VIEW_MESSAGE
};
typedef struct _MailViewPrivate MailViewPrivate;
@@ -71,4 +72,5 @@ void mail_view_check_mail(MailView *mv);
void mail_view_set_folder_tree_widget (MailView *mv, GtkWidget *tree);
void mail_view_set_folder_tree (MailView *mv, GtkWidget *tree);
void mail_view_save (MailView *mv);
+MailViewChild * mail_view_add_page (MailView *mv, guint16 type);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]