[KPhotoAlbum] Problems with the context menu in image view
Robert Krawitz
rlk at alum.mit.edu
Sat Sep 11 04:22:35 BST 2010
On Fri, 10 Sep 2010 19:47:42 -0400, Robert Krawitz wrote:
> A couple of problems I've found related in a general sense to the
> context menu in image view:
>
> 1) Invoke External Progam is *extremely* slow. The first time I use
> it on a fresh session, it takes several minutes (!) to pop up the
> list of programs. It appears the culprit is this, in
> MainWindow/ExternalPopup.cpp:
>
> // Fetch set of offers
> OfferType offers;
> if ( which == 0 )
> offers = appInfos( QStringList() << current->fileName(DB::AbsolutePath) );
> else
> offers = appInfos( imageList );
>
> appInfos(), in turn, calls mimeTypes(), which then does this:
>
> QString MainWindow::ExternalPopup::mimeType( const QString& file )
> {
> return KFileItem( KFileItem::Unknown, KFileItem::Unknown, KUrl(file) ).mimetype();
> }
This is much faster (basically instantaneous). It assumes that
everything with the same file extension has the same mime type.
With millions of images this might be a bit of a bottleneck...but
there are probably a lot of other issues up around there. We could
save a little by reusing the offers for All Selected Items with Copy
and Open, but I leave that as an exercise for the reader.
Index: ExternalPopup.cpp
===================================================================
--- ExternalPopup.cpp (revision 1173991)
+++ 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;
}
More information about the Kphotoalbum
mailing list