Browse Source

Remove the old rss feed downloader code

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
cb0942b388
  1. 1
      src/rss/automatedrssdownloader.cpp
  2. 294
      src/rss/feeddownloader.cpp
  3. 86
      src/rss/feeddownloader.h
  4. 549
      src/rss/feeddownloader.ui
  5. 5
      src/rss/rss.pri
  6. 1
      src/rss/rssfeed.cpp
  7. 216
      src/rss/rssfilters.cpp
  8. 80
      src/rss/rssfilters.h

1
src/rss/automatedrssdownloader.cpp

@ -35,7 +35,6 @@
#include "automatedrssdownloader.h" #include "automatedrssdownloader.h"
#include "ui_automatedrssdownloader.h" #include "ui_automatedrssdownloader.h"
#include "rssfilters.h"
#include "rsssettings.h" #include "rsssettings.h"
#include "rssdownloadrulelist.h" #include "rssdownloadrulelist.h"
#include "preferences.h" #include "preferences.h"

294
src/rss/feeddownloader.cpp

@ -1,294 +0,0 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "feeddownloader.h"
FeedDownloaderDlg::FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, QBtSession* BTSession):
QDialog(parent), feed_url(feed_url), feed_name(feed_name), BTSession(BTSession), selected_filter(QString::null)
{
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
Q_ASSERT(!feed_name.isEmpty());
rssfeed_lbl->setText(feed_name);
filters = RssFilters::getFeedFilters(feed_url);
// Connect Signals/Slots
connect(filtersList, SIGNAL(currentItemChanged(QListWidgetItem* , QListWidgetItem *)), this, SLOT(showFilterSettings(QListWidgetItem *)));
connect(filtersList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFiltersListMenu(const QPoint&)));
connect(actionAdd_filter, SIGNAL(triggered()), this, SLOT(addFilter()));
connect(actionRemove_filter, SIGNAL(triggered()), this, SLOT(deleteFilter()));
connect(actionRename_filter, SIGNAL(triggered()), this, SLOT(renameFilter()));
connect(del_button, SIGNAL(clicked(bool)), this, SLOT(deleteFilter()));
connect(add_button, SIGNAL(clicked(bool)), this, SLOT(addFilter()));
connect(enableDl_cb, SIGNAL(stateChanged(int)), this, SLOT(enableFilterBox(int)));
// Restore saved info
enableDl_cb->setChecked(filters.isDownloadingEnabled());
fillFiltersList();
if(filters.size() > 0) {
// Select first filter
filtersList->setCurrentItem(filtersList->item(0));
//showFilterSettings(filtersList->item(0));
}
// Show
show();
}
FeedDownloaderDlg::~FeedDownloaderDlg() {
if(enableDl_cb->isChecked())
emit filteringEnabled();
// Make sure we save everything
saveCurrentFilterSettings();
filters.save();
}
void FeedDownloaderDlg::saveCurrentFilterSettings() {
if(!selected_filter.isEmpty()) {
RssFilter filter = filters.getFilter(selected_filter);
filter.setMatchingTokens(match_line->text());
filter.setNotMatchingTokens(notmatch_line->text());
QString save_path = savepath_line->text().trimmed();
if(save_path.isEmpty())
save_path = BTSession->getDefaultSavePath();
filter.setSavePath(save_path);
// Save updated filter
filters.setFilter(selected_filter, filter);
}
}
void FeedDownloaderDlg::on_browse_button_clicked() {
QString default_path = savepath_line->text();
if(default_path.isEmpty() || !QDir(default_path).exists()) {
default_path = QDir::homePath();
}
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
if(!dir.isNull() && QDir(dir).exists()) {
savepath_line->setText(dir);
}
}
void FeedDownloaderDlg::fillFiltersList() {
// Fill filter list
foreach(QString filter_name, filters.names()) {
new QListWidgetItem(filter_name, filtersList);
}
}
void FeedDownloaderDlg::displayFiltersListMenu(const QPoint&) {
QMenu myFiltersListMenu(this);
if(filtersList->selectedItems().size() > 0) {
myFiltersListMenu.addAction(actionRename_filter);
myFiltersListMenu.addAction(actionRemove_filter);
} else {
myFiltersListMenu.addAction(actionAdd_filter);
}
// Call menu
myFiltersListMenu.exec(QCursor::pos());
}
void FeedDownloaderDlg::showFilterSettings(QListWidgetItem *item) {
// First, save current filter settings
saveCurrentFilterSettings();
// Clear all fields
clearFields();
if(!item) {
qDebug("No new selected item");
return;
}
// Actually show filter settings
QString filter_name = item->text();
RssFilter filter = filters.getFilter(filter_name);
filterSettingsBox->setEnabled(true);
match_line->setText(filter.getMatchingTokens_str());
if(match_line->text().trimmed().isEmpty()) {
match_line->setText(filter_name);
}
notmatch_line->setText(filter.getNotMatchingTokens_str());
QString save_path = filter.getSavePath();
if(save_path.isEmpty())
save_path = BTSession->getDefaultSavePath();
savepath_line->setText(save_path);
// Update selected filter
selected_filter = filter_name;
}
void FeedDownloaderDlg::deleteFilter() {
QList<QListWidgetItem *> items = filtersList->selectedItems();
if(items.size() == 1) {
QListWidgetItem * item = items.first();
filters.remove(item->text());
selected_filter = QString::null;
delete item;
// Reset Filter settings view
if(filters.size() == 0) {
clearFields();
filterSettingsBox->setEnabled(false);
}
}
}
void FeedDownloaderDlg::renameFilter() {
QList<QListWidgetItem *> items = filtersList->selectedItems();
if(items.size() == 1) {
QListWidgetItem *item = items.first();
QString current_name = item->text();
QString new_name;
bool validated = false;
do {
new_name = askFilterName(current_name);
if(new_name.isNull() || new_name == current_name) return;
if(!filters.hasFilter(new_name)) {
validated = true;
} else {
QMessageBox::warning(0, tr("Invalid filter name"), tr("This filter name is already in use."));
}
}while(!validated);
// Save the current filter
saveCurrentFilterSettings();
// Rename the filter
filters.rename(current_name, new_name);
if(selected_filter == current_name)
selected_filter = new_name;
item->setText(new_name);
}
}
void FeedDownloaderDlg::enableFilterBox(int state) {
if(state == Qt::Checked) {
filtersBox->setEnabled(true);
filters.setDownloadingEnabled(true);
} else {
filtersBox->setEnabled(false);
filters.setDownloadingEnabled(false);
}
}
QString FeedDownloaderDlg::askFilterName(QString name) {
QString name_prop;
if(name.isEmpty())
name_prop = tr("New filter");
else
name_prop = name;
QString new_name;
bool validated = false;
do {
bool ok;
new_name = QInputDialog::getText(this, tr("Please choose a name for this filter"), tr("Filter name:"), QLineEdit::Normal, name_prop, &ok);
if(!ok) {
return QString::null;
}
// Validate filter name
new_name = new_name.trimmed();
if(new_name.isEmpty()) {
// Cannot be left empty
QMessageBox::warning(0, tr("Invalid filter name"), tr("The filter name cannot be left empty."));
} else {
validated = true;
}
} while(!validated);
return new_name;
}
void FeedDownloaderDlg::addFilter() {
QString filter_name = QString::null;
bool validated = false;
do {
filter_name = askFilterName();
if(filter_name.isNull()) return;
if(filters.hasFilter(filter_name)) {
// Filter alread exists
QMessageBox::warning(0, tr("Invalid filter name"), tr("This filter name is already in use."));
} else {
validated = true;
}
}while(!validated);
QListWidgetItem *it = new QListWidgetItem(filter_name, filtersList);
filtersList->setCurrentItem(it);
//showFilterSettings(it);
}
void FeedDownloaderDlg::clearFields() {
match_line->clear();
notmatch_line->clear();
savepath_line->clear();
test_res_lbl->setText("");
test_line->clear();
}
void FeedDownloaderDlg::on_testButton_clicked(bool) {
test_res_lbl->clear();
if(selected_filter.isEmpty()) {
qDebug("No filter is selected!!!");
return;
}
QString s = test_line->text().trimmed();
if(s.isEmpty()) {
QMessageBox::warning(0, tr("Filter testing error"), tr("Please specify a test torrent name."));
return;
}
// Get current filter
saveCurrentFilterSettings();
RssFilter f = filters.getFilter(selected_filter);
if(f.matches(s))
test_res_lbl->setText("<b><font color=\"green\">"+tr("matches")+"</font></b>");
else
test_res_lbl->setText("<b><font color=\"red\">"+tr("does not match")+"</font></b>");
}
void FeedDownloaderDlg::on_importButton_clicked(bool) {
QString source = QFileDialog::getOpenFileName(0, tr("Select file to import"), QDir::homePath(), tr("Filters Files")+QString::fromUtf8(" (*.filters)"));
if(source.isEmpty()) return;
if(filters.unserialize(source)) {
// Clean up first
clearFields();
filtersList->clear();
selected_filter = QString::null;
fillFiltersList();
if(filters.size() > 0)
filtersList->setCurrentItem(filtersList->item(0));
QMessageBox::information(0, tr("Import successful"), tr("Filters import was successful."));
} else {
QMessageBox::warning(0, tr("Import failure"), tr("Filters could not be imported due to an I/O error."));
}
}
void FeedDownloaderDlg::on_exportButton_clicked(bool) {
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination file"), QDir::homePath(), tr("Filters Files")+QString::fromUtf8(" (*.filters)"));
if(destination.isEmpty()) return;
// Append file extension
if(!destination.endsWith(".filters"))
destination += ".filters";
/*if(QFile::exists(destination)) {
int ret = QMessageBox::question(0, tr("Overwriting confirmation"), tr("Are you sure you want to overwrite existing file?"), QMessageBox::Yes|QMessageBox::No);
if(ret != QMessageBox::Yes) return;
}*/
if(filters.serialize(destination))
QMessageBox::information(0, tr("Export successful"), tr("Filters export was successful."));
else
QMessageBox::warning(0, tr("Export failure"), tr("Filters could not be exported due to an I/O error."));
}

