summaryrefslogtreecommitdiffstats
path: root/logic/BaseInstance.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-22 01:06:45 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-22 01:06:45 +0200
commit9ba1cd15e7f902cae705ff22451e4f76ad0d71ab (patch)
treeaafc4d87d81489d3e8ab782c8b7922c44f1ea192 /logic/BaseInstance.cpp
parentb10761711234b69cf8509bacb055f7d5c3c021e8 (diff)
downloadMultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.gz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.lz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.xz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.zip
GH-1217 add simple instance play time tracking
Not reliable in the face of crashes... but what is?
Diffstat (limited to 'logic/BaseInstance.cpp')
-rw-r--r--logic/BaseInstance.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp
index 3e02235e..b0235b47 100644
--- a/logic/BaseInstance.cpp
+++ b/logic/BaseInstance.cpp
@@ -38,6 +38,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
m_settings->registerSetting("notes", "");
m_settings->registerSetting("lastLaunchTime", 0);
+ m_settings->registerSetting("totalTimePlayed", 0);
// Custom Commands
auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
@@ -93,9 +94,31 @@ bool BaseInstance::isRunning() const
void BaseInstance::setRunning(bool running)
{
+ if(running && !m_isRunning)
+ {
+ m_timeStarted = QDateTime::currentDateTime();
+ }
+ else if(!running && m_isRunning)
+ {
+ qint64 current = settings()->get("totalTimePlayed").toLongLong();
+ QDateTime timeEnded = QDateTime::currentDateTime();
+ settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
+ emit propertiesChanged(this);
+ }
m_isRunning = running;
}
+int64_t BaseInstance::totalTimePlayed()
+{
+ qint64 current = settings()->get("totalTimePlayed").toLongLong();
+ if(m_isRunning)
+ {
+ QDateTime timeNow = QDateTime::currentDateTime();
+ return current + m_timeStarted.secsTo(timeNow);
+ }
+ return current;
+}
+
QString BaseInstance::instanceType() const
{
return m_settings->get("InstanceType").toString();