messagingappbase/ncnlist/src/NcnOutboxObserver.cpp
branchRCL_3
changeset 60 7fdbb852d323
equal deleted inserted replaced
57:ebe688cedc25 60:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2004 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 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <e32def.h>
       
    22 #include    <msvids.h>              // Entry Ids
       
    23 #include	<e32property.h>
       
    24 #include	<PSVariables.h>
       
    25 
       
    26 #include    <NcnListInternalPSKeys.h>
       
    27 #include    <NcnListInternalCRKeys.h>
       
    28 #include    <NcnListSDKPSKeys.h>
       
    29 
       
    30 #include    "NcnDebug.h"
       
    31 #include    "NcnOutboxSender.h"
       
    32 #include    "NcnOutboxObserver.h"
       
    33 #include    "NcnModelBase.h"
       
    34 #include    "CNcnMsvSessionHandler.h"
       
    35 #include    "CNcnMobileSignalStrengthHandler.h"
       
    36 #include <miutset.h>
       
    37 
       
    38 const TUid KUidMsgTypeCmailMtmVal = {0x2001F406};
       
    39 // ================= MEMBER FUNCTIONS =======================
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CNcnOutboxObserver::CNcnOutboxObserver
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 CNcnOutboxObserver::CNcnOutboxObserver( CNcnModelBase* aModel ) :
       
    46     iModel( aModel )
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CNcnOutboxObserver::ConstructL
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 void CNcnOutboxObserver::ConstructL()
       
    55     {    
       
    56     NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Constructing signal strength handler") );
       
    57     
       
    58     // instantiate the signal strength handler
       
    59     iSignalStrengthHandler = CNcnMobileSignalStrengthHandler::NewL();    
       
    60     
       
    61     // Set observer and start observing, if supported
       
    62     if( iSignalStrengthHandler->ObservingSupported() )
       
    63         {
       
    64         iSignalStrengthHandler->SetSignalStrengthObserverL( this );
       
    65         iSignalStrengthHandler->StartObservingL();
       
    66         NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Signal strength observing started") );
       
    67         }
       
    68     else
       
    69         {
       
    70         NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Signal strength observing not supported") );
       
    71         }
       
    72     
       
    73     // add observer to msv session handler
       
    74     iModel->MsvSessionHandler().AddObserverL( this );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CNcnOutboxObserver::NewL
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 CNcnOutboxObserver* CNcnOutboxObserver::NewL( CNcnModelBase* aModel )
       
    83     {
       
    84     // Create the instance of the outbox observer
       
    85     CNcnOutboxObserver* self = new (ELeave) CNcnOutboxObserver( aModel );
       
    86 
       
    87     // Push it to stack while executing the constructor
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop();
       
    91 
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CNcnOutboxObserver::~CNcnOutboxObserver
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 CNcnOutboxObserver::~CNcnOutboxObserver()
       
   100     {
       
   101     if( iModel )
       
   102         {
       
   103         // remove observer from msv session handler
       
   104         iModel->MsvSessionHandler().RemoveObserver( this );
       
   105         }
       
   106     
       
   107     delete iSignalStrengthHandler;
       
   108         
       
   109     EndSessions();
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CNcnOutboxObserver::CheckOutboxAndNotifyL
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CNcnOutboxObserver::CheckOutboxAndNotifyL()
       
   117     {
       
   118     NCN_RDEBUG( _L("CNcnOutboxObserver::CheckOutboxAndNotifyL" ) );
       
   119     // Check messagecount in outbox
       
   120     TInt msgCount = iOutboxFolder->Count();
       
   121     
       
   122     CMsvEntrySelection *smtpselection = NULL ;
       
   123     CMsvEntrySelection *pop3selection = NULL;
       
   124     CMsvEntrySelection *imapselection = NULL ;
       
   125     CMsvEntrySelection *cmailselection = NULL ;
       
   126 
       
   127     smtpselection = iOutboxFolder ->ChildrenWithMtmL( KUidMsgTypeSMTP );
       
   128     CleanupStack::PushL( smtpselection );
       
   129     TInt smtpCount= smtpselection ->Count();
       
   130     
       
   131     pop3selection = iOutboxFolder ->ChildrenWithMtmL( KUidMsgTypePOP3 );
       
   132     CleanupStack::PushL( pop3selection );    
       
   133     TInt pop3Count= pop3selection ->Count();
       
   134 
       
   135     imapselection = iOutboxFolder ->ChildrenWithMtmL( KUidMsgTypeIMAP4 );
       
   136     CleanupStack::PushL( imapselection );
       
   137     TInt imapCount= imapselection ->Count();
       
   138     
       
   139     cmailselection = iOutboxFolder ->ChildrenWithMtmL( KUidMsgTypeCmailMtmVal);
       
   140     CleanupStack::PushL( cmailselection );
       
   141     TInt cmailCount= cmailselection ->Count();
       
   142     
       
   143     CleanupStack::PopAndDestroy( 4 );
       
   144     // Check messagecount in outbox
       
   145     msgCount  = msgCount - (smtpCount+pop3Count+ imapCount+cmailCount);
       
   146     // Set msg count to the CR key
       
   147     NCN_RDEBUG_INT( _L("CNcnOutboxObserver::CheckOutboxAndNotifyL SetCRInt(KNcnMessageCountInOutbox) %d" ), msgCount );
       
   148     User::LeaveIfError( iModel->SetCRInt( 
       
   149         KCRUidNcnList, KNcnMessageCountInOutbox, msgCount ) );
       
   150 
       
   151     if( msgCount )
       
   152         {
       
   153         // Turn indicator on, if any messages in outbox
       
   154         iModel->NotifyPublishAndSubscribe(
       
   155             KUidSystemCategory,
       
   156             KPSNcnOutboxStatus,
       
   157             ENcnDocumentsInOutbox );
       
   158         }
       
   159     else
       
   160         {
       
   161         // If no messages in outbox, remove indicator
       
   162         iModel->NotifyPublishAndSubscribe(
       
   163             KUidSystemCategory,
       
   164             KPSNcnOutboxStatus,
       
   165             ENcnOutboxEmpty );
       
   166         }
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CNcnOutboxObserver::SignalStrengthUpdatedL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CNcnOutboxObserver::SignalStrengthAndBarUpdatedL( TInt /*aNewSignalValue*/, TInt aNewBarValue )
       
   174     {
       
   175     NCN_RDEBUG_INT( _L("CNcnOutboxObserver::SignalStrengthUpdatedL - Signal bars %d"), aNewBarValue );
       
   176     
       
   177     // pass new bar value to outbox sender
       
   178     InformOutboxSenderL( aNewBarValue );
       
   179     }
       
   180     
       
   181 // ---------------------------------------------------------
       
   182 // CNcnOutboxObserver::InformOutboxSenderL
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 void CNcnOutboxObserver::InformOutboxSenderL( const TInt& aNetworkBars )
       
   186     {
       
   187     if( iOutboxSender )
       
   188         {
       
   189         NCN_RDEBUG( _L("CNcnOutboxObserver::InformOutboxSenderL - Informing outbox sender.") );
       
   190         
       
   191         iOutboxSender->CheckAndStartSendingL( aNetworkBars );
       
   192         }
       
   193     else
       
   194         {
       
   195         NCN_RDEBUG( _L("CNcnOutboxObserver::InformOutboxSenderL - Outbox sender not initialized." ) );
       
   196         }
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CNcnOutboxObserver::StartSessionsL
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 void CNcnOutboxObserver::StartSessionsL( CMsvSession& aMsvSession )
       
   204     {    
       
   205     // Set outbox folder
       
   206     iOutboxFolder = aMsvSession.GetEntryL( KMsvGlobalOutBoxIndexEntryId );
       
   207     iOutboxFolder->AddObserverL( *this );
       
   208     
       
   209     // Remove the Sender, if it exists
       
   210     delete iOutboxSender;
       
   211     iOutboxSender = NULL;
       
   212 
       
   213     // Check if feature is supported
       
   214     if( iModel->IsSupported( KNcnOfflineSupport ) )
       
   215         {
       
   216         NCN_RDEBUG( _L("CNcnOutboxObserver::StartSessionsL - Initializing outbox sender.." ) );
       
   217         iOutboxSender = CNcnOutboxSender::NewL( iModel, aMsvSession );
       
   218 
       
   219         NCN_RDEBUG( _L("CNcnOutboxObserver::StartSessionsL - Informing outbox sender of network status.." ) );
       
   220         
       
   221         // get current signal bar value
       
   222         TInt signalBars = 0;                
       
   223         TRAPD( err, signalBars = iSignalStrengthHandler->BarValueL() );
       
   224         
       
   225         // check error
       
   226         if( err == KErrNone )
       
   227             {
       
   228             NCN_RDEBUG_INT( _L( "CNcnOutboxObserver::StartSessionsL - Got signal bar value %d, notifying.."), signalBars );
       
   229             iOutboxSender->CheckAndStartSendingL( signalBars );
       
   230             }
       
   231         else
       
   232             {
       
   233             NCN_RDEBUG_INT( _L("CNcnOutboxObserver::StartSessionsL - Failed to get signal bar value (err = %d)"), err );
       
   234             }
       
   235         }
       
   236         
       
   237     // Check if there are messages in the OutBox.
       
   238     CheckOutboxAndNotifyL();
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CNcnOutboxObserver::EndSessions
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 void CNcnOutboxObserver::EndSessions()
       
   246     {
       
   247     // Delete Outbox sender
       
   248     delete iOutboxSender;
       
   249     iOutboxSender = NULL;   
       
   250     
       
   251     if( iOutboxFolder )
       
   252         {
       
   253         // Delete outbox folder
       
   254         iOutboxFolder->RemoveObserver( *this );
       
   255         delete iOutboxFolder;
       
   256         iOutboxFolder = NULL;
       
   257         }    
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // CNcnOutboxObserver::HandleMsvSessionReadyL
       
   262 // ---------------------------------------------------------
       
   263 //    
       
   264 void CNcnOutboxObserver::HandleMsvSessionReadyL( CMsvSession& aMsvSession )
       
   265     {
       
   266     StartSessionsL( aMsvSession );
       
   267     }
       
   268 // ---------------------------------------------------------
       
   269 // CNcnOutboxObserver::HandleMsvSessionClosedL
       
   270 // ---------------------------------------------------------
       
   271 //    
       
   272 void CNcnOutboxObserver::HandleMsvSessionClosedL()
       
   273     {
       
   274     EndSessions();
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------
       
   278 // CNcnOutboxObserver::HandleEntryEventL
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 void CNcnOutboxObserver::HandleEntryEventL( 
       
   282     TMsvEntryEvent  /*aEvent*/, 
       
   283     TAny*           /*aArg1*/, 
       
   284     TAny*           /*aArg2*/, 
       
   285     TAny*           /*aArg3*/ )
       
   286     {
       
   287     // Count objects in folders for every event
       
   288     CheckOutboxAndNotifyL();
       
   289     }
       
   290 
       
   291 //  End of File