![]() |
Home · All Namespaces · All Classes |
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of systemui. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 #include "batterybusinesslogic.h" 00020 00021 #include <MLocale> 00022 #include <QTimer> 00023 00024 #include <MNotification> 00025 #include <MFeedback> 00026 00027 /* 00028 * TODO List 00029 * -) Connect sounds with notifications 00030 */ 00031 00032 namespace { 00033 const int LowBatteryActiveInterval = 30 * 60 * 1000; //30 mins 00034 const int LowBatteryInactiveInterval = 2 * 60 * 60 * 1000; //2 hours 00035 const int ChargingAnimationRateUSB = 800; // 800 ms 00036 const int ChargingAnimationRateWall = 400; // 400 ms 00037 } 00038 00039 /****************************************************************************** 00040 * Methods for the LowBatteryNotifier class. 00041 */ 00042 LowBatteryNotifier::LowBatteryNotifier ( 00043 QObject *parent) : 00044 QObject (parent), 00045 m_Timer (new QTimer (this)), 00046 m_Sleep (false) 00047 { 00048 m_ActiveInterval = LowBatteryActiveInterval; 00049 m_InactiveInterval = LowBatteryInactiveInterval; 00050 m_Time.start (); 00051 00052 #ifdef HAVE_QMSYSTEM 00053 m_Display = new MeeGo::QmDisplayState; 00054 m_Sleep = m_Display->get () == MeeGo::QmDisplayState::Off; 00055 connect (m_Display, 00056 SIGNAL (displayStateChanged (MeeGo::QmDisplayState::DisplayState)), 00057 this, 00058 SLOT (displayStateChanged (MeeGo::QmDisplayState::DisplayState))); 00059 #endif 00060 00061 connect (m_Timer, SIGNAL (timeout ()), 00062 this, SLOT (showLowBatteryNotification ())); 00063 } 00064 00065 LowBatteryNotifier::~LowBatteryNotifier () 00066 { 00067 } 00068 00069 00070 void 00071 LowBatteryNotifier::showLowBatteryNotification () 00072 { 00073 emit lowBatteryAlert (); 00074 00075 m_Time.start (); //restart time 00076 00077 #ifdef HAVE_QMSYSTEM 00078 switch (m_Display->get ()) { 00079 case MeeGo::QmDisplayState::On: 00080 case MeeGo::QmDisplayState::Dimmed: 00081 m_Sleep = false; 00082 m_Timer->start (m_ActiveInterval); 00083 break; 00084 00085 case MeeGo::QmDisplayState::Off: 00086 m_Sleep = true; 00087 m_Timer->start (m_InactiveInterval); 00088 break; 00089 00090 default: 00091 break; 00092 } 00093 #endif 00094 } 00095 00096 #ifdef HAVE_QMSYSTEM 00097 void 00098 LowBatteryNotifier::displayStateChanged ( 00099 MeeGo::QmDisplayState::DisplayState state) 00100 { 00101 switch (state) { 00102 case MeeGo::QmDisplayState::On: 00103 if (!m_Sleep) 00104 break; 00105 if (m_Time.elapsed () < m_ActiveInterval) 00106 m_Timer->setInterval (m_ActiveInterval - m_Time.elapsed ()); 00107 else 00108 showLowBatteryNotification (); 00109 m_Sleep = false; 00110 break; 00111 00112 case MeeGo::QmDisplayState::Dimmed: 00113 m_Sleep = false; 00114 break; 00115 00116 case MeeGo::QmDisplayState::Off: 00117 m_Timer->setInterval (m_InactiveInterval - m_Time.elapsed ()); 00118 m_Sleep = true; 00119 break; 00120 00121 default: 00122 // FIXME: what about the other states [Unknown]? 00123 break; 00124 } 00125 } 00126 #endif 00127 00128 /****************************************************************************** 00129 * Methods for the BatteryBusinessLogic class. 00130 */ 00131 BatteryBusinessLogic::BatteryBusinessLogic ( 00132 QObject *parent) : 00133 QObject (parent), 00134 m_LowBatteryNotifier (0), 00135 m_notification (0) 00136 #ifdef HAVE_QMSYSTEM 00137 ,m_Battery (new MeeGo::QmBattery), 00138 m_DeviceMode (new MeeGo::QmDeviceMode), 00139 m_Led (new MeeGo::QmLED), 00140 m_ChargerType (MeeGo::QmBattery::Unknown) 00141 #endif 00142 { 00143 #ifdef HAVE_QMSYSTEM 00144 /* connect to QmSystem signals */ 00145 connect (m_Battery, 00146 SIGNAL (batteryStateChanged (MeeGo::QmBattery::BatteryState)), 00147 this, 00148 SLOT (batteryStateChanged (MeeGo::QmBattery::BatteryState))); 00149 connect (m_Battery, 00150 SIGNAL (chargingStateChanged (MeeGo::QmBattery::ChargingState)), 00151 this, 00152 SLOT (chargingStateChanged (MeeGo::QmBattery::ChargingState))); 00153 connect (m_Battery, 00154 SIGNAL (chargerEvent (MeeGo::QmBattery::ChargerType)), 00155 this, 00156 SLOT (batteryChargerEvent (MeeGo::QmBattery::ChargerType))); 00157 00158 connect (m_DeviceMode, 00159 SIGNAL (devicePSMStateChanged (MeeGo::QmDeviceMode::PSMState)), 00160 this, 00161 SLOT (devicePSMStateChanged (MeeGo::QmDeviceMode::PSMState))); 00162 #endif 00163 00164 // Init battery values delayed... 00165 initBattery (); 00166 } 00167 00168 00169 BatteryBusinessLogic::~BatteryBusinessLogic () 00170 { 00171 #ifdef HAVE_QMSYSTEM 00172 delete m_Battery; 00173 m_Battery = NULL; 00174 00175 delete m_DeviceMode; 00176 m_DeviceMode = NULL; 00177 00178 delete m_Led; 00179 m_Led = NULL; 00180 #endif 00181 } 00182 00183 // This method should be called also when the device is returned from sleep 00184 // mode 00185 void 00186 BatteryBusinessLogic::initBattery () 00187 { 00188 #ifdef HAVE_QMSYSTEM 00189 //init the charging status 00190 chargingStateChanged (m_Battery->getChargingState ()); 00191 00192 //init the battery level 00193 batteryStateChanged (m_Battery->getBatteryState ()); 00194 #endif 00195 } 00196 00200 void 00201 BatteryBusinessLogic::lowBatteryAlert () 00202 { 00203 sendNotification (NotificationLowBattery); 00204 } 00205 00206 #ifdef HAVE_QMSYSTEM 00207 void 00208 BatteryBusinessLogic::chargingStateChanged ( 00209 MeeGo::QmBattery::ChargingState state) 00210 { 00211 switch (state) { 00212 case MeeGo::QmBattery::StateCharging: 00213 if (m_Battery->getChargerType () == MeeGo::QmBattery::USB_100mA) 00214 { 00215 sendNotification (NotificationNoEnoughPower); 00216 } 00217 else 00218 { 00219 /* 00220 * The low battery notifications should not be sent 00221 * when the battery is actually charging. 00222 */ 00223 if (m_LowBatteryNotifier != 0) 00224 { 00225 delete m_LowBatteryNotifier; 00226 m_LowBatteryNotifier = 0; 00227 } 00228 00229 sendNotification (NotificationCharging); 00230 } 00231 break; 00232 00233 case MeeGo::QmBattery::StateNotCharging: 00234 utiliseLED (false, QString ("PatternBatteryCharging")); 00235 break; 00236 00237 case MeeGo::QmBattery::StateChargingFailed: 00238 sendNotification (NotificationChargingNotStarted); 00239 break; 00240 } 00241 } 00242 00243 void 00244 BatteryBusinessLogic::batteryStateChanged ( 00245 MeeGo::QmBattery::BatteryState state) 00246 { 00247 switch (state) { 00248 case MeeGo::QmBattery::StateFull: 00249 sendNotification (NotificationChargingComplete); 00250 break; 00251 00252 case MeeGo::QmBattery::StateOK: 00253 /* no-operation here... */ 00254 break; 00255 00256 case MeeGo::QmBattery::StateLow: 00257 if (m_Battery->getChargingState () != MeeGo::QmBattery::StateCharging) { 00258 if (m_LowBatteryNotifier == 0) { 00259 m_LowBatteryNotifier = new LowBatteryNotifier (); 00260 connect (m_LowBatteryNotifier, SIGNAL(lowBatteryAlert()), 00261 this, SLOT(lowBatteryAlert())); 00262 } 00263 00264 m_LowBatteryNotifier->showLowBatteryNotification (); 00265 } 00266 break; 00267 00268 case MeeGo::QmBattery::StateEmpty: 00269 sendNotification (NotificationRechargeBattery); 00270 break; 00271 00272 case MeeGo::QmBattery::StateError: 00273 break; 00274 } 00275 } 00276 00277 void 00278 BatteryBusinessLogic::batteryChargerEvent ( 00279 MeeGo::QmBattery::ChargerType type) 00280 { 00281 switch (type) { 00282 case MeeGo::QmBattery::None: 00283 /* 00284 * After the user plugs out the charger from the device, this system 00285 * banner is displayed to remind the users to unplug charger from 00286 * the power supply for conserving energy. Remove charger 00287 * notification should not be shown in case if USB cable is used for 00288 * charging the device. 00289 */ 00290 if (m_ChargerType == MeeGo::QmBattery::Wall) 00291 sendNotification (NotificationRemoveCharger); 00292 break; 00293 00294 case MeeGo::QmBattery::Wall: 00295 // Wall charger 00296 break; 00297 00298 case MeeGo::QmBattery::USB_500mA: 00299 // USB with 500mA output 00300 break; 00301 00302 case MeeGo::QmBattery::USB_100mA: 00303 // USB with 100mA output 00304 break; 00305 00306 default: 00307 break; 00308 } 00309 00310 m_ChargerType = type; 00311 } 00312 00313 void 00314 BatteryBusinessLogic::devicePSMStateChanged ( 00315 MeeGo::QmDeviceMode::PSMState PSMState) 00316 { 00317 if (PSMState == MeeGo::QmDeviceMode::PSMStateOff) 00318 { 00319 sendNotification (NotificationExitingPSM); 00320 } 00321 else if (PSMState == MeeGo::QmDeviceMode::PSMStateOn) 00322 { 00323 sendNotification (NotificationEnteringPSM); 00324 } 00325 } 00326 #endif 00327 00328 void 00329 BatteryBusinessLogic::utiliseLED ( 00330 bool activate, 00331 const QString &pattern) 00332 { 00333 #ifdef HAVE_QMSYSTEM 00334 if (activate) 00335 m_Led->activate (pattern); 00336 else 00337 m_Led->deactivate (pattern); 00338 #endif 00339 } 00340 00341 void 00342 BatteryBusinessLogic::sendNotification ( 00343 BatteryBusinessLogic::NotificationID id) 00344 { 00345 switch (id) { 00346 case NotificationCharging: 00347 utiliseLED (true, QString ("PatternBatteryCharging")); 00348 sendNotification ( 00349 "x-nokia.battery", 00350 //% "Charging" 00351 qtTrId ("qtn_ener_charging"), 00352 chargingImageId ()); 00353 break; 00354 00355 case NotificationChargingComplete: 00356 utiliseLED (true, QString ("PatternBatteryFull")); 00357 sendNotification ( 00358 "x-nokia.battery.chargingcomplete", 00359 //% "Charging complete" 00360 qtTrId ("qtn_ener_charcomp")); 00361 break; 00362 00363 case NotificationRemoveCharger: 00364 sendNotification ( 00365 "x-nokia.battery.removecharger", 00366 //% "Disconnect charger from power supply to save energy" 00367 qtTrId ("qtn_ener_remcha")); 00368 break; 00369 00370 case NotificationChargingNotStarted: 00371 utiliseLED (false, QString ("PatternBatteryCharging")); 00372 sendNotification ( 00373 "x-nokia.battery.chargingnotstarted", 00374 //% "Charging not started. Replace charger." 00375 qtTrId ("qtn_ener_repcharger")); 00376 break; 00377 00378 case NotificationRechargeBattery: 00379 sendNotification ( 00380 "x-nokia.battery.recharge", 00381 //% "Recharge battery" 00382 qtTrId ("qtn_ener_rebatt")); 00383 break; 00384 00385 case NotificationEnteringPSM: 00386 sendNotification ( 00387 "x-nokia.battery.enterpsm", 00388 //% "Entering power save mode" 00389 qtTrId ("qtn_ener_ent_psnote")); 00390 break; 00391 00392 case NotificationExitingPSM: 00393 sendNotification ( 00394 "x-nokia.battery.exitpsm", 00395 //% "Exiting power save mode" 00396 qtTrId ("qtn_ener_exit_psnote")); 00397 break; 00398 00399 case NotificationLowBattery: 00400 sendNotification ( 00401 "x-nokia.battery.lowbattery", 00402 //% "Low battery" 00403 qtTrId ("qtn_ener_lowbatt")); 00404 break; 00405 00406 case NotificationNoEnoughPower: 00407 sendNotification ( 00408 "x-nokia.battery.notenoughpower", 00409 //% "Not enough power to charge" 00410 qtTrId ("qtn_ener_nopowcharge"), 00411 "icon-m-energy-management-insufficient-power"); 00412 break; 00413 } 00414 } 00415 00416 void 00417 BatteryBusinessLogic::sendNotification ( 00418 const QString &eventType, 00419 const QString &text, 00420 const QString &icon) 00421 { 00422 if (m_notification != 0) { 00423 m_notification->remove (); 00424 delete m_notification; 00425 m_notification = 0; 00426 } 00427 00428 /* 00429 * We send this signal before the actual notification so it will arrive as 00430 * soon as possible. 00431 */ 00432 emit notificationSent (eventType, text, icon); 00433 00434 m_notification = new MNotification (eventType, "", text); 00435 if (!icon.isEmpty()) 00436 m_notification->setImage (icon); 00437 m_notification->publish (); 00438 } 00439 00440 QString 00441 BatteryBusinessLogic::chargingImageId () 00442 { 00443 #ifdef HAVE_QMSYSTEM 00444 int percentage = m_Battery->getRemainingCapacityPct (); 00445 00446 if (percentage >= 84) 00447 return QString ("icon-m-energy-management-charging8"); 00448 else if (percentage >= 73) 00449 return QString ("icon-m-energy-management-charging7"); 00450 else if (percentage >= 62) 00451 return QString ("icon-m-energy-management-charging6"); 00452 else if (percentage >= 51) 00453 return QString ("icon-m-energy-management-charging5"); 00454 else if (percentage >= 39) 00455 return QString ("icon-m-energy-management-charging4"); 00456 else if (percentage >= 28) 00457 return QString ("icon-m-energy-management-charging3"); 00458 else if (percentage >= 17) 00459 return QString ("icon-m-energy-management-charging2"); 00460 else if (percentage >= 5) 00461 return QString ("icon-m-energy-management-charging1"); 00462 #endif 00463 return QString ("icon-m-energy-management-charging-low"); 00464 } 00465
| Copyright © 2010 Nokia Corporation | Generated on Wed Nov 10 16:04:51 2010 Doxygen 1.6.1 |
MeeGo Touch |
