Some refactorings.
This commit is contained in:
parent
28676a4abd
commit
95445368bc
3 changed files with 55 additions and 51 deletions
|
|
@ -217,16 +217,16 @@ FeedsModelRootItem *FeedsProxyModel::selectedItem() const {
|
||||||
return m_selectedItem;
|
return m_selectedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsProxyModel::setSelectedItem(FeedsModelRootItem *selectedItem) {
|
void FeedsProxyModel::setSelectedItem(FeedsModelRootItem *selected_item) {
|
||||||
m_selectedItem = selectedItem;
|
m_selectedItem = selected_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FeedsProxyModel::showUnreadOnly() const {
|
bool FeedsProxyModel::showUnreadOnly() const {
|
||||||
return m_showUnreadOnly;
|
return m_showUnreadOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsProxyModel::setShowUnreadOnly(bool showUnreadOnly) {
|
void FeedsProxyModel::setShowUnreadOnly(bool show_unread_only) {
|
||||||
m_showUnreadOnly = showUnreadOnly;
|
m_showUnreadOnly = show_unread_only;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndexList FeedsProxyModel::mapListToSource(const QModelIndexList &indexes) {
|
QModelIndexList FeedsProxyModel::mapListToSource(const QModelIndexList &indexes) {
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,10 @@ class FeedsProxyModel : public QSortFilterProxyModel {
|
||||||
QModelIndexList mapListToSource(const QModelIndexList &indexes);
|
QModelIndexList mapListToSource(const QModelIndexList &indexes);
|
||||||
|
|
||||||
bool showUnreadOnly() const;
|
bool showUnreadOnly() const;
|
||||||
void setShowUnreadOnly(bool showUnreadOnly);
|
void setShowUnreadOnly(bool show_unread_only);
|
||||||
|
|
||||||
FeedsModelRootItem *selectedItem() const;
|
FeedsModelRootItem *selectedItem() const;
|
||||||
void setSelectedItem(FeedsModelRootItem *selectedItem);
|
void setSelectedItem(FeedsModelRootItem *selected_item);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void invalidateFilter();
|
void invalidateFilter();
|
||||||
|
|
|
||||||
|
|
@ -211,24 +211,24 @@ bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) {
|
||||||
|
|
||||||
file.write(part1);
|
file.write(part1);
|
||||||
file.write(part2);
|
file.write(part2);
|
||||||
file.flush();
|
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write(data);
|
file.write(data);
|
||||||
file.flush();
|
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.flush();
|
||||||
|
file.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule *AdBlockSubscription::rule(int offset) const{
|
const AdBlockRule *AdBlockSubscription::rule(int offset) const{
|
||||||
if (!(offset >= 0 && m_rules.size() > offset)) {
|
if (offset >= 0 && m_rules.size() > offset) {
|
||||||
return NULL;
|
return m_rules[offset];
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rules[offset];
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,31 +237,33 @@ QVector<AdBlockRule*> AdBlockSubscription::allRules() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule *AdBlockSubscription::enableRule(int offset) {
|
const AdBlockRule *AdBlockSubscription::enableRule(int offset) {
|
||||||
if (!(offset >= 0 && m_rules.size() > offset)) {
|
if (offset >= 0 && m_rules.size() > offset) {
|
||||||
|
AdBlockRule *rule = m_rules[offset];
|
||||||
|
rule->setEnabled(true);
|
||||||
|
AdBlockManager::instance()->removeDisabledRule(rule->filter());
|
||||||
|
|
||||||
|
emit subscriptionChanged();
|
||||||
|
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockRule *rule = m_rules[offset];
|
|
||||||
rule->setEnabled(true);
|
|
||||||
AdBlockManager::instance()->removeDisabledRule(rule->filter());
|
|
||||||
|
|
||||||
emit subscriptionChanged();
|
|
||||||
|
|
||||||
return rule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule *AdBlockSubscription::disableRule(int offset) {
|
const AdBlockRule *AdBlockSubscription::disableRule(int offset) {
|
||||||
if (!(offset >= 0 && m_rules.size() > offset)) {
|
if (offset >= 0 && m_rules.size() > offset) {
|
||||||
|
AdBlockRule *rule = m_rules[offset];
|
||||||
|
rule->setEnabled(false);
|
||||||
|
AdBlockManager::instance()->addDisabledRule(rule->filter());
|
||||||
|
|
||||||
|
emit subscriptionChanged();
|
||||||
|
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockRule *rule = m_rules[offset];
|
|
||||||
rule->setEnabled(false);
|
|
||||||
AdBlockManager::instance()->addDisabledRule(rule->filter());
|
|
||||||
|
|
||||||
emit subscriptionChanged();
|
|
||||||
|
|
||||||
return rule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockSubscription::canEditRules() const {
|
bool AdBlockSubscription::canEditRules() const {
|
||||||
|
|
@ -314,7 +316,7 @@ void AdBlockCustomList::saveSubscription() {
|
||||||
textStream << "Url: " << url().toString() << endl;
|
textStream << "Url: " << url().toString() << endl;
|
||||||
textStream << "[Adblock Plus 1.1.1]" << endl;
|
textStream << "[Adblock Plus 1.1.1]" << endl;
|
||||||
|
|
||||||
foreach (const AdBlockRule* rule, m_rules) {
|
foreach (const AdBlockRule *rule, m_rules) {
|
||||||
textStream << rule->filter() << endl;
|
textStream << rule->filter() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,30 +362,32 @@ int AdBlockCustomList::addRule(AdBlockRule *rule) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockCustomList::removeRule(int offset) {
|
bool AdBlockCustomList::removeRule(int offset) {
|
||||||
if (!(offset >= 0 && m_rules.size() > offset)) {
|
if (offset >= 0 && m_rules.size() > offset) {
|
||||||
|
AdBlockRule *rule = m_rules.at(offset);
|
||||||
|
const QString filter = rule->filter();
|
||||||
|
|
||||||
|
m_rules.remove(offset);
|
||||||
|
emit subscriptionChanged();
|
||||||
|
|
||||||
|
AdBlockManager::instance()->removeDisabledRule(filter);
|
||||||
|
delete rule;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockRule *rule = m_rules.at(offset);
|
|
||||||
const QString filter = rule->filter();
|
|
||||||
|
|
||||||
m_rules.remove(offset);
|
|
||||||
emit subscriptionChanged();
|
|
||||||
|
|
||||||
AdBlockManager::instance()->removeDisabledRule(filter);
|
|
||||||
delete rule;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule *AdBlockCustomList::replaceRule(AdBlockRule *rule, int offset) {
|
const AdBlockRule *AdBlockCustomList::replaceRule(AdBlockRule *rule, int offset) {
|
||||||
if (!(offset >= 0 && m_rules.size() > offset)) {
|
if (offset >= 0 && m_rules.size() > offset) {
|
||||||
|
AdBlockRule *oldRule = m_rules.at(offset);
|
||||||
|
m_rules[offset] = rule;
|
||||||
|
emit subscriptionChanged();
|
||||||
|
|
||||||
|
delete oldRule;
|
||||||
|
return m_rules[offset];
|
||||||
|
}
|
||||||
|
else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockRule *oldRule = m_rules.at(offset);
|
|
||||||
m_rules[offset] = rule;
|
|
||||||
emit subscriptionChanged();
|
|
||||||
|
|
||||||
delete oldRule;
|
|
||||||
return m_rules[offset];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue