#2228, #2229 - Auto import pack icons and fixed to big version selection - Closes #2228, Closes #2229
This commit is contained in:
parent
38ed0c2a1f
commit
7e1c5d439a
@ -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
|
bool IconList::iconFileExists(const QString &key) const
|
||||||
{
|
{
|
||||||
auto iconEntry = icon(key);
|
auto iconEntry = icon(key);
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
void installIcons(const QStringList &iconFiles) override;
|
void installIcons(const QStringList &iconFiles) override;
|
||||||
|
void installIcon(const QString &file, const QString &name) override;
|
||||||
|
|
||||||
const MMCIcon * icon(const QString &key) const;
|
const MMCIcon * icon(const QString &key) const;
|
||||||
|
|
||||||
|
@ -22,4 +22,5 @@ public:
|
|||||||
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
|
virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0;
|
||||||
virtual bool iconFileExists(const QString &key) const = 0;
|
virtual bool iconFileExists(const QString &key) const = 0;
|
||||||
virtual void installIcons(const QStringList &iconFiles) = 0;
|
virtual void installIcons(const QStringList &iconFiles) = 0;
|
||||||
|
virtual void installIcon(const QString &file, const QString &name) = 0;
|
||||||
};
|
};
|
||||||
|
@ -100,6 +100,7 @@ void NewInstanceDialog::reject()
|
|||||||
void NewInstanceDialog::accept()
|
void NewInstanceDialog::accept()
|
||||||
{
|
{
|
||||||
MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
|
MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
|
||||||
|
importIconNow();
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +136,16 @@ void NewInstanceDialog::setSuggestedPack(const QString& name, InstanceTask* task
|
|||||||
m_buttons->button(QDialogButtonBox::Ok)->setEnabled(allowOK);
|
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 * NewInstanceDialog::extractTask()
|
||||||
{
|
{
|
||||||
InstanceTask * extracted = creationTask.get();
|
InstanceTask * extracted = creationTask.get();
|
||||||
@ -177,6 +188,7 @@ QString NewInstanceDialog::iconKey() const
|
|||||||
|
|
||||||
void NewInstanceDialog::on_iconButton_clicked()
|
void NewInstanceDialog::on_iconButton_clicked()
|
||||||
{
|
{
|
||||||
|
importIconNow(); //so the user can switch back
|
||||||
IconPickerDialog dlg(this);
|
IconPickerDialog dlg(this);
|
||||||
dlg.execWithSelection(InstIconKey);
|
dlg.execWithSelection(InstIconKey);
|
||||||
|
|
||||||
@ -184,6 +196,7 @@ void NewInstanceDialog::on_iconButton_clicked()
|
|||||||
{
|
{
|
||||||
InstIconKey = dlg.selectedIconKey;
|
InstIconKey = dlg.selectedIconKey;
|
||||||
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
|
||||||
|
importIcon = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,3 +204,13 @@ void NewInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
|
|||||||
{
|
{
|
||||||
updateDialogState();
|
updateDialogState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewInstanceDialog::importIconNow()
|
||||||
|
{
|
||||||
|
if(importIcon) {
|
||||||
|
MMC->icons()->installIcon(importIconPath, importIconName);
|
||||||
|
InstIconKey = importIconName;
|
||||||
|
importIcon = false;
|
||||||
|
}
|
||||||
|
MMC->settings()->set("NewInstanceGeometry", saveGeometry().toBase64());
|
||||||
|
}
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
void updateDialogState();
|
void updateDialogState();
|
||||||
|
|
||||||
void setSuggestedPack(const QString & name = QString(), InstanceTask * task = nullptr);
|
void setSuggestedPack(const QString & name = QString(), InstanceTask * task = nullptr);
|
||||||
|
void setSuggestedIconFromFile(const QString &path, const QString &name);
|
||||||
|
|
||||||
InstanceTask * extractTask();
|
InstanceTask * extractTask();
|
||||||
|
|
||||||
QString dialogTitle() override;
|
QString dialogTitle() override;
|
||||||
@ -66,4 +68,10 @@ private:
|
|||||||
QString InstIconKey;
|
QString InstIconKey;
|
||||||
ImportPage *importPage = nullptr;
|
ImportPage *importPage = nullptr;
|
||||||
std::unique_ptr<InstanceTask> creationTask;
|
std::unique_ptr<InstanceTask> creationTask;
|
||||||
|
|
||||||
|
bool importIcon = false;
|
||||||
|
QString importIconPath;
|
||||||
|
QString importIconName;
|
||||||
|
|
||||||
|
void importIconNow();
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,9 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent)
|
|||||||
thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting());
|
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->sortByBox, &QComboBox::currentTextChanged, this, &FTBPage::onSortingSelectionChanged);
|
||||||
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
connect(ui->packVersionSelection, &QComboBox::currentTextChanged, this, &FTBPage::onVersionSelectionItemChanged);
|
||||||
|
|
||||||
@ -96,6 +99,15 @@ void FTBPage::suggestCurrent()
|
|||||||
if(!selected.broken)
|
if(!selected.broken)
|
||||||
{
|
{
|
||||||
dialog->setSuggestedPack(selected.name, new FtbPackInstallTask(selected, selectedVersion));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -175,6 +175,9 @@ void FtbListModel::requestLogo(QString file)
|
|||||||
auto fullPath = entry->getFullPath();
|
auto fullPath = entry->getFullPath();
|
||||||
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
|
QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{
|
||||||
emit logoLoaded(file, QIcon(fullPath));
|
emit logoLoaded(file, QIcon(fullPath));
|
||||||
|
if(waitingCallbacks.contains(file)) {
|
||||||
|
waitingCallbacks.value(file)(fullPath);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(job, &NetJob::failed, this, [this, file]{
|
QObject::connect(job, &NetJob::failed, this, [this, file]{
|
||||||
@ -185,3 +188,12 @@ void FtbListModel::requestLogo(QString file)
|
|||||||
|
|
||||||
m_loadingLogos.append(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
typedef QMap<QString, QIcon> FtbLogoMap;
|
typedef QMap<QString, QIcon> FtbLogoMap;
|
||||||
|
typedef std::function<void(QString)> LogoCallback;
|
||||||
|
|
||||||
class FtbFilterModel : public QSortFilterProxyModel
|
class FtbFilterModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
@ -42,6 +43,7 @@ private:
|
|||||||
QStringList m_failedLogos;
|
QStringList m_failedLogos;
|
||||||
QStringList m_loadingLogos;
|
QStringList m_loadingLogos;
|
||||||
FtbLogoMap m_logoMap;
|
FtbLogoMap m_logoMap;
|
||||||
|
QMap<QString, LogoCallback> waitingCallbacks;
|
||||||
|
|
||||||
void requestLogo(QString file);
|
void requestLogo(QString file);
|
||||||
QString translatePackType(FtbPackType type) const;
|
QString translatePackType(FtbPackType type) const;
|
||||||
@ -61,5 +63,5 @@ public:
|
|||||||
void fill(FtbModpackList modpacks);
|
void fill(FtbModpackList modpacks);
|
||||||
|
|
||||||
FtbModpack at(int row);
|
FtbModpack at(int row);
|
||||||
|
void getLogo(const QString &logo, LogoCallback callback);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user