Mercurial > pidgin.yaz
annotate plugins/history.c @ 4229:c1857c9c912d
[gaim-migrate @ 4474]
Is it ironic that I use Time Warner cable to help develope an
AIM client?
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 07 Jan 2003 20:57:48 +0000 |
parents | 59751fe608c5 |
children | cba92ec56248 |
rev | line source |
---|---|
3598 | 1 /* Puts last 4k of log in new conversations a la Everybuddy (and then |
2 * stolen by Trillian "Pro") */ | |
3 | |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
4 #include "config.h" |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
5 |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
6 #ifndef GAIM_PLUGINS |
3598 | 7 #define GAIM_PLUGINS |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
8 #endif |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
9 |
3598 | 10 #include "gaim.h" |
11 #include "gtkimhtml.h" | |
12 #include <sys/stat.h> | |
13 #include <unistd.h> | |
14 | |
15 #define HISTORY_SIZE (4 * 1024) | |
16 | |
17 GModule *handle; | |
18 | |
19 void historize (char *name, void *data) | |
20 { | |
21 struct conversation *c = find_conversation(name); | |
22 struct stat st; | |
23 FILE *fd; | |
3655 | 24 char *userdir = g_strdup(gaim_user_dir()); |
3598 | 25 char *logfile = g_strdup_printf("%s.log", normalize(name)); |
26 char *path = g_build_filename(userdir, "logs", logfile, NULL); | |
27 char buf[HISTORY_SIZE+1]; | |
28 char *tmp; | |
29 int size; | |
3602 | 30 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; |
3598 | 31 |
32 if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 || | |
33 !(fd = fopen(path, "r"))) { | |
34 g_free(userdir); | |
35 g_free(logfile); | |
36 g_free(path); | |
37 return; | |
38 } | |
39 | |
3981 | 40 fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : 0, SEEK_SET); |
3598 | 41 size = fread(buf, 1, HISTORY_SIZE, fd); |
42 tmp = buf; | |
43 tmp[size] = 0; | |
44 | |
45 /* start the history at a newline */ | |
46 while (*tmp && *tmp != '\n') | |
47 tmp++; | |
48 | |
49 if (*tmp) tmp++; | |
3602 | 50 |
51 if(*tmp == '<') | |
52 options |= GTK_IMHTML_NO_NEWLINE; | |
53 | |
54 gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), options); | |
3598 | 55 |
56 g_free(userdir); | |
57 g_free(logfile); | |
58 g_free(path); | |
59 } | |
60 | |
61 char *gaim_plugin_init(GModule *h) { | |
62 handle = h; | |
63 | |
64 gaim_signal_connect(handle, event_new_conversation, historize, NULL); | |
65 | |
66 return NULL; | |
67 } | |
68 | |
69 struct gaim_plugin_description desc; | |
70 struct gaim_plugin_description *gaim_plugin_desc() { | |
71 desc.api_version = PLUGIN_API_VERSION; | |
4113 | 72 desc.name = g_strdup(_("History")); |
3598 | 73 desc.version = g_strdup(VERSION); |
4113 | 74 desc.description = g_strdup(_("Shows recently logged conversations in new conversations ")); |
3598 | 75 desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); |
76 desc.url = g_strdup(WEBSITE); | |
77 return &desc; | |
78 } |