summaryrefslogtreecommitdiffstats
path: root/fbreader/src/network/NetworkItems.h
blob: 169e5b70f9c6414c41f6b9772e341f6dcc7f6b84 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#ifndef __NETWORKITEMS_H__
#define __NETWORKITEMS_H__

#include <string>
#include <vector>
#include <map>

#include <shared_ptr.h>

#include <ZLFile.h>
#include <ZLTypeId.h>
#include <ZLBoolean3.h>
#include <ZLNetworkRequest.h>

#include <ZLTreeNode.h>

#include "BookReference.h"

class NetworkAuthenticationManager;
class NetworkLink;

class NetworkItem : public ZLObjectWithRTTI {

public:
	typedef std::vector<shared_ptr<NetworkItem> > List;

	enum URLType {
		URL_NONE,
		URL_CATALOG,
		URL_HTML_PAGE,
		URL_COVER,
		URL_FULL_COVER,
		URL_SINGLE_ENTRY
	};

	typedef std::map<URLType,std::string> UrlInfoCollection;

protected:
	static const ZLTypeId TYPE_ID;

protected:
	NetworkItem(
		const NetworkLink &link,
		const std::string &title,
		const std::string &summary,
		const UrlInfoCollection &urlByType
	);

public:
	virtual ~NetworkItem();

	virtual const ZLTypeId &typeId() const = 0;

public:
	const NetworkLink &Link;
	const std::string Title;
	/*const*/ std::string Summary;
	/*const*/ UrlInfoCollection URLByType;

private: // disable copying
	NetworkItem(const NetworkItem &item);
	const NetworkItem &operator = (const NetworkItem &);
};

class NetworkCatalogItem : public NetworkItem {

public:
	static const ZLTypeId TYPE_ID;

	enum AccessibilityType {
		ALWAYS,
		SIGNED_IN,
		HAS_BOOKS
	};

	enum CatalogFlags {
		FLAG_NONE                              = 0,
		FLAG_SHOW_AUTHOR                       = 1 << 0,
		FLAG_GROUP_BY_AUTHOR                   = 1 << 1,
		FLAG_GROUP_BY_SERIES                   = 1 << 2,
		FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES  = 1 << 3,
		FLAGS_DEFAULT =
			FLAG_SHOW_AUTHOR |
			FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES,
		FLAGS_GROUP =
			FLAG_GROUP_BY_AUTHOR |
			FLAG_GROUP_BY_SERIES |
			FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES,
	};

public:
	NetworkCatalogItem(
		const NetworkLink &link,
		const std::string &title,
		const std::string &summary,
		const UrlInfoCollection &urlByType,
		AccessibilityType accessibility = ALWAYS,
		int flags = FLAGS_DEFAULT
	);

	const ZLTypeId &typeId() const;

	// method is called each time the View Node is created for the Item.
	virtual void onDisplayItem();
	// returns error message
	virtual std::string loadChildren(List &children, shared_ptr<ZLNetworkRequest::Listener> listener = 0) = 0;
	virtual bool supportsResumeLoading();
	virtual std::string resumeLoading(List &children, shared_ptr<ZLNetworkRequest::Listener> listener = 0);

	int getFlags() const;
	AccessibilityType getAccessibility() const;
	ZLBoolean3 getVisibility() const;

protected:
	virtual std::string getCatalogUrl();

private:
	const AccessibilityType myAccessibility;
	const int myFlags;
};

class NetworkBookItem : public NetworkItem {

public:
	struct AuthorData {
		std::string DisplayName;
		std::string SortKey;

		bool operator < (const AuthorData &data) const;
		bool operator != (const AuthorData &data) const;
		bool operator == (const AuthorData &data) const;
	};

public:
	static const ZLTypeId TYPE_ID;

public:
	NetworkBookItem(
		const NetworkLink &link,
		const std::string &id,
		unsigned int index,
		const std::string &title,
		const std::string &summary,
		const std::string &language,
		const std::string &date,
		const std::vector<AuthorData> &authors,
		const std::vector<std::string> &tags,
		const std::string &seriesTitle,
		unsigned int indexInSeries,
		const UrlInfoCollection &urlByType,
		const std::vector<shared_ptr<BookReference> > references
	);
	NetworkBookItem(const NetworkBookItem &book, unsigned int index);

	const ZLTypeId &typeId() const;

public:
	shared_ptr<BookReference> reference(BookReference::Type type) const;

	std::string localCopyFileName() const;
	void removeLocalFiles() const;

	virtual bool isFullyLoaded() const;
	virtual void loadFullInformation(shared_ptr<ZLNetworkRequest::Listener> listener);
	virtual std::vector<shared_ptr<NetworkItem> > getRelatedCatalogsItems() const;

	void updateReferences(const std::vector<shared_ptr<BookReference> > &references);

public:
	/*const*/ unsigned int Index;
	const std::string Id;
	const std::string Language;
	const std::string Date;
	const std::vector<AuthorData> Authors;
	const std::vector<std::string> Tags;
	const std::string SeriesTitle;
	const int IndexInSeries;

private:
	std::vector<shared_ptr<BookReference> > myReferences;
};

#endif /* __NETWORKITEMS_H__ */