[cstdstring] demise Format, replacing with StringUtils::Format
[vuplus_xbmc] / xbmc / peripherals / devices / PeripheralHID.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "PeripheralHID.h"
22 #include "utils/log.h"
23 #include "guilib/LocalizeStrings.h"
24 #include "input/ButtonTranslator.h"
25
26 using namespace PERIPHERALS;
27 using namespace std;
28
29 CPeripheralHID::CPeripheralHID(const PeripheralScanResult& scanResult) :
30   CPeripheral(scanResult),
31   m_bInitialised(false)
32 {
33   m_strDeviceName = scanResult.m_strDeviceName.IsEmpty() ? g_localizeStrings.Get(35001) : scanResult.m_strDeviceName;
34   m_features.push_back(FEATURE_HID);
35 }
36
37 CPeripheralHID::~CPeripheralHID(void)
38 {
39   if (!m_strKeymap.IsEmpty() && !GetSettingBool("do_not_use_custom_keymap"))
40   {
41     CLog::Log(LOGDEBUG, "%s - switching active keymapping to: default", __FUNCTION__);
42     CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
43   }
44 }
45
46 bool CPeripheralHID::InitialiseFeature(const PeripheralFeature feature)
47 {
48   if (feature == FEATURE_HID && !m_bInitialised)
49   {
50     m_bInitialised = true;
51
52     if (HasSetting("keymap"))
53       m_strKeymap = GetSettingString("keymap");
54
55     if (m_strKeymap.IsEmpty())
56     {
57       m_strKeymap = StringUtils::Format("v%sp%s", VendorIdAsString(), ProductIdAsString());
58       SetSetting("keymap", m_strKeymap);
59     }
60
61     if (!IsSettingVisible("keymap"))
62       SetSettingVisible("do_not_use_custom_keymap", false);
63
64     if (!m_strKeymap.IsEmpty())
65     {
66       bool bKeymapEnabled(!GetSettingBool("do_not_use_custom_keymap"));
67       if (bKeymapEnabled)
68       {
69         CLog::Log(LOGDEBUG, "%s - adding keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
70         CButtonTranslator::GetInstance().AddDevice(m_strKeymap);
71       }
72       else if (!bKeymapEnabled)
73       {
74         CLog::Log(LOGDEBUG, "%s - removing keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
75         CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
76       }
77     }
78
79     CLog::Log(LOGDEBUG, "%s - initialised HID device (%s:%s)", __FUNCTION__, m_strVendorId.c_str(), m_strProductId.c_str());
80   }
81
82   return CPeripheral::InitialiseFeature(feature);
83 }
84
85 void CPeripheralHID::OnSettingChanged(const CStdString &strChangedSetting)
86 {
87   if (m_bInitialised && ((strChangedSetting.Equals("keymap") && !GetSettingBool("do_not_use_custom_keymap")) || strChangedSetting.Equals("keymap_enabled")))
88   {
89     m_bInitialised = false;
90     InitialiseFeature(FEATURE_HID);
91   }
92 }
93