From 24a735fc878e61a74fe83ddc0473983a55430058 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 6 Dec 2020 00:08:29 +1000
Subject: Add support for autolaunch


diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp
index ee50acb..0a0a144 100644
--- a/src/utils/confighandler.cpp
+++ b/src/utils/confighandler.cpp
@@ -296,7 +296,10 @@ bool ConfigHandler::verifyLaunchFile()
 {
     bool res = false;
 
-#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
+#if defined(Q_OS_HAIKU)
+    QString path = QDir::homePath() + "/config/settings/boot/launch/Flameshot";
+    res = QFile(path).exists();
+#elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
     QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
     res = QFile(path).exists();
 #elif defined(Q_OS_WIN)
@@ -311,7 +314,16 @@ bool ConfigHandler::verifyLaunchFile()
 
 void ConfigHandler::setStartupLaunch(const bool start)
 {
-#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
+#if defined(Q_OS_HAIKU)
+    QString linkname = QDir::homePath() + "/config/settings/boot/launch/Flameshot";
+    QFile appFile(QCoreApplication::applicationFilePath());
+    QFile linkFile(linkname);
+    if (start) {
+		appFile.link(linkname);
+    } else {
+        linkFile.remove();
+    }
+#elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
     QString path = QDir::homePath() + "/.config/autostart/";
     QDir autostartDir(path);
     if (!autostartDir.exists()) {
-- 
2.28.0


From 4b818982fc484de02d324b579ee15981e5355416 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 6 Dec 2020 00:09:32 +1000
Subject: DBus autostart


diff --git a/src/main.cpp b/src/main.cpp
index 2d44f54..314642f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,6 +30,7 @@
 #include <QTextStream>
 #include <QTimer>
 #include <QTranslator>
+#include <QProcess>
 
 #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
 #include "src/core/flameshotdbusadapter.h"
@@ -48,6 +49,28 @@ int main(int argc, char* argv[])
     // no arguments, just launch Flameshot
     if (argc == 1) {
         SingleApplication app(argc, argv);
+
+#ifdef Q_OS_HAIKU
+		int status=0;
+		QProcess dbusProcess;
+		QString exec = "/bin/dbus-launch";
+		QStringList params;
+		dbusProcess.start(exec, params);
+		dbusProcess.waitForFinished();
+		QString output(dbusProcess.readAllStandardOutput());
+
+		QFile file ("/tmp/flameshot_session");
+		if (file.open(QFile::WriteOnly | QFile::Truncate)) {
+			QTextStream outstream(&file);
+			outstream << output;
+			file.close();
+		}
+
+		QStringList list = output.split("\n", QString::SkipEmptyParts);
+		foreach (const QString &str, list)
+			putenv(str.toLatin1().data());
+#endif
+
         QApplication::setStyle(new StyleOverride);
 
         QTranslator translator, qtTranslator;
@@ -89,10 +112,30 @@ int main(int argc, char* argv[])
         // Exporting captures must be connected after the dbus interface
         // or the dbus signal gets blocked until we end the exports.
         c->enableExports();
+#ifdef Q_OS_HAIKU
+		status = app.exec();
+		system("kill -3 $DBUS_SESSION_BUS_PID");
+		return status;
+#else
         return app.exec();
+#endif
     }
 
 #ifndef Q_OS_WIN
+
+#ifdef Q_OS_HAIKU
+QFile inputFile("/tmp/flameshot_session");
+if (inputFile.open(QIODevice::ReadOnly))
+{
+   QTextStream in(&inputFile);
+   while (!in.atEnd())
+   {
+      QString line = in.readLine();
+      putenv(line.toLatin1().data());
+   }
+   inputFile.close();
+}
+#endif
     /*--------------|
      * CLI parsing  |
      * ------------*/
diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp
index e3eb0e7..fb64d60 100644
--- a/src/utils/filenamehandler.cpp
+++ b/src/utils/filenamehandler.cpp
@@ -25,7 +25,9 @@
 FileNameHandler::FileNameHandler(QObject* parent)
   : QObject(parent)
 {
+#ifndef __HAIKU__
     std::locale::global(std::locale(""));
+#endif
 }
 
 QString FileNameHandler::parsedPattern()
-- 
2.28.0


From 2b60946e9bccb5fa51740ac21021180f74b5b1cf Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 16 Dec 2020 08:53:52 +1000
Subject: Don't use icon from theme


diff --git a/src/core/controller.cpp b/src/core/controller.cpp
index b0cf0b3..07c06ff 100644
--- a/src/core/controller.cpp
+++ b/src/core/controller.cpp
@@ -225,7 +225,7 @@ void Controller::enableTrayIcon()
     m_trayIcon->setToolTip(QStringLiteral("Flameshot"));
     m_trayIcon->setContextMenu(trayIconMenu);
     QIcon trayicon =
-      QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
+      QIcon(":img/app/flameshot.png");
     m_trayIcon->setIcon(trayicon);
 
     auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
-- 
2.28.0


