Added initial starred status switching.
This commit is contained in:
parent
c8d4819270
commit
7bfbdca4e9
@ -301,11 +301,11 @@ bool MessagesModel::switchMessageImportance(int row_index) {
|
|||||||
RootItem::Importance current_importance = (RootItem::Importance) data(target_index, Qt::EditRole).toInt();
|
RootItem::Importance current_importance = (RootItem::Importance) data(target_index, Qt::EditRole).toInt();
|
||||||
RootItem::Importance next_importance = current_importance == RootItem::Important ?
|
RootItem::Importance next_importance = current_importance == RootItem::Important ?
|
||||||
RootItem::NotImportant : RootItem::Important;
|
RootItem::NotImportant : RootItem::Important;
|
||||||
int message_id = messageId(row_index);
|
Message message = messageAt(row_index);
|
||||||
QPair<int,RootItem::Importance> pair(message_id, next_importance);
|
QPair<Message,RootItem::Importance> pair(message, next_importance);
|
||||||
|
|
||||||
if (!m_selectedItem->getParentServiceRoot()->onBeforeSwitchMessageImportance(m_selectedItem,
|
if (!m_selectedItem->getParentServiceRoot()->onBeforeSwitchMessageImportance(m_selectedItem,
|
||||||
QList<QPair<int,RootItem::Importance> >() << pair)) {
|
QList<QPair<Message,RootItem::Importance> >() << pair)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,14 +326,14 @@ bool MessagesModel::switchMessageImportance(int row_index) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
query_importance_msg.bindValue(QSL(":id"), message_id);
|
query_importance_msg.bindValue(QSL(":id"), message.m_id);
|
||||||
query_importance_msg.bindValue(QSL(":important"), (int) next_importance);
|
query_importance_msg.bindValue(QSL(":important"), (int) next_importance);
|
||||||
|
|
||||||
|
|
||||||
// Commit changes.
|
// Commit changes.
|
||||||
if (query_importance_msg.exec()) {
|
if (query_importance_msg.exec()) {
|
||||||
return m_selectedItem->getParentServiceRoot()->onAfterSwitchMessageImportance(m_selectedItem,
|
return m_selectedItem->getParentServiceRoot()->onAfterSwitchMessageImportance(m_selectedItem,
|
||||||
QList<QPair<int,RootItem::Importance> >() << pair);
|
QList<QPair<Message,RootItem::Importance> >() << pair);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
@ -343,17 +343,17 @@ bool MessagesModel::switchMessageImportance(int row_index) {
|
|||||||
bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages) {
|
bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages) {
|
||||||
QSqlQuery query_read_msg(database());
|
QSqlQuery query_read_msg(database());
|
||||||
QStringList message_ids;
|
QStringList message_ids;
|
||||||
QList<QPair<int,RootItem::Importance> > message_states;
|
QList<QPair<Message,RootItem::Importance> > message_states;
|
||||||
|
|
||||||
query_read_msg.setForwardOnly(true);
|
query_read_msg.setForwardOnly(true);
|
||||||
|
|
||||||
// Obtain IDs of all desired messages.
|
// Obtain IDs of all desired messages.
|
||||||
foreach (const QModelIndex &message, messages) {
|
foreach (const QModelIndex &message, messages) {
|
||||||
int message_id = messageId(message.row());
|
Message msg = messageAt(message.row());
|
||||||
RootItem::Importance message_importance = messageImportance((message.row()));
|
RootItem::Importance message_importance = messageImportance((message.row()));
|
||||||
|
|
||||||
message_states.append(QPair<int,RootItem::Importance>(message_id, message_importance));
|
message_states.append(QPair<Message,RootItem::Importance>(msg, message_importance));
|
||||||
message_ids.append(QString::number(message_id));
|
message_ids.append(QString::number(msg.m_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_selectedItem->getParentServiceRoot()->onBeforeSwitchMessageImportance(m_selectedItem, message_states)) {
|
if (!m_selectedItem->getParentServiceRoot()->onBeforeSwitchMessageImportance(m_selectedItem, message_states)) {
|
||||||
|
@ -109,7 +109,7 @@ class ServiceRoot : public RootItem {
|
|||||||
// some ONLINE service or something.
|
// some ONLINE service or something.
|
||||||
//
|
//
|
||||||
// "changes" - list of pairs - <message (integer id), new status>
|
// "changes" - list of pairs - <message (integer id), new status>
|
||||||
virtual bool onBeforeSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes) = 0;
|
virtual bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes) = 0;
|
||||||
|
|
||||||
// Called AFTER this importance switch update is stored in DB,
|
// Called AFTER this importance switch update is stored in DB,
|
||||||
// when false is returned, change is aborted.
|
// when false is returned, change is aborted.
|
||||||
@ -117,7 +117,7 @@ class ServiceRoot : public RootItem {
|
|||||||
// which items are actually changed.
|
// which items are actually changed.
|
||||||
//
|
//
|
||||||
// "changes" - list of pairs - <message (integer id), new status>
|
// "changes" - list of pairs - <message (integer id), new status>
|
||||||
virtual bool onAfterSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes) = 0;
|
virtual bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes) = 0;
|
||||||
|
|
||||||
// Called BEFORE the list of messages is about to be deleted
|
// Called BEFORE the list of messages is about to be deleted
|
||||||
// by the user from message list.
|
// by the user from message list.
|
||||||
|
@ -524,7 +524,7 @@ bool StandardServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool StandardServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
|
bool StandardServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
|
||||||
QList<QPair<int,RootItem::Importance> > changes) {
|
const QList<QPair<Message,Importance> > &changes) {
|
||||||
Q_UNUSED(selected_item)
|
Q_UNUSED(selected_item)
|
||||||
Q_UNUSED(changes)
|
Q_UNUSED(changes)
|
||||||
|
|
||||||
@ -532,7 +532,7 @@ bool StandardServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_ite
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool StandardServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item,
|
bool StandardServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item,
|
||||||
QList<QPair<int,RootItem::Importance> > changes) {
|
const QList<QPair<Message,Importance> > &changes) {
|
||||||
Q_UNUSED(selected_item)
|
Q_UNUSED(selected_item)
|
||||||
Q_UNUSED(changes)
|
Q_UNUSED(changes)
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ class StandardServiceRoot : public ServiceRoot {
|
|||||||
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||||
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||||
|
|
||||||
bool onBeforeSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes);
|
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
|
||||||
bool onAfterSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes);
|
bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
|
||||||
|
|
||||||
bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||||
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||||
|
@ -171,14 +171,14 @@ TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, bool fo
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QList<int> &ids,
|
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList &ids,
|
||||||
UpdateArticle::OperatingField field,
|
UpdateArticle::OperatingField field,
|
||||||
UpdateArticle::Mode mode,
|
UpdateArticle::Mode mode,
|
||||||
QNetworkReply::NetworkError &error) {
|
QNetworkReply::NetworkError &error) {
|
||||||
QtJson::JsonObject json;
|
QtJson::JsonObject json;
|
||||||
json["op"] = "updateArticle";
|
json["op"] = "updateArticle";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["article_ids"] = encodeArticleIds(ids);
|
json["article_ids"] = ids.join(QL1C(','));
|
||||||
json["mode"] = (int) mode;
|
json["mode"] = (int) mode;
|
||||||
json["field"] = (int) field;
|
json["field"] = (int) field;
|
||||||
|
|
||||||
@ -199,16 +199,6 @@ TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QList<int>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssNetworkFactory::encodeArticleIds(const QList<int> &ids) {
|
|
||||||
QStringList strings;
|
|
||||||
|
|
||||||
foreach (int id, ids) {
|
|
||||||
strings.append(QString::number(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.join(QL1C(','));
|
|
||||||
}
|
|
||||||
|
|
||||||
TtRssResponse::TtRssResponse(const QString &raw_content) {
|
TtRssResponse::TtRssResponse(const QString &raw_content) {
|
||||||
m_rawContent = QtJson::parse(raw_content).toMap();
|
m_rawContent = QtJson::parse(raw_content).toMap();
|
||||||
}
|
}
|
||||||
|
@ -130,12 +130,10 @@ class TtRssNetworkFactory {
|
|||||||
bool show_content, bool include_attachments,
|
bool show_content, bool include_attachments,
|
||||||
bool sanitize, QNetworkReply::NetworkError &error);
|
bool sanitize, QNetworkReply::NetworkError &error);
|
||||||
|
|
||||||
TtRssUpdateArticleResponse updateArticles(const QList<int> &ids, UpdateArticle::OperatingField field,
|
TtRssUpdateArticleResponse updateArticles(const QStringList &ids, UpdateArticle::OperatingField field,
|
||||||
UpdateArticle::Mode mode, QNetworkReply::NetworkError &error);
|
UpdateArticle::Mode mode, QNetworkReply::NetworkError &error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString encodeArticleIds(const QList<int> &ids);
|
|
||||||
|
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_username;
|
QString m_username;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
|
@ -174,12 +174,32 @@ bool TtRssServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const QLi
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, QList<QPair<int, RootItem::Importance> > changes) {
|
bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,Importance> > &changes) {
|
||||||
return false;
|
Q_UNUSED(selected_item)
|
||||||
|
|
||||||
|
QNetworkReply::NetworkError error;
|
||||||
|
|
||||||
|
// NOTE: We just toggle it here, because we know, that there is only
|
||||||
|
// toggling of starred status supported by RSS Guard right now and
|
||||||
|
// Tiny Tiny RSS API allows it, which is greate.
|
||||||
|
TtRssUpdateArticleResponse response = m_network->updateArticles(customIDsOfMessages(changes),
|
||||||
|
UpdateArticle::Starred,
|
||||||
|
UpdateArticle::Togggle,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (error == QNetworkReply::NoError && response.updateStatus() == STATUS_OK && response.articlesUpdated() == changes.size()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item, QList<QPair<int, RootItem::Importance> > changes) {
|
bool TtRssServiceRoot::onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,Importance> > &changes) {
|
||||||
return false;
|
Q_UNUSED(selected_item)
|
||||||
|
Q_UNUSED(changes)
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids) {
|
bool TtRssServiceRoot::onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids) {
|
||||||
@ -345,11 +365,21 @@ void TtRssServiceRoot::syncIn() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> TtRssServiceRoot::customIDsOfMessages(const QList<Message> &messages) {
|
QStringList TtRssServiceRoot::customIDsOfMessages(const QList<QPair<Message,RootItem::Importance> > &changes) {
|
||||||
QList<int> list;
|
QStringList list;
|
||||||
|
|
||||||
|
for (int i = 0; i < changes.size(); i++) {
|
||||||
|
list.append(changes.at(i).first.m_customId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TtRssServiceRoot::customIDsOfMessages(const QList<Message> &messages) {
|
||||||
|
QStringList list;
|
||||||
|
|
||||||
foreach (const Message &message, messages) {
|
foreach (const Message &message, messages) {
|
||||||
list.append(message.m_customId.toInt());
|
list.append(message.m_customId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -57,8 +57,8 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||||||
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
bool onBeforeSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||||
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
bool onAfterSetMessagesRead(RootItem *selected_item, const QList<Message> &messages, ReadStatus read);
|
||||||
|
|
||||||
bool onBeforeSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes);
|
bool onBeforeSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
|
||||||
bool onAfterSwitchMessageImportance(RootItem *selected_item, QList<QPair<int,RootItem::Importance> > changes);
|
bool onAfterSwitchMessageImportance(RootItem *selected_item, const QList<QPair<Message,RootItem::Importance> > &changes);
|
||||||
|
|
||||||
bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||||
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||||
@ -77,7 +77,8 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||||||
void syncIn();
|
void syncIn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<int> customIDsOfMessages(const QList<Message> &messages);
|
QStringList customIDsOfMessages(const QList<QPair<Message,Importance> > &changes);
|
||||||
|
QStringList customIDsOfMessages(const QList<Message> &messages);
|
||||||
|
|
||||||
// Returns converted ids of given feeds
|
// Returns converted ids of given feeds
|
||||||
// which are suitable as IN clause for SQL queries.
|
// which are suitable as IN clause for SQL queries.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user