aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/CMakeLists.txt7
-rw-r--r--src/shared/help/bookmarkmanager.cpp2
-rw-r--r--src/shared/help/topicchooser.cpp17
-rw-r--r--src/shared/help/topicchooser.h1
-rw-r--r--src/shared/pch_files.qbs16
-rw-r--r--src/shared/proparser/proparser.qbs6
-rw-r--r--src/shared/proparser/qmakebuiltins.cpp44
-rw-r--r--src/shared/proparser/qmakeevaluator.h5
-rw-r--r--src/shared/proparser/qmakeglobals.cpp2
-rw-r--r--src/shared/qtlockedfile/CMakeLists.txt17
-rw-r--r--src/shared/qtlockedfile/README.txt10
-rw-r--r--src/shared/qtlockedfile/namespace.patch70
-rw-r--r--src/shared/qtlockedfile/qtlockedfile.cpp132
-rw-r--r--src/shared/qtlockedfile/qtlockedfile.h48
-rw-r--r--src/shared/qtlockedfile/qtlockedfile_unix.cpp82
-rw-r--r--src/shared/qtlockedfile/qtlockedfile_win.cpp170
-rw-r--r--src/shared/qtsingleapplication/CMakeLists.txt2
-rw-r--r--src/shared/qtsingleapplication/qtlocalpeer.cpp7
-rw-r--r--src/shared/qtsingleapplication/qtlocalpeer.h9
-rw-r--r--src/shared/qtsingleapplication/qtsingleapplication.cpp15
20 files changed, 80 insertions, 582 deletions
diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt
index 93409b0bf4..b945e8faa9 100644
--- a/src/shared/CMakeLists.txt
+++ b/src/shared/CMakeLists.txt
@@ -1,7 +1,6 @@
add_subdirectory(designerintegrationv2)
add_subdirectory(proparser)
add_subdirectory(qtsingleapplication)
-add_subdirectory(qtlockedfile)
add_subdirectory(help)
add_subdirectory(registryaccess)
@@ -19,7 +18,11 @@ if (BUILD_QBS)
set(QBS_LIB_INSTALL_DIR "${IDE_LIBRARY_PATH}" CACHE STRING "" FORCE)
set(QBS_DLL_INSTALL_DIR "${IDE_BIN_PATH}" CACHE STRING "" FORCE)
set(QBS_LIBEXEC_INSTALL_DIR "${IDE_LIBEXEC_PATH}" CACHE STRING "" FORCE)
- set(QBS_PLUGINS_INSTALL_BASE "${IDE_PLUGIN_PATH}" CACHE STRING "" FORCE)
+ if (APPLE)
+ set(QBS_PLUGINS_INSTALL_BASE "${IDE_PLUGIN_PATH}/../" CACHE STRING "" FORCE)
+ else()
+ set(QBS_PLUGINS_INSTALL_BASE "${_IDE_LIBRARY_BASE_PATH}/" CACHE STRING "" FORCE)
+ endif()
set(QBS_RESOURCES_INSTALL_BASE "${IDE_DATA_PATH}/qbs" CACHE STRING "" FORCE)
set(QBS_DOC_INSTALL_DIR "${IDE_DOC_PATH}" CACHE STRING "" FORCE)
set(QBS_HEADERS_INSTALL_DIR "${IDE_DATA_PATH}/qbs/include/qbs" CACHE STRING "" FORCE)
diff --git a/src/shared/help/bookmarkmanager.cpp b/src/shared/help/bookmarkmanager.cpp
index 72bd5db321..2f287f2d31 100644
--- a/src/shared/help/bookmarkmanager.cpp
+++ b/src/shared/help/bookmarkmanager.cpp
@@ -600,7 +600,7 @@ void BookmarkManager::saveBookmarks()
QDataStream stream(&bookmarks, QIODevice::WriteOnly);
readBookmarksRecursive(treeModel->invisibleRootItem(), stream, 0);
- Core::ICore::settings()->setValue(QLatin1String(kBookmarksKey), bookmarks);
+ Core::ICore::settings()->setValue(kBookmarksKey, bookmarks);
}
QStringList BookmarkManager::bookmarkFolders() const
diff --git a/src/shared/help/topicchooser.cpp b/src/shared/help/topicchooser.cpp
index 93a4bf47be..43d24cd136 100644
--- a/src/shared/help/topicchooser.cpp
+++ b/src/shared/help/topicchooser.cpp
@@ -9,6 +9,8 @@
#include <utils/layoutbuilder.h>
#include <utils/utilstr.h>
+#include <coreplugin/icore.h>
+
#include <QMap>
#include <QUrl>
@@ -18,12 +20,18 @@
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
+const int kInitialWidth = 400;
+const int kInitialHeight = 220;
+const char kPreferenceDialogSize[] = "Core/TopicChooserSize";
+
TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
const QMultiMap<QString, QUrl> &links)
: QDialog(parent)
, m_filterModel(new QSortFilterProxyModel(this))
{
- resize(400, 220);
+ const QSize initialSize(kInitialWidth, kInitialHeight);
+ resize(Core::ICore::settings()->value(kPreferenceDialogSize, initialSize).toSize());
+
setWindowTitle(::Help::Tr::tr("Choose Topic"));
QStandardItemModel *model = new QStandardItemModel(this);
@@ -70,6 +78,13 @@ TopicChooser::TopicChooser(QWidget *parent, const QString &keyword,
this, &TopicChooser::setFilter);
}
+TopicChooser::~TopicChooser()
+{
+ Core::ICore::settings()->setValueWithDefault(kPreferenceDialogSize,
+ size(),
+ QSize(kInitialWidth, kInitialHeight));
+}
+
QUrl TopicChooser::link() const
{
if (m_activedIndex.isValid())
diff --git a/src/shared/help/topicchooser.h b/src/shared/help/topicchooser.h
index 53954cad09..feca98c85f 100644
--- a/src/shared/help/topicchooser.h
+++ b/src/shared/help/topicchooser.h
@@ -24,6 +24,7 @@ class TopicChooser : public QDialog
public:
TopicChooser(QWidget *parent, const QString &keyword,
const QMultiMap<QString, QUrl> &links);
+ ~TopicChooser() override;
QUrl link() const;
diff --git a/src/shared/pch_files.qbs b/src/shared/pch_files.qbs
deleted file mode 100644
index 237f8456db..0000000000
--- a/src/shared/pch_files.qbs
+++ /dev/null
@@ -1,16 +0,0 @@
-import qbs
-import qbs.FileInfo
-
-Product {
- name: "precompiled headers"
- condition: qtc.make_dev_package
- Depends { name: "qtc" }
- Group {
- files: [
- "qtcreator_pch.h",
- "qtcreator_gui_pch.h",
- ]
- qbs.install: true
- qbs.installDir: qtc.ide_shared_sources_path
- }
-}
diff --git a/src/shared/proparser/proparser.qbs b/src/shared/proparser/proparser.qbs
index dd9ce7cc64..290ffdff5d 100644
--- a/src/shared/proparser/proparser.qbs
+++ b/src/shared/proparser/proparser.qbs
@@ -6,13 +6,13 @@ Product {
Export {
Depends { name: "cpp" }
- cpp.defines: base.concat([
+ cpp.defines: [
"QMAKE_AS_LIBRARY",
"PROPARSER_THREAD_SAFE",
"PROEVALUATOR_THREAD_SAFE",
"PROEVALUATOR_CUMULATIVE",
"PROEVALUATOR_SETENV",
- ])
- cpp.includePaths: base.concat([exportingProduct.sourceDirectory + "/.."])
+ ]
+ cpp.includePaths: exportingProduct.sourceDirectory + "/.."
}
}
diff --git a/src/shared/proparser/qmakebuiltins.cpp b/src/shared/proparser/qmakebuiltins.cpp
index 87707106e6..505b4cf989 100644
--- a/src/shared/proparser/qmakebuiltins.cpp
+++ b/src/shared/proparser/qmakebuiltins.cpp
@@ -441,6 +441,13 @@ QMAKE_EXPORT std::function<void(ProcessData *data)> &theProcessRunner()
return runner;
}
+QMAKE_EXPORT std::function<std::optional<QString>(const QString &, const QStringList &)>
+ &thePrompter()
+{
+ static std::function<std::optional<QString>(const QString &, const QStringList &)> prompter;
+ return prompter;
+}
+
void QMakeEvaluator::runProcessHelper(ProcessData *data) const
{
const QString root = deviceRoot();
@@ -1161,12 +1168,12 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
}
}
break;
-#ifdef PROEVALUATOR_FULL
+//#ifdef PROEVALUATOR_FULL
case E_PROMPT: {
if (args.count() != 1 && args.count() != 2) {
evalError(fL1S("prompt(question, [decorate=true]) requires one or two arguments."));
-// } else if (currentFileName() == QLatin1String("-")) {
-// evalError(fL1S("prompt(question) cannot be used when '-o -' is used"));
+ } else if (currentFileName() == QLatin1String("-")) {
+ evalError(fL1S("prompt(question) cannot be used when '-o -' is used"));
} else {
QString msg = m_option->expandEnvVars(args.at(0).toQString(m_tmp1));
bool decorate = true;
@@ -1179,20 +1186,32 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
} else {
fputs(qPrintable(msg), stderr);
}
- QFile qfile;
- if (qfile.open(stdin, QIODevice::ReadOnly)) {
- QTextStream t(&qfile);
- const QString &line = t.readLine();
- if (t.atEnd()) {
+
+ if (thePrompter()) {
+ std::optional<QString> line = thePrompter()(msg, m_logBuffer);
+ m_logBuffer.clear();
+ if (!line) {
fputs("\n", stderr);
evalError(fL1S("Unexpected EOF."));
return ReturnError;
}
- ret = split_value_list(QStringView(line));
- }
+ ret = split_value_list(QStringView(*line));
+ } else {
+ QFile qfile;
+ if (qfile.open(stdin, QIODevice::ReadOnly)) {
+ QTextStream t(&qfile);
+ const QString &line = t.readLine();
+ if (t.atEnd()) {
+ fputs("\n", stderr);
+ evalError(fL1S("Unexpected EOF."));
+ return ReturnError;
+ }
+ ret = split_value_list(QStringView(line));
+ }
+ }
}
break; }
-#endif
+//#endif
case E_REPLACE:
if (args.count() != 3 ) {
evalError(fL1S("replace(var, before, after) requires three arguments."));
@@ -1827,6 +1846,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
const QString &msg = m_option->expandEnvVars(args.at(0).toQString(m_tmp2));
if (!m_skipLevel) {
if (func_t == T_LOG) {
+ m_logBuffer.append(msg);
+ if (m_logBuffer.size() > 15)
+ m_logBuffer.takeFirst();
#ifdef PROEVALUATOR_FULL
fputs(msg.toLatin1().constData(), stderr);
#endif
diff --git a/src/shared/proparser/qmakeevaluator.h b/src/shared/proparser/qmakeevaluator.h
index da681b3bbe..a3d7438d82 100644
--- a/src/shared/proparser/qmakeevaluator.h
+++ b/src/shared/proparser/qmakeevaluator.h
@@ -48,6 +48,10 @@ public:
QT_BEGIN_NAMESPACE
QMAKE_EXPORT std::function<void(ProcessData *data)> &theProcessRunner();
+
+QMAKE_EXPORT std::function<std::optional<QString>(const QString &, const QStringList &)> &
+ thePrompter();
+
QMAKE_EXPORT QString removeHostAndScheme(const QString &remotePath);
class QMakeGlobals;
@@ -296,6 +300,7 @@ public:
QStringList m_qmakepath;
QStringList m_qmakefeatures;
QStringList m_mkspecPaths;
+ QStringList m_logBuffer;
QExplicitlySharedDataPointer<QMakeFeatureRoots> m_featureRoots;
ProString m_dirSep;
ProFunctionDefs m_functionDefs;
diff --git a/src/shared/proparser/qmakeglobals.cpp b/src/shared/proparser/qmakeglobals.cpp
index 03e0fd6055..7fa8915920 100644
--- a/src/shared/proparser/qmakeglobals.cpp
+++ b/src/shared/proparser/qmakeglobals.cpp
@@ -79,7 +79,7 @@ QString QMakeGlobals::cleanSpec(QMakeCmdLineParserState &state, const QString &s
QString ret = QDir::cleanPath(spec);
if (ret.contains(QLatin1Char('/'))) {
QString absRet = IoUtils::resolvePath(device_root, state.pwd, ret);
- if (QFile::exists(absRet))
+ if (QFileInfo::exists(absRet))
ret = absRet;
}
return ret;
diff --git a/src/shared/qtlockedfile/CMakeLists.txt b/src/shared/qtlockedfile/CMakeLists.txt
deleted file mode 100644
index f7f8a1c666..0000000000
--- a/src/shared/qtlockedfile/CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-if (WIN32)
- set(OS_SOURCES qtlockedfile_win.cpp)
-else()
- set(OS_SOURCES qtlockedfile_unix.cpp)
-endif()
-
-add_library(shared_qtlockedfile STATIC ${OS_SOURCES} qtlockedfile.cpp qtlockedfile.h)
-target_link_libraries(shared_qtlockedfile Qt::Core)
-target_include_directories(shared_qtlockedfile PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-if (WIN32)
- target_compile_definitions(shared_qtlockedfile PRIVATE
- "QT_QTLOCKEDFILE_EXPORT=__declspec(dllexport)" _UNICODE UNICODE)
-endif()
-
-if (WITH_SANITIZE)
- qtc_enable_sanitize(shared_qtlockedfile ${SANITIZE_FLAGS})
-endif()
diff --git a/src/shared/qtlockedfile/README.txt b/src/shared/qtlockedfile/README.txt
deleted file mode 100644
index 6fcf2fd295..0000000000
--- a/src/shared/qtlockedfile/README.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-This is the src directory of the QtLockedFile
-solution integrated over from addons/main/utils/qtlockedfile/src .
-
-namespace.patch was applied to introduce the SharedTools namespace.
-
-It is required by the QtSingleApplication solution.
-
-History:
-
-16.05.2008 Integrated
diff --git a/src/shared/qtlockedfile/namespace.patch b/src/shared/qtlockedfile/namespace.patch
deleted file mode 100644
index 301cae8cff..0000000000
--- a/src/shared/qtlockedfile/namespace.patch
+++ /dev/null
@@ -1,70 +0,0 @@
-
---- qtlockedfile.cpp 1970-01-01 01:00:00.000000000
-+++ qtlockedfile.cpp 2008/05/16 10:51:19.000000000
-@@ -1,5 +1,7 @@
- #include "qtlockedfile.h"
-
-+namespace SharedTools {
-+
- /*!
- \class QtLockedFile
-
-@@ -123,3 +125,5 @@
-
- Destroys the \e QtLockedFile object. If any locks were held, they are released.
- */
-+
-+}
-
---- qtlockedfile.h 1970-01-01 01:00:00.000000000
-+++ qtlockedfile.h 2008/05/16 10:51:19.000000000
-@@ -19,6 +19,8 @@
- # define QT_QTLOCKEDFILE_EXPORT
- #endif
-
-+namespace SharedTools {
-+
- class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
- {
- public:
-@@ -41,4 +43,6 @@
- LockMode m_lock_mode;
- };
-
-+}
-+
- #endif
-
---- qtlockedfile_unix.cpp 1970-01-01 01:00:00.000000000
-+++ qtlockedfile_unix.cpp 2008/05/16 10:51:19.000000000
-@@ -5,6 +5,8 @@
-
- #include "qtlockedfile.h"
-
-+namespace SharedTools {
-+
- bool QtLockedFile::lock(LockMode mode, bool block)
- {
- if (!isOpen()) {
-@@ -73,3 +75,4 @@
- unlock();
- }
-
-+}
-
---- qtlockedfile_win.cpp 1970-01-01 01:00:00.000000000
-+++ qtlockedfile_win.cpp 2008/05/16 10:51:19.000000000
-@@ -2,6 +2,8 @@
- #include <qt_windows.h>
- #include <QtCore/QFileInfo>
-
-+namespace SharedTools {
-+
- #define SEMAPHORE_PREFIX "QtLockedFile semaphore "
- #define MUTEX_PREFIX "QtLockedFile mutex "
- #define SEMAPHORE_MAX 100
-@@ -168,3 +170,4 @@
- }
- }
-
-+}
diff --git a/src/shared/qtlockedfile/qtlockedfile.cpp b/src/shared/qtlockedfile/qtlockedfile.cpp
deleted file mode 100644
index a14c7e14b0..0000000000
--- a/src/shared/qtlockedfile/qtlockedfile.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "qtlockedfile.h"
-
-namespace SharedTools {
-
-/*!
- \class QtLockedFile
-
- \brief The QtLockedFile class extends QFile with advisory locking functions.
-
- A file may be locked in read or write mode. Multiple instances of
- \e QtLockedFile, created in multiple processes running on the same
- machine, may have a file locked in read mode. Exactly one instance
- may have it locked in write mode. A read and a write lock cannot
- exist simultaneously on the same file.
-
- The file locks are advisory. This means that nothing prevents
- another process from manipulating a locked file using QFile or
- file system functions offered by the OS. Serialization is only
- guaranteed if all processes that access the file use
- QtLockedFile. Also, while holding a lock on a file, a process
- must not open the same file again (through any API), or locks
- can be unexpectedly lost.
-
- The lock provided by an instance of \e QtLockedFile is released
- whenever the program terminates. This is true even when the
- program crashes and no destructors are called.
-*/
-
-/*! \enum QtLockedFile::LockMode
-
- This enum describes the available lock modes.
-
- \value ReadLock A read lock.
- \value WriteLock A write lock.
- \value NoLock Neither a read lock nor a write lock.
-*/
-
-/*!
- Constructs an unlocked \e QtLockedFile object. This constructor behaves in the same way
- as \e QFile::QFile().
-
- \sa QFile::QFile()
-*/
-QtLockedFile::QtLockedFile()
- : QFile()
-{
-#ifdef Q_OS_WIN
- m_semaphore_hnd = 0;
- m_mutex_hnd = 0;
-#endif
- m_lock_mode = NoLock;
-}
-
-/*!
- Constructs an unlocked QtLockedFile object with file \a name. This constructor behaves in
- the same way as \e QFile::QFile(const QString&).
-
- \sa QFile::QFile()
-*/
-QtLockedFile::QtLockedFile(const QString &name)
- : QFile(name)
-{
-#ifdef Q_OS_WIN
- m_semaphore_hnd = 0;
- m_mutex_hnd = 0;
-#endif
- m_lock_mode = NoLock;
-}
-
-/*!
- Returns \e true if this object has a in read or write lock;
- otherwise returns \e false.
-
- \sa lockMode()
-*/
-bool QtLockedFile::isLocked() const
-{
- return m_lock_mode != NoLock;
-}
-
-/*!
- Returns the type of lock currently held by this object, or \e QtLockedFile::NoLock.
-
- \sa isLocked()
-*/
-QtLockedFile::LockMode QtLockedFile::lockMode() const
-{
- return m_lock_mode;
-}
-
-/*!
- \fn bool QtLockedFile::lock(LockMode mode, bool block = true)
-
- Obtains a lock of type \a mode.
-
- If \a block is true, this
- function will block until the lock is acquired. If \a block is
- false, this function returns \e false immediately if the lock cannot
- be acquired.
-
- If this object already has a lock of type \a mode, this function returns \e true immediately. If this object has a lock of a different type than \a mode, the lock
- is first released and then a new lock is obtained.
-
- This function returns \e true if, after it executes, the file is locked by this object,
- and \e false otherwise.
-
- \sa unlock(), isLocked(), lockMode()
-*/
-
-/*!
- \fn bool QtLockedFile::unlock()
-
- Releases a lock.
-
- If the object has no lock, this function returns immediately.
-
- This function returns \e true if, after it executes, the file is not locked by
- this object, and \e false otherwise.
-
- \sa lock(), isLocked(), lockMode()
-*/
-
-/*!
- \fn QtLockedFile::~QtLockedFile()
-
- Destroys the \e QtLockedFile object. If any locks were held, they are released.
-*/
-
-} // namespace SharedTools
diff --git a/src/shared/qtlockedfile/qtlockedfile.h b/src/shared/qtlockedfile/qtlockedfile.h
deleted file mode 100644
index d4aa9a59c0..0000000000
--- a/src/shared/qtlockedfile/qtlockedfile.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#pragma once
-
-#include <QFile>
-
-#if defined(Q_OS_WIN)
-# if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT)
-# define QT_QTLOCKEDFILE_EXPORT
-# elif defined(QT_QTLOCKEDFILE_IMPORT)
-# if defined(QT_QTLOCKEDFILE_EXPORT)
-# undef QT_QTLOCKEDFILE_EXPORT
-# endif
-# define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport)
-# elif defined(QT_QTLOCKEDFILE_EXPORT)
-# undef QT_QTLOCKEDFILE_EXPORT
-# define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport)
-# endif
-#else
-# define QT_QTLOCKEDFILE_EXPORT
-#endif
-
-namespace SharedTools {
-
-class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
-{
-public:
- enum LockMode { NoLock = 0, ReadLock, WriteLock };
-
- QtLockedFile();
- QtLockedFile(const QString &name);
- ~QtLockedFile();
-
- bool lock(LockMode mode, bool block = true);
- bool unlock();
- bool isLocked() const;
- LockMode lockMode() const;
-
-private:
-#ifdef Q_OS_WIN
- Qt::HANDLE m_semaphore_hnd;
- Qt::HANDLE m_mutex_hnd;
-#endif
- LockMode m_lock_mode;
-};
-
-} // namespace SharedTools
diff --git a/src/shared/qtlockedfile/qtlockedfile_unix.cpp b/src/shared/qtlockedfile/qtlockedfile_unix.cpp
deleted file mode 100644
index e189f31472..0000000000
--- a/src/shared/qtlockedfile/qtlockedfile_unix.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "qtlockedfile.h"
-
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-namespace SharedTools {
-
-bool QtLockedFile::lock(LockMode mode, bool block)
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::lock(): file is not opened");
- return false;
- }
-
- if (mode == NoLock)
- return unlock();
-
- if (mode == m_lock_mode)
- return true;
-
- if (m_lock_mode != NoLock)
- unlock();
-
- struct flock fl;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
- fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK;
- int cmd = block ? F_SETLKW : F_SETLK;
- int ret = fcntl(handle(), cmd, &fl);
-
- if (ret == -1) {
- if (errno != EINTR && errno != EAGAIN)
- qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
- return false;
- }
-
-
- m_lock_mode = mode;
- return true;
-}
-
-
-bool QtLockedFile::unlock()
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::unlock(): file is not opened");
- return false;
- }
-
- if (!isLocked())
- return true;
-
- struct flock fl;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
- fl.l_type = F_UNLCK;
- int ret = fcntl(handle(), F_SETLKW, &fl);
-
- if (ret == -1) {
- qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno));
- return false;
- }
-
- m_lock_mode = NoLock;
- remove();
- return true;
-}
-
-QtLockedFile::~QtLockedFile()
-{
- if (isOpen())
- unlock();
-}
-
-} // namespace SharedTools
diff --git a/src/shared/qtlockedfile/qtlockedfile_win.cpp b/src/shared/qtlockedfile/qtlockedfile_win.cpp
deleted file mode 100644
index 2f35635b55..0000000000
--- a/src/shared/qtlockedfile/qtlockedfile_win.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "qtlockedfile.h"
-
-#include <qt_windows.h>
-#include <QFileInfo>
-
-namespace SharedTools {
-
-#define SEMAPHORE_PREFIX "QtLockedFile semaphore "
-#define MUTEX_PREFIX "QtLockedFile mutex "
-#define SEMAPHORE_MAX 100
-
-static QString errorCodeToString(DWORD errorCode)
-{
- QString result;
- char *data = 0;
- FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- 0, errorCode, 0,
- (char*)&data, 0, 0);
- result = QString::fromLocal8Bit(data);
- if (data != 0)
- LocalFree(data);
-
- if (result.endsWith(QLatin1Char('\n')))
- result.truncate(result.length() - 1);
-
- return result;
-}
-
-bool QtLockedFile::lock(LockMode mode, bool block)
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::lock(): file is not opened");
- return false;
- }
-
- if (mode == m_lock_mode)
- return true;
-
- if (m_lock_mode != 0)
- unlock();
-
- if (m_semaphore_hnd == 0) {
- QFileInfo fi(*this);
- QString sem_name = QString::fromLatin1(SEMAPHORE_PREFIX)
- + fi.absoluteFilePath().toLower();
-
- m_semaphore_hnd = CreateSemaphoreW(0, SEMAPHORE_MAX, SEMAPHORE_MAX,
- (TCHAR*)sem_name.utf16());
-
- if (m_semaphore_hnd == 0) {
- qWarning("QtLockedFile::lock(): CreateSemaphore: %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- return false;
- }
- }
-
- bool gotMutex = false;
- int decrement;
- if (mode == ReadLock) {
- decrement = 1;
- } else {
- decrement = SEMAPHORE_MAX;
- if (m_mutex_hnd == 0) {
- QFileInfo fi(*this);
- QString mut_name = QString::fromLatin1(MUTEX_PREFIX)
- + fi.absoluteFilePath().toLower();
-
- m_mutex_hnd = CreateMutexW(NULL, FALSE, (TCHAR*)mut_name.utf16());
-
- if (m_mutex_hnd == 0) {
- qWarning("QtLockedFile::lock(): CreateMutex: %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- return false;
- }
- }
- DWORD res = WaitForSingleObject(m_mutex_hnd, block ? INFINITE : 0);
- if (res == WAIT_TIMEOUT)
- return false;
- if (res == WAIT_FAILED) {
- qWarning("QtLockedFile::lock(): WaitForSingleObject (mutex): %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- return false;
- }
- gotMutex = true;
- }
-
- for (int i = 0; i < decrement; ++i) {
- DWORD res = WaitForSingleObject(m_semaphore_hnd, block ? INFINITE : 0);
- if (res == WAIT_TIMEOUT) {
- if (i) {
- // A failed nonblocking rw locking. Undo changes to semaphore.
- if (ReleaseSemaphore(m_semaphore_hnd, i, NULL) == 0) {
- qWarning("QtLockedFile::unlock(): ReleaseSemaphore: %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- // Fall through
- }
- }
- if (gotMutex)
- ReleaseMutex(m_mutex_hnd);
- return false;
- }
- if (res != WAIT_OBJECT_0) {
- if (gotMutex)
- ReleaseMutex(m_mutex_hnd);
- qWarning("QtLockedFile::lock(): WaitForSingleObject (semaphore): %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- return false;
- }
- }
-
- m_lock_mode = mode;
- if (gotMutex)
- ReleaseMutex(m_mutex_hnd);
- return true;
-}
-
-bool QtLockedFile::unlock()
-{
- if (!isOpen()) {
- qWarning("QtLockedFile::unlock(): file is not opened");
- return false;
- }
-
- if (!isLocked())
- return true;
-
- int increment;
- if (m_lock_mode == ReadLock)
- increment = 1;
- else
- increment = SEMAPHORE_MAX;
-
- DWORD ret = ReleaseSemaphore(m_semaphore_hnd, increment, 0);
- if (ret == 0) {
- qWarning("QtLockedFile::unlock(): ReleaseSemaphore: %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- return false;
- }
-
- m_lock_mode = QtLockedFile::NoLock;
- remove();
- return true;
-}
-
-QtLockedFile::~QtLockedFile()
-{
- if (isOpen())
- unlock();
- if (m_mutex_hnd != 0) {
- DWORD ret = CloseHandle(m_mutex_hnd);
- if (ret == 0) {
- qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (mutex): %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- }
- m_mutex_hnd = 0;
- }
- if (m_semaphore_hnd != 0) {
- DWORD ret = CloseHandle(m_semaphore_hnd);
- if (ret == 0) {
- qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (semaphore): %s",
- errorCodeToString(GetLastError()).toLatin1().constData());
- }
- m_semaphore_hnd = 0;
- }
-}
-
-} // namespace SharedTools
diff --git a/src/shared/qtsingleapplication/CMakeLists.txt b/src/shared/qtsingleapplication/CMakeLists.txt
index fae6a08545..5b8e9c0271 100644
--- a/src/shared/qtsingleapplication/CMakeLists.txt
+++ b/src/shared/qtsingleapplication/CMakeLists.txt
@@ -2,7 +2,7 @@ add_library(shared_qtsingleapplication STATIC
qtsingleapplication.cpp qtsingleapplication.h
qtlocalpeer.cpp qtlocalpeer.h
)
-target_link_libraries(shared_qtsingleapplication shared_qtlockedfile Qt::Core Qt::Network Qt::Widgets)
+target_link_libraries(shared_qtsingleapplication Qt::Core Qt::Network Qt::Widgets)
target_include_directories(shared_qtsingleapplication PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
if (WIN32)
target_compile_definitions(shared_qtsingleapplication PRIVATE "QT_QTSINGLEAPPLICATION_EXPORT=__declspec(dllexport)")
diff --git a/src/shared/qtsingleapplication/qtlocalpeer.cpp b/src/shared/qtsingleapplication/qtlocalpeer.cpp
index af72ece772..47dd3805ba 100644
--- a/src/shared/qtsingleapplication/qtlocalpeer.cpp
+++ b/src/shared/qtsingleapplication/qtlocalpeer.cpp
@@ -59,16 +59,15 @@ 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(QtLockedFile::WriteLock, false))
+ if (!lockFile->tryLock())
return true;
if (!QLocalServer::removeServer(socketName))
diff --git a/src/shared/qtsingleapplication/qtlocalpeer.h b/src/shared/qtsingleapplication/qtlocalpeer.h
index 67a0d42e2c..27578a7aca 100644
--- a/src/shared/qtsingleapplication/qtlocalpeer.h
+++ b/src/shared/qtsingleapplication/qtlocalpeer.h
@@ -3,11 +3,12 @@
#pragma once
-#include <qtlockedfile.h>
+#include <QDir>
#include <QLocalServer>
#include <QLocalSocket>
-#include <QDir>
+#include <QLockFile>
+#include <QScopedPointer>
namespace SharedTools {
@@ -31,8 +32,8 @@ protected:
QString id;
QString socketName;
- QLocalServer* server;
- QtLockedFile lockFile;
+ QLocalServer* server{nullptr};
+ QScopedPointer<QLockFile> lockFile;
};
} // namespace SharedTools
diff --git a/src/shared/qtsingleapplication/qtsingleapplication.cpp b/src/shared/qtsingleapplication/qtsingleapplication.cpp
index 0f8fa8b6d1..b791d1875f 100644
--- a/src/shared/qtsingleapplication/qtsingleapplication.cpp
+++ b/src/shared/qtsingleapplication/qtsingleapplication.cpp
@@ -4,10 +4,9 @@
#include "qtsingleapplication.h"
#include "qtlocalpeer.h"
-#include <qtlockedfile.h>
-
#include <QDir>
#include <QFileOpenEvent>
+#include <QLockFile>
#include <QSharedMemory>
#include <QWidget>
@@ -50,11 +49,10 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char *
}
}
- // QtLockedFile is used to workaround QTBUG-10364
- QtLockedFile lockfile(instancesLockFilename(appSessionId));
+ // QLockFile is used to workaround QTBUG-10364
+ QLockFile lockfile(instancesLockFilename(appSessionId));
- lockfile.open(QtLockedFile::ReadWrite);
- lockfile.lock(QtLockedFile::WriteLock);
+ lockfile.lock();
qint64 *pids = static_cast<qint64 *>(instances->data());
if (!created) {
// Find the first instance that it still running
@@ -79,9 +77,8 @@ QtSingleApplication::~QtSingleApplication()
if (!instances)
return;
const qint64 appPid = QCoreApplication::applicationPid();
- QtLockedFile lockfile(instancesLockFilename(QtLocalPeer::appSessionId(appId)));
- lockfile.open(QtLockedFile::ReadWrite);
- lockfile.lock(QtLockedFile::WriteLock);
+ QLockFile lockfile(instancesLockFilename(QtLocalPeer::appSessionId(appId)));
+ lockfile.lock();
// Rewrite array, removing current pid and previously crashed ones
qint64 *pids = static_cast<qint64 *>(instances->data());
qint64 *newpids = pids;