1 /* |
|
2 * Copyright (c) 2006-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: View for restore settings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <StringLoader.h> |
|
22 #include <aknlists.h> |
|
23 #include <akntitle.h> |
|
24 #include <CFileManagerEngine.h> |
|
25 #include <FileManager.rsg> |
|
26 #include <FileManagerDlgUtils.h> |
|
27 #include <CFileManagerRestoreSettings.h> |
|
28 #include <FileManagerDebug.h> |
|
29 #include "CFileManagerRestoreView.h" |
|
30 #include "CFileManagerSettingListContainer.h" |
|
31 #include "CFileManagerDocument.h" |
|
32 #include "CFileManagerAppUi.h" |
|
33 #include "FileManager.hrh" |
|
34 |
|
35 // CONSTANTS |
|
36 const TUid CFileManagerRestoreView::KDeleteBackups = { EDeleteBackups }; |
|
37 const TInt KMaxSelection = 64; |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // CFileManagerRestoreView::CFileManagerRestoreView |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 CFileManagerRestoreView::CFileManagerRestoreView() |
|
46 { |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CFileManagerRestoreView::NewLC |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 CFileManagerRestoreView* CFileManagerRestoreView::NewLC() |
|
54 { |
|
55 CFileManagerRestoreView* self = new( ELeave ) CFileManagerRestoreView(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( R_FILEMANAGER_RESTORE_VIEW ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CFileManagerRestoreView::~CFileManagerRestoreView |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 CFileManagerRestoreView::~CFileManagerRestoreView() |
|
66 { |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CFileManagerRestoreView::DoActivateL |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 void CFileManagerRestoreView::DoActivateL( |
|
74 const TVwsViewId& aPrevViewId, |
|
75 TUid aCustomMessageId, |
|
76 const TDesC8& aCustomMessage ) |
|
77 { |
|
78 FUNC_LOG |
|
79 |
|
80 iSelection = 0; // Reset stored list selection |
|
81 iDeleteBackups = ( aCustomMessageId == KDeleteBackups ); |
|
82 |
|
83 CFileManagerViewBase::DoActivateL( |
|
84 aPrevViewId, aCustomMessageId, aCustomMessage ); |
|
85 |
|
86 static_cast< CFileManagerAppUi* >( AppUi() )->SetTitleL( |
|
87 iDeleteBackups ? |
|
88 R_QTN_FMGR_DELETE_BACKUP_TITLE : R_QTN_FMGR_RESTORE_TITLE ); |
|
89 |
|
90 CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() ); |
|
91 settings.RefreshL(); |
|
92 |
|
93 iContainer->RefreshListL( iIndex ); |
|
94 |
|
95 CEikButtonGroupContainer* cba = Cba(); |
|
96 cba->SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL__MARK ); |
|
97 cba->MakeCommandVisible( EAknSoftkeyOk, EFalse ); |
|
98 cba->MakeCommandVisible( EAknSoftkeyMark, ETrue ); |
|
99 |
|
100 if ( !iContainer->ListBoxNumberOfItems() ) |
|
101 { |
|
102 cba->MakeCommandVisible( EAknSoftkeyMark, EFalse ); |
|
103 } |
|
104 cba->DrawDeferred(); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CFileManagerRestoreView::DoDeactivate |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 void CFileManagerRestoreView::DoDeactivate() |
|
112 { |
|
113 FUNC_LOG |
|
114 |
|
115 CFileManagerViewBase::DoDeactivate(); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // CFileManagerRestoreView::DirectoryChangedL |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 void CFileManagerRestoreView::DirectoryChangedL() |
|
123 { |
|
124 FUNC_LOG |
|
125 |
|
126 if ( iContainer ) |
|
127 { |
|
128 CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() ); |
|
129 settings.RefreshL(); |
|
130 iContainer->RefreshListL( iIndex ); |
|
131 RestoreSelectionL(); |
|
132 } |
|
133 } |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // CFileManagerRestoreView::Id |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 TUid CFileManagerRestoreView::Id() const |
|
140 { |
|
141 return CFileManagerAppUi::KFileManagerRestoreViewId; |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CFileManagerRestoreView::CreateContainerL |
|
146 // ---------------------------------------------------------------------------- |
|
147 // |
|
148 CFileManagerContainerBase* CFileManagerRestoreView::CreateContainerL() |
|
149 { |
|
150 CFileManagerRestoreSettings& settings( iEngine.RestoreSettingsL() ); |
|
151 CFileManagerContainerBase* container = |
|
152 CFileManagerSettingListContainer::NewL( |
|
153 ClientRect(), |
|
154 iIndex, |
|
155 CFileManagerSettingListContainer::EListRestore, |
|
156 &settings ); |
|
157 container->SetEmptyTextL( R_QTN_FMGR_RESTORE_NO_BACKUPS ); |
|
158 return container; |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CFileManagerRestoreView::HandleCommandL |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 void CFileManagerRestoreView::HandleCommandL( TInt aCommand ) |
|
166 { |
|
167 switch( aCommand ) |
|
168 { |
|
169 case EAknSoftkeySelect: // FALLTHROUGH |
|
170 case EAknSoftkeyMark: // FALLTHROUGH |
|
171 case EAknSoftkeyUnmark: // FALLTHROUGH |
|
172 case EFileManagerSelectionKey: // FALLTHROUGH |
|
173 case EFileManagerToggleMark: // FALLTHROUGH |
|
174 case EFileManagerOpen: |
|
175 { |
|
176 CmdSelectL(); |
|
177 break; |
|
178 } |
|
179 case EAknSoftkeyOk: |
|
180 { |
|
181 CmdOkL(); |
|
182 break; |
|
183 } |
|
184 case EAknSoftkeyCancel: // FALLTHROUGH |
|
185 case EAknSoftkeyBack: |
|
186 { |
|
187 CmdCancelL(); |
|
188 break; |
|
189 } |
|
190 case EFileManagerCheckMark: |
|
191 { |
|
192 CmdCheckMarkL(); |
|
193 break; |
|
194 } |
|
195 default: |
|
196 { |
|
197 break; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // CFileManagerRestoreView::CmdOkL |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 void CFileManagerRestoreView::CmdOkL() |
|
207 { |
|
208 if ( !iContainer ) |
|
209 { |
|
210 return; |
|
211 } |
|
212 const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes(); |
|
213 |
|
214 TInt count( items->Count() ); |
|
215 |
|
216 if ( count ) |
|
217 { |
|
218 if( FileManagerDlgUtils::ShowConfirmQueryWithYesNoL( |
|
219 iDeleteBackups ? |
|
220 R_QTN_FMGR_DELETE_BACKUP_QUERY : R_QTN_FMGR_RESTORE_QUERY ) ) |
|
221 { |
|
222 if ( !CheckPhoneState() ) |
|
223 { |
|
224 FileManagerDlgUtils::ShowErrorNoteL( R_QTN_CRITICAL_ERROR ); |
|
225 } |
|
226 else |
|
227 { |
|
228 TUint64 selection( 0 ); |
|
229 for ( TInt i( 0 ); i < count; ++i ) |
|
230 { |
|
231 selection |= ( ( TUint64 ) 1 ) << ( ( *items )[ i ] ); |
|
232 } |
|
233 |
|
234 CFileManagerRestoreSettings& settings( |
|
235 iEngine.RestoreSettingsL() ); |
|
236 settings.SetSelection( selection ); |
|
237 |
|
238 if ( iDeleteBackups ) |
|
239 { |
|
240 // Delete selected backups and close this view |
|
241 iEngine.DeleteBackupsL(); |
|
242 iIndex = 0; |
|
243 static_cast< CFileManagerAppUi* >( |
|
244 AppUi() )->CloseRestoreViewL(); |
|
245 } |
|
246 else |
|
247 { |
|
248 // Start restoring selected backups |
|
249 TRAPD( err, StartProcessL( ERestoreProcess ) ); |
|
250 if ( err == KErrCorrupt ) |
|
251 { |
|
252 FileManagerDlgUtils::ShowErrorNoteL( |
|
253 R_QTN_FMGR_ERROR_CORRUPTED_BACKUP_FILE ); |
|
254 } |
|
255 else |
|
256 { |
|
257 User::LeaveIfError( err ); |
|
258 } |
|
259 } |
|
260 } |
|
261 } |
|
262 } |
|
263 else |
|
264 { |
|
265 CmdCancelL(); |
|
266 } |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------------------------------- |
|
270 // CFileManagerRestoreView::CmdCancelL |
|
271 // ---------------------------------------------------------------------------- |
|
272 // |
|
273 void CFileManagerRestoreView::CmdCancelL() |
|
274 { |
|
275 iIndex = 0; |
|
276 static_cast< CFileManagerAppUi* >( AppUi() )->CloseRestoreViewL(); |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // CFileManagerRestoreView::CmdSelectL |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 void CFileManagerRestoreView::CmdSelectL() |
|
284 { |
|
285 if ( !iContainer ) |
|
286 { |
|
287 return; |
|
288 } |
|
289 if ( !iContainer->ListBoxNumberOfItems() ) |
|
290 { |
|
291 return; |
|
292 } |
|
293 TInt index( iContainer->ListBoxCurrentItemIndex() ); |
|
294 iContainer->ListBoxToggleItemL( index ); |
|
295 iSelection ^= ( ( TUint64 ) 1 ) << index; // Toggle stored list selection |
|
296 UpdateCbaFromSelectionL(); |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // CFileManagerRestoreView::CmdCheckMarkL |
|
301 // ---------------------------------------------------------------------------- |
|
302 // |
|
303 void CFileManagerRestoreView::CmdCheckMarkL() |
|
304 { |
|
305 if ( !iContainer ) |
|
306 { |
|
307 return; |
|
308 } |
|
309 TInt mskTextId( R_QTN_MSK_MARK ); |
|
310 if ( iContainer->ListBoxIsItemSelected( |
|
311 iContainer->ListBoxCurrentItemIndex() ) ) |
|
312 { |
|
313 mskTextId = R_QTN_MSK_UNMARK; |
|
314 } |
|
315 |
|
316 SetCbaMskTextL( mskTextId ); |
|
317 } |
|
318 |
|
319 // ---------------------------------------------------------------------------- |
|
320 // CFileManagerRestoreView::ProcessFinishedL |
|
321 // ---------------------------------------------------------------------------- |
|
322 // |
|
323 void CFileManagerRestoreView::ProcessFinishedL( |
|
324 TInt aError, const TDesC& aName ) |
|
325 { |
|
326 TBool isRestore( iActiveProcess == ERestoreProcess ); |
|
327 |
|
328 CFileManagerViewBase::ProcessFinishedL( aError, aName ); |
|
329 |
|
330 // Exit when restore finished |
|
331 if ( isRestore ) |
|
332 { |
|
333 CmdCancelL(); |
|
334 } |
|
335 } |
|
336 |
|
337 // ---------------------------------------------------------------------------- |
|
338 // CFileManagerRestoreView::NotifyForegroundStatusChange |
|
339 // ---------------------------------------------------------------------------- |
|
340 // |
|
341 void CFileManagerRestoreView::NotifyForegroundStatusChange( |
|
342 TBool aForeground ) |
|
343 { |
|
344 FUNC_LOG |
|
345 |
|
346 if ( aForeground ) |
|
347 { |
|
348 TRAP_IGNORE( RefreshSettingsL() ); |
|
349 } |
|
350 } |
|
351 |
|
352 // ---------------------------------------------------------------------------- |
|
353 // CFileManagerRestoreView::RefreshSettingsL |
|
354 // ---------------------------------------------------------------------------- |
|
355 // |
|
356 void CFileManagerRestoreView::RefreshSettingsL() |
|
357 { |
|
358 FUNC_LOG |
|
359 |
|
360 DirectoryChangedL(); |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // CFileManagerRestoreView::RestoreSelectionL |
|
365 // ---------------------------------------------------------------------------- |
|
366 // |
|
367 void CFileManagerRestoreView::RestoreSelectionL() |
|
368 { |
|
369 if ( !iContainer ) |
|
370 { |
|
371 return; |
|
372 } |
|
373 const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes(); |
|
374 for ( TInt i( 0 ); i < KMaxSelection; ++i ) |
|
375 { |
|
376 if ( iSelection & ( ( ( TUint64 ) 1 ) << i ) ) |
|
377 { |
|
378 iContainer->ListBoxSelectItemL( i ); |
|
379 } |
|
380 else |
|
381 { |
|
382 iContainer->ListBoxDeselectItem( i ); |
|
383 } |
|
384 } |
|
385 UpdateCbaFromSelectionL(); |
|
386 } |
|
387 |
|
388 // ---------------------------------------------------------------------------- |
|
389 // CFileManagerRestoreView::UpdateCbaFromSelectionL |
|
390 // ---------------------------------------------------------------------------- |
|
391 // |
|
392 void CFileManagerRestoreView::UpdateCbaFromSelectionL() |
|
393 { |
|
394 if ( !iContainer ) |
|
395 { |
|
396 return; |
|
397 } |
|
398 CmdCheckMarkL(); |
|
399 CEikButtonGroupContainer* cba = Cba(); |
|
400 TBool hasItem(iContainer->ListBoxNumberOfItems()); |
|
401 const CArrayFix< TInt >* items = iContainer->ListBoxSelectionIndexes(); |
|
402 if ( hasItem && items->Count() ) |
|
403 { |
|
404 cba->MakeCommandVisible( EAknSoftkeyOk, ETrue ); |
|
405 } |
|
406 else |
|
407 { |
|
408 cba->MakeCommandVisible( EAknSoftkeyOk, EFalse ); |
|
409 } |
|
410 cba->DrawDeferred(); |
|
411 } |
|
412 |
|
413 // ---------------------------------------------------------------------------- |
|
414 // CFileManagerRestoreView::UpdateCbaL |
|
415 // ---------------------------------------------------------------------------- |
|
416 // |
|
417 void CFileManagerRestoreView::UpdateCbaL() |
|
418 { |
|
419 CEikButtonGroupContainer* cba = Cba(); |
|
420 TBool hasItem(iContainer->ListBoxNumberOfItems()); |
|
421 cba->MakeCommandVisible( EAknSoftkeyMark, hasItem ); |
|
422 TBool hasSelecttionItem( hasItem && ( iContainer->ListBoxSelectionIndexesCount() ) ); |
|
423 cba->MakeCommandVisible( EAknSoftkeyOk, hasSelecttionItem ); |
|
424 cba->DrawDeferred(); |
|
425 } |
|
426 |
|
427 // End of File |
|