3 * A file-manager extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 * FileManager-Actions is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * FileManager-Actions is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FileManager-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
34 #include <glib/gi18n.h>
36 #include "fma-desktop-environment.h"
38 static const FMADesktopEnv st_desktops
[] = {
39 { DESKTOP_GNOME
, N_( "GNOME desktop" ) },
40 { DESKTOP_KDE
, N_( "KDE desktop" ) },
41 { DESKTOP_LXDE
, N_( "LXDE desktop" ) },
42 { DESKTOP_ROX
, N_( "ROX desktop" ) },
43 { DESKTOP_XFCE
, N_( "XFCE desktop" ) },
44 { DESKTOP_OLD
, N_( "Legacy systems" ) },
49 * fma_desktop_environment_get_known_list:
51 * Returns the list of known desktop environments as defined by the
52 * corresponding XDG specification.
55 fma_desktop_environment_get_known_list( void )
57 return(( const FMADesktopEnv
* ) st_desktops
);
61 * fma_desktop_environment_detect_running_desktop:
63 * Have asked on xdg-list how to identify the currently running desktop environment
64 * (see http://standards.freedesktop.org/menu-spec/latest/apb.html)
65 * For now, just reproduce the xdg-open algorythm from xdg-utils 1.0
68 fma_desktop_environment_detect_running_desktop( void )
70 static const gchar
*thisfn
= "fma_desktop_environment_detect_running_desktop";
72 gchar
*output_str
, *error_str
;
78 value
= g_getenv( "XDG_CURRENT_DESKTOP" );
79 if( value
&& strlen( value
)){
80 for( i
= 0 ; st_desktops
[i
].id
; ++i
){
81 if( !strcmp( st_desktops
[i
].id
, value
)){
82 return( st_desktops
[i
].id
);
87 value
= g_getenv( "KDE_FULL_SESSION" );
88 if( value
&& !strcmp( value
, "true" )){
89 return( DESKTOP_KDE
);
92 /* GNOME_DESKTOP_SESSION_ID=this-is-deprecated
94 value
= g_getenv( "GNOME_DESKTOP_SESSION_ID" );
95 if( value
&& strlen( value
)){
96 return( DESKTOP_GNOME
);
99 value
= g_getenv( "DESKTOP_SESSION" );
101 if( !strcmp( value
, "gnome" )){
102 return( DESKTOP_GNOME
);
104 if( !strcmp( value
, "xfce" )){
105 return( DESKTOP_XFCE
);
112 if( g_spawn_command_line_sync(
113 "dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager",
114 &output_str
, &error_str
, &exit_status
, &error
)){
115 ok
= ( exit_status
== 0 && output_str
&& strlen( output_str
) && ( !error_str
|| !strlen( error_str
)));
116 g_free( output_str
);
119 return( DESKTOP_GNOME
);
123 g_warning( "%s: dbus-send: %s", thisfn
, error
->message
);
124 g_error_free( error
);
130 if( g_spawn_command_line_sync(
131 "xprop -root _DT_SAVE_MODE", &output_str
, &error_str
, &exit_status
, &error
)){
132 ok
= ( exit_status
== 0 && output_str
&& strlen( output_str
) && ( !error_str
|| !strlen( error_str
)));
134 ok
= ( g_strstr_len( output_str
, -1, "xfce" ) != NULL
);
136 g_free( output_str
);
139 return( DESKTOP_XFCE
);
143 g_warning( "%s: xprop: %s", thisfn
, error
->message
);
144 g_error_free( error
);
147 /* do not know how to identify ROX
148 * this one and other desktops are just identified as 'Old' (legacy systems)
150 return( DESKTOP_OLD
);
154 * fma_desktop_environment_get_label:
155 * @id: desktop identifier.
157 * Returns: the label of the desktop environment.
159 * Defaults to returning the provided identifier if it is not found in
160 * our internal reference.
165 fma_desktop_environment_get_label( const gchar
*id
)
167 static const gchar
*thisfn
= "fma_desktop_environment_get_label";
170 g_return_val_if_fail( id
&& strlen( id
), NULL
);
172 for( i
= 0 ; st_desktops
[i
].id
; ++ i
){
173 if( !strcmp( st_desktops
[i
].id
, id
)){
174 return( st_desktops
[i
].label
);
178 g_warning( "%s: unknwon desktop identifier: %s", thisfn
, id
);