Simplify some sync-in logic.

This commit is contained in:
Martin Rotter 2020-10-06 19:58:21 +02:00
parent e2198faedc
commit 821192906e
6 changed files with 74 additions and 49 deletions

View file

@ -6,7 +6,7 @@
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
LabelsNode::LabelsNode(RootItem* parent_item) : RootItem(parent_item) { 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("mail-mark-important"))); setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important")));
@ -14,3 +14,14 @@ LabelsNode::LabelsNode(RootItem* parent_item) : RootItem(parent_item) {
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());
} }
QList<QAction*> LabelsNode::contextMenuFeedsList() {
if (m_actLabelNew == nullptr) {
// Initialize it all.
m_actLabelNew = new QAction(qApp->icons()->fromTheme("tag-new"), tr("New label"), this);
}
return QList<QAction*> {
m_actLabelNew
};
}

View file

@ -10,6 +10,11 @@ class LabelsNode : public RootItem {
public: public:
explicit LabelsNode(RootItem* parent_item = nullptr); explicit LabelsNode(RootItem* parent_item = nullptr);
virtual QList<QAction*> contextMenuFeedsList();
private:
QAction* m_actLabelNew;
}; };
#endif // LABELSNODE_H #endif // LABELSNODE_H

View file

@ -99,48 +99,20 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
virtual int countOfUnreadMessages() const; virtual int countOfUnreadMessages() const;
virtual int countOfAllMessages() const; virtual int countOfAllMessages() const;
inline RootItem* parent() const { RootItem* parent() const;
return m_parentItem; void setParent(RootItem* parent_item);
}
inline void setParent(RootItem* parent_item) {
m_parentItem = parent_item;
}
inline RootItem* child(int row) {
return m_childItems.value(row);
}
inline int childCount() const {
return m_childItems.size();
}
inline void appendChild(RootItem* child) {
if (child != nullptr) {
m_childItems.append(child);
child->setParent(this);
}
}
// Access to children. // Access to children.
inline QList<RootItem*> childItems() const { RootItem* child(int row);
return m_childItems; int childCount() const;
} void appendChild(RootItem* child);
QList<RootItem*> childItems() const;
// Removes all children from this item. void clearChildren();
// NOTE: Children are NOT freed from the memory. void setChildItems(const QList<RootItem*>& child_items);
inline void clearChildren() {
m_childItems.clear();
}
inline void setChildItems(const QList<RootItem*>& child_items) {
m_childItems = child_items;
}
// Removes particular child at given index. // Removes particular child at given index.
// NOTE: Child is NOT freed from the memory. // NOTE: Child is NOT freed from the memory.
bool removeChild(int index); bool removeChild(int index);
bool removeChild(RootItem* child); bool removeChild(RootItem* child);
// Checks whether "this" object is child (direct or indirect) // Checks whether "this" object is child (direct or indirect)
@ -219,6 +191,41 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
RootItem* m_parentItem; RootItem* m_parentItem;
}; };
inline RootItem* RootItem::parent() const {
return m_parentItem;
}
inline void RootItem::setParent(RootItem* parent_item) {
m_parentItem = parent_item;
}
inline RootItem* RootItem::child(int row) {
return m_childItems.value(row);
}
inline int RootItem::childCount() const {
return m_childItems.size();
}
inline void RootItem::appendChild(RootItem* child) {
if (child != nullptr) {
m_childItems.append(child);
child->setParent(this);
}
}
inline QList<RootItem*> RootItem::childItems() const {
return m_childItems;
}
inline void RootItem::clearChildren() {
m_childItems.clear();
}
inline void RootItem::setChildItems(const QList<RootItem*>& child_items) {
m_childItems = child_items;
}
RootItem::Kind operator|(RootItem::Kind a, RootItem::Kind b); RootItem::Kind operator|(RootItem::Kind a, RootItem::Kind b);
RootItem::Kind operator&(RootItem::Kind a, RootItem::Kind b); RootItem::Kind operator&(RootItem::Kind a, RootItem::Kind b);

View file

@ -196,9 +196,9 @@ bool ServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
} }
void ServiceRoot::storeNewFeedTree(RootItem* root) { void ServiceRoot::storeNewFeedTree(RootItem* root) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); DatabaseQueries::storeAccountTree(qApp->database()->connection(metaObject()->className()), root, accountId());
if (DatabaseQueries::storeAccountTree(database, root, accountId())) { /*if (DatabaseQueries::storeAccountTree(database, root, accountId())) {
RecycleBin* bin = recycleBin(); RecycleBin* bin = recycleBin();
if (bin != nullptr && !childItems().contains(bin)) { if (bin != nullptr && !childItems().contains(bin)) {
@ -213,7 +213,7 @@ void ServiceRoot::storeNewFeedTree(RootItem* root) {
appendChild(imp); appendChild(imp);
imp->updateCounts(true); imp->updateCounts(true);
} }
} }*/
} }
void ServiceRoot::removeLeftOverMessages() { void ServiceRoot::removeLeftOverMessages() {
@ -271,7 +271,9 @@ void ServiceRoot::addNewFeed(RootItem* selected_item, const QString& url) {
Q_UNUSED(url) Q_UNUSED(url)
} }
void ServiceRoot::addNewCategory(RootItem* selected_item) {} void ServiceRoot::addNewCategory(RootItem* selected_item) {
Q_UNUSED(selected_item)
}
QMap<QString, QVariantMap> ServiceRoot::storeCustomFeedsData() { QMap<QString, QVariantMap> ServiceRoot::storeCustomFeedsData() {
QMap<QString, QVariantMap> custom_data; QMap<QString, QVariantMap> custom_data;

View file

@ -164,8 +164,7 @@ class ServiceRoot : public RootItem {
protected: protected:
// This method should obtain new tree of feed/messages/etc to perform // This method should obtain new tree of feed/categories/whatever to perform sync in.
// sync in.
virtual RootItem* obtainNewTreeForSyncIn() const; virtual RootItem* obtainNewTreeForSyncIn() const;
// Removes all messages/categories/feeds which are // Removes all messages/categories/feeds which are

View file

@ -12,6 +12,7 @@
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
#include "miscellaneous/settings.h" #include "miscellaneous/settings.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"
#include "services/standard/gui/formstandardcategorydetails.h" #include "services/standard/gui/formstandardcategorydetails.h"
#include "services/standard/gui/formstandardfeeddetails.h" #include "services/standard/gui/formstandardfeeddetails.h"