From 0970386a931335c2047dd000ad81a857097607e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20Mizsei?= <zmizsei@extrowerk.com>
Date: Thu, 12 Aug 2021 13:10:39 +0000
Subject: Haiku supporting patches


diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro
index 84d1894..163953e 100644
--- a/libretroshare/src/libretroshare.pro
+++ b/libretroshare/src/libretroshare.pro
@@ -315,12 +315,13 @@ openbsd-* {
 
 haiku-* {
 
-	QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen
+	QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dstat64=stat -Dstatvfs64=statvfs -Dfopen64=fopen -D_BSD_SOURCE
 	OPENPGPSDK_DIR = ../../openpgpsdk/src
 	INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk
 	DEFINES *= NO_SQLCIPHER
 	CONFIG += release
 	DESTDIR = lib
+	LIBS += -lnetwork -lbsd
 }
 
 ################################### COMMON stuff ##################################
diff --git a/libretroshare/src/rsserver/rsaccounts.cc b/libretroshare/src/rsserver/rsaccounts.cc
index 8be5607..f26a80e 100644
--- a/libretroshare/src/rsserver/rsaccounts.cc
+++ b/libretroshare/src/rsserver/rsaccounts.cc
@@ -341,7 +341,11 @@ bool RsAccountsDetail::defaultBaseDirectory()
 	}
 
 	basedir = h;
-	basedir += "/.retroshare";
+	#ifndef __HAIKU__
+		basedir += "/.retroshare";
+	#else
+		basedir += "/config/settings/retroshare";
+	#endif
 
 #else
 	if (RsInit::isPortable())
@@ -813,6 +817,8 @@ static bool checkAccount(const std::string &accountdir, AccountDetails &account,
 	dataDirectory = ".";
 #elif defined(ANDROID)
 	dataDirectory = PathBaseDirectory()+"/usr/share/retroshare";
+#elif defined(__HAIKU__)
+	dataDirectory = "/system/apps/RetroShare";
 #elif defined(DATA_DIR)
 	// cppcheck-suppress ConfigurationNotChecked
 	dataDirectory = DATA_DIR;
diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc
index 8449a9e..40d1f0b 100644
--- a/libretroshare/src/rsserver/rsinit.cc
+++ b/libretroshare/src/rsserver/rsinit.cc
@@ -1190,6 +1190,9 @@ int RsServer::StartupRetroShare()
 #ifdef __APPLE__
 	plugins_directories.push_back(RsAccounts::systemDataDirectory()) ;
 #endif
+#ifdef __HAIKU__
+	plugins_directories.push_back("/system/apps/RetroShare/plugins") ;
+#endif
 #if !defined(WINDOWS_SYS) && defined(PLUGIN_DIR)
 	plugins_directories.push_back(std::string(PLUGIN_DIR)) ;
 #endif
diff --git a/libretroshare/src/util/folderiterator.cc b/libretroshare/src/util/folderiterator.cc
index c67204f..5e5f8d5 100644
--- a/libretroshare/src/util/folderiterator.cc
+++ b/libretroshare/src/util/folderiterator.cc
@@ -136,6 +136,7 @@ bool FolderIterator::updateFileInfo(bool& should_skip)
 
 #warning cyril soler: should we take care of symbolic links on windows?
 #ifndef WINDOWS_SYS
+#ifndef __HAIKU__
    if( ent->d_type == DT_LNK)
    {
 	  if(!mAllowSymLinks)
@@ -151,6 +152,7 @@ bool FolderIterator::updateFileInfo(bool& should_skip)
 	   should_skip = true ;
 	   return true ;
    }
+#endif /*HAIKU*/
 #endif
 
    struct stat64 buf ;
diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc
index 035ad21..466b3b9 100644
--- a/libretroshare/src/util/rsthreads.cc
+++ b/libretroshare/src/util/rsthreads.cc
@@ -37,6 +37,7 @@
 #include <sys/time.h>
 #endif
 
+#ifndef __HAIKU__
 #ifdef __APPLE__
 int __attribute__((weak)) pthread_setname_np(const char *__buf) ;
 int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) {
@@ -63,6 +64,7 @@ int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) {
 #ifdef RSMUTEX_ABORT
 	#include <stdlib.h>
 #endif
+#endif /*HAIKU*/
 
 #ifdef DEBUG_THREADS
 	#include <iostream>
@@ -214,9 +216,10 @@ bool RsThread::start(const std::string& threadName)
 
 		/* Set PThread thread name which is restricted to 16 characters
 		 * including the terminating null byte */
+#ifndef __HAIKU__
 		if(pthread_setname_np && !threadName.empty())
 			RS_pthread_setname_np(mTid, threadName.substr(0, 15).c_str());
-
+#endif
 		return true;
 	}
 
