Fixed selected feeds for message viewing + some methods moved to feedsview/model."

This commit is contained in:
Martin Rotter 2013-12-26 15:15:28 +01:00
parent 2fdd613805
commit 3735267e31
12 changed files with 66 additions and 44 deletions

View file

@ -21,7 +21,8 @@ void FeedDownloader::updateFeeds(const QList<FeedsModelFeed *> &feeds) {
for (int i = 0, total = feeds.size(); i < total; i++) { for (int i = 0, total = feeds.size(); i < total; i++) {
feeds.at(i)->update(); feeds.at(i)->update();
qDebug("Made progress in feed updates: %d/%d.", i + 1, total); qDebug("Made progress in feed updates: %d/%d (id of feed is %d).",
i + 1, total, feeds.at(i)->id());
emit progress(feeds.at(i), i + 1, total); emit progress(feeds.at(i), i + 1, total);
} }

View file

@ -282,13 +282,32 @@ QList<FeedsModelFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
return getFeeds(item); return getFeeds(item);
} }
bool FeedsModel::isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs) {
return !isEqual(lhs, rhs);
}
bool FeedsModel::isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs) {
return lhs->id() == rhs->id();
}
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
QList<FeedsModelFeed*> feeds; QList<FeedsModelFeed*> feeds;
// Get selected feeds for each index.
foreach (const QModelIndex &index, indexes) { foreach (const QModelIndex &index, indexes) {
feeds.append(feedsForIndex(index)); feeds.append(feedsForIndex(index));
} }
// Now we obtained all feeds from corresponding indexes.
if (indexes.size() != feeds.size()) {
// Selection contains duplicate feeds (for
// example situation where feed and its parent category are both
// selected). So, remove duplicates from the list.
qSort(feeds.begin(), feeds.end(), isUnequal);
feeds.erase(std::unique(feeds.begin(), feeds.end(), isEqual),
feeds.end());
}
return feeds; return feeds;
} }

View file

@ -54,6 +54,9 @@ class FeedsModel : public QAbstractItemModel {
// Returns feeds contained within single index. // Returns feeds contained within single index.
QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index); QList<FeedsModelFeed*> feedsForIndex(const QModelIndex &index);
static bool isUnequal(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
static bool isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
public slots: public slots:
// Signals that properties (probably counts) // Signals that properties (probably counts)
// of ALL items have changed. // of ALL items have changed.

View file

@ -151,6 +151,8 @@ void FeedsModelStandardFeed::update() {
"download_timeout", "download_timeout",
5000).toInt(); 5000).toInt();
// TODO: Provide download time-measures debugging
// outputs here.
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(), QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(),
download_timeout, download_timeout,
feed_contents); feed_contents);

View file

@ -18,6 +18,7 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item = NULL); explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item = NULL);
virtual ~FeedsModelStandardFeed(); virtual ~FeedsModelStandardFeed();
// Obtains data related to this feed.
QVariant data(int column, int role) const; QVariant data(int column, int role) const;
// Perform fetching of new messages. // Perform fetching of new messages.

View file

