From 0a187d0ad36f1223334a260b0c51c0b1b2935298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 15 Sep 2015 22:51:10 +0200 Subject: [PATCH] GH-1227 protect world from corruption --- application/pages/WorldListPage.cpp | 35 +++++++ application/pages/WorldListPage.h | 3 + application/pages/WorldListPage.ui | 153 +++++++++++++++------------- 3 files changed, 120 insertions(+), 71 deletions(-) diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp index 3b531d5dd..a952d02c6 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/WorldListPage.cpp @@ -156,6 +156,9 @@ void WorldListPage::on_mcEditBtn_clicked() return; } + if(!worldSafetyNagQuestion()) + return; + auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); #ifdef Q_OS_OSX @@ -230,6 +233,25 @@ void WorldListPage::on_addBtn_clicked() } } +bool WorldListPage::isWorldSafe(QModelIndex) +{ + return !m_inst->isRunning(); +} + +bool WorldListPage::worldSafetyNagQuestion() +{ + if(!isWorldSafe(getSelectedWorld())) + { + auto result = QMessageBox::question(this, tr("Copy World"), tr("Changing a world while Minecraft is running is potentially unsafe.\nDo you wish to proceed?")); + if(result == QMessageBox::No) + { + return false; + } + } + return true; +} + + void WorldListPage::on_copyBtn_clicked() { QModelIndex index = getSelectedWorld(); @@ -237,6 +259,10 @@ void WorldListPage::on_copyBtn_clicked() { return; } + + if(!worldSafetyNagQuestion()) + return; + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); auto world = (World *) worldVariant.value(); bool ok = false; @@ -255,6 +281,10 @@ void WorldListPage::on_renameBtn_clicked() { return; } + + if(!worldSafetyNagQuestion()) + return; + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); auto world = (World *) worldVariant.value(); @@ -266,3 +296,8 @@ void WorldListPage::on_renameBtn_clicked() world->rename(name); } } + +void WorldListPage::on_refreshBtn_clicked() +{ + m_worlds->update(); +} diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h index f0b0e7e90..5cf0966a0 100644 --- a/application/pages/WorldListPage.h +++ b/application/pages/WorldListPage.h @@ -68,6 +68,8 @@ protected: private: QModelIndex getSelectedWorld(); + bool isWorldSafe(QModelIndex index); + bool worldSafetyNagQuestion(); private: Ui::WorldListPage *ui; @@ -84,6 +86,7 @@ private slots: void on_addBtn_clicked(); void on_copyBtn_clicked(); void on_renameBtn_clicked(); + void on_refreshBtn_clicked(); void on_viewFolderBtn_clicked(); void worldChanged(const QModelIndex ¤t, const QModelIndex &previous); }; diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui index b5fd33daf..b172fed89 100644 --- a/application/pages/WorldListPage.ui +++ b/application/pages/WorldListPage.ui @@ -36,7 +36,86 @@ Tab 1 - + + + + + + Add + + + + + + + + + + Rename + + + + + + + Copy + + + + + + + &Remove + + + + + + + MCEdit + + + + + + + + + + Copy Seed + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Refresh + + + + + + + &View Folder + + + + + + @@ -61,75 +140,6 @@ - - - - - - Add - - - - - - - Copy - - - - - - - Rename - - - - - - - &Remove - - - - - - - - - - MCEdit - - - - - - - Copy Seed - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - &View Folder - - - - - @@ -148,11 +158,12 @@ tabWidget worldTreeView addBtn - copyBtn renameBtn + copyBtn rmWorldBtn mcEditBtn copySeedBtn + refreshBtn viewFolderBtn