aboutsummaryrefslogtreecommitdiff
path: root/afdnotebook.h
blob: 49d06b04081f3a2de4a94aed2098b4d019465381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * scribiu -- read notebooks and voice memos from Livescribe pens
 * Copyright (C) 2015 Javier S. Pedro <javier@javispedro.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef AFDNOTEBOOK_H
#define AFDNOTEBOOK_H

#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QMap>
#include <QtGui/QImage>
#include "afdpageaddress.h"
#include "stfreader.h"

class AfdNotebook : public QObject
{
	Q_OBJECT

public:
	AfdNotebook(QObject *parent = 0);
	~AfdNotebook();

	bool open(const QString &path);
	void close();

	QString title() const;
	quint64 guid() const;

	int numPages() const;

	AfdPageAddress getPageAddress(int pageNum) const;
	int getPageNumber(const AfdPageAddress &addr) const;

	QString getPageBackgroundName(int page) const;
	QPixmap getPageBackground(int page);

	QSize getPageSize(int page) const;
	QRect getPageTrim(int page) const;

	QStringList penSerials() const;
	QList<int> pagesWithStrokes(const QString &penSerial) const;

	QStringList strokeFiles(const QString &penSerial, int page) const;

	bool readStrokes(const QString &penSerial, int page, StfReader::StrokeHandler *handler);

private:
	struct Gfx {
		QString basename;
	};

	struct Page {
		Gfx *gfx;
		QSize size;
	};

	struct StrokeData {
		QString file;
		QDateTime begin;
		QDateTime end;
	};

	struct PenData {
		QMultiMap<int, StrokeData> strokes;
	};

private:
	static QMap<QString, QString> parsePropertyList(QIODevice *dev);
	QMap<QString, QString> parsePropertyList(const QString &relativePath) const;

	bool parseMainInfo();
	bool parseMainDocument();
	bool parseGfx(const QString &file);
	bool findPenData();

private:
	QDir _dir;
	QString _title;
	quint64 _guid;
	AfdPageAddress _firstPage, _lastPage;
	uint _pagesPerBook;
	QMap<QString, Gfx> _gfx;
	QList<Page> _pages;
	QMap<QString, PenData> _penData;
};

#endif