Commit 8e23c893 authored by Volker Krause's avatar Volker Krause
Browse files

Unify calendar item access utility methods

Those were spread out over the implementation here, and they exist as
public API in calendarsupport. Make those public API here instead.
parent 913b0f66
Pipeline #166926 passed with stage
in 7 minutes and 40 seconds
......@@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.20.41")
set(PIM_VERSION "5.20.42")
project(Akonadi-Calendar VERSION ${PIM_VERSION})
# ECM setup
......
......@@ -7,7 +7,7 @@
#include "etmcalendartest.h"
#include "../src/etmcalendar.h"
#include "../src/utils_p.h"
#include <Akonadi/CalendarUtils>
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/CollectionFetchScope>
#include <Akonadi/CollectionModifyJob>
......@@ -26,17 +26,6 @@ using namespace KCalendarCore;
Q_DECLARE_METATYPE(QSet<QByteArray>)
KCalendarCore::Incidence::Ptr Akonadi::CalendarUtils::incidence(const Akonadi::Item &item)
{
// With this try-catch block, we get a 2x performance improvement in retrieving the payload
// since we don't call hasPayload()
try {
return item.payload<KCalendarCore::Incidence::Ptr>();
} catch (const Akonadi::PayloadException &) {
return {};
}
}
void ETMCalendarTest::createIncidence(const QString &uid)
{
Item item;
......
......@@ -16,6 +16,8 @@ target_sources(KF5AkonadiCalendar PRIVATE
calendarclipboard_p.h
calendarmodel.cpp
calendarmodel_p.h
calendarutils.cpp
calendarutils.h
calfilterpartstatusproxymodel_p.cpp
calfilterpartstatusproxymodel_p.h
calfilterproxymodel_p.cpp
......@@ -139,6 +141,7 @@ ecm_generate_headers(AkonadiCalendar_CamelCase_HEADERS
BlockAlarmsAttribute
CalendarBase
CalendarClipboard
CalendarUtils
ETMCalendar
FetchJobCalendar
FreeBusyManager
......
......@@ -8,8 +8,8 @@
#include "calendarbase.h"
#include "akonadicalendar_debug.h"
#include "calendarbase_p.h"
#include "calendarutils.h"
#include "incidencechanger.h"
#include "utils_p.h"
#include <Akonadi/CollectionFetchJob>
#include <KLocalizedString>
......
......@@ -8,7 +8,7 @@
#include "calendarmodel_p.h"
#include "utils_p.h"
#include "calendarutils.h"
#include <Akonadi/ItemFetchScope>
#include <Akonadi/Monitor>
#include <KCalendarCore/Event>
......@@ -21,11 +21,6 @@
using namespace Akonadi;
static KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item)
{
return item.hasPayload<KCalendarCore::Todo::Ptr>() ? item.payload<KCalendarCore::Todo::Ptr>() : KCalendarCore::Todo::Ptr();
}
class Akonadi::CalendarModelPrivate
{
public:
......@@ -95,21 +90,21 @@ QVariant CalendarModel::entityData(const Akonadi::Item &item, int column, int ro
return inc->dateTime(KCalendarCore::Incidence::RoleEndTimeZone).toString();
case DateTimeDue:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->dtDue().toString();
} else {
return {};
}
case Priority:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->priority();
} else {
return {};
}
case PercentComplete:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->percentComplete();
} else {
return {};
......@@ -134,21 +129,21 @@ QVariant CalendarModel::entityData(const Akonadi::Item &item, int column, int ro
return inc->dateTime(KCalendarCore::Incidence::RoleEndTimeZone).toUTC();
case DateTimeDue:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->dtDue().toUTC();
} else {
return {};
}
case Priority:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->priority();
} else {
return {};
}
case PercentComplete:
if (KCalendarCore::Todo::Ptr t = todo(item)) {
if (KCalendarCore::Todo::Ptr t = CalendarUtils::todo(item)) {
return t->percentComplete();
} else {
return {};
......
/*
SPDX-FileCopyrightText: 2009, 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
SPDX-FileContributor: Frank Osterfeld <osterfeld@kde.org>
SPDX-FileContributor: Andras Mantia <andras@kdab.com>
SPDX-FileCopyrightText: 2010-2012 Sérgio Martins <iamsergio@gmail.com>
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "calendarutils.h"
#include <Akonadi/Item>
using namespace Akonadi;
KCalendarCore::Incidence::Ptr CalendarUtils::incidence(const Akonadi::Item &item)
{
// With this try-catch block, we get a 2x performance improvement in retrieving the payload
// since we don't call hasPayload()
try {
return item.payload<KCalendarCore::Incidence::Ptr>();
} catch (const Akonadi::PayloadException &) {
return {};
}
}
KCalendarCore::Event::Ptr CalendarUtils::event(const Akonadi::Item &item)
{
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (incidence && incidence->type() == KCalCore::Incidence::TypeEvent) {
return item.payload<KCalendarCore::Event::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
KCalendarCore::Todo::Ptr CalendarUtils::todo(const Akonadi::Item &item)
{
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (incidence && incidence->type() == KCalCore::Incidence::TypeTodo) {
return item.payload<KCalendarCore::Todo::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
KCalendarCore::Journal::Ptr CalendarUtils::journal(const Akonadi::Item &item)
{
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (incidence && incidence->type() == KCalCore::Incidence::TypeJournal) {
return item.payload<KCalendarCore::Journal::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
/*
SPDX-FileCopyrightText: 2009, 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
SPDX-FileContributor: Frank Osterfeld <osterfeld@kde.org>
SPDX-FileContributor: Andras Mantia <andras@kdab.com>
SPDX-FileCopyrightText: 2010-2012 Sérgio Martins <iamsergio@gmail.com>
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef AKONADI_CALENDARUTILS_H
#define AKONADI_CALENDARUTILS_H
#include "akonadi-calendar_export.h"
#include <KCalendarCore/Event>
#include <KCalendarCore/Journal>
#include <KCalendarCore/Todo>
namespace Akonadi
{
class Item;
/** Utility methods for dealing with calendar content in Akonadi items.
* @since 5.20.42
*/
namespace CalendarUtils
{
/**
* Returns the incidence from an Akonadi item, or a null pointer if the item has no such payload.
*/
AKONADI_CALENDAR_EXPORT KCalendarCore::Incidence::Ptr incidence(const Akonadi::Item &item);
/**
* Returns the event from an Akonadi item, or a null pointer if the item has no such payload.
*/
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item);
/**
* Returns the todo from an Akonadi item, or a null pointer if the item has no such payload.
*/
AKONADI_CALENDAR_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item);
/**
* Returns the journal from an Akonadi item, or a null pointer if the item has no such payload.
*/
AKONADI_CALENDAR_EXPORT KCalendarCore::Journal::Ptr journal(const Akonadi::Item &item);
}
}
#endif // AKONADI_CALENDARUTILS_H
......@@ -5,6 +5,7 @@
*/
#include "calfilterpartstatusproxymodel_p.h"
#include "calendarutils.h"
#include "utils_p.h"
#include <Akonadi/Collection>
......
......@@ -6,7 +6,7 @@
*/
#include "calfilterproxymodel_p.h"
#include "utils_p.h"
#include "calendarutils.h"
#include <Akonadi/EntityTreeModel>
#include <Akonadi/Item>
......
......@@ -8,11 +8,11 @@
#include "akonadicalendar_debug.h"
#include "blockalarmsattribute.h"
#include "calendarmodel_p.h"
#include "calendarutils.h"
#include "calfilterpartstatusproxymodel_p.h"
#include "calfilterproxymodel_p.h"
#include "etmcalendar_p.h"
#include "kcolumnfilterproxymodel_p.h"
#include "utils_p.h"
#include <Akonadi/CollectionFilterProxyModel>
#include <Akonadi/EntityDisplayAttribute>
#include <Akonadi/EntityMimeTypeFilterModel>
......
......@@ -6,6 +6,7 @@
*/
#include "incidencechanger.h"
#include "akonadicalendar_debug.h"
#include "calendarutils.h"
#include "incidencechanger_p.h"
#include "mailscheduler_p.h"
#include "utils_p.h"
......
......@@ -6,6 +6,7 @@
#include "incidencechanger_p.h"
#include "akonadicalendar_debug.h"
#include "calendarutils.h"
#include "utils_p.h"
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/CollectionFetchScope>
......
......@@ -5,9 +5,9 @@
*/
#include "todopurger.h"
#include "calendarutils.h"
#include "fetchjobcalendar.h"
#include "todopurger_p.h"
#include "utils_p.h"
#include <KCalendarCore/Todo>
......@@ -63,7 +63,7 @@ void TodoPurgerPrivate::deleteTodos()
Akonadi::Item::List toDelete;
m_ignoredItems = 0;
for (const Akonadi::Item &item : items) {
KCalendarCore::Todo::Ptr todo = CalendarUtils::incidence(item).dynamicCast<KCalendarCore::Todo>();
KCalendarCore::Todo::Ptr todo = CalendarUtils::todo(item);
if (!todo || !todo->isCompleted()) {
continue;
......
......@@ -98,14 +98,3 @@ QStringList Akonadi::CalendarUtils::allEmails()
}
return emails;
}
KCalendarCore::Incidence::Ptr Akonadi::CalendarUtils::incidence(const Akonadi::Item &item)
{
// With this try-catch block, we get a 2x performance improvement in retrieving the payload
// since we don't call hasPayload()
try {
return item.payload<KCalendarCore::Incidence::Ptr>();
} catch (const Akonadi::PayloadException &) {
return {};
}
}
......@@ -33,8 +33,6 @@ Q_REQUIRED_RESULT bool thatIsMe(const KCalendarCore::Attendee &attendee);
Q_REQUIRED_RESULT QStringList allEmails();
Q_REQUIRED_RESULT KCalendarCore::Incidence::Ptr incidence(const Akonadi::Item &item);
Q_REQUIRED_RESULT Akonadi::Collection
selectCollection(QWidget *parent, int &dialogCode, const QStringList &mimeTypes, const Akonadi::Collection &defaultCollection = Akonadi::Collection());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment