console/gntnotify.c

changeset 14041
6afba85cfc30
parent 14033
127990de806d
child 14050
800c76ca93f7
equal deleted inserted replaced
14040:d45421f147d1 14041:6afba85cfc30
55 } 55 }
56 56
57 /* handle is, in all/most occasions, a GntWidget * */ 57 /* handle is, in all/most occasions, a GntWidget * */
58 static void gg_close_notify(GaimNotifyType type, void *handle) 58 static void gg_close_notify(GaimNotifyType type, void *handle)
59 { 59 {
60 gnt_widget_destroy(GNT_WIDGET(handle)); 60 GntWidget *widget = handle;
61 while (widget->parent)
62 widget = widget->parent;
63
64 if (type == GAIM_NOTIFY_SEARCHRESULTS)
65 gaim_notify_searchresults_free(g_object_get_data(handle, "notify-results"));
66 gnt_widget_destroy(widget);
61 } 67 }
62 68
63 static void *gg_notify_formatted(const char *title, const char *primary, 69 static void *gg_notify_formatted(const char *title, const char *primary,
64 const char *secondary, const char *text) 70 const char *secondary, const char *text)
65 { 71 {
178 ui_handle = gg_notify_formatted(_("Buddy Information"), primary, NULL, text); 184 ui_handle = gg_notify_formatted(_("Buddy Information"), primary, NULL, text);
179 g_free(primary); 185 g_free(primary);
180 return ui_handle; 186 return ui_handle;
181 } 187 }
182 188
189 static void
190 notify_button_activated(GntWidget *widget, GaimNotifySearchButton *b)
191 {
192 GList *list = NULL;
193 GaimAccount *account = g_object_get_data(G_OBJECT(widget), "notify-account");
194 gpointer data = g_object_get_data(G_OBJECT(widget), "notify-data");
195
196 list = gnt_tree_get_selection_text_list(GNT_TREE(widget));
197
198 b->callback(gaim_account_get_connection(account), list, data);
199 g_list_foreach(list, (GFunc)g_free, NULL);
200 g_list_free(list);
201 }
202
203 static void
204 gg_notify_sr_new_rows(GaimConnection *gc,
205 GaimNotifySearchResults *results, void *data)
206 {
207 GntTree *tree = GNT_TREE(data);
208 GList *o;
209
210 /* XXX: Do I need to empty the tree here? */
211
212 for (o = results->rows; o; o = o->next)
213 {
214 gnt_tree_add_row_after(GNT_TREE(tree), o->data,
215 gnt_tree_create_row_from_list(GNT_TREE(tree), o->data),
216 NULL, NULL);
217 }
218 }
219
220 static void *
221 gg_notify_searchresults(GaimConnection *gc, const char *title,
222 const char *primary, const char *secondary,
223 GaimNotifySearchResults *results, gpointer data)
224 {
225 GntWidget *window, *tree, *box, *button;
226 GList *iter;
227
228 window = gnt_vbox_new(FALSE);
229 gnt_box_set_toplevel(GNT_BOX(window), TRUE);
230 gnt_box_set_title(GNT_BOX(window), title);
231 gnt_box_set_fill(GNT_BOX(window), FALSE);
232 gnt_box_set_pad(GNT_BOX(window), 0);
233 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
234
235 gnt_box_add_widget(GNT_BOX(window),
236 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD));
237 gnt_box_add_widget(GNT_BOX(window),
238 gnt_label_new_with_format(secondary, GNT_TEXT_FLAG_NORMAL));
239
240 tree = gnt_tree_new_with_columns(g_list_length(results->columns));
241 gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
242 gnt_box_add_widget(GNT_BOX(window), tree);
243
244 box = gnt_hbox_new(TRUE);
245
246 for (iter = results->buttons; iter; iter = iter->next)
247 {
248 GaimNotifySearchButton *b = iter->data;
249 const char *text;
250
251 switch (b->type)
252 {
253 case GAIM_NOTIFY_BUTTON_LABELED:
254 text = b->label;
255 break;
256 case GAIM_NOTIFY_BUTTON_CONTINUE:
257 text = _("Continue");
258 break;
259 case GAIM_NOTIFY_BUTTON_ADD:
260 text = _("Add");
261 break;
262 case GAIM_NOTIFY_BUTTON_INFO:
263 text = _("Info");
264 break;
265 case GAIM_NOTIFY_BUTTON_IM:
266 text = _("IM");
267 break;
268 case GAIM_NOTIFY_BUTTON_JOIN:
269 text = _("Join");
270 break;
271 case GAIM_NOTIFY_BUTTON_INVITE:
272 text = _("Invite");
273 break;
274 }
275
276 button = gnt_button_new(text);
277 g_object_set_data(G_OBJECT(button), "notify-account", gaim_connection_get_account(gc));
278 g_object_set_data(G_OBJECT(button), "notify-data", data);
279 g_signal_connect_swapped(G_OBJECT(button), "activate",
280 G_CALLBACK(notify_button_activated), b);
281
282 gnt_box_add_widget(GNT_BOX(box), button);
283 }
284
285 gnt_box_add_widget(GNT_BOX(window), box);
286
287 gg_notify_sr_new_rows(gc, results, tree);
288
289 gnt_widget_show(window);
290 g_object_set_data(G_OBJECT(window), "notify-results", results);
291
292 return tree;
293 }
294
183 static GaimNotifyUiOps ops = 295 static GaimNotifyUiOps ops =
184 { 296 {
185 .notify_message = gg_notify_message, 297 .notify_message = gg_notify_message,
186 .close_notify = gg_close_notify, /* The rest of the notify-uiops return a GntWidget. 298 .close_notify = gg_close_notify, /* The rest of the notify-uiops return a GntWidget.
187 These widgets should be destroyed from here. */ 299 These widgets should be destroyed from here. */
188 .notify_formatted = gg_notify_formatted, 300 .notify_formatted = gg_notify_formatted,
189 .notify_email = gg_notify_email, 301 .notify_email = gg_notify_email,
190 .notify_emails = gg_notify_emails, 302 .notify_emails = gg_notify_emails,
191 .notify_userinfo = gg_notify_userinfo, 303 .notify_userinfo = gg_notify_userinfo,
192 304
193 .notify_searchresults = NULL, /* We are going to need multi-column GntTree's for this */ 305 .notify_searchresults = gg_notify_searchresults,
194 .notify_searchresults_new_rows = NULL, 306 .notify_searchresults_new_rows = gg_notify_sr_new_rows,
195 .notify_uri = NULL /* This is of low-priority to me */ 307 .notify_uri = NULL /* This is of low-priority to me */
196 }; 308 };
197 309
198 GaimNotifyUiOps *gg_notify_get_ui_ops() 310 GaimNotifyUiOps *gg_notify_get_ui_ops()
199 { 311 {

mercurial