Skip to content
This repository
Browse code

Merge pull request #1536 from Karlson2k/Imon_addition_01

Replace system-wide iMON setting with per-device setting
  • Loading branch information...
commit 6671312465caf64feb5240ddd0ec2ccd9bdc780d 2 parents 0630b59 + 4c21c6c
davilla authored December 13, 2012
10  language/English/strings.po
@@ -11224,12 +11224,14 @@ msgctxt "#35100"
11224 11224
 msgid "Enable joystick and gamepad support"
11225 11225
 msgstr ""
11226 11226
 
11227  
-#: xbmc/settings/GUISettings.cpp
11228  
-msgctxt "#35101"
11229  
-msgid "Disable joystick when iMON is present"
  11227
+#empty string with id 35101
  11228
+
  11229
+#: system/peripherals.xml
  11230
+msgctxt "#35102"
  11231
+msgid "Disable joystick when device is present"
11230 11232
 msgstr ""
11231 11233
 
11232  
-#empty strings from id 35102 to 35499
  11234
+#empty strings from id 35103 to 35499
11233 11235
 
11234 11236
 msgctxt "#35500"
11235 11237
 msgid "Location"
3  system/peripherals.xml
@@ -57,6 +57,7 @@
57 57
   </peripheral>
58 58
 
59 59
   <peripheral vendor_product="15C2:32,15C2:33,15C2:34,15C2:35,15C2:36,15C2:37,15C2:38,15C2:39,15C2:3A,15C2:3B,15C2:3C,15C2:3D,15C2:3E,15C2:3F,15C2:41,15C2:42,15C2:43,15C2:44,15C2:45,15C2:46" bus="usb" name="iMON HID device" mapTo="imon">
60  
-    <setting key="do_not_use_custom_keymap" type="bool" value="1" label="35009" order="1" configurable="0"/>
  60
+    <setting key="do_not_use_custom_keymap" type="bool" value="1" label="35009" configurable="0"/>
  61
+    <setting key="disable_winjoystick" type="bool" value="1" label="35102" order="1" />
61 62
   </peripheral>
62 63
 </peripherals>
2  xbmc/Application.cpp
@@ -1396,7 +1396,7 @@ bool CApplication::Initialize()
1396 1396
 
1397 1397
 #ifdef HAS_SDL_JOYSTICK
1398 1398
   g_Joystick.SetEnabled(g_guiSettings.GetBool("input.enablejoystick") &&
1399  
-                    (CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0 || !g_guiSettings.GetBool("input.disablejoystickwithimon")) );
  1399
+                    CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0 );
1400 1400
 #endif
1401 1401
 
1402 1402
   return true;
61  xbmc/peripherals/devices/PeripheralImon.cpp
@@ -34,26 +34,21 @@
34 34
 using namespace PERIPHERALS;
35 35
 using namespace std;
36 36
 
37  
-volatile long CPeripheralImon::m_CountOfImonsConflictWithDInput = 0;
  37
+volatile long CPeripheralImon::m_lCountOfImonsConflictWithDInput = 0;
38 38
 
39 39
 
40 40
 CPeripheralImon::CPeripheralImon(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId) :
41 41
   CPeripheralHID(type, busType, strLocation, strDeviceName.IsEmpty() ? g_localizeStrings.Get(35001) : strDeviceName, iVendorId, iProductId)
42 42
 {
43 43
   m_features.push_back(FEATURE_IMON);
44  
-#if defined(TARGET_WINDOWS)
45  
-  if (iProductId >= 0x34 && iProductId <= 0x46)
46  
-    m_ImonConflictsWithDInput = true;
47  
-  else 
48  
-#endif // TARGET_WINDOWS
49  
-    m_ImonConflictsWithDInput = false;
  44
+  m_bImonConflictsWithDInput = false;
50 45
 }
51 46
 
52 47
 void CPeripheralImon::OnDeviceRemoved()
