# HG changeset patch # User Christian Hammond # Date 1055591715 0 # Node ID d6b5cab288bb8ff4ac7dd4b47584f32fac1a50c6 # Parent 412c5a0f9ef17315cdd8ff79ccbb501fbb640c54 [gaim-migrate @ 6297] Pounces are now imported and saved to disk. However, they are not yet loaded. I'll get to that tomorrow (later today? awwww!) committer: Tailor Script diff -r 412c5a0f9ef1 -r d6b5cab288bb src/gtkpounce.c --- a/src/gtkpounce.c Sat Jun 14 11:18:08 2003 +0000 +++ b/src/gtkpounce.c Sat Jun 14 11:55:15 2003 +0000 @@ -831,7 +831,7 @@ const char *buddy; GList *bp; - for (bp = gaim_get_pounces(); bp != NULL; bp = bp->next) { + for (bp = gaim_pounces_get_all(); bp != NULL; bp = bp->next) { pounce = (GaimPounce *)bp->data; buddy = gaim_pounce_get_pouncee(pounce); diff -r 412c5a0f9ef1 -r d6b5cab288bb src/main.c --- a/src/main.c Sat Jun 14 11:18:08 2003 +0000 +++ b/src/main.c Sat Jun 14 11:55:15 2003 +0000 @@ -839,6 +839,7 @@ gaim_plugins_load_saved(); gaim_accounts_load(); + gaim_pounces_load(); #ifdef _WIN32 /* Various win32 initializations */ diff -r 412c5a0f9ef1 -r d6b5cab288bb src/pounce.c --- a/src/pounce.c Sat Jun 14 11:18:08 2003 +0000 +++ b/src/pounce.c Sat Jun 14 11:55:15 2003 +0000 @@ -20,8 +20,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ +#include +#include #include -#include "gaim.h" +#include +#include +#include + +#include "debug.h" +#include "pounce.h" +#include "util.h" typedef struct { @@ -34,7 +42,9 @@ } GaimPounceActionData; -static GList *pounces = NULL; +static GList *pounces = NULL; +static guint pounces_save_timer = 0; +static gboolean pounces_loaded = FALSE; static GaimPounceActionData * find_action_data(const GaimPounce *pounce, const char *name) @@ -61,6 +71,22 @@ g_free(action_data); } +static gboolean +pounces_save_cb(gpointer unused) +{ + gaim_pounces_sync(); + pounces_save_timer = 0; + + return FALSE; +} + +static void +schedule_pounces_save(void) +{ + if (!pounces_save_timer) + pounces_save_timer = g_timeout_add(5000, pounces_save_cb, NULL); +} + GaimPounce * gaim_pounce_new(const char *ui_type, GaimAccount *pouncer, const char *pouncee, GaimPounceEvent event, @@ -108,6 +134,8 @@ pounce->free(pounce->data); g_free(pounce); + + schedule_pounces_save(); } void @@ -117,6 +145,8 @@ g_return_if_fail(pounce != GAIM_POUNCE_NONE); pounce->events = events; + + schedule_pounces_save(); } void @@ -126,6 +156,8 @@ g_return_if_fail(pouncer != NULL); pounce->pouncer = pouncer; + + schedule_pounces_save(); } void @@ -138,6 +170,8 @@ g_free(pounce->pouncee); pounce->pouncee = (pouncee == NULL ? NULL : g_strdup(pouncee)); + + schedule_pounces_save(); } void @@ -146,6 +180,8 @@ g_return_if_fail(pounce != NULL); pounce->save = save; + + schedule_pounces_save(); } void @@ -164,6 +200,8 @@ g_free, g_free); g_hash_table_insert(pounce->actions, g_strdup(name), action_data); + + schedule_pounces_save(); } void @@ -180,6 +218,8 @@ g_return_if_fail(action_data != NULL); action_data->enabled = enabled; + + schedule_pounces_save(); } void @@ -201,6 +241,8 @@ else g_hash_table_insert(action_data->atts, g_strdup(attr), g_strdup(value)); + + schedule_pounces_save(); } void @@ -294,7 +336,7 @@ g_return_if_fail(pouncee != NULL); g_return_if_fail(events != GAIM_POUNCE_NONE); - for (l = gaim_get_pounces(); l != NULL; l = l_next) { + for (l = gaim_pounces_get_all(); l != NULL; l = l_next) { pounce = (GaimPounce *)l->data; l_next = l->next; @@ -323,7 +365,7 @@ g_return_val_if_fail(pouncee != NULL, NULL); g_return_val_if_fail(events != GAIM_POUNCE_NONE, NULL); - for (l = gaim_get_pounces(); l != NULL; l = l->next) { + for (l = gaim_pounces_get_all(); l != NULL; l = l->next) { pounce = (GaimPounce *)l->data; if ((gaim_pounce_get_events(pounce) & events) && @@ -337,8 +379,162 @@ return NULL; } +gboolean +gaim_pounces_load(void) +{ + pounces_loaded = TRUE; + + return TRUE; +} + +static void +write_action_parameter(gpointer key, gpointer value, gpointer user_data) +{ + const char *name, *param_value; + FILE *fp; + + param_value = (const char *)value; + name = (const char *)key; + fp = (FILE *)user_data; + + fprintf(fp, " %s\n", name, param_value); +} + +static void +write_action_parameter_list(gpointer key, gpointer value, gpointer user_data) +{ + GaimPounceActionData *action_data; + const char *action; + FILE *fp; + + action_data = (GaimPounceActionData *)value; + action = (const char *)key; + fp = (FILE *)user_data; + + if (!action_data->enabled) + return; + + fprintf(fp, " atts) == 0) { + fprintf(fp, "/>\n"); + } + else { + fprintf(fp, ">\n"); + + g_hash_table_foreach(action_data->atts, write_action_parameter, fp); + + fprintf(fp, " \n"); + } +} + +static void +gaim_pounces_write(FILE *fp, GaimPounce *pounce) +{ + GaimAccount *pouncer; + GaimPounceEvent events; + char *pouncer_name; + + pouncer = gaim_pounce_get_pouncer(pounce); + events = gaim_pounce_get_events(pounce); + + pouncer_name = g_markup_escape_text(gaim_account_get_username(pouncer), -1); + + fprintf(fp, " \n", pounce->ui_type); + fprintf(fp, " %s\n", + pouncer->protocol_id, pouncer_name); + fprintf(fp, " %s\n", gaim_pounce_get_pouncee(pounce)); + fprintf(fp, " \n"); + + if (events & GAIM_POUNCE_SIGNON) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_SIGNOFF) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_AWAY) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_AWAY_RETURN) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_IDLE) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_IDLE_RETURN) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_TYPING) + fprintf(fp, " \n"); + if (events & GAIM_POUNCE_TYPING_STOPPED) + fprintf(fp, " \n"); + + fprintf(fp, " \n"); + fprintf(fp, " \n"); + + g_hash_table_foreach(pounce->actions, write_action_parameter_list, fp); + + fprintf(fp, " \n"); + fprintf(fp, " \n"); + + g_free(pouncer_name); +} + +void +gaim_pounces_sync(void) +{ + FILE *fp; + const char *user_dir = gaim_user_dir(); + char *filename; + char *filename_real; + + if (!pounces_loaded) { + gaim_debug(GAIM_DEBUG_WARNING, "pounces", + "Writing pounces to disk.\n"); + schedule_pounces_save(); + return; + } + + if (user_dir == NULL) + return; + + gaim_debug(GAIM_DEBUG_INFO, "pounces", "Writing pounces to disk.\n"); + + fp = fopen(user_dir, "r"); + + if (fp == NULL) + mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); + else + fclose(fp); + + filename = g_build_filename(user_dir, "pounces.xml.save", NULL); + + if ((fp = fopen(filename, "w")) != NULL) { + GList *l; + + fprintf(fp, "\n\n"); + fprintf(fp, "\n"); + + for (l = gaim_pounces_get_all(); l != NULL; l = l->next) + gaim_pounces_write(fp, l->data); + + fprintf(fp, "\n"); + + fclose(fp); + chmod(filename, S_IRUSR | S_IWUSR); + } + else { + gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Unable to write %s\n", + filename); + } + + filename_real = g_build_filename(user_dir, "pounces.xml", NULL); + + if (rename(filename, filename_real) < 0) { + gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Error renaming %s to %s\n", + filename, filename_real); + } + + g_free(filename); + g_free(filename_real); +} + GList * -gaim_get_pounces(void) +gaim_pounces_get_all(void) { return pounces; } diff -r 412c5a0f9ef1 -r d6b5cab288bb src/pounce.h --- a/src/pounce.h Sat Jun 14 11:18:08 2003 +0000 +++ b/src/pounce.h Sat Jun 14 11:55:15 2003 +0000 @@ -25,6 +25,9 @@ typedef struct _GaimPounce GaimPounce; +#include +#include "account.h" + /** * Events that trigger buddy pounces. */ @@ -261,10 +264,20 @@ const char *pouncee, GaimPounceEvent events); /** + * Loads the pounces. + */ +gboolean gaim_pounces_load(void); + +/** + * Force an immediate write of pounces. + */ +void gaim_pounces_sync(void); + +/** * Returns a list of all registered buddy pounces. * * @return The list of buddy pounces. */ -GList *gaim_get_pounces(void); +GList *gaim_pounces_get_all(void); #endif /* _GAIM_POUNCE_H_ */