-rw-r--r-- | core/launcher/documentlist.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index 033dd10..7f9366e 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp | |||
@@ -1,58 +1,59 @@ | |||
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 | #include "launcherglobal.h" | ||
22 | 23 | ||
23 | #include <qtopia/mimetype.h> | 24 | #include <qtopia/mimetype.h> |
24 | #include <qtopia/resource.h> | 25 | #include <qtopia/resource.h> |
25 | #include <qtopia/global.h> | 26 | #include <qtopia/global.h> |
26 | #include <qtopia/categories.h> | 27 | #include <qtopia/private/categories.h> |
27 | #include <qtopia/qpeapplication.h> | 28 | #include <qtopia/qpeapplication.h> |
28 | #include <qtopia/applnk.h> | 29 | #include <qtopia/applnk.h> |
29 | #include <qtopia/storage.h> | 30 | #include <qtopia/storage.h> |
30 | #ifdef Q_WS_QWS | 31 | #ifdef Q_WS_QWS |
31 | #include <qtopia/qcopenvelope_qws.h> | 32 | #include <qtopia/qcopenvelope_qws.h> |
32 | #endif | 33 | #endif |
33 | 34 | ||
34 | #include <qtimer.h> | 35 | #include <qtimer.h> |
35 | #include <qfileinfo.h> | 36 | #include <qfileinfo.h> |
36 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
37 | #include <qfile.h> | 38 | #include <qfile.h> |
38 | #include <qdir.h> | 39 | #include <qdir.h> |
39 | #include <qpainter.h> | 40 | #include <qpainter.h> |
40 | #include <qimage.h> | 41 | #include <qimage.h> |
41 | #include <qcopchannel_qws.h> | 42 | #include <qcopchannel_qws.h> |
42 | #include <qlistview.h> | 43 | #include <qlistview.h> |
43 | #include <qlist.h> | 44 | #include <qlist.h> |
44 | #include <qpixmap.h> | 45 | #include <qpixmap.h> |
45 | 46 | ||
46 | 47 | ||
47 | AppLnkSet *DocumentList::appLnkSet = 0; | 48 | AppLnkSet *DocumentList::appLnkSet = 0; |
48 | 49 | ||
49 | static const int MAX_SEARCH_DEPTH = 10; | 50 | static const int MAX_SEARCH_DEPTH = 10; |
50 | 51 | ||
51 | 52 | ||
52 | class DocumentListPrivate : public QObject { | 53 | class DocumentListPrivate : public QObject { |
53 | Q_OBJECT | 54 | Q_OBJECT |
54 | public: | 55 | public: |
55 | DocumentListPrivate( ServerInterface *gui ); | 56 | DocumentListPrivate( ServerInterface *gui ); |
56 | ~DocumentListPrivate(); | 57 | ~DocumentListPrivate(); |
57 | 58 | ||
58 | void initialize(); | 59 | void initialize(); |
@@ -213,95 +214,95 @@ void DocumentList::reloadAppLnks() | |||
213 | QPixmap pm = appLnkSet->typePixmap(*ittypes); | 214 | QPixmap pm = appLnkSet->typePixmap(*ittypes); |
214 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); | 215 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); |
215 | 216 | ||
216 | if (pm.isNull()) { | 217 | if (pm.isNull()) { |
217 | QImage img( Resource::loadImage( "UnknownDocument" ) ); | 218 | QImage img( Resource::loadImage( "UnknownDocument" ) ); |
218 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 219 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
219 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); | 220 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); |
220 | } | 221 | } |
221 | 222 | ||
222 | //qDebug("adding type %s", (*ittypes).latin1()); | 223 | //qDebug("adding type %s", (*ittypes).latin1()); |
223 | 224 | ||
224 | // ### our current launcher expects docs tab to be last | 225 | // ### our current launcher expects docs tab to be last |
225 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 226 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
226 | } | 227 | } |
227 | prevTypeList.remove(*ittypes); | 228 | prevTypeList.remove(*ittypes); |
228 | } | 229 | } |
229 | } | 230 | } |
230 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 231 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
231 | //qDebug("removing type %s", (*ittypes).latin1()); | 232 | //qDebug("removing type %s", (*ittypes).latin1()); |
232 | d->serverGui->typeRemoved(*ittypes); | 233 | d->serverGui->typeRemoved(*ittypes); |
233 | } | 234 | } |
234 | prevTypeList = types; | 235 | prevTypeList = types; |
235 | } | 236 | } |
236 | 237 | ||
237 | QListIterator<AppLnk> itapp( appLnkSet->children() ); | 238 | QListIterator<AppLnk> itapp( appLnkSet->children() ); |
238 | AppLnk* l; | 239 | AppLnk* l; |
239 | while ( (l=itapp.current()) ) { | 240 | while ( (l=itapp.current()) ) { |
240 | ++itapp; | 241 | ++itapp; |
241 | if ( d->sendAppLnks && d->serverGui ) | 242 | if ( d->sendAppLnks && d->serverGui ) |
242 | d->serverGui->applicationAdded( l->type(), *l ); | 243 | d->serverGui->applicationAdded( l->type(), *l ); |
243 | } | 244 | } |
244 | 245 | ||
245 | if ( d->sendAppLnks && d->serverGui ) | 246 | if ( d->sendAppLnks && d->serverGui ) |
246 | d->serverGui->applicationScanningProgress( 100 ); | 247 | d->serverGui->applicationScanningProgress( 100 ); |
247 | } | 248 | } |
248 | 249 | ||
249 | void DocumentList::reloadDocLnks() | 250 | void DocumentList::reloadDocLnks() |
250 | { | 251 | { |
251 | if ( !d->scanDocs ) | 252 | if ( !d->scanDocs ) |
252 | return; | 253 | return; |
253 | 254 | ||
254 | if ( d->sendDocLnks && d->serverGui ) { | 255 | if ( d->sendDocLnks && d->serverGui ) { |
255 | d->serverGui->documentScanningProgress( 0 ); | 256 | d->serverGui->documentScanningProgress( 0 ); |
256 | d->serverGui->allDocumentsRemoved(); | 257 | d->serverGui->allDocumentsRemoved(); |
257 | } | 258 | } |
258 | 259 | ||
259 | rescan(); | 260 | rescan(); |
260 | } | 261 | } |
261 | 262 | ||
262 | void DocumentList::linkChanged( QString arg ) | 263 | void DocumentList::linkChanged( QString arg ) |
263 | { | 264 | { |
264 | //qDebug( "linkchanged( %s )", arg.latin1() ); | 265 | //qDebug( "linkchanged( %s )", arg.latin1() ); |
265 | 266 | ||
266 | if ( arg.isNull() || Global::isAppLnkFileName( arg ) ) { | 267 | if ( arg.isNull() || Opie::Global::isAppLnkFileName( arg ) ) { |
267 | reloadAppLnks(); | 268 | reloadAppLnks(); |
268 | } else { | 269 | } else { |
269 | 270 | ||
270 | const QList<DocLnk> &list = d->dls.children(); | 271 | const QList<DocLnk> &list = d->dls.children(); |
271 | QListIterator<DocLnk> it( list ); | 272 | QListIterator<DocLnk> it( list ); |
272 | while ( it.current() ) { | 273 | while ( it.current() ) { |
273 | DocLnk *doc = it.current(); | 274 | DocLnk *doc = it.current(); |
274 | ++it; | 275 | ++it; |
275 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) | 276 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) |
276 | || ( doc->fileKnown() && doc->file() == arg ) ) { | 277 | || ( doc->fileKnown() && doc->file() == arg ) ) { |
277 | //qDebug( "found old link" ); | 278 | //qDebug( "found old link" ); |
278 | DocLnk* dl = new DocLnk( arg ); | 279 | DocLnk* dl = new DocLnk( arg ); |
279 | // add new one if it exists and matches the mimetype | 280 | // add new one if it exists and matches the mimetype |
280 | if ( d->store( dl ) ) { | 281 | if ( d->store( dl ) ) { |
281 | // Existing link has been changed, send old link ref and a ref | 282 | // Existing link has been changed, send old link ref and a ref |
282 | // to the new link | 283 | // to the new link |
283 | //qDebug( "change case" ); | 284 | //qDebug( "change case" ); |
284 | if ( d->serverGui ) | 285 | if ( d->serverGui ) |
285 | d->serverGui->documentChanged( *doc, *dl ); | 286 | d->serverGui->documentChanged( *doc, *dl ); |
286 | 287 | ||
287 | } else { | 288 | } else { |
288 | // Link has been removed or doesn't match the mimetypes any more | 289 | // Link has been removed or doesn't match the mimetypes any more |
289 | // so we aren't interested in it, so take it away from the list | 290 | // so we aren't interested in it, so take it away from the list |
290 | //qDebug( "removal case" ); | 291 | //qDebug( "removal case" ); |
291 | if ( d->serverGui ) | 292 | if ( d->serverGui ) |
292 | d->serverGui->documentRemoved( *doc ); | 293 | d->serverGui->documentRemoved( *doc ); |
293 | 294 | ||
294 | } | 295 | } |
295 | d->dls.remove( doc ); // remove old link from docLnkSet | 296 | d->dls.remove( doc ); // remove old link from docLnkSet |
296 | delete doc; | 297 | delete doc; |
297 | return; | 298 | return; |
298 | } | 299 | } |
299 | } | 300 | } |
300 | // Didn't find existing link, must be new | 301 | // Didn't find existing link, must be new |
301 | DocLnk* dl = new DocLnk( arg ); | 302 | DocLnk* dl = new DocLnk( arg ); |
302 | if ( d->store( dl ) ) { | 303 | if ( d->store( dl ) ) { |
303 | // Add if it's a link we are interested in | 304 | // Add if it's a link we are interested in |
304 | //qDebug( "add case" ); | 305 | //qDebug( "add case" ); |
305 | add( *dl ); | 306 | add( *dl ); |
306 | } | 307 | } |
307 | 308 | ||
@@ -427,66 +428,66 @@ void DocumentListPrivate::initialize() | |||
427 | reference.clear(); | 428 | reference.clear(); |
428 | 429 | ||
429 | QDir docDir( QPEApplication::documentDir() ); | 430 | QDir docDir( QPEApplication::documentDir() ); |
430 | if ( docDir.exists() ) | 431 | if ( docDir.exists() ) |
431 | docPaths += QPEApplication::documentDir(); | 432 | docPaths += QPEApplication::documentDir(); |
432 | int i = 1; | 433 | int i = 1; |
433 | const QList<FileSystem> &fs = storage->fileSystems(); | 434 | const QList<FileSystem> &fs = storage->fileSystems(); |
434 | QListIterator<FileSystem> it( fs ); | 435 | QListIterator<FileSystem> it( fs ); |
435 | for ( ; it.current(); ++it ) | 436 | for ( ; it.current(); ++it ) |
436 | if ( (*it)->isRemovable() ) { | 437 | if ( (*it)->isRemovable() ) { |
437 | docPaths += (*it)->path(); | 438 | docPaths += (*it)->path(); |
438 | i++; | 439 | i++; |
439 | } | 440 | } |
440 | 441 | ||
441 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 442 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
442 | if ( listDirs[i] ) { | 443 | if ( listDirs[i] ) { |
443 | delete listDirs[i]; | 444 | delete listDirs[i]; |
444 | listDirs[i] = 0; | 445 | listDirs[i] = 0; |
445 | } | 446 | } |
446 | lists[i] = 0; | 447 | lists[i] = 0; |
447 | listPositions[i] = 0; | 448 | listPositions[i] = 0; |
448 | } | 449 | } |
449 | 450 | ||
450 | docPathsSearched = 0; | 451 | docPathsSearched = 0; |
451 | searchDepth = -1; | 452 | searchDepth = -1; |
452 | state = Find; | 453 | state = Find; |
453 | dit = 0; | 454 | dit = 0; |
454 | } | 455 | } |
455 | 456 | ||
456 | 457 | ||
457 | DocumentListPrivate::~DocumentListPrivate() | 458 | DocumentListPrivate::~DocumentListPrivate() |
458 | { | 459 | { |
459 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) | 460 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) |
460 | if ( listDirs[i] ) | 461 | if ( listDirs[i] ) |
461 | delete listDirs[i]; | 462 | delete listDirs[i]; |
462 | delete dit; | 463 | delete dit; |
463 | } | 464 | } |
464 | 465 | ||
465 | 466 | ||
466 | void DocumentListPrivate::estimatedPercentScanned() | 467 | void DocumentListPrivate::estimatedPercentScanned() |
467 | { | 468 | { |
468 | double overallProgress = 0.0; | 469 | double overallProgress = 0.0; |
469 | double levelWeight = 75.0; | 470 | double levelWeight = 75.0; |
470 | 471 | ||
471 | int topCount = docPaths.count(); | 472 | int topCount = docPaths.count(); |
472 | if ( topCount > 1 ) { | 473 | if ( topCount > 1 ) { |
473 | levelWeight = levelWeight / topCount; | 474 | levelWeight = levelWeight / topCount; |
474 | overallProgress += (docPathsSearched - 1) * levelWeight; | 475 | overallProgress += (docPathsSearched - 1) * levelWeight; |
475 | } | 476 | } |
476 | 477 | ||
477 | for ( int d = 0; d <= searchDepth; d++ ) { | 478 | for ( int d = 0; d <= searchDepth; d++ ) { |
478 | if ( listDirs[d] ) { | 479 | if ( listDirs[d] ) { |
479 | int items = lists[d]->count(); | 480 | int items = lists[d]->count(); |
480 | if ( items > 1 ) { | 481 | if ( items > 1 ) { |
481 | levelWeight = levelWeight / items; | 482 | levelWeight = levelWeight / items; |
482 | // Take in to account "." and ".." | 483 | // Take in to account "." and ".." |
483 | overallProgress += (listPositions[d] - 3) * levelWeight; | 484 | overallProgress += (listPositions[d] - 3) * levelWeight; |
484 | } | 485 | } |
485 | } else { | 486 | } else { |
486 | break; | 487 | break; |
487 | } | 488 | } |
488 | } | 489 | } |
489 | 490 | ||
490 | // qDebug( "overallProgress: %f", overallProgress ); | 491 | // qDebug( "overallProgress: %f", overallProgress ); |
491 | 492 | ||
492 | if ( serverGui ) | 493 | if ( serverGui ) |
@@ -593,54 +594,54 @@ const DocLnk *DocumentListPrivate::iterate() | |||
593 | if ( serverGui ) | 594 | if ( serverGui ) |
594 | serverGui->documentScanningProgress( 75 ); | 595 | serverGui->documentScanningProgress( 75 ); |
595 | } | 596 | } |
596 | 597 | ||
597 | static int iterationI; | 598 | static int iterationI; |
598 | static int iterationCount; | 599 | static int iterationCount; |
599 | 600 | ||
600 | if ( state == RemoveKnownFiles ) { | 601 | if ( state == RemoveKnownFiles ) { |
601 | //qDebug("state RemoveKnownFiles"); | 602 | //qDebug("state RemoveKnownFiles"); |
602 | const QList<DocLnk> &list = dls.children(); | 603 | const QList<DocLnk> &list = dls.children(); |
603 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 604 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
604 | reference.remove( (*it)->file() ); | 605 | reference.remove( (*it)->file() ); |
605 | // ### does this need to be deleted? | 606 | // ### does this need to be deleted? |
606 | } | 607 | } |
607 | dit = new QDictIterator<void>(reference); | 608 | dit = new QDictIterator<void>(reference); |
608 | state = MakeUnknownFiles; | 609 | state = MakeUnknownFiles; |
609 | 610 | ||
610 | iterationI = 0; | 611 | iterationI = 0; |
611 | iterationCount = dit->count(); | 612 | iterationCount = dit->count(); |
612 | } | 613 | } |
613 | 614 | ||
614 | if ( state == MakeUnknownFiles ) { | 615 | if ( state == MakeUnknownFiles ) { |
615 | //qDebug("state MakeUnknownFiles"); | 616 | //qDebug("state MakeUnknownFiles"); |
616 | for (void* c; (c=dit->current()); ++(*dit) ) { | 617 | for (void* c; (c=dit->current()); ++(*dit) ) { |
617 | if ( c == MAGIC_NUMBER ) { | 618 | if ( c == MAGIC_NUMBER ) { |
618 | DocLnk* dl = new DocLnk; | 619 | DocLnk* dl = new DocLnk; |
619 | QFileInfo fi( dit->currentKey() ); | 620 | QFileInfo fi( dit->currentKey() ); |
620 | dl->setFile( fi.filePath() ); | 621 | dl->setFile( fi.filePath() ); |
621 | dl->setName( fi.baseName() ); | 622 | dl->setName( fi.baseName() ); |
622 | if ( store(dl) ) { | 623 | if ( store(dl) ) { |
623 | ++*dit; | 624 | ++*dit; |
624 | iterationI++; | 625 | iterationI++; |
625 | if ( serverGui ) | 626 | if ( serverGui ) |
626 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 627 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
627 | return dl; | 628 | return dl; |
628 | } | 629 | } |
629 | } | 630 | } |
630 | iterationI++; | 631 | iterationI++; |
631 | } | 632 | } |
632 | 633 | ||
633 | delete dit; | 634 | delete dit; |
634 | dit = 0; | 635 | dit = 0; |
635 | state = Done; | 636 | state = Done; |
636 | } | 637 | } |
637 | 638 | ||
638 | //qDebug("state Done"); | 639 | //qDebug("state Done"); |
639 | return NULL; | 640 | return NULL; |
640 | } | 641 | } |
641 | 642 | ||
642 | 643 | ||
643 | #include "documentlist.moc" | 644 | #include "documentlist.moc" |
644 | 645 | ||
645 | 646 | ||
646 | 647 | ||