pidgin/plugins/disco/gtkdisco.c

changeset 27315
898c56e61aa1
parent 27314
402d25ce01da
child 27316
4bcca82b93c1
equal deleted inserted replaced
27314:402d25ce01da 27315:898c56e61aa1
27 #include "internal.h" 27 #include "internal.h"
28 #include "debug.h" 28 #include "debug.h"
29 #include "gtkutils.h" 29 #include "gtkutils.h"
30 #include "pidgin.h" 30 #include "pidgin.h"
31 #include "request.h" 31 #include "request.h"
32 #include "pidgintooltip.h"
32 33
33 #include "gtkdisco.h" 34 #include "gtkdisco.h"
34 #include "xmppdisco.h" 35 #include "xmppdisco.h"
35 36
36 GList *dialogs = NULL; 37 GList *dialogs = NULL;
345 static gboolean account_filter_func(PurpleAccount *account) 346 static gboolean account_filter_func(PurpleAccount *account)
346 { 347 {
347 return purple_strequal(purple_account_get_protocol_id(account), XMPP_PLUGIN_ID); 348 return purple_strequal(purple_account_get_protocol_id(account), XMPP_PLUGIN_ID);
348 } 349 }
349 350
351 static gboolean
352 disco_paint_tooltip(GtkWidget *tipwindow, gpointer data)
353 {
354 PangoLayout *layout = g_object_get_data(G_OBJECT(tipwindow), "tooltip-plugin");
355 gtk_paint_layout(tipwindow->style, tipwindow->window, GTK_STATE_NORMAL, FALSE,
356 NULL, tipwindow, "tooltip",
357 6, 6, layout);
358 return TRUE;
359 }
360
361 static gboolean
362 disco_create_tooltip(GtkWidget *tipwindow, GtkTreePath *path,
363 gpointer data, int *w, int *h)
364 {
365 PidginDiscoList *pdl = data;
366 GtkTreeIter iter;
367 PangoLayout *layout;
368 int width, height;
369 XmppDiscoService *service;
370 GValue val;
371 const char *type = NULL;
372 char *markup, *jid, *name, *desc = NULL;
373
374 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(pdl->model), &iter, path))
375 return FALSE;
376
377 val.g_type = 0;
378 gtk_tree_model_get_value(GTK_TREE_MODEL(pdl->model), &iter, SERVICE_COLUMN,
379 &val);
380 service = g_value_get_pointer(&val);
381
382 switch (service->type) {
383 case XMPP_DISCO_SERVICE_TYPE_UNSET:
384 type = _("Unknown");
385 break;
386
387 case XMPP_DISCO_SERVICE_TYPE_GATEWAY:
388 type = _("Gateway");
389 break;
390
391 case XMPP_DISCO_SERVICE_TYPE_DIRECTORY:
392 type = _("Directory");
393 break;
394
395 case XMPP_DISCO_SERVICE_TYPE_CHAT:
396 type = _("Chat");
397 break;
398
399 case XMPP_DISCO_SERVICE_TYPE_PUBSUB_COLLECTION:
400 type = _("PubSub Collection");
401 break;
402
403 case XMPP_DISCO_SERVICE_TYPE_PUBSUB_LEAF:
404 type = _("PubSub Leaf");
405 break;
406
407 case XMPP_DISCO_SERVICE_TYPE_OTHER:
408 type = _("Other");
409 break;
410 }
411
412 markup = g_strdup_printf("<span size='x-large' weight='bold'>%s</span>\n<b>%s:</b> %s%s%s",
413 name = g_markup_escape_text(service->name, -1),
414 type,
415 jid = g_markup_escape_text(service->jid, -1),
416 service->description ? _("\n<b>Description:</b> ") : "",
417 service->description ? desc = g_markup_escape_text(service->description, -1) : "");
418
419 layout = gtk_widget_create_pango_layout(tipwindow, NULL);
420 pango_layout_set_markup(layout, markup, -1);
421 pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
422 pango_layout_set_width(layout, 500000);
423 pango_layout_get_size(layout, &width, &height);
424 g_object_set_data_full(G_OBJECT(tipwindow), "tooltip-plugin", layout, g_object_unref);
425
426 if (w)
427 *w = PANGO_PIXELS(width) + 12;
428 if (h)
429 *h = PANGO_PIXELS(height) + 12;
430
431 g_free(markup);
432 g_free(jid);
433 g_free(name);
434 g_free(desc);
435
436 return TRUE;
437 }
438
350 static void pidgin_disco_create_tree(PidginDiscoList *pdl) 439 static void pidgin_disco_create_tree(PidginDiscoList *pdl)
351 { 440 {
352 GtkCellRenderer *text_renderer, *pixbuf_renderer; 441 GtkCellRenderer *text_renderer, *pixbuf_renderer;
353 GtkTreeViewColumn *column; 442 GtkTreeViewColumn *column;
354 GtkTreeSelection *selection; 443 GtkTreeSelection *selection;
402 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE); 491 gtk_tree_view_column_set_reorderable(GTK_TREE_VIEW_COLUMN(column), TRUE);
403 gtk_tree_view_append_column(GTK_TREE_VIEW(pdl->tree), column); 492 gtk_tree_view_append_column(GTK_TREE_VIEW(pdl->tree), column);
404 493
405 g_signal_connect(G_OBJECT(pdl->tree), "row-expanded", G_CALLBACK(row_expanded_cb), pdl); 494 g_signal_connect(G_OBJECT(pdl->tree), "row-expanded", G_CALLBACK(row_expanded_cb), pdl);
406 g_signal_connect(G_OBJECT(pdl->tree), "row-activated", G_CALLBACK(row_activated_cb), pdl); 495 g_signal_connect(G_OBJECT(pdl->tree), "row-activated", G_CALLBACK(row_activated_cb), pdl);
496
497 pidgin_tooltip_setup_for_treeview(pdl->tree, pdl,
498 disco_create_tooltip,
499 disco_paint_tooltip);
407 } 500 }
408 501
409 void pidgin_disco_signed_off_cb(PurpleConnection *pc) 502 void pidgin_disco_signed_off_cb(PurpleConnection *pc)
410 { 503 {
411 GList *node; 504 GList *node;

mercurial