
From 5d39eaa4c2578632be296d2cebbc4b830c77ccff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Mon, 11 Feb 2019 15:53:49 +1000
Subject: Make sure libs are searched in the develop/ dir by CMake

Static libs at least are not in the lib[/x86] dirs...

diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf
index 24ed125..52f637e 100644
--- a/mkspecs/features/create_cmake.prf
+++ b/mkspecs/features/create_cmake.prf
@@ -112,6 +112,9 @@ win32:!static:!staticlib {
         CMAKE_DLL_DIR = $$[QT_INSTALL_BINS]/
         CMAKE_DLL_DIR_IS_ABSOLUTE = True
     }
+} else:haiku {
+    CMAKE_DLL_DIR = develop/$$CMAKE_LIB_DIR
+    CMAKE_DLL_DIR_IS_ABSOLUTE = $$CMAKE_LIB_DIR_IS_ABSOLUTE
 } else {
     CMAKE_DLL_DIR = $$CMAKE_LIB_DIR
     CMAKE_DLL_DIR_IS_ABSOLUTE = $$CMAKE_LIB_DIR_IS_ABSOLUTE
-- 
2.28.0


From 3f3429604a1a48e23444cda1861526351da2bc10 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 11 Feb 2019 15:55:08 +1000
Subject: Disable built-in haiku QPA plugin


diff --git a/src/plugins/platforms/platforms.pro b/src/plugins/platforms/platforms.pro
index 23f838a..8ef1812 100644
--- a/src/plugins/platforms/platforms.pro
+++ b/src/plugins/platforms/platforms.pro
@@ -42,10 +42,6 @@ freebsd {
     SUBDIRS += bsdfb
 }
 
-haiku {
-    SUBDIRS += haiku
-}
-
 wasm: SUBDIRS += wasm
 
 qtConfig(integrityfb): SUBDIRS += integrity
-- 
2.28.0

From 437c03637773374d1b084752c81860b7e3bbc766 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 11 Feb 2019 15:56:12 +1000
Subject: Fix QStandartPaths for Haiku


diff --git a/src/corelib/io/qstandardpaths_haiku.cpp b/src/corelib/io/qstandardpaths_haiku.cpp
index 044d69f..1f255a9 100644
--- a/src/corelib/io/qstandardpaths_haiku.cpp
+++ b/src/corelib/io/qstandardpaths_haiku.cpp
@@ -145,22 +145,22 @@ QString QStandardPaths::writableLocation(StandardLocation type)
         return haikuStandardPath(B_USER_NONPACKAGED_BIN_DIRECTORY);
     case TempLocation:
         return haikuStandardPath(B_SYSTEM_TEMP_DIRECTORY);
-    case AppDataLocation: // fall through
+    case AppDataLocation:
+    	return haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY);
     case AppLocalDataLocation:
-        return haikuAppStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
+        return haikuAppStandardPath(B_USER_CACHE_DIRECTORY);
     case GenericDataLocation:
-        return haikuStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY);
+        return haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY);
     case CacheLocation:
         return haikuAppStandardPath(B_USER_CACHE_DIRECTORY);
     case GenericCacheLocation:
-        return haikuStandardPath(B_USER_CACHE_DIRECTORY);
-    case ConfigLocation: // fall through
+        return haikuStandardPath(B_SYSTEM_CACHE_DIRECTORY);
+    case ConfigLocation:
     case AppConfigLocation:
-        return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
     case GenericConfigLocation:
-        return haikuStandardPath(B_USER_SETTINGS_DIRECTORY);
+        return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
     default:
-        return QString();
+        return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
     }
 }
 
@@ -179,7 +179,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
     case MoviesLocation:
     case DownloadLocation:
     case HomeLocation:
-        paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY);
+        paths += haikuStandardPath(B_USER_DIRECTORY);
         break;
     case FontsLocation:
         paths += haikuStandardPaths(B_FIND_PATH_FONTS_DIRECTORY);
@@ -203,7 +203,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
         break;
     case ConfigLocation: // fall through
     case AppConfigLocation:
-        paths += haikuAppStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
+        paths += haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY);
         break;
     case GenericConfigLocation:
         paths += haikuStandardPath(B_SYSTEM_SETTINGS_DIRECTORY);
-- 
2.28.0


From 682592ede1decdfc17128e7d4e3837d3334fd89a Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 11 Feb 2019 15:56:39 +1000
Subject: QSslSocketPrivate::unixRootCertDirectories(): add ssl path for Haiku.


diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index fbeb9de..02cc653 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -2958,6 +2958,7 @@ QList<QByteArray> QSslSocketPrivate::unixRootCertDirectories()
                                << "/usr/local/ssl/certs/" // Solaris
                                << "/etc/openssl/certs/" // BlackBerry
                                << "/opt/openssl/certs/" // HP-UX
+                               << "/system/data/ssl/" // Haiku
                                << "/etc/ssl/"; // OpenBSD
 }
 
-- 
2.28.0


From e19569f03ff18d11e985db17df76ae542b4f82d2 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 11 Feb 2019 15:56:59 +1000
Subject: Fix build for Haiku platform


diff --git a/mkspecs/features/toolchain.prf b/mkspecs/features/toolchain.prf
index 9d790f6..55d156c 100644
--- a/mkspecs/features/toolchain.prf
+++ b/mkspecs/features/toolchain.prf
@@ -254,7 +254,7 @@ isEmpty($${target_prefix}.INCDIRS) {
                 }
             }
         }
-        if(!darwin:clang)|intel_icc {
+        if(!darwin:clang)|haiku|intel_icc {
             # Clang on a non-Apple system (that is, a system without ld64 -- say, with GNU ld
             # or gold under Linux) will not print any library search path. Need to use another
             # invocation with different options (which in turn doesn't print include search
-- 
2.28.0


From f54915880945d5dcd7e79a85adb4d483c3f2c5e9 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 11 Feb 2019 15:57:54 +1000
Subject: Fix endian detection


diff --git a/src/3rdparty/sha3/brg_endian.h b/src/3rdparty/sha3/brg_endian.h
index 9bb306e..9f0ea58 100644
--- a/src/3rdparty/sha3/brg_endian.h
+++ b/src/3rdparty/sha3/brg_endian.h
@@ -39,10 +39,10 @@ Changes for ARM 9/9/2010 [Downstream relative to Gladman's GitHub, upstream to Q
 #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
       defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
 #  include <machine/endian.h>
-#elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
+#elif defined( __linux__ ) || defined( __HAIKU__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
 #  if !defined( __MINGW32__ ) && !defined( _AIX ) && !defined(Q_OS_QNX)
 #    include <endian.h>
-#    if !defined( __BEOS__ ) && !defined(Q_OS_RTEMS)
+#    if !defined( __BEOS__ ) && !defined( __HAIKU__ ) && !defined(Q_OS_RTEMS)
 #      include <byteswap.h>
 #    endif
 #  endif
-- 
2.28.0


From 4c650b583fea535c61bf2f71f44f6ef7582032b8 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 27 Apr 2019 17:47:23 +1000
Subject: Add dnslookup query function for Haiku


diff --git a/src/network/kernel/kernel.pri b/src/network/kernel/kernel.pri
index 7282e20..d2faef3 100644
--- a/src/network/kernel/kernel.pri
+++ b/src/network/kernel/kernel.pri
@@ -54,6 +54,11 @@ android:qtConfig(dnslookup) {
     SOURCES += kernel/qdnslookup_android.cpp
 }
 
+haiku:qtConfig(dnslookup) {
+    SOURCES -= kernel/qdnslookup_unix.cpp
+    SOURCES += kernel/qdnslookup_haiku.cpp
+}
+
 win32: {
     SOURCES += kernel/qhostinfo_win.cpp
 
diff --git a/src/network/kernel/qdnslookup_haiku.cpp b/src/network/kernel/qdnslookup_haiku.cpp
new file mode 100644
index 0000000..0b387df
--- /dev/null
+++ b/src/network/kernel/qdnslookup_haiku.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Gerasim Troeglazov <3dEyes@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdnslookup_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)
+{
+    Q_UNUSED(requestType);
+    Q_UNUSED(requestName);
+    Q_UNUSED(nameserver);
+    Q_UNUSED(reply);
+    qWarning("Not yet supported on Haiku");
+    reply->error = QDnsLookup::ResolverError;
+    reply->errorString = tr("Not yet supported on Haiku");
+    return;
+}
+
+QT_END_NAMESPACE
-- 
2.28.0


From b378401733f24ec8666c2d88c6985d47341f88f5 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 27 May 2020 19:54:30 +1000
Subject: Disable LibResolv for Haiku


diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 9b0a2ee..480671b 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -87,7 +87,7 @@ typedef void (*res_nclose_proto)(res_state_ptr);
 static res_nclose_proto local_res_nclose = nullptr;
 static res_state_ptr local_res = nullptr;
 
-#if QT_CONFIG(library) && !defined(Q_OS_QNX)
+#if QT_CONFIG(library) && !defined(Q_OS_QNX) && !defined(Q_OS_HAIKU)
 namespace {
 struct LibResolv
 {
-- 
2.28.0


From 3c308f71240c494fe3f3131614d1ec71b8ba1d13 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 8 Sep 2019 00:17:19 +1000
Subject: Don't use ifaddrs for Haiku


diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp
index 4c57bff..0c8e38f 100644
--- a/src/network/kernel/qnetworkinterface_unix.cpp
+++ b/src/network/kernel/qnetworkinterface_unix.cpp
@@ -51,7 +51,7 @@
 #  include "qdatetime.h"
 #endif
 
-#if defined(QT_LINUXBASE)
+#if defined(QT_LINUXBASE) || defined(Q_OS_HAIKU)
 #  define QT_NO_GETIFADDRS
 #endif
 
-- 
2.28.0


From 09d34cea1ca67bb36367710d0d2dcabeb30a4f10 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 8 Sep 2019 18:32:05 +1000
Subject: Add platform plugins installer


diff --git a/src/gui/gui.pro b/src/gui/gui.pro
index 20372d9..803e9b7 100644
--- a/src/gui/gui.pro
+++ b/src/gui/gui.pro
@@ -35,6 +35,7 @@ testcocoon {
 
 osx: LIBS_PRIVATE += -framework AppKit
 darwin: LIBS_PRIVATE += -framework CoreGraphics
+haiku: LIBS_PRIVATE += -lbe
 
 CONFIG += simd optimize_full
 
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 239a783..8bdb7f6 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -116,6 +116,11 @@
 #  include <QtCore/QLibraryInfo>
 #endif // Q_OS_WIN
 
+#if defined(Q_OS_HAIKU)
+#include <Application.h>
+#include <Alert.h>
+#endif
+
 #ifdef Q_OS_WASM
 #include <emscripten.h>
 #endif
@@ -1245,6 +1250,27 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
         if (!availablePlugins.isEmpty())
             fatalMessage += QStringLiteral("\nAvailable platform plugins are: %1.\n").arg(availablePlugins.join(QLatin1String(", ")));
 
+#if defined(Q_OS_HAIKU)
+		BApplication bApp("application/x-vnd.qt5-qtbase");
+		QString errorMessage = QStringLiteral("Qt platform plugins package is required but not installed.\n\n"
+			"Do you want to install it now?");
+		int32 index = (new BAlert("Error", errorMessage.toUtf8().constData(),
+			"Install", "Cancel", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
+		if (index == 0) {
+#if defined(__INTEL__) && defined(__i386__) && !defined(__x86_64__)
+			int ret = system ("pkgman install qthaikuplugins_x86 -y");
+#else
+			int ret = system ("pkgman install qthaikuplugins -y");
+#endif
+			if (ret == 0)
+				(new BAlert("Information", "Platform plugins has been succesfully installed.\nTry running this application again.",
+					"Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT))->Go();
+			else
+				(new BAlert("Error", "Platform plugins is not installed.", "Close", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
+		}
+		exit(-1);
+#endif // Q_OS_HAIKU
+
 #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
         // Windows: Display message box unless it is a console application
         // or debug build showing an assert box.
-- 
2.28.0



From 61e1c632163e47eb6fe825084ba459b55010c687 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 27 May 2020 19:54:58 +1000
Subject: Disable sharedmemory feature for bootstrap


diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro
index c212ccb..1a31b62 100644
--- a/src/tools/bootstrap/bootstrap.pro
+++ b/src/tools/bootstrap/bootstrap.pro
@@ -11,7 +11,8 @@ MODULE_DEFINES = \
         QT_VERSION_MINOR=$$QT_MINOR_VERSION \
         QT_VERSION_PATCH=$$QT_PATCH_VERSION \
         QT_BOOTSTRAPPED \
-        QT_NO_CAST_TO_ASCII
+        QT_NO_CAST_TO_ASCII \
+        QT_NO_SHAREDMEMORY
 MODULE_CONFIG = gc_binaries
 
 DEFINES += \
-- 
2.28.0


From 05f9feef7a57b1dd03b62c0e9190fecd63603a49 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 29 Dec 2019 18:13:19 +1000
Subject: Fix build for x86_gcc2


diff --git a/src/3rdparty/forkfd/forkfd.c b/src/3rdparty/forkfd/forkfd.c
index b663b8a..5ad2b12 100644
--- a/src/3rdparty/forkfd/forkfd.c
+++ b/src/3rdparty/forkfd/forkfd.c
@@ -719,7 +719,7 @@ int forkfd(int flags, pid_t *ppid)
         /* parent process */
         info->deathPipe = death_pipe[1];
         fd = death_pipe[0];
-        ffd_atomic_store(&info->pid, pid, FFD_ATOMIC_RELEASE);
+        ffd_atomic_store(&info->pid, (int32_t)pid, FFD_ATOMIC_RELEASE);
 
         /* release the child */
 #ifdef HAVE_EVENTFD
-- 
2.28.0


From d9fb34037c2500d55ee24212110360127d9e8994 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 4 Jun 2020 23:11:17 +1000
Subject: Implement QFilesystemWatcher for Haiku


diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index a33ffe7..91190d4 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -96,6 +96,9 @@ qtConfig(filesystemwatcher) {
     } else:macos {
         OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm
         HEADERS += io/qfilesystemwatcher_fsevents_p.h
+    } else:haiku {
+        SOURCES += io/qfilesystemwatcher_haiku.cpp
+        HEADERS += io/qfilesystemwatcher_haiku_p.h
     } else:qtConfig(inotify) {
         SOURCES += io/qfilesystemwatcher_inotify.cpp
         HEADERS += io/qfilesystemwatcher_inotify_p.h
diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp
index 96d9210..f6147de 100644
--- a/src/corelib/io/qfilesystemwatcher.cpp
+++ b/src/corelib/io/qfilesystemwatcher.cpp
@@ -54,6 +54,8 @@
 #include "qfilesystemwatcher_polling_p.h"
 #if defined(Q_OS_WIN)
 #  include "qfilesystemwatcher_win_p.h"
+#elif defined(Q_OS_HAIKU)
+#  include "qfilesystemwatcher_haiku_p.h"
 #elif defined(USE_INOTIFY)
 #  include "qfilesystemwatcher_inotify_p.h"
 #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) || defined(QT_PLATFORM_UIKIT)
@@ -73,6 +75,8 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject
 {
 #if defined(Q_OS_WIN)
     return new QWindowsFileSystemWatcherEngine(parent);
+#elif defined(Q_OS_HAIKU)
+    return new QHaikuFileSystemWatcherEngine(parent);
 #elif defined(USE_INOTIFY)
     // there is a chance that inotify may fail on Linux pre-2.6.13 (August
     // 2005), so we can't just new inotify directly.
diff --git a/src/corelib/io/qfilesystemwatcher_haiku.cpp b/src/corelib/io/qfilesystemwatcher_haiku.cpp
new file mode 100644
index 0000000..8355ca8
--- /dev/null
+++ b/src/corelib/io/qfilesystemwatcher_haiku.cpp
@@ -0,0 +1,254 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2015-2020 Gerasim Troeglazov,
+** Contact: 3dEyes@gmail.com
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qfilesystemwatcher_haiku_p.h"
+#include <QtCore/qscopeguard.h>
+#include <QtCore/qtimer.h>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+QHaikuFileWatcher::QHaikuFileWatcher() : QObject(), BLooper() {};
+QHaikuDirWatcher::QHaikuDirWatcher() : QObject(), BLooper() {};
+
+QHaikuFileSystemWatcherEngine::QHaikuFileSystemWatcherEngine(QObject *parent)
+	: QFileSystemWatcherEngine(parent)
+{
+	fileLooper = new QHaikuFileWatcher();
+	connect(fileLooper, SIGNAL(fileChanged(const QString &, bool)), SLOT(bfsFileChanged(const QString &, bool)));
+	fileLooper->Run();
+
+	dirLooper = new QHaikuDirWatcher();
+	connect(dirLooper, SIGNAL(directoryChanged(const QString &, bool)), SLOT(bfsDirectoryChanged(const QString &, bool)));
+	dirLooper->Run();
+}
+
+QHaikuFileSystemWatcherEngine::~QHaikuFileSystemWatcherEngine()
+{
+	stop_watching(fileLooper);
+	if (fileLooper->Lock())
+		fileLooper->Quit();
+
+	stop_watching(dirLooper);
+	if (dirLooper->Lock())
+		dirLooper->Quit();
+}
+
+QStringList QHaikuFileSystemWatcherEngine::addPaths(const QStringList &paths,
+                                                      QStringList *files,
+                                                      QStringList *directories)
+{
+	QStringList unhandled;
+	for (const QString &path : paths) {
+		QFileInfo fi(path);
+		bool isDir = fi.isDir();
+		auto sg = qScopeGuard([&]{ unhandled.push_back(path); });
+		if (isDir) {
+			if (directories->contains(path))
+				continue;
+		} else {
+			if (files->contains(path))
+				continue;
+		}
+
+		BEntry entry(path.toUtf8().constData());       
+		if (!entry.Exists())
+			continue;
+
+		node_ref nref;
+		entry.GetNodeRef(&nref);
+		status_t status = isDir ?
+			watch_node(&nref, (B_WATCH_NAME | B_WATCH_ATTR | B_WATCH_STAT | B_WATCH_DIRECTORY), dirLooper):
+			watch_node(&nref, (B_WATCH_NAME | B_WATCH_ATTR | B_WATCH_STAT), fileLooper);
+
+		if (status != B_OK) {
+			qWarning("watch_node(%ls) failed:", path.constData());
+			continue;
+		}
+
+		sg.dismiss();
+
+		if (isDir)
+			directories->append(path);
+		else
+			files->append(path);
+	}
+	return unhandled;
+}
+
+QStringList QHaikuFileSystemWatcherEngine::removePaths(const QStringList &paths,
+                                                         QStringList *files,
+                                                         QStringList *directories)
+{
+	QStringList unhandled;
+	for (const QString &path : paths) {
+		auto sg = qScopeGuard([&]{ unhandled.push_back(path); });
+
+		BEntry entry(path.toUtf8().constData());
+		node_ref nref;
+		entry.GetNodeRef(&nref);
+
+		if (directories->contains(path)) {
+			directories->removeAll(path);
+			status_t status = watch_node(&nref, B_STOP_WATCHING, dirLooper);
+		} else if (files->contains(path)) {
+			files->removeAll(path);
+			status_t status = watch_node(&nref, B_STOP_WATCHING, fileLooper);
+		} else {
+			continue;
+		}
+
+		sg.dismiss();
+	}
+
+	return unhandled;
+}
+
+void
+QHaikuDirWatcher::MessageReceived(BMessage* message)
+{
+	if (message->what == B_NODE_MONITOR) {
+		int32 opcode;
+
+		if (message->FindInt32("opcode", &opcode) != B_OK)
+			return;
+
+		switch (opcode) {
+			case B_ENTRY_MOVED:
+				{
+					int32 device = 0;
+					int64 srcFolder = 0;
+					int64 dstFolder = 0;
+					const char* name = NULL;
+					if (message->FindInt32("device", &device) != B_OK
+						|| message->FindInt64("to directory", &dstFolder) != B_OK
+						|| message->FindInt64("from directory", &srcFolder) != B_OK
+						|| message->FindString("name", &name) != B_OK)
+							break;
+
+					entry_ref ref(device, srcFolder, name);
+					BEntry entry(&ref);
+
+					BEntry dirEntry;
+					entry.GetParent(&dirEntry);
+
+					BPath path;
+					dirEntry.GetPath(&path);
+					
+					QString qpath = QString::fromUtf8(path.Path());
+
+					emit directoryChanged(qpath, false);
+				}
+				break;
+			case B_ENTRY_CREATED:
+			case B_ENTRY_REMOVED:
+				{
+					int64 directory;
+					int32 device;
+					int64 node;
+					const char *name;
+					if (message->FindInt64("directory", &directory) != B_OK
+						|| message->FindInt32("device", &device) != B_OK
+						|| message->FindInt64("node", &node) != B_OK
+						|| message->FindString("name", &name) != B_OK)
+							break;
+
+					entry_ref ref(device, directory, name);
+					BEntry entry(&ref);				
+					BEntry dirEntry;
+					entry.GetParent(&dirEntry);
+
+					BPath path;
+					dirEntry.GetPath(&path);
+
+					QString qpath = QString::fromUtf8(path.Path());
+					emit directoryChanged(qpath, opcode == B_ENTRY_REMOVED);
+				}
+				break;
+		}
+	}
+}
+
+void
+QHaikuFileWatcher::MessageReceived(BMessage* message)
+{
+	if (message->what == B_NODE_MONITOR) {
+		int32 opcode;
+		node_ref nref;
+		const char *name;
+
+		if (message->FindInt32("opcode", &opcode) != B_OK)
+			return;
+
+		switch (opcode) {
+			case B_ENTRY_MOVED:
+				{
+					int32 device = 0;
+					int64 srcFolder = 0;
+					int64 dstFolder = 0;
+					const char* name = NULL;
+					if (message->FindInt32("device", &device) != B_OK
+						|| message->FindInt64("to directory", &dstFolder) != B_OK
+						|| message->FindInt64("from directory", &srcFolder) != B_OK
+						|| message->FindString("name", &name) != B_OK)
+							break;
+
+					entry_ref ref(device, srcFolder, name);
+					BEntry entry(&ref);
+
+					BPath path;
+					entry.GetPath(&path);
+
+					QString qpath = QString::fromUtf8(path.Path());
+
+					emit fileChanged(qpath, false);
+				}
+				break;
+			case B_STAT_CHANGED:
+			case B_ATTR_CHANGED:
+				BString path;
+				if (message->FindString("path", &path) == B_OK) {
+					QString qpath = QString::fromUtf8(path.String());
+
+			        QFileInfo fi(qpath);
+			        if (!fi.exists())
+			            emit fileChanged(qpath, true);
+			        else
+			            emit fileChanged(qpath, false);
+				}
+				break;
+		}
+	}
+}
+
+void 
+QHaikuFileSystemWatcherEngine::bfsDirectoryChanged(const QString &path, bool removed)
+{
+	emit directoryChanged(path, removed);
+}
+
+void
+QHaikuFileSystemWatcherEngine::bfsFileChanged(const QString &path, bool removed)
+{
+	emit fileChanged(path, removed);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qfilesystemwatcher_haiku_p.cpp"
diff --git a/src/corelib/io/qfilesystemwatcher_haiku_p.h b/src/corelib/io/qfilesystemwatcher_haiku_p.h
new file mode 100644
index 0000000..8a8d75a
--- /dev/null
+++ b/src/corelib/io/qfilesystemwatcher_haiku_p.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2015-2020 Gerasim Troeglazov,
+** Contact: 3dEyes@gmail.com
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#ifndef QFILESYSTEMWATCHER_HAIKU_P_H
+#define QFILESYSTEMWATCHER_HAIKU_P_H
+
+#include <QtCore/qfileinfo.h>
+#include <QtCore/qmutex.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qtimer.h>
+#include <QtCore/qhash.h>
+
+#include <Application.h>
+#include <NodeMonitor.h>
+#include <Looper.h>
+#include <String.h>
+#include <Autolock.h>
+#include <Handler.h>
+#include <Entry.h>
+#include <Path.h>
+
+#include "qfilesystemwatcher_p.h"
+
+QT_REQUIRE_CONFIG(filesystemwatcher);
+QT_BEGIN_NAMESPACE
+
+class QHaikuDirWatcher : public QObject, public BLooper {
+	Q_OBJECT
+public:
+	QHaikuDirWatcher();
+	virtual	void MessageReceived(BMessage* msg);
+Q_SIGNALS:
+	void directoryChanged(const QString &path, bool removed);
+};
+
+class QHaikuFileWatcher : public QObject, public BLooper {
+	Q_OBJECT
+public:
+	QHaikuFileWatcher();
+	virtual	void MessageReceived(BMessage* msg);
+Q_SIGNALS:
+	void fileChanged(const QString &path, bool removed);
+};
+
+class QHaikuFileSystemWatcherEngine : public QFileSystemWatcherEngine
+{
+    Q_OBJECT
+
+public:
+    QHaikuFileSystemWatcherEngine(QObject *parent);
+    ~QHaikuFileSystemWatcherEngine();
+
+    QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
+    QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
+
+private:
+	QHaikuDirWatcher *dirLooper;
+	QHaikuFileWatcher *fileLooper;
+
+private Q_SLOTS:
+	void bfsDirectoryChanged(const QString &path, bool removed);
+	void bfsFileChanged(const QString &path, bool removed);
+};
+
+QT_END_NAMESPACE
+#endif // QFILESYSTEMWATCHER_HAIKU_P_H
+
-- 
2.28.0


From 99c3380949601083a8b194b9d6bb70d2d68a8fdd Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 16 Jun 2020 18:06:57 +1000
Subject: Don't use AF_INET6 for new sockets


diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index e5b9fbb..a1b1fc4 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -265,8 +265,12 @@ bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType soc
     }
     int protocol = 0;
 #endif // QT_NO_SCTP
+#ifdef Q_OS_HAIKU
+	int domain = AF_INET;
+#else
     int domain = (socketProtocol == QAbstractSocket::IPv6Protocol
                   || socketProtocol == QAbstractSocket::AnyIPProtocol) ? AF_INET6 : AF_INET;
+#endif
     int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM;
 
     int socket = qt_safe_socket(domain, type, protocol, O_NONBLOCK);
-- 
2.28.0


From cd28dcebb36aedacc5f826acd30c6ba6c5f24286 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 5 Oct 2020 19:40:40 +1000
Subject: Disable Haswell CPU feature for plugins


diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp
index a5c72f8..cc2afac 100644
--- a/src/corelib/plugin/qlibrary_unix.cpp
+++ b/src/corelib/plugin/qlibrary_unix.cpp
@@ -191,7 +191,7 @@ bool QLibraryPrivate::load_sys()
         prefixes.append(QString());
     }
 
-#if defined(Q_PROCESSOR_X86) && !defined(Q_OS_DARWIN)
+#if defined(Q_PROCESSOR_X86) && !defined(Q_OS_DARWIN) && !defined(Q_OS_HAIKU)
     if (qCpuHasFeature(ArchHaswell)) {
         auto transform = [](QStringList &list, void (*f)(QString *)) {
             QStringList tmp;
-- 
2.28.0


From d7e8622c4b1b6246c80a54c0c84dc164ea8afeac Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 9 Oct 2021 18:33:27 +1000
Subject: QSharedMemory implementation for Haiku


diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri
index 749672c..e9bb3e9 100644
--- a/src/corelib/kernel/kernel.pri
+++ b/src/corelib/kernel/kernel.pri
@@ -167,13 +167,18 @@ unix|integrity {
 
     qtConfig(clock-gettime): QMAKE_USE_PRIVATE += librt
 
-    !android {
+    !android:!haiku {
         SOURCES += kernel/qsharedmemory_posix.cpp \
                    kernel/qsharedmemory_systemv.cpp \
                    kernel/qsharedmemory_unix.cpp \
                    kernel/qsystemsemaphore_posix.cpp \
                    kernel/qsystemsemaphore_systemv.cpp \
                    kernel/qsystemsemaphore_unix.cpp
+    } else:haiku {
+        SOURCES += kernel/qsharedmemory_haiku.cpp \
+                   kernel/qsystemsemaphore_posix.cpp \
+                   kernel/qsystemsemaphore_systemv.cpp \
+                   kernel/qsystemsemaphore_unix.cpp
     } else {
         SOURCES += kernel/qsharedmemory_android.cpp \
                    kernel/qsystemsemaphore_android.cpp
diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp
index 2d65e0b..8fd63d1 100644
--- a/src/corelib/kernel/qsharedmemory.cpp
+++ b/src/corelib/kernel/qsharedmemory.cpp
@@ -46,6 +46,9 @@
 #ifdef Q_OS_WIN
 #  include <qt_windows.h>
 #endif
+#ifdef Q_OS_HAIKU
+#  include <OS.h>
+#endif
 
 QT_BEGIN_NAMESPACE
 
@@ -77,6 +80,14 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,
     result.append(QLatin1String(hex));
 #ifdef Q_OS_WIN
     return result;
+#elif defined(Q_OS_HAIKU)
+    if (key.length() < B_OS_NAME_LENGTH)
+        return key;
+
+    result = key;
+    result.truncate(B_OS_NAME_LENGTH - 4);
+    quint16 summ = qChecksum(key.toLatin1().constData(), key.length());
+    return result + QLatin1Char('_') + QString::number(summ, 16);
 #elif defined(QT_POSIX_IPC)
     return QLatin1Char('/') + result;
 #else
diff --git a/src/corelib/kernel/qsharedmemory_haiku.cpp b/src/corelib/kernel/qsharedmemory_haiku.cpp
new file mode 100644
index 0000000..afc24ed
--- /dev/null
+++ b/src/corelib/kernel/qsharedmemory_haiku.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 Gerasim Troeglazov,
+** Contact: 3dEyes@gmail.com
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "qsharedmemory.h"
+#include "qsharedmemory_p.h"
+#include <qdebug.h>
+
+#include <OS.h>
+
+#ifndef QT_NO_SHAREDMEMORY
+QT_BEGIN_NAMESPACE
+
+QSharedMemoryPrivate::QSharedMemoryPrivate()
+	: QObjectPrivate(), memory(0), size(0), error(QSharedMemory::NoError),
+#ifndef QT_NO_SYSTEMSEMAPHORE
+	systemSemaphore(QString()), lockedByMe(false),
+#endif
+	hand(-1)
+{
+}
+
+void QSharedMemoryPrivate::setErrorString(QLatin1String function)
+{
+	Q_UNUSED(function);
+}
+
+key_t QSharedMemoryPrivate::handle()
+{
+	const QString safeKey = makePlatformSafeKey(key);
+	if (safeKey.isEmpty()) {
+		errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle"));
+		error = QSharedMemory::KeyError;
+		return 0;
+	}
+
+	return 1;
+}
+
+#endif // QT_NO_SHAREDMEMORY
+
+#if !(defined(QT_NO_SHAREDMEMORY) && defined(QT_NO_SYSTEMSEMAPHORE))
+int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
+{
+	Q_UNUSED(fileName);
+	return 0;
+}
+#endif // QT_NO_SHAREDMEMORY && QT_NO_SYSTEMSEMAPHORE
+
+#ifndef QT_NO_SHAREDMEMORY
+
+bool QSharedMemoryPrivate::cleanHandle()
+{
+	if (hand > 0)
+		delete_area(hand);
+
+	hand = -1;
+
+	return true;
+}
+
+bool QSharedMemoryPrivate::create(int size)
+{
+	if (!handle())
+		return false;
+
+	const QLatin1String function("QSharedMemory::create");
+
+	const QString areaName = makePlatformSafeKey(key);
+
+	if (find_area(areaName.toUtf8().constData()) > 0) {
+		errorString = QSharedMemory::tr("%1: already exists").arg(function);
+		error = QSharedMemory::AlreadyExists;
+		return false;
+	}
+
+	hand = create_area(areaName.toUtf8().constData(), &memory, B_ANY_ADDRESS, size,
+		B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
+
+	if (hand <= B_ERROR) {
+		switch (hand) {
+			case B_NO_MEMORY:
+				errorString = QSharedMemory::tr("%1: not enough memory").arg(function);
+				error = QSharedMemory::OutOfResources;
+				break;
+			case B_BAD_VALUE:
+				errorString = QSharedMemory::tr("%1: bad area name").arg(function);
+				error = QSharedMemory::KeyError;
+				break;
+			default:
+				errorString = QSharedMemory::tr("%1: unknown error").arg(function);
+				error = QSharedMemory::UnknownError;
+				break;
+		}
+		return false;
+	}
+
+	return true;
+}
+
+bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
+{
+	const QLatin1String function("QSharedMemory::attach");
+
+	const QString areaName = makePlatformSafeKey(key);
+
+	uint32 permissions = mode == QSharedMemory::ReadOnly ? B_READ_AREA : B_READ_AREA | B_WRITE_AREA;
+
+	if (hand <= B_ERROR) {
+		area_id baseArea = find_area(areaName.toUtf8().constData());
+		if (baseArea <= B_ERROR) {
+			error = QSharedMemory::NotFound;
+			errorString = QSharedMemory::tr("%1: doesn't exist").arg(function);
+			cleanHandle();
+			return false;
+		}
+
+		hand = clone_area(areaName.toUtf8().constData(), &memory, B_ANY_ADDRESS, permissions, baseArea);
+		if (hand <= B_ERROR) {
+			error = QSharedMemory::UnknownError;
+			errorString = QSharedMemory::tr("%1: clone_area failed").arg(function);
+			cleanHandle();
+			return false;
+		}
+	}
+
+	area_info info;
+	if (get_area_info(hand, &info) != B_OK) {
+		error = QSharedMemory::UnknownError;
+		errorString = QSharedMemory::tr("%1: size query failed").arg(function);
+		cleanHandle();
+		return false;
+	}
+
+	size = info.size;
+	memory = info.address;
+
+	return true;
+}
+
+bool QSharedMemoryPrivate::detach()
+{
+	const QLatin1String function("QSharedMemory::detach");
+
+	area_id id = area_for(memory);
+
+	if (id == B_ERROR) {
+		error = QSharedMemory::NotFound;
+		errorString = QSharedMemory::tr("%1: doesn't exist").arg(function);
+		return false;
+	}
+
+	if (delete_area(id) != B_OK) {
+		error = QSharedMemory::UnknownError;
+		errorString = QSharedMemory::tr("%1: delete_area failed").arg(function);
+		return false;
+	}
+
+	memory = 0;
+	size = 0;
+
+	return cleanHandle();
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SHAREDMEMORY
diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h
index e6e989a..dbf32b6 100644
--- a/src/corelib/kernel/qsharedmemory_p.h
+++ b/src/corelib/kernel/qsharedmemory_p.h
@@ -72,10 +72,14 @@ namespace QSharedMemoryPrivate
 # include "private/qobject_p.h"
 #endif
 
-#if !defined(Q_OS_WIN) && !defined(Q_OS_ANDROID) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_RTEMS)
+#if !defined(Q_OS_WIN) && !defined(Q_OS_ANDROID) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_RTEMS) && !defined(Q_OS_HAIKU)
 #  include <sys/sem.h>
 #endif
 
+#if defined(Q_OS_HAIKU)
+#  include <OS.h>
+#endif
+
 QT_BEGIN_NAMESPACE
 
 #ifndef QT_NO_SYSTEMSEMAPHORE
@@ -138,6 +142,8 @@ public:
             const QString &prefix = QLatin1String("qipc_sharedmemory_"));
 #ifdef Q_OS_WIN
     Qt::HANDLE handle();
+#elif defined(Q_OS_HAIKU)
+	area_id handle();
 #elif defined(QT_POSIX_IPC)
     int handle();
 #else
@@ -165,6 +171,8 @@ public:
 private:
 #ifdef Q_OS_WIN
     Qt::HANDLE hand;
+#elif defined(Q_OS_HAIKU)
+	area_id hand;
 #elif defined(QT_POSIX_IPC)
     int hand;
 #else
-- 
2.30.2

