From bba82eedbef0a2e3ea30ef924d64c85a7a105ad4 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 29 Jun 2010 11:05:19 +0200 Subject: Add a timer stopping the proccess after a while if idling There is no point to keep it around when not needed. --- src/empathy-av.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src') diff --git a/src/empathy-av.c b/src/empathy-av.c index f86999cba..cb0e82b1b 100644 --- a/src/empathy-av.c +++ b/src/empathy-av.c @@ -38,6 +38,56 @@ #include +/* Exit after $TIMEOUT seconds if not displaying any call window */ +#define TIMEOUT 60 + +static guint nb_windows = 0; +static guint timeout_id = 0; + +static gboolean +timeout_cb (gpointer data) +{ + DEBUG ("Timing out; exiting"); + + gtk_main_quit (); + return FALSE; +} + +static void +start_timer (void) +{ + if (timeout_id != 0) + return; + + DEBUG ("Start timer"); + + timeout_id = g_timeout_add_seconds (TIMEOUT, timeout_cb, NULL); +} + +static void +stop_timer (void) +{ + if (timeout_id == 0) + return; + + DEBUG ("Stop timer"); + + g_source_remove (timeout_id); + timeout_id = 0; +} + +static void +call_window_destroy_cb (EmpathyCallWindow *window, + gpointer user_data) +{ + nb_windows--; + + if (nb_windows > 0) + return; + + start_timer (); +} + static void new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler, @@ -46,7 +96,16 @@ new_call_handler_cb (EmpathyCallFactory *factory, { EmpathyCallWindow *window; + DEBUG ("Create a new call window"); + window = empathy_call_window_new (handler); + + nb_windows++; + stop_timer (); + + g_signal_connect (window, "destroy", + G_CALLBACK (call_window_destroy_cb), NULL); + gtk_widget_show (GTK_WIDGET (window)); } @@ -107,6 +166,8 @@ main (int argc, return EXIT_FAILURE; } + start_timer (); + gtk_main (); g_object_unref (call_factory); -- cgit v1.2.3