32
32
void update_icon (void)
34
34
gboolean bNeedRedraw = FALSE;
35
cd_message ("%s (on battery: %d -> %d; time:%.1f -> %.1f ; charge:%.1f -> %.1f)", __func__, myData.bPrevOnBattery, myData.bOnBattery, (double)myData.iPrevTime, (double)myData.iTime, (double)myData.iPrevPercentage, (double)myData.iPercentage);
35
cd_debug ("%s (on battery: %d -> %d; time:%.1f -> %.1f ; charge:%.1f -> %.1f)", __func__, myData.bPrevOnBattery, myData.bOnBattery, (double)myData.iPrevTime, (double)myData.iTime, (double)myData.iPrevPercentage, (double)myData.iPercentage);
37
// no information available, draw a default icon.
37
38
if (myData.cBatteryStateFilePath == NULL && myData.pUPowerClient == NULL)
39
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("sector.svg");
40
CD_APPLET_SET_IMAGE_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/sector.svg");
40
41
CD_APPLET_REDRAW_MY_ICON;
45
// hide the icon when not on battery
46
if (myConfig.bHideNotOnBattery && ! myData.bOnBattery && myDock)
48
if (! myData.bIsHidden)
49
{ // we remove the icon
50
cairo_dock_detach_icon_from_dock (myIcon, myDock, myIconsParam.iSeparateIcons);
51
myData.bIsHidden = TRUE;
52
cairo_dock_update_dock_size (myDock);
53
cairo_dock_redraw_container (CAIRO_CONTAINER (myDock)); // dock refresh forced
55
return; // no need any redraw if the icon is hidden, and can't display the dialog properly without the icon.
57
else if (myData.bIsHidden && myData.bOnBattery && myDock) // if the icon is hidden but we are now on battery, we (re-)insert the icon.
59
cd_debug ("Re-insert the icon");
60
cairo_dock_insert_icon_in_dock (myIcon, myDock, CAIRO_DOCK_UPDATE_DOCK_SIZE, CAIRO_DOCK_ANIMATE_ICON);
61
cairo_dock_redraw_container (CAIRO_CONTAINER (myDock)); // dock refresh forced
62
myData.bIsHidden = FALSE;
43
65
// on prend en compte la nouvelle charge.
44
66
if (myData.bPrevOnBattery != myData.bOnBattery || myData.iPrevPercentage != myData.iPercentage || myData.iTime != myData.iPrevTime)
46
if (myData.bPrevOnBattery != myData.bOnBattery)
48
myData.bPrevOnBattery = myData.bOnBattery;
49
myData.bAlerted = FALSE; // On a change de statut, donc on reinitialise les alertes
50
myData.bCritical = FALSE;
53
68
// on redessine l'icone.
54
69
if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH)
56
double fPercent = (double) myData.iPercentage / 100.;
72
if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE && ! myData.bBatteryPresent)
73
fPercent = CAIRO_DATA_RENDERER_UNDEF_VALUE;
75
fPercent = (double) myData.iPercentage / 100.;
57
76
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fPercent);
58
77
bNeedRedraw = FALSE;
62
81
cd_powermanager_draw_icon_with_effect (myData.bOnBattery);
63
82
bNeedRedraw = FALSE;
84
if (! myData.bOnBattery)
86
CD_APPLET_DRAW_EMBLEM_ON_MY_ICON (myData.pEmblem);
87
} // else emblem is implicitely erased.
66
89
// on declenche les alarmes.
67
90
if (myData.bOnBattery)
69
// Alert when battery charge is under a configured value in %
70
if (myData.iPercentage <= myConfig.lowBatteryValue && ! myData.bAlerted)
92
// Alert when battery charge goes under a configured value in %
93
if (myData.iPrevPercentage > myConfig.lowBatteryValue && myData.iPercentage <= myConfig.lowBatteryValue)
72
95
cd_powermanager_alert(POWER_MANAGER_CHARGE_LOW);
73
96
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW] != NULL)
74
97
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW]);
76
99
// Alert when battery charge is under 4%
77
if (myData.iPercentage <= 4 && ! myData.bCritical)
100
if (myData.iPrevPercentage > 4 && myData.iPercentage <= 4)
79
myData.bCritical = TRUE;
80
102
cd_powermanager_alert (POWER_MANAGER_CHARGE_CRITICAL);
81
103
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL] != NULL)
82
104
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL]);
84
// emblem is implicitely erased.
88
109
// Alert when battery is charged
89
if(myData.iPercentage == 100 && ! myData.bAlerted)
110
if(myData.iPrevPercentage < 100 && myData.iPercentage == 100)
90
111
cd_powermanager_alert (POWER_MANAGER_CHARGE_FULL);
92
CD_APPLET_DRAW_EMBLEM_ON_MY_ICON (myData.pEmblem);
114
// update the icon's label.
95
115
if (myConfig.defaultTitle == NULL || *myConfig.defaultTitle == '\0')
97
117
if (! myData.bOnBattery && myData.iPercentage > 99.9)
246
266
g_string_printf (sInfo, "%s (%d%%)", D_("PowerManager.\nYour battery is now charged"), (int)myData.iPercentage);
247
267
_cd_powermanager_dialog (sInfo->str, myConfig.iNotificationDuration);
249
if (myConfig.iNotificationType != 2)
269
if (! myData.bIsHidden && myConfig.iNotificationType != 2)
251
271
CD_APPLET_DEMANDS_ATTENTION (myConfig.cNotificationAnimation, myConfig.iNotificationDuration);
326
345
int time = myData.iTime;
327
346
int hours = time / 3600;
328
347
int minutes = (time % 3600) / 60;
329
g_print ("time: %d -> %d;%d\n", time, hours, minutes);
348
cd_debug ("time: %d -> %d;%d", time, hours, minutes);
331
350
snprintf (cFormatBuffer, iBufferLength, "%dh%02d", hours, abs (minutes));