summaryrefslogtreecommitdiff
path: root/src/atomchannel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/atomchannel.h')
-rw-r--r--src/atomchannel.h82
1 files changed, 78 insertions, 4 deletions
diff --git a/src/atomchannel.h b/src/atomchannel.h
index 7f7294a..87727d2 100644
--- a/src/atomchannel.h
+++ b/src/atomchannel.h
@@ -1,15 +1,87 @@
#pragma once
+#include <optional>
+
#include <QDateTime>
#include <QDebug>
+#include <QDomDocument>
#include <QList>
#include <QString>
+#include <QUrl>
#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<qlonglong>, 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: <image>
+
+class Item : public DbItem
+{
+ Q_GADGET
+
+ GADGET_PROPERTY(QString, title);
+ GADGET_PROPERTY(QUrl, link);
+ GADGET_PROPERTY(QStringList, categories);
+ 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:
@@ -26,20 +98,20 @@ public:
* and return db id if any
* \return id on success, 0 otherwise
*/
- int getDbId();
+ std::optional<int> getDbId();
/*!
* \brief createInDb - create channel in db
* \return new channel id on success, 0 otherwise
*/
- int createInDb();
+ std::optional<int> 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
*/
- int getOrInsertDbId();
+ std::optional<int> getOrInsertDbId();
/*!
* \brief syncDbItems - create items in db if not exist
@@ -51,7 +123,7 @@ public:
/*!
* \brief m_id - cache db m_id
*/
- int m_id{0};
+ std::optional<int> m_id{0};
QString title;
/*!
@@ -68,3 +140,5 @@ public:
};
QDebug operator<<(QDebug debug, const AtomChannel &channel);
+QDebug operator<<(QDebug debug, const Channel &channel);
+QDebug operator<<(QDebug debug, const Item &item);