Mercurial > pidgin
annotate finch/gntnotify.c @ 18203:c23aef39f9bb
merge of '088881d37b32f572377200c693a5d9662e4e3586'
and 'c8ccb9550c625221a5a784368b13cfb5bf821c00'
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Tue, 19 Jun 2007 23:52:23 +0000 |
parents | 7f652ef12ed6 |
children | b8572b937c09 |
rev | line source |
---|---|
15817 | 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:
15870
diff
changeset
|
3 * @ingroup finch |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 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> | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
30 #include <gntutils.h> |
15817 | 31 |
32 #include <util.h> | |
33 | |
34 #include "gntnotify.h" | |
15822 | 35 #include "finch.h" |
15817 | 36 |
37 static struct | |
38 { | |
39 GntWidget *window; | |
40 GntWidget *tree; | |
41 } emaildialog; | |
42 | |
43 static void | |
15822 | 44 notify_msg_window_destroy_cb(GntWidget *window, PurpleNotifyMsgType type) |
15817 | 45 { |
15822 | 46 purple_notify_close(type, window); |
15817 | 47 } |
48 | |
49 static void * | |
15822 | 50 finch_notify_message(PurpleNotifyMsgType type, const char *title, |
15817 | 51 const char *primary, const char *secondary) |
52 { | |
53 GntWidget *window, *button; | |
54 GntTextFormatFlags pf = 0, sf = 0; | |
55 | |
56 switch (type) | |
57 { | |
15822 | 58 case PURPLE_NOTIFY_MSG_ERROR: |
15817 | 59 sf |= GNT_TEXT_FLAG_BOLD; |
15822 | 60 case PURPLE_NOTIFY_MSG_WARNING: |
15817 | 61 pf |= GNT_TEXT_FLAG_UNDERLINE; |
15822 | 62 case PURPLE_NOTIFY_MSG_INFO: |
15817 | 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); | |
17805
7f652ef12ed6
Remove the confusing 'OK' button from the auth dialog.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17804
diff
changeset
|
72 gnt_box_set_pad(GNT_BOX(window), 0); |
15817 | 73 |
74 if (primary) | |
75 gnt_box_add_widget(GNT_BOX(window), | |
76 gnt_label_new_with_format(primary, pf)); | |
77 | |
78 button = gnt_button_new(_("OK")); | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
79 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
80 if (secondary) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
81 GntWidget *msg; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
82 if (type == PURPLE_NOTIFY_FORMATTED) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
83 int width = -1, height = -1; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
84 msg = gnt_text_view_new(); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 } else { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
91 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
|
92 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
93 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
|
94 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
|
95 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
96 |
15817 | 97 gnt_box_add_widget(GNT_BOX(window), button); |
98 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
99 G_CALLBACK(gnt_widget_destroy), window); | |
100 g_signal_connect(G_OBJECT(window), "destroy", | |
101 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type)); | |
102 | |
103 gnt_widget_show(window); | |
104 return window; | |
105 } | |
106 | |
107 /* handle is, in all/most occasions, a GntWidget * */ | |
15822 | 108 static void finch_close_notify(PurpleNotifyType type, void *handle) |
15817 | 109 { |
110 GntWidget *widget = handle; | |
111 | |
112 if (!widget) | |
113 return; | |
114 | |
115 while (widget->parent) | |
116 widget = widget->parent; | |
117 | |
15822 | 118 if (type == PURPLE_NOTIFY_SEARCHRESULTS) |
119 purple_notify_searchresults_free(g_object_get_data(handle, "notify-results")); | |
15817 | 120 #if 1 |
121 /* This did not seem to be necessary */ | |
122 g_signal_handlers_disconnect_by_func(G_OBJECT(widget), | |
123 G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(type)); | |
124 #endif | |
125 gnt_widget_destroy(widget); | |
126 } | |
127 | |
128 static void *finch_notify_formatted(const char *title, const char *primary, | |
129 const char *secondary, const char *text) | |
130 { | |
131 /* XXX: For now, simply strip the html and use _notify_message. For future use, | |
132 * there should be some way of parsing the makrups from GntTextView */ | |
15822 | 133 char *unformat = purple_markup_strip_html(text); |
15817 | 134 char *t = g_strdup_printf("%s%s%s", |
135 secondary ? secondary : "", | |
136 secondary ? "\n" : "", | |
137 unformat ? unformat : ""); | |
138 | |
15822 | 139 void *ret = finch_notify_message(PURPLE_NOTIFY_FORMATTED, title, primary, t); |
15817 | 140 |
141 g_free(t); | |
142 g_free(unformat); | |
143 | |
144 return ret; | |
145 } | |
146 | |
147 static void | |
148 reset_email_dialog() | |
149 { | |
150 emaildialog.window = NULL; | |
151 emaildialog.tree = NULL; | |
152 } | |
153 | |
154 static void | |
155 setup_email_dialog() | |
156 { | |
157 GntWidget *box, *tree, *button; | |
158 if (emaildialog.window) | |
159 return; | |
160 | |
161 emaildialog.window = box = gnt_vbox_new(FALSE); | |
162 gnt_box_set_toplevel(GNT_BOX(box), TRUE); | |
163 gnt_box_set_title(GNT_BOX(box), _("Emails")); | |
164 gnt_box_set_fill(GNT_BOX(box), FALSE); | |
165 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); | |
166 gnt_box_set_pad(GNT_BOX(box), 0); | |
167 | |
168 gnt_box_add_widget(GNT_BOX(box), | |
169 gnt_label_new_with_format(_("You have mail!"), GNT_TEXT_FLAG_BOLD)); | |
170 | |
171 emaildialog.tree = tree = gnt_tree_new_with_columns(3); | |
17747 | 172 gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("Sender"), _("Subject")); |
15817 | 173 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); |
174 gnt_tree_set_col_width(GNT_TREE(tree), 0, 15); | |
175 gnt_tree_set_col_width(GNT_TREE(tree), 1, 25); | |
176 gnt_tree_set_col_width(GNT_TREE(tree), 2, 25); | |
177 | |
178 gnt_box_add_widget(GNT_BOX(box), tree); | |
179 | |
180 button = gnt_button_new(_("Close")); | |
181 gnt_box_add_widget(GNT_BOX(box), button); | |
182 | |
183 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box); | |
184 g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL); | |
185 } | |
186 | |
187 static void * | |
15822 | 188 finch_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
15817 | 189 const char **subjects, const char **froms, const char **tos, |
190 const char **urls) | |
191 { | |
15822 | 192 PurpleAccount *account = purple_connection_get_account(gc); |
15817 | 193 GString *message = g_string_new(NULL); |
194 void *ret; | |
195 | |
196 if (!detailed) | |
197 { | |
198 g_string_append_printf(message, | |
199 ngettext("%s (%s) has %d new message.", | |
200 "%s (%s) has %d new messages.", | |
201 (int)count), | |
15822 | 202 tos ? *tos : purple_account_get_username(account), |
203 purple_account_get_protocol_name(account), (int)count); | |
15817 | 204 } |
205 else | |
206 { | |
207 char *to; | |
208 | |
209 setup_email_dialog(); | |
210 | |
15822 | 211 to = g_strdup_printf("%s (%s)", tos ? *tos : purple_account_get_username(account), |
212 purple_account_get_protocol_name(account)); | |
15817 | 213 gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), |
214 gnt_tree_create_row(GNT_TREE(emaildialog.tree), to, | |
215 froms ? *froms : "[Unknown sender]", | |
216 *subjects), | |
217 NULL, NULL); | |
218 g_free(to); | |
219 gnt_widget_show(emaildialog.window); | |
220 return NULL; | |
221 } | |
222 | |
15822 | 223 ret = finch_notify_message(PURPLE_NOTIFY_EMAIL, _("New Mail"), _("You have mail!"), message->str); |
15817 | 224 g_string_free(message, TRUE); |
225 return ret; | |
226 } | |
227 | |
228 static void * | |
15822 | 229 finch_notify_email(PurpleConnection *gc, const char *subject, const char *from, |
15817 | 230 const char *to, const char *url) |
231 { | |
232 return finch_notify_emails(gc, 1, subject != NULL, | |
233 subject ? &subject : NULL, | |
234 from ? &from : NULL, | |
235 to ? &to : NULL, | |
236 url ? &url : NULL); | |
237 } | |
238 | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
239 /** User information. **/ |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
240 static GHashTable *userinfo; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
241 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
242 static char * |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
243 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
|
244 { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
245 char key[256]; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
246 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
|
247 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
|
248 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
249 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
250 static void |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
251 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
|
252 { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
253 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
|
254 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
255 |
15817 | 256 static void * |
15822 | 257 finch_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) |
15817 | 258 { |
259 char *primary; | |
260 char *info; | |
261 void *ui_handle; | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
262 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
|
263 |
15822 | 264 info = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
265 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
266 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
|
267 if (ui_handle != NULL) { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17747
diff
changeset
|
272 while (GNT_WIDGET(ui_handle)->parent) |
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17747
diff
changeset
|
273 ui_handle = GNT_WIDGET(ui_handle)->parent; |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
274 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
|
275 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
|
276 |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
277 gnt_text_view_clear(msg); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 ntvw += 3; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
282 ntvh++; |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
283 |
17804
464840043c66
Show information about the user requesting authorization.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17747
diff
changeset
|
284 gnt_screen_resize_widget(GNT_WIDGET(ui_handle), width + MAX(0, ntvw - tvw), height + MAX(0, ntvh - tvh)); |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
285 g_free(strip); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
286 g_free(key); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
287 } else { |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 g_free(primary); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
292 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
|
293 } |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
294 |
15817 | 295 g_free(info); |
296 return ui_handle; | |
297 } | |
298 | |
299 static void | |
15822 | 300 notify_button_activated(GntWidget *widget, PurpleNotifySearchButton *b) |
15817 | 301 { |
302 GList *list = NULL; | |
15822 | 303 PurpleAccount *account = g_object_get_data(G_OBJECT(widget), "notify-account"); |
15817 | 304 gpointer data = g_object_get_data(G_OBJECT(widget), "notify-data"); |
305 | |
306 list = gnt_tree_get_selection_text_list(GNT_TREE(widget)); | |
307 | |
15822 | 308 b->callback(purple_account_get_connection(account), list, data); |
15817 | 309 g_list_foreach(list, (GFunc)g_free, NULL); |
310 g_list_free(list); | |
311 } | |
312 | |
313 static void | |
15822 | 314 finch_notify_sr_new_rows(PurpleConnection *gc, |
315 PurpleNotifySearchResults *results, void *data) | |
15817 | 316 { |
317 GntTree *tree = GNT_TREE(data); | |
318 GList *o; | |
319 | |
320 /* XXX: Do I need to empty the tree here? */ | |
321 | |
322 for (o = results->rows; o; o = o->next) | |
323 { | |
324 gnt_tree_add_row_after(GNT_TREE(tree), o->data, | |
325 gnt_tree_create_row_from_list(GNT_TREE(tree), o->data), | |
326 NULL, NULL); | |
327 } | |
328 } | |
329 | |
330 static void * | |
15822 | 331 finch_notify_searchresults(PurpleConnection *gc, const char *title, |
15817 | 332 const char *primary, const char *secondary, |
15822 | 333 PurpleNotifySearchResults *results, gpointer data) |
15817 | 334 { |
335 GntWidget *window, *tree, *box, *button; | |
336 GList *iter; | |
337 | |
338 window = gnt_vbox_new(FALSE); | |
339 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
340 gnt_box_set_title(GNT_BOX(window), title); | |
341 gnt_box_set_fill(GNT_BOX(window), FALSE); | |
342 gnt_box_set_pad(GNT_BOX(window), 0); | |
343 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
344 | |
345 gnt_box_add_widget(GNT_BOX(window), | |
346 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); | |
347 gnt_box_add_widget(GNT_BOX(window), | |
348 gnt_label_new_with_format(secondary, GNT_TEXT_FLAG_NORMAL)); | |
349 | |
350 tree = gnt_tree_new_with_columns(g_list_length(results->columns)); | |
351 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | |
352 gnt_box_add_widget(GNT_BOX(window), tree); | |
353 | |
354 box = gnt_hbox_new(TRUE); | |
355 | |
356 for (iter = results->buttons; iter; iter = iter->next) | |
357 { | |
15822 | 358 PurpleNotifySearchButton *b = iter->data; |
15817 | 359 const char *text; |
360 | |
361 switch (b->type) | |
362 { | |
15822 | 363 case PURPLE_NOTIFY_BUTTON_LABELED: |
15817 | 364 text = b->label; |
365 break; | |
15822 | 366 case PURPLE_NOTIFY_BUTTON_CONTINUE: |
15817 | 367 text = _("Continue"); |
368 break; | |
15822 | 369 case PURPLE_NOTIFY_BUTTON_ADD: |
15817 | 370 text = _("Add"); |
371 break; | |
15822 | 372 case PURPLE_NOTIFY_BUTTON_INFO: |
15817 | 373 text = _("Info"); |
374 break; | |
15822 | 375 case PURPLE_NOTIFY_BUTTON_IM: |
15817 | 376 text = _("IM"); |
377 break; | |
15822 | 378 case PURPLE_NOTIFY_BUTTON_JOIN: |
15817 | 379 text = _("Join"); |
380 break; | |
15822 | 381 case PURPLE_NOTIFY_BUTTON_INVITE: |
15817 | 382 text = _("Invite"); |
383 break; | |
384 default: | |
385 text = _("(none)"); | |
386 } | |
387 | |
388 button = gnt_button_new(text); | |
15822 | 389 g_object_set_data(G_OBJECT(button), "notify-account", purple_connection_get_account(gc)); |
15817 | 390 g_object_set_data(G_OBJECT(button), "notify-data", data); |
391 g_signal_connect_swapped(G_OBJECT(button), "activate", | |
392 G_CALLBACK(notify_button_activated), b); | |
393 | |
394 gnt_box_add_widget(GNT_BOX(box), button); | |
395 } | |
396 | |
397 gnt_box_add_widget(GNT_BOX(window), box); | |
398 | |
399 finch_notify_sr_new_rows(gc, results, tree); | |
400 | |
401 gnt_widget_show(window); | |
402 g_object_set_data(G_OBJECT(window), "notify-results", results); | |
403 | |
404 return tree; | |
405 } | |
406 | |
15822 | 407 static PurpleNotifyUiOps ops = |
15817 | 408 { |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
409 finch_notify_message, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
410 finch_notify_email, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
411 finch_notify_emails, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
412 finch_notify_formatted, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
413 finch_notify_searchresults, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
414 finch_notify_sr_new_rows, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
415 finch_notify_userinfo, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
416 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:
16925
diff
changeset
|
417 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:
16925
diff
changeset
|
418 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:
16925
diff
changeset
|
419 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
420 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
421 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16925
diff
changeset
|
422 NULL |
15817 | 423 |
424 }; | |
425 | |
15822 | 426 PurpleNotifyUiOps *finch_notify_get_ui_ops() |
15817 | 427 { |
428 return &ops; | |
429 } | |
430 | |
431 void finch_notify_init() | |
432 { | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
433 userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
15817 | 434 } |
435 | |
436 void finch_notify_uninit() | |
437 { | |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
438 g_hash_table_destroy(userinfo); |
15817 | 439 } |
440 | |
441 |