2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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 14:25:02 +01:00
|
|
|
#include "rsswidget.h"
|
|
|
|
#include "ui_rsswidget.h"
|
2011-03-03 15:24:23 +01:00
|
|
|
#include "mainapplication.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-03 15:24:23 +01:00
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "rssnotification.h"
|
2011-03-03 14:25:02 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QToolTip>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QWebFrame>
|
|
|
|
|
2011-10-30 17:20:22 +01:00
|
|
|
RSSWidget::RSSWidget(WebView* view, QWidget* parent)
|
|
|
|
: QMenu(parent)
|
|
|
|
, ui(new Ui::RSSWidget)
|
|
|
|
, m_view(view)
|
2011-03-03 14:25:02 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-10-30 17:20:22 +01:00
|
|
|
|
2012-01-07 10:26:52 +01:00
|
|
|
#ifndef KDE
|
2011-12-27 17:49:51 +01:00
|
|
|
// Use light color for QLabels even with Ubuntu Ambiance theme
|
|
|
|
QPalette pal = palette();
|
|
|
|
pal.setColor(QPalette::WindowText, QToolTip::palette().color(QPalette::ToolTipText));
|
|
|
|
ui->label_2->setPalette(pal);
|
2012-01-07 10:26:52 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QWebFrame* frame = m_view->page()->mainFrame();
|
|
|
|
QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]");
|
2011-12-27 17:49:51 +01:00
|
|
|
|
2011-10-30 17:20:22 +01:00
|
|
|
for (int i = 0; i < links.count(); i++) {
|
|
|
|
QWebElement element = links.at(i);
|
|
|
|
QString title = element.attribute("title");
|
|
|
|
QString href = element.attribute("href");
|
2011-12-24 13:43:26 +01:00
|
|
|
if (href.isEmpty()) {
|
2011-10-30 17:20:22 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-30 17:20:22 +01:00
|
|
|
|
2011-12-24 13:43:26 +01:00
|
|
|
if (title.isEmpty()) {
|
|
|
|
title = tr("Untitled feed");
|
|
|
|
}
|
|
|
|
|
2011-03-03 15:24:23 +01:00
|
|
|
QPushButton* button = new QPushButton(this);
|
|
|
|
button->setText(tr("Add"));
|
2011-10-30 17:20:22 +01:00
|
|
|
button->setWhatsThis(href);
|
|
|
|
button->setToolTip(title);
|
2011-03-03 15:24:23 +01:00
|
|
|
QLabel* label = new QLabel(this);
|
2012-01-07 10:26:52 +01:00
|
|
|
#ifndef KDE
|
2011-12-27 17:49:51 +01:00
|
|
|
label->setPalette(pal);
|
2012-01-07 10:26:52 +01:00
|
|
|
#endif
|
2011-10-30 17:20:22 +01:00
|
|
|
label->setText(title);
|
2011-03-03 15:24:23 +01:00
|
|
|
ui->gridLayout->addWidget(label, i, 0);
|
|
|
|
ui->gridLayout->addWidget(button, i, 1);
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(addRss()));
|
|
|
|
}
|
2011-03-03 14:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RSSWidget::showAt(QWidget* _parent)
|
|
|
|
{
|
|
|
|
QPoint p = _parent->mapToGlobal(QPoint(0, 0));
|
2011-11-06 17:01:23 +01:00
|
|
|
move((p.x() + _parent->width() - width()), p.y() + _parent->height());
|
2011-03-03 14:25:02 +01:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2011-03-03 15:24:23 +01:00
|
|
|
void RSSWidget::addRss()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_view) {
|
2011-03-03 15:24:23 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QPushButton* button = qobject_cast<QPushButton*>(sender())) {
|
2011-03-03 15:24:23 +01:00
|
|
|
QUrl url = QUrl(button->whatsThis());
|
|
|
|
QString urlString = button->whatsThis();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.host().isEmpty()) {
|
|
|
|
if (!urlString.startsWith("/")) {
|
|
|
|
urlString = "/" + urlString;
|
|
|
|
}
|
|
|
|
urlString = m_view->url().host() + urlString;
|
2011-03-03 15:24:23 +01:00
|
|
|
QUrl temp(urlString);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (temp.scheme().isEmpty()) {
|
|
|
|
urlString = "http://" + urlString;
|
|
|
|
}
|
2011-03-03 15:24:23 +01:00
|
|
|
temp = QUrl(urlString);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (temp.scheme().isEmpty() || temp.host().isEmpty()) {
|
2011-03-03 15:24:23 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-03 15:24:23 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!url.isValid()) {
|
2011-03-03 15:24:23 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-03 15:24:23 +01:00
|
|
|
|
|
|
|
QString title;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (button->toolTip().isEmpty()) {
|
2011-03-03 15:24:23 +01:00
|
|
|
title = m_view->url().host();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-03 15:24:23 +01:00
|
|
|
title = button->toolTip();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-03 15:24:23 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
if (mApp->rssManager()->addRssFeed(urlString, title, m_view->icon())) {
|
2011-03-03 15:24:23 +01:00
|
|
|
RSSNotification* notif = new RSSNotification(title, m_view);
|
|
|
|
m_view->addNotification(notif);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:25:02 +01:00
|
|
|
RSSWidget::~RSSWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|