File indexing completed on 2024-05-26 05:37:15

0001 /*
0002     SPDX-FileCopyrightText: 2013 Alexander Mezin <mezin.alexander@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QDBusPendingCallWatcher>
0010 #include <QDBusServiceWatcher>
0011 #include <QPointer>
0012 #include <QTimer>
0013 #include <QVariantList>
0014 
0015 #include <KDEDModule>
0016 #include <KNotification>
0017 
0018 #include "kdedsettings.h"
0019 #include "touchpadbackend.h"
0020 
0021 class TouchpadDisabler : public KDEDModule
0022 {
0023     Q_OBJECT
0024     Q_CLASSINFO("D-Bus Interface", "org.kde.touchpad")
0025 
0026 public:
0027     TouchpadDisabler(QObject *, const QVariantList &);
0028 
0029 Q_SIGNALS:
0030     Q_SCRIPTABLE void enabledChanged(bool);
0031     Q_SCRIPTABLE void mousePluggedInChanged(bool);
0032     Q_SCRIPTABLE void workingTouchpadFoundChanged(bool);
0033 
0034 public Q_SLOTS:
0035     Q_SCRIPTABLE Q_NOREPLY void reloadSettings();
0036     Q_SCRIPTABLE Q_NOREPLY void toggle();
0037     Q_SCRIPTABLE Q_NOREPLY void disable();
0038     Q_SCRIPTABLE Q_NOREPLY void enable();
0039     Q_SCRIPTABLE bool isEnabled() const;
0040     Q_SCRIPTABLE bool workingTouchpadFound() const;
0041     Q_SCRIPTABLE bool isMousePluggedIn() const;
0042 
0043 private Q_SLOTS:
0044     void keyboardActivityStarted();
0045     void keyboardActivityFinished();
0046     void timerElapsed();
0047     void mousePlugged();
0048     void updateCurrentState();
0049     void serviceRegistered(const QString &);
0050     void handleReset();
0051     void serviceNameFetchFinished(QDBusPendingCallWatcher *);
0052     void onPrepareForSleep(bool sleep);
0053 
0054 private:
0055     void showNotification(const QString &name, const QString &text);
0056     void lateInit();
0057     void updateWorkingTouchpadFound();
0058     void showOsd();
0059 
0060     TouchpadBackend *m_backend;
0061     TouchpadDisablerSettings m_settings;
0062     QTimer m_keyboardActivityTimeout;
0063     QDBusServiceWatcher m_dependencies;
0064 
0065     TouchpadBackend::TouchpadOffState m_keyboardDisableState;
0066     bool m_userRequestedState, m_touchpadEnabled;
0067     bool m_workingTouchpadFound;
0068     bool m_keyboardActivity, m_mouse;
0069 
0070     QPointer<KNotification> m_notification;
0071 
0072     bool m_preparingForSleep = false;
0073 };