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