• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdehtml
 

tdehtml

  • tdehtml
tdehtml_settings.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 1999 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tqfontdatabase.h>
21 
22 #include "tdehtml_settings.h"
23 #include "tdehtmldefaults.h"
24 #include <tdeglobalsettings.h>
25 #include <tdeconfig.h>
26 #include <tdeglobal.h>
27 #include <tdelocale.h>
28 #include <kdebug.h>
29 #include <tqregexp.h>
30 #include <tqvaluevector.h>
31 #include <tdemessagebox.h>
32 
37 struct KPerDomainSettings {
38  bool m_bEnableJava : 1;
39  bool m_bEnableJavaScript : 1;
40  bool m_bEnablePlugins : 1;
41  // don't forget to maintain the bitfields as the enums grow
42  TDEHTMLSettings::KJSWindowOpenPolicy m_windowOpenPolicy : 2;
43  TDEHTMLSettings::KJSWindowStatusPolicy m_windowStatusPolicy : 1;
44  TDEHTMLSettings::KJSWindowFocusPolicy m_windowFocusPolicy : 1;
45  TDEHTMLSettings::KJSWindowMovePolicy m_windowMovePolicy : 1;
46  TDEHTMLSettings::KJSWindowResizePolicy m_windowResizePolicy : 1;
47 
48 #ifdef DEBUG_SETTINGS
49  void dump(const TQString &infix = TQString::null) const {
50  kdDebug() << "KPerDomainSettings " << infix << " @" << this << ":" << endl;
51  kdDebug() << " m_bEnableJava: " << m_bEnableJava << endl;
52  kdDebug() << " m_bEnableJavaScript: " << m_bEnableJavaScript << endl;
53  kdDebug() << " m_bEnablePlugins: " << m_bEnablePlugins << endl;
54  kdDebug() << " m_windowOpenPolicy: " << m_windowOpenPolicy << endl;
55  kdDebug() << " m_windowStatusPolicy: " << m_windowStatusPolicy << endl;
56  kdDebug() << " m_windowFocusPolicy: " << m_windowFocusPolicy << endl;
57  kdDebug() << " m_windowMovePolicy: " << m_windowMovePolicy << endl;
58  kdDebug() << " m_windowResizePolicy: " << m_windowResizePolicy << endl;
59  }
60 #endif
61 };
62 
63 typedef TQMap<TQString,KPerDomainSettings> PolicyMap;
64 
65 class TDEHTMLSettingsPrivate
66 {
67 public:
68  bool m_bChangeCursor : 1;
69  bool m_bOpenMiddleClick : 1;
70  bool m_bBackRightClick : 1;
71  bool m_underlineLink : 1;
72  bool m_hoverLink : 1;
73  bool m_bEnableJavaScriptDebug : 1;
74  bool m_bEnableJavaScriptErrorReporting : 1;
75  bool enforceCharset : 1;
76  bool m_bAutoLoadImages : 1;
77  bool m_bUnfinishedImageFrame : 1;
78  bool m_formCompletionEnabled : 1;
79  bool m_autoDelayedActionsEnabled : 1;
80  bool m_jsErrorsEnabled : 1;
81  bool m_follow_system_colors : 1;
82  bool m_allowTabulation : 1;
83  bool m_autoSpellCheck : 1;
84  bool m_adFilterEnabled : 1;
85  bool m_hideAdsEnabled : 1;
86  bool m_jsPopupBlockerPassivePopup : 1;
87  bool m_accessKeysEnabled : 1;
88 
89  // the virtual global "domain"
90  KPerDomainSettings global;
91 
92  int m_fontSize;
93  int m_minFontSize;
94  int m_maxFormCompletionItems;
95  TDEHTMLSettings::KAnimationAdvice m_showAnimations;
96 
97  TQString m_encoding;
98  TQString m_userSheet;
99 
100  TQColor m_textColor;
101  TQColor m_baseColor;
102  TQColor m_linkColor;
103  TQColor m_vLinkColor;
104 
105  PolicyMap domainPolicy;
106  TQStringList fonts;
107  TQStringList defaultFonts;
108 
109  TQValueVector<TQRegExp> adFilters;
110  TQValueList< TQPair< TQString, TQChar > > m_fallbackAccessKeysAssignments;
111 };
112 
113 
117 static KPerDomainSettings &setup_per_domain_policy(
118  TDEHTMLSettingsPrivate *d,
119  const TQString &domain) {
120  if (domain.isEmpty()) {
121  kdWarning() << "setup_per_domain_policy: domain is empty" << endl;
122  }
123  const TQString ldomain = domain.lower();
124  PolicyMap::iterator it = d->domainPolicy.find(ldomain);
125  if (it == d->domainPolicy.end()) {
126  // simply copy global domain settings (they should have been initialized
127  // by this time)
128  it = d->domainPolicy.insert(ldomain,d->global);
129  }
130  return *it;
131 }
132 
133 
134 TDEHTMLSettings::KJavaScriptAdvice TDEHTMLSettings::strToAdvice(const TQString& _str)
135 {
136  KJavaScriptAdvice ret = KJavaScriptDunno;
137 
138  if (!_str)
139  ret = KJavaScriptDunno;
140 
141  if (_str.lower() == TQString::fromLatin1("accept"))
142  ret = KJavaScriptAccept;
143  else if (_str.lower() == TQString::fromLatin1("reject"))
144  ret = KJavaScriptReject;
145 
146  return ret;
147 }
148 
149 const char* TDEHTMLSettings::adviceToStr(KJavaScriptAdvice _advice)
150 {
151  switch( _advice ) {
152  case KJavaScriptAccept: return I18N_NOOP("Accept");
153  case KJavaScriptReject: return I18N_NOOP("Reject");
154  default: return 0;
155  }
156  return 0;
157 }
158 
159 
160 void TDEHTMLSettings::splitDomainAdvice(const TQString& configStr, TQString &domain,
161  KJavaScriptAdvice &javaAdvice, KJavaScriptAdvice& javaScriptAdvice)
162 {
163  TQString tmp(configStr);
164  int splitIndex = tmp.find(':');
165  if ( splitIndex == -1)
166  {
167  domain = configStr.lower();
168  javaAdvice = KJavaScriptDunno;
169  javaScriptAdvice = KJavaScriptDunno;
170  }
171  else
172  {
173  domain = tmp.left(splitIndex).lower();
174  TQString adviceString = tmp.mid( splitIndex+1, tmp.length() );
175  int splitIndex2 = adviceString.find( ':' );
176  if( splitIndex2 == -1 ) {
177  // Java advice only
178  javaAdvice = strToAdvice( adviceString );
179  javaScriptAdvice = KJavaScriptDunno;
180  } else {
181  // Java and JavaScript advice
182  javaAdvice = strToAdvice( adviceString.left( splitIndex2 ) );
183  javaScriptAdvice = strToAdvice( adviceString.mid( splitIndex2+1,
184  adviceString.length() ) );
185  }
186  }
187 }
188 
189 void TDEHTMLSettings::readDomainSettings(TDEConfig *config, bool reset,
190  bool global, KPerDomainSettings &pd_settings) {
191  TQString jsPrefix = global ? TQString::null
192  : TQString::fromLatin1("javascript.");
193  TQString javaPrefix = global ? TQString::null
194  : TQString::fromLatin1("java.");
195  TQString pluginsPrefix = global ? TQString::null
196  : TQString::fromLatin1("plugins.");
197 
198  // The setting for Java
199  TQString key = javaPrefix + TQString::fromLatin1("EnableJava");
200  if ( (global && reset) || config->hasKey( key ) )
201  pd_settings.m_bEnableJava = config->readBoolEntry( key, false );
202  else if ( !global )
203  pd_settings.m_bEnableJava = d->global.m_bEnableJava;
204 
205  // The setting for Plugins
206  key = pluginsPrefix + TQString::fromLatin1("EnablePlugins");
207  if ( (global && reset) || config->hasKey( key ) )
208  pd_settings.m_bEnablePlugins = config->readBoolEntry( key, true );
209  else if ( !global )
210  pd_settings.m_bEnablePlugins = d->global.m_bEnablePlugins;
211 
212  // The setting for JavaScript
213  key = jsPrefix + TQString::fromLatin1("EnableJavaScript");
214  if ( (global && reset) || config->hasKey( key ) )
215  pd_settings.m_bEnableJavaScript = config->readBoolEntry( key, true );
216  else if ( !global )
217  pd_settings.m_bEnableJavaScript = d->global.m_bEnableJavaScript;
218 
219  // window property policies
220  key = jsPrefix + TQString::fromLatin1("WindowOpenPolicy");
221  if ( (global && reset) || config->hasKey( key ) )
222  pd_settings.m_windowOpenPolicy = (KJSWindowOpenPolicy)
223  config->readUnsignedNumEntry( key, KJSWindowOpenSmart );
224  else if ( !global )
225  pd_settings.m_windowOpenPolicy = d->global.m_windowOpenPolicy;
226 
227  key = jsPrefix + TQString::fromLatin1("WindowMovePolicy");
228  if ( (global && reset) || config->hasKey( key ) )
229  pd_settings.m_windowMovePolicy = (KJSWindowMovePolicy)
230  config->readUnsignedNumEntry( key, KJSWindowMoveAllow );
231  else if ( !global )
232  pd_settings.m_windowMovePolicy = d->global.m_windowMovePolicy;
233 
234  key = jsPrefix + TQString::fromLatin1("WindowResizePolicy");
235  if ( (global && reset) || config->hasKey( key ) )
236  pd_settings.m_windowResizePolicy = (KJSWindowResizePolicy)
237  config->readUnsignedNumEntry( key, KJSWindowResizeAllow );
238  else if ( !global )
239  pd_settings.m_windowResizePolicy = d->global.m_windowResizePolicy;
240 
241  key = jsPrefix + TQString::fromLatin1("WindowStatusPolicy");
242  if ( (global && reset) || config->hasKey( key ) )
243  pd_settings.m_windowStatusPolicy = (KJSWindowStatusPolicy)
244  config->readUnsignedNumEntry( key, KJSWindowStatusAllow );
245  else if ( !global )
246  pd_settings.m_windowStatusPolicy = d->global.m_windowStatusPolicy;
247 
248  key = jsPrefix + TQString::fromLatin1("WindowFocusPolicy");
249  if ( (global && reset) || config->hasKey( key ) )
250  pd_settings.m_windowFocusPolicy = (KJSWindowFocusPolicy)
251  config->readUnsignedNumEntry( key, KJSWindowFocusAllow );
252  else if ( !global )
253  pd_settings.m_windowFocusPolicy = d->global.m_windowFocusPolicy;
254 
255 }
256 
257 
258 TDEHTMLSettings::TDEHTMLSettings()
259 {
260  d = new TDEHTMLSettingsPrivate();
261  init();
262 }
263 
264 TDEHTMLSettings::TDEHTMLSettings(const TDEHTMLSettings &other)
265 {
266  d = new TDEHTMLSettingsPrivate();
267  *d = *other.d;
268 }
269 
270 TDEHTMLSettings::~TDEHTMLSettings()
271 {
272  delete d;
273 }
274 
275 bool TDEHTMLSettings::changeCursor() const
276 {
277  return d->m_bChangeCursor;
278 }
279 
280 bool TDEHTMLSettings::underlineLink() const
281 {
282  return d->m_underlineLink;
283 }
284 
285 bool TDEHTMLSettings::hoverLink() const
286 {
287  return d->m_hoverLink;
288 }
289 
290 void TDEHTMLSettings::init()
291 {
292  TDEConfig global( "tdehtmlrc", true, false );
293  init( &global, true );
294 
295  TDEConfig *local = TDEGlobal::config();
296  if ( !local )
297  return;
298 
299  init( local, false );
300 }
301 
302 void TDEHTMLSettings::init( TDEConfig * config, bool reset )
303 {
304  TQString group_save = config->group();
305  if (reset || config->hasGroup("MainView Settings"))
306  {
307  config->setGroup( "MainView Settings" );
308 
309  if ( reset || config->hasKey( "OpenMiddleClick" ) )
310  d->m_bOpenMiddleClick = config->readBoolEntry( "OpenMiddleClick", true );
311 
312  if ( reset || config->hasKey( "BackRightClick" ) )
313  d->m_bBackRightClick = config->readBoolEntry( "BackRightClick", false );
314  }
315 
316  if (reset || config->hasGroup("Access Keys")) {
317  config->setGroup( "Access Keys" );
318  d->m_accessKeysEnabled = config->readBoolEntry( "Enabled", true );
319  }
320 
321  if (reset || config->hasGroup("Filter Settings"))
322  {
323  config->setGroup( "Filter Settings" );
324  d->m_adFilterEnabled = config->readBoolEntry("Enabled", false);
325  d->m_hideAdsEnabled = config->readBoolEntry("Shrink", false);
326 
327  d->adFilters.clear();
328 
329  TQMap<TQString,TQString> entryMap = config->entryMap("Filter Settings");
330  TQMap<TQString,TQString>::ConstIterator it;
331  d->adFilters.reserve(entryMap.count());
332  for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
333  {
334  TQString name = it.key();
335  TQString url = it.data();
336 
337  if (url.startsWith("!"))
338  continue;
339 
340  if (name.startsWith("Filter"))
341  {
342  if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')
343  {
344  TQString inside = url.mid(1, url.length()-2);
345  TQRegExp rx(inside);
346  d->adFilters.append(rx);
347  }
348  else
349  {
350  TQRegExp rx;
351  int left,right;
352 
353  for (right=url.length(); right>0 && url[right-1]=='*' ; --right);
354  for (left=0; left<right && url[left]=='*' ; ++left);
355 
356  rx.setWildcard(true);
357  rx.setPattern(url.mid(left,right-left));
358 
359  d->adFilters.append(rx);
360  }
361  }
362  }
363  }
364 
365 
366  if (reset || config->hasGroup("HTML Settings"))
367  {
368  config->setGroup( "HTML Settings" );
369  // Fonts and colors
370  if( reset ) {
371  d->defaultFonts = TQStringList();
372  d->defaultFonts.append( config->readEntry( "StandardFont", TDEGlobalSettings::generalFont().family() ) );
373  d->defaultFonts.append( config->readEntry( "FixedFont", TDEGlobalSettings::fixedFont().family() ) );
374  d->defaultFonts.append( config->readEntry( "SerifFont", HTML_DEFAULT_VIEW_SERIF_FONT ) );
375  d->defaultFonts.append( config->readEntry( "SansSerifFont", HTML_DEFAULT_VIEW_SANSSERIF_FONT ) );
376  d->defaultFonts.append( config->readEntry( "CursiveFont", HTML_DEFAULT_VIEW_CURSIVE_FONT ) );
377  d->defaultFonts.append( config->readEntry( "FantasyFont", HTML_DEFAULT_VIEW_FANTASY_FONT ) );
378  d->defaultFonts.append( TQString( "0" ) ); // font size adjustment
379  }
380 
381  if ( reset || config->hasKey( "MinimumFontSize" ) )
382  d->m_minFontSize = config->readNumEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE );
383 
384  if ( reset || config->hasKey( "MediumFontSize" ) )
385  d->m_fontSize = config->readNumEntry( "MediumFontSize", 12 );
386 
387  d->fonts = config->readListEntry( "Fonts" );
388 
389  if ( reset || config->hasKey( "DefaultEncoding" ) )
390  d->m_encoding = config->readEntry( "DefaultEncoding", "" );
391 
392  if ( reset || config->hasKey( "EnforceDefaultCharset" ) )
393  d->enforceCharset = config->readBoolEntry( "EnforceDefaultCharset", false );
394 
395  // Behavior
396  if ( reset || config->hasKey( "ChangeCursor" ) )
397  d->m_bChangeCursor = config->readBoolEntry( "ChangeCursor", KDE_DEFAULT_CHANGECURSOR );
398 
399  if ( reset || config->hasKey("UnderlineLinks") )
400  d->m_underlineLink = config->readBoolEntry( "UnderlineLinks", true );
401 
402  if ( reset || config->hasKey( "HoverLinks" ) )
403  {
404  if ( ( d->m_hoverLink = config->readBoolEntry( "HoverLinks", false ) ) )
405  d->m_underlineLink = false;
406  }
407 
408  if ( reset || config->hasKey( "AllowTabulation" ) )
409  d->m_allowTabulation = config->readBoolEntry( "AllowTabulation", false );
410 
411  if ( reset || config->hasKey( "AutoSpellCheck" ) )
412  d->m_autoSpellCheck = config->readBoolEntry( "AutoSpellCheck", true );
413 
414  // Other
415  if ( reset || config->hasKey( "AutoLoadImages" ) )
416  d->m_bAutoLoadImages = config->readBoolEntry( "AutoLoadImages", true );
417 
418  if ( reset || config->hasKey( "UnfinishedImageFrame" ) )
419  d->m_bUnfinishedImageFrame = config->readBoolEntry( "UnfinishedImageFrame", true );
420 
421  if ( reset || config->hasKey( "ShowAnimations" ) )
422  {
423  TQString value = config->readEntry( "ShowAnimations").lower();
424  if (value == "disabled")
425  d->m_showAnimations = KAnimationDisabled;
426  else if (value == "looponce")
427  d->m_showAnimations = KAnimationLoopOnce;
428  else
429  d->m_showAnimations = KAnimationEnabled;
430  }
431 
432  if ( config->readBoolEntry( "UserStyleSheetEnabled", false ) == true ) {
433  if ( reset || config->hasKey( "UserStyleSheet" ) )
434  d->m_userSheet = config->readEntry( "UserStyleSheet", "" );
435  }
436 
437  d->m_formCompletionEnabled = config->readBoolEntry("FormCompletion", true);
438  d->m_maxFormCompletionItems = config->readNumEntry("MaxFormCompletionItems", 10);
439  d->m_autoDelayedActionsEnabled = config->readBoolEntry ("AutoDelayedActions", true);
440  d->m_jsErrorsEnabled = config->readBoolEntry("ReportJSErrors", true);
441  TQStringList accesskeys = config->readListEntry("FallbackAccessKeysAssignments");
442  d->m_fallbackAccessKeysAssignments.clear();
443  for( TQStringList::ConstIterator it = accesskeys.begin(); it != accesskeys.end(); ++it )
444  if( (*it).length() > 2 && (*it)[ 1 ] == ':' )
445  d->m_fallbackAccessKeysAssignments.append( qMakePair( (*it).mid( 2 ), (*it)[ 0 ] ));
446  }
447 
448  // Colors
449 
450  if ( reset || config->hasKey( "FollowSystemColors" ) )
451  d->m_follow_system_colors = config->readBoolEntry( "FollowSystemColors", false );
452 
453  if ( reset || config->hasGroup( "General" ) )
454  {
455  config->setGroup( "General" ); // group will be restored by cgs anyway
456  if ( reset || config->hasKey( "foreground" ) )
457  d->m_textColor = config->readColorEntry( "foreground", &HTML_DEFAULT_TXT_COLOR );
458 
459  if ( reset || config->hasKey( "linkColor" ) )
460  d->m_linkColor = config->readColorEntry( "linkColor", &HTML_DEFAULT_LNK_COLOR );
461 
462  if ( reset || config->hasKey( "visitedLinkColor" ) )
463  d->m_vLinkColor = config->readColorEntry( "visitedLinkColor", &HTML_DEFAULT_VLNK_COLOR);
464 
465  if ( reset || config->hasKey( "background" ) )
466  d->m_baseColor = config->readColorEntry( "background", &HTML_DEFAULT_BASE_COLOR);
467  }
468 
469  if( reset || config->hasGroup( "Java/JavaScript Settings" ) )
470  {
471  config->setGroup( "Java/JavaScript Settings" );
472 
473  // The global setting for JavaScript debugging
474  // This is currently always enabled by default
475  if ( reset || config->hasKey( "EnableJavaScriptDebug" ) )
476  d->m_bEnableJavaScriptDebug = config->readBoolEntry( "EnableJavaScriptDebug", false );
477 
478  // The global setting for JavaScript error reporting
479  if ( reset || config->hasKey( "ReportJavaScriptErrors" ) )
480  d->m_bEnableJavaScriptErrorReporting = config->readBoolEntry( "ReportJavaScriptErrors", false );
481 
482  // The global setting for popup block passive popup
483  if ( reset || config->hasKey( "PopupBlockerPassivePopup" ) )
484  d->m_jsPopupBlockerPassivePopup = config->readBoolEntry("PopupBlockerPassivePopup", true);
485 
486  // Read options from the global "domain"
487  readDomainSettings(config,reset,true,d->global);
488 #ifdef DEBUG_SETTINGS
489  d->global.dump("init global");
490 #endif
491 
492  // The domain-specific settings.
493 
494  static const char *const domain_keys[] = { // always keep order of keys
495  "ECMADomains", "JavaDomains", "PluginDomains"
496  };
497  bool check_old_ecma_settings = true;
498  bool check_old_java_settings = true;
499  // merge all domains into one list
500  TQMap<TQString,int> domainList; // why can't Qt have a QSet?
501  for (unsigned i = 0; i < sizeof domain_keys/sizeof domain_keys[0]; ++i) {
502  if ( reset || config->hasKey(domain_keys[i]) ) {
503  if (i == 0) check_old_ecma_settings = false;
504  else if (i == 1) check_old_java_settings = false;
505  const TQStringList dl = config->readListEntry( domain_keys[i] );
506  const TQMap<TQString,int>::Iterator notfound = domainList.end();
507  TQStringList::ConstIterator it = dl.begin();
508  const TQStringList::ConstIterator itEnd = dl.end();
509  for (; it != itEnd; ++it) {
510  const TQString domain = (*it).lower();
511  TQMap<TQString,int>::Iterator pos = domainList.find(domain);
512  if (pos == notfound) domainList.insert(domain,0);
513  }/*next it*/
514  }
515  }/*next i*/
516 
517  if (reset)
518  d->domainPolicy.clear();
519 
520  TQString js_group_save = config->group();
521  {
522  TQMap<TQString,int>::ConstIterator it = domainList.begin();
523  const TQMap<TQString,int>::ConstIterator itEnd = domainList.end();
524  for ( ; it != itEnd; ++it)
525  {
526  const TQString domain = it.key();
527  config->setGroup(domain);
528  readDomainSettings(config,reset,false,d->domainPolicy[domain]);
529 #ifdef DEBUG_SETTINGS
530  d->domainPolicy[domain].dump("init "+domain);
531 #endif
532  }
533  }
534  config->setGroup(js_group_save);
535 
536  bool check_old_java = true;
537  if( ( reset || config->hasKey( "JavaDomainSettings" ) )
538  && check_old_java_settings )
539  {
540  check_old_java = false;
541  const TQStringList domainList = config->readListEntry( "JavaDomainSettings" );
542  TQStringList::ConstIterator it = domainList.begin();
543  const TQStringList::ConstIterator itEnd = domainList.end();
544  for ( ; it != itEnd; ++it)
545  {
546  TQString domain;
547  KJavaScriptAdvice javaAdvice;
548  KJavaScriptAdvice javaScriptAdvice;
549  splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
550  setup_per_domain_policy(d,domain).m_bEnableJava =
551  javaAdvice == KJavaScriptAccept;
552 #ifdef DEBUG_SETTINGS
553  setup_per_domain_policy(d,domain).dump("JavaDomainSettings 4 "+domain);
554 #endif
555  }
556  }
557 
558  bool check_old_ecma = true;
559  if( ( reset || config->hasKey( "ECMADomainSettings" ) )
560  && check_old_ecma_settings )
561  {
562  check_old_ecma = false;
563  const TQStringList domainList = config->readListEntry( "ECMADomainSettings" );
564  TQStringList::ConstIterator it = domainList.begin();
565  const TQStringList::ConstIterator itEnd = domainList.end();
566  for ( ; it != itEnd; ++it)
567  {
568  TQString domain;
569  KJavaScriptAdvice javaAdvice;
570  KJavaScriptAdvice javaScriptAdvice;
571  splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
572  setup_per_domain_policy(d,domain).m_bEnableJavaScript =
573  javaScriptAdvice == KJavaScriptAccept;
574 #ifdef DEBUG_SETTINGS
575  setup_per_domain_policy(d,domain).dump("ECMADomainSettings 4 "+domain);
576 #endif
577  }
578  }
579 
580  if( ( reset || config->hasKey( "JavaScriptDomainAdvice" ) )
581  && ( check_old_java || check_old_ecma )
582  && ( check_old_ecma_settings || check_old_java_settings ) )
583  {
584  const TQStringList domainList = config->readListEntry( "JavaScriptDomainAdvice" );
585  TQStringList::ConstIterator it = domainList.begin();
586  const TQStringList::ConstIterator itEnd = domainList.end();
587  for ( ; it != itEnd; ++it)
588  {
589  TQString domain;
590  KJavaScriptAdvice javaAdvice;
591  KJavaScriptAdvice javaScriptAdvice;
592  splitDomainAdvice(*it, domain, javaAdvice, javaScriptAdvice);
593  if( check_old_java )
594  setup_per_domain_policy(d,domain).m_bEnableJava =
595  javaAdvice == KJavaScriptAccept;
596  if( check_old_ecma )
597  setup_per_domain_policy(d,domain).m_bEnableJavaScript =
598  javaScriptAdvice == KJavaScriptAccept;
599 #ifdef DEBUG_SETTINGS
600  setup_per_domain_policy(d,domain).dump("JavaScriptDomainAdvice 4 "+domain);
601 #endif
602  }
603 
604  //save all the settings into the new keywords if they don't exist
605 #if 0
606  if( check_old_java )
607  {
608  TQStringList domainConfig;
609  PolicyMap::Iterator it;
610  for( it = d->javaDomainPolicy.begin(); it != d->javaDomainPolicy.end(); ++it )
611  {
612  TQCString javaPolicy = adviceToStr( it.data() );
613  TQCString javaScriptPolicy = adviceToStr( KJavaScriptDunno );
614  domainConfig.append(TQString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
615  }
616  config->writeEntry( "JavaDomainSettings", domainConfig );
617  }
618 
619  if( check_old_ecma )
620  {
621  TQStringList domainConfig;
622  PolicyMap::Iterator it;
623  for( it = d->javaScriptDomainPolicy.begin(); it != d->javaScriptDomainPolicy.end(); ++it )
624  {
625  TQCString javaPolicy = adviceToStr( KJavaScriptDunno );
626  TQCString javaScriptPolicy = adviceToStr( it.data() );
627  domainConfig.append(TQString::fromLatin1("%1:%2:%3").arg(it.key()).arg(javaPolicy).arg(javaScriptPolicy));
628  }
629  config->writeEntry( "ECMADomainSettings", domainConfig );
630  }
631 #endif
632  }
633  }
634  config->setGroup(group_save);
635 }
636 
637 
642 static const KPerDomainSettings &lookup_hostname_policy(
643  const TDEHTMLSettingsPrivate *d,
644  const TQString& hostname)
645 {
646 #ifdef DEBUG_SETTINGS
647  kdDebug() << "lookup_hostname_policy(" << hostname << ")" << endl;
648 #endif
649  if (hostname.isEmpty()) {
650 #ifdef DEBUG_SETTINGS
651  d->global.dump("global");
652 #endif
653  return d->global;
654  }
655 
656  const PolicyMap::const_iterator notfound = d->domainPolicy.end();
657 
658  // First check whether there is a perfect match.
659  PolicyMap::const_iterator it = d->domainPolicy.find(hostname);
660  if( it != notfound ) {
661 #ifdef DEBUG_SETTINGS
662  kdDebug() << "perfect match" << endl;
663  (*it).dump(hostname);
664 #endif
665  // yes, use it (unless dunno)
666  return *it;
667  }
668 
669  // Now, check for partial match. Chop host from the left until
670  // there's no dots left.
671  TQString host_part = hostname;
672  int dot_idx = -1;
673  while( (dot_idx = host_part.find(TQChar('.'))) >= 0 ) {
674  host_part.remove(0,dot_idx);
675  it = d->domainPolicy.find(host_part);
676  Q_ASSERT(notfound == d->domainPolicy.end());
677  if( it != notfound ) {
678 #ifdef DEBUG_SETTINGS
679  kdDebug() << "partial match" << endl;
680  (*it).dump(host_part);
681 #endif
682  return *it;
683  }
684  // assert(host_part[0] == TQChar('.'));
685  host_part.remove(0,1); // Chop off the dot.
686  }
687 
688  // No domain-specific entry: use global domain
689 #ifdef DEBUG_SETTINGS
690  kdDebug() << "no match" << endl;
691  d->global.dump("global");
692 #endif
693  return d->global;
694 }
695 
696 bool TDEHTMLSettings::isOpenMiddleClickEnabled()
697 {
698  return d->m_bOpenMiddleClick;
699 }
700 
701 bool TDEHTMLSettings::isBackRightClickEnabled()
702 {
703  return d->m_bBackRightClick;
704 }
705 
706 bool TDEHTMLSettings::accessKeysEnabled() const
707 {
708  return d->m_accessKeysEnabled;
709 }
710 
711 bool TDEHTMLSettings::isAdFilterEnabled() const
712 {
713  return d->m_adFilterEnabled;
714 }
715 
716 bool TDEHTMLSettings::isHideAdsEnabled() const
717 {
718  return d->m_hideAdsEnabled;
719 }
720 
721 bool TDEHTMLSettings::isAdFiltered( const TQString &url ) const
722 {
723  if (d->m_adFilterEnabled)
724  {
725  if (!url.startsWith("data:"))
726  {
727  TQValueVector<TQRegExp>::const_iterator it(d->adFilters.constBegin());
728  TQValueVector<TQRegExp>::const_iterator end(d->adFilters.constEnd());
729  for (; it != end; ++it)
730  {
731  if ((*it).search(url) != -1)
732  {
733  kdDebug( 6080 ) << "Filtered: " << url << endl;
734  return true;
735  }
736  }
737  }
738  }
739  return false;
740 }
741 
742 void TDEHTMLSettings::addAdFilter( const TQString &url )
743 {
744  TDEConfig config( "tdehtmlrc", false, false );
745  config.setGroup( "Filter Settings" );
746 
747  TQRegExp rx;
748  if (url.length()>2 && url[0]=='/' && url[url.length()-1] == '/')
749  {
750  TQString inside = url.mid(1, url.length()-2);
751  rx.setWildcard(false);
752  rx.setPattern(inside);
753  }
754  else
755  {
756  int left,right;
757 
758  rx.setWildcard(true);
759  for (right=url.length(); right>0 && url[right-1]=='*' ; --right);
760  for (left=0; left<right && url[left]=='*' ; ++left);
761 
762  rx.setPattern(url.mid(left,right-left));
763  }
764 
765  if (rx.isValid())
766  {
767  int last=config.readNumEntry("Count",0);
768  TQString key = "Filter-" + TQString::number(last);
769  config.writeEntry(key, url);
770  config.writeEntry("Count",last+1);
771  config.sync();
772 
773  d->adFilters.append(rx);
774  }
775  else
776  {
777  KMessageBox::error(0,
778  rx.errorString(),
779  i18n("Filter error"));
780  }
781 }
782 
783 bool TDEHTMLSettings::isJavaEnabled( const TQString& hostname )
784 {
785  return lookup_hostname_policy(d,hostname.lower()).m_bEnableJava;
786 }
787 
788 bool TDEHTMLSettings::isJavaScriptEnabled( const TQString& hostname )
789 {
790  return lookup_hostname_policy(d,hostname.lower()).m_bEnableJavaScript;
791 }
792 
793 bool TDEHTMLSettings::isJavaScriptDebugEnabled( const TQString& /*hostname*/ )
794 {
795  // debug setting is global for now, but could change in the future
796  return d->m_bEnableJavaScriptDebug;
797 }
798 
799 bool TDEHTMLSettings::isJavaScriptErrorReportingEnabled( const TQString& /*hostname*/ ) const
800 {
801  // error reporting setting is global for now, but could change in the future
802  return d->m_bEnableJavaScriptErrorReporting;
803 }
804 
805 bool TDEHTMLSettings::isPluginsEnabled( const TQString& hostname )
806 {
807  return lookup_hostname_policy(d,hostname.lower()).m_bEnablePlugins;
808 }
809 
810 TDEHTMLSettings::KJSWindowOpenPolicy TDEHTMLSettings::windowOpenPolicy(
811  const TQString& hostname) const {
812  return lookup_hostname_policy(d,hostname.lower()).m_windowOpenPolicy;
813 }
814 
815 TDEHTMLSettings::KJSWindowMovePolicy TDEHTMLSettings::windowMovePolicy(
816  const TQString& hostname) const {
817  return lookup_hostname_policy(d,hostname.lower()).m_windowMovePolicy;
818 }
819 
820 TDEHTMLSettings::KJSWindowResizePolicy TDEHTMLSettings::windowResizePolicy(
821  const TQString& hostname) const {
822  return lookup_hostname_policy(d,hostname.lower()).m_windowResizePolicy;
823 }
824 
825 TDEHTMLSettings::KJSWindowStatusPolicy TDEHTMLSettings::windowStatusPolicy(
826  const TQString& hostname) const {
827  return lookup_hostname_policy(d,hostname.lower()).m_windowStatusPolicy;
828 }
829 
830 TDEHTMLSettings::KJSWindowFocusPolicy TDEHTMLSettings::windowFocusPolicy(
831  const TQString& hostname) const {
832  return lookup_hostname_policy(d,hostname.lower()).m_windowFocusPolicy;
833 }
834 
835 int TDEHTMLSettings::mediumFontSize() const
836 {
837  return d->m_fontSize;
838 }
839 
840 int TDEHTMLSettings::minFontSize() const
841 {
842  return d->m_minFontSize;
843 }
844 
845 TQString TDEHTMLSettings::settingsToCSS() const
846 {
847  // lets start with the link properties
848  TQString str = "a:link {\ncolor: ";
849  str += d->m_linkColor.name();
850  str += ";";
851  if(d->m_underlineLink)
852  str += "\ntext-decoration: underline;";
853 
854  if( d->m_bChangeCursor )
855  {
856  str += "\ncursor: pointer;";
857  str += "\n}\ninput[type=image] { cursor: pointer;";
858  }
859  str += "\n}\n";
860  str += "a:visited {\ncolor: ";
861  str += d->m_vLinkColor.name();
862  str += ";";
863  if(d->m_underlineLink)
864  str += "\ntext-decoration: underline;";
865 
866  if( d->m_bChangeCursor )
867  str += "\ncursor: pointer;";
868  str += "\n}\n";
869 
870  if(d->m_hoverLink)
871  str += "a:link:hover, a:visited:hover { text-decoration: underline; }\n";
872 
873  return str;
874 }
875 
876 const TQString &TDEHTMLSettings::availableFamilies()
877 {
878  if ( !avFamilies ) {
879  avFamilies = new TQString;
880  TQFontDatabase db;
881  TQStringList families = db.families();
882  TQStringList s;
883  TQRegExp foundryExp(" \\[.+\\]");
884 
885  //remove foundry info
886  TQStringList::Iterator f = families.begin();
887  const TQStringList::Iterator fEnd = families.end();
888 
889  for ( ; f != fEnd; ++f ) {
890  (*f).replace( foundryExp, "");
891  if (!s.contains(*f))
892  s << *f;
893  }
894  s.sort();
895 
896  *avFamilies = ',' + s.join(",") + ',';
897  }
898 
899  return *avFamilies;
900 }
901 
902 TQString TDEHTMLSettings::lookupFont(int i) const
903 {
904  TQString font;
905  if (d->fonts.count() > (uint) i)
906  font = d->fonts[i];
907  if (font.isEmpty())
908  font = d->defaultFonts[i];
909  return font;
910 }
911 
912 TQString TDEHTMLSettings::stdFontName() const
913 {
914  return lookupFont(0);
915 }
916 
917 TQString TDEHTMLSettings::fixedFontName() const
918 {
919  return lookupFont(1);
920 }
921 
922 TQString TDEHTMLSettings::serifFontName() const
923 {
924  return lookupFont(2);
925 }
926 
927 TQString TDEHTMLSettings::sansSerifFontName() const
928 {
929  return lookupFont(3);
930 }
931 
932 TQString TDEHTMLSettings::cursiveFontName() const
933 {
934  return lookupFont(4);
935 }
936 
937 TQString TDEHTMLSettings::fantasyFontName() const
938 {
939  return lookupFont(5);
940 }
941 
942 void TDEHTMLSettings::setStdFontName(const TQString &n)
943 {
944  while(d->fonts.count() <= 0)
945  d->fonts.append(TQString::null);
946  d->fonts[0] = n;
947 }
948 
949 void TDEHTMLSettings::setFixedFontName(const TQString &n)
950 {
951  while(d->fonts.count() <= 1)
952  d->fonts.append(TQString::null);
953  d->fonts[1] = n;
954 }
955 
956 TQString TDEHTMLSettings::userStyleSheet() const
957 {
958  return d->m_userSheet;
959 }
960 
961 bool TDEHTMLSettings::isFormCompletionEnabled() const
962 {
963  return d->m_formCompletionEnabled;
964 }
965 
966 int TDEHTMLSettings::maxFormCompletionItems() const
967 {
968  return d->m_maxFormCompletionItems;
969 }
970 
971 const TQString &TDEHTMLSettings::encoding() const
972 {
973  return d->m_encoding;
974 }
975 
976 bool TDEHTMLSettings::followSystemColors() const
977 {
978  return d->m_follow_system_colors;
979 }
980 
981 const TQColor& TDEHTMLSettings::textColor() const
982 {
983  return d->m_textColor;
984 }
985 
986 const TQColor& TDEHTMLSettings::baseColor() const
987 {
988  return d->m_baseColor;
989 }
990 
991 const TQColor& TDEHTMLSettings::linkColor() const
992 {
993  return d->m_linkColor;
994 }
995 
996 const TQColor& TDEHTMLSettings::vLinkColor() const
997 {
998  return d->m_vLinkColor;
999 }
1000 
1001 bool TDEHTMLSettings::autoLoadImages() const
1002 {
1003  return d->m_bAutoLoadImages;
1004 }
1005 
1006 bool TDEHTMLSettings::unfinishedImageFrame() const
1007 {
1008  return d->m_bUnfinishedImageFrame;
1009 }
1010 
1011 TDEHTMLSettings::KAnimationAdvice TDEHTMLSettings::showAnimations() const
1012 {
1013  return d->m_showAnimations;
1014 }
1015 
1016 bool TDEHTMLSettings::isAutoDelayedActionsEnabled() const
1017 {
1018  return d->m_autoDelayedActionsEnabled;
1019 }
1020 
1021 bool TDEHTMLSettings::jsErrorsEnabled() const
1022 {
1023  return d->m_jsErrorsEnabled;
1024 }
1025 
1026 void TDEHTMLSettings::setJSErrorsEnabled(bool enabled)
1027 {
1028  d->m_jsErrorsEnabled = enabled;
1029  // save it
1030  TDEConfig *config = TDEGlobal::config();
1031  config->setGroup("HTML Settings");
1032  config->writeEntry("ReportJSErrors", enabled);
1033  config->sync();
1034 }
1035 
1036 bool TDEHTMLSettings::allowTabulation() const
1037 {
1038  return d->m_allowTabulation;
1039 }
1040 
1041 bool TDEHTMLSettings::autoSpellCheck() const
1042 {
1043  return d->m_autoSpellCheck;
1044 }
1045 
1046 TQValueList< TQPair< TQString, TQChar > > TDEHTMLSettings::fallbackAccessKeysAssignments() const
1047 {
1048  return d->m_fallbackAccessKeysAssignments;
1049 }
1050 
1051 void TDEHTMLSettings::setJSPopupBlockerPassivePopup(bool enabled)
1052 {
1053  d->m_jsPopupBlockerPassivePopup = enabled;
1054  // save it
1055  TDEConfig *config = TDEGlobal::config();
1056  config->setGroup("Java/JavaScript Settings");
1057  config->writeEntry("PopupBlockerPassivePopup", enabled);
1058  config->sync();
1059 }
1060 
1061 bool TDEHTMLSettings::jsPopupBlockerPassivePopup() const
1062 {
1063  return d->m_jsPopupBlockerPassivePopup;
1064 }
KMessageBox::error
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
TDEConfigBase::readColorEntry
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfigBase::readUnsignedNumEntry
unsigned int readUnsignedNumEntry(const TQString &pKey, unsigned int nDefault=0) const
TDEConfigBase::hasGroup
bool hasGroup(const TQString &group) const
TDEConfigBase::group
TQString group() const
TDEConfigBase::readListEntry
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
TDEConfigBase::sync
virtual void sync()
TDEConfigBase::hasKey
bool hasKey(const TQString &key) const
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
TDEConfig::entryMap
virtual TQMap< TQString, TQString > entryMap(const TQString &pGroup) const
TDEGlobalSettings::generalFont
static TQFont generalFont()
TDEGlobalSettings::fixedFont
static TQFont fixedFont()
TDEGlobal::config
static TDEConfig * config()
TDEHTMLSettings
Settings for the HTML view.
Definition: tdehtml_settings.h:39
TDEHTMLSettings::KJavaScriptAdvice
KJavaScriptAdvice
This enum specifies whether Java/JavaScript execution is allowed.
Definition: tdehtml_settings.h:45
TDEHTMLSettings::~TDEHTMLSettings
virtual ~TDEHTMLSettings()
Destructor.
Definition: tdehtml_settings.cpp:270
TDEHTMLSettings::readDomainSettings
void readDomainSettings(TDEConfig *config, bool reset, bool global, KPerDomainSettings &pd_settings)
reads from config's current group, forcing initialization if reset is true.
Definition: tdehtml_settings.cpp:189
TDEHTMLSettings::init
void init()
Called by constructor and reparseConfiguration.
Definition: tdehtml_settings.cpp:290
TDEHTMLSettings::KJSWindowMovePolicy
KJSWindowMovePolicy
This enum specifies the policy for window.moveBy and .moveTo.
Definition: tdehtml_settings.h:78
TDEHTMLSettings::KJSWindowResizePolicy
KJSWindowResizePolicy
This enum specifies the policy for window.resizeBy and .resizeTo.
Definition: tdehtml_settings.h:86
TDEHTMLSettings::KJSWindowOpenPolicy
KJSWindowOpenPolicy
This enum specifies the policy for window.open.
Definition: tdehtml_settings.h:60
TDEHTMLSettings::KJSWindowStatusPolicy
KJSWindowStatusPolicy
This enum specifies the policy for window.status and .defaultStatus.
Definition: tdehtml_settings.h:70
TDEHTMLSettings::KJSWindowFocusPolicy
KJSWindowFocusPolicy
This enum specifies the policy for window.focus.
Definition: tdehtml_settings.h:94
I18N_NOOP
#define I18N_NOOP(x)
endl
kndbgstream & endl(kndbgstream &s)
kdWarning
kdbgstream kdWarning(int area=0)
kdDebug
kdbgstream kdDebug(int area=0)
TDEStdAccel::key
int key(StdAccel id)
TDEStdAccel::end
const TDEShortcut & end()
tdelocale.h

tdehtml

Skip menu "tdehtml"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.9.1
This website is maintained by Timothy Pearson.