86
src/rss/feeddownloader.h

@ -1,86 +0,0 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef FEEDDOWNLOADER_H
#define FEEDDOWNLOADER_H
#include <QString>
#include <QListWidget>
#include <QListWidgetItem>
#include <QInputDialog>
#include <QMessageBox>
#include <QRegExp>
#include <QMenu>
#include <QFile>
#include <QDataStream>
#include <QFileDialog>
#include <QHash>
#include "qbtsession.h"
#include "ui_feeddownloader.h"
#include "qinisettings.h"
#include "rssfilters.h"
class FeedDownloaderDlg : public QDialog, private Ui_FeedDownloader{
Q_OBJECT
public:
FeedDownloaderDlg(QWidget *parent, QString feed_url, QString feed_name, QBtSession* BTSession);
~FeedDownloaderDlg();
protected slots:
void saveCurrentFilterSettings();
void on_browse_button_clicked();
void fillFiltersList();
void displayFiltersListMenu(const QPoint&);
void showFilterSettings(QListWidgetItem *item);
void deleteFilter();
void renameFilter();
void enableFilterBox(int state);
QString askFilterName(QString name=QString::null);
void addFilter();
void clearFields();
void on_testButton_clicked(bool);
void on_importButton_clicked(bool);
void on_exportButton_clicked(bool);
signals:
void filteringEnabled();
private:
QString feed_url;
QString feed_name;
RssFilters filters;
QBtSession *BTSession;
QString selected_filter; // name
};
#endif // FEEDDOWNLOADER_H

