author | brad <brad> | 2004-04-12 07:01:55 (UTC) |
---|---|---|
committer | brad <brad> | 2004-04-12 07:01:55 (UTC) |
commit | 2c087dc52d50eb9b13670254f70347d7b1147b20 (patch) (side-by-side diff) | |
tree | 79814aa2618a6a512a0e669ba2b6829ca13b7bdd | |
parent | 66f497a5c7990d7e54cc1ae26995231ade55b86c (diff) | |
download | opie-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.
-rw-r--r-- | core/launcher/documentlist.cpp | 90 | ||||
-rw-r--r-- | core/launcher/documentlist.h | 1 |
2 files changed, 90 insertions, 1 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 @@ -268,133 +268,221 @@ void DocumentList::reloadDocLnks() if ( d->sendDocLnks && d->serverGui ) { d->serverGui->documentScanningProgress( 0 ); d->serverGui->allDocumentsRemoved(); } rescan(); } void DocumentList::linkChanged( QString arg ) { //odebug << "linkchanged( " << arg << " )" << oendl; if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { reloadAppLnks(); } else { const QList<DocLnk> &list = d->dls.children(); QListIterator<DocLnk> it( list ); while ( it.current() ) { DocLnk *doc = it.current(); ++it; if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) || ( doc->fileKnown() && doc->file() == arg ) ) { //odebug << "found old link" << oendl; DocLnk* dl = new DocLnk( arg ); // add new one if it exists and matches the mimetype if ( d->store( dl ) ) { // Existing link has been changed, send old link ref and a ref // to the new link //odebug << "change case" << oendl; if ( d->serverGui ) d->serverGui->documentChanged( *doc, *dl ); } else { // Link has been removed or doesn't match the mimetypes any more // so we aren't interested in it, so take it away from the list //odebug << "removal case" << oendl; if ( d->serverGui ) d->serverGui->documentRemoved( *doc ); } d->dls.remove( doc ); // remove old link from docLnkSet delete doc; return; } } // Didn't find existing link, must be new DocLnk* dl = new DocLnk( arg ); if ( d->store( dl ) ) { // Add if it's a link we are interested in //odebug << "add case" << oendl; add( *dl ); } } } void DocumentList::restoreDone() { reloadAppLnks(); reloadDocLnks(); } +void DocumentList::DiffAppLnks() +{ + static AppLnkSet *appLnkSet2; + + appLnkSet2 = new AppLnkSet( MimeType::appsFolderName() ); + + if ( d->sendAppLnks && d->serverGui ) { + static QStringList prevTypeList = appLnkSet->types(); + QStringList types = appLnkSet2->types(); + for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { + if ( !(*ittypes).isEmpty() ) { + if ( !prevTypeList.contains(*ittypes) ) { + QString name = appLnkSet2->typeName(*ittypes); + QPixmap pm = appLnkSet2->typePixmap(*ittypes); + QPixmap bgPm = appLnkSet2->typeBigPixmap(*ittypes); + + if (pm.isNull()) { + QImage img( Resource::loadImage( "UnknownDocument" ) ); + pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); + bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); + } + + odebug << "adding type " << (*ittypes) << "" << oendl; + + // ### our current launcher expects docs tab to be last + d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); + } + prevTypeList.remove(*ittypes); + } + } + for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { + odebug << "removing type " << (*ittypes) << "" << oendl; + d->serverGui->typeRemoved(*ittypes); + } + prevTypeList = types; + } + + + QListIterator<AppLnk> it1( appLnkSet->children() ); + QListIterator<AppLnk> it2( appLnkSet2->children() ); + + AppLnk *i; + AppLnk *j; + bool found; + + while ( (j=it2.current()) ) { + it1 = appLnkSet->children(); + found = false; + while ( (i=it1.current()) ){ + if (strcmp(i->name().ascii(),j->name().ascii()) == 0) + found = true; + ++it1; + } + if (!found) { + qDebug("Item %s needs to be added",j->name().ascii() ); + d->serverGui->applicationAdded( j->type(), *j ); + } + ++it2; + } + + it1 = appLnkSet->children(); + while ( (i=it1.current()) ) { + it2 = appLnkSet2->children(); + found = false; + while ( (j=it2.current()) ){ + if (strcmp(i->name().ascii(),j->name().ascii()) == 0) + found = true; + ++it2; + } + if (!found) { + qDebug("Item %s needs to be removed",i->name().ascii() ); + d->serverGui->applicationRemoved( i->type(), *i ); + } + + ++it1; + } + + delete appLnkSet; + appLnkSet = appLnkSet2; + +} void DocumentList::storageChanged() { + QTime t; // ### can implement better - reloadAppLnks(); + + t.start(); + DiffAppLnks(); +// reloadAppLnks(); + qDebug("Reload App links took %i ms",t.elapsed() ); reloadDocLnks(); +// odebug << "Reload links took " << t.elapsed() << " ms " << oendl; + qDebug("Reload All links took %i ms",t.elapsed() ); // ### Optimization opportunity // Could be a bit more intelligent and somehow work out which // mtab entry has changed and then only scan that and add and remove // links appropriately. // rescan(); } void DocumentList::sendAllDocLinks() { if ( d->tid != 0 ) { // We are in the middle of scanning, set a flag so // we do this when we finish our scanning d->needToSendAllDocLinks = true; return; } QString contents; Categories cats; for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { DocLnk *doc = it.current(); QFileInfo fi( doc->file() ); if ( !fi.exists() ) continue; bool fake = !doc->linkFileKnown(); if ( !fake ) { QFile f( doc->linkFile() ); if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); ts.setEncoding( QTextStream::UnicodeUTF8 ); contents += ts.read(); f.close(); } else fake = TRUE; } if (fake) { contents += "[Desktop Entry]\n"; // No tr contents += "Categories = " + // No tr cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr contents += "Name = "+doc->name()+"\n"; // No tr contents += "Type = "+doc->type()+"\n"; // No tr } contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) contents += QString("Size = %1\n").arg( fi.size() ); // No tr } //odebug << "sending length " << contents.length() << "" << oendl; #ifndef QT_NO_COP QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); e << contents; #endif //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; d->needToSendAllDocLinks = false; } 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 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef DOCUMENT_LIST_H #define DOCUMENT_LIST_H #include <qobject.h> #include <qtopia/applnk.h> class DocumentListPrivate; class ServerInterface; class DocumentList : public QObject { Q_OBJECT public: DocumentList( ServerInterface *serverGui, bool scanDocs = TRUE, QObject *parent = 0, const char *name = 0 ); ~DocumentList(); void linkChanged( QString link ); void restoreDone(); void storageChanged(); void sendAllDocLinks(); void reloadAppLnks(); void reloadDocLnks(); + void DiffAppLnks(); // Orig DocList stuff void start(); void pause(); void resume(); void rescan(); static AppLnkSet *appLnkSet; /* void resend(); signals: void added( const DocLnk& doc ); void removed( const DocLnk& doc ); void changed( const DocLnk& oldDoc, const DocLnk& newDoc ); void allRemoved(); void doneForNow(); private slots: void resendWorker(); */ private slots: void startInitialScan(); protected: void timerEvent( QTimerEvent *te ); private: void add( const DocLnk& doc ); DocumentListPrivate *d; }; #endif |