From bc98181ec274dfc933c5c0207943f9de1dbaf1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 9 Jan 2020 15:31:32 +0100 Subject: [PATCH] GH-2769 add an option to not copy play time when copying instances --- api/logic/InstanceCopyTask.cpp | 6 +++++- api/logic/InstanceCopyTask.h | 3 ++- application/MainWindow.cpp | 2 +- application/dialogs/CopyInstanceDialog.cpp | 19 +++++++++++++++++++ application/dialogs/CopyInstanceDialog.h | 3 +++ application/dialogs/CopyInstanceDialog.ui | 16 +++++++++++++++- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/api/logic/InstanceCopyTask.cpp b/api/logic/InstanceCopyTask.cpp index a576a0fd9..35adeaf9b 100644 --- a/api/logic/InstanceCopyTask.cpp +++ b/api/logic/InstanceCopyTask.cpp @@ -5,9 +5,10 @@ #include "pathmatcher/RegexpMatcher.h" #include -InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves) +InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime) { m_origInstance = origInstance; + m_keepPlaytime = keepPlaytime; if(!copySaves) { @@ -46,6 +47,9 @@ void InstanceCopyTask::copyFinished() InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath)); inst->setName(m_instName); inst->setIconKey(m_instIcon); + if(!m_keepPlaytime) { + inst->resetTimePlayed(); + } emitSucceeded(); } diff --git a/api/logic/InstanceCopyTask.h b/api/logic/InstanceCopyTask.h index 8dd55b408..6465e92d8 100644 --- a/api/logic/InstanceCopyTask.h +++ b/api/logic/InstanceCopyTask.h @@ -15,7 +15,7 @@ class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask { Q_OBJECT public: - explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves); + explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves, bool keepPlaytime); protected: //! Entry point for tasks. @@ -28,4 +28,5 @@ private: /* data */ QFuture m_copyFuture; QFutureWatcher m_copyFutureWatcher; std::unique_ptr m_matcher; + bool m_keepPlaytime; }; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index f308c439a..34ffc54b3 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -1358,7 +1358,7 @@ void MainWindow::on_actionCopyInstance_triggered() if (!copyInstDlg.exec()) return; - auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.shouldCopySaves()); + auto copyTask = new InstanceCopyTask(m_selectedInstance, copyInstDlg.shouldCopySaves(), copyInstDlg.shouldKeepPlaytime()); copyTask->setName(copyInstDlg.instName()); copyTask->setGroup(copyInstDlg.instGroup()); copyTask->setIcon(copyInstDlg.iconKey()); diff --git a/application/dialogs/CopyInstanceDialog.cpp b/application/dialogs/CopyInstanceDialog.cpp index 6100860c6..ab76e737f 100644 --- a/application/dialogs/CopyInstanceDialog.cpp +++ b/application/dialogs/CopyInstanceDialog.cpp @@ -53,6 +53,7 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->copySavesCheckbox->setChecked(m_copySaves); + ui->keepPlaytimeCheckbox->setChecked(m_keepPlaytime); } CopyInstanceDialog::~CopyInstanceDialog() @@ -123,3 +124,21 @@ void CopyInstanceDialog::on_copySavesCheckbox_stateChanged(int state) m_copySaves = true; } } + +bool CopyInstanceDialog::shouldKeepPlaytime() const +{ + return m_keepPlaytime; +} + + +void CopyInstanceDialog::on_keepPlaytimeCheckbox_stateChanged(int state) +{ + if(state == Qt::Unchecked) + { + m_keepPlaytime = false; + } + else if(state == Qt::Checked) + { + m_keepPlaytime = true; + } +} diff --git a/application/dialogs/CopyInstanceDialog.h b/application/dialogs/CopyInstanceDialog.h index d46e647cc..2b8475b72 100644 --- a/application/dialogs/CopyInstanceDialog.h +++ b/application/dialogs/CopyInstanceDialog.h @@ -40,16 +40,19 @@ public: QString instGroup() const; QString iconKey() const; bool shouldCopySaves() const; + bool shouldKeepPlaytime() const; private slots: void on_iconButton_clicked(); void on_instNameTextBox_textChanged(const QString &arg1); void on_copySavesCheckbox_stateChanged(int state); + void on_keepPlaytimeCheckbox_stateChanged(int state); private: Ui::CopyInstanceDialog *ui; QString InstIconKey; InstancePtr m_original; bool m_copySaves = true; + bool m_keepPlaytime = true; }; diff --git a/application/dialogs/CopyInstanceDialog.ui b/application/dialogs/CopyInstanceDialog.ui index bbb1bbb3b..fa6754556 100644 --- a/application/dialogs/CopyInstanceDialog.ui +++ b/application/dialogs/CopyInstanceDialog.ui @@ -10,7 +10,7 @@ 0 0 345 - 240 + 323 @@ -116,6 +116,13 @@ + + + + Keep play time + + + @@ -128,6 +135,13 @@ + + iconButton + instNameTextBox + groupBox + copySavesCheckbox + keepPlaytimeCheckbox +