From 526dbcddf5a3969a8714b49441e4dd62927837f3 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 18 Aug 2010 16:55:03 +0200 Subject: Implement a timeout machinery for the auth client Similar to the one used in empathy-av.c --- src/empathy-auth-client.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/empathy-auth-client.c b/src/empathy-auth-client.c index 45812e8e9..7546164d3 100644 --- a/src/empathy-auth-client.c +++ b/src/empathy-auth-client.c @@ -39,6 +39,47 @@ #include +#define TIMEOUT 60 + +static gboolean use_timer = TRUE; +static guint timeout_id = 0; +static guint num_windows = 0; + +static gboolean +timeout_cb (gpointer p) +{ + DEBUG ("Timeout reached; exiting..."); + + gtk_main_quit (); + return FALSE; +} + +static void +start_timer (void) +{ + if (!use_timer) + return; + + 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 tls_dialog_response_cb (GtkDialog *dialog, gint response_id, @@ -69,6 +110,14 @@ tls_dialog_response_cb (GtkDialog *dialog, empathy_tls_certificate_store_ca (certificate); g_object_unref (certificate); + + /* restart the timeout */ + num_windows--; + + if (num_windows > 0) + return; + + start_timer (); } static void @@ -78,6 +127,10 @@ display_interactive_dialog (EmpathyTLSCertificate *certificate, { GtkWidget *tls_dialog; + /* stop the timeout */ + num_windows++; + stop_timer (); + tls_dialog = empathy_tls_dialog_new (certificate, reason, details); g_signal_connect (tls_dialog, "response", G_CALLBACK (tls_dialog_response_cb), NULL); @@ -188,7 +241,16 @@ main (int argc, return EXIT_FAILURE; } - DEBUG ("Empathy auth client started."); + DEBUG ("Empathy auth client started."); + + if (g_getenv ("EMPATHY_PERSIST") != NULL) + { + DEBUG ("Timed-exit disabled"); + + use_timer = FALSE; + } + + start_timer (); gtk_main (); -- cgit v1.2.3