1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
SPDX-FileCopyrightText: 2013-2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "notesagent.h"
#include "notesagentadaptor.h"
#include "notesagentsettings.h"
#include "notesagentsettingsdialog.h"
#include "notesharedglobalconfig.h"
#include "notesmanager.h"
#include <Akonadi/ServerManager>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <Kdelibs4ConfigMigrator>
#endif
#include <KWindowSystem>
#include <QDBusConnection>
NotesAgent::NotesAgent(const QString &id)
: Akonadi::AgentBase(id)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Kdelibs4ConfigMigrator migrate(QStringLiteral("notesagent"));
migrate.setConfigFiles(QStringList() << QStringLiteral("akonadi_notes_agentrc") << QStringLiteral("akonadi_notes_agent.notifyrc"));
migrate.migrate();
#endif
mNotesManager = new NotesManager(this);
new NotesAgentAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/NotesAgent"), this, QDBusConnection::ExportAdaptors);
setNeedsNetwork(true);
if (NotesAgentSettings::enabled()) {
QTimer::singleShot(60 * 1000, this, &NotesAgent::slotStartAgent);
}
}
NotesAgent::~NotesAgent() = default;
void NotesAgent::doSetOnline(bool online)
{
if (mAgentInitialized) {
if (online) {
reload();
} else {
mNotesManager->stopAll();
}
}
}
void NotesAgent::slotStartAgent()
{
mAgentInitialized = true;
if (isOnline()) {
mNotesManager->load();
}
}
void NotesAgent::reload()
{
if (NotesAgentSettings::enabled()) {
mNotesManager->load();
}
}
void NotesAgent::setEnableAgent(bool enabled)
{
if (NotesAgentSettings::enabled() == enabled) {
return;
}
NotesAgentSettings::setEnabled(enabled);
NotesAgentSettings::self()->save();
if (enabled) {
mNotesManager->load();
} else {
mNotesManager->stopAll();
}
}
bool NotesAgent::enabledAgent() const
{
return NotesAgentSettings::enabled();
}
void NotesAgent::configure(WId windowId)
{
showConfigureDialog((qlonglong)windowId);
}
void NotesAgent::showConfigureDialog(qlonglong windowId)
{
QPointer<NotesAgentSettingsDialog> dialog = new NotesAgentSettingsDialog;
if (windowId) {
dialog->setAttribute(Qt::WA_NativeWindow, true);
KWindowSystem::setMainWindow(dialog->windowHandle(), windowId);
}
if (dialog->exec()) {
mNotesManager->load();
}
delete dialog;
}
bool NotesAgent::receiveNotes() const
{
return NoteShared::NoteSharedGlobalConfig::receiveNotes();
}
void NotesAgent::setReceiveNotes(bool b)
{
if (NoteShared::NoteSharedGlobalConfig::receiveNotes() != b) {
NoteShared::NoteSharedGlobalConfig::setReceiveNotes(b);
NoteShared::NoteSharedGlobalConfig::self()->save();
mNotesManager->updateNetworkListener();
}
}
int NotesAgent::port() const
{
return NoteShared::NoteSharedGlobalConfig::port();
}
void NotesAgent::setPort(int value)
{
if (value < 0) {
return;
}
if (NoteShared::NoteSharedGlobalConfig::port() != static_cast<uint>(value)) {
NoteShared::NoteSharedGlobalConfig::setPort(value);
NoteShared::NoteSharedGlobalConfig::self()->save();
if (NotesAgentSettings::enabled()) {
mNotesManager->updateNetworkListener();
}
}
}
void NotesAgent::setAlarmCheckInterval(int value)
{
if (value < 0) {
return;
}
if (NoteShared::NoteSharedGlobalConfig::checkInterval() != static_cast<uint>(value)) {
NoteShared::NoteSharedGlobalConfig::setCheckInterval(value);
NoteShared::NoteSharedGlobalConfig::self()->save();
reload();
}
}
void NotesAgent::configurationChanged()
{
NoteShared::NoteSharedGlobalConfig::self()->config()->reparseConfiguration();
mNotesManager->updateNetworkListener();
}
int NotesAgent::alarmCheckInterval() const
{
return NoteShared::NoteSharedGlobalConfig::checkInterval();
}
AKONADI_AGENT_MAIN(NotesAgent)
|