Commit c4a70bb3 authored by Volker Krause's avatar Volker Krause
Browse files

Remove the alarm daemon systray entry

With switching to notifications this is no longer necessary, as both
inhibition and the ability to disable alarms permanently are provided
by KNotification itself already for us.
parent 95ecb639
Pipeline #105245 passed with stage
in 5 minutes and 10 seconds
......@@ -4,7 +4,6 @@
set(kalendarac_SRCS
kalendaralarmclient.cpp
alarmdockwindow.cpp
alarmnotification.cpp
notificationhandler.cpp
kalendaracmain.cpp
......@@ -23,8 +22,6 @@ target_link_libraries(kalendarac
KF5::CalendarSupport
KF5::I18n
KF5::Notifications
KF5::IconThemes
KF5::WindowSystem
Qt5::Core
Qt5::DBus
)
......
// SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
// SPDX-FileCopyrightText: 2008-2009 Allen Winter <winter@kde.org>
// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Qt-Commercial-exception-1.0
#include "alarmdockwindow.h"
#include <KConfigGroup>
#include <KIconEffect>
#include <KIconLoader>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSharedConfig>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDebug>
#include <QMenu>
AlarmDockWindow::AlarmDockWindow()
: KStatusNotifierItem(nullptr)
{
// Read the autostart status from the config file
KConfigGroup config(KSharedConfig::openConfig(), "General");
const bool autostartSet = config.hasKey("Autostart");
const bool autostart = config.readEntry("Autostart", true);
// const bool grabFocus = config.readEntry("GrabFocus", false);
const bool alarmsEnabled = config.readEntry("Enabled", true);
// Don't mention Daemon here since it's a technical
// term the user doesn't care about
mName = i18nc("@title:window", "Kalendar Reminders");
setToolTipTitle(mName);
setToolTipIconByName(QStringLiteral("kalendarac"));
setTitle(mName);
// Set up icons
const QIcon iconEnabled = QIcon::fromTheme(QStringLiteral("org.kde.kalendar"));
KIconLoader loader;
QImage iconDisabled = iconEnabled.pixmap(loader.currentSize(KIconLoader::Panel)).toImage();
KIconEffect::toGray(iconDisabled, 1.0);
mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled));
changeSystrayIcon(alarmsEnabled);
// Set up the context menu
mAlarmsEnabled = contextMenu()->addAction(i18nc("@action:inmenu", "Enable Reminders"));
connect(mAlarmsEnabled, &QAction::toggled, this, &AlarmDockWindow::toggleAlarmsEnabled);
mAlarmsEnabled->setCheckable(true);
mAutostart = contextMenu()->addAction(i18nc("@action:inmenu", "Start Reminder Daemon at Login"));
connect(mAutostart, &QAction::toggled, this, &AlarmDockWindow::toggleAutostart);
mAutostart->setCheckable(true);
mAlarmsEnabled->setChecked(alarmsEnabled);
mAutostart->setChecked(autostart);
// Disable standard quit behaviour. We have to intercept the quit even,
// if the main window is hidden.
QAction *act = action(QStringLiteral("quit"));
if (act) {
disconnect(act, SIGNAL(triggered(bool)), this, SLOT(maybeQuit()));
connect(act, &QAction::triggered, this, &AlarmDockWindow::slotQuit);
} else {
qDebug() << "No Quit standard action.";
}
mAutostartSet = autostartSet;
}
AlarmDockWindow::~AlarmDockWindow()
{
}
void AlarmDockWindow::slotUpdate(int reminders)
{
const bool actif = (reminders > 0);
if (actif) {
setToolTip(QStringLiteral("kalendarac"), mName, i18ncp("@info:status", "There is 1 active reminder.", "There are %1 active reminders.", reminders));
} else {
setToolTip(QStringLiteral("kalendarac"), mName, i18nc("@info:status", "No active reminders."));
}
}
void AlarmDockWindow::toggleAlarmsEnabled(bool checked)
{
changeSystrayIcon(checked);
KConfigGroup config(KSharedConfig::openConfig(), "General");
config.writeEntry("Enabled", checked);
config.sync();
}
void AlarmDockWindow::toggleAutostart(bool checked)
{
// qCDebug(KOALARMCLIENT_LOG);
mAutostartSet = true;
enableAutostart(checked);
}
void AlarmDockWindow::toggleGrabFocus(bool checked)
{
KConfigGroup config(KSharedConfig::openConfig(), "General");
config.writeEntry("GrabFocus", checked);
}
void AlarmDockWindow::slotSuspendAll()
{
Q_EMIT suspendAllSignal();
}
void AlarmDockWindow::slotDismissAll()
{
Q_EMIT dismissAllSignal();
}
void AlarmDockWindow::enableAutostart(bool enable)
{
KConfigGroup config(KSharedConfig::openConfig(), "General");
config.writeEntry("Autostart", enable);
config.sync();
}
void AlarmDockWindow::activate(const QPoint &pos)
{
Q_UNUSED(pos)
QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.kalendar"));
}
void AlarmDockWindow::slotQuit()
{
if (mAutostartSet == true) {
const int result = KMessageBox::warningContinueCancel(associatedWidget(),
xi18nc("@info",
"Do you want to quit the Kalendar reminder daemon?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>"),
i18nc("@title:window", "Close Kalendar Reminder Daemon"),
KStandardGuiItem::quit());
if (result == KMessageBox::Continue) {
Q_EMIT quitSignal();
}
} else {
const int result = KMessageBox::questionYesNoCancel(associatedWidget(),
xi18nc("@info",
"Do you want to start the Kalendar reminder daemon at login?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>"),
i18nc("@title:window", "Close Kalendar Reminder Daemon"),
KGuiItem(i18nc("@action:button start the reminder daemon", "Start")),
KGuiItem(i18nc("@action:button do not start the reminder daemon", "Do Not Start")),
KStandardGuiItem::cancel(),
QStringLiteral("AskForStartAtLogin"));
bool autostart = true;
if (result == KMessageBox::No) {
autostart = false;
}
enableAutostart(autostart);
if (result != KMessageBox::Cancel) {
Q_EMIT quitSignal();
}
}
}
void AlarmDockWindow::changeSystrayIcon(bool alarmsEnabled)
{
if (alarmsEnabled) {
setIconByName(QStringLiteral("org.kde.kalendar"));
} else {
setIconByPixmap(mIconDisabled.pixmap(22, 22));
}
}
// SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
// SPDX-FileCopyrightText: 2008-2009 Allen Winter <winter@kde.org>
// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Qt-Commercial-exception-1.0
#pragma once
#include <KStatusNotifierItem>
#include <QAction>
#include <QIcon>
class AlarmDockWindow : public KStatusNotifierItem
{
Q_OBJECT
public:
AlarmDockWindow();
~AlarmDockWindow() override;
void enableAutostart(bool enabled);
public Q_SLOTS:
void toggleAlarmsEnabled(bool checked);
void toggleAutostart(bool checked);
void toggleGrabFocus(bool checked);
void slotUpdate(int reminders);
Q_SIGNALS:
void quitSignal();
void suspendAllSignal();
void dismissAllSignal();
void showReminderSignal();
protected Q_SLOTS:
void activate(const QPoint &pos) override;
void slotQuit();
void slotSuspendAll();
void slotDismissAll();
private:
void changeSystrayIcon(bool alarmsEnabled);
QIcon mIconDisabled;
QString mName;
QAction *mAlarmsEnabled = nullptr;
QAction *mAutostart = nullptr;
QAction *mShow = nullptr;
bool mAutostartSet = false;
};
......@@ -5,13 +5,14 @@
#include <KAboutData>
#include <KDBusService>
#include <KLocalizedString>
#include <QApplication>
#include <QCommandLineParser>
#include <QGuiApplication>
int main(int argc, char **argv)
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QGuiApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
KAboutData aboutData(
......
......@@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "kalendaralarmclient.h"
#include "alarmdockwindow.h"
#include "alarmnotification.h"
#include "kalendaracadaptor.h"
#include "notificationhandler.h"
......@@ -28,12 +27,6 @@ KalendarAlarmClient::KalendarAlarmClient(QObject *parent)
m_notificationHandler = new NotificationHandler(this);
if (dockerEnabled()) {
mDocker = new AlarmDockWindow;
connect(this, &KalendarAlarmClient::reminderCount, mDocker, &AlarmDockWindow::slotUpdate);
connect(mDocker, &AlarmDockWindow::quitSignal, this, &KalendarAlarmClient::slotQuit);
}
// Check if Akonadi is already configured
const QString akonadiConfigFile = Akonadi::ServerManager::serverConfigFilePath(Akonadi::ServerManager::ReadWrite);
if (QFileInfo::exists(akonadiConfigFile)) {
......@@ -61,10 +54,7 @@ KalendarAlarmClient::KalendarAlarmClient(QObject *parent)
restoreSuspendedFromConfig();
}
KalendarAlarmClient::~KalendarAlarmClient()
{
delete mDocker;
}
KalendarAlarmClient::~KalendarAlarmClient() = default;
void KalendarAlarmClient::setupAkonadi()
{
......@@ -151,13 +141,6 @@ void KalendarAlarmClient::flushSuspendedToConfig()
KSharedConfig::openConfig()->sync();
}
bool KalendarAlarmClient::dockerEnabled()
{
KConfig kalendarConfig(QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kalendarrc")));
KConfigGroup generalGroup(&kalendarConfig, "System Tray");
return generalGroup.readEntry("ShowReminderDaemon", true);
}
bool KalendarAlarmClient::collectionsAvailable() const
{
// The list of collections must be available.
......@@ -229,7 +212,6 @@ void KalendarAlarmClient::checkAlarms()
void KalendarAlarmClient::slotQuit()
{
Q_EMIT saveAllSignal();
flushSuspendedToConfig();
saveLastCheckTime();
quit();
......@@ -250,7 +232,6 @@ void KalendarAlarmClient::quit()
void KalendarAlarmClient::slotCommitData(QSessionManager &)
{
Q_EMIT saveAllSignal();
saveLastCheckTime();
}
......@@ -297,20 +278,3 @@ QStringList KalendarAlarmClient::dumpAlarms() const
return lst;
}
void KalendarAlarmClient::hide()
{
delete mDocker;
mDocker = nullptr;
}
void KalendarAlarmClient::show()
{
if (!mDocker) {
if (dockerEnabled()) {
mDocker = new AlarmDockWindow;
connect(this, &KalendarAlarmClient::reminderCount, mDocker, &AlarmDockWindow::slotUpdate);
connect(mDocker, &AlarmDockWindow::quitSignal, this, &KalendarAlarmClient::slotQuit);
}
}
}
......@@ -30,8 +30,6 @@ public:
// DBUS interface
void quit();
void hide();
void show();
void forceAlarmCheck();
Q_REQUIRED_RESULT QString dumpDebug() const;
Q_REQUIRED_RESULT QStringList dumpAlarms() const;
......@@ -39,10 +37,6 @@ public:
public Q_SLOTS:
void slotQuit();
Q_SIGNALS:
void reminderCount(int);
void saveAllSignal();
private:
void deferredInit();
void restoreSuspendedFromConfig();
......@@ -50,11 +44,9 @@ private:
void checkAlarms();
void setupAkonadi();
void slotCommitData(QSessionManager &);
Q_REQUIRED_RESULT bool dockerEnabled();
Q_REQUIRED_RESULT bool collectionsAvailable() const;
void saveLastCheckTime();
AlarmDockWindow *mDocker = nullptr; // the panel icon
Akonadi::ETMCalendar::Ptr mCalendar;
Akonadi::EntityTreeModel *mETM = nullptr;
......
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