javauis/lcdui_akn/lcdui/src/CMIDCallIndicator.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
parent 14 04becd199f91
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 //using CTelephony class
       
    21 #include <etel3rdparty.h>
       
    22 #include "CMIDCallIndicator.h"
       
    23 //using CMIDCanvas class - needed for CMIDNetworkIndicator
       
    24 #include "CMIDCanvas.h"
       
    25 //using CMIDNetworkIndicator class - iNetworkIndicator
       
    26 #include "CMIDNetworkIndicator.h"
       
    27 #include <j2me/jdebug.h>
       
    28 
       
    29 /**
       
    30  * Constructor. Defines the priority for this active object and adds him to AS.
       
    31  */
       
    32 CMIDCallIndicator::CMIDCallIndicator(
       
    33     CMIDNetworkIndicator *aNetworkIndicator):
       
    34         CActive(EPriorityStandard)
       
    35         , iNetworkIndicator(aNetworkIndicator)
       
    36         , iLineStatusPckg(iLineStatus)
       
    37 {
       
    38     iNetworkIndicator->SetCallIndicator(this);
       
    39     CActiveScheduler::Add(this);
       
    40 }
       
    41 
       
    42 /**
       
    43  * Two-phased constructor.
       
    44  */
       
    45 CMIDCallIndicator* CMIDCallIndicator::NewL(
       
    46     CMIDNetworkIndicator *aNetworkIndicator)
       
    47 {
       
    48     DEBUG(">>> CMIDCallIndicator::NewL");
       
    49     CMIDCallIndicator* self = CMIDCallIndicator::NewLC(aNetworkIndicator);
       
    50     CleanupStack::Pop(self);
       
    51     DEBUG("<<< CMIDCallIndicator::NewL");
       
    52     return self;
       
    53 }
       
    54 
       
    55 /**
       
    56  * Two-phased constructor.
       
    57  */
       
    58 CMIDCallIndicator* CMIDCallIndicator::NewLC(
       
    59     CMIDNetworkIndicator *aNetworkIndicator)
       
    60 {
       
    61     CMIDCallIndicator* self = new(ELeave) CMIDCallIndicator(
       
    62         aNetworkIndicator);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     return self;
       
    66 }
       
    67 
       
    68 /**
       
    69  * 2nd phase constructor.
       
    70  */
       
    71 void CMIDCallIndicator::ConstructL()
       
    72 {
       
    73     iTelephony = CTelephony::NewL();
       
    74     Init();
       
    75 }
       
    76 
       
    77 /**
       
    78  * Destructor.
       
    79  */
       
    80 CMIDCallIndicator::~CMIDCallIndicator()
       
    81 {
       
    82     DEBUG(">>> CMIDCallIndicator::~CMIDCallIndicator");
       
    83     Cancel();
       
    84     delete iTelephony;
       
    85     DEBUG("<<< CMIDCallIndicator::~CMIDCallIndicator");
       
    86 }
       
    87 
       
    88 /**
       
    89  * Activates the AO and register for notification by the CTelephony
       
    90  */
       
    91 void CMIDCallIndicator::SetActiveLocal()
       
    92 {
       
    93     // XXX DEBUG(">>> CMIDCallIndicator::SetActiveLocal");
       
    94     if (!this->IsActive())
       
    95     {
       
    96         iTelephony->NotifyChange(iStatus,
       
    97                                  CTelephony::EVoiceLineStatusChange,
       
    98                                  iLineStatusPckg);
       
    99         SetActive();
       
   100     }
       
   101     // XXX DEBUG("<<< CMIDCallIndicator::SetActiveLocal");
       
   102 }
       
   103 
       
   104 /**
       
   105  * Finds out if call is ongoing when opening canvas and sets members.
       
   106  */
       
   107 void CMIDCallIndicator::Init()
       
   108 {
       
   109     CTelephony::TPhoneLine line = CTelephony::EVoiceLine;
       
   110 
       
   111     iTelephony->GetLineStatus(line, iLineStatusPckg);
       
   112 
       
   113     if (CallInProgress(iLineStatus.iStatus))
       
   114     {
       
   115         // Call in progress, show call indicator.
       
   116         TRAPD(ignoreError,
       
   117               iNetworkIndicator->CreateNetworkResourceL(EBearerInfoCSD, 0));
       
   118         if (ignoreError != KErrNone)
       
   119         { // Leave is ignored. It is not so important to pass leave only
       
   120             // because the icon wasnt created.
       
   121             DEBUG_INT("CMIDCallIndicator::SetActiveLocal - Exception from CreateNetworkResourceL. Error = %d", ignoreError);
       
   122         }
       
   123         iNetworkIndicator->Repaint();
       
   124         iView = ETrue;
       
   125     }
       
   126     else
       
   127     {
       
   128         iLineStatus.iStatus = CTelephony::EStatusUnknown;
       
   129         iView = EFalse;
       
   130     }
       
   131 }
       
   132 
       
   133 /*
       
   134 * Check the call status. If there is call established
       
   135 * return true orwise return false.
       
   136 *
       
   137 * @param   aCallStatus     call status.
       
   138 * @return ETrue if calling else EFalse.
       
   139 */
       
   140 TBool CMIDCallIndicator::CallInProgress(CTelephony::TCallStatus aCallStatus)
       
   141 {
       
   142     switch (aCallStatus)
       
   143     {
       
   144     case CTelephony::EStatusDialling:
       
   145     case CTelephony::EStatusRinging:
       
   146     case CTelephony::EStatusAnswering:
       
   147     case CTelephony::EStatusConnecting:
       
   148     case CTelephony::EStatusConnected:
       
   149     case CTelephony::EStatusReconnectPending:
       
   150     case CTelephony::EStatusDisconnecting:
       
   151     case CTelephony::EStatusHold:
       
   152     case CTelephony::EStatusTransferring:
       
   153     case CTelephony::EStatusTransferAlerting:
       
   154     {
       
   155         return ETrue; // call is in progress
       
   156     }
       
   157     case CTelephony::EStatusIdle:
       
   158     case CTelephony::EStatusUnknown:
       
   159     default:
       
   160     {
       
   161         return EFalse; // no active call
       
   162     }
       
   163     }
       
   164 }
       
   165 
       
   166 /**
       
   167  * Returns the call activity.
       
   168  *
       
   169  * @return Member iView. ETrue when active call indicator is shown = call
       
   170  *         is ongoing and EFalse otherwise.
       
   171  */
       
   172 TBool CMIDCallIndicator::GetCallActivity()
       
   173 {
       
   174     return iView;
       
   175 }
       
   176 
       
   177 /**
       
   178  * From CActive.
       
   179  */
       
   180 void CMIDCallIndicator::RunL()
       
   181 {
       
   182     DEBUG(">>> CMIDCallIndicator::RunL");
       
   183 
       
   184     TBool callOn = CallInProgress(iLineStatus.iStatus);
       
   185 
       
   186     if (!iView && callOn)
       
   187     {
       
   188         // Draw active call indicator because the call just started.
       
   189         // Create the network resource.
       
   190         // XXX    DEBUG("CMIDCallIndicator::RunL() -Newcall");
       
   191         TRAPD(ignoreError,
       
   192               iNetworkIndicator->CreateNetworkResourceL(EBearerInfoCSD, 0));
       
   193         if (ignoreError != KErrNone)
       
   194         { // Leave is ignored. It is not so important to pass leave only
       
   195             // because the icon wasnt created.
       
   196             DEBUG_INT("CMIDCallIndicator::SetActiveLocal - Exception from CreateNetworkResourceL. Error = %d", ignoreError);
       
   197         }
       
   198         iView = ETrue;
       
   199         // Repaints the indicator
       
   200         iNetworkIndicator->Repaint(ETrue);
       
   201     }
       
   202     else if (iView && !callOn)
       
   203     {
       
   204         // XXX    DEBUG("CMIDCallIndicator::RunL() -Idle/unknown - iView=ETrue >>>");
       
   205         // Call just ended. Clean the bitmap. Fill it with network indicator
       
   206         // stored in temp bitmaps only if the network connection is active.
       
   207         // Used to repaints the active call indicator with network indicator
       
   208         // immediately after the call ends.
       
   209         iNetworkIndicator->CleanNetworkResource();
       
   210         if (iNetworkIndicator->IsNetworkActive())
       
   211         {
       
   212             // There is active network connection, show its indicator.
       
   213             // XXX DEBUG("CMIDCallIndicator::RunL() -Network is active - copybitmaps");
       
   214             iNetworkIndicator->CopyBitmaps();
       
   215             iNetworkIndicator->ResizeBitmap();
       
   216         }
       
   217         iView = EFalse;
       
   218         iNetworkIndicator->Repaint(ETrue);
       
   219         // XXX DEBUG("CMIDCallIndicator::RunL() -Idle/unknown - iView=ETrue <<<");
       
   220     }
       
   221     // Set active to get next voice line status change.
       
   222     SetActiveLocal();
       
   223     DEBUG("<<< CMIDCallIndicator::RunL");
       
   224 }
       
   225 
       
   226 /**
       
   227  * From CActive.
       
   228  */
       
   229 TInt CMIDCallIndicator::RunError(TInt anError)
       
   230 {
       
   231     return anError;
       
   232 }
       
   233 
       
   234 /**
       
   235  * From CActive.
       
   236  */
       
   237 void CMIDCallIndicator::DoCancel()
       
   238 {
       
   239     // The EVoiceLineStatusChange cancellation code.
       
   240     iTelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
       
   241 }
       
   242