summaryrefslogtreecommitdiff
path: root/capplets/appearance/appearance-ui.c
blob: 72fef092ca814d19870ba0da7afb7ba19e65ae0a (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
/*
 * Copyright (C) 2007 The GNOME Foundation
 * Written by Jonathan Blandford <jrb@gnome.org>
 *            Jens Granseuer <jensgr@gmx.net>
 * All Rights Reserved
 *
 * 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, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "appearance.h"
#include "stdio.h"

static void
set_have_icons (AppearanceData *data, gboolean value)
{
    static const char *menu_item_names[] = {
        "menu_item_1",
        "menu_item_2",
        "menu_item_3",
        "menu_item_4",
        "menu_item_5",
        "cut",
        "copy",
        "paste",
        NULL
    };

    const char **name;

    for (name = menu_item_names; *name != NULL; name++) {
        GtkImageMenuItem *item = GTK_IMAGE_MENU_ITEM (appearance_capplet_get_widget (data, *name));
        GtkWidget *image;

        if (value) {
            image = g_object_get_data (G_OBJECT (item), "image");
            if (image) {
                gtk_image_menu_item_set_image (item, image);
                g_object_unref (image);
            }
        }
        else
        {
            image = gtk_image_menu_item_get_image (item);
            g_object_set_data (G_OBJECT (item), "image", image);
            g_object_ref (image);
            gtk_image_menu_item_set_image (item, NULL);
        }
    }
}

static void
menus_have_icons_cb (GSettings *settings,
                     gchar *key,
                     AppearanceData      *data)
{
    set_have_icons (data, g_settings_get_boolean (settings, key));
}

/** GUI Callbacks **/

static gint
button_press_block_cb (GtkWidget *toolbar,
                       GdkEvent  *event,
                       gpointer   data)
{
    return TRUE;
}

/** Public Functions **/

void
ui_init (AppearanceData *data)
{
    GtkWidget* widget;

    /* FIXME maybe just remove that stuff from .ui file */
    GtkWidget* container = appearance_capplet_get_widget(data, "vbox24");

    // Remove menu accels and toolbar style toggles for new GTK versions
    gtk_container_remove((GtkContainer *) container,
                         appearance_capplet_get_widget(data, "menu_accel_toggle"));
    gtk_container_remove((GtkContainer *) container,
                         appearance_capplet_get_widget(data, "hbox11"));

    widget = appearance_capplet_get_widget(data, "menu_icons_toggle");
    g_settings_bind (data->interface_settings,
                     MENU_ICONS_KEY,
                     G_OBJECT (widget),
                     "active",
                     G_SETTINGS_BIND_DEFAULT);
    g_signal_connect (data->interface_settings, "changed::" MENU_ICONS_KEY,
                      G_CALLBACK (menus_have_icons_cb), data);

    set_have_icons (data,
                    g_settings_get_boolean (data->interface_settings,
                                            MENU_ICONS_KEY));

    widget = appearance_capplet_get_widget(data, "button_icons_toggle");
    g_settings_bind (data->interface_settings,
                     BUTTON_ICONS_KEY,
                     G_OBJECT (widget),
                     "active",
                     G_SETTINGS_BIND_DEFAULT);
}