diff options
author | Michele Calgaro <[email protected]> | 2024-06-07 23:30:05 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2024-06-07 23:30:05 +0900 |
commit | 17b259df9cb6b28779d4881b2b6c805ee2e48eea (patch) | |
tree | 5ed61937459cb7081089111b0242c01ec178f1f3 /fbreader/src/network/litres | |
parent | 1cba8bce178eb2d6719c6f7f21e2c9352c5513a6 (diff) | |
download | tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.tar.gz tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.zip |
Rename to tde-ebook-reader
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'fbreader/src/network/litres')
24 files changed, 0 insertions, 2424 deletions
diff --git a/fbreader/src/network/litres/LitResAuthorsItem.cpp b/fbreader/src/network/litres/LitResAuthorsItem.cpp deleted file mode 100644 index ece7438..0000000 --- a/fbreader/src/network/litres/LitResAuthorsItem.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <ZLNetworkManager.h> - -#include "../NetworkLink.h" -#include "../NetworkComparators.h" -#include "../NetworkErrors.h" -#include "../NetworkItems.h" - -#include "LitResUtil.h" -#include "LitResAuthorsParser.h" -#include "LitResBooksFeedItem.h" - -#include "LitResAuthorsItem.h" - -LitResAuthorsItem::LitResAuthorsItem( - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility, - int flags -) : NetworkCatalogItem( - link, - title, - summary, - urlByType, - accessibility, - flags -) { -} - -class LitResAuthorsItemRunnable : public ZLRunnable { -public: - LitResAuthorsItemRunnable(LitResAuthorsItem *item, NetworkItem::List &children) : myItem(item), myChildren(children) { } - void run() { - myItem->fillChildrenWithAuthors(myChildren, myItem->myAuthorsList); - } -private: - LitResAuthorsItem *myItem; - NetworkItem::List &myChildren; -}; - -std::string LitResAuthorsItem::loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { - //TODO maybe add sid parameter if possible - //(at LitRes API documentation it said that's adding sid _always_ is a good practice) - - myAuthorsList.clear(); - shared_ptr<ZLNetworkRequest> data = ZLNetworkManager::Instance().createXMLParserRequest( - getCatalogUrl(), - new LitResAuthorsParser(myAuthorsList), - new LitResAuthorsItemRunnable(this, children) - ); - data->setListener(listener); - return ZLNetworkManager::Instance().performAsync(data); -} - -void LitResAuthorsItem::fillChildrenWithAuthors(NetworkItem::List &children, const LitResAuthorsParser::AuthorsList &authors) { - for (std::size_t i = 0; i < authors.size(); ++i) { - const LitResAuthorsParser::LitresAuthorData &author = authors.at(i); - - UrlInfoCollection urlByType = URLByType; - urlByType[NetworkItem::URL_CATALOG] = LitResUtil::generateBooksByAuthorUrl(author.Id); - //TODO add icon change for one author here - //urlByType[NetworkItem::URL_COVER] = - children.push_back(new LitResBooksFeedItem( - true, - Link, - author.DisplayName, - getSubtitle(author), - urlByType, - NetworkCatalogItem::ALWAYS, - NetworkCatalogItem::FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES - )); - } -} - -std::string LitResAuthorsItem::getSubtitle(const LitResAuthorsParser::LitresAuthorData &author) { - static const std::string SPACE = " "; - std::string subtitle = author.FirstName; - if (!author.MiddleName.empty()) { - if (!subtitle.empty()) { - subtitle += SPACE; - } - subtitle += author.MiddleName; - } - if (!author.LastName.empty()) { - if (!subtitle.empty()) { - subtitle += SPACE; - } - subtitle += author.LastName; - } - return subtitle; -} diff --git a/fbreader/src/network/litres/LitResAuthorsItem.h b/fbreader/src/network/litres/LitResAuthorsItem.h deleted file mode 100644 index 31847f4..0000000 --- a/fbreader/src/network/litres/LitResAuthorsItem.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESAUTHORSITEM_H__ -#define __LITRESAUTHORSITEM_H__ - -#include "../NetworkItems.h" - -#include "LitResAuthorsParser.h" - -class LitResAuthorsItem : public NetworkCatalogItem { - -public: - LitResAuthorsItem( - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility, - int flags = FLAGS_DEFAULT - ); - -protected: - void fillChildrenWithAuthors(NetworkItem::List &children, const LitResAuthorsParser::AuthorsList &authors); - std::string loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - - static std::string getSubtitle(const LitResAuthorsParser::LitresAuthorData &author); - -private: - LitResAuthorsParser::AuthorsList myAuthorsList; - -friend class LitResAuthorsItemRunnable; -}; - -#endif /* __LITRESAUTHORSITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResAuthorsParser.cpp b/fbreader/src/network/litres/LitResAuthorsParser.cpp deleted file mode 100644 index 453ffb5..0000000 --- a/fbreader/src/network/litres/LitResAuthorsParser.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <cstdlib> - -#include <ZLUnicodeUtil.h> - -#include "../NetworkLink.h" -#include "LitResGenre.h" -#include "LitResUtil.h" - -#include "LitResAuthorsParser.h" - -static const std::string TAG_CATALOG = "catalit-persons"; -static const std::string TAG_SUBJECT = "subject"; -static const std::string TAG_TITLE = "title"; -static const std::string TAG_MAIN = "main"; -static const std::string TAG_FIRST_NAME = "first-name"; -static const std::string TAG_MIDDLE_NAME = "middle-name"; -static const std::string TAG_LAST_NAME = "last-name"; - -std::string LitResAuthorsParser::stringAttributeValue(const char **attributes, const char *name) { - if (attributes == 0) { - return std::string(); - } - const char *value = attributeValue(attributes, name); - return value != 0 ? value : std::string(); -} - -LitResAuthorsParser::LitResAuthorsParser(AuthorsList &authors) : myAuthors(authors) { - myState = START; -} - - -void LitResAuthorsParser::startElementHandler(const char *tag, const char **attributes) { - processState(tag, false, attributes); - myState = getNextState(tag, false); - myBuffer.clear(); -} - -void LitResAuthorsParser::endElementHandler(const char *tag) { - processState(tag, true, 0); - myState = getNextState(tag, true); - myBuffer.clear(); -} - -void LitResAuthorsParser::characterDataHandler(const char *data, std::size_t len) { - myBuffer.append(data, len); -} - -void LitResAuthorsParser::processState(const std::string &tag, bool closed, const char **attributes) { - switch(myState) { - case START: - break; - case CATALOG: - if (!closed && TAG_SUBJECT == tag) { - myAuthorId = stringAttributeValue(attributes, "id"); - } - break; - case SUBJECT: - if (closed && TAG_SUBJECT == tag) { - LitresAuthorData litresAuthor; - litresAuthor.Id = myAuthorId; - litresAuthor.DisplayName = myAuthorDisplayName; - litresAuthor.FirstName = myAuthorFirstName; - litresAuthor.MiddleName = myAuthorMiddleName; - litresAuthor.LastName = myAuthorLastName; - litresAuthor.SortKey = ZLUnicodeUtil::toLower(myAuthorLastName); - - myAuthors.push_back(litresAuthor); - myAuthorId.clear(); - myAuthorDisplayName.clear(); - myAuthorFirstName.clear(); - myAuthorMiddleName.clear(); - myAuthorLastName.clear(); - } - break; - case TITLE: - break; - case MAIN: - if (closed && TAG_MAIN == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorDisplayName = myBuffer; - } - break; - case FIRST_NAME: - if (closed && TAG_FIRST_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorFirstName = myBuffer; - } - break; - case MIDDLE_NAME: - if (closed && TAG_MIDDLE_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorMiddleName = myBuffer; - } - break; - case LAST_NAME: - if (closed && TAG_LAST_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorLastName = myBuffer; - } - break; - } -} - -LitResAuthorsParser::State LitResAuthorsParser::getNextState(const std::string &tag, bool closed) { - switch(myState) { - case START: - if (!closed && TAG_CATALOG == tag) { - return CATALOG; - } - break; - case CATALOG: - if (!closed) { - if (TAG_SUBJECT == tag) { - return SUBJECT; - } - } else { - if (TAG_CATALOG == tag) { - return START; - } - } - break; - case SUBJECT: - if (!closed) { - if (TAG_TITLE == tag) { - return TITLE; - } - } else { - if (TAG_SUBJECT == tag) { - return CATALOG; - } - } - break; - case TITLE: - if (!closed) { - if (TAG_MAIN == tag) { - return MAIN; - } - } else { - if (TAG_TITLE == tag) { - return FIRST_NAME; - } - } - break; - case MAIN: - if (closed && TAG_MAIN == tag) { - return TITLE; - } - break; - case FIRST_NAME: - if (closed && TAG_FIRST_NAME == tag) { - return MIDDLE_NAME; - } - break; - case MIDDLE_NAME: - if (closed && TAG_MIDDLE_NAME == tag) { - return LAST_NAME; - } - break; - case LAST_NAME: - if (closed && TAG_LAST_NAME == tag) { - return SUBJECT; - } - break; - } - return myState; -} diff --git a/fbreader/src/network/litres/LitResAuthorsParser.h b/fbreader/src/network/litres/LitResAuthorsParser.h deleted file mode 100644 index ead137d..0000000 --- a/fbreader/src/network/litres/LitResAuthorsParser.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESAUTHORSPARSER_H__ -#define __LITRESAUTHORSPARSER_H__ - -#include <vector> -#include <map> - -#include <ZLXMLReader.h> - -#include "../NetworkItems.h" - -class NetworkLink; -struct LitResGenre; -class NetworkAuthenticationManager; - -class LitResAuthorsParser : public ZLXMLReader { - -public: - struct LitresAuthorData { - std::string Id; - std::string DisplayName; - std::string FirstName; - std::string MiddleName; - std::string LastName; - std::string SortKey; - - bool operator< (const LitresAuthorData &authorData) const; - }; - typedef std::vector<LitresAuthorData> AuthorsList; - -public: - LitResAuthorsParser(AuthorsList &authors); - -private: - void startElementHandler(const char *tag, const char **attributes); - void endElementHandler(const char *tag); - void characterDataHandler(const char *text, std::size_t len); - -private: - enum State { - START, CATALOG, SUBJECT, TITLE, MAIN, FIRST_NAME, MIDDLE_NAME, LAST_NAME - }; - - std::string stringAttributeValue(const char **attributes, const char *name); - void processState(const std::string &tag, bool closed, const char **attributes); - State getNextState(const std::string &tag, bool closed); - -private: - AuthorsList &myAuthors; - - std::string myBuffer; - State myState; - - std::string myAuthorId; - std::string myAuthorDisplayName; - std::string myAuthorFirstName; - std::string myAuthorMiddleName; - std::string myAuthorLastName; -}; - -inline bool LitResAuthorsParser::LitresAuthorData::operator< (const LitresAuthorData &authorData) const { - return SortKey.compare(authorData.SortKey) < 0; -} - -#endif /* __LITRESAUTHORSPARSER_H__ */ diff --git a/fbreader/src/network/litres/LitResBookItem.cpp b/fbreader/src/network/litres/LitResBookItem.cpp deleted file mode 100644 index cdc9306..0000000 --- a/fbreader/src/network/litres/LitResBookItem.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <ZLResource.h> -#include <ZLStringUtil.h> - -#include "LitResBooksFeedItem.h" -#include "LitResUtil.h" - -#include "LitResBookItem.h" - -LitResBookItem::LitResBookItem( - 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, - const std::vector<std::string> authorIds -) : - NetworkBookItem(link, id, index, title, summary, language, date, authors, - tags, seriesTitle, indexInSeries, urlByType, references), - myAuthorIds(authorIds) -{ - -} - -std::vector<shared_ptr<NetworkItem> > LitResBookItem::getRelatedCatalogsItems() const { - std::vector<shared_ptr<NetworkItem> > items; - - UrlInfoCollection urlByType = URLByType; - - urlByType[URL_CATALOG] = LitResUtil::generateAlsoReadUrl(Id); - items.push_back(new LitResBooksFeedItem(false, Link, resource("alsoRead").value(), std::string(), urlByType)); - - for (std::size_t i = 0; i < myAuthorIds.size(); ++i) { - urlByType[URL_CATALOG] = LitResUtil::generateBooksByAuthorUrl(myAuthorIds.at(i)); - std::string title = ZLStringUtil::printf(resource("sameAuthor").value(), Authors.at(i).DisplayName); - items.push_back(new LitResBooksFeedItem(false, Link, title, std::string(), urlByType)); - } - - return items; -} - -const ZLResource &LitResBookItem::resource(const std::string &resourceKey) const { - return ZLResource::resource("networkView")["bookNode"][resourceKey]; -} diff --git a/fbreader/src/network/litres/LitResBookItem.h b/fbreader/src/network/litres/LitResBookItem.h deleted file mode 100644 index 129b6a6..0000000 --- a/fbreader/src/network/litres/LitResBookItem.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESBOOKITEM_H__ -#define __LITRESBOOKITEM_H__ - -#include "../NetworkItems.h" - -class LitResBookItem : public NetworkBookItem { -public: - LitResBookItem( - 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, - const std::vector<std::string> authorIds - ); - - std::vector<shared_ptr<NetworkItem> > getRelatedCatalogsItems() const; - -protected: - const ZLResource &resource(const std::string &resourceKey) const; - -private: - std::vector<std::string> myAuthorIds; -}; - -#endif /* __LITRESBOOKITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResBooksFeedItem.cpp b/fbreader/src/network/litres/LitResBooksFeedItem.cpp deleted file mode 100644 index b597255..0000000 --- a/fbreader/src/network/litres/LitResBooksFeedItem.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <algorithm> - -#include <ZLNetworkManager.h> -#include <ZLNetworkUtil.h> -#include <ZLStringUtil.h> - -#include "../NetworkLink.h" -#include "../NetworkComparators.h" -#include "../NetworkErrors.h" -#include "../NetworkItems.h" - -#include "LitResUtil.h" -#include "LitResBooksFeedParser.h" - -#include "LitResBooksFeedItem.h" - -LitResBooksFeedItem::LitResBooksFeedItem( - bool shouldSort, - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility, - int flags -) : NetworkCatalogItem( - link, - title, - summary, - urlByType, - accessibility, - flags -), myShouldSort(shouldSort) { - -} - -void LitResBooksFeedItem::onDisplayItem() { -} - -class LitResBooksFeedItemRunnable : public ZLNetworkRequest::Listener { -public: - LitResBooksFeedItemRunnable(LitResBooksFeedItem &item, shared_ptr<ZLNetworkRequest> request, NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) : - myItem(item), myChildren(children), myListener(listener) { - request->setListener(this); - ZLNetworkManager::Instance().performAsync(request); - } - - void finished(const std::string &error) { - if (error.empty()) { - ++myItem.myLoadingState.CurrentPage; - if (myItem.myShouldSort) { - std::sort(myChildren.begin(), myChildren.end(), NetworkBookItemComparator()); - } - } - myListener->finished(error); - } -private: - LitResBooksFeedItem &myItem; - NetworkItem::List &myChildren; - shared_ptr<ZLNetworkRequest::Listener> myListener; -}; - - -std::string LitResBooksFeedItem::loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { -// //TODO maybe add sid parameter if possible -// //(at LitRes API documentation it said that's adding sid _always_ is a good practice) - - myLoadingState.CurrentPage = 0; - myLoadingState.AllPagesCount = 1; - - shared_ptr<ZLNetworkRequest> request = getRequest(children); - new LitResBooksFeedItemRunnable(*this, request, children, listener); - return std::string(); -} - -bool LitResBooksFeedItem::supportsResumeLoading() { - return true; -} - -std::string LitResBooksFeedItem::resumeLoading(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { - shared_ptr<ZLNetworkRequest> request = getRequest(children); - if (request.isNull()) { - listener->finished(); - return std::string(); - } - new LitResBooksFeedItemRunnable(*this, request, children, listener); - return std::string(); -} - -shared_ptr<ZLNetworkRequest> LitResBooksFeedItem::getRequest(NetworkItem::List &children) { - if (myLoadingState.CurrentPage >= myLoadingState.AllPagesCount) { - return 0; - } - return ZLNetworkManager::Instance().createXMLParserRequest( - withLimitParameters(getCatalogUrl(), myLoadingState), - new LitResBooksFeedParser(Link, children, &myLoadingState) - ); -} - -std::string LitResBooksFeedItem::withLimitParameters(std::string query, const LoadingState &state) { - static const unsigned int ITEMS_PER_PAGE = 40; - unsigned int startItemNumber = (unsigned int)state.CurrentPage * ITEMS_PER_PAGE; - std::string params; - ZLStringUtil::appendNumber(params, startItemNumber); - params += ","; - ZLStringUtil::appendNumber(params, ITEMS_PER_PAGE); - ZLNetworkUtil::appendParameter(query, "limit", params); - return query; -} - diff --git a/fbreader/src/network/litres/LitResBooksFeedItem.h b/fbreader/src/network/litres/LitResBooksFeedItem.h deleted file mode 100644 index 8af7df2..0000000 --- a/fbreader/src/network/litres/LitResBooksFeedItem.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESBOOKFEEDITEM_H__ -#define __LITRESBOOKFEEDITEM_H__ - -#include "../NetworkItems.h" - -class LitResBooksFeedItem : public NetworkCatalogItem { - -public: - struct LoadingState { - int CurrentPage; - int AllPagesCount; - } myLoadingState; - -public: - LitResBooksFeedItem( - bool shouldSort, - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility = ALWAYS, - int flags = FLAGS_DEFAULT - ); - -private: - void onDisplayItem(); - std::string loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - bool supportsResumeLoading(); - std::string resumeLoading(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - -private: - shared_ptr<ZLNetworkRequest> getRequest(NetworkItem::List &children); - static std::string withLimitParameters(std::string url, const LoadingState &state); - -private: - bool myShouldSort; - -friend class LitResBooksFeedItemRunnable; -}; - -#endif /* __LITRESBOOKFEEDITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResBooksFeedParser.cpp b/fbreader/src/network/litres/LitResBooksFeedParser.cpp deleted file mode 100644 index 970a8eb..0000000 --- a/fbreader/src/network/litres/LitResBooksFeedParser.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <cstdlib> - -#include <ZLStringUtil.h> -#include <ZLUnicodeUtil.h> - -#include "LitResBooksFeedParser.h" -#include "LitResBookItem.h" -#include "LitResGenre.h" -#include "LitResUtil.h" -#include "../NetworkLink.h" - -static const std::string TAG_CATALOG = "catalit-fb2-books"; -static const std::string TAG_BOOK = "fb2-book"; -static const std::string TAG_TEXT_DESCRIPTION = "text_description"; -static const std::string TAG_HIDDEN = "hidden"; -static const std::string TAG_TITLE_INFO = "title-info"; -static const std::string TAG_GENRE = "genre"; -static const std::string TAG_AUTHOR = "author"; -static const std::string TAG_FIRST_NAME = "first-name"; -static const std::string TAG_MIDDLE_NAME = "middle-name"; -static const std::string TAG_LAST_NAME = "last-name"; -static const std::string TAG_AUTHOR_ID = "id"; -static const std::string TAG_BOOK_TITLE = "book-title"; -static const std::string TAG_ANNOTATION = "annotation"; -static const std::string TAG_DATE = "date"; -static const std::string TAG_SEQUENCE = "sequence"; -static const std::string TAG_LANGUAGE = "lang"; - -std::string LitResBooksFeedParser::stringAttributeValue(const char **attributes, const char *name) { - if (attributes == 0) { - return std::string(); - } - const char *value = attributeValue(attributes, name); - return value != 0 ? value : std::string(); -} - -LitResBooksFeedParser::LitResBooksFeedParser(const NetworkLink &link, NetworkItem::List &books, LitResBooksFeedItem::LoadingState *loadingState) : - myLink(link), - myBooks(books), - myIndex(0), - myLoadingState(loadingState) { - myState = START; -} - - -void LitResBooksFeedParser::startElementHandler(const char *tag, const char **attributes) { - processState(tag, false, attributes); - myState = getNextState(tag, false); - myBuffer.clear(); -} - -void LitResBooksFeedParser::endElementHandler(const char *tag) { - processState(tag, true, 0); - myState = getNextState(tag, true); - myBuffer.clear(); -} - -void LitResBooksFeedParser::characterDataHandler(const char *data, std::size_t len) { - myBuffer.append(data, len); -} - -void LitResBooksFeedParser::processState(const std::string &tag, bool closed, const char **attributes) { - switch(myState) { - case START: - if (!closed && TAG_CATALOG == tag) { - if (myLoadingState) { - myLoadingState->AllPagesCount = ZLStringUtil::stringToInteger(stringAttributeValue(attributes, "pages"), 1); - } - } - break; - case CATALOG: - if (!closed && TAG_BOOK == tag) { - myBookId = stringAttributeValue(attributes, "hub_id"); - myURLByType[NetworkItem::URL_COVER] = - stringAttributeValue(attributes, "cover_preview"); - myURLByType[NetworkItem::URL_FULL_COVER] = - stringAttributeValue(attributes, "cover"); - - std::string url = stringAttributeValue(attributes, "url"); - if (!url.empty()) { - myLink.rewriteUrl(url, true); // This code duplicates code in FBReader::openInBrowser and is not required - myURLByType[NetworkItem::URL_HTML_PAGE] = url; - } - - //TODO check if buying book works right - std::string price = BuyBookReference::price(stringAttributeValue(attributes, "price"), "RUB"); - myReferences.push_back(new BuyBookReference( - LitResUtil::generatePurchaseUrl(myLink, myBookId), - BookReference::FB2_ZIP, - BookReference::BUY, - price - )); - - std::string hasTrial = stringAttributeValue(attributes, "has_trial"); - if (!hasTrial.empty() && hasTrial != "0") { - myReferences.push_back(new BookReference( - LitResUtil::generateTrialUrl(myBookId), - BookReference::FB2_ZIP, - BookReference::DOWNLOAD_DEMO - )); - } - - myReferences.push_back(new BookReference( - LitResUtil::generateDownloadUrl(myBookId), - BookReference::FB2_ZIP, - BookReference::DOWNLOAD_FULL_CONDITIONAL - )); - } - break; - case BOOK: - if (closed && TAG_BOOK == tag) { - myBooks.push_back(new LitResBookItem( - myLink, - myBookId, - myIndex++, - myTitle, - mySummary, - myLanguage, - myDate, - myAuthors, - myTags, - mySeriesTitle, - myIndexInSeries, - myURLByType, - myReferences, - myAuthorsIds - )); - - myTitle.erase(); - mySummary.erase(); - myLanguage.erase(); - myDate.erase(); - mySeriesTitle.erase(); - myIndexInSeries = 0; - myAuthors.clear(); - myAuthorsIds.clear(); - myTags.clear(); - myURLByType.clear(); - myReferences.clear(); - } - break; - case BOOK_DESCRIPTION: - break; - case HIDDEN: - break; - case TITLE_INFO: - if (!closed) { - if (TAG_AUTHOR == tag) { - myAuthorFirstName.clear(); - myAuthorMiddleName.clear(); - myAuthorLastName.clear(); - } else if (TAG_SEQUENCE == tag) { - mySeriesTitle = stringAttributeValue(attributes, "name"); - if (!mySeriesTitle.empty()) { - const char *indexInSeries = attributeValue(attributes, "number"); - myIndexInSeries = indexInSeries != 0 ? std::atoi(indexInSeries) : 0; - } - } - } - break; - case AUTHOR: - if (closed && TAG_AUTHOR == tag) { - NetworkBookItem::AuthorData data; - if (!myAuthorFirstName.empty()) { - data.DisplayName.append(myAuthorFirstName); - } - if (!myAuthorMiddleName.empty()) { - if (!data.DisplayName.empty()) { - data.DisplayName.append(" "); - } - data.DisplayName.append(myAuthorMiddleName); - } - if (!myAuthorLastName.empty()) { - if (!data.DisplayName.empty()) { - data.DisplayName.append(" "); - } - data.DisplayName.append(myAuthorLastName); - } - data.SortKey = myAuthorLastName; - myAuthors.push_back(data); - myAuthorsIds.push_back(myAuthorId); - } - break; - case FIRST_NAME: - if (closed && TAG_FIRST_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorFirstName = myBuffer; - } - break; - case MIDDLE_NAME: - if (closed && TAG_MIDDLE_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorMiddleName = myBuffer; - } - break; - case LAST_NAME: - if (closed && TAG_LAST_NAME == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorLastName = myBuffer; - } - break; - case AUTHOR_ID: - if (closed && TAG_AUTHOR_ID == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myAuthorId = myBuffer; - } - break; - case GENRE: - if (closed && TAG_GENRE == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - - const std::map<std::string,shared_ptr<LitResGenre> > &genresMap = - LitResGenreMap::Instance().genresMap(); - const std::map<shared_ptr<LitResGenre>,std::string> &genresTitles = - LitResGenreMap::Instance().genresTitles(); - - std::map<std::string, shared_ptr<LitResGenre> >::const_iterator it = genresMap.find(myBuffer); - if (it != genresMap.end()) { - std::map<shared_ptr<LitResGenre>, std::string>::const_iterator jt = genresTitles.find(it->second); - if (jt != genresTitles.end()) { - myTags.push_back(jt->second); - } - } - } - break; - case BOOK_TITLE: - if (closed && TAG_BOOK_TITLE == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myTitle = myBuffer; - } - break; - case ANNOTATION: - if (!closed) { - ZLUnicodeUtil::utf8Trim(myBuffer); - if (!myBuffer.empty()) { - mySummary.append(myBuffer); - mySummary.append(" "); - } - } else { - ZLUnicodeUtil::utf8Trim(myBuffer); - mySummary.append(myBuffer); - int size = mySummary.size(); - if (size > 0) { - if (TAG_ANNOTATION == tag) { - if (mySummary[size - 1] == '\n') { - mySummary.erase(size - 1); - } - } else if ("p" == tag) { - if (mySummary[size - 1] != '\n') { - mySummary.append("\n"); - } - } else { - if (!myBuffer.empty() && mySummary[size - 1] != '\n') { - mySummary.append(" "); - } - } - } - } - break; - case DATE: - if (closed && TAG_DATE == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myDate = myBuffer; - } - break; - case LANGUAGE: - if (closed && TAG_LANGUAGE == tag) { - ZLUnicodeUtil::utf8Trim(myBuffer); - myLanguage = myBuffer; - } - break; - } -} - -LitResBooksFeedParser::State LitResBooksFeedParser::getNextState(const std::string &tag, bool closed) { - switch(myState) { - case START: - if (!closed && TAG_CATALOG == tag) { - return CATALOG; - } - break; - case CATALOG: - if (!closed) { - if (TAG_BOOK == tag) { - return BOOK; - } - } else { - if (TAG_CATALOG == tag) { - return START; - } - } - break; - case BOOK: - if (!closed) { - if (TAG_TEXT_DESCRIPTION == tag) { - return BOOK_DESCRIPTION; - } - } else { - if (TAG_BOOK == tag) { - return CATALOG; - } - } - break; - case BOOK_DESCRIPTION: - if (!closed) { - if (TAG_HIDDEN == tag) { - return HIDDEN; - } - } else { - if (TAG_TEXT_DESCRIPTION == tag) { - return BOOK; - } - } - break; - case HIDDEN: - if (!closed) { - if (TAG_TITLE_INFO == tag) { - return TITLE_INFO; - } - } else { - if (TAG_HIDDEN == tag) { - return BOOK_DESCRIPTION; - } - } - break; - case TITLE_INFO: - if (!closed) { - if (TAG_GENRE == tag) { - return GENRE; - } else if (TAG_AUTHOR == tag) { - return AUTHOR; - } else if (TAG_BOOK_TITLE == tag) { - return BOOK_TITLE; - } else if (TAG_ANNOTATION == tag) { - return ANNOTATION; - } else if (TAG_DATE == tag) { - return DATE; - } else if (TAG_LANGUAGE == tag) { - return LANGUAGE; - } /*else if (TAG_SEQUENCE == tag) { - return SEQUENCE; // handled without state through attributes - }*/ - } else { - if (TAG_TITLE_INFO == tag) { - return HIDDEN; - } - } - break; - case AUTHOR: - if (!closed) { - if (TAG_FIRST_NAME == tag) { - return FIRST_NAME; - } else if (TAG_MIDDLE_NAME == tag) { - return MIDDLE_NAME; - } else if (TAG_LAST_NAME == tag) { - return LAST_NAME; - } else if (TAG_AUTHOR_ID == tag) { - return AUTHOR_ID; - } - } else { - if (TAG_AUTHOR == tag) { - return TITLE_INFO; - } - } - break; - case FIRST_NAME: - if (closed && TAG_FIRST_NAME == tag) { - return AUTHOR; - } - break; - case MIDDLE_NAME: - if (closed && TAG_MIDDLE_NAME == tag) { - return AUTHOR; - } - break; - case LAST_NAME: - if (closed && TAG_LAST_NAME == tag) { - return AUTHOR; - } - break; - case AUTHOR_ID: - if (closed && TAG_AUTHOR_ID == tag) { - return AUTHOR; - } - break; - case GENRE: - if (closed && TAG_GENRE == tag) { - return TITLE_INFO; - } - break; - case BOOK_TITLE: - if (closed && TAG_BOOK_TITLE == tag) { - return TITLE_INFO; - } - break; - case ANNOTATION: - if (closed && TAG_ANNOTATION == tag) { - return TITLE_INFO; - } - break; - case DATE: - if (closed && TAG_DATE == tag) { - return TITLE_INFO; - } - break; - case LANGUAGE: - if (closed && TAG_LANGUAGE == tag) { - return TITLE_INFO; - } - break; - } - return myState; -} - diff --git a/fbreader/src/network/litres/LitResBooksFeedParser.h b/fbreader/src/network/litres/LitResBooksFeedParser.h deleted file mode 100644 index 6f9a6dc..0000000 --- a/fbreader/src/network/litres/LitResBooksFeedParser.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESBOOKSFEEDPARSER_H__ -#define __LITRESBOOKSFEEDPARSER_H__ - -#include <vector> -#include <map> - -#include <ZLXMLReader.h> - -#include "../NetworkItems.h" - -#include "LitResBooksFeedItem.h" - -class NetworkLink; -struct LitResGenre; -class NetworkAuthenticationManager; - -class LitResBooksFeedParser : public ZLXMLReader { - -public: - LitResBooksFeedParser(const NetworkLink &link, NetworkItem::List &books, LitResBooksFeedItem::LoadingState *state = 0); - -private: - void startElementHandler(const char *tag, const char **attributes); - void endElementHandler(const char *tag); - void characterDataHandler(const char *text, std::size_t len); - -private: - enum State { - START, CATALOG, BOOK, BOOK_DESCRIPTION, HIDDEN, TITLE_INFO, - GENRE, AUTHOR, FIRST_NAME, MIDDLE_NAME, LAST_NAME, AUTHOR_ID, BOOK_TITLE, - ANNOTATION, DATE, LANGUAGE, - }; - - std::string stringAttributeValue(const char **attributes, const char *name); - void processState(const std::string &tag, bool closed, const char **attributes); - State getNextState(const std::string &tag, bool closed); - -private: - const NetworkLink &myLink; - - NetworkItem::List &myBooks; - std::string myBuffer; - - unsigned int myIndex; - - State myState; - - std::string myBookId; - std::string myTitle; - std::string mySummary; - std::string myLanguage; - std::string myDate; - std::string mySeriesTitle; - int myIndexInSeries; - - std::string myAuthorFirstName; - std::string myAuthorMiddleName; - std::string myAuthorLastName; - std::string myAuthorId; - std::vector<NetworkBookItem::AuthorData> myAuthors; - std::vector<std::string> myAuthorsIds; - - std::vector<std::string> myTags; - NetworkItem::UrlInfoCollection myURLByType; - std::vector<shared_ptr<BookReference> > myReferences; - - LitResBooksFeedItem::LoadingState *myLoadingState; -}; - -#endif /* __LITRESBOOKSFEEDPARSER_H__ */ diff --git a/fbreader/src/network/litres/LitResBookshelfItem.cpp b/fbreader/src/network/litres/LitResBookshelfItem.cpp deleted file mode 100644 index be931fe..0000000 --- a/fbreader/src/network/litres/LitResBookshelfItem.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <algorithm> - -#include <ZLNetworkRequest.h> -#include <ZLExecutionUtil.h> - -#include "LitResBookshelfItem.h" -#include "../authentication/litres/LitResAuthenticationManager.h" - -#include "../NetworkLink.h" -#include "../NetworkComparators.h" -#include "../NetworkErrors.h" - -#include "SortedCatalogItem.h" - -LitResBookshelfItem::LitResBookshelfItem( - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility -) : NetworkCatalogItem( - link, - title, - summary, - urlByType, - accessibility -) { - myForceReload = false; -} - -void LitResBookshelfItem::onDisplayItem() { - myForceReload = false; -} - -class LitResBookshelfItemLoaderScope : public ZLUserData { -public: - LitResBookshelfItemLoaderScope(NetworkItem::List &children) : Children(children) {} - NetworkItem::List &Children; - shared_ptr<ZLNetworkRequest::Listener> listener; -}; - - -std::string LitResBookshelfItem::loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { - LitResAuthenticationManager &mgr = (LitResAuthenticationManager&)*Link.authenticationManager(); - if (mgr.isAuthorised().Status == B3_FALSE) { - listener->finished(NetworkErrors::errorMessage(NetworkErrors::ERROR_AUTHENTICATION_FAILED)); - return NetworkErrors::errorMessage(NetworkErrors::ERROR_AUTHENTICATION_FAILED); - } - - LitResBookshelfItemLoaderScope *scope = new LitResBookshelfItemLoaderScope(children); - scope->listener = listener; - - shared_ptr<ZLUserDataHolder> scopeData = new ZLUserDataHolder; - scopeData->addUserData("scope", scope); - if (myForceReload) { - mgr.reloadPurchasedBooks(ZLExecutionUtil::createListener(scopeData, this, &LitResBookshelfItem::onReloaded)); - return std::string(); - } - onReloaded(*scopeData, std::string()); - return std::string(); -} - -void LitResBookshelfItem::onReloaded(ZLUserDataHolder &data, const std::string &error) { - LitResBookshelfItemLoaderScope &scope = static_cast<LitResBookshelfItemLoaderScope&>(*data.getUserData("scope")); - LitResAuthenticationManager &mgr = static_cast<LitResAuthenticationManager&>(*Link.authenticationManager()); - myForceReload = true; - NetworkItem::List tmpChildren; - mgr.collectPurchasedBooks(tmpChildren); - std::sort(tmpChildren.begin(), tmpChildren.end(), NetworkBookItemComparator()); - - - NetworkItem::List &children = scope.Children; - - if (tmpChildren.size() <= 5) { - children.assign(tmpChildren.begin(), tmpChildren.end()); - std::sort(children.begin(), children.end(), NetworkBookItemComparator()); - } else { - children.push_back(SortedCatalogItem::create(*this, "byDate", tmpChildren, FLAG_SHOW_AUTHOR)); - children.push_back(SortedCatalogItem::create(*this, "byAuthor", tmpChildren, FLAG_GROUP_BY_AUTHOR, NetworkBookItemComparator())); - children.push_back(SortedCatalogItem::create(*this, "byTitle", tmpChildren, FLAG_SHOW_AUTHOR, NetworkBookItemByTitleComparator())); - SortedCatalogItem* bySeries = SortedCatalogItem::create(*this, "bySeries", tmpChildren, FLAG_SHOW_AUTHOR | FLAG_GROUP_BY_SERIES, - NetworkBookItemBySeriesComparator(), SortedCatalogItem::BySeriesFilter()); - - if (!bySeries->isEmpty()) { - children.push_back(bySeries); - } else { - delete bySeries; - } - } - - scope.listener->finished(error); -} diff --git a/fbreader/src/network/litres/LitResBookshelfItem.h b/fbreader/src/network/litres/LitResBookshelfItem.h deleted file mode 100644 index 22ea8d9..0000000 --- a/fbreader/src/network/litres/LitResBookshelfItem.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESBOOKSHELFITEM_H__ -#define __LITRESBOOKSHELFITEM_H__ - -#include <ZLResource.h> -#include <ZLExecutionUtil.h> - -#include "../NetworkComparators.h" -#include "../NetworkItems.h" - -class NetworkLink; - -class LitResBookshelfItem : public NetworkCatalogItem { - -public: - LitResBookshelfItem( - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility = ALWAYS - ); - -private: - void onDisplayItem(); - std::string loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - void onReloaded(ZLUserDataHolder &data, const std::string &error); - -private: - bool myForceReload; -}; - -#endif /* __LITRESBOOKSHELFITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResByGenresItem.cpp b/fbreader/src/network/litres/LitResByGenresItem.cpp deleted file mode 100644 index a9b6367..0000000 --- a/fbreader/src/network/litres/LitResByGenresItem.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <algorithm> - -#include <ZLNetworkManager.h> - -#include "../NetworkLink.h" -#include "../NetworkComparators.h" -#include "../NetworkErrors.h" -#include "../NetworkItems.h" - -#include "LitResUtil.h" -#include "LitResBooksFeedParser.h" -#include "LitResBooksFeedItem.h" - -#include "LitResByGenresItem.h" - -static const std::string EMPTY_STRING = std::string(); - -LitResByGenresItem::LitResByGenresItem( - const std::vector<shared_ptr<LitResGenre> > &genreTree, - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility, - int flags -) : NetworkCatalogItem( - link, - title, - summary, - urlByType, - accessibility, - flags -), myGenreTree(genreTree) { -} - -std::string LitResByGenresItem::loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { - for (std::size_t i = 0; i < myGenreTree.size(); ++i) { - shared_ptr<LitResGenre> genre = myGenreTree.at(i); - if (genre->Children.empty()) { - UrlInfoCollection urlByType = URLByType; - urlByType[NetworkItem::URL_CATALOG] = LitResUtil::generateBooksByGenreUrl(genre->Id); - //TODO add icon change for one genre here - //urlByType[NetworkItem::URL_COVER] = - children.push_back(new LitResBooksFeedItem(true, Link, genre->Title, EMPTY_STRING, urlByType, ALWAYS)); - } else { - children.push_back(new LitResByGenresItem(genre->Children, Link, genre->Title, EMPTY_STRING, URLByType, ALWAYS, FLAG_NONE)); - } - } - listener->finished(); - return std::string(); -} - diff --git a/fbreader/src/network/litres/LitResByGenresItem.h b/fbreader/src/network/litres/LitResByGenresItem.h deleted file mode 100644 index 3af0e23..0000000 --- a/fbreader/src/network/litres/LitResByGenresItem.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESBYGENRESITEM_H__ -#define __LITRESBYGENRESITEM_H__ - -#include "../NetworkItems.h" - -#include "LitResGenre.h" - -class LitResByGenresItem : public NetworkCatalogItem { - -public: - LitResByGenresItem( - const std::vector<shared_ptr<LitResGenre> > &genreTree, - const NetworkLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility, - int flags - ); - -private: - std::string loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - -private: - const std::vector<shared_ptr<LitResGenre> > &myGenreTree; -}; - -#endif /* __LITRESBYGENRESITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResGenre.cpp b/fbreader/src/network/litres/LitResGenre.cpp deleted file mode 100644 index a541948..0000000 --- a/fbreader/src/network/litres/LitResGenre.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <cstdlib> - -#include <ZLStringUtil.h> -#include <ZLUnicodeUtil.h> -#include <ZLNetworkManager.h> - -#include <ZLibrary.h> -#include <ZLDir.h> -#include <ZLFile.h> -#include <ZLTime.h> - -#include "LitResGenresParser.h" -#include "LitResGenre.h" -#include "LitResUtil.h" - -static const std::string GENRES_CACHE_PREFIX = "litres_genres_"; -static const std::string GENRES_CACHE_SUFFIX = ".xml"; - -LitResGenre::LitResGenre() { -} - -LitResGenre::LitResGenre(const std::string &id, const std::string &title) : Id(id), Title(title) { -} - -LitResGenreMap *LitResGenreMap::ourInstance = 0; - -const LitResGenreMap &LitResGenreMap::Instance() { - if (ourInstance == 0) { - ourInstance = new LitResGenreMap(); - } - return *ourInstance; -} - -LitResGenreMap::LitResGenreMap() : myInitialized(false) { -} - -void LitResGenreMap::validateGenres() const { - if (!myInitialized) { - if (loadGenres()) { - buildGenresTitles(myGenresTree); - myInitialized = true; - } - } -} - -const std::map<std::string, shared_ptr<LitResGenre> > &LitResGenreMap::genresMap() const { - validateGenres(); - return myGenresMap; -} - -const std::vector<shared_ptr<LitResGenre> > &LitResGenreMap::genresTree() const { - validateGenres(); - return myGenresTree; -} - -const std::map<shared_ptr<LitResGenre>, std::string> &LitResGenreMap::genresTitles() const { - validateGenres(); - return myGenresTitles; -} - -void LitResGenreMap::fillGenreIds(const std::string &tag, std::vector<std::string> &ids) const { - std::vector<std::string> words; - int index = 0; - - const std::map<shared_ptr<LitResGenre>, std::string> map = genresTitles(); - - do { - int index2 = tag.find(' ', index); - std::string word = tag.substr(index, index2 - index); - ZLUnicodeUtil::utf8Trim(word); - if (!word.empty()) { - words.push_back(ZLUnicodeUtil::toLower(word)); - } - index = index2 + 1; - } while (index != 0); - - for (std::map<shared_ptr<LitResGenre>, std::string>::const_iterator it = map.begin(); it != map.end(); ++it) { - const LitResGenre &genre = *it->first; - std::string title = ZLUnicodeUtil::toLower(it->second); - bool containsAll = true; - for (std::vector<std::string>::const_iterator jt = words.begin(); jt != words.end(); ++jt) { - if (title.find(*jt) == std::string::npos) { - containsAll = false; - break; - } - } - if (containsAll) { - ids.push_back(genre.Id); - } - } -} - -bool LitResGenreMap::loadGenres() const { - static const std::string directoryPath = ZLNetworkManager::CacheDirectory(); - static shared_ptr<ZLDir> dir = ZLFile(directoryPath).directory(true); - - const std::string url = LitResUtil::url("pages/catalit_genres/"); - - myGenresTree.clear(); - myGenresMap.clear(); - myGenresTitles.clear(); - - if (dir.isNull()) { - shared_ptr<ZLNetworkRequest> networkData = ZLNetworkManager::Instance().createXMLParserRequest( - url, - new LitResGenresParser(myGenresTree, myGenresMap) - ); - const std::string error = ZLNetworkManager::Instance().perform(networkData); - if (!error.empty()) { - myGenresTree.clear(); - myGenresMap.clear(); - myGenresTitles.clear(); - return false; - } - return true; - } - - std::string cacheName; - bool cacheValid = false; - - std::vector<std::string> files; - dir->collectFiles(files, false); - for (std::vector<std::string>::const_iterator it = files.begin(); it != files.end(); ++it) { - const std::string &name = *it; - if (ZLStringUtil::stringStartsWith(name, GENRES_CACHE_PREFIX)) { - cacheName = name; - } - } - files.clear(); - - ZLTime now; - - if (!cacheName.empty()) { - std::string cacheDate = cacheName.substr(GENRES_CACHE_PREFIX.size(), 8); - int cacheYear = std::atoi(cacheDate.substr(0, 4).c_str()); - int cacheMonth = std::atoi(cacheDate.substr(4, 2).c_str()); - int cacheDay = std::atoi(cacheDate.substr(6, 2).c_str()); - int daysDiff = (now.year() - cacheYear) * 365 + (now.month() - cacheMonth) * 31 + (now.dayOfMonth() - cacheDay); - if (daysDiff < 30) { - cacheValid = true; - } - cacheName = dir->itemPath(cacheName); - } - - if (!cacheValid) { - std::string yearStr, monthStr, dayStr; - ZLStringUtil::appendNumber(yearStr, now.year()); - ZLStringUtil::appendNumber(monthStr, now.month()); - ZLStringUtil::appendNumber(dayStr, now.dayOfMonth()); - while (monthStr.size() < 2) { - monthStr = "0" + monthStr; - } - while (dayStr.size() < 2) { - dayStr = "0" + dayStr; - } - - const std::string fileName = dir->path() + ZLibrary::FileNameDelimiter + - GENRES_CACHE_PREFIX + yearStr + monthStr + dayStr + GENRES_CACHE_SUFFIX; - - const std::string error = ZLNetworkManager::Instance().downloadFile(url, fileName); - if (!error.empty()) { - ZLFile(fileName).remove(); - } else { - ZLFile(cacheName).remove(); - cacheName = fileName; - } - } - - if (cacheName.empty()) { - return false; - } - - shared_ptr<ZLXMLReader> parser = new LitResGenresParser(myGenresTree, myGenresMap); - return parser->readDocument(ZLFile(cacheName)); -} - -void LitResGenreMap::buildGenresTitles(const std::vector<shared_ptr<LitResGenre> > &genres, const std::string &titlePrefix) const { - for (std::vector<shared_ptr<LitResGenre> >::const_iterator it = genres.begin(); it != genres.end(); ++it) { - shared_ptr<LitResGenre> genre = *it; - std::string title = titlePrefix.empty() ? (genre->Title) : (titlePrefix + "/" + genre->Title); - if (genre->Id.empty()) { - buildGenresTitles(genre->Children, title); - } else { - myGenresTitles[genre] = title; - } - } -} diff --git a/fbreader/src/network/litres/LitResGenre.h b/fbreader/src/network/litres/LitResGenre.h deleted file mode 100644 index 4b2bd3b..0000000 --- a/fbreader/src/network/litres/LitResGenre.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESGENRE_H__ -#define __LITRESGENRE_H__ - -#include <string> -#include <vector> -#include <map> - -#include <shared_ptr.h> - -struct LitResGenre { - std::string Id; - std::string Title; - std::vector<shared_ptr<LitResGenre> > Children; - - LitResGenre(); - LitResGenre(const std::string &id, const std::string &title); -}; - -class LitResGenreMap { - -public: - static const LitResGenreMap &Instance(); - -private: - static LitResGenreMap *ourInstance; - -private: - LitResGenreMap(); - -public: - const std::map<std::string, shared_ptr<LitResGenre> > &genresMap() const; - const std::vector<shared_ptr<LitResGenre> > &genresTree() const; - const std::map<shared_ptr<LitResGenre>, std::string> &genresTitles() const; - void fillGenreIds(const std::string &tag, std::vector<std::string> &ids) const; - -private: - void validateGenres() const; - bool loadGenres() const; - void buildGenresTitles(const std::vector<shared_ptr<LitResGenre> > &genres, const std::string &titlePrefix = "") const; - - mutable std::vector<shared_ptr<LitResGenre> > myGenresTree; - mutable std::map<std::string, shared_ptr<LitResGenre> > myGenresMap; - mutable std::map<shared_ptr<LitResGenre>, std::string> myGenresTitles; - mutable bool myInitialized; -}; - -#endif /* __LITRESGENRE_H__ */ diff --git a/fbreader/src/network/litres/LitResGenresParser.cpp b/fbreader/src/network/litres/LitResGenresParser.cpp deleted file mode 100644 index 9ed3f2d..0000000 --- a/fbreader/src/network/litres/LitResGenresParser.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <ZLStringUtil.h> - -#include "LitResGenresParser.h" - -#include "LitResGenre.h" - -static const std::string TAG_GENRE = "genre"; - - -LitResGenresParser::LitResGenresParser(std::vector<shared_ptr<LitResGenre> > &genresTree, std::map<std::string, shared_ptr<LitResGenre> > &genresMap) : - myGenresTree(genresTree), - myGenresMap(genresMap), - myDontPopStack(false) { -} - -void LitResGenresParser::saveGenre(shared_ptr<LitResGenre> genre, const std::string &token) { - if (myStack.empty()) { - myGenresTree.push_back(genre); - } else { - myStack.back()->Children.push_back(genre); - } - if (genre->Id.empty()) { - myStack.push_back(genre); - } else { - myDontPopStack = true; - if (!token.empty()) { - myGenresMap[token] = genre; - } - } -} - -void LitResGenresParser::startElementHandler(const char *tag, const char **attributes) { - if (TAG_GENRE == tag) { - const char *id = attributeValue(attributes, "id"); - const char *title = attributeValue(attributes, "title"); - const char *token = attributeValue(attributes, "token"); - std::string strId, strTitle, strToken; - if (id != 0) { - strId = id; - } - if (title != 0) { - strTitle = title; - } - if (token != 0) { - strToken = token; - } - saveGenre(new LitResGenre(strId, strTitle), strToken); - } -} - -void LitResGenresParser::endElementHandler(const char *tag) { - if (TAG_GENRE == tag) { - if (!myDontPopStack) { - myStack.pop_back(); - } - myDontPopStack = false; - } -} - -void LitResGenresParser::characterDataHandler(const char *, std::size_t) { -} - diff --git a/fbreader/src/network/litres/LitResGenresParser.h b/fbreader/src/network/litres/LitResGenresParser.h deleted file mode 100644 index 424d37b..0000000 --- a/fbreader/src/network/litres/LitResGenresParser.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESGENRESPARSER_H__ -#define __LITRESGENRESPARSER_H__ - - -#include <map> -#include <vector> -#include <string> - -#include <ZLXMLReader.h> - -struct LitResGenre; - -class LitResGenresParser : public ZLXMLReader { - -public: - LitResGenresParser(std::vector<shared_ptr<LitResGenre> > &genresTree, std::map<std::string, shared_ptr<LitResGenre> > &genresMap); - -private: - void startElementHandler(const char *tag, const char **attributes); - void endElementHandler(const char *tag); - void characterDataHandler(const char *text, std::size_t len); - - void saveGenre(shared_ptr<LitResGenre> genre, const std::string &token); - - const std::string &titlePrefix(); - -private: - std::vector<shared_ptr<LitResGenre> > &myGenresTree; - std::map<std::string, shared_ptr<LitResGenre> > &myGenresMap; - std::vector<shared_ptr<LitResGenre> > myStack; - bool myDontPopStack; - - std::vector<std::string> myTitleStack; - std::string myTitlePrefix; -}; - -#endif /* __LITRESGENRESPARSER_H__ */ diff --git a/fbreader/src/network/litres/LitResRecommendationsItem.cpp b/fbreader/src/network/litres/LitResRecommendationsItem.cpp deleted file mode 100644 index 54d7cd7..0000000 --- a/fbreader/src/network/litres/LitResRecommendationsItem.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <ZLStringUtil.h> -#include <ZLNetworkUtil.h> - -#include "../NetworkLink.h" -#include "../authentication/litres/LitResAuthenticationManager.h" - -#include "LitResRecommendationsItem.h" - -LitResRecommendationsItem::LitResRecommendationsItem( - const OPDSLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility -) : OPDSCatalogItem( - link, - title, - summary, - urlByType, - accessibility -) { } - -std::string LitResRecommendationsItem::getCatalogUrl() { - LitResAuthenticationManager &mgr = (LitResAuthenticationManager&)*Link.authenticationManager(); - std::string catalogUrl = OPDSCatalogItem::getCatalogUrl(); - if (mgr.isAuthorised().Status == B3_FALSE) { - return catalogUrl; - } - std::string query = ZLStringUtil::join(mgr.getPurchasedIds(), ","); - ZLNetworkUtil::appendParameter(catalogUrl, "ids", query); - return catalogUrl; -} diff --git a/fbreader/src/network/litres/LitResRecommendationsItem.h b/fbreader/src/network/litres/LitResRecommendationsItem.h deleted file mode 100644 index ba27623..0000000 --- a/fbreader/src/network/litres/LitResRecommendationsItem.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESRECOMMENDATIONSITEM_H__ -#define __LITRESRECOMMENDATIONSITEM_H__ - -#include "../opds/OPDSCatalogItem.h" - -class LitResRecommendationsItem : public OPDSCatalogItem { - -public: - LitResRecommendationsItem( - const OPDSLink &link, - const std::string &title, - const std::string &summary, - const UrlInfoCollection &urlByType, - AccessibilityType accessibility = ALWAYS - ); - -private: - std::string getCatalogUrl(); -}; - -#endif /* __LITRESRECOMMENDATIONSITEM_H__ */ diff --git a/fbreader/src/network/litres/LitResUtil.cpp b/fbreader/src/network/litres/LitResUtil.cpp deleted file mode 100644 index 992b7d9..0000000 --- a/fbreader/src/network/litres/LitResUtil.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include <ZLNetworkUtil.h> -#include <ZLStringUtil.h> - -#include "../NetworkLink.h" -#include "../opds/OPDSMetadata.h" - -#include "LitResBookshelfItem.h" -#include "LitResBooksFeedItem.h" -#include "LitResRecommendationsItem.h" -#include "LitResByGenresItem.h" -#include "LitResAuthorsItem.h" - -#include "LitResUtil.h" - - -static std::string LITRES_API_URL = "://robot.litres.ru/"; - -std::string LitResUtil::url(const std::string &path) { - std::string url = LITRES_API_URL + path; - if (ZLNetworkUtil::hasParameter(url, "sid") || - ZLNetworkUtil::hasParameter(url, "pwd")) { - url = "https" + url; - } else { - url = "http" + url; - } - return url; -} - -std::string LitResUtil::url(const NetworkLink &link, const std::string &path) { - std::string urlString = url(path); - link.rewriteUrl(urlString); - return urlString; -} - -std::string LitResUtil::url(bool secure, const std::string &path) { - std::string url = LITRES_API_URL + path; - if (secure) { - url = "https" + url; - } else { - url = "http" + url; - } - return url; -} - -std::string LitResUtil::url(const NetworkLink &link, bool secure, const std::string &path) { - std::string urlString = url(secure, path); - link.rewriteUrl(urlString, true); - return urlString; -} - -std::string LitResUtil::generateTrialUrl(std::string bookId) { - std::size_t len = bookId.length(); - if (len < 8) { - bookId = std::string(8 - len, '0') + bookId; - } - std::string query = "static/trials/%s/%s/%s/%s.fb2.zip"; - query = ZLStringUtil::printf(query, bookId.substr(0,2)); - query = ZLStringUtil::printf(query, bookId.substr(2,2)); - query = ZLStringUtil::printf(query, bookId.substr(4,2)); - query = ZLStringUtil::printf(query, bookId); - return url(false, query); -} - -std::string LitResUtil::generatePurchaseUrl(const NetworkLink &link, const std::string &bookId) { - std::string query; - ZLNetworkUtil::appendParameter(query, "art", bookId); - return url(link, true, "pages/purchase_book/" + query); -} - -std::string LitResUtil::generateDownloadUrl(const std::string &bookId) { - std::string query; - ZLNetworkUtil::appendParameter(query, "art", bookId); - return url(true, "pages/catalit_download_book/" + query); -} - -std::string LitResUtil::generateAlsoReadUrl(const std::string &bookId) { - std::string query; - ZLNetworkUtil::appendParameter(query, "rating", "with"); - ZLNetworkUtil::appendParameter(query, "art", bookId); - return url(false, "pages/catalit_browser/" + query); -} - -std::string LitResUtil::generateBooksByGenreUrl(const std::string &genreId) { - std::string query; - ZLNetworkUtil::appendParameter(query, "checkpoint", "2000-01-01"); - ZLNetworkUtil::appendParameter(query, "genre", genreId); - return url(false, "pages/catalit_browser/" + query); -} - -std::string LitResUtil::generateBooksByAuthorUrl(const std::string &authorId) { - std::string query; - ZLNetworkUtil::appendParameter(query, "checkpoint", "2000-01-01"); - ZLNetworkUtil::appendParameter(query, "person", authorId); - return url(false, "pages/catalit_browser/" + query); -} - -shared_ptr<NetworkItem> LitResUtil::createLitResNode(shared_ptr<ZLMimeType> type, std::string rel, const NetworkLink &link, std::string title, - std::string annotation, std::map<NetworkItem::URLType,std::string> urlMap, bool dependsOnAccount) { - static const std::string TYPE = "type"; - static const std::string NO = "no"; - - std::string litresType = type->getParameter(TYPE); - - if (rel == OPDSConstants::REL_BOOKSHELF) { - return new LitResBookshelfItem( - link, - title, - annotation, - urlMap, - NetworkCatalogItem::SIGNED_IN - ); - } else if (rel == OPDSConstants::REL_RECOMMENDATIONS) { - return new LitResRecommendationsItem( - (OPDSLink&)link, - title, - annotation, - urlMap, - NetworkCatalogItem::HAS_BOOKS - ); - } else if (litresType == ZLMimeType::APPLICATION_LITRES_XML_BOOKS->getParameter(TYPE)) { - int flags = NetworkCatalogItem::FLAGS_DEFAULT; - if (type->getParameter("groupSeries") == NO) { - flags &= ~NetworkCatalogItem::FLAG_GROUP_MORE_THAN_1_BOOK_BY_SERIES; - } - if (type->getParameter("showAuthor") == "false") { - flags &= ~NetworkCatalogItem::FLAG_SHOW_AUTHOR; - } - bool sort = type->getParameter("sort") != NO; - return new LitResBooksFeedItem( - sort, - link, - title, - annotation, - urlMap, - dependsOnAccount ? NetworkCatalogItem::SIGNED_IN : NetworkCatalogItem::ALWAYS, - flags - ); - } else if (litresType == ZLMimeType::APPLICATION_LITRES_XML_GENRES->getParameter(TYPE)) { - return new LitResByGenresItem( - LitResGenreMap::Instance().genresTree(), - link, - title, - annotation, - urlMap, - NetworkCatalogItem::ALWAYS, - NetworkCatalogItem::FLAG_SHOW_AUTHOR - ); - } else if (litresType == ZLMimeType::APPLICATION_LITRES_XML_AUTHORS->getParameter(TYPE)) { - return new LitResAuthorsItem( - link, - title, - annotation, - urlMap, - NetworkCatalogItem::ALWAYS - ); - } else { - return 0; - } -} diff --git a/fbreader/src/network/litres/LitResUtil.h b/fbreader/src/network/litres/LitResUtil.h deleted file mode 100644 index fd23a08..0000000 --- a/fbreader/src/network/litres/LitResUtil.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <[email protected]> - * - * 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 __LITRESUTIL_H__ -#define __LITRESUTIL_H__ - -#include <string> - -#include "../NetworkItems.h" - -class NetworkLink; - -class LitResUtil { - -public: - static std::string url(const std::string &path); - static std::string url(const NetworkLink &link, const std::string &path); - static std::string url(const NetworkLink &link, bool secure, const std::string &path); - static std::string url(bool secure, const std::string &path); - - static std::string generateTrialUrl(std::string bookId); - static std::string generatePurchaseUrl(const NetworkLink &link, const std::string &bookId); - static std::string generateDownloadUrl(const std::string &bookId); - static std::string generateAlsoReadUrl(const std::string &bookId); - static std::string generateBooksByGenreUrl(const std::string &genreId); - static std::string generateBooksByAuthorUrl(const std::string &authorId); - -public: - static shared_ptr<NetworkItem> createLitResNode(shared_ptr<ZLMimeType> type, std::string rel, - const NetworkLink &link, std::string title, - std::string annotation, std::map<NetworkItem::URLType,std::string> urlMap, - bool dependsOnAccount); - -private: - LitResUtil(); -}; - -#endif /* __LITRESUTIL_H__ */ diff --git a/fbreader/src/network/litres/SortedCatalogItem.cpp b/fbreader/src/network/litres/SortedCatalogItem.cpp deleted file mode 100644 index 79d7f49..0000000 --- a/fbreader/src/network/litres/SortedCatalogItem.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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. - */ - -#include "SortedCatalogItem.h" - -bool SortedCatalogItem::BookItemFilter::accepts(NetworkItem* item) const { - return zlobject_cast<NetworkBookItem*>(item) != 0; -} - -bool SortedCatalogItem::BySeriesFilter::accepts(NetworkItem* item) const { - NetworkBookItem* bookItem = zlobject_cast<NetworkBookItem*>(item); - return bookItem != 0 && !bookItem->SeriesTitle.empty(); -} - -SortedCatalogItem::SortedCatalogItem(const NetworkCatalogItem &parent, const ZLResource &resource, - const NetworkItem::List &children, int flags) - : NetworkCatalogItem(parent.Link, resource.value(), resource["summary"].value(), parent.URLByType, ALWAYS, flags) { - myChildren = children; -} - -std::string SortedCatalogItem::loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener) { - children.assign(myChildren.begin(), myChildren.end()); - listener->finished(); - return std::string(); -} - -bool SortedCatalogItem::isEmpty() const { - return myChildren.empty(); -} - -const ZLResource &SortedCatalogItem::resource(const std::string &resourceKey) { - return ZLResource::resource("networkView")[resourceKey]; -} diff --git a/fbreader/src/network/litres/SortedCatalogItem.h b/fbreader/src/network/litres/SortedCatalogItem.h deleted file mode 100644 index e4f2744..0000000 --- a/fbreader/src/network/litres/SortedCatalogItem.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <[email protected]> - * - * 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 __SORTEDCATALOGITEM_H__ -#define __SORTEDCATALOGITEM_H__ - -#include <algorithm> - -#include <ZLResource.h> - -#include "../NetworkComparators.h" -#include "../NetworkItems.h" - -class SortedCatalogItem : public NetworkCatalogItem { - -public: - class BookItemFilter { - public: - bool accepts(NetworkItem* item) const; - }; - - class BySeriesFilter { - public: - bool accepts(NetworkItem* item) const; - }; - - //TODO maybe refactor (using templates is too complex for this simple case - //(templates were used because in C++ virtual methods can't be called from constructor) - template <class T, class F> - static SortedCatalogItem* create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags, T comparator, F filter); - template <class T> - static SortedCatalogItem* create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags, T comparator); - static SortedCatalogItem* create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags); - -public: - SortedCatalogItem(const NetworkCatalogItem &parent, const ZLResource &resource, const NetworkItem::List &children, int flags); - -public: - std::string loadChildren(NetworkItem::List &children, shared_ptr<ZLNetworkRequest::Listener> listener); - bool isEmpty() const; - //TODO following method should be in class NetworkLibrary or smth like that - static const ZLResource &resource(const std::string &resourceKey); - -protected: - NetworkItem::List myChildren; -}; - -template <class T, class F> -SortedCatalogItem* SortedCatalogItem::create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags, T comparator, F filter) { - NetworkItem::List tmpChildren; - for (std::size_t i = 0; i < children.size(); ++i) { - shared_ptr<NetworkItem> child = children.at(i); - if (filter.accepts(&(*child))) { - tmpChildren.push_back(child); - } - } - std::sort(tmpChildren.begin(), tmpChildren.end(), comparator); - return new SortedCatalogItem(parent, resource(resourceKey), tmpChildren, flags); -} - -template <class T> -SortedCatalogItem* SortedCatalogItem::create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags, T comparator) { - return create(parent, resourceKey, children, flags, comparator, BookItemFilter()); -} - -inline SortedCatalogItem* SortedCatalogItem::create(const NetworkCatalogItem &parent, const std::string &resourceKey, - const NetworkItem::List &children, int flags) { - BookItemFilter filter; - NetworkItem::List tmpChildren; - for (std::size_t i = 0; i < children.size(); ++i) { - shared_ptr<NetworkItem> child = children.at(i); - if (filter.accepts(&(*child))) { - tmpChildren.push_back(child); - } - } - return new SortedCatalogItem(parent, resource(resourceKey), tmpChildren, flags); -} - -#endif /* __SORTEDCATALOGITEM_H__ */ |