Work on labels, it is starting to look good.
This commit is contained in:
parent
0a79d07e01
commit
684ee4d2b1
@ -53,6 +53,10 @@ void MessagesModel::repopulate() {
|
|||||||
while (canFetchMore()) {
|
while (canFetchMore()) {
|
||||||
fetchMore();
|
fetchMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebugNN << LOGSEC_MESSAGEMODEL
|
||||||
|
<< "Repopulated model, SQL statement is now:\n"
|
||||||
|
<< QUOTE_W_SPACE_DOT(selectStatement());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessagesModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
bool MessagesModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
||||||
|
@ -72,11 +72,6 @@ void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order) {
|
|||||||
m_sortColumns.prepend(column);
|
m_sortColumns.prepend(column);
|
||||||
m_sortOrders.prepend(order);
|
m_sortOrders.prepend(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebugNN << LOGSEC_MESSAGEMODEL
|
|
||||||
<< "Added sort state, select statement is now:\n'"
|
|
||||||
<< selectStatement()
|
|
||||||
<< "'";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesModelSqlLayer::setFilter(const QString& filter) {
|
void MessagesModelSqlLayer::setFilter(const QString& filter) {
|
||||||
|
@ -604,6 +604,81 @@ int DatabaseQueries::getMessageCountsForBin(const QSqlDatabase& db, int account_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Message> DatabaseQueries::getUndeletedMessagesWithLabel(const QSqlDatabase& db, const Label* label, bool* ok) {
|
||||||
|
QList<Message> messages;
|
||||||
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
q.prepare(QSL(
|
||||||
|
"SELECT Messages.id, Messages.is_read, Messages.is_deleted, Messages.is_important, Feeds.title, Messages.title, Messages.url, Messages.author, Messages.date_created, Messages.contents, Messages.is_pdeleted, Messages.enclosures, Messages.account_id, Messages.custom_id, Messages.custom_hash, Messages.feed, CASE WHEN length(Messages.enclosures) > 10 THEN 'true' ELSE 'false' END AS has_enclosures "
|
||||||
|
"FROM Messages "
|
||||||
|
"INNER JOIN Feeds "
|
||||||
|
"ON Messages.feed = Feeds.custom_id AND Messages.account_id = :account_id AND Messages.account_id = Feeds.account_id "
|
||||||
|
"INNER JOIN LabelsInMessages "
|
||||||
|
"ON "
|
||||||
|
" Messages.is_pdeleted = 0 AND Messages.is_deleted = 0 AND "
|
||||||
|
" LabelsInMessages.account_id = :account_id AND LabelsInMessages.account_id = Messages.account_id AND "
|
||||||
|
" LabelsInMessages.label = :label AND LabelsInMessages.message = Messages.custom_id;"));
|
||||||
|
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
|
||||||
|
q.bindValue(QSL(":label"), label->customId());
|
||||||
|
|
||||||
|
if (q.exec()) {
|
||||||
|
while (q.next()) {
|
||||||
|
bool decoded;
|
||||||
|
Message message = Message::fromSqlRecord(q.record(), &decoded);
|
||||||
|
|
||||||
|
if (decoded) {
|
||||||
|
messages.append(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Message> DatabaseQueries::getUndeletedLabelledMessages(const QSqlDatabase& db, int account_id, bool* ok) {
|
||||||
|
QList<Message> messages;
|
||||||
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
q.prepare(QSL(
|
||||||
|
"SELECT Messages.id, Messages.is_read, Messages.is_deleted, Messages.is_important, Feeds.title, Messages.title, Messages.url, Messages.author, Messages.date_created, Messages.contents, Messages.is_pdeleted, Messages.enclosures, Messages.account_id, Messages.custom_id, Messages.custom_hash, Messages.feed, CASE WHEN length(Messages.enclosures) > 10 THEN 'true' ELSE 'false' END AS has_enclosures "
|
||||||
|
"FROM Messages "
|
||||||
|
"LEFT JOIN Feeds "
|
||||||
|
"ON Messages.feed = Feeds.custom_id AND Messages.account_id = Feeds.account_id "
|
||||||
|
"WHERE Messages.is_deleted = 0 AND Messages.is_pdeleted = 0 AND Messages.account_id = :account_id AND (SELECT COUNT(*) FROM LabelsInMessages WHERE account_id = :account_id AND message = Messages.custom_id) > 0;"));
|
||||||
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
|
|
||||||
|
if (q.exec()) {
|
||||||
|
while (q.next()) {
|
||||||
|
bool decoded;
|
||||||
|
Message message = Message::fromSqlRecord(q.record(), &decoded);
|
||||||
|
|
||||||
|
if (decoded) {
|
||||||
|
messages.append(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Message> DatabaseQueries::getUndeletedImportantMessages(const QSqlDatabase& db, int account_id, bool* ok) {
|
QList<Message> DatabaseQueries::getUndeletedImportantMessages(const QSqlDatabase& db, int account_id, bool* ok) {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
@ -637,8 +712,8 @@ QList<Message> DatabaseQueries::getUndeletedImportantMessages(const QSqlDatabase
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Message> DatabaseQueries::getUndeletedMessagesForFeed(const QSqlDatabase& db, const QString& feed_custom_id, int account_id,
|
QList<Message> DatabaseQueries::getUndeletedMessagesForFeed(const QSqlDatabase& db, const QString& feed_custom_id,
|
||||||
bool* ok) {
|
int account_id, bool* ok) {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
@ -69,13 +69,11 @@ class DatabaseQueries {
|
|||||||
static int getMessageCountsForBin(const QSqlDatabase& db, int account_id, bool including_total_counts, bool* ok = nullptr);
|
static int getMessageCountsForBin(const QSqlDatabase& db, int account_id, bool including_total_counts, bool* ok = nullptr);
|
||||||
|
|
||||||
// Get messages (for newspaper view for example).
|
// Get messages (for newspaper view for example).
|
||||||
static QList<Message> getUndeletedImportantMessages(const QSqlDatabase& db,
|
static QList<Message> getUndeletedMessagesWithLabel(const QSqlDatabase& db, const Label* label, bool* ok = nullptr);
|
||||||
int account_id,
|
static QList<Message> getUndeletedLabelledMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
bool* ok = nullptr);
|
static QList<Message> getUndeletedImportantMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
static QList<Message> getUndeletedMessagesForFeed(const QSqlDatabase& db,
|
static QList<Message> getUndeletedMessagesForFeed(const QSqlDatabase& db, const QString& feed_custom_id,
|
||||||
const QString& feed_custom_id,
|
int account_id, bool* ok = nullptr);
|
||||||
int account_id,
|
|
||||||
bool* ok = nullptr);
|
|
||||||
static QList<Message> getUndeletedMessagesForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
static QList<Message> getUndeletedMessagesForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
static QList<Message> getUndeletedMessagesForAccount(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
static QList<Message> getUndeletedMessagesForAccount(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
|
|
||||||
|
@ -42,12 +42,13 @@ class Feed : public RootItem {
|
|||||||
explicit Feed(const Feed& other);
|
explicit Feed(const Feed& other);
|
||||||
virtual ~Feed();
|
virtual ~Feed();
|
||||||
|
|
||||||
QList<Message> undeletedMessages() const;
|
virtual QList<Message> undeletedMessages() const;
|
||||||
|
virtual QString additionalTooltip() const;
|
||||||
QString additionalTooltip() const;
|
virtual bool markAsReadUnread(ReadStatus status);
|
||||||
|
virtual bool cleanMessages(bool clean_read_only);
|
||||||
int countOfAllMessages() const;
|
virtual QList<Message> obtainNewMessages(bool* error_during_obtaining) = 0;
|
||||||
int countOfUnreadMessages() const;
|
virtual int countOfAllMessages() const;
|
||||||
|
virtual int countOfUnreadMessages() const;
|
||||||
|
|
||||||
void setCountOfAllMessages(int count_all_messages);
|
void setCountOfAllMessages(int count_all_messages);
|
||||||
void setCountOfUnreadMessages(int count_unread_messages);
|
void setCountOfUnreadMessages(int count_unread_messages);
|
||||||
@ -74,14 +75,10 @@ class Feed : public RootItem {
|
|||||||
void setMessageFilters(const QList<QPointer<MessageFilter>>& messageFilters);
|
void setMessageFilters(const QList<QPointer<MessageFilter>>& messageFilters);
|
||||||
void removeMessageFilter(MessageFilter* filter);
|
void removeMessageFilter(MessageFilter* filter);
|
||||||
|
|
||||||
bool markAsReadUnread(ReadStatus status);
|
int updateMessages(const QList<Message>& messages, bool error_during_obtaining);
|
||||||
bool cleanMessages(bool clean_read_only);
|
|
||||||
|
|
||||||
virtual QList<Message> obtainNewMessages(bool* error_during_obtaining) = 0;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateCounts(bool including_total_count);
|
virtual void updateCounts(bool including_total_count);
|
||||||
int updateMessages(const QList<Message>& messages, bool error_during_obtaining);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString getAutoUpdateStatusDescription() const;
|
QString getAutoUpdateStatusDescription() const;
|
||||||
|
@ -87,6 +87,12 @@ void Label::updateCounts(bool including_total_count) {
|
|||||||
setCountOfUnreadMessages(DatabaseQueries::getMessageCountsForLabel(database, this, account_id, false));
|
setCountOfUnreadMessages(DatabaseQueries::getMessageCountsForLabel(database, this, account_id, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Message> Label::undeletedMessages() const {
|
||||||
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
|
|
||||||
|
return DatabaseQueries::getUndeletedMessagesWithLabel(database, this);
|
||||||
|
}
|
||||||
|
|
||||||
QIcon Label::generateIcon(const QColor& color) {
|
QIcon Label::generateIcon(const QColor& color) {
|
||||||
QPixmap pxm(64, 64);
|
QPixmap pxm(64, 64);
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class Label : public RootItem {
|
|||||||
virtual bool canBeDeleted() const;
|
virtual bool canBeDeleted() const;
|
||||||
virtual bool deleteViaGui();
|
virtual bool deleteViaGui();
|
||||||
virtual void updateCounts(bool including_total_count);
|
virtual void updateCounts(bool including_total_count);
|
||||||
|
virtual QList<Message> undeletedMessages() const;
|
||||||
static QIcon generateIcon(const QColor& color);
|
static QIcon generateIcon(const QColor& color);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -26,6 +26,12 @@ void LabelsNode::loadLabels(const QList<Label*>& labels) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Message> LabelsNode::undeletedMessages() const {
|
||||||
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
|
|
||||||
|
return DatabaseQueries::getUndeletedLabelledMessages(database, getParentServiceRoot()->accountId());
|
||||||
|
}
|
||||||
|
|
||||||
QList<Label*> LabelsNode::labels() const {
|
QList<Label*> LabelsNode::labels() const {
|
||||||
auto list = boolinq::from(childItems()).select([](RootItem* it) {
|
auto list = boolinq::from(childItems()).select([](RootItem* it) {
|
||||||
return static_cast<Label*>(it);
|
return static_cast<Label*>(it);
|
||||||
|
@ -16,6 +16,7 @@ class LabelsNode : public RootItem {
|
|||||||
QList<Label*> labels() const;
|
QList<Label*> labels() const;
|
||||||
void loadLabels(const QList<Label*>& labels);
|
void loadLabels(const QList<Label*>& labels);
|
||||||
|
|
||||||
|
virtual QList<Message> undeletedMessages() const;
|
||||||
virtual QList<QAction*> contextMenuFeedsList();
|
virtual QList<QAction*> contextMenuFeedsList();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -84,7 +84,7 @@ QList<Message> RootItem::undeletedMessages() const {
|
|||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
|
|
||||||
for (RootItem* child : m_childItems) {
|
for (RootItem* child : m_childItems) {
|
||||||
if (child->kind() != RootItem::Kind::Bin) {
|
if (child->kind() != Kind::Bin && child->kind() != Kind::Labels && child->kind() != Kind::Label) {
|
||||||
messages.append(child->undeletedMessages());
|
messages.append(child->undeletedMessages());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,8 +144,6 @@ RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
|
|||||||
else {
|
else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderServiceRoot::saveAllCachedData(bool async) {
|
void InoreaderServiceRoot::saveAllCachedData(bool async) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user