+2002-11-30 [christoph] 0.8.6claws50
+
+ * src/common/Makefile.am
+ add src/common/hooks.[ch]
+
+ * src/common/hooks.[ch]
+ implement a simple hook system using glib's hook functions
+
+ * src/folder.[ch]
+ * src/folderview.c
+ use new hook system for folder item updates
+
2002-11-30 [christoph] 0.8.6claws49
* doc-src/ui_seperation.txt ** NEW **
* src/common/utils.c
* src/summaryview.c
* src/xml.c
- o move debug_mode to commno/utils.c
+ o move debug_mode to common/utils.c
o add functions to set and get debug_mode
* src/defs.h ** REMOVE **
MICRO_VERSION=6
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=claws49
+EXTRA_VERSION=claws50
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
dnl set $target
libsylpheedcommon_la_SOURCES = \
utils.c utils.h \
+ hooks.c hooks.h \
base64.c base64.h \
uuencode.c uuencode.h \
socket.c socket.h \
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#include "hooks.h"
+
+GHashTable *hooklist_table;
+
+GHookList *hooks_get_hooklist(gchar *hooklist_name)
+{
+ GHookList *hooklist;
+
+ if (hooklist_table == NULL)
+ hooklist_table = g_hash_table_new(g_str_hash, g_str_equal);
+
+ hooklist = (GHookList *) g_hash_table_lookup(hooklist_table, hooklist_name);
+ if (hooklist != NULL)
+ return hooklist;
+
+ hooklist = g_new0(GHookList, 1);
+ g_hook_list_init(hooklist, sizeof(GHook));
+ g_hash_table_insert(hooklist_table, hooklist_name, hooklist);
+
+ return hooklist;
+}
+
+gint hooks_register_hook(gchar *hooklist_name,
+ SylpheedHookFunction hook_func,
+ gpointer userdata)
+{
+ GHookList *hooklist;
+ GHook *hook;
+
+ g_return_val_if_fail(hooklist_name != NULL, -1);
+ g_return_val_if_fail(hook_func != NULL, -1);
+
+ hooklist = hooks_get_hooklist(hooklist_name);
+ g_return_val_if_fail(hooklist != NULL, -1);
+
+ hook = g_hook_alloc(hooklist);
+ g_return_val_if_fail(hook != NULL, -1);
+
+ hook->func = hook_func;
+ hook->data = userdata;
+
+ g_hook_append(hooklist, hook);
+
+ return hook->hook_id;
+}
+
+void hooks_unregister_hook(gchar *hooklist_name,
+ guint hook_id)
+{
+}
+
+static void hooks_marshal(GHook *hook, gpointer source)
+{
+ gboolean (*func) (gpointer source, gpointer data);
+
+ func = hook->func;
+ func(source, hook->data);
+}
+
+void hooks_invoke(gchar *hooklist_name,
+ gpointer source)
+{
+ GHookList *hooklist;
+
+ g_return_if_fail(hooklist_name != NULL);
+
+ hooklist = hooks_get_hooklist(hooklist_name);
+ g_return_if_fail(hooklist != NULL);
+
+ g_hook_list_marshal(hooklist, TRUE, hooks_marshal, source);
+}
--- /dev/null
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 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 HOOKS_H
+#define HOOKS_H
+
+typedef void (*SylpheedHookFunction) (gpointer source,
+ gpointer userdata);
+
+gint hooks_register_hook (gchar *hooklist_name,
+ SylpheedHookFunction hook_func,
+ gpointer userdata);
+void hooks_unregister_hook (gchar *hooklist_name,
+ guint hook_id);
+void hooks_invoke (gchar *hooklist_name,
+ gpointer source);
+
+#endif /* HOOKS_H */
#include "prefs_folder_item.h"
#include "procheader.h"
#include "statusbar.h"
+#include "hooks.h"
/* Dependecies to be removed ?! */
#include "prefs_common.h"
/*
* Callback handling for FolderItem content changes
*/
-GSList *folder_item_update_callbacks_list = NULL;
-gint folder_item_update_callbacks_nextid = 0;
-
-struct FolderItemUpdateCallback
-{
- gint id;
- FolderItemUpdateFunc func;
- gpointer data;
-};
-
-gint folder_item_update_callback_register(FolderItemUpdateFunc func, gpointer data)
-{
- struct FolderItemUpdateCallback *callback;
-
- g_return_val_if_fail(func != NULL, -1);
-
- folder_item_update_callbacks_nextid++;
-
- callback = g_new0(struct FolderItemUpdateCallback, 1);
- callback->id = folder_item_update_callbacks_nextid;
- callback->func = func;
- callback->data = data;
-
- folder_item_update_callbacks_list =
- g_slist_append(folder_item_update_callbacks_list, callback);
-
- return folder_item_update_callbacks_nextid;
-}
-
-void folder_item_update_callback_unregister(gint id)
-{
- GSList *list, *next;
-
- for (list = folder_item_update_callbacks_list; list != NULL; list = next) {
- struct FolderItemUpdateCallback *callback;
-
- next = list->next;
-
- callback = list->data;
- if (callback->id == id) {
- folder_item_update_callbacks_list =
- g_slist_remove(folder_item_update_callbacks_list, callback);
- g_free(callback);
- }
- }
-}
-
-static void folder_item_update_callback_execute(FolderItem *item, gboolean contentchange)
-{
- GSList *list;
-
- for (list = folder_item_update_callbacks_list; list != NULL; list = list->next) {
- struct FolderItemUpdateCallback *callback;
-
- callback = list->data;
- callback->func(item, contentchange, callback->data);
- }
-}
-
void folder_update_item(FolderItem *item, gboolean contentchange)
{
- folder_item_update_callback_execute(item, contentchange);
+ FolderItemUpdateData source;
+
+ source.item = item;
+ source.content_change = contentchange;
+ hooks_invoke("folder_item_update", &source);
}
static void folder_update_item_func(FolderItem *item, gpointer contentchange)
{
+ FolderItemUpdateData source;
+
if (item->need_update) {
- folder_item_update_callback_execute(item, GPOINTER_TO_INT(contentchange));
+ source.item = item;
+ source.content_change = GPOINTER_TO_INT(contentchange);
+ hooks_invoke("folder_item_update", &source);
+
item->need_update = FALSE;
}
}
void folder_update_item_recursive(FolderItem *item, gboolean update_summary)
{
GNode *node = item->folder->node;
+ FolderItemUpdateData source;
+
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
node = node->children;
- folder_item_update_callback_execute(item, update_summary);
+
+ source.item = item;
+ source.content_change = update_summary;
+ hooks_invoke("folder_item_update", &source);
while (node != NULL) {
if (node && node->data) {
FolderItem *next_item = (FolderItem*) node->data;
- folder_item_update_callback_execute(next_item, update_summary);
+
+ source.item = next_item;
+ source.content_change = update_summary;
+ hooks_invoke("folder_item_update", &source);
}
node = node->next;
}
#include <glib.h>
#include <time.h>
-typedef struct _Folder Folder;
-typedef struct _LocalFolder LocalFolder;
-typedef struct _RemoteFolder RemoteFolder;
+typedef struct _Folder Folder;
+typedef struct _LocalFolder LocalFolder;
+typedef struct _RemoteFolder RemoteFolder;
#if 0
-typedef struct _MaildirFolder MaildirFolder;
+typedef struct _MaildirFolder MaildirFolder;
#endif
-typedef struct _FolderItem FolderItem;
+typedef struct _FolderItem FolderItem;
+typedef struct _FolderItemUpdateData FolderItemUpdateData;
#include "prefs_folder_item.h"
gpointer data);
typedef void (*FolderItemFunc) (FolderItem *item,
gpointer data);
-typedef void (*FolderItemUpdateFunc) (FolderItem *item,
- gboolean contentchange,
- gpointer data);
struct _Folder
{
guint ret_rcpt : 1; /* CLAWS */
} PersistPrefs;
+struct _FolderItemUpdateData
+{
+ FolderItem *item;
+ gboolean content_change;
+};
+
Folder *folder_new (FolderType type,
const gchar *name,
const gchar *path);
void folder_update_items_when_required (gboolean contentchange);
void folder_update_item_recursive (FolderItem *item,
gboolean update_summary);
-gint folder_item_update_callback_register(FolderItemUpdateFunc func,
- gpointer data);
-void folder_item_update_callback_unregister(gint id);
#endif /* __FOLDER_H__ */
#include "foldersel.h"
#include "inc.h"
#include "statusbar.h"
+#include "hooks.h"
typedef enum
{
void folderview_create_folder_node (FolderView *folderview,
FolderItem *item);
-void folderview_update_item (FolderItem *item,
- gboolean update_summary,
- gpointer data);
+void folderview_update_item (gpointer source,
+ gpointer data);
static void folderview_scoring_cb(FolderView *folderview, guint action,
GtkWidget *widget);
folderview->mbox_factory = mbox_factory;
folderview->folder_item_update_callback_id =
- folder_item_update_callback_register(folderview_update_item, (gpointer) folderview);
+ hooks_register_hook("folder_item_update", folderview_update_item, (gpointer) folderview);
gtk_widget_show_all(scrolledwin);
folderview_update_node(folderview, node);
}
-void folderview_update_item(FolderItem *item, gboolean update_summary, gpointer data)
+void folderview_update_item(gpointer source, gpointer data)
{
+ FolderItemUpdateData *update_info = (FolderItemUpdateData *)source;
FolderView *folderview = (FolderView *)data;
GtkCTree *ctree;
GtkCTreeNode *node;
+ g_return_if_fail(update_info != NULL);
+ g_return_if_fail(update_info->item != NULL);
g_return_if_fail(folderview != NULL);
- g_return_if_fail(item != NULL);
ctree = GTK_CTREE(folderview->ctree);
- node = gtk_ctree_find_by_row_data(ctree, NULL, item);
+ node = gtk_ctree_find_by_row_data(ctree, NULL, update_info->item);
if (node) {
folderview_update_node(folderview, node);
- if (update_summary && folderview->opened == node)
- summary_show(folderview->summaryview, item);
+ if (update_info->content_change && folderview->opened == node)
+ summary_show(folderview->summaryview, update_info->item);
}
}