src/hbservers/hbthemeserver/hbthemeserverutils.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
--- a/src/hbservers/hbthemeserver/hbthemeserverutils.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbservers/hbthemeserver/hbthemeserverutils.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -125,10 +125,8 @@
         *inSharedCache = false;
     }
 
-#ifdef THEME_SERVER_TRACES
-    qDebug() << "In " << Q_FUNC_INFO;
-#endif // THEME_SERVER_TRACES
     if (cssOffset < 0) {
+        THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Stylesheet: " << fileName << " not found in shared cache.";
         HbCss::Parser parser;
         if (!parseCssFile(parser, fileName, cssOffset, fileExists)) {
             if (parser.errorCode == HbCss::Parser::OutOfMemoryError) {
@@ -264,14 +262,10 @@
     QFile file(fileName);
     fileExists = file.open(QFile::ReadOnly | QFile::Text);
     if (!fileExists) {
-#ifdef THEME_SERVER_TRACES
-        qWarning("Unable to open file");
-#endif
+        THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Unable to open the file: " << fileName;
         return -1;
     }
-#ifdef THEME_SERVER_TRACES
-    qDebug() << "Trying to load: " << fileName << "::" << layout << "::" << section;
-#endif // THEME_SERVER_TRACES
+    THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "Trying to load: " << fileName << "::" << layout << "::" << section;
 
     HbWidgetLoader::LayoutDefinition *layoutDef(0);
     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
@@ -354,24 +348,15 @@
  */
 int HbThemeServerUtils::getSharedEffect(const QString &fileName)
 {
-#ifdef THEME_SERVER_TRACES
-    qDebug() << "In " << Q_FUNC_INFO << fileName;
-#endif // THEME_SERVER_TRACES
+    THEME_GENERIC_DEBUG() << Q_FUNC_INFO << "called with fileName: " << fileName;
 
     qptrdiff effOffset = -1;
     if (effCache()->contains(fileName)) {
         effOffset = effCache()->value(fileName);
-
-#ifdef THEME_SERVER_TRACES
-        qDebug() << "Got effect in cache: " << fileName << "offset=" << effOffset;
-#endif //THEME_SERVER_TRACES
-
+        THEME_GENERIC_DEBUG() << "in cache: " << fileName << "offset=" << effOffset;
     } else {
-
-#ifdef THEME_SERVER_TRACES
-        qDebug() << "Not in cache, parsing: " << fileName;
-#endif //THEME_SERVER_TRACES
-
+        THEME_GENERIC_DEBUG() << "Not in cache, parsing: " << fileName;
+        
         // 1. Create an effect in shared memory
         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
         HbEffectFxmlData *data = 0;
@@ -386,6 +371,7 @@
                 manager->free(effOffset);
                 effOffset = -1;
             }
+            THEME_GENERIC_DEBUG() << "Exception when allocating shared memory.";
             return effOffset;
         }
         // 2. Parse the file.
@@ -405,14 +391,13 @@
                 fail = true;
             }
         } else {
-#ifdef THEME_SERVER_TRACES
-            qWarning() << "Cannot open" << fileName;
-#endif // THEME_SERVER_TRACES
+            THEME_GENERIC_DEBUG() << "Cannot open:" << fileName;
             fail = true;
         }
         if (fail) {
             data->~HbEffectFxmlData();
             manager->free(effOffset);
+            THEME_GENERIC_DEBUG() << "Failed to parese effect.";
             return -1;
         }
 
@@ -422,25 +407,20 @@
         // in the server side.
         HbSharedCache::instance()->add(HbSharedCache::Effect, fileName, effOffset);
     }
-
-#ifdef THEME_SERVER_TRACES
-    qDebug() << "returning offset: " << effOffset;
-#endif // THEME_SERVER_TRACES
-
+    
+    THEME_GENERIC_DEBUG() << "returning offset: " << effOffset;
     return effOffset;
 }
 
 void HbThemeServerUtils::createThemeIndex(const QString &themePath, const HbThemeType &themetype)
 {
-    #ifdef THEME_INDEX_TRACES
-    qDebug() <<  "ThemeIndex: createThemeIndex" << themePath.toUtf8();
-    #endif
+    THEME_INDEX_DEBUG() <<  "ThemeIndex: createThemeIndex" << themePath.toUtf8();
     QDir themeBasePath(themePath);
     // Path is like "C:/resource/hb/themes/icons/sfwhitetheme"
     QString themeName = themeBasePath.dirName();
     
     QString filename(themeBasePath.absolutePath());
-    int cutindex = filename.lastIndexOf("/",filename.lastIndexOf("/")-1)+1;
+    int cutindex = filename.lastIndexOf('/',filename.lastIndexOf('/')-1)+1;
     filename = filename.left(cutindex);
     themeBasePath.setPath(filename);
     filename.append(themeName);
@@ -457,50 +437,33 @@
     bool indexOK = false;
 
     if (indexFile.open(QIODevice::ReadOnly)) {
-
         indexOK = true;
-
         GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
 
-        HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();
-        
+        HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();        
         qint64 byteSize = indexFile.size();
-
-        #ifdef THEME_INDEX_TRACES
-        qDebug() <<  "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize;
-        #endif
+        THEME_INDEX_DEBUG() <<  "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize;
 
         int offset = manager->alloc(byteSize);
         if (offset >= 0) {
-            #ifdef THEME_INDEX_TRACES
-            qDebug() <<  "ThemeIndex: memory allocated for theme: " << themeName.toUtf8();
-            #endif
+            THEME_INDEX_DEBUG() <<  "ThemeIndex: memory allocated for theme: " << themeName.toUtf8();
 
             // Read the theme index in the shared chunk
             char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset);
 
             indexFile.read(address, byteSize);
             indexFile.close();
-
-            #ifdef THEME_INDEX_TRACES
-            qDebug() <<  "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!";
-            #endif
+            THEME_INDEX_DEBUG() <<  "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!";
 
             // Verify theme index contents if it is not located in ROM,
             // so that it does not have over-indexing offsets which might
             // crash all the clients trying to read from it.
 
             if (themePath[0] != 'z' && themePath[0] != 'Z') {
-                #ifdef THEME_INDEX_TRACES
-                qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8();
-                #endif
-
+                THEME_INDEX_DEBUG() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8();
                 HbThemeIndex index(address);
                 indexOK = index.validateItems(byteSize);
-
-                #ifdef THEME_INDEX_TRACES
-                qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK;
-                #endif
+                THEME_INDEX_DEBUG() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK;
             }
 
             if (indexOK) {