mirror of
https://github.com/KDE/kasts.git
synced 2024-12-25 08:00:48 +01:00
Add command line parameters
This commit is contained in:
parent
2c125c3819
commit
bec24f9436
@ -42,7 +42,7 @@ GenericName[uk]=Читання подач
|
|||||||
GenericName[x-test]=xxFeed Readerxx
|
GenericName[x-test]=xxFeed Readerxx
|
||||||
Encoding=UTF-8
|
Encoding=UTF-8
|
||||||
Icon=alligator
|
Icon=alligator
|
||||||
Exec=alligator
|
Exec=alligator %u
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=Qt;KDE;RSS;
|
Categories=Qt;KDE;RSS;
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "alligatorsettings.h"
|
#include "alligatorsettings.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "fetcher.h"
|
||||||
|
|
||||||
#define TRUE_OR_RETURN(x) \
|
#define TRUE_OR_RETURN(x) \
|
||||||
if (!x) \
|
if (!x) \
|
||||||
@ -122,3 +123,32 @@ void Database::cleanup()
|
|||||||
execute(query);
|
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));
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
}
|
}
|
||||||
bool execute(QSqlQuery &query);
|
bool execute(QSqlQuery &query);
|
||||||
bool execute(QString query);
|
bool execute(QString query);
|
||||||
|
void addFeed(QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Database();
|
Database();
|
||||||
@ -40,4 +41,5 @@ private:
|
|||||||
bool migrate();
|
bool migrate();
|
||||||
bool migrateTo1();
|
bool migrateTo1();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
bool feedExists(QString url);
|
||||||
};
|
};
|
||||||
|
@ -49,21 +49,7 @@ QHash<int, QByteArray> FeedListModel::roleNames() const
|
|||||||
|
|
||||||
void FeedListModel::addFeed(QString url)
|
void FeedListModel::addFeed(QString url)
|
||||||
{
|
{
|
||||||
qDebug() << "Adding feed";
|
Database::instance().addFeed(url);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FeedListModel::data(const QModelIndex &index, int role) const
|
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);
|
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)
|
void FeedListModel::removeFeed(int index)
|
||||||
{
|
{
|
||||||
Fetcher::instance().removeImage(data(createIndex(index, 0), Image).toString());
|
Fetcher::instance().removeImage(data(createIndex(index, 0), Image).toString());
|
||||||
|
@ -44,7 +44,4 @@ public:
|
|||||||
Q_INVOKABLE void addFeed(QString url);
|
Q_INVOKABLE void addFeed(QString url);
|
||||||
Q_INVOKABLE void removeFeed(int index);
|
Q_INVOKABLE void removeFeed(int index);
|
||||||
Q_INVOKABLE QString image(QString url);
|
Q_INVOKABLE QString image(QString url);
|
||||||
|
|
||||||
private:
|
|
||||||
bool feedExists(QString url);
|
|
||||||
};
|
};
|
||||||
|
@ -42,6 +42,8 @@ void Fetcher::fetch(QUrl url)
|
|||||||
{
|
{
|
||||||
qDebug() << "Starting to fetch" << url.toString();
|
qDebug() << "Starting to fetch" << url.toString();
|
||||||
|
|
||||||
|
emit updated();
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply *reply = manager->get(request);
|
QNetworkReply *reply = manager->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
||||||
|
14
src/main.cpp
14
src/main.cpp
@ -27,6 +27,7 @@
|
|||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQuickView>
|
#include <QQuickView>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KLocalizedContext>
|
#include <KLocalizedContext>
|
||||||
@ -60,6 +61,19 @@ int main(int argc, char *argv[])
|
|||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.rootContext()->setContextObject(new KLocalizedContext(&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"));
|
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"));
|
about.addAuthor(i18n("Tobias Fella"), QString(), QStringLiteral("fella@posteo.de"));
|
||||||
KAboutData::setApplicationData(about);
|
KAboutData::setApplicationData(about);
|
||||||
|
Loading…
Reference in New Issue
Block a user