~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/keys/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * main.cpp
3
 
 *
4
 
 * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
5
 
 *
6
 
 * Requires the Qt widget libraries, available at no cost at
7
 
 * http://www.troll.no/
8
 
 *
9
 
 *  This program is free software; you can redistribute it and/or modify
10
 
 *  it under the terms of the GNU General Public License as published by
11
 
 *  the Free Software Foundation; either version 2 of the License, or
12
 
 *  (at your option) any later version.
13
 
 *
14
 
 *  This program is distributed in the hope that it will be useful,
15
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 *  GNU General Public License for more details.
18
 
 *
19
 
 *  You should have received a copy of the GNU General Public License
20
 
 *  along with this program; if not, write to the Free Software
21
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22
 
 */
23
 
 
24
 
#include <qlayout.h>
25
 
 
26
 
#include <kdebug.h>
27
 
#include <klocale.h>
28
 
#include <ksimpleconfig.h>
29
 
 
30
 
#include "commandShortcuts.h"
31
 
#include "main.h"
32
 
#include "modifiers.h"
33
 
#include "shortcuts.h"
34
 
#include "khotkeys.h"
35
 
 
36
 
/*
37
 
| Shortcut Schemes | Modifier Keys |
38
 
 
39
 
o Current scheme  o New scheme  o Pre-set scheme
40
 
| KDE Traditional |v|| <Save Scheme...> <Remove Scheme>
41
 
[] Prefer 4-modifier defaults
42
 
 
43
 
o Current scheme
44
 
o New scheme       <Save Scheme>
45
 
o Pre-set scheme   <Remove Scheme>
46
 
  | KDE Traditional |v||
47
 
[] Prefer 4-modifier defaults
48
 
 
49
 
Global Shortcuts
50
 
*/
51
 
KeyModule::KeyModule( QWidget *parent, const char *name )
52
 
: KCModule( parent, name )
53
 
{
54
 
    setQuickHelp( i18n("<h1>Keyboard Shortcuts</h1> Using shortcuts you can configure certain actions to be"
55
 
    " triggered when you press a key or a combination of keys, e.g. Ctrl+C is normally bound to"
56
 
    " 'Copy'. KDE allows you to store more than one 'scheme' of shortcuts, so you might want"
57
 
    " to experiment a little setting up your own scheme, although you can still change back to the"
58
 
    " KDE defaults.<p> In the 'Global Shortcuts' tab you can configure non-application-specific"
59
 
    " bindings, like how to switch desktops or maximize a window; in the 'Application Shortcuts' tab"
60
 
    " you will find bindings typically used in applications, such as copy and paste."));
61
 
 
62
 
        initGUI();
63
 
}
64
 
 
65
 
KeyModule::~KeyModule()
66
 
{
67
 
    KHotKeys::cleanup();
68
 
}
69
 
 
70
 
void KeyModule::initGUI()
71
 
{
72
 
        m_pTab = new QTabWidget( this );
73
 
        QVBoxLayout *l = new QVBoxLayout(this);
74
 
        l->addWidget(m_pTab);
75
 
 
76
 
        m_pShortcuts = new ShortcutsModule( this );
77
 
        m_pTab->addTab( m_pShortcuts, i18n("Shortcut Schemes") );
78
 
        connect( m_pShortcuts, SIGNAL(changed(bool)), SIGNAL(changed(bool)) );
79
 
 
80
 
        m_pCommandShortcuts = new CommandShortcutsModule ( this );
81
 
        m_pTab->addTab( m_pCommandShortcuts, i18n("Command Shortcuts") );
82
 
        connect( m_pCommandShortcuts, SIGNAL(changed(bool)), SIGNAL(changed(bool)) );
83
 
    connect( m_pTab, SIGNAL(currentChanged(QWidget*)), m_pCommandShortcuts, SLOT(showing(QWidget*)) );
84
 
 
85
 
        m_pModifiers = new ModifiersModule( this );
86
 
        m_pTab->addTab( m_pModifiers, i18n("Modifier Keys") );
87
 
        connect( m_pModifiers, SIGNAL(changed(bool)), SIGNAL(changed(bool)) );
88
 
}
89
 
 
90
 
void KeyModule::load()
91
 
{
92
 
   load( false );
93
 
}
94
 
 
95
 
// Called when [Reset] is pressed
96
 
void KeyModule::load( bool useDefaults )
97
 
{
98
 
        kdDebug(125) << "KeyModule::load()" << endl;
99
 
        m_pShortcuts->load();
100
 
        m_pCommandShortcuts->load();
101
 
        m_pModifiers->load( useDefaults );
102
 
 
103
 
   emit changed( useDefaults );
104
 
}
105
 
 
106
 
// When [Apply] or [OK] are clicked.
107
 
void KeyModule::save()
108
 
{
109
 
        kdDebug(125) << "KeyModule::save()" << endl;
110
 
        m_pShortcuts->save();
111
 
        m_pCommandShortcuts->save();
112
 
        m_pModifiers->save();
113
 
}
114
 
 
115
 
