annotate finch/gntlog.c @ 23158:da5d1ecc5c20

Add support for setting and removing custom buddy icons to contacts, chats, and groups via their respective right-click menus in the buddy list. Also display the buddy icons for chats and groups in the buddy list.
author Etan Reisner <pidgin@unreliablesource.net>
date Sat, 17 May 2008 19:53:28 +0000
parents 946f1bb22adb
children adde385c7904
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
1 /**
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
2 * @file gntlog.c GNT Log viewer
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
3 * @ingroup finch
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
4 */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
5
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
6 /* finch
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
7 *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
8 * Finch is the legal property of its developers, whose names are too numerous
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
10 * source distribution.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
11 *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
15 * (at your option) any later version.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
16 *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
20 * GNU General Public License for more details.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
21 *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
25 */
22648
864c82371181 Include finch.h instead of internal.h
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22346
diff changeset
26 #include "finch.h"
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
27
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
28 #include <gnt.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
29 #include <gntbox.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
30 #include <gntbutton.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
31 #include <gntentry.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
32 #include <gntlabel.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
33 #include <gnttextview.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
34 #include <gnttree.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
35 #include <gntwindow.h>
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
36
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
37 #include "account.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
38 #include "debug.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
39 #include "log.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
40 #include "notify.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
41 #include "request.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
42 #include "util.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
43
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
44 #include "gntlog.h"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
45
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
46 static GHashTable *log_viewers = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
47 static void populate_log_tree(FinchLogViewer *lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
48 static FinchLogViewer *syslog_viewer = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
49
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
50 struct log_viewer_hash_t {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
51 PurpleLogType type;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
52 char *screenname;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
53 PurpleAccount *account;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
54 PurpleContact *contact;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
55 };
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
56
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
57 static guint log_viewer_hash(gconstpointer data)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
58 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
59 const struct log_viewer_hash_t *viewer = data;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
60
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
61 if (viewer->contact != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
62 return g_direct_hash(viewer->contact);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
63
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
64 return g_str_hash(viewer->screenname) +
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
65 g_str_hash(purple_account_get_username(viewer->account));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
66 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
67
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
68 static gboolean log_viewer_equal(gconstpointer y, gconstpointer z)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
69 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
70 const struct log_viewer_hash_t *a, *b;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
71 int ret;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
72 char *normal;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
73
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
74 a = y;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
75 b = z;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
76
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
77 if (a->contact != NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
78 if (b->contact != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
79 return (a->contact == b->contact);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
80 else
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
81 return FALSE;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
82 } else {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
83 if (b->contact != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
84 return FALSE;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
85 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
86
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
87 normal = g_strdup(purple_normalize(a->account, a->screenname));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
88 ret = (a->account == b->account) &&
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
89 !strcmp(normal, purple_normalize(b->account, b->screenname));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
90 g_free(normal);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
91
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
92 return ret;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
93 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
94
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
95 static const char *log_get_date(PurpleLog *log)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
96 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
97 if (log->tm)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
98 return purple_date_format_full(log->tm);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
99 else
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
100 return purple_date_format_full(localtime(&log->time));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
101 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
102
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
103 static void search_cb(GntWidget *button, FinchLogViewer *lv)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
104 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
105 const char *search_term = gnt_entry_get_text(GNT_ENTRY(lv->entry));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
106 GList *logs;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
107
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
108 if (!(*search_term)) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
109 /* reset the tree */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
110 gnt_tree_remove_all(GNT_TREE(lv->tree));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
111 g_free(lv->search);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
112 lv->search = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
113 populate_log_tree(lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
114 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
115 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
116
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
117 if (lv->search != NULL && !strcmp(lv->search, search_term)) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
118 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
119 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
120
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
121 g_free(lv->search);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
122 lv->search = g_strdup(search_term);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
123
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
124 gnt_tree_remove_all(GNT_TREE(lv->tree));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
125 gnt_text_view_clear(GNT_TEXT_VIEW(lv->text));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
126
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
127 for (logs = lv->logs; logs != NULL; logs = logs->next) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
128 char *read = purple_log_read((PurpleLog*)logs->data, NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
129 if (read && *read && purple_strcasestr(read, search_term)) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
130 PurpleLog *log = logs->data;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
131
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
132 gnt_tree_add_row_last(GNT_TREE(lv->tree),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
133 log,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
134 gnt_tree_create_row(GNT_TREE(lv->tree), log_get_date(log)),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
135 NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
136 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
137 g_free(read);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
138 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
139
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
140 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
141
22766
946f1bb22adb Always top-align the logs in the log-viewer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22648
diff changeset
142 static void destroy_cb(GntWidget *w, struct log_viewer_hash_t *ht)
946f1bb22adb Always top-align the logs in the log-viewer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22648
diff changeset
143 {
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
144 FinchLogViewer *lv = syslog_viewer;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
145
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
146 if (ht != NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
147 lv = g_hash_table_lookup(log_viewers, ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
148 g_hash_table_remove(log_viewers, ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
149
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
150 g_free(ht->screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
151 g_free(ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
152 } else
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
153 syslog_viewer = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
154
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
155 purple_request_close_with_handle(lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
156
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
157 g_list_foreach(lv->logs, (GFunc)purple_log_free, NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
158 g_list_free(lv->logs);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
159
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
160 g_free(lv->search);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
161 g_free(lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
162
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
163 gnt_widget_destroy(w);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
164 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
165
22766
946f1bb22adb Always top-align the logs in the log-viewer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22648
diff changeset
166 static void log_select_cb(GntWidget *w, gpointer old, gpointer new, FinchLogViewer *viewer)
946f1bb22adb Always top-align the logs in the log-viewer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22648
diff changeset
167 {
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
168 GntTree *tree = GNT_TREE(w);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
169 PurpleLog *log = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
170 PurpleLogReadFlags flags;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
171 char *read = NULL, *strip, *newline;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
172
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
173 if (!viewer->search && !gnt_tree_get_parent_key(tree, new))
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
174 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
175
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
176 log = (PurpleLog *)new;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
177
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
178 if (log == NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
179 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
180
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
181 if (log->type != PURPLE_LOG_SYSTEM) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
182 char *title;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
183 if (log->type == PURPLE_LOG_CHAT)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
184 title = g_strdup_printf(_("Conversation in %s on %s"),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
185 log->name, log_get_date(log));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
186 else
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
187 title = g_strdup_printf(_("Conversation with %s on %s"),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
188 log->name, log_get_date(log));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
189
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
190 gnt_label_set_text(GNT_LABEL(viewer->label), title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
191 g_free(title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
192 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
193
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
194 read = purple_log_read(log, &flags);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
195 if (flags != PURPLE_LOG_READ_NO_NEWLINE) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
196 newline = purple_strdup_withhtml(read);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
197 strip = purple_markup_strip_html(newline);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
198 g_free(newline);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
199 } else {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
200 strip = purple_markup_strip_html(read);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
201 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
202 viewer->flags = flags;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
203
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
204 purple_signal_emit(finch_log_get_handle(), "log-displaying", viewer, log);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
205
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
206 gnt_text_view_clear(GNT_TEXT_VIEW(viewer->text));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
207 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(viewer->text), strip, GNT_TEXT_FLAG_NORMAL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
208 g_free(read);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
209 g_free(strip);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
210 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
211
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
212 /* I want to make this smarter, but haven't come up with a cool algorithm to do so, yet.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
213 * I want the tree to be divided into groups like "Today," "Yesterday," "Last week,"
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
214 * "August," "2002," etc. based on how many conversation took place in each subdivision.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
215 *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
216 * For now, I'll just make it a flat list.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
217 */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
218 static void populate_log_tree(FinchLogViewer *lv)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
219 /* Logs are made from trees in real life.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
220 This is a tree made from logs */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
221 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
222 const char *pmonth;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
223 char *month = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
224 char prev_top_month[30] = "";
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
225 GList *logs = lv->logs;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
226
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
227 while (logs != NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
228 PurpleLog *log = logs->data;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
229
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
230 pmonth = purple_utf8_strftime(_("%B %Y"),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
231 log->tm ? log->tm : localtime(&log->time));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
232
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
233 if (strcmp(pmonth, prev_top_month) != 0) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
234 month = g_strdup(pmonth);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
235 /* top level */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
236 gnt_tree_add_row_last(GNT_TREE(lv->tree),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
237 month,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
238 gnt_tree_create_row(GNT_TREE(lv->tree), month),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
239 NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
240 gnt_tree_set_expanded(GNT_TREE(lv->tree), month, FALSE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
241
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
242 strncpy(prev_top_month, month, sizeof(prev_top_month));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
243 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
244
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
245 /* sub */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
246 gnt_tree_add_row_last(GNT_TREE(lv->tree),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
247 log,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
248 gnt_tree_create_row(GNT_TREE(lv->tree), log_get_date(log)),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
249 month);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
250
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
251 logs = logs->next;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
252 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
253 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
254
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
255 static FinchLogViewer *display_log_viewer(struct log_viewer_hash_t *ht, GList *logs,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
256 const char *title, int log_size)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
257 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
258 FinchLogViewer *lv;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
259 char *text;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
260 GntWidget *vbox, *hbox;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
261 GntWidget *size_label;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
262
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
263 if (logs == NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
264 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
265 /* No logs were found. */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
266 const char *log_preferences = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
267
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
268 if (ht == NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
269 if (!purple_prefs_get_bool("/purple/logging/log_system"))
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
270 log_preferences = _("System events will only be logged if the \"Log all status changes to system log\" preference is enabled.");
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
271 } else {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
272 if (ht->type == PURPLE_LOG_IM) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
273 if (!purple_prefs_get_bool("/purple/logging/log_ims"))
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
274 log_preferences = _("Instant messages will only be logged if the \"Log all instant messages\" preference is enabled.");
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
275 } else if (ht->type == PURPLE_LOG_CHAT) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
276 if (!purple_prefs_get_bool("/purple/logging/log_chats"))
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
277 log_preferences = _("Chats will only be logged if the \"Log all chats\" preference is enabled.");
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
278 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
279 g_free(ht->screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
280 g_free(ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
281 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
282
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
283 purple_notify_info(NULL, title, _("No logs were found"), log_preferences);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
284 return NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
285 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
286
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
287 lv = g_new0(FinchLogViewer, 1);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
288 lv->logs = logs;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
289
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
290 if (ht != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
291 g_hash_table_insert(log_viewers, ht, lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
292
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
293 /* Window ***********/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
294 lv->window = gnt_vwindow_new(FALSE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
295 gnt_box_set_title(GNT_BOX(lv->window), title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
296 gnt_box_set_toplevel(GNT_BOX(lv->window), TRUE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
297 gnt_box_set_pad(GNT_BOX(lv->window), 0);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
298 g_signal_connect(G_OBJECT(lv->window), "destroy", G_CALLBACK(destroy_cb), ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
299
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
300 vbox = gnt_vbox_new(FALSE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
301 gnt_box_add_widget(GNT_BOX(lv->window), vbox);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
302
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
303 /* Label ************/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
304 text = g_strdup_printf("%s", title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
305 lv->label = gnt_label_new(text);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
306 g_free(text);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
307 gnt_box_add_widget(GNT_BOX(vbox), lv->label);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
308
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
309 hbox = gnt_hbox_new(FALSE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
310 gnt_box_add_widget(GNT_BOX(vbox), hbox);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
311 /* List *************/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
312 lv->tree = gnt_tree_new();
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
313 gnt_widget_set_size(lv->tree, 30, 0);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
314 populate_log_tree(lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
315 g_signal_connect (G_OBJECT(lv->tree), "selection-changed",
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
316 G_CALLBACK (log_select_cb),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
317 lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
318 gnt_box_add_widget(GNT_BOX(hbox), lv->tree);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
319
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
320 /* Viewer ************/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
321 lv->text = gnt_text_view_new();
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
322 gnt_box_add_widget(GNT_BOX(hbox), lv->text);
22766
946f1bb22adb Always top-align the logs in the log-viewer.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22648
diff changeset
323 gnt_text_view_set_flag(GNT_TEXT_VIEW(lv->text), GNT_TEXT_VIEW_TOP_ALIGN);
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
324
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
325 hbox = gnt_hbox_new(FALSE);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
326 gnt_box_add_widget(GNT_BOX(vbox), hbox);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
327 /* Log size ************/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
328 if (log_size) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
329 char *sz_txt = purple_str_size_to_units(log_size);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
330 text = g_strdup_printf("%s %s", _("Total log size:"), sz_txt);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
331 size_label = gnt_label_new(text);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
332 gnt_box_add_widget(GNT_BOX(hbox), size_label);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
333 g_free(sz_txt);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
334 g_free(text);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
335 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
336
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
337 /* Search box **********/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
338 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Scroll/Search: ")));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
339 lv->entry = gnt_entry_new("");
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
340 gnt_box_add_widget(GNT_BOX(hbox), lv->entry);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
341 g_signal_connect(GNT_ENTRY(lv->entry), "activate", G_CALLBACK(search_cb), lv);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
342
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
343 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(lv->text), lv->entry);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
344 gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(lv->text), lv->entry);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
345
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
346 gnt_widget_show(lv->window);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
347
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
348 return lv;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
349 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
350
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
351 void finch_log_show(PurpleLogType type, const char *screenname, PurpleAccount *account) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
352 struct log_viewer_hash_t *ht;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
353 FinchLogViewer *lv = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
354 const char *name = screenname;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
355 char *title;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
356
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
357 g_return_if_fail(account != NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
358 g_return_if_fail(screenname != NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
359
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
360 ht = g_new0(struct log_viewer_hash_t, 1);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
361
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
362 ht->type = type;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
363 ht->screenname = g_strdup(screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
364 ht->account = account;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
365
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
366 if (log_viewers == NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
367 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
368 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
369 gnt_window_present(lv->window);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
370 g_free(ht->screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
371 g_free(ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
372 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
373 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
374
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
375 if (type == PURPLE_LOG_CHAT) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
376 PurpleChat *chat;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
377
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
378 chat = purple_blist_find_chat(account, screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
379 if (chat != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
380 name = purple_chat_get_name(chat);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
381
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
382 title = g_strdup_printf(_("Conversations in %s"), name);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
383 } else {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
384 PurpleBuddy *buddy;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
385
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
386 buddy = purple_find_buddy(account, screenname);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
387 if (buddy != NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
388 name = purple_buddy_get_contact_alias(buddy);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
389
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
390 title = g_strdup_printf(_("Conversations with %s"), name);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
391 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
392
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
393 display_log_viewer(ht, purple_log_get_logs(type, screenname, account),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
394 title, purple_log_get_total_size(type, screenname, account));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
395
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
396 g_free(title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
397 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
398
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
399 void finch_log_show_contact(PurpleContact *contact) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
400 struct log_viewer_hash_t *ht;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
401 PurpleBlistNode *child;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
402 FinchLogViewer *lv = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
403 GList *logs = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
404 const char *name = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
405 char *title;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
406 int total_log_size = 0;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
407
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
408 g_return_if_fail(contact != NULL);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
409
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
410 ht = g_new0(struct log_viewer_hash_t, 1);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
411 ht->type = PURPLE_LOG_IM;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
412 ht->contact = contact;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
413
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
414 if (log_viewers == NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
415 log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
416 } else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
417 gnt_window_present(lv->window);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
418 g_free(ht);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
419 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
420 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
421
22346
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
422 for (child = purple_blist_node_get_first_child((PurpleBlistNode*)contact); child;
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
423 child = purple_blist_node_get_sibling_next(child)) {
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
424 if (!PURPLE_BLIST_NODE_IS_BUDDY(child))
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
425 continue;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
426
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
427 logs = g_list_concat(purple_log_get_logs(PURPLE_LOG_IM, ((PurpleBuddy *)child)->name,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
428 ((PurpleBuddy *)child)->account), logs);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
429 total_log_size += purple_log_get_total_size(PURPLE_LOG_IM, ((PurpleBuddy *)child)->name, ((PurpleBuddy *)child)->account);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
430 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
431 logs = g_list_sort(logs, purple_log_compare);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
432
22346
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
433 name = purple_contact_get_alias(contact);
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
434 if (!name)
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
435 name = purple_buddy_get_contact_alias(purple_contact_get_priority_buddy(contact));
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
436
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
437 /* This will happen if the contact doesn't have an alias,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
438 * and none of the contact's buddies are online.
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
439 * There is probably a better way to deal with this. */
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
440 if (name == NULL) {
22346
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
441 child = purple_blist_node_get_first_child((PurpleBlistNode*)contact);
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
442 if (child != NULL && PURPLE_BLIST_NODE_IS_BUDDY(child))
561729870929 Fix showing a contact's log, and don't access struct internals
Richard Nelson <wabz@pidgin.im>
parents: 22248
diff changeset
443 name = purple_buddy_get_contact_alias((PurpleBuddy *)child);
22248
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
444 if (name == NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
445 name = "";
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
446 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
447
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
448 title = g_strdup_printf(_("Conversations with %s"), name);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
449 display_log_viewer(ht, logs, title, total_log_size);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
450 g_free(title);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
451 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
452
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
453 void finch_syslog_show()
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
454 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
455 GList *accounts = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
456 GList *logs = NULL;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
457
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
458 if (syslog_viewer != NULL) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
459 gnt_window_present(syslog_viewer->window);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
460 return;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
461 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
462
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
463 for(accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
464
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
465 PurpleAccount *account = (PurpleAccount *)accounts->data;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
466 if(purple_find_prpl(purple_account_get_protocol_id(account)) == NULL)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
467 continue;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
468
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
469 logs = g_list_concat(purple_log_get_system_logs(account), logs);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
470 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
471 logs = g_list_sort(logs, purple_log_compare);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
472
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
473 syslog_viewer = display_log_viewer(NULL, logs, _("System Log"), 0);
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
474 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
475
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
476 /****************************************************************************
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
477 * GNT LOG SUBSYSTEM *******************************************************
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
478 ****************************************************************************/
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
479
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
480 void *
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
481 finch_log_get_handle(void)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
482 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
483 static int handle;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
484
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
485 return &handle;
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
486 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
487
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
488 void finch_log_init(void)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
489 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
490 void *handle = finch_log_get_handle();
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
491
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
492 purple_signal_register(handle, "log-displaying",
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
493 purple_marshal_VOID__POINTER_POINTER,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
494 NULL, 2,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
495 purple_value_new(PURPLE_TYPE_BOXED,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
496 "FinchLogViewer *"),
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
497 purple_value_new(PURPLE_TYPE_SUBTYPE,
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
498 PURPLE_SUBTYPE_LOG));
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
499 }
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
500
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
501 void
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
502 finch_log_uninit(void)
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
503 {
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
504 purple_signals_unregister_by_instance(finch_log_get_handle());
88796aff14d6 Add a finch log viewer. This is largely copied from Pidgin.
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
505 }