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
@@ -1,684 +1,689 @@
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*); 66 void appendDocpath(FileSystem*);
67 67
68 68
69 DocLnkSet dls; 69 DocLnkSet dls;
70 QDict<void> reference; 70 QDict<void> reference;
71 QDictIterator<void> *dit; 71 QDictIterator<void> *dit;
72 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; 72 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
73 73
74 QStringList docPaths; 74 QStringList docPaths;
75 unsigned int docPathsSearched; 75 unsigned int docPathsSearched;
76 76
77 int searchDepth; 77 int searchDepth;
78 QDir *listDirs[MAX_SEARCH_DEPTH]; 78 QDir *listDirs[MAX_SEARCH_DEPTH];
79 const QFileInfoList *lists[MAX_SEARCH_DEPTH]; 79 const QFileInfoList *lists[MAX_SEARCH_DEPTH];
80 unsigned int listPositions[MAX_SEARCH_DEPTH]; 80 unsigned int listPositions[MAX_SEARCH_DEPTH];
81 81
82 StorageInfo *storage; 82 StorageInfo *storage;
83 83
84 int tid; 84 int tid;
85 85
86 ServerInterface *serverGui; 86 ServerInterface *serverGui;
87 87
88 bool needToSendAllDocLinks; 88 bool needToSendAllDocLinks;
89 bool sendAppLnks; 89 bool sendAppLnks;
90 bool sendDocLnks; 90 bool sendDocLnks;
91 bool scanDocs; 91 bool scanDocs;
92}; 92};
93 93
94 94
95/* 95/*
96 * scandocs will be read from Config 96 * scandocs will be read from Config
97 */ 97 */
98DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, 98DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
99 QObject *parent, const char *name ) 99 QObject *parent, const char *name )
100 : QObject( parent, name ) 100 : QObject( parent, name )
101{ 101{
102 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 102 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
103 d = new DocumentListPrivate( serverGui ); 103 d = new DocumentListPrivate( serverGui );
104 d->needToSendAllDocLinks = false; 104 d->needToSendAllDocLinks = false;
105 105
106 Config cfg( "Launcher" ); 106 Config cfg( "Launcher" );
107 cfg.setGroup( "DocTab" ); 107 cfg.setGroup( "DocTab" );
108 d->scanDocs = cfg.readBoolEntry( "Enable", true ); 108 d->scanDocs = cfg.readBoolEntry( "Enable", true );
109 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); 109 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
110 110
111 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); 111 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
112} 112}
113 113
114void DocumentList::startInitialScan() 114void DocumentList::startInitialScan()
115{ 115{
116 reloadAppLnks(); 116 reloadAppLnks();
117 reloadDocLnks(); 117 reloadDocLnks();
118} 118}
119 119
120DocumentList::~DocumentList() 120DocumentList::~DocumentList()
121{ 121{
122 delete appLnkSet; 122 delete appLnkSet;
123 delete d; 123 delete d;
124} 124}
125 125
126 126
127void DocumentList::add( const DocLnk& doc ) 127void DocumentList::add( const DocLnk& doc )
128{ 128{
129 if ( d->serverGui && QFile::exists( doc.file() ) ) 129 if ( d->serverGui && QFile::exists( doc.file() ) )
130 d->serverGui->documentAdded( doc ); 130 d->serverGui->documentAdded( doc );
131} 131}
132 132
133 133
134void DocumentList::start() 134void DocumentList::start()
135{ 135{
136 resume(); 136 resume();
137} 137}
138 138
139 139
140void DocumentList::pause() 140void DocumentList::pause()
141{ 141{
142 //qDebug("pause %i", d->tid); 142 //qDebug("pause %i", d->tid);
143 killTimer( d->tid ); 143 killTimer( d->tid );
144 d->tid = 0; 144 d->tid = 0;
145} 145}
146 146
147 147
148void DocumentList::resume() 148void DocumentList::resume()
149{ 149{
150 if ( d->tid == 0 ) { 150 if ( d->tid == 0 ) {
151 d->tid = startTimer( 20 ); 151 d->tid = startTimer( 20 );
152 //qDebug("resumed %i", d->tid); 152 //qDebug("resumed %i", d->tid);
153 } 153 }
154} 154}
155 155
156/* 156/*
157void DocumentList::resend() 157void DocumentList::resend()
158{ 158{
159 // 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
160 // clear what they have as it is being sent again) 160 // clear what they have as it is being sent again)
161 pause(); 161 pause();
162 emit allRemoved(); 162 emit allRemoved();
163 QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); 163 QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
164} 164}
165 165
166 166
167void DocumentList::resendWorker() 167void DocumentList::resendWorker()
168{ 168{
169 const QList<DocLnk> &list = d->dls.children(); 169 const QList<DocLnk> &list = d->dls.children();
170 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) 170 for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
171 add( *(*it) ); 171 add( *(*it) );
172 resume(); 172 resume();
173} 173}
174*/ 174*/
175 175
176void DocumentList::rescan() 176void DocumentList::rescan()
177{ 177{
178 //qDebug("rescan"); 178 //qDebug("rescan");
179 pause(); 179 pause();
180 d->initialize(); 180 d->initialize();
181 resume(); 181 resume();
182} 182}
183 183
184 184
185void DocumentList::timerEvent( QTimerEvent *te ) 185void DocumentList::timerEvent( QTimerEvent *te )
186{ 186{
187 if ( te->timerId() == d->tid ) { 187 if ( te->timerId() == d->tid ) {
188 // Do 3 at a time 188 // Do 3 at a time
189 for (int i = 0; i < 3; i++ ) { 189 for (int i = 0; i < 3; i++ ) {
190 const DocLnk *lnk = d->iterate(); 190 const DocLnk *lnk = d->iterate();
191 if ( lnk ) { 191 if ( lnk ) {
192 add( *lnk ); 192 add( *lnk );
193 } else { 193 } else {
194 // stop when done 194 // stop when done
195 pause(); 195 pause();
196 if ( d->serverGui ) 196 if ( d->serverGui )
197 d->serverGui->documentScanningProgress( 100 ); 197 d->serverGui->documentScanningProgress( 100 );
198 if ( d->needToSendAllDocLinks ) 198 if ( d->needToSendAllDocLinks )
199 sendAllDocLinks(); 199 sendAllDocLinks();
200 break; 200 break;
201 } 201 }
202 } 202 }
203 } 203 }
204} 204}
205 205
206 206
207void DocumentList::reloadAppLnks() 207void DocumentList::reloadAppLnks()
208{ 208{
209 if ( d->sendAppLnks && d->serverGui ) { 209 if ( d->sendAppLnks && d->serverGui ) {
210 d->serverGui->applicationScanningProgress( 0 ); 210 d->serverGui->applicationScanningProgress( 0 );
211 d->serverGui->allApplicationsRemoved(); 211 d->serverGui->allApplicationsRemoved();
212 } 212 }
213 213
214 delete appLnkSet; 214 delete appLnkSet;
215 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 215 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
216 216
217 if ( d->sendAppLnks && d->serverGui ) { 217 if ( d->sendAppLnks && d->serverGui ) {
218 static QStringList prevTypeList; 218 static QStringList prevTypeList;
219 QStringList types = appLnkSet->types(); 219 QStringList types = appLnkSet->types();
220 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 220 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
221 if ( !(*ittypes).isEmpty() ) { 221 if ( !(*ittypes).isEmpty() ) {
222 if ( !prevTypeList.contains(*ittypes) ) { 222 if ( !prevTypeList.contains(*ittypes) ) {
223 QString name = appLnkSet->typeName(*ittypes); 223 QString name = appLnkSet->typeName(*ittypes);
224 QPixmap pm = appLnkSet->typePixmap(*ittypes); 224 QPixmap pm = appLnkSet->typePixmap(*ittypes);
225 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 225 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
226 226
227 if (pm.isNull()) { 227 if (pm.isNull()) {
228 QImage img( Resource::loadImage( "UnknownDocument" ) ); 228 QImage img( Resource::loadImage( "UnknownDocument" ) );
229 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 229 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
230 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); 230 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
231 } 231 }
232 232
233 //qDebug("adding type %s", (*ittypes).latin1()); 233 //qDebug("adding type %s", (*ittypes).latin1());
234 234
235 // ### our current launcher expects docs tab to be last 235 // ### our current launcher expects docs tab to be last
236 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 236 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
237 } 237 }
238 prevTypeList.remove(*ittypes); 238 prevTypeList.remove(*ittypes);
239 } 239 }
240 } 240 }
241 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 241 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
242 //qDebug("removing type %s", (*ittypes).latin1()); 242 //qDebug("removing type %s", (*ittypes).latin1());
243 d->serverGui->typeRemoved(*ittypes); 243 d->serverGui->typeRemoved(*ittypes);
244 } 244 }
245 prevTypeList = types; 245 prevTypeList = types;
246 } 246 }
247 247
248 QListIterator<AppLnk> itapp( appLnkSet->children() ); 248 QListIterator<AppLnk> itapp( appLnkSet->children() );
249 AppLnk* l; 249 AppLnk* l;
250 while ( (l=itapp.current()) ) { 250 while ( (l=itapp.current()) ) {
251 ++itapp; 251 ++itapp;
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;
636 static int iterationCount; 641 static int iterationCount;
637 642
638 if ( state == RemoveKnownFiles ) { 643 if ( state == RemoveKnownFiles ) {
639 //qDebug("state RemoveKnownFiles"); 644 //qDebug("state RemoveKnownFiles");
640 const QList<DocLnk> &list = dls.children(); 645 const QList<DocLnk> &list = dls.children();
641 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 646 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
642 reference.remove( (*it)->file() ); 647 reference.remove( (*it)->file() );
643 // ### does this need to be deleted? 648 // ### does this need to be deleted?
644 } 649 }
645 dit = new QDictIterator<void>(reference); 650 dit = new QDictIterator<void>(reference);
646 state = MakeUnknownFiles; 651 state = MakeUnknownFiles;
647 652
648 iterationI = 0; 653 iterationI = 0;
649 iterationCount = dit->count(); 654 iterationCount = dit->count();
650 } 655 }
651 656
652 if ( state == MakeUnknownFiles ) { 657 if ( state == MakeUnknownFiles ) {
653 //qDebug("state MakeUnknownFiles"); 658 //qDebug("state MakeUnknownFiles");
654 for (void* c; (c=dit->current()); ++(*dit) ) { 659 for (void* c; (c=dit->current()); ++(*dit) ) {
655 if ( c == MAGIC_NUMBER ) { 660 if ( c == MAGIC_NUMBER ) {
656 DocLnk* dl = new DocLnk; 661 DocLnk* dl = new DocLnk;
657 QFileInfo fi( dit->currentKey() ); 662 QFileInfo fi( dit->currentKey() );
658 dl->setFile( fi.filePath() ); 663 dl->setFile( fi.filePath() );
659 dl->setName( fi.baseName() ); 664 dl->setName( fi.baseName() );
660 if ( store(dl) ) { 665 if ( store(dl) ) {
661 ++*dit; 666 ++*dit;
662 iterationI++; 667 iterationI++;
663 if ( serverGui ) 668 if ( serverGui )
664 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); 669 serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount );
665 return dl; 670 return dl;
666 } 671 }
667 } 672 }
668 iterationI++; 673 iterationI++;
669 } 674 }
670 675
671 delete dit; 676 delete dit;
672 dit = 0; 677 dit = 0;
673 state = Done; 678 state = Done;
674 } 679 }
675 680
676 //qDebug("state Done"); 681 //qDebug("state Done");
677 return NULL; 682 return NULL;
678} 683}
679 684
680 685
681#include "documentlist.moc" 686#include "documentlist.moc"
682 687
683 688
684 689