De-duplicated small piece of code

This commit is contained in:
Albert Vaca 2014-06-15 21:39:46 +02:00
parent 8c7c95f98b
commit 734b27ed50
2 changed files with 12 additions and 10 deletions

View file

@ -57,11 +57,7 @@ Device::Device(QObject* parent, const QString& id)
const QString& key = data.readEntry<QString>("publicKey", QString());
m_publicKey = QCA::RSAPublicKey::fromPEM(key);
//TODO: It is redundant to have our own private key in every instance of Device, move this to a singleton somewhere (Daemon?)
const QString privateKeyPath = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect"));
QFile privKey(privateKeyPath);
privKey.open(QIODevice::ReadOnly);
m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
initPrivateKey();
//Register in bus
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
@ -75,11 +71,7 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
, m_pairStatus(Device::NotPaired)
, m_protocolVersion(identityPackage.get<int>("protocolVersion"))
{
//TODO: It is redundant to have our own private key in every instance of Device, move this to a singleton somewhere (Daemon?)
const QString privateKeyPath = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect"));
QFile privKey(privateKeyPath);
privKey.open(QIODevice::ReadOnly);
m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
initPrivateKey();
addLink(identityPackage, dl);
@ -87,6 +79,15 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
}
void Device::initPrivateKey()
{
//TODO: It is redundant to have our own private key in every instance of Device, move this to a singleton somewhere (Daemon?)
const QString privateKeyPath = KStandardDirs::locateLocal("appdata", "key.pem", true, KComponentData("kdeconnect", "kdeconnect"));
QFile privKey(privateKeyPath);
privKey.open(QIODevice::ReadOnly);
m_privateKey = QCA::PrivateKey::fromPEM(privKey.readAll());
}
Device::~Device()
{

View file

@ -140,6 +140,7 @@ private:
void setAsPaired();
void storeAsTrusted();
bool sendOwnPublicKey();
void initPrivateKey();
};