Ejemplo n.º 1
0
void hybrid_head_init()
{
	GtkWidget *align;

	hybrid_head = g_new0(HybridHead, 1);
	hybrid_head->vbox = gtk_vbox_new(FALSE, 0);
	hybrid_head->eventbox = gtk_event_box_new();
	hybrid_head->editbox = gtk_vbox_new(TRUE, 4);

	hybrid_head->cellview = gtk_cell_view_new();
	gtk_container_add(GTK_CONTAINER(hybrid_head->eventbox), 
	                  hybrid_head->cellview);

	hybrid_head->edit_label = gtk_label_new(NULL);
	hybrid_head->edit_entry = gtk_entry_new();

	align = gtk_alignment_new(0, 0, 0, 0);
	gtk_container_add(GTK_CONTAINER(align), hybrid_head->edit_label);
	gtk_box_pack_start(GTK_BOX(hybrid_head->editbox),
						align, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hybrid_head->editbox),
						hybrid_head->edit_entry, FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(hybrid_head->vbox), hybrid_head->eventbox,
						FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(hybrid_head->vbox), hybrid_head->editbox,
						FALSE, FALSE, 0);

	gtk_container_set_border_width(GTK_CONTAINER(hybrid_head->editbox), 3);

	g_signal_connect(G_OBJECT(hybrid_head->eventbox),
				     "button_press_event",
					 GTK_SIGNAL_FUNC(button_press_cb), NULL);

	g_signal_connect(G_OBJECT(hybrid_head->edit_entry),
				     "focus-out-event",
					 GTK_SIGNAL_FUNC(focus_out_cb), NULL);

	g_signal_connect(G_OBJECT(hybrid_head->edit_entry),
				     "activate",
					 GTK_SIGNAL_FUNC(entry_activate_cb), NULL);

	hybrid_tooltip_setup(hybrid_head->eventbox, NULL, NULL, tooltip_init, NULL);

	cell_view_init(hybrid_head);

	hybrid_head_bind_to_account(NULL);
}
Ejemplo n.º 2
0
/**
 * Create the buddy tips panel. We implement it with GtkCellView.
 * The layout is:
 *
 * -----------------------------------------------------
 * |         | Name                  |  Proto | Status |
 * |  Icon   |--------------(markup)-|  Icon  |  Icon  |
 * | (32×32) | Mood phrase           | (16×16)| (16×16)|
 * -----------------------------------------------------
 */
static void
create_buddy_tips_panel(GtkWidget *vbox, HybridChatWindow *chat)
{
    GtkWidget       *cellview;
    GtkListStore    *store;
    GtkCellRenderer *renderer;
    GtkTreePath     *path;
    HybridAccount   *account;
    HybridModule    *proto;
    HybridBuddy     *buddy;
    gchar           *name_text;
    gchar           *mood_text;
    GdkPixbuf       *icon_pixbuf;
    GdkPixbuf       *proto_pixbuf;
    GdkPixbuf       *presence_pixbuf;
    GtkWidget       *eventbox;

    g_return_if_fail(vbox != NULL);


    cellview = gtk_cell_view_new();

    store = gtk_list_store_new(LABEL_COLUMNS,
                               GDK_TYPE_PIXBUF,
                               G_TYPE_STRING,
                               GDK_TYPE_PIXBUF,
                               GDK_TYPE_PIXBUF);

    gtk_cell_view_set_model(GTK_CELL_VIEW(cellview), GTK_TREE_MODEL(store));

    /*
     * GtkCellView doesn't have a GdkWindow, we wrap it with an EventBox,
     * and then setup tooltip on the EventBox.
     */
    eventbox = gtk_event_box_new();
    gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE);
    gtk_container_add(GTK_CONTAINER(eventbox), cellview);

    /* buddy icon renderer */
    renderer = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer,
            "pixbuf", BUDDY_ICON_COLUMN, NULL);
    g_object_set(renderer, "yalign", 0.5, "xpad", 3, "ypad", 0, NULL);

    /* buddy name renderer */
    renderer = gtk_cell_renderer_text_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, TRUE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer,
            "markup", BUDDY_NAME_COLUMN, NULL);
    g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL);
    g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);

    /* protocol icon renderer */
    renderer = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer,
            "pixbuf", BUDDY_PROTO_ICON_COLUMN, NULL);
    g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL);

    /* status icon renderer */
    renderer = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cellview), renderer, FALSE);
    gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cellview), renderer,
            "pixbuf", BUDDY_STATUS_ICON_COLUMN, NULL);
    g_object_set(renderer, "xalign", 0.0, "xpad", 6, "ypad", 0, NULL);

    gtk_list_store_append(store, &chat->tipiter);
    path = gtk_tree_path_new_from_string("0");
    gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(cellview), path);
    gtk_tree_path_free(path);

    chat->tiplabel = cellview;

    if (IS_SYSTEM_CHAT(chat)) {

        buddy = chat->data;
        hybrid_tooltip_setup(eventbox, NULL, NULL, init_tooltip, buddy);

        icon_pixbuf = hybrid_create_round_pixbuf(buddy->icon_data,
                        buddy->icon_data_length, 32);

        presence_pixbuf = hybrid_create_presence_pixbuf(buddy->state, 16);

        mood_text = g_markup_escape_text(buddy->mood ? buddy->mood : "", -1);

        name_text = g_strdup_printf(
                "<b>%s</b>\n<small><span font=\"#8f8f8f\">%s</span></small>",
                buddy->name && *(buddy->name) != '\0' ? buddy->name : buddy->id,
                mood_text);

        gtk_list_store_set(store, &chat->tipiter,
                           BUDDY_ICON_COLUMN, icon_pixbuf,
                           BUDDY_NAME_COLUMN, name_text,
                           BUDDY_STATUS_ICON_COLUMN, presence_pixbuf, -1);

        g_object_unref(icon_pixbuf);
        g_object_unref(presence_pixbuf);

        g_free(name_text);
        g_free(mood_text);
    }

    account = chat->account;
    proto   = account->proto;

    proto_pixbuf = hybrid_create_proto_icon(proto->info->name, 16);

    gtk_list_store_set(store, &chat->tipiter,
                    BUDDY_PROTO_ICON_COLUMN, proto_pixbuf, -1);

    g_object_unref(proto_pixbuf);

    gtk_box_pack_start(GTK_BOX(vbox), eventbox, FALSE, FALSE, 5);
}