106 // Store the active theme name in a member string |
106 // Store the active theme name in a member string |
107 iCurrentThemeName = HbThemeUtils::getThemeSetting(HbThemeUtils::CurrentThemeSetting); |
107 iCurrentThemeName = HbThemeUtils::getThemeSetting(HbThemeUtils::CurrentThemeSetting); |
108 |
108 |
109 if (iCurrentThemeName.isEmpty()) { |
109 if (iCurrentThemeName.isEmpty()) { |
110 iCurrentThemeName = HbThemeUtils::defaultTheme().name; |
110 iCurrentThemeName = HbThemeUtils::defaultTheme().name; |
111 // Set the current theme also in the cenrep key that is used to notify clients. |
|
112 HbThemeUtils::setThemeSetting(HbThemeUtils::CurrentThemeSetting, iCurrentThemeName); |
|
113 } |
111 } |
114 |
112 |
115 // Cache ROM theme(name)s |
113 // Cache ROM theme(name)s |
116 QString romPath = "Z:\\resource\\hb\\themes\\icons\\"; |
114 QString romPath = "Z:\\resource\\hb\\themes\\icons\\"; |
117 QDir dir(romPath); |
115 QDir dir(romPath); |
118 romThemeNames = dir.entryList(QDir::Dirs); |
116 romThemeNames = dir.entryList(QDir::Dirs); |
|
117 |
|
118 // Resolve the path of the current theme |
|
119 QDir path(iCurrentThemeName); |
|
120 if (!path.isAbsolute()) { |
|
121 // Resolve the path of the current theme |
|
122 resolveThemePath(iCurrentThemeName, iCurrentThemePath); |
|
123 } else { |
|
124 iCurrentThemeName = path.dirName(); |
|
125 iCurrentThemePath = path.absolutePath(); |
|
126 } |
119 |
127 |
120 // Resolve the path of the current theme |
|
121 resolveThemePath(iCurrentThemeName, iCurrentThemePath); |
|
122 |
|
123 // Register theme system effects in construction |
|
124 // TODO: fix parameter |
|
125 HbThemeSystemEffect::handleThemeChange(iCurrentThemeName); |
|
126 |
|
127 // Open index file to prevent uninstallation of the active theme |
128 // Open index file to prevent uninstallation of the active theme |
128 if (!openCurrentIndexFile()) { |
129 if (!openCurrentIndexFile()) { |
129 // theme doesn't exist activate default theme |
130 // theme doesn't exist activate default theme |
130 iCurrentThemeName = HbThemeUtils::defaultTheme().name; |
131 iCurrentThemeName = HbThemeUtils::defaultTheme().name; |
131 resolveThemePath(iCurrentThemeName, iCurrentThemePath); |
132 resolveThemePath(iCurrentThemeName, iCurrentThemePath); |
152 #endif |
153 #endif |
153 |
154 |
154 // Process base theme index, it is used as parent index also when the current theme is something else |
155 // Process base theme index, it is used as parent index also when the current theme is something else |
155 QString basePath; |
156 QString basePath; |
156 resolveThemePath(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting), basePath); |
157 resolveThemePath(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting), basePath); |
157 createThemeIndex(basePath, BaseTheme); |
158 |
|
159 HbThemeServerUtils::createThemeIndex(basePath, BaseTheme); |
158 // Process operator theme indexes |
160 // Process operator theme indexes |
159 QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting); |
161 QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting); |
160 if (!operatorName.isEmpty()) { |
162 if (!operatorName.isEmpty()) { |
161 QString operatorPath; |
163 QString operatorPath; |
162 operatorPath.append(KOperatorCPath); |
164 operatorPath.append(KOperatorCPath); |
163 operatorPath.append(operatorName); |
165 operatorPath.append(operatorName); |
164 createThemeIndex(operatorPath, OperatorC); |
166 HbThemeServerUtils::createThemeIndex(operatorPath, OperatorC); |
165 // Process operator Drive Z theme index |
167 // Process operator Drive Z theme index |
166 QString operatorROMPath; |
168 QString operatorROMPath; |
167 operatorROMPath.append(KOperatorZPath); |
169 operatorROMPath.append(KOperatorZPath); |
168 operatorROMPath.append(operatorName); |
170 operatorROMPath.append(operatorName); |
169 createThemeIndex(operatorROMPath, OperatorROM); |
171 HbThemeServerUtils::createThemeIndex(operatorROMPath, OperatorROM); |
170 } |
172 } |
171 // Process current theme index |
173 // Process current theme index |
172 createThemeIndex(iCurrentThemePath, ActiveTheme); |
174 HbThemeServerUtils::createThemeIndex(iCurrentThemePath, ActiveTheme); |
173 |
175 |
|
176 // Register theme system effects in construction |
|
177 // TODO: fix parameter |
|
178 HbThemeSystemEffect::handleThemeChange(iCurrentThemeName); |
|
179 |
|
180 // Set the current theme also in the cenrep key that is used to notify clients. |
|
181 HbThemeUtils::setThemeSetting(HbThemeUtils::CurrentThemeSetting, iCurrentThemePath); |
|
182 |
174 // Temporary hack for pre-loading app. background graphics in server startup to give more realistic |
183 // Temporary hack for pre-loading app. background graphics in server startup to give more realistic |
175 // results in performance tests. (Normally these graphics get loaded anyway when the first hb app is started.) |
184 // results in performance tests. (Normally these graphics get loaded anyway when the first hb app is started.) |
176 #ifndef HB_NVG_CS_ICON |
185 #ifndef HB_NVG_CS_ICON |
177 QProcess::startDetached("hbiconpreloader.exe"); |
186 QProcess::startDetached("hbiconpreloader.exe"); |
178 #endif |
187 #endif |
347 QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting); |
359 QString operatorName = HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting); |
348 if (!operatorName.isEmpty()) { |
360 if (!operatorName.isEmpty()) { |
349 QString operatorPath; |
361 QString operatorPath; |
350 operatorPath.append(KOperatorCPath); |
362 operatorPath.append(KOperatorCPath); |
351 operatorPath.append(operatorName); |
363 operatorPath.append(operatorName); |
352 createThemeIndex(operatorPath, OperatorC); |
364 HbThemeServerUtils::createThemeIndex(operatorPath, OperatorC); |
353 } |
365 } |
354 // Process current theme index |
366 // Process current theme index |
355 createThemeIndex(iCurrentThemePath, ActiveTheme); |
367 HbThemeServerUtils::createThemeIndex(iCurrentThemePath, ActiveTheme); |
356 |
368 |
357 // Clear cached icons and session data |
369 // Clear cached icons and session data |
358 clearIconCache(); |
370 clearIconCache(); |
359 iSessionIter.SetToFirst(); |
371 iSessionIter.SetToFirst(); |
360 while(iSessionIter) { |
372 while(iSessionIter) { |
725 */ |
729 */ |
726 void HbThemeServerPrivate::doCleanup() |
730 void HbThemeServerPrivate::doCleanup() |
727 { |
731 { |
728 HbThemeServerUtils::cleanupUnusedCss(cssCache); |
732 HbThemeServerUtils::cleanupUnusedCss(cssCache); |
729 } |
733 } |
730 |
|
731 void HbThemeServerPrivate::createThemeIndex(const QString &themePath, const HbThemeType &themetype) |
|
732 { |
|
733 #ifdef THEME_INDEX_TRACES |
|
734 qDebug() << "ThemeIndex: createThemeIndex" << themePath.toUtf8(); |
|
735 #endif |
|
736 QDir themeBasePath(themePath); |
|
737 // Path is like "C:/resource/hb/themes/icons/sfwhitetheme" |
|
738 QString themeName = themeBasePath.dirName(); |
|
739 |
|
740 QString filename(themeBasePath.absolutePath()); |
|
741 int cutindex = filename.lastIndexOf("/",filename.lastIndexOf("/")-1)+1; |
|
742 filename = filename.left(cutindex); |
|
743 themeBasePath.setPath(filename); |
|
744 filename.append(themeName); |
|
745 filename.append(".themeindex"); |
|
746 |
|
747 if (themePath == ":\\themes\\icons\\hbdefault") { |
|
748 themeBasePath.setPath(":/themes"); |
|
749 filename = ":/themes/hbdefault.themeindex"; |
|
750 themeName = "hbdefault"; |
|
751 } |
|
752 |
|
753 QFile indexFile(filename); |
|
754 |
|
755 bool indexOK = false; |
|
756 |
|
757 if (indexFile.open(QIODevice::ReadOnly)) { |
|
758 |
|
759 indexOK = true; |
|
760 |
|
761 GET_MEMORY_MANAGER(HbMemoryManager::SharedMemory); |
|
762 |
|
763 HbSharedChunkHeader *chunkHeader = (HbSharedChunkHeader*) manager->base(); |
|
764 |
|
765 qint64 byteSize = indexFile.size(); |
|
766 |
|
767 #ifdef THEME_INDEX_TRACES |
|
768 qDebug() << "ThemeIndex: " << themeName.toUtf8() << " index file size:" << byteSize; |
|
769 #endif |
|
770 |
|
771 int offset = manager->alloc(byteSize); |
|
772 if (offset >= 0) { |
|
773 #ifdef THEME_INDEX_TRACES |
|
774 qDebug() << "ThemeIndex: memory allocated for theme: " << themeName.toUtf8(); |
|
775 #endif |
|
776 |
|
777 // Read the theme index in the shared chunk |
|
778 char *address = HbMemoryUtils::getAddress<char>(HbMemoryManager::SharedMemory, offset); |
|
779 |
|
780 indexFile.read(address, byteSize); |
|
781 indexFile.close(); |
|
782 |
|
783 #ifdef THEME_INDEX_TRACES |
|
784 qDebug() << "ThemeIndex: Reading themeindex for theme" << themeName.toUtf8() << "... Done!"; |
|
785 #endif |
|
786 |
|
787 // Verify theme index contents if it is not located in ROM, |
|
788 // so that it does not have over-indexing offsets which might |
|
789 // crash all the clients trying to read from it. |
|
790 |
|
791 if (themePath[0] != 'z' && themePath[0] != 'Z') { |
|
792 #ifdef THEME_INDEX_TRACES |
|
793 qDebug() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8(); |
|
794 #endif |
|
795 |
|
796 HbThemeIndex index(address); |
|
797 indexOK = index.validateItems(byteSize); |
|
798 |
|
799 #ifdef THEME_INDEX_TRACES |
|
800 qDebug() << "ThemeIndex: Validating themeindex for theme" << themeName.toUtf8() << " done! Result: " << indexOK; |
|
801 #endif |
|
802 } |
|
803 |
|
804 if (indexOK) { |
|
805 // Allocate theme path string from shared memory |
|
806 QByteArray themePathArray = themeBasePath.absolutePath().toLatin1(); |
|
807 quint32 themePathOffset = manager->alloc(themePathArray.size()+1); |
|
808 memcpy(HbMemoryUtils::getAddress<char>( |
|
809 HbMemoryManager::SharedMemory, |
|
810 themePathOffset), |
|
811 themePathArray.data(), |
|
812 themePathArray.size()+1); // +1 for '/0' |
|
813 |
|
814 // Allocate theme name string from shared memory |
|
815 QByteArray themeNameArray = themeName.toLatin1(); |
|
816 quint32 themeNameOffset = manager->alloc(themeNameArray.size()+1); |
|
817 memcpy(HbMemoryUtils::getAddress<char>( |
|
818 HbMemoryManager::SharedMemory, |
|
819 themeNameOffset), |
|
820 themeNameArray.data(), |
|
821 themeNameArray.size()+1); // +1 for '/0' |
|
822 |
|
823 // Store offset to the index in chunk |
|
824 switch (themetype) { |
|
825 case BaseTheme: |
|
826 // Release previously allocated content |
|
827 manager->free(chunkHeader->baseThemePathOffset); |
|
828 manager->free(chunkHeader->baseThemeNameOffset); |
|
829 manager->free(chunkHeader->baseThemeIndexOffset); |
|
830 // Base theme offsets |
|
831 chunkHeader->baseThemePathOffset = themePathOffset; |
|
832 chunkHeader->baseThemeNameOffset = themeNameOffset; |
|
833 chunkHeader->baseThemeIndexOffset = offset; |
|
834 break; |
|
835 case OperatorC: |
|
836 // Release previously allocated content |
|
837 manager->free(chunkHeader->operatorThemeDriveCPathOffset); |
|
838 manager->free(chunkHeader->operatorThemeDriveCNameOffset); |
|
839 manager->free(chunkHeader->operatorThemeDriveCIndexOffset); |
|
840 // Operator theme in C-drive offsets |
|
841 chunkHeader->operatorThemeDriveCPathOffset = themePathOffset; |
|
842 chunkHeader->operatorThemeDriveCNameOffset = themeNameOffset; |
|
843 chunkHeader->operatorThemeDriveCIndexOffset = offset; |
|
844 break; |
|
845 case OperatorROM: |
|
846 // Release previously allocated content |
|
847 manager->free(chunkHeader->operatorThemeRomPathOffset); |
|
848 manager->free(chunkHeader->operatorThemeRomNameOffset); |
|
849 manager->free(chunkHeader->operatorThemeRomIndexOffset); |
|
850 // Operator theme in ROM offsets |
|
851 chunkHeader->operatorThemeRomPathOffset = themePathOffset; |
|
852 chunkHeader->operatorThemeRomNameOffset = themeNameOffset; |
|
853 chunkHeader->operatorThemeRomIndexOffset = offset; |
|
854 break; |
|
855 case ActiveTheme: |
|
856 // Release previously allocated content |
|
857 manager->free(chunkHeader->activeThemePathOffset); |
|
858 manager->free(chunkHeader->activeThemeNameOffset); |
|
859 manager->free(chunkHeader->activeThemeIndexOffset); |
|
860 // Active theme offsets |
|
861 chunkHeader->activeThemePathOffset = themePathOffset; |
|
862 chunkHeader->activeThemeNameOffset = themeNameOffset; |
|
863 chunkHeader->activeThemeIndexOffset = offset; |
|
864 break; |
|
865 default: |
|
866 break; |
|
867 } |
|
868 } else { |
|
869 // If the index contents were not OK, remove the index from the chunk |
|
870 manager->free(offset); |
|
871 } |
|
872 } |
|
873 } |
|
874 } |
|
875 |
734 |
876 //********************************** |
735 //********************************** |
877 //HbThemeServerSession |
736 //HbThemeServerSession |
878 //********************************** |
737 //********************************** |
879 /** |
738 /** |
1366 QString effFileName((QChar*)fileName.Ptr(), fileName.Length()); |
1221 QString effFileName((QChar*)fileName.Ptr(), fileName.Length()); |
1367 HbSharedEffectInfo offsetInfo; |
1222 HbSharedEffectInfo offsetInfo; |
1368 offsetInfo.offset = HbThemeServerUtils::getSharedEffect(effFileName); |
1223 offsetInfo.offset = HbThemeServerUtils::getSharedEffect(effFileName); |
1369 TPckg<HbSharedEffectInfo> data(offsetInfo); |
1224 TPckg<HbSharedEffectInfo> data(offsetInfo); |
1370 aMessage.WriteL(1, data); |
1225 aMessage.WriteL(1, data); |
1371 } |
|
1372 |
|
1373 void HbThemeServerSession::GetSharedIconDefaultSizeInfoL(const RMessage2 &aMessage) |
|
1374 { |
|
1375 TIconParams params = ReadMessageAndRetrieveParams(aMessage); |
|
1376 |
|
1377 // Need to be allocated from heap or the leave in the end causes a crash |
|
1378 QScopedPointer<QString> filenamePtr(new QString((QChar*)params.fileName.Ptr(), params.fileName.Length())); |
|
1379 |
|
1380 // See if the icon's default size has been queried already earlier and |
|
1381 // can be found stored in the hash. |
|
1382 |
|
1383 QSizeF defSize = iServer->iconDefaultSizeCacheItem(*filenamePtr.data()); |
|
1384 |
|
1385 if (!defSize.isValid()) { |
|
1386 defSize = RetrieveIconDefaultSize(*filenamePtr.data()); |
|
1387 |
|
1388 // If the default size was retrieved, insert it in the hash for further lookups |
|
1389 if (defSize.isValid()) { |
|
1390 iServer->insertIconDefaultSizeCacheItem(*filenamePtr.data(), defSize); |
|
1391 } |
|
1392 } |
|
1393 |
|
1394 // Return the default size back to the client if it was resolved |
|
1395 if (defSize.isValid()) { |
|
1396 TPckg<QSizeF> returnData(defSize); |
|
1397 aMessage.WriteL(1, returnData); |
|
1398 #ifdef THEME_SERVER_TRACES |
|
1399 qDebug() << "Completed aMessage.WriteL"; |
|
1400 #endif |
|
1401 } |
|
1402 // Otherwise leave with error code |
|
1403 else { |
|
1404 User::Leave(KErrNotFound); |
|
1405 } |
|
1406 } |
|
1407 |
|
1408 QSizeF HbThemeServerSession::RetrieveIconDefaultSize(const QString &filename) |
|
1409 { |
|
1410 QSizeF ret; |
|
1411 |
|
1412 // Get icon source, previous icons sources are cached so if accessed again, |
|
1413 // they don't need to be loaded and parsed from a file always. |
|
1414 HbIconSource *source = HbThemeServerUtils::getIconSource(filename); |
|
1415 if (source) { |
|
1416 ret = source->defaultSize(); |
|
1417 } |
|
1418 |
|
1419 return ret; |
|
1420 } |
1226 } |
1421 |
1227 |
1422 /** |
1228 /** |
1423 * GetSharedIconInfoL |
1229 * GetSharedIconInfoL |
1424 */ |
1230 */ |