From 7ccf9e499deeaf0a79b066c8f6ee41a2f3c2055e Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 6 Jan 2021 16:33:35 +1000 Subject: [PATCH] [nemo-qml-plugin-calendar] Use mKCal::Notebook color as canonical color. Contributes to JB#51280 Previously, the canonical color used for display purposes in the jolla-calendar application for a particular notebook was stored in a QSettings .ini file. That allowed the user to define a color for a calendar locally, without perturbing the color specified on the server. However, it also meant that the semantics of color selection were not easily discoverable, and further, that synchronisation of the color selection would never be performed. This commit ensures that the synced color will be used as the color displayed in the application, and that the color selection will be stored into the notebook in the database. Finally, it ensures that if no color is set, a default color is chosen and stored into the notebook, to avoid the possibility that the color of the primary notebook can change between reboots. --- src/calendarworker.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/calendarworker.cpp b/src/calendarworker.cpp index 1d55a7c..05ee379 100644 --- a/src/calendarworker.cpp +++ b/src/calendarworker.cpp @@ -689,13 +689,15 @@ void CalendarWorker::setNotebookColor(const QString ¬ebookUid, const QString return; if (mNotebooks.value(notebookUid).color != color) { + if (mKCal::Notebook::Ptr mkNotebook = mStorage->notebook(notebookUid)) { + mkNotebook->setColor(color); + mStorage->updateNotebook(mkNotebook); + } + CalendarData::Notebook notebook = mNotebooks.value(notebookUid); notebook.color = color; mNotebooks.insert(notebook.uid, notebook); - QSettings settings("nemo", "nemo-qml-plugin-calendar"); - settings.setValue("colors/" + notebook.uid, notebook.color); - emit notebooksChanged(mNotebooks.values()); } } @@ -950,11 +952,20 @@ void CalendarWorker::loadNotebooks() notebook.excluded = true; } - notebook.color = settings.value("colors/" + notebook.uid, QString()).toString(); - if (notebook.color.isEmpty()) - notebook.color = mkNotebook->color(); - if (notebook.color.isEmpty()) - notebook.color = defaultNotebookColors.at((nextDefaultNotebookColor++) % defaultNotebookColors.count()); + const QString &confColor = settings.value("colors/" + notebook.uid, QString()).toString(); + const QString ¬ebookColor = confColor.isEmpty() ? mkNotebook->color() : confColor; + const bool confHasColor = !confColor.isEmpty(); + notebook.color = notebookColor.isEmpty() + ? defaultNotebookColors.at((nextDefaultNotebookColor++) % defaultNotebookColors.count()) + : notebookColor; + bool canRemoveConf = true; + if (notebook.color != mkNotebook->color()) { + mkNotebook->setColor(notebook.color); + canRemoveConf = mStorage->updateNotebook(mkNotebook); + } + if (confHasColor && canRemoveConf) { + settings.remove("colors/" + notebook.uid); + } QString accountStr = mkNotebook->account(); if (!accountStr.isEmpty()) {