summaryrefslogtreecommitdiffstats
path: root/src/remmina_sysinfo.c
blob: cfbe1c39093cb9b2f74b43d71cec93ace5fedece (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
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
/*
 * Remmina - The GTK+ Remote Desktop Client
 * Copyright (C) 2010 Vic Lee
 * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
 * Copyright (C) 2016-2023 Antenore Gatta, Giovanni Panozzo
 *
 * 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.
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of portions of this program with the
 *  OpenSSL library under certain conditions as described in each
 *  individual source file, and distribute linked combinations
 *  including the two.
 *  You must obey the GNU General Public License in all respects
 *  for all of the code used other than OpenSSL. *  If you modify
 *  file(s) with this exception, you may extend this exception to your
 *  version of the file(s), but you are not obligated to do so. *  If you
 *  do not wish to do so, delete this exception statement from your
 *  version. *  If you delete this exception statement from all source
 *  files in the program, then also delete it here.
 *
 */

#include "config.h"
#include <glib/gi18n.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include "remmina/remmina_trace_calls.h"
#include "remmina_sysinfo.h"

gboolean remmina_sysinfo_is_appindicator_available()
{
	/* Check if we have an appindicator available (which uses
	 * DBUS KDE StatusNotifier)
	 */

	TRACE_CALL(__func__);
	GDBusConnection *con;
	GVariant *v;
	GError *error;
	gboolean available;

	available = FALSE;
	con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	if (con) {
		error = NULL;
		v = g_dbus_connection_call_sync(con,
			"org.kde.StatusNotifierWatcher",
			"/StatusNotifierWatcher",
			"org.freedesktop.DBus.Introspectable",
			"Introspect",
			NULL,
			NULL,
			G_DBUS_CALL_FLAGS_NONE,
			-1,
			NULL,
			&error);
		if (v) {
			available = TRUE;
			g_variant_unref(v);
		}
		g_object_unref(con);
	}
	return available;
}

/**
 * Query DBUS to get GNOME Shell version.
 * @return the GNOME Shell version as a string or NULL if error or no GNOME Shell found.
 * @warning The returned string must be freed with g_free.
 */
gchar *remmina_sysinfo_get_gnome_shell_version()
{
	TRACE_CALL(__func__);
	GDBusConnection *con;
	GDBusProxy *p;
	GVariant *v;
	GError *error;
	gsize sz;
	gchar *ret;

	ret = NULL;

	con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	if (con) {
		error = NULL;
		p = g_dbus_proxy_new_sync(con,
			G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
			NULL,
			"org.gnome.Shell",
			"/org/gnome/Shell",
			"org.gnome.Shell",
			NULL,
			&error);
		if (p) {
			v = g_dbus_proxy_get_cached_property(p, "ShellVersion");
			if (v) {
				if (g_variant_is_of_type(v, G_VARIANT_TYPE_STRING)) {
					ret = g_strdup(g_variant_get_string(v, &sz));
				}
				g_variant_unref(v);
			}
			g_object_unref(p);
		}
		g_object_unref(con);
	}
	return ret;
}

/**
 * Query environment variables to get the Window manager name.
 * @return a string composed by XDG_CURRENT_DESKTOP and GDMSESSION as a string
 * or \0 if nothing has been found.
 * @warning The returned string must be freed with g_free.
 */
gchar *remmina_sysinfo_get_wm_name()
{
	TRACE_CALL(__func__);
	const gchar *xdg_current_desktop;
	const gchar *gdmsession;
	gchar *ret;

	xdg_current_desktop = g_environ_getenv(g_get_environ(), "XDG_CURRENT_DESKTOP");
	gdmsession = g_environ_getenv(g_get_environ(), "GDMSESSION");

	if (!xdg_current_desktop || xdg_current_desktop[0] == '\0') {
		if (!gdmsession || gdmsession[0] == '\0') {
			ret = NULL;
		}else {
			ret = g_strdup_printf("%s", gdmsession);
		}
	}else if (!gdmsession || gdmsession[0] == '\0') {
		ret = g_strdup_printf("%s", xdg_current_desktop);
		return ret;
	}else if (g_strcmp0(xdg_current_desktop,gdmsession) == 0) {
		ret = g_strdup_printf("%s", xdg_current_desktop);
	}else {
		ret = g_strdup_printf("%s %s", xdg_current_desktop, gdmsession);
	}
	return ret;
}