pidgin/plugins/disco/gtkdisco.c

changeset 40946
f3bb3efca77b
parent 40944
6e95a22ee02f
child 41030
ec8b76f3bf0a
equal deleted inserted replaced
40945:bbeb2e98ea5b 40946:f3bb3efca77b
416 { 416 {
417 gtk_widget_destroy(GTK_WIDGET(dialog)); 417 gtk_widget_destroy(GTK_WIDGET(dialog));
418 } 418 }
419 419
420 static gboolean 420 static gboolean
421 disco_paint_tooltip(GtkWidget *tipwindow, cairo_t *cr, gpointer data) 421 disco_query_tooltip(GtkWidget *widget, int x, int y, gboolean keyboard_mode,
422 { 422 GtkTooltip *tooltip, gpointer data)
423 PangoLayout *layout = g_object_get_data(G_OBJECT(tipwindow), "tooltip-plugin");
424 GtkStyleContext *context = gtk_widget_get_style_context(tipwindow);
425 gtk_style_context_add_class(context, GTK_STYLE_CLASS_TOOLTIP);
426 gtk_render_layout(context, cr, 6, 6, layout);
427 return TRUE;
428 }
429
430 static gboolean
431 disco_create_tooltip(GtkWidget *tipwindow, GtkTreePath *path,
432 gpointer data, int *w, int *h)
433 { 423 {
434 PidginDiscoDialog *dialog = data; 424 PidginDiscoDialog *dialog = data;
425 GtkTreePath *path = NULL;
435 GtkTreeIter iter; 426 GtkTreeIter iter;
436 PangoLayout *layout;
437 int width, height;
438 XmppDiscoService *service; 427 XmppDiscoService *service;
439 GValue val; 428 GValue val;
440 const char *type = NULL; 429 const char *type = NULL;
441 char *markup, *jid, *name, *desc = NULL; 430 char *markup, *jid, *name, *desc = NULL;
442 431
443 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, 432 if (keyboard_mode) {
444 path)) { 433 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
445 return FALSE; 434 if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) {
435 return FALSE;
436 }
437 path = gtk_tree_model_get_path(GTK_TREE_MODEL(dialog->model), &iter);
438 } else {
439 gint bx, by;
440
441 gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(widget),
442 x, y, &bx, &by);
443 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bx, by, &path,
444 NULL, NULL, NULL);
445 if (path == NULL) {
446 return FALSE;
447 }
448
449 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path)) {
450 gtk_tree_path_free(path);
451 return FALSE;
452 }
446 } 453 }
447 454
448 val.g_type = 0; 455 val.g_type = 0;
449 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model), &iter, 456 gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model), &iter,
450 SERVICE_COLUMN, &val); 457 SERVICE_COLUMN, &val);
451 service = g_value_get_pointer(&val); 458 service = g_value_get_pointer(&val);
452 if (!service) 459 if (!service) {
460 gtk_tree_path_free(path);
453 return FALSE; 461 return FALSE;
462 }
454 463
455 switch (service->type) { 464 switch (service->type) {
456 case XMPP_DISCO_SERVICE_TYPE_UNSET: 465 case XMPP_DISCO_SERVICE_TYPE_UNSET:
457 type = _("Unknown"); 466 type = _("Unknown");
458 break; 467 break;
487 type, 496 type,
488 jid = g_markup_escape_text(service->jid, -1), 497 jid = g_markup_escape_text(service->jid, -1),
489 service->description ? _("\n<b>Description:</b> ") : "", 498 service->description ? _("\n<b>Description:</b> ") : "",
490 service->description ? desc = g_markup_escape_text(service->description, -1) : ""); 499 service->description ? desc = g_markup_escape_text(service->description, -1) : "");
491 500
492 layout = gtk_widget_create_pango_layout(tipwindow, NULL); 501 gtk_tooltip_set_markup(tooltip, markup);
493 pango_layout_set_markup(layout, markup, -1); 502 gtk_tree_view_set_tooltip_row(GTK_TREE_VIEW(widget), tooltip, path);
494 pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
495 pango_layout_set_width(layout, 500000);
496 pango_layout_get_size(layout, &width, &height);
497 g_object_set_data_full(G_OBJECT(tipwindow), "tooltip-plugin", layout, g_object_unref);
498
499 if (w)
500 *w = PANGO_PIXELS(width) + 12;
501 if (h)
502 *h = PANGO_PIXELS(height) + 12;
503 503
504 g_free(markup); 504 g_free(markup);
505 g_free(jid); 505 g_free(jid);
506 g_free(name); 506 g_free(name);
507 g_free(desc); 507 g_free(desc);
508 gtk_tree_path_free(path);
508 509
509 return TRUE; 510 return TRUE;
510 } 511 }
511 512
512 void pidgin_disco_signed_off_cb(PurpleConnection *pc) 513 void pidgin_disco_signed_off_cb(PurpleConnection *pc)
615 PIDGIN_ACCOUNT_CHOOSER(dialog->account_chooser)); 616 PIDGIN_ACCOUNT_CHOOSER(dialog->account_chooser));
616 617
617 /* browse button */ 618 /* browse button */
618 gtk_widget_set_sensitive(dialog->browse_button, dialog->account != NULL); 619 gtk_widget_set_sensitive(dialog->browse_button, dialog->account != NULL);
619 620
620 pidgin_tooltip_setup_for_treeview(GTK_WIDGET(dialog->tree), dialog, 621 gtk_widget_set_has_tooltip(GTK_WIDGET(dialog->tree), TRUE);
621 disco_create_tooltip, 622 g_signal_connect(G_OBJECT(dialog->tree), "query-tooltip",
622 disco_paint_tooltip); 623 G_CALLBACK(disco_query_tooltip), dialog);
623 } 624 }
624 625
625 /****************************************************************************** 626 /******************************************************************************
626 * Public API 627 * Public API
627 *****************************************************************************/ 628 *****************************************************************************/

mercurial