7#include "connector_p.h"
10#include "../shared/connectorutils_p.h"
14#include <QStandardPaths>
19ConnectorPrivate::ConnectorPrivate(
Connector *qq)
26ConnectorPrivate::~ConnectorPrivate()
33 qCDebug(
Log) << token << message << messageIdentifier;
34 if (token != m_token) {
35 qCWarning(
Log) <<
"Got message for a different token??";
38 Q_EMIT q->messageReceived(message);
41void ConnectorPrivate::NewEndpoint(
const QString &token,
const QString &endpoint)
43 qCDebug(
Log) << token << endpoint;
44 if (token != m_token) {
45 qCWarning(
Log) <<
"Got new endpoint for a different token??";
50 QString actuallyWorkingEndpoint(endpoint);
53 if (m_endpoint != actuallyWorkingEndpoint) {
54 m_endpoint = actuallyWorkingEndpoint;
55 Q_EMIT q->endpointChanged(m_endpoint);
61void ConnectorPrivate::Unregistered(
const QString &token)
63 qCDebug(
Log) << token;
69 Q_EMIT q->endpointChanged(m_endpoint);
71 qCDebug(
Log) <<
"Removing" << stateFile() << res;
76 else if (token == m_token) {
78 Q_EMIT q->endpointChanged(m_endpoint);
84 m_currentCommand = Command::None;
89QString ConnectorPrivate::stateFile()
const
94void ConnectorPrivate::loadState()
97 settings.beginGroup(QStringLiteral(
"Client"));
98 m_token = settings.value(QStringLiteral(
"Token"),
QString()).toString();
99 m_endpoint = settings.value(QStringLiteral(
"Endpoint"),
QString()).toString();
100 m_description = settings.value(QStringLiteral(
"Description"),
QString()).toString();
103void ConnectorPrivate::storeState()
const
106 settings.beginGroup(QStringLiteral(
"Client"));
107 settings.setValue(QStringLiteral(
"Token"), m_token);
108 settings.setValue(QStringLiteral(
"Endpoint"), m_endpoint);
109 settings.setValue(QStringLiteral(
"Description"), m_description);
112void ConnectorPrivate::setDistributor(
const QString &distServiceName)
114 if (distServiceName.
isEmpty()) {
115 qCWarning(
Log) <<
"No UnifiedPush distributor found.";
120 doSetDistributor(distServiceName);
121 qCDebug(
Log) <<
"Selected distributor" << distServiceName;
124 if (!m_token.isEmpty()) {
125 q->registerClient(m_description);
131 qCDebug(
Log) << state;
132 if (m_state == state) {
137 Q_EMIT q->stateChanged(m_state);
140void ConnectorPrivate::addCommand(ConnectorPrivate::Command cmd)
143 if (!m_commandQueue.empty()) {
144 if (m_commandQueue.back() == cmd) {
148 m_commandQueue.pop_back();
151 }
else if (m_currentCommand == cmd) {
155 m_commandQueue.push_back(cmd);
156 processNextCommand();
159void ConnectorPrivate::processNextCommand()
161 if (m_currentCommand != Command::None || !hasDistributor() || m_commandQueue.empty()) {
165 m_currentCommand = m_commandQueue.front();
166 m_commandQueue.pop_front();
168 switch (m_currentCommand) {
171 case Command::Register:
174 m_currentCommand = Command::None;
178 if (m_token.isEmpty()) {
181 qCDebug(
Log) <<
"Registering";
187 m_currentCommand = Command::None;
190 qCDebug(
Log) <<
"Unregistering";
195 processNextCommand();
201 , d(new ConnectorPrivate(this))
203 d->m_serviceName = serviceName;
204 if (d->m_serviceName.isEmpty()) {
205 qCWarning(Log) <<
"empty D-Bus service name!";
210 d->setDistributor(ConnectorUtils::selectDistributor());
213Connector::~Connector() =
default;
217 return d->m_endpoint;
222 qCDebug(
Log) << d->m_state;
223 d->m_description = description;
224 d->addCommand(ConnectorPrivate::Command::Register);
229 qCDebug(
Log) << d->m_state;
230 d->addCommand(ConnectorPrivate::Command::Unregister);
238#include "moc_connector.cpp"
240#include "moc_connector_p.cpp"
@ Unregister
unregistration requested by client
Client connector to UnifiedPush.
Connector(const QString &serviceName, QObject *parent=nullptr)
Create a new connector instance.
void unregisterClient()
Unregister this client.
@ NoDistributor
Connector cannot find a UnifiedPush distributor to register at.
@ Registering
Connector is registering with the push provider.
@ Registered
Connector is registered and thus operational.
@ Unregistered
Connector is not yet registered, or explicitly unregistered.
void registerClient(const QString &description)
Register this client.
Client-side integration with UnifiedPush.
QString writableLocation(StandardLocation type)
bool isEmpty() const const
QString toString(StringFormat mode) const const