~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to powermanager/src/powermanager-init.c

  • Committer: Matthieu Baerts
  • Date: 2011-08-09 19:51:45 UTC
  • mfrom: (1.1.12 upstream)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: matttbe@gmail.com-20110809195145-6t55jtykipujuyn5
* New upstream release. (LP: #823514)
* Upstream (short) ChangeLog:
 - The Power-Manager applet has been rewritten to work on any plateform.
 - Compiz-icon applet has been replaced by Composite-Manager.
 - Improved integration in the XFCE, LXDE and GNOME3 desktop.
 - Logout is now working even if there is no/an unknow session manager.
 - Several new DBus methods lets you interact on the dock more easily.
 - Added the possibility to shutdown/logout with GMenu.
 - Improved Status-Notifier and added its own watcher.
 - Added a new applet: Impulse (still need testing).
 - Fixed a few bugs as usual.
* debian/patches:
 - Removed all patches (they was already unapplied).
* debian/copyright:
 - Updated with new files/directory.
* debian/cairo-dock-plug-ins.install:
 - Added status-notifier-watcher used by Status-Notifier applet.
* debian/control:
 - Updated the version of cairo-dock-[core;data;dev].
 - Bump Standard-Version to 3.9.2.
 - Added fftw3, pulse (Impulse) and upower-glib (Logout)
    as new dependences for the build process.
 - Added indicator-[me;messages] as new recommendations
    for cairo-dock-plug-ins (needed for [Me;Messaging]Menu applets).
 - Removed gawk from the build dependences list (no longer needed).
* cairo-dock-plug-ins package needs to be recompiled (LP: #811579)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdlib.h>
21
21
#include <cairo-dock.h>
22
22
 
23
 
#include "powermanager-draw.h"
 
23
#include "powermanager-struct.h"
24
24
#include "powermanager-config.h"
25
 
#include "powermanager-dbus.h"
 
25
#include "powermanager-common.h"
 
26
#include "powermanager-upower.h"
26
27
#include "powermanager-menu-functions.h"
27
 
#include "powermanager-struct.h"
 
28
#include "powermanager-draw.h"
28
29
#include "powermanager-init.h"
29
30
 
30
31
 
31
32
CD_APPLET_DEFINITION (N_("PowerManager"),
32
 
        2, 0, 6,
 
33
        2, 3, 0,
33
34
        CAIRO_DOCK_CATEGORY_APPLET_SYSTEM,
34
 
        N_("A power manager for laptop batteries. Works with ACPI and DBus."),
35
 
        "Necropotame (Adrien Pilleboue)")
 
35
        N_("This applet displays the current state of your <b>laptop battery</b>: charge, time remaining, etc\n"
 
36
        "<b>Click</b> on the icon to have useful inforamtion,\n"
 
37
        "<b>Right-click</b> on the icon to hibernate or suspend the system."),
 
38
        "Necropotame (Adrien Pilleboue) and Fabounet")
 
39
 
36
40
 
37
41
static void _set_data_renderer (CairoDockModuleInstance *myApplet, gboolean bReload)
38
42
{
51
55
                memset (&attr, 0, sizeof (CairoGraphAttribute));
52
56
                pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&attr);
53
57
                pRenderAttr->cModelName = "graph";
54
 
                pRenderAttr->iMemorySize = (myIcon->fWidth > 1 ? myIcon->fWidth : 32);  // fWidht peut etre <= 1 en mode desklet au chargement.
 
58
                pRenderAttr->iMemorySize = (myIcon->fWidth > 1 ? myIcon->fWidth : 32);  // fWidth peut etre <= 1 en mode desklet au chargement.
55
59
                attr.iType = myConfig.iGraphType;
56
60
                attr.iRadius = 10;
57
61
                attr.fHighColor = myConfig.fHigholor;
80
84
 
81
85
 
82
86
CD_APPLET_INIT_BEGIN
83
 
        
84
87
        if (myDesklet)
85
88
        {
86
89
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
87
90
                CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
88
91
        }
89
92
        
90
 
        // on ne charge pas toutes les surfaces, ce qui economise de la memoire, et du temps au chargement, car 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 5 minutes peut-etre, ce qui ne justifie pas de pre-charger les surfaces.
91
 
        
92
 
        if (cd_powermanager_find_battery())
93
 
        {
94
 
                myData.dbus_enable = dbus_connect_to_bus ();  // pour le changement d'etat.
95
 
                ///get_on_battery();
96
 
                
97
 
                // Initialisation du rendu.
98
 
                _set_data_renderer (myApplet, FALSE);
99
 
                
100
 
                if (myConfig.cEmblemIconName == NULL)
101
 
                        myData.pEmblem = CD_APPLET_MAKE_EMBLEM (MY_APPLET_SHARE_DATA_DIR"/charge.svg");
102
 
                else
103
 
                        myData.pEmblem = CD_APPLET_MAKE_EMBLEM (myConfig.cEmblemIconName);
104
 
                cairo_dock_set_emblem_position (myData.pEmblem, CAIRO_DOCK_EMBLEM_MIDDLE);
105
 
                
106
 
                if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH)
107
 
                {
108
 
                        double x=0;
109
 
                        CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&x);
110
 
                }
111
 
                
112
 
                // initialisation des parametres pour le 1er redessin.
113
 
                myData.prev_battery_present = TRUE;
