diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 2c716aa84..00238c386 100755 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -6,6 +6,8 @@ Added: ▪ Background color of notifications is now changeable. (issue #134) ▪ 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) +▪ 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: diff --git a/src/gui/discoverfeedsbutton.cpp b/src/gui/discoverfeedsbutton.cpp index e6c26b852..24f7e5331 100755 --- a/src/gui/discoverfeedsbutton.cpp +++ b/src/gui/discoverfeedsbutton.cpp @@ -19,9 +19,17 @@ #include "miscellaneous/application.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 -DiscoverFeedsButton::DiscoverFeedsButton(QWidget *parent) : QToolButton(parent) { +DiscoverFeedsButton::DiscoverFeedsButton(QWidget *parent) : QToolButton(parent), m_addresses(QStringList()) { setEnabled(false); setIcon(qApp->icons()->fromTheme(QSL("folder-feed"))); setPopupMode(QToolButton::InstantPopup); @@ -44,19 +52,34 @@ void DiscoverFeedsButton::setFeedAddresses(const QStringList &addresses) { // Initialize the menu. setMenu(new QMenu(this)); connect(menu(), SIGNAL(triggered(QAction*)), this, SLOT(linkTriggered(QAction*))); + connect(menu(), SIGNAL(aboutToShow()), this, SLOT(fillMenu())); } menu()->hide(); - - if (!addresses.isEmpty()) { - menu()->clear(); - - foreach (const QString &feed, addresses) { - menu()->addAction(feed); - } - } + m_addresses = addresses; } void DiscoverFeedsButton::linkTriggered(QAction *action) { - emit addingOfFeedRequested(action->text()); + // TODO: Obtain link and root. + QString url = action->property("url").toString(); + ServiceRoot *root = static_cast(action->property("root").value()); + + 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)); + } + } + } } diff --git a/src/gui/discoverfeedsbutton.h b/src/gui/discoverfeedsbutton.h old mode 100644 new mode 100755 index eb15cd7b1..ee738e5ff --- a/src/gui/discoverfeedsbutton.h +++ b/src/gui/discoverfeedsbutton.h @@ -36,10 +36,10 @@ class DiscoverFeedsButton : public QToolButton { private slots: // User chose any of addresses. void linkTriggered(QAction *action); + void fillMenu(); - signals: - // User requests addition of selected address. - void addingOfFeedRequested(const QString &feed_link); + private: + QStringList m_addresses; }; #endif // DISCOVERFEEDSBUTTON_H diff --git a/src/network-web/webbrowser.cpp b/src/network-web/webbrowser.cpp index 9bd5ea1a2..61ef0fb6b 100755 --- a/src/network-web/webbrowser.cpp +++ b/src/network-web/webbrowser.cpp @@ -206,30 +206,12 @@ void WebBrowser::createConnections() { // Misc connections. connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui())); - connect(m_btnDiscoverFeeds, SIGNAL(addingOfFeedRequested(QString)), this, SLOT(addFeedFromWebsite(QString))); } void WebBrowser::onIconChanged() { 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) { if (new_title.isEmpty()) { //: Webbrowser tab title when no title is available. diff --git a/src/network-web/webbrowser.h b/src/network-web/webbrowser.h index 02464e4bc..694a7ad91 100755 --- a/src/network-web/webbrowser.h +++ b/src/network-web/webbrowser.h @@ -42,7 +42,7 @@ class TabWidget; class WebBrowser : public TabContent { Q_OBJECT - + public: // Constructors and destructors. explicit WebBrowser(QWidget *parent = 0); @@ -136,10 +136,6 @@ class WebBrowser : public TabContent { void onTitleChanged(const QString &new_title); 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: // User requests opening of new tab or clicks the link // with middle mouse button diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index c4c3a0455..ecc63a6d1 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -52,6 +52,9 @@ class ServiceRoot : public RootItem { 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. // So typical list of returned actions could look like: // a) Add new feed diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index e5aeba95f..33412dd5e 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -124,6 +124,15 @@ bool StandardServiceRoot::markAsReadUnread(RootItem::ReadStatus 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 { switch (role) { case Qt::ToolTipRole: diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index bfb43b461..216a082e5 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -49,6 +49,9 @@ class StandardServiceRoot : public ServiceRoot { bool markAsReadUnread(ReadStatus status); + bool supportsFeedAddingByUrl() const; + void addFeedByUrl(const QString &url); + QVariant data(int column, int role) const; Qt::ItemFlags additionalFlags() const; diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index d6bd20f6f..ec512a2aa 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -36,6 +36,7 @@ #include #include #include +#include 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() { return true; } diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h index 1609fe21c..495a7ad8d 100755 --- a/src/services/tt-rss/ttrssserviceroot.h +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -47,6 +47,9 @@ class TtRssServiceRoot : public ServiceRoot { bool markAsReadUnread(ReadStatus status); + bool supportsFeedAddingByUrl() const; + void addFeedByUrl(const QString &url); + QVariant data(int column, int role) const; QList addItemMenu();