changeset 13952:841a5ffbfee4

[gaim-migrate @ 16500] uiops for GaimConnections. This only shows an error message for a disconnect. uiops for GaimNotify. I have not done the notifications for searchresults yet. That will require multi-column GntTree's, which will also allow for improved email-notifications. I hope to complete it by next week. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 17 Jul 2006 03:45:24 +0000
parents 614c56622453
children 8b2306c64efa
files console/Makefile console/gntblist.c console/gntconn.c console/gntconn.h console/gntgaim.h console/gntnotify.c console/gntnotify.h console/gntui.c console/libgnt/gntlabel.c console/libgnt/gntlabel.h console/libgnt/gntmain.c console/libgnt/gnttextview.c console/libgnt/gnttextview.h console/libgnt/gnttree.c console/libgnt/gnttree.h console/libgnt/test/multiwin.c console/libgnt/test/tv.c
diffstat 17 files changed, 314 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/console/Makefile	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/Makefile	Mon Jul 17 03:45:24 2006 +0000
@@ -6,19 +6,25 @@
 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:
--- a/console/gntblist.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/gntblist.c	Mon Jul 17 03:45:24 2006 +0000
@@ -288,7 +288,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 +325,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));
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntconn.c	Mon Jul 17 03:45:24 2006 +0000
@@ -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()
+{}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntconn.h	Mon Jul 17 03:45:24 2006 +0000
@@ -0,0 +1,8 @@
+#include "connection.h"
+
+GaimConnectionUiOps *gg_connections_get_ui_ops();
+
+void gg_connections_init();
+
+void gg_connections_uninit();
+
--- a/console/gntgaim.h	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/gntgaim.h	Mon Jul 17 03:45:24 2006 +0000
@@ -1,4 +1,5 @@
 #include <glib.h>
+#include <libintl.h>
 
 #define GAIM_GNT_UI "gnt-gaim"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntnotify.c	Mon Jul 17 03:45:24 2006 +0000
@@ -0,0 +1,160 @@
+#include <gnt.h>
+#include <gntbox.h>
+#include <gntbutton.h>
+#include <gntlabel.h>
+
+#include <util.h>
+
+#include "gntnotify.h"
+#include "gntgaim.h"
+
+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);
+
+	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 *
+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
+	{
+		/* XXX: Yes, yes. I know, the combined dialog thing. Maybe later. */
+		g_string_append_printf(message,
+				_("You have received a mail \"%s\""), *subjects);
+		if (froms && *froms && **froms)
+			g_string_append_printf(message, _("\nfrom %s"), *froms);
+		g_string_append_printf(message, _(" to %s (%s)"),
+				tos ? *tos : gaim_account_get_username(account),
+				gaim_account_get_protocol_name(account));
+	}
+
+	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()
+{
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/gntnotify.h	Mon Jul 17 03:45:24 2006 +0000
@@ -0,0 +1,8 @@
+#include "notify.h"
+
+GaimNotifyUiOps *gg_notify_get_ui_ops();
+
+void gg_notify_init();
+
+void gg_notify_uninit();
+
--- a/console/gntui.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/gntui.c	Mon Jul 17 03:45:24 2006 +0000
@@ -2,7 +2,9 @@
 
 #include "gntaccount.h"
 #include "gntblist.h"
+#include "gntconn.h"
 #include "gntconv.h"
+#include "gntnotify.h"
 
 void init_gnt_ui()
 {
@@ -12,6 +14,10 @@
 	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 +26,27 @@
 	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());
+
 	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();
 }
 
--- a/console/libgnt/gntlabel.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gntlabel.c	Mon Jul 17 03:45:24 2006 +0000
@@ -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,10 +110,16 @@
 
 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);
 
--- a/console/libgnt/gntlabel.h	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gntlabel.h	Mon Jul 17 03:45:24 2006 +0000
@@ -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,8 @@
 
 GntWidget *gnt_label_new(const char *text);
 
+GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags);
+
 G_END_DECLS
 
 #endif /* GNT_LABEL_H */
--- a/console/libgnt/gntmain.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gntmain.c	Mon Jul 17 03:45:24 2006 +0000
@@ -262,6 +262,7 @@
 		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);
--- a/console/libgnt/gnttextview.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gnttextview.c	Mon Jul 17 03:45:24 2006 +0000
@@ -178,19 +178,7 @@
 	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;
-
-	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);
+	fl = gnt_text_format_flag_to_chtype(flags);
 
 	view->list = g_list_first(view->list);
 
@@ -262,3 +250,24 @@
 	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;
+}
+
--- a/console/libgnt/gnttextview.h	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gnttextview.h	Mon Jul 17 03:45:24 2006 +0000
@@ -64,6 +64,8 @@
  * 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);
+
 G_END_DECLS
 
 #endif /* GNT_TEXT_VIEW_H */
--- a/console/libgnt/gnttree.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gnttree.c	Mon Jul 17 03:45:24 2006 +0000
@@ -716,3 +716,24 @@
 	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);
+}
+
--- a/console/libgnt/gnttree.h	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/gnttree.h	Mon Jul 17 03:45:24 2006 +0000
@@ -84,6 +84,8 @@
 
 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
 
+void gnt_tree_set_selected(GntTree *tree , void *key);
+
 G_END_DECLS
 
 #endif /* GNT_TREE_H */
--- a/console/libgnt/test/multiwin.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/test/multiwin.c	Mon Jul 17 03:45:24 2006 +0000
@@ -60,6 +60,8 @@
 
 	gnt_tree_set_row_flags(GNT_TREE(tree), "e", GNT_TEXT_FLAG_DIM);
 
+	gnt_tree_set_selected(GNT_TREE(tree), "2");
+
 	g_timeout_add(5000, (GSourceFunc)show, box2);
 
 	gnt_main();
--- a/console/libgnt/test/tv.c	Sun Jul 16 19:08:31 2006 +0000
+++ b/console/libgnt/test/tv.c	Mon Jul 17 03:45:24 2006 +0000
@@ -59,6 +59,7 @@
 
 	gnt_box_add_widget(GNT_BOX(hbox), view);
 	gnt_box_add_widget(GNT_BOX(hbox), entry);
+	gnt_box_add_widget(GNT_BOX(hbox), gnt_button_new("OK"));
 
 	gnt_widget_show(hbox);