File indexing completed on 2024-04-28 13:42:04
0001 // SPDX-License-Identifier: GPL-3.0-or-later 0002 /* 0003 Copyright 2017 - 2020 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 _DeviceList_H_ 0022 #define _DeviceList_H_ 0023 0024 #include <QScrollArea> 0025 #include <QVBoxLayout> 0026 #include <QMap> 0027 0028 #include <Solid/Device> 0029 #include <Solid/Predicate> 0030 #include <Solid/SolidNamespace> 0031 #include <QLabel> 0032 #include <QTimer> 0033 #include <QToolButton> 0034 #include <QPointer> 0035 0036 #include <KCMultiDialog> 0037 #include <KServiceAction> 0038 0039 #include <KdeConnect.hxx> 0040 0041 //-------------------------------------------------------------------------------- 0042 0043 struct DeviceAction 0044 { 0045 DeviceAction() { } 0046 DeviceAction(const QString &filePath, Solid::Predicate p, KServiceAction a) 0047 : path(filePath), predicate(p), action(a) { } 0048 0049 QString path; 0050 Solid::Predicate predicate; 0051 KServiceAction action; 0052 }; 0053 0054 //-------------------------------------------------------------------------------- 0055 0056 class DeviceItem : public QFrame 0057 { 0058 Q_OBJECT 0059 0060 public: 0061 DeviceItem(Solid::Device dev, const QVector<DeviceAction> &deviceActions); 0062 DeviceItem(const KdeConnect::Device &dev); 0063 0064 void markAsNew(); 0065 0066 private: 0067 static QString errorToString(Solid::ErrorType error); 0068 void fillData(); 0069 void kdeConnectDeviceChanged(const KdeConnect::Device &dev); 0070 0071 enum Action { Mount, Unmount }; 0072 void mountDone(Action action, Solid::ErrorType error, QVariant errorData, const QString &udi); 0073 0074 private Q_SLOTS: 0075 void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi); 0076 void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi); 0077 0078 private: 0079 Solid::Device device; 0080 QToolButton *mountButton = nullptr; 0081 QLabel *textLabel = nullptr, *statusLabel = nullptr, *newFlagLabel = nullptr; 0082 QLabel *chargeIcon = nullptr; 0083 QToolButton *ringButton = nullptr; 0084 QTimer statusTimer, mountBusyTimer; 0085 QPointer<KCMultiDialog> dialog; 0086 QString pendingCommand; // used when click -> mount -> action 0087 }; 0088 0089 //-------------------------------------------------------------------------------- 0090 0091 class DeviceList : public QScrollArea 0092 { 0093 Q_OBJECT 0094 0095 public: 0096 DeviceList(QWidget *parent); 0097 0098 bool isEmpty() const { return items.isEmpty(); } 0099 0100 QSize sizeHint() const override; 0101 0102 Q_SIGNALS: 0103 void deviceWasAdded(); 0104 void deviceWasRemoved(); 0105 0106 private Q_SLOTS: 0107 void deviceAdded(const QString &dev); 0108 void deviceRemoved(const QString &dev); 0109 void kdeConnectDeviceAdded(const KdeConnect::Device &dev); 0110 0111 private: 0112 void loadActions(); 0113 DeviceItem *addDevice(Solid::Device device); 0114 0115 private: 0116 QVBoxLayout *vbox; 0117 QMap<QString, DeviceItem *> items; 0118 Solid::Predicate predicate; 0119 0120 QVector<DeviceAction> actions; 0121 KdeConnect kdeConnect; 0122 }; 0123 0124 #endif