static gboolean csm_logout_dialog_timeout (gpointer data) { CsmLogoutDialog *logout_dialog; char *seconds_warning; char *secondary_text; logout_dialog = (CsmLogoutDialog *) data; if (!logout_dialog->priv->timeout && logout_dialog->priv->delay_toggle) { gtk_dialog_response (GTK_DIALOG (logout_dialog), logout_dialog->priv->default_response); return FALSE; } switch (logout_dialog->priv->type) { case CSM_DIALOG_LOGOUT_TYPE_LOGOUT: /* This string is shared with csm-fail-whale-dialog.c */ seconds_warning = ngettext ("You will be automatically logged " "out in %d second.", "You will be logged " "out in %d seconds.", logout_dialog->priv->timeout); break; case CSM_DIALOG_LOGOUT_TYPE_SHUTDOWN: seconds_warning = ngettext ("This system will be automatically " "shut down in %d second.", "This system will be " "shut down in %d seconds.", logout_dialog->priv->timeout); break; case CSM_DIALOG_LOGOUT_TYPE_REBOOT: seconds_warning = ngettext ("This system will be automatically " "restarted in %d second.", "This system will be " "restarted in %d seconds.", logout_dialog->priv->timeout); break; default: g_assert_not_reached (); } if (!csm_system_is_login_session (logout_dialog->priv->system)) { char *name; name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL); if (!name || name[0] == '\0' || strcmp (name, "Unknown") == 0) { name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL); } if (!name) { name = g_strdup (g_get_user_name ()); } secondary_text = g_strdup_printf (_("You are currently logged in as \"%s\"."), name); g_free (name); } gdouble delay; delay = (gdouble)logout_dialog->priv->delay; seconds_warning = g_strdup_printf (seconds_warning, logout_dialog->priv->timeout); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar), logout_dialog->priv->timeout / delay); gtk_progress_bar_set_show_text( GTK_PROGRESS_BAR(logout_dialog->priv->progressbar), TRUE ); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar), seconds_warning); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog), secondary_text, NULL); logout_dialog->priv->timeout--; g_free (secondary_text); g_free (seconds_warning); return TRUE; }
static gboolean csm_logout_dialog_timeout (gpointer data) { CsmLogoutDialog *logout_dialog; char *seconds_warning; char *secondary_text; int seconds_to_show; logout_dialog = (CsmLogoutDialog *) data; if (!logout_dialog->priv->timeout) { gtk_dialog_response (GTK_DIALOG (logout_dialog), logout_dialog->priv->default_response); return FALSE; } if (logout_dialog->priv->timeout <= 30) { seconds_to_show = logout_dialog->priv->timeout; } else { seconds_to_show = (logout_dialog->priv->timeout/10) * 10; if (logout_dialog->priv->timeout % 10) seconds_to_show += 10; } switch (logout_dialog->priv->type) { case CSM_DIALOG_LOGOUT_TYPE_LOGOUT: /* This string is shared with csm-fail-whale-dialog.c */ seconds_warning = ngettext ("You will be automatically logged " "out in %d second.", "You will be automatically logged " "out in %d seconds.", seconds_to_show); break; case CSM_DIALOG_LOGOUT_TYPE_SHUTDOWN: seconds_warning = ngettext ("This system will be automatically " "shut down in %d second.", "This system will be automatically " "shut down in %d seconds.", seconds_to_show); break; case CSM_DIALOG_LOGOUT_TYPE_REBOOT: seconds_warning = ngettext ("This system will be automatically " "restarted in %d second.", "This system will be automatically " "restarted in %d seconds.", seconds_to_show); break; default: g_assert_not_reached (); } if (!csm_system_is_login_session (logout_dialog->priv->system)) { char *name, *tmp; name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL); if (!name || name[0] == '\0' || strcmp (name, "Unknown") == 0) { name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL); } if (!name) { name = g_strdup (g_get_user_name ()); } tmp = g_strdup_printf (_("You are currently logged in as \"%s\"."), name); secondary_text = g_strconcat (tmp, "\n", seconds_warning, NULL); g_free (tmp); g_free (name); } else { secondary_text = g_strdup (seconds_warning); } gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog), secondary_text, seconds_to_show, NULL); logout_dialog->priv->timeout--; g_free (secondary_text); return TRUE; }