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