Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1a3257f4 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Fix client-side Connection handling

Fix connecting to named pipes for Notification connection and make
the code platform independent.
parent 17062ae1
......@@ -22,6 +22,7 @@
#include "servermanager_p.h"
#include "akonadicore_debug.h"
#include "commandbuffer_p.h"
#include <private/instance_p.h>
#include <QDataStream>
#include <QFile>
......@@ -86,6 +87,31 @@ void Connection::reconnect()
Q_UNUSED(ok)
}
QString Connection::defaultAddressForTypeAndMethod(ConnectionType type, const QString &method)
{
if (method == QLatin1String("UnixPath")) {
const QString defaultSocketDir = StandardDirs::saveDir("data");
if (type == CommandConnection) {
return defaultSocketDir % QStringLiteral("akonadiserver-cmd.socket");
} else if (type == NotificationConnection) {
return defaultSocketDir % QStringLiteral("akonadiserver-ntf.socket");
}
} else if (method == QLatin1String("NamedPipe")) {
QString suffix;
if (Instance::hasIdentifier()) {
suffix += QStringLiteral("%1-").arg(Instance::identifier());
}
suffix += QString::fromUtf8(QUrl::toPercentEncoding(qApp->applicationDirPath()));
if (type == CommandConnection) {
return QStringLiteral("Akonadi-Cmd-") % suffix;
} else if (type == NotificationConnection) {
return QStringLiteral("Akonadi-Ntf-") % suffix;
}
}
Q_UNREACHABLE();
}
void Connection::doReconnect()
{
Q_ASSERT(QThread::currentThread() == thread());
......@@ -135,29 +161,18 @@ void Connection::doReconnect()
"akonadi/akonadiconnectionrc' can not be found!";
}
// TODO: share socket setup with server
const QSettings connectionSettings(connectionConfigFile, QSettings::IniFormat);
#ifdef Q_OS_WIN
// use the installation prefix as uid
const QString prefix = QString::fromUtf8(QUrl::toPercentEncoding(qApp->applicationDirPath()));
if (mConnectionType == CommandConnection) {
const QString defaultPipe = QStringLiteral("Akonadi-Cmd-") % prefix;
serverAddress = connectionSettings.value(QStringLiteral("Data/NamedPipe"), defaultPipe).toString();
} else if (mConnectionType == NotificationConnection) {
const QString defaultPipe = QStringLiteral("Akonadi-Ntf-") % prefix;
serverAddress = connectionSettings.value(QStringLiteral("Data/NamedPipe"), defaultPipe).toString();
}
#else
const QString defaultSocketDir = StandardDirs::saveDir("data");
QSettings connectionSettings(connectionConfigFile, QSettings::IniFormat);
QString connectionType;
if (mConnectionType == CommandConnection) {
const QString defaultSocketPath = defaultSocketDir % QStringLiteral("/akonadiserver-cmd.socket");
serverAddress = connectionSettings.value(QStringLiteral("Data/UnixPath"), defaultSocketPath).toString();
connectionType = QStringLiteral("Data");
} else if (mConnectionType == NotificationConnection) {
const QString defaultSocketPath = defaultSocketDir % QStringLiteral("/akonadiserver-ntf.socket");
serverAddress = connectionSettings.value(QStringLiteral("Notifications/UnixPath"), defaultSocketPath).toString();
connectionType = QStringLiteral("Notifications");
}
#endif
connectionSettings.beginGroup(connectionType);
const auto method = connectionSettings.value(QStringLiteral("Method"), QStringLiteral("UnixPath")).toString();
serverAddress = connectionSettings.value(method, defaultAddressForTypeAndMethod(mConnectionType, method)).toString();
}
// create sockets if not yet done, note that this does not yet allow changing socket types on the fly
......
......@@ -80,7 +80,7 @@ private Q_SLOTS:
private:
QString defaultAddressForTypeAndMethod(ConnectionType type, const QString &method);
bool handleCommand(qint64 tag, const Protocol::CommandPtr &cmd);
ConnectionType mConnectionType;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment