# HG changeset patch # User hgs # Date 1278645475 -28800 # Node ID df183af6b92f3f596553b4d03b15f1f83c1fdda3 # Parent b7bfdea70ca209471a339daada22854f9f3ffadc 201027 diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp --- a/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -36,7 +36,7 @@ FmBackupWidget::FmBackupWidget( QGraphicsItem *parent ) -: HbWidget( parent ), mLastPressedItem( 0 ), mScrolled( 0 ), mListReleased( false ) +: HbWidget( parent ) { init(); } @@ -47,16 +47,12 @@ delete mModel; } -void FmBackupWidget::on_list_released( const QModelIndex &index ) -{ - HbDataFormModelItem *item = mModel->itemFromIndex(index); - if( item != mLastPressedItem || mDataForm->isScrolling() || mScrolled ) { - mScrolled = false; - return; - } - mScrolled = false; - if( item == mContentsItem ){ +void FmBackupWidget::on_list_activated( const QModelIndex &index ) +{ + // change item data when receive activated signal + HbDataFormModelItem *item = mModel->itemFromIndex(index); + if( item == mContentsItem ){ emit changeContents(); } else if( item == mTargetItem ){ emit changeTargetDrive(); @@ -69,16 +65,6 @@ } } -void FmBackupWidget::on_list_pressed( const QModelIndex &index ) -{ - mLastPressedItem = mModel->itemFromIndex(index); -} - -void FmBackupWidget::on_list_scrollingStarted() -{ - mScrolled = true; -} - void FmBackupWidget::init() { QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout( this ); @@ -91,16 +77,9 @@ mDataForm = new HbDataForm( this ); mDataForm->setModel( mModel ); vLayout->addItem( mDataForm ); - - - connect( mDataForm, SIGNAL( released( const QModelIndex & ) ), - this, SLOT( on_list_released( const QModelIndex & ) ) ); - - connect( mDataForm, SIGNAL( pressed( const QModelIndex & ) ), - this, SLOT( on_list_pressed( const QModelIndex & ) ) ); - - connect( mDataForm, SIGNAL( scrollingStarted() ), - this, SLOT( on_list_scrollingStarted() ) ); + + connect( mDataForm, SIGNAL( activated( const QModelIndex & ) ), + this, SLOT( on_list_activated( const QModelIndex & ) ) ); connect( this, SIGNAL( doModelRefresh() ), this, SLOT( refreshModel() ), Qt::QueuedConnection ); diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/backuprestore/fmbackupwidget.h --- a/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.h Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/backuprestore/fmbackupwidget.h Fri Jul 09 11:17:55 2010 +0800 @@ -50,9 +50,7 @@ void refreshModel(); private slots: - void on_list_released( const QModelIndex &index ); - void on_list_pressed( const QModelIndex &index ); - void on_list_scrollingStarted(); + void on_list_activated( const QModelIndex &index ); void on_changeContents(); void on_changeScheduling(); @@ -81,10 +79,6 @@ HbDataFormModelItem *mLastBackupDateItem; FmBackupSettings *mBackupSettings; FmBackupConfigLoader *mBackupConfigLoader; - HbDataFormModelItem *mLastPressedItem; - - bool mScrolled; - bool mListReleased; }; #endif // FMBACKUPWIDGET_H diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/components/fmdlgutils.cpp --- a/filemanager/src/filemanager/src/components/fmdlgutils.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdlgutils.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -246,22 +246,20 @@ } bool FmDlgUtils::showTextQuery( - const QString& title, QString& text, bool isDimPrimaryActionWhenEmpty, int maxLength, - const QString &associatedDrives, bool isReturnFalseWhenNoTextChanged ) + const QString& title, QString& text, QStringList validRegExpStringList, + int maxLength, const QString &associatedDrives, bool isReturnFalseWhenNoTextChanged ) { bool ret( false ); bool ok ( true ); // SK return (out parameter) - FmSingleTextQuery::Options options( 0 ); - if( isDimPrimaryActionWhenEmpty ) { - options = FmSingleTextQuery::DimPrimereActionWhenEmpty; - } - FmSingleTextQuery *cQuery = new FmSingleTextQuery( options ); + FmSingleTextQuery *cQuery = new FmSingleTextQuery(); if( maxLength != -1 ){ cQuery->setLineEditMaxLength( maxLength ); } cQuery->setHeadingWidget( new HbLabel( title ) ); + cQuery->setRegExpStringList( validRegExpStringList ); + QString sk1 ( hbTrId ( "txt_common_button_ok" ) ); QString sk2 ( hbTrId ( "txt_common_button_cancel" ) ); @@ -307,13 +305,12 @@ { bool ret( false ); - FmSingleTextQuery *cQuery = new FmSingleTextQuery( FmSingleTextQuery::DimPrimereActionWhenEmpty, - HbLineEdit::Password ); + FmSingleTextQuery *cQuery = new FmSingleTextQuery( HbLineEdit::Password ); if( maxLength != -1 ){ cQuery->setLineEditMaxLength( maxLength ); } cQuery->setHeadingWidget( new HbLabel( title ) ); - + cQuery->setRegExpStringList( QStringList( Regex_ValidUnEmpty ) ); QString sk1 ( hbTrId("txt_common_button_ok" ) ); QString sk2 ( hbTrId("txt_common_button_cancel" ) ); diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/components/fmdlgutils.h --- a/filemanager/src/filemanager/src/components/fmdlgutils.h Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmdlgutils.h Fri Jul 09 11:17:55 2010 +0800 @@ -77,8 +77,8 @@ const QString &associatedDrives = QString() ); static bool showTextQuery( - const QString &title, QString &driveName, bool isDimPrimaryActionWhenEmpty, int maxLength = -1, - const QString &associatedDrives = QString(), bool isReturnFalseWhenNoTextChanged = true ); + const QString &title, QString &text, QStringList validRegExpStringList = QStringList( Regex_ValidUnEmpty ), + int maxLength = -1, const QString &associatedDrives = QString(), bool isReturnFalseWhenNoTextChanged = true ); static bool showSinglePasswordQuery( const QString &title, QString &pwd, int maxLength = -1, diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/components/fmsingletextquery.cpp --- a/filemanager/src/filemanager/src/components/fmsingletextquery.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmsingletextquery.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -19,14 +19,14 @@ #include "fmsingletextquery.h" #include +#include #include #include #include -FmSingleTextQuery::FmSingleTextQuery( Options options, - HbLineEdit::EchoMode echoMode, QGraphicsItem *parent ) : - FmDialog( parent ), mOptions( options ), mEchoMode( echoMode ) +FmSingleTextQuery::FmSingleTextQuery( HbLineEdit::EchoMode echoMode, QGraphicsItem *parent ) : + FmDialog( parent ), mEchoMode( echoMode ) { init(); } @@ -74,13 +74,26 @@ mTextEdit->setMaxLength( length ); } +void FmSingleTextQuery::setRegExpStringList( QStringList regExpStringList ) +{ + mRegExpStringList = regExpStringList; +} + void FmSingleTextQuery::checkActions() { - if( mOptions & DimPrimereActionWhenEmpty ) { - if( !mTextEdit->text().isEmpty() ){ - this->primaryAction()->setEnabled( true ); - } else { - this->primaryAction()->setEnabled( false ); + // check if all regExp match, disable primary action if not match + bool validateResult = true; + foreach( const QString ®ExpString, mRegExpStringList ) { + if( !regExpString.isEmpty() ) { + QRegExp regExp( regExpString ); + if( !regExp.exactMatch( mTextEdit->text() ) ) { + validateResult = false; + } } } + if( validateResult ) { + this->primaryAction()->setEnabled( true ); + } else { + this->primaryAction()->setEnabled( false ); + } } diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/components/fmsingletextquery.h --- a/filemanager/src/filemanager/src/components/fmsingletextquery.h Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/components/fmsingletextquery.h Fri Jul 09 11:17:55 2010 +0800 @@ -28,23 +28,18 @@ { Q_OBJECT public: - enum Option - { - DimPrimereActionWhenEmpty = 0x00000001 - }; - Q_DECLARE_FLAGS(Options, Option) - FmSingleTextQuery( Options options = 0, - HbLineEdit::EchoMode echoMode = HbLineEdit::Normal, QGraphicsItem *parent = 0 ); + FmSingleTextQuery( HbLineEdit::EchoMode echoMode = HbLineEdit::Normal, QGraphicsItem *parent = 0 ); ~FmSingleTextQuery(); public: void setLineEditText( const QString &text ); QString getLineEditText(); void setLineEditMaxLength( int length ); + void setRegExpStringList( QStringList regExpStringList ); public slots: - void checkActions(); + void checkActions(); private: void init(); @@ -52,8 +47,10 @@ private: HbWidget *mContentWidget; HbLineEdit *mTextEdit; - Options mOptions; HbLineEdit::EchoMode mEchoMode; + + // used to check if input text is vaild. Disable primary action when text is not vaild + QStringList mRegExpStringList; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(FmSingleTextQuery::Options) + #endif diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/fmdriverlistwidget.cpp --- a/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/fmdriverlistwidget.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -257,13 +257,21 @@ return; } - QString title( hbTrId( "Drive name ") ); - QString volumeName = driverInfo.volumeName(); - + QString title( hbTrId( "Drive name ") ); + //save the volume status, empty or set + bool needToSetVolume = false; + QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( diskName, needToSetVolume ); + QString oldVolumeName( volumeName ); QString associatedDrives( FmUtils::getDriveLetterFromPath( diskName ) ); - while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName, associatedDrives ) ){ + //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will + //be excuted at lease once to set the volume name. + while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, associatedDrives, false ) ){ + //if volume is not set or oldVolumeName != volumeName , FmUtils::renameDrive will be called + if ( oldVolumeName == volumeName && !needToSetVolume ) { + break; + } int err = FmUtils::renameDrive( diskName, volumeName ); - if ( err == FmErrNone ){ + if ( err == FmErrNone ) { FmDlgUtils::information( hbTrId( "The name has been changed!" ) ); mModel->refresh(); break; diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/fmfilebrowsewidget.cpp --- a/filemanager/src/filemanager/src/fmfilebrowsewidget.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/fmfilebrowsewidget.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -527,6 +527,11 @@ mEmptyTipLabel->setPlainText( hbTrId( "Drive can not be opened " ) ); } setStyle( LabelStyle ); + //hide search panel when the drive is removed + if ( mSearchPanel->isVisible() ){ + mSearchPanel->hide(); + mLayout->removeItem( mSearchPanel ); + } emit setEmptyMenu( true ); break; } @@ -708,9 +713,12 @@ QString filePath = mModel->filePath( mCurrentItem->modelIndex() ); QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() ); int maxFileNameLength = FmUtils::getMaxFileNameLength(); + // regExpList used to disable primary action of text query dialog if input text is not match + QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot ); + QString oldSuffix( fileInfo.suffix() ); QString newName( fileInfo.fileName() ); - while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, true, + while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, regExpList, maxFileNameLength, QString() , true ) ){ // remove whitespace from the start and the end. newName = newName.trimmed(); @@ -719,7 +727,8 @@ QFileInfo newFileInfo( newTargetPath ); QString errString; // check if name/path is available for use - if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) { + // add new Name to check, in order to avoid problem of newName is empty + if( !FmUtils::checkNewFolderOrFile( newName, newTargetPath, errString ) ) { FmDlgUtils::information( errString ); continue; } diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/fmfileview.cpp --- a/filemanager/src/filemanager/src/fmfileview.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/fmfileview.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -396,18 +396,19 @@ QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() ); QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() ); QString dirName = createDefaultFolderName( path ); - + QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot ); + QDir dir( path ); if( dir.exists() ) { while( FmDlgUtils::showTextQuery( hbTrId( "txt_fmgr_title_new_folder" ), dirName, - true, maxFileNameLength, associatedDrive , false ) ){ + regExpList, maxFileNameLength, associatedDrive , false ) ){ // remove whitespace from the start and the end. dirName = dirName.trimmed(); QString newTargetPath = FmUtils::fillPathWithSplash( dir.absolutePath() ) + dirName; QString errString; // check if name/path is available for use - if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) { + if( !FmUtils::checkNewFolderOrFile( dirName, newTargetPath, errString ) ) { FmDlgUtils::information( errString ); continue; } diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp --- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -46,7 +46,10 @@ srcFile + QString( " already exist, please rename:" ); QString value; QFileInfo fileInfo(srcFile); - bool ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false ); + QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot ); + + bool ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, + maxFileNameLength, QString(), false ); while ( ret ) { // remove whitespace from the start and the end. value = value.trimmed(); @@ -54,9 +57,9 @@ fileInfo.absolutePath() ) + value; QString errString; // check if name/path is available for use. - if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) { + if( !FmUtils::checkNewFolderOrFile( value, newTargetPath, errString ) ) { FmDlgUtils::information( errString ); - ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false ); + ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, maxFileNameLength, QString(), false ); continue; } else { break; @@ -213,10 +216,13 @@ if( ( state & FmDriverInfo::EDriveAvailable ) && ( state & FmDriverInfo::EDriveRemovable ) && !( state & FmDriverInfo::EDriveMassStorage ) ) { - QString volumeName; - while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){ + bool needToSetVolume = false; + QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( driveName, needToSetVolume ); + //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will + //be excuted at lease once to set the volume name. + while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, QString(), false ) ){ int err = FmUtils::renameDrive( driveName, volumeName ); - if ( err == FmErrNone ){ + if ( err == FmErrNone ) { FmDlgUtils::information( hbTrId( "The name has been changed!" ) ); mOperationService->on_operationThread_refreshModel( driveName ); break; diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/inc/fmdefine.h --- a/filemanager/src/inc/fmdefine.h Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/inc/fmdefine.h Fri Jul 09 11:17:55 2010 +0800 @@ -71,4 +71,20 @@ #define FmMaxLengthofDriveName 11 #define FmMaxLengthofDrivePassword 8 + +// 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. +// 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. +#define Regex_ValidFileFolderName QString( "^[^\\\\/:*?\"<>|]*[^\\\\/:*?\"<>|\\s][^\\\\/:*?\"<>|]*$" ) + +// is not end with dot( trim blank characters in the end first ) +#define Regex_ValidNotEndWithDot QString( "^.*[^\\.\\s][\\s]*$" ) + #endif diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/inc/fmutils.h --- a/filemanager/src/inc/fmutils.h Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/inc/fmutils.h Fri Jul 09 11:17:55 2010 +0800 @@ -127,11 +127,20 @@ /** * check file or folder path is illegal or not. * - * @param path file/folder path. + * @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 &path, QString &errString ); + 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 ); }; diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/inc/fmutils_s60.cpp --- a/filemanager/src/inc/fmutils_s60.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/inc/fmutils_s60.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -94,7 +94,7 @@ } } - if( volumeName == KErrNone || driveInfoErr == KErrNone ) { + if( volumeInfoErr == KErrNone || driveInfoErr == KErrNone ) { //TDriveInfo driveInfo = volumeInfo.iDrive; quint32 drvStatus( 0 ); @@ -684,15 +684,19 @@ int FmUtils::isPathAccessabel( const QString &path ) { // Used to check if path is accessable, very important feature - // and will return filemanager error. + // and will return filemanager error. FmLogger::log( QString( "isPathAccessabel:" ) + path ); if( path.isEmpty() ) { return FmErrPathNotExist; } - if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive + + // 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 ) ) { FmLogger::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 ) ) { @@ -917,33 +921,41 @@ } return true; } + bool FmUtils::checkFolderFileName( const QString& name ) { - if( name.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { + // 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( name.contains( QChar('\\'), Qt::CaseInsensitive ) || - name.contains( QChar('/'), Qt::CaseInsensitive ) || - name.contains( QChar(':'), Qt::CaseInsensitive ) || - name.contains( QChar('*'), Qt::CaseInsensitive ) || - name.contains( QChar('?'), Qt::CaseInsensitive ) || - name.contains( QChar('\"'), Qt::CaseInsensitive ) || - name.contains( QChar('<'), Qt::CaseInsensitive ) || - name.contains( QChar('>'), Qt::CaseInsensitive ) || - name.contains( QChar('|'), Qt::CaseInsensitive ) ){ + 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 &path, QString &errString ) +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( fileInfo.fileName() ) ) { + if (!FmUtils::checkFolderFileName( fileName ) ) { errString = hbTrId( "Invalid file or folder name!" ); ret = false; } else if( !FmUtils::checkMaxPathLength( path ) ) { @@ -955,3 +967,30 @@ } return ret; } + +QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName ) +{ + FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName ); + + QString volumeName = driverInfo.volumeName(); + //save the volume status, whether it is default name + defaultName = false; + //volume name may be null if not set, it will be set at least for one time in the following while cycling. + if ( ( volumeName.isEmpty() ) && + ( driverInfo.driveState() & FmDriverInfo::EDriveAvailable ) ) { + defaultName = true; + if ( driverInfo.driveState() & FmDriverInfo::EDriveRemovable ) { + if ( driverInfo.driveState() & FmDriverInfo::EDriveUsbMemory ) { + volumeName = hbTrId("USB memory"); + } else if ( driverInfo.driveState() & FmDriverInfo::EDriveMassStorage ) { + volumeName = hbTrId("Mass storage"); + } + else { + volumeName = hbTrId("Memory card"); + } + } else { + volumeName = hbTrId("Device memory"); + } + } + return volumeName; +} diff -r b7bfdea70ca2 -r df183af6b92f filemanager/src/inc/fmutils_win.cpp --- a/filemanager/src/inc/fmutils_win.cpp Fri Jun 25 17:08:34 2010 +0800 +++ b/filemanager/src/inc/fmutils_win.cpp Fri Jul 09 11:17:55 2010 +0800 @@ -466,33 +466,42 @@ } return true; } + bool FmUtils::checkFolderFileName( const QString& name ) { - if( name.endsWith( QChar('.'), Qt::CaseInsensitive ) ) { + // 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( name.contains( QChar('\\'), Qt::CaseInsensitive ) || - name.contains( QChar('/'), Qt::CaseInsensitive ) || - name.contains( QChar(':'), Qt::CaseInsensitive ) || - name.contains( QChar('*'), Qt::CaseInsensitive ) || - name.contains( QChar('?'), Qt::CaseInsensitive ) || - name.contains( QChar('\"'), Qt::CaseInsensitive ) || - name.contains( QChar('<'), Qt::CaseInsensitive ) || - name.contains( QChar('>'), Qt::CaseInsensitive ) || - name.contains( QChar('|'), Qt::CaseInsensitive ) ){ + 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 &path, QString &errString ) +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( fileInfo.fileName() ) ) { + if (!FmUtils::checkFolderFileName( fileName ) ) { errString = hbTrId( "Invalid file or folder name, try again!" ); ret = false; } else if( !FmUtils::checkMaxPathLength( path ) ) { @@ -504,3 +513,12 @@ } 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(); +} +