filemanager/src/filemanager/src/fmfilebrowsewidget.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
equal deleted inserted replaced
16:ada7962b4308 37:15bc28c9dd51
    22 #include "fmfilebrowsewidget.h"
    22 #include "fmfilebrowsewidget.h"
    23 #include "fmviewdetailsdialog.h"
    23 #include "fmviewdetailsdialog.h"
    24 #include "fmviewmanager.h"
    24 #include "fmviewmanager.h"
    25 #include "fmfiledialog.h"
    25 #include "fmfiledialog.h"
    26 #include "fmdlgutils.h"
    26 #include "fmdlgutils.h"
       
    27 #include "fmfileiconprovider.h"
    27 
    28 
    28 #include <QFile>
    29 #include <QFile>
    29 #include <QDirModel>
    30 #include <QFileSystemModel>
    30 #include <QSizePolicy>
    31 #include <QSizePolicy>
    31 #include <QGraphicsLinearLayout>
    32 #include <QGraphicsLinearLayout>
    32 
    33 
    33 #include <hbmenu.h>
    34 #include <hbmenu.h>
    34 #include <hblistview.h>
    35 #include <hblistview.h>
    35 #include <hbtreeview.h>
    36 #include <hbtreeview.h>
    36 #include <hbabstractviewitem.h>
    37 #include <hbabstractviewitem.h>
    37 #include <hbaction.h>
    38 #include <hbaction.h>
    38 #include <hbsearchpanel.h>
    39 #include <hbsearchpanel.h>
    39 #include <hbmessagebox.h>
       
    40 #include <hblabel.h>
    40 #include <hblabel.h>
       
    41 
       
    42 // These define comes from implementation of QFileSystemModel
       
    43 #define QFileSystemSortName 0
       
    44 #define QFileSystemSortSize 1 
       
    45 #define QFileSystemSortType 2
       
    46 #define QFileSystemSortTime 3
    41 
    47 
    42 FmFileBrowseWidget::FmFileBrowseWidget( HbWidget *parent, FmFileBrowseWidget::Style style )
    48 FmFileBrowseWidget::FmFileBrowseWidget( HbWidget *parent, FmFileBrowseWidget::Style style )
    43     : HbWidget( parent ),
    49     : HbWidget( parent ),
    44       mTreeView( 0 ),
    50       mTreeView( 0 ),
    45       mListView( 0 ),
    51       mListView( 0 ),
    48       mSelectable( false ), 
    54       mSelectable( false ), 
    49       mStyle( NoStyle ), 
    55       mStyle( NoStyle ), 
    50       mFileBrowseStyle( style ),
    56       mFileBrowseStyle( style ),
    51       mCurrentItem( 0 ),
    57       mCurrentItem( 0 ),
    52       mOperationService( 0 ),
    58       mOperationService( 0 ),
    53       mSearchPanel( 0 )
    59       mSearchPanel( 0 ),
       
    60       mListLongPressed( false )
    54 {
    61 {
    55     initFileModel();
    62     initFileModel();
    56     initListView();
    63     initListView();
    57     initTreeView();
    64     initTreeView();
    58     initSearchPanel();
    65     initSearchPanel();
    68     //take the model out from view and delete it.
    75     //take the model out from view and delete it.
    69     //so that the model could be destroy earlier
    76     //so that the model could be destroy earlier
    70     //since there is a thread running in background
    77     //since there is a thread running in background
    71     //if the model destroy later, the thread might not quit properly.
    78     //if the model destroy later, the thread might not quit properly.
    72 
    79 
    73     if( mStyle == ListStyle || mStyle == TreeStyle ) {
       
    74         QFileInfo oldFileInfo = mModel->fileInfo( mListView->rootIndex() );
       
    75         if( oldFileInfo.exists() ) {
       
    76             FmViewManager *viewManager = FmViewManager::viewManager();
       
    77             if( viewManager ) {
       
    78                 viewManager->removeWatchPath( oldFileInfo.absoluteFilePath() );
       
    79             }   
       
    80         }
       
    81     }
       
    82 
       
    83     mTreeView->setModel( 0 );
    80     mTreeView->setModel( 0 );
    84     mListView->setModel( 0 );
    81     mListView->setModel( 0 );
    85     delete mModel;
    82     delete mModel;
       
    83     
       
    84     delete mFileIconProvider;
    86 }
    85 }
    87 
    86 
    88 QFileInfo FmFileBrowseWidget::currentPath() const
    87 QFileInfo FmFileBrowseWidget::currentPath() const
    89 {
    88 {
    90     QModelIndex index = mListView->rootIndex();
    89     QModelIndex index = mListView->rootIndex();
   119 }
   118 }
   120 
   119 
   121 void FmFileBrowseWidget::setRootPath( const QString &pathName )
   120 void FmFileBrowseWidget::setRootPath( const QString &pathName )
   122 {
   121 {
   123     QString logString = "FmFileBrowseWidget::setRootPath(" + pathName + ')';
   122     QString logString = "FmFileBrowseWidget::setRootPath(" + pathName + ')';
   124     FmLogger::log( logString );
   123     FM_LOG( logString );
   125 
   124 
   126     if( checkPathAndSetStyle( pathName ) ) {
   125     int err = checkPathAndSetStyle( pathName );
   127         mListView->setModel(0);
   126     switch( err )
   128         mTreeView->setModel(0);
   127         {
   129         delete mModel;
   128         case FmErrNone:
   130         mModel = new QDirModel(this);
   129             {
   131         mListView->setModel(mModel);
   130             mListView->setRootIndex( mModel->setRootPath( pathName ) );
   132         mTreeView->setModel(mModel);
   131             emit currentPathChanged( pathName );
   133         
   132             break;
   134         mListView->setRootIndex( mModel->index( pathName ) );
   133             }
   135         mTreeView->setRootIndex( mModel->index( pathName ) );
   134         case FmErrPathNotExist:
   136         FmViewManager::viewManager()->addWatchPath( pathName );
   135             {
   137     }
   136             FmDlgUtils::information( hbTrId( "Path is not exist" ) );
       
   137             break;
       
   138             }
       
   139         case FmErrDriveNotAvailable:
       
   140             {
       
   141             // do not take any action as widget set note in label already. 
       
   142             break;
       
   143             }
       
   144         case FmErrDriveDenied:
       
   145         case FmErrPathDenied:
       
   146             {
       
   147             FmDlgUtils::information( hbTrId( "Can not access" ) );
       
   148             break;
       
   149             }
       
   150         default:
       
   151             Q_ASSERT_X( false, "setRootPath", "please handle all error from isPathAccessabel" );
       
   152             break;
       
   153         }
   138     mCurrentDrive = pathName.left( 3 );
   154     mCurrentDrive = pathName.left( 3 );
   139 }
   155 }
   140 
   156 
   141 void FmFileBrowseWidget::setStyle( FmFileBrowseWidget::Style style )
   157 void FmFileBrowseWidget::setStyle( FmFileBrowseWidget::Style style )
   142 {
   158 {
   205 
   221 
   206 
   222 
   207 bool FmFileBrowseWidget::rename( const QString &oldName, const QString &newName )
   223 bool FmFileBrowseWidget::rename( const QString &oldName, const QString &newName )
   208 {
   224 {
   209     return QFile::rename( oldName, newName );
   225     return QFile::rename( oldName, newName );
   210     /*
       
   211     if (QFile::rename( oldName, newName )) {
       
   212     QModelIndex index = mModel->index( newName );
       
   213     mModel->refresh( index );
       
   214     index = mModel->index( oldName );
       
   215     mModel->refresh( index );
       
   216     }
       
   217     */
       
   218 }
   226 }
   219 
   227 
   220 
   228 
   221 
   229 
   222 
   230 
   223 bool FmFileBrowseWidget::cdUp()
   231 bool FmFileBrowseWidget::cdUp()
   224 {
   232 {
   225     if (mStyle == ListStyle) {
   233 	if (mStyle == ListStyle) {
   226         QModelIndex index = mListView->rootIndex().parent();
   234         QModelIndex parentIndex = mListView->rootIndex().parent();
   227         mModel->refresh(index);
   235 		// QFileSystemModel will auto refresh for file/folder change
   228         if (index.isValid()) {
   236         if (parentIndex.isValid()) {
   229             changeRootIndex( index );
   237 			changeRootIndex( parentIndex );
   230             return true;
   238             return true;
   231         }
   239         }
   232     }
   240     }
   233 
   241 
   234     return false;
   242     return false;
   235 }
   243 }
   236 
   244 
   237 void FmFileBrowseWidget::on_list_activated( const QModelIndex &index )
   245 void FmFileBrowseWidget::on_list_activated( const QModelIndex &index )
   238 {
   246 {
       
   247     mActivatedModelIndex = index;
       
   248     emit listActivated();
       
   249 }
       
   250 
       
   251 void FmFileBrowseWidget::on_listActivated()
       
   252 {
       
   253     FM_LOG("FmFileBrowseWidget::on_listActivated start");
       
   254     if( mListLongPressed ) {
       
   255         FM_LOG("FmFileBrowseWidget::on_list_activated end because longPressed");
       
   256         return;
       
   257     }
   239     if (!mSelectable) {
   258     if (!mSelectable) {
   240         if (mModel->isDir(index) ) {
   259         if (mModel->isDir(mActivatedModelIndex) ) {
   241             changeRootIndex( index );
   260             FM_LOG("FmFileBrowseWidget::on_list_activated changeRootIndex>>");
       
   261             changeRootIndex( mActivatedModelIndex );
       
   262             FM_LOG("FmFileBrowseWidget::on_list_activated changeRootIndex<<");
   242         } else {
   263         } else {
   243             QString filePath( mModel->filePath( index ) );
   264             QString filePath( mModel->filePath( mActivatedModelIndex ) );
   244             QFileInfo fileInfo( filePath );
   265             QFileInfo fileInfo( filePath );
   245             if ( fileInfo.isFile() ) {
   266             if ( fileInfo.isFile() ) {
   246                 mOperationService->syncLaunchFileOpen( filePath );
   267                 mOperationService->syncLaunchFileOpen( filePath );
   247             }
   268             }
   248         }
   269         }
   249     }
   270     }
       
   271     FM_LOG("FmFileBrowseWidget::on_listActivated end");
   250 }
   272 }
   251 
   273 
   252 void FmFileBrowseWidget::on_tree_activated( const QModelIndex &index )
   274 void FmFileBrowseWidget::on_tree_activated( const QModelIndex &index )
   253 {
   275 {
   254     if (!mSelectable) {
   276     if (!mSelectable) {
   256     }
   278     }
   257 }
   279 }
   258 
   280 
   259 void FmFileBrowseWidget::on_list_longPressed( HbAbstractViewItem *item, const QPointF &coords )
   281 void FmFileBrowseWidget::on_list_longPressed( HbAbstractViewItem *item, const QPointF &coords )
   260 {
   282 {
       
   283     mListLongPressed = true;
   261     HbMenu *contextMenu = new HbMenu();
   284     HbMenu *contextMenu = new HbMenu();
   262     mCurrentItem = item;
   285     mCurrentItem = item;
   263     
   286     
   264     HbAction *viewAction = new HbAction();
   287     HbAction *viewAction = new HbAction();
   265     viewAction->setObjectName( "viewAction" );
   288     viewAction->setObjectName( "viewAction" );
   266     viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_file" ) );
   289     viewAction->setText( hbTrId( "txt_fmgr_menu_view_details_file" ) );
   267     contextMenu->addAction( viewAction );
   290     contextMenu->addAction( viewAction );
   268 
   291 
   269     connect( viewAction, SIGNAL( triggered() ),
   292     connect( viewAction, SIGNAL( triggered() ),
   270     this, SLOT( on_viewAction_triggered() ) );
   293         this, SLOT( on_viewAction_triggered() ), Qt::QueuedConnection );
   271 
   294 
   272     //copy
   295     //copy
   273     HbAction *copyAction = new HbAction();
   296     HbAction *copyAction = new HbAction();
   274     copyAction->setObjectName( "copyAction" );
   297     copyAction->setObjectName( "copyAction" );
   275     copyAction->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   298     copyAction->setText( hbTrId( "txt_fmgr_menu_copy" ) );
   276     contextMenu->addAction( copyAction );
   299     contextMenu->addAction( copyAction );
   277 
   300 
   278     connect( copyAction, SIGNAL( triggered() ),
   301     connect( copyAction, SIGNAL( triggered() ),
   279     this, SLOT( on_copyAction_triggered() ) );
   302     this, SLOT( on_copyAction_triggered() ), Qt::QueuedConnection );
   280 
   303 
   281     
   304     
   282     QString filePath( mModel->filePath( item->modelIndex() ) );
   305     QString filePath( mModel->filePath( item->modelIndex() ) );
   283     QString formatFilePath( FmUtils::formatPath( filePath ) );
   306     QString formatFilePath( FmUtils::fillPathWithSplash( filePath ) );
   284     QFileInfo fileInfo( filePath );
   307     QFileInfo fileInfo( filePath );
   285     
   308     
   286     if( ( fileInfo.isFile() ) || ( fileInfo.isDir() && !( FmUtils::isDefaultFolder( formatFilePath ) ) ) ){
   309     if( ( fileInfo.isFile() ) || ( fileInfo.isDir() && !( FmUtils::isDefaultFolder( formatFilePath ) ) ) ){
   287         //Move
   310         //Move
   288         HbAction *moveAction = new HbAction();
   311         HbAction *moveAction = new HbAction();
   289         moveAction->setObjectName( "moveAction" );
   312         moveAction->setObjectName( "moveAction" );
   290         moveAction->setText( hbTrId( "txt_fmgr_menu_move" ) );
   313         moveAction->setText( hbTrId( "txt_fmgr_menu_move" ) );
   291         contextMenu->addAction( moveAction );
   314         contextMenu->addAction( moveAction );
   292     
   315     
   293         connect( moveAction, SIGNAL( triggered() ),
   316         connect( moveAction, SIGNAL( triggered() ),
   294         this, SLOT( on_moveAction_triggered() ) );
   317         this, SLOT( on_moveAction_triggered() ), Qt::QueuedConnection );
   295     
   318     
   296         //Delete
   319         //Delete
   297         HbAction *deleteAction = new HbAction();
   320         HbAction *deleteAction = new HbAction();
   298         deleteAction->setObjectName( "deleteAction" );
   321         deleteAction->setObjectName( "deleteAction" );
   299         deleteAction->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   322         deleteAction->setText( hbTrId( "txt_fmgr_menu_delete" ) );
   300         contextMenu->addAction( deleteAction );
   323         contextMenu->addAction( deleteAction );
   301     
   324     
   302         connect( deleteAction, SIGNAL( triggered() ),
   325         connect( deleteAction, SIGNAL( triggered() ),
   303         this, SLOT( on_deleteAction_triggered() ) );
   326         this, SLOT( on_deleteAction_triggered() ), Qt::QueuedConnection );
   304     
   327     
   305         //rename
   328         //rename
   306         HbAction *renameAction = new HbAction();
   329         HbAction *renameAction = new HbAction();
   307         renameAction->setObjectName( "renameAction" );
   330         renameAction->setObjectName( "renameAction" );
   308         renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) );
   331         renameAction->setText( hbTrId( "txt_fmgr_menu_rename" ) );
   309         contextMenu->addAction( renameAction );
   332         contextMenu->addAction( renameAction );
   310     
   333     
   311         connect( renameAction, SIGNAL( triggered() ),
   334         connect( renameAction, SIGNAL( triggered() ),
   312         this, SLOT( on_renameAction_triggered() ) );
   335         this, SLOT( on_renameAction_triggered() ), Qt::QueuedConnection );
   313     }
   336     }
   314     
   337     
   315 //    if( fileInfo.isFile() ){
   338 //    if( fileInfo.isFile() ){
   316 //        HbAction *sendAction = new HbAction();
   339 //        HbAction *sendAction = new HbAction();
   317 //        sendAction->setObjectName( "sendAction" );
   340 //        sendAction->setObjectName( "sendAction" );
   320 //        
   343 //        
   321 //        connect( sendAction, SIGNAL( triggered() ),
   344 //        connect( sendAction, SIGNAL( triggered() ),
   322 //        this, SLOT( on_sendAction_triggered() ) );
   345 //        this, SLOT( on_sendAction_triggered() ) );
   323 //    }
   346 //    }
   324     
   347     
   325     contextMenu->exec( coords );     
   348     contextMenu->setPreferredPos( coords );
       
   349     contextMenu->open();
       
   350 }
       
   351 
       
   352 void FmFileBrowseWidget::on_list_pressed( const QModelIndex &  index )
       
   353 {
       
   354     mListLongPressed = false;
   326 }
   355 }
   327 
   356 
   328 void FmFileBrowseWidget::on_tree_longPressed( HbAbstractViewItem *item, const QPointF &coords )
   357 void FmFileBrowseWidget::on_tree_longPressed( HbAbstractViewItem *item, const QPointF &coords )
   329 {
   358 {
   330     Q_UNUSED( item );
   359     Q_UNUSED( item );
   355     mListView->setObjectName( "list" );
   384     mListView->setObjectName( "list" );
   356     mListView->setModel( mModel );
   385     mListView->setModel( mModel );
   357 
   386 
   358     connect( mListView, SIGNAL( activated( const QModelIndex& ) ),
   387     connect( mListView, SIGNAL( activated( const QModelIndex& ) ),
   359         this, SLOT( on_list_activated( const QModelIndex& ) ) );
   388         this, SLOT( on_list_activated( const QModelIndex& ) ) );
       
   389     connect( this, SIGNAL( listActivated() ),
       
   390         this, SLOT( on_listActivated() ), Qt::QueuedConnection );
       
   391     connect( mListView, SIGNAL( pressed( const QModelIndex & ) ),
       
   392         this, SLOT( on_list_pressed( const QModelIndex & ) ) );
   360     connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ),
   393     connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ),
   361         this, SLOT( on_list_longPressed( HbAbstractViewItem *, const QPointF & ) ) );
   394         this, SLOT( on_list_longPressed( HbAbstractViewItem *, const QPointF & ) ) );
   362 }
   395 }
   363 
   396 
   364 void FmFileBrowseWidget::initTreeView()
   397 void FmFileBrowseWidget::initTreeView()
   373         this, SLOT( on_tree_longPressed( HbAbstractViewItem *, const QPointF & ) ) );
   406         this, SLOT( on_tree_longPressed( HbAbstractViewItem *, const QPointF & ) ) );
   374 }
   407 }
   375 
   408 
   376 void FmFileBrowseWidget::initFileModel()
   409 void FmFileBrowseWidget::initFileModel()
   377 {
   410 {
   378     mModel = new QDirModel( this );
   411     mModel = new QFileSystemModel( this );
   379     mModel->setReadOnly( false );
   412     mModel->setReadOnly( false );
   380     disconnect( mModel, SIGNAL( rowsInserted( const QModelIndex &, int, int ) ), 0 ,0 );
   413     
       
   414     mFileIconProvider = new FmFileIconProvider();
       
   415     mModel->setIconProvider( mFileIconProvider );
   381 }
   416 }
   382 
   417 
   383 void FmFileBrowseWidget::initLayout()
   418 void FmFileBrowseWidget::initLayout()
   384 {
   419 {
   385     mLayout = new QGraphicsLinearLayout( this );
   420     mLayout = new QGraphicsLinearLayout( this );
   395     mSearchPanel->setSearchOptionsEnabled( true );
   430     mSearchPanel->setSearchOptionsEnabled( true );
   396     mSearchPanel->setProgressive( false );
   431     mSearchPanel->setProgressive( false );
   397     mSearchPanel->hide();
   432     mSearchPanel->hide();
   398     
   433     
   399     connect( mSearchPanel, SIGNAL( searchOptionsClicked() ),
   434     connect( mSearchPanel, SIGNAL( searchOptionsClicked() ),
   400         this, SLOT( on_searchPanel_searchOptionsClicked() ) );
   435         this, SLOT( on_searchPanel_searchOptionsClicked() ), Qt::QueuedConnection );
   401     
   436     
   402     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
   437     connect( mSearchPanel, SIGNAL( criteriaChanged( const QString & ) ),
   403         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) );
   438         this, SLOT( on_searchPanel_criteriaChanged( const QString & ) ) );
   404     
   439     
   405     connect( mSearchPanel, SIGNAL( exitClicked() ),
   440     connect( mSearchPanel, SIGNAL( exitClicked() ),
   414 }
   449 }
   415 
   450 
   416 
   451 
   417 void FmFileBrowseWidget::changeRootIndex( const QModelIndex &index )
   452 void FmFileBrowseWidget::changeRootIndex( const QModelIndex &index )
   418 {
   453 {
   419     QFileInfo oldFileInfo = mModel->fileInfo( mListView->rootIndex() );
   454 	QString filePath = mModel->fileInfo( index ).absoluteFilePath();
   420     FmViewManager::viewManager()->removeWatchPath( oldFileInfo.absoluteFilePath() );
   455 	setRootPath( filePath );
   421 
       
   422     mModel->refresh(index);
       
   423     if ( mStyle == ListStyle ) {
       
   424         mListView->setRootIndex( index );
       
   425     } else if ( mStyle == TreeStyle ) {
       
   426         mTreeView->setRootIndex( index );
       
   427     }
       
   428     QFileInfo fileInfo = mModel->fileInfo( mListView->rootIndex() );
       
   429     QString string = fileInfo.absoluteFilePath();
       
   430     emit currentPathChanged( string );
       
   431     FmViewManager::viewManager()->addWatchPath( string );
       
   432 }
   456 }
   433 
   457 
   434 bool FmFileBrowseWidget::isDriver(const QModelIndex &index) const
   458 bool FmFileBrowseWidget::isDriver(const QModelIndex &index) const
   435 {
   459 {
   436     QString path = mModel->filePath(index);
   460     QString path = mModel->filePath(index);
   449 void FmFileBrowseWidget::setModelFilter( QDir::Filters filters ) 
   473 void FmFileBrowseWidget::setModelFilter( QDir::Filters filters ) 
   450 {
   474 {
   451     mModel->setFilter( filters );
   475     mModel->setFilter( filters );
   452 }
   476 }
   453 
   477 
   454 void FmFileBrowseWidget::refreshModel( const QString& path )
   478 void FmFileBrowseWidget::on_driveChanged()
   455 {
   479 {
       
   480     FM_LOG( "FmFileBrowseWidget::on_driveChanged start" );
   456     QString currPath( currentPath().absoluteFilePath() );
   481     QString currPath( currentPath().absoluteFilePath() );
   457     QString refreshPath( path );
   482     
   458     
   483     if(style()==ListStyle) {
   459     if( !currPath.isEmpty() ) {
   484         // display normally, setRootPath again to check if drive is available 
   460         if( refreshPath.isEmpty() ) {
   485         setRootPath( currPath );
   461             refreshPath = currPath;
   486     } else{
   462         }
   487         // display label style, setRootPath to drive root
   463         if(  !FmUtils::isPathEqual( refreshPath, currPath ) ) {
   488         setRootPath( mCurrentDrive );
   464             // no need refresh other path
   489     }
   465             return;
   490     emit setTitle( FmUtils::fillDriveVolume( mCurrentDrive, true ) );
   466         }
   491     FM_LOG( "FmFileBrowseWidget::on_driveChanged end" );
   467         if( checkPathAndSetStyle( refreshPath ) ) {               
   492 }
   468             mModel->refresh( mModel->index( refreshPath ) );
   493 
   469         } else {
   494 int FmFileBrowseWidget::checkPathAndSetStyle( const QString& path )
   470             FmViewManager *viewManager = FmViewManager::viewManager();
   495 {
   471             if( viewManager ) {
   496     FM_LOG( "FmFileBrowseWidget::checkPathAndSetStyle start_" + path );
   472                 viewManager->removeWatchPath( currentPath().absoluteFilePath() );
   497     int err = FmUtils::isPathAccessabel( path );
   473             } 
   498     switch( err )
   474         }
   499         {
   475     } else {
   500         case FmErrNone:
   476         // current path is empty, so change root path to Drive root.
   501             {
   477         refreshPath = mCurrentDrive;
   502             setStyle( mFileBrowseStyle );
   478         setRootPath( refreshPath );
   503             emit setEmptyMenu( false );
   479         emit setTitle( FmUtils::fillDriveVolume( mCurrentDrive, true ) );
   504             break;
   480     }
   505             }
   481 }
   506         case FmErrDriveNotAvailable:
   482 
   507             {
   483 bool FmFileBrowseWidget::checkPathAndSetStyle( const QString& path )
   508             QString driveName = FmUtils::getDriveNameFromPath( path );
   484 {
   509             FmDriverInfo::DriveState state = FmUtils::queryDriverInfo( driveName ).driveState();
   485     if( !FmUtils::isPathAccessabel( path ) ){
   510             
   486         QString driveName = FmUtils::getDriveNameFromPath( path );
   511             if( state & FmDriverInfo::EDriveLocked ) {
   487         FmDriverInfo::DriveState state = FmUtils::queryDriverInfo( driveName ).driveState();
   512                 mEmptyTipLabel->setPlainText( hbTrId( "Drive is locked" ) );       
   488         
   513             } else if( state & FmDriverInfo::EDriveNotPresent ) {
   489         if( state & FmDriverInfo::EDriveLocked ) {
   514                 mEmptyTipLabel->setPlainText( hbTrId( "Drive is not present" ) );
   490             mEmptyTipLabel->setPlainText( hbTrId( "Memory Card is locked" ) );       
   515             } else if( state & FmDriverInfo::EDriveCorrupted ) {
   491         } else if( state & FmDriverInfo::EDriveNotPresent ) {
   516                 mEmptyTipLabel->setPlainText( hbTrId( "Drive is Corrupted" ) );
   492             mEmptyTipLabel->setPlainText( hbTrId( "Memory Card is not present" ) );
   517             } else {
   493         } else if( state & FmDriverInfo::EDriveCorrupted ) {
   518                 mEmptyTipLabel->setPlainText( hbTrId( "Drive can not be opened " ) );
   494             mEmptyTipLabel->setPlainText( hbTrId( "Drive is Corrupted" ) );
   519             }
   495         } else {
   520             setStyle( LabelStyle );
   496             mEmptyTipLabel->setPlainText( hbTrId( "Drive can not be opened " ) );
   521 			//hide search panel when the drive is removed 
   497         }
   522             if ( mSearchPanel->isVisible() ){
   498         setStyle( LabelStyle );
   523                 mSearchPanel->hide();
   499         emit setEmptyMenu( true );
   524                 mLayout->removeItem( mSearchPanel );
   500         return false;
   525             }    
   501     } else {
   526             emit setEmptyMenu( true );
   502         setStyle( mFileBrowseStyle );
   527             break;
   503         emit setEmptyMenu( false );
   528             }
   504         return true;
   529         case FmErrPathNotExist:
   505     }
   530         case FmErrDriveDenied:
   506     
   531         case FmErrPathDenied:
       
   532             {
       
   533             // do not tack any action, error note shoule be shown by invoker.
       
   534             // checkPathAndSetStyle just check path and set style.
       
   535             break;
       
   536             }
       
   537         default:
       
   538             Q_ASSERT_X( false, "checkPathAndSetStyle", "please handle all error from isPathAccessabel" );
       
   539             break;
       
   540         }
       
   541     return err;
   507 }
   542 }
   508 
   543 
   509 void FmFileBrowseWidget::sortFiles( TSortType sortType )
   544 void FmFileBrowseWidget::sortFiles( TSortType sortType )
   510 {
   545 {
   511     switch( sortType ){
   546     switch( sortType ){
   512         case ESortByName:{
   547         case ESortByName:{
   513             mModel->setSorting( QDir::Name );
   548 			mModel->sort( QFileSystemSortName );
   514         }
   549         }
   515             break;
   550             break;
   516         case ESortByTime:{
   551         case ESortByTime:{
   517             mModel->setSorting( QDir::Time );
   552             mModel->sort( QFileSystemSortTime );
   518         }
   553         }
   519             break;
   554             break;
   520         case ESortBySize:{
   555         case ESortBySize:{
   521             mModel->setSorting( QDir::Size );
   556             mModel->sort( QFileSystemSortSize );
   522         }
   557         }
   523             break;
   558             break;
   524         case ESortByType:{
   559         case ESortByType:{
   525             mModel->setSorting( QDir::Type | QDir::DirsFirst );
   560             mModel->sort( QFileSystemSortType );
   526         }
   561         }
   527             break;
   562             break;
   528         default:
   563         default:
   529             break;
   564             break;
   530     }
   565     }
   537     mSearchPanel->show();
   572     mSearchPanel->show();
   538 }
   573 }
   539 
   574 
   540 void FmFileBrowseWidget::on_searchPanel_searchOptionsClicked()
   575 void FmFileBrowseWidget::on_searchPanel_searchOptionsClicked()
   541 {
   576 {
   542     mFindTargetPath = FmFileDialog::getExistingDirectory( 0, hbTrId( "Look in:" ), QString(""),
   577     mFindTargetPath = FmUtils::fillPathWithSplash( FmFileDialog::getExistingDirectory( 0, hbTrId( "Look in:" ), QString(""),
   543         QStringList() );
   578         QStringList() ) );
   544 }
   579 }
   545 
   580 
   546 void FmFileBrowseWidget::on_searchPanel_criteriaChanged( const QString &criteria )
   581 void FmFileBrowseWidget::on_searchPanel_criteriaChanged( const QString &criteria )
   547 {
   582 {
   548     if( mFindTargetPath.isEmpty() ){
   583     if( mFindTargetPath.isEmpty() ){
   583 
   618 
   584 void FmFileBrowseWidget::on_deleteAction_triggered()
   619 void FmFileBrowseWidget::on_deleteAction_triggered()
   585 {
   620 {
   586     QStringList fileList;
   621     QStringList fileList;
   587     fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) );
   622     fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) );
   588     if ( HbMessageBox::question( hbTrId("Confirm Deletion?" ) )) {
   623     if ( FmDlgUtils::question( hbTrId("Confirm Deletion?" ) )) {
   589         int ret = mOperationService->asyncRemove( fileList );
   624         int ret = mOperationService->asyncRemove( fileList );
   590         switch( ret ) {
   625         switch( ret ) {
   591             case FmErrNone:
   626             case FmErrNone:
   592                 // no error, do not show note to user
   627                 // no error, do not show note to user
   593                 break;
   628                 break;
   594             case FmErrAlreadyStarted:
   629             case FmErrAlreadyStarted:
   595                 // last operation have not finished
   630                 // last operation have not finished
   596                 HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   631                 FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   597                 break;
   632                 break;
   598             case FmErrWrongParam:
   633             case FmErrWrongParam:
   599                 HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   634                 FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   600                 break;
   635                 break;
   601             default:
   636             default:
   602                 HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   637                 FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   603         }
   638         }
   604     }
   639     }
   605 }
   640 }
   606 
   641 
   607 void FmFileBrowseWidget::on_copyAction_triggered()
   642 void FmFileBrowseWidget::on_copyAction_triggered()
   620             case FmErrNone:
   655             case FmErrNone:
   621                 // no error, do not show note to user
   656                 // no error, do not show note to user
   622                 break;
   657                 break;
   623             case FmErrAlreadyStarted:
   658             case FmErrAlreadyStarted:
   624                 // last operation have not finished
   659                 // last operation have not finished
   625                 HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   660                 FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   626                 break;
   661                 break;
   627             case FmErrWrongParam:
   662             case FmErrWrongParam:
   628                 HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   663                 FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   629                 break;
   664                 break;
   630             default:
   665             default:
   631                 HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   666                 FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   632         }
   667         }
   633     }
   668     }
   634 
   669 
   635 }
   670 }
   636  
   671  
   637 void FmFileBrowseWidget::on_moveAction_triggered()
   672 void FmFileBrowseWidget::on_moveAction_triggered()
   638 {
   673 {
   639     QStringList fileList;
   674     QStringList fileList;
   640     fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) );
   675     fileList.push_back( mModel->filePath( mCurrentItem->modelIndex() ) );
   641 
   676 
   642     QString targetPathName = FmFileDialog::getExistingDirectory( 0, tr( "move to" ),
   677     QString targetPathName = FmFileDialog::getExistingDirectory( 0, hbTrId( "move to" ),
   643             QString(""), QStringList() );
   678             QString(""), QStringList() );
   644 
   679 
   645     if( !targetPathName.isEmpty() ) {
   680     if( !targetPathName.isEmpty() ) {
   646         targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   681         targetPathName = FmUtils::fillPathWithSplash( targetPathName );
   647 
   682 
   650             case FmErrNone:
   685             case FmErrNone:
   651                 // no error, do not show note to user
   686                 // no error, do not show note to user
   652                 break;
   687                 break;
   653             case FmErrAlreadyStarted:
   688             case FmErrAlreadyStarted:
   654                 // last operation have not finished
   689                 // last operation have not finished
   655                 HbMessageBox::information( hbTrId( "Operatin already started!" ) );
   690                 FmDlgUtils::information( hbTrId( "Operatin already started!" ) );
   656                 break;
   691                 break;
   657             case FmErrWrongParam:
   692             case FmErrWrongParam:
   658                 HbMessageBox::information( hbTrId( "Wrong parameters!" ) );
   693                 FmDlgUtils::information( hbTrId( "Wrong parameters!" ) );
   659                 break;
   694                 break;
   660             default:
   695             default:
   661                 HbMessageBox::information( hbTrId( "Operation fail to start!" ) );
   696                 FmDlgUtils::information( hbTrId( "Operation fail to start!" ) );
   662         }
   697         }
   663     }
   698     }
   664 }
   699 }
   665 
   700 
   666 
   701 
   667 void FmFileBrowseWidget::on_renameAction_triggered()
   702 void FmFileBrowseWidget::on_renameAction_triggered()
   668 {
   703 {
   669     QString filePath = mModel->filePath( mCurrentItem->modelIndex() );
   704     QString filePath = mModel->filePath( mCurrentItem->modelIndex() );
   670     QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() );
   705     QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() );
   671 
   706     int maxFileNameLength = FmUtils::getMaxFileNameLength();
       
   707     // regExpList used to disable primary action of text query dialog if input text is not match
       
   708     QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
       
   709 
       
   710     QString oldSuffix( fileInfo.suffix() );
   672     QString newName( fileInfo.fileName() );
   711     QString newName( fileInfo.fileName() );
   673     
   712     while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, regExpList,
   674     while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, true ) ){
   713             maxFileNameLength, QString() , true ) ){
       
   714         // remove whitespace from the start and the end.
       
   715         newName = newName.trimmed();
   675         QString newTargetPath = FmUtils::fillPathWithSplash(
   716         QString newTargetPath = FmUtils::fillPathWithSplash(
   676             fileInfo.absolutePath() ) + newName;
   717             fileInfo.absolutePath() ) + newName;
   677         QFileInfo newFileInfo( newTargetPath );
   718         QFileInfo newFileInfo( newTargetPath );
   678         if( newFileInfo.exists() ) {
   719         QString errString;
   679             HbMessageBox::information( hbTrId( "%1 already exist!" ).arg( newName ) );
   720         // check if name/path is available for use
       
   721         // add new Name to check, in order to avoid problem of newName is empty
       
   722         if( !FmUtils::checkNewFolderOrFile( newName, newTargetPath, errString ) ) {
       
   723             FmDlgUtils::information( errString );
   680             continue;
   724             continue;
   681         }
   725         }
   682 
       
   683         if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) {
   726         if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) {
   684             HbMessageBox::information( hbTrId("Rename failed!") );
   727             FmDlgUtils::information( hbTrId("Rename failed!") );
       
   728         }
       
   729         else {
       
   730             // Rename succeed
       
   731             if ( ( oldSuffix.compare( newFileInfo.suffix(), Qt::CaseInsensitive ) != 0 )
       
   732                 && newFileInfo.isFile() ) {
       
   733                 // popup warning when the suffix of file is changed.
       
   734                 FmDlgUtils::information( hbTrId( "File may become unusable when file name extension is changed" ) );        
       
   735             }   
   685         }
   736         }
   686         break;
   737         break;
   687     }   
   738     }
   688 }
   739 }
       
   740