~cairo-dock-team/ubuntu/precise/cairo-dock-plug-ins/984054

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-10 00:05:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810000557-pfxoz5w7hbyclcqh
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614625)
* Fixed a few bugs on LP:
 - LP: #483963: Dustbin applet does not display trashes on all volumes
 - LP: #485159: Some apps have problem with Systray
 - LP: #500677: ~/.xsession-errors is too much used by CD
 - LP: #500979: Shortcuts: the order gets messed up
 - LP: #521531: Mail: crashes on Maildir
 - LP: #519915: GTG: create a new applet to control GTG
 - LP: #526138: GMenu doesn't handle desktop file exec strings properly
 - LP: #531317: CMake: Added an error if the prefix of 'cairo-dock-plugins'
                 is not the same 'cairo-dock-core'
 - LP: #531319: CMake: check the version of 'cairo-dock' when building
                 'cairo-dock-plugins'
 - LP: #537115: Click at the position where icon lavel was, the icon
                 and dock still receive the event
 - LP: #537943: Terminal applet shortkey behaviour
 - LP: #538637: Trash applet doesn't create .trashinfo files on XFCE
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - cdbs is now used.
* debian/copyright:
 - Updated with the new applets
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev, libindicator-dev, libdbusmenu-glib-dev
   libido-0.1-dev, libical-dev, libdbusmenu-gtk-dev as Build-deps
 - Bump Standard-Version to 3.9.1
 - Wget is required for dnd2share applet
 - Added the exact realease for 'cairo-dock-dev' in order to prevent any
    build error if this package is not already available (thx to didrocks)
* debian/cairo-dock-plug-ins*.install:
 - All sonames are now installed into lib32 or lib64 (lib*)

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
#include <stdlib.h>
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include <math.h>
 
24
 
 
25
#include <fcntl.h>
 
26
#include <unistd.h>
 
27
#include <unistd.h>
 
28
 
 
29
#include "applet-struct.h"
 
30
#include "applet-rame.h"
 
31
 
 
32
#define RAME_DATA_PIPE CD_SYSMONITOR_PROC_FS"/meminfo"
 
33
 
 
34
#define goto_next_line \
 
35
        str = strchr (str, '\n'); \
 
36
        if (str == NULL) { \
 
37
                myData.bAcquisitionOK = FALSE; \
 
38
                return; \
 
39
        } \
 
40
        str ++;
 
41
#define get_value(iValue) \
 
42
        str = strchr (str, ':'); \
 
43
        if (str == NULL) { \
 
44
                myData.bAcquisitionOK = FALSE; \
 
45
                g_free (cContent); \
 
46
                return; \
 
47
        } \
 
48
        str ++; \
 
49
        while (*str == ' ') \
 
50
                str ++; \
 
51
        iValue = atoll (str);
 
52
void cd_sysmonitor_get_ram_data (CairoDockModuleInstance *myApplet)
 
53
{
 
54
        gchar *cContent = NULL;
 
55
        gsize length=0;
 
56
        GError *erreur = NULL;
 
57
        g_file_get_contents (RAME_DATA_PIPE, &cContent, &length, &erreur);
 
58
        if (erreur != NULL)
 
59
        {
 
60
                cd_warning("ram : %s", erreur->message);
 
61
                g_error_free(erreur);
 
62
                erreur = NULL;
 
63
                myData.bAcquisitionOK = FALSE;
 
64
        }
 
65
        else
 
66
        {
 
67
                int iNumLine = 1;
 
68
                gchar *str = cContent;
 
69
                
 
70
                get_value (myData.ramTotal)  // MemTotal
 
71
                
 
72
                
 
73
                goto_next_line
 
74
                get_value (myData.ramFree)  // MemFree
 
75
                
 
76
                
 
77
                myData.ramUsed = myData.ramTotal - myData.ramFree;
 
78
                goto_next_line
 
79
                get_value (myData.ramBuffers)  // Buffers.
 
80
                
 
81
                goto_next_line
 
82
                get_value (myData.ramCached)  // Cached.
 
83
                
 
84
                
 
85
                myData.fRamPercent = 100. * (myData.ramUsed - myData.ramCached - myData.ramBuffers) / myData.ramTotal;
 
86
                
 
87
                if (fabs (myData.fRamPercent - myData.fPrevRamPercent) > 1)
 
88
                {
 
89
                        myData.fPrevRamPercent = myData.fRamPercent;
 
90
                        myData.bNeedsUpdate = TRUE;
 
91
                }
 
92
                
 
93
                if (myConfig.bShowSwap)
 
94
                {
 
95
                        goto_next_line  // SwapCached:
 
96
                        goto_next_line  // Active:
 
97
                        goto_next_line  // Inactive:
 
98
                        
 
99
                        while (strncmp (str, "SwapTotal", 9) != 0)  // apres, suivant la version su noyau, les lignes ne sont pas les memes, on fait donc une recherche.
 
100
                        {
 
101
                                goto_next_line
 
102
                        }
 
103
                        get_value (myData.swapTotal)  // SwapTotal.
 
104
                        goto_next_line
 
105
                        get_value (myData.swapFree)  // SwapFree.
 
106
                        
 
107
                        myData.swapUsed = myData.swapTotal - myData.swapFree;
 
108
                        
 
109
                        myData.fSwapPercent = 100. * myData.swapUsed / myData.swapTotal;  // que faire de SwapCached ?...
 
110
                        if (fabs (myData.fSwapPercent - myData.fPrevSwapPercent) > 1)
 
111
                        {
 
112
                                myData.fPrevSwapPercent = myData.fSwapPercent;
 
113
                                myData.bNeedsUpdate = TRUE;
 
114
                        }
 
115
                }
 
116
                
 
117
                g_free (cContent);
 
118
        }
 
119
}