|
1 /* |
|
2 * Copyright (c) 2002 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: Handles the global progress dialog |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <AknGlobalProgressDialog.h> |
|
24 #include "obexutilsglobalprogressdialog.h" |
|
25 #include "obexutilsuilayer.h" |
|
26 #include <StringLoader.h> |
|
27 #include <AknIconUtils.h> |
|
28 #include <avkon.mbg> |
|
29 #include <avkon.rsg> |
|
30 #include <bautils.h> |
|
31 //#include <BtuiViewResources.rsg> // Compiled resource ids |
|
32 #include <e32math.h> |
|
33 |
|
34 #include <StringLoader.h> // Localisation stringloader |
|
35 #include <eikenv.h> |
|
36 |
|
37 #include "obexutilsdebug.h" |
|
38 |
|
39 const TInt KMaxDisplayFileName = 17; // used while showing receiving filename. |
|
40 // If the filename is longer than 20 bytes, we make it show only 20 bytes. |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // |
|
47 CGlobalProgressDialog::CGlobalProgressDialog() : CActive(EPriorityNormal) |
|
48 { |
|
49 CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 |
|
53 // Symbian default constructor can leave. |
|
54 void CGlobalProgressDialog::ConstructL(MGlobalProgressCallback* aObserver) |
|
55 { |
|
56 iProgressDialog = CAknGlobalProgressDialog::NewL(); |
|
57 iKeyCallback = aObserver; |
|
58 } |
|
59 |
|
60 |
|
61 // Two-phased constructor. |
|
62 EXPORT_C CGlobalProgressDialog* CGlobalProgressDialog::NewL(MGlobalProgressCallback* aObserver) |
|
63 { |
|
64 CGlobalProgressDialog* self = NewLC(aObserver); |
|
65 CleanupStack::Pop(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // Two-phased constructor.- stack version |
|
70 EXPORT_C CGlobalProgressDialog* CGlobalProgressDialog::NewLC(MGlobalProgressCallback* aObserver) |
|
71 { |
|
72 CGlobalProgressDialog* self=new (ELeave) CGlobalProgressDialog(); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(aObserver); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 // Destructor |
|
80 CGlobalProgressDialog::~CGlobalProgressDialog() |
|
81 { |
|
82 Cancel(); |
|
83 delete iProgressDialog; |
|
84 delete iStringResourceReader; |
|
85 } |
|
86 |
|
87 |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CGlobalProgressDialog::DoCancel |
|
91 // Active object cancel |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 void CGlobalProgressDialog::DoCancel() |
|
95 { |
|
96 if ( iProgressDialog ) |
|
97 { |
|
98 iProgressDialog->CancelProgressDialog(); |
|
99 } |
|
100 |
|
101 if(iStringResourceReader) |
|
102 { |
|
103 delete iStringResourceReader; |
|
104 iStringResourceReader = NULL; |
|
105 } |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CGlobalProgressDialog::RunL |
|
110 // Active object RunL |
|
111 // --------------------------------------------------------- |
|
112 // |
|
113 void CGlobalProgressDialog::RunL() |
|
114 { |
|
115 if ( iKeyCallback != NULL ) |
|
116 { |
|
117 iKeyCallback->HandleGlobalProgressDialogL(iStatus.Int()); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CGlobalProgressDialog::SetIconL |
|
123 // Set icon on the dialog |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 void CGlobalProgressDialog::SetIconL( const TDesC& aIconText, const TDesC& aIconFile, |
|
127 TInt aIconId, TInt aIconMaskId ) |
|
128 { |
|
129 iProgressDialog->SetIconL(aIconText, aIconFile, aIconId, aIconMaskId ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------- |
|
133 // CGlobalProgressDialog::SetImageL |
|
134 // Set image on the dialog |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 void CGlobalProgressDialog::SetImageL( const TDesC& aImageFile, TInt aImageId, |
|
138 TInt aImageMaskId ) |
|
139 { |
|
140 iProgressDialog->SetImageL(aImageFile, aImageId, aImageMaskId); |
|
141 } |
|
142 |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CGlobalProgressDialog::ShowProgressDialogL |
|
146 // Shows progress dialog and sets active object active |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C void CGlobalProgressDialog::ShowProgressDialogL(TInt aStringId) |
|
150 { |
|
151 TFileName fileName; |
|
152 fileName += KObexUtilsFileDrive; |
|
153 fileName += KDC_RESOURCE_FILES_DIR; |
|
154 fileName += KObexUtilsResourceFileName; |
|
155 |
|
156 if(!iStringResourceReader) |
|
157 { |
|
158 iStringResourceReader= CStringResourceReader::NewL( fileName ); |
|
159 } |
|
160 TPtrC buf; |
|
161 //buf.Set(iStringResourceReader-> ReadResourceString(R_BT_RECEIVING_DATA)); |
|
162 buf.Set(iStringResourceReader-> ReadResourceString(aStringId)); |
|
163 iProgressDialog->ShowProgressDialogL( iStatus, buf, R_AVKON_SOFTKEYS_HIDE_CANCEL__HIDE ); |
|
164 //iProgressDialog->ShowProgressDialogL( iStatus, buf, R_BTUI_SOFTKEYS_OPTIONS_EXIT__CHANGE ); //R_OBEXUTILS_SOFTKEYS_HIDE_CANCEL ); |
|
165 SetActive(); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CGlobalProgressDialog::ShowProgressDialogNameSizeL |
|
170 // Shows progress dialog and sets active object active |
|
171 // --------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CGlobalProgressDialog::ShowProgressDialogNameSizeL( |
|
174 TDesC& aFileName, |
|
175 TInt64 aFileSize) |
|
176 { |
|
177 TFileName fileName; |
|
178 fileName += KObexUtilsFileDrive; |
|
179 fileName += KDC_RESOURCE_FILES_DIR; |
|
180 fileName += KObexUtilsResourceFileName; |
|
181 |
|
182 if(!iStringResourceReader) |
|
183 { |
|
184 iStringResourceReader= CStringResourceReader::NewL( fileName ); |
|
185 } |
|
186 TPtrC buf; |
|
187 |
|
188 |
|
189 TBuf<20> sizeInString; |
|
190 sizeInString.Zero(); |
|
191 |
|
192 if ( aFileSize >> 20 ) // size in MB |
|
193 { |
|
194 TReal sizeInMB = 0; |
|
195 sizeInMB = ((TReal)aFileSize ) / (1024*1024); |
|
196 _LIT16(KFormatTwoDecimal,"%4.2f"); // keep 2 decimals |
|
197 sizeInString.Format(KFormatTwoDecimal,sizeInMB); |
|
198 buf.Set(iStringResourceReader-> ReadResourceString(R_BT_IR_RECEIVING_DATA_SIZE_MB)); |
|
199 } |
|
200 else if( aFileSize >> 10 ) // size in KB |
|
201 { |
|
202 TInt64 sizeInKB = 0; |
|
203 sizeInKB = aFileSize >> 10; |
|
204 sizeInString.AppendNum(sizeInKB); |
|
205 buf.Set(iStringResourceReader-> ReadResourceString(R_BT_IR_RECEIVING_DATA_SIZE_KB)); |
|
206 } |
|
207 else // size is unknown or less than 1K |
|
208 { |
|
209 buf.Set(iStringResourceReader-> ReadResourceString(R_BT_IR_RECEIVING_DATA_NO_SIZE)); |
|
210 } |
|
211 |
|
212 |
|
213 TBuf<100> tbuf; |
|
214 tbuf.Zero(); |
|
215 tbuf.Append(buf); |
|
216 _LIT(KPrefix,"["); |
|
217 _LIT(Ksuffix,"]"); |
|
218 TInt prefixPos = tbuf.Find(KPrefix); |
|
219 if (prefixPos!= KErrNotFound) |
|
220 { |
|
221 TInt keyLength = 0; |
|
222 TInt suffixPos = tbuf.Find(Ksuffix); |
|
223 keyLength =(tbuf.Mid(prefixPos)).Length()-(tbuf.Mid(suffixPos)).Length()+1; |
|
224 tbuf.Delete(prefixPos, keyLength); |
|
225 } |
|
226 _LIT(KString,"%U"); |
|
227 |
|
228 |
|
229 |
|
230 if ( aFileName.Length() > KMaxDisplayFileName ) |
|
231 { |
|
232 // Filename is too long, |
|
233 // We make it shorter. Hiding the chars in the middle part of filename. |
|
234 // |
|
235 TFileName shortname; |
|
236 shortname = aFileName.Mid(0,KMaxDisplayFileName/2); |
|
237 shortname.Append(_L("...")); |
|
238 shortname.Append(aFileName.Mid(aFileName.Length() - KMaxDisplayFileName/2, KMaxDisplayFileName/2)); |
|
239 tbuf.Replace(tbuf.Find(KString) , 2, shortname); |
|
240 } |
|
241 else |
|
242 { |
|
243 tbuf.Replace(tbuf.Find(KString) , 2, aFileName); |
|
244 } |
|
245 _LIT(KInt, "%N"); |
|
246 if ( sizeInString.Length() > 0 ) |
|
247 { |
|
248 tbuf.Replace(tbuf.Find(KInt) , 2, sizeInString); |
|
249 } |
|
250 |
|
251 iProgressDialog->ShowProgressDialogL( iStatus, tbuf, R_AVKON_SOFTKEYS_HIDE_CANCEL__HIDE ); |
|
252 SetActive(); |
|
253 } |
|
254 // --------------------------------------------------------- |
|
255 // CGlobalProgressDialog::UpdateProgressDialog |
|
256 // Updates the progress dialog |
|
257 // --------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C void CGlobalProgressDialog::UpdateProgressDialog(TInt aValue, TInt aFinalValue) |
|
260 { |
|
261 iProgressDialog->UpdateProgressDialog(aValue, aFinalValue); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // CGlobalProgressDialog::ProcessFinished |
|
266 // Stops the progress dialog |
|
267 // --------------------------------------------------------- |
|
268 // |
|
269 EXPORT_C void CGlobalProgressDialog::ProcessFinished() |
|
270 { |
|
271 iProgressDialog->ProcessFinished(); |
|
272 } |