Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konqueror / settings / konqhtml / jspolicies.h
blobd6213e5b864ab9e5a64f8f101aa9c27fe595c1f9
1 /*
2 Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
3 Derived from jsopt.h, code copied from there is copyrighted to its
4 respective owners.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __JSPOLICIES_H__
23 #define __JSPOLICIES_H__
25 #include <QtGui/QGroupBox>
28 #include <khtml_settings.h>
30 #include "policies.h"
32 class QButtonGroup;
34 // special value for inheriting a global policy
35 #define INHERIT_POLICY 32767
37 /**
38 * @short Contains all the JavaScript policies and methods for their manipulation.
40 * This class provides access to the JavaScript policies.
42 * @author Leo Savernik
44 class JSPolicies : public Policies {
45 public:
46 #if 0
47 /**
48 * Enumeration for all policies
50 enum Policies { JavaScriptEnabled = 0, WindowOpen, WindowResize,
51 WindowMove, WindowFocus, WindowStatus, NumPolicies };
52 #endif
54 /**
55 * constructor
56 * @param config configuration to initialize this instance from
57 * @param group config group to use if this instance contains the global
58 * policies (global == true)
59 * @param global true if this instance contains the global policy settings,
60 * false if this instance contains policies specific for a domain.
61 * @param domain name of the domain this instance is used to configure the
62 * policies for (case insensitive, ignored if global == true)
64 JSPolicies(KSharedConfig::Ptr config, const QString &group, bool global,
65 const QString &domain = QString());
67 /**
68 * dummy constructor to make QMap happy.
70 * Never construct an object by using this.
71 * @internal
73 JSPolicies();
75 virtual ~JSPolicies();
77 /**
78 * Returns whether the WindowOpen policy is inherited.
80 bool isWindowOpenPolicyInherited() const {
81 return window_open == INHERIT_POLICY;
83 /**
84 * Returns the current value of the WindowOpen policy.
86 * This will return an illegal value if isWindowOpenPolicyInherited is
87 * true.
89 KHTMLSettings::KJSWindowOpenPolicy windowOpenPolicy() const {
90 return (KHTMLSettings::KJSWindowOpenPolicy)window_open;
93 /**
94 * Returns whether the WindowResize policy is inherited.
96 bool isWindowResizePolicyInherited() const {
97 return window_resize == INHERIT_POLICY;
99 /**
100 * Returns the current value of the WindowResize policy.
102 * This will return an illegal value if isWindowResizePolicyInherited is
103 * true.
105 KHTMLSettings::KJSWindowResizePolicy windowResizePolicy() const {
106 return (KHTMLSettings::KJSWindowResizePolicy)window_resize;
110 * Returns whether the WindowMove policy is inherited.
112 bool isWindowMovePolicyInherited() const {
113 return window_move == INHERIT_POLICY;
116 * Returns the current value of the WindowMove policy.
118 * This will return an illegal value if isWindowMovePolicyInherited is
119 * true.
121 KHTMLSettings::KJSWindowMovePolicy windowMovePolicy() const {
122 return (KHTMLSettings::KJSWindowMovePolicy)window_move;
126 * Returns whether the WindowFocus policy is inherited.
128 bool isWindowFocusPolicyInherited() const {
129 return window_focus == INHERIT_POLICY;
132 * Returns the current value of the WindowFocus policy.
134 * This will return an illegal value if isWindowFocusPolicyInherited is
135 * true.
137 KHTMLSettings::KJSWindowFocusPolicy windowFocusPolicy() const {
138 return (KHTMLSettings::KJSWindowFocusPolicy)window_focus;
142 * Returns whether the WindowStatus policy is inherited.
144 bool isWindowStatusPolicyInherited() const {
145 return window_status == INHERIT_POLICY;
148 * Returns the current value of the WindowStatus policy.
150 * This will return an illegal value if isWindowStatusPolicyInherited is
151 * true.
153 KHTMLSettings::KJSWindowStatusPolicy windowStatusPolicy() const {
154 return (KHTMLSettings::KJSWindowStatusPolicy)window_status;
158 * (re)loads settings from configuration file given in the constructor.
160 virtual void load();
162 * saves current settings to the configuration file given in the constructor
164 virtual void save();
166 * restores the default settings
168 virtual void defaults();
170 private:
171 // one of KHTMLSettings::KJSWindowOpenPolicy or INHERIT_POLICY
172 unsigned int window_open;
173 // one of KHTMLSettings::KJSWindowResizePolicy or INHERIT_POLICY
174 unsigned int window_resize;
175 // one of KHTMLSettings::KJSWindowMovePolicy or INHERIT_POLICY
176 unsigned int window_move;
177 // one of KHTMLSettings::KJSWindowFocusPolicy or INHERIT_POLICY
178 unsigned int window_focus;
179 // one of KHTMLSettings::KJSWindowStatusPolicy or INHERIT_POLICY
180 unsigned int window_status;
182 friend class JSPoliciesFrame; // for changing policies
186 * @short Provides a framed widget with controls for the JavaScript policy settings.
188 * This widget contains controls for changing all JavaScript policies
189 * except the JavaScript enabled policy itself. The rationale behind this is
190 * that the enabled policy be separate from the rest in a prominent
191 * place.
193 * It is suitable for the global policy settings as well as for the
194 * domain-specific settings.
196 * The difference between global and domain-specific is the existence of
197 * a special inheritance option in the latter case. That way domain-specific
198 * policies can inherit their value from the global policies.
200 * @author Leo Savernik
202 class JSPoliciesFrame : public QGroupBox {
203 Q_OBJECT
204 public:
206 * constructor
207 * @param policies associated object containing the policy values. This
208 * object will be updated accordingly as the settings are changed.
209 * @param title title for group box
210 * @param parent parent widget
212 JSPoliciesFrame(JSPolicies *policies, const QString &title,
213 QWidget* parent = 0);
215 virtual ~JSPoliciesFrame();
218 * updates the controls to resemble the status of the underlying
219 * JSPolicies object.
221 void refresh();
223 * (re)loads settings from configuration file given in the constructor.
225 void load() {
226 policies->load();
227 refresh();
230 * saves current settings to the configuration file given in the constructor
232 void save() {
233 policies->save();
236 * restores the default settings
238 void defaults() {
239 policies->defaults();
240 refresh();
243 Q_SIGNALS:
245 * emitted every time an option has been changed
247 void changed();
249 private Q_SLOTS:
250 void setWindowOpenPolicy(int id);
251 void setWindowResizePolicy(int id);
252 void setWindowMovePolicy(int id);
253 void setWindowFocusPolicy(int id);
254 void setWindowStatusPolicy(int id);
256 private:
258 JSPolicies *policies;
259 QButtonGroup *js_popup;
260 QButtonGroup *js_resize;
261 QButtonGroup *js_move;
262 QButtonGroup *js_focus;
263 QButtonGroup *js_statusbar;
267 #endif // __JSPOLICIES_H__