summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-05-09 11:06:49 +0200
committerPatrick Griffis <tingping@tingping.se>2016-06-29 15:42:11 -0400
commit215a164e57c7eb19beca503be2da1f50660ffb82 (patch)
tree7c4fb6b2bee69acf287701e2e160e893c7d35f75 /src
parent9e4c2ddc47592d26cd4184e8942806fbd7becf18 (diff)
Ensure that timers are freed and activated when necessary
Diffstat (limited to 'src')
-rw-r--r--src/common/hexchat.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/common/hexchat.c b/src/common/hexchat.c
index 3104ec53..64fd351e 100644
--- a/src/common/hexchat.c
+++ b/src/common/hexchat.c
@@ -377,26 +377,50 @@ hexchat_reinit_timers (void)
 	static int lag_check_tag = 0;
 	static int away_tag = 0;
 
-	if (prefs.hex_notify_timeout)
+	/* notify timeout */
+	if (prefs.hex_notify_timeout && notify_tag == 0)
 	{
 		notify_tag = fe_timeout_add_seconds (prefs.hex_notify_timeout,
 						     notify_checklist, NULL);
-	} else
+	}
+	else if (notify_tag != 0)
 	{
 		fe_timeout_remove (notify_tag);
+		notify_tag = 0;
 	}
 
-	fe_timeout_remove (away_tag);
-	away_tag = fe_timeout_add_seconds (prefs.hex_away_timeout, away_check, NULL);
+	/* away status tracking */
+	if (prefs.hex_away_track && away_tag == 0)
+	{
+		away_tag = fe_timeout_add_seconds (prefs.hex_away_timeout, away_check, NULL);
+	}
+	else if (away_tag != 0)
+	{
+		fe_timeout_remove (away_tag);
+		away_tag = 0;
+	}
 
-	if (prefs.hex_gui_lagometer)
+	/* lag-o-meter */
+	if (prefs.hex_gui_lagometer && lag_check_update_tag == 0)
 	{
 		lag_check_update_tag = fe_timeout_add (500, hexchat_lag_check_update, NULL);
-		lag_check_tag = fe_timeout_add_seconds (30, hexchat_lag_check, NULL);
-	} else
+	}
+	else if (lag_check_update_tag != 0)
 	{
 		fe_timeout_remove (lag_check_update_tag);
+		lag_check_update_tag = 0;
+	}
+
+	/* network timeouts and lag-o-meter */
+	if ((prefs.hex_net_ping_timeout != 0 || prefs.hex_gui_lagometer)
+	    && lag_check_tag == 0)
+	{
+		lag_check_tag = fe_timeout_add_seconds (30, hexchat_lag_check, NULL);
+	}
+	else if (lag_check_tag != 0)
+	{
 		fe_timeout_remove (lag_check_tag);
+		lag_check_tag = 0;
 	}
 }