New API for feeds operations.
This commit is contained in:
parent
2eda5f58a5
commit
d78ff65044
@ -196,6 +196,17 @@ void FeedsModel::reloadChangedLayout(QModelIndexList list) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList FeedsModel::textualFeedIds(const QList<FeedsModelFeed*> &feeds) {
|
||||||
|
QStringList stringy_ids;
|
||||||
|
stringy_ids.reserve(feeds.size());
|
||||||
|
|
||||||
|
foreach (FeedsModelFeed *feed, feeds) {
|
||||||
|
stringy_ids.append(QString::number(feed->id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringy_ids;
|
||||||
|
}
|
||||||
|
|
||||||
void FeedsModel::reloadWholeLayout() {
|
void FeedsModel::reloadWholeLayout() {
|
||||||
// NOTE: Take a look at docs about this.
|
// NOTE: Take a look at docs about this.
|
||||||
// I have tested that this is LITTLE slower than code above,
|
// I have tested that this is LITTLE slower than code above,
|
||||||
@ -291,6 +302,75 @@ bool FeedsModel::isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs) {
|
|||||||
return lhs->id() == rhs->id();
|
return lhs->id() == rhs->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
|
||||||
|
int read) {
|
||||||
|
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName());
|
||||||
|
|
||||||
|
if (!db_handle.transaction()) {
|
||||||
|
qWarning("Starting transaction for feeds read change.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query_read_msg(db_handle);
|
||||||
|
if (!query_read_msg.prepare(QString("UPDATE messages SET read = :read "
|
||||||
|
"WHERE feed IN (%1) AND deleted = 0").arg(textualFeedIds(feeds).join(", ")))) {
|
||||||
|
qWarning("Query preparation failed for feeds read change.");
|
||||||
|
|
||||||
|
db_handle.rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
query_read_msg.bindValue(":read", read);
|
||||||
|
|
||||||
|
if (!query_read_msg.exec()) {
|
||||||
|
qDebug("Query execution for feeds read change failed.");
|
||||||
|
db_handle.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit changes.
|
||||||
|
if (db_handle.commit()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return db_handle.rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds,
|
||||||
|
int deleted) {
|
||||||
|
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName());
|
||||||
|
|
||||||
|
if (!db_handle.transaction()) {
|
||||||
|
qWarning("Starting transaction for feeds clearing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query_delete_msg(db_handle);
|
||||||
|
if (!query_delete_msg.prepare(QString("UPDATE messages SET deleted = :deleted "
|
||||||
|
"WHERE feed IN (%1) AND deleted = 0").arg(textualFeedIds(feeds).join(", ")))) {
|
||||||
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
|
|
||||||
|
db_handle.rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
query_delete_msg.bindValue(":deleted", deleted);
|
||||||
|
|
||||||
|
if (!query_delete_msg.exec()) {
|
||||||
|
qDebug("Query execution for feeds clearing failed.");
|
||||||
|
db_handle.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit changes.
|
||||||
|
if (db_handle.commit()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return db_handle.rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||||
QList<FeedsModelFeed*> feeds;
|
QList<FeedsModelFeed*> feeds;
|
||||||
|
|
||||||
|
@ -59,6 +59,9 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
static bool isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
|
static bool isEqual(FeedsModelFeed *lhs, FeedsModelFeed *rhs);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
bool markFeedsRead(const QList<FeedsModelFeed*> &feeds, int read);
|
||||||
|
bool markFeedsDeleted(const QList<FeedsModelFeed*> &feeds, int deleted);
|
||||||
|
|
||||||
// Signals that properties (probably counts)
|
// Signals that properties (probably counts)
|
||||||
// of ALL items have changed.
|
// of ALL items have changed.
|
||||||
void reloadWholeLayout();
|
void reloadWholeLayout();
|
||||||
@ -68,6 +71,8 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
void reloadChangedLayout(QModelIndexList list);
|
void reloadChangedLayout(QModelIndexList list);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QStringList textualFeedIds(const QList<FeedsModelFeed*> &feeds);
|
||||||
|
|
||||||
// Returns feed/category which lies at the specified index or
|
// Returns feed/category which lies at the specified index or
|
||||||
// null if index is invalid.
|
// null if index is invalid.
|
||||||
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
|
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
|
||||||
|
@ -147,6 +147,8 @@ void FeedMessageViewer::createConnections() {
|
|||||||
m_messagesView, SLOT(loadFeeds(QList<int>)));
|
m_messagesView, SLOT(loadFeeds(QList<int>)));
|
||||||
connect(m_messagesView, SIGNAL(feedCountsChanged()),
|
connect(m_messagesView, SIGNAL(feedCountsChanged()),
|
||||||
m_feedsView, SLOT(updateCountsOfSelectedFeeds()));
|
m_feedsView, SLOT(updateCountsOfSelectedFeeds()));
|
||||||
|
connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(int)),
|
||||||
|
m_messagesView, SLOT(reloadSelections(int)));
|
||||||
|
|
||||||
// Downloader connections.
|
// Downloader connections.
|
||||||
connect(m_feedDownloaderThread, SIGNAL(finished()),
|
connect(m_feedDownloaderThread, SIGNAL(finished()),
|
||||||
@ -174,11 +176,11 @@ void FeedMessageViewer::createConnections() {
|
|||||||
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_actionMarkFeedsAsRead,
|
connect(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsRead,
|
||||||
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesRead()));
|
SIGNAL(triggered()), m_feedsView, SLOT(markSelectedFeedsRead()));
|
||||||
connect(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread,
|
connect(FormMain::getInstance()->m_ui->m_actionMarkFeedsAsUnread,
|
||||||
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesUnread()));
|
SIGNAL(triggered()), m_feedsView, SLOT(markSelectedFeedsUnread()));
|
||||||
connect(FormMain::getInstance()->m_ui->m_actionClearFeeds,
|
connect(FormMain::getInstance()->m_ui->m_actionClearFeeds,
|
||||||
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesDeleted()));
|
SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds()));
|
||||||
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,
|
connect(FormMain::getInstance()->m_ui->m_actionUpdateAllFeeds,
|
||||||
|
@ -38,6 +38,32 @@ QList<FeedsModelFeed *> FeedsView::allFeeds() const {
|
|||||||
return m_sourceModel->getAllFeeds();
|
return m_sourceModel->getAllFeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FeedsView::setSelectedFeedsClearStatus(int clear) {
|
||||||
|
m_sourceModel->markFeedsDeleted(selectedFeeds(), clear);
|
||||||
|
updateCountsOfSelectedFeeds();
|
||||||
|
|
||||||
|
emit feedsNeedToBeReloaded(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeedsView::clearSelectedFeeds() {
|
||||||
|
setSelectedFeedsClearStatus(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||||
|
m_sourceModel->markFeedsRead(selectedFeeds(), read);
|
||||||
|
updateCountsOfSelectedFeeds(false);
|
||||||
|
|
||||||
|
emit feedsNeedToBeReloaded(read);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeedsView::markSelectedFeedsRead() {
|
||||||
|
markSelectedFeedsReadStatus(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeedsView::markSelectedFeedsUnread() {
|
||||||
|
markSelectedFeedsReadStatus(0);
|
||||||
|
}
|
||||||
|
|
||||||
void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
|
void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
|
||||||
foreach (FeedsModelFeed *feed, selectedFeeds()) {
|
foreach (FeedsModelFeed *feed, selectedFeeds()) {
|
||||||
feed->updateCounts(update_total_too);
|
feed->updateCounts(update_total_too);
|
||||||
|
@ -24,6 +24,15 @@ class FeedsView : public QTreeView {
|
|||||||
QList<FeedsModelFeed*> allFeeds() const;
|
QList<FeedsModelFeed*> allFeeds() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Feed read/unread manipulators.
|
||||||
|
void markSelectedFeedsReadStatus(int read);
|
||||||
|
void markSelectedFeedsRead();
|
||||||
|
void markSelectedFeedsUnread();
|
||||||
|
|
||||||
|
// Feed clearers.
|
||||||
|
void setSelectedFeedsClearStatus(int clear);
|
||||||
|
void clearSelectedFeeds();
|
||||||
|
|
||||||
// Reloads counts for selected feeds.
|
// Reloads counts for selected feeds.
|
||||||
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
||||||
|
|
||||||
@ -38,6 +47,7 @@ class FeedsView : public QTreeView {
|
|||||||
const QItemSelection &deselected);
|
const QItemSelection &deselected);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void feedsNeedToBeReloaded(int mark_current_index_read);
|
||||||
void feedsSelected(const QList<int> &feed_ids);
|
void feedsSelected(const QList<int> &feed_ids);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -46,6 +46,37 @@ void MessagesView::createConnections() {
|
|||||||
this, SLOT(adjustColumns()));
|
this, SLOT(adjustColumns()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesView::reloadSelections(int mark_current_index_read) {
|
||||||
|
QModelIndex current_index = selectionModel()->currentIndex();
|
||||||
|
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
|
||||||
|
QModelIndexList selected_indexes = selectionModel()->selectedRows();
|
||||||
|
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
|
||||||
|
|
||||||
|
// Reload the model now.
|
||||||
|
m_sourceModel->select();
|
||||||
|
m_sourceModel->fetchAll();
|
||||||
|
|
||||||
|
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
|
||||||
|
|
||||||
|
selected_indexes = m_proxyModel->mapListFromSource(mapped_indexes, true);
|
||||||
|
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(),
|
||||||
|
mapped_current_index.column()));
|
||||||
|
|
||||||
|
if (mark_current_index_read == 0) {
|
||||||
|
// User selected to mark some messages as unread, if one
|
||||||
|
// of them will be marked as current, then it will be read again.
|
||||||
|
m_batchUnreadSwitch = true;
|
||||||
|
setCurrentIndex(current_index);
|
||||||
|
m_batchUnreadSwitch = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setCurrentIndex(current_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollTo(current_index);
|
||||||
|
reselectIndexes(selected_indexes);
|
||||||
|
}
|
||||||
|
|
||||||
MessagesModel *MessagesView::sourceModel() {
|
MessagesModel *MessagesView::sourceModel() {
|
||||||
return m_sourceModel;
|
return m_sourceModel;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,12 @@ class MessagesView : public QTreeView {
|
|||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
// Called after data got changed externally
|
||||||
|
// and it needs to be reloaded to the view.
|
||||||
|
// If "mark_current_index_read" is 0, then message with
|
||||||
|
// "current" index is not marked as read.
|
||||||
|
void reloadSelections(int mark_current_index_read);
|
||||||
|
|
||||||
// Loads un-deleted messages from selected feeds.
|
// Loads un-deleted messages from selected feeds.
|
||||||
void loadFeeds(const QList<int> &feed_ids);
|
void loadFeeds(const QList<int> &feed_ids);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user