File indexing completed on 2024-04-21 04:56:45

0001 /**
0002  * SPDX-FileCopyrightText: 2015 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef KDECONNECTCONFIG_H
0008 #define KDECONNECTCONFIG_H
0009 
0010 #include <QDir>
0011 
0012 #include "deviceinfo.h"
0013 #include "kdeconnectcore_export.h"
0014 
0015 class QSslCertificate;
0016 
0017 class KDECONNECTCORE_EXPORT KdeConnectConfig
0018 {
0019 public:
0020     static KdeConnectConfig &instance();
0021 
0022     /*
0023      * Our own info
0024      */
0025 
0026     QString deviceId();
0027     QString name();
0028     DeviceType deviceType();
0029     QSslCertificate certificate();
0030     DeviceInfo deviceInfo();
0031     QString privateKeyPath();
0032     QString certificatePath();
0033 
0034     void setName(const QString &name);
0035 
0036     /*
0037      * Trusted devices
0038      */
0039 
0040     QStringList trustedDevices(); // list of ids
0041     void removeTrustedDevice(const QString &id);
0042     void addTrustedDevice(const DeviceInfo &deviceInfo);
0043     void updateTrustedDeviceInfo(const DeviceInfo &deviceInfo);
0044     DeviceInfo getTrustedDevice(const QString &id);
0045     QSslCertificate getTrustedDeviceCertificate(const QString &id);
0046 
0047     void setDeviceProperty(const QString &deviceId, const QString &name, const QString &value);
0048     QString getDeviceProperty(const QString &deviceId, const QString &name, const QString &defaultValue = QString());
0049 
0050     // Custom devices
0051     void setCustomDevices(const QStringList &addresses);
0052     QStringList customDevices() const;
0053 
0054     /*
0055      * Paths for config files, there is no guarantee the directories already exist
0056      */
0057     QDir baseConfigDir();
0058     QDir deviceConfigDir(const QString &deviceId);
0059     QDir pluginConfigDir(const QString &deviceId, const QString &pluginName); // Used by KdeConnectPluginConfig
0060 
0061 #ifdef Q_OS_MAC
0062     /*
0063      * Get private DBus Address when use private DBus
0064      */
0065     QString privateDBusAddressPath();
0066     QString privateDBusAddress();
0067 #endif
0068 private:
0069     KdeConnectConfig();
0070 
0071     void loadOrGeneratePrivateKeyAndCertificate(const QString &keyPath, const QString &certPath);
0072     bool loadPrivateKey(const QString &path);
0073     bool loadCertificate(const QString &path);
0074     void generatePrivateKey(const QString &path);
0075     void generateCertificate(const QString &path);
0076 
0077     struct KdeConnectConfigPrivate *d;
0078 };
0079 
0080 #endif