-rw-r--r-- | noncore/apps/keyz-cfg/zkbnames.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkbnames.h | 4 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkbxml.cpp | 14 |
3 files changed, 0 insertions, 21 deletions
diff --git a/noncore/apps/keyz-cfg/zkbnames.cpp b/noncore/apps/keyz-cfg/zkbnames.cpp index fec3a2e..c20a114 100644 --- a/noncore/apps/keyz-cfg/zkbnames.cpp +++ b/noncore/apps/keyz-cfg/zkbnames.cpp | |||
@@ -1,34 +1,32 @@ | |||
1 | #ifdef USE_ZKB_NAMES | ||
2 | |||
3 | #include <qmap.h> | 1 | #include <qmap.h> |
4 | #include <qstring.h> | 2 | #include <qstring.h> |
5 | 3 | ||
6 | #include "zkbnames.h" | 4 | #include "zkbnames.h" |
7 | 5 | ||
8 | QString Null_String((const char*) 0); | 6 | QString Null_String((const char*) 0); |
9 | 7 | ||
10 | // Implementation of KeyNames | 8 | // Implementation of KeyNames |
11 | static struct { | 9 | static struct { |
12 | int key; | 10 | int key; |
13 | char *name; | 11 | char *name; |
14 | } Key_Names[] = { | 12 | } Key_Names[] = { |
15 | { 32, "Space" }, | 13 | { 32, "Space" }, |
16 | { 39, "Apostrophe" }, | 14 | { 39, "Apostrophe" }, |
17 | { 44, "Comma" }, | 15 | { 44, "Comma" }, |
18 | { 46, "Period" }, | 16 | { 46, "Period" }, |
19 | { 47, "Slash" }, | 17 | { 47, "Slash" }, |
20 | { 65, "A" }, | 18 | { 65, "A" }, |
21 | { 66, "B" }, | 19 | { 66, "B" }, |
22 | { 67, "C" }, | 20 | { 67, "C" }, |
23 | { 68, "D" }, | 21 | { 68, "D" }, |
24 | { 69, "E" }, | 22 | { 69, "E" }, |
25 | { 70, "F" }, | 23 | { 70, "F" }, |
26 | { 71, "G" }, | 24 | { 71, "G" }, |
27 | { 72, "H" }, | 25 | { 72, "H" }, |
28 | { 73, "I" }, | 26 | { 73, "I" }, |
29 | { 74, "J" }, | 27 | { 74, "J" }, |
30 | { 75, "K" }, | 28 | { 75, "K" }, |
31 | { 76, "L" }, | 29 | { 76, "L" }, |
32 | { 77, "M" }, | 30 | { 77, "M" }, |
33 | { 78, "N" }, | 31 | { 78, "N" }, |
34 | { 79, "O" }, | 32 | { 79, "O" }, |
@@ -418,33 +416,32 @@ void init_kcn_maps() { | |||
418 | kcn_map.insert(name, keycode); | 416 | kcn_map.insert(name, keycode); |
419 | kcn_rmap.insert(keycode, name); | 417 | kcn_rmap.insert(keycode, name); |
420 | i++; | 418 | i++; |
421 | } | 419 | } |
422 | } | 420 | } |
423 | 421 | ||
424 | int KeycodeNames::find(const QString& key) { | 422 | int KeycodeNames::find(const QString& key) { |
425 | if (kcn_map.isEmpty()) { | 423 | if (kcn_map.isEmpty()) { |
426 | init_kcn_maps(); | 424 | init_kcn_maps(); |
427 | } | 425 | } |
428 | 426 | ||
429 | QMap<QString, int>::Iterator it = kcn_map.find(key); | 427 | QMap<QString, int>::Iterator it = kcn_map.find(key); |
430 | if (it == kcn_map.end()) { | 428 | if (it == kcn_map.end()) { |
431 | return -1; | 429 | return -1; |
432 | } else { | 430 | } else { |
433 | return it.data(); | 431 | return it.data(); |
434 | } | 432 | } |
435 | } | 433 | } |
436 | 434 | ||
437 | const QString& KeycodeNames::find(int k) { | 435 | const QString& KeycodeNames::find(int k) { |
438 | if (kcn_map.isEmpty()) { | 436 | if (kcn_map.isEmpty()) { |
439 | init_kcn_maps(); | 437 | init_kcn_maps(); |
440 | } | 438 | } |
441 | 439 | ||
442 | QMap<int, QString>::Iterator it = kcn_rmap.find(k); | 440 | QMap<int, QString>::Iterator it = kcn_rmap.find(k); |
443 | if (it == kcn_rmap.end()) { | 441 | if (it == kcn_rmap.end()) { |
444 | return Null_String; | 442 | return Null_String; |
445 | } else { | 443 | } else { |
446 | return it.data(); | 444 | return it.data(); |
447 | } | 445 | } |
448 | } | 446 | } |
449 | 447 | ||
450 | #endif | ||
diff --git a/noncore/apps/keyz-cfg/zkbnames.h b/noncore/apps/keyz-cfg/zkbnames.h index 58462ff..0d1e7f5 100644 --- a/noncore/apps/keyz-cfg/zkbnames.h +++ b/noncore/apps/keyz-cfg/zkbnames.h | |||
@@ -1,27 +1,23 @@ | |||
1 | #ifndef ZKBNAMES_H | 1 | #ifndef ZKBNAMES_H |
2 | #define ZKBNAMES_H | 2 | #define ZKBNAMES_H |
3 | 3 | ||
4 | #ifdef USE_ZKB_NAMES | ||
5 | |||
6 | #include <qstring.h> | 4 | #include <qstring.h> |
7 | 5 | ||
8 | class KeyNames { | 6 | class KeyNames { |
9 | public: | 7 | public: |
10 | static int find(const QString& key); | 8 | static int find(const QString& key); |
11 | static const QString& find(int); | 9 | static const QString& find(int); |
12 | }; | 10 | }; |
13 | 11 | ||
14 | class KeycodeNames { | 12 | class KeycodeNames { |
15 | public: | 13 | public: |
16 | static int find(const QString& key); | 14 | static int find(const QString& key); |
17 | static const QString& find(int); | 15 | static const QString& find(int); |
18 | }; | 16 | }; |
19 | 17 | ||
20 | class ModifierNames { | 18 | class ModifierNames { |
21 | public: | 19 | public: |
22 | static int find(const QString& key); | 20 | static int find(const QString& key); |
23 | static const QString& find(int); | 21 | static const QString& find(int); |
24 | }; | 22 | }; |
25 | |||
26 | #endif | ||
27 | #endif | 23 | #endif |
diff --git a/noncore/apps/keyz-cfg/zkbxml.cpp b/noncore/apps/keyz-cfg/zkbxml.cpp index 76472cb..5b0084c 100644 --- a/noncore/apps/keyz-cfg/zkbxml.cpp +++ b/noncore/apps/keyz-cfg/zkbxml.cpp | |||
@@ -460,128 +460,114 @@ bool ZkbXmlHandler::end_keymap() { | |||
460 | 460 | ||
461 | bool ZkbXmlHandler::end_include() { | 461 | bool ZkbXmlHandler::end_include() { |
462 | return endIncludeElement(); | 462 | return endIncludeElement(); |
463 | } | 463 | } |
464 | 464 | ||
465 | bool ZkbXmlHandler::end_label() { | 465 | bool ZkbXmlHandler::end_label() { |
466 | return endLabelElement(); | 466 | return endLabelElement(); |
467 | } | 467 | } |
468 | 468 | ||
469 | bool ZkbXmlHandler::end_state() { | 469 | bool ZkbXmlHandler::end_state() { |
470 | return endStateElement(); | 470 | return endStateElement(); |
471 | } | 471 | } |
472 | 472 | ||
473 | bool ZkbXmlHandler::end_map() { | 473 | bool ZkbXmlHandler::end_map() { |
474 | return endMapElement(); | 474 | return endMapElement(); |
475 | } | 475 | } |
476 | 476 | ||
477 | bool ZkbXmlHandler::end_event() { | 477 | bool ZkbXmlHandler::end_event() { |
478 | return endEventElement(); | 478 | return endEventElement(); |
479 | } | 479 | } |
480 | 480 | ||
481 | bool ZkbXmlHandler::end_next_state() { | 481 | bool ZkbXmlHandler::end_next_state() { |
482 | return endNextStateElement(); | 482 | return endNextStateElement(); |
483 | } | 483 | } |
484 | 484 | ||
485 | void ZkbXmlHandler::setError(const QString& e) { | 485 | void ZkbXmlHandler::setError(const QString& e) { |
486 | err = e; | 486 | err = e; |
487 | } | 487 | } |
488 | 488 | ||
489 | int ZkbXmlHandler::str2key(const QString& s) { | 489 | int ZkbXmlHandler::str2key(const QString& s) { |
490 | int ret; | 490 | int ret; |
491 | 491 | ||
492 | #ifdef USE_ZKB_NAMES | ||
493 | ret = KeyNames::find(s); | 492 | ret = KeyNames::find(s); |
494 | if (ret == -1) { | 493 | if (ret == -1) { |
495 | setError("Invalid value: " + s); | 494 | setError("Invalid value: " + s); |
496 | } | 495 | } |
497 | 496 | ||
498 | #else | ||
499 | ret = str2uint(s); | ||
500 | #endif | ||
501 | |||
502 | return ret; | 497 | return ret; |
503 | } | 498 | } |
504 | 499 | ||
505 | int ZkbXmlHandler::str2modifier(const QString& val) { | 500 | int ZkbXmlHandler::str2modifier(const QString& val) { |
506 | int ret; | 501 | int ret; |
507 | 502 | ||
508 | #ifdef USE_ZKB_NAMES | ||
509 | int n, i; | 503 | int n, i; |
510 | ret = 0; | 504 | ret = 0; |
511 | n = 0; | 505 | n = 0; |
512 | do { | 506 | do { |
513 | i = val.find('|', n); | 507 | i = val.find('|', n); |
514 | if (i < 0) { | 508 | if (i < 0) { |
515 | i = val.length(); | 509 | i = val.length(); |
516 | } | 510 | } |
517 | 511 | ||
518 | QString s = val.mid(n, i - n); | 512 | QString s = val.mid(n, i - n); |
519 | int v = ModifierNames::find(s.stripWhiteSpace()); | 513 | int v = ModifierNames::find(s.stripWhiteSpace()); |
520 | 514 | ||
521 | if (v == -1) { | 515 | if (v == -1) { |
522 | setError("Invalid value: " + val); | 516 | setError("Invalid value: " + val); |
523 | return -1; | 517 | return -1; |
524 | } | 518 | } |
525 | 519 | ||
526 | ret |= v; | 520 | ret |= v; |
527 | n = i + 1; | 521 | n = i + 1; |
528 | } while (n < val.length()); | 522 | } while (n < val.length()); |
529 | #else | ||
530 | ret = str2uint(val); | ||
531 | #endif | ||
532 | 523 | ||
533 | return ret; | 524 | return ret; |
534 | } | 525 | } |
535 | 526 | ||
536 | bool ZkbXmlHandler::str2bool(const QString& s) { | 527 | bool ZkbXmlHandler::str2bool(const QString& s) { |
537 | if (s == "true") { | 528 | if (s == "true") { |
538 | return true; | 529 | return true; |
539 | } else { | 530 | } else { |
540 | return false; | 531 | return false; |
541 | } | 532 | } |
542 | } | 533 | } |
543 | 534 | ||
544 | int ZkbXmlHandler::str2unicode(const QString& s) { | 535 | int ZkbXmlHandler::str2unicode(const QString& s) { |
545 | return str2uint(s); | 536 | return str2uint(s); |
546 | } | 537 | } |
547 | 538 | ||
548 | int ZkbXmlHandler::str2keycode(const QString& s) { | 539 | int ZkbXmlHandler::str2keycode(const QString& s) { |
549 | int ret; | 540 | int ret; |
550 | 541 | ||
551 | #ifdef USE_ZKB_NAMES | ||
552 | ret = KeycodeNames::find(s); | 542 | ret = KeycodeNames::find(s); |
553 | if (ret == -1) { | 543 | if (ret == -1) { |
554 | setError("Invalid value: " + s); | 544 | setError("Invalid value: " + s); |
555 | } | 545 | } |
556 | 546 | ||
557 | #else | ||
558 | ret = str2uint(s); | ||
559 | #endif | ||
560 | |||
561 | return ret; | 547 | return ret; |
562 | } | 548 | } |
563 | 549 | ||
564 | int ZkbXmlHandler::str2uint(const QString& s) { | 550 | int ZkbXmlHandler::str2uint(const QString& s) { |
565 | int ret; | 551 | int ret; |
566 | bool ok; | 552 | bool ok; |
567 | QString val = s; | 553 | QString val = s; |
568 | int r; | 554 | int r; |
569 | 555 | ||
570 | if (val.left(2) == "0x") { | 556 | if (val.left(2) == "0x") { |
571 | val = s.mid(2); | 557 | val = s.mid(2); |
572 | r = 16; | 558 | r = 16; |
573 | } else if (val.left(1) == "0") { | 559 | } else if (val.left(1) == "0") { |
574 | val = s.mid(1); | 560 | val = s.mid(1); |
575 | r = 8; | 561 | r = 8; |
576 | } else { | 562 | } else { |
577 | r = 10; | 563 | r = 10; |
578 | } | 564 | } |
579 | 565 | ||
580 | ret = val.toInt(&ok, r); | 566 | ret = val.toInt(&ok, r); |
581 | if (!ok) { | 567 | if (!ok) { |
582 | setError("Invalid value: " + s); | 568 | setError("Invalid value: " + s); |
583 | ret = -1; | 569 | ret = -1; |
584 | } | 570 | } |
585 | 571 | ||
586 | return ret; | 572 | return ret; |
587 | } | 573 | } |