Commit d5313fd9 authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Fix adding an event or task to a default collection when there is no default...


Fix adding an event or task to a default collection when there is no default or previously used collection in Config

Signed-off-by: Claudio Cambra's avatarClaudio Cambra <claudio.cambra@gmail.com>
parent e13bc540
Pipeline #247325 passed with stage
in 4 minutes and 10 seconds
......@@ -420,6 +420,20 @@ KCalendarCore::Incidence::List CalendarManager::childIncidences(const QString &u
void CalendarManager::addIncidence(IncidenceWrapper *incidenceWrapper)
{
if (incidenceWrapper->collectionId() < 0) {
const auto sharedConfig = KSharedConfig::openConfig();
const auto editorConfigSection = sharedConfig->group("Editor");
const auto lastUsedCollectionType = incidenceWrapper->incidenceType() == KCalendarCore::IncidenceBase::TypeTodo
? QStringLiteral("lastUsedTodoCollection")
: QStringLiteral("lastUsedEventCollection");
const auto lastUsedCollectionId = editorConfigSection.readEntry(lastUsedCollectionType, -1);
if (lastUsedCollectionId > -1) {
incidenceWrapper->setCollectionId(lastUsedCollectionId);
}
}
Akonadi::Collection collection(incidenceWrapper->collectionId());
switch (incidenceWrapper->incidencePtr()->type()) {
......
......@@ -66,13 +66,18 @@ Kirigami.ScrollablePage {
if (editMode) {
edited(incidenceWrapper);
} else if (root.validDates) {
added(incidenceWrapper);
if(root.incidenceWrapper.collectionId < 0) {
root.incidenceWrapper.collectionId = editorLoader.item.calendarCombo.currentValue;
}
if(root.incidenceWrapper.incidenceType === IncidenceWrapper.TypeTodo) {
Config.lastUsedTodoCollection = root.incidenceWrapper.collectionId;
} else {
Config.lastUsedEventCollection = root.incidenceWrapper.collectionId;
}
Config.save();
added(incidenceWrapper);
}
cancel(); // Easy way to close the editor
}
......@@ -115,6 +120,8 @@ Kirigami.ScrollablePage {
property alias attendeesColumnY: attendeesColumn.y
readonly property alias calendarCombo: calendarCombo
Kirigami.InlineMessage {
id: invalidDateMessage
......@@ -139,9 +146,16 @@ Kirigami.ScrollablePage {
Kirigami.FormData.label: i18n("Calendar:")
Layout.fillWidth: true
defaultCollectionId: if (root.incidenceWrapper.collectionId === -1) {
return incidenceForm.isTodo ? Config.lastUsedTodoCollection : Config.lastUsedEventCollection;
} else {
defaultCollectionId: {
if (root.incidenceWrapper.collectionId === -1) {
if ((incidenceForm.isTodo && Config.lastUsedTodoCollection === -1) ||
(!incidenceForm.isTodo && Config.lastUsedEventCollection === -1)) {
return selectedCollectionId;
}
return incidenceForm.isTodo ? Config.lastUsedTodoCollection : Config.lastUsedEventCollection;
}
return root.incidenceWrapper.collectionId;
}
......@@ -151,7 +165,7 @@ Kirigami.ScrollablePage {
return [Akonadi.MimeTypes.todo]
}
accessRightsFilter: Akonadi.Collection.CanCreateItem
onSelectedCollectionChanged: root.incidenceWrapper.setCollection(collection)
onUserSelectedCollection: root.incidenceWrapper.setCollection(collection)
}
QQC2.TextField {
......
......@@ -28,9 +28,9 @@ public:
};
Q_ENUM(Right)
enum Role {
CollectionRole = Akonadi::EntityTreeModel::CollectionRole,
CollectionColorRole = Qt::BackgroundRole,
};
Q_ENUM(Role)
};
......
......@@ -175,4 +175,4 @@ void CollectionComboBoxModel::setCurrentIndex(int currentIndex)
Q_EMIT currentIndexChanged();
}
#include "moc_collectioncomboboxmodel.cpp"
\ No newline at end of file
#include "moc_collectioncomboboxmodel.cpp"
......@@ -51,22 +51,33 @@ QQC2.ComboBox {
*/
property alias accessRightsFilter: collectionComboBoxModel.accessRightsFilter
/**
* Signal emitted when the selected collection changed
*/
signal selectedCollectionChanged(var collection)
signal userSelectedCollection(var collection)
currentIndex: 0
onActivated: if (index > -1) {
const selectedModelIndex = collectionComboBoxModel.index(currentIndex, 0);
const selectedCollection = collectionComboBoxModel.data(selectedModelIndex, Akonadi.Collection.CollectionRole);
userSelectedCollection(selectedCollection);
}
textRole: "display"
valueRole: "collectionColor"
valueRole: "collectionId"
indicator: Rectangle {
id: indicatorDot
// Make sure to check the currentValue property directly or risk listening to something that won't necessarily emit a changed() signal'
readonly property var selectedModelIndex: comboBox.currentValue > -1 ? comboBox.model.index(comboBox.currentIndex, 0) : null
readonly property var selectedCollectionColor: comboBox.currentValue > -1 ? comboBox.model.data(selectedModelIndex, Akonadi.Collection.CollectionColorRole) : null
implicitHeight: comboBox.implicitHeight * 0.4
implicitWidth: implicitHeight
x: comboBox.mirrored ? comboBox.leftPadding : comboBox.width - (comboBox.leftPadding * 3) - Kirigami.Units.iconSizes.smallMedium
y: comboBox.topPadding + (comboBox.availableHeight - height) / 2
radius: width * 0.5
color: parent.currentValue
color: selectedCollectionColor
}
model: Akonadi.CollectionComboBoxModel {
......@@ -81,16 +92,9 @@ QQC2.ComboBox {
anchors.margins: Kirigami.Units.smallSpacing
width: height
radius: width * 0.5
color: collectionColor
}
}
currentIndex: 0
onCurrentIndexChanged: if (currentIndex !== -1) {
const collection = model.data(model.index(currentIndex, 0), Akonadi.Collection.CollectionRole);
if (collection) {
comboBox.selectedCollectionChanged(collection);
color: model.collectionColor
}
}
popup.z: 1000
}
\ No newline at end of file
}
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