/*!
 * We have three functions her that notify us about the changes in the charging
 * state. We use all of the three slots the same way, but we keep them
 * separately so we can actually see why do we need to recalculate the charging
 * info.
 */
void
BatteryBusinessLogic::batteryChargerEvent (
        MeeGo::QmBattery::ChargerType type)
{
    Q_UNUSED (type);

    SYS_DEBUG ("");
    recalculateChargingInfo ();
}
void 
BatteryBusinessLogic::batteryStateChanged (
        MeeGo::QmBattery::BatteryState batteryState)
{
    Q_UNUSED (batteryState);
    
    SYS_DEBUG ("");
    recalculateChargingInfo ();
}
/*
 * This function does the initialization and signal connection to QmBattery and
 * QmDeviceMode, and emits all the signals with the current values...
 *
 * FIXME: This function should be called realize() or something...
 */
void
BatteryBusinessLogic::requestValues ()
{
    DEBUG_CLOCK_START;
    if (m_initialized)
        return;

    m_initialized = true;

    #ifdef HAVE_QMSYSTEM
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (
        m_battery, SIGNAL(chargerEvent(MeeGo::QmBattery::ChargerType)),
        this, SLOT(batteryChargerEvent(MeeGo::QmBattery::ChargerType)));
    connect (
        m_battery, SIGNAL(chargingStateChanged(MeeGo::QmBattery::ChargingState)),
        this, SLOT(chargingStateChanged(MeeGo::QmBattery::ChargingState)));
    connect (
        m_battery, SIGNAL(batteryStateChanged(MeeGo::QmBattery::BatteryState)),
        this, SLOT (batteryStateChanged(MeeGo::QmBattery::BatteryState)));

    /*
     * We have two signals showing that the battery energy level has been
     * changed. We listen both of these signals.
     */
    SYS_DEBUG ("Connecting to the signals of the QmBattery class");
    connect (m_battery, SIGNAL (batteryRemainingCapacityChanged (int, int)),
            this, SLOT (batteryRemCapacityChanged (int, int)));


    // batteryBarValueReceived also emitted by chargingStateChanged ^^^
    // FIXME: Why?

    /*
     * Init the power-save-mode value, and connect to QmSystem2 signal
     */
    m_PowerSaveMode = (m_devicemode->getPSMState () ==
                       MeeGo::QmDeviceMode::PSMStateOn);
    connect (m_devicemode,
             SIGNAL (devicePSMStateChanged (MeeGo::QmDeviceMode::PSMState)),
             this, SLOT (PSMStateChanged (MeeGo::QmDeviceMode::PSMState)));
    #else
    /*
     * FIXME: To create an implementation without the QmSystem
     */
    #endif

    recalculateChargingInfo ();
    DEBUG_CLOCK_END("Data request");
}