Add command line parameters

This commit is contained in:
Tobias Fella 2020-05-11 21:13:27 +02:00
parent 2c125c3819
commit bec24f9436
No known key found for this signature in database
GPG Key ID: E55EDAB3CA5D9925
7 changed files with 50 additions and 29 deletions

View File

@ -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

View File

@ -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));
}

View File

@ -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);
};

View File

@ -49,21 +49,7 @@ QHash<int, QByteArray> 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());

View File

@ -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);
};

View File

@ -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]() {

View File

@ -27,6 +27,7 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickView>
#include <QCommandLineParser>
#include <KAboutData>
#include <KLocalizedContext>
@ -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);