CHTTPWebinterfaceHandler::CHTTPWebinterfaceHandler(const HTTPRequest &request) : CHTTPFileHandler(request) { // resolve the URL into a file path and a HTTP response status std::string file; int responseStatus = ResolveUrl(request.pathUrl, file); // set the file and the HTTP response status SetFile(file, responseStatus); }
void RedditModel::FetchMoreFinished(QNetworkReply* reply) { is_fetching_more_ = false; if (reply->error() != QNetworkReply::NoError) { qLog(Warning) << "Error fetching links" << reply->url(); no_more_links_ = true; return; } // Parse the JSON response QJson::Parser parser; QVariantMap data = parser.parse(reply).toMap(); if (!data.contains("data") || !data["data"].toMap().contains("children")) { qLog(Warning) << "Error parsing link response" << reply->url(); no_more_links_ = true; return; } QVariantList links = data["data"].toMap()["children"].toList(); if (links.isEmpty()) { no_more_links_ = true; return; } QList<Link> new_links; int row = links_.count(); foreach (const QVariant& link_variant, links) { QVariantMap link_data = link_variant.toMap(); if (!link_data.contains("data")) continue; link_data = link_data["data"].toMap(); Image image; image.InitFromJson(link_data); // Update the last seen name - this must be done before skipping anything // for the case that we skip all the images in this set. last_seen_name_ = image.reddit_name(); // Skip self posts if (!show_self_posts_ && link_data["is_self"].toBool()) continue; // Check if this image has been viewed before if (app_->image_backend()->FindImage(image, &image)) { if (image.is_viewed() && !show_viewed_images_) continue; } // Adjust the URL to get just the image if we can. image.set_reddit_url(ResolveUrl(image.reddit_url())); // Create a Link object new_links << Link(image); // Start fetching the thumbnail if (!image.reddit_thumbnail_url().scheme().isEmpty()) { qLog(Debug) << "Fetching thumbnail" << image.reddit_thumbnail_url(); QNetworkReply* reply = network_->get(QNetworkRequest(image.reddit_thumbnail_url())); NewClosure(reply, SIGNAL(finished()), this, SLOT(ThumbnailFinished(QNetworkReply*,int)), reply, row); }
int CHTTPWebinterfaceHandler::ResolveUrl(const std::string &url, std::string &path) { ADDON::AddonPtr dummyAddon; return ResolveUrl(url, path, dummyAddon); }