summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/gui/icons/IconList.cpp11
-rw-r--r--api/gui/icons/IconList.h1
-rw-r--r--api/logic/icons/IIconList.h1
-rw-r--r--application/dialogs/NewInstanceDialog.cpp23
-rw-r--r--application/dialogs/NewInstanceDialog.h8
-rw-r--r--application/pages/modplatform/FTBPage.cpp12
-rw-r--r--application/pages/modplatform/FtbListModel.cpp12
-rw-r--r--application/pages/modplatform/FtbListModel.h4
8 files changed, 71 insertions, 1 deletions
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp
index 5c2c1386..997a03db 100644
--- a/api/gui/icons/IconList.cpp
+++ b/api/gui/icons/IconList.cpp
@@ -269,6 +269,17 @@ void IconList::installIcons(const QStringList &iconFiles)
}
}
+void IconList::installIcon(const QString &file, const QString &name)
+{
+ QFileInfo fileinfo(file);
+ if(!fileinfo.isReadable() || !fileinfo.isFile())
+ return;
+
+ QString target = FS::PathCombine(m_dir.dirName(), name);
+
+ QFile::copy(file, target);
+}
+
bool IconList::iconFileExists(const QString &key) const
{
auto iconEntry = icon(key);
diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h
index b8599103..fad3336f 100644
--- a/api/gui/icons/IconList.h
+++ b/api/gui/icons/IconList.h
@@ -56,6 +56,7 @@ public:
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
void installIcons(const QStringList &iconFiles) override;
+ void installIcon(const QString &file, const QString &name) override;
const MMCIcon * icon(const QString &key) const;
diff --git a/api/logic/icons/IIconList.h b/api/logic/icons/IIconList.h
index ebf99d05..e6c16d50 100644
--- a/api/logic/icons/IIconList.h
+++ b/api/logic/icons/IIconList.h
@@ -22,4 +22,5 @@ public:
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
virtual bool iconFileExists(const QString &key) const = 0;
virtual void installIcons(const QStringList &iconFiles) = 0;
+ virtual void installIcon(const QString &file, const QString &name) = 0;
};
diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp
index 900b33f7..b3ce5c6c 100644
--- a/application/dialogs/NewInstanceDialog.cpp
+++ b/application/dialogs/NewInstanceDialog.cpp
@@ -100,6 +100,7 @@ void NewInstanceDialog::reject()
void NewInstanceDialog::accept()
{
MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
+ importIconNow();
QDialog::accept();
}
@@ -135,6 +136,16 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
}
+void NewInstanceDialog::setSuggestedIconFromFile(const QString &path, const QString &name)
+{
+ importIcon = true;
+ importIconPath = path;
+ importIconName = name;
+
+ //Hmm, for some reason they can be to small
+ ui->iconButton->setIcon(QIcon(path));
+}
+
InstanceTask * NewInstanceDialog::extractTask()
{
InstanceTask * extracted = creationTask.get();
@@ -177,6 +188,7 @@ QString NewInstanceDialog::iconKey() const
void NewInstanceDialog::on_iconButton_clicked()
{
+ importIconNow(); //so the user can switch back
IconPickerDialog dlg(this);
dlg.execWithSelection(InstIconKey);
@@ -184,6 +196,7 @@ void NewInstanceDialog::on_iconButton_clicked()
{
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
+ importIcon = false;
}
}
@@ -191,3 +204,13 @@ void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
{
updateDialogState();
}
+
+void NewInstanceDialog::importIconNow()
+{
+ if(importIcon) {
+ MMC->icons()->installIcon(importIconPath, importIconName);
+ InstIconKey = importIconName;
+ importIcon = false;
+ }
+ MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
+}
diff --git a/application/dialogs/NewInstanceDialog.h b/application/dialogs/NewInstanceDialog.h
index 9d7cab01..1448d225 100644
--- a/application/dialogs/NewInstanceDialog.h
+++ b/application/dialogs/NewInstanceDialog.h
@@ -41,6 +41,8 @@ public:
void updateDialogState();
void setSuggestedPack(const QString & name = QString(), InstanceTask * task = nullptr);
+ void setSuggestedIconFromFile(const QString &path, const QString &name);
+
InstanceTask * extractTask();
QString dialogTitle() override;
@@ -66,4 +68,10 @@ private:
QString InstIconKey;
ImportPage *importPage = nullptr;
std::unique_ptr<InstanceTask> creationTask;
+
+ bool importIcon = false;
+ QString importIconPath;
+ QString importIconName;
+
+ void importIconNow();
};
diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp
index 7f8ee54e..f438fce7 100644
--- a/application/pages/modplatform/FTBPage.cpp
+++ b/application/pages/modplatform/FTBPage.cpp
@@ -50,6 +50,9 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
}
+ ui->packVersionSelection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ ui->packVersionSelection->view()->parentWidget()->setMaximumHeight(300);
+
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
@@ -96,6 +99,15 @@ void FTBPage::suggestCurrent()
if(!selected.broken)
{
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
+ if(selected.type == FtbPackType::Public) {
+ publicListModel->getLogo(selected.logo, [this](QString logo){
+ dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
+ });
+ } else if (selected.type == FtbPackType::ThirdParty) {
+ thirdPartyModel->getLogo(selected.logo, [this](QString logo){
+ dialog->setSuggestedIconFromFile(logo, "ftb_" + selected.name);
+ });
+ }
}
else
{
diff --git a/application/pages/modplatform/FtbListModel.cpp b/application/pages/modplatform/FtbListModel.cpp
index 8e52f541..c14907c6 100644
--- a/application/pages/modplatform/FtbListModel.cpp
+++ b/application/pages/modplatform/FtbListModel.cpp
@@ -175,6 +175,9 @@ void FtbListModel::requestLogo(QString file)
auto fullPath = entry->getFullPath();
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
emit logoLoaded(file, QIcon(fullPath));
+ if(waitingCallbacks.contains(file)) {
+ waitingCallbacks.value(file)(fullPath);
+ }
});
QObject::connect(job, &NetJob::failed, this, [this, file]{
@@ -185,3 +188,12 @@ void FtbListModel::requestLogo(QString file)
m_loadingLogos.append(file);
}
+
+void FtbListModel::getLogo(const QString &logo, LogoCallback callback)
+{
+ if(m_logoMap.contains(logo)) {
+ callback(ENV.metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath());
+ } else {
+ requestLogo(logo);
+ }
+}
diff --git a/application/pages/modplatform/FtbListModel.h b/application/pages/modplatform/FtbListModel.h
index 12b26be1..5f6c9db1 100644
--- a/application/pages/modplatform/FtbListModel.h
+++ b/application/pages/modplatform/FtbListModel.h
@@ -10,6 +10,7 @@
#include <QIcon>
typedef QMap<QString, QIcon> FtbLogoMap;
+typedef std::function<void(QString)> LogoCallback;
class FtbFilterModel : public QSortFilterProxyModel
{
@@ -42,6 +43,7 @@ private:
QStringList m_failedLogos;
QStringList m_loadingLogos;
FtbLogoMap m_logoMap;
+ QMap<QString, LogoCallback> waitingCallbacks;
void requestLogo(QString file);
QString translatePackType(FtbPackType type) const;
@@ -61,5 +63,5 @@ public:
void fill(FtbModpackList modpacks);
FtbModpack at(int row);
-
+ void getLogo(const QString &logo, LogoCallback callback);
};