messagingapp/msgsettings/msginit/src/coutboxsender.cpp
changeset 46 b1f0785c289d
equal deleted inserted replaced
41:25fe1fe642e3 46:b1f0785c289d
       
     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 class
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include <CoreApplicationUIsSDKCRKeys.h>
       
    21 #include <msvuids.h>                 // Entry Uids
       
    22 #include "coutboxsendoperation.h"
       
    23 #include "coutboxsender.h"
       
    24 #include "debugtraces.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KListBar0(0);
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ----------------------------------------------------
       
    32 //  COutboxSender::NewL
       
    33 // ----------------------------------------------------
       
    34 //
       
    35 COutboxSender* COutboxSender::NewL(CMsvSession& aMsvSession)
       
    36 {
       
    37     COutboxSender* self = new (ELeave) COutboxSender(aMsvSession);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     return self;
       
    42 }
       
    43 
       
    44 // ----------------------------------------------------
       
    45 //  COutboxSender::COutboxSender
       
    46 // ----------------------------------------------------
       
    47 //
       
    48 COutboxSender::COutboxSender(CMsvSession& aMsvSession) :
       
    49  iMsvSession(aMsvSession)
       
    50 {
       
    51 }
       
    52 
       
    53 // ----------------------------------------------------
       
    54 //  COutboxSender::~COutboxSender
       
    55 // ----------------------------------------------------
       
    56 //
       
    57 COutboxSender::~COutboxSender()
       
    58 {
       
    59     // Stop and delete the sending operation
       
    60     delete iRunningOperation;
       
    61 
       
    62     // Check if notification is set
       
    63     if (iFlags & EUserSettingsNotifierSet) 
       
    64     {
       
    65         // Remove the notification from list
       
    66         if (iNotifyHandler) 
       
    67         {
       
    68             iNotifyHandler->StopListening();
       
    69             delete iNotifyHandler;
       
    70         }
       
    71 
       
    72         delete iSession;
       
    73     }
       
    74 
       
    75 }
       
    76 
       
    77 // ----------------------------------------------------
       
    78 //  COutboxSender::ConstructL
       
    79 // ----------------------------------------------------
       
    80 //
       
    81 void COutboxSender::ConstructL()
       
    82 {
       
    83     iNetworkBars = KListBar0;
       
    84     iSession = CRepository::NewL(KCRUidCoreApplicationUIs);
       
    85     iNotifyHandler = CCenRepNotifyHandler::NewL(*this, *iSession, CCenRepNotifyHandler::EIntKey,
       
    86         KCoreAppUIsNetworkConnectionAllowed);
       
    87     iNotifyHandler->StartListeningL();
       
    88 
       
    89     // Turn flag on for possible error handling cases
       
    90     iFlags |= EUserSettingsNotifierSet;
       
    91 
       
    92     CheckBootPhaseL();
       
    93 }
       
    94 
       
    95 // ----------------------------------------------------
       
    96 //  COutboxSender::StartSendingL
       
    97 // ----------------------------------------------------
       
    98 //
       
    99 void COutboxSender::StartSendingL()
       
   100 {
       
   101     // Check if the sending is already in progress
       
   102     if (!IsSending()) 
       
   103     {
       
   104         // Create instance of Single Operation Watcher
       
   105         CMsvSingleOpWatcher* singleOpWatcher = CMsvSingleOpWatcher::NewL(*this);
       
   106 
       
   107         // Push to cleanup stack while creating sending operation
       
   108         CleanupStack::PushL(singleOpWatcher);
       
   109         CMsvOperation* op = COutboxSendOperation::NewL(iMsvSession, singleOpWatcher->iStatus);
       
   110         CleanupStack::Pop(singleOpWatcher);
       
   111 
       
   112         // Set operation
       
   113         singleOpWatcher->SetOperation(op); // takes immediately ownership
       
   114         iRunningOperation = singleOpWatcher;
       
   115     }
       
   116 }
       
   117 
       
   118 // ----------------------------------------------------
       
   119 //  COutboxSender::CancelSending
       
   120 // ----------------------------------------------------
       
   121 //
       
   122 void COutboxSender::CancelSending()
       
   123 {
       
   124     // Remove the running operation
       
   125     delete iRunningOperation;
       
   126     iRunningOperation = NULL;
       
   127 }
       
   128 
       
   129 // ----------------------------------------------------
       
   130 //  COutboxSender::IsSending
       
   131 // ----------------------------------------------------
       
   132 //
       
   133 TBool COutboxSender::IsSending() const
       
   134 {
       
   135     return (iRunningOperation != NULL);
       
   136 }
       
   137 
       
   138 // ----------------------------------------------------
       
   139 //  COutboxSender::OpCompleted
       
   140 // ----------------------------------------------------
       
   141 //
       
   142 void COutboxSender::OpCompleted(CMsvSingleOpWatcher& /*aOpWatcher*/, TInt /*aCompletionCode*/)
       
   143 {
       
   144     delete iRunningOperation;
       
   145     iRunningOperation = NULL;
       
   146 }
       
   147 
       
   148 // ----------------------------------------------------
       
   149 //  COutboxSender::HandleNotifyInt
       
   150 // ----------------------------------------------------
       
   151 //
       
   152 void COutboxSender::HandleNotifyInt(const TUint32 aID, const TInt aNewValue)
       
   153 {
       
   154     QDEBUG_WRITE(("COutboxSender::HandleNotifyInt"));
       
   155     // Check if key is for offline-connecton
       
   156     if (aID == KCoreAppUIsNetworkConnectionAllowed) 
       
   157     {
       
   158         QDEBUG_WRITE(("COutboxSender::HandleNotifyInt KCoreAppUIsNetworkConnectionAllowed"));
       
   159         // Check if connection is established
       
   160         if (aNewValue == ECoreAppUIsNetworkConnectionAllowed) 
       
   161         {
       
   162             QDEBUG_WRITE(("COutboxSender::HandleNotifyInt ECoreAppUIsNetworkConnectionAllowed 1"));
       
   163             // Phone switched on again!
       
   164             iFlags |= EOffllineSendingNeeded;
       
   165 
       
   166             QDEBUG_WRITE_FORMAT(("COutboxSender::HandleNotifyInt iNetworkBars = %d"), iNetworkBars );
       
   167             if (iNetworkBars > KListBar0) 
       
   168             {
       
   169                 QDEBUG_WRITE_FORMAT(("COutboxSender::HandleNotifyInt sending now, iNetworkBars = %d"), iNetworkBars );
       
   170                 TRAP_IGNORE( StartSendingL() );
       
   171             }
       
   172         }
       
   173         else 
       
   174         {
       
   175             QDEBUG_WRITE("COutboxSender::HandleNotifyInt ECoreAppUIsNetworkConnectionAllowed 0");
       
   176             // Clear flag
       
   177             iFlags &= ~EOffllineSendingNeeded;
       
   178             // Stop sending
       
   179             CancelSending();
       
   180             // Set the coverage to 0 in case it didn't come from network in time
       
   181             iNetworkBars = KListBar0;
       
   182         }
       
   183     }
       
   184 }
       
   185 
       
   186 // ----------------------------------------------------
       
   187 //  COutboxSender::HandleNotifyGeneric
       
   188 // ----------------------------------------------------
       
   189 //
       
   190 void COutboxSender::HandleNotifyGeneric(const TUint32 /*aID*/)
       
   191 {
       
   192     //NO OPERATION
       
   193 }
       
   194 
       
   195 // ----------------------------------------------------
       
   196 //  COutboxSender::HandleNotifyError
       
   197 // ----------------------------------------------------
       
   198 //
       
   199 void COutboxSender::HandleNotifyError(const TUint32 /*aID*/, const TInt /*aError*/,
       
   200     CCenRepNotifyHandler* /*aHandler*/)
       
   201 {
       
   202     //NO OPERATION
       
   203 }
       
   204 
       
   205 // ----------------------------------------------------
       
   206 //  COutboxSender::CheckAndStartSendingL
       
   207 // ----------------------------------------------------
       
   208 //
       
   209 void COutboxSender::CheckAndStartSendingL(const TInt& aNetworkBars)
       
   210 {
       
   211     QDEBUG_WRITE_FORMAT("COutboxSender::CheckAndStartSendingL aNetworkBars = ", aNetworkBars );
       
   212     iNetworkBars = aNetworkBars;
       
   213     // Check if sending is needed and network is available
       
   214     if (aNetworkBars > KListBar0) 
       
   215     {
       
   216         QDEBUG_WRITE_FORMAT("COutboxSender::CheckAndStartSendingL sending now, iNetworkBars ", iNetworkBars );
       
   217         // Start sending
       
   218         StartSendingL();
       
   219     }
       
   220     else 
       
   221     {
       
   222         QDEBUG_WRITE_FORMAT("COutboxSender::CheckAndStartSendingL not sending, iNetworkBars = ", iNetworkBars );
       
   223     }
       
   224 }
       
   225 
       
   226 // ----------------------------------------------------
       
   227 //  COutboxSender::CheckBootPhaseL
       
   228 // ----------------------------------------------------
       
   229 //
       
   230 void COutboxSender::CheckBootPhaseL()
       
   231 {
       
   232     TInt connection;
       
   233 
       
   234     TInt err = iSession->Get(KCoreAppUIsNetworkConnectionAllowed, connection);
       
   235 
       
   236     if (err == KErrNone) 
       
   237     {
       
   238         // Check if connection is established
       
   239         if (connection) 
       
   240         {
       
   241             QDEBUG_WRITE("COutboxSender::CheckBootPhaseL KGSNetworkConnectionAllowed 1");
       
   242             // Phone switched on again!            
       
   243             iFlags |= EOffllineSendingNeeded;
       
   244 
       
   245             if (iNetworkBars > KListBar0) 
       
   246             {
       
   247                 QDEBUG_WRITE_FORMAT("COutboxSender::CheckBootPhaseL sending now, iNetworkBars = ", iNetworkBars );
       
   248                 StartSendingL();
       
   249             }
       
   250         }
       
   251     }
       
   252     else 
       
   253     {
       
   254         QDEBUG_WRITE("COutboxSender::CheckBootPhaseL Cannot access shared data");
       
   255     }
       
   256 }
       
   257 
       
   258 // End of file