diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-01-08 08:45:58 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-01-08 08:45:58 +0800 |
commit | e96bfc58ca850606a7c787636bc6e787266e6598 (patch) | |
tree | 5c833b88b17d7dac27cb5afb45f65dff89d6d02f | |
parent | 91aa52c36931748f4eb7f74d44d06ef77d834eac (diff) | |
download | gsoc2013-evolution-e96bfc58ca850606a7c787636bc6e787266e6598.tar.gz gsoc2013-evolution-e96bfc58ca850606a7c787636bc6e787266e6598.tar.zst gsoc2013-evolution-e96bfc58ca850606a7c787636bc6e787266e6598.zip |
Flush the only-once actions.
2002-01-07 Jeffrey Stedfast <fejj@ximian.com>
* camel-folder.c (filter_filter): Flush the only-once actions.
* camel-filter-driver.c (camel_filter_driver_filter_message):
Don't increment a filtered_count here any longer.
(camel_filter_driver_reset_filtered_count): Removed.
(camel_filter_driver_get_filtered_count): Removed.
(do_beep): New action.
(play_sound): New action to play a sound
(do_only_once): Another new action.
(camel_filter_driver_finalise): Free the only_once hash if the
driver has not been "flushed".
(camel_filter_driver_flush): Flush all of the only-once actions.
svn path=/trunk/; revision=15262
-rw-r--r-- | camel/ChangeLog | 13 | ||||
-rw-r--r-- | camel/camel-filter-driver.c | 159 | ||||
-rw-r--r-- | camel/camel-filter-driver.h | 7 | ||||
-rw-r--r-- | camel/camel-folder.c | 5 |
4 files changed, 155 insertions, 29 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 7255bebf28..d887f6a785 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,18 @@ 2002-01-07 Jeffrey Stedfast <fejj@ximian.com> + * camel-folder.c (filter_filter): Flush the only-once actions. + + * camel-filter-driver.c (camel_filter_driver_filter_message): + Don't increment a filtered_count here any longer. + (camel_filter_driver_reset_filtered_count): Removed. + (camel_filter_driver_get_filtered_count): Removed. + (do_beep): New action. + (play_sound): New action to play a sound + (do_only_once): Another new action. + (camel_filter_driver_finalise): Free the only_once hash if the + driver has not been "flushed". + (camel_filter_driver_flush): Flush all of the only-once actions. + * camel-charset-map.c: Moved windows-1251 to the end of the list since it contains the euro and we'd prefer to use iso-8859-15 when the euro is requested than a windows charset if possible. diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index 221947601c..9a05b91b2c 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -28,6 +28,7 @@ #include <time.h> #include <glib.h> +#include <gtk/gtk.h> #include <errno.h> @@ -68,8 +69,6 @@ struct _filter_rule { struct _CamelFilterDriverPrivate { GHashTable *globals; /* global variables */ - int filtered_count; /* count of the number of messages filtered so far */ - CamelFolder *defaultfolder; /* defualt folder */ CamelFilterStatusFunc *statusfunc; /* status callback */ @@ -78,6 +77,9 @@ struct _CamelFilterDriverPrivate { CamelFilterShellExecFunc *execfunc; /* execute shell command callback */ void *execdata; /* execute shell command data */ + CamelFilterPlaySoundFunc *playfunc; /* play-sound command callback */ + void *playdata; /* play-sound command data */ + /* for callback */ CamelFilterGetFolderFunc get_folder; void *data; @@ -86,6 +88,7 @@ struct _CamelFilterDriverPrivate { GHashTable *folders; /* folders that message has been copied to */ int closed; /* close count */ GHashTable *forwards; /* addresses that have been forwarded the message */ + GHashTable *only_once; /* actions to run only-once */ gboolean terminated; /* message processing was terminated */ gboolean deleted; /* message was marked for deletion */ @@ -99,7 +102,7 @@ struct _CamelFilterDriverPrivate { FILE *logfile; /* log file */ EDList rules; /* list of _filter_rule structs */ - + CamelException *ex; /* evaluator */ @@ -126,6 +129,9 @@ static ESExpResult *do_colour (struct _ESExp *f, int argc, struct _ESExpResult * static ESExpResult *do_score (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *do_beep (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *play_sound (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *do_only_once (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); /* these are our filter actions - each must have a callback */ static struct { @@ -142,7 +148,10 @@ static struct { { "set-colour", (ESExpFunc *) do_colour, 0 }, { "set-score", (ESExpFunc *) do_score, 0 }, { "set-system-flag", (ESExpFunc *) do_flag, 0 }, - { "shell-exec", (ESExpFunc *) shell_exec, 0 } + { "shell-exec", (ESExpFunc *) shell_exec, 0 }, + { "beep", (ESExpFunc *) do_beep, 0 }, + { "play-sound", (ESExpFunc *) play_sound, 0 }, + { "only-once", (ESExpFunc *) do_only_once, 0 } }; static CamelObjectClass *camel_filter_driver_parent; @@ -197,6 +206,8 @@ camel_filter_driver_init (CamelFilterDriver *obj) p->globals = g_hash_table_new (g_str_hash, g_str_equal); p->folders = g_hash_table_new (g_str_hash, g_str_equal); + + p->only_once = g_hash_table_new (g_str_hash, g_str_equal); } static void @@ -219,7 +230,10 @@ camel_filter_driver_finalise (CamelObject *obj) g_hash_table_foreach (p->globals, free_hash_strings, driver); g_hash_table_destroy (p->globals); - + + g_hash_table_foreach (p->only_once, free_hash_strings, driver); + g_hash_table_destroy (p->only_once); + e_sexp_unref(p->eval); if (p->defaultfolder) { @@ -249,22 +263,6 @@ camel_filter_driver_new (void) } void -camel_filter_driver_reset_filtered_count (CamelFilterDriver *driver) -{ - struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); - - p->filtered_count = 0; -} - -int -camel_filter_driver_get_filtered_count (CamelFilterDriver *driver) -{ - struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); - - return p->filtered_count; -} - -void camel_filter_driver_set_folder_func (CamelFilterDriver *d, CamelFilterGetFolderFunc get_folder, void *data) { struct _CamelFilterDriverPrivate *p = _PRIVATE (d); @@ -300,6 +298,15 @@ camel_filter_driver_set_shell_exec_func (CamelFilterDriver *d, CamelFilterShellE } void +camel_filter_driver_set_play_sound_func (CamelFilterDriver *d, CamelFilterPlaySoundFunc *func, void *data) +{ + struct _CamelFilterDriverPrivate *p = _PRIVATE (d); + + p->playfunc = func; + p->playdata = data; +} + +void camel_filter_driver_set_default_folder (CamelFilterDriver *d, CamelFolder *def) { struct _CamelFilterDriverPrivate *p = _PRIVATE (d); @@ -557,6 +564,46 @@ shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterD return NULL; } +static ESExpResult * +do_beep (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +{ + d(fprintf (stderr, "beep\n")); + + camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Beep"); + /*gdk_beep ();*/ + + return NULL; +} + +static ESExpResult * +play_sound (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +{ + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + + d(fprintf (stderr, "play sound\n")); + + if (p->playfunc && argc == 1 && argv[0]->type == ESEXP_RES_STRING) { + p->playfunc (driver, argv[0]->value.string, p->playdata); + camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Play sound"); + } + + return NULL; +} + +static ESExpResult * +do_only_once (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +{ + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + + d(fprintf (stderr, "only once\n")); + + if (argc == 2 && !g_hash_table_lookup (p->only_once, argv[0]->value.string)) + g_hash_table_insert (p->only_once, g_strdup (argv[0]->value.string), + g_strdup (argv[1]->value.string)); + + return NULL; +} + static CamelFolder * open_folder (CamelFilterDriver *driver, const char *folder_url) { @@ -681,6 +728,72 @@ camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_t status, co } +struct _run_only_once { + CamelFilterDriver *driver; + CamelException *ex; +}; + +static gboolean +run_only_once (gpointer key, char *action, struct _run_only_once *data) +{ + struct _CamelFilterDriverPrivate *p = _PRIVATE (data->driver); + CamelFilterDriver *driver = data->driver; + CamelException *ex = data->ex; + ESExpResult *r; + + printf ("evaluating: %s\n\n", action); + + e_sexp_input_text (p->eval, action, strlen (action)); + if (e_sexp_parse (p->eval) == -1) { + if (!camel_exception_is_set (ex)) + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Error parsing filter: %s: %s"), + e_sexp_error (p->eval), action); + goto done; + } + + r = e_sexp_eval (p->eval); + if (r == NULL) { + if (!camel_exception_is_set (ex)) + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Error executing filter: %s: %s"), + e_sexp_error (p->eval), action); + goto done; + } + + e_sexp_result_free (p->eval, r); + + done: + + g_free (key); + g_free (action); + + return TRUE; +} + + +/** + * camel_filter_driver_flush: + * @driver: + * @ex: + * + * Flush all of the only-once filter actions. + **/ +void +camel_filter_driver_flush (CamelFilterDriver *driver, CamelException *ex) +{ + struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + struct _run_only_once data; + + if (!p->only_once) + return; + + data.driver = driver; + data.ex = ex; + + g_hash_table_foreach_remove (p->only_once, run_only_once, &data); +} + /** * camel_filter_driver_filter_mbox: * @driver: CamelFilterDriver @@ -886,7 +999,7 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folde report_status (driver, CAMEL_FILTER_STATUS_END, 100, _("Complete")); g_free (source_url); - + return status; } @@ -1013,8 +1126,6 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage if (freeinfo) camel_message_info_free (info); - p->filtered_count++; - return 0; error: diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h index d003cc4a48..4e7c179971 100644 --- a/camel/camel-filter-driver.h +++ b/camel/camel-filter-driver.h @@ -62,18 +62,17 @@ typedef void (CamelFilterStatusFunc) (CamelFilterDriver *driver, enum camel_filt int pc, const char *desc, void *data); typedef void (CamelFilterShellExecFunc) (CamelFilterDriver *driver, const char *command, void *data); +typedef void (CamelFilterPlaySoundFunc) (CamelFilterDriver *driver, const char *filename, void *data); CamelType camel_filter_driver_get_type (void); CamelFilterDriver *camel_filter_driver_new (void); /* modifiers */ -void camel_filter_driver_reset_filtered_count (CamelFilterDriver *driver); -int camel_filter_driver_get_filtered_count (CamelFilterDriver *driver); - void camel_filter_driver_set_logfile (CamelFilterDriver *d, FILE *logfile); void camel_filter_driver_set_status_func (CamelFilterDriver *d, CamelFilterStatusFunc *func, void *data); void camel_filter_driver_set_shell_exec_func (CamelFilterDriver *d, CamelFilterShellExecFunc *func, void *data); +void camel_filter_driver_set_play_sound_func (CamelFilterDriver *d, CamelFilterPlaySoundFunc *func, void *data); void camel_filter_driver_set_folder_func (CamelFilterDriver *d, CamelFilterGetFolderFunc fetcher, void *data); void camel_filter_driver_set_default_folder (CamelFilterDriver *d, CamelFolder *def); @@ -83,6 +82,8 @@ void camel_filter_driver_add_rule (CamelFilterDriver *d, const char /*void camel_filter_driver_set_global(CamelFilterDriver *, const char *name, const char *value);*/ +void camel_filter_driver_flush (CamelFilterDriver *driver, CamelException *ex); + int camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info, const char *uri, CamelFolder *source, const char *source_url, diff --git a/camel/camel-folder.c b/camel/camel-folder.c index fd1fc13736..b29a845fb2 100644 --- a/camel/camel-folder.c +++ b/camel/camel-folder.c @@ -1479,8 +1479,9 @@ static void filter_filter(CamelSession *session, CamelSessionThreadMsg *msg) { struct _folder_filter_msg *m = (struct _folder_filter_msg *)msg; - - camel_filter_driver_filter_folder(m->driver, m->folder, NULL, m->recents, FALSE, &m->ex); + + camel_filter_driver_filter_folder(m->driver, m->folder, NULL, m->recents, FALSE, &m->ex); + camel_filter_driver_flush (m->driver, &m->ex); } static void |