|
1 /* |
|
2 * Copyright (c) 2004 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 * Provides MMS Settings. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <coemain.h> |
|
23 #include <eikenv.h> |
|
24 #include <ApUtils.h> //CApUtils, CCommsDatabase, EDatabaseTypeIAP |
|
25 #include <AknQueryDialog.h> |
|
26 #include <AknWaitDialog.h> |
|
27 #include <akninputblock.h> //CAknInputBlock |
|
28 #include <bautils.h> |
|
29 #include <ConeResLoader.h> // for RConeResourceLoader |
|
30 #include <StringLoader.h> |
|
31 #include <data_caging_path_literals.hrh> |
|
32 |
|
33 #include <msvids.h> |
|
34 |
|
35 #include <MmsSettings.rsg> |
|
36 #include <mmsclient.h> |
|
37 #include <mmserrors.h> |
|
38 #include <MtmExtendedCapabilities.hrh> // for TMscFactorySettingsLevel |
|
39 |
|
40 #include "MmsSettingsHandler.h" |
|
41 #include "MmsSettingsPanic.h" |
|
42 #include "MmsMtmConst.h" |
|
43 |
|
44 _LIT( KMmsSettingsResourceFileName, "mmssettings.rsc" ); |
|
45 |
|
46 GLREF_C void Panic(TMmsSettingsPanic aPanic) |
|
47 { |
|
48 _LIT( KPanicText,"MmsSettings.dll" ); |
|
49 User::Panic( KPanicText, aPanic ); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CMmsSettingsHandler::CMmsSettingsHandler() |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CMmsSettingsHandler::CMmsSettingsHandler( CMmsClientMtm& aMmsClient ) : |
|
57 iMmsClient( aMmsClient ), iResourceOffset( 0 ) |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CMsgInfoMessageInfoDialog::ConstructL |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CMmsSettingsHandler::ConstructL() |
|
66 { |
|
67 iMmsSettings = CMmsSettings::NewL(); |
|
68 iMmsClient.RestoreSettingsL(); |
|
69 iMmsSettings->CopyL( iMmsClient.MmsSettings() ); |
|
70 |
|
71 TParse fileParse; |
|
72 fileParse.Set( KMmsSettingsResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
73 TFileName fileName( fileParse.FullName() ); |
|
74 CEikonEnv* env = CEikonEnv::Static( ); |
|
75 BaflUtils::NearestLanguageFile( env->FsSession(), fileName ); |
|
76 iResourceOffset = env->AddResourceFileL( fileName ); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CMmsSettingsHandler::NewL() |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C CMmsSettingsHandler* CMmsSettingsHandler::NewL( CMmsClientMtm& aMmsClient ) |
|
84 { |
|
85 LOGTEXT( _L8( "CMmsSettingsHandler::NewL, start" ) ); |
|
86 CMmsSettingsHandler* self = new ( ELeave ) CMmsSettingsHandler( aMmsClient ); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop(); //self |
|
90 return self; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CMmsSettingsHandler::~CMmsSettingsHandler |
|
95 // Destructor |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CMmsSettingsHandler::~CMmsSettingsHandler() |
|
99 { |
|
100 if( iResourceOffset ) |
|
101 { |
|
102 CCoeEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
103 } |
|
104 delete iMmsSettings; |
|
105 if ( iWaitDialog ) |
|
106 { |
|
107 TRAP_IGNORE( iWaitDialog->ProcessFinishedL() ); |
|
108 } |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CMmsSettingsHandler::ApExistsL |
|
113 // Checks the existence of given access point |
|
114 // according to id. |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C TBool CMmsSettingsHandler::ApExistsL( TInt32 aAp ) |
|
118 { |
|
119 if ( aAp == KErrNotFound ) |
|
120 { |
|
121 return EFalse; |
|
122 } |
|
123 CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
124 CleanupStack::PushL( commsDb ); |
|
125 CApUtils* apUtils = CApUtils::NewLC( *commsDb ); |
|
126 |
|
127 TBool exists = EFalse; |
|
128 TRAPD( error, ( exists = apUtils->WapApExistsL( aAp ) ) ); |
|
129 |
|
130 CleanupStack::PopAndDestroy( 2 ); //apUtils, commsDb |
|
131 |
|
132 if ( exists ) |
|
133 { |
|
134 return ETrue; |
|
135 } |
|
136 |
|
137 if ( error != KErrNotFound ) |
|
138 { |
|
139 User::LeaveIfError( error ); |
|
140 } |
|
141 return EFalse; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CMmsSettingsHandler::CheckSettingsL() const |
|
146 // Check MMS service settings |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C TBool CMmsSettingsHandler::CheckSettingsL( |
|
150 CMmsSettingsDialog::TMmsExitCode& aExitCode ) |
|
151 { |
|
152 TInt error = iMmsSettings->ValidateSettings(); |
|
153 if ( error == KMmsErrorInvalidSettings ) |
|
154 { |
|
155 //Settings corrupted. Restore factory settings. |
|
156 RestoreDefaultSettingsL( EMmsFactorySettingsLevelNormal ); |
|
157 //Re-check the service. |
|
158 //error = iMmsClient.ValidateService( iMmsClient.DefaultSettingsL() ); |
|
159 error = iMmsSettings->ValidateSettings(); |
|
160 } |
|
161 if ( error != KErrNone ) |
|
162 { // something wrong in service settings |
|
163 CAknQueryDialog* settingsNotOkQuery = CAknQueryDialog::NewL(); |
|
164 |
|
165 if ( settingsNotOkQuery->ExecuteLD( R_MMSUI_QUERY_AP_ERROR ) ) |
|
166 { |
|
167 // user wants to correct the settings |
|
168 CEikStatusPane* sp = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
169 TInt previous = sp->CurrentLayoutResId(); |
|
170 sp->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL ); |
|
171 sp->MakeVisible( ETrue ); |
|
172 sp->DrawNow(); |
|
173 |
|
174 LaunchSettingsDialogL( aExitCode ); |
|
175 |
|
176 sp->SwitchLayoutL( previous ); |
|
177 sp->MakeVisible( ETrue ); |
|
178 sp->DrawNow(); |
|
179 } |
|
180 return EFalse; |
|
181 } |
|
182 return ETrue; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CMsvOperation* CMmsSettingsHandler::CompleteSettingsOperationL( |
|
187 // TRequestStatus& aCompletionStatus, const CMmsSettingsDialog::TMmsExitCode& aExitCode) |
|
188 // Creates completed operation after settings dialog closing with appropriate parameters. |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C CMsvOperation* CMmsSettingsHandler::CompleteSettingsOperationL( |
|
192 TRequestStatus& aCompletionStatus, |
|
193 const CMmsSettingsDialog::TMmsExitCode& aExitCode |
|
194 /* = CMmsSettingsDialog::EMmsExternalInterrupt */) |
|
195 { |
|
196 TInt err = KErrNone; |
|
197 if ( aExitCode == CMmsSettingsDialog::EMmsExit ) |
|
198 { |
|
199 LOGTEXT( _L8( "MmsMtmUi Service Settings dialog exiting" ) ); |
|
200 err = EEikCmdExit; |
|
201 } |
|
202 // Nothing to do, so return a completed operation. |
|
203 return CMsvCompletedOperation::NewL( iMmsClient.Session(), |
|
204 KUidMsvLocalServiceMtm, |
|
205 KNullDesC8, |
|
206 KMsvLocalServiceIndexEntryId, |
|
207 aCompletionStatus, |
|
208 err ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CMmsSettingsHandler::HandleFactorySettingsL |
|
213 // Reset Factory Settings support |
|
214 // --------------------------------------------------------- |
|
215 EXPORT_C void CMmsSettingsHandler::HandleFactorySettingsL( TDes8& aLevel ) |
|
216 { |
|
217 TPckgBuf <TMsvFactorySettingsLevel> paramPack; |
|
218 const TInt paramSize = sizeof( TMsvFactorySettingsLevel ); |
|
219 |
|
220 __ASSERT_DEBUG( aLevel.Length() > 0, Panic( EMmsSettingsWrongParameters ) ); |
|
221 |
|
222 if ( aLevel.Length() > 0 ) |
|
223 { |
|
224 paramPack.Copy( aLevel.Ptr(), paramSize ); |
|
225 const TMsvFactorySettingsLevel& level = paramPack(); |
|
226 |
|
227 LOGTEXT2( _L16( "CMmsSettingsHandler calling RestoreFactorySettings with level %d"), level ); |
|
228 if ( level == EMsvFactorySettingsLevelNormal ) |
|
229 { |
|
230 RestoreDefaultSettingsL( EMmsFactorySettingsLevelNormal ); |
|
231 } |
|
232 else if ( level == EMsvFactorySettingsLevelDeep ) |
|
233 { |
|
234 RestoreDefaultSettingsL( EMmsFactorySettingsLevelDeep ); |
|
235 } |
|
236 else |
|
237 { |
|
238 __ASSERT_DEBUG( EFalse, Panic( EMmsSettingsWrongParameters ) ); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------- |
|
244 // void CMmsSettingsHandler::LaunchSettingsDialogL( |
|
245 // CMmsSettingsDialog::TMmsExitCode& aExitCode ) |
|
246 // Opens either MMS Service Settings or MMS Sending Settings dialog. |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C void CMmsSettingsHandler::LaunchSettingsDialogL( |
|
250 CMmsSettingsDialog::TMmsExitCode& aExitCode ) |
|
251 { |
|
252 // Reload settings, because mce does not create CMmsSettingsHandler from scratch |
|
253 RefreshSettingsL(); |
|
254 CMmsSettingsDialog* dlg = new ( ELeave ) CMmsSettingsDialog( iMmsSettings, aExitCode ); |
|
255 |
|
256 LOGTEXT( _L8( "MmsMtmUi Opening Settings dialog" ) ); |
|
257 dlg->ConstructL( R_SETTINGSDIALOG_MENUBAR ); |
|
258 dlg->ExecuteLD( R_MMSUI_MMSSETTINGS ); |
|
259 //return value ignored. |
|
260 |
|
261 // Save changes only if Back or ExitWithSave is selected |
|
262 if ( aExitCode==CMmsSettingsDialog::EMmsBack |
|
263 || aExitCode==CMmsSettingsDialog::EMmsExitWithSave ) |
|
264 { |
|
265 iWaitDialog = new ( ELeave ) CAknWaitDialog( NULL ); |
|
266 iWaitDialog->PrepareLC( SAVING_WAIT_NOTE ); |
|
267 HBufC* text = StringLoader::LoadLC( R_MMS_SETTINGS_PROCESSING ); |
|
268 iWaitDialog->SetTextL( *text ); |
|
269 CleanupStack::PopAndDestroy(); // text |
|
270 |
|
271 iWaitDialog->SetCallback(this); |
|
272 iWaitDialog->RunLD(); |
|
273 //Adding InputBlocker to avoid handling of user keypresses until the mmsclient operations have completed |
|
274 CAknInputBlock* inputBlock = CAknInputBlock::NewLC(); |
|
275 iMmsClient.SetSettingsL( *iMmsSettings ); |
|
276 iMmsClient.StoreSettingsL(); |
|
277 CleanupStack::PopAndDestroy(inputBlock); |
|
278 |
|
279 if ( iWaitDialog ) |
|
280 { |
|
281 iWaitDialog->ProcessFinishedL(); |
|
282 iWaitDialog = NULL; |
|
283 } |
|
284 |
|
285 if ( aExitCode==CMmsSettingsDialog::EMmsExitWithSave ) |
|
286 { // Change exit code if ExitWithSave is selected |
|
287 aExitCode = CMmsSettingsDialog::EMmsExit; |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CMsvOperation* CMmsSettingsHandler::OpenServiceSettingsDialogL(TRequestStatus& aCompletionStatus) |
|
294 // Handles MMS service settings |
|
295 // --------------------------------------------------------- |
|
296 // |
|
297 EXPORT_C CMsvOperation* CMmsSettingsHandler::OpenServiceSettingsDialogL( TRequestStatus& aCompletionStatus ) |
|
298 { |
|
299 CMmsSettingsDialog::TMmsExitCode exitCode; |
|
300 LaunchSettingsDialogL( exitCode ); |
|
301 return CompleteSettingsOperationL( aCompletionStatus, exitCode ); |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------- |
|
305 // CMmsSettingsHandler::CreateDefaultServiceL |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 void CMmsSettingsHandler::RestoreDefaultSettingsL( TMmsFactorySettingsLevel aLevel ) const |
|
309 { |
|
310 iMmsSettings->RestoreFactorySettingsL( iMmsClient.Session(), aLevel ); |
|
311 iMmsClient.SetSettingsL( *iMmsSettings ); |
|
312 iMmsClient.StoreSettingsL(); |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // DialogDismissedL |
|
317 // --------------------------------------------------------- |
|
318 // |
|
319 void CMmsSettingsHandler::DialogDismissedL( TInt /*aButtonId*/ ) |
|
320 { |
|
321 iWaitDialog = NULL; |
|
322 } |
|
323 // End of File |