Commit 78a21f56 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

korgac: only try to start Akonadi if it has been configured

Summary:
korgac is autostarted on login. We don't want it to start up Akonadi
though if the user has not set up Akonadi yet. In that case (i.e. when
akonadiserverrc does not exist yet), korgac will wait for the server
to be started and only then continues to set up ETM and other Akonadi
stuff. If Akonadi has been configured previously, then korgac will
just continue to create ETM and thus start Akonadi if necessary right
after login.

Reviewers: kde-pim

Subscribers: lbeltrame, winterz

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D2050
parents e396e796 a6500724
......@@ -35,6 +35,7 @@
#include <AkonadiCore/Item>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/Session>
#include <AkonadiCore/ServerManager>
#include <KCalCore/Calendar>
......@@ -59,22 +60,29 @@ KOAlarmClient::KOAlarmClient(QObject *parent)
connect(this, &KOAlarmClient::reminderCount, mDocker, &AlarmDockWindow::slotUpdate);
connect(mDocker, &AlarmDockWindow::quitSignal, this, &KOAlarmClient::slotQuit);
}
QStringList mimeTypes;
mimeTypes << Event::eventMimeType() << Todo::todoMimeType();
mCalendar = Akonadi::ETMCalendar::Ptr(new Akonadi::ETMCalendar(mimeTypes));
mCalendar->setObjectName(QStringLiteral("KOrgac's calendar"));
mETM = mCalendar->entityTreeModel();
connect(&mCheckTimer, &QTimer::timeout, this, &KOAlarmClient::checkAlarms);
connect(mETM, &Akonadi::EntityTreeModel::collectionPopulated, this, &KOAlarmClient::deferredInit);
connect(mETM, &Akonadi::EntityTreeModel::collectionTreeFetched, this, &KOAlarmClient::deferredInit);
// Check if Akonadi is already configured
const QString akonadiConfigFile = Akonadi::ServerManager::serverConfigFilePath(Akonadi::ServerManager::ReadWrite);
if (QFile::exists(akonadiConfigFile)) {
// Akonadi is configured, create ETM and friends, which will start Akonadi
// if its not running yet
setupAkonadi();
} else {
// Akonadi has not been set up yet, wait for someone else to start it,
// so that we don't unnecessarily slow session start up
connect(Akonadi::ServerManager::self(), &Akonadi::ServerManager::stateChanged,
this, [this](Akonadi::ServerManager::State state) {
if (state == Akonadi::ServerManager::Running) {
setupAkonadi();
}
});
}
KConfigGroup alarmGroup(KSharedConfig::openConfig(), "Alarms");
const int interval = alarmGroup.readEntry("Interval", 60);
qCDebug(KOALARMCLIENT_LOG) << "KOAlarmClient check interval:" << interval << "seconds.";
mLastChecked = alarmGroup.readEntry("CalendarsLastChecked", QDateTime());
checkAlarms();
mCheckTimer.start(1000 * interval); // interval in seconds
connect(qApp, &QApplication::commitDataRequest, this, &KOAlarmClient::slotCommitData);
}
......@@ -85,6 +93,22 @@ KOAlarmClient::~KOAlarmClient()
delete mDialog;
}
void KOAlarmClient::setupAkonadi()
{
QStringList mimeTypes;
mimeTypes << Event::eventMimeType() << Todo::todoMimeType();
mCalendar = Akonadi::ETMCalendar::Ptr(new Akonadi::ETMCalendar(mimeTypes));
mCalendar->setObjectName(QStringLiteral("KOrgac's calendar"));
mETM = mCalendar->entityTreeModel();
connect(&mCheckTimer, &QTimer::timeout, this, &KOAlarmClient::checkAlarms);
connect(mETM, &Akonadi::EntityTreeModel::collectionPopulated, this, &KOAlarmClient::deferredInit);
connect(mETM, &Akonadi::EntityTreeModel::collectionTreeFetched, this, &KOAlarmClient::deferredInit);
checkAlarms();
}
void checkAllItems(KCheckableProxyModel *model, const QModelIndex &parent = QModelIndex())
{
const int rowCount = model->rowCount(parent);
......
......@@ -60,6 +60,7 @@ protected Q_SLOTS:
void deferredInit();
void checkAlarms();
private Q_SLOTS:
void setupAkonadi();
void slotCommitData(QSessionManager &);
Q_SIGNALS:
......
Markdown is supported
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