changeset 18003:7935fe8ed901

merge of 'ac83216c7b78e652b47f1fd0bcb91f1eaf2cdf36' and 'f14ddacb0fca39c611f9756626e529d89514edec'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 10 Jun 2007 16:05:13 +0000
parents 38a72d6dce7f (current diff) a2c36e2010f1 (diff)
children d40fd7106ebf
files libpurple/conversation.c pidgin/gtkconv.c
diffstat 5 files changed, 162 insertions(+), 130 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/conversation.c	Mon Jun 04 06:32:21 2007 +0000
+++ b/libpurple/conversation.c	Sun Jun 10 16:05:13 2007 +0000
@@ -1536,20 +1536,22 @@
 		PurpleConvChatBuddyFlags flag = GPOINTER_TO_INT(fl->data);
 		const char *extra_msg = (extra_msgs ? extra_msgs->data : NULL);
 
-		if (!strcmp(chat->nick, purple_normalize(conv->account, user))) {
-			const char *alias2 = purple_account_get_alias(conv->account);
-			if (alias2 != NULL)
-				alias = alias2;
-			else
-			{
-				const char *display_name = purple_connection_get_display_name(gc);
-				if (display_name != NULL)
-					alias = display_name;
+		if(!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
+			if (!strcmp(chat->nick, purple_normalize(conv->account, user))) {
+				const char *alias2 = purple_account_get_alias(conv->account);
+				if (alias2 != NULL)
+					alias = alias2;
+				else
+				{
+					const char *display_name = purple_connection_get_display_name(gc);
+					if (display_name != NULL)
+						alias = display_name;
+				}
+			} else {
+				PurpleBuddy *buddy;
+				if ((buddy = purple_find_buddy(gc->account, user)) != NULL)
+					alias = purple_buddy_get_contact_alias(buddy);
 			}
-		} else if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
-			PurpleBuddy *buddy;
-			if ((buddy = purple_find_buddy(gc->account, user)) != NULL)
-				alias = purple_buddy_get_contact_alias(buddy);
 		}
 
 		quiet = GPOINTER_TO_INT(purple_signal_emit_return_1(purple_conversations_get_handle(),
@@ -1634,14 +1636,16 @@
 		/* Note this for later. */
 		is_me = TRUE;
 
-		alias = purple_account_get_alias(conv->account);
-		if (alias != NULL)
-			new_alias = alias;
-		else
-		{
-			const char *display_name = purple_connection_get_display_name(gc);
-			if (display_name != NULL)
-				alias = display_name;
+		if(!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
+			alias = purple_account_get_alias(conv->account);
+			if (alias != NULL)
+				new_alias = alias;
+			else
+			{
+				const char *display_name = purple_connection_get_display_name(gc);
+				if (display_name != NULL)
+					alias = display_name;
+			}
 		}
 	} else if (!(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
 		PurpleBuddy *buddy;
--- a/libpurple/idle.c	Mon Jun 04 06:32:21 2007 +0000
+++ b/libpurple/idle.c	Sun Jun 10 16:05:13 2007 +0000
@@ -92,7 +92,7 @@
 }
 
 
-static int no_away = 0;
+static gboolean no_away = FALSE;
 static gint time_until_next_idle_event;
 /*
  * This function should be called when you think your idle state
@@ -118,15 +118,15 @@
 	time_t time_idle;
 	gboolean auto_away;
 	const gchar *idle_reporting;
-	gboolean report_idle;
-	GList *l;
+	gboolean report_idle = TRUE;
 	gint away_seconds = 0;
 	gint idle_recheck_interval = 0;
 
 	purple_signal_emit(purple_blist_get_handle(), "update-idle");
 
 	idle_reporting = purple_prefs_get_string("/purple/away/idle_reporting");
-	report_idle = TRUE;
+	auto_away = purple_prefs_get_bool("/purple/away/away_when_idle");
+
 	if (!strcmp(idle_reporting, "system") &&
 		(idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL))
 	{
@@ -145,15 +145,9 @@
 		/* Don't report idle time */
 		time_idle = 0;
 		report_idle = FALSE;
-	}
 
-	/* Auto-away stuff */
-	auto_away = purple_prefs_get_bool("/purple/away/away_when_idle");
-
-	/* If we're not reporting idle, we can still do auto-away.
-	 * First try "system" and if that isn't possible, use "purple" */
-	if (!report_idle)
-	{
+		/* If we're not reporting idle, we can still do auto-away.
+		 * First try "system" and if that isn't possible, use "purple" */
 		if (auto_away)
 		{
 			if ((idle_ui_ops != NULL) && (idle_ui_ops->get_time_idle != NULL))
@@ -172,7 +166,7 @@
 			if (!no_away)
 			{
 				purple_savedstatus_set_idleaway(FALSE);
-				no_away = 1;
+				no_away = TRUE;
 			}
 			time_until_next_idle_event = 0;
 			return;
@@ -192,11 +186,11 @@
 	if (auto_away && time_idle > away_seconds)
 	{
 		purple_savedstatus_set_idleaway(TRUE);
-		no_away = 0;
+		no_away = FALSE;
 	}
 	else if (!no_away && time_idle < away_seconds)
 	{
-		no_away = 1;
+		no_away = TRUE;
 		purple_savedstatus_set_idleaway(FALSE);
 		if (time_until_next_idle_event == 0 || (away_seconds - time_idle) < time_until_next_idle_event)
 			time_until_next_idle_event = away_seconds - time_idle;
@@ -205,6 +199,7 @@
 	/* Idle reporting stuff */
 	if (report_idle && (time_idle >= IDLEMARK))
 	{
+		GList *l;
 		for (l = purple_connections_get_all(); l != NULL; l = l->next)
 		{
 			PurpleConnection *gc = l->data;
--- a/libpurple/protocols/yahoo/yahoo_packet.c	Mon Jun 04 06:32:21 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo_packet.c	Sun Jun 10 16:05:13 2007 +0000
@@ -110,6 +110,29 @@
 	return len;
 }
 
+/*
+ * 'len' is the value given to us by the server that is supposed to
+ * be the length of 'data'.  But apparently there's a time when this
+ * length is incorrect.  Christopher Layne thinks it might be a bug
+ * in their server code.
+ *
+ * The following information is from Christopher:
+ *
+ * It sometimes happens when Yahoo! sends a packet continuation within
+ * chat.  Sometimes when joining a large chatroom the initial
+ * SERVICE_CHATJOIN packet will be so large that it will need to be
+ * split into multiple packets.  That's fine, except that the length
+ * of the second packet is wrong.  The packet has the same length as
+ * the first packet, and the length given in the header is the same,
+ * however the actual data in the packet is shorter than this length.
+ * So half of the packet contains good, valid data, and then the rest
+ * of the packet is junk.  Luckily there is a null terminator after
+ * the valid data and before the invalid data.
+ *
+ * What does all this mean?  It means that we parse through the data
+ * pulling out key/value pairs until we've parsed 'len' bytes, or until
+ * we run into a null terminator, whichever comes first.
+ */
 void yahoo_packet_read(struct yahoo_packet *pkt, const guchar *data, int len)
 {
 	int pos = 0;
@@ -121,18 +144,8 @@
 
 	while (pos + 1 < len)
 	{
-		/* this is weird, and in one of the chat packets, and causes us to
-		 * think all the values are keys and all the keys are values after
-		 * this point if we don't handle it */
-		if (data[pos] == '\0') {
-			while (pos + 1 < len) {
-				if (data[pos] == 0xc0 && data[pos + 1] == 0x80)
-					break;
-				pos++;
-			}
-			pos += 2;
-			continue;
-		}
+		if (data[pos] == '\0')
+			break;
 
 		pair = g_new0(struct yahoo_pair, 1);
 
--- a/pidgin/gtkconv.c	Mon Jun 04 06:32:21 2007 +0000
+++ b/pidgin/gtkconv.c	Sun Jun 10 16:05:13 2007 +0000
@@ -2817,14 +2817,25 @@
 	GList *list;
 	PidginConversation *gtkconv;
 	PurpleConversation *conv;
-	PurpleBuddy *buddy;
+	PurpleBlistNode *node = NULL;
+	PurpleChat *chat = NULL;
+	PurpleBuddy *buddy = NULL;
 
 	gtkconv = pidgin_conv_window_get_active_gtkconv(win);
 	conv = gtkconv->active_conv;
-	buddy = purple_find_buddy(conv->account, conv->name);
 
 	menu = gtk_item_factory_get_widget(win->menu.item_factory, N_("/Conversation/More"));
 
+	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
+		chat = purple_blist_find_chat(conv->account, conv->name);
+	else
+		buddy = purple_find_buddy(conv->account, conv->name);
+
+	if (chat)
+		node = (PurpleBlistNode *)chat;
+	else if (buddy)
+		node = (PurpleBlistNode *)buddy;
+
 	/* Remove the previous entries */
 	for (list = gtk_container_get_children(GTK_CONTAINER(menu)); list; )
 	{
@@ -2834,12 +2845,11 @@
 	}
 
 	/* Now add the stuff */
-	if (buddy)
+	if (node)
 	{
 		if (purple_account_is_connected(conv->account))
-			pidgin_append_blist_node_proto_menu(menu, conv->account->gc,
-												  (PurpleBlistNode *)buddy);
-		pidgin_append_blist_node_extended_menu(menu, (PurpleBlistNode *)buddy);
+			pidgin_append_blist_node_proto_menu(menu, conv->account->gc, node);
+		pidgin_append_blist_node_extended_menu(menu, node);
 	}
 
 	if ((list = gtk_container_get_children(GTK_CONTAINER(menu))) == NULL)
--- a/pidgin/gtkimhtmltoolbar.c	Mon Jun 04 06:32:21 2007 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Sun Jun 10 16:05:13 2007 +0000
@@ -792,7 +792,8 @@
 	g_object_unref(object);
 }
 
-static void update_buttons(GtkIMHtmlToolbar *toolbar) {
+static void update_buttons(GtkIMHtmlToolbar *toolbar)
+{
 	gboolean bold, italic, underline;
 	char *tmp;
 	char *tmp2;
@@ -862,51 +863,53 @@
                     int               *x,
                     int               *y,
                     gboolean          *push_in,
-                    gpointer data)
+                    gpointer          data)
 {
-  GtkRequisition menu_req;
-  GtkTextDirection direction;
-  GdkRectangle monitor;
-  gint monitor_num;
-  GdkScreen *screen;
-  GtkWidget *widget = data;
+	GtkRequisition menu_req;
+	GtkTextDirection direction;
+	GdkRectangle monitor;
+	gint monitor_num;
+	GdkScreen *screen;
+	GtkWidget *widget = GTK_WIDGET(data);
 
-  gtk_widget_size_request (GTK_WIDGET (widget), &menu_req);
+	gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
 
-  direction = gtk_widget_get_direction (widget);
+	direction = gtk_widget_get_direction (widget);
 
-  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
-  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
-  if (monitor_num < 0)
-    monitor_num = 0;
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+	screen = gtk_widget_get_screen (GTK_WIDGET (menu));
+	monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+	if (monitor_num < 0)
+		monitor_num = 0;
+	gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
-  gdk_window_get_origin (widget->window, x, y);
-  *x += widget->allocation.x;
-    *y += widget->allocation.y;
+	gdk_window_get_origin (widget->window, x, y);
+	*x += widget->allocation.x;
+	*y += widget->allocation.y;
 
-      if (direction == GTK_TEXT_DIR_LTR)
-	*x += MAX (widget->allocation.width - menu_req.width, 0);
-      else if (menu_req.width > widget->allocation.width)
-        *x -= menu_req.width - widget->allocation.width;
+	if (direction == GTK_TEXT_DIR_LTR)
+		*x += MAX (widget->allocation.width - menu_req.width, 0);
+	else if (menu_req.width > widget->allocation.width)
+		*x -= menu_req.width - widget->allocation.width;
 
-      if ((*y + widget->allocation.height + menu_req.height) <= monitor.y + monitor.height)
-	*y += widget->allocation.height;
-      else if ((*y - menu_req.height) >= monitor.y)
-	*y -= menu_req.height;
-      else if (monitor.y + monitor.height - (*y + widget->allocation.height) > *y)
-	*y += widget->allocation.height;
-      else
-	*y -= menu_req.height;
-  *push_in = FALSE;
+	if ((*y + widget->allocation.height + menu_req.height) <= monitor.y + monitor.height)
+		*y += widget->allocation.height;
+	else if ((*y - menu_req.height) >= monitor.y)
+		*y -= menu_req.height;
+	else if (monitor.y + monitor.height - (*y + widget->allocation.height) > *y)
+		*y += widget->allocation.height;
+	else
+		*y -= menu_req.height;
+	*push_in = FALSE;
 }
 
-static void pidgin_menu_clicked(GtkWidget *button, GtkMenu *menu) {
+static void pidgin_menu_clicked(GtkWidget *button, GtkMenu *menu)
+{
 	gtk_widget_show_all(GTK_WIDGET(menu));
 	gtk_menu_popup(menu, NULL, NULL, menu_position_func, button, 0, gtk_get_current_event_time());
 }
 
-static void pidgin_menu_deactivate(GtkWidget *menu, GtkToggleButton *button) {
+static void pidgin_menu_deactivate(GtkWidget *menu, GtkToggleButton *button)
+{
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
 }
 
@@ -1026,8 +1029,20 @@
 	g_signal_connect(G_OBJECT(button), "clicked",
 			 G_CALLBACK(insert_smiley_cb), toolbar);
 	toolbar->smiley = button;
+}
 
+static void
+button_sensitiveness_changed(GtkWidget *button, gpointer dontcare, GtkWidget *item)
+{
+	gtk_widget_set_sensitive(item, GTK_WIDGET_IS_SENSITIVE(button));
+}
 
+static void
+update_menuitem(GtkToggleButton *button, GtkCheckMenuItem *item)
+{
+	g_signal_handlers_block_by_func(G_OBJECT(item), G_CALLBACK(gtk_button_clicked), button);
+	gtk_check_menu_item_set_active(item, gtk_toggle_button_get_active(button));
+	g_signal_handlers_unblock_by_func(G_OBJECT(item), G_CALLBACK(gtk_button_clicked), button);
 }
 
 static void gtk_imhtmltoolbar_init (GtkIMHtmlToolbar *toolbar)
@@ -1042,6 +1057,25 @@
 	GtkWidget *insert_menu;
 	GtkWidget *button;
 	GtkWidget *sep;
+	int i;
+	struct {
+		const char *label;
+		GtkWidget **button;
+	} buttons[] = {
+		{_("_Bold"), &toolbar->bold},
+		{_("_Italic"), &toolbar->italic},
+		{_("_Underline"), &toolbar->underline},
+		{_("_Larger"), &toolbar->larger_size},
+#if 0
+		{_("_Normal"), &toolbar->normal_size},
+#endif
+		{_("_Smaller"), &toolbar->smaller_size},
+		{_("_Font face"), &toolbar->font},
+		{_("_Foreground color"), &toolbar->fgcolor},
+		{_("_Background color"), &toolbar->bgcolor},
+		{NULL, NULL}
+	};
+
 
 	toolbar->imhtml = NULL;
 	toolbar->font_dialog = NULL;
@@ -1057,7 +1091,7 @@
 
 	gtk_imhtmltoolbar_create_old_buttons(toolbar);
 
-	/* Bold */
+	/* Fonts */
 	font_button = gtk_toggle_button_new();
 	gtk_button_set_relief(GTK_BUTTON(font_button), GTK_RELIEF_NONE);
 	bbox = gtk_hbox_new(FALSE, 3);
@@ -1070,45 +1104,21 @@
 	gtk_widget_show_all(font_button);
 
 	font_menu = gtk_menu_new();
-
-	button = gtk_check_menu_item_new_with_mnemonic(_("_Bold"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->bold);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_check_menu_item_new_with_mnemonic(_("_Italic"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->italic);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_check_menu_item_new_with_mnemonic(_("_Underline"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->underline);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Larger"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->larger_size);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Normal"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->normal_size);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Smaller"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->smaller_size);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Font face"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->font);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Foreground color"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->fgcolor);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
-	button = gtk_menu_item_new_with_mnemonic(_("_Background color"));
-	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->bgcolor);
-	gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), button);
-
+	
+	for (i = 0; buttons[i].label; i++) {
+		GtkWidget *old = *buttons[i].button;
+		GtkWidget *menuitem = gtk_check_menu_item_new_with_mnemonic(buttons[i].label);
+		g_signal_connect_swapped(G_OBJECT(menuitem), "activate",
+				G_CALLBACK(gtk_button_clicked), old);
+		g_signal_connect_after(G_OBJECT(old), "toggled",
+				G_CALLBACK(update_menuitem), menuitem);
+		gtk_menu_shell_append(GTK_MENU_SHELL(font_menu), menuitem);
+		g_signal_connect(G_OBJECT(old), "notify::sensitive",
+				G_CALLBACK(button_sensitiveness_changed), menuitem);
+	}
+  
 	g_signal_connect(G_OBJECT(font_button), "clicked", G_CALLBACK(pidgin_menu_clicked), font_menu);
-	g_signal_connect(G_OBJECT(font_menu), "deactivate", G_CALLBACK(pidgin_menu_deactivate), font_button);	
+	g_signal_connect(G_OBJECT(font_menu), "deactivate", G_CALLBACK(pidgin_menu_deactivate), font_button);
 
 	/* Sep */
 	sep = gtk_vseparator_new();
@@ -1135,7 +1145,7 @@
 	gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, FALSE, 0);
 	gtk_widget_show_all(sep);
 
-	/* Insert Link */
+	/* Insert */
 	insert_button = gtk_toggle_button_new();
 	gtk_button_set_relief(GTK_BUTTON(insert_button), GTK_RELIEF_NONE);
 	bbox = gtk_hbox_new(FALSE, 3);
@@ -1148,11 +1158,11 @@
 	gtk_widget_show_all(insert_button);
 
 	insert_menu = gtk_menu_new();
-
+	
 	button = gtk_menu_item_new_with_mnemonic(_("_Smiley"));
 	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->smiley);
 	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), button);
-
+	
 	button = gtk_menu_item_new_with_mnemonic(_("_Image"));
 	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->image);
 	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), button);
@@ -1160,7 +1170,7 @@
 	button = gtk_menu_item_new_with_mnemonic(_("_Link"));
 	g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gtk_button_clicked), toolbar->link);
 	gtk_menu_shell_append(GTK_MENU_SHELL(insert_menu), button);
-
+	
 	g_signal_connect(G_OBJECT(insert_button), "clicked", G_CALLBACK(pidgin_menu_clicked), insert_menu);
 	g_signal_connect(G_OBJECT(insert_menu), "deactivate", G_CALLBACK(pidgin_menu_deactivate), insert_button);
 	toolbar->sml = NULL;