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