Mercurial > pidgin
comparison plugins/history.c @ 3598:c6f92ece3097
[gaim-migrate @ 3700]
This will make it easier to try it out.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 06 Oct 2002 07:56:43 +0000 |
parents | |
children | a9cf9903bd74 |
comparison
equal
deleted
inserted
replaced
3597:bc87186a7478 | 3598:c6f92ece3097 |
---|---|
1 /* Puts last 4k of log in new conversations a la Everybuddy (and then | |
2 * stolen by Trillian "Pro") */ | |
3 | |
4 #define GAIM_PLUGINS | |
5 #include "gaim.h" | |
6 #include "gtkimhtml.h" | |
7 #include <sys/stat.h> | |
8 #include <unistd.h> | |
9 | |
10 #define HISTORY_SIZE (4 * 1024) | |
11 | |
12 GModule *handle; | |
13 | |
14 void historize (char *name, void *data) | |
15 { | |
16 struct conversation *c = find_conversation(name); | |
17 struct stat st; | |
18 FILE *fd; | |
19 char *userdir = gaim_user_dir(); | |
20 char *logfile = g_strdup_printf("%s.log", normalize(name)); | |
21 char *path = g_build_filename(userdir, "logs", logfile, NULL); | |
22 char buf[HISTORY_SIZE+1]; | |
23 char *tmp; | |
24 int size; | |
25 | |
26 if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 || | |
27 !(fd = fopen(path, "r"))) { | |
28 g_free(userdir); | |
29 g_free(logfile); | |
30 g_free(path); | |
31 return; | |
32 } | |
33 | |
34 fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : st.st_size, SEEK_SET); | |
35 size = fread(buf, 1, HISTORY_SIZE, fd); | |
36 tmp = buf; | |
37 tmp[size] = 0; | |
38 | |
39 /* start the history at a newline */ | |
40 while (*tmp && *tmp != '\n') | |
41 tmp++; | |
42 | |
43 if (*tmp) tmp++; | |
44 | |
45 gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_NEWLINE); | |
46 | |
47 g_free(userdir); | |
48 g_free(logfile); | |
49 g_free(path); | |
50 } | |
51 | |
52 char *gaim_plugin_init(GModule *h) { | |
53 handle = h; | |
54 | |
55 gaim_signal_connect(handle, event_new_conversation, historize, NULL); | |
56 | |
57 return NULL; | |
58 } | |
59 | |
60 struct gaim_plugin_description desc; | |
61 struct gaim_plugin_description *gaim_plugin_desc() { | |
62 desc.api_version = PLUGIN_API_VERSION; | |
63 desc.name = g_strdup("History"); | |
64 desc.version = g_strdup(VERSION); | |
65 desc.description = g_strdup("Shows recently logged conversations in new conversations "); | |
66 desc.authors = g_strdup("Sean Egan <bj91704@binghamton.edu>"); | |
67 desc.url = g_strdup(WEBSITE); | |
68 return &desc; | |
69 } |