Example #1
0
File: chat.c Project: VoxOx/VoxOx
/* merge this with the function below when we get everyone on the same page wrt /commands */
void jabber_chat_change_topic(JabberChat *chat, const char *topic)
{
	if(topic && *topic) {
		JabberMessage *jm;
		jm = g_new0(JabberMessage, 1);
		jm->js = chat->js;
		jm->type = JABBER_MESSAGE_GROUPCHAT;
		jm->subject = gaim_markup_strip_html(topic);
		jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
		jabber_message_send(jm);
		jabber_message_free(jm);
	} else {
		const char *cur = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(chat->conv));
		char *buf, *tmp, *tmp2;

		if(cur) {
			tmp = g_markup_escape_text(cur, -1);
			tmp2 = gaim_markup_linkify(tmp);
			buf = g_strdup_printf(_("current topic is: %s"), tmp2);
			g_free(tmp);
			g_free(tmp2);
		} else
			buf = g_strdup(_("No topic is set"));
		gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", buf,
				GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, time(NULL));
		g_free(buf);
	}

}
static void *
gaim_gtk_notify_formatted(const char *title, const char *primary,
                          const char *secondary, const char *text,
                          GCallback cb, void *user_data)
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *button;
    GtkWidget *imhtml;
    GtkWidget *sw;
    int options = 0;
    char label_text[2048];
    char *linked_text;

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), title);
    gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
    gtk_container_set_border_width(GTK_CONTAINER(window), 12);

    g_signal_connect(G_OBJECT(window), "delete_event",
                     G_CALLBACK(formatted_close_cb), NULL);

    /* Setup the main vbox */
    vbox = gtk_vbox_new(FALSE, 12);
    gtk_container_add(GTK_CONTAINER(window), vbox);
    gtk_widget_show(vbox);

    /* Setup the descriptive label */
    g_snprintf(label_text, sizeof(label_text),
               "<span weight=\"bold\" size=\"larger\">%s</span>%s%s",
               primary,
               (secondary ? "\n" : ""),
               (secondary ? secondary : ""));

    label = gtk_label_new(NULL);

    gtk_label_set_markup(GTK_LABEL(label), label_text);
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
    gtk_widget_show(label);

    /* Setup the scrolled window that we're putting the gtkimhtml in. */
    sw = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
                                   GTK_POLICY_NEVER,
                                   GTK_POLICY_ALWAYS);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
                                        GTK_SHADOW_IN);
    gtk_widget_set_size_request(sw, 300, 250);
    gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
    gtk_widget_show(sw);

    /* Now build that gtkimhtml */
    imhtml = gtk_imhtml_new(NULL, NULL);
    gtk_widget_set_name(imhtml, "gaim_gtknotify_imhtml");
    gtk_container_add(GTK_CONTAINER(sw), imhtml);
    gtk_widget_show(imhtml);
    gaim_setup_imhtml(imhtml);

    /* Add the Close button. */
    button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
    gtk_widget_show(button);

    g_signal_connect_swapped(G_OBJECT(button), "clicked",
                             G_CALLBACK(formatted_close_cb), window);
    g_signal_connect(G_OBJECT(window), "key_press_event",
                     G_CALLBACK(formatted_input_cb), NULL);


    /* Add the text to the gtkimhtml */
    if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_colors"))
        options ^= GTK_IMHTML_NO_COLOURS;
    if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_fonts"))
        options ^= GTK_IMHTML_NO_FONTS;
    if (gaim_prefs_get_bool("/gaim/gtk/conversations/ignore_font_sizes"))
        options ^= GTK_IMHTML_NO_SIZES;

    options ^= GTK_IMHTML_NO_COMMENTS;
    options ^= GTK_IMHTML_NO_TITLE;
    options ^= GTK_IMHTML_NO_NEWLINE;
    options ^= GTK_IMHTML_NO_SCROLL;

    /* Make sure URLs are clickable */
    linked_text = gaim_markup_linkify(text);
    gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text,
                           options);
    g_free(linked_text);

    /* Show the window */
    gtk_widget_show(window);

    return window;
}