Apply clang-format
This commit is contained in:
parent
4acd43d240
commit
97e9b4c663
@ -18,16 +18,18 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QSqlError>
|
||||
#include <QSqlDatabase>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "database.h"
|
||||
#include "alligatorsettings.h"
|
||||
#include "database.h"
|
||||
|
||||
#define TRUE_OR_RETURN(x) if(!x) return false;
|
||||
#define TRUE_OR_RETURN(x) \
|
||||
if (!x) \
|
||||
return false;
|
||||
|
||||
Database::Database()
|
||||
{
|
||||
@ -37,19 +39,22 @@ Database::Database()
|
||||
db.setDatabaseName(databasePath + QStringLiteral("/database.db3"));
|
||||
db.open();
|
||||
|
||||
if(!migrate()) {
|
||||
if (!migrate()) {
|
||||
qCritical() << "Failed to migrate the database";
|
||||
}
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool Database::migrate() {
|
||||
if(version() < 1) TRUE_OR_RETURN(migrateTo1());
|
||||
bool Database::migrate()
|
||||
{
|
||||
if (version() < 1)
|
||||
TRUE_OR_RETURN(migrateTo1());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Database::migrateTo1() {
|
||||
bool Database::migrateTo1()
|
||||
{
|
||||
qDebug() << "Migrating database to version 1";
|
||||
QSqlQuery query(QSqlDatabase::database());
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT);")));
|
||||
@ -59,14 +64,16 @@ bool Database::migrateTo1() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Database::execute(QString query) {
|
||||
bool Database::execute(QString query)
|
||||
{
|
||||
QSqlQuery q;
|
||||
q.prepare(query);
|
||||
return execute(q);
|
||||
}
|
||||
|
||||
bool Database::execute(QSqlQuery &query) {
|
||||
if(!query.exec()) {
|
||||
bool Database::execute(QSqlQuery &query)
|
||||
{
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to execute SQL Query";
|
||||
qWarning() << query.lastQuery();
|
||||
qWarning() << query.lastError();
|
||||
@ -75,33 +82,39 @@ bool Database::execute(QSqlQuery &query) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int Database::version() {
|
||||
int Database::version()
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("PRAGMA user_version;"));
|
||||
execute(query);
|
||||
if(query.next()) {
|
||||
if (query.next()) {
|
||||
bool ok;
|
||||
int value = query.value(0).toInt(&ok);
|
||||
qDebug() << "Database version " << value;
|
||||
if(ok) return value;
|
||||
if (ok)
|
||||
return value;
|
||||
} else {
|
||||
qCritical() << "Failed to check database version";
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Database::cleanup() {
|
||||
void Database::cleanup()
|
||||
{
|
||||
AlligatorSettings settings;
|
||||
int count = settings.deleteAfterCount();
|
||||
int type = settings.deleteAfterType();
|
||||
|
||||
if(type == 0) { // Delete after <count> posts per feed
|
||||
//TODO
|
||||
if (type == 0) { // Delete after <count> posts per feed
|
||||
// TODO
|
||||
} else {
|
||||
QDateTime dateTime = QDateTime::currentDateTime();
|
||||
if(type == 1) dateTime = dateTime.addDays(-count);
|
||||
else if(type == 2) dateTime = dateTime.addDays(-7*count);
|
||||
else if(type == 3) dateTime = dateTime.addMonths(-count);
|
||||
if (type == 1)
|
||||
dateTime = dateTime.addDays(-count);
|
||||
else if (type == 2)
|
||||
dateTime = dateTime.addDays(-7 * count);
|
||||
else if (type == 3)
|
||||
dateTime = dateTime.addMonths(-count);
|
||||
qint64 sinceEpoch = dateTime.toSecsSinceEpoch();
|
||||
|
||||
QSqlQuery query;
|
||||
|
@ -18,12 +18,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QVector>
|
||||
#include <QDateTime>
|
||||
#include <QVector>
|
||||
|
||||
#include "database.h"
|
||||
#include "entryListModel.h"
|
||||
#include "fetcher.h"
|
||||
#include "database.h"
|
||||
|
||||
EntryListModel::EntryListModel(QObject *parent)
|
||||
: QSqlTableModel(parent)
|
||||
@ -36,12 +36,12 @@ EntryListModel::EntryListModel(QObject *parent)
|
||||
|
||||
QVariant EntryListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(role == Updated || role == Created) {
|
||||
if (role == Updated || role == Created) {
|
||||
QDateTime updated;
|
||||
updated.setSecsSinceEpoch(QSqlQueryModel::data(createIndex(index.row(), role), 0).toInt());
|
||||
return updated;
|
||||
}
|
||||
return QSqlQueryModel::data(createIndex(index.row(), role), 0);
|
||||
return QSqlQueryModel::data(createIndex(index.row(), role), 0);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> EntryListModel::roleNames() const
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSqlTableModel>
|
||||
#include <QObject>
|
||||
#include <QSqlTableModel>
|
||||
#include <QString>
|
||||
|
||||
class EntryListModel : public QSqlTableModel
|
||||
|
@ -18,15 +18,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QUrl>
|
||||
#include <QSqlRecord>
|
||||
#include <QDebug>
|
||||
#include <QModelIndex>
|
||||
#include <QSqlError>
|
||||
#include <QSqlRecord>
|
||||
#include <QUrl>
|
||||
|
||||
#include "database.h"
|
||||
#include "feedListModel.h"
|
||||
#include "fetcher.h"
|
||||
#include "database.h"
|
||||
|
||||
FeedListModel::FeedListModel(QObject *parent)
|
||||
: QSqlTableModel(parent)
|
||||
@ -49,7 +49,7 @@ QHash<int, QByteArray> FeedListModel::roleNames() const
|
||||
void FeedListModel::addFeed(QString url)
|
||||
{
|
||||
qDebug() << "Adding feed";
|
||||
if(feedExists(url)) {
|
||||
if (feedExists(url)) {
|
||||
qDebug() << "Feed already exists";
|
||||
return;
|
||||
}
|
||||
@ -75,7 +75,8 @@ QVariant FeedListModel::data(const QModelIndex &index, int role) const
|
||||
return QSqlTableModel::data(createIndex(index.row(), role), 0);
|
||||
}
|
||||
|
||||
bool FeedListModel::feedExists(QString url) {
|
||||
bool FeedListModel::feedExists(QString url)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT COUNT (url) FROM Feeds WHERE url=:url;"));
|
||||
query.bindValue(QStringLiteral(":url"), url);
|
||||
@ -95,7 +96,7 @@ void FeedListModel::removeFeed(int index)
|
||||
query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString());
|
||||
Database::instance().execute(query);
|
||||
|
||||
//Workaround...
|
||||
// Workaround...
|
||||
query.prepare(QStringLiteral("DELETE FROM Feeds WHERE url=:url;"));
|
||||
query.bindValue(QStringLiteral(":url"), data(createIndex(index, 0), 1).toString());
|
||||
Database::instance().execute(query);
|
||||
|
@ -23,10 +23,11 @@
|
||||
|
||||
#include <Syndication/Syndication>
|
||||
|
||||
#include "fetcher.h"
|
||||
#include "database.h"
|
||||
#include "fetcher.h"
|
||||
|
||||
Fetcher::Fetcher() {
|
||||
Fetcher::Fetcher()
|
||||
{
|
||||
}
|
||||
|
||||
void Fetcher::fetch(QUrl url)
|
||||
@ -44,7 +45,8 @@ void Fetcher::fetch(QUrl url)
|
||||
Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url.toString());
|
||||
Syndication::FeedPtr feed = Syndication::parserCollection()->parse(*document, QStringLiteral("Atom"));
|
||||
|
||||
if(feed.isNull()) return;
|
||||
if (feed.isNull())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
|
||||
@ -61,14 +63,15 @@ void Fetcher::fetch(QUrl url)
|
||||
query.bindValue(QStringLiteral(":id"), entry->id());
|
||||
Database::instance().execute(query);
|
||||
query.next();
|
||||
if(query.value(0).toInt() != 0) continue;
|
||||
if (query.value(0).toInt() != 0)
|
||||
continue;
|
||||
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated);"));
|
||||
query.bindValue(QStringLiteral(":feed"), url.toString());
|
||||
query.bindValue(QStringLiteral(":id"), entry->id());
|
||||
query.bindValue(QStringLiteral(":title"), entry->title());
|
||||
query.bindValue(QStringLiteral(":created"), static_cast<int>(entry->datePublished()));
|
||||
query.bindValue(QStringLiteral(":updated"), static_cast<int>(entry->dateUpdated()));
|
||||
if(!entry->content().isEmpty())
|
||||
if (!entry->content().isEmpty())
|
||||
query.bindValue(QStringLiteral(":content"), entry->content());
|
||||
else
|
||||
query.bindValue(QStringLiteral(":content"), entry->description());
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -25,18 +25,18 @@
|
||||
#endif
|
||||
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickView>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickView>
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KLocalizedString>
|
||||
#include <KLocalizedContext>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include "entryListModel.h"
|
||||
#include "feedListModel.h"
|
||||
#include "database.h"
|
||||
#include "alligatorsettings.h"
|
||||
#include "database.h"
|
||||
#include "entryListModel.h"
|
||||
#include "feed.h"
|
||||
#include "feedListModel.h"
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
Q_DECL_EXPORT
|
||||
@ -60,8 +60,7 @@ int main(int argc, char *argv[])
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
|
||||
KAboutData about(QStringLiteral("alligator"), i18n("Alligator"), QStringLiteral("0.1"), i18n("Feed Reader"),
|
||||
KAboutLicense::GPL, i18n("© 2020 KDE Community"));
|
||||
KAboutData about(QStringLiteral("alligator"), i18n("Alligator"), QStringLiteral("0.1"), i18n("Feed Reader"), KAboutLicense::GPL, i18n("© 2020 KDE Community"));
|
||||
about.addAuthor(i18n("Tobias Fella"), QString(), QStringLiteral("fella@posteo.de"));
|
||||
KAboutData::setApplicationData(about);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user