0.8.10claws76
authorChristoph Hohmann <reboot@gmx.ch>
Mon, 3 Mar 2003 20:45:57 +0000 (20:45 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Mon, 3 Mar 2003 20:45:57 +0000 (20:45 +0000)
* src/mainwindow.[ch]
* src/common/Makefile.am
* src/common/progressindicator.[ch]
        add UI independent progress indicator handling

* src/news.[ch]
        use new progress indicator for message info fetching

* src/common/hooks.h
        code cleanup

ChangeLog.claws
configure.ac
src/common/Makefile.am
src/common/hooks.h
src/common/progressindicator.c [new file with mode: 0644]
src/common/progressindicator.h [new file with mode: 0644]
src/mainwindow.c
src/mainwindow.h
src/news.c
src/news.h

index 013d164..4c1230d 100644 (file)
@@ -1,3 +1,16 @@
+2003-03-03 [christoph] 0.8.10claws76
+
+       * src/mainwindow.[ch]
+       * src/common/Makefile.am
+       * src/common/progressindicator.[ch]
+               add UI independent progress indicator handling
+
+       * src/news.[ch]
+               use new progress indicator for message info fetching
+
+       * src/common/hooks.h
+               code cleanup
+
 2003-03-03 [oliver]    0.8.10claws75
 
        * src/toolbar.c
index 1846717..a4f5917 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws75
+EXTRA_VERSION=claws76
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 0a494ed..451ae12 100644 (file)
@@ -12,6 +12,7 @@ libsylpheedcommon_la_SOURCES = \
        passcrypt.c passcrypt.h \
        plugin.c plugin.h \
        prefs.c prefs.h \
+       progressindicator.c progressindicator.h \
        quoted-printable.c quoted-printable.h \
        session.c session.h \
        smtp.c smtp.h \
index 447d688..ecdb23e 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef HOOKS_H
 #define HOOKS_H
 
+#include <glib.h>
+
 typedef gboolean (*SylpheedHookFunction)       (gpointer source,
                                                 gpointer userdata);
 
diff --git a/src/common/progressindicator.c b/src/common/progressindicator.c
new file mode 100644 (file)
index 0000000..5c00bf4
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+#include "hooks.h"
+#include "progressindicator.h"
+
+void progressindicator_start(ProgressType type)
+{
+       ProgressData data;
+
+       data.cmd = PROGRESS_COMMAND_START;
+       data.type = type;
+
+       hooks_invoke(PROGRESSINDICATOR_HOOKLIST, &data);
+}
+
+void progressindicator_set_percentage(ProgressType type, gfloat percent)
+{
+       ProgressData data;
+
+       data.cmd = PROGRESS_COMMAND_SET_PERCENTAGE;
+       data.type = type;
+       data.value = percent;
+
+       hooks_invoke(PROGRESSINDICATOR_HOOKLIST, &data);
+}
+
+void progressindicator_stop(ProgressType type)
+{
+       ProgressData data;
+
+       data.cmd = PROGRESS_COMMAND_START;
+       data.type = type;
+
+       hooks_invoke(PROGRESSINDICATOR_HOOKLIST, &data);
+}
diff --git a/src/common/progressindicator.h b/src/common/progressindicator.h
new file mode 100644 (file)
index 0000000..2c73098
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PROCESSINDICATOR_H
+#define PROCESSINDICATOR_H
+
+#include <glib.h>
+
+#define PROGRESSINDICATOR_HOOKLIST "progressindicator_hooklist"
+
+typedef struct _ProgressData ProgressData;
+
+typedef enum {
+       PROGRESS_COMMAND_START,
+       PROGRESS_COMMAND_SET_PERCENTAGE,
+       PROGRESS_COMMAND_STOP,
+} ProgressCommand;
+
+typedef enum {
+       PROGRESS_TYPE_NETWORK,
+} ProgressType;
+
+struct _ProgressData {
+       ProgressCommand cmd;
+       ProgressType    type;
+       gfloat          value;
+};
+
+void progressindicator_start(ProgressType type);
+void progressindicator_set_percentage(ProgressType type, gfloat percent);
+void progressindicator_stop(ProgressType type);
+
+#endif /* PROCESSINDICATOR_H */
index 5b2cc08..8aeeadb 100644 (file)
@@ -85,6 +85,8 @@
 #include "sslcertwindow.h"
 #include "prefs_gtk.h"
 #include "pluginwindow.h"
+#include "hooks.h"
+#include "progressindicator.h"
 
 #define AC_LABEL_WIDTH 240
 
@@ -400,6 +402,8 @@ static gboolean mainwindow_focus_in_event   (GtkWidget      *widget,
 void main_window_reply_cb                      (MainWindow     *mainwin, 
                                                 guint           action,
                                                 GtkWidget      *widget);
+gboolean mainwindow_progressindicator_hook     (gpointer        source,
+                                                gpointer        userdata);
 #define  SEPARATE_ACTION 500 
 
 static GtkItemFactoryEntry mainwin_entries[] =
@@ -1009,6 +1013,9 @@ MainWindow *main_window_create(SeparateType type)
        mainwin->menu_lock_count = 0;
        mainwin->cursor_count = 0;
 
+       mainwin->progressindicator_hook =
+               hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
+
        if (!watch_cursor)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
 
@@ -2739,6 +2746,25 @@ MainWindow *mainwindow_get_mainwindow(void)
                return NULL;
 }
 
+gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
+{
+       ProgressData *data = (ProgressData *) source;
+       MainWindow *mainwin = (MainWindow *) userdata;
+
+       switch (data->cmd) {
+       case PROGRESS_COMMAND_START:
+       case PROGRESS_COMMAND_STOP:
+               gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), 0.0);
+               break;
+       case PROGRESS_COMMAND_SET_PERCENTAGE:
+               gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), data->value);
+               break;          
+       }
+       while (gtk_events_pending()) gtk_main_iteration ();
+
+       return FALSE;
+}
+
 /*
 * End of Source.
 */
