File indexing completed on 2024-10-13 10:45:58
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-only 0003 SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org> 0004 */ 0005 0006 #define _KHOTKEYSGLOBAL_CPP_ 0007 0008 #include "khotkeysglobal.h" 0009 0010 #include <KGlobal> 0011 #include <QDebug> 0012 #include <kstandarddirs.h> 0013 0014 #include "input.h" 0015 #include "shortcuts_handler.h" 0016 #include "triggers/gestures.h" 0017 #include "triggers/triggers.h" 0018 #include "windows_handler.h" 0019 0020 namespace KHotKeys 0021 { 0022 QPointer<ShortcutsHandler> keyboard_handler = nullptr; 0023 QPointer<WindowsHandler> windows_handler = nullptr; 0024 0025 static bool _khotkeys_active = false; 0026 0027 void init_global_data(bool active_P, QObject *owner_P) 0028 { 0029 // Make these singletons. 0030 if (!keyboard_handler) { 0031 keyboard_handler = new ShortcutsHandler(active_P ? ShortcutsHandler::Active : ShortcutsHandler::Configuration, owner_P); 0032 } 0033 if (!windows_handler) { 0034 windows_handler = new WindowsHandler(active_P, owner_P); 0035 } 0036 if (!gesture_handler) { 0037 gesture_handler = new Gesture(active_P, owner_P); 0038 } 0039 khotkeys_set_active(false); 0040 } 0041 0042 void khotkeys_set_active(bool active_P) 0043 { 0044 _khotkeys_active = active_P; 0045 } 0046 0047 bool khotkeys_active() 0048 { 0049 return _khotkeys_active; 0050 } 0051 0052 // does the opposite of KStandardDirs::findResource() i.e. e.g. 0053 // "/opt/kde2/share/applnk/System/konsole.desktop" -> "System/konsole.desktop" 0054 QString get_menu_entry_from_path(const QString &path_P) 0055 { 0056 const QStringList dirs = KGlobal::dirs()->resourceDirs("apps"); 0057 for (QStringList::ConstIterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) 0058 if (path_P.indexOf(*it) == 0) { 0059 QString ret = path_P; 0060 ret.remove(0, (*it).length()); 0061 if (ret[0] == '/') 0062 ret.remove(0, 1); 0063 return ret; 0064 } 0065 return path_P; 0066 } 0067 0068 } // namespace KHotKeys