[anjal] Make Delete/Junk from message view work.



commit e0d52638e378fc8138dc379cc380b95c69bd9d09
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Sun Mar 22 17:05:40 2009 +0530

    Make Delete/Junk from message view work.
    Make way to shrink the message conv  view as and when you delete mails
    Add some coolness to status and make it possible to mark read/unread
    from message view.
---
 src/mail-conv-view.c    |   54 ++++++++++++++++++++++++++++++++++++++++
 src/mail-message-view.c |   62 +++++++++++++++++++++++++++++++++++++++++++++-
 src/mail-message-view.h |    1 +
 3 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/src/mail-conv-view.c b/src/mail-conv-view.c
index d7411a5..44ff37b 100644
--- a/src/mail-conv-view.c
+++ b/src/mail-conv-view.c
@@ -200,6 +200,59 @@ mcv_message_selected (MailMessageView *mmv, MailConvView *mcv)
 		g_warning ("Unable to find the selected mail in conversation\n");
 }
 
+static void
+mcv_free_node (MailConvView *mcv, MailMessageView *mmv, GList *node)
+{
+	 if (mcv->priv->selected_child == node) {
+		  GList *tmp = mcv->priv->selected_child;
+
+		  if (tmp->next)
+			   mcv->priv->selected_child = tmp->next;
+		  else if (tmp->prev)
+			   mcv->priv->selected_child = tmp->prev;
+		  else
+			   mcv->priv->selected_child = NULL; //Free mcv
+
+		  if (mcv->priv->selected_child)
+			   gtk_widget_grab_focus (mcv->priv->selected_child->data);
+		  
+	 }
+	 gtk_widget_destroy (mmv);
+	 g_list_free_1 (node);
+}
+
+static void
+mcv_message_removed (MailMessageView *mmv, MailConvView *mcv)
+{
+	GtkWidget *focus = mail_message_view_get_focus_widget (mmv);
+	GList *tmp = mcv->priv->child, *prev;
+
+	prev = tmp;
+	if (tmp->data == focus) {
+		 /* remove first node; */
+		 mcv->priv->child = mcv->priv->child->next;
+		 if (mcv->priv->child)
+			  mcv->priv->child->prev = NULL;
+		 /* Free view */
+		 mcv_free_node (mcv, mmv, tmp);
+		 return;
+	}
+	tmp = tmp->next;
+	while (tmp) {
+		 if (tmp->data == focus) {
+			  prev->next = tmp->next;
+			  if (tmp->next)
+				   tmp->next->prev = prev;
+			  mcv_free_node (mcv, mmv, tmp);
+			  return;
+		 }
+		tmp = tmp->next;
+	}
+
+	if (!tmp)
+		g_warning ("Unable to find the deleted  mail in conversation\n");
+}
+
 void
 mail_conv_view_set_thread (MailConvView *mcv, CamelFolder *folder, GPtrArray *array)
 {
@@ -231,6 +284,7 @@ mail_conv_view_set_thread (MailConvView *mcv, CamelFolder *folder, GPtrArray *ar
 
 		mail_message_view_set_message (child, folder, array->pdata[i]);
 		g_signal_connect (child, "message-selected", G_CALLBACK(mcv_message_selected), mcv);
+		g_signal_connect (child, "message-removed", G_CALLBACK(mcv_message_removed), mcv);
 		focus = g_list_prepend (focus, mail_message_view_get_focus_widget(child));
 	}
 
diff --git a/src/mail-message-view.c b/src/mail-message-view.c
index 0556ccb..38303ce 100644
--- a/src/mail-message-view.c
+++ b/src/mail-message-view.c
@@ -48,12 +48,14 @@ struct  _MailMessageViewPrivate {
 	GtkWidget *header_row;
 	const char *active_color;
 	GtkWidget *spinner;
+	GtkWidget *unread_image;
 };
 
 G_DEFINE_TYPE (MailMessageView, mail_message_view, GTK_TYPE_VBOX)
 
 enum {
 	MESSAGE_SELECTED,
+	MESSAGE_REMOVED,
 	LAST_SIGNAL
 };
 
@@ -62,6 +64,8 @@ static guint signals[LAST_SIGNAL] = { 0 };
 static const char *norm_color = "#d3d7cf";
 static const char *sel_color = "#729fcf";
 
+static void unread_toggled (GtkWidget *w, GdkEventButton *event, MailMessageView *mmv);
+
 static void
 mail_message_view_init (MailMessageView  *shell)
 {
@@ -100,7 +104,15 @@ mail_message_view_class_init (MailMessageViewClass *klass)
 			      G_STRUCT_OFFSET (MailMessageViewClass , message_selected),
 			      NULL, NULL,
 			      g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);	
+			      G_TYPE_NONE, 0);
+	signals[MESSAGE_REMOVED] =
+		g_signal_new ("message-removed",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_FIRST,
+			      G_STRUCT_OFFSET (MailMessageViewClass , message_removed),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			     G_TYPE_NONE, 0);
 }
 
 static void