index 1dd928e..64081a1 100644 (file)
@@ -130,6 +130,8 @@ struct _MainWindow
        SummaryView     *summaryview;
        MessageView     *messageview;
        LogWindow       *logwin;
+
+       gint    progressindicator_hook;
 };
 
 MainWindow *main_window_create         (SeparateType    type);
index cf40007..54b519d 100644 (file)
@@ -48,6 +48,7 @@
 #include "inputdialog.h"
 #include "alertpanel.h"
 #include "log.h"
+#include "progressindicator.h"
 #if USE_OPENSSL
 #  include "ssl.h"
 #endif
@@ -899,6 +900,7 @@ static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *ite
        GSList *newlist = NULL;
        GSList *llast = NULL;
        MsgInfo *msginfo;
+       guint count = 0, lines = (end - begin + 1) * 3;
 
        g_return_val_if_fail(session != NULL, NULL);
        g_return_val_if_fail(item != NULL, NULL);
@@ -915,6 +917,9 @@ static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *ite
                        log_warning(_("error occurred while getting xover.\n"));
                        return newlist;
                }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
 
                if (buf[0] == '.' && buf[1] == '\r') break;
 
@@ -949,6 +954,9 @@ static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *ite
                        log_warning(_("error occurred while getting xhdr.\n"));
                        return newlist;
                }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
 
                if (buf[0] == '.' && buf[1] == '\r') break;
                if (!llast) {
@@ -974,6 +982,9 @@ static GSList *news_get_msginfos_for_range(NNTPSession *session, FolderItem *ite
                        log_warning(_("error occurred while getting xhdr.\n"));
                        return newlist;
                }
+               count++;
+               progressindicator_set_percentage
+                       (PROGRESS_TYPE_NETWORK, session->fetch_base_percentage + ((gfloat) count / (gfloat) lines));
 
                if (buf[0] == '.' && buf[1] == '\r') break;
                if (!llast) {
@@ -1000,6 +1011,7 @@ GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
        NNTPSession *session;
        GSList *elem, *msginfo_list = NULL, *tmp_msgnum_list, *tmp_msginfo_list;
        guint first, last, next;
+       guint tofetch, fetched;
        
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(folder->type == F_NEWS, NULL);
@@ -1012,13 +1024,19 @@ GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
        tmp_msgnum_list = g_slist_copy(msgnum_list);
        tmp_msgnum_list = g_slist_sort(tmp_msgnum_list, news_fetch_msgnum_sort);
 
+       progressindicator_start(PROGRESS_TYPE_NETWORK);
+       tofetch = g_slist_length(tmp_msgnum_list);
+       fetched = 0;
+
        first = GPOINTER_TO_INT(tmp_msgnum_list->data);
        last = first;
        for(elem = g_slist_next(tmp_msgnum_list); elem != NULL; elem = g_slist_next(elem)) {
                next = GPOINTER_TO_INT(elem->data);
                if(next != (last + 1)) {
+                       session->fetch_base_percentage = (gfloat) fetched / (gfloat) tofetch;
                        tmp_msginfo_list = news_get_msginfos_for_range(session, item, first, last);
                        msginfo_list = g_slist_concat(msginfo_list, tmp_msginfo_list);
+                       fetched = last - first + 1;
                        first = next;
                }
                last = next;
@@ -1028,5 +1046,7 @@ GSList *news_get_msginfos(Folder *folder, FolderItem *item, GSList *msgnum_list)
 
        g_slist_free(tmp_msgnum_list);
        
+       progressindicator_stop(PROGRESS_TYPE_NETWORK);
+
        return msginfo_list;
 }
index 52d1023..622d425 100644 (file)
@@ -47,6 +47,7 @@ struct _NNTPSession
 
        NNTPSockInfo *nntp_sock;
        gchar *group;
+       gfloat fetch_base_percentage;
 };
 
 struct _NewsGroupInfo