2012-06-02 [wwp] 3.8.0cvs52
authorTristan Chabredier <wwp@claws-mail.org>
Sat, 2 Jun 2012 09:06:29 +0000 (09:06 +0000)
committerTristan Chabredier <wwp@claws-mail.org>
Sat, 2 Jun 2012 09:06:29 +0000 (09:06 +0000)
* 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).

ChangeLog
PATCHSETS
configure.ac
doc/man/claws-mail.1
src/gtk/about.c
src/inc.c
src/main.c
src/main.h
src/procmsg.c

index f8f166e..5084da0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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).
+
 2012-06-02 [wwp]       3.8.0cvs51
 
        * src/compose.c
index 786502e..272c0a4 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.9.2.51 -r 1.9.2.52 src/common/ssl.c;  ) > 3.8.0cvs49.patchset
 ( cvs diff -u -r 1.382.2.601 -r 1.382.2.602 src/compose.c;  cvs diff -u -r 1.274.2.345 -r 1.274.2.346 src/mainwindow.c;  cvs diff -u -r 1.94.2.232 -r 1.94.2.233 src/messageview.c;  ) > 3.8.0cvs50.patchset
 ( cvs diff -u -r 1.382.2.602 -r 1.382.2.603 src/compose.c;  ) > 3.8.0cvs51.patchset
+( cvs diff -u -r 1.1.2.9 -r 1.1.2.10 doc/man/claws-mail.1;  cvs diff -u -r 1.115.2.249 -r 1.115.2.250 src/main.c;  cvs diff -u -r 1.7.2.20 -r 1.7.2.21 src/main.h;  cvs diff -u -r 1.149.2.106 -r 1.149.2.107 src/inc.c;  cvs diff -u -r 1.150.2.123 -r 1.150.2.124 src/procmsg.c;  cvs diff -u -r 1.4.2.83 -r 1.4.2.84 src/gtk/about.c;  ) > 3.8.0cvs52.patchset
index e449e9d..84f1d05 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=8
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=51
+EXTRA_VERSION=52
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 0514f2c..7254aa2 100644 (file)
@@ -113,6 +113,10 @@ This list is not complete.
 .br 
 \fB \-\-status\-full\fR
 .br 
