From: Christoph Hohmann Date: Mon, 3 Mar 2003 20:45:57 +0000 (+0000) Subject: 0.8.10claws76 X-Git-Tag: rel_0_8_11~45 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=1e54657b1c7ee8a54e8d28d2c005ae605baafbde 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 --- diff --git a/ChangeLog.claws b/ChangeLog.claws index 013d164e9..4c1230d3c 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -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 diff --git a/configure.ac b/configure.ac index 184671765..a4f5917d9 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 0a494ed1a..451ae1217 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 \ diff --git a/src/common/hooks.h b/src/common/hooks.h index 447d68865..ecdb23e8d 100644 --- a/src/common/hooks.h +++ b/src/common/hooks.h @@ -20,6 +20,8 @@ #ifndef HOOKS_H #define HOOKS_H +#include + typedef gboolean (*SylpheedHookFunction) (gpointer source, gpointer userdata); diff --git a/src/common/progressindicator.c b/src/common/progressindicator.c new file mode 100644 index 000000000..5c00bf407 --- /dev/null +++ b/src/common/progressindicator.c @@ -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 + +#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 index 000000000..2c73098ef --- /dev/null +++ b/src/common/progressindicator.h @@ -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 + +#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 */ diff --git a/src/mainwindow.c b/src/mainwindow.c index 5b2cc08f8..8aeeadbb0 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -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. */ diff --git a/src/mainwindow.h b/src/mainwindow.h index 1dd928eb7..64081a157 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -130,6 +130,8 @@ struct _MainWindow SummaryView *summaryview; MessageView *messageview; LogWindow *logwin; + + gint progressindicator_hook; }; MainWindow *main_window_create (SeparateType type); diff --git a/src/news.c b/src/news.c index cf40007df..54b519d05 100644 --- a/src/news.c +++ b/src/news.c @@ -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; } diff --git a/src/news.h b/src/news.h index 52d1023b1..622d425ae 100644 --- a/src/news.h +++ b/src/news.h @@ -47,6 +47,7 @@ struct _NNTPSession NNTPSockInfo *nntp_sock; gchar *group; + gfloat fetch_base_percentage; }; struct _NewsGroupInfo