diff options
Diffstat (limited to 'src/atomchannel.h')
| -rw-r--r-- | src/atomchannel.h | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/atomchannel.h b/src/atomchannel.h index e52048a..e88c05f 100644 --- a/src/atomchannel.h +++ b/src/atomchannel.h @@ -32,11 +32,14 @@ public: \ protected: \ type m_##name -class DbItem +class DbItem : public QObject { - Q_GADGET + // Q_GADGET + Q_OBJECT - GADGET_PROPERTY(std::optional<qlonglong>, id); +public: + using DbId = std::optional<qlonglong>; + GADGET_PROPERTY(DbId, id); static constexpr auto dateFormat = Qt::DateFormat::RFC2822Date; @@ -44,28 +47,44 @@ public: explicit DbItem(const QDomNode &node); public: - void init(const QMetaObject &mo, const QDomNode &node); + virtual bool isValid() const = 0; + + virtual void init(const QDomNode &node); + + // TODO: sync list of items, thus minimizing amount of db queries + virtual DbId syncWithDb(); + + virtual QStringList propertyNames() const; + virtual QList<QMetaProperty> properties() const; + + virtual const QStringList &uniqueFields() const = 0; }; -class Channel : public DbItem +class Feed : public DbItem { - Q_GADGET + Q_OBJECT GADGET_PROPERTY(QString, title); GADGET_PROPERTY(QUrl, link); + GADGET_PROPERTY(QUrl, image_url); public: - explicit Channel(const QDomNode &node); + explicit Feed(const QDomNode &node); public: - bool isValid() const; + bool isValid() const override; + + const QStringList &uniqueFields() const override; + +private: + static inline QStringList m_uniqueFields{{"link"}}; }; // TODO: <image> class Item : public DbItem { - Q_GADGET + Q_OBJECT GADGET_PROPERTY(QString, title); GADGET_PROPERTY(QUrl, link); @@ -79,7 +98,12 @@ public: explicit Item(const QDomNode &node); public: - bool isValid() const; + bool isValid() const override; + + const QStringList &uniqueFields() const override; + +private: + static inline QStringList m_uniqueFields{{"link"}}; }; class AtomChannel @@ -140,5 +164,5 @@ public: }; QDebug operator<<(QDebug debug, const AtomChannel &channel); -QDebug operator<<(QDebug debug, const Channel &channel); +QDebug operator<<(QDebug debug, const Feed &feed); QDebug operator<<(QDebug debug, const Item &item); |
