src/hbservers/hbthemeserver/hbthemeserver_symbian.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 5 627c4a0fd0e7
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
    30 #include "hbthemeindex_p.h"
    30 #include "hbthemeindex_p.h"
    31 #include "hbthemeutils_p.h"
    31 #include "hbthemeutils_p.h"
    32 #include "hbsharedmemorymanager_p.h"
    32 #include "hbsharedmemorymanager_p.h"
    33 #include "hbtypefaceinfodatabase_p.h"
    33 #include "hbtypefaceinfodatabase_p.h"
    34 
    34 
    35 
       
    36 #include <QHash>
    35 #include <QHash>
    37 #include <QImage>
    36 #include <QImage>
    38 #include <QSharedMemory>
    37 #include <QSharedMemory>
    39 #include <QDebug>
    38 #include <QDebug>
    40 #include <QProcess>
    39 #include <QProcess>
    41 #include <QFile>
    40 #include <QFile>
       
    41 #include <QFileInfo>
    42 #include <QPainter>
    42 #include <QPainter>
    43 #include <QSettings>
    43 #include <QSettings>
    44 #include <QSizeF>
    44 #include <QSizeF>
    45 #include <e32property.h>
    45 #include <e32property.h>
    46 #include <e32base.h>
    46 #include <e32base.h>
    61 // 5 MB  CPU cache size
    61 // 5 MB  CPU cache size
    62 #define CPU_CACHE_SIZE 0x500000
    62 #define CPU_CACHE_SIZE 0x500000
    63 
    63 
    64 static const TInt KThemeName = 0;
    64 static const TInt KThemeName = 0;
    65 
    65 
    66 // Publish/Subscribe themeRequestProp specific
    66 const QString KOperatorCPath = "C:/resource/hb/operatorTheme/icons/";
    67 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
    67 const QString KOperatorZPath = "Z:/resource/hb/operatorTheme/icons/";
    68 static _LIT_SECURITY_POLICY_C1(KThemeChangerPolicy,ECapabilityWriteDeviceData);
    68 
    69 
       
    70 
       
    71 const QString operatorCPath = "C:/resource/hb/operatorTheme/icons/";
       
    72 const QString operatorZPath = "Z:/resource/hb/operatorTheme/icons/";
       
    73 
       
    74 static HbThemeServerPrivate *TheServer = 0;
       
    75 bool HbThemeServerPrivate::gpuGoodMemoryState = true;
    69 bool HbThemeServerPrivate::gpuGoodMemoryState = true;
    76 // This is used as parent theme always regardless of the active theme
    70 // This is used as parent theme always regardless of the active theme
    77 
    71 
    78 //**********************************
    72 //**********************************
    79 //HbThemeServerPrivate
    73 //HbThemeServerPrivate
    91 HbThemeServerPrivate * HbThemeServerPrivate::NewL(CActive::TPriority aActiveObjectPriority)
    85 HbThemeServerPrivate * HbThemeServerPrivate::NewL(CActive::TPriority aActiveObjectPriority)
    92 {
    86 {
    93     HbThemeServerPrivate* self = new(ELeave) HbThemeServerPrivate(aActiveObjectPriority);
    87     HbThemeServerPrivate* self = new(ELeave) HbThemeServerPrivate(aActiveObjectPriority);
    94     CleanupStack::PushL(self);
    88     CleanupStack::PushL(self);
    95     self->ConstructL();
    89     self->ConstructL();
    96     CleanupStack::Pop(); // self
    90     CleanupStack::Pop(self);
    97     return self;
    91     return self;
    98 }
    92 }
    99 
    93 
   100 /**
    94 /**
   101 ConstructL
    95 ConstructL
   129     // Register theme system effects in construction
   123     // Register theme system effects in construction
   130     // TODO: fix parameter
   124     // TODO: fix parameter
   131     HbThemeSystemEffect::handleThemeChange(iCurrentThemeName);
   125     HbThemeSystemEffect::handleThemeChange(iCurrentThemeName);
   132 
   126 
   133     // Open index file to prevent uninstallation of the active theme
   127     // Open index file to prevent uninstallation of the active theme
   134     openCurrentIndexFile();
   128     if (!openCurrentIndexFile()) {
       
   129         // theme doesn't exist activate default theme
       
   130         iCurrentThemeName = HbThemeUtils::defaultTheme().name;
       
   131         resolveThemePath(iCurrentThemeName, iCurrentThemePath);
       
   132     }
   135     cache = 0;
   133     cache = 0;
   136     cssCache = 0;
   134     cssCache = 0;
   137 
   135 
   138     QT_TRY {
   136     QT_TRY {
   139         //Create the Icon cache
   137         //Create the Icon cache
   155     
   153     
   156     // Process base theme index, it is used as parent index also when the current theme is something else
   154     // Process base theme index, it is used as parent index also when the current theme is something else
   157     QString basePath;
   155     QString basePath;
   158     resolveThemePath(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting), basePath);
   156     resolveThemePath(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting), basePath);
   159     createThemeIndex(basePath, BaseTheme);
   157     createThemeIndex(basePath, BaseTheme);
   160     // Process operator Drive C theme index
   158     // Process operator theme indexes
   161     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
   159     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
   162     if (!operatorName.isEmpty()) {
   160     if (!operatorName.isEmpty()) {
   163         QString operatorPath;
   161         QString operatorPath;
   164         operatorPath.append(operatorCPath);
   162         operatorPath.append(KOperatorCPath);
   165         operatorPath.append(operatorName);
   163         operatorPath.append(operatorName);
   166         createThemeIndex(operatorPath, OperatorC);
   164         createThemeIndex(operatorPath, OperatorC);
   167         // Process operator Drive Z theme index
   165         // Process operator Drive Z theme index
   168         QString operatorROMPath;
   166         QString operatorROMPath;
   169         operatorROMPath.append(operatorZPath);    
   167         operatorROMPath.append(KOperatorZPath);
   170         operatorROMPath.append(operatorName);
   168         operatorROMPath.append(operatorName);
   171         createThemeIndex(operatorROMPath, OperatorROM);
   169         createThemeIndex(operatorROMPath, OperatorROM);
   172     }
   170     }
   173     // Process current theme index
   171     // Process current theme index
   174     createThemeIndex(iCurrentThemePath, ActiveTheme);
   172     createThemeIndex(iCurrentThemePath, ActiveTheme);
   178 #ifndef HB_NVG_CS_ICON
   176 #ifndef HB_NVG_CS_ICON
   179     QProcess::startDetached("hbiconpreloader.exe");
   177     QProcess::startDetached("hbiconpreloader.exe");
   180 #endif
   178 #endif
   181 
   179 
   182     // Start the splash screen generator app.
   180     // Start the splash screen generator app.
   183     //QProcess::startDetached("hbsplashgenerator.exe");
   181     QProcess::startDetached("hbsplashgenerator.exe");
   184 }
   182 }
   185 
   183 
   186 /**
   184 /**
   187 Constructor takes the server priority value.
   185 Constructor takes the server priority value.
   188 
   186 
   192 It passes the priority value to the base class in the Ctor list.
   190 It passes the priority value to the base class in the Ctor list.
   193 By default, the session is not sharable, which is what we want here
   191 By default, the session is not sharable, which is what we want here
   194 so no second parameter is passed to the CServer2 constructor.
   192 so no second parameter is passed to the CServer2 constructor.
   195 */
   193 */
   196 HbThemeServerPrivate::HbThemeServerPrivate(CActive::TPriority aActiveObjectPriority)
   194 HbThemeServerPrivate::HbThemeServerPrivate(CActive::TPriority aActiveObjectPriority)
   197     : CServer2( aActiveObjectPriority )
   195     : CServer2( aActiveObjectPriority ), iWatcher(0)
   198 {
   196 {
   199     // Set server pointer in static variable
       
   200     TheServer = this;
       
   201 
       
   202     // Set up the listener to listen for Publish events
   197     // Set up the listener to listen for Publish events
   203     TRAPD(err, iListener = CHbThemeChangeNotificationListener::NewL(*this));
   198     TRAPD(err, iListener = CHbThemeChangeNotificationListener::NewL(*this));
   204     if (err) {
   199     if (err) {
   205         qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: CHbThemeChangeNotificationListener::NewL failed = %d", err );
   200         qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: CHbThemeChangeNotificationListener::NewL failed = %d", err );
   206     } else {
   201     } else {
   207         TRAPD( err, iListener->startListening());
   202         TRAPD(err, iListener->startListeningL());
   208         if (err) {
   203         if (err) {
   209              qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: iListener->startListening failed = %d", err );
   204              qWarning( "HbThemeServerPrivate::HbThemeServerPrivate: iListener->startListening failed = %d", err );
   210          }
   205          }
   211     }
   206     }    
   212 }
   207 }
   213 
   208 
   214 /**
   209 /**
   215 Destructor
   210 Destructor
   216  */
   211  */
   224     if(err != KErrNotFound) {
   219     if(err != KErrNotFound) {
   225         User::LeaveIfError(err);
   220         User::LeaveIfError(err);
   226     }
   221     }
   227     // Delete the listener for Publish/Subscribe
   222     // Delete the listener for Publish/Subscribe
   228     delete iListener;
   223     delete iListener;
   229 }
   224     // Delete file watcher
   230 
   225     if (iWatcher) {
   231 HbThemeServerPrivate *HbThemeServerPrivate::Instance()
   226         delete iWatcher;
   232 {
   227     }
   233     return TheServer;
   228 }
   234 }
   229 
   235 
   230 /*
   236 void HbThemeServerPrivate::openCurrentIndexFile()
   231  * Returns FALSE if file doesn't exist, TRUE otherwise
       
   232  */
       
   233 bool HbThemeServerPrivate::openCurrentIndexFile()
   237 {
   234 {
   238     // Open index file to prevent uninstallation of the active theme
   235     // Open index file to prevent uninstallation of the active theme
   239     if (!iCurrentThemePath.isEmpty() && iCurrentThemePath[0] != 'Z') {
   236     if (!iCurrentThemePath.isEmpty() && iCurrentThemePath[0] != 'z' && 
       
   237         iCurrentThemePath[0] != 'Z' && iCurrentThemePath[0] != ':') {
   240         QString indexFileName;
   238         QString indexFileName;
   241         indexFileName.append(iCurrentThemePath);
   239         indexFileName.append(iCurrentThemePath);
   242         indexFileName.append("\\index.theme");
   240         indexFileName.append("/index.theme");
   243 
   241         
   244         currentIndexfile.setFileName(indexFileName);
   242         QFile currentIndexfile(indexFileName);
   245         if(!currentIndexfile.open(QIODevice::ReadOnly)) {
   243         if(!currentIndexfile.open(QIODevice::ReadOnly)) {
   246             qWarning()<< "HbSymbianThemeServer: No Index file found in the new theme, How did this happen ??";
   244             qWarning()<< "HbSymbianThemeServer: No Index file found in the new theme, How did this happen ??";
   247         }
   245             return false;
   248     }
   246         } else {
       
   247             currentIndexfile.close();
       
   248             if (!iWatcher) {
       
   249                 // Set up the file watcher for active theme changes
       
   250                 TRAP_IGNORE(iWatcher = CHbThemeWatcher::NewL(*this));
       
   251             }
       
   252             // Start watching in case of mmc ejection
       
   253             if (iWatcher) {
       
   254                 iWatcher->startWatchingL(indexFileName);
       
   255             }
       
   256         }
       
   257     }
       
   258     return true;
   249 }
   259 }
   250 
   260 
   251 bool HbThemeServerPrivate::resolveThemePath(const QString &themeName, QString &themePath)
   261 bool HbThemeServerPrivate::resolveThemePath(const QString &themeName, QString &themePath)
   252 {
   262 {
   253     if(themeName == "hbdefault") {
   263     if(themeName == "hbdefault") {
   324     #ifdef THEME_INDEX_TRACES
   334     #ifdef THEME_INDEX_TRACES
   325     qDebug() << "ThemeIndex: theme change request, new theme =" << cleanThemeName.toUtf8();
   335     qDebug() << "ThemeIndex: theme change request, new theme =" << cleanThemeName.toUtf8();
   326     #endif
   336     #endif
   327 
   337 
   328     
   338     
   329     currentIndexfile.close();
       
   330     // Open index file to prevent uninstallation of the active theme
   339     // Open index file to prevent uninstallation of the active theme
   331     openCurrentIndexFile();
   340     if (!openCurrentIndexFile()) {
       
   341         // theme doesn't exist activate default theme
       
   342         iCurrentThemeName = HbThemeUtils::defaultTheme().name;
       
   343         resolveThemePath(iCurrentThemeName, iCurrentThemePath);
       
   344     }
   332 
   345 
   333     // Process operator Drive C theme index
   346     // Process operator Drive C theme index
   334     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
   347     QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting);
   335     if (!operatorName.isEmpty()) {
   348     if (!operatorName.isEmpty()) {
   336         QString operatorPath;
   349         QString operatorPath;
   337         operatorPath.append(operatorCPath);
   350         operatorPath.append(KOperatorCPath);
   338         operatorPath.append(operatorName);
   351         operatorPath.append(operatorName);
   339         createThemeIndex(operatorPath, OperatorC);
   352         createThemeIndex(operatorPath, OperatorC);
   340     }
   353     }
   341     // Process current theme index
   354     // Process current theme index
   342     createThemeIndex(iCurrentThemePath, ActiveTheme);
   355     createThemeIndex(iCurrentThemePath, ActiveTheme);
   343 
   356 
   344     // Clear cached icons and session data
   357     // Clear cached icons and session data
   345     clearIconCache();
   358     clearIconCache();
   346     iSessionIter.SetToFirst();
   359     iSessionIter.SetToFirst();
   347     while(iSessionIter != NULL) {
   360     while(iSessionIter) {
   348         HbThemeServerSession &session = reinterpret_cast<HbThemeServerSession &>(*iSessionIter);
   361         HbThemeServerSession &session = reinterpret_cast<HbThemeServerSession &>(*iSessionIter);
   349         session.ClearSessionData();
   362         session.ClearSessionData();
   350         iSessionIter++;
   363         iSessionIter++;
   351     }
   364     }
   352 	
   365 	
   750         HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();
   763         HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base();
   751         
   764         
   752         qint64 byteSize = indexFile.size();
   765         qint64 byteSize = indexFile.size();
   753 
   766 
   754         #ifdef THEME_INDEX_TRACES
   767         #ifdef THEME_INDEX_TRACES
   755         qDebug() <<  "ThemeIndex: " << theme.toUtf8() << " index file size:" << byteSize;
   768         qDebug() <<  "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize;
   756         #endif
   769         #endif
   757 
   770 
   758         int offset = manager->alloc(byteSize);
   771         int offset = manager->alloc(byteSize);
   759         if (offset >= 0) {
   772         if (offset >= 0) {
   760             #ifdef THEME_INDEX_TRACES
   773             #ifdef THEME_INDEX_TRACES
   761             qDebug() <<  "ThemeIndex: memory allocated for theme: " << theme.toUtf8();
   774             qDebug() <<  "ThemeIndex: memory allocated for theme: " << themeName.toUtf8();
   762             #endif
   775             #endif
   763 
   776 
   764             // Read the theme index in the shared chunk
   777             // Read the theme index in the shared chunk
   765             char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset);
   778             char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset);
   766 
   779 
   767             indexFile.read(address, byteSize);
   780             indexFile.read(address, byteSize);
   768             indexFile.close();
   781             indexFile.close();
   769 
   782 
   770             #ifdef THEME_INDEX_TRACES
   783             #ifdef THEME_INDEX_TRACES
   771             qDebug() <<  "ThemeIndex: Reading themeindex for theme" << theme.toUtf8() << "... Done!";
   784             qDebug() <<  "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!";
   772             #endif
   785             #endif
   773 
   786 
   774             // Verify theme index contents if it is not located in ROM,
   787             // Verify theme index contents if it is not located in ROM,
   775             // so that it does not have over-indexing offsets which might
   788             // so that it does not have over-indexing offsets which might
   776             // crash all the clients trying to read from it.
   789             // crash all the clients trying to read from it.
   777 
   790 
   778             if (themePath[0] != 'Z') {
   791             if (themePath[0] != 'z' && themePath[0] != 'Z') {
   779                 #ifdef THEME_INDEX_TRACES
   792                 #ifdef THEME_INDEX_TRACES
   780                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << theme.toUtf8();
   793                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8();
   781                 #endif
   794                 #endif
   782 
   795 
   783                 HbThemeIndex index(address);
   796                 HbThemeIndex index(address);
   784                 indexOK = index.validateItems(byteSize);
   797                 indexOK = index.validateItems(byteSize);
   785 
   798 
   786                 #ifdef THEME_INDEX_TRACES
   799                 #ifdef THEME_INDEX_TRACES
   787                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << theme.toUtf8() << " done! Result: " << indexOK;
   800                 qDebug() <<  "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK;
   788                 #endif
   801                 #endif
   789             }
   802             }
   790 
   803 
   791             if (indexOK) {
   804             if (indexOK) {
   792                 // Allocate theme path string from shared memory
   805                 // Allocate theme path string from shared memory
   920     qDebug() << "Just entered HbThemeServerSession::ServiceL";
   933     qDebug() << "Just entered HbThemeServerSession::ServiceL";
   921 #endif
   934 #endif
   922 
   935 
   923     TRAPD(err, DispatchMessageL(aMessage));
   936     TRAPD(err, DispatchMessageL(aMessage));
   924     aMessage.Complete(err);
   937     aMessage.Complete(err);
       
   938 
       
   939 #ifdef THEME_SERVER_TRACES
   925     QString er;
   940     QString er;
   926     er.setNum(err);
   941     er.setNum(err);
   927 
       
   928 #ifdef THEME_SERVER_TRACES
       
   929     qDebug() << "completed DispatchMessageL error code is " + er;
   942     qDebug() << "completed DispatchMessageL error code is " + er;
   930 #endif
   943 #endif
   931 
   944 
   932 }
   945 }
   933 
   946 
  1226         qDebug()<< "HbThemeServerSession::SwitchRenderingMode:GPU Memory After Switching to Software:" << sgImg->freeGPUMemory();
  1239         qDebug()<< "HbThemeServerSession::SwitchRenderingMode:GPU Memory After Switching to Software:" << sgImg->freeGPUMemory();
  1227 #endif //HB_ICON_CACHE_DEBUG            
  1240 #endif //HB_ICON_CACHE_DEBUG            
  1228     } 
  1241     } 
  1229 #endif
  1242 #endif
  1230 }
  1243 }
       
  1244 
  1231 /**
  1245 /**
  1232  * HandleStyleSheetLookupL
  1246  * HandleStyleSheetLookupL
  1233  */
  1247  */
  1234 void HbThemeServerSession::HandleStyleSheetLookupL(const RMessage2& aMessage)
  1248 void HbThemeServerSession::HandleStyleSheetLookupL(const RMessage2& aMessage)
  1235 {
  1249 {
  1238         qDebug() << "Empty Filename";
  1252         qDebug() << "Empty Filename";
  1239 #endif
  1253 #endif
  1240         return;
  1254         return;
  1241     }
  1255     }
  1242 
  1256 
  1243     TBuf<256> fileName;
  1257     TFileName fileName;
  1244     aMessage.ReadL(0, fileName, 0);
  1258     aMessage.ReadL(0, fileName, 0);
  1245     TBuf<256> layerPriorityBuf;
  1259     TBuf<256> layerPriorityBuf;
  1246     aMessage.ReadL(1, layerPriorityBuf, 0);
  1260     aMessage.ReadL(1, layerPriorityBuf, 0);
  1247     TLex lex(layerPriorityBuf);
  1261     TLex lex(layerPriorityBuf);
  1248     TInt priorityValue;
  1262     TInt priorityValue;
  1289     }
  1303     }
  1290     TPckg<HbSharedStyleSheetInfo> data(offsetInfo);
  1304     TPckg<HbSharedStyleSheetInfo> data(offsetInfo);
  1291     aMessage.WriteL(2, data);
  1305     aMessage.WriteL(2, data);
  1292 }
  1306 }
  1293 
  1307 
       
  1308 static const TInt KMaxLayoutName = 256;
       
  1309 static const TInt KMaxSectionName = 256;
       
  1310 
  1294 /**
  1311 /**
  1295  * HandleWidgetMLLookUp
  1312  * HandleWidgetMLLookUp
  1296  */
  1313  */
  1297 void HbThemeServerSession::HandleWidgetMLLookupL(const RMessage2& aMessage)
  1314 void HbThemeServerSession::HandleWidgetMLLookupL(const RMessage2& aMessage)
  1298 {
  1315 {
  1299     if (aMessage.GetDesLength(0) == 0) {
  1316     if (aMessage.GetDesLength(0) == 0) {
  1300         return;
  1317         return;
  1301     }
  1318     }
  1302 
  1319 
  1303     TBuf<256> fileName;
  1320     TFileName fileName;
  1304     aMessage.ReadL(0, fileName, 0);
  1321     aMessage.ReadL(0, fileName, 0);
  1305     TBuf<256> layoutName;
  1322     TBuf<KMaxLayoutName> layoutName;
  1306     aMessage.ReadL(1, layoutName, 0);
  1323     aMessage.ReadL(1, layoutName, 0);
  1307     TBuf<256> sectionName;
  1324     TBuf<KMaxSectionName> sectionName;
  1308     aMessage.ReadL(2, sectionName, 0);
  1325     aMessage.ReadL(2, sectionName, 0);
  1309 
  1326 
  1310     QString wmlFileName((QChar*)fileName.Ptr(), fileName.Length());
  1327     QString wmlFileName((QChar*)fileName.Ptr(), fileName.Length());
  1311     QString layout((QChar*)layoutName.Ptr(), layoutName.Length());
  1328     QString layout((QChar*)layoutName.Ptr(), layoutName.Length());
  1312     QString section((QChar*)sectionName.Ptr(), sectionName.Length());
  1329     QString section((QChar*)sectionName.Ptr(), sectionName.Length());
  1431             data.type = INVALID_FORMAT;
  1448             data.type = INVALID_FORMAT;
  1432         }
  1449         }
  1433     } else {
  1450     } else {
  1434         QT_TRY {
  1451         QT_TRY {
  1435             QString format = HbThemeServerUtils::formatFromPath(key.filename);
  1452             QString format = HbThemeServerUtils::formatFromPath(key.filename);
  1436 	        QScopedPointer <HbIconCacheItem> tempIconCacheItem(HbIconCacheItemCreator::createCacheItem( key,
  1453                 QScopedPointer <HbIconCacheItem> tempIconCacheItem(
  1437                                                                     (HbIconLoader::IconLoaderOptions)params.options,                                                                    
  1454                     HbIconCacheItemCreator::createCacheItem(key,
  1438                                                                     format,
  1455                         static_cast<HbIconLoader::IconLoaderOptions>(params.options),
  1439                                                                     iServer->currentRenderingMode()));
  1456                         format, iServer->currentRenderingMode()));
  1440             cacheItem = tempIconCacheItem.data();
  1457             cacheItem = tempIconCacheItem.data();
  1441             if (cacheItem) {
  1458             if (cacheItem) {
  1442                 if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1459                 if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1443                     data = cacheItem->rasterIconData;
  1460                     data = cacheItem->rasterIconData;
  1444                 } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1461                 } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1522         color.setRgba((QRgb)aRgba);
  1539         color.setRgba((QRgb)aRgba);
  1523     }
  1540     }
  1524     return color;
  1541     return color;
  1525 }
  1542 }
  1526 
  1543 
       
  1544 inline
       
  1545 QSize convert(const TSize &size)
       
  1546 {
       
  1547     return QSize(size.iWidth, size.iHeight);
       
  1548 }
       
  1549 inline
       
  1550 QRect convert(const TRect &rect)
       
  1551 {
       
  1552     return QRect(QPoint(rect.iTl.iX, rect.iTl.iY), QPoint(rect.iBr.iX, rect.iBr.iY));
       
  1553 }
       
  1554 
  1527 /**
  1555 /**
  1528  * HbThemeServerPrivate::GetSharedMultiIconInfoL
  1556  * HbThemeServerPrivate::GetSharedMultiIconInfoL
  1529   Creates a consolidated icon of the frame item pieces ,
  1557   Creates a consolidated icon of the frame item pieces ,
  1530   if failed to do so creates a icons of the pieces provided
  1558   if failed to do so creates a icons of the pieces provided
  1531   there is enough space in the cache and shared memory.
  1559   there is enough space in the cache and shared memory.
  1542     QString fullPath((QChar*)params.multiPartIconList[0].Ptr(), params.multiPartIconList[0].Length());
  1570     QString fullPath((QChar*)params.multiPartIconList[0].Ptr(), params.multiPartIconList[0].Length());
  1543     int index = fullPath.lastIndexOf("/");
  1571     int index = fullPath.lastIndexOf("/");
  1544     fullPath = fullPath.left(index + 1);
  1572     fullPath = fullPath.left(index + 1);
  1545     iconId.prepend(fullPath);
  1573     iconId.prepend(fullPath);
  1546     HbIconKey finalIconKey(iconId,
  1574     HbIconKey finalIconKey(iconId,
  1547                            (QSizeF)params.size,
  1575                            params.size,
  1548                            (Qt::AspectRatioMode)params.aspectRatioMode,
  1576                            static_cast<Qt::AspectRatioMode>(params.aspectRatioMode),
  1549                            (QIcon::Mode)params.mode,
  1577                            static_cast<QIcon::Mode>(params.mode),
  1550                            (bool)params.mirrored,
  1578                            params.mirrored,
  1551                            color,
  1579                            color,
  1552                            (HbRenderingMode)params.renderMode);
  1580                            static_cast<HbRenderingMode>(params.renderMode));
  1553 
  1581 
  1554     if (!IconInfoFromSingleIcon(finalIconKey, stitchedData)) {
  1582     if (!IconInfoFromSingleIcon(finalIconKey, stitchedData)) {
  1555         HbMultiIconParams frameItemParams;
  1583         HbMultiIconParams frameItemParams;
  1556         int noOfPieces = 1;
  1584         int noOfPieces = 1;
  1557         if (iconId.contains("_3PV", Qt::CaseInsensitive) || iconId.contains("_3PH", Qt::CaseInsensitive)) {
  1585         if (iconId.contains("_3PV", Qt::CaseInsensitive) || iconId.contains("_3PH", Qt::CaseInsensitive)) {
  1559         } else if (iconId.contains("_9P", Qt::CaseInsensitive)) {
  1587         } else if (iconId.contains("_9P", Qt::CaseInsensitive)) {
  1560             noOfPieces = 9;
  1588             noOfPieces = 9;
  1561         }
  1589         }
  1562 
  1590 
  1563         frameItemParams.multiPartIconId = iconId;
  1591         frameItemParams.multiPartIconId = iconId;
  1564         frameItemParams.aspectRatioMode = (Qt::AspectRatioMode)params.aspectRatioMode;
  1592         frameItemParams.aspectRatioMode = params.aspectRatioMode;
  1565         frameItemParams.colorflag = params.colorflag;
  1593         frameItemParams.colorflag = params.colorflag;
  1566         frameItemParams.mirrored = (bool)params.mirrored;
  1594         frameItemParams.mirrored = params.mirrored;
  1567         frameItemParams.options = params.options;
  1595         frameItemParams.options = params.options;
  1568         frameItemParams.rgba = params.rgba;
  1596         frameItemParams.rgba = params.rgba;
  1569         frameItemParams.mode = (QIcon::Mode)params.mode;
  1597         frameItemParams.mode = params.mode;
  1570         frameItemParams.size = (QSizeF)params.size;
  1598         frameItemParams.size = params.size;
  1571         frameItemParams.color = color;
  1599         frameItemParams.color = color;
  1572         frameItemParams.renderMode = params.renderMode;
  1600         frameItemParams.renderMode = params.renderMode;
  1573         QT_TRY {
  1601         QT_TRY {
  1574             for (int i = 0; i < noOfPieces; i++) {
  1602             for (int i = 0; i < noOfPieces; i++) {
  1575                 frameItemParams.multiPartIconData.pixmapSizes[i] = (QSize &)params.pixmapSizes[i];
  1603                 frameItemParams.multiPartIconData.pixmapSizes[i] = convert(params.pixmapSizes[i]);
  1576                 frameItemParams.multiPartIconData.targets[i] = (QRect &)params.targets[i];
  1604                 frameItemParams.multiPartIconData.targets[i] = convert(params.targets[i]);
  1577                 frameItemParams.multiPartIconData.sources[i] = (QRect &)params.sources[i];
  1605                 frameItemParams.multiPartIconData.sources[i] = convert(params.sources[i]);
  1578                 QString pieceName((QChar*)params.multiPartIconList[i].Ptr(), params.multiPartIconList[i].Length());
  1606                 QString pieceName((QChar*)params.multiPartIconList[i].Ptr(), params.multiPartIconList[i].Length());
  1579                 frameItemParams.multiPartIconList.append(pieceName);
  1607                 frameItemParams.multiPartIconList.append(pieceName);
  1580             }
  1608             }
  1581 
  1609 
  1582             IconInfoFromMultiParts(frameItemParams, noOfPieces, finalIconKey, stitchedData);
  1610             IconInfoFromMultiParts(frameItemParams, noOfPieces, finalIconKey, stitchedData);
  1969     TPckg<TIconListParams> paramPckg(params);
  1997     TPckg<TIconListParams> paramPckg(params);
  1970     // Copy the client's descriptor data into our buffer.
  1998     // Copy the client's descriptor data into our buffer.
  1971     aMessage.ReadL(0, paramPckg, 0);
  1999     aMessage.ReadL(0, paramPckg, 0);
  1972 
  2000 
  1973     QColor color = GetColorFromRgba(params.rgba, params.colorflag);
  2001     QColor color = GetColorFromRgba(params.rgba, params.colorflag);
  1974     Qt::AspectRatioMode aspectRatioMode = (Qt::AspectRatioMode)params.aspectRatioMode;
  2002     Qt::AspectRatioMode aspectRatioMode = static_cast<Qt::AspectRatioMode>(params.aspectRatioMode);
  1975     QIcon::Mode mode = (QIcon::Mode)params.mode;
  2003     QIcon::Mode mode = static_cast<QIcon::Mode>(params.mode);
  1976     TBool mirrored = params.mirrored;
  2004     TBool mirrored = params.mirrored;
  1977 
  2005 
  1978     TInt iconCount = params.iconCount;
  2006     TInt iconCount = params.iconCount;
  1979     for (int i = 0; i < iconCount; i++) {
  2007     for (int i = 0; i < iconCount; i++) {
  1980         QString filename((QChar*)params.iconList[i].Ptr(), params.iconList[i].Length());
  2008         QString filename((QChar*)params.iconList[i].Ptr(), params.iconList[i].Length());
  1981         HbIconKey key(filename, params.sizeList[i], aspectRatioMode, mode, mirrored, color, 
  2009         HbIconKey key(filename, params.sizeList[i], aspectRatioMode, mode, mirrored, color, 
  1982                                 (HbRenderingMode)params.renderMode);
  2010                                 static_cast<HbRenderingMode>(params.renderMode));
  1983         iServer->CleanupSessionIconItem(key);
  2011         iServer->CleanupSessionIconItem(key);
  1984         sessionData.removeOne(key);
  2012         sessionData.removeOne(key);
  1985     }
  2013     }
  1986 }
  2014 }
  1987 
  2015 
  2059 
  2087 
  2060     HbIconKey key(filename, QSizeF(params.width, params.height),
  2088     HbIconKey key(filename, QSizeF(params.width, params.height),
  2061                   (Qt::AspectRatioMode)params.aspectRatioMode,
  2089                   (Qt::AspectRatioMode)params.aspectRatioMode,
  2062                   (QIcon::Mode)params.mode, params.mirrored, color, (HbRenderingMode)params.renderMode);
  2090                   (QIcon::Mode)params.mode, params.mirrored, color, (HbRenderingMode)params.renderMode);
  2063 
  2091 
  2064     HbIconCacheItem* cacheItem = cache->value(key);//iconCacheItem(key);
  2092     HbIconCacheItem* cacheItem = cache->value(key);
  2065     if(cacheItem)
  2093     if(cacheItem)
  2066         refCount =  cacheItem->refCount;
  2094         refCount =  cacheItem->refCount;
  2067     else
  2095     else
  2068         refCount = 0;
  2096         refCount = 0;
  2069     return refCount;
  2097     return refCount;
  2070 }
  2098 }
  2071 #endif
  2099 #endif
  2072 
  2100 
  2073 #endif
  2101 #endif
  2074 
       
  2075 CHbThemeChangeNotificationListener* CHbThemeChangeNotificationListener::NewL(HbThemeServerPrivate& aObserver)
       
  2076 {
       
  2077     CHbThemeChangeNotificationListener* self = new (ELeave) CHbThemeChangeNotificationListener(aObserver);
       
  2078     CleanupStack::PushL(self);
       
  2079     self->ConstructL();
       
  2080     CleanupStack::Pop();
       
  2081     return self;
       
  2082 }
       
  2083 
       
  2084 CHbThemeChangeNotificationListener::CHbThemeChangeNotificationListener(HbThemeServerPrivate& aObserver)
       
  2085     :CActive(EPriorityStandard),iObserver(aObserver)
       
  2086 {
       
  2087 
       
  2088 }
       
  2089 
       
  2090 void CHbThemeChangeNotificationListener::ConstructL()
       
  2091 {
       
  2092     TInt err = RProperty::Define( KServerUid3, KNewThemeForThemeChanger, RProperty::ELargeText, KAllowAllPolicy, KThemeChangerPolicy );
       
  2093      if ( err != KErrAlreadyExists ) {
       
  2094          User::LeaveIfError( err );
       
  2095      }
       
  2096     err = themeRequestProp.Attach(KServerUid3, KNewThemeForThemeChanger );
       
  2097     User::LeaveIfError(err);
       
  2098 
       
  2099     CActiveScheduler::Add(this);
       
  2100 }
       
  2101 
       
  2102 CHbThemeChangeNotificationListener::~CHbThemeChangeNotificationListener()
       
  2103 {
       
  2104     stopListening();
       
  2105 }
       
  2106 
       
  2107 void CHbThemeChangeNotificationListener::startListening()
       
  2108 {
       
  2109     if (IsActive()) {
       
  2110          return; //do nothing if allready listening
       
  2111     }
       
  2112 
       
  2113     User::LeaveIfError(themeRequestProp.Attach(KServerUid3,KNewThemeForThemeChanger));
       
  2114     //Subscribe for updates
       
  2115     themeRequestProp.Subscribe(iStatus);
       
  2116 
       
  2117     SetActive();
       
  2118 
       
  2119 }
       
  2120 
       
  2121 void CHbThemeChangeNotificationListener::stopListening()
       
  2122 {
       
  2123      Cancel(); // cancel
       
  2124      if(IsActive()) { // only if already listening
       
  2125         themeRequestProp.Close(); // Close the handle since it is not needed anymore
       
  2126    }
       
  2127 }
       
  2128 
       
  2129 /*
       
  2130  * Returns TRUE if parsing succeeded, FALSE otherwise
       
  2131  */
       
  2132 bool CHbThemeChangeNotificationListener::parseData( TDesC& requestData, HbThemeServerRequest& etype, TDes& data)
       
  2133 {
       
  2134     TInt result = 0;
       
  2135     const TChar delimiter = ':';
       
  2136     // initialize return value as failed
       
  2137     bool bSuccess = false;
       
  2138 
       
  2139     result = requestData.Locate( delimiter );
       
  2140     if( KErrNotFound != result ) {
       
  2141         TInt len = requestData.Length();
       
  2142         const TDesC& typestr = requestData.Mid( 0, result);
       
  2143         TLex atype ( typestr );
       
  2144         TInt iType;
       
  2145         atype.Val( iType );
       
  2146         etype = static_cast<HbThemeServerRequest>(iType);
       
  2147         data.Copy( requestData.Mid( result + 1, len - result - 1 ) );
       
  2148         bSuccess = true;
       
  2149     } else {
       
  2150         bSuccess = false;
       
  2151     }
       
  2152 
       
  2153     return bSuccess;
       
  2154 }
       
  2155 
       
  2156 void CHbThemeChangeNotificationListener::RunL()
       
  2157 {
       
  2158     // Subscribe first to make sure we don't miss any
       
  2159     // when handling this one.
       
  2160     themeRequestProp.Subscribe(iStatus);
       
  2161 
       
  2162     SetActive();
       
  2163 
       
  2164     TBuf<256> requestData;
       
  2165     TInt ret = themeRequestProp.Get(requestData);
       
  2166     switch (ret) {
       
  2167         case KErrNone:
       
  2168             {
       
  2169                 QString qrequestData((QChar*)requestData.Ptr(),requestData.Length());
       
  2170                 HbThemeServerRequest etype = EInvalidServerRequest;
       
  2171                 TBuf<256> data;
       
  2172                 ///Parse the data from the Publisher
       
  2173                 bool bSuccess = parseData( requestData, etype, data);
       
  2174                 if( bSuccess && EThemeSelection == etype) {
       
  2175                     QString str((QChar*)data.Ptr(),data.Length());
       
  2176                     str = str.trimmed();
       
  2177                     iObserver.HandleThemeSelection( str );
       
  2178                 }
       
  2179             }
       
  2180             break;
       
  2181         case KErrPermissionDenied:
       
  2182             qDebug() << "KErrPermissionDenied";
       
  2183             break;
       
  2184         case KErrNotFound:
       
  2185             qDebug() << "KErrNotFound";
       
  2186             break;
       
  2187         case KErrArgument:
       
  2188             qDebug() << "KErrArgument";
       
  2189             break;
       
  2190         case KErrOverflow:
       
  2191             qDebug() << "KErrOverflow";
       
  2192             break;
       
  2193     }
       
  2194 }
       
  2195 
       
  2196 void CHbThemeChangeNotificationListener::DoCancel()
       
  2197 {
       
  2198     themeRequestProp.Cancel();
       
  2199 }
       
  2200 
       
  2201 
       
  2202