examples/QtQuick/phoneutil/batteryinfoprivate.cpp

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation
00006 **
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** You may use this file under the terms of the BSD license as follows:
00010 **
00011 ** "Redistribution and use in source and binary forms, with or without
00012 ** modification, are permitted provided that the following conditions are
00013 ** met:
00014 **   * Redistributions of source code must retain the above copyright
00015 **     notice, this list of conditions and the following disclaimer.
00016 **   * Redistributions in binary form must reproduce the above copyright
00017 **     notice, this list of conditions and the following disclaimer in
00018 **     the documentation and/or other materials provided with the
00019 **     distribution.
00020 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00021 **     the names of its contributors may be used to endorse or promote
00022 **     products derived from this software without specific prior written
00023 **     permission.
00024 **
00025 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00036 ** $QT_END_LICENSE$
00037 **
00038 ****************************************************************************/
00039 #include "batteryinfoprivate.h"
00040 #include "batteryinfowrapper.h"
00041 
00046  BatteryInfoPrivate::BatteryInfoPrivate(BatteryInfoWrapper *wrapper)
00047  : CActive(CActive::EPriorityStandard), q_ptr(wrapper),
00048  iTelephony(NULL), iBatteryInfoV1Pckg(iBatteryInfoV1)
00049  {
00050     CActiveScheduler::Add(this);
00051  }
00052 
00056  void BatteryInfoPrivate::RequestBatteryInfo()
00057  {
00058     ASSERT(!IsActive());
00059     int err = CreateCTelephony();
00060     if ( err )
00061         {
00062         emit (q_ptr->errorOccured(err));        
00063         }
00064     else
00065         {        
00066         iTelephony->GetBatteryInfo(iStatus, iBatteryInfoV1Pckg);
00067         SetActive();
00068         }
00069  }
00070 
00076  int BatteryInfoPrivate::CreateCTelephony()
00077  {
00078     int err = 0;
00079     if( !iTelephony )
00080         {
00081         TRAP(err, iTelephony = CTelephony::NewL());
00082         }
00083     return err;
00084  }
00085 
00086 
00090  void BatteryInfoPrivate::RunL()
00091  {
00092     CTelephony::TBatteryInfoV1 BatteryInfo = iBatteryInfoV1;
00093 
00094     if( iStatus == KErrNone ) {
00095         // Registering for change in the battery strength
00096         iTelephony->NotifyChange(iStatus, CTelephony::EBatteryInfoChange, iBatteryInfoV1Pckg );
00097         QString text = QString::number(iBatteryInfoV1.iChargeLevel);
00098         // Emitting the signal with the battery strength
00099         emit (q_ptr->batteryInfoUpdated(text));
00100     } else {
00101         // Checking the type of error
00102         CTelephony::TBatteryStatus batteryStatus = BatteryInfo.iStatus;
00103         switch (batteryStatus)
00104         {
00105             case CTelephony::EPowerStatusUnknown:
00106                 emit (q_ptr->errorOccured(CTelephony::EPowerStatusUnknown));
00107                 break;
00108             case CTelephony::EPoweredByBattery:
00109                 emit (q_ptr->errorOccured(CTelephony::EPoweredByBattery));
00110                 break;
00111             case CTelephony::EBatteryConnectedButExternallyPowered:
00112                 emit (q_ptr->errorOccured(CTelephony::EBatteryConnectedButExternallyPowered));
00113                 break;
00114             case CTelephony::ENoBatteryConnected:
00115                 emit (q_ptr->errorOccured(CTelephony::ENoBatteryConnected));
00116                 break;
00117             case CTelephony::EPowerFault:
00118                 emit (q_ptr->errorOccured(CTelephony::EPowerFault));
00119                 break;
00120             default:
00121                 emit (q_ptr->errorOccured(iStatus.Int()));
00122         }
00123       }
00124 }
00125 
00129 void BatteryInfoPrivate::DoCancel()
00130 {
00131     // Cancels an outstanding asynchronous request.
00132     iTelephony->CancelAsync(CTelephony::EBatteryInfoChangeCancel);
00133 }

Generated by  doxygen 1.6.2