Mercurial > pidgin
annotate finch/plugins/gnthistory.c @ 21487:f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
add new strings)
| author | Sadrul Habib Chowdhury <imadil@gmail.com> |
|---|---|
| date | Wed, 14 Nov 2007 05:27:47 +0000 |
| parents | 3cc856ca2338 |
| children | 665e04562de0 |
| 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" | |
|
21487
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
28 #include "request.h" |
| 15817 | 29 #include "prefs.h" |
| 30 #include "signals.h" | |
| 31 #include "util.h" | |
| 32 #include "version.h" | |
| 33 | |
| 34 #include "gntplugin.h" | |
|
21487
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
35 #include "gntrequest.h" |
| 15817 | 36 |
| 37 #define HISTORY_PLUGIN_ID "gnt-history" | |
| 38 | |
| 39 #define HISTORY_SIZE (4 * 1024) | |
| 40 | |
| 15822 | 41 static void historize(PurpleConversation *c) |
| 15817 | 42 { |
| 15822 | 43 PurpleAccount *account = purple_conversation_get_account(c); |
| 44 const char *name = purple_conversation_get_name(c); | |
| 45 PurpleConversationType convtype; | |
| 15817 | 46 GList *logs = NULL; |
| 47 const char *alias = name; | |
| 15822 | 48 PurpleLogReadFlags flags; |
| 15817 | 49 char *history; |
| 50 char *header; | |
| 15822 | 51 PurpleMessageFlags mflag; |
| 15817 | 52 |
| 15822 | 53 convtype = purple_conversation_get_type(c); |
| 54 if (convtype == PURPLE_CONV_TYPE_IM) | |
| 15817 | 55 { |
| 56 GSList *buddies; | |
| 57 GSList *cur; | |
| 58 | |
| 59 /* If we're not logging, don't show anything. | |
| 60 * 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
|
61 if (!purple_prefs_get_bool("/purple/logging/log_ims")) |
| 15817 | 62 return; |
| 63 | |
| 64 /* Find buddies for this conversation. */ | |
| 15822 | 65 buddies = purple_find_buddies(account, name); |
| 15817 | 66 |
| 67 /* If we found at least one buddy, save the first buddy's alias. */ | |
| 68 if (buddies != NULL) | |
| 15822 | 69 alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data); |
| 15817 | 70 |
| 71 for (cur = buddies; cur != NULL; cur = cur->next) | |
| 72 { | |
| 15822 | 73 PurpleBlistNode *node = cur->data; |
| 15817 | 74 if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) |
| 75 { | |
| 15822 | 76 PurpleBlistNode *node2; |
| 15817 | 77 |
| 15822 | 78 alias = purple_buddy_get_contact_alias((PurpleBuddy *)node); |
| 15817 | 79 |
| 80 /* We've found a buddy that matches this conversation. It's part of a | |
| 15822 | 81 * PurpleContact with more than one PurpleBuddy. Loop through the PurpleBuddies |
| 15817 | 82 * in the contact and get all the logs. */ |
| 83 for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next) | |
| 84 { | |
| 85 logs = g_list_concat( | |
| 15822 | 86 purple_log_get_logs(PURPLE_LOG_IM, |
| 87 purple_buddy_get_name((PurpleBuddy *)node2), | |
| 88 purple_buddy_get_account((PurpleBuddy *)node2)), | |
| 15817 | 89 logs); |
| 90 } | |
| 91 break; | |
| 92 } | |
| 93 } | |
| 94 g_slist_free(buddies); | |
| 95 | |
| 96 if (logs == NULL) | |
| 15822 | 97 logs = purple_log_get_logs(PURPLE_LOG_IM, name, account); |
| 15817 | 98 else |
| 15822 | 99 logs = g_list_sort(logs, purple_log_compare); |
| 15817 | 100 } |
| 15822 | 101 else if (convtype == PURPLE_CONV_TYPE_CHAT) |
| 15817 | 102 { |
| 103 /* If we're not logging, don't show anything. | |
| 104 * 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
|
105 if (!purple_prefs_get_bool("/purple/logging/log_chats")) |
| 15817 | 106 return; |
| 107 | |
| 15822 | 108 logs = purple_log_get_logs(PURPLE_LOG_CHAT, name, account); |
| 15817 | 109 } |
| 110 | |
| 111 if (logs == NULL) | |
| 112 return; | |
| 113 | |
| 15822 | 114 mflag = PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_DELAYED; |
| 115 history = purple_log_read((PurpleLog*)logs->data, &flags); | |
| 15817 | 116 |
| 117 header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), alias, | |
| 15822 | 118 purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time))); |
| 119 purple_conversation_write(c, "", header, mflag, time(NULL)); | |
| 15817 | 120 g_free(header); |
| 121 | |
| 15822 | 122 if (flags & PURPLE_LOG_READ_NO_NEWLINE) |
| 123 purple_str_strip_char(history, '\n'); | |
| 124 purple_conversation_write(c, "", history, mflag, time(NULL)); | |
| 15817 | 125 g_free(history); |
| 126 | |
| 15822 | 127 purple_conversation_write(c, "", "<hr>", mflag, time(NULL)); |
| 15817 | 128 |
| 15822 | 129 g_list_foreach(logs, (GFunc)purple_log_free, NULL); |
| 15817 | 130 g_list_free(logs); |
| 131 } | |
| 132 | |
| 133 static void | |
| 15822 | 134 history_prefs_check(PurplePlugin *plugin) |
| 15817 | 135 { |
|
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
|
136 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
|
137 !purple_prefs_get_bool("/purple/logging/log_chats")) |
| 15817 | 138 { |
|
21487
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
139 PurpleRequestFields *fields = purple_request_fields_new(); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
140 PurpleRequestFieldGroup *group; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
141 PurpleRequestField *field; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
142 struct { |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
143 const char *pref; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
144 const char *label; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
145 } prefs[] = { |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
146 {"/purple/logging/log_ims", N_("Log IMs")}, |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
147 {"/purple/logging/log_chats", N_("Log chats")}, |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
148 {NULL, NULL} |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
149 }; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
150 int iter; |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
151 GList *list = purple_log_logger_get_options(); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
152 const char *system = purple_prefs_get_string("/purple/logging/format"); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
153 |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
154 group = purple_request_field_group_new(_("Logging")); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
155 |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
156 field = purple_request_field_list_new("/purple/logging/format", _("Log format")); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
157 while (list) { |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
158 const char *label = _(list->data); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
159 list = g_list_delete_link(list, list); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
160 purple_request_field_list_add(field, label, list->data); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
161 if (system && strcmp(system, list->data) == 0) |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
162 purple_request_field_list_add_selected(field, label); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
163 list = g_list_delete_link(list, list); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
164 } |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
165 purple_request_field_group_add_field(group, field); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
166 |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
167 for (iter = 0; prefs[iter].pref; iter++) { |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
168 field = purple_request_field_bool_new(prefs[iter].pref, _(prefs[iter].label), |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
169 purple_prefs_get_bool(prefs[iter].pref)); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
170 purple_request_field_group_add_field(group, field); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
171 } |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
172 |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
173 purple_request_fields_add_group(fields, group); |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
174 |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
175 purple_request_fields_with_hint(plugin, NULL, _("History Plugin Requires Logging"), |
| 15817 | 176 _("Logging can be enabled from Tools -> Preferences -> Logging.\n\n" |
| 177 "Enabling logs for instant messages and/or chats will activate " | |
|
21487
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
178 "history for the same conversation type(s)."), |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
179 fields, |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
180 _("OK"), G_CALLBACK(finch_request_save_in_prefs), |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
181 _("Cancel"), NULL, |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
182 NULL, NULL, NULL, |
|
f2e42e09e635
Allow turning on logging when enabling the gnthistory plugin. (this doesn't
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21030
diff
changeset
|
183 "42. That's your hint. Take it, or leave it.", plugin); |
| 15817 | 184 } |
| 185 } | |
| 186 | |
| 15822 | 187 static void history_prefs_cb(const char *name, PurplePrefType type, |
| 15817 | 188 gconstpointer val, gpointer data) |
| 189 { | |
| 15822 | 190 history_prefs_check((PurplePlugin *)data); |
| 15817 | 191 } |
| 192 | |
| 193 static gboolean | |
| 15822 | 194 plugin_load(PurplePlugin *plugin) |
| 15817 | 195 { |
| 15822 | 196 purple_signal_connect(purple_conversations_get_handle(), |
| 15817 | 197 "conversation-created", |
| 15822 | 198 plugin, PURPLE_CALLBACK(historize), NULL); |
| 15817 | 199 |
|
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
|
200 purple_prefs_connect_callback(plugin, "/purple/logging/log_ims", |
| 15817 | 201 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
|
202 purple_prefs_connect_callback(plugin, "/purple/logging/log_chats", |
| 15817 | 203 history_prefs_cb, plugin); |
| 204 | |
| 205 history_prefs_check(plugin); | |
| 206 | |
| 207 return TRUE; | |
| 208 } | |
| 209 | |
| 15822 | 210 static PurplePluginInfo info = |
| 15817 | 211 { |
| 15822 | 212 PURPLE_PLUGIN_MAGIC, |
| 213 PURPLE_MAJOR_VERSION, | |
| 214 PURPLE_MINOR_VERSION, | |
| 215 PURPLE_PLUGIN_STANDARD, | |
| 15817 | 216 NULL, |
| 217 0, | |
| 218 NULL, | |
| 15822 | 219 PURPLE_PRIORITY_DEFAULT, |
| 15817 | 220 HISTORY_PLUGIN_ID, |
| 221 N_("GntHistory"), | |
|
21030
3cc856ca2338
Add a --with-extraversion option to ./configure so packagers can fine tune
Stu Tomlinson <stu@nosnilmot.com>
parents:
19681
diff
changeset
|
222 DISPLAY_VERSION, |
| 15817 | 223 N_("Shows recently logged conversations in new conversations."), |
| 224 N_("When a new conversation is opened this plugin will insert " | |
| 225 "the last conversation into the current conversation."), | |
| 226 "Sean Egan <seanegan@gmail.com>\n" | |
| 227 "Sadrul H Chowdhury <sadrul@users.sourceforge.net>", | |
| 15822 | 228 PURPLE_WEBSITE, |
| 15817 | 229 plugin_load, |
| 230 NULL, | |
| 231 NULL, | |
| 232 NULL, | |
| 233 NULL, | |
| 234 NULL, | |
|
16669
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
235 NULL, |
|
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
236 |
|
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
237 /* padding */ |
|
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
238 NULL, |
|
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
239 NULL, |
|
30829e806dae
And finch is up to date
Gary Kramlich <grim@reaperworld.com>
parents:
16424
diff
changeset
|
240 NULL, |
| 15817 | 241 NULL |
| 242 }; | |
| 243 | |
| 244 static void | |
| 15822 | 245 init_plugin(PurplePlugin *plugin) |
| 15817 | 246 { |
| 247 } | |
| 248 | |
| 15822 | 249 PURPLE_INIT_PLUGIN(gnthistory, init_plugin, info) |
| 15817 | 250 |
