7432
|
1 /**
|
|
2 * @file gtklog.c GTK+ Log viewer
|
|
3 * @ingroup gtkui
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Copyright (C) 2003 Error of Ruto
|
|
8 *
|
|
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;
|
|
35
|
|
36 struct log_viewer_hash_t {
|
|
37 char *screenname;
|
|
38 GaimAccount *account;
|
|
39 };
|
|
40
|
7440
|
41 static guint log_viewer_hash(gconstpointer data)
|
7432
|
42 {
|
7440
|
43 const struct log_viewer_hash_t *viewer = data;
|
7432
|
44 return g_str_hash(viewer->screenname) + g_str_hash(gaim_account_get_username(viewer->account));
|
7440
|
45
|
7432
|
46 }
|
|
47
|
7440
|
48 static gint log_viewer_equal(gconstpointer y, gconstpointer z)
|
7432
|
49 {
|
7440
|
50 const struct log_viewer_hash_t *a, *b;
|
7432
|
51 int ret;
|
7440
|
52 char *normal;
|
|
53
|
|
54 a = y;
|
|
55 b = z;
|
|
56
|
|
57 normal = g_strdup(gaim_normalize(a->account, a->screenname));
|
|
58 ret = (a->account == b->account) &&
|
|
59 !strcmp(normal, gaim_normalize(b->account, b->screenname));
|
7432
|
60 g_free(normal);
|
|
61 return ret;
|
|
62 }
|
|
63
|
|
64 static void log_select(GtkTreeSelection *sel, GaimGtkLogViewer *viewer) {
|
|
65 GtkTreeIter iter;
|
|
66 GValue val = { 0, };
|
|
67 GtkTreeModel *model = GTK_TREE_MODEL(viewer->treestore);
|
|
68 GaimLog *log = NULL;
|
|
69 GaimLogReadFlags flags;
|
|
70 char *read = NULL;
|
|
71 char time[64];
|
|
72
|
|
73 char *title;
|
|
74
|
|
75 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
|
|
76 return;
|
|
77 gtk_tree_model_get_value (model, &iter, 1, &val);
|
|
78 log = g_value_get_pointer(&val);
|
|
79 g_value_unset(&val);
|
|
80
|
|
81 if (!log)
|
|
82 return;
|
|
83
|
|
84 read = gaim_log_read(log, &flags);
|
|
85 viewer->flags = flags;
|
|
86 strftime(time, sizeof(time), "%c", localtime(&log->time));
|
|
87 title = g_strdup_printf("%s - %s", log->name, time);
|
|
88 gtk_window_set_title(GTK_WINDOW(viewer->window), title);
|
|
89 gtk_imhtml_clear(GTK_IMHTML(viewer->imhtml));
|
|
90 gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read,
|
|
91 GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL |
|
|
92 ((flags & GAIM_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0));
|
|
93 g_free(read);
|
|
94 g_free(title);
|
|
95 }
|
|
96
|
|
97 /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet.
|
|
98 * I want the tree to be divided into groups like "Today," "Yesterday," "Last week,"
|
|
99 * "August," "2002," etc. based on how many conversation took place in each subdivision.
|
|
100 *
|
|
101 * For now, I'll just make it a flat list.
|
|
102 */
|
|
103 static void populate_log_tree(GaimGtkLogViewer *lv)
|
|
104 /* Logs are made from trees in real life.
|
|
105 This is a tree made from logs */
|
|
106 {
|
7440
|
107 char title[64];
|
7432
|
108 GtkTreeIter iter;
|
|
109 GList *logs = lv->logs;
|
|
110 while (logs) {
|
|
111 GaimLog *log = logs->data;
|
|
112 strftime(title, sizeof(title), "%c", localtime(&log->time));
|
|
113 gtk_tree_store_append (lv->treestore, &iter, NULL);
|
|
114 gtk_tree_store_set(lv->treestore, &iter,
|
|
115 0, title,
|
|
116 1, log, -1);
|
|
117 logs = logs->next;
|
|
118 }
|
|
119 }
|
|
120
|
|
121 void gaim_gtk_log_show(const char *screenname, GaimAccount *account) {
|
|
122 /* if (log_viewers && g_hash_table */
|
|
123 GtkWidget *hbox, *vbox;
|
|
124 GdkPixbuf *pixbuf, *scale;
|
|
125 GtkCellRenderer *rend;
|
|
126 GtkTreeViewColumn *col;
|
|
127 GaimGtkLogViewer *lv = NULL;
|
|
128 GtkTreeSelection *sel;
|
|
129 GtkWidget *icon, *label, *pane, *sw, *button;
|
|
130 GList *logs;
|
|
131 char *text;
|
7436
|
132 struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1);
|
|
133
|
7432
|
134 ht->screenname = g_strdup(screenname);
|
|
135 ht->account = account;
|
|
136
|
|
137 if (!log_viewers) {
|
|
138 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
|
|
139 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
|
|
140 gtk_window_present(GTK_WINDOW(lv->window));
|
|
141 return;
|
|
142 }
|
|
143
|
|
144 lv = g_new0(GaimGtkLogViewer, 1);
|
|
145 lv->logs = logs = gaim_log_get_logs(g_strdup(screenname), account);
|
|
146 g_hash_table_insert(log_viewers, ht, lv);
|
|
147
|
|
148 /* Window ***********/
|
|
149 lv->window = gtk_dialog_new_with_buttons(screenname, NULL, 0,
|
|
150 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
|
|
151 gtk_container_set_border_width (GTK_CONTAINER(lv->window), 6);
|
|
152 gtk_dialog_set_has_separator(GTK_DIALOG(lv->window), FALSE);
|
|
153 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(lv->window)->vbox), 0);
|
|
154
|
|
155 hbox = gtk_hbox_new(FALSE, 6);
|
|
156 gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
|
|
157 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), hbox, FALSE, FALSE, 0);
|
|
158
|
|
159 /* Icon *************/
|
|
160 pixbuf = create_prpl_icon(account);
|
|
161 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);
|
|
162 icon = gtk_image_new_from_pixbuf(scale);
|
|
163 gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0);
|
|
164 g_object_unref(G_OBJECT(pixbuf));
|
|
165 g_object_unref(G_OBJECT(scale));
|
|
166
|
|
167 /* Label ************/
|
|
168 label = gtk_label_new(NULL);
|
|
169 text = g_strdup_printf("<span size='larger' weight='bold'>%s %s</span>",
|
|
170 _("Conversations with"), screenname);
|
|
171 gtk_label_set_markup(GTK_LABEL(label), text);
|
|
172 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
173 g_free(text);
|
|
174
|
|
175 /* Pane *************/
|
|
176 pane = gtk_hpaned_new();
|
|
177 gtk_container_set_border_width(GTK_CONTAINER(pane), 6);
|
|
178 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(lv->window)->vbox), pane, TRUE, TRUE, 0);
|
|
179
|
|
180 /* List *************/
|
|
181 sw = gtk_scrolled_window_new (NULL, NULL);
|
|
182 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
|
|
183 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
184 gtk_paned_add1(GTK_PANED(pane), sw);
|
|
185 lv->treestore = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
|
|
186 lv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (lv->treestore));
|
|
187 rend = gtk_cell_renderer_text_new();
|
|
188 col = gtk_tree_view_column_new_with_attributes ("time", rend, "markup", 0, NULL);
|
|
189 gtk_tree_view_append_column (GTK_TREE_VIEW(lv->treeview), col);
|
|
190 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (lv->treeview), FALSE);
|
|
191 gtk_container_add (GTK_CONTAINER (sw), lv->treeview);
|
|
192
|
|
193 gtk_widget_set_size_request(lv->treeview, 170, 200);
|
|
194 populate_log_tree(lv);
|
|
195
|
|
196 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (lv->treeview));
|
|
197 g_signal_connect (G_OBJECT (sel), "changed",
|
|
198 G_CALLBACK (log_select),
|
|
199 lv);
|
|
200
|
|
201 /* Viewer ************/
|
|
202 vbox = gtk_vbox_new(FALSE, 6);
|
|
203 gtk_paned_add2(GTK_PANED(pane), vbox);
|
|
204 sw = gtk_scrolled_window_new(NULL, NULL);
|
|
205 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
|
|
206 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
|
|
207 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
208 lv->imhtml = gtk_imhtml_new(NULL, NULL);
|
|
209 gtk_container_add(GTK_CONTAINER(sw), lv->imhtml);
|
|
210 gaim_setup_imhtml(lv->imhtml);
|
|
211 gtk_widget_set_size_request(lv->imhtml, 320, 200);
|
|
212
|
|
213 /* Search box **********/
|
|
214 hbox = gtk_hbox_new(FALSE, 6);
|
|
215 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
216 lv->entry = gtk_entry_new();
|
|
217 gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0);
|
|
218 button = gtk_button_new_from_stock(GTK_STOCK_FIND);
|
|
219 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
220
|
|
221 gtk_widget_show_all(lv->window);
|
|
222 }
|