29
29
#include "applet-disk-usage.h"
30
30
#include "applet-rame.h"
32
gchar* ltrim( gchar* str, const gchar* t ) // Couper tout depuis la gauche
36
char look[ 256 ] = { 1, 0 };
38
look[ (unsigned char)*t++ ] = 1;
41
while( *curStr && look[ *curStr ] )
43
strcpy( str, curStr );
48
33
gchar* rtrim( gchar* str, const gchar* t ) // Couper tout depuis la droite
50
char* curEnd = str, *end = str;
52
char look[ 256 ] = { 1, 0 };
35
gchar* curEnd = str, *end = str;
36
gchar look[ 256 ] = { 1, 0 };
54
38
look[ (unsigned char)*t++ ] = 1;
58
41
if ( !look[ *end ] )
53
gchar* ltrim( gchar* str, const gchar* t ) // Couper tout depuis la gauche
56
gchar* cSearch = g_strdup_printf("%s", t);
57
g_strreverse (cSearch);
68
66
gchar *g_str_replace (const gchar *cString, const gchar *cWord, const gchar *cReplace)
70
71
if (g_strstr_len (cString, -1, cWord) != NULL) // On remplace
72
73
gchar *cFinalString = g_strdup_printf("%s", cString);
73
74
while (g_strstr_len (cFinalString, -1, cWord) != NULL)
75
gchar *cPart1 = g_strdup_printf("%s", cFinalString);
76
gchar *cWordTemp = g_strdup_printf("%s", cWord);
76
cPart1 = g_strdup_printf("%s", cFinalString);
77
cWordTemp = g_strdup_printf("%s", cWord);
77
78
g_strreverse (cPart1);
78
79
g_strreverse (cWordTemp);
79
80
cPart1 = strstr(cPart1, cWordTemp) ;
80
81
ltrim( cPart1, cWordTemp );
81
82
g_strreverse (cPart1);
82
gchar *cPart2 = g_strdup_printf("%s", cFinalString);
83
cPart2 = g_strdup_printf("%s", cFinalString);
84
85
while (g_strstr_len (cPart2, -1, cWord) != NULL)
86
cPart2 = strstr(cPart2, cWord);
87
cPart2 = strstr(cPart2, cWord);
87
88
ltrim( cPart2, cWord );
89
90
// On colle le texte au milieu
90
91
cFinalString = g_strdup_printf ("%s%s%s", cPart1, g_strdup_printf("%s",cReplace), cPart2);
93
return g_strdup_printf("%s", cFinalString);
96
return g_strdup_printf("%s",cString); // On retourne la phrase d'origine
94
return g_strdup_printf("%s", cFinalString);
95
g_free (cFinalString);
98
return g_strdup_printf("%s",cString); // Remplacement non trouvé -> On retourne la phrase d'origine
105
gchar *g_str_position (const gchar *cString, const int iPosition, const char cSeparator)
107
gchar *strSeparator = g_strdup_printf("%c", cSeparator);
109
if ((g_strstr_len (cString, -1, strSeparator) != NULL) && (iPosition > 0)) // Separator trouvé -> On coupe
111
gchar *cFinalString = g_strdup_printf("%s", cString);
115
g_strreverse (cFinalString);
116
cFinalString = strrchr(cFinalString, cSeparator);
117
ltrim( cFinalString, strSeparator);
118
g_strreverse (cFinalString);
125
if (g_strstr_len (cFinalString, -1, strSeparator) == NULL) // Il n'y a plus de séparateur -> Mauvais champ spécifié
127
cd_debug ("DONCKY-debug : /!\\ Missing values detected. Search for the string '%s' to fix it.", cString);
128
// On retourne 0 pour le champ non trouvé :
129
cFinalString = g_strdup_printf("0");
134
cFinalString = strchr(cFinalString, cSeparator);
135
ltrim( cFinalString, strSeparator);
139
while (i != iPosition);
141
if ((g_strstr_len (cFinalString, -1, strSeparator) != NULL) && (iPosition > 0)) // Il reste des séparateurs -> On coupe les derniers champs
143
g_strreverse (cFinalString);
144
cFinalString = strrchr(cFinalString, cSeparator);
145
ltrim( cFinalString, strSeparator);
146
g_strreverse (cFinalString);
149
return g_strdup_printf("%s", cFinalString);
150
g_free (cFinalString);
151
g_free (strSeparator);
155
return g_strdup_printf("%s",cString); // Pas de séparateur -> On retourne la phrase d'origine
376
422
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 5));
378
424
else if (strcmp (pTextZone->cCommand, "fs_device") == 0)
379
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 6));
425
pTextZone->cResult = g_strdup_printf ("%s", cd_doncky_get_disk_info (pTextZone->cMountPoint, 6));
386
432
gboolean cd_retrieve_command_result (CairoDockModuleInstance *myApplet)
390
static double s_fValues[CD_SYSMONITOR_NB_MAX_VALUES];
393
if ( ! myData.bAcquisitionOK)
395
cd_warning ("One or more datas couldn't be retrieved");
396
memset (s_fValues, 0, sizeof (s_fValues));
397
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
401
if (! myData.bInitialized)
403
memset (s_fValues, 0, sizeof (s_fValues));
404
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
408
// Copier les donnes en memoire partagee...
410
//~ 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.
412
//~ gboolean bOneLine = (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_LABEL);
413
//~ GString *sInfo = g_string_new ("");
414
//~ if (myConfig.bShowCpu)
416
//~ g_string_printf (sInfo, (myData.fCpuPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
417
//~ (myDesklet ? "CPU:" : ""),
418
//~ myData.fCpuPercent,
419
//~ (bOneLine ? " - " : "\n"));
421
//~ if (myConfig.bShowRam)
423
//~ g_string_append_printf (sInfo, (myData.fRamPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
424
//~ (myDesklet ? "RAM:" : ""),
425
//~ myData.fRamPercent,
426
//~ (bOneLine ? " - " : "\n"));
428
//~ if (myConfig.bShowSwap)
430
//~ g_string_append_printf (sInfo, (myData.fSwapPercent < 10 ? "%s%.1f%%%s" : "%s%.0f%%%s"),
431
//~ (myDesklet ? "SWAP:" : ""),
432
//~ myData.fSwapPercent,
433
//~ (bOneLine ? " - " : "\n"));
435
//~ if (myConfig.bShowNvidia)
437
//~ g_string_append_printf (sInfo, "%s%d°C%s",
438
//~ (myDesklet ? "GPU:" : ""),
440
//~ (bOneLine ? " - " : "\n"));
442
//~ sInfo->str[sInfo->len-(bOneLine?3:1)] = '\0';
444
//~ CD_APPLET_SET_NAME_FOR_MY_ICON (sInfo->str);
446
//~ CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (sInfo->str);
447
//~ g_string_free (sInfo, TRUE);
450
if (myData.bNeedsUpdate || myConfig.iDisplayType == CD_SYSMONITOR_GRAPH)
453
if (myConfig.bShowCpu)
455
s_fValues[i++] = myData.fCpuPercent / 100.;
457
if (myConfig.bShowRam)
459
s_fValues[i++] = myData.fRamPercent / 100.;
461
if (myConfig.bShowSwap)
462
s_fValues[i++] = (myData.swapTotal ? ((double)myData.swapUsed) / myData.swapTotal : 0.);
463
if (myConfig.bShowNvidia)
464
s_fValues[i++] = myData.fGpuTempPercent / 100.;
466
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (s_fValues);
476
435
TextZone *pTextZone;
479
437
for (it = myData.pTextZoneList; it != NULL; it = it->next)
481
439
pTextZone = it->data;
483
441
if (pTextZone->iRefresh != 0 || pTextZone->bRefresh)
485
443
if (pTextZone->bRefresh && pTextZone->cResult != NULL)
487
445
pTextZone->cText = g_strdup_printf ("%s",pTextZone->cResult);
490
448
if (pTextZone->iRefresh != 0 && pTextZone->iTimer >= pTextZone->iRefresh)
492
450
pTextZone->bRefresh = TRUE;
495
453
else // Pas de refresh de spécifié
498
if (pTextZone->cText == NULL || strcmp (pTextZone->cText, "") == 0) // La récupération s'est mal passé -> On relance !
455
if (pTextZone->cText == NULL || strcmp (pTextZone->cText, "Please wait...") == 0) // La récupération s'est mal passé -> On relance !
499
457
pTextZone->bRefresh = TRUE;
458
pTextZone->iTimer = 0; // On remet le timer à 0
460
cd_debug ("DONCKY-debug : Commande non passée = %s", pTextZone->cCommand);
501
463
pTextZone->bRefresh = FALSE; // On a récupéré l'info -> On arrête là !
505
467
cd_applet_update_my_icon (myApplet); // Quand tous les textes sont chargés, on peut dessiner
506
myData.pPeriodicRefreshTask = NULL;
508
CD_APPLET_LEAVE (myData.bAcquisitionOK);
512
472
void cd_applet_draw_my_desklet (CairoDockModuleInstance *myApplet, int iWidth, int iHeight)
514
474
PangoLayout *pLayout = pango_cairo_create_layout (myDrawContext);