@@ -338,7 +350,7 @@ mark_mail_read  (GtkWidget *w, GdkEventExpose *event, MailMessageView *mmv)
 {
 	 if ((mmv->priv->info->flags & CAMEL_MESSAGE_SEEN) == 0)
 		  mmv_set_flags (mmv, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
-	 
+	 gtk_image_set_from_pixbuf (mmv->priv->unread_image, e_icon_factory_get_icon ("mail-read", E_ICON_SIZE_MENU));
 	 g_signal_handlers_disconnect_by_func(w, mark_mail_read, mmv);
 	 return FALSE;
 }
@@ -433,6 +445,33 @@ mail_message_view_create_webview (MailMessageView *mmv, GtkWidget *box)
 
 #define EXPOSE(widget,mmv) 	g_signal_connect (widget, "expose-event", G_CALLBACK (mmv_sh_color_expose), mmv);
 
+static void
+unread_toggled (GtkWidget *w, GdkEventButton *event, MailMessageView *mmv)
+{
+	 if (camel_message_info_flags(mmv->priv->info) & CAMEL_MESSAGE_SEEN) {
+		  mmv_set_flags(mmv, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED, 0);
+		  gtk_image_set_from_pixbuf (mmv->priv->unread_image, e_icon_factory_get_icon ("mail-unread", E_ICON_SIZE_MENU));
+	 } else {
+		  mmv_set_flags(mmv, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN);
+		  gtk_image_set_from_pixbuf (mmv->priv->unread_image, e_icon_factory_get_icon ("mail-read", E_ICON_SIZE_MENU));
+	 }
+//	 mmv_invalidate_row (mmv->priv->header_row);
+}
+
+static void
+junk_clicked (GtkWidget *w, MailMessageView *mmv)
+{
+	 mmv_set_flags(mmv, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_JUNK|CAMEL_MESSAGE_NOTJUNK|CAMEL_MESSAGE_JUNK_LEARN,
+				   CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_JUNK|CAMEL_MESSAGE_JUNK_LEARN);
+}
+
+static void
+delete_clicked (GtkWidget *w, MailMessageView *mmv)
+{
+	 mmv_set_flags(mmv, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_SEEN|CAMEL_MESSAGE_DELETED );
+	 g_signal_emit (mmv, signals[MESSAGE_REMOVED], 0);
+}
+
 void
 mail_message_view_set_message (MailMessageView *mmview, CamelFolder *folder, const char *uid)
 {
@@ -490,6 +529,21 @@ mail_message_view_set_message (MailMessageView *mmview, CamelFolder *folder, con
 	mmview->priv->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
 	gtk_widget_show (mmview->priv->arrow);
 	gtk_box_pack_start (header_row, mmview->priv->arrow, FALSE, FALSE, 2);
+
+	tmp = gtk_event_box_new ();
+	EXPOSE(tmp, mmview);
+	mmview->priv->unread_image = gtk_image_new ();
+	EXPOSE(mmview->priv->unread_image, mmview);
+	if (camel_message_info_flags(info) & CAMEL_MESSAGE_SEEN)
+		 gtk_image_set_from_pixbuf (mmview->priv->unread_image, e_icon_factory_get_icon ("mail-read", E_ICON_SIZE_MENU));
+	else
+		 gtk_image_set_from_pixbuf (mmview->priv->unread_image, e_icon_factory_get_icon ("mail-unread", E_ICON_SIZE_MENU));
+	gtk_widget_show (mmview->priv->unread_image);
+	gtk_widget_show (tmp);
+	gtk_container_add (tmp, mmview->priv->unread_image);
+	gtk_box_pack_start (header_row, tmp, FALSE, FALSE, 2);
+	g_signal_connect (tmp, "button-press-event", G_CALLBACK(unread_toggled), mmview);
+	
 	str = camel_message_info_from(info);
 	strv = g_strsplit (str, "<", 2);
 	str = g_strdup_printf("<b>%s</b> - %s", *strv, camel_message_info_subject(info));
@@ -615,12 +669,16 @@ mail_message_view_set_message (MailMessageView *mmview, CamelFolder *folder, con
 	vbox = gtk_vbox_new (FALSE, 2);
 	gtk_box_pack_end (mmview->main_header, vbox, FALSE, FALSE, 0);
 	tmp = gtk_button_new ();
+	g_object_set (tmp, "focus-on-click", FALSE, NULL);
+	g_signal_connect (tmp, "clicked", G_CALLBACK(delete_clicked), mmview);
 	gtk_button_set_relief(tmp, GTK_RELIEF_NONE);
 	img = e_icon_factory_get_icon ("stock_delete", E_ICON_SIZE_BUTTON);
 	gtk_button_set_label (tmp, _("Delete"));
 	gtk_button_set_image (tmp, gtk_image_new_from_pixbuf(img));
 	gtk_box_pack_start (vbox, tmp, FALSE, FALSE, 0);
 	tmp = gtk_button_new  ();
+	g_object_set (tmp, "focus-on-click", FALSE, NULL);
+	g_signal_connect (tmp, "clicked", G_CALLBACK(junk_clicked), mmview);
 	gtk_button_set_relief(tmp, GTK_RELIEF_NONE);
 	img = e_icon_factory_get_icon ("mail-mark-junk", E_ICON_SIZE_BUTTON);
 	gtk_button_set_label (tmp, _("Junk"));
diff --git a/src/mail-message-view.h b/src/mail-message-view.h
index 871540c..de030ef 100644
--- a/src/mail-message-view.h
+++ b/src/mail-message-view.h
@@ -59,6 +59,7 @@ typedef struct _MailMessageViewClass {
 	GtkVBoxClass parent_class;
 
 	void (*message_selected) (MailMessageView *);
+	 void (*message_removed) (MailMessageView *);
 } MailMessageViewClass;
 
 MailMessageView * mail_message_view_new (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]