From: Sean E. <sea...@us...> - 2002-10-06 07:56:45
|
Update of /cvsroot/gaim/gaim/plugins In directory usw-pr-cvs1:/tmp/cvs-serv9671/plugins Added Files: history.c timestamp.c Log Message: This will make it easier to try it out. --- NEW FILE: history.c --- /* Puts last 4k of log in new conversations a la Everybuddy (and then * stolen by Trillian "Pro") */ #define GAIM_PLUGINS #include "gaim.h" #include "gtkimhtml.h" #include <sys/stat.h> #include <unistd.h> #define HISTORY_SIZE (4 * 1024) GModule *handle; void historize (char *name, void *data) { struct conversation *c = find_conversation(name); struct stat st; FILE *fd; char *userdir = gaim_user_dir(); char *logfile = g_strdup_printf("%s.log", normalize(name)); char *path = g_build_filename(userdir, "logs", logfile, NULL); char buf[HISTORY_SIZE+1]; char *tmp; int size; if (stat(path, &st) || S_ISDIR(st.st_mode) || st.st_size == 0 || !(fd = fopen(path, "r"))) { g_free(userdir); g_free(logfile); g_free(path); return; } fseek(fd, st.st_size > HISTORY_SIZE ? st.st_size - HISTORY_SIZE : st.st_size, SEEK_SET); size = fread(buf, 1, HISTORY_SIZE, fd); tmp = buf; tmp[size] = 0; /* start the history at a newline */ while (*tmp && *tmp != '\n') tmp++; if (*tmp) tmp++; gtk_imhtml_append_text(GTK_IMHTML(c->text), tmp, strlen(tmp), GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_NEWLINE); g_free(userdir); g_free(logfile); g_free(path); } char *gaim_plugin_init(GModule *h) { handle = h; gaim_signal_connect(handle, event_new_conversation, historize, NULL); return NULL; } struct gaim_plugin_description desc; struct gaim_plugin_description *gaim_plugin_desc() { desc.api_version = PLUGIN_API_VERSION; desc.name = g_strdup("History"); desc.version = g_strdup(VERSION); desc.description = g_strdup("Shows recently logged conversations in new conversations "); desc.authors = g_strdup("Sean Egan <bj...@bi...>"); desc.url = g_strdup(WEBSITE); return &desc; } --- NEW FILE: timestamp.c --- /* iChat-like timestamps by Sean Egan. * <INSERT GPL HERE> */ #define GAIM_PLUGINS #include <time.h> #include "gaim.h" #include "gtkimhtml.h" #define TIMESTAMP_DELAY (5 * 60 * 1000) GModule *handle; GSList *timestamp_timeouts; gboolean do_timestamp (struct conversation *c) { char *buf; char mdate[6]; time_t tim = time(NULL); if (!g_list_find(conversations, c)) return FALSE; strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim)); buf = g_strdup_printf(" %s", mdate); write_to_conv(c, buf, WFLAG_NOLOG, NULL, tim, -1); g_free(buf); return TRUE; } void timestamp_new_convo(char *name) { struct conversation *c = find_conversation(name); do_timestamp(c); timestamp_timeouts = g_slist_append(timestamp_timeouts, GINT_TO_POINTER(gtk_timeout_add(TIMESTAMP_DELAY, do_timestamp, c))); } char *gaim_plugin_init(GModule *h) { GList *cnvs = conversations; struct conversation *c; handle = h; while (cnvs) { c = cnvs->data; timestamp_new_convo(c->name); cnvs = cnvs->next; } gaim_signal_connect(handle, event_new_conversation, timestamp_new_convo, NULL); return NULL; } void gaim_plugin_remove() { GSList *to; to = timestamp_timeouts; while (to) { gtk_timeout_remove(to->data); to = to->next; } g_slist_free(timestamp_timeouts); } struct gaim_plugin_description desc; struct gaim_plugin_description *gaim_plugin_desc() { desc.api_version = PLUGIN_API_VERSION; desc.name = g_strdup("Timestamp"); desc.version = g_strdup(VERSION); desc.description = g_strdup("Adds iChat-style timestamps to conversations every 5 minutes."); desc.authors = g_strdup("Sean Egan <bj...@bi...>"); desc.url = g_strdup(WEBSITE); return &desc; } |