summaryrefslogtreecommitdiffstats
path: root/khotkeys/shared/khotkeysglobal.cpp
blob: 87fe74c38af8048130cc55516ed29e86c9142d72 (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
/****************************************************************************

 KHotKeys
 
 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>

 Distributed under the terms of the GNU General Public License version 2.
 
****************************************************************************/

#define _KHOTKEYSGLOBAL_CPP_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "khotkeysglobal.h"

#include <assert.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <klibloader.h>

#include "input.h"
#include "windows.h"
#include "triggers.h"
#include "gestures.h"
#include "voices.h"
#include "soundrecorder.h"

namespace KHotKeys
{

Kbd* keyboard_handler;
Windows* windows_handler;
static bool _khotkeys_active = false;

void init_global_data( bool active_P, TQObject* owner_P )
    {
    assert( keyboard_handler == NULL );
    assert( windows_handler == NULL );
    assert( gesture_handler == NULL );
    static_cast< void >( new Kbd( active_P, owner_P ));
    static_cast< void >( new Windows( active_P, owner_P ));
    static_cast< void >( new Gesture( active_P, owner_P ));
    static_cast< void >( new Voice( active_P, owner_P ));
    khotkeys_set_active( false );
    }
    
void khotkeys_set_active( bool active_P )
    {
    _khotkeys_active = active_P;
    }
    
bool khotkeys_active()
    {
    return _khotkeys_active;
    }
    
// does the opposite of TDEStandardDirs::findResource() i.e. e.g.
// "/opt/kde2/share/applnk/System/konsole.desktop" -> "System/konsole.desktop"
TQString get_menu_entry_from_path( const TQString& path_P )
    {
    TQStringList dirs = TDEGlobal::dirs()->resourceDirs( "apps" );
    for( TQStringList::ConstIterator it = dirs.begin();
         it != dirs.end();
         ++it )
        if( path_P.find( *it ) == 0 )
            {
            TQString ret = path_P;
            ret.remove( 0, (*it).length());
            if( ret[ 0 ] == '/' )
                ret.remove( 0, 1 );
            return ret;
            }
    return path_P;
    }

static int have_arts = -1;

bool haveArts()
    {
    if( have_arts == -1 )
        {
        have_arts = 0;
        KLibrary* arts = KLibLoader::self()->library( "khotkeys_arts" );
        if( arts == NULL )
            kdDebug( 1217 ) << "Couldn't load khotkeys_arts:" << KLibLoader::self()->lastErrorMessage() << endl;
        if( arts != NULL && SoundRecorder::init( arts ))
            have_arts = 1;
        }
    return have_arts != 0;
    }

void disableArts()
    {
    have_arts = 0;
    }

} // namespace KHotKeys