Enable labels for all accounts.

This commit is contained in:
Martin Rotter 2020-10-08 20:30:58 +02:00
parent 44e467b9c7
commit a9b6ecd351
9 changed files with 47 additions and 51 deletions

View File

@ -9,14 +9,16 @@
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
LabelsNode::LabelsNode(const QList<Label*>& labels, RootItem* parent_item) : RootItem(parent_item), m_actLabelNew(nullptr) { LabelsNode::LabelsNode(RootItem* parent_item) : RootItem(parent_item), m_actLabelNew(nullptr) {
setKind(RootItem::Kind::Labels); setKind(RootItem::Kind::Labels);
setId(ID_LABELS); setId(ID_LABELS);
setIcon(qApp->icons()->fromTheme(QSL("tag-folder"))); setIcon(qApp->icons()->fromTheme(QSL("tag-folder")));
setTitle(tr("Labels")); setTitle(tr("Labels"));
setDescription(tr("You can see all your labels (tags) here.")); setDescription(tr("You can see all your labels (tags) here."));
setCreationDate(QDateTime::currentDateTime()); setCreationDate(QDateTime::currentDateTime());
}
void LabelsNode::loadLabels(const QList<Label*>& labels) {
for (Label* lbl : labels) { for (Label* lbl : labels) {
appendChild(lbl); appendChild(lbl);
} }

View File

@ -11,7 +11,9 @@ class LabelsNode : public RootItem {
Q_OBJECT Q_OBJECT
public: public:
explicit LabelsNode(const QList<Label*>& labels, RootItem* parent_item = nullptr); explicit LabelsNode(RootItem* parent_item = nullptr);
void loadLabels(const QList<Label*>& labels);
virtual QList<QAction*> contextMenuFeedsList(); virtual QList<QAction*> contextMenuFeedsList();

View File

@ -12,10 +12,12 @@
#include "services/abstract/category.h" #include "services/abstract/category.h"
#include "services/abstract/feed.h" #include "services/abstract/feed.h"
#include "services/abstract/importantnode.h" #include "services/abstract/importantnode.h"
#include "services/abstract/labelsnode.h"
#include "services/abstract/recyclebin.h" #include "services/abstract/recyclebin.h"
ServiceRoot::ServiceRoot(RootItem* parent) ServiceRoot::ServiceRoot(RootItem* parent)
: RootItem(parent), m_recycleBin(new RecycleBin(this)), m_importantNode(new ImportantNode(this)), m_accountId(NO_PARENT_CATEGORY) { : RootItem(parent), m_recycleBin(new RecycleBin(this)), m_importantNode(new ImportantNode(this)),
m_labelsNode(new LabelsNode(this)), m_accountId(NO_PARENT_CATEGORY) {
setKind(RootItem::Kind::ServiceRoot); setKind(RootItem::Kind::ServiceRoot);
setCreationDate(QDateTime::currentDateTime()); setCreationDate(QDateTime::currentDateTime());
} }
@ -312,6 +314,10 @@ ImportantNode* ServiceRoot::importantNode() const {
return m_importantNode; return m_importantNode;
} }
LabelsNode* ServiceRoot::labelsNode() const {
return m_labelsNode;
}
void ServiceRoot::setRecycleBin(RecycleBin* recycle_bin) { void ServiceRoot::setRecycleBin(RecycleBin* recycle_bin) {
m_recycleBin = recycle_bin; m_recycleBin = recycle_bin;
} }
@ -356,6 +362,22 @@ void ServiceRoot::syncIn() {
itemChanged(getSubTree()); itemChanged(getSubTree());
} }
void ServiceRoot::performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList<Label*>& labels) {
// All data are now obtained, lets create the hierarchy.
assembleCategories(categories);
assembleFeeds(feeds);
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
appendChild(labelsNode());
labelsNode()->loadLabels(labels);
requestItemExpand({ labelsNode() }, true);
updateCounts(true);
}
RootItem* ServiceRoot::obtainNewTreeForSyncIn() const { RootItem* ServiceRoot::obtainNewTreeForSyncIn() const {
return nullptr; return nullptr;
} }

View File

