File indexing completed on 2024-03-24 17:23:07

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2017 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef _KdeConnect_H_
0022 #define _KdeConnect_H_
0023 
0024 #include <QObject>
0025 #include <QMap>
0026 #include <QIcon>
0027 #include <QSharedPointer>
0028 #include <QPointer>
0029 #include <QDBusInterface>
0030 
0031 #include <KNotification>
0032 
0033 class QDBusMessage;
0034 
0035 //--------------------------------------------------------------------------------
0036 
0037 class KdeConnectDevice : public QObject
0038 {
0039   Q_OBJECT
0040 
0041   Q_SIGNALS:
0042     void changed();
0043 
0044   public Q_SLOTS:
0045     void updatePlugins();
0046 
0047   public:
0048     void ringPhone();
0049 
0050     QString id;
0051     QString name;
0052     QIcon icon, chargeIcon;
0053     QStringList plugins;
0054     int charge = -1;
0055     bool isCharging = false;
0056     bool warned = false;
0057     QDBusInterface *batteryInterface = nullptr;
0058 
0059   private Q_SLOTS:
0060     void nameChangedSlot(const QString &newName);
0061     void chargeChangedSlot();
0062 
0063   private:
0064     QPointer<KNotification> notif;
0065 };
0066 
0067 //--------------------------------------------------------------------------------
0068 
0069 class KdeConnect : public QObject
0070 {
0071   Q_OBJECT
0072 
0073   public:
0074     KdeConnect();
0075 
0076     struct Device : public QSharedPointer<KdeConnectDevice>
0077     {
0078       Device() : QSharedPointer(new KdeConnectDevice) {}
0079     };
0080 
0081   Q_SIGNALS:
0082     void deviceAdded(const Device &device);
0083     void deviceRemoved(const QString &devId);
0084 
0085   private Q_SLOTS:
0086     void getDevices();
0087     void gotDevices(const QDBusMessage &msg);
0088     void deviceAddedSlot(const QString &dev);
0089     void deviceRemovedSlot(const QString &dev);
0090     void deviceVisibilityChanged(const QString &dev, bool visible);
0091 
0092   private:
0093     QMap<QString, Device> devices;
0094 };
0095 
0096 #endif