mirror of https://github.com/KDE/kasts.git
First work on datamanager
This commit is contained in:
parent
03573e69c2
commit
8035f0fd60
|
@ -10,6 +10,7 @@ add_executable(alligator
|
|||
enclosure.cpp
|
||||
enclosuredownloadjob.cpp
|
||||
queuemodel.cpp
|
||||
datamanager.cpp
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
|
||||
#include "datamanager.h"
|
||||
#include "fetcher.h"
|
||||
#include "database.h"
|
||||
|
||||
|
||||
DataManager::DataManager()
|
||||
{
|
||||
// Only read unique feedurls and entry ids from the database.
|
||||
// The feed and entry datastructres will be loaded lazily.
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT url FROM Feeds;"));
|
||||
Database::instance().execute(query);
|
||||
while (query.next()) {
|
||||
m_feedmap += query.value(QStringLiteral("url")).toString();
|
||||
}
|
||||
qDebug() << m_feedmap;
|
||||
|
||||
for (auto &feedurl : m_feedmap) {
|
||||
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated;"));
|
||||
query.bindValue(QStringLiteral(":feed"), feedurl);
|
||||
Database::instance().execute(query);
|
||||
while (query.next()) {
|
||||
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
|
||||
}
|
||||
qDebug() << m_entrymap[feedurl];
|
||||
}
|
||||
qDebug() << m_entrymap;
|
||||
}
|
||||
|
||||
Feed* DataManager::getFeed(int const index) const
|
||||
{
|
||||
return getFeed(m_feedmap[index]);
|
||||
}
|
||||
|
||||
Feed* DataManager::getFeed(QString const feedurl) const
|
||||
{
|
||||
if (m_feeds[feedurl] == nullptr)
|
||||
loadFeed(feedurl);
|
||||
return m_feeds[feedurl];
|
||||
}
|
||||
|
||||
void DataManager::loadFeed(QString const feedurl) const
|
||||
{
|
||||
m_feeds[feedurl] = new Feed(feedurl);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "feed.h"
|
||||
#include "entry.h"
|
||||
|
||||
class DataManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static DataManager &instance()
|
||||
{
|
||||
static DataManager _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Feed* getFeed(int const index) const;
|
||||
Feed* getFeed(QString const feedurl) const;
|
||||
|
||||
private:
|
||||
DataManager();
|
||||
void loadFeed(QString feedurl) const;
|
||||
|
||||
QVector<QString> m_feedmap;
|
||||
mutable QHash<QString, Feed*> m_feeds;
|
||||
QHash<QString, QVector<QString> > m_entrymap;
|
||||
mutable QHash<QString, Entry*> m_entries;
|
||||
};
|
|
@ -28,6 +28,7 @@
|
|||
#include "feedsmodel.h"
|
||||
#include "fetcher.h"
|
||||
#include "queuemodel.h"
|
||||
#include "datamanager.h"
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
Q_DECL_EXPORT
|
||||
|
@ -57,6 +58,10 @@ int main(int argc, char *argv[])
|
|||
engine->setObjectOwnership(&Database::instance(), QQmlEngine::CppOwnership);
|
||||
return &Database::instance();
|
||||
});
|
||||
qmlRegisterSingletonType<DataManager>("org.kde.alligator", 1, 0, "DataManager", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
|
||||
engine->setObjectOwnership(&DataManager::instance(), QQmlEngine::CppOwnership);
|
||||
return &DataManager::instance();
|
||||
});
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
|
@ -83,6 +88,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
Database::instance();
|
||||
|
||||
DataManager::instance();
|
||||
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
|
||||
if (engine.rootObjects().isEmpty()) {
|
||||
|
|
Loading…
Reference in New Issue