messagingapp/msgappfw/msghistory/src/msghistoryprivate.cpp
branchRCL_3
changeset 26 ebe688cedc25
equal deleted inserted replaced
25:fa1df4b99609 26:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 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 
       
    18 //SYSTEM INCLUDES
       
    19 #include <ccsrequesthandler.h>
       
    20 #include <ccsconversationentry.h>
       
    21 #include <ccsclientconversation.h>
       
    22 #include <xqconversions.h>
       
    23 
       
    24 //USER INCLUDES
       
    25 #include "msghistoryprivate.h"
       
    26 #include "msghistoryimpl.h"
       
    27 #include <msgitem.h>
       
    28 
       
    29 // CONSTANTS
       
    30 _LIT(KUnixEpoch, "19700000:000000.000000");
       
    31 
       
    32 const TInt KMaxConversationIPCLimit = 250;
       
    33 
       
    34 
       
    35 //---------------------------------------------------------------
       
    36 // MsgHistoryPrivate::MsgHistoryPrivate
       
    37 // @see header
       
    38 //---------------------------------------------------------------
       
    39 MsgHistoryPrivate::MsgHistoryPrivate( MsgHistoryImpl* ptr )
       
    40 :CActive(EPriorityStandard),
       
    41 currentState(EInit),
       
    42 q_ptr(ptr) 
       
    43 
       
    44     { 
       
    45     CActiveScheduler::Add(this);
       
    46     handler = CCSRequestHandler::NewL();
       
    47     handler->RequestResultsEventL(this);
       
    48     }
       
    49 
       
    50 //---------------------------------------------------------------
       
    51 // MsgHistoryPrivate::MsgHistoryPrivate
       
    52 // @see header
       
    53 //---------------------------------------------------------------
       
    54 MsgHistoryPrivate::~MsgHistoryPrivate()
       
    55     {
       
    56     if ( handler )
       
    57         delete handler;
       
    58      if(msgs.count())
       
    59         {
       
    60          msgs.clear();
       
    61         }
       
    62     // Cancel the active Object 
       
    63     Cancel();
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // RunL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void MsgHistoryPrivate::RunL()
       
    71 {
       
    72     if (iStatus != KErrNone)
       
    73     {
       
    74         return;
       
    75     }
       
    76     //process
       
    77     switch (currentState)
       
    78     {
       
    79        case EFetchMoreConversations:
       
    80            GetMessagingHistory(contactId, msgs.count());
       
    81             break;
       
    82     }
       
    83 }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // DoCancel
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void MsgHistoryPrivate::DoCancel()
       
    90 {
       
    91     currentState = EInit;
       
    92     contactId = -1;
       
    93    
       
    94 }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Make the active object alive.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void MsgHistoryPrivate::IssueRequest()
       
   101 {
       
   102     if (!IsActive())
       
   103     {
       
   104         iStatus = KRequestPending;
       
   105         TRequestStatus* status = &iStatus;
       
   106         SetActive();
       
   107         User::RequestComplete(status, KErrNone);
       
   108     }
       
   109 }
       
   110 //---------------------------------------------------------------
       
   111 // MsgHistoryPrivate::GetMessagingHistory
       
   112 // @see header
       
   113 //---------------------------------------------------------------
       
   114 TBool MsgHistoryPrivate::GetMessagingHistory( const TInt aContactId ,
       
   115                                               TInt aKnownIndex)
       
   116     {
       
   117     contactId = aContactId;
       
   118     TRAPD(err, handler->GetMessagingHistoryL(contactId,
       
   119                                              aKnownIndex,
       
   120                                              KMaxConversationIPCLimit));
       
   121     if ( err == KErrNone )
       
   122         return ETrue;
       
   123 
       
   124     return EFalse;
       
   125     }
       
   126 
       
   127 //---------------------------------------------------------------
       
   128 // MsgHistoryPrivate::ClearMessagingHistory
       
   129 // @see header
       
   130 //---------------------------------------------------------------
       
   131 TBool MsgHistoryPrivate::ClearMessagingHistory( const TInt aContactId )
       
   132     {
       
   133     TRAPD(err, handler->ClearMessagingHistoryL(aContactId));
       
   134     if ( err == KErrNone )
       
   135         return ETrue;
       
   136 
       
   137     return EFalse;
       
   138     }
       
   139 
       
   140 //---------------------------------------------------------------
       
   141 // MsgHistoryPrivate::MarkReadMessagingHistory
       
   142 // @see header
       
   143 //---------------------------------------------------------------
       
   144 TBool MsgHistoryPrivate::MarkReadMessagingHistory( const TInt aContactId )
       
   145     {
       
   146     TRAPD(err, handler->MarkMessagingHistoryReadL(aContactId));
       
   147     if ( err == KErrNone )
       
   148         return ETrue;
       
   149 
       
   150     return EFalse;
       
   151     }
       
   152 
       
   153 //---------------------------------------------------------------
       
   154 // MsgHistoryPrivate::Subscribe
       
   155 // @see header
       
   156 //---------------------------------------------------------------
       
   157 TBool MsgHistoryPrivate::Subscribe( const TInt aContactId )
       
   158     {
       
   159     TInt conversationId = -1;
       
   160     TRAPD(err, 
       
   161             conversationId = handler->GetConversationIdL(aContactId));
       
   162     CCsClientConversation* clientConversation = CCsClientConversation::NewL();
       
   163     clientConversation->SetConversationEntryId(conversationId);
       
   164     // set the contact id, which will be used in case when the 
       
   165     // conversation entry id is -1.
       
   166     clientConversation->SetContactId(aContactId);
       
   167     //set dummy entry
       
   168     CCsConversationEntry *entry = CCsConversationEntry::NewL();
       
   169     clientConversation->SetConversationEntryL(entry);
       
   170 
       
   171     handler->RequestConversationChangeEventL(this, clientConversation);
       
   172     delete clientConversation;
       
   173     delete entry;        
       
   174     if ( err == KErrNone )
       
   175         return ETrue;
       
   176 
       
   177     return EFalse;
       
   178     }
       
   179 
       
   180 //---------------------------------------------------------------
       
   181 // MsgHistoryPrivate::UnSubscribe
       
   182 // @see header
       
   183 //---------------------------------------------------------------
       
   184 TBool MsgHistoryPrivate::UnSubscribe( const TInt aContactId )
       
   185     {
       
   186     TInt conversationId = -1;
       
   187     TRAPD(err, 
       
   188             conversationId = handler->GetConversationIdL(aContactId));
       
   189     CCsClientConversation* clientConversation = CCsClientConversation::NewL();
       
   190     clientConversation->SetConversationEntryId(conversationId);
       
   191     // set the contact id, which will be used in case when the 
       
   192     // conversation entry id is -1.
       
   193     clientConversation->SetContactId(aContactId);
       
   194     //set dummy entry
       
   195     CCsConversationEntry *entry = CCsConversationEntry::NewL();
       
   196     clientConversation->SetConversationEntryL(entry);
       
   197 
       
   198     handler->RemoveConversationChangeEventL(this, clientConversation);
       
   199     delete clientConversation;
       
   200 		
       
   201 	delete entry;
       
   202     if ( err == KErrNone )
       
   203         return ETrue;
       
   204 
       
   205     return EFalse;
       
   206     }
       
   207 
       
   208 //---------------------------------------------------------------
       
   209 // MsgHistoryPrivate::ConversationList
       
   210 // @see header
       
   211 //---------------------------------------------------------------
       
   212 void MsgHistoryPrivate::ConversationList
       
   213 ( RPointerArray<CCsClientConversation>& /*aClientConversationList*/ )
       
   214     {
       
   215     // No implementation required.
       
   216     }
       
   217 
       
   218 //---------------------------------------------------------------
       
   219 // MsgHistoryPrivate::Conversations
       
   220 // @see header
       
   221 //---------------------------------------------------------------
       
   222 void MsgHistoryPrivate::Conversations
       
   223 ( RPointerArray<CCsConversationEntry>& aConversationEntryList,
       
   224         TInt& aTotalCount)
       
   225     {
       
   226  
       
   227     for(TInt i = 0 ; i < aConversationEntryList.Count(); i++ )
       
   228         {
       
   229         MsgItem item;
       
   230         PopulateMsgItem(item,*(aConversationEntryList[i]));
       
   231         msgs.append(item);
       
   232         }  
       
   233     //emit signal, when all the messages in the conversation are fetched.
       
   234     if(msgs.count()== aTotalCount)
       
   235         {
       
   236             currentState = EInit;
       
   237             q_ptr->messagesReadyEvent(msgs);
       
   238             msgs.clear();
       
   239 
       
   240         }
       
   241         else
       
   242         {
       
   243             currentState = EFetchMoreConversations;
       
   244             IssueRequest();
       
   245         }
       
   246     }
       
   247 
       
   248 //---------------------------------------------------------------
       
   249 // MsgHistoryPrivate::AddConversation
       
   250 // @see header
       
   251 //---------------------------------------------------------------
       
   252 void MsgHistoryPrivate::AddConversation 
       
   253 ( const CCsConversationEntry& aConversationEntry )
       
   254     {
       
   255     MsgItem item;
       
   256     PopulateMsgItem(item, aConversationEntry);
       
   257     q_ptr->messageAddedEvent(item);
       
   258     }
       
   259 
       
   260 //---------------------------------------------------------------
       
   261 // MsgHistoryPrivate::ModifyConversation
       
   262 // @see header
       
   263 //---------------------------------------------------------------
       
   264 void MsgHistoryPrivate::ModifyConversation
       
   265 ( const CCsConversationEntry& aConversationEntry )
       
   266     {
       
   267     MsgItem item;
       
   268     PopulateMsgItem(item, aConversationEntry);
       
   269     q_ptr->messageChangedEvent(item);
       
   270     }
       
   271 
       
   272 //---------------------------------------------------------------
       
   273 // MsgHistoryPrivate::DeleteConversation
       
   274 // @see header
       
   275 //---------------------------------------------------------------
       
   276 void MsgHistoryPrivate::DeleteConversation
       
   277 ( const CCsConversationEntry& aConversationEntry )
       
   278     {
       
   279     MsgItem item;
       
   280     PopulateMsgItem(item, aConversationEntry);
       
   281     q_ptr->messageDeletedEvent(item);
       
   282     }
       
   283 
       
   284 //---------------------------------------------------------------
       
   285 // MsgHistoryPrivate::RefreshConversation
       
   286 // @see header
       
   287 //---------------------------------------------------------------
       
   288 void MsgHistoryPrivate::RefreshConversation()
       
   289     {
       
   290     // No implementation required.
       
   291     }
       
   292 
       
   293 //---------------------------------------------------------------
       
   294 // MsgHistoryPrivate::populateMsgItem
       
   295 // @see header
       
   296 //---------------------------------------------------------------
       
   297 void MsgHistoryPrivate::PopulateMsgItem
       
   298 (MsgItem& item, const CCsConversationEntry& entry)
       
   299     {
       
   300     // id             
       
   301     item.setId(entry.EntryId());
       
   302     
       
   303     // message type.        
       
   304     item.setType((MsgItem::MsgType)entry.GetType());
       
   305 
       
   306     // description
       
   307     HBufC* description = entry.Description();    
       
   308     if( description && description->Length())
       
   309         {
       
   310         item.setBody(XQConversions::s60DescToQString(*description)); 
       
   311         }
       
   312 
       
   313     // time stamp 
       
   314     TTime unixEpoch(KUnixEpoch);
       
   315     TTimeIntervalSeconds seconds;
       
   316     TTime timeStamp(entry.TimeStamp() );
       
   317     timeStamp.SecondsFrom(unixEpoch, seconds);    
       
   318     item.setTimeStamp(seconds.Int());
       
   319 
       
   320     //contact details
       
   321     HBufC* contact = entry.Contact();
       
   322     if( contact && contact->Length())
       
   323         {
       
   324         item.setPhoneNumber(XQConversions::s60DescToQString(*contact));      
       
   325         }
       
   326 
       
   327     //sending state
       
   328     item.setState((MsgItem::MsgState)entry.GetSendState());    
       
   329     
       
   330     // direction
       
   331     item.setDirection((MsgItem::MsgDirection)entry.ConversationDir());  
       
   332     
       
   333     //attributes
       
   334     SetMsgAttributes(item, entry);    
       
   335     }
       
   336 
       
   337 //---------------------------------------------------------------
       
   338 // MsgHistoryPrivate::SetMsgAttributes
       
   339 // @see header
       
   340 //---------------------------------------------------------------
       
   341 void MsgHistoryPrivate::SetMsgAttributes
       
   342 (MsgItem& item, const CCsConversationEntry& entry)
       
   343     {
       
   344     //draft
       
   345     if(entry.IsAttributeSet(ECsAttributeDraft))
       
   346         {
       
   347         item.changeAttributes(MsgItem::MsgAttributeDraft); 
       
   348         }
       
   349     //sent
       
   350     if(entry.IsAttributeSet(ECsAttributeSent))
       
   351         {
       
   352         item.changeAttributes(MsgItem::MsgAttributeSent);  
       
   353         }
       
   354     //new
       
   355     if(entry.IsAttributeSet(ECsAttributeNew))
       
   356         {
       
   357         item.changeAttributes(MsgItem::MsgAttributeNew); 
       
   358         }
       
   359     //unread
       
   360     if(entry.IsAttributeSet(ECsAttributeUnread))
       
   361         {
       
   362         item.changeAttributes(MsgItem::MsgAttributeUnread); 
       
   363         }
       
   364     //High priority
       
   365     if(entry.IsAttributeSet(ECsAttributeHighPriority))
       
   366         {
       
   367         item.changeAttributes(MsgItem::MsgAttributeHighPriority); 
       
   368         }
       
   369     //low priority
       
   370     if(entry.IsAttributeSet(ECsAttributeLowPriority))
       
   371         {
       
   372         item.changeAttributes(MsgItem::MsgAttributeLowPriority); 
       
   373         }
       
   374     //attachment
       
   375     if(entry.IsAttributeSet(ECsAttributeAttachment))
       
   376         {
       
   377         item.changeAttributes(MsgItem::MsgAttributeAttachment); 
       
   378         }
       
   379     }
       
   380 
       
   381 //EOF