[KPhotoAlbum] Make "Run Program" much faster

Robert Krawitz rlk at alum.mit.edu
Fri Oct 15 00:00:12 BST 2010


I don't remember if I actually sent this in.  If you right click on an
image in the viewer and accidentally hover over Run Program (on the
selection), it is extremely slow.  I tracked that down to the Run
Program code looking at all the files to determine the set of MIME
types in order to select appropriate programs to populate the menu
with.

If we make the assumption that MIME type is determined solely by the
extension (which is probably reasonable for this purpose), we can
speed matters up tremendously.

Index: MainWindow/ExternalPopup.cpp
===================================================================
--- MainWindow/ExternalPopup.cpp        (revision 1185973)
+++ MainWindow/ExternalPopup.cpp        (working copy)
@@ -166,14 +166,21 @@
 
 QString MainWindow::ExternalPopup::mimeType( const QString& file )
 {
-    return KFileItem( KFileItem::Unknown, KFileItem::Unknown, KUrl(file) ).mimetype();
+    return KMimeType::findByPath(file, 0, true)->name();
 }
 
 Utilities::StringSet MainWindow::ExternalPopup::mimeTypes( const QStringList& files )
 {
     StringSet res;
+    StringSet extensions;
     for( QStringList::ConstIterator fileIt = files.begin(); fileIt != files.end(); ++fileIt ) {
-        res.insert( mimeType( *fileIt ) );
+       QString baseFileName = *fileIt;
+       int extStart = baseFileName.lastIndexOf(QChar::fromLatin1('.'));
+       baseFileName.remove(0, extStart);
+       if (! extensions.contains(baseFileName)) {
+           res.insert( mimeType( *fileIt ) );
+           extensions.insert( baseFileName );
+       }
     }
     return res;
 }

-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

Tall Clubs International  --  http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom  --  http://ProgFree.org
Project lead for Gutenprint   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the Kphotoalbum mailing list