16 */ |
16 */ |
17 #include "fmoperationresultprocesser.h" |
17 #include "fmoperationresultprocesser.h" |
18 #include "fmoperationbase.h" |
18 #include "fmoperationbase.h" |
19 #include "fmoperationservice.h" |
19 #include "fmoperationservice.h" |
20 #include "fmoperationformat.h" |
20 #include "fmoperationformat.h" |
|
21 #include "fmbkupengine.h" |
|
22 #include "fmbackupsettings.h" |
|
23 #include "fmbackuprestorehandler.h" |
|
24 #include "fmoperationviewdetails.h" |
21 #include "fmviewdetailsdialog.h" |
25 #include "fmviewdetailsdialog.h" |
22 #include "fmdlgutils.h" |
26 #include "fmdlgutils.h" |
23 #include "fmutils.h" |
27 #include "fmutils.h" |
24 |
28 #include <hbaction.h> |
25 #include <hbprogressdialog.h> |
29 #include <hbprogressdialog.h> |
26 #include <hbaction.h> |
30 #include <hbaction.h> |
27 #include <hbmessagebox.h> |
31 #include <hbglobal.h> |
28 |
32 #include <QFileInfo> |
|
33 |
|
34 /* |
|
35 * Constructs one operation result processer with \a operation Service. |
|
36 */ |
29 FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService ) |
37 FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService ) |
30 : mOperationService( operationService ), mNote( 0 ) |
38 : mOperationService( operationService ), mNote( 0 ) |
31 { |
39 { |
32 } |
40 } |
33 |
41 |
|
42 /* |
|
43 * Destructs the operation result processer |
|
44 */ |
34 FmOperationResultProcesser::~FmOperationResultProcesser(void) |
45 FmOperationResultProcesser::~FmOperationResultProcesser(void) |
35 { |
46 { |
36 } |
47 } |
37 |
48 |
|
49 /* |
|
50 * Called by operation service on_operation_askForRename |
|
51 * \sa FmOperationService::on_operation_askForRename |
|
52 */ |
38 void FmOperationResultProcesser::onAskForRename( |
53 void FmOperationResultProcesser::onAskForRename( |
39 FmOperationBase* operationBase, const QString &srcFile, QString *destFile ) |
54 FmOperationBase* operationBase, const QString &srcFile, QString *destFile ) |
40 { |
55 { |
41 Q_UNUSED( operationBase ); |
56 Q_UNUSED( operationBase ); |
|
57 int maxFileNameLength = FmUtils::getMaxFileNameLength(); |
42 |
58 |
43 QString questionText = QString( "file " ) + |
59 QString questionText = QString( "file " ) + |
44 srcFile + QString( " already exist, please rename:" ); |
60 srcFile + QString( " already exist, please rename:" ); |
45 QString value; |
61 QString value; |
46 FmDlgUtils::showTextQuery( questionText, value, true ); |
62 QFileInfo srcFileInfo(srcFile); |
47 *destFile = value; |
63 QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot ); |
48 } |
64 |
49 |
65 bool ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, |
|
66 maxFileNameLength, QString(), false ); |
|
67 while ( ret ) { |
|
68 // remove whitespace from the start and the end. |
|
69 value = value.trimmed(); |
|
70 QString newTargetPath = FmUtils::fillPathWithSplash( |
|
71 srcFileInfo.absolutePath() ) + value; |
|
72 QString errString; |
|
73 // check if name/path is available for use. |
|
74 if( !FmUtils::checkNewFolderOrFile( value, newTargetPath, errString ) ) { |
|
75 FmDlgUtils::information( errString ); |
|
76 ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, maxFileNameLength, QString(), false ); |
|
77 continue; |
|
78 } else { |
|
79 break; |
|
80 } |
|
81 } |
|
82 if( ret ) { |
|
83 // Got file/folder name for rename, save it to destFile |
|
84 *destFile = value; |
|
85 QFileInfo destFileInfo( *destFile ); |
|
86 if ( ( srcFileInfo.suffix().compare( destFileInfo.suffix(), Qt::CaseInsensitive ) != 0 ) |
|
87 && srcFileInfo.isFile() ) { |
|
88 // popup warning when the suffix of file is changed. |
|
89 FmDlgUtils::information( hbTrId( "File may become unusable when file name extension is changed" ) ); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 /* |
|
95 * Called by operation service on_operation_askForReplace |
|
96 * \sa FmOperationService::on_operation_askForReplace |
|
97 */ |
50 void FmOperationResultProcesser::onAskForReplace( |
98 void FmOperationResultProcesser::onAskForReplace( |
51 FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted ) |
99 FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted ) |
52 { |
100 { |
53 Q_UNUSED( operationBase ); |
101 Q_UNUSED( operationBase ); |
54 Q_UNUSED( destFile ); |
102 Q_UNUSED( destFile ); |
55 |
103 |
56 QString questionText = QString( "file " ) + |
104 QString questionText = QString( "file " ) + |
57 srcFile + QString( " already exist, replace it?" ); |
105 srcFile + QString( " already exist, replace it?" ); |
58 if( HbMessageBox::question( questionText ) ) { |
106 if( FmDlgUtils::question( questionText ) ) { |
59 *isAccepted = true; |
107 *isAccepted = true; |
60 } else { |
108 } else { |
61 *isAccepted = false; |
109 *isAccepted = false; |
62 } |
110 } |
63 } |
111 } |
64 |
112 |
|
113 /* |
|
114 * Called by operation service on_operation_showNote |
|
115 * \sa FmOperationService::on_operation_showNote |
|
116 */ |
|
117 void FmOperationResultProcesser::onShowNote( FmOperationBase* operationBase, const char *noteString ) |
|
118 { |
|
119 Q_UNUSED( operationBase ); |
|
120 FmDlgUtils::information(hbTrId(noteString)); |
|
121 } |
|
122 |
|
123 /* |
|
124 * Called by operation service on_operation_notifyWaiting |
|
125 * \sa FmOperationService::on_operation_notifyWaiting |
|
126 */ |
65 void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable ) |
127 void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable ) |
66 { |
128 { |
67 QString title = tr("Operation"); |
129 QString title = hbTrId("Operation"); |
68 switch( operationBase->operationType() ) |
130 switch( operationBase->operationType() ) |
69 { |
131 { |
70 case FmOperationService::EOperationTypeBackup: |
132 case FmOperationService::EOperationTypeBackup: |
71 title = hbTrId("backuping"); |
133 title = hbTrId("backuping"); |
72 break; |
134 break; |
177 FmUtils::getDriveLetterFromPath( paramFolderDetails->folderPath() ) ); |
255 FmUtils::getDriveLetterFromPath( paramFolderDetails->folderPath() ) ); |
178 break; |
256 break; |
179 } |
257 } |
180 case FmOperationService::EOperationTypeFormat: |
258 case FmOperationService::EOperationTypeFormat: |
181 { |
259 { |
182 HbMessageBox::information( QString( hbTrId("Format succeed!")) ); |
260 FmDlgUtils::information( QString( hbTrId("Format succeed!")) ); |
183 FmOperationFormat *paramFormat = static_cast<FmOperationFormat*>( operationBase ); |
261 FmOperationFormat *paramFormat = static_cast<FmOperationFormat*>( operationBase ); |
184 QString title( tr( "Drive name ") ); |
262 QString title( hbTrId( "Drive name ") ); |
185 QString driveName( paramFormat->driverName() ); |
263 QString driveName( paramFormat->driverName() ); |
186 QString volumeName; |
264 FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName ); |
187 while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){ |
265 FmDriverInfo::DriveState state = driverInfo.driveState(); |
|
266 FmDriverInfo::DriveType driveType = driverInfo.driveType(); |
|
267 |
|
268 // If drive is available and it is mmc or usb memory |
|
269 if( ( state & FmDriverInfo::EDriveAvailable ) && |
|
270 ( driveType == FmDriverInfo::EDriveTypeMemoryCard || |
|
271 driveType == FmDriverInfo::EDriveTypeUsbMemory ) ) { |
|
272 bool needToSetVolume = false; |
|
273 QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( driveName, needToSetVolume ); |
|
274 //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will |
|
275 //be excuted at lease once to set the volume name. |
|
276 while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, QString(), false ) ){ |
188 int err = FmUtils::renameDrive( driveName, volumeName ); |
277 int err = FmUtils::renameDrive( driveName, volumeName ); |
189 if ( err == FmErrNone ){ |
278 if ( err == FmErrNone ) { |
190 HbMessageBox::information( hbTrId( "The name has been changed!" ) ); |
279 FmDlgUtils::information( hbTrId( "The name has been changed!" ) ); |
191 mOperationService->on_operationThread_refreshModel( driveName ); |
280 mOperationService->on_operation_driveSpaceChanged(); |
192 break; |
281 break; |
193 } else if( err == FmErrBadName ) { |
282 } else if( err == FmErrBadName ) { |
194 HbMessageBox::information( hbTrId( "Illegal characters! Use only letters and numbers." ) ); |
283 FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) ); |
195 } else{ |
284 } else{ |
196 HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) ); |
285 FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) ); |
197 break; |
286 break; |
198 } |
287 } |
199 } |
288 } |
|
289 } |
200 break; |
290 break; |
201 } |
291 } |
202 case FmOperationService::EOperationTypeBackup: |
292 case FmOperationService::EOperationTypeBackup: |
203 { |
293 { |
204 HbMessageBox::information( QString( hbTrId("Backup succeed!")) ); |
294 FmDlgUtils::information( QString( hbTrId("Backup succeed!")) ); |
205 break; |
295 break; |
206 } |
296 } |
207 case FmOperationService::EOperationTypeRestore: |
297 case FmOperationService::EOperationTypeRestore: |
208 { |
298 { |
209 HbMessageBox::information( QString( hbTrId("Restore succeed!")) ); |
299 FmDlgUtils::information( QString( hbTrId("Restore succeed!")) ); |
210 break; |
300 break; |
211 } |
301 } |
212 default: |
302 default: |
213 HbMessageBox::information( QString( hbTrId("Operation finished")) ); |
303 FmDlgUtils::information( QString( hbTrId("Operation finished")) ); |
214 |
304 |
215 } |
305 } |
216 } |
306 } |
217 void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, QString errString ) |
307 |
|
308 /* |
|
309 * Called by operation service on_operation_notifyError |
|
310 * \sa FmOperationService::on_operation_notifyError |
|
311 */ |
|
312 void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, const QString &errString ) |
218 { |
313 { |
219 Q_UNUSED( errString ); |
314 Q_UNUSED( errString ); |
220 failAndCloseProgress(); |
315 failAndCloseProgress(); |
221 switch( error ) |
316 switch( error ) |
222 { |
317 { |
|
318 case FmErrCancel: |
|
319 cancelProgress(); |
|
320 // Do not pop up general cancel note as it is not needed( according to TB9.2 ). |
|
321 // If it should be added later, please do not use blocking note. |
|
322 // Blocking note will cause second backup operaion freeze after cancel previous backup operation |
|
323 // as QEventLoop::exec will cause some problem when used for blocking dialog. |
|
324 // HbDialog has already removed exec function which is implemented with QEventLoop::exec. |
|
325 // If need use QEventLoop::exec to block code execute sequence, It should be invoked in a Qt::QueuedConnection slot. |
|
326 return; |
223 case FmErrAlreadyStarted: |
327 case FmErrAlreadyStarted: |
224 HbMessageBox::information( QString( hbTrId("Operation already started!")) ); |
328 FmDlgUtils::information( QString( hbTrId("Operation already started!")) ); |
|
329 return; |
|
330 case FmErrLocked: |
|
331 { |
|
332 FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase); |
|
333 if( operationBackup ) { |
|
334 // special error note for backup |
|
335 QString targetDrive( operationBackup->targetDrive() ); |
|
336 QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); |
|
337 QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); |
|
338 FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_locked") ).arg( driveString ) ); |
|
339 } else { |
|
340 FmDlgUtils::information( QString( hbTrId("Operation failed because drive is locked!")) ); |
|
341 } |
|
342 return; |
|
343 } |
|
344 case FmErrPathNotFound: |
|
345 FmDlgUtils::information( QString( hbTrId("Operation failed because can not find target path or drive is not available!") ) ); |
|
346 return; |
|
347 case FmErrCorrupt: |
|
348 { |
|
349 FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase); |
|
350 if( operationBackup ) { |
|
351 // special error note for backup |
|
352 QString targetDrive( operationBackup->targetDrive() ); |
|
353 QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); |
|
354 QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); |
|
355 FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_corrupted") ).arg( driveString ) ); |
|
356 } else { |
|
357 FmDlgUtils::information( QString( hbTrId("Operation failed because target media is corrupted!") ) ); |
|
358 } |
|
359 return; |
|
360 } |
|
361 case FmErrNotReady: // Caused when MMC & OTG is not inserted when start backup |
|
362 { |
|
363 FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase); |
|
364 if( operationBackup ) { |
|
365 // special error note for backup |
|
366 QString targetDrive( operationBackup->targetDrive() ); |
|
367 QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); |
|
368 QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); |
|
369 FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_unavailable") ).arg( driveString ) ); |
|
370 } else { |
|
371 FmDlgUtils::information( QString( hbTrId("Operation failed because device is not ready!") ) ); |
|
372 } |
|
373 return; |
|
374 } |
|
375 case FmErrDisMounted: // Caused by eject MMC when preparing backup, will be localized later |
|
376 FmDlgUtils::information( QString( hbTrId("Operation failed because backup target drive has been removed!") ) ); |
225 return; |
377 return; |
226 case FmErrDiskFull: |
378 case FmErrDiskFull: |
227 HbMessageBox::information( QString( hbTrId("Not enough space. Operation cancelled.!")) ); |
379 FmDlgUtils::information( QString( hbTrId("Not enough space. Operation cancelled!")) ); |
228 return; |
380 return; |
229 case FmErrCopyDestToSubFolderInSrc: |
381 case FmErrCopyDestToSubFolderInSrc: |
230 HbMessageBox::information( QString( hbTrId("Can not copy to sub folder!")) ); |
382 FmDlgUtils::information( QString( hbTrId("Can not copy to sub folder!")) ); |
231 return; |
383 return; |
232 case FmErrMoveDestToSubFolderInSrc: |
384 case FmErrMoveDestToSubFolderInSrc: |
233 HbMessageBox::information( QString( hbTrId("Can not move to sub folder!")) ); |
385 FmDlgUtils::information( QString( hbTrId("Can not move to sub folder!")) ); |
234 return; |
386 return; |
235 case FmErrCannotRemove:{ |
387 case FmErrCannotRemove:{ |
236 if( operationBase->operationType() == FmOperationService::EOperationTypeCopy ) { |
388 if( operationBase->operationType() == FmOperationService::EOperationTypeCopy ) { |
237 // when copy a file/dir to same name destination, and delete dest fail, this error will occur |
389 // when copy a file/dir to same name destination, and delete dest fail, this error will occur |
238 HbMessageBox::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) ); |
390 FmDlgUtils::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) ); |
239 return; |
391 return; |
240 } |
392 } |
241 else if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) { |
393 else if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) { |
242 // when move a file/dir to same name destination, and delete dest fail, this error will occur |
394 // when move a file/dir to same name destination, and delete dest fail, this error will occur |
243 HbMessageBox::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) ); |
395 FmDlgUtils::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) ); |
244 return; |
396 return; |
245 } |
397 } |
246 // when delete file/dir fail, this error will occur |
398 // when delete file/dir fail, this error will occur |
247 HbMessageBox::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) ); |
399 FmDlgUtils::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) ); |
248 return; |
400 return; |
249 } |
401 } |
250 case FmErrRemoveDefaultFolder:{ |
402 case FmErrRemoveDefaultFolder:{ |
251 if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) { |
403 if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) { |
252 // when move a default folder |
404 // when move a default folder |
253 HbMessageBox::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) ); |
405 FmDlgUtils::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) ); |
254 return; |
406 return; |
255 } |
407 } |
256 else { |
408 else { |
257 // when delete the default folder |
409 // when delete the default folder |
258 HbMessageBox::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) ); |
410 FmDlgUtils::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) ); |
259 return; |
411 return; |
260 } |
412 } |
261 } |
413 } |
262 } |
414 } |
263 |
415 |
264 switch( operationBase->operationType() ) |
416 switch( operationBase->operationType() ) |
265 { |
417 { |
266 case FmOperationService::EOperationTypeFormat: |
418 case FmOperationService::EOperationTypeFormat: |
267 HbMessageBox::information( QString( hbTrId("Format failed!")) ); |
419 FmDlgUtils::information( QString( hbTrId("Format failed!")) ); |
268 break; |
420 break; |
269 default: |
421 default: |
270 HbMessageBox::information( QString( hbTrId("Operation failed")) ); |
422 FmDlgUtils::information( QString( hbTrId("Operation failed")) ); |
271 } |
423 } |
272 |
424 |
273 } |
425 } |
274 |
426 |
275 void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase ) |
427 /* |
276 { |
428 * Responds to waiting note's cancel signal. |
277 Q_UNUSED( operationBase ); |
429 */ |
278 cancelProgress(); |
|
279 HbMessageBox::information( QString( hbTrId("Operation Canceled!") ) ); |
|
280 } |
|
281 |
|
282 |
|
283 void FmOperationResultProcesser::onProgressCancelled() |
430 void FmOperationResultProcesser::onProgressCancelled() |
284 { |
431 { |
285 mOperationService->cancelOperation(); |
432 mOperationService->cancelOperation(); |
286 } |
433 } |
287 |
434 |
288 |
435 |
289 // |
436 /* |
|
437 * Shows the waiting dialog with |
|
438 * \a title the title of the dialog. |
|
439 * \a cancelable whether it could be cancelled. |
|
440 */ |
290 void FmOperationResultProcesser::showWaiting( QString title, bool cancelable ) |
441 void FmOperationResultProcesser::showWaiting( QString title, bool cancelable ) |
291 { |
442 { |
292 qDebug("show warning"); |
443 qDebug("show warning"); |
293 if( mNote ){ |
444 if( mNote ){ |
294 mNote->close(); |
445 mNote->close(); |