void NetworkBookBuyDirectlyAction::onAuthorised(ZLUserDataHolder &data, const std::string &error) { (void) data; if (!error.empty()) { // finished(error); return; } NetworkAuthenticationManager &mgr = *myBook.Link.authenticationManager(); if (!mgr.needPurchase(myBook)) { // finished(std::string()); return; } ZLResourceKey boxKey("purchaseConfirmBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); const int code = ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("buy"), ZLResourceKey("buyAndDownload"), ZLDialogManager::CANCEL_BUTTON); if (code == 2) { // finished(std::string()); return; } bool downloadBook = code == 1; if (mgr.needPurchase(myBook)) { ZLUserDataHolder *bookData = new ZLUserDataHolder; if (downloadBook) bookData->addUserData("downloadBook", new ZLUserData); // mgr.purchaseBook(myBook, ZLExecutionData::createListener(bookData, this, &NetworkBookBuyDirectlyAction::onPurchased)); } else if (downloadBook) { NetworkBookDownloadAction::run(); } }
void NetworkBookTree::BookItemWrapper::onCoverLoaded(ZLUserDataHolder &data, const std::string &error) { BookItemWrapperScope &scope = static_cast<BookItemWrapperScope&>(*data.getUserData("scope")); if (error.empty()) { myIsInitialized = true; } scope.listener->finished(error); }
void NetworkBookBuyDirectlyAction::onPurchased(ZLUserDataHolder &data, const std::string &error) { if (!error.empty()) { ZLDialogManager::Instance().errorBox( ZLResourceKey("networkError"), error ); // finished(error); return; } if (data.getUserData("downloadBook").isNull()) {} // finished(std::string()); else NetworkBookDownloadAction::run(); }
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); }