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.post_process_script;
new_feed = StandardFeed::guessFeed(source_type,
feed_lookup.url,
pp_script,
NetworkFactory::NetworkAuthentication::NoAuthentication,
!feed_lookup.do_not_fetch_icons,
{},
{},
feed_lookup.custom_proxy);
try {
new_feed = StandardFeed::guessFeed(source_type,
feed_lookup.url,
pp_script,
NetworkFactory::NetworkAuthentication::NoAuthentication,
!feed_lookup.do_not_fetch_icons,
{},
{},
feed_lookup.custom_proxy);
new_feed->setSourceType(source_type);
new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script);
new_feed->setSourceType(source_type);
new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script);
if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString();
if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString();
if (!old_title.simplified().isEmpty()) {
new_feed->setTitle(old_title);
if (!old_title.simplified().isEmpty()) {
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);
}
}
}
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")));
catch (...) {
if (feed_lookup.add_errored_feeds) {
// Feed guessing failed, add like regular feed anyway.
new_feed = new StandardFeed();
fillFeedFromFeedLookupData(new_feed, feed_lookup);
}
else {
new_feed->setIcon(old_icon);
throw;
}
}
}
else {
new_feed = new StandardFeed();
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);
}
}
fillFeedFromFeedLookupData(new_feed, feed_lookup);
}
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,
bool fetch_metadata_online,
bool do_not_fetch_titles,

View File

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

View File

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

View File

@ -42,7 +42,7 @@ TextBrowserViewer::TextBrowserViewer(QWidget* parent)
setDocument(m_document.data());
m_resourceDownloader->moveToThread(m_resourceDownloaderThread);
m_resourceDownloaderThread->start(QThread::LowPriority);
m_resourceDownloaderThread->start(QThread::Priority::LowPriority);
connect(this, &TextBrowserViewer::reloadDocument, this, [this]() {
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));
}
#if QT_VERSION_MAJOR == 6
#if QT_VERSION >= 0x060200 // Qt >= 6.2.0
// Avoid competing with interactive processes/threads by running the
// worker pool at a very low priority
m_workHorsePool->setThreadPriority(QThread::LowestPriority);
m_workHorsePool->setThreadPriority(QThread::Priority::LowestPriority);
#endif
// 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::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.
#include "definitions/definitions.h"
#include "miscellaneous/thread.h"
#include "definitions/definitions.h"
#include <QThread>
#if defined(Q_OS_LINUX)
@ -11,57 +12,61 @@
#include <unistd.h>
#endif
// Returns the thread ID of the caller
// Returns the thread ID of the caller.
qlonglong getThreadID() {
#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX)
return qlonglong(gettid());
#else
#else
return qlonglong(QThread::currentThreadId());
#endif
#endif
}
#if defined(Q_OS_LINUX)
// 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
// 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.
void setThreadPriority(Priority prio) {
int current_policy = sched_getscheduler(0);
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) {
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) {
struct sched_param p = {0};
if (sched_setscheduler(0, SCHED_BATCH, &p) != 0) {
qDebugNN << "Setting the scheduler to SCHED_BATCH for thread"
<< QUOTE_W_SPACE(getThreadID())
qDebugNN << "Setting the scheduler to SCHED_BATCH for thread" << QUOTE_W_SPACE(getThreadID())
<< "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);
if (errno != 0) {
qDebugNN << "Getting the priority for thread"
<< QUOTE_W_SPACE(getThreadID())
<< "failed with error" << QUOTE_W_SPACE_DOT(errno);
} else {
qDebugNN << "Getting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< QUOTE_W_SPACE_DOT(errno);
}
else {
if (current_priority != prio) {
setpriority(PRIO_PROCESS, 0, prio);
if (errno != 0) {
qDebugNN << "Setting the priority for thread"
<< QUOTE_W_SPACE(getThreadID())
<< "failed with error" << QUOTE_W_SPACE_DOT(errno);
qDebugNN << "Setting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< QUOTE_W_SPACE_DOT(errno);
}
}
}
} else {
qDebugNN << "Getting the priority for thread"
<< QUOTE_W_SPACE(getThreadID())
<< "failed with error" << QUOTE_W_SPACE_DOT(errno);
}
else {
qDebugNN << "Getting the priority for thread" << QUOTE_W_SPACE(getThreadID()) << "failed with error"
<< QUOTE_W_SPACE_DOT(errno);
}
}
#endif

View File

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