From 17b259df9cb6b28779d4881b2b6c805ee2e48eea Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 7 Jun 2024 23:30:05 +0900 Subject: Rename to tde-ebook-reader Signed-off-by: Michele Calgaro --- fbreader/src/network/tree/NetworkCatalogUtil.cpp | 92 ------------------------ 1 file changed, 92 deletions(-) delete mode 100644 fbreader/src/network/tree/NetworkCatalogUtil.cpp (limited to 'fbreader/src/network/tree/NetworkCatalogUtil.cpp') diff --git a/fbreader/src/network/tree/NetworkCatalogUtil.cpp b/fbreader/src/network/tree/NetworkCatalogUtil.cpp deleted file mode 100644 index 953bf67..0000000 --- a/fbreader/src/network/tree/NetworkCatalogUtil.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2009-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. - */ - -#include -#include - -#include -#include - -#include "NetworkCatalogUtil.h" - -#include "../NetworkLinkCollection.h" - -shared_ptr NetworkCatalogUtil::getImageByNetworkUrl(const std::string &url, const std::string &prefix) { - if (!ZLStringUtil::stringStartsWith(url, prefix)) { - return 0; - } - - return new ZLNetworkImage(ZLMimeType::IMAGE_AUTO, url); -} - -shared_ptr NetworkCatalogUtil::getImageByDataUrl(const std::string &url) { - if (!ZLStringUtil::stringStartsWith(url, "data:")) { - return 0; - } - - std::size_t index = url.find(','); - if (index == std::string::npos) { - return 0; - } - - ZLBase64EncodedImage *image = new ZLBase64EncodedImage(ZLMimeType::IMAGE_AUTO); - image->addData(url, index + 1, std::string::npos); - return image; -} - -shared_ptr NetworkCatalogUtil::getImageByUrl(const std::string &url) { - shared_ptr image; - - image = getImageByNetworkUrl(url, "http://"); - if (!image.isNull()) { - return image; - } - - image = getImageByNetworkUrl(url, "https://"); - if (!image.isNull()) { - return image; - } - - return getImageByDataUrl(url); -} - -class NetworkImageDownloadListener : public ZLNetworkRequest::Listener { -public: - NetworkImageDownloadListener(ZLTreeNode *node) : myNode(node) {} - void finished(const std::string &error) { - if (error.empty()) { - myNode->updated(); - } - } -private: - ZLTreeNode *myNode; -}; - -shared_ptr NetworkCatalogUtil::getAndDownloadImageByUrl(const std::string &url, const ZLTreeNode *node) { - shared_ptr image = getImageByUrl(url); - - if (!image.isNull()) { - shared_ptr downloadRequest = image->synchronizationData(); - if (!downloadRequest.isNull()) { - downloadRequest->setListener(new NetworkImageDownloadListener(const_cast(node))); - ZLNetworkManager::Instance().performAsync(downloadRequest); - } - } - return image; -} -- cgit v1.2.3