23
23
#include "powermanager-struct.h"
24
24
#include "powermanager-draw.h"
27
no battery -> empty gauge (0%), on-sector emblem, no alert
28
on battery -> gauge + %, no emblem, alert
29
on sector -> gauge + %, on-sector emblem, alert
27
void update_icon(void)
32
void update_icon (void)
29
34
gboolean bNeedRedraw = FALSE;
30
cd_message ("%s (time:%.2f -> %.2f ; charge:%.2f -> %.2f)", __func__, myData.previous_battery_time, myData.battery_time, myData.previous_battery_charge, myData.battery_charge);
31
if(myData.battery_present)
33
// on prend en compte la nouvelle charge.
34
if (myData.previously_on_battery != myData.on_battery || myData.previous_battery_charge != myData.battery_charge)
36
if (myData.previously_on_battery != myData.on_battery)
38
myData.previously_on_battery = myData.on_battery;
39
myData.alerted = FALSE; //On a changé de statut, donc on réinitialise les alertes
40
myData.bCritical = FALSE;
43
// on redessine l'icone.
44
if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH)
46
double fPercent = (double) myData.battery_charge / 100.;
47
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fPercent);
50
else if (myConfig.iDisplayType == CD_POWERMANAGER_ICONS)
52
cd_powermanager_draw_icon_with_effect (myData.on_battery);
56
// on declenche les alarmes.
59
//Alert when battery charge is under a configured value in %
60
if (myData.battery_charge <= myConfig.lowBatteryValue && ! myData.alerted)
62
cd_powermanager_alert(POWER_MANAGER_CHARGE_LOW);
63
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW] != NULL)
64
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW]);
66
//Alert when battery charge is under 4%
67
if (myData.battery_charge <= 4 && ! myData.bCritical)
69
myData.bCritical = TRUE;
70
cd_powermanager_alert (POWER_MANAGER_CHARGE_CRITICAL);
71
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL] != NULL)
72
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL]);
74
//Embleme sur notre icône
75
//CD_APPLET_DRAW_EMBLEM (CAIRO_DOCK_EMBLEM_BLANK, CAIRO_DOCK_EMBLEM_MIDDLE);
79
//Alert when battery is charged
80
if(myData.battery_charge == 100 && ! myData.alerted)
81
cd_powermanager_alert (POWER_MANAGER_CHARGE_FULL);
83
//CD_APPLET_DRAW_EMBLEM (CAIRO_DOCK_EMBLEM_CHARGE, CAIRO_DOCK_EMBLEM_MIDDLE);
84
CD_APPLET_DRAW_EMBLEM_ON_MY_ICON (myData.pEmblem);
87
myData.previously_on_battery = myData.on_battery;
88
myData.previous_battery_charge = myData.battery_charge;
91
// on reactualise le temps restant en info rapide.
92
if (myData.previous_battery_time != myData.battery_time)
94
/*if(myConfig.quickInfoType == POWER_MANAGER_TIME)
96
if (myData.battery_time != 0) {
97
CD_APPLET_SET_HOURS_MINUTES_AS_QUICK_INFO (myData.battery_time);
100
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("-:--");
103
else if(myConfig.quickInfoType == POWER_MANAGER_CHARGE)
105
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%%", (int)myData.battery_charge);
109
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
112
bNeedRedraw = TRUE;*/
114
if (myConfig.defaultTitle == NULL || *myConfig.defaultTitle == '\0')
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);
37
if (myData.cBatteryStateFilePath == NULL && myData.pUPowerClient == NULL)
39
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("sector.svg");
40
CD_APPLET_REDRAW_MY_ICON;
43
// on prend en compte la nouvelle charge.
44
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
// on redessine l'icone.
54
if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH)
56
double fPercent = (double) myData.iPercentage / 100.;
57
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fPercent);
60
else if (myConfig.iDisplayType == CD_POWERMANAGER_ICONS)
62
cd_powermanager_draw_icon_with_effect (myData.bOnBattery);
66
// on declenche les alarmes.
67
if (myData.bOnBattery)
69
// Alert when battery charge is under a configured value in %
70
if (myData.iPercentage <= myConfig.lowBatteryValue && ! myData.bAlerted)
72
cd_powermanager_alert(POWER_MANAGER_CHARGE_LOW);
73
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW] != NULL)
74
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_LOW]);
76
// Alert when battery charge is under 4%
77
if (myData.iPercentage <= 4 && ! myData.bCritical)
79
myData.bCritical = TRUE;
80
cd_powermanager_alert (POWER_MANAGER_CHARGE_CRITICAL);
81
if (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL] != NULL)
82
cairo_dock_play_sound (myConfig.cSoundPath[POWER_MANAGER_CHARGE_CRITICAL]);
84
// emblem is implicitely erased.
88
// Alert when battery is charged
89
if(myData.iPercentage == 100 && ! myData.bAlerted)
90
cd_powermanager_alert (POWER_MANAGER_CHARGE_FULL);
92
CD_APPLET_DRAW_EMBLEM_ON_MY_ICON (myData.pEmblem);
95
if (myConfig.defaultTitle == NULL || *myConfig.defaultTitle == '\0')
97
if (! myData.bOnBattery && myData.iPercentage > 99.9)
99
CD_APPLET_SET_NAME_FOR_MY_ICON_PRINTF ("%s (%d%%)",
100
D_("Battery charged"),
101
(int)myData.iPercentage);
116
105
gchar cFormatBuffer[21];
117
106
int iBufferLength = 20;
118
if (myData.battery_time != 0)
107
if (myData.iTime != 0)
120
int time = myData.battery_time;
109
int time = myData.iTime;
121
110
int hours = time / 3600;
122
111
int minutes = (time % 3600) / 60;
168
151
cairo_dock_remove_dialog_if_any (myIcon);
170
const gchar *cIconPath;
171
if (!myData.on_battery || !myData.battery_present)
153
/**const gchar *cIconPath;
154
if (!myData.bOnBattery)
172
155
cIconPath = MY_APPLET_SHARE_DATA_DIR"/sector.svg";
174
157
cIconPath = MY_APPLET_SHARE_DATA_DIR"/default-battery.svg";
176
cd_debug ("%s (%s)", cInfo, cIconPath);
177
cairo_dock_show_temporary_dialog_with_icon (cInfo, myIcon, myContainer, 1000*iDuration, cIconPath);
159
cd_debug ("%s (%s)", cInfo, cIconPath);*/
160
cairo_dock_show_temporary_dialog_with_icon (cInfo, myIcon, myContainer, 1000*iDuration, "same icon");
180
163
void cd_powermanager_bubble (void)
182
165
GString *sInfo = g_string_new ("");
183
if(myData.battery_present)
166
if (myData.cBatteryStateFilePath != NULL || myData.pUPowerClient != NULL)
185
169
gchar *hms = NULL;
186
if (myData.battery_time > 0.)
187
hms = get_hours_minutes (myData.battery_time);
170
if (myData.iTime > 0.)
171
hms = get_hours_minutes (myData.iTime);
189
173
hms = g_strdup_printf ("%s", D_("Unknown"));
190
if(myData.on_battery)
174
if (myData.bOnBattery)
192
g_string_printf (sInfo, "%s %.2f%% \n %s %s", D_("Laptop on Battery.\n Battery charged at:"), myData.battery_charge, D_("Estimated time with charge:"), hms);
176
g_string_printf (sInfo, "%s\n"
179
D_("Laptop on Battery."),
180
D_("Battery charged at:"), (int)myData.iPercentage,
181
D_("Estimated time before empty:"), hms);
196
g_string_printf (sInfo, "%s %.2f%% \n %s %s", D_("Laptop on Charge.\n Battery charged at:"), myData.battery_charge, D_("Estimated charge time:"), (myData.battery_charge > 99.9 ? "0" : hms));
185
g_string_printf (sInfo, "%s\n"
188
D_("Laptop on Charge."),
189
D_("Battery charged at:"), (int)myData.iPercentage,
190
D_("Estimated time before full:"), (myData.iPercentage > 99.9 ? "0" : hms));
195
if (myData.cVendor != NULL || myData.cModel != NULL)
197
g_string_append_printf (sInfo, "\n%s: %s %s", D_("Model"), myData.cVendor ? myData.cVendor : "", myData.cModel ? myData.cModel : "");
199
/*if (0&&myData.cTechnology != NULL) // if (0 && (...)) ??? :)
201
g_string_append_printf (sInfo, "\n%s: %s", D_("Technology"), myData.cTechnology);
203
if (myData.fMaxAvailableCapacity != 0)
205
g_string_append_printf (sInfo, "\n%s: %d%%", D_("Maximum capacity"), (int)myData.fMaxAvailableCapacity);
202
g_string_printf (sInfo, "%s", D_("No battery found."));
210
g_string_assign (sInfo, D_("No battery found."));
205
_cd_powermanager_dialog (sInfo->str, 6);
213
_cd_powermanager_dialog (sInfo->str, 7);
206
214
g_string_free (sInfo, TRUE);
288
296
case POWER_MANAGER_EFFECT_ZOOM :
289
297
cairo_save (myDrawContext);
290
double fScale = .3 + .7 * myData.battery_charge / 100.;
298
double fScale = .3 + .7 * myData.iPercentage / 100.;
291
299
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ZOOM (pSurface, fScale);
292
300
cairo_restore (myDrawContext);
294
302
case POWER_MANAGER_EFFECT_TRANSPARENCY :
295
303
cairo_save (myDrawContext);
296
double fAlpha = .3 + .7 * myData.battery_charge / 100.;
304
double fAlpha = .3 + .7 * myData.iPercentage / 100.;
297
305
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ALPHA (pSurface, fAlpha);
298
306
cairo_restore (myDrawContext);
300
308
case POWER_MANAGER_EFFECT_BAR :
301
309
cairo_save (myDrawContext);
302
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_BAR (pSurface, myData.battery_charge * .01);
310
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_BAR (pSurface, myData.iPercentage * .01);
303
311
cairo_restore (myDrawContext);