annotate plugins/timestamp.c @ 3633:c084394b86de

[gaim-migrate @ 3756] Lets not do file send just yet its buggy, I need to redo it committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Fri, 11 Oct 2002 03:46:38 +0000
parents c6f92ece3097
children dadb43e0bcae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3598
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /* iChat-like timestamps by Sean Egan.
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * <INSERT GPL HERE> */
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 #define GAIM_PLUGINS
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 #include <time.h>
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 #include "gaim.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 #include "gtkimhtml.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 #define TIMESTAMP_DELAY (5 * 60 * 1000)
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 GModule *handle;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 GSList *timestamp_timeouts;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 gboolean do_timestamp (struct conversation *c)
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 char *buf;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 char mdate[6];
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 time_t tim = time(NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 if (!g_list_find(conversations, c))
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 return FALSE;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 buf = g_strdup_printf(" %s", mdate);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 write_to_conv(c, buf, WFLAG_NOLOG, NULL, tim, -1);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 g_free(buf);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 return TRUE;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 void timestamp_new_convo(char *name)
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 struct conversation *c = find_conversation(name);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 do_timestamp(c);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 timestamp_timeouts = g_slist_append(timestamp_timeouts, GINT_TO_POINTER(gtk_timeout_add(TIMESTAMP_DELAY, do_timestamp, c)));
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 char *gaim_plugin_init(GModule *h) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 GList *cnvs = conversations;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 struct conversation *c;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 handle = h;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 while (cnvs) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 c = cnvs->data;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 timestamp_new_convo(c->name);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 cnvs = cnvs->next;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 gaim_signal_connect(handle, event_new_conversation, timestamp_new_convo, NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 return NULL;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 void gaim_plugin_remove() {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 GSList *to;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 to = timestamp_timeouts;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 while (to) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 gtk_timeout_remove(to->data);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 to = to->next;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 g_slist_free(timestamp_timeouts);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 struct gaim_plugin_description desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 struct gaim_plugin_description *gaim_plugin_desc() {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 desc.api_version = PLUGIN_API_VERSION;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 desc.name = g_strdup("Timestamp");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 desc.version = g_strdup(VERSION);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 desc.description = g_strdup("Adds iChat-style timestamps to conversations every 5 minutes.");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 desc.authors = g_strdup("Sean Egan &lt;bj91704@binghamton.edu>");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 desc.url = g_strdup(WEBSITE);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 return &desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 }