annotate 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
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 /* Puts last 4k of log in new conversations a la Everybuddy (and then
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * stolen by Trillian "Pro") */
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 "gaim.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 #include "gtkimhtml.h"
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 #include <sys/stat.h>
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 #include <unistd.h>
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 #define HISTORY_SIZE (4 * 1024)
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 GModule *handle;
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 void historize (char *name, void *data)
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 struct conversation *c = find_conversation(name);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 struct stat st;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 FILE *fd;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 char *userdir = gaim_user_dir();
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 char *logfile = g_strdup_printf("%s.log", normalize(name));
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 char *path = g_build_filename(userdir, "logs", logfile, NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 char buf[HISTORY_SIZE+1];
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 char *tmp;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 int size;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 ||
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 !(fd = fopen(path, "r"))) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 g_free(userdir);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 g_free(logfile);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 g_free(path);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 return;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 }
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : st.st_size, SEEK_SET);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 size = fread(buf, 1, HISTORY_SIZE, fd);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 tmp = buf;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 tmp[size] = 0;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 /* start the history at a newline */
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 while (*tmp && *tmp != '\n')
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 tmp++;
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 if (*tmp) tmp++;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_NEWLINE);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 g_free(userdir);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 g_free(logfile);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 g_free(path);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 }
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 char *gaim_plugin_init(GModule *h) {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 handle = h;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 gaim_signal_connect(handle, event_new_conversation, historize, NULL);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 return NULL;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 }
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 struct gaim_plugin_description desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 struct gaim_plugin_description *gaim_plugin_desc() {
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 desc.api_version = PLUGIN_API_VERSION;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 desc.name = g_strdup("History");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 desc.version = g_strdup(VERSION);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 desc.description = g_strdup("Shows recently logged conversations in new conversations ");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 desc.authors = g_strdup("Sean Egan &lt;bj91704@binghamton.edu>");
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 desc.url = g_strdup(WEBSITE);
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 return &desc;
c6f92ece3097 [gaim-migrate @ 3700]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 }