54 { |
57 { |
55 QModelIndex index( mListView->rootIndex() ); |
58 QModelIndex index( mListView->rootIndex() ); |
56 if( !index.isValid() ) { |
59 if( !index.isValid() ) { |
57 return QFileInfo(); |
60 return QFileInfo(); |
58 } |
61 } |
59 if( mCurrentModel == mDirModel ) { |
62 if( mCurrentModel == mFileSystemModel ) { |
60 return mDirModel->fileInfo( index ); |
63 return mFileSystemModel->fileInfo( index ); |
61 } else { |
64 } else { |
62 return QFileInfo(); |
65 return QFileInfo(); |
63 } |
66 } |
64 } |
67 } |
65 |
68 |
66 void FmFileWidget::setRootPath( const QString &pathName ) |
69 void FmFileWidget::setRootPath( const QString &pathName ) |
67 { |
70 { |
68 if( pathName.isEmpty() || !FmUtils::isPathAccessabel( pathName ) ) { |
71 FmLogger::log( "FmFileWidget::setRootPath start" ); |
|
72 // If path is empty or can not access, set model as DriveModel |
|
73 // Otherwise set model as FileSystemModel, means it will return to drive view if error occur. |
|
74 if( ( pathName.isEmpty() ) || ( FmErrNone != FmUtils::isPathAccessabel( pathName ) ) ) { |
|
75 FmLogger::log( "FmFileWidget::setRootPath set drive model" ); |
69 setModel( mDriveModel ); |
76 setModel( mDriveModel ); |
|
77 FmLogger::log( "FmFileWidget::setRootPath set drive model end" ); |
70 emit pathChanged( QString() ); |
78 emit pathChanged( QString() ); |
71 } else { |
79 } else { |
72 setModel( mDirModel ); |
80 FmLogger::log( "FmFileWidget::setRootPath set dir model end" ); |
73 mListView->setRootIndex( mDirModel->index( pathName ) ); |
81 setModel( mFileSystemModel ); |
|
82 FmLogger::log( "FmFileWidget::setRootPath set dir model end" ); |
|
83 mListView->setRootIndex( mFileSystemModel->setRootPath( pathName ) ); |
|
84 FmLogger::log( "FmFileWidget::setRootPath set rootIndex" ); |
74 emit pathChanged( pathName ); |
85 emit pathChanged( pathName ); |
75 } |
86 } |
76 } |
87 FmLogger::log( "FmFileWidget::setRootPath end" ); |
77 |
88 } |
78 |
|
79 void FmFileWidget::on_list_activated( const QModelIndex &index ) |
89 void FmFileWidget::on_list_activated( const QModelIndex &index ) |
80 { |
90 { |
|
91 mActivatedModelIndex = index; |
|
92 emit listActivated(); |
|
93 } |
|
94 |
|
95 void FmFileWidget::on_listActivated() |
|
96 { |
|
97 FmLogger::log("FmFileWidget::on_list_activated start" ); |
81 if( mCurrentModel == mDriveModel ) { |
98 if( mCurrentModel == mDriveModel ) { |
82 QString driveName = mDriveModel->driveName( index ); |
99 //If currenty model is DriveModel, open drive and set path |
|
100 QString driveName = mDriveModel->driveName( mActivatedModelIndex ); |
83 QString checkedPath = FmUtils::checkDriveToFolderFilter( driveName ); |
101 QString checkedPath = FmUtils::checkDriveToFolderFilter( driveName ); |
84 if( checkedPath.isEmpty() ) { |
102 if( checkedPath.isEmpty() ) { |
|
103 FmLogger::log("FmFileWidget::on_list_activated end becaise checkedpath empty" ); |
85 return; |
104 return; |
86 } |
105 } |
87 |
106 |
88 setModel( mDirModel ); |
107 FmLogger::log("FmFileWidget::on_list_activated setModel dir start" ); |
89 mListView->setRootIndex( mDirModel->index( checkedPath ) ); |
108 setModel( mFileSystemModel ); |
|
109 FmLogger::log("FmFileWidget::on_list_activated setModel dir end" ); |
|
110 setRootPath( checkedPath ); |
|
111 FmLogger::log("FmFileWidget::on_list_activated setRootIndex" ); |
90 emit pathChanged( checkedPath ); |
112 emit pathChanged( checkedPath ); |
91 } |
113 FmLogger::log("FmFileWidget::on_list_activated finish emit pathChanged" ); |
92 else if( mCurrentModel == mDirModel ) { |
114 } |
93 if ( mDirModel->isDir(index) ) { |
115 else if( mCurrentModel == mFileSystemModel ) { |
94 changeRootIndex( index ); |
116 //If currenty model is FileSystemModel, open path or emit file activate signal. |
|
117 if ( mFileSystemModel->isDir( mActivatedModelIndex ) ) { |
|
118 FmLogger::log("FmFileWidget::on_list_activated start changeRootIndex" ); |
|
119 changeRootIndex( mActivatedModelIndex ); |
|
120 FmLogger::log("FmFileWidget::on_list_activated finish changeRootIndex" ); |
95 } else { |
121 } else { |
96 QFileInfo fileInfo( mDirModel->filePath( index ) ); |
122 QFileInfo fileInfo( mFileSystemModel->filePath( mActivatedModelIndex ) ); |
97 if( fileInfo.isFile() ) { |
123 if( fileInfo.isFile() ) { |
98 emit fileActivated( fileInfo.fileName() ); |
124 emit fileActivated( fileInfo.fileName() ); |
|
125 FmLogger::log("FmFileWidget::on_list_activated finish emit fileActivated" ); |
99 } |
126 } |
100 } |
127 } |
101 } else { |
128 } else { |
102 Q_ASSERT( false ); |
129 Q_ASSERT( false ); |
103 } |
130 } |
|
131 FmLogger::log("FmFileWidget::on_list_activated end" ); |
104 } |
132 } |
105 |
133 |
106 void FmFileWidget::setModelFilter( QDir::Filters filters ) |
134 void FmFileWidget::setModelFilter( QDir::Filters filters ) |
107 { |
135 { |
108 mDirModel->setFilter( filters ); |
136 mFileSystemModel->setFilter( filters ); |
109 } |
137 } |
110 |
138 |
111 void FmFileWidget::setNameFilters( const QStringList &nameFilters ) |
139 void FmFileWidget::setNameFilters( const QStringList &nameFilters ) |
112 { |
140 { |
113 mDirModel->setNameFilters( nameFilters ); |
141 mFileSystemModel->setNameFilters( nameFilters ); |
114 } |
142 } |
115 |
143 |
116 void FmFileWidget::changeRootIndex( const QModelIndex &index ) |
144 void FmFileWidget::changeRootIndex( const QModelIndex &index ) |
117 { |
145 { |
118 if( mCurrentModel != mDirModel ) { |
146 FmLogger::log("FmFileWidget::changeRootIndex start" ); |
|
147 if( mCurrentModel != mFileSystemModel ) { |
|
148 FmLogger::log("FmFileWidget::changeRootIndex end because model not equal mFileSystemModel" ); |
119 return; |
149 return; |
120 } |
150 } |
121 |
151 |
122 mDirModel->fetchMore(index); |
152 mFileSystemModel->fetchMore(index); |
123 mListView->setRootIndex( index ); |
153 QString filePath = mFileSystemModel->fileInfo( index ).absoluteFilePath(); |
124 QFileInfo fileInfo = mDirModel->fileInfo( mListView->rootIndex() ); |
154 // pathChanged signal will be emitted in setRootPath |
125 QString string = fileInfo.absoluteFilePath(); |
155 setRootPath( filePath ); |
126 emit pathChanged( string ); |
156 FmLogger::log("FmFileWidget::changeRootIndex end" ); |
127 } |
157 } |
128 |
158 |
129 void FmFileWidget::init() |
159 void FmFileWidget::init() |
130 { |
160 { |
131 mLayout = new QGraphicsLinearLayout( this ); |
161 mLayout = new QGraphicsLinearLayout( this ); |
136 mListView->setObjectName( "list" ); |
166 mListView->setObjectName( "list" ); |
137 mLayout->addItem( mListView ); |
167 mLayout->addItem( mListView ); |
138 |
168 |
139 mDriveModel = new FmDriveModel( this, |
169 mDriveModel = new FmDriveModel( this, |
140 FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | FmDriveModel::HideUnAvailableDrive ); |
170 FmDriveModel::FillWithVolume | FmDriveModel::FillWithDefaultVolume | FmDriveModel::HideUnAvailableDrive ); |
141 qDebug("constructed dirveModel"); |
171 |
142 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
172 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
143 mDirModel = new QDirModel( this ); |
173 mFileSystemModel = new QFileSystemModel( this ); |
144 qDebug("constructed dirModel"); |
174 mFileIconProvider = new FmFileIconProvider(); |
|
175 mFileSystemModel->setIconProvider( mFileIconProvider ); |
|
176 qDebug("constructed mFileSystemModel"); |
|
177 |
145 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
178 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
146 setModel( mDriveModel ); |
179 setModel( mDriveModel ); |
147 qDebug("setmodel"); |
180 qDebug("setmodel"); |
148 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
181 qDebug( QTime::currentTime().toString().toUtf8().data() ); |
149 |
182 |
200 if( currentViewType() == DriveView ) { |
237 if( currentViewType() == DriveView ) { |
201 setModel( 0 ); |
238 setModel( 0 ); |
202 setModel( mDriveModel ); |
239 setModel( mDriveModel ); |
203 emit pathChanged( QString() ); |
240 emit pathChanged( QString() ); |
204 } else if( currentViewType() == DirView ) { |
241 } else if( currentViewType() == DirView ) { |
205 if( !FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) { |
242 if( FmErrNone != FmUtils::isPathAccessabel( currentPath().absoluteFilePath() ) ) { |
206 // path not available, set model to drive |
243 // path not available, set model to drive |
207 FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged path not availeable, set drivemodel:" |
244 FmLogger::log( QString( "FmFileDialog_FmFileWidget::on_driveWatcher_driveAddedOrChanged path not availeable, set drivemodel:" |
208 + currentPath().absoluteFilePath() ) ); |
245 + currentPath().absoluteFilePath() ) ); |
209 setModel( mDriveModel ); |
246 setModel( mDriveModel ); |
210 emit pathChanged( QString() ); |
247 emit pathChanged( QString() ); |