@ -60,13 +60,17 @@ QList<int> MessagesModel::currentFeeds() const {
} }
void MessagesModel::loadMessages(const QList<int> feed_ids) { void MessagesModel::loadMessages(const QList<int> feed_ids) {
// Conversion of parameter. // Conversion of parameter.
m_currentFeeds = feed_ids; m_currentFeeds = feed_ids;
setFilter(QString("feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", "))); QString assembled_ids = textualFeeds().join(", ");
setFilter(QString("feed IN (%1) AND deleted = 0").arg(assembled_ids));
select(); select();
fetchAll(); fetchAll();
qDebug("Loading messages from feeds: %s.", qPrintable(assembled_ids));
} }
QStringList MessagesModel::textualFeeds() const { QStringList MessagesModel::textualFeeds() const {

View file

@ -18,7 +18,10 @@ QList<Message> ParsingFactory::parseAsRSS20(const QString &data) {
QList<Message> messages; QList<Message> messages;
QDomDocument xml_file; QDomDocument xml_file;
QDateTime current_time = QDateTime::currentDateTime(); QDateTime current_time = QDateTime::currentDateTime();
xml_file.setContent(data, true); xml_file.setContent(data, true);
// Pull out all messages.
QDomNodeList messages_in_xml = xml_file.elementsByTagName("item"); QDomNodeList messages_in_xml = xml_file.elementsByTagName("item");
for (int i = 0; i < messages_in_xml.size(); i++) { for (int i = 0; i < messages_in_xml.size(); i++) {

View file

@ -105,14 +105,22 @@ void FeedMessageViewer::updateSelectedFeeds() {
} }
} }
void FeedMessageViewer::updateAllFeeds() {
if (SystemFactory::getInstance()->applicationCloseLock()->tryLockForRead()) {
emit feedsUpdateRequested(m_feedsView->allFeeds());
}
else {
qDebug("Lock for feed updates was NOT obtained.");
}
}
void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed, void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed,
int current, int current,
int total) { int total) {
// Some feed got updated. // Some feed got updated.
// Now we should change some widgets (reload counts // TODO: Now we should change some widgets (reload counts
// of messages for the feed, update status bar and so on). // of messages for the feed, update status bar and so on).
// TODO: Don't update counts of all feeds here, // TODO: Don't update counts of all feeds here,
// it is enough to update counts of update feed. // it is enough to update counts of update feed.
m_feedsView->updateCountsOfAllFeeds(true); m_feedsView->updateCountsOfAllFeeds(true);
@ -165,14 +173,16 @@ void FeedMessageViewer::createConnections() {
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesInternally())); SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesInternally()));
connect(FormMain::getInstance()->m_ui->m_actionOpenSelectedMessagesInternally, connect(FormMain::getInstance()->m_ui->m_actionOpenSelectedMessagesInternally,
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally())); SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally()));
connect(FormMain::getInstance()->m_ui->m_actionMarkAllMessagesAsRead, connect(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsRead,
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesRead())); SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesRead()));
connect(FormMain::getInstance()->m_ui->m_actionMarkAllMessagesAsUnread, connect(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread,
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesUnread())); SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesUnread()));
connect(FormMain::getInstance()->m_ui->m_actionDeleteAllMessages, connect(FormMain::getInstance()->m_ui->m_actionDeleteAllMessages,
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesDeleted())); SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesDeleted()));
connect(FormMain::getInstance()->m_ui->m_actionUpdateSelectedFeeds, connect(FormMain::getInstance()->m_ui->m_actionUpdateSelectedFeeds,
SIGNAL(triggered()), this, SLOT(updateSelectedFeeds())); SIGNAL(triggered()), this, SLOT(updateSelectedFeeds()));
connect(FormMain::getInstance()->m_ui->m_actionUpdateAllFeeds,
SIGNAL(triggered()), this, SLOT(updateAllFeeds()));
} }
void FeedMessageViewer::initialize() { void FeedMessageViewer::initialize() {
@ -188,9 +198,9 @@ void FeedMessageViewer::initialize() {
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionAddNewFeed); m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionAddNewFeed);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionEditSelectedFeed); m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionEditSelectedFeed);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionDeleteSelectedFeeds); m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionDeleteSelectedFeeds);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsRead);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread);
m_toolBar->addSeparator(); m_toolBar->addSeparator();
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionMarkAllMessagesAsRead);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionMarkAllMessagesAsUnread);
m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionDeleteAllMessages); m_toolBar->addAction(FormMain::getInstance()->m_ui->m_actionDeleteAllMessages);
// Finish web/message browser setup. // Finish web/message browser setup.

View file

@ -34,6 +34,7 @@ class FeedMessageViewer : public TabContent {
public slots: public slots:
void updateSelectedFeeds(); void updateSelectedFeeds();
void updateAllFeeds();
protected slots: protected slots:
void onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total); void onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total);

View file

@ -81,8 +81,8 @@ QList<QAction*> FormMain::getActions() {
actions << m_ui->m_actionOpenSelectedSourceArticlesExternally << actions << m_ui->m_actionOpenSelectedSourceArticlesExternally <<
m_ui->m_actionOpenSelectedSourceArticlesInternally << m_ui->m_actionOpenSelectedSourceArticlesInternally <<
m_ui->m_actionOpenSelectedMessagesInternally << m_ui->m_actionOpenSelectedMessagesInternally <<
m_ui->m_actionMarkAllMessagesAsRead << m_ui->m_actionMarkFeedsAsRead <<
m_ui->m_actionMarkAllMessagesAsUnread << m_ui->m_actionMarkFeedsAsUnread <<
m_ui->m_actionDeleteAllMessages << m_ui->m_actionDeleteAllMessages <<
m_ui->m_actionMarkSelectedMessagesAsRead << m_ui->m_actionMarkSelectedMessagesAsRead <<
m_ui->m_actionMarkSelectedMessagesAsUnread << m_ui->m_actionMarkSelectedMessagesAsUnread <<
@ -225,8 +225,8 @@ void FormMain::setupIcons() {
m_ui->m_actionAddNewCategory->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); m_ui->m_actionAddNewCategory->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new")); m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("document-new"));
m_ui->m_actionEditSelectedFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("gnome-other")); m_ui->m_actionEditSelectedFeed->setIcon(IconThemeFactory::getInstance()->fromTheme("gnome-other"));
m_ui->m_actionMarkAllMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk")); m_ui->m_actionMarkFeedsAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk"));
m_ui->m_actionMarkAllMessagesAsUnread->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-important")); m_ui->m_actionMarkFeedsAsUnread->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-important"));
m_ui->m_actionMarkFeedsAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk")); m_ui->m_actionMarkFeedsAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk"));
m_ui->m_actionMarkSelectedMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk")); m_ui->m_actionMarkSelectedMessagesAsRead->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-not-junk"));
m_ui->m_actionMarkSelectedMessagesAsUnread->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-important")); m_ui->m_actionMarkSelectedMessagesAsUnread->setIcon(IconThemeFactory::getInstance()->fromTheme("mail-mark-important"));

