# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1283447817 -10800 # Node ID fc4654ce4fcb1f20dcf7f19f7acf8aefe1894ab0 # Parent 060d0b1ab8451a6b0e1529244e5523a8a10c41b1 Revision: 201033 Kit: 201035 diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/filemanager.pri --- a/filemanager/src/filemanager/filemanager.pri Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/filemanager.pri Thu Sep 02 20:16:57 2010 +0300 @@ -19,8 +19,7 @@ INCLUDEPATH += ./src/backuprestore INCLUDEPATH += ./src/operationservice -HEADERS += src/fmdriverlistwidget.h \ - src/listviewitems.h \ +HEADERS += src/fmdriverlistwidget.h \ src/fmfileview.h \ src/fmfilebrowsewidget.h \ src/fmdriverview.h \ @@ -62,8 +61,7 @@ src/components/fmdrivequery.h SOURCES += src/main.cpp \ - src/fmdriverlistwidget.cpp \ - src/listviewitems.cpp \ + src/fmdriverlistwidget.cpp \ src/fmfileview.cpp \ src/fmfilebrowsewidget.cpp \ src/fmdriverview.cpp \ diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/filemanager.pro --- a/filemanager/src/filemanager/filemanager.pro Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/filemanager.pro Thu Sep 02 20:16:57 2010 +0300 @@ -41,8 +41,8 @@ -lshareui \ -lefsrv \ -lapgrfx \ - -lcone \ - -ldirectorylocalizer + -lcone \ + -lsysutil TARGET.UID3 = 0x2002BCC0 TARGET.EPOCHEAPSIZE = 0x020000 0x1000000 diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/filemanager.qrc --- a/filemanager/src/filemanager/filemanager.qrc Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/filemanager.qrc Thu Sep 02 20:16:57 2010 +0300 @@ -6,6 +6,8 @@ image/qgn_prop_fmgr_mmc_no_sub.svg image/qgn_prop_phone_memc.svg image/qgn_prop_usb_memc.svg - image/qgn_prop_fmgr_ms.svg + image/qgn_prop_fmgr_ms.svg + resources/hblistviewitem.css + resources/hblistviewitem.widgetml \ No newline at end of file diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/resources/hblistviewitem.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/resources/hblistviewitem.css Thu Sep 02 20:16:57 2010 +0300 @@ -0,0 +1,57 @@ + +HbListViewItem[layoutName="drive"]:portrait{ + layout: drive-portrait; +} + + +HbListViewItem[layoutName="drive"]:landscape{ + layout: drive-landscape; +} + +HbListViewItem::text-1[layoutName="drive"]:portrait{ + top: -var(hb-param-margin-gene-middle-vertical); + font-variant: primary; + text-align: left; +} + +HbListViewItem::text-2[layoutName="drive"]:portrait{ + font-variant: secondary; + text-align: left; +} +HbListViewItem::text-3[layoutName="drive"]:portrait{ + bottom: var(hb-param-margin-gene-middle-vertical); + font-variant: secondary-small; + text-align: left; +} +HbListViewItem::icon-1[layoutName="drive"]:portrait{ + top: -var(hb-param-margin-gene-top); + left: -var(hb-param-margin-gene-middle-horizontal); + + fixed-height: var(hb-param-graphic-size-primary-large); + fixed-width: var(hb-param-graphic-size-primary-large); +} + +HbListViewItem::text-1[layoutName="drive"]:landscape{ + top: -var(hb-param-margin-gene-top); + font-variant: primary; + text-align: left; +} + +HbListViewItem::text-2[layoutName="drive"]:landscape { + top: -var(hb-param-margin-gene-top); + font-variant: secondary; + text-align: left; +} +HbListViewItem::text-3[layoutName="drive"]:landscape{ + bottom: var(hb-param-margin-gene-top); + font-variant: secondary-small; + text-align: left; +} +HbListViewItem::icon-1[layoutName="drive"]:landscape{ + top: -var(hb-param-margin-gene-top); + left: -var(hb-param-margin-gene-middle-horizontal); + bottom: var(hb-param-margin-gene-bottom); + fixed-height: var(hb-param-graphic-size-primary-large); + fixed-width: var(hb-param-graphic-size-primary-large); +} + diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/resources/hblistviewitem.widgetml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/filemanager/resources/hblistviewitem.widgetml Thu Sep 02 20:16:57 2010 +0300 @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/backuprestore/fmbackuprestorehandler.cpp --- a/filemanager/src/filemanager/src/backuprestore/fmbackuprestorehandler.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/backuprestore/fmbackuprestorehandler.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -72,8 +72,8 @@ mCurrentProcess = ProcessBackup; bool ret = mBkupEngine->startBackup( backupConfigLoader()->driversAndOperationList(), backupConfigLoader()->backupCategoryList(), - mBkupEngine->BackupSettingsL()->availableTargetDrive(), - mBkupEngine->BackupSettingsL()->content() ); + operationBackup->targetDrive(), // targetDrive is stored in FmOperationBackup + operationBackup->content() ); // content is stored in FmOperationBackup if( !ret ) { mCurrentProcess = ProcessNone; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp --- a/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -131,10 +131,12 @@ mContentsItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( "" ), mContentsGroup ); mContentsItem->setContentWidgetData( QString("readOnly"), QString("true") ); + mContentsItem->setContentWidgetData( QString("objectName"), QString("backupContentItem") ); mTargetItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( "" ), mContentsGroup ); mTargetItem->setContentWidgetData( QString("readOnly"), QString("true") ); + mTargetItem->setContentWidgetData( QString("objectName"), QString("backupTargetItem") ); mSchedulingGroup = mModel->appendDataFormGroup( QString( hbTrId( "Scheduling" ) ), mModel->invisibleRootItem()); @@ -142,19 +144,22 @@ mSchedulingItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); mSchedulingItem->setContentWidgetData( QString("readOnly"), QString("true") ); + mSchedulingItem->setContentWidgetData( QString("objectName"), QString("backupSchedulingItem") ); mWeekdayItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); mWeekdayItem->setContentWidgetData( QString("readOnly"), QString("true") ); + mWeekdayItem->setContentWidgetData( QString("objectName"), QString("backupWeekdayItem") ); mTimeItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( "" ), mSchedulingGroup ); mTimeItem->setContentWidgetData( QString("readOnly"), QString("true") ); + mTimeItem->setContentWidgetData( QString("objectName"), QString("backupTimeItem") ); mLastBackupDateItem = mModel->appendDataFormItem( HbDataFormModelItem::TextItem, QString( ( "" )), mModel->invisibleRootItem() ); mLastBackupDateItem->setContentWidgetData( QString("readOnly"), QString("true") ); - + mLastBackupDateItem->setContentWidgetData( QString("objectName"), QString("backupLastBackupDateItem") ); } diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/components/fmsingletextquery.h --- a/filemanager/src/filemanager/src/components/fmsingletextquery.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/components/fmsingletextquery.h Thu Sep 02 20:16:57 2010 +0300 @@ -29,7 +29,7 @@ Q_OBJECT public: - FmSingleTextQuery( HbLineEdit::EchoMode echoMode = HbLineEdit::Normal, QGraphicsItem *parent = 0 ); + explicit FmSingleTextQuery( HbLineEdit::EchoMode echoMode = HbLineEdit::Normal, QGraphicsItem *parent = 0 ); ~FmSingleTextQuery(); public: @@ -49,7 +49,7 @@ HbLineEdit *mTextEdit; HbLineEdit::EchoMode mEchoMode; - // used to check if input text is vaild. Disable primary action when text is not vaild + // used to check if input text is valid. Disable primary action when text is not valid QStringList mRegExpStringList; }; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/components/fmtimequery.cpp --- a/filemanager/src/filemanager/src/components/fmtimequery.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/components/fmtimequery.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -21,7 +21,7 @@ #include #include -#include +#include FmTimeQuery::FmTimeQuery( QGraphicsItem *parent ) : FmDialog( parent ) @@ -33,7 +33,7 @@ QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); vLayout->setOrientation( Qt::Vertical ); - mTimeWidget = new HbDateTimeEdit(); + mTimeWidget = new HbDateTimePicker(); mTimeWidget->setObjectName( "timeQueryTimeWidget" ); vLayout->addItem( mTimeWidget ); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/components/fmtimequery.h --- a/filemanager/src/filemanager/src/components/fmtimequery.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/components/fmtimequery.h Thu Sep 02 20:16:57 2010 +0300 @@ -25,7 +25,7 @@ #include class QGraphicsWidget; -class HbDateTimeEdit; +class HbDateTimePicker; class FmTimeQuery : public FmDialog { public: @@ -46,7 +46,7 @@ private: QGraphicsWidget *mContentWidget; - HbDateTimeEdit *mTimeWidget; + HbDateTimePicker *mTimeWidget; }; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp --- a/filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/components/fmviewdetailsdialog.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmdriverlistwidget.cpp --- a/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -16,7 +16,6 @@ * The driver model file for file manager */ #include "fmdriverlistwidget.h" -#include "listviewitems.h" #include "fmutils.h" #include "fmdlgutils.h" #include "fmviewmanager.h" @@ -24,7 +23,8 @@ #include "fmoperationbase.h" #include "fmdrivemodel.h" #include "fmfiledialog.h" - +#include "fmoperationservice.h" +#include #include #include #include @@ -36,12 +36,10 @@ FmDriverListWidget::FmDriverListWidget( QGraphicsItem *parent ) : HbWidget( parent ), mListView(0), mModel(0), - mCurrentItem(0), mSearchPanel(0), mOperationService(0), + mCurrentItem(0), mSearchPanel(0), mFileSystemWatcher(0), mLayout(0), mContextMenu(0), mListLongPressed( false ) { - init(); - mOperationService = FmViewManager::viewManager()->operationService(); - + init(); mFileSystemWatcher = new QFileSystemWatcher( this ); connect( mFileSystemWatcher, SIGNAL( directoryChanged ( const QString & ) ), this, SLOT( on_directoryChanged( const QString & ) ) ); @@ -72,23 +70,18 @@ mLayout = new QGraphicsLinearLayout( this ); mLayout->setOrientation( Qt::Vertical ); - mListView = new HbListView( this ); - mListView->setSelectionMode( HbAbstractItemView::SingleSelection ); - + mListView = new HbListView( this ); + mListView->setLayoutName( "drive" ); mModel = new FmDriveModel( this, - FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume ); + FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | + FmDriveModel::FillWithTotalSize | FmDriveModel::FillWithFreeSize ); mListView->setModel( mModel ); - - mLayout->addItem( mListView ); - + mLayout->addItem( mListView ); mSearchPanel = new HbSearchPanel( this ); mSearchPanel->setObjectName( "searchPanel" ); mSearchPanel->setSearchOptionsEnabled( true ); mSearchPanel->setProgressive( false ); mSearchPanel->hide(); -// mLayout->addItem( mSearchPanel ); - - mListView->setItemPrototype( new DiskListViewItem(this) ); connect( mListView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( on_list_activated( const QModelIndex & ) ) ); connect( mListView, SIGNAL( pressed( const QModelIndex & ) ), @@ -188,19 +181,20 @@ 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( driveType == FmDriverInfo::EDriveTypeMemoryCard || driveType == FmDriverInfo::EDriveTypeUsbMemory ) + } //if( state & FmDriverInfo::EDriveAvailable ) + + // Eject action + // put outside of EDriveAvailable so that removable drive which is corrupted or locked can be removed + 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 ); + } // Format action if ( ( state & FmDriverInfo::EDriveRemovable ) || ( state & FmDriverInfo::EDriveCorrupted ) @@ -213,10 +207,10 @@ connect( formatAction, SIGNAL( triggered() ), this, SLOT( on_formatAction_triggered() ), Qt::QueuedConnection ); } - } + } //if( !( state & FmDriverInfo::EDriveNotPresent ) ) // Unlock action - // put ouside of !EDriveNotPresent judgement so that + // put ouside of !EDriveNotPresent judgment so that // user could unlock drive if connected to PC with mass storage mode if( state & FmDriverInfo::EDriveLocked ){ HbAction *unLockedAction = new HbAction(); @@ -239,13 +233,14 @@ void FmDriverListWidget::on_list_pressed( const QModelIndex & index ) { + Q_UNUSED( index ); mListLongPressed = false; } void FmDriverListWidget::on_viewAction_triggered() { - QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); - mOperationService->asyncViewDriveDetails( diskName ); + QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); + FmViewManager::viewManager()->operationService()->asyncViewDriveDetails( diskName ); } void FmDriverListWidget::on_renameAction_triggered() @@ -408,7 +403,7 @@ QString diskName = mModel->driveName( mCurrentItem->modelIndex() ); if( FmDlgUtils::question( hbTrId( "Format? Data will be deleted during formatting." ) ) ){ - if( FmErrNone != mOperationService->asyncFormat( diskName ) ) + if( FmErrNone != FmViewManager::viewManager()->operationService()->asyncFormat( diskName ) ) FmDlgUtils::information( hbTrId( "Formatting failed." ) ); } } diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmdriverlistwidget.h --- a/filemanager/src/filemanager/src/fmdriverlistwidget.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmdriverlistwidget.h Thu Sep 02 20:16:57 2010 +0300 @@ -20,7 +20,6 @@ #define FMDRIVERLISTWIDGET_H #include "fmcommon.h" -#include "fmoperationservice.h" #include class FmDriveModel; @@ -76,7 +75,6 @@ HbAbstractViewItem* mCurrentItem; HbSearchPanel* mSearchPanel; - FmOperationService *mOperationService; QFileSystemWatcher *mFileSystemWatcher; QString mFindTargetPath; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmfindthread.cpp --- a/filemanager/src/filemanager/src/fmfindthread.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmfindthread.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -27,10 +27,10 @@ #define ParentDir QString( ".." ) // if got 5 result and have not send notify event, then send notify event -#define notifyPerCount 5 +const int notifyPerCount = 5; // if got notifyPerElapsedTime milliseconds and have not send notify event, then send notify event. -#define notifyPerElapsedTime 500 +const int notifyPerElapsedTime = 500; /*! \fn void found( const QStringList &dataList ) diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmmainwindow.cpp --- a/filemanager/src/filemanager/src/fmmainwindow.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmmainwindow.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -23,11 +23,14 @@ FmMainWindow::FmMainWindow() : mViewManager( 0 ), mFirstViewLoaded( false ) { - connect(this, SIGNAL(viewReady()), this, SLOT(delayedLoading())); + // connect(this, SIGNAL(viewReady()), this, SLOT(delayedLoading())); + init(); } FmMainWindow::~FmMainWindow() { + //save file manager activity to activity manager. + mViewManager->saveActivity(); FmViewManager::RemoveViewManager(); } @@ -48,6 +51,8 @@ FM_LOG("FmMainWindow::init start"); mViewManager = FmViewManager::CreateViewManager( this ); mViewManager->createDriverView(); + connect(this, SIGNAL(aboutToChangeView(HbView *, HbView *)), + mViewManager, SLOT(onAboutToChangeView(HbView *, HbView *))); connect( this, SIGNAL( orientationChanged( Qt::Orientation ) ), this, SLOT( onOrientationChanged( Qt::Orientation ) ) ); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmviewmanager.cpp --- a/filemanager/src/filemanager/src/fmviewmanager.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmviewmanager.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -32,9 +32,12 @@ #include "fmdlgutils.h" #include +#include +#include +#include #include #include - +#include FmViewManager *FmViewManager::mViewManager = 0; @@ -70,12 +73,9 @@ return mDialog; } -FmViewManager::FmViewManager( FmMainWindow* mainWindow ) +FmViewManager::FmViewManager( FmMainWindow* mainWindow ) : mOperationService( 0 ) { mMainWindow = mainWindow; - mOperationService = new FmOperationService( this ); - mOperationService->setObjectName( "operationService" ); - mDriveWatcher = new FmDriveWatcher( this ); mDriveWatcher->setObjectName( "driveWatcher" ); mDriveWatcher->startWatch(); @@ -85,7 +85,6 @@ FmViewManager::~FmViewManager(void) { - FmViewBase *view = static_cast( mMainWindow->currentView() ); while( view ) { mMainWindow->removeView( view ); @@ -123,6 +122,10 @@ FmOperationService *FmViewManager::operationService() { + if ( !mOperationService ) { + mOperationService = new FmOperationService( this ); + mOperationService->setObjectName( "operationService" ); + } return mOperationService; } @@ -130,7 +133,10 @@ { FmViewBase *view = static_cast( mMainWindow->currentView() ); view->setNavigationAction( 0 ); - + // grap the screen when only the drive view is in view stack. + if( viewCount() == 1 ) { + mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); + } mMainWindow->removeView( view ); delete view; @@ -175,11 +181,17 @@ mMainWindow->addView( driverView ); mMainWindow->setCurrentView( driverView ); + HbActivityManager* activityManager = qobject_cast(qApp)->activityManager(); + bool ok = activityManager->removeActivity("FMMemoryStoragesList"); connect( this, SIGNAL( driveSpaceChanged() ), driverView, SLOT( refreshDrive() ) ); + // Refresh drive view when gaining foreground + // ( switch back to filemanager from home screen or any other applications ) + connect( mMainWindow, SIGNAL( revealed() ), + driverView, SLOT( refreshDrive() ) ); - // use Qt::QueuedConnection becuase synchronous refresh is not work well while + // use Qt::QueuedConnection because 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. @@ -302,3 +314,32 @@ } } } + +void FmViewManager::saveActivity() +{ + //grap the screen when current view is drive view. + FmDriverView *driveView = qobject_cast(mMainWindow->currentView()); + if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) { + mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); + } + QVariantHash metadata; + metadata.insert("screenshot", mScreenShot); + HbActivityManager* activityManager = qobject_cast(qApp)->activityManager(); + // add the activity to the activity manager + bool ok = activityManager->addActivity("FMMemoryStoragesList", QVariant(), metadata); + if ( !ok ) + { + qFatal("Add failed" ); + } + +} + +void FmViewManager::onAboutToChangeView(HbView * oldView, HbView *newView) +{ + Q_UNUSED(newView); + //grap the screen when oldView is drive view. + FmDriverView *driveView = qobject_cast(oldView); + if ( ( driveView != 0 ) && ( driveView->viewType() == FmViewBase::EDriverView ) ) { + mScreenShot = QPixmap::grabWidget(mMainWindow, mMainWindow->rect()); + } +} diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/fmviewmanager.h --- a/filemanager/src/filemanager/src/fmviewmanager.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/fmviewmanager.h Thu Sep 02 20:16:57 2010 +0300 @@ -22,6 +22,7 @@ #include #include #include "fmcommon.h" +#include class FmMainWindow; class HbView; @@ -34,7 +35,7 @@ /* * this class is used to record relationship between dialog and drive name - * FmViewManager will auto-close dialog which releated drive is not available again. + * FmViewManager will auto-close dialog which related drive is not available again. * for example. set name to MMC will pop a dialog, if add the dialog to FmViewManager::addDlgCloseUnit * then after eject MMC, the dialog will be auto-closed by FmViewManager::checkDlgCloseUnit() */ @@ -75,8 +76,8 @@ void createBackupView(); void createRestoreView(); void createDeleteBackupView(); - - // add a close unit. this is used to auto-close dialog which releated drive is not available again. + void saveActivity(); + // add a close unit. this is used to auto-close dialog which related drive is not available again. void addDlgCloseUnit( FmDlgCloseUnit* unit ) { FM_LOG( "FmViewManager::addDlgCloseUnit_" + unit->associatedDrives() ); @@ -110,6 +111,8 @@ // so this is the central controller function void on_operationService_notifyFinish( FmOperationBase *operationBase ); + void onAboutToChangeView(HbView * oldView, HbView *newView); + signals: // emit when drive space is changed by some operation inside filemanager. void driveSpaceChanged(); @@ -124,7 +127,7 @@ // when drive is ejected, this function will be called and exam dialogs in mDlgCloseUnitList // it will colse dialogs if related drive is not available void checkDlgCloseUnit(); - + private: static FmViewManager *mViewManager; @@ -141,6 +144,8 @@ // used to record some dialogs that related to drive // the dialog should be closed in checkDlgCloseUnit if drive is not available QList mDlgCloseUnitList; + + QPixmap mScreenShot; }; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/listviewitems.cpp --- a/filemanager/src/filemanager/src/listviewitems.cpp Wed Aug 18 09:39:39 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +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: -* Zhiqiang Yang -* Steven Yao -* -* Description: -* The source file of the disk list view item -* -*/ -#include "listviewitems.h" -#include "fmutils.h" - -#include - -#include -#include -#include -#include - -DiskListViewItem::DiskListViewItem( QGraphicsItem *parent ) - : HbListViewItem( parent ), - mIconLabel( 0 ), - mDiskNameLabel( 0 ), - mFirstLabel( 0 ), - mSecondLabel( 0 ), - mCheckBox( 0 ), - hLayout( 0 ) - -{ - //init(); -} - -DiskListViewItem::~DiskListViewItem() -{ -} - -void DiskListViewItem::polish(HbStyleParameters& params) -{ - Q_UNUSED(params); -} - -bool DiskListViewItem::canSetModelIndex( const QModelIndex &index ) const -{ - Q_UNUSED( index ); - return true; -} - - -HbAbstractViewItem *DiskListViewItem::createItem() -{ - return new DiskListViewItem( *this ); -} - -void DiskListViewItem::updateChildItems() -{ - //HbListViewItem::updateChildItems(); - if( !hLayout ) { - init(); - } - QVariant variant = modelIndex().data( Qt::DecorationRole ); - QIcon icon = qvariant_cast( variant ); - // FmFileIconProvider in FmDriveModel already handle null icon issue - QString displayString = modelIndex().data( Qt::DisplayRole ).toString(); - QString diskName = modelIndex().data( Qt::UserRole ).toString(); - - diskName = FmUtils::fillPathWithSplash( diskName ); - - mIconLabel->setIcon( HbIcon( icon ) ); - - FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); - - mDiskNameLabel->setPlainText( displayString ); - if( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) { - mFirstLabel->setPlainText( hbTrId ( "Size: " ) + FmUtils::formatStorageSize( driverInfo.size() ) ); - mSecondLabel->setPlainText( hbTrId ( "Free: " ) + FmUtils::formatStorageSize( driverInfo.freeSize() ) ); - } else if( driverInfo.driveState() & FmDriverInfo::EDriveLocked ) { - mFirstLabel->setPlainText( hbTrId ( "Locked" ) ); - mSecondLabel->setPlainText( QString(" ") ); - } else if( driverInfo.driveState() & FmDriverInfo::EDriveCorrupted ) { - mFirstLabel->setPlainText( hbTrId ( "Corrupted" ) ); - mSecondLabel->setPlainText( QString(" ") ); - } else if( driverInfo.driveState() & FmDriverInfo::EDriveNotPresent ) { - mFirstLabel->setPlainText( hbTrId ( "Not Ready" ) ); - mSecondLabel->setPlainText( QString(" ") ); - } - -// mCheckBox->setCheckState( checkState() ); -} - -void DiskListViewItem::setCheckedState( int state ) -{ - HbAbstractViewItem::setCheckState( static_cast(state) ); -} - -void DiskListViewItem::init() -{ - hLayout = new QGraphicsLinearLayout(); - - hLayout->setOrientation( Qt::Horizontal ); - hLayout->addItem(layout()); - - mIconLabel = new HbLabel(); - mIconLabel->setMinimumWidth(32); - hLayout->addItem( mIconLabel ); - hLayout->setAlignment( mIconLabel, Qt::AlignTop ); - hLayout->setStretchFactor( mIconLabel, 1 ); - - QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(); - vLayout->setOrientation( Qt::Vertical ); - - mDiskNameLabel = new HbLabel(); - mDiskNameLabel->setFontSpec( HbFontSpec( HbFontSpec::Primary ) ); - vLayout->addItem( mDiskNameLabel ); - vLayout->setAlignment( mDiskNameLabel, Qt::AlignLeft ); - - mFirstLabel = new HbLabel(); - mFirstLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) ); - vLayout->addItem( mFirstLabel ); - vLayout->setAlignment( mFirstLabel, Qt::AlignLeft ); - - mSecondLabel = new HbLabel(); - mSecondLabel->setFontSpec( HbFontSpec( HbFontSpec::Secondary ) ); - vLayout->addItem( mSecondLabel ); - vLayout->setAlignment( mSecondLabel, Qt::AlignLeft ); - - HbWidget *labelsWidget = new HbWidget(); - labelsWidget->setLayout(vLayout); - - hLayout->addItem( labelsWidget ); - hLayout->setStretchFactor( labelsWidget, 5 ); - - setLayout( hLayout ); -} diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/listviewitems.h --- a/filemanager/src/filemanager/src/listviewitems.h Wed Aug 18 09:39:39 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +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: -* Zhiqiang Yang -* -* Description: -* The header file of the disk list view item -* -*/ - -#ifndef LISTVIEWITEMS_H -#define LISTVIEWITEMS_H - -#include "fmcommon.h" - -#include - -class HbCheckBox; -class HbLabel; -class QGraphicsLinearLayout; - -class DiskListViewItem : public HbListViewItem -{ - Q_OBJECT - -public: - DiskListViewItem( QGraphicsItem *parent = 0 ); - ~DiskListViewItem(); - - virtual bool canSetModelIndex( const QModelIndex &index ) const; - virtual HbAbstractViewItem *createItem(); - virtual void updateChildItems(); -private slots: - void setCheckedState( int state ); - -private: - virtual void polish(HbStyleParameters& params); - -private: - void init(); - - HbLabel *mIconLabel; - HbLabel *mDiskNameLabel; - HbLabel *mFirstLabel; - HbLabel *mSecondLabel; - HbCheckBox *mCheckBox; - QGraphicsLinearLayout *hLayout; -}; - -/* not used -class FileListViewItem : public HbListViewItem -{ - Q_OBJECT - -public: - FileListViewItem( QGraphicsItem *parent = 0 ); - ~FileListViewItem(); - - virtual bool canSetModelIndex( const QModelIndex &index ) const; - virtual HbAbstractViewItem *createItem(); - virtual void updateChildItems(); - - virtual void polish(HbStyleParameters& params); -private slots: - void setCheckedState( int state ); - -private: - void init(); - - HbLabel *mIconLabel; - HbLabel *mNameLabel; - HbCheckBox *mCheckBox; -}; -*/ - -#endif //LISTVIEWITEMS_H diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/main.cpp --- a/filemanager/src/filemanager/src/main.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/main.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -23,23 +23,23 @@ #include "fmmainwindow.h" #include - +#include +#include #include #include int main( int argc, char *argv[] ) { FM_LOG( "main start" ); - HbApplication app( argc, argv ); - - QTranslator translator; - QString lang = QLocale::system().name(); - QString path = "z:/resource/qt/translations/"; - translator.load( path + "filemanager_" + lang ); - app.installTranslator(&translator); - + HbApplication app( argc, argv ); + + HbTranslator translator("filemanager"); + translator.loadCommon(); app.setApplicationName( hbTrId("txt_fmgr_title_file_manager") ); + HbStyleLoader::registerFilePath(":/resources/hblistviewitem.css"); + HbStyleLoader::registerFilePath(":/resources/hblistviewitem.widgetml"); + FM_LOG( "main_createMainwindow start" ); FmMainWindow mw; FM_LOG( "main_createMainwindow end" ); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationbase.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -107,9 +107,12 @@ /* Constructs a backup operation with \a parent parent + \a targetDrive backup target drive + backup \a content is mask for contents want to backup. Refer to mContent in FmBackupSettings */ -FmOperationBackup::FmOperationBackup( QObject *parent ) - : FmOperationBase( parent, FmOperationService::EOperationTypeBackup ) +FmOperationBackup::FmOperationBackup( QObject *parent, const QString &targetDrive, quint32 content ) + : FmOperationBase( parent, FmOperationService::EOperationTypeBackup ), + mTargetDrive( targetDrive ), mContent( content ) { } @@ -122,6 +125,22 @@ } /* + Get target backup drive +*/ +QString FmOperationBackup::targetDrive() const +{ + return mTargetDrive; +} + +/* + Get backup content mask. Refer to mContent in FmBackupSettings +*/ +quint32 FmOperationBackup::content() const +{ + return mContent; +} + +/* Constructs a restore operation with \a parent parent \a selection the selected backup items @@ -141,7 +160,7 @@ /* Returns the backup items */ -quint64 FmOperationRestore::selection() +quint64 FmOperationRestore::selection() const { return mSelection; } diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationbase.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationbase.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationbase.h Thu Sep 02 20:16:57 2010 +0300 @@ -52,18 +52,29 @@ class FmOperationBackup : public FmOperationBase { +Q_OBJECT public: - explicit FmOperationBackup( QObject *parent ); + explicit FmOperationBackup( QObject *parent, const QString &targetDrive, quint32 content ); virtual ~FmOperationBackup(); + + QString targetDrive() const; + quint32 content() const ; +private: + // used to save backup target drive + QString mTargetDrive; + + // used to save FmBackupSettings::content() + quint32 mContent; }; class FmOperationRestore : public FmOperationBase { +Q_OBJECT public: explicit FmOperationRestore( QObject *parent, quint64 selection ); virtual ~FmOperationRestore(); - quint64 selection(); + quint64 selection() const; private: quint64 mSelection; }; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -100,12 +100,11 @@ mCopiedOrMovedSize = 0; mCurrentStep = 0; - if( mSourceList.empty() ) { + if ( mSourceList.empty() ) { emit notifyError( FmErrWrongParam, mErrString ); return ; } - - emit notifyPreparing( true ); + emit notifyPreparing( true ); int numofFolders = 0; int numofFiles = 0; @@ -115,8 +114,11 @@ if( ret != FmErrNone ) { emit notifyError( ret, mErrString ); return; - } - + } + if ( !targetHasEnoughSpace() ) { + emit notifyError( FmErrDiskFull, mErrString ); + return; + } emit notifyStart( true, mTotalSteps ); foreach( const QString& source, mSourceList ) { @@ -210,6 +212,13 @@ int ret = FmErrNone; if ( fi.isFile() ) { + if ( FmUtils::getDriveLetterFromPath( source ) == + FmUtils::getDriveLetterFromPath( targetPath ) && + operationType() == FmOperationService::EOperationTypeMove ) + { + return FmUtils::moveInsideDrive( source, newName ); + + } quint64 fileSize = fi.size(); ret = copyOneFile( source, newName ); if (ret != FmErrNone) { @@ -364,7 +373,7 @@ } /* - * Copys one file from \a srcFile to \a desFile + * Copies one file from \a srcFile to \a desFile */ int FmOperationCopyOrMove::copyOneFile( const QString &srcFile, const QString &desFile ) { @@ -424,3 +433,14 @@ } } +bool FmOperationCopyOrMove::targetHasEnoughSpace() +{ + QString sourceDrive = FmUtils::getDriveLetterFromPath( mSourceList.front() ); + QString targetDrive = FmUtils::getDriveLetterFromPath( mTargetPath ); + if ( sourceDrive == targetDrive && + operationType() == FmOperationService::EOperationTypeMove ) { + return true; + } else { + return FmUtils::hasEnoughSpace( targetDrive, mTotalSize ); + } +} diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.h --- a/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationcopyormove.h Thu Sep 02 20:16:57 2010 +0300 @@ -46,6 +46,7 @@ void increaseProgress( quint64 size ); void queryForRename( const QString &srcFile, QString *destFile ); int copyOneFile( const QString &srcFile, const QString &desFile ); + bool targetHasEnoughSpace(); private: FmOperationService *mOperationService; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationformat_win.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -54,13 +54,13 @@ * Starts to format. * \a isStopped not used */ -void FmOperationFormat::start( volatile bool */*isStopped*/ ); +void FmOperationFormat::start( volatile bool */*isStopped*/ ) { QString logString = "FmOperationFormat::start"; FM_LOG( logString ); if( mDriverName.isEmpty() ) { - emit notifyError( FmErrWrongParam ); + emit notifyError( FmErrWrongParam, QString() ); return; } int totalCount( 100 ); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -18,6 +18,9 @@ #include "fmoperationbase.h" #include "fmoperationservice.h" #include "fmoperationformat.h" +#include "fmbkupengine.h" +#include "fmbackupsettings.h" +#include "fmbackuprestorehandler.h" #include "fmoperationviewdetails.h" #include "fmviewdetailsdialog.h" #include "fmdlgutils.h" @@ -314,25 +317,63 @@ { case FmErrCancel: cancelProgress(); - FmDlgUtils::information( QString( hbTrId("Operation Canceled!") ) ); + // Do not pop up general cancel note as it is not needed( according to TB9.2 ). + // If it should be added later, please do not use blocking note. + // Blocking note will cause second backup operaion freeze after cancel previous backup operation + // as QEventLoop::exec will cause some problem when used for blocking dialog. + // HbDialog has already removed exec function which is implemented with QEventLoop::exec. + // If need use QEventLoop::exec to block code execute sequence, It should be invoked in a Qt::QueuedConnection slot. return; case FmErrAlreadyStarted: FmDlgUtils::information( QString( hbTrId("Operation already started!")) ); return; case FmErrLocked: - FmDlgUtils::information( QString( hbTrId("Operation failed because drive is locked!")) ); - return; + { + FmOperationBackup *operationBackup = qobject_cast(operationBase); + if( operationBackup ) { + // special error note for backup + QString targetDrive( operationBackup->targetDrive() ); + QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); + QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); + FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_locked") ).arg( driveString ) ); + } else { + FmDlgUtils::information( QString( hbTrId("Operation failed because drive is locked!")) ); + } + return; + } case FmErrPathNotFound: FmDlgUtils::information( QString( hbTrId("Operation failed because can not find target path or drive is not available!") ) ); return; case FmErrCorrupt: - FmDlgUtils::information( QString( hbTrId("Operation failed because target media is corrupted!") ) ); - return; + { + FmOperationBackup *operationBackup = qobject_cast(operationBase); + if( operationBackup ) { + // special error note for backup + QString targetDrive( operationBackup->targetDrive() ); + QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); + QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); + FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_corrupted") ).arg( driveString ) ); + } else { + FmDlgUtils::information( QString( hbTrId("Operation failed because target media is corrupted!") ) ); + } + return; + } case FmErrNotReady: // Caused when MMC & OTG is not inserted when start backup - FmDlgUtils::information( QString( hbTrId("Operation failed because device is not ready!") ) ); - return; - case FmErrDisMounted: // Caused by eject MMC when preparing backup - FmDlgUtils::information( QString( hbTrId("Operation failed because device has been removed!") ) ); + { + FmOperationBackup *operationBackup = qobject_cast(operationBase); + if( operationBackup ) { + // special error note for backup + QString targetDrive( operationBackup->targetDrive() ); + QString defaultDriveVolume( FmUtils::getDefaultVolumeName( targetDrive ) ); + QString driveString( defaultDriveVolume.isEmpty()? targetDrive:defaultDriveVolume ); + FmDlgUtils::information( QString( hbTrId("txt_fmgr_info_backup_unavailable") ).arg( driveString ) ); + } else { + FmDlgUtils::information( QString( hbTrId("Operation failed because device is not ready!") ) ); + } + return; + } + case FmErrDisMounted: // Caused by eject MMC when preparing backup, will be localized later + FmDlgUtils::information( QString( hbTrId("Operation failed because backup target drive has been removed!") ) ); return; case FmErrDiskFull: FmDlgUtils::information( QString( hbTrId("Not enough space. Operation cancelled!")) ); @@ -414,6 +455,7 @@ // mNote->setProgressDialogType( HbProgressDialog::WaitNote ); // } mNote->setText( title ); + //KRAZY: ignore krazy warning because QAction must be used. QList actionList = mNote->actions(); if (actionList.size() > 0) { QAction *cancelAction = actionList.at(0); @@ -453,6 +495,7 @@ mNote->setMaximum( 65535 ); mNote->setProgressValue( 0 ); mNote->setText( title ); + //KRAZY: ignore krazy warning because QAction must be used. QList actionList = mNote->actions(); if (actionList.size() > 0) { QAction *cancelAction = actionList.at(0); @@ -493,6 +536,7 @@ mNote->setMaximum( maxValue ); mNote->setProgressValue( 0 ); + //KRAZY: ignore krazy warning because QAction must be used. QList actionList = mNote->actions(); if (actionList.size() > 0) { QAction *cancelAction = actionList.at(0); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationservice.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -20,6 +20,7 @@ #include "fmoperationthread.h" #include "fmbackupconfigloader.h" #include "fmbkupengine.h" +#include "fmbackupsettings.h" #include "fmviewdetailsdialog.h" #include "fmoperationresultprocesser.h" #include "fmoperationcopyormove.h" @@ -65,13 +66,10 @@ * Constructs one operation Service with \a parent. */ FmOperationService::FmOperationService( QObject *parent ) : QObject( parent ), - mCurrentOperation( 0 ) + mCurrentOperation( 0 ), mBackupRestoreHandler( 0 ) { mThread = new FmOperationThread( this ); mThread->setObjectName( "operationThread" ); - mBackupRestoreHandler = new FmBackupRestoreHandler( this ); - mBackupRestoreHandler->setObjectName( "backupRestore" ) ; - mOperationResultProcesser = new FmOperationResultProcesser( this ); QMetaObject::connectSlotsByName( this ); @@ -83,7 +81,9 @@ FmOperationService::~FmOperationService() { delete mThread; + mThread = 0; delete mBackupRestoreHandler; + mBackupRestoreHandler = 0; } /* @@ -95,7 +95,7 @@ } /* - * Copys the file or foler \a targetPath asynchronously. + * Copies the file or foler \a targetPath asynchronously. */ int FmOperationService::asyncCopy( const QStringList &sourceList, const QString &targetPath ) { @@ -204,7 +204,11 @@ return FmErrAlreadyStarted; Q_ASSERT( !mCurrentOperation ); - FmOperationBackup *operationBackup = new FmOperationBackup( mBackupRestoreHandler ); + // BackupSettingsL will not leave, coding convention will be improvied in another task. + QString targetDrive( backupRestoreHandler()->bkupEngine()->BackupSettingsL()->availableTargetDrive() ); + quint32 content( backupRestoreHandler()->bkupEngine()->BackupSettingsL()->content() ); + FmOperationBackup *operationBackup = + new FmOperationBackup( backupRestoreHandler(), targetDrive, content ); mCurrentOperation = operationBackup; int ret = backupRestoreHandler()->startBackup( operationBackup ); if( ret ){ @@ -242,7 +246,7 @@ */ int FmOperationService::syncDeleteBackup( quint64 selection ) { - return mBackupRestoreHandler->deleteBackup( selection ); + return backupRestoreHandler()->deleteBackup( selection ); } /* @@ -325,7 +329,8 @@ FmBackupRestoreHandler *FmOperationService::backupRestoreHandler() { if( !mBackupRestoreHandler ) { - mBackupRestoreHandler = new FmBackupRestoreHandler( this ); + mBackupRestoreHandler = new FmBackupRestoreHandler( this ); + mBackupRestoreHandler->setObjectName( "backupRestore" ) ; QMetaObject::connectSlotsByName( this ); } return mBackupRestoreHandler; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/fmfiledialog/fmfiledialog.pro --- a/filemanager/src/fmfiledialog/fmfiledialog.pro Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/fmfiledialog/fmfiledialog.pro Thu Sep 02 20:16:57 2010 +0300 @@ -28,8 +28,8 @@ -lshareui \ -lefsrv \ -lapgrfx \ - -lcone \ - -ldirectorylocalizer + -lcone \ + -lsysutil TARGET.UID3 = 0x2002BCC3 diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/fmfiledialog/src/fmfilewidget.cpp --- a/filemanager/src/fmfiledialog/src/fmfilewidget.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/fmfiledialog/src/fmfilewidget.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -96,7 +96,7 @@ { FM_LOG("FmFileWidget::on_list_activated start" ); if( mCurrentModel == mDriveModel ) { - //If currenty model is DriveModel, open drive and set path + //If current model is DriveModel, open drive and set path QString driveName = mDriveModel->driveName( mActivatedModelIndex ); QString checkedPath = FmUtils::checkDriveToFolderFilter( driveName ); if( checkedPath.isEmpty() ) { @@ -113,7 +113,7 @@ FM_LOG("FmFileWidget::on_list_activated finish emit pathChanged" ); } else if( mCurrentModel == mFileSystemModel ) { - //If currenty model is FileSystemModel, open path or emit file activate signal. + //If current model is FileSystemModel, open path or emit file activate signal. if ( mFileSystemModel->isDir( mActivatedModelIndex ) ) { FM_LOG("FmFileWidget::on_list_activated start changeRootIndex" ); changeRootIndex( mActivatedModelIndex ); @@ -221,7 +221,7 @@ QString path( FmUtils::checkFolderToDriveFilter( currentPath().absoluteFilePath() ) ); QFileInfo fileInfo( path ); QString cdUpPath; - // path length>3 means currenty path is a sub folder, then get up level path and navigate to it + // path length>3 means current path is a sub folder, then get up level path and navigate to it // Otherwise means current path is a top level drive path, Should navigate to drive view. So setRootPath with empty path string. if( path.length() > 3 ) { cdUpPath = fileInfo.dir().absolutePath(); diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/commonutils.pri --- a/filemanager/src/inc/commonutils.pri Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/commonutils.pri Thu Sep 02 20:16:57 2010 +0300 @@ -23,7 +23,8 @@ INTERNAL_SOURCES += $$PWD/fmdrivemodel.cpp \ $$PWD/fmfileiconprovider.cpp \ $$PWD/fmdrivewatcher/fmdrivewatcher.cpp \ - $$PWD/fmfiletyperecognizer.cpp + $$PWD/fmfiletyperecognizer.cpp \ + $$PWD/fmutils.cpp symbian { INTERNAL_HEADERS += $$PWD/fms60utils.h \ diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmcommon.h --- a/filemanager/src/inc/fmcommon.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmcommon.h Thu Sep 02 20:16:57 2010 +0300 @@ -22,26 +22,11 @@ // MACRO for enable actions for change orientation // #define FM_CHANGE_ORIENT_ENABLE -// MACRO for launch find view quickly from driver view and search "b" in "c:\ruby" -//#define _DEBUG_SPEED_FINDVIEW_ - -// #define _DEBUG_ENABLE_FORMATMENU_ - +// MACRO for enable debug log +// #define _DEBUG_LOG_ENABLE_ -// MARCO for hide d, z, folder except C:\data in windows for debug -//#define _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ - -//#define _DEBUG_LOG_ENABLE_ - -//used to test drive hide which drive could be listed but not available -// #define _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ - -//used to test locked drive -// #define _DEBUG_LOCKED_DRIVE_Z #include "fmlogger.h" #include "fmdefine.h" - - #endif diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmdefine.h --- a/filemanager/src/inc/fmdefine.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmdefine.h Thu Sep 02 20:16:57 2010 +0300 @@ -77,13 +77,13 @@ // used to match un-empty string, and is not totally empty characters. #define Regex_ValidUnEmpty QString( "^.*[^\\s].*$" ) -// this is regexp for vaild file/folder name: no \/:*?"<>| and is not totally empty characters. +// this is regexp for valid file/folder name: no \/:*?"<>| and is not totally empty characters. // file name can not end with "." , but it is not include in this RegExp. It should be checked in Regex_ValidNotEndWithDot // this expression is composed by two expressions: // ^.*[^\\s].*$ used to match un-empty string and is not totally empty characters. // [^\\\\/:*?\"<>|] used to math valid file/folder name // merge the two regex together: -// vaild file/folder name and is not totally empty. +// valid file/folder name and is not totally empty. #define Regex_ValidFileFolderName QString( "^[^\\\\/:*?\"<>|]*[^\\\\/:*?\"<>|\\s][^\\\\/:*?\"<>|]*$" ) // is not end with dot( trim blank characters in the end first ) diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmdrivemodel.cpp --- a/filemanager/src/inc/fmdrivemodel.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmdrivemodel.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -84,10 +84,7 @@ if (role == Qt::DisplayRole ) { return displayString( index ); - } else if (role == Qt::UserRole ) { - return driveName( index ); - } - + } if (index.column() == 0) { if (role == Qt::DecorationRole ) { QString path = driveName( index ); @@ -139,17 +136,39 @@ return data; } -QString FmDriveModel::displayString( const QModelIndex &index ) const +QVariant FmDriveModel::displayString( const QModelIndex &index ) const { - QString data; + QStringList data; if (index.row() >= 0 && index.row() < mDriveList.size()) { int row = index.row(); QString diskName = mDriveList[ row ]; if( mOptions & FillWithVolume ) { - data = FmUtils::fillDriveVolume( diskName, mOptions & FillWithDefaultVolume ); + data << FmUtils::fillDriveVolume( diskName, mOptions & FillWithDefaultVolume ); } else { - data = FmUtils::removePathSplash( diskName ); + data << FmUtils::removePathSplash( diskName ); + } + diskName = FmUtils::fillPathWithSplash( diskName ); + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); + if ( mOptions & FillWithTotalSize ) { + if( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) { + data << QString( hbTrId ( "Size: " ) + FmUtils::formatStorageSize( driverInfo.size() ) ); + } else if( driverInfo.driveState() & FmDriverInfo::EDriveLocked ) { + data << QString( hbTrId ( "Locked" ) ); + } else if( driverInfo.driveState() & FmDriverInfo::EDriveCorrupted ) { + data << QString( hbTrId ( "Corrupted" ) ); + } else if( driverInfo.driveState() & FmDriverInfo::EDriveNotPresent ) { + data << QString( hbTrId ( "Not Ready" ) ); + } + } + if ( mOptions & FillWithFreeSize ) { + if( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) { + data << QString( hbTrId ( "Free: " ) + FmUtils::formatStorageSize( driverInfo.freeSize() ) ); + } else if( ( driverInfo.driveState() & FmDriverInfo::EDriveLocked ) || + ( driverInfo.driveState() & FmDriverInfo::EDriveCorrupted ) || + ( driverInfo.driveState() & FmDriverInfo::EDriveNotPresent )) { + data << QString( QString(" ") ); + } } } return data; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmdrivemodel.h --- a/filemanager/src/inc/fmdrivemodel.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmdrivemodel.h Thu Sep 02 20:16:57 2010 +0300 @@ -51,9 +51,11 @@ public: enum Option { - FillWithVolume = 0x00000001, // add volume behind disname - FillWithDefaultVolume = 0x00000002, // add default diskname while enable FillWithVolume and volume is empty - HideUnAvailableDrive = 0x00000004 // for example: drive F when no MMC card inserted. + FillWithVolume = 0x00000001, // add volume behind disname + FillWithDefaultVolume = 0x00000002, // add default diskname while enable FillWithVolume and volume is empty + HideUnAvailableDrive = 0x00000004, // for example: drive F when no MMC card inserted. + FillWithTotalSize = 0x00000008, // show the drive's total size. + FillWithFreeSize = 0x00000010 //show the drive's free size. }; Q_DECLARE_FLAGS(Options, Option) @@ -68,7 +70,7 @@ QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; bool indexValid( const QModelIndex &index ) const; QString driveName( const QModelIndex &index ) const; - QString displayString( const QModelIndex &index ) const; + QVariant displayString( const QModelIndex &index ) const; private: QStringList mFindResult; diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmdrivewatcher/private/symbian/fmdriveevent.cpp --- a/filemanager/src/inc/fmdrivewatcher/private/symbian/fmdriveevent.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmdrivewatcher/private/symbian/fmdriveevent.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -18,8 +18,8 @@ // INCLUDE FILES +#include "fmdriveevent.h" #include -#include "fmdriveevent.h" #include "fmcommon.h" #include diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmfileiconprovider.cpp --- a/filemanager/src/inc/fmfileiconprovider.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmfileiconprovider.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -38,7 +38,7 @@ #define usbMemoryIcon "qtg_large_usb_memory" //TODO: UI_Update: mmcl locked icon have not provided in icon spec -// Just use orignal custom-defined icon +// Just use original custom-defined icon #define mmcLockedIcon ":image/qgn_prop_mmc_locked.svg" @@ -95,10 +95,10 @@ case FmDriverInfo::EDriveTypePhoneMemory: retIcon = HbIcon( phoneMemoryIcon ).qicon(); break; - default: - Q_ASSERT_X( false, "FmFileIconProvider::icon", "please handle drive type"); + case FmDriverInfo::EDriveTypeNotExist: // drive not exist, let QFileIconProvider to judge icon + default: // filemanger do not provide icon for other drive types, let QFileIconProvider to judge icon break; - } + } break; } case FmFileTypeRecognizer::FileTypeFolder: @@ -167,8 +167,6 @@ } // if cannot get icon, return icon from QFileIconProvider - // this will be mostly used in win32 platform, - // because path for HbIcon only existed in hb theme of symbian if( retIcon.isNull() ) { retIcon = QFileIconProvider::icon( info ); } diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmfiletyperecognizer.h --- a/filemanager/src/inc/fmfiletyperecognizer.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmfiletyperecognizer.h Thu Sep 02 20:16:57 2010 +0300 @@ -16,8 +16,8 @@ * The header file of the file type recognizer */ -#ifndef FMFILERECOGNIZER_H -#define FMFILERECOGNIZER_H +#ifndef FMFILETYPERECOGNIZER_H +#define FMFILETYPERECOGNIZER_H #include "fmcommon.h" #include @@ -63,5 +63,5 @@ QMap mFileExtensionMap; }; -#endif /* FMDRIVEDETAILSTYPE_H */ +#endif /* FMFILETYPERECOGNIZER_H */ diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmutils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filemanager/src/inc/fmutils.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -0,0 +1,412 @@ +/* +* 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: +* Zhiqiang Yang +* +* Description: +* The source file of the file manager utilities +*/ + +#include "fmutils.h" + +#include +#include + +#include + +/*! + Used to get drive type for convenience. +*/ +FmDriverInfo::DriveType FmDriverInfo::driveType() +{ + FmDriverInfo::DriveType driveType; + if( mDriveState & FmDriverInfo::EDriveRemovable ) { + // if drive is removable, it may be mass, usb, or remote drive + 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 { + // if drive type is not recognized in previous condition, + // it should be an un-existed drive or phone memory + if( mDriveState & EDriveNotPresent ){ + // if come here, means 2 conditions: + // 1 this drive is not exist( FmUtils::queryDriverInfo will give EDriveNotPresent to mDriveState ) + // 2 un-mounted removable drive + // removable drive filted in previous condifiton. So, give EDriveTypeNotExist + driveType = FmDriverInfo::EDriveTypeNotExist; + } else { + // drive is existed, only remain the type of EDriveTypePhoneMemory + driveType = FmDriverInfo::EDriveTypePhoneMemory; + } + } + + return driveType; +} + +/*! + return drive name for \a path +*/ +QString FmUtils::getDriveNameFromPath( const QString &path ) +{ + // fillPathWithSplash make sure path length will be at least 3 if it is not empty. + QString checkedPath( fillPathWithSplash( path ) ); + if( checkedPath.length() < 3 ) { + return QString(); + } + return checkedPath.left( 3 ); +} + +/*! + return drive letter for \a path +*/ +QString FmUtils::getDriveLetterFromPath( const QString &path ) +{ + if( path.length() <2 ) { + return QString(); + } + return path.left( 1 ); +} + +/*! + return formatted string for size. +*/ +QString FmUtils::formatStorageSize( quint64 size ) +{ + if ( size < 1000 ) { + return QString::number( size ) + " B"; + } else if ( size < 1000 * 1000 ) { + return QString::number( size / 1024.0, 'f', 2 ) + " KB"; + } else if ( size < 1000 * 1000 * 1000 ) { + return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; + } else { + return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; + } +} + +/*! + Judge if a path is drive path, not a folder or a file. + For example, true for C:\ while false for C:\data +*/ +bool FmUtils::isDrive( const QString &path ) +{ + bool ret( false ); + if( path.length() <= 3 && path.length() >=2 ) { + ret = true; + } + + return ret; +} + +/*! + All "/" and "\" in \a path will be changed to QDir::separator + \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end +*/ +QString FmUtils::formatPath( const QString &path ) +{ + QString formatPath; + if( path.isEmpty() ) { + return formatPath; + } + + foreach( const QChar &ch, path ) { + if( ch == QChar('\\') || ch == QChar('/') ) { + formatPath.append( QDir::separator() ); + } else { + formatPath.append( ch ); + } + } + + return formatPath; +} + +/*! + Fill splash in the end of \a filePath. And all "/" and "\" will be changed to QDir::separator + Please do not call this function if path is a file. + Use \a formatPath instead, \a formatPath will not append QDir::separator in the end. + \sa formatPath only changed "/" and "\" to QDir::separator +*/ +QString FmUtils::fillPathWithSplash( const QString &filePath ) +{ + QString newFilePath; + if( filePath.isEmpty() ) { + return newFilePath; + } + + newFilePath = formatPath( filePath ); + + if( newFilePath.right( 1 )!= QDir::separator() ){ + newFilePath.append( QDir::separator() ); + } + return newFilePath; +} + +/*! + Remove splash in the end of \a filePath. +*/ +QString FmUtils::removePathSplash( const QString &filePath ) +{ + QString newFilePath( filePath ); + if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) { + newFilePath = filePath.left( filePath.length() - 1 ); + } + return newFilePath; +} + +/*! + fill \a driveList of drives can be shown in driveListView +*/ +void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ) +{ + if( isHideUnAvailableDrive ) { + FM_LOG( QString( "getDriveList HideUnAvailableDrive_true" ) ); + } else { + FM_LOG( QString( "getDriveList HideUnAvailableDrive_false" ) ); + } + QFileInfoList infoList = QDir::drives(); + + foreach( const QFileInfo &fileInfo, infoList ) { + QString driveName = fileInfo.absolutePath(); + if( checkDriveAccessFilter( driveName ) ) { + if( !isHideUnAvailableDrive ) { + driveList.append( driveName ); + } + else if ( isDriveAvailable( driveName ) ) { + driveList.append( driveName ); + } + } + } + return; +} + +/*! + return the combined string of drive name and volume( e.g. C: Phone memory for C drive) + \a driveName the drive name. + If set \a isFillWithDefaultVolume true, fill result with default volume if drive volume is empty. +*/ +QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) +{ + QString ret; + if( driveName.isEmpty() ) { + return ret; + } + QString tempDriveName = fillPathWithSplash( driveName ); + + QString checkedDriveName( removePathSplash( driveName ) ); + + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); + QString volumeName = driverInfo.volumeName(); + + if( volumeName.isEmpty() && isFillWithDefaultVolume ){ + 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; + case FmDriverInfo::EDriveTypeNotExist:// no such drive + default:// do not need get volume for other drive types, e.g. Ram, Rom + break; + } + } + + if( ret.isEmpty() ) { + // 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 the default volume for drive + \a driveName the drive. + \sa getVolumeNameWithDefaultNameIfNull +*/ +QString FmUtils::getDefaultVolumeName( const QString &driveName ) +{ + QString defaultVolumeName; + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName ); + + switch ( driverInfo.driveType() ) + { + case FmDriverInfo::EDriveTypeMassStorage: + defaultVolumeName = hbTrId("Mass storage"); + break; + case FmDriverInfo::EDriveTypeUsbMemory: + defaultVolumeName = hbTrId("USB memory"); + break; + case FmDriverInfo::EDriveTypeMemoryCard: + defaultVolumeName = hbTrId("Memory card"); + break; + case FmDriverInfo::EDriveTypePhoneMemory: + defaultVolumeName = hbTrId("Device memory"); + break; + case FmDriverInfo::EDriveTypeNotExist:// no such drive, break and return empty string + default:// do not have default volume for other drive types, e.g. Ram, Rom + break; + } + return defaultVolumeName; +} + +/*! + get the volume name of the drive, if it is null, then return the default name. + \a driveName the drive letter. + \a defaultName whether it is the default name. + return the volume name. +*/ +QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &driveName, bool &defaultName ) +{ + // do not re-use FmUtils::getDefaultVolumeName to save one time for call FmUtils::queryDriverInfo + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName ); + + 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() ) { + 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; + case FmDriverInfo::EDriveTypeNotExist:// no such drive + default:// do not need get volume for other drive types, e.g. Ram, Rom + break; + } + if( !volumeName.isEmpty() ) { + defaultName = true; + } + } + return volumeName; +} + +/*! + Check if two path are the same. +*/ +bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast ) +{ + QString fst( fillPathWithSplash( pathFst ) ); + QString last( fillPathWithSplash( pathLast ) ); + if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) { + return true; + } + return false; +} + +/*! + Check if a name is illegal for folder/file naming rule. +*/ +bool FmUtils::checkFolderFileName( const QString& name ) +{ + // trim space firest, because there may be some spaces after "." , it is also not valid + QString trimmedName( name.trimmed() ); + if( trimmedName.isEmpty() ) { + return false; + } + if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { + return false; + } + if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('?'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('<'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('>'), Qt::CaseInsensitive ) || + trimmedName.contains( QChar('|'), Qt::CaseInsensitive ) ){ + return false; + } + // use original name to exam max size of file name + if( name.length() > getMaxFileNameLength() ) { + return false; + } + return true; +} + +/*! + check file or folder path is illegal or not. + \a fileName file/folder name, used to check illegal characters + \a path file/folder path, used to check if path is available to use. + \a errString if return false, errString will be set for error note. + return true for not illegal and false for illegal path. +*/ +bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString ) +{ + // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last + QFileInfo fileInfo( path ); + bool ret( true ); + if (!FmUtils::checkFolderFileName( fileName ) ) { + errString = hbTrId( "Invalid file or folder name!" ); + ret = false; + } else if( !FmUtils::checkMaxPathLength( path ) ) { + errString = hbTrId( "the path you specified is too long!" ); + ret = false; + } else if (fileInfo.exists()) { + errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() ); + ret = false; + } + return ret; +} + +/*! + 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; +} diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmutils.h --- a/filemanager/src/inc/fmutils.h Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmutils.h Thu Sep 02 20:16:57 2010 +0300 @@ -23,6 +23,10 @@ #include +/*! + \class FmDriverInfo + \brief The class FmDriverInfo provide drive info data + */ class FmDriverInfo { public: @@ -58,6 +62,7 @@ */ enum DriveType { + EDriveTypeNotExist = -1, // specified drive is not existed in device EDriveTypeRom, EDriveTypeRam, EDriveTypePhoneMemory, @@ -85,13 +90,36 @@ this->mDriveState = rhs.mDriveState; return *this; } - + + /*! + Total size for drive + */ quint64 size() const { return mSize; } + + /*! + Free size for drive + */ quint64 freeSize() const { return mFreeSize; } + + /*! + path for drive + */ QString name() const { return mName; } + + /*! + volume for drive + */ QString volumeName() const { return mVolumeName; } + + /*! + status for drive + */ DriveState driveState() const { return mDriveState; } - FmDriverInfo::DriveType driveType(); + + /*! + drive type + */ + DriveType driveType(); private: quint64 mSize; @@ -103,70 +131,80 @@ }; Q_DECLARE_OPERATORS_FOR_FLAGS( FmDriverInfo::DriveState ) +/*! + \class FmUtils + \brief The class FmUtils provide util functions + This class is implemented by three parts: + fmutils.cpp for Qt Based functions + fmutils_s60.cpp is symbian implement version for platform based functions + fmutils_win.cpp is win32 implement version for platform based functions( a simple wrapper ) + */ class FmUtils { public: - static QString getDriveNameFromPath( const QString &path ); - static QString getDriveLetterFromPath( const QString &path ); + ////////////////////////////////////////////////////////////////// + // + static QString getDriveNameFromPath( const QString &path ); + static QString getDriveLetterFromPath( const QString &path ); + static QString formatStorageSize( quint64 size ); + static bool isDrive( const QString &path ); + static QString formatPath( const QString &path ); + static QString fillPathWithSplash( const QString &filePath ); + static QString removePathSplash( const QString &filePath ); + static void getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ); + static QString fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ); + static QString getDefaultVolumeName( const QString &driveName ); + static QString getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ); + static bool isPathEqual( const QString &pathFst, const QString &pathLast ); + static bool checkFolderFileName( const QString& name ); + static bool checkNewFolderOrFile( const QString& fileName, const QString &path, QString &errString ); + static bool isSubLevelPath( const QString &src, const QString &dest ); + // + ////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////// + // static FmDriverInfo queryDriverInfo( const QString &driverName ); - static QString formatStorageSize( quint64 size ); - static int removeDrivePwd( const QString &driverName, const QString &Pwd ); - static int unlockDrive( const QString &driverName, const QString &Pwd ); - static int checkDrivePwd( const QString &driverName, const QString &pwd); - static int setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd); - static void emptyPwd( QString &pwd ); - static int renameDrive( const QString &driverName, const QString &newVolumeName); - static int ejectDrive( const QString &driverName ); - static QString getFileType( const QString &filePath ); - static quint64 getDriveDetailsResult( const QString &folderPath, const QString &extension ); - static bool isDriveC( const QString &driverName ); - static bool isDrive( const QString &path ); - static void createDefaultFolders( const QString &driverName ); - static QString fillPathWithSplash( const QString &filePath ); - static QString removePathSplash( const QString &filePath ); - static QString formatPath( const QString &path ); - static bool checkDriveAccessFilter( const QString &driveName ); - static QString checkDriveToFolderFilter( const QString &path ); - static QString checkFolderToDriveFilter( const QString &path ); - static int isPathAccessabel( const QString &path ); - static bool isDriveAvailable( const QString &path ); - static bool isPathEqual( const QString &pathFst, const QString &pathLast ); - - /// fill driveList of drives can be shown in driveListView - static void getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ); - static QString fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ); - - static int launchFile( const QString &filePath ); - static void sendFiles( QStringList &filePathList ); - static QString getBurConfigPath( QString appPath ); - static bool isDefaultFolder( const QString &folderPath ); - static QString Localize( const QString &path ); + + // password related functions + static int removeDrivePwd( const QString &driverName, const QString &Pwd ); + static int unlockDrive( const QString &driverName, const QString &Pwd ); + static int checkDrivePwd( const QString &driverName, const QString &pwd); + static int setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd); + static void emptyPwd( QString &pwd ); + + // external drive related functions + static int renameDrive( const QString &driverName, const QString &newVolumeName); + static int ejectDrive( const QString &driverName ); + + // drive security related functions + static bool checkDriveAccessFilter( const QString &driveName ); + static QString checkDriveToFolderFilter( const QString &path ); + static QString checkFolderToDriveFilter( const QString &path ); + static int isPathAccessabel( const QString &path ); + static bool isDriveAvailable( const QString &path ); - static int getMaxFileNameLength(); - static bool checkMaxPathLength( const QString& path ); - static bool checkFolderFileName( const QString& name ); - - /** - * check file or folder path is illegal or not. - * - * @param fileName file/folder name, used to check illegal characters - * @param path file/folder path, used to check if path is available to use. - * @param errString if return false, errString will be set for error note. - * @return true for not illegal and false for illegal path. - */ - static bool checkNewFolderOrFile( const QString& fileName, const QString &path, QString &errString ); - - /* - * get the volume name of the disk, if it is null, then return the default name. - * @param diskName the driver letter. - * @param defaultName whether it is the default name. - * @return the volume name. - */ - 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 ); + // system default folder related functions + static bool isDefaultFolder( const QString &folderPath ); + static void createDefaultFolders( const QString &driverName ); + static QString localize( const QString &path ); + + // copy move related functions + static int setFileAttributes( const QString &srcFile, const QString &desFile ); + static bool hasEnoughSpace( const QString &targetDrive, qint64 size ); + static int moveInsideDrive( const QString &source, const QString &target ); + + // other fucntions + static int launchFile( const QString &filePath ); + static void sendFiles( QStringList &filePathList ); + static QString getBurConfigPath( QString appPath ); + static QString getFileType( const QString &filePath ); + static bool isDriveC( const QString &driverName ); + static int getMaxFileNameLength(); + static bool checkMaxPathLength( const QString& path ); + // + ////////////////////////////////////////////////////////////////// }; #endif diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmutils_s60.cpp --- a/filemanager/src/inc/fmutils_s60.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmutils_s60.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -13,99 +13,57 @@ * Zhiqiang Yang * * Description: -* The source file of the file manager utilities +* The source file of the file manager utilities on Symbian */ #include "fmutils.h" +#include "fmcommon.h" #include "fms60utils.h" -#include "fmcommon.h" -#include - +#include +#include +#include #include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include + #include #include -#include +#include +#include +#include + +#include #include -#include - #include -#include #include +#include +#include #define BURCONFIGFILE "z:/private/2002BCC0/burconfig.xml" - /*! - Used to get drive type for convenience. + query drive info and status for \a driveName + return \a FmDriverInfo */ -FmDriverInfo::DriveType FmDriverInfo::driveType() +FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName ) { - 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. - QString checkedPath( fillPathWithSplash( path ) ); - if( checkedPath.length() < 3 ) { - return QString(); - } - return checkedPath.left( 3 ); -} - -QString FmUtils::getDriveLetterFromPath( const QString &path ) -{ - if( path.length() <2 ) { - return QString(); - } - return path.left( 1 ); -} - -FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName ) -{ - if( driverName.isEmpty() ) { - return FmDriverInfo( 0, 0, driverName, QString(), FmDriverInfo::EDriveNotPresent ); + if( driveName.isEmpty() ) { + return FmDriverInfo( 0, 0, driveName, QString(), FmDriverInfo::EDriveNotPresent ); } CCoeEnv *env = CCoeEnv::Static(); RFs& fs = env->FsSession(); TVolumeInfo volumeInfo; TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; quint32 state( 0 ); + int volumeInfoErr( KErrNone ); int driveInfoErr( KErrNone ); int errorCode( KErrNone ); @@ -133,7 +91,6 @@ if ( ( drvStatus & DriveInfo::EDriveInternal ) && ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){ // Handle mass storage bits here - state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable; } @@ -224,34 +181,25 @@ state |= FmDriverInfo::EDriveNotPresent; break; } - QString logString ( "FmUtils::queryDriverInfo_" + driverName + + QString logString ( "FmUtils::queryDriverInfo_" + driveName + "_volumeInfoErr:" + QString::number( volumeInfoErr ) + "_driveInfoErr:" + QString::number( driveInfoErr ) + "_errorCode:" + QString::number( errorCode ) + "_driveSatus:" + QString::number( state ) ); FM_LOG( logString ); - return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driverName, volumeName, state ); + return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driveName, volumeName, state ); } -QString FmUtils::formatStorageSize( quint64 size ) +/*! + remove drive password for \a driveName + \a Pwd is original password. +*/ +int FmUtils::removeDrivePwd( const QString &driveName, const QString &Pwd ) { - if ( size < 1000 ) { - return QString::number( size ) + " B"; - } else if ( size < 1000 * 1000 ) { - return QString::number( size / 1024.0, 'f', 2 ) + " KB"; - } else if ( size < 1000 * 1000 * 1000 ) { - return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; - } else { - return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; - } -} - -int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd ) -{ - if( driverName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { + if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } - QString logString = "Drive name:" + driverName; + QString logString = "Drive name:" + driveName; FM_LOG( logString ); logString = "Password:" + Pwd; FM_LOG( logString ); @@ -261,7 +209,7 @@ TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; HBufC* password16 = XQConversions::qStringToS60Desc( Pwd ); TMediaPassword password; @@ -289,12 +237,15 @@ } } -int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd ) +/*! + Unlock drive \a driveName with provided password \a Pwd +*/ +int FmUtils::unlockDrive( const QString &driveName, const QString &Pwd ) { - if( driverName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { + if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } - QString logString = "Drive name:" + driverName; + QString logString = "Drive name:" + driveName; FM_LOG( logString ); logString = "Password:" + Pwd; FM_LOG( logString ); @@ -303,7 +254,7 @@ RFs& fs = env->FsSession(); TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; HBufC* password16 = XQConversions::qStringToS60Desc( Pwd ); TMediaPassword password; @@ -336,25 +287,31 @@ } } -int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd ) +/*! + Check if \a pwd is the right password for drive \a driveName +*/ +int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd ) { - if( driverName.isEmpty() || pwd.length() > FmMaxLengthofDrivePassword ) { + if( driveName.isEmpty() || pwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } - QString logString = "checkDrivePwd Drive name:" + driverName; + QString logString = "checkDrivePwd Drive name:" + driveName; logString += " password:" + pwd; FM_LOG( logString ); - return setDrivePwd( driverName, pwd, pwd ); + return setDrivePwd( driveName, pwd, pwd ); } -int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd) +/*! + Set new password \a newPwd for drive \a driveName. \a oldPwd is old password +*/ +int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd) { - if( driverName.isEmpty() || + if( driveName.isEmpty() || oldPwd.length() > FmMaxLengthofDrivePassword || newPwd.length() > FmMaxLengthofDrivePassword ) { return FmErrWrongParam; } - QString logString = "setDrivePwd Drive name:" + driverName ; + QString logString = "setDrivePwd Drive name:" + driveName ; logString += " Old password:" + oldPwd; logString += " New password:" + newPwd; FM_LOG( logString ); @@ -363,7 +320,7 @@ RFs& fs = env->FsSession(); TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; HBufC* newPassword16 = XQConversions::qStringToS60Desc( newPwd); HBufC* oldPassword16 = XQConversions::qStringToS60Desc( oldPwd ); @@ -397,6 +354,9 @@ } } +/*! + Set \a pwd as empty password +*/ void FmUtils::emptyPwd( QString &pwd ) { TBuf< FmMaxLengthofDrivePassword > nullPwd; @@ -405,9 +365,12 @@ pwd = XQConversions::s60DescToQString( nullPwd ); } -int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName) +/*! + Set drive volume for drive \a driveName +*/ +int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName) { - if( driverName.isEmpty() ) { + if( driveName.isEmpty() ) { return FmErrWrongParam; } foreach( const QChar &ch, newVolumeName ) @@ -425,7 +388,7 @@ RFs& fs = env->FsSession(); TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; TPtr newName ( ( XQConversions::qStringToS60Desc( newVolumeName ) )->Des() ); @@ -445,16 +408,19 @@ } } -int FmUtils::ejectDrive( const QString &driverName ) +/*! + Eject drive \a driveName +*/ +int FmUtils::ejectDrive( const QString &driveName ) { - if( driverName.isEmpty() ) { + if( driveName.isEmpty() ) { return FmErrWrongParam; } QString logString = "FmUtils::ejectDrive start"; FM_LOG( logString ); TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; const int KDriveShift = 16; @@ -467,119 +433,166 @@ return FmErrNone; } -QString FmUtils::getFileType( const QString &filePath ) +/*! + Check if drive \a driveName is accessable for user +*/ +bool FmUtils::checkDriveAccessFilter( const QString &driveName ) +{ + if( driveName.isEmpty() ) { + return false; + } + FmDriverInfo driveInfo = queryDriverInfo( driveName ); + if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) || + ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) { + return false; + } + return true; +} + +/*! + This function should be called to adjust path if user goto a drive. + data folder will be append to C:\ becuase user could only view C:\data instead C:\ +*/ +QString FmUtils::checkDriveToFolderFilter( const QString &path ) { - RApaLsSession apaSession; - TDataType dataType; - TUid appUid; - - TBuf<128> mimeTypeBuf; - - int err = apaSession.Connect(); + QString checkedPath = fillPathWithSplash( path ); + if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) { + checkedPath += QString( "data" ) + QDir::separator(); + return checkedPath; + } + return path; + +} + +/*! + This function should be called to adjust path if user back to up level path. + If user is at C:\data then path level should be returned as C:\ + Becuase C:\data is root path for C drive +*/ +QString FmUtils::checkFolderToDriveFilter( const QString &path ) +{ + QString logString; + logString = QString( "checkFolderToDriveFilter: " ) + path; + FM_LOG( logString ); + QString checkedPath = fillPathWithSplash( path ); + + logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath; + FM_LOG( logString ); - if ( err == KErrNone ){ - err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), - appUid, dataType ); - - if( err == KErrNone ){ - mimeTypeBuf.Copy(dataType.Des8()); - } + if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) { + FM_LOG( QString( " change from c:/data/ to C:/" ) ); + return Drive_C; } - - apaSession.Close(); - return XQConversions::s60DescToQString( mimeTypeBuf ); + return path; + } -quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension ) +/*! + Check if \a path is accessable for user +*/ +int FmUtils::isPathAccessabel( const QString &path ) { - int err; - - RFs fs; - err = fs.Connect(); - - QString string( fillPathWithSplash( folderPath ) ); + // Used to check if path is accessable, very important feature + // and will return filemanager error. + FM_LOG( QString( "isPathAccessabel:" ) + path ); + if( path.isEmpty() ) { + return FmErrPathNotExist; + } - TPtrC desFolderPath( XQConversions::qStringToS60Desc( string )->Des() ); - TPtrC ptrExtension( XQConversions::qStringToS60Desc( extension )->Des() ); - - CDir* results = 0; - TParse parse; - - quint64 size = 0; - - const TInt pathlength = ptrExtension.Length() + desFolderPath.Length(); - - if ( pathlength > KMaxFileName ){ - err = KErrNotFound; + // used to filter locked/ejected/corrupted drive + // check if drive is available, no matter if it is a drive, a folder, or a file. + if( !isDriveAvailable( path ) ) { + FM_LOG( QString( "isPathAccessabel false: path is drive and not available" ) ); + return FmErrDriveNotAvailable; } - else{ - err = fs.Parse( ptrExtension, desFolderPath, parse ); - err = fs.GetDir( parse.FullName(), KEntryAttMaskSupported|KEntryAttAllowUid, - ESortNone, results ); - - TDesC des = parse.FullName(); - - if (err == KErrNotFound) - { - return 0; - } - } - - if ( results ){ - CleanupStack::PushL(results); + + QFileInfo fileInfo( path ); - // Go through all files in the list and tell subclass - TFileName file; - const TInt count = results->Count(); - for( TInt i=0; i=2 ) { - ret = true; - } - - return ret; + HBufC *path = XQConversions::qStringToS60Desc( folderPath ); + TPtrC desFolderPath( path->Des() ); + + bool ret( true ); + TInt pathType( PathInfo::PathType( desFolderPath ) ); + switch( pathType ){ + case PathInfo::ENotSystemPath:{ + QString locString( localize( folderPath ) ); + if ( locString.isEmpty() ){ + ret = false; + break; + } + ret = true; + break; + } + case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH + case PathInfo::EMemoryCardRootPath: // FALL THROUGH + case PathInfo::ERomRootPath:{ + ret = false; + break; + } + // Accept other folders + default:{ + ret = true; + break; + } + } + delete path; + return ret; } -void FmUtils::createDefaultFolders( const QString &driverName ) +/*! + Create system default folders for drive \a driveName. + Default folders should be created after format a drive. +*/ +void FmUtils::createDefaultFolders( const QString &driveName ) { - if( driverName.isEmpty() ) { + if( driveName.isEmpty() ) { return; } int err; TInt drive = 0; - drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; RFs fs; err = fs.Connect(); @@ -643,440 +656,17 @@ } /*! - 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 + In Symbian system, default folders will be localized. + So localize is used to check if a path is a default folder + \sa isDefaultFolder */ -QString FmUtils::fillPathWithSplash( const QString &filePath ) -{ - QString newFilePath; - if( filePath.isEmpty() ) { - return newFilePath; - } - - newFilePath = formatPath( filePath ); - - if( newFilePath.right( 1 )!= QDir::separator() ){ - newFilePath.append( QDir::separator() ); - } - return newFilePath; -} - -QString FmUtils::removePathSplash( const QString &filePath ) -{ - QString newFilePath( filePath ); - if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) { - newFilePath = filePath.left( filePath.length() - 1 ); - } - return newFilePath; -} - -// filter un-accessable drive -bool FmUtils::checkDriveAccessFilter( const QString &driveName ) -{ - if( driveName.isEmpty() ) { - return false; - } - FmDriverInfo driveInfo = queryDriverInfo( driveName ); - if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) || - ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) { - return false; - } - return true; -} - -QString FmUtils::checkDriveToFolderFilter( const QString &path ) -{ - /* - QFileInfo fileInfo( path ); - if( !fileInfo.exists() ) { - return QString(); - } - */ - QString checkedPath = fillPathWithSplash( path ); - if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) { - checkedPath += QString( "data" ) + QDir::separator(); - return checkedPath; - } - return path; - -} - -QString FmUtils::checkFolderToDriveFilter( const QString &path ) -{ - QString logString; - logString = QString( "checkFolderToDriveFilter: " ) + path; - FM_LOG( logString ); - QString checkedPath = fillPathWithSplash( path ); - - logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath; - FM_LOG( logString ); - - if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) { - FM_LOG( QString( " change from c:/data/ to C:/" ) ); - return Drive_C; - } - return path; - -} - -int FmUtils::isPathAccessabel( const QString &path ) -{ - // Used to check if path is accessable, very important feature - // and will return filemanager error. - FM_LOG( QString( "isPathAccessabel:" ) + path ); - if( path.isEmpty() ) { - return FmErrPathNotExist; - } - - // used to filter locked/ejected/corrupted drive - // check if drive is available, no matter if it is a drive, a folder, or a file. - if( !isDriveAvailable( path ) ) { - FM_LOG( QString( "isPathAccessabel false: path is drive and not available" ) ); - return FmErrDriveNotAvailable; - } - - QFileInfo fileInfo( path ); - if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) && - !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) { - FM_LOG( QString( "isPathAccessabel false: path contain C and not in data folder" ) ); - return FmErrPathDenied; - } - if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){ - return FmErrDriveDenied; - } - if( !fileInfo.exists() ) { - FM_LOG( QString( "isPathAccessabel false: path not exist" ) ); - return FmErrPathNotExist; - } - FM_LOG( QString( "isPathAccessabel FmErrNone" ) ); - return FmErrNone; -} - -// only used to check drive, when MMC is not inserted, also return false -bool FmUtils::isDriveAvailable( const QString &path ) -{ - FM_LOG( QString( "isDriveAvailable:" ) + path ); - if( path.isEmpty() ) { - return false; - } - FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState(); - if( ( driveState & FmDriverInfo::EDriveAvailable ) ) { - FM_LOG( QString( "isDriveAvailable true" ) ); - return true; - } - FM_LOG( QString( "isDriveAvailable false" ) ); - return false; -} - -void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ) -{ - if( isHideUnAvailableDrive ) { - FM_LOG( QString( "getDriveList HideUnAvailableDrive_true" ) ); - } else { - FM_LOG( QString( "getDriveList HideUnAvailableDrive_false" ) ); - } - QFileInfoList infoList = QDir::drives(); - - foreach( QFileInfo fileInfo, infoList ) { - QString driveName = fileInfo.absolutePath(); - if( checkDriveAccessFilter( driveName ) ) { - if( !isHideUnAvailableDrive ) { - driveList.append( driveName ); - } - else if ( isDriveAvailable( driveName ) ) { - driveList.append( driveName ); - } - } - } - 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; - if( driveName.isEmpty() ) { - return ret; - } - QString tempDriveName = fillPathWithSplash( driveName ); - - QString checkedDriveName( removePathSplash( driveName ) ); - - FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); - QString volumeName = driverInfo.volumeName(); - - if( volumeName.isEmpty() && isFillWithDefaultVolume ){ - 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() ) { - // 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 ) +QString FmUtils::localize( const QString &path ) { - 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 ); - if( !file.exists() ) { - return false; - } - - XQApplicationManager mAiwMgr; - XQAiwRequest *request = mAiwMgr.create(file); - if ( request == 0 ) { - // No handlers for the URI - return FmErrUnKnown; - } - - // Set function parameters - QList args; - args << file.fileName(); - request->setArguments(args); - - // Send the request - bool res = request->send(); - if (!res) - { - // Request failed. - int error = request->lastError(); - - delete request; - return FmErrUnKnown; - } - - delete request; - return FmErrNone; -} - -void FmUtils::sendFiles( QStringList &filePathList ) -{ - ShareUi shareui; - shareui.send( filePathList, false ); -} - -QString FmUtils::getBurConfigPath( QString appPath ) -{ - Q_UNUSED( appPath ); - QString path( BURCONFIGFILE ); - return path; -} - -bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast ) -{ - QString fst( fillPathWithSplash( pathFst ) ); - QString last( fillPathWithSplash( pathLast ) ); - if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) { - return true; - } - return false; -} - -bool FmUtils::isDefaultFolder( const QString &folderPath ) -{ - TPtrC desFolderPath( XQConversions::qStringToS60Desc( folderPath )->Des() ); + // HbDirectoryNameLocalizer can not recognize path with \ in the end + QString locPath( removePathSplash( path ) ); - TInt pathType( PathInfo::PathType( desFolderPath ) ); - switch( pathType ){ - case PathInfo::ENotSystemPath:{ - QString locString( Localize( folderPath ) ); - if ( locString.isEmpty() ){ - return false; - } - return true; - } - case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH - case PathInfo::EMemoryCardRootPath: // FALL THROUGH - case PathInfo::ERomRootPath:{ - return false; - } - // Accept other folders - default:{ - return true; - } - } -} - -QString FmUtils::Localize( const QString &path ) -{ - QString locPath = fillPathWithSplash( path ); - - TPtrC desPath( XQConversions::qStringToS60Desc( locPath )->Des() ); - CDirectoryLocalizer *localizer = CDirectoryLocalizer::NewL(); - - localizer->SetFullPath( desPath ); - if( localizer->IsLocalized() ){ - return XQConversions::s60DescToQString( localizer->LocalizedName() ); - } - - 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() ); - } else { - formatPath.append( ch ); - } - } - - return formatPath; -} - -int FmUtils::getMaxFileNameLength() -{ - return KMaxFileName; -} - -bool FmUtils::checkMaxPathLength( const QString& path ) -{ - if( path.length() > KMaxPath ) { - return false; - } - return true; -} - -bool FmUtils::checkFolderFileName( const QString& name ) -{ - // trim space firest, because there may be some spaces after "." , it is also not valid - QString trimmedName( name.trimmed() ); - if( trimmedName.isEmpty() ) { - return false; - } - if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { - return false; - } - if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('?'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('<'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('>'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('|'), Qt::CaseInsensitive ) ){ - return false; - } - // use orignal name to exam max size of file name - if( name.length() > KMaxFileName ) { - return false; - } - return true; -} - -bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString ) -{ - // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last - QFileInfo fileInfo( path ); - bool ret( true ); - if (!FmUtils::checkFolderFileName( fileName ) ) { - errString = hbTrId( "Invalid file or folder name!" ); - ret = false; - } else if( !FmUtils::checkMaxPathLength( path ) ) { - errString = hbTrId( "the path you specified is too long!" ); - ret = false; - } else if (fileInfo.exists()) { - errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() ); - ret = false; - } - return ret; -} - -/*! - 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; + HbDirectoryNameLocalizer localizer; + return localizer.translate( locPath ); } /*! @@ -1111,3 +701,159 @@ CleanupStack::PopAndDestroy(); // fsSession return err; } + +/*! + judge whether there is enough space on \a targetDrive for \a size. + return true if has, false if not. +*/ +bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size ) +{ + RFs fsSession; + QT_TRAP_THROWING( fsSession.Connect() ); + CleanupClosePushL( fsSession ); + TInt dstDrv(0); + HBufC* hbuf = XQConversions::qStringToS60Desc( targetDrive ); + QT_TRAP_THROWING( RFs::CharToDrive( hbuf->operator [](0), dstDrv ) ); + bool ret = !SysUtil::DiskSpaceBelowCriticalLevelL( &fsSession, size , dstDrv ); + CleanupStack::PopAndDestroy(); // fsSession + return ret; + +} + +/*! + move one file insice the same drive, from \a source to \a target. + return KErrNone if successful, otherwise one of the other system-wide error codes. +*/ +int FmUtils::moveInsideDrive( const QString &source, const QString &target ) +{ + RFs fsSession; + QT_TRAP_THROWING( fsSession.Connect() ); + CleanupClosePushL( fsSession ); + HBufC* oldName = XQConversions::qStringToS60Desc( source ); + HBufC* newName = XQConversions::qStringToS60Desc( target ); + int ret = fsSession.Rename( *oldName, *newName ); + CleanupStack::PopAndDestroy(); // fsSession + return ret; +} + +/*! + Launch a file with associated application. +*/ +int FmUtils::launchFile( const QString &filePath ) + +{ + QFile file( filePath ); + if( !file.exists() ) { + return false; + } + + XQApplicationManager mAiwMgr; + XQAiwRequest *request = mAiwMgr.create(file); + if ( request == 0 ) { + // No handlers for the URI + return FmErrUnKnown; + } + + // Set function parameters + QList args; + args << file.fileName(); + request->setArguments(args); + + // Send the request + bool res = request->send(); + if (!res) + { + // Request failed. + int error = request->lastError(); + + delete request; + return FmErrUnKnown; + } + + delete request; + return FmErrNone; +} + +/*! + Send files( \a filePathList ) with share ui. +*/ +void FmUtils::sendFiles( QStringList &filePathList ) +{ + ShareUi shareui; + shareui.send( filePathList, false ); +} + +/*! + return path for backup restore config file. + Currently \a appPath is not used. +*/ +QString FmUtils::getBurConfigPath( QString appPath ) +{ + Q_UNUSED( appPath ); + QString path( BURCONFIGFILE ); + return path; +} + +/*! + return MetaData string for \a filePath +*/ +QString FmUtils::getFileType( const QString &filePath ) +{ + RApaLsSession apaSession; + TDataType dataType; + TUid appUid; + + TBuf<128> mimeTypeBuf; + + int err = apaSession.Connect(); + + if ( err == KErrNone ){ + err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), + appUid, dataType ); + + if( err == KErrNone ){ + mimeTypeBuf.Copy(dataType.Des8()); + } + } + + apaSession.Close(); + return XQConversions::s60DescToQString( mimeTypeBuf ); +} + +/*! + Check if drive \a driveName is drive C +*/ +bool FmUtils::isDriveC( const QString &driveName ) +{ + if( driveName.isEmpty() ) { + return false; + } + TInt drive = 0; + drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA; + if( drive == EDriveC ){ + return true; + } + else{ + return false; + } + +} + +/*! + return max file name length +*/ +int FmUtils::getMaxFileNameLength() +{ + return KMaxFileName; +} + +/*! + Check if length of \a path is exceed max path length. +*/ +bool FmUtils::checkMaxPathLength( const QString& path ) +{ + if( path.length() > KMaxPath ) { + return false; + } + return true; +} diff -r 060d0b1ab845 -r fc4654ce4fcb filemanager/src/inc/fmutils_win.cpp --- a/filemanager/src/inc/fmutils_win.cpp Wed Aug 18 09:39:39 2010 +0300 +++ b/filemanager/src/inc/fmutils_win.cpp Thu Sep 02 20:16:57 2010 +0300 @@ -16,14 +16,15 @@ * The source file of the file manager utilities on windows */ +#include "fmutils.h" + #include -#include "fmutils.h" #include +#include +#include #include #include -#include -#include #include @@ -31,39 +32,23 @@ const int KMaxFileName=0x100; const int KMaxPath=0x100; -QString FmUtils::getDriveNameFromPath( const QString &path ) -{ - if( path.length() <3 ) { - return QString(); - } - return path.left( 3 ); -} - -QString FmUtils::getDriveLetterFromPath( const QString &path ) -{ - if( path.length() <3 ) { - return QString(); - } - return path.left( 1 ); -} - -FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName ) +FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName ) { quint64 size = 0; quint64 freeSize = 0; - QString driver = driverName; + QString drive = driveName; - driver.replace( '/', "\\" ); - if ( driver.right(1) != "\\" ) { - driver.append( "\\" ); + drive.replace( '/', "\\" ); + if ( drive.right(1) != "\\" ) { + drive.append( "\\" ); } - GetDiskFreeSpaceEx( (LPCWSTR)driver.constData(), + GetDiskFreeSpaceEx( (LPCWSTR)drive.constData(), (PULARGE_INTEGER)&freeSize, (PULARGE_INTEGER)&size, 0 ); TCHAR volumeName[MAX_PATH + 1] = { 0 }; - GetVolumeInformation( (LPCWSTR)driver.constData(), + GetVolumeInformation( (LPCWSTR)drive.constData(), &volumeName[0], MAX_PATH + 1, 0, @@ -73,87 +58,42 @@ 0 ); quint32 state( 0 ); - quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); + quint32 drvStatus = GetDriveType( (LPCWSTR)drive.constData() ); if ( drvStatus == DRIVE_REMOVABLE ) { state |= FmDriverInfo::EDriveRemovable; } -#ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ - if ( driverName.contains( Drive_D, Qt::CaseInsensitive ) ) { - state |= FmDriverInfo::EDriveNotPresent; - } -#endif -#ifdef _DEBUG_LOCKED_DRIVE_Z - if ( driverName.contains( Drive_Z, Qt::CaseInsensitive ) ) { - state |= FmDriverInfo::EDriveLocked; - } -#endif if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) && !(state&FmDriverInfo::EDriveCorrupted) ) { state |= FmDriverInfo::EDriveAvailable; } - return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ), state ); -} - -QString FmUtils::formatStorageSize( quint64 size ) -{ - if ( size < 1000 ) { - return QString::number( size ) + " B"; - } else if ( size < 1000 * 1000 ) { - return QString::number( size / 1024.0, 'f', 2 ) + " KB"; - } else if ( size < 1000 * 1000 * 1000 ) { - return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB"; - } else { - return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB"; - } + return FmDriverInfo( size, freeSize, driveName, QString::fromWCharArray( &volumeName[0] ), state ); } -/* -quint32 FmUtils::getDriverState( const QString &driverName ) +int FmUtils::removeDrivePwd( const QString &driveName, const QString &Pwd ) { - quint32 state( 0 ); - - QString driver = driverName; - - driver.replace( '/', "\\" ); - if ( driver.right(1) != "\\" ) { - driver.append( "\\" ); - } - - quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() ); - - if ( drvStatus == DRIVE_REMOVABLE ) { - state |= FmDriverInfo::EDriveRemovable; - } - - return state; - -} -*/ -int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd ) -{ - Q_UNUSED( driverName ); + Q_UNUSED( driveName ); Q_UNUSED( Pwd ); return 0; } -int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd ) +int FmUtils::unlockDrive( const QString &driveName, const QString &Pwd ) { - Q_UNUSED( driverName ); + Q_UNUSED( driveName ); Q_UNUSED( Pwd ); return 0; } -int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd) +int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd) { - Q_UNUSED( driverName ); + Q_UNUSED( driveName ); Q_UNUSED( pwd ); return 0; } -int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd) +int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd) { - Q_UNUSED( driverName ); + Q_UNUSED( driveName ); Q_UNUSED( oldPwd ); Q_UNUSED( newPwd ); return 0; @@ -164,9 +104,9 @@ Q_UNUSED( pwd ); } -int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName) +int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName) { - Q_UNUSED( driverName ); + Q_UNUSED( driveName ); foreach( const QChar &ch, newVolumeName ) { // If not alphadigit or space, return error @@ -178,221 +118,85 @@ return 0; } -int FmUtils::ejectDrive( const QString &driverName ) -{ - Q_UNUSED( driverName ); - return FmErrNone; -} - -QString FmUtils::getFileType( const QString &filePath ) -{ - Q_UNUSED( filePath ); - return QString( "" ); -} - -quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension ) -{ - Q_UNUSED( folderPath ); - Q_UNUSED( extension ); - return 0; -} - -bool FmUtils::isDriveC( const QString &driverName ) -{ - if( driverName.contains(Drive_C,Qt::CaseInsensitive) ){ - return true; - } - else{ - return false; - } -} - -bool FmUtils::isDrive( const QString &path ) +int FmUtils::ejectDrive( const QString &driveName ) { - bool ret( false ); - if( path.length() <= 3 && path.length() >=2 ) { - ret = true; - } - - return ret; -} - -void FmUtils::createDefaultFolders( const QString &driverName ) -{ - 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; - if( filePath.isEmpty() ) { - return newFilePath; - } - - newFilePath = formatPath( filePath ); - - if( newFilePath.right( 1 )!= QDir::separator() ){ - newFilePath.append( QDir::separator() ); - } - return newFilePath; -} - -QString FmUtils::removePathSplash( const QString &filePath ) -{ - QString newFilePath( filePath ); - if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) { - newFilePath = filePath.left( filePath.length() - 1 ); - } - return newFilePath; + Q_UNUSED( driveName ); + return FmErrNone; } bool FmUtils::checkDriveAccessFilter( const QString &driveName ) { -#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ - if( driveName.contains( Drive_D, Qt::CaseInsensitive ) || driveName.contains( Drive_Z, Qt::CaseInsensitive ) ) { - return false; - } -#endif + Q_UNUSED( driveName ); return true; } QString FmUtils::checkDriveToFolderFilter( const QString &path ) { - QFileInfo fileInfo( path ); - if( !fileInfo.exists() ) { - return QString(); - } - -#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ - QString checkedPath = fillPathWithSplash( path ); - if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) { - checkedPath += QString( "data/" ); - QFileInfo fileInfo( checkedPath ); - if( !fileInfo.exists() ) { - return QString(); - } - return checkedPath; - } -#endif + Q_UNUSED( path ); return path; } QString FmUtils::checkFolderToDriveFilter( const QString &path ) { -#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ - QString logString; - logString = QString( "checkFolderToDriveFilter: " ) + path; - FM_LOG( logString ); - QString checkedPath = fillPathWithSplash( path ); - - logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath; - FM_LOG( logString ); - - if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) { - FM_LOG( QString( " change from c:/data/ to C:/" ) ); - return QString( "C:/" ); - } -#endif + Q_UNUSED( path ); return path; } int FmUtils::isPathAccessabel( const QString &path ) { - if(!isDriveAvailable( path ) ) { //used to filter locked drive - return FmErrDriveNotAvailable; - } - - QFileInfo fileInfo( path ); - -#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_ - if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) && - !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) { - return false; - } - if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) { - return false; - } - if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) { - return false; - } -#endif - if( !fileInfo.exists() ) { - return FmErrPathNotExist; - } + Q_UNUSED( path ); return FmErrNone; } bool FmUtils::isDriveAvailable( const QString &path ) { -#ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_ - if(path.contains(Drive_D, Qt::CaseInsensitive)) - return false; -#endif -#ifdef _DEBUG_LOCKED_DRIVE_Z - if(path.contains(Drive_Z, Qt::CaseInsensitive)) - return false; -#endif + Q_UNUSED( path ); return true; } -void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive ) +bool FmUtils::isDefaultFolder( const QString &folderPath ) { - QFileInfoList infoList = QDir::drives(); + Q_UNUSED( folderPath ); + return false; +} - foreach( QFileInfo fileInfo, infoList ) { - QString driveName = fileInfo.absolutePath(); - if( checkDriveAccessFilter( driveName ) ) { - if( !isHideUnAvailableDrive ) { - driveList.append( driveName ); - } - else if ( isDriveAvailable( driveName ) ) { - driveList.append( driveName ); - } - } - } - return; +void FmUtils::createDefaultFolders( const QString &driveName ) +{ + Q_UNUSED( driveName ); +} + +/*! + set the \a desFile attributes as the same with \a srcFile +*/ +int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile ) +{ + Q_UNUSED( srcFile ); + Q_UNUSED( desFile ); + return FmErrNone; } -QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume ) +/*! + judge whether there is enough space on \a targetDrive for \a size. + return true if has, false if not. +*/ +bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size ) { - QString ret; - QString tempDriveName = fillPathWithSplash( driveName ); - - QString checkedDriveName( removePathSplash( driveName ) ); - - FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName ); - QString volumeName = driverInfo.volumeName(); + Q_UNUSED( targetDrive ); + Q_UNUSED( size ); + return true; +} - 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 - ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName ); - } - } - } else { - ret = hbTrId( "txt_fmgr_dblist_1_2" ).arg( checkedDriveName ).arg( volumeName ); - } - return ret; +/*! + move one file insice the same drive, from \a source to \a target. + return KErrNone if successful, otherwise one of the other system-wide error codes. +*/ +int FmUtils::moveInsideDrive( const QString &source, const QString &target ) +{ + Q_UNUSED( source ); + Q_UNUSED( target ); + return FmErrNone; } int FmUtils::launchFile( const QString &filePath ) @@ -406,7 +210,7 @@ void FmUtils::sendFiles( QStringList &filePathList ) { - + Q_UNUSED( filePathList ); } QString FmUtils::getBurConfigPath( QString appPath ) @@ -419,139 +223,31 @@ return path; } -bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast ) +QString FmUtils::getFileType( const QString &filePath ) { - QString fst( fillPathWithSplash( pathFst ) ); - QString last( fillPathWithSplash( pathLast ) ); - if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) { - return true; - } - return false; -} - -bool FmUtils::isDefaultFolder( const QString &folderPath ) -{ - Q_UNUSED( folderPath ); - return false; + Q_UNUSED( filePath ); + 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 ) +bool FmUtils::isDriveC( const QString &driveName ) { - QString formatPath; - if( path.isEmpty() ) { - return formatPath; + if( driveName.contains(Drive_C,Qt::CaseInsensitive) ){ + return true; } - - foreach( QChar ch, path ) { - if( ch == QChar('\\') || ch == QChar('/') ) { - formatPath.append( QDir::separator() ); - } else { - formatPath.append( ch ); - } + else{ + return false; } - - return formatPath; } int FmUtils::getMaxFileNameLength() { - return KMaxFileName; + return KMaxFileName; } bool FmUtils::checkMaxPathLength( const QString& path ) { - if( path.length() > KMaxPath ) { - return false; - } - return true; -} - -bool FmUtils::checkFolderFileName( const QString& name ) -{ - // trim space firest, because there may be some spaces after "." , it is also not valid - // or there may only have spaces in name - QString trimmedName( name.trimmed() ); - if( trimmedName.isEmpty() ) { - return false; - } - if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { - return false; - } - if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('?'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('<'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('>'), Qt::CaseInsensitive ) || - trimmedName.contains( QChar('|'), Qt::CaseInsensitive ) ){ - return false; - } - // use orignal name to exam max size of file name - if( name.length() > KMaxFileName ) { + if( path.length() > KMaxPath ) { return false; } return true; } - -bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString ) -{ - // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last - QFileInfo fileInfo( path ); - bool ret( true ); - if (!FmUtils::checkFolderFileName( fileName ) ) { - errString = hbTrId( "Invalid file or folder name, try again!" ); - ret = false; - } else if( !FmUtils::checkMaxPathLength( path ) ) { - errString = hbTrId( "the path you specified is too long, try again!" ); - ret = false; - } else if (fileInfo.exists()) { - errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() ); - ret = false; - } - return ret; -} - -QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ) -{ - FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); - - // do not add default volume for win32 version as this is only the dummy implememnt for debug on windows - 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; -}