summaryrefslogtreecommitdiffstats
path: root/kcontrol/keys/khotkeys.cpp
blob: 636cd972c328d2f2573cdfa24019b9b5e4b9cffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
 *                      Lubos Lunak    <l.lunak@email.cz>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#include <klibloader.h>
#include "khotkeys.h"

extern "C"
{
    static void (*khotkeys_init_2)( void );
    static void (*khotkeys_cleanup_2)( void );
    static TQString (*khotkeys_get_menu_entry_shortcut_2)( const TQString& entry_P );
    static TQString (*khotkeys_change_menu_entry_shortcut_2)( const TQString& entry_P,
                                                             const TQString& shortcut_P );
    static bool (*khotkeys_menu_entry_moved_2)( const TQString& new_P, const TQString& old_P );
    static void (*khotkeys_menu_entry_deleted_2)( const TQString& entry_P );
}

static bool khotkeys_present = false;
static bool khotkeys_inited = false;

bool KHotKeys::init()
{
    khotkeys_inited = true;
    KLibrary* lib = KLibLoader::self()->library( "kcm_khotkeys.la" );
    if( lib == NULL ) return false;

    khotkeys_init_2 = ( void (*)(void)) ( lib->symbol( "khotkeys_init" ));
    khotkeys_cleanup_2 = ( void (*)(void)) ( lib->symbol( "khotkeys_cleanup" ));
    khotkeys_get_menu_entry_shortcut_2 =
        ( TQString (*)( const TQString& ))
        ( lib->symbol( "khotkeys_get_menu_entry_shortcut" ));
    khotkeys_change_menu_entry_shortcut_2 =
        ( TQString (*)( const TQString&, const TQString& ))
        ( lib->symbol( "khotkeys_change_menu_entry_shortcut" ));
    khotkeys_menu_entry_moved_2 =
        ( bool (*)( const TQString&, const TQString& ))
        ( lib->symbol( "khotkeys_menu_entry_moved" ));
    khotkeys_menu_entry_deleted_2 =
        ( void (*)( const TQString& ))
        ( lib->symbol( "khotkeys_menu_entry_deleted" ));
    if( khotkeys_init_2
        && khotkeys_cleanup_2
        && khotkeys_get_menu_entry_shortcut_2
        && khotkeys_change_menu_entry_shortcut_2
        && khotkeys_menu_entry_moved_2
        && khotkeys_menu_entry_deleted_2 )
    {
        khotkeys_init_2();
        khotkeys_present = true;
        return true;
    }
    return false;
}

void KHotKeys::cleanup()
{
    if( khotkeys_inited )
        khotkeys_cleanup_2();
    khotkeys_inited = false;
}

bool KHotKeys::present()
{
    if( !khotkeys_inited )
        init();
    return khotkeys_present;
}

TQString KHotKeys::getMenuEntryShortcut( const TQString& entry_P )
{
    if( !khotkeys_inited )
        init();
    if( !khotkeys_present )
        return "";
    return khotkeys_get_menu_entry_shortcut_2( entry_P );
}

TQString KHotKeys::changeMenuEntryShortcut( const TQString& entry_P,
    const TQString shortcut_P )
    {
    if( !khotkeys_inited )
        init();
    if( !khotkeys_present )
        return "";
    return khotkeys_change_menu_entry_shortcut_2( entry_P, shortcut_P );
    }

bool KHotKeys::menuEntryMoved( const TQString& new_P, const TQString& old_P )
{
    if( !khotkeys_inited )
        init();
    if( !khotkeys_present )
        return "";
    return khotkeys_menu_entry_moved_2( new_P, old_P );
}

void KHotKeys::menuEntryDeleted( const TQString& entry_P )
{
    if( !khotkeys_inited )
        init();
    if( !khotkeys_present )
        return;
    khotkeys_menu_entry_deleted_2( entry_P );
}