emailuis/emailui/src/fsemailstatuspaneindicatorhandler.cpp
branchRCL_3
changeset 10 f5907b1a1053
child 11 0396474f30f5
equal deleted inserted replaced
8:e1b6206813b4 10:f5907b1a1053
       
     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 : Handles mailiindicator updating
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include <coemain.h> // CCoeEnv
       
    21 #include <coeaui.h> // CCoeAppUi
       
    22 #include "emailtrace.h"
       
    23 
       
    24 #include "cfsmailclient.h"
       
    25 #include "freestyleemailuiappui.h"
       
    26 #include "freestyleemailuiutilities.h"
       
    27 #include "freestyleemailuiconstants.h"
       
    28 #include "fsemailstatuspaneindicatorhandler.h"
       
    29 #include "commonemailcrkeys.h"
       
    30 #include "freestyleemailcenrepkeys.h"
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 // FUNCTION DEFINITIONS
       
    36 void TFsEmailStatusPaneIndicatorHandler::StatusPaneMailIndicatorHandlingL( TInt aMailBoxId  )
       
    37     {
       
    38     FUNC_LOG;
       
    39     //emailindicator control    
       
    40     CRepository* emailRepository = CRepository::NewL( KFreestyleEmailCenRep );    
       
    41     CleanupStack::PushL(emailRepository);
       
    42     CRepository* commonEmailRepository = CRepository::NewL( KCmailDataRepository );
       
    43     CleanupStack::PushL(commonEmailRepository);
       
    44     TInt numberOfMailboxes(0);
       
    45 
       
    46     emailRepository->Get(KNumberOfMailboxesWithNewEmails,numberOfMailboxes);
       
    47     if(numberOfMailboxes > 0)
       
    48         {
       
    49         RArray<TInt> repositoryIds;
       
    50         CleanupClosePushL(repositoryIds);
       
    51         TInt tmp (0); //used to store the mailbox and plugin ids
       
    52         for(TInt i = 1 ; i <= numberOfMailboxes * 2; i++ )
       
    53             {
       
    54             emailRepository->Get(KNumberOfMailboxesWithNewEmails+i, tmp);
       
    55             repositoryIds.Append(tmp);
       
    56             }
       
    57         // Here we check if the current mailbox id is already in the repository:
       
    58         TInt index = repositoryIds.Find(aMailBoxId);
       
    59 
       
    60         if(index != KErrNotFound)
       
    61             {
       
    62             repositoryIds.Remove(index);
       
    63             repositoryIds.Remove(index-1);
       
    64             // Rearrange the mailbox/mailplugin ids
       
    65             // in the repository
       
    66             for(TInt j = 0; j < repositoryIds.Count(); j++)
       
    67                 {
       
    68                 emailRepository->Set(KNumberOfMailboxesWithNewEmails + 1 + j, repositoryIds.operator [](j));
       
    69                 }
       
    70             // And delete last two remaining keys, that contains old information:
       
    71             emailRepository->Delete(KNumberOfMailboxesWithNewEmails + ( numberOfMailboxes * 2 - 1 ));
       
    72             emailRepository->Delete(KNumberOfMailboxesWithNewEmails + ( numberOfMailboxes * 2 ));
       
    73 
       
    74             // Decrease the number of mailboxes and update the repository:
       
    75             numberOfMailboxes -= 1;
       
    76             emailRepository->Set(KNumberOfMailboxesWithNewEmails,numberOfMailboxes);
       
    77 
       
    78             // Finally update the mailbox name to indicator pop-up note if there is still unchecked mailboxes
       
    79             if(numberOfMailboxes > 0)
       
    80                 {
       
    81                 TInt lastMBoxIdInRepository (0);
       
    82                 TInt lastMPluginIdInRepository (0);
       
    83                 emailRepository->Get(KNumberOfMailboxesWithNewEmails+(numberOfMailboxes*2), lastMBoxIdInRepository);
       
    84                 // Get matching email account.
       
    85                 TFSMailMsgId prevMboxId;
       
    86                 prevMboxId.SetId(lastMBoxIdInRepository);
       
    87                 emailRepository->Get(KNumberOfMailboxesWithNewEmails+(numberOfMailboxes*2-1), lastMPluginIdInRepository);
       
    88                 TUid lastMPluginUidInRepository = { lastMPluginIdInRepository };
       
    89                 prevMboxId.SetPluginId(lastMPluginUidInRepository);                
       
    90                 CFreestyleEmailUiAppUi* appUi = 
       
    91                 static_cast<CFreestyleEmailUiAppUi*>( CCoeEnv::Static()->AppUi() );
       
    92                 //Write the name commonEmailRepository
       
    93                 commonEmailRepository->Set(KCmailNewEmailDisplayText,appUi->GetMailClient()->GetMailBoxByUidL(prevMboxId)->GetName());
       
    94                 }
       
    95             }
       
    96         if(numberOfMailboxes == 0)
       
    97             {       
       
    98             // Set email indicator off.. user has checked the new emails in all the mailboxes
       
    99             TFsEmailUiUtility::ToggleEmailIconL(EFalse);
       
   100             }
       
   101         repositoryIds.Reset();
       
   102         CleanupStack::PopAndDestroy();//repositoryIds
       
   103         }
       
   104     CleanupStack::PopAndDestroy(2); //emailRepository, CommonEmailRepository
       
   105     }