24 |
24 |
25 FmFindResultModel::FmFindResultModel( QObject *parent ) |
25 FmFindResultModel::FmFindResultModel( QObject *parent ) |
26 : QAbstractListModel( parent ) |
26 : QAbstractListModel( parent ) |
27 { |
27 { |
28 init(); |
28 init(); |
29 QMetaObject::connectSlotsByName( this ); |
29 connect( mFindThread, SIGNAL(finished()), this, SIGNAL(finished()) ); |
|
30 connect( mFindThread, SIGNAL(found(int)), this, SLOT(on_findThread_found( int) ), Qt::BlockingQueuedConnection ); |
30 } |
31 } |
31 |
32 |
32 FmFindResultModel::~FmFindResultModel() |
33 FmFindResultModel::~FmFindResultModel() |
33 { |
34 { |
34 delete mIconProvider; |
35 delete mIconProvider; |
185 return mFindThread->isRunning(); |
186 return mFindThread->isRunning(); |
186 } |
187 } |
187 |
188 |
188 void FmFindResultModel::on_findThread_found( int count ) |
189 void FmFindResultModel::on_findThread_found( int count ) |
189 { |
190 { |
|
191 int size = mFindResult.size(); |
190 insertRows( mFindResult.size() - count, count ); |
192 insertRows( mFindResult.size() - count, count ); |
191 emit modelCountChanged( mFindResult.size() ); |
193 emit modelCountChanged( mFindResult.size() ); |
192 } |
194 } |
193 |
195 |
194 bool FmFindResultModel::indexValid( const QModelIndex &index ) const |
196 bool FmFindResultModel::indexValid( const QModelIndex &index ) const |
199 |
201 |
200 void FmFindResultModel::init() |
202 void FmFindResultModel::init() |
201 { |
203 { |
202 mFindThread = new FmFindThread( &mFindResult, this ); |
204 mFindThread = new FmFindThread( &mFindResult, this ); |
203 mFindThread->setObjectName( "findThread" ); |
205 mFindThread->setObjectName( "findThread" ); |
204 |
|
205 connect( mFindThread, SIGNAL(finished()), this, SIGNAL(finished()) ); |
|
206 |
|
207 mIconProvider = new QFileIconProvider(); |
206 mIconProvider = new QFileIconProvider(); |
208 } |
207 } |
209 |
208 |
210 bool FmFindResultModel::caseNameLessThan(const QString &s1, const QString &s2) |
209 bool FmFindResultModel::caseNameLessThan(const QString &s1, const QString &s2) |
211 { |
210 { |
233 |
232 |
234 bool FmFindResultModel::caseTypeLessThan(const QString &s1, const QString &s2) |
233 bool FmFindResultModel::caseTypeLessThan(const QString &s1, const QString &s2) |
235 { |
234 { |
236 QFileInfo info1( s1 ); |
235 QFileInfo info1( s1 ); |
237 QFileInfo info2( s2 ); |
236 QFileInfo info2( s2 ); |
238 |
237 |
239 return info1.suffix().toLower() < info2.suffix().toLower(); |
238 if( info1.isDir() != info2.isDir() ){ |
|
239 return info1.isDir(); |
|
240 } |
|
241 else{ |
|
242 return info1.suffix().toLower() < info2.suffix().toLower(); |
|
243 } |
240 } |
244 } |
241 |
245 |
242 |
246 |
243 void FmFindResultModel::sort ( int column, Qt::SortOrder order ) |
247 void FmFindResultModel::sort ( int column, Qt::SortOrder order ) |
244 { |
248 { |
245 Q_UNUSED( order ); |
249 Q_UNUSED( order ); |
|
250 |
|
251 // emit layoutAboutToBeChanged(); |
246 |
252 |
247 switch( ( SortFlag )column ) |
253 switch( ( SortFlag )column ) |
248 { |
254 { |
249 case Name: |
255 case Name: |
250 qSort(mFindResult.begin(), mFindResult.end(), caseNameLessThan); |
256 qSort( mFindResult.begin(), mFindResult.end(), caseNameLessThan ); |
251 break; |
257 break; |
252 case Time: |
258 case Time: |
253 qSort(mFindResult.begin(), mFindResult.end(), caseTimeLessThan); |
259 qSort( mFindResult.begin(), mFindResult.end(), caseTimeLessThan ); |
254 break; |
260 break; |
255 case Size: |
261 case Size: |
256 qSort(mFindResult.begin(), mFindResult.end(), caseSizeLessThan); |
262 qSort( mFindResult.begin(), mFindResult.end(), caseSizeLessThan ); |
257 break; |
263 break; |
258 case Type: |
264 case Type: |
259 qSort(mFindResult.begin(), mFindResult.end(), caseTypeLessThan); |
265 qSort( mFindResult.begin(), mFindResult.end(), caseTypeLessThan ); |
260 break; |
266 break; |
261 } |
267 } |
262 emit layoutChanged(); |
268 // emit layoutChanged(); |
263 } |
269 emit refresh(); |
|
270 } |