File indexing completed on 2024-04-21 16:12:57
0001 #ifndef WINDOW_SELECTION_RULES_H 0002 #define WINDOW_SELECTION_RULES_H 0003 /* SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org> 0004 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #include "windows_helper/window_selection_interface.h" 0010 0011 namespace KHotKeys 0012 { 0013 /** 0014 * Rules to match a windows. 0015 */ 0016 class Q_DECL_EXPORT Windowdef_simple : public Windowdef 0017 { 0018 typedef Windowdef base; 0019 0020 public: 0021 /** 0022 * How to compare. 0023 */ 0024 enum substr_type_t { 0025 NOT_IMPORTANT, 0026 CONTAINS, 0027 IS, 0028 REGEXP, 0029 CONTAINS_NOT, 0030 IS_NOT, 0031 REGEXP_NOT, 0032 }; 0033 0034 /** 0035 * Window Type 0036 */ 0037 enum window_type_t { 0038 WINDOW_TYPE_NORMAL = (1 << NET::Normal), 0039 WINDOW_TYPE_DESKTOP = (1 << NET::Desktop), 0040 WINDOW_TYPE_DOCK = (1 << NET::Dock), 0041 WINDOW_TYPE_DIALOG = (1 << NET::Dialog), 0042 }; 0043 0044 /** 0045 * Constructor 0046 */ 0047 Windowdef_simple(const QString &comment_P = QString(), 0048 const QString &title_P = QString(), 0049 substr_type_t _title_type_P = NOT_IMPORTANT, 0050 const QString &wclass_P = QString(), 0051 substr_type_t wclass_type_P = NOT_IMPORTANT, 0052 const QString &role_P = QString(), 0053 substr_type_t role_type_P = NOT_IMPORTANT, 0054 int window_types_P = 0); 0055 0056 /** 0057 * Create from a configuration file. 0058 */ 0059 Windowdef_simple(KConfigGroup &cfg_P); 0060 0061 /** 0062 * Match against window @p window_P 0063 */ 0064 bool match(const Window_data &window_P) override; 0065 0066 /** 0067 * Write to configuration file @p cfg_P 0068 */ 0069 void cfg_write(KConfigGroup &cfg_P) const override; 0070 0071 /** 0072 * The string to compare with the window title 0073 */ 0074 const QString &title() const; 0075 void set_title(const QString &title); 0076 0077 /** 0078 * How to match the window title 0079 */ 0080 substr_type_t title_match_type() const; 0081 void set_title_match_type(const substr_type_t &type); 0082 0083 /** 0084 * The string to compare with the window class 0085 */ 0086 const QString &wclass() const; 0087 void set_wclass(const QString &wclass); 0088 0089 /** 0090 * How to match the window class 0091 */ 0092 substr_type_t wclass_match_type() const; 0093 void set_wclass_match_type(const substr_type_t &); 0094 0095 /** 0096 * The string to compare with the window role 0097 */ 0098 const QString &role() const; 0099 void set_role(const QString &role); 0100 0101 /** 0102 * How to match the window type 0103 */ 0104 substr_type_t role_match_type() const; 0105 void set_role_match_type(const substr_type_t &type); 0106 0107 /** 0108 * The window types to match 0109 */ 0110 int window_types() const; 0111 void set_window_types(const int types); 0112 0113 /** 0114 * 0115 */ 0116 bool type_match(window_type_t type_P) const; 0117 0118 /** 0119 */ 0120 bool type_match(NET::WindowType type_P) const; 0121 0122 /** 0123 * Create a copy 0124 */ 0125 Windowdef_simple *copy(/*ActionDataBase* data_P*/) const override; 0126 0127 /** 0128 * The description of this rule. 0129 * 0130 * @todo: Move to base class? 0131 */ 0132 const QString description() const override; 0133 0134 protected: 0135 /** 0136 */ 0137 bool is_substr_match(const QString &str1_P, const QString &str2_P, substr_type_t type_P); 0138 0139 private: 0140 //! The title string 0141 QString _title; 0142 0143 //! How to use the title string 0144 substr_type_t _title_match_type; 0145 0146 //! The class string 0147 QString _wclass; 0148 0149 //! How to use the class string 0150 substr_type_t _wclass_match_type; 0151 0152 //! The role string 0153 QString _role; 0154 0155 //! How to use the role string 0156 substr_type_t _role_match_type; 0157 0158 //! Which window types to match 0159 int _window_types; 0160 }; 0161 0162 } // namespace KHotKeys 0163 0164 #endif /* #ifndef WINDOW_SELECTION_RULES_H */