changeset 13885:582aaa4e287e

[gaim-migrate @ 16365] Add ui for conversation. It 'works', but it's broken. So don't use it just yet. I probably will not be able to touch it in the next couple of days. So feel free to fix the brokenness :) committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 28 Jun 2006 05:52:23 +0000
parents eac18261c6f0
children 90eb736b4c26
files console/Makefile console/gntblist.c console/gntconv.c console/gntconv.h console/gntui.c console/libgnt/gntcolors.h console/libgnt/gntmain.c
diffstat 7 files changed, 311 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/console/Makefile	Wed Jun 28 01:46:41 2006 +0000
+++ b/console/Makefile	Wed Jun 28 05:52:23 2006 +0000
@@ -3,14 +3,17 @@
 
 GG_SOURCES = \
 	gntblist.c \
+	gntconv.c \
 	gntui.c
 
 GG_HEADERS = \
 	gntblist.h \
+	gntconv.h \
 	gntui.h
 
 GG_OBJECTS = \
 	gntblist.o \
+	gntconv.o \
 	gntui.o
 
 all:
@@ -20,6 +23,7 @@
 gntgaim: gntgaim.o $(GG_OBJECTS)
 	$(CC) -o gntgaim gntgaim.o $(GG_OBJECTS) $(LDFLAGS)
 gntblist.o: gntblist.c $(GG_HEADERS)
+gntconv.o: gntconv.c $(GG_HEADERS)
 gntgaim.o: gntgaim.c gntgaim.h $(GG_HEADERS)
 gntui.o: gntui.c $(GG_HEADERS)
 
--- a/console/gntblist.c	Wed Jun 28 01:46:41 2006 +0000
+++ b/console/gntblist.c	Wed Jun 28 05:52:23 2006 +0000
@@ -179,6 +179,8 @@
 	{
 		GaimChat *chat = (GaimChat*)node;
 		name = gaim_chat_get_name(chat);
+
+		strncpy(status, "~", sizeof(status) - 1);
 	}
 
 	snprintf(text, sizeof(text) - 1, "%s %s", status, name);
@@ -363,6 +365,25 @@
 			return TRUE;
 		}
 	}
+	else if (text[0] == '\r' && text[1] == '\0')
+	{
+		GntTree *tree = GNT_TREE(ggblist->tree);
+		GaimBlistNode *node = gnt_tree_get_selection_data(tree);
+
+		if (GAIM_BLIST_NODE_IS_BUDDY(node))
+		{
+			GaimBuddy *buddy = (GaimBuddy *)node;
+			gaim_conversation_new(GAIM_CONV_TYPE_IM,
+					gaim_buddy_get_account(buddy),
+					gaim_buddy_get_name(buddy));
+		}
+		else if (GAIM_BLIST_NODE_IS_CHAT(node))
+		{
+			GaimChat *chat = (GaimChat*)node;
+			serv_join_chat(chat->account->gc, chat->components);
+		}
+	}
+
 	return FALSE;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntconv.c	Wed Jun 28 05:52:23 2006 +0000
