~cairo-dock-team/cairo-dock-plug-ins/experimental

« back to all changes in this revision

Viewing changes to Doncky/src/applet-monitor.c

  • Committer: nochka85
  • Date: 2010-01-31 14:38:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1490.
  • Revision ID: nochka85@nochka85-desktop-20100131143819-j6nno0cl7yxssexq
Doncky - 1st release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
 
 
21
#include <stdlib.h>
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
 
 
25
#include <fcntl.h>
 
26
#include <unistd.h>
 
27
 
 
28
#include "applet-struct.h"
 
29
#include "applet-notifications.h"
 
30
#include "applet-cpusage.h"
 
31
#include "applet-rame.h"
 
32
#include "applet-nvidia.h"
 
33
#include "applet-monitor.h"
 
34
 
 
35
 
 
36
void cd_sysmonitor_get_data (CairoDockModuleInstance *myApplet)
 
37
{
 
38
        myData.bNeedsUpdate = FALSE;
 
39
        
 
40
        if (myConfig.bShowCpu)
 
41
        {
 
42
                cd_sysmonitor_get_cpu_data (myApplet);
 
43
        }
 
44
        if (myConfig.bShowRam || myConfig.bShowSwap)
 
45
        {
 
46
                cd_sysmonitor_get_ram_data (myApplet);
 
47
        }
 
48
        if (myConfig.bShowNvidia)
 
49
        {
 
50
                if ((myData.iTimerCount % 3) == 0)  // la temperature ne varie pas tres vite et le script nvidia-settings est lours, on decide donc de ne mettre a jour qu'une fois sur 3.
 
51
                        cd_sysmonitor_get_nvidia_data (myApplet);
 
52
        }
 
53
        
 
54
        if (! myData.bInitialized)
 
55
        {
 
56
                cd_sysmonitor_get_cpu_info (myApplet);
 
57
                myData.bInitialized = TRUE;
 
58
        }
 
59
        myData.iTimerCount ++;
 
60
}
 
61
 
 
62
 
 
63
gboolean cd_sysmonitor_update_from_data (CairoDockModuleInstance *myApplet)
 
64
{
 
65
        static double s_fValues[CD_SYSMONITOR_NB_MAX_VALUES];
 
66
        CD_APPLET_ENTER;
 
67
        
 
68
        if ( ! myData.bAcquisitionOK)
 
69
        {
 
70
                cd_warning ("One or more datas couldn't be retrieved");
 
71
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("N/A");  // plus discret qu'une bulle de dialogue.
 
72
                if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL)
 
73
                        CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
 
74
                memset (s_fValues, 0, sizeof (s_fValues));
 
75
                CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
 
76
        }
 
77
        else
 
78
        {
 
79
                if (! myData.bInitialized)
 
80
                {
 
81
                        if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON)
 
82
                                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (myDock ? "..." : D_("Loading"));
 
83
                        memset (s_fValues, 0, sizeof (s_fValues));
 
84
                        CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
 
85
                }
 
86
                else
 
87
                {
 
88
                        // Copier les donnes en memoire partagee...
 
89
                        
 
90
                        if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON || (myDock && myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL))  // on affiche les valeurs soit en info-rapide, soit sur l'etiquette en mode dock.
 
