|
1 /* |
|
2 * ============================================================================ |
|
3 * Name : CWPSaver.cpp |
|
4 * Part of : Provisioning / ProvisioningBC |
|
5 * Description : Helper class for saving Provisioning settings. Provides a progress note. |
|
6 * Version : %version: 2 % << Don't touch! Updated by Synergy at check-out. |
|
7 * |
|
8 * Copyright © 2002-2006 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <commdb.h> |
|
21 #include <CWPEngine.h> |
|
22 #include <CWPAdapter.h> |
|
23 |
|
24 #include "CWPSaver.h" |
|
25 #include <HbProgressDialog> |
|
26 #include <HbAction> |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KMaxWaitTime = 2000000; |
|
30 const TInt KRetryCount = 5; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 // ========================== MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ---------------------------------------------------------------------------- |
|
37 // C++ default constructor. |
|
38 // ---------------------------------------------------------------------------- |
|
39 CWPSaver::CWPSaver( CWPEngine& aEngine, TBool aSetAsDefault ) |
|
40 : CActive( EPriorityStandard ), |
|
41 iEngine( aEngine ), |
|
42 iSetAsDefault( aSetAsDefault ), |
|
43 iCurrentItem( 0 ), |
|
44 iResult( KErrNone ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ---------------------------------------------------------------------------- |
|
49 // CWPSaver::PrepareLC |
|
50 // ---------------------------------------------------------------------------- |
|
51 // |
|
52 void CWPSaver::PrepareLC() |
|
53 { |
|
54 // Assume ownership of this. |
|
55 CleanupStack::PushL( this ); |
|
56 iProgress = new HbProgressDialog(HbProgressDialog::WaitDialog); |
|
57 iProgress->setText(hbTrId("txt_device_update_setlabel_saving_settings")); |
|
58 iProgress->clearActions(); |
|
59 iProgress->show(); |
|
60 |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CWPSaver::ExecuteLD |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 TInt CWPSaver::ExecuteLD( TInt& aNumSaved, TBufC<256>& Value ) |
|
68 { |
|
69 PrepareLC(); |
|
70 |
|
71 // Add us to active scheduler and make sure RunL() gets called. |
|
72 CActiveScheduler::Add( this ); |
|
73 CompleteRequest(); |
|
74 iWait.Start(); |
|
75 |
|
76 // Progress note has been finished/cancelled. Cache the result |
|
77 // and delete this. |
|
78 TInt result( iResult ); |
|
79 aNumSaved = iCurrentItem; |
|
80 Value = iValue; |
|
81 CleanupStack::PopAndDestroy(); // this |
|
82 |
|
83 return result; |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // Destructor |
|
88 // ---------------------------------------------------------------------------- |
|
89 CWPSaver::~CWPSaver() |
|
90 { |
|
91 Cancel(); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // CWPSaver::DoCancel |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 void CWPSaver::DoCancel() |
|
99 { |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CWPSaver::RunL |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 void CWPSaver::RunL() |
|
107 { |
|
108 // Choose whether to save or set as default |
|
109 TInt err( KErrNone ); |
|
110 if( iSetAsDefault ) |
|
111 { |
|
112 TRAP( err, |
|
113 if( iEngine.CanSetAsDefault( iCurrentItem ) ) |
|
114 { |
|
115 iEngine.SetAsDefaultL( iCurrentItem ); |
|
116 } ); |
|
117 } |
|
118 else |
|
119 { |
|
120 TRAP(err, QT_TRYCATCH_LEAVING( iEngine.SaveL( iCurrentItem ) )); |
|
121 } |
|
122 if( err != KErrNone ) |
|
123 { |
|
124 // For all other errors, pass them through. |
|
125 iValue = iEngine.SummaryText(iCurrentItem); |
|
126 delete iProgress; |
|
127 iProgress = NULL; |
|
128 User::LeaveIfError( err ); |
|
129 } |
|
130 // Succesful save, so reset retry count |
|
131 iRetryCount = 0; |
|
132 |
|
133 // Normal progress |
|
134 if( iCurrentItem == iEngine.ItemCount()-1 ) |
|
135 { |
|
136 //iProgress->cancel(); |
|
137 //iProgress->close(); |
|
138 delete iProgress; |
|
139 iProgress = NULL; |
|
140 iWait.AsyncStop(); |
|
141 } |
|
142 else |
|
143 { |
|
144 //CEikProgressInfo* progressInfo = iDialog->GetProgressInfoL(); |
|
145 iCurrentItem++; |
|
146 //progressInfo->SetAndDraw(iCurrentItem); |
|
147 CompleteRequest(); |
|
148 } |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CWPSaver::RunError |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CWPSaver::RunError( TInt aError ) |
|
156 { |
|
157 // There was a leave in RunL(). Store the error and |
|
158 // stop the dialog. |
|
159 iResult = aError; |
|
160 iWait.AsyncStop(); |
|
161 return KErrNone; |
|
162 } |
|
163 |
|
164 // ---------------------------------------------------------------------------- |
|
165 // CWPSaver::CompleteRequest |
|
166 // ---------------------------------------------------------------------------- |
|
167 // |
|
168 void CWPSaver::CompleteRequest() |
|
169 { |
|
170 // Schedule an immediate complete. Make sure that there |
|
171 // is no timer alive first |
|
172 Cancel(); |
|
173 //iRetryTimer->Cancel(); |
|
174 |
|
175 SetActive(); |
|
176 TRequestStatus* sp = &iStatus; |
|
177 User::RequestComplete( sp, KErrNone ); |
|
178 } |
|
179 |