|
1 /* |
|
2 * Copyright (c) 2003 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 * Changes message flag. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "MceChangeFlagOperation.h" // header |
|
23 |
|
24 #include <msvids.h> // KMsvRootIndexEntryId |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 _LIT8 ( KMceSpace8, " " ); // 8 bit space |
|
29 |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // ---------------------------------------------------- |
|
34 // CMceRemoveNewFlag::NewL |
|
35 // Two-phased constructor. |
|
36 // ---------------------------------------------------- |
|
37 CMceRemoveNewFlag* CMceRemoveNewFlag::NewL( |
|
38 TUint32 aRemoveFlags, |
|
39 CMsvSession& aMsvSession, |
|
40 TRequestStatus& aObserverRequestStatus, |
|
41 CMsvEntrySelection* aSelection ) |
|
42 { |
|
43 CMceRemoveNewFlag* self=new (ELeave) CMceRemoveNewFlag( |
|
44 aRemoveFlags, aMsvSession, aObserverRequestStatus, KMsvRootIndexEntryId, aSelection ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------- |
|
52 // CMceRemoveNewFlag::CMceRemoveNewFlag |
|
53 // Constructor. |
|
54 // ---------------------------------------------------- |
|
55 CMceRemoveNewFlag::CMceRemoveNewFlag( |
|
56 TUint32 aRemoveFlags, |
|
57 CMsvSession& aMsvSession, |
|
58 TRequestStatus& aObserverRequestStatus, |
|
59 TMsvId aFolderId, |
|
60 CMsvEntrySelection* aSelection ) |
|
61 : |
|
62 CMsvOperation(aMsvSession, CActive::EPriorityStandard, aObserverRequestStatus), |
|
63 iFolderId( aFolderId ), |
|
64 iEntrySelection( aSelection ), |
|
65 iBlank( KMceSpace8 ) |
|
66 { |
|
67 CActiveScheduler::Add( this ); |
|
68 iRemoveFlags.SetMceFlag( aRemoveFlags ); |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------- |
|
72 // CMceRemoveNewFlag::~CMceRemoveNewFlag |
|
73 // Destructor. |
|
74 // ---------------------------------------------------- |
|
75 CMceRemoveNewFlag::~CMceRemoveNewFlag() |
|
76 { |
|
77 Cancel(); |
|
78 delete iOperation; |
|
79 delete iEntry; |
|
80 delete iEntrySelection; |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------- |
|
84 // CMceRemoveNewFlag::ConstructL |
|
85 // Constructor.. |
|
86 // ---------------------------------------------------- |
|
87 void CMceRemoveNewFlag::ConstructL() |
|
88 { |
|
89 iCount = iEntrySelection->Count(); |
|
90 iEntry = CMsvEntry::NewL( iMsvSession, iFolderId, TMsvSelectionOrdering() ); |
|
91 |
|
92 if ( iEntrySelection->Count() == 0 ) |
|
93 { |
|
94 iStatus=KRequestPending; |
|
95 SetActive(); |
|
96 TRequestStatus* status = &iStatus; |
|
97 User::RequestComplete( status, KErrNone ); |
|
98 } |
|
99 else |
|
100 { |
|
101 TMsvId serviceId; // not used |
|
102 TMsvEntry entry; |
|
103 for ( TInt loop=iCount-1; loop>=0; loop-- ) |
|
104 { |
|
105 const TMsvId id = iEntrySelection->At( loop ); |
|
106 User::LeaveIfError( iMsvSession.GetEntry( id, serviceId, entry ) ); |
|
107 DeleteFromSelection( loop, entry.Unread() ); |
|
108 } |
|
109 if ( iEntrySelection->Count() > 0 ) |
|
110 { |
|
111 RemoveNextNewFlagL(); |
|
112 } |
|
113 else |
|
114 { |
|
115 //all were read |
|
116 iStatus=KRequestPending; |
|
117 SetActive(); |
|
118 TRequestStatus* status = &iStatus; |
|
119 User::RequestComplete( status, KErrNone ); |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 // CMceRemoveNewFlag::DeleteFromSelection() |
|
127 // ---------------------------------------------------------------------------- |
|
128 // |
|
129 void CMceRemoveNewFlag::DeleteFromSelection( TInt aIndex, TBool aUnread ) |
|
130 { |
|
131 // Remove from selection, |
|
132 // when read and setting to read or |
|
133 // when unread and setting to unread |
|
134 if ( iRemoveFlags.MceFlag( |
|
135 EMceRemoveEntryFlagUnread ) && !aUnread || |
|
136 iRemoveFlags.MceFlag( |
|
137 EMceRemoveEntryFlagNew ) && aUnread ) //Changed from EMceRestoreEntryFlagRead |
|
138 { |
|
139 //remove read entries from selection |
|
140 iEntrySelection->Delete( aIndex ); |
|
141 } |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------- |
|
145 // CMceRemoveNewFlag::RemoveNextNewFlagL |
|
146 // Starts handling next message to mark it read. |
|
147 // ---------------------------------------------------- |
|
148 void CMceRemoveNewFlag::RemoveNextNewFlagL() |
|
149 { |
|
150 delete iOperation; |
|
151 iOperation = NULL; |
|
152 |
|
153 TMsvId serviceId; // not used |
|
154 TMsvEntry entry; |
|
155 const TMsvId id = iEntrySelection->At( 0 ); |
|
156 User::LeaveIfError( iMsvSession.GetEntry( id, serviceId, entry ) ); |
|
157 |
|
158 TRAPD( err, MakeNextRemoveL() ); |
|
159 |
|
160 // whether error or not, remove the data for this operation |
|
161 iEntrySelection->Delete( 0 ); |
|
162 // and set active |
|
163 iStatus=KRequestPending; |
|
164 SetActive(); |
|
165 // if error then complete this pass with the error code |
|
166 if ( err ) |
|
167 { |
|
168 TRequestStatus* status = &iStatus; |
|
169 User::RequestComplete( status, err ); |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 // ---------------------------------------------------- |
|
175 // CMceRemoveNewFlag::MakeNextRemoveL |
|
176 // Marks message read. |
|
177 // ---------------------------------------------------- |
|
178 void CMceRemoveNewFlag::MakeNextRemoveL() |
|
179 { |
|
180 iEntry->SetEntryL( (*iEntrySelection)[0] ); |
|
181 iNewEntry = iEntry->Entry(); |
|
182 |
|
183 // In no case that mce should set a message new |
|
184 // it used to be "!iRemoveFlags.MceFlag( EMceRemoveEntryFlagNew )" for some unknown reason |
|
185 iNewEntry.SetNew( EFalse ); |
|
186 iNewEntry.SetUnread( !iRemoveFlags.MceFlag( EMceRemoveEntryFlagUnread ) ); |
|
187 iOperation=iEntry->ChangeL( iNewEntry, iStatus ); |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------- |
|
191 // CMceRemoveNewFlag::DoCancel |
|
192 // Cancels active object. |
|
193 // ---------------------------------------------------- |
|
194 void CMceRemoveNewFlag::DoCancel() |
|
195 { |
|
196 if ( iOperation ) |
|
197 { |
|
198 iOperation->Cancel(); |
|
199 } |
|
200 TRequestStatus* status = &iObserverRequestStatus; |
|
201 User::RequestComplete( status, iStatus.Int() ); |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------- |
|
205 // CMceRemoveNewFlag::RunL |
|
206 // Runs active object. |
|
207 // ---------------------------------------------------- |
|
208 void CMceRemoveNewFlag::RunL() |
|
209 { |
|
210 if ( iEntrySelection->Count()==0 ) |
|
211 { |
|
212 // nothing left to process, so complete the observer |
|
213 TRequestStatus* status = &iObserverRequestStatus; |
|
214 User::RequestComplete( status, iStatus.Int() ); |
|
215 } |
|
216 else |
|
217 { |
|
218 // start the next pass |
|
219 RemoveNextNewFlagL(); |
|
220 } |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------- |
|
224 // CMceRemoveNewFlag::ProgressL |
|
225 // Progressing of active object. |
|
226 // ---------------------------------------------------- |
|
227 const TDesC8& CMceRemoveNewFlag::ProgressL() |
|
228 { |
|
229 if ( iOperation ) |
|
230 { |
|
231 return iOperation->ProgressL(); |
|
232 } |
|
233 return iBlank; |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CMceRemoveNewFlag::DecodeProgress |
|
238 // |
|
239 // --------------------------------------------------------- |
|
240 // |
|
241 TInt CMceRemoveNewFlag::DecodeProgress( |
|
242 const TDesC8& /*aProgress*/, |
|
243 TBuf<CBaseMtmUi::EProgressStringMaxLen>& aReturnString, |
|
244 TInt& aTotalEntryCount, |
|
245 TInt& aEntriesDone, |
|
246 TInt& aCurrentEntrySize, |
|
247 TInt& aCurrentBytesTrans, |
|
248 TBool /*aInternal*/ ) |
|
249 { |
|
250 aCurrentEntrySize = aTotalEntryCount = iCount; |
|
251 aCurrentBytesTrans = aEntriesDone = iCount - (iEntrySelection->Count()); |
|
252 aReturnString.Copy( _L("") ); |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 // End of file |