update languages, fix recent PR compilation error

This commit is contained in:
Martin Rotter 2024-09-23 12:40:06 +02:00
parent edad7fad32
commit c83ab230f9
9 changed files with 713 additions and 212 deletions

File diff suppressed because it is too large Load Diff

View File

@ -195,87 +195,53 @@ bool FeedsImportExportModel::produceFeed(const FeedLookup& feed_lookup) {
? feed_lookup.custom_data[QSL("postProcessScript")].toString() ? feed_lookup.custom_data[QSL("postProcessScript")].toString()
: feed_lookup.post_process_script; : feed_lookup.post_process_script;
new_feed = StandardFeed::guessFeed(source_type, try {
feed_lookup.url, new_feed = StandardFeed::guessFeed(source_type,
pp_script, feed_lookup.url,
NetworkFactory::NetworkAuthentication::NoAuthentication, pp_script,
!feed_lookup.do_not_fetch_icons, NetworkFactory::NetworkAuthentication::NoAuthentication,
{}, !feed_lookup.do_not_fetch_icons,
{}, {},
feed_lookup.custom_proxy); {},
feed_lookup.custom_proxy);
new_feed->setSourceType(source_type); new_feed->setSourceType(source_type);
new_feed->setSource(feed_lookup.url); new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script); new_feed->setPostProcessScript(pp_script);
if (feed_lookup.do_not_fetch_titles) { if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString(); QString old_title = feed_lookup.custom_data[QSL("title")].toString();
if (!old_title.simplified().isEmpty()) { if (!old_title.simplified().isEmpty()) {
new_feed->setTitle(old_title); new_feed->setTitle(old_title);
}
}
if (feed_lookup.do_not_fetch_icons) {
QIcon old_icon = feed_lookup.custom_data[QSL("icon")].value<QIcon>();
if (old_icon.isNull()) {
new_feed->setIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
}
else {
new_feed->setIcon(old_icon);
}
} }
} }
catch (...) {
if (feed_lookup.do_not_fetch_icons) { if (feed_lookup.add_errored_feeds) {
QIcon old_icon = feed_lookup.custom_data[QSL("icon")].value<QIcon>(); // Feed guessing failed, add like regular feed anyway.
new_feed = new StandardFeed();
if (old_icon.isNull()) { fillFeedFromFeedLookupData(new_feed, feed_lookup);
new_feed->setIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
} }
else { else {
new_feed->setIcon(old_icon); throw;
} }
} }
} }
else { else {
new_feed = new StandardFeed(); new_feed = new StandardFeed();
fillFeedFromFeedLookupData(new_feed, feed_lookup);
if (feed_lookup.custom_data.isEmpty()) {
// We assume these are "best-guess" defaults.
new_feed->setSourceType(StandardFeed::SourceType::Url);
new_feed->setType(StandardFeed::Type::Rss2X);
new_feed->setSource(feed_lookup.url);
new_feed->setTitle(feed_lookup.url);
new_feed->setIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
new_feed->setEncoding(QSL(DEFAULT_FEED_ENCODING));
new_feed->setPostProcessScript(feed_lookup.post_process_script);
}
else {
QString feed_title = feed_lookup.custom_data[QSL("title")].toString();
QString feed_encoding = feed_lookup.custom_data.value(QSL("encoding"), QSL(DEFAULT_FEED_ENCODING)).toString();
QString feed_type = feed_lookup.custom_data.value(QSL("type"), QSL(DEFAULT_FEED_TYPE)).toString().toUpper();
QString feed_description = feed_lookup.custom_data[QSL("description")].toString();
QIcon feed_icon = feed_lookup.custom_data[QSL("icon")].value<QIcon>();
StandardFeed::SourceType source_type =
feed_lookup.custom_data[QSL("sourceType")].value<StandardFeed::SourceType>();
QString post_process = feed_lookup.custom_data[QSL("postProcessScript")].toString();
new_feed->setTitle(feed_title);
new_feed->setDescription(feed_description);
new_feed->setEncoding(feed_encoding);
new_feed->setSource(feed_lookup.url);
new_feed->setSourceType(source_type);
new_feed->setPostProcessScript(feed_lookup.post_process_script.isEmpty() ? post_process
: feed_lookup.post_process_script);
if (!feed_icon.isNull()) {
new_feed->setIcon(feed_icon);
}
if (feed_type == QL1S("RSS1")) {
new_feed->setType(StandardFeed::Type::Rdf);
}
else if (feed_type == QL1S("JSON")) {
new_feed->setType(StandardFeed::Type::Json);
}
else if (feed_type == QL1S("ATOM")) {
new_feed->setType(StandardFeed::Type::Atom10);
}
else {
new_feed->setType(StandardFeed::Type::Rss2X);
}
}
} }
QMutexLocker mtx(&m_mtxLookup); QMutexLocker mtx(&m_mtxLookup);
@ -295,6 +261,53 @@ bool FeedsImportExportModel::produceFeed(const FeedLookup& feed_lookup) {
} }
} }
void FeedsImportExportModel::fillFeedFromFeedLookupData(StandardFeed* feed, const FeedLookup& feed_lookup) {
if (feed_lookup.custom_data.isEmpty()) {
// We assume these are "best-guess" defaults.
feed->setSourceType(StandardFeed::SourceType::Url);
feed->setType(StandardFeed::Type::Rss2X);
feed->setSource(feed_lookup.url);
feed->setTitle(feed_lookup.url);
feed->setIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
feed->setEncoding(QSL(DEFAULT_FEED_ENCODING));
feed->setPostProcessScript(feed_lookup.post_process_script);
}
else {
QString feed_title = feed_lookup.custom_data[QSL("title")].toString();
QString feed_encoding = feed_lookup.custom_data.value(QSL("encoding"), QSL(DEFAULT_FEED_ENCODING)).toString();
QString feed_type = feed_lookup.custom_data.value(QSL("type"), QSL(DEFAULT_FEED_TYPE)).toString().toUpper();
QString feed_description = feed_lookup.custom_data[QSL("description")].toString();
QIcon feed_icon = feed_lookup.custom_data[QSL("icon")].value<QIcon>();
StandardFeed::SourceType source_type = feed_lookup.custom_data[QSL("sourceType")].value<StandardFeed::SourceType>();
QString post_process = feed_lookup.custom_data[QSL("postProcessScript")].toString();
feed->setTitle(feed_title);
feed->setDescription(feed_description);
feed->setEncoding(feed_encoding);
feed->setSource(feed_lookup.url);
feed->setSourceType(source_type);
feed->setPostProcessScript(feed_lookup.post_process_script.isEmpty() ? post_process
: feed_lookup.post_process_script);
if (!feed_icon.isNull()) {
feed->setIcon(feed_icon);
}
if (feed_type == QL1S("RSS1")) {
feed->setType(StandardFeed::Type::Rdf);
}
else if (feed_type == QL1S("JSON")) {
feed->setType(StandardFeed::Type::Json);
}
else if (feed_type == QL1S("ATOM")) {
feed->setType(StandardFeed::Type::Atom10);
}
else {
feed->setType(StandardFeed::Type::Rss2X);
}
}
}
void FeedsImportExportModel::importAsOPML20(const QByteArray& data, void FeedsImportExportModel::importAsOPML20(const QByteArray& data,
bool fetch_metadata_online, bool fetch_metadata_online,
bool do_not_fetch_titles, bool do_not_fetch_titles,

View File

@ -19,6 +19,7 @@ struct FeedLookup {
bool fetch_metadata_online; bool fetch_metadata_online;
bool do_not_fetch_titles; bool do_not_fetch_titles;
bool do_not_fetch_icons; bool do_not_fetch_icons;
bool add_errored_feeds;
QNetworkProxy custom_proxy; QNetworkProxy custom_proxy;
QString post_process_script; QString post_process_script;
}; };
@ -62,6 +63,8 @@ class FeedsImportExportModel : public AccountCheckSortedModel {
private: private:
bool produceFeed(const FeedLookup& feed_lookup); bool produceFeed(const FeedLookup& feed_lookup);
void fillFeedFromFeedLookupData(StandardFeed* feed, const FeedLookup& feed_lookup);
private: private:
StandardServiceRoot* m_account; StandardServiceRoot* m_account;
QMutex m_mtxLookup; QMutex m_mtxLookup;

View File

@ -155,9 +155,9 @@ void FeedDownloader::updateFeeds(const QList<Feed*>& feeds) {
std::function<FeedUpdateResult(const FeedUpdateRequest&)> func = std::function<FeedUpdateResult(const FeedUpdateRequest&)> func =
[=](const FeedUpdateRequest& fd) -> FeedUpdateResult { [=](const FeedUpdateRequest& fd) -> FeedUpdateResult {
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
setThreadPriority(Priority::LOWEST); setThreadPriority(Priority::Lowest);
#endif #endif
return updateThreadedFeed(fd); return updateThreadedFeed(fd);
}; };
@ -437,8 +437,7 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
} }
void FeedDownloader::finalizeUpdate() { void FeedDownloader::finalizeUpdate() {
qDebugNN << LOGSEC_FEEDDOWNLOADER << "Finished feed updates in thread" qDebugNN << LOGSEC_FEEDDOWNLOADER << "Finished feed updates in thread" << QUOTE_W_SPACE_DOT(getThreadID());
<< QUOTE_W_SPACE_DOT(getThreadID());
m_feeds.clear(); m_feeds.clear();

View File

@ -42,7 +42,7 @@ TextBrowserViewer::TextBrowserViewer(QWidget* parent)
setDocument(m_document.data()); setDocument(m_document.data());
m_resourceDownloader->moveToThread(m_resourceDownloaderThread); m_resourceDownloader->moveToThread(m_resourceDownloaderThread);
m_resourceDownloaderThread->start(QThread::LowPriority); m_resourceDownloaderThread->start(QThread::Priority::LowPriority);
connect(this, &TextBrowserViewer::reloadDocument, this, [this]() { connect(this, &TextBrowserViewer::reloadDocument, this, [this]() {
const auto scr = verticalScrollBarPosition(); const auto scr = verticalScrollBarPosition();

View File

@ -1157,10 +1157,10 @@ void Application::setupWorkHorsePool() {
m_workHorsePool->setMaxThreadCount((std::min)(MAX_THREADPOOL_THREADS, 2 * ideal_th_count)); m_workHorsePool->setMaxThreadCount((std::min)(MAX_THREADPOOL_THREADS, 2 * ideal_th_count));
} }
#if QT_VERSION_MAJOR == 6 #if QT_VERSION >= 0x060200 // Qt >= 6.2.0
// Avoid competing with interactive processes/threads by running the // Avoid competing with interactive processes/threads by running the
// worker pool at a very low priority // worker pool at a very low priority
m_workHorsePool->setThreadPriority(QThread::LowestPriority); m_workHorsePool->setThreadPriority(QThread::Priority::LowestPriority);
#endif #endif
// NOTE: Do not expire threads so that their IDs are not reused. // NOTE: Do not expire threads so that their IDs are not reused.

View File

@ -128,7 +128,7 @@ void FeedReader::initializeFeedDownloader() {
connect(m_feedDownloader, &FeedDownloader::updateStarted, this, &FeedReader::feedUpdatesStarted); connect(m_feedDownloader, &FeedDownloader::updateStarted, this, &FeedReader::feedUpdatesStarted);
connect(m_feedDownloader, &FeedDownloader::updateFinished, qApp->feedUpdateLock(), &Mutex::unlock); connect(m_feedDownloader, &FeedDownloader::updateFinished, qApp->feedUpdateLock(), &Mutex::unlock);
m_feedDownloaderThread->start(QThread::LowPriority); m_feedDownloaderThread->start(QThread::Priority::LowPriority);
} }
} }

View File

@ -1,8 +1,9 @@
// For license of this file, see <project-root-folder>/LICENSE.md. // For license of this file, see <project-root-folder>/LICENSE.md.
#include "definitions/definitions.h"
#include "miscellaneous/thread.h" #include "miscellaneous/thread.h"
#include "definitions/definitions.h"
#include <QThread> #include <QThread>
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
@ -11,57 +12,61 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
// Returns the thread ID of the caller // Returns the thread ID of the caller.
qlonglong getThreadID() { qlonglong getThreadID() {
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
return qlonglong(gettid()); return qlonglong(gettid());
#else #else
return qlonglong(QThread::currentThreadId()); return qlonglong(QThread::currentThreadId());
#endif #endif
} }
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
// On Linux QThread priorities do nothing with the default scheduler SCHED_OTHER // On Linux QThread priorities do nothing with the default scheduler SCHED_OTHER.
// Set the nice value manually in this case until Qt supports nice values //
// Set the nice value manually in this case until Qt supports nice values.
void setThreadPriority(Priority prio) { void setThreadPriority(Priority prio) {
int current_policy = sched_getscheduler(0); int current_policy = sched_getscheduler(0);
if (current_policy != -1) { if (current_policy != -1) {
// If the current scheduling policy is neither of these the QThread priority should be working // If the current scheduling policy is neither of these the QThread priority should be working.
if (current_policy != SCHED_BATCH && current_policy != SCHED_OTHER) { if (current_policy != SCHED_BATCH && current_policy != SCHED_OTHER) {
return; return;
} }
// Set the scheduler to SCHED_BATCH if needed, indicating that this process is non-interactive // Set the scheduler to SCHED_BATCH if needed, indicating that this process is non-interactive.
if (current_policy == SCHED_OTHER) { if (current_policy == SCHED_OTHER) {
struct sched_param p = {0}; struct sched_param p = {0};
if (sched_setscheduler(0, SCHED_BATCH, &p) != 0) { if (sched_setscheduler(0, SCHED_BATCH, &p) != 0) {
qDebugNN << "Setting the scheduler to SCHED_BATCH for thread" qDebugNN << "Setting the scheduler to SCHED_BATCH for thread" << QUOTE_W_SPACE(getThreadID())
<< QUOTE_W_SPACE(getThreadID())
<< "failed with error" << QUOTE_W_SPACE_DOT(errno); << "failed with error" << QUOTE_W_SPACE_DOT(errno);
// We can still try to set the nice value // We can still try to set the nice value.
} }
} }
errno = 0; // Clear errno since -1 is a legitimate return value errno = 0; // Clear errno since -1 is a legitimate return value.
int current_priority = getpriority(PRIO_PROCESS, 0); int current_priority = getpriority(PRIO_PROCESS, 0);
if (errno != 0) { if (errno != 0) {
qDebugNN << "Getting the priority for thread" qDebugNN << "Getting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< QUOTE_W_SPACE(getThreadID()) << QUOTE_W_SPACE_DOT(errno);
<< "failed with error" << QUOTE_W_SPACE_DOT(errno); }
} else { else {
if (current_priority != prio) { if (current_priority != prio) {
setpriority(PRIO_PROCESS, 0, prio); setpriority(PRIO_PROCESS, 0, prio);
if (errno != 0) { if (errno != 0) {
qDebugNN << "Setting the priority for thread" qDebugNN << "Setting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< QUOTE_W_SPACE(getThreadID()) << QUOTE_W_SPACE_DOT(errno);
<< "failed with error" << QUOTE_W_SPACE_DOT(errno);
} }
} }
} }
} else { }
qDebugNN << "Getting the priority for thread" else {
<< QUOTE_W_SPACE(getThreadID()) qDebugNN << "Getting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< "failed with error" << QUOTE_W_SPACE_DOT(errno); << QUOTE_W_SPACE_DOT(errno);
} }
} }
#endif #endif

View File

@ -3,14 +3,16 @@
#ifndef THREAD_H #ifndef THREAD_H
#define THREAD_H #define THREAD_H
#include <QtGlobal>
qlonglong getThreadID(); qlonglong getThreadID();
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
// Values corresponding to nice values // Values corresponding to nice values.
enum Priority { enum Priority {
LOWEST = 19, Lowest = 19,
LOW = 10, Low = 10,
NORMAL = 0 Normal = 0
}; };
void setThreadPriority(Priority); void setThreadPriority(Priority);