91
                        {
 
92
                                gboolean bOneLine = (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL);
 
93
                                GString *sInfo = g_string_new ("");
 
94
                                if (myConfig.bShowCpu)
 
95
                                {
 
96
                                        g_string_printf (sInfo, (myData.fCpuPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
 
97
                                                (myDesklet ? "CPU:" : ""),
 
98
                                                myData.fCpuPercent,
 
99
                                                (bOneLine ? " - " : "\n"));
 
100
                                }
 
101
                                if (myConfig.bShowRam)
 
102
                                {
 
103
                                        g_string_append_printf (sInfo, (myData.fRamPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
 
104
                                                (myDesklet ? "RAM:" : ""),
 
105
                                                myData.fRamPercent,
 
106
                                                (bOneLine ? " - " : "\n"));
 
107
                                }
 
108
                                if (myConfig.bShowSwap)
 
109
                                {
 
110
                                        g_string_append_printf (sInfo, (myData.fSwapPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
 
111
                                                (myDesklet ? "SWAP:" : ""),
 
112
                                                myData.fSwapPercent,
 
113
                                                (bOneLine ? " - " : "\n"));
 
114
                                }
 
115
                                if (myConfig.bShowNvidia)
 
116
                                {
 
117
                                        g_string_append_printf (sInfo, "%s%d°C%s",
 
118
                                                (myDesklet ? "GPU:" : ""),
 
119
                                                myData.iGPUTemp,
 
120
                                                (bOneLine ? " - " : "\n"));
 
121
                                }
 
122
                                sInfo->str[sInfo->len-(bOneLine?3:1)] = '\0';
 
123
                                if (bOneLine)
 
124
                                        CD_APPLET_SET_NAME_FOR_MY_ICON (sInfo->str);
 
125
                                else
 
126
                                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (sInfo->str);
 
127
                                g_string_free (sInfo, TRUE);
 
128
                        }
 
129
                        
 
130
                        if (myData.bNeedsUpdate || myConfig.iDisplayType == CD_SYSMONITOR_GRAPH)
 
131
                        {
 
132
                                int i = 0;
 
133
                                if (myConfig.bShowCpu)
 
134
                                {
 
135
                                        s_fValues[i++] = myData.fCpuPercent / 100.;
 
136
                                }
 
137
                                if (myConfig.bShowRam)
 
138
                                {
 
139
                                        s_fValues[i++] = myData.fRamPercent / 100.;
 
140
                                }
 
141
                                if (myConfig.bShowSwap)
 
142
                                {
 
143
                                        s_fValues[i++] = (myData.swapTotal ? (myConfig.bShowFreeMemory ? (double)myData.swapFree : (double)myData.swapUsed) / myData.swapTotal : 0.);
 
144
                                }
 
145
                                if (myConfig.bShowNvidia)
 
146
                                {
 
147
                                        s_fValues[i++] = myData.fGpuTempPercent / 100.;
 
148
                                        if (myData.bAlerted && myData.iGPUTemp < myConfig.iAlertLimit)
 
149
                                                myData.bAlerted = FALSE; //On reinitialise l'alerte quand la temperature descend en dessou de la limite.
 
150
                                        
 
151
                                        if (!myData.bAlerted && myData.iGPUTemp >= myConfig.iAlertLimit)
 
152
                                                cd_nvidia_alert (myApplet);
 
153
                                }
 
154
                                CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
 
155
                        }
 
156
                }
 
157
        }
 
158
        
 
159
        CD_APPLET_LEAVE (myData.bAcquisitionOK);
 
160
        //return myData.bAcquisitionOK;
 
161
}
 
162
 
 
163
 
 
164
void cd_sysmonitor_format_value (double fValue, int iNumValue, gchar *cFormatBuffer, int iBufferLength, CairoDockModuleInstance *myApplet)
 
165
{
 
166
        int i = -1;
 
167
        if (myConfig.bShowCpu)
 
168
        {
 
169
                i ++;
 
170
                if (i == iNumValue)  // c'est celle-la qu'on veut afficher.
 
171
                {
 
172
                        snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
 
173
                        return ;
 
174
                }
 
175
        }
 
176
        if (myConfig.bShowRam)
 
177
        {
 
178
                i ++;
 
179
                if (i == iNumValue)
 
180
                {
 
181
                        snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
 
182
                        return ;
 
183
                }
 
184
        }
 
185
        if (myConfig.bShowSwap)
 
186
        {
 
187
                i ++;
 
188
                if (i == iNumValue)
 
189
                {
 
190
                        snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f%%" : (fValue < 1 ? " %.0f%%" : "%.0f%%"), fValue * 100.);
 
191
                        return ;
 
192
                }
 
193
        }
 
194
        if (myConfig.bShowNvidia)
 
195
        {
 
196
                i ++;
 
197
                if (i == iNumValue)
 
198
                {
 
199
                        double fTemp = myConfig.iLowerLimit + fValue * (myConfig.iUpperLimit - myConfig.iLowerLimit);
 
200
                        snprintf (cFormatBuffer, iBufferLength, fTemp < 100. ? " %.0f�" : "%.0f�", fTemp);
 
201
                        return ;
 
202
                }
 
203
        }
 
204
        snprintf (cFormatBuffer, iBufferLength, fValue < .0995 ? "%.1f" : (fValue < 1 ? " %.0f" : "%.0f"), fValue * 100.);
 
205
}