summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/jspolicies.h
blob: 7f3e400fa7df0da4d1ba8c6d69b9a99ab2e5959b (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
  Copyright (c) 2002 Leo Savernik <l.savernik@aon.at>
  Derived from jsopt.h, code copied from there is copyrighted to its
  respective owners.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#ifndef __JSPOLICIES_H__
#define __JSPOLICIES_H__

#include <tqgroupbox.h>
#include <tqstring.h>

#include <khtml_settings.h>

#include "policies.h"

class TDEConfig;
class TQRadioButton;
class TQButtonGroup;

// special value for inheriting a global policy
#define INHERIT_POLICY		32767

/**
 * @short Contains all the JavaScript policies and methods for their manipulation.
 *
 * This class provides access to the JavaScript policies.
 *
 * @author Leo Savernik
 */
class JSPolicies : public Policies {
public:
#if 0
  /**
   * Enumeration for all policies
   */
  enum Policies { JavaScriptEnabled = 0, WindowOpen, WindowResize,
  		WindowMove, WindowFocus, WindowStatus, NumPolicies };
#endif

  /**
   * constructor
   * @param config configuration to initialize this instance from
   * @param group config group to use if this instance contains the global
   *	policies (global == true)
   * @param global true if this instance contains the global policy settings,
   *	false if this instance contains policies specific for a domain.
   * @param domain name of the domain this instance is used to configure the
   *	policies for (case insensitive, ignored if global == true)
   */
  JSPolicies(TDEConfig* config, const TQString &group, bool global,
  		const TQString &domain = TQString::null);
		
  /**
   * dummy constructor to make TQMap happy.
   *
   * Never construct an object by using this.
   * @internal
   */
  JSPolicies();

  virtual ~JSPolicies();

  /**
   * Returns whether the WindowOpen policy is inherited.
   */
  bool isWindowOpenPolicyInherited() const {
    return window_open == INHERIT_POLICY;
  }
  /**
   * Returns the current value of the WindowOpen policy.
   *
   * This will return an illegal value if isWindowOpenPolicyInherited is
   * true.
   */
  KHTMLSettings::KJSWindowOpenPolicy windowOpenPolicy() const {
    return (KHTMLSettings::KJSWindowOpenPolicy)window_open;
  }

  /**
   * Returns whether the WindowResize policy is inherited.
   */
  bool isWindowResizePolicyInherited() const {
    return window_resize == INHERIT_POLICY;
  }
  /**
   * Returns the current value of the WindowResize policy.
   *
   * This will return an illegal value if isWindowResizePolicyInherited is
   * true.
   */
  KHTMLSettings::KJSWindowResizePolicy windowResizePolicy() const {
    return (KHTMLSettings::KJSWindowResizePolicy)window_resize;
  }

  /**
   * Returns whether the WindowMove policy is inherited.
   */
  bool isWindowMovePolicyInherited() const {
    return window_move == INHERIT_POLICY;
  }
  /**
   * Returns the current value of the WindowMove policy.
   *
   * This will return an illegal value if isWindowMovePolicyInherited is
   * true.
   */
  KHTMLSettings::KJSWindowMovePolicy windowMovePolicy() const {
    return (KHTMLSettings::KJSWindowMovePolicy)window_move;
  }

  /**
   * Returns whether the WindowFocus policy is inherited.
   */
  bool isWindowFocusPolicyInherited() const {
    return window_focus == INHERIT_POLICY;
  }
  /**
   * Returns the current value of the WindowFocus policy.
   *
   * This will return an illegal value if isWindowFocusPolicyInherited is
   * true.
   */
  KHTMLSettings::KJSWindowFocusPolicy windowFocusPolicy() const {
    return (KHTMLSettings::KJSWindowFocusPolicy)window_focus;
  }

  /**
   * Returns whether the WindowStatus policy is inherited.
   */
  bool isWindowStatusPolicyInherited() const {
    return window_status == INHERIT_POLICY;
  }
  /**
   * Returns the current value of the WindowStatus policy.
   *
   * This will return an illegal value if isWindowStatusPolicyInherited is
   * true.
   */
  KHTMLSettings::KJSWindowStatusPolicy windowStatusPolicy() const {
    return (KHTMLSettings::KJSWindowStatusPolicy)window_status;
  }

  /**
   * (re)loads settings from configuration file given in the constructor.
   */
  virtual void load();
  /**
   * saves current settings to the configuration file given in the constructor
   */
  virtual void save();
  /**
   * restores the default settings
   */
  virtual void defaults();

private:
  // one of KHTMLSettings::KJSWindowOpenPolicy or INHERIT_POLICY
  unsigned int window_open;
  // one of KHTMLSettings::KJSWindowResizePolicy or INHERIT_POLICY
  unsigned int window_resize;
  // one of KHTMLSettings::KJSWindowMovePolicy or INHERIT_POLICY
  unsigned int window_move;
  // one of KHTMLSettings::KJSWindowFocusPolicy or INHERIT_POLICY
  unsigned int window_focus;
  // one of KHTMLSettings::KJSWindowStatusPolicy or INHERIT_POLICY
  unsigned int window_status;

  friend class JSPoliciesFrame;	// for changing policies
};

/**
 * @short Provides a framed widget with controls for the JavaScript policy settings.
 *
 * This widget contains controls for changing all JavaScript policies
 * except the JavaScript enabled policy itself. The rationale behind this is
 * that the enabled policy be separate from the rest in a prominent
 * place.
 *
 * It is suitable for the global policy settings as well as for the
 * domain-specific settings.
 *
 * The difference between global and domain-specific is the existence of
 * a special inheritance option in the latter case. That way domain-specific
 * policies can inherit their value from the global policies.
 *
 * @author Leo Savernik
 */
class JSPoliciesFrame : public TQGroupBox {
  Q_OBJECT
public:
  /**
   * constructor
   * @param policies associated object containing the policy values. This
   *	object will be updated accordingly as the settings are changed.
   * @param title title for group box
   * @param parent parent widget
   */
  JSPoliciesFrame(JSPolicies *policies, const TQString &title,
		TQWidget* parent = 0);

  virtual ~JSPoliciesFrame();

  /**
   * updates the controls to resemble the status of the underlying
   * JSPolicies object.
   */
  void refresh();
  /**
   * (re)loads settings from configuration file given in the constructor.
   */
  void load() {
    policies->load();
    refresh();
  }
  /**
   * saves current settings to the configuration file given in the constructor
   */
  void save() {
    policies->save();
  }
  /**
   * restores the default settings
   */
  void defaults() {
    policies->defaults();
    refresh();
  }

signals:
  /**
   * emitted every time an option has been changed
   */
  void changed();

private slots:
  void setWindowOpenPolicy(int id);
  void setWindowResizePolicy(int id);
  void setWindowMovePolicy(int id);
  void setWindowFocusPolicy(int id);
  void setWindowStatusPolicy(int id);

private:

  JSPolicies *policies;
  TQButtonGroup *js_popup;
  TQButtonGroup *js_resize;
  TQButtonGroup *js_move;
  TQButtonGroup *js_focus;
  TQButtonGroup *js_statusbar;
};


#endif		// __JSPOLICIES_H__