Mercurial > pidgin
changeset 13983:b7a99d54a5a9
[gaim-migrate @ 16552]
Add a debug window. The scrolling doesn't seem to work properly. I
will try to figure out what's wrong with it.
Start the request-ui. The ui for request input, choice and action are
mostly done. I am not handling multiline input requests yet. It's not
too high in my todo-list either.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 23 Jul 2006 20:38:07 +0000 |
parents | 052aee037835 |
children | 599b35acd842 |
files | console/Makefile console/gntdebug.c console/gntdebug.h console/gntgaim.c console/gntprefs.c console/gntprefs.h console/gntrequest.c console/gntrequest.h console/gntui.c console/libgnt/gntmain.c |
diffstat | 10 files changed, 392 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/console/Makefile Sun Jul 23 18:58:59 2006 +0000 +++ b/console/Makefile Sun Jul 23 20:38:07 2006 +0000 @@ -8,7 +8,10 @@ gntblist.c \ gntconn.c \ gntconv.c \ + gntdebug.c \ gntnotify.c \ + gntprefs.c \ + gntrequest.c \ gntui.c GG_HEADERS = \ @@ -16,7 +19,10 @@ gntblist.h \ gntconn.h \ gntconv.h \ + gntdebug.h \ gntnotify.h \ + gntprefs.h \ + gntrequest.h \ gntui.h GG_OBJECTS = \ @@ -24,7 +30,10 @@ gntblist.o \ gntconn.o \ gntconv.o \ + gntdebug.o \ gntnotify.o \ + gntprefs.o \ + gntrequest.o \ gntui.o all: gntgaim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntdebug.c Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,106 @@ +#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) + { + /* XXX: This doesn't seem to always work */ + 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 == NULL) + fprintf(stderr, "%s: %s\n", category, args); + else + { + 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_next_line(GNT_TEXT_VIEW(debug.tview)); + gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); + + g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview); + } +} + +static GaimDebugUiOps uiops = +{ + gg_debug_print, +}; + +GaimDebugUiOps *gg_debug_get_ui_ops() +{ + return &uiops; +} + +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); + } + + gnt_widget_show(debug.window); +} + +void gg_debug_init() +{ + gg_debug_window_show(); +} + +void gg_debug_uninit() +{ +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntdebug.h Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,8 @@ +#include "debug.h" + +GaimDebugUiOps *gg_debug_get_ui_ops(); + +void gg_debug_init(); + +void gg_debug_uninit(); +
--- a/console/gntgaim.c Sun Jul 23 18:58:59 2006 +0000 +++ b/console/gntgaim.c Sun Jul 23 20:38:07 2006 +0000 @@ -15,18 +15,25 @@ #include "util.h" #include "whiteboard.h" +#include "gntdebug.h" #include "gntgaim.h" +#include "gntprefs.h" #include "gntui.h" #define _GNU_SOURCE #include <getopt.h> -/* Anything IO-related is directly copied from gtkgaim's source tree */ +static void +debug_init() +{ + gg_debug_init(); + gaim_debug_set_ui_ops(gg_debug_get_ui_ops()); +} static GaimCoreUiOps core_ops = { - NULL, /*gaim_gtk_prefs_init,*/ - NULL, /*debug_init,*/ + gg_prefs_init, + debug_init, NULL, /*gaim_gtk_ui_init,*/ NULL, /*gaim_gtk_quit*/ }; @@ -37,6 +44,8 @@ return &core_ops; } +/* Anything IO-related is directly copied from gtkgaim's source tree */ + #define GAIM_GTK_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) #define GAIM_GTK_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) @@ -293,6 +302,8 @@ /* XXX: Don't puke */ freopen(".error", "w", stderr); + gnt_init(); + /* Initialize the libgaim stuff */ if (!init_libgaim(argc, argv)) return 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntprefs.c Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,14 @@ +#include <prefs.h> + +#include "gntprefs.h" +#include "gntgaim.h" + +void gg_prefs_init() +{ + gaim_prefs_add_none("/gaim"); + gaim_prefs_add_none("/gaim/gnt"); + + gaim_prefs_add_none("/gaim/gnt/plugins"); + gaim_prefs_add_string_list("/gaim/gnt/plugins/loaded", NULL); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntprefs.h Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,2 @@ +void gg_prefs_init(); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntrequest.c Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,218 @@ +#include <gnt.h> +#include <gntbox.h> +#include <gntbutton.h> +#include <gntcombobox.h> +#include <gntentry.h> +#include <gntlabel.h> + +#include "gntrequest.h" + +static GntWidget * +setup_request_window(const char *title, const char *primary, + const char *secondary) +{ + GntWidget *window; + + window = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), title); + gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); + + if (primary) + gnt_box_add_widget(GNT_BOX(window), + gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); + if (secondary) + gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary)); + + return window; +} + +static GntWidget * +setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...) +{ + GntWidget *box, *button; + va_list list; + const char *text; + gpointer callback; + + box = gnt_hbox_new(TRUE); + + va_start(list, data); + + while ((text = va_arg(list, const char *))) + { + callback = va_arg(list, gpointer); + button = gnt_button_new(text); + gnt_box_add_widget(GNT_BOX(box), button); + g_object_set_data(G_OBJECT(button), "activate-callback", callback); + g_object_set_data(G_OBJECT(button), "activate-userdata", userdata); + g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data); + } + + va_end(list); + return box; +} + +static void +notify_input_cb(GntWidget *button, GntWidget *entry) +{ + GaimRequestInputCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); + gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); + const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); + + if (callback) + callback(data, text); + + while (button->parent) + button = button->parent; + + gaim_request_close(GAIM_REQUEST_INPUT, button); +} + +static void * +gg_request_input(const char *title, const char *primary, + const char *secondary, const char *default_value, + gboolean multiline, gboolean masked, gchar *hint, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + void *user_data) +{ + GntWidget *window, *box, *entry; + + window = setup_request_window(title, primary, secondary); + + entry = gnt_entry_new(default_value); + if (masked) + gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); + gnt_box_add_widget(GNT_BOX(window), entry); + + box = setup_button_box(user_data, notify_input_cb, entry, + ok_text, ok_cb, cancel_text, cancel_cb, NULL); + gnt_box_add_widget(GNT_BOX(window), box); + + gnt_widget_show(window); + + return window; +} + +static void +gg_close_request(GaimRequestType type, gpointer ui_handle) +{ + GntWidget *widget = GNT_WIDGET(ui_handle); + while (widget->parent) + widget = widget->parent; + gnt_widget_destroy(widget); +} + +static void +request_choice_cb(GntWidget *button, GntComboBox *combo) +{ + GaimRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); + gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); + int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1; + + if (callback) + callback(data, choice); + + while (button->parent) + button = button->parent; + + gaim_request_close(GAIM_REQUEST_INPUT, button); +} + +static void * +gg_request_choice(const char *title, const char *primary, + const char *secondary, unsigned int default_value, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + void *user_data, va_list choices) +{ + GntWidget *window, *combo, *box; + const char *text; + int val; + + window = setup_request_window(title, primary, secondary); + + combo = gnt_combo_box_new(); + gnt_box_add_widget(GNT_BOX(window), combo); + while ((text = va_arg(choices, const char *))) + { + val = va_arg(choices, int); + gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text); + } + gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1)); + + box = setup_button_box(user_data, request_choice_cb, combo, + ok_text, ok_cb, cancel_text, cancel_cb, NULL); + gnt_box_add_widget(GNT_BOX(window), box); + + gnt_widget_show(window); + + return window; +} + +static void +request_action_cb(GntWidget *button, GntWidget *window) +{ + GaimRequestActionCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); + gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); + int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "activate-id")); + + callback(data, id); + + gaim_request_close(GAIM_REQUEST_ACTION, window); +} + +static void* +gg_request_action(const char *title, const char *primary, + const char *secondary, unsigned int default_value, + void *user_data, size_t actioncount, + va_list actions) +{ + GntWidget *window, *box, *button; + int i; + + window = setup_request_window(title, primary, secondary); + + box = gnt_hbox_new(TRUE); + gnt_box_add_widget(GNT_BOX(window), box); + for (i = 0; i < actioncount; i++) + { + const char *text = va_arg(actions, const char *); + GaimRequestActionCb callback = va_arg(actions, GaimRequestActionCb); + + button = gnt_button_new(text); + gnt_box_add_widget(GNT_BOX(box), button); + + g_object_set_data(G_OBJECT(button), "activate-callback", callback); + g_object_set_data(G_OBJECT(button), "activate-userdata", user_data); + g_object_set_data(G_OBJECT(button), "activate-id", GINT_TO_POINTER(i)); + g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(request_action_cb), window); + } + + gnt_widget_show(window); + + return window; +} + +static GaimRequestUiOps uiops = +{ + .request_input = gg_request_input, + .close_request = gg_close_request, + .request_choice = gg_request_choice, + .request_action = gg_request_action, +}; + +GaimRequestUiOps *gg_request_get_ui_ops() +{ + return &uiops; +} + +void gg_request_init() +{ +} + +void gg_request_uninit() +{ +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/console/gntrequest.h Sun Jul 23 20:38:07 2006 +0000 @@ -0,0 +1,8 @@ +#include "request.h" + +GaimRequestUiOps *gg_request_get_ui_ops(); + +void gg_request_init(); + +void gg_request_uninit(); +
--- a/console/gntui.c Sun Jul 23 18:58:59 2006 +0000 +++ b/console/gntui.c Sun Jul 23 20:38:07 2006 +0000 @@ -5,6 +5,7 @@ #include "gntconn.h" #include "gntconv.h" #include "gntnotify.h" +#include "gntrequest.h" void init_gnt_ui() { @@ -31,6 +32,9 @@ gg_notify_init(); gaim_notify_set_ui_ops(gg_notify_get_ui_ops()); + gg_request_init(); + gaim_request_set_ui_ops(gg_request_get_ui_ops()); + #ifdef STANDALONE gnt_main(); @@ -49,6 +53,9 @@ gaim_notify_set_ui_ops(NULL); gg_notify_uninit(); + gaim_request_set_ui_ops(NULL); + gg_request_uninit(); + gnt_quit(); #endif }
--- a/console/libgnt/gntmain.c Sun Jul 23 18:58:59 2006 +0000 +++ b/console/libgnt/gntmain.c Sun Jul 23 20:38:07 2006 +0000 @@ -524,7 +524,12 @@ void gnt_init() { - GIOChannel *channel = g_io_channel_unix_new(0); + static GIOChannel *channel = NULL; + + if (channel) + return; + + channel = g_io_channel_unix_new(0); g_io_channel_set_encoding(channel, NULL, NULL); g_io_channel_set_buffered(channel, FALSE);