filemanager/src/fmfiledialog/src/fmfilewidget.cpp
changeset 25 b7bfdea70ca2
parent 16 ada7962b4308
child 32 39cf9ced4cc4
--- a/filemanager/src/fmfiledialog/src/fmfilewidget.cpp	Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/fmfiledialog/src/fmfilewidget.cpp	Fri Jun 25 17:08:34 2010 +0800
@@ -20,6 +20,8 @@
 #include "fmutils.h"
 #include "fmdrivemodel.h"
 #include "fmdrivewatcher.h"
+#include "fmcommon.h"
+#include "fmfileiconprovider.h"
 
 #include "hbstyle.h"
 #include "hbabstractitemview.h"
@@ -27,7 +29,7 @@
 
 #include <QModelIndex>
 #include <QGraphicsLinearLayout>
-#include <QDirModel>
+#include <QFileSystemModel>
 #include <QTime>
 #include <QFileInfo>
 
@@ -42,7 +44,8 @@
 FmFileWidget::~FmFileWidget()
 {
     setModel( 0 );
-    delete mDirModel;
+    delete mFileSystemModel;
+    delete mFileIconProvider;
     delete mDriveModel;
     
     mDriveWatcher->cancelWatch();
@@ -56,8 +59,8 @@
     if( !index.isValid() ) {
         return QFileInfo();
     }
-    if( mCurrentModel == mDirModel ) {
-        return mDirModel->fileInfo( index );
+    if( mCurrentModel == mFileSystemModel ) {
+        return mFileSystemModel->fileInfo( index );
     } else {
         return QFileInfo();
     }
@@ -65,65 +68,92 @@
 
 void FmFileWidget::setRootPath( const QString &pathName )
 {
-    if( pathName.isEmpty() || !FmUtils::isPathAccessabel( pathName ) ) {
+    FmLogger::log( "FmFileWidget::setRootPath start" );
+	// If path is empty or can not access, set model as DriveModel
+	// Otherwise set model as FileSystemModel, means it will return to drive view if error occur.
+    if( ( pathName.isEmpty() ) || ( FmErrNone != FmUtils::isPathAccessabel( pathName ) ) ) {
+        FmLogger::log( "FmFileWidget::setRootPath set drive model" );
         setModel( mDriveModel );
+        FmLogger::log( "FmFileWidget::setRootPath set drive model end" );
         emit pathChanged( QString() );
     } else {
-        setModel( mDirModel );
-        mListView->setRootIndex( mDirModel->index( pathName ) );
+        FmLogger::log( "FmFileWidget::setRootPath set dir model end" );
+        setModel( mFileSystemModel );
+        FmLogger::log( "FmFileWidget::setRootPath set dir model end" );
+		mListView->setRootIndex( mFileSystemModel->setRootPath( pathName ) );
+        FmLogger::log( "FmFileWidget::setRootPath set rootIndex" );
         emit pathChanged( pathName );
     }    
+    FmLogger::log( "FmFileWidget::setRootPath end" );
 }
-
-
 void FmFileWidget::on_list_activated( const QModelIndex &index )
+    {
+    mActivatedModelIndex = index;
+    emit listActivated();
+    }
+
+void FmFileWidget::on_listActivated()
 {
+    FmLogger::log("FmFileWidget::on_list_activated start" );
     if( mCurrentModel == mDriveModel ) {
-        QString driveName = mDriveModel->driveName( index );
+    //If currenty model is DriveModel, open drive and set path
+        QString driveName = mDriveModel->driveName( mActivatedModelIndex );
         QString checkedPath = FmUtils::checkDriveToFolderFilter( driveName );
         if( checkedPath.isEmpty() ) {
+            FmLogger::log("FmFileWidget::on_list_activated end becaise checkedpath empty" );
             return;
         }
 
-        setModel( mDirModel );
-        mListView->setRootIndex( mDirModel->index( checkedPath ) );
+        FmLogger::log("FmFileWidget::on_list_activated setModel dir start" );
+        setModel( mFileSystemModel );
+        FmLogger::log("FmFileWidget::on_list_activated setModel dir end" );
+        setRootPath( checkedPath );
+        FmLogger::log("FmFileWidget::on_list_activated setRootIndex" );
         emit pathChanged( checkedPath );
+        FmLogger::log("FmFileWidget::on_list_activated finish emit pathChanged" );
     }
-    else if( mCurrentModel == mDirModel ) {
-        if ( mDirModel->isDir(index) ) {
-            changeRootIndex( index );
+    else if( mCurrentModel == mFileSystemModel ) {
+    //If currenty model is FileSystemModel, open path or emit file activate signal.
+        if ( mFileSystemModel->isDir( mActivatedModelIndex ) ) {
+            FmLogger::log("FmFileWidget::on_list_activated start changeRootIndex" );
+            changeRootIndex( mActivatedModelIndex );
+            FmLogger::log("FmFileWidget::on_list_activated finish changeRootIndex" );
         } else {
-            QFileInfo fileInfo( mDirModel->filePath( index ) );
+            QFileInfo fileInfo( mFileSystemModel->filePath( mActivatedModelIndex ) );
             if( fileInfo.isFile() ) {
                 emit fileActivated( fileInfo.fileName() );
+                FmLogger::log("FmFileWidget::on_list_activated finish emit fileActivated" );
             }
         }
     } else {
         Q_ASSERT( false );
     }
+    FmLogger::log("FmFileWidget::on_list_activated end" );
 }
 
 void FmFileWidget::setModelFilter( QDir::Filters filters )
 {
-    mDirModel->setFilter( filters );
+    mFileSystemModel->setFilter( filters );
 }
 
 void FmFileWidget::setNameFilters( const QStringList &nameFilters )
 {
-    mDirModel->setNameFilters( nameFilters );
+    mFileSystemModel->setNameFilters( nameFilters );
 }
 
 void FmFileWidget::changeRootIndex( const QModelIndex &index )
 {
-    if( mCurrentModel != mDirModel ) {
+    FmLogger::log("FmFileWidget::changeRootIndex start" );
+    if( mCurrentModel != mFileSystemModel ) {
+        FmLogger::log("FmFileWidget::changeRootIndex end because model not equal mFileSystemModel" );
         return;
     }
 
-    mDirModel->fetchMore(index);
-    mListView->setRootIndex( index );
-    QFileInfo fileInfo = mDirModel->fileInfo( mListView->rootIndex() );
-    QString string = fileInfo.absoluteFilePath();
-    emit pathChanged( string );
+    mFileSystemModel->fetchMore(index);
+	QString filePath = mFileSystemModel->fileInfo( index ).absoluteFilePath();
+    // pathChanged signal will be emitted in setRootPath
+	setRootPath( filePath );
+    FmLogger::log("FmFileWidget::changeRootIndex end" );
 }
 
 void FmFileWidget::init()
@@ -138,10 +168,13 @@
 
     mDriveModel = new FmDriveModel( this, 
         FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | FmDriveModel::HideUnAvailableDrive );
-    qDebug("constructed dirveModel");
+    
     qDebug( QTime::currentTime().toString().toUtf8().data() );
-    mDirModel = new QDirModel( this );
-    qDebug("constructed dirModel");
+    mFileSystemModel = new QFileSystemModel( this );
+    mFileIconProvider = new FmFileIconProvider();
+    mFileSystemModel->setIconProvider( mFileIconProvider );
+    qDebug("constructed mFileSystemModel");
+    
     qDebug( QTime::currentTime().toString().toUtf8().data() );
     setModel( mDriveModel );
     qDebug("setmodel");
@@ -154,7 +187,9 @@
 //    QMetaObject::connectSlotsByName( this );
     connect( mListView, SIGNAL( activated( QModelIndex ) ),
         this, SLOT( on_list_activated( QModelIndex ) ) );
-    
+    connect( this, SIGNAL( listActivated() ),
+        this, SLOT( on_listActivated() ), Qt::QueuedConnection );
+        
     connect( mDriveWatcher, SIGNAL( driveAddedOrChanged() ),
             this, SLOT( on_driveWatcher_driveAddedOrChanged() ) );
     
@@ -172,7 +207,7 @@
     ViewType viewType = DriveView;
     if( mCurrentModel == mDriveModel ) {
         viewType = DriveView;
-    } else if( mCurrentModel == mDirModel ) {
+    } else if( mCurrentModel == mFileSystemModel ) {
         viewType = DirView;
     } else {
         Q_ASSERT( false );
@@ -186,6 +221,8 @@
     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
+    // 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();
     }
@@ -202,7 +239,7 @@
         setModel( mDriveModel );
         emit pathChanged( QString() );
     } else if( currentViewType() == DirView ) {
-        if( !FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) {
+        if( FmErrNone != FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) {
             // path not available, set model to drive
             FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged path not availeable, set drivemodel:"
                     + currentPath().absoluteFilePath() ) );