53 48
 {
54  
-  if (m_ImonConflictsWithDInput)
  49
+  if (m_bImonConflictsWithDInput)
55 50
   {
56  
-    if (AtomicDecrement(&m_CountOfImonsConflictWithDInput) == 0)
  51
+    if (AtomicDecrement(&m_lCountOfImonsConflictWithDInput) == 0)
57 52
       ActionOnImonConflict(false);    
58 53
   }
59 54
 }
@@ -62,9 +57,16 @@ bool CPeripheralImon::InitialiseFeature(const PeripheralFeature feature)
62 57
 {
63 58
   if (feature == FEATURE_IMON)
64 59
   {
65  
-    if (m_ImonConflictsWithDInput)
  60
+#if defined(TARGET_WINDOWS)
  61
+    if (HasSetting("disable_winjoystick") && GetSettingBool("disable_winjoystick"))
  62
+      m_bImonConflictsWithDInput = true;
  63
+    else 
  64
+#endif // TARGET_WINDOWS
  65
+      m_bImonConflictsWithDInput = false;
  66
+
  67
+    if (m_bImonConflictsWithDInput)
66 68
     {
67  
-      AtomicIncrement(&m_CountOfImonsConflictWithDInput);
  69
+      AtomicIncrement(&m_lCountOfImonsConflictWithDInput);
68 70
       ActionOnImonConflict(true);
69 71
     }
70 72
     return CPeripheral::InitialiseFeature(feature);
@@ -73,19 +75,42 @@ bool CPeripheralImon::InitialiseFeature(const PeripheralFeature feature)
73 75
   return CPeripheralHID::InitialiseFeature(feature);
74 76
 }
75 77
 
  78
+void CPeripheralImon::AddSetting(const CStdString &strKey, const CSetting *setting)
  79
+{
  80
+#if !defined(TARGET_WINDOWS)
  81
+  if (strKey.compare("disable_winjoystick")!=0)
  82
+#endif // !TARGET_WINDOWS
  83
+    CPeripheralHID::AddSetting(strKey, setting);
  84
+}
  85
+
  86
+void CPeripheralImon::OnSettingChanged(const CStdString &strChangedSetting)
  87
+{
  88
+  if (strChangedSetting.compare("disable_winjoystick") == 0)
  89
+  {
  90
+    if (m_bImonConflictsWithDInput && !GetSettingBool("disable_winjoystick"))
  91
+    {
  92
+      m_bImonConflictsWithDInput = false;
  93
+      if (AtomicDecrement(&m_lCountOfImonsConflictWithDInput) == 0)
  94
+        ActionOnImonConflict(false);
  95
+    }
  96
+    else if(!m_bImonConflictsWithDInput && GetSettingBool("disable_winjoystick"))
  97
+    {
  98
+      m_bImonConflictsWithDInput = true;
  99
+      AtomicIncrement(&m_lCountOfImonsConflictWithDInput);
  100
+      ActionOnImonConflict(true);
  101
+    }
  102
+  }
  103
+}
  104
+
76 105
 void CPeripheralImon::ActionOnImonConflict(bool deviceInserted /*= true*/)
77 106
 {
78  
-  if (deviceInserted || m_CountOfImonsConflictWithDInput == 0)
  107
+  if (deviceInserted || m_lCountOfImonsConflictWithDInput == 0)
79 108
   {
80  
-#if defined(TARGET_WINDOWS) && defined (HAS_SDL_JOYSTICK)
81  
-    bool enableJoystickNow = (!deviceInserted || !g_guiSettings.GetBool("input.disablejoystickwithimon")) 
82  
-        && g_guiSettings.GetBool("input.enablejoystick");
  109
+#if defined(TARGET_WINDOWS) && defined(HAS_SDL_JOYSTICK)
  110
+    bool enableJoystickNow = !deviceInserted && g_guiSettings.GetBool("input.enablejoystick");
83 111
     CLog::Log(LOGNOTICE, "Problematic iMON hardware %s. Joystick usage: %s", (deviceInserted ? "detected" : "was removed"),
84 112
         (enableJoystickNow) ? "enabled." : "disabled." );
85 113
     g_Joystick.SetEnabled(enableJoystickNow);
86  
-    CSetting* setting = g_guiSettings.GetSetting("input.disablejoystickwithimon");
87  
-    if(setting)
88  
-      setting->SetVisible(deviceInserted && !setting->IsAdvanced());
89 114
 #endif
90 115
   }
91 116
 }
11  xbmc/peripherals/devices/PeripheralImon.h
@@ -29,14 +29,17 @@ namespace PERIPHERALS
29 29
     CPeripheralImon(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
30 30
     virtual ~CPeripheralImon(void) {}
31 31
     virtual bool InitialiseFeature(const PeripheralFeature feature);
  32
+    virtual void OnSettingChanged(const CStdString &strChangedSetting);
32 33
     virtual void OnDeviceRemoved();
  34
+    virtual void AddSetting(const CStdString &strKey, const CSetting *setting);
33 35
     inline bool IsImonConflictsWithDInput() 
34  
-    { return m_ImonConflictsWithDInput;}
  36
+    { return m_bImonConflictsWithDInput;}
35 37
     static inline long GetCountOfImonsConflictWithDInput()
36  
-    { return m_CountOfImonsConflictWithDInput; }
  38
+    { return m_lCountOfImonsConflictWithDInput; }
37 39
     static void ActionOnImonConflict(bool deviceInserted = true);
  40
+
38 41
   private:
39  
-    bool m_ImonConflictsWithDInput;
40  
-    static volatile long m_CountOfImonsConflictWithDInput;
  42
+    bool m_bImonConflictsWithDInput;
  43
+    static volatile long m_lCountOfImonsConflictWithDInput;
41 44
   };
42 45
 }
