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
@@ -1,655 +1,684 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
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{
114 reloadAppLnks(); 116 reloadAppLnks();
115 reloadDocLnks(); 117 reloadDocLnks();
116} 118}
117 119
118DocumentList::~DocumentList() 120DocumentList::~DocumentList()
119{ 121{
120 delete appLnkSet; 122 delete appLnkSet;
121 delete d; 123 delete d;
122} 124}
123 125
124 126
125void DocumentList::add( const DocLnk& doc ) 127void DocumentList::add( const DocLnk& doc )
126{ 128{
127 if ( d->serverGui && QFile::exists( doc.file() ) ) 129 if ( d->serverGui && QFile::exists( doc.file() ) )
128 d->serverGui->documentAdded( doc ); 130 d->serverGui->documentAdded( doc );
129} 131}
130 132
131 133
132void DocumentList::start() 134void DocumentList::start()
133{ 135{
134 resume(); 136 resume();
135} 137}
136 138
137 139
138void DocumentList::pause() 140void DocumentList::pause()
139{ 141{
140 //qDebug("pause %i", d->tid); 142 //qDebug("pause %i", d->tid);
141 killTimer( d->tid ); 143 killTimer( d->tid );
142 d->tid = 0; 144 d->tid = 0;
143} 145}
144 146
145 147
146void DocumentList::resume() 148void DocumentList::resume()
147{ 149{
148 if ( d->tid == 0 ) { 150 if ( d->tid == 0 ) {
149 d->tid = startTimer( 20 ); 151 d->tid = startTimer( 20 );
150 //qDebug("resumed %i", d->tid); 152 //qDebug("resumed %i", d->tid);
151 } 153 }
152} 154}
153 155
154/* 156/*
155void DocumentList::resend() 157void DocumentList::resend()
156{ 158{
157 // Re-emits all the added items to the list (firstly letting everyone know to 159 // Re-emits all the added items to the list (firstly letting everyone know to
158 // clear what they have as it is being sent again) 160 // clear what they have as it is being sent again)
159 pause(); 161 pause();
160 emit allRemoved(); 162 emit allRemoved();
161 QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); 163 QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
162} 164}
163 165
164 166
165void DocumentList::resendWorker() 167void DocumentList::resendWorker()
166{ 168{
167 const QList<DocLnk> &list = d->dls.children(); 169 const QList<DocLnk> &list = d->dls.children();
168 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) 170 for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
169 add( *(*it) ); 171 add( *(*it) );
170 resume(); 172 resume();
171} 173}
172*/ 174*/
173 175
174void DocumentList::rescan() 176void DocumentList::rescan()
175{ 177{
176 //qDebug("rescan"); 178 //qDebug("rescan");
177 pause(); 179 pause();
178 d->initialize(); 180 d->initialize();
179 resume(); 181 resume();
180} 182}
181 183
182 184
183void DocumentList::timerEvent( QTimerEvent *te ) 185void DocumentList::timerEvent( QTimerEvent *te )
184{ 186{
185 if ( te->timerId() == d->tid ) { 187 if ( te->timerId() == d->tid ) {
186 // Do 3 at a time 188 // Do 3 at a time
187 for (int i = 0; i < 3; i++ ) { 189 for (int i = 0; i < 3; i++ ) {
188 const DocLnk *lnk = d->iterate(); 190 const DocLnk *lnk = d->iterate();
189 if ( lnk ) { 191 if ( lnk ) {
190 add( *lnk ); 192 add( *lnk );
191 } else { 193 } else {
192 // stop when done 194 // stop when done
193 pause(); 195 pause();
194 if ( d->serverGui ) 196 if ( d->serverGui )
195 d->serverGui->documentScanningProgress( 100 ); 197 d->serverGui->documentScanningProgress( 100 );
196 if ( d->needToSendAllDocLinks ) 198 if ( d->needToSendAllDocLinks )
197 sendAllDocLinks(); 199 sendAllDocLinks();
198 break; 200 break;
199 } 201 }
200 } 202 }
201 } 203 }
202} 204}
203 205
204 206
205void DocumentList::reloadAppLnks() 207void DocumentList::reloadAppLnks()
206{ 208{
207 if ( d->sendAppLnks && d->serverGui ) { 209 if ( d->sendAppLnks && d->serverGui ) {
208 d->serverGui->applicationScanningProgress( 0 ); 210 d->serverGui->applicationScanningProgress( 0 );
209 d->serverGui->allApplicationsRemoved(); 211 d->serverGui->allApplicationsRemoved();
210 } 212 }
211 213
212 delete appLnkSet; 214 delete appLnkSet;
213 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 215 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
214 216
215 if ( d->sendAppLnks && d->serverGui ) { 217 if ( d->sendAppLnks && d->serverGui ) {
216 static QStringList prevTypeList; 218 static QStringList prevTypeList;
217 QStringList types = appLnkSet->types(); 219 QStringList types = appLnkSet->types();
218 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 220 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
219 if ( !(*ittypes).isEmpty() ) { 221 if ( !(*ittypes).isEmpty() ) {
220 if ( !prevTypeList.contains(*ittypes) ) { 222 if ( !prevTypeList.contains(*ittypes) ) {
221 QString name = appLnkSet->typeName(*ittypes); 223 QString name = appLnkSet->typeName(*ittypes);
222 QPixmap pm = appLnkSet->typePixmap(*ittypes); 224 QPixmap pm = appLnkSet->typePixmap(*ittypes);
223 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 225 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
224 226
225 if (pm.isNull()) { 227 if (pm.isNull()) {
226 QImage img( Resource::loadImage( "UnknownDocument" ) ); 228 QImage img( Resource::loadImage( "UnknownDocument" ) );
227 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 229 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
228 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); 230 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
229 } 231 }
230 232
231 //qDebug("adding type %s", (*ittypes).latin1()); 233 //qDebug("adding type %s", (*ittypes).latin1());
232 234
233 // ### our current launcher expects docs tab to be last 235 // ### our current launcher expects docs tab to be last
234 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 236 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
235 } 237 }
236 prevTypeList.remove(*ittypes); 238 prevTypeList.remove(*ittypes);
237 } 239 }
238 } 240 }
239 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 241 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
240 //qDebug("removing type %s", (*ittypes).latin1()); 242 //qDebug("removing type %s", (*ittypes).latin1());
241 d->serverGui->typeRemoved(*ittypes); 243 d->serverGui->typeRemoved(*ittypes);
242 } 244 }
243 prevTypeList = types; 245 prevTypeList = types;
244 } 246 }
245 247
246 QListIterator<AppLnk> itapp( appLnkSet->children() ); 248 QListIterator<AppLnk> itapp( appLnkSet->children() );
247 AppLnk* l; 249 AppLnk* l;
248 while ( (l=itapp.current()) ) { 250 while ( (l=itapp.current()) ) {
249 ++itapp; 251 ++itapp;
250 if ( d->sendAppLnks && d->serverGui ) 252 if ( d->sendAppLnks && d->serverGui )
251 d->serverGui->applicationAdded( l->type(), *l ); 253 d->serverGui->applicationAdded( l->type(), *l );
252 } 254 }
253 255
254 if ( d->sendAppLnks && d->serverGui ) 256 if ( d->sendAppLnks && d->serverGui )
255 d->serverGui->applicationScanningProgress( 100 ); 257 d->serverGui->applicationScanningProgress( 100 );
256} 258}
257 259
258void DocumentList::reloadDocLnks() 260void DocumentList::reloadDocLnks()
259{ 261{
260 if ( !d->scanDocs ) 262 if ( !d->scanDocs )
261 return; 263 return;
262 264
263 if ( d->sendDocLnks && d->serverGui ) { 265 if ( d->sendDocLnks && d->serverGui ) {
264 d->serverGui->documentScanningProgress( 0 ); 266 d->serverGui->documentScanningProgress( 0 );
265 d->serverGui->allDocumentsRemoved(); 267 d->serverGui->allDocumentsRemoved();
266 } 268 }
267 269
268 rescan(); 270 rescan();
269} 271}
270 272
271void DocumentList::linkChanged( QString arg ) 273void DocumentList::linkChanged( QString arg )
272{ 274{
273 //qDebug( "linkchanged( %s )", arg.latin1() ); 275 //qDebug( "linkchanged( %s )", arg.latin1() );
274 276
275 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { 277 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
276 reloadAppLnks(); 278 reloadAppLnks();
277 } else { 279 } else {
278 280
279 const QList<DocLnk> &list = d->dls.children(); 281 const QList<DocLnk> &list = d->dls.children();
280 QListIterator<DocLnk> it( list ); 282 QListIterator<DocLnk> it( list );
281 while ( it.current() ) { 283 while ( it.current() ) {
282 DocLnk *doc = it.current(); 284 DocLnk *doc = it.current();
283 ++it; 285 ++it;
284 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 286 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
285 || ( doc->fileKnown() && doc->file() == arg ) ) { 287 || ( doc->fileKnown() && doc->file() == arg ) ) {
286 //qDebug( "found old link" ); 288 //qDebug( "found old link" );
287 DocLnk* dl = new DocLnk( arg ); 289 DocLnk* dl = new DocLnk( arg );
288 // add new one if it exists and matches the mimetype 290 // add new one if it exists and matches the mimetype
289 if ( d->store( dl ) ) { 291 if ( d->store( dl ) ) {
290 // 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
291 // to the new link 293 // to the new link
292 //qDebug( "change case" ); 294 //qDebug( "change case" );
293 if ( d->serverGui ) 295 if ( d->serverGui )
294 d->serverGui->documentChanged( *doc, *dl ); 296 d->serverGui->documentChanged( *doc, *dl );
295 297
296 } else { 298 } else {
297 // 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
298 // 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
299 //qDebug( "removal case" ); 301 //qDebug( "removal case" );
300 if ( d->serverGui ) 302 if ( d->serverGui )
301 d->serverGui->documentRemoved( *doc ); 303 d->serverGui->documentRemoved( *doc );
302 304
303 } 305 }
304 d->dls.remove( doc ); // remove old link from docLnkSet 306 d->dls.remove( doc ); // remove old link from docLnkSet
305 delete doc; 307 delete doc;
306 return; 308 return;
307 } 309 }
308 } 310 }
309 // Didn't find existing link, must be new 311 // Didn't find existing link, must be new
310 DocLnk* dl = new DocLnk( arg ); 312 DocLnk* dl = new DocLnk( arg );
311 if ( d->store( dl ) ) { 313 if ( d->store( dl ) ) {
312 // Add if it's a link we are interested in 314 // Add if it's a link we are interested in
313 //qDebug( "add case" ); 315 //qDebug( "add case" );
314 add( *dl ); 316 add( *dl );
315 } 317 }
316 318
317 } 319 }
318} 320}
319 321
320void DocumentList::restoreDone() 322void DocumentList::restoreDone()
321{ 323{
322 reloadAppLnks(); 324 reloadAppLnks();
323 reloadDocLnks(); 325 reloadDocLnks();
324} 326}
325 327
326void DocumentList::storageChanged() 328void DocumentList::storageChanged()
327{ 329{
328 // ### can implement better 330 // ### can implement better
329 reloadAppLnks(); 331 reloadAppLnks();
330 reloadDocLnks(); 332 reloadDocLnks();
331 // ### Optimization opportunity 333 // ### Optimization opportunity
332 // Could be a bit more intelligent and somehow work out which 334 // Could be a bit more intelligent and somehow work out which
333 // 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
334 // links appropriately. 336 // links appropriately.
335// rescan(); 337// rescan();
336} 338}
337 339
338void DocumentList::sendAllDocLinks() 340void DocumentList::sendAllDocLinks()
339{ 341{
340 if ( d->tid != 0 ) { 342 if ( d->tid != 0 ) {
341 // We are in the middle of scanning, set a flag so 343 // We are in the middle of scanning, set a flag so
342 // we do this when we finish our scanning 344 // we do this when we finish our scanning
343 d->needToSendAllDocLinks = true; 345 d->needToSendAllDocLinks = true;
344 return; 346 return;
345 } 347 }
346 348
347 QString contents; 349 QString contents;
348 Categories cats; 350 Categories cats;
349 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 351 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
350 DocLnk *doc = it.current(); 352 DocLnk *doc = it.current();
351 QFileInfo fi( doc->file() ); 353 QFileInfo fi( doc->file() );
352 if ( !fi.exists() ) 354 if ( !fi.exists() )
353 continue; 355 continue;
354 356
355 bool fake = !doc->linkFileKnown(); 357 bool fake = !doc->linkFileKnown();
356 if ( !fake ) { 358 if ( !fake ) {
357 QFile f( doc->linkFile() ); 359 QFile f( doc->linkFile() );
358 if ( f.open( IO_ReadOnly ) ) { 360 if ( f.open( IO_ReadOnly ) ) {
359 QTextStream ts( &f ); 361 QTextStream ts( &f );
360 ts.setEncoding( QTextStream::UnicodeUTF8 ); 362 ts.setEncoding( QTextStream::UnicodeUTF8 );
361 contents += ts.read(); 363 contents += ts.read();
362 f.close(); 364 f.close();
363 } else 365 } else
364 fake = TRUE; 366 fake = TRUE;
365 } 367 }
366 if (fake) { 368 if (fake) {
367 contents += "[Desktop Entry]\n"; // No tr 369 contents += "[Desktop Entry]\n"; // No tr
368 contents += "Categories = " + // No tr 370 contents += "Categories = " + // No tr
369 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 371 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
370 contents += "Name = "+doc->name()+"\n"; // No tr 372 contents += "Name = "+doc->name()+"\n"; // No tr
371 contents += "Type = "+doc->type()+"\n"; // No tr 373 contents += "Type = "+doc->type()+"\n"; // No tr
372 } 374 }
373 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 375 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
374 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 376 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
375 } 377 }
376 378
377 //qDebug( "sending length %d", contents.length() ); 379 //qDebug( "sending length %d", contents.length() );
378#ifndef QT_NO_COP 380#ifndef QT_NO_COP
379 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 381 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
380 e << contents; 382 e << contents;
381#endif 383#endif
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
499 // qDebug( "overallProgress: %f", overallProgress ); 528 // qDebug( "overallProgress: %f", overallProgress );
500 529
501 if ( serverGui ) 530 if ( serverGui )
502 serverGui->documentScanningProgress( (int)overallProgress ); 531 serverGui->documentScanningProgress( (int)overallProgress );
503} 532}
504 533
505 534
506const QString DocumentListPrivate::nextFile() 535const QString DocumentListPrivate::nextFile()
507{ 536{
508 while ( TRUE ) { 537 while ( TRUE ) {
509 while ( searchDepth < 0 ) { 538 while ( searchDepth < 0 ) {
510 // go to next base path 539 // go to next base path
511 if ( docPathsSearched >= docPaths.count() ) { 540 if ( docPathsSearched >= docPaths.count() ) {
512 // end of base paths 541 // end of base paths
513 return QString::null; 542 return QString::null;
514 } else { 543 } else {
515 QDir dir( docPaths[docPathsSearched] ); 544 QDir dir( docPaths[docPathsSearched] );
516 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); 545 // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() );
517 docPathsSearched++; 546 docPathsSearched++;
518 if ( !dir.exists( ".Qtopia-ignore" ) ) { 547 if ( !dir.exists( ".Qtopia-ignore" ) ) {
519 listDirs[0] = new QDir( dir ); 548 listDirs[0] = new QDir( dir );
520 lists[0] = listDirs[0]->entryInfoList(); 549 lists[0] = listDirs[0]->entryInfoList();
521 listPositions[0] = 0; 550 listPositions[0] = 0;
522 searchDepth = 0; 551 searchDepth = 0;
523 } 552 }
524 } 553 }
525 } 554 }
526 555
527 const QFileInfoList *fil = lists[searchDepth]; 556 const QFileInfoList *fil = lists[searchDepth];
528 QFileInfoList *fl = (QFileInfoList *)fil; 557 QFileInfoList *fl = (QFileInfoList *)fil;
529 unsigned int pos = listPositions[searchDepth]; 558 unsigned int pos = listPositions[searchDepth];
530 559
531 if ( pos >= fl->count() ) { 560 if ( pos >= fl->count() ) {
532 // go up a depth 561 // go up a depth
533 delete listDirs[searchDepth]; 562 delete listDirs[searchDepth];
534 listDirs[searchDepth] = 0; 563 listDirs[searchDepth] = 0;
535 lists[searchDepth] = 0; 564 lists[searchDepth] = 0;
536 listPositions[searchDepth] = 0; 565 listPositions[searchDepth] = 0;
537 searchDepth--; 566 searchDepth--;
538 } else { 567 } else {
539 const QFileInfo *fi = fl->at(pos); 568 const QFileInfo *fi = fl->at(pos);
540 listPositions[searchDepth]++; 569 listPositions[searchDepth]++;
541 QString bn = fi->fileName(); 570 QString bn = fi->fileName();
542 if ( bn[0] != '.' ) { 571 if ( bn[0] != '.' ) {
543 if ( fi->isDir() ) { 572 if ( fi->isDir() ) {
544 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { 573 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) {
545 // go down a depth 574 // go down a depth
546 QDir dir( fi->filePath() ); 575 QDir dir( fi->filePath() );
547 // qDebug("now going in to path: %s", bn.latin1() ); 576 // qDebug("now going in to path: %s", bn.latin1() );
548 if ( !dir.exists( ".Qtopia-ignore" ) ) { 577 if ( !dir.exists( ".Qtopia-ignore" ) ) {
549 if ( searchDepth < MAX_SEARCH_DEPTH - 1) { 578 if ( searchDepth < MAX_SEARCH_DEPTH - 1) {
550 searchDepth++; 579 searchDepth++;
551 listDirs[searchDepth] = new QDir( dir ); 580 listDirs[searchDepth] = new QDir( dir );
552 lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); 581 lists[searchDepth] = listDirs[searchDepth]->entryInfoList();
553 listPositions[searchDepth] = 0; 582 listPositions[searchDepth] = 0;
554 } 583 }
555 } 584 }
556 } 585 }
557 } else { 586 } else {
558 estimatedPercentScanned(); 587 estimatedPercentScanned();
559 return fl->at(pos)->filePath(); 588 return fl->at(pos)->filePath();
560 } 589 }
561 } 590 }
562 } 591 }
563 } 592 }
564 593
565 return QString::null; 594 return QString::null;
566} 595}
567 596
568 597
569bool DocumentListPrivate::store( DocLnk* dl ) 598bool DocumentListPrivate::store( DocLnk* dl )
570{ 599{
571 // if ( dl->fileKnown() && !dl->file().isEmpty() ) { 600 // if ( dl->fileKnown() && !dl->file().isEmpty() ) {
572 if ( dl && dl->fileKnown() ) { 601 if ( dl && dl->fileKnown() ) {
573 dls.add( dl ); // store 602 dls.add( dl ); // store
574 return TRUE; 603 return TRUE;
575 } 604 }
576 605
577 // don't store - delete 606 // don't store - delete
578 delete dl; 607 delete dl;
579 return FALSE; 608 return FALSE;
580} 609}
581 610
582 611
583 #define MAGIC_NUMBER((void*)2) 612 #define MAGIC_NUMBER((void*)2)
584 613
585const DocLnk *DocumentListPrivate::iterate() 614const DocLnk *DocumentListPrivate::iterate()
586{ 615{
587 if ( state == Find ) { 616 if ( state == Find ) {
588 //qDebug("state Find"); 617 //qDebug("state Find");
589 QString file = nextFile(); 618 QString file = nextFile();
590 while ( !file.isNull() ) { 619 while ( !file.isNull() ) {
591 if ( file.right(8) == ".desktop" ) { // No tr 620 if ( file.right(8) == ".desktop" ) { // No tr
592 DocLnk* dl = new DocLnk( file ); 621 DocLnk* dl = new DocLnk( file );
593 if ( store(dl) ) 622 if ( store(dl) )
594 return dl; 623 return dl;
595 } else { 624 } else {
596 reference.insert( file, MAGIC_NUMBER ); 625 reference.insert( file, MAGIC_NUMBER );
597 } 626 }
598 file = nextFile(); 627 file = nextFile();
599 } 628 }
600 state = RemoveKnownFiles; 629 state = RemoveKnownFiles;
601 630
602 if ( serverGui ) 631 if ( serverGui )
603 serverGui->documentScanningProgress( 75 ); 632 serverGui->documentScanningProgress( 75 );
604 } 633 }
605 634
606 static int iterationI; 635 static int iterationI;
607 static int iterationCount; 636 static int iterationCount;
608 637
609 if ( state == RemoveKnownFiles ) { 638 if ( state == RemoveKnownFiles ) {
610 //qDebug("state RemoveKnownFiles"); 639 //qDebug("state RemoveKnownFiles");
611 const QList<DocLnk> &list = dls.children(); 640 const QList<DocLnk> &list = dls.children();
612 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 641 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
613 reference.remove( (*it)->file() ); 642 reference.remove( (*it)->file() );
614 // ### does this need to be deleted? 643 // ### does this need to be deleted?
615 } 644 }
616 dit = new QDictIterator<void>(reference); 645 dit = new QDictIterator<void>(reference);
617 state = MakeUnknownFiles; 646 state = MakeUnknownFiles;
618 647
619 iterationI = 0; 648 iterationI = 0;
620 iterationCount = dit->count(); 649 iterationCount = dit->count();
621 } 650 }
622 651
623 if ( state == MakeUnknownFiles ) { 652 if ( state == MakeUnknownFiles ) {
624 //qDebug("state MakeUnknownFiles"); 653 //qDebug("state MakeUnknownFiles");
625 for (void* c; (c=dit->current()); ++(*dit) ) { 654 for (void* c; (c=dit->current()); ++(*dit) ) {
626 if ( c == MAGIC_NUMBER ) { 655 if ( c == MAGIC_NUMBER ) {
627 DocLnk* dl = new DocLnk; 656 DocLnk* dl = new DocLnk;
628 QFileInfo fi( dit->currentKey() ); 657 QFileInfo fi( dit->currentKey() );
629 dl->setFile( fi.filePath() ); 658 dl->setFile( fi.filePath() );
630 dl->setName( fi.baseName() ); 659 dl->setName( fi.baseName() );
631 if ( store(dl) ) { 660 if ( store(dl) ) {
632 ++*dit; 661 ++*dit;
633 iterationI++; 662 iterationI++;
634 if ( serverGui ) 663 if ( serverGui )
635 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); 664 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount );
636 return dl; 665 return dl;
637 } 666 }
638 } 667 }
639 iterationI++; 668 iterationI++;
640 } 669 }
641 670
642 delete dit; 671 delete dit;
643 dit = 0; 672 dit = 0;
644 state = Done; 673 state = Done;
645 } 674 }
646 675
647 //qDebug("state Done"); 676 //qDebug("state Done");
648 return NULL; 677 return NULL;
649} 678}
650 679
651 680
652#include "documentlist.moc" 681#include "documentlist.moc"
653 682
654 683
655 684