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 #ifndef _SETTINGS_H_ 0007 #define _SETTINGS_H_ 0008 0009 #include "action_data/action_data_group.h" 0010 #include "actions/actions.h" 0011 #include <kshortcut.h> 0012 0013 class KConfig; 0014 class KConfigBase; 0015 0016 namespace KHotKeys 0017 { 0018 class ActionDataGroup; 0019 0020 /** 0021 * How to handle imports. 0022 */ 0023 enum ImportType { 0024 ImportNone, //!< no import is done 0025 ImportAsk, //!< if already imported before, ask (called from GUI) 0026 ImportSilent, //!< if already imported before, ignore (called from the update script) 0027 }; 0028 0029 enum ActionState { 0030 Retain, //!< Keep the current state 0031 Enabled, //!< Enable all actions 0032 Disabled, //!< Disable all actions 0033 }; 0034 0035 /** 0036 * Handles KHotKeys Settings. 0037 * 0038 * Settings are saved to the khotkeysrc file. 0039 */ 0040 class Q_DECL_EXPORT Settings 0041 { 0042 Q_DISABLE_COPY(Settings) 0043 0044 public: 0045 Settings(); 0046 ~Settings(); 0047 0048 /** 0049 * Get the system group. 0050 */ 0051 ActionDataGroup *get_system_group(ActionDataGroup::system_group_t group_id); 0052 0053 /** 0054 * Read the settings. 0055 * 0056 * \param include_disabled_P Load disabled shortcuts? 0057 */ 0058 bool reread_settings(bool include_disabled = true); 0059 0060 /** 0061 * Update the settings. 0062 * 0063 * Checks if updates are available and imports them if not yet done. 0064 */ 0065 bool update(); 0066 0067 /** 0068 * Write the settings. 0069 */ 0070 void write(); 0071 0072 /** 0073 * Export settings to @a config. 0074 * 0075 * @param id use id for the exported file. 0076 * @param state state to use for exported actions 0077 */ 0078 void exportTo(ActionDataBase *what, KConfigBase &config, const QString &id, ActionState state, bool allowMerging); 0079 0080 /** 0081 * Import settings from \a cfg_P. 0082 */ 0083 bool import(KConfig &cfg_P, ImportType ask, ActionState state); 0084 0085 bool importFrom(ActionDataGroup *parent, KConfigBase const &config, ImportType ask, ActionState state); 0086 0087 /** 0088 * Get all actions 0089 */ 0090 ActionDataGroup *actions(); 0091 const ActionDataGroup *actions() const; 0092 0093 /** 0094 * Take the actions. 0095 * 0096 * \note Ownership is transferred to you. Subsequent calls to action() will 0097 * return 0 0098 */ 0099 ActionDataGroup *takeActions(); 0100 0101 /** 0102 * Set the actions. 0103 * 0104 * \note Ownership is taken. The current action list will be deleted. If 0105 * \@a actions is nullptr the method will create a new ActionDataGroup 0106 */ 0107 void setActions(ActionDataGroup *actions); 0108 0109 /** 0110 * @name KHotkeys Daemon 0111 */ 0112 //@{ 0113 /** 0114 * Disable the daemon. 0115 */ 0116 void disableDaemon(); 0117 0118 /** 0119 * Enable the daemon. 0120 */ 0121 void enableDaemon(); 0122 0123 /** 0124 * Is the daemon disabled? 0125 */ 0126 bool isDaemonDisabled() const; 0127 //@} 0128 0129 /** 0130 * Load the default settings 0131 */ 0132 bool loadDefaults(); 0133 0134 /** 0135 * @name Gestures 0136 */ 0137 //@{ 0138 void disableGestures(); 0139 void enableGestures(); 0140 bool areGesturesDisabled() const; 0141 0142 int gestureMouseButton() const; 0143 void setGestureMouseButton(int); 0144 0145 int gestureTimeOut() const; 0146 void setGestureTimeOut(int); 0147 0148 void setGesturesExclude(Windowdef_list *gestures); 0149 Windowdef_list *gesturesExclude(); 0150 const Windowdef_list *gesturesExclude() const; 0151 //@} 0152 0153 /** 0154 * @name Voice Commands 0155 */ 0156 //@{ 0157 void setVoiceShortcut(const QKeySequence &shortcut); 0158 QKeySequence voiceShortcut() const; 0159 //@} 0160 0161 /** 0162 * Check if the given config file is a valid khotkeys file 0163 */ 0164 bool isConfigFileValid(KConfigBase const &config, ImportType ask); 0165 0166 static bool isOutdated; 0167 0168 protected: 0169 /** 0170 * Read settings from \a cfg_P. 0171 * 0172 * @param root the group to import to 0173 * @param config config object to read from 0174 * @param include_disabled should we read disabled actions? 0175 * @param state enable, disable or keep the actions enabled state 0176 */ 0177 bool read_settings(ActionDataGroup *root, KConfigBase const &config, bool include_disabled, ActionState state); 0178 0179 /** 0180 * Make sure all System Groups exists 0181 */ 0182 void validate(); 0183 0184 private: 0185 // Reset all values. No defaults are loaded 0186 void reinitialize(); 0187 0188 /** 0189 * TODO 0190 */ 0191 ActionDataGroup *m_actions; 0192 0193 /** 0194 * @name Gestures 0195 */ 0196 //@{ 0197 /** 0198 * Gestures globally disabled? 0199 */ 0200 bool gestures_disabled; 0201 0202 /** 0203 * Mouse button used for gestures. 0204 */ 0205 int gesture_mouse_button; 0206 0207 /** 0208 * Gesture timeout 0209 */ 0210 int gesture_timeout; 0211 0212 /** 0213 * Windows to exclude from gestures 0214 */ 0215 Windowdef_list *gestures_exclude; 0216 //@} 0217 0218 /** 0219 * KHotKeys daemon disabled? 0220 */ 0221 bool daemon_disabled; 0222 0223 /** 0224 * The shortcut that triggers a voice command 0225 */ 0226 QKeySequence voice_shortcut; 0227 0228 /** 0229 * List of id's for all imported files. 0230 */ 0231 QStringList already_imported; 0232 0233 friend class SettingsWriter; 0234 }; 0235 0236 } // namespace KHotKeys 0237 0238 #endif