@ -50,35 +50,92 @@ DownloadRule::DownloadRule()
bool DownloadRule : : matches ( const QString & articleTitle ) const
bool DownloadRule : : matches ( const QString & articleTitle ) const
{
{
QRegExp whitespace ( " \\ s+ " ) ;
if ( ! m_mustContain . empty ( ) ) {
if ( ! m_mustContain . empty ( ) ) {
bool logged = false ;
bool logged = false ;
bool foundMustContain = true ;
// Each expression is either a regex, or a set of wildcards separated by whitespace.
// Accept if any complete expression matches.
foreach ( const QString & expression , m_mustContain ) {
if ( expression . isEmpty ( ) )
continue ;
foreach ( const QString & token , m_mustContain ) {
if ( ! token . isEmpty ( ) ) {
if ( ! logged ) {
if ( ! logged ) {
qDebug ( ) < < " Checking matching expressions: " < < m_mustContain . join ( " | " ) ;
qDebug ( ) < < " Checking matching expressions: " < < m_mustContain . join ( " | " ) ;
logged = true ;
logged = true ;
}
}
QRegExp reg ( token , Qt : : CaseInsensitive , m_useRegex ? QRegExp : : RegExp : QRegExp : : Wildcard ) ;
if ( m_useRegex ) {
if ( reg . indexIn ( articleTitle ) < 0 )
QRegExp reg ( expression , Qt : : CaseInsensitive , QRegExp : : RegExp ) ;
return false ;
if ( reg . indexIn ( articleTitle ) > - 1 )
foundMustContain = true ;
}
else {
// Only accept if every wildcard token (separated by spaces) is present in the article name.
// Order of wildcard tokens is unimportant (if order is important, they should have used *).
foundMustContain = true ;
foreach ( const QString & wildcard , expression . split ( whitespace , QString : : SplitBehavior : : SkipEmptyParts ) ) {
QRegExp reg ( wildcard , Qt : : CaseInsensitive , QRegExp : : Wildcard ) ;
if ( reg . indexIn ( articleTitle ) = = - 1 ) {
foundMustContain = false ;
break ;
}
}
}
}
}
}
if ( foundMustContain ) {
qDebug ( ) < < " Found matching expression: " < < expression ;
break ;
}
}
if ( ! foundMustContain )
return false ;
}
if ( ! m_mustNotContain . empty ( ) ) {
if ( ! m_mustNotContain . empty ( ) ) {
bool logged = false ;
bool logged = false ;
foreach ( const QString & token , m_mustNotContain ) {
// Each expression is either a regex, or a set of wildcards separated by whitespace.
if ( ! token . isEmpty ( ) ) {
// Reject if any complete expression matches.
foreach ( const QString & expression , m_mustNotContain ) {
if ( expression . isEmpty ( ) )
continue ;
if ( ! logged ) {
if ( ! logged ) {
qDebug ( ) < < " Checking not matching expressions: " < < m_mustNotContain . join ( " | " ) ;
qDebug ( ) < < " Checking not matching expressions: " < < m_mustNotContain . join ( " | " ) ;
logged = true ;
logged = true ;
}
}
QRegExp reg ( token , Qt : : CaseInsensitive , m_useRegex ? QRegExp : : RegExp : QRegExp : : Wildcard ) ;
if ( m_useRegex ) {
if ( reg . indexIn ( articleTitle ) > - 1 )
QRegExp reg ( expression , Qt : : CaseInsensitive , QRegExp : : RegExp ) ;
if ( reg . indexIn ( articleTitle ) > - 1 ) {
qDebug ( ) < < " Found not matching expression: " < < expression ;
return false ;
}
}
// Only reject if every wildcard token (separated by spaces) is present in the article name.
// Order of wildcard tokens is unimportant (if order is important, they should have used *).
bool foundMustNotContain = true ;
foreach ( const QString & wildcard , expression . split ( whitespace , QString : : SplitBehavior : : SkipEmptyParts ) ) {
QRegExp reg ( wildcard , Qt : : CaseInsensitive , QRegExp : : Wildcard ) ;
if ( reg . indexIn ( articleTitle ) = = - 1 ) {
foundMustNotContain = false ;
break ;
}
}
if ( foundMustNotContain ) {
qDebug ( ) < < " Found not matching expression: " < < expression ;
return false ;
return false ;
}
}
}
}
@ -162,7 +219,7 @@ void DownloadRule::setMustContain(const QString &tokens)
if ( m_useRegex )
if ( m_useRegex )
m_mustContain = QStringList ( ) < < tokens ;
m_mustContain = QStringList ( ) < < tokens ;
else
else
m_mustContain = tokens . split ( " " ) ;
m_mustContain = tokens . split ( " | " ) ;
}
}
void DownloadRule : : setMustNotContain ( const QString & tokens )
void DownloadRule : : setMustNotContain ( const QString & tokens )
@ -220,7 +277,7 @@ QVariantHash DownloadRule::toVariantHash() const
{
{
QVariantHash hash ;
QVariantHash hash ;
hash [ " name " ] = m_name ;
hash [ " name " ] = m_name ;
hash [ " must_contain " ] = m_mustContain . join ( " " ) ;
hash [ " must_contain " ] = m_mustContain . join ( " | " ) ;
hash [ " must_not_contain " ] = m_mustNotContain . join ( " | " ) ;
hash [ " must_not_contain " ] = m_mustNotContain . join ( " | " ) ;
hash [ " save_path " ] = m_savePath ;
hash [ " save_path " ] = m_savePath ;
hash [ " affected_feeds " ] = m_rssFeeds ;
hash [ " affected_feeds " ] = m_rssFeeds ;
@ -296,7 +353,7 @@ int DownloadRule::ignoreDays() const
QString DownloadRule : : mustContain ( ) const
QString DownloadRule : : mustContain ( ) const
{
{
return m_mustContain . join ( " " ) ;
return m_mustContain . join ( " | " ) ;
}
}
QString DownloadRule : : mustNotContain ( ) const
QString DownloadRule : : mustNotContain ( ) const