Bug 219792 - [patch] Mimetype hierarchy not respected in EngineController::canDecode()
Summary: [patch] Mimetype hierarchy not respected in EngineController::canDecode()
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: Playback (show other bugs)
Version: 2.3-GIT
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-23 08:50 UTC by Rafał Rzepecki
Modified: 2009-12-23 09:18 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch solving the problem (1.57 KB, patch)
2009-12-23 08:51 UTC, Rafał Rzepecki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rafał Rzepecki 2009-12-23 08:50:02 UTC
Version:           2.2-GIT (using 4.3.85 (KDE 4.3.85 (KDE 4.4 Beta2)), compiled sources)
Compiler:          gcc
OS:                Linux (i686) release 2.6.30-gentoo-r8

EngineController::canDecode() decides whether it can decode a file by simple matching a QString mimetype of a file to a QStringList of mimetypes returned by the engine. This ignores the fact that mimetypes are in hierarchy and in fact there might not be a string match even if the type is listed.

In particular, on my system it leads to Amarok being unable to recognize ogg vorbis files in filesystem browser as playable. KFileInfo returns audio/x-vorbis type for them, but the closest thing on the engine's list is audio/x-vorbis+ogg.

Using KMimeType::is() function instead of string matching solves the problem. Patch follows.
Comment 1 Rafał Rzepecki 2009-12-23 08:51:27 UTC
Created attachment 39279 [details]
Patch solving the problem
Comment 2 Mark Kretschmann 2009-12-23 09:16:59 UTC
commit bdb9b1af986d58bb104da07f14b730fdd820e40f
Author: Mark Kretschmann <kretschmann@kde.org>
Date:   Wed Dec 23 09:14:27 2009 +0100

    More reliable MimeType detection for music formats.
    
    Patch by RafaÅ Rzepecki <divided.mind@gmail.com>.
    
    BUG: 219792

diff --git a/ChangeLog b/ChangeLog
index 8b6e6c5..43c6236 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -77,6 +77,8 @@ VERSION 2.2.2
       PowerTOP when using the Xine backend.
 
   BUGFIXES:
+    * More reliable MimeType detection for music formats. Patch by RafaÅ
+      Rzepecki <divided.mind@gmail.com>. (BR 219792)
     * Fixed regression causing many scripted services, including the, shipped by
       default, LibriVox service to not work at all.
     * Fixed corner case that could prevent scans from being completed,
diff --git a/src/EngineController.cpp b/src/EngineController.cpp
index 55f607f..b055994 100644
--- a/src/EngineController.cpp
+++ b/src/EngineController.cpp
@@ -219,11 +219,20 @@ EngineController::canDecode( const KUrl &url ) //static
     mimeTable << "audio/x-m4b"; // MP4 Audio Books have a different extension that KFileItem/Phonon don't grok
     //mimeTable << "?/?"; //Add comment
 
-    const QString mimeType = item.mimetype();
-    const bool valid = mimeTable.contains( mimeType, Qt::CaseInsensitive );
+    const KMimeType::Ptr mimeType = item.mimeTypePtr();
+    
+    bool valid = false;
+    foreach( const QString &type, mimeTable )
+    {
+        if( mimeType->is( type ) )
+        {
+            valid = true;
+            break;
+        }
+    }
 
-    //we special case this as otherwise users hate us
-    if ( !valid && ( mimeType == "audio/mp3" || mimeType == "audio/x-mp3" ) && !installDistroCodec() )
+    // We special case this, as otherwise the users would hate us
+    if ( !valid && ( mimeType->is( "audio/mp3" ) || mimeType->is( "audio/x-mp3" ) ) && !installDistroCodec() )
         The::statusBar()->longMessage(
                 i18n( "<p>Phonon claims it <b>cannot</b> play MP3 files. You may want to examine "
                       "the installation of the backend that phonon uses.</p>"
Comment 3 Mark Kretschmann 2009-12-23 09:18:16 UTC
commit bdb9b1af986d58bb104da07f14b730fdd820e40f
Author: Mark Kretschmann <kretschmann@kde.org>
Date:   Wed Dec 23 09:14:27 2009 +0100

    More reliable MimeType detection for music formats.
    
    Patch by RafaÅ Rzepecki <divided.mind@gmail.com>.
    
    BUG: 219792

diff --git a/ChangeLog b/ChangeLog
index 8b6e6c5..43c6236 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -77,6 +77,8 @@ VERSION 2.2.2
       PowerTOP when using the Xine backend.
 
   BUGFIXES:
+    * More reliable MimeType detection for music formats. Patch by RafaÅ
+      Rzepecki <divided.mind@gmail.com>. (BR 219792)
     * Fixed regression causing many scripted services, including the, shipped by
       default, LibriVox service to not work at all.
     * Fixed corner case that could prevent scans from being completed,
diff --git a/src/EngineController.cpp b/src/EngineController.cpp
index 55f607f..b055994 100644
--- a/src/EngineController.cpp
+++ b/src/EngineController.cpp
@@ -219,11 +219,20 @@ EngineController::canDecode( const KUrl &url ) //static
     mimeTable << "audio/x-m4b"; // MP4 Audio Books have a different extension that KFileItem/Phonon don't grok
     //mimeTable << "?/?"; //Add comment
 
-    const QString mimeType = item.mimetype();
-    const bool valid = mimeTable.contains( mimeType, Qt::CaseInsensitive );
+    const KMimeType::Ptr mimeType = item.mimeTypePtr();
+    
+    bool valid = false;
+    foreach( const QString &type, mimeTable )
+    {
+        if( mimeType->is( type ) )
+        {
+            valid = true;
+            break;
+        }
+    }
 
-    //we special case this as otherwise users hate us
-    if ( !valid && ( mimeType == "audio/mp3" || mimeType == "audio/x-mp3" ) && !installDistroCodec() )
+    // We special case this, as otherwise the users would hate us
+    if ( !valid && ( mimeType->is( "audio/mp3" ) || mimeType->is( "audio/x-mp3" ) ) && !installDistroCodec() )
         The::statusBar()->longMessage(
                 i18n( "<p>Phonon claims it <b>cannot</b> play MP3 files. You may want to examine "
                       "the installation of the backend that phonon uses.</p>"