summaryrefslogtreecommitdiff
path: root/src/atomitem.h
blob: 7b368162ac23313e40f59281c5f902973e2eea95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include <QDateTime>
#include <QDebug>
#include <QString>
#include <QUrl>

class QXmlStreamReader;

class AtomChannel;

struct AtomGuid : public QString
{
    using QString::QString;

    // NOTE: unused
    bool isPermalink{false};
};

class AtomItem
{
public:
    // TODO: move to interface
    static inline const QString tag{"item"};

public:
    explicit AtomItem(QXmlStreamReader *xmlReader);

public:
    /*!
     * \brief getDbId - check if item with corresponding `link` exists in db
     * and return db id if any
     * \return id on success, 0 otherwise
     */
    int getDbId();

    /*!
     * \brief createInDb - create item in db
     * \return new item id on success, 0 otherwise
     */
    int createInDb(const int feedId);

    /*!
     * \brief getOrInsertDbId - get existing item id or try to create a new
     * item and get its id
     * \return existing or new item id on success, 0 otherwise
     */
    int getOrInsertDbId(const int feedId);

public:
    /*!
     * \brief id - cache db id
     */
    int id{0};

    QString title;
    QUrl link;
    QString author;
    QStringList categories;
    AtomGuid guid;
    QDateTime pubDate;
    QString description;
    QString encoded;
};

QDebug operator<<(QDebug debug, const AtomItem &item);