qtmobility/src/contacts/qcontactmanager_p.cpp
changeset 8 71781823f776
parent 5 453da2cfceef
child 11 06b8e2af4411
--- a/qtmobility/src/contacts/qcontactmanager_p.cpp	Fri May 14 16:41:33 2010 +0300
+++ b/qtmobility/src/contacts/qcontactmanager_p.cpp	Thu May 27 13:42:11 2010 +0300
@@ -39,7 +39,6 @@
 **
 ****************************************************************************/
 
-#include <src/global/qbuildcfg.h>
 #include "qcontactmanager.h"
 #include "qcontactmanager_p.h"
 #include "qcontactmanagerengine.h"
@@ -63,6 +62,7 @@
 
 #include "qcontactmemorybackend_p.h"
 #include "qcontactinvalidbackend_p.h"
+#include "qmobilitypluginsearch.h"
 
 QTM_BEGIN_NAMESPACE
 
@@ -191,63 +191,6 @@
     }
 }
 
-class DirChecker
-{
-public:
-    DirChecker();
-    ~DirChecker();
-    bool checkDir(const QDir& dir);
-
-private:
-#if defined(Q_OS_SYMBIAN)
-    RFs rfs;
-#endif
-};
-
-#if defined(Q_OS_SYMBIAN)
-DirChecker::DirChecker()
-{
-    qt_symbian_throwIfError(rfs.Connect());
-}
-
-bool DirChecker::checkDir(const QDir& dir)
-{
-    bool pathFound = false;
-    // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
-    // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
-    // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
-    // Use native Symbian code to check for directory existence, because checking
-    // for files from under non-existent protected dir like E:/private/<uid> using
-    // QDir::exists causes platform security violations on most apps.
-    QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
-    TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
-    TUint attributes;
-    TInt err = rfs.Att(ptr, attributes);
-    if (err == KErrNone) {
-        // yes, the directory exists.
-        pathFound = true;
-    }
-    return pathFound;
-}
-
-DirChecker::~DirChecker()
-{
-    rfs.Close();
-}
-#else
-DirChecker::DirChecker()
-{
-}
-
-DirChecker::~DirChecker()
-{
-}
-
-bool DirChecker::checkDir(const QDir &dir)
-{
-    return dir.exists();
-}
-#endif
 
 /* Plugin loader */
 void QContactManagerData::loadFactories()
@@ -259,69 +202,16 @@
     // Always do this..
     loadStaticFactories();
 
-    if (!m_discovered || QApplication::libraryPaths() != m_pluginPaths) {
-        m_discovered = true;
-        m_pluginPaths = QApplication::libraryPaths();
-
-        /* Discover a bunch o plugins */
-        QStringList plugins;
-
-        QStringList paths;
-        QSet<QString> processed;
-
-        paths << QApplication::applicationDirPath() << QApplication::libraryPaths();
-        QString val = qt_mobility_configure_prefix_path_str;
-        if(val.length() > 0){
-            paths << val;
-        }
-#if !defined QT_NO_DEBUG
-        if (showDebug)
-            qDebug() << "Plugin paths:" << paths;
-#endif
-
-        DirChecker dirChecker;
+    QStringList plugins;
+    plugins = mobilityPlugins(QLatin1String("contacts"));
 
-        /* Enumerate our plugin paths */
-        for (int i=0; i < paths.count(); i++) {
-            if (processed.contains(paths.at(i)))
-                continue;
-            processed.insert(paths.at(i));
-            QDir pluginsDir(paths.at(i));
-            if (!dirChecker.checkDir(pluginsDir))
-                continue;
-
-#if defined(Q_OS_WIN)
-            if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
-                pluginsDir.cdUp();
-#elif defined(Q_OS_MAC)
-            if (pluginsDir.dirName() == QLatin1String("MacOS")) {
-                pluginsDir.cdUp();
-                pluginsDir.cdUp();
-                pluginsDir.cdUp();
-            }
-#endif
-
-            QString subdir(QLatin1String("plugins/contacts"));
-            if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
-                || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
-                subdir = QLatin1String("contacts");
-
-            if (dirChecker.checkDir(QDir(pluginsDir.path() + QLatin1Char('/') + subdir))) {
-                pluginsDir.cd(subdir);
-                const QStringList& files = pluginsDir.entryList(QDir::Files);
-#if !defined QT_NO_DEBUG
-                if (showDebug)
-                    qDebug() << "Looking for contacts plugins in" << pluginsDir.path() << files;
-#endif
-                for (int j=0; j < files.count(); j++) {
-                    plugins <<  pluginsDir.absoluteFilePath(files.at(j));
-                }
-            }
-        }
+    if (!m_discovered || plugins != m_pluginPaths) {
+        m_discovered = true;
+        m_pluginPaths = plugins;
 
         /* Now discover the dynamic plugins */
-        for (int i=0; i < plugins.count(); i++) {
-            QPluginLoader qpl(plugins.at(i));
+        for (int i=0; i < m_pluginPaths.count(); i++) {
+            QPluginLoader qpl(m_pluginPaths.at(i));
             QContactManagerEngineFactory *f = qobject_cast<QContactManagerEngineFactory*>(qpl.instance());
             if (f) {
                 QString name = f->managerName();
@@ -332,12 +222,12 @@
                 if (name != QLatin1String("memory") && name != QLatin1String("invalid") && !name.isEmpty()) {
                     // we also need to ensure that we haven't already loaded this factory.
                     if (m_engines.keys().contains(name)) {
-                        qWarning() << "Contacts plugin" << plugins.at(i) << "has the same name as currently loaded plugin" << name << "; ignored";
+                        qWarning() << "Contacts plugin" << m_pluginPaths.at(i) << "has the same name as currently loaded plugin" << name << "; ignored";
                     } else {
                         m_engines.insertMulti(name, f);
                     }
                 } else {
-                    qWarning() << "Contacts plugin" << plugins.at(i) << "with reserved name" << name << "ignored";
+                    qWarning() << "Contacts plugin" << m_pluginPaths.at(i) << "with reserved name" << name << "ignored";
                 }
             }