aboutsummaryrefslogtreecommitdiff
path: root/smartpensyncer.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2021-09-12 19:41:12 +0200
committerJavier <dev.git@javispedro.com>2021-09-12 19:41:12 +0200
commitac7b085449fb49f54225d22c7c229da6ad120e2b (patch)
tree7910cc8c9a3268dbacbbe434c7f3cea4eedafd3d /smartpensyncer.cc
parent66dd35254724ec5d4471a8be71f92e06cf0fa8e8 (diff)
downloadscribiu-ac7b085449fb49f54225d22c7c229da6ad120e2b.tar.gz
scribiu-ac7b085449fb49f54225d22c7c229da6ad120e2b.zip
remove PEN_EPOCH mistake and get usertime from the pen
Diffstat (limited to 'smartpensyncer.cc')
-rw-r--r--smartpensyncer.cc32
1 files changed, 21 insertions, 11 deletions
diff --git a/smartpensyncer.cc b/smartpensyncer.cc
index 9149f33..794b7c5 100644
--- a/smartpensyncer.cc
+++ b/smartpensyncer.cc
@@ -26,7 +26,7 @@
#include "notebookmodel.h"
#include "smartpensyncer.h"
-#define BUFFER_SIZE 16 * 1024
+#define BUFFER_SIZE 128 * 1024
namespace {
class LockFile
@@ -108,7 +108,7 @@ Smartpen::PenTime TimestampFile::get()
if (_f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString data = QString::fromUtf8(_f.readLine(32));
_f.close();
- return data.toLongLong();
+ return data.toULongLong();
} else {
qWarning() << "Could not read timestamp file:" << _f.fileName();
}
@@ -219,10 +219,22 @@ bool SmartpenSyncer::syncPen()
return false;
}
- TimestampFile lastSyncFile(_penDataDir.filePath(".lastsync"));
+ // Get the current user time offset from the pen
+ // and store it so that we have it even when the pen is offline
+ TimestampFile userTimeFile(_penDataDir.filePath(PEN_USER_TIME_FILE));
+ Smartpen::PenTime userTime = _pen->getPenTime(Smartpen::PenUserTime);
+ userTimeFile.set(userTime);
+ qDebug() << "pen time base:" << userTime << Smartpen::fromPenTime(userTime, 0);
+
+ Smartpen::PenTime penTime = _pen->getPenTime(Smartpen::PenRtcTime);
+ qDebug() << "pen current time:" << penTime << Smartpen::fromPenTime(userTime, penTime);
+
+ // Read when is the last time we synchronized with this pen (in PenTime, not user time)
+ TimestampFile lastSyncFile(_penDataDir.filePath(PEN_LAST_SYNC_FILE));
Smartpen::PenTime lastSync = lastSyncFile.get();
if (lastSync != 0) lastSync += 1; // We want the changes _from_ the last sync
+ // Ask the pen for all the changes which happened since the last sync time
QList<Smartpen::ChangeReport> changes = _pen->getChangeList(lastSync);
Smartpen::PenTime changesEndTime = 0;
@@ -269,9 +281,9 @@ bool SmartpenSyncer::syncNotebook(Smartpen::PenTime lastSync, const Smartpen::Ch
}
}
- LockFile lock(notebookDir.filePath(".sync.lck"));
+ LockFile lock(notebookDir.filePath(PEN_SYNC_LOCK_FILE));
if (!lock.lock()) {
- qWarning() << "Notebook is already being synchronized; delete this file if it is not:" << notebookDir.absoluteFilePath(".sync.lck");
+ qWarning() << "Notebook is already being synchronized; delete this file if it is not:" << notebookDir.absoluteFilePath(PEN_SYNC_LOCK_FILE);
return false;
}
@@ -293,9 +305,9 @@ bool SmartpenSyncer::syncPaperReplay(Smartpen::PenTime lastSync, const Smartpen:
}
}
- LockFile lock(replayDir.filePath(".sync.lck"));
+ LockFile lock(replayDir.filePath(PEN_SYNC_LOCK_FILE));
if (!lock.lock()) {
- qWarning() << "Paper replay is already being synchronized; delete this file if it is not:" << replayDir.absoluteFilePath(".sync.lck");
+ qWarning() << "Paper replay is already being synchronized; delete this file if it is not:" << replayDir.absoluteFilePath(PEN_SYNC_LOCK_FILE);
return false;
}
@@ -319,7 +331,7 @@ bool SmartpenSyncer::extractZip(QByteArray &zipData, QDir &dir)
return false;
}
- QScopedArrayPointer<char> buffer(new char[BUFFER_SIZE]);
+ QByteArray buffer(BUFFER_SIZE, Qt::Uninitialized);
for (bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
QString zipName = zip.getCurrentFileName();
@@ -350,7 +362,7 @@ bool SmartpenSyncer::extractZip(QByteArray &zipData, QDir &dir)
}
while (!zipFile.atEnd()) {
- qint64 read = zipFile.read(buffer.data(), BUFFER_SIZE);
+ qint64 read = zipFile.read(buffer.data(), buffer.size());
if (read <= 0) {
qWarning() << "short read on:" << zipName;
zipFile.close();
@@ -368,8 +380,6 @@ bool SmartpenSyncer::extractZip(QByteArray &zipData, QDir &dir)
zipFile.close();
}
- buffer.reset();
-
if (zip.getZipError() == UNZ_OK) {
return true;
} else {