[Commits] about.c 1.4.2.83 1.4.2.84

wwp at claws-mail.org wwp at claws-mail.org
Sat Jun 2 11:06:30 CEST 2012


Update of /home/claws-mail/claws/src/gtk
In directory srv:/tmp/cvs-serv32044/src/gtk

Modified Files:
      Tag: gtk2
	about.c 
Log Message:
2012-06-02 [wwp]	3.8.0cvs52

	* doc/man/claws-mail.1
	* src/main.c
	* src/main.h
	* src/inc.c
	* src/procmsg.c
	* src/gtk/about.c
		Introduce a new feature: basic session statistics (from the about dialog
		or the command-line).

Index: about.c
===================================================================
RCS file: /home/claws-mail/claws/src/gtk/about.c,v
retrieving revision 1.4.2.83
retrieving revision 1.4.2.84
diff -u -d -r1.4.2.83 -r1.4.2.84
--- about.c	27 May 2012 17:31:06 -0000	1.4.2.83
+++ about.c	2 Jun 2012 09:06:27 -0000	1.4.2.84
@@ -42,6 +42,10 @@
 #include "codeconv.h"
 #include "menu.h"
 #include "textview.h"
+#include "main.h"
+
+extern SessionStats session_stats;
+static GtkTextBuffer *stats_text_buffer;
 
 static GtkWidget *window;
 static gchar* uri_hover = NULL;
@@ -64,6 +68,7 @@
 static void about_size_allocate_cb(GtkWidget *widget,
 				   	GtkAllocation *allocation);
 static void about_textview_uri_update(GtkWidget *textview, gint x, gint y);
+static void about_update_stats(void);
 
 static GtkWidget *link_popupmenu;
 
@@ -72,8 +77,10 @@
 {
 	if (!window)
 		about_create();
-	else 
+	else {
+		about_update_stats();
 		gtk_window_present(GTK_WINDOW(window));
+	}
 	
 }
 
@@ -219,7 +226,7 @@
 	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
 	gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
 
-	/* init formatting tag: indentation  for list items */
+	/* init formatting tag: indentation for list items */
 	gtk_text_buffer_create_tag(buffer, "indented-list-item",
 				"indent", 8,
 				NULL);
@@ -633,6 +640,101 @@
 	return scrolledwin;
 }
 
+static GtkWidget *about_create_child_page_session_stats(void)
+{
+	GtkWidget *scrolledwin;
+	GtkWidget *text;
+	GtkTextIter iter;
+
+	scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
+			GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
+			GTK_SHADOW_IN);
+	text = gtk_text_view_new();
+	gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
+	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
+	gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
+	gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
+	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
+	gtk_container_add(GTK_CONTAINER(scrolledwin), text);
+
+	stats_text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
+
+	gtk_text_buffer_get_iter_at_offset(stats_text_buffer, &iter, 0);
+	gtk_text_buffer_create_tag(stats_text_buffer, "indented-list-item",
+				"indent", 8,
+				NULL);
+	gtk_text_buffer_create_tag(stats_text_buffer, "underlined-list-title",
+				"underline", PANGO_UNDERLINE_SINGLE,
+				NULL);
+	gtk_text_buffer_create_tag(stats_text_buffer, "bold", "weight", PANGO_WEIGHT_BOLD,
+				   NULL);
+
+	about_update_stats();
+
+	return scrolledwin;
+}
+
+static void about_update_stats(void)
+{
+	if (stats_text_buffer != NULL)
+	{
+		GtkTextIter start, end, iter;
+		gchar buf[1024];
+
+		gtk_text_buffer_get_start_iter(stats_text_buffer, &start);
+		gtk_text_buffer_get_end_iter(stats_text_buffer, &end);
+		gtk_text_buffer_delete(stats_text_buffer, &start, &end);
+
+		gtk_text_buffer_get_iter_at_offset(stats_text_buffer, &iter, 0);
+
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter,
+				(_("Session statistics\n")), -1,
+				"underlined-list-title", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("Started: %s\n"),
+					ctime(&session_stats.time_started));
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", NULL);
+
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter,
+				(_("Incoming traffic\n")), -1,
+				"underlined-list-title", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("Received messages: %d\n"),
+					session_stats.received);
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", "bold", NULL);
+
+		gtk_text_buffer_insert(stats_text_buffer, &iter, "\n", 1);
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter,
+				(_("Outgoing traffic\n")), -1,
+				"underlined-list-title", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("New/redirected messages: %d\n"),
+					session_stats.sent);
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("Replied messages: %d\n"),
+					session_stats.replied);
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("Forwarded messages: %d\n"),
+					session_stats.forwarded);
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", NULL);
+
+		g_snprintf(buf, sizeof(buf), _("Total outgoing messages: %d\n"),
+					(session_stats.sent + session_stats.replied +
+					 session_stats.forwarded));
+		gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1,
+				"indented-list-item", "bold", NULL);
+	} 
+}
+
 static void about_create(void)
 {
 	GtkWidget *vbox1;
@@ -648,6 +750,8 @@
 	GtkWidget *close_button;
 	static GdkGeometry geometry;
 
+	stats_text_buffer = NULL;
+
 	window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "about");
 	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_window_set_title(GTK_WINDOW(window), _("About Claws Mail"));
@@ -751,6 +855,12 @@
 				gtk_label_new_with_mnemonic(_("_Release Notes")));
 	}
 
+	if ((scrolledwin = about_create_child_page_session_stats()) != NULL) {
+		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
+				scrolledwin,
+				gtk_label_new_with_mnemonic(_("_Statistics")));
+	}
+
 	gtk_box_pack_start(GTK_BOX(vbox1), notebook, TRUE, TRUE, 0);
 
 	gtkut_stock_button_set_create(&confirm_area, &close_button, GTK_STOCK_CLOSE,



More information about the Commits mailing list