ginebra2/SystemDeviceImpl.cpp
changeset 3 0954f5dd2cd0
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 *
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 * This file implements the SystemDeviceImpl class.
       
    20 */
       
    21 #include <QList>
       
    22 #include <QString>
       
    23 #include "SystemDeviceImpl.h"
       
    24 #include "Utilities.h"
       
    25 
       
    26 namespace GVA {
       
    27 
       
    28 SystemDeviceImpl::SystemDeviceImpl()
       
    29 {
       
    30     // create Qt Mobility API objects for device info
       
    31     m_deviceInfo = new QSystemDeviceInfo(this);
       
    32 
       
    33     // When the m_deviceInfo signals battery level changed,
       
    34     // DeviceDelegate emits batteryLevelChanged
       
    35     safe_connect(m_deviceInfo, SIGNAL(batteryLevelChanged(int)),
       
    36                  this, SIGNAL(batteryLevelChanged(int)));
       
    37 
       
    38     // set current charging state then keep it up to date with signal handler
       
    39     m_batteryCharging = (m_deviceInfo->currentPowerState() ==
       
    40         QSystemDeviceInfo::WallPowerChargingBattery) ? true : false;
       
    41     safe_connect(m_deviceInfo, SIGNAL(powerStateChanged(QSystemDeviceInfo::PowerState)),
       
    42                  this, SLOT(handlePowerStateChanged(QSystemDeviceInfo::PowerState)));
       
    43 }
       
    44 
       
    45 SystemDeviceImpl::~SystemDeviceImpl()
       
    46 {
       
    47     // clean up
       
    48     delete m_deviceInfo;
       
    49 }
       
    50 
       
    51 //! Get the current battery level.
       
    52 int SystemDeviceImpl::getBatteryLevel() const
       
    53 {
       
    54     return (m_deviceInfo->batteryLevel());
       
    55 }
       
    56 
       
    57 //! Handles the powerStateChanged signal from system device info.
       
    58 /*!
       
    59   \param state new power state
       
    60 */
       
    61 void SystemDeviceImpl::handlePowerStateChanged(QSystemDeviceInfo::PowerState state)
       
    62 {
       
    63     bool batteryCharging =
       
    64         (state == QSystemDeviceInfo::WallPowerChargingBattery) ? true : false;
       
    65 
       
    66     if (batteryCharging != m_batteryCharging) {
       
    67         m_batteryCharging = batteryCharging;
       
    68         //qDebug() << "DeviceDelegate: new charging = " << m_batteryCharging;
       
    69         // emit battery level - subscriber will get charging state if desired
       
    70         emit batteryLevelChanged(m_deviceInfo->batteryLevel());
       
    71     }
       
    72 }
       
    73 
       
    74 } // GVA
       
    75