From 4d69b3890f171c31c05cc7cc5f97c74794e5e9fe Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 17 Aug 2019 20:06:49 +1000
Subject: Dbus autostart


diff --git a/ktorrent/main.cpp b/ktorrent/main.cpp
index d296bb3..1d4441a 100644
--- a/ktorrent/main.cpp
+++ b/ktorrent/main.cpp
@@ -36,6 +36,10 @@
 #include <QDir>
 #include <QFile>
 
+#ifdef __HAIKU__
+#include <QProcess>
+#endif
+
 #include <KAboutData>
 #include <KCrash>
 #include <KDBusService>
@@ -93,6 +97,18 @@ bool GrabPIDLock()
 
 int main(int argc, char** argv)
 {
+#ifdef __HAIKU__
+	int status=0;
+    QProcess dbusProcess;
+    QString exec = QString::fromStdString("/bin/dbus-launch");
+    QStringList params;
+	dbusProcess.start(exec, params);
+	dbusProcess.waitForFinished();
+	QString output = QString::fromStdString(dbusProcess.readAllStandardOutput().data());
+	QStringList list = output.split(QString::fromStdString("\n"), QString::SkipEmptyParts);
+	foreach (const QString &str, list)
+		putenv(str.toLatin1().data());
+#endif
 #ifndef Q_WS_WIN
     // ignore SIGPIPE and SIGXFSZ
     signal(SIGPIPE, SIG_IGN);
@@ -252,6 +268,9 @@ int main(int argc, char** argv)
         Out(SYS_GEN | LOG_IMPORTANT) << "Uncaught unknown exception " << endl;
     }
     bt::Globals::cleanup();
+#ifdef __HAIKU__
+    system("kill -9 $DBUS_SESSION_BUS_PID");
+#endif
     return 0;
 }
 
-- 
2.21.0

