static GtkWidget * gsm_get_dialog (GsmDialogLogoutType type, GdkScreen *screen, guint32 activate_time) { GsmLogoutDialog *logout_dialog; GtkWidget *dialog_image; GtkWidget *hbox; const char *primary_text; const char *icon_name; if (current_dialog != NULL) { gtk_widget_destroy (GTK_WIDGET (current_dialog)); } logout_dialog = g_object_new (GSM_TYPE_LOGOUT_DIALOG, NULL); current_dialog = logout_dialog; gtk_window_set_title (GTK_WINDOW (logout_dialog), ""); logout_dialog->priv->type = type; icon_name = NULL; primary_text = NULL; switch (type) { case GSM_DIALOG_LOGOUT_TYPE_LOGOUT: icon_name = GSM_ICON_LOGOUT; primary_text = _("Log out of this system now?"); logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_LOGOUT; if (gsm_logout_supports_switch_user (logout_dialog)) { gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("_Switch User"), GSM_LOGOUT_RESPONSE_SWITCH_USER); } gtk_dialog_add_button (GTK_DIALOG (logout_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("_Log Out"), GSM_LOGOUT_RESPONSE_LOGOUT); break; case GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN: icon_name = GSM_ICON_SHUTDOWN; primary_text = _("Shut down this system now?"); logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_SHUTDOWN; if (gsm_logout_supports_system_suspend (logout_dialog)) { gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("S_uspend"), GSM_LOGOUT_RESPONSE_SLEEP); } if (gsm_logout_supports_system_hibernate (logout_dialog)) { gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("_Hibernate"), GSM_LOGOUT_RESPONSE_HIBERNATE); } if (gsm_logout_supports_reboot (logout_dialog)) { gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("_Restart"), GSM_LOGOUT_RESPONSE_REBOOT); } gtk_dialog_add_button (GTK_DIALOG (logout_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); if (gsm_logout_supports_shutdown (logout_dialog)) { gtk_dialog_add_button (GTK_DIALOG (logout_dialog), _("_Shut Down"), GSM_LOGOUT_RESPONSE_SHUTDOWN); } break; default: g_assert_not_reached (); } dialog_image = gtk_message_dialog_get_image (GTK_MESSAGE_DIALOG (logout_dialog)); #if GTK_CHECK_VERSION (3, 0, 0) hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #else hbox = gtk_hbox_new (FALSE, 0); #endif logout_dialog->priv->progressbar = gtk_progress_bar_new (); #if GTK_CHECK_VERSION (3, 0, 0) gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar), TRUE); #endif gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (logout_dialog->priv->progressbar), 1.0); gtk_box_pack_start (GTK_BOX (hbox), logout_dialog->priv->progressbar, TRUE, TRUE, 12); gtk_widget_show_all (hbox); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (logout_dialog))), hbox); gtk_image_set_from_icon_name (GTK_IMAGE (dialog_image), icon_name, GTK_ICON_SIZE_DIALOG); gtk_window_set_icon_name (GTK_WINDOW (logout_dialog), icon_name); gtk_window_set_position (GTK_WINDOW (logout_dialog), GTK_WIN_POS_CENTER_ALWAYS); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (logout_dialog), primary_text); gtk_dialog_set_default_response (GTK_DIALOG (logout_dialog), logout_dialog->priv->default_response); gtk_window_set_screen (GTK_WINDOW (logout_dialog), screen); return GTK_WIDGET (logout_dialog); }
static GtkWidget * gsm_get_dialog (GsmDialogLogoutType type, GdkScreen *screen, guint32 activate_time) { GsmLogoutDialog *logout_dialog; GtkWidget *dialog_image; GtkWidget *vbox; GtkWidget *tile; const char *icon_name; const char *title; if (current_dialog != NULL) { gtk_widget_destroy (GTK_WIDGET (current_dialog)); } logout_dialog = g_object_new (GSM_TYPE_LOGOUT_DIALOG, NULL); current_dialog = logout_dialog; vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (logout_dialog)->vbox), vbox, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_widget_show (vbox); icon_name = NULL; title = NULL; switch (type) { case GSM_DIALOG_LOGOUT_TYPE_LOGOUT: icon_name = GSM_ICON_LOGOUT; title = _("Log Out of the Session"); logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_LOGOUT; gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_LOGOUT, GSM_ICON_LOGOUT, _("_Log Out"), _("Ends your session and logs you " "out.")); tile = gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_SWITCH_USER, GSM_ICON_SWITCH, _("_Switch User"), _("Suspends your session, " "allowing another user to " "log in and use the " "computer.")); if (!gsm_logout_supports_switch_user (logout_dialog)) { gtk_widget_set_sensitive (tile, FALSE); } break; case GSM_DIALOG_LOGOUT_TYPE_SHUTDOWN: icon_name = GSM_ICON_SHUTDOWN; title = _("Shut Down the Computer"); logout_dialog->priv->default_response = GSM_LOGOUT_RESPONSE_SHUTDOWN; tile = gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_SHUTDOWN, GSM_ICON_SHUTDOWN, _("_Shut Down"), _("Ends your session and turns " "off the computer.")); if (!gsm_logout_supports_shutdown (logout_dialog)) { gtk_widget_set_sensitive (tile, FALSE); /* If shutdown is not available, let's just fallback * on cancel as the default action. We could fallback * on reboot first, then suspend and then hibernate * but it's not that useful, really */ logout_dialog->priv->default_response = GTK_RESPONSE_CANCEL; } tile = gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_REBOOT, GSM_ICON_REBOOT, _("_Restart"), _("Ends your session and " "restarts the computer.")); if (!gsm_logout_supports_reboot (logout_dialog)) { gtk_widget_set_sensitive (tile, FALSE); } /* We don't set those options insensitive if they are no * supported (like we do for shutdown/restart) since some * hardware just don't support suspend/hibernate. So we * don't show those options in this case. */ if (gsm_logout_supports_system_suspend (logout_dialog)) { gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_SLEEP, GSM_ICON_SLEEP, _("S_uspend"), _("Suspends your session " "quickly, using minimal " "power while the computer " "stands by.")); } if (gsm_logout_supports_system_hibernate (logout_dialog)) { gsm_logout_append_tile (vbox, GSM_LOGOUT_RESPONSE_HIBERNATE, GSM_ICON_HIBERNATE, _("Hiber_nate"), _("Suspends your session, " "using no power until the " "computer is restarted.")); } break; default: g_assert_not_reached (); } logout_dialog->priv->info_label = gtk_label_new (""); gtk_label_set_line_wrap (GTK_LABEL (logout_dialog->priv->info_label), TRUE); gtk_box_pack_start (GTK_BOX (vbox), logout_dialog->priv->info_label, TRUE, TRUE, 0); gtk_widget_show (logout_dialog->priv->info_label); gtk_window_set_icon_name (GTK_WINDOW (logout_dialog), icon_name); gtk_window_set_title (GTK_WINDOW (logout_dialog), title); gtk_window_set_position (GTK_WINDOW (logout_dialog), GTK_WIN_POS_CENTER_ALWAYS); gtk_dialog_set_default_response (GTK_DIALOG (logout_dialog), logout_dialog->priv->default_response); /* Note that focus is on the widget for the default response by default * (since they're the first widget, except when it's Cancel */ if (logout_dialog->priv->default_response == GTK_RESPONSE_CANCEL) gtk_window_set_focus (GTK_WINDOW (logout_dialog), logout_dialog->priv->cancel_button); gtk_window_set_screen (GTK_WINDOW (logout_dialog), screen); return GTK_WIDGET (logout_dialog); }