summaryrefslogtreecommitdiffstats
path: root/application/pages
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-15 22:51:10 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-15 22:51:10 +0200
commit0a187d0ad36f1223334a260b0c51c0b1b2935298 (patch)
treed05214e6dbe1204c11f291b82509d5aa80ad061b /application/pages
parent8d3f13c4478f7e99a32a0804d57ac2ece05d7e92 (diff)
downloadMultiMC-0a187d0ad36f1223334a260b0c51c0b1b2935298.tar
MultiMC-0a187d0ad36f1223334a260b0c51c0b1b2935298.tar.gz
MultiMC-0a187d0ad36f1223334a260b0c51c0b1b2935298.tar.lz
MultiMC-0a187d0ad36f1223334a260b0c51c0b1b2935298.tar.xz
MultiMC-0a187d0ad36f1223334a260b0c51c0b1b2935298.zip
GH-1227 protect world from corruption
Diffstat (limited to 'application/pages')
-rw-r--r--application/pages/WorldListPage.cpp35
-rw-r--r--application/pages/WorldListPage.h3
-rw-r--r--application/pages/WorldListPage.ui79
3 files changed, 83 insertions, 34 deletions
diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp
index 3b531d5d..a952d02c 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<void *>();
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<void *>();
@@ -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 f0b0e7e9..5cf0966a 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 &current, const QModelIndex &previous);
};
diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui
index b5fd33da..b172fed8 100644
--- a/application/pages/WorldListPage.ui
+++ b/application/pages/WorldListPage.ui
@@ -36,32 +36,7 @@
<string>Tab 1</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QTreeView" name="worldTreeView">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="acceptDrops">
- <bool>true</bool>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::DragDrop</enum>
- </property>
- <property name="sortingEnabled">
- <bool>true</bool>
- </property>
- <property name="allColumnsShowFocus">
- <bool>true</bool>
- </property>
- <attribute name="headerStretchLastSection">
- <bool>false</bool>
- </attribute>
- </widget>
- </item>
- <item row="0" column="1">
+ <item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addBtn">
@@ -71,16 +46,19 @@
</widget>
</item>
<item>
- <widget class="QPushButton" name="copyBtn">
+ <widget class="LineSeparator" name="separator" native="true"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="renameBtn">
<property name="text">
- <string>Copy</string>
+ <string>Rename</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="renameBtn">
+ <widget class="QPushButton" name="copyBtn">
<property name="text">
- <string>Rename</string>
+ <string>Copy</string>
</property>
</widget>
</item>
@@ -92,9 +70,6 @@
</widget>
</item>
<item>
- <widget class="LineSeparator" name="separator" native="true"/>
- </item>
- <item>
<widget class="QPushButton" name="mcEditBtn">
<property name="text">
<string>MCEdit</string>
@@ -102,6 +77,9 @@
</widget>
</item>
<item>
+ <widget class="LineSeparator" name="separator_2" native="true"/>
+ </item>
+ <item>
<widget class="QPushButton" name="copySeedBtn">
<property name="text">
<string>Copy Seed</string>
@@ -122,6 +100,13 @@
</spacer>
</item>
<item>
+ <widget class="QPushButton" name="refreshBtn">
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QPushButton" name="viewFolderBtn">
<property name="text">
<string>&amp;View Folder</string>
@@ -130,6 +115,31 @@
</item>
</layout>
</item>
+ <item row="0" column="1">
+ <widget class="QTreeView" name="worldTreeView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DragDrop</enum>
+ </property>
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <attribute name="headerStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
@@ -148,11 +158,12 @@
<tabstop>tabWidget</tabstop>
<tabstop>worldTreeView</tabstop>
<tabstop>addBtn</tabstop>
- <tabstop>copyBtn</tabstop>
<tabstop>renameBtn</tabstop>
+ <tabstop>copyBtn</tabstop>
<tabstop>rmWorldBtn</tabstop>
<tabstop>mcEditBtn</tabstop>
<tabstop>copySeedBtn</tabstop>
+ <tabstop>refreshBtn</tabstop>
<tabstop>viewFolderBtn</tabstop>
</tabstops>
<resources/>