--- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Tue Aug 24 10:24:14 2010 +0800
@@ -18,35 +18,83 @@
#include "fmoperationbase.h"
#include "fmoperationservice.h"
#include "fmoperationformat.h"
+#include "fmbkupengine.h"
+#include "fmbackupsettings.h"
+#include "fmbackuprestorehandler.h"
+#include "fmoperationviewdetails.h"
#include "fmviewdetailsdialog.h"
#include "fmdlgutils.h"
#include "fmutils.h"
-
+#include <hbaction.h>
#include <hbprogressdialog.h>
#include <hbaction.h>
-#include <hbmessagebox.h>
+#include <hbglobal.h>
+#include <QFileInfo>
+/*
+ * Constructs one operation result processer with \a operation Service.
+ */
FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService )
: mOperationService( operationService ), mNote( 0 )
{
}
+/*
+ * Destructs the operation result processer
+ */
FmOperationResultProcesser::~FmOperationResultProcesser(void)
{
}
+/*
+ * Called by operation service on_operation_askForRename
+ * \sa FmOperationService::on_operation_askForRename
+ */
void FmOperationResultProcesser::onAskForRename(
FmOperationBase* operationBase, const QString &srcFile, QString *destFile )
{
Q_UNUSED( operationBase );
+ int maxFileNameLength = FmUtils::getMaxFileNameLength();
QString questionText = QString( "file " ) +
srcFile + QString( " already exist, please rename:" );
- QString value;
- FmDlgUtils::showTextQuery( questionText, value, true );
- *destFile = value;
+ QString value;
+ QFileInfo srcFileInfo(srcFile);
+ QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
+
+ bool ret = FmDlgUtils::showTextQuery( questionText, value, regExpList,
+ maxFileNameLength, QString(), false );
+ while ( ret ) {
+ // remove whitespace from the start and the end.
+ value = value.trimmed();
+ QString newTargetPath = FmUtils::fillPathWithSplash(
+ srcFileInfo.absolutePath() ) + value;
+ QString errString;
+ // check if name/path is available for use.
+ if( !FmUtils::checkNewFolderOrFile( value, newTargetPath, errString ) ) {
+ FmDlgUtils::information( errString );
+ ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, maxFileNameLength, QString(), false );
+ continue;
+ } else {
+ break;
+ }
+ }
+ if( ret ) {
+ // Got file/folder name for rename, save it to destFile
+ *destFile = value;
+ QFileInfo destFileInfo( *destFile );
+ if ( ( srcFileInfo.suffix().compare( destFileInfo.suffix(), Qt::CaseInsensitive ) != 0 )
+ && srcFileInfo.isFile() ) {
+ // popup warning when the suffix of file is changed.
+ FmDlgUtils::information( hbTrId( "File may become unusable when file name extension is changed" ) );
+ }
+ }
}
+/*
+ * Called by operation service on_operation_askForReplace
+ * \sa FmOperationService::on_operation_askForReplace
+ */
void FmOperationResultProcesser::onAskForReplace(
FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted )
{
@@ -55,16 +103,30 @@
QString questionText = QString( "file " ) +
srcFile + QString( " already exist, replace it?" );
- if( HbMessageBox::question( questionText ) ) {
+ if( FmDlgUtils::question( questionText ) ) {
*isAccepted = true;
} else {
*isAccepted = false;
}
}
+/*
+ * Called by operation service on_operation_showNote
+ * \sa FmOperationService::on_operation_showNote
+ */
+void FmOperationResultProcesser::onShowNote( FmOperationBase* operationBase, const char *noteString )
+{
+ Q_UNUSED( operationBase );
+ FmDlgUtils::information(hbTrId(noteString));
+}
+
+/*
+ * Called by operation service on_operation_notifyWaiting
+ * \sa FmOperationService::on_operation_notifyWaiting
+ */
void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable )
{
- QString title = tr("Operation");
+ QString title = hbTrId("Operation");
switch( operationBase->operationType() )
{
case FmOperationService::EOperationTypeBackup:
@@ -87,6 +149,10 @@
showWaiting( title, cancelable );
}
+/*
+ * Called by operation service on_operation_notifyPreparing
+ * \sa FmOperationService::on_operation_notifyPreparing
+ */
void FmOperationResultProcesser::onNotifyPreparing( FmOperationBase* operationBase, bool cancelable )
{
QString title = hbTrId("Operation");
@@ -117,9 +183,13 @@
showPreparing( title, cancelable );
}
+/*
+ * Called by operation service on_operation_notifyStart
+ * \sa FmOperationService::on_operation_notifyStart
+ */
void FmOperationResultProcesser::onNotifyStart( FmOperationBase* operationBase, bool cancelable, int maxSteps )
{
- QString title = tr("Operation");
+ QString title = hbTrId("Operation");
switch( operationBase->operationType() )
{
case FmOperationService::EOperationTypeBackup:
@@ -147,12 +217,20 @@
showProgress( title, cancelable, maxSteps );
}
+/*
+ * Called by operation service on_operation_notifyProgress
+ * \sa FmOperationService::on_operation_notifyProgress
+ */
void FmOperationResultProcesser::onNotifyProgress( FmOperationBase* operationBase, int currentStep )
{
Q_UNUSED( operationBase );
setProgress( currentStep );
}
+/*
+ * Called by operation service on_operation_notifyFinish
+ * \sa FmOperationService::on_operation_notifyFinish
+ */
void FmOperationResultProcesser::onNotifyFinish( FmOperationBase* operationBase )
{
@@ -179,83 +257,157 @@
}
case FmOperationService::EOperationTypeFormat:
{
- HbMessageBox::information( QString( hbTrId("Format succeed!")) );
+ FmDlgUtils::information( QString( hbTrId("Format succeed!")) );
FmOperationFormat *paramFormat = static_cast<FmOperationFormat*>( operationBase );
- QString title( tr( "Drive name ") );
+ QString title( hbTrId( "Drive name ") );
QString driveName( paramFormat->driverName() );
- QString volumeName;
- while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){
+ FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName );
+ FmDriverInfo::DriveState state = driverInfo.driveState();
+ FmDriverInfo::DriveType driveType = driverInfo.driveType();
+
+ // If drive is available and it is mmc or usb memory
+ if( ( state & FmDriverInfo::EDriveAvailable ) &&
+ ( driveType == FmDriverInfo::EDriveTypeMemoryCard ||
+ driveType == FmDriverInfo::EDriveTypeUsbMemory ) ) {
+ bool needToSetVolume = false;
+ QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( driveName, needToSetVolume );
+ //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will
+ //be excuted at lease once to set the volume name.
+ while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, QString(), false ) ){
int err = FmUtils::renameDrive( driveName, volumeName );
- if ( err == FmErrNone ){
- HbMessageBox::information( hbTrId( "The name has been changed!" ) );
- mOperationService->on_operationThread_refreshModel( driveName );
+ if ( err == FmErrNone ) {
+ FmDlgUtils::information( hbTrId( "The name has been changed!" ) );
+ mOperationService->on_operation_driveSpaceChanged();
break;
} else if( err == FmErrBadName ) {
- HbMessageBox::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
+ FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
} else{
- HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
+ FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
break;
}
}
+ }
break;
}
case FmOperationService::EOperationTypeBackup:
{
- HbMessageBox::information( QString( hbTrId("Backup succeed!")) );
+ FmDlgUtils::information( QString( hbTrId("Backup succeed!")) );
break;
}
case FmOperationService::EOperationTypeRestore:
{
- HbMessageBox::information( QString( hbTrId("Restore succeed!")) );
+ FmDlgUtils::information( QString( hbTrId("Restore succeed!")) );
break;
}
default:
- HbMessageBox::information( QString( hbTrId("Operation finished")) );
+ FmDlgUtils::information( QString( hbTrId("Operation finished")) );
}
}
-void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, QString errString )
+
+/*
+ * Called by operation service on_operation_notifyError
+ * \sa FmOperationService::on_operation_notifyError
+ */
+void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, const QString &errString )
{
Q_UNUSED( errString );
failAndCloseProgress();
switch( error )
{
+ case FmErrCancel:
+ cancelProgress();
+ // Do not pop up general cancel note as it is not needed( according to TB9.2 ).
+ // If it should be added later, please do not use blocking note.
+ // Blocking note will cause second backup operaion freeze after cancel previous backup operation
+ // as QEventLoop::exec will cause some problem when used for blocking dialog.
+ // HbDialog has already removed exec function which is implemented with QEventLoop::exec.
+ // If need use QEventLoop::exec to block code execute sequence, It should be invoked in a Qt::QueuedConnection slot.
+ return;
case FmErrAlreadyStarted:
- HbMessageBox::information( QString( hbTrId("Operation already started!")) );
+ FmDlgUtils::information( QString( hbTrId("Operation already started!")) );
+ return;
+ case FmErrLocked:
+ {
+ FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase);
+ if( operationBackup ) {
+ // special error note for backup
+ QString targetDrive( operationBackup->targetDrive() );
+ QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) );
+ QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume );
+ FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_locked") ).arg( driveString ) );
+ } else {
+ FmDlgUtils::information( QString( hbTrId("Operation failed because drive is locked!")) );
+ }
+ return;
+ }
+ case FmErrPathNotFound:
+ FmDlgUtils::information( QString( hbTrId("Operation failed because can not find target path or drive is not available!") ) );
+ return;
+ case FmErrCorrupt:
+ {
+ FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase);
+ if( operationBackup ) {
+ // special error note for backup
+ QString targetDrive( operationBackup->targetDrive() );
+ QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) );
+ QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume );
+ FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_corrupted") ).arg( driveString ) );
+ } else {
+ FmDlgUtils::information( QString( hbTrId("Operation failed because target media is corrupted!") ) );
+ }
+ return;
+ }
+ case FmErrNotReady: // Caused when MMC & OTG is not inserted when start backup
+ {
+ FmOperationBackup *operationBackup = qobject_cast<FmOperationBackup*>(operationBase);
+ if( operationBackup ) {
+ // special error note for backup
+ QString targetDrive( operationBackup->targetDrive() );
+ QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) );
+ QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume );
+ FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_unavailable") ).arg( driveString ) );
+ } else {
+ FmDlgUtils::information( QString( hbTrId("Operation failed because device is not ready!") ) );
+ }
+ return;
+ }
+ case FmErrDisMounted: // Caused by eject MMC when preparing backup, will be localized later
+ FmDlgUtils::information( QString( hbTrId("Operation failed because backup target drive has been removed!") ) );
return;
case FmErrDiskFull:
- HbMessageBox::information( QString( hbTrId("Not enough space. Operation cancelled.!")) );
+ FmDlgUtils::information( QString( hbTrId("Not enough space. Operation cancelled!")) );
return;
case FmErrCopyDestToSubFolderInSrc:
- HbMessageBox::information( QString( hbTrId("Can not copy to sub folder!")) );
+ FmDlgUtils::information( QString( hbTrId("Can not copy to sub folder!")) );
return;
case FmErrMoveDestToSubFolderInSrc:
- HbMessageBox::information( QString( hbTrId("Can not move to sub folder!")) );
+ FmDlgUtils::information( QString( hbTrId("Can not move to sub folder!")) );
return;
case FmErrCannotRemove:{
if( operationBase->operationType() == FmOperationService::EOperationTypeCopy ) {
// when copy a file/dir to same name destination, and delete dest fail, this error will occur
- HbMessageBox::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) );
+ FmDlgUtils::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) );
return;
}
else if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
// when move a file/dir to same name destination, and delete dest fail, this error will occur
- HbMessageBox::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) );
+ FmDlgUtils::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) );
return;
}
// when delete file/dir fail, this error will occur
- HbMessageBox::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) );
+ FmDlgUtils::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) );
return;
}
case FmErrRemoveDefaultFolder:{
if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
// when move a default folder
- HbMessageBox::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) );
+ FmDlgUtils::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) );
return;
}
else {
// when delete the default folder
- HbMessageBox::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) );
+ FmDlgUtils::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) );
return;
}
}
@@ -264,29 +416,28 @@
switch( operationBase->operationType() )
{
case FmOperationService::EOperationTypeFormat:
- HbMessageBox::information( QString( hbTrId("Format failed!")) );
+ FmDlgUtils::information( QString( hbTrId("Format failed!")) );
break;
default:
- HbMessageBox::information( QString( hbTrId("Operation failed")) );
+ FmDlgUtils::information( QString( hbTrId("Operation failed")) );
}
}
-void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase )
-{
- Q_UNUSED( operationBase );
- cancelProgress();
- HbMessageBox::information( QString( hbTrId("Operation Canceled!") ) );
-}
-
-
+/*
+ * Responds to waiting note's cancel signal.
+ */
void FmOperationResultProcesser::onProgressCancelled()
{
mOperationService->cancelOperation();
}
-//
+/*
+ * Shows the waiting dialog with
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
void FmOperationResultProcesser::showWaiting( QString title, bool cancelable )
{
qDebug("show warning");
@@ -304,14 +455,25 @@
// mNote->setProgressDialogType( HbProgressDialog::WaitNote );
// }
mNote->setText( title );
- if( !cancelable )
- mNote->primaryAction()->setDisabled( true );
- else
- mNote->primaryAction()->setDisabled( false );
- mNote->exec();
+ //KRAZY: ignore krazy warning because QAction must be used.
+ QList<QAction *> actionList = mNote->actions();
+ if (actionList.size() > 0) {
+ QAction *cancelAction = actionList.at(0);
+ if (!cancelable) {
+ cancelAction->setDisabled( true );
+ } else {
+ cancelAction->setDisabled( false );
+ }
+ }
+ mNote->open();
}
+/*
+ * Shows the preparing dialog with
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
void FmOperationResultProcesser::showPreparing( QString title, bool cancelable )
{
qDebug("show preparing");
@@ -333,15 +495,24 @@
mNote->setMaximum( 65535 );
mNote->setProgressValue( 0 );
mNote->setText( title );
- if( !cancelable ){
- mNote->primaryAction()->setDisabled( true );
- }
- else{
- mNote->primaryAction()->setDisabled( false );
- }
- mNote->exec();
+ //KRAZY: ignore krazy warning because QAction must be used.
+ QList<QAction *> actionList = mNote->actions();
+ if (actionList.size() > 0) {
+ QAction *cancelAction = actionList.at(0);
+ if (!cancelable) {
+ cancelAction->setDisabled( true );
+ } else {
+ cancelAction->setDisabled( false );
+ }
+ }
+ mNote->open();
}
+/*
+ * Shows the progress dialog with
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
void FmOperationResultProcesser::showProgress( QString title, bool cancelable, int maxValue )
{
qDebug("show progress");
@@ -365,23 +536,32 @@
mNote->setMaximum( maxValue );
mNote->setProgressValue( 0 );
-
- if( !cancelable ){
- mNote->primaryAction()->setDisabled( true );
- }
- else{
- mNote->primaryAction()->setDisabled( false );
- }
-
- mNote->exec();
+ //KRAZY: ignore krazy warning because QAction must be used.
+ QList<QAction *> actionList = mNote->actions();
+ if (actionList.size() > 0) {
+ QAction *cancelAction = actionList.at(0);
+ if(!cancelable) {
+ cancelAction->setDisabled( true );
+ } else {
+ cancelAction->setDisabled( false );
+ }
+ }
+ mNote->open();
}
+/*
+ * Sets the current progress value to be \a value
+ */
void FmOperationResultProcesser::setProgress( int value )
{
qDebug("set progress");
if( mNote )
mNote->setProgressValue( value );
}
+
+/*
+ * Finishes the progress.
+ */
void FmOperationResultProcesser::finishProgress()
{
qDebug("finish progress");
@@ -390,6 +570,9 @@
}
}
+/*
+ * Cancels the progress bar.
+ */
void FmOperationResultProcesser::cancelProgress()
{
qDebug("cancel progress");
@@ -398,6 +581,9 @@
}
}
+/*
+ * Fails and closes the progress bar.
+ */
void FmOperationResultProcesser::failAndCloseProgress()
{
qDebug("fail progress");