Skip to content

Commit 8900f88

Browse files
committed
Replace qtsingleapplication and add option to disable registry overloading
IB-8820 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 38737af commit 8900f88

56 files changed

Lines changed: 68 additions & 5436 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ else()
2626
target_link_libraries(qdigidoccommon PUBLIC PkgConfig::PCSCLITE)
2727
endif()
2828

29-
if(NOT APPLE)
30-
target_sources(qdigidoccommon PRIVATE qtsingleapplication/src/qtlocalpeer.cpp qtsingleapplication/src/qtsingleapplication.cpp)
31-
endif()
32-
3329
if( CONFIG_URL )
3430
set_env( LAST_CHECK_DAYS 4 CACHE STRING "How often check configuration changes" )
3531
if( LAST_CHECK_DAYS )

Common.cpp

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,26 @@
1919

2020
#include "Common.h"
2121

22+
#include <QtCore/QCoreApplication>
23+
#include <QtCore/QDir>
2224
#include <QtCore/QOperatingSystemVersion>
2325
#include <QtCore/QSettings>
26+
#include <QtCore/QStandardPaths>
27+
#include <QtCore/QThread>
28+
#include <QtNetwork/QLocalServer>
29+
#include <QtNetwork/QLocalSocket>
30+
31+
#include <chrono>
32+
33+
using namespace std::chrono_literals;
2434

2535
#ifdef Q_OS_WIN
2636
#include <qt_windows.h>
2737
#include <Regstr.h>
2838
#include <Setupapi.h>
2939

3040
using namespace Qt::StringLiterals;
31-
#elif defined(Q_OS_MAC)
41+
#elifdef Q_OS_MAC
3242
#include <PCSC/wintypes.h>
3343
#include <PCSC/winscard.h>
3444
#include <arpa/inet.h>
@@ -73,7 +83,7 @@ QStringList Common::drivers()
7383
{
7484
QStringList list;
7585
#ifdef Q_OS_WIN
76-
GUID guid {0x50dd5230L, 0xba8a, 0x11d1, 0xbf, 0x5d, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30}; // SmartCardReader
86+
static const GUID guid {0x50dd5230L, 0xba8a, 0x11d1, 0xbf, 0x5d, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30}; // SmartCardReader
7787
HDEVINFO h = SetupDiGetClassDevs(&guid, nullptr, 0, DIGCF_PRESENT);
7888
if(!h)
7989
return list;
@@ -111,8 +121,56 @@ QStringList Common::drivers()
111121
if(SCardListReaders(context, nullptr, data.data(), &size) != SCARD_S_SUCCESS)
112122
data.clear();
113123
SCardReleaseContext(context);
114-
list = QString::fromLatin1(data).split('\0');
115-
list.removeAll({});
124+
for(const char *name = data.data(); *name; name += std::char_traits<char>::length(name) + 1)
125+
list.append(QString::fromLatin1(name));
116126
#endif
117127
return list;
118128
}
129+
130+
static QString serverName()
131+
{
132+
#ifdef Q_OS_WIN
133+
return QCoreApplication::applicationName();
134+
#else
135+
QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
136+
if(runtimeDir.isEmpty())
137+
runtimeDir = QDir::tempPath();
138+
return runtimeDir + QLatin1Char('/') + QCoreApplication::applicationName();
139+
#endif
140+
}
141+
142+
bool Common::sendLocalMessage(const QStringList &args)
143+
{
144+
QLocalSocket socket;
145+
int timeout = 5000;
146+
for(int i = 0; i < 2; i++) {
147+
socket.connectToServer(serverName(), QLocalSocket::WriteOnly);
148+
if(socket.waitForConnected(timeout/2))
149+
break;
150+
if(i)
151+
return false;
152+
QThread::sleep(250ms);
153+
}
154+
QDataStream ds(&socket);
155+
ds << args;
156+
return socket.waitForBytesWritten(timeout);
157+
}
158+
159+
bool Common::startLocalServer(QObject *parent, std::function<void (const QStringList&)> f)
160+
{
161+
auto *server = new QLocalServer(parent);
162+
QObject::connect(server, &QLocalServer::newConnection, parent, [server, parent, f = std::move(f)] {
163+
while(QLocalSocket *socket = server->nextPendingConnection())
164+
{
165+
QObject::connect(socket, &QLocalSocket::readyRead, parent, [socket, f = std::move(f)] {
166+
QDataStream ds(socket);
167+
QStringList args;
168+
ds >> args;
169+
socket->waitForDisconnected(1000);
170+
socket->deleteLater();
171+
f(args);
172+
});
173+
}
174+
});
175+
return server->listen(serverName());
176+
}

Common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121

2222
#include <QtCore/QStringList>
2323

24+
#include <functional>
25+
2426
class Common
2527
{
2628
public:
2729
static QString applicationOs();
2830
static QStringList drivers();
29-
31+
static bool sendLocalMessage(const QStringList &args);
32+
static bool startLocalServer(QObject *parent, std::function<void (const QStringList&)> f);
3033
};

Configuration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ void Configuration::Private::setData(const QByteArray &_data, const QByteArray &
111111
data = _data;
112112
signature = _signature;
113113
dataobject = toObject(data);
114+
#ifdef NO_REGISTRY
114115
QSettings system(QSettings::SystemScope);
115116
for(const QString &key: system.childKeys())
116117
{
@@ -126,6 +127,7 @@ void Configuration::Private::setData(const QByteArray &_data, const QByteArray &
126127
default: break;
127128
}
128129
}
130+
#endif
129131
}
130132

131133
bool Configuration::Private::validate(const QByteArray &data, const QByteArray &signature) const

qtsingleapplication/INSTALL.TXT

Lines changed: 0 additions & 254 deletions
This file was deleted.

0 commit comments

Comments
 (0)