Mercurial > pidgin.yaz
comparison pidgin/gtklog.c @ 15374:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | 29e443e0613f |
comparison
equal
deleted
inserted
replaced
15373:f79e0f4df793 | 15374:5fe8042783c1 |
---|---|
1 /** | |
2 * @file gtklog.c GTK+ Log viewer | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include "internal.h" | |
26 #include "gtkgaim.h" | |
27 | |
28 #include "account.h" | |
29 #include "gtkblist.h" | |
30 #include "gtkimhtml.h" | |
31 #include "gtklog.h" | |
32 #include "gtkutils.h" | |
33 #include "log.h" | |
34 #include "notify.h" | |
35 #include "util.h" | |
36 | |
37 static GHashTable *log_viewers = NULL; | |
38 static void populate_log_tree(GaimGtkLogViewer *lv); | |
39 static GaimGtkLogViewer *syslog_viewer = NULL; | |
40 | |
41 struct log_viewer_hash_t { | |
42 GaimLogType type; | |
43 char *screenname; | |
44 GaimAccount *account; | |
45 GaimContact *contact; | |
46 }; | |
47 | |
48 static guint log_viewer_hash(gconstpointer data) | |
49 { | |
50 const struct log_viewer_hash_t *viewer = data; | |
51 | |
52 if (viewer->contact != NULL) | |
53 return g_direct_hash(viewer->contact); | |
54 | |
55 return g_str_hash(viewer->screenname) + | |
56 g_str_hash(gaim_account_get_username(viewer->account)); | |
57 } | |
58 | |
59 static gboolean log_viewer_equal(gconstpointer y, gconstpointer z) | |
60 { | |
61 const struct log_viewer_hash_t *a, *b; | |
62 int ret; | |
63 char *normal; | |
64 | |
65 a = y; | |
66 b = z; | |
67 | |
68 if (a->contact != NULL) { | |
69 if (b->contact != NULL) | |
70 return (a->contact == b->contact); | |
71 else | |
72 return FALSE; | |
73 } else { | |
74 if (b->contact != NULL) | |
75 return FALSE; | |
76 } | |
77 | |
78 normal = g_strdup(gaim_normalize(a->account, a->screenname)); | |
79 ret = (a->account == b->account) && | |
80 !strcmp(normal, gaim_normalize(b->account, b->screenname)); | |
81 g_free(normal); | |
82 | |
83 return ret; | |
84 } | |
85 | |
86 static void select_first_log(GaimGtkLogViewer *lv) | |
87 { | |
88 GtkTreeModel *model; | |
89 GtkTreeIter iter, it; | |
90 GtkTreePath *path; | |
91 | |
92 model = GTK_TREE_MODEL(lv->treestore); | |
93 | |
94 if (!gtk_tree_model_get_iter_first(model, &iter)) | |
95 return; | |
96 | |
97 path = gtk_tree_model_get_path(model, &iter); | |
98 if (gtk_tree_model_iter_children(model, &it, &iter)) | |
99 { | |
100 gtk_tree_view_expand_row(GTK_TREE_VIEW(lv->treeview), path, TRUE); | |
101 path = gtk_tree_model_get_path(model, &it); | |
102 } | |
103 | |
104 gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(lv->treeview)), path); | |
105 | |
106 gtk_tree_path_free(path); | |
107 } | |
108 | |
109 static const char *log_get_date(GaimLog *log) | |
110 { | |
111 if (log->tm) | |
112 return gaim_date_format_full(log->tm); | |
113 else | |
114 return gaim_date_format_full(localtime(&log->time)); | |
115 } | |
116 | |
117 static void search_cb(GtkWidget *button, GaimGtkLogViewer *lv) | |
118 { | |
119 const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry)); | |
120 GList *logs; | |
121 | |
122 if (!(*search_term)) { | |
123 /* reset the tree */ | |
124 gtk_tree_store_clear(lv->treestore); | |
125 populate_log_tree(lv); | |
126 g_free(lv->search); | |
127 lv->search = NULL; | |
128 gtk_imhtml_search_clear(GTK_IMHTML(lv->imhtml)); | |
129 select_first_log(lv); | |
130 return; | |
131 } | |
132 | |
133 if (lv->search != NULL && !strcmp(lv->search, search_term)) | |
134 { | |
135 /* Searching for the same term acts as "Find Next" */ | |
136 gtk_imhtml_search_find(GTK_IMHTML(lv->imhtml), lv->search); | |
137 return; | |
138 } | |
139 | |
140 gaim_gtk_set_cursor(lv->window, GDK_WATCH); | |
141 | |
142 g_free(lv->search); | |
143 lv->search = g_strdup(search_term); | |
144 | |
145 gtk_tree_store_clear(lv->treestore); | |
146 gtk_imhtml_clear(GTK_IMHTML(lv->imhtml)); | |
147 | |
148 for (logs = lv->logs; logs != NULL; logs = logs->next) { | |
149 char *read = gaim_log_read((GaimLog*)logs->data, NULL); | |
150 if (read && *read && gaim_strcasestr(read, search_term)) { | |
151 GtkTreeIter iter; | |
152 GaimLog *log = logs->data; | |
153 | |
154 gtk_tree_store_append (lv->treestore, &iter, NULL); | |
155 gtk_tree_store_set(lv->treestore, &iter, | |
156 0, log_get_date(log), | |
157 1, log, -1); | |
158 } | |
159 g_free(read); | |
160 } | |
161 | |
162 select_first_log(lv); | |
163 gaim_gtk_clear_cursor(lv->window); | |
164 } | |
165 | |
166 static void destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) { | |
167 GaimGtkLogViewer *lv = syslog_viewer; | |
168 | |
169 #ifdef _WIN32 | |
170 if (resp == GTK_RESPONSE_HELP) { | |
171 char *logdir = g_build_filename(gaim_user_dir(), "logs", NULL); | |
172 gtkwgaim_shell_execute(logdir, "explore", NULL); | |
173 g_free(logdir); | |
174 return; | |
175 } | |
176 #endif | |
177 | |
178 if (ht != NULL) { | |
179 lv = g_hash_table_lookup(log_viewers, ht); | |
180 g_hash_table_remove(log_viewers, ht); | |
181 | |
182 g_free(ht->screenname); | |
183 g_free(ht); | |
184 } else | |
185 syslog_viewer = NULL; | |
186 | |
187 g_list_foreach(lv->logs, (GFunc)gaim_log_free, NULL); | |
188 g_list_free(lv->logs); | |
189 | |
190 g_free(lv->search); | |
191 g_free(lv); | |
192 | |
193 gtk_widget_destroy(w); | |
194 } | |
195 | |
196 static void log_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, GaimGtkLogViewer *viewer) { | |
197 if (gtk_tree_view_row_expanded(tv, path)) | |
198 gtk_tree_view_collapse_row(tv, path); | |
199 else | |
200 gtk_tree_view_expand_row(tv, path, FALSE); | |
201 } | |
202 | |
203 static gboolean search_find_cb(gpointer data) | |
204 { | |
205 GaimGtkLogViewer *viewer = data; | |
206 gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search); | |
207 return FALSE; | |
208 } | |
209 | |
210 static void log_select_cb(GtkTreeSelection *sel, GaimGtkLogViewer *viewer) { | |
211 GtkTreeIter iter; | |
212 GValue val; | |
213 GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore); | |
214 GaimLog *log = NULL; | |
215 GaimLogReadFlags flags; | |
216 char *read = NULL; | |
217 | |
218 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) | |
219 return; | |
220 | |
221 val.g_type = 0; | |
222 gtk_tree_model_get_value (model, &iter, 1, &val); | |
223 log = g_value_get_pointer(&val); | |
224 g_value_unset(&val); | |
225 | |
226 if (log == NULL) | |
227 return; | |
228 | |
229 gaim_gtk_set_cursor(viewer->window, GDK_WATCH); | |
230 | |
231 if (log->type != GAIM_LOG_SYSTEM) { | |
232 char *title; | |
233 if (log->type == GAIM_LOG_CHAT) | |
234 title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation in %s on %s</span>"), | |
235 log->name, log_get_date(log)); | |
236 else | |
237 title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation with %s on %s</span>"), | |
238 log->name, log_get_date(log)); | |
239 | |
240 gtk_label_set_markup(GTK_LABEL(viewer->label), title); | |
241 g_free(title); | |
242 } | |
243 | |
244 read = gaim_log_read(log, &flags); | |
245 viewer->flags = flags; | |
246 | |
247 gtk_imhtml_clear(GTK_IMHTML(viewer->imhtml)); | |
248 gtk_imhtml_set_protocol_name(GTK_IMHTML(viewer->imhtml), | |
249 gaim_account_get_protocol_name(log->account)); | |
250 | |
251 gaim_signal_emit(gaim_gtk_log_get_handle(), "log-displaying", viewer, log); | |
252 | |
253 gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read, | |
254 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL | | |
255 ((flags & GAIM_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0)); | |
256 g_free(read); | |
257 | |
258 if (viewer->search != NULL) { | |
259 gtk_imhtml_search_clear(GTK_IMHTML(viewer->imhtml)); | |
260 g_idle_add(search_find_cb, viewer); | |
261 } | |
262 | |
263 gaim_gtk_clear_cursor(viewer->window); | |
264 } | |
265 | |
266 /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet. | |
267 * I want the tree to be divided into groups like "Today," "Yesterday," "Last week," | |
268 * "August," "2002," etc. based on how many conversation took place in each subdivision. | |
269 * | |
270 * For now, I'll just make it a flat list. | |
271 */ | |
272 static void populate_log_tree(GaimGtkLogViewer *lv) | |
273 /* Logs are made from trees in real life. | |
274 This is a tree made from logs */ | |
275 { | |
276 const char *month; | |
277 char prev_top_month[30] = ""; | |
278 GtkTreeIter toplevel, child; | |
279 GList *logs = lv->logs; | |
280 | |
281 while (logs != NULL) { | |
282 GaimLog *log = logs->data; | |
283 | |
284 month = gaim_utf8_strftime(_("%B %Y"), | |
285 log->tm ? log->tm : localtime(&log->time)); | |
286 | |
287 if (strcmp(month, prev_top_month) != 0) | |
288 { | |
289 /* top level */ | |
290 gtk_tree_store_append(lv->treestore, &toplevel, NULL); | |
291 gtk_tree_store_set(lv->treestore, &toplevel, 0, month, 1, NULL, -1); | |
292 | |
293 strncpy(prev_top_month, month, sizeof(prev_top_month)); | |
294 } | |
295 | |
296 /* sub */ | |
297 gtk_tree_store_append(lv->treestore, &child, &toplevel); | |
298 gtk_tree_store_set(lv->treestore, &child, | |
299 0, log_get_date(log), | |
300 1, log, | |
301 -1); | |
302 | |
303 logs = logs->next; | |
304 } | |
305 } | |
306 | |
307 static GaimGtkLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, GList *logs, | |
308 const char *title, GdkPixbuf *pixbuf, int log_size) | |
309 { | |
310 GaimGtkLogViewer *lv; | |
311 GtkWidget *title_box; | |
312 char *text; | |
313 GtkWidget *pane; | |
314 GtkWidget *sw; | |
315 GtkCellRenderer *rend; | |
316 GtkTreeViewColumn *col; | |
317 GtkTreeSelection *sel; | |
318 GtkWidget *vbox; | |
319 GtkWidget *frame; | |
320 GtkWidget *hbox; | |
321 GtkWidget *find_button; | |
322 GtkWidget *size_label; | |
323 | |
324 if (logs == NULL) | |
325 { | |
326 /* No logs were found. */ | |
327 const char *log_preferences = NULL; | |
328 | |
329 if (ht == NULL) { | |
330 if (!gaim_prefs_get_bool("/core/logging/log_system")) | |
331 log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled."); | |
332 } else { | |
333 if (ht->type == GAIM_LOG_IM) { | |
334 if (!gaim_prefs_get_bool("/core/logging/log_ims")) | |
335 log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled."); | |
336 } else if (ht->type == GAIM_LOG_CHAT) { | |
337 if (!gaim_prefs_get_bool("/core/logging/log_chats")) | |
338 log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled."); | |
339 } | |
340 } | |
341 | |
342 gaim_notify_info(NULL, title, _("No logs were found"), log_preferences); | |
343 return NULL; | |
344 } | |
345 | |
346 lv = g_new0(GaimGtkLogViewer, 1); | |
347 lv->logs = logs; | |
348 | |
349 if (ht != NULL) | |
350 g_hash_table_insert(log_viewers, ht, lv); | |
351 | |
352 /* Window ***********/ | |
353 lv->window = gtk_dialog_new_with_buttons(title, NULL, 0, | |
354 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | |
355 #ifdef _WIN32 | |
356 /* Steal the "HELP" response and use it to trigger browsing to the logs folder */ | |
357 gtk_dialog_add_button(GTK_DIALOG(lv->window), _("_Browse logs folder"), GTK_RESPONSE_HELP); | |
358 #endif | |
359 gtk_container_set_border_width (GTK_CONTAINER(lv->window), GAIM_HIG_BOX_SPACE); | |
360 gtk_dialog_set_has_separator(GTK_DIALOG(lv->window), FALSE); | |
361 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(lv->window)->vbox), 0); | |
362 g_signal_connect(G_OBJECT(lv->window), "response", | |
363 G_CALLBACK(destroy_cb), ht); | |
364 gtk_window_set_role(GTK_WINDOW(lv->window), "log_viewer"); | |
365 | |
366 /* Icon *************/ | |
367 if (pixbuf != NULL) { | |
368 GdkPixbuf *scale; | |
369 GtkWidget *icon; | |
370 | |
371 title_box = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
372 gtk_container_set_border_width(GTK_CONTAINER(title_box), GAIM_HIG_BOX_SPACE); | |
373 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), title_box, FALSE, FALSE, 0); | |
374 | |
375 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
376 icon = gtk_image_new_from_pixbuf(scale); | |
377 gtk_box_pack_start(GTK_BOX(title_box), icon, FALSE, FALSE, 0); | |
378 g_object_unref(G_OBJECT(pixbuf)); | |
379 g_object_unref(G_OBJECT(scale)); | |
380 } else | |
381 title_box = GTK_DIALOG(lv->window)->vbox; | |
382 | |
383 /* Label ************/ | |
384 lv->label = gtk_label_new(NULL); | |
385 | |
386 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>", title); | |
387 | |
388 gtk_label_set_markup(GTK_LABEL(lv->label), text); | |
389 gtk_misc_set_alignment(GTK_MISC(lv->label), 0, 0); | |
390 gtk_box_pack_start(GTK_BOX(title_box), lv->label, FALSE, FALSE, 0); | |
391 g_free(text); | |
392 | |
393 /* Pane *************/ | |
394 pane = gtk_hpaned_new(); | |
395 gtk_container_set_border_width(GTK_CONTAINER(pane), GAIM_HIG_BOX_SPACE); | |
396 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), pane, TRUE, TRUE, 0); | |
397 | |
398 /* List *************/ | |
399 sw = gtk_scrolled_window_new (NULL, NULL); | |
400 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); | |
401 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
402 gtk_paned_add1(GTK_PANED(pane), sw); | |
403 lv->treestore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); | |
404 lv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (lv->treestore)); | |
405 rend = gtk_cell_renderer_text_new(); | |
406 col = gtk_tree_view_column_new_with_attributes ("time", rend, "markup", 0, NULL); | |
407 gtk_tree_view_append_column (GTK_TREE_VIEW(lv->treeview), col); | |
408 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (lv->treeview), FALSE); | |
409 gtk_container_add (GTK_CONTAINER (sw), lv->treeview); | |
410 | |
411 populate_log_tree(lv); | |
412 | |
413 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (lv->treeview)); | |
414 g_signal_connect (G_OBJECT (sel), "changed", | |
415 G_CALLBACK (log_select_cb), | |
416 lv); | |
417 g_signal_connect (G_OBJECT(lv->treeview), "row-activated", | |
418 G_CALLBACK(log_row_activated_cb), | |
419 lv); | |
420 gaim_set_accessible_label(lv->treeview, lv->label); | |
421 | |
422 /* Log size ************/ | |
423 if(log_size) { | |
424 char *sz_txt = gaim_str_size_to_units(log_size); | |
425 text = g_strdup_printf("<span weight='bold'>%s</span> %s", _("Total log size:"), sz_txt); | |
426 size_label = gtk_label_new(NULL); | |
427 gtk_label_set_markup(GTK_LABEL(size_label), text); | |
428 /* gtk_paned_add1(GTK_PANED(pane), size_label); */ | |
429 gtk_misc_set_alignment(GTK_MISC(size_label), 0, 0); | |
430 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(lv->window)->vbox), size_label, FALSE, FALSE, 0); | |
431 g_free(sz_txt); | |
432 g_free(text); | |
433 } | |
434 | |
435 /* A fancy little box ************/ | |
436 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
437 gtk_paned_add2(GTK_PANED(pane), vbox); | |
438 | |
439 /* Viewer ************/ | |
440 frame = gaim_gtk_create_imhtml(FALSE, &lv->imhtml, NULL, NULL); | |
441 gtk_widget_set_name(lv->imhtml, "gaim_gtklog_imhtml"); | |
442 gtk_widget_set_size_request(lv->imhtml, 320, 200); | |
443 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
444 gtk_widget_show(frame); | |
445 | |
446 /* Search box **********/ | |
447 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
448 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
449 lv->entry = gtk_entry_new(); | |
450 gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0); | |
451 find_button = gtk_button_new_from_stock(GTK_STOCK_FIND); | |
452 gtk_box_pack_start(GTK_BOX(hbox), find_button, FALSE, FALSE, 0); | |
453 g_signal_connect(GTK_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv); | |
454 g_signal_connect(GTK_BUTTON(find_button), "clicked", G_CALLBACK(search_cb), lv); | |
455 | |
456 select_first_log(lv); | |
457 | |
458 gtk_widget_show_all(lv->window); | |
459 | |
460 return lv; | |
461 } | |
462 | |
463 void gaim_gtk_log_show(GaimLogType type, const char *screenname, GaimAccount *account) { | |
464 struct log_viewer_hash_t *ht; | |
465 GaimGtkLogViewer *lv = NULL; | |
466 const char *name = screenname; | |
467 char *title; | |
468 | |
469 g_return_if_fail(account != NULL); | |
470 g_return_if_fail(screenname != NULL); | |
471 | |
472 ht = g_new0(struct log_viewer_hash_t, 1); | |
473 | |
474 ht->type = type; | |
475 ht->screenname = g_strdup(screenname); | |
476 ht->account = account; | |
477 | |
478 if (log_viewers == NULL) { | |
479 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal); | |
480 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) { | |
481 gtk_window_present(GTK_WINDOW(lv->window)); | |
482 g_free(ht->screenname); | |
483 g_free(ht); | |
484 return; | |
485 } | |
486 | |
487 if (type == GAIM_LOG_CHAT) { | |
488 GaimChat *chat; | |
489 | |
490 chat = gaim_blist_find_chat(account, screenname); | |
491 if (chat != NULL) | |
492 name = gaim_chat_get_name(chat); | |
493 | |
494 title = g_strdup_printf(_("Conversations in %s"), name); | |
495 } else { | |
496 GaimBuddy *buddy; | |
497 | |
498 buddy = gaim_find_buddy(account, screenname); | |
499 if (buddy != NULL) | |
500 name = gaim_buddy_get_contact_alias(buddy); | |
501 | |
502 title = g_strdup_printf(_("Conversations with %s"), name); | |
503 } | |
504 | |
505 display_log_viewer(ht, gaim_log_get_logs(type, screenname, account), | |
506 title, gaim_gtk_create_prpl_icon(account, 0.5), gaim_log_get_total_size(type, screenname, account)); | |
507 g_free(title); | |
508 } | |
509 | |
510 void gaim_gtk_log_show_contact(GaimContact *contact) { | |
511 struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1); | |
512 GaimBlistNode *child; | |
513 GaimGtkLogViewer *lv = NULL; | |
514 GList *logs = NULL; | |
515 char *filename; | |
516 GdkPixbuf *pixbuf; | |
517 const char *name = NULL; | |
518 char *title; | |
519 int total_log_size = 0; | |
520 | |
521 g_return_if_fail(contact != NULL); | |
522 | |
523 ht->type = GAIM_LOG_IM; | |
524 ht->contact = contact; | |
525 | |
526 if (log_viewers == NULL) { | |
527 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal); | |
528 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) { | |
529 gtk_window_present(GTK_WINDOW(lv->window)); | |
530 g_free(ht); | |
531 return; | |
532 } | |
533 | |
534 for (child = contact->node.child ; child ; child = child->next) { | |
535 if (!GAIM_BLIST_NODE_IS_BUDDY(child)) | |
536 continue; | |
537 | |
538 logs = g_list_concat(gaim_log_get_logs(GAIM_LOG_IM, ((GaimBuddy *)child)->name, | |
539 ((GaimBuddy *)child)->account), logs); | |
540 total_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy *)child)->name, ((GaimBuddy *)child)->account); | |
541 } | |
542 logs = g_list_sort(logs, gaim_log_compare); | |
543 | |
544 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
545 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
546 g_free(filename); | |
547 | |
548 if (contact->alias != NULL) | |
549 name = contact->alias; | |
550 else if (contact->priority != NULL) | |
551 name = gaim_buddy_get_contact_alias(contact->priority); | |
552 | |
553 title = g_strdup_printf(_("Conversations with %s"), name); | |
554 display_log_viewer(ht, logs, title, pixbuf, total_log_size); | |
555 g_free(title); | |
556 } | |
557 | |
558 void gaim_gtk_syslog_show() | |
559 { | |
560 GList *accounts = NULL; | |
561 GList *logs = NULL; | |
562 | |
563 if (syslog_viewer != NULL) { | |
564 gtk_window_present(GTK_WINDOW(syslog_viewer->window)); | |
565 return; | |
566 } | |
567 | |
568 for(accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { | |
569 | |
570 GaimAccount *account = (GaimAccount *)accounts->data; | |
571 if(gaim_find_prpl(gaim_account_get_protocol_id(account)) == NULL) | |
572 continue; | |
573 | |
574 logs = g_list_concat(gaim_log_get_system_logs(account), logs); | |
575 } | |
576 logs = g_list_sort(logs, gaim_log_compare); | |
577 | |
578 syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), NULL, 0); | |
579 } | |
580 | |
581 /**************************************************************************** | |
582 * GTK+ LOG SUBSYSTEM ******************************************************* | |
583 ****************************************************************************/ | |
584 | |
585 void * | |
586 gaim_gtk_log_get_handle(void) | |
587 { | |
588 static int handle; | |
589 | |
590 return &handle; | |
591 } | |
592 | |
593 void gaim_gtk_log_init(void) | |
594 { | |
595 void *handle = gaim_gtk_log_get_handle(); | |
596 | |
597 gaim_signal_register(handle, "log-displaying", | |
598 gaim_marshal_VOID__POINTER_POINTER, | |
599 NULL, 2, | |
600 gaim_value_new(GAIM_TYPE_BOXED, | |
601 "GaimGtkLogViewer *"), | |
602 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
603 GAIM_SUBTYPE_LOG)); | |
604 } | |
605 | |
606 void | |
607 gaim_gtk_log_uninit(void) | |
608 { | |
609 gaim_signals_unregister_by_instance(gaim_gtk_log_get_handle()); | |
610 } |