@ -47,8 +47,8 @@
# include "ui_automatedrssdownloader.h"
# include "ui_automatedrssdownloader.h"
# include "automatedrssdownloader.h"
# include "automatedrssdownloader.h"
AutomatedRssDownloader : : AutomatedRssDownloader ( const QWeakPointer < Rss : : Manager > & manager , QWidget * parent ) :
AutomatedRssDownloader : : AutomatedRssDownloader ( const QWeakPointer < Rss : : Manager > & manager , QWidget * parent )
QDialog ( parent ) ,
: QDialog ( parent ) ,
ui ( new Ui : : AutomatedRssDownloader ) ,
ui ( new Ui : : AutomatedRssDownloader ) ,
m_manager ( manager ) , m_editedRule ( 0 )
m_manager ( manager ) , m_editedRule ( 0 )
{
{
@ -76,15 +76,15 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>&
Qt : : CaseInsensitive ) ,
Qt : : CaseInsensitive ) ,
ui - > lineEFilter ) ;
ui - > lineEFilter ) ;
ui - > lineEFilter - > setValidator ( m_episodeValidator ) ;
ui - > lineEFilter - > setValidator ( m_episodeValidator ) ;
QString tip = " <p> " + tr ( " Matches articles based on episode filter. " ) + " </p><p><b> " + tr ( " Example: " ) +
QString tip = " <p> " + tr ( " Matches articles based on episode filter. " ) + " </p><p><b> " + tr ( " Example: " )
" 1x2;8-15;5;30-;</b> " + tr ( " will match 2, 5, 8 through 15, 30 and onward episodes of season one " , " example X will match " ) + " </p> " ;
+ " 1x2;8-15;5;30-;</b> " + tr ( " will match 2, 5, 8 through 15, 30 and onward episodes of season one " , " example X will match " ) + " </p> " ;
tip + = " <p> " + tr ( " Episode filter rules: " ) + " </p><ul><li> " + tr ( " Season number is a mandatory non-zero value " ) + " </li> " +
tip + = " <p> " + tr ( " Episode filter rules: " ) + " </p><ul><li> " + tr ( " Season number is a mandatory non-zero value " ) + " </li> "
" <li> " + tr ( " Episode number is a mandatory non-zero value " ) + " </li> " +
+ " <li> " + tr ( " Episode number is a mandatory non-zero value " ) + " </li> "
" <li> " + tr ( " Filter must end with semicolon " ) + " </li> " +
+ " <li> " + tr ( " Filter must end with semicolon " ) + " </li> "
" <li> " + tr ( " Three range types for episodes are supported: " ) + " </li> " + " <li><ul> "
+ " <li> " + tr ( " Three range types for episodes are supported: " ) + " </li> " + " <li><ul> "
" <li> " + tr ( " Single number: <b>1x25;</b> matches episode 25 of season one " ) + " </li> " +
" <li> " + tr ( " Single number: <b>1x25;</b> matches episode 25 of season one " ) + " </li> "
" <li> " + tr ( " Normal range: <b>1x25-40;</b> matches episodes 25 through 40 of season one " ) + " </li> " +
+ " <li> " + tr ( " Normal range: <b>1x25-40;</b> matches episodes 25 through 40 of season one " ) + " </li> "
" <li> " + tr ( " Infinite range: <b>1x25-;</b> matches episodes 25 and upward of season one " ) + " </li> " + " </ul></li></ul> " ;
+ " <li> " + tr ( " Infinite range: <b>1x25-;</b> matches episodes 25 and upward of season one " ) + " </li> " + " </ul></li></ul> " ;
ui - > lineEFilter - > setToolTip ( tip ) ;
ui - > lineEFilter - > setToolTip ( tip ) ;
initCategoryCombobox ( ) ;
initCategoryCombobox ( ) ;
loadFeedList ( ) ;
loadFeedList ( ) ;
@ -159,9 +159,8 @@ void AutomatedRssDownloader::saveSettings()
void AutomatedRssDownloader : : loadRulesList ( )
void AutomatedRssDownloader : : loadRulesList ( )
{
{
// Make sure we save the current item before clearing
// Make sure we save the current item before clearing
if ( m_editedRule ) {
if ( m_editedRule )
saveEditedRule ( ) ;
saveEditedRule ( ) ;
}
ui - > listRules - > clear ( ) ;
ui - > listRules - > clear ( ) ;
foreach ( const QString & rule_name , m_editableRuleList - > ruleNames ( ) ) {
foreach ( const QString & rule_name , m_editableRuleList - > ruleNames ( ) ) {
QListWidgetItem * item = new QListWidgetItem ( rule_name , ui - > listRules ) ;
QListWidgetItem * item = new QListWidgetItem ( rule_name , ui - > listRules ) ;
@ -171,7 +170,7 @@ void AutomatedRssDownloader::loadRulesList()
else
else
item - > setCheckState ( Qt : : Unchecked ) ;
item - > setCheckState ( Qt : : Unchecked ) ;
}
}
if ( ui - > listRules - > count ( ) > 0 & & ! ui - > listRules - > currentItem ( ) )
if ( ( ui - > listRules - > count ( ) > 0 ) & & ! ui - > listRules - > currentItem ( ) )
ui - > listRules - > setCurrentRow ( 0 ) ;
ui - > listRules - > setCurrentRow ( 0 ) ;
}
}
@ -204,13 +203,13 @@ void AutomatedRssDownloader::updateFeedList()
Rss : : DownloadRulePtr rule = m_editableRuleList - > getRule ( ruleItem - > text ( ) ) ;
Rss : : DownloadRulePtr rule = m_editableRuleList - > getRule ( ruleItem - > text ( ) ) ;
if ( ! rule ) continue ;
if ( ! rule ) continue ;
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " affects " < < rule - > rssFeeds ( ) . size ( ) < < " feeds. " ;
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " affects " < < rule - > rssFeeds ( ) . size ( ) < < " feeds. " ;
foreach ( QString test , rule - > rssFeeds ( ) ) {
foreach ( QString test , rule - > rssFeeds ( ) )
qDebug ( ) < < " Feed is " < < test ;
qDebug ( ) < < " Feed is " < < test ;
}
if ( rule - > rssFeeds ( ) . contains ( feed_url ) ) {
if ( rule - > rssFeeds ( ) . contains ( feed_url ) ) {
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " affects feed " < < feed_url ;
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " affects feed " < < feed_url ;
all_enabled = true ;
all_enabled = true ;
} else {
}
else {
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " does NOT affect feed " < < feed_url ;
qDebug ( ) < < " Rule " < < rule - > name ( ) < < " does NOT affect feed " < < feed_url ;
all_enabled = false ;
all_enabled = false ;
break ;
break ;
@ -257,7 +256,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
if ( rule - > category ( ) . isEmpty ( ) ) {
if ( rule - > category ( ) . isEmpty ( ) ) {
ui - > comboCategory - > setCurrentIndex ( - 1 ) ;
ui - > comboCategory - > setCurrentIndex ( - 1 ) ;
ui - > comboCategory - > clearEditText ( ) ;
ui - > comboCategory - > clearEditText ( ) ;
} else {
}
else {
ui - > comboCategory - > setCurrentIndex ( ui - > comboCategory - > findText ( rule - > category ( ) ) ) ;
ui - > comboCategory - > setCurrentIndex ( ui - > comboCategory - > findText ( rule - > category ( ) ) ) ;
}
}
ui - > comboAddPaused - > setCurrentIndex ( rule - > addPaused ( ) ) ;
ui - > comboAddPaused - > setCurrentIndex ( rule - > addPaused ( ) ) ;
@ -271,7 +271,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
ui - > lblLastMatch - > setText ( lMatch ) ;
ui - > lblLastMatch - > setText ( lMatch ) ;
updateMustLineValidity ( ) ;
updateMustLineValidity ( ) ;
updateMustNotLineValidity ( ) ;
updateMustNotLineValidity ( ) ;
} else {
}
else {
// New rule
// New rule
clearRuleDefinitionBox ( ) ;
clearRuleDefinitionBox ( ) ;
ui - > lineContains - > setText ( selection . first ( ) - > text ( ) ) ;
ui - > lineContains - > setText ( selection . first ( ) - > text ( ) ) ;
@ -280,7 +281,8 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
updateFieldsToolTips ( ui - > checkRegex - > isChecked ( ) ) ;
updateFieldsToolTips ( ui - > checkRegex - > isChecked ( ) ) ;
// Enable
// Enable
ui - > ruleDefBox - > setEnabled ( true ) ;
ui - > ruleDefBox - > setEnabled ( true ) ;
} else {
}
else {
m_editedRule = 0 ;
m_editedRule = 0 ;
// Clear
// Clear
clearRuleDefinitionBox ( ) ;
clearRuleDefinitionBox ( ) ;
@ -353,7 +355,6 @@ void AutomatedRssDownloader::saveEditedRule()
m_editableRuleList - > saveRule ( rule ) ;
m_editableRuleList - > saveRule ( rule ) ;
}
}
void AutomatedRssDownloader : : on_addRuleBtn_clicked ( )
void AutomatedRssDownloader : : on_addRuleBtn_clicked ( )
{
{
// Ask for a rule name
// Ask for a rule name
@ -447,7 +448,8 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
delAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Delete rule " ) ) ;
delAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Delete rule " ) ) ;
menu . addSeparator ( ) ;
menu . addSeparator ( ) ;
renameAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename rule... " ) ) ;
renameAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename rule... " ) ) ;
} else {
}
else {
delAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Delete selected rules " ) ) ;
delAct = menu . addAction ( GuiIconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Delete selected rules " ) ) ;
}
}
}
}
@ -480,7 +482,8 @@ void AutomatedRssDownloader::renameSelectedRule()
if ( new_name . isEmpty ( ) ) return ;
if ( new_name . isEmpty ( ) ) return ;
if ( m_editableRuleList - > ruleNames ( ) . contains ( new_name , Qt : : CaseInsensitive ) ) {
if ( m_editableRuleList - > ruleNames ( ) . contains ( new_name , Qt : : CaseInsensitive ) ) {
QMessageBox : : warning ( this , tr ( " Rule name conflict " ) , tr ( " A rule with this name already exists, please choose another name. " ) ) ;
QMessageBox : : warning ( this , tr ( " Rule name conflict " ) , tr ( " A rule with this name already exists, please choose another name. " ) ) ;
} else {
}
else {
// Rename the rule
// Rename the rule
m_editableRuleList - > renameRule ( item - > text ( ) , new_name ) ;
m_editableRuleList - > renameRule ( item - > text ( ) , new_name ) ;
item - > setText ( new_name ) ;
item - > setText ( new_name ) ;
@ -491,10 +494,9 @@ void AutomatedRssDownloader::renameSelectedRule()
void AutomatedRssDownloader : : handleFeedCheckStateChange ( QListWidgetItem * feed_item )
void AutomatedRssDownloader : : handleFeedCheckStateChange ( QListWidgetItem * feed_item )
{
{
if ( ui - > ruleDefBox - > isEnabled ( ) ) {
if ( ui - > ruleDefBox - > isEnabled ( ) )
// Make sure the current rule is saved
// Make sure the current rule is saved
saveEditedRule ( ) ;
saveEditedRule ( ) ;
}
const QString feed_url = feed_item - > data ( Qt : : UserRole ) . toString ( ) ;
const QString feed_url = feed_item - > data ( Qt : : UserRole ) . toString ( ) ;
foreach ( QListWidgetItem * rule_item , ui - > listRules - > selectedItems ( ) ) {
foreach ( QListWidgetItem * rule_item , ui - > listRules - > selectedItems ( ) ) {
Rss : : DownloadRulePtr rule = m_editableRuleList - > getRule ( rule_item - > text ( ) ) ;
Rss : : DownloadRulePtr rule = m_editableRuleList - > getRule ( rule_item - > text ( ) ) ;
@ -503,10 +505,9 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
if ( feed_item - > checkState ( ) = = Qt : : Checked ) {
if ( feed_item - > checkState ( ) = = Qt : : Checked ) {
if ( ! affected_feeds . contains ( feed_url ) )
if ( ! affected_feeds . contains ( feed_url ) )
affected_feeds < < feed_url ;
affected_feeds < < feed_url ;
} else {
if ( affected_feeds . contains ( feed_url ) )
affected_feeds . removeOne ( feed_url ) ;
}
}
else if ( affected_feeds . contains ( feed_url ) )
affected_feeds . removeOne ( feed_url ) ;
// Save the updated rule
// Save the updated rule
if ( affected_feeds . size ( ) ! = rule - > rssFeeds ( ) . size ( ) ) {
if ( affected_feeds . size ( ) ! = rule - > rssFeeds ( ) . size ( ) ) {
rule - > setRssFeeds ( affected_feeds ) ;
rule - > setRssFeeds ( affected_feeds ) ;
@ -580,7 +581,8 @@ void AutomatedRssDownloader::updateFieldsToolTips(bool regex)
tip = tr ( " Regex mode: use Perl-like regular expressions " ) ;
tip = tr ( " Regex mode: use Perl-like regular expressions " ) ;
ui - > lineContains - > setToolTip ( tip ) ;
ui - > lineContains - > setToolTip ( tip ) ;
ui - > lineNotContains - > setToolTip ( tip ) ;
ui - > lineNotContains - > setToolTip ( tip ) ;
} else {
}
else {
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> " ) ;
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 ) ;
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> " ) ;
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> " ) ;
@ -607,7 +609,8 @@ void AutomatedRssDownloader::updateMustLineValidity()
if ( valid ) {
if ( valid ) {
ui - > lineContains - > setStyleSheet ( " " ) ;
ui - > lineContains - > setStyleSheet ( " " ) ;
ui - > lbl_must_stat - > setPixmap ( QPixmap ( ) ) ;
ui - > lbl_must_stat - > setPixmap ( QPixmap ( ) ) ;
} else {
}
else {
ui - > lineContains - > setStyleSheet ( " QLineEdit { color: #ff0000; } " ) ;
ui - > lineContains - > setStyleSheet ( " QLineEdit { color: #ff0000; } " ) ;
ui - > lbl_must_stat - > setPixmap ( GuiIconProvider : : instance ( ) - > getIcon ( " task-attention " ) . pixmap ( 16 , 16 ) ) ;
ui - > lbl_must_stat - > setPixmap ( GuiIconProvider : : instance ( ) - > getIcon ( " task-attention " ) . pixmap ( 16 , 16 ) ) ;
}
}
@ -632,13 +635,15 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if ( valid ) {
if ( valid ) {
ui - > lineNotContains - > setStyleSheet ( " " ) ;
ui - > lineNotContains - > setStyleSheet ( " " ) ;
ui - > lbl_mustnot_stat - > setPixmap ( QPixmap ( ) ) ;
ui - > lbl_mustnot_stat - > setPixmap ( QPixmap ( ) ) ;
} else {
}
else {
ui - > lineNotContains - > setStyleSheet ( " QLineEdit { color: #ff0000; } " ) ;
ui - > lineNotContains - > setStyleSheet ( " QLineEdit { color: #ff0000; } " ) ;
ui - > lbl_mustnot_stat - > setPixmap ( GuiIconProvider : : instance ( ) - > getIcon ( " task-attention " ) . pixmap ( 16 , 16 ) ) ;
ui - > lbl_mustnot_stat - > setPixmap ( GuiIconProvider : : instance ( ) - > getIcon ( " task-attention " ) . pixmap ( 16 , 16 ) ) ;
}
}
}
}
void AutomatedRssDownloader : : onFinished ( int result ) {
void AutomatedRssDownloader : : onFinished ( int result )
{
Q_UNUSED ( result ) ;
Q_UNUSED ( result ) ;
// Save current item on exit
// Save current item on exit
saveEditedRule ( ) ;
saveEditedRule ( ) ;