View file

@ -15,16 +15,7 @@
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -48,7 +39,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>979</width> <width>979</width>
<height>19</height> <height>20</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="m_menuFile"> <widget class="QMenu" name="m_menuFile">
@ -106,6 +97,7 @@
<addaction name="m_actionDeleteSelectedFeeds"/> <addaction name="m_actionDeleteSelectedFeeds"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="m_actionMarkFeedsAsRead"/> <addaction name="m_actionMarkFeedsAsRead"/>
<addaction name="m_actionMarkFeedsAsUnread"/>
</widget> </widget>
<widget class="QMenu" name="m_menuMessages"> <widget class="QMenu" name="m_menuMessages">
<property name="title"> <property name="title">
@ -113,8 +105,6 @@
</property> </property>
<addaction name="m_actionMarkSelectedMessagesAsRead"/> <addaction name="m_actionMarkSelectedMessagesAsRead"/>
<addaction name="m_actionMarkSelectedMessagesAsUnread"/> <addaction name="m_actionMarkSelectedMessagesAsUnread"/>
<addaction name="m_actionMarkAllMessagesAsRead"/>
<addaction name="m_actionMarkAllMessagesAsUnread"/>
<addaction name="m_actionSwitchImportanceOfSelectedMessages"/> <addaction name="m_actionSwitchImportanceOfSelectedMessages"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="m_actionDeleteSelectedMessages"/> <addaction name="m_actionDeleteSelectedMessages"/>
@ -324,29 +314,18 @@
</action> </action>
<action name="m_actionMarkFeedsAsRead"> <action name="m_actionMarkFeedsAsRead">
<property name="text"> <property name="text">
<string>Mark selected feed(s)/category(ies) as read</string> <string>Mark &amp;selected feed(s) read</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Mark selected feed(s)/category(ies) as read.</string> <string>Marks all messages (without message filters) from selected feeds as read.</string>
</property>
<property name="shortcut">
<string notr="true"/>
</property> </property>
</action> </action>
<action name="m_actionMarkAllMessagesAsRead"> <action name="m_actionMarkFeedsAsUnread">
<property name="text"> <property name="text">
<string>Mark &amp;all messages read</string> <string>Mark selected feeds unread</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Mark all messages from selected feeds read. This does NOT take message filters into account.</string> <string>Marks all messages (without message filters) from selected feeds as unread.</string>
</property>
</action>
<action name="m_actionMarkAllMessagesAsUnread">
<property name="text">
<string>Mark a&amp;ll messages unread</string>
</property>
<property name="toolTip">
<string>Mark all messages from selected feeds unread. This does NOT take message filters into account.</string>
</property> </property>
</action> </action>
<action name="m_actionDeleteSelectedMessages"> <action name="m_actionDeleteSelectedMessages">

View file

@ -20,7 +20,6 @@ MessagesView::MessagesView(QWidget *parent)
// Forward count changes to the view. // Forward count changes to the view.
createConnections(); createConnections();
setModel(m_proxyModel); setModel(m_proxyModel);
setupAppearance(); setupAppearance();
} }
@ -113,7 +112,7 @@ void MessagesView::setupAppearance() {
// Make sure that initial sorting is that unread messages are visible // Make sure that initial sorting is that unread messages are visible
// first. // first.
// NOTE: This can be rewritten so that it's changeable. // NOTE: This can be rewritten so that it's changeable.
sortByColumn(MSG_DB_DCREATED_INDEX, Qt::AscendingOrder); sortByColumn(MSG_DB_DCREATED_INDEX, Qt::DescendingOrder);
} }
void MessagesView::keyPressEvent(QKeyEvent *event) { void MessagesView::keyPressEvent(QKeyEvent *event) {