Clean up host information propertly once removed from settings
This commit is contained in:
parent
264f803a17
commit
422e7675f9
@ -49,8 +49,8 @@ class NymeaConnection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
||||
Q_PROPERTY(NymeaHost* currentHost READ currentHost WRITE setCurrentHost NOTIFY currentHostChanged)
|
||||
Q_PROPERTY(Connection* currentConnection READ currentConnection NOTIFY currentConnectionChanged)
|
||||
Q_PROPERTY(NymeaHost *currentHost READ currentHost WRITE setCurrentHost NOTIFY currentHostChanged)
|
||||
Q_PROPERTY(Connection *currentConnection READ currentConnection NOTIFY currentConnectionChanged)
|
||||
Q_PROPERTY(NymeaConnection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged)
|
||||
Q_PROPERTY(ConnectionStatus connectionStatus READ connectionStatus NOTIFY connectionStatusChanged)
|
||||
|
||||
@ -98,11 +98,10 @@ public:
|
||||
bool connected();
|
||||
ConnectionStatus connectionStatus() const;
|
||||
|
||||
NymeaHost* currentHost() const;
|
||||
NymeaHost *currentHost() const;
|
||||
void setCurrentHost(NymeaHost *host);
|
||||
|
||||
Connection* currentConnection() const;
|
||||
|
||||
Connection *currentConnection() const;
|
||||
|
||||
void sendData(const QByteArray &data);
|
||||
|
||||
@ -134,8 +133,8 @@ private:
|
||||
ConnectionStatus m_connectionStatus = ConnectionStatusUnconnected;
|
||||
NetworkReachabilityMonitor *m_networkReachabilityMonitor = nullptr;
|
||||
|
||||
QHash<QString, NymeaTransportInterfaceFactory*> m_transportFactories;
|
||||
QHash<NymeaTransportInterface*, Connection*> m_transportCandidates;
|
||||
QHash<QString, NymeaTransportInterfaceFactory *> m_transportFactories;
|
||||
QHash<NymeaTransportInterface *, Connection *> m_transportCandidates;
|
||||
NymeaTransportInterface *m_currentTransport = nullptr;
|
||||
NymeaHost *m_currentHost = nullptr;
|
||||
Connection *m_preferredConnection = nullptr;
|
||||
|
||||
@ -92,12 +92,15 @@ void NymeaHosts::removeHost(NymeaHost *host)
|
||||
{
|
||||
int idx = m_hosts.indexOf(host);
|
||||
if (idx == -1) {
|
||||
qWarning() << "Cannot remove NymeaHost" << host << "as its nit in the model";
|
||||
qWarning() << "Cannot remove NymeaHost" << host << "as its not in the model";
|
||||
return;
|
||||
}
|
||||
beginRemoveRows(QModelIndex(), idx, idx);
|
||||
m_hosts.takeAt(idx);
|
||||
endRemoveRows();
|
||||
|
||||
|
||||
|
||||
emit hostRemoved(host);
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ protected:
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
private:
|
||||
QList<NymeaHost*> m_hosts;
|
||||
QList<NymeaHost *> m_hosts;
|
||||
};
|
||||
|
||||
class NymeaHostsFilterModel: public QSortFilterProxyModel
|
||||
@ -94,10 +94,10 @@ class NymeaHostsFilterModel: public QSortFilterProxyModel
|
||||
public:
|
||||
NymeaHostsFilterModel(QObject *parent = nullptr);
|
||||
|
||||
NymeaDiscovery* discovery() const;
|
||||
NymeaDiscovery *discovery() const;
|
||||
void setDiscovery(NymeaDiscovery *discovery);
|
||||
|
||||
JsonRpcClient* jsonRpcClient() const;
|
||||
JsonRpcClient *jsonRpcClient() const;
|
||||
void setJsonRpcClient(JsonRpcClient* jsonRpcClient);
|
||||
|
||||
bool showUnreachableBearers() const;
|
||||
|
||||
@ -77,8 +77,8 @@ public:
|
||||
NymeaConnection::BearerTypes availableBearerTypes() const;
|
||||
NymeaConnection::ConnectionStatus connectionStatus() const;
|
||||
bool connected() const;
|
||||
NymeaHost* currentHost() const;
|
||||
Connection* currentConnection() const;
|
||||
NymeaHost *currentHost() const;
|
||||
Connection *currentConnection() const;
|
||||
QVariantMap certificateIssuerInfo() const;
|
||||
bool initialSetupRequired() const;
|
||||
bool authenticationRequired() const;
|
||||
@ -147,8 +147,8 @@ private slots:
|
||||
private:
|
||||
int m_id;
|
||||
// < namespace, method> >
|
||||
QHash<QObject*, QString> m_notificationHandlerMethods;
|
||||
QMultiHash<QString, QObject*> m_notificationHandlers;
|
||||
QHash<QObject *, QString> m_notificationHandlerMethods;
|
||||
QMultiHash<QString, QObject *> m_notificationHandlers;
|
||||
QHash<int, JsonRpcReply *> m_replies;
|
||||
NymeaConnection *m_connection = nullptr;
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "configuredhostsmodel.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcApplication)
|
||||
@ -99,12 +101,55 @@ void ConfiguredHostsModel::removeHost(int index)
|
||||
qCWarning(dcApplication()) << "Cannot remove connection at index" << index;
|
||||
return;
|
||||
}
|
||||
|
||||
beginRemoveRows(QModelIndex(), index, index);
|
||||
m_list.takeAt(index)->deleteLater();
|
||||
|
||||
ConfiguredHost *host = m_list.takeAt(index);
|
||||
qCDebug(dcApplication()) << "Remove configured host" << host->name() << host->uuid().toString();
|
||||
|
||||
QSettings settings;
|
||||
|
||||
QString hostUuidString = host->uuid().toString();
|
||||
|
||||
qCDebug(dcApplication()) << "-> Remove stored token";
|
||||
settings.beginGroup("jsonTokens");
|
||||
if (settings.contains(hostUuidString)) {
|
||||
settings.remove(hostUuidString);
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
qCDebug(dcApplication()) << "-> Remove cached hosts";
|
||||
settings.beginGroup("HostCache");
|
||||
settings.beginGroup(hostUuidString);
|
||||
settings.remove("");
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
|
||||
qCDebug(dcApplication()) << "-> Remove host settings";
|
||||
settings.beginGroup(hostUuidString);
|
||||
settings.remove("");
|
||||
settings.endGroup();
|
||||
|
||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/sslcerts/");
|
||||
QFile certFile(dir.absoluteFilePath(hostUuidString.remove(QRegExp("[{}]")) + ".pem"));
|
||||
if (certFile.exists()) {
|
||||
if (!certFile.remove()) {
|
||||
qCWarning(dcApplication()) << "Failed to remove certificate file" << certFile.fileName() << certFile.errorString();
|
||||
} else {
|
||||
qCDebug(dcApplication()) << "-> Removed successfully host certificate" << certFile.fileName();
|
||||
}
|
||||
} else {
|
||||
qCDebug(dcApplication()) << "-> No certificated stored for this host";
|
||||
}
|
||||
|
||||
host->deleteLater();
|
||||
|
||||
saveToDisk();
|
||||
|
||||
endRemoveRows();
|
||||
emit countChanged();
|
||||
|
||||
|
||||
if (m_list.isEmpty()) {
|
||||
createHost();
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ class ConfiguredHost: public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QUuid uuid READ uuid WRITE setUuid NOTIFY uuidChanged)
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(Engine* engine READ engine CONSTANT)
|
||||
Q_PROPERTY(Engine *engine READ engine CONSTANT)
|
||||
|
||||
public:
|
||||
ConfiguredHost(const QUuid &uuid = QUuid(), QObject *parent = nullptr);
|
||||
@ -57,8 +57,8 @@ public:
|
||||
void setCurrentIndex(int currentIndex);
|
||||
|
||||
Q_INVOKABLE int indexOf(ConfiguredHost *host) const;
|
||||
Q_INVOKABLE ConfiguredHost* get(int index) const;
|
||||
Q_INVOKABLE ConfiguredHost* createHost();
|
||||
Q_INVOKABLE ConfiguredHost *get(int index) const;
|
||||
Q_INVOKABLE ConfiguredHost *createHost();
|
||||
Q_INVOKABLE void removeHost(int index);
|
||||
Q_INVOKABLE void move(int from, int to);
|
||||
|
||||
@ -72,7 +72,7 @@ private:
|
||||
void saveToDisk();
|
||||
|
||||
private:
|
||||
QList<ConfiguredHost*> m_list;
|
||||
QList<ConfiguredHost *> m_list;
|
||||
int m_currentIndex = 0;
|
||||
};
|
||||
|
||||
@ -85,13 +85,13 @@ class ConfiguredHostsProxyModel: public QSortFilterProxyModel
|
||||
public:
|
||||
ConfiguredHostsProxyModel(QObject *parent = nullptr);
|
||||
|
||||
ConfiguredHostsModel* model() const;
|
||||
ConfiguredHostsModel *model() const;
|
||||
void setModel(ConfiguredHostsModel *model);
|
||||
|
||||
QUuid currentHost() const;
|
||||
void setCurrentHost(const QUuid ¤tHost);
|
||||
|
||||
Q_INVOKABLE ConfiguredHost* get(int index) const;
|
||||
Q_INVOKABLE ConfiguredHost *get(int index) const;
|
||||
|
||||
signals:
|
||||
void modelChanged();
|
||||
|
||||
Reference in New Issue
Block a user