Mercurial > pidgin
annotate src/gtklog.c @ 7572:6300424eafbf
[gaim-migrate @ 8188]
Update installer for gaim language macros
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Wed, 19 Nov 2003 22:43:22 +0000 |
parents | 083427fd8ba8 |
children | 5c5acdf8b982 |
rev | line source |
---|---|
7432 | 1 /** |
2 * @file gtklog.c GTK+ Log viewer | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Error of Ruto | |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
8 * |
7432 | 9 * This program is free software; you can redistribute it and/or modify |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 | |
24 #include "gtkinternal.h" | |
25 | |
26 #include "account.h" | |
27 #include "util.h" | |
28 #include "gtkblist.h" | |
29 #include "gtkimhtml.h" | |
30 #include "gtklog.h" | |
31 #include "gtkutils.h" | |
32 #include "log.h" | |
33 | |
34 static GHashTable *log_viewers = NULL; | |
7535 | 35 static void populate_log_tree(GaimGtkLogViewer *lv); |
7432 | 36 |
37 struct log_viewer_hash_t { | |
38 char *screenname; | |
39 GaimAccount *account; | |
40 }; | |
41 | |
7440 | 42 static guint log_viewer_hash(gconstpointer data) |
7432 | 43 { |
7440 | 44 const struct log_viewer_hash_t *viewer = data; |
7432 | 45 return g_str_hash(viewer->screenname) + g_str_hash(gaim_account_get_username(viewer->account)); |
7440 | 46 |
7432 | 47 } |
48 | |
7440 | 49 static gint log_viewer_equal(gconstpointer y, gconstpointer z) |
7432 | 50 { |
7440 | 51 const struct log_viewer_hash_t *a, *b; |
7432 | 52 int ret; |
7440 | 53 char *normal; |
54 | |
55 a = y; | |
56 b = z; | |
57 | |
58 normal = g_strdup(gaim_normalize(a->account, a->screenname)); | |
59 ret = (a->account == b->account) && | |
60 !strcmp(normal, gaim_normalize(b->account, b->screenname)); | |
7432 | 61 g_free(normal); |
62 return ret; | |
63 } | |
64 | |
7535 | 65 static void search_cb(GtkWidget *button, GaimGtkLogViewer *lv) |
66 { | |
67 const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry)); | |
68 GList *logs; | |
69 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); | |
70 | |
71 if (lv->search) | |
72 g_free(lv->search); | |
73 | |
74 gtk_tree_store_clear(lv->treestore); | |
75 if (strlen(search_term) == 0) {/* reset the tree */ | |
76 populate_log_tree(lv); | |
77 lv->search = NULL; | |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
78 gtk_imhtml_search_clear(GTK_IMHTML(lv->imhtml)); |
7535 | 79 return; |
80 } | |
81 | |
82 lv->search = g_strdup(search_term); | |
83 | |
84 gdk_window_set_cursor(lv->window->window, cursor); | |
85 while (gtk_events_pending()) | |
86 gtk_main_iteration(); | |
87 gdk_cursor_unref(cursor); | |
88 | |
89 for (logs = lv->logs; logs != NULL; logs = logs->next) { | |
90 char *read = gaim_log_read((GaimLog*)logs->data, NULL); | |
91 if (gaim_strcasestr(read, search_term)) { | |
92 GtkTreeIter iter; | |
93 GaimLog *log = logs->data; | |
94 char title[64]; | |
95 strftime(title, sizeof(title), "%c", localtime(&log->time)); | |
96 gtk_tree_store_append (lv->treestore, &iter, NULL); | |
97 gtk_tree_store_set(lv->treestore, &iter, | |
98 0, title, | |
99 1, log, -1); | |
100 } | |
101 } | |
102 | |
103 | |
104 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
105 gdk_window_set_cursor(lv->window->window, cursor); | |
106 gdk_cursor_unref(cursor); | |
107 } | |
108 | |
7454 | 109 static gboolean destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) { |
110 GaimGtkLogViewer *lv = g_hash_table_lookup(log_viewers, ht); | |
111 | |
112 g_hash_table_remove(log_viewers, ht); | |
113 g_free(ht->screenname); | |
114 g_free(ht); | |
7535 | 115 while (lv->logs) { |
7533 | 116 GaimLog *log = lv->logs->data; |
7535 | 117 GList *logs2; |
7533 | 118 g_free(log->name); |
119 g_free(log); | |
7535 | 120 logs2 = lv->logs->next; |
121 g_list_free_1(lv->logs); | |
122 lv->logs = logs2; | |
7533 | 123 } |
7535 | 124 if (lv->search) |
125 g_free(lv->search); | |
7533 | 126 g_free(lv); |
7454 | 127 gtk_widget_destroy(w); |
128 | |
129 return TRUE; | |
130 } | |
131 | |
132 static void log_select_cb(GtkTreeSelection *sel, GaimGtkLogViewer *viewer) { | |
7432 | 133 GtkTreeIter iter; |
134 GValue val = { 0, }; | |
135 GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore); | |
136 GaimLog *log = NULL; | |
137 GaimLogReadFlags flags; | |
138 char *read = NULL; | |
139 char time[64]; | |
140 | |
141 char *title; | |
142 | |
143 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) | |
144 return; | |
145 gtk_tree_model_get_value (model, &iter, 1, &val); | |
146 log = g_value_get_pointer(&val); | |
147 g_value_unset(&val); | |
148 | |
149 if (!log) | |
150 return; | |
151 | |
152 read = gaim_log_read(log, &flags); | |
153 viewer->flags = flags; | |
154 strftime(time, sizeof(time), "%c", localtime(&log->time)); | |
155 title = g_strdup_printf("%s - %s", log->name, time); | |
156 gtk_window_set_title(GTK_WINDOW(viewer->window), title); | |
157 gtk_imhtml_clear(GTK_IMHTML(viewer->imhtml)); | |
158 gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read, | |
159 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL | | |
160 ((flags & GAIM_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0)); | |
7535 | 161 |
162 if (viewer->search) | |
7537
083427fd8ba8
[gaim-migrate @ 8150]
Christian Hammond <chipx86@chipx86.com>
parents:
7535
diff
changeset
|
163 gtk_imhtml_search_find(GTK_IMHTML(viewer->imhtml), viewer->search); |
7535 | 164 |
7432 | 165 g_free(read); |
166 g_free(title); | |
167 } | |
168 | |
169 /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet. | |
170 * I want the tree to be divided into groups like "Today," "Yesterday," "Last week," | |
171 * "August," "2002," etc. based on how many conversation took place in each subdivision. | |
172 * | |
173 * For now, I'll just make it a flat list. | |
174 */ | |
175 static void populate_log_tree(GaimGtkLogViewer *lv) | |
176 /* Logs are made from trees in real life. | |
177 This is a tree made from logs */ | |
178 { | |
7440 | 179 char title[64]; |
7432 | 180 GtkTreeIter iter; |
181 GList *logs = lv->logs; | |
182 while (logs) { | |
183 GaimLog *log = logs->data; | |
184 strftime(title, sizeof(title), "%c", localtime(&log->time)); | |
185 gtk_tree_store_append (lv->treestore, &iter, NULL); | |
186 gtk_tree_store_set(lv->treestore, &iter, | |
187 0, title, | |
188 1, log, -1); | |
189 logs = logs->next; | |
190 } | |
191 } | |
192 | |
193 void gaim_gtk_log_show(const char *screenname, GaimAccount *account) { | |
194 /* if (log_viewers && g_hash_table */ | |
195 GtkWidget *hbox, *vbox; | |
196 GdkPixbuf *pixbuf, *scale; | |
197 GtkCellRenderer *rend; | |
198 GtkTreeViewColumn *col; | |
199 GaimGtkLogViewer *lv = NULL; | |
200 GtkTreeSelection *sel; | |
201 GtkWidget *icon, *label, *pane, *sw, *button; | |
202 GList *logs; | |
203 char *text; | |
7436 | 204 struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1); |
205 | |
7432 | 206 ht->screenname = g_strdup(screenname); |
207 ht->account = account; | |
208 | |
209 if (!log_viewers) { | |
210 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal); | |
211 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) { | |
212 gtk_window_present(GTK_WINDOW(lv->window)); | |
213 return; | |
214 } | |
215 | |
216 lv = g_new0(GaimGtkLogViewer, 1); | |
7485 | 217 lv->logs = logs = gaim_log_get_logs(screenname, account); |
7432 | 218 g_hash_table_insert(log_viewers, ht, lv); |
219 | |
220 /* Window ***********/ | |
221 lv->window = gtk_dialog_new_with_buttons(screenname, NULL, 0, | |
222 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | |
223 gtk_container_set_border_width (GTK_CONTAINER(lv->window), 6); | |
224 gtk_dialog_set_has_separator(GTK_DIALOG(lv->window), FALSE); | |
225 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(lv->window)->vbox), 0); | |
7454 | 226 g_signal_connect(G_OBJECT(lv->window), "response", |
227 G_CALLBACK(destroy_cb), ht); | |
228 | |
7432 | 229 hbox = gtk_hbox_new(FALSE, 6); |
230 gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); | |
231 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), hbox, FALSE, FALSE, 0); | |
232 | |
233 /* Icon *************/ | |
234 pixbuf = create_prpl_icon(account); | |
235 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR); | |
236 icon = gtk_image_new_from_pixbuf(scale); | |
237 gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); | |
238 g_object_unref(G_OBJECT(pixbuf)); | |
239 g_object_unref(G_OBJECT(scale)); | |
240 | |
241 /* Label ************/ | |
242 label = gtk_label_new(NULL); | |
243 text = g_strdup_printf("<span size='larger' weight='bold'>%s %s</span>", | |
244 _("Conversations with"), screenname); | |
245 gtk_label_set_markup(GTK_LABEL(label), text); | |
246 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
247 g_free(text); | |
248 | |
249 /* Pane *************/ | |
250 pane = gtk_hpaned_new(); | |
251 gtk_container_set_border_width(GTK_CONTAINER(pane), 6); | |
252 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), pane, TRUE, TRUE, 0); | |
253 | |
254 /* List *************/ | |
255 sw = gtk_scrolled_window_new (NULL, NULL); | |
256 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); | |
257 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
258 gtk_paned_add1(GTK_PANED(pane), sw); | |
259 lv->treestore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); | |
260 lv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (lv->treestore)); | |
261 rend = gtk_cell_renderer_text_new(); | |
262 col = gtk_tree_view_column_new_with_attributes ("time", rend, "markup", 0, NULL); | |
263 gtk_tree_view_append_column (GTK_TREE_VIEW(lv->treeview), col); | |
264 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (lv->treeview), FALSE); | |
265 gtk_container_add (GTK_CONTAINER (sw), lv->treeview); | |
266 | |
267 gtk_widget_set_size_request(lv->treeview, 170, 200); | |
268 populate_log_tree(lv); | |
269 | |
270 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (lv->treeview)); | |
271 g_signal_connect (G_OBJECT (sel), "changed", | |
7454 | 272 G_CALLBACK (log_select_cb), |
7432 | 273 lv); |
274 | |
275 /* Viewer ************/ | |
276 vbox = gtk_vbox_new(FALSE, 6); | |
277 gtk_paned_add2(GTK_PANED(pane), vbox); | |
278 sw = gtk_scrolled_window_new(NULL, NULL); | |
279 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
280 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
281 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | |
282 lv->imhtml = gtk_imhtml_new(NULL, NULL); | |
283 gtk_container_add(GTK_CONTAINER(sw), lv->imhtml); | |
284 gaim_setup_imhtml(lv->imhtml); | |
285 gtk_widget_set_size_request(lv->imhtml, 320, 200); | |
286 | |
287 /* Search box **********/ | |
288 hbox = gtk_hbox_new(FALSE, 6); | |
289 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
290 lv->entry = gtk_entry_new(); | |
291 gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0); | |
292 button = gtk_button_new_from_stock(GTK_STOCK_FIND); | |
7535 | 293 g_signal_connect (G_OBJECT (button), "pressed", |
294 G_CALLBACK (search_cb), | |
295 lv); | |
7432 | 296 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
297 | |
298 gtk_widget_show_all(lv->window); | |
299 } |