1/*
2 * Color lines for GNOME
3 * Copyright © 1999 Free Software Foundation
4 * Authors: Robert Szokovacs <szo@appaloosacorp.hu>
5 *          Szabolcs Ban <shooby@gnome.hu>
6 *          Karuna Grewal <karunagrewal98@gmail.com>
7 *          Ruxandra Simion <ruxandra.simion93@gmail.com>
8 * Copyright © 2007 Christian Persch
9 *
10 * This game is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
22 */
23
24[GtkTemplate (ui = "/org/gnome/five-or-more/ui/preferences-dialog.ui")]
25public class PreferencesDialog : Gtk.Dialog
26{
27    private Settings settings;
28
29    [GtkChild]
30    private Gtk.ComboBoxText theme_box;
31
32    [GtkChild]
33    private Gtk.ColorButton color_button;
34
35    private void theme_set_cb (Gtk.ComboBox self)
36    {
37        var combo_box_text = self as Gtk.ComboBoxText;
38        var theme = combo_box_text.get_active_id ();
39        foreach (var t in ThemeRenderer.themes)
40        {
41            if (t.split (".")[0] == theme)
42            {
43                if (!settings.set_string ("ball-theme", t))
44                    warning ("Failed to set theme: %s", t);
45
46                return;
47            }
48        }
49    }
50
51    private void color_set_cb (Gtk.ColorButton self)
52    {
53        var color = self.get_rgba ();
54        if (!settings.set_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR, color.to_string ()))
55            warning ("Failed to set color: %s", color.to_string ());
56    }
57
58    public PreferencesDialog (Settings settings)
59    {
60        this.settings = settings;
61
62         /* Set up theme */
63        string theme = settings.get_string (FiveOrMoreApp.KEY_THEME);
64        for (int id = 0; id < ThemeRenderer.themes.length; id++)
65        {
66            if (ThemeRenderer.themes[id] == theme)
67                theme_box.set_active (id);
68        }
69        theme_box.changed.connect (theme_set_cb);
70
71        /* Set up board color */
72        var color_str = settings.get_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR);
73        Gdk.RGBA color = Gdk.RGBA ();
74        color.parse (color_str);
75        color_button.set_rgba (color);
76        color_button.color_set.connect (color_set_cb);
77
78    }
79}
80