385 } |
386 } |
386 |
387 |
387 { |
388 { |
388 QDir dir; |
389 QDir dir; |
389 dir.setPath(cfgdir->absolutePath() + "/Data/Themes"); |
390 dir.setPath(cfgdir->absolutePath() + "/Data/Themes"); |
390 Themes = new QStringList(); |
391 |
391 Themes->append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
392 QStringList themes; |
|
393 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
392 |
394 |
393 dir.setPath(datadir->absolutePath() + "/Themes"); |
395 dir.setPath(datadir->absolutePath() + "/Themes"); |
394 Themes->append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
396 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
395 qDebug() << *Themes; |
397 |
396 for(int i = Themes->size() - 1; i >= 0; --i) |
398 QList<QPair<QIcon, QIcon> > icons; |
|
399 |
|
400 for(int i = themes.size() - 1; i >= 0; --i) |
397 { |
401 { |
398 QFile tmpfile; |
402 QFile tmpfile; |
399 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(Themes->at(i))); |
403 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
400 if (!tmpfile.exists()) |
404 if (!tmpfile.exists()) |
401 { |
405 { |
402 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(Themes->at(i))); |
406 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
403 if(!tmpfile.exists()) |
407 if(tmpfile.exists()) |
404 Themes->removeAt(i); |
408 { // load icon |
|
409 QPair<QIcon, QIcon> ic; |
|
410 ic.first = QIcon(QFileInfo(tmpfile).absoluteFilePath()); |
|
411 |
|
412 QFile previewIconFile; |
|
413 previewIconFile.setFileName(QString("%1/Data/Themes/%2/icon@2x.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
|
414 if (previewIconFile.exists()) ic.second = QIcon(QFileInfo(previewIconFile).absoluteFilePath()); |
|
415 else ic.second = QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
|
416 |
|
417 icons.prepend(ic); |
|
418 } |
|
419 else |
|
420 { |
|
421 themes.removeAt(i); |
|
422 } |
405 } |
423 } |
|
424 } |
|
425 |
|
426 themesModel = new ThemesModel(themes); |
|
427 for(int i = 0; i < icons.size(); ++i) |
|
428 { |
|
429 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
|
430 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
|
431 |
|
432 qDebug() << "icon test" << themesModel->index(i).data(Qt::UserRole).toString(); |
406 } |
433 } |
407 } |
434 } |
408 |
435 |
409 QDir tmpdir; |
436 QDir tmpdir; |
410 tmpdir.cd(cfgdir->absolutePath()); |
437 tmpdir.cd(cfgdir->absolutePath()); |
432 if (!scriptList->contains(*it,Qt::CaseInsensitive)) scriptList->append(*it); |
459 if (!scriptList->contains(*it,Qt::CaseInsensitive)) scriptList->append(*it); |
433 |
460 |
434 QTranslator Translator; |
461 QTranslator Translator; |
435 { |
462 { |
436 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
463 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
437 QString cc = settings.value("misc/locale", "").toString(); |
464 QString cc = settings.value("misc/locale", QString()).toString(); |
438 if(!cc.compare("")) |
465 if(cc.isEmpty()) |
439 cc = QLocale::system().name(); |
466 cc = QLocale::system().name(); |
440 QFile tmpfile; |
467 QFile tmpfile; |
441 tmpfile.setFileName(cfgdir->absolutePath() + "Data/Locale/hedgewars_" + cc); |
468 tmpfile.setFileName(cfgdir->absolutePath() + "Data/Locale/hedgewars_" + cc); |
442 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "Locale/hedgewars_" + cc); |
469 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "Locale/hedgewars_" + cc); |
443 Translator.load(QFileInfo(tmpfile).absoluteFilePath()); |
470 Translator.load(QFileInfo(tmpfile).absoluteFilePath()); |