summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-24 02:47:03 (UTC)
committer alwin <alwin>2004-02-24 02:47:03 (UTC)
commitf196130d43642f2397ddadeed72e3ea062cda281 (patch) (unidiff)
tree1916d2e66a8ea4fb149397b71888057c62156091
parent4baf741237a4c4575b3efe0bff6c4e143902b7ec (diff)
downloadopie-f196130d43642f2397ddadeed72e3ea062cda281.zip
opie-f196130d43642f2397ddadeed72e3ea062cda281.tar.gz
opie-f196130d43642f2397ddadeed72e3ea062cda281.tar.bz2
- check now for the storage media flag "check =" in DocumentListPrivate::appendDocpath
- fixed a possible segmentation fault in DocumentListPrivate::nextFile
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 39dc7c9..63f853e 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -188,503 +188,510 @@ void DocumentList::timerEvent( QTimerEvent *te )
188 if ( te->timerId() == d->tid ) { 188 if ( te->timerId() == d->tid ) {
189 // Do 3 at a time 189 // Do 3 at a time
190 for (int i = 0; i < 3; i++ ) { 190 for (int i = 0; i < 3; i++ ) {
191 const DocLnk *lnk = d->iterate(); 191 const DocLnk *lnk = d->iterate();
192 if ( lnk ) { 192 if ( lnk ) {
193 add( *lnk ); 193 add( *lnk );
194 } else { 194 } else {
195 // stop when done 195 // stop when done
196 pause(); 196 pause();
197 if ( d->serverGui ) 197 if ( d->serverGui )
198 d->serverGui->documentScanningProgress( 100 ); 198 d->serverGui->documentScanningProgress( 100 );
199 if ( d->needToSendAllDocLinks ) 199 if ( d->needToSendAllDocLinks )
200 sendAllDocLinks(); 200 sendAllDocLinks();
201 break; 201 break;
202 } 202 }
203 } 203 }
204 } 204 }
205} 205}
206 206
207 207
208void DocumentList::reloadAppLnks() 208void DocumentList::reloadAppLnks()
209{ 209{
210 if ( d->sendAppLnks && d->serverGui ) { 210 if ( d->sendAppLnks && d->serverGui ) {
211 d->serverGui->applicationScanningProgress( 0 ); 211 d->serverGui->applicationScanningProgress( 0 );
212 d->serverGui->allApplicationsRemoved(); 212 d->serverGui->allApplicationsRemoved();
213 } 213 }
214 214
215 delete appLnkSet; 215 delete appLnkSet;
216 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 216 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
217 217
218 if ( d->sendAppLnks && d->serverGui ) { 218 if ( d->sendAppLnks && d->serverGui ) {
219 static QStringList prevTypeList; 219 static QStringList prevTypeList;
220 QStringList types = appLnkSet->types(); 220 QStringList types = appLnkSet->types();
221 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 221 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
222 if ( !(*ittypes).isEmpty() ) { 222 if ( !(*ittypes).isEmpty() ) {
223 if ( !prevTypeList.contains(*ittypes) ) { 223 if ( !prevTypeList.contains(*ittypes) ) {
224 QString name = appLnkSet->typeName(*ittypes); 224 QString name = appLnkSet->typeName(*ittypes);
225 QPixmap pm = appLnkSet->typePixmap(*ittypes); 225 QPixmap pm = appLnkSet->typePixmap(*ittypes);
226 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 226 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
227 227
228 if (pm.isNull()) { 228 if (pm.isNull()) {
229 QImage img( Resource::loadImage( "UnknownDocument" ) ); 229 QImage img( Resource::loadImage( "UnknownDocument" ) );
230 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 230 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
231 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); 231 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
232 } 232 }
233 233
234 //qDebug("adding type %s", (*ittypes).latin1()); 234 //qDebug("adding type %s", (*ittypes).latin1());
235 235
236 // ### our current launcher expects docs tab to be last 236 // ### our current launcher expects docs tab to be last
237 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 237 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
238 } 238 }
239 prevTypeList.remove(*ittypes); 239 prevTypeList.remove(*ittypes);
240 } 240 }
241 } 241 }
242 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 242 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
243 //qDebug("removing type %s", (*ittypes).latin1()); 243 //qDebug("removing type %s", (*ittypes).latin1());
244 d->serverGui->typeRemoved(*ittypes); 244 d->serverGui->typeRemoved(*ittypes);
245 } 245 }
246 prevTypeList = types; 246 prevTypeList = types;
247 } 247 }
248 248
249 QListIterator<AppLnk> itapp( appLnkSet->children() ); 249 QListIterator<AppLnk> itapp( appLnkSet->children() );
250 AppLnk* l; 250 AppLnk* l;
251 while ( (l=itapp.current()) ) { 251 while ( (l=itapp.current()) ) {
252 ++itapp; 252 ++itapp;
253 if ( d->sendAppLnks && d->serverGui ) 253 if ( d->sendAppLnks && d->serverGui )
254 d->serverGui->applicationAdded( l->type(), *l ); 254 d->serverGui->applicationAdded( l->type(), *l );
255 } 255 }
256 256
257 if ( d->sendAppLnks && d->serverGui ) 257 if ( d->sendAppLnks && d->serverGui )
258 d->serverGui->applicationScanningProgress( 100 ); 258 d->serverGui->applicationScanningProgress( 100 );
259} 259}
260 260
261void DocumentList::reloadDocLnks() 261void DocumentList::reloadDocLnks()
262{ 262{
263 if ( !d->scanDocs ) 263 if ( !d->scanDocs )
264 return; 264 return;
265 265
266 if ( d->sendDocLnks && d->serverGui ) { 266 if ( d->sendDocLnks && d->serverGui ) {
267 d->serverGui->documentScanningProgress( 0 ); 267 d->serverGui->documentScanningProgress( 0 );
268 d->serverGui->allDocumentsRemoved(); 268 d->serverGui->allDocumentsRemoved();
269 } 269 }
270 270
271 rescan(); 271 rescan();
272} 272}
273 273
274void DocumentList::linkChanged( QString arg ) 274void DocumentList::linkChanged( QString arg )
275{ 275{
276 //qDebug( "linkchanged( %s )", arg.latin1() ); 276 //qDebug( "linkchanged( %s )", arg.latin1() );
277 277
278 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { 278 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
279 reloadAppLnks(); 279 reloadAppLnks();
280 } else { 280 } else {
281 281
282 const QList<DocLnk> &list = d->dls.children(); 282 const QList<DocLnk> &list = d->dls.children();
283 QListIterator<DocLnk> it( list ); 283 QListIterator<DocLnk> it( list );
284 while ( it.current() ) { 284 while ( it.current() ) {
285 DocLnk *doc = it.current(); 285 DocLnk *doc = it.current();
286 ++it; 286 ++it;
287 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 287 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
288 || ( doc->fileKnown() && doc->file() == arg ) ) { 288 || ( doc->fileKnown() && doc->file() == arg ) ) {
289 //qDebug( "found old link" ); 289 //qDebug( "found old link" );
290 DocLnk* dl = new DocLnk( arg ); 290 DocLnk* dl = new DocLnk( arg );
291 // add new one if it exists and matches the mimetype 291 // add new one if it exists and matches the mimetype
292 if ( d->store( dl ) ) { 292 if ( d->store( dl ) ) {
293 // Existing link has been changed, send old link ref and a ref 293 // Existing link has been changed, send old link ref and a ref
294 // to the new link 294 // to the new link
295 //qDebug( "change case" ); 295 //qDebug( "change case" );
296 if ( d->serverGui ) 296 if ( d->serverGui )
297 d->serverGui->documentChanged( *doc, *dl ); 297 d->serverGui->documentChanged( *doc, *dl );
298 298
299 } else { 299 } else {
300 // Link has been removed or doesn't match the mimetypes any more 300 // Link has been removed or doesn't match the mimetypes any more
301 // so we aren't interested in it, so take it away from the list 301 // so we aren't interested in it, so take it away from the list
302 //qDebug( "removal case" ); 302 //qDebug( "removal case" );
303 if ( d->serverGui ) 303 if ( d->serverGui )
304 d->serverGui->documentRemoved( *doc ); 304 d->serverGui->documentRemoved( *doc );
305 305
306 } 306 }
307 d->dls.remove( doc ); // remove old link from docLnkSet 307 d->dls.remove( doc ); // remove old link from docLnkSet
308 delete doc; 308 delete doc;
309 return; 309 return;
310 } 310 }
311 } 311 }
312 // Didn't find existing link, must be new 312 // Didn't find existing link, must be new
313 DocLnk* dl = new DocLnk( arg ); 313 DocLnk* dl = new DocLnk( arg );
314 if ( d->store( dl ) ) { 314 if ( d->store( dl ) ) {
315 // Add if it's a link we are interested in 315 // Add if it's a link we are interested in
316 //qDebug( "add case" ); 316 //qDebug( "add case" );
317 add( *dl ); 317 add( *dl );
318 } 318 }
319 319
320 } 320 }
321} 321}
322 322
323void DocumentList::restoreDone() 323void DocumentList::restoreDone()
324{ 324{
325 reloadAppLnks(); 325 reloadAppLnks();
326 reloadDocLnks(); 326 reloadDocLnks();
327} 327}
328 328
329void DocumentList::storageChanged() 329void DocumentList::storageChanged()
330{ 330{
331 // ### can implement better 331 // ### can implement better
332 reloadAppLnks(); 332 reloadAppLnks();
333 reloadDocLnks(); 333 reloadDocLnks();
334 // ### Optimization opportunity 334 // ### Optimization opportunity
335 // Could be a bit more intelligent and somehow work out which 335 // Could be a bit more intelligent and somehow work out which
336 // mtab entry has changed and then only scan that and add and remove 336 // mtab entry has changed and then only scan that and add and remove
337 // links appropriately. 337 // links appropriately.
338// rescan(); 338// rescan();
339} 339}
340 340
341void DocumentList::sendAllDocLinks() 341void DocumentList::sendAllDocLinks()
342{ 342{
343 if ( d->tid != 0 ) { 343 if ( d->tid != 0 ) {
344 // We are in the middle of scanning, set a flag so 344 // We are in the middle of scanning, set a flag so
345 // we do this when we finish our scanning 345 // we do this when we finish our scanning
346 d->needToSendAllDocLinks = true; 346 d->needToSendAllDocLinks = true;
347 return; 347 return;
348 } 348 }
349 349
350 QString contents; 350 QString contents;
351 Categories cats; 351 Categories cats;
352 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 352 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
353 DocLnk *doc = it.current(); 353 DocLnk *doc = it.current();
354 QFileInfo fi( doc->file() ); 354 QFileInfo fi( doc->file() );
355 if ( !fi.exists() ) 355 if ( !fi.exists() )
356 continue; 356 continue;
357 357
358 bool fake = !doc->linkFileKnown(); 358 bool fake = !doc->linkFileKnown();
359 if ( !fake ) { 359 if ( !fake ) {
360 QFile f( doc->linkFile() ); 360 QFile f( doc->linkFile() );
361 if ( f.open( IO_ReadOnly ) ) { 361 if ( f.open( IO_ReadOnly ) ) {
362 QTextStream ts( &f ); 362 QTextStream ts( &f );
363 ts.setEncoding( QTextStream::UnicodeUTF8 ); 363 ts.setEncoding( QTextStream::UnicodeUTF8 );
364 contents += ts.read(); 364 contents += ts.read();
365 f.close(); 365 f.close();
366 } else 366 } else
367 fake = TRUE; 367 fake = TRUE;
368 } 368 }
369 if (fake) { 369 if (fake) {
370 contents += "[Desktop Entry]\n"; // No tr 370 contents += "[Desktop Entry]\n"; // No tr
371 contents += "Categories = " + // No tr 371 contents += "Categories = " + // No tr
372 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 372 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
373 contents += "Name = "+doc->name()+"\n"; // No tr 373 contents += "Name = "+doc->name()+"\n"; // No tr
374 contents += "Type = "+doc->type()+"\n"; // No tr 374 contents += "Type = "+doc->type()+"\n"; // No tr
375 } 375 }
376 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 376 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
377 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 377 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
378 } 378 }
379 379
380 //qDebug( "sending length %d", contents.length() ); 380 //qDebug( "sending length %d", contents.length() );
381#ifndef QT_NO_COP 381#ifndef QT_NO_COP
382 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 382 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
383 e << contents; 383 e << contents;
384#endif 384#endif
385 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); 385 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() );
386 386
387 d->needToSendAllDocLinks = false; 387 d->needToSendAllDocLinks = false;
388} 388}
389 389
390 390
391 391
392 392
393 393
394 394
395 395
396 396
397 397
398 398
399 399
400 400
401 401
402 402
403 403
404 404
405 405
406 406
407 407
408 408
409 409
410 410
411 411
412 412
413DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) 413DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
414{ 414{
415 storage = new StorageInfo( this ); 415 storage = new StorageInfo( this );
416 serverGui = gui; 416 serverGui = gui;
417 if ( serverGui ) { 417 if ( serverGui ) {
418 sendAppLnks = serverGui->requiresApplications(); 418 sendAppLnks = serverGui->requiresApplications();
419 sendDocLnks = serverGui->requiresDocuments(); 419 sendDocLnks = serverGui->requiresDocuments();
420 } else { 420 } else {
421 sendAppLnks = false; 421 sendAppLnks = false;
422 sendDocLnks = false; 422 sendDocLnks = false;
423 } 423 }
424 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 424 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
425 listDirs[i] = 0; 425 listDirs[i] = 0;
426 lists[i] = 0; 426 lists[i] = 0;
427 listPositions[i] = 0; 427 listPositions[i] = 0;
428 } 428 }
429 initialize(); 429 initialize();
430 tid = 0; 430 tid = 0;
431} 431}
432 432
433void DocumentListPrivate::appendDocpath(FileSystem*fs) 433void DocumentListPrivate::appendDocpath(FileSystem*fs)
434{ 434{
435 QDir defPath(fs->path()+"/Documents"); 435 QDir defPath(fs->path()+"/Documents");
436 QFileInfo f(fs->path()+"/.opiestorage.cf"); 436 QFileInfo f(fs->path()+"/.opiestorage.cf");
437 if (!f.exists()) { 437 if (!f.exists()) {
438 Mediadlg dlg(fs); 438 Mediadlg dlg(fs);
439 if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) { 439 if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) {
440 return; 440 return;
441 } 441 }
442 } 442 }
443 Config conf(f.filePath(), Config::File ); 443 Config conf(f.filePath(), Config::File );
444 conf.setGroup("main");
445 if (!conf.readBoolEntry("check",false)) {
446 return;
447 }
444 conf.setGroup("subdirs"); 448 conf.setGroup("subdirs");
445 bool read_all = conf.readBoolEntry("wholemedia",true); 449 bool read_all = conf.readBoolEntry("wholemedia",true);
446 if (read_all) { 450 if (read_all) {
447 docPaths+=fs->path(); 451 docPaths+=fs->path();
448 return; 452 return;
449 } 453 }
450 QStringList subDirs = conf.readListEntry("subdirs",':'); 454 QStringList subDirs = conf.readListEntry("subdirs",':');
451 if (subDirs.isEmpty()) { 455 if (subDirs.isEmpty()) {
452 if (defPath.exists()) { 456 if (defPath.exists()) {
453 docPaths+=defPath.path(); 457 docPaths+=defPath.path();
454 } 458 }
455 return; 459 return;
456 } 460 }
457 for (unsigned c = 0; c < subDirs.count();++c) { 461 for (unsigned c = 0; c < subDirs.count();++c) {
458 QDir docDir(QString(fs->path()+"/"+subDirs[c])); 462 QDir docDir(QString(fs->path()+"/"+subDirs[c]));
459 if (docDir.exists()) { 463 if (docDir.exists()) {
460 docPaths+=docDir.path(); 464 docPaths+=docDir.path();
461 } 465 }
462 } 466 }
463} 467}
464 468
465void DocumentListPrivate::initialize() 469void DocumentListPrivate::initialize()
466{ 470{
467 // Reset 471 // Reset
468 dls.clear(); 472 dls.clear();
469 docPaths.clear(); 473 docPaths.clear();
470 reference.clear(); 474 reference.clear();
471 475
472 QDir docDir( QPEApplication::documentDir() ); 476 QDir docDir( QPEApplication::documentDir() );
473 if ( docDir.exists() ) 477 if ( docDir.exists() )
474 docPaths += QPEApplication::documentDir(); 478 docPaths += QPEApplication::documentDir();
475 int i = 1; 479 int i = 1;
476 const QList<FileSystem> &fs = storage->fileSystems(); 480 const QList<FileSystem> &fs = storage->fileSystems();
477 QListIterator<FileSystem> it( fs ); 481 QListIterator<FileSystem> it( fs );
478 for ( ; it.current(); ++it ) { 482 for ( ; it.current(); ++it ) {
479 if ( (*it)->isRemovable() ) { 483 if ( (*it)->isRemovable() ) {
480 appendDocpath((*it)); 484 appendDocpath((*it));
481 ++i; 485 ++i;
482 } 486 }
483 } 487 }
484 488
485 for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { 489 for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) {
486 if ( listDirs[i] ) { 490 if ( listDirs[i] ) {
487 delete listDirs[i]; 491 delete listDirs[i];
488 listDirs[i] = 0; 492 listDirs[i] = 0;
489 } 493 }
490 lists[i] = 0; 494 lists[i] = 0;
491 listPositions[i] = 0; 495 listPositions[i] = 0;
492 } 496 }
493 497
494 docPathsSearched = 0; 498 docPathsSearched = 0;
495 searchDepth = -1; 499 searchDepth = -1;
496 state = Find; 500 state = Find;
497 dit = 0; 501 dit = 0;
498} 502}
499 503
500 504
501DocumentListPrivate::~DocumentListPrivate() 505DocumentListPrivate::~DocumentListPrivate()
502{ 506{
503 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) 507 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ )
504 if ( listDirs[i] ) 508 if ( listDirs[i] )
505 delete listDirs[i]; 509 delete listDirs[i];
506 delete dit; 510 delete dit;
507} 511}
508 512
509 513
510void DocumentListPrivate::estimatedPercentScanned() 514void DocumentListPrivate::estimatedPercentScanned()
511{ 515{
512 double overallProgress = 0.0; 516 double overallProgress = 0.0;
513 double levelWeight = 75.0; 517 double levelWeight = 75.0;
514 518
515 int topCount = docPaths.count(); 519 int topCount = docPaths.count();
516 if ( topCount > 1 ) { 520 if ( topCount > 1 ) {
517 levelWeight = levelWeight / topCount; 521 levelWeight = levelWeight / topCount;
518 overallProgress += (docPathsSearched - 1) * levelWeight; 522 overallProgress += (docPathsSearched - 1) * levelWeight;
519 } 523 }
520 524
521 for ( int d = 0; d <= searchDepth; d++ ) { 525 for ( int d = 0; d <= searchDepth; d++ ) {
522 if ( listDirs[d] ) { 526 if ( listDirs[d] ) {
523 int items = lists[d]->count(); 527 int items = lists[d]->count();
524 if ( items > 1 ) { 528 if ( items > 1 ) {
525 levelWeight = levelWeight / items; 529 levelWeight = levelWeight / items;
526 // Take in to account "." and ".." 530 // Take in to account "." and ".."
527 overallProgress += (listPositions[d] - 3) * levelWeight; 531 overallProgress += (listPositions[d] - 3) * levelWeight;
528 } 532 }
529 } else { 533 } else {
530 break; 534 break;
531 } 535 }
532 } 536 }
533 537
534 // qDebug( "overallProgress: %f", overallProgress ); 538 // qDebug( "overallProgress: %f", overallProgress );
535 539
536 if ( serverGui ) 540 if ( serverGui )
537 serverGui->documentScanningProgress( (int)overallProgress ); 541 serverGui->documentScanningProgress( (int)overallProgress );
538} 542}
539 543
540 544
541const QString DocumentListPrivate::nextFile() 545const QString DocumentListPrivate::nextFile()
542{ 546{
543 while ( TRUE ) { 547 while ( TRUE ) {
544 while ( searchDepth < 0 ) { 548 while ( searchDepth < 0 ) {
545 // go to next base path 549 // go to next base path
546 if ( docPathsSearched >= docPaths.count() ) { 550 if ( docPathsSearched >= docPaths.count() ) {
547 // end of base paths 551 // end of base paths
548 return QString::null; 552 return QString::null;
549 } else { 553 } else {
550 QDir dir( docPaths[docPathsSearched] ); 554 QDir dir( docPaths[docPathsSearched] );
551 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); 555 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() );
552 docPathsSearched++; 556 docPathsSearched++;
553 if ( !dir.exists( ".Qtopia-ignore" ) ) { 557 if ( !dir.exists( ".Qtopia-ignore" ) ) {
554 listDirs[0] = new QDir( dir ); 558 listDirs[0] = new QDir( dir );
555 lists[0] = listDirs[0]->entryInfoList(); 559 lists[0] = listDirs[0]->entryInfoList();
556 listPositions[0] = 0; 560 listPositions[0] = 0;
557 searchDepth = 0; 561 searchDepth = 0;
558 } 562 }
559 } 563 }
560 } 564 }
561 565
562 const QFileInfoList *fil = lists[searchDepth]; 566 const QFileInfoList *fil = lists[searchDepth];
567 if (!fil) {
568 return QString::null;
569 }
563 QFileInfoList *fl = (QFileInfoList *)fil; 570 QFileInfoList *fl = (QFileInfoList *)fil;
564 unsigned int pos = listPositions[searchDepth]; 571 unsigned int pos = listPositions[searchDepth];
565 572
566 if ( pos >= fl->count() ) { 573 if ( pos >= fl->count() ) {
567 // go up a depth 574 // go up a depth
568 delete listDirs[searchDepth]; 575 delete listDirs[searchDepth];
569 listDirs[searchDepth] = 0; 576 listDirs[searchDepth] = 0;
570 lists[searchDepth] = 0; 577 lists[searchDepth] = 0;
571 listPositions[searchDepth] = 0; 578 listPositions[searchDepth] = 0;
572 searchDepth--; 579 searchDepth--;
573 } else { 580 } else {
574 const QFileInfo *fi = fl->at(pos); 581 const QFileInfo *fi = fl->at(pos);
575 listPositions[searchDepth]++; 582 listPositions[searchDepth]++;
576 QString bn = fi->fileName(); 583 QString bn = fi->fileName();
577 if ( bn[0] != '.' ) { 584 if ( bn[0] != '.' ) {
578 if ( fi->isDir() ) { 585 if ( fi->isDir() ) {
579 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { 586 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) {
580 // go down a depth 587 // go down a depth
581 QDir dir( fi->filePath() ); 588 QDir dir( fi->filePath() );
582 // qDebug("now going in to path: %s", bn.latin1() ); 589 // qDebug("now going in to path: %s", bn.latin1() );
583 if ( !dir.exists( ".Qtopia-ignore" ) ) { 590 if ( !dir.exists( ".Qtopia-ignore" ) ) {
584 if ( searchDepth < MAX_SEARCH_DEPTH - 1) { 591 if ( searchDepth < MAX_SEARCH_DEPTH - 1) {
585 searchDepth++; 592 searchDepth++;
586 listDirs[searchDepth] = new QDir( dir ); 593 listDirs[searchDepth] = new QDir( dir );
587 lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); 594 lists[searchDepth] = listDirs[searchDepth]->entryInfoList();
588 listPositions[searchDepth] = 0; 595 listPositions[searchDepth] = 0;
589 } 596 }
590 } 597 }
591 } 598 }
592 } else { 599 } else {
593 estimatedPercentScanned(); 600 estimatedPercentScanned();
594 return fl->at(pos)->filePath(); 601 return fl->at(pos)->filePath();
595 } 602 }
596 } 603 }
597 } 604 }
598 } 605 }
599 606
600 return QString::null; 607 return QString::null;
601} 608}
602 609
603 610
604bool DocumentListPrivate::store( DocLnk* dl ) 611bool DocumentListPrivate::store( DocLnk* dl )
605{ 612{
606 // if ( dl->fileKnown() && !dl->file().isEmpty() ) { 613 // if ( dl->fileKnown() && !dl->file().isEmpty() ) {
607 if ( dl && dl->fileKnown() ) { 614 if ( dl && dl->fileKnown() ) {
608 dls.add( dl ); // store 615 dls.add( dl ); // store
609 return TRUE; 616 return TRUE;
610 } 617 }
611 618
612 // don't store - delete 619 // don't store - delete
613 delete dl; 620 delete dl;
614 return FALSE; 621 return FALSE;
615} 622}
616 623
617 624
618 #define MAGIC_NUMBER((void*)2) 625 #define MAGIC_NUMBER((void*)2)
619 626
620const DocLnk *DocumentListPrivate::iterate() 627const DocLnk *DocumentListPrivate::iterate()
621{ 628{
622 if ( state == Find ) { 629 if ( state == Find ) {
623 //qDebug("state Find"); 630 //qDebug("state Find");
624 QString file = nextFile(); 631 QString file = nextFile();
625 while ( !file.isNull() ) { 632 while ( !file.isNull() ) {
626 if ( file.right(8) == ".desktop" ) { // No tr 633 if ( file.right(8) == ".desktop" ) { // No tr
627 DocLnk* dl = new DocLnk( file ); 634 DocLnk* dl = new DocLnk( file );
628 if ( store(dl) ) 635 if ( store(dl) )
629 return dl; 636 return dl;
630 } else { 637 } else {
631 reference.insert( file, MAGIC_NUMBER ); 638 reference.insert( file, MAGIC_NUMBER );
632 } 639 }
633 file = nextFile(); 640 file = nextFile();
634 } 641 }
635 state = RemoveKnownFiles; 642 state = RemoveKnownFiles;
636 643
637 if ( serverGui ) 644 if ( serverGui )
638 serverGui->documentScanningProgress( 75 ); 645 serverGui->documentScanningProgress( 75 );
639 } 646 }
640 647
641 static int iterationI; 648 static int iterationI;
642 static int iterationCount; 649 static int iterationCount;
643 650
644 if ( state == RemoveKnownFiles ) { 651 if ( state == RemoveKnownFiles ) {
645 //qDebug("state RemoveKnownFiles"); 652 //qDebug("state RemoveKnownFiles");
646 const QList<DocLnk> &list = dls.children(); 653 const QList<DocLnk> &list = dls.children();
647 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 654 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
648 reference.remove( (*it)->file() ); 655 reference.remove( (*it)->file() );
649 // ### does this need to be deleted? 656 // ### does this need to be deleted?
650 } 657 }
651 dit = new QDictIterator<void>(reference); 658 dit = new QDictIterator<void>(reference);
652 state = MakeUnknownFiles; 659 state = MakeUnknownFiles;
653 660
654 iterationI = 0; 661 iterationI = 0;
655 iterationCount = dit->count(); 662 iterationCount = dit->count();
656 } 663 }
657 664
658 if ( state == MakeUnknownFiles ) { 665 if ( state == MakeUnknownFiles ) {
659 //qDebug("state MakeUnknownFiles"); 666 //qDebug("state MakeUnknownFiles");
660 for (void* c; (c=dit->current()); ++(*dit) ) { 667 for (void* c; (c=dit->current()); ++(*dit) ) {
661 if ( c == MAGIC_NUMBER ) { 668 if ( c == MAGIC_NUMBER ) {
662 DocLnk* dl = new DocLnk; 669 DocLnk* dl = new DocLnk;
663 QFileInfo fi( dit->currentKey() ); 670 QFileInfo fi( dit->currentKey() );
664 dl->setFile( fi.filePath() ); 671 dl->setFile( fi.filePath() );
665 dl->setName( fi.baseName() ); 672 dl->setName( fi.baseName() );
666 if ( store(dl) ) { 673 if ( store(dl) ) {
667 ++*dit; 674 ++*dit;
668 iterationI++; 675 iterationI++;
669 if ( serverGui ) 676 if ( serverGui )
670 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); 677 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount );
671 return dl; 678 return dl;
672 } 679 }
673 } 680 }
674 iterationI++; 681 iterationI++;
675 } 682 }
676 683
677 delete dit; 684 delete dit;
678 dit = 0; 685 dit = 0;
679 state = Done; 686 state = Done;
680 } 687 }
681 688
682 //qDebug("state Done"); 689 //qDebug("state Done");
683 return NULL; 690 return NULL;
684} 691}
685 692
686 693
687#include "documentlist.moc" 694#include "documentlist.moc"
688 695
689 696
690 697