src/global/qmobilitypluginsearch.h
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
    36 **
    36 **
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
       
    41 #ifndef QMOBILITYPLUGINSEARCH_H
       
    42 #define QMOBILITYPLUGINSEARCH_H
       
    43 
    41 #include <QApplication>
    44 #include <QApplication>
    42 #include <QStringList>
    45 #include <QStringList>
       
    46 #include <QDir>
    43 
    47 
    44 #if defined(Q_OS_SYMBIAN)
    48 #if defined(Q_OS_SYMBIAN)
    45 # include <f32file.h>
    49 # include <f32file.h>
    46 #endif
    50 #endif
    47 
    51 
    48 QTM_BEGIN_NAMESPACE
    52 QTM_BEGIN_NAMESPACE
    49 
    53 
    50 class DirChecker
    54 //class DirChecker
    51 {
    55 //{
    52 public:
    56 //public:
    53     DirChecker();
    57 //    DirChecker();
    54     ~DirChecker();
    58 //    ~DirChecker();
    55     bool checkDir(const QDir& dir);
    59 //    bool checkDir(const QDir& dir);
    56 
    60 
    57 private:
    61 //private:
       
    62 //#if defined(Q_OS_SYMBIAN)
       
    63 //    RFs rfs;
       
    64 //#endif
       
    65 //};
       
    66 
       
    67 //#if defined(Q_OS_SYMBIAN)
       
    68 //DirChecker::DirChecker()
       
    69 //{
       
    70 //    qt_symbian_throwIfError(rfs.Connect());
       
    71 //}
       
    72 
       
    73 //bool DirChecker::checkDir(const QDir& dir)
       
    74 //{
       
    75 //    bool pathFound = false;
       
    76 //    // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
       
    77 //    // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
       
    78 //    // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
       
    79 //    // Use native Symbian code to check for directory existence, because checking
       
    80 //    // for files from under non-existent protected dir like E:/private/<uid> using
       
    81 //    // QDir::exists causes platform security violations on most apps.
       
    82 //    QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
       
    83 //    TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
       
    84 //    TUint attributes;
       
    85 //    TInt err = rfs.Att(ptr, attributes);
       
    86 //    if (err == KErrNone) {
       
    87 //        // yes, the directory exists.
       
    88 //        pathFound = true;
       
    89 //    }
       
    90 //    return pathFound;
       
    91 //}
       
    92 
       
    93 //DirChecker::~DirChecker()
       
    94 //{
       
    95 //    rfs.Close();
       
    96 //}
       
    97 //#else
       
    98 //DirChecker::DirChecker()
       
    99 //{
       
   100 //}
       
   101 
       
   102 //DirChecker::~DirChecker()
       
   103 //{
       
   104 //}
       
   105 
       
   106 //bool DirChecker::checkDir(const QDir &dir)
       
   107 //{
       
   108 //    return dir.exists();
       
   109 //}
       
   110 //#endif
       
   111 
    58 #if defined(Q_OS_SYMBIAN)
   112 #if defined(Q_OS_SYMBIAN)
    59     RFs rfs;
   113     inline bool checkMobilityPluginsDir(const QDir &dir)
    60 #endif
   114     {
    61 };
   115         RFs rfs;
    62 
   116         qt_symbian_throwIfError(rfs.Connect());
    63 #if defined(Q_OS_SYMBIAN)
   117         bool pathFound = false;
    64 DirChecker::DirChecker()
   118         // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
    65 {
   119         // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
    66     qt_symbian_throwIfError(rfs.Connect());
   120         // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
    67 }
   121         // Use native Symbian code to check for directory existence, because checking
    68 
   122         // for files from under non-existent protected dir like E:/private/<uid> using
    69 bool DirChecker::checkDir(const QDir& dir)
   123         // QDir::exists causes platform security violations on most apps.
    70 {
   124         QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
    71     bool pathFound = false;
   125         TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
    72     // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
   126         TUint attributes;
    73     // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
   127         TInt err = rfs.Att(ptr, attributes);
    74     // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
   128         if (err == KErrNone) {
    75     // Use native Symbian code to check for directory existence, because checking
   129             // yes, the directory exists.
    76     // for files from under non-existent protected dir like E:/private/<uid> using
   130             pathFound = true;
    77     // QDir::exists causes platform security violations on most apps.
   131         }
    78     QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
   132         rfs.Close();
    79     TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
   133         return pathFound;
    80     TUint attributes;
       
    81     TInt err = rfs.Att(ptr, attributes);
       
    82     if (err == KErrNone) {
       
    83         // yes, the directory exists.
       
    84         pathFound = true;
       
    85     }
   134     }
    86     return pathFound;
       
    87 }
       
    88 
       
    89 DirChecker::~DirChecker()
       
    90 {
       
    91     rfs.Close();
       
    92 }
       
    93 #else
   135 #else
    94 DirChecker::DirChecker()
   136     inline bool checkMobilityPluginsDir(const QDir &dir)
    95 {
   137     {
    96 }
   138         return dir.exists();
    97 
   139     }
    98 DirChecker::~DirChecker()
       
    99 {
       
   100 }
       
   101 
       
   102 bool DirChecker::checkDir(const QDir &dir)
       
   103 {
       
   104     return dir.exists();
       
   105 }
       
   106 #endif
   140 #endif
   107 
   141 
   108 inline QStringList mobilityPlugins(const QString plugintype)
   142 inline QStringList mobilityPlugins(const QString plugintype)
   109 {
   143 {
   110 #if !defined QT_NO_DEBUG
   144 #if !defined QT_NO_DEBUG
   118 #if !defined QT_NO_DEBUG
   152 #if !defined QT_NO_DEBUG
   119     if (showDebug)
   153     if (showDebug)
   120         qDebug() << "Plugin paths:" << paths;
   154         qDebug() << "Plugin paths:" << paths;
   121 #endif
   155 #endif
   122 
   156 
   123     DirChecker dirChecker;
   157     //DirChecker dirChecker;
   124 
   158 
   125     //temp variable to avoid multiple identic path
   159     //temp variable to avoid multiple identic path
   126     QSet<QString> processed;
   160     QSet<QString> processed;
   127 
   161 
   128     /* Discover a bunch o plugins */
   162     /* Discover a bunch o plugins */
   132     for (int i=0; i < paths.count(); i++) {
   166     for (int i=0; i < paths.count(); i++) {
   133         if (processed.contains(paths.at(i)))
   167         if (processed.contains(paths.at(i)))
   134             continue;
   168             continue;
   135         processed.insert(paths.at(i));
   169         processed.insert(paths.at(i));
   136         QDir pluginsDir(paths.at(i));
   170         QDir pluginsDir(paths.at(i));
   137         if (!dirChecker.checkDir(pluginsDir))
   171         if (!checkMobilityPluginsDir(pluginsDir))
   138             continue;
   172             continue;
   139 
   173 
   140 #if defined(Q_OS_WIN)
   174 #if defined(Q_OS_WIN)
   141         if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
   175         if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
   142             pluginsDir.cdUp();
   176             pluginsDir.cdUp();
   152         subdir += plugintype;
   186         subdir += plugintype;
   153         if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
   187         if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
   154             || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
   188             || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
   155             subdir = plugintype;
   189             subdir = plugintype;
   156 
   190 
   157         if (dirChecker.checkDir(QDir(pluginsDir.path() + QLatin1Char('/') + subdir))) {
   191         if (checkMobilityPluginsDir(QDir(pluginsDir.path() + QLatin1Char('/') + subdir))) {
   158             pluginsDir.cd(subdir);
   192             pluginsDir.cd(subdir);
   159             QStringList files = pluginsDir.entryList(QDir::Files);
   193             QStringList files = pluginsDir.entryList(QDir::Files);
   160 
   194 
   161 #if !defined QT_NO_DEBUG
   195 #if !defined QT_NO_DEBUG
   162             if (showDebug)
   196             if (showDebug)
   170     }
   204     }
   171     return  plugins;
   205     return  plugins;
   172 }
   206 }
   173 
   207 
   174 QTM_END_NAMESPACE
   208 QTM_END_NAMESPACE
       
   209 
       
   210 #endif