File indexing completed on 2024-05-12 09:39:26
0001 /* 0002 * SPDX-FileCopyrightText: 2017, 2018, 2019 Ivan Cukic <ivan.cukic (at) kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef PLASMAVAULT_KDED_ENGINE_VAULT_H 0008 #define PLASMAVAULT_KDED_ENGINE_VAULT_H 0009 0010 #include <QDBusArgument> 0011 #include <QObject> 0012 #include <QString> 0013 #include <QVariant> 0014 0015 #include <common/vaultinfo.h> 0016 0017 #include "types.h" 0018 0019 #include "commandresult.h" 0020 0021 namespace PlasmaVault 0022 { 0023 // Main keys 0024 #define KEY_NAME "vault-name" 0025 #define KEY_BACKEND "vault-backend" 0026 #define KEY_PASSWORD "vault-password" 0027 #define KEY_DEVICE "vault-device" 0028 #define KEY_MOUNT_POINT "vault-mount-point" 0029 0030 // Additional options 0031 #define KEY_ACTIVITIES "vault-activities" 0032 #define KEY_OFFLINEONLY "vault-offline-only" 0033 0034 class Vault : public QObject 0035 { 0036 Q_OBJECT 0037 0038 Q_PROPERTY(PlasmaVault::Device device READ device) 0039 Q_PROPERTY(PlasmaVault::MountPoint mountPoint READ mountPoint NOTIFY mountPointChanged) 0040 0041 Q_PROPERTY(VaultInfo::Status status READ status NOTIFY statusChanged) 0042 0043 Q_PROPERTY(bool isInitialized READ isInitialized NOTIFY isInitializedChanged) 0044 Q_PROPERTY(bool isOpened READ isOpened NOTIFY isOpenedChanged) 0045 Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) 0046 0047 Q_PROPERTY(QString name READ name NOTIFY nameChanged) 0048 Q_PROPERTY(QString message READ message NOTIFY messageChanged) 0049 0050 Q_PROPERTY(QStringList activities READ activities NOTIFY activitiesChanged) 0051 Q_PROPERTY(bool isOfflineOnly READ isOfflineOnly NOTIFY isOfflineOnlyChanged) 0052 0053 public: 0054 Vault(const Device &device, QObject *parent = nullptr); 0055 ~Vault() override; 0056 0057 typedef QHash<QByteArray, QVariant> Payload; 0058 0059 bool isValid() const; 0060 0061 FutureResult<> create(const QString &name, const MountPoint &mountPoint, const Payload &payload); 0062 FutureResult<> import(const QString &name, const MountPoint &mountPoint, const Payload &payload); 0063 0064 FutureResult<> open(const Payload &payload); 0065 FutureResult<> close(); 0066 0067 // FutureResult<> configure(); 0068 FutureResult<> forceClose(); 0069 0070 FutureResult<> dismantle(const Payload &payload); 0071 0072 VaultInfo info() const; 0073 0074 // TODO: Replace this with shared_ptr and enable_shared_from_this? 0075 void scheduleDeletion(); 0076 0077 void updateStatus(); 0078 0079 public Q_SLOTS: 0080 QString message() const; 0081 VaultInfo::Status status() const; 0082 0083 bool isInitialized() const; 0084 bool isOpened() const; 0085 bool isBusy() const; 0086 0087 Device device() const; 0088 QString backend() const; 0089 0090 MountPoint mountPoint() const; 0091 void setMountPoint(const MountPoint &mountPoint); 0092 0093 QString name() const; 0094 void setName(const QString &name); 0095 0096 QStringList activities() const; 0097 void setActivities(const QStringList &activities); 0098 0099 bool isOfflineOnly() const; 0100 void setIsOfflineOnly(bool isOfflineOnly); 0101 0102 void saveConfiguration(); 0103 0104 Q_SIGNALS: 0105 void mountPointChanged(const QString &mountPoint); 0106 void statusChanged(VaultInfo::Status status); 0107 void isInitializedChanged(bool isInitialized); 0108 void isOpenedChanged(bool isOpened); 0109 void isBusyChanged(bool isBusy); 0110 void activitiesChanged(const QStringList &activities); 0111 void messageChanged(const QString &message); 0112 void nameChanged(const QString &name); 0113 void isOfflineOnlyChanged(bool isOfflineOnly); 0114 0115 void infoChanged(); 0116 0117 public: 0118 static QList<Device> availableDevices(); 0119 static QStringList statusMessage(); 0120 0121 private: 0122 class Private; 0123 QScopedPointer<Private> d; 0124 }; 0125 0126 } // namespace PlasmaVault 0127 0128 #endif // include guard