+\fB \-\-statistics\fR
+.br 
+\fB \-\-reset-statistics\fR
+.br 
 \fB \-\-select [#mh/mailbox/]folder[/msg|/msgid]\fR
 .br 
 \fB \-\-online\fR
@@ -283,6 +287,14 @@ show the total number of messages per folder
 .br 
 [new][unread][unread answers to marked][total]
 .TP 
+\fB\-\-statistics\fR
+.br 
+show session statistics
+.TP 
+\fB\-\-reset-statistics\fR
+.br 
+reset session statistics
+.TP 
 \fB\-\-select [#mh/mailbox/]folder[/msg|/msgid]\fR
 on startup, jumps to the specified folder/message
 .TP 
index 36e385d..d95f50a 100644 (file)
 #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 gboolean about_textview_leave_notify(GtkWidget *widget,
 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 @@ void about_show(void)
 {
        if (!window)
                about_create();
-       else 
+       else {
+               about_update_stats();
                gtk_window_present(GTK_WINDOW(window));
+       }
        
 }
 
@@ -219,7 +226,7 @@ static GtkWidget *about_create_child_page_authors(void)
        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 @@ static GtkWidget *about_create_child_page_release_notes(void)
        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 @@ static void about_create(void)
        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 @@ static void about_create(void)
                                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,
index 82d69c8..86fabbc 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -78,6 +78,8 @@ static gboolean maemo_warned_offline = FALSE;
 #endif
 #endif
 
+extern SessionStats session_stats;
+
 static GList *inc_dialog_list = NULL;
 
 guint inc_lock_count = 0;
@@ -88,6 +90,7 @@ static GdkPixbuf *okpix;
 
 #define MSGBUFSIZE     8192
 
+static void inc_update_stats(gint new_msgs);
 static void inc_finished               (MainWindow             *mainwin,
                                         gboolean                new_messages,
                                         gboolean                autocheck);
@@ -153,7 +156,15 @@ static gint inc_autocheck_func                     (gpointer        data);
 
 static void inc_notify_cmd             (gint new_msgs, 
                                         gboolean notify);
-       
+
+static void inc_update_stats(gint new_msgs)
+{
+       /* update session statistics */
+       session_stats.received += new_msgs;
+fprintf(stdout, "++ STATS ++ INC %d %d\n", session_stats.received, new_msgs);
+fflush(stdout);
+}
+
 /**
  * inc_finished:
  * @mainwin: Main window.
@@ -214,6 +225,7 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
                        new_msgs += account_new_msgs;
        }
 
+       inc_update_stats(new_msgs);
        inc_finished(mainwin, new_msgs > 0, FALSE);
        main_window_unlock(mainwin);
        inc_notify_cmd(new_msgs, notify);
@@ -307,6 +319,7 @@ gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account)
 
        new_msgs = inc_account_mail_real(mainwin, account);
 
+       inc_update_stats(new_msgs);
        inc_finished(mainwin, new_msgs > 0, FALSE);
        main_window_unlock(mainwin);
        inc_autocheck_timer_set();
@@ -335,6 +348,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
 
        list = account_get_list();
        if (!list) {
+               inc_update_stats(new_msgs);
                inc_finished(mainwin, new_msgs > 0, autocheck);
                main_window_unlock(mainwin);
                inc_notify_cmd(new_msgs, notify);
@@ -390,6 +404,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
                new_msgs += inc_start(inc_dialog);
        }
 
+       inc_update_stats(new_msgs);
        inc_finished(mainwin, new_msgs > 0, autocheck);
        main_window_unlock(mainwin);
        inc_notify_cmd(new_msgs, notify);
@@ -1407,7 +1422,6 @@ osso_context_t *get_osso_context(void);
 
 static void inc_notify_cmd(gint new_msgs, gboolean notify)
 {
-
 #ifndef MAEMO
        gchar *buf, *numpos, *ret_str;
        gssize by_read = 0, by_written = 0;
index 6011838..df8a6d4 100644 (file)
@@ -207,6 +207,8 @@ static struct RemoteCmd {
        gboolean search_recursive;
        gboolean status;
        gboolean status_full;
+       gboolean statistics;
+       gboolean reset_statistics;
        GPtrArray *status_folders;
        GPtrArray *status_full_folders;
        gboolean send;
@@ -219,6 +221,10 @@ static struct RemoteCmd {
        const gchar *target;
 } cmd;
 
+SessionStats session_stats;
+
+static void reset_statistics(void);
+               
 static void parse_cmd_opt(int argc, char *argv[]);
 
 static gint prohibit_duplicate_launch  (void);
@@ -1031,6 +1037,16 @@ static void install_dbus_status_handler(void)
 }
 #endif
 
+static void reset_statistics(void)
+{
+       /* (re-)initialize session statistics */
+       session_stats.received = 0;
+       session_stats.sent = 0;
+       session_stats.replied = 0;
+       session_stats.forwarded = 0;
+       session_stats.time_started = time(NULL);
+}
+               
 int main(int argc, char *argv[])
 {
 #ifdef MAEMO
@@ -1106,7 +1122,8 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       if (cmd.status || cmd.status_full || cmd.search) {
+       if (cmd.status || cmd.status_full || cmd.search ||
+               cmd.statistics || cmd.reset_statistics) {
                puts("0 Claws Mail not running.");
                lock_socket_remove();
                return 0;
@@ -1117,6 +1134,8 @@ int main(int argc, char *argv[])
        if (!g_thread_supported())
                g_thread_init(NULL);
 
+       reset_statistics();
+       
        gtk_set_locale();
        gtk_init(&argc, &argv);
 
@@ -2000,6 +2019,10 @@ static void parse_cmd_opt(int argc, char *argv[])
                        cmd.online_mode = ONLINE_MODE_ONLINE;
                } else if (!strncmp(argv[i], "--offline", 9)) {
                        cmd.online_mode = ONLINE_MODE_OFFLINE;
+               } else if (!strncmp(argv[i], "--statistics", 12)) {
+                       cmd.statistics = TRUE;
+               } else if (!strncmp(argv[i], "--reset-statistics", 18)) {
+                       cmd.reset_statistics = TRUE;
                } else if (!strncmp(argv[i], "--help", 6) ||
                           !strncmp(argv[i], "-h", 2)) {
                        gchar *base = g_path_get_basename(argv[0]);
@@ -2028,6 +2051,8 @@ static void parse_cmd_opt(int argc, char *argv[])
                        g_print("%s\n", _("  --status [folder]...   show the total number of messages"));
                        g_print("%s\n", _("  --status-full [folder]...\n"
                                          "                         show the status of each folder"));
+                       g_print("%s\n", _("  --statistics           show session statistics"));
+                       g_print("%s\n", _("  --reset-statistics     reset session statistics"));
                        g_print("%s\n", _("  --select folder[/msg]  jumps to the specified folder/message\n" 
                                          "                         folder is a folder id like 'folder/sub_folder'"));
                        g_print("%s\n", _("  --online               switch to online mode"));
@@ -2373,6 +2398,16 @@ static gint prohibit_duplicate_launch(void)
                }
        } else if (cmd.exit) {
                fd_write_all(uxsock, "exit\n", 5);
+       } else if (cmd.statistics) {
+               gchar buf[BUFSIZ];
+               fd_write(uxsock, "statistics\n", 11);
+               for (;;) {
+                       fd_gets(uxsock, buf, sizeof(buf));
+                       if (!strncmp(buf, ".\n", 2)) break;
+                       fputs(buf, stdout);
+               }
+       } else if (cmd.reset_statistics) {
+               fd_write(uxsock, "reset_statistics\n", 17);
        } else if (cmd.target) {
                gchar *str = g_strdup_printf("select %s\n", cmd.target);
                fd_write_all(uxsock, str, strlen(str));
@@ -2532,6 +2567,48 @@ static void lock_socket_input_cb(gpointer data,
                fd_write_all(sock, ".\n", 2);
                g_free(status);
                if (folders) g_ptr_array_free(folders, TRUE);
+       } else if (!strncmp(buf, "statistics", 10)) {
+               gchar tmp[BUFSIZ];
+
+               g_snprintf(tmp, sizeof(tmp), _("Session statistics\n"));
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Started: %s\n"),
+                               ctime(&session_stats.time_started));
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Incoming traffic\n"));
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Received messages: %d\n"),
+                               session_stats.received);
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               fd_write_all(sock, "\n", 1);
+
+               g_snprintf(tmp, sizeof(tmp), _("Outgoing traffic\n"));
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("New/redirected messages: %d\n"),
+                               session_stats.sent);
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Replied messages: %d\n"),
+                               session_stats.replied);
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Forwarded messages: %d\n"),
+                               session_stats.forwarded);
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               g_snprintf(tmp, sizeof(tmp), _("Total outgoing messages: %d\n"),
+                               (session_stats.sent + session_stats.replied +
+                                session_stats.forwarded));
+               fd_write_all(sock, tmp, strlen(tmp));
+
+               fd_write_all(sock, ".\n", 2);
+       } else if (!strncmp(buf, "reset_statistics", 16)) {
+               reset_statistics();
        } else if (!strncmp(buf, "select ", 7)) {
                const gchar *target = buf+7;
                mainwindow_jump_to(target, TRUE);
index 9ad9ed1..8b2d1bd 100644 (file)
@@ -30,6 +30,7 @@
 #include <hildon-widgets/hildon-window.h>
 #endif
 #endif
+#include <sys/time.h>
 
 extern gchar *prog_version;
 extern gboolean debug_mode;
@@ -38,6 +39,17 @@ extern gboolean debug_mode;
 extern HildonProgram *hildon_program;
 #endif
 
+typedef struct _SessionStats SessionStats;
+
+struct _SessionStats
+{
+       gint received;
+       gint sent;
+       gint replied;
+       gint forwarded;
+       time_t time_started;
+};
+
 void app_will_exit     (GtkWidget *widget, gpointer data);
 gboolean clean_quit    (gpointer data);
 gboolean claws_is_exiting(void);
index 8b92f95..e0c4862 100644 (file)
@@ -49,6 +49,8 @@
 #include "timing.h"
 #include "inc.h"
 
+extern SessionStats session_stats;
+
 static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
                                            FolderItem *queue, gint msgnum, gboolean *queued_removed);
 static void procmsg_update_unread_children     (MsgInfo        *info,
@@ -1761,6 +1763,19 @@ send_mail:
 
        fclose(fp);
 
+       /* update session statistics */
+       if (mailval == 0 && newsval == 0) {
+               /* update session stats */
+               if (replymessageid)
+                       session_stats.replied++;
+               else if (fwdmessageid)
+                       session_stats.forwarded++;
+               else
+                       session_stats.sent++;
+fprintf(stdout, "++ STATS ++ SENT %d %d %d\n", session_stats.sent, session_stats.replied, session_stats.forwarded);
+fflush(stdout);
+       }
+
        /* save message to outbox */
        if (mailval == 0 && newsval == 0 && savecopyfolder) {
                FolderItem *outbox;