1 /*
2  * Copyright (C) 2009-2010 Geometer Plus <contact@geometerplus.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 #ifndef __NETWORKNODES_H__
21 #define __NETWORKNODES_H__
22 
23 #include "../blockTree/FBReaderNode.h"
24 
25 #include "../network/NetworkItems.h"
26 
27 class NetworkBookCollection;
28 class NetworkLink;
29 
30 class NetworkContainerNode : public FBReaderNode {
31 
32 public:
33 	static const ZLTypeId TYPE_ID;
34 
35 protected:
36 	NetworkContainerNode(ZLBlockTreeView::RootNode *parent, size_t atPosition = (size_t)-1);
37 	NetworkContainerNode(NetworkContainerNode *parent, size_t atPosition = (size_t)-1);
38 
39 private:
40 	void drawCover(ZLPaintContext &context, int vOffset);
41 	const ZLTypeId &typeId() const;
42 };
43 
44 class NetworkCatalogNode : public NetworkContainerNode {
45 
46 public:
47 	static const ZLTypeId TYPE_ID;
48 
49 protected:
50 	class ExpandCatalogAction : public ZLRunnableWithKey {
51 
52 	public:
53 		ExpandCatalogAction(NetworkCatalogNode &node);
54 		ZLResourceKey key() const;
55 		void run();
56 
57 	private:
58 		NetworkCatalogNode &myNode;
59 	};
60 
61 	class ReloadAction : public ZLRunnableWithKey {
62 
63 	public:
64 		ReloadAction(NetworkCatalogNode &node);
65 		ZLResourceKey key() const;
66 		bool makesSense() const;
67 		void run();
68 
69 	private:
70 		NetworkCatalogNode &myNode;
71 	};
72 
73 	class OpenInBrowserAction;
74 
75 protected:
76 	NetworkCatalogNode(ZLBlockTreeView::RootNode *parent, shared_ptr<NetworkItem> item, size_t atPosition = (size_t)-1);
77 	NetworkCatalogNode(NetworkCatalogNode *parent, shared_ptr<NetworkItem> item, size_t atPosition = (size_t)-1);
78 
79 private:
80 	void init();
81 	const ZLResource &resource() const;
82 	const ZLTypeId &typeId() const;
83 
84 friend class NetworkNodesFactory;
85 
86 public:
87 	NetworkCatalogItem &item();
88 	const NetworkItem::List &childrenItems();
89 
90 	void updateChildren();
91 
92 protected:
93 	shared_ptr<ZLImage> extractCoverImage() const;
94 	std::string title() const;
95 	std::string summary() const;
96 	virtual shared_ptr<ZLImage> lastResortCoverImage() const;
97 
98 private:
99 	shared_ptr<NetworkItem> myItem;
100 	NetworkItem::List myChildrenItems;
101 };
102 
103 class NetworkCatalogRootNode : public NetworkCatalogNode {
104 
105 public:
106 	static const ZLTypeId TYPE_ID;
107 
108 private:
109 	class LoginAction;
110 	class LogoutAction;
111 	class RefillAccountAction;
112 	class DontShowAction;
113 	class PasswordRecoveryAction;
114 	class RegisterUserAction;
115 
116 public:
117 	NetworkCatalogRootNode(ZLBlockTreeView::RootNode *parent, NetworkLink &link, size_t atPosition = (size_t)-1);
118 
119 	const NetworkLink &link() const;
120 
121 private:
122 	void init();
123 	const ZLResource &resource() const;
124 	const ZLTypeId &typeId() const;
125 
126 	shared_ptr<ZLImage> lastResortCoverImage() const;
127 
128 private:
129 	NetworkLink &myLink;
130 };
131 
132 class SearchResultNode : public NetworkContainerNode {
133 
134 public:
135 	static const ZLTypeId TYPE_ID;
136 
137 public:
138 	SearchResultNode(ZLBlockTreeView::RootNode *parent, shared_ptr<NetworkBookCollection> searchResult, const std::string &summary, size_t atPosition = (size_t)-1);
139 
140 	shared_ptr<NetworkBookCollection> searchResult();
141 
142 private:
143 	void init();
144 	const ZLResource &resource() const;
145 	const ZLTypeId &typeId() const;
146 	shared_ptr<ZLImage> extractCoverImage() const;
147 	std::string title() const;
148 	std::string summary() const;
149 
150 private:
151 	shared_ptr<NetworkBookCollection> mySearchResult;
152 	std::string mySummary;
153 };
154 
155 class NetworkAuthorNode : public NetworkContainerNode {
156 
157 public:
158 	static const ZLTypeId TYPE_ID;
159 
160 protected:
161 	NetworkAuthorNode(NetworkContainerNode *parent, const NetworkBookItem::AuthorData &author);
162 
163 friend class NetworkNodesFactory;
164 
165 public:
166 	const NetworkBookItem::AuthorData &author();
167 
168 private:
169 	void init();
170 	const ZLResource &resource() const;
171 	const ZLTypeId &typeId() const;
172 	shared_ptr<ZLImage> extractCoverImage() const;
173 	std::string title() const;
174 
175 private:
176 	NetworkBookItem::AuthorData myAuthor;
177 };
178 
179 class NetworkSeriesNode : public NetworkContainerNode {
180 
181 public:
182 	static const ZLTypeId TYPE_ID;
183 
184 	enum SummaryType { AUTHORS, BOOKS };
185 
186 protected:
187 	NetworkSeriesNode(NetworkContainerNode *parent, const std::string &seriesTitle, SummaryType summaryType);
188 
189 friend class NetworkNodesFactory;
190 
191 private:
192 	void init();
193 	const ZLResource &resource() const;
194 	const ZLTypeId &typeId() const;
195 	shared_ptr<ZLImage> extractCoverImage() const;
196 	std::string title() const;
197 	std::string summary() const;
198 
199 private:
200 	std::string mySeriesTitle;
201 	SummaryType mySummaryType;
202 	mutable std::string mySummary;
203 };
204 
205 class NetworkBookNode : public FBReaderNode {
206 
207 public:
208 	static const ZLTypeId TYPE_ID;
209 
210 	enum SummaryType { AUTHORS, NONE };
211 
212 private:
213 	NetworkBookNode(NetworkContainerNode *parent, shared_ptr<NetworkItem> book, SummaryType summaryType);
214 	void init();
215 
216 friend class NetworkNodesFactory;
217 
218 public:
219 	const NetworkBookItem &book() const;
220 
221 private:
222 	const ZLResource &resource() const;
223 	const ZLTypeId &typeId() const;
224 	shared_ptr<ZLImage> extractCoverImage() const;
225 	std::string title() const;
226 	std::string summary() const;
227 	void drawCover(ZLPaintContext &context, int vOffset);
228 
229 private:
230 	shared_ptr<NetworkItem> myBook;
231 	SummaryType mySummaryType;
232 };
233 
234 #endif /* __NETWORKNODES_H__ */
235