Changeset View
Changeset View
Standalone View
Standalone View
src/selectioncontroller.cpp
Show All 18 Lines | 1 | /* | |||
---|---|---|---|---|---|
19 | 19 | | |||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program | ||
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, | ||
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. | ||
23 | */ | 23 | */ | ||
24 | 24 | | |||
25 | #include "selectioncontroller.h" | 25 | #include "selectioncontroller.h" | ||
26 | 26 | | |||
27 | #include "akregatorconfig.h" | ||||
27 | #include "actionmanager.h" | 28 | #include "actionmanager.h" | ||
28 | #include "article.h" | 29 | #include "article.h" | ||
29 | #include "articlejobs.h" | 30 | #include "articlejobs.h" | ||
30 | #include "articlemodel.h" | 31 | #include "articlemodel.h" | ||
31 | #include "feedlist.h" | 32 | #include "feedlist.h" | ||
32 | #include "subscriptionlistmodel.h" | 33 | #include "subscriptionlistmodel.h" | ||
33 | #include "treenode.h" | 34 | #include "treenode.h" | ||
34 | 35 | | |||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
76 | } // anon namespace | 77 | } // anon namespace | ||
77 | 78 | | |||
78 | Akregator::SelectionController::SelectionController(QObject *parent) | 79 | Akregator::SelectionController::SelectionController(QObject *parent) | ||
79 | : AbstractSelectionController(parent) | 80 | : AbstractSelectionController(parent) | ||
80 | , m_feedList() | 81 | , m_feedList() | ||
81 | , m_feedSelector() | 82 | , m_feedSelector() | ||
82 | , m_articleLister(0) | 83 | , m_articleLister(0) | ||
83 | , m_singleDisplay(0) | 84 | , m_singleDisplay(0) | ||
84 | , m_subscriptionModel(new SubscriptionListModel(QSharedPointer<FeedList>(), this)) | 85 | , m_subscriptionModel(new FilterUnreadProxyModel(this)) | ||
85 | , m_folderExpansionHandler(0) | 86 | , m_folderExpansionHandler(0) | ||
86 | , m_articleModel(0) | 87 | , m_articleModel(0) | ||
87 | , m_selectedSubscription() | 88 | , m_selectedSubscription() | ||
88 | { | 89 | { | ||
90 | m_subscriptionModel->setDoFilter(Settings::hideReadFeeds()); | ||||
91 | m_subscriptionModel->setSourceModel(new SubscriptionListModel(QSharedPointer<FeedList>(), this)); | ||||
89 | } | 92 | } | ||
90 | 93 | | |||
91 | Akregator::SelectionController::~SelectionController() | 94 | Akregator::SelectionController::~SelectionController() | ||
92 | { | 95 | { | ||
93 | delete m_articleModel; | 96 | delete m_articleModel; | ||
94 | } | 97 | } | ||
95 | 98 | | |||
96 | void Akregator::SelectionController::setFeedSelector(QAbstractItemView *feedSelector) | 99 | void Akregator::SelectionController::setFeedSelector(QAbstractItemView *feedSelector) | ||
97 | { | 100 | { | ||
98 | if (m_feedSelector == feedSelector) { | 101 | if (m_feedSelector == feedSelector) { | ||
99 | return; | 102 | return; | ||
100 | } | 103 | } | ||
101 | 104 | | |||
102 | if (m_feedSelector) { | 105 | if (m_feedSelector) { | ||
103 | m_feedSelector->disconnect(this); | 106 | m_feedSelector->disconnect(this); | ||
104 | m_feedSelector->selectionModel()->disconnect(this); | 107 | m_feedSelector->selectionModel()->disconnect(this); | ||
108 | m_feedSelector->selectionModel()->disconnect(m_subscriptionModel); | ||||
105 | } | 109 | } | ||
106 | 110 | | |||
107 | m_feedSelector = feedSelector; | 111 | m_feedSelector = feedSelector; | ||
108 | 112 | | |||
109 | if (!m_feedSelector) { | 113 | if (!m_feedSelector) { | ||
110 | return; | 114 | return; | ||
111 | } | 115 | } | ||
112 | 116 | | |||
113 | m_feedSelector->setModel(m_subscriptionModel); | 117 | m_feedSelector->setModel(m_subscriptionModel); | ||
118 | m_subscriptionModel->clearCache(); | ||||
114 | 119 | | |||
115 | connect(m_feedSelector.data(), &QAbstractItemView::customContextMenuRequested, this, &SelectionController::subscriptionContextMenuRequested); | 120 | connect(m_feedSelector.data(), &QAbstractItemView::customContextMenuRequested, this, &SelectionController::subscriptionContextMenuRequested); | ||
116 | connect(m_feedSelector->selectionModel(), &QItemSelectionModel::currentChanged, this, &SelectionController::selectedSubscriptionChanged); | 121 | connect(m_feedSelector->selectionModel(), &QItemSelectionModel::currentChanged, this, &SelectionController::selectedSubscriptionChanged); | ||
117 | connect(m_feedSelector.data(), &QAbstractItemView::activated, this, &SelectionController::selectedSubscriptionChanged); | 122 | connect(m_feedSelector.data(), &QAbstractItemView::activated, this, &SelectionController::selectedSubscriptionChanged); | ||
123 | connect(m_feedSelector->selectionModel(), &QItemSelectionModel::selectionChanged, m_subscriptionModel, &FilterUnreadProxyModel::selectionChanged); | ||||
118 | } | 124 | } | ||
119 | 125 | | |||
120 | void Akregator::SelectionController::setArticleLister(Akregator::ArticleLister *lister) | 126 | void Akregator::SelectionController::setArticleLister(Akregator::ArticleLister *lister) | ||
121 | { | 127 | { | ||
122 | if (m_articleLister == lister) { | 128 | if (m_articleLister == lister) { | ||
123 | return; | 129 | return; | ||
124 | } | 130 | } | ||
125 | 131 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
170 | 176 | | |||
171 | void Akregator::SelectionController::setFeedList(const QSharedPointer<FeedList> &list) | 177 | void Akregator::SelectionController::setFeedList(const QSharedPointer<FeedList> &list) | ||
172 | { | 178 | { | ||
173 | if (m_feedList == list) { | 179 | if (m_feedList == list) { | ||
174 | return; | 180 | return; | ||
175 | } | 181 | } | ||
176 | 182 | | |||
177 | m_feedList = list; | 183 | m_feedList = list; | ||
178 | std::unique_ptr<SubscriptionListModel> oldModel(m_subscriptionModel); | 184 | SubscriptionListModel *m = qobject_cast<SubscriptionListModel*>(m_subscriptionModel->sourceModel()); | ||
179 | m_subscriptionModel = new SubscriptionListModel(m_feedList, this); | 185 | std::unique_ptr<SubscriptionListModel> oldModel(m); | ||
186 | m_subscriptionModel->setSourceModel(new SubscriptionListModel(m_feedList, this)); | ||||
180 | 187 | | |||
181 | if (m_folderExpansionHandler) { | 188 | if (m_folderExpansionHandler) { | ||
182 | m_folderExpansionHandler->setFeedList(m_feedList); | 189 | m_folderExpansionHandler->setFeedList(m_feedList); | ||
183 | m_folderExpansionHandler->setModel(m_subscriptionModel); | 190 | m_folderExpansionHandler->setModel(m_subscriptionModel); | ||
184 | } | 191 | } | ||
185 | 192 | | |||
186 | if (m_feedSelector) { | 193 | if (m_feedSelector) { | ||
187 | if (m_feedList) { | 194 | if (m_feedList) { | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | |||||
299 | } | 306 | } | ||
300 | 307 | | |||
301 | void Akregator::SelectionController::articleIndexDoubleClicked(const QModelIndex &index) | 308 | void Akregator::SelectionController::articleIndexDoubleClicked(const QModelIndex &index) | ||
302 | { | 309 | { | ||
303 | const Akregator::Article article = ::articleForIndex(index, m_feedList.data()); | 310 | const Akregator::Article article = ::articleForIndex(index, m_feedList.data()); | ||
304 | Q_EMIT articleDoubleClicked(article); | 311 | Q_EMIT articleDoubleClicked(article); | ||
305 | } | 312 | } | ||
306 | 313 | | |||
314 | /** | ||||
315 | * Called when the applications settings are changed; sets whether we apply a the filter or not. | ||||
316 | */ | ||||
317 | void Akregator::SelectionController::settingsChanged() | ||||
318 | { | ||||
319 | m_subscriptionModel->setDoFilter(Settings::hideReadFeeds()); | ||||
320 | } | ||||
321 | | ||||
307 | void SelectionController::setFilters(const std::vector<QSharedPointer<const Filters::AbstractMatcher> > &matchers) | 322 | void SelectionController::setFilters(const std::vector<QSharedPointer<const Filters::AbstractMatcher> > &matchers) | ||
308 | { | 323 | { | ||
309 | Q_ASSERT(m_articleLister); | 324 | Q_ASSERT(m_articleLister); | ||
310 | m_articleLister->setFilters(matchers); | 325 | m_articleLister->setFilters(matchers); | ||
311 | } | 326 | } | ||
312 | 327 | | |||
313 | void SelectionController::forceFilterUpdate() | 328 | void SelectionController::forceFilterUpdate() | ||
314 | { | 329 | { | ||
315 | Q_ASSERT(m_articleLister); | 330 | Q_ASSERT(m_articleLister); | ||
316 | m_articleLister->forceFilterUpdate(); | 331 | m_articleLister->forceFilterUpdate(); | ||
317 | } | 332 | } |