|
@@ -955,38 +955,38 @@ void CModListView::on_tabWidget_currentChanged(int index)
|
|
|
|
|
|
void CModListView::loadScreenshots()
|
|
void CModListView::loadScreenshots()
|
|
{
|
|
{
|
|
- if(ui->tabWidget->currentIndex() == 2)
|
|
|
|
|
|
+ if(ui->tabWidget->currentIndex() != 2)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ assert(ui->allModsView->currentIndex().isValid());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!ui->allModsView->currentIndex().isValid())
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ ui->screenshotsList->clear();
|
|
|
|
+ QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
|
+ assert(modStateModel->isModExists(modName)); //should be filtered out by check above
|
|
|
|
+
|
|
|
|
+ for(QString url : modStateModel->getMod(modName).getScreenshots())
|
|
{
|
|
{
|
|
- if(!ui->allModsView->currentIndex().isValid())
|
|
|
|
|
|
+ // URL must be encoded to something else to get rid of symbols illegal in file names
|
|
|
|
+ const auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5);
|
|
|
|
+ const auto fileName = QString{QLatin1String{"%1.png"}}.arg(QLatin1String{hashed.toHex()});
|
|
|
|
+
|
|
|
|
+ const auto fullPath = QString{QLatin1String{"%1/%2"}}.arg(CLauncherDirs::downloadsPath(), fileName);
|
|
|
|
+ QPixmap pixmap(fullPath);
|
|
|
|
+ if(pixmap.isNull())
|
|
{
|
|
{
|
|
- // select the first mod, so we can access its data
|
|
|
|
- ui->allModsView->setCurrentIndex(filterModel->index(0, 0));
|
|
|
|
|
|
+ // image file not exists or corrupted - try to redownload
|
|
|
|
+ downloadFile(fileName, url, tr("screenshots"));
|
|
}
|
|
}
|
|
-
|
|
|
|
- ui->screenshotsList->clear();
|
|
|
|
- QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
|
- assert(modStateModel->isModExists(modName)); //should be filtered out by check above
|
|
|
|
-
|
|
|
|
- for(QString url : modStateModel->getMod(modName).getScreenshots())
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- // URL must be encoded to something else to get rid of symbols illegal in file names
|
|
|
|
- const auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5);
|
|
|
|
- const auto fileName = QString{QLatin1String{"%1.png"}}.arg(QLatin1String{hashed.toHex()});
|
|
|
|
-
|
|
|
|
- const auto fullPath = QString{QLatin1String{"%1/%2"}}.arg(CLauncherDirs::downloadsPath(), fileName);
|
|
|
|
- QPixmap pixmap(fullPath);
|
|
|
|
- if(pixmap.isNull())
|
|
|
|
- {
|
|
|
|
- // image file not exists or corrupted - try to redownload
|
|
|
|
- downloadFile(fileName, url, tr("screenshots"));
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- // managed to load cached image
|
|
|
|
- QIcon icon(pixmap);
|
|
|
|
- auto * item = new QListWidgetItem(icon, QString(tr("Screenshot %1")).arg(ui->screenshotsList->count() + 1));
|
|
|
|
- ui->screenshotsList->addItem(item);
|
|
|
|
- }
|
|
|
|
|
|
+ // managed to load cached image
|
|
|
|
+ QIcon icon(pixmap);
|
|
|
|
+ auto * item = new QListWidgetItem(icon, QString(tr("Screenshot %1")).arg(ui->screenshotsList->count() + 1));
|
|
|
|
+ ui->screenshotsList->addItem(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|