Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-calendar] Base excluded notebook on mkcal notebook v…
…isibility, don't list notebook for disabled services. Contributes to JB#49136
  • Loading branch information
dcaliste committed Jun 9, 2020
1 parent 0cd9e2b commit 483c858
Showing 1 changed file with 41 additions and 18 deletions.
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 483c858

Please sign in to comment.