ukui-search/libsearch/remote-file-event-helper.cpp

49 lines
1.9 KiB
C++
Raw Normal View History

#include "remote-file-event-helper.h"
#include "rep_fileeventhandler_replica.h"
#include <QtRemoteObjects>
#include <QDebug>
RemoteFileEventHelper::RemoteFileEventHelper(QObject *parent) : QObject(parent)
{
setupConnections();
}
RemoteFileEventHelper::~RemoteFileEventHelper()
{
delete m_fileEventHandlerIface;
delete m_remoteNode;
}
void RemoteFileEventHelper::setupConnections()
{
m_remoteNode = new QRemoteObjectNode;
m_remoteNode->connectToNode(nodeUrl());
m_fileEventHandlerIface = m_remoteNode->acquire<FileEventHandlerReplica>();
qDebug() << "connect handle" << m_fileEventHandlerIface;
connect(m_fileEventHandlerIface, &QRemoteObjectReplica::initialized, this, [=]{
qDebug() << "initilized" << m_fileEventHandlerIface;
});
connect(m_fileEventHandlerIface, &QRemoteObjectReplica::stateChanged, this, [=](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState){
qDebug() << "state changed" << state << oldState << m_fileEventHandlerIface;
if (state == QRemoteObjectReplica::Suspect) {
qDebug() << "try reconnect";
m_fileEventHandlerIface->deleteLater();
m_remoteNode->deleteLater();
setupConnections();
}
});
connect(this, &RemoteFileEventHelper::handleFileEventRequest, m_fileEventHandlerIface, [=](int type, const QString &arg1, const QString &arg2){
qDebug() << type << arg1 << arg2 << m_fileEventHandlerIface;
if (m_fileEventHandlerIface->state() == QRemoteObjectReplica::Valid)
m_fileEventHandlerIface->handleFileEvent(type, arg1, arg2);
});
}
QUrl RemoteFileEventHelper::nodeUrl()
{
QString displayEnv = (qgetenv("XDG_SESSION_TYPE") == "wayland") ? QLatin1String("WAYLAND_DISPLAY") : QLatin1String("DISPLAY");
QString display(qgetenv(displayEnv.toUtf8().data()));
return QUrl(QStringLiteral("local:ukui-idm-") + QString(qgetenv("USER")) + display);
}