Skip to content

Commit

Permalink
QtSingleApplication: Replaced QtLockedFile with QLockFile (#4170)
Browse files Browse the repository at this point in the history
This also drops support for Qt 4 in this part of the code, since
QLockFile was introduced in Qt 5.1. But it was already requiring Qt 5.4
due to use of qUtf8Printable anyway.

The same change was done for Qt Creator here:
https://codereview.qt-project.org/c/qt-creator/qt-creator/+/499187
  • Loading branch information
bjorn authored Feb 7, 2025
1 parent 47285d8 commit 4ee592f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 727 deletions.
1 change: 0 additions & 1 deletion src/qtsingleapplication/src/QtLockedFile

This file was deleted.

23 changes: 6 additions & 17 deletions src/qtsingleapplication/src/qtlocalpeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
#include "qtlocalpeer.h"
#include <QCoreApplication>
#include <QDataStream>
#include <QDir>
#include <QLocalSocket>
#include <QRegularExpression>
#include <QTime>

#if defined(Q_OS_WIN)
#include <QLibrary>
Expand All @@ -64,15 +65,6 @@ static PProcessIdToSessionId pProcessIdToSessionId = 0;
#include <unistd.h>
#endif

namespace QtLP_Private {
#include "qtlockedfile.cpp"
#if defined(Q_OS_WIN)
#include "qtlockedfile_win.cpp"
#else
#include "qtlockedfile_unix.cpp"
#endif
}

const char* QtLocalPeer::ack = "ack";

QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
Expand Down Expand Up @@ -116,22 +108,19 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
QString lockName = QDir(QDir::tempPath()).absolutePath()
+ QLatin1Char('/') + socketName
+ QLatin1String("-lockfile");
lockFile.setFileName(lockName);
lockFile.open(QIODevice::ReadWrite);
lockFile.reset(new QLockFile(lockName));
}



bool QtLocalPeer::isClient()
{
if (lockFile.isLocked())
if (lockFile->isLocked())
return false;

if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false))
if (!lockFile->tryLock())
return true;

bool res = server->listen(socketName);
#if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0))
#if defined(Q_OS_UNIX)
// ### Workaround
if (!res && server->serverError() == QAbstractSocket::AddressInUseError) {
QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName);
Expand Down
11 changes: 4 additions & 7 deletions src/qtsingleapplication/src/qtlocalpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
#define QTLOCALPEER_H

#include <QLocalServer>
#include <QLocalSocket>
#include <QDir>

#include "qtlockedfile.h"
#include <QLockFile>
#include <QScopedPointer>

class QtLocalPeer : public QObject
{
Expand All @@ -55,8 +53,7 @@ class QtLocalPeer : public QObject
QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
bool isClient();
bool sendMessage(const QString &message, int timeout);
QString applicationId() const
{ return id; }
QString applicationId() const { return id; }

Q_SIGNALS:
void messageReceived(const QString &message);
Expand All @@ -68,7 +65,7 @@ protected Q_SLOTS:
QString id;
QString socketName;
QLocalServer* server;
QtLP_Private::QtLockedFile lockFile;
QScopedPointer<QLockFile> lockFile;

private:
static const char* ack;
Expand Down
193 changes: 0 additions & 193 deletions src/qtsingleapplication/src/qtlockedfile.cpp

This file was deleted.

97 changes: 0 additions & 97 deletions src/qtsingleapplication/src/qtlockedfile.h

This file was deleted.

Loading

0 comments on commit 4ee592f

Please sign in to comment.