src/hbcore/cssparser/hblayeredstyleloader_p.cpp
changeset 21 4633027730f5
parent 6 c3690ec91ef8
child 28 b7da29130b0e
--- a/src/hbcore/cssparser/hblayeredstyleloader_p.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbcore/cssparser/hblayeredstyleloader_p.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -87,6 +87,11 @@
 
 Q_GLOBAL_STATIC(HbLayeredStyleLoader::ConcernStacks, globalConcernStacks)
 
+/**
+ * Keeps a list of files known not to exist
+ */
+Q_GLOBAL_STATIC(QSet<uint>, missingFiles);
+
 /*!
     Returns a static instance of a stack related to the given concern
     
@@ -100,13 +105,7 @@
     ConcernStacks *stacks = globalConcernStacks();
     if (stacks) {
         if (!stacks->contains(con)) {
-            (*stacks)[con].mConcern = con;
-            if (con != Concern_All) {
-                HbLayeredStyleLoader *allStack = getStack(Concern_All);
-                if (allStack) {
-                    (*stacks)[con].mUsedLayers = allStack->mUsedLayers;
-                }
-            }
+            (*stacks)[con].init(con);
         }
         result = &((*stacks)[con]);
     }
@@ -114,6 +113,22 @@
     return result;
 }
 
+void HbLayeredStyleLoader::init(Concern con)
+{
+    mConcern = con;
+    if (con != Concern_All) {
+        HbLayeredStyleLoader *allStack = getStack(Concern_All);
+        if (allStack) {
+            mUsedLayers = allStack->mUsedLayers;
+        }
+    }
+#ifdef HB_USETHEMESERVER
+    mServerHbCssMisses = HbThemeClient::global()->getSharedMissedHbCss();
+#else
+    mServerHbCssMisses = 0;
+#endif
+}
+
 
 /*!
     Loads the specified file, and appends the resulting selectors to 
@@ -138,43 +153,52 @@
 #ifdef LAYEREDSTYLELOADER_DEBUG
     qDebug() << "HbLayeredStyleLoader::load called for" << fileName;
 #endif
+    uint fileNameHash = qHash(fileName);
+    if (missingFiles()->contains(fileNameHash)) {
+        return 0;
+    }
+    if (mServerHbCssMisses && mServerHbCssMisses->contains(fileNameHash)) {
+        return 0;
+    }
+
     Layer &layer = mStyleLayers[priority];
     HbCss::StyleSheet* styleSheet = 0;
 
-    // Check for the availability of the file, as QFile::Exists takes more time this method is used
-    QFile file(fileName);
-    bool fileExists = file.open(QIODevice::ReadOnly);
-    file.close();
-    //if file doesn't exist no need to proceed further
-    if (fileExists) {
-        //if sharing is required based on Layer Priority, e.g. Core, Operator, Theme, 
-        //get the shared stylesheet from the theme client, which in turn fetches it 
-        // from the server.
-        if (sharingNeeded(priority)) {
-            
+    //if sharing is required based on Layer Priority, e.g. Core, Operator, Theme, 
+    //get the shared stylesheet from the theme client, which in turn fetches it 
+    // from the server.
+    if (sharingNeeded(priority)) {
+
 #ifdef LAYEREDSTYLELOADER_DEBUG
-            QTime time;
-            time.start();
+        QTime time;
+        time.start();
 #endif
 #ifdef HB_USETHEMESERVER
-            styleSheet = HbThemeClient::global()->getSharedStyleSheet(fileName,priority);
+        bool fileExists(true);
+        styleSheet = HbThemeClient::global()->getSharedStyleSheet(fileName,priority,fileExists);
+        if (!fileExists) {
+            missingFiles()->insert(fileNameHash);
+            return 0;
+        }
 #endif
 #ifdef LAYEREDSTYLELOADER_DEBUG
-            qDebug() << "Time elapsed in getting the shared stylesheet "<< fileName << " is : %d ms" <<time.elapsed();
+        qDebug() << "Time elapsed in getting the shared stylesheet "<< fileName << " is : %d ms" <<time.elapsed();
 #endif
-        }
-        // fallback incase of themeserver could not open the file or OOM condition in SharedMemory.
-        if (!styleSheet) {
-            //if sharing of stylesheet is not required, it means stylesheet is app specific
-            //so it won't be loaded from the server
+    }
+    // fallback incase of themeserver could not open the file or OOM condition in SharedMemory.
+    if (!styleSheet) {
+        //if sharing of stylesheet is not required, it means stylesheet is app specific
+        //so it won't be loaded from the server
+
+        HbCss::Parser parser;
+        if (parser.init(fileName, true)) {
             styleSheet = HbMemoryUtils::create<HbCss::StyleSheet>(HbMemoryManager::HeapMemory);
-
-            HbCss::Parser parser;
-            parser.init(fileName, true);
             if (!parser.parse(styleSheet)) {
                 HbMemoryUtils::release<HbCss::StyleSheet>(styleSheet);
                 styleSheet = 0;
             }
+        } else {
+            missingFiles()->insert(fileNameHash);
         }
     }
 
@@ -189,7 +213,9 @@
     qDebug("Handle returned: %x", handle);
 #endif
 
-    updateLayersListIfRequired(priority);
+    if (handle) {
+        updateLayersListIfRequired(priority);
+    }
     return handle;
 }
 
@@ -213,17 +239,20 @@
         QString contents = stream.readAll();
 
         HbCss::Parser parser;
-        parser.init(contents, false);
-        HbCss::StyleSheet* styleSheet = 
-            HbMemoryUtils::create<HbCss::StyleSheet>(HbMemoryManager::HeapMemory);
+        if (parser.init(contents, false)) {
+            HbCss::StyleSheet* styleSheet = 
+                HbMemoryUtils::create<HbCss::StyleSheet>(HbMemoryManager::HeapMemory);
 
-        if (parser.parse(styleSheet)) {
-            layer.styleSelector.addStyleSheet(styleSheet);
-            handle = reinterpret_cast<qptrdiff>(layer.styleSelector.styleSheets.last());
+            if (parser.parse(styleSheet)) {
+                layer.styleSelector.addStyleSheet(styleSheet);
+                handle = reinterpret_cast<qptrdiff>(layer.styleSelector.styleSheets.last());
+            }
         }
     }
 
-    updateLayersListIfRequired(priority);
+    if (handle) {
+        updateLayersListIfRequired(priority);
+    }
     return handle;
 }