Mercurial > pidgin
annotate src/gtklog.c @ 13434:ffd724befbf8
[gaim-migrate @ 15809]
Cleanup the busy cursor handling code to eliminate a bunch of these loops:
while (gtk_events_pending())
gtk_main_iteration();
They seem like a race condition waiting to happen. This code is also simpler,
and more generic.
This leaves only one such loop, in src/gtkblist.c's gaim_gtk_blist_expand_contact_cb().
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 07 Mar 2006 05:48:54 +0000 |
parents | 3de53fe8345f |
children | 6034444bbcf5 |
rev | line source |
---|---|
7432 | 1 /** |
2 * @file gtklog.c GTK+ Log viewer | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
8046 | 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. | |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
10 * |
7432 | 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 */ | |
9791 | 25 #include "internal.h" |
26 #include "gtkgaim.h" | |
7432 | 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" | |
11769 | 34 #include "notify.h" |
10636 | 35 #include "util.h" |
7432 | 36 |
37 static GHashTable *log_viewers = NULL; | |
7535 | 38 static void populate_log_tree(GaimGtkLogViewer *lv); |
8573 | 39 static GaimGtkLogViewer *syslog_viewer = NULL; |
7432 | 40 |
41 struct log_viewer_hash_t { | |
10663 | 42 GaimLogType type; |
7432 | 43 char *screenname; |
44 GaimAccount *account; | |
10663 | 45 GaimContact *contact; |
7432 | 46 }; |
47 | |
7440 | 48 static guint log_viewer_hash(gconstpointer data) |
7432 | 49 { |
7440 | 50 const struct log_viewer_hash_t *viewer = data; |
51 | |
10663 | 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)); | |
7432 | 57 } |
58 | |
10663 | 59 static gboolean log_viewer_equal(gconstpointer y, gconstpointer z) |
7432 | 60 { |
7440 | 61 const struct log_viewer_hash_t *a, *b; |
7432 | 62 int ret; |
7440 | 63 char *normal; |
64 | |
65 a = y; | |
66 b = z; | |
67 | |
10663 | 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 | |
7440 | 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)); | |
7432 | 81 g_free(normal); |
10663 | 82 |
7432 | 83 return ret; |
84 } | |
85 | |
7535 | 86 static void search_cb(GtkWidget *button, GaimGtkLogViewer *lv) |
87 { | |
88 const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry)); | |
89 GList *logs; | |
10175 | 90 |
10663 | 91 if (lv->search != NULL) |
7535 | 92 g_free(lv->search); |
10175 | 93 |
11585 | 94 gtk_tree_store_clear(lv->treestore); |
12232
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
95 if (!(*search_term)) { |
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
96 /* reset the tree */ |
7535 | 97 populate_log_tree(lv); |
98 lv->search = NULL; | |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
99 gtk_imhtml_search_clear(GTK_IMHTML(lv->imhtml)); |
7535 | 100 return; |
101 } | |
10175 | 102 |
7535 | 103 lv->search = g_strdup(search_term); |
10175 | 104 |
13434
ffd724befbf8
[gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents:
13280
diff
changeset
|
105 gaim_gtk_set_cursor(lv->window, GDK_WATCH); |
10175 | 106 |
7535 | 107 for (logs = lv->logs; logs != NULL; logs = logs->next) { |
108 char *read = gaim_log_read((GaimLog*)logs->data, NULL); | |
12232
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
109 if (read && *read && gaim_strcasestr(read, search_term)) { |
7535 | 110 GtkTreeIter iter; |
111 GaimLog *log = logs->data; | |
12232
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
112 |
7535 | 113 gtk_tree_store_append (lv->treestore, &iter, NULL); |
114 gtk_tree_store_set(lv->treestore, &iter, | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
115 0, gaim_date_format_full(localtime(&log->time)), |
10175 | 116 1, log, -1); |
7535 | 117 } |
10574 | 118 g_free(read); |
7535 | 119 } |
10175 | 120 |
13434
ffd724befbf8
[gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents:
13280
diff
changeset
|
121 gaim_gtk_clear_cursor(lv->window); |
7535 | 122 } |
123 | |
7454 | 124 static gboolean destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) { |
8573 | 125 GaimGtkLogViewer *lv = syslog_viewer; |
7454 | 126 |
10663 | 127 if (ht != NULL) { |
8573 | 128 lv = g_hash_table_lookup(log_viewers, ht); |
129 g_hash_table_remove(log_viewers, ht); | |
10663 | 130 |
131 if (ht->screenname != NULL) | |
132 g_free(ht->screenname); | |
133 | |
8573 | 134 g_free(ht); |
135 } else | |
136 syslog_viewer = NULL; | |
137 | |
10663 | 138 while (lv->logs != NULL) { |
7535 | 139 GList *logs2; |
10663 | 140 |
141 gaim_log_free((GaimLog *)lv->logs->data); | |
142 | |
7535 | 143 logs2 = lv->logs->next; |
144 g_list_free_1(lv->logs); | |
145 lv->logs = logs2; | |
7533 | 146 } |
10663 | 147 |
148 if (lv->search != NULL) | |
7535 | 149 g_free(lv->search); |
10663 | 150 |
8573 | 151 g_free(lv); |
7454 | 152 gtk_widget_destroy(w); |
153 | |
154 return TRUE; | |
155 } | |
156 | |
10663 | 157 static void log_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, GaimGtkLogViewer *viewer) { |
158 if (gtk_tree_view_row_expanded(tv, path)) | |
159 gtk_tree_view_collapse_row(tv, path); | |
160 else | |
161 gtk_tree_view_expand_row(tv, path, FALSE); | |
8573 | 162 } |
10663 | 163 |
7454 | 164 static void log_select_cb(GtkTreeSelection *sel, GaimGtkLogViewer *viewer) { |
12838
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
165 GtkTreeIter iter; |
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12232
diff
changeset
|
166 GValue val; |
7432 | 167 GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore); |
168 GaimLog *log = NULL; | |
169 GaimLogReadFlags flags; | |
170 char *read = NULL; | |
171 | |
10663 | 172 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) |
7432 | 173 return; |
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12232
diff
changeset
|
174 |
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12232
diff
changeset
|
175 val.g_type = 0; |
7432 | 176 gtk_tree_model_get_value (model, &iter, 1, &val); |
177 log = g_value_get_pointer(&val); | |
178 g_value_unset(&val); | |
179 | |
10663 | 180 if (log == NULL) |
7432 | 181 return; |
182 | |
13434
ffd724befbf8
[gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents:
13280
diff
changeset
|
183 gaim_gtk_set_cursor(viewer->window, GDK_WATCH); |
12232
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
184 |
10663 | 185 if (log->type != GAIM_LOG_SYSTEM) { |
186 char *title; | |
187 if (log->type == GAIM_LOG_CHAT) | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
188 title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation in %s on %s</span>"), |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
189 log->name, |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
190 log->tm ? gaim_date_format_full(log->tm) : |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
191 gaim_date_format_full(localtime(&log->time))); |
10663 | 192 else |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
193 title = g_strdup_printf(_("<span size='larger' weight='bold'>Conversation with %s on %s</span>"), |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
194 log->name, |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
195 log->tm ? gaim_date_format_full(log->tm) : |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
196 gaim_date_format_full(localtime(&log->time))); |
10663 | 197 |
198 gtk_label_set_markup(GTK_LABEL(viewer->label), title); | |
199 g_free(title); | |
200 } | |
201 | |
7432 | 202 read = gaim_log_read(log, &flags); |
203 viewer->flags = flags; | |
10663 | 204 |
7432 | 205 gtk_imhtml_clear(GTK_IMHTML(viewer->imhtml)); |
10645 | 206 gtk_imhtml_set_protocol_name(GTK_IMHTML(viewer->imhtml), |
207 gaim_account_get_protocol_name(log->account)); | |
12838
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
208 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
209 gaim_signal_emit(gaim_gtk_log_get_handle(), "log-displaying", viewer, log); |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
210 |
10574 | 211 gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read, |
10175 | 212 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL | |
7432 | 213 ((flags & GAIM_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0)); |
12232
375f1f3817a8
[gaim-migrate @ 14534]
Richard Laager <rlaager@wiktel.com>
parents:
11869
diff
changeset
|
214 g_free(read); |
7535 | 215 |
10663 | 216 if (viewer->search != NULL) { |
10574 | 217 gtk_imhtml_search_clear(GTK_IMHTML(viewer->imhtml)); |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
218 gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search); |
10574 | 219 } |
10175 | 220 |
13434
ffd724befbf8
[gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents:
13280
diff
changeset
|
221 gaim_gtk_clear_cursor(viewer->window); |
7432 | 222 } |
223 | |
224 /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet. | |
225 * I want the tree to be divided into groups like "Today," "Yesterday," "Last week," | |
226 * "August," "2002," etc. based on how many conversation took place in each subdivision. | |
227 * | |
228 * For now, I'll just make it a flat list. | |
229 */ | |
230 static void populate_log_tree(GaimGtkLogViewer *lv) | |
11585 | 231 /* Logs are made from trees in real life. |
7432 | 232 This is a tree made from logs */ |
233 { | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
234 const char *month; |
10663 | 235 char prev_top_month[30] = ""; |
9435 | 236 GtkTreeIter toplevel, child; |
7432 | 237 GList *logs = lv->logs; |
10663 | 238 |
239 while (logs != NULL) { | |
7432 | 240 GaimLog *log = logs->data; |
10175 | 241 |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
242 month = gaim_utf8_strftime(_("%B %Y"), |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
243 log->tm ? log->tm : localtime(&log->time)); |
10175 | 244 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
245 if (strcmp(month, prev_top_month) != 0) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
246 { |
9435 | 247 /* top level */ |
248 gtk_tree_store_append(lv->treestore, &toplevel, NULL); | |
249 gtk_tree_store_set(lv->treestore, &toplevel, 0, month, 1, NULL, -1); | |
10175 | 250 |
10680 | 251 strncpy(prev_top_month, month, sizeof(prev_top_month)); |
252 } | |
10175 | 253 |
10680 | 254 /* sub */ |
255 gtk_tree_store_append(lv->treestore, &child, &toplevel); | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
256 gtk_tree_store_set(lv->treestore, &child, |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
257 0, log->tm ? gaim_date_format_full(log->tm) : gaim_date_format_full(localtime(&log->time)), |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
258 1, log, |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
259 -1); |
10175 | 260 |
7432 | 261 logs = logs->next; |
262 } | |
263 } | |
264 | |
10663 | 265 static GaimGtkLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, GList *logs, |
11585 | 266 const char *title, GdkPixbuf *pixbuf, int log_size) |
10663 | 267 { |
268 GaimGtkLogViewer *lv; | |
269 GtkWidget *title_box; | |
270 char *text; | |
11769 | 271 GtkWidget *pane; |
272 GtkWidget *sw; | |
273 GtkCellRenderer *rend; | |
274 GtkTreeViewColumn *col; | |
275 GtkTreeSelection *sel; | |
11780 | 276 #if GTK_CHECK_VERSION(2,2,0) |
11769 | 277 GtkTreePath *path_to_first_log; |
11780 | 278 #endif |
11769 | 279 GtkWidget *vbox; |
280 GtkWidget *frame; | |
281 GtkWidget *hbox; | |
282 GtkWidget *button; | |
283 GtkWidget *size_label; | |
7432 | 284 |
285 lv = g_new0(GaimGtkLogViewer, 1); | |
10663 | 286 lv->logs = logs; |
287 | |
11769 | 288 if (logs == NULL) |
289 { | |
290 /* No logs were found. */ | |
291 const char *log_preferences = NULL; | |
292 | |
293 if (ht == NULL) { | |
294 if (!gaim_prefs_get_bool("/core/logging/log_system")) | |
295 log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled."); | |
296 } else { | |
297 if (ht->type == GAIM_LOG_IM) { | |
298 if (!gaim_prefs_get_bool("/core/logging/log_ims")) | |
299 log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled."); | |
300 } else if (ht->type == GAIM_LOG_CHAT) { | |
301 if (!gaim_prefs_get_bool("/core/logging/log_chats")) | |
11869 | 302 log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled."); |
11769 | 303 } |
304 } | |
305 | |
306 gaim_notify_info(NULL, title, _("No logs were found"), log_preferences); | |
307 return NULL; | |
308 } | |
309 | |
10663 | 310 if (ht != NULL) |
311 g_hash_table_insert(log_viewers, ht, lv); | |
7432 | 312 |
313 /* Window ***********/ | |
10663 | 314 lv->window = gtk_dialog_new_with_buttons(title, NULL, 0, |
7432 | 315 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); |
11243 | 316 gtk_container_set_border_width (GTK_CONTAINER(lv->window), GAIM_HIG_BOX_SPACE); |
7432 | 317 gtk_dialog_set_has_separator(GTK_DIALOG(lv->window), FALSE); |
318 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(lv->window)->vbox), 0); | |
10175 | 319 g_signal_connect(G_OBJECT(lv->window), "response", |
7454 | 320 G_CALLBACK(destroy_cb), ht); |
11004
a3d3729a9130
[gaim-migrate @ 12859]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10884
diff
changeset
|
321 gtk_window_set_role(GTK_WINDOW(lv->window), "log_viewer"); |
7454 | 322 |
10663 | 323 /* Icon *************/ |
324 if (pixbuf != NULL) { | |
325 GdkPixbuf *scale; | |
326 GtkWidget *icon; | |
7432 | 327 |
11243 | 328 title_box = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
329 gtk_container_set_border_width(GTK_CONTAINER(title_box), GAIM_HIG_BOX_SPACE); | |
10663 | 330 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), title_box, FALSE, FALSE, 0); |
331 | |
332 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
333 icon = gtk_image_new_from_pixbuf(scale); | |
334 gtk_box_pack_start(GTK_BOX(title_box), icon, FALSE, FALSE, 0); | |
335 g_object_unref(G_OBJECT(pixbuf)); | |
336 g_object_unref(G_OBJECT(scale)); | |
337 } else | |
338 title_box = GTK_DIALOG(lv->window)->vbox; | |
7432 | 339 |
340 /* Label ************/ | |
10663 | 341 lv->label = gtk_label_new(NULL); |
342 | |
343 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>", title); | |
9624 | 344 |
10663 | 345 gtk_label_set_markup(GTK_LABEL(lv->label), text); |
346 gtk_misc_set_alignment(GTK_MISC(lv->label), 0, 0); | |
347 gtk_box_pack_start(GTK_BOX(title_box), lv->label, FALSE, FALSE, 0); | |
7432 | 348 g_free(text); |
349 | |
11769 | 350 /* Pane *************/ |
351 pane = gtk_hpaned_new(); | |
352 gtk_container_set_border_width(GTK_CONTAINER(pane), GAIM_HIG_BOX_SPACE); | |
353 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), pane, TRUE, TRUE, 0); | |
7432 | 354 |
11769 | 355 /* List *************/ |
356 sw = gtk_scrolled_window_new (NULL, NULL); | |
357 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); | |
358 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
359 gtk_paned_add1(GTK_PANED(pane), sw); | |
360 lv->treestore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); | |
361 lv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (lv->treestore)); | |
362 rend = gtk_cell_renderer_text_new(); | |
363 col = gtk_tree_view_column_new_with_attributes ("time", rend, "markup", 0, NULL); | |
364 gtk_tree_view_append_column (GTK_TREE_VIEW(lv->treeview), col); | |
365 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (lv->treeview), FALSE); | |
366 gtk_container_add (GTK_CONTAINER (sw), lv->treeview); | |
11402 | 367 |
11769 | 368 populate_log_tree(lv); |
11402 | 369 |
11769 | 370 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (lv->treeview)); |
371 g_signal_connect (G_OBJECT (sel), "changed", | |
372 G_CALLBACK (log_select_cb), | |
373 lv); | |
374 g_signal_connect (G_OBJECT(lv->treeview), "row-activated", | |
375 G_CALLBACK(log_row_activated_cb), | |
376 lv); | |
377 gaim_set_accessible_label(lv->treeview, lv->label); | |
11585 | 378 |
11769 | 379 /* Log size ************/ |
380 if(log_size) { | |
381 char *sz_txt = gaim_str_size_to_units(log_size); | |
382 text = g_strdup_printf("<span weight='bold'>%s</span> %s", _("Total log size:"), sz_txt); | |
383 size_label = gtk_label_new(NULL); | |
384 gtk_label_set_markup(GTK_LABEL(size_label), text); | |
385 /* gtk_paned_add1(GTK_PANED(pane), size_label); */ | |
386 gtk_misc_set_alignment(GTK_MISC(size_label), 0, 0); | |
387 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(lv->window)->vbox), size_label, FALSE, FALSE, 0); | |
388 g_free(sz_txt); | |
389 g_free(text); | |
390 } | |
11402 | 391 |
11769 | 392 /* A fancy little box ************/ |
393 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
394 gtk_paned_add2(GTK_PANED(pane), vbox); | |
11402 | 395 |
11769 | 396 /* Viewer ************/ |
13280
3de53fe8345f
[gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents:
13119
diff
changeset
|
397 frame = gaim_gtk_create_imhtml(FALSE, &lv->imhtml, NULL, NULL); |
11769 | 398 gtk_widget_set_name(lv->imhtml, "gaim_gtklog_imhtml"); |
399 gtk_widget_set_size_request(lv->imhtml, 320, 200); | |
400 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | |
401 gtk_widget_show(frame); | |
10181 | 402 |
11769 | 403 /* Search box **********/ |
404 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
405 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
406 lv->entry = gtk_entry_new(); | |
407 gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0); | |
408 button = gtk_button_new_from_stock(GTK_STOCK_FIND); | |
409 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
410 g_signal_connect(GTK_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv); | |
411 g_signal_connect(GTK_BUTTON(button), "activate", G_CALLBACK(search_cb), lv); | |
412 g_signal_connect(GTK_BUTTON(button), "clicked", G_CALLBACK(search_cb), lv); | |
10175 | 413 |
11780 | 414 #if GTK_CHECK_VERSION(2,2,0) |
11769 | 415 /* Show most recent log **********/ |
416 path_to_first_log = gtk_tree_path_new_from_string("0:0"); | |
417 if (path_to_first_log) | |
418 { | |
419 gtk_tree_view_expand_to_path(GTK_TREE_VIEW(lv->treeview), path_to_first_log); | |
420 gtk_tree_selection_select_path(sel, path_to_first_log); | |
421 gtk_tree_path_free(path_to_first_log); | |
10663 | 422 } |
11780 | 423 #endif |
7432 | 424 |
425 gtk_widget_show_all(lv->window); | |
10663 | 426 |
427 return lv; | |
428 } | |
429 | |
430 void gaim_gtk_log_show(GaimLogType type, const char *screenname, GaimAccount *account) { | |
431 struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1); | |
432 GaimGtkLogViewer *lv = NULL; | |
433 const char *name = screenname; | |
434 char *title; | |
435 | |
436 g_return_if_fail(account != NULL); | |
437 g_return_if_fail(screenname != NULL); | |
438 | |
439 ht->type = type; | |
440 ht->screenname = g_strdup(screenname); | |
441 ht->account = account; | |
442 | |
443 if (log_viewers == NULL) { | |
444 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal); | |
445 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) { | |
446 gtk_window_present(GTK_WINDOW(lv->window)); | |
447 g_free(ht); | |
448 return; | |
449 } | |
450 | |
451 if (type == GAIM_LOG_CHAT) { | |
452 GaimChat *chat; | |
453 | |
454 chat = gaim_blist_find_chat(account, screenname); | |
455 if (chat != NULL) | |
456 name = gaim_chat_get_name(chat); | |
457 | |
458 title = g_strdup_printf(_("Conversations in %s"), name); | |
459 } else { | |
460 GaimBuddy *buddy; | |
461 | |
462 buddy = gaim_find_buddy(account, screenname); | |
463 if (buddy != NULL) | |
464 name = gaim_buddy_get_contact_alias(buddy); | |
465 | |
466 title = g_strdup_printf(_("Conversations with %s"), name); | |
467 } | |
468 | |
469 display_log_viewer(ht, gaim_log_get_logs(type, screenname, account), | |
13090 | 470 title, gaim_gtk_create_prpl_icon(account, 0.5), gaim_log_get_total_size(type, screenname, account)); |
10663 | 471 g_free(title); |
472 } | |
473 | |
474 void gaim_gtk_log_show_contact(GaimContact *contact) { | |
475 struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1); | |
476 GaimBlistNode *child; | |
477 GaimGtkLogViewer *lv = NULL; | |
478 GList *logs = NULL; | |
479 char *filename; | |
480 GdkPixbuf *pixbuf; | |
481 const char *name = NULL; | |
482 char *title; | |
11585 | 483 int total_log_size = 0; |
10663 | 484 |
485 g_return_if_fail(contact != NULL); | |
486 | |
487 ht->type = GAIM_LOG_IM; | |
488 ht->contact = contact; | |
489 | |
490 if (log_viewers == NULL) { | |
491 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal); | |
492 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) { | |
493 gtk_window_present(GTK_WINDOW(lv->window)); | |
494 g_free(ht); | |
495 return; | |
496 } | |
497 | |
498 for (child = contact->node.child ; child ; child = child->next) { | |
499 if (!GAIM_BLIST_NODE_IS_BUDDY(child)) | |
500 continue; | |
501 | |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11700
diff
changeset
|
502 logs = g_list_concat(gaim_log_get_logs(GAIM_LOG_IM, ((GaimBuddy *)child)->name, |
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11700
diff
changeset
|
503 ((GaimBuddy *)child)->account), logs); |
11585 | 504 total_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy *)child)->name, ((GaimBuddy *)child)->account); |
10663 | 505 } |
506 logs = g_list_sort(logs, gaim_log_compare); | |
507 | |
508 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); | |
509 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
510 g_free(filename); | |
511 | |
512 if (contact->alias != NULL) | |
513 name = contact->alias; | |
514 else if (contact->priority != NULL) | |
515 name = gaim_buddy_get_contact_alias(contact->priority); | |
516 | |
517 title = g_strdup_printf(_("Conversations with %s"), name); | |
11585 | 518 display_log_viewer(ht, logs, title, pixbuf, total_log_size); |
10663 | 519 g_free(title); |
7432 | 520 } |
8573 | 521 |
522 void gaim_gtk_syslog_show() | |
523 { | |
524 GList *accounts = NULL; | |
10663 | 525 GList *logs = NULL; |
8573 | 526 |
10181 | 527 if (syslog_viewer != NULL) { |
8573 | 528 gtk_window_present(GTK_WINDOW(syslog_viewer->window)); |
529 return; | |
530 } | |
531 | |
10663 | 532 for(accounts = gaim_accounts_get_all(); accounts != NULL; accounts = accounts->next) { |
8573 | 533 |
534 GaimAccount *account = (GaimAccount *)accounts->data; | |
10663 | 535 if(gaim_find_prpl(gaim_account_get_protocol_id(account)) == NULL) |
8573 | 536 continue; |
537 | |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11700
diff
changeset
|
538 logs = g_list_concat(gaim_log_get_system_logs(account), logs); |
8573 | 539 } |
10663 | 540 logs = g_list_sort(logs, gaim_log_compare); |
10175 | 541 |
11585 | 542 syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), NULL, 0); |
8573 | 543 } |
12838
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
544 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
545 /**************************************************************************** |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
546 * GTK+ LOG SUBSYSTEM ******************************************************* |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
547 ****************************************************************************/ |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
548 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
549 void * |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
550 gaim_gtk_log_get_handle(void) |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
551 { |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
552 static int handle; |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
553 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
554 return &handle; |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
555 } |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
556 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
557 void gaim_gtk_log_init(void) |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
558 { |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
559 void *handle = gaim_gtk_log_get_handle(); |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
560 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
561 gaim_signal_register(handle, "log-displaying", |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
562 gaim_marshal_VOID__POINTER_POINTER, |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
563 NULL, 2, |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
564 gaim_value_new(GAIM_TYPE_BOXED, |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
565 "GaimGtkLogViewer *"), |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
566 gaim_value_new(GAIM_TYPE_SUBTYPE, |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
567 GAIM_SUBTYPE_LOG)); |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
568 } |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
569 |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
570 void |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
571 gaim_gtk_log_uninit(void) |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
572 { |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
573 gaim_signals_unregister_by_instance(gaim_gtk_log_get_handle()); |
cb36bc2db7c5
[gaim-migrate @ 15186]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
574 } |