@ -12,6 +12,8 @@
class FeedsModel; class FeedsModel;
class RecycleBin; class RecycleBin;
class ImportantNode; class ImportantNode;
class LabelsNode;
class Label;
class QAction; class QAction;
class MessagesModel; class MessagesModel;
@ -39,6 +41,7 @@ class ServiceRoot : public RootItem {
void setRecycleBin(RecycleBin* recycle_bin); void setRecycleBin(RecycleBin* recycle_bin);
virtual ImportantNode* importantNode() const; virtual ImportantNode* importantNode() const;
virtual LabelsNode* labelsNode() const;
virtual bool downloadAttachmentOnMyOwn(const QUrl& url) const; virtual bool downloadAttachmentOnMyOwn(const QUrl& url) const;
QList<Message> undeletedMessages() const; QList<Message> undeletedMessages() const;
@ -163,6 +166,7 @@ class ServiceRoot : public RootItem {
virtual void syncIn(); virtual void syncIn();
protected: protected:
void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList<Label*>& labels);
// This method should obtain new tree of feed/categories/whatever to perform sync in. // This method should obtain new tree of feed/categories/whatever to perform sync in.
virtual RootItem* obtainNewTreeForSyncIn() const; virtual RootItem* obtainNewTreeForSyncIn() const;
@ -212,6 +216,7 @@ class ServiceRoot : public RootItem {
protected: protected:
RecycleBin* m_recycleBin; RecycleBin* m_recycleBin;
ImportantNode* m_importantNode; ImportantNode* m_importantNode;
LabelsNode* m_labelsNode;
int m_accountId; int m_accountId;
QAction* m_actionSyncIn; QAction* m_actionSyncIn;
QList<QAction*> m_serviceMenu; QList<QAction*> m_serviceMenu;

View File

@ -63,20 +63,15 @@ void GmailServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId()); Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
Assignment feeds = DatabaseQueries::getFeeds<GmailFeed>(database, qApp->feedReader()->messageFilters(), accountId()); Assignment feeds = DatabaseQueries::getFeeds<GmailFeed>(database, qApp->feedReader()->messageFilters(), accountId());
auto labels = DatabaseQueries::getLabels(database, accountId());
// All data are now obtained, lets create the hierarchy. performInitialAssembly(categories, feeds, labels);
assembleCategories(categories);
assembleFeeds(feeds);
for (RootItem* feed : childItems()) { for (RootItem* feed : childItems()) {
if (feed->customId() == QL1S("INBOX")) { if (feed->customId() == QL1S("INBOX")) {
feed->setKeepOnTop(true); feed->setKeepOnTop(true);
} }
} }
appendChild(recycleBin());
appendChild(importantNode());
updateCounts(true);
} }
void GmailServiceRoot::saveAccountDataToDatabase() { void GmailServiceRoot::saveAccountDataToDatabase() {
@ -191,7 +186,7 @@ void GmailServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
loadCacheFromFile(accountId()); loadCacheFromFile(accountId());
if (childCount() <= 2) { if (childCount() <= 3) {
syncIn(); syncIn();
} }

View File

@ -36,15 +36,9 @@ void InoreaderServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId()); Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
Assignment feeds = DatabaseQueries::getFeeds<InoreaderFeed>(database, qApp->feedReader()->messageFilters(), accountId()); Assignment feeds = DatabaseQueries::getFeeds<InoreaderFeed>(database, qApp->feedReader()->messageFilters(), accountId());
auto labels = DatabaseQueries::getLabels(database, accountId());
// All data are now obtained, lets create the hierarchy. performInitialAssembly(categories, feeds, labels);
assembleCategories(categories);
assembleFeeds(feeds);
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
updateCounts(true);
} }
void InoreaderServiceRoot::saveAccountDataToDatabase() { void InoreaderServiceRoot::saveAccountDataToDatabase() {
@ -111,7 +105,7 @@ void InoreaderServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
loadCacheFromFile(accountId()); loadCacheFromFile(accountId());
if (childCount() <= 2) { if (childCount() <= 3) {
syncIn(); syncIn();
} }
else { else {

View File

@ -68,7 +68,7 @@ void OwnCloudServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
loadCacheFromFile(accountId()); loadCacheFromFile(accountId());
if (childCount() <= 2) { if (childCount() <= 3) {
syncIn(); syncIn();
} }
} }
@ -191,13 +191,7 @@ void OwnCloudServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId()); Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
Assignment feeds = DatabaseQueries::getFeeds<OwnCloudFeed>(database, qApp->feedReader()->messageFilters(), accountId()); Assignment feeds = DatabaseQueries::getFeeds<OwnCloudFeed>(database, qApp->feedReader()->messageFilters(), accountId());
auto labels = DatabaseQueries::getLabels(database, accountId());
// All data are now obtained, lets create the hierarchy. performInitialAssembly(categories, feeds, labels);
assembleCategories(categories);
assembleFeeds(feeds);
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
updateCounts(true);
} }

View File

@ -134,21 +134,9 @@ void StandardServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories<StandardCategory>(database, accountId()); Assignment categories = DatabaseQueries::getCategories<StandardCategory>(database, accountId());
Assignment feeds = DatabaseQueries::getFeeds<StandardFeed>(database, qApp->feedReader()->messageFilters(), accountId()); Assignment feeds = DatabaseQueries::getFeeds<StandardFeed>(database, qApp->feedReader()->messageFilters(), accountId());
auto labels = DatabaseQueries::getLabels(database, accountId());
// All data are now obtained, lets create the hierarchy. performInitialAssembly(categories, feeds, labels);
assembleCategories(categories);
assembleFeeds(feeds);
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
auto* labelss = new LabelsNode(DatabaseQueries::getLabels(database, accountId()), this);
appendChild(labelss);
requestItemExpand({ labelss }, true);
updateCounts(true);
} }
void StandardServiceRoot::checkArgumentsForFeedAdding() { void StandardServiceRoot::checkArgumentsForFeedAdding() {

View File

@ -206,15 +206,9 @@ void TtRssServiceRoot::loadFromDatabase() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId()); Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
Assignment feeds = DatabaseQueries::getFeeds<TtRssFeed>(database, qApp->feedReader()->messageFilters(), accountId()); Assignment feeds = DatabaseQueries::getFeeds<TtRssFeed>(database, qApp->feedReader()->messageFilters(), accountId());
auto labels = DatabaseQueries::getLabels(database, accountId());
// All data are now obtained, lets create the hierarchy. performInitialAssembly(categories, feeds, labels);
assembleCategories(categories);
assembleFeeds(feeds);
// As the last item, add recycle bin, which is needed.
appendChild(recycleBin());
appendChild(importantNode());
updateCounts(true);
} }
void TtRssServiceRoot::updateTitle() { void TtRssServiceRoot::updateTitle() {