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/>.
21
#include <cairo-dock.h>
23
#include "powermanager-draw.h"
24
#include "powermanager-config.h"
25
#include "powermanager-dbus.h"
26
#include "powermanager-menu-functions.h"
27
#include "powermanager-struct.h"
28
#include "powermanager-init.h"
31
CD_APPLET_DEFINITION ("PowerManager",
33
CAIRO_DOCK_CATEGORY_ACCESSORY,
34
N_("A power manager for laptop's battery. It works with ACPI and DBus."),
35
"Necropotame (Adrien Pilleboue)")
41
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
43
// on ne charge pas toutes les surfaces, car cela prend trop de memoire, et trop de temps au chargement, alors que ce n'est pas necessaire. En effet, on ne redessine que si il y'a changement. Or la batterie se vide lentement, et la recharge n'est pas non plus fulgurante, donc au total on redesine reellement l'icone 1 fois toutes les 10 minutes peut-etre, ce qui ne justifie pas de pre-charger les surfaces.
45
myData.dbus_enable = dbus_connect_to_bus ();
46
if (myData.dbus_enable)
48
if(myData.battery_present)
52
if (myConfig.bUseGauge)
54
double fMaxScale = cairo_dock_get_max_scale (myContainer);
55
myData.pGauge = cairo_dock_load_gauge (myDrawContext, myConfig.cGThemePath, myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
58
myData.previous_battery_charge = -1;
59
myData.previous_battery_time = -1;
60
myData.alerted = TRUE;
61
myData.bCritical = TRUE;
63
myData.checkLoop = g_timeout_add_seconds (myConfig.iCheckInterval, (GSourceFunc) update_stats, (gpointer) NULL);
66
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("sector.svg");
69
else // sinon on signale par l'icone appropriee que le bus n'est pas accessible.
70
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("broken.svg");
72
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
73
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
78
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
79
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
81
dbus_disconnect_from_bus ();
83
if(myData.checkLoop != 0)
85
g_source_remove (myData.checkLoop);
91
CD_APPLET_RELOAD_BEGIN
93
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
95
double fMaxScale = cairo_dock_get_max_scale (myContainer);
96
if (CD_APPLET_MY_CONFIG_CHANGED)
98
cairo_dock_free_gauge(myData.pGauge);
99
myData.pGauge = cairo_dock_load_gauge(myDrawContext,myConfig.cGThemePath,myIcon->fWidth * fMaxScale,myIcon->fHeight * fMaxScale);
101
if(myData.checkLoop != 0) // la frequence peut avoir change.
103
g_source_remove (myData.checkLoop);
104
myData.checkLoop = 0;
106
myData.checkLoop = g_timeout_add_seconds (myConfig.iCheckInterval, (GSourceFunc) update_stats, (gpointer) NULL);
110
cairo_dock_reload_gauge (myDrawContext, myData.pGauge, myIcon->fWidth * fMaxScale,myIcon->fHeight * fMaxScale);
112
//\_______________ On redessine notre icone.
113
if (myData.dbus_enable)
115
if(myData.battery_present)
117
if (myConfig.bUseGauge) // On recharge la jauge.
119
///double fMaxScale = (myDock != NULL ? 1 + g_fAmplitude : 1);
120
///myData.pGauge = cairo_dock_load_gauge(myDrawContext,myConfig.cThemePath,myIcon->fWidth * fMaxScale,myIcon->fHeight * fMaxScale);
122
cairo_dock_render_gauge (myDrawContext, myContainer, myIcon, myData.pGauge, (double) myData.battery_charge / 100);
124
//Embleme sur notre icône
125
CD_APPLET_DRAW_EMBLEM ((myData.on_battery ? CAIRO_DOCK_EMBLEM_BLANK : CAIRO_DOCK_EMBLEM_CHARGE), CAIRO_DOCK_EMBLEM_MIDDLE);
127
else // on redessine juste l'icone actuelle.
128
cd_powermanager_draw_icon_with_effect (myData.on_battery);
130
if (!myData.on_battery && myData.battery_charge < 100)
131
myData.alerted = FALSE; //We will alert when battery charge reach 100%
132
if (myData.on_battery)
134
if (myData.battery_charge > myConfig.lowBatteryValue)
135
myData.alerted = FALSE; //We will alert when battery charge is under myConfig.lowBatteryValue
137
if (myData.battery_charge > 4)
138
myData.bCritical = FALSE; //We will alert when battery charge is critical (under 4%)
141
myData.previous_battery_charge = -1;
142
myData.previous_battery_time = -1;
146
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("sector.svg");
149
else // sinon on signale par l'icone appropriee que le bus n'est pas accessible.
150
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("broken.svg");