feat: Import all the things!
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
		@@ -109,13 +109,12 @@
 | 
			
		||||
#include "ui/dialogs/UpdateDialog.h"
 | 
			
		||||
#include "ui/dialogs/EditAccountDialog.h"
 | 
			
		||||
#include "ui/dialogs/ExportInstanceDialog.h"
 | 
			
		||||
#include "ui/dialogs/ImportResourcePackDialog.h"
 | 
			
		||||
#include "ui/dialogs/ImportResourceDialog.h"
 | 
			
		||||
#include "ui/themes/ITheme.h"
 | 
			
		||||
 | 
			
		||||
#include <minecraft/mod/ResourcePackFolderModel.h>
 | 
			
		||||
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
 | 
			
		||||
#include <minecraft/mod/TexturePackFolderModel.h>
 | 
			
		||||
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
 | 
			
		||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
 | 
			
		||||
#include "minecraft/mod/ModFolderModel.h"
 | 
			
		||||
#include "minecraft/WorldList.h"
 | 
			
		||||
 | 
			
		||||
#include "UpdateController.h"
 | 
			
		||||
#include "KonamiCode.h"
 | 
			
		||||
@@ -954,7 +953,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
 | 
			
		||||
        view->installEventFilter(this);
 | 
			
		||||
        view->setContextMenuPolicy(Qt::CustomContextMenu);
 | 
			
		||||
        connect(view, &QWidget::customContextMenuRequested, this, &MainWindow::showInstanceContextMenu);
 | 
			
		||||
        connect(view, &InstanceView::droppedURLs, this, &MainWindow::droppedURLs, Qt::QueuedConnection);
 | 
			
		||||
        connect(view, &InstanceView::droppedURLs, this, &MainWindow::processURLs, Qt::QueuedConnection);
 | 
			
		||||
 | 
			
		||||
        proxymodel = new InstanceProxyModel(this);
 | 
			
		||||
        proxymodel->setSourceModel(APPLICATION->instances().get());
 | 
			
		||||
@@ -1813,10 +1812,12 @@ void MainWindow::on_actionAddInstance_triggered()
 | 
			
		||||
    addInstance();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::droppedURLs(QList<QUrl> urls)
 | 
			
		||||
