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 Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
*********************************************************************************/
30
#include <sys/types.h>
31
#include <sys/statfs.h>
34
#include <cairo-dock.h>
36
#include "applet-struct.h"
37
#include "applet-disk-usage.h"
40
void cd_shortcuts_get_fs_stat (const gchar *cDiskURI, CDDiskUsage *pDiskUsage)
42
static struct statfs sts;
43
const gchar *cMountPath = (strncmp (cDiskURI, "file://", 7) == 0 ? cDiskURI + 7 : cDiskURI);
44
//g_print ("checking device on '%s'...\n", cMountPath);
46
if (statfs (cMountPath, &sts) == 0)
48
if (pDiskUsage->iType == 0)
49
pDiskUsage->iType = sts.f_type;
50
pDiskUsage->iPrevAvail = pDiskUsage->iAvail;
51
pDiskUsage->iAvail = (long long)sts.f_bavail * sts.f_bsize; // Blocs libres pour utilisateurs
52
pDiskUsage->iFree = (long long)sts.f_bfree * sts.f_bsize; // Blocs libres
53
pDiskUsage->iTotal = (long long)sts.f_blocks * sts.f_bsize; // Nombre total de blocs
54
pDiskUsage->iUsed = pDiskUsage->iTotal - pDiskUsage->iAvail;
55
//g_print ("%lld / %lld\n", pDiskUsage->iAvail, pDiskUsage->iTotal);
59
void cd_shortcuts_get_disk_usage (CairoDockModuleInstance *myApplet)
61
const gchar *cMountPath;
62
GList *pElement = myData.pDiskUsageList;
63
CDDiskUsage *pDiskUsage;
64
long long iAvail, iFree, iTotal, iUsed, iType;
67
GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
68
for (ic = pIconsList; ic != NULL; ic = ic->next)
71
if (pIcon->iType != 6)
73
//g_print ("%s () : %s\n", __func__, pIcon->acCommand);
74
if (pIcon->acCommand != NULL)
78
pDiskUsage = pElement->data;
79
pElement = pElement->next;
83
pDiskUsage = g_new0 (CDDiskUsage, 1);
84
myData.pDiskUsageList = g_list_append (myData.pDiskUsageList, pDiskUsage);
87
cd_shortcuts_get_fs_stat (pIcon->acCommand, pDiskUsage);
92
gboolean cd_shortcuts_update_disk_usage (CairoDockModuleInstance *myApplet)
94
g_return_val_if_fail (myData.pDiskUsageList != NULL, TRUE);
96
CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
97
GList *pElement = myData.pDiskUsageList;
98
CDDiskUsage *pDiskUsage;
102
GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
103
for (ic = pIconsList; ic != NULL; ic = ic->next)
106
if (pIcon->iType != 6)
108
if (pIcon->acCommand != NULL && pElement != NULL)
110
pDiskUsage = pElement->data;
111
if (pDiskUsage->iPrevAvail != pDiskUsage->iAvail)
113
switch (myConfig.iDisplayType)
115
case CD_SHOW_FREE_SPACE :
116
fValue = (double) pDiskUsage->iAvail / pDiskUsage->iTotal;
117
cairo_dock_set_size_as_quick_info (myDrawContext, pIcon, pContainer, pDiskUsage->iAvail);
119
case CD_SHOW_USED_SPACE :
120
fValue = (double) - pDiskUsage->iUsed / pDiskUsage->iTotal; // <0 => du vert au rouge.
121
cairo_dock_set_size_as_quick_info (myDrawContext, pIcon, pContainer, pDiskUsage->iUsed);
123
case CD_SHOW_FREE_SPACE_PERCENT :
124
fValue = (double) pDiskUsage->iAvail / pDiskUsage->iTotal;
125
cairo_dock_set_quick_info_full (myDrawContext, pIcon, pContainer, "%.1f%%", 100.*fValue);
127
case CD_SHOW_USED_SPACE_PERCENT :
128
fValue = (double) - pDiskUsage->iUsed / pDiskUsage->iTotal; // <0 => du vert au rouge.
129
cairo_dock_set_quick_info_full (myDrawContext, pIcon, pContainer, "%.1f%%", -100.*fValue);
133
if (myConfig.bDrawBar)
136
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
137
cairo_surface_t *pSurface = cairo_dock_create_surface_for_icon (pIcon->acFileName, myDrawContext, iWidth, iHeight);;
138
cairo_t *pIconContext = cairo_create (pIcon->pIconBuffer);
140
cairo_dock_set_icon_surface_with_bar (pIconContext, pSurface, fValue, pIcon, pContainer);
142
cairo_destroy (pIconContext);
143
cairo_surface_destroy (pSurface);
146
if (pDiskUsage->iPrevAvail != 0)
147
cairo_dock_redraw_icon (pIcon, pContainer);
149
pElement = pElement->next;
157
void cd_shortcuts_stop_disk_periodic_task (CairoDockModuleInstance *myApplet)
159
cairo_dock_stop_task (myData.pDiskTask);
160
g_list_foreach (myData.pDiskUsageList, (GFunc) g_free, NULL);
161
g_list_free (myData.pDiskUsageList);
162
myData.pDiskUsageList = NULL;
165
void cd_shortcuts_launch_disk_periodic_task (CairoDockModuleInstance *myApplet)
167
if (myConfig.iDisplayType != CD_SHOW_NOTHING)
169
if (myData.pDiskTask == NULL)
171
myData.pDiskTask = cairo_dock_new_task (myConfig.iCheckInterval,
172
(CairoDockGetDataAsyncFunc) cd_shortcuts_get_disk_usage,
173
(CairoDockUpdateSyncFunc) cd_shortcuts_update_disk_usage,
176
cairo_dock_launch_task (myData.pDiskTask);
182
void cd_shortcuts_get_fs_info (const gchar *cDiskURI, GString *sInfo)
184
const gchar *cMountPath = (strncmp (cDiskURI, "file://", 7) == 0 ? cDiskURI + 7 : cDiskURI);
186
FILE *mtab = setmntent ("/etc/mtab", "r");
193
cd_warning ("couldn't open /etc/mtab");
197
gchar *cFsInfo = NULL;
198
while ((me = getmntent (mtab)) != NULL)
200
if (me->mnt_dir && strcmp (me->mnt_dir, cMountPath) == 0)
202
g_string_append_printf (sInfo, "Mount point : %s\nFile system : %s\nDevice : %s\nMount options : %s",
207
if (me->mnt_freq != 0)
208
g_string_append_printf (sInfo, "\nBackup frequency : %d days", me->mnt_freq);