summaryrefslogtreecommitdiff
authorbrad <brad>2004-04-12 07:01:55 (UTC)
committer brad <brad>2004-04-12 07:01:55 (UTC)
commit2c087dc52d50eb9b13670254f70347d7b1147b20 (patch) (unidiff)
tree79814aa2618a6a512a0e669ba2b6829ca13b7bdd
parent66f497a5c7990d7e54cc1ae26995231ade55b86c (diff)
downloadopie-2c087dc52d50eb9b13670254f70347d7b1147b20.zip
opie-2c087dc52d50eb9b13670254f70347d7b1147b20.tar.gz
opie-2c087dc52d50eb9b13670254f70347d7b1147b20.tar.bz2
Changed launcher to only add/remove icons/tabs that have changed when removable
media is mounted/unmounted. A card insert on my machine used to take 7500ms. It now takes 548ms. Same with card removal. Old code has been left as is an can be re-enabled with a simple comment.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/documentlist.cpp92
-rw-r--r--core/launcher/documentlist.h1
2 files changed, 91 insertions, 2 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index 92b8c25..59dd721 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -284,102 +284,190 @@ void DocumentList::linkChanged( QString arg )
284 284
285 const QList<DocLnk> &list = d->dls.children(); 285 const QList<DocLnk> &list = d->dls.children();
286 QListIterator<DocLnk> it( list ); 286 QListIterator<DocLnk> it( list );
287 while ( it.current() ) { 287 while ( it.current() ) {
288 DocLnk *doc = it.current(); 288 DocLnk *doc = it.current();
289 ++it; 289 ++it;
290 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 290 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
291 || ( doc->fileKnown() && doc->file() == arg ) ) { 291 || ( doc->fileKnown() && doc->file() == arg ) ) {
292 //odebug << "found old link" << oendl; 292 //odebug << "found old link" << oendl;
293 DocLnk* dl = new DocLnk( arg ); 293 DocLnk* dl = new DocLnk( arg );
294 // add new one if it exists and matches the mimetype 294 // add new one if it exists and matches the mimetype
295 if ( d->store( dl ) ) { 295 if ( d->store( dl ) ) {
296 // Existing link has been changed, send old link ref and a ref 296 // Existing link has been changed, send old link ref and a ref
297 // to the new link 297 // to the new link
298 //odebug << "change case" << oendl; 298 //odebug << "change case" << oendl;
299 if ( d->serverGui ) 299 if ( d->serverGui )
300 d->serverGui->documentChanged( *doc, *dl ); 300 d->serverGui->documentChanged( *doc, *dl );
301 301
302 } else { 302 } else {
303 // Link has been removed or doesn't match the mimetypes any more 303 // Link has been removed or doesn't match the mimetypes any more
304 // so we aren't interested in it, so take it away from the list 304 // so we aren't interested in it, so take it away from the list
305 //odebug << "removal case" << oendl; 305 //odebug << "removal case" << oendl;
306 if ( d->serverGui ) 306 if ( d->serverGui )
307 d->serverGui->documentRemoved( *doc ); 307 d->serverGui->documentRemoved( *doc );
308 308
309 } 309 }
310 d->dls.remove( doc ); // remove old link from docLnkSet 310 d->dls.remove( doc ); // remove old link from docLnkSet
311 delete doc; 311 delete doc;
312 return; 312 return;
313 } 313 }
314 } 314 }
315 // Didn't find existing link, must be new 315 // Didn't find existing link, must be new
316 DocLnk* dl = new DocLnk( arg ); 316 DocLnk* dl = new DocLnk( arg );
317 if ( d->store( dl ) ) { 317 if ( d->store( dl ) ) {
318 // Add if it's a link we are interested in 318 // Add if it's a link we are interested in
319 //odebug << "add case" << oendl; 319 //odebug << "add case" << oendl;
320 add( *dl ); 320 add( *dl );
321 } 321 }
322 322
323 } 323 }
324} 324}
325 325
326void DocumentList::restoreDone() 326void DocumentList::restoreDone()
327{ 327{
328 reloadAppLnks(); 328 reloadAppLnks();
329 reloadDocLnks(); 329 reloadDocLnks();
330} 330}
331 331
332void DocumentList::DiffAppLnks()
333{
334 static AppLnkSet *appLnkSet2;
335
336 appLnkSet2 = new AppLnkSet( MimeType::appsFolderName() );
337
338 if ( d->sendAppLnks && d->serverGui ) {
339 static QStringList prevTypeList = appLnkSet->types();
340 QStringList types = appLnkSet2->types();
341 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
342 if ( !(*ittypes).isEmpty() ) {
343 if ( !prevTypeList.contains(*ittypes) ) {
344 QString name = appLnkSet2->typeName(*ittypes);
345 QPixmap pm = appLnkSet2->typePixmap(*ittypes);
346 QPixmap bgPm = appLnkSet2->typeBigPixmap(*ittypes);
347
348 if (pm.isNull()) {
349 QImage img( Resource::loadImage( "UnknownDocument" ) );
350 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
351 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
352 }
353
354 odebug << "adding type " << (*ittypes) << "" << oendl;
355
356 // ### our current launcher expects docs tab to be last
357 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
358 }
359 prevTypeList.remove(*ittypes);
360 }
361 }
362 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
363 odebug << "removing type " << (*ittypes) << "" << oendl;
364 d->serverGui->typeRemoved(*ittypes);
365 }
366 prevTypeList = types;
367 }
368
369
370 QListIterator<AppLnk> it1( appLnkSet->children() );
371 QListIterator<AppLnk> it2( appLnkSet2->children() );
372
373 AppLnk *i;
374 AppLnk *j;
375 bool found;
376
377 while ( (j=it2.current()) ) {
378 it1 = appLnkSet->children();
379 found = false;
380 while ( (i=it1.current()) ){
381 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
382 found = true;
383 ++it1;
384 }
385 if (!found) {
386 qDebug("Item %s needs to be added",j->name().ascii() );
387 d->serverGui->applicationAdded( j->type(), *j );
388 }
389 ++it2;
390 }
391
392 it1 = appLnkSet->children();
393 while ( (i=it1.current()) ) {
394 it2 = appLnkSet2->children();
395 found = false;
396 while ( (j=it2.current()) ){
397 if (strcmp(i->name().ascii(),j->name().ascii()) == 0)
398 found = true;
399 ++it2;
400 }
401 if (!found) {
402 qDebug("Item %s needs to be removed",i->name().ascii() );
403 d->serverGui->applicationRemoved( i->type(), *i );
404 }
405
406 ++it1;
407 }
408
409 delete appLnkSet;
410 appLnkSet = appLnkSet2;
411
412}
332void DocumentList::storageChanged() 413void DocumentList::storageChanged()
333{ 414{
415 QTime t;
334 // ### can implement better 416 // ### can implement better
335 reloadAppLnks(); 417
418 t.start();
419 DiffAppLnks();
420// reloadAppLnks();
421 qDebug("Reload App links took %i ms",t.elapsed() );
336 reloadDocLnks(); 422 reloadDocLnks();
337 // ### Optimization opportunity 423// odebug << "Reload links took " << t.elapsed() << " ms " << oendl;
424 qDebug("Reload All links took %i ms",t.elapsed() );
425// ### Optimization opportunity
338 // Could be a bit more intelligent and somehow work out which 426 // Could be a bit more intelligent and somehow work out which
339 // mtab entry has changed and then only scan that and add and remove 427 // mtab entry has changed and then only scan that and add and remove
340 // links appropriately. 428 // links appropriately.
341// rescan(); 429// rescan();
342} 430}
343 431
344void DocumentList::sendAllDocLinks() 432void DocumentList::sendAllDocLinks()
345{ 433{
346 if ( d->tid != 0 ) { 434 if ( d->tid != 0 ) {
347 // We are in the middle of scanning, set a flag so 435 // We are in the middle of scanning, set a flag so
348 // we do this when we finish our scanning 436 // we do this when we finish our scanning
349 d->needToSendAllDocLinks = true; 437 d->needToSendAllDocLinks = true;
350 return; 438 return;
351 } 439 }
352 440
353 QString contents; 441 QString contents;
354 Categories cats; 442 Categories cats;
355 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 443 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
356 DocLnk *doc = it.current(); 444 DocLnk *doc = it.current();
357 QFileInfo fi( doc->file() ); 445 QFileInfo fi( doc->file() );
358 if ( !fi.exists() ) 446 if ( !fi.exists() )
359 continue; 447 continue;
360 448
361 bool fake = !doc->linkFileKnown(); 449 bool fake = !doc->linkFileKnown();
362 if ( !fake ) { 450 if ( !fake ) {
363 QFile f( doc->linkFile() ); 451 QFile f( doc->linkFile() );
364 if ( f.open( IO_ReadOnly ) ) { 452 if ( f.open( IO_ReadOnly ) ) {
365 QTextStream ts( &f ); 453 QTextStream ts( &f );
366 ts.setEncoding( QTextStream::UnicodeUTF8 ); 454 ts.setEncoding( QTextStream::UnicodeUTF8 );
367 contents += ts.read(); 455 contents += ts.read();
368 f.close(); 456 f.close();
369 } else 457 } else
370 fake = TRUE; 458 fake = TRUE;
371 } 459 }
372 if (fake) { 460 if (fake) {
373 contents += "[Desktop Entry]\n"; // No tr 461 contents += "[Desktop Entry]\n"; // No tr
374 contents += "Categories = " + // No tr 462 contents += "Categories = " + // No tr
375 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 463 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
376 contents += "Name = "+doc->name()+"\n"; // No tr 464 contents += "Name = "+doc->name()+"\n"; // No tr
377 contents += "Type = "+doc->type()+"\n"; // No tr 465 contents += "Type = "+doc->type()+"\n"; // No tr
378 } 466 }
379 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 467 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
380 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 468 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
381 } 469 }
382 470
383 //odebug << "sending length " << contents.length() << "" << oendl; 471 //odebug << "sending length " << contents.length() << "" << oendl;
384#ifndef QT_NO_COP 472#ifndef QT_NO_COP
385 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 473 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
diff --git a/core/launcher/documentlist.h b/core/launcher/documentlist.h
index bd5c031..232bb6a 100644
--- a/core/launcher/documentlist.h
+++ b/core/launcher/documentlist.h
@@ -1,77 +1,78 @@
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#ifndef DOCUMENT_LIST_H 20#ifndef DOCUMENT_LIST_H
21#define DOCUMENT_LIST_H 21#define DOCUMENT_LIST_H
22 22
23 23
24#include <qobject.h> 24#include <qobject.h>
25#include <qtopia/applnk.h> 25#include <qtopia/applnk.h>
26 26
27 27
28class DocumentListPrivate; 28class DocumentListPrivate;
29class ServerInterface; 29class ServerInterface;
30 30
31class DocumentList : public QObject { 31class DocumentList : public QObject {
32 Q_OBJECT 32 Q_OBJECT
33public: 33public:
34 DocumentList( ServerInterface *serverGui, bool scanDocs = TRUE, 34 DocumentList( ServerInterface *serverGui, bool scanDocs = TRUE,
35 QObject *parent = 0, const char *name = 0 ); 35 QObject *parent = 0, const char *name = 0 );
36 ~DocumentList(); 36 ~DocumentList();
37 37
38 void linkChanged( QString link ); 38 void linkChanged( QString link );
39 void restoreDone(); 39 void restoreDone();
40 void storageChanged(); 40 void storageChanged();
41 void sendAllDocLinks(); 41 void sendAllDocLinks();
42 42
43 void reloadAppLnks(); 43 void reloadAppLnks();
44 void reloadDocLnks(); 44 void reloadDocLnks();
45 void DiffAppLnks();
45 46
46// Orig DocList stuff 47// Orig DocList stuff
47 void start(); 48 void start();
48 void pause(); 49 void pause();
49 void resume(); 50 void resume();
50 void rescan(); 51 void rescan();
51 52
52 static AppLnkSet *appLnkSet; 53 static AppLnkSet *appLnkSet;
53 54
54/* 55/*
55 void resend(); 56 void resend();
56signals: 57signals:
57 void added( const DocLnk& doc ); 58 void added( const DocLnk& doc );
58 void removed( const DocLnk& doc ); 59 void removed( const DocLnk& doc );
59 void changed( const DocLnk& oldDoc, const DocLnk& newDoc ); 60 void changed( const DocLnk& oldDoc, const DocLnk& newDoc );
60 void allRemoved(); 61 void allRemoved();
61 void doneForNow(); 62 void doneForNow();
62private slots: 63private slots:
63 void resendWorker(); 64 void resendWorker();
64*/ 65*/
65private slots: 66private slots:
66 void startInitialScan(); 67 void startInitialScan();
67protected: 68protected:
68 void timerEvent( QTimerEvent *te ); 69 void timerEvent( QTimerEvent *te );
69private: 70private:
70 void add( const DocLnk& doc ); 71 void add( const DocLnk& doc );
71 DocumentListPrivate *d; 72 DocumentListPrivate *d;
72 73
73}; 74};
74 75
75 76
76#endif 77#endif
77 78