# HG changeset patch # User Sadrul Habib Chowdhury # Date 1156092357 0 # Node ID 7c560c01b8f94fd169a50352049d983f3e84b0b5 # Parent 8c13a650cef50f1f7b560d8c04c3844cd47d5068 [gaim-migrate @ 16904] Add a plugin gnthistory. The plugin is a core plugin, but does not look good in gtkgaim. committer: Tailor Script diff -r 8c13a650cef5 -r 7c560c01b8f9 console/plugins/Makefile.am --- a/console/plugins/Makefile.am Sun Aug 20 16:38:10 2006 +0000 +++ b/console/plugins/Makefile.am Sun Aug 20 16:45:57 2006 +0000 @@ -1,27 +1,29 @@ gntgf_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) +gnthistory_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) if PLUGINS plugin_LTLIBRARIES = \ - gntgf.la + gntgf.la \ + gnthistory.la plugindir = $(libdir)/gaim gntgf_la_SOURCES = gntgf.c +gnthistory_la_SOURCES = gnthistory.c endif # PLUGINS EXTRA_DIST = -GNT_CFLAGS = `pkg-config --cflags gnt` -I.. - AM_CPPFLAGS = \ -DDATADIR=\"$(datadir)\" \ -DVERSION=\"$(VERSION)\" \ - -I$(top_builddir)/src \ - -I$(top_srcdir)/src \ + -I$(top_builddir)/libgaim \ + -I$(top_srcdir)/libgaim \ + -I$(top_srcdir)/console \ + -I$(top_srcdir)/console/libgnt \ $(DEBUG_CFLAGS) \ - $(GNT_CFLAGS) \ $(GLIB_CFLAGS) \ $(PLUGIN_CFLAGS) diff -r 8c13a650cef5 -r 7c560c01b8f9 console/plugins/gntgf.c --- a/console/plugins/gntgf.c Sun Aug 20 16:38:10 2006 +0000 +++ b/console/plugins/gntgf.c Sun Aug 20 16:45:57 2006 +0000 @@ -18,7 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define GAIM_PLUGINS + +#include "internal.h" #define PLUGIN_STATIC_NAME "GntGf" @@ -47,8 +48,6 @@ #include -#define _(X) X - typedef struct { GntWidget *window; @@ -202,10 +201,10 @@ char *display; } prefs[] = { - {PREFS_EVENT_SIGNONF, _("Buddy signs on/off")}, - {PREFS_EVENT_IM_MSG, _("You receive an IM")}, - {PREFS_EVENT_CHAT_MSG, _("Someone speaks in a chat")}, - {PREFS_EVENT_CHAT_NICK, _("Someone says your name in a chat")}, + {PREFS_EVENT_SIGNONF, N_("Buddy signs on/off")}, + {PREFS_EVENT_IM_MSG, N_("You receive an IM")}, + {PREFS_EVENT_CHAT_MSG, N_("Someone speaks in a chat")}, + {PREFS_EVENT_CHAT_NICK, N_("Someone says your name in a chat")}, {NULL, NULL} }; diff -r 8c13a650cef5 -r 7c560c01b8f9 console/plugins/gnthistory.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/plugins/gnthistory.c Sun Aug 20 16:45:57 2006 +0000 @@ -0,0 +1,202 @@ +/** + * @file gnthistory.c Show log from previous conversation + * + * Copyright (C) 2006 Sadrul Habib Chowdhury + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Ripped from gtk/plugins/history.c */ + +#include "internal.h" +#include "gntgaim.h" + +#include "conversation.h" +#include "debug.h" +#include "log.h" +#include "notify.h" +#include "prefs.h" +#include "signals.h" +#include "util.h" +#include "version.h" + +#include "gntplugin.h" + +#include + +#define HISTORY_PLUGIN_ID "gnt-history" + +#define HISTORY_SIZE (4 * 1024) + +static void historize(GaimConversation *c) +{ + GaimAccount *account = gaim_conversation_get_account(c); + const char *name = gaim_conversation_get_name(c); + GaimConversationType convtype; + GList *logs = NULL; + const char *alias = name; + guint flags; + char *history; + char *header; + + convtype = gaim_conversation_get_type(c); + if (convtype == GAIM_CONV_TYPE_IM) + { + GSList *buddies; + GSList *cur; + + /* If we're not logging, don't show anything. + * Otherwise, we might show a very old log. */ + if (!gaim_prefs_get_bool("/core/logging/log_ims")) + return; + + /* Find buddies for this conversation. */ + buddies = gaim_find_buddies(account, name); + + /* If we found at least one buddy, save the first buddy's alias. */ + if (buddies != NULL) + alias = gaim_buddy_get_contact_alias((GaimBuddy *)buddies->data); + + for (cur = buddies; cur != NULL; cur = cur->next) + { + GaimBlistNode *node = cur->data; + if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) + { + GaimBlistNode *node2; + + alias = gaim_buddy_get_contact_alias((GaimBuddy *)node); + + /* We've found a buddy that matches this conversation. It's part of a + * GaimContact with more than one GaimBuddy. Loop through the GaimBuddies + * in the contact and get all the logs. */ + for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next) + { + logs = g_list_concat( + gaim_log_get_logs(GAIM_LOG_IM, + gaim_buddy_get_name((GaimBuddy *)node2), + gaim_buddy_get_account((GaimBuddy *)node2)), + logs); + } + break; + } + } + g_slist_free(buddies); + + if (logs == NULL) + logs = gaim_log_get_logs(GAIM_LOG_IM, name, account); + else + logs = g_list_sort(logs, gaim_log_compare); + } + else if (convtype == GAIM_CONV_TYPE_CHAT) + { + /* If we're not logging, don't show anything. + * Otherwise, we might show a very old log. */ + if (!gaim_prefs_get_bool("/core/logging/log_chats")) + return; + + logs = gaim_log_get_logs(GAIM_LOG_CHAT, name, account); + } + + if (logs == NULL) + return; + + history = gaim_log_read((GaimLog*)logs->data, &flags); + + header = g_strdup_printf(_("Conversation with %s on %s:
"), alias, + gaim_date_format_full(localtime(&((GaimLog *)logs->data)->time))); + gaim_conversation_write(c, "", header, GAIM_MESSAGE_NO_LOG, time(NULL)); + g_free(header); + + g_strchomp(history); + gaim_conversation_write(c, "", history, GAIM_MESSAGE_NO_LOG, time(NULL)); + g_free(history); + + gaim_conversation_write(c, "", "\n---------------\n", GAIM_MESSAGE_NO_LOG, time(NULL)); + + g_list_foreach(logs, (GFunc)gaim_log_free, NULL); + g_list_free(logs); +} + +static void +history_prefs_check(GaimPlugin *plugin) +{ + if (!gaim_prefs_get_bool("/core/logging/log_ims") && + !gaim_prefs_get_bool("/core/logging/log_chats")) + { + gaim_notify_warning(plugin, NULL, _("History Plugin Requires Logging"), + _("Logging can be enabled from Tools -> Preferences -> Logging.\n\n" + "Enabling logs for instant messages and/or chats will activate " + "history for the same conversation type(s).")); + } +} + +static void history_prefs_cb(const char *name, GaimPrefType type, + gconstpointer val, gpointer data) +{ + history_prefs_check((GaimPlugin *)data); +} + +static gboolean +plugin_load(GaimPlugin *plugin) +{ + gaim_signal_connect(gaim_conversations_get_handle(), + "conversation-created", + plugin, GAIM_CALLBACK(historize), NULL); + + gaim_prefs_connect_callback(plugin, "/core/logging/log_ims", + history_prefs_cb, plugin); + gaim_prefs_connect_callback(plugin, "/core/logging/log_chats", + history_prefs_cb, plugin); + + history_prefs_check(plugin); + + return TRUE; +} + +static GaimPluginInfo info = +{ + GAIM_PLUGIN_MAGIC, + GAIM_MAJOR_VERSION, + GAIM_MINOR_VERSION, + GAIM_PLUGIN_STANDARD, + NULL, + 0, + NULL, + GAIM_PRIORITY_DEFAULT, + HISTORY_PLUGIN_ID, + N_("GntHistory"), + VERSION, + N_("Shows recently logged conversations in new conversations."), + N_("When a new conversation is opened this plugin will insert " + "the last conversation into the current conversation."), + "Sean Egan \n" + "Sadrul H Chowdhury ", + GAIM_WEBSITE, + plugin_load, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +static void +init_plugin(GaimPlugin *plugin) +{ +} + +GAIM_INIT_PLUGIN(gnthistory, init_plugin, info) +