|
1 /* |
|
2 * Copyright (c) 2008 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 file implements class CIpsSetUtilsDisconnectLogic. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include "ipssetutilsdisconnectlogic.h" |
|
21 |
|
22 #include <SendUiConsts.h> |
|
23 #include <mtclreg.h> |
|
24 #include <mtclbase.h> |
|
25 #include <e32des8.h> |
|
26 #include <imapcmds.h> |
|
27 #include <pop3cmds.h> |
|
28 #include <msvstd.h> |
|
29 #include <msvids.h> |
|
30 #include <AknQueryDialog.h> |
|
31 #include <StringLoader.h> |
|
32 #include <ipssossettings.rsg> |
|
33 |
|
34 |
|
35 _LIT( KIpsSetUtilsSrvType, "SrvType"); |
|
36 |
|
37 #ifdef _DEBUG |
|
38 _LIT( KIpsSetUtilsInitError, "InitError"); |
|
39 #endif |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CIpsSetUtilsDisconnectLogic* CIpsSetUtilsDisconnectLogic::NewL( |
|
45 CMsvSession& aSession, TMsvId aMailboxId ) |
|
46 { |
|
47 FUNC_LOG; |
|
48 CIpsSetUtilsDisconnectLogic* self = |
|
49 new( ELeave ) CIpsSetUtilsDisconnectLogic( |
|
50 aSession, aMailboxId ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL( ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CIpsSetUtilsDisconnectLogic::CIpsSetUtilsDisconnectLogic( |
|
61 CMsvSession& aSession, TMsvId aMailboxId ) : |
|
62 CActive( EPriorityStandard ), iSession( aSession ), |
|
63 iMailboxId( aMailboxId ), iIsDisconnectComplete( EFalse ) |
|
64 { |
|
65 FUNC_LOG; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CIpsSetUtilsDisconnectLogic::~CIpsSetUtilsDisconnectLogic() |
|
72 { |
|
73 FUNC_LOG; |
|
74 Cancel(); |
|
75 delete iOperation; |
|
76 delete iAsyncWaitNote; |
|
77 delete iBaseMtm; |
|
78 delete iMtmReg; |
|
79 } |
|
80 // --------------------------------------------------------------------------- |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CIpsSetUtilsDisconnectLogic::ConstructL() |
|
84 { |
|
85 FUNC_LOG; |
|
86 CActiveScheduler::Add(this); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CIpsSetUtilsDisconnectLogic::StepL() |
|
93 { |
|
94 FUNC_LOG; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 TBool CIpsSetUtilsDisconnectLogic::IsProcessDone() const |
|
101 { |
|
102 FUNC_LOG; |
|
103 return iIsDisconnectComplete; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CIpsSetUtilsDisconnectLogic::ProcessFinished() |
|
111 { |
|
112 FUNC_LOG; |
|
113 } |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CIpsSetUtilsDisconnectLogic::DialogDismissedL( TInt /*aButtonId*/ ) |
|
120 { |
|
121 FUNC_LOG; |
|
122 //EAknSoftkeyCancel when red key or cancel pressed |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 TInt CIpsSetUtilsDisconnectLogic::CycleError( TInt /*aError*/ ) |
|
130 { |
|
131 FUNC_LOG; |
|
132 // called when StepL leaves |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CIpsSetUtilsDisconnectLogic::DoCancel() |
|
140 { |
|
141 FUNC_LOG; |
|
142 if ( iOperation && iOperation->IsActive() ) |
|
143 { |
|
144 iOperation->Cancel(); |
|
145 } |
|
146 iIsDisconnectComplete = ETrue; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CIpsSetUtilsDisconnectLogic::RunL() |
|
153 { |
|
154 FUNC_LOG; |
|
155 if ( iOperation && iOperation->iStatus.Int() != KErrNone ) |
|
156 { |
|
157 // error notes? |
|
158 TInt error = iStatus.Int(); |
|
159 } |
|
160 iIsDisconnectComplete = ETrue; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CIpsSetUtilsDisconnectLogic::RunError( TInt aError ) |
|
167 { |
|
168 FUNC_LOG; |
|
169 iIsDisconnectComplete = ETrue; |
|
170 aError = KErrNone; |
|
171 return aError; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CIpsSetUtilsDisconnectLogic::RunDisconnectLogicL( TBool aDoShowQuery ) |
|
178 { |
|
179 FUNC_LOG; |
|
180 // NOTE: this not react "red key" same way as rest of FSEmail, when |
|
181 // redkey is pressed during progress bar, only focus is lost but application |
|
182 // not exits |
|
183 TInt error = KErrNone; |
|
184 TMsvEntry entry; |
|
185 error = CheckConnectionAndQueryDisconnectL( entry, aDoShowQuery ); |
|
186 |
|
187 if ( error == KErrDisconnected ) |
|
188 { |
|
189 // not connected |
|
190 return KErrNone; |
|
191 } |
|
192 else if ( error == KErrNone ) |
|
193 { |
|
194 // connected and user want's to disconnect |
|
195 CreateDisconnectOperationL( entry ); |
|
196 |
|
197 // show wait note |
|
198 iAsyncWaitNote = CAknWaitNoteWrapper::NewL(); |
|
199 TBool result = iAsyncWaitNote->ExecuteL( |
|
200 R_IPS_SETUI_WAIT_DISCONNECTING_DIALOG, *this ); |
|
201 |
|
202 if ( !result ) |
|
203 { |
|
204 error = KErrCancel; |
|
205 } |
|
206 } |
|
207 |
|
208 // only possible return codes are KErrNone and KErrCancel |
|
209 return error; |
|
210 } |
|
211 |
|
212 |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CIpsSetUtilsDisconnectLogic::CheckConnectionAndQueryDisconnectL( |
|
218 TMsvEntry& aEntry, TBool aDoShowQuery ) |
|
219 { |
|
220 FUNC_LOG; |
|
221 TMsvId service; |
|
222 User::LeaveIfError( iSession.GetEntry( iMailboxId, service, aEntry ) ); |
|
223 |
|
224 TInt error = KErrNone; |
|
225 if ( !aEntry.Connected() ) |
|
226 { |
|
227 error = KErrDisconnected; |
|
228 } |
|
229 else if ( aDoShowQuery ) |
|
230 { |
|
231 HBufC* message = StringLoader::LoadLC( R_FSE_SETTINGS_MAIL_QUERY_DISCONNECT ); |
|
232 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
233 CleanupStack::PushL(dlg); |
|
234 dlg->SetPromptL(*message); |
|
235 CleanupStack::Pop(dlg); |
|
236 TBool result = dlg->ExecuteLD( R_IPS_SETUI_CONFIRMATION_QUERY ); |
|
237 CleanupStack::PopAndDestroy(message); |
|
238 if ( !result ) |
|
239 { |
|
240 error = KErrCancel; |
|
241 } |
|
242 } |
|
243 return error; |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 void CIpsSetUtilsDisconnectLogic::CreateDisconnectOperationL( |
|
250 const TMsvEntry& aEntry ) |
|
251 { |
|
252 FUNC_LOG; |
|
253 // check mtm type and make sure that this function is not called |
|
254 // twice without releasing data |
|
255 __ASSERT_ALWAYS( |
|
256 ( aEntry.iMtm.iUid == KSenduiMtmImap4UidValue |
|
257 || aEntry.iMtm.iUid == KSenduiMtmPop3UidValue ), |
|
258 User::Panic( KIpsSetUtilsSrvType, KErrGeneral ) ); |
|
259 |
|
260 __ASSERT_DEBUG( ( !iAsyncWaitNote && !iMtmReg && !iBaseMtm ), |
|
261 User::Panic( KIpsSetUtilsInitError, KErrGeneral ) ); |
|
262 |
|
263 iMtmReg = CClientMtmRegistry::NewL( iSession ); |
|
264 iBaseMtm = iMtmReg->NewMtmL( aEntry.iMtm ); |
|
265 |
|
266 iBaseMtm->SwitchCurrentEntryL( aEntry.Id() ); |
|
267 // create and invoke disconnect operation |
|
268 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
269 CleanupStack::PushL(sel); |
|
270 sel->AppendL( aEntry.Id() ); |
|
271 TBuf8<1> dummy; |
|
272 if ( aEntry.iMtm.iUid == KSenduiMtmImap4UidValue ) |
|
273 { |
|
274 iOperation = iBaseMtm->InvokeAsyncFunctionL( |
|
275 KIMAP4MTMDisconnect, *sel, dummy, iStatus ); |
|
276 } |
|
277 else |
|
278 { |
|
279 iOperation = iBaseMtm->InvokeAsyncFunctionL( |
|
280 KPOP3MTMDisconnect, *sel, dummy, iStatus ); |
|
281 } |
|
282 CleanupStack::PopAndDestroy( sel ); |
|
283 |
|
284 SetActive(); |
|
285 } |
|
286 |
|
287 |
|
288 |
|
289 |