|
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: This Class handles Add, Delete & Modify conversation list client events. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "conversationlistchangehandler.h" |
|
19 |
|
20 // SYSTEM INCLUDES |
|
21 #include <ccsconversationentry.h> |
|
22 #include <ccsclientconversation.h> |
|
23 // USER INCLUDE |
|
24 #include "conversationsengine_p.h" |
|
25 #include "conversationsengine.h" |
|
26 #include "conversationssummarymodel.h" |
|
27 |
|
28 TInt ListWindowSize = 7; |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 ConversationsListChangeHandler::ConversationsListChangeHandler( |
|
34 ConversationsEnginePrivate* convEnginePrivate, |
|
35 ConversationsSummaryModel* conversationsSummaryModel) : |
|
36 CActive(EPriorityStandard), |
|
37 mCurrentState(EInit), |
|
38 mFirstWindowCached(EFalse), |
|
39 mCurrentIndex(-1), |
|
40 mConvSummaryModel(conversationsSummaryModel), |
|
41 mConvEnginePrivate(convEnginePrivate) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Destructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 ConversationsListChangeHandler::~ConversationsListChangeHandler() |
|
51 { |
|
52 mClientConversationList.ResetAndDestroy(); |
|
53 // Cancel the active object |
|
54 Cancel(); |
|
55 } |
|
56 |
|
57 //----------------------------------------------------------------------- |
|
58 // From CActive class. |
|
59 //----------------------------------------------------------------------- |
|
60 // |
|
61 void ConversationsListChangeHandler::RunL() |
|
62 { |
|
63 if (iStatus != KErrNone) |
|
64 { |
|
65 // Reading events has failed |
|
66 return; |
|
67 } |
|
68 else |
|
69 { |
|
70 switch (mCurrentState) |
|
71 { |
|
72 case EInitialCache: |
|
73 { |
|
74 HandleConversationListL(); |
|
75 break; |
|
76 } |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 //----------------------------------------------------------------------- |
|
82 // From CActive class. |
|
83 //----------------------------------------------------------------------- |
|
84 // |
|
85 void ConversationsListChangeHandler::DoCancel() |
|
86 { |
|
87 mCurrentState = EListenToEvents; |
|
88 } |
|
89 |
|
90 //----------------------------------------------------------------------- |
|
91 // From CActive class. |
|
92 //----------------------------------------------------------------------- |
|
93 // |
|
94 void ConversationsListChangeHandler::ConversationListL(RPointerArray< |
|
95 CCsClientConversation>& aClientConversationList) |
|
96 { |
|
97 mClientConversationList.ResetAndDestroy(); |
|
98 |
|
99 for (TInt i = 0; i < aClientConversationList.Count(); ++i) |
|
100 { |
|
101 CCsClientConversation *entry = aClientConversationList[i]->CloneL(); |
|
102 mClientConversationList.AppendL(entry); |
|
103 } |
|
104 |
|
105 if (aClientConversationList.Count() > 0) |
|
106 { |
|
107 mCurrentIndex = 0; |
|
108 mFirstWindowCached = EFalse; |
|
109 mCurrentState = EInitialCache; |
|
110 IssueRequest(); |
|
111 } |
|
112 else |
|
113 { |
|
114 mConvEnginePrivate->registerForConversationListUpdatesL(); |
|
115 mCurrentState = EListenToEvents; |
|
116 } |
|
117 } |
|
118 |
|
119 //----------------------------------------------------------------------- |
|
120 // This is for handling new conversation event asynchronusly from the server |
|
121 //----------------------------------------------------------------------- |
|
122 // |
|
123 void ConversationsListChangeHandler::AddConversationList( |
|
124 const CCsClientConversation& aClientConversation) |
|
125 { |
|
126 mConvSummaryModel->addRow(aClientConversation); |
|
127 } |
|
128 |
|
129 //----------------------------------------------------------------------- |
|
130 // This is for handling delete conversation event asynchronusly from the server |
|
131 //----------------------------------------------------------------------- |
|
132 // |
|
133 void ConversationsListChangeHandler::DeleteConversationList( |
|
134 const CCsClientConversation& aClientConversation) |
|
135 { |
|
136 mConvSummaryModel->deleteRow(aClientConversation.GetConversationEntryId()); |
|
137 } |
|
138 |
|
139 //----------------------------------------------------------------------- |
|
140 // This is for handling modify conversation event asynchronusly from the server |
|
141 //----------------------------------------------------------------------- |
|
142 // |
|
143 void ConversationsListChangeHandler::ModifyConversationList( |
|
144 const CCsClientConversation& aClientConversation) |
|
145 { |
|
146 mConvSummaryModel->addRow(aClientConversation); |
|
147 } |
|
148 |
|
149 //----------------------------------------------------------------------- |
|
150 // This is for handling refresh conversation event asynchronusly from the server |
|
151 //----------------------------------------------------------------------- |
|
152 // |
|
153 void ConversationsListChangeHandler::RefreshConversationList() |
|
154 { |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Make the active object alive. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void ConversationsListChangeHandler::IssueRequest() |
|
162 { |
|
163 if (!IsActive()) |
|
164 { |
|
165 iStatus = KRequestPending; |
|
166 TRequestStatus* status = &iStatus; |
|
167 SetActive(); |
|
168 User::RequestComplete(status, KErrNone); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // Handles Conversation List received from server and updates into model |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void ConversationsListChangeHandler::HandleConversationListL() |
|
177 { |
|
178 for (int i = 0; i < ListWindowSize; ++i) |
|
179 { |
|
180 if (mCurrentIndex < mClientConversationList.Count()) |
|
181 { |
|
182 mConvSummaryModel->addRow( |
|
183 * (mClientConversationList[mCurrentIndex])); |
|
184 mCurrentIndex++; |
|
185 } |
|
186 else |
|
187 { |
|
188 break; |
|
189 } |
|
190 } |
|
191 if (mCurrentIndex < mClientConversationList.Count()) |
|
192 { |
|
193 if (!mFirstWindowCached) |
|
194 { |
|
195 ConversationsEngine::instance()-> |
|
196 emitConversationListModelPopulated(); |
|
197 mFirstWindowCached = ETrue; |
|
198 } |
|
199 IssueRequest(); |
|
200 } |
|
201 else |
|
202 { |
|
203 if (!mFirstWindowCached) |
|
204 { |
|
205 ConversationsEngine::instance()-> |
|
206 emitConversationListModelPopulated(); |
|
207 mFirstWindowCached = ETrue; |
|
208 } |
|
209 mClientConversationList.ResetAndDestroy(); |
|
210 mConvEnginePrivate->registerForConversationListUpdatesL(); |
|
211 mCurrentState = EListenToEvents; |
|
212 } |
|
213 |
|
214 } |
|
215 |
|
216 // EOF |