28 class Daemon : public QObject, public QDBusContext { |
28 class Daemon : public QObject, public QDBusContext { |
29 Q_OBJECT; |
29 Q_OBJECT; |
30 |
30 |
31 private: |
31 private: |
32 |
32 |
33 HIDDevice getMouse() { |
33 static unsigned short const VENDOR_ID = 0x256f; |
34 return HIDDevice(VENDOR_ID, PRODUCT_ID, nullptr); |
34 static unsigned short const PRODUCT_ID_WIRELESS = 0xc652; |
35 } |
35 static unsigned short const PRODUCT_ID_WIRED = 0xc656; |
36 |
36 |
37 void logException(const HIDException& e) { |
37 void logException(const HIDException& e) { |
38 std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
38 std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
39 } |
39 } |
40 public: |
40 public: |
41 |
41 |
42 static unsigned short const VENDOR_ID = 0x256f; |
42 Daemon(QObject* parent = nullptr) : QObject(parent) { |
43 static unsigned short const PRODUCT_ID = 0xc652; |
43 } |
44 |
44 |
45 Daemon(QObject* parent = nullptr) : QObject(parent) { |
45 static HIDDevice getMouse() { |
|
46 // TODO: multiple mouse support, better mouse selection, specific settings for particular type… |
|
47 // (probably after future redesign/rewrite – this is just a simple tool written for 3DConnexion CadMouse Pro) |
|
48 std::vector<HIDDeviceInfo> devices = HIDDeviceInfo::enumerate(); |
|
49 for (auto pid :{PRODUCT_ID_WIRELESS, PRODUCT_ID_WIRED}) { |
|
50 for (HIDDeviceInfo device : devices) { |
|
51 if (device.matches(VENDOR_ID, pid)) return device.open(); |
|
52 } |
|
53 } |
|
54 throw HIDException(L"No suitable mouse found."); |
46 } |
55 } |
47 |
56 |
48 Q_PROPERTY(bool devicePresent READ devicePresent) |
57 Q_PROPERTY(bool devicePresent READ devicePresent) |
49 bool devicePresent() { |
58 bool devicePresent() { |
50 std::wcout << L"checking mouse presence: "; |
59 std::wcout << L"checking mouse presence: "; |