From bec24f9436d3f5d6ea6f48f61758764c3e98f640 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 11 May 2020 21:13:27 +0200 Subject: [PATCH] Add command line parameters --- org.kde.mobile.alligator.desktop | 2 +- src/database.cpp | 30 ++++++++++++++++++++++++++++++ src/database.h | 2 ++ src/feedListModel.cpp | 26 +------------------------- src/feedListModel.h | 3 --- src/fetcher.cpp | 2 ++ src/main.cpp | 14 ++++++++++++++ 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/org.kde.mobile.alligator.desktop b/org.kde.mobile.alligator.desktop index f2e4bb82..dd886681 100755 --- a/org.kde.mobile.alligator.desktop +++ b/org.kde.mobile.alligator.desktop @@ -42,7 +42,7 @@ GenericName[uk]=Читання подач GenericName[x-test]=xxFeed Readerxx Encoding=UTF-8 Icon=alligator -Exec=alligator +Exec=alligator %u Type=Application Categories=Qt;KDE;RSS; Terminal=false diff --git a/src/database.cpp b/src/database.cpp index e9dace92..04a3786b 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -26,6 +26,7 @@ #include "alligatorsettings.h" #include "database.h" +#include "fetcher.h" #define TRUE_OR_RETURN(x) \ if (!x) \ @@ -122,3 +123,32 @@ void Database::cleanup() execute(query); } } + +bool Database::feedExists(QString url) +{ + QSqlQuery query; + query.prepare(QStringLiteral("SELECT COUNT (url) FROM Feeds WHERE url=:url;")); + query.bindValue(QStringLiteral(":url"), url); + Database::instance().execute(query); + query.next(); + return query.value(0).toInt() != 0; +} + +void Database::addFeed(QString url) +{ + qDebug() << "Adding feed"; + if (feedExists(url)) { + qDebug() << "Feed already exists"; + return; + } + qDebug() << "Feed does not yet exist"; + + QSqlQuery query; + query.prepare(QStringLiteral("INSERT INTO Feeds VALUES (:name, :url, :image);")); + query.bindValue(QStringLiteral(":name"), url); + query.bindValue(QStringLiteral(":url"), url); + query.bindValue(QStringLiteral(":image"), QLatin1String("")); + execute(query); + + Fetcher::instance().fetch(QUrl(url)); +} diff --git a/src/database.h b/src/database.h index 54693533..6b1398dc 100644 --- a/src/database.h +++ b/src/database.h @@ -32,6 +32,7 @@ public: } bool execute(QSqlQuery &query); bool execute(QString query); + void addFeed(QString url); private: Database(); @@ -40,4 +41,5 @@ private: bool migrate(); bool migrateTo1(); void cleanup(); + bool feedExists(QString url); }; diff --git a/src/feedListModel.cpp b/src/feedListModel.cpp index c38a6a69..c30c5aa2 100644 --- a/src/feedListModel.cpp +++ b/src/feedListModel.cpp @@ -49,21 +49,7 @@ QHash FeedListModel::roleNames() const void FeedListModel::addFeed(QString url) { - qDebug() << "Adding feed"; - if (feedExists(url)) { - qDebug() << "Feed already exists"; - return; - } - qDebug() << "Feed does not yet exist"; - - QSqlRecord rec = record(); - rec.setValue(0, url); - rec.setValue(1, url); - rec.setValue(2, QLatin1String("")); - - insertRecord(-1, rec); - - Fetcher::instance().fetch(QUrl(url)); + Database::instance().addFeed(url); } QVariant FeedListModel::data(const QModelIndex &index, int role) const @@ -71,16 +57,6 @@ QVariant FeedListModel::data(const QModelIndex &index, int role) const return QSqlTableModel::data(createIndex(index.row(), role), 0); } -bool FeedListModel::feedExists(QString url) -{ - QSqlQuery query; - query.prepare(QStringLiteral("SELECT COUNT (url) FROM Feeds WHERE url=:url;")); - query.bindValue(QStringLiteral(":url"), url); - Database::instance().execute(query); - query.next(); - return query.value(0).toInt() != 0; -} - void FeedListModel::removeFeed(int index) { Fetcher::instance().removeImage(data(createIndex(index, 0), Image).toString()); diff --git a/src/feedListModel.h b/src/feedListModel.h index 134a4f61..73aa2409 100644 --- a/src/feedListModel.h +++ b/src/feedListModel.h @@ -44,7 +44,4 @@ public: Q_INVOKABLE void addFeed(QString url); Q_INVOKABLE void removeFeed(int index); Q_INVOKABLE QString image(QString url); - -private: - bool feedExists(QString url); }; diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 80a7d1db..4782f884 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -42,6 +42,8 @@ void Fetcher::fetch(QUrl url) { qDebug() << "Starting to fetch" << url.toString(); + emit updated(); + QNetworkRequest request(url); QNetworkReply *reply = manager->get(request); connect(reply, &QNetworkReply::finished, this, [this, url, reply]() { diff --git a/src/main.cpp b/src/main.cpp index 90a4c0be..dae7a895 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,19 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); + QCommandLineParser parser; + parser.setApplicationDescription(i18n("RSS Feed Reader")); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument(QLatin1String("url"), i18n("Url to add to the subscriptions")); + parser.process(app); + + if(parser.positionalArguments().size() == 1) { + QString url = parser.positionalArguments().at(0); + qDebug() << url; + //TODO + } + 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);