kasts/src/entry.cpp

102 lines
2.3 KiB
C++
Raw Normal View History

2020-05-26 16:32:07 +02:00
/**
* Copyright 2020 Tobias Fella <fella@posteo.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "entry.h"
2020-06-06 00:05:32 +02:00
#include <QSqlQuery>
2020-05-26 16:32:07 +02:00
#include <QUrl>
2020-06-06 00:05:32 +02:00
#include "database.h"
Entry::Entry(Feed *feed, QString id, QString title, QString content, QVector<Author *> authors, QDateTime created, QDateTime updated, QString link, bool read, QObject *parent)
2020-05-26 16:32:07 +02:00
: QObject(parent)
2020-06-06 00:05:32 +02:00
, m_feed(feed)
, m_id(id)
2020-05-26 16:32:07 +02:00
, m_title(title)
, m_content(content)
, m_authors(authors)
, m_created(created)
, m_updated(updated)
, m_link(link)
2020-06-06 00:05:32 +02:00
, m_read(read)
2020-05-26 16:32:07 +02:00
{
}
Entry::~Entry()
{
}
2020-06-06 00:05:32 +02:00
QString Entry::id() const
{
return m_id;
}
2020-05-26 16:32:07 +02:00
QString Entry::title() const
{
return m_title;
}
QString Entry::content() const
{
return m_content;
}
QVector<Author *> Entry::authors() const
{
return m_authors;
}
QDateTime Entry::created() const
{
return m_created;
}
QDateTime Entry::updated() const
{
return m_updated;
}
QString Entry::link() const
{
return m_link;
}
2020-06-06 00:05:32 +02:00
bool Entry::read() const
{
return m_read;
}
2020-05-26 16:32:07 +02:00
QString Entry::baseUrl() const
{
return QUrl(m_link).adjusted(QUrl::RemovePath).toString();
}
2020-06-06 00:05:32 +02:00
void Entry::setRead(bool read)
{
m_read = read;
Q_EMIT readChanged(m_read);
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Entries SET read=:read WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_id);
query.bindValue(QStringLiteral(":feed"), m_feed->url());
query.bindValue(QStringLiteral(":read"), m_read);
Database::instance().execute(query);
}