2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-02-08 12:10:12 +01:00
|
|
|
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-03 15:24:23 +01:00
|
|
|
#include "rssnotification.h"
|
|
|
|
#include "ui_rssnotification.h"
|
|
|
|
#include "mainapplication.h"
|
2012-06-28 17:16:45 +02:00
|
|
|
#include "browsinglibrary.h"
|
2011-09-30 21:44:18 +02:00
|
|
|
#include "iconprovider.h"
|
2012-06-28 17:16:45 +02:00
|
|
|
#include "processinfo.h"
|
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "webview.h"
|
2013-02-13 21:48:06 +01:00
|
|
|
#include "qztools.h"
|
2011-03-03 15:24:23 +01:00
|
|
|
|
2012-06-28 17:16:45 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
RSSNotification::RSSNotification(const QString &title, const QUrl &url, WebView* parent)
|
2011-12-12 21:14:43 +01:00
|
|
|
: AnimatedWidget(AnimatedWidget::Down, 300, parent)
|
|
|
|
, ui(new Ui::RSSNotification)
|
2012-06-28 17:16:45 +02:00
|
|
|
, m_title(title)
|
|
|
|
, m_url(url)
|
|
|
|
, m_view(parent)
|
2011-03-03 15:24:23 +01:00
|
|
|
{
|
2013-02-14 23:23:28 +01:00
|
|
|
setAutoFillBackground(true);
|
2011-03-03 15:24:23 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2012-06-28 17:16:45 +02:00
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
ui->setupUi(widget());
|
2012-04-22 20:51:28 +02:00
|
|
|
ui->closeButton->setIcon(qIconProvider->standardIcon(QStyle::SP_DialogCloseButton));
|
2012-06-28 17:16:45 +02:00
|
|
|
ui->label->setText(tr("RSS feed <b>\"%1\"</b>").arg(title));
|
2011-03-03 15:24:23 +01:00
|
|
|
|
2013-02-15 12:29:13 +01:00
|
|
|
RssApp bloglines;
|
|
|
|
bloglines.type = WebApplication;
|
|
|
|
bloglines.title = "Bloglines";
|
|
|
|
bloglines.icon = QIcon(":/icons/sites/bloglines.png");
|
|
|
|
bloglines.address = "http://www.bloglines.com/sub?url=";
|
|
|
|
|
|
|
|
RssApp myaol;
|
|
|
|
myaol.type = WebApplication;
|
|
|
|
myaol.title = "My AOL";
|
|
|
|
myaol.icon = QIcon(":/icons/sites/aol.png");
|
|
|
|
myaol.address = "http://feeds.my.aol.com/add.jsp?url=";
|
|
|
|
|
|
|
|
RssApp netvibes;
|
|
|
|
netvibes.type = WebApplication;
|
|
|
|
netvibes.title = "Netvibes";
|
|
|
|
netvibes.icon = QIcon(":/icons/sites/netvibes.png");
|
|
|
|
netvibes.address = "http://www.netvibes.com/subscribe.php?url=";
|
|
|
|
|
|
|
|
RssApp yahoo;
|
|
|
|
yahoo.type = WebApplication;
|
|
|
|
yahoo.title = "Yahoo!";
|
|
|
|
yahoo.icon = QIcon(":/icons/sites/yahoo.png");
|
|
|
|
yahoo.address = "http://add.my.yahoo.com/rss?url=";
|
|
|
|
|
2013-06-22 17:33:59 +02:00
|
|
|
m_rssApps << bloglines << myaol << netvibes << yahoo;
|
2012-06-28 17:16:45 +02:00
|
|
|
|
2012-12-22 12:47:45 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2013-02-13 21:48:06 +01:00
|
|
|
const QString &akregatorBin = QzTools::resolveFromPath("akregator");
|
|
|
|
const QString &lifereaBin = QzTools::resolveFromPath("liferea");
|
|
|
|
const QString &lifereaAddFeedBin = QzTools::resolveFromPath("liferea-add-feed");
|
|
|
|
|
|
|
|
if (!akregatorBin.isEmpty()) {
|
2013-02-15 12:29:13 +01:00
|
|
|
RssApp akregator;
|
|
|
|
akregator.type = DesktopApplication;
|
|
|
|
akregator.title = "Akregator";
|
|
|
|
akregator.icon = QIcon(":/icons/sites/akregator.png");
|
|
|
|
akregator.executable = akregatorBin;
|
|
|
|
akregator.arguments = "-a";
|
|
|
|
|
|
|
|
m_rssApps << akregator;
|
2012-06-28 17:16:45 +02:00
|
|
|
}
|
|
|
|
|
2013-02-13 21:48:06 +01:00
|
|
|
if (!lifereaBin.isEmpty() && !lifereaAddFeedBin.isEmpty()) {
|
2013-02-15 12:29:13 +01:00
|
|
|
RssApp liferea;
|
|
|
|
liferea.type = DesktopApplication;
|
|
|
|
liferea.title = "Liferea";
|
|
|
|
liferea.icon = QIcon(":/icons/sites/liferea.png");
|
|
|
|
liferea.executable = lifereaAddFeedBin;
|
|
|
|
|
|
|
|
m_rssApps << liferea;
|
2012-06-28 17:16:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const RssApp &app, m_rssApps) {
|
2012-06-28 17:16:45 +02:00
|
|
|
ui->comboBox->addItem(app.icon, app.title, QVariant(app.type));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->comboBox->addItem(QIcon(":/icons/qupzilla.png"), tr("Internal Reader"), QVariant(Internal));
|
|
|
|
ui->comboBox->addItem(tr("Other..."), QVariant(Other));
|
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("RSS");
|
|
|
|
ui->comboBox->setCurrentIndex(settings.value("LastAddOptionIndex", ui->comboBox->count() - 2).toInt());
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
connect(ui->add, SIGNAL(clicked()), this, SLOT(addRss()));
|
2011-03-03 15:24:23 +01:00
|
|
|
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide()));
|
2012-06-28 17:16:45 +02:00
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
startAnimation();
|
2011-03-03 15:24:23 +01:00
|
|
|
}
|
|
|
|
|
2012-06-28 17:16:45 +02:00
|
|
|
void RSSNotification::hide()
|
|
|
|
{
|
|
|
|
m_view->setFocus();
|
|
|
|
AnimatedWidget::hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RSSNotification::addRss()
|
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
int index = ui->comboBox->currentIndex();
|
|
|
|
|
|
|
|
switch (ui->comboBox->itemData(index).toInt()) {
|
|
|
|
case WebApplication: {
|
2013-02-08 12:10:12 +01:00
|
|
|
const RssApp app = m_rssApps.at(index);
|
2012-12-20 14:45:35 +01:00
|
|
|
const QUrl &url = QUrl::fromEncoded(QString(app.address + QUrl::toPercentEncoding(m_url.toString())).toLatin1());
|
2012-06-28 17:16:45 +02:00
|
|
|
|
|
|
|
m_view->openUrlInNewTab(url, Qz::NT_SelectedTab);
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DesktopApplication: {
|
2013-02-08 12:10:12 +01:00
|
|
|
const RssApp app = m_rssApps.at(index);
|
2013-02-15 12:29:13 +01:00
|
|
|
if (app.title == QLatin1String("Liferea")) {
|
2012-06-28 17:16:45 +02:00
|
|
|
if (!ProcessInfo("liferea").isRunning()) {
|
|
|
|
QMessageBox::warning(this, tr("Liferea not running"), tr("Liferea must be running in order to add new feed."));
|
|
|
|
success = false;
|
2013-02-15 12:29:13 +01:00
|
|
|
break;
|
2012-06-28 17:16:45 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-15 12:29:13 +01:00
|
|
|
const QString &arguments = QString("%1 %2").arg(app.arguments, QString::fromUtf8(m_url.toEncoded()));
|
|
|
|
success = QzTools::startExternalProcess(app.executable, arguments);
|
2012-06-28 17:16:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Other: {
|
|
|
|
QApplication::clipboard()->setText(m_url.toEncoded());
|
|
|
|
const QString &message = tr("To add this RSS feed into other application, please use this information:<br/><br/>"
|
|
|
|
"<b>Title: </b>%1<br/><b>Url: </b>%2<br/><br/>"
|
|
|
|
"Url address of this feed has been copied into your clipboard.").arg(m_title, m_url.toString());
|
|
|
|
QMessageBox::information(0, tr("Add feed into other application"), message);
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Internal:
|
|
|
|
success = mApp->rssManager()->addRssFeed(m_url, m_title, m_view->icon());
|
|
|
|
if (success) {
|
|
|
|
mApp->browsingLibrary()->showRSS(mApp->mainWindows().at(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("RSS");
|
|
|
|
settings.setValue("LastAddOptionIndex", index);
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-03 15:24:23 +01:00
|
|
|
RSSNotification::~RSSNotification()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|