Skip to content

Commit

Permalink
Fixed #265.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rotter committed Feb 3, 2021
1 parent c53b4bb commit a94c016
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 273 deletions.
2 changes: 1 addition & 1 deletion resources/desktop/com.github.rssguard.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.8.4" date="2021-02-02"/>
<release version="3.8.4" date="2021-02-03"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>
Expand Down
33 changes: 25 additions & 8 deletions resources/docs/Feed-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@ RSS Guard is a modular application which supports plugins. It offers well-mainta
* [Tiny Tiny RSS](https://tt-rss.org) plugin: Adds ability to synchronize messages with TT-RSS instances, either self-hosted or via 3rd-party external service.
* [Inoreader](https://www.inoreader.com) plugin: Adds ability to synchronize messages with Inoreader. All you need to do is create free account on their website and start rocking.
* [Nextcloud News](https://apps.nextcloud.com/apps/news) plugin: Nextcloud News is a Nextcloud app which adds feed reader abilities into your Nextcloud instances.
* Google Reader API plugin: This plugin was added in RSS Guard 3.9.0 and offers two-way synchronization with services which implement Google Reader API. At this point, plugin was tested and works with Bazqux, The Old Reader and FreshRSS.
* [Google Reader API](https://rss-sync.github.io/Open-Reader-API/resources/#unofficial-google-reader-documentation) plugin: This plugin was added in RSS Guard 3.9.0 and offers two-way synchronization with services which implement Google Reader API. At this point, plugin was tested and works with Bazqux, The Old Reader and FreshRSS.
* [Gmail](https://www.google.com/gmail) plugin: Yes, you are reading it right. RSS Guard can be used as very lightweight and simple e-mail client. This plugins uses [Gmail API](https://developers.google.com/gmail/api) and offers even e-mail sending.

All plugins share almost all core RSS Guard's features, including labels, recycle bins, podcasts fetching or newspaper view. They are implemented in a very transparent way, making it easy to maintain them or add new ones.
> All plugins share almost all core RSS Guard's features, including labels, recycle bins, podcasts fetching or newspaper view. They are implemented in a very transparent way, making it easy to maintain them or add new ones.
Usually, plugins have some exclusive functionality, for example Gmail plugin allows user to send e-mail messages. This extra functionality is always accessible via plugin's context menu and also via main menu.
Usually, plugins have some exclusive functionality, for example Gmail plugin allows user to send e-mail messages or reply to existing ones. This extra functionality is always accessible via plugin's context menu and also via main menu.

<img src="images/gmail-context-menu.png" width="80%">

If there is interest in other plugins, you might write one yourself or if many people are interested then I might write it for you, even commercially if we make proper arrangements.

## Plugin API
RSS Guard offers simple `C++` API for creating new service plugins. All base API classes are in folder [`abstract`](https://github.com/martinrotter/rssguard/tree/master/src/librssguard/services/abstract). User must subclass and implement all interface classes:

| Class | Purpose |
|-------|---------|
| `ServiceEntryPoint` | Very base class which provides basic information about the plugin name, author etc. It also provides methods which are called when new account should be created and when existing accounts should be loaded from database. |
| `ServiceRoot` | This is the core "account" class which represents account node in feed's list and offers interface for all critical functionality of a plugin, including handlers which are called when starting/stoping a plugin, marking messages read/unread/starred/deleted, (de)assigning labels etc. |

API is reasonably simple to understand but relatively large. Sane default behavior is employed where it makes sense.

Perhaps the best approach to use when writing new plugin is to copy [existing](https://github.com/martinrotter/rssguard/tree/master/src/librssguard/services/greader) one and start from there.

Note that RSS Guard can support loading of plugins from external libraries (dll, so, etc.) but the functionality must be polished because so far all plugins are directly bundled into the app as no one really requested run-time loading of plugins so far.

## Features found exclusively in `standard RSS` plugin
Standard plugin in RSS Guard offers some features which are specific to it. Of course it supports all news syndication formats which are nowadays used:
* RSS 0.90, 0.91, 0.92, 1.0 (also known as *RDF*), 2.0.
Expand All @@ -30,10 +44,11 @@ OPML files can be exported/imported in simple dialog.

You just select output file (in case of OPML export), check desired feeds and hit `Export to file`.

### Websites scraping and other related advanced features
RSS Guard 3.9.0+ offers extra advanced features which were inspired by [Liferea](https://lzone.de/liferea/).
### Websites scraping and related advanced features

> **Only proceed if you consider yourself as power user and you know you are doing!**
**Only proceed if you consider yourself as power user and you know you are doing!**
RSS Guard 3.9.0+ offers extra advanced features which are inspired by [Liferea](https://lzone.de/liferea/).

You can select source type of each feed. If you select `URL`, then RSS Guard simply downloads feed file from given location.

Expand All @@ -43,13 +58,15 @@ However, if you choose `Script` option, then you cannot provide URL of your feed

Any errors in your script must be written to **error output**.

Note that you must provide full execution line to your custom script, including interpreter binary path and name and all that must be written in special format `<interpreter>#<arguments>`. The `#` character is there to separate interpreter from its arguments. Interpreter must be provided in all cases, arguments do not have to be. For example `bash.exe#` is valid execution line, as well as `bash#-C "cat feed.atom"`. Some examples of valid and tested execution lines are:
Note that you must provide full execution line to your custom script, including interpreter binary path and name and all that must be written in special format `<interpreter>#<arguments>`. The `#` character is there to separate interpreter from its arguments.

Interpreter must be provided in all cases, arguments do not have to be. For example `bash.exe#` is valid execution line, as well as `bash#-C "cat feed.atom"`. Note the difference in interpreter's binary name suffix. Some examples of valid and tested execution lines are:

| Command | Explanation |
|---------|-------------|
| `bash#-c "curl 'https://github.com/martinrotter.atom'"` | Downloads ATOM feed file with Bash and Curl. |
| `Powershell#"Invoke-WebRequest 'https://github.com/martinrotter.atom' | Select-Object -ExpandProperty Content"` | Downloads ATOM feed file with Powershell. |
| `php#tweeper.php https://twitter.com/NSACareers` | Downloads RSS feed file with [Tweeper](https://git.ao2.it/tweeper.git/). Tweeper is utility which is able to produce RSS feed from Twitter. |
| `php#tweeper.php -v 0 https://twitter.com/NSACareers` | Downloads RSS feed file with [Tweeper](https://git.ao2.it/tweeper.git/). Tweeper is utility which is able to produce RSS feed from Twitter. |

<img src="images/scrape-source.png" width="50%">

Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/7za
Submodule 7za updated 2 files
+ 7za.exe
+1 −1 License.txt
4 changes: 4 additions & 0 deletions src/librssguard/exceptions/applicationexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ ApplicationException::ApplicationException(QString message) : m_message(std::mov
QString ApplicationException::message() const {
return m_message;
}

void ApplicationException::setMessage(const QString& message) {
m_message = message;
}
3 changes: 3 additions & 0 deletions src/librssguard/exceptions/applicationexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class ApplicationException {

QString message() const;

protected:
void setMessage(const QString& message);

private:
QString m_message;
};
Expand Down
39 changes: 39 additions & 0 deletions src/librssguard/exceptions/scriptexception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// For license of this file, see <project-root-folder>/LICENSE.md.

#include "exceptions/scriptexception.h"

#include "definitions/definitions.h"

ScriptException::ScriptException(Reason reason, QString message) : ApplicationException(message), m_reason(reason) {
if (message.isEmpty()) {
setMessage(messageForReason(reason));
}
else if (reason == ScriptException::Reason::InterpreterError ||
reason == ScriptException::Reason::OtherError) {
setMessage(messageForReason(reason) + QSL(": '%1'").arg(message));
}
}

ScriptException::Reason ScriptException::reason() const {
return m_reason;
}

QString ScriptException::messageForReason(ScriptException::Reason reason) const {
switch (reason) {
case ScriptException::Reason::ExecutionLineInvalid:
return tr("script line is not well-formed");

case ScriptException::Reason::InterpreterError:
return tr("script threw an error");

case ScriptException::Reason::InterpreterNotFound:
return tr("script's interpreter was not found");

case ScriptException::Reason::InterpreterTimeout:
return tr("script execution took too long");

case ScriptException::Reason::OtherError:
default:
return tr("unknown error");
}
}
33 changes: 33 additions & 0 deletions src/librssguard/exceptions/scriptexception.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// For license of this file, see <project-root-folder>/LICENSE.md.

#ifndef SCRIPTEXCEPTION_H
#define SCRIPTEXCEPTION_H

#include "exceptions/applicationexception.h"

#include <QCoreApplication>

class ScriptException : public ApplicationException {
Q_DECLARE_TR_FUNCTIONS(ScriptException)

public:
enum class Reason {
ExecutionLineInvalid,
InterpreterNotFound,
InterpreterError,
InterpreterTimeout,
OtherError
};

explicit ScriptException(Reason reason = Reason::OtherError, QString message = QString());

Reason reason() const;

private:
QString messageForReason(Reason reason) const;

private:
Reason m_reason;
};

#endif // SCRIPTEXCEPTION_H
2 changes: 2 additions & 0 deletions src/librssguard/librssguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ HEADERS += core/feeddownloader.h \
exceptions/applicationexception.h \
exceptions/filteringexception.h \
exceptions/ioexception.h \
exceptions/scriptexception.h \
gui/baselineedit.h \
gui/basetoolbar.h \
gui/colortoolbutton.h \
Expand Down Expand Up @@ -221,6 +222,7 @@ SOURCES += core/feeddownloader.cpp \
exceptions/applicationexception.cpp \
exceptions/filteringexception.cpp \
exceptions/ioexception.cpp \
exceptions/scriptexception.cpp \
gui/baselineedit.cpp \
gui/basetoolbar.cpp \
gui/colortoolbutton.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ int FormStandardFeedDetails::addEditFeed(StandardFeed* input_feed, RootItem* par
}

void FormStandardFeedDetails::guessFeed() {
m_standardFeedDetails->guessFeed(m_standardFeedDetails->m_ui.m_txtSource->lineEdit()->text(),
m_standardFeedDetails->guessFeed(m_standardFeedDetails->sourceType(),
m_standardFeedDetails->m_ui.m_txtSource->lineEdit()->text(),
m_standardFeedDetails->m_ui.m_txtPostProcessScript->lineEdit()->text(),
m_authDetails->m_txtUsername->lineEdit()->text(),
m_authDetails->m_txtPassword->lineEdit()->text());
}

void FormStandardFeedDetails::guessIconOnly() {
m_standardFeedDetails->guessIconOnly(m_standardFeedDetails->m_ui.m_txtSource->lineEdit()->text(),
m_standardFeedDetails->guessIconOnly(m_standardFeedDetails->sourceType(),
m_standardFeedDetails->m_ui.m_txtSource->lineEdit()->text(),
m_standardFeedDetails->m_ui.m_txtPostProcessScript->lineEdit()->text(),
m_authDetails->m_txtUsername->lineEdit()->text(),
m_authDetails->m_txtPassword->lineEdit()->text());
}
Expand Down
66 changes: 38 additions & 28 deletions src/librssguard/services/standard/gui/standardfeeddetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,53 +107,63 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) {
onPostProcessScriptChanged({});
}

void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username,
void StandardFeedDetails::guessIconOnly(StandardFeed::SourceType source_type, const QString& source,
const QString& post_process_script, const QString& username,
const QString& password, const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
username,
password,
custom_proxy);

if (result.first != nullptr) {
bool result;
StandardFeed* metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
&result,
username,
password,
custom_proxy);

if (metadata != nullptr) {
// Icon or whole feed was guessed.
m_ui.m_btnIcon->setIcon(result.first->icon());
m_ui.m_btnIcon->setIcon(metadata->icon());

if (result.second == QNetworkReply::NoError) {
if (result) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Icon fetched successfully."),
tr("Icon metadata fetched."));
}
else {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Icon metadata not fetched."),
tr("Icon metadata not fetched."));
}

// Remove temporary feed object.
delete result.first;
delete metadata;
}
else {
// No feed guessed, even no icon available.
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No icon fetched."),
tr("No icon fetched."));
}
}

void StandardFeedDetails::guessFeed(const QString& url, const QString& username,
void StandardFeedDetails::guessFeed(StandardFeed::SourceType source_type, const QString& source,
const QString& post_process_script, const QString& username,
const QString& password, const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
username,
password,
custom_proxy);

if (result.first != nullptr) {
bool result;
StandardFeed* metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
&result,
username,
password,
custom_proxy);

if (metadata != nullptr) {
// Icon or whole feed was guessed.
m_ui.m_btnIcon->setIcon(result.first->icon());
m_ui.m_txtTitle->lineEdit()->setText(result.first->title());
m_ui.m_txtDescription->lineEdit()->setText(result.first->description());
m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int) result.first->type())));
int encoding_index = m_ui.m_cmbEncoding->findText(result.first->encoding(), Qt::MatchFixedString);
m_ui.m_btnIcon->setIcon(metadata->icon());
m_ui.m_txtTitle->lineEdit()->setText(metadata->title());
m_ui.m_txtDescription->lineEdit()->setText(metadata->description());
m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int) metadata->type())));
int encoding_index = m_ui.m_cmbEncoding->findText(metadata->encoding(), Qt::MatchFlag::MatchFixedString);

if (encoding_index >= 0) {
m_ui.m_cmbEncoding->setCurrentIndex(encoding_index);
Expand All @@ -162,24 +172,24 @@ void StandardFeedDetails::guessFeed(const QString& url, const QString& username,
m_ui.m_cmbEncoding->setCurrentIndex(m_ui.m_cmbEncoding->findText(DEFAULT_FEED_ENCODING, Qt::MatchFixedString));
}

if (result.second == QNetworkReply::NoError) {
if (result) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("All metadata fetched successfully."),
tr("Feed and icon metadata fetched."));
}
else {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Feed or icon metadata not fetched."),
tr("Feed or icon metadata not fetched."));
}

// Remove temporary feed object.
delete result.first;
delete metadata;
}
else {
// No feed guessed, even no icon available.
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("No metadata fetched."),
tr("No metadata fetched."));
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/librssguard/services/standard/gui/standardfeeddetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ class StandardFeedDetails : public QWidget {
explicit StandardFeedDetails(QWidget* parent = nullptr);

private slots:
void guessIconOnly(const QString& url,
void guessIconOnly(StandardFeed::SourceType source_type,
const QString& source,
const QString& post_process_script,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
void guessFeed(const QString& url,
void guessFeed(StandardFeed::SourceType source_type,
const QString& source,
const QString& post_process_script,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
Expand Down
Loading

0 comments on commit a94c016

Please sign in to comment.