Thu, 17 Oct 2002 22:47:23 +0000
[gaim-migrate @ 3870]
whoops
| 3598 | 1 | /* iChat-like timestamps by Sean Egan. |
| 2 | * <INSERT GPL HERE> */ | |
| 3 | ||
| 4 | #define GAIM_PLUGINS | |
| 5 | #include <time.h> | |
| 6 | #include "gaim.h" | |
| 7 | #include "gtkimhtml.h" | |
| 8 | ||
| 9 | #define TIMESTAMP_DELAY (5 * 60 * 1000) | |
| 10 | ||
| 11 | GModule *handle; | |
| 12 | GSList *timestamp_timeouts; | |
| 13 | ||
| 14 | gboolean do_timestamp (struct conversation *c) | |
| 15 | { | |
| 16 | char *buf; | |
| 17 | char mdate[6]; | |
| 18 | time_t tim = time(NULL); | |
| 19 | ||
| 20 | if (!g_list_find(conversations, c)) | |
| 21 | return FALSE; | |
| 22 | ||
| 23 | strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim)); | |
| 24 | buf = g_strdup_printf(" %s", mdate); | |
| 25 | write_to_conv(c, buf, WFLAG_NOLOG, NULL, tim, -1); | |
| 26 | g_free(buf); | |
| 27 | return TRUE; | |
| 28 | } | |
| 29 | ||
| 30 | void timestamp_new_convo(char *name) | |
| 31 | { | |
| 32 | struct conversation *c = find_conversation(name); | |
| 33 | do_timestamp(c); | |
| 34 | ||
| 3727 | 35 | timestamp_timeouts = g_slist_append(timestamp_timeouts, |
| 36 | GINT_TO_POINTER(gtk_timeout_add(TIMESTAMP_DELAY, | |
| 37 | (GtkFunction)do_timestamp, c))); | |
| 3598 | 38 | |
| 39 | } | |
| 40 | char *gaim_plugin_init(GModule *h) { | |
| 41 | GList *cnvs = conversations; | |
| 42 | struct conversation *c; | |
| 43 | handle = h; | |
| 44 | ||
| 45 | while (cnvs) { | |
| 46 | c = cnvs->data; | |
| 47 | timestamp_new_convo(c->name); | |
| 48 | cnvs = cnvs->next; | |
| 49 | } | |
| 50 | gaim_signal_connect(handle, event_new_conversation, timestamp_new_convo, NULL); | |
| 51 | ||
| 52 | return NULL; | |
| 53 | } | |
| 54 | ||
| 55 | void gaim_plugin_remove() { | |
| 56 | GSList *to; | |
| 57 | to = timestamp_timeouts; | |
| 58 | while (to) { | |
| 3727 | 59 | gtk_timeout_remove(GPOINTER_TO_INT(to->data)); |
| 3598 | 60 | to = to->next; |
| 61 | } | |
| 62 | g_slist_free(timestamp_timeouts); | |
| 63 | } | |
| 64 | ||
| 65 | struct gaim_plugin_description desc; | |
| 66 | struct gaim_plugin_description *gaim_plugin_desc() { | |
| 67 | desc.api_version = PLUGIN_API_VERSION; | |
| 68 | desc.name = g_strdup("Timestamp"); | |
| 69 | desc.version = g_strdup(VERSION); | |
| 70 | desc.description = g_strdup("Adds iChat-style timestamps to conversations every 5 minutes."); | |
| 71 | desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); | |
| 72 | desc.url = g_strdup(WEBSITE); | |
| 73 | return &desc; | |
| 74 | } |