void KeyModule::defaults()
116
 
{
117
 
        kdDebug(125) << "KeyModule::defaults()" << endl;
118
 
        m_pShortcuts->defaults();
119
 
        m_pCommandShortcuts->defaults();
120
 
        m_pModifiers->defaults();
121
 
}
122
 
 
123
 
void KeyModule::resizeEvent( QResizeEvent * )
124
 
{
125
 
        m_pTab->setGeometry( 0, 0, width(), height() );
126
 
}
127
 
 
128
 
//----------------------------------------------------
129
 
 
130
 
extern "C"
131
 
{
132
 
  KDE_EXPORT KCModule *create_keys(QWidget *parent, const char * /*name*/)
133
 
  {
134
 
        // What does this do?  Why not insert klipper and kxkb, too? --ellis, 2002/01/15
135
 
        KGlobal::locale()->insertCatalogue("kwin");
136
 
        KGlobal::locale()->insertCatalogue("kdesktop");
137
 
        KGlobal::locale()->insertCatalogue("kicker");
138
 
        return new KeyModule(parent, "kcmkeys");
139
 
  }
140
 
 
141
 
  KDE_EXPORT void initModifiers()
142
 
  {
143
 
        kdDebug(125) << "KeyModule::initModifiers()" << endl;
144
 
 
145
 
        KConfigGroupSaver cgs( KGlobal::config(), "Keyboard" );
146
 
        bool bMacSwap = KGlobal::config()->readBoolEntry( "Mac Modifier Swap", false );
147
 
        if( bMacSwap )
148
 
                ModifiersModule::setupMacModifierKeys();
149
 
  }
150
 
 
151
 
  KDE_EXPORT void init_keys()
152
 
  {
153
 
        kdDebug(125) << "KeyModule::init()\n";
154
 
 
155
 
        /*kdDebug(125) << "KKeyModule::init() - Initialize # Modifier Keys Settings\n";
156
 
        KConfigGroupSaver cgs( KGlobal::config(), "Keyboard" );
157
 
        QString fourMods = KGlobal::config()->readEntry( "Use Four Modifier Keys", KAccel::keyboardHasMetaKey() ? "true" : "false" );
158
 
        KAccel::useFourModifierKeys( fourMods == "true" );
159
 
        bool bUseFourModifierKeys = KAccel::useFourModifierKeys();
160
 
        KGlobal::config()->writeEntry( "User Four Modifier Keys", bUseFourModifierKeys ? "true" : "false", true, true );
161
 
        */
162
 
        KAccelActions* keys = new KAccelActions();
163
 
 
164
 
        kdDebug(125) << "KeyModule::init() - Load Included Bindings\n";
165
 
// this should match the included files above
166
 
#define NOSLOTS
167
 
#define SHIFT Qt::SHIFT
168
 
#define CTRL Qt::CTRL
169
 
#define ALT Qt::ALT
170
 
#include "../../klipper/klipperbindings.cpp"
171
 
#include "../../kwin/kwinbindings.cpp"
172
 
#define KICKER_ALL_BINDINGS
173
 
#include "../../kicker/kicker/core/kickerbindings.cpp"
174
 
#include "../../kicker/taskbar/taskbarbindings.cpp"
175
 
#include "../../kdesktop/kdesktopbindings.cpp"
176
 
#include "../../kxkb/kxkbbindings.cpp"
177
 
 
178
 
  // Write all the global keys to kdeglobals.
179
 
  // This is needed to be able to check for conflicts with global keys in app's keyconfig
180
 
  // dialogs, kdeglobals is empty as long as you don't apply any change in controlcenter/keys.
181
 
  // However, avoid writing at every KDE startup, just update them after every rebuild of this file.
182
 
        KConfigGroup group( KGlobal::config(), "Global Shortcuts" );
183
 
        if( group.readEntry( "Defaults timestamp" ) != __DATE__ __TIME__ ) {
184
 
            kdDebug(125) << "KeyModule::init() - Read Config Bindings\n";
185
 
            // Check for old group,
186
 
            if( KGlobal::config()->hasGroup( "Global Keys" ) ) {
187
 
                keys->readActions( "Global Keys" );
188
 
                KGlobal::config()->deleteGroup( "Global Keys", true, true );
189
 
            }
190
 
            keys->readActions( "Global Shortcuts" );
191
 
            KGlobal::config()->deleteGroup( "Global Shortcuts", true, true );
192
 
 
193
 
            kdDebug(125) << "KeyModule::init() - Write Config Bindings\n";
194
 
            keys->writeActions( "Global Shortcuts", 0, true, true );
195
 
            group.writeEntry( "Defaults timestamp", __DATE__ __TIME__, true, true );
196
 
        }
197
 
        delete keys;
198
 
 
199
 
        initModifiers();
200
 
  }
201
 
}
202
 
 
203
 
#include "main.moc"