save work
This commit is contained in:
parent
114dbef367
commit
5238c7e417
3 changed files with 30 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "gui/guiutilities.h"
|
#include "gui/guiutilities.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
#include "miscellaneous/settings.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
#include "services/standard/definitions.h"
|
#include "services/standard/definitions.h"
|
||||||
|
@ -96,11 +97,26 @@ FormDiscoverFeeds::~FormDiscoverFeeds() {
|
||||||
qDeleteAll(m_parsers);
|
qDeleteAll(m_parsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<StandardFeed*> FormDiscoverFeeds::discoverFeedsWithParser(const FeedParser* parser, const QString& url) {
|
||||||
|
auto feeds = parser->discoverFeeds(m_serviceRoot, url);
|
||||||
|
QPixmap icon;
|
||||||
|
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
|
|
||||||
|
if (NetworkFactory::downloadIcon({{url, false}}, timeout, icon, {}, m_serviceRoot->networkProxy()) ==
|
||||||
|
QNetworkReply::NetworkError::NoError) {
|
||||||
|
for (Feed* feed : feeds) {
|
||||||
|
feed->setIcon(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return feeds;
|
||||||
|
}
|
||||||
|
|
||||||
void FormDiscoverFeeds::discoverFeeds() {
|
void FormDiscoverFeeds::discoverFeeds() {
|
||||||
QString url = m_ui.m_txtUrl->lineEdit()->text();
|
QString url = m_ui.m_txtUrl->lineEdit()->text();
|
||||||
|
|
||||||
std::function<QList<StandardFeed*>(const FeedParser*)> func = [=](const FeedParser* parser) -> QList<StandardFeed*> {
|
std::function<QList<StandardFeed*>(const FeedParser*)> func = [=](const FeedParser* parser) -> QList<StandardFeed*> {
|
||||||
return parser->discoverFeeds(m_serviceRoot, url);
|
return discoverFeedsWithParser(parser, url);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<QList<StandardFeed*>(QList<StandardFeed*>&, const QList<StandardFeed*>&)> reducer =
|
std::function<QList<StandardFeed*>(QList<StandardFeed*>&, const QList<StandardFeed*>&)> reducer =
|
||||||
|
|
|
@ -57,6 +57,8 @@ class FormDiscoverFeeds : public QDialog {
|
||||||
void importSelectedFeeds();
|
void importSelectedFeeds();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<StandardFeed*> discoverFeedsWithParser(const FeedParser* parser, const QString& url);
|
||||||
|
|
||||||
void userWantsAdvanced();
|
void userWantsAdvanced();
|
||||||
void loadDiscoveredFeeds(const QList<StandardFeed*>& feeds);
|
void loadDiscoveredFeeds(const QList<StandardFeed*>& feeds);
|
||||||
void loadCategories(const QList<Category*>& categories, RootItem* root_item);
|
void loadCategories(const QList<Category*>& categories, RootItem* root_item);
|
||||||
|
|
|
@ -24,6 +24,8 @@ SitemapParser::~SitemapParser() {}
|
||||||
QList<StandardFeed*> SitemapParser::discoverFeeds(ServiceRoot* root, const QUrl& url) const {
|
QList<StandardFeed*> SitemapParser::discoverFeeds(ServiceRoot* root, const QUrl& url) const {
|
||||||
QHash<QString, StandardFeed*> feeds;
|
QHash<QString, StandardFeed*> feeds;
|
||||||
QStringList to_process_sitemaps;
|
QStringList to_process_sitemaps;
|
||||||
|
int sitemap_index_limit = 2;
|
||||||
|
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
|
|
||||||
// 1. Process "URL/robots.txt" file.
|
// 1. Process "URL/robots.txt" file.
|
||||||
// 2. Process "URLHOST/robots.txt" file.
|
// 2. Process "URLHOST/robots.txt" file.
|
||||||
|
@ -42,7 +44,6 @@ QList<StandardFeed*> SitemapParser::discoverFeeds(ServiceRoot* root, const QUrl&
|
||||||
|
|
||||||
for (const QString& robots_url : to_process_robots) {
|
for (const QString& robots_url : to_process_robots) {
|
||||||
// Download URL.
|
// Download URL.
|
||||||
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
auto res = NetworkFactory::performNetworkOperation(robots_url,
|
auto res = NetworkFactory::performNetworkOperation(robots_url,
|
||||||
timeout,
|
timeout,
|
||||||
|
@ -92,7 +93,6 @@ QList<StandardFeed*> SitemapParser::discoverFeeds(ServiceRoot* root, const QUrl&
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download URL.
|
// Download URL.
|
||||||
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
auto res = NetworkFactory::performNetworkOperation(my_url,
|
auto res = NetworkFactory::performNetworkOperation(my_url,
|
||||||
timeout,
|
timeout,
|
||||||
|
@ -111,12 +111,16 @@ QList<StandardFeed*> SitemapParser::discoverFeeds(ServiceRoot* root, const QUrl&
|
||||||
auto guessed_feed = guessFeed(data, res.m_contentType);
|
auto guessed_feed = guessFeed(data, res.m_contentType);
|
||||||
|
|
||||||
guessed_feed.first->setSource(my_url);
|
guessed_feed.first->setSource(my_url);
|
||||||
|
guessed_feed.first->setTitle(my_url);
|
||||||
|
|
||||||
feeds.insert(my_url, guessed_feed.first);
|
feeds.insert(my_url, guessed_feed.first);
|
||||||
}
|
}
|
||||||
catch (const FeedRecognizedButFailedException& ex) {
|
catch (const FeedRecognizedButFailedException& ex) {
|
||||||
// This is index.
|
// This is index.
|
||||||
|
if (sitemap_index_limit-- > 0) {
|
||||||
to_process_sitemaps.append(ex.arbitraryData().toStringList());
|
to_process_sitemaps.append(ex.arbitraryData().toStringList());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (const ApplicationException&) {
|
catch (const ApplicationException&) {
|
||||||
qDebugNN << LOGSEC_CORE << QUOTE_W_SPACE(my_url) << "is not a direct sitemap file.";
|
qDebugNN << LOGSEC_CORE << QUOTE_W_SPACE(my_url) << "is not a direct sitemap file.";
|
||||||
}
|
}
|
||||||
|
@ -226,6 +230,10 @@ QString SitemapParser::xmlMessageTitle(const QDomElement& msg_element) const {
|
||||||
str_title = msg_element.elementsByTagNameNS(sitemapVideoNamespace(), QSL("title")).at(0).toElement().text();
|
str_title = msg_element.elementsByTagNameNS(sitemapVideoNamespace(), QSL("title")).at(0).toElement().text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (str_title.isEmpty()) {
|
||||||
|
str_title = msg_element.elementsByTagNameNS(sitemapImageNamespace(), QSL("title")).at(0).toElement().text();
|
||||||
|
}
|
||||||
|
|
||||||
return str_title;
|
return str_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue