aboutsummaryrefslogtreecommitdiff
path: root/smartpensyncer.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-06-21 20:49:42 +0200
committerJavier <dev.git@javispedro.com>2015-06-21 20:49:42 +0200
commitd334906cdb5ad988c9e3ad1e9827eab774d1a283 (patch)
treeb0207db387da9fab419ae25f4ebcb995636da6d4 /smartpensyncer.cc
parenta27ad0c43b3b5202fa71e1e857ba7955df46338d (diff)
downloadscribiu-d334906cdb5ad988c9e3ad1e9827eab774d1a283.tar.gz
scribiu-d334906cdb5ad988c9e3ad1e9827eab774d1a283.zip
use pen time, not host wall clock to store lastsync timestamp
Diffstat (limited to 'smartpensyncer.cc')
-rw-r--r--smartpensyncer.cc75
1 files changed, 44 insertions, 31 deletions
diff --git a/smartpensyncer.cc b/smartpensyncer.cc
index cdf9bc6..f076ff9 100644
--- a/smartpensyncer.cc
+++ b/smartpensyncer.cc
@@ -48,11 +48,11 @@ class TimestampFile
public:
TimestampFile(const QString &path);
- QDateTime get();
- void set();
+ Smartpen::PenTime get();
+ void set(Smartpen::PenTime time);
private:
- QFileInfo _fi;
+ QFile _f;
};
LockFile::LockFile(const QString &path)
@@ -98,29 +98,34 @@ bool LockFile::lock()
}
TimestampFile::TimestampFile(const QString &path)
- : _fi(path)
+ : _f(path)
{
}
-QDateTime TimestampFile::get()
+Smartpen::PenTime TimestampFile::get()
{
- qDebug() << "Checking timestamp" << _fi.filePath();
- if (_fi.exists()) {
- return _fi.lastModified();
- } else {
- return QDateTime();
+ if (_f.exists()) {
+ if (_f.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ QString data = QString::fromAscii(_f.readLine(24));
+ _f.close();
+ return data.toLongLong();
+ } else {
+ qWarning() << "Could not read timestamp file:" << _f.fileName();
+ }
}
+
+ return 0;
}
-void TimestampFile::set()
+void TimestampFile::set(Smartpen::PenTime time)
{
- QFile f(_fi.filePath());
- if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
- qWarning() << "Could not set timestamp file:" << _fi.absoluteFilePath();
+ if (_f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+ _f.write(QString::number(time).toAscii());
+ _f.close();
+ } else {
+ qWarning() << "Could not set timestamp file:" << _f.fileName();
return;
}
- f.close();
- _fi.refresh();
}
}
@@ -200,34 +205,48 @@ bool SmartpenSyncer::syncPen()
return false;
}
- TimestampFile lastSync(_penDataDir.filePath(".lastsync"));
- QList<Smartpen::ChangeReport> changes = _pen->getChangeList(lastSync.get());
+ TimestampFile lastSyncFile(_penDataDir.filePath(".lastsync"));
+ Smartpen::PenTime lastSync = lastSyncFile.get();
+ if (lastSync != 0) lastSync += 1; // We want the changes _from_ the last sync
+
+ QList<Smartpen::ChangeReport> changes = _pen->getChangeList(lastSync);
+
+ Smartpen::PenTime changesEndTime = 0;
foreach(const Smartpen::ChangeReport &change, changes) {
if (!change.guid.isEmpty()) {
qDebug() << "Synchronizing guid: " << change.guid << change.title;
- if (!syncNotebook(change)) {
+ if (!syncNotebook(lastSync, change)) {
return false;
}
} else if (change.className == "com.livescribe.paperreplay.PaperReplay") {
qDebug() << "Synchronizing paper replay";
- if (!syncPaperReplay()) {
+ if (!syncPaperReplay(lastSync, change)) {
return false;
}
+ } else {
+ qWarning() << "Unknown change report";
+ return false;
}
if (_aborted) {
qWarning() << "Aborting sync";
return false;
}
+
+ if (change.endTime > changesEndTime) {
+ changesEndTime = change.endTime;
+ }
}
- lastSync.set();
+ if (changesEndTime > 0) {
+ lastSyncFile.set(changesEndTime);
+ }
return true;
}
-bool SmartpenSyncer::syncNotebook(const Smartpen::ChangeReport &change)
+bool SmartpenSyncer::syncNotebook(Smartpen::PenTime lastSync, const Smartpen::ChangeReport &change)
{
QDir notebookDir(_penDataDir.filePath(change.title + ".afd"));
if (!notebookDir.exists()) {
@@ -242,19 +261,16 @@ bool SmartpenSyncer::syncNotebook(const Smartpen::ChangeReport &change)
return false;
}
- TimestampFile lastSync(notebookDir.filePath(".lastsync"));
- QByteArray lspData = _pen->getLspData(change.guid, lastSync.get());
+ QByteArray lspData = _pen->getLspData(change.guid, lastSync);
if (!extractZip(lspData, notebookDir)) {
return false;
}
- lastSync.set();
-
return true;
}
-bool SmartpenSyncer::syncPaperReplay()
+bool SmartpenSyncer::syncPaperReplay(Smartpen::PenTime lastSync, const Smartpen::ChangeReport &)
{
QDir replayDir(_penDataDir.filePath(PAPER_REPLAY));
if (!replayDir.exists()) {
@@ -269,15 +285,12 @@ bool SmartpenSyncer::syncPaperReplay()
return false;
}
- TimestampFile lastSync(replayDir.filePath(".lastsync"));
- QByteArray replayData = _pen->getPaperReplay(lastSync.get());
+ QByteArray replayData = _pen->getPaperReplay(lastSync);
if (!extractZip(replayData, replayDir)) {
return false;
}
- lastSync.set();
-
return true;
}