|
1 /* |
|
2 * Copyright (c) 2009 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 provides the messaging mw interface for MMS |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <commdb.h> |
|
19 #include <commdbconnpref.h> |
|
20 #include <msvapi.h> |
|
21 #include <msvstd.h> |
|
22 #include <msvuids.h> |
|
23 #include <mmsaccount.h> |
|
24 #include <mmssettings.h> |
|
25 #include <mtclreg.h> //For client reg |
|
26 #include <mmsclient.h> //For MMS client |
|
27 #include <mmsconst.h> |
|
28 |
|
29 #include "debugtraces.h" |
|
30 |
|
31 |
|
32 #include "mmssettingprivate.h" |
|
33 |
|
34 /** |
|
35 * Message Server session event handler |
|
36 */ |
|
37 class CEventHandler : public MMsvSessionObserver |
|
38 { |
|
39 public: |
|
40 void HandleSessionEvent(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, |
|
41 TAny* aArg3); |
|
42 void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, |
|
43 TAny* aArg3); |
|
44 }; |
|
45 void CEventHandler::HandleSessionEvent(TMsvSessionEvent /*aEvent*/, |
|
46 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
47 { |
|
48 } |
|
49 void CEventHandler::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, |
|
50 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
51 { |
|
52 } |
|
53 |
|
54 //two phase constructor |
|
55 MmsSettingsPrivate* MmsSettingsPrivate::NewL() |
|
56 { |
|
57 MmsSettingsPrivate* self = new (ELeave) MmsSettingsPrivate(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 //--------------------------------------------------------------- |
|
65 // MmsSettingsPrivate::MmsSettingsPrivate |
|
66 // @see header |
|
67 //--------------------------------------------------------------- |
|
68 MmsSettingsPrivate::MmsSettingsPrivate() |
|
69 { |
|
70 //do nothing |
|
71 } |
|
72 |
|
73 //2nd phase constructor |
|
74 void MmsSettingsPrivate::ConstructL() |
|
75 { |
|
76 //for debug only |
|
77 //createRepositoryL(); |
|
78 } |
|
79 |
|
80 //--------------------------------------------------------------- |
|
81 // MmsSettingsPrivate::~MmsSettingsPrivate |
|
82 // @see header |
|
83 //--------------------------------------------------------------- |
|
84 MmsSettingsPrivate::~MmsSettingsPrivate() |
|
85 { |
|
86 // do nothing |
|
87 } |
|
88 |
|
89 //--------------------------------------------------------------- |
|
90 // MmsSettingsPrivate::createRepository |
|
91 // @see header |
|
92 //--------------------------------------------------------------- |
|
93 void MmsSettingsPrivate::createRepositoryL() |
|
94 { |
|
95 CEventHandler* pObserver = new (ELeave) CEventHandler(); |
|
96 CleanupStack::PushL(pObserver); |
|
97 |
|
98 CMsvSession* iMsvSession = CMsvSession::OpenSyncL(*pObserver); |
|
99 CleanupStack::PushL(iMsvSession); |
|
100 |
|
101 CMmsSettings* mmsSetting = CMmsSettings::NewL(); |
|
102 CleanupStack::PushL(mmsSetting); |
|
103 |
|
104 mmsSetting->LoadSettingsL(); |
|
105 |
|
106 TMsvId entryToBeKilled = KMsvNullIndexEntryId; |
|
107 // Get access to root index |
|
108 CMsvEntry* cEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId); |
|
109 CleanupStack::PushL(cEntry); |
|
110 |
|
111 entryToBeKilled = mmsSetting->Service(); |
|
112 cEntry->SetSortTypeL(TMsvSelectionOrdering(KMsvNoGrouping, |
|
113 EMsvSortByNone, |
|
114 ETrue)); |
|
115 if (entryToBeKilled == KMsvNullIndexEntryId) |
|
116 { |
|
117 mmsSetting->CreateNewServiceL(*iMsvSession); |
|
118 } |
|
119 |
|
120 CleanupStack::PopAndDestroy(); // cEntry |
|
121 |
|
122 mmsSetting->SetReceivingModeHome(EMmsReceivingAutomatic); |
|
123 mmsSetting->SetReceivingModeForeign(EMmsReceivingAutomatic); |
|
124 |
|
125 mmsSetting->SaveSettingsL(); |
|
126 |
|
127 CleanupStack::PopAndDestroy(3); // settings |
|
128 } |
|
129 |
|
130 void MmsSettingsPrivate::setMMSRetrievalL(MsgSettingEngine::MmsRetrieval aRetrieval) |
|
131 { |
|
132 CEventHandler* pObserver = new (ELeave) CEventHandler(); |
|
133 CleanupStack::PushL(pObserver); |
|
134 |
|
135 CMsvSession* mMsvSession = CMsvSession::OpenSyncL(*pObserver); |
|
136 CleanupStack::PushL(mMsvSession); |
|
137 |
|
138 CClientMtmRegistry* mMtmReg = CClientMtmRegistry::NewL(*mMsvSession); |
|
139 CleanupStack::PushL(mMtmReg); |
|
140 |
|
141 CMmsClientMtm* mMmsClient = static_cast<CMmsClientMtm*> |
|
142 (mMtmReg->NewMtmL(KUidMsgTypeMultimedia)); |
|
143 CleanupStack::PushL(mMmsClient); |
|
144 |
|
145 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
146 CleanupStack::PushL(mMmsSetting); |
|
147 |
|
148 //Load settings |
|
149 mMmsClient->RestoreSettingsL(); |
|
150 mMmsSetting->CopyL( mMmsClient->MmsSettings() ); |
|
151 |
|
152 switch ( aRetrieval ) |
|
153 { |
|
154 case MsgSettingEngine::AutomInHomeNetwork: |
|
155 { |
|
156 mMmsSetting->SetReceivingModeHome( EMmsReceivingAutomatic ); |
|
157 mMmsSetting->SetReceivingModeForeign( EMmsReceivingManual ); |
|
158 break; |
|
159 } |
|
160 case MsgSettingEngine::AlwaysAutomatic: |
|
161 { |
|
162 mMmsSetting->SetReceivingModeHome( EMmsReceivingAutomatic ); |
|
163 mMmsSetting->SetReceivingModeForeign( EMmsReceivingAutomatic ); |
|
164 break; |
|
165 } |
|
166 case MsgSettingEngine::Manual: |
|
167 { |
|
168 mMmsSetting->SetReceivingModeHome( EMmsReceivingManual ); |
|
169 mMmsSetting->SetReceivingModeForeign( EMmsReceivingManual ); |
|
170 break; |
|
171 } |
|
172 case MsgSettingEngine::Off: |
|
173 { |
|
174 mMmsSetting->SetReceivingModeHome( EMmsReceivingPostpone ); |
|
175 mMmsSetting->SetReceivingModeForeign( EMmsReceivingPostpone ); |
|
176 break; |
|
177 } |
|
178 case MsgSettingEngine::No: |
|
179 { |
|
180 mMmsSetting->SetReceivingModeHome( EMmsReceivingReject ); |
|
181 mMmsSetting->SetReceivingModeForeign( EMmsReceivingReject ); |
|
182 break; |
|
183 } |
|
184 default: |
|
185 break; |
|
186 } |
|
187 |
|
188 |
|
189 //save the settings |
|
190 mMmsClient->SetSettingsL( *mMmsSetting ); |
|
191 //TODO:User Input should be blocked when save is being done |
|
192 //This should be called as this takes care of automatic |
|
193 //downloading of messages upon change of retrieval mode |
|
194 mMmsClient->StoreSettingsL(); |
|
195 |
|
196 CleanupStack::PopAndDestroy(5); |
|
197 } |
|
198 |
|
199 void MmsSettingsPrivate::setAnonymousMessagesL(TBool aAnonymous) |
|
200 { |
|
201 CMmsAccount* mMmsAccount = CMmsAccount::NewL(); |
|
202 CleanupStack::PushL(mMmsAccount); |
|
203 |
|
204 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
205 CleanupStack::PushL(mMmsSetting); |
|
206 |
|
207 mMmsAccount->LoadSettingsL(*mMmsSetting); |
|
208 |
|
209 //do your operation |
|
210 mMmsSetting->SetAcceptAnonymousMessages(aAnonymous); |
|
211 |
|
212 //save the settings |
|
213 mMmsAccount->SaveSettingsL(*mMmsSetting); |
|
214 CleanupStack::PopAndDestroy(2); |
|
215 } |
|
216 |
|
217 void MmsSettingsPrivate::setReceiveMMSAdvertsL(TBool aReceiveAdvert) |
|
218 { |
|
219 CMmsAccount* mMmsAccount = CMmsAccount::NewL(); |
|
220 CleanupStack::PushL(mMmsAccount); |
|
221 |
|
222 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
223 CleanupStack::PushL(mMmsSetting); |
|
224 |
|
225 mMmsAccount->LoadSettingsL(*mMmsSetting); |
|
226 |
|
227 //do your operation |
|
228 mMmsSetting->SetAcceptAdvertisementMessages(aReceiveAdvert); |
|
229 |
|
230 //save the settings |
|
231 mMmsAccount->SaveSettingsL(*mMmsSetting); |
|
232 CleanupStack::PopAndDestroy(2); |
|
233 } |
|
234 |
|
235 void MmsSettingsPrivate::advanceMmsSettingsL( |
|
236 MsgSettingEngine::MmsRetrieval& aRetrieval, |
|
237 TBool& aAnonymousStatus, |
|
238 TBool& aMmsAdvertsStatus) |
|
239 { |
|
240 CMmsAccount* mMmsAccount = CMmsAccount::NewL(); |
|
241 CleanupStack::PushL(mMmsAccount); |
|
242 |
|
243 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
244 CleanupStack::PushL(mMmsSetting); |
|
245 |
|
246 mMmsAccount->LoadSettingsL(*mMmsSetting); |
|
247 |
|
248 TMmsReceivingMode receveModeHome = mMmsSetting->ReceivingModeHome(); |
|
249 TMmsReceivingMode receveModeForeign = mMmsSetting->ReceivingModeForeign(); |
|
250 |
|
251 |
|
252 // if default value is not acceptable, choose next by keeping costs low |
|
253 if ( receveModeHome == EMmsReceivingAutomatic && |
|
254 receveModeForeign == EMmsReceivingAutomatic ) |
|
255 { |
|
256 aRetrieval = MsgSettingEngine::AlwaysAutomatic; |
|
257 } |
|
258 else if ( receveModeHome == EMmsReceivingManual && |
|
259 receveModeForeign == EMmsReceivingManual ) |
|
260 { |
|
261 aRetrieval = MsgSettingEngine::Manual; |
|
262 } |
|
263 else if ( receveModeHome == EMmsReceivingReject && |
|
264 receveModeForeign == EMmsReceivingReject ) |
|
265 { |
|
266 aRetrieval = MsgSettingEngine::No; |
|
267 } |
|
268 else if ( receveModeHome == EMmsReceivingPostpone && |
|
269 receveModeForeign == EMmsReceivingPostpone ) |
|
270 { |
|
271 aRetrieval = MsgSettingEngine::Off; |
|
272 } |
|
273 // Should always be automatic@home & manaul@roam |
|
274 else |
|
275 { |
|
276 aRetrieval = MsgSettingEngine::AutomInHomeNetwork; |
|
277 } |
|
278 aAnonymousStatus = mMmsSetting->AcceptAnonymousMessages(); |
|
279 |
|
280 aMmsAdvertsStatus = mMmsSetting->AcceptAdvertisementMessages(); |
|
281 |
|
282 CleanupStack::PopAndDestroy(2); |
|
283 } |
|
284 |
|
285 //--------------------------------------------------------------- |
|
286 // SmsSettings::iAPSelector |
|
287 // @see header |
|
288 //--------------------------------------------------------------- |
|
289 void MmsSettingsPrivate::getAllAccessPointsL( |
|
290 RPointerArray<HBufC>& aAccessPoints, |
|
291 TInt& aDefaultIndex) |
|
292 { |
|
293 #ifdef _DEBUG_TRACES_ |
|
294 qDebug() << "Enter MmsSettingsPrivate::getAllAccessPoints: Index= " << aDefaultIndex; |
|
295 #endif |
|
296 |
|
297 CCommsDatabase *db; |
|
298 CCommsDbTableView *view; |
|
299 TInt result, err; |
|
300 |
|
301 //select the access point and store it in cenrep |
|
302 CMmsAccount* mmsAccount = CMmsAccount::NewL(); |
|
303 CleanupStack::PushL(mmsAccount); |
|
304 |
|
305 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
306 CleanupStack::PushL(mMmsSetting); |
|
307 |
|
308 mmsAccount->LoadSettingsL(*mMmsSetting); |
|
309 |
|
310 //select the default access point |
|
311 TInt32 defaultId = mMmsSetting->AccessPoint(0); |
|
312 |
|
313 TBuf<KCommsDbSvrMaxColumnNameLength> iapName; |
|
314 TBuf<KCommsDbSvrMaxFieldLength> serviceType; |
|
315 TUint32 iapId = 0; |
|
316 db = CCommsDatabase::NewL(EDatabaseTypeIAP); |
|
317 CleanupStack::PushL(db); |
|
318 view = db->OpenTableLC(TPtrC(IAP)); |
|
319 |
|
320 // Walk through records |
|
321 result = view->GotoFirstRecord(); |
|
322 TInt recordIndex = 0; |
|
323 while (result == KErrNone) |
|
324 { |
|
325 TRAP(err, view->ReadTextL(TPtrC(COMMDB_NAME), iapName)); |
|
326 TRAP(err, view->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType)); |
|
327 #ifdef __WINSCW__ |
|
328 if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0) |
|
329 { |
|
330 HBufC* accessPointName = iapName.Alloc(); |
|
331 aAccessPoints.AppendL(accessPointName); |
|
332 TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId)); |
|
333 |
|
334 // check to see if this is default set for MMsAccesspoint |
|
335 if (defaultId == iapId) |
|
336 { |
|
337 aDefaultIndex = recordIndex; |
|
338 } |
|
339 recordIndex++; |
|
340 } |
|
341 #else |
|
342 if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0) |
|
343 { |
|
344 HBufC* accessPointName = iapName.Alloc(); |
|
345 aAccessPoints.AppendL(accessPointName); |
|
346 TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId)); |
|
347 |
|
348 // check to see if this is default set for MMsAccesspoint |
|
349 if (defaultId == iapId) |
|
350 { |
|
351 aDefaultIndex = recordIndex; |
|
352 } |
|
353 recordIndex++; |
|
354 } |
|
355 #endif |
|
356 TRAP(err, result = view->GotoNextRecord()); |
|
357 } |
|
358 CleanupStack::PopAndDestroy(4); // nMmsSettings, db,view |
|
359 #ifdef _DEBUG_TRACES_ |
|
360 qDebug() << "Exit MmsSettingsPrivate::getAllAccessPoints: Index=" |
|
361 << aDefaultIndex |
|
362 << "\n"; |
|
363 #endif |
|
364 |
|
365 } |
|
366 |
|
367 //--------------------------------------------------------------- |
|
368 // MmsSettingsPrivate::setMMSAccesspoint |
|
369 // @see header |
|
370 //--------------------------------------------------------------- |
|
371 void MmsSettingsPrivate::setMMSAccesspointL(TInt& aDefaultIndex) |
|
372 { |
|
373 #ifdef _DEBUG_TRACES_ |
|
374 qDebug() << "Enter MmsSettingsPrivate::setMMSAccesspoint: Index=" |
|
375 << aDefaultIndex |
|
376 << "\n"; |
|
377 #endif |
|
378 |
|
379 |
|
380 //select the access point and store it in cenrep |
|
381 CMmsAccount* mmsAccount = CMmsAccount::NewL(); |
|
382 CleanupStack::PushL(mmsAccount); |
|
383 |
|
384 CMmsSettings* mMmsSetting = CMmsSettings::NewL(); |
|
385 CleanupStack::PushL(mMmsSetting); |
|
386 |
|
387 mmsAccount->LoadSettingsL(*mMmsSetting); |
|
388 |
|
389 CCommsDatabase *db; |
|
390 CCommsDbTableView *view; |
|
391 TInt result, err; |
|
392 |
|
393 TCommDbConnPref prefs; |
|
394 |
|
395 TBuf<KCommsDbSvrMaxColumnNameLength> iapName; |
|
396 TBuf<KCommsDbSvrMaxFieldLength> serviceType; |
|
397 TUint32 iapId = 0; |
|
398 db = CCommsDatabase::NewL(EDatabaseTypeIAP); |
|
399 CleanupStack::PushL(db); |
|
400 view = db->OpenTableLC(TPtrC(IAP)); |
|
401 |
|
402 // Walk through records |
|
403 result = view->GotoFirstRecord(); |
|
404 TInt serviceCounter = 0; |
|
405 while (result == KErrNone) |
|
406 { |
|
407 TRAP(err, view->ReadTextL(TPtrC(COMMDB_NAME), iapName)); |
|
408 TRAP(err, view->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType)); |
|
409 |
|
410 #ifdef __WINSCW__ |
|
411 if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0 && serviceCounter |
|
412 == aDefaultIndex) |
|
413 { |
|
414 TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId)); |
|
415 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
416 prefs.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
417 prefs.SetIapId(iapId); |
|
418 |
|
419 while (mMmsSetting->AccessPointCount()) |
|
420 { |
|
421 mMmsSetting->DeleteAccessPointL(0); |
|
422 } |
|
423 if (iapId != 0) |
|
424 { |
|
425 #ifdef _DEBUG_TRACES_ |
|
426 qDebug() << "Set MMs Accesspoint IAP ID:" |
|
427 << iapId; |
|
428 #endif |
|
429 |
|
430 |
|
431 mMmsSetting->AddAccessPointL(iapId, 0); |
|
432 } |
|
433 mmsAccount->SaveSettingsL(*mMmsSetting); |
|
434 serviceCounter++; |
|
435 } |
|
436 else if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0) |
|
437 { |
|
438 serviceCounter++; |
|
439 } |
|
440 #else |
|
441 if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0 && |
|
442 serviceCounter == aDefaultIndex) |
|
443 { |
|
444 TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId)); |
|
445 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
446 prefs.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
447 prefs.SetIapId(iapId); |
|
448 |
|
449 while ( mMmsSetting->AccessPointCount() ) |
|
450 { |
|
451 #ifdef _DEBUG_TRACES_ |
|
452 qDebug() << "Set MMs Accesspoint IAP ID:" |
|
453 << iapId; |
|
454 #endif |
|
455 |
|
456 mMmsSetting->DeleteAccessPointL( 0 ); |
|
457 } |
|
458 if ( iapId != 0 ) |
|
459 { |
|
460 mMmsSetting->AddAccessPointL(iapId, 0); |
|
461 } |
|
462 mmsAccount->SaveSettingsL(*mMmsSetting); |
|
463 serviceCounter++; |
|
464 } |
|
465 else if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0) |
|
466 { |
|
467 serviceCounter++; |
|
468 } |
|
469 #endif |
|
470 TRAP(err, result = view->GotoNextRecord()); |
|
471 } |
|
472 |
|
473 CleanupStack::PopAndDestroy(4); // mMmsSetting, db,view |
|
474 #ifdef _DEBUG_TRACES_ |
|
475 qDebug() << "Exit MmsSettingsPrivate::setMMSAccesspoint: Index=" |
|
476 << aDefaultIndex |
|
477 << "\n"; |
|
478 #endif |
|
479 |
|
480 } |
|
481 |
|
482 //eof |
|
483 |