7#include "connector_p.h"
10#include "../shared/unifiedpush-constants.h"
11#include "../shared/connectorutils_p.h"
15#include <QStandardPaths>
20ConnectorPrivate::ConnectorPrivate(
Connector *qq)
27ConnectorPrivate::~ConnectorPrivate()
34 qCDebug(
Log) << token << message << messageIdentifier;
35 if (token != m_token) {
36 qCWarning(
Log) <<
"Got message for a different token??";
39 Q_EMIT q->messageReceived(message);
42void ConnectorPrivate::NewEndpoint(
const QString &token,
const QString &endpoint)
44 qCDebug(
Log) << token << endpoint;
45 if (token != m_token) {
46 qCWarning(
Log) <<
"Got new endpoint for a different token??";
51 QString actuallyWorkingEndpoint(endpoint);
54 if (m_endpoint != actuallyWorkingEndpoint) {
55 m_endpoint = actuallyWorkingEndpoint;
56 Q_EMIT q->endpointChanged(m_endpoint);
62void ConnectorPrivate::Unregistered(
const QString &token)
64 qCDebug(
Log) << token;
70 Q_EMIT q->endpointChanged(m_endpoint);
72 qCDebug(
Log) <<
"Removing" << stateFile() << res;
77 else if (token == m_token) {
79 Q_EMIT q->endpointChanged(m_endpoint);
85 m_currentCommand = Command::None;
90QString ConnectorPrivate::stateFile()
const
95void ConnectorPrivate::loadState()
98 settings.beginGroup(QStringLiteral(
"Client"));
99 m_token = settings.value(QStringLiteral(
"Token"),
QString()).toString();
100 m_endpoint = settings.value(QStringLiteral(
"Endpoint"),
QString()).toString();
101 m_description = settings.value(QStringLiteral(
"Description"),
QString()).toString();
104void ConnectorPrivate::storeState()
const
107 settings.beginGroup(QStringLiteral(
"Client"));
108 settings.setValue(QStringLiteral(
"Token"), m_token);
109 settings.setValue(QStringLiteral(
"Endpoint"), m_endpoint);
110 settings.setValue(QStringLiteral(
"Description"), m_description);
113void ConnectorPrivate::setDistributor(
const QString &distServiceName)
115 if (distServiceName.
isEmpty()) {
116 qCWarning(
Log) <<
"No UnifiedPush distributor found.";
121 doSetDistributor(distServiceName);
122 qCDebug(
Log) <<
"Selected distributor" << distServiceName;
125 if (!m_token.isEmpty()) {
126 q->registerClient(m_description);
132 qCDebug(
Log) << state;
133 if (m_state == state) {
138 Q_EMIT q->stateChanged(m_state);
141void ConnectorPrivate::addCommand(ConnectorPrivate::Command cmd)
144 if (!m_commandQueue.empty()) {
145 if (m_commandQueue.back() == cmd) {
149 m_commandQueue.pop_back();
152 }
else if (m_currentCommand == cmd) {
156 m_commandQueue.push_back(cmd);
157 processNextCommand();
160void ConnectorPrivate::processNextCommand()
162 if (m_currentCommand != Command::None || !hasDistributor() || m_commandQueue.empty()) {
166 m_currentCommand = m_commandQueue.front();
167 m_commandQueue.pop_front();
169 switch (m_currentCommand) {
172 case Command::Register:
175 m_currentCommand = Command::None;
179 if (m_token.isEmpty()) {
182 qCDebug(
Log) <<
"Registering";
188 m_currentCommand = Command::None;
191 qCDebug(
Log) <<
"Unregistering";
196 processNextCommand();
202 , d(new ConnectorPrivate(this))
204 d->m_serviceName = serviceName;
205 if (d->m_serviceName.isEmpty()) {
206 qCWarning(Log) <<
"empty D-Bus service name!";
211 d->setDistributor(ConnectorUtils::selectDistributor());
214Connector::~Connector() =
default;
218 return d->m_endpoint;
223 qCDebug(
Log) << d->m_state;
224 d->m_description = description;
225 d->addCommand(ConnectorPrivate::Command::Register);
230 qCDebug(
Log) << d->m_state;
231 d->addCommand(ConnectorPrivate::Command::Unregister);
239#include "moc_connector.cpp"
241#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