Ticket #2239: mythtv-lirc-20060824.diff
| File mythtv-lirc-20060824.diff, 22.8 KB (added by , 19 years ago) |
|---|
-
libs/libmythtv/tv_play.cpp
39 39 #include "DVDRingBuffer.h" 40 40 #include "datadirect.h" 41 41 #include "sourceutil.h" 42 #include "mythkeysequence.h" 42 43 43 44 #ifndef HAVE_ROUND 44 45 #define round(x) ((int) ((x) + 0.5)) … … 608 609 { 609 610 query.next(); 610 611 611 QKeySequence keyseq(query.value(0).toString());612 MythKeySequence keyseq(query.value(0).toString()); 612 613 613 int keynum = keyseq[0] ;614 int keynum = keyseq[0]->value(); 614 615 keynum &= ~Qt::UNICODE_ACCEL; 615 616 616 617 keyList.prepend(new QKeyEvent(QEvent::KeyPress, keynum, 0, 0)); -
libs/libmythui/mythmainwindow.cpp
40 40 #include "mythcontext.h" 41 41 #include "mythdbcon.h" 42 42 #include "mythgesture.h" 43 #include "mythkeysequence.h" 43 44 44 45 /* from libmyth */ 45 46 #include "screensaver.h" … … 95 96 class KeyContext 96 97 { 97 98 public: 98 void AddMapping( intkey, QString action)99 void AddMapping(QString key, QString action) 99 100 { 100 101 actionMap[key].append(action); 101 102 } 103 void AddMapping(int key, QString action) 104 { 105 QString keystr; 106 keystr.setNum(key); 107 actionMap[keystr].append(action); 108 } 102 109 103 bool GetMapping( intkey, QStringList &actions)110 bool GetMapping(QString key, QStringList &actions) 104 111 { 105 112 if (actionMap.count(key) > 0) 106 113 { … … 109 116 } 110 117 return false; 111 118 } 119 bool GetMapping(int key, QStringList &actions) 120 { 121 QString keystr; 122 keystr.setNum(key); 123 return GetMapping(keystr, actions); 124 } 112 125 113 QMap<int, QStringList> actionMap; 126 //QMap<int, QStringList> actionMap; 127 QMap<QString, QStringList> actionMap; 114 128 }; 115 129 116 130 struct JumpData … … 153 167 bool popwindows; 154 168 155 169 QDict<KeyContext> keyContexts; 156 QMap<int, JumpData*> jumpMap; 170 //QMap<int, JumpData*> jumpMap; 171 QMap<QString, JumpData*> jumpMap; 157 172 QMap<QString, JumpData> destinationMap; 158 173 QMap<QString, MHData> mediaHandlerMap; 159 174 QMap<QString, MPData> mediaPluginMap; … … 649 664 0, Qt::NoButton); 650 665 QObject *key_target = getTarget(*key); 651 666 QApplication::postEvent(key_target, key); 667 return; 652 668 } 653 669 return; 654 670 } … … 672 688 QKeyEvent *key = new QKeyEvent(QEvent::KeyPress, d->escapekey, 673 689 0, Qt::NoButton); 674 690 QApplication::postEvent(this, key); 691 return; 675 692 } 676 693 return; 677 694 } … … 705 722 { 706 723 actions.clear(); 707 724 int keynum = d->TranslateKeyNum(e); 725 bool retval = false; 708 726 727 QString keystr; 728 keystr.setNum( keynum ); 729 730 #ifdef USE_LIRC 731 /* If there's LIRC support, we must check for those here -- check the 732 * remoteXXXXX identifiers; 733 */ 734 if ((e->ascii( ) == 0) && (e->key( ) == 0) && (e->text( ).left(6) == "remote")) 735 { 736 VERBOSE(VB_GENERAL, QString("MythMainWindow::TranslateKeyPress() - Remote button '%1' received in context '%2'.") 737 .arg(e->text( )).arg(context.latin1()) ); 738 739 if (allowJumps && 740 d->jumpMap.count(e->text()) > 0 && d->exitmenucallback == NULL) 741 { 742 d->exitingtomain = true; 743 d->exitmenucallback = d->jumpMap[ e->text() ]->callback; 744 QApplication::postEvent(this, new ExitToMainMenuEvent()); 745 return false; 746 } 747 748 749 if ((d->keyContexts[context]) && 750 (d->keyContexts[context]->GetMapping( e->text(), actions))) 751 { 752 retval = true; 753 } 754 755 756 if ((context != "Global") && 757 (d->keyContexts["Global"]->GetMapping( e->text(), actions ))) 758 { 759 retval = true; 760 } 761 762 return retval; 763 } 764 765 #endif // USE_LIRC 766 709 767 if (allowJumps && 710 d->jumpMap.count(key num) > 0 && d->exitmenucallback == NULL)768 d->jumpMap.count(keystr) > 0 && d->exitmenucallback == NULL) 711 769 { 712 770 d->exitingtomain = true; 713 d->exitmenucallback = d->jumpMap[key num]->callback;771 d->exitmenucallback = d->jumpMap[keystr]->callback; 714 772 QApplication::postEvent(this, new ExitToMainMenuEvent()); 715 773 return false; 716 774 } 717 775 718 bool retval = false;719 776 720 777 if (d->keyContexts[context]) 721 778 { 722 if (d->keyContexts[context]->GetMapping(key num, actions))779 if (d->keyContexts[context]->GetMapping(keystr, actions)) 723 780 retval = true; 724 781 } 725 782 726 783 if (context != "Global" && 727 d->keyContexts["Global"]->GetMapping(key num, actions))784 d->keyContexts["Global"]->GetMapping(keystr, actions)) 728 785 { 729 786 retval = true; 730 787 } … … 737 794 KeyContext * keycontext = d->keyContexts[context]; 738 795 if (keycontext == NULL) return; 739 796 740 QMap<int,QStringList>::Iterator it; 797 //QMap<int,QStringList>::Iterator it; 798 QMap<QString,QStringList>::Iterator it; 741 799 for (it = keycontext->actionMap.begin(); 742 800 it != keycontext->actionMap.end(); 743 801 it++) … … 763 821 void MythMainWindow::BindKey(const QString &context, const QString &action, 764 822 const QString &key) 765 823 { 766 QKeySequence keyseq(key);824 MythKeySequence keyseq(key); 767 825 768 826 if (!d->keyContexts[context]) 769 827 d->keyContexts.insert(context, new KeyContext()); 770 828 771 829 for (unsigned int i = 0; i < keyseq.count(); i++) 772 830 { 773 int keynum = keyseq[i] ;831 int keynum = keyseq[i]->value(); 774 832 keynum &= ~Qt::UNICODE_ACCEL; 833 QString keystr; 834 #ifdef USE_LIRC 835 if(keyseq[i]->isRemote()) keystr = keyseq[i]->text(); 836 else // intensional 837 #endif // USE_LIRC 838 keystr.setNum( keynum ); 775 839 776 840 QStringList dummyaction = ""; 777 if (d->keyContexts[context]->GetMapping(key num, dummyaction))841 if (d->keyContexts[context]->GetMapping(keystr, dummyaction)) 778 842 { 779 843 VERBOSE(VB_GENERAL, QString("Key %1 is bound to multiple actions " 780 844 "in context %2.") 781 845 .arg(key).arg(context)); 782 846 } 783 847 784 d->keyContexts[context]->AddMapping(key num, action);848 d->keyContexts[context]->AddMapping(keystr, action); 785 849 //VERBOSE(VB_GENERAL, QString("Binding: %1 to action: %2 (%3)") 786 850 // .arg(key).arg(action) 787 851 // .arg(context)); … … 868 932 return; 869 933 } 870 934 871 QMap<int, JumpData*>::Iterator it; 935 // QMap<int, JumpData*>::Iterator it; 936 QMap<QString, JumpData*>::Iterator it; 872 937 for (it = d->jumpMap.begin(); it != d->jumpMap.end(); ++it) 873 938 { 874 939 … … 888 953 return; 889 954 } 890 955 891 QKeySequence keyseq(key);956 MythKeySequence keyseq(key); 892 957 893 958 for (unsigned int i = 0; i < keyseq.count(); i++) 894 959 { 895 int keynum = keyseq[i] ;960 int keynum = keyseq[i]->value(); 896 961 keynum &= ~Qt::UNICODE_ACCEL; 962 QString keystr; 963 #ifdef USE_LIRC 964 if (keyseq[i]->isRemote()) keystr = keyseq[i]->text(); 965 else // intensional 966 #endif 967 keystr.setNum( keynum ); 897 968 898 if (d->jumpMap.count( keynum) == 0)969 if (d->jumpMap.count( keystr ) == 0) 899 970 { 900 971 //VERBOSE(VB_GENERAL, QString("Binding: %1 to JumpPoint: %2") 901 972 // .arg(keybind).arg(destination)); 902 903 d->jumpMap[ keynum] = &d->destinationMap[destination];973 974 d->jumpMap[ keystr ] = &d->destinationMap[destination]; 904 975 } 905 976 else 906 977 { 907 VERBOSE(VB_GENERAL, QString(" Key%1 is already bound to a jump "908 "point.").arg(key ));978 VERBOSE(VB_GENERAL, QString("%1 is already bound to a jump " 979 "point.").arg(keystr)); 909 980 } 981 //else 982 // VERBOSE(VB_GENERAL, QString("JumpPoint: %2 exists, no keybinding") 983 // .arg(destination)); 910 984 } 911 //else912 // VERBOSE(VB_GENERAL, QString("JumpPoint: %2 exists, no keybinding")913 // .arg(destination));914 915 985 } 916 986 917 987 void MythMainWindow::RegisterJump(const QString &destination, … … 1259 1329 LircKeycodeEvent *lke = (LircKeycodeEvent *)ce; 1260 1330 int keycode = lke->getKeycode(); 1261 1331 1262 if ( keycode)1332 if (lke->getLircText().left(6) == "remote") 1263 1333 { 1334 /* Attempt to send this to the application; 1335 */ 1336 VERBOSE(VB_GENERAL, QString("MythMainWindow::customEvent() - Sending '%1' to keypress-handler.") 1337 .arg(lke->getLircText()) ); 1338 1339 /* Send a press & release -- abusing the Unicode field for 1340 * passing the LIRC logical identifier. 1341 */ 1342 QKeyEvent keyp( QEvent::KeyPress, 0, 0, 0, lke->getLircText( ) ); 1343 QKeyEvent keyr( QEvent::KeyRelease, 0, 0, 0, lke->getLircText( ) ); 1344 1345 QObject *key_target = getTarget(keyp); 1346 1347 if (!key_target) 1348 { 1349 QApplication::sendEvent( this, &keyp ); 1350 QApplication::sendEvent( this, &keyr ); 1351 } 1352 else 1353 { 1354 QApplication::sendEvent( key_target, &keyp ); 1355 QApplication::sendEvent( key_target, &keyr ); 1356 } 1357 } 1358 else if (keycode) 1359 { 1264 1360 gContext->ResetScreensaver(); 1265 1361 if (gContext->GetScreenIsAsleep()) 1266 1362 return; -
libs/libmyth/lirc.cpp
15 15 #include "lirc.h" 16 16 #include "lircevent.h" 17 17 #include "util.h" 18 #include "mythkeysequence.h" 18 19 19 20 #if (QT_VERSION < 0x030100) 20 21 #error Native LIRC support requires Qt 3.1 or greater. … … 72 73 while ((ret = lirc_code2char(lircConfig, ir, &code)) == 0 && 73 74 code != NULL) 74 75 { 75 QKeySequence a(code);76 MythKeySequence a(code); 76 77 77 78 int keycode = 0; 78 79 … … 85 86 86 87 for (unsigned int i = 0; i < a.count(); i++) 87 88 { 88 keycode = a[i]; 89 90 QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 89 if (a[i]->isRemote()) // is really bound to a remoteXXX 90 { 91 QApplication::postEvent(mainWindow, new LircKeycodeEvent( a[i]->text().latin1(), 0, true )); 92 } 93 else 94 { 95 keycode = a[i]->value( ); 96 QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 91 97 keycode, true)); 92 QApplication::postEvent(mainWindow, new LircKeycodeEvent(code,98 QApplication::postEvent(mainWindow, new LircKeycodeEvent(code, 93 99 keycode, false)); 94 100 101 } 102 95 103 SpawnApp(); 96 104 } 97 105 } -
libs/libmyth/jsmenu.cpp
32 32 #include <fcntl.h> 33 33 34 34 #include "mythcontext.h" 35 #include "mythkeysequence.h" 35 36 36 37 #include <iostream> 37 38 using namespace std; … … 292 293 **--------------------------------------------------------------------------*/ 293 294 void JoystickMenuClient::EmitKey(QString code) 294 295 { 295 QKeySequence a(code);296 MythKeySequence a(code); 296 297 297 298 int keycode = 0; 298 299 … … 305 306 306 307 for (unsigned int i = 0; i < a.count(); i++) 307 308 { 308 keycode = a[i] ;309 keycode = a[i]->value(); 309 310 310 311 QApplication::postEvent(mainWindow, new JoystickKeycodeEvent(code, 311 312 keycode, true)); -
libs/libmyth/libmyth.pro
19 19 HEADERS += dbsettings.h screensaver-null.h output.h visual.h 20 20 HEADERS += langsettings.h audiooutputnull.h mythsocket.h 21 21 HEADERS += DisplayResScreen.h util-x11.h mythdeque.h qmdcodec.h 22 HEADERS += exitcodes.h virtualkeyboard.h mythobservable.h mythevent.h 22 HEADERS += exitcodes.h virtualkeyboard.h mythobservable.h mythevent.h mythkeysequence.h 23 23 24 24 SOURCES += dialogbox.cpp lcddevice.cpp mythcontext.cpp mythwidgets.cpp 25 25 SOURCES += oldsettings.cpp remotefile.cpp settings.cpp … … 31 31 SOURCES += dbsettings.cpp screensaver.cpp screensaver-null.cpp output.cpp 32 32 SOURCES += langsettings.cpp mythdbcon.cpp audiooutputnull.cpp 33 33 SOURCES += DisplayResScreen.cpp util-x11.cpp qmdcodec.cpp 34 SOURCES += virtualkeyboard.cpp mythobservable.cpp mythsocket.cpp 34 SOURCES += virtualkeyboard.cpp mythobservable.cpp mythsocket.cpp mythkeysequence.cpp 35 35 36 36 INCLUDEPATH += ../libmythsamplerate ../libmythsoundtouch ../.. ../ 37 37 DEPENDPATH += ../libmythsamplerate ../libmythsoundtouch ../ ../libmythui -
libs/libmyth/mythkeysequence.h
1 /* 2 * File: mythkeysequence.h 3 * 4 * Purpose: This implements the MythKeySequence class. QKeySequence cannot 5 * be easily extended not to ignore 'remoteXXX' identifiers. 6 * 7 * This replacement class fixes that and removes the need for 8 * some duplicate code in MythTV and the MythControls-plugin. 9 * 10 * History: 11 * 12 * 20060620 13 * - Renamed member routine 'keyNum()' to 'value()'. 14 * - Bugfixed problem with 'F1,M,{,<' only assigning 3 keys. 15 * - Max.length of sequence configurable through #define MYTHKEY_SEQLEN. 16 */ 17 18 #ifndef _KEYSEQ_H_ 19 #define _KEYSEQ_H_ 20 21 #include <qobject.h> 22 #include <qkeysequence.h> 23 24 /* The #define's below define internal features; 25 ***********************************************/ 26 27 // Maximum length of KeySequence -- default same as QKeySequence: 28 #ifndef MYTHKEY_SEQLEN 29 30 #define MYTHKEY_SEQLEN 4 31 #else 32 33 #warning MYTHKEY_SEQLEN is already defined -- skipping assignment. 34 #endif 35 36 37 /******************** MythKeySequence / MythKey classes **********************/ 38 class MythKeySequence; 39 40 class MythKey : public QObject 41 { 42 Q_OBJECT 43 44 public: 45 MythKey( ); 46 MythKey( const int ); 47 MythKey( const QString ); 48 49 /* Assign the key */ 50 bool setKey( const int ); 51 bool setKey( const QString ); 52 void clear( ); 53 54 /* Text representation, ie. Ctrl+PgUp, or remoteGUIDE */ 55 QString text( ); 56 /* Numeric value, only valid if Keys */ 57 int value( ); 58 /* More query stuff */ 59 bool isRemote( ); 60 bool isAssigned( ); 61 62 operator int(); 63 64 private: 65 bool key_assigned; /* .. */ 66 int is_button; /* Key is a button, i.e. not coming from a keyboard */ 67 68 int key_num; /* Integer representation of key (is 0 for remote buttons) */ 69 QString key_str; /* Text representation of key / button */ 70 71 friend class MythKeySequence; 72 }; 73 74 class MythKeySequence : public QObject 75 { 76 Q_OBJECT 77 78 public: 79 MythKeySequence( ); 80 MythKeySequence( int k1, int k2=0, int k3=0, int k4=0 ); 81 MythKeySequence( const QString & ); 82 83 /* Assign multiple keys */ 84 uint setKeys( const QString & ); 85 86 /* Query stuff */ 87 bool isEmpty( ); 88 void clear( ); 89 uint count( ); 90 91 MythKey* operator[]( int index ); 92 bool operator ==( const MythKeySequence & ); 93 operator QString( ); 94 95 MythKey keys[ MYTHKEY_SEQLEN ]; 96 97 private: 98 uint keys_assigned; 99 }; 100 101 #endif // _KEYSEQ_H_ -
libs/libmyth/mythkeysequence.cpp
1 /* 2 * File: mythkeysequence.cpp 3 * 4 * Purpose: See mythkeysequence.h 5 */ 6 #include <mythkeysequence.h> 7 8 /*** MythKey *** 9 ***************/ 10 MythKey::MythKey( ) 11 { 12 this->clear( ); 13 } 14 15 MythKey::MythKey( const int key ) 16 { 17 if (!(this->setKey( key ))) 18 this->clear( ); 19 } 20 21 MythKey::MythKey( const QString key ) 22 { 23 if (!(this->setKey( key ))) 24 this->clear( ); 25 } 26 27 /* MythKey member routines */ 28 void MythKey::clear( ) 29 { 30 this->key_assigned = false; 31 this->key_str = ""; 32 this->key_num = 0; 33 } 34 35 bool MythKey::setKey( const int key ) 36 { 37 bool retval = false; 38 39 // Passed by key-num are keys, no buttons 40 this->is_button = 0; 41 QKeySequence keyseq( key ); 42 if (keyseq.count( ) > 0) 43 { 44 retval = true; 45 this->key_num = keyseq[ 0 ]; 46 this->key_str = QString(keyseq); 47 } 48 this->key_assigned = retval; 49 return retval; 50 } 51 52 bool MythKey::isRemote( ) 53 { 54 return this->is_button; 55 } 56 57 bool MythKey::isAssigned( ) 58 { 59 return this->key_assigned; 60 } 61 62 bool MythKey::setKey( const QString key ) 63 { 64 this->key_assigned = false; 65 bool retval = false; 66 if (key.left( 6 ).lower( ) == "remote") 67 { 68 retval = true; 69 this->is_button = 1; 70 71 /* Use this value as-is, no checking at all */ 72 this->key_str = key; 73 this->key_num = 0; 74 } 75 else 76 { 77 this->is_button = 0; 78 79 /* Use the QKeySequence to check this key's validity and to set 80 * appropriate fields. We pass ',,' to make the QKeySequence 81 * see the ',' because it'll fail on a *single* ',' */ 82 QString keystr = key.stripWhiteSpace( ); 83 QKeySequence keyseq( (keystr == ","?",,":keystr) ); 84 if (keyseq[ 0 ]) 85 { 86 retval = true; 87 this->key_num = keyseq[ 0 ]; 88 this->key_str = key.stripWhiteSpace( ); 89 } 90 // else printf( "no keyseq\n" ); 91 } 92 93 this->key_assigned = retval; 94 return retval; 95 } 96 97 98 QString MythKey::text( ) 99 { 100 if (this->key_assigned) 101 { 102 if (this->key_str.length() == 0) 103 { 104 QString key; 105 key.setNum( this->key_num ); 106 return key; 107 } 108 else return this->key_str; 109 } 110 111 return ""; 112 } 113 114 int MythKey::value( ) 115 { 116 if (this->key_assigned) 117 return this->key_num; 118 else 119 return 0; 120 } 121 122 MythKey::operator int( ) 123 { 124 return this->value( ); 125 } 126 127 128 /*** MythKeySequence *** 129 ***********************/ 130 MythKeySequence::MythKeySequence( ) 131 { 132 this->clear( ); 133 } 134 135 MythKeySequence::MythKeySequence( int k1, int k2, int k3, int k4 ) 136 { 137 uint k_index = 0; 138 139 if (k1 > 0) this->keys[ ++k_index ].setKey( k1 ); 140 if (k2 > 0) this->keys[ ++k_index ].setKey( k2 ); 141 if (k3 > 0) this->keys[ ++k_index ].setKey( k3 ); 142 if (k4 > 0) this->keys[ ++k_index ].setKey( k4 ); 143 } 144 145 MythKeySequence::MythKeySequence( const QString &keys ) 146 { 147 this->setKeys( keys ); 148 } 149 150 151 /* MythKeySequence member routines */ 152 uint MythKeySequence::setKeys( const QString &keys ) 153 { 154 unsigned int token_start = 0, k_index = 0, new_start; 155 unsigned int i, max=keys.length(); 156 unsigned char c_last = 0; 157 bool fc = (keys[ 0 ] == ","), lc = false; 158 int commas = (fc?1:0); 159 int do_comma, do_token; 160 // 161 for (i=1; i< max; i++) 162 { 163 do_comma=do_token=0; 164 if (keys[i] == ",") 165 { 166 /* Got a comma -- if this is the first one there 167 * could be a token before it. */ 168 if ((!lc) && (i>1)) do_token=1; 169 else token_start = i + 1; 170 171 lc=true; 172 commas++; 173 174 /* If we reached the end here at 2 comma's, we 175 * should register one. */ 176 if ((commas == 2) && (i == max - 1)) 177 { 178 do_comma = 1; 179 new_start = i; 180 } 181 } 182 else 183 { 184 /* No comma -- still in a token. 185 */ 186 if (commas == 0) 187 { 188 if (i==max-1) 189 { 190 i = max; 191 do_token=1; 192 193 new_start = i + 1; 194 } 195 } 196 else if ((commas == 2) && (fc)) 197 { 198 do_comma = 1; 199 new_start = i; 200 } 201 else if ((commas == 2) && (i == max - 1)) 202 { 203 do_comma = 1; 204 new_start = i; 205 } 206 else if (commas == 3) 207 { 208 if (i < max - 1) 209 { 210 do_comma = 1; 211 new_start = i; 212 } 213 } 214 215 fc=lc=false; 216 commas = 0; 217 } 218 219 if (do_token || do_comma) 220 { 221 if (k_index < MYTHKEY_SEQLEN) 222 { 223 if (this->keys[ k_index ].setKey( do_comma?",":keys.mid( token_start, i - token_start ) )) 224 k_index++; 225 } 226 227 token_start = i + do_token; //new_start; 228 } 229 230 } // for(.. 231 232 if (max == 1) 233 { 234 this->keys[ k_index++ ].setKey( keys.stripWhiteSpace() ); 235 } 236 else if ( (c_last != ',') && (c_last != keys.mid( token_start )) && (k_index < MYTHKEY_SEQLEN) ) 237 { 238 this->keys[ k_index++ ].setKey( keys.mid( token_start ) ); 239 } 240 241 this->keys_assigned = k_index; 242 return k_index; 243 } 244 245 uint MythKeySequence::count( ) 246 { 247 return this->keys_assigned; 248 } 249 250 void MythKeySequence::clear( ) 251 { 252 this->keys_assigned = 0; 253 254 for(int i=0; i<MYTHKEY_SEQLEN; i++) 255 this->keys[ i ].clear( ); 256 } 257 258 259 MythKey* MythKeySequence::operator[]( int index ) 260 { 261 if( (index >= 0) && (index < MYTHKEY_SEQLEN) ) 262 return &(this->keys[ index ]); 263 return 0; 264 } 265 266 MythKeySequence::operator QString( ) 267 { 268 QString retval = ""; 269 for (uint i=0; i<MYTHKEY_SEQLEN; i++) 270 { 271 if (this->keys[i].key_assigned) 272 { 273 if (retval != "") retval += ", "; 274 retval += this->keys[i].text( ); 275 } 276 } 277 return retval; 278 }
