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 <collection.h>
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()
27 {
28 }
29 
30 void FetchJobCalendarPrivate::slotSearchJobFinished(KJob *job)
31 {
32  auto searchJob = static_cast<Akonadi::IncidenceFetchJob *>(job);
33  m_success = true;
34  m_errorMessage = QString();
35  if (searchJob->error()) {
36  m_success = false;
37  m_errorMessage = searchJob->errorText();
38  qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << searchJob->errorText();
39  } else {
40  const Akonadi::Item::List lstItem = searchJob->items();
41  for (const Akonadi::Item &item : lstItem) {
43  m_success = false;
44  m_errorMessage = QStringLiteral("Invalid item or payload: %1").arg(item.id());
45  qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << m_errorMessage;
46  continue;
47  }
48  internalInsert(item);
49  }
50  }
51 
52  if (mCollectionJobs.isEmpty()) {
53  slotFetchJobFinished();
54  }
55 }
56 
57 void FetchJobCalendarPrivate::slotFetchJobFinished()
58 {
59  m_isLoaded = true;
60  // Q_EMIT loadFinished() in a delayed manner, due to freezes because of execs.
61  QMetaObject::invokeMethod(q, "loadFinished", Qt::QueuedConnection, Q_ARG(bool, m_success), Q_ARG(QString, m_errorMessage));
62 }
63 
65  : CalendarBase(new FetchJobCalendarPrivate(this), parent)
66 {
67 }
68 
70 {
71 }
72 
74 {
75  auto d = static_cast<FetchJobCalendarPrivate *>(d_ptr.data());
76  return d->m_isLoaded;
77 }
78 
79 #include "moc_fetchjobcalendar.cpp"
80 #include "moc_fetchjobcalendar_p.cpp"
bool isValid() const
Akonadi::Item item(const QString &uid) const
Returns the Item containing the incidence with uid uid or an invalid Item if the incidence isn&#39;t foun...
Id id() const
FetchJobCalendar(QObject *parent=nullptr)
Creates a new FetchJobCalendar.
T * data() const const
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.
FreeBusyManager::Singleton.
bool isLoaded() const override
Returns if the calendar already finished loading.
A KCalendarCore::Calendar that uses a one time IncidenceFetchJob to populate itself.
void result(KJob *job)
The base class for all akonadi aware calendars.
Definition: calendarbase.h:35
bool hasPayload() const
QueuedConnection
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun May 16 2021 23:12:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.