changeset 22627:c240e7eb379d

merge of 'b2b2efabbafab6588e02ceb16509419dcb0c79e9' and 'b426234bbef68ed60bc6f15fc35ea1690d5a8ed1'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 04 Apr 2008 06:11:09 +0000
parents eccdd341dc6e (current diff) 357809e70305 (diff)
children 29f20ae16bf9 98775a5b4817
files
diffstat 2 files changed, 53 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/status.c	Fri Apr 04 04:42:26 2008 +0000
+++ b/libpurple/status.c	Fri Apr 04 06:11:09 2008 +0000
@@ -1547,14 +1547,37 @@
 	return purple_presence_is_online(presence) ? presence->login_time : 0;
 }
 
+static int
+purple_presence_compute_score(const PurplePresence *presence)
+{
+	GList *l;
+	int score = 0;
+
+	for (l = purple_presence_get_statuses(presence); l != NULL; l = l->next) {
+		PurpleStatus *status = (PurpleStatus *)l->data;
+		PurpleStatusType *type = purple_status_get_type(status);
+
+		if (purple_status_is_active(status)) {
+			score += primitive_scores[purple_status_type_get_primitive(type)];
+			if (!purple_status_is_online(status)) {
+				PurpleBuddy *b = purple_presence_get_buddy(presence);
+				if (b && purple_account_supports_offline_message(purple_buddy_get_account(b), b))
+					score += primitive_scores[SCORE_OFFLINE_MESSAGE];
+			}
+		}
+	}
+	score += purple_account_get_int(purple_presence_get_account(presence), "score", 0);
+	if (purple_presence_is_idle(presence))
+		score += primitive_scores[SCORE_IDLE];
+	return score;
+}
+
 gint
 purple_presence_compare(const PurplePresence *presence1,
 		const PurplePresence *presence2)
 {
-	gboolean idle1, idle2;
 	time_t idle_time_1, idle_time_2;
 	int score1 = 0, score2 = 0;
-	GList *l;
 
 	if (presence1 == presence2)
 		return 0;
@@ -1563,49 +1586,18 @@
 	else if (presence2 == NULL)
 		return -1;
 
-	/* Compute the score of the first set of statuses. */
-	for (l = purple_presence_get_statuses(presence1); l != NULL; l = l->next)
-	{
-		PurpleStatus *status = (PurpleStatus *)l->data;
-		PurpleStatusType *type = purple_status_get_type(status);
+	if (purple_presence_is_online(presence1) &&
+			!purple_presence_is_online(presence2))
+		return -1;
+	else if (purple_presence_is_online(presence2) &&
+			!purple_presence_is_online(presence1))
+		return 1;
 
-		if (purple_status_is_active(status)) {
-			score1 += primitive_scores[purple_status_type_get_primitive(type)];
-			if (!purple_status_is_online(status)) {
-				PurpleBuddy *b = purple_presence_get_buddy(presence1);
-				if (b && purple_account_supports_offline_message(purple_buddy_get_account(b),b))
-					score1 += primitive_scores[SCORE_OFFLINE_MESSAGE];
-			}
-		}
-	}
-	score1 += purple_account_get_int(purple_presence_get_account(presence1), "score", 0);
+	/* Compute the score of the first set of statuses. */
+	score1 = purple_presence_compute_score(presence1);
 
 	/* Compute the score of the second set of statuses. */
-	for (l = purple_presence_get_statuses(presence2); l != NULL; l = l->next)
-	{
-		PurpleStatus *status = (PurpleStatus *)l->data;
-		PurpleStatusType *type = purple_status_get_type(status);
-
-		if (purple_status_is_active(status)) {
-			score2 += primitive_scores[purple_status_type_get_primitive(type)];
-			if (!purple_status_is_online(status)) {
-				PurpleBuddy *b = purple_presence_get_buddy(presence2);
-				if (b && purple_account_supports_offline_message(purple_buddy_get_account(b),b))
-					score2 += primitive_scores[SCORE_OFFLINE_MESSAGE];
-			}
-
-		}
-	}
-	score2 += purple_account_get_int(purple_presence_get_account(presence2), "score", 0);
-
-	idle1 = purple_presence_is_idle(presence1);
-	idle2 = purple_presence_is_idle(presence2);
-
-	if (idle1)
-		score1 += primitive_scores[SCORE_IDLE];
-
-	if (idle2)
-		score2 += primitive_scores[SCORE_IDLE];
+	score2 = purple_presence_compute_score(presence2);
 
 	idle_time_1 = time(NULL) - purple_presence_get_idle_time(presence1);
 	idle_time_2 = time(NULL) - purple_presence_get_idle_time(presence2);
--- a/pidgin/gtkconv.c	Fri Apr 04 04:42:26 2008 +0000
+++ b/pidgin/gtkconv.c	Fri Apr 04 06:11:09 2008 +0000
@@ -4363,33 +4363,35 @@
 {
 	GtkTextBuffer *buffer;
 	GtkTextIter iter;
-	int wrapped_lines;
 	int lines;
 	GdkRectangle oneline;
 	int height, diff;
 	int pad_top, pad_inside, pad_bottom;
 	int max_height = gtkconv->tab_cont->allocation.height / 2;
 
-	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
-
-	wrapped_lines = 1;
-	gtk_text_buffer_get_start_iter(buffer, &iter);
-	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(gtkconv->entry), &iter, &oneline);
-	while (gtk_text_view_forward_display_line(GTK_TEXT_VIEW(gtkconv->entry), &iter))
-		wrapped_lines++;
-
-	lines = gtk_text_buffer_get_line_count(buffer);
-
-	/* Show at least two lines */
-	wrapped_lines = MAX(wrapped_lines, 2);
-
 	pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(gtkconv->entry));
 	pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(gtkconv->entry));
 	pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(gtkconv->entry));
 
-	height = (oneline.height + pad_top + pad_bottom) * lines;
-	if (wrapped_lines > lines)
-		height += (oneline.height + pad_inside) * (wrapped_lines - lines);
+	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
+	gtk_text_buffer_get_start_iter(buffer, &iter);
+	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(gtkconv->entry), &iter, &oneline);
+
+	lines = gtk_text_buffer_get_line_count(buffer);
+
+	height = 0;
+	do {
+		int lineheight = 0;
+		gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(gtkconv->entry), &iter, NULL, &lineheight);
+		height += lineheight;
+		lines--;
+	} while (gtk_text_iter_forward_line(&iter));
+	height += lines * (oneline.height + pad_top + pad_bottom);
+
+	/* Make sure there's enough room for at least two lines. Allocate enough space to
+	 * prevent scrolling when the second line is a continuation of the first line, or
+	 * is the beginning of a new paragraph. */
+	height = MAX(height, 2 * (oneline.height + MAX(pad_inside, pad_top + pad_bottom)));
 
 	height = MIN(height, max_height);