Implement instance sorting options.
This commit is contained in:
		| @@ -291,10 +291,6 @@ void MultiMC::initGlobalSettings() | ||||
| 	m_settings->registerSetting(new Setting("ShowConsole", true)); | ||||
| 	m_settings->registerSetting(new Setting("AutoCloseConsole", true)); | ||||
|  | ||||
| 	// Toolbar settings | ||||
| 	m_settings->registerSetting(new Setting("InstanceToolbarVisible", true)); | ||||
| 	m_settings->registerSetting(new Setting("InstanceToolbarPosition", QPoint())); | ||||
|  | ||||
| 	// Console Colors | ||||
| 	//	m_settings->registerSetting(new Setting("SysMessageColor", QColor(Qt::blue))); | ||||
| 	//	m_settings->registerSetting(new Setting("StdOutColor", QColor(Qt::black))); | ||||
| @@ -328,6 +324,8 @@ void MultiMC::initGlobalSettings() | ||||
| 	// Shall the main window hide on instance launch | ||||
| 	m_settings->registerSetting(new Setting("NoHide", false)); | ||||
|  | ||||
| 	m_settings->registerSetting(new Setting("InstSortMode", "Name")); | ||||
|  | ||||
| 	// Persistent value for the client ID | ||||
| 	m_settings->registerSetting(new Setting("YggdrasilClientToken", "")); | ||||
| 	QString currentYggID = m_settings->get("YggdrasilClientToken").toString(); | ||||
|   | ||||
| @@ -23,6 +23,15 @@ class JavaVersionList; | ||||
| #endif | ||||
| #define MMC (static_cast<MultiMC *>(QCoreApplication::instance())) | ||||
|  | ||||
| // FIXME: possibly move elsewhere | ||||
| enum InstSortMode | ||||
| { | ||||
| 	// Sort alphabetically by name. | ||||
| 	Sort_Name, | ||||
| 	// Sort by which instance was launched most recently. | ||||
| 	Sort_LastLaunch, | ||||
| }; | ||||
|  | ||||
| class MultiMC : public QApplication | ||||
| { | ||||
| 	Q_OBJECT | ||||
|   | ||||
| @@ -129,8 +129,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi | ||||
| 		view->installEventFilter(this); | ||||
|  | ||||
| 		proxymodel = new InstanceProxyModel(this); | ||||
| 		proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); | ||||
| 		proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); | ||||
| //		proxymodel->setSortRole(KCategorizedSortFilterProxyModel::CategorySortRole); | ||||
| 		//proxymodel->setFilterRole(KCategorizedSortFilterProxyModel::CategorySortRole); | ||||
| 		// proxymodel->setDynamicSortFilter ( true ); | ||||
|  | ||||
| 		// FIXME: instList should be global-ish, or at least not tied to the main window... | ||||
| @@ -420,6 +420,9 @@ void MainWindow::on_actionSettings_triggered() | ||||
| { | ||||
| 	SettingsDialog dialog(this); | ||||
| 	dialog.exec(); | ||||
| 	//FIXME: quick HACK to make this work. improve, optimize. | ||||
| 	proxymodel->invalidate(); | ||||
| 	proxymodel->sort(0); | ||||
| } | ||||
|  | ||||
| void MainWindow::on_actionReportBug_triggered() | ||||
|   | ||||
| @@ -33,6 +33,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se | ||||
| { | ||||
| 	MultiMCPlatform::fixWM_CLASS(this); | ||||
| 	ui->setupUi(this); | ||||
| 	ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); | ||||
| 	ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); | ||||
|  | ||||
| 	loadSettings(MMC->settings().get()); | ||||
| 	updateCheckboxStuff(); | ||||
| @@ -165,6 +167,20 @@ void SettingsDialog::applySettings(SettingsObject *s) | ||||
| 	// Custom Commands | ||||
| 	s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); | ||||
| 	s->set("PostExitCommand", ui->postExitCmdTextBox->text()); | ||||
|  | ||||
| 	auto sortMode = (InstSortMode) ui->sortingModeGroup->checkedId(); | ||||
| 	switch(sortMode) | ||||
| 	{ | ||||
| 		case Sort_LastLaunch: | ||||
| 			s->set("InstSortMode", "LastLaunch"); | ||||
| 			break; | ||||
| 		case Sort_Name: | ||||
| 		default: | ||||
| 			s->set("InstSortMode", "Name"); | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| 	s->set("PostExitCommand", ui->postExitCmdTextBox->text()); | ||||
| } | ||||
|  | ||||
| void SettingsDialog::loadSettings(SettingsObject *s) | ||||
| @@ -195,6 +211,17 @@ void SettingsDialog::loadSettings(SettingsObject *s) | ||||
| 	ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); | ||||
| 	ui->permGenSpinBox->setValue(s->get("PermGen").toInt()); | ||||
|  | ||||
| 	QString sortMode = s->get("InstSortMode").toString(); | ||||
|  | ||||
| 	if(sortMode == "LastLaunch") | ||||
| 	{ | ||||
| 		ui->sortLastLaunchedBtn->setChecked(true); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ui->sortByNameBtn->setChecked(true); | ||||
| 	} | ||||
|  | ||||
| 	// Java Settings | ||||
| 	ui->javaPathTextBox->setText(s->get("JavaPath").toString()); | ||||
| 	ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); | ||||
|   | ||||
| @@ -422,7 +422,13 @@ bool InstanceProxyModel::subSortLessThan(const QModelIndex &left, | ||||
| { | ||||
| 	BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer()); | ||||
| 	BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer()); | ||||
| 	// kDebug() << *pdataLeft << *pdataRight; | ||||
| 	return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; | ||||
| 	// return pdataLeft->name() < pdataRight->name(); | ||||
| 	QString sortMode = MMC->settings()->get("InstSortMode").toString(); | ||||
| 	if(sortMode == "LastLaunch") | ||||
| 	{ | ||||
| 		return pdataLeft->lastLaunch() > pdataRight->lastLaunch(); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user