Commit be08ed4e authored by Volker Krause's avatar Volker Krause
Browse files

Use calendar item access utility methods from akonadi-calendar

This completes the move of those methods to akonadi-calendar.
parent f6c18e50
Pipeline #173215 passed with stage
in 5 minutes and 8 seconds
......@@ -42,7 +42,7 @@ set(QT_REQUIRED_VERSION "5.15.2")
set(KMIME_LIB_VERSION "5.20.40")
set(CALENDARUTILS_LIB_VERSION "5.20.40")
set(IDENTITYMANAGEMENT_LIB_VERSION "5.20.40")
set(AKONADICALENDAR_LIB_VERSION "5.20.40")
set(AKONADICALENDAR_LIB_VERSION "5.20.42")
set(AKONADI_VERSION "5.20.40")
set(AKONADI_NOTES_VERSION "5.20.40")
find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED)
......
......@@ -18,9 +18,9 @@
@author Allen Winter \<winter@kde.org\>
*/
#include "attachmenthandler.h"
#include "calendarsupport/utils.h"
#include "calendarsupport_debug.h"
#include <Akonadi/CalendarUtils>
#include <Akonadi/ItemFetchJob>
#include <KIO/FileCopyJob>
......@@ -269,7 +269,7 @@ void AttachmentHandler::slotFinishSaveAs(KJob *job)
auto fetchJob = qobject_cast<ItemFetchJob *>(job);
const Item::List items = fetchJob->items();
if (!items.isEmpty()) {
Incidence::Ptr incidence = CalendarSupport::incidence(items.first());
Incidence::Ptr incidence = Akonadi::CalendarUtils::incidence(items.first());
success = incidence && saveAs(info.attachmentName, incidence);
} else {
qCWarning(CALENDARSUPPORT_LOG) << Q_FUNC_INFO << "No item found";
......@@ -291,7 +291,7 @@ void AttachmentHandler::slotFinishView(KJob *job)
auto fetchJob = qobject_cast<ItemFetchJob *>(job);
const Item::List items = fetchJob->items();
if (!items.isEmpty()) {
Incidence::Ptr incidence = CalendarSupport::incidence(items.first());
Incidence::Ptr incidence = Akonadi::CalendarUtils::incidence(items.first());
success = incidence && view(info.attachmentName, incidence);
} else {
qCWarning(CALENDARSUPPORT_LOG) << Q_FUNC_INFO << "No item found";
......
......@@ -9,7 +9,8 @@
#include "eventarchiver.h"
#include "kcalprefs.h"
#include "utils.h"
#include <Akonadi/CalendarUtils>
#include <Akonadi/IncidenceChanger>
#include <KCalendarCore/FileStorage>
......@@ -145,7 +146,7 @@ void EventArchiver::deleteIncidences(Akonadi::IncidenceChanger *changer, QDate l
Akonadi::Item::List::ConstIterator end(items.constEnd());
incidenceStrs.reserve(items.count());
for (it = items.constBegin(); it != end; ++it) {
incidenceStrs.append(CalendarSupport::incidence(*it)->summary());
incidenceStrs.append(Akonadi::CalendarUtils::incidence(*it)->summary());
}
if (withGUI) {
......
......@@ -14,6 +14,7 @@
#include "incidenceattachmentmodel.h"
#include <Akonadi/CalendarBase>
#include <Akonadi/CalendarUtils>
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/ItemFetchScope>
......@@ -77,7 +78,7 @@ public:
if (mCurrentItem.isValid()) {
text = KCalUtils::IncidenceFormatter::extensiveDisplayStr(CalendarSupport::displayName(mCalendar, mParentCollection),
CalendarSupport::incidence(mCurrentItem),
Akonadi::CalendarUtils::incidence(mCurrentItem),
mDate);
text.prepend(mHeaderText);
mBrowser->setHtml(text);
......@@ -107,7 +108,7 @@ public:
void slotAttachmentUrlClicked(const QString &uri)
{
const QString attachmentName = QString::fromUtf8(QByteArray::fromBase64(uri.mid(7).toUtf8()));
mAttachmentHandler->view(attachmentName, CalendarSupport::incidence(mCurrentItem));
mAttachmentHandler->view(attachmentName, Akonadi::CalendarUtils::incidence(mCurrentItem));
}
Akonadi::ETMCalendar *mCalendar = nullptr;
......
......@@ -15,6 +15,7 @@
#include <cmath>
#include <Akonadi/CalendarUtils>
#include <Akonadi/Item>
#include <KCalendarCore/Visitor>
......@@ -464,7 +465,7 @@ void CalPrintIncidence::print(QPainter &p, int width, int height)
QString datesString;
int count = 0;
for (const Akonadi::Item &item : std::as_const(relations)) {
KCalendarCore::Todo::Ptr todo = CalendarSupport::todo(item);
KCalendarCore::Todo::Ptr todo = Akonadi::CalendarUtils::todo(item);
++count;
if (!todo) { // defensive, skip any zero pointers
continue;
......
......@@ -12,6 +12,7 @@
#include <Akonadi/AgentInstance>
#include <Akonadi/AgentManager>
#include <Akonadi/CalendarUtils>
#include <Akonadi/EntityDisplayAttribute>
#include <Akonadi/EntityTreeModel>
......@@ -41,30 +42,6 @@
#include <QStyle>
#include <QUrlQuery>
KCalendarCore::Incidence::Ptr CalendarSupport::incidence(const Akonadi::Item &item)
{
// relying on exception for performance reasons
try {
return item.payload<KCalendarCore::Incidence::Ptr>();
} catch (const Akonadi::PayloadException &) {
return {};
}
}
KCalendarCore::Event::Ptr CalendarSupport::event(const Akonadi::Item &item)
{
// relying on exception for performance reasons
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (hasEvent(incidence)) {
return item.payload<KCalendarCore::Event::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
KCalendarCore::Event::Ptr CalendarSupport::event(const KCalendarCore::Incidence::Ptr &incidence)
{
if (hasEvent(incidence)) {
......@@ -77,26 +54,13 @@ KCalendarCore::Incidence::List CalendarSupport::incidencesFromItems(const Akonad
{
KCalendarCore::Incidence::List incidences;
for (const Akonadi::Item &item : items) {
if (const KCalendarCore::Incidence::Ptr e = CalendarSupport::incidence(item)) {
if (const KCalendarCore::Incidence::Ptr e = Akonadi::CalendarUtils::incidence(item)) {
incidences.push_back(e);
}
}
return incidences;
}
KCalendarCore::Todo::Ptr CalendarSupport::todo(const Akonadi::Item &item)
{
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (hasTodo(incidence)) {
return item.payload<KCalendarCore::Todo::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
KCalendarCore::Todo::Ptr CalendarSupport::todo(const KCalendarCore::Incidence::Ptr &incidence)
{
if (hasTodo(incidence)) {
......@@ -105,19 +69,6 @@ KCalendarCore::Todo::Ptr CalendarSupport::todo(const KCalendarCore::Incidence::P
return {};
}
KCalendarCore::Journal::Ptr CalendarSupport::journal(const Akonadi::Item &item)
{
try {
auto incidence = item.payload<KCalendarCore::Incidence::Ptr>();
if (hasJournal(incidence)) {
return item.payload<KCalendarCore::Journal::Ptr>();
}
} catch (const Akonadi::PayloadException &) {
return {};
}
return {};
}
KCalendarCore::Journal::Ptr CalendarSupport::journal(const KCalendarCore::Incidence::Ptr &incidence)
{
if (hasJournal(incidence)) {
......@@ -172,7 +123,7 @@ QMimeData *CalendarSupport::createMimeData(const Akonadi::Item::List &items)
QList<QUrl> urls;
int incidencesFound = 0;
for (const Akonadi::Item &item : items) {
const KCalendarCore::Incidence::Ptr incidence(CalendarSupport::incidence(item));
const KCalendarCore::Incidence::Ptr incidence(Akonadi::CalendarUtils::incidence(item));
if (!incidence) {
continue;
}
......@@ -221,7 +172,7 @@ static QByteArray findMostCommonType(const Akonadi::Item::List &items)
if (!CalendarSupport::hasIncidence(item)) {
continue;
}
const QByteArray type = CalendarSupport::incidence(item)->typeStr();
const QByteArray type = Akonadi::CalendarUtils::incidence(item)->typeStr();
if (!prev.isEmpty() && type != prev) {
return "Incidence";
}
......@@ -251,7 +202,7 @@ QDrag *CalendarSupport::createDrag(const Akonadi::Item::List &items, QObject *pa
static bool itemMatches(const Akonadi::Item &item, const KCalendarCore::CalFilter *filter)
{
assert(filter);
KCalendarCore::Incidence::Ptr inc = CalendarSupport::incidence(item);
KCalendarCore::Incidence::Ptr inc = Akonadi::CalendarUtils::incidence(item);
if (!inc) {
return false;
}
......
......@@ -37,16 +37,6 @@ class QMimeData;
namespace CalendarSupport
{
class Calendar;
/**
* returns the incidence from an akonadi item, or a null pointer if the item has no such payload
*/
CALENDARSUPPORT_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
*/
CALENDARSUPPORT_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item);
/**
* returns the event from an incidence, or a null pointer if the item has no such payload
*/
......@@ -57,21 +47,11 @@ CALENDARSUPPORT_EXPORT KCalendarCore::Event::Ptr event(const KCalendarCore::Inci
*/
CALENDARSUPPORT_EXPORT KCalendarCore::Incidence::List incidencesFromItems(const Akonadi::Item::List &items);
/**
* returns the todo from an akonadi item, or a null pointer if the item has no such payload
*/
CALENDARSUPPORT_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item);
/**
* returns the todo from an incidence, or a null pointer if the item has no such payload
*/
CALENDARSUPPORT_EXPORT KCalendarCore::Todo::Ptr todo(const KCalendarCore::Incidence::Ptr &incidence);
/**
* returns the journal from an akonadi item, or a null pointer if the item has no such payload
*/
CALENDARSUPPORT_EXPORT KCalendarCore::Journal::Ptr journal(const Akonadi::Item &item);
/**
* returns the journal from an incidence, or a null pointer if the item has no such payload
*/
......
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