Don't ignore debug plugins on Mac when release plugins aren't available
authorRohan McGovern <rohan.mcgovern@nokia.com>
Tue, 25 Oct 2011 01:05:20 +0000 (11:05 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 25 Oct 2011 04:15:12 +0000 (06:15 +0200)
Previously, we unconditionally ignored any plugins whose names ended
with _debug.dylib.  This makes the mediaservice plugins unusable on Mac
if Qt is configured to build plugins as debug-only (which is
incidentally the default).

Change-Id: I5a8981b2251e803fa233b74c968f6eaa452d367c
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
src/multimedia/qmediapluginloader.cpp

index 32f3369..284ff59 100644 (file)
@@ -121,15 +121,36 @@ QStringList QMediaPluginLoader::availablePlugins() const
 
     foreach (const QString &path, paths) {
         QDir typeDir(path + m_location);
-        foreach (const QString &file, typeDir.entryList(QDir::Files)) {
+        foreach (const QString &file, typeDir.entryList(QDir::Files, QDir::Name)) {
 #if defined(Q_OS_MAC)
             if (!imageSuffix.isEmpty()) {   // Only add appropriate images
                 if (file.lastIndexOf(imageSuffix, -6) == -1)
                     continue;
-            } else {  // Ignore any images with common suffixes
-                if (file.endsWith(QLatin1String("_debug.dylib")) ||
-                    file.endsWith(QLatin1String("_profile.dylib")))
-                    continue;
+            } else {
+                int foundSuffix = file.lastIndexOf(QLatin1String("_debug.dylib"));
+                if (foundSuffix == -1) {
+                    foundSuffix = file.lastIndexOf(QLatin1String("_profile.dylib"));
+                }
+                if (foundSuffix != -1) {
+                    /*
+                        If this is a "special" version of the plugin, prefer the release
+                        version, where available.
+                        Avoids warnings like:
+
+                            objc[23101]: Class TransparentQTMovieView is implemented in both
+                            libqqt7engine_debug.dylib and libqqt7engine.dylib. One of the two
+                            will be used. Which one is undefined.
+
+                        Note, this code relies on QDir::Name sorting!
+                    */
+
+                    QString preferred =
+                        typeDir.absoluteFilePath(file.left(foundSuffix) + QLatin1String(".dylib"));
+
+                    if (plugins.contains(preferred)) {
+                        continue;
+                    }
+                }
             }
 #elif defined(Q_OS_UNIX)
             // Ignore separate debug files