114
 
                myData.previous_battery_charge = -1;
115
 
                myData.previous_battery_time = -1;
116
 
                myData.alerted = TRUE;
117
 
                myData.bCritical = TRUE;
118
 
                update_stats();
119
 
                myData.checkLoop = g_timeout_add_seconds (myConfig.iCheckInterval, (GSourceFunc) update_stats, (gpointer) NULL);
120
 
        }
 
93
        _set_data_renderer (myApplet, FALSE);
 
94
        if (myConfig.cEmblemIconName == NULL)
 
95
                myData.pEmblem = CD_APPLET_MAKE_EMBLEM (MY_APPLET_SHARE_DATA_DIR"/charge.svg");
121
96
        else
122
 
        {
123
 
                CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON ("sector.svg");
124
 
        }
 
97
                myData.pEmblem = CD_APPLET_MAKE_EMBLEM (myConfig.cEmblemIconName);
 
98
        cairo_dock_set_emblem_position (myData.pEmblem, CAIRO_DOCK_EMBLEM_MIDDLE);
 
99
        
 
100
        cd_powermanager_start ();
125
101
        
126
102
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
127
103
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
132
108
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
133
109
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
134
110
        
135
 
        dbus_disconnect_from_bus ();
136
 
        
137
 
        if(myData.checkLoop != 0)
 
111
        cairo_dock_discard_task (myData.pTask);
 
112
        
 
113
        if (myData.pUPowerClient != NULL)
 
114
        {
 
115
                g_object_unref (myData.pUPowerClient);
 
116
        }
 
117
        
 
118
        if (myData.checkLoop != 0)
138
119
        {
139
120
                g_source_remove (myData.checkLoop);
140
 
                myData.checkLoop = 0;
141
121
        }
142
 
        
143
122
CD_APPLET_STOP_END
144
123
 
145
124
 
161
140
                
162
141
                _set_data_renderer (myApplet, TRUE);
163
142
                
164
 
                if(myData.checkLoop != 0)  // la frequence peut avoir change.
165
 
                        g_source_remove (myData.checkLoop);
166
 
                myData.checkLoop = g_timeout_add_seconds (myConfig.iCheckInterval, (GSourceFunc) update_stats, (gpointer) NULL);
 
143
                cd_powermanager_change_loop_frequency (myConfig.iCheckInterval);
167
144
        }
168
145
        else
169
146
        {
173
150
        }
174
151
        
175
152
        //\_______________ On redessine notre icone.
176
 
        if (myData.cBatteryStateFilePath)
 
153
        if (myData.cBatteryStateFilePath || myData.pUPowerClient != NULL)
177
154
        {
178
155
                if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH)  // On recharge la jauge.
179
156
                {
180
 
                        double fPercent = (double) myData.battery_charge / 100.;
 
157
                        double fPercent = (double) myData.iPercentage / 100.;
181
158
                        CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fPercent);
182
159
                        
183
160
                        //Embleme sur notre icône
184
 
                        //CD_APPLET_DRAW_EMBLEM ((myData.on_battery ? CAIRO_DOCK_EMBLEM_BLANK : CAIRO_DOCK_EMBLEM_CHARGE), CAIRO_DOCK_EMBLEM_MIDDLE);
185
 
                        if (! myData.on_battery)
 
161
                        //CD_APPLET_DRAW_EMBLEM ((myData.bOnBattery ? CAIRO_DOCK_EMBLEM_BLANK : CAIRO_DOCK_EMBLEM_CHARGE), CAIRO_DOCK_EMBLEM_MIDDLE);
 
162
                        if (! myData.bOnBattery)
186
163
                                CD_APPLET_DRAW_EMBLEM_ON_MY_ICON (myData.pEmblem);
187
164
                }
188
165
                else if (myConfig.iDisplayType == CD_POWERMANAGER_ICONS)
189
 
                        cd_powermanager_draw_icon_with_effect (myData.on_battery);
 
166
                        cd_powermanager_draw_icon_with_effect (myData.bOnBattery);
190
167
                
191
 
                if (!myData.on_battery && myData.battery_charge < 100)
192
 
                        myData.alerted = FALSE; //We will alert when battery charge reach 100%
193
 
                if (myData.on_battery)
 
168
                if (!myData.bOnBattery && myData.iPercentage < 100)
 
169
                        myData.bAlerted = FALSE; //We will alert when battery charge reach 100%
 
170
                if (myData.bOnBattery)
194
171
                {
195
 
                        if (myData.battery_charge > myConfig.lowBatteryValue)
196
 
                                myData.alerted = FALSE; //We will alert when battery charge is under myConfig.lowBatteryValue
 
172
                        if (myData.iPercentage > myConfig.lowBatteryValue)
 
173
                                myData.bAlerted = FALSE; //We will alert when battery charge is under myConfig.lowBatteryValue
197
174
                        
198
 
                        if (myData.battery_charge > 4)
 
175
                        if (myData.iPercentage > 4)
199
176
                                myData.bCritical = FALSE; //We will alert when battery charge is critical (under 4%)
200
177
                }
201
178
                
202
 
                myData.previous_battery_charge = -1;
203
 
                myData.previous_battery_time = -1;
 
179
                myData.iPrevPercentage = -1;
 
180
                myData.iPrevTime = -1;
204
181
                update_icon();
205
182
 
206
183
        }