annotate console/gntdebug.c @ 14162:cef7f6a93592

[gaim-migrate @ 16810] sf patch #1541754, from Sadrul Habib Chowdhury "Setting an account to 'offline' while it is connecting doesn't cause the connection to stop. This patch fixes that." committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 17 Aug 2006 06:21:28 +0000
parents 7dfa024c1a4a
children 43d9afee9c3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include <gnt.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2 #include <gntbox.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 #include <gnttextview.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 #include "gntdebug.h"
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 #include "gntgaim.h"
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 #include <stdio.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 #include <string.h>
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 static struct
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13 GntWidget *window;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 GntWidget *tview;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15 } debug;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
16
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 static gboolean
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
18 debug_window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
20 if (key[0] == 27)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
21 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
22 if (strcmp(key+1, GNT_KEY_DOWN) == 0)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
23 gnt_text_view_scroll(view, 1);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 else if (strcmp(key+1, GNT_KEY_UP) == 0)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
25 gnt_text_view_scroll(view, -1);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
26 else if (strcmp(key+1, GNT_KEY_PGDOWN) == 0)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
27 gnt_text_view_scroll(view, wid->priv.height - 2);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
28 else if (strcmp(key+1, GNT_KEY_PGUP) == 0)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 gnt_text_view_scroll(view, -(wid->priv.height - 2));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30 else
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 return FALSE;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 return TRUE;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 return FALSE;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 static void
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 gg_debug_print(GaimDebugLevel level, const char *category,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 const char *args)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 {
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13985
diff changeset
41 if (debug.window)
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
42 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
43 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
44
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
45 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
46 category, GNT_TEXT_FLAG_BOLD);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
47 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
48 ": ", GNT_TEXT_FLAG_BOLD);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
49
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
50 switch (level)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
51 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
52 case GAIM_DEBUG_WARNING:
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
53 flag |= GNT_TEXT_FLAG_UNDERLINE;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
54 case GAIM_DEBUG_ERROR:
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
55 case GAIM_DEBUG_FATAL:
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
56 flag |= GNT_TEXT_FLAG_BOLD;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
57 break;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
58 default:
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
59 break;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
60 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
61
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
62 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
63 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
64 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
65 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
66
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
67 static GaimDebugUiOps uiops =
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
68 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
69 gg_debug_print,
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
70 };
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
71
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
72 GaimDebugUiOps *gg_debug_get_ui_ops()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
73 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 return &uiops;
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76
13985
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
77 static void
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
78 reset_debug_win(GntWidget *w, gpointer null)
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
79 {
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
80 debug.window = debug.tview = NULL;
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
81 }
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
82
14125
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
83 static void
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
84 print_stderr(const char *string)
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
85 {
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
86 g_printerr("%s", string);
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
87 }
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
88
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 void gg_debug_window_show()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 if (debug.window == NULL)
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93 debug.window = gnt_vbox_new(FALSE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95 gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window"));
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 debug.tview = gnt_text_view_new();
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 gnt_box_add_widget(GNT_BOX(debug.window), debug.tview);
13985
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
99
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
100 /* XXX: Add checkboxes/buttons for Clear, Pause, Timestamps */
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
101
13985
a7b1d2ab9cb0 [gaim-migrate @ 16555]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13983
diff changeset
102 g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL);
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
103 g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview);
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 gnt_widget_show(debug.window);
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 void gg_debug_init()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 {
14125
7dfa024c1a4a [gaim-migrate @ 16763]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
111 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13985
diff changeset
112 if (gaim_debug_is_enabled())
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13985
diff changeset
113 gg_debug_window_show();
13983
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 void gg_debug_uninit()
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 {
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 }
b7a99d54a5a9 [gaim-migrate @ 16552]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119