diff -r 7516d6d86cf5 -r ed14f46c0e55 src/hbtools/hbthemeindexer/main.cpp --- a/src/hbtools/hbthemeindexer/main.cpp Mon Oct 04 17:49:30 2010 +0300 +++ b/src/hbtools/hbthemeindexer/main.cpp Mon Oct 18 18:23:13 2010 +0300 @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -37,6 +39,11 @@ #include #include +#if !defined(QT_DLL) && !defined(QT_SHARED) +#include +Q_IMPORT_PLUGIN(qsvg) +#endif + #define RESOURCE_LIB_NAME "HbCore" #define WIN32_DEBUG_SUFFIX "d" #define MAC_DEBUG_SUFFIX "_debug" @@ -105,12 +112,6 @@ } } -QSize getDefaultSize(const QString &filename) -{ - HbIconSource source(filename); - return source.defaultSize().toSize(); -} - void appendItem(HbThemeIndexItemData &itemData, const QString &itemName) { bool alreadyExists = false; @@ -231,10 +232,17 @@ // If we come here, the filename must end with .* (e.g. .svg) iconname = filename.left(filename.lastIndexOf('.')); - itemData.itemNameHash = HbThemeIndex::hash(iconname); + itemData.itemNameHash = hbHash(iconname); // Define default size - QSize defaultSize = getDefaultSize(fullFilename); + HbIconSource source(fullFilename); + if (itemData.itemType != HbThemeIndexItemData::NvgItem) { + if (!source.imageReader()) { + std::cout << "ERROR: could not read file " << fullFilename.toStdString() << "\n"; + return; // Don't add invalid file to the index + } + } + QSize defaultSize = source.defaultSize().toSize(); itemData.defaultWidth = static_cast(defaultSize.width()); itemData.defaultHeight = static_cast(defaultSize.height()); @@ -259,9 +267,14 @@ QString mirroredFilenameCandidate = mirroredFilepath + iconname + ext; if (QFile::exists(mirroredFilenameCandidate)) { + HbIconSource mirroredSource(fullFilename); + if ((ext != ".nvg") && !mirroredSource.imageReader()) { + std::cout << "ERROR: could not read file " << fullFilename.toStdString() << "\n"; + continue; // Don't register invalid mirrored icon + } itemData.mirroredItemType = getItemType(mirroredFilenameCandidate); // Define mirrored icon size - QSize mirroredSize = getDefaultSize(mirroredFilenameCandidate); + QSize mirroredSize = mirroredSource.defaultSize().toSize(); itemData.mirroredWidth = static_cast(mirroredSize.width()); itemData.mirroredHeight = static_cast(mirroredSize.height()); break; @@ -288,7 +301,7 @@ case HbThemeIndexItemData::FxmlItem: { // Define fileName (file extension not removed) - itemData.itemNameHash = HbThemeIndex::hash(filename); + itemData.itemNameHash = hbHash(filename); if (LockedList.contains(filename)) { itemData.flags |= HbThemeIndexItemData::Locked; @@ -342,7 +355,7 @@ value = line.mid(startIndex, endIndex - startIndex).trimmed(); } - itemData.itemNameHash = HbThemeIndex::hash(name); + itemData.itemNameHash = hbHash(name); itemData.itemType = HbThemeIndexItemData::ColorItem; bool ok = false; itemData.colorValue = (quint32)value.toUInt(&ok, 16); // Might cause compiler warning in 64 bit systems @@ -356,97 +369,120 @@ return; } -void processDir(const QDir &dir, const QString &themename, const QString targetName, bool subDir = false) +void processDir(const QDir &dir, const QString &themename, const QString targetName) { - if (!subDir) { - IndexItems.clear(); - AddedItems.clear(); - MirroredList.clear(); - LockedList.clear(); - createMirroredList(dir.absolutePath()+"/icons/"+themename); - createLockedList(dir.absolutePath()+"/icons/"+themename); + QString iconPath(dir.absolutePath()+"/icons/"+themename); + QString animationPath(dir.absolutePath()+"/animations/"+themename); + QString effectPath(dir.absolutePath()+"/effects/"+themename); + + // Do the initialization + IndexItems.clear(); + AddedItems.clear(); + MirroredList.clear(); + LockedList.clear(); + createMirroredList(iconPath); + createLockedList(iconPath); + + // Only check icons under scalable and pixmap folders + QDir scalableDir(iconPath+"/scalable"); + if (scalableDir.exists()) { + QFileInfoList entries = scalableDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + for (int i=0; i(&header), sizeof(HbThemeIndexHeaderV1)); - assert(ret == sizeof(HbThemeIndexHeaderV1)); - - // Write items into the file stream - foreach(const HbThemeIndexItemData &itemData, IndexItems) { - ret = indexFile.write(reinterpret_cast(&itemData), sizeof(HbThemeIndexItemData)); - assert(ret == sizeof(HbThemeIndexItemData)); - } - - indexFile.close(); + if (verboseOn) { + std::cout << "============================TOTALS==============================\n"; + std::cout << "Added " << header.itemCount << " items.\n"; + std::cout << "================================================================\n"; } + + // Sort the list + qStableSort(IndexItems.begin(), IndexItems.end(), themeIndexItemDataLessThan); + + // Write header info into the file stream + qint64 ret = indexFile.write(reinterpret_cast(&header), sizeof(HbThemeIndexHeaderV1)); + assert(ret == sizeof(HbThemeIndexHeaderV1)); + + // Write items into the file stream + foreach(const HbThemeIndexItemData &itemData, IndexItems) { + ret = indexFile.write(reinterpret_cast(&itemData), sizeof(HbThemeIndexItemData)); + assert(ret == sizeof(HbThemeIndexItemData)); + } + + indexFile.close(); } void showHelp() {