Mercurial > pidgin.yaz
annotate finch/gntnotify.c @ 17676:08eef35b27dd
ChangeLog a few things
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 03 Jun 2007 18:32:12 +0000 |
parents | 46f2f86e08e4 |
children | bac7cec1609d |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntnotify.c GNT Notify API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15871
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <gnt.h> | |
26 #include <gntbox.h> | |
27 #include <gntbutton.h> | |
28 #include <gntlabel.h> | |
29 #include <gnttree.h> | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
30 #include <gntutils.h> |
15818 | 31 |
32 #include <util.h> | |
33 | |
34 #include "gntnotify.h" | |
15823 | 35 #include "finch.h" |
15818 | 36 |
37 static struct | |
38 { | |
39 GntWidget *window; | |
40 GntWidget *tree; | |
41 } emaildialog; | |
42 | |
43 static void | |
15823 | 44 notify_msg_window_destroy_cb(GntWidget *window, PurpleNotifyMsgType type) |
15818 | 45 { |
15823 | 46 purple_notify_close(type, window); |
15818 | 47 } |
48 | |
49 static void * | |
15823 | 50 finch_notify_message(PurpleNotifyMsgType type, const char *title, |
15818 | 51 const char *primary, const char *secondary) |
52 { | |
53 GntWidget *window, *button; | |
54 GntTextFormatFlags pf = 0, sf = 0; | |
55 | |
56 switch (type) | |
57 { | |
15823 | 58 case PURPLE_NOTIFY_MSG_ERROR: |
15818 | 59 sf |= GNT_TEXT_FLAG_BOLD; |
15823 | 60 case PURPLE_NOTIFY_MSG_WARNING: |
15818 | 61 pf |= GNT_TEXT_FLAG_UNDERLINE; |
15823 | 62 case PURPLE_NOTIFY_MSG_INFO: |
15818 | 63 pf |= GNT_TEXT_FLAG_BOLD; |
64 break; | |
65 } | |
66 | |
67 window = gnt_box_new(FALSE, TRUE); | |
68 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
69 gnt_box_set_title(GNT_BOX(window), title); | |
70 gnt_box_set_fill(GNT_BOX(window), FALSE); | |
71 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
72 | |
73 if (primary) | |
74 gnt_box_add_widget(GNT_BOX(window), | |
75 gnt_label_new_with_format(primary, pf)); | |
76 | |
77 button = gnt_button_new(_("OK")); | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
78 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
79 if (secondary) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
80 GntWidget *msg; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
81 if (type == PURPLE_NOTIFY_FORMATTED) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
82 int width = -1, height = -1; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
83 msg = gnt_text_view_new(); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
84 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(msg), secondary, sf); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
85 gnt_text_view_scroll(GNT_TEXT_VIEW(msg), 0); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
86 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(msg), button); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
87 gnt_util_get_text_bound(secondary, &width, &height); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
88 gnt_widget_set_size(msg, width + 3, height + 1); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
89 } else { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
90 msg = gnt_label_new_with_format(secondary, sf); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
91 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
92 gnt_box_add_widget(GNT_BOX(window), msg); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
93 g_object_set_data(G_OBJECT(window), "info-widget", msg); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
94 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
95 |
15818 | 96 gnt_box_add_widget(GNT_BOX(window), button); |
97 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
98 G_CALLBACK(gnt_widget_destroy), window); | |
99 g_signal_connect(G_OBJECT(window), "destroy", | |
100 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type)); | |
101 | |
102 gnt_widget_show(window); | |
103 return window; | |
104 } | |
105 | |
106 /* handle is, in all/most occasions, a GntWidget * */ | |
15823 | 107 static void finch_close_notify(PurpleNotifyType type, void *handle) |
15818 | 108 { |
109 GntWidget *widget = handle; | |
110 | |
111 if (!widget) | |
112 return; | |
113 | |
114 while (widget->parent) | |
115 widget = widget->parent; | |
116 | |
15823 | 117 if (type == PURPLE_NOTIFY_SEARCHRESULTS) |
118 purple_notify_searchresults_free(g_object_get_data(handle, "notify-results")); | |
15818 | 119 #if 1 |
120 /* This did not seem to be necessary */ | |
121 g_signal_handlers_disconnect_by_func(G_OBJECT(widget), | |
122 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type)); | |
123 #endif | |
124 gnt_widget_destroy(widget); | |
125 } | |
126 | |
127 static void *finch_notify_formatted(const char *title, const char *primary, | |
128 const char *secondary, const char *text) | |
129 { | |
130 /* XXX: For now, simply strip the html and use _notify_message. For future use, | |
131 * there should be some way of parsing the makrups from GntTextView */ | |
15823 | 132 char *unformat = purple_markup_strip_html(text); |
15818 | 133 char *t = g_strdup_printf("%s%s%s", |
134 secondary ? secondary : "", | |
135 secondary ? "\n" : "", | |
136 unformat ? unformat : ""); | |
137 | |
15823 | 138 void *ret = finch_notify_message(PURPLE_NOTIFY_FORMATTED, title, primary, t); |
15818 | 139 |
140 g_free(t); | |
141 g_free(unformat); | |
142 | |
143 return ret; | |
144 } | |
145 | |
146 static void | |
147 reset_email_dialog() | |
148 { | |
149 emaildialog.window = NULL; | |
150 emaildialog.tree = NULL; | |
151 } | |
152 | |
153 static void | |
154 setup_email_dialog() | |
155 { | |
156 GntWidget *box, *tree, *button; | |
157 if (emaildialog.window) | |
158 return; | |
159 | |
160 emaildialog.window = box = gnt_vbox_new(FALSE); | |
161 gnt_box_set_toplevel(GNT_BOX(box), TRUE); | |
162 gnt_box_set_title(GNT_BOX(box), _("Emails")); | |
163 gnt_box_set_fill(GNT_BOX(box), FALSE); | |
164 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); | |
165 gnt_box_set_pad(GNT_BOX(box), 0); | |
166 | |
167 gnt_box_add_widget(GNT_BOX(box), | |
168 gnt_label_new_with_format(_("You have mail!"), GNT_TEXT_FLAG_BOLD)); | |
169 | |
170 emaildialog.tree = tree = gnt_tree_new_with_columns(3); | |
171 gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("From"), _("Subject")); | |
172 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
173 gnt_tree_set_col_width(GNT_TREE(tree), 0, 15); | |
174 gnt_tree_set_col_width(GNT_TREE(tree), 1, 25); | |
175 gnt_tree_set_col_width(GNT_TREE(tree), 2, 25); | |
176 | |
177 gnt_box_add_widget(GNT_BOX(box), tree); | |
178 | |
179 button = gnt_button_new(_("Close")); | |
180 gnt_box_add_widget(GNT_BOX(box), button); | |
181 | |
182 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box); | |
183 g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL); | |
184 } | |
185 | |
186 static void * | |
15823 | 187 finch_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
15818 | 188 const char **subjects, const char **froms, const char **tos, |
189 const char **urls) | |
190 { | |
15823 | 191 PurpleAccount *account = purple_connection_get_account(gc); |
15818 | 192 GString *message = g_string_new(NULL); |
193 void *ret; | |
194 | |
195 if (!detailed) | |
196 { | |
197 g_string_append_printf(message, | |
198 ngettext("%s (%s) has %d new message.", | |
199 "%s (%s) has %d new messages.", | |
200 (int)count), | |
15823 | 201 tos ? *tos : purple_account_get_username(account), |
202 purple_account_get_protocol_name(account), (int)count); | |
15818 | 203 } |
204 else | |
205 { | |
206 char *to; | |
207 | |
208 setup_email_dialog(); | |
209 | |
15823 | 210 to = g_strdup_printf("%s (%s)", tos ? *tos : purple_account_get_username(account), |
211 purple_account_get_protocol_name(account)); | |
15818 | 212 gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), |
213 gnt_tree_create_row(GNT_TREE(emaildialog.tree), to, | |
214 froms ? *froms : "[Unknown sender]", | |
215 *subjects), | |
216 NULL, NULL); | |
217 g_free(to); | |
218 gnt_widget_show(emaildialog.window); | |
219 return NULL; | |
220 } | |
221 | |
15823 | 222 ret = finch_notify_message(PURPLE_NOTIFY_EMAIL, _("New Mail"), _("You have mail!"), message->str); |
15818 | 223 g_string_free(message, TRUE); |
224 return ret; | |
225 } | |
226 | |
227 static void * | |
15823 | 228 finch_notify_email(PurpleConnection *gc, const char *subject, const char *from, |
15818 | 229 const char *to, const char *url) |
230 { | |
231 return finch_notify_emails(gc, 1, subject != NULL, | |
232 subject ? &subject : NULL, | |
233 from ? &from : NULL, | |
234 to ? &to : NULL, | |
235 url ? &url : NULL); | |
236 } | |
237 | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
238 /** User information. **/ |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
239 static GHashTable *userinfo; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
240 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
241 static char * |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
242 userinfo_hash(PurpleAccount *account, const char *who) |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
243 { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
244 char key[256]; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
245 snprintf(key, sizeof(key), "%s - %s", purple_account_get_username(account), purple_normalize(account, who)); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
246 return g_utf8_strup(key, -1); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
247 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
248 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
249 static void |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
250 remove_userinfo(GntWidget *widget, gpointer key) |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
251 { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
252 g_hash_table_remove(userinfo, key); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
253 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
254 |
15818 | 255 static void * |
15823 | 256 finch_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) |
15818 | 257 { |
258 char *primary; | |
259 char *info; | |
260 void *ui_handle; | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
261 char *key = userinfo_hash(purple_connection_get_account(gc), who); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
262 |
15823 | 263 info = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
264 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
265 ui_handle = g_hash_table_lookup(userinfo, key); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
266 if (ui_handle != NULL) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
267 GntTextView *msg = GNT_TEXT_VIEW(g_object_get_data(G_OBJECT(ui_handle), "info-widget")); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
268 char *strip = purple_markup_strip_html(info); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
269 int tvw, tvh, width, height, ntvw, ntvh; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
270 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
271 gnt_widget_get_size(GNT_WIDGET(ui_handle), &width, &height); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
272 gnt_widget_get_size(GNT_WIDGET(msg), &tvw, &tvh); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
273 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
274 /* Ideally, I would replace the information in "info". But replacing tagged text is a |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
275 * bit nasty right now. So clear the view and add the new stuff instead. */ |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
276 gnt_text_view_clear(msg); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
277 gnt_text_view_append_text_with_flags(msg, strip, GNT_TEXT_FLAG_NORMAL); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
278 gnt_text_view_scroll(msg, 0); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
279 gnt_util_get_text_bound(strip, &ntvw, &ntvh); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
280 ntvw += 3; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
281 ntvh++; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
282 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
283 gnt_screen_resize_widget(GNT_WIDGET(ui_handle), width + (ntvw - tvw), height + (ntvh - tvh)); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
284 g_free(strip); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
285 g_free(key); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
286 } else { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
287 primary = g_strdup_printf(_("Info for %s"), who); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
288 ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
289 g_hash_table_insert(userinfo, key, ui_handle); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
290 g_free(primary); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
291 g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
292 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
293 |
15818 | 294 g_free(info); |
295 return ui_handle; | |
296 } | |
297 | |
298 static void | |
15823 | 299 notify_button_activated(GntWidget *widget, PurpleNotifySearchButton *b) |
15818 | 300 { |
301 GList *list = NULL; | |
15823 | 302 PurpleAccount *account = g_object_get_data(G_OBJECT(widget), "notify-account"); |
15818 | 303 gpointer data = g_object_get_data(G_OBJECT(widget), "notify-data"); |
304 | |
305 list = gnt_tree_get_selection_text_list(GNT_TREE(widget)); | |
306 | |
15823 | 307 b->callback(purple_account_get_connection(account), list, data); |
15818 | 308 g_list_foreach(list, (GFunc)g_free, NULL); |
309 g_list_free(list); | |
310 } | |
311 | |
312 static void | |
15823 | 313 finch_notify_sr_new_rows(PurpleConnection *gc, |
314 PurpleNotifySearchResults *results, void *data) | |
15818 | 315 { |
316 GntTree *tree = GNT_TREE(data); | |
317 GList *o; | |
318 | |
319 /* XXX: Do I need to empty the tree here? */ | |
320 | |
321 for (o = results->rows; o; o = o->next) | |
322 { | |
323 gnt_tree_add_row_after(GNT_TREE(tree), o->data, | |
324 gnt_tree_create_row_from_list(GNT_TREE(tree), o->data), | |
325 NULL, NULL); | |
326 } | |
327 } | |
328 | |
329 static void * | |
15823 | 330 finch_notify_searchresults(PurpleConnection *gc, const char *title, |
15818 | 331 const char *primary, const char *secondary, |
15823 | 332 PurpleNotifySearchResults *results, gpointer data) |
15818 | 333 { |
334 GntWidget *window, *tree, *box, *button; | |
335 GList *iter; | |
336 | |
337 window = gnt_vbox_new(FALSE); | |
338 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
339 gnt_box_set_title(GNT_BOX(window), title); | |
340 gnt_box_set_fill(GNT_BOX(window), FALSE); | |
341 gnt_box_set_pad(GNT_BOX(window), 0); | |
342 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
343 | |
344 gnt_box_add_widget(GNT_BOX(window), | |
345 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); | |
346 gnt_box_add_widget(GNT_BOX(window), | |
347 gnt_label_new_with_format(secondary, GNT_TEXT_FLAG_NORMAL)); | |
348 | |
349 tree = gnt_tree_new_with_columns(g_list_length(results->columns)); | |
350 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
351 gnt_box_add_widget(GNT_BOX(window), tree); | |
352 | |
353 box = gnt_hbox_new(TRUE); | |
354 | |
355 for (iter = results->buttons; iter; iter = iter->next) | |
356 { | |
15823 | 357 PurpleNotifySearchButton *b = iter->data; |
15818 | 358 const char *text; |
359 | |
360 switch (b->type) | |
361 { | |
15823 | 362 case PURPLE_NOTIFY_BUTTON_LABELED: |
15818 | 363 text = b->label; |
364 break; | |
15823 | 365 case PURPLE_NOTIFY_BUTTON_CONTINUE: |
15818 | 366 text = _("Continue"); |
367 break; | |
15823 | 368 case PURPLE_NOTIFY_BUTTON_ADD: |
15818 | 369 text = _("Add"); |
370 break; | |
15823 | 371 case PURPLE_NOTIFY_BUTTON_INFO: |
15818 | 372 text = _("Info"); |
373 break; | |
15823 | 374 case PURPLE_NOTIFY_BUTTON_IM: |
15818 | 375 text = _("IM"); |
376 break; | |
15823 | 377 case PURPLE_NOTIFY_BUTTON_JOIN: |
15818 | 378 text = _("Join"); |
379 break; | |
15823 | 380 case PURPLE_NOTIFY_BUTTON_INVITE: |
15818 | 381 text = _("Invite"); |
382 break; | |
383 default: | |
384 text = _("(none)"); | |
385 } | |
386 | |
387 button = gnt_button_new(text); | |
15823 | 388 g_object_set_data(G_OBJECT(button), "notify-account", purple_connection_get_account(gc)); |
15818 | 389 g_object_set_data(G_OBJECT(button), "notify-data", data); |
390 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
391 G_CALLBACK(notify_button_activated), b); | |
392 | |
393 gnt_box_add_widget(GNT_BOX(box), button); | |
394 } | |
395 | |
396 gnt_box_add_widget(GNT_BOX(window), box); | |
397 | |
398 finch_notify_sr_new_rows(gc, results, tree); | |
399 | |
400 gnt_widget_show(window); | |
401 g_object_set_data(G_OBJECT(window), "notify-results", results); | |
402 | |
403 return tree; | |
404 } | |
405 | |
15823 | 406 static PurpleNotifyUiOps ops = |
15818 | 407 { |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
408 finch_notify_message, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
409 finch_notify_email, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
410 finch_notify_emails, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
411 finch_notify_formatted, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
412 finch_notify_searchresults, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
413 finch_notify_sr_new_rows, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
414 finch_notify_userinfo, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
415 NULL, /* notify_uri is of low-priority to me. --sadrul */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
416 finch_close_notify, /* The rest of the notify-uiops return a GntWidget. |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
417 These widgets should be destroyed from here. */ |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
418 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
419 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
420 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16936
diff
changeset
|
421 NULL |
15818 | 422 |
423 }; | |
424 | |
15823 | 425 PurpleNotifyUiOps *finch_notify_get_ui_ops() |
15818 | 426 { |
427 return &ops; | |
428 } | |
429 | |
430 void finch_notify_init() | |
431 { | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
432 userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
15818 | 433 } |
434 | |
435 void finch_notify_uninit() | |
436 { | |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
437 g_hash_table_destroy(userinfo); |
15818 | 438 } |
439 | |
440 |