RSSWidget::RSSWidget(WebView* view, QWidget* parent) : LocationBarPopup(parent) , ui(new Ui::RSSWidget) , m_view(view) { ui->setupUi(this); QWebEngineFrame* frame = m_view->page()->mainFrame(); QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]"); // Make sure RSS feeds fit into a window, in case there is a lot of feeds from one page // See #906 int cols = links.count() / 10 == 0 ? 1 : links.count() / 10; int row = 0; for (int i = 0; i < links.count(); i++) { QWebElement element = links.at(i); QString title = element.attribute("title"); const QUrl url = QUrl::fromEncoded(element.attribute("href").toUtf8()); if (url.isEmpty()) { continue; } if (title.isEmpty()) { title = tr("Untitled feed"); } QPushButton* button = new QPushButton(this); button->setIcon(QIcon(":icons/other/feed.png")); button->setStyleSheet("text-align:left"); button->setText(title); button->setProperty("rss-url", url); button->setProperty("rss-title", title); if (!isRssFeedAlreadyStored(url)) { button->setFlat(true); button->setToolTip(url.toString()); } else { button->setFlat(false); button->setEnabled(false); button->setToolTip(tr("You already have this feed.")); } int pos = i % cols > 0 ? (i % cols) * 2 : 0; ui->gridLayout->addWidget(button, row, pos); connect(button, SIGNAL(clicked()), this, SLOT(addRss())); if (i % cols == cols - 1) { row++; } } }
RSSDetectionWidget::RSSDetectionWidget(WebView* view, QWidget* parent) : QFrame(parent, Qt::Popup) , view_(view) { setAttribute(Qt::WA_DeleteOnClose); setFrameStyle(QFrame::StyledPanel | QFrame::Plain); setLineWidth(1); setMidLineWidth(2); gridLayout_ = new QGridLayout(this); gridLayout_->setMargin(5); gridLayout_->setSpacing(5); QWebFrame* frame = view_->page()->mainFrame(); QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]"); int cols = links.count() / 10 == 0 ? 1 : links.count() / 10; int row = 0; for (int i = 0; i < links.count(); i++) { QWebElement element = links.at(i); QString title = element.attribute("title"); const QUrl url = QUrl::fromEncoded(element.attribute("href").toUtf8()); if (url.isEmpty()) { continue; } if (title.isEmpty()) { title = tr("Untitled feed"); } QPushButton* button = new QPushButton(this); button->setStyleSheet("QPushButton {text-align:left; border: none; padding: 0px;}" "QPushButton:hover {color: #1155CC;}"); button->setCursor(Qt::PointingHandCursor); button->setText(title); button->setToolTip(url.toString()); button->setProperty("rss-url", url); button->setProperty("rss-title", title); int pos = i % cols > 0 ? (i % cols) * 2 : 0; gridLayout_->addWidget(button, row, pos); connect(button, SIGNAL(clicked()), this, SLOT(addRss())); if (i % cols == cols - 1) { row++; } } }
} #endif foreach(const RssApp & app, m_rssApps) { 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())); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide())); startAnimation(); } void RSSNotification::hide() { m_view->setFocus(); AnimatedWidget::hide(); } void RSSNotification::addRss() { bool success = false; int index = ui->comboBox->currentIndex();