395 dir.setPath(datadir->absolutePath() + "/Themes"); |
395 dir.setPath(datadir->absolutePath() + "/Themes"); |
396 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
396 themes.append(dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)); |
397 |
397 |
398 QList<QPair<QIcon, QIcon> > icons; |
398 QList<QPair<QIcon, QIcon> > icons; |
399 |
399 |
|
400 themes.sort(); |
400 for(int i = themes.size() - 1; i >= 0; --i) |
401 for(int i = themes.size() - 1; i >= 0; --i) |
401 { |
402 { |
402 QFile tmpfile; |
403 QFile tmpfile; |
403 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
404 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
404 if (!tmpfile.exists()) |
405 if (!tmpfile.exists()) |
|
406 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
|
407 |
|
408 if(tmpfile.exists()) |
|
409 { // load icon |
|
410 QPair<QIcon, QIcon> ic; |
|
411 ic.first = QIcon(QFileInfo(tmpfile).absoluteFilePath()); |
|
412 |
|
413 QFile previewIconFile; |
|
414 previewIconFile.setFileName(QString("%1/Data/Themes/%2/icon@2x.png").arg(cfgdir->absolutePath()).arg(themes.at(i))); |
|
415 if (previewIconFile.exists()) ic.second = QIcon(QFileInfo(previewIconFile).absoluteFilePath()); |
|
416 else ic.second = QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
|
417 |
|
418 icons.prepend(ic); |
|
419 } |
|
420 else |
405 { |
421 { |
406 tmpfile.setFileName(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(themes.at(i))); |
422 themes.removeAt(i); |
407 if(tmpfile.exists()) |
|
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 } |
|
423 } |
423 } |
424 } |
424 } |
425 |
425 |
426 themesModel = new ThemesModel(themes); |
426 themesModel = new ThemesModel(themes); |
|
427 Q_ASSERT(themes.size() == icons.size()); |
427 for(int i = 0; i < icons.size(); ++i) |
428 for(int i = 0; i < icons.size(); ++i) |
428 { |
429 { |
429 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
430 themesModel->setData(themesModel->index(i), icons[i].first, Qt::DecorationRole); |
430 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
431 themesModel->setData(themesModel->index(i), icons[i].second, Qt::UserRole); |
431 |
|
432 qDebug() << "icon test" << themesModel->index(i).data(Qt::UserRole).toString(); |
|
433 } |
432 } |
434 } |
433 } |
435 |
434 |
436 QDir tmpdir; |
435 QDir tmpdir; |
437 tmpdir.cd(cfgdir->absolutePath()); |
436 tmpdir.cd(cfgdir->absolutePath()); |