qtmobility/src/global/qmobilitypluginsearch.h
branchRCL_3
changeset 9 5d007b20cfd0
parent 8 885c2596c964
child 10 cd2778e5acfe
equal deleted inserted replaced
8:885c2596c964 9:5d007b20cfd0
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include <QApplication>
       
    42 #include <QStringList>
       
    43 
       
    44 #if defined(Q_OS_SYMBIAN)
       
    45 # include <f32file.h>
       
    46 #endif
       
    47 
       
    48 QTM_BEGIN_NAMESPACE
       
    49 
       
    50 class DirChecker
       
    51 {
       
    52 public:
       
    53     DirChecker();
       
    54     ~DirChecker();
       
    55     bool checkDir(const QDir& dir);
       
    56 
       
    57 private:
       
    58 #if defined(Q_OS_SYMBIAN)
       
    59     RFs rfs;
       
    60 #endif
       
    61 };
       
    62 
       
    63 #if defined(Q_OS_SYMBIAN)
       
    64 DirChecker::DirChecker()
       
    65 {
       
    66     qt_symbian_throwIfError(rfs.Connect());
       
    67 }
       
    68 
       
    69 bool DirChecker::checkDir(const QDir& dir)
       
    70 {
       
    71     bool pathFound = false;
       
    72     // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
       
    73     // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
       
    74     // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
       
    75     // Use native Symbian code to check for directory existence, because checking
       
    76     // for files from under non-existent protected dir like E:/private/<uid> using
       
    77     // QDir::exists causes platform security violations on most apps.
       
    78     QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
       
    79     TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
       
    80     TUint attributes;
       
    81     TInt err = rfs.Att(ptr, attributes);
       
    82     if (err == KErrNone) {
       
    83         // yes, the directory exists.
       
    84         pathFound = true;
       
    85     }
       
    86     return pathFound;
       
    87 }
       
    88 
       
    89 DirChecker::~DirChecker()
       
    90 {
       
    91     rfs.Close();
       
    92 }
       
    93 #else
       
    94 DirChecker::DirChecker()
       
    95 {
       
    96 }
       
    97 
       
    98 DirChecker::~DirChecker()
       
    99 {
       
   100 }
       
   101 
       
   102 bool DirChecker::checkDir(const QDir &dir)
       
   103 {
       
   104     return dir.exists();
       
   105 }
       
   106 #endif
       
   107 
       
   108 inline QStringList mobilityPlugins(const QString plugintype)
       
   109 {
       
   110 #if !defined QT_NO_DEBUG
       
   111     const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
       
   112 #endif
       
   113 
       
   114     QStringList paths = QApplication::libraryPaths();
       
   115 #ifdef QTM_PLUGIN_PATH
       
   116     paths << QLatin1String(QTM_PLUGIN_PATH);
       
   117 #endif
       
   118 #if !defined QT_NO_DEBUG
       
   119     if (showDebug)
       
   120         qDebug() << "Plugin paths:" << paths;
       
   121 #endif
       
   122 
       
   123     DirChecker dirChecker;
       
   124 
       
   125     //temp variable to avoid multiple identic path
       
   126     QSet<QString> processed;
       
   127 
       
   128     /* Discover a bunch o plugins */
       
   129     QStringList plugins;
       
   130 
       
   131     /* Enumerate our plugin paths */
       
   132     for (int i=0; i < paths.count(); i++) {
       
   133         if (processed.contains(paths.at(i)))
       
   134             continue;
       
   135         processed.insert(paths.at(i));
       
   136         QDir pluginsDir(paths.at(i));
       
   137         if (!dirChecker.checkDir(pluginsDir))
       
   138             continue;
       
   139 
       
   140 #if defined(Q_OS_WIN)
       
   141         if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
       
   142             pluginsDir.cdUp();
       
   143 #elif defined(Q_OS_MAC)
       
   144         if (pluginsDir.dirName() == QLatin1String("MacOS")) {
       
   145             pluginsDir.cdUp();
       
   146             pluginsDir.cdUp();
       
   147             pluginsDir.cdUp();
       
   148         }
       
   149 #endif
       
   150 
       
   151         QString subdir(QLatin1String("plugins/"));
       
   152         subdir += plugintype;
       
   153         if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
       
   154             || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
       
   155             subdir = plugintype;
       
   156 
       
   157         if (dirChecker.checkDir(QDir(pluginsDir.path() + QLatin1Char('/') + subdir))) {
       
   158             pluginsDir.cd(subdir);
       
   159             QStringList files = pluginsDir.entryList(QDir::Files);
       
   160 
       
   161 #if !defined QT_NO_DEBUG
       
   162             if (showDebug)
       
   163                 qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files;
       
   164 #endif
       
   165 
       
   166             for (int j=0; j < files.count(); j++) {
       
   167                 plugins <<  pluginsDir.absoluteFilePath(files.at(j));
       
   168             }
       
   169         }
       
   170     }
       
   171     return  plugins;
       
   172 }
       
   173 
       
   174 QTM_END_NAMESPACE