From 2a1bc97e0d4b2a7dd5cb1b902960b2b2a3fb440a Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 5 May 2020 18:27:33 +1000
Subject: GCi 2019 Task - Aqemu - Add platform specific code to get memory size


diff --git a/src/Add_Port_Window.cpp b/src/Add_Port_Window.cpp
index 116122c..46b8e27 100644
--- a/src/Add_Port_Window.cpp
+++ b/src/Add_Port_Window.cpp
@@ -41,7 +41,11 @@ Add_Port_Window::Add_Port_Window( QWidget *parent )
 	#ifdef Q_OS_WIN32
 	ui.RB_COM->setEnabled( true );
 	#endif
-	
+
+	#ifdef Q_OS_HAIKU
+	ui.RB_stdio->setEnabled(true);
+	#endif
+
 	Connect_Slots();
 }
 
diff --git a/src/System_Info.cpp b/src/System_Info.cpp
index fcbc984..37bc8d7 100644
--- a/src/System_Info.cpp
+++ b/src/System_Info.cpp
@@ -31,6 +31,10 @@
 #include "Utils.h"
 #include "System_Info.h"
 
+#ifdef Q_OS_HAIKU
+#include <OS.h>
+#endif
+
 System_Info::System_Info()
 {
 }
@@ -2098,7 +2102,7 @@ bool System_Info::Delete_From_Used_USB_List( const VM_USB &device )
 	return Used_Host_USB.removeOne( device );
 }
 
-#ifdef Q_OS_LINUX
+#if defined Q_OS_LINUX || defined Q_OS_HAIKU
 
 bool System_Info::Update_Host_USB()
 {
@@ -2503,7 +2507,10 @@ bool System_Info::Scan_USB_Proc( QList<VM_USB> &list )
 	return true;
 }
 
+#ifndef Q_OS_HAIKU
 #include <sys/sysinfo.h>
+#endif
+
 #include <QDir>
 #include <QFileInfoList>
 
@@ -2595,11 +2602,23 @@ void System_Info::Get_Free_Memory_Size( int &allRAM, int &freeRAM )
 	}
 	
 	// If proc fs not exists
+	
+#ifdef Q_OS_HAIKU
+	system_info sysinfo;
+	get_system_info(&sysinfo);
+
+	uint64 tmp;
+	tmp = (sysinfo.max_pages + sysinfo.ignored_pages) * B_PAGE_SIZE;
+	allRAM = (int)(tmp / 1024.0 / 1024.0);
+
+	freeRAM = (int)(sysinfo.free_memory / 1024.0 / 1024.0);
+#else
 	struct sysinfo sysInfo;
 	sysinfo( &sysInfo );
 	
 	allRAM = (int)(unsigned long)(sysInfo.totalram * sysInfo.mem_unit) / 1024.0 / 1024.0;
 	freeRAM  = (int)(unsigned long)((sysInfo.freeram + sysInfo.bufferram) * sysInfo.mem_unit) / 1024.0 / 1024.0;
+#endif
 }
 
 QStringList System_Info::Get_Host_FDD_List()
diff --git a/src/System_Info.h b/src/System_Info.h
index d0e2f35..fe325f7 100644
--- a/src/System_Info.h
+++ b/src/System_Info.h
@@ -59,7 +59,7 @@ class System_Info
 		static QMap<QString, Available_Devices> Emulator_QEMU_2_0;
 
 	private:
-		#ifdef Q_OS_LINUX
+		#if defined Q_OS_LINUX || defined Q_OS_HAIKU
 		static bool Scan_USB_Sys( QList<VM_USB> &list );
 		static bool Scan_USB_Proc( QList<VM_USB> &list );
 		static bool Read_SysFS_File( const QString &path, QString &data );
