summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-08-14 01:56:52 (UTC)
committer llornkcor <llornkcor>2005-08-14 01:56:52 (UTC)
commit11644efb6f433c5def0341b8d086804ce457d5a5 (patch) (unidiff)
tree5432a575837e77f3238aac8bdcc397586c45a21f
parent6ee18e3d11d5204ca6c8e885bc563ab34befdaec (diff)
downloadopie-11644efb6f433c5def0341b8d086804ce457d5a5.zip
opie-11644efb6f433c5def0341b8d086804ce457d5a5.tar.gz
opie-11644efb6f433c5def0341b8d086804ce457d5a5.tar.bz2
make assumption that Documents files will never be installed/written to /proc /dev /bin and similar places.. so we don't need to waste time scanning these.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index fd385d6..35a5d56 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -59,196 +59,196 @@ using namespace Opie::Core;
59 59
60 60
61AppLnkSet *DocumentList::appLnkSet = 0; 61AppLnkSet *DocumentList::appLnkSet = 0;
62 62
63static const int MAX_SEARCH_DEPTH = 10; 63static const int MAX_SEARCH_DEPTH = 10;
64 64
65 65
66class DocumentListPrivate : public QObject { 66class DocumentListPrivate : public QObject {
67 Q_OBJECT 67 Q_OBJECT
68public: 68public:
69 DocumentListPrivate( ServerInterface *gui ); 69 DocumentListPrivate( ServerInterface *gui );
70 ~DocumentListPrivate(); 70 ~DocumentListPrivate();
71 71
72 void initialize(); 72 void initialize();
73 73
74 const QString nextFile(); 74 const QString nextFile();
75 const DocLnk *iterate(); 75 const DocLnk *iterate();
76 bool store( DocLnk* dl ); 76 bool store( DocLnk* dl );
77 void estimatedPercentScanned(); 77 void estimatedPercentScanned();
78 void appendDocpath(FileSystem*); 78 void appendDocpath(FileSystem*);
79 79
80 80
81 DocLnkSet dls; 81 DocLnkSet dls;
82 QDict<void> reference; 82 QDict<void> reference;
83 QDictIterator<void> *dit; 83 QDictIterator<void> *dit;
84 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; 84 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
85 85
86 QStringList docPaths; 86 QStringList docPaths;
87 unsigned int docPathsSearched; 87 unsigned int docPathsSearched;
88 88
89 int searchDepth; 89 int searchDepth;
90 QDir *listDirs[MAX_SEARCH_DEPTH]; 90 QDir *listDirs[MAX_SEARCH_DEPTH];
91 const QFileInfoList *lists[MAX_SEARCH_DEPTH]; 91 const QFileInfoList *lists[MAX_SEARCH_DEPTH];
92 unsigned int listPositions[MAX_SEARCH_DEPTH]; 92 unsigned int listPositions[MAX_SEARCH_DEPTH];
93 93
94 StorageInfo *storage; 94 StorageInfo *storage;
95 95
96 int tid; 96 int tid;
97 97
98 ServerInterface *serverGui; 98 ServerInterface *serverGui;
99 99
100 bool needToSendAllDocLinks; 100 bool needToSendAllDocLinks;
101 bool sendAppLnks; 101 bool sendAppLnks;
102 bool sendDocLnks; 102 bool sendDocLnks;
103 bool scanDocs; 103 bool scanDocs;
104}; 104};
105 105
106 106
107/* 107/*
108 * scandocs will be read from Config 108 * scandocs will be read from Config
109 */ 109 */
110DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, 110DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
111 QObject *parent, const char *name ) 111 QObject *parent, const char *name )
112 : QObject( parent, name ) 112 : QObject( parent, name )
113{ 113{
114 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 114 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
115 d = new DocumentListPrivate( serverGui ); 115 d = new DocumentListPrivate( serverGui );
116 d->needToSendAllDocLinks = false; 116 d->needToSendAllDocLinks = false;
117 117
118 Config cfg( "Launcher" ); 118 Config cfg( "Launcher" );
119 cfg.setGroup( "DocTab" ); 119 cfg.setGroup( "DocTab" );
120 d->scanDocs = cfg.readBoolEntry( "Enable", true ); 120 d->scanDocs = cfg.readBoolEntry( "Enable", true );
121 odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl; 121 odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl;
122 122
123 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); 123 QTimer::singleShot( 0, this, SLOT( startInitialScan() ) );
124} 124}
125 125
126void DocumentList::startInitialScan() 126void DocumentList::startInitialScan()
127{ 127{
128 reloadAppLnks(); 128 reloadAppLnks();
129 reloadDocLnks(); 129 reloadDocLnks();
130} 130}
131 131
132DocumentList::~DocumentList() 132DocumentList::~DocumentList()
133{ 133{
134 delete appLnkSet; 134 delete appLnkSet;
135 delete d; 135 delete d;
136} 136}
137 137
138 138
139void DocumentList::add( const DocLnk& doc ) 139void DocumentList::add( const DocLnk& doc )
140{ 140{
141 if ( d->serverGui && QFile::exists( doc.file() ) ) 141 if ( d->serverGui && QFile::exists( doc.file() ) )
142 d->serverGui->documentAdded( doc ); 142 d->serverGui->documentAdded( doc );
143} 143}
144 144
145 145
146void DocumentList::start() 146void DocumentList::start()
147{ 147{
148 resume(); 148 resume();
149} 149}
150 150
151 151
152void DocumentList::pause() 152void DocumentList::pause()
153{ 153{
154 //odebug << "pause " << d->tid << "" << oendl; 154 //odebug << "pause " << d->tid << "" << oendl;
155 killTimer( d->tid ); 155 killTimer( d->tid );
156 d->tid = 0; 156 d->tid = 0;
157} 157}
158 158
159 159
160void DocumentList::resume() 160void DocumentList::resume()
161{ 161{
162 if ( d->tid == 0 ) { 162 if ( d->tid == 0 ) {
163 d->tid = startTimer( 20 ); 163 d->tid = startTimer( 20 );
164 //odebug << "resumed " << d->tid << "" << oendl; 164 //odebug << "resumed " << d->tid << "" << oendl;
165 } 165 }
166} 166}
167 167
168/* 168/*
169void DocumentList::resend() 169void DocumentList::resend()
170{ 170{
171 // Re-emits all the added items to the list (firstly letting everyone know to 171 // Re-emits all the added items to the list (firstly letting everyone know to
172 // clear what they have as it is being sent again) 172 // clear what they have as it is being sent again)
173 pause(); 173 pause();
174 emit allRemoved(); 174 emit allRemoved();
175 QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); 175 QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
176} 176}
177 177
178 178
179void DocumentList::resendWorker() 179void DocumentList::resendWorker()
180{ 180{
181 const QList<DocLnk> &list = d->dls.children(); 181 const QList<DocLnk> &list = d->dls.children();
182 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) 182 for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
183 add( *(*it) ); 183 add( *(*it) );
184 resume(); 184 resume();
185} 185}
186*/ 186*/
187 187
188void DocumentList::rescan() 188void DocumentList::rescan()
189{ 189{
190 //odebug << "rescan" << oendl; 190 owarn << "XXXXXXXXXXX rescan" << oendl;
191 pause(); 191 pause();
192 d->initialize(); 192 d->initialize();
193 resume(); 193 resume();
194} 194}
195 195
196 196
197void DocumentList::timerEvent( QTimerEvent *te ) 197void DocumentList::timerEvent( QTimerEvent *te )
198{ 198{
199 if ( te->timerId() == d->tid ) { 199 if ( te->timerId() == d->tid ) {
200 // Do 3 at a time 200 // Do 3 at a time
201 if ( d->serverGui ) 201 if ( d->serverGui )
202 d->serverGui->aboutToAddBegin(); 202 d->serverGui->aboutToAddBegin();
203 for (int i = 0; i < 3; i++ ) { 203 for (int i = 0; i < 3; i++ ) {
204 const DocLnk *lnk = d->iterate(); 204 const DocLnk *lnk = d->iterate();
205 if ( lnk ) { 205 if ( lnk ) {
206 add( *lnk ); 206 add( *lnk );
207 } else { 207 } else {
208 // stop when done 208 // stop when done
209 pause(); 209 pause();
210 if ( d->serverGui ) 210 if ( d->serverGui )
211 d->serverGui->documentScanningProgress( 100 ); 211 d->serverGui->documentScanningProgress( 100 );
212 if ( d->needToSendAllDocLinks ) 212 if ( d->needToSendAllDocLinks )
213 sendAllDocLinks(); 213 sendAllDocLinks();
214 break; 214 break;
215 } 215 }
216 } 216 }
217 if ( d->serverGui ) 217 if ( d->serverGui )
218 d->serverGui->aboutToAddEnd(); 218 d->serverGui->aboutToAddEnd();
219 } 219 }
220} 220}
221 221
222 222
223void DocumentList::reloadAppLnks() 223void DocumentList::reloadAppLnks()
224{ 224{
225 if ( d->sendAppLnks && d->serverGui ) { 225 if ( d->sendAppLnks && d->serverGui ) {
226 d->serverGui->applicationScanningProgress( 0 ); 226 d->serverGui->applicationScanningProgress( 0 );
227 d->serverGui->allApplicationsRemoved(); 227 d->serverGui->allApplicationsRemoved();
228 } 228 }
229 229
230 delete appLnkSet; 230 delete appLnkSet;
231 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 231 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
232 232
233 if ( d->sendAppLnks && d->serverGui ) { 233 if ( d->sendAppLnks && d->serverGui ) {
234 static QStringList prevTypeList; 234 static QStringList prevTypeList;
235 QStringList types = appLnkSet->types(); 235 QStringList types = appLnkSet->types();
236 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 236 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
237 if ( !(*ittypes).isEmpty() ) { 237 if ( !(*ittypes).isEmpty() ) {
238 if ( !prevTypeList.contains(*ittypes) ) { 238 if ( !prevTypeList.contains(*ittypes) ) {
239 QString name = appLnkSet->typeName(*ittypes); 239 QString name = appLnkSet->typeName(*ittypes);
240 QPixmap pm = appLnkSet->typePixmap(*ittypes); 240 QPixmap pm = appLnkSet->typePixmap(*ittypes);
241 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 241 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
242 242
243 if (pm.isNull()) 243 if (pm.isNull())
244 { 244 {
245 pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon ); 245 pm = OResource::loadImage( "UnknownDocument", OResource::SmallIcon );
246 bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon ); 246 bgPm = OResource::loadImage( "UnknownDocument", OResource::BigIcon );
247 } 247 }
248 248
249 //FIXME our current launcher expects docs tab to be last 249 //FIXME our current launcher expects docs tab to be last
250 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 250 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
251 } 251 }
252 prevTypeList.remove(*ittypes); 252 prevTypeList.remove(*ittypes);
253 } 253 }
254 } 254 }
@@ -640,129 +640,131 @@ void DocumentListPrivate::estimatedPercentScanned()
640 overallProgress += (docPathsSearched - 1) * levelWeight; 640 overallProgress += (docPathsSearched - 1) * levelWeight;
641 } 641 }
642 642
643 for ( int d = 0; d <= searchDepth; d++ ) { 643 for ( int d = 0; d <= searchDepth; d++ ) {
644 if ( listDirs[d] ) { 644 if ( listDirs[d] ) {
645 int items = lists[d]->count(); 645 int items = lists[d]->count();
646 if ( items > 1 ) { 646 if ( items > 1 ) {
647 levelWeight = levelWeight / items; 647 levelWeight = levelWeight / items;
648 // Take in to account "." and ".." 648 // Take in to account "." and ".."
649 overallProgress += (listPositions[d] - 3) * levelWeight; 649 overallProgress += (listPositions[d] - 3) * levelWeight;
650 } 650 }
651 } else { 651 } else {
652 break; 652 break;
653 } 653 }
654 } 654 }
655 655
656 // odebug << "overallProgress: " << overallProgress << "" << oendl; 656 // odebug << "overallProgress: " << overallProgress << "" << oendl;
657 657
658 if ( serverGui ) 658 if ( serverGui )
659 serverGui->documentScanningProgress( (int)overallProgress ); 659 serverGui->documentScanningProgress( (int)overallProgress );
660} 660}
661 661
662 662
663const QString DocumentListPrivate::nextFile() 663const QString DocumentListPrivate::nextFile()
664{ 664{
665 while ( TRUE ) { 665 while ( TRUE ) {
666 while ( searchDepth < 0 ) { 666 while ( searchDepth < 0 ) {
667 // go to next base path 667 // go to next base path
668 if ( docPathsSearched >= docPaths.count() ) { 668 if ( docPathsSearched >= docPaths.count() ) {
669 // end of base paths 669 // end of base paths
670 return QString::null; 670 return QString::null;
671 } else { 671 } else {
672 QDir dir( docPaths[docPathsSearched] ); 672 QDir dir( docPaths[docPathsSearched] );
673 // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl; 673 // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl;
674 docPathsSearched++; 674 docPathsSearched++;
675 if ( !dir.exists( ".Qtopia-ignore" ) ) { 675 if ( !dir.exists( ".Qtopia-ignore" ) ) {
676 listDirs[0] = new QDir( dir ); 676 listDirs[0] = new QDir( dir );
677 lists[0] = listDirs[0]->entryInfoList(); 677 lists[0] = listDirs[0]->entryInfoList();
678 listPositions[0] = 0; 678 listPositions[0] = 0;
679 searchDepth = 0; 679 searchDepth = 0;
680 } 680 }
681 } 681 }
682 } 682 }
683 683
684 const QFileInfoList *fil = lists[searchDepth]; 684 const QFileInfoList *fil = lists[searchDepth];
685 if (!fil) { 685 if (!fil) {
686 return QString::null; 686 return QString::null;
687 } 687 }
688 QFileInfoList *fl = (QFileInfoList *)fil; 688 QFileInfoList *fl = (QFileInfoList *)fil;
689 unsigned int pos = listPositions[searchDepth]; 689 unsigned int pos = listPositions[searchDepth];
690 690
691 if ( pos >= fl->count() ) { 691 if ( pos >= fl->count() ) {
692 // go up a depth 692 // go up a depth
693 delete listDirs[searchDepth]; 693 delete listDirs[searchDepth];
694 listDirs[searchDepth] = 0; 694 listDirs[searchDepth] = 0;
695 lists[searchDepth] = 0; 695 lists[searchDepth] = 0;
696 listPositions[searchDepth] = 0; 696 listPositions[searchDepth] = 0;
697 searchDepth--; 697 searchDepth--;
698 } else { 698 } else {
699 const QFileInfo *fi = fl->at(pos); 699 const QFileInfo *fi = fl->at(pos);
700 listPositions[searchDepth]++; 700 listPositions[searchDepth]++;
701 QString bn = fi->fileName(); 701 QString bn = fi->fileName();
702 if ( bn[0] != '.' ) { 702 if ( bn[0] != '.' ) {
703 if ( fi->isDir() ) { 703 if ( fi->isDir() ) {
704 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { 704 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop"
705 && bn != "proc" && bn != "dev" && bn != "bin" && bn != "usr"
706 && bn != "etc" && bn != "lib" && bn != "sbin" && bn != "tmp" && bn != "var") {
705 // go down a depth 707 // go down a depth
706 QDir dir( fi->filePath() ); 708 QDir dir( fi->filePath() );
707 // odebug << "now going in to path: " << bn << "" << oendl; 709 // odebug << "now going in to path: " << bn << "" << oendl;
708 if ( !dir.exists( ".Qtopia-ignore" ) ) { 710 if ( !dir.exists( ".Qtopia-ignore" ) ) {
709 if ( searchDepth < MAX_SEARCH_DEPTH - 1) { 711 if ( searchDepth < MAX_SEARCH_DEPTH - 1) {
710 searchDepth++; 712 searchDepth++;
711 listDirs[searchDepth] = new QDir( dir ); 713 listDirs[searchDepth] = new QDir( dir );
712 lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); 714 lists[searchDepth] = listDirs[searchDepth]->entryInfoList();
713 listPositions[searchDepth] = 0; 715 listPositions[searchDepth] = 0;
714 } 716 }
715 } 717 }
716 } 718 }
717 } else { 719 } else {
718 estimatedPercentScanned(); 720 estimatedPercentScanned();
719 return fl->at(pos)->filePath(); 721 return fl->at(pos)->filePath();
720 } 722 }
721 } 723 }
722 } 724 }
723 } 725 }
724 726
725 return QString::null; 727 return QString::null;
726} 728}
727 729
728 730
729bool DocumentListPrivate::store( DocLnk* dl ) 731bool DocumentListPrivate::store( DocLnk* dl )
730{ 732{
731 // if ( dl->fileKnown() && !dl->file().isEmpty() ) { 733 // if ( dl->fileKnown() && !dl->file().isEmpty() ) {
732 if ( dl && dl->fileKnown() ) { 734 if ( dl && dl->fileKnown() ) {
733 dls.add( dl ); // store 735 dls.add( dl ); // store
734 return TRUE; 736 return TRUE;
735 } 737 }
736 738
737 // don't store - delete 739 // don't store - delete
738 delete dl; 740 delete dl;
739 return FALSE; 741 return FALSE;
740} 742}
741 743
742 744
743#define MAGIC_NUMBER ((void*)2) 745#define MAGIC_NUMBER ((void*)2)
744 746
745const DocLnk *DocumentListPrivate::iterate() 747const DocLnk *DocumentListPrivate::iterate()
746{ 748{
747 if ( state == Find ) { 749 if ( state == Find ) {
748 //odebug << "state Find" << oendl; 750 //odebug << "state Find" << oendl;
749 QString file = nextFile(); 751 QString file = nextFile();
750 while ( !file.isNull() ) { 752 while ( !file.isNull() ) {
751 if ( file.right(8) == ".desktop" ) { // No tr 753 if ( file.right(8) == ".desktop" ) { // No tr
752 DocLnk* dl = new DocLnk( file ); 754 DocLnk* dl = new DocLnk( file );
753 if ( store(dl) ) 755 if ( store(dl) )
754 return dl; 756 return dl;
755 } else { 757 } else {
756 reference.insert( file, MAGIC_NUMBER ); 758 reference.insert( file, MAGIC_NUMBER );
757 } 759 }
758 file = nextFile(); 760 file = nextFile();
759 } 761 }
760 state = RemoveKnownFiles; 762 state = RemoveKnownFiles;
761 763
762 if ( serverGui ) 764 if ( serverGui )
763 serverGui->documentScanningProgress( 75 ); 765 serverGui->documentScanningProgress( 75 );
764 } 766 }
765 767
766 static int iterationI; 768 static int iterationI;
767 static int iterationCount; 769 static int iterationCount;
768 770