Created
January 10, 2016 19:15
-
-
Save DASPRiD/8693ba8b4515599ef62e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7c0d660519a9c9a17c03a2cb53d579f66b35469c Mon Sep 17 00:00:00 2001 | |
From: Ben Scholzen <[email protected]> | |
Date: Sun, 10 Jan 2016 20:14:00 +0100 | |
Subject: [PATCH] Add feature to show editing time of a document in the | |
document information dialog | |
--- | |
krita/ui/KisDocument.cpp | 31 ++++++++++++++++++++++++++++++- | |
krita/ui/KisDocument.h | 2 ++ | |
libs/odf/KoDocumentInfo.cpp | 3 ++- | |
libs/widgets/KoDocumentInfoDlg.cpp | 26 ++++++++++++++++++++++++++ | |
libs/widgets/KoDocumentInfoDlg.h | 2 ++ | |
5 files changed, 62 insertions(+), 2 deletions(-) | |
diff --git a/krita/ui/KisDocument.cpp b/krita/ui/KisDocument.cpp | |
index ebd9dd8..450153b 100644 | |
--- a/krita/ui/KisDocument.cpp | |
+++ b/krita/ui/KisDocument.cpp | |
@@ -348,6 +348,9 @@ public: | |
bool modified; | |
bool readwrite; | |
+ QDateTime firstMod; | |
+ QDateTime lastMod; | |
+ | |
bool disregardAutosaveFailure; | |
KisNameServer *nserver; | |
@@ -571,6 +574,9 @@ KisDocument::KisDocument() | |
KConfigGroup cfgGrp(KisFactory::componentData().config(), "Undo"); | |
d->undoStack->setUndoLimit(cfgGrp.readEntry("UndoLimit", 1000)); | |
+ d->firstMod = QDateTime::currentDateTime(); | |
+ d->lastMod = QDateTime::currentDateTime(); | |
+ | |
connect(d->undoStack, SIGNAL(indexChanged(int)), this, SLOT(slotUndoStackIndexChanged(int))); | |
// preload the krita resources | |
@@ -601,7 +607,7 @@ KisDocument::~KisDocument() | |
// Despite being QObject they needs to be deleted before the image | |
delete d->shapeController; | |
- | |
+ | |
delete d->koShapeController; | |
if (d->image) { | |
@@ -1772,6 +1778,10 @@ void KisDocument::setModified() | |
void KisDocument::setModified(bool mod) | |
{ | |
+ if (mod) { | |
+ updateTimeElapsed(false); | |
+ } | |
+ | |
if (isAutosaving()) // ignore setModified calls due to autosaving | |
return; | |
@@ -1804,6 +1814,23 @@ void KisDocument::setModified(bool mod) | |
emit modified(mod); | |
} | |
+void KisDocument::updateTimeElapsed(bool forceStoreElapsed) | |
+{ | |
+ QDateTime now = QDateTime::currentDateTime(); | |
+ int firstModDelta = d->firstMod.secsTo(now); | |
+ int lastModDelta = d->lastMod.secsTo(now); | |
+ | |
+ if (lastModDelta > 30) { | |
+ d->docInfo->setAboutInfo("time-elapsed", QString::number(d->docInfo->aboutInfo("time-elapsed").toInt() + d->firstMod.secsTo(d->lastMod))); | |
+ d->firstMod = now; | |
+ } else if (firstModDelta > 60 || forceStoreElapsed) { | |
+ d->docInfo->setAboutInfo("time-elapsed", QString::number(d->docInfo->aboutInfo("time-elapsed").toInt() + firstModDelta)); | |
+ d->firstMod = now; | |
+ } | |
+ | |
+ d->lastMod = now; | |
+} | |
+ | |
QString KisDocument::prettyPathOrUrl() const | |
{ | |
QString _url( url().pathOrUrl() ); | |
@@ -2309,6 +2336,8 @@ bool KisDocument::save() | |
if ( d->m_file.isEmpty() ) // document was created empty | |
d->prepareSaving(); | |
+ updateTimeElapsed(true); | |
+ | |
DocumentProgressProxy *progressProxy = 0; | |
if (!d->document->progressProxy()) { | |
KisMainWindow *mainWindow = 0; | |
diff --git a/krita/ui/KisDocument.h b/krita/ui/KisDocument.h | |
index 09343cc..faeb880 100644 | |
--- a/krita/ui/KisDocument.h | |
+++ b/krita/ui/KisDocument.h | |
@@ -545,6 +545,8 @@ public: | |
*/ | |
void setModified(bool _mod); | |
+ void updateTimeElapsed(bool forceStoreElapsed); | |
+ | |
/** | |
* Initialize an empty document using default values | |
*/ | |
diff --git a/libs/odf/KoDocumentInfo.cpp b/libs/odf/KoDocumentInfo.cpp | |
index a02d9b2..6a38a56 100644 | |
--- a/libs/odf/KoDocumentInfo.cpp | |
+++ b/libs/odf/KoDocumentInfo.cpp | |
@@ -42,7 +42,7 @@ | |
KoDocumentInfo::KoDocumentInfo(QObject *parent) : QObject(parent) | |
{ | |
m_aboutTags << "title" << "description" << "subject" << "comments" | |
- << "keyword" << "initial-creator" << "editing-cycles" | |
+ << "keyword" << "initial-creator" << "editing-cycles" << "time-elapsed" | |
<< "date" << "creation-date" << "language"; | |
m_authorTags << "creator" << "initial" << "author-title" | |
@@ -51,6 +51,7 @@ KoDocumentInfo::KoDocumentInfo(QObject *parent) : QObject(parent) | |
<< "street" << "position" << "company"; | |
setAboutInfo("editing-cycles", "0"); | |
+ setAboutInfo("time-elapsed", "0"); | |
setAboutInfo("initial-creator", i18n("Unknown")); | |
setAboutInfo("creation-date", QDateTime::currentDateTime() | |
.toString(Qt::ISODate)); | |
diff --git a/libs/widgets/KoDocumentInfoDlg.cpp b/libs/widgets/KoDocumentInfoDlg.cpp | |
index c8f1730..0144a23 100644 | |
--- a/libs/widgets/KoDocumentInfoDlg.cpp | |
+++ b/libs/widgets/KoDocumentInfoDlg.cpp | |
@@ -214,6 +214,8 @@ void KoDocumentInfoDlg::initAboutTab() | |
d->aboutUi->lblRevision->setText(d->info->aboutInfo("editing-cycles")); | |
+ updateEditingTime(); | |
+ | |
if (doc && (doc->supportedSpecialFormats() & KoDocumentBase::SaveEncrypted)) { | |
if (doc->specialOutputFlag() == KoDocumentBase::SaveEncrypted) { | |
if (d->toggleEncryption) { | |
@@ -263,6 +265,30 @@ void KoDocumentInfoDlg::initAuthorTab() | |
d->authorUi->position->setText(d->info->authorInfo("position")); | |
} | |
+void KoDocumentInfoDlg::updateEditingTime() | |
+{ | |
+ const int timeElapsed = d->info->aboutInfo("time-elapsed").toInt(); | |
+ | |
+ const int secondsElapsed = timeElapsed % 60; | |
+ const int minutesElapsed = (timeElapsed / 60) % 60; | |
+ const int hoursElapsed = (timeElapsed / 3600) % 24; | |
+ const int daysElapsed = (timeElapsed / 86400) % 7; | |
+ const int weeksElapsed = timeElapsed / 604800; | |
+ | |
+ // @todo needs proper formatting / i18n | |
+ if (weeksElapsed > 0) { | |
+ d->aboutUi->lblEditing->setText(i18n("%1 weeks and %2 days", weeksElapsed, daysElapsed)); | |
+ } else if (daysElapsed > 0) { | |
+ d->aboutUi->lblEditing->setText(i18n("%1 days and %2 hours", daysElapsed, hoursElapsed)); | |
+ } else if (hoursElapsed > 0) { | |
+ d->aboutUi->lblEditing->setText(i18n("%1 hours and %2 minutes", hoursElapsed, minutesElapsed)); | |
+ } else if (minutesElapsed > 0) { | |
+ d->aboutUi->lblEditing->setText(i18n("%1 minutes and %2 seconds", minutesElapsed, secondsElapsed)); | |
+ } else { | |
+ d->aboutUi->lblEditing->setText(i18n("%1 seconds", secondsElapsed)); | |
+ } | |
+} | |
+ | |
void KoDocumentInfoDlg::slotApply() | |
{ | |
saveAboutData(); | |
diff --git a/libs/widgets/KoDocumentInfoDlg.h b/libs/widgets/KoDocumentInfoDlg.h | |
index 64d5bcc..979ab40 100644 | |
--- a/libs/widgets/KoDocumentInfoDlg.h | |
+++ b/libs/widgets/KoDocumentInfoDlg.h | |
@@ -95,6 +95,8 @@ private: | |
/** Saves the changed data back to the KoDocumentInfo class */ | |
void saveAboutData(); | |
+ void updateEditingTime(); | |
+ | |
void slotButtonClicked(int button); | |
class KoDocumentInfoDlgPrivate; | |
-- | |
1.9.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment