Skip to content

Commit

Permalink
Merge branch 'alarms' into 'master'
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Base excluded notebook on mkcal notebook visibility, don't list notebook for disabled services.

See merge request mer-core/nemo-qml-plugin-calendar!55
  • Loading branch information
llewelld committed Jun 9, 2020
2 parents 0cd9e2b + 9252009 commit 32a1bf4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/calendarmanager.cpp
Expand Up @@ -135,16 +135,16 @@ void CalendarManager::setDefaultNotebook(const QString &notebookUid)

CalendarEvent* CalendarManager::eventObject(const QString &eventUid, const KDateTime &recurrenceId)
{
CalendarData::Event event = getEvent(eventUid, recurrenceId);
if (event.isValid()) {
QMultiHash<QString, CalendarEvent *>::iterator it = mEventObjects.find(eventUid);
while (it != mEventObjects.end() && it.key() == eventUid) {
if ((*it)->recurrenceId() == recurrenceId) {
return *it;
}
++it;
QMultiHash<QString, CalendarEvent *>::iterator it = mEventObjects.find(eventUid);
while (it != mEventObjects.end() && it.key() == eventUid) {
if ((*it)->recurrenceId() == recurrenceId) {
return *it;
}
++it;
}

CalendarData::Event event = getEvent(eventUid, recurrenceId);
if (event.isValid()) {
CalendarEvent *calendarEvent = new CalendarEvent(this, eventUid, recurrenceId);
mEventObjects.insert(eventUid, calendarEvent);
return calendarEvent;
Expand Down
59 changes: 41 additions & 18 deletions src/calendarworker.cpp
Expand Up @@ -582,22 +582,20 @@ QStringList CalendarWorker::excludedNotebooks() const

bool CalendarWorker::saveExcludeNotebook(const QString &notebookUid, bool exclude)
{
if (!mNotebooks.contains(notebookUid))
return false;

if (mNotebooks.value(notebookUid).excluded == exclude)
QHash<QString, CalendarData::Notebook>::Iterator notebook = mNotebooks.find(notebookUid);
if (notebook == mNotebooks.end())
return false;
bool changed = (notebook->excluded != exclude);
notebook->excluded = exclude;

CalendarData::Notebook notebook = mNotebooks.value(notebookUid);
QSettings settings("nemo", "nemo-qml-plugin-calendar");
notebook.excluded = exclude;
if (exclude)
settings.setValue("exclude/" + notebook.uid, true);
else
settings.remove("exclude/" + notebook.uid);
// Ensure, mKCal backend is up-to-date on notebook visibility.
const mKCal::Notebook::Ptr mkNotebook = mStorage->notebook(notebookUid);
if (mkNotebook && mkNotebook->isVisible() != !exclude) {
mkNotebook->setIsVisible(!exclude);
mStorage->updateNotebook(mkNotebook);
}

mNotebooks.insert(notebook.uid, notebook);
return true;
return changed;
}

void CalendarWorker::setExcludedNotebooks(const QStringList &list)
Expand Down Expand Up @@ -829,12 +827,34 @@ CalendarData::Event CalendarWorker::createEventStruct(const KCalCore::Event::Ptr
return event;
}

static bool serviceIsEnabled(Accounts::Account *account, const QString &syncProfile)
{
account->selectService();
if (account->enabled()) {
for (const Accounts::Service &service : account->services()) {
account->selectService(service);
const QStringList allKeys = account->allKeys();
for (const QString &key : allKeys) {
if (key.endsWith(QLatin1String("/profile_id"))
&& account->valueAsString(key) == syncProfile) {
bool ret = account->enabled();
account->selectService();
return ret;
}
}
}
account->selectService();
return true;
}
return false;
}

void CalendarWorker::loadNotebooks()
{
QStringList defaultNotebookColors = QStringList() << "#00aeef" << "red" << "blue" << "green" << "pink" << "yellow";
int nextDefaultNotebookColor = 0;

mKCal::Notebook::List notebooks = mStorage->notebooks();
const mKCal::Notebook::List notebooks = mStorage->notebooks();
QSettings settings("nemo", "nemo-qml-plugin-calendar");

QHash<QString, CalendarData::Notebook> newNotebooks;
Expand All @@ -854,7 +874,9 @@ void CalendarWorker::loadNotebooks()
&& !mkNotebook->isShared()
&& mkNotebook->pluginName().isEmpty();

notebook.excluded = settings.value("exclude/" + notebook.uid, false).toBool();
notebook.excluded = !mkNotebook->isVisible()
// To keep backward compatibility:
|| settings.value("exclude/" + notebook.uid, false).toBool();

notebook.color = settings.value("colors/" + notebook.uid, QString()).toString();
if (notebook.color.isEmpty())
Expand All @@ -872,6 +894,9 @@ void CalendarWorker::loadNotebooks()
if (ok && accountId > 0) {
Accounts::Account *account = Accounts::Account::fromId(mAccountManager, accountId, this);
if (account) {
if (!serviceIsEnabled(account, mkNotebook->syncProfile())) {
continue;
}
notebook.accountId = accountId;
notebook.accountIcon = mAccountManager->provider(account->providerName()).iconName();
if (notebook.description.isEmpty()) {
Expand All @@ -886,9 +911,7 @@ void CalendarWorker::loadNotebooks()
if (mNotebooks.contains(notebook.uid) && mNotebooks.value(notebook.uid) != notebook)
changed = true;

if (mkNotebook->isVisible()) {
newNotebooks.insert(notebook.uid, notebook);
}
newNotebooks.insert(notebook.uid, notebook);
}

if (changed || mNotebooks.count() != newNotebooks.count()) {
Expand Down

0 comments on commit 32a1bf4

Please sign in to comment.