From b2d32a349c6078a273d8db8a037741253cc800a9 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 29 Jul 2012 18:38:23 +0200 Subject: [PATCH] Factor out dialog creation for getting input --- src/lib-display-blanking-status-menu-widget.c | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/lib-display-blanking-status-menu-widget.c b/src/lib-display-blanking-status-menu-widget.c index 3b83795..2daaff6 100644 --- a/src/lib-display-blanking-status-menu-widget.c +++ b/src/lib-display-blanking-status-menu-widget.c @@ -163,14 +163,9 @@ on_mode_dialog_button_clicked (GtkWidget *button, GtkDialog *dialog) gtk_dialog_response (dialog, GTK_RESPONSE_OK); } -static void -on_mode_button_clicked (GtkWidget *button, - DisplayBlankingStatusPluginPrivate *priv) +static gint +mode_get_input (DisplayBlankingStatusPluginPrivate *priv) { - GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button), - GTK_TYPE_WINDOW); - gtk_widget_hide (parent); - g_assert (priv->mode_dialog == NULL); priv->mode_dialog = gtk_dialog_new (); gtk_window_set_modal (GTK_WINDOW (priv->mode_dialog), TRUE); @@ -209,20 +204,32 @@ on_mode_button_clicked (GtkWidget *button, G_CALLBACK (on_mode_dialog_button_clicked), priv->mode_dialog); } - gtk_widget_show_all (priv->mode_dialog); - g_object_set_data (G_OBJECT (priv->mode_dialog), "mode", &mode); + gtk_widget_show_all (priv->mode_dialog); gtk_dialog_run (GTK_DIALOG (priv->mode_dialog)); + gtk_widget_destroy (priv->mode_dialog); + priv->mode_dialog = NULL; + + return mode; +} + +static void +on_mode_button_clicked (GtkWidget *button, + DisplayBlankingStatusPluginPrivate *priv) +{ + GtkWidget *parent = gtk_widget_get_ancestor (GTK_WIDGET (priv->mode_button), + GTK_TYPE_WINDOW); + gtk_widget_hide (parent); + + gint mode = mode_get_input (priv); + if (mode != BLANKING_MODES) { // will trigger the gconf notify signal GError *error = NULL; gconf_client_set_int (priv->gconf_client, MODE_GCONF_KEY, mode, &error); g_assert (error == NULL); } - - gtk_widget_destroy (priv->mode_dialog); - priv->mode_dialog = NULL; } static void -- 2.43.0