@ -68,6 +68,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& m
ok = connect ( ui - > listRules , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayRulesListMenu ( const QPoint & ) ) ) ;
ok = connect ( ui - > listRules , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayRulesListMenu ( const QPoint & ) ) ) ;
Q_ASSERT ( ok ) ;
Q_ASSERT ( ok ) ;
m_ruleList = manager . toStrongRef ( ) - > downloadRules ( ) ;
m_ruleList = manager . toStrongRef ( ) - > downloadRules ( ) ;
m_editableRuleList = new RssDownloadRuleList ; // Read rule list from disk
initLabelCombobox ( ) ;
initLabelCombobox ( ) ;
loadFeedList ( ) ;
loadFeedList ( ) ;
loadSettings ( ) ;
loadSettings ( ) ;
@ -101,8 +102,11 @@ AutomatedRssDownloader::~AutomatedRssDownloader()
qDebug ( ) < < Q_FUNC_INFO ;
qDebug ( ) < < Q_FUNC_INFO ;
// Save current item on exit
// Save current item on exit
saveEditedRule ( ) ;
saveEditedRule ( ) ;
m_ruleList - > replace ( m_editableRuleList ) ;
m_ruleList - > saveRulesToStorage ( ) ;
saveSettings ( ) ;
saveSettings ( ) ;
delete ui ;
delete ui ;
delete m_editableRuleList ;
}
}
void AutomatedRssDownloader : : loadSettings ( )
void AutomatedRssDownloader : : loadSettings ( )
@ -132,10 +136,10 @@ void AutomatedRssDownloader::loadRulesList()
saveEditedRule ( ) ;
saveEditedRule ( ) ;
}
}
ui - > listRules - > clear ( ) ;
ui - > listRules - > clear ( ) ;
foreach ( const QString & rule_name , m_r uleList - > ruleNames ( ) ) {
foreach ( const QString & rule_name , m_editableR uleList - > ruleNames ( ) ) {
QListWidgetItem * item = new QListWidgetItem ( rule_name , ui - > listRules ) ;
QListWidgetItem * item = new QListWidgetItem ( rule_name , ui - > listRules ) ;
item - > setFlags ( item - > flags ( ) | Qt : : ItemIsUserCheckable ) ;
item - > setFlags ( item - > flags ( ) | Qt : : ItemIsUserCheckable ) ;
if ( m_r uleList - > getRule ( rule_name ) - > isEnabled ( ) )
if ( m_editableR uleList - > getRule ( rule_name ) - > isEnabled ( ) )
item - > setCheckState ( Qt : : Checked ) ;
item - > setCheckState ( Qt : : Checked ) ;
else
else
item - > setCheckState ( Qt : : Unchecked ) ;
item - > setCheckState ( Qt : : Unchecked ) ;
@ -170,7 +174,7 @@ void AutomatedRssDownloader::updateFeedList()
const QString feed_url = item - > data ( Qt : : UserRole ) . toString ( ) ;
const QString feed_url = item - > data ( Qt : : UserRole ) . toString ( ) ;
bool all_enabled = false ;
bool all_enabled = false ;
foreach ( const QListWidgetItem * ruleItem , ui - > listRules - > selectedItems ( ) ) {
foreach ( const QListWidgetItem * ruleItem , ui - > listRules - > selectedItems ( ) ) {
RssDownloadRulePtr rule = m_r uleList - > getRule ( ruleItem - > text ( ) ) ;
RssDownloadRulePtr rule = m_editableR uleList - > 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 ( ) ) {
@ -257,7 +261,7 @@ RssDownloadRulePtr AutomatedRssDownloader::getCurrentRule() const
{
{
QListWidgetItem * current_item = ui - > listRules - > currentItem ( ) ;
QListWidgetItem * current_item = ui - > listRules - > currentItem ( ) ;
if ( current_item )
if ( current_item )
return m_r uleList - > getRule ( current_item - > text ( ) ) ;
return m_editableR uleList - > getRule ( current_item - > text ( ) ) ;
return RssDownloadRulePtr ( ) ;
return RssDownloadRulePtr ( ) ;
}
}
@ -279,7 +283,7 @@ void AutomatedRssDownloader::saveEditedRule()
qDebug ( ) < < " Probably removed the item, no need to save it " ;
qDebug ( ) < < " Probably removed the item, no need to save it " ;
return ;
return ;
}
}
RssDownloadRulePtr rule = m_r uleList - > getRule ( m_editedRule - > text ( ) ) ;
RssDownloadRulePtr rule = m_editableR uleList - > getRule ( m_editedRule - > text ( ) ) ;
if ( ! rule ) {
if ( ! rule ) {
rule = RssDownloadRulePtr ( new RssDownloadRule ) ;
rule = RssDownloadRulePtr ( new RssDownloadRule ) ;
rule - > setName ( m_editedRule - > text ( ) ) ;
rule - > setName ( m_editedRule - > text ( ) ) ;
@ -301,7 +305,7 @@ void AutomatedRssDownloader::saveEditedRule()
Preferences ( ) . addTorrentLabel ( rule - > label ( ) ) ;
Preferences ( ) . addTorrentLabel ( rule - > label ( ) ) ;
//rule->setRssFeeds(getSelectedFeeds());
//rule->setRssFeeds(getSelectedFeeds());
// Save it
// Save it
m_r uleList - > saveRule ( rule ) ;
m_editableR uleList - > saveRule ( rule ) ;
}
}
@ -311,7 +315,7 @@ void AutomatedRssDownloader::on_addRuleBtn_clicked()
const QString rule_name = QInputDialog : : getText ( this , tr ( " New rule name " ) , tr ( " Please type the name of the new download rule. " ) ) ;
const QString rule_name = QInputDialog : : getText ( this , tr ( " New rule name " ) , tr ( " Please type the name of the new download rule. " ) ) ;
if ( rule_name . isEmpty ( ) ) return ;
if ( rule_name . isEmpty ( ) ) return ;
// Check if this rule name already exists
// Check if this rule name already exists
if ( m_r uleList - > getRule ( rule_name ) ) {
if ( m_editableR uleList - > getRule ( rule_name ) ) {
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. " ) ) ;
return ;
return ;
}
}
@ -342,8 +346,8 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked()
// Clean up memory
// Clean up memory
delete item ;
delete item ;
qDebug ( " Removed item for the UI list " ) ;
qDebug ( " Removed item for the UI list " ) ;
// Remove it from the m_r uleList
// Remove it from the m_editableR uleList
m_r uleList - > removeRule ( rule_name ) ;
m_editableR uleList - > removeRule ( rule_name ) ;
}
}
}
}
@ -356,7 +360,7 @@ void AutomatedRssDownloader::on_browseSP_clicked()
void AutomatedRssDownloader : : on_exportBtn_clicked ( )
void AutomatedRssDownloader : : on_exportBtn_clicked ( )
{
{
if ( m_r uleList - > isEmpty ( ) ) {
if ( m_editableR uleList - > isEmpty ( ) ) {
QMessageBox : : warning ( this , tr ( " Invalid action " ) , tr ( " The list is empty, there is nothing to export. " ) ) ;
QMessageBox : : warning ( this , tr ( " Invalid action " ) , tr ( " The list is empty, there is nothing to export. " ) ) ;
return ;
return ;
}
}
@ -365,7 +369,7 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
if ( save_path . isEmpty ( ) ) return ;
if ( save_path . isEmpty ( ) ) return ;
if ( ! save_path . endsWith ( " .rssrules " , Qt : : CaseInsensitive ) )
if ( ! save_path . endsWith ( " .rssrules " , Qt : : CaseInsensitive ) )
save_path + = " .rssrules " ;
save_path + = " .rssrules " ;
if ( ! m_r uleList - > serialize ( save_path ) ) {
if ( ! m_editableR uleList - > serialize ( save_path ) ) {
QMessageBox : : warning ( this , tr ( " I/O Error " ) , tr ( " Failed to create the destination file " ) ) ;
QMessageBox : : warning ( this , tr ( " I/O Error " ) , tr ( " Failed to create the destination file " ) ) ;
return ;
return ;
}
}
@ -377,7 +381,7 @@ void AutomatedRssDownloader::on_importBtn_clicked()
QString load_path = QFileDialog : : getOpenFileName ( this , tr ( " Please point to the RSS download rules file " ) , QDir : : homePath ( ) , tr ( " Rules list (*.rssrules *.filters) " ) ) ;
QString load_path = QFileDialog : : getOpenFileName ( this , tr ( " Please point to the RSS download rules file " ) , QDir : : homePath ( ) , tr ( " Rules list (*.rssrules *.filters) " ) ) ;
if ( load_path . isEmpty ( ) | | ! QFile : : exists ( load_path ) ) return ;
if ( load_path . isEmpty ( ) | | ! QFile : : exists ( load_path ) ) return ;
// Load it
// Load it
if ( ! m_r uleList - > unserialize ( load_path ) ) {
if ( ! m_editableR uleList - > unserialize ( load_path ) ) {
QMessageBox : : warning ( this , tr ( " Import Error " ) , tr ( " Failed to import the selected rules file " ) ) ;
QMessageBox : : warning ( this , tr ( " Import Error " ) , tr ( " Failed to import the selected rules file " ) ) ;
return ;
return ;
}
}
@ -426,11 +430,11 @@ void AutomatedRssDownloader::renameSelectedRule()
QString new_name = QInputDialog : : getText ( this , tr ( " Rule renaming " ) , tr ( " Please type the new rule name " ) , QLineEdit : : Normal , item - > text ( ) ) ;
QString new_name = QInputDialog : : getText ( this , tr ( " Rule renaming " ) , tr ( " Please type the new rule name " ) , QLineEdit : : Normal , item - > text ( ) ) ;
new_name = new_name . trimmed ( ) ;
new_name = new_name . trimmed ( ) ;
if ( new_name . isEmpty ( ) ) return ;
if ( new_name . isEmpty ( ) ) return ;
if ( m_r uleList - > ruleNames ( ) . contains ( new_name , Qt : : CaseInsensitive ) ) {
if ( m_editableR uleList - > 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_r uleList - > renameRule ( item - > text ( ) , new_name ) ;
m_editableR uleList - > renameRule ( item - > text ( ) , new_name ) ;
item - > setText ( new_name ) ;
item - > setText ( new_name ) ;
return ;
return ;
}
}
@ -445,7 +449,7 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
}
}
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 ( ) ) {
RssDownloadRulePtr rule = m_r uleList - > getRule ( rule_item - > text ( ) ) ;
RssDownloadRulePtr rule = m_editableR uleList - > getRule ( rule_item - > text ( ) ) ;
Q_ASSERT ( rule ) ;
Q_ASSERT ( rule ) ;
QStringList affected_feeds = rule - > rssFeeds ( ) ;
QStringList affected_feeds = rule - > rssFeeds ( ) ;
if ( feed_item - > checkState ( ) = = Qt : : Checked ) {
if ( feed_item - > checkState ( ) = = Qt : : Checked ) {
@ -458,7 +462,7 @@ void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feed_it
// 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 ) ;
m_r uleList - > saveRule ( rule ) ;
m_editableR uleList - > saveRule ( rule ) ;
}
}
}
}
// Update Matching articles
// Update Matching articles
@ -477,7 +481,7 @@ void AutomatedRssDownloader::updateMatchingArticles()
const QHash < QString , RssFeedPtr > all_feeds = manager - > getAllFeedsAsHash ( ) ;
const QHash < QString , RssFeedPtr > all_feeds = manager - > getAllFeedsAsHash ( ) ;
foreach ( const QListWidgetItem * rule_item , ui - > listRules - > selectedItems ( ) ) {
foreach ( const QListWidgetItem * rule_item , ui - > listRules - > selectedItems ( ) ) {
RssDownloadRulePtr rule = m_r uleList - > getRule ( rule_item - > text ( ) ) ;
RssDownloadRulePtr rule = m_editableR uleList - > getRule ( rule_item - > text ( ) ) ;
if ( ! rule ) continue ;
if ( ! rule ) continue ;
foreach ( const QString & feed_url , rule - > rssFeeds ( ) ) {
foreach ( const QString & feed_url , rule - > rssFeeds ( ) ) {
qDebug ( ) < < Q_FUNC_INFO < < feed_url ;
qDebug ( ) < < Q_FUNC_INFO < < feed_url ;