Mercurial > pidgin
annotate plugins/history.c @ 5164:98d16e2d1bf9
[gaim-migrate @ 5528]
This should fix a memleak when hitting cancel on the file selection dialog
when sending a file, or trying to send a file that doesn't exist, or a
file of size 0, or one that you don't have permission to access.
I'm sure Christian has some kind of cool master plan for what to do here,
since he's all about cool master plans, but this should at least fix a lil'
memleak until he has time to get his implement on.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 18 Apr 2003 06:49:49 +0000 |
parents | e245e686f62f |
children | fefad67de2c7 |
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 | |
5114
e245e686f62f
[gaim-migrate @ 5477]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4359
diff
changeset
|
65 G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) { |
3598 | 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; | |
5114
e245e686f62f
[gaim-migrate @ 5477]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4359
diff
changeset
|
74 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { |
3598 | 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 } |