aboutsummaryrefslogtreecommitdiff
path: root/smartpensyncer.cc
diff options
context:
space:
mode:
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;
}