locationsystemui/locationsysui/possettings/possettingsengine/src/possettingspluginsloader.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Implementation of the Positioning Settings Plugins Loader class 
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 #include "possettingspluginsloader.h"
       
    20 #include "possettingscrkey.h"
       
    21 #include <QDir>
       
    22 #include <QFileInfoList>
       
    23 #include <QFileInfo>
       
    24 #include <QPluginLoader>
       
    25 #include <QDebug>
       
    26 #include <xqsettingsmanager.h>
       
    27 #include <xqsettingskey.h>
       
    28 
       
    29 
       
    30 #ifdef Q_OS_SYMBIAN
       
    31 #define PLUGIN_PATH QString("\\resource\\qt\\plugins\\positioningsettings")
       
    32 
       
    33 #else
       
    34 #define PLUGIN_PATH QString("C:\\qt\\plugins\\positioningsettings")
       
    35 #endif 
       
    36 
       
    37 // constants
       
    38 const int KNoOfDigits = 4;
       
    39 
       
    40 //---------------------------------------------------------------------
       
    41 // PosSettingsPluginsLoader::PosSettingsPluginsLoader
       
    42 // 
       
    43 //---------------------------------------------------------------------
       
    44 PosSettingsPluginsLoader::PosSettingsPluginsLoader()
       
    45     {
       
    46     qDebug() << "+ PosSettingsPluginsLoader::PosSettingsPluginsLoader()";
       
    47     qDebug() << "- PosSettingsPluginsLoader::PosSettingsPluginsLoader()";
       
    48     }
       
    49 
       
    50 //---------------------------------------------------------------------
       
    51 // PosSettingsPluginsLoader::~PosSettingsPluginsLoader
       
    52 // 
       
    53 //---------------------------------------------------------------------
       
    54 PosSettingsPluginsLoader::~PosSettingsPluginsLoader()
       
    55     {
       
    56     qDebug() << "+ PosSettingsPluginsLoader::~PosSettingsPluginsLoader()";
       
    57     mDllNameList.clear();
       
    58     qDebug() << "- PosSettingsPluginsLoader::~PosSettingsPluginsLoader()";
       
    59     }
       
    60 //---------------------------------------------------------------------
       
    61 // PosSettingsPluginsLoader::loadPlugins
       
    62 // 
       
    63 //---------------------------------------------------------------------
       
    64 QList<PosSettingsAdvInterface*> PosSettingsPluginsLoader::loadPlugins()
       
    65     {
       
    66     qDebug() << "+ PosSettingsPluginsLoader::loadPlugins()";
       
    67     // parse the default cen rep key value which is used to determine
       
    68     // the order of loading the default positioning settings plugins
       
    69     ParseCenRepKey();
       
    70     // List containing the plugins implementing the PositioningSettingsAdvancedInterface
       
    71     QList<PosSettingsAdvInterface*> pluginsList;
       
    72     // Check for the files under the positioningsettings directory
       
    73     QDir pluginsDir(PLUGIN_PATH + QDir::separator());
       
    74     QFileInfoList fileInfoList = pluginsDir.entryInfoList();
       
    75     // check each file in this directory,only if its a dll give it to the
       
    76     // plugin loader
       
    77     foreach ( const QFileInfo &fileInfo, fileInfoList )
       
    78             {
       
    79             QString fileName = fileInfo.absoluteFilePath();
       
    80 						qDebug() << "Filename: " <<  fileName;
       
    81 						
       
    82             if (!QLibrary::isLibrary(fileName))
       
    83                 {
       
    84                 continue;
       
    85                 }
       
    86             // load the dlls using QPluginLoader
       
    87             QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
       
    88             qDebug() << "Plugin Filename: " <<  pluginsDir.absoluteFilePath(fileName);
       
    89             QObject *plugin = pluginLoader.instance();
       
    90             // Check if the plugin found is an implementation of the
       
    91             // PosSettingsAdvInterface,if yes add it to the plugins list
       
    92 
       
    93             if (plugin)
       
    94                 {
       
    95                 PosSettingsAdvInterface* advancedInterface = qobject_cast<
       
    96                         PosSettingsAdvInterface *> (plugin);
       
    97 
       
    98                 if (advancedInterface)
       
    99                     {
       
   100                     
       
   101                     QString dllName = fileInfo.baseName();
       
   102                     // check the position into which the plugin needs to be
       
   103                     // inserted if it is one of the default plugins
       
   104                     for (int i = 0; i < mDllNameList.count(); i++)
       
   105                         {
       
   106                         if (dllName.compare(mDllNameList[i],Qt::CaseInsensitive) == KErrNone)
       
   107                             {
       
   108                             pluginsList.insert(i, advancedInterface);
       
   109                             break;
       
   110                             }
       
   111                         }
       
   112                     }
       
   113                 }
       
   114             }
       
   115     qDebug() << "- PosSettingsPluginsLoader::loadPlugins()";
       
   116     return pluginsList;
       
   117     }
       
   118 
       
   119 //---------------------------------------------------------------------
       
   120 // PosSettingsPluginsLoader::ParseCenRepKey
       
   121 // 
       
   122 //---------------------------------------------------------------------
       
   123 void PosSettingsPluginsLoader::ParseCenRepKey()
       
   124     {
       
   125     qDebug() << "+ PosSettingsPluginsLoader::ParseCenRepKey()";
       
   126     // create a XQSettingsManager instance
       
   127     XQSettingsManager* manager = new XQSettingsManager();
       
   128     // create a XQSettingsKey object to read the cenrep key value
       
   129     XQSettingsKey cenrepKey(XQSettingsKey::TargetCentralRepository,
       
   130             KCRUidPositioningSettings.iUid, KPositioningSettingsPlugins);
       
   131     // read the cenrep key value
       
   132     QVariant key(manager->readItemValue(cenrepKey,XQSettingsManager::TypeString));
       
   133     // convert the key value to string
       
   134     QString keyStringValue = key.toString();
       
   135     // if the length of default value is less than 4 digits then return
       
   136     if (keyStringValue.size() < KNoOfDigits)
       
   137         {
       
   138         qDebug() << "- PosSettingsPluginsLoader::ParseCenRepKey()";
       
   139         return;
       
   140         }
       
   141     // get the count of the number of plugin dlls
       
   142     int dllCount = keyStringValue.left(KNoOfDigits).toInt();
       
   143     // initialise current index to 4
       
   144     int currentIndex = KNoOfDigits;
       
   145     // extract the name of each of the dll from the cenrep key value
       
   146     for (int i = 0; i < dllCount; i++)
       
   147         {
       
   148         // extract length of dll name
       
   149         int length = keyStringValue.mid(currentIndex, KNoOfDigits).toInt();
       
   150         // increment the current index value
       
   151         currentIndex += KNoOfDigits;
       
   152         // get the dll name
       
   153         QString dllName = keyStringValue.mid(currentIndex, length);
       
   154         // append to list of dll names
       
   155         mDllNameList.append(dllName);
       
   156         // increment the value of currentIndex by length of name
       
   157         currentIndex += length;
       
   158         }
       
   159     qDebug() << "- PosSettingsPluginsLoader::ParseCenRepKey()";
       
   160     }
       
   161