Expose Fetcher as QML Singleton

This commit is contained in:
Tobias Fella 2020-05-19 20:37:51 +02:00
parent d68d44faa8
commit a8fb481631
8 changed files with 8 additions and 16 deletions

View File

@ -104,11 +104,6 @@ void EntryListModel::fetch()
Fetcher::instance().fetch(QUrl(m_feed)); Fetcher::instance().fetch(QUrl(m_feed));
} }
QString EntryListModel::image(QString url)
{
return Fetcher::instance().image(url);
}
QString EntryListModel::baseUrl(QString url) QString EntryListModel::baseUrl(QString url)
{ {
return QUrl(url).adjusted(QUrl::RemovePath).toString(); return QUrl(url).adjusted(QUrl::RemovePath).toString();

View File

@ -45,7 +45,6 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void fetch(); Q_INVOKABLE void fetch();
Q_INVOKABLE QString image(QString url);
Q_INVOKABLE QString baseUrl(QString url); Q_INVOKABLE QString baseUrl(QString url);
QString feed() const; QString feed() const;

View File

@ -79,8 +79,3 @@ void FeedListModel::removeFeed(int index)
Database::instance().execute(query); Database::instance().execute(query);
select(); select();
} }
QString FeedListModel::image(QString url)
{
return Fetcher::instance().image(url);
}

View File

@ -43,5 +43,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);
}; };

View File

@ -35,9 +35,9 @@ public:
return _instance; return _instance;
} }
void fetch(QUrl); void fetch(QUrl);
QString image(QString); Q_INVOKABLE QString image(QString);
void removeImage(QString); void removeImage(QString);
void download(QString url); Q_INVOKABLE void download(QString url);
private: private:
Fetcher(); Fetcher();

View File

@ -57,6 +57,10 @@ int main(int argc, char *argv[])
qmlRegisterType<FeedListModel>("org.kde.alligator", 1, 0, "FeedListModel"); qmlRegisterType<FeedListModel>("org.kde.alligator", 1, 0, "FeedListModel");
qmlRegisterType<EntryListModel>("org.kde.alligator", 1, 0, "EntryListModel"); qmlRegisterType<EntryListModel>("org.kde.alligator", 1, 0, "EntryListModel");
qmlRegisterSingletonType<Fetcher>("org.kde.alligator", 1, 0, "Fetcher", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
engine->setObjectOwnership(&Fetcher::instance(), QQmlEngine::CppOwnership);
return &Fetcher::instance();
});
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.rootContext()->setContextObject(new KLocalizedContext(&engine));

View File

@ -77,7 +77,7 @@ Kirigami.ScrollablePage {
height: root.height * 0.2 height: root.height * 0.2
visible: !all visible: !all
Kirigami.Icon { Kirigami.Icon {
source: entryListModel.image(page.image) source: Fetcher.image(page.image)
width: height width: height
height: parent.height height: parent.height
Component.onCompleted: console.log("Height: " + page.height) Component.onCompleted: console.log("Height: " + page.height)

View File

@ -102,7 +102,7 @@ Kirigami.ScrollablePage {
Item { Item {
Kirigami.Icon { Kirigami.Icon {
id: icon id: icon
source: feedListModel.image(model.image) source: Fetcher.image(model.image)
width: height width: height
height: parent.height height: parent.height
} }