summaryrefslogtreecommitdiffstats
path: root/widgets/src/StandaloneWindow.c
blob: 6ba4031f0abbdc9c9ad9e9d9c4dd304a8d3cc2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Copyright (C) 2011  Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Chris Lumens <clumens@redhat.com>
 */

#include "BaseWindow.h"
#include "StandaloneWindow.h"
#include "intl.h"

/**
 * SECTION: StandaloneWindow
 * @title: AnacondaStandaloneWindow
 * @short_description: Window for displaying standalone spokes
 *
 * A #AnacondaStandaloneWindow is a top-level window that displays a standalone
 * spoke.  A standalone spoke is like a normal spoke, but is not entered via a
 * hub.  Instead, it is displayed by itself.  Examples include the welcome and
 * network configuration screens at the beginning of installation.
 *
 * The window consist of three areas:
 *
 * - A navigation area in the top of the screen, inherited from #AnacondaBaseWindow.
 *
 * - A button box at the bottom of the screen, with Quit and Continue buttons.
 *   The Continue button may not be enabled until required information is
 *   entered by the user.
 *
 * - An action area in the middle of the screen, taking up a majority of the
 *   space.  This is where widgets will be added and the user will do things.
 */

enum {
    SIGNAL_QUIT_CLICKED,
    SIGNAL_CONTINUE_CLICKED,
    LAST_SIGNAL
};

static guint window_signals[LAST_SIGNAL] = { 0 };

struct _AnacondaStandaloneWindowPrivate {
    GtkWidget  *button_box;
    GtkWidget  *continue_button, *quit_button;
};

static void anaconda_standalone_window_quit_clicked(GtkButton *button,
                                                    AnacondaStandaloneWindow *win);
static void anaconda_standalone_window_continue_clicked(GtkButton *button,
                                                        AnacondaStandaloneWindow *win);

G_DEFINE_TYPE(AnacondaStandaloneWindow, anaconda_standalone_window, ANACONDA_TYPE_BASE_WINDOW)

static void anaconda_standalone_window_class_init(AnacondaStandaloneWindowClass *klass) {
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    klass->quit_clicked = NULL;
    klass->continue_clicked = NULL;

    /**
     * AnacondaStandaloneWindow::quit-clicked:
     * @window: the window that received the signal
     *
     * Emitted when the quit button has been activated (pressed and released).
     *
     * Since: 1.0
     */
    window_signals[SIGNAL_QUIT_CLICKED] = g_signal_new("quit-clicked",
                                                       G_TYPE_FROM_CLASS(object_class),
                                                       G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                                                       G_STRUCT_OFFSET(AnacondaStandaloneWindowClass, quit_clicked),
                                                       NULL, NULL,
                                                       g_cclosure_marshal_VOID__VOID,
                                                       G_TYPE_NONE, 0);

    /**
     * AnacondaStandaloneWindow::continue-clicked:
     * @window: the window that received the signal
     *
     * Emitted when the continue button has been activated (pressed and released).
     *
     * Since: 1.0
     */
    window_signals[SIGNAL_CONTINUE_CLICKED] = g_signal_new("continue-clicked",
                                                           G_TYPE_FROM_CLASS(object_class),
                                                           G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                                                           G_STRUCT_OFFSET(AnacondaStandaloneWindowClass, continue_clicked),
                                                           NULL, NULL,
                                                           g_cclosure_marshal_VOID__VOID,
                                                           G_TYPE_NONE, 0);

    g_type_class_add_private(object_class, sizeof(AnacondaStandaloneWindowPrivate));
}

/**
 * anaconda_standalone_window_new:
 *
 * Creates a new #AnacondaStandaloneWindow, which is a window designed for
 * displaying a standalone spoke, such as the welcome screen or network
 * configuration.
 *
 * Returns: A new #AnacondaStandaloneWindow.
 */
GtkWidget *anaconda_standalone_window_new() {
    return g_object_new(ANACONDA_TYPE_STANDALONE_WINDOW, NULL);
}

static void anaconda_standalone_window_init(AnacondaStandaloneWindow *win) {
    /* This is the section of the parent AnacondaBaseWindow class where we
     * put buttons, dialogs, etc.  We need a reference to it here to pac
     * things into.
     */
    GtkWidget *action_area = anaconda_base_window_get_action_area(ANACONDA_BASE_WINDOW(win));

    win->priv = G_TYPE_INSTANCE_GET_PRIVATE(win,
                                            ANACONDA_TYPE_STANDALONE_WINDOW,
                                            AnacondaStandaloneWindowPrivate);

    /* Create the buttons. */
    win->priv->quit_button = gtk_button_new_with_mnemonic(_("_QUIT"));
    win->priv->continue_button = gtk_button_new_with_mnemonic(_("_CONTINUE"));

    /* Hook up some signals for those buttons.  The signal handlers here will
     * just raise our own custom signals for the whole window.
     */
    g_signal_connect(win->priv->quit_button, "clicked",
                     G_CALLBACK(anaconda_standalone_window_quit_clicked), win);
    g_signal_connect(win->priv->continue_button, "clicked",
                     G_CALLBACK(anaconda_standalone_window_continue_clicked), win);

    /* Create the button box and pack the buttons into it. */
    win->priv->button_box = gtk_hbutton_box_new();
    gtk_button_box_set_layout(GTK_BUTTON_BOX(win->priv->button_box), GTK_BUTTONBOX_EDGE);
    gtk_container_add(GTK_CONTAINER(win->priv->button_box), win->priv->quit_button);
    gtk_container_add(GTK_CONTAINER(win->priv->button_box), win->priv->continue_button);

    /* Pack the button box into the action_area. */
    gtk_box_pack_end(GTK_BOX(action_area), win->priv->button_box, FALSE, TRUE, 0);
}

static void anaconda_standalone_window_quit_clicked(GtkButton *button,
                                                    AnacondaStandaloneWindow *win) {
    g_signal_emit(win, window_signals[SIGNAL_QUIT_CLICKED], 0);
}

static void anaconda_standalone_window_continue_clicked(GtkButton *button,
                                                        AnacondaStandaloneWindow *win) {
    g_signal_emit(win, window_signals[SIGNAL_CONTINUE_CLICKED], 0);
}

/**
 * anaconda_standalone_window_get_may_continue:
 * @win: a #AnacondaStandaloneWindow
 *
 * Returns whether or not the continue button is sensitive (thus, whether the
 * user may continue forward from this window).
 *
 * Returns: Whether the continue button on @win is sensitive.
 *
 * Since: 1.0
 */
gboolean anaconda_standalone_window_get_may_continue(AnacondaStandaloneWindow *win) {
    return gtk_widget_get_sensitive(win->priv->continue_button);
}

/**
 * anaconda_standalone_window_set_may_continue:
 * @win: a #AnacondaStandaloneWindow
 * @may_continue: %TRUE if this window's continue button should be sensitive.
 *
 * Specifies whether the user may continue forward from this window.  If so,
 * the continue button will be made sensitive.  Windows default to continuable
 * so you must set it as false if you want.  The reason the user may not be
 * able to continue is if there is required information the user must enter
 * when no reasonable default may be given.
 *
 * Since: 1.0
 */
void anaconda_standalone_window_set_may_continue(AnacondaStandaloneWindow *win,
                                                 gboolean may_continue) {
    gtk_widget_set_sensitive(win->priv->continue_button, may_continue);
}