messagingapp/msgappfw/utils/src/ccsconversationentry.cpp
changeset 23 238255e8b033
child 34 84197e66a4bd
child 37 518b245aa84c
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Client side class to hold the conversation entry.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <ccsconversationentry.h>
       
    21 
       
    22 // USER INCLUDE FILES
       
    23 #include "ccsdebug.h"
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KMaxDescrSize = 1500; // Message body restricted to this size
       
    27 
       
    28 // ============================== MEMBER FUNCTIONS ============================
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CCsConEntry::CCsConEntry
       
    32 // Default constructor
       
    33 // ----------------------------------------------------------------------------
       
    34 CCsConversationEntry::CCsConversationEntry()
       
    35     {
       
    36     }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CCsConversationEntry::ConstructL
       
    40 // Two phase construction
       
    41 // ----------------------------------------------------------------------------
       
    42 void CCsConversationEntry::ConstructL()
       
    43     {
       
    44     iEntryID = 0;
       
    45     iTimeStamp = 0;
       
    46     iContact = NULL;
       
    47     iConversationDir = ECsDirectionUnknown;
       
    48     iDescription = NULL;
       
    49     iConversationType = ECsUnknown;
       
    50     iConversationAttrib = ECsAttributeNone;
       
    51     iConversationStatus = ECsSendStateUnknown;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CCsConversationEntry::NewL
       
    56 // Two Phase constructor
       
    57 // ----------------------------------------------------------------------------
       
    58 EXPORT_C CCsConversationEntry* CCsConversationEntry::NewL()
       
    59     {
       
    60     CCsConversationEntry* self = new (ELeave) CCsConversationEntry();
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CCsConversationEntry::~CCsConversationEntry
       
    69 // Destructor
       
    70 // ----------------------------------------------------------------------------
       
    71 EXPORT_C CCsConversationEntry::~CCsConversationEntry()
       
    72     {
       
    73     // delete the iContact if its allocated
       
    74     if(iContact)
       
    75         {
       
    76         delete iContact;
       
    77         iContact = NULL;
       
    78         }
       
    79     
       
    80     // delete the iDescription if its allocated
       
    81     if(iDescription)
       
    82         {
       
    83         delete iDescription;
       
    84         iDescription = NULL;
       
    85         }
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CCsConEntry::EntryId
       
    90 // Returns the EntryId of the object
       
    91 // ----------------------------------------------------------------------------
       
    92 EXPORT_C TInt CCsConversationEntry::EntryId() const
       
    93 {
       
    94 return iEntryID;
       
    95 }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // CCsConversationEntry::SetEntryId
       
    99 // Sets the entryID of this object
       
   100 // ----------------------------------------------------------------------------
       
   101 EXPORT_C void CCsConversationEntry::SetEntryId(const TInt aEnryId)
       
   102     {
       
   103     iEntryID = aEnryId;
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // CCsConversationEntry::TimeStamp
       
   108 // Provides the Conversation TimeStamp of this object
       
   109 // ----------------------------------------------------------------------------
       
   110 EXPORT_C TInt64 CCsConversationEntry::TimeStamp() const
       
   111     {
       
   112     return iTimeStamp;
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // CCsConversationEntry::SetTimeStampL
       
   117 // Sets the Conversation TimeStamp of this object
       
   118 // ----------------------------------------------------------------------------
       
   119 EXPORT_C void CCsConversationEntry::SetTimeStampL(const TInt64 aTimeStamp)
       
   120     {
       
   121     iTimeStamp = aTimeStamp;
       
   122     }
       
   123 
       
   124 // ----------------------------------------------------------------------------
       
   125 // CCsConversationEntry::Contact
       
   126 // Provides the Conversation contact of this object
       
   127 // ----------------------------------------------------------------------------
       
   128 EXPORT_C HBufC* CCsConversationEntry::Contact() const
       
   129     {
       
   130     return iContact;
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CCsConversationEntry::SetContactL
       
   135 // Sets the Conversation contact of this object
       
   136 // ----------------------------------------------------------------------------
       
   137 EXPORT_C void CCsConversationEntry::SetContactL(const TDesC& aContact)
       
   138     {
       
   139     if((&aContact))
       
   140         {
       
   141         iContact = aContact.AllocL();
       
   142         }
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // CCsConversationEntry::ConversationDir
       
   147 // Provides the Conversation direction of this object
       
   148 // ----------------------------------------------------------------------------
       
   149 EXPORT_C TCsDirection CCsConversationEntry::ConversationDir() const
       
   150     {
       
   151     return iConversationDir;
       
   152     }
       
   153 
       
   154 // ----------------------------------------------------------------------------
       
   155 // CCsConversationEntry::SetConversationDir
       
   156 // Sets the Conversation direction of this object
       
   157 // ----------------------------------------------------------------------------
       
   158 EXPORT_C void CCsConversationEntry::SetConversationDir(
       
   159         const TCsDirection aConversationDir)
       
   160     {
       
   161     iConversationDir = aConversationDir;
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CCsConversationEntry::GetType
       
   166 // Provides the conversation flags of the object
       
   167 // ----------------------------------------------------------------------------
       
   168 EXPORT_C TCsType CCsConversationEntry::GetType() const
       
   169     {
       
   170     return iConversationType;
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // CCsConversationEntry::SetType
       
   175 // Sets the conversation flags of this object
       
   176 // ----------------------------------------------------------------------------
       
   177 EXPORT_C void CCsConversationEntry::SetType(const TCsType& aCsConversationType)
       
   178     {
       
   179     iConversationType = aCsConversationType;
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CCsConversationEntry::GetSendState
       
   184 // Provides the conversation status of this object
       
   185 // ----------------------------------------------------------------------------
       
   186 EXPORT_C TCsSendState CCsConversationEntry::GetSendState() const
       
   187     {
       
   188     return iConversationStatus;
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CCsConversationEntry::SetSendState
       
   193 // Sets the conversation status of this object
       
   194 // ----------------------------------------------------------------------------
       
   195 EXPORT_C void CCsConversationEntry::SetSendState(const TCsSendState& aCsConversationStatus)
       
   196     {
       
   197     iConversationStatus = aCsConversationStatus;
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // CCsConversationEntry::Description
       
   202 // Provides the Conversation description(body) of this object
       
   203 // ----------------------------------------------------------------------------
       
   204 EXPORT_C HBufC* CCsConversationEntry::Description() const
       
   205     {
       
   206     return iDescription;
       
   207     }
       
   208 
       
   209 // ----------------------------------------------------------------------------
       
   210 // CCsConversationEntry::SetDescriptionL
       
   211 // Sets the Conversation description of this object
       
   212 // ----------------------------------------------------------------------------
       
   213 EXPORT_C void CCsConversationEntry::SetDescriptionL(const TDesC& aDescription)
       
   214     {
       
   215     if((&aDescription))
       
   216         {
       
   217         TInt descrLength = aDescription.Length();
       
   218         if ( descrLength > KMaxDescrSize )
       
   219             descrLength = KMaxDescrSize;
       
   220         
       
   221         iDescription = HBufC::NewL(descrLength);
       
   222         iDescription->Des().Copy(aDescription.Left(descrLength));
       
   223         }
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // CCsConversationEntry::ChangeAttributes
       
   228 // Sets or Clears the given attribute(s).
       
   229 // ----------------------------------------------------------------------------
       
   230 EXPORT_C void CCsConversationEntry::ChangeAttributes( TUint16 aSetAttributes,
       
   231         TUint16 aClearAttributes )
       
   232     {
       
   233     // Set attribute(s)
       
   234     iConversationAttrib |= aSetAttributes;
       
   235 
       
   236     // Clear atttibute(s)
       
   237     iConversationAttrib &= ~aClearAttributes;
       
   238     }
       
   239 
       
   240 // ----------------------------------------------------------------------------
       
   241 // CCsConversationEntry::IsAttributeSet
       
   242 // Checks if the give attribute is set.
       
   243 // ----------------------------------------------------------------------------
       
   244 EXPORT_C TBool CCsConversationEntry::IsAttributeSet(TCsAttribute aAttribute ) const
       
   245     {
       
   246     return ( iConversationAttrib & aAttribute );
       
   247     }
       
   248 
       
   249 // ----------------------------------------------------------------------------
       
   250 // CCsConversationEntry::CloneL
       
   251 // Provides the clone of this object
       
   252 // ----------------------------------------------------------------------------
       
   253 EXPORT_C CCsConversationEntry* CCsConversationEntry::CloneL() const
       
   254     {
       
   255     CCsConversationEntry* cloneObject = CCsConversationEntry::NewL();
       
   256     CleanupStack::PushL(cloneObject);
       
   257 
       
   258     cloneObject->SetContactL(*iContact);
       
   259     cloneObject->SetConversationDir(iConversationDir);
       
   260     cloneObject->SetType(iConversationType);
       
   261     cloneObject->SetEntryId(iEntryID);
       
   262     cloneObject->SetSendState(iConversationStatus);
       
   263     cloneObject->ChangeAttributes(iConversationAttrib, ECsAttributeNone);
       
   264     cloneObject->SetDescriptionL(*iDescription);
       
   265     cloneObject->SetTimeStampL(iTimeStamp);
       
   266 
       
   267     CleanupStack::Pop(cloneObject);
       
   268     return cloneObject;
       
   269     }
       
   270 
       
   271 //------------------------------------------------------------------------------
       
   272 // CCsConversationEntry::ExternalizeL
       
   273 // Writes CCsConversationEntry variable to the stream
       
   274 // ----------------------------------------------------------------------------
       
   275 EXPORT_C  void CCsConversationEntry::ExternalizeL(RWriteStream& aStream) const
       
   276     {
       
   277     // write iEntryId into the stream
       
   278     aStream.WriteInt32L(iEntryID);
       
   279 
       
   280     // write iTimeStamp
       
   281     aStream.WriteReal64L(iTimeStamp);
       
   282 
       
   283     // write iConversationAttrib
       
   284     aStream.WriteUint16L(iConversationAttrib);
       
   285 
       
   286     if (iContact)
       
   287         {
       
   288         // write iContact length
       
   289         aStream.WriteInt8L(iContact->Length());
       
   290         // write iContact
       
   291         aStream << *iContact;
       
   292         }
       
   293     else
       
   294         {
       
   295         // write 0 contact len
       
   296         aStream.WriteInt8L(0);
       
   297         }
       
   298 
       
   299     // write iConDir length
       
   300     aStream.WriteUint8L(iConversationDir);
       
   301 
       
   302     if (iDescription)
       
   303         {
       
   304         // write iDescription length
       
   305         aStream.WriteUint16L(iDescription->Length());
       
   306         // write iDescription
       
   307         aStream << *iDescription;
       
   308         }
       
   309     else
       
   310         {
       
   311         // write 0 iDescription len
       
   312         aStream.WriteUint16L(0);
       
   313         }
       
   314 
       
   315     // write iConversationType
       
   316     aStream.WriteUint8L(iConversationType);
       
   317 
       
   318     // write iConversationStatus
       
   319     aStream.WriteUint8L(iConversationStatus);
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CCsConversationEntry::InternalizeL
       
   324 // Initializes CCsConversationEntry from stream
       
   325 // ----------------------------------------------------------------------------
       
   326 EXPORT_C  void CCsConversationEntry::InternalizeL(RReadStream& aStream)
       
   327     {
       
   328     // Read iEntryID length
       
   329     iEntryID = aStream.ReadInt32L();
       
   330 
       
   331     // read iTimeStamp
       
   332     iTimeStamp = aStream.ReadReal64L();
       
   333 
       
   334     // read iConversationAttrib
       
   335     iConversationAttrib = aStream.ReadUint16L();
       
   336 
       
   337     // Read iContact length
       
   338     TInt lenContact = aStream.ReadInt8L();
       
   339 
       
   340     if (lenContact > 0)
       
   341         {
       
   342         // read iContact
       
   343         iContact = HBufC::NewL(aStream, lenContact);
       
   344         }
       
   345     else
       
   346         iContact = NULL;
       
   347 
       
   348     // Read iConversationDir
       
   349     iConversationDir =
       
   350         static_cast<TCsDirection> (aStream.ReadUint8L());
       
   351 
       
   352     // Read iDescription length
       
   353     TInt lenDescription = aStream.ReadUint16L();
       
   354 
       
   355     if (lenDescription > 0)
       
   356         {
       
   357         // read iDescription
       
   358         iDescription = HBufC::NewL(aStream, lenDescription);
       
   359         }
       
   360     
       
   361     // Read iConversationType
       
   362     iConversationType =
       
   363         static_cast<TCsType> (aStream.ReadUint8L());
       
   364 
       
   365     // Read iConversationStatus
       
   366     iConversationStatus =
       
   367         static_cast<TCsSendState> (aStream.ReadUint8L());
       
   368     }
       
   369 
       
   370 //-----------------------------------------------------------------------------
       
   371 // CCsConversationEntry::Compare
       
   372 // Compare to conversation entry object based on timestamp
       
   373 //----------------------------------------------------------------------------
       
   374 EXPORT_C TInt CCsConversationEntry::Compare(
       
   375         const CCsConversationEntry& aFirst,
       
   376         const CCsConversationEntry& aSecond)
       
   377     {
       
   378 
       
   379     if (aFirst.EntryId() < aSecond.EntryId())
       
   380         return -1;
       
   381     if (aFirst.EntryId() > aSecond.EntryId())
       
   382         return 1;
       
   383     return 0;
       
   384     }
       
   385 
       
   386 //-----------------------------------------------------------------------------
       
   387 // CCsConversationEntry::CompareById
       
   388 // Compare to conversation entry object based on Entry Ids
       
   389 //----------------------------------------------------------------------------
       
   390 EXPORT_C TBool CCsConversationEntry::CompareById(
       
   391         const CCsConversationEntry& aFirst,
       
   392         const CCsConversationEntry& aSecond)
       
   393     {
       
   394     if (aFirst.EntryId() == aSecond.EntryId())
       
   395         return ETrue;
       
   396     
       
   397     return EFalse;
       
   398     }
       
   399 
       
   400 //-----------------------------------------------------------------------------
       
   401 // CCsConversationEntry::CompareByUnreadAttrib
       
   402 // Compare to conversation entry object based on their unread attribute.
       
   403 //----------------------------------------------------------------------------
       
   404 EXPORT_C TBool CCsConversationEntry::CompareByUnreadAttrib(
       
   405         const CCsConversationEntry& aFirst,
       
   406         const CCsConversationEntry& aSecond)
       
   407     {
       
   408     if (aFirst.IsAttributeSet(ECsAttributeUnread) ==
       
   409             aSecond.IsAttributeSet(ECsAttributeUnread))
       
   410         return ETrue;
       
   411 
       
   412     return EFalse;
       
   413     }
       
   414 
       
   415 //EOF