summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-22 20:06:29 (UTC)
committer alwin <alwin>2004-02-22 20:06:29 (UTC)
commit63e45b90437e78ee11753c6782516dc38c30dd24 (patch) (unidiff)
treeb9a700b759ef5ee03c04f2df0e59e43c5a0bfa50
parent5738a3d33bdaeb69994f70fd5ec8aa49df98ceeb (diff)
downloadopie-63e45b90437e78ee11753c6782516dc38c30dd24.zip
opie-63e45b90437e78ee11753c6782516dc38c30dd24.tar.gz
opie-63e45b90437e78ee11753c6782516dc38c30dd24.tar.bz2
read more settings from opiestorage.cf
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index fdba687..9736e65 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -252,384 +252,389 @@ void DocumentList::reloadAppLnks()
252 if ( d->sendAppLnks && d->serverGui ) 252 if ( d->sendAppLnks && d->serverGui )
253 d->serverGui->applicationAdded( l->type(), *l ); 253 d->serverGui->applicationAdded( l->type(), *l );
254 } 254 }
255 255
256 if ( d->sendAppLnks && d->serverGui ) 256 if ( d->sendAppLnks && d->serverGui )
257 d->serverGui->applicationScanningProgress( 100 ); 257 d->serverGui->applicationScanningProgress( 100 );
258} 258}
259 259
260void DocumentList::reloadDocLnks() 260void DocumentList::reloadDocLnks()
261{ 261{
262 if ( !d->scanDocs ) 262 if ( !d->scanDocs )
263 return; 263 return;
264 264
265 if ( d->sendDocLnks && d->serverGui ) { 265 if ( d->sendDocLnks && d->serverGui ) {
266 d->serverGui->documentScanningProgress( 0 ); 266 d->serverGui->documentScanningProgress( 0 );
267 d->serverGui->allDocumentsRemoved(); 267 d->serverGui->allDocumentsRemoved();
268 } 268 }
269 269
270 rescan(); 270 rescan();
271} 271}
272 272
273void DocumentList::linkChanged( QString arg ) 273void DocumentList::linkChanged( QString arg )
274{ 274{
275 //qDebug( "linkchanged( %s )", arg.latin1() ); 275 //qDebug( "linkchanged( %s )", arg.latin1() );
276 276
277 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { 277 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
278 reloadAppLnks(); 278 reloadAppLnks();
279 } else { 279 } else {
280 280
281 const QList<DocLnk> &list = d->dls.children(); 281 const QList<DocLnk> &list = d->dls.children();
282 QListIterator<DocLnk> it( list ); 282 QListIterator<DocLnk> it( list );
283 while ( it.current() ) { 283 while ( it.current() ) {
284 DocLnk *doc = it.current(); 284 DocLnk *doc = it.current();
285 ++it; 285 ++it;
286 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 286 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
287 || ( doc->fileKnown() && doc->file() == arg ) ) { 287 || ( doc->fileKnown() && doc->file() == arg ) ) {
288 //qDebug( "found old link" ); 288 //qDebug( "found old link" );
289 DocLnk* dl = new DocLnk( arg ); 289 DocLnk* dl = new DocLnk( arg );
290 // add new one if it exists and matches the mimetype 290 // add new one if it exists and matches the mimetype
291 if ( d->store( dl ) ) { 291 if ( d->store( dl ) ) {
292 // Existing link has been changed, send old link ref and a ref 292 // Existing link has been changed, send old link ref and a ref
293 // to the new link 293 // to the new link
294 //qDebug( "change case" ); 294 //qDebug( "change case" );
295 if ( d->serverGui ) 295 if ( d->serverGui )
296 d->serverGui->documentChanged( *doc, *dl ); 296 d->serverGui->documentChanged( *doc, *dl );
297 297
298 } else { 298 } else {
299 // Link has been removed or doesn't match the mimetypes any more 299 // Link has been removed or doesn't match the mimetypes any more
300 // so we aren't interested in it, so take it away from the list 300 // so we aren't interested in it, so take it away from the list
301 //qDebug( "removal case" ); 301 //qDebug( "removal case" );
302 if ( d->serverGui ) 302 if ( d->serverGui )
303 d->serverGui->documentRemoved( *doc ); 303 d->serverGui->documentRemoved( *doc );
304 304
305 } 305 }
306 d->dls.remove( doc ); // remove old link from docLnkSet 306 d->dls.remove( doc ); // remove old link from docLnkSet
307 delete doc; 307 delete doc;
308 return; 308 return;
309 } 309 }
310 } 310 }
311 // Didn't find existing link, must be new 311 // Didn't find existing link, must be new
312 DocLnk* dl = new DocLnk( arg ); 312 DocLnk* dl = new DocLnk( arg );
313 if ( d->store( dl ) ) { 313 if ( d->store( dl ) ) {
314 // Add if it's a link we are interested in 314 // Add if it's a link we are interested in
315 //qDebug( "add case" ); 315 //qDebug( "add case" );
316 add( *dl ); 316 add( *dl );
317 } 317 }
318 318
319 } 319 }
320} 320}
321 321
322void DocumentList::restoreDone() 322void DocumentList::restoreDone()
323{ 323{
324 reloadAppLnks(); 324 reloadAppLnks();
325 reloadDocLnks(); 325 reloadDocLnks();
326} 326}
327 327
328void DocumentList::storageChanged() 328void DocumentList::storageChanged()
329{ 329{
330 // ### can implement better 330 // ### can implement better
331 reloadAppLnks(); 331 reloadAppLnks();
332 reloadDocLnks(); 332 reloadDocLnks();
333 // ### Optimization opportunity 333 // ### Optimization opportunity
334 // Could be a bit more intelligent and somehow work out which 334 // Could be a bit more intelligent and somehow work out which
335 // mtab entry has changed and then only scan that and add and remove 335 // mtab entry has changed and then only scan that and add and remove
336 // links appropriately. 336 // links appropriately.
337// rescan(); 337// rescan();
338} 338}
339 339
340void DocumentList::sendAllDocLinks() 340void DocumentList::sendAllDocLinks()
341{ 341{
342 if ( d->tid != 0 ) { 342 if ( d->tid != 0 ) {
343 // We are in the middle of scanning, set a flag so 343 // We are in the middle of scanning, set a flag so
344 // we do this when we finish our scanning 344 // we do this when we finish our scanning
345 d->needToSendAllDocLinks = true; 345 d->needToSendAllDocLinks = true;
346 return; 346 return;
347 } 347 }
348 348
349 QString contents; 349 QString contents;
350 Categories cats; 350 Categories cats;
351 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 351 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
352 DocLnk *doc = it.current(); 352 DocLnk *doc = it.current();
353 QFileInfo fi( doc->file() ); 353 QFileInfo fi( doc->file() );
354 if ( !fi.exists() ) 354 if ( !fi.exists() )
355 continue; 355 continue;
356 356
357 bool fake = !doc->linkFileKnown(); 357 bool fake = !doc->linkFileKnown();
358 if ( !fake ) { 358 if ( !fake ) {
359 QFile f( doc->linkFile() ); 359 QFile f( doc->linkFile() );
360 if ( f.open( IO_ReadOnly ) ) { 360 if ( f.open( IO_ReadOnly ) ) {
361 QTextStream ts( &f ); 361 QTextStream ts( &f );
362 ts.setEncoding( QTextStream::UnicodeUTF8 ); 362 ts.setEncoding( QTextStream::UnicodeUTF8 );
363 contents += ts.read(); 363 contents += ts.read();
364 f.close(); 364 f.close();
365 } else 365 } else
366 fake = TRUE; 366 fake = TRUE;
367 } 367 }
368 if (fake) { 368 if (fake) {
369 contents += "[Desktop Entry]\n"; // No tr 369 contents += "[Desktop Entry]\n"; // No tr
370 contents += "Categories = " + // No tr 370 contents += "Categories = " + // No tr
371 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 371 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
372 contents += "Name = "+doc->name()+"\n"; // No tr 372 contents += "Name = "+doc->name()+"\n"; // No tr
373 contents += "Type = "+doc->type()+"\n"; // No tr 373 contents += "Type = "+doc->type()+"\n"; // No tr
374 } 374 }
375 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 375 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
376 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 376 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
377 } 377 }
378 378
379 //qDebug( "sending length %d", contents.length() ); 379 //qDebug( "sending length %d", contents.length() );
380#ifndef QT_NO_COP 380#ifndef QT_NO_COP
381 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 381 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
382 e << contents; 382 e << contents;
383#endif 383#endif
384 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); 384 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() );
385 385
386 d->needToSendAllDocLinks = false; 386 d->needToSendAllDocLinks = false;
387} 387}
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
412DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) 412DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
413{ 413{
414 storage = new StorageInfo( this ); 414 storage = new StorageInfo( this );
415 serverGui = gui; 415 serverGui = gui;
416 if ( serverGui ) { 416 if ( serverGui ) {
417 sendAppLnks = serverGui->requiresApplications(); 417 sendAppLnks = serverGui->requiresApplications();
418 sendDocLnks = serverGui->requiresDocuments(); 418 sendDocLnks = serverGui->requiresDocuments();
419 } else { 419 } else {
420 sendAppLnks = false; 420 sendAppLnks = false;
421 sendDocLnks = false; 421 sendDocLnks = false;
422 } 422 }
423 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 423 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
424 listDirs[i] = 0; 424 listDirs[i] = 0;
425 lists[i] = 0; 425 lists[i] = 0;
426 listPositions[i] = 0; 426 listPositions[i] = 0;
427 } 427 }
428 initialize(); 428 initialize();
429 tid = 0; 429 tid = 0;
430} 430}
431 431
432void DocumentListPrivate::appendDocpath(FileSystem*fs) 432void DocumentListPrivate::appendDocpath(FileSystem*fs)
433{ 433{
434 QDir defPath(fs->path()+"/Documents"); 434 QDir defPath(fs->path()+"/Documents");
435 QFileInfo f(fs->path()+"/.opiestorage.cf"); 435 QFileInfo f(fs->path()+"/.opiestorage.cf");
436 if (!f.exists()) { 436 if (!f.exists()) {
437 if (defPath.exists()) { 437 if (defPath.exists()) {
438 docPaths+=defPath.path(); 438 docPaths+=defPath.path();
439 } 439 }
440 return; 440 return;
441 } 441 }
442 Config conf(f.filePath(), Config::File ); 442 Config conf(f.filePath(), Config::File );
443 conf.setGroup("subdirs"); 443 conf.setGroup("subdirs");
444 bool read_all = conf.readBoolEntry("wholemedia",true);
445 if (read_all) {
446 docPaths+=fs->path();
447 return;
448 }
444 QStringList subDirs = conf.readListEntry("subdirs",':'); 449 QStringList subDirs = conf.readListEntry("subdirs",':');
445 if (subDirs.isEmpty()) { 450 if (subDirs.isEmpty()) {
446 if (defPath.exists()) { 451 if (defPath.exists()) {
447 docPaths+=defPath.path(); 452 docPaths+=defPath.path();
448 } 453 }
449 return; 454 return;
450 } 455 }
451 for (unsigned c = 0; c < subDirs.count();++c) { 456 for (unsigned c = 0; c < subDirs.count();++c) {
452 QDir docDir(QString(fs->path()+"/"+subDirs[c])); 457 QDir docDir(QString(fs->path()+"/"+subDirs[c]));
453 if (docDir.exists()) { 458 if (docDir.exists()) {
454 docPaths+=docDir.path(); 459 docPaths+=docDir.path();
455 } 460 }
456 } 461 }
457} 462}
458 463
459void DocumentListPrivate::initialize() 464void DocumentListPrivate::initialize()
460{ 465{
461 // Reset 466 // Reset
462 dls.clear(); 467 dls.clear();
463 docPaths.clear(); 468 docPaths.clear();
464 reference.clear(); 469 reference.clear();
465 470
466 QDir docDir( QPEApplication::documentDir() ); 471 QDir docDir( QPEApplication::documentDir() );
467 if ( docDir.exists() ) 472 if ( docDir.exists() )
468 docPaths += QPEApplication::documentDir(); 473 docPaths += QPEApplication::documentDir();
469 int i = 1; 474 int i = 1;
470 const QList<FileSystem> &fs = storage->fileSystems(); 475 const QList<FileSystem> &fs = storage->fileSystems();
471 QListIterator<FileSystem> it( fs ); 476 QListIterator<FileSystem> it( fs );
472 for ( ; it.current(); ++it ) { 477 for ( ; it.current(); ++it ) {
473 if ( (*it)->isRemovable() ) { 478 if ( (*it)->isRemovable() ) {
474 appendDocpath((*it)); 479 appendDocpath((*it));
475 ++i; 480 ++i;
476 } 481 }
477 } 482 }
478 483
479 for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { 484 for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) {
480 if ( listDirs[i] ) { 485 if ( listDirs[i] ) {
481 delete listDirs[i]; 486 delete listDirs[i];
482 listDirs[i] = 0; 487 listDirs[i] = 0;
483 } 488 }
484 lists[i] = 0; 489 lists[i] = 0;
485 listPositions[i] = 0; 490 listPositions[i] = 0;
486 } 491 }
487 492
488 docPathsSearched = 0; 493 docPathsSearched = 0;
489 searchDepth = -1; 494 searchDepth = -1;
490 state = Find; 495 state = Find;
491 dit = 0; 496 dit = 0;
492} 497}
493 498
494 499
495DocumentListPrivate::~DocumentListPrivate() 500DocumentListPrivate::~DocumentListPrivate()
496{ 501{
497 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) 502 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ )
498 if ( listDirs[i] ) 503 if ( listDirs[i] )
499 delete listDirs[i]; 504 delete listDirs[i];
500 delete dit; 505 delete dit;
501} 506}
502 507
503 508
504void DocumentListPrivate::estimatedPercentScanned() 509void DocumentListPrivate::estimatedPercentScanned()
505{ 510{
506 double overallProgress = 0.0; 511 double overallProgress = 0.0;
507 double levelWeight = 75.0; 512 double levelWeight = 75.0;
508 513
509 int topCount = docPaths.count(); 514 int topCount = docPaths.count();
510 if ( topCount > 1 ) { 515 if ( topCount > 1 ) {
511 levelWeight = levelWeight / topCount; 516 levelWeight = levelWeight / topCount;
512 overallProgress += (docPathsSearched - 1) * levelWeight; 517 overallProgress += (docPathsSearched - 1) * levelWeight;
513 } 518 }
514 519
515 for ( int d = 0; d <= searchDepth; d++ ) { 520 for ( int d = 0; d <= searchDepth; d++ ) {
516 if ( listDirs[d] ) { 521 if ( listDirs[d] ) {
517 int items = lists[d]->count(); 522 int items = lists[d]->count();
518 if ( items > 1 ) { 523 if ( items > 1 ) {
519 levelWeight = levelWeight / items; 524 levelWeight = levelWeight / items;
520 // Take in to account "." and ".." 525 // Take in to account "." and ".."
521 overallProgress += (listPositions[d] - 3) * levelWeight; 526 overallProgress += (listPositions[d] - 3) * levelWeight;
522 } 527 }
523 } else { 528 } else {
524 break; 529 break;
525 } 530 }
526 } 531 }
527 532
528 // qDebug( "overallProgress: %f", overallProgress ); 533 // qDebug( "overallProgress: %f", overallProgress );
529 534
530 if ( serverGui ) 535 if ( serverGui )
531 serverGui->documentScanningProgress( (int)overallProgress ); 536 serverGui->documentScanningProgress( (int)overallProgress );
532} 537}
533 538
534 539
535const QString DocumentListPrivate::nextFile() 540const QString DocumentListPrivate::nextFile()
536{ 541{
537 while ( TRUE ) { 542 while ( TRUE ) {
538 while ( searchDepth < 0 ) { 543 while ( searchDepth < 0 ) {
539 // go to next base path 544 // go to next base path
540 if ( docPathsSearched >= docPaths.count() ) { 545 if ( docPathsSearched >= docPaths.count() ) {
541 // end of base paths 546 // end of base paths
542 return QString::null; 547 return QString::null;
543 } else { 548 } else {
544 QDir dir( docPaths[docPathsSearched] ); 549 QDir dir( docPaths[docPathsSearched] );
545 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); 550 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() );
546 docPathsSearched++; 551 docPathsSearched++;
547 if ( !dir.exists( ".Qtopia-ignore" ) ) { 552 if ( !dir.exists( ".Qtopia-ignore" ) ) {
548 listDirs[0] = new QDir( dir ); 553 listDirs[0] = new QDir( dir );
549 lists[0] = listDirs[0]->entryInfoList(); 554 lists[0] = listDirs[0]->entryInfoList();
550 listPositions[0] = 0; 555 listPositions[0] = 0;
551 searchDepth = 0; 556 searchDepth = 0;
552 } 557 }
553 } 558 }
554 } 559 }
555 560
556 const QFileInfoList *fil = lists[searchDepth]; 561 const QFileInfoList *fil = lists[searchDepth];
557 QFileInfoList *fl = (QFileInfoList *)fil; 562 QFileInfoList *fl = (QFileInfoList *)fil;
558 unsigned int pos = listPositions[searchDepth]; 563 unsigned int pos = listPositions[searchDepth];
559 564
560 if ( pos >= fl->count() ) { 565 if ( pos >= fl->count() ) {
561 // go up a depth 566 // go up a depth
562 delete listDirs[searchDepth]; 567 delete listDirs[searchDepth];
563 listDirs[searchDepth] = 0; 568 listDirs[searchDepth] = 0;
564 lists[searchDepth] = 0; 569 lists[searchDepth] = 0;
565 listPositions[searchDepth] = 0; 570 listPositions[searchDepth] = 0;
566 searchDepth--; 571 searchDepth--;
567 } else { 572 } else {
568 const QFileInfo *fi = fl->at(pos); 573 const QFileInfo *fi = fl->at(pos);
569 listPositions[searchDepth]++; 574 listPositions[searchDepth]++;
570 QString bn = fi->fileName(); 575 QString bn = fi->fileName();
571 if ( bn[0] != '.' ) { 576 if ( bn[0] != '.' ) {
572 if ( fi->isDir() ) { 577 if ( fi->isDir() ) {
573 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { 578 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) {
574 // go down a depth 579 // go down a depth
575 QDir dir( fi->filePath() ); 580 QDir dir( fi->filePath() );
576 // qDebug("now going in to path: %s", bn.latin1() ); 581 // qDebug("now going in to path: %s", bn.latin1() );
577 if ( !dir.exists( ".Qtopia-ignore" ) ) { 582 if ( !dir.exists( ".Qtopia-ignore" ) ) {
578 if ( searchDepth < MAX_SEARCH_DEPTH - 1) { 583 if ( searchDepth < MAX_SEARCH_DEPTH - 1) {
579 searchDepth++; 584 searchDepth++;
580 listDirs[searchDepth] = new QDir( dir ); 585 listDirs[searchDepth] = new QDir( dir );
581 lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); 586 lists[searchDepth] = listDirs[searchDepth]->entryInfoList();
582 listPositions[searchDepth] = 0; 587 listPositions[searchDepth] = 0;
583 } 588 }
584 } 589 }
585 } 590 }
586 } else { 591 } else {
587 estimatedPercentScanned(); 592 estimatedPercentScanned();
588 return fl->at(pos)->filePath(); 593 return fl->at(pos)->filePath();
589 } 594 }
590 } 595 }
591 } 596 }
592 } 597 }
593 598
594 return QString::null; 599 return QString::null;
595} 600}
596 601
597 602
598bool DocumentListPrivate::store( DocLnk* dl ) 603bool DocumentListPrivate::store( DocLnk* dl )
599{ 604{
600 // if ( dl->fileKnown() && !dl->file().isEmpty() ) { 605 // if ( dl->fileKnown() && !dl->file().isEmpty() ) {
601 if ( dl && dl->fileKnown() ) { 606 if ( dl && dl->fileKnown() ) {
602 dls.add( dl ); // store 607 dls.add( dl ); // store
603 return TRUE; 608 return TRUE;
604 } 609 }
605 610
606 // don't store - delete 611 // don't store - delete
607 delete dl; 612 delete dl;
608 return FALSE; 613 return FALSE;
609} 614}
610 615
611 616
612 #define MAGIC_NUMBER((void*)2) 617 #define MAGIC_NUMBER((void*)2)
613 618
614const DocLnk *DocumentListPrivate::iterate() 619const DocLnk *DocumentListPrivate::iterate()
615{ 620{
616 if ( state == Find ) { 621 if ( state == Find ) {
617 //qDebug("state Find"); 622 //qDebug("state Find");
618 QString file = nextFile(); 623 QString file = nextFile();
619 while ( !file.isNull() ) { 624 while ( !file.isNull() ) {
620 if ( file.right(8) == ".desktop" ) { // No tr 625 if ( file.right(8) == ".desktop" ) { // No tr
621 DocLnk* dl = new DocLnk( file ); 626 DocLnk* dl = new DocLnk( file );
622 if ( store(dl) ) 627 if ( store(dl) )
623 return dl; 628 return dl;
624 } else { 629 } else {
625 reference.insert( file, MAGIC_NUMBER ); 630 reference.insert( file, MAGIC_NUMBER );
626 } 631 }
627 file = nextFile(); 632 file = nextFile();
628 } 633 }
629 state = RemoveKnownFiles; 634 state = RemoveKnownFiles;
630 635
631 if ( serverGui ) 636 if ( serverGui )
632 serverGui->documentScanningProgress( 75 ); 637 serverGui->documentScanningProgress( 75 );
633 } 638 }
634 639
635 static int iterationI; 640 static int iterationI;