~ubuntu-branches/ubuntu/utopic/xfdesktop4/utopic

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
195
196
197
198
199
/*
 *  xfdesktop - xfce4's desktop manager
 *
 *  Copyright (c) 2004-2008 Brian J. Tarricone <bjt23@cornell.edu>
 *
 *  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 Library 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
 *
 *  Random portions taken from or inspired by the original xfdesktop for xfce4:
 *     Copyright (C) 2002-2003 Jasper Huijsmans (huysmans@users.sourceforge.net)
 *     Copyright (C) 2003 Benedikt Meurer <benedikt.meurer@unix-ag.uni-siegen.de>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include <glib.h>
#include <gtk/gtk.h>

#include <libxfce4util/libxfce4util.h>

#include "menu.h"
#ifdef USE_DESKTOP_MENU
#include "xfce-desktop-menu.h"
#endif

#ifdef USE_DESKTOP_MENU
static XfceDesktopMenu *desktop_menu = NULL;
static gboolean show_desktop_menu_icons = TRUE;
#endif

#ifdef USE_DESKTOP_MENU
static void
_stop_menu_module(void) {
    if(desktop_menu) {
        xfce_desktop_menu_destroy(desktop_menu);
        desktop_menu = NULL;
    }
}

static gboolean
_start_menu_module(void)
{
    desktop_menu = xfce_desktop_menu_new(TRUE);
    if(desktop_menu) {
        xfce_desktop_menu_set_show_icons(desktop_menu, show_desktop_menu_icons);
        return TRUE;
    } else {
        g_warning("%s: Unable to initialise menu module. Right-click menu will be unavailable.\n", PACKAGE);
        return FALSE;
    }
}
#endif

#ifdef USE_DESKTOP_MENU
static void
menu_populate(XfceDesktop *desktop,
              GtkMenuShell *menu,
              gpointer user_data)
{
    GtkWidget *desktop_menu_widget;
    GList *menu_children;
    
    TRACE("ENTERING");
    
    if(!desktop_menu)
        return;
    
    /* check to see if the menu is empty.  if not, add the desktop menu
     * to a submenu */
    menu_children = gtk_container_get_children(GTK_CONTAINER(menu));
    if(menu_children) {
        g_list_free(menu_children);
        
        desktop_menu_widget = xfce_desktop_menu_get_widget(desktop_menu);
        if(desktop_menu_widget) {
            GtkWidget *mi, *img = NULL;
            GtkIconTheme *itheme = gtk_icon_theme_get_default();
            
            mi = gtk_separator_menu_item_new();
            gtk_widget_show(mi);
            gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
            
            if(gtk_icon_theme_has_icon(itheme, "applications-other")) {
                img = gtk_image_new_from_icon_name("applications-other",
                                                   GTK_ICON_SIZE_MENU);
                gtk_widget_show(img);
            }
            
            mi = gtk_image_menu_item_new_with_mnemonic(_("_Applications"));
            gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
            gtk_widget_show(mi);
            gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
            
            gtk_menu_item_set_submenu(GTK_MENU_ITEM(mi), desktop_menu_widget);
        }
    } else {
        /* just get the menu as a list of toplevel GtkMenuItems instead of
         * a toplevel menu */
        xfce_desktop_menu_populate_menu(desktop_menu, GTK_WIDGET(menu));
    }
}
#endif /* USE_DESKTOP_MENU */

#ifdef USE_DESKTOP_MENU
static void
menu_settings_changed(XfconfChannel *channel,
                      const gchar *property,
                      const GValue *value,
                      gpointer user_data)
{
    if(!strcmp(property, "/desktop-menu/show")) {
        if(!G_VALUE_TYPE(value) || g_value_get_boolean(value)) {
            if(!desktop_menu) {
                _start_menu_module();
                if(desktop_menu && !show_desktop_menu_icons)
                    xfce_desktop_menu_set_show_icons(desktop_menu, FALSE);
            }
        } else {
            if(desktop_menu)
                _stop_menu_module();
        }
    } else if(!strcmp(property, "/desktop-menu/show-icons")) {
        show_desktop_menu_icons = G_VALUE_TYPE(value)
                                  ? g_value_get_boolean(value)
                                  : TRUE;
        if(desktop_menu) {
            xfce_desktop_menu_set_show_icons(desktop_menu,
                                             show_desktop_menu_icons);
        }
    }
}
#endif

void
menu_init(XfconfChannel *channel)
{    
#ifdef USE_DESKTOP_MENU
    if(!channel
       || xfconf_channel_get_bool(channel, "/desktop-menu/show", TRUE))
    {
        if(channel) {
            show_desktop_menu_icons = xfconf_channel_get_bool(channel,
                                                              "/desktop-menu/show-icons",
                                                              TRUE);
        }
        _start_menu_module();
    } else
        _stop_menu_module();

    if(channel) {
        g_signal_connect(G_OBJECT(channel), "property-changed",
                         G_CALLBACK(menu_settings_changed), NULL);
    }
#endif
}

void
menu_attach(XfceDesktop *desktop)
{
#ifdef USE_DESKTOP_MENU
    DBG("attached default menu");
    g_signal_connect_after(G_OBJECT(desktop), "populate-root-menu",
                           G_CALLBACK(menu_populate), NULL);
#endif /* USE_DESKTOP_MENU */
}

void
menu_reload(void)
{
#ifdef USE_DESKTOP_MENU
    if(desktop_menu)
        xfce_desktop_menu_force_regen(desktop_menu);
#endif
}

void
menu_cleanup(void)
{
#ifdef USE_DESKTOP_MENU
    _stop_menu_module();
#endif
}