1 /**
2  * SPDX-FileCopyrightText: 2015 Albert Vaca <albertvaka@gmail.com>
3  *
4  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5  */
6 
7 #ifndef KDECONNECTCONFIG_H
8 #define KDECONNECTCONFIG_H
9 
10 #include <QDir>
11 
12 #include "kdeconnectcore_export.h"
13 
14 class QSslCertificate;
15 
16 class KDECONNECTCORE_EXPORT KdeConnectConfig
17 {
18 public:
19     struct DeviceInfo {
20         QString deviceName;
21         QString deviceType;
22     };
23 
24     static KdeConnectConfig& instance();
25 
26     /*
27      * Our own info
28      */
29 
30     QString deviceId();
31     QString name();
32     QString deviceType();
33 
34     QString privateKeyPath();
35     QString certificatePath();
36     QSslCertificate certificate();
37 
38     void setName(const QString& name);
39 
40     /*
41      * Trusted devices
42      */
43 
44     QStringList trustedDevices(); //list of ids
45     void removeTrustedDevice(const QString& id);
46     void addTrustedDevice(const QString& id, const QString& name, const QString& type);
47     KdeConnectConfig::DeviceInfo getTrustedDevice(const QString& id);
48 
49     void setDeviceProperty(const QString& deviceId, const QString& name, const QString& value);
50     QString getDeviceProperty(const QString& deviceId, const QString& name, const QString& defaultValue = QString());
51 
52     // Custom devices
53     void setCustomDevices(const QStringList& addresses);
54     QStringList customDevices() const;
55 
56     /*
57      * Paths for config files, there is no guarantee the directories already exist
58      */
59     QDir baseConfigDir();
60     QDir deviceConfigDir(const QString& deviceId);
61     QDir pluginConfigDir(const QString& deviceId, const QString& pluginName); //Used by KdeConnectPluginConfig
62 
63 #ifdef USE_PRIVATE_DBUS
64     /*
65      * Get private DBus Address when use private DBus
66      */
67     QString privateDBusAddressPath();
68     QString privateDBusAddress();
69 #endif
70 private:
71     KdeConnectConfig();
72 
73     void loadPrivateKey();
74     void generatePrivateKey(const QString&  path);
75     void loadCertificate();
76     void generateCertificate(const QString&  path);
77 
78     struct KdeConnectConfigPrivate* d;
79 };
80 
81 #endif
82