• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 API Reference
  • KDE Home
  • Contact Us
 

KParts

  • kparts
htmlextension.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2010 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 "htmlextension.h"
21 
22 #include "part.h"
23 
24 #include <kglobal.h>
25 #include <klocalizedstring.h>
26 
27 
28 using namespace KParts;
29 
30 KParts::HtmlExtension::HtmlExtension(KParts::ReadOnlyPart* parent)
31  : QObject(parent), d(0)
32 {
33 }
34 
35 KParts::HtmlExtension::~HtmlExtension()
36 {
37 }
38 
39 bool HtmlExtension::hasSelection() const
40 {
41  return false;
42 }
43 
44 HtmlExtension * KParts::HtmlExtension::childObject( QObject *obj )
45 {
46  return KGlobal::findDirectChild<KParts::HtmlExtension *>(obj);
47 }
48 
49 SelectorInterface::QueryMethods SelectorInterface::supportedQueryMethods() const
50 {
51  return KParts::SelectorInterface::None;
52 }
53 
54 class SelectorInterface::ElementPrivate : public QSharedData
55 {
56 public:
57  QString tag;
58  QHash<QString, QString> attributes;
59 };
60 
61 SelectorInterface::Element::Element()
62  : d(new ElementPrivate)
63 {
64 }
65 
66 SelectorInterface::Element::Element(const SelectorInterface::Element& other)
67  : d(other.d)
68 {
69 }
70 
71 SelectorInterface::Element::~Element()
72 {
73 }
74 
75 bool SelectorInterface::Element::isNull() const
76 {
77  return d->tag.isNull();
78 }
79 
80 void SelectorInterface::Element::setTagName(const QString& tag)
81 {
82  d->tag = tag;
83 }
84 
85 QString SelectorInterface::Element::tagName() const
86 {
87  return d->tag;
88 }
89 
90 void SelectorInterface::Element::setAttribute(const QString& name, const QString& value)
91 {
92  d->attributes[name] = value; // insert or replace
93 }
94 
95 QStringList SelectorInterface::Element::attributeNames() const
96 {
97  return d->attributes.keys();
98 }
99 
100 QString SelectorInterface::Element::attribute(const QString& name, const QString& defaultValue) const
101 {
102  return d->attributes.value(name, defaultValue);
103 }
104 
105 bool SelectorInterface::Element::hasAttribute(const QString& name) const
106 {
107  return d->attributes.contains(name);
108 }
109 
110 const char* HtmlSettingsInterface::javascriptAdviceToText(HtmlSettingsInterface::JavaScriptAdvice advice)
111 {
112  // NOTE: The use of I18N_NOOP below is intended to allow GUI code to call
113  // i18n on the returned text without affecting use of untranslated text in
114  // config files.
115  switch (advice) {
116  case JavaScriptAccept:
117  return I18N_NOOP("Accept");
118  case JavaScriptReject:
119  return I18N_NOOP("Reject");
120  default:
121  break;
122  }
123 
124  return 0;
125 }
126 
127 HtmlSettingsInterface::JavaScriptAdvice HtmlSettingsInterface::textToJavascriptAdvice(const QString& text)
128 {
129  JavaScriptAdvice ret = JavaScriptDunno;
130 
131  if (!text.isEmpty()) {
132  if (text.compare(QLatin1String("accept"), Qt::CaseInsensitive) == 0) {
133  ret = JavaScriptAccept;
134  } else if (text.compare(QLatin1String("reject"), Qt::CaseInsensitive) == 0) {
135  ret = JavaScriptReject;
136  }
137  }
138 
139  return ret;
140 }
141 
142 void HtmlSettingsInterface::splitDomainAdvice(const QString& adviceStr, QString& domain, HtmlSettingsInterface::JavaScriptAdvice& javaAdvice, HtmlSettingsInterface::JavaScriptAdvice& javaScriptAdvice)
143 {
144  const QString tmp(adviceStr);
145  const int splitIndex = tmp.indexOf(':');
146 
147  if (splitIndex == -1) {
148  domain = adviceStr.toLower();
149  javaAdvice = JavaScriptDunno;
150  javaScriptAdvice = JavaScriptDunno;
151  } else {
152  domain = tmp.left(splitIndex).toLower();
153  const QString adviceString = tmp.mid(splitIndex+1, tmp.length());
154  const int splitIndex2 = adviceString.indexOf(QLatin1Char(':'));
155  if (splitIndex2 == -1) {
156  // Java advice only
157  javaAdvice = textToJavascriptAdvice(adviceString);
158  javaScriptAdvice = JavaScriptDunno;
159  } else {
160  // Java and JavaScript advice
161  javaAdvice = textToJavascriptAdvice(adviceString.left(splitIndex2));
162  javaScriptAdvice = textToJavascriptAdvice(adviceString.mid(splitIndex2+1,
163  adviceString.length()));
164  }
165  }
166 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Wed Jun 5 2013 18:39:50 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KParts

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

kdelibs-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal