Akonadi Calendar

fetchjobcalendar.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Sérgio Martins <sergio.martins@kdab.com>
3 SPDX-FileCopyrightText: 2012 Sérgio Martins <iamsergio@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "fetchjobcalendar.h"
9#include "akonadicalendar_debug.h"
10#include "fetchjobcalendar_p.h"
11#include "incidencefetchjob_p.h"
12#include <Akonadi/Collection>
13
14using namespace Akonadi;
15using namespace KCalendarCore;
16
17FetchJobCalendarPrivate::FetchJobCalendarPrivate(FetchJobCalendar *qq)
18 : CalendarBasePrivate(qq)
19 , q(qq)
20{
21 auto job = new IncidenceFetchJob();
22 connect(job, &KJob::result, this, &FetchJobCalendarPrivate::slotSearchJobFinished);
23 connect(this, &CalendarBasePrivate::fetchFinished, this, &FetchJobCalendarPrivate::slotFetchJobFinished);
24}
25
26FetchJobCalendarPrivate::~FetchJobCalendarPrivate() = default;
27
28void FetchJobCalendarPrivate::slotSearchJobFinished(KJob *job)
29{
30 auto searchJob = static_cast<Akonadi::IncidenceFetchJob *>(job);
31 m_success = true;
32 m_errorMessage = QString();
33 if (searchJob->error()) {
34 m_success = false;
35 m_errorMessage = searchJob->errorText();
36 qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << searchJob->errorText();
37 } else {
38 const Akonadi::Item::List lstItem = searchJob->items();
39 for (const Akonadi::Item &item : lstItem) {
40 if (!item.isValid() || !item.hasPayload<KCalendarCore::Incidence::Ptr>()) {
41 m_success = false;
42 m_errorMessage = QStringLiteral("Invalid item or payload: %1").arg(item.id());
43 qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << m_errorMessage;
44 continue;
45 }
46 internalInsert(item);
47 }
48 }
49
50 if (mCollectionJobs.isEmpty()) {
51 slotFetchJobFinished();
52 }
53}
54
55void FetchJobCalendarPrivate::slotFetchJobFinished()
56{
57 q->setIsLoading(false);
58 // Q_EMIT loadFinished() in a delayed manner, due to freezes because of execs.
59 QMetaObject::invokeMethod(q, "loadFinished", Qt::QueuedConnection, Q_ARG(bool, m_success), Q_ARG(QString, m_errorMessage));
60}
61
63 : CalendarBase(new FetchJobCalendarPrivate(this), parent)
64{
65 setIsLoading(true);
66}
67
69
70#include "moc_fetchjobcalendar.cpp"
71#include "moc_fetchjobcalendar_p.cpp"
The base class for all akonadi aware calendars.
A KCalendarCore::Calendar that uses a one time IncidenceFetchJob to populate itself.
FetchJobCalendar(QObject *parent=nullptr)
Creates a new FetchJobCalendar.
~FetchJobCalendar() override
Destroys this FetchJobCalendar.
void setIsLoading(bool isLoading)
void result(KJob *job)
FreeBusyManager::Singleton.
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QueuedConnection
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 11:56:25 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.