Skip to content

Commit

Permalink
update languages, fix recent PR compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Sep 23, 2024
1 parent edad7fa commit c83ab23
Show file tree
Hide file tree
Showing 9 changed files with 712 additions and 211 deletions.
685 changes: 582 additions & 103 deletions localization/rssguard_en.ts

Large diffs are not rendered by default.

155 changes: 84 additions & 71 deletions src/librssguard-standard/src/standardfeedsimportexportmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,88 +195,54 @@ 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);

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 (!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>();
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);

if (old_icon.isNull()) {
new_feed->setIcon(qApp->icons()->fromTheme(QSL("application-rss+xml")));
}
else {
new_feed->setIcon(old_icon);
}
}
}
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);
new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script);

if (!feed_icon.isNull()) {
new_feed->setIcon(feed_icon);
}
if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString();

if (feed_type == QL1S("RSS1")) {
new_feed->setType(StandardFeed::Type::Rdf);
if (!old_title.simplified().isEmpty()) {
new_feed->setTitle(old_title);
}
}
else if (feed_type == QL1S("JSON")) {
new_feed->setType(StandardFeed::Type::Json);

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);
}
}
else if (feed_type == QL1S("ATOM")) {
new_feed->setType(StandardFeed::Type::Atom10);
}
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->setType(StandardFeed::Type::Rss2X);
throw;
}
}
}
else {
new_feed = new StandardFeed();
fillFeedFromFeedLookupData(new_feed, feed_lookup);
}

QMutexLocker mtx(&m_mtxLookup);
feed_lookup.parent->appendChild(new_feed);
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/librssguard-standard/src/standardfeedsimportexportmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/librssguard/core/feeddownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/librssguard/miscellaneous/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/librssguard/miscellaneous/feedreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
53 changes: 29 additions & 24 deletions src/librssguard/miscellaneous/thread.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
10 changes: 6 additions & 4 deletions src/librssguard/miscellaneous/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c83ab23

Please sign in to comment.