diff options
Diffstat (limited to 'src/kueapplication.cpp')
| -rw-r--r-- | src/kueapplication.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/kueapplication.cpp b/src/kueapplication.cpp new file mode 100644 index 0000000..b459acf --- /dev/null +++ b/src/kueapplication.cpp @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2024 Alexander Kavon <me+kue@alexkavon.com> + +#include "kueapplication.h" +#include <KAuthorized> +#include <KLocalizedString> +#include <KDescendantsProxyModel> +#include <Akonadi/ServerManager> +#include <Akonadi/Session> +#include <Akonadi/Monitor> +#include <Akonadi/EntityTreeModel> +#include <Akonadi/CollectionFilterProxyModel> +#include <KMime/Message> +#include <QApplication> +#include <QDebug> + +using namespace Qt::StringLiterals; + +KueApplication::KueApplication(QObject *parent) + : AbstractKirigamiApplication(parent) + , m_loading(true) +{ + m_session = new Akonadi::Session(QByteArrayLiteral("Kue Kernel"), this); + + auto monitor = new Akonadi::Monitor(this); + + auto treeModel = new Akonadi::EntityTreeModel(monitor, this); + treeModel->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation); + + auto entityTreeModel = new Akonadi::CollectionFilterProxyModel(this); + entityTreeModel->setSourceModel(treeModel); + entityTreeModel->addMimeTypeFilter(KMime::Message::mimeType()); + + m_descendantsProxyModel = new KDescendantsProxyModel(this); + m_descendantsProxyModel->setSourceModel(entityTreeModel); + qDebug() << m_descendantsProxyModel->rowCount(); + + if (Akonadi::ServerManager::isRunning()) { + m_loading = false; + } else { + connect(Akonadi::ServerManager::self(), &Akonadi::ServerManager::stateChanged, this, [this](Akonadi::ServerManager::State state) { + if (state == Akonadi::ServerManager::Broken) { + qDebug() << "ServerManager Broken"; + qApp->exit(-1); + return; + } + bool loading = state != Akonadi::ServerManager::State::Running; + if (loading == m_loading) { + return; + } + m_loading = loading; + Q_EMIT loadingChanged(); + disconnect(Akonadi::ServerManager::self(), &Akonadi::ServerManager::stateChanged, this, nullptr); + }); + } +} + +bool KueApplication::loading() const +{ + return m_loading; +} + +KDescendantsProxyModel *KueApplication::descendantsProxyModel() const +{ + return m_descendantsProxyModel; +} + +Akonadi::Session *KueApplication::session() const +{ + return m_session; +} + +#include "moc_kueapplication.cpp" |
