2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Rémy Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
26
Fabrice Rey <fabounet@users.berlios.de>
28
******************************************************************************/
34
#include <glib/gi18n.h>
35
#include <glib/gstdio.h>
37
#include "applet-struct.h"
38
#include "applet-notifications.h"
39
#include "applet-draw.h"
40
#include "applet-nvidia.h"
43
static char *s_cTmpFileConfig = NULL;
44
static char *s_cTmpFile = NULL;
47
//Récupération de la température
48
void cd_nvidia_acquisition (void) {
49
s_cTmpFile = g_strdup ("/tmp/nvidia.XXXXXX");
50
int fds =mkstemp (s_cTmpFile);
56
gchar *cCommand = g_strdup_printf ("bash %s/nvidia %s", MY_APPLET_SHARE_DATA_DIR, s_cTmpFile);
62
void cd_nvidia_read_data (void) {
63
cd_nvidia_acquisition ();
64
if (s_cTmpFile == NULL)
66
gchar *cContent = NULL;
68
GError *erreur = NULL;
70
g_file_get_contents(s_cTmpFile, &cContent, &length, &erreur);
72
cd_warning("nVidia : %s", erreur->message);
75
myData.bAcquisitionOK = FALSE;
78
iGpuTemp = atoi (cContent);
80
cd_warning("nVidia : couldn't acquire GPU temperature\n is 'nvidia-settings' installed on your system and its version >= 1.0 ?");
81
myData.bAcquisitionOK = FALSE;
84
myData.bAcquisitionOK = TRUE;
85
myData.pGPUData.iGPUTemp = iGpuTemp;
88
g_remove (s_cTmpFile);
93
gboolean cd_nvidia_update_from_data (void) {
94
if (myData.bAcquisitionOK) {
95
cd_nvidia_draw_icon ();
99
cd_nvidia_draw_no_data ();
100
cd_warning ("Couldn't get infos from nvidia setting (may not be installed or too old), halt.");
101
return FALSE; // pas la peine d'insister.
108
//Récupération de la config
109
void cd_nvidia_config_acquisition (void) {
110
s_cTmpFileConfig = g_strdup ("/tmp/nvidia-config.XXXXXX");
111
int fds =mkstemp (s_cTmpFileConfig);
113
g_free (s_cTmpFileConfig);
114
s_cTmpFileConfig = NULL;
117
gchar *cCommand = g_strdup_printf ("bash %s/nvidia-config %s", MY_APPLET_SHARE_DATA_DIR, s_cTmpFileConfig);
123
static gboolean _nvidia_get_values_from_file (gchar *cContent) {
124
cd_nvidia_config_acquisition ();
125
gchar **cInfopipesList = g_strsplit (cContent, "\n", -1);
128
//g_print ("%s ()\n", __func__);
130
g_free (myData.pGPUData.cGPUName);
131
myData.pGPUData.cGPUName = NULL;
132
g_free (myData.pGPUData.cDriverVersion);
133
myData.pGPUData.cDriverVersion = NULL;
135
for (i = 0; cInfopipesList[i] != NULL; i ++) {
136
cOneInfopipe = cInfopipesList[i];
137
if (*cOneInfopipe == '\0')
140
if ((i == 0) && (strcmp (cOneInfopipe,"nvidia") == 0)) {
141
g_strfreev (cInfopipesList);
146
gchar *str = g_strstr_len (cOneInfopipe, strlen (cOneInfopipe), "version");
151
gchar *str2 = strchr (str, ' ');
154
int iMajorVersion=0, iMinorVersion=0, iMicroVersion=0;
155
cairo_dock_get_version_from_string (str, &iMajorVersion, &iMinorVersion, &iMicroVersion);
156
/*if (iMajorVersion == 0 || (iMajorVersion == 1 && iMinorVersion < 0)) { /// A confirmer ...
157
myData.bSettingsTooOld == TRUE;
158
cd_warning ("Attention : your nvidia-settings's version is too old (%d.%d.%d)", iMajorVersion, iMinorVersion, iMicroVersion);
163
else if (i == 1) { //GPU Name
164
myData.pGPUData.cGPUName = g_strdup (cOneInfopipe);
165
gchar *str = strchr (myData.pGPUData.cGPUName, ')');
169
else if (i == 2) { //Video Ram
170
myData.pGPUData.iVideoRam = atoi (cOneInfopipe);
171
myData.pGPUData.iVideoRam = myData.pGPUData.iVideoRam >> 10; // passage en Mo.
173
else if (i == 3) { //Driver Version
174
myData.pGPUData.cDriverVersion = g_strdup (cOneInfopipe);
179
cd_debug ("nVidia %s %dMB %sV %d°C", myData.pGPUData.cGPUName, myData.pGPUData.iVideoRam, myData.pGPUData.cDriverVersion, myData.pGPUData.iGPUTemp);
181
g_strfreev (cInfopipesList);
185
void cd_nvidia_config_read_data (void) {
186
//g_print ("%s ()\n", __func__);
187
if (s_cTmpFileConfig == NULL)
189
gchar *cContent = NULL;
191
GError *erreur = NULL;
192
g_file_get_contents(s_cTmpFileConfig, &cContent, &length, &erreur);
193
if (erreur != NULL) {
194
cd_warning("nVidia : %s", erreur->message);
195
g_error_free(erreur);
197
myData.bAcquisitionOK = FALSE;
200
gboolean bAcquisitionOK = _nvidia_get_values_from_file (cContent);
203
g_remove (s_cTmpFileConfig);
204
g_free (s_cTmpFileConfig);
205
s_cTmpFileConfig = NULL;
208
gboolean cd_nvidia_config_update_from_data (void) {
209
//g_print ("%s ()\n", __func__);
210
if (myConfig.bCardName) {
211
CD_APPLET_SET_NAME_FOR_MY_ICON (myData.pGPUData.cGPUName);