view console/gntdebug.c @ 14089:10e8eb6a4910

[gaim-migrate @ 16712] Pretty large commit here. Basically I got sick of having to verify that gc is still valid on all the callback functions for gaim_proxy_connect(). The fix for this for gaim_proxy_connect() to return something that allows the connection attempt to be canceled. It's not quite there yet, but this is a good first step. I changed gaim_proxy_connect() to return a reference to a new GaimProxyConnectInfo (this used to be called PHB). Eventually this can be passed to a function that'll cancel the connection attempt. I also decided to add an error_cb instead of using connect_cb and passing a file descriptor of -1. And proxy.c will also pass an error message to callers which should explain the reason that the connection attempt failed. Oh, and proxy.c now never calls gaim_connection_error() committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 12 Aug 2006 10:12:43 +0000
parents 2d1b41e3cf0d
children 7dfa024c1a4a
line wrap: on
line source

#include <gnt.h>
#include <gntbox.h>
#include <gnttextview.h>

#include "gntdebug.h"
#include "gntgaim.h"

#include <stdio.h>
#include <string.h>

static struct
{
	GntWidget *window;
	GntWidget *tview;
} debug;

static gboolean
debug_window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view)
{
	if (key[0] == 27)
	{
		if (strcmp(key+1, GNT_KEY_DOWN) == 0)
			gnt_text_view_scroll(view, 1);
		else if (strcmp(key+1, GNT_KEY_UP) == 0)
			gnt_text_view_scroll(view, -1);
		else if (strcmp(key+1, GNT_KEY_PGDOWN) == 0)
			gnt_text_view_scroll(view, wid->priv.height - 2);
		else if (strcmp(key+1, GNT_KEY_PGUP) == 0)
			gnt_text_view_scroll(view, -(wid->priv.height - 2));
		else
			return FALSE;
		return TRUE;
	}
	return FALSE;
}

static void
gg_debug_print(GaimDebugLevel level, const char *category,
		const char *args)
{
	if (debug.window)
	{
		GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;

		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				category, GNT_TEXT_FLAG_BOLD);
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				": ", GNT_TEXT_FLAG_BOLD);
		
		switch (level)
		{
			case GAIM_DEBUG_WARNING:
				flag |= GNT_TEXT_FLAG_UNDERLINE;
			case GAIM_DEBUG_ERROR:
			case GAIM_DEBUG_FATAL:
				flag |= GNT_TEXT_FLAG_BOLD;
				break;
			default:
				break;
		}
		
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag);
		gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0);
	}
}

static GaimDebugUiOps uiops = 
{
	gg_debug_print,
};

GaimDebugUiOps *gg_debug_get_ui_ops()
{
	return &uiops;
}

static void
reset_debug_win(GntWidget *w, gpointer null)
{
	debug.window = debug.tview = NULL;
}

void gg_debug_window_show()
{
	if (debug.window == NULL)
	{
		debug.window = gnt_vbox_new(FALSE);
		gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE);
		gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window"));

		debug.tview = gnt_text_view_new();
		gnt_box_add_widget(GNT_BOX(debug.window), debug.tview);

		/* XXX: Add checkboxes/buttons for Clear, Pause, Timestamps */

		g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL);
		g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview);
	}

	gnt_widget_show(debug.window);
}

void gg_debug_init()
{
	if (gaim_debug_is_enabled())
		gg_debug_window_show();
}

void gg_debug_uninit()
{
}