diff --git a/src/main.cpp b/src/main.cpp
index 40a3c61..ace8799 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -240,7 +240,7 @@ int main( int argc, char *argv[] )
 	// Find Data Folder
 	if( settings.value("AQEMU_Data_Folder", "").toString().isEmpty() )
 	{
-		#ifdef Q_OS_WIN32
+		#if defined Q_OS_WIN32 || defined Q_OS_HAIKU
 		if( QDir(QDir::currentPath() + "\\os_icons").exists() &&
 			QDir(QDir::currentPath() + "\\os_templates").exists() )
 		{
-- 
2.26.0


From a59474bb9427410adf15d0e41348a1e40b526b0e Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 5 May 2020 19:32:10 +1000
Subject: Add Qt to X11 scancode mapper for VNC


diff --git a/src/Embedded_Display/vncview.cpp b/src/Embedded_Display/vncview.cpp
index 8faef72..97527b1 100644
--- a/src/Embedded_Display/vncview.cpp
+++ b/src/Embedded_Display/vncview.cpp
@@ -46,6 +46,116 @@
 #include <QPainter>
 #include <QMouseEvent>
 
+#ifdef Q_OS_HAIKU
+
+static const uint misc_keys[] =
+{
+    XK_Escape,
+    XK_Tab,
+    XK_Tab, //XK_ISO_Left_Tab
+    XK_BackSpace,
+    XK_Return,
+    XK_KP_Enter,
+    XK_Insert,
+    XK_Delete,
+    XK_Pause,
+    XK_Print,
+    XK_Sys_Req,
+    XK_Clear,
+
+    0, 0, 0, 0, // padding
+
+    XK_Home,
+    XK_End,
+    XK_Left,
+    XK_Up,
+    XK_Right,
+    XK_Down,
+    XK_Page_Up,
+    XK_Page_Down,
+
+    0, 0, 0, 0, 0, 0, 0, 0, // padding
+
+    XK_Shift_L,
+    XK_Control_L,
+    XK_Super_L,
+    XK_Alt_L,
+    XK_Caps_Lock,
+    XK_Num_Lock,
+    XK_Scroll_Lock,
+
+    0, 0, 0, 0, 0, 0, 0, 0, 0, // padding
+
+    XK_F1,
+    XK_F2,
+    XK_F3,
+    XK_F4,
+    XK_F5,
+    XK_F6,
+    XK_F7,
+    XK_F8,
+    XK_F9,
+    XK_F10,
+    XK_F11,
+    XK_F12,
+    XK_F13,
+    XK_F14,
+    XK_F15,
+    XK_F16,
+    XK_F17,
+    XK_F18,
+    XK_F19,
+    XK_F20,
+    XK_F21,
+    XK_F22,
+    XK_F23,
+    XK_F24,
+    XK_F25,
+
+    0
+};
+
+static bool capslock_active = false;
+static Qt::KeyboardModifiers mod_last = 0; 
+
+unsigned int map_qt_to_x11(QKeyEvent *e)
+{
+    int k = e->key();
+    bool pressed = (e->type() == QEvent::KeyPress);
+    Qt::KeyboardModifiers mod = e->modifiers();
+    Qt::KeyboardModifiers modXor = mod ^ mod_last;
+    mod_last = mod;
+
+    if (k >= XK_space && k <= XK_ydiaeresis)
+    {
+        #define XOR(a, b) (!(a && b) && (a || b))
+
+        // check if lowercase ascii
+        if ((k >= XK_A && k <= XK_Z
+        ||   k >= XK_Agrave && k <= XK_Thorn)
+        && !(XOR(mod & Qt::ShiftModifier, capslock_active)))
+            return k + 0x20;
+
+        #undef XOR
+		qDebug() << k;
+        return k;
+    }
+
+    if (k >= 0x01000000 && k <= 0x01000048) {  	
+        return misc_keys[k - 0x01000000];
+    }
+	
+	if (modXor & Qt::ShiftModifier)
+		return XK_Shift_L;
+	if (modXor & Qt::ControlModifier)
+		return XK_Control_L;
+	if (modXor & Qt::AltModifier)
+		return XK_Alt_L;
+
+    return 0;
+}
+#endif
+
 // Definition of key modifier mask constants
 #define KMOD_Alt_R 	0x01
 #define KMOD_Alt_L 	0x02
@@ -579,7 +689,11 @@ void VncView::keyEventHandler(QKeyEvent *e)
         return;
 
 // parts of this code are based on http://italc.sourcearchive.com/documentation/1.0.9.1/vncview_8cpp-source.html
+#ifdef Q_OS_HAIKU
+	rfbKeySym k = map_qt_to_x11(e);
+#else
     rfbKeySym k = e->nativeVirtualKey();
+#endif
 
     // we do not handle Key_Backtab separately as the Shift-modifier
     // is already enabled
-- 
2.26.0


From 36a868b0e5ad16da18f0bb8f4fa0f077a0bdc228 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 5 May 2020 20:49:18 +1000
Subject: Use application dir as data dir


diff --git a/src/main.cpp b/src/main.cpp
index ace8799..ef05043 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -240,7 +240,7 @@ int main( int argc, char *argv[] )
 	// Find Data Folder
 	if( settings.value("AQEMU_Data_Folder", "").toString().isEmpty() )
 	{
-		#if defined Q_OS_WIN32 || defined Q_OS_HAIKU
+		#ifdef Q_OS_WIN32
 		if( QDir(QDir::currentPath() + "\\os_icons").exists() &&
 			QDir(QDir::currentPath() + "\\os_templates").exists() )
 		{
@@ -257,6 +257,9 @@ int main( int argc, char *argv[] )
 		dataDirs << "/usr/share/aqemu/"
 				 << "/usr/share/apps/aqemu/"
 				 << "/usr/local/share/aqemu/";
+#ifdef Q_OS_HAIKU
+		dataDirs << QCoreApplication::applicationDirPath() + "/";
+#endif
 		
 		// Find data dir
 		for( int dx = 0; dx < dataDirs.count(); ++dx )
-- 
2.26.0


From 99cb71d549f8be8ae0da5c76cde581de48078da7 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 23 May 2020 22:26:07 +1000
Subject: Fix widget name conflict


diff --git a/src/Advanced_Settings_Window.ui b/src/Advanced_Settings_Window.ui
index c3c0faf..c06fdf2 100644
--- a/src/Advanced_Settings_Window.ui
+++ b/src/Advanced_Settings_Window.ui
@@ -2177,7 +2177,7 @@ with embedded display</string>
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout_26">
             <item>
-             <widget class="QWidget" name="widget_2" native="true">
+             <widget class="QWidget" name="widget_1" native="true">
               <layout class="QVBoxLayout" name="verticalLayout_19">
                <property name="leftMargin">
                 <number>10</number>
@@ -2220,7 +2220,7 @@ Supports only USB &amp;1.1 controller emulation.</string>
            </property>
            <layout class="QHBoxLayout" name="horizontalLayout_25">
             <item>
-             <widget class="QWidget" name="widget" native="true">
+             <widget class="QWidget" name="widget_2" native="true">
               <layout class="QVBoxLayout" name="verticalLayout_16">
                <property name="leftMargin">
                 <number>10</number>
diff --git a/src/Main_Window.ui b/src/Main_Window.ui
index 550f6e2..a642b78 100644
--- a/src/Main_Window.ui
+++ b/src/Main_Window.ui
@@ -226,7 +226,7 @@
              </widget>
             </item>
             <item>
-             <widget class="QWidget" name="widget" native="true">
+             <widget class="QWidget" name="widget_0" native="true">
               <layout class="QGridLayout" name="gridLayout_12">
                <property name="leftMargin">
                 <number>24</number>
@@ -2493,7 +2493,7 @@
                     </layout>
                    </item>
                    <item row="1" column="0" colspan="2">
-                    <widget class="QWidget" name="widget" native="true">
+                    <widget class="QWidget" name="widget_1" native="true">
                      <layout class="QHBoxLayout" name="Widget_Redirection_Protocol">
                       <property name="spacing">
                        <number>6</number>
@@ -2551,7 +2551,7 @@
                     </widget>
                    </item>
                    <item row="2" column="0" colspan="2">
-                    <widget class="QWidget" name="widget" native="true">
+                    <widget class="QWidget" name="widget_2" native="true">
                      <layout class="QHBoxLayout" name="Widget_Redirection_Net">
                       <property name="spacing">
                        <number>6</number>
diff --git a/src/SPICE_Settings_Widget.ui b/src/SPICE_Settings_Widget.ui
index 3cf1a6e..bb1e339 100644
--- a/src/SPICE_Settings_Widget.ui
+++ b/src/SPICE_Settings_Widget.ui
@@ -95,7 +95,7 @@
            <number>0</number>
           </property>
           <item>
-           <widget class="QGroupBox" name="groupBox">
+           <widget class="QGroupBox" name="groupBox_0">
             <property name="title">
              <string>Network</string>
             </property>
@@ -209,7 +209,7 @@
            </widget>
           </item>
           <item>
-           <widget class="QGroupBox" name="groupBox">
+           <widget class="QGroupBox" name="groupBox_1">
             <property name="title">
              <string>Image, Video and Audio</string>
             </property>
@@ -387,7 +387,7 @@
            </widget>
           </item>
           <item>
-           <widget class="QGroupBox" name="groupBox">
+           <widget class="QGroupBox" name="groupBox_2">
             <property name="title">
              <string>Security</string>
             </property>
-- 
2.26.0

