src/hbservers/hbthemeserver/hbthemeserver_generic.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    49 #include "hbcache_p.h"
    49 #include "hbcache_p.h"
    50 #include "hbdeviceprofiledatabase_p.h"
    50 #include "hbdeviceprofiledatabase_p.h"
    51 #include "hbpixmapiconimpl_p.h"
    51 #include "hbpixmapiconimpl_p.h"
    52 #include "hbpixmapiconprocessor_p.h"
    52 #include "hbpixmapiconprocessor_p.h"
    53 #include "hblayeredstyleloader_p.h"
    53 #include "hblayeredstyleloader_p.h"
       
    54 #include "hbthemesystemeffect_p.h"
       
    55 #include "hbsharedmemorymanager_p.h"
    54 
    56 
    55 /*!
    57 /*!
    56   @hbserver
    58   @hbserver
    57   \class HbThemeServerPrivate
    59   \class HbThemeServerPrivate
    58   \brief HbThemeServerPrivate implements the theme server
    60   \brief HbThemeServerPrivate implements the theme server
   243 #ifdef THEME_SERVER_TRACES
   245 #ifdef THEME_SERVER_TRACES
   244     qDebug() << Q_FUNC_INFO << "  theme=" << newTheme;
   246     qDebug() << Q_FUNC_INFO << "  theme=" << newTheme;
   245 #endif
   247 #endif
   246     // Modify the QSettings to store the applied theme
   248     // Modify the QSettings to store the applied theme
   247     QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT));
   249     QSettings settings(QLatin1String(ORGANIZATION), QLatin1String(THEME_COMPONENT));
   248     QString prevTheme = settings.value("currenttheme").toString();
   250     QString prevTheme = settings.value(CURRENT_THEME_KEY).toString();
   249     if (prevTheme == newTheme) {
   251     if (prevTheme == newTheme) {
   250         // Theme did not change, return.
   252         // Theme did not change, return.
   251         return;
   253         return;
   252     }
   254     }
       
   255     // Clear cached icons and session data
       
   256     clearIconCache();
       
   257     HbThemeServerSession *session;
       
   258     foreach(session, sessionList) {
       
   259         session->clearSessionIconData();
       
   260     }
       
   261 
   253     QString cleanThemeName = newTheme.trimmed();
   262     QString cleanThemeName = newTheme.trimmed();
   254     settings.setValue("currenttheme", cleanThemeName);
   263     settings.remove("currenttheme"); //temporary
       
   264     settings.setValue(CURRENT_THEME_KEY, cleanThemeName);
   255     settings.sync();
   265     settings.sync();
       
   266 
       
   267     // Register new system effects
       
   268     HbThemeSystemEffect::handleThemeChange(cleanThemeName);
       
   269 
   256     HbThemeServerRequest requestType;
   270     HbThemeServerRequest requestType;
   257     requestType = EThemeSelection;
   271     requestType = EThemeSelection;
   258     QByteArray block;
   272     QByteArray block;
   259     QDataStream out(&block, QIODevice::WriteOnly);
   273     QDataStream out(&block, QIODevice::WriteOnly);
   260     out << (int)requestType;
   274     out << (int)requestType;
   261     out << cleanThemeName;
   275     out << cleanThemeName;
   262     writeToClients(block);
   276     writeToClients(block);
       
   277 }
       
   278 
       
   279 void HbThemeServerPrivate::handleContentUpdate(const QStringList &fileNames)
       
   280 {
       
   281     // If list is empty clear all themed content
       
   282     if (!fileNames.count()) {
       
   283         // Clear icons
       
   284         HbThemeServerSession *session;
       
   285         foreach(session, sessionList) {
       
   286             session->clearSessionIconData();
       
   287         }
       
   288         iconCache->clear();
       
   289 
       
   290         // Clear effects
       
   291         HbThemeServerUtils::clearSharedEffects();
       
   292 
       
   293         // Clear stylesheets
       
   294         QHash<QString, HbCacheItem*>::const_iterator itEnd(themePriorityItems.constEnd());
       
   295         for (QHash<QString, HbCacheItem*>::const_iterator iter = themePriorityItems.constBegin();
       
   296                 iter != itEnd;
       
   297                 ++iter) {
       
   298             cssCache->cacheHandle().remove(iter.key());
       
   299             HbThemeServerSession *session;
       
   300             foreach(session, sessionList) {
       
   301                 session->removeSessionCssItem(iter.key());
       
   302             }
       
   303         }
       
   304         themePriorityItems.clear();
       
   305 
       
   306         return;
       
   307     }
       
   308 
       
   309     // Else delete only specified files
       
   310     for (int i=0; i<fileNames.count();i++) {
       
   311         QString filename = fileNames.at(i);
       
   312 
       
   313         // Stylesheet
       
   314         if (themePriorityItems.contains(filename)) {
       
   315             cssCache->cacheHandle().remove(filename);
       
   316             themePriorityItems.remove(filename);
       
   317             HbThemeServerSession *session;
       
   318             foreach(session, sessionList) {
       
   319                 session->removeSessionCssItem(filename);
       
   320             }
       
   321             break;
       
   322         }
       
   323         // Effect
       
   324         if (HbThemeServerUtils::removeSharedEffect(filename)) {
       
   325             break;
       
   326         }
       
   327 
       
   328         // Icon
       
   329         QVector<const HbIconKey *> keys = iconCache->getKeys(filename);
       
   330         for (int j = 0; j<keys.count();j++) {
       
   331             HbThemeServerSession *session;
       
   332             foreach(session, sessionList) {
       
   333                 session->removeSessionIconItem(*keys.at(j));
       
   334             }
       
   335             iconCache->remove(*keys.at(j),false);
       
   336         }
       
   337     }
   263 }
   338 }
   264 
   339 
   265 /*!
   340 /*!
   266   \fn HbThemeServerPrivate::writeToClients()
   341   \fn HbThemeServerPrivate::writeToClients()
   267   Write to all clients
   342   Write to all clients
   575             iServer->setThemeSelectionClient(themeSelectionClient);
   650             iServer->setThemeSelectionClient(themeSelectionClient);
   576             iServer->handleThemeSelection(themename);
   651             iServer->handleThemeSelection(themename);
   577             break;
   652             break;
   578         }
   653         }
   579         case EThemeContentUpdate: {
   654         case EThemeContentUpdate: {
   580             iServer->clearIconCache();
   655             QStringList themedItems;
       
   656             inputDataStream >> themedItems;
       
   657             iServer->handleContentUpdate(themedItems);
   581             HbThemeServerRequest requestType = EThemeContentUpdate;
   658             HbThemeServerRequest requestType = EThemeContentUpdate;
   582             QByteArray block;
   659             QByteArray block;
   583             QDataStream out(&block, QIODevice::WriteOnly);
   660             QDataStream out(&block, QIODevice::WriteOnly);
   584             out << (int)requestType;
   661             out << (int)requestType;
       
   662             out << themedItems;
   585             iServer->writeToClients(block);
   663             iServer->writeToClients(block);
   586             break;
   664             break;
   587         }
   665         }
   588         case EThemeServerStop: {
   666         case EThemeServerStop: {
   589             //This segment is used by HbThemeApiWrapperUi.
   667             //This segment is used by HbThemeApiWrapperUi.
   718             inputDataStream >> mirrored;
   796             inputDataStream >> mirrored;
   719             inputDataStream >> options;
   797             inputDataStream >> options;
   720             inputDataStream >> color;
   798             inputDataStream >> color;
   721 
   799 
   722 #ifdef THEME_SERVER_TRACES
   800 #ifdef THEME_SERVER_TRACES
   723             qDebug() << "image req at server: " << filename;
   801             qDebug() << "image req at server: " << fileList;
   724 #endif
   802 #endif
   725             QByteArray output;
   803             QByteArray output;
   726             for (int i = 0; i < fileList.count(); i++) {
   804             for (int i = 0; i < fileList.count(); i++) {
   727                 HbIconKey key(fileList[i], sizeList[i], (Qt::AspectRatioMode)aspectRatioMode, (QIcon::Mode)mode, mirrored, color);
   805                 HbIconKey key(fileList[i], sizeList[i],
       
   806                               static_cast<Qt::AspectRatioMode>(aspectRatioMode),
       
   807                               static_cast<QIcon::Mode>(mode), mirrored, color);
   728                 output.append(handleIconLookup(key, data, options));
   808                 output.append(handleIconLookup(key, data, options));
   729             }
   809             }
   730 
   810 
   731             ((QLocalSocket *)sender())->write(output);
   811             ((QLocalSocket *)sender())->write(output);
   732 
   812 
       
   813             break;
       
   814         }
       
   815         case ENotifyForegroundLost: {
       
   816             //Nothing to do here when the app notifies it's foreground lost event
   733             break;
   817             break;
   734         }
   818         }
   735         //Debug Code for Test Purpose
   819         //Debug Code for Test Purpose
   736 #ifdef HB_ICON_CACHE_DEBUG
   820 #ifdef HB_ICON_CACHE_DEBUG
   737         case ECacheIconCount: {
   821         case ECacheIconCount: {
   855                 QDataStream outputDataStream(&outputByteArray, QIODevice::WriteOnly);
   939                 QDataStream outputDataStream(&outputByteArray, QIODevice::WriteOnly);
   856                 outputDataStream << (int)requestType;
   940                 outputDataStream << (int)requestType;
   857                 ((QLocalSocket *)sender())->write(outputByteArray);
   941                 ((QLocalSocket *)sender())->write(outputByteArray);
   858                 break;
   942                 break;
   859             }
   943             }
       
   944         case EFreeSharedMem: {
       
   945             int freeSharedMem = iServer->freeSharedMemory();
       
   946             QByteArray outputByteArray;
       
   947             QDataStream outputDataStream(&outputByteArray, QIODevice::WriteOnly);
       
   948             outputDataStream << requestType;
       
   949             outputDataStream << freeSharedMem;
       
   950             ((QLocalSocket *)sender())->write(outputByteArray);
       
   951             break;
       
   952         }
       
   953         case EAllocatedSharedMem: {
       
   954             int allocatedSharedMem = iServer->allocatedSharedMemory();
       
   955             QByteArray outputByteArray;
       
   956             QDataStream outputDataStream(&outputByteArray, QIODevice::WriteOnly);
       
   957             outputDataStream << requestType;
       
   958             outputDataStream << allocatedSharedMem;
       
   959             ((QLocalSocket *)sender())->write(outputByteArray);
       
   960             break;
       
   961         }
       
   962 
   860         default:
   963         default:
   861             break;
   964             break;
   862         }
   965         }
   863     }
   966     }
   864 }
   967 }
   930     }
  1033     }
   931     bool insertKeyIntoSessionList = false;
  1034     bool insertKeyIntoSessionList = false;
   932     stitchedData.type = INVALID_FORMAT;
  1035     stitchedData.type = INVALID_FORMAT;
   933     QString format = HbThemeServerUtils::formatFromPath(params.multiPartIconList[0]);
  1036     QString format = HbThemeServerUtils::formatFromPath(params.multiPartIconList[0]);
   934 
  1037 
   935     QScopedPointer <HbPixmapIconProcessor> tempIconProcessor(new HbPixmapIconProcessor(finalIconKey, (HbIconLoader::IconLoaderOptions)params.options, format));
  1038     QScopedPointer <HbPixmapIconProcessor> tempIconProcessor(new HbPixmapIconProcessor(finalIconKey,
       
  1039                                                 static_cast<HbIconLoader::IconLoaderOptions>(params.options), format));
   936     HbPixmapIconProcessor * rasterIcon = tempIconProcessor.data();
  1040     HbPixmapIconProcessor * rasterIcon = tempIconProcessor.data();
   937     rasterIcon->createMultiPieceIconData(dataForParts, params);
  1041     rasterIcon->createMultiPieceIconData(dataForParts, params);
   938 
  1042 
   939     QScopedPointer <HbIconCacheItem> tempIconCacheItem;
  1043     QScopedPointer <HbIconCacheItem> tempIconCacheItem;
   940     tempIconCacheItem.reset(HbIconCacheItemCreator::createCacheItem(finalIconKey, (HbIconLoader::IconLoaderOptions)params.options, format, false));
  1044     tempIconCacheItem.reset(HbIconCacheItemCreator::createCacheItem(finalIconKey,
       
  1045                                     static_cast<HbIconLoader::IconLoaderOptions>(params.options), format, false));
   941     cacheItem = tempIconCacheItem.data();
  1046     cacheItem = tempIconCacheItem.data();
   942 
  1047 
   943     cacheItem->rasterIconData = rasterIcon->sharedIconData();
  1048     cacheItem->rasterIconData = rasterIcon->sharedIconData();
   944     cacheItem->rasterIconDataCost = rasterIcon->sharedIconDataCost();
  1049     cacheItem->rasterIconDataCost = rasterIcon->sharedIconDataCost();
   945     stitchedData = cacheItem->rasterIconData;
  1050     stitchedData = cacheItem->rasterIconData;
   950             freeDataFromCacheItem(cacheItem);
  1055             freeDataFromCacheItem(cacheItem);
   951             stitchedData.type = INVALID_FORMAT;
  1056             stitchedData.type = INVALID_FORMAT;
   952         }
  1057         }
   953     }
  1058     }
   954     tempIconCacheItem.take();
  1059     tempIconCacheItem.take();
   955     delete rasterIcon;
       
   956     return insertKeyIntoSessionList;
  1060     return insertKeyIntoSessionList;
   957 }
  1061 }
   958 
  1062 
   959 
  1063 
   960 /*!
  1064 /*!
   970     QVector<HbIconKey> keysInserted;
  1074     QVector<HbIconKey> keysInserted;
   971     QVector<HbSharedIconInfo>  dataForParts;
  1075     QVector<HbSharedIconInfo>  dataForParts;
   972     bool insertKeyIntoSessionList = false;
  1076     bool insertKeyIntoSessionList = false;
   973     bool failedToCreateParts = false;
  1077     bool failedToCreateParts = false;
   974     QString format;
  1078     QString format;
   975 
  1079     try {
   976 
  1080         for (int i = 0; i < noOfPieces; i++) {
   977     for (int i = 0; i < noOfPieces; i++) {
  1081             HbSharedIconInfo data;
   978         HbSharedIconInfo data;
  1082             bool iconPieceMirrored = false;
   979         bool iconPieceMirrored = false;
  1083             HbIconKey key(params.multiPartIconList.at(i), params.multiPartIconData.pixmapSizes[i],
   980         HbIconKey key(params.multiPartIconList.at(i), params.multiPartIconData.pixmapSizes[i], (Qt::AspectRatioMode)stichedKey.aspectRatioMode, (QIcon::Mode)stichedKey.mode, iconPieceMirrored, stichedKey.color);
  1084                           static_cast<Qt::AspectRatioMode>(stichedKey.aspectRatioMode),
   981         insertKeyIntoSessionList = iconInfoFromSingleIcon(key, data);
  1085                           static_cast<QIcon::Mode>(stichedKey.mode), iconPieceMirrored, stichedKey.color);
   982         if (!insertKeyIntoSessionList) {
  1086             insertKeyIntoSessionList = iconInfoFromSingleIcon(key, data);
   983             insertKeyIntoSessionList = createCacheItemData(key, params.options, data);
  1087             if (!insertKeyIntoSessionList) {
   984         }
  1088                 insertKeyIntoSessionList = createCacheItemData(key, params.options, data);
   985         if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) {
  1089             }
   986             failedToCreateParts = true;
  1090             if ((data.type == INVALID_FORMAT) || (!insertKeyIntoSessionList)) {
   987             break;
  1091                 failedToCreateParts = true;
   988         } else {
  1092                 break;
   989             //The session will only keep track of icons that were either successfully found or were
  1093             } else {
   990             //successfully inserted in the cache.
  1094                 //The session will only keep track of icons that were either successfully found or were
   991             keysInserted.append(key);
  1095                 //successfully inserted in the cache.
   992             dataForParts.append(data);
  1096                 keysInserted.append(key);
   993             sessionIconData.append(key);
  1097                 dataForParts.append(data);
   994         }
  1098                 sessionIconData.append(key);
   995     }//end of for
  1099             }
       
  1100         }//end of for
       
  1101     } catch(std::exception &) {
       
  1102         failedToCreateParts = true;
       
  1103     }
   996 
  1104 
   997     if ((failedToCreateParts) || (dataForParts.count() != noOfPieces) || (!insertKeyIntoSessionList)) {
  1105     if ((failedToCreateParts) || (dataForParts.count() != noOfPieces) || (!insertKeyIntoSessionList)) {
   998         //atLeast one of the icon did'nt get constructed , so move the cached piece icons to unused state and return
  1106         //atLeast one of the icon did'nt get constructed , so move the cached piece icons to unused state and return
   999         for (int i = 0; i < keysInserted.count(); i++) {
  1107         for (int i = 0; i < keysInserted.count(); i++) {
  1000             sessionIconData.removeOne(keysInserted.at(i));
  1108             sessionIconData.removeOne(keysInserted.at(i));
  1003         stitchedData.type = INVALID_FORMAT;
  1111         stitchedData.type = INVALID_FORMAT;
  1004         return;
  1112         return;
  1005     }
  1113     }
  1006 // Create a stitched icon of the available piece shared iconinfos
  1114 // Create a stitched icon of the available piece shared iconinfos
  1007     if ((dataForParts.count() == noOfPieces) && (!failedToCreateParts)) {
  1115     if ((dataForParts.count() == noOfPieces) && (!failedToCreateParts)) {
  1008         if (createStichedIconInfoOfParts(dataForParts, params, stichedKey, stitchedData)) {
  1116         try {
  1009             sessionIconData.append(stichedKey);
  1117             if (createStichedIconInfoOfParts(dataForParts, params, stichedKey, stitchedData)) {
       
  1118                 sessionIconData.append(stichedKey);
       
  1119             }
       
  1120         } catch(std::exception &) {
  1010         }
  1121         }
  1011     }
  1122     }
  1012 // Move the keys created for pieces to unused state*/
  1123 // Move the keys created for pieces to unused state*/
  1013     for (int i = 0; i < keysInserted.count(); i++) {
  1124     for (int i = 0; i < keysInserted.count(); i++) {
  1014         sessionIconData.removeOne(keysInserted.at(i));
  1125         sessionIconData.removeOne(keysInserted.at(i));
  1015     }
  1126     }
       
  1127 }
       
  1128 
       
  1129 /*!
       
  1130   \fn HbThemeServerSession::clearSessionIconData()
       
  1131   Clears the session data of the icons found in the cache.
       
  1132 */
       
  1133 void HbThemeServerSession::clearSessionIconData()
       
  1134 {
       
  1135     sessionIconData.clear();
       
  1136 }
       
  1137 
       
  1138 void HbThemeServerSession::removeSessionIconItem(const HbIconKey &key)
       
  1139 {
       
  1140     sessionIconData.removeAll(key);
       
  1141 }
       
  1142 
       
  1143 void HbThemeServerSession::removeSessionCssItem(const QString &key)
       
  1144 {
       
  1145     sessionCssData.removeAll(key);
  1016 }
  1146 }
  1017 
  1147 
  1018 /*!
  1148 /*!
  1019   \fn HbThemeServerSession::freeDataFromCacheItem()
  1149   \fn HbThemeServerSession::freeDataFromCacheItem()
  1020   Frees data from the cached item when insertion to the list fails.
  1150   Frees data from the cached item when insertion to the list fails.
  1166                 if (priority == HbLayeredStyleLoader::Priority_Core && cssItem->refCount == 1) {
  1296                 if (priority == HbLayeredStyleLoader::Priority_Core && cssItem->refCount == 1) {
  1167                     // This will make sure the requested stylesheet will always remain
  1297                     // This will make sure the requested stylesheet will always remain
  1168                     // in the primary and secondary cache.
  1298                     // in the primary and secondary cache.
  1169                     cssItem->incrementRefCount();
  1299                     cssItem->incrementRefCount();
  1170                 }
  1300                 }
       
  1301                 if (priority == HbLayeredStyleLoader::Priority_Theme && cssItem->refCount == 1) {
       
  1302                     iServer->themePriorityItems.insert(fileName,cssItem);
       
  1303                 }
  1171                 break;
  1304                 break;
  1172             } else if (offset == OUT_OF_MEMORY_ERROR && tryAgain == false) {
  1305             } else if (offset == OUT_OF_MEMORY_ERROR && tryAgain == false) {
  1173                 iServer->doCleanup();
  1306                 iServer->doCleanup();
  1174                 tryAgain = true;
  1307                 tryAgain = true;
  1175             } else if (offset == OUT_OF_MEMORY_ERROR && tryAgain == true) {
  1308             } else if (offset == OUT_OF_MEMORY_ERROR && tryAgain == true) {
  1218         }
  1351         }
  1219     } else {
  1352     } else {
  1220         QString format = HbThemeServerUtils::formatFromPath(key.filename);
  1353         QString format = HbThemeServerUtils::formatFromPath(key.filename);
  1221         QT_TRY {
  1354         QT_TRY {
  1222             tempIconCacheItem.reset(HbIconCacheItemCreator::createCacheItem(key,
  1355             tempIconCacheItem.reset(HbIconCacheItemCreator::createCacheItem(key,
  1223             (HbIconLoader::IconLoaderOptions)options,
  1356                 (HbIconLoader::IconLoaderOptions)options,
  1224             format,
  1357                 format,
  1225             false));
  1358                 false));
  1226             cacheItem = tempIconCacheItem.data();
  1359             cacheItem = tempIconCacheItem.data();
  1227             if (cacheItem) {
  1360             if (cacheItem) {
  1228                 if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1361                 if (cacheItem->rasterIconData.type != INVALID_FORMAT) {
  1229                     data = cacheItem->rasterIconData;
  1362                     data = cacheItem->rasterIconData;
  1230                 } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1363                 } else if (cacheItem->vectorIconData.type != INVALID_FORMAT) {
  1310 int HbThemeServerPrivate::sessionListCount() const
  1443 int HbThemeServerPrivate::sessionListCount() const
  1311 {
  1444 {
  1312     return sessionList.count();
  1445     return sessionList.count();
  1313 }
  1446 }
  1314 
  1447 
       
  1448 /**
       
  1449  * HbThemeServerPrivate::freeSharedMemory()
       
  1450  * Gives the free shared memory.
       
  1451  */
       
  1452 int HbThemeServerPrivate::freeSharedMemory() const
       
  1453 {
       
  1454     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
       
  1455     return static_cast<HbSharedMemoryManager *>(manager)->freeSharedMemory();
       
  1456 }
       
  1457 
       
  1458 /**
       
  1459  * HbThemeServerPrivate::allocatedSharedMemory()
       
  1460  * Gives the allocated shared memory.
       
  1461  */
       
  1462 int HbThemeServerPrivate::allocatedSharedMemory() const
       
  1463 {
       
  1464     GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory);
       
  1465     return static_cast<HbSharedMemoryManager *>(manager)->allocatedSharedMemory();
       
  1466 }