]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/profile.cpp
QString no longer supports toAscii, use toUtf8 instead
[virtualjaguar] / src / gui / profile.cpp
index 114b98c9059cb59e520a08fb87de1c2897a9286f..484d4b4f8e79f01d07b837d5661c432cd0d2b99e 100644 (file)
@@ -30,7 +30,6 @@
 //
 
 #include "profile.h"
-#include <QtGui>
 #include "gamepad.h"
 #include "log.h"
 #include "settings.h"
@@ -49,6 +48,7 @@ int gamepadIDSlot2;
 int numberOfProfiles;
 int numberOfDevices;
 char deviceNames[MAX_DEVICES][128];
+static int numberOfProfilesSave;
 
 // This is so that new devices have something reasonable to show for default
 uint32_t defaultMap[21] = {
@@ -68,6 +68,7 @@ int FindProfileForDevice(int deviceNum, int preferred, int * found);
 //
 void SaveProfiles(void)
 {
+       numberOfProfilesSave = numberOfProfiles;
        memcpy(&profileBackup, &profile, sizeof(Profile) * MAX_PROFILES);
 }
 
@@ -75,6 +76,7 @@ void SaveProfiles(void)
 void RestoreProfiles(void)
 {
        memcpy(&profile, &profileBackup, sizeof(Profile) * MAX_PROFILES);
+       numberOfProfiles = numberOfProfilesSave;
 }
 
 
@@ -94,7 +96,7 @@ void ReadProfiles(QSettings * set)
        for(int i=1; i<numberOfDevices; i++)
        {
                set->setArrayIndex(i - 1);
-               strcpy(deviceNames[i], set->value("deviceName").toString().toAscii().data());
+               strcpy(deviceNames[i], set->value("deviceName").toString().toUtf8().data());
 #ifdef DEBUG_PROFILES
 printf("Read device name: %s\n", deviceNames[i]);
 #endif
@@ -110,7 +112,7 @@ printf("Number of profiles: %u\n", numberOfProfiles);
        {
                set->setArrayIndex(i);
                profile[i].device = set->value("deviceNum").toInt();
-               strcpy(profile[i].mapName, set->value("mapName").toString().toAscii().data());
+               strcpy(profile[i].mapName, set->value("mapName").toString().toUtf8().data());
                profile[i].preferredSlot = set->value("preferredSlot").toInt();
 
                for(int j=0; j<21; j++)
@@ -357,15 +359,20 @@ One more stab at this...
 */
 void AutoConnectProfiles(void)
 {
-       int foundProfiles[MAX_PROFILES];
+//     int foundProfiles[MAX_PROFILES];
        controller1Profile = -1;
        controller2Profile = -1;
        gamepadIDSlot1 = -1;
        gamepadIDSlot2 = -1;
 
-       // Connect keyboard devices first... (N.B.: this leaves gampadIDSlot1 at -1,
-       // so it can be overridden by plugged-in gamepads.)
-       ConnectProfileToDevice(0);
+       // Connect the keyboard automagically only if no gamepads are plugged in.
+       // Otherwise, check after all other devices have been checked, then try to
+       // add it in.
+       if (Gamepad::numJoysticks == 0)
+       {
+               ConnectProfileToDevice(0);
+               return;
+       }
 
        // Connect the profiles that prefer a slot, if any.
        // N.B.: Conflicts are detected, but ignored. 1st controller to grab a
@@ -437,6 +444,23 @@ void AutoConnectProfiles(void)
                }
        }
 
+       // Connect the keyboard device (lowest priority)
+       // N.B.: The keyboard is always mapped to profile #0, so we can locate it
+       //       easily. :-)
+       int slot = profile[0].preferredSlot;
+
+       if ((slot == CONTROLLER1) && (gamepadIDSlot1 == -1))
+               controller1Profile = 0;
+       else if ((slot == CONTROLLER2) && (gamepadIDSlot2 == -1))
+               controller2Profile = 0;
+       else if (slot == (CONTROLLER1 | CONTROLLER2))
+       {
+               if (gamepadIDSlot1 == -1)
+                       controller1Profile = 0;
+               else if (gamepadIDSlot2 == -1)
+                       controller2Profile = 0;
+       }
+
        // Finally, attempt to connect profiles to controllers
        ConnectProfileToController(controller1Profile, 0);
        ConnectProfileToController(controller2Profile, 1);