Added better "add feed from website" feature accounts/plugins integration.

This commit is contained in:
Martin Rotter 2015-12-22 12:25:45 +01:00
parent d50038f6ed
commit 9f4e38f30a
10 changed files with 67 additions and 36 deletions

View File

@ -6,6 +6,8 @@ Added:
▪ Background color of notifications is now changeable. (issue #134) ▪ Background color of notifications is now changeable. (issue #134)
▪ Auto-update setting of individual Tiny Tiny RSS feeds can now be changed. ▪ Auto-update setting of individual Tiny Tiny RSS feeds can now be changed.
▪ RSS Guard is now useable as external RSS reader by common web browsers like Firefox etc. (issue #135) ▪ RSS Guard is now useable as external RSS reader by common web browsers like Firefox etc. (issue #135)
▪ Tiny Tiny RSS plugin now supports adding of new feeds.
▪ Activated accounts are now integrated into built-in web browser "add feed from website" feature.
Fixed: Fixed:

View File

@ -19,9 +19,17 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "gui/dialogs/formmain.h"
#include "gui/tabwidget.h"
#include "gui/feedmessageviewer.h"
#include "gui/feedsview.h"
#include "core/feedsmodel.h"
#include "services/abstract/serviceroot.h"
#include <QVariant>
DiscoverFeedsButton::DiscoverFeedsButton(QWidget *parent) : QToolButton(parent) { DiscoverFeedsButton::DiscoverFeedsButton(QWidget *parent) : QToolButton(parent), m_addresses(QStringList()) {
setEnabled(false); setEnabled(false);
setIcon(qApp->icons()->fromTheme(QSL("folder-feed"))); setIcon(qApp->icons()->fromTheme(QSL("folder-feed")));
setPopupMode(QToolButton::InstantPopup); setPopupMode(QToolButton::InstantPopup);
@ -44,19 +52,34 @@ void DiscoverFeedsButton::setFeedAddresses(const QStringList &addresses) {
// Initialize the menu. // Initialize the menu.
setMenu(new QMenu(this)); setMenu(new QMenu(this));
connect(menu(), SIGNAL(triggered(QAction*)), this, SLOT(linkTriggered(QAction*))); connect(menu(), SIGNAL(triggered(QAction*)), this, SLOT(linkTriggered(QAction*)));
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(fillMenu()));
} }
menu()->hide(); menu()->hide();
m_addresses = addresses;
if (!addresses.isEmpty()) {
menu()->clear();
foreach (const QString &feed, addresses) {
menu()->addAction(feed);
}
}
} }
void DiscoverFeedsButton::linkTriggered(QAction *action) { void DiscoverFeedsButton::linkTriggered(QAction *action) {
emit addingOfFeedRequested(action->text()); // TODO: Obtain link and root.
QString url = action->property("url").toString();
ServiceRoot *root = static_cast<ServiceRoot*>(action->property("root").value<void*>());
root->addFeedByUrl(url);
}
void DiscoverFeedsButton::fillMenu() {
menu()->clear();
foreach (ServiceRoot *root, qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) {
QMenu *root_menu = menu()->addMenu(root->icon(), root->title());
foreach (const QString &url, m_addresses) {
if (root->supportsFeedAddingByUrl()) {
QAction *url_action = root_menu->addAction(root->icon(), url);
url_action->setProperty("url", url);
url_action->setProperty("root", QVariant::fromValue((void*) root));
}
}
}
} }

6
src/gui/discoverfeedsbutton.h Normal file → Executable file
View File

@ -36,10 +36,10 @@ class DiscoverFeedsButton : public QToolButton {
private slots: private slots:
// User chose any of addresses. // User chose any of addresses.
void linkTriggered(QAction *action); void linkTriggered(QAction *action);
void fillMenu();
signals: private:
// User requests addition of selected address. QStringList m_addresses;
void addingOfFeedRequested(const QString &feed_link);
}; };
#endif // DISCOVERFEEDSBUTTON_H #endif // DISCOVERFEEDSBUTTON_H

View File