549
src/rss/feeddownloader.ui

@ -1,549 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FeedDownloader</class>
<widget class="QDialog" name="FeedDownloader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>737</width>
<height>415</height>
</rect>
</property>
<property name="windowTitle">
<string>RSS Feed downloader</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>RSS feed:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rssfeed_lbl">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Feed name</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="enableDl_cb">
<property name="text">
<string>Automatically download torrents from this feed</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="filtersBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Download filters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Filters:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="filtersList">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="del_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="add_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="filterSettingsBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string/>
</property>
<property name="title">
<string>Filter settings</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Matches:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Does not match:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Destination folder:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLineEdit" name="match_line">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="notmatch_line"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="savepath_line">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="browse_button">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="testerBox">
<property name="title">
<string>Filter testing</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Torrent title:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Result:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLineEdit" name="test_line"/>
</item>
<item>
<widget class="QPushButton" name="testButton">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="test_res_lbl">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>9</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string>Import...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="text">
<string>Export...</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<action name="actionRename_filter">
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/edit_clear.png</normaloff>:/Icons/oxygen/edit_clear.png</iconset>
</property>
<property name="text">
<string>Rename filter</string>
</property>
<property name="toolTip">
<string>Rename filter</string>
</property>
</action>
<action name="actionRemove_filter">
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
</property>
<property name="text">
<string>Remove filter</string>
</property>
<property name="toolTip">
<string>Remove filter</string>
</property>
</action>
<action name="actionAdd_filter">
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
</property>
<property name="text">
<string>Add filter</string>
</property>
</action>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>FeedDownloader</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>FeedDownloader</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

5
src/rss/rss.pri

