| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 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. |
| 11 |
* |
| 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/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <cairo-dock.h> |
| 22 |
|
| 23 |
#include "powermanager-struct.h" |
| 24 |
#include "powermanager-config.h" |
| 25 |
#include "powermanager-common.h" |
| 26 |
#include "powermanager-upower.h" |
| 27 |
#include "powermanager-menu-functions.h" |
| 28 |
#include "powermanager-draw.h" |
| 29 |
#include "powermanager-init.h" |
| 30 |
|
| 31 |
|
| 32 |
CD_APPLET_DEFINITION (N_("PowerManager"), |
| 33 |
2, 3, 0, |
| 34 |
CAIRO_DOCK_CATEGORY_APPLET_SYSTEM, |
| 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 |
|
| 40 |
|
| 41 |
CD_APPLET_INIT_BEGIN |
| 42 |
if (myDesklet) |
| 43 |
{ |
| 44 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 45 |
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET; |
| 46 |
} |
| 47 |
|
| 48 |
///_set_data_renderer (myApplet); |
| 49 |
|
| 50 |
cd_powermanager_start (); |
| 51 |
|
| 52 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 53 |
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 54 |
CD_APPLET_INIT_END |
| 55 |
|
| 56 |
|
| 57 |
CD_APPLET_STOP_BEGIN |
| 58 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 59 |
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 60 |
|
| 61 |
gldi_task_discard (myData.pTask); |
| 62 |
|
| 63 |
// stop UPower monitoring |
| 64 |
cd_upower_stop (); |
| 65 |
|
| 66 |
// stop ACPI check loop |
| 67 |
if (myData.checkLoop != 0) |
| 68 |
{ |
| 69 |
g_source_remove (myData.checkLoop); |
| 70 |
} |
| 71 |
CD_APPLET_STOP_END |
| 72 |
|
| 73 |
|
| 74 |
CD_APPLET_RELOAD_BEGIN |
| 75 |
CD_APPLET_REMOVE_OVERLAY_ON_MY_ICON (CAIRO_OVERLAY_MIDDLE); |
| 76 |
|
| 77 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 78 |
{ |
| 79 |
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. |
| 80 |
{ |
| 81 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 82 |
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET; |
| 83 |
} |
| 84 |
|
| 85 |
// handle options that may have changed |
| 86 |
///_set_data_renderer (myApplet); |
| 87 |
|
| 88 |
cd_powermanager_change_loop_frequency (myConfig.iCheckInterval); |
| 89 |
|
| 90 |
if (myDock) |
| 91 |
{ |
| 92 |
if (myConfig.bHideNotOnBattery && ! myData.bOnBattery) |
| 93 |
{ // hide the icon when not on battery and if needed |
| 94 |
gldi_icon_detach (myIcon); |
| 95 |
myData.bIsHidden = TRUE; |
| 96 |
} |
| 97 |
else if (myData.bIsHidden) |
| 98 |
{ |
| 99 |
gldi_icon_insert_in_container (myIcon, myContainer, CAIRO_DOCK_ANIMATE_ICON); |
| 100 |
myData.bIsHidden = FALSE; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
// force the update of the icon |
| 105 |
myData.bPrevOnBattery = ! myData.bOnBattery; |
| 106 |
myData.iPrevPercentage = -1; |
| 107 |
myData.iPrevTime = -1; |
| 108 |
CD_APPLET_REMOVE_MY_DATA_RENDERER; |
| 109 |
update_icon(); |
| 110 |
} |
| 111 |
else |
| 112 |
{ |
| 113 |
if (myConfig.iDisplayType == CD_POWERMANAGER_GRAPH) |
| 114 |
CD_APPLET_SET_MY_DATA_RENDERER_HISTORY_TO_MAX; |
| 115 |
if (myData.bBatteryPresent && ! myData.bOnBattery) |
| 116 |
CD_APPLET_ADD_OVERLAY_ON_MY_ICON (myConfig.cEmblemIconName ? myConfig.cEmblemIconName : MY_APPLET_SHARE_DATA_DIR"/charge.svg", CAIRO_OVERLAY_MIDDLE); |
| 117 |
} |
| 118 |
|
| 119 |
//\_______________ On redessine notre icone. |
| 120 |
/**if (myData.cBatteryStateFilePath || myData.pBatteryDeviceList != NULL) |
| 121 |
{ |
| 122 |
if (myConfig.iDisplayType == CD_POWERMANAGER_GAUGE || myConfig.iDisplayType == CD_POWERMANAGER_GRAPH) // On recharge la jauge. |
| 123 |
{ |
| 124 |
double fPercent = (double) myData.iPercentage / 100.; |
| 125 |
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fPercent); |
| 126 |
} |
| 127 |
else if (myConfig.iDisplayType == CD_POWERMANAGER_ICONS) |
| 128 |
{ |
| 129 |
cd_powermanager_draw_icon_with_effect (myData.bOnBattery); |
| 130 |
} |
| 131 |
|
| 132 |
// re-set the overlay if on sector |
| 133 |
if (! myData.bOnBattery) |
| 134 |
CD_APPLET_ADD_OVERLAY_ON_MY_ICON (myConfig.cEmblemIconName ? myConfig.cEmblemIconName : MY_APPLET_SHARE_DATA_DIR"/charge.svg", CAIRO_OVERLAY_MIDDLE); |
| 135 |
|
| 136 |
myData.iPrevPercentage = -1; |
| 137 |
myData.iPrevTime = -1; |
| 138 |
update_icon(); |
| 139 |
} |
| 140 |
else // sinon on signale par l'icone appropriee qu'aucune donnee n'est accessible. |
| 141 |
CD_APPLET_SET_IMAGE_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/sector.svg");*/ |
| 142 |
CD_APPLET_RELOAD_END |