README: add deprecation notice
[nautilus-actions.git] / src / core / fma-desktop-environment.c
blobaf52f73e6e80914b2ce6dcb4eec9cf554aca982b
1 /*
2 * FileManager-Actions
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/>.
23 * Authors:
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)
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
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" ) },
45 { NULL }
49 * fma_desktop_environment_get_known_list:
51 * Returns the list of known desktop environments as defined by the
52 * corresponding XDG specification.
54 const FMADesktopEnv *
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
67 const gchar *
68 fma_desktop_environment_detect_running_desktop( void )
70 static const gchar *thisfn = "fma_desktop_environment_detect_running_desktop";
71 const gchar *value;
72 gchar *output_str, *error_str;
73 gint exit_status;
74 GError *error;
75 gboolean ok;
76 int i;
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" );
100 if( value ){
101 if( !strcmp( value, "gnome" )){
102 return( DESKTOP_GNOME );
104 if( !strcmp( value, "xfce" )){
105 return( DESKTOP_XFCE );
109 output_str = NULL;
110 error_str = NULL;
111 error = NULL;
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 );
117 g_free( error_str );
118 if( ok ){
119 return( DESKTOP_GNOME );
122 if( error ){
123 g_warning( "%s: dbus-send: %s", thisfn, error->message );
124 g_error_free( error );
127 output_str = NULL;
128 error_str = NULL;
129 error = NULL;
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 )));
133 if( ok ){
134 ok = ( g_strstr_len( output_str, -1, "xfce" ) != NULL );
136 g_free( output_str );
137 g_free( error_str );
138 if( ok ){
139 return( DESKTOP_XFCE );
142 if( error ){
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.
162 * Since: 3.2
164 const gchar *
165 fma_desktop_environment_get_label( const gchar *id )
167 static const gchar *thisfn = "fma_desktop_environment_get_label";
168 int i;
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 );
180 return( id );