@@ -0,0 +1,248 @@
+#include <util.h>
+
+#include "gntgaim.h"
+#include "gntconv.h"
+
+#include "gnt.h"
+#include "gntbox.h"
+#include "gntentry.h"
+#include "gnttextview.h"
+
+GHashTable *ggconvs;
+
+typedef struct _GGConv GGConv;
+typedef struct _GGConvChat GGConvChat;
+typedef struct _GGConvIm GGConvIm;
+
+struct _GGConv
+{
+	GaimConversation *conv;
+
+	GntWidget *window;        /* the container */
+	GntWidget *entry;         /* entry */
+	GntWidget *tv;            /* text-view */
+
+	union
+	{
+		GGConvChat *chat;
+		GGConvIm *im;
+	} u;
+};
+
+struct _GGConvChat
+{
+	GntWidget *userlist;       /* the userlist */
+};
+
+struct _GGConvIm
+{
+	void *nothing_for_now;
+};
+
+static gboolean
+entry_key_pressed(GntWidget *w, const char *key, GGConv *ggconv)
+{
+	if (key[0] == '\r' && key[1] == 0)
+	{
+		const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
+		switch (gaim_conversation_get_type(ggconv->conv))
+		{
+			case GAIM_CONV_TYPE_IM:
+				gaim_conv_im_send_with_flags(GAIM_CONV_IM(ggconv->conv), text, GAIM_MESSAGE_SEND);
+				break;
+			case GAIM_CONV_TYPE_CHAT:
+				gaim_conv_chat_send(GAIM_CONV_CHAT(ggconv->conv), text);
+				break;
+			default:
+				g_return_val_if_reached(FALSE);
+		}
+		gnt_entry_clear(GNT_ENTRY(ggconv->entry));
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static void
+closing_window(GntWidget *window, GGConv *ggconv)
+{
+	ggconv->window = NULL;
+	gaim_conversation_destroy(ggconv->conv);
+}
+
+static void
+gg_create_conversation(GaimConversation *conv)
+{
+	GGConv *ggc = g_hash_table_lookup(ggconvs, conv);
+	char *title;
+	GaimConversationType type;
+
+	if (ggc)
+		return;
+
+	ggc = g_new0(GGConv, 1);
+	g_hash_table_insert(ggconvs, conv, ggc);
+
+	ggc->conv = conv;
+
+	type = gaim_conversation_get_type(conv);
+	title = g_strdup_printf(_("Conversation: %s"), gaim_conversation_get_name(conv));
+	ggc->window = gnt_box_new(FALSE, TRUE);
+	gnt_box_set_title(GNT_BOX(ggc->window), title);
+	gnt_box_set_toplevel(GNT_BOX(ggc->window), TRUE);
+	gnt_widget_set_name(ggc->window, "conversation-window");
+
+	ggc->tv = gnt_text_view_new();
+	gnt_box_add_widget(GNT_BOX(ggc->window), ggc->tv);
+	gnt_widget_set_name(ggc->tv, "conversation-window-textview");
+	gnt_widget_set_size(ggc->tv, getmaxx(stdscr) - 40, getmaxy(stdscr) - 15);
+
+	ggc->entry = gnt_entry_new(NULL);
+	gnt_box_add_widget(GNT_BOX(ggc->window), ggc->entry);
+	gnt_widget_set_name(ggc->entry, "conversation-window-entry");
+	gnt_widget_set_size(ggc->entry, getmaxx(stdscr) - 40, 1);
+
+	g_signal_connect(G_OBJECT(ggc->entry), "key_pressed", G_CALLBACK(entry_key_pressed), ggc);
+	g_signal_connect(G_OBJECT(ggc->window), "destroy", G_CALLBACK(closing_window), ggc);
+
+	gnt_widget_set_position(ggc->window, 32, 0);
+	gnt_widget_show(ggc->window);
+
+	g_free(title);
+}
+
+static void
+gg_destroy_conversation(GaimConversation *conv)
+{
+	g_hash_table_remove(ggconvs, conv);
+}
+
+static void
+gg_write_chat(GaimConversation *conv, const char *who, const char *message,
+		GaimMessageFlags flags, time_t mtime)
+{
+	GGConv *ggconv = g_hash_table_lookup(ggconvs, conv);
+	char *name, *strip;
+
+	g_return_if_fail(ggconv != NULL);
+
+	name = g_strdup_printf("%s: ", who);
+	strip = gaim_markup_strip_html(message);
+
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			name, GNT_TEXT_FLAG_BOLD);
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			strip, (flags & GAIM_MESSAGE_NICK) ? GNT_TEXT_FLAG_UNDERLINE : 0);
+	gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv));
+
+	g_free(name);
+	g_free(strip);
+}
+
+static void
+gg_write_im(GaimConversation *conv, const char *who, const char *message,
+		GaimMessageFlags flags, time_t mtime)
+{
+	GGConv *ggconv = g_hash_table_lookup(ggconvs, conv);
+	char *strip;
+	char *name;
+
+	g_return_if_fail(ggconv != NULL);
+
+	if (flags & GAIM_MESSAGE_SEND)
+	{
+		who = gaim_connection_get_display_name(conv->account->gc);
+		if (!who)
+			who = gaim_account_get_alias(conv->account);
+		if (!who)
+			who = gaim_account_get_username(conv->account);
+	}
+	else if (flags & GAIM_MESSAGE_RECV)
+		who = gaim_conversation_get_name(conv);
+
+	name = g_strdup_printf("%s: ", who);
+
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			name, GNT_TEXT_FLAG_BOLD);
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			(strip = gaim_markup_strip_html(message)), 0);
+	gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv));
+	g_free(strip);
+	g_free(name);
+}
+
+static void
+gg_write_conv(GaimConversation *conv, const char *who, const char *message,
+		GaimMessageFlags flags, time_t mtime)
+{
+	GGConv *ggconv = g_hash_table_lookup(ggconvs, conv);
+	char *strip;
+	char *name;
+
+	g_return_if_fail(ggconv != NULL);
+
+	strip = gaim_markup_strip_html(message);
+	name = g_strdup_printf("%s: ", who);
+
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			name, GNT_TEXT_FLAG_BOLD);
+	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(ggconv->tv),
+			strip, 0);
+	gnt_text_view_next_line(GNT_TEXT_VIEW(ggconv->tv));
+
+	g_free(strip);
+}
+
+static void
+gg_chat_add_users(GaimConversation *conv, GList *users, GList *flags, GList *aliases, gboolean new_arrivals)
+{}
+
+static void
+gg_chat_rename_user(GaimConversation *conv, const char *old, const char *new_n, const char *new_a)
+{}
+
+static void
+gg_chat_remove_user(GaimConversation *conv, GList *list)
+{}
+
+static void
+gg_chat_update_user(GaimConversation *conv, const char *user)
+{}
+
+static GaimConversationUiOps conv_ui_ops = 
+{
+	.create_conversation = gg_create_conversation,
+	.destroy_conversation = gg_destroy_conversation,
+	.write_chat = gg_write_chat,
+	.write_im = gg_write_im,
+	.write_chat = gg_write_conv,
+	.chat_add_users = gg_chat_add_users,
+	.chat_rename_user = gg_chat_rename_user,
+	.chat_remove_users = gg_chat_remove_user,
+	.chat_update_user = gg_chat_update_user,
+	.present = NULL,
+	.has_focus = NULL,
+	.custom_smiley_add = NULL,
+	.custom_smiley_write = NULL,
+	.custom_smiley_close = NULL
+};
+
+static void
+destroy_ggconv(gpointer data)
+{
+	GGConv *conv = data;
+	gnt_widget_destroy(conv->window);
+	g_free(conv);
+}
+
+GaimConversationUiOps *gg_conv_get_ui_ops()
+{
+	return &conv_ui_ops;
+}
+
+
+void gg_conversation_init()
+{
+	ggconvs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, destroy_ggconv);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntconv.h	Wed Jun 28 05:52:23 2006 +0000
@@ -0,0 +1,5 @@
+#include "conversation.h"
+
+GaimConversationUiOps *gg_conv_get_ui_ops();
+
+void gg_conversation_init();
--- a/console/gntui.c	Wed Jun 28 01:46:41 2006 +0000
+++ b/console/gntui.c	Wed Jun 28 05:52:23 2006 +0000
@@ -13,6 +13,8 @@
 	gaim_blist_set_ui_ops(gg_blist_get_ui_ops());
 
 	/* Now the conversations */
