Akonadi Calendar

fetchjobcalendar.cpp
1 /*
2  Copyright (C) 2011 Sérgio Martins <[email protected]>
3  Copyright (C) 2012 Sérgio Martins <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "fetchjobcalendar.h"
22 #include "fetchjobcalendar_p.h"
23 #include "incidencefetchjob_p.h"
24 #include "akonadicalendar_debug.h"
25 #include <item.h>
26 #include <collection.h>
27 
28 using namespace Akonadi;
29 using namespace KCalendarCore;
30 
31 FetchJobCalendarPrivate::FetchJobCalendarPrivate(FetchJobCalendar *qq)
32  : CalendarBasePrivate(qq)
33  , m_isLoaded(false)
34  , q(qq)
35 {
36  IncidenceFetchJob *job = new IncidenceFetchJob();
37  connect(job, &KJob::result,
38  this, &FetchJobCalendarPrivate::slotSearchJobFinished);
39  connect(this, &CalendarBasePrivate::fetchFinished,
40  this, &FetchJobCalendarPrivate::slotFetchJobFinished);
41 }
42 
43 FetchJobCalendarPrivate::~FetchJobCalendarPrivate()
44 {
45 }
46 
47 void FetchJobCalendarPrivate::slotSearchJobFinished(KJob *job)
48 {
49  IncidenceFetchJob *searchJob = static_cast<Akonadi::IncidenceFetchJob *>(job);
50  m_success = true;
51  m_errorMessage = QString();
52  if (searchJob->error()) {
53  m_success = false;
54  m_errorMessage = searchJob->errorText();
55  qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << searchJob->errorText();
56  } else {
57  const Akonadi::Item::List lstItem = searchJob->items();
58  for (const Akonadi::Item &item : lstItem) {
59  if (!item.isValid() || !item.hasPayload<KCalendarCore::Incidence::Ptr>()) {
60  m_success = false;
61  m_errorMessage = QStringLiteral("Invalid item or payload: %1").arg(item.id());
62  qCWarning(AKONADICALENDAR_LOG) << "Unable to fetch incidences:" << m_errorMessage;
63  continue;
64  }
65  internalInsert(item);
66  }
67  }
68 
69  if (mCollectionJobs.isEmpty()) {
70  slotFetchJobFinished();
71  }
72 }
73 
74 void FetchJobCalendarPrivate::slotFetchJobFinished()
75 {
76  m_isLoaded = true;
77  // Q_EMIT loadFinished() in a delayed manner, due to freezes because of execs.
78  QMetaObject::invokeMethod(q, "loadFinished", Qt::QueuedConnection,
79  Q_ARG(bool, m_success), Q_ARG(QString, m_errorMessage));
80 }
81 
83  : CalendarBase(new FetchJobCalendarPrivate(this), parent)
84 {
85 }
86 
88 {
89 }
90 
92 {
93  FetchJobCalendarPrivate *d = static_cast<FetchJobCalendarPrivate *>(d_ptr.data());
94  return d->m_isLoaded;
95 }
96 
97 #include "moc_fetchjobcalendar.cpp"
98 #include "moc_fetchjobcalendar_p.cpp"
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...
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:48
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-2020 The KDE developers.
Generated on Tue May 26 2020 22:41:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.