KDEUI
kkeyserver.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2001 Ellis Whitehead <ellis@kde.org> 00003 00004 Win32 port: 00005 Copyright (C) 2004 Jarosław Staniek <staniek@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "kkeyserver.h" 00024 00025 #include <config.h> 00026 #include <klocale.h> 00027 #include <kglobal.h> 00028 #include <kconfig.h> 00029 #include <kconfiggroup.h> 00030 00031 namespace KKeyServer { 00032 //--------------------------------------------------------------------- 00033 // Array Structures 00034 //--------------------------------------------------------------------- 00035 00036 struct ModInfo 00037 { 00038 int modQt; 00039 const char* psName; 00040 QString* sLabel; // this struct is used in static objects, so must use a pointer here. 00041 }; 00042 00043 //--------------------------------------------------------------------- 00044 // Arrays 00045 //--------------------------------------------------------------------- 00046 00047 // Key names with this context are extracted elsewhere, 00048 // no need for I18N_NOOP2's here. 00049 #define KEYCTXT "keyboard-key-name" 00050 static ModInfo g_rgModInfo[4] = 00051 { 00052 { Qt::SHIFT, "Shift", 0 }, 00053 { Qt::CTRL, "Ctrl", 0 }, 00054 { Qt::ALT, "Alt", 0 }, 00055 { Qt::META, "Meta", 0 } 00056 }; 00057 00058 //--------------------------------------------------------------------- 00059 // Initialization 00060 //--------------------------------------------------------------------- 00061 static bool g_bInitializedKKeyLabels; 00062 static bool g_bMacLabels; 00063 00064 static void intializeKKeyLabels() 00065 { 00066 KConfigGroup cg( KGlobal::config(), "Keyboard" ); 00067 g_rgModInfo[0].sLabel = new QString( cg.readEntry( "Label Shift", i18nc(KEYCTXT, g_rgModInfo[0].psName) ) ); 00068 g_rgModInfo[1].sLabel = new QString( cg.readEntry( "Label Ctrl", i18nc(KEYCTXT, g_rgModInfo[1].psName) ) ); 00069 g_rgModInfo[2].sLabel = new QString( cg.readEntry( "Label Alt", i18nc(KEYCTXT, g_rgModInfo[2].psName) ) ); 00070 g_rgModInfo[3].sLabel = new QString( cg.readEntry( "Label Win", i18nc(KEYCTXT, g_rgModInfo[3].psName) ) ); 00071 g_bMacLabels = (*g_rgModInfo[2].sLabel == "Command"); 00072 g_bInitializedKKeyLabels = true; 00073 00074 } 00075 00076 //--------------------------------------------------------------------- 00077 // Public functions 00078 //--------------------------------------------------------------------- 00079 00080 static QString modToString( uint mod, bool bUserSpace ) 00081 { 00082 if( bUserSpace && !g_bInitializedKKeyLabels ) 00083 intializeKKeyLabels(); 00084 00085 QString s; 00086 for( int i = 3; i >= 0; i-- ) { 00087 if( mod & g_rgModInfo[i].modQt ) { 00088 if( !s.isEmpty() ) 00089 s += '+'; 00090 s += (bUserSpace) 00091 ? *g_rgModInfo[i].sLabel 00092 : QString(g_rgModInfo[i].psName); 00093 } 00094 } 00095 return s; 00096 } 00097 00098 QString modToStringUser( uint mod ) 00099 { 00100 return modToString( mod, true ); 00101 } 00102 00103 uint stringUserToMod( const QString& mod ) 00104 { 00105 QString s; 00106 for( int i = 3; i >= 0; i-- ) { 00107 if( mod.toLower() == g_rgModInfo[i].sLabel->toLower()) 00108 return g_rgModInfo[i].modQt; 00109 } 00110 return 0; 00111 } 00112 00113 bool isShiftAsModifierAllowed( int keyQt ) 00114 { 00115 // remove any modifiers 00116 keyQt &= ~Qt::KeyboardModifierMask; 00117 00118 // Shift only works as a modifier with certain keys. It's not possible 00119 // to enter the SHIFT+5 key sequence for me because this is handled as 00120 // '%' by qt on my keyboard. 00121 // The working keys are all hardcoded here :-( 00122 if (keyQt >= Qt::Key_F1 && keyQt <= Qt::Key_F35) 00123 return true; 00124 00125 if (QChar(keyQt).isLetter()) 00126 return true; 00127 00128 switch (keyQt) { 00129 case Qt::Key_Return: 00130 case Qt::Key_Space: 00131 case Qt::Key_Backspace: 00132 case Qt::Key_Backtab: 00133 case Qt::Key_Escape: 00134 case Qt::Key_Print: 00135 case Qt::Key_ScrollLock: 00136 case Qt::Key_Pause: 00137 case Qt::Key_PageUp: 00138 case Qt::Key_PageDown: 00139 case Qt::Key_Insert: 00140 case Qt::Key_Delete: 00141 case Qt::Key_Home: 00142 case Qt::Key_End: 00143 case Qt::Key_Up: 00144 case Qt::Key_Down: 00145 case Qt::Key_Left: 00146 case Qt::Key_Right: 00147 case Qt::Key_Enter: 00148 case Qt::Key_SysReq: 00149 case Qt::Key_CapsLock: 00150 case Qt::Key_NumLock: 00151 case Qt::Key_Help: 00152 case Qt::Key_Back: 00153 case Qt::Key_Forward: 00154 case Qt::Key_Stop: 00155 case Qt::Key_Refresh: 00156 case Qt::Key_Favorites: 00157 case Qt::Key_LaunchMedia: 00158 case Qt::Key_OpenUrl: 00159 case Qt::Key_HomePage: 00160 case Qt::Key_Search: 00161 case Qt::Key_VolumeDown: 00162 case Qt::Key_VolumeMute: 00163 case Qt::Key_VolumeUp: 00164 case Qt::Key_BassBoost: 00165 case Qt::Key_BassUp: 00166 case Qt::Key_BassDown: 00167 case Qt::Key_TrebleUp: 00168 case Qt::Key_TrebleDown: 00169 case Qt::Key_MediaPlay: 00170 case Qt::Key_MediaStop: 00171 case Qt::Key_MediaPrevious: 00172 case Qt::Key_MediaNext: 00173 case Qt::Key_MediaRecord: 00174 case Qt::Key_MediaPause: 00175 case Qt::Key_MediaTogglePlayPause: 00176 case Qt::Key_LaunchMail: 00177 case Qt::Key_Calculator: 00178 case Qt::Key_Memo: 00179 case Qt::Key_ToDoList: 00180 case Qt::Key_Calendar: 00181 case Qt::Key_PowerDown: 00182 case Qt::Key_ContrastAdjust: 00183 case Qt::Key_Standby: 00184 case Qt::Key_MonBrightnessUp: 00185 case Qt::Key_MonBrightnessDown: 00186 case Qt::Key_KeyboardLightOnOff: 00187 case Qt::Key_KeyboardBrightnessUp: 00188 case Qt::Key_KeyboardBrightnessDown: 00189 case Qt::Key_PowerOff: 00190 case Qt::Key_WakeUp: 00191 case Qt::Key_Eject: 00192 case Qt::Key_ScreenSaver: 00193 case Qt::Key_WWW: 00194 case Qt::Key_Sleep: 00195 case Qt::Key_LightBulb: 00196 case Qt::Key_Shop: 00197 case Qt::Key_History: 00198 case Qt::Key_AddFavorite: 00199 case Qt::Key_HotLinks: 00200 case Qt::Key_BrightnessAdjust: 00201 case Qt::Key_Finance: 00202 case Qt::Key_Community: 00203 case Qt::Key_AudioRewind: 00204 case Qt::Key_BackForward: 00205 case Qt::Key_ApplicationLeft: 00206 case Qt::Key_ApplicationRight: 00207 case Qt::Key_Book: 00208 case Qt::Key_CD: 00209 case Qt::Key_Clear: 00210 case Qt::Key_ClearGrab: 00211 case Qt::Key_Close: 00212 case Qt::Key_Copy: 00213 case Qt::Key_Cut: 00214 case Qt::Key_Display: 00215 case Qt::Key_DOS: 00216 case Qt::Key_Documents: 00217 case Qt::Key_Excel: 00218 case Qt::Key_Explorer: 00219 case Qt::Key_Game: 00220 case Qt::Key_Go: 00221 case Qt::Key_iTouch: 00222 case Qt::Key_LogOff: 00223 case Qt::Key_Market: 00224 case Qt::Key_Meeting: 00225 case Qt::Key_MenuKB: 00226 case Qt::Key_MenuPB: 00227 case Qt::Key_MySites: 00228 case Qt::Key_News: 00229 case Qt::Key_OfficeHome: 00230 case Qt::Key_Option: 00231 case Qt::Key_Paste: 00232 case Qt::Key_Phone: 00233 case Qt::Key_Reply: 00234 case Qt::Key_Reload: 00235 case Qt::Key_RotateWindows: 00236 case Qt::Key_RotationPB: 00237 case Qt::Key_RotationKB: 00238 case Qt::Key_Save: 00239 case Qt::Key_Send: 00240 case Qt::Key_Spell: 00241 case Qt::Key_SplitScreen: 00242 case Qt::Key_Support: 00243 case Qt::Key_TaskPane: 00244 case Qt::Key_Terminal: 00245 case Qt::Key_Tools: 00246 case Qt::Key_Travel: 00247 case Qt::Key_Video: 00248 case Qt::Key_Word: 00249 case Qt::Key_Xfer: 00250 case Qt::Key_ZoomIn: 00251 case Qt::Key_ZoomOut: 00252 case Qt::Key_Away: 00253 case Qt::Key_Messenger: 00254 case Qt::Key_WebCam: 00255 case Qt::Key_MailForward: 00256 case Qt::Key_Pictures: 00257 case Qt::Key_Music: 00258 case Qt::Key_Battery: 00259 case Qt::Key_Bluetooth: 00260 case Qt::Key_WLAN: 00261 case Qt::Key_UWB: 00262 case Qt::Key_AudioForward: 00263 case Qt::Key_AudioRepeat: 00264 case Qt::Key_AudioRandomPlay: 00265 case Qt::Key_Subtitle: 00266 case Qt::Key_AudioCycleTrack: 00267 case Qt::Key_Time: 00268 case Qt::Key_Select: 00269 case Qt::Key_View: 00270 case Qt::Key_TopMenu: 00271 case Qt::Key_Suspend: 00272 case Qt::Key_Hibernate: 00273 case Qt::Key_Launch0: 00274 case Qt::Key_Launch1: 00275 case Qt::Key_Launch2: 00276 case Qt::Key_Launch3: 00277 case Qt::Key_Launch4: 00278 case Qt::Key_Launch5: 00279 case Qt::Key_Launch6: 00280 case Qt::Key_Launch7: 00281 case Qt::Key_Launch8: 00282 case Qt::Key_Launch9: 00283 case Qt::Key_LaunchA: 00284 case Qt::Key_LaunchB: 00285 case Qt::Key_LaunchC: 00286 case Qt::Key_LaunchD: 00287 case Qt::Key_LaunchE: 00288 case Qt::Key_LaunchF: 00289 return true; 00290 00291 default: 00292 return false; 00293 } 00294 } 00295 00296 }
KDE 4.7 API Reference