mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
Add regex help and validation (RSS downloader
This commit is contained in:
@@ -80,8 +80,12 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
|
||||
// Update matching articles when necessary
|
||||
ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles()));
|
||||
Q_ASSERT(ok);
|
||||
ok = connect(ui->lineContains, SIGNAL(textEdited(QString)), SLOT(updateMustLineValidity()));
|
||||
Q_ASSERT(ok);
|
||||
ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMatchingArticles()));
|
||||
Q_ASSERT(ok);
|
||||
ok = connect(ui->lineNotContains, SIGNAL(textEdited(QString)), SLOT(updateMustNotLineValidity()));
|
||||
Q_ASSERT(ok);
|
||||
updateRuleDefinitionBox();
|
||||
updateFeedList();
|
||||
}
|
||||
@@ -212,6 +216,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
||||
} else {
|
||||
ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule.label()));
|
||||
}
|
||||
updateMustLineValidity();
|
||||
updateMustNotLineValidity();
|
||||
} else {
|
||||
// New rule
|
||||
clearRuleDefinitionBox();
|
||||
@@ -237,6 +243,8 @@ void AutomatedRssDownloader::clearRuleDefinitionBox()
|
||||
ui->comboLabel->clearEditText();
|
||||
ui->checkRegex->setChecked(false);
|
||||
updateFieldsToolTips(ui->checkRegex->isChecked());
|
||||
updateMustLineValidity();
|
||||
updateMustNotLineValidity();
|
||||
}
|
||||
|
||||
RssDownloadRule AutomatedRssDownloader::getCurrentRule() const
|
||||
@@ -511,11 +519,64 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
|
||||
QString tip;
|
||||
if(regex) {
|
||||
tip = tr("Regex mode: use Perl-like regular expressions");
|
||||
ui->lineContains->setToolTip(tip);
|
||||
ui->lineNotContains->setToolTip(tip);
|
||||
} else {
|
||||
tip = tr("Wildcard mode: you can use:\n ? to match any single character.\n * to match zero or more of any characters.\n Whitespaces count as AND operators.");
|
||||
tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>Whitespaces count as AND operators</li></ul>");
|
||||
ui->lineContains->setToolTip(tip);
|
||||
tip = tr("Wildcard mode: you can use<ul><li>? to match any single character</li><li>* to match zero or more of any characters</li><li>| is used as OR operator</li></ul>");
|
||||
ui->lineNotContains->setToolTip(tip);
|
||||
}
|
||||
}
|
||||
|
||||
void AutomatedRssDownloader::updateMustLineValidity()
|
||||
{
|
||||
const QString text = ui->lineContains->text();
|
||||
bool valid = true;
|
||||
QStringList tokens;
|
||||
if(ui->checkRegex->isChecked())
|
||||
tokens << text;
|
||||
else
|
||||
tokens << text.split(" ");
|
||||
foreach(const QString &token, tokens) {
|
||||
QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if(!reg.isValid()) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(valid) {
|
||||
ui->lineContains->setStyleSheet("");
|
||||
ui->lbl_must_stat->setPixmap(QPixmap());
|
||||
} else {
|
||||
ui->lineContains->setStyleSheet("QLineEdit { color: #ff0000; }");
|
||||
ui->lbl_must_stat->setPixmap(IconProvider::instance()->getIcon("task-attention").pixmap(16, 16));
|
||||
}
|
||||
}
|
||||
|
||||
void AutomatedRssDownloader::updateMustNotLineValidity()
|
||||
{
|
||||
const QString text = ui->lineNotContains->text();
|
||||
bool valid = true;
|
||||
QStringList tokens;
|
||||
if(ui->checkRegex->isChecked())
|
||||
tokens << text;
|
||||
else
|
||||
tokens << text.split(QRegExp("[\\s|]"));
|
||||
foreach(const QString &token, tokens) {
|
||||
QRegExp reg(token, Qt::CaseInsensitive, ui->checkRegex->isChecked() ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if(!reg.isValid()) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(valid) {
|
||||
ui->lineNotContains->setStyleSheet("");
|
||||
ui->lbl_mustnot_stat->setPixmap(QPixmap());
|
||||
} else {
|
||||
ui->lineNotContains->setStyleSheet("QLineEdit { color: #ff0000; }");
|
||||
ui->lbl_mustnot_stat->setPixmap(IconProvider::instance()->getIcon("task-attention").pixmap(16, 16));
|
||||
}
|
||||
ui->lineContains->setToolTip(tip);
|
||||
ui->lineNotContains->setToolTip(tip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -76,6 +76,8 @@ private slots:
|
||||
void renameSelectedRule();
|
||||
void updateMatchingArticles();
|
||||
void updateFieldsToolTips(bool regex);
|
||||
void updateMustLineValidity();
|
||||
void updateMustNotLineValidity();
|
||||
|
||||
private:
|
||||
RssDownloadRule getCurrentRule() const;
|
||||
|
||||
@@ -122,111 +122,175 @@
|
||||
<property name="title">
|
||||
<string>Rule definition</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Must contain:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineContains"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Must not contain:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineNotContains"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Assign label:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="comboLabel">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="saveDiffDir_check">
|
||||
<property name="text">
|
||||
<string>Save to a different directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save to:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineSavePath">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="browseSP">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkRegex">
|
||||
<property name="text">
|
||||
<string>Use regular expressions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Must contain:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineContains"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_must_stat">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Must not contain:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineNotContains"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_mustnot_stat">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Assign label:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboLabel">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="saveDiffDir_check">
|
||||
<property name="text">
|
||||
<string>Save to a different directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save to:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineSavePath">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="browseSP">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user