@ -2,14 +2,12 @@ INCLUDEPATH += $$PWD
HEADERS += $$PWD/rss_imp.h \ HEADERS += $$PWD/rss_imp.h \
$$PWD/rsssettingsdlg.h \ $$PWD/rsssettingsdlg.h \
$$PWD/feeddownloader.h \
$$PWD/feedlistwidget.h \ $$PWD/feedlistwidget.h \
$$PWD/rssmanager.h \ $$PWD/rssmanager.h \
$$PWD/rssfeed.h \ $$PWD/rssfeed.h \
$$PWD/rssfolder.h \ $$PWD/rssfolder.h \
$$PWD/rssfile.h \ $$PWD/rssfile.h \
$$PWD/rssarticle.h \ $$PWD/rssarticle.h \
$$PWD/rssfilters.h \
$$PWD/automatedrssdownloader.h \ $$PWD/automatedrssdownloader.h \
$$PWD/rsssettings.h \ $$PWD/rsssettings.h \
$$PWD/rssdownloadrule.h \ $$PWD/rssdownloadrule.h \
@ -22,13 +20,10 @@ SOURCES += $$PWD/rss_imp.cpp \
$$PWD/rssfeed.cpp \ $$PWD/rssfeed.cpp \
$$PWD/rssfolder.cpp \ $$PWD/rssfolder.cpp \
$$PWD/rssarticle.cpp \ $$PWD/rssarticle.cpp \
$$PWD/feeddownloader.cpp \
$$PWD/rssfilters.cpp \
$$PWD/automatedrssdownloader.cpp \ $$PWD/automatedrssdownloader.cpp \
$$PWD/rssdownloadrule.cpp \ $$PWD/rssdownloadrule.cpp \
$$PWD/rssdownloadrulelist.cpp $$PWD/rssdownloadrulelist.cpp
FORMS += $$PWD/rss.ui \ FORMS += $$PWD/rss.ui \
$$PWD/feeddownloader.ui \
$$PWD/rsssettingsdlg.ui \ $$PWD/rsssettingsdlg.ui \
$$PWD/automatedrssdownloader.ui $$PWD/automatedrssdownloader.ui

1
src/rss/rssfeed.cpp

@ -34,7 +34,6 @@
#include "rssfolder.h" #include "rssfolder.h"
#include "rsssettings.h" #include "rsssettings.h"
#include "rssarticle.h" #include "rssarticle.h"
#include "feeddownloader.h"
#include "misc.h" #include "misc.h"
#include "rssdownloadrulelist.h" #include "rssdownloadrulelist.h"

216
src/rss/rssfilters.cpp

