diff options
Diffstat (limited to 'gui/mainwindow.cpp')
-rw-r--r-- | gui/mainwindow.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5b6e034c..52971acf 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -63,7 +63,6 @@ #include <logic/IconListModel.h> #include <logic/LegacyInstance.h> -#include "instancemodel.h" #include "instancedelegate.h" #include "IconPickerDialog.h" #include "LabeledToolButton.h" @@ -108,12 +107,11 @@ MainWindow::MainWindow ( QWidget *parent ) : view->setUniformItemWidths(true); view->installEventFilter(this); - model = new InstanceModel ( instList,this ); proxymodel = new InstanceProxyModel ( this ); proxymodel->setSortRole ( KCategorizedSortFilterProxyModel::CategorySortRole ); proxymodel->setFilterRole ( KCategorizedSortFilterProxyModel::CategorySortRole ); //proxymodel->setDynamicSortFilter ( true ); - proxymodel->setSourceModel ( model ); + proxymodel->setSourceModel ( &instList ); proxymodel->sort ( 0 ); view->setFrameShape ( QFrame::NoFrame ); @@ -137,6 +135,7 @@ MainWindow::MainWindow ( QWidget *parent ) : this, SLOT(instanceChanged(const QModelIndex &,const QModelIndex &)) ); + connect(&instList,SIGNAL(dataIsInvalid()),SLOT(selectionBad())); // Load the instances. FIXME: this is not the place I'd say. instList.loadList(); @@ -160,7 +159,6 @@ MainWindow::~MainWindow() { delete ui; delete proxymodel; - delete model; delete drawer; delete assets_downloader; } @@ -228,7 +226,7 @@ void MainWindow::instanceActivated ( QModelIndex index ) { if(!index.isValid()) return; - BaseInstance * inst = (BaseInstance *) index.data(InstanceModel::InstancePointerRole).value<void *>(); + BaseInstance * inst = (BaseInstance *) index.data(InstanceList::InstancePointerRole).value<void *>(); doLogin(); } @@ -380,8 +378,7 @@ void MainWindow::on_actionDeleteInstance_triggered() QString("This is permanent! Are you sure?\nAbout to delete: ") + m_selectedInstance->name()); if (response == QMessageBox::Yes) { - QDir(m_selectedInstance->instanceRoot()).removeRecursively(); - instList.loadList(); + m_selectedInstance->nuke(); } } } @@ -596,25 +593,32 @@ void MainWindow::on_actionInstanceSettings_triggered() void MainWindow::instanceChanged( const QModelIndex& current, const QModelIndex& previous ) { - QString iconKey = "infinity"; - - if(current.isValid() && nullptr != (m_selectedInstance = (BaseInstance *) current.data(InstanceModel::InstancePointerRole).value<void *>())) + if(current.isValid() && nullptr != (m_selectedInstance = (BaseInstance *) current.data(InstanceList::InstancePointerRole).value<void *>())) { ui->instanceToolBar->setEnabled(true); - iconKey = m_selectedInstance->iconKey(); + QString iconKey = m_selectedInstance->iconKey(); renameButton->setText(m_selectedInstance->name()); ui->actionChangeInstLWJGLVersion->setEnabled(m_selectedInstance->menuActionEnabled("actionChangeInstLWJGLVersion")); ui->actionEditInstMods->setEnabled(m_selectedInstance->menuActionEnabled("actionEditInstMods")); statusBar()->clearMessage(); statusBar()->showMessage(m_selectedInstance->getStatusbarDescription()); + IconList * iconListModel = IconList::instance(); + auto ico =iconListModel->getIcon(iconKey); + ui->actionChangeInstIcon->setIcon(ico); } else { - statusBar()->clearMessage(); - ui->instanceToolBar->setEnabled(false); - renameButton->setText("Rename Instance"); + selectionBad(); } - +} + +void MainWindow::selectionBad() +{ + m_selectedInstance = nullptr; + QString iconKey = "infinity"; + statusBar()->clearMessage(); + ui->instanceToolBar->setEnabled(false); + renameButton->setText("Rename Instance"); IconList * iconListModel = IconList::instance(); auto ico =iconListModel->getIcon(iconKey); ui->actionChangeInstIcon->setIcon(ico); @@ -622,7 +626,6 @@ void MainWindow::instanceChanged( const QModelIndex& current, const QModelIndex& - void MainWindow::on_actionEditInstNotes_triggered() { if (!m_selectedInstance) |