aboutsummaryrefslogtreecommitdiff
path: root/paperreplay.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paperreplay.cc')
-rw-r--r--paperreplay.cc105
1 files changed, 82 insertions, 23 deletions
diff --git a/paperreplay.cc b/paperreplay.cc
index 579ea3c..e0e654e 100644
--- a/paperreplay.cc
+++ b/paperreplay.cc
@@ -24,14 +24,72 @@ PaperReplay::PaperReplay(QObject *parent) :
{
}
-PaperReplay::Session::Session() : d(new SessionData)
+PaperReplay::Session::Session() : d()
{
}
+PaperReplay::Session::Session(quint64 id) : d(new SessionData)
+{
+ d->id = id;
+}
+
PaperReplay::Session::~Session()
{
}
+bool PaperReplay::Session::isValid() const
+{
+ return d;
+}
+
+quint64 PaperReplay::Session::id() const
+{
+ return d ? d->id : 0;
+}
+
+QString PaperReplay::Session::fileName() const
+{
+ return d->file;
+}
+
+qint64 PaperReplay::Session::startTime() const
+{
+ return d->start;
+}
+
+qint64 PaperReplay::Session::endTime() const
+{
+ return d->end;
+}
+
+PaperReplay::SessionList::SessionList()
+{
+}
+
+PaperReplay::SessionList::SessionList(const QMap<qint64, Session> &byTime)
+ : _m(byTime)
+{
+}
+
+QList<PaperReplay::Session> PaperReplay::SessionList::sessionsDuringTime(qint64 time) const
+{
+ QList<Session> sessions;
+ if (_m.isEmpty()) return sessions;
+ QMap<qint64, Session>::const_iterator it = _m.lowerBound(time);
+
+ if (it == _m.end()) --it;
+
+ while (it->d->start <= time && time <= it->d->end) {
+ sessions.append(*it);
+ if (it == _m.begin()) {
+ break;
+ } else {
+ --it;
+ }
+ }
+ return sessions;
+}
+
bool PaperReplay::open(const QString &path, const QString &penSerial, quint64 notebookGuid)
{
_dir.setPath(path + QString("/userdata/%1/Paper Replay/99/%2/sessions")
@@ -44,44 +102,43 @@ bool PaperReplay::open(const QString &path, const QString &penSerial, quint64 no
QDirIterator iter(_dir.path(), QStringList("PRS-*"), QDir::Dirs | QDir::NoDotAndDotDot);
while (iter.hasNext()) {
- QDir sessionDir(iter.next());
bool ok;
+ QDir sessionDir(iter.next());
quint64 sessionId = sessionDir.dirName().mid(4).toULongLong(&ok, 16);
+
if (!ok) {
qWarning() << "Invalid session identifier:" << sessionDir.dirName();
+ continue;
}
- Session &session = _sessions[sessionId];
+
+ Session session(sessionId);
if (!parseSessionInfo(session.d, sessionDir.filePath("session.info"))) {
qWarning() << "Could not parse:" << sessionDir.absoluteFilePath("session.info");
}
if (!parseSessionPages(session.d, sessionDir.filePath("session.pages"))) {
qWarning() << "Could not parse:" << sessionDir.absoluteFilePath("session.pages");
}
- }
+ if (!session.d->file.isEmpty()) {
+ session.d->file = sessionDir.filePath(session.d->file);
+ }
+
+ foreach (quint64 page, session.d->pages) {
+ _byPageTime[page].insert(session.d->start, session);
+ }
+ }
return true;
}
void PaperReplay::close()
{
- _sessions.clear();
- _byPage.clear();
+ _byPageTime.clear();
_dir.setPath(QString());
}
-QList<PaperReplay::Session> PaperReplay::sessions() const
+PaperReplay::SessionList PaperReplay::sessions(quint64 pageAddress) const
{
- return _sessions.values();
-}
-
-QList<PaperReplay::Session> PaperReplay::sessions(quint64 pageAddress) const
-{
- QList<Session> sessions;
- QMultiMap<quint64, quint64>::const_iterator it = _byPage.constFind(pageAddress);
- while (it != _byPage.end() && it.key() == pageAddress) {
- sessions.append(_sessions[it.value()]);
- }
- return sessions;
+ return SessionList(_byPageTime[pageAddress]);
}
bool PaperReplay::parseSessionInfo(SessionData *session, const QString &path)
@@ -123,7 +180,7 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
QDataStream s(dev);
if (s.skipRawData(5) != 5) return false;
- quint64 startTime, endTime, creationTime;
+ qint64 startTime, endTime, creationTime;
QString name;
s >> startTime >> endTime >> creationTime;
@@ -132,10 +189,10 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
}
session->name = name;
- session->start = Smartpen::fromPenTime(startTime);
- session->end = Smartpen::fromPenTime(endTime);
+ session->start = startTime;
+ session->end = endTime;
- qDebug() << "Session:" << name << session->start << session->end;
+ qDebug() << "Session:" << name << Smartpen::fromPenTime(session->start) << Smartpen::fromPenTime(session->end);
quint16 num_clips;
s >> num_clips;
@@ -156,6 +213,7 @@ bool PaperReplay::parseSessionInfoV3(SessionData *session, QIODevice *dev)
quint16 num_strokes;
s >> num_strokes;
+ // TODO:
for (uint i = 0; i < num_strokes; ++i) {
quint64 a, b, c;
quint32 d;
@@ -216,7 +274,8 @@ bool PaperReplay::parseSessionPagesV1(SessionData *session, QIODevice *dev)
session->pages.reserve(session->pages.size() + num_pages);
for (uint i = 0; i < num_pages; ++i) {
- quint64 address, time;
+ quint64 address;
+ qint64 time;
s >> address >> time;
session->pages.append(address);