From: <ro...@us...> - 2006-07-21 03:35:18
|
Revision: 16535 Author: roast Date: 2006-07-20 20:34:03 -0700 (Thu, 20 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16535&view=rev Log Message: ----------- merged with svn trunk. 16498:16534. Modified Paths: -------------- branches/soc-2006-file-loggers/console/Makefile branches/soc-2006-file-loggers/console/gntaccount.c branches/soc-2006-file-loggers/console/gntblist.c branches/soc-2006-file-loggers/console/gntconv.c branches/soc-2006-file-loggers/console/gntgaim.c branches/soc-2006-file-loggers/console/gntgaim.h branches/soc-2006-file-loggers/console/gntui.c branches/soc-2006-file-loggers/console/libgnt/gntbox.c branches/soc-2006-file-loggers/console/libgnt/gntbox.h branches/soc-2006-file-loggers/console/libgnt/gntcolors.c branches/soc-2006-file-loggers/console/libgnt/gntcolors.h branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c branches/soc-2006-file-loggers/console/libgnt/gntlabel.c branches/soc-2006-file-loggers/console/libgnt/gntlabel.h branches/soc-2006-file-loggers/console/libgnt/gntline.h branches/soc-2006-file-loggers/console/libgnt/gntmain.c branches/soc-2006-file-loggers/console/libgnt/gnttextview.c branches/soc-2006-file-loggers/console/libgnt/gnttextview.h branches/soc-2006-file-loggers/console/libgnt/gnttree.c branches/soc-2006-file-loggers/console/libgnt/gnttree.h branches/soc-2006-file-loggers/console/libgnt/test/Makefile branches/soc-2006-file-loggers/console/libgnt/test/combo.c branches/soc-2006-file-loggers/console/libgnt/test/focus.c branches/soc-2006-file-loggers/console/libgnt/test/multiwin.c branches/soc-2006-file-loggers/console/libgnt/test/tv.c branches/soc-2006-file-loggers/plugins/dbus-example.c branches/soc-2006-file-loggers/plugins/musicmessaging/musicmessaging.c branches/soc-2006-file-loggers/plugins/tcl/tcl.c branches/soc-2006-file-loggers/src/buddyicon.h branches/soc-2006-file-loggers/src/connection.c branches/soc-2006-file-loggers/src/connection.h branches/soc-2006-file-loggers/src/conversation.c branches/soc-2006-file-loggers/src/conversation.h branches/soc-2006-file-loggers/src/core.c branches/soc-2006-file-loggers/src/dbus-server.c branches/soc-2006-file-loggers/src/dbus-server.h branches/soc-2006-file-loggers/src/gtkblist.c branches/soc-2006-file-loggers/src/gtkconv.c branches/soc-2006-file-loggers/src/gtkconv.h branches/soc-2006-file-loggers/src/gtknotify.c branches/soc-2006-file-loggers/src/log.c branches/soc-2006-file-loggers/src/notify.c branches/soc-2006-file-loggers/src/plugin.c branches/soc-2006-file-loggers/src/protocols/jabber/jabber.c branches/soc-2006-file-loggers/src/protocols/jabber/presence.c branches/soc-2006-file-loggers/src/protocols/jabber/roster.c branches/soc-2006-file-loggers/src/protocols/msn/dialog.c branches/soc-2006-file-loggers/src/protocols/msn/slp.c branches/soc-2006-file-loggers/src/protocols/msn/slplink.c branches/soc-2006-file-loggers/src/protocols/msn/switchboard.c branches/soc-2006-file-loggers/src/protocols/msn/switchboard.h branches/soc-2006-file-loggers/src/protocols/msn/user.c branches/soc-2006-file-loggers/src/protocols/msn/userlist.c branches/soc-2006-file-loggers/src/protocols/oscar/family_icbm.c branches/soc-2006-file-loggers/src/protocols/oscar/oscar.c branches/soc-2006-file-loggers/src/protocols/oscar/peer.c branches/soc-2006-file-loggers/src/protocols/oscar/peer_proxy.c branches/soc-2006-file-loggers/src/protocols/sametime/sametime.c branches/soc-2006-file-loggers/src/protocols/silc/silc.c branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo.c branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo_picture.c branches/soc-2006-file-loggers/src/protocols/yahoo/yahoo_picture.h branches/soc-2006-file-loggers/src/protocols/yahoo/yahoochat.c branches/soc-2006-file-loggers/src/proxy.c branches/soc-2006-file-loggers/src/signals.c branches/soc-2006-file-loggers/src/util.h Added Paths: ----------- branches/soc-2006-file-loggers/console/gntconn.c branches/soc-2006-file-loggers/console/gntconn.h branches/soc-2006-file-loggers/console/gntnotify.c branches/soc-2006-file-loggers/console/gntnotify.h branches/soc-2006-file-loggers/console/libgnt/test/wm.c Modified: branches/soc-2006-file-loggers/console/Makefile =================================================================== --- branches/soc-2006-file-loggers/console/Makefile 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/Makefile 2006-07-21 03:34:03 UTC (rev 16535) @@ -1,24 +1,30 @@ VERSION=gntgaim-0.0.0dev CC=gcc -CFLAGS=`pkg-config --cflags gaim gobject-2.0 gnt` -g -Wall -DVERSION=\"$(VERSION)\" +CFLAGS=`pkg-config --cflags gaim gobject-2.0 gnt` -g -Wall -DVERSION=\"$(VERSION)\" -DSTANDALONE LDFLAGS=`pkg-config --libs gaim gobject-2.0 libxml-2.0 gnt` -pg GG_SOURCES = \ gntaccount.c \ gntblist.c \ + gntconn.c \ gntconv.c \ + gntnotify.c \ gntui.c GG_HEADERS = \ gntaccount.h \ gntblist.h \ + gntconn.h \ gntconv.h \ + gntnotify.h \ gntui.h GG_OBJECTS = \ gntaccount.o \ gntblist.o \ + gntconn.o \ gntconv.o \ + gntnotify.o \ gntui.o all: gntgaim @@ -29,6 +35,7 @@ gntblist.o: gntblist.c $(GG_HEADERS) gntconv.o: gntconv.c $(GG_HEADERS) gntgaim.o: gntgaim.c gntgaim.h $(GG_HEADERS) +gntnotify.o: gntnotify.c $(GG_HEADERS) gntui.o: gntui.c $(GG_HEADERS) clean: Modified: branches/soc-2006-file-loggers/console/gntaccount.c =================================================================== --- branches/soc-2006-file-loggers/console/gntaccount.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntaccount.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -210,25 +210,26 @@ gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); - accounts.tree = gnt_tree_new(); + accounts.tree = gnt_tree_new_with_columns(2); GNT_WIDGET_SET_FLAGS(accounts.tree, GNT_WIDGET_NO_BORDER); for (iter = gaim_accounts_get_all(); iter; iter = iter->next) { GaimAccount *account = iter->data; - char *str = g_strdup_printf("%s (%s)", - gaim_account_get_username(account), gaim_account_get_protocol_id(account)); gnt_tree_add_choice(GNT_TREE(accounts.tree), account, - str, NULL, NULL); + gnt_tree_create_row(GNT_TREE(accounts.tree), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)), + NULL, NULL); gnt_tree_set_choice(GNT_TREE(accounts.tree), account, gaim_account_get_enabled(account, GAIM_GNT_UI)); - g_free(str); } g_signal_connect(G_OBJECT(accounts.tree), "toggled", G_CALLBACK(account_toggled), NULL); - gnt_widget_set_size(accounts.tree, 40, 10); + gnt_tree_set_col_width(GNT_TREE(accounts.tree), 0, 40); + gnt_tree_set_col_width(GNT_TREE(accounts.tree), 1, 10); gnt_box_add_widget(GNT_BOX(accounts.window), accounts.tree); gnt_box_add_widget(GNT_BOX(accounts.window), gnt_line_new(FALSE)); Modified: branches/soc-2006-file-loggers/console/gntblist.c =================================================================== --- branches/soc-2006-file-loggers/console/gntblist.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntblist.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -1,5 +1,6 @@ #include <account.h> #include <blist.h> +#include <request.h> #include <server.h> #include <signal.h> #include <util.h> @@ -19,6 +20,9 @@ GntWidget *tooltip; GaimBlistNode *tnode; /* Who is the tooltip being displayed for? */ + + GntWidget *context; + GaimBlistNode *cnode; } GGBlist; GGBlist *ggblist; @@ -28,6 +32,7 @@ static void add_chat(GaimChat *chat, GGBlist *ggblist); static void add_node(GaimBlistNode *node, GGBlist *ggblist); static void draw_tooltip(GGBlist *ggblist); +static void remove_peripherals(GGBlist *ggblist); static void new_node(GaimBlistNode *node) @@ -124,8 +129,9 @@ GaimBlistNode *node = (GaimBlistNode *)group; if (node->ui_data) return; + gnt_tree_remove(GNT_TREE(ggblist->tree), group); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group, - group->name, NULL, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), group->name), NULL, NULL); } static const char * @@ -186,8 +192,10 @@ group = gaim_chat_get_group(chat); add_node((GaimBlistNode*)group, ggblist); + gnt_tree_remove(GNT_TREE(ggblist->tree), chat); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat, - get_display_name(node), group, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), + group, NULL); } static void @@ -201,8 +209,10 @@ group = gaim_buddy_get_group(buddy); add_node((GaimBlistNode*)group, ggblist); + gnt_tree_remove(GNT_TREE(ggblist->tree), buddy); node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, - get_display_name(node), group, NULL); + gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), + group, NULL); if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy))) gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM); else @@ -252,6 +262,233 @@ } static void +remove_context_menu(GGBlist *ggblist) +{ + if (ggblist->context) + gnt_widget_destroy(ggblist->context->parent); + ggblist->context = NULL; + ggblist->cnode = NULL; +} + +static void +gnt_append_menu_action(GntTree *tree, GaimMenuAction *action, gpointer parent) +{ + GList *list; + + gnt_tree_add_row_after(tree, action, + gnt_tree_create_row(tree, action->label), parent, NULL); + for (list = action->children; list; list = list->next) + gnt_append_menu_action(tree, list->data, action); +} + +static void +append_proto_menu(GntTree *tree, GaimConnection *gc, GaimBlistNode *node) +{ + GList *list; + GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); + + if(!prpl_info || !prpl_info->blist_node_menu) + return; + + for(list = prpl_info->blist_node_menu(node); list; + list = g_list_delete_link(list, list)) + { + GaimMenuAction *act = (GaimMenuAction *) list->data; + gnt_append_menu_action(tree, act, NULL); + } +} + +static void +add_custom_action(GntTree *tree, const char *label, GaimCallback callback, + gpointer data) +{ + GaimMenuAction *action = gaim_menu_action_new(label, callback, data, NULL); + gnt_append_menu_action(tree, action, NULL); + g_signal_connect_swapped(G_OBJECT(tree), "destroy", + G_CALLBACK(gaim_menu_action_free), action); +} + +static void +create_chat_menu(GntTree *tree, GaimChat *chat) +{ +} + +static void +create_group_menu(GntTree *tree, GaimGroup *group) +{ +} + +static void +gg_blist_get_buddy_info_cb(GaimBuddy *buddy, GaimBlistNode *null) +{ + serv_get_info(buddy->account->gc, gaim_buddy_get_name(buddy)); +} + +static void +create_buddy_menu(GntTree *tree, GaimBuddy *buddy) +{ + GaimPluginProtocolInfo *prpl_info; + + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); + if (prpl_info && prpl_info->get_info) + { + add_custom_action(tree, _("Get Info"), + GAIM_CALLBACK(gg_blist_get_buddy_info_cb), buddy); + } + +#if 0 + add_custom_action(tree, _("Add Buddy Pounce"), + GAIM_CALLBACK(gg_blist_add_buddy_pounce_cb)), buddy); + + if (prpl_info && prpl_info->send_file) + { + if (!prpl_info->can_receive_file || + prpl_info->can_receive_file(buddy->account->gc, buddy->name)) + add_custom_action(tree, _("Send File"), + GAIM_CALLBACK(gg_blist_show_file_cb)), buddy); + } + + add_custom_action(tree, _("View Log"), + GAIM_CALLBACK(gg_blist_view_log_cb)), buddy); +#endif + + /* Protocol actions */ + append_proto_menu(tree, + gaim_account_get_connection(gaim_buddy_get_account(buddy)), + (GaimBlistNode*)buddy); +} + +static void +append_extended_menu(GntTree *tree, GaimBlistNode *node) +{ + GList *iter; + + for (iter = gaim_blist_node_get_extended_menu(node); + iter; iter = g_list_delete_link(iter, iter)) + { + gnt_append_menu_action(tree, iter->data, NULL); + } +} + +static void +context_menu_callback(GntTree *tree, GGBlist *ggblist) +{ + GaimMenuAction *action = gnt_tree_get_selection_data(tree); + GaimBlistNode *node = ggblist->cnode; + + if (action) + { + void (*callback)(GaimBlistNode *, gpointer); + callback = (void (*)(GaimBlistNode *, gpointer))action->callback; + callback(node, action->data); + } + + remove_context_menu(ggblist); +} + +static void +gg_blist_rename_node_cb(GaimBlistNode *node, GaimBlistNode *null) +{ +} + +/* XXX: This still doesn't do anything, because request doesn't have a ui yet */ +static void +gg_blist_remove_node_cb(GaimBlistNode *node, GaimBlistNode *null) +{ + void (*callback)(gpointer); + + if (GAIM_BLIST_NODE_IS_BUDDY(node)) + callback = (void(*)(gpointer))gaim_blist_remove_buddy; + else if (GAIM_BLIST_NODE_IS_CHAT(node)) + callback = (void(*)(gpointer))gaim_blist_remove_chat; + else if (GAIM_BLIST_NODE_IS_GROUP(node)) + callback = (void(*)(gpointer))gaim_blist_remove_group; + + /* XXX: anything to do with the returned ui-handle? */ + gaim_request_action(node, _("Confirm Remove"), + _("Are you sure you want to remove ..."), NULL, /* XXX: tidy up */ + 1, node, 2, + _("Remove"), callback, + _("No"), NULL); + +} + +static void +draw_context_menu(GGBlist *ggblist) +{ + GaimBlistNode *node = NULL; + GntWidget *context = NULL, *window = NULL; + GntTree *tree = NULL; + int x, y, top, width; + char *title = NULL; + + tree = GNT_TREE(ggblist->tree); + + if (ggblist->context) + { + remove_context_menu(ggblist); + } + + node = gnt_tree_get_selection_data(tree); + + if (node == NULL) + return; + if (ggblist->tooltip) + remove_tooltip(ggblist); + + ggblist->cnode = node; + ggblist->context = context = gnt_tree_new(); + GNT_WIDGET_SET_FLAGS(context, GNT_WIDGET_NO_BORDER); + gnt_widget_set_name(context, "context menu"); + g_signal_connect(G_OBJECT(context), "activate", G_CALLBACK(context_menu_callback), ggblist); + + if (GAIM_BLIST_NODE_IS_BUDDY(node)) + { + GaimBuddy *buddy = (GaimBuddy *)node; + create_buddy_menu(GNT_TREE(context), buddy); + title = g_strdup(gaim_buddy_get_name(buddy)); + } + else if (GAIM_BLIST_NODE_IS_CHAT(node)) + { + GaimChat *chat = (GaimChat*)node; + create_chat_menu(GNT_TREE(context), chat); + title = g_strdup(gaim_chat_get_name(chat)); + } + else if (GAIM_BLIST_NODE_IS_GROUP(node)) + { + GaimGroup *group = (GaimGroup *)node; + create_group_menu(GNT_TREE(context), group); + title = g_strdup(group->name); + } + + append_extended_menu(GNT_TREE(context), node); + + /* These are common for everything */ + add_custom_action(GNT_TREE(context), _("Rename"), + GAIM_CALLBACK(gg_blist_rename_node_cb), node); + add_custom_action(GNT_TREE(context), _("Remove"), + GAIM_CALLBACK(gg_blist_remove_node_cb), node); + + window = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), title); + + gnt_box_add_widget(GNT_BOX(window), context); + + /* Set the position for the popup */ + gnt_widget_get_position(GNT_WIDGET(tree), &x, &y); + gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL); + top = gnt_tree_get_selection_visible_line(tree); + + x += width; + y += top - 1; + + gnt_widget_set_position(window, x, y); + gnt_widget_draw(window); + g_free(title); +} + +static void draw_tooltip(GGBlist *ggblist) { GaimBlistNode *node; @@ -270,6 +507,9 @@ if (!gnt_widget_has_focus(ggblist->tree)) return; + if (ggblist->context) + return; + if (ggblist->tooltip) { /* XXX: Once we can properly redraw on expose events, this can be removed at the end @@ -288,7 +528,9 @@ GaimBuddy *buddy = (GaimBuddy *)node; account = gaim_buddy_get_account(buddy); - g_string_append_printf(str, _("Account: %s"), gaim_account_get_username(account)); + g_string_append_printf(str, _("Account: %s (%s)"), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); @@ -323,7 +565,9 @@ GaimChat *chat = (GaimChat *)node; GaimAccount *account = chat->account; - g_string_append_printf(str, _("Account: %s"), gaim_account_get_username(account)); + g_string_append_printf(str, _("Account: %s (%s)"), + gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); title = g_strdup(gaim_chat_get_name(chat)); } @@ -368,24 +612,41 @@ static gboolean key_pressed(GntWidget *widget, const char *text, GGBlist *ggblist) { + gboolean stop = FALSE, ret = FALSE; if (text[0] == 27 && text[1] == 0) { /* Escape was pressed */ - if (ggblist->tooltip) + remove_peripherals(ggblist); + stop = TRUE; + ret = TRUE; + } + + if (ggblist->context) + { + ret = gnt_widget_key_pressed(ggblist->context, text); + stop = TRUE; + } + + if (text[0] == 27) + { + if (strcmp(text + 1, GNT_KEY_POPUP) == 0) { - gnt_widget_destroy(ggblist->tooltip); - ggblist->tooltip = NULL; - return TRUE; + draw_context_menu(ggblist); + stop = TRUE; + ret = TRUE; } } - return FALSE; + if (stop) + g_signal_stop_emission_by_name(G_OBJECT(widget), "key_pressed"); + + return ret; } static void update_buddy_display(GaimBuddy *buddy, GGBlist *ggblist) { - gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, get_display_name((GaimBlistNode*)buddy)); + gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((GaimBlistNode*)buddy)); if (ggblist->tnode == (GaimBlistNode*)buddy) draw_tooltip(ggblist); @@ -407,6 +668,15 @@ update_buddy_display(buddy, ggblist); } +static void +remove_peripherals(GGBlist *ggblist) +{ + if (ggblist->tooltip) + remove_tooltip(ggblist); + else if (ggblist->context) + remove_context_menu(ggblist); +} + void gg_blist_init() { ggblist = g_new0(GGBlist, 1); @@ -421,7 +691,8 @@ ggblist->tree = gnt_tree_new(); GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); - gnt_widget_set_size(ggblist->tree, 25, getmaxy(stdscr) - 4); + gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, 25); + gnt_widget_set_size(ggblist->tree, 0, getmaxy(stdscr) - 4); gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); gnt_widget_show(ggblist->window); @@ -452,7 +723,7 @@ g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist); g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip), ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); - g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_tooltip), + g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_peripherals), ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); } Copied: branches/soc-2006-file-loggers/console/gntconn.c (from rev 16534, trunk/console/gntconn.c) =================================================================== --- branches/soc-2006-file-loggers/console/gntconn.c (rev 0) +++ branches/soc-2006-file-loggers/console/gntconn.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -0,0 +1,45 @@ +#include "notify.h" + +#include "gntconn.h" +#include "gntgaim.h" + +static void +gg_connection_report_disconnect(GaimConnection *gc, const char *text) +{ + char *act, *primary, *secondary; + GaimAccount *account = gaim_connection_get_account(gc); + + act = g_strdup_printf(_("%s (%s)"), gaim_account_get_username(account), + gaim_account_get_protocol_name(account)); + + primary = g_strdup_printf(_("%s disconnected."), act); + secondary = g_strdup_printf(_("%s was disconnected due to the following error:\n%s"), + act, text); + + gaim_notify_error(account, _("Connection Error"), primary, secondary); + + g_free(act); + g_free(primary); + g_free(secondary); +} + +static GaimConnectionUiOps ops = +{ + .connect_progress = NULL, + .connected = NULL, + .disconnected = NULL, + .notice = NULL, + .report_disconnect = gg_connection_report_disconnect +}; + +GaimConnectionUiOps *gg_connections_get_ui_ops() +{ + return &ops; +} + +void gg_connections_init() +{} + +void gg_connections_uninit() +{} + Copied: branches/soc-2006-file-loggers/console/gntconn.h (from rev 16534, trunk/console/gntconn.h) =================================================================== --- branches/soc-2006-file-loggers/console/gntconn.h (rev 0) +++ branches/soc-2006-file-loggers/console/gntconn.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -0,0 +1,8 @@ +#include "connection.h" + +GaimConnectionUiOps *gg_connections_get_ui_ops(); + +void gg_connections_init(); + +void gg_connections_uninit(); + Modified: branches/soc-2006-file-loggers/console/gntconv.c =================================================================== --- branches/soc-2006-file-loggers/console/gntconv.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntconv.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -1,4 +1,6 @@ #include <string.h> + +#include <cmds.h> #include <util.h> #include "gntgaim.h" @@ -49,12 +51,53 @@ const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry)); if (*text == '/') { - /* XXX: Need to check for /-commands here */ + GaimConversation *conv = ggconv->conv; + GaimCmdStatus status; + const char *cmdline = text + 1; + char *error = NULL, *escape; + + escape = g_markup_escape_text(cmdline, -1); + status = gaim_cmd_do_command(conv, cmdline, escape, &error); + g_free(escape); + + switch (status) + { + case GAIM_CMD_STATUS_OK: + break; + case GAIM_CMD_STATUS_NOT_FOUND: + gaim_conversation_write(conv, "", _("No such command."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + break; + case GAIM_CMD_STATUS_WRONG_ARGS: + gaim_conversation_write(conv, "", _("Syntax Error: You typed the wrong number of arguments " + "to that command."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + break; + case GAIM_CMD_STATUS_FAILED: + gaim_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + break; + case GAIM_CMD_STATUS_WRONG_TYPE: + if(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) + gaim_conversation_write(conv, "", _("That command only works in chats, not IMs."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + else + gaim_conversation_write(conv, "", _("That command only works in IMs, not chats."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + break; + case GAIM_CMD_STATUS_WRONG_PRPL: + gaim_conversation_write(conv, "", _("That command doesn't work on this protocol."), + GAIM_MESSAGE_NO_LOG, time(NULL)); + break; + } + g_free(error); +#if 0 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv), _("Commands are not supported yet. Message was NOT sent."), GNT_TEXT_FLAG_DIM | GNT_TEXT_FLAG_UNDERLINE); gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv)); gnt_text_view_scroll(GNT_TEXT_VIEW(ggconv->tv), 0); +#endif } else { @@ -202,11 +245,12 @@ { if (flags & GAIM_MESSAGE_SEND) { - who = gaim_connection_get_display_name(conv->account->gc); + GaimAccount *account = gaim_conversation_get_account(conv); + who = gaim_connection_get_display_name(gaim_account_get_connection(account)); if (!who) - who = gaim_account_get_alias(conv->account); + who = gaim_account_get_alias(account); if (!who) - who = gaim_account_get_username(conv->account); + who = gaim_account_get_username(account); } else if (flags & GAIM_MESSAGE_RECV) who = gaim_conversation_get_name(conv); @@ -230,20 +274,48 @@ } static void -gg_chat_add_users(GaimConversation *conv, GList *users, GList *flags, GList *aliases, gboolean new_arrivals) -{} +gg_chat_add_users(GaimConversation *conv, GList *users, gboolean new_arrivals) +{ + if (!new_arrivals) + { + /* Print the list of users in the room */ + GString *string = g_string_new(_("List of users:\n")); + GList *iter; + for (iter = users; iter; iter = iter->next) + { + GaimConvChatBuddy *cbuddy = iter->data; + char *str; + + if ((str = cbuddy->alias) == NULL) + str = cbuddy->name; + g_string_append_printf(string, "[ %s ]", str); + } + + gaim_conversation_write(conv, NULL, string->str, + GAIM_MESSAGE_SYSTEM, time(NULL)); + g_string_free(string, TRUE); + } + /* XXX: Add the names for string completion */ +} + static void gg_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a) -{} +{ + /* XXX: Update the name for string completion */ +} static void gg_chat_remove_user(GaimConversation *conv, GList *list) -{} +{ + /* XXX: Remove the name from string completion */ +} static void gg_chat_update_user(GaimConversation *conv, const char *user) -{} +{ + /* XXX: This probably will not require updating the string completion */ +} static GaimConversationUiOps conv_ui_ops = { @@ -266,9 +338,9 @@ static void destroy_ggconv(gpointer data) { - GGConv *conv = data; - gnt_widget_destroy(conv->window); - g_free(conv); + GGConv *ggconv = data; + gnt_widget_destroy(ggconv->window); + g_free(ggconv); } GaimConversationUiOps *gg_conv_get_ui_ops() @@ -276,10 +348,132 @@ return &conv_ui_ops; } +/* Xerox */ +static GaimCmdRet +say_command_cb(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) + gaim_conv_im_send(GAIM_CONV_IM(conv), args[0]); + else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) + gaim_conv_chat_send(GAIM_CONV_CHAT(conv), args[0]); + return GAIM_CMD_RET_OK; +} + +/* Xerox */ +static GaimCmdRet +me_command_cb(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + char *tmp; + + tmp = g_strdup_printf("/me %s", args[0]); + + if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) + gaim_conv_im_send(GAIM_CONV_IM(conv), tmp); + else if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) + gaim_conv_chat_send(GAIM_CONV_CHAT(conv), tmp); + + g_free(tmp); + return GAIM_CMD_RET_OK; +} + +/* Xerox */ +static GaimCmdRet +debug_command_cb(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + char *tmp, *markup; + GaimCmdStatus status; + + if (!g_ascii_strcasecmp(args[0], "version")) { + tmp = g_strdup_printf("me is using %s.", VERSION); + markup = g_markup_escape_text(tmp, -1); + + status = gaim_cmd_do_command(conv, tmp, markup, error); + + g_free(tmp); + g_free(markup); + return status; + } else { + gaim_conversation_write(conv, NULL, _("Supported debug options are: version"), + GAIM_MESSAGE_NO_LOG|GAIM_MESSAGE_ERROR, time(NULL)); + return GAIM_CMD_STATUS_OK; + } +} + +/* Xerox */ +static GaimCmdRet +clear_command_cb(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + GGConv *ggconv = conv->ui_data; + gnt_text_view_clear(GNT_TEXT_VIEW(ggconv->tv)); + return GAIM_CMD_STATUS_OK; +} + +/* Xerox */ +static GaimCmdRet +help_command_cb(GaimConversation *conv, + const char *cmd, char **args, char **error, void *data) +{ + GList *l, *text; + GString *s; + + if (args[0] != NULL) { + s = g_string_new(""); + text = gaim_cmd_help(conv, args[0]); + + if (text) { + for (l = text; l; l = l->next) + if (l->next) + g_string_append_printf(s, "%s\n", (char *)l->data); + else + g_string_append_printf(s, "%s", (char *)l->data); + } else { + g_string_append(s, _("No such command (in this context).")); + } + } else { + s = g_string_new(_("Use \"/help <command>\" for help on a specific command.\n" + "The following commands are available in this context:\n")); + + text = gaim_cmd_list(conv); + for (l = text; l; l = l->next) + if (l->next) + g_string_append_printf(s, "%s, ", (char *)l->data); + else + g_string_append_printf(s, "%s.", (char *)l->data); + g_list_free(text); + } + + gaim_conversation_write(conv, NULL, s->str, GAIM_MESSAGE_NO_LOG, time(NULL)); + g_string_free(s, TRUE); + + return GAIM_CMD_STATUS_OK; +} + + void gg_conversation_init() { ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv); + + /* Xerox */ + gaim_cmd_register("say", "S", GAIM_CMD_P_DEFAULT, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, + say_command_cb, _("say <message>: Send a message normally as if you weren't using a command."), NULL); + gaim_cmd_register("me", "S", GAIM_CMD_P_DEFAULT, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, + me_command_cb, _("me <action>: Send an IRC style action to a buddy or chat."), NULL); + gaim_cmd_register("debug", "w", GAIM_CMD_P_DEFAULT, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, + debug_command_cb, _("debug <option>: Send various debug information to the current conversation."), NULL); + gaim_cmd_register("clear", "", GAIM_CMD_P_DEFAULT, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM, NULL, + clear_command_cb, _("clear: Clears the conversation scrollback."), NULL); + gaim_cmd_register("help", "w", GAIM_CMD_P_DEFAULT, + GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, + help_command_cb, _("help <command>: Help on a specific command."), NULL); } void gg_conversation_uninit() Modified: branches/soc-2006-file-loggers/console/gntgaim.c =================================================================== --- branches/soc-2006-file-loggers/console/gntgaim.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntgaim.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -299,8 +299,9 @@ /* Initialize and run the UI */ init_gnt_ui(); - +#ifdef STANDALONE gaim_core_quit(); +#endif return 0; } Modified: branches/soc-2006-file-loggers/console/gntgaim.h =================================================================== --- branches/soc-2006-file-loggers/console/gntgaim.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntgaim.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -1,4 +1,5 @@ #include <glib.h> +#include <libintl.h> #define GAIM_GNT_UI "gnt-gaim" Copied: branches/soc-2006-file-loggers/console/gntnotify.c (from rev 16534, trunk/console/gntnotify.c) =================================================================== --- branches/soc-2006-file-loggers/console/gntnotify.c (rev 0) +++ branches/soc-2006-file-loggers/console/gntnotify.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -0,0 +1,211 @@ +#include <gnt.h> +#include <gntbox.h> +#include <gntbutton.h> +#include <gntlabel.h> +#include <gnttree.h> + +#include <util.h> + +#include "gntnotify.h" +#include "gntgaim.h" + +static struct +{ + GntWidget *window; + GntWidget *tree; +} emaildialog; + +static void * +gg_notify_message(GaimNotifyMsgType type, const char *title, + const char *primary, const char *secondary) +{ + GntWidget *window, *button; + GntTextFormatFlags pf = 0, sf = 0; + + switch (type) + { + case GAIM_NOTIFY_MSG_ERROR: + sf |= GNT_TEXT_FLAG_BOLD; + case GAIM_NOTIFY_MSG_WARNING: + pf |= GNT_TEXT_FLAG_UNDERLINE; + case GAIM_NOTIFY_MSG_INFO: + pf |= GNT_TEXT_FLAG_BOLD; + break; + } + + window = gnt_box_new(FALSE, TRUE); + gnt_box_set_toplevel(GNT_BOX(window), TRUE); + gnt_box_set_title(GNT_BOX(window), title); + gnt_box_set_fill(GNT_BOX(window), FALSE); + 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, pf)); + if (secondary) + gnt_box_add_widget(GNT_BOX(window), + gnt_label_new_with_format(secondary, sf)); + + button = gnt_button_new(_("OK")); + gnt_box_add_widget(GNT_BOX(window), button); + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window); + + gnt_widget_show(window); + return window; +} + +/* handle is, in all/most occasions, a GntWidget * */ +static void gg_close_notify(GaimNotifyType type, void *handle) +{ + gnt_widget_destroy(GNT_WIDGET(handle)); +} + +static void *gg_notify_formatted(const char *title, const char *primary, + const char *secondary, const char *text) +{ + /* XXX: For now, simply strip the html and use _notify_message. For future use, + * there should be some way of parsing the makrups from GntTextView */ + char *unformat = gaim_markup_strip_html(text); + char *t = g_strdup_printf("%s%s%s", + secondary ? secondary : "", + secondary ? "\n" : "", + unformat ? unformat : ""); + + void *ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, title, primary, t); + + g_free(t); + g_free(unformat); + + return ret; +} + +static void +reset_email_dialog() +{ + emaildialog.window = NULL; + emaildialog.tree = NULL; +} + +static void +setup_email_dialog() +{ + GntWidget *box, *tree, *button; + if (emaildialog.window) + return; + + emaildialog.window = box = gnt_vbox_new(FALSE); + gnt_box_set_toplevel(GNT_BOX(box), TRUE); + gnt_box_set_title(GNT_BOX(box), _("Emails")); + gnt_box_set_fill(GNT_BOX(box), FALSE); + gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); + gnt_box_set_pad(GNT_BOX(box), 0); + + gnt_box_add_widget(GNT_BOX(box), + gnt_label_new_with_format(_("You have mail!"), GNT_TEXT_FLAG_BOLD)); + + emaildialog.tree = tree = gnt_tree_new_with_columns(3); + gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("From"), _("Subject")); + gnt_tree_set_show_title(GNT_TREE(tree), TRUE); + gnt_tree_set_col_width(GNT_TREE(tree), 0, 15); + gnt_tree_set_col_width(GNT_TREE(tree), 1, 25); + gnt_tree_set_col_width(GNT_TREE(tree), 2, 25); + + gnt_box_add_widget(GNT_BOX(box), tree); + + button = gnt_button_new(_("Close")); + gnt_box_add_widget(GNT_BOX(box), button); + + g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), box); + g_signal_connect(G_OBJECT(box), "destroy", G_CALLBACK(reset_email_dialog), NULL); +} + +static void * +gg_notify_emails(GaimConnection *gc, size_t count, gboolean detailed, + const char **subjects, const char **froms, const char **tos, + const char **urls) +{ + GaimAccount *account = gaim_connection_get_account(gc); + GString *message = g_string_new(NULL); + void *ret; + + if (!detailed) + { + g_string_append_printf(message, + ngettext("%s (%s) has %d new message.", + "%s (%s) has %d new messages.", + (int)count), + tos ? *tos : gaim_account_get_username(account), + gaim_account_get_protocol_name(account), (int)count); + } + else + { + setup_email_dialog(); + + gnt_tree_add_row_after(GNT_TREE(emaildialog.tree), GINT_TO_POINTER(time(NULL)), + gnt_tree_create_row(GNT_TREE(emaildialog.tree), + tos ? *tos : gaim_account_get_username(account), /* XXX: Perhaps add the prpl-name */ + froms ? *froms : "[Unknown sender]", + *subjects), + NULL, NULL); + gnt_widget_show(emaildialog.window); + return NULL; + } + + ret = gg_notify_message(GAIM_NOTIFY_MSG_INFO, _("New Mail"), _("You have mail!"), message->str); + g_string_free(message, TRUE); + return ret; +} + +static void * +gg_notify_email(GaimConnection *gc, const char *subject, const char *from, + const char *to, const char *url) +{ + return gg_notify_emails(gc, 1, subject != NULL, + subject ? &subject : NULL, + from ? &from : NULL, + to ? &to : NULL, + url ? &url : NULL); +} + +static void * +gg_notify_userinfo(GaimConnection *gc, const char *who, const char *text) +{ + /* Xeroxed from gtknotify.c */ + char *primary; + void *ui_handle; + + primary = g_strdup_printf(_("Info for %s"), who); + ui_handle = gg_notify_formatted(_("Buddy Information"), primary, NULL, text); + g_free(primary); + return ui_handle; +} + +static GaimNotifyUiOps ops = +{ + .notify_message = gg_notify_message, + .close_notify = gg_close_notify, /* The rest of the notify-uiops return a GntWidget. + These widgets should be destroyed from here. */ + .notify_formatted = gg_notify_formatted, + .notify_email = gg_notify_email, + .notify_emails = gg_notify_emails, + .notify_userinfo = gg_notify_userinfo, + + .notify_searchresults = NULL, /* We are going to need multi-column GntTree's for this */ + .notify_searchresults_new_rows = NULL, + .notify_uri = NULL /* This is of low-priority to me */ +}; + +GaimNotifyUiOps *gg_notify_get_ui_ops() +{ + return &ops; +} + +void gg_notify_init() +{ +} + +void gg_notify_uninit() +{ +} + + Copied: branches/soc-2006-file-loggers/console/gntnotify.h (from rev 16534, trunk/console/gntnotify.h) =================================================================== --- branches/soc-2006-file-loggers/console/gntnotify.h (rev 0) +++ branches/soc-2006-file-loggers/console/gntnotify.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -0,0 +1,8 @@ +#include "notify.h" + +GaimNotifyUiOps *gg_notify_get_ui_ops(); + +void gg_notify_init(); + +void gg_notify_uninit(); + Modified: branches/soc-2006-file-loggers/console/gntui.c =================================================================== --- branches/soc-2006-file-loggers/console/gntui.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/gntui.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -2,16 +2,23 @@ #include "gntaccount.h" #include "gntblist.h" +#include "gntconn.h" #include "gntconv.h" +#include "gntnotify.h" void init_gnt_ui() { +#ifdef STANDALONE gnt_init(); - +#endif /* Accounts */ gg_accounts_init(); gaim_accounts_set_ui_ops(gg_accounts_get_ui_ops()); + /* Connections */ + gg_connections_init(); + gaim_connections_set_ui_ops(gg_connections_get_ui_ops()); + /* Initialize the buddy list */ gg_blist_init(); gaim_blist_set_ui_ops(gg_blist_get_ui_ops()); @@ -20,17 +27,29 @@ gg_conversation_init(); gaim_conversations_set_ui_ops(gg_conv_get_ui_ops()); + /* Notify */ + gg_notify_init(); + gaim_notify_set_ui_ops(gg_notify_get_ui_ops()); + +#ifdef STANDALONE gnt_main(); gaim_accounts_set_ui_ops(NULL); gg_accounts_uninit(); + gaim_connections_set_ui_ops(NULL); + gg_connections_uninit(); + gaim_blist_set_ui_ops(NULL); gg_blist_uninit(); gaim_conversations_set_ui_ops(NULL); gg_conversation_uninit(); + gaim_notify_set_ui_ops(NULL); + gg_notify_uninit(); + gnt_quit(); +#endif } Modified: branches/soc-2006-file-loggers/console/libgnt/gntbox.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntbox.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntbox.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -173,31 +173,30 @@ if (maxw < w) maxw = w; } - - if (box->homogeneous) + + for (iter = box->list; iter; iter = iter->next) { - for (iter = box->list; iter; iter = iter->next) + int w, h; + GntWidget *wid = GNT_WIDGET(iter->data); + + gnt_widget_get_size(wid, &w, &h); + + if (box->homogeneous) { - gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, maxh); + if (box->vertical) + h = maxh; + else + w = maxw; } - } - else - { - for (iter = box->list; iter; iter = iter->next) + if (box->fill) { if (box->vertical) - { - int h; - gnt_widget_get_size(GNT_WIDGET(iter->data), NULL, &h); - gnt_widget_set_size(GNT_WIDGET(iter->data), maxw, h); - } + w = maxw; else - { - int w; - gnt_widget_get_size(GNT_WIDGET(iter->data), &w, NULL); - gnt_widget_set_size(GNT_WIDGET(iter->data), w, maxh); - } + h = maxh; } + + gnt_widget_set_size(wid, w, h); } reposition_children(widget); @@ -495,6 +494,7 @@ box->homogeneous = homo; box->vertical = vert; box->pad = 1; + box->fill = TRUE; gnt_widget_set_take_focus(widget, TRUE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); if (vert) @@ -669,3 +669,8 @@ } } +void gnt_box_set_fill(GntBox *box, gboolean fill) +{ + box->fill = fill; +} + Modified: branches/soc-2006-file-loggers/console/libgnt/gntbox.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntbox.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntbox.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -33,6 +33,7 @@ gboolean vertical; gboolean homogeneous; + gboolean fill; GList *list; /* List of widgets */ GntWidget *active; @@ -85,6 +86,8 @@ void gnt_box_readjust(GntBox *box); +void gnt_box_set_fill(GntBox *box, gboolean fill); + G_END_DECLS #endif /* GNT_BOX_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gntcolors.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntcolors.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntcolors.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -1,10 +1,40 @@ #include <ncursesw/ncurses.h> #include "gntcolors.h" +static struct +{ + short r, g, b; +} colors[GNT_TOTAL_COLORS]; + +static void +backup_colors() +{ + short i; + for (i = 0; i < GNT_TOTAL_COLORS; i++) + { + color_content(i, &colors[i].r, + &colors[i].g, &colors[i].b); + } +} + +static void +restore_colors() +{ + short i; + for (i = 0; i < GNT_TOTAL_COLORS; i++) + { + init_color(i, colors[i].r, + colors[i].g, colors[i].b); + } +} + void gnt_init_colors() { + start_color(); if (can_change_color()) { + backup_colors(); + /* XXX: Do some init_color()s */ init_color(GNT_COLOR_BLACK, 0, 0, 0); init_color(GNT_COLOR_RED, 1000, 0, 0); @@ -39,3 +69,9 @@ } } +void +gnt_uninit_colors() +{ + restore_colors(); +} + Modified: branches/soc-2006-file-loggers/console/libgnt/gntcolors.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntcolors.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntcolors.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -32,4 +32,6 @@ /* populate some default colors */ void gnt_init_colors(); +void gnt_uninit_colors(); + #endif Modified: branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntcombobox.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -235,7 +235,8 @@ void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) { - gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, text, NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(box->dropdown), key, + gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL, NULL); if (box->selected == NULL) set_selection(box, key); } Modified: branches/soc-2006-file-loggers/console/libgnt/gntlabel.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntlabel.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntlabel.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -21,8 +21,9 @@ gnt_label_draw(GntWidget *widget) { GntLabel *label = GNT_LABEL(widget); + chtype flag = gnt_text_format_flag_to_chtype(label->flags); - wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); + wbkgdset(widget->window, '\0' | flag); mvwprintw(widget->window, 0, 0, label->text); DEBUG; @@ -109,13 +110,32 @@ GntWidget *gnt_label_new(const char *text) { + return gnt_label_new_with_format(text, 0); +} + +GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags) +{ GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); GntLabel *label = GNT_LABEL(widget); label->text = g_strdup(text); + label->flags = flags; gnt_widget_set_take_focus(widget, FALSE); GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); return widget; } +void gnt_label_set_text(GntLabel *label, const char *text) +{ + g_free(label->text); + label->text = g_strdup(text); + + if (GNT_WIDGET(label)->window) + { + gnt_widget_hide(GNT_WIDGET(label)); + gnt_label_size_request(GNT_WIDGET(label)); + gnt_widget_draw(GNT_WIDGET(label)); + } +} + Modified: branches/soc-2006-file-loggers/console/libgnt/gntlabel.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntlabel.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntlabel.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -3,6 +3,7 @@ #include "gnt.h" #include "gntwidget.h" +#include "gnttextview.h" #define GNT_TYPE_LABEL (gnt_label_get_gtype()) #define GNT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_LABEL, GntLabel)) @@ -19,6 +20,7 @@ GntWidget parent; char *text; + GntTextFormatFlags flags; void (*gnt_reserved1)(void); void (*gnt_reserved2)(void); @@ -42,6 +44,10 @@ GntWidget *gnt_label_new(const char *text); +GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags); + +void gnt_label_set_text(GntLabel *label, const char *text); + G_END_DECLS #endif /* GNT_LABEL_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gntline.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntline.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntline.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -42,6 +42,9 @@ GType gnt_line_get_gtype(void); +#define gnt_hline_new() gnt_line_new(FALSE) +#define gnt_vline_new() gnt_line_new(TRUE) + GntWidget *gnt_line_new(gboolean vertical); G_END_DECLS Modified: branches/soc-2006-file-loggers/console/libgnt/gntmain.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gntmain.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gntmain.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -258,13 +258,16 @@ { GntBox *box = GNT_BOX(iter->data); - gnt_tree_add_row_after(GNT_TREE(tree), box, box->title, NULL, NULL); + gnt_tree_add_row_after(GNT_TREE(tree), box, + gnt_tree_create_row(GNT_TREE(tree), box->title), NULL, NULL); update_window_in_list(GNT_WIDGET(box)); } + gnt_tree_set_selected(GNT_TREE(tree), focus_list->data); gnt_box_add_widget(GNT_BOX(win), tree); - gnt_widget_set_size(tree, getmaxx(stdscr) / 3, getmaxy(stdscr) / 2); + gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); + gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); lock_focus_list = 1; @@ -274,6 +277,34 @@ g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), NULL); } +static void +shift_window(GntWidget *widget, int dir) +{ + GList *all = g_list_first(focus_list); + GList *list = g_list_find(all, widget); + int length, pos; + if (!list) + return; + + length = g_list_length(all); + pos = g_list_position(all, list); + + pos += dir; + if (dir > 0) + pos++; + + if (pos < 0) + pos = length; + else if (pos > length) + pos = 0; + + all = g_list_insert(all, widget, pos); + all = g_list_delete_link(all, list); + if (focus_list == list) + focus_list = g_list_find(all, widget); + draw_taskbar(); +} + static gboolean io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) { @@ -350,6 +381,15 @@ /* Resize window */ mode = GNT_KP_MODE_RESIZE; } + else if (strcmp(buffer + 1, ",") == 0 && focus_list) + { + /* Re-order the list of windows */ + shift_window(focus_list->data, -1); + } + else if (strcmp(buffer + 1, ".") == 0 && focus_list) + { + shift_window(focus_list->data, 1); + } } } } @@ -501,7 +541,6 @@ ascii_only = TRUE; initscr(); - start_color(); gnt_init_colors(); X_MIN = 0; @@ -564,7 +603,8 @@ && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { gnt_tree_add_row_after(GNT_TREE(window_list.tree), widget, - GNT_BOX(widget)->title, NULL, NULL); + gnt_tree_create_row(GNT_TREE(window_list.tree), GNT_BOX(widget)->title), + NULL, NULL); update_window_in_list(widget); } } @@ -654,6 +694,7 @@ void gnt_quit() { + gnt_uninit_colors(); endwin(); } Modified: branches/soc-2006-file-loggers/console/libgnt/gnttextview.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttextview.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gnttextview.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -178,20 +178,8 @@ if (text == NULL || *text == '\0') return; - if (flags & GNT_TEXT_FLAG_BOLD) - fl |= A_BOLD; - if (flags & GNT_TEXT_FLAG_UNDERLINE) - fl |= A_UNDERLINE; - if (flags & GNT_TEXT_FLAG_BLINK) - fl |= A_BLINK; + fl = gnt_text_format_flag_to_chtype(flags); - if (flags & GNT_TEXT_FLAG_DIM) - fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); - else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) - fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); - else - fl |= COLOR_PAIR(GNT_COLOR_NORMAL); - view->list = g_list_first(view->list); split = g_strsplit(text, "\n", 0); @@ -262,3 +250,39 @@ gnt_widget_draw(GNT_WIDGET(view)); } +chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) +{ + chtype fl = 0; + + if (flags & GNT_TEXT_FLAG_BOLD) + fl |= A_BOLD; + if (flags & GNT_TEXT_FLAG_UNDERLINE) + fl |= A_UNDERLINE; + if (flags & GNT_TEXT_FLAG_BLINK) + fl |= A_BLINK; + + if (flags & GNT_TEXT_FLAG_DIM) + fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); + else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) + fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); + else + fl |= COLOR_PAIR(GNT_COLOR_NORMAL); + + return fl; +} + +void gnt_text_view_clear(GntTextView *view) +{ + GntTextLine *line; + + g_list_foreach(view->list, free_text_line, NULL); + g_list_free(view->list); + view->list = NULL; + + line = g_new0(GntTextLine, 1); + view->list = g_list_append(view->list, line); + + if (GNT_WIDGET(view)->window) + gnt_widget_draw(GNT_WIDGET(view)); +} + Modified: branches/soc-2006-file-loggers/console/libgnt/gnttextview.h =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttextview.h 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gnttextview.h 2006-07-21 03:34:03 UTC (rev 16535) @@ -30,6 +30,7 @@ typedef enum { + GNT_TEXT_FLAG_NORMAL = 0, GNT_TEXT_FLAG_BOLD = 1 << 0, GNT_TEXT_FLAG_UNDERLINE = 1 << 1, GNT_TEXT_FLAG_BLINK = 1 << 2, @@ -64,6 +65,10 @@ * It first completes the current line with the current text-attributes. */ void gnt_text_view_next_line(GntTextView *view); +chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags); + +void gnt_text_view_clear(GntTextView *view); + G_END_DECLS #endif /* GNT_TEXT_VIEW_H */ Modified: branches/soc-2006-file-loggers/console/libgnt/gnttree.c =================================================================== --- branches/soc-2006-file-loggers/console/libgnt/gnttree.c 2006-07-20 21:43:15 UTC (rev 16534) +++ branches/soc-2006-file-loggers/console/libgnt/gnttree.c 2006-07-21 03:34:03 UTC (rev 16535) @@ -18,7 +18,6 @@ struct _GnTreeRow { void *key; - char *text; void *data; /* XXX: unused */ gboolean collapsed; @@ -31,8 +30,16 @@ GntTreeRow *child; GntTreeRow *next; GntTreeRow *prev; + + GList *columns; }; +struct _GnTreeCol +{ + char *text; + int span; /* How many columns does it span? */ +}; + static GntWidgetClass *parent_class = NULL; static guint signals[SIGS] = { 0 }; @@ -151,14 +158,98 @@ return (hb - ha); } +static int +find_depth(GntTreeRow *row) +{ + int dep = -1; + + while (row) + { + dep++; + row = row->parent; + } + + return dep; +} + +static char * +update_row_text(GntTree *tree, GntTreeRow *row) +{ + GString *string = g_string_new(NULL); + GList *iter; + int i; + + for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) + { + GntTreeCol *col = iter->data; + char *text; + int len = g_utf8_strlen(col->text, -1); + int fl = 0; + + if (i == 0) + { + if (row->choice) + { + g_string_append_printf(string, "[%c] ", + row->isselected ? 'X' : ' '); + fl = 4; + } + else if (row->parent == NULL && row->child) + { + if (row->collapsed) + { + string = g_string_append(string, "+ "); + } + else + { + string = g_string_append(string, "- "); + } + fl = 2; + } + else + { + fl = TAB_SIZE * find_depth(row); + g_string_append_printf(string, "%*s", fl, ""); + } + len += fl; + } + else + g_string_append_c(string, '|'); + + if (len > tree->columns[i].width) + { + len = tree->columns[i].width; + } + + text = g_utf8_offset_to_pointer(col->text, len - fl); + string = g_string_append_len(string, col->text, text - col->text); + if (len < tree->columns[i].width) + g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); + } + return g_string_free(string, FALSE); +} + static void +tree_mark_columns(GntTree *tree, int pos, int y, chtype type) +{ + GntWidget *widget = GNT_WIDGET(tree); + int i; + int x = pos; + + for (i = 0; i < tree->ncol - 1; i++) + { + x += tree->columns[i].width; + mvwaddch(widget->window, y, x + i, type); + } +} + +static void redraw_tree(GntTree *tree) { int start; GntWidget *widget = GNT_WIDGET(tree); GntTreeRow *row; int pos; - gboolean deep; if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER)) pos = 0; @@ -172,37 +263,39 @@ wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); - deep = TRUE; + start = 0; + if (tree->show_title) + { + int i; + int x = pos; + + mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), + widget->priv.width - pos - 1); + + for (i = 0; i < tree->ncol; i++) + { + mvwprintw(widget->window, pos, x + i, tree->columns[i].title); + x += tree->columns[i].width; + } + if (pos) + tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); + tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL)); + tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL)); + start = 2; + } + row = tree->top; - for (start = pos; row && start < widget->priv.height - pos; + for (start = start + pos; row && start < widget->priv.height - pos; start++, row = get_next(row)) { - char str[2048]; + char *str; int wr; - char format[16] = ""; GntTextFormatFlags flags = row->flags; int attr = 0; - deep = TRUE; + str = update_row_text(tree, row); - if (row->parent == NULL && row->child) - { - if (row->collapsed) - { - strcpy(format, "+ "); - deep = FALSE; - } - else - strcpy(format, "- "); - } - else if (row->choice) - { - g_snprintf(format, sizeof(format) - 1, "[%c] ", row->isselected ? 'X' : ' '); - } - - g_snprintf(str, sizeof(str) - 1, "%s%s", format, row->text); - if ((wr = g_utf8_strlen(str, -1)) >= widget->priv.width - 1 - pos) { /* XXX: ellipsize */ @@ -238,6 +331,8 @@ mvwprintw(widget->window, start, pos, str); whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1)); tree->bottom = row; + g_free(str); + tree_mark_columns(tree, pos, start, ACS_VLINE | attr); } wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); @@ -245,6 +340,7 @@ { mvwhline(widget->window, start, pos, ' ', widget->priv.width - pos * 2); + tree_mark_columns(tree, pos, start, ACS_VLINE); start++; } @@ -267,7 +363,13 @@ if (widget->priv.height == 0) widget->priv.height = 10; /* XXX: Why?! */ if (widget->priv.width == 0) - widget->priv.width = 20; /* YYY: 'cuz ... */ + { + GntTree *tree = GNT_TREE(widget); + int i, width = 0; + for (i = 0; i < tree->ncol; i++) + width += tree->columns[i].width; + widget->priv.width = width + i; + } } static void @@ -353,9 +455,16 @@ gnt_tree_destroy(GntWidget *widget) { GntTree *tree = GNT_TREE(widget); + int i; g_hash_table_destroy(tree->hash); g_list_free(tree->list); + + for (i = 0; i < tree->ncol; i++) + { + g_free(tree->columns[i].title); + } + g_free(tree->columns); } static void @@ -437,6 +546,15 @@ } static void +free_tree_col(gpointer data) +{ + GntTreeCol *col = data; + + g_free(col->text); + g_free(col); +} + +static void free_tree_row(gpointer data) { GntTreeRow *row = data; @@ -444,20 +562,14 @@ if (!row) return; - g_free(row->text); + g_list_foreach(row->columns, (GFunc)free_tree_col, NULL); + g_list_free(row->columns); g_free(row); } GntWidget *gnt_tree_new() { - GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); - GntTree *tree = GNT_TREE(widget); - - tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); - GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); - gnt_widget_set_take_focus(widget, TRUE); - - return widget; + return gnt_tree_new_with_columns(1); } void gnt_tree_set_visible_rows(GntTree *tree, int rows) @@ -500,24 +612,10 @@ g_signal_emit(tree, signals[SIG_SCROLLED], 0, count); } -static int -find_depth(GntTreeRow *row) +GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) { - int dep = -1; + GntTreeRow *pr = NULL; - while (row) - { - dep++; - row = row->parent; - } - - return dep; -} - -GntTreeRow *gnt_tree_add_row_after(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) -{ - GntTreeRow *row = g_new0(GntTreeRow, 1), *pr = NULL; - g_hash_table_replace(tree->hash, key, row); if (tree->root == NULL) @@ -575,7 +673,6 @@ } row->key = key; - row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); row->data = NULL; if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_MAPPED)) @@ -591,10 +688,10 @@ return NULL; } -const char *gnt_tree_get_selection_text(GntTree *tree) +char *gnt_tree_get_selection_text(GntTree *tree) { if (tree->current) - return tree->current->text; + update_row_text(tree, tree->current); return NULL; } @@ -657,27 +754,32 @@ !!(GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); } -void gnt_tree_change_text(GntTree *tree, gpointer key, const char *text) +void gnt_tree_change_text(GntTree *tree, gpointer key, int colno, const char *text) { - GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + GntTreeRow *row; + GntTreeCol *col; + + g_return_if_fail(colno < tree->ncol); + + row = g_hash_table_lookup(tree->hash, key); if (row) { - g_free(row->text); - row->text = g_strdup_printf("%*s%s", TAB_SIZE * find_depth(row), "", text); + col = g_list_nth_data(row->columns, colno); + g_free(col->text); + col->text = g_strdup(text); if (get_distance(tree->top, row) >= 0 && get_distance(row, tree->bottom) > 0) redraw_tree(tree); } } -GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, const char *text, void *parent, void *bigbro) +GntTreeRow *gnt_tree_add_choice(GntTree *tree, void *key, GntTreeRow *row, void *parent, void *bigbro) { - GntTreeRow *row; - - row = g_hash_table_lookup(tree->hash, key); - g_return_val_if_fail(!row || !row->choice, NULL); + GntTreeRow *r; + r = g_hash_table_lookup(tree->hash, key); + g_return_val_if_fail(!r || !r->choice, NULL); - row = gnt_tree_add_row_after(tree, key, text, parent, bigbro); + row = gnt_tree_add_row_after(tree, key, row, parent, bigbro); row->choice = TRUE; return row; @@ -716,3 +818,91 @@ redraw_tree(tree); /* XXX: It shouldn't be necessary to redraw the whole darned tree */ } +void gnt_tree_set_selected(GntTree *tree , void *key) +{ + int dist; + GntTreeRow *row = g_hash_table_lookup(tree->hash, key); + if (!row) + return; + + if (tree->top == NULL) + tree->top = row; + if (tree->bottom == NULL) + tree->bottom = row; + + tree->current = row; + if ((dist = get_distance(tree->current, tree->bottom)) < 0) + gnt_tree_scroll(tree, -dist); + else if ((dist = get_distance(tree->current, tree->top)) > 0) + gnt_tree_scroll(tree, -dist); + else + redraw_tree(tree); +} + +GntWidget *gnt_tree_new_with_columns(int col) +{ + GntWidget *widget = g_object_new(GNT_TYPE_TR... [truncated message content] |