messagingapp/msgnotifications/flashmsgnotifier/src/flashmsgnotifier_p.cpp
changeset 52 12db4185673b
equal deleted inserted replaced
44:36f374c67aa8 52:12db4185673b
       
     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:  handler for saving and deleting flash messages
       
    15  *
       
    16  */
       
    17 
       
    18 #include "flashmsgnotifier_p.h"
       
    19 #include <xqconversions.h>
       
    20 #include <msvids.h>
       
    21 #include <txtrich.h>
       
    22 #include <smuthdr.h>
       
    23 #include <debugtraces.h>
       
    24 #include <ccsrequesthandler.h>
       
    25 #include <tmsvsmsentry.h>
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // FlashMsgNotifierPrivate::FlashMsgNotifierPrivate
       
    31 // constructor.
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 FlashMsgNotifierPrivate::FlashMsgNotifierPrivate(FlashMsgNotifier* notifier) :
       
    35     iMsvSession(NULL), iRequestHandler(NULL),iNotifier(notifier)
       
    36 {
       
    37     InitL();
       
    38 }
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // FlashMsgNotifierPrivate::~FlashMsgNotifierPrivate
       
    42 // Destructor.
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 FlashMsgNotifierPrivate::~FlashMsgNotifierPrivate()
       
    46 {
       
    47     if (iMsvSession) {
       
    48         delete iMsvSession;
       
    49         iMsvSession = NULL;
       
    50     }
       
    51     if(iRequestHandler) {
       
    52         delete iRequestHandler;
       
    53         iRequestHandler = NULL;
       
    54     }
       
    55     iNotifier = NULL;
       
    56 
       
    57 }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // InitL( )
       
    61 // @see header
       
    62 // ---------------------------------------------------------
       
    63 void FlashMsgNotifierPrivate::InitL()
       
    64 {
       
    65     iMsvSession = CMsvSession::OpenSyncL(*this);
       
    66     iRequestHandler = CCSRequestHandler::NewL();
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // FlashMsgNotifierPrivate::HandleSessionEventL()
       
    71 // @see header
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 void FlashMsgNotifierPrivate::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/,
       
    75     TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    76 {
       
    77 
       
    78 }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // FlashMsgNotifierPrivate::DeleteMessage()
       
    82 // @see header
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void FlashMsgNotifierPrivate::DeleteMessage(TMsvId aMsgId)
       
    86 {
       
    87     iMsvSession->RemoveEntry(aMsgId);
       
    88 }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // FlashMsgNotifierPrivate::SaveMessageL()
       
    92 // @see header
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 void FlashMsgNotifierPrivate::SaveMessageL(TMsvId aMsgId)
       
    96 {
       
    97     QDEBUG_WRITE_FORMAT("SaveMessageL Begin", aMsgId);
       
    98     
       
    99     CMsvEntry* msgEntry = iMsvSession->GetEntryL(aMsgId);
       
   100     CleanupStack::PushL( msgEntry );
       
   101     
       
   102     TMsvEntry entry = msgEntry->Entry();
       
   103     
       
   104     // If the entry is readonly we need to make it read...
       
   105     if(entry.ReadOnly())
       
   106     {
       
   107         entry.SetReadOnly(EFalse);
       
   108         entry.SetUnread(EFalse);
       
   109 		entry.SetNew(EFalse);
       
   110         msgEntry->ChangeL(entry);                
       
   111     }
       
   112     
       
   113     CPlainText* nullString = CPlainText::NewL();
       
   114     CleanupStack::PushL( nullString );
       
   115 
       
   116     CSmsHeader* smsheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *nullString);
       
   117     CleanupStack::PushL( smsheader );
       
   118     
       
   119     CMsvStore* store = msgEntry->EditStoreL();
       
   120     CleanupStack::PushL( store );
       
   121     
       
   122     smsheader->RestoreL(*store);
       
   123     smsheader->Message().SmsPDU().SetClass(ETrue, TSmsDataCodingScheme::ESmsClass1 );
       
   124     smsheader->StoreL( *store );
       
   125     store->Commit();
       
   126     
       
   127     TMsvSmsEntry entry1 = msgEntry->Entry();
       
   128     entry1.SetClass(ETrue, TSmsDataCodingScheme::ESmsClass1 );            
       
   129     msgEntry->ChangeL(entry1);
       
   130     CleanupStack::PopAndDestroy(4);
       
   131     QDEBUG_WRITE_FORMAT("SaveMessageL End", aMsgId);
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // FlashMsgNotifierPrivate::GetConversationIdFromAddressL()
       
   136 // @see header
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 TInt FlashMsgNotifierPrivate::GetConversationIdFromAddressL(
       
   140         TDesC& aContactAddress)
       
   141 {
       
   142     return 
       
   143     iRequestHandler->GetConversationIdFromAddressL(aContactAddress);
       
   144 }
       
   145 
       
   146 // End of file