From 091c2860bf117fa761048d539a9a3c354980e772 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 15 May 2020 20:51:12 +1000
Subject: Fixes for Haiku


diff --git a/src/common.cpp b/src/common.cpp
index 3ffdb7c..5f6e561 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -393,7 +393,7 @@ bool romSorter(const Rom &firstRom, const Rom &lastRom)
 {
     QString sort, direction;
 
-    QString layout = SETTINGS.value("View/layout", "None").toString();
+    QString layout = SETTINGS.value("View/layout", "grid").toString();
     if (layout == "grid") {
         sort = SETTINGS.value("Grid/sort", "Filename").toString();
         direction = SETTINGS.value("Grid/sortdirection", "ascending").toString();
diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp
index 2ef4586..54eb80b 100644
--- a/src/dialogs/settingsdialog.cpp
+++ b/src/dialogs/settingsdialog.cpp
@@ -184,7 +184,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, int activeTab) : QDialog(parent)
           << (QStringList() << tr("Super")       << "Super");
 
 
-    if (SETTINGS.value("Other/downloadinfo", "").toString() == "true")
+    if (SETTINGS.value("Other/downloadinfo", "true").toString() == "true")
         populateTableAndListTab(true);
     else
         populateTableAndListTab(false);
@@ -370,13 +370,13 @@ SettingsDialog::SettingsDialog(QWidget *parent, int activeTab) : QDialog(parent)
                    << ui->listSizeLabel
                    << ui->listSizeBox;
 
-    if (SETTINGS.value("Other/downloadinfo", "").toString() == "true") {
+    if (SETTINGS.value("Other/downloadinfo", "true").toString() == "true") {
         toggleDownload(true);
         ui->downloadOption->setChecked(true);
     } else
         toggleDownload(false);
 
-    if (SETTINGS.value("saveoptions", "").toString() == "true")
+    if (SETTINGS.value("saveoptions", "true").toString() == "true")
         ui->saveOption->setChecked(true);
 
     ui->parametersLine->setText(SETTINGS.value("Other/parameters", "").toString());
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0915a5a..132f175 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -64,7 +64,7 @@
 #include <QTimer>
 #include <QVBoxLayout>
 
-#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
+#if defined(Q_OS_WIN) || defined(Q_OS_OSX) || defined(Q_OS_HAIKU)
 #include <QCoreApplication>
 #endif
 
@@ -123,7 +123,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
 
 void MainWindow::addToView(Rom *currentRom, int count)
 {
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     if (visibleLayout == "table")
         tableView->addToTableView(currentRom);
@@ -202,6 +202,16 @@ void MainWindow::autoloadSettings()
             SETTINGS.setValue("Paths/data", mupen64App+"/Resources");
         }
 #endif
+
+#ifdef Q_OS_HAIKU
+        QString currentDir = QCoreApplication::applicationDirPath();
+        if (QFileInfo(currentDir+"/bin/Mupen64Plus").exists()) {
+            SETTINGS.setValue("Paths/mupen64plus", currentDir+"/bin/Mupen64Plus");
+            SETTINGS.setValue("Paths/plugins", currentDir+"/plugins");
+            SETTINGS.setValue("Paths/data", currentDir+"/data");
+        }
+#endif
+
     }
 
     checkConfigLocation();
@@ -218,6 +228,8 @@ void MainWindow::checkConfigLocation()
 
 #ifdef Q_OS_WIN
         QString configCheck = homeDir + "/AppData/Roaming/Mupen64Plus/";
+#elif defined(Q_OS_HAIKU)
+		QString configCheck = homeDir + "/config/settings/Mupen64Plus/";
 #else
         QString configCheck = homeDir + "/.config/mupen64plus";
 #endif
@@ -329,7 +341,7 @@ void MainWindow::createMenu()
             << (QStringList() << tr("Grid View")  << "grid")
             << (QStringList() << tr("List View")  << "list");
 
-    QString layoutValue = SETTINGS.value("View/layout", "none").toString();
+    QString layoutValue = SETTINGS.value("View/layout", "grid").toString();
 
     foreach (QStringList layoutName, layouts)
     {
@@ -478,7 +490,7 @@ void MainWindow::disableButtons()
 
 void MainWindow::disableViews(bool imageUpdated)
 {
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     //Save position in current layout
     if (visibleLayout == "table")
@@ -508,7 +520,7 @@ void MainWindow::enableButtons()
 
 void MainWindow::enableViews(int romCount, bool cached)
 {
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     if (romCount != 0) { //else no ROMs, so leave views disabled
         QStringList tableVisible = SETTINGS.value("Table/columns", "Filename|Size").toString().split("|");
@@ -608,7 +620,7 @@ bool MainWindow::eventFilter(QObject*, QEvent *event)
 
 QString MainWindow::getCurrentRomInfoFromView(QString infoName)
 {
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     if (visibleLayout == "table")
         return tableView->getCurrentRomInfo(infoName);
@@ -875,7 +887,7 @@ void MainWindow::resetLayouts(bool imageUpdated)
 
 void MainWindow::showActiveView()
 {
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     if (visibleLayout == "table")
         tableView->setHidden(false);
@@ -918,7 +930,7 @@ void MainWindow::showRomMenu(const QPoint &pos)
 
 
     QWidget *activeWidget = new QWidget(this);
-    QString visibleLayout = SETTINGS.value("View/layout", "none").toString();
+    QString visibleLayout = SETTINGS.value("View/layout", "grid").toString();
 
     if (visibleLayout == "table")
         activeWidget = tableView->viewport();
-- 
2.26.0