2  xbmc/settings/GUISettings.cpp
@@ -545,8 +545,6 @@ void CGUISettings::Initialize()
545 545
 #endif
546 546
 #if defined(HAS_SDL_JOYSTICK)
547 547
   AddBool(in, "input.enablejoystick", 35100, true);
548  
-  AddBool(in, "input.disablejoystickwithimon", 35101, true);
549  
-  GetSetting("input.disablejoystickwithimon")->SetVisible(false);
550 548
 #endif
551 549
 
552 550
   CSettingsCategory* net = AddCategory(SETTINGS_SYSTEM, "network", 798);
12  xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -1016,6 +1016,12 @@ void CGUIWindowSettingsCategory::UpdateSettings()
1016 1016
       if (pControl)
1017 1017
         pControl->SetEnabled(g_peripherals.GetNumberOfPeripherals() > 0);
1018 1018
     }
  1019
+    else if (strSetting.Equals("input.enablejoystick"))
  1020
+    {
  1021
+      CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
  1022
+      if (pControl)
  1023
+        pControl->SetEnabled(CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0);
  1024
+    }
1019 1025
   }
1020 1026
 
1021 1027
   g_guiSettings.SetChanged();
@@ -1061,6 +1067,8 @@ void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
1061 1067
     CGUIDialogPeripheralManager *dialog = (CGUIDialogPeripheralManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_MANAGER);
1062 1068
     if (dialog)
1063 1069
       dialog->DoModal();
  1070
+    // refresh settings
  1071
+    UpdateSettings();
1064 1072
     return;
1065 1073
   }
1066 1074
 
@@ -1442,11 +1450,11 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
1442 1450
   {
1443 1451
     g_Mouse.SetEnabled(g_guiSettings.GetBool("input.enablemouse"));
1444 1452
   }
1445  
-  else if (strSetting.Equals("input.enablejoystick") || strSetting.Equals("input.disablejoystickwithimon"))
  1453
+  else if (strSetting.Equals("input.enablejoystick"))
1446 1454
   {
1447 1455
 #if defined(HAS_SDL_JOYSTICK)
1448 1456
     g_Joystick.SetEnabled(g_guiSettings.GetBool("input.enablejoystick")  
1449  
-        && (CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0 || !g_guiSettings.GetBool("input.disablejoystickwithimon")) );
  1457
+        && CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0);
1450 1458
 #endif
1451 1459
   }
1452 1460
   else if (strSetting.Equals("videoscreen.screen"))

0 notes on commit 6671312

Please sign in to comment.
Something went wrong with that request. Please try again.