|
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: implementation of header of all convesation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Include Files |
|
20 |
|
21 #include "cimcachemessageheader.h" |
|
22 |
|
23 #include "cimcachemessagebase.h" |
|
24 //logs |
|
25 #include "imcachedebugtrace.h" |
|
26 |
|
27 |
|
28 // CONSTRUCTION |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CIMCacheMessageHeader::NewL |
|
31 // Static constructor |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CIMCacheMessageHeader* CIMCacheMessageHeader::NewL(TInt aServiceId, const TDesC& aBuddyId ) |
|
35 { |
|
36 TRACE( T_LIT( "CIMCacheMessageHeader::NewL begin") ); |
|
37 CIMCacheMessageHeader* self = new (ELeave) CIMCacheMessageHeader; |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL( aServiceId, aBuddyId ); |
|
40 CleanupStack::Pop(); |
|
41 TRACE( T_LIT( "CIMCacheMessageHeader::NewL end") ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CIMCacheMessageHeader::~CIMCacheMessageHeader |
|
48 // Destructor (virtual by CBase) |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CIMCacheMessageHeader::~CIMCacheMessageHeader() |
|
52 { |
|
53 TRACE( T_LIT( "CIMCacheMessageHeader::~CIMCacheMessageHeader begin") ); |
|
54 delete iBuddyId; |
|
55 iMessageArray.ResetAndDestroy() ; // all messages |
|
56 TRACE( T_LIT( "CIMCacheMessageHeader::~CIMCacheMessageHeader end") ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CIMCacheMessageHeader::ConstructL |
|
61 // Second phase construct |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CIMCacheMessageHeader::ConstructL(TInt aServiceId, const TDesC& aBuddyId ) |
|
65 { |
|
66 TRACE( T_LIT( "CIMCacheMessageHeader::ConstructL begin") ); |
|
67 iServiceId = aServiceId; |
|
68 iBuddyId = aBuddyId.AllocL(); |
|
69 TRACE( T_LIT( "CIMCacheMessageHeader::ConstructL end") ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CIMCacheMessageHeader::CIMCacheMessageHeader |
|
74 // Constructor |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CIMCacheMessageHeader::CIMCacheMessageHeader(): |
|
78 iChatStarted( EFalse) |
|
79 { |
|
80 TRACE( T_LIT( "CIMCacheMessageHeader::CIMCacheMessageHeader") ); |
|
81 } |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CIMCacheMessageHeader::Recipient |
|
86 // name of history data |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 const TDesC& CIMCacheMessageHeader::BuddyId() const |
|
90 { |
|
91 TRACE( T_LIT( "CIMCacheMessageHeader::Recipient begin") ); |
|
92 if( iBuddyId ) |
|
93 { |
|
94 return *iBuddyId; |
|
95 } |
|
96 TRACE( T_LIT( "CIMCacheMessageHeader::Recipient end") ); |
|
97 return KNullDesC; |
|
98 |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CIMCacheMessageHeader::ServiceId |
|
103 // name of history data |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 TInt CIMCacheMessageHeader::ServiceId() const |
|
107 { |
|
108 return iServiceId; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CIMCacheMessageHeader::MessageCount |
|
113 // name of history data |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CIMCacheMessageHeader::MessageCount() const |
|
117 { |
|
118 return iMessageArray.Count(); |
|
119 } |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CIMCacheMessageHeader::GetMessage |
|
122 // name of history data |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 CIMCacheMessageBase* CIMCacheMessageHeader::GetMessage(TInt aIndex ) |
|
126 { |
|
127 return iMessageArray[aIndex]; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CIMCacheMessageHeader::AppendMessageL |
|
132 // name of history data |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CIMCacheMessageHeader::AppendMessageL(CIMCacheMessageBase* aMessge) |
|
136 { |
|
137 TRACE( T_LIT( "CIMCacheMessageHeader::AppendMessageL begin") ); |
|
138 |
|
139 iMessageArray.AppendL( aMessge ); |
|
140 |
|
141 TRACE( T_LIT( "CIMCacheMessageHeader::AppendMessageL end") ); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CIMCacheMessageHeader::UnreadMessageCount |
|
146 // name of history data |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CIMCacheMessageHeader::UnreadMessageCount() const |
|
150 { |
|
151 TRACE( T_LIT( "CIMCacheMessageHeader::UnreadMessageCount begin") ); |
|
152 TInt ret = 0; |
|
153 TInt msgcount = iMessageArray.Count(); |
|
154 for(TInt i=0; i<msgcount; i++ ) |
|
155 { |
|
156 CIMCacheMessageBase* msg = iMessageArray[i]; |
|
157 if(msg->IsUnread() ) |
|
158 { |
|
159 ret++; |
|
160 } |
|
161 } |
|
162 TRACE( T_LIT( "CIMCacheMessageHeader::UnreadMessageCount end") ); |
|
163 return ret; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CIMCacheMessageHeader::IsChatStarted |
|
168 // name of history data |
|
169 //----------------------------------------------------------------------------- |
|
170 TBool CIMCacheMessageHeader::IsChatStarted() |
|
171 { |
|
172 return iChatStarted; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CIMCacheMessageHeader::SetChatStarted |
|
177 // name of history data |
|
178 //----------------------------------------------------------------------------- |
|
179 void CIMCacheMessageHeader::SetChatStarted(TBool aStarted ) |
|
180 { |
|
181 iChatStarted = aStarted; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CIMCacheMessageHeader::MarkAllRead |
|
186 // name of history data |
|
187 //----------------------------------------------------------------------------- |
|
188 void CIMCacheMessageHeader::MarkAllRead() |
|
189 { |
|
190 TInt unreadCount = UnreadMessageCount(); |
|
191 TInt count = MessageCount(); |
|
192 |
|
193 for( TInt i = count-1; i >= count- unreadCount; i-- ) |
|
194 { |
|
195 iMessageArray[i]->SetRead(); |
|
196 } |
|
197 } |
|
198 |
|
199 // End of File |