+	gg_conversation_init();
+	gaim_conversations_set_ui_ops(gg_conv_get_ui_ops());
 
 	gnt_main();
 }
--- a/console/libgnt/gntcolors.h	Wed Jun 28 01:46:41 2006 +0000
+++ b/console/libgnt/gntcolors.h	Wed Jun 28 05:52:23 2006 +0000
@@ -18,7 +18,7 @@
 
 enum
 {
-	GNT_COLOR_BLACK = 1,
+	GNT_COLOR_BLACK = 0,
 	GNT_COLOR_RED,
 	GNT_COLOR_GREEN,
 	GNT_COLOR_BLUE,
--- a/console/libgnt/gntmain.c	Wed Jun 28 01:46:41 2006 +0000
+++ b/console/libgnt/gntmain.c	Wed Jun 28 05:52:23 2006 +0000
@@ -49,7 +49,6 @@
 	if (focus_list)
 	{
 		gboolean ret = FALSE;
-		/*g_signal_emit_by_name(focus_list->data, "key_pressed", buffer, &ret);*/
 		ret = gnt_widget_key_pressed(focus_list->data, buffer);
 	}
 
@@ -57,22 +56,35 @@
 	{
 		/* Some special key has been pressed */
 		if (strcmp(buffer+1, GNT_KEY_POPUP) == 0)
-		{
-			/*printf("popup\n");*/
-		}
-		else
+		{}
+		else if (strcmp(buffer + 1, "c") == 0)
 		{
-			/*printf("Unknown: %s\n", buffer+1);*/
+			/* Alt + c was pressed. I am going to use it to close a window. */
+			if (focus_list)
+			{
+				gnt_widget_destroy(focus_list->data);
+				gnt_screen_remove_widget(focus_list->data);
+			}
 		}
-	}
-	else
-	{
-		if (buffer[0] == 'q')
+		else if (strcmp(buffer + 1, "q") == 0)
 		{
+			/* I am going to use Alt + q to quit. */
 			endwin();
 			exit(1);
 		}
-		/*printf("%s\n", buffer);*/
+		else if (strcmp(buffer + 1, "n") == 0)
+		{
+			/* Alt + n to go to the next window */
+			if (focus_list && focus_list->next)
+				focus_list = focus_list->next;
+			else
+				focus_list = g_list_first(focus_list);
+			if (focus_list)
+			{
+				/* XXX: Need a way to bring it on top */
+				gnt_widget_draw(focus_list->data);
+			}
+		}
 	}
 	refresh();
 
@@ -184,7 +196,7 @@
 	WINDOW *win;
 	GList *iter;
 	GntNode *node = g_hash_table_lookup(nodes, widget);
-	if (node == NULL || node->below == NULL)	/* Yay! Nothing to do. */
+	if (node == NULL)	/* Yay! Nothing to do. */
 		return;
 
 	win = dupwin(widget->window);
@@ -212,6 +224,12 @@
 		n->above = g_list_remove(n->above, node);
 	}
 
+	for (iter = node->above; iter; iter = iter->next)
+	{
+		GntNode *n = iter->data;
+		n->below = g_list_remove(n->below, node);
+	}
+
 	wrefresh(win);
 	delwin(win);