void MainWindow::processURLs(QList<QUrl> urls)
 | 
			
		||||
{
 | 
			
		||||
    // NOTE: This loop only processes one dropped file!
 | 
			
		||||
    for (auto& url : urls) {
 | 
			
		||||
        qDebug() << "Processing :" << url;
 | 
			
		||||
 | 
			
		||||
        // The isLocalFile() check below doesn't work as intended without an explicit scheme.
 | 
			
		||||
        if (url.scheme().isEmpty())
 | 
			
		||||
            url.setScheme("file");
 | 
			
		||||
@@ -1829,28 +1830,49 @@ void MainWindow::droppedURLs(QList<QUrl> urls)
 | 
			
		||||
        auto localFileName = url.toLocalFile();
 | 
			
		||||
        QFileInfo localFileInfo(localFileName);
 | 
			
		||||
 | 
			
		||||
        bool isResourcePack = ResourcePackUtils::validate(localFileInfo);
 | 
			
		||||
        bool isTexturePack = TexturePackUtils::validate(localFileInfo);
 | 
			
		||||
        auto type = ResourceUtils::identify(localFileInfo);
 | 
			
		||||
 | 
			
		||||
        if (!isResourcePack && !isTexturePack) {  // probably instance/modpack
 | 
			
		||||
        // bool is_resource = type;
 | 
			
		||||
 | 
			
		||||
        if (!(ResourceUtils::ValidResourceTypes.count(type) > 0)) {  // probably instance/modpack
 | 
			
		||||
            addInstance(localFileName);
 | 
			
		||||
            break;
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ImportResourcePackDialog dlg(this);
 | 
			
		||||
        ImportResourceDialog dlg(localFileName, type, this);
 | 
			
		||||
 | 
			
		||||
        if (dlg.exec() != QDialog::Accepted)
 | 
			
		||||
            break;
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        qDebug() << "Adding resource/texture pack" << localFileName << "to" << dlg.selectedInstanceKey;
 | 
			
		||||
        qDebug() << "Adding resource" << localFileName << "to" << dlg.selectedInstanceKey;
 | 
			
		||||
 | 
			
		||||
        auto inst = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
 | 
			
		||||
        auto minecraftInst = std::dynamic_pointer_cast<MinecraftInstance>(inst);
 | 
			
		||||
        if (isResourcePack)
 | 
			
		||||
 | 
			
		||||
        switch (type) {
 | 
			
		||||
            case PackedResourceType::ResourcePack:
 | 
			
		||||
            minecraftInst->resourcePackList()->installResource(localFileName);
 | 
			
		||||
        else if (isTexturePack)
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::TexturePack:
 | 
			
		||||
            minecraftInst->texturePackList()->installResource(localFileName);
 | 
			
		||||
        break;
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::DataPack:
 | 
			
		||||
            qWarning() << "Importing of Data Packs not supported at this time. Ignoring" << localFileName;
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::Mod:
 | 
			
		||||
            minecraftInst->loaderModList()->installMod(localFileName);
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::ShaderPack:
 | 
			
		||||
            minecraftInst->shaderPackList()->installResource(localFileName);
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::WorldSave:
 | 
			
		||||
            minecraftInst->worldList()->installWorld(localFileName);
 | 
			
		||||
            break;
 | 
			
		||||
            case PackedResourceType::UNKNOWN:
 | 
			
		||||
            default:
 | 
			
		||||
            qDebug() << "Can't Identify" << localFileName << "Ignoring it.";
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,7 @@ public:
 | 
			
		||||
 | 
			
		||||
    void updatesAllowedChanged(bool allowed);
 | 
			
		||||
 | 
			
		||||
    void droppedURLs(QList<QUrl> urls);
 | 
			
		||||
    void processURLs(QList<QUrl> urls);
 | 
			
		||||
signals:
 | 
			
		||||
    void isClosing();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
#include "ImportResourcePackDialog.h"
 | 
			
		||||
#include "ui_ImportResourcePackDialog.h"
 | 
			
		||||
#include "ImportResourceDialog.h"
 | 
			
		||||
#include "ui_ImportResourceDialog.h"
 | 
			
		||||
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
@@ -8,10 +8,11 @@
 | 
			
		||||
#include "InstanceList.h"
 | 
			
		||||
 | 
			
		||||
#include <InstanceList.h>
 | 
			
		||||
#include "ui/instanceview/InstanceProxyModel.h"
 | 
			
		||||
#include "ui/instanceview/InstanceDelegate.h"
 | 
			
		||||
#include "ui/instanceview/InstanceProxyModel.h"
 | 
			
		||||
 | 
			
		||||
ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog)
 | 
			
		||||
ImportResourceDialog::ImportResourceDialog(QString file_path, PackedResourceType type, QWidget* parent)
 | 
			
		||||
    : QDialog(parent), ui(new Ui::ImportResourceDialog), m_resource_type(type), m_file_path(file_path)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    setWindowModality(Qt::WindowModal);
 | 
			
		||||
@@ -40,15 +41,19 @@ ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(pa
 | 
			
		||||
    connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex)));
 | 
			
		||||
    connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
 | 
			
		||||
            SLOT(selectionChanged(QItemSelection, QItemSelection)));
 | 
			
		||||
 | 
			
		||||
    ui->label->setText(
 | 
			
		||||
        tr("Choose the instance you would like to import this %1 to.").arg(ResourceUtils::getPackedTypeName(m_resource_type)));
 | 
			
		||||
    ui->label_file_path->setText(tr("File: %1").arg(m_file_path));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportResourcePackDialog::activated(QModelIndex index)
 | 
			
		||||
void ImportResourceDialog::activated(QModelIndex index)
 | 
			
		||||
{
 | 
			
		||||
    selectedInstanceKey = index.data(InstanceList::InstanceIDRole).toString();
 | 
			
		||||
    accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
 | 
			
		||||
void ImportResourceDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
 | 
			
		||||
{
 | 
			
		||||
    if (selected.empty())
 | 
			
		||||
        return;
 | 
			
		||||
@@ -59,7 +64,7 @@ void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSe
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImportResourcePackDialog::~ImportResourcePackDialog()
 | 
			
		||||
ImportResourceDialog::~ImportResourceDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								launcher/ui/dialogs/ImportResourceDialog.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								launcher/ui/dialogs/ImportResourceDialog.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QItemSelection>
 | 
			
		||||
 | 
			
		||||
#include "ui/instanceview/InstanceProxyModel.h"
 | 
			
		||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ImportResourceDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ImportResourceDialog : public QDialog {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
   public:
 | 
			
		||||
    explicit ImportResourceDialog(QString file_path, PackedResourceType type, QWidget* parent = 0);
 | 
			
		||||
    ~ImportResourceDialog();
 | 
			
		||||
    InstanceProxyModel* proxyModel;
 | 
			
		||||
    QString selectedInstanceKey;
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    Ui::ImportResourceDialog* ui;
 | 
			
		||||
    PackedResourceType m_resource_type;
 | 
			
		||||
    QString m_file_path;
 | 
			
		||||
 | 
			
		||||
   private slots:
 | 
			
		||||
    void selectionChanged(QItemSelection, QItemSelection);
 | 
			
		||||
    void activated(QModelIndex);
 | 
			
		||||
};
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>ImportResourcePackDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="ImportResourcePackDialog">
 | 
			
		||||
 <class>ImportResourceDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="ImportResourceDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Choose instance to import</string>
 | 
			
		||||
   <string>Choose instance to import to</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item>
 | 
			
		||||
@@ -21,6 +21,13 @@
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QLabel" name="label_file_path">
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string/>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QListView" name="instanceView"/>
 | 
			
		||||
   </item>
 | 
			
		||||
@@ -41,7 +48,7 @@
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>ImportResourcePackDialog</receiver>
 | 
			
		||||
   <receiver>ImportResourceDialog</receiver>
 | 
			
		||||
   <slot>accept()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
@@ -57,7 +64,7 @@
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>rejected()</signal>
 | 
			
		||||
   <receiver>ImportResourcePackDialog</receiver>
 | 
			
		||||
   <receiver>ImportResourceDialog</receiver>
 | 
			
		||||
   <slot>reject()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QItemSelection>
 | 
			
		||||
 | 
			
		||||
#include "ui/instanceview/InstanceProxyModel.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ImportResourcePackDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ImportResourcePackDialog : public QDialog {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
   public:
 | 
			
		||||
    explicit ImportResourcePackDialog(QWidget* parent = 0);
 | 
			
		||||
    ~ImportResourcePackDialog();
 | 
			
		||||
    InstanceProxyModel* proxyModel;
 | 
			
		||||
    QString selectedInstanceKey;
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    Ui::ImportResourcePackDialog* ui;
 | 
			
		||||
 | 
			
		||||
   private slots:
 | 
			
		||||
    void selectionChanged(QItemSelection, QItemSelection);
 | 
			
		||||
    void activated(QModelIndex);
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user