Sun, 06 Oct 2002 07:56:43 +0000
[gaim-migrate @ 3700]
This will make it easier to try it out.
| 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 | ||
| 35 | timestamp_timeouts = g_slist_append(timestamp_timeouts, GINT_TO_POINTER(gtk_timeout_add(TIMESTAMP_DELAY, do_timestamp, c))); | |
| 36 | ||
| 37 | } | |
| 38 | char *gaim_plugin_init(GModule *h) { | |
| 39 | GList *cnvs = conversations; | |
| 40 | struct conversation *c; | |
| 41 | handle = h; | |
| 42 | ||
| 43 | while (cnvs) { | |
| 44 | c = cnvs->data; | |
| 45 | timestamp_new_convo(c->name); | |
| 46 | cnvs = cnvs->next; | |
| 47 | } | |
| 48 | gaim_signal_connect(handle, event_new_conversation, timestamp_new_convo, NULL); | |
| 49 | ||
| 50 | return NULL; | |
| 51 | } | |
| 52 | ||
| 53 | void gaim_plugin_remove() { | |
| 54 | GSList *to; | |
| 55 | to = timestamp_timeouts; | |
| 56 | while (to) { | |
| 57 | gtk_timeout_remove(to->data); | |
| 58 | to = to->next; | |
| 59 | } | |
| 60 | g_slist_free(timestamp_timeouts); | |
| 61 | } | |
| 62 | ||
| 63 | struct gaim_plugin_description desc; | |
| 64 | struct gaim_plugin_description *gaim_plugin_desc() { | |
| 65 | desc.api_version = PLUGIN_API_VERSION; | |
| 66 | desc.name = g_strdup("Timestamp"); | |
| 67 | desc.version = g_strdup(VERSION); | |
| 68 | desc.description = g_strdup("Adds iChat-style timestamps to conversations every 5 minutes."); | |
| 69 | desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); | |
| 70 | desc.url = g_strdup(WEBSITE); | |
| 71 | return &desc; | |
| 72 | } |