diff --git a/plugins/FeedReader/FeedReader.pro b/plugins/FeedReader/FeedReader.pro
index b78dda9..acde004 100644
--- a/plugins/FeedReader/FeedReader.pro
+++ b/plugins/FeedReader/FeedReader.pro
@@ -156,9 +156,10 @@ openbsd-* {
 }
 
 haiku-* {
-	LIBXML2_DIR = pkg-config --cflags libxml-2.0
+	CONFIG += link_pkgconfig
+	PKGCONFIG *= libcurl libxml-2.0 libxslt
 
+	LIBXML2_DIR = pkg-config --cflags libxml-2.0
 	INCLUDEPATH += $${LIBXML2_DIR}
-
 	LIBS += -lcurl -lxml2 -lxslt
 }
diff --git a/plugins/VOIP/VOIP.pro b/plugins/VOIP/VOIP.pro
index 8186c48..36e789b 100644
--- a/plugins/VOIP/VOIP.pro
+++ b/plugins/VOIP/VOIP.pro
@@ -58,6 +58,18 @@ linux-* {
 	LIBS += -lspeex -lspeexdsp -lavcodec -lavutil
 }
 
+#################################### Haiku #####################################
+
+haiku-* {
+	CONFIG += link_pkgconfig
+
+	PKGCONFIG += libavcodec libavutil
+	PKGCONFIG += speex speexdsp
+	PKGCONFIG += opencv4
+} else {
+	LIBS += -lspeex -lspeexdsp -lavcodec -lavutil
+}
+
 #################################### Windows #####################################
 
 win32 {
diff --git a/retroshare-gui/src/gui/elastic/fft.h b/retroshare-gui/src/gui/elastic/fft.h
index c26dd61..a2ffcc7 100644
--- a/retroshare-gui/src/gui/elastic/fft.h
+++ b/retroshare-gui/src/gui/elastic/fft.h
@@ -95,6 +95,15 @@ function prototypes
 */
 
 
+#ifdef __HAIKU__
+	#include <math.h>
+	void sincos(double x, double* p_sin, double* p_cos) {
+		*p_sin = sin(x);
+		*p_cos = cos(x);
+	}
+#endif /*HAIKU*/
+
+
 /* -------- initializing routines -------- */
 
 #pragma once
diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp
index cbed669..344c541 100644
--- a/retroshare-gui/src/rshare.cpp
+++ b/retroshare-gui/src/rshare.cpp
@@ -859,6 +859,8 @@ Rshare::defaultDataDirectory()
 {
 #if defined(Q_OS_WIN)
   return (win32_app_data_folder() + "\\RetroShare");
+#elif defined(__HAIKU__)
+  return (QDir::homePath() + "/config/settings/retroshare");
 #else
   return (QDir::homePath() + "/.RetroShare");
 #endif
diff --git a/retroshare-service/src/retroshare-service.pro b/retroshare-service/src/retroshare-service.pro
index cbd1b9d..bb05c75 100644
--- a/retroshare-service/src/retroshare-service.pro
+++ b/retroshare-service/src/retroshare-service.pro
@@ -64,6 +64,10 @@ unix {
     INSTALLS += target
 }
 
+haiku {
+	LIBS *= -lnetwork -lbsd
+}
+
 ################################# MacOSX ##########################################
 
 macx {
@@ -86,6 +90,7 @@ macx {
 	INCLUDEPATH += . $$INC_DIR
 }
 
+
 ################################# Windows ##########################################
 
 win32-g++|win32-clang-g++ {
-- 
2.30.2


From 1146847079c1f68262994a931a761fea9833be03 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 18 Aug 2021 14:25:46 +0000
Subject: Haiku style by default


diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp
index 86a9355..c16d4e9 100644
--- a/retroshare-gui/src/gui/settings/rsharesettings.cpp
+++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp
@@ -107,7 +107,8 @@ void RshareSettings::initSettings()
 #ifdef Q_OS_LINUX
 	// use GTK as default style on linux
 	setDefault(SETTING_STYLE, "GTK+");
-#else
+#elif defined(Q_OS_HAIKU)
+	setDefault(SETTING_STYLE, "Haiku");
 #if defined(Q_OS_MAC)
 	setDefault(SETTING_STYLE, "macintosh (aqua)");
 #else
-- 
2.30.2


From 5ffcb97de2063e52da0c1045d22f2af5e12f43b5 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 19 Aug 2021 08:13:13 +1000
Subject: Use libupnp for Haiku


diff --git a/retroshare.pri b/retroshare.pri
index 2c2201e..4e91cbb 100644
--- a/retroshare.pri
+++ b/retroshare.pri
@@ -765,6 +765,11 @@ macx-* {
 	QT += macextras
 }
 
+haiku-* {
+	RS_UPNP_LIB = upnp ixml
+}
+
+
 # If not yet defined attempt UPnP library autodetection should works at least
 # for miniupnc libupnp-1.6.x and libupnp-1.8.x
 isEmpty(RS_UPNP_LIB) {
-- 
2.30.2


From 3f2665daf8792744c9ef3d787b517ac7f743454a Mon Sep 17 00:00:00 2001
From: Gioacchino Mazzurco <gio@eigenlab.org>
Date: Fri, 6 Aug 2021 12:15:34 +0200
Subject: Fix compilation with C++17


diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc
index 8556b81..41d2270 100644
--- a/libretroshare/src/util/rsdir.cc
+++ b/libretroshare/src/util/rsdir.cc
@@ -64,6 +64,26 @@
  * #define RSDIR_DEBUG 1
  ****/
 
+#if __cplusplus < 201703L
+bool std::filesystem::create_directories(const std::string& path)
+{
+	for( std::string::size_type lastIndex = 0; lastIndex < std::string::npos;
+	     lastIndex = path.find('/', lastIndex) )
+	{
+		std::string&& curDir = path.substr(0, ++lastIndex);
+		if(!RsDirUtil::checkCreateDirectory(curDir))
+		{
+			RsErr() << __PRETTY_FUNCTION__ << " failure creating: " << curDir
+			        << " of: " << path << std::endl;
+			return false;
+		}
+	}
+	return true;
+}
+#else
+#	include <filesystem>
+#endif // __cplusplus < 201703L
+
 std::string 	RsDirUtil::getTopDir(const std::string& dir)
 {
 	std::string top;
@@ -528,24 +548,6 @@ bool RsDirUtil::checkCreateDirectory(const std::string& dir)
 	return true;
 }
 
-#if __cplusplus < 201703L
-bool std::filesystem::create_directories(const std::string& path)
-{
-	for( std::string::size_type lastIndex = 0; lastIndex < std::string::npos;
-	     lastIndex = path.find('/', lastIndex) )
-	{
-		std::string&& curDir = path.substr(0, ++lastIndex);
-		if(!RsDirUtil::checkCreateDirectory(curDir))
-		{
-			RsErr() << __PRETTY_FUNCTION__ << " failure creating: " << curDir
-			        << " of: " << path << std::endl;
-			return false;
-		}
-	}
-	return true;
-}
-#endif // __cplusplus < 201703L
-
 std::string RsDirUtil::removeSymLinks(const std::string& path)
 {
 #if defined(WINDOWS_SYS) || defined(__APPLE__) || defined(__ANDROID__)
-- 
2.30.2


From 80701101852c3961e5c84a19540a81f54f596dea Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 12 Nov 2021 19:04:07 +1000
Subject: Fix bdThread


diff --git a/libbitdht/src/util/bdthreads.cc b/libbitdht/src/util/bdthreads.cc
index 3fce7ff..9e908b9 100644
--- a/libbitdht/src/util/bdthreads.cc
+++ b/libbitdht/src/util/bdthreads.cc
@@ -121,7 +121,7 @@ void bdThread::join() /* waits for the the mTid thread to stop */
 
     mMutex.lock();
     {
-#if defined(_WIN32) || defined(__MINGW32__) || defined(__APPLE__)
+#if defined(_WIN32) || defined(__MINGW32__) || defined(__APPLE__) || defined(__HAIKU__)
 	/* Its a struct in Windows compile and the member .p ist checked in the pthreads library */
 #else
 	if(mTid > 0)
-- 
2.30.2


From 9172243cb7feea3e63ae4e2127e519df53708f69 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 12 Nov 2021 20:20:23 +1000
Subject: Haiku style by default


diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp
index c16d4e9..6b46cc1 100644
--- a/retroshare-gui/src/gui/settings/rsharesettings.cpp
+++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp
@@ -163,7 +163,11 @@ void RshareSettings::setLanguageCode(const QString& languageCode)
 /** Gets the interface style key (e.g., "windows", "motif", etc.) */
 QString RshareSettings::getInterfaceStyle()
 {
+#ifdef __HAIKU__
+	return value(SETTING_STYLE, "haiku").toString();
+#else
 	return value(SETTING_STYLE, "fusion").toString();
+#endif
 }
 
 /** Sets the interface style key. */
-- 
2.30.2


From a7896a244af95425ebccde9946faf0ed72f57a85 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 13 Nov 2021 20:08:42 +1000
Subject: Use system typedefs for int types


diff --git a/libretroshare/src/tcponudp/tcppacket.h b/libretroshare/src/tcponudp/tcppacket.h
index e87c3e3..78ded40 100644
--- a/libretroshare/src/tcponudp/tcppacket.h
+++ b/libretroshare/src/tcponudp/tcppacket.h
@@ -24,10 +24,13 @@
 
 #include <sys/types.h>
 
-
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#else
 typedef unsigned int   uint32;
 typedef unsigned short uint16;
 typedef unsigned char  uint8;
+#endif
 
 #define TCP_PSEUDO_HDR_SIZE 20
 
-- 
2.30.2

