changeset 26531:b162300ab1e7

A patch from Arunan Balasubramaniam to use timeouts in seconds instead of milliseconds in Pidgin. This enables grouping of timers for greater power efficiency. Fixes #8834. committer: Elliott Sales de Andrade <qulogic@pidgin.im>
author foss@abala.me
date Fri, 10 Apr 2009 06:32:57 +0000
parents b87843de7c6a
children 344061a9f85d
files pidgin/gtkblist.c pidgin/gtkconv.c pidgin/gtkdebug.c pidgin/gtksound.c pidgin/gtkstatusbox.c pidgin/gtkutils.c pidgin/plugins/cap/cap.c pidgin/plugins/mailchk.c
diffstat 8 files changed, 31 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkblist.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtkblist.c	Fri Apr 10 06:32:57 2009 +0000
@@ -5795,7 +5795,7 @@
 	purple_blist_set_visible(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/list_visible"));
 
 	/* start the refresh timer */
-	gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)pidgin_blist_refresh_timer, list);
+	gtkblist->refresh_timer = purple_timeout_add_seconds(30, (GSourceFunc)pidgin_blist_refresh_timer, list);
 
 	handle = pidgin_blist_get_handle();
 
@@ -5916,7 +5916,7 @@
 	blist = purple_get_blist();
 	gtkblist = PIDGIN_BLIST(purple_get_blist());
 
-	gtkblist->refresh_timer = g_timeout_add(30000,(GSourceFunc)pidgin_blist_refresh_timer, blist);
+	gtkblist->refresh_timer = purple_timeout_add_seconds(30,(GSourceFunc)pidgin_blist_refresh_timer, blist);
 }
 
 static gboolean get_iter_from_node(PurpleBlistNode *node, GtkTreeIter *iter) {
@@ -6637,7 +6637,7 @@
 	pidgin_blist_tooltip_destroy();
 
 	if (gtkblist->refresh_timer)
-		g_source_remove(gtkblist->refresh_timer);
+		purple_timeout_remove(gtkblist->refresh_timer);
 	if (gtkblist->timeout)
 		g_source_remove(gtkblist->timeout);
 	if (gtkblist->drag_timeout)
@@ -7452,7 +7452,7 @@
 
 	if(gtknode->recent_signonoff_timer > 0)
 		purple_timeout_remove(gtknode->recent_signonoff_timer);
-	gtknode->recent_signonoff_timer = purple_timeout_add(10000,
+	gtknode->recent_signonoff_timer = purple_timeout_add_seconds(10,
 			(GSourceFunc)buddy_signonoff_timeout_cb, buddy);
 }
 
--- a/pidgin/gtkconv.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtkconv.c	Fri Apr 10 06:32:57 2009 +0000
@@ -7514,7 +7514,7 @@
 	}
 
 	/* In case a conversation is started after the buddy has signed-on/off */
-	g_timeout_add(11000, (GSourceFunc)update_buddy_status_timeout, buddy);
+	purple_timeout_add_seconds(11, (GSourceFunc)update_buddy_status_timeout, buddy);
 }
 
 static void
--- a/pidgin/gtkdebug.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtkdebug.c	Fri Apr 10 06:32:57 2009 +0000
@@ -94,7 +94,7 @@
 	if(debug_win->timer != 0) {
 		const gchar *text;
 
-		g_source_remove(debug_win->timer);
+		purple_timeout_remove(debug_win->timer);
 
 		text = gtk_entry_get_text(GTK_ENTRY(debug_win->expression));
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/debug/regex", text);
@@ -552,7 +552,7 @@
 	}
 
 	if(win->timer == 0)
-		win->timer = purple_timeout_add(5000, (GSourceFunc)regex_timer_cb, win);
+		win->timer = purple_timeout_add_seconds(5, (GSourceFunc)regex_timer_cb, win);
 
 	regex_compile(win);
 }
--- a/pidgin/gtksound.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtksound.c	Fri Apr 10 06:32:57 2009 +0000
@@ -226,9 +226,9 @@
 account_signon_cb(PurpleConnection *gc, gpointer data)
 {
 	if (mute_login_sounds_timeout != 0)
-		g_source_remove(mute_login_sounds_timeout);
+		purple_timeout_remove(mute_login_sounds_timeout);
 	mute_login_sounds = TRUE;
-	mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL);
+	mute_login_sounds_timeout = purple_timeout_add_seconds(10, unmute_login_sounds_cb, NULL);
 }
 
 const char *
--- a/pidgin/gtkstatusbox.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtkstatusbox.c	Fri Apr 10 06:32:57 2009 +0000
@@ -67,7 +67,8 @@
 #  endif
 #endif
 
-#define TYPING_TIMEOUT 4000
+/* Timeout for typing notifications in seconds */
+#define TYPING_TIMEOUT 4
 
 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data);
 static void imhtml_format_changed_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, void *data);
@@ -1155,7 +1156,7 @@
 	/* Reset the status if Escape was pressed */
 	if (event->keyval == GDK_Escape)
 	{
-		g_source_remove(status_box->typing);
+		purple_timeout_remove(status_box->typing);
 		status_box->typing = 0;
 		if (status_box->account != NULL)
 			update_to_reflect_account_status(status_box, status_box->account,
@@ -1168,8 +1169,8 @@
 	}
 
 	pidgin_status_box_pulse_typing(status_box);
-	g_source_remove(status_box->typing);
-	status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
+	purple_timeout_remove(status_box->typing);
+	status_box->typing = purple_timeout_add_seconds(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
 
 	return FALSE;
 }
@@ -2596,7 +2597,7 @@
 		return;
 	}
 
