Akonadi Calendar

fetchjobcalendar.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Sérgio Martins <[email protected]>
3  SPDX-FileCopyrightText: 2012 Sérgio Martins <[email protected]>
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 
14 using namespace Akonadi;
15 using namespace KCalendarCore;
16 
17 FetchJobCalendarPrivate::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 
26 FetchJobCalendarPrivate::~FetchJobCalendarPrivate() = default;
27 
28 void 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 
55 void 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"
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QueuedConnection
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
~FetchJobCalendar() override
Destroys this FetchJobCalendar.
FetchJobCalendar(QObject *parent=nullptr)
Creates a new FetchJobCalendar.
A KCalendarCore::Calendar that uses a one time IncidenceFetchJob to populate itself.
void setIsLoading(bool isLoading)
The base class for all akonadi aware calendars.
Definition: calendarbase.h:37
FreeBusyManager::Singleton.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Dec 11 2023 03:52:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.