aboutsummaryrefslogtreecommitdiff
path: root/smartpensyncer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'smartpensyncer.cc')
-rw-r--r--smartpensyncer.cc48
1 files changed, 34 insertions, 14 deletions
diff --git a/smartpensyncer.cc b/smartpensyncer.cc
index f076ff9..8047f4e 100644
--- a/smartpensyncer.cc
+++ b/smartpensyncer.cc
@@ -20,7 +20,7 @@
#include <QtCore/QScopedArrayPointer>
#include <QtCore/QThread>
#include <QtCore/QDebug>
-#include <quazip/quazipfile.h>
+#include <quazip5/quazipfile.h>
#include <cstdio>
#include "paperreplay.h"
#include "notebookmodel.h"
@@ -79,7 +79,7 @@ bool LockFile::lock()
QFileInfo info(_path);
if (info.exists()) {
- if (info.created().secsTo(QDateTime::currentDateTime()) > 10 * 60) {
+ if (info.lastModified().secsTo(QDateTime::currentDateTime()) > 10 * 60) {
if (QFile::remove(info.filePath())) {
qDebug() << "Removing stale lock file:" << info.absoluteFilePath();
}
@@ -106,7 +106,7 @@ Smartpen::PenTime TimestampFile::get()
{
if (_f.exists()) {
if (_f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- QString data = QString::fromAscii(_f.readLine(24));
+ QString data = QString::fromUtf8(_f.readLine(32));
_f.close();
return data.toLongLong();
} else {
@@ -120,18 +120,21 @@ Smartpen::PenTime TimestampFile::get()
void TimestampFile::set(Smartpen::PenTime time)
{
if (_f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
- _f.write(QString::number(time).toAscii());
+ _f.write(QString::number(time).toUtf8());
_f.close();
} else {
qWarning() << "Could not set timestamp file:" << _f.fileName();
return;
}
}
-}
+} /* anonymous namespace */
SmartpenSyncer::SmartpenSyncer(const Smartpen::Address &addr, QObject *parent) :
- QThread(parent), _addr(addr), _pen(new Smartpen(this)), _errored(false), _aborted(false)
+ QThread(parent),
+ _addr(addr), _errored(false), _aborted(false),
+ _pen(new Smartpen(this))
{
+ connect(_pen, SIGNAL(linkError(QString)), SLOT(handleLinkError(QString)));
}
SmartpenSyncer::~SmartpenSyncer()
@@ -147,11 +150,6 @@ Smartpen::Address SmartpenSyncer::penAddress() const
return _addr;
}
-QString SmartpenSyncer::penName() const
-{
- return _penName;
-}
-
bool SmartpenSyncer::hasErrors() const
{
return _errored;
@@ -162,6 +160,12 @@ void SmartpenSyncer::abort()
_aborted = true;
}
+void SmartpenSyncer::reset()
+{
+ _aborted = false;
+ _errored = false;
+}
+
void SmartpenSyncer::run()
{
if (!_pen->connectToPen(_addr)) {
@@ -170,19 +174,23 @@ void SmartpenSyncer::run()
return;
}
+ if (_aborted) {
+ _pen->disconnectFromPen();
+ return;
+ }
+
_penName = _pen->getPenName();
qDebug() << "got pen name:" << _penName;
- emit penNameChanged();
+ emit gotPenName(_penName);
QVariantMap penInfo = _pen->getPenInfo();
if (penInfo.isEmpty()) {
qWarning() << "Could not get pen info";
_errored = true;
+ _pen->disconnectFromPen();
return;
}
- _penSerial = penInfo["penserial"].toString();
-
_penDataDir.setPath(NotebookModel::userDataDirectory() + "/" + _penName + ".pen");
if (!_penDataDir.exists()) {
if (!_penDataDir.mkpath(".")) {
@@ -194,6 +202,12 @@ void SmartpenSyncer::run()
_errored = true;
}
+ if (_errored) {
+ qDebug() << "Sync finished with errors";
+ } else {
+ qDebug() << "Sync finished";
+ }
+
_pen->disconnectFromPen();
}
@@ -363,3 +377,9 @@ bool SmartpenSyncer::extractZip(QByteArray &zipData, QDir &dir)
return false;
}
}
+
+void SmartpenSyncer::handleLinkError(const QString &msg)
+{
+ qWarning() << "link error:" << msg;
+ _errored = true;
+}