-
Notifications
You must be signed in to change notification settings - Fork 0
/
ButtonTranslator.cpp
1768 lines (1607 loc) · 65 KB
/
ButtonTranslator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h"
#include "interfaces/Builtins.h"
#include "ButtonTranslator.h"
#include "profiles/ProfilesManager.h"
#include "utils/URIUtils.h"
#include "input/Key.h"
#include "guilib/WindowIDs.h"
#include "input/MouseStat.h"
#include "input/XBMC_keysym.h"
#include "input/XBMC_keytable.h"
#include "filesystem/File.h"
#include "filesystem/Directory.h"
#include "FileItem.h"
#include "utils/StringUtils.h"
#include "utils/log.h"
#include "utils/XBMCTinyXML.h"
#include "utils/RegExp.h"
#include "XBIRRemote.h"
#include "Util.h"
#include <algorithm>
#if defined(TARGET_WINDOWS)
#include "input/windows/WINJoystick.h"
#elif defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
#include "SDLJoystick.h"
#endif
#define JOYSTICK_DEFAULT_MAP "_xbmc_"
using namespace std;
using namespace XFILE;
typedef struct
{
const char* name;
int action;
} ActionMapping;
typedef struct
{
int origin;
int target;
} WindowMapping;
static const ActionMapping actions[] =
{
{"left" , ACTION_MOVE_LEFT },
{"right" , ACTION_MOVE_RIGHT},
{"up" , ACTION_MOVE_UP },
{"down" , ACTION_MOVE_DOWN },
{"pageup" , ACTION_PAGE_UP },
{"pagedown" , ACTION_PAGE_DOWN},
{"select" , ACTION_SELECT_ITEM},
{"highlight" , ACTION_HIGHLIGHT_ITEM},
{"parentdir" , ACTION_NAV_BACK}, // backward compatibility
{"parentfolder" , ACTION_PARENT_DIR},
//{"back" , ACTION_NAV_BACK},
{"previousmenu" , ACTION_PREVIOUS_MENU},
{"info" , ACTION_SHOW_INFO},
{"pause" , ACTION_PAUSE},
{"stop" , ACTION_STOP},
{"skipnext" , ACTION_NEXT_ITEM},
{"skipprevious" , ACTION_PREV_ITEM},
{"fullscreen" , ACTION_SHOW_GUI},
{"aspectratio" , ACTION_ASPECT_RATIO},
{"stepforward" , ACTION_STEP_FORWARD},
{"stepback" , ACTION_STEP_BACK},
{"bigstepforward" , ACTION_BIG_STEP_FORWARD},
{"bigstepback" , ACTION_BIG_STEP_BACK},
{"chapterorbigstepforward", ACTION_CHAPTER_OR_BIG_STEP_FORWARD},
{"chapterorbigstepback" , ACTION_CHAPTER_OR_BIG_STEP_BACK},
{"osd" , ACTION_SHOW_OSD},
{"showsubtitles" , ACTION_SHOW_SUBTITLES},
{"nextsubtitle" , ACTION_NEXT_SUBTITLE},
{"cyclesubtitle" , ACTION_CYCLE_SUBTITLE},
{"codecinfo" , ACTION_SHOW_CODEC},
{"nextpicture" , ACTION_NEXT_PICTURE},
{"previouspicture" , ACTION_PREV_PICTURE},
{"zoomout" , ACTION_ZOOM_OUT},
{"zoomin" , ACTION_ZOOM_IN},
{"playlist" , ACTION_SHOW_PLAYLIST},
{"queue" , ACTION_QUEUE_ITEM},
{"zoomnormal" , ACTION_ZOOM_LEVEL_NORMAL},
{"zoomlevel1" , ACTION_ZOOM_LEVEL_1},
{"zoomlevel2" , ACTION_ZOOM_LEVEL_2},
{"zoomlevel3" , ACTION_ZOOM_LEVEL_3},
{"zoomlevel4" , ACTION_ZOOM_LEVEL_4},
{"zoomlevel5" , ACTION_ZOOM_LEVEL_5},
{"zoomlevel6" , ACTION_ZOOM_LEVEL_6},
{"zoomlevel7" , ACTION_ZOOM_LEVEL_7},
{"zoomlevel8" , ACTION_ZOOM_LEVEL_8},
{"zoomlevel9" , ACTION_ZOOM_LEVEL_9},
{"nextcalibration" , ACTION_CALIBRATE_SWAP_ARROWS},
{"resetcalibration" , ACTION_CALIBRATE_RESET},
{"analogmove" , ACTION_ANALOG_MOVE},
{"analogmovex" , ACTION_ANALOG_MOVE_X},
{"analogmovey" , ACTION_ANALOG_MOVE_Y},
{"rotate" , ACTION_ROTATE_PICTURE_CW},
{"rotateccw" , ACTION_ROTATE_PICTURE_CCW},
{"close" , ACTION_NAV_BACK}, // backwards compatibility
{"subtitledelayminus", ACTION_SUBTITLE_DELAY_MIN},
{"subtitledelay" , ACTION_SUBTITLE_DELAY},
{"subtitledelayplus" , ACTION_SUBTITLE_DELAY_PLUS},
{"audiodelayminus" , ACTION_AUDIO_DELAY_MIN},
{"audiodelay" , ACTION_AUDIO_DELAY},
{"audiodelayplus" , ACTION_AUDIO_DELAY_PLUS},
{"subtitleshiftup" , ACTION_SUBTITLE_VSHIFT_UP},
{"subtitleshiftdown" , ACTION_SUBTITLE_VSHIFT_DOWN},
{"subtitlealign" , ACTION_SUBTITLE_ALIGN},
{"audionextlanguage" , ACTION_AUDIO_NEXT_LANGUAGE},
{"verticalshiftup" , ACTION_VSHIFT_UP},
{"verticalshiftdown" , ACTION_VSHIFT_DOWN},
{"nextresolution" , ACTION_CHANGE_RESOLUTION},
{"audiotoggledigital", ACTION_TOGGLE_DIGITAL_ANALOG},
{"number0" , REMOTE_0},
{"number1" , REMOTE_1},
{"number2" , REMOTE_2},
{"number3" , REMOTE_3},
{"number4" , REMOTE_4},
{"number5" , REMOTE_5},
{"number6" , REMOTE_6},
{"number7" , REMOTE_7},
{"number8" , REMOTE_8},
{"number9" , REMOTE_9},
{"osdleft" , ACTION_OSD_SHOW_LEFT},
{"osdright" , ACTION_OSD_SHOW_RIGHT},
{"osdup" , ACTION_OSD_SHOW_UP},
{"osddown" , ACTION_OSD_SHOW_DOWN},
{"osdselect" , ACTION_OSD_SHOW_SELECT},
{"osdvalueplus" , ACTION_OSD_SHOW_VALUE_PLUS},
{"osdvalueminus" , ACTION_OSD_SHOW_VALUE_MIN},
{"smallstepback" , ACTION_SMALL_STEP_BACK},
{"fastforward" , ACTION_PLAYER_FORWARD},
{"rewind" , ACTION_PLAYER_REWIND},
{"play" , ACTION_PLAYER_PLAY},
{"playpause" , ACTION_PLAYER_PLAYPAUSE},
{"switchplayer" , ACTION_SWITCH_PLAYER},
{"delete" , ACTION_DELETE_ITEM},
{"copy" , ACTION_COPY_ITEM},
{"move" , ACTION_MOVE_ITEM},
{"mplayerosd" , ACTION_SHOW_MPLAYER_OSD},
{"hidesubmenu" , ACTION_OSD_HIDESUBMENU},
{"screenshot" , ACTION_TAKE_SCREENSHOT},
{"rename" , ACTION_RENAME_ITEM},
{"togglewatched" , ACTION_TOGGLE_WATCHED},
{"scanitem" , ACTION_SCAN_ITEM},
{"reloadkeymaps" , ACTION_RELOAD_KEYMAPS},
{"volumeup" , ACTION_VOLUME_UP},
{"volumedown" , ACTION_VOLUME_DOWN},
{"mute" , ACTION_MUTE},
{"backspace" , ACTION_BACKSPACE},
{"scrollup" , ACTION_SCROLL_UP},
{"scrolldown" , ACTION_SCROLL_DOWN},
{"analogfastforward" , ACTION_ANALOG_FORWARD},
{"analogrewind" , ACTION_ANALOG_REWIND},
{"moveitemup" , ACTION_MOVE_ITEM_UP},
{"moveitemdown" , ACTION_MOVE_ITEM_DOWN},
{"contextmenu" , ACTION_CONTEXT_MENU},
{"shift" , ACTION_SHIFT},
{"symbols" , ACTION_SYMBOLS},
{"cursorleft" , ACTION_CURSOR_LEFT},
{"cursorright" , ACTION_CURSOR_RIGHT},
{"showtime" , ACTION_SHOW_OSD_TIME},
{"analogseekforward" , ACTION_ANALOG_SEEK_FORWARD},
{"analogseekback" , ACTION_ANALOG_SEEK_BACK},
{"showpreset" , ACTION_VIS_PRESET_SHOW},
{"nextpreset" , ACTION_VIS_PRESET_NEXT},
{"previouspreset" , ACTION_VIS_PRESET_PREV},
{"lockpreset" , ACTION_VIS_PRESET_LOCK},
{"randompreset" , ACTION_VIS_PRESET_RANDOM},
{"increasevisrating" , ACTION_VIS_RATE_PRESET_PLUS},
{"decreasevisrating" , ACTION_VIS_RATE_PRESET_MINUS},
{"showvideomenu" , ACTION_SHOW_VIDEOMENU},
{"enter" , ACTION_ENTER},
{"increaserating" , ACTION_INCREASE_RATING},
{"decreaserating" , ACTION_DECREASE_RATING},
{"togglefullscreen" , ACTION_TOGGLE_FULLSCREEN},
{"nextscene" , ACTION_NEXT_SCENE},
{"previousscene" , ACTION_PREV_SCENE},
{"nextletter" , ACTION_NEXT_LETTER},
{"prevletter" , ACTION_PREV_LETTER},
{"jumpsms2" , ACTION_JUMP_SMS2},
{"jumpsms3" , ACTION_JUMP_SMS3},
{"jumpsms4" , ACTION_JUMP_SMS4},
{"jumpsms5" , ACTION_JUMP_SMS5},
{"jumpsms6" , ACTION_JUMP_SMS6},
{"jumpsms7" , ACTION_JUMP_SMS7},
{"jumpsms8" , ACTION_JUMP_SMS8},
{"jumpsms9" , ACTION_JUMP_SMS9},
{"filter" , ACTION_FILTER},
{"filterclear" , ACTION_FILTER_CLEAR},
{"filtersms2" , ACTION_FILTER_SMS2},
{"filtersms3" , ACTION_FILTER_SMS3},
{"filtersms4" , ACTION_FILTER_SMS4},
{"filtersms5" , ACTION_FILTER_SMS5},
{"filtersms6" , ACTION_FILTER_SMS6},
{"filtersms7" , ACTION_FILTER_SMS7},
{"filtersms8" , ACTION_FILTER_SMS8},
{"filtersms9" , ACTION_FILTER_SMS9},
{"firstpage" , ACTION_FIRST_PAGE},
{"lastpage" , ACTION_LAST_PAGE},
{"guiprofile" , ACTION_GUIPROFILE_BEGIN},
{"red" , ACTION_TELETEXT_RED},
{"green" , ACTION_TELETEXT_GREEN},
{"yellow" , ACTION_TELETEXT_YELLOW},
{"blue" , ACTION_TELETEXT_BLUE},
{"increasepar" , ACTION_INCREASE_PAR},
{"decreasepar" , ACTION_DECREASE_PAR},
{"volampup" , ACTION_VOLAMP_UP},
{"volampdown" , ACTION_VOLAMP_DOWN},
{"volumeamplification", ACTION_VOLAMP},
{"createbookmark" , ACTION_CREATE_BOOKMARK},
{"createepisodebookmark" , ACTION_CREATE_EPISODE_BOOKMARK},
{"settingsreset" , ACTION_SETTINGS_RESET},
{"settingslevelchange", ACTION_SETTINGS_LEVEL_CHANGE},
// 3D movie playback/GUI
{"stereomode" , ACTION_STEREOMODE_SELECT}, // cycle 3D modes, for now an alias for next
{"nextstereomode" , ACTION_STEREOMODE_NEXT},
{"previousstereomode" , ACTION_STEREOMODE_PREVIOUS},
{"togglestereomode" , ACTION_STEREOMODE_TOGGLE},
{"stereomodetomono" , ACTION_STEREOMODE_TOMONO},
// PVR actions
{"channelup" , ACTION_CHANNEL_UP},
{"channeldown" , ACTION_CHANNEL_DOWN},
{"previouschannelgroup" , ACTION_PREVIOUS_CHANNELGROUP},
{"nextchannelgroup" , ACTION_NEXT_CHANNELGROUP},
{"playpvr" , ACTION_PVR_PLAY},
{"playpvrtv" , ACTION_PVR_PLAY_TV},
{"playpvrradio" , ACTION_PVR_PLAY_RADIO},
{"record" , ACTION_RECORD},
// Mouse actions
{"leftclick" , ACTION_MOUSE_LEFT_CLICK},
{"rightclick" , ACTION_MOUSE_RIGHT_CLICK},
{"middleclick" , ACTION_MOUSE_MIDDLE_CLICK},
{"doubleclick" , ACTION_MOUSE_DOUBLE_CLICK},
{"longclick" , ACTION_MOUSE_LONG_CLICK},
{"wheelup" , ACTION_MOUSE_WHEEL_UP},
{"wheeldown" , ACTION_MOUSE_WHEEL_DOWN},
{"mousedrag" , ACTION_MOUSE_DRAG},
{"mousemove" , ACTION_MOUSE_MOVE},
// Touch
{"tap" , ACTION_TOUCH_TAP},
{"longpress" , ACTION_TOUCH_LONGPRESS},
{"pangesture" , ACTION_GESTURE_PAN},
{"zoomgesture" , ACTION_GESTURE_ZOOM},
{"rotategesture" , ACTION_GESTURE_ROTATE},
{"swipeleft" , ACTION_GESTURE_SWIPE_LEFT},
{"swiperight" , ACTION_GESTURE_SWIPE_RIGHT},
{"swipeup" , ACTION_GESTURE_SWIPE_UP},
{"swipedown" , ACTION_GESTURE_SWIPE_DOWN},
// Do nothing / error action
{ "error" , ACTION_ERROR},
{ "noop" , ACTION_NOOP}
};
static const ActionMapping windows[] =
{{"home" , WINDOW_HOME},
{"programs" , WINDOW_PROGRAMS},
{"pictures" , WINDOW_PICTURES},
{"filemanager" , WINDOW_FILES},
{"files" , WINDOW_FILES}, // backward compat
{"settings" , WINDOW_SETTINGS_MENU},
{"music" , WINDOW_MUSIC},
{"video" , WINDOW_VIDEOS},
{"videos" , WINDOW_VIDEO_NAV},
{"pvr" , WINDOW_TV_CHANNELS}, // backward compat
{"tvchannels" , WINDOW_TV_CHANNELS},
{"tvrecordings" , WINDOW_TV_RECORDINGS},
{"tvguide" , WINDOW_TV_GUIDE},
{"tvtimers" , WINDOW_TV_TIMERS},
{"tvsearch" , WINDOW_TV_SEARCH},
{"radiochannels" , WINDOW_RADIO_CHANNELS},
{"radiorecordings" , WINDOW_RADIO_RECORDINGS},
{"radioguide" , WINDOW_RADIO_GUIDE},
{"radiotimers" , WINDOW_RADIO_TIMERS},
{"radiosearch" , WINDOW_RADIO_SEARCH},
{"pvrguideinfo" , WINDOW_DIALOG_PVR_GUIDE_INFO},
{"pvrrecordinginfo" , WINDOW_DIALOG_PVR_RECORDING_INFO},
{"pvrtimersetting" , WINDOW_DIALOG_PVR_TIMER_SETTING},
{"pvrgroupmanager" , WINDOW_DIALOG_PVR_GROUP_MANAGER},
{"pvrchannelmanager" , WINDOW_DIALOG_PVR_CHANNEL_MANAGER},
{"pvrguidesearch" , WINDOW_DIALOG_PVR_GUIDE_SEARCH},
{"pvrchannelscan" , WINDOW_DIALOG_PVR_CHANNEL_SCAN},
{"pvrupdateprogress" , WINDOW_DIALOG_PVR_UPDATE_PROGRESS},
{"pvrosdchannels" , WINDOW_DIALOG_PVR_OSD_CHANNELS},
{"pvrosdguide" , WINDOW_DIALOG_PVR_OSD_GUIDE},
{"pvrosdteletext" , WINDOW_DIALOG_OSD_TELETEXT},
{"systeminfo" , WINDOW_SYSTEM_INFORMATION},
{"testpattern" , WINDOW_TEST_PATTERN},
{"screencalibration" , WINDOW_SCREEN_CALIBRATION},
{"guicalibration" , WINDOW_SCREEN_CALIBRATION}, // backward compat
{"picturessettings" , WINDOW_SETTINGS_MYPICTURES},
{"programssettings" , WINDOW_SETTINGS_MYPROGRAMS},
{"weathersettings" , WINDOW_SETTINGS_MYWEATHER},
{"musicsettings" , WINDOW_SETTINGS_MYMUSIC},
{"systemsettings" , WINDOW_SETTINGS_SYSTEM},
{"videossettings" , WINDOW_SETTINGS_MYVIDEOS},
{"networksettings" , WINDOW_SETTINGS_SERVICE}, // backward compat
{"servicesettings" , WINDOW_SETTINGS_SERVICE},
{"appearancesettings" , WINDOW_SETTINGS_APPEARANCE},
{"pvrsettings" , WINDOW_SETTINGS_MYPVR},
{"tvsettings" , WINDOW_SETTINGS_MYPVR}, // backward compat
{"scripts" , WINDOW_PROGRAMS}, // backward compat
{"videofiles" , WINDOW_VIDEO_FILES},
{"videolibrary" , WINDOW_VIDEO_NAV},
{"videoplaylist" , WINDOW_VIDEO_PLAYLIST},
{"loginscreen" , WINDOW_LOGIN_SCREEN},
{"profiles" , WINDOW_SETTINGS_PROFILES},
{"skinsettings" , WINDOW_SKIN_SETTINGS},
{"addonbrowser" , WINDOW_ADDON_BROWSER},
{"yesnodialog" , WINDOW_DIALOG_YES_NO},
{"progressdialog" , WINDOW_DIALOG_PROGRESS},
{"virtualkeyboard" , WINDOW_DIALOG_KEYBOARD},
{"volumebar" , WINDOW_DIALOG_VOLUME_BAR},
{"submenu" , WINDOW_DIALOG_SUB_MENU},
{"favourites" , WINDOW_DIALOG_FAVOURITES},
{"contextmenu" , WINDOW_DIALOG_CONTEXT_MENU},
{"infodialog" , WINDOW_DIALOG_KAI_TOAST},
{"numericinput" , WINDOW_DIALOG_NUMERIC},
{"gamepadinput" , WINDOW_DIALOG_GAMEPAD},
{"shutdownmenu" , WINDOW_DIALOG_BUTTON_MENU},
{"mutebug" , WINDOW_DIALOG_MUTE_BUG},
{"playercontrols" , WINDOW_DIALOG_PLAYER_CONTROLS},
{"seekbar" , WINDOW_DIALOG_SEEK_BAR},
{"musicosd" , WINDOW_DIALOG_MUSIC_OSD},
{"addonsettings" , WINDOW_DIALOG_ADDON_SETTINGS},
{"visualisationsettings" , WINDOW_DIALOG_ADDON_SETTINGS}, // backward compat
{"visualisationpresetlist" , WINDOW_DIALOG_VIS_PRESET_LIST},
{"osdvideosettings" , WINDOW_DIALOG_VIDEO_OSD_SETTINGS},
{"osdaudiosettings" , WINDOW_DIALOG_AUDIO_OSD_SETTINGS},
{"videobookmarks" , WINDOW_DIALOG_VIDEO_BOOKMARKS},
{"filebrowser" , WINDOW_DIALOG_FILE_BROWSER},
{"networksetup" , WINDOW_DIALOG_NETWORK_SETUP},
{"mediasource" , WINDOW_DIALOG_MEDIA_SOURCE},
{"profilesettings" , WINDOW_DIALOG_PROFILE_SETTINGS},
{"locksettings" , WINDOW_DIALOG_LOCK_SETTINGS},
{"contentsettings" , WINDOW_DIALOG_CONTENT_SETTINGS},
{"songinformation" , WINDOW_DIALOG_SONG_INFO},
{"smartplaylisteditor" , WINDOW_DIALOG_SMART_PLAYLIST_EDITOR},
{"smartplaylistrule" , WINDOW_DIALOG_SMART_PLAYLIST_RULE},
{"busydialog" , WINDOW_DIALOG_BUSY},
{"pictureinfo" , WINDOW_DIALOG_PICTURE_INFO},
{"accesspoints" , WINDOW_DIALOG_ACCESS_POINTS},
{"fullscreeninfo" , WINDOW_DIALOG_FULLSCREEN_INFO},
{"karaokeselector" , WINDOW_DIALOG_KARAOKE_SONGSELECT},
{"karaokelargeselector" , WINDOW_DIALOG_KARAOKE_SELECTOR},
{"sliderdialog" , WINDOW_DIALOG_SLIDER},
{"addoninformation" , WINDOW_DIALOG_ADDON_INFO},
{"subtitlesearch" , WINDOW_DIALOG_SUBTITLES},
{"musicplaylist" , WINDOW_MUSIC_PLAYLIST},
{"musicfiles" , WINDOW_MUSIC_FILES},
{"musiclibrary" , WINDOW_MUSIC_NAV},
{"musicplaylisteditor" , WINDOW_MUSIC_PLAYLIST_EDITOR},
{"teletext" , WINDOW_DIALOG_OSD_TELETEXT},
{"selectdialog" , WINDOW_DIALOG_SELECT},
{"musicinformation" , WINDOW_DIALOG_MUSIC_INFO},
{"okdialog" , WINDOW_DIALOG_OK},
{"movieinformation" , WINDOW_DIALOG_VIDEO_INFO},
{"textviewer" , WINDOW_DIALOG_TEXT_VIEWER},
{"fullscreenvideo" , WINDOW_FULLSCREEN_VIDEO},
{"fullscreenlivetv" , WINDOW_FULLSCREEN_LIVETV}, // virtual window/keymap section for PVR specific bindings in fullscreen playback (which internally uses WINDOW_FULLSCREEN_VIDEO)
{"fullscreenradio" , WINDOW_FULLSCREEN_RADIO}, // virtual window for fullscreen radio, uses WINDOW_VISUALISATION as fallback
{"visualisation" , WINDOW_VISUALISATION},
{"slideshow" , WINDOW_SLIDESHOW},
{"filestackingdialog" , WINDOW_DIALOG_FILESTACKING},
{"karaoke" , WINDOW_KARAOKELYRICS},
{"weather" , WINDOW_WEATHER},
{"screensaver" , WINDOW_SCREENSAVER},
{"videoosd" , WINDOW_DIALOG_VIDEO_OSD},
{"videomenu" , WINDOW_VIDEO_MENU},
{"videotimeseek" , WINDOW_VIDEO_TIME_SEEK},
{"musicoverlay" , WINDOW_DIALOG_MUSIC_OVERLAY},
{"videooverlay" , WINDOW_DIALOG_VIDEO_OVERLAY},
{"startwindow" , WINDOW_START},
{"startup" , WINDOW_STARTUP_ANIM},
{"peripherals" , WINDOW_DIALOG_PERIPHERAL_MANAGER},
{"peripheralsettings" , WINDOW_DIALOG_PERIPHERAL_SETTINGS},
{"extendedprogressdialog" , WINDOW_DIALOG_EXT_PROGRESS},
{"mediafilter" , WINDOW_DIALOG_MEDIA_FILTER},
{"addon" , WINDOW_ADDON_START}};
static const ActionMapping mousekeys[] =
{
{ "click", KEY_MOUSE_CLICK },
{ "leftclick", KEY_MOUSE_CLICK },
{ "rightclick", KEY_MOUSE_RIGHTCLICK },
{ "middleclick", KEY_MOUSE_MIDDLECLICK },
{ "doubleclick", KEY_MOUSE_DOUBLE_CLICK },
{ "longclick", KEY_MOUSE_LONG_CLICK },
{ "wheelup", KEY_MOUSE_WHEEL_UP },
{ "wheeldown", KEY_MOUSE_WHEEL_DOWN },
{ "mousemove", KEY_MOUSE_MOVE },
{ "mousedrag", KEY_MOUSE_DRAG },
{ "mousedragstart", KEY_MOUSE_DRAG_START },
{ "mousedragend", KEY_MOUSE_DRAG_END },
{ "mouserdrag", KEY_MOUSE_RDRAG },
{ "mouserdragstart", KEY_MOUSE_RDRAG_START },
{ "mouserdragend", KEY_MOUSE_RDRAG_END }
};
static const ActionMapping touchcommands[] =
{
{ "tap", ACTION_TOUCH_TAP },
{ "longpress", ACTION_TOUCH_LONGPRESS },
{ "pan", ACTION_GESTURE_PAN },
{ "zoom", ACTION_GESTURE_ZOOM },
{ "rotate", ACTION_GESTURE_ROTATE },
{ "swipeleft", ACTION_GESTURE_SWIPE_LEFT },
{ "swiperight", ACTION_GESTURE_SWIPE_RIGHT },
{ "swipeup", ACTION_GESTURE_SWIPE_UP },
{ "swipedown", ACTION_GESTURE_SWIPE_DOWN }
};
static const WindowMapping fallbackWindows[] =
{
{ WINDOW_FULLSCREEN_LIVETV, WINDOW_FULLSCREEN_VIDEO },
{ WINDOW_DIALOG_FULLSCREEN_INFO, WINDOW_FULLSCREEN_VIDEO },
{ WINDOW_FULLSCREEN_RADIO, WINDOW_VISUALISATION }
};
#ifdef TARGET_WINDOWS
static const ActionMapping appcommands[] =
{
{ "browser_back", APPCOMMAND_BROWSER_BACKWARD },
{ "browser_forward", APPCOMMAND_BROWSER_FORWARD },
{ "browser_refresh", APPCOMMAND_BROWSER_REFRESH },
{ "browser_stop", APPCOMMAND_BROWSER_STOP },
{ "browser_search", APPCOMMAND_BROWSER_SEARCH },
{ "browser_favorites", APPCOMMAND_BROWSER_FAVORITES },
{ "browser_home", APPCOMMAND_BROWSER_HOME },
{ "volume_mute", APPCOMMAND_VOLUME_MUTE },
{ "volume_down", APPCOMMAND_VOLUME_DOWN },
{ "volume_up", APPCOMMAND_VOLUME_UP },
{ "next_track", APPCOMMAND_MEDIA_NEXTTRACK },
{ "prev_track", APPCOMMAND_MEDIA_PREVIOUSTRACK },
{ "stop", APPCOMMAND_MEDIA_STOP },
{ "play_pause", APPCOMMAND_MEDIA_PLAY_PAUSE },
{ "launch_mail", APPCOMMAND_LAUNCH_MAIL },
{ "launch_media_select", APPCOMMAND_LAUNCH_MEDIA_SELECT },
{ "launch_app1", APPCOMMAND_LAUNCH_APP1 },
{ "launch_app2", APPCOMMAND_LAUNCH_APP2 },
{ "play", APPCOMMAND_MEDIA_PLAY },
{ "pause", APPCOMMAND_MEDIA_PAUSE },
{ "fastforward", APPCOMMAND_MEDIA_FAST_FORWARD },
{ "rewind", APPCOMMAND_MEDIA_REWIND },
{ "channelup", APPCOMMAND_MEDIA_CHANNEL_UP },
{ "channeldown", APPCOMMAND_MEDIA_CHANNEL_DOWN }
};
#endif
CButtonTranslator& CButtonTranslator::GetInstance()
{
static CButtonTranslator sl_instance;
return sl_instance;
}
CButtonTranslator::CButtonTranslator()
{
m_deviceList.clear();
m_Loaded = false;
}
#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
void CButtonTranslator::ClearLircButtonMapEntries()
{
vector<lircButtonMap*> maps;
for (map<std::string,lircButtonMap*>::iterator it = lircRemotesMap.begin();
it != lircRemotesMap.end();++it)
maps.push_back(it->second);
sort(maps.begin(),maps.end());
vector<lircButtonMap*>::iterator itend = unique(maps.begin(),maps.end());
for (vector<lircButtonMap*>::iterator it = maps.begin(); it != itend;++it)
delete *it;
}
#endif
CButtonTranslator::~CButtonTranslator()
{
#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
ClearLircButtonMapEntries();
#endif
}
// Add the supplied device name to the list of connected devices
void CButtonTranslator::AddDevice(std::string& strDevice)
{
// Only add the device if it isn't already in the list
std::list<std::string>::iterator it;
for (it = m_deviceList.begin(); it != m_deviceList.end(); ++it)
if (*it == strDevice)
return;
// Add the device
m_deviceList.push_back(strDevice);
m_deviceList.sort();
// New device added so reload the key mappings
Load();
}
void CButtonTranslator::RemoveDevice(std::string& strDevice)
{
// Find the device
std::list<std::string>::iterator it;
for (it = m_deviceList.begin(); it != m_deviceList.end(); ++it)
if (*it == strDevice)
break;
if (it == m_deviceList.end())
return;
// Remove the device
m_deviceList.remove(strDevice);
// Device removed so reload the key mappings
Load();
}
bool CButtonTranslator::Load(bool AlwaysLoad)
{
m_translatorMap.clear();
// Directories to search for keymaps. They're applied in this order,
// so keymaps in profile/keymaps/ override e.g. system/keymaps
static const char* DIRS_TO_CHECK[] = {
"special://xbmc/system/keymaps/",
"special://masterprofile/keymaps/",
"special://profile/keymaps/"
};
bool success = false;
for (unsigned int dirIndex = 0; dirIndex < ARRAY_SIZE(DIRS_TO_CHECK); ++dirIndex)
{
if (XFILE::CDirectory::Exists(DIRS_TO_CHECK[dirIndex]))
{
CFileItemList files;
XFILE::CDirectory::GetDirectory(DIRS_TO_CHECK[dirIndex], files, ".xml");
// Sort the list for filesystem based priorities, e.g. 01-keymap.xml, 02-keymap-overrides.xml
files.Sort(SortByFile, SortOrderAscending);
for(int fileIndex = 0; fileIndex<files.Size(); ++fileIndex)
{
if (!files[fileIndex]->m_bIsFolder)
success |= LoadKeymap(files[fileIndex]->GetPath());
}
// Load mappings for any HID devices we have connected
std::list<std::string>::iterator it;
for (it = m_deviceList.begin(); it != m_deviceList.end(); ++it)
{
std::string devicedir = DIRS_TO_CHECK[dirIndex];
devicedir.append(*it);
devicedir.append("/");
if( XFILE::CDirectory::Exists(devicedir) )
{
CFileItemList files;
XFILE::CDirectory::GetDirectory(devicedir, files, ".xml");
// Sort the list for filesystem based priorities, e.g. 01-keymap.xml, 02-keymap-overrides.xml
files.Sort(SortByFile, SortOrderAscending);
for(int fileIndex = 0; fileIndex<files.Size(); ++fileIndex)
{
if (!files[fileIndex]->m_bIsFolder)
success |= LoadKeymap(files[fileIndex]->GetPath());
}
}
}
}
}
if (!success)
{
CLog::Log(LOGERROR, "Error loading keymaps from: %s or %s or %s", DIRS_TO_CHECK[0], DIRS_TO_CHECK[1], DIRS_TO_CHECK[2]);
return false;
}
#if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
#ifdef TARGET_POSIX
#define REMOTEMAP "Lircmap.xml"
#else
#define REMOTEMAP "IRSSmap.xml"
#endif
std::string lircmapPath = URIUtils::AddFileToFolder("special://xbmc/system/", REMOTEMAP);
lircRemotesMap.clear();
if(CFile::Exists(lircmapPath))
success |= LoadLircMap(lircmapPath);
else
CLog::Log(LOGDEBUG, "CButtonTranslator::Load - no system %s found, skipping", REMOTEMAP);
lircmapPath = CProfilesManager::Get().GetUserDataItem(REMOTEMAP);
if(CFile::Exists(lircmapPath))
success |= LoadLircMap(lircmapPath);
else
CLog::Log(LOGDEBUG, "CButtonTranslator::Load - no userdata %s found, skipping", REMOTEMAP);
if (!success)
CLog::Log(LOGERROR, "CButtonTranslator::Load - unable to load remote map %s", REMOTEMAP);
// don't return false - it is to only indicate a fatal error (which this is not)
#endif
// Done!
m_Loaded = true;
return true;
}
bool CButtonTranslator::LoadKeymap(const std::string &keymapPath)
{
CXBMCTinyXML xmlDoc;
CLog::Log(LOGINFO, "Loading %s", keymapPath.c_str());
if (!xmlDoc.LoadFile(keymapPath))
{
CLog::Log(LOGERROR, "Error loading keymap: %s, Line %d\n%s", keymapPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc());
return false;
}
TiXmlElement* pRoot = xmlDoc.RootElement();
if (!pRoot)
{
CLog::Log(LOGERROR, "Error getting keymap root: %s", keymapPath.c_str());
return false;
}
std::string strValue = pRoot->Value();
if ( strValue != "keymap")
{
CLog::Log(LOGERROR, "%s Doesn't contain <keymap>", keymapPath.c_str());
return false;
}
// run through our window groups
TiXmlNode* pWindow = pRoot->FirstChild();
while (pWindow)
{
if (pWindow->Type() == TiXmlNode::TINYXML_ELEMENT)
{
int windowID = WINDOW_INVALID;
const char *szWindow = pWindow->Value();
if (szWindow)
{
if (strcmpi(szWindow, "joystickFamily") == 0)
MapJoystickFamily(pWindow);
else if (strcmpi(szWindow, "global") == 0)
windowID = -1;
else
windowID = TranslateWindow(szWindow);
}
MapWindowActions(pWindow, windowID);
}
pWindow = pWindow->NextSibling();
}
return true;
}
bool CButtonTranslator::LoadLircMap(const std::string &lircmapPath)
{
#ifdef TARGET_POSIX
#define REMOTEMAPTAG "lircmap"
#else
#define REMOTEMAPTAG "irssmap"
#endif
// load our xml file, and fill up our mapping tables
CXBMCTinyXML xmlDoc;
// Load the config file
CLog::Log(LOGINFO, "Loading %s", lircmapPath.c_str());
if (!xmlDoc.LoadFile(lircmapPath))
{
CLog::Log(LOGERROR, "%s, Line %d\n%s", lircmapPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc());
return false; // This is so people who don't have the file won't fail, just warn
}
TiXmlElement* pRoot = xmlDoc.RootElement();
std::string strValue = pRoot->Value();
if (strValue != REMOTEMAPTAG)
{
CLog::Log(LOGERROR, "%sl Doesn't contain <%s>", lircmapPath.c_str(), REMOTEMAPTAG);
return false;
}
// run through our window groups
TiXmlNode* pRemote = pRoot->FirstChild();
while (pRemote)
{
if (pRemote->Type() == TiXmlNode::TINYXML_ELEMENT)
{
const char *szRemote = pRemote->Value();
if (szRemote)
{
TiXmlAttribute* pAttr = pRemote->ToElement()->FirstAttribute();
if (pAttr)
MapRemote(pRemote, pAttr->Value());
}
}
pRemote = pRemote->NextSibling();
}
return true;
}
void CButtonTranslator::MapRemote(TiXmlNode *pRemote, const char* szDevice)
{
CLog::Log(LOGINFO, "* Adding remote mapping for device '%s'", szDevice);
vector<string> RemoteNames;
map<std::string, lircButtonMap*>::iterator it = lircRemotesMap.find(szDevice);
if (it == lircRemotesMap.end())
lircRemotesMap[szDevice] = new lircButtonMap;
lircButtonMap& buttons = *lircRemotesMap[szDevice];
TiXmlElement *pButton = pRemote->FirstChildElement();
while (pButton)
{
if (!pButton->NoChildren())
{
if (pButton->ValueStr() == "altname")
RemoteNames.push_back(pButton->FirstChild()->ValueStr());
else
buttons[pButton->FirstChild()->ValueStr()] = pButton->ValueStr();
}
pButton = pButton->NextSiblingElement();
}
for (vector<string>::iterator it = RemoteNames.begin();
it != RemoteNames.end();++it)
{
CLog::Log(LOGINFO, "* Linking remote mapping for '%s' to '%s'", szDevice, it->c_str());
lircRemotesMap[*it] = &buttons;
}
}
int CButtonTranslator::TranslateLircRemoteString(const char* szDevice, const char *szButton)
{
// Find the device
map<std::string, lircButtonMap*>::iterator it = lircRemotesMap.find(szDevice);
if (it == lircRemotesMap.end())
return 0;
// Find the button
lircButtonMap::iterator it2 = (*it).second->find(szButton);
if (it2 == (*it).second->end())
return 0;
// Convert the button to code
if (strnicmp((*it2).second.c_str(), "obc", 3) == 0)
return TranslateUniversalRemoteString((*it2).second.c_str());
return TranslateRemoteString((*it2).second.c_str());
}
#if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
void CButtonTranslator::MapJoystickFamily(TiXmlNode *pNode)
{
TiXmlElement *pFamily = pNode->ToElement();
if (pFamily && pFamily->Attribute("name"))
{
std::string joyFamilyName = pFamily->Attribute("name");
JoystickFamily* joyFamily = &m_joystickFamilies[joyFamilyName];
TiXmlElement *pMember = pFamily->FirstChildElement();
while (pMember)
{
TiXmlNode* pName = pMember->FirstChild();
if (pName && pName->ValueStr() != "") {
std::shared_ptr<CRegExp> re(new CRegExp(true, CRegExp::asciiOnly));
std::string joyRe = JoynameToRegex(pName->ValueStr());
if (!re->RegComp(joyRe, CRegExp::StudyRegExp))
{
CLog::Log(LOGNOTICE, "Invalid joystick regex specified: '%s'", pName->Value());
continue;
}
AddFamilyRegex(joyFamily, re);
}
pMember = pMember->NextSiblingElement();
}
}
else
{
CLog::Log(LOGNOTICE, "Ignoring nameless joystick family");
}
}
void CButtonTranslator::MapJoystickActions(int windowID, TiXmlNode *pJoystick)
{
std::string joyFamilyName;
map<int, string> buttonMap;
map<int, string> axisMap;
AxesConfig axesConfig;
ActionMap hatMap;
TiXmlElement *pJoy = pJoystick->ToElement();
if (pJoy && pJoy->Attribute("family"))
joyFamilyName = pJoy->Attribute("family");
else if (pJoy) {
// transform loose name to new family, including altnames
string joyName = JOYSTICK_DEFAULT_MAP; // default global map name
if (pJoy->Attribute("name"))
joyName = pJoy->Attribute("name");
joyFamilyName = joyName;
JoystickFamily* joyFamily = &m_joystickFamilies[joyFamilyName];
std::shared_ptr<CRegExp> re(new CRegExp(true, CRegExp::asciiOnly));
std::string joyRe = JoynameToRegex(joyName);
if (!re->RegComp(joyRe, CRegExp::StudyRegExp))
{
CLog::Log(LOGNOTICE, "Invalid joystick regex specified: '%s'", joyName.c_str());
return;
}
AddFamilyRegex(joyFamily, re);
// add altnames to family
TiXmlElement *pNode = pJoystick->FirstChildElement();
while (pNode) {
const std::string &type = pNode->ValueStr();
if (type == "altname") {
std::string altName = pNode->FirstChild()->ValueStr();
std::shared_ptr<CRegExp> altRe(new CRegExp(true, CRegExp::asciiOnly));
std::string altReStr = JoynameToRegex(altName);
if (!altRe->RegComp(altReStr, CRegExp::StudyRegExp))
CLog::Log(LOGNOTICE, "Ignoring invalid joystick altname regex: '%s'", altReStr.c_str());
else
AddFamilyRegex(joyFamily, altRe);
}
pNode = pNode->NextSiblingElement();
}
}
// parse map
TiXmlElement *pButton = pJoystick->FirstChildElement();
int id = 0;
while (pButton)
{
const std::string &type = pButton->ValueStr();
std::string action;
if (!pButton->NoChildren())
action = pButton->FirstChild()->ValueStr();
// skip altname tags here because those contain no mappings ...
if (type == "altname")
{
pButton = pButton->NextSiblingElement();
continue;
}
if ((pButton->QueryIntAttribute("id", &id) == TIXML_SUCCESS) && id>=0 && id<=256)
{
if (type == "button")
{
buttonMap[id] = action;
}
else if (type == "axis")
{
int limit = 0;
if (pButton->QueryIntAttribute("limit", &limit) == TIXML_SUCCESS)
{
if (limit==-1)
axisMap[-id] = action;
else if (limit==1)
axisMap[id] = action;
else if (limit==0)
axisMap[id|0xFFFF0000] = action;
else
{
axisMap[id] = action;
axisMap[-id] = action;
CLog::Log(LOGERROR, "Error in joystick map, invalid limit specified %d for axis %d", limit, id);
}
}
else
{
axisMap[id] = action;
axisMap[-id] = action;
}
if (windowID == -1) {
// in <global> we can override the rest state value of axes and whether they are triggers
bool trigger = false;
int restStateValue = 0;
pButton->QueryBoolAttribute("trigger", &trigger);
pButton->QueryIntAttribute("rest", &restStateValue);
// if it deviates from the defaults
if (trigger || restStateValue != 0)
axesConfig.push_back(AxisConfig(id, trigger, restStateValue));
}
}
else if (type == "hat")
{
string position;
if (pButton->QueryValueAttribute("position", &position) == TIXML_SUCCESS)
{
uint32_t hatID = id|0xFFF00000;
if (position.compare("up") == 0)
hatMap[(JACTIVE_HAT_UP<<16)|hatID] = action;
else if (position.compare("down") == 0)
hatMap[(JACTIVE_HAT_DOWN<<16)|hatID] = action;
else if (position.compare("right") == 0)
hatMap[(JACTIVE_HAT_RIGHT<<16)|hatID] = action;
else if (position.compare("left") == 0)
hatMap[(JACTIVE_HAT_LEFT<<16)|hatID] = action;
else
CLog::Log(LOGERROR, "Error in joystick map, invalid position specified %s for axis %d", position.c_str(), id);
}
}
else
CLog::Log(LOGERROR, "Error reading joystick map element, unknown button type: %s", type.c_str());
}
else
CLog::Log(LOGERROR, "Error reading joystick map element, Invalid id: %d", id);
pButton = pButton->NextSiblingElement();
}
m_joystickButtonMap[joyFamilyName][windowID].insert(buttonMap.begin(), buttonMap.end());
m_joystickAxisMap[joyFamilyName][windowID].insert(axisMap.begin(), axisMap.end());
m_joystickHatMap[joyFamilyName][windowID].insert(hatMap.begin(), hatMap.end());
if (windowID == -1)
m_joystickAxesConfigs[joyFamilyName] = axesConfig;
}
std::string CButtonTranslator::JoynameToRegex(const std::string& joyName) const
{
if (joyName.empty())
return joyName;
// names already presented as regex are identified by a leading /
else if (joyName[0] == '/')
return joyName.substr(1);
// the others we'll have to escape
return "\\Q" + joyName + "\\E";
}
bool CButtonTranslator::AddFamilyRegex(JoystickFamily* family, std::shared_ptr<CRegExp> regex)
{
// even though family is a set, this does not prevent the same regex
// from being added twice, so we manually match on pattern equality
JoystickFamily::iterator it;
for (it = family->begin(); it != family->end(); it++)
{
if ((*it)->GetPattern() == regex->GetPattern())
return false;
}
family->insert(regex);
return true;
}
const AxesConfig* CButtonTranslator::GetAxesConfigFor(const std::string& joyName) const
{
JoystickFamilyMap::const_iterator familyIt = FindJoystickFamily(joyName);
if (familyIt == m_joystickFamilies.end())
return NULL;
else {
std::map<std::string, AxesConfig>::const_iterator it = m_joystickAxesConfigs.find(familyIt->first);
if (it == m_joystickAxesConfigs.end())
return NULL;
else
return &it->second;
}
}
CButtonTranslator::JoystickMap::const_iterator CButtonTranslator::FindWindowMap(const std::string& joyName, const JoystickMap &maps) const
{
JoystickFamilyMap::const_iterator familyIt = FindJoystickFamily(joyName);
if (familyIt == m_joystickFamilies.end())
return maps.end();
else
return maps.find(familyIt->first);
}
CButtonTranslator::JoystickFamilyMap::const_iterator CButtonTranslator::FindJoystickFamily(const std::string& joyName) const
{
// find the family corresponding to a joystick name
JoystickFamilyMap::const_iterator it;
for (it = m_joystickFamilies.begin(); it != m_joystickFamilies.end(); it++)
{
JoystickFamily::const_iterator regexIt;
for (regexIt = it->second.begin(); regexIt != it->second.end(); regexIt++)
{
if ((*regexIt)->RegFind(joyName) >= 0)
{
// CLog::Log(LOGDEBUG, "Regex %s matches joystick %s", it->first->GetPattern().c_str(), joyName.c_str());