|
1 /* |
|
2 * Copyright (c) 2005-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: Part of SyncML Data Synchronization Plug In Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <msvapi.h> |
|
22 #include <msvuids.h> |
|
23 #include <msvstd.h> |
|
24 #include <msvids.h> |
|
25 #include "mmsadaptermsvapi.h" |
|
26 #include "logger.h" |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CMmsAdapterMsvApi::NewL |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CMmsAdapterMsvApi* CMmsAdapterMsvApi::NewL( CMsvSession& aMsvSession ) |
|
35 { |
|
36 CMmsAdapterMsvApi* self = new( ELeave ) CMmsAdapterMsvApi( aMsvSession ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CMmsAdapterMsvApi::~CMmsAdapterMsvApi() |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CMmsAdapterMsvApi::~CMmsAdapterMsvApi() |
|
48 { |
|
49 TRACE_FUNC; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CMmsAdapterMsvApi::CMmsAdapterMsvApi |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CMmsAdapterMsvApi::CMmsAdapterMsvApi( CMsvSession& aMsvSession ): |
|
57 iSession( aMsvSession ) |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CMmsAdapterMsvApi::ConstructL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CMmsAdapterMsvApi::ConstructL() |
|
66 { |
|
67 } |
|
68 |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMmsAdapterMsvApi::DeleteUserFolderL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 TInt CMmsAdapterMsvApi::DeleteUserFolderL( TMsvId aUid ) |
|
75 { |
|
76 TRACE_FUNC_ENTRY; |
|
77 |
|
78 CMsvEntry* entry = iSession.GetEntryL(aUid); |
|
79 CleanupStack::PushL(entry); |
|
80 |
|
81 TMsvEntry tEntry = entry->Entry(); |
|
82 TMsvId parent = tEntry.Parent(); |
|
83 |
|
84 if ( tEntry.iType != KUidMsvFolderEntry || parent != KMsvMyFoldersEntryIdValue ) |
|
85 { |
|
86 LOGGER_WRITE( "Not correct folder" ); |
|
87 CleanupStack::PopAndDestroy(entry); |
|
88 LOGGER_LEAVEFN( "MsvApi::DeleteUserFolderL" ); |
|
89 return KErrNotSupported; |
|
90 } |
|
91 |
|
92 CMsvEntrySelection* children = entry->ChildrenL(); |
|
93 TInt count = children->Count(); |
|
94 delete children; |
|
95 |
|
96 if ( count > 0 ) |
|
97 { |
|
98 LOGGER_WRITE( "Folder not empty" ); |
|
99 CleanupStack::PopAndDestroy( entry ); |
|
100 LOGGER_LEAVEFN( "MsvApi::DeleteUserFolderL" ); |
|
101 return KErrInUse; |
|
102 } |
|
103 |
|
104 tEntry.SetReadOnly( EFalse ); |
|
105 entry->ChangeL( tEntry ); |
|
106 |
|
107 entry->SetEntryL( parent ); |
|
108 entry->DeleteL( aUid ); |
|
109 |
|
110 CleanupStack::PopAndDestroy( entry ); |
|
111 TRACE_FUNC_EXIT; |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CMmsAdapterMsvApi::ValidUserFolder |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 TBool CMmsAdapterMsvApi::ValidFolderL( TMsvId aFolder, TBool aOutboxValid ) |
|
120 { |
|
121 TBool valid(EFalse); |
|
122 |
|
123 switch ( aFolder ) |
|
124 { |
|
125 case KMsvGlobalInBoxIndexEntryId: |
|
126 valid = ETrue; |
|
127 break; |
|
128 case KMsvDraftEntryId: |
|
129 valid = ETrue; |
|
130 break; |
|
131 case KMsvSentEntryId: |
|
132 valid = ETrue; |
|
133 break; |
|
134 case KMsvGlobalOutBoxIndexEntryId: |
|
135 if ( aOutboxValid ) |
|
136 { |
|
137 valid = ETrue; |
|
138 } |
|
139 break; |
|
140 case KMsvMyFoldersEntryIdValue: |
|
141 valid = ETrue; |
|
142 break; |
|
143 default: |
|
144 valid = FindUserFolderL( aFolder ); |
|
145 } |
|
146 |
|
147 return valid; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CMmsAdapterMsvApi::FindUserFolderL |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 TBool CMmsAdapterMsvApi::FindUserFolderL( TMsvId aFolder, TPtrC& aName, TTime& aDate ) |
|
155 { |
|
156 TBool found( EFalse ); |
|
157 |
|
158 CMsvEntry* entry = iSession.GetEntryL( KMsvMyFoldersEntryIdValue ); |
|
159 CleanupStack::PushL( entry ); |
|
160 |
|
161 CMsvEntrySelection* selection = entry->ChildrenL(); |
|
162 CleanupStack::PushL( selection ); |
|
163 |
|
164 TMsvId serviceId; |
|
165 TMsvEntry entryT; |
|
166 |
|
167 for ( TInt i = 0; i < selection->Count(); i++ ) |
|
168 { |
|
169 User::LeaveIfError( iSession.GetEntry( selection->At( i ), serviceId, entryT ) ); |
|
170 |
|
171 if ( !entryT.Deleted() && entryT.iType == KUidMsvFolderEntry && entryT.Id() == aFolder ) |
|
172 { |
|
173 found = ETrue; |
|
174 aDate = entryT.iDate; |
|
175 aName.Set( entryT.iDetails ); |
|
176 break; |
|
177 } |
|
178 } |
|
179 |
|
180 CleanupStack::PopAndDestroy( selection ); |
|
181 CleanupStack::PopAndDestroy( entry ); |
|
182 |
|
183 return found; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CMmsAdapterMsvApi::FindUserFolderL |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TBool CMmsAdapterMsvApi::FindUserFolderL( TMsvId aFolder ) |
|
191 { |
|
192 TPtrC name; |
|
193 TTime time; |
|
194 |
|
195 return FindUserFolderL( aFolder, name, time ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CMmsAdapterMsvApi::FindUserFolderL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TBool CMmsAdapterMsvApi::FindUserFolderL( const TDesC& aName, TMsvId& aFolder ) |
|
203 { |
|
204 CMsvEntry* entry = iSession.GetEntryL( KMsvMyFoldersEntryIdValue ); |
|
205 CleanupStack::PushL( entry ); |
|
206 |
|
207 CMsvEntrySelection* selection = entry->ChildrenL(); |
|
208 CleanupStack::PushL( selection ); |
|
209 |
|
210 TBool found( EFalse ); |
|
211 TMsvId serviceId; |
|
212 TMsvEntry entryT; |
|
213 |
|
214 for ( TInt i = 0; i < selection->Count(); i++ ) |
|
215 { |
|
216 User::LeaveIfError( iSession.GetEntry( selection->At( i ), serviceId, entryT ) ); |
|
217 |
|
218 if ( !entryT.Deleted() && entryT.iType == KUidMsvFolderEntry && |
|
219 aName.Compare(entryT.iDescription) == 0 ) |
|
220 { |
|
221 found = ETrue; |
|
222 aFolder = entryT.Id(); |
|
223 break; |
|
224 } |
|
225 } |
|
226 |
|
227 CleanupStack::PopAndDestroy( selection ); |
|
228 CleanupStack::PopAndDestroy( entry ); |
|
229 |
|
230 return found; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CMmsAdapterMsvApi::AddUserFolderL |
|
235 // Creates new user folder |
|
236 // ----------------------------------------------------------------------------- |
|
237 TInt CMmsAdapterMsvApi::AddUserFolderL( TMsvId& aFolder, const TDesC& aName ) |
|
238 { |
|
239 TRACE_FUNC_ENTRY; |
|
240 LOGGER_WRITE_1( "aName: %S", &aName ); |
|
241 |
|
242 // Make sure that we are not going to add same folder twise |
|
243 TBool found( EFalse ); |
|
244 found = FindUserFolderL( aName, aFolder ); |
|
245 if ( found ) |
|
246 { |
|
247 LOGGER_WRITE( "Folder already exists" ); |
|
248 LOGGER_LEAVEFN( "CMmsAdapterMsvApi::AddUserFolderL" ); |
|
249 return KErrNone; |
|
250 } |
|
251 |
|
252 CMsvEntry* entry = iSession.GetEntryL(KMsvMyFoldersEntryIdValue); |
|
253 CleanupStack::PushL( entry ); |
|
254 |
|
255 TTime date; |
|
256 date.UniversalTime(); |
|
257 |
|
258 TMsvEntry folderEntry; |
|
259 folderEntry.iType = KUidMsvFolderEntry; |
|
260 folderEntry.iMtm = KUidMsvLocalServiceMtm; |
|
261 folderEntry.iDetails.Set( aName ); |
|
262 folderEntry.iServiceId = KMsvLocalServiceIndexEntryIdValue; |
|
263 folderEntry.iSize = sizeof( folderEntry ); |
|
264 folderEntry.iDate = date; |
|
265 folderEntry.SetStandardFolder( EFalse ); |
|
266 folderEntry.SetVisible( ETrue ); |
|
267 folderEntry.SetComplete( ETrue ); |
|
268 folderEntry.SetInPreparation( EFalse ); |
|
269 folderEntry.SetReadOnly( EFalse ); |
|
270 |
|
271 entry->CreateL( folderEntry ); |
|
272 CleanupStack::PopAndDestroy( entry ); |
|
273 |
|
274 aFolder = folderEntry.Id(); |
|
275 |
|
276 TRACE_FUNC_EXIT; |
|
277 return KErrNone; |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CMmsAdapterMsvApi::UpdateUserFolderL |
|
282 // Updates user folder (changes name) |
|
283 // ----------------------------------------------------------------------------- |
|
284 TInt CMmsAdapterMsvApi::UpdateUserFolderL( TMsvId aFolder, const TDesC& aName ) |
|
285 { |
|
286 TRACE_FUNC_ENTRY; |
|
287 LOGGER_WRITE_1( "aName: %S", &aName ); |
|
288 |
|
289 CMsvEntry* entry = iSession.GetEntryL( aFolder ); |
|
290 CleanupStack::PushL( entry ); |
|
291 |
|
292 TMsvEntry tEntry = entry->Entry(); |
|
293 |
|
294 if ( tEntry.iType != KUidMsvFolderEntry ) |
|
295 { |
|
296 CleanupStack::PopAndDestroy( entry ); |
|
297 LOGGER_WRITE( "No message folder" ); |
|
298 TRACE_FUNC_EXIT; |
|
299 return KErrNotSupported; |
|
300 } |
|
301 |
|
302 tEntry.iDetails.Set( aName ); |
|
303 tEntry.iDescription.Set( aName ); |
|
304 |
|
305 entry->ChangeL( tEntry ); |
|
306 |
|
307 CleanupStack::PopAndDestroy( entry ); |
|
308 |
|
309 TRACE_FUNC_EXIT; |
|
310 return KErrNone; |
|
311 } |
|
312 |
|
313 // End of file |