@ -206,30 +206,12 @@ void WebBrowser::createConnections() {
// Misc connections. // Misc connections.
connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui())); connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui()));
connect(m_btnDiscoverFeeds, SIGNAL(addingOfFeedRequested(QString)), this, SLOT(addFeedFromWebsite(QString)));
} }
void WebBrowser::onIconChanged() { void WebBrowser::onIconChanged() {
emit iconChanged(m_index, m_webView->icon()); emit iconChanged(m_index, m_webView->icon());
} }
void WebBrowser::addFeedFromWebsite(const QString &feed_link) {
qApp->clipboard()->setText(feed_link);
StandardServiceRoot *service = qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot();
if (service != NULL) {
service->addNewFeed();
}
else {
qApp->showGuiMessage(tr("Cannot add feed"),
tr("You cannot add this feed to %1 because standard RSS/ATOM account is not enabled. Enable it first.").arg(APP_NAME),
QSystemTrayIcon::Warning,
qApp->mainForm(),
true);
}
}
void WebBrowser::onTitleChanged(const QString &new_title) { void WebBrowser::onTitleChanged(const QString &new_title) {
if (new_title.isEmpty()) { if (new_title.isEmpty()) {
//: Webbrowser tab title when no title is available. //: Webbrowser tab title when no title is available.

View File

@ -136,10 +136,6 @@ class WebBrowser : public TabContent {
void onTitleChanged(const QString &new_title); void onTitleChanged(const QString &new_title);
void onIconChanged(); void onIconChanged();
// User selected any feed from website to add to reader.
// This copies feed link to clipboard and triggers "add feed" dialog.
void addFeedFromWebsite(const QString &feed_link);
signals: signals:
// User requests opening of new tab or clicks the link // User requests opening of new tab or clicks the link
// with middle mouse button // with middle mouse button

View File

@ -52,6 +52,9 @@ class ServiceRoot : public RootItem {
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
virtual bool supportsFeedAddingByUrl() const = 0;
virtual void addFeedByUrl(const QString &url) = 0;
// Returns list of specific actions for "Add new item" main window menu. // Returns list of specific actions for "Add new item" main window menu.
// So typical list of returned actions could look like: // So typical list of returned actions could look like:
// a) Add new feed // a) Add new feed

View File

@ -124,6 +124,15 @@ bool StandardServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
return ServiceRoot::markAsReadUnread(status); return ServiceRoot::markAsReadUnread(status);
} }
bool StandardServiceRoot::supportsFeedAddingByUrl() const {
return true;
}
void StandardServiceRoot::addFeedByUrl(const QString &url) {
qApp->clipboard()->setText(url);
addNewFeed();
}
QVariant StandardServiceRoot::data(int column, int role) const { QVariant StandardServiceRoot::data(int column, int role) const {
switch (role) { switch (role) {
case Qt::ToolTipRole: case Qt::ToolTipRole:

View File

@ -49,6 +49,9 @@ class StandardServiceRoot : public ServiceRoot {
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool supportsFeedAddingByUrl() const;
void addFeedByUrl(const QString &url);
QVariant data(int column, int role) const; QVariant data(int column, int role) const;
Qt::ItemFlags additionalFlags() const; Qt::ItemFlags additionalFlags() const;

View File

@ -36,6 +36,7 @@
#include <QSqlError> #include <QSqlError>
#include <QPointer> #include <QPointer>
#include <QPair> #include <QPair>
#include <QClipboard>
TtRssServiceRoot::TtRssServiceRoot(RootItem *parent) TtRssServiceRoot::TtRssServiceRoot(RootItem *parent)
@ -108,6 +109,15 @@ bool TtRssServiceRoot::markAsReadUnread(RootItem::ReadStatus status) {
} }
} }
bool TtRssServiceRoot::supportsFeedAddingByUrl() const {
return true;
}
void TtRssServiceRoot::addFeedByUrl(const QString &url) {
qApp->clipboard()->setText(url);
addNewFeed();
}
bool TtRssServiceRoot::canBeEdited() { bool TtRssServiceRoot::canBeEdited() {
return true; return true;
} }

View File

@ -47,6 +47,9 @@ class TtRssServiceRoot : public ServiceRoot {
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool supportsFeedAddingByUrl() const;
void addFeedByUrl(const QString &url);
QVariant data(int column, int role) const; QVariant data(int column, int role) const;
QList<QAction*> addItemMenu(); QList<QAction*> addItemMenu();