Mercurial > pidgin.yaz
annotate plugins/history.c @ 4685:794cc8ec1166
[gaim-migrate @ 4996]
this fixes the ever-red tabs, the convo titles not switching, and some other
fun stuff. Oh, and the font-face button in the convo toolbar is back.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 10 Mar 2003 04:11:18 +0000 |
parents | 5fb47ec9bfe4 |
children | e245e686f62f |
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 { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4235
diff
changeset
|
22 struct gaim_conversation *c = gaim_find_conversation(name); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4235
diff
changeset
|
23 struct gaim_gtk_conversation *gtkconv; |
3598 | 24 struct stat st; |
25 FILE *fd; | |
3655 | 26 char *userdir = g_strdup(gaim_user_dir()); |
3598 | 27 char *logfile = g_strdup_printf("%s.log", normalize(name)); |
28 char *path = g_build_filename(userdir, "logs", logfile, NULL); | |
29 char buf[HISTORY_SIZE+1]; | |
30 char *tmp; | |
31 int size; | |
3602 | 32 GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS; |
3598 | 33 |
34 if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 || | |
35 !(fd = fopen(path, "r"))) { | |
36 g_free(userdir); | |
37 g_free(logfile); | |
38 g_free(path); | |
39 return; | |
40 } | |
41 | |
3981 | 42 fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : 0, SEEK_SET); |
3598 | 43 size = fread(buf, 1, HISTORY_SIZE, fd); |
44 tmp = buf; | |
45 tmp[size] = 0; | |
46 | |
47 /* start the history at a newline */ | |
48 while (*tmp && *tmp != '\n') | |
49 tmp++; | |
50 | |
51 if (*tmp) tmp++; | |
3602 | 52 |
53 if(*tmp == '<') | |
54 options |= GTK_IMHTML_NO_NEWLINE; | |
55 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4235
diff
changeset
|
56 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4235
diff
changeset
|
57 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4235
diff
changeset
|
58 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), tmp, strlen(tmp), options); |
3598 | 59 |
60 g_free(userdir); | |
61 g_free(logfile); | |
62 g_free(path); | |
63 } | |
64 | |
65 char *gaim_plugin_init(GModule *h) { | |
66 handle = h; | |
67 | |
68 gaim_signal_connect(handle, event_new_conversation, historize, NULL); | |
69 | |
70 return NULL; | |
71 } | |
72 | |
73 struct gaim_plugin_description desc; | |
74 struct gaim_plugin_description *gaim_plugin_desc() { | |
75 desc.api_version = PLUGIN_API_VERSION; | |
4113 | 76 desc.name = g_strdup(_("History")); |
3598 | 77 desc.version = g_strdup(VERSION); |
4113 | 78 desc.description = g_strdup(_("Shows recently logged conversations in new conversations ")); |
3598 | 79 desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); |
80 desc.url = g_strdup(WEBSITE); | |
81 return &desc; | |
82 } |