summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-21 21:43:40 (UTC)
committer alwin <alwin>2004-02-21 21:43:40 (UTC)
commit1a89ecd8e2d11d48a8e80b2fd8b1e95b738a286c (patch) (unidiff)
tree2c0aaf8487c87c23855dd06599b51c22fa8d6478
parentc7e563cbb26c20807e66dd4284d1ce9cbf8e1419 (diff)
downloadopie-1a89ecd8e2d11d48a8e80b2fd8b1e95b738a286c.zip
opie-1a89ecd8e2d11d48a8e80b2fd8b1e95b738a286c.tar.gz
opie-1a89ecd8e2d11d48a8e80b2fd8b1e95b738a286c.tar.bz2
on removable medias take a look into .opiestorage.cf and read the list
of subdirs of the media where to search for documents. If this value isn't set, it will reduce search to FS+"/Documents" so not the whole media is searched. ToDo: Work on mediummount that users can set this values. Implement same stuff in global.cpp of libqpe.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 440bf1e..fdba687 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -18,96 +18,98 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "documentlist.h" 20#include "documentlist.h"
21#include "serverinterface.h" 21#include "serverinterface.h"
22 22
23#include <opie2/oglobal.h> 23#include <opie2/oglobal.h>
24 24
25#include <qtopia/config.h> 25#include <qtopia/config.h>
26#include <qtopia/mimetype.h> 26#include <qtopia/mimetype.h>
27#include <qtopia/resource.h> 27#include <qtopia/resource.h>
28#include <qtopia/private/categories.h> 28#include <qtopia/private/categories.h>
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30#include <qtopia/applnk.h> 30#include <qtopia/applnk.h>
31#include <qtopia/storage.h> 31#include <qtopia/storage.h>
32#ifdef Q_WS_QWS 32#ifdef Q_WS_QWS
33#include <qtopia/qcopenvelope_qws.h> 33#include <qtopia/qcopenvelope_qws.h>
34#endif 34#endif
35 35
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qimage.h> 42#include <qimage.h>
43#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
44#include <qlistview.h> 44#include <qlistview.h>
45#include <qlist.h> 45#include <qlist.h>
46#include <qpixmap.h> 46#include <qpixmap.h>
47 47
48 48
49AppLnkSet *DocumentList::appLnkSet = 0; 49AppLnkSet *DocumentList::appLnkSet = 0;
50 50
51static const int MAX_SEARCH_DEPTH = 10; 51static const int MAX_SEARCH_DEPTH = 10;
52 52
53 53
54class DocumentListPrivate : public QObject { 54class DocumentListPrivate : public QObject {
55 Q_OBJECT 55 Q_OBJECT
56public: 56public:
57 DocumentListPrivate( ServerInterface *gui ); 57 DocumentListPrivate( ServerInterface *gui );
58 ~DocumentListPrivate(); 58 ~DocumentListPrivate();
59 59
60 void initialize(); 60 void initialize();
61 61
62 const QString nextFile(); 62 const QString nextFile();
63 const DocLnk *iterate(); 63 const DocLnk *iterate();
64 bool store( DocLnk* dl ); 64 bool store( DocLnk* dl );
65 void estimatedPercentScanned(); 65 void estimatedPercentScanned();
66 void appendDocpath(FileSystem*);
67
66 68
67 DocLnkSet dls; 69 DocLnkSet dls;
68 QDict<void> reference; 70 QDict<void> reference;
69 QDictIterator<void> *dit; 71 QDictIterator<void> *dit;
70 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; 72 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
71 73
72 QStringList docPaths; 74 QStringList docPaths;
73 unsigned int docPathsSearched; 75 unsigned int docPathsSearched;
74 76
75 int searchDepth; 77 int searchDepth;
76 QDir *listDirs[MAX_SEARCH_DEPTH]; 78 QDir *listDirs[MAX_SEARCH_DEPTH];
77 const QFileInfoList *lists[MAX_SEARCH_DEPTH]; 79 const QFileInfoList *lists[MAX_SEARCH_DEPTH];
78 unsigned int listPositions[MAX_SEARCH_DEPTH]; 80 unsigned int listPositions[MAX_SEARCH_DEPTH];
79 81
80 StorageInfo *storage; 82 StorageInfo *storage;
81 83
82 int tid; 84 int tid;
83 85
84 ServerInterface *serverGui; 86 ServerInterface *serverGui;
85 87
86 bool needToSendAllDocLinks; 88 bool needToSendAllDocLinks;
87 bool sendAppLnks; 89 bool sendAppLnks;
88 bool sendDocLnks; 90 bool sendDocLnks;
89 bool scanDocs; 91 bool scanDocs;
90}; 92};
91 93
92 94
93/* 95/*
94 * scandocs will be read from Config 96 * scandocs will be read from Config
95 */ 97 */
96DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, 98DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
97 QObject *parent, const char *name ) 99 QObject *parent, const char *name )
98 : QObject( parent, name ) 100 : QObject( parent, name )
99{ 101{
100 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 102 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
101 d = new DocumentListPrivate( serverGui ); 103 d = new DocumentListPrivate( serverGui );
102 d->needToSendAllDocLinks = false; 104 d->needToSendAllDocLinks = false;
103 105
104 Config cfg( "Launcher" ); 106 Config cfg( "Launcher" );
105 cfg.setGroup( "DocTab" ); 107 cfg.setGroup( "DocTab" );
106 d->scanDocs = cfg.readBoolEntry( "Enable", true ); 108 d->scanDocs = cfg.readBoolEntry( "Enable", true );
107 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); 109 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
108 110
109 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); 111 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
110} 112}
111 113
112void DocumentList::startInitialScan() 114void DocumentList::startInitialScan()
113{ 115{
@@ -382,117 +384,144 @@ void DocumentList::sendAllDocLinks()
382 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); 384 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() );
383 385
384 d->needToSendAllDocLinks = false; 386 d->needToSendAllDocLinks = false;
385} 387}
386 388
387 389
388 390
389 391
390 392
391 393
392 394
393 395
394 396
395 397
396 398
397 399
398 400
399 401
400 402
401 403
402 404
403 405
404 406
405 407
406 408
407 409
408 410
409 411
410DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) 412DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
411{ 413{
412 storage = new StorageInfo( this ); 414 storage = new StorageInfo( this );
413 serverGui = gui; 415 serverGui = gui;
414 if ( serverGui ) { 416 if ( serverGui ) {
415 sendAppLnks = serverGui->requiresApplications(); 417 sendAppLnks = serverGui->requiresApplications();
416 sendDocLnks = serverGui->requiresDocuments(); 418 sendDocLnks = serverGui->requiresDocuments();
417 } else { 419 } else {
418 sendAppLnks = false; 420 sendAppLnks = false;
419 sendDocLnks = false; 421 sendDocLnks = false;
420 } 422 }
421 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 423 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
422 listDirs[i] = 0; 424 listDirs[i] = 0;
423 lists[i] = 0; 425 lists[i] = 0;
424 listPositions[i] = 0; 426 listPositions[i] = 0;
425 } 427 }
426 initialize(); 428 initialize();
427 tid = 0; 429 tid = 0;
428} 430}
429 431
432void DocumentListPrivate::appendDocpath(FileSystem*fs)
433{
434 QDir defPath(fs->path()+"/Documents");
435 QFileInfo f(fs->path()+"/.opiestorage.cf");
436 if (!f.exists()) {
437 if (defPath.exists()) {
438 docPaths+=defPath.path();
439 }
440 return;
441 }
442 Config conf(f.filePath(), Config::File );
443 conf.setGroup("subdirs");
444 QStringList subDirs = conf.readListEntry("subdirs",':');
445 if (subDirs.isEmpty()) {
446 if (defPath.exists()) {
447 docPaths+=defPath.path();
448 }
449 return;
450 }
451 for (unsigned c = 0; c < subDirs.count();++c) {
452 QDir docDir(QString(fs->path()+"/"+subDirs[c]));
453 if (docDir.exists()) {
454 docPaths+=docDir.path();
455 }
456 }
457}
430 458
431void DocumentListPrivate::initialize() 459void DocumentListPrivate::initialize()
432{ 460{
433 // Reset 461 // Reset
434 dls.clear(); 462 dls.clear();
435 docPaths.clear(); 463 docPaths.clear();
436 reference.clear(); 464 reference.clear();
437 465
438 QDir docDir( QPEApplication::documentDir() ); 466 QDir docDir( QPEApplication::documentDir() );
439 if ( docDir.exists() ) 467 if ( docDir.exists() )
440 docPaths += QPEApplication::documentDir(); 468 docPaths += QPEApplication::documentDir();
441 int i = 1; 469 int i = 1;
442 const QList<FileSystem> &fs = storage->fileSystems(); 470 const QList<FileSystem> &fs = storage->fileSystems();
443 QListIterator<FileSystem> it( fs ); 471 QListIterator<FileSystem> it( fs );
444 for ( ; it.current(); ++it ) 472 for ( ; it.current(); ++it ) {
445 if ( (*it)->isRemovable() ) { 473 if ( (*it)->isRemovable() ) {
446 docPaths += (*it)->path(); 474 appendDocpath((*it));
447 i++; 475 ++i;
448 } 476 }
477 }
449 478
450 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 479 for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) {
451 if ( listDirs[i] ) { 480 if ( listDirs[i] ) {
452 delete listDirs[i]; 481 delete listDirs[i];
453 listDirs[i] = 0; 482 listDirs[i] = 0;
454 } 483 }
455 lists[i] = 0; 484 lists[i] = 0;
456 listPositions[i] = 0; 485 listPositions[i] = 0;
457 } 486 }
458 487
459 docPathsSearched = 0; 488 docPathsSearched = 0;
460 searchDepth = -1; 489 searchDepth = -1;
461 state = Find; 490 state = Find;
462 dit = 0; 491 dit = 0;
463} 492}
464 493
465 494
466DocumentListPrivate::~DocumentListPrivate() 495DocumentListPrivate::~DocumentListPrivate()
467{ 496{
468 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) 497 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ )
469 if ( listDirs[i] ) 498 if ( listDirs[i] )
470 delete listDirs[i]; 499 delete listDirs[i];
471 delete dit; 500 delete dit;
472} 501}
473 502
474 503
475void DocumentListPrivate::estimatedPercentScanned() 504void DocumentListPrivate::estimatedPercentScanned()
476{ 505{
477 double overallProgress = 0.0; 506 double overallProgress = 0.0;
478 double levelWeight = 75.0; 507 double levelWeight = 75.0;
479 508
480 int topCount = docPaths.count(); 509 int topCount = docPaths.count();
481 if ( topCount > 1 ) { 510 if ( topCount > 1 ) {
482 levelWeight = levelWeight / topCount; 511 levelWeight = levelWeight / topCount;
483 overallProgress += (docPathsSearched - 1) * levelWeight; 512 overallProgress += (docPathsSearched - 1) * levelWeight;
484 } 513 }
485 514
486 for ( int d = 0; d <= searchDepth; d++ ) { 515 for ( int d = 0; d <= searchDepth; d++ ) {
487 if ( listDirs[d] ) { 516 if ( listDirs[d] ) {
488 int items = lists[d]->count(); 517 int items = lists[d]->count();
489 if ( items > 1 ) { 518 if ( items > 1 ) {
490 levelWeight = levelWeight / items; 519 levelWeight = levelWeight / items;
491 // Take in to account "." and ".." 520 // Take in to account "." and ".."
492 overallProgress += (listPositions[d] - 3) * levelWeight; 521 overallProgress += (listPositions[d] - 3) * levelWeight;
493 } 522 }
494 } else { 523 } else {
495 break; 524 break;
496 } 525 }
497 } 526 }
498 527