-	g_source_remove(status_box->typing);
+	purple_timeout_remove(status_box->typing);
 	status_box->typing = 0;
 
 	activate_currently_selected_status(status_box);
@@ -2624,7 +2625,7 @@
 			   DATA_COLUMN, &data,
 			   -1);
 	if (status_box->typing != 0)
-		g_source_remove(status_box->typing);
+		purple_timeout_remove(status_box->typing);
 	status_box->typing = 0;
 
 	if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box)))
@@ -2692,7 +2693,7 @@
 			GtkTextIter start, end;
 			GtkTextBuffer *buffer;
 			gtk_widget_show_all(status_box->vbox);
-			status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
+			status_box->typing = purple_timeout_add_seconds(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
 			gtk_widget_grab_focus(status_box->imhtml);
 			buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml));
 			gtk_text_buffer_get_bounds(buffer, &start, &end);
@@ -2741,9 +2742,9 @@
 	{
 		if (status_box->typing != 0) {
 			pidgin_status_box_pulse_typing(status_box);
-			g_source_remove(status_box->typing);
+			purple_timeout_remove(status_box->typing);
 		}
-		status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
+		status_box->typing = purple_timeout_add_seconds(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
 	}
 	pidgin_status_box_refresh(status_box);
 }
--- a/pidgin/gtkutils.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/gtkutils.c	Fri Apr 10 06:32:57 2009 +0000
@@ -950,7 +950,7 @@
 	           "accel changed, scheduling save.\n");
 
 	if (!accels_save_timer)
-		accels_save_timer = g_timeout_add(5000, pidgin_save_accels,
+		accels_save_timer = purple_timeout_add_seconds(5, pidgin_save_accels,
 		                                  NULL);
 }
 
--- a/pidgin/plugins/cap/cap.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/plugins/cap/cap.c	Fri Apr 10 06:32:57 2009 +0000
@@ -135,7 +135,7 @@
 	/* g_free(stats->hourly_usage); */
 	/* g_free(stats->daily_usage); */
 	if (stats->timeout_source_id != 0)
-		g_source_remove(stats->timeout_source_id);
+		purple_timeout_remove(stats->timeout_source_id);
 	g_free(stats);
 }
 
@@ -352,7 +352,7 @@
 	if (buddy == NULL)
 		return;
 
-	interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60;
+	interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 60;
 	words = word_count(message);
 
 	stats = get_stats_for(buddy);
@@ -361,9 +361,9 @@
 	stats->last_message = time(NULL);
 	stats->last_message_status_id = purple_status_get_id(get_status_for(buddy));
 	if(stats->timeout_source_id != 0)
-		g_source_remove(stats->timeout_source_id);
+		purple_timeout_remove(stats->timeout_source_id);
 
-	stats->timeout_source_id = g_timeout_add(interval, max_message_difference_cb, stats);
+	stats->timeout_source_id = purple_timeout_add_seconds(interval, max_message_difference_cb, stats);
 }
 
 /* received-im-msg */
@@ -386,7 +386,7 @@
 	 * then cancel the timeout callback. */
 	if(stats->timeout_source_id != 0) {
 		purple_debug_info("cap", "Cancelling timeout callback\n");
-		g_source_remove(stats->timeout_source_id);
+		purple_timeout_remove(stats->timeout_source_id);
 		stats->timeout_source_id = 0;
 	}
 
@@ -697,7 +697,7 @@
 static void cancel_conversation_timeouts(gpointer key, gpointer value, gpointer user_data) {
 	CapStatistics *stats = value;
 	if(stats->timeout_source_id != 0) {
-		g_source_remove(stats->timeout_source_id);
+		purple_timeout_remove(stats->timeout_source_id);
 		stats->timeout_source_id = 0;
 	}
 }
--- a/pidgin/plugins/mailchk.c	Fri Apr 10 06:18:08 2009 +0000
+++ b/pidgin/plugins/mailchk.c	Fri Apr 10 06:32:57 2009 +0000
@@ -13,7 +13,7 @@
 #define UNREAD_MAIL 0x02
 #define NEW_MAIL    0x04
 
-static guint32 timer = 0;
+static guint timer = 0;
 static GtkWidget *mail = NULL;
 
 static gint
@@ -93,7 +93,7 @@
 	PurpleBuddyList *list = purple_get_blist();
 	if (list && PURPLE_IS_GTK_BLIST(list) && !timer) {
 		check_timeout(NULL); /* we want the box to be drawn immediately */
-		timer = g_timeout_add(2000, check_timeout, NULL);
+		timer = purple_timeout_add_seconds(2, check_timeout, NULL);
 	}
 }
 
@@ -102,7 +102,7 @@
 {
 	PurpleBuddyList *list = purple_get_blist();
 	if ((!list || !PURPLE_IS_GTK_BLIST(list) || !PIDGIN_BLIST(list)->vbox) && timer) {
-		g_source_remove(timer);
+		purple_timeout_remove(timer);
 		timer = 0;
 	}
 }
@@ -123,7 +123,7 @@
 	}
 
 	if (list && PURPLE_IS_GTK_BLIST(list) && PIDGIN_BLIST(list)->vbox)
-		timer = g_timeout_add(2000, check_timeout, NULL);
+		timer = purple_timeout_add_seconds(2, check_timeout, NULL);
 
 	purple_signal_connect(conn_handle, "signed-on",
 						plugin, PURPLE_CALLBACK(signon_cb), NULL);
@@ -137,7 +137,7 @@
 plugin_unload(PurplePlugin *plugin)
 {
 	if (timer)
-		g_source_remove(timer);
+		purple_timeout_remove(timer);
 	timer = 0;
 	if (mail)
 		gtk_widget_destroy(mail);