summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-06-01 01:19:12 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-01 01:19:12 +0200
commit405cea177877234981019c6916f6f97d818dfd51 (patch)
tree2e1cc92f5bb807836fe8c4ecee98c1015305ce04
parent96c497f6542daabeaa67e96e4298df50f65663d0 (diff)
downloadMultiMC-405cea177877234981019c6916f6f97d818dfd51.tar
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.gz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.lz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.xz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.zip
GH-1031 include icon in exported instance if it is custom
-rw-r--r--application/MainWindow.cpp23
-rw-r--r--application/dialogs/ExportInstanceDialog.cpp49
-rw-r--r--application/dialogs/NewInstanceDialog.cpp2
-rw-r--r--application/dialogs/NewInstanceDialog.ui4
-rw-r--r--logic/icons/IconList.cpp18
-rw-r--r--logic/icons/IconList.h3
6 files changed, 92 insertions, 7 deletions
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index 6c5aa3af..9ff120bd 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -1137,7 +1137,27 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
}
newInstance->setName(instName);
- newInstance->setIconKey(instIcon);
+ if(instIcon != "default")
+ {
+ newInstance->setIconKey(instIcon);
+ }
+ else
+ {
+ instIcon = newInstance->iconKey();
+ auto importIconPath = PathCombine(newInstance->instanceRoot(), instIcon + ".png");
+ if (QFile::exists(importIconPath))
+ {
+ // import icon
+ auto iconList = ENV.icons();
+ // FIXME: check if the file is OK before removing the existing one...
+ if(iconList->iconFileExists(instIcon))
+ {
+ //FIXME: ask if icon should be overwritten. Show difference in the question dialog.
+ iconList->deleteIcon(instIcon);
+ }
+ iconList->installIcons({importIconPath});
+ }
+ }
newInstance->setGroupInitial(instGroup);
MMC->instances()->add(InstancePtr(newInstance));
MMC->instances()->saveGroupList();
@@ -1225,7 +1245,6 @@ void MainWindow::on_actionAddInstance_triggered()
const QUrl modpackUrl = newInstDlg.modpackUrl();
-
if (modpackUrl.isValid())
{
instanceFromZipPack(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), modpackUrl);
diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp
index 5d24c54b..ec376b1d 100644
--- a/application/dialogs/ExportInstanceDialog.cpp
+++ b/application/dialogs/ExportInstanceDialog.cpp
@@ -28,6 +28,8 @@
#include <QSaveFile>
#include "MMCStrings.h"
#include "SeparatorPrefixTree.h"
+#include "Env.h"
+#include <icons/IconList.h>
class PackIgnoreProxy : public QSortFilterProxyModel
{
@@ -333,6 +335,51 @@ ExportInstanceDialog::~ExportInstanceDialog()
delete ui;
}
+/// Save icon to instance's folder is needed
+void SaveIcon(InstancePtr m_instance)
+{
+ auto iconKey = m_instance->iconKey();
+ auto iconList = ENV.icons();
+ auto mmcIcon = iconList->icon(iconKey);
+ if(mmcIcon)
+ {
+ bool saveIcon = false;
+ switch(mmcIcon->type())
+ {
+ case MMCIcon::FileBased:
+ case MMCIcon::Transient:
+ saveIcon = true;
+ default:
+ break;
+ }
+ if(saveIcon)
+ {
+ auto & image = mmcIcon->m_images[mmcIcon->type()];
+ auto & icon = image.icon;
+ auto sizes = icon.availableSizes();
+ if(sizes.size() == 0)
+ {
+ return;
+ }
+ auto areaOf = [](QSize size)
+ {
+ return size.width() * size.height();
+ };
+ QSize largest = sizes[0];
+ // find variant with largest area
+ for(auto size: sizes)
+ {
+ if(areaOf(largest) < areaOf(size))
+ {
+ largest = size;
+ }
+ }
+ auto pixmap = icon.pixmap(largest);
+ pixmap.save(PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
+ }
+ }
+}
+
bool ExportInstanceDialog::doExport()
{
auto name = RemoveInvalidFilenameChars(m_instance->name());
@@ -356,6 +403,8 @@ bool ExportInstanceDialog::doExport()
}
}
+ SaveIcon(m_instance);
+
if (!MMCZip::compressDir(output, m_instance->instanceRoot(), name, &proxyModel->blockedPaths()))
{
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp
index d67d3ada..6cd651e4 100644
--- a/application/dialogs/NewInstanceDialog.cpp
+++ b/application/dialogs/NewInstanceDialog.cpp
@@ -65,7 +65,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
layout()->setSizeConstraint(QLayout::SetFixedSize);
setSelectedVersion(MMC->minecraftlist()->getRecommended(), true);
- InstIconKey = "infinity";
+ InstIconKey = "default";
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui
index 6cb0c97c..58a87354 100644
--- a/application/dialogs/NewInstanceDialog.ui
+++ b/application/dialogs/NewInstanceDialog.ui
@@ -41,10 +41,6 @@
</item>
<item>
<widget class="QToolButton" name="iconButton">
- <property name="icon">
- <iconset>
- <normaloff>:/icons/instances/infinity</normaloff>:/icons/instances/infinity</iconset>
- </property>
<property name="iconSize">
<size>
<width>80</width>
diff --git a/logic/icons/IconList.cpp b/logic/icons/IconList.cpp
index 40949392..45d39575 100644
--- a/logic/icons/IconList.cpp
+++ b/logic/icons/IconList.cpp
@@ -261,6 +261,24 @@ void IconList::installIcons(QStringList iconFiles)
}
}
+bool IconList::iconFileExists(QString key)
+{
+ auto iconEntry = icon(key);
+ if(!iconEntry)
+ {
+ return false;
+ }
+ return iconEntry->has(MMCIcon::FileBased);
+}
+
+const MMCIcon *IconList::icon(QString key)
+{
+ int iconIdx = getIconIndex(key);
+ if (iconIdx == -1)
+ return nullptr;
+ return &icons[iconIdx];
+}
+
bool IconList::deleteIcon(QString key)
{
int iconIdx = getIconIndex(key);
diff --git a/logic/icons/IconList.h b/logic/icons/IconList.h
index 07fb1379..cc2ba5c4 100644
--- a/logic/icons/IconList.h
+++ b/logic/icons/IconList.h
@@ -43,6 +43,7 @@ public:
bool addIcon(QString key, QString name, QString path, MMCIcon::Type type);
bool deleteIcon(QString key);
+ bool iconFileExists(QString key);
virtual QStringList mimeTypes() const;
virtual Qt::DropActions supportedDropActions() const;
@@ -52,6 +53,8 @@ public:
void installIcons(QStringList iconFiles);
+ const MMCIcon * icon(QString key);
+
void startWatching();
void stopWatching();