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-02 16:57:41 +01:00
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "ui_rssmanager.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "treewidget.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2011-07-30 17:57:14 +02:00
|
|
|
#include "browsinglibrary.h"
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "globalfunctions.h"
|
2011-10-29 13:36:04 +02:00
|
|
|
#include "followredirectreply.h"
|
2012-01-07 20:56:58 +01:00
|
|
|
#include "networkmanager.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QWebSettings>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2012-04-26 12:35:03 +02:00
|
|
|
#include <QSqlQuery>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-10-26 19:23:50 +02:00
|
|
|
RSSManager::RSSManager(QupZilla* mainClass, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::RSSManager)
|
|
|
|
, p_QupZilla(mainClass)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->tabWidget->setElideMode(Qt::ElideRight);
|
2012-01-07 20:56:58 +01:00
|
|
|
m_networkManager = mApp->networkManager();
|
|
|
|
|
|
|
|
m_reloadButton = new QToolButton(this);
|
|
|
|
m_reloadButton->setAutoRaise(true);
|
|
|
|
m_reloadButton->setToolTip(tr("Reload"));
|
2012-04-22 20:51:28 +02:00
|
|
|
m_reloadButton->setIcon(qIconProvider->standardIcon(QStyle::SP_BrowserReload));
|
2012-01-07 20:56:58 +01:00
|
|
|
|
|
|
|
ui->tabWidget->setCornerWidget(m_reloadButton);
|
|
|
|
|
|
|
|
connect(m_reloadButton, SIGNAL(clicked()), this, SLOT(reloadFeeds()));
|
|
|
|
connect(ui->add, SIGNAL(clicked()), this, SLOT(addFeed()));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(ui->deletebutton, SIGNAL(clicked()), this, SLOT(deleteFeed()));
|
|
|
|
connect(ui->edit, SIGNAL(clicked()), this, SLOT(editFeed()));
|
2011-07-30 17:57:14 +02:00
|
|
|
|
|
|
|
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QupZilla* RSSManager::getQupZilla()
|
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (!p_QupZilla) {
|
2011-03-04 13:59:07 +01:00
|
|
|
p_QupZilla = mApp->getWindow();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-09 21:56:01 +01:00
|
|
|
return p_QupZilla.data();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void RSSManager::setMainWindow(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (window) {
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla = window;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RSSManager::refreshTable()
|
|
|
|
{
|
|
|
|
QSqlQuery query;
|
|
|
|
ui->tabWidget->clear();
|
2011-07-30 17:57:14 +02:00
|
|
|
query.exec("SELECT address, title, icon FROM rss");
|
2011-03-02 16:57:41 +01:00
|
|
|
int i = 0;
|
|
|
|
while (query.next()) {
|
|
|
|
QUrl address = query.value(0).toUrl();
|
|
|
|
QString title = query.value(1).toString();
|
2012-04-22 20:51:28 +02:00
|
|
|
QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(2).toByteArray()));
|
2011-03-02 16:57:41 +01:00
|
|
|
TreeWidget* tree = new TreeWidget();
|
|
|
|
tree->setHeaderLabel(tr("News"));
|
|
|
|
tree->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(customContextMenuRequested(const QPoint &)));
|
|
|
|
|
|
|
|
ui->tabWidget->addTab(tree, title);
|
|
|
|
ui->tabWidget->setTabToolTip(i, address.toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(loadFeed(QTreeWidgetItem*)));
|
2011-10-26 19:23:50 +02:00
|
|
|
connect(tree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(controlLoadFeed(QTreeWidgetItem*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(tree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(controlLoadFeed(QTreeWidgetItem*)));
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, tr("Loading..."));
|
|
|
|
tree->addTopLevelItem(item);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
ui->tabWidget->setTabIcon(i, icon);
|
2011-03-02 16:57:41 +01:00
|
|
|
beginToLoadSlot(address);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i > 0) {
|
|
|
|
ui->deletebutton->setEnabled(true);
|
2012-01-07 20:56:58 +01:00
|
|
|
m_reloadButton->setEnabled(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
ui->edit->setEnabled(true);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-07-29 15:39:43 +02:00
|
|
|
ui->deletebutton->setEnabled(false);
|
2012-01-07 20:56:58 +01:00
|
|
|
m_reloadButton->setEnabled(false);
|
2011-07-29 15:39:43 +02:00
|
|
|
ui->edit->setEnabled(false);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QFrame* frame = new QFrame();
|
2011-09-11 19:15:06 +02:00
|
|
|
frame->setObjectName("rssmanager-frame");
|
2011-11-06 17:01:23 +01:00
|
|
|
QVBoxLayout* verticalLayout = new QVBoxLayout(frame);
|
|
|
|
QLabel* label_2 = new QLabel(frame);
|
2011-07-29 15:39:43 +02:00
|
|
|
label_2->setPixmap(QPixmap(":/icons/menu/rss.png"));
|
2011-11-06 17:01:23 +01:00
|
|
|
label_2->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
|
2011-07-29 15:39:43 +02:00
|
|
|
verticalLayout->addWidget(label_2);
|
2011-11-06 17:01:23 +01:00
|
|
|
QLabel* label = new QLabel(frame);
|
|
|
|
label->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
2011-07-29 15:39:43 +02:00
|
|
|
label->setText(tr("You don't have any RSS Feeds.<br/>\nPlease add some with RSS icon in navigation bar on site which offers feeds."));
|
|
|
|
verticalLayout->addWidget(label);
|
|
|
|
ui->tabWidget->addTab(frame, tr("Empty"));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-07 20:56:58 +01:00
|
|
|
void RSSManager::reloadFeeds()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
TreeWidget* treeWidget = qobject_cast<TreeWidget*>(ui->tabWidget->widget(ui->tabWidget->currentIndex()));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!treeWidget) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
treeWidget->clear();
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, tr("Loading..."));
|
|
|
|
treeWidget->addTopLevelItem(item);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
beginToLoadSlot(QUrl(ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex())));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-07 20:56:58 +01:00
|
|
|
void RSSManager::addFeed()
|
|
|
|
{
|
|
|
|
QUrl url = QUrl(QInputDialog::getText(this, tr("Add new feed"), tr("Please enter URL of new feed:")));
|
|
|
|
|
|
|
|
if (url.isEmpty() || !url.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
addRssFeed(url, tr("New feed"), _iconForUrl(url));
|
2012-01-07 20:56:58 +01:00
|
|
|
refreshTable();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void RSSManager::deleteFeed()
|
|
|
|
{
|
|
|
|
QString url = ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2012-08-23 15:37:43 +02:00
|
|
|
query.prepare("DELETE FROM rss WHERE address=?");
|
|
|
|
query.addBindValue(url);
|
|
|
|
query.exec();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
ui->tabWidget->removeTab(ui->tabWidget->currentIndex());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (ui->tabWidget->count() == 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
refreshTable();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RSSManager::editFeed()
|
|
|
|
{
|
|
|
|
QString url = ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QDialog* dialog = new QDialog(this);
|
|
|
|
QFormLayout* layout = new QFormLayout(dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLineEdit* editUrl = new QLineEdit(dialog);
|
|
|
|
QLineEdit* editTitle = new QLineEdit(dialog);
|
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
|
|
|
|
label->setText(tr("Fill title and URL of a feed: "));
|
|
|
|
layout->addRow(label);
|
|
|
|
layout->addRow(new QLabel(tr("Feed title: ")), editTitle);
|
|
|
|
layout->addRow(new QLabel(tr("Feed URL: ")), editUrl);
|
|
|
|
layout->addRow(box);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
editUrl->setText(ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex()));
|
|
|
|
editTitle->setText(ui->tabWidget->tabText(ui->tabWidget->currentIndex()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
dialog->setWindowTitle(tr("Edit RSS Feed"));
|
|
|
|
dialog->setMinimumSize(400, 100);
|
|
|
|
dialog->exec();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QString address = editUrl->text();
|
|
|
|
QString title = editTitle->text();
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (address.isEmpty() || title.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("UPDATE rss SET address=?, title=? WHERE address=?");
|
|
|
|
query.bindValue(0, address);
|
|
|
|
query.bindValue(1, title);
|
|
|
|
query.bindValue(2, url);
|
|
|
|
query.exec();
|
|
|
|
|
|
|
|
refreshTable();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RSSManager::customContextMenuRequested(const QPoint &position)
|
|
|
|
{
|
|
|
|
TreeWidget* treeWidget = qobject_cast<TreeWidget*>(ui->tabWidget->widget(ui->tabWidget->currentIndex()));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!treeWidget) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!treeWidget->itemAt(position)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QString link = treeWidget->itemAt(position)->toolTip(0);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (link.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QMenu menu;
|
2012-01-25 15:46:18 +01:00
|
|
|
menu.addAction(tr("Open link in current tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link);
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addAction(tr("Open link in new tab"), this, SLOT(loadFeedInNewTab()))->setData(link);
|
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-04-11 18:06:50 +02:00
|
|
|
QPoint pos = treeWidget->viewport()->mapToGlobal(position);
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.exec(p);
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void RSSManager::loadFeed(QTreeWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
if (item->toolTip(0).isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
getQupZilla()->loadAddress(QUrl(item->toolTip(0)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void RSSManager::controlLoadFeed(QTreeWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-06-27 18:05:09 +02:00
|
|
|
if (!item || item->toolTip(0).isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-06-27 18:05:09 +02:00
|
|
|
|
2012-08-10 21:16:43 +02:00
|
|
|
getQupZilla()->tabWidget()->addView(QUrl(item->toolTip(0)), qzSettings->newTabPosition);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RSSManager::loadFeedInNewTab()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2012-08-10 21:16:43 +02:00
|
|
|
getQupZilla()->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RSSManager::beginToLoadSlot(const QUrl &url)
|
|
|
|
{
|
2011-10-29 13:36:04 +02:00
|
|
|
FollowRedirectReply* reply = new FollowRedirectReply(url, m_networkManager);
|
|
|
|
connect(reply, SIGNAL(finished()), this, SLOT(finished()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-29 13:36:04 +02:00
|
|
|
QPair<FollowRedirectReply*, QUrl> pair;
|
|
|
|
pair.first = reply;
|
|
|
|
pair.second = url;
|
|
|
|
m_replies.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-29 13:36:04 +02:00
|
|
|
void RSSManager::finished()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-10-29 13:36:04 +02:00
|
|
|
FollowRedirectReply* reply = qobject_cast<FollowRedirectReply*> (sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!reply) {
|
2011-10-29 13:36:04 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-29 13:36:04 +02:00
|
|
|
|
|
|
|
QString replyUrl;
|
|
|
|
for (int i = 0; i < m_replies.count(); i++) {
|
|
|
|
QPair<FollowRedirectReply*, QUrl> pair = m_replies.at(i);
|
|
|
|
if (pair.first == reply) {
|
|
|
|
replyUrl = pair.second.toString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (replyUrl.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QString currentTag;
|
|
|
|
QString linkString;
|
|
|
|
QString titleString;
|
2011-10-29 13:36:04 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QXmlStreamReader xml;
|
2012-07-03 21:54:04 +02:00
|
|
|
xml.addData(reply->readAll());
|
2011-12-04 20:09:44 +01:00
|
|
|
|
|
|
|
reply->deleteLater();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
int tabIndex = -1;
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = 0; i < ui->tabWidget->count(); i++) {
|
2011-03-02 16:57:41 +01:00
|
|
|
if (replyUrl == ui->tabWidget->tabToolTip(i)) {
|
|
|
|
tabIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (tabIndex == -1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
TreeWidget* treeWidget = qobject_cast<TreeWidget*>(ui->tabWidget->widget(tabIndex));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!treeWidget) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
treeWidget->clear();
|
|
|
|
|
|
|
|
while (!xml.atEnd()) {
|
|
|
|
xml.readNext();
|
|
|
|
if (xml.isStartElement()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.name() == QLatin1String("item")) {
|
2011-03-02 16:57:41 +01:00
|
|
|
linkString = xml.attributes().value("rss:about").toString();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-30 17:54:49 +01:00
|
|
|
currentTag = xml.qualifiedName().toString();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (xml.isEndElement()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.qualifiedName() == QLatin1String("item")) {
|
2011-11-06 17:01:23 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
|
|
|
item->setText(0, titleString);
|
|
|
|
item->setIcon(0, QIcon(":/icons/other/feed.png"));
|
|
|
|
item->setToolTip(0, linkString);
|
|
|
|
treeWidget->addTopLevelItem(item);
|
|
|
|
|
|
|
|
titleString.clear();
|
|
|
|
linkString.clear();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (xml.isCharacters() && !xml.isWhitespace()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (currentTag == QLatin1String("title")) {
|
2011-11-06 17:01:23 +01:00
|
|
|
titleString = xml.text().toString();
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (currentTag == QLatin1String("link")) {
|
2011-11-06 17:01:23 +01:00
|
|
|
linkString += xml.text().toString();
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (treeWidget->topLevelItemCount() == 0) {
|
2011-03-17 17:03:04 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
2011-03-02 16:57:41 +01:00
|
|
|
item->setText(0, tr("Error in fetching feed"));
|
|
|
|
treeWidget->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
bool RSSManager::addRssFeed(const QUrl &url, const QString &title, const QIcon &icon)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-03-13 17:51:06 +01:00
|
|
|
if (url.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2012-03-13 17:51:06 +01:00
|
|
|
query.prepare("SELECT id FROM rss WHERE address=?");
|
|
|
|
query.addBindValue(url);
|
|
|
|
query.exec();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (!query.next()) {
|
2012-01-17 19:27:24 +01:00
|
|
|
QImage image = icon.pixmap(16, 16).toImage();
|
2012-03-13 17:51:06 +01:00
|
|
|
|
2012-04-22 20:51:28 +02:00
|
|
|
if (image == qIconProvider->emptyWebImage()) {
|
2012-01-17 19:27:24 +01:00
|
|
|
image.load(":icons/other/feed.png");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-30 17:57:14 +02:00
|
|
|
|
|
|
|
query.prepare("INSERT INTO rss (address, title, icon) VALUES(?,?,?)");
|
2012-03-13 17:51:06 +01:00
|
|
|
query.bindValue(0, url);
|
2011-03-02 16:57:41 +01:00
|
|
|
query.bindValue(1, title);
|
2012-01-17 19:27:24 +01:00
|
|
|
QByteArray ba;
|
|
|
|
QBuffer buffer(&ba);
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
image.save(&buffer, "PNG");
|
|
|
|
query.bindValue(2, buffer.data());
|
2012-04-26 12:35:03 +02:00
|
|
|
query.exec();
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-03 15:24:23 +01:00
|
|
|
|
|
|
|
QMessageBox::warning(getQupZilla(), tr("RSS feed duplicated"), tr("You already have this feed."));
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
void RSSManager::optimizeDb()
|
|
|
|
{
|
2011-10-20 17:56:01 +02:00
|
|
|
BrowsingLibrary* b = qobject_cast<BrowsingLibrary*>(parentWidget()->parentWidget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!b) {
|
2011-07-30 17:57:14 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-30 17:57:14 +02:00
|
|
|
b->optimizeDatabase();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
RSSManager::~RSSManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|