#pragma once #include #include #include #include #include #include #include #include "atomchannelimage.h" #include "atomitem.h" class QXmlStreamReader; // TODO: mark items as read in all user channels #define GADGET_PROPERTY(type, name) \ protected: \ Q_PROPERTY(const type name READ get_##name WRITE set_##name) \ public: \ const type &get_##name() const \ { \ return m_##name; \ } \ void set_##name(const type &name) \ { \ m_##name = name; \ } \ \ protected: \ type m_##name class DbItem { Q_GADGET GADGET_PROPERTY(std::optional, id); static constexpr auto dateFormat = Qt::DateFormat::RFC2822Date; public: explicit DbItem(const QDomNode &node); public: void init(const QMetaObject &mo, const QDomNode &node); }; class Channel : public DbItem { Q_GADGET GADGET_PROPERTY(QString, title); GADGET_PROPERTY(QUrl, link); public: explicit Channel(const QDomNode &node); public: bool isValid() const; }; // TODO: class Item : public DbItem { Q_GADGET GADGET_PROPERTY(QString, title); GADGET_PROPERTY(QUrl, link); GADGET_PROPERTY(QStringList, category); GADGET_PROPERTY(QString, guid); GADGET_PROPERTY(QDateTime, pubDate); GADGET_PROPERTY(QString, description); GADGET_PROPERTY(QString, content); public: explicit Item(const QDomNode &node); public: bool isValid() const; }; class AtomChannel { public: // TODO: move to interface static inline const QString xmlTag{"channel"}; public: explicit AtomChannel(QXmlStreamReader *xmlReader); public: // TODO: update db data if differs. here and everywhere (item, user, etc) /*! * \brief getDbId - check if channel with corresponding `link` exists in db * and return db id if any * \return id on success, 0 otherwise */ std::optional getDbId(); /*! * \brief createInDb - create channel in db * \return new channel id on success, 0 otherwise */ std::optional createInDb(); /*! * \brief getOrInsertDbId - get existing channel id or try to create a new * channel and get its id * \return existing or new channel id on success, 0 otherwise */ std::optional getOrInsertDbId(); /*! * \brief syncDbItems - create items in db if not exist * \return list of new items ids */ QList syncDbItems(); public: /*! * \brief m_id - cache db m_id */ std::optional m_id{0}; QString title; /*! * \brief link - field called `link` in atom xml. Points to feed itself */ QUrl link; QString description; QDateTime lastBuildDate; QLocale::Language language; // ... // TODO: shared_ptr AtomChannelImage image; QList items; }; QDebug operator<<(QDebug debug, const AtomChannel &channel); QDebug operator<<(QDebug debug, const Channel &channel); QDebug operator<<(QDebug debug, const Item &item);