@ -1,216 +0,0 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez, Arnaud Demaiziere
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact: chris@qbittorrent.org, arnaud@qbittorrent.org
*/
#include <QFile>
#include "preferences.h"
#include "rssfilters.h"
// RssFilter
RssFilter::RssFilter(): valid(true) {
}
RssFilter::RssFilter(bool valid): valid(valid) {
}
RssFilter::RssFilter(QHash<QString, QVariant> filter):
QHash<QString, QVariant>(filter), valid(true) {
}
bool RssFilter::matches(QString s) {
QStringList match_tokens = getMatchingTokens();
foreach(const QString& token, match_tokens) {
if(token.isEmpty() || token == "")
continue;
QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard);
//reg.setMinimal(false);
if(reg.indexIn(s) < 0) return false;
}
qDebug("Checking not matching tokens");
// Checking not matching
QStringList notmatch_tokens = getNotMatchingTokens();
foreach(const QString& token, notmatch_tokens) {
if(token.isEmpty()) continue;
QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard);
if(reg.indexIn(s) > -1) return false;
}
return true;
}
bool RssFilter::isValid() const {
return valid;
}
QStringList RssFilter::getMatchingTokens() const {
QString matches = this->value("matches", "").toString();
return matches.split(" ");
}
QString RssFilter::getMatchingTokens_str() const {
return this->value("matches", "").toString();
}
void RssFilter::setMatchingTokens(QString tokens) {
tokens = tokens.trimmed();
if(tokens.isEmpty())
(*this)["matches"] = "";
else
(*this)["matches"] = tokens;
}
QStringList RssFilter::getNotMatchingTokens() const {
QString notmatching = this->value("not", "").toString();
return notmatching.split(QRegExp("[\\s|]"));
}
QString RssFilter::getNotMatchingTokens_str() const {
return this->value("not", "").toString();
}
void RssFilter::setNotMatchingTokens(QString tokens) {
(*this)["not"] = tokens.trimmed();
}
QString RssFilter::getSavePath() const {
return this->value("save_path", "").toString();
}
void RssFilter::setSavePath(QString save_path) {
(*this)["save_path"] = save_path;
}
// RssFilters
RssFilters::RssFilters() {
}
RssFilters::RssFilters(QString feed_url, QHash<QString, QVariant> filters):
QHash<QString, QVariant>(filters), feed_url(feed_url) {
}
bool RssFilters::hasFilter(QString name) const {
return this->contains(name);
}
RssFilter* RssFilters::matches(QString s) {
if(!isDownloadingEnabled()) return 0;
if(this->size() == 0) return new RssFilter(false);
foreach(QVariant var_hash_filter, this->values()) {
QHash<QString, QVariant> hash_filter = var_hash_filter.toHash();
RssFilter *filter = new RssFilter(hash_filter);
if(filter->matches(s))
return filter;
else
delete filter;
}
return 0;
}
QStringList RssFilters::names() const {
return this->keys();
}
RssFilter RssFilters::getFilter(QString name) const {
if(this->contains(name))
return RssFilter(this->value(name).toHash());
return RssFilter();
}
void RssFilters::setFilter(QString name, RssFilter f) {
(*this)[name] = f;
}
bool RssFilters::isDownloadingEnabled() const {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash();
return feeds_w_downloader.value(feed_url, false).toBool();
}
void RssFilters::setDownloadingEnabled(bool enabled) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on", QHash<QString, QVariant>()).toHash();
feeds_w_downloader[feed_url] = enabled;
qBTRSS.setValue("downloader_on", feeds_w_downloader);
}
RssFilters RssFilters::getFeedFilters(QString url) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> all_feeds_filters = qBTRSS.value("feed_filters", QHash<QString, QVariant>()).toHash();
return RssFilters(url, all_feeds_filters.value(url, QHash<QString, QVariant>()).toHash());
}
void RssFilters::rename(QString old_name, QString new_name) {
Q_ASSERT(this->contains(old_name));
(*this)[new_name] = this->take(old_name);
}
bool RssFilters::serialize(QString path) {
QFile f(path);
if(f.open(QIODevice::WriteOnly)) {
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_3);
out << (QHash<QString, QVariant>)(*this);
f.close();
return true;
} else {
return false;
}
}
bool RssFilters::unserialize(QString path) {
QFile f(path);
if(f.open(QIODevice::ReadOnly)) {
QDataStream in(&f);
in.setVersion(QDataStream::Qt_4_3);
QHash<QString, QVariant> tmp;
in >> tmp;
qDebug("Unserialized %d filters", tmp.size());
foreach(const QString& key, tmp.keys()) {
(*this)[key] = tmp[key];
}
return true;
} else {
return false;
}
}
void RssFilters::save() {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> all_feeds_filters = qBTRSS.value("feed_filters", QHash<QString, QVariant>()).toHash();
qDebug("Saving filters for feed: %s (%d filters)", qPrintable(feed_url), (*this).size());
all_feeds_filters[feed_url] = *this;
qBTRSS.setValue("feed_filters", all_feeds_filters);
}

80
src/rss/rssfilters.h

@ -1,80 +0,0 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez, Arnaud Demaiziere
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact: chris@qbittorrent.org, arnaud@qbittorrent.org
*/
#ifndef RSSDOWNLOADERFILTERS_H
#define RSSDOWNLOADERFILTERS_H
#include <QHash>
#include <QStringList>
#include <QVariant>
class RssFilter: public QHash<QString, QVariant> {
private:
bool valid;
public:
RssFilter();
RssFilter(bool valid);
RssFilter(QHash<QString, QVariant> filter);
bool matches(QString s);
bool isValid() const;
QStringList getMatchingTokens() const;
QString getMatchingTokens_str() const;
void setMatchingTokens(QString tokens);
QStringList getNotMatchingTokens() const;
QString getNotMatchingTokens_str() const;
void setNotMatchingTokens(QString tokens);
QString getSavePath() const;
void setSavePath(QString save_path);
};
class RssFilters : public QHash<QString, QVariant> {
public:
RssFilters();
RssFilters(QString feed_url, QHash<QString, QVariant> filters);
bool hasFilter(QString name) const;
RssFilter* matches(QString s);
QStringList names() const;
RssFilter getFilter(QString name) const;
void setFilter(QString name, RssFilter f);
bool isDownloadingEnabled() const;
void setDownloadingEnabled(bool enabled);
static RssFilters getFeedFilters(QString url);
void rename(QString old_name, QString new_name);
bool serialize(QString path);
bool unserialize(QString path);
void save();
private:
QString feed_url;
};
#endif // RSSDOWNLOADERFILTERS_H
Loading…
Cancel
Save