messagingapp/msgui/appengine/src/conversationsengine_p.cpp
branchRCL_3
changeset 26 ebe688cedc25
equal deleted inserted replaced
25:fa1df4b99609 26:ebe688cedc25
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17 #include "conversationsengine_p.h"
       
    18 
       
    19 //SYSTEM INCLUDES
       
    20 #include <ccsconversationentry.h>
       
    21 #include <ccsclientconversation.h>
       
    22 //USER INCLUDES
       
    23 #include "conversationsenginedefines.h"
       
    24 #include "conversationmsgstorehandler.h"
       
    25 #include "conversationssummarymodel.h"
       
    26 #include "conversationsmodel.h"
       
    27 #include "conversationchangehandler.h"
       
    28 #include "conversationlistchangehandler.h"
       
    29 #include "debugtraces.h"
       
    30 
       
    31 
       
    32 //CONSTANTS
       
    33 /**
       
    34  *Max number of conversation that can be exchanged in IPC call
       
    35  */
       
    36 const TInt KMaxConversationIPCLimit =  250;
       
    37 //---------------------------------------------------------------
       
    38 // ConversationsEnginePrivate::ConversationsEnginePrivate
       
    39 // @see header
       
    40 //---------------------------------------------------------------
       
    41 ConversationsEnginePrivate::ConversationsEnginePrivate(
       
    42     ConversationMsgStoreHandler* conversationMsgStoreHandler,
       
    43     ConversationsSummaryModel *conversationsSummaryModel,
       
    44     ConversationsModel *conversationsModel
       
    45     ):mServer(NULL),
       
    46     mClientConv(NULL),
       
    47     mConversationMsgStoreHandler(conversationMsgStoreHandler),
       
    48     mConversationsSummaryModel(conversationsSummaryModel),
       
    49     mConversationsModel(conversationsModel)
       
    50 {
       
    51         initL();
       
    52 }
       
    53 
       
    54 //---------------------------------------------------------------
       
    55 // ConversationsEnginePrivate::~ConversationsEnginePrivate
       
    56 // @see header
       
    57 //---------------------------------------------------------------
       
    58 ConversationsEnginePrivate::~ConversationsEnginePrivate()
       
    59 {
       
    60 
       
    61     if( mClientConv )
       
    62     {        
       
    63         if(mServer && mConvChangeHandler)
       
    64         {    
       
    65         TRAP_IGNORE(mServer->RemoveConversationChangeEventL(
       
    66                 mConvChangeHandler,mClientConv));
       
    67         }
       
    68         delete mClientConv;
       
    69         mClientConv = NULL;
       
    70     }
       
    71     if(mServer && mConvListChangeHandler)
       
    72     {
       
    73         TRAP_IGNORE(mServer->RemoveConversationListChangeEventL(
       
    74                 mConvListChangeHandler));
       
    75         TRAP_IGNORE(mServer->RemoveResultsEventL ( this ));
       
    76         mServer->Cancel();
       
    77         delete mServer;
       
    78         mServer = NULL;
       
    79     }
       
    80     
       
    81     delete mConvChangeHandler;
       
    82     
       
    83     delete mConvListChangeHandler;
       
    84     
       
    85 }
       
    86 
       
    87 //---------------------------------------------------------------
       
    88 // ConversationsEnginePrivate::initL
       
    89 // @see header
       
    90 //---------------------------------------------------------------
       
    91 void ConversationsEnginePrivate::initL()
       
    92 {
       
    93     mServer = CCSRequestHandler::NewL();
       
    94     
       
    95     //Add results observer to the server
       
    96     mServer->RequestResultsEventL(this);
       
    97     
       
    98     //Fetch the conversation list from server
       
    99     mServer->GetConversationListL();    
       
   100     
       
   101     mConvChangeHandler = new ConversationsChangeHandler(this,
       
   102         mConversationsModel);
       
   103     
       
   104     mConvListChangeHandler = new ConversationsListChangeHandler(this,
       
   105         mConversationsSummaryModel);
       
   106 }
       
   107 
       
   108 //---------------------------------------------------------------
       
   109 // ConversationsEnginePrivate::registerForConversationListUpdatesL
       
   110 // @see header
       
   111 //---------------------------------------------------------------
       
   112 void ConversationsEnginePrivate::registerForConversationListUpdatesL()
       
   113 {
       
   114     //Add ConversationListChange Observer
       
   115     mServer->RequestConversationListChangeEventL (mConvListChangeHandler);
       
   116 }
       
   117 
       
   118 //---------------------------------------------------------------
       
   119 // ConversationsEnginePrivate::getConversationsL
       
   120 // @see header
       
   121 //---------------------------------------------------------------
       
   122 void ConversationsEnginePrivate::getConversationsL( TInt aConversationId)
       
   123 {	
       
   124     if(!mClientConv)
       
   125     {
       
   126         QCRITICAL_WRITE("ConversationsEnginePrivate::getConversationsL start.");
       
   127         //Clear the model before issueing fetch
       
   128         mConversationsModel->clear();
       
   129         //create a client conversation
       
   130         mClientConv = CCsClientConversation::NewL();
       
   131         mClientConv->SetConversationEntryId(aConversationId);
       
   132         //set dummy entry
       
   133         CCsConversationEntry *entry = CCsConversationEntry::NewL();
       
   134         CleanupStack::PushL(entry);
       
   135         mClientConv->SetConversationEntryL(entry);
       
   136         CleanupStack::PopAndDestroy(entry);
       
   137         // Reset the values in change handler before initiating a request
       
   138         mConvChangeHandler->ResetValuesForNewConversation();
       
   139         
       
   140         //Get the conversations for new conversationId 
       
   141         mServer->GetConversationsL(mClientConv,0,KMaxConversationIPCLimit);
       
   142 
       
   143         QCRITICAL_WRITE("ConversationsEnginePrivate::getConversationsL end.");
       
   144         }   
       
   145     
       
   146 }
       
   147 
       
   148 //---------------------------------------------------------------
       
   149 // ConversationsEnginePrivate::deleteConversationL
       
   150 // @see header
       
   151 //---------------------------------------------------------------
       
   152 void ConversationsEnginePrivate::deleteConversationL(TInt aConversationId)
       
   153 {
       
   154     mServer->DeleteConversationL(aConversationId);
       
   155 }
       
   156 
       
   157 //---------------------------------------------------------------
       
   158 // ConversationsEnginePrivate::deleteMessages
       
   159 // @see header
       
   160 //---------------------------------------------------------------
       
   161 void ConversationsEnginePrivate::deleteMessages(RArray<TInt>& aIdArray)
       
   162 {
       
   163     mConversationMsgStoreHandler->DeleteMessages(aIdArray);
       
   164 }
       
   165 
       
   166 //---------------------------------------------------------------
       
   167 // ConversationsEnginePrivate::deleteallDraftMessages
       
   168 // @see header
       
   169 //---------------------------------------------------------------
       
   170 void ConversationsEnginePrivate::deleteAllDraftMessagesL()
       
   171 {
       
   172     mConversationMsgStoreHandler->DeleteAllDraftMessagesL();
       
   173 }
       
   174 
       
   175 //---------------------------------------------------------------
       
   176 // ConversationsEnginePrivate::markConversationReadL
       
   177 // @see header
       
   178 //---------------------------------------------------------------
       
   179 void ConversationsEnginePrivate::markConversationReadL(TInt aConversationId)
       
   180 {
       
   181     mServer->MarkConversationReadL(aConversationId);
       
   182 }
       
   183 
       
   184 //---------------------------------------------------------------
       
   185 // ConversationsEnginePrivate::markMessagesReadL
       
   186 // @see header
       
   187 //---------------------------------------------------------------
       
   188 void ConversationsEnginePrivate::markMessagesReadL(RArray<TInt>& aIdArray)
       
   189 {
       
   190     mConversationMsgStoreHandler->MarkMessagesReadL(aIdArray);
       
   191 }
       
   192 
       
   193 //---------------------------------------------------------------
       
   194 // ConversationsEnginePrivate::getConversationCurrentId
       
   195 // @see header
       
   196 //---------------------------------------------------------------
       
   197 TInt ConversationsEnginePrivate::getConversationCurrentId()
       
   198 {
       
   199     TInt convId = -1;
       
   200     if(mClientConv)
       
   201     {
       
   202         convId = mClientConv->GetConversationEntryId();    
       
   203     }
       
   204     return convId;
       
   205 }
       
   206 
       
   207 //---------------------------------------------------------------
       
   208 // ConversationsEnginePrivate::getConversationIdFromContactId
       
   209 // @see header
       
   210 //---------------------------------------------------------------
       
   211 TInt ConversationsEnginePrivate::getConversationIdFromContactIdL(TInt contactId)
       
   212 {
       
   213     TInt convId = -1;
       
   214     
       
   215     convId = mServer->GetConversationIdL(contactId);
       
   216     
       
   217     return convId;
       
   218 }
       
   219 
       
   220 //---------------------------------------------------------------
       
   221 // ConversationsEnginePrivate::getConversationIdFromAddress
       
   222 // @see header
       
   223 //---------------------------------------------------------------
       
   224 TInt ConversationsEnginePrivate::getConversationIdFromAddressL(TDesC& contactAddress)
       
   225 {
       
   226     TInt convId = -1;
       
   227     
       
   228     convId = mServer->GetConversationIdFromAddressL(contactAddress);
       
   229     
       
   230     return convId;
       
   231 }
       
   232 
       
   233 //---------------------------------------------------------------
       
   234 // ConversationsEnginePrivate::getConversationFromConversationId
       
   235 // @see header
       
   236 //---------------------------------------------------------------
       
   237 CCsClientConversation* ConversationsEnginePrivate::getConversationFromConversationIdL(TInt aConversationId)
       
   238 {
       
   239      return mServer->GetConversationFromConversationIdL(aConversationId);
       
   240 }
       
   241 
       
   242 //---------------------------------------------------------------
       
   243 // ConversationsEnginePrivate::clearConversationsL
       
   244 // @see header
       
   245 //---------------------------------------------------------------
       
   246 void ConversationsEnginePrivate::clearConversationsL()
       
   247 {    
       
   248     QCRITICAL_WRITE("ConversationsEnginePrivate::clearConversationsL start.");
       
   249     
       
   250     mConvChangeHandler->Cancel();
       
   251     //Clear conversations model before populating with new data 
       
   252     mConversationsModel->clearModel();
       
   253     
       
   254     // Delete old CCsClientConversation object 
       
   255     // Remove the old Conversation change observer
       
   256     if(mClientConv)
       
   257     {   
       
   258         int error = KErrNone;
       
   259         TRAP(error, mServer->RemoveConversationChangeEventL (mConvChangeHandler ,mClientConv));
       
   260         delete mClientConv;
       
   261         mClientConv = NULL;
       
   262         User::LeaveIfError(error);
       
   263     }
       
   264     
       
   265     QCRITICAL_WRITE("ConversationsEnginePrivate::clearConversationsL end.");
       
   266 }
       
   267 
       
   268 //---------------------------------------------------------------
       
   269 // ConversationsEnginePrivate::registerForConversationUpdatesL
       
   270 // @see header
       
   271 //---------------------------------------------------------------
       
   272 void ConversationsEnginePrivate::registerForConversationUpdatesL()
       
   273 {
       
   274     //Add the Conversation Change for new  conversationId
       
   275     if(mClientConv)
       
   276     {    
       
   277     mServer->RequestConversationChangeEventL (mConvChangeHandler ,mClientConv);
       
   278     }
       
   279 }
       
   280 
       
   281 //---------------------------------------------------------------
       
   282 // ConversationsEnginePrivate::deRegisterCVUpdatesTemporary
       
   283 // @see header
       
   284 //---------------------------------------------------------------
       
   285 void ConversationsEnginePrivate::deRegisterCVUpdatesTemporary()
       
   286 {
       
   287     mServer->RemoveConversationChangeEventL (mConvChangeHandler ,mClientConv);
       
   288 }
       
   289 
       
   290 //---------------------------------------------------------------
       
   291 // ConversationsEnginePrivate::registerAgainForConversationUpdatesL
       
   292 // @see header
       
   293 //---------------------------------------------------------------
       
   294 void ConversationsEnginePrivate::registerAgainForConversationUpdatesL(
       
   295         int newConversationId)
       
   296 {
       
   297     //Add the Conversation Change for new  conversationId
       
   298     if(mClientConv)
       
   299     {    
       
   300     mClientConv->SetConversationEntryId(newConversationId);
       
   301     mServer->RequestConversationChangeEventL (mConvChangeHandler ,mClientConv);
       
   302     }
       
   303 }
       
   304 
       
   305 //---------------------------------------------------------------
       
   306 // ConversationsEnginePrivate::ConversationList
       
   307 // @see header
       
   308 //---------------------------------------------------------------
       
   309 void ConversationsEnginePrivate::ConversationList(
       
   310     RPointerArray<CCsClientConversation>& aClientConversationList)
       
   311 {
       
   312     int error;
       
   313     TRAP(error,
       
   314         mConvListChangeHandler->ConversationListL(aClientConversationList));
       
   315 }
       
   316 
       
   317 //---------------------------------------------------------------
       
   318 // ConversationsEnginePrivate::Conversations
       
   319 // @see header
       
   320 //---------------------------------------------------------------
       
   321 void ConversationsEnginePrivate::Conversations(
       
   322     RPointerArray<CCsConversationEntry>& aConversationEntryList,
       
   323     TInt& aTotalCount)
       
   324 {
       
   325     int error;
       
   326     if (mClientConv)
       
   327         {
       
   328         QCRITICAL_WRITE("ConversationsEnginePrivate::Conversations start.");
       
   329 
       
   330         TRAP(error,mConvChangeHandler->ConversationsL(aConversationEntryList,aTotalCount));
       
   331 
       
   332         QCRITICAL_WRITE("ConversationsEnginePrivate::Conversations end.");
       
   333         }
       
   334 }
       
   335 
       
   336 
       
   337 //---------------------------------------------------------------
       
   338 // ConversationsEngine::fetchMoreConversations
       
   339 // @see header
       
   340 //---------------------------------------------------------------
       
   341 void ConversationsEnginePrivate::fetchMoreConversations()
       
   342 {
       
   343     if (mClientConv)
       
   344         {
       
   345         mConvChangeHandler->restartHandleConversations();
       
   346         }
       
   347 }
       
   348 
       
   349 //---------------------------------------------------------------
       
   350 // ConversationsEngine::fetchRemainingConversations
       
   351 // @see header
       
   352 //---------------------------------------------------------------
       
   353 void ConversationsEnginePrivate::fetchRemainingConversations(TInt& aCount)
       
   354     {
       
   355     if ( mServer && mClientConv )
       
   356             {
       
   357                     
       
   358             // Get conversations from server
       
   359              mServer->GetConversationsL(mClientConv, 
       
   360                      (aCount - 1),
       
   361                     KMaxConversationIPCLimit);
       
   362             }
       
   363     }
       
   364 //---------------------------------------------------------------
       
   365 // ConversationsEnginePrivate::resendMessage()
       
   366 // @see header
       
   367 //---------------------------------------------------------------
       
   368 bool ConversationsEnginePrivate::resendMessage(TMsvId messageId)
       
   369 {
       
   370     TInt err = KErrNone;
       
   371     bool retval = true;
       
   372     TRAP(err, retval = mConversationMsgStoreHandler->ResendMessageL(messageId));
       
   373     return ((err == KErrNone) && (retval == true))?true:false;
       
   374 }
       
   375 
       
   376 //---------------------------------------------------------------
       
   377 // ConversationsEnginePrivate::downloadMessage
       
   378 // @see header
       
   379 //---------------------------------------------------------------
       
   380 TInt ConversationsEnginePrivate::downloadMessage(TMsvId messageId)
       
   381 {
       
   382     TInt err = KErrNone;
       
   383     TInt retval = KErrNone;
       
   384     TRAP(err, retval = 
       
   385             mConversationMsgStoreHandler->DownloadMessageL(messageId));
       
   386             
       
   387     if( err!=KErrNone)
       
   388     {
       
   389         retval = KErrGeneral;
       
   390     }
       
   391     
       
   392     return retval;
       
   393 }
       
   394 
       
   395 //---------------------------------------------------------------
       
   396 // ConversationsEnginePrivate::downloadOperationSupported()
       
   397 // @see header
       
   398 //---------------------------------------------------------------
       
   399 bool ConversationsEnginePrivate::downloadOperationSupported(TMsvId messageId)
       
   400 {
       
   401   return mConversationMsgStoreHandler->DownloadOperationSupported(messageId);   
       
   402 }
       
   403 //EOF
       
   404