controlpanelui/src/cpcategorymodel/src/cppluginconfigreader.cpp
changeset 33 0cfa53de576f
parent 10 0a74be98a8bc
--- a/controlpanelui/src/cpcategorymodel/src/cppluginconfigreader.cpp	Thu Aug 05 11:28:29 2010 +0800
+++ b/controlpanelui/src/cpcategorymodel/src/cppluginconfigreader.cpp	Tue Aug 24 10:56:32 2010 +0800
@@ -11,7 +11,7 @@
 *
 * Contributors:
 *
-* Description:  
+* Description:  This class reads cpcfg files.
 *
 */
 
@@ -27,19 +27,30 @@
 const QString PLUGIN_DISPALYNAME_ATTR   = "displayname";
 const QString DESC_TAG                  = "desc";
 
+/*
+ * Constructor.
+ * @configPath : the full path of the config file.
+ */
 CpPluginConfigReader::CpPluginConfigReader(const QString &configPath)
 : mConfigPath (configPath)
 {
 }
 
+/*
+ * Desctructor
+ */
 CpPluginConfigReader::~CpPluginConfigReader()
 {
 }
 
+/*
+ * Reads a cpcfg file, returns a list of CpPluginConfig.
+ */
 QList<CpPluginConfig> CpPluginConfigReader::readCpPluginConfigs()
 { 
     CPFW_LOG(QLatin1String("reading cpcfg file:") + mConfigPath);
     
+    // Empty config file
     if (mConfigPath.isNull() || mConfigPath.isEmpty()) {
         CPFW_LOG("CpPluginConfigReader::readCpPluginConfigs() mConfigPath is empty.");
         return QList<CpPluginConfig> ();
@@ -47,11 +58,13 @@
 
     QFile file(mConfigPath);
     
+    // Config file doesn't exist
     if (!file.exists()) {
         CPFW_LOG( mConfigPath  + " does not exist.");
         return QList<CpPluginConfig> ();
     }
     
+    // Open config file failed
     if (!file.open(QFile::ReadOnly | QFile::Text)) {
         CPFW_LOG(QString("CpPluginConfigReader::readCpPluginConfigs() open file failed. Error:%1")
             .arg(static_cast<int>(file.error()),0,10));
@@ -69,6 +82,9 @@
     return cpPluginConfigList;
 }
 
+/*
+ * Read a list of CpPluginConfig from a xml stream.
+ */
 void CpPluginConfigReader::readCpPluginConfigs(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList)
 {
     xmlReader.readNext();
@@ -76,6 +92,7 @@
     while (!xmlReader.atEnd()) {
         
         if (xmlReader.isStartElement()) {
+            // Read <childplugins> node
             if (xmlReader.name() == CHILD_PLUGINS_TAG) {
                 readChildPluginsElement(xmlReader, cpPluginConfigList);
             }
@@ -90,6 +107,9 @@
     }
 }
 
+/*
+ * Read <childplugins> node.
+ */
 void CpPluginConfigReader::readChildPluginsElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList)
 {
     xmlReader.readNext();
@@ -102,9 +122,11 @@
         }
 
         if (xmlReader.isStartElement()) {
+            // Read <plugin> node
             if (xmlReader.name() == PLUGIN_TAG) {
                 readPluginElement(xmlReader, cpPluginConfigList);
             }
+            // Skip invalid node
             else {
                 skipUnknownElement(xmlReader);
             }
@@ -116,34 +138,46 @@
     }
 }
 
+/*
+ * Read <plugin> node.
+ */
 void CpPluginConfigReader::readPluginElement(QXmlStreamReader &xmlReader,QList<CpPluginConfig> &cpPluginConfigList)
 { 
     CpPluginConfig cpPluginConfig;
   
     QXmlStreamAttributes xmlAttributes = xmlReader.attributes();
   
+    // Read <id> attribute
     if (xmlAttributes.hasAttribute(PLUGIN_ID_ATTR))  {
         cpPluginConfig.mUid 
             = (xmlAttributes.value(PLUGIN_ID_ATTR)).toString().toUInt(0,16);
     }
   
+    // Read <dll> attribute
     if (xmlAttributes.hasAttribute(PLUGIN_DLL_ATTR)) {
         cpPluginConfig.mPluginFile 
             = (xmlAttributes.value(PLUGIN_DLL_ATTR)).toString();
     }
   
+    // Read <displayname> attribute
     if (xmlAttributes.hasAttribute(PLUGIN_DISPALYNAME_ATTR)) {
         cpPluginConfig.mDisplayName 
             = (xmlAttributes.value(PLUGIN_DISPALYNAME_ATTR)).toString();
     }
   
+    // Read <description> node
     readDescElement(xmlReader,cpPluginConfig);
   
+#ifdef ENABLE_CPFW_LOG
     cpPluginConfig.dump();
+#endif
   
     cpPluginConfigList.append(cpPluginConfig);
 }
 
+/*
+ * Read <description> node.
+ */
 void CpPluginConfigReader::readDescElement(QXmlStreamReader &xmlReader,CpPluginConfig &cpPluginConfig)
 {
     xmlReader.readNext();
@@ -156,12 +190,17 @@
         }
 
         if (xmlReader.isStartElement()) {
+            // valid description node
             if (xmlReader.name() == DESC_TAG) {
                 cpPluginConfig.mDescription = xmlReader.readElementText();
                 if (xmlReader.isEndElement()) {
                     xmlReader.readNext();
                 }
             }
+            // invalid node, skip it
+            else {
+                skipUnknownElement(xmlReader);
+            }
         }
         
         else {
@@ -170,6 +209,9 @@
     }
 }
 
+/*
+ * ignore invalid node.
+ */
 void CpPluginConfigReader::skipUnknownElement(QXmlStreamReader &xmlReader)
 {
     xmlReader.readNext();