Commit 574157ab authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Incidence wrapper is now an ItemMonitor, letting us update incidence info...

Incidence wrapper is now an ItemMonitor, letting us update incidence info automatically when they change in calendars
parent f10fccbf
Pipeline #100939 passed with stage
in 6 minutes
......@@ -659,6 +659,11 @@ QVariantMap CalendarManager::undoRedoData()
};
}
Akonadi::Item CalendarManager::incidenceItem(KCalendarCore::Incidence::Ptr incidence)
{
return m_calendar->item(incidence);
}
void CalendarManager::addIncidence(IncidenceWrapper *incidenceWrapper)
{
Akonadi::Collection collection(incidenceWrapper->collectionId());
......
......@@ -76,6 +76,7 @@ public:
Q_INVOKABLE int getCalendarSelectableIndex(IncidenceWrapper *incidenceWrapper);
QVariantMap undoRedoData();
Q_INVOKABLE Akonadi::Item incidenceItem(KCalendarCore::Incidence::Ptr incidence);
Q_INVOKABLE void addIncidence(IncidenceWrapper *incidenceWrapper);
Q_INVOKABLE void editIncidence(IncidenceWrapper *incidenceWrapper);
Q_INVOKABLE void updateIncidenceDates(IncidenceWrapper *incidenceWrapper,
......
......@@ -14,7 +14,7 @@ Kirigami.OverlayDrawer {
id: incidenceInfo
signal addSubTodo(var parentWrapper)
signal editIncidence(var incidencePtr, var collectionId)
signal editIncidence(var incidencePtr)
signal deleteIncidence(var incidencePtr, date deleteDate)
signal tagClicked(string tagName)
......@@ -51,11 +51,11 @@ Kirigami.OverlayDrawer {
}
}
onIncidenceDataChanged: {
incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
incidenceInfo, "incidence");
incidenceWrapper.incidencePtr = incidenceData.incidencePtr;
incidenceWrapper.incidenceItem = CalendarManager.incidenceItem(incidenceData.incidencePtr);
collectionData = CalendarManager.getCollectionDetails(incidenceWrapper.collectionId);
}
enabled: true
......@@ -106,7 +106,6 @@ Kirigami.OverlayDrawer {
text: i18n("Add Sub-Task")
visible: incidenceInfo.incidenceWrapper.incidenceType === IncidenceWrapper.TypeTodo
onTriggered: {
incidenceInfo.incidenceWrapper.collectionId = collectionData.id;
addSubTodo(incidenceInfo.incidenceWrapper);
}
},
......@@ -124,7 +123,7 @@ Kirigami.OverlayDrawer {
icon.name: "edit-entry"
text: i18n("Edit")
enabled: incidenceInfo.collectionData && !incidenceInfo.collectionData.readOnly
onTriggered: editIncidence(incidenceInfo.incidenceData.incidencePtr, incidenceInfo.incidenceData.collectionId)
onTriggered: editIncidence(incidenceInfo.incidenceData.incidencePtr)
},
Kirigami.Action {
icon.name: "edit-delete"
......@@ -160,7 +159,7 @@ Kirigami.OverlayDrawer {
Kirigami.Heading {
Layout.fillWidth: true
text: "<b>" + incidenceInfo.incidenceData.text + "</b>"
text: "<b>" + incidenceInfo.incidenceWrapper.summary + "</b>"
wrapMode: Text.Wrap
}
Kirigami.Icon {
......@@ -180,7 +179,7 @@ Kirigami.OverlayDrawer {
Layout.fillWidth: true
height: Kirigami.Units.gridUnit / 2
color: incidenceInfo.incidenceData.color
color: incidenceInfo.collectionData.color
}
ColumnLayout {
......
......@@ -10,8 +10,8 @@ import org.kde.kalendar 1.0 as Kalendar
MouseArea {
id: mouseArea
signal viewClicked(var incidenceData, var collectionData)
signal editClicked(var incidencePtr, var collectionId)
signal viewClicked(var incidenceData)
signal editClicked(var incidencePtr)
signal deleteClicked(var incidencePtr, date deleteDate)
signal todoCompletedClicked(var incidencePtr)
signal addSubTodoClicked(var parentWrapper)
......@@ -19,7 +19,7 @@ MouseArea {
property double clickX
property double clickY
property var incidenceData
property var collectionId
property int collectionId
property var collectionDetails
anchors.fill: parent
......@@ -27,8 +27,8 @@ MouseArea {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button == Qt.LeftButton) {
collectionDetails = Kalendar.CalendarManager.getCollectionDetails(collectionId)
viewClicked(incidenceData, collectionDetails);
collectionDetails = Kalendar.CalendarManager.getCollectionDetails(mouseArea.collectionId)
viewClicked(incidenceData);
} else if (mouse.button == Qt.RightButton) {
clickX = mouseX;
clickY = mouseY;
......@@ -41,8 +41,8 @@ MouseArea {
incidenceActions.createObject(mouseArea, {}).open();
}
onDoubleClicked: {
collectionDetails = Kalendar.CalendarManager.getCollectionDetails(collectionId);
editClicked(incidenceData.incidencePtr, incidenceData.collectionId);
collectionDetails = Kalendar.CalendarManager.getCollectionDetails(mouseArea.collectionId)
editClicked(incidenceData.incidencePtr);
}
Component {
......@@ -57,13 +57,13 @@ MouseArea {
QQC2.MenuItem {
icon.name: "dialog-icon-preview"
text:i18n("View")
onClicked: viewClicked(incidenceData, collectionDetails);
onClicked: viewClicked(incidenceData);
}
QQC2.MenuItem {
icon.name: "edit-entry"
text:i18n("Edit")
enabled: !mouseArea.collectionDetails["readOnly"]
onClicked: editClicked(incidenceData.incidencePtr, incidenceData.collectionId)
onClicked: editClicked(incidenceData.incidencePtr)
}
QQC2.MenuItem {
icon.name: "edit-delete"
......@@ -87,8 +87,7 @@ MouseArea {
enabled: !mouseArea.collectionDetails["readOnly"]
onClicked: {
let parentWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', this, "incidence");
parentWrapper.incidencePtr = mouseArea.incidenceData.incidencePtr;
parentWrapper.collectionId = mouseArea.collectionDetails.id;
parentWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(mouseArea.incidenceData.incidencePtr);
addSubTodoClicked(parentWrapper);
}
visible: incidenceData.incidenceType === Kalendar.IncidenceWrapper.TypeTodo
......
......@@ -15,8 +15,8 @@ Kirigami.Page {
id: monthPage
signal addIncidence(int type, date addDate)
signal viewIncidence(var modelData, var collectionData)
signal editIncidence(var incidencePtr, var collectionId)
signal viewIncidence(var modelData)
signal editIncidence(var incidencePtr)
signal deleteIncidence(var incidencePtr, date deleteDate)
signal completeTodo(var incidencePtr)
signal addSubTodo(var parentWrapper)
......@@ -209,8 +209,8 @@ Kirigami.Page {
openOccurrence: monthPage.openOccurrence
onAddIncidence: monthPage.addIncidence(type, addDate)
onViewIncidence: monthPage.viewIncidence(modelData, collectionData)
onEditIncidence: monthPage.editIncidence(incidencePtr, collectionId)
onViewIncidence: monthPage.viewIncidence(modelData)
onEditIncidence: monthPage.editIncidence(incidencePtr)
onDeleteIncidence: monthPage.deleteIncidence(incidencePtr, deleteDate)
onCompleteTodo: monthPage.completeTodo(incidencePtr)
onAddSubTodo: monthPage.addSubTodo(parentWrapper)
......
......@@ -16,8 +16,8 @@ Item {
id: root
signal addIncidence(int type, date addDate)
signal viewIncidence(var modelData, var collectionData)
signal editIncidence(var incidencePtr, var collectionId)
signal viewIncidence(var modelData)
signal editIncidence(var incidencePtr)
signal deleteIncidence(var incidencePtr, date deleteDate)
signal completeTodo(var incidencePtr)
signal addSubTodo(var parentWrapper)
......@@ -168,8 +168,7 @@ Item {
drop.source.caught = true;
const incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', incidenceDropArea, "incidence");
incidenceWrapper.incidencePtr = drop.source.incidencePtr;
incidenceWrapper.collectionId = drop.source.collectionId;
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.incidencePtr);
let sameTimeOnDate = new Date(backgroundDayMouseArea.addDate);
sameTimeOnDate = new Date(sameTimeOnDate.setHours(drop.source.occurrenceDate.getHours(), drop.source.occurrenceDate.getMinutes()));
......
......@@ -56,7 +56,6 @@ Rectangle {
property bool isDark: false
property alias mouseArea: mouseArea
property var incidencePtr: modelData.incidencePtr
property var collectionId: modelData.collectionId
property date occurrenceDate: modelData.startTime
property date occurrenceEndDate: modelData.endTime
property bool repositionAnimationEnabled: false
......@@ -162,8 +161,8 @@ Rectangle {
drag.target: !Kirigami.Settings.isMobile && !modelData.isReadOnly ? parent : undefined
onReleased: parent.Drag.drop()
onViewClicked: viewIncidence(modelData, collectionData)
onEditClicked: editIncidence(incidencePtr, collectionId)
onViewClicked: viewIncidence(modelData)
onEditClicked: editIncidence(incidencePtr)
onDeleteClicked: deleteIncidence(incidencePtr, deleteDate)
onTodoCompletedClicked: completeTodo(incidencePtr)
onAddSubTodoClicked: root.addSubTodo(parentWrapper)
......
......@@ -15,8 +15,8 @@ Kirigami.Page {
id: root
signal addIncidence(int type, date addDate)
signal viewIncidence(var modelData, var collectionData)
signal editIncidence(var incidencePtr, var collectionId)
signal viewIncidence(var modelData)
signal editIncidence(var incidencePtr)
signal deleteIncidence(var incidencePtr, date deleteDate)
signal completeTodo(var incidencePtr)
signal addSubTodo(var parentWrapper)
......@@ -257,8 +257,7 @@ Kirigami.Page {
drop.source.caught = true;
const incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', incidenceDropArea, "incidence");
incidenceWrapper.incidencePtr = drop.source.incidencePtr;
incidenceWrapper.collectionId = drop.source.collectionId;
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.incidencePtr);
let sameTimeOnDate = new Date(dayMouseArea.addDate);
sameTimeOnDate = new Date(sameTimeOnDate.setHours(drop.source.occurrenceDate.getHours(), drop.source.occurrenceDate.getMinutes()));
......@@ -399,7 +398,6 @@ Kirigami.Page {
property alias mouseArea: incidenceMouseArea
property var incidencePtr: modelData.incidencePtr
property var collectionId: modelData.collectionId
property date occurrenceDate: modelData.startTime
property date occurrenceEndDate: modelData.endTime
property bool repositionAnimationEnabled: false
......@@ -576,8 +574,8 @@ Kirigami.Page {
drag.target: !Kirigami.Settings.isMobile && !modelData.isReadOnly ? incidenceCard : undefined
onReleased: incidenceCard.Drag.drop()
onViewClicked: root.viewIncidence(modelData, collectionData)
onEditClicked: root.editIncidence(incidencePtr, collectionId)
onViewClicked: root.viewIncidence(modelData)
onEditClicked: root.editIncidence(incidencePtr)
onDeleteClicked: root.deleteIncidence(incidencePtr, deleteDate)
onTodoCompletedClicked: root.completeTodo(incidencePtr)
onAddSubTodoClicked: root.addSubTodo(parentWrapper)
......
......@@ -18,27 +18,25 @@ Kirigami.ScrollablePage {
id: root
signal addTodo(int collectionId)
signal viewTodo(var todoData, var collectionData)
signal editTodo(var todoPtr, int collectionId)
signal viewTodo(var todoData)
signal editTodo(var todoPtr)
signal deleteTodo(var todoPtr, date deleteDate)
signal completeTodo(var todoPtr)
signal addSubTodo(var parentWrapper)
signal deselect
// We need to store a copy of opened incidence data or we will lose it as we scroll the listviews.
function retainTodoData(todoData, collectionData) {
function retainTodoData(todoData) {
retainedTodoData = {
incidencePtr: todoData.incidencePtr,
incidenceId: todoData.incidenceId,
collectionId: collectionData.id,
text: todoData.text,
color: todoData.color,
startTime: todoData.startTime,
endTime: todoData.endTime,
durationString: todoData.durationString
};
retainedCollectionData = Kalendar.CalendarManager.getCollectionDetails(collectionData.id);
viewTodo(retainedTodoData, retainedCollectionData);
viewTodo(retainedTodoData);
}
property var retainedTodoData: {}
......@@ -144,11 +142,11 @@ Kirigami.ScrollablePage {
completedSheet.closeDialog();
}
onViewTodo: {
root.retainTodoData(todoData, collectionData);
root.retainTodoData(todoData);
completedSheet.closeDialog();
}
onEditTodo: {
root.editTodo(todoPtr, collectionId);
root.editTodo(todoPtr);
completedSheet.closeDialog();
}
onDeleteTodo: {
......@@ -191,8 +189,8 @@ Kirigami.ScrollablePage {
sortBy: root.sortBy
ascendingOrder: root.ascendingOrder
onAddTodo: root.addTodo(collectionId)
onViewTodo: root.retainTodoData(todoData, collectionData)
onEditTodo: root.editTodo(todoPtr, collectionId)
onViewTodo: root.retainTodoData(todoData)
onEditTodo: root.editTodo(todoPtr)
onDeleteTodo: root.deleteTodo(todoPtr, deleteDate)
onCompleteTodo: root.completeTodo(todoPtr);
onAddSubTodo: root.addSubTodo(parentWrapper)
......
......@@ -16,8 +16,8 @@ TreeListView {
id: root
signal addTodo(int collectionId)
signal viewTodo(var todoData, var collectionData)
signal editTodo(var todoPtr, var collectionId)
signal viewTodo(var todoData)
signal editTodo(var todoPtr)
signal deleteTodo(var todoPtr, date deleteDate)
signal completeTodo(var todoPtr)
signal addSubTodo(var parentWrapper)
......@@ -152,8 +152,8 @@ TreeListView {
collectionId: model.collectionId
propagateComposedEvents: true
onViewClicked: root.viewTodo(model, collectionDetails), listItem.clicked()
onEditClicked: root.editTodo(model.incidencePtr, model.collectionId)
onViewClicked: root.viewTodo(model), listItem.clicked()
onEditClicked: root.editTodo(model.incidencePtr)
onDeleteClicked: root.deleteTodo(model.incidencePtr, model.endTime ? model.endTime : model.startTime ? model.startTime : null)
onTodoCompletedClicked: model.checked = model.checked === 0 ? 2 : 0
onAddSubTodoClicked: root.addSubTodo(parentWrapper)
......@@ -267,6 +267,6 @@ TreeListView {
}
}
onClicked: root.viewTodo(model, Kalendar.CalendarManager.getCollectionDetails(model.collectionId))
onClicked: root.viewTodo(model)
}
}
......@@ -15,8 +15,8 @@ Kirigami.Page {
id: root
signal addIncidence(int type, date addDate, bool includeTime)
signal viewIncidence(var modelData, var collectionData)
signal editIncidence(var incidencePtr, var collectionId)
signal viewIncidence(var modelData)
signal editIncidence(var incidencePtr)
signal deleteIncidence(var incidencePtr, date deleteDate)
signal completeTodo(var incidencePtr)
signal addSubTodo(var parentWrapper)
......@@ -446,8 +446,7 @@ Kirigami.Page {
drop.source.caught = true;
const incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', incidenceDropArea, "incidence");
incidenceWrapper.incidencePtr = drop.source.incidencePtr;
incidenceWrapper.collectionId = drop.source.collectionId;
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.incidencePtr);
let sameTimeOnDate = new Date(listViewMenu.addDate);
sameTimeOnDate = new Date(sameTimeOnDate.setHours(drop.source.occurrenceDate.getHours(), drop.source.occurrenceDate.getMinutes()));
......@@ -718,8 +717,7 @@ Kirigami.Page {
let incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', incidenceDropArea, "incidence");
if(drop.source.objectName === "incidenceDelegate") {
incidenceWrapper.incidencePtr = drop.source.incidencePtr;
incidenceWrapper.collectionId = drop.source.collectionId;
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.incidencePtr);
const pos = mapToItem(root, dropAreaHighlightRectangle.x, dropAreaHighlightRectangle.y);
drop.source.caughtX = pos.x + incidenceSpacing;
......@@ -733,8 +731,7 @@ Kirigami.Page {
root.moveIncidence(startOffset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
} else { // The resize affects the end time
incidenceWrapper.incidencePtr = drop.source.parent.incidencePtr;
incidenceWrapper.collectionId = drop.source.parent.collectionId;
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.parent.incidencePtr);
const pos = mapToItem(drop.source.parent, dropAreaHighlightRectangle.x, dropAreaHighlightRectangle.y);
drop.source.parent.caughtHeight = (pos.y + dropAreaHighlightRectangle.height - incidenceSpacing)
......@@ -795,7 +792,6 @@ Kirigami.Page {
property alias mouseArea: mouseArea
property var incidencePtr: modelData.incidencePtr
property var collectionId: modelData.collectionId
property date occurrenceDate: modelData.startTime
property date occurrenceEndDate: modelData.endTime
property bool repositionAnimationEnabled: false
......@@ -929,8 +925,8 @@ Kirigami.Page {
drag.target: !Kirigami.Settings.isMobile && !modelData.isReadOnly ? parent : undefined
onReleased: parent.Drag.drop()
onViewClicked: viewIncidence(modelData, collectionData)
onEditClicked: editIncidence(incidencePtr, collectionId)
onViewClicked: viewIncidence(modelData)
onEditClicked: editIncidence(incidencePtr)
onDeleteClicked: deleteIncidence(incidencePtr, deleteDate)
onTodoCompletedClicked: completeTodo(incidencePtr)
onAddSubTodoClicked: root.addSubTodo(parentWrapper)
......
......@@ -472,7 +472,7 @@ Kirigami.ApplicationWindow {
if (modal) { incidenceInfo.close() }
}
onEditIncidence: {
setUpEdit(incidencePtr, collectionId);
setUpEdit(incidencePtr);
if (modal) { incidenceInfo.close() }
}
onDeleteIncidence: {
......@@ -842,25 +842,23 @@ Kirigami.ApplicationWindow {
editorToUse.incidenceWrapper.incidenceEnd = parentWrapper.incidenceEnd;
}
function setUpView(modelData, collectionData) {
incidenceInfo.incidenceData = modelData
incidenceInfo.collectionData = collectionData
incidenceInfo.open()
function setUpView(modelData) {
incidenceInfo.incidenceData = modelData;
incidenceInfo.open();
}
function setUpEdit(incidencePtr, collectionId) {
function setUpEdit(incidencePtr) {
let editorToUse = root.editorToUse();
editorToUse.incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
editorToUse, "incidence");
editorToUse.incidenceWrapper.incidencePtr = incidencePtr;
editorToUse.incidenceWrapper.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
editorToUse.incidenceWrapper.triggerEditMode();
editorToUse.incidenceWrapper.collectionId = collectionId;
editorToUse.editMode = true;
}
function setUpDelete(incidencePtr, deleteDate) {
let incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', root, "incidence");
incidenceWrapper.incidencePtr = incidencePtr;
incidenceWrapper.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
const openDialogWindow = pageStack.pushDialogLayer(deleteIncidenceSheetComponent, {
incidenceWrapper: incidenceWrapper,
......@@ -877,8 +875,7 @@ Kirigami.ApplicationWindow {
let todo = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
this, "incidence");
todo.incidencePtr = incidencePtr;
todo.collectionId = -1;
todo.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
if(todo.incidenceType === IncidenceWrapper.TypeTodo) {
todo.todoCompleted = !todo.todoCompleted;
......@@ -1037,8 +1034,8 @@ Kirigami.ApplicationWindow {
model: monthScaleModelLoader.item
onAddIncidence: root.setUpAdd(type, addDate)
onViewIncidence: root.setUpView(modelData, collectionData)
onEditIncidence: root.setUpEdit(incidencePtr, collectionId)
onViewIncidence: root.setUpView(modelData)
onEditIncidence: root.setUpEdit(incidencePtr)
onDeleteIncidence: root.setUpDelete(incidencePtr, deleteDate)
onCompleteTodo: root.completeTodo(incidencePtr)
onAddSubTodo: root.setUpAddSubTodo(parentWrapper)
......@@ -1076,8 +1073,8 @@ Kirigami.ApplicationWindow {
Component.onCompleted: setToDate(root.selectedDate, true)
onAddIncidence: root.setUpAdd(type, addDate)
onViewIncidence: root.setUpView(modelData, collectionData)
onEditIncidence: root.setUpEdit(incidencePtr, collectionId)
onViewIncidence: root.setUpView(modelData)
onEditIncidence: root.setUpEdit(incidencePtr)
onDeleteIncidence: root.setUpDelete(incidencePtr, deleteDate)
onCompleteTodo: root.completeTodo(incidencePtr)
onAddSubTodo: root.setUpAddSubTodo(parentWrapper)
......@@ -1113,8 +1110,8 @@ Kirigami.ApplicationWindow {
Component.onCompleted: setToDate(root.selectedDate, true)
onAddIncidence: root.setUpAdd(type, addDate, null, includeTime)
onViewIncidence: root.setUpView(modelData, collectionData)
onEditIncidence: root.setUpEdit(incidencePtr, collectionId)
onViewIncidence: root.setUpView(modelData)
onEditIncidence: root.setUpEdit(incidencePtr)
onDeleteIncidence: root.setUpDelete(incidencePtr, deleteDate)
onCompleteTodo: root.completeTodo(incidencePtr)
onAddSubTodo: root.setUpAddSubTodo(parentWrapper)
......@@ -1160,8 +1157,8 @@ Kirigami.ApplicationWindow {
filter: if(root.filter) root.filter
onAddTodo: root.setUpAdd(IncidenceWrapper.TypeTodo, new Date(), collectionId)
onViewTodo: root.setUpView(todoData, collectionData)
onEditTodo: root.setUpEdit(todoPtr, collectionId)
onViewTodo: root.setUpView(todoData)
onEditTodo: root.setUpEdit(todoPtr)
onDeleteTodo: root.setUpDelete(todoPtr, deleteDate)
onCompleteTodo: root.completeTodo(todoPtr)
onAddSubTodo: root.setUpAddSubTodo(parentWrapper)
......
......@@ -9,14 +9,8 @@
IncidenceWrapper::IncidenceWrapper(QObject *parent)
: QObject(parent)
, KCalendarCore::IncidenceBase::IncidenceObserver()
, m_incidence(new KCalendarCore::Event)
, m_remindersModel(parent, m_incidence)
, m_attendeesModel(parent, m_incidence)
, m_recurrenceExceptionsModel(parent, m_incidence)
, m_attachmentsModel(parent, m_incidence)
{
m_incidence->registerObserver(this);
, Akonadi::ItemMonitor()
{
// Change incidence pointer in remindersmodel if changed here
connect(this, &IncidenceWrapper::incidencePtrChanged, &m_remindersModel, [=](KCalendarCore::Incidence::Ptr incidencePtr) {
m_remindersModel.setIncidencePtr(incidencePtr);
......@@ -30,25 +24,20 @@ IncidenceWrapper::IncidenceWrapper(QObject *parent)
connect(this, &IncidenceWrapper::incidencePtrChanged, &m_attachmentsModel, [=](KCalendarCore::Incidence::Ptr incidencePtr) {
m_attachmentsModel.setIncidencePtr(incidencePtr);
});
}
IncidenceWrapper::~IncidenceWrapper()
{
m_incidence->unRegisterObserver(this);
}
Akonadi::ItemFetchScope scope;
scope.fetchFullPayload();
scope.fetchAllAttributes();
scope.setFetchRelations(true);
scope.setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
setFetchScope(scope);
void IncidenceWrapper::incidenceUpdate(const QString &uid, const QDateTime &)
{
if (uid == m_incidence->uid()) {
Q_EMIT incidenceAboutToChange();
}
setNewEvent();
}
void IncidenceWrapper::incidenceUpdated(const QString &uid, const QDateTime &)
IncidenceWrapper::~IncidenceWrapper()
{
if (uid == m_incidence->uid()) {
notifyDataChanged();
}
}
void IncidenceWrapper::notifyDataChanged()
......@@ -83,6 +72,23 @@ void IncidenceWrapper::notifyDataChanged()
Q_EMIT todoPercentCompleteChanged();
}
Akonadi::Item IncidenceWrapper::incidenceItem() const
{
return item();
}
void IncidenceWrapper::setIncidenceItem(const Akonadi::Item &incidenceItem)
{
if (incidenceItem.hasPayload<KCalendarCore::Incidence::Ptr>()) {
setItem(incidenceItem);
setIncidencePtr(incidenceItem.payload<KCalendarCore::Incidence::Ptr>());
Q_EMIT incidenceItemChanged();
Q_EMIT collectionIdChanged();
} else {
qWarning() << "This is not an incidence item.";
}
}
KCalendarCore::Incidence::Ptr IncidenceWrapper::incidencePtr() const
{
return m_incidence;
......@@ -90,9 +96,7 @@ KCalendarCore::Incidence::Ptr IncidenceWrapper::incidencePtr() const
void IncidenceWrapper::setIncidencePtr(const KCalendarCore::Incidence::Ptr incidencePtr)
{
m_incidence->unRegisterObserver(this);
m_incidence = incidencePtr;
m_incidence->registerObserver(this);
KCalendarCore::Incidence::Ptr originalIncidence(incidencePtr->clone());
m_originalIncidence = originalIncidence;
......@@ -129,7 +133,7 @@ QString IncidenceWrapper::uid() const
qint64 IncidenceWrapper::collectionId() const
{
return m_collectionId;
return m_collectionId < 0 ? item().parentCollection().id() : m_collectionId;
}
void IncidenceWrapper::setCollectionId(qint64 collectionId)
......@@ -641,13 +645,18 @@ void IncidenceWrapper::setNewEvent()
auto event = KCalendarCore::Event::Ptr(new KCalendarCore::Event);
event->setDtStart(QDateTime::currentDateTime());
event->setDtEnd(QDateTime::currentDateTime().addSecs(60 * 60));
setIncidencePtr(event);
Akonadi::Item incidenceItem;
incidenceItem.setPayload<KCalendarCore::Event::Ptr>(event);
setIncidenceItem(incidenceItem);
}
void IncidenceWrapper::setNewTodo()
{
auto todo = KCalendarCore::Todo::Ptr(new KCalendarCore::Todo);
setIncidencePtr(todo);
Akonadi::Item incidenceItem;
incidenceItem.setPayload<KCalendarCore::Todo::Ptr>(todo);