Mercurial > pidgin
annotate finch/plugins/gnthistory.c @ 20649:964014aee978
merge of '025faf23aaac403798451974c320c4de6df470d5'
and '5c5edb6508adac74635924c3b6fa2676a92323e3'
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 22 Sep 2007 03:21:11 +0000 |
parents | 44b4e8bd759b |
children | 3cc856ca2338 |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gnthistory.c Show log from previous conversation | |
3 * | |
4 * Copyright (C) 2006 Sadrul Habib Chowdhury <sadrul@users.sourceforge.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16669
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15817 | 19 */ |
20 | |
21 /* Ripped from gtk/plugins/history.c */ | |
22 | |
23 #include "internal.h" | |
24 | |
25 #include "conversation.h" | |
26 #include "debug.h" | |
27 #include "log.h" | |
28 #include "notify.h" | |
29 #include "prefs.h" | |
30 #include "signals.h" | |
31 #include "util.h" | |
32 #include "version.h" | |
33 | |
34 #include "gntplugin.h" | |
35 | |
36 #define HISTORY_PLUGIN_ID "gnt-history" | |
37 | |
38 #define HISTORY_SIZE (4 * 1024) | |
39 | |
15822 | 40 static void historize(PurpleConversation *c) |
15817 | 41 { |
15822 | 42 PurpleAccount *account = purple_conversation_get_account(c); |
43 const char *name = purple_conversation_get_name(c); | |
44 PurpleConversationType convtype; | |
15817 | 45 GList *logs = NULL; |
46 const char *alias = name; | |
15822 | 47 PurpleLogReadFlags flags; |
15817 | 48 char *history; |
49 char *header; | |
15822 | 50 PurpleMessageFlags mflag; |
15817 | 51 |
15822 | 52 convtype = purple_conversation_get_type(c); |
53 if (convtype == PURPLE_CONV_TYPE_IM) | |
15817 | 54 { |
55 GSList *buddies; | |
56 GSList *cur; | |
57 | |
58 /* If we're not logging, don't show anything. | |
59 * Otherwise, we might show a very old log. */ | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
60 if (!purple_prefs_get_bool("/purple/logging/log_ims")) |
15817 | 61 return; |
62 | |
63 /* Find buddies for this conversation. */ | |
15822 | 64 buddies = purple_find_buddies(account, name); |
15817 | 65 |
66 /* If we found at least one buddy, save the first buddy's alias. */ | |
67 if (buddies != NULL) | |
15822 | 68 alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data); |
15817 | 69 |
70 for (cur = buddies; cur != NULL; cur = cur->next) | |
71 { | |
15822 | 72 PurpleBlistNode *node = cur->data; |
15817 | 73 if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) |
74 { | |
15822 | 75 PurpleBlistNode *node2; |
15817 | 76 |
15822 | 77 alias = purple_buddy_get_contact_alias((PurpleBuddy *)node); |
15817 | 78 |
79 /* We've found a buddy that matches this conversation. It's part of a | |
15822 | 80 * PurpleContact with more than one PurpleBuddy. Loop through the PurpleBuddies |
15817 | 81 * in the contact and get all the logs. */ |
82 for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next) | |
83 { | |
84 logs = g_list_concat( | |
15822 | 85 purple_log_get_logs(PURPLE_LOG_IM, |
86 purple_buddy_get_name((PurpleBuddy *)node2), | |
87 purple_buddy_get_account((PurpleBuddy *)node2)), | |
15817 | 88 logs); |
89 } | |
90 break; | |
91 } | |
92 } | |
93 g_slist_free(buddies); | |
94 | |
95 if (logs == NULL) | |
15822 | 96 logs = purple_log_get_logs(PURPLE_LOG_IM, name, account); |
15817 | 97 else |
15822 | 98 logs = g_list_sort(logs, purple_log_compare); |
15817 | 99 } |
15822 | 100 else if (convtype == PURPLE_CONV_TYPE_CHAT) |
15817 | 101 { |
102 /* If we're not logging, don't show anything. | |
103 * Otherwise, we might show a very old log. */ | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
104 if (!purple_prefs_get_bool("/purple/logging/log_chats")) |
15817 | 105 return; |
106 | |
15822 | 107 logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account); |
15817 | 108 } |
109 | |
110 if (logs == NULL) | |
111 return; | |
112 | |
15822 | 113 mflag = PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_DELAYED; |
114 history = purple_log_read((PurpleLog*)logs->data, &flags); | |
15817 | 115 |
116 header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), alias, | |
15822 | 117 purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time))); |
118 purple_conversation_write(c, "", header, mflag, time(NULL)); | |
15817 | 119 g_free(header); |
120 | |
15822 | 121 if (flags & PURPLE_LOG_READ_NO_NEWLINE) |
122 purple_str_strip_char(history, '\n'); | |
123 purple_conversation_write(c, "", history, mflag, time(NULL)); | |
15817 | 124 g_free(history); |
125 | |
15822 | 126 purple_conversation_write(c, "", "<hr>", mflag, time(NULL)); |
15817 | 127 |
15822 | 128 g_list_foreach(logs, (GFunc)purple_log_free, NULL); |
15817 | 129 g_list_free(logs); |
130 } | |
131 | |
132 static void | |
15822 | 133 history_prefs_check(PurplePlugin *plugin) |
15817 | 134 { |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
135 if (!purple_prefs_get_bool("/purple/logging/log_ims") && |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
136 !purple_prefs_get_bool("/purple/logging/log_chats")) |
15817 | 137 { |
15822 | 138 purple_notify_warning(plugin, NULL, _("History Plugin Requires Logging"), |
15817 | 139 _("Logging can be enabled from Tools -> Preferences -> Logging.\n\n" |
140 "Enabling logs for instant messages and/or chats will activate " | |
141 "history for the same conversation type(s).")); | |
142 } | |
143 } | |
144 | |
15822 | 145 static void history_prefs_cb(const char *name, PurplePrefType type, |
15817 | 146 gconstpointer val, gpointer data) |
147 { | |
15822 | 148 history_prefs_check((PurplePlugin *)data); |
15817 | 149 } |
150 | |
151 static gboolean | |
15822 | 152 plugin_load(PurplePlugin *plugin) |
15817 | 153 { |
15822 | 154 purple_signal_connect(purple_conversations_get_handle(), |
15817 | 155 "conversation-created", |
15822 | 156 plugin, PURPLE_CALLBACK(historize), NULL); |
15817 | 157 |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
158 purple_prefs_connect_callback(plugin, "/purple/logging/log_ims", |
15817 | 159 history_prefs_cb, plugin); |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
15822
diff
changeset
|
160 purple_prefs_connect_callback(plugin, "/purple/logging/log_chats", |
15817 | 161 history_prefs_cb, plugin); |
162 | |
163 history_prefs_check(plugin); | |
164 | |
165 return TRUE; | |
166 } | |
167 | |
15822 | 168 static PurplePluginInfo info = |
15817 | 169 { |
15822 | 170 PURPLE_PLUGIN_MAGIC, |
171 PURPLE_MAJOR_VERSION, | |
172 PURPLE_MINOR_VERSION, | |
173 PURPLE_PLUGIN_STANDARD, | |
15817 | 174 NULL, |
175 0, | |
176 NULL, | |
15822 | 177 PURPLE_PRIORITY_DEFAULT, |
15817 | 178 HISTORY_PLUGIN_ID, |
179 N_("GntHistory"), | |
180 VERSION, | |
181 N_("Shows recently logged conversations in new conversations."), | |
182 N_("When a new conversation is opened this plugin will insert " | |
183 "the last conversation into the current conversation."), | |
184 "Sean Egan <seanegan@gmail.com>\n" | |
185 "Sadrul H Chowdhury <sadrul@users.sourceforge.net>", | |
15822 | 186 PURPLE_WEBSITE, |
15817 | 187 plugin_load, |
188 NULL, | |
189 NULL, | |
190 NULL, | |
191 NULL, | |
192 NULL, | |
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
193 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
194 |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
195 /* padding */ |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
196 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
197 NULL, |
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
198 NULL, |
15817 | 199 NULL |
200 }; | |
201 | |
202 static void | |
15822 | 203 init_plugin(PurplePlugin *plugin) |
15817 | 204 { |
205 } | |
206 | |
15822 | 207 PURPLE_INIT_PLUGIN(gnthistory, init_plugin, info) |
15817 | 208 |