Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KAlarm
Commits
e612979b
Commit
e612979b
authored
Sep 27, 2019
by
David Jarvie
Browse files
Move Akonadi object functions out of KAEvent
parent
0e80c04b
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
e612979b
...
...
@@ -3,6 +3,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libkalarmcal5\")
set
(
kalarmcal_LIB_SRCS
kacalendar.cpp
karecurrence.cpp
akonadi.cpp
alarmtext.cpp
identities.cpp
kaevent.cpp
...
...
src/akonadi.cpp
0 → 100644
View file @
e612979b
/*
* akonadi.cpp - Akonadi object functions
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2011,2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
* License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include
"akonadi.h"
#include
"kaevent.h"
#include
<AkonadiCore/Item>
#include
<QStringList>
namespace
KAlarmCal
{
/******************************************************************************
* Initialise an Item with the event.
* Note that the event is not updated with the Item ID.
* Reply = true if successful,
* false if event's category does not match collection's mime types.
*/
bool
setItemPayload
(
Akonadi
::
Item
&
item
,
const
KAEvent
&
event
,
const
QStringList
&
collectionMimeTypes
)
{
QString
mimetype
;
switch
(
event
.
category
())
{
case
CalEvent
::
ACTIVE
:
mimetype
=
MIME_ACTIVE
;
break
;
case
CalEvent
::
ARCHIVED
:
mimetype
=
MIME_ARCHIVED
;
break
;
case
CalEvent
::
TEMPLATE
:
mimetype
=
MIME_TEMPLATE
;
break
;
default:
Q_ASSERT
(
0
);
return
false
;
}
if
(
!
collectionMimeTypes
.
contains
(
mimetype
))
{
return
false
;
}
item
.
setMimeType
(
mimetype
);
item
.
setPayload
<
KAEvent
>
(
event
);
return
true
;
}
}
src/akonadi.h
0 → 100644
View file @
e612979b
/*
* akonadi.h - Akonadi object functions
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2011,2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
* License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef KALARMCAL_AKONADI_H
#define KALARMCAL_AKONADI_H
#include
"kalarmcal_export.h"
class
QStringList
;
namespace
Akonadi
{
class
Item
;
}
namespace
KAlarmCal
{
class
KAEvent
;
/** Initialise an Akonadi::Item with the event's data.
* Note that the event is not updated with the Item ID, and the Item is not
* added to the Collection.
* @param item the Item to initialise.
* @param event the event whose data will be used to intialise the Item.
* @param collectionMimeTypes the mime types for the Collection which will contain the Item.
* @return @c true if successful; @c false if the event's category does not match the
* collection's mime types.
*/
bool
setItemPayload
(
Akonadi
::
Item
&
item
,
const
KAEvent
&
event
,
const
QStringList
&
collectionMimeTypes
);
}
#endif // KALARMCAL_AKONADI_H
src/kacalendar.cpp
View file @
e612979b
...
...
@@ -25,8 +25,6 @@
#include
"kaevent.h"
#include
"version.h"
#include
"collectionattribute.h"
#include
<kcalendarcore/event.h>
#include
<kcalendarcore/alarm.h>
#include
<kcalendarcore/memorycalendar.h>
...
...
@@ -40,7 +38,6 @@
#include
<QTextStream>
using
namespace
KCalendarCore
;
using
Akonadi
::
Collection
;
namespace
KAlarmCal
{
...
...
src/kacalendar.h
View file @
e612979b
...
...
@@ -2,7 +2,7 @@
* kacalendar.h - KAlarm kcal library calendar and event categorisation
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2005-201
2 by
David Jarvie <djarvie@kde.org>
* Copyright © 2005-201
9
David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
...
...
@@ -24,10 +24,12 @@
#define KALARM_KACALENDAR_H
#include
"kalarmcal_export.h"
#include
<kcalendarcore/filestorage.h>
#include
<kcalendarcore/calendar.h>
#include
<kcalendarcore/event.h>
#include
<collection.h>
#include
<AkonadiCore/Collection>
#include
<QByteArray>
#include
<QStringList>
...
...
@@ -45,6 +47,9 @@ extern const QLatin1String KALARMCAL_EXPORT MIME_ACTIVE; //!< The mime type f
extern
const
QLatin1String
KALARMCAL_EXPORT
MIME_ARCHIVED
;
//!< The mime type for KAlarm archived alarms
extern
const
QLatin1String
KALARMCAL_EXPORT
MIME_TEMPLATE
;
//!< The mime type for KAlarm alarm templates
/** Declaration type for a calendar resource ID. */
typedef
Akonadi
::
Collection
::
Id
ResourceId
;
/**
* @short Class representing attributes of a KAlarm calendar.
*
...
...
src/kaevent.cpp
View file @
e612979b
...
...
@@ -22,6 +22,7 @@
#include
"kaevent.h"
#include
"akonadi.h"
// for deprecated setItemPayload() only
#include
"alarmtext.h"
#include
"identities.h"
#include
"version.h"
...
...
@@ -178,8 +179,8 @@ public:
void
activateReminderAfter
(
const
DateTime
&
mainAlarmTime
);
void
defer
(
const
DateTime
&
,
bool
reminder
,
bool
adjustRecurrence
=
false
);
void
cancelDefer
();
bool
setDisplaying
(
const
KAEventPrivate
&
,
KAAlarm
::
Type
,
Akonadi
::
Collection
::
Id
,
const
KADateTime
&
dt
,
bool
showEdit
,
bool
showDefer
);
void
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
,
Akonadi
::
Collection
::
Id
&
,
bool
&
showEdit
,
bool
&
showDefer
);
bool
setDisplaying
(
const
KAEventPrivate
&
,
KAAlarm
::
Type
,
Resource
Id
,
const
KADateTime
&
dt
,
bool
showEdit
,
bool
showDefer
);
void
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
,
Resource
Id
&
,
bool
&
showEdit
,
bool
&
showDefer
);
void
startChanges
()
{
++
mChangeCount
;
...
...
@@ -254,7 +255,7 @@ public:
QString
mTemplateName
;
// alarm template's name, or null if normal event
QMap
<
QByteArray
,
QString
>
mCustomProperties
;
// KCal::Event's non-KAlarm custom properties
Akonadi
::
Item
::
Id
mItemId
;
// Akonadi::Item ID for this event
mutable
Akonadi
::
Collection
::
Id
mCollectionId
;
// ID of collection containing the event, or for a displaying event,
mutable
ResourceId
mResourceId
;
// ID of collection containing the event, or for a displaying event,
// saved collection ID (not the collection the event is in)
QString
mText
;
// message text, file URL, command, email body [or audio file for KAAlarm]
QString
mAudioFile
;
// ATTACH: audio file to play
...
...
@@ -493,7 +494,7 @@ KAEventPrivate::KAEventPrivate()
:
mCommandError
(
KAEvent
::
CMD_NO_ERROR
),
mItemId
(
-
1
),
m
Collection
Id
(
-
1
),
m
Resource
Id
(
-
1
),
mReminderMinutes
(
0
),
mReminderActive
(
NO_REMINDER
),
mRevision
(
0
),
...
...
@@ -577,7 +578,7 @@ void KAEventPrivate::copy(const KAEventPrivate &event)
mTemplateName
=
event
.
mTemplateName
;
mCustomProperties
=
event
.
mCustomProperties
;
mItemId
=
event
.
mItemId
;
m
Collection
Id
=
event
.
m
Collection
Id
;
m
Resource
Id
=
event
.
m
Resource
Id
;
mText
=
event
.
mText
;
mAudioFile
=
event
.
mAudioFile
;
mPreAction
=
event
.
mPreAction
;
...
...
@@ -669,7 +670,7 @@ void KAEventPrivate::set(const KCalendarCore::Event::Ptr &event)
mTemplateName
.
clear
();
mLogFile
.
clear
();
mItemId
=
-
1
;
m
CollectionId
=
-
1
;
m
ResourceId
=
-
1
;
mTemplateAfterTime
=
-
1
;
mBeep
=
false
;
mSpeak
=
false
;
...
...
@@ -710,7 +711,7 @@ void KAEventPrivate::set(const KCalendarCore::Event::Ptr &event)
if
(
n
)
{
const
qlonglong
id
=
params
[
0
].
toLongLong
(
&
ok
);
if
(
ok
)
{
m
Collection
Id
=
id
;
// original collection ID which contained the event
m
Resource
Id
=
id
;
// original collection ID which contained the event
}
for
(
int
i
=
1
;
i
<
n
;
++
i
)
{
if
(
params
[
i
]
==
DISP_DEFER
)
{
...
...
@@ -1131,7 +1132,7 @@ void KAEventPrivate::set(const KADateTime &dateTime, const QString &text, const
mEventID
.
clear
();
mTemplateName
.
clear
();
mItemId
=
-
1
;
m
CollectionId
=
-
1
;
m
ResourceId
=
-
1
;
mPreAction
.
clear
();
mPostAction
.
clear
();
mText
=
(
mActionSubType
==
KAEvent
::
COMMAND
)
?
text
.
trimmed
()
...
...
@@ -1238,7 +1239,7 @@ bool KAEventPrivate::updateKCalEvent(const Event::Ptr &ev, KAEvent::UidAction ui
QString
param
;
if
(
mCategory
==
CalEvent
::
DISPLAYING
)
{
param
=
QString
::
number
(
m
Collection
Id
);
// original collection ID which contained the event
param
=
QString
::
number
(
m
Resource
Id
);
// original collection ID which contained the event
if
(
mDisplayingDefer
)
{
param
+=
SC
+
DISP_DEFER
;
}
...
...
@@ -1789,20 +1790,36 @@ int KAEvent::revision() const
return
d
->
mRevision
;
}
void
KAEvent
::
setResourceId
(
ResourceId
id
)
{
d
->
mResourceId
=
id
;
}
void
KAEvent
::
setResourceId_const
(
ResourceId
id
)
const
{
d
->
mResourceId
=
id
;
}
ResourceId
KAEvent
::
resourceId
()
const
{
// A displaying alarm contains the event's original collection ID
return
d
->
mDisplaying
?
-
1
:
d
->
mResourceId
;
}
void
KAEvent
::
setCollectionId
(
Akonadi
::
Collection
::
Id
id
)
{
d
->
mCollectionId
=
id
;
setResourceId
(
id
)
;
}
void
KAEvent
::
setCollectionId_const
(
Akonadi
::
Collection
::
Id
id
)
const
{
d
->
mCollectionId
=
id
;
setResourceId_const
(
id
)
;
}
Akonadi
::
Collection
::
Id
KAEvent
::
collectionId
()
const
{
// A displaying alarm contains the event's original collection ID
return
d
->
mDisplaying
?
-
1
:
d
->
m
Collection
Id
;
return
d
->
mDisplaying
?
-
1
:
d
->
m
Resource
Id
;
}
void
KAEvent
::
setItemId
(
Akonadi
::
Item
::
Id
id
)
...
...
@@ -1823,19 +1840,7 @@ Akonadi::Item::Id KAEvent::itemId() const
*/
bool
KAEvent
::
setItemPayload
(
Akonadi
::
Item
&
item
,
const
QStringList
&
collectionMimeTypes
)
const
{
QString
mimetype
;
switch
(
d
->
mCategory
)
{
case
CalEvent
::
ACTIVE
:
mimetype
=
MIME_ACTIVE
;
break
;
case
CalEvent
::
ARCHIVED
:
mimetype
=
MIME_ARCHIVED
;
break
;
case
CalEvent
::
TEMPLATE
:
mimetype
=
MIME_TEMPLATE
;
break
;
default:
Q_ASSERT
(
0
);
return
false
;
}
if
(
!
collectionMimeTypes
.
contains
(
mimetype
))
{
return
false
;
}
item
.
setMimeType
(
mimetype
);
item
.
setPayload
<
KAEvent
>
(
*
this
);
return
true
;
return
KAlarmCal
::
setItemPayload
(
item
,
*
this
,
collectionMimeTypes
);
}
void
KAEvent
::
setCompatibility
(
KACalendar
::
Compat
c
)
...
...
@@ -3381,12 +3386,12 @@ KAEvent::OccurType KAEventPrivate::previousOccurrence(const KADateTime &afterDat
* saved in case their end time expires before the next login.
* Reply = true if successful, false if alarm was not copied.
*/
bool
KAEvent
::
setDisplaying
(
const
KAEvent
&
e
,
KAAlarm
::
Type
t
,
Akonadi
::
Collection
::
Id
id
,
const
KADateTime
&
dt
,
bool
showEdit
,
bool
showDefer
)
bool
KAEvent
::
setDisplaying
(
const
KAEvent
&
e
,
KAAlarm
::
Type
t
,
Resource
Id
id
,
const
KADateTime
&
dt
,
bool
showEdit
,
bool
showDefer
)
{
return
d
->
setDisplaying
(
*
e
.
d
,
t
,
id
,
dt
,
showEdit
,
showDefer
);
}
bool
KAEventPrivate
::
setDisplaying
(
const
KAEventPrivate
&
event
,
KAAlarm
::
Type
alarmType
,
Akonadi
::
Collection
::
Id
collection
Id
,
bool
KAEventPrivate
::
setDisplaying
(
const
KAEventPrivate
&
event
,
KAAlarm
::
Type
alarmType
,
ResourceId
resource
Id
,
const
KADateTime
&
repeatAtLoginTime
,
bool
showEdit
,
bool
showDefer
)
{
if
(
!
mDisplaying
...
...
@@ -3402,7 +3407,7 @@ bool KAEventPrivate::setDisplaying(const KAEventPrivate &event, KAAlarm::Type al
// Change the event ID to avoid duplicating the same unique ID as the original event
setCategory
(
CalEvent
::
DISPLAYING
);
mItemId
=
-
1
;
// the display event doesn't have an associated Item
m
Collection
Id
=
collection
Id
;
// original collection ID which contained the event
m
Resource
Id
=
resource
Id
;
// original collection ID which contained the event
mDisplayingDefer
=
showDefer
;
mDisplayingEdit
=
showEdit
;
mDisplaying
=
true
;
...
...
@@ -3424,19 +3429,19 @@ bool KAEventPrivate::setDisplaying(const KAEventPrivate &event, KAAlarm::Type al
/******************************************************************************
* Reinstate the original event from the 'displaying' event.
*/
void
KAEvent
::
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
e
,
Akonadi
::
Collection
::
Id
&
id
,
bool
&
showEdit
,
bool
&
showDefer
)
void
KAEvent
::
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
e
,
Resource
Id
&
id
,
bool
&
showEdit
,
bool
&
showDefer
)
{
d
->
reinstateFromDisplaying
(
e
,
id
,
showEdit
,
showDefer
);
}
void
KAEventPrivate
::
reinstateFromDisplaying
(
const
Event
::
Ptr
&
kcalEvent
,
Akonadi
::
Collection
::
Id
&
collection
Id
,
bool
&
showEdit
,
bool
&
showDefer
)
void
KAEventPrivate
::
reinstateFromDisplaying
(
const
Event
::
Ptr
&
kcalEvent
,
ResourceId
&
resource
Id
,
bool
&
showEdit
,
bool
&
showDefer
)
{
set
(
kcalEvent
);
if
(
mDisplaying
)
{
// Retrieve the original event's unique ID
setCategory
(
CalEvent
::
ACTIVE
);
collection
Id
=
m
Collection
Id
;
m
Collection
Id
=
-
1
;
resource
Id
=
m
Resource
Id
;
m
Resource
Id
=
-
1
;
showDefer
=
mDisplayingDefer
;
showEdit
=
mDisplayingEdit
;
mDisplaying
=
false
;
...
...
@@ -3812,7 +3817,7 @@ void KAEventPrivate::dumpDebug() const
qCDebug
(
KALARMCAL_LOG
)
<<
"-- mConfirmAck:"
<<
mConfirmAck
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- mEnabled:"
<<
mEnabled
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- mItemId:"
<<
mItemId
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- m
CollectionId:"
<<
mCollection
Id
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- m
ResourceId:"
<<
mResource
Id
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- mCompatibility:"
<<
mCompatibility
;
qCDebug
(
KALARMCAL_LOG
)
<<
"-- mReadOnly:"
<<
mReadOnly
;
if
(
mReminderMinutes
)
{
...
...
src/kaevent.h
View file @
e612979b
...
...
@@ -457,8 +457,13 @@ public:
/** Return the revision number of the event (SEQUENCE property in iCalendar). */
int
revision
()
const
;
/** Set the ID of the Akonadi Collection which contains the event. */
void
setCollectionId
(
Akonadi
::
Collection
::
Id
id
);
/** Set the ID of the Akonadi Collection which contains the event.
* @deprecated Use setResourceId() instead.
*/
KALARMCAL_DEPRECATED
void
setCollectionId
(
Akonadi
::
Collection
::
Id
id
);
/** Set the ID of the calendar resource which contains the event. */
void
setResourceId
(
ResourceId
id
);
/** Set the ID of the Akonadi Collection which contains the event.
* @warning This is a const method, which means that any other instance
...
...
@@ -466,11 +471,26 @@ public:
* updated. It is designed to be used when a KAEvent is
* being created from an Akonadi Item, to avoid unnecessary
* copying. Use with caution!
* @deprecated Use setResourceId_const() instead.
*/
KALARMCAL_DEPRECATED
void
setCollectionId_const
(
Akonadi
::
Collection
::
Id
id
)
const
;
/** Set the ID of the Akonadi Collection which contains the event.
* @warning This is a const method, which means that any other instance
* which references the same shared data will also be
* updated. It is designed to be used when a KAEvent is
* being created from an Akonadi Item, to avoid unnecessary
* copying. Use with caution!
*/
void
setResourceId_const
(
ResourceId
id
)
const
;
/** Return the ID of the Akonadi Collection which contains the event.
* @deprecated Use resourceId() instead.
*/
void
setCollectionId_const
(
Akonadi
::
Collection
::
Id
id
)
const
;
KALARMCAL_DEPRECATED
Akonadi
::
Collection
::
Id
collectionId
(
)
const
;
/** Return the ID of the
Akonadi Collection
which contains the event. */
Akonadi
::
Collection
::
Id
collection
Id
()
const
;
/** Return the ID of the
calendar resource
which contains the event. */
ResourceId
resource
Id
()
const
;
/** Set the ID of the Akonadi Item which contains the event. */
void
setItemId
(
Akonadi
::
Item
::
Id
id
);
...
...
@@ -482,8 +502,9 @@ public:
* Note that the event is not updated with the Item ID.
* @return @c true if successful; @c false if the event's category does not match the
* collection's mime types.
* @deprecated Use KAlarmCal::setItemPayload() instead.
*/
bool
setItemPayload
(
Akonadi
::
Item
&
,
const
QStringList
&
collectionMimeTypes
)
const
;
KALARMCAL_DEPRECATED
bool
setItemPayload
(
Akonadi
::
Item
&
,
const
QStringList
&
collectionMimeTypes
)
const
;
/** Note the event's storage format compatibility compared to the current KAlarm calendar format. */
void
setCompatibility
(
KACalendar
::
Compat
c
);
...
...
@@ -1192,24 +1213,25 @@ public:
* saved in case their end time expires before the next login.
* @param event the event to copy
* @param type the alarm type (main, reminder, deferred etc.)
* @param colId the ID of the c
ollection
which originally contained the event
* @param colId the ID of the c
alendar resource
which originally contained the event
* @param repeatAtLoginTime repeat-at-login time if @p type == AT_LOGIN_ALARM, else ignored
* @param showEdit whether the Edit button was displayed
* @param showDefer whether the Defer button was displayed
* @return @c true if successful, @c false if alarm was not copied.
*/
bool
setDisplaying
(
const
KAEvent
&
event
,
KAAlarm
::
Type
type
,
Akonadi
::
Collection
::
Id
colId
,
const
KADateTime
&
repeatAtLoginTime
,
bool
showEdit
,
bool
showDefer
);
bool
setDisplaying
(
const
KAEvent
&
event
,
KAAlarm
::
Type
type
,
Resource
Id
colId
,
const
KADateTime
&
repeatAtLoginTime
,
bool
showEdit
,
bool
showDefer
);
/** Reinstate the original event from the 'displaying' event.
* This instance is initialised from the supplied displaying @p event,
* and appropriate adjustments are made to convert it back to the
* original pre-displaying state.
* @param event the displaying event
* @param colId updated to the ID of the collection which originally contained the event
* @param colId updated to the ID of the calendar resource which
* originally contained the event
* @param showEdit updated to true if Edit button was displayed, else false
* @param showDefer updated to true if Defer button was displayed, else false
*/
void
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
event
,
Akonadi
::
Collection
::
Id
&
colId
,
bool
&
showEdit
,
bool
&
showDefer
);
void
reinstateFromDisplaying
(
const
KCalendarCore
::
Event
::
Ptr
&
event
,
Resource
Id
&
colId
,
bool
&
showEdit
,
bool
&
showDefer
);
/** Return the original alarm which the displaying alarm refers to.
* Note that the caller is responsible for ensuring that the event was
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment