/* * Copyright (C) 2004-2012 Geometer Plus * * 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 __NETWORKTREENODES_H__ #define __NETWORKTREENODES_H__ #include #include #include #include #include #include "../NetworkLink.h" #include "../../tree/FBTree.h" //maybe RootTree should be nested class for NetworkLibrary? class RootTree : public ZLTreeNode { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: RootTree(); void setDialog(shared_ptr dialog); protected: ZLTreeListener *listener() const; private: shared_ptr myListener; }; class NetworkTree : public FBTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: NetworkTree(RootTree *parent, std::size_t position); NetworkTree(NetworkTree *parent, std::size_t position = (std::size_t)-1); }; class NetworkCatalogTree : public NetworkTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: NetworkCatalogTree(RootTree *parent, shared_ptr item, std::size_t position = (std::size_t)-1); NetworkCatalogTree(NetworkCatalogTree *parent, shared_ptr item, std::size_t position = (std::size_t)-1); std::string title() const; std::string subtitle() const; shared_ptr image() const; void requestChildren(shared_ptr listener); void requestMoreChildren(shared_ptr listener); virtual void onChildrenReceived(NetworkItem::List &childrens, const std::string &error); NetworkCatalogItem &item(); void updateVisibility(); void clearCatalog(); private: void init(); void notifyListeners(const std::string &error); private: void onAuthCheck(const std::string &error); private: const ZLResource &resource() const; private: shared_ptr myItem; NetworkItem::List myChildrenItems; std::vector > myListeners; mutable shared_ptr myImage; friend class NetworkTreeFactory; friend class NetworkCatalogTreeAuthListener; }; class NetworkCatalogRootTree : public NetworkCatalogTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: class LoginAction; class LogoutAction; class TopupAccountAction; class PasswordRecoveryAction; class RegisterUserAction; public: NetworkCatalogRootTree(RootTree *parent, NetworkLink &link, std::size_t position); void init(); private: const ZLResource &resource() const; private: NetworkLink &myLink; }; class SearchCatalogTree : public NetworkCatalogTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: SearchCatalogTree(RootTree *parent, shared_ptr item, std::size_t position = (std::size_t)-1); void requestChildren(shared_ptr listener); void onChildrenReceived(NetworkItem::List &childrens, const std::string &error); }; class NetworkAuthorTree : public NetworkTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; protected: NetworkAuthorTree(NetworkTree *parent, const NetworkBookItem::AuthorData &author); friend class NetworkTreeFactory; public: const NetworkBookItem::AuthorData &author(); private: void init(); const ZLResource &resource() const; shared_ptr image() const; std::string title() const; private: NetworkBookItem::AuthorData myAuthor; }; class NetworkSeriesTree : public NetworkTree { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; protected: NetworkSeriesTree(NetworkTree *parent, const std::string &seriesTitle); friend class NetworkTreeFactory; private: void init(); const ZLResource &resource() const; shared_ptr image() const; std::string title() const; std::string subtitle() const; private: std::string mySeriesTitle; mutable std::vector > myImages; }; class NetworkBookTree : public ZLTreePageNode { public: static const ZLTypeId TYPE_ID; private: const ZLTypeId &typeId() const; public: enum SummaryType { AUTHORS, NONE }; private: NetworkBookTree(NetworkTree *parent, shared_ptr book, SummaryType summaryType); void init(); friend class NetworkTreeFactory; public: const NetworkBookItem &book() const; public: const ZLResource &resource() const; shared_ptr image() const; shared_ptr fullImage() const; std::string title() const; std::string subtitle() const; shared_ptr getPageInfo(); private: class BookItemWrapper : public ZLTreePageInfo { public: BookItemWrapper(NetworkBookTree &tree, shared_ptr bookItem); bool isPageInfoLoaded(); void loadAll(shared_ptr listener); void onInformationLoaded(ZLUserDataHolder &data, const std::string &error); void onCoverLoaded(ZLUserDataHolder &data, const std::string &error); public: std::string title() const; std::vector authors() const; std::vector tags() const; std::string summary() const; shared_ptr image() const; //TODO maybe store actions in other place? const std::vector > &actions() const; std::string actionText(const shared_ptr &action) const; const std::vector > relatedActions() const; private: NetworkBookItem &book() const; private: NetworkBookTree &myTree; shared_ptr myBookItem; mutable bool myIsInitialized; mutable std::vector > myRelatedActions; }; private: shared_ptr myBook; SummaryType mySummaryType; mutable shared_ptr myImage; shared_ptr myPageInfo; }; #endif /* __NETWORKTREENODES_H__ */