Huge Java detection refactor, version dialogs on first run (no JavaPath set) and "auto detect" button
This commit is contained in:
@ -53,6 +53,7 @@
|
||||
#include "logic/lists/MinecraftVersionList.h"
|
||||
#include "logic/lists/LwjglVersionList.h"
|
||||
#include "logic/lists/IconList.h"
|
||||
#include "logic/lists/JavaVersionList.h"
|
||||
|
||||
#include "logic/net/LoginTask.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
@ -60,6 +61,7 @@
|
||||
#include "logic/MinecraftProcess.h"
|
||||
#include "logic/OneSixAssets.h"
|
||||
#include "logic/OneSixUpdate.h"
|
||||
#include "logic/JavaUtils.h"
|
||||
|
||||
#include "logic/LegacyInstance.h"
|
||||
|
||||
@ -701,3 +703,31 @@ void MainWindow::instanceEnded()
|
||||
this->show();
|
||||
ui->actionLaunchInstance->setEnabled(m_selectedInstance);
|
||||
}
|
||||
|
||||
void MainWindow::checkSetDefaultJava()
|
||||
{
|
||||
QString currentJavaPath = MMC->settings()->get("JavaPath").toString();
|
||||
if(currentJavaPath.isEmpty())
|
||||
{
|
||||
QLOG_DEBUG() << "Java path not set, showing Java selection dialog...";
|
||||
|
||||
JavaVersionPtr java;
|
||||
|
||||
VersionSelectDialog vselect(MMC->javalist().get(), tr("First run: select a Java version"), this, false);
|
||||
vselect.setResizeOn(2);
|
||||
vselect.exec();
|
||||
|
||||
if (!vselect.selectedVersion())
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this, tr("Invalid version selected"), tr("You didn't select a valid Java version, so MultiMC will select the default. "
|
||||
"You can change this in the settings dialog."));
|
||||
|
||||
JavaUtils ju;
|
||||
java = ju.GetDefaultJava();
|
||||
}
|
||||
|
||||
java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion());
|
||||
MMC->settings()->set("JavaPath", java->path);
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
// Browser Dialog
|
||||
void openWebPage(QUrl url);
|
||||
|
||||
void checkSetDefaultJava();
|
||||
|
||||
private slots:
|
||||
void onCatToggled(bool);
|
||||
|
||||
@ -128,7 +130,6 @@ protected:
|
||||
void setCatBackground(bool enabled);
|
||||
|
||||
private:
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
KCategoryDrawer *drawer;
|
||||
KCategorizedView *view;
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
#include "logic/JavaUtils.h"
|
||||
#include "gui/versionselectdialog.h"
|
||||
#include "logic/lists/JavaVersionList.h"
|
||||
|
||||
#include <settingsobject.h>
|
||||
#include <QFileDialog>
|
||||
@ -184,10 +186,17 @@ void SettingsDialog::loadSettings(SettingsObject *s)
|
||||
|
||||
void SettingsDialog::on_pushButton_clicked()
|
||||
{
|
||||
JavaUtils jut;
|
||||
auto javas = jut.FindJavaPaths();
|
||||
JavaVersionPtr java;
|
||||
|
||||
ui->javaPathTextBox->setText(std::get<JI_PATH>(javas.at(0)));
|
||||
VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true);
|
||||
vselect.setResizeOn(2);
|
||||
vselect.exec();
|
||||
|
||||
if (vselect.result() == QDialog::Accepted && vselect.selectedVersion())
|
||||
{
|
||||
java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion());
|
||||
ui->javaPathTextBox->setText(java->path);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::on_btnBrowse_clicked()
|
||||
|
@ -423,7 +423,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto-detect</string>
|
||||
<string>Auto-detect...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <logic/lists/BaseVersionList.h>
|
||||
#include <logic/tasks/Task.h>
|
||||
|
||||
VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent)
|
||||
VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, bool cancelable)
|
||||
: QDialog(parent), ui(new Ui::VersionSelectDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -40,7 +40,12 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title,
|
||||
|
||||
ui->listView->setModel(m_proxyModel);
|
||||
ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
|
||||
if(!cancelable)
|
||||
{
|
||||
ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
VersionSelectDialog::~VersionSelectDialog()
|
||||
@ -48,6 +53,13 @@ VersionSelectDialog::~VersionSelectDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void VersionSelectDialog::setResizeOn(int column)
|
||||
{
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::ResizeToContents);
|
||||
resizeOnColumn = column;
|
||||
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
|
||||
}
|
||||
|
||||
int VersionSelectDialog::exec()
|
||||
{
|
||||
QDialog::open();
|
||||
|
@ -33,7 +33,7 @@ class VersionSelectDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0);
|
||||
explicit VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent = 0, bool cancelable = true);
|
||||
~VersionSelectDialog();
|
||||
|
||||
virtual int exec();
|
||||
@ -44,6 +44,7 @@ public:
|
||||
BaseVersionPtr selectedVersion() const;
|
||||
|
||||
void setFilter(int column, QString filter);
|
||||
void setResizeOn(int column);
|
||||
|
||||
private slots:
|
||||
void on_refreshButton_clicked();
|
||||
@ -53,6 +54,8 @@ private:
|
||||
BaseVersionList *m_vlist;
|
||||
|
||||
QSortFilterProxyModel *m_proxyModel;
|
||||
|
||||
int resizeOnColumn = 0;
|
||||
};
|
||||
|
||||
#endif // VERSIONSELECTDIALOG_H
|
||||
|
Reference in New Issue
Block a user