aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2018-01-27 01:45:04 +0100
committerDaniel Vrátil <[email protected]>2018-01-27 01:45:04 +0100
commit1a3257f47e7519782aec70ba704ea4cfb763c049 (patch)
tree23535b5f5e1b05198fe5f07daf51ca118abf6358
parent17062ae17fff096c08447a792ccf077c6eab5ef2 (diff)
Fix client-side Connection handling
Fix connecting to named pipes for Notification connection and make the code platform independent.
-rw-r--r--src/core/connection.cpp53
-rw-r--r--src/core/connection_p.h2
2 files changed, 35 insertions, 20 deletions
diff --git a/src/core/connection.cpp b/src/core/connection.cpp
index e0d5f95..c8a21ee 100644
--- a/src/core/connection.cpp
+++ b/src/core/connection.cpp
@@ -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
diff --git a/src/core/connection_p.h b/src/core/connection_p.h
index fa0e4fb..c2d7d3d 100644
--- a/src/core/connection_p.h
+++ b/src/core/connection_p.h
@@ -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;