wizardproviders/ftuwizardprovider/src/ftumanifestparser.cpp
changeset 0 c464cd7e2753
child 9 aa22d2c19e57
equal deleted inserted replaced
-1:000000000000 0:c464cd7e2753
       
     1 /*
       
     2 * Copyright (c) 2009 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:  FTU manifest parser.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ftumanifestparser.h"
       
    20 #ifdef Q_OS_SYMBIAN
       
    21 #include "ftuwizardproviderinternalcrkeys.h"
       
    22 #endif
       
    23 #include <QDomDocument>
       
    24 #include <QFile>
       
    25 #include <QStringList>
       
    26 #include <QFileInfo>
       
    27 #include <QDir>
       
    28 #include <QDebug>
       
    29 
       
    30 #ifdef Q_OS_SYMBIAN
       
    31 
       
    32 #include <XQSettingsManager> // for reading cenrep keys
       
    33 #endif // Q_OS_SYMBIAN
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // FtuManifestParser::FtuManifestParser
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 FtuManifestParser::FtuManifestParser(QObject* aParent)
       
    40     : QObject(aParent)
       
    41 {
       
    42 }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // FtuManifestParser::~FtuManifestParser
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 FtuManifestParser::~FtuManifestParser()
       
    49 {
       
    50 
       
    51 }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // FtuManifestParser::parsePluginList
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 QStringList FtuManifestParser::parsePluginList(const QString& manifestPath)
       
    59 {
       
    60     QStringList dllNameList;
       
    61     QStringList pathList;
       
    62     
       
    63     //Check plugin dirs from root of different drives
       
    64     QFileInfoList drives = QDir::drives();
       
    65     int i;
       
    66     for(i = 0; i < drives.count(); i++)
       
    67     {
       
    68         QFileInfo drive = drives.at(i);
       
    69         QString driveLetter = drive.absolutePath();
       
    70         QString path = driveLetter + manifestPath;
       
    71         if(QDir(path).exists())
       
    72         {
       
    73             qDebug() << "ftu:: append to path list: " << path;
       
    74             pathList << path;
       
    75         }
       
    76     }      
       
    77     // Read the configured plugin list.
       
    78     QStringList filesToRead = readManifestFilesFromConfig();
       
    79 
       
    80     for(i=0; i < pathList.count(); i++)
       
    81     {
       
    82         QString path = pathList.at(i);
       
    83         QDir dir(path);
       
    84 
       
    85         // Use the configured list as a filter while getting the 
       
    86         // manifest files.
       
    87         dir.setNameFilters(filesToRead);
       
    88         QStringList entries = dir.entryList(filesToRead, QDir::Files);
       
    89     
       
    90         qDebug() << "ftu: Configured manifest file count " 
       
    91                  << filesToRead.count()
       
    92                  << " found manifest files from system " << entries.count();
       
    93         
       
    94         // Go through the configured list and find the manifest files.
       
    95         for(int j=0; j < filesToRead.count() ; ++j)
       
    96         {
       
    97             int index = entries.indexOf(filesToRead[j]);
       
    98             qDebug() << "ftu:reading manifest file from "<< index;
       
    99             if(index > -1 && index <= entries.count())
       
   100             {
       
   101                 QString fileName = entries[index]; 
       
   102                 qDebug() << "ftu:: loading from manifest file: " << fileName;
       
   103                 QString path = loadFromXml(dir.absoluteFilePath(fileName));
       
   104                 qDebug() << "ftu:: path from manifest: " << path;
       
   105                 if(!path.isEmpty())
       
   106                 {
       
   107                     dllNameList << path;
       
   108                 }
       
   109             }
       
   110         }    
       
   111     }
       
   112     return dllNameList;
       
   113 }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // FtuManifestParser::readManifestFilesFromConfig
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 
       
   120 QStringList FtuManifestParser::readManifestFilesFromConfig()
       
   121 {
       
   122     QStringList filesFromConf;
       
   123 #ifdef Q_OS_SYMBIAN
       
   124     
       
   125     XQSettingsManager* settingsManager = new XQSettingsManager();
       
   126     
       
   127     XQSettingsKey numberOfPluginsKey(XQSettingsKey::TargetCentralRepository,
       
   128                                      KCrUidFtuWizardProvider,
       
   129                                      KFtuNumberOfWizardPlugins);
       
   130     
       
   131     bool ok = false;
       
   132     int numberOfPlugins = settingsManager->readItemValue(
       
   133                                               numberOfPluginsKey).toInt(&ok);
       
   134 
       
   135     qDebug() << "Ftu:FtuManifestParser reading the nbr of plugins resulted: "
       
   136              << ok;
       
   137     
       
   138     if(ok)
       
   139     {
       
   140         qDebug() << "Ftu:reading config for " << numberOfPlugins 
       
   141                  << " plugins";
       
   142         
       
   143         
       
   144         for(int i=1; i <= numberOfPlugins ; ++i)
       
   145         {
       
   146             XQSettingsKey fileKey(XQSettingsKey::TargetCentralRepository,
       
   147                                   KCrUidFtuWizardProvider,
       
   148                                   KFtuNumberOfWizardPlugins + i);
       
   149             
       
   150             QString file = settingsManager->readItemValue(fileKey, 
       
   151                                    XQSettingsManager::TypeString).toString();
       
   152             qDebug() << "Ftu:Reading filename from conf :" << file;            
       
   153             filesFromConf << file;
       
   154         }
       
   155     }
       
   156     delete settingsManager;
       
   157 #else
       
   158     // Add hardcoded strings for windows environment,
       
   159     // currently the settings manager is not available for windows.
       
   160 	filesFromConf << "ftusocialmediawizard.manifest"
       
   161                   << "ftudatetimelocationwizard.manifest"
       
   162 				  << "ftuexamplewizard.manifest"
       
   163 				  << "ftuemailwizard.manifest";
       
   164 #endif    
       
   165     return filesFromConf;
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // FtuManifestParser::loadFromXml
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 QString FtuManifestParser::loadFromXml(const QString& aFileName)
       
   173 {
       
   174 
       
   175     qDebug() << "ftu:: ManifestParser::loadFromXml " << aFileName;
       
   176     QFile file(aFileName);
       
   177     
       
   178     if(!file.exists())
       
   179     {
       
   180         qDebug() << "ftu: file does not exist";
       
   181         return QString();
       
   182     }
       
   183 
       
   184     QDomDocument document;
       
   185     if(!document.setContent(&file))
       
   186     {
       
   187         return QString();
       
   188     }
       
   189 
       
   190     QDomElement element = document.documentElement();
       
   191     if(element.tagName() != "plugin")
       
   192     {
       
   193         qDebug() << "ftu: Tag name plugin not found";
       
   194         return QString();
       
   195     }
       
   196 
       
   197     QDomNodeList plugins = element.elementsByTagName("runtime");
       
   198 
       
   199     for(int i = 0; i < plugins.count(); ++i)
       
   200     {
       
   201         element = plugins.at(i).toElement();
       
   202         QString attr = parseAttribute(element, "library");
       
   203         qDebug() << "ftu::parsed attr " << attr;
       
   204         return attr;
       
   205     }
       
   206     return QString();
       
   207 }
       
   208 
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // FtuManifestParser::parseAttribute
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 QString FtuManifestParser::parseAttribute(QDomElement& element, 
       
   215                                           const QString& attributeName) const
       
   216 {
       
   217     QDomAttr attribute = element.attributeNode(attributeName);
       
   218     if(attribute.isNull() || attribute.value().isEmpty())
       
   219     {
       
   220         qDebug() << "ftu: attribute not parsed [attr name]" << attributeName;
       
   221         return QString();
       
   222     }
       
   223 
       
   224     return attribute.value();
       
   225 }
       
   226 
       
   227