messagingapp/msgsettings/msginit/src/coutboxobserver.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2010 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:   Implements the class
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32def.h>
       
    20 #include <msvids.h>              // Entry Ids
       
    21 #include <e32property.h>
       
    22 #include <PSVariables.h>
       
    23 #include "coutboxsender.h"
       
    24 #include "coutboxobserver.h"
       
    25 #include "cmobilesignalstrengthhandler.h"
       
    26 #include "debugtraces.h"
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // COutboxObserver::COutboxObserver
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 COutboxObserver::COutboxObserver(){}
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // COutboxObserver::ConstructL
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 void COutboxObserver::ConstructL()
       
    41 {
       
    42     QDEBUG_WRITE( "COutboxObserver::ConstructL Enter" );
       
    43     // instantiate the signal strength handler
       
    44     iSignalStrengthHandler = CMobileSignalStrengthHandler::NewL();
       
    45 
       
    46     if (iSignalStrengthHandler->ObservingSupported()) 
       
    47     {
       
    48         iSignalStrengthHandler->SetSignalStrengthObserverL(this);
       
    49         iSignalStrengthHandler->StartObservingL();
       
    50     }
       
    51     else 
       
    52     {
       
    53         QDEBUG_WRITE( "COutboxObserver::ConstructL else part" );
       
    54     }
       
    55     QDEBUG_WRITE( "COutboxObserver::ConstructL Exit" );
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // COutboxObserver::NewL
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 COutboxObserver* COutboxObserver::NewL()
       
    63 {
       
    64     // Create the instance of the outbox observer
       
    65     COutboxObserver* self = new (ELeave) COutboxObserver();
       
    66     // Push it to stack while executing the constructor
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop();
       
    70     return self;
       
    71 }
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // COutboxObserver::~COutboxObserver
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 COutboxObserver::~COutboxObserver()
       
    78 {
       
    79     delete iSignalStrengthHandler;
       
    80     EndSessions();
       
    81 }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // COutboxObserver::SignalStrengthUpdatedL
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void COutboxObserver::SignalStrengthAndBarUpdatedL(TInt /*aNewSignalValue*/, TInt aNewBarValue)
       
    88 {
       
    89     QDEBUG_WRITE_FORMAT( "COutboxObserver::SignalStrengthUpdatedL - Signal bars ", aNewBarValue );
       
    90     // pass new bar value to outbox sender
       
    91     InformOutboxSenderL(aNewBarValue);
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // COutboxObserver::InformOutboxSenderL
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void COutboxObserver::InformOutboxSenderL(const TInt& aNetworkBars)
       
    99 {
       
   100     if (iOutboxSender) {
       
   101         QDEBUG_WRITE( "COutboxObserver::InformOutboxSenderL - Informing outbox sender." );
       
   102 
       
   103         iOutboxSender->CheckAndStartSendingL(aNetworkBars);
       
   104     }
       
   105     else {
       
   106         QDEBUG_WRITE( "COutboxObserver::InformOutboxSenderL - Outbox sender not initialized." );
       
   107     }
       
   108 }
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // COutboxObserver::StartSessionsL
       
   112 // ---------------------------------------------------------
       
   113 //
       
   114 void COutboxObserver::StartSessionsL(CMsvSession& aMsvSession)
       
   115 {
       
   116     // Set outbox folder
       
   117     iOutboxFolder = aMsvSession.GetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   118     iOutboxFolder->AddObserverL(*this);
       
   119 
       
   120     // Remove the Sender, if it exists
       
   121     delete iOutboxSender;
       
   122     iOutboxSender = NULL;
       
   123 
       
   124     QDEBUG_WRITE("COutboxObserver::StartSessionsL - Initializing outbox sender.." );
       
   125     iOutboxSender = COutboxSender::NewL(aMsvSession);
       
   126 
       
   127     QDEBUG_WRITE( "COutboxObserver::StartSessionsL - Informing outbox sender of network status.." );
       
   128 
       
   129     // get current signal bar value
       
   130     TInt signalBars = 0;
       
   131     TRAPD( err, signalBars = iSignalStrengthHandler->BarValueL() );
       
   132 
       
   133     // check error
       
   134     if (err == KErrNone) 
       
   135     {
       
   136         QDEBUG_WRITE_FORMAT("COutboxObserver::StartSessionsL - Got signal bar value notifying..", signalBars );
       
   137         iOutboxSender->CheckAndStartSendingL(signalBars);
       
   138     }
       
   139     else 
       
   140     {
       
   141         QDEBUG_WRITE_FORMAT( "COutboxObserver::StartSessionsL - Failed to get signal bar value (err = )", err );
       
   142     }
       
   143 
       
   144 }
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // COutboxObserver::EndSessions
       
   148 // ---------------------------------------------------------
       
   149 //
       
   150 void COutboxObserver::EndSessions()
       
   151 {
       
   152     // Delete Outbox sender
       
   153     delete iOutboxSender;
       
   154     iOutboxSender = NULL;
       
   155 
       
   156     if (iOutboxFolder) {
       
   157         // Delete outbox folder
       
   158         iOutboxFolder->RemoveObserver(*this);
       
   159         delete iOutboxFolder;
       
   160         iOutboxFolder = NULL;
       
   161     }
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // COutboxObserver::HandleMsvSessionReadyL
       
   166 // ---------------------------------------------------------
       
   167 //    
       
   168 void COutboxObserver::HandleMsvSessionReadyL(CMsvSession& aMsvSession)
       
   169 {
       
   170     StartSessionsL(aMsvSession);
       
   171 }
       
   172 // ---------------------------------------------------------
       
   173 // COutboxObserver::HandleMsvSessionClosedL
       
   174 // ---------------------------------------------------------
       
   175 //    
       
   176 void COutboxObserver::HandleMsvSessionClosedL()
       
   177 {
       
   178     EndSessions();
       
   179 }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // COutboxObserver::HandleEntryEventL
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void COutboxObserver::HandleEntryEventL(TMsvEntryEvent /*aEvent*/, TAny* /*aArg1*/,
       
   186     TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   187 {
       
   188 
       
   189 }
       
   190 
       
   191 //  End of File