2 Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
5 Copyright (C) 2004 Jarosław Staniek <staniek@kde.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include "kkeyserver.h"
29 #include <kconfiggroup.h>
31 namespace KKeyServer
{
32 //---------------------------------------------------------------------
34 //---------------------------------------------------------------------
40 QString
* sLabel
; // this struct is used in static objects, so must use a pointer here.
43 //---------------------------------------------------------------------
45 //---------------------------------------------------------------------
47 // Key names with this context are extracted elsewhere,
48 // no need for I18N_NOOP2's here.
49 #define KEYCTXT "keyboard-key-name"
50 static ModInfo g_rgModInfo
[4] =
52 { Qt::SHIFT
, "Shift", 0 },
53 { Qt::CTRL
, "Ctrl", 0 },
54 { Qt::ALT
, "Alt", 0 },
55 { Qt::META
, "Meta", 0 }
58 //---------------------------------------------------------------------
60 //---------------------------------------------------------------------
61 static bool g_bInitializedKKeyLabels
;
62 static bool g_bMacLabels
;
64 static void intializeKKeyLabels()
66 KConfigGroup
cg( KGlobal::config(), "Keyboard" );
67 g_rgModInfo
[0].sLabel
= new QString( cg
.readEntry( "Label Shift", i18nc(KEYCTXT
, g_rgModInfo
[0].psName
) ) );
68 g_rgModInfo
[1].sLabel
= new QString( cg
.readEntry( "Label Ctrl", i18nc(KEYCTXT
, g_rgModInfo
[1].psName
) ) );
69 g_rgModInfo
[2].sLabel
= new QString( cg
.readEntry( "Label Alt", i18nc(KEYCTXT
, g_rgModInfo
[2].psName
) ) );
70 g_rgModInfo
[3].sLabel
= new QString( cg
.readEntry( "Label Win", i18nc(KEYCTXT
, g_rgModInfo
[3].psName
) ) );
71 g_bMacLabels
= (*g_rgModInfo
[2].sLabel
== "Command");
72 g_bInitializedKKeyLabels
= true;
76 //---------------------------------------------------------------------
78 //---------------------------------------------------------------------
80 static QString
modToString( uint mod
, bool bUserSpace
)
82 if( bUserSpace
&& !g_bInitializedKKeyLabels
)
83 intializeKKeyLabels();
86 for( int i
= 3; i
>= 0; i
-- ) {
87 if( mod
& g_rgModInfo
[i
].modQt
) {
91 ? *g_rgModInfo
[i
].sLabel
92 : QString(g_rgModInfo
[i
].psName
);
98 QString
modToStringUser( uint mod
)
100 return modToString( mod
, true );
103 uint
stringUserToMod( const QString
& mod
)
106 for( int i
= 3; i
>= 0; i
-- ) {
107 if( mod
.toLower() == g_rgModInfo
[i
].sLabel
->toLower())
108 return g_rgModInfo
[i
].modQt
;