Mercurial > pidgin
annotate plugins/history.c @ 4286:ff419780b2cb
[gaim-migrate @ 4538]
Missed a few.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 11 Jan 2003 00:21:36 +0000 |
parents | cba92ec56248 |
children | 5fb47ec9bfe4 |
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> | |
4235 | 14 #include <string.h> |
3598 | 15 |
16 #define HISTORY_SIZE (4 * 1024) | |
17 | |
18 GModule *handle; | |
19 | |
20 void historize (char *name, void *data) | |
21 { | |
22 struct conversation *c = find_conversation(name); | |
23 struct stat st; | |
24 FILE *fd; | |
3655 | 25 char *userdir = g_strdup(gaim_user_dir()); |
3598 | 26 char *logfile = g_strdup_printf("%s.log", normalize(name)); |
27 char *path = g_build_filename(userdir, "logs", logfile, NULL); | |
28 char buf[HISTORY_SIZE+1]; | |
29 char *tmp; | |
30 int size; | |
3602 | 31 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; |
3598 | 32 |
33 if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 || | |
34 !(fd = fopen(path, "r"))) { | |
35 g_free(userdir); | |
36 g_free(logfile); | |
37 g_free(path); | |
38 return; | |
39 } | |
40 | |
3981 | 41 fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : 0, SEEK_SET); |
3598 | 42 size = fread(buf, 1, HISTORY_SIZE, fd); |
43 tmp = buf; | |
44 tmp[size] = 0; | |
45 | |
46 /* start the history at a newline */ | |
47 while (*tmp && *tmp != '\n') | |
48 tmp++; | |
49 | |
50 if (*tmp) tmp++; | |
3602 | 51 |
52 if(*tmp == '<') | |
53 options |= GTK_IMHTML_NO_NEWLINE; | |
54 | |
55 gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), options); | |
3598 | 56 |
57 g_free(userdir); | |
58 g_free(logfile); | |
59 g_free(path); | |
60 } | |
61 | |
62 char *gaim_plugin_init(GModule *h) { | |
63 handle = h; | |
64 | |
65 gaim_signal_connect(handle, event_new_conversation, historize, NULL); | |
66 | |
67 return NULL; | |
68 } | |
69 | |
70 struct gaim_plugin_description desc; | |
71 struct gaim_plugin_description *gaim_plugin_desc() { | |
72 desc.api_version = PLUGIN_API_VERSION; | |
4113 | 73 desc.name = g_strdup(_("History")); |
3598 | 74 desc.version = g_strdup(VERSION); |
4113 | 75 desc.description = g_strdup(_("Shows recently logged conversations in new conversations ")); |
3598 | 76 desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); |
77 desc.url = g_strdup(WEBSITE); | |
78 return &desc; | |
79 } |