source: ldm/trunk/fuentes/gtkgreet/prefwin.c @ 855

Last change on this file since 855 was 855, checked in by mabarracus, 5 years ago
  • Updated sources to 2.2.18
  • Ported code from patches to apply in 2.2.18
File size: 4.2 KB
Line 
1/*
2 * LTSP Graphical GTK Greeter
3 * Copyright (C) 2010 Simon Poirier, <simon.poirier@revolutionlinux.com>
4 *
5 * - Queries servers to get information about them
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <glib/gi18n.h>
23#include <glib.h>
24#include <gtk/gtk.h>
25
26#include "prefs.h"
27#include "../src/ldminfo.h"
28#include "greeter.h"
29
30static GtkWidget *pref_combo = NULL;
31static gint choice_total = 0;
32
33extern GIOChannel *g_stdout;
34
35typedef struct {
36    GtkWidget *prefwin;
37    const gchar *prefname;
38} PrefData;
39
40/*
41 * Local functions
42 */
43
44static void
45prefwin_accept(GtkWidget * widget, PrefData * data)
46{
47    GreeterPref *pref = greeter_pref_get_pref(data->prefname);
48    gchar *notif;
49
50    pref->value.int_val =
51        gtk_combo_box_get_active(GTK_COMBO_BOX(pref_combo));
52    gtk_widget_destroy(data->prefwin);
53
54    notif = g_strconcat("@", data->prefname, "@\n", NULL);
55    g_io_channel_write_chars(g_stdout, notif, -1, NULL, NULL);
56    g_io_channel_flush(g_stdout, NULL);
57    g_free(notif);
58
59    g_free(data);
60}
61
62/*
63 * External functions
64 */
65
66void
67populate_pref_combo_box(const char *choice, GtkWidget * pref_combo_box)
68{
69    gtk_combo_box_append_text(GTK_COMBO_BOX(pref_combo_box),
70                              g_strdup(choice));
71    ++choice_total;
72}
73
74void
75prefwin(GtkWidget * widget, gpointer pref_name)
76{
77
78    GreeterPref *pref;
79    GtkWidget *prefwin, *label, *vbox, *buttonbox;
80    GtkWidget *cancel, *accept, *frame;
81
82    pref_combo = gtk_combo_box_new_text();
83    pref = greeter_pref_get_pref(pref_name);
84
85    /*
86     * Populate lang with default host hash
87     */
88
89    gtk_combo_box_append_text(GTK_COMBO_BOX(pref_combo),
90                              g_strdup(_("Default")));
91    g_list_foreach(pref->choices,
92                   (GFunc) populate_pref_combo_box, pref_combo);
93
94    gtk_combo_box_set_active(GTK_COMBO_BOX(pref_combo),
95                             pref->value.int_val);
96
97    /*
98     * Build window
99     */
100
101    prefwin = gtk_window_new(GTK_WINDOW_POPUP);
102    gtk_window_set_position((GtkWindow *) prefwin,
103                            GTK_WIN_POS_CENTER_ALWAYS);
104    gtk_window_set_modal((GtkWindow *) prefwin, TRUE);
105
106    vbox = gtk_vbox_new(FALSE, 0);
107    buttonbox = gtk_hbox_new(FALSE, 5);
108    gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
109
110    cancel = gtk_button_new_from_stock("gtk-cancel");
111    g_signal_connect(G_OBJECT(cancel), "clicked",
112                     G_CALLBACK(destroy_popup), prefwin);
113
114    accept = gtk_button_new_from_stock("gtk-ok");
115    PrefData *data = g_malloc0(sizeof(PrefData));
116    data->prefwin = prefwin;
117    data->prefname = pref_name;
118    g_signal_connect(G_OBJECT(accept), "clicked",
119                     G_CALLBACK(prefwin_accept), data);
120
121    gtk_box_pack_end((GtkBox *) buttonbox, (GtkWidget *) accept, FALSE,
122                     FALSE, 0);
123    gtk_box_pack_end((GtkBox *) buttonbox, (GtkWidget *) cancel, FALSE,
124                     FALSE, 0);
125
126    label = gtk_label_new("");
127    gtk_label_set_markup((GtkLabel *) label, _(pref->title));
128
129    gtk_box_pack_start((GtkBox *) vbox, (GtkWidget *) label, FALSE, FALSE,
130                       0);
131    gtk_box_pack_start((GtkBox *) vbox, (GtkWidget *) pref_combo, FALSE,
132                       FALSE, 5);
133    gtk_box_pack_start((GtkBox *) vbox, (GtkWidget *) buttonbox, TRUE,
134                       TRUE, 5);
135
136    frame = gtk_frame_new("");
137    gtk_frame_set_shadow_type((GtkFrame *) frame, GTK_SHADOW_OUT);
138    gtk_frame_set_label_align((GtkFrame *) frame, 1.0, 0.0);
139
140    gtk_container_add(GTK_CONTAINER(frame), vbox);
141    gtk_container_add(GTK_CONTAINER(prefwin), frame);
142
143    gtk_widget_show_all(prefwin);
144
145    return;
146}
Note: See TracBrowser for help on using the repository browser.