57 // ------ |
57 // ------ |
58 |
58 |
59 |
59 |
60 void createMirroredList(const QString &fullThemePath) |
60 void createMirroredList(const QString &fullThemePath) |
61 { |
61 { |
62 std::cout << "Parsing mirrored list for theme " << fullThemePath.toStdString() << "\n"; |
62 if (verboseOn) { |
|
63 std::cout << "Parsing mirrored list for theme " << fullThemePath.toStdString() << "\n"; |
|
64 } |
63 // Find mirrored.txt file |
65 // Find mirrored.txt file |
64 QString filename = fullThemePath + "/mirrored.txt"; |
66 QString filename = fullThemePath + "/mirrored.txt"; |
65 // Try to read file |
67 // Try to read file |
66 QFile file(filename); |
68 QFile file(filename); |
67 if (file.open(QIODevice::ReadOnly)) { |
69 if (file.open(QIODevice::ReadOnly)) { |
79 } |
81 } |
80 } |
82 } |
81 |
83 |
82 void createLockedList(const QString &fullThemePath) |
84 void createLockedList(const QString &fullThemePath) |
83 { |
85 { |
84 std::cout << "Parsing locked list for theme " << fullThemePath.toStdString() << "\n"; |
86 if (verboseOn) { |
|
87 std::cout << "Parsing locked list for theme " << fullThemePath.toStdString() << "\n"; |
|
88 } |
85 // Find locked.txt file |
89 // Find locked.txt file |
86 QString filename = fullThemePath + "/locked.txt"; |
90 QString filename = fullThemePath + "/locked.txt"; |
87 // Try to read file |
91 // Try to read file |
88 QFile file(filename); |
92 QFile file(filename); |
89 if (file.open(QIODevice::ReadOnly)) { |
93 if (file.open(QIODevice::ReadOnly)) { |
152 } |
156 } |
153 |
157 |
154 if (itemData.flags & HbThemeIndexItemData::Mirrorable) { |
158 if (itemData.flags & HbThemeIndexItemData::Mirrorable) { |
155 std::cout << "Icon is automatically mirrored\n"; |
159 std::cout << "Icon is automatically mirrored\n"; |
156 } |
160 } |
|
161 } else if (itemData.itemType == HbThemeIndexItemData::ColorItem) { |
|
162 std::cout << "Color value: " << itemData.colorValue << "\n"; |
|
163 if (itemData.flags & HbThemeIndexItemData::Reference) { |
|
164 std::cout << "Item is reference\n"; |
|
165 } |
157 } |
166 } |
158 if (itemData.flags & HbThemeIndexItemData::Locked) { |
167 if (itemData.flags & HbThemeIndexItemData::Locked) { |
159 std::cout << "Item is locked\n"; |
168 std::cout << "Item is locked\n"; |
160 } |
169 } |
|
170 |
161 std::cout << "----------------------------------------------------------------\n\n"; |
171 std::cout << "----------------------------------------------------------------\n\n"; |
162 } else { // Item already added in index with some other extension, do not add duplicates |
172 } else { // Item already added in index with some other extension, do not add duplicates |
163 std::cout << "----------------------------------------------------------------\n"; |
173 std::cout << "----------------------------------------------------------------\n"; |
164 std::cout << "WARNING! Skipped already existing item:" << itemName.toStdString() << "\n"; |
174 std::cout << "WARNING! Skipped already existing item:" << itemName.toStdString() << "\n"; |
165 } |
175 } |
300 bool themeIndexItemDataLessThan(const HbThemeIndexItemData &d1, const HbThemeIndexItemData &d2) |
310 bool themeIndexItemDataLessThan(const HbThemeIndexItemData &d1, const HbThemeIndexItemData &d2) |
301 { |
311 { |
302 return d1.itemNameHash < d2.itemNameHash; |
312 return d1.itemNameHash < d2.itemNameHash; |
303 } |
313 } |
304 |
314 |
|
315 void indexColorVariables(const QString &filename) |
|
316 { |
|
317 QFile file(filename); |
|
318 |
|
319 // Index only if given CSS file exists in theme. |
|
320 if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
321 QTextStream in(&file); |
|
322 |
|
323 while(!in.atEnd()) { |
|
324 QString line = in.readLine().trimmed(); |
|
325 |
|
326 if (line.startsWith("qtc_")) { |
|
327 HbThemeIndexItemData itemData; |
|
328 |
|
329 // Extract name and value from line |
|
330 QString name = line.mid(0, line.indexOf(':')).trimmed(); |
|
331 QString value; |
|
332 if (line.at(line.indexOf(':') + 1) == QChar('#')) { |
|
333 // qtc_conv_list_received_normal:#B5B5B5; |
|
334 int startIndex = line.indexOf('#'); |
|
335 int endIndex = line.indexOf(';'); |
|
336 value = line.mid(startIndex + 1, endIndex - startIndex - 1).trimmed(); |
|
337 } else if (line.indexOf("var(") >= 0) { |
|
338 // qtc_conv_list_received_normal:var(qtc_conv_list_sent_normal); |
|
339 itemData.flags |= HbThemeIndexItemData::Reference; |
|
340 int startIndex = line.indexOf("var(") + 4; |
|
341 int endIndex = line.indexOf(')'); |
|
342 value = line.mid(startIndex, endIndex - startIndex).trimmed(); |
|
343 } |
|
344 |
|
345 itemData.itemNameHash = HbThemeIndex::hash(name); |
|
346 itemData.itemType = HbThemeIndexItemData::ColorItem; |
|
347 bool ok = false; |
|
348 itemData.colorValue = (quint32)value.toUInt(&ok, 16); // Might cause compiler warning in 64 bit systems |
|
349 appendItem(itemData, name); |
|
350 } |
|
351 } |
|
352 file.close(); |
|
353 } else if (verboseOn) { |
|
354 std::cout << "No " << filename.toStdString() << " in theme!\n"; |
|
355 } |
|
356 return; |
|
357 } |
|
358 |
305 void processDir(const QDir &dir, const QString &themename, const QString targetName, bool subDir = false) |
359 void processDir(const QDir &dir, const QString &themename, const QString targetName, bool subDir = false) |
306 { |
360 { |
307 if (!subDir) { |
361 if (!subDir) { |
308 IndexItems.clear(); |
362 IndexItems.clear(); |
309 AddedItems.clear(); |
363 AddedItems.clear(); |
335 HbThemeIndexItemData itemData; |
389 HbThemeIndexItemData itemData; |
336 itemData.itemNameHash = HbThemeIndex::hash(mirrored); |
390 itemData.itemNameHash = HbThemeIndex::hash(mirrored); |
337 itemData.flags |= HbThemeIndexItemData::Mirrorable; |
391 itemData.flags |= HbThemeIndexItemData::Mirrorable; |
338 appendItem(itemData, mirrored); |
392 appendItem(itemData, mirrored); |
339 } |
393 } |
340 QDir targetDir(targetName); |
394 |
341 if (!targetDir.exists()) { |
395 // Read application and widget color group CSS files and index their content |
|
396 // Temporary check |
|
397 if (QFile::exists(dir.absolutePath() + "/style/" + themename + "/variables/color/hbapplicationcolorgroup.css") && |
|
398 QFile::exists(dir.absolutePath() + "/style/" + themename + "/variables/color/hbwidgetcolorgroup.css")) { |
|
399 if (verboseOn) { |
|
400 std::cout << "Processing hbapplicationcolorgroup.css and hbwidgetcolorgroup.css"; |
|
401 } |
|
402 indexColorVariables(dir.absolutePath() + "/style/" + themename + "/variables/color/hbapplicationcolorgroup.css"); |
|
403 indexColorVariables(dir.absolutePath() + "/style/" + themename + "/variables/color/hbwidgetcolorgroup.css"); |
|
404 } else { |
|
405 if (verboseOn) { |
|
406 std::cout << "Processing hbcolorgroup.css"; |
|
407 } |
|
408 indexColorVariables(dir.absolutePath() + "/style/" + themename + "/variables/color/hbcolorgroup.css"); |
|
409 } |
|
410 |
|
411 QDir targetDir; |
|
412 if (!targetDir.exists(targetName)) { |
342 targetDir.mkpath(targetName); |
413 targetDir.mkpath(targetName); |
343 } |
414 } |
344 QString filename = targetName + themename + ".themeindex"; |
415 QString filename = targetName + themename + ".themeindex"; |
345 |
416 |
346 QFile::remove(filename); |
417 QFile::remove(filename); |
378 } |
449 } |
379 } |
450 } |
380 |
451 |
381 void showHelp() { |
452 void showHelp() { |
382 std::cout << "Themeindexer.exe usage:\n\n"; |
453 std::cout << "Themeindexer.exe usage:\n\n"; |
383 std::cout << "hbthemeindexer [-v] -f filename OR -n themename -s themes source directory -t theme index file target directory\n\n"; |
454 std::cout << "hbthemeindexer [-v] -f filename OR (-n themename) -s themes source directory -t theme index file target directory\n\n"; |
384 |
455 |
385 std::cout << "-n \t\ttheme to be indexed (\"<themename>.themeindex\").\n"; |
456 std::cout << "-n \t\ttheme to be indexed (\"<themename>.themeindex\"). If omitted, all found\n"; |
386 std::cout << "-s \t\tthemes source directory is scanned recursively and all the"; |
457 std::cout << "\t\tthemes are indexed.\n"; |
387 std::cout << "\t\t\trecognized resource files for given theme are aded in the theme index.\n"; |
458 std::cout << "-s \t\tthemes source directory is scanned recursively and all the recognized\n"; |
|
459 std::cout << "\t\tresource files for given theme are aded in the theme index.\n"; |
388 std::cout << "-t \t\ttarget directory for the index file.\n"; |
460 std::cout << "-t \t\ttarget directory for the index file.\n"; |
389 |
461 |
390 std::cout << "-f <filename>\tfile which contains multiple themes to be indexed. Each in its own row.\n"; |
462 std::cout << "-f <filename>\tfile which contains multiple themes to be indexed. Each in its own row.\n"; |
391 std::cout << "-v \t\tverbose output\n\n"; |
463 std::cout << "-v \t\tverbose output\n\n"; |
392 |
464 |
485 } else { |
557 } else { |
486 std::cout << "Error: file " << filename.toStdString() << " could not be opened.\n"; |
558 std::cout << "Error: file " << filename.toStdString() << " could not be opened.\n"; |
487 } |
559 } |
488 } |
560 } |
489 } else { |
561 } else { |
490 // Index only given theme |
562 // Index only given dir |
491 |
563 |
492 targetname.replace('\\', '/'); |
564 targetname.replace('\\', '/'); |
493 // Check that targetname has / at the end |
565 // Check that targetname has / at the end |
494 if (!targetname.endsWith('/')) { |
566 if (!targetname.endsWith('/')) { |
495 targetname.append('/'); |
567 targetname.append('/'); |
496 } |
568 } |
497 |
569 |
498 processDir(basedir, themename, targetname); |
570 if (themename.isEmpty()) { |
|
571 // Theme name not given, determine available themes |
|
572 QDir icondir(basedir); |
|
573 if (icondir.cd("icons")) { |
|
574 QStringList entries = icondir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
|
575 foreach (const QString &entry, entries) { |
|
576 QDir entrydir(icondir.filePath(entry)); |
|
577 if (entrydir.exists("index.theme")) { |
|
578 processDir(basedir, entrydir.dirName(), targetname); |
|
579 } |
|
580 } |
|
581 } |
|
582 } else { |
|
583 // Process only given theme |
|
584 processDir(basedir, themename, targetname); |
|
585 } |
499 |
586 |
500 } |
587 } |
501 } |
588 } |
502 |
589 |
503 IndexItems.clear(); |
590 IndexItems.clear(); |