# HG changeset patch # User hgs # Date 1280979007 -28800 # Node ID 328cf6fbe40c8f2e9be016981b284ce07fa08763 # Parent 39cf9ced4cc42c0a37a41d3e43d3304b5ff4b6f4 201031 diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/filemanager.pri --- a/filemanager/src/filemanager/filemanager.pri Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/filemanager.pri Thu Aug 05 11:30:07 2010 +0800 @@ -36,10 +36,10 @@ src/operationservice/fmoperationthread.h \ src/operationservice/fmoperationbase.h \ src/operationservice/fmoperationresultprocesser.h \ - src/operationservice/fmoperationcopy.h \ - src/operationservice/fmoperationmove.h \ + src/operationservice/fmoperationcopyormove.h \ src/operationservice/fmoperationremove.h \ src/operationservice/fmoperationformat.h \ + src/operationservice/fmoperationviewdetails.h \ src/backuprestore/fmbackupview.h \ src/backuprestore/fmbackupwidget.h \ src/backuprestore/fmrestoreview.h \ @@ -79,9 +79,9 @@ src/operationservice/fmoperationthread.cpp \ src/operationservice/fmoperationbase.cpp \ src/operationservice/fmoperationresultprocesser.cpp \ - src/operationservice/fmoperationcopy.cpp \ - src/operationservice/fmoperationmove.cpp \ + src/operationservice/fmoperationcopyormove.cpp \ src/operationservice/fmoperationremove.cpp \ + src/operationservice/fmoperationviewdetails.cpp \ src/backuprestore/fmbackupview.cpp \ src/backuprestore/fmbackupwidget.cpp \ src/backuprestore/fmrestoreview.cpp \ diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmcombinedquery.cpp --- a/filemanager/src/filemanager/src/components/fmcombinedquery.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmcombinedquery.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -28,7 +28,9 @@ FmCombinedQuery::FmCombinedQuery( QGraphicsItem *parent ) : FmDialog( parent ), mSelectMode ( MultiSelectMode ), mDominantIndex ( -1 ) { + setObjectName( "combinedQueryDialog" ); mContentWidget = new QGraphicsWidget(); + mContentWidget->setObjectName( "CombinedQueryContentWidget" ); setContentWidget(mContentWidget); QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); @@ -38,7 +40,7 @@ vLayout->addItem( mListWidget ); mListWidget->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); - + mListWidget->setObjectName( "CombinedQueryListWidget" ); this->setTimeout( NoTimeout ); mContentWidget->setLayout( vLayout ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmdialog.cpp --- a/filemanager/src/filemanager/src/components/fmdialog.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdialog.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -50,6 +50,7 @@ void FmDialog::setPrimaryAction( HbAction *action ) { + action->setObjectName( "primaryAction" ); QList actionList = QGraphicsWidget::actions(); if (actionList.size() == 0) { QGraphicsWidget::addAction(action); @@ -74,9 +75,12 @@ void FmDialog::setSecondaryAction( HbAction *action ) { + action->setObjectName( "secondaryAction" ); QList actionList = QGraphicsWidget::actions(); if (actionList.size() == 0) { - QGraphicsWidget::addAction(new HbAction(hbTrId("Ok"))); + HbAction *primaryAction = new HbAction(hbTrId("txt_common_button_ok")); + primaryAction->setObjectName( "primaryAction" ); + QGraphicsWidget::addAction(primaryAction); QGraphicsWidget::addAction(action); } else if (actionList.size() == 1) { QGraphicsWidget::addAction(action); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmdlgutils.cpp --- a/filemanager/src/filemanager/src/components/fmdlgutils.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdlgutils.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -32,33 +32,29 @@ #include #include - -FmDlgUtils::FmDlgUtils( void ) + +/* + Private Constructor +*/ +FmDlgUtils::FmDlgUtils() { } -FmDlgUtils::~FmDlgUtils( void ) +/*! + Destructor +*/ +FmDlgUtils::~FmDlgUtils() { } -HbAction *FmDlgUtils::executeDialog( FmDialog *dialog, const QString &associatedDrives ) -{ - for( int i = 0; i < associatedDrives.length(); i++ ) { - QString drive( associatedDrives[i] + QString( ":/" ) ); - if( !FmUtils::isDriveAvailable( drive ) ) { - FM_LOG( "executeDialog return 0_ " + associatedDrives ); - return 0; - } - } - - FmDlgCloseUnit dlgCloseUnit( dialog ); - dlgCloseUnit.addAssociatedDrives( associatedDrives ); - FmViewManager::viewManager()->addDlgCloseUnit( &dlgCloseUnit ); - HbAction* action = dialog->exec(); - FmViewManager::viewManager()->removeDlgCloseUnit( &dlgCloseUnit ); - return action; -} - +/*! + Shows single select setting query dialog + \a title used for title text + \a textList used for text list for available settings + \a selectedIndex used for storing selected index + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return true if selection made, otherwise false +*/ bool FmDlgUtils::showSingleSettingQuery( const QString &title, const QStringList &textList, @@ -128,6 +124,15 @@ return ret; } +/*! + Shows multi select setting query dialog + \a title used for title text + \a textList used for text list for available settings + \a selection used for storing selected indexes as bitmask + \a dominantIndex used for dominant index for select all behaviour + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return true if selection made, otherwise false +*/ bool FmDlgUtils::showMultiSettingQuery( const QString &title, const QStringList &textList, @@ -203,6 +208,13 @@ return ret; } +/*! + Shows time setting query dialog + \a title used for title text + \a time used for selected time + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return true if selection made, otherwise false +*/ bool FmDlgUtils::showTimeSettingQuery( const QString &title, QTime &time, const QString &associatedDrives ) { @@ -245,6 +257,16 @@ return ret; } +/*! + Shows text query dialog + \a title used for title text + \a text used for receiving user input text + \a validRegExpStringList used for set valid regExp string list + \a maxLength used for setting max length of input text + Dialog will be closed as canceled while drive in \a associatedDrives is removed + Set \a isReturnFalseWhenNoTextChanged true if need make return value as true while no text changed + return true if text change is made, otherwise false +*/ bool FmDlgUtils::showTextQuery( const QString& title, QString& text, QStringList validRegExpStringList, int maxLength, const QString &associatedDrives, bool isReturnFalseWhenNoTextChanged ) @@ -301,6 +323,14 @@ return ret; } +/*! + Shows single-line password query dialog + \a title used for title text + \a pwd used for receiving user input password + \a maxLength used for setting max length of input password + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return true if password text is inputted, otherwise false +*/ bool FmDlgUtils::showSinglePasswordQuery( const QString &title, QString &pwd, int maxLength, const QString &associatedDrives ) { bool ret( false ); @@ -310,7 +340,9 @@ cQuery->setLineEditMaxLength( maxLength ); } cQuery->setHeadingWidget( new HbLabel( title ) ); - cQuery->setRegExpStringList( QStringList( Regex_ValidUnEmpty ) ); + + // validate that length is not zero. space is acceptable character. + cQuery->setRegExpStringList( QStringList( Regex_ValidUnZeroLength ) ); QString sk1 ( hbTrId("txt_common_button_ok" ) ); QString sk2 ( hbTrId("txt_common_button_cancel" ) ); @@ -338,6 +370,15 @@ return ret; } +/*! + Shows mulit-line password query dialog. If two password is not equal, primary action is dimmed + \a firstLabel used for first line title text + \a secondLabel used for second line title text + \a pwd used for receiving user input password + \a maxLength used for setting max length of input password + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return true if password text is inputted, otherwise false +*/ bool FmDlgUtils::showMultiPasswordQuery( const QString &firstLabel, const QString &secondLabel, QString &pwd, int maxLength, const QString &associatedDrives ) { @@ -381,19 +422,34 @@ return ret; } -bool FmDlgUtils::question( const QString &questionText, const QString &primaryButtonText, - const QString &secondaryButtonText ) +/*! + This is a convenience function for showing a question dialog with \a questionText + Default buttons are Yes and No. +*/ +bool FmDlgUtils::question( const QString &questionText, + HbMessageBox::StandardButtons buttons ) { FmMessageBox msgBox; - return msgBox.question( questionText, primaryButtonText, secondaryButtonText ); + return msgBox.question( questionText, buttons ); } -void FmDlgUtils::information( const QString &informationText ) +/*! + This is a convenience function for showing an information dialog with \a informationText + Default button is OK. +*/ +void FmDlgUtils::information( const QString &informationText, + HbMessageBox::StandardButtons buttons ) { FmMessageBox msgBox; - return msgBox.information( informationText ); + return msgBox.information( informationText, buttons ); } +/*! + Shows query dialog for select backup drive + \a title used for title text + only backup target drives will be shown. + return selected drive, and empty string for cancel. +*/ QString FmDlgUtils::showBackupDriveQuery( const QString& title ) { QString ret; @@ -412,3 +468,28 @@ delete cQuery; return ret; } + +/* + Private function used to popup \a dialog + If want popup dialog in class FmDlgUtils, please call this function. + Dialog will be closed as canceled while drive in \a associatedDrives is removed + return selected action. +*/ +HbAction *FmDlgUtils::executeDialog( FmDialog *dialog, const QString &associatedDrives ) +{ + for( int i = 0; i < associatedDrives.length(); i++ ) { + QString drive( associatedDrives[i] + QString( ":/" ) ); + if( !FmUtils::isDriveAvailable( drive ) ) { + FM_LOG( "executeDialog return 0_ " + associatedDrives ); + return 0; + } + } + + FmDlgCloseUnit dlgCloseUnit( dialog ); + dlgCloseUnit.addAssociatedDrives( associatedDrives ); + + FmViewManager::viewManager()->addDlgCloseUnit( &dlgCloseUnit ); + HbAction* action = dialog->exec(); + FmViewManager::viewManager()->removeDlgCloseUnit( &dlgCloseUnit ); + return action; +} diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmdlgutils.h --- a/filemanager/src/filemanager/src/components/fmdlgutils.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdlgutils.h Thu Aug 05 11:30:07 2010 +0800 @@ -26,38 +26,25 @@ #include #include +#include class FmDialog; class HbAction; +/*! + \class FmDlgUtils + \brief The class FmDlgUtils is static utility class. Used to popup dialogs + */ class FmDlgUtils : public QObject { Q_OBJECT public: - - /** - * Shows single select setting page - * - * @param title Title text - * @param textList Text list for available settings - * @param selectedIndex For storing selected index - * @return true if selection made, otherwise false - */ static bool showSingleSettingQuery( const QString &title, const QStringList &textList, int &selectedIndex, const QString &associatedDrives = QString() ); - /** - * Shows multi select setting page - * - * @param title Title text - * @param textList Text list for available settings - * @param selection For storing selected indexes as bitmask - * @param dominantIndex Dominant index for select all behaviour - * @return true if selection made, otherwise false - */ static bool showMultiSettingQuery( const QString &title, const QStringList &textList, @@ -65,45 +52,33 @@ int dominantIndex, const QString &associatedDrives = QString() ); - /** - * Shows time setting page - * - * @param title Title text id - * @param time Selected time - * @return true if selection made, otherwise false - */ static bool showTimeSettingQuery( const QString &title, QTime &time, - const QString &associatedDrives = QString() ); + const QString &associatedDrives = QString() ); static bool showTextQuery( - const QString &title, QString &text, QStringList validRegExpStringList = QStringList( Regex_ValidUnEmpty ), - int maxLength = -1, const QString &associatedDrives = QString(), bool isReturnFalseWhenNoTextChanged = true ); + const QString &title, QString &text, QStringList validRegExpStringList = QStringList( Regex_ValidUnEmpty ), + int maxLength = -1, const QString &associatedDrives = QString(), bool isReturnFalseWhenNoTextChanged = true ); static bool showSinglePasswordQuery( - const QString &title, QString &pwd, int maxLength = -1, - const QString &associatedDrives = QString() ); + const QString &title, QString &pwd, int maxLength = -1, + const QString &associatedDrives = QString() ); static bool showMultiPasswordQuery( - const QString &firstLabel, const QString &secondLabel, QString &pwd, int maxLength = -1, - const QString &associatedDrives = QString() ); + const QString &firstLabel, const QString &secondLabel, QString &pwd, int maxLength = -1, + const QString &associatedDrives = QString() ); - static bool question( const QString &questionText, const QString &primaryButtonText = QString( hbTrId("Yes") ), - const QString &secondaryButtonText = QString( hbTrId("No") ) ); + static bool question( const QString &questionText, + HbMessageBox::StandardButtons buttons = HbMessageBox::Yes | HbMessageBox::No ); - static void information( const QString &informationText ); - - /** - * Query drive for backup - * - * @param title Title for query dialog - * @return selected drive name. empty for cancel. - */ + static void information( const QString &informationText, + HbMessageBox::StandardButtons buttons = HbMessageBox::Ok ); + static QString showBackupDriveQuery( const QString& title ); - ~FmDlgUtils(void); + ~FmDlgUtils(); private: - FmDlgUtils(void); + FmDlgUtils(); static HbAction *executeDialog( FmDialog *dialog, const QString &associatedDrives ); }; diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmdrivequery.cpp --- a/filemanager/src/filemanager/src/components/fmdrivequery.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdrivequery.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -25,13 +25,16 @@ FmDriveQuery::FmDriveQuery( QGraphicsItem *parent ) : FmDialog( parent ) { + setObjectName( "driveQueryDialog" ); mContentWidget = new QGraphicsWidget(); + mContentWidget->setObjectName( "driveQueryContentWidget" ); setContentWidget(mContentWidget); QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); vLayout->setOrientation( Qt::Vertical ); mListView = new HbListView(); + mListView->setObjectName( "driveQueryListView" ); vLayout->addItem( mListView ); mListView->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmmessagebox.cpp --- a/filemanager/src/filemanager/src/components/fmmessagebox.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmmessagebox.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -19,18 +19,25 @@ #include "fmmessagebox.h" #include -void FmMessageBox::information( const QString &informationText ) +/*! + This is a convenience function for showing an information dialog with \a informationText +*/ +void FmMessageBox::information( const QString &informationText, + HbMessageBox::StandardButtons buttons ) { HbMessageBox::information ( informationText, - this, SLOT(dialogClosed(HbAction*)) ); + this, SLOT(dialogClosed(HbAction*)), buttons ); mEventLoop.exec(); } -bool FmMessageBox::question( const QString &questionText, const QString &primaryButtonText, - const QString &secondaryButtonText ) +/*! + This is a convenience function for showing a question dialog with \a questionText +*/ +bool FmMessageBox::question( const QString &questionText, + HbMessageBox::StandardButtons buttons ) { HbMessageBox::question ( questionText, - this, SLOT(dialogClosed(HbAction*)), primaryButtonText, secondaryButtonText ); + this, SLOT(dialogClosed(HbAction*)), buttons ); mEventLoop.exec(); return mRet; } diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmmessagebox.h --- a/filemanager/src/filemanager/src/components/fmmessagebox.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmmessagebox.h Thu Aug 05 11:30:07 2010 +0800 @@ -33,10 +33,12 @@ ~FmMessageBox() { } - void information( const QString &informationText ); + void information( const QString &informationText, + HbMessageBox::StandardButtons buttons ); - bool question( const QString &questionText, const QString &primaryButtonText, - const QString &secondaryButtonText ); + bool question( const QString &questionText, + HbMessageBox::StandardButtons buttons ); + public slots: void dialogClosed(HbAction *action); private: diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmmultitextquery.cpp --- a/filemanager/src/filemanager/src/components/fmmultitextquery.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmmultitextquery.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -37,29 +37,35 @@ void FmMultiTextQuery::init() { + setObjectName( "MultiTextQuery" ); setDismissPolicy( HbPopup::NoDismiss ); mContentWidget = new HbWidget(); + mContentWidget->setObjectName( "MultiTextContentWidget" ); setContentWidget( mContentWidget ); QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); vLayout->setOrientation( Qt::Vertical ); mFirstLabel = new HbLabel(); + mFirstLabel->setObjectName( "MutiTextFirstLabel" ); mFirstLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); vLayout->addItem( mFirstLabel ); mFirstEdit = new HbLineEdit(); mFirstEdit->setEchoMode( mEchoMode ); mFirstEdit->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); + mFirstEdit->setObjectName("firstLineEdit"); vLayout->addItem( mFirstEdit ); mSecondLabel = new HbLabel(); mSecondLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); + mSecondLabel->setObjectName( "MutiTextSecondLabel" ); vLayout->addItem( mSecondLabel ); mSecondEdit = new HbLineEdit(); mSecondEdit->setEchoMode( mEchoMode ); mSecondEdit->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); + mSecondEdit->setObjectName("secondLineEdit"); vLayout->addItem( mSecondEdit ); mContentWidget->setLayout( vLayout ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmsingletextquery.cpp --- a/filemanager/src/filemanager/src/components/fmsingletextquery.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmsingletextquery.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -37,9 +37,12 @@ void FmSingleTextQuery::init() { + setObjectName( "SingleTextQuery " ); setDismissPolicy( HbPopup::NoDismiss ); mContentWidget = new HbWidget(); - setContentWidget( mContentWidget ); + mContentWidget->setObjectName( "SingleTextContentWidget" ); + setContentWidget( mContentWidget ); + QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); vLayout->setOrientation( Qt::Vertical ); @@ -47,6 +50,7 @@ mTextEdit = new HbLineEdit(); mTextEdit->setEchoMode( mEchoMode ); mTextEdit->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); + mTextEdit->setObjectName( "textLineEdit" ); vLayout->addItem( mTextEdit ); mContentWidget->setLayout( vLayout ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmtimequery.cpp --- a/filemanager/src/filemanager/src/components/fmtimequery.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmtimequery.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -26,15 +26,16 @@ FmTimeQuery::FmTimeQuery( QGraphicsItem *parent ) : FmDialog( parent ) { - + setObjectName( "timeQueryDialog" ); mContentWidget = new QGraphicsWidget(); setContentWidget(mContentWidget); - + mContentWidget->setObjectName( "timeQueryContentWidget" ); QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); vLayout->setOrientation( Qt::Vertical ); mTimeWidget = new HbDateTimeEdit(); - vLayout->addItem(mTimeWidget); + mTimeWidget->setObjectName( "timeQueryTimeWidget" ); + vLayout->addItem( mTimeWidget ); mTimeWidget->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); mTimeWidget->setDisplayFormat( "hh:mm" ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp --- a/filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -61,10 +61,13 @@ void FmViewDetailsDialog::init() { + setObjectName( "viewDetailsDialog" ); mHeaderLabel = new HbLabel( this ); setHeadingWidget( mHeaderLabel ); + mHeaderLabel->setObjectName( "viewDetailsHeaderLabel" ); mListView = new HbListView( this ); + mListView->setObjectName( "viewDetailsListView" ); setContentWidget( mListView ); // init QStardardItemModel as 0 row and 1 column diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/components/fmviewdetailsitem.cpp --- a/filemanager/src/filemanager/src/components/fmviewdetailsitem.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmviewdetailsitem.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -81,11 +81,13 @@ mDetailsContentLabel = new HbLabel(""); mDetailsContentLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); + mDetailsContentLabel->setObjectName( "detaisContentLabel" ); mLayout->addItem( mDetailsContentLabel ); mLayout->setAlignment( mDetailsContentLabel, Qt::AlignLeft ); mDetailsLabel = new HbLabel(""); mDetailsLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) ); + mDetailsLabel->setObjectName( "detailsLabel" ); mLayout->addItem( mDetailsLabel ); mLayout->setAlignment( mDetailsLabel, Qt::AlignLeft ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/fmdriverlistwidget.cpp --- a/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -127,6 +127,7 @@ mContextMenu->clearActions(); } FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); + FmDriverInfo::DriveType driveType = driverInfo.driveType(); FmDriverInfo::DriveState state = driverInfo.driveState(); if( !( state & FmDriverInfo::EDriveNotPresent ) ) { if( state & FmDriverInfo::EDriveAvailable ) { @@ -134,76 +135,76 @@ viewAction->setObjectName( "viewAction" ); viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_memory" ) ); mContextMenu->addAction( viewAction ); - - //state = 0x210; - connect( viewAction, SIGNAL( triggered() ), this, SLOT( on_viewAction_triggered() ), Qt::QueuedConnection ); - } - - if( ( state & FmDriverInfo::EDriveAvailable ) && ( state & FmDriverInfo::EDriveRemovable ) && !( state & FmDriverInfo::EDriveMassStorage ) ){ - // MMC or Usb memory - if ( driverInfo.volumeName().length() ){ - HbAction *renameAction = new HbAction(); - renameAction->setObjectName( "renameAction" ); - renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) ); - mContextMenu->addAction( renameAction ); - - connect( renameAction, SIGNAL( triggered() ), - this, SLOT( on_renameAction_triggered() ), Qt::QueuedConnection ); - } - else{ - HbAction *nameAction = new HbAction(); - nameAction->setObjectName( "nameAction" ); - nameAction->setText( hbTrId( "txt_fmgr_menu_name" ) ); - mContextMenu->addAction( nameAction ); - - connect( nameAction, SIGNAL( triggered() ), - this, SLOT( on_nameAction_triggered() ), Qt::QueuedConnection ); - } - if( !( state & FmDriverInfo::EDriveUsbMemory ) ) { // MMC - if( state & FmDriverInfo::EDrivePasswordProtected ){ - HbAction *changePwdAction = new HbAction(); - changePwdAction->setObjectName( "changePwdAction" ); - changePwdAction->setText( hbTrId( "txt_fmgr_menu_change_password" ) ); - mContextMenu->addAction( changePwdAction ); + + if( driveType == FmDriverInfo::EDriveTypeMemoryCard || driveType == FmDriverInfo::EDriveTypeUsbMemory ) { + // MMC or Usb memory + + // Name/Rename action + if ( driverInfo.volumeName().length() ){ + HbAction *renameAction = new HbAction(); + renameAction->setObjectName( "renameAction" ); + renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) ); + mContextMenu->addAction( renameAction ); + + connect( renameAction, SIGNAL( triggered() ), + this, SLOT( on_renameAction_triggered() ), Qt::QueuedConnection ); + } else { + HbAction *nameAction = new HbAction(); + nameAction->setObjectName( "nameAction" ); + nameAction->setText( hbTrId( "txt_fmgr_menu_name" ) ); + mContextMenu->addAction( nameAction ); - HbAction *removePwdAction = new HbAction(); - removePwdAction->setObjectName( "removePwdAction" ); - removePwdAction->setText( hbTrId( "txt_fmgr_menu_remove_password" ) ); - mContextMenu->addAction( removePwdAction ); - - connect( changePwdAction, SIGNAL( triggered() ), - this, SLOT( on_changePwdAction_triggered() ), Qt::QueuedConnection ); - connect( removePwdAction, SIGNAL( triggered() ), - this, SLOT( on_removePwdAction_triggered() ), Qt::QueuedConnection ); + connect( nameAction, SIGNAL( triggered() ), + this, SLOT( on_nameAction_triggered() ), Qt::QueuedConnection ); } - else{ - HbAction *setPwdAction = new HbAction(); - setPwdAction->setObjectName( "setPwdAction" ); - setPwdAction->setText( hbTrId( "txt_fmgr_menu_set_password" ) ); - mContextMenu->addAction( setPwdAction ); - - connect( setPwdAction, SIGNAL( triggered() ), - this, SLOT( on_setPwdAction_triggered() ), Qt::QueuedConnection ); + + // Set/Change/Remove password action + if( driveType == FmDriverInfo::EDriveTypeMemoryCard ) { // MMC + if( state & FmDriverInfo::EDrivePasswordProtected ){ + HbAction *changePwdAction = new HbAction(); + changePwdAction->setObjectName( "changePwdAction" ); + changePwdAction->setText( hbTrId( "txt_fmgr_menu_change_password" ) ); + mContextMenu->addAction( changePwdAction ); + + HbAction *removePwdAction = new HbAction(); + removePwdAction->setObjectName( "removePwdAction" ); + removePwdAction->setText( hbTrId( "txt_fmgr_menu_remove_password" ) ); + mContextMenu->addAction( removePwdAction ); + + connect( changePwdAction, SIGNAL( triggered() ), + this, SLOT( on_changePwdAction_triggered() ), Qt::QueuedConnection ); + connect( removePwdAction, SIGNAL( triggered() ), + this, SLOT( on_removePwdAction_triggered() ), Qt::QueuedConnection ); + } + else{ + HbAction *setPwdAction = new HbAction(); + setPwdAction->setObjectName( "setPwdAction" ); + setPwdAction->setText( hbTrId( "txt_fmgr_menu_set_password" ) ); + mContextMenu->addAction( setPwdAction ); + + connect( setPwdAction, SIGNAL( triggered() ), + this, SLOT( on_setPwdAction_triggered() ), Qt::QueuedConnection ); + } } + + // Eject action + if( state & FmDriverInfo::EDriveEjectable ){ + HbAction *ejectAction = new HbAction(); + ejectAction->setObjectName( "ejectAction" ); + ejectAction->setText( hbTrId( "txt_fmgr_menu_eject" ) ); + mContextMenu->addAction( ejectAction ); + + connect( ejectAction, SIGNAL( triggered() ), + this, SLOT( on_ejectAction_triggered() ), Qt::QueuedConnection ); + } } } - if( state & FmDriverInfo::EDriveEjectable ){ - HbAction *ejectAction = new HbAction(); - ejectAction->setObjectName( "ejectAction" ); - ejectAction->setText( hbTrId( "txt_fmgr_menu_eject" ) ); - mContextMenu->addAction( ejectAction ); - - connect( ejectAction, SIGNAL( triggered() ), - this, SLOT( on_ejectAction_triggered() ), Qt::QueuedConnection ); - } - - #ifndef _DEBUG_ENABLE_FORMATMENU_ - if ( ( state & FmDriverInfo::EDriveRemovable ) || ( state & FmDriverInfo::EDriveCorrupted ) + // Format action + if ( ( state & FmDriverInfo::EDriveRemovable ) || ( state & FmDriverInfo::EDriveCorrupted ) || ( state & FmDriverInfo::EDriveLocked ) ){ - #endif HbAction *formatAction = new HbAction(); formatAction->setObjectName( "formatAction" ); formatAction->setText( hbTrId( "txt_fmgr_menu_format" ) ); @@ -211,20 +212,23 @@ connect( formatAction, SIGNAL( triggered() ), this, SLOT( on_formatAction_triggered() ), Qt::QueuedConnection ); - #ifndef _DEBUG_ENABLE_FORMATMENU_ - } - #endif - - if( state & FmDriverInfo::EDriveLocked ){ - HbAction *unLockedAction = new HbAction(); - unLockedAction->setObjectName( "unLockedAction" ); - unLockedAction->setText( hbTrId( "Unlock" ) ); - mContextMenu->addAction( unLockedAction ); - - connect( unLockedAction, SIGNAL( triggered() ), - this, SLOT( on_unLockedAction_triggered() ), Qt::QueuedConnection ); } } + + // Unlock action + // put ouside of !EDriveNotPresent judgement so that + // user could unlock drive if connected to PC with mass storage mode + if( state & FmDriverInfo::EDriveLocked ){ + HbAction *unLockedAction = new HbAction(); + unLockedAction->setObjectName( "unLockedAction" ); + unLockedAction->setText( hbTrId( "Unlock" ) ); + mContextMenu->addAction( unLockedAction ); + + connect( unLockedAction, SIGNAL( triggered() ), + this, SLOT( on_unLockedAction_triggered() ), Qt::QueuedConnection ); + } + + // Pop up menu or open drive if( mContextMenu->actions().count() > 0 ) { mContextMenu->setPreferredPos( coords ); mContextMenu->open(); @@ -325,7 +329,7 @@ QString associatedDrives( FmUtils::getDriveLetterFromPath( diskName ) ); while( FmDlgUtils::showSinglePasswordQuery( title, oldPwd, FmMaxLengthofDrivePassword, associatedDrives ) ) { if ( FmUtils::checkDrivePwd( diskName, oldPwd ) == 0 ){ - if( FmDlgUtils::showMultiPasswordQuery( firstLabel, secondLabel, newPwd ) ){ + if( FmDlgUtils::showMultiPasswordQuery( firstLabel, secondLabel, newPwd, FmMaxLengthofDrivePassword, associatedDrives ) ){ if ( FmUtils::setDrivePwd( diskName, oldPwd, newPwd ) == 0 ){ FmDlgUtils::information( hbTrId( "The password has been changed!" ) ); } else { @@ -379,7 +383,7 @@ QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); //Do not add associatedDrives as Locked MMC is not available Drive but only present Drive - while( FmDlgUtils::showSinglePasswordQuery( title, oldPwd ) ) { + while( FmDlgUtils::showSinglePasswordQuery( title, oldPwd, FmMaxLengthofDrivePassword ) ) { int err = FmUtils::unlockDrive( diskName, oldPwd ); if( err == FmErrNone ) { FmDlgUtils::information( hbTrId( "The memory is unlocked!" ) ); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/fmfilebrowsewidget.cpp --- a/filemanager/src/filemanager/src/fmfilebrowsewidget.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/fmfilebrowsewidget.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -303,7 +303,7 @@ QString filePath( mModel->filePath( item->modelIndex() ) ); - QString formatFilePath( FmUtils::formatPath( filePath ) ); + QString formatFilePath( FmUtils::fillPathWithSplash( filePath ) ); QFileInfo fileInfo( filePath ); if( ( fileInfo.isFile() ) || ( fileInfo.isDir() && !( FmUtils::isDefaultFolder( formatFilePath ) ) ) ){ diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/fmviewmanager.cpp --- a/filemanager/src/filemanager/src/fmviewmanager.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/fmviewmanager.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -179,8 +179,13 @@ connect( this, SIGNAL( driveSpaceChanged() ), driverView, SLOT( refreshDrive() ) ); + // use Qt::QueuedConnection becuase synchronous refresh is not work well while + // connected with another OTG device which have more than one external drive in it. + // File server only give driveChanged event once, but two drive is inserted. + // Synchronous refresh will miss another drive. + // So use Qt::QueuedConnection to performance asynchronous refresh. connect( this, SIGNAL( driveChanged() ), - driverView, SLOT( refreshDrive() ) ); + driverView, SLOT( refreshDrive() ), Qt::QueuedConnection ); } void FmViewManager::createFileView( const QString &path, diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -19,114 +19,128 @@ #include "fmoperationbase.h" #include "fmdrivedetailstype.h" #include +/* + * \fn void showNote( const QString ¬e ) + * This signal is emitted when operation needs operation service to show some note. + * \a note indicates the note to show. + */ +/* \fn void notifyWaiting( bool cancelable ) + * This signal is emitted when operation needs operation service to wait. + * \a cancelable indicates whether it could be canceled. + */ + +/* \fn void notifyPreparing( bool cancelable ) + * This signal is emitted when operation needs operation service to prepare. + * \a cancelable indicates whether it could be canceled. + */ + +/* \fn void notifyStart( bool cancelable, int maxSteps ) + * This signal is emitted when operation starts and operation service shows progress bar. + * \a cancelable indicates whether it could be canceled. + * \a maxStep indicates the max of progress bar. + */ + +/* \fn void notifyProgress( int currentStep ) + * This signal is emitted when operation needs operation service update progress bar. + * \a currentStep the current step. + */ + +/* \fn void notifyFinish() + * This signal is emitted when operation finished. + */ + +/* \fn void notifyError( int error, const QString &errString ) + * This signal is used to notify error. + * \a error the error id. + * \a errString the error string. + */ + +/* + Constructs the base operation with + \a parent parent + \a operationType the type of current operation. +*/ FmOperationBase::FmOperationBase( QObject *parent, FmOperationService::TOperationType operationType ) : QObject( parent ), mOperationType( operationType ) { } +/* + Destructs the operation +*/ FmOperationBase::~FmOperationBase() { } +/* + Returns the current operation type +*/ FmOperationService::TOperationType FmOperationBase::operationType() { return mOperationType; } - -//FmOperationFormat -//FmOperationFormat::FmOperationFormat( QObject *parent, QString mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ), -// mDriverName( mDriverName ) -//{ -//} -//FmOperationFormat::~FmOperationFormat() -//{ -//} -// -//QString FmOperationFormat::driverName() -//{ -// return mDriverName; -//} - -//FmOperationDriveDetails -FmOperationDriveDetails::FmOperationDriveDetails( QObject *parent, QString driverName ) : - FmOperationBase( parent, FmOperationService::EOperationTypeDriveDetails ), - mDriverName( driverName ) -{ -} -FmOperationDriveDetails::~FmOperationDriveDetails() -{ - qDeleteAll(mDetailsSizeList); -} - -QString FmOperationDriveDetails::driverName() -{ - return mDriverName; -} - -QList &FmOperationDriveDetails::detailsSizeList() -{ - return mDetailsSizeList; -} - -//FmOperationFolderDetails -FmOperationFolderDetails::FmOperationFolderDetails( QObject *parent, const QString folderPath ) : - FmOperationBase( parent, FmOperationService::EOperationTypeFolderDetails ), - mFolderPath( folderPath ), - mNumofSubFolders( 0 ), - mNumofFiles( 0 ), - mSizeofFolder( 0 ) - -{ -} -FmOperationFolderDetails::~FmOperationFolderDetails() +/* + Starts the operation, called by FmOperationThread. + Use empty implementation because Backup and Restore + are not done within thread, so they will not reimplement + this function. + \sa FmOperationThread::run +*/ +void FmOperationBase::start( volatile bool */*isStopped*/ ) { } -QString FmOperationFolderDetails::folderPath() -{ - return mFolderPath; -} - -int &FmOperationFolderDetails::numofSubFolders() +/* + Does some additional work before starting the operation. + Returns the error number. +*/ +int FmOperationBase::prepare() { - return mNumofSubFolders; -} - -int &FmOperationFolderDetails::numofFiles() -{ - return mNumofFiles; -} - -quint64 &FmOperationFolderDetails::sizeofFolder() -{ - return mSizeofFolder; + return FmErrNone; } - +/* + Constructs a backup operation with + \a parent parent +*/ FmOperationBackup::FmOperationBackup( QObject *parent ) : FmOperationBase( parent, FmOperationService::EOperationTypeBackup ) { } + +/* + Destructs the backup operation +*/ FmOperationBackup::~FmOperationBackup() { } - +/* + Constructs a restore operation with + \a parent parent + \a selection the selected backup items +*/ FmOperationRestore::FmOperationRestore( QObject *parent, quint64 selection ) : FmOperationBase( parent, FmOperationService::EOperationTypeRestore ), mSelection( selection ) { } +/* + Destructs the restore operation +*/ FmOperationRestore::~FmOperationRestore() { } +/* + Returns the backup items +*/ quint64 FmOperationRestore::selection() { return mSelection; diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationbase.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationbase.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationbase.h Thu Aug 05 11:30:07 2010 +0800 @@ -32,52 +32,23 @@ virtual ~FmOperationBase(); FmOperationService::TOperationType operationType(); + virtual int prepare(); + virtual void start( volatile bool *isStopped ); + +signals: + void showNote( const QString ¬e ); + void notifyWaiting( bool cancelable ); + void notifyPreparing( bool cancelable ); + void notifyStart( bool cancelable, int maxSteps ); + void notifyProgress( int currentStep ); + void notifyFinish(); + void notifyError( int error, const QString &errString ); + private: FmOperationService::TOperationType mOperationType; }; -//class FmOperationFormat : public FmOperationBase -//{ -//public: -// explicit FmOperationFormat( QObject *parent, QString mDriverName ); -// virtual ~FmOperationFormat(); -// QString driverName(); -//private: -// QString mDriverName; -//}; - -class FmOperationDriveDetails : public FmOperationBase -{ -public: - explicit FmOperationDriveDetails( QObject *parent, QString driverName ); - - virtual ~FmOperationDriveDetails(); - QString driverName(); - QList &detailsSizeList(); -private: - QString mDriverName; - QList mDetailsSizeList; -}; - -class FmOperationFolderDetails : public FmOperationBase -{ -public: - explicit FmOperationFolderDetails( QObject *parent, const QString folderPath ); - - virtual ~FmOperationFolderDetails(); - QString folderPath(); - int &numofSubFolders(); - int &numofFiles(); - quint64 &sizeofFolder(); - -private: - QString mFolderPath; - int mNumofSubFolders; - int mNumofFiles; - quint64 mSizeofFolder; -}; - class FmOperationBackup : public FmOperationBase { diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationcopy.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationcopy.cpp Fri Jul 23 11:12:24 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,258 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#include "fmoperationcopy.h" -#include "fmcommon.h" -#include "fmoperationbase.h" -#include "fmdrivedetailstype.h" -#include "fmutils.h" - -#include -#include -#include -#include - - -FmOperationCopy::FmOperationCopy( QObject *parent, QStringList sourceList, QString targetPath ) : - FmOperationBase( parent, FmOperationService::EOperationTypeCopy ), - mSourceList( sourceList ), mTargetPath( targetPath ), - mStop( 0 ), mTotalSize( 0 ), mErrString( 0 ), mCopiedSize( 0 ), mTotalSteps( 100 ), mCurrentStep( 0 ) -{ -} - -FmOperationCopy::~FmOperationCopy() -{ -} - -QStringList FmOperationCopy::sourceList() -{ - return mSourceList; -} - -QString FmOperationCopy::targetPath() -{ - return mTargetPath; -} - -int FmOperationCopy::start( volatile bool *isStopped, QString *errString ) -{ - mStop = isStopped; - mErrString = errString; - mTotalSize = 0; - mCopiedSize = 0; - mCurrentStep = 0; - - if( mSourceList.empty() ) { - return FmErrWrongParam; - } - - emit notifyPreparing( true ); - - int numofFolders = 0; - int numofFiles = 0; - - int ret = FmFolderDetails::queryDetailOfContentList( mSourceList, numofFolders, - numofFiles, mTotalSize, mStop, true ); - if( ret != FmErrNone ) { - return ret; - } - - emit notifyStart( true, mTotalSteps ); - - foreach( const QString& source, mSourceList ) { - QFileInfo fi( source ); - if( !fi.exists() ) { - *mErrString = source; - ret = FmErrSrcPathDoNotExist; - return ret; - } - QString newName; - bool isAcceptReplace = false; - QFileInfo destFi( mTargetPath + fi.fileName() ); - - // while for duplicated file/dir - while( destFi.exists() ) { - if( destFi.isFile() && destFi.absoluteFilePath().compare( fi.absoluteFilePath(), Qt::CaseInsensitive ) != 0 ) { - emit askForReplace( destFi.absoluteFilePath(), fi.absoluteFilePath(), &isAcceptReplace ); - if( isAcceptReplace ) { - //delete src file - if( !QFile::remove( destFi.absoluteFilePath() ) ) { - *mErrString = destFi.absoluteFilePath(); - ret = FmErrCannotRemove; - break; - } - destFi.setFile( destFi.absoluteFilePath() ); - } else { - queryForRename( destFi.absoluteFilePath(), &newName ); - if( newName.isEmpty() ) { - ret = FmErrCancel; - break; - } - QString targetName = mTargetPath + newName; - destFi.setFile( targetName ); - } - } else{ - // destination is dir - queryForRename( destFi.absoluteFilePath(), &newName ); - if( newName.isEmpty() ) { - ret = FmErrCancel; - break; - } - QString targetName = mTargetPath + newName; - destFi.setFile( targetName ); - } - } - if( ret != FmErrNone ) { - return ret; - } - ret = copy( source, mTargetPath, newName ); - if( ret != FmErrNone ) { - return ret; - } - } - return FmErrNone; -} - - - -int FmOperationCopy::copy( const QString &source, const QString &targetPath, - const QString &newTargetName ) -{ - if( *mStop ) { - return FmErrCancel; - } - - QFileInfo fi( source ); - if( !fi.exists() ) { - *mErrString = source; - return FmErrSrcPathDoNotExist; - } - QString newName; - if( !newTargetName.isEmpty() ) { - newName = targetPath + newTargetName; - } else { - newName = targetPath + fi.fileName(); - } - - int ret = FmErrNone; - - if (fi.isFile()) { - quint64 fileSize = fi.size(); - if ( !QFile::copy( source, newName )) { - *mErrString = source; - ret = FmErrCannotCopy; - } else { - increaseProgress( fileSize ); - } - } else if (fi.isDir()) { - ret = copyDirInsideContent( source, newName ); - } else { - qWarning( "Things other than file and directory are not copied" ); - ret = FmErrIsNotFileOrFolder; - } - - return ret; -} - - - -int FmOperationCopy::copyDirInsideContent( const QString &srcPath, const QString &destPath ) -{ - QFileInfo srcInfo( srcPath ); - QFileInfo destInfo( destPath ); - - QString destUpPath = FmUtils::fillPathWithSplash( destInfo.absolutePath() ); - if( destUpPath.contains( srcPath, Qt::CaseInsensitive ) ) { - *mErrString = destPath; - return FmErrCopyDestToSubFolderInSrc; - } - - - if( !srcInfo.isDir() || !srcInfo.exists() ) { - *mErrString = srcPath; - return FmErrSrcPathDoNotExist; - } - - if( !destInfo.exists() ) { - if( !destInfo.dir().mkdir( destInfo.absoluteFilePath() ) ) { - *mErrString = destPath; - return FmErrCannotMakeDir; - } - } - - if( !srcInfo.isDir() ) { - *mErrString = destPath; - return FmErrCannotMakeDir; - } - - //start to copy - QFileInfoList infoList = QDir( srcPath ).entryInfoList( QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System ); - while( !infoList.isEmpty() ) { - if( *mStop ) { - return FmErrCancel; - } - - QFileInfo fileInfo = infoList.takeFirst(); - if( fileInfo.isFile() ){ - //copy file - QString newFilePath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); - if (!QFile::copy( fileInfo.absoluteFilePath(), newFilePath ) ) { - *mErrString = fileInfo.absoluteFilePath(); - return FmErrCannotCopy; - } - increaseProgress( fileInfo.size() ); - } else if( fileInfo.isDir() ) { - //makedir - QString newDirPath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); - if( !QDir( newDirPath ).exists() && !QDir( destPath ).mkdir( newDirPath ) ) { - *mErrString = newDirPath; - return FmErrCannotMakeDir; - } - // add dir content to list. - QFileInfoList infoListDir = QDir( fileInfo.absoluteFilePath() ).entryInfoList( - QDir::NoDotAndDotDot | QDir::AllEntries ); - while( !infoListDir.isEmpty() ) { - infoList.push_front( infoListDir.takeLast() ); - } - - } else { - *mErrString = fileInfo.absoluteFilePath(); - return FmErrIsNotFileOrFolder; - } - - } - - return FmErrNone; -} - -void FmOperationCopy::increaseProgress( quint64 size ) -{ - if( mTotalSize <=0 ) { - return; - } - mCopiedSize += size; - int step = ( mCopiedSize * 100 ) / mTotalSize; - if( step > mCurrentStep ) { - mCurrentStep = step; - emit notifyProgress( mCurrentStep ); - } -} - -void FmOperationCopy::queryForRename( const QString &srcFile, QString *destFile ) -{ - emit askForRename( srcFile, destFile ); -} diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationcopy.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationcopy.h Fri Jul 23 11:12:24 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#ifndef FMOPERATIONCOPY_H -#define FMOPERATIONCOPY_H -#include -#include - -#include "fmoperationbase.h" - -class FmOperationCopy : public FmOperationBase -{ -Q_OBJECT -public: - explicit FmOperationCopy( QObject *parent, QStringList sourceList, QString targetPath ); - virtual ~FmOperationCopy(); - int start( volatile bool *isStopped, QString *errString ); - - QStringList sourceList(); - QString targetPath(); - -signals: - void askForRename( const QString &srcFile, QString *destFile ); - void askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); - void showNote( const char *note ); - void notifyPreparing( bool cancelable ); - void notifyStart( bool cancelable, int maxSteps ); - void notifyProgress( int currentStep ); - -private: - int copy( const QString &source, const QString &targetPath, const QString &newTargetName = QString() ); - int copyDirInsideContent( const QString &srcPath, const QString &destPath ); - void increaseProgress( quint64 size ); - void queryForRename( const QString &srcFile, QString *destFile ); - -private: - QStringList mSourceList; - QString mTargetPath; - -private: - volatile bool *mStop; - quint64 mTotalSize; - - QString *mErrString; - - quint64 mCopiedSize; - int mTotalSteps; - int mCurrentStep; -}; -#endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -0,0 +1,426 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "fmoperationcopyormove.h" +#include "fmcommon.h" +#include "fmoperationbase.h" +#include "fmdrivedetailstype.h" +#include "fmutils.h" + +#include +#include +#include +#include + +/* \fn void askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ) + * This signal is emitted when the same file as \a srcFile exists. + * \a destFile the destination file. + * \a isAccepted whether to replace the destination file. + */ + +/* \fn void askForRename( const QString &srcFile, QString *destFile ) + * This signal is emitted when \a srcFile needs to be renamed. + * \a destFile return the new name. + */ + +/* \fn void driveSpaceChanged() + * This signal is emitted when copy or move is completed, and used to update the drive size. + */ + +//the size of one time copy +const int FmOneTimeCopyOrMoveSize = 1024; +//the total steps of progress bar +const int FmTotalProgressBarSteps = 100; +/* + * Constructs a copy or move operation with + * \a operationService parent + * \a type the type of operation(EOperationTypeCopy or EOperationTypeMove) + * \a sourceList the source file or path lists that will be copied + * \a targetPath the target path where the source file will be copied + */ +FmOperationCopyOrMove::FmOperationCopyOrMove( FmOperationService *operationService, FmOperationService::TOperationType type, const QStringList &sourceList, const QString &targetPath ) + : FmOperationBase( operationService, type ), + mOperationService( operationService ), mSourceList( sourceList ), mTargetPath( targetPath ), + mStop( 0 ), mTotalSize( 0 ), mCopiedOrMovedSize( 0 ), mTotalSteps( FmTotalProgressBarSteps ), mCurrentStep( 0 ) +{ + mTargetPath = FmUtils::fillPathWithSplash( mTargetPath ); + connect( this, SIGNAL( askForRename( QString, QString* ) ), + mOperationService, SLOT( on_operation_askForRename( QString, QString* )), Qt::BlockingQueuedConnection ); + connect( this, SIGNAL( askForReplace( QString, QString, bool* ) ), + mOperationService, SLOT( on_operation_askForReplace( QString, QString, bool* )), Qt::BlockingQueuedConnection ); + connect( this, SIGNAL( driveSpaceChanged() ), + mOperationService, SLOT( on_operation_driveSpaceChanged() ) ); +} + +/* + * Destructs the copy or move operation. + */ +FmOperationCopyOrMove::~FmOperationCopyOrMove() +{ +} + +/* + * Returns the source file or path list + */ +QStringList FmOperationCopyOrMove::sourceList() +{ + return mSourceList; +} + +/* + * Returns the target path + */ +QString FmOperationCopyOrMove::targetPath() +{ + return mTargetPath; +} + +/* + * Starts the operation. + * \a isStopped flag the outside stop operation + */ +void FmOperationCopyOrMove::start( volatile bool *isStopped ) +{ + mStop = isStopped; + mTotalSize = 0; + mCopiedOrMovedSize = 0; + mCurrentStep = 0; + + if( mSourceList.empty() ) { + emit notifyError( FmErrWrongParam, mErrString ); + return ; + } + + emit notifyPreparing( true ); + + int numofFolders = 0; + int numofFiles = 0; + + int ret = FmFolderDetails::queryDetailOfContentList( mSourceList, numofFolders, + numofFiles, mTotalSize, mStop, true ); + if( ret != FmErrNone ) { + emit notifyError( ret, mErrString ); + return; + } + + emit notifyStart( true, mTotalSteps ); + + foreach( const QString& source, mSourceList ) { + // formatPath, but do not append splash in the end + // Otherwise could not get fileName in QFileInfo::fileName + QString checkedSource( FmUtils::formatPath( source ) ); + QFileInfo fi( checkedSource ); + if( !fi.exists() ) { + mErrString = checkedSource; + emit notifyError( FmErrSrcPathDoNotExist, mErrString ); + return; + } + QString newName; + bool isAcceptReplace = false; + QFileInfo destFi( mTargetPath + fi.fileName() ); + + // while for duplicated file/dir + while( destFi.exists() ) { + if( destFi.isFile() && destFi.absoluteFilePath().compare( fi.absoluteFilePath(), Qt::CaseInsensitive ) != 0 ) { + emit askForReplace( destFi.absoluteFilePath(), fi.absoluteFilePath(), &isAcceptReplace ); + if( isAcceptReplace ) { + //delete src file + if( !QFile::remove( destFi.absoluteFilePath() ) ) { + mErrString = destFi.absoluteFilePath(); + ret = FmErrCannotRemove; + break; + } + destFi.setFile( destFi.absoluteFilePath() ); + } else { + queryForRename( destFi.absoluteFilePath(), &newName ); + if( newName.isEmpty() ) { + ret = FmErrCancel; + break; + } + QString targetName = mTargetPath + newName; + destFi.setFile( targetName ); + } + } else{ + // destination is dir + queryForRename( destFi.absoluteFilePath(), &newName ); + if( newName.isEmpty() ) { + ret = FmErrCancel; + break; + } + QString targetName = mTargetPath + newName; + destFi.setFile( targetName ); + } + } + if( ret != FmErrNone ) { + emit notifyError( ret, mErrString ); + // refresh drive space no care if cancel, error or finished. + // as filemanger cannot notify drive space changed + // do not refresh path as QFileSystemModel will do auto-refresh + emit driveSpaceChanged(); + return; + } + ret = copyOrMove( checkedSource, mTargetPath, newName ); + if( ret != FmErrNone ) { + emit notifyError( ret, mErrString ); + emit driveSpaceChanged(); + return; + } + } + emit notifyFinish(); + emit driveSpaceChanged(); +} + +/* + * Copy or move the \a source to \a targetPath + * with \a newTargetName + */ +int FmOperationCopyOrMove::copyOrMove( const QString &source, const QString &targetPath, + const QString &newTargetName ) +{ + if( *mStop ) { + return FmErrCancel; + } + + QFileInfo fi( source ); + if( !fi.exists() ) { + mErrString = source; + return FmErrSrcPathDoNotExist; + } + QString newName; + if( !newTargetName.isEmpty() ) { + newName = targetPath + newTargetName; + } else { + newName = targetPath + fi.fileName(); + } + + int ret = FmErrNone; + + if ( fi.isFile() ) { + quint64 fileSize = fi.size(); + ret = copyOneFile( source, newName ); + if (ret != FmErrNone) { + mErrString = source; + return ret; + } + if ( operationType() == FmOperationService::EOperationTypeMove + && !QFile::remove( source ) ) { + mErrString = source; + return FmErrCannotRemove; + } + } else if ( fi.isDir() ) { + if( operationType() == FmOperationService::EOperationTypeMove + && FmUtils::isDefaultFolder( source ) ){ + ret = FmErrRemoveDefaultFolder; + } + else{ + ret = copyOrMoveDirInsideContent( source, newName ); + } + if( ret!= FmErrNone ) { + return ret; + } + if ( operationType() == FmOperationService::EOperationTypeMove + && !fi.dir().rmdir( fi.absoluteFilePath() ) ) { + mErrString = fi.absolutePath(); + return FmErrCannotRemove; + } + } else { + qWarning( "Things other than file and directory are not copied" ); + ret = FmErrIsNotFileOrFolder; + } + + return ret; +} + +/* + copy \a srcPath as \a destPath + both \a srcPath and \a destPath are Directory +*/ +int FmOperationCopyOrMove::copyOrMoveDirInsideContent( const QString &srcPath, const QString &destPath ) +{ + QFileInfo srcInfo( srcPath ); + QFileInfo destInfo( destPath ); + + if( FmUtils::isSubLevelPath( srcPath, destPath ) ) { + mErrString = destPath; + if ( operationType() == FmOperationService::EOperationTypeMove ) { + return FmErrMoveDestToSubFolderInSrc; + } else { + return FmErrCopyDestToSubFolderInSrc; + } + + } + + if( !srcInfo.isDir() || !srcInfo.exists() ) { + mErrString = srcPath; + return FmErrSrcPathDoNotExist; + } + + if( !destInfo.exists() ) { + if( !destInfo.dir().mkdir( destInfo.absoluteFilePath() ) ) { + mErrString = destPath; + return FmErrCannotMakeDir; + } + } + destInfo.setFile( destPath ); + if( !destInfo.isDir() ) { + mErrString = destPath; + return FmErrCannotMakeDir; + } + + //start to copy + QFileInfoList infoList = QDir( srcPath ).entryInfoList( QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System ); + while( !infoList.isEmpty() ) { + if( *mStop ) { + return FmErrCancel; + } + + QFileInfo fileInfo = infoList.takeFirst(); + if( fileInfo.isFile() ){ + //copy file + QString newFilePath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); + int ret = copyOneFile( fileInfo.absoluteFilePath(), newFilePath ); + if ( ret != FmErrNone ) { + mErrString = fileInfo.absoluteFilePath(); + return ret; + } + if( operationType() == FmOperationService::EOperationTypeMove + && !QFile::remove( fileInfo.absoluteFilePath() ) ) { + mErrString = fileInfo.absoluteFilePath(); + return FmErrCannotRemove; + } + } else if( fileInfo.isDir() ) { + //makedir + QString newDirPath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); + if( !QDir( newDirPath ).exists() && !QDir( destPath ).mkdir( newDirPath ) ) { + mErrString = newDirPath; + return FmErrCannotMakeDir; + } + // add dir content to list. + QFileInfoList infoListDir = QDir( fileInfo.absoluteFilePath() ).entryInfoList( + QDir::NoDotAndDotDot | QDir::AllEntries ); + if ( operationType() == FmOperationService::EOperationTypeMove ) { + if( infoListDir.isEmpty() ) { + if ( !fileInfo.dir().rmdir( fileInfo.absoluteFilePath() ) ) { + mErrString = fileInfo.absolutePath(); + return FmErrCannotRemove; + } + } else { + infoList.push_front( fileInfo ); + } + } + while( !infoListDir.isEmpty() ) { + infoList.push_front( infoListDir.takeLast() ); + } + + } else { + mErrString = fileInfo.absoluteFilePath(); + return FmErrIsNotFileOrFolder; + } + + } + + return FmErrNone; +} + +/* + * Increase the progress bar + * \a size the current copy or moved size + */ +void FmOperationCopyOrMove::increaseProgress( quint64 size ) +{ + if( mTotalSize <=0 ) { + return; + } + mCopiedOrMovedSize += size; + int step = ( mCopiedOrMovedSize * FmTotalProgressBarSteps ) / mTotalSize; + if( step > mCurrentStep ) { + mCurrentStep = step; + emit notifyProgress( mCurrentStep ); + } +} + +/* + * Emits askForRename signal. + * \a srcFile the source file path. + * \a destFile get the new name from user input + */ +void FmOperationCopyOrMove::queryForRename( const QString &srcFile, QString *destFile ) +{ + emit askForRename( srcFile, destFile ); +} + +/* + * Copys one file from \a srcFile to \a desFile + */ +int FmOperationCopyOrMove::copyOneFile( const QString &srcFile, const QString &desFile ) +{ + QFile src( srcFile ); + QFile des( desFile ); + if ( !src.open( QIODevice::ReadOnly ) || !des.open( QIODevice::WriteOnly ) ) { + return FmErrCannotCopy; + } + QDataStream outputStream( &src ); + QDataStream inputStream( &des ); + //used to cache data from source file to target file during one copy + QScopedPointer tempString( new char[FmOneTimeCopyOrMoveSize] ); + memset( tempString.data(), 0, FmOneTimeCopyOrMoveSize ); + while ( !outputStream.atEnd() ) { + if ( *mStop ) { + src.close(); + des.close(); + QFile::remove( desFile ); + return FmErrCancel; + } + int ret = outputStream.readRawData(tempString.data(), FmOneTimeCopyOrMoveSize ); + if (ret == -1) { + src.close(); + des.close(); + QFile::remove( desFile ); + return FmErrCannotCopy; + } + ret = inputStream.writeRawData(tempString.data(), ret); + if (ret == -1) { + src.close(); + des.close(); + QFile::remove( desFile ); + return FmErrCannotCopy; + } + memset( tempString.data(), 0, FmOneTimeCopyOrMoveSize ); + increaseProgress( ret ); + } + src.close(); + des.close(); + if ( FmUtils::setFileAttributes( srcFile, desFile ) != FmErrNone ) { + QFile::remove( desFile ); + return FmErrCannotCopy; + } + return FmErrNone; +} + +/* + * Prepare some work before starting operation. + * Returns error number. + */ +int FmOperationCopyOrMove::prepare() +{ + if( mSourceList.empty() ) { + return FmErrWrongParam; + } else { + return FmErrNone; + } +} + diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.h Thu Aug 05 11:30:07 2010 +0800 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef FMOPERATIONCOPYORMOVE_H +#define FMOPERATIONCOPYORMOVE_H + +#include +#include + +#include "fmoperationbase.h" + +class FmOperationCopyOrMove : public FmOperationBase +{ + Q_OBJECT + +public: + explicit FmOperationCopyOrMove( FmOperationService *operationService, FmOperationService::TOperationType type, const QStringList &sourceList, const QString &targetPath ); + virtual ~FmOperationCopyOrMove(); + virtual int prepare(); + virtual void start( volatile bool *isStopped ); + QStringList sourceList(); + QString targetPath(); + +signals: + void askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); + void askForRename( const QString &srcFile, QString *destFile ); + void driveSpaceChanged(); + +private: + int copyOrMove( const QString &source, const QString &targetPath, const QString &newTargetName = QString() ); + int copyOrMoveDirInsideContent( const QString &srcPath, const QString &destPath ); + void increaseProgress( quint64 size ); + void queryForRename( const QString &srcFile, QString *destFile ); + int copyOneFile( const QString &srcFile, const QString &desFile ); + +private: + FmOperationService *mOperationService; + QStringList mSourceList; + QString mTargetPath; + volatile bool *mStop; + QString mErrString; + + quint64 mTotalSize; + quint64 mCopiedOrMovedSize; + int mTotalSteps; + int mCurrentStep; +}; +#endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationformat.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationformat.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationformat.h Thu Aug 05 11:30:07 2010 +0800 @@ -28,16 +28,13 @@ { Q_OBJECT public: - explicit FmOperationFormat( QObject *parent, QString mDriverName ); + explicit FmOperationFormat( QObject *parent, const QString &mDriverName ); virtual ~FmOperationFormat(); - QString driverName(); + QString driverName(); + virtual void start( volatile bool *isStopped ); - int start(); - signals: - void notifyStart( bool cancelable, int maxSteps ); - void notifyProgress( int currentStep ); - void notifyPreparing( bool cancelable ); + void driveSpaceChanged(); private: QString mDriverName; diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -26,20 +26,41 @@ #include #include -FmOperationFormat::FmOperationFormat( QObject *parent, QString mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ), +/* \fn void driveSpaceChanged() + * This signal is emitted when copy or move is completed, and used to update the drive size. + */ + +/* + * Constructs a format operation with \a parent + * \a mDriverName the drive to be formatted. + */ +FmOperationFormat::FmOperationFormat( QObject *parent, const QString &mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ), mDriverName( mDriverName ) { + connect( this, SIGNAL( driveSpaceChanged() ), + parent, SLOT( on_operation_driveSpaceChanged() ) ); } + +/* + * Destructs the operation. + */ FmOperationFormat::~FmOperationFormat() { } +/* + * Returns the to be formatted drive name + */ QString FmOperationFormat::driverName() { return mDriverName; } -int FmOperationFormat::start() +/* + * Starts to format. + * \a isStopped not used + */ +void FmOperationFormat::start( volatile bool */*isStopped*/ ) { QString logString = "FmOperationFormat::start"; FM_LOG( logString ); @@ -47,7 +68,8 @@ emit notifyPreparing( false ); if( mDriverName.isEmpty() ) { - return FmErrWrongParam; + emit notifyError( FmErrWrongParam, QString() ); + return; } RFormat format; @@ -56,7 +78,8 @@ int err = fs.Connect(); if( err != KErrNone ){ - return FmErrTypeFormatFailed; + emit notifyError( FmErrTypeFormatFailed, QString() ); + return; } TInt drive = 0; @@ -177,9 +200,14 @@ } if( err == KErrNone ){ - return FmErrNone; + emit notifyFinish(); } else{ - return FmErrTypeFormatFailed; + emit notifyError( FmErrTypeFormatFailed, QString() ); } + // refresh drive space no care if cancel, error or finished. + // as filemanger cannot notify drive space changed + // do not refresh path as QFileSystemModel will do auto-refresh + emit driveSpaceChanged(); + } diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -22,26 +22,46 @@ #include -FmOperationFormat::FmOperationFormat( QObject *parent, QString mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ), +/* \fn void driveSpaceChanged() + * This signal is emitted when copy or move is completed, and used to update the drive size. + */ + +/* + * Constructs a format operation with \a parent + * \a mDriverName the drive to be formatted. + */ +FmOperationFormat::FmOperationFormat( QObject *parent, const QString &mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ), mDriverName( mDriverName ) { } + +/* + * Destructs the operation. + */ FmOperationFormat::~FmOperationFormat() { } +/* + * Returns the to be formatted drive name + */ QString FmOperationFormat::driverName() { return mDriverName; } -int FmOperationFormat::start() +/* + * Starts to format. + * \a isStopped not used + */ +void FmOperationFormat::start( volatile bool */*isStopped*/ ); { QString logString = "FmOperationFormat::start"; FM_LOG( logString ); if( mDriverName.isEmpty() ) { - return FmErrWrongParam; + emit notifyError( FmErrWrongParam ); + return; } int totalCount( 100 ); emit notifyStart( totalCount, false ); @@ -49,6 +69,7 @@ emit notifyProgress( i ); } - return FmErrNone; + emit notifyFinish(); + emit driveSpaceChanged(); } diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationmove.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationmove.cpp Fri Jul 23 11:12:24 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,277 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#include "fmoperationmove.h" -#include "fmcommon.h" -#include "fmoperationbase.h" -#include "fmdrivedetailstype.h" -#include "fmutils.h" - -#include -#include -#include -#include - -FmOperationMove::FmOperationMove( QObject *parent, QStringList sourceList, QString targetPath ) : - FmOperationBase( parent, FmOperationService::EOperationTypeMove ), - mSourceList( sourceList ), mTargetPath( targetPath ), - mStop( 0 ), mTotalSize( 0 ), mErrString( 0 ), mMovedSize( 0 ), mTotalSteps( 100 ), mCurrentStep( 0 ) -{ -} - -FmOperationMove::~FmOperationMove() -{ -} - -QStringList FmOperationMove::sourceList() -{ - return mSourceList; -} -QString FmOperationMove::targetPath() -{ - return mTargetPath; -} - -int FmOperationMove::start( volatile bool *isStopped, QString *errString ) -{ - mStop = isStopped; - mErrString = errString; - - mTotalSize = 0; - mMovedSize = 0; - mCurrentStep = 0; - - - if( mSourceList.empty() ) { - return FmErrWrongParam; - } - - emit notifyPreparing( true ); - - int numofFolders = 0; - int numofFiles = 0; - - int ret = FmFolderDetails::queryDetailOfContentList( mSourceList, numofFolders, - numofFiles, mTotalSize, mStop, true ); - if( ret != FmErrNone ) { - return ret; - } - - emit notifyStart( true, mTotalSteps ); - foreach( const QString& source, mSourceList ) { - QFileInfo fi( source ); - if( !fi.exists() ) { - *mErrString = source; - ret = FmErrSrcPathDoNotExist; - return ret; - } - QString newName; - bool isAcceptReplace = false; - QFileInfo destFi( mTargetPath + fi.fileName() ); - // while for duplicated file/dir - while( destFi.exists() ) { - if( destFi.isFile() && destFi.absoluteFilePath().compare( fi.absoluteFilePath(), Qt::CaseInsensitive ) != 0 ) { - emit askForReplace( destFi.absoluteFilePath(), fi.absoluteFilePath(), &isAcceptReplace ); - if( isAcceptReplace ) { - //delete src file - if( !QFile::remove( destFi.absoluteFilePath() ) ) { - *mErrString = destFi.absoluteFilePath(); - ret = FmErrCannotRemove; - break; - } - destFi.setFile( destFi.absoluteFilePath() ); - } else { - queryForRename( destFi.absoluteFilePath(), &newName ); - if( newName.isEmpty() ) { - ret = FmErrCancel; - break; - } - QString targetName = mTargetPath + newName; - destFi.setFile( targetName ); - } - } else{ - // destination is dir - queryForRename( destFi.absoluteFilePath(), &newName ); - if( newName.isEmpty() ) { - ret = FmErrCancel; - break; - } - QString targetName = mTargetPath + newName; - destFi.setFile( targetName ); - } - } - if( ret != FmErrNone ) { - return ret; - } - - int ret = move( source, mTargetPath, newName ); - if( ret != FmErrNone ) { - return ret; - } - } - return FmErrNone; -} - -int FmOperationMove::move( const QString &source, const QString &targetPath, const QString &newTargetName ) -{ - if( *mStop ) { - return FmErrCancel; - } - - QFileInfo fi( source ); - if( !fi.exists() ) { - *mErrString = source; - return FmErrSrcPathDoNotExist; - } - QString newName; - if( !newTargetName.isEmpty() ) { - newName = targetPath + newTargetName; - } else { - newName = targetPath + fi.fileName(); - } - - int ret = FmErrNone; - if (fi.isFile()) { - int fileSize = fi.size(); - if ( !QFile::copy( source, newName )) { - *mErrString = source; - ret = FmErrCannotCopy; - } - if( !QFile::remove( source ) ) { - *mErrString = source; - ret = FmErrCannotRemove; - } - increaseProgress( fileSize ); - } else if (fi.isDir()) { - if( FmUtils::isDefaultFolder( source ) ){ - ret = FmErrRemoveDefaultFolder; - } - else{ - ret = moveDirInsideContent( source, newName ); - } - - if( ret!= FmErrNone ) { - return ret; - } - if ( !fi.dir().rmdir( fi.absoluteFilePath() ) ) { - *mErrString = fi.absolutePath(); - return FmErrCannotRemove; - } - } else { - qWarning( "Things other than file and directory are not copied" ); - ret = FmErrIsNotFileOrFolder; - } - - return ret; -} -int FmOperationMove::moveDirInsideContent( const QString &srcPath, const QString &destPath ) -{ - QFileInfo srcInfo( srcPath ); - QFileInfo destInfo( destPath ); - - QString destUpPath = FmUtils::fillPathWithSplash( destInfo.absolutePath() ); - if( destUpPath.contains( srcPath, Qt::CaseInsensitive ) ) { - *mErrString = destPath; - return FmErrMoveDestToSubFolderInSrc; - } - - if( !srcInfo.isDir() || !srcInfo.exists() ) { - *mErrString = srcPath; - return FmErrSrcPathDoNotExist; - } - - if( !destInfo.exists() ) { - if( !destInfo.dir().mkdir( destInfo.absoluteFilePath() ) ) { - *mErrString = destPath; - return FmErrCannotMakeDir; - } - } - if( !srcInfo.isDir() ) { - *mErrString = destPath; - return FmErrCannotMakeDir; - } - - //start to move - QFileInfoList infoList = QDir( srcPath ).entryInfoList( QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System ); - while( !infoList.isEmpty() ) { - if( *mStop ) { - return FmErrCancel; - } - - QFileInfo fileInfo = infoList.takeFirst(); - if( fileInfo.isFile() ){ - //copy file - quint64 fileSize = fileInfo.size(); - QString newFilePath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); - if (!QFile::copy( fileInfo.absoluteFilePath(), newFilePath ) ) { - *mErrString = fileInfo.absoluteFilePath(); - return FmErrCannotCopy; - } - if( !QFile::remove( fileInfo.absoluteFilePath() ) ) { - *mErrString = fileInfo.absoluteFilePath(); - return FmErrCannotRemove; - } - increaseProgress( fileSize ); - } else if( fileInfo.isDir() ) { - //makedir - QString newDirPath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() ); - if( !QDir( newDirPath ).exists() && !QDir( destPath ).mkdir( newDirPath ) ) { - *mErrString = newDirPath; - return FmErrCannotMakeDir; - } - // add dir content to list. - QFileInfoList infoListDir = QDir( fileInfo.absoluteFilePath() ).entryInfoList( - QDir::NoDotAndDotDot | QDir::AllEntries ); - if( infoListDir.isEmpty() ) { - if ( !fileInfo.dir().rmdir( fileInfo.absoluteFilePath() ) ) { - *mErrString = fileInfo.absolutePath(); - return FmErrCannotRemove; - } - } else { - infoList.push_front( fileInfo ); - } - while( !infoListDir.isEmpty() ) { - infoList.push_front( infoListDir.takeLast() ); - } - - } else { - *mErrString = fileInfo.absoluteFilePath(); - return FmErrIsNotFileOrFolder; - } - - } - - return FmErrNone; -} - -void FmOperationMove::increaseProgress( quint64 size ) -{ - if( mTotalSize <=0 ) { - return; - } - mMovedSize += size; - int step = ( mMovedSize * 100 ) / mTotalSize; - if( step > mCurrentStep ) { - mCurrentStep = step; - emit notifyProgress( mCurrentStep ); - } -} - -void FmOperationMove::queryForRename( const QString &srcFile, QString *destFile ) -{ - emit askForRename( srcFile, destFile ); -} diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationmove.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationmove.h Fri Jul 23 11:12:24 2010 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - -#ifndef FMOPERATIONMOVE_H -#define FMOPERATIONMOVE_H -#include -#include - -#include "fmoperationbase.h" - -class FmOperationMove : public FmOperationBase -{ -Q_OBJECT -public: - explicit FmOperationMove( QObject *parent, QStringList sourceList, QString targetPath ); - virtual ~FmOperationMove(); - QStringList sourceList(); - QString targetPath(); - int start( volatile bool *isStopped, QString *errString ); - -signals: - void askForRename( const QString &srcFile, QString *destFile ); - void askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); - void showNote( const QString ¬eString ); - void notifyPreparing( bool cancelable ); - void notifyStart( bool cancelable, int maxSteps ); - void notifyProgress( int currentStep ); - -private: - int move( const QString &source, const QString &targetPath, const QString &newTargetName = QString() ); - int moveDirInsideContent( const QString &srcPath, const QString &destPath ); - void increaseProgress( quint64 size ); - void queryForRename( const QString &srcFile, QString *destFile ); - -private: - QStringList mSourceList; - QString mTargetPath; - -private: - volatile bool *mStop; - quint64 mTotalSize; - QString *mErrString; - - quint64 mMovedSize; - int mTotalSteps; - int mCurrentStep; -}; - -#endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationremove.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationremove.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationremove.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -26,33 +26,54 @@ #include #include -FmOperationRemove::FmOperationRemove( QObject *parent, QStringList pathList ) : - FmOperationBase( parent, FmOperationService::EOperationTypeRemove ), - mPathList( pathList ), mStop( 0 ), mTotalCount( 0 ), - mErrString( 0 ), mRemovedCount( 0 ), mTotalSteps( 100 ), mCurrentStep( 0 ) +/* \fn void driveSpaceChanged() + * This signal is emitted when copy or move is completed, and used to update the drive size. + */ + +/* + * Constructs a remove operation with + * \a parent parent + * \a pathList the file or path to be removed. + */ +FmOperationRemove::FmOperationRemove(QObject *parent, const QStringList &pathList ) : + FmOperationBase( parent, FmOperationService::EOperationTypeRemove ), + mPathList( pathList ), + mStop( 0 ), + mTotalCount( 0 ), mRemovedCount( 0 ), mTotalSteps( 100 ), mCurrentStep( 0 ) { + connect( this, SIGNAL( driveSpaceChanged() ), + parent, SLOT( on_operation_driveSpaceChanged() ) ); } +/* + * Destructs the operation. + */ FmOperationRemove::~FmOperationRemove() { } +/* + * Returns the path list + */ QStringList FmOperationRemove::pathList() { return mPathList; } -int FmOperationRemove::start( volatile bool *isStopped, QString *errString ) +/* + * Starts the operation. + * \a isStopped flag the outside stop operation + */ +void FmOperationRemove::start( volatile bool *isStopped ) { mStop = isStopped; - mErrString = errString; - mTotalCount = 0; mRemovedCount = 0; mCurrentStep = 0; if( mPathList.empty() ) { - return FmErrWrongParam; + emit notifyError( FmErrWrongParam, mErrString ); + return ; } emit notifyPreparing( true ); @@ -64,7 +85,8 @@ int ret = FmFolderDetails::queryDetailOfContentList( mPathList, numofFolders, numofFiles, totalSize, mStop, true ); if( ret != FmErrNone ) { - return ret; + emit notifyError( ret, mErrString ); + return; } mTotalCount = numofFolders + numofFiles; @@ -73,12 +95,21 @@ foreach( const QString& srcPath, mPathList ) { int ret = remove( srcPath ); if( ret != FmErrNone ) { - return ret; + emit notifyError( ret, mErrString ); + // refresh drive space no care if cancel, error or finished. + // as filemanger cannot notify drive space changed + // do not refresh path as QFileSystemModel will do auto-refresh + emit driveSpaceChanged(); + return; } } - return FmErrNone; + emit notifyFinish(); + emit driveSpaceChanged(); } +/* + * Removes the file or dir with name \a fileName + */ int FmOperationRemove::remove( const QString &fileName ) { if( *mStop ) { @@ -89,7 +120,7 @@ QFileInfo fi( fileName ); if (fi.isFile()) { if( !QFile::remove( fileName ) ) { - *mErrString = fileName; + mErrString = fileName; ret = FmErrCannotRemove; } IncreaseProgressOnce(); @@ -109,6 +140,9 @@ return ret; } +/* + * Remove the dir with name \a pathName + */ int FmOperationRemove::recursiveRemoveDir( const QString &pathName ) { QFileInfo fi( pathName ); @@ -123,7 +157,7 @@ if (infoList.size() == 0) { QDir dirToRemove( dirs.pop() ); if ( !dirToRemove.rmdir( dirToRemove.absolutePath() ) ) { - *mErrString = dirToRemove.absolutePath(); + mErrString = dirToRemove.absolutePath(); return FmErrCannotRemove; } IncreaseProgressOnce(); @@ -139,7 +173,7 @@ dirList.push_front( QDir( it->absoluteFilePath() ) ); } else { if ( !QFile::remove( it->absoluteFilePath() ) ) { - *mErrString = it->absoluteFilePath(); + mErrString = it->absoluteFilePath(); return FmErrCannotRemove; } IncreaseProgressOnce(); @@ -153,6 +187,9 @@ return FmErrNone; } +/* + * Increase the progress bar + */ void FmOperationRemove::IncreaseProgressOnce() { if( mTotalCount <= 0 ) diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationremove.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationremove.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationremove.h Thu Aug 05 11:30:07 2010 +0800 @@ -23,21 +23,18 @@ class FmOperationRemove : public FmOperationBase { -Q_OBJECT + Q_OBJECT + public: - explicit FmOperationRemove( QObject *parent, QStringList pathList ); + explicit FmOperationRemove( QObject *parent, const QStringList &pathList ); virtual ~FmOperationRemove(); QStringList pathList(); - int start( volatile bool *isStopped, QString *errString ); - + void start( volatile bool *isStopped ); + signals: - void askForRename( const QString &srcFile, QString &destFile ); - - void notifyPreparing( bool cancelable ); - void notifyStart( bool cancelable, int maxSteps ); - void notifyProgress( int currentStep ); - + void driveSpaceChanged(); + private: int remove( const QString &fileName ); int recursiveRemoveDir( const QString &path ); @@ -46,15 +43,13 @@ private: QStringList mPathList; -private: - volatile bool *mStop; - quint64 mTotalCount; + volatile bool *mStop; + QString mErrString; - QString *mErrString; - - quint64 mRemovedCount; - int mTotalSteps; - int mCurrentStep; + quint64 mTotalCount; + quint64 mRemovedCount; + int mTotalSteps; + int mCurrentStep; }; #endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -18,6 +18,7 @@ #include "fmoperationbase.h" #include "fmoperationservice.h" #include "fmoperationformat.h" +#include "fmoperationviewdetails.h" #include "fmviewdetailsdialog.h" #include "fmdlgutils.h" #include "fmutils.h" @@ -27,15 +28,25 @@ #include #include +/* + * 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 ) { @@ -77,6 +88,10 @@ } } +/* + * 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 ) { @@ -92,12 +107,20 @@ } } +/* + * 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 = hbTrId("Operation"); @@ -123,6 +146,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"); @@ -153,6 +180,10 @@ 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 = hbTrId("Operation"); @@ -183,12 +214,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 ) { @@ -221,9 +260,12 @@ QString driveName( paramFormat->driverName() ); 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 ) && - ( state & FmDriverInfo::EDriveRemovable ) && - !( state & FmDriverInfo::EDriveMassStorage ) ) { + ( 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 @@ -232,7 +274,7 @@ int err = FmUtils::renameDrive( driveName, volumeName ); if ( err == FmErrNone ) { FmDlgUtils::information( hbTrId( "The name has been changed!" ) ); - mOperationService->on_operationThread_driveSpaceChanged(); + mOperationService->on_operation_driveSpaceChanged(); break; } else if( err == FmErrBadName ) { FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) ); @@ -259,12 +301,21 @@ } } -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(); + FmDlgUtils::information( QString( hbTrId("Operation Canceled!") ) ); + return; case FmErrAlreadyStarted: FmDlgUtils::information( QString( hbTrId("Operation already started!")) ); return; @@ -332,21 +383,20 @@ } -void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase ) -{ - Q_UNUSED( operationBase ); - cancelProgress(); - FmDlgUtils::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"); @@ -377,6 +427,11 @@ } +/* + * 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"); @@ -410,6 +465,11 @@ 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"); @@ -445,12 +505,19 @@ 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"); @@ -459,6 +526,9 @@ } } +/* + * Cancels the progress bar. + */ void FmOperationResultProcesser::cancelProgress() { qDebug("cancel progress"); @@ -467,6 +537,9 @@ } } +/* + * Fails and closes the progress bar. + */ void FmOperationResultProcesser::failAndCloseProgress() { qDebug("fail progress"); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.h Thu Aug 05 11:30:07 2010 +0800 @@ -41,8 +41,8 @@ void onNotifyFinish( FmOperationBase* operationBase ); - void onNotifyError( FmOperationBase* operationBase, int error, QString errString ); - void onNotifyCanceled( FmOperationBase* operationBase ); + void onNotifyError( FmOperationBase* operationBase, int error, const QString &errString ); + private slots: void onProgressCancelled(); private: diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -19,17 +19,51 @@ #include "fmoperationservice.h" #include "fmoperationthread.h" #include "fmbackupconfigloader.h" -#include "fmbackuprestorehandler.h" #include "fmbkupengine.h" #include "fmviewdetailsdialog.h" #include "fmoperationresultprocesser.h" -#include "fmoperationcopy.h" -#include "fmoperationmove.h" +#include "fmoperationcopyormove.h" #include "fmoperationremove.h" #include "fmoperationformat.h" - +#include "fmoperationviewdetails.h" +#include "fmbackuprestorehandler.h" #include +/* \fn void driveSpaceChanged( FmOperationBase* operationBase ) + * This signal is emitted when disk size changed. + */ + +/* \fn void notifyWaiting( FmOperationBase* operationBase, bool cancelable ) + * This signal is emitted when the operation emits notifyWaiting. + */ + +/* \fn void notifyPreparing( FmOperationBase* operationBase, bool cancelable ) + * This signal is emitted when the operation emits notifyPreparing. + */ + +/* \fn void notifyStart( FmOperationBase* operationBase, bool cancelable, int maxSteps ) + * This signal is emitted when the operation emits notifyStart. + */ + +/* \fn void notifyProgress( FmOperationBase* operationBase, int currentStep ) + * This signal is emitted when the operation emits notifyProgress. + */ + +/* \fn void notifyFinish( FmOperationBase* operationBase ) + * This signal is emitted when the operation emits notifyFinish. + */ + +/* \fn void notifyError( FmOperationBase* operationBase, int error, QString errString ) + * This signal is emitted when the operation emits notifyError. + */ + +/* \fn void notifyCanceled( FmOperationBase* operationBase ) + * This signal is emitted when the operation emits notifyCanceled. + */ + +/* + * Constructs one operation Service with \a parent. + */ FmOperationService::FmOperationService( QObject *parent ) : QObject( parent ), mCurrentOperation( 0 ) { @@ -43,119 +77,127 @@ QMetaObject::connectSlotsByName( this ); } +/* + * Destructs the operation service. + */ FmOperationService::~FmOperationService() { - delete mThread; - + delete mThread; delete mBackupRestoreHandler; - } +/* + * Returns true if the thread is running, false if not. + */ bool FmOperationService::isRunning() { - if( mCurrentOperation ) { - return true; - } else { - return false; - } - + return mThread->isRunning(); } -int FmOperationService::asyncCopy( QStringList sourceList, QString targetPath ) -{ - if ( isRunning() ) - return FmErrAlreadyStarted; - Q_ASSERT( !mCurrentOperation ); - - if( sourceList.empty() ) { - return FmErrWrongParam; - } - mCurrentOperation = new FmOperationCopy( mThread, sourceList, targetPath ); - - int ret = mThread->asyncCopy( mCurrentOperation ); - if( ret != FmErrNone ) { +/* + * Copys the file or foler \a targetPath asynchronously. + */ +int FmOperationService::asyncCopy( const QStringList &sourceList, const QString &targetPath ) +{ + Q_ASSERT( !mCurrentOperation ); + mCurrentOperation = new FmOperationCopyOrMove( this, FmOperationService::EOperationTypeCopy, sourceList, targetPath ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { resetOperation(); - } - return ret; + return ret; + } + return FmErrNone; } -int FmOperationService::asyncMove( QStringList sourceList, QString targetPath ) +/* + * Moves the file or foler \a sourceList to \a targetPath asynchronously. + */ +int FmOperationService::asyncMove( const QStringList &sourceList, const QString &targetPath ) { - if ( isRunning() ) - return FmErrAlreadyStarted; Q_ASSERT( !mCurrentOperation ); - if( sourceList.empty() ) { - return FmErrWrongParam; - } - mCurrentOperation = new FmOperationMove( mThread, sourceList, targetPath ); - - int ret = mThread->asyncMove( mCurrentOperation ); - if( ret != FmErrNone ) { + mCurrentOperation = new FmOperationCopyOrMove( this, FmOperationService::EOperationTypeMove, sourceList, targetPath ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { resetOperation(); - } - return ret; + return ret; + } + return FmErrNone; } -int FmOperationService::asyncRemove( QStringList pathList ) +/* + * Removes the file or dir \a pathList asynchronously. + */ +int FmOperationService::asyncRemove( const QStringList &pathList ) { - if ( isRunning() ) - return FmErrAlreadyStarted; Q_ASSERT( !mCurrentOperation ); - mCurrentOperation = new FmOperationRemove( mThread, pathList ); - - int ret = mThread->asyncRemove( mCurrentOperation ); - if( ret != FmErrNone ) { + mCurrentOperation = new FmOperationRemove( this, pathList ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { resetOperation(); - } - return ret; + return ret; + } + return FmErrNone; } -int FmOperationService::asyncFormat( QString driverName ) +/* + * Formats the drive \a driverName asynchronously. + */ +int FmOperationService::asyncFormat( const QString &driverName ) { - if ( isRunning() ) - return FmErrAlreadyStarted; Q_ASSERT( !mCurrentOperation ); - mCurrentOperation = new FmOperationFormat( mThread, driverName ); - - int ret = mThread->asyncFormat( mCurrentOperation ); - if( ret != FmErrNone ) { + mCurrentOperation = new FmOperationFormat( this, driverName ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { resetOperation(); - } - return ret; -} -int FmOperationService::asyncViewDriveDetails( const QString driverName ) -{ - if ( isRunning() ) - return FmErrAlreadyStarted; - Q_ASSERT( !mCurrentOperation ); - - mCurrentOperation = new FmOperationDriveDetails( mThread, driverName ); - - int ret = mThread->asyncViewDriveDetails( mCurrentOperation ); - if( ret != FmErrNone ) { - resetOperation(); - } - return ret; + return ret; + } + return FmErrNone; } -int FmOperationService::asyncViewFolderDetails( const QString folderPath ) +/* + * Views drive \a driverName details asynchronously. + */ +int FmOperationService::asyncViewDriveDetails( const QString &driverName ) { - if ( isRunning() ) - return FmErrAlreadyStarted; Q_ASSERT( !mCurrentOperation ); - - mCurrentOperation = new FmOperationFolderDetails( mThread, folderPath ); - - int ret = mThread->asyncViewFolderDetails( mCurrentOperation ); - if( ret != FmErrNone ) { + + mCurrentOperation = new FmOperationDriveDetails( this, driverName ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { resetOperation(); - } - return ret; + return ret; + } + return FmErrNone; } +/* + * Views folder \a folderPath details asynchronously. + */ +int FmOperationService::asyncViewFolderDetails( const QString &folderPath ) +{ + Q_ASSERT( !mCurrentOperation ); + + mCurrentOperation = new FmOperationFolderDetails( this, folderPath ); + connectSignalsAndSlots( mCurrentOperation ); + int ret = mThread->prepareOperationAndStart( mCurrentOperation ); + if ( ret!= FmErrNone ) { + resetOperation(); + return ret; + } + return FmErrNone; +} + +/* + * Backups asynchronously. + */ int FmOperationService::asyncBackup() { if ( isRunning() ) @@ -173,6 +215,10 @@ } } +/* + * Restores asynchronously. + * \a selection selected restore items + */ int FmOperationService::asyncRestore( quint64 selection ) { if ( isRunning() ) @@ -190,11 +236,18 @@ } } +/* + * Delete backup synchronously. + * \a selection selected backup items + */ int FmOperationService::syncDeleteBackup( quint64 selection ) { return mBackupRestoreHandler->deleteBackup( selection ); } +/* + * Cancels current operation. + */ void FmOperationService::cancelOperation() { switch( mCurrentOperation->operationType() ) @@ -225,7 +278,9 @@ } } - +/* + * Set valume synchronously. not used. + */ int FmOperationService::syncSetVolume( const QString &driverName, const QString &volume ) { Q_UNUSED( driverName ); @@ -233,6 +288,9 @@ return FmErrNone; } +/* + * Set drive password synchronously. not used. + */ int FmOperationService::syncSetdDriverPassword( const QString &driverName, const QString &oldPassword, const QString &newPassword ) @@ -243,6 +301,9 @@ return FmErrNone; } +/* + * Rename synchronously. not used. + */ int FmOperationService::syncRename( const QString &oldPath, const QString &newName ) { Q_UNUSED( oldPath ); @@ -250,13 +311,17 @@ return FmErrNone; } +/* + * Launches the file in synchronous way. + */ int FmOperationService::syncLaunchFileOpen( const QString &filePath ) { return FmUtils::launchFile( filePath ); } - - +/* + * Returns the backup handler. + */ FmBackupRestoreHandler *FmOperationService::backupRestoreHandler() { if( !mBackupRestoreHandler ) { @@ -266,6 +331,9 @@ return mBackupRestoreHandler; } +/* + * Deletes the operation and set it to be 0. + */ void FmOperationService::resetOperation() { if( mCurrentOperation ) { @@ -274,113 +342,201 @@ } } -///////////////////////////////////////////////////// -///Thread -void FmOperationService::on_operationThread_askForRename( const QString &srcFile, QString *destFile ) +/* + * Connects \a operation's sinals to slots + */ +void FmOperationService::connectSignalsAndSlots( FmOperationBase *operation ) +{ + + connect( operation, SIGNAL( showNote( QString ) ), + this, SLOT( on_operation_showNote( QString )), Qt::BlockingQueuedConnection ); + connect( operation, SIGNAL( notifyError( int, QString ) ), + this, SLOT( on_operation_notifyError( int, QString ) ) ); + connect( operation, SIGNAL( notifyStart( bool, int ) ), + this, SLOT( on_operation_notifyStart( bool, int ) ) ); + connect( operation, SIGNAL( notifyProgress( int ) ), + this, SLOT( on_operation_notifyProgress( int ) ) ); + connect( operation, SIGNAL( notifyFinish() ), + this, SLOT( on_operation_notifyFinish()) ); + connect( operation, SIGNAL( notifyWaiting( bool ) ), + this, SLOT( on_operation_notifyWaiting( bool )) ); + +} + +/* + * Responds to mCurrentOperation's askForRename signal. + * \a srcFile the source file. + * \a destFile the new file name. + */ +void FmOperationService::on_operation_askForRename( const QString &srcFile, QString *destFile ) { mOperationResultProcesser->onAskForRename( mCurrentOperation, srcFile, destFile ); } -void FmOperationService::on_operationThread_askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ) +/* + * Responds to mCurrentOperation's askForReplace signal. + * \a srcFile the source file. + * \a destFile the target file. + * \a isAccepted whether to replace the target file. + */ +void FmOperationService::on_operation_askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ) { mOperationResultProcesser->onAskForReplace( mCurrentOperation, srcFile, destFile, isAccepted ); } -void FmOperationService::on_operationThread_driveSpaceChanged() -{ - emit driveSpaceChanged( mCurrentOperation ); -} -void FmOperationService::on_operationThread_showNote( const char *noteString ) +/* + * Responds to mCurrentOperation's showNote signal. + * \a noteString the note content. + */ +void FmOperationService::on_operation_showNote( const char *noteString ) { mOperationResultProcesser->onShowNote( mCurrentOperation, noteString ); } -void FmOperationService::on_operationThread_notifyWaiting( bool cancelable ) + +/* + * Responds to mCurrentOperation's showNote signal. + * \a noteString the note content. + */ +void FmOperationService::on_operation_notifyWaiting( bool cancelable ) { mOperationResultProcesser->onNotifyWaiting( mCurrentOperation, cancelable ); emit notifyWaiting( mCurrentOperation, cancelable ); } -void FmOperationService::on_operationThread_notifyPreparing( bool cancelable ) + +/* + * Responds to mCurrentOperation's notifyPreparing signal. + * \a cancelable indicates whether the progress bar could be cancelled. + */ +void FmOperationService::on_operation_notifyPreparing( bool cancelable ) { mOperationResultProcesser->onNotifyPreparing( mCurrentOperation, cancelable ); emit notifyPreparing( mCurrentOperation, cancelable ); } -void FmOperationService::on_operationThread_notifyStart( bool cancelable, int maxSteps ) + +/* + * Responds to mCurrentOperation's notifyPreparing signal. + * \a cancelable indicates whether the progress bar could be cancelled. + * \maxSteps the length of progress bar. + */ +void FmOperationService::on_operation_notifyStart( bool cancelable, int maxSteps ) { mOperationResultProcesser->onNotifyStart( mCurrentOperation, cancelable, maxSteps ); emit notifyStart( mCurrentOperation, cancelable, maxSteps ); } -void FmOperationService::on_operationThread_notifyProgress( int currentStep ) + +/* + * Responds to mCurrentOperation's notifyPreparing signal. + * \a currentStep indicates the current length of progress bar. + */ +void FmOperationService::on_operation_notifyProgress( int currentStep ) { mOperationResultProcesser->onNotifyProgress( mCurrentOperation, currentStep ); emit notifyProgress( mCurrentOperation, currentStep ); } -void FmOperationService::on_operationThread_notifyFinish() + +/* + * Responds to mCurrentOperation's notifyFinish signal, indicate the + * progress is over. + */ +void FmOperationService::on_operation_notifyFinish() { mOperationResultProcesser->onNotifyFinish( mCurrentOperation ); emit notifyFinish( mCurrentOperation ); resetOperation(); } -void FmOperationService::on_operationThread_notifyError(int error, QString errString ) + +/* + * Responds to mCurrentOperation's notifyError signal. + * \a error error id. + * \a errString the error string. + */ +void FmOperationService::on_operation_notifyError(int error, QString errString ) { mOperationResultProcesser->onNotifyError( mCurrentOperation, error, errString ); emit notifyError( mCurrentOperation, error, errString ); resetOperation(); } -void FmOperationService::on_operationThread_notifyCanceled() + +/* + * Responds to mCurrentOperation's driveSpaceChanged + */ +void FmOperationService::on_operation_driveSpaceChanged() { - mOperationResultProcesser->onNotifyCanceled( - mCurrentOperation ); - emit notifyCanceled( mCurrentOperation ); - resetOperation(); + emit driveSpaceChanged( mCurrentOperation ); } -/// -///////////////////////////////////////////////////// -///////////////////////////////////////////////////// -///BackupRestore +/* + * Responds to mBackupRestoreHandler's notifyPreparing + * \a cancelable indicates whether it could be cancelled. + */ void FmOperationService::on_backupRestore_notifyPreparing( bool cancelable ) { mOperationResultProcesser->onNotifyPreparing( mCurrentOperation, cancelable ); emit notifyPreparing( mCurrentOperation, cancelable ); } + +/* + * Responds to mBackupRestoreHandler's notifyStart + * \a cancelable indicates whether it could be cancelled. + * \a maxSteps the lenth of progress bar. + */ void FmOperationService::on_backupRestore_notifyStart( bool cancelable, int maxSteps ) { mOperationResultProcesser->onNotifyStart( mCurrentOperation, cancelable, maxSteps ); emit notifyStart( mCurrentOperation, cancelable, maxSteps ); } + +/* + * Responds to mBackupRestoreHandler's notifyProgress + * \a currentStep the current progress bar's step. + */ void FmOperationService::on_backupRestore_notifyProgress( int currentStep ) { mOperationResultProcesser->onNotifyProgress( mCurrentOperation, currentStep ); emit notifyProgress( mCurrentOperation, currentStep ); } + +/* + * Responds to mBackupRestoreHandler's notifyFinish + */ void FmOperationService::on_backupRestore_notifyFinish() { mOperationResultProcesser->onNotifyFinish( mCurrentOperation ); emit notifyFinish( mCurrentOperation ); resetOperation(); } -void FmOperationService::on_backupRestore_notifyError(int error, QString errString ) + +/* + * Responds to mBackupRestoreHandler's notifyError + * \a error the error id. + * \a errString the error string. + */ +void FmOperationService::on_backupRestore_notifyError(int error, const QString &errString ) { mOperationResultProcesser->onNotifyError( mCurrentOperation, error, errString ); emit notifyError( mCurrentOperation, error, errString ); resetOperation(); } + +/* + * Responds to mBackupRestoreHandler's notifyCanceled + */ void FmOperationService::on_backupRestore_notifyCanceled() { - mOperationResultProcesser->onNotifyCanceled( - mCurrentOperation ); - emit notifyCanceled( mCurrentOperation ); + mOperationResultProcesser->onNotifyError( + mCurrentOperation, FmErrCancel, QString() ); + emit notifyError( mCurrentOperation, FmErrCancel, QString() ); resetOperation(); } diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationservice.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationservice.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationservice.h Thu Aug 05 11:30:07 2010 +0800 @@ -57,17 +57,17 @@ //return error if any path exist. //renturn error if list count is not as the same the other. - int asyncCopy( QStringList sourceList, QString targetPath ); + int asyncCopy( const QStringList &sourceList, const QString &targetPath ); - int asyncMove( QStringList sourceList, QString targetPath ); + int asyncMove( const QStringList &sourceList, const QString &targetPath ); - int asyncRemove( QStringList pathList ); + int asyncRemove( const QStringList &pathList ); //return error if can not be format. //notify error while format error. - int asyncFormat( QString driverName ); - int asyncViewDriveDetails( const QString driverName ); - int asyncViewFolderDetails( const QString folderPath ); + int asyncFormat( const QString &driverName ); + int asyncViewDriveDetails( const QString &driverName ); + int asyncViewFolderDetails( const QString &folderPath ); int asyncBackup(); int asyncRestore( quint64 selection ); @@ -89,23 +89,21 @@ void on_backupRestore_notifyStart( bool cancelable, int maxSteps ); void on_backupRestore_notifyProgress( int currentStep ); void on_backupRestore_notifyFinish(); - void on_backupRestore_notifyError(int error, QString errString ); + void on_backupRestore_notifyError(int error, const QString &errString ); void on_backupRestore_notifyCanceled(); - - void on_operationThread_askForRename( const QString &srcFile, QString *destFile ); - void on_operationThread_askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); - void on_operationThread_driveSpaceChanged(); - void on_operationThread_showNote( const char *noteString ); - void on_operationThread_notifyWaiting( bool cancelable ); - void on_operationThread_notifyPreparing( bool cancelable ); - void on_operationThread_notifyStart( bool cancelable, int maxSteps ); - void on_operationThread_notifyProgress( int currentStep ); - void on_operationThread_notifyFinish(); - void on_operationThread_notifyError(int error, QString errString ); - void on_operationThread_notifyCanceled(); + void on_operation_askForRename( const QString &srcFile, QString *destFile ); + void on_operation_askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); + void on_operation_showNote( const char *noteString ); + void on_operation_notifyWaiting( bool cancelable ); + void on_operation_notifyPreparing( bool cancelable ); + void on_operation_notifyStart( bool cancelable, int maxSteps ); + void on_operation_notifyProgress( int currentStep ); + void on_operation_notifyFinish(); + void on_operation_notifyError(int error, QString errString ); + void on_operation_driveSpaceChanged(); signals: -// void askForRename( FmOperationBase* operationBase, const QString &srcFile, QString &destFile ); + void driveSpaceChanged( FmOperationBase* operationBase ); void notifyWaiting( FmOperationBase* operationBase, bool cancelable ); @@ -119,6 +117,7 @@ private: void resetOperation(); + void connectSignalsAndSlots( FmOperationBase *operation ); private: FmOperationThread *mThread; diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationthread.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationthread.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationthread.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -17,287 +17,59 @@ */ #include "fmoperationthread.h" -#include "fmoperationbase.h" -#include "fmdrivedetailstype.h" -#include "fmcommon.h" -#include "fmoperationcopy.h" -#include "fmoperationmove.h" -#include "fmoperationremove.h" -#include "fmoperationformat.h" +#include "fmbackuprestorehandler.h" #include #include -FmOperationThread::FmOperationThread( QObject *parent ) : QThread( parent ), mOperationBase( 0 ) +/* + * Constructs the operation thread with \a parent. + */ +FmOperationThread::FmOperationThread( QObject *parent ) : QThread( parent ), + mStop( false), mOperationBase( 0 ) { - - + setPriority( LowestPriority ); } +/* + * Destructs the operation thread. + */ FmOperationThread::~FmOperationThread() { } -int FmOperationThread::asyncCopy( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; +/* + * Prepare some conditions before starts the operation. + * Returns the error id. + * \a operationBase the operation to be prepared. + */ +int FmOperationThread::prepareOperationAndStart( FmOperationBase* operationBase ) +{ + if ( isRunning() ) { + return FmErrAlreadyStarted; } - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - connect( mOperationBase, SIGNAL( askForRename( QString, QString* ) ), - this, SLOT( onAskForRename( QString, QString* )), Qt::BlockingQueuedConnection ); - connect( mOperationBase, SIGNAL( askForReplace( QString, QString, bool* ) ), - this, SLOT( onAskForReplace( QString, QString, bool* )), Qt::BlockingQueuedConnection ); - connect( mOperationBase, SIGNAL( showNote( QString ) ), - this, SLOT( onShowNote( QString )), Qt::BlockingQueuedConnection ); - - start(); - return FmErrNone; -} - -int FmOperationThread::asyncMove( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; - } - - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - connect( mOperationBase, SIGNAL( askForRename( QString, QString* ) ), - this, SLOT( onAskForRename( QString, QString* )), Qt::BlockingQueuedConnection ); - connect( mOperationBase, SIGNAL( askForReplace( QString, QString, bool* ) ), - this, SLOT( onAskForReplace( QString, QString, bool* )), Qt::BlockingQueuedConnection ); - connect( mOperationBase, SIGNAL( showNote( QString ) ), - this, SLOT( onShowNote( QString )), Qt::BlockingQueuedConnection ); - - - start(); - return FmErrNone; + int ret = mOperationBase->prepare(); + if ( ret == FmErrNone ) { + mStop = false; + start(); + } + return ret; } -int FmOperationThread::asyncRemove( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; - } - - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - - start(); - return FmErrNone; -} - -int FmOperationThread::asyncFormat( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; - } - - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - - start(); - return FmErrNone; -} -int FmOperationThread::asyncViewDriveDetails( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; - } - - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - - start(); - return FmErrNone; -} - -int FmOperationThread::asyncViewFolderDetails( FmOperationBase* operationBase ) -{ - if( isRunning() ){ - return FmErrAlreadyStarted; - } - - mOperationBase = operationBase; - mOperationBase->setObjectName( "operationElement" ); - QMetaObject::connectSlotsByName( this ); - - start(); - return FmErrNone; -} - - +/* Stops the current thread. + * Caused by user interaction. + */ void FmOperationThread::stop() { mStop = true; } -void FmOperationThread::onAskForRename( const QString &srcFile, QString *destFile ) -{ - emit askForRename( srcFile, destFile ); -} -void FmOperationThread::onAskForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ) -{ - emit askForReplace( srcFile, destFile, isAccepted ); -} - -void FmOperationThread::onShowNote( const char *noteString ) -{ - emit showNote( noteString ); -} - -void FmOperationThread::on_operationElement_notifyPreparing( bool cancelable ) -{ - emit notifyPreparing( cancelable ); -} -void FmOperationThread::on_operationElement_notifyStart( bool cancelable, int maxSteps ) -{ - emit notifyStart( cancelable, maxSteps ); -} -void FmOperationThread::on_operationElement_notifyProgress( int currentStep ) -{ - emit notifyProgress( currentStep ); +/* + * reimp + */ +void FmOperationThread::run() +{ + mOperationBase->start( &mStop ); } -void FmOperationThread::run() -{ - mStop = false; - this->setPriority( LowestPriority ); - switch( mOperationBase->operationType() ) - { - case FmOperationService::EOperationTypeCopy: - { - mErrString.clear(); - FmOperationCopy *operationCopy = static_cast(mOperationBase); - - int ret = operationCopy->start( &mStop, &mErrString ); - switch( ret ) - { - case FmErrCancel: - emit notifyCanceled(); - break; - case FmErrNone: - emit notifyFinish(); - break; - default: - emit notifyError( ret, mErrString ); - break; - } - // refresh drive space no care if cancel, error or finished. - // as filemanger cannot notify drive space changed - // do not refresh path as QFileSystemModel will do auto-refresh - emit driveSpaceChanged(); - break; - } - case FmOperationService::EOperationTypeMove: - { - mErrString.clear(); - FmOperationMove *operationMove = static_cast(mOperationBase); - - int ret = operationMove->start( &mStop, &mErrString ); - switch( ret ) - { - case FmErrCancel: - emit notifyCanceled(); - break; - case FmErrNone: - emit notifyFinish(); - break; - default: - emit notifyError( ret, mErrString ); - } - // refresh drive space no care if cancel, error or finished. - // as filemanger cannot notify drive space changed - // do not refresh path as QFileSystemModel will do auto-refresh - emit driveSpaceChanged(); - break; - } - case FmOperationService::EOperationTypeRemove: - { - mErrString.clear(); - FmOperationRemove *operationRemove = static_cast(mOperationBase); - - int ret = operationRemove->start( &mStop, &mErrString ); - switch( ret ) - { - case FmErrCancel: - emit notifyCanceled(); - break; - case FmErrNone: - emit notifyFinish(); - break; - default: - emit notifyError( ret, mErrString ); - } - // refresh drive space no care if cancel, error or finished. - // as filemanger cannot notify drive space changed - // do not refresh path as QFileSystemModel will do auto-refresh - emit driveSpaceChanged(); - break; - } - case FmOperationService::EOperationTypeFormat: - { -// emit notifyWaiting( false ); - FM_LOG(QString("start format")); - FmOperationFormat *operationFormat = static_cast( mOperationBase ); - FM_LOG(QString("get param and start format")); - - if ( FmErrNone != operationFormat->start() ) { - emit notifyError( FmErrTypeFormatFailed, operationFormat->driverName() ); - return; - } - FM_LOG(QString("format done")); - emit notifyFinish(); - // refresh drive space no care if cancel, error or finished. - // as filemanger cannot notify drive space changed - // do not refresh path as QFileSystemModel will do auto-refresh - emit driveSpaceChanged(); - FM_LOG(QString("format done and emit finish")); - break; - } - case FmOperationService::EOperationTypeDriveDetails: - { - emit notifyWaiting( true ); - - FmOperationDriveDetails *operationDriverDetails = static_cast( mOperationBase ); - int ret = FmDriveDetailsContent::querySizeofContent( - operationDriverDetails->driverName(), operationDriverDetails->detailsSizeList(), &mStop ); - if( ret == FmErrNone ) { - emit notifyFinish(); - } else if( ret == FmErrCancel ) { - emit notifyCanceled(); - } - - break; - } - case FmOperationService::EOperationTypeFolderDetails: - { - emit notifyWaiting( true ); - - FmOperationFolderDetails *operationFolderDetails = static_cast( mOperationBase ); - int ret = FmFolderDetails::getNumofSubfolders( operationFolderDetails->folderPath(), operationFolderDetails->numofSubFolders(), - operationFolderDetails->numofFiles(), operationFolderDetails->sizeofFolder(), - &mStop ); - if( ret == FmErrNone ) { - emit notifyFinish(); - } else if( ret == FmErrCancel ) { - emit notifyCanceled(); - } - - break; - - } - default: - Q_ASSERT( false ); - - } -} - diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationthread.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationthread.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationthread.h Thu Aug 05 11:30:07 2010 +0800 @@ -19,7 +19,7 @@ #ifndef FMOPERATIONTHREAD_H #define FMOPERATIONTHREAD_H -#include "fmoperationservice.h" +#include "fmoperationbase.h" #include "fmcommon.h" #include @@ -27,51 +27,14 @@ #include -class FmDriveDetailsSize; -class FmOperationBase; - -class FmOperationCopy; -class FmOperationMove; -class FmOperationRemove; - class FmOperationThread : public QThread { Q_OBJECT public: FmOperationThread( QObject *parent ); ~FmOperationThread(); - - int asyncCopy( FmOperationBase* operationBase ); - int asyncMove( FmOperationBase *operationBase ); - int asyncRemove( FmOperationBase *operationBase ); - - int asyncFormat( FmOperationBase *operationBase ); - int asyncViewDriveDetails( FmOperationBase *operationBase ); - int asyncViewFolderDetails( FmOperationBase *operationBase ); - void stop(); - -signals: - void askForRename( const QString &srcFile, QString *destFile ); - void askForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); - void driveSpaceChanged(); - - void showNote(const char*); - void notifyWaiting( bool cancelable ); - void notifyPreparing( bool cancelable ); // this step could not be used if not needed. - void notifyStart( bool cancelable, int maxSteps ); - void notifyProgress( int currentStep ); - - void notifyFinish(); - void notifyError(int error, QString errString ); - void notifyCanceled(); - -private slots: - void onAskForRename( const QString &srcFile, QString *destFile ); - void onAskForReplace( const QString &srcFile, const QString &destFile, bool *isAccepted ); - void onShowNote( const char *noteString ); - void on_operationElement_notifyPreparing( bool cancelable ); - void on_operationElement_notifyStart( bool cancelable, int maxSteps ); - void on_operationElement_notifyProgress( int currentStep ); + int prepareOperationAndStart( FmOperationBase* operationBase ); + void stop(); protected: void run(); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationviewdetails.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationviewdetails.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -0,0 +1,143 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The source file of the operation param of file manager +* +*/ + +#include "fmoperationviewdetails.h" +#include "fmdrivedetailstype.h" +#include + +/* + * Constructs one view drive details operation with + * \a parent parent. + * \a driverName the drive name. + */ +FmOperationDriveDetails::FmOperationDriveDetails( QObject *parent, const QString &driverName ) : + FmOperationBase( parent, FmOperationService::EOperationTypeDriveDetails ), + mDriverName( driverName ), mStop( 0 ) +{ +} + +/* + * Destructs the operation. + */ +FmOperationDriveDetails::~FmOperationDriveDetails() +{ + qDeleteAll(mDetailsSizeList); +} + +/* + * Returns the drive name. + */ +QString FmOperationDriveDetails::driverName() +{ + return mDriverName; +} + +/* + * reimp. + */ +void FmOperationDriveDetails::start( volatile bool *isStopped ) +{ + mStop = isStopped; + emit notifyWaiting( true ); + //FmOperationDriveDetails *operationDriverDetails = static_cast( mOperationBase ); + int ret = FmDriveDetailsContent::querySizeofContent( driverName(), detailsSizeList(), mStop ); + if( ret == FmErrNone ) { + emit notifyFinish(); + } else { + emit notifyError( ret, QString() ); + } +} + +/* + * Returns detail items size list. + */ +QList &FmOperationDriveDetails::detailsSizeList() +{ + return mDetailsSizeList; +} + +/* + * Constructs one view folder details operation with + * \a parent parent. + * \a driverName the drive name. + */ +FmOperationFolderDetails::FmOperationFolderDetails( QObject *parent, const QString &folderPath ) : + FmOperationBase( parent, FmOperationService::EOperationTypeFolderDetails ), + mFolderPath( folderPath ), + mNumofSubFolders( 0 ), + mNumofFiles( 0 ), + mSizeofFolder( 0 ) + +{ +} + +/* + * Destructs the operation. + */ +FmOperationFolderDetails::~FmOperationFolderDetails() +{ + +} + +/* + * Returns the folder path. + */ +QString FmOperationFolderDetails::folderPath() +{ + return mFolderPath; +} + +/* + * Returns the number of sub folders. + */ +int &FmOperationFolderDetails::numofSubFolders() +{ + return mNumofSubFolders; +} + +/* + * Returns the number of files + */ +int &FmOperationFolderDetails::numofFiles() +{ + return mNumofFiles; +} + +/* + * Returns the size of folder. + */ +quint64 &FmOperationFolderDetails::sizeofFolder() +{ + return mSizeofFolder; +} + +/* + * Reimp. + */ +void FmOperationFolderDetails::start( volatile bool *isStopped ) +{ + mStop = isStopped; + emit notifyWaiting( true ); + int ret = FmFolderDetails::getNumofSubfolders( folderPath(), numofSubFolders(), + numofFiles(), sizeofFolder(), mStop ); + if( ret == FmErrNone ) { + emit notifyFinish(); + } else { + emit notifyError( ret, QString() ); + } +} diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/filemanager/src/operationservice/fmoperationviewdetails.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationviewdetails.h Thu Aug 05 11:30:07 2010 +0800 @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* The header file of the operation param of file manager +* +*/ + +#ifndef FMOPERATIONVIEWDETAILS_H +#define FMOPERATIONVIEWDETAILS_H + +#include "fmoperationservice.h" +#include "fmoperationbase.h" + +#include +#include + +class FmOperationDriveDetails : public FmOperationBase +{ +public: + explicit FmOperationDriveDetails( QObject *parent, const QString &driverName ); + + virtual ~FmOperationDriveDetails(); + QString driverName(); + virtual void start( volatile bool *isStopped ); + QList &detailsSizeList(); + +private: + QString mDriverName; + QList mDetailsSizeList; + volatile bool *mStop; +}; + +class FmOperationFolderDetails : public FmOperationBase +{ +public: + explicit FmOperationFolderDetails( QObject *parent, const QString &folderPath ); + + virtual ~FmOperationFolderDetails(); + virtual void start( volatile bool *isStopped ); + + QString folderPath(); + int &numofSubFolders(); + int &numofFiles(); + quint64 &sizeofFolder(); + +private: + QString mFolderPath; + int mNumofSubFolders; + int mNumofFiles; + quint64 mSizeofFolder; + volatile bool *mStop; +}; +#endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/fmbkupengine/inc/CMMCScBkupOperationParameters.h --- a/filemanager/src/fmbkupengine/inc/CMMCScBkupOperationParameters.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/fmbkupengine/inc/CMMCScBkupOperationParameters.h Thu Aug 05 11:30:07 2010 +0800 @@ -39,7 +39,7 @@ _LIT( KBackUpFolder, "\\Backup\\" ); _LIT( KBackUpFiles, "*.arc" ); - +const TInt KCArrayGranularity = 10; class TBkupDrivesAndOperation { @@ -86,9 +86,9 @@ } void ConstructL() { - mUids = new ( ELeave ) CArrayFixFlat( 10 ); - mExclude_uids = new ( ELeave ) CArrayFixFlat( 10 ); - mArchive_name = HBufC::NewL(1); + mUids = new ( ELeave ) CArrayFixFlat( KCArrayGranularity ); + mExclude_uids = new ( ELeave ) CArrayFixFlat( KCArrayGranularity ); + mArchive_name = 0; } ~CBkupCategory() @@ -105,8 +105,11 @@ void setArchive_name( TDesC16& archive_name ) { - delete mArchive_name; - mArchive_name = HBufC::NewL( archive_name.Length() ); + if ( mArchive_name != 0 ) + { + delete mArchive_name; + } + TRAP_IGNORE( mArchive_name = HBufC::NewL( archive_name.Length() ) ); *mArchive_name = archive_name; } @@ -122,12 +125,12 @@ void addUids( unsigned int uid ) { - mUids->AppendL( uid, sizeof(unsigned int)); + TRAP_IGNORE( mUids->AppendL( uid, sizeof(unsigned int) ) ); } void addExclude_uids( unsigned int exclude_uid ) { - mExclude_uids->AppendL( exclude_uid, sizeof(unsigned int) ); + TRAP_IGNORE( mExclude_uids->AppendL( exclude_uid, sizeof(unsigned int) ) ); } unsigned int category() { return mCategory; } diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/fmbkupengine/src/CMMCScBkupStateArchiveOpPublicDataFiles.cpp --- a/filemanager/src/fmbkupengine/src/CMMCScBkupStateArchiveOpPublicDataFiles.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/fmbkupengine/src/CMMCScBkupStateArchiveOpPublicDataFiles.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -373,8 +373,7 @@ // progress info. See CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() // for the point when the public data size is zeroed. - // First, find the associated data owner. - CMMCScBkupDataOwnerInfo& owner = dataOwners.OwnerL( fileInfo.SecureId() ); + __LOG3("CMMCScBkupStateArchiveOpPublicDataFiles::AddIndexRecordL() - offset: %6d, length: %6d, file: %S", info.Offset(), info.Length(), &fileInfo.FileName()); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/fmbkupengine/src/CMMCScBkupStateValidateDiskSpace.cpp --- a/filemanager/src/fmbkupengine/src/CMMCScBkupStateValidateDiskSpace.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/fmbkupengine/src/CMMCScBkupStateValidateDiskSpace.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -188,18 +188,18 @@ // Calculate the total progress required for the entire backup operation uncompressedSize = dataOwners.TotalOperationalSizeL(); __LOG1("CMMCScBkupStateValidateDiskSpace::ValidateFreeSpaceBeforeBackupL() - Total estimated uncompressed size for archive %Ld", uncompressedSize); - const TInt ownerCount = dataOwners.Count(); + //const TInt ownerCount = dataOwners.Count(); - for( TInt i=0; iAppendL( drvAndOp ); } //////// - - FmBackupSettings& bkupSettings( *( q->BackupSettingsL() ) ); // Create restore params - ownership is transferred to // secure backup engine @@ -634,6 +632,7 @@ CMMCScBkupOpParamsRestoreFull::NewL( driveReader, EBUCatAllInOne ); CleanupStack::PopAndDestroy(); // driveReader + FmBackupSettings& bkupSettings( *( q->BackupSettingsL() ) ); // Get list of all archives RPointerArray< CMMCScBkupArchiveInfo > archives; TCleanupItem cleanupItem( ResetAndDestroyArchives, &archives ); @@ -670,8 +669,7 @@ QList< FmRestoreInfo > &restoreInfoList, const QString& aDrive ) { - int targetDrive = DriverNameToNumber( aDrive ); - FmBackupSettings& settings( *( q->BackupSettingsL() ) ); + int targetDrive = DriverNameToNumber( aDrive ); restoreInfoList.clear(); diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/commoninc.pri --- a/filemanager/src/inc/commoninc.pri Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/commoninc.pri Thu Aug 05 11:30:07 2010 +0800 @@ -16,6 +16,7 @@ INTERNAL_HEADERS += $$PWD/fmcommon.h \ $$PWD/fmlogger.h \ - $$PWD/fmdefine.h \ + $$PWD/fmdefine.h -HEADERS += $$INTERNAL_HEADERS \ No newline at end of file +HEADERS += $$INTERNAL_HEADERS + diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/fmdefine.h --- a/filemanager/src/inc/fmdefine.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/fmdefine.h Thu Aug 05 11:30:07 2010 +0800 @@ -71,6 +71,8 @@ #define FmMaxLengthofDriveName 11 #define FmMaxLengthofDrivePassword 8 +// used to match un-zeroLength string, empty character such as space is acceptable +#define Regex_ValidUnZeroLength QString( "^.+$" ) // used to match un-empty string, and is not totally empty characters. #define Regex_ValidUnEmpty QString( "^.*[^\\s].*$" ) diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/fmfileiconprovider.cpp --- a/filemanager/src/inc/fmfileiconprovider.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/fmfileiconprovider.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -76,40 +76,30 @@ { case FmFileTypeRecognizer::FileTypeDrive: { - FmDriverInfo::DriveState driveState = FmUtils::queryDriverInfo( filePath ).driveState(); - if( driveState & FmDriverInfo::EDriveAvailable ){ - if( driveState & FmDriverInfo::EDriveRemovable ) { - if( driveState & FmDriverInfo::EDriveMassStorage ) { - // Mass Storage - retIcon = HbIcon( massMemoryIcon ).qicon(); - break; - } else if( driveState & FmDriverInfo::EDriveUsbMemory ) { - // Usb Memory - retIcon = HbIcon( usbMemoryIcon ).qicon(); - break; - } else{ - //Memory Card + FmDriverInfo driveInfo = FmUtils::queryDriverInfo( filePath ); + switch ( driveInfo.driveType() ) + { + case FmDriverInfo::EDriveTypeMassStorage: + retIcon = HbIcon( massMemoryIcon ).qicon(); + break; + case FmDriverInfo::EDriveTypeUsbMemory: + retIcon = HbIcon( usbMemoryIcon ).qicon(); + break; + case FmDriverInfo::EDriveTypeMemoryCard: + if( !( driveInfo.driveState() & FmDriverInfo::EDriveNotPresent ) ) { retIcon = HbIcon( mmcIcon ).qicon(); - break; + } else { + retIcon = HbIcon( mmcNoneIcon ).qicon(); } - } else{ - //Phone Memory + break; + case FmDriverInfo::EDriveTypePhoneMemory: retIcon = HbIcon( phoneMemoryIcon ).qicon(); break; + default: + Q_ASSERT_X( false, "FmFileIconProvider::icon", "please handle drive type"); + break; } - } else if( driveState & FmDriverInfo::EDriveLocked ) { - retIcon = HbIcon( mmcLockedIcon ).qicon(); - break; - } else if( driveState & FmDriverInfo::EDriveCorrupted ) { - retIcon = HbIcon( mmcNoneIcon ).qicon(); - break; - } else if( driveState & FmDriverInfo::EDriveNotPresent ){ - retIcon = HbIcon( mmcNoneIcon ).qicon(); - break; - } else { - retIcon = HbIcon( mmcNoneIcon ).qicon(); - break; - } + break; } case FmFileTypeRecognizer::FileTypeFolder: { diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/fmutils.h --- a/filemanager/src/inc/fmutils.h Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/fmutils.h Thu Aug 05 11:30:07 2010 +0800 @@ -26,6 +26,10 @@ class FmDriverInfo { public: + /*! + Used to get drive status for convenience. + /sa DriveType is used to get drive type. + */ enum driveState { EDriveNotPresent = 0x1, // true when Drive have not inserted, for example, MMC Card @@ -46,7 +50,23 @@ EDriveMassStorage = 0x8000, EDriveRam = 0x10000, EDriveUsbMemory = 0x20000, + EDriveRemote = 0x40000, }; + + /*! + Used to get drive type for convenience. + */ + enum DriveType + { + EDriveTypeRom, + EDriveTypeRam, + EDriveTypePhoneMemory, + EDriveTypeMassStorage, + EDriveTypeMemoryCard, + EDriveTypeUsbMemory, + EDriveTypeRemote, + }; + Q_DECLARE_FLAGS( DriveState, driveState ) FmDriverInfo( quint64 s, quint64 f, const QString &n, const QString &vN, const quint32 driveState ) : @@ -71,6 +91,7 @@ QString name() const { return mName; } QString volumeName() const { return mVolumeName; } DriveState driveState() const { return mDriveState; } + FmDriverInfo::DriveType driveType(); private: quint64 mSize; @@ -78,6 +99,7 @@ QString mName; QString mVolumeName; DriveState mDriveState; + DriveType mDriveType; }; Q_DECLARE_OPERATORS_FOR_FLAGS( FmDriverInfo::DriveState ) @@ -142,6 +164,9 @@ */ static QString getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ); + static bool isSubLevelPath( const QString &src, const QString &dest ); + + static int setFileAttributes( const QString &srcFile, const QString &desFile ); }; #endif diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/fmutils_s60.cpp --- a/filemanager/src/inc/fmutils_s60.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/fmutils_s60.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -36,7 +36,8 @@ #include #include #include - +#include +#include #include #include @@ -46,6 +47,34 @@ #define BURCONFIGFILE "z:/private/2002BCC0/burconfig.xml" + +/*! + Used to get drive type for convenience. +*/ +FmDriverInfo::DriveType FmDriverInfo::driveType() +{ + FmDriverInfo::DriveType driveType; + if( mDriveState & FmDriverInfo::EDriveRemovable ) { + if( mDriveState & FmDriverInfo::EDriveMassStorage ) { + driveType = FmDriverInfo::EDriveTypeMassStorage; + } else if( mDriveState & FmDriverInfo::EDriveUsbMemory ) { + driveType = FmDriverInfo::EDriveTypeUsbMemory; + } else if( mDriveState & FmDriverInfo::EDriveRemote ){ + driveType = FmDriverInfo::EDriveTypeRemote; + } else { + driveType = FmDriverInfo::EDriveTypeMemoryCard; + } + } else if( mDriveState & FmDriverInfo::EDriveRom ) { + driveType = FmDriverInfo::EDriveTypeRom; + } else if( mDriveState & FmDriverInfo::EDriveRam ) { + driveType = FmDriverInfo::EDriveTypeRam; + } else { + driveType = FmDriverInfo::EDriveTypePhoneMemory; + } + + return driveType; +} + QString FmUtils::getDriveNameFromPath( const QString &path ) { // fillPathWithSplash make sure path length will be at least 3 if it is not empty. @@ -112,7 +141,12 @@ { state |= FmDriverInfo::EDriveUsbMemory; } - + + if ( drvStatus & DriveInfo::EDriveRemote ) + { + state |= FmDriverInfo::EDriveRemote; + } + if ( drvStatus & DriveInfo::EDriveRom ){ state |= FmDriverInfo::EDriveRom; } @@ -214,7 +248,7 @@ int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd ) { - if( driverName.isEmpty() ) { + if( driverName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } QString logString = "Drive name:" + driverName; @@ -227,7 +261,7 @@ TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; HBufC* password16 = XQConversions::qStringToS60Desc( Pwd ); TMediaPassword password; @@ -242,6 +276,8 @@ logString = "Clear password error:" + QString::number( err ); FM_LOG( logString ); + delete password16; + if( err == KErrNone ){ return FmErrNone; } @@ -255,7 +291,7 @@ int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd ) { - if( driverName.isEmpty() ) { + if( driverName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } QString logString = "Drive name:" + driverName; @@ -281,6 +317,8 @@ logString = "Unlock drive error:" + QString::number( err ); FM_LOG( logString ); + delete password16; + if( err == KErrNone ){ return FmErrNone; } @@ -300,7 +338,7 @@ int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd ) { - if( driverName.isEmpty() ) { + if( driverName.isEmpty() || pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } QString logString = "checkDrivePwd Drive name:" + driverName; @@ -312,7 +350,8 @@ int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd) { - if( driverName.isEmpty() ) { + if( driverName.isEmpty() || + oldPwd.length() > FmMaxLengthofDrivePassword || newPwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } QString logString = "setDrivePwd Drive name:" + driverName ; @@ -345,6 +384,8 @@ logString = "Password set error:" + QString::number( err ); FM_LOG( logString ); + delete newPassword16; + delete oldPassword16; if( err == KErrNone ){ return FmErrNone; } @@ -358,10 +399,10 @@ void FmUtils::emptyPwd( QString &pwd ) { - TPtr des ( ( XQConversions::qStringToS60Desc( pwd ) )->Des() ); - des.FillZ( des.MaxLength() ); - des.Zero(); - pwd = XQConversions::s60DescToQString( des ); + TBuf< FmMaxLengthofDrivePassword > nullPwd; + nullPwd.FillZ( nullPwd.MaxLength() ); + nullPwd.Zero(); + pwd = XQConversions::s60DescToQString( nullPwd ); } int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName) @@ -456,7 +497,7 @@ RFs fs; err = fs.Connect(); - QString string( formatPath( folderPath ) ); + QString string( fillPathWithSplash( folderPath ) ); TPtrC desFolderPath( XQConversions::qStringToS60Desc( string )->Des() ); TPtrC ptrExtension( XQConversions::qStringToS60Desc( extension )->Des() ); @@ -601,6 +642,11 @@ CleanupStack::PopAndDestroy( array ); } +/*! + fill splash in the end of \a filePath if the path is not a file + All "/" and "\" will be changed to QDir::separator + \sa formatPath only changed "/" and "\" to QDir::separator +*/ QString FmUtils::fillPathWithSplash( const QString &filePath ) { QString newFilePath; @@ -608,18 +654,11 @@ return newFilePath; } - foreach( QChar ch, filePath ) { - if( ch == QChar('\\') || ch == QChar('/') ) { - newFilePath.append( QDir::separator() ); - } else { - newFilePath.append( ch ); - } - } + newFilePath = formatPath( filePath ); if( newFilePath.right( 1 )!= QDir::separator() ){ newFilePath.append( QDir::separator() ); } - return newFilePath; } @@ -753,6 +792,10 @@ return; } +/*! + fill volume name for \a driveName, with drive letter at the front, for example, C: Phone memory + if \a isFillWithDefaultVolume is true, default volume is provided for non-volume drive. +*/ QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) { QString ret; @@ -765,36 +808,73 @@ FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); QString volumeName = driverInfo.volumeName(); - + if( volumeName.isEmpty() && isFillWithDefaultVolume ){ - FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState(); - if( driveState & FmDriverInfo::EDriveAvailable ){ - if( driveState & FmDriverInfo::EDriveRemovable ) { - if( driveState & FmDriverInfo::EDriveMassStorage ) { - // Mass Storage - ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName ); - } else if( driveState & FmDriverInfo::EDriveUsbMemory ) { - // USB Memory - ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName ); - } else{ - // Memory Card - ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName ); - } - } else{ - // phone memory + switch ( driverInfo.driveType() ) + { + case FmDriverInfo::EDriveTypeMassStorage: + ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName ); + break; + case FmDriverInfo::EDriveTypeUsbMemory: + ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName ); + break; + case FmDriverInfo::EDriveTypeMemoryCard: + ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName ); + break; + case FmDriverInfo::EDriveTypePhoneMemory: ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName ); - } - } + break; + default: + Q_ASSERT_X( false, "FmUtils::fillDriveVolume", "please handle drive type"); + break; + } } if( ret.isEmpty() ) { - // set ret as volumeName + // ret is not got. fill ret as default method // txt_fmgr_dblist_1_2 is not correct, can not use. ret = hbTrId( "%1 %2" ).arg( checkedDriveName ).arg( volumeName ); } return ret; } + +/*! + return volume name for \a driveName. without drive letter at the front. + \a defaultName is set true if default volume name is return for volume name +*/ +QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ) +{ + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); + + QString volumeName = driverInfo.volumeName(); + //save the volume status, whether it is default name + defaultName = false; + //volume name may be null if not set, it will be set at least for one time in the following while cycling. + if ( volumeName.isEmpty() ) { + defaultName = true; + switch ( driverInfo.driveType() ) + { + case FmDriverInfo::EDriveTypeMassStorage: + volumeName = hbTrId("Mass storage"); + break; + case FmDriverInfo::EDriveTypeUsbMemory: + volumeName = hbTrId("USB memory"); + break; + case FmDriverInfo::EDriveTypeMemoryCard: + volumeName = hbTrId("Memory card"); + break; + case FmDriverInfo::EDriveTypePhoneMemory: + volumeName = hbTrId("Device memory"); + break; + default: + Q_ASSERT_X( false, "FmUtils::getVolumeNameWithDefaultNameIfNull", "please handle drive type" ); + break; + } + } + return volumeName; +} + int FmUtils::launchFile( const QString &filePath ) { QFile file( filePath ); @@ -879,7 +959,7 @@ QString FmUtils::Localize( const QString &path ) { - QString locPath = formatPath( path ); + QString locPath = fillPathWithSplash( path ); TPtrC desPath( XQConversions::qStringToS60Desc( locPath )->Des() ); CDirectoryLocalizer *localizer = CDirectoryLocalizer::NewL(); @@ -892,9 +972,17 @@ return QString(); } +/*! + All "/" and "\" in \a path will be changed to QDir::separator + \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end if path is no a file +*/ QString FmUtils::formatPath( const QString &path ) { QString formatPath; + if( path.isEmpty() ) { + return formatPath; + } + foreach( QChar ch, path ) { if( ch == QChar('\\') || ch == QChar('/') ) { formatPath.append( QDir::separator() ); @@ -903,9 +991,6 @@ } } - if( formatPath.right( 1 ) != QDir::separator() ){ - formatPath.append( QDir::separator() ); - } return formatPath; } @@ -968,29 +1053,61 @@ return ret; } -QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ) +/*! + Check if \a dest is sub level path of \a src + Used to check True/False when copy a folder to itself or its subfolder + For example, c:\data\test is sub path of c:\data. + But c:\data123\test is not sub path of c:\data. + So after got right part of path, the first char must be \ or / +*/ +bool FmUtils::isSubLevelPath( const QString &src, const QString &dest ) { - FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); - - QString volumeName = driverInfo.volumeName(); - //save the volume status, whether it is default name - defaultName = false; - //volume name may be null if not set, it will be set at least for one time in the following while cycling. - if ( ( volumeName.isEmpty() ) && - ( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) ) { - defaultName = true; - if ( driverInfo.driveState() & FmDriverInfo::EDriveRemovable ) { - if ( driverInfo.driveState() & FmDriverInfo::EDriveUsbMemory ) { - volumeName = hbTrId("USB memory"); - } else if ( driverInfo.driveState() & FmDriverInfo::EDriveMassStorage ) { - volumeName = hbTrId("Mass storage"); - } - else { - volumeName = hbTrId("Memory card"); - } - } else { - volumeName = hbTrId("Device memory"); - } + FM_LOG("FmUtils::isSubFolder: src=" + src + " dest=" + dest); + QString checkedSrc( FmUtils::fillPathWithSplash( src ) ); + QString checkedDest( FmUtils::fillPathWithSplash( dest ) ); + + if( checkedDest.contains( checkedSrc, Qt::CaseInsensitive) && + checkedDest.length() > checkedSrc.length() ) { + // for example c:\data\ vs c:\data\123\ + FM_LOG("FmUtils::isSubFolder: true"); + return true; } - return volumeName; + // for example c:\data\ vs c:\data\ + // for example c:\data\ vs c:\data123\ + + FM_LOG("FmUtils::isSubFolder: false"); + return false; } + +/*! + set the \a desFile attributes as the same with \a srcFile +*/ +int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile ) +{ + RFs fsSession; + User::LeaveIfError( fsSession.Connect() ); + CleanupClosePushL( fsSession ); + RFile64 src; + RFile64 des; + HBufC *buf1 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( srcFile ) ) ); + HBufC *buf2 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( desFile ) ) ); + User::LeaveIfError( src.Open( fsSession, *buf1, EFileRead | EFileShareReadersOnly ) ); + User::LeaveIfError( des.Open( fsSession, *buf2, EFileWrite | EFileShareExclusive ) ); + TTime mod; + int err = src.Modified( mod );; + if ( err == FmErrNone ) { + err = des.SetModified( mod ); + } + TUint att( 0 ); + if ( err == FmErrNone ) { + err = src.Att( att ); + } + if ( err == FmErrNone ) { + des.SetAtt( att, ( ~att ) & KEntryAttMaskSupported ); + } + src.Close(); + des.Close(); + fsSession.Close(); + CleanupStack::PopAndDestroy(); // fsSession + return err; +} diff -r 39cf9ced4cc4 -r 328cf6fbe40c filemanager/src/inc/fmutils_win.cpp --- a/filemanager/src/inc/fmutils_win.cpp Fri Jul 23 11:12:24 2010 +0800 +++ b/filemanager/src/inc/fmutils_win.cpp Thu Aug 05 11:30:07 2010 +0800 @@ -222,25 +222,23 @@ Q_UNUSED( driverName ); } +/*! + fill splash in the end of \a filePath if the path is not a file + All "/" and "\" will be changed to QDir::separator + \sa formatPath only changed "/" and "\" to QDir::separator +*/ QString FmUtils::fillPathWithSplash( const QString &filePath ) { - QString newFilePath; + QString newFilePath; if( filePath.isEmpty() ) { return newFilePath; } - foreach( QChar ch, filePath ) { - if( ch == QChar('\\') || ch == QChar('/') ) { - newFilePath.append( QDir::separator() ); - } else { - newFilePath.append( ch ); - } - } + newFilePath = formatPath( filePath ); if( newFilePath.right( 1 )!= QDir::separator() ){ newFilePath.append( QDir::separator() ); } - return newFilePath; } @@ -437,20 +435,25 @@ return false; } +/*! + All "/" and "\" in \a path will be changed to QDir::separator + \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end if path is no a file +*/ QString FmUtils::formatPath( const QString &path ) { QString formatPath; - foreach( QChar ch, path ) { - if( ch == QChar('\\') || ch == QChar('/') ) { - formatPath.append( QDir::separator() ); - } else { - formatPath.append( ch ); - } + if( path.isEmpty() ) { + return formatPath; + } + + foreach( QChar ch, path ) { + if( ch == QChar('\\') || ch == QChar('/') ) { + formatPath.append( QDir::separator() ); + } else { + formatPath.append( ch ); + } } - if( formatPath.right( 1 ) != QDir::separator() ){ - formatPath.append( QDir::separator() ); - } return formatPath; } @@ -522,3 +525,33 @@ return driverInfo.volumeName(); } +/*! + Check if \a dest is sub level path of \a src + Used to check True/False when copy a folder to itself or its subfolder + For example, c:\data\test is sub path of c:\data. + But c:\data123\test is not sub path of c:\data. + So after got right part of path, the first char must be \ or / +*/ +bool FmUtils::isSubLevelPath( const QString &src, const QString &dest ) +{ + FM_LOG("FmUtils::isSubFolder: src=" + src + " dest=" + dest); + QString checkedSrc( FmUtils::fillPathWithSplash( src ) ); + QString checkedDest( FmUtils::fillPathWithSplash( dest ) ); + + if( checkedDest.contains( checkedSrc, Qt::CaseInsensitive) && + checkedDest.length() > checkedSrc.length() ) { + // for example c:\data\ vs c:\data\123\ + FM_LOG("FmUtils::isSubFolder: true"); + return true; + } + // for example c:\data\ vs c:\data\ + // for example c:\data\ vs c:\data123\ + + FM_LOG("FmUtils::isSubFolder: false"); + return false; +} + +